From: David Teigland Date: Tue, 1 Dec 2015 18:00:57 +0000 (-0600) Subject: toollib: allow VG UUID to be used in place of VG name X-Git-Tag: v2_02_137~16 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=166adf0e1fb01f0557a068086a73d9d40f9e5652;p=lvm2.git toollib: allow VG UUID to be used in place of VG name 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. --- diff --git a/tools/toollib.c b/tools/toollib.c index e49356f12..8e4db5e19 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -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