Blame SOURCES/0031-lvmdevices-make-deldev-work-for-missing-device.patch

ab86b0
From df2b1555aff71452cde156badec70117065c9e2c Mon Sep 17 00:00:00 2001
ab86b0
From: David Teigland <teigland@redhat.com>
ab86b0
Date: Thu, 3 Feb 2022 16:56:03 -0600
ab86b0
Subject: [PATCH 31/54] lvmdevices: make deldev work for missing device
ab86b0
ab86b0
---
ab86b0
 lib/device/device_id.c |  6 +++---
ab86b0
 lib/device/device_id.h |  1 +
ab86b0
 tools/lvmdevices.c     | 33 ++++++++++++++++-----------------
ab86b0
 3 files changed, 20 insertions(+), 20 deletions(-)
ab86b0
ab86b0
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
ab86b0
index ccc5f43a1..aeaa1ffc6 100644
ab86b0
--- a/lib/device/device_id.c
ab86b0
+++ b/lib/device/device_id.c
ab86b0
@@ -894,7 +894,7 @@ struct dev_use *get_du_for_pvid(struct cmd_context *cmd, const char *pvid)
ab86b0
 	return NULL;
ab86b0
 }
ab86b0
 
ab86b0
-static struct dev_use *_get_du_for_devname(struct cmd_context *cmd, const char *devname)
ab86b0
+struct dev_use *get_du_for_devname(struct cmd_context *cmd, const char *devname)
ab86b0
 {
ab86b0
 	struct dev_use *du;
ab86b0
 
ab86b0
@@ -1093,7 +1093,7 @@ id_done:
ab86b0
 	du_pvid = get_du_for_pvid(cmd, pvid);
ab86b0
 
ab86b0
 	/* Is there already an entry using this device's name? */
ab86b0
-	du_devname = _get_du_for_devname(cmd, dev_name(dev));
ab86b0
+	du_devname = get_du_for_devname(cmd, dev_name(dev));
ab86b0
 
ab86b0
 	/* Is there already an entry using the device_id for this device? */
ab86b0
 	du_devid = _get_du_for_device_id(cmd, id->idtype, id->idname);
ab86b0
@@ -1514,7 +1514,7 @@ int device_ids_match_dev(struct cmd_context *cmd, struct device *dev)
ab86b0
 	struct dev_use *du;
ab86b0
 
ab86b0
 	/* First check the du entry with matching devname since it's likely correct. */
ab86b0
-	if ((du = _get_du_for_devname(cmd, dev_name(dev)))) {
ab86b0
+	if ((du = get_du_for_devname(cmd, dev_name(dev)))) {
ab86b0
 		if (_match_du_to_dev(cmd, du, dev))
ab86b0
 			return 1;
ab86b0
 	}
ab86b0
diff --git a/lib/device/device_id.h b/lib/device/device_id.h
ab86b0
index 4cf1374c8..2cd2fd7c6 100644
ab86b0
--- a/lib/device/device_id.h
ab86b0
+++ b/lib/device/device_id.h
ab86b0
@@ -40,6 +40,7 @@ void device_id_update_vg_uuid(struct cmd_context *cmd, struct volume_group *vg,
ab86b0
 
ab86b0
 struct dev_use *get_du_for_dev(struct cmd_context *cmd, struct device *dev);
ab86b0
 struct dev_use *get_du_for_pvid(struct cmd_context *cmd, const char *pvid);
ab86b0
+struct dev_use *get_du_for_devname(struct cmd_context *cmd, const char *devname);
ab86b0
 
ab86b0
 char *devices_file_version(void);
ab86b0
 int devices_file_exists(struct cmd_context *cmd);
ab86b0
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
ab86b0
index c50c09f90..662b35f9a 100644
ab86b0
--- a/tools/lvmdevices.c
ab86b0
+++ b/tools/lvmdevices.c
ab86b0
@@ -383,28 +383,27 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
ab86b0
 		 * No filter because we always want to allow removing a device
ab86b0
 		 * by name from the devices file.
ab86b0
 		 */
ab86b0
-		if (!(dev = dev_cache_get(cmd, devname, NULL))) {
ab86b0
-			log_error("No device found for %s.", devname);
ab86b0
-			goto bad;
ab86b0
-		}
ab86b0
-
ab86b0
-		/*
ab86b0
-		 * dev_cache_scan uses sysfs to check if an LV is using each dev
ab86b0
-		 * and sets this flag is so.
ab86b0
-		 */
ab86b0
-		if (dev_is_used_by_active_lv(cmd, dev, NULL, NULL, NULL, NULL)) {
ab86b0
-			if (!arg_count(cmd, yes_ARG) &&
ab86b0
-			    yes_no_prompt("Device %s is used by an active LV, continue to remove? ", devname) == 'n') {
ab86b0
-				log_error("Device not removed.");
ab86b0
-				goto bad;
ab86b0
+		if ((dev = dev_cache_get(cmd, devname, NULL))) {
ab86b0
+			/*
ab86b0
+			 * dev_cache_scan uses sysfs to check if an LV is using each dev
ab86b0
+			 * and sets this flag is so.
ab86b0
+			 */
ab86b0
+			if (dev_is_used_by_active_lv(cmd, dev, NULL, NULL, NULL, NULL)) {
ab86b0
+				if (!arg_count(cmd, yes_ARG) &&
ab86b0
+			    	    yes_no_prompt("Device %s is used by an active LV, continue to remove? ", devname) == 'n') {
ab86b0
+					log_error("Device not removed.");
ab86b0
+					goto bad;
ab86b0
+				}
ab86b0
 			}
ab86b0
+			if ((du = get_du_for_dev(cmd, dev)))
ab86b0
+				goto dev_del;
ab86b0
 		}
ab86b0
 
ab86b0
-		if (!(du = get_du_for_dev(cmd, dev))) {
ab86b0
-			log_error("Device not found in devices file.");
ab86b0
+		if (!(du = get_du_for_devname(cmd, devname))) {
ab86b0
+			log_error("No devices file entry for %s.", devname);
ab86b0
 			goto bad;
ab86b0
 		}
ab86b0
-
ab86b0
+ dev_del:
ab86b0
 		dm_list_del(&du->list);
ab86b0
 		free_du(du);
ab86b0
 		device_ids_write(cmd);
ab86b0
-- 
ab86b0
2.34.3
ab86b0