aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2021-12-10 12:51:26 -0600
committerJóhann B. Guðmundsson <johannbg@gmail.com>2022-02-02 22:48:13 +0000
commit1af46743195422aaebcde5c508a5dd479eff51ea (patch)
treea1aabf7a4faa38ed768f70797bf2c7bc1e456c3f
parent7ffc5e388bcce20785803825bdd260c3c854b34f (diff)
downloaddracut-1af46743195422aaebcde5c508a5dd479eff51ea.tar.gz
feat(lvm): only run lvchange for LV that is seen on devices
Change the command listing LVs from lvscan to lvs, and list only the LV names that are being activated. Before attempting to activate an LV, check that that LV name appears in the lvs command output. This avoids wasting time running an lvchange command that we know will fail.
-rwxr-xr-xmodules.d/90lvm/lvm_scan.sh18
1 files changed, 14 insertions, 4 deletions
diff --git a/modules.d/90lvm/lvm_scan.sh b/modules.d/90lvm/lvm_scan.sh
index bda265f6..89f077ae 100755
--- a/modules.d/90lvm/lvm_scan.sh
+++ b/modules.d/90lvm/lvm_scan.sh
@@ -119,7 +119,7 @@ sub=${sub%%\(*}
# ignores locking failures (--ignorelockingfailure)
# disables hints (--nohints)
#
-# For lvscan and vgscan:
+# For lvs and vgscan:
# disable locking (--nolocking)
# disable hints (--nohints)
@@ -136,10 +136,20 @@ check_lvm_ver 2 3 14 "$maj" "$min" "$sub" \
if [ -n "$LVS" ]; then
info "Scanning devices $lvmdevs for LVM logical volumes $LVS"
# shellcheck disable=SC2086
- lvm lvscan $scan_args 2>&1 | vinfo
+ LVSLIST=$(lvm lvs $scan_args --noheading -o lv_full_name,segtype $LVS)
+ info "$LVSLIST"
+
+ # Only attempt to activate an LV if it appears in the lvs output.
for LV in $LVS; do
- # shellcheck disable=SC2086
- lvm lvchange --yes -K -ay $activate_args "$LV" 2>&1 | vinfo
+ if strstr "$LVSLIST" "$LV"; then
+ # This lvchange is expected to fail if all PVs used by
+ # the LV are not yet present. Premature/failed lvchange
+ # could be avoided by reporting if an LV is complete
+ # from the lvs command above and skipping this lvchange
+ # if the LV is not lised as complete.
+ # shellcheck disable=SC2086
+ lvm lvchange --yes -K -ay $activate_args "$LV" 2>&1 | vinfo
+ fi
done
fi