1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-10-21 15:33:18 +03:00

Compare commits

..

1 Commits

Author SHA1 Message Date
David Teigland
7b8098e749 pvscan: add options listlvs listvg checkcomplete
pvscan --cache <dev>
    . read only dev
    . create online file for dev

pvscan --listvg <dev>
    . read only dev
    . list VG using dev

pvscan --listlvs <dev>
    . read only dev
    . list VG using dev
    . list LVs using dev

pvscan --cache --listvg [--checkcomplete] <dev>
    . read only dev
    . create online file for dev
    . list VG using dev
    . [check online files and report if VG is complete]

pvscan --cache --listlvs [--checkcomplete] <dev>
    . read only dev
    . create online file for dev
    . list VG using dev
    . list LVs using dev
    . [check online files and report if VG is complete]
    . [check online files and report if LVs are complete]

[--vgonline]
can be used with --checkcomplete, to enable use of a vg online
file.  This results in only the first pvscan command to see
the complete VG to report 'VG complete', and others will report
'VG finished'.  This allows the caller to easily run a single
activation of the VG.

The list of complete LVs is meant to be passed to lvchange -aay,
or the complete VG used with vgchange -aay.

Example of listlvs
------------------

$ lvs -a vg -olvname,devices
  LV     Devices
  lv_a   /dev/loop0(0)
  lv_ab  /dev/loop0(1),/dev/loop1(1)
  lv_abc /dev/loop0(3),/dev/loop1(3),/dev/loop2(1)
  lv_b   /dev/loop1(0)
  lv_c   /dev/loop2(0)

$ pvscan --cache --listlvs --checkcomplete /dev/loop0
  pvscan[35680] PV /dev/loop0 online, VG vg incomplete (need 2).
  VG vg incomplete
  LV vg/lv_a complete
  LV vg/lv_ab incomplete
  LV vg/lv_abc incomplete

$ pvscan --cache --listlvs --checkcomplete /dev/loop1
  pvscan[35681] PV /dev/loop1 online, VG vg incomplete (need 1).
  VG vg incomplete
  LV vg/lv_b complete
  LV vg/lv_ab complete
  LV vg/lv_abc incomplete

$ pvscan --cache --listlvs --checkcomplete /dev/loop2
  pvscan[35682] PV /dev/loop2 online, VG vg is complete.
  VG vg complete
  LV vg/lv_c complete
  LV vg/lv_abc complete

Example of listvg
-----------------

$ pvscan --cache --listvg --checkcomplete /dev/loop0
  pvscan[35684] PV /dev/loop0 online, VG vg incomplete (need 2).
  VG vg incomplete

$ pvscan --cache --listvg --checkcomplete /dev/loop1
  pvscan[35685] PV /dev/loop1 online, VG vg incomplete (need 1).
  VG vg incomplete

$ pvscan --cache --listvg --checkcomplete /dev/loop2
  pvscan[35686] PV /dev/loop2 online, VG vg is complete.
  VG vg complete
2020-12-16 15:15:13 -06:00
3 changed files with 47 additions and 22 deletions

View File

@@ -850,6 +850,10 @@ arg(vgmetadatacopies_ARG, '\0', "vgmetadatacopies", vgmetadatacopies_VAL, 0, 0,
"\\fBall\\fP causes LVM to first clear the metadataignore flags on\n"
"all PVs, and then to become unmanaged.\n")
arg(vgonline_ARG, '\0', "vgonline", 0, 0, 0,
"The first command to see the complete VG will report it uniquely.\n"
"Other commands to see the complete VG will report it differently.\n")
arg(withsummary_ARG, '\0', "withsummary", 0, 0, 0,
"Display a one line comment for each configuration node.\n")

View File

@@ -1581,15 +1581,15 @@ OO: --ignorelockingfailure, --reportformat ReportFmt,
OP: PV|String ...
IO: --background
ID: pvscan_cache
DESC: Record that a PV is online and autoactivate VG if complete.
DESC: Record that a PV is online and autoactivate the VG if complete.
pvscan --cache_long --listvg PV
OO: --ignorelockingfailure, --checkcomplete
OO: --ignorelockingfailure, --checkcomplete, --vgonline
ID: pvscan_cache
DESC: Record that a PV is online and list the VG using the PV.
pvscan --cache_long --listlvs PV
OO: --ignorelockingfailure, --checkcomplete
OO: --ignorelockingfailure, --checkcomplete, --vgonline
ID: pvscan_cache
DESC: Record that a PV is online and list LVs using the PV.

View File

@@ -1244,13 +1244,14 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
struct format_instance *fid;
struct metadata_area *mda1, *mda2;
struct volume_group *vg;
const char *vgname;
const char *vgname = NULL;
uint32_t ext_version, ext_flags;
int do_cache = arg_is_set(cmd, cache_long_ARG);
int do_activate = arg_is_set(cmd, activate_ARG);
int list_lvs = arg_is_set(cmd, listlvs_ARG);
int list_vg = arg_is_set(cmd, listvg_ARG);
int check_complete = arg_is_set(cmd, checkcomplete_ARG);
int do_list_lvs = arg_is_set(cmd, listlvs_ARG);
int do_list_vg = arg_is_set(cmd, listvg_ARG);
int do_check_complete = arg_is_set(cmd, checkcomplete_ARG);
int do_vgonline = arg_is_set(cmd, vgonline_ARG);
int pvs_online;
int pvs_offline;
int pvs_unknown;
@@ -1360,7 +1361,7 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
/*
* A plain pvscan --cache <dev> just creates the online file.
*/
if (!do_activate && !list_lvs && !list_vg) {
if (!do_activate && !do_list_lvs && !do_list_vg) {
log_print("pvscan[%d] PV %s online.", getpid(), dev_name(dev));
release_vg(vg);
continue;
@@ -1372,7 +1373,7 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
* complete_vgnames (activation phase will want to know which
* VGs to activate.)
*/
if (do_activate || check_complete) {
if (do_activate || do_check_complete) {
pvs_online = 0;
pvs_offline = 0;
pvs_unknown = 0;
@@ -1429,7 +1430,38 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
if (!vgname && vg)
vgname = vg->name;
if (list_lvs) {
if (do_list_vg || do_list_lvs) {
if (!vgname)
log_print("VG unknown");
else if (!do_check_complete)
log_print("VG %s", vgname);
else if (vg_complete) {
if (do_vgonline && !_online_vg_file_create(cmd, vgname))
log_print("VG %s finished", vgname);
else
log_print("VG %s complete", vgname);
} else {
log_print("VG %s incomplete", vgname);
}
/*
* When the VG is complete|finished, we could print
* a list of devices in the VG, by reading the pvid files
* that were counted, which provides major:minor of each
* device and using that to get the struct dev and dev_name.
* The user could pass this list of devices to --devices
* to optimize a subsequent command (activation) on the VG.
* Just call set_pv_devices_online (if not done othewise)
* since that finds the devs.
*/
}
if (do_list_lvs && !vg) {
/* require all PVs used for booting have metadata */
log_print("Cannot list LVs from device without metadata.");
}
if (do_list_lvs && vg) {
struct dm_list lvs_list;
struct lv_list *lvl;
@@ -1447,7 +1479,7 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
if (!get_visible_lvs_using_pv(cmd, vg, dev, &lvs_list))
log_warn("WARNING: failed to find LVs using %s.", dev_name(dev));
if (!check_complete) {
if (!do_check_complete) {
dm_list_iterate_items(lvl, &lvs_list)
log_print("LV %s", display_lvname(lvl->lv));
} else if (vg_complete) {
@@ -1473,17 +1505,6 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
}
}
if (list_vg) {
if (!vgname)
log_print("VG unknown");
else if (!check_complete)
log_print("VG %s", vgname);
else if (vg_complete)
log_print("VG %s complete", vgname);
else
log_print("VG %s incomplete", vgname);
}
/*
* When "pvscan --cache -aay <dev>" completes the vg, save the
* struct vg to use for quick activation function.