main - vgchange -aay: optimize device list using pvs_online files
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=62533ae3fad9fece6f27e3fae7b56e40c66438fa Commit: 62533ae3fad9fece6f27e3fae7b56e40c66438fa Parent: 5f7cb977438891a073227d75029f61970b1710bd Author: David Teigland <[email protected]> AuthorDate: Fri Nov 5 12:19:35 2021 -0500 Committer: David Teigland <[email protected]> CommitterDate: Fri Nov 5 12:19:35 2021 -0500
vgchange -aay: optimize device list using pvs_online files
Port another optimization from pvscan -aay to vgchange -aay:
"pvscan: only add device args to dev cache"
This optimization avoids doing a full dev_cache_scan, and instead populates dev-cache with only the devices in the VG being activated.
This involves shifting the use of pvs_online files from the hints interface up to the higher level label_scan interface. This specialized label_scan is structured around creating a list of devices from the pvs_online files. Previously, a list of all devices was created first, and then reduced based on the pvs_online files. The initial step of listing all devices was slow when thousands of devices are present on the system.
This optimization extends the previous optimization that used pvs_online files to limit the devices that were actually scanned (i.e. reading to identify the device):
"vgchange -aay: optimize device scan using pvs_online files"
--- lib/cache/lvmcache.c | 10 ++ lib/cache/lvmcache.h | 2 + lib/commands/toolcontext.h | 1 - lib/device/dev-cache.c | 6 +- lib/device/dev-cache.h | 3 +- lib/device/online.c | 116 ++++++++++++++++++++++- lib/device/online.h | 11 +++ lib/label/hints.c | 129 ++------------------------ lib/label/hints.h | 3 + lib/label/label.c | 182 +++++++++++++++++++++++++++++++++++++ lib/label/label.h | 1 + test/shell/udev-pvscan-vgchange.sh | 3 + tools/lvmcmdline.c | 2 - tools/pvscan.c | 2 +- tools/vgchange.c | 21 ++++- 15 files changed, 357 insertions(+), 135 deletions(-)
lib/cache/lvmcache.c +10 -0
@@ -572,6 +572,16 @@ static const char *_get_pvsummary_device_id(const char *pvid_arg, const char **dreturn NULL ; } +int lvmcache_pvsummary_count (const char *vgname) +{ +struct lvmcache_vginfo *vginfo; + +if (!(vginfo =lvmcache_vginfo_from_vgname (vgname,NULL ))) + return_0; + +return dm_list_size (&vginfo->pvsummaries); +} +/* * Check if any PVs in vg->pvs have the same PVID as any * entries in _unused_duplicates.
lib/cache/lvmcache.h +2 -0
@@ -229,4 +229,6 @@ void lvmcache_extra_md_component_checks(struct cmd_context *cmd);unsigned int lvmcache_vg_info_count (void ); +int lvmcache_pvsummary_count (const char *vgname); +#endif
lib/commands/toolcontext.h +0 -1
@@ -183,7 +183,6 @@ struct cmd_context { unsigned enable_hints:1; /* hints are enabled for cmds in general */ unsigned use_hints:1; /* if hints are enabled this cmd can use them */ unsigned pvscan_recreate_hints:1; /* enable special case hint handling for pvscan --cache */ - unsigned hints_pvs_online:1; /* hints="pvs_online" */ unsigned scan_lvs:1; unsigned wipe_outdated_pvs:1; unsigned enable_devices_list:1; /* command is using --devices option */
lib/device/dev-cache.c +3 -3
@@ -2056,12 +2056,12 @@ int setup_device(struct cmd_context *cmd, const char *devname) }/* -* pvscan --cache is specialized/optimized to look only at command args, +* autoactivation is specialized/optimized to look only at command args, * so this just sets up the devices file, then individual devices are -* added to dev-cache and matched with device_ids later in pvscan. +* added to dev-cache and matched with device_ids. */ -int setup_devices_for_pvscan_cache (struct cmd_context *cmd) +int setup_devices_for_online_autoactivation (struct cmd_context *cmd) {if (cmd->enable_devices_list) {if (!_setup_devices_list (cmd))
lib/device/dev-cache.h +1 -2
@@ -79,8 +79,7 @@ int setup_devices_file(struct cmd_context *cmd);int setup_devices (struct cmd_context *cmd);int setup_device (struct cmd_context *cmd,const char *devname); -/* Normal device setup functions are split up for pvscan optimization. */ -int setup_devices_for_pvscan_cache (struct cmd_context *cmd); +int setup_devices_for_online_autoactivation (struct cmd_context *cmd);int setup_devname_in_dev_cache (struct cmd_context *cmd,const char *devname);int setup_devno_in_dev_cache (struct cmd_context *cmd,dev_t devno);
lib/device/online.c +114 -2
132 lines not on this page · raw message
lib/device/online.h +11 -0
@@ -15,6 +15,14 @@#ifndef _ONLINE_H#define _ONLINE_H +struct pv_online { +struct dm_list list; +struct device *dev; +dev_t devno; +char pvid[ID_LEN +1 ]; +char vgname[NAME_LEN ]; +}; +/* * Avoid a duplicate pvscan[%d] prefix when logging to the journal. * FIXME: this should probably replace if (udevoutput) with
@@ -42,5 +50,8 @@ void online_vg_file_remove(const char *vgname);int online_pvid_file_create (struct cmd_context *cmd,struct device *dev,const char *vgname);int online_pvid_file_exists (const char *pvid);void online_dir_setup (struct cmd_context *cmd); +int get_pvs_online (struct dm_list *pvs_online,const char *vgname); +int get_pvs_lookup (struct dm_list *pvs_online,const char *vgname); +void free_po_list (struct dm_list *list);#endif
lib/label/hints.c +9 -120
165 lines not on this page · raw message
lib/label/hints.h +3 -0
@@ -41,5 +41,8 @@ void hints_exit(struct cmd_context *cmd);void pvscan_recreate_hints_begin (struct cmd_context *cmd); +void get_single_vgname_cmd_arg (struct cmd_context *cmd, +struct dm_list *hints,char **vgname); +#endif
lib/label/label.c +182 -0
194 lines not on this page · raw message
lib/label/label.h +1 -0
@@ -118,6 +118,7 @@ int label_scan_open_excl(struct device *dev);int label_scan_open_rw (struct device *dev);int label_scan_reopen_rw (struct device *dev);int label_read_pvid (struct device *dev,int *has_pvid); +int label_scan_vg_online (struct cmd_context *cmd,const char *vgname);int label_scan_for_pvid (struct cmd_context *cmd,char *pvid,struct device **dev_out);
test/shell/udev-pvscan-vgchange.sh +3 -0
@@ -219,6 +219,8 @@ udevadm trigger -c add /sys/block/$BDEV3 aux udev_wait wait_lvm_activate $vg4 +ls "$RUNDIR/lvm/pvs_lookup/" +cat "$RUNDIR/lvm/pvs_lookup/$vg4" || true ls "$RUNDIR/lvm/pvs_online/$PVID1" ls "$RUNDIR/lvm/pvs_online/$PVID2" ls "$RUNDIR/lvm/pvs_online/$PVID3"
@@ -375,6 +377,7 @@ touch $DF mdadm --create --metadata=1.0 "$mddev" --level 1 --chunk=64 --raid-devices=2 "$dev1" "$dev2" wait_md_create "$mddev" vgcreate $vg9 "$mddev" +lvmdevices --adddev "$mddev" || true PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'` BDEVMD=$(basename "$mddev")
tools/lvmcmdline.c +0 -2
@@ -2542,8 +2542,6 @@ static int _get_current_settings(struct cmd_context *cmd)if (!strcmp (hint_mode,"none" )) { cmd->enable_hints =0 ; cmd->use_hints =0 ; - }else if (!strcmp (hint_mode,"pvs_online" )) { - cmd->hints_pvs_online =1 ; } }
tools/pvscan.c +1 -1
@@ -1378,7 +1378,7 @@ static int _pvscan_cache_args(struct cmd_context *cmd, int argc, char **argv,* Does not do dev_cache_scan (adds nothing to dev-cache), and * does not do any device id matching. */ -if (!setup_devices_for_pvscan_cache (cmd)) { +if (!setup_devices_for_online_autoactivation (cmd)) {log_error_pvscan (cmd,"Failed to set up devices." );return 0 ; }
tools/vgchange.c +17 -4
@@ -15,6 +15,7 @@#include "tools.h" #include "lib/device/device_id.h" +#include "lib/label/hints.h" struct vgchange_params {int lock_start_count;
@@ -755,10 +756,7 @@ static int _check_autoactivation(struct cmd_context *cmd, struct vgchange_params vp->vg_complete_to_activate =1 ; -if (!arg_is_set (cmd, nohints_ARG)) - cmd->hints_pvs_online =1 ; -else - cmd->use_hints =0 ; + cmd->use_hints =0 ;return 1 ; }
@@ -767,6 +765,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv) {struct vgchange_params vp = {0 };struct processing_handle *handle; +char *vgname =NULL ;uint32_t flags =0 ;int ret;
@@ -885,6 +884,20 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)return ECMD_FAILED ;if (skip_command)return ECMD_PROCESSED ; + +/* +* Special label scan optimized for autoactivation +* that is based on info read from /run/lvm/ files +* created by pvscan --cache during autoactivation. +* (Add an option to disable this optimization?) +*/ +get_single_vgname_cmd_arg (cmd,NULL , &vgname); +if (vgname) { +if (!label_scan_vg_online (cmd, vgname)) +log_debug ("Standard label_scan required in place of online scan." ); +else + flags |=PROCESS_SKIP_SCAN ; + } }if (update)