From 0101886ba42b8e95a923fc35999e9ad2bd449fc9 Mon Sep 17 00:00:00 2001 From: Alexander Parenkov Date: Tue, 22 Oct 2024 16:50:49 +0300 Subject: [PATCH] vgreduce: enable --select option with --removemissing Calling vgreduce with --removemissing option results in an error if there is more than one volume group with the passed name. The error message suggests using volume group UUID in place of the name; however, there is no way to do so. This allows passing volume group UUID via --select option --- tools/command-lines.in | 4 ++-- tools/commands.h | 2 +- tools/vgreduce.c | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/command-lines.in b/tools/command-lines.in index ada6b2c38..5e18b93fd 100644 --- a/tools/command-lines.in +++ b/tools/command-lines.in @@ -1943,8 +1943,8 @@ OO: OO_VGREDUCE ID: vgreduce_all DESC: Remove all unused PVs from a VG. -vgreduce --removemissing VG -OO: --mirrorsonly, OO_VGREDUCE +vgreduce --removemissing VG|Select +OO: --mirrorsonly, OO_VGREDUCE, --select String ID: vgreduce_missing DESC: Remove all missing PVs from a VG. diff --git a/tools/commands.h b/tools/commands.h index 1d01c725f..34a7aa476 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -229,7 +229,7 @@ xx(vgmknodes, xx(vgreduce, "Remove physical volume(s) from a volume group", - 0) + ALL_VGS_IS_DEFAULT) xx(vgremove, "Remove volume group(s)", diff --git a/tools/vgreduce.c b/tools/vgreduce.c index f500b553a..e0950f31c 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -176,7 +176,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) { struct processing_handle *handle; struct vgreduce_params vp = { 0 }; - const char *vg_name; + const char *vg_name = NULL; int repairing = arg_is_set(cmd, removemissing_ARG); int saved_ignore_suspended_devices = ignore_suspended_devices(); int ret; @@ -187,7 +187,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - if (!argc) { /* repairing */ + if (!argc && !arg_is_set(cmd, select_ARG)) { /* repairing */ log_error("Please give volume group name."); return EINVALID_CMD_LINE; } @@ -213,9 +213,12 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - vg_name = skip_dev_dir(cmd, argv[0], NULL); - argv++; - argc--; + if (argc) + { + vg_name = skip_dev_dir(cmd, argv[0], NULL); + argv++; + argc--; + } if (!lock_global(cmd, "ex")) return_ECMD_FAILED;