Skip to contentSkip to conversation

master - vgextend: Use process_each_vg.

PATCH Alasdair Kergon 1 participant 1 message Feb 13, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f5d06efbab4c7c77298b18b95c23111575a8db1a
Commit:        f5d06efbab4c7c77298b18b95c23111575a8db1a
Parent:        1ced5562cddb38b0eda1be1e1657b5eee2500f37
Author:        David Teigland <[email protected]>
AuthorDate:    Fri Feb 13 14:58:51 2015 +0000
Committer:     Alasdair G Kergon <[email protected]>
CommitterDate: Fri Feb 13 14:58:51 2015 +0000

vgextend: Use process_each_vg.

Tags and --select are not yet supported because new code is needed to ensure exactly one VG matches before the VG starts to be processed.

---
 WHATS_NEW        |    1 +
 lib/log/log.h    |    2 +
 tools/pvcreate.c |    2 +-
 tools/toollib.c  |   25 ++++++-
 tools/toollib.h  |    3 +-
 tools/tools.h    |    4 +-
 tools/vgcreate.c |    2 +-
 tools/vgextend.c |  189 +++++++++++++++++++++++++++++++----------------------
 8 files changed, 141 insertions(+), 87 deletions(-)
WHATS_NEW +1 -0
index 2c50c78..1aba0ac 100644
@@ -1,5 +1,6 @@
 Version 2.02.117 - 
 ====================================
+  Update vgextend to use process_each_vg.
   Add --ignoreskippedcluster to pvchange.
   Allow pvchange to modify several properties at once.
   Update pvchange to use process_each_pv.
lib/log/log.h +2 -0
index 99e7623..75a6220 100644
@@ -109,6 +109,8 @@
 
 #define return_0	do { stack; return 0; } while (0)
 #define return_NULL	do { stack; return NULL; } while (0)
+#define return_EINVALID_CMD_LINE \
+			do { stack; return EINVALID_CMD_LINE; } while (0)
 #define return_ECMD_FAILED do { stack; return ECMD_FAILED; } while (0)
 #define goto_out	do { stack; goto out; } while (0)
 #define goto_bad	do { stack; goto bad; } while (0)
tools/pvcreate.c +1 -1
index 958e353..1398198 100644
@@ -101,7 +101,7 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
 	if (!pvcreate_restore_params_validate(cmd, argc, argv, &pp)) {
 		return EINVALID_CMD_LINE;
 	}
-	if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
+	if (!pvcreate_params_validate(cmd, argc, &pp)) {
 		return EINVALID_CMD_LINE;
 	}
 
tools/toollib.c +22 -3
index 22fd9a6..df3f479 100644
@@ -881,8 +881,7 @@ void lv_spawn_background_polling(struct cmd_context *cmd,
  * Output arguments:
  * pp: structure allocated by caller, fields written / validated here
  */
-int pvcreate_params_validate(struct cmd_context *cmd,
-			     int argc, char **argv,
+int pvcreate_params_validate(struct cmd_context *cmd, int argc,
 			     struct pvcreate_params *pp)
 {
 	if (!argc) {
@@ -1468,6 +1467,7 @@ struct vgnameid_list {
  */
 static int _get_arg_vgnames(struct cmd_context *cmd,
 			    int argc, char **argv,
+			    unsigned one_vgname_arg,
 			    struct dm_list *arg_vgnames,
 			    struct dm_list *arg_tags)
 {
@@ -1479,18 +1479,26 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
 
 	for (; opt < argc; opt++) {
 		vg_name = argv[opt];
+
 		if (*vg_name == '@') {
+			if (one_vgname_arg) {
+				log_error("This command does not yet support a tag to identify a Volume Group.");
+				return EINVALID_CMD_LINE;
+			}
+
 			if (!validate_tag(vg_name + 1)) {
 				log_error("Skipping invalid tag: %s", vg_name);
 				if (ret_max < EINVALID_CMD_LINE)
 					ret_max = EINVALID_CMD_LINE;
 				continue;
 			}
+
 			if (!str_list_add(cmd->mem, arg_tags,
 					  dm_pool_strdup(cmd->mem, vg_name + 1))) {
 				log_error("strlist allocation failed.");
 				return ECMD_FAILED;
 			}
+
 			continue;
 		}
 
@@ -1499,13 +1507,19 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
 			log_error("Invalid volume group name %s.", vg_name);
 			if (ret_max < EINVALID_CMD_LINE)
 				ret_max = EINVALID_CMD_LINE;
+			if (one_vgname_arg)
+				break;
 			continue;
 		}
+
 		if (!str_list_add(cmd->mem, arg_vgnames,
 				  dm_pool_strdup(cmd->mem, vg_name))) {
 			log_error("strlist allocation failed.");
 			return ECMD_FAILED;
 		}
+
+		if (one_vgname_arg)
+			break;
 	}
 
 	return ret_max;
@@ -1718,6 +1732,9 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
 	if (dm_list_empty(arg_vgnames) && dm_list_empty(arg_tags))
 		process_all = 1;
 
+	/*
+	 * FIXME If one_vgname_arg, only proceed if exactly one VG matches tags or selection.
+	 */
 	dm_list_iterate_items(vgnl, vgnameids_to_process) {
 		if (sigint_caught())
 			return_ECMD_FAILED;
@@ -1805,6 +1822,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
 	struct dm_list vgnameids_to_process;	/* vgnameid_list */
 
 	int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
+	unsigned one_vgname_arg = (flags & ONE_VGNAME_ARG);
 	int ret;
 
 	dm_list_init(&arg_tags);
@@ -1815,7 +1833,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
 	/*
 	 * Find any VGs or tags explicitly provided on the command line.
 	 */
-	if ((ret = _get_arg_vgnames(cmd, argc, argv, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED)
+	if ((ret = _get_arg_vgnames(cmd, argc, argv, one_vgname_arg, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED)
 		goto_out;
 
 	/*
@@ -1855,6 +1873,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
 out:
 	if (!handle_supplied)
 		destroy_processing_handle(cmd, handle);
+
 	return ret;
 }
 
tools/toollib.h +1 -2
index 7486d44..b9d4680 100644
@@ -174,8 +174,7 @@ int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv);
 int vg_refresh_visible(struct cmd_context *cmd, struct volume_group *vg);
 void lv_spawn_background_polling(struct cmd_context *cmd,
 				 struct logical_volume *lv);
-int pvcreate_params_validate(struct cmd_context *cmd,
-			     int argc, char **argv,
+int pvcreate_params_validate(struct cmd_context *cmd, int argc,
 			     struct pvcreate_params *pp);
 
 int get_activation_monitoring_mode(struct cmd_context *cmd,
tools/tools.h +3 -1
index 2196dba..109834a 100644
@@ -102,10 +102,12 @@ struct arg_value_group_list {
 
 #define CACHE_VGMETADATA	0x00000001
 #define PERMITTED_READ_ONLY 	0x00000002
-/* Process all vgs if none specified on the command line. */
+/* Process all VGs if none specified on the command line. */
 #define ALL_VGS_IS_DEFAULT	0x00000004
 /* Process all devices with --all if none are specified on the command line. */
 #define ENABLE_ALL_DEVS		0x00000008	
+/* Exactly one VG name argument required. */
+#define ONE_VGNAME_ARG		0x00000010
  
 /* a register of the lvm commands */
 struct command {
tools/vgcreate.c +1 -1
index 01bf421..ed6c4d9 100644
@@ -37,7 +37,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
 	argv++;
 
 	pvcreate_params_set_defaults(&pp);
-	if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
+	if (!pvcreate_params_validate(cmd, argc, &pp)) {
 		return EINVALID_CMD_LINE;
 	}
 
tools/vgextend.c +110 -79

220 lines not on this page · raw message