Skip to contentSkip to conversation

master - toollib: replace void *handle with struct processing_handle for use in processing functions (process_each_*/process_single_* and related)

PATCH Peter Rajnoha 1 participant 1 message Feb 10, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=51d96a170314b7ce75f233d42501262805384770
Commit:        51d96a170314b7ce75f233d42501262805384770
Parent:        2a19866a74c5101d262586ad0e08317e9a514977
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Thu Nov 27 15:02:13 2014 +0100
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Tue Feb 10 16:05:24 2015 +0100

toollib: replace void *handle with struct processing_handle for use in processing functions (process_each_*/process_single_* and related)

This patch replaces "void *handle" with "struct processing_handle *handle" in process_each_*, process_single_* and related functions.

The struct processing_handle consists of two handles inside now:

- the "struct selection_handle *selection_handle" used for applying selection criteria while processing process_each_*, process_single_* and related functions (patches using this logic will follow)

- the "void* custom_handle" (this is actually the original handle used before this patch - a pointer to custom data passed into process_each_*, process_single_* and related functions).

---
 lib/report/report.h |   25 ++++++++++++
 tools/lvchange.c    |    2 +-
 tools/lvconvert.c   |   10 +++-
 tools/lvdisplay.c   |    4 +-
 tools/lvscan.c      |    2 +-
 tools/polldaemon.c  |   10 +++-
 tools/pvdisplay.c   |    5 +-
 tools/pvresize.c    |    9 +++-
 tools/reporter.c    |  102 +++++++++++++++++++++++++++------------------------
 tools/toollib.c     |   33 +++++++++-------
 tools/toollib.h     |   88 ++++++++++++++++++++++++++++++++++++-------
 tools/vgcfgbackup.c |    9 +++-
 tools/vgchange.c    |    2 +-
 tools/vgck.c        |    2 +-
 tools/vgconvert.c   |    2 +-
 tools/vgdisplay.c   |    2 +-
 tools/vgexport.c    |    2 +-
 tools/vgimport.c    |    2 +-
 tools/vgmknodes.c   |    2 +-
 tools/vgreduce.c    |    2 +-
 tools/vgremove.c    |    2 +-
 tools/vgscan.c      |    2 +-
 22 files changed, 214 insertions(+), 105 deletions(-)
lib/report/report.h +25 -0
index 563f684e18..aef6d72 100644
@@ -34,6 +34,31 @@ typedef enum {
 	DEVTYPES	= 1024
 } report_type_t;
 
+/*
+ * The "struct selection_handle" is used only for selection
+ * of items that should be processed further (not for display!).
+ *
+ * It consists of selection reporting handle "selection_rh"
+ * used for the selection itself (not for display on output!).
+ * The items are reported directly in memory to a buffer and
+ * then compared against selection criteria. Once we know the
+ * result of the selection, the buffer is dropped!
+ *
+ * The "orig_report_type" is the original requested report type.
+ * The "report_type" is the reporting type actually used which
+ * also counts with report types of the fields used in selection
+ * criteria.
+ *
+ * The "selected" variable is used for propagating the result
+ * of the selection.
+ */
+struct selection_handle {
+	struct dm_report *selection_rh;
+	report_type_t orig_report_type;
+	report_type_t report_type;
+	int selected;
+};
+
 struct field;
 struct report_handle;
 
tools/lvchange.c +1 -1
index 8a175e0..17e977f 100644
@@ -848,7 +848,7 @@ static int lvchange_activation_skip(struct logical_volume *lv)
 
 
 static int _lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
-			   void *handle __attribute__((unused)))
+			   struct processing_handle *handle __attribute__((unused)))
 {
 	int doit = 0, docmds = 0;
 	struct logical_volume *origin;
tools/lvconvert.c +7 -3
index 20f017a..f9f666d 100644
@@ -3486,9 +3486,9 @@ out:
 }
 
 static int _lvconvert_merge_single(struct cmd_context *cmd, struct logical_volume *lv,
-				  void *handle)
+				   struct processing_handle *handle)
 {
-	struct lvconvert_params *lp = handle;
+	struct lvconvert_params *lp = (struct lvconvert_params *) handle->custom_handle;
 	const char *vg_name;
 	struct logical_volume *refreshed_lv;
 	int ret;
@@ -3542,13 +3542,17 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
 		.target_attr = ~0,
 	};
 
+	struct processing_handle handle = { .internal_report_for_select = 1,
+					    .selection_handle = NULL,
+					    .custom_handle = &lp };
+
 	if (!_read_params(cmd, argc, argv, &lp)) {
 		stack;
 		return EINVALID_CMD_LINE;
 	}
 
 	if (lp.merge)
-		return process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &lp,
+		return process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &handle,
 				       &_lvconvert_merge_single);
 
 	return lvconvert_single(cmd, &lp);
tools/lvdisplay.c +2 -2
index fb3420a..6b1540f 100644
@@ -16,7 +16,7 @@
 #include "tools.h"
 
 static int _lvdisplay_single(struct cmd_context *cmd, struct logical_volume *lv,
-			     void *handle)
+			     struct processing_handle *handle __attribute__ ((unused)))
 {
 	if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
 		return ECMD_PROCESSED;
@@ -24,7 +24,7 @@ static int _lvdisplay_single(struct cmd_context *cmd, struct logical_volume *lv,
 	if (arg_count(cmd, colon_ARG))
 		lvdisplay_colons(lv);
 	else {
-		lvdisplay_full(cmd, lv, handle);
+		lvdisplay_full(cmd, lv, NULL);
 		if (arg_count(cmd, maps_ARG))
 			lvdisplay_segments(lv);
 	}
tools/lvscan.c +1 -1
index 2d7be07..fa9d976 100644
@@ -48,7 +48,7 @@ static int _lvscan_single_lvmetad(struct cmd_context *cmd, struct logical_volume
 }
 
 static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,
-			 void *handle __attribute__((unused)))
+			 struct processing_handle *handle __attribute__((unused)))
 {
 	struct lvinfo info;
 	int inkernel, snap_active = 1;
tools/polldaemon.c +7 -3
index 8d5c6ba..3eb9b17 100644
@@ -189,9 +189,9 @@ static int _wait_for_single_lv(struct cmd_context *cmd, const char *name, const
 }
 
 static int _poll_vg(struct cmd_context *cmd, const char *vgname,
-		    struct volume_group *vg, void *handle)
+		    struct volume_group *vg, struct processing_handle *handle)
 {
-	struct daemon_parms *parms = (struct daemon_parms *) handle;
+	struct daemon_parms *parms = (struct daemon_parms *) handle->custom_handle;
 	struct lv_list *lvl;
 	struct logical_volume *lv;
 	const char *name;
@@ -229,9 +229,13 @@ static int _poll_vg(struct cmd_context *cmd, const char *vgname,
 static void _poll_for_all_vgs(struct cmd_context *cmd,
 			      struct daemon_parms *parms)
 {
+	struct processing_handle handle = { .internal_report_for_select = 1,
+					    .selection_handle = NULL,
+					    .custom_handle = parms };
+
 	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, &handle, _poll_vg);
 		if (!parms->outstanding_count)
 			break;
 		sleep(parms->interval);
tools/pvdisplay.c +3 -2
index 50522d9..94a3bbf 100644
@@ -17,7 +17,8 @@
 
 static int _pvdisplay_single(struct cmd_context *cmd,
 			     struct volume_group *vg,
-			     struct physical_volume *pv, void *handle)
+			     struct physical_volume *pv,
+			     struct processing_handle *handle __attribute__((unused)))
 {
 	const char *pv_name = pv_dev_name(pv);
 	int ret = ECMD_PROCESSED;
@@ -48,7 +49,7 @@ static int _pvdisplay_single(struct cmd_context *cmd,
 		goto out;
 	}
 
-	pvdisplay_full(cmd, pv, handle);
+	pvdisplay_full(cmd, pv, NULL);
 
 	if (arg_count(cmd, maps_ARG))
 		pvdisplay_segments(pv);
tools/pvresize.c +6 -3
index 631e63e..a2f6b8b 100644
@@ -26,9 +26,9 @@ struct pvresize_params {
 static int _pvresize_single(struct cmd_context *cmd,
 			    struct volume_group *vg,
 			    struct physical_volume *pv,
-			    void *handle)
+			    struct processing_handle *handle)
 {
-	struct pvresize_params *params = (struct pvresize_params *) handle;
+	struct pvresize_params *params = (struct pvresize_params *) handle->custom_handle;
 
 	if (!params) {
 		log_error(INTERNAL_ERROR "Invalid resize params.");
@@ -47,6 +47,9 @@ static int _pvresize_single(struct cmd_context *cmd,
 int pvresize(struct cmd_context *cmd, int argc, char **argv)
 {
 	struct pvresize_params params;
+	struct processing_handle handle = { .internal_report_for_select = 1,
+					    .selection_handle = NULL,
+					    .custom_handle = &params };
 	int ret;
 
 	if (!argc) {
@@ -65,7 +68,7 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv)
 	params.done = 0;
 	params.total = 0;
 
-	ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, &params,
+	ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, &handle,
 			      _pvresize_single);
 
 	log_print_unless_silent("%d physical volume(s) resized / %d physical volume(s) "
tools/reporter.c +54 -48

344 lines not on this page · raw message

tools/toollib.c +19 -14
index c634b17..759769e 100644
@@ -203,7 +203,7 @@ int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsiste
 int process_each_segment_in_pv(struct cmd_context *cmd,
 			       struct volume_group *vg,
 			       struct physical_volume *pv,
-			       void *handle,
+			       struct processing_handle *handle,
 			       process_single_pvseg_fn_t process_single_pvseg)
 {
 	struct pv_segment *pvseg;
@@ -235,7 +235,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
 
 int process_each_segment_in_lv(struct cmd_context *cmd,
 			       struct logical_volume *lv,
-			       void *handle,
+			       struct processing_handle *handle,
 			       process_single_seg_fn_t process_single_seg)
 {
 	struct lv_segment *seg;
@@ -1236,7 +1236,8 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,
 	return 1;
 }
 
-int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *handle,
+int process_each_label(struct cmd_context *cmd, int argc, char **argv,
+		       struct processing_handle *handle,
 		       process_single_label_fn_t process_single_label)
 {
 	struct label *label;
@@ -1564,7 +1565,8 @@ int select_match_pv(struct cmd_context *cmd, struct volume_group *vg,
 static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
 				  struct dm_list *vgnameids_to_process,
 				  struct dm_list *arg_vgnames,
-				  struct dm_list *arg_tags, void *handle,
+				  struct dm_list *arg_tags,
+				  struct processing_handle *handle,
 				  process_single_vg_fn_t process_single_vg)
 {
 	struct volume_group *vg;
@@ -1657,7 +1659,7 @@ static int _copy_str_to_vgnameid_list(struct cmd_context *cmd, struct dm_list *s
  * Call process_single_vg() for each VG selected by the command line arguments.
  */
 int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
-		    uint32_t flags, void *handle,
+		    uint32_t flags, struct processing_handle *handle,
 		    process_single_vg_fn_t process_single_vg)
 {
 	struct dm_list arg_tags;		/* str_list */
@@ -1716,7 +1718,8 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
 int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
 			  struct dm_list *arg_lvnames, const struct dm_list *tags_in,
 			  int stop_on_error,
-			  void *handle, process_single_lv_fn_t process_single_lv)
+			  struct processing_handle *handle,
+			  process_single_lv_fn_t process_single_lv)
 {
 	int ret_max = ECMD_PROCESSED;
 	int ret = 0;
@@ -1939,7 +1942,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
 				     struct dm_list *arg_vgnames,
 				     struct dm_list *arg_lvnames,
 				     struct dm_list *arg_tags,
-				     void *handle,
+				     struct processing_handle *handle,
 				     process_single_lv_fn_t process_single_lv)
 {
 	struct volume_group *vg;
@@ -2023,7 +2026,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
  * Call process_single_lv() for each LV selected by the command line arguments.
  */
 int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t flags,
-		    void *handle, process_single_lv_fn_t process_single_lv)
+		    struct processing_handle *handle, process_single_lv_fn_t process_single_lv)
 {
 	struct dm_list arg_tags;		/* str_list */
 	struct dm_list arg_vgnames;		/* str_list */
@@ -2219,7 +2222,8 @@ static struct device_id_list *_device_list_find_pvid(struct dm_list *devices, st
 }
 
 static int _process_device_list(struct cmd_context *cmd, struct dm_list *all_devices,
-				void *handle, process_single_pv_fn_t process_single_pv)
+				struct processing_handle *handle,
+				process_single_pv_fn_t process_single_pv)
 {
 	struct physical_volume pv_dummy;
 	struct physical_volume *pv;
@@ -2260,7 +2264,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
 			      int process_all_pvs,
 			      int process_all_devices,
 			      int skip,
-			      void *handle,
+			      struct processing_handle *handle,
 			      process_single_pv_fn_t process_single_pv)
 {
 	struct physical_volume *pv;
@@ -2423,7 +2427,7 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t flags,
 			       struct dm_list *arg_tags,
 			       int process_all_pvs,
 			       int process_all_devices,
-			       void *handle,
+			       struct processing_handle *handle,
 			       process_single_pv_fn_t process_single_pv)
 {
 	struct volume_group *vg;
@@ -2480,7 +2484,7 @@ int process_each_pv(struct cmd_context *cmd,
 		    int argc, char **argv,
 		    const char *only_this_vgname,
 		    uint32_t flags,
-		    void *handle,
+		    struct processing_handle *handle,
 		    process_single_pv_fn_t process_single_pv)
 {
 	struct dm_list arg_tags;	/* str_list */
@@ -2570,7 +2574,8 @@ out:
 }
 
 int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
-			  void *handle, process_single_pv_fn_t process_single_pv)
+			  struct processing_handle *handle,
+			  process_single_pv_fn_t process_single_pv)
 {
 	int ret_max = ECMD_PROCESSED;
 	int ret;
@@ -2591,7 +2596,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
 }
 
 int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
-		    void *handle __attribute__((unused)))
+		    struct processing_handle *handle __attribute__((unused)))
 {
 	/*
 	 * Single force is equivalent to single --yes
tools/toollib.h +73 -15

145 lines not on this page · raw message

tools/vgcfgbackup.c +6 -3
index 7cf19bc..ee65f18 100644
@@ -49,9 +49,9 @@ static char *_expand_filename(const char *template, const char *vg_name,
 
 static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
 			    struct volume_group *vg,
-			    void *handle)
+			    struct processing_handle *handle)
 {
-	char **last_filename = (char **)handle;
+	char **last_filename = (char **)handle->custom_handle;
 	char *filename;
 
 	if (arg_count(cmd, file_ARG)) {
@@ -83,11 +83,14 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
 {
 	int ret;
 	char *last_filename = NULL;
+	struct processing_handle handle = { .internal_report_for_select = 1,
+					    .selection_handle = NULL,
+					    .custom_handle = &last_filename };
 
 	init_pvmove(1);
 
 	ret = process_each_vg(cmd, argc, argv, READ_ALLOW_INCONSISTENT,
-			      &last_filename, &vg_backup_single);
+			      &handle, &vg_backup_single);
 
 	dm_free(last_filename);
 
tools/vgchange.c +1 -1
index e5d700d..e3f852b 100644
@@ -473,7 +473,7 @@ static int _vgchange_profile(struct cmd_context *cmd,
 
 static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
 			   struct volume_group *vg,
-			   void *handle __attribute__((unused)))
+			   struct processing_handle *handle __attribute__((unused)))
 {
 	int ret = ECMD_PROCESSED;
 	unsigned i;
tools/vgck.c +1 -1
index b9d05ae..1631289 100644
@@ -18,7 +18,7 @@
 static int vgck_single(struct cmd_context *cmd __attribute__((unused)),
 		       const char *vg_name,
 		       struct volume_group *vg,
-		       void *handle __attribute__((unused)))
+		       struct processing_handle *handle __attribute__((unused)))
 {
 	if (!vg_check_status(vg, EXPORTED_VG))
 		return_ECMD_FAILED;
tools/vgconvert.c +1 -1
index 1089344..50b3e44 100644
@@ -17,7 +17,7 @@
 
 static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
 			    struct volume_group *vg,
-			    void *handle __attribute__((unused)))
+			    struct processing_handle *handle __attribute__((unused)))
 {
 	struct physical_volume *pv, *existing_pv;
 	struct pvcreate_restorable_params rp;
tools/vgdisplay.c +1 -1
index 59d741a..3c34727 100644
@@ -17,7 +17,7 @@
 
 static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name,
 			    struct volume_group *vg,
-			    void *handle __attribute__((unused)))
+			    struct processing_handle *handle __attribute__((unused)))
 {
 	if (arg_count(cmd, activevolumegroups_ARG) && !lvs_in_vg_activated(vg))
 		return ECMD_PROCESSED;
tools/vgexport.c +1 -1
index d9f8efa..aeff612 100644
@@ -18,7 +18,7 @@
 static int vgexport_single(struct cmd_context *cmd __attribute__((unused)),
 			   const char *vg_name,
 			   struct volume_group *vg,
-			   void *handle __attribute__((unused)))
+			   struct processing_handle *handle __attribute__((unused)))
 {
 	struct pv_list *pvl;
 
tools/vgimport.c +1 -1
index 7cb9337..857f4a9 100644
@@ -18,7 +18,7 @@
 static int vgimport_single(struct cmd_context *cmd __attribute__((unused)),
 			   const char *vg_name,
 			   struct volume_group *vg,
-			   void *handle __attribute__((unused)))
+			   struct processing_handle *handle __attribute__((unused)))
 {
 	struct pv_list *pvl;
 	struct physical_volume *pv;
tools/vgmknodes.c +1 -1
index 9ba0677..92eb2d0 100644
@@ -16,7 +16,7 @@
 #include "tools.h"
 
 static int _vgmknodes_single(struct cmd_context *cmd, struct logical_volume *lv,
-			     void *handle __attribute__((unused)))
+			     struct processing_handle *handle __attribute__((unused)))
 {
 	if (arg_count(cmd, refresh_ARG) && lv_is_visible(lv))
 		if (!lv_refresh(cmd, lv))
tools/vgreduce.c +1 -1
index 7af5a76..0adf1bb 100644
@@ -123,7 +123,7 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
 /* Or take pv_name instead? */
 static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
 			    struct physical_volume *pv,
-			    void *handle __attribute__((unused)))
+			    struct processing_handle *handle __attribute__((unused)))
 {
 	int r;
 
tools/vgremove.c +1 -1
index 1dce41f..315e1dc 100644
@@ -17,7 +17,7 @@
 
 static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
 			   struct volume_group *vg,
-			   void *handle __attribute__((unused)))
+			   struct processing_handle *handle __attribute__((unused)))
 {
 	/*
 	 * Single force is equivalent to sinle --yes
tools/vgscan.c +1 -1
index bca98cc..b3af9bc 100644
@@ -17,7 +17,7 @@
 
 static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
 			 struct volume_group *vg,
-			 void *handle __attribute__((unused)))
+			 struct processing_handle *handle __attribute__((unused)))
 {
 	log_print_unless_silent("Found %svolume group \"%s\" using metadata type %s",
 				vg_is_exported(vg) ? "exported " : "", vg_name,