From 622284740a5582533e63a89be4949923ac67845f Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 10 Nov 2023 16:24:45 -0600 Subject: [PATCH] pvs, pvscan: new option -A to show PVs outside the devices file pvs -A|--allpvs Show PVs that would otherwise be excluded by the devices file. pvscan -A|--allpvs Show PVs that would otherwise be excluded by the devices file. For those devices that are included by the devices file, their device ID is displayed in place of the usual "lvm2" format and size. (pvs -a|--all is unchanged, and shows devices not formatted as PVs.) --- lib/cache/lvmcache.c | 8 ++++--- tools/args.h | 8 +++++++ tools/command-lines.in | 4 ++-- tools/pvscan.c | 47 +++++++++++++++++++++++++++++++++++++++++- tools/reporter.c | 5 +++++ 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 0cbe146c1..f20ea4bee 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -3026,9 +3026,11 @@ void lvmcache_get_max_name_lengths(struct cmd_context *cmd, *pv_max_name_len = 0; dm_list_iterate_items(vginfo, &_vginfos) { - len = strlen(vginfo->vgname); - if (*vg_max_name_len < len) - *vg_max_name_len = len; + if (!is_orphan_vg(vginfo->vgname)) { + len = strlen(vginfo->vgname); + if (*vg_max_name_len < len) + *vg_max_name_len = len; + } dm_list_iterate_items(info, &vginfo->infos) { len = strlen(dev_name(info->dev)); diff --git a/tools/args.h b/tools/args.h index 35dfcfd3b..ab548ae03 100644 --- a/tools/args.h +++ b/tools/args.h @@ -1143,6 +1143,14 @@ arg(activevolumegroups_ARG, 'A', "activevolumegroups", 0, 0, 0, "Only select active VGs. The VG is considered active\n" "if at least one of its LVs is active.\n") +arg(allpvs_ARG, 'A', "allpvs", 0, 0, 0, + "#pvs\n" + "Show information about PVs outside the devices file.\n" + "Combine with with -a|--all to include devices that are not PVs.\n" + "#pvscan\n" + "Show information about PVs outside the devices file.\n" + "Displays the device ID for PVs included in the devices file.\n") + arg(background_ARG, 'b', "background", 0, 0, 0, "If the operation requires polling, this option causes the command to\n" "return before the operation is complete, and polling is done in the\n" diff --git a/tools/command-lines.in b/tools/command-lines.in index 633ea2090..b077422a7 100644 --- a/tools/command-lines.in +++ b/tools/command-lines.in @@ -1648,7 +1648,7 @@ ID: pvremove_general --- pvs -OO: --segments, OO_REPORT +OO: --segments, --allpvs, OO_REPORT OP: PV|Tag ... IO: --partial, --ignoreskippedcluster, --trustcache ID: pvs_general @@ -1658,7 +1658,7 @@ RULE: --noheadings not --headings pvscan OO: --ignorelockingfailure, --reportformat ReportFmt, --exported, --novolumegroup, ---short, --uuid +--short, --uuid, --allpvs ID: pvscan_display DESC: Display PV information. diff --git a/tools/pvscan.c b/tools/pvscan.c index 37c67f5d8..a9412b685 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -18,6 +18,7 @@ #include "lib/cache/lvmcache.h" #include "lib/metadata/metadata.h" #include "lib/label/hints.h" +#include "lib/filters/filter.h" #include "lib/device/online.h" #include @@ -88,7 +89,46 @@ static int _pvscan_display_pv(struct cmd_context *cmd, pv_len += suffix_len; } - if (is_orphan(pv)) + if (arg_is_set(cmd, allpvs_ARG)) { + struct device *dev = pv->dev; + if (!cmd->enable_devices_file) { + if (is_orphan(pv)) { + log_print_unless_silent("PV %-*s %-*s", + pv_len, pvdevname, + params->vg_max_name_len, " "); + } else { + log_print_unless_silent("PV %-*s VG %-*s", + pv_len, pvdevname, + params->vg_max_name_len, pv_vg_name(pv)); + } + } else if (!(dev->flags & DEV_MATCHED_USE_ID)) { + if (is_orphan(pv)) { + log_print_unless_silent("PV %-*s %-*s %-10s %s", + pv_len, pvdevname, + params->vg_max_name_len, " ", + "-", "-"); + } else { + log_print_unless_silent("PV %-*s VG %-*s %-10s %s", + pv_len, pvdevname, + params->vg_max_name_len, pv_vg_name(pv), + "-", "-"); + } + } else { + if (is_orphan(pv)) { + log_print_unless_silent("PV %-*s %-*s %-10s %s", + pv_len, pvdevname, + params->vg_max_name_len, " ", + idtype_to_str(dev->id->idtype), + dev->id->idname ?: "none"); + } else { + log_print_unless_silent("PV %-*s VG %-*s %-10s %s", + pv_len, pvdevname, + params->vg_max_name_len, pv_vg_name(pv), + idtype_to_str(dev->id->idtype), + dev->id->idname ?: "none"); + } + } + } else if (is_orphan(pv)) log_print_unless_silent("PV %-*s %-*s %s [%s]", pv_len, pvdevname, params->vg_max_name_len, " ", @@ -150,6 +190,11 @@ int pvscan_display_cmd(struct cmd_context *cmd, int argc, char **argv) arg_is_set(cmd, exported_ARG) ? "of exported volume group(s)" : "in no volume group"); + if (arg_is_set(cmd, allpvs_ARG)) { + cmd->filter_deviceid_skip = 1; + cmd->use_hints = 0; + } + if (!(handle = init_processing_handle(cmd, NULL))) { log_error("Failed to initialize processing handle."); ret = ECMD_FAILED; diff --git a/tools/reporter.c b/tools/reporter.c index 82b39b212..61af33af5 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -1448,6 +1448,11 @@ int pvs(struct cmd_context *cmd, int argc, char **argv) if (arg_is_set(cmd, all_ARG)) cmd->use_hints = 0; + if (arg_is_set(cmd, allpvs_ARG)) { + cmd->filter_deviceid_skip = 1; + cmd->use_hints = 0; + } + if (arg_is_set(cmd, segments_ARG)) type = PVSEGS; else