]>
sourceware.org Git - lvm2.git/blob - tools/lvrename.c
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include "lvm-types.h"
21 * lvrename command implementation.
22 * Check arguments and call lv_rename() to execute the request.
24 int lvrename(struct cmd_context
*cmd
, int argc
, char **argv
)
27 char *lv_name_old
, *lv_name_new
;
28 const char *vg_name
, *vg_name_new
, *vg_name_old
;
32 struct volume_group
*vg
= NULL
;
36 vg_name
= skip_dev_dir(cmd
, argv
[0], NULL
);
37 lv_name_old
= argv
[1];
38 lv_name_new
= argv
[2];
39 if (strchr(lv_name_old
, '/') &&
40 (vg_name_old
= extract_vgname(cmd
, lv_name_old
)) &&
41 strcmp(vg_name_old
, vg_name
)) {
42 log_error("Please use a single volume group name "
43 "(\"%s\" or \"%s\")", vg_name
, vg_name_old
);
44 return EINVALID_CMD_LINE
;
46 } else if (argc
== 2) {
47 lv_name_old
= argv
[0];
48 lv_name_new
= argv
[1];
49 vg_name
= extract_vgname(cmd
, lv_name_old
);
51 log_error("Old and new logical volume names required");
52 return EINVALID_CMD_LINE
;
55 if (!validate_name(vg_name
)) {
56 log_error("Please provide a valid volume group name");
57 return EINVALID_CMD_LINE
;
60 if (strchr(lv_name_new
, '/') &&
61 (vg_name_new
= extract_vgname(cmd
, lv_name_new
)) &&
62 strcmp(vg_name
, vg_name_new
)) {
63 log_error("Logical volume names must "
64 "have the same volume group (\"%s\" or \"%s\")",
65 vg_name
, vg_name_new
);
66 return EINVALID_CMD_LINE
;
69 if ((st
= strrchr(lv_name_old
, '/')))
72 if ((st
= strrchr(lv_name_new
, '/')))
75 /* Check sanity of new name */
76 maxlen
= NAME_LEN
- strlen(vg_name
) - strlen(cmd
->dev_dir
) - 3;
77 if (strlen(lv_name_new
) > maxlen
) {
78 log_error("New logical volume path exceeds maximum length "
79 "of %" PRIsize_t
"!", maxlen
);
84 log_error("New logical volume name may not be blank");
88 if (!apply_lvname_restrictions(lv_name_new
)) {
93 if (!validate_name(lv_name_new
)) {
94 log_error("New logical volume name \"%s\" is invalid",
96 return EINVALID_CMD_LINE
;
99 if (!strcmp(lv_name_old
, lv_name_new
)) {
100 log_error("Old and new logical volume names must differ");
101 return EINVALID_CMD_LINE
;
104 log_verbose("Checking for existing volume group \"%s\"", vg_name
);
105 vg
= vg_read_for_update(cmd
, vg_name
, NULL
, 0);
106 if (vg_read_error(vg
)) {
112 if (!(lvl
= find_lv_in_vg(vg
, lv_name_old
))) {
113 log_error("Existing logical volume \"%s\" not found in "
114 "volume group \"%s\"", lv_name_old
, vg_name
);
118 if (lvl
->lv
->status
& (RAID_IMAGE
| RAID_META
)) {
119 log_error("Cannot rename a RAID %s directly",
120 (lvl
->lv
->status
& RAID_IMAGE
) ? "image" :
126 if (lv_is_raid_with_tracking(lvl
->lv
)) {
127 log_error("Cannot rename %s while it is tracking a split image",
133 if (!lv_rename(cmd
, lvl
->lv
, lv_name_new
))
136 log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
137 lv_name_old
, lv_name_new
, vg_name
);
141 unlock_and_release_vg(cmd
, vg
, vg_name
);
This page took 0.044206 seconds and 5 git commands to generate.