d1a34d
From ec9b1e872ad3be0ec9440927a0f702c7bfa80932 Mon Sep 17 00:00:00 2001
d1a34d
From: David Teigland <teigland@redhat.com>
d1a34d
Date: Fri, 10 Dec 2021 12:51:26 -0600
d1a34d
Subject: [PATCH] feat(lvm): only run lvchange for LV that is seen on devices
d1a34d
d1a34d
Change the command listing LVs from lvscan to lvs, and list
d1a34d
only the LV names that are being activated.  Before attempting
d1a34d
to activate an LV, check that that LV name appears in the
d1a34d
lvs command output.  This avoids wasting time running an
d1a34d
lvchange command that we know will fail.
d1a34d
d1a34d
(cherry picked from commit 1af46743195422aaebcde5c508a5dd479eff51ea)
d1a34d
d1a34d
Resolves: #2037955
d1a34d
---
d1a34d
 modules.d/90lvm/lvm_scan.sh | 18 ++++++++++++++----
d1a34d
 1 file changed, 14 insertions(+), 4 deletions(-)
d1a34d
d1a34d
diff --git a/modules.d/90lvm/lvm_scan.sh b/modules.d/90lvm/lvm_scan.sh
d1a34d
index bda265f6..89f077ae 100755
d1a34d
--- a/modules.d/90lvm/lvm_scan.sh
d1a34d
+++ b/modules.d/90lvm/lvm_scan.sh
d1a34d
@@ -119,7 +119,7 @@ sub=${sub%%\(*}
d1a34d
 # ignores locking failures (--ignorelockingfailure)
d1a34d
 # disables hints (--nohints)
d1a34d
 #
d1a34d
-# For lvscan and vgscan:
d1a34d
+# For lvs and vgscan:
d1a34d
 # disable locking (--nolocking)
d1a34d
 # disable hints (--nohints)
d1a34d
 
d1a34d
@@ -136,10 +136,20 @@ check_lvm_ver 2 3 14 "$maj" "$min" "$sub" \
d1a34d
 if [ -n "$LVS" ]; then
d1a34d
     info "Scanning devices $lvmdevs for LVM logical volumes $LVS"
d1a34d
     # shellcheck disable=SC2086
d1a34d
-    lvm lvscan $scan_args 2>&1 | vinfo
d1a34d
+    LVSLIST=$(lvm lvs $scan_args --noheading -o lv_full_name,segtype $LVS)
d1a34d
+    info "$LVSLIST"
d1a34d
+
d1a34d
+    # Only attempt to activate an LV if it appears in the lvs output.
d1a34d
     for LV in $LVS; do
d1a34d
-        # shellcheck disable=SC2086
d1a34d
-        lvm lvchange --yes -K -ay $activate_args "$LV" 2>&1 | vinfo
d1a34d
+        if strstr "$LVSLIST" "$LV"; then
d1a34d
+            # This lvchange is expected to fail if all PVs used by
d1a34d
+            # the LV are not yet present.  Premature/failed lvchange
d1a34d
+            # could be avoided by reporting if an LV is complete
d1a34d
+            # from the lvs command above and skipping this lvchange
d1a34d
+            # if the LV is not lised as complete.
d1a34d
+            # shellcheck disable=SC2086
d1a34d
+            lvm lvchange --yes -K -ay $activate_args "$LV" 2>&1 | vinfo
d1a34d
+        fi
d1a34d
     done
d1a34d
 fi
d1a34d
 
d1a34d