Skip to contentSkip to conversation

Add 'flags' parameter to process_each_lv and process_each_lv_in_vg.

PATCH New Dave Wysochanski 1 participant 2 messages Sep 25, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add 'flags' parameter to process_each_lv and process_each_lv_in_vg.

No functional change.

---
 tools/lvchange.c  |    2 +-
 tools/lvdisplay.c |    2 +-
 tools/lvremove.c  |    2 +-
 tools/lvscan.c    |    2 +-
 tools/reporter.c  |    8 ++++----
 tools/toollib.c   |    8 +++++---
 tools/toollib.h   |    6 ++++--
 tools/vgdisplay.c |    3 ++-
 tools/vgmknodes.c |    2 +-
 9 files changed, 20 insertions(+), 15 deletions(-)
tools/lvchange.c +1 -1
index 4016c8f..299abd8 100644
@@ -732,5 +732,5 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	return process_each_lv(cmd, argc, argv, LCK_VG_WRITE, NULL,
-			       &lvchange_single);
+			       &lvchange_single, 0);
 }
tools/lvdisplay.c +1 -1
index 16e7052..b896b4b 100644
@@ -55,5 +55,5 @@ int lvdisplay(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	return process_each_lv(cmd, argc, argv, LCK_VG_READ, NULL,
-			       &_lvdisplay_single);
+			       &_lvdisplay_single, 0);
 }
tools/lvremove.c +1 -1
index 24278b2..c219d54 100644
@@ -34,5 +34,5 @@ int lvremove(struct cmd_context *cmd, int argc, char **argv)
 	cmd->handles_missing_pvs = 1;
 
 	return process_each_lv(cmd, argc, argv, LCK_VG_WRITE, NULL,
-			       &lvremove_single);
+			       &lvremove_single, 0);
 }
tools/lvscan.c +1 -1
index f63d05f..a493112 100644
@@ -81,5 +81,5 @@ int lvscan(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	return process_each_lv(cmd, argc, argv, LCK_VG_READ, NULL,
-			       &lvscan_single);
+			       &lvscan_single, 0);
 }
tools/reporter.c +4 -4
index 5c35a0c..518c649 100644
@@ -349,8 +349,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
 
 	switch (report_type) {
 	case LVS:
-		r = process_each_lv(cmd, argc, argv, LCK_VG_READ, report_handle,
-				    &_lvs_single);
+		r = process_each_lv(cmd, argc, argv, LCK_VG_READ,
+				    report_handle, &_lvs_single, 0);
 		break;
 	case VGS:
 		r = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0,
@@ -365,8 +365,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
 					    report_handle, &_pvs_in_vg);
 		break;
 	case SEGS:
-		r = process_each_lv(cmd, argc, argv, LCK_VG_READ, report_handle,
-				    &_lvsegs_single);
+		r = process_each_lv(cmd, argc, argv, LCK_VG_READ,
+				    report_handle, &_lvsegs_single, 0);
 		break;
 	case PVSEGS:
 		if (args_are_pvs)
tools/toollib.c +5 -3
index 4d11b9b..e0b7f2f 100644
@@ -143,7 +143,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
 			  const struct list *arg_lvnames,
 			  const struct list *tags,
 			  void *handle,
-			  process_single_lv_fn_t process_single)
+			  process_single_lv_fn_t process_single,
+	                  const uint32_t flags)
 {
 	int ret_max = ECMD_PROCESSED;
 	int ret = 0;
@@ -220,7 +221,8 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 		    uint32_t lock_type, void *handle,
 		    int (*process_single) (struct cmd_context * cmd,
 					   struct logical_volume * lv,
-					   void *handle))
+					   void *handle),
+	            const uint32_t flags)
 {
 	int opt = 0;
 	int ret_max = ECMD_PROCESSED;
@@ -399,7 +401,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 		}
 
 		ret = process_each_lv_in_vg(cmd, vg, &lvnames, tags_arg,
-					    handle, process_single);
+					    handle, process_single, flags);
 		unlock_vg(cmd, vgname);
 		if (ret > ret_max)
 			ret_max = ret;
tools/toollib.h +4 -2
index ef2b9db..44c5fbd 100644
@@ -52,7 +52,8 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 		    uint32_t lock_type, void *handle,
 		    int (*process_single) (struct cmd_context * cmd,
 					   struct logical_volume * lv,
-					   void *handle));
+					   void *handle),
+		    const uint32_t flags);
 
 int process_each_segment_in_lv(struct cmd_context *cmd,
 			       struct logical_volume *lv, void *handle,
@@ -78,7 +79,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
 			  const struct list *arg_lvnames,
 			  const struct list *tags,
 			  void *handle,
-			  process_single_lv_fn_t process_single);
+			  process_single_lv_fn_t process_single,
+			  const uint32_t flags);
 
 char *default_vgname(struct cmd_context *cmd);
 const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
tools/vgdisplay.c +2 -1
index 532cc18..6cfc1ed 100644
@@ -46,7 +46,8 @@ static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name,
 		vgdisplay_extents(vg);
 
 		process_each_lv_in_vg(cmd, vg, NULL, NULL, NULL,
-				      (process_single_lv_fn_t)lvdisplay_full);
+				      (process_single_lv_fn_t)lvdisplay_full,
+				      0);
 
 		log_print("--- Physical volumes ---");
 		process_each_pv_in_vg(cmd, vg, NULL, NULL,
tools/vgmknodes.c +1 -1
index cb5b279..2d1f37e 100644
@@ -29,7 +29,7 @@ int vgmknodes(struct cmd_context *cmd, int argc, char **argv)
 	int r;
 
 	r = process_each_lv(cmd, argc, argv, LCK_VG_READ, NULL,
-			    &_vgmknodes_single);
+			    &_vgmknodes_single, 0);
 
 	if (!lv_mknodes(cmd, NULL) && (r < ECMD_FAILED))
 		r = ECMD_FAILED;
Signature · 1 line
1.5.5.1
#1 lore raw

PATCH 2/2 Add 'PROCESS_ONLY_VISIBLE_LVS' flag to modify LV iteration functions.

Fixes rhbz 232499: 'lvchange -a' w/VG arg causes "Unable" msgs for hidden LVs

---
 tools/lvchange.c |    2 +-
 tools/toollib.c  |    9 +++++++++
 tools/toollib.h  |   11 +++++++++++
 3 files changed, 21 insertions(+), 1 deletions(-)
tools/lvchange.c +1 -1
index 299abd8..e541158 100644
@@ -732,5 +732,5 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	return process_each_lv(cmd, argc, argv, LCK_VG_WRITE, NULL,
-			       &lvchange_single, 0);
+			       &lvchange_single, PROCESS_ONLY_VISIBLE_LVS);
 }
tools/toollib.c +9 -0
index e0b7f2f..34cf0ce 100644
@@ -179,6 +179,15 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
 		if (lvl->lv->status & SNAPSHOT)
 			continue;
 
+		/*
+		 * If no LVs given on the cmdline, this is not a visible LV,
+		 * and we should process only visible ones, then skip this LV.
+		 */
+		if (!lvargs_supplied && 
+		    !lv_is_visible(lvl->lv) &&
+		    (flags & PROCESS_ONLY_VISIBLE_LVS))
+			continue;
+
 		/* Should we process this LV? */
 		if (process_all)
 			process_lv = 1;
tools/toollib.h +11 -0
index 44c5fbd..de748c7 100644
@@ -18,6 +18,17 @@
 
 #include "metadata-exported.h"
 
+/* Flags that modify iterator function behavior */
+/*
+ * Indicates whether we should process only visible LVs when looping
+ * through a list of LVs on a VG.
+ * NOTE: This does not apply if a hidden/non-visible LV is given on the
+ * commandline for a tool, only if another option is given (e.g. a VG) that
+ * implies a list of LVs and the tools need to make a decision.
+ */
+#define PROCESS_ONLY_VISIBLE_LVS 0x1
+
+
 int autobackup_set(void);
 int autobackup_init(const char *backup_dir, int keep_days, int keep_number,
 		    int autobackup);
Signature · 1 line
1.5.5.1