Blame SOURCES/0010-device_id-fix-search-on-filtered-device.patch

429878
From 5533cd7bf4c1edc5d8fb0e95d2f83b2b2d446339 Mon Sep 17 00:00:00 2001
429878
From: David Teigland <teigland@redhat.com>
429878
Date: Tue, 16 Nov 2021 09:29:24 -0600
ab86b0
Subject: [PATCH 10/54] device_id: fix search on filtered device
429878
429878
When devnames are used as device ids and devnames change,
429878
then new devices need to be located for the PVs.  If the old
429878
devname is now used by a filtered device, this was preventing
429878
the code from searching for the new device, so the PV was
429878
reported as missing.
429878
---
429878
 lib/device/device_id.c            | 16 ++++++-
429878
 test/shell/devicesfile-devname.sh | 69 +++++++++++++++++++++++++++++++
429878
 2 files changed, 83 insertions(+), 2 deletions(-)
429878
429878
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
429878
index dea739fc4..48f1682a3 100644
429878
--- a/lib/device/device_id.c
429878
+++ b/lib/device/device_id.c
429878
@@ -2025,12 +2025,19 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
429878
 	search_auto = !strcmp(cmd->search_for_devnames, "auto");
429878
 
429878
 	dm_list_iterate_items(du, &cmd->use_devices) {
429878
-		if (du->dev)
429878
-			continue;
429878
 		if (!du->pvid)
429878
 			continue;
429878
 		if (du->idtype != DEV_ID_TYPE_DEVNAME)
429878
 			continue;
429878
+
429878
+		/*
429878
+		 * if the old incorrect devname is now a device that's
429878
+		 * filtered and not scanned, e.g. an mpath component,
429878
+		 * then we want to look for the pvid on a new device.
429878
+		 */
429878
+		if (du->dev && !du->dev->filtered_flags)
429878
+			continue;
429878
+
429878
 		if (!(dil = dm_pool_zalloc(cmd->mem, sizeof(*dil))))
429878
 			continue;
429878
 
429878
@@ -2055,6 +2062,11 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
429878
 	 * the searched file, so a subsequent lvm command will do the search
429878
 	 * again.  In future perhaps we could add a policy to automatically
429878
 	 * remove a devices file entry that's not been found for some time.
429878
+	 *
429878
+	 * TODO: like the hint file, add a hash of all devnames to the searched
429878
+	 * file so it can be ignored and removed if the devs/hash change.
429878
+	 * If hints are enabled, the hints invalidation could also remove the
429878
+	 * searched file.
429878
 	 */
429878
 	if (_searched_devnames_exists(cmd)) {
429878
 		log_debug("Search for PVIDs skipped for %s", _searched_file);
429878
diff --git a/test/shell/devicesfile-devname.sh b/test/shell/devicesfile-devname.sh
429878
index f95be52b1..a99fe3e9a 100644
429878
--- a/test/shell/devicesfile-devname.sh
429878
+++ b/test/shell/devicesfile-devname.sh
429878
@@ -545,4 +545,73 @@ grep "$PVID2" "$DF" |tee out
429878
 grep "$dev2" out
429878
 not grep "$dev1" out
429878
 
429878
+vgchange -an $vg1
429878
+vgchange -an $vg2
429878
+vgremove -ff $vg1
429878
+vgremove -ff $vg2
429878
+
429878
+# devnames change so the new devname now refers to a filtered device,
429878
+# e.g. an mpath or md component, which is not scanned
429878
+
429878
+wait_md_create() {
429878
+        local md=$1
429878
+
429878
+        while :; do
429878
+                if ! grep "$(basename $md)" /proc/mdstat; then
429878
+                        echo "$md not ready"
429878
+                        cat /proc/mdstat
429878
+                        sleep 2
429878
+                else
429878
+                        break
429878
+                fi
429878
+        done
429878
+        echo "$md" > WAIT_MD_DEV
429878
+}
429878
+
429878
+aux wipefs_a "$dev1"
429878
+aux wipefs_a "$dev2"
429878
+aux wipefs_a "$dev3"
429878
+aux wipefs_a "$dev4"
429878
+
429878
+mddev="/dev/md33"
429878
+not grep $mddev /proc/mdstat || skip
429878
+
429878
+rm "$DF"
429878
+touch "$DF"
429878
+vgcreate $vg1 "$dev1" "$dev2"
429878
+cat "$DF"
429878
+cp "$DF" "$ORIG"
429878
+
429878
+# PVID with dashes for matching pvs -o+uuid output
429878
+OPVID1=`pvs "$dev1" --noheading -o uuid | awk '{print $1}'`
429878
+OPVID2=`pvs "$dev2" --noheading -o uuid | awk '{print $1}'`
429878
+
429878
+# PVID without dashes for matching devices file fields
429878
+PVID1=`pvs "$dev1" --noheading -o uuid | tr -d - | awk '{print $1}'`
429878
+PVID2=`pvs "$dev2" --noheading -o uuid | tr -d - | awk '{print $1}'`
429878
+
429878
+mdadm --create --metadata=1.0 "$mddev" --level 1 --chunk=64 --raid-devices=2 "$dev3" "$dev4"
429878
+wait_md_create "$mddev"
429878
+
429878
+sed -e "s|DEVNAME=$dev1|DEVNAME=$dev3|" "$ORIG" > tmp1.devices
429878
+sed -e "s|IDNAME=$dev1|IDNAME=$dev3|" tmp1.devices > "$DF"
429878
+cat "$DF"
429878
+pvs -o+uuid |tee out
429878
+grep "$dev1" out
429878
+grep "$dev2" out
429878
+grep "$OPVID1" out
429878
+grep "$OPVID2" out
429878
+not grep "$dev3" out
429878
+not grep "$dev4" out
429878
+
429878
+grep "$dev1" "$DF"
429878
+grep "$dev2" "$DF"
429878
+grep "$PVID1" "$DF"
429878
+grep "$PVID2" "$DF"
429878
+not grep "$dev3" "$DF"
429878
+not grep "$dev4" "$DF"
429878
+
429878
+mdadm --stop "$mddev"
429878
+aux udev_wait
429878
+
429878
 vgremove -ff $vg1
429878
-- 
ab86b0
2.34.3
429878