Blame SOURCES/0026-lvmdevices-check-error-exit-if-update-is-needed.patch

ab86b0
From bb477d63e336a10e5959962a9f26a028ea9e55eb Mon Sep 17 00:00:00 2001
ab86b0
From: David Teigland <teigland@redhat.com>
ab86b0
Date: Thu, 13 Jan 2022 14:52:54 -0600
ab86b0
Subject: [PATCH 26/54] lvmdevices check: error exit if update is needed
ab86b0
ab86b0
. error exit means that lvmdevices --update would make a change.
ab86b0
ab86b0
. remove check of PART field from --check because it isn't used.
ab86b0
ab86b0
. unlink searched_devnames file to ensure check|update will search
ab86b0
---
ab86b0
 lib/device/device_id.c             |  3 ++-
ab86b0
 test/shell/devicesfile-realdevs.sh |  8 +++----
ab86b0
 tools/args.h                       |  3 ++-
ab86b0
 tools/lvmdevices.c                 | 37 +++++++++++++-----------------
ab86b0
 4 files changed, 24 insertions(+), 27 deletions(-)
ab86b0
ab86b0
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
ab86b0
index 0621bc858..a33dcebe0 100644
ab86b0
--- a/lib/device/device_id.c
ab86b0
+++ b/lib/device/device_id.c
ab86b0
@@ -2271,7 +2271,8 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
ab86b0
 			continue;
ab86b0
 		}
ab86b0
 
ab86b0
-		log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
ab86b0
+		if (!noupdate)
ab86b0
+			log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
ab86b0
 
ab86b0
 		free(du->idname);
ab86b0
 		free(du->devname);
ab86b0
diff --git a/test/shell/devicesfile-realdevs.sh b/test/shell/devicesfile-realdevs.sh
ab86b0
index 8d4aa3e67..23d4bedb4 100644
ab86b0
--- a/test/shell/devicesfile-realdevs.sh
ab86b0
+++ b/test/shell/devicesfile-realdevs.sh
ab86b0
@@ -423,7 +423,7 @@ sed "s/$pvid1/badpvid/" "$DF.orig" |tee $DF
ab86b0
 not grep $pvid1 $DF
ab86b0
 grep $did1 $DF
ab86b0
 
ab86b0
-lvmdevices --check 2>&1|tee out
ab86b0
+not lvmdevices --check 2>&1|tee out
ab86b0
 grep $dev1 out
ab86b0
 grep badpvid out
ab86b0
 grep $pvid1 out
ab86b0
@@ -493,7 +493,7 @@ rm $DF
ab86b0
 d1=$(basename $dev1)
ab86b0
 d3=$(basename $dev3)
ab86b0
 sed "s/$d1/$d3/" "$DF.orig" |tee $DF
ab86b0
-lvmdevices --check 2>&1 |tee out
ab86b0
+not lvmdevices --check 2>&1 |tee out
ab86b0
 grep $dev1 out
ab86b0
 
ab86b0
 lvmdevices --update
ab86b0
@@ -515,7 +515,7 @@ sed "s/$d1/tmp/" "$DF.orig" |tee ${DF}_1
ab86b0
 sed "s/$d2/$d1/" "${DF}_1" |tee ${DF}_2
ab86b0
 sed "s/tmp/$d2/" "${DF}_2" |tee $DF
ab86b0
 rm ${DF}_1 ${DF}_2
ab86b0
-lvmdevices --check 2>&1 |tee out
ab86b0
+not lvmdevices --check 2>&1 |tee out
ab86b0
 grep $dev1 out
ab86b0
 grep $dev2 out
ab86b0
 
ab86b0
@@ -536,7 +536,7 @@ rm $DF
ab86b0
 d1=$(basename $dev1)
ab86b0
 d3=$(basename $dev3)
ab86b0
 sed "s/$d1/$d3/" "$DF.orig" |tee $DF
ab86b0
-lvmdevices --check 2>&1 |tee out
ab86b0
+not lvmdevices --check 2>&1 |tee out
ab86b0
 grep $dev1 out
ab86b0
 
ab86b0
 pvs -o+uuid,deviceid | grep $vg |tee out
ab86b0
diff --git a/tools/args.h b/tools/args.h
ab86b0
index 774ce33f4..9a7bf81b2 100644
ab86b0
--- a/tools/args.h
ab86b0
+++ b/tools/args.h
ab86b0
@@ -153,7 +153,8 @@ arg(cachesize_ARG, '\0', "cachesize", sizemb_VAL, 0, 0,
ab86b0
     "The size of cache to use.\n")
ab86b0
 
ab86b0
 arg(check_ARG, '\0', "check", 0, 0, 0,
ab86b0
-    "Check the content of the devices file.\n")
ab86b0
+    "Checks the content of the devices file.\n"
ab86b0
+    "Reports incorrect device names or PVIDs for entries.\n")
ab86b0
 
ab86b0
 arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
ab86b0
     "The command profile to use for command configuration.\n"
ab86b0
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
ab86b0
index 3f104f7de..c50c09f90 100644
ab86b0
--- a/tools/lvmdevices.c
ab86b0
+++ b/tools/lvmdevices.c
ab86b0
@@ -128,7 +128,6 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
ab86b0
 	struct device *dev;
ab86b0
 	struct dev_use *du, *du2;
ab86b0
 	const char *deviceidtype;
ab86b0
-	int changes = 0;
ab86b0
 
ab86b0
 	dm_list_init(&search_pvids);
ab86b0
 	dm_list_init(&found_devs);
ab86b0
@@ -184,8 +183,11 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
ab86b0
 
ab86b0
 	if (arg_is_set(cmd, check_ARG) || arg_is_set(cmd, update_ARG)) {
ab86b0
 		int search_count = 0;
ab86b0
+		int update_needed = 0;
ab86b0
 		int invalid = 0;
ab86b0
 
ab86b0
+		unlink_searched_devnames(cmd);
ab86b0
+
ab86b0
 		label_scan_setup_bcache();
ab86b0
 
ab86b0
 		dm_list_iterate_items(du, &cmd->use_devices) {
ab86b0
@@ -225,6 +227,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
ab86b0
 		 * run just above.
ab86b0
 		 */
ab86b0
 		device_ids_validate(cmd, NULL, &invalid, 1);
ab86b0
+		if (invalid)
ab86b0
+			update_needed = 1;
ab86b0
 
ab86b0
 		/*
ab86b0
 		 * Find and fix any devname entries that have moved to a
ab86b0
@@ -240,33 +244,24 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
ab86b0
 				label_scan_invalidate(du->dev);
ab86b0
 		}
ab86b0
 
ab86b0
-		/*
ab86b0
-		 * check du->part
ab86b0
-		 */
ab86b0
-		dm_list_iterate_items(du, &cmd->use_devices) {
ab86b0
-			int part = 0;
ab86b0
-			if (!du->dev)
ab86b0
-				continue;
ab86b0
-			dev = du->dev;
ab86b0
-
ab86b0
-			dev_get_partition_number(dev, &part);
ab86b0
-
ab86b0
-			if (part != du->part) {
ab86b0
-				log_warn("Device %s partition %u has incorrect PART in devices file (%u)",
ab86b0
-					 dev_name(dev), part, du->part);
ab86b0
-				du->part = part;
ab86b0
-				changes++;
ab86b0
-			}
ab86b0
-		}
ab86b0
-
ab86b0
 		if (arg_is_set(cmd, update_ARG)) {
ab86b0
-			if (invalid || !dm_list_empty(&found_devs)) {
ab86b0
+			if (update_needed || !dm_list_empty(&found_devs)) {
ab86b0
 				if (!device_ids_write(cmd))
ab86b0
 					goto_bad;
ab86b0
 				log_print("Updated devices file to version %s", devices_file_version());
ab86b0
 			} else {
ab86b0
 				log_print("No update for devices file is needed.");
ab86b0
 			}
ab86b0
+		} else {
ab86b0
+			/*
ab86b0
+			 * --check exits with an error if the devices file
ab86b0
+			 * needs updates, i.e. running --update would make
ab86b0
+			 * changes.
ab86b0
+			 */
ab86b0
+			if (update_needed) {
ab86b0
+				log_error("Updates needed for devices file.");
ab86b0
+				goto bad;
ab86b0
+			}
ab86b0
 		}
ab86b0
 		goto out;
ab86b0
 	}
ab86b0
-- 
ab86b0
2.34.3
ab86b0