Skip to contentSkip to conversation

LVM2 lib/metadata/metadata-exported.h lib/meta ...

PATCH [email protected] 1 participant 1 message Jan 15, 2008

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2008-01-15 22:56:30

Modified files:
lib/metadata : metadata-exported.h metadata.c
tools : toollib.c toollib.h vgcreate.c vgrename.c
vgsplit.c
Added files:
test : t-vgrename-usage.sh

Log message:

	Move more parameter validation into the library.
	Update vgrename to call validate_vg_rename_params().
	Fix vgcreate and vgsplit default arguments by adding defaults parameter to
	fill_vg_create_params().
	Add t-vgrename-usage.sh test.
	Bugzilla: bz251992
	---
	tools/toollib.c  |   32 ++++++++------------------------
	tools/toollib.h  |    5 ++---
	tools/vgcreate.c |   35 +++++++++++++++++++++--------------
	tools/vgrename.c |   35 ++++++-----------------------------
	tools/vgsplit.c  |   21 ++++++++++++++-------
	5 files changed, 51 insertions(+), 77 deletions(-)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.32&r2=1.33
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.147&r2=1.148
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-vgrename-usage.sh.diff?cvsroot=lvm2&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.124&r2=1.125
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.h.diff?cvsroot=lvm2&r1=1.55&r2=1.56
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgcreate.c.diff?cvsroot=lvm2&r1=1.54&r2=1.55
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgrename.c.diff?cvsroot=lvm2&r1=1.48&r2=1.49
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgsplit.c.diff?cvsroot=lvm2&r1=1.44&r2=1.45

lib/metadata/metadata-exported.h +3 -0
@@ -540,4 +540,7 @@
 int validate_vg_create_params(struct cmd_context *cmd,
 			      struct vgcreate_params *vp);
 
+int validate_vg_rename_params(struct cmd_context *cmd,
+			      const char *vg_name_old,
+			      const char *vg_name_new);
 #endif
lib/metadata/metadata.c +49 -0

61 lines not on this page · raw message

/cvs/lvm2/LVM2/test/t-vgrename-usage.sh,v --> standard output revision 1.1

- renamed from test/t-vgrename-usage.sh +46 -0

46 lines not on this page · raw message

tools/toollib.c +14 -28

64 lines not on this page · raw message

tools/toollib.h +2 -3
@@ -96,8 +96,7 @@
 
 int apply_lvname_restrictions(const char *name);
 
-int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name);
-
 int fill_vg_create_params(struct cmd_context *cmd,
-			  char *vg_name, struct vgcreate_params *vp);
+			  char *vg_name, struct vgcreate_params *vp_new,
+			  struct vgcreate_params *vp_def);
 #endif
tools/vgcreate.c +21 -14
@@ -17,7 +17,8 @@
 
 int vgcreate(struct cmd_context *cmd, int argc, char **argv)
 {
-	struct vgcreate_params vp;
+	struct vgcreate_params vp_new;
+	struct vgcreate_params vp_def;
 	struct volume_group *vg;
 	const char *tag;
 
@@ -32,23 +33,29 @@
 		return EINVALID_CMD_LINE;
 	}
 
-	if (fill_vg_create_params(cmd, argv[0], &vp))
+	vp_def.vg_name = NULL;
+	vp_def.extent_size = DEFAULT_PE_SIZE;
+	vp_def.max_pv = 0;
+	vp_def.max_lv = 0;
+	vp_def.alloc = ALLOC_NORMAL;
+	vp_def.clustered = 0;
+	if (fill_vg_create_params(cmd, argv[0], &vp_new, &vp_def))
 		return EINVALID_CMD_LINE;
 
-	if (validate_vg_create_params(cmd, &vp))
+	if (validate_vg_create_params(cmd, &vp_new))
 	    return EINVALID_CMD_LINE;
 
 	/* Create the new VG */
-	if (!(vg = vg_create(cmd, vp.vg_name, vp.extent_size, vp.max_pv,
-			     vp.max_lv, vp.alloc,
+	if (!(vg = vg_create(cmd, vp_new.vg_name, vp_new.extent_size,
+			     vp_new.max_pv, vp_new.max_lv, vp_new.alloc,
 			     argc - 1, argv + 1)))
 		return ECMD_FAILED;
 
-	if (vp.max_lv != vg->max_lv)
+	if (vp_new.max_lv != vg->max_lv)
 		log_warn("WARNING: Setting maxlogicalvolumes to %d "
 			 "(0 means unlimited)", vg->max_lv);
 
-	if (vp.max_pv != vg->max_pv)
+	if (vp_new.max_pv != vg->max_pv)
 		log_warn("WARNING: Setting maxphysicalvolumes to %d "
 			 "(0 means unlimited)", vg->max_pv);
 
@@ -65,13 +72,13 @@
 
 		if (!str_list_add(cmd->mem, &vg->tags, tag)) {
 			log_error("Failed to add tag %s to volume group %s",
-				  tag, vp.vg_name);
+				  tag, vp_new.vg_name);
 			return ECMD_FAILED;
 		}
 	}
 
 	/* FIXME: move this inside vg_create? */
-	if (vp.clustered)
+	if (vp_new.clustered)
 		vg->status |= CLUSTERED;
 	else
 		vg->status &= ~CLUSTERED;
@@ -81,26 +88,26 @@
 		return ECMD_FAILED;
 	}
 
-	if (!lock_vol(cmd, vp.vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
-		log_error("Can't get lock for %s", vp.vg_name);
+	if (!lock_vol(cmd, vp_new.vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
+		log_error("Can't get lock for %s", vp_new.vg_name);
 		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	}
 
 	if (!archive(vg)) {
-		unlock_vg(cmd, vp.vg_name);
+		unlock_vg(cmd, vp_new.vg_name);
 		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	}
 
 	/* Store VG on disk(s) */
 	if (!vg_write(vg) || !vg_commit(vg)) {
-		unlock_vg(cmd, vp.vg_name);
+		unlock_vg(cmd, vp_new.vg_name);
 		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	}
 
-	unlock_vg(cmd, vp.vg_name);
+	unlock_vg(cmd, vp_new.vg_name);
 	unlock_vg(cmd, VG_ORPHANS);
 
 	backup(vg);
tools/vgrename.c +1 -18
@@ -19,7 +19,6 @@
 			  const char *new_vg_path)
 {
 	char *dev_dir;
-	unsigned length;
 	struct id id;
 	int consistent = 1;
 	int match = 0;
@@ -35,25 +34,9 @@
 	vg_name_new = skip_dev_dir(cmd, new_vg_path, NULL);
 
 	dev_dir = cmd->dev_dir;
-	length = strlen(dev_dir);
 
-	/* Check sanity of new name */
-	if (strlen(vg_name_new) > NAME_LEN - length - 2) {
-		log_error("New volume group path exceeds maximum length "
-			  "of %d!", NAME_LEN - length - 2);
+	if (!validate_vg_rename_params(cmd, vg_name_old, vg_name_new))
 		return 0;
-	}
-
-	if (!validate_new_vg_name(cmd, vg_name_new)) {
-		log_error("New volume group name \"%s\" is invalid",
-			  vg_name_new);
-		return 0;
-	}
-
-	if (!strcmp(vg_name_old, vg_name_new)) {
-		log_error("Old and new volume group names must differ");
-		return 0;
-	}
 
 	log_verbose("Checking for existing volume group \"%s\"", vg_name_old);
 
tools/vgsplit.c +14 -7
@@ -212,7 +212,8 @@
 
 int vgsplit(struct cmd_context *cmd, int argc, char **argv)
 {
-	struct vgcreate_params vp;
+	struct vgcreate_params vp_new;
+	struct vgcreate_params vp_def;
 	char *vg_name_from, *vg_name_to;
 	struct volume_group *vg_to, *vg_from;
 	int opt;
@@ -260,18 +261,24 @@
 		/* FIXME: need some common logic */
 		cmd->fmt = vg_from->fid->fmt;
 
-		/* FIXME: original code took defaults from vg_from */
-		if (fill_vg_create_params(cmd, vg_name_to, &vp))
+		vp_def.vg_name = NULL;
+		vp_def.extent_size = vg_from->extent_size;
+		vp_def.max_pv = vg_from->max_pv;
+		vp_def.max_lv = vg_from->max_lv;
+		vp_def.alloc = vg_from->alloc;
+		vp_def.clustered = 0;
+
+		if (fill_vg_create_params(cmd, vg_name_to, &vp_new, &vp_def))
 			return EINVALID_CMD_LINE;
 
-		if (validate_vg_create_params(cmd, &vp))
+		if (validate_vg_create_params(cmd, &vp_new))
 			return EINVALID_CMD_LINE;
 
 		/* Create new VG structure */
 		/* FIXME: allow user input same params as to vgcreate tool */
-		if (!(vg_to = vg_create(cmd, vg_name_to, vp.extent_size,
-					vp.max_pv, vp.max_lv,
-					vp.alloc, 0, NULL)))
+		if (!(vg_to = vg_create(cmd, vg_name_to, vp_new.extent_size,
+					vp_new.max_pv, vp_new.max_lv,
+					vp_new.alloc, 0, NULL)))
 			goto error;
 
 		if (vg_from->status & CLUSTERED)