]> sourceware.org Git - lvm2.git/commitdiff
vgextend: pass single vgname as process_each_vg arg
authorDavid Teigland <teigland@redhat.com>
Mon, 30 Nov 2015 23:00:26 +0000 (17:00 -0600)
committerDavid Teigland <teigland@redhat.com>
Tue, 1 Dec 2015 15:36:45 +0000 (09:36 -0600)
Pass the single vgname as a new process_each_vg arg
instead of setting a cmd flag to tell process_each_vg
to take only the first vgname arg from argv.

Other commands with different argv formats will be
able to use it this way.

16 files changed:
tools/commands.h
tools/polldaemon.c
tools/reporter.c
tools/toollib.c
tools/toollib.h
tools/tools.h
tools/vgcfgbackup.c
tools/vgchange.c
tools/vgck.c
tools/vgconvert.c
tools/vgdisplay.c
tools/vgexport.c
tools/vgextend.c
tools/vgimport.c
tools/vgremove.c
tools/vgscan.c

index b232a7db5a195eb381a2fa2eb22c7ca45101badd..5770bf3eeadf26387447b53abcf22fd02cb41999 100644 (file)
@@ -1214,7 +1214,7 @@ xx(vgexport,
 
 xx(vgextend,
    "Add physical volumes to a volume group",
-   ONE_VGNAME_ARG,
+   0,
    "vgextend\n"
    "\t[-A|--autobackup y|n]\n"
    "\t[--restoremissing]\n"
index ccfaa7d71257328345eb3bf2ac1c000d2a27a098..9172d71ef0a316b598cdb30ee850458821143fb1 100644 (file)
@@ -364,7 +364,7 @@ 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, handle, _poll_vg);
+               process_each_vg(cmd, 0, NULL, NULL, READ_FOR_UPDATE, handle, _poll_vg);
                if (!parms->outstanding_count)
                        break;
                if (parms->interval)
@@ -508,7 +508,7 @@ static void _lvmpolld_poll_for_all_vgs(struct cmd_context *cmd,
 
        handle->custom_handle = &lpdp;
 
-       process_each_vg(cmd, 0, NULL, 0, handle, _lvmpolld_init_poll_vg);
+       process_each_vg(cmd, 0, NULL, NULL, 0, handle, _lvmpolld_init_poll_vg);
 
        first = dm_list_first(&lpdp.idls);
 
index 71f20a309c780dedbf8b2066092ca62331cccfb6..88025ec10c31a84289d73dd68e04d8426896cda3 100644 (file)
@@ -884,7 +884,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, NULL, 0,
                                    &handle, &_vgs_single);
                break;
        case LABEL:
@@ -896,7 +896,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
                        r = process_each_pv(cmd, argc, argv, NULL, 0,
                                            &handle, &_pvs_single);
                else
-                       r = process_each_vg(cmd, argc, argv, 0,
+                       r = process_each_vg(cmd, argc, argv, NULL, 0,
                                            &handle, &_pvs_in_vg);
                break;
        case SEGSSTATUS:
@@ -917,7 +917,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
                                            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,
+                       r = process_each_vg(cmd, argc, argv, NULL, 0,
                                            &handle, &_pvsegs_in_vg);
                break;
        }
index f9794757254241b26a24f7cc6074a29b6d63de18..e49356f127a1e8af97ae4e83b2aa3d72b4b5463d 100644 (file)
@@ -1729,7 +1729,7 @@ int validate_restricted_lvname_param(struct cmd_context *cmd, const char **vg_na
  */
 static int _get_arg_vgnames(struct cmd_context *cmd,
                            int argc, char **argv,
-                           unsigned one_vgname_arg,
+                           const char *one_vgname,
                            struct dm_list *arg_vgnames,
                            struct dm_list *arg_tags)
 {
@@ -1739,15 +1739,19 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
 
        log_verbose("Using volume group(s) on command line.");
 
+       if (one_vgname) {
+               if (!str_list_add(cmd->mem, arg_vgnames,
+                                 dm_pool_strdup(cmd->mem, one_vgname))) {
+                       log_error("strlist allocation failed.");
+                       return ECMD_FAILED;
+               }
+               return ret_max;
+       }
+
        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)
@@ -1769,8 +1773,6 @@ 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;
                }
 
@@ -1779,9 +1781,6 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
                        log_error("strlist allocation failed.");
                        return ECMD_FAILED;
                }
-
-               if (one_vgname_arg)
-                       break;
        }
 
        return ret_max;
@@ -1937,7 +1936,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
                process_all = 1;
 
        /*
-        * FIXME If one_vgname_arg, only proceed if exactly one VG matches tags or selection.
+        * FIXME If one_vgname, only proceed if exactly one VG matches tags or selection.
         */
        dm_list_iterate_items(vgnl, vgnameids_to_process) {
                if (sigint_caught())
@@ -2120,9 +2119,12 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
 
 /*
  * Call process_single_vg() for each VG selected by the command line arguments.
+ * If one_vgname is set, process only that VG and ignore argc/argv (which should be 0/NULL)..
+ * If one_vgname is not set, get VG names to process from argc/argv.
  */
 int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
-                   uint32_t read_flags, struct processing_handle *handle,
+                   const char *one_vgname, uint32_t read_flags,
+                   struct processing_handle *handle,
                    process_single_vg_fn_t process_single_vg)
 {
        int handle_supplied = handle != NULL;
@@ -2131,7 +2133,6 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
        struct dm_list vgnameids_on_system;     /* vgnameid_list */
        struct dm_list vgnameids_to_process;    /* vgnameid_list */
        int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
-       int one_vgname_arg = (cmd->command->flags & ONE_VGNAME_ARG);
        int process_all_vgs_on_system = 0;
        int ret_max = ECMD_PROCESSED;
        int ret;
@@ -2147,7 +2148,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, one_vgname_arg, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) {
+       if ((ret = _get_arg_vgnames(cmd, argc, argv, one_vgname, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) {
                ret_max = ret;
                goto_out;
        }
index 2dc5ad73fee8680bf86e04dadad7f0e5c8780ea2..400bac520506c823b8995bead462c56955c51b29 100644 (file)
@@ -97,7 +97,8 @@ typedef int (*process_single_pvseg_fn_t) (struct cmd_context * cmd,
                                          struct processing_handle *handle);
 
 int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
-                   uint32_t flags, struct processing_handle *handle,
+                   const char *one_vgname, 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,
index 4ed893fc4b3b3394988ae3d7ac79314bd2b31cfa..27061fc94137aa53604709d1a90866a4506c2f36 100644 (file)
@@ -99,8 +99,6 @@ struct arg_value_group_list {
 #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
 /* Command needs a shared lock on a VG; it only reads the VG. */
 #define LOCKD_VG_SH            0x00000020
 /* Command does not process any metadata. */
index 5e80c806adff131ad51546b9891caaefe4e3228b..be4dbb0c8b00ed14f76ddfdb003573145a9369b3 100644 (file)
@@ -94,7 +94,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, NULL, READ_ALLOW_INCONSISTENT,
                              handle, &vg_backup_single);
 
        dm_free(last_filename);
index 81e4bf30f5d0a402da8142f16d3e00960e855017..9e1b09e3cd8043ae0f771c0e4a7caddb23eea71e 100644 (file)
@@ -1227,7 +1227,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
        if (arg_is_set(cmd, lockstart_ARG) || arg_is_set(cmd, lockstop_ARG))
                flags |= READ_ALLOW_EXPORTED;
 
-       ret = process_each_vg(cmd, argc, argv, flags, NULL, &vgchange_single);
+       ret = process_each_vg(cmd, argc, argv, NULL, flags, NULL, &vgchange_single);
 
        /* Wait for lock-start ops that were initiated in vgchange_lockstart. */
 
index 16312891b3ec21085b77316a04d220416a7bd099..b73544b7ec5d8829022461d522bf1eb8696e35a2 100644 (file)
@@ -38,6 +38,6 @@ static int vgck_single(struct cmd_context *cmd __attribute__((unused)),
 int vgck(struct cmd_context *cmd, int argc, char **argv)
 {
        lvmetad_set_active(cmd, 0);
-       return process_each_vg(cmd, argc, argv, 0, NULL,
+       return process_each_vg(cmd, argc, argv, NULL, 0, NULL,
                               &vgck_single);
 }
index c4bb37a23002163d0c21937bd37ab0a47ebe403a..9e6cb57f55375d5e030d836f0702bb7812c3f7ee 100644 (file)
@@ -249,6 +249,6 @@ int vgconvert(struct cmd_context *cmd, int argc, char **argv)
                return EINVALID_CMD_LINE;
        }
 
-       return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
+       return process_each_vg(cmd, argc, argv, NULL, READ_FOR_UPDATE, NULL,
                               &vgconvert_single);
 }
index 1acb3ece772c0aa71af37d532d02bfe8583c70bd..f232a830a509bdcd170d076503f4cf25978af83e 100644 (file)
@@ -89,7 +89,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, NULL, 0, NULL,
                               vgdisplay_single);
 
 /******** FIXME Need to count number processed
index 566cc96e48d3a18ae0d3281af222de3ab9f2c658..59ad1231dbac6c3aab5bd6b1c0b55e26a4c1a2e2 100644 (file)
@@ -80,6 +80,6 @@ int vgexport(struct cmd_context *cmd, int argc, char **argv)
                return EINVALID_CMD_LINE;
        }
 
-       return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
+       return process_each_vg(cmd, argc, argv, NULL, READ_FOR_UPDATE, NULL,
                               &vgexport_single);
 }
index bddc22f92bd1cf0e9dc9e13ce095714834617ee3..a747113d2724de0ca60cbcc3eff8de4e2ec71adf 100644 (file)
@@ -129,6 +129,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
        struct vgextend_params vp;
        unsigned restoremissing = arg_is_set(cmd, restoremissing_ARG);
        struct processing_handle *handle;
+       const char *one_vgname;
        int ret;
 
        if (!argc) {
@@ -137,6 +138,8 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
                return EINVALID_CMD_LINE;
        }
 
+       one_vgname = skip_dev_dir(cmd, argv[0], NULL);
+
        if (arg_count(cmd, metadatacopies_ARG)) {
                log_error("Invalid option --metadatacopies, "
                          "use --pvmetadatacopies instead.");
@@ -169,7 +172,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
        if (!lockd_gl(cmd, "ex", 0))
                return_ECMD_FAILED;
 
-       ret = process_each_vg(cmd, argc, argv,
+       ret = process_each_vg(cmd, 0, NULL, one_vgname,
                              READ_FOR_UPDATE, handle,
                              restoremissing ? &_vgextend_restoremissing : &_vgextend_single);
 
index 04a59dce5afd3da831802baebe2a91cfb53e6b71..9e27ca3cbd85bef9d2e46795ef76c9c72ae1bf6d 100644 (file)
@@ -98,7 +98,7 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)
                return ECMD_FAILED;
        }
 
-       return process_each_vg(cmd, argc, argv,
+       return process_each_vg(cmd, argc, argv, NULL,
                               READ_FOR_UPDATE | READ_ALLOW_EXPORTED,
                               NULL,
                               &vgimport_single);
index 219149ee0f3e605a3b8e5520ea3087b047d6a8cc..3bf2b7045e0f6c47b2146bff07b18b159359a05b 100644 (file)
@@ -109,7 +109,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
        cmd->lockd_gl_disable = 1;
 
        cmd->handles_missing_pvs = 1;
-       ret = process_each_vg(cmd, argc, argv,
+       ret = process_each_vg(cmd, argc, argv, NULL,
                              READ_FOR_UPDATE,
                              NULL, &vgremove_single);
 
index 7328a096d8544f63f83082b7b29b05ad2150b058..45841ec4c495acd2f2755121d658e02deec0a73d 100644 (file)
@@ -62,7 +62,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, NULL, 0, NULL,
                                 &vgscan_single);
 
        if (arg_count(cmd, mknodes_ARG)) {
This page took 0.066767 seconds and 5 git commands to generate.