Blame SOURCES/0056-exit-with-error-when-devicesfile-name-doesn-t-exist.patch

38b7b2
From 73b9a2805ca2f2c70f6f631b405f8fea3f72f23b Mon Sep 17 00:00:00 2001
38b7b2
From: David Teigland <teigland@redhat.com>
38b7b2
Date: Tue, 5 Jul 2022 17:08:00 -0500
38b7b2
Subject: [PATCH] exit with error when --devicesfile name doesn't exist
38b7b2
38b7b2
---
38b7b2
 lib/cache/lvmcache.c            |  3 ++-
38b7b2
 lib/label/label.c               |  4 ++--
38b7b2
 test/shell/devicesfile-basic.sh |  1 +
38b7b2
 tools/pvcreate.c                |  3 ++-
38b7b2
 tools/pvremove.c                |  3 ++-
38b7b2
 tools/pvscan.c                  |  3 ++-
38b7b2
 tools/toollib.c                 | 27 +++++++++++++++++++++------
38b7b2
 tools/vgcfgrestore.c            |  5 ++++-
38b7b2
 tools/vgcreate.c                |  5 ++++-
38b7b2
 tools/vgextend.c                |  3 ++-
38b7b2
 tools/vgmerge.c                 |  3 ++-
38b7b2
 tools/vgsplit.c                 |  3 ++-
38b7b2
 12 files changed, 46 insertions(+), 17 deletions(-)
38b7b2
38b7b2
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
38b7b2
index 0e62cd267..61a2fee6d 100644
38b7b2
--- a/lib/cache/lvmcache.c
38b7b2
+++ b/lib/cache/lvmcache.c
38b7b2
@@ -1600,7 +1600,8 @@ int lvmcache_label_scan(struct cmd_context *cmd)
38b7b2
 	 * with infos/vginfos based on reading headers from
38b7b2
 	 * each device, and a vg summary from each mda.
38b7b2
 	 */
38b7b2
-	label_scan(cmd);
38b7b2
+	if (!label_scan(cmd))
38b7b2
+		return_0;
38b7b2
 
38b7b2
 	/*
38b7b2
 	 * When devnames are used as device ids (which is dispreferred),
38b7b2
diff --git a/lib/label/label.c b/lib/label/label.c
38b7b2
index 06958b502..00ede2b76 100644
38b7b2
--- a/lib/label/label.c
38b7b2
+++ b/lib/label/label.c
38b7b2
@@ -800,7 +800,7 @@ static int _setup_bcache(void)
38b7b2
 	}
38b7b2
 
38b7b2
 	if (!(scan_bcache = bcache_create(BCACHE_BLOCK_SIZE_IN_SECTORS, cache_blocks, ioe))) {
38b7b2
-		log_error("Failed to create bcache with %d cache blocks.", cache_blocks);
38b7b2
+		log_error("Failed to set up io layer with %d blocks.", cache_blocks);
38b7b2
 		return 0;
38b7b2
 	}
38b7b2
 
38b7b2
@@ -1015,7 +1015,7 @@ int label_scan(struct cmd_context *cmd)
38b7b2
 	 * data to invalidate.)
38b7b2
 	 */
38b7b2
 	if (!(iter = dev_iter_create(NULL, 0))) {
38b7b2
-		log_error("Scanning failed to get devices.");
38b7b2
+		log_error("Failed to get device list.");
38b7b2
 		return 0;
38b7b2
 	}
38b7b2
 	while ((dev = dev_iter_get(cmd, iter))) {
38b7b2
diff --git a/test/shell/devicesfile-basic.sh b/test/shell/devicesfile-basic.sh
38b7b2
index d1cfb6a35..2d197a73a 100644
38b7b2
--- a/test/shell/devicesfile-basic.sh
38b7b2
+++ b/test/shell/devicesfile-basic.sh
38b7b2
@@ -107,6 +107,7 @@ not vgs --devicesfile test.devices $vg2
38b7b2
 # misspelled override name fails
38b7b2
 not vgs --devicesfile doesnotexist $vg1
38b7b2
 not vgs --devicesfile doesnotexist $vg2
38b7b2
+not vgs --devicesfile doesnotexist
38b7b2
 
38b7b2
 # devicesfile and devices cannot be used together
38b7b2
 not vgs --devicesfile test.devices --devices "$dev1","$dev1" $vg1
38b7b2
diff --git a/tools/pvcreate.c b/tools/pvcreate.c
38b7b2
index 71eb060a3..a1ef0e9e1 100644
38b7b2
--- a/tools/pvcreate.c
38b7b2
+++ b/tools/pvcreate.c
38b7b2
@@ -144,7 +144,8 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
38b7b2
 
38b7b2
 	cmd->create_edit_devices_file = 1;
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd))
38b7b2
+		return_ECMD_FAILED;
38b7b2
 
38b7b2
 	if (!(handle = init_processing_handle(cmd, NULL))) {
38b7b2
 		log_error("Failed to initialize processing handle.");
38b7b2
diff --git a/tools/pvremove.c b/tools/pvremove.c
38b7b2
index 2dfdbd016..5c39ee0c7 100644
38b7b2
--- a/tools/pvremove.c
38b7b2
+++ b/tools/pvremove.c
38b7b2
@@ -45,7 +45,8 @@ int pvremove(struct cmd_context *cmd, int argc, char **argv)
38b7b2
 
38b7b2
 	clear_hint_file(cmd);
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd))
38b7b2
+		return_ECMD_FAILED;
38b7b2
 
38b7b2
 	/* When forcibly clearing a PV we don't care about a VG lock. */
38b7b2
 	if (pp.force == DONT_PROMPT_OVERRIDE)
38b7b2
diff --git a/tools/pvscan.c b/tools/pvscan.c
38b7b2
index 50d46051a..bce1fbb40 100644
38b7b2
--- a/tools/pvscan.c
38b7b2
+++ b/tools/pvscan.c
38b7b2
@@ -1626,7 +1626,8 @@ static int _pvscan_cache_all(struct cmd_context *cmd, int argc, char **argv,
38b7b2
 	 * which we want 'pvscan --cache' to do, and that uses
38b7b2
 	 * info from lvmcache, e.g. duplicate pv info.
38b7b2
 	 */
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd))
38b7b2
+		return_0;
38b7b2
 
38b7b2
 	cmd->pvscan_recreate_hints = 0;
38b7b2
 	cmd->use_hints = 0;
38b7b2
diff --git a/tools/toollib.c b/tools/toollib.c
38b7b2
index 01ba03658..210b3dca5 100644
38b7b2
--- a/tools/toollib.c
38b7b2
+++ b/tools/toollib.c
38b7b2
@@ -1601,7 +1601,10 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
38b7b2
 
38b7b2
 	log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LABEL);
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd)) {
38b7b2
+		ret_max = ECMD_FAILED;
38b7b2
+		goto_out;
38b7b2
+	}
38b7b2
 
38b7b2
 	if (argc) {
38b7b2
 		for (; opt < argc; opt++) {
38b7b2
@@ -2381,8 +2384,13 @@ int process_each_vg(struct cmd_context *cmd,
38b7b2
 	 * Scan all devices to populate lvmcache with initial
38b7b2
 	 * list of PVs and VGs.
38b7b2
 	 */
38b7b2
-	if (!(read_flags & PROCESS_SKIP_SCAN))
38b7b2
-		lvmcache_label_scan(cmd);
38b7b2
+	if (!(read_flags & PROCESS_SKIP_SCAN)) {
38b7b2
+		if (!lvmcache_label_scan(cmd)) {
38b7b2
+			ret_max = ECMD_FAILED;
38b7b2
+			goto_out;
38b7b2
+		}
38b7b2
+	}
38b7b2
+
38b7b2
 
38b7b2
 	/*
38b7b2
 	 * A list of all VGs on the system is needed when:
38b7b2
@@ -3932,7 +3940,10 @@ int process_each_lv(struct cmd_context *cmd,
38b7b2
 	 * Scan all devices to populate lvmcache with initial
38b7b2
 	 * list of PVs and VGs.
38b7b2
 	 */
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd)) {
38b7b2
+		ret_max = ECMD_FAILED;
38b7b2
+		goto_out;
38b7b2
+	}
38b7b2
 
38b7b2
 	/*
38b7b2
 	 * A list of all VGs on the system is needed when:
38b7b2
@@ -4568,8 +4579,12 @@ int process_each_pv(struct cmd_context *cmd,
38b7b2
 		goto_out;
38b7b2
 	}
38b7b2
 
38b7b2
-	if (!(read_flags & PROCESS_SKIP_SCAN))
38b7b2
-		lvmcache_label_scan(cmd);
38b7b2
+	if (!(read_flags & PROCESS_SKIP_SCAN)) {
38b7b2
+		if (!lvmcache_label_scan(cmd)) {
38b7b2
+			ret_max = ECMD_FAILED;
38b7b2
+			goto_out;
38b7b2
+		}
38b7b2
+	}
38b7b2
 
38b7b2
 	if (!lvmcache_get_vgnameids(cmd, &all_vgnameids, only_this_vgname, 1)) {
38b7b2
 		ret_max = ret;
38b7b2
diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c
38b7b2
index e49313d14..9fcba89d4 100644
38b7b2
--- a/tools/vgcfgrestore.c
38b7b2
+++ b/tools/vgcfgrestore.c
38b7b2
@@ -132,7 +132,10 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
38b7b2
 
38b7b2
 	clear_hint_file(cmd);
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd)) {
38b7b2
+		unlock_vg(cmd, NULL, vg_name);
38b7b2
+		return_ECMD_FAILED;
38b7b2
+	}
38b7b2
 
38b7b2
 	cmd->handles_unknown_segments = 1;
38b7b2
 
38b7b2
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
38b7b2
index dde3f1eac..14608777f 100644
38b7b2
--- a/tools/vgcreate.c
38b7b2
+++ b/tools/vgcreate.c
38b7b2
@@ -84,7 +84,10 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
38b7b2
 
38b7b2
 	cmd->create_edit_devices_file = 1;
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd)) {
38b7b2
+		unlock_vg(cmd, NULL, vp_new.vg_name);
38b7b2
+		return_ECMD_FAILED;
38b7b2
+	}
38b7b2
 
38b7b2
 	if (lvmcache_vginfo_from_vgname(vp_new.vg_name, NULL)) {
38b7b2
 		unlock_vg(cmd, NULL, vp_new.vg_name);
38b7b2
diff --git a/tools/vgextend.c b/tools/vgextend.c
38b7b2
index 0856b4c78..fecd6bdd5 100644
38b7b2
--- a/tools/vgextend.c
38b7b2
+++ b/tools/vgextend.c
38b7b2
@@ -160,7 +160,8 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
38b7b2
 
38b7b2
 	cmd->edit_devices_file = 1;
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd))
38b7b2
+		return_ECMD_FAILED;
38b7b2
 
38b7b2
 	if (!(handle = init_processing_handle(cmd, NULL))) {
38b7b2
 		log_error("Failed to initialize processing handle.");
38b7b2
diff --git a/tools/vgmerge.c b/tools/vgmerge.c
38b7b2
index 08615cd62..4ed4a8f0b 100644
38b7b2
--- a/tools/vgmerge.c
38b7b2
+++ b/tools/vgmerge.c
38b7b2
@@ -72,7 +72,8 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
38b7b2
 		return ECMD_FAILED;
38b7b2
 	}
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd))
38b7b2
+		return_ECMD_FAILED;
38b7b2
 
38b7b2
 	if (strcmp(vg_name_to, vg_name_from) > 0)
38b7b2
 		lock_vg_from_first = 1;
38b7b2
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
38b7b2
index a085ac2ba..9d6534e89 100644
38b7b2
--- a/tools/vgsplit.c
38b7b2
+++ b/tools/vgsplit.c
38b7b2
@@ -559,7 +559,8 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
38b7b2
 		return ECMD_FAILED;
38b7b2
 	}
38b7b2
 
38b7b2
-	lvmcache_label_scan(cmd);
38b7b2
+	if (!lvmcache_label_scan(cmd))
38b7b2
+		return_ECMD_FAILED;
38b7b2
 
38b7b2
 	if (!(vginfo_to = lvmcache_vginfo_from_vgname(vg_name_to, NULL))) {
38b7b2
 		if (!validate_name(vg_name_to)) {
38b7b2
-- 
38b7b2
2.34.3
38b7b2