Skip to contentSkip to conversation

main - exit with error when --devicesfile name doesn't exist

PATCH David Teigland 1 participant 1 message Jul 6, 2022

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=92b4fcf57f3c6d212d06b72b097e1a06e6efb84b
Commit:        92b4fcf57f3c6d212d06b72b097e1a06e6efb84b
Parent:        d0f94e763d6e6bca491c74cea93ec3062f32757e
Author:        David Teigland <[email protected]>
AuthorDate:    Tue Jul 5 17:08:00 2022 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Wed Jul 6 10:10:58 2022 -0500

exit with error when --devicesfile name doesn't exist

---
 lib/cache/lvmcache.c            |  3 ++-
 lib/label/label.c               |  4 ++--
 test/shell/devicesfile-basic.sh |  1 +
 tools/pvcreate.c                |  3 ++-
 tools/pvremove.c                |  3 ++-
 tools/pvscan.c                  |  3 ++-
 tools/toollib.c                 | 27 +++++++++++++++++++++------
 tools/vgcfgrestore.c            |  5 ++++-
 tools/vgcreate.c                |  5 ++++-
 tools/vgextend.c                |  3 ++-
 tools/vgmerge.c                 |  3 ++-
 tools/vgsplit.c                 |  3 ++-
 12 files changed, 46 insertions(+), 17 deletions(-)
lib/cache/lvmcache.c +2 -1
index 22edcfd84..a1c4a61c8 100644
@@ -1612,7 +1612,8 @@ int lvmcache_label_scan(struct cmd_context *cmd)
 	 * with infos/vginfos based on reading headers from
 	 * each device, and a vg summary from each mda.
 	 */
-	label_scan(cmd);
+	if (!label_scan(cmd))
+		return_0;
 
 	/*
 	 * When devnames are used as device ids (which is dispreferred),
lib/label/label.c +2 -2
index 711edb6f4..f845abb96 100644
@@ -801,7 +801,7 @@ static int _setup_bcache(void)
 	}
 
 	if (!(scan_bcache = bcache_create(BCACHE_BLOCK_SIZE_IN_SECTORS, cache_blocks, ioe))) {
-		log_error("Failed to create bcache with %d cache blocks.", cache_blocks);
+		log_error("Failed to set up io layer with %d blocks.", cache_blocks);
 		return 0;
 	}
 
@@ -1292,7 +1292,7 @@ int label_scan(struct cmd_context *cmd)
 	 * data to invalidate.)
 	 */
 	if (!(iter = dev_iter_create(NULL, 0))) {
-		log_error("Scanning failed to get devices.");
+		log_error("Failed to get device list.");
 		return 0;
 	}
 	while ((dev = dev_iter_get(cmd, iter))) {
test/shell/devicesfile-basic.sh +1 -0
index 77fe265a0..715c579b3 100644
@@ -107,6 +107,7 @@ not vgs --devicesfile test.devices $vg2
 # misspelled override name fails
 not vgs --devicesfile doesnotexist $vg1
 not vgs --devicesfile doesnotexist $vg2
+not vgs --devicesfile doesnotexist
 
 # devicesfile and devices cannot be used together
 not vgs --devicesfile test.devices --devices "$dev1","$dev1" $vg1
tools/pvcreate.c +2 -1
index 71eb060a3..a1ef0e9e1 100644
@@ -144,7 +144,8 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
 
 	cmd->create_edit_devices_file = 1;
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd))
+		return_ECMD_FAILED;
 
 	if (!(handle = init_processing_handle(cmd, NULL))) {
 		log_error("Failed to initialize processing handle.");
tools/pvremove.c +2 -1
index 2dfdbd016..5c39ee0c7 100644
@@ -45,7 +45,8 @@ int pvremove(struct cmd_context *cmd, int argc, char **argv)
 
 	clear_hint_file(cmd);
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd))
+		return_ECMD_FAILED;
 
 	/* When forcibly clearing a PV we don't care about a VG lock. */
 	if (pp.force == DONT_PROMPT_OVERRIDE)
tools/pvscan.c +2 -1
index 1e47d754a..72c3279c3 100644
@@ -1407,7 +1407,8 @@ static int _pvscan_cache_all(struct cmd_context *cmd, int argc, char **argv,
 	 * which we want 'pvscan --cache' to do, and that uses
 	 * info from lvmcache, e.g. duplicate pv info.
 	 */
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd))
+		return_0;
 
 	cmd->pvscan_recreate_hints = 0;
 	cmd->use_hints = 0;
tools/toollib.c +21 -6
index d77092d89..544791808 100644
@@ -1655,7 +1655,10 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
 
 	log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LABEL);
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd)) {
+		ret_max = ECMD_FAILED;
+		goto_out;
+	}
 
 	if (argc) {
 		for (; opt < argc; opt++) {
@@ -2435,8 +2438,13 @@ int process_each_vg(struct cmd_context *cmd,
 	 * Scan all devices to populate lvmcache with initial
 	 * list of PVs and VGs.
 	 */
-	if (!(read_flags & PROCESS_SKIP_SCAN))
-		lvmcache_label_scan(cmd);
+	if (!(read_flags & PROCESS_SKIP_SCAN)) {
+		if (!lvmcache_label_scan(cmd)) {
+			ret_max = ECMD_FAILED;
+			goto_out;
+		}
+	}
+
 
 	/*
 	 * A list of all VGs on the system is needed when:
@@ -3987,7 +3995,10 @@ int process_each_lv(struct cmd_context *cmd,
 	 * Scan all devices to populate lvmcache with initial
 	 * list of PVs and VGs.
 	 */
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd)) {
+		ret_max = ECMD_FAILED;
+		goto_out;
+	}
 
 	/*
 	 * A list of all VGs on the system is needed when:
@@ -4623,8 +4634,12 @@ int process_each_pv(struct cmd_context *cmd,
 		goto_out;
 	}
 
-	if (!(read_flags & PROCESS_SKIP_SCAN))
-		lvmcache_label_scan(cmd);
+	if (!(read_flags & PROCESS_SKIP_SCAN)) {
+		if (!lvmcache_label_scan(cmd)) {
+			ret_max = ECMD_FAILED;
+			goto_out;
+		}
+	}
 
 	if (!lvmcache_get_vgnameids(cmd, &all_vgnameids, only_this_vgname, 1)) {
 		ret_max = ret;
tools/vgcfgrestore.c +4 -1
index e49313d14..9fcba89d4 100644
@@ -132,7 +132,10 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
 
 	clear_hint_file(cmd);
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd)) {
+		unlock_vg(cmd, NULL, vg_name);
+		return_ECMD_FAILED;
+	}
 
 	cmd->handles_unknown_segments = 1;
 
tools/vgcreate.c +4 -1
index dde3f1eac..14608777f 100644
@@ -84,7 +84,10 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
 
 	cmd->create_edit_devices_file = 1;
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd)) {
+		unlock_vg(cmd, NULL, vp_new.vg_name);
+		return_ECMD_FAILED;
+	}
 
 	if (lvmcache_vginfo_from_vgname(vp_new.vg_name, NULL)) {
 		unlock_vg(cmd, NULL, vp_new.vg_name);
tools/vgextend.c +2 -1
index 0856b4c78..fecd6bdd5 100644
@@ -160,7 +160,8 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
 
 	cmd->edit_devices_file = 1;
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd))
+		return_ECMD_FAILED;
 
 	if (!(handle = init_processing_handle(cmd, NULL))) {
 		log_error("Failed to initialize processing handle.");
tools/vgmerge.c +2 -1
index 08615cd62..4ed4a8f0b 100644
@@ -72,7 +72,8 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
 		return ECMD_FAILED;
 	}
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd))
+		return_ECMD_FAILED;
 
 	if (strcmp(vg_name_to, vg_name_from) > 0)
 		lock_vg_from_first = 1;
tools/vgsplit.c +2 -1
index 5f113b363..c7f4b8af4 100644
@@ -559,7 +559,8 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
 		return ECMD_FAILED;
 	}
 
-	lvmcache_label_scan(cmd);
+	if (!lvmcache_label_scan(cmd))
+		return_ECMD_FAILED;
 
 	if (!(vginfo_to = lvmcache_vginfo_from_vgname(vg_name_to, NULL))) {
 		if (!validate_name(vg_name_to)) {