1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
David Teigland 2015-12-01 12:00:57 -06:00
parent 67763a9bec
commit 166adf0e1f

View 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