All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Teigland <teigland@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - lvmdevices check: error exit if update is needed
Date: Fri, 14 Jan 2022 21:52:33 +0000 (GMT)	[thread overview]
Message-ID: <20220114215233.B00BD3858C39@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a972d63c547dc9699c0b3664175eb96b5d89ff8f
Commit:        a972d63c547dc9699c0b3664175eb96b5d89ff8f
Parent:        d5a950ca67c106403054ecb847e226e8b5a7c30e
Author:        David Teigland <teigland@redhat.com>
AuthorDate:    Thu Jan 13 14:52:54 2022 -0600
Committer:     David Teigland <teigland@redhat.com>
CommitterDate: Fri Jan 14 14:59:28 2022 -0600

lvmdevices check: error exit if update is needed

. error exit means that lvmdevices --update would make a change.

. remove check of PART field from --check because it isn't used.

. unlink searched_devnames file to ensure check|update will search
---
 lib/device/device_id.c             |  3 ++-
 test/shell/devicesfile-realdevs.sh |  8 ++++----
 tools/args.h                       |  3 ++-
 tools/lvmdevices.c                 | 37 ++++++++++++++++---------------------
 4 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 6e9107fff..ad9694b8a 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2278,7 +2278,8 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
 			continue;
 		}
 
-		log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
+		if (!noupdate)
+			log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
 
 		free(du->idname);
 		free(du->devname);
diff --git a/test/shell/devicesfile-realdevs.sh b/test/shell/devicesfile-realdevs.sh
index 8d4aa3e67..23d4bedb4 100644
--- a/test/shell/devicesfile-realdevs.sh
+++ b/test/shell/devicesfile-realdevs.sh
@@ -423,7 +423,7 @@ sed "s/$pvid1/badpvid/" "$DF.orig" |tee $DF
 not grep $pvid1 $DF
 grep $did1 $DF
 
-lvmdevices --check 2>&1|tee out
+not lvmdevices --check 2>&1|tee out
 grep $dev1 out
 grep badpvid out
 grep $pvid1 out
@@ -493,7 +493,7 @@ rm $DF
 d1=$(basename $dev1)
 d3=$(basename $dev3)
 sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
 grep $dev1 out
 
 lvmdevices --update
@@ -515,7 +515,7 @@ sed "s/$d1/tmp/" "$DF.orig" |tee ${DF}_1
 sed "s/$d2/$d1/" "${DF}_1" |tee ${DF}_2
 sed "s/tmp/$d2/" "${DF}_2" |tee $DF
 rm ${DF}_1 ${DF}_2
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
 grep $dev1 out
 grep $dev2 out
 
@@ -536,7 +536,7 @@ rm $DF
 d1=$(basename $dev1)
 d3=$(basename $dev3)
 sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
 grep $dev1 out
 
 pvs -o+uuid,deviceid | grep $vg |tee out
diff --git a/tools/args.h b/tools/args.h
index 2aed8afbb..3f4580b8d 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -159,7 +159,8 @@ arg(cachesize_ARG, '\0', "cachesize", sizemb_VAL, 0, 0,
     "The size of cache to use.\n")
 
 arg(check_ARG, '\0', "check", 0, 0, 0,
-    "Check the content of the devices file.\n")
+    "Checks the content of the devices file.\n"
+    "Reports incorrect device names or PVIDs for entries.\n")
 
 arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
     "The command profile to use for command configuration.\n"
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
index 3f104f7de..c50c09f90 100644
--- a/tools/lvmdevices.c
+++ b/tools/lvmdevices.c
@@ -128,7 +128,6 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
 	struct device *dev;
 	struct dev_use *du, *du2;
 	const char *deviceidtype;
-	int changes = 0;
 
 	dm_list_init(&search_pvids);
 	dm_list_init(&found_devs);
@@ -184,8 +183,11 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
 
 	if (arg_is_set(cmd, check_ARG) || arg_is_set(cmd, update_ARG)) {
 		int search_count = 0;
+		int update_needed = 0;
 		int invalid = 0;
 
+		unlink_searched_devnames(cmd);
+
 		label_scan_setup_bcache();
 
 		dm_list_iterate_items(du, &cmd->use_devices) {
@@ -225,6 +227,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
 		 * run just above.
 		 */
 		device_ids_validate(cmd, NULL, &invalid, 1);
+		if (invalid)
+			update_needed = 1;
 
 		/*
 		 * Find and fix any devname entries that have moved to a
@@ -240,33 +244,24 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
 				label_scan_invalidate(du->dev);
 		}
 
-		/*
-		 * check du->part
-		 */
-		dm_list_iterate_items(du, &cmd->use_devices) {
-			int part = 0;
-			if (!du->dev)
-				continue;
-			dev = du->dev;
-
-			dev_get_partition_number(dev, &part);
-
-			if (part != du->part) {
-				log_warn("Device %s partition %u has incorrect PART in devices file (%u)",
-					 dev_name(dev), part, du->part);
-				du->part = part;
-				changes++;
-			}
-		}
-
 		if (arg_is_set(cmd, update_ARG)) {
-			if (invalid || !dm_list_empty(&found_devs)) {
+			if (update_needed || !dm_list_empty(&found_devs)) {
 				if (!device_ids_write(cmd))
 					goto_bad;
 				log_print("Updated devices file to version %s", devices_file_version());
 			} else {
 				log_print("No update for devices file is needed.");
 			}
+		} else {
+			/*
+			 * --check exits with an error if the devices file
+			 * needs updates, i.e. running --update would make
+			 * changes.
+			 */
+			if (update_needed) {
+				log_error("Updates needed for devices file.");
+				goto bad;
+			}
 		}
 		goto out;
 	}



                 reply	other threads:[~2022-01-14 21:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220114215233.B00BD3858C39@sourceware.org \
    --to=teigland@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.