summaryrefslogtreecommitdiff
path: root/tools/lvmdevices.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2022-04-06 12:29:26 -0500
committerDavid Teigland <teigland@redhat.com>2022-04-06 12:51:34 -0500
commitfb7698b0ce47b965db056022cad712a965554f3a (patch)
treebbac231a31b407d349a5cb8a2cda540dcaa4ee1e /tools/lvmdevices.c
parent151ce8b27672134438d0bc457f49123db96a176c (diff)
downloadlvm2-fb7698b0ce47b965db056022cad712a965554f3a.tar.gz
lvmdevices: --deldev using device id
When used with --deviceidtype, --deldev can specify a device id to remove.
Diffstat (limited to 'tools/lvmdevices.c')
-rw-r--r--tools/lvmdevices.c47
1 files changed, 46 insertions, 1 deletions
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 };