Skip to contentSkip to conversation

toollib: rework process_each_vg

PATCH New David Teigland 1 participant 1 message Mar 15, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 toollib: rework process_each_vg

A new flag from commands makes explicit when process_each_vg may query for "all vgs" and run the command on each. A command is run against all vgs only when this flag is provided and no vg names or tags are provided.

When vg names or tags are explicitly named on the command line, the command is only run against named vgs, or vgs with tags matching one provided.

There should be no functional change.

---
 lib/metadata/metadata-exported.h |   3 +-
 tools/polldaemon.c               |   3 +-
 tools/reporter.c                 |   6 +-
 tools/toollib.c                  | 244 ++++++++++++++++++++++++---------------
 tools/vgcfgbackup.c              |   2 +-
 tools/vgchange.c                 |   8 +-
 tools/vgck.c                     |   2 +-
 tools/vgdisplay.c                |   2 +-
 tools/vgexport.c                 |   7 +-
 tools/vgscan.c                   |   2 +-
 10 files changed, 174 insertions(+), 105 deletions(-)
lib/metadata/metadata-exported.h +2 -1
index c2728d5..7db0e68 100644
@@ -119,8 +119,9 @@
 #define READ_ALLOW_EXPORTED	0x00020000U
 #define READ_WITHOUT_LOCK	0x00040000U
 
-/* A meta-flag, useful with toollib for_each_* functions. */
+/* meta-flags, useful with toollib for_each_* functions. */
 #define READ_FOR_UPDATE		0x00100000U
+#define ENABLE_ALL_VGNAMES	0x00200000U	/* run cmd on all vg names if none are named */
 
 /* vg's "read_status" field */
 #define FAILED_INCONSISTENT	0x00000001U
tools/polldaemon.c +2 -1
index 5724623..95f048b 100644
@@ -290,7 +290,8 @@ static void _poll_for_all_vgs(struct cmd_context *cmd,
 {
 	while (1) {
 		parms->outstanding_count = 0;
-		process_each_vg(cmd, 0, NULL, READ_FOR_UPDATE, parms, _poll_vg);
+		process_each_vg(cmd, 0, NULL, READ_FOR_UPDATE | ENABLE_ALL_VGNAMES,
+				parms, _poll_vg);
 		if (!parms->outstanding_count)
 			break;
 		sleep(parms->interval);
tools/reporter.c +3 -3
index 3db8b83..ead401b 100644
@@ -370,7 +370,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
 				    &_lvs_single);
 		break;
 	case VGS:
-		r = process_each_vg(cmd, argc, argv, 0,
+		r = process_each_vg(cmd, argc, argv, ENABLE_ALL_VGNAMES,
 				    report_handle, &_vgs_single);
 		break;
 	case LABEL:
@@ -382,7 +382,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
 			r = process_each_pv(cmd, argc, argv, NULL, 0,
 					    0, report_handle, &_pvs_single);
 		else
-			r = process_each_vg(cmd, argc, argv, 0,
+			r = process_each_vg(cmd, argc, argv, ENABLE_ALL_VGNAMES,
 					    report_handle, &_pvs_in_vg);
 		break;
 	case SEGS:
@@ -394,7 +394,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
 			r = process_each_pv(cmd, argc, argv, NULL, 0,
 					    0, report_handle, &_pvsegs_single);
 		else
-			r = process_each_vg(cmd, argc, argv, 0,
+			r = process_each_vg(cmd, argc, argv, ENABLE_ALL_VGNAMES,
 					    report_handle, &_pvsegs_in_vg);
 		break;
 	}
tools/toollib.c +150 -94

265 lines not on this page · raw message

tools/vgcfgbackup.c +1 -1
index 32948d8..84f85cc 100644
@@ -92,7 +92,7 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
 
 	init_pvmove(1);
 
-	ret = process_each_vg(cmd, argc, argv, READ_ALLOW_INCONSISTENT,
+	ret = process_each_vg(cmd, argc, argv, READ_ALLOW_INCONSISTENT | ENABLE_ALL_VGNAMES,
 			      &last_filename, &vg_backup_single);
 
 	dm_free(last_filename);
tools/vgchange.c +7 -1
index ccf31da..d359af0 100644
@@ -538,6 +538,8 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
 
 int vgchange(struct cmd_context *cmd, int argc, char **argv)
 {
+	uint32_t flags = 0;
+
 	/* Update commands that can be combined */
 	int update_partial_safe =
 		arg_count(cmd, deltag_ARG) ||
@@ -618,6 +620,10 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
 	if (!update || !update_partial_unsafe)
 		cmd->handles_missing_pvs = 1;
 
-	return process_each_vg(cmd, argc, argv, update ? READ_FOR_UPDATE : 0,
+	flags = ENABLE_ALL_VGNAMES;
+	if (update)
+		flags |= READ_FOR_UPDATE;
+
+	return process_each_vg(cmd, argc, argv, flags,
 			       NULL, &vgchange_single);
 }
tools/vgck.c +1 -1
index bdfee05..3583ebb 100644
@@ -42,6 +42,6 @@ static int vgck_single(struct cmd_context *cmd __attribute__((unused)),
 
 int vgck(struct cmd_context *cmd, int argc, char **argv)
 {
-	return process_each_vg(cmd, argc, argv, 0, NULL,
+	return process_each_vg(cmd, argc, argv, ENABLE_ALL_VGNAMES, NULL,
 			       &vgck_single);
 }
tools/vgdisplay.c +1 -1
index afc92fe..6efbab7 100644
@@ -88,7 +88,7 @@ int vgdisplay(struct cmd_context *cmd, int argc, char **argv)
 	}
 **********/
 
-	return process_each_vg(cmd, argc, argv, 0, NULL,
+	return process_each_vg(cmd, argc, argv, ENABLE_ALL_VGNAMES, NULL,
 			       vgdisplay_single);
 
 /******** FIXME Need to count number processed
tools/vgexport.c +6 -1
index c573619..26eb4fb 100644
@@ -54,6 +54,8 @@ bad:
 
 int vgexport(struct cmd_context *cmd, int argc, char **argv)
 {
+	uint32_t flags = READ_FOR_UPDATE;
+
 	if (!argc && !arg_count(cmd, all_ARG)) {
 		log_error("Please supply volume groups or use -a for all.");
 		return ECMD_FAILED;
@@ -64,6 +66,9 @@ int vgexport(struct cmd_context *cmd, int argc, char **argv)
 		return ECMD_FAILED;
 	}
 
-	return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
+	if (!argc && arg_count(cmd, all_ARG))
+		flags |= ENABLE_ALL_VGNAMES;
+
+	return process_each_vg(cmd, argc, argv, flags, NULL,
 			       &vgexport_single);
 }
tools/vgscan.c +1 -1
index 99124ef..b960960 100644
@@ -60,7 +60,7 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
 
 	log_print_unless_silent("Reading all physical volumes.  This may take a while...");
 
-	maxret = process_each_vg(cmd, argc, argv, 0, NULL,
+	maxret = process_each_vg(cmd, argc, argv, ENABLE_ALL_VGNAMES, NULL,
 				 &vgscan_single);
 
 	if (arg_count(cmd, mknodes_ARG)) {
Signature · 1 line
1.8.1.rc1.5.g7e0651a