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

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.)
This commit is contained in:
David Teigland 2023-11-10 16:24:45 -06:00
parent 29c0763480
commit 622284740a
5 changed files with 66 additions and 6 deletions

View File

@ -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));

View File

@ -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"

View File

@ -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.

View File

@ -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 <dirent.h>
@ -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;

View File

@ -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