]> sourceware.org Git - lvm2.git/commitdiff
toollib: replace void *handle with struct processing_handle for use in processing...
authorPeter Rajnoha <prajnoha@redhat.com>
Thu, 27 Nov 2014 14:02:13 +0000 (15:02 +0100)
committerPeter Rajnoha <prajnoha@redhat.com>
Tue, 10 Feb 2015 15:05:24 +0000 (16:05 +0100)
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).

22 files changed:
lib/report/report.h
tools/lvchange.c
tools/lvconvert.c
tools/lvdisplay.c
tools/lvscan.c
tools/polldaemon.c
tools/pvdisplay.c
tools/pvresize.c
tools/reporter.c
tools/toollib.c
tools/toollib.h
tools/vgcfgbackup.c
tools/vgchange.c
tools/vgck.c
tools/vgconvert.c
tools/vgdisplay.c
tools/vgexport.c
tools/vgimport.c
tools/vgmknodes.c
tools/vgreduce.c
tools/vgremove.c
tools/vgscan.c

index 563f684e18c66e5ba81012442e3f2a816b9e25a0..aef6d7258a1b033ab936488b0a5bed92f38ae00b 100644 (file)
@@ -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;
 
index 8a175e033c374768c4aff938bc0f575c8279f13b..17e977f7bf6b5c7d66b09a9682f46837b88a7094 100644 (file)
@@ -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;
index 20f017aa38d10d2310a7882acb56168bc978b11b..f9f666d449a4afb2e163d3148686847d38029d14 100644 (file)
@@ -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);
index fb3420a56013b7a314c0c27afafc65681f8e7557..6b1540f54d9249ba11ff5a4048d862fcb328371c 100644 (file)
@@ -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);
        }
index 2d7be074b367e63f69399a05862db9a49dd98a5d..fa9d976948fffe934633f30d75c7738ff1b7c14f 100644 (file)
@@ -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;
index 8d5c6babb89ecf52416405551ab3fb6b1d140e3b..3eb9b178a6c6e5f5eafeaafc45fdb980ae49517f 100644 (file)
@@ -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);
index 50522d9c2ec1ce74965190ed587121ea61745a08..94a3bbf65ec479dfffed640b2c346330c6027be6 100644 (file)
@@ -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);
index 631e63e0b138ecf9efbb9c9be2e107090f9cf6c4..a2f6b8bf4cad7b187c81264c63b3f57bdcc23604 100644 (file)
@@ -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) "
index 7517ac5bfee7168c59fee6b0196ae762ecb125af..3d7e5ddd6dd542968a68c550fb83c5001e84d7c4 100644 (file)
 #include "tools.h"
 #include "report.h"
 
-static int _process_each_devtype(struct cmd_context *cmd, int argc, void *handle)
+static int _process_each_devtype(struct cmd_context *cmd, int argc,
+                                struct processing_handle *handle)
 {
        if (argc)
                log_warn("WARNING: devtypes currently ignores command line arguments.");
 
-       if (!report_devtypes(handle))
+       if (!report_devtypes(handle->custom_handle))
                return_ECMD_FAILED;
 
        return ECMD_PROCESSED;
@@ -29,9 +30,9 @@ static int _process_each_devtype(struct cmd_context *cmd, int argc, void *handle
 
 static int _vgs_single(struct cmd_context *cmd __attribute__((unused)),
                       const char *vg_name, struct volume_group *vg,
-                      void *handle)
+                      struct processing_handle *handle)
 {
-       if (!report_object(handle, vg, NULL, NULL, NULL, NULL, NULL, NULL))
+       if (!report_object(handle->custom_handle, vg, NULL, NULL, NULL, NULL, NULL, NULL))
                return_ECMD_FAILED;
 
        check_current_backup(vg);
@@ -85,7 +86,7 @@ static int _do_info_and_status(struct cmd_context *cmd,
 static int _do_lvs_with_info_and_status_single(struct cmd_context *cmd,
                                               const struct logical_volume *lv,
                                               int do_info, int do_status,
-                                              void *handle)
+                                              struct processing_handle *handle)
 {
        struct lv_with_info_and_seg_status status = {
                .seg_status.type = SEG_STATUS_NONE
@@ -95,9 +96,9 @@ static int _do_lvs_with_info_and_status_single(struct cmd_context *cmd,
        if (!_do_info_and_status(cmd, lv, NULL, &status, do_info, do_status))
                goto_out;
 
-       if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL,
-                          &status, NULL))
-               goto_out;
+       if (!report_object(handle->custom_handle, lv->vg, lv,
+                          NULL, NULL, NULL, &status, NULL))
+               goto out;
 
        r = ECMD_PROCESSED;
 out:
@@ -108,25 +109,25 @@ out:
 }
 
 static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
-                      void *handle)
+                      struct processing_handle *handle)
 {
        return _do_lvs_with_info_and_status_single(cmd, lv, 0, 0, handle);
 }
 
 static int _lvs_with_info_single(struct cmd_context *cmd, struct logical_volume *lv,
-                                void *handle)
+                                struct processing_handle *handle)
 {
        return _do_lvs_with_info_and_status_single(cmd, lv, 1, 0, handle);
 }
 
 static int _lvs_with_status_single(struct cmd_context *cmd, struct logical_volume *lv,
-                                  void *handle)
+                                  struct processing_handle *handle)
 {
        return _do_lvs_with_info_and_status_single(cmd, lv, 0, 1, handle);
 }
 
 static int _lvs_with_info_and_status_single(struct cmd_context *cmd, struct logical_volume *lv,
-                                           void *handle)
+                                           struct processing_handle *handle)
 {
        return _do_lvs_with_info_and_status_single(cmd, lv, 1, 1, handle);
 }
@@ -134,7 +135,7 @@ static int _lvs_with_info_and_status_single(struct cmd_context *cmd, struct logi
 static int _do_segs_with_info_and_status_single(struct cmd_context *cmd,
                                                const struct lv_segment *seg,
                                                int do_info, int do_status,
-                                               void *handle)
+                                               struct processing_handle *handle)
 {
        struct lv_with_info_and_seg_status status = {
                .seg_status.type = SEG_STATUS_NONE
@@ -144,7 +145,7 @@ static int _do_segs_with_info_and_status_single(struct cmd_context *cmd,
        if (!_do_info_and_status(cmd, seg->lv, seg, &status, do_info, do_status))
                goto_out;
 
-       if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL,
+       if (!report_object(handle->custom_handle, seg->lv->vg, seg->lv, NULL, seg, NULL,
                           &status, NULL))
                goto_out;
 
@@ -157,31 +158,31 @@ out:
 }
 
 static int _segs_single(struct cmd_context *cmd, struct lv_segment *seg,
-                       void *handle)
+                       struct processing_handle *handle)
 {
        return _do_segs_with_info_and_status_single(cmd, seg, 0, 0, handle);
 }
 
 static int _segs_with_info_single(struct cmd_context *cmd, struct lv_segment *seg,
-                                 void *handle)
+                                 struct processing_handle *handle)
 {
        return _do_segs_with_info_and_status_single(cmd, seg, 1, 0, handle);
 }
 
 static int _segs_with_status_single(struct cmd_context *cmd, struct lv_segment *seg,
-                                   void *handle)
+                                   struct processing_handle *handle)
 {
        return _do_segs_with_info_and_status_single(cmd, seg, 0, 1, handle);
 }
 
 static int _segs_with_info_and_status_single(struct cmd_context *cmd, struct lv_segment *seg,
-                                            void *handle)
+                                            struct processing_handle *handle)
 {
        return _do_segs_with_info_and_status_single(cmd, seg, 1, 1, handle);
 }
 
 static int _lvsegs_single(struct cmd_context *cmd, struct logical_volume *lv,
-                         void *handle)
+                         struct processing_handle *handle)
 {
        if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
@@ -190,7 +191,7 @@ static int _lvsegs_single(struct cmd_context *cmd, struct logical_volume *lv,
 }
 
 static int _lvsegs_with_info_single(struct cmd_context *cmd, struct logical_volume *lv,
-                                   void *handle)
+                                   struct processing_handle *handle)
 {
        if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
@@ -199,7 +200,7 @@ static int _lvsegs_with_info_single(struct cmd_context *cmd, struct logical_volu
 }
 
 static int _lvsegs_with_status_single(struct cmd_context *cmd, struct logical_volume *lv,
-                                     void *handle)
+                                     struct processing_handle *handle)
 {
        if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
@@ -208,7 +209,7 @@ static int _lvsegs_with_status_single(struct cmd_context *cmd, struct logical_vo
 }
 
 static int _lvsegs_with_info_and_status_single(struct cmd_context *cmd, struct logical_volume *lv,
-                                              void *handle)
+                                              struct processing_handle *handle)
 {
        if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
@@ -221,7 +222,7 @@ static int _do_pvsegs_sub_single(struct cmd_context *cmd,
                                 struct pv_segment *pvseg,
                                 int do_info,
                                 int do_status,
-                                void *handle)
+                                struct processing_handle *handle)
 {
        int ret = ECMD_PROCESSED;
        struct lv_segment *seg = pvseg->lvseg;
@@ -267,8 +268,8 @@ static int _do_pvsegs_sub_single(struct cmd_context *cmd,
        if (seg && !_do_info_and_status(cmd, seg->lv, seg, &status, do_info, do_status))
                goto_out;
 
-       if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
-                          seg ? : &_free_lv_segment, pvseg, &status,
+       if (!report_object(handle->custom_handle, vg, seg ? seg->lv : &_free_logical_volume,
+                          pvseg->pv, seg ? : &_free_lv_segment, pvseg, &status,
                           pv_label(pvseg->pv))) {
                ret = ECMD_FAILED;
                goto_out;
@@ -284,7 +285,7 @@ static int _do_pvsegs_sub_single(struct cmd_context *cmd,
 static int _pvsegs_sub_single(struct cmd_context *cmd,
                              struct volume_group *vg,
                              struct pv_segment *pvseg,
-                             void *handle)
+                             struct processing_handle *handle)
 {
        return _do_pvsegs_sub_single(cmd, vg, pvseg, 0, 0, handle);
 }
@@ -292,7 +293,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
 static int _pvsegs_with_lv_info_sub_single(struct cmd_context *cmd,
                                           struct volume_group *vg,
                                           struct pv_segment *pvseg,
-                                          void *handle)
+                                          struct processing_handle *handle)
 {
        return _do_pvsegs_sub_single(cmd, vg, pvseg, 1, 0, handle);
 }
@@ -300,7 +301,7 @@ static int _pvsegs_with_lv_info_sub_single(struct cmd_context *cmd,
 static int _pvsegs_with_lv_status_sub_single(struct cmd_context *cmd,
                                             struct volume_group *vg,
                                             struct pv_segment *pvseg,
-                                            void *handle)
+                                            struct processing_handle *handle)
 {
        return _do_pvsegs_sub_single(cmd, vg, pvseg, 0, 1, handle);
 }
@@ -308,7 +309,7 @@ static int _pvsegs_with_lv_status_sub_single(struct cmd_context *cmd,
 static int _pvsegs_with_lv_info_and_status_sub_single(struct cmd_context *cmd,
                                                      struct volume_group *vg,
                                                      struct pv_segment *pvseg,
-                                                     void *handle)
+                                                     struct processing_handle *handle)
 {
        return _do_pvsegs_sub_single(cmd, vg, pvseg, 1, 1, handle);
 }
@@ -316,7 +317,7 @@ static int _pvsegs_with_lv_info_and_status_sub_single(struct cmd_context *cmd,
 static int _pvsegs_single(struct cmd_context *cmd,
                          struct volume_group *vg,
                          struct physical_volume *pv,
-                         void *handle)
+                         struct processing_handle *handle)
 {
        return process_each_segment_in_pv(cmd, vg, pv, handle, _pvsegs_sub_single);
 }
@@ -324,7 +325,7 @@ static int _pvsegs_single(struct cmd_context *cmd,
 static int _pvsegs_with_lv_info_single(struct cmd_context *cmd,
                                       struct volume_group *vg,
                                       struct physical_volume *pv,
-                                      void *handle)
+                                      struct processing_handle *handle)
 {
        return process_each_segment_in_pv(cmd, vg, pv, handle, _pvsegs_with_lv_info_sub_single);
 }
@@ -332,7 +333,7 @@ static int _pvsegs_with_lv_info_single(struct cmd_context *cmd,
 static int _pvsegs_with_lv_status_single(struct cmd_context *cmd,
                                         struct volume_group *vg,
                                         struct physical_volume *pv,
-                                        void *handle)
+                                        struct processing_handle *handle)
 {
        return process_each_segment_in_pv(cmd, vg, pv, handle, _pvsegs_with_lv_status_sub_single);
 }
@@ -340,24 +341,25 @@ static int _pvsegs_with_lv_status_single(struct cmd_context *cmd,
 static int _pvsegs_with_lv_info_and_status_single(struct cmd_context *cmd,
                                                  struct volume_group *vg,
                                                  struct physical_volume *pv,
-                                                 void *handle)
+                                                 struct processing_handle *handle)
 {
        return process_each_segment_in_pv(cmd, vg, pv, handle, _pvsegs_with_lv_info_and_status_sub_single);
 }
 
 static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
-                      struct physical_volume *pv, void *handle)
+                      struct physical_volume *pv,
+                      struct processing_handle *handle)
 {
-       if (!report_object(handle, vg, NULL, pv, NULL, NULL, NULL, NULL))
+       if (!report_object(handle->custom_handle, vg, NULL, pv, NULL, NULL, NULL, NULL))
                return_ECMD_FAILED;
 
        return ECMD_PROCESSED;
 }
 
 static int _label_single(struct cmd_context *cmd, struct label *label,
-                        void *handle)
+                        struct processing_handle *handle)
 {
-       if (!report_object(handle, NULL, NULL, NULL, NULL, NULL, NULL, label))
+       if (!report_object(handle->custom_handle, NULL, NULL, NULL, NULL, NULL, NULL, label))
                return_ECMD_FAILED;
 
        return ECMD_PROCESSED;
@@ -365,7 +367,7 @@ static int _label_single(struct cmd_context *cmd, struct label *label,
 
 static int _pvs_in_vg(struct cmd_context *cmd, const char *vg_name,
                      struct volume_group *vg,
-                     void *handle)
+                     struct processing_handle *handle)
 {
        int skip;
 
@@ -380,7 +382,7 @@ static int _pvs_in_vg(struct cmd_context *cmd, const char *vg_name,
 
 static int _pvsegs_in_vg(struct cmd_context *cmd, const char *vg_name,
                         struct volume_group *vg,
-                        void *handle)
+                        struct processing_handle *handle)
 {
        int skip;
 
@@ -397,6 +399,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
                   report_type_t report_type)
 {
        void *report_handle;
+       struct processing_handle handle = {0};
        const char *opts;
        char *str;
        const char *keys = NULL, *options = NULL, *selection = NULL, *separator;
@@ -565,9 +568,12 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
                }
        }
 
+       handle.internal_report_for_select = 0;
+       handle.custom_handle = report_handle;
+
        switch (report_type) {
        case DEVTYPES:
-               r = _process_each_devtype(cmd, argc, report_handle);
+               r = _process_each_devtype(cmd, argc, &handle);
                break;
        case LVSINFO:
                /* fall through */
@@ -576,7 +582,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
        case LVSINFOSTATUS:
                /* fall through */
        case LVS:
-               r = process_each_lv(cmd, argc, argv, 0, report_handle,
+               r = process_each_lv(cmd, argc, argv, 0, &handle,
                                    lv_info_needed && !lv_segment_status_needed ? &_lvs_with_info_single :
                                    !lv_info_needed && lv_segment_status_needed ? &_lvs_with_status_single :
                                    lv_info_needed && lv_segment_status_needed ? &_lvs_with_info_and_status_single :
@@ -584,24 +590,24 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
                break;
        case VGS:
                r = process_each_vg(cmd, argc, argv, 0,
-                                   report_handle, &_vgs_single);
+                                   &handle, &_vgs_single);
                break;
        case LABEL:
                r = process_each_label(cmd, argc, argv,
-                                      report_handle, &_label_single);
+                                      &handle, &_label_single);
                break;
        case PVS:
                if (args_are_pvs)
                        r = process_each_pv(cmd, argc, argv, NULL, 0,
-                                           report_handle, &_pvs_single);
+                                           &handle, &_pvs_single);
                else
                        r = process_each_vg(cmd, argc, argv, 0,
-                                           report_handle, &_pvs_in_vg);
+                                           &handle, &_pvs_in_vg);
                break;
        case SEGSSTATUS:
                /* fall through */
        case SEGS:
-               r = process_each_lv(cmd, argc, argv, 0, report_handle,
+               r = process_each_lv(cmd, argc, argv, 0, &handle,
                                    lv_info_needed && !lv_segment_status_needed ? &_lvsegs_with_info_single :
                                    !lv_info_needed && lv_segment_status_needed ? &_lvsegs_with_status_single :
                                    lv_info_needed && lv_segment_status_needed ? &_lvsegs_with_info_and_status_single :
@@ -610,14 +616,14 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
        case PVSEGS:
                if (args_are_pvs)
                        r = process_each_pv(cmd, argc, argv, NULL, 0,
-                                           report_handle,
+                                           &handle,
                                            lv_info_needed && !lv_segment_status_needed ? &_pvsegs_with_lv_info_single :
                                            !lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_status_single :
                                            lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_info_and_status_single :
                                                                                         &_pvsegs_single);
                else
                        r = process_each_vg(cmd, argc, argv, 0,
-                                           report_handle, &_pvsegs_in_vg);
+                                           &handle, &_pvsegs_in_vg);
                break;
        }
 
index c634b175cbfd19aacb29293dda9276f8ed3cdabe..759769edb3fdc21be5e2c9e814d90ba50b4e6731 100644 (file)
@@ -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
index 56259fb708c19102842825b8a1f3cb482bf9f075..cc862276e236904125e48d648006e8590458503d 100644 (file)
 #define _LVM_TOOLLIB_H
 
 #include "metadata-exported.h"
+#include "report.h"
 
 int become_daemon(struct cmd_context *cmd, int skip_lvm);
 
 int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsistent, int *skip);
 
+/*
+ * The "struct processing_handle" is used as a handle for processing
+ * functions (process_each_* and related).
+ *
+ * The "custom_handle" is any handle used to pass custom data into
+ * process_each_* and related functions.
+ *
+ * The "internal_report_for_select=0" makes processing function to
+ * skip checking the report/selection criteria (if given on cmd line)
+ * before executing the action on the item.
+ *
+ * The "selection_handle" is only used if "internal_report_for_select=1".
+ *
+ * Some important notes about selection:
+ * =====================================
+ * In case we're processing for display, the selection is directly
+ * a part of reporting for the display on output so we don't need to
+ * report the item in memory to get the selection result, then dropping
+ * the report and then reporting the same thing again for it to be
+ * displayed on output.
+ * For example, compare these code paths:
+ *
+ *   - when reporting for display on output:
+ *      _report -> process_each_* -> ... -> dm_report_object
+ *      (Here the dm_report_object does both selection and
+ *       reporting for display on output.)
+ *
+ *   - for any other processing and reporting for selection:
+ *      process_each_* -> _select_match_* -> ... -> dm_report_object_is_selected
+ *                                                            |
+ *                                                            --> (selection result) --> ...
+ *      (Here the dm_report_object_is_selected just gets
+ *       the selection result and it drops reporting buffer
+ *       immediately. Then based on the selection result,
+ *       the process_each_* action on the item is executed
+ *       or not...)
+ *
+ * Simply, we want to avoid this double reporting when reporting
+ * for display on output:
+ *     _report -> process_each_* -> _select_match_* -> ... -> dm_report_object_is_selected
+ *                                                                      |
+ *                                                                      --> (selection result) -> dm_report_object
+ *
+ * So whenever the processing action is "to display item on output", use
+ * "internal_report_for_select=0" as report/selection is already
+ * a part of that reporting for display (dm_report_object).
+ */
+struct processing_handle {
+       int internal_report_for_select;
+       struct selection_handle *selection_handle;
+       void *custom_handle;
+};
+
 typedef int (*process_single_vg_fn_t) (struct cmd_context * cmd,
                                       const char *vg_name,
                                       struct volume_group * vg,
-                                      void *handle);
+                                      struct processing_handle *handle);
 typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd,
                                  struct volume_group *vg,
                                  struct physical_volume *pv,
-                                 void *handle);
+                                 struct processing_handle *handle);
 typedef int (*process_single_label_fn_t) (struct cmd_context *cmd,
                                          struct label *label,
-                                         void *handle);
+                                         struct processing_handle *handle);
 typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd,
                                  struct logical_volume *lv,
-                                 void *handle);
+                                 struct processing_handle *handle);
 typedef int (*process_single_seg_fn_t) (struct cmd_context * cmd,
                                        struct lv_segment * seg,
-                                       void *handle);
+                                       struct processing_handle *handle);
 typedef int (*process_single_pvseg_fn_t) (struct cmd_context * cmd,
                                          struct volume_group * vg,
                                          struct pv_segment * pvseg,
-                                         void *handle);
+                                         struct processing_handle *handle);
 
 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);
 
 int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
                    const char *vg_name, uint32_t lock_type,
-                   void *handle, process_single_pv_fn_t process_single_pv);
+                   struct processing_handle *handle,
+                   process_single_pv_fn_t process_single_pv);
 
 int process_each_label(struct cmd_context *cmd, int argc, char **argv,
-                      void *handle, process_single_label_fn_t process_single_label);
+                      struct processing_handle *handle,
+                      process_single_label_fn_t process_single_label);
 
 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);
 
 int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
-                   uint32_t flags, void *handle,
+                   uint32_t flags, struct processing_handle *handle,
                    process_single_lv_fn_t process_single_lv);
 
 
 int process_each_segment_in_lv(struct cmd_context *cmd,
-                              struct logical_volume *lv, void *handle,
+                              struct logical_volume *lv,
+                              struct processing_handle *handle,
                               process_single_seg_fn_t process_single_seg);
 
 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 process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
                          struct dm_list *arg_lvnames, const struct dm_list *tagsl,
-                         int stop_on_error, void *handle,
+                         int stop_on_error, struct processing_handle *handle,
                          process_single_lv_fn_t process_single_lv);
 
 int select_match_vg(struct cmd_context *cmd, struct volume_group *vg,
@@ -145,6 +203,6 @@ int validate_restricted_lvname_param(struct cmd_context *cmd, const char **vg_na
                                     const char **lv_name);
 
 int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
-                    void *handle __attribute__((unused)));
+                    struct processing_handle *handle __attribute__((unused)));
 
 #endif
index 7cf19bc283798ad8b6be472308cd34309d1a27e5..ee65f180c4533c51dba0e66655746c7f3db6f295 100644 (file)
@@ -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);
 
index e5d700de8c0ad5f9783b0066e58b58777cd46ea6..e3f852b8dafc3584269e8f30688ff8f3be1e415f 100644 (file)
@@ -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;
index b9d05ae1c756a711bb930bf0d1969984edc47fc6..16312891b3ec21085b77316a04d220416a7bd099 100644 (file)
@@ -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;
index 10893441c3627fbce5db2a623fd95e7762aaf07a..50b3e44a9f16508966b8968a8aa0434d30d55427 100644 (file)
@@ -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;
index 59d741ad820113527529b5e6b2d2650b31feac79..3c34727e68d46c87d38461d5043e12045c1e0984 100644 (file)
@@ -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;
index d9f8efadc14c407ed7d68d384d71088f4566eabb..aeff612e1fc4bf49698b19836390567293bb84ab 100644 (file)
@@ -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;
 
index 7cb93378f3b156dc1774fcc4e2bdd1f0bdebe291..857f4a9fcfeafc65c50d1d40ddaf9cd09fe71119 100644 (file)
@@ -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;
index 9ba06778f98da2149a42cf3218763fbdcb12e163..92eb2d0d10d9162860a5fc68071123a30b31d9e1 100644 (file)
@@ -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))
index 7af5a7683f4719e88275a05655e1b1313ab2098e..0adf1bb854937d2c514bb63d061e7c35840f743d 100644 (file)
@@ -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;
 
index 1dce41f24bda141edddddf2bb98d1b90bc556dac..315e1dcfb49d914cc56d0a11d275ae4b81295da7 100644 (file)
@@ -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
index bca98cc6ea3163b038fcd1bb9ea7b1918d40a20f..b3af9bca0cdf54564ea558f6aabfaf63b439e614 100644 (file)
@@ -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,
This page took 0.086419 seconds and 5 git commands to generate.