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

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