]> sourceware.org Git - lvm2.git/commitdiff
toollib: allow VG UUID to be used in place of VG name
authorDavid Teigland <teigland@redhat.com>
Tue, 1 Dec 2015 18:00:57 +0000 (12:00 -0600)
committerDavid Teigland <teigland@redhat.com>
Tue, 1 Dec 2015 18:08:24 +0000 (12:08 -0600)
If the VG arg from the command line does not match the
name of any known VGs, then check if the arg looks like
a UUID.  If it's a valid UUID, then compare it to the
UUID of known VGs.  If it matches the UUID of a known VG,
then process that VG.

tools/toollib.c

index e49356f127a1e8af97ae4e83b2aa3d72b4b5463d..8e4db5e19623b2efb8e76b69460e89d4c586d141 100644 (file)
@@ -2077,8 +2077,11 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
                                   struct dm_list *vgnameids_on_system,
                                   struct dm_list *vgnameids_to_process)
 {
+       char uuid[64] __attribute__((aligned(8)));
        struct dm_str_list *sl, *sl2;
        struct vgnameid_list *vgnl, *vgnl2;
+       struct id id;
+       int arg_is_uuid;
        int found;
 
        dm_list_iterate_items_safe(sl, sl2, arg_vgnames) {
@@ -2092,6 +2095,42 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
                        found = 1;
                        break;
                }
+
+               /*
+                * If the VG name arg looks like a UUID, then check if it
+                * matches the UUID of a VG.
+                *
+                * FIXME: Do we want to allow vgname args to be interpretted
+                * as uuids for all commands or only some (e.g. vgrename)?
+                * If only some, then use a cmd flag to enable this.
+                */
+               if (!found) {
+                       log_suppress(2);
+                       arg_is_uuid = id_read_format(&id, sl->str);
+                       log_suppress(0);
+               }
+
+               if (!found && arg_is_uuid) {
+                       dm_list_iterate_items_safe(vgnl, vgnl2, vgnameids_on_system) {
+                               if (!(id_write_format((const struct id*)vgnl->vgid, uuid, sizeof(uuid))))
+                                       continue;
+
+                               if (strcmp(sl->str, uuid))
+                                       continue;
+
+                               log_print("Processing VG %s because of matching UUID %s",
+                                         vgnl->vg_name, uuid);
+
+                               dm_list_del(&vgnl->list);
+                               dm_list_add(vgnameids_to_process, &vgnl->list);
+
+                               /* Make the arg_vgnames entry use the actual VG name. */
+                               sl->str = dm_pool_strdup(cmd->mem, vgnl->vg_name);
+
+                               found = 1;
+                               break;
+                       }
+               }
                
                /*
                 * If the name arg was not found in the list of all VGs, then
This page took 0.044874 seconds and 5 git commands to generate.