master - pvscan: autoactivate a VG once
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=74a388cca15baa4149a24e37bccb421c53f726e5 Commit: 74a388cca15baa4149a24e37bccb421c53f726e5 Parent: f0089472e7fd679acbc004daf4b35e9a86fc11a9 Author: David Teigland <[email protected]> AuthorDate: Wed Feb 13 14:21:56 2019 -0600 Committer: David Teigland <[email protected]> CommitterDate: Thu Feb 21 15:17:41 2019 -0600
pvscan: autoactivate a VG once
When a VG has multiple PVs, and all those PVs come online at the same time, concurrent pvscans for each PV will all create the individual pvid files, and all will often see the VG is now complete. This causes each of the pvscan commands to think it should activate the VG, so there are multiple activations of the same VG. The vg lock serializes them, and only the first pvscan actually does the activation, but there is still a lot of extra overhead and time used by the other pvscans that attempt to activate the already active VG. This can lead to a backlog of pvscans and timeouts.
To fix this, this adds a new /run/lvm/vgs_online/ dir that works like the existing /run/lvm/pvs_online/ dir. Each pvscan that wants to activate a VG will first try to exlusively create the file vgs_online/<vgname>. Only the first pvscan will succeed, and that one will do the VG activation. The other pvscans will find the vgname file exists and will not do the activation step.
When a PV goes offline, the vgs_online file for the corresponding VG is removed. This allows the VG to be autoactivated again when the PV comes online again. This requires that the vgname be stored in the pvid files.
--- test/shell/pvscan-autoactivate.sh | 39 ++++--- test/shell/pvscan-cache.sh | 20 +++- tools/pvscan.c | 214 +++++++++++++++++++++++++++++++----- 3 files changed, 226 insertions(+), 47 deletions(-)
test/shell/pvscan-autoactivate.sh +24 -15
@@ -14,14 +14,15 @@ SKIP_WITH_LVMPOLLD=1 RUNDIR="/run" test -d "$RUNDIR" || RUNDIR="/var/run" -ONLINEDIR="$RUNDIR/lvm/pvs_online" +PVS_ONLINE_DIR="$RUNDIR/lvm/pvs_online" +VGS_ONLINE_DIR="$RUNDIR/lvm/vgs_online" # FIXME: kills logic for running system -_clear_online() { +_clear_online_files() { # wait till udev is finished aux udev_wait - rm -f "$ONLINEDIR"/* - test -n "${1+varset}" || touch "$ONLINEDIR/foo" + rm -f "$PVS_ONLINE_DIR"/* + rm -f "$VGS_ONLINE_DIR"/* } . lib/inittest
@@ -32,8 +33,9 @@ vgcreate $vg1 "$dev1" "$dev2" lvcreate -n $lv1 -l 4 -a n $vg1 # the first pvscan scans all devs -test -d "$ONLINEDIR" || mkdir -p "$ONLINEDIR" -_clear_online nofoo +test -d "$PVS_ONLINE_DIR" || mkdir -p "$PVS_ONLINE_DIR" +test -d "$VGS_ONLINE_DIR" || mkdir -p "$VGS_ONLINE_DIR" +_clear_online_files pvscan --cache -aay check lv_field $vg1/$lv1 lv_active "active"
@@ -42,7 +44,7 @@ lvchange -an $vg1 # the first pvscan scans all devs even when # only one device is specified -_clear_online nofoo +_clear_online_files pvscan --cache -aay "$dev1" check lv_field $vg1/$lv1 lv_active "active"
@@ -50,7 +52,8 @@ lvchange -an $vg1 # touch foo to disable first-pvscan case, # then check pvscan with no args scans all -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache -aay check lv_field $vg1/$lv1 lv_active "active"
@@ -60,7 +63,8 @@ lvchange -an $vg1 # then check that vg is activated only after # both devs appear separately -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache -aay "$dev1" check lv_field $vg1/$lv1 lv_active ""
@@ -72,7 +76,8 @@ lvchange -an $vg1 # then check that vg is activated when both # devs appear together -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache -aay "$dev1" "$dev2" check lv_field $vg1/$lv1 lv_active "active"
@@ -92,7 +97,8 @@ lvcreate -n $lv1 -l 4 -a n $vg1 # touch foo to disable first-pvscan case, # test case where dev with metadata appears first -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache -aay "$dev2" check lv_field $vg1/$lv1 lv_active ""
@@ -104,7 +110,8 @@ lvchange -an $vg1 # test case where dev without metadata # appears first which triggers scanning all -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache -aay "$dev1" check lv_field $vg1/$lv1 lv_active "active"
@@ -115,7 +122,7 @@ lvchange -an $vg1 # dev without metadata is scanned, but # first-pvscan case scans all devs -_clear_online nofoo +_clear_online_files pvscan --cache -aay "$dev1" check lv_field $vg1/$lv1 lv_active "active"
@@ -125,7 +132,8 @@ lvchange -an $vg1 # is online without the -aay option to # activate until after they are online -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache "$dev1" check lv_field $vg1/$lv1 lv_active ""
@@ -137,7 +145,8 @@ lvchange -an $vg1 # like previous -_clear_online +_clear_online_files +touch "$RUNDIR/lvm/pvs_online/foo" pvscan --cache "$dev1" check lv_field $vg1/$lv1 lv_active ""
test/shell/pvscan-cache.sh +18 -2
@@ -13,6 +13,18 @@ SKIP_WITH_LVMLOCKD=1 SKIP_WITH_LVMPOLLD=1 +RUNDIR="/run" +test -d "$RUNDIR" || RUNDIR="/var/run" +PVS_ONLINE_DIR="$RUNDIR/lvm/pvs_online" +VGS_ONLINE_DIR="$RUNDIR/lvm/vgs_online" + +_clear_online_files() { + # wait till udev is finished + aux udev_wait + rm -f "$PVS_ONLINE_DIR"/* + rm -f "$VGS_ONLINE_DIR"/* +} + . lib/inittest aux prepare_pvs 2
@@ -35,9 +47,12 @@ check lv_exists $vg1 check lv_field $vg1/$lv1 lv_active "" # Check that an LV cannot be activated by pvscan while VG is exported +vgchange -an $vg1 +_clear_online_files vgexport $vg1 -not pvscan --cache -aay "$dev1" -not pvscan --cache -aay "$dev2" +pvscan --cache -aay "$dev1" || true +pvscan --cache -aay "$dev2" || true +_clear_online_files vgimport $vg1 check lv_exists $vg1 check lv_field $vg1/$lv1 lv_active ""
@@ -51,6 +66,7 @@ lvchange -an $vg1/$lv1 # metadata which hasn't been updated for some # time and also since the MDA is marked as ignored, # it should really be *ignored*! +_clear_online_files pvchange --metadataignore y "$dev1" aux disable_dev "$dev2" pvscan --cache
tools/pvscan.c +184 -30
372 lines not on this page · raw message