diff options
author | David Teigland <teigland@redhat.com> | 2022-04-06 12:29:26 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2022-04-06 12:51:34 -0500 |
commit | fb7698b0ce47b965db056022cad712a965554f3a (patch) | |
tree | bbac231a31b407d349a5cb8a2cda540dcaa4ee1e /tools | |
parent | 151ce8b27672134438d0bc457f49123db96a176c (diff) | |
download | lvm2-fb7698b0ce47b965db056022cad712a965554f3a.tar.gz |
lvmdevices: --deldev using device id
When used with --deviceidtype, --deldev can specify
a device id to remove.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/args.h | 8 | ||||
-rw-r--r-- | tools/command-lines.in | 3 | ||||
-rw-r--r-- | tools/lvmdevices.c | 47 |
3 files changed, 54 insertions, 4 deletions
diff --git a/tools/args.h b/tools/args.h index 03fe24556..c4d8fe7ff 100644 --- a/tools/args.h +++ b/tools/args.h @@ -46,8 +46,12 @@ arg(addtag_ARG, '\0', "addtag", tag_VAL, ARG_GROUPABLE, 0, arg(adddev_ARG, '\0', "adddev", pv_VAL, 0, 0, "Add a device to the devices file.\n") -arg(deldev_ARG, '\0', "deldev", pv_VAL, 0, 0, - "Remove a device from the devices file.\n") + +arg(deldev_ARG, '\0', "deldev", string_VAL, 0, 0, + "Remove a device from the devices file.\n" + "When used alone, --deldev specifies a device name.\n" + "When used with --deviceidtype, --deldev specifies a device id.\n") + arg(addpvid_ARG, '\0', "addpvid", string_VAL, 0, 0, "Find a device with the PVID and add the device to the devices file.\n") arg(delpvid_ARG, '\0', "delpvid", string_VAL, 0, 0, diff --git a/tools/command-lines.in b/tools/command-lines.in index 6f431e233..ce350e95c 100644 --- a/tools/command-lines.in +++ b/tools/command-lines.in @@ -1434,7 +1434,8 @@ OO: --deviceidtype String ID: lvmdevices_edit DESC: Add a device to the devices file. -lvmdevices --deldev PV +lvmdevices --deldev PV|String +OO: --deviceidtype String ID: lvmdevices_edit DESC: Remove a device from the devices file. diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c index b03411b8b..04f707519 100644 --- a/tools/lvmdevices.c +++ b/tools/lvmdevices.c @@ -416,12 +416,15 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv) goto out; } - if (arg_is_set(cmd, deldev_ARG)) { + if (arg_is_set(cmd, deldev_ARG) && !arg_is_set(cmd, deviceidtype_ARG)) { const char *devname; if (!(devname = arg_str_value(cmd, deldev_ARG, NULL))) goto_bad; + if (strncmp(devname, "/dev/", 5)) + log_warn("WARNING: to remove a device by device id, include --deviceidtype."); + /* * No filter because we always want to allow removing a device * by name from the devices file. @@ -453,6 +456,48 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv) goto out; } + /* + * By itself, --deldev <devname> specifies a device name to remove. + * With an id type specified, --deldev specifies a device id to remove: + * --deldev <idname> --deviceidtype <idtype> + */ + if (arg_is_set(cmd, deldev_ARG) && arg_is_set(cmd, deviceidtype_ARG)) { + const char *idtype_str = arg_str_value(cmd, deviceidtype_ARG, NULL); + const char *idname = arg_str_value(cmd, deldev_ARG, NULL); + int idtype; + + if (!idtype_str || !idname || !strlen(idname) || !strlen(idtype_str)) + goto_bad; + + if (!(idtype = idtype_from_str(idtype_str))) { + log_error("Unknown device_id type."); + goto_bad; + } + + if (!strncmp(idname, "/dev/", 5)) + log_warn("WARNING: to remove a device by name, do not include --deviceidtype."); + + if (!(du = get_du_for_device_id(cmd, idtype, idname))) { + log_error("No devices file entry with device id %s %s.", idtype_str, idname); + goto_bad; + } + + dev = du->dev; + + if (dev && dev_is_used_by_active_lv(cmd, dev, NULL, NULL, NULL, NULL)) { + if (!arg_count(cmd, yes_ARG) && + yes_no_prompt("Device %s is used by an active LV, continue to remove? ", dev_name(dev)) == 'n') { + log_error("Device not removed."); + goto bad; + } + } + + dm_list_del(&du->list); + free_du(du); + device_ids_write(cmd); + goto out; + } + if (arg_is_set(cmd, delpvid_ARG)) { struct id id; char pvid[ID_LEN+1] = { 0 }; |