main - pvscan: add options listlvs listvg checkcomplete
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0b6782fa0139e412f827cc9d1f0cd96ea38e27b0 Commit: 0b6782fa0139e412f827cc9d1f0cd96ea38e27b0 Parent: 3e1316bb09b087ec79c9661ead14d8556c36fa8d Author: David Teigland <[email protected]> AuthorDate: Wed Dec 9 10:59:40 2020 -0600 Committer: David Teigland <[email protected]> CommitterDate: Thu Oct 7 12:06:49 2021 -0500
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.
[--udevoutput]
can be used with --cache --listvg --checkcomplete, to enable an output mode that prints LVM_VG_NAME_COMPLETE='vgname' that a udev rule can import, and prevents other output from the command (other output causes udev to ignore the command.)
The list of complete LVs is meant to be passed to lvchange -aay, or the complete VG used with vgchange -aay.
When --checkcomplete is used, lvm assumes that that the output will be used to trigger event-based autoactivation, so the pvscan does nothing if event_activation=0 and --checkcomplete is used.
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 --- lib/commands/toolcontext.h | 1 + lib/metadata/metadata.c | 33 ++++ lib/metadata/metadata.h | 4 + tools/args.h | 20 +++ tools/command-lines.in | 30 +++- tools/lvmcmdline.c | 4 + tools/pvscan.c | 418 ++++++++++++++++++++++++++++++++++----------- tools/toollib.c | 18 ++ tools/tools.h | 2 + 9 files changed, 431 insertions(+), 99 deletions(-)
lib/commands/toolcontext.h +1 -0
@@ -29,6 +29,7 @@ struct config_info {int debug_classes;int verbose;int silent; +int suppress;int test;int yes;int syslog;
lib/metadata/metadata.c +33 -0
@@ -5279,3 +5279,36 @@ struct volume_group *vg_read_for_update(struct cmd_context *cmd, const char *vg_return vg; } + +int get_visible_lvs_using_pv (struct cmd_context *cmd,struct volume_group *vg,struct device *dev, +struct dm_list *lvs_list) +{ +struct pv_list *pvl; +struct lv_list *lvl, *lvl2; +struct physical_volume *pv =NULL ; + + dm_list_iterate_items(pvl, &vg->pvs) { +if (pvl->pv->dev == dev) { + pv = pvl->pv; +break ; + } + } + +if (!pv) + return_0; + + dm_list_iterate_items(lvl, &vg->lvs) { +if (!lv_is_visible (lvl->lv)) +continue ; +if (!lv_is_on_pv (lvl->lv, pv)) +continue ; + +if (!(lvl2 =dm_pool_zalloc (cmd->mem,sizeof (*lvl2)))) + return_0; + lvl2->lv = lvl->lv; +dm_list_add (lvs_list, &lvl2->list); + } + +return 1 ; +} +
lib/metadata/metadata.h +4 -0
@@ -535,4 +535,8 @@ char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tagsl);void set_pv_devices (struct format_instance *fid,struct volume_group *vg); +int get_visible_lvs_using_pv (struct cmd_context *cmd,struct volume_group *vg,struct device *dev, +struct dm_list *lvs_list); + +#endif
tools/args.h +20 -0
@@ -329,6 +329,19 @@ arg(labelsector_ARG, '\0', "labelsector", number_VAL, 0, 0, "start of the disk (between 0 and 3 inclusive - see LABEL_SCAN_SECTORS\n" "in the source). Use with care.\n") +arg(listlvs_ARG, '\0', "listlvs", 0, 0, 0, + "Print a list of LVs that use the device.\n") + +arg(listvg_ARG, '\0', "listvg", 0, 0, 0, + "Print the VG that uses the device.\n") + +arg (checkcomplete_ARG,'\0' ,"checkcomplete" ,0 ,0 ,0 , +"Check if all the devices used by a VG or LV are present,\n" +"and print \"complete\" or \"incomplete\" for each listed\n" +"VG or LV. This option is used as a part of event-based\n" +"autoactivation, so pvscan will do nothing if this option\n" + "is set and event_activation=0 in the config settings.\n") +arg (lockopt_ARG,'\0' ,"lockopt" , string_VAL,0 ,0 ,"Used to pass options for special cases to lvmlockd.\n" "See \\fBlvmlockd\\fP(8) for more information.\n" )
@@ -816,6 +829,9 @@ arg(type_ARG, '\0', "type", segtype_VAL, 0, 0, "(e.g. --stripes, --mirrors, --snapshot, --virtualsize, --thin, --cache, --vdo).\n" "Use inferred types with care because it can lead to unexpected results.\n") +arg(udevoutput_ARG, '\0', "udevoutput", 0, 0, 0, + "Command output is modified to be imported from a udev rule.\n") +arg (unbuffered_ARG,'\0' ,"unbuffered" ,0 ,0 ,0 ,"Produce output immediately without sorting or aligning the columns properly.\n" )
@@ -892,6 +908,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 a 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" )
tools/command-lines.in +28 -2
@@ -1634,11 +1634,37 @@ DESC: Display PV information. pvscan --cache_long OO: --ignorelockingfailure, --reportformat ReportFmt, ---activate ay, --major Number, --minor Number, --noudevsync +--major Number, --minor Number, --noudevsync OP: PV|String ... IO: --background ID: pvscan_cache -DESC: Autoactivate a VG when all PVs are online. +DESC: Record that a PV is online or offline. + +pvscan --cache_long --activate ay +OO: --ignorelockingfailure, --reportformat ReportFmt, +--major Number, --minor Number, --noudevsync +OP: PV|String ... +IO: --background +ID: pvscan_cache +DESC: Record that a PV is online and autoactivate the VG if complete. + +pvscan --cache_long --listvg PV +OO: --ignorelockingfailure, --checkcomplete, --vgonline, --udevoutput +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, --vgonline +ID: pvscan_cache +DESC: Record that a PV is online and list LVs using the PV. + +pvscan --listlvs PV +ID: pvscan_cache +DESC: List LVs using the PV. + +pvscan --listvg PV +ID: pvscan_cache +DESC: List the VG using the PV. ---
tools/lvmcmdline.c +4 -0
@@ -2391,6 +2391,9 @@ static void _reset_current_settings_to_default(struct cmd_context *cmd)static void _get_current_output_settings_from_args (struct cmd_context *cmd) { +if (arg_is_set (cmd, udevoutput_ARG)) + cmd->current_settings.suppress =1 ; +if (arg_is_set (cmd, debug_ARG)) cmd->current_settings.debug = _LOG_FATAL + (arg_count (cmd, debug_ARG) -1 );
@@ -2406,6 +2409,7 @@ static void _get_current_output_settings_from_args(struct cmd_context *cmd)static void _apply_current_output_settings (struct cmd_context *cmd) { +log_suppress (cmd->current_settings.suppress);init_debug (cmd->current_settings.debug);init_debug_classes_logged (cmd->default_settings.debug_classes);init_verbose (cmd->current_settings.verbose +VERBOSE_BASE_LEVEL );
tools/pvscan.c +321 -97
727 lines not on this page · raw message
tools/toollib.c +18 -0
@@ -813,6 +813,24 @@ int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv,lv_clear_integrity_recalculate_metadata (lv); } +/* +* When LVs are deactivated, then autoactivation of the VG is +* "re-armed" by removing the vg online file. So, after deactivation +* of LVs, if PVs are disconnected and reconnected again, event +* activation will trigger autoactivation again. This secondary +* autoactivation is somewhat different from, and not as important as +* the initial autoactivation during system startup. The secondary +* autoactivation will happen to a VG on a running system and may be +* mixing with user commands, so the end result is unpredictable. +* +* It's possible that we might want a config setting for usersto +* disable secondary autoactivations. Once a system is up, the +* user may want to take charge of activation changes to the VG +* and not have the system autoactivation interfere. +*/ +if (!is_change_activating (activate) &&find_config_tree_bool (cmd, global_event_activation_CFG,NULL )) +online_vg_file_remove (lv->vg->name); +set_lv_notify (lv->vg->cmd);return r;
tools/tools.h +2 -0
@@ -295,4 +295,6 @@ int lvconvert_cachevol_attach_single(struct cmd_context *cmd,struct logical_volume *lv, struct processing_handle *handle); +void online_vg_file_remove (const char *vgname); +#endif