Blame SOURCES/0035-devices-simplify-dev_cache_get_by_devt.patch

ab86b0
From 8552290efae4905fd1a942be8e752842b11f1881 Mon Sep 17 00:00:00 2001
ab86b0
From: David Teigland <teigland@redhat.com>
ab86b0
Date: Thu, 24 Feb 2022 15:57:29 -0600
ab86b0
Subject: [PATCH 35/54] devices: simplify dev_cache_get_by_devt
ab86b0
ab86b0
remove unused args, and no callers need or want a
ab86b0
repeated dev_cache_scan if there is no dev from the
ab86b0
lookup.
ab86b0
---
ab86b0
 lib/device/dev-cache.c | 60 ++++--------------------------------------
ab86b0
 lib/device/dev-cache.h |  2 +-
ab86b0
 lib/label/label.c      |  2 +-
ab86b0
 tools/pvscan.c         |  6 ++---
ab86b0
 4 files changed, 10 insertions(+), 60 deletions(-)
ab86b0
ab86b0
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
ab86b0
index c6e5f68cf..cc1af7c7a 100644
ab86b0
--- a/lib/device/dev-cache.c
ab86b0
+++ b/lib/device/dev-cache.c
ab86b0
@@ -1577,63 +1577,13 @@ struct device *dev_cache_get(struct cmd_context *cmd, const char *name, struct d
ab86b0
 	return dev;
ab86b0
 }
ab86b0
 
ab86b0
-struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t dev, struct dev_filter *f, int *filtered)
ab86b0
+struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t devt)
ab86b0
 {
ab86b0
-	char path[PATH_MAX];
ab86b0
-	const char *sysfs_dir;
ab86b0
-	struct stat info;
ab86b0
-	struct device *d = (struct device *) btree_lookup(_cache.devices, (uint32_t) dev);
ab86b0
-	int ret;
ab86b0
-
ab86b0
-	if (filtered)
ab86b0
-		*filtered = 0;
ab86b0
-
ab86b0
-	if (!d) {
ab86b0
-		sysfs_dir = dm_sysfs_dir();
ab86b0
-		if (sysfs_dir && *sysfs_dir) {
ab86b0
-			/* First check if dev is sysfs to avoid useless scan */
ab86b0
-			if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d",
ab86b0
-					sysfs_dir, (int)MAJOR(dev), (int)MINOR(dev)) < 0) {
ab86b0
-				log_error("dm_snprintf partition failed.");
ab86b0
-				return NULL;
ab86b0
-			}
ab86b0
-
ab86b0
-			if (lstat(path, &info)) {
ab86b0
-				log_debug("No sysfs entry for %d:%d errno %d at %s.",
ab86b0
-					  (int)MAJOR(dev), (int)MINOR(dev), errno, path);
ab86b0
-				return NULL;
ab86b0
-			}
ab86b0
-		}
ab86b0
-
ab86b0
-		log_debug_devs("Device num not found in dev_cache repeat dev_cache_scan for %d:%d",
ab86b0
-				(int)MAJOR(dev), (int)MINOR(dev));
ab86b0
-		dev_cache_scan(cmd);
ab86b0
-		d = (struct device *) btree_lookup(_cache.devices, (uint32_t) dev);
ab86b0
-
ab86b0
-		if (!d)
ab86b0
-			return NULL;
ab86b0
-	}
ab86b0
-
ab86b0
-	if (d->flags & DEV_REGULAR)
ab86b0
-		return d;
ab86b0
-
ab86b0
-	if (!f)
ab86b0
-		return d;
ab86b0
-
ab86b0
-	ret = f->passes_filter(cmd, f, d, NULL);
ab86b0
-
ab86b0
-	if (ret == -EAGAIN) {
ab86b0
-		log_debug_devs("get device by number defer filter %s", dev_name(d));
ab86b0
-		d->flags |= DEV_FILTER_AFTER_SCAN;
ab86b0
-		ret = 1;
ab86b0
-	}
ab86b0
-
ab86b0
-	if (ret)
ab86b0
-		return d;
ab86b0
-
ab86b0
-	if (filtered)
ab86b0
-		*filtered = 1;
ab86b0
+	struct device *dev = (struct device *) btree_lookup(_cache.devices, (uint32_t) devt);
ab86b0
 
ab86b0
+	if (dev)
ab86b0
+		return dev;
ab86b0
+	log_debug_devs("No devno %d:%d in dev cache.", (int)MAJOR(devt), (int)MINOR(devt));
ab86b0
 	return NULL;
ab86b0
 }
ab86b0
 
ab86b0
diff --git a/lib/device/dev-cache.h b/lib/device/dev-cache.h
ab86b0
index 635dc4fc9..7305eeb0e 100644
ab86b0
--- a/lib/device/dev-cache.h
ab86b0
+++ b/lib/device/dev-cache.h
ab86b0
@@ -54,7 +54,7 @@ int dev_cache_has_scanned(void);
ab86b0
 int dev_cache_add_dir(const char *path);
ab86b0
 struct device *dev_cache_get(struct cmd_context *cmd, const char *name, struct dev_filter *f);
ab86b0
 
ab86b0
-struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t device, struct dev_filter *f, int *filtered);
ab86b0
+struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t devt);
ab86b0
 
ab86b0
 struct device *dev_hash_get(const char *name);
ab86b0
 
ab86b0
diff --git a/lib/label/label.c b/lib/label/label.c
ab86b0
index 354ab35e2..ffe925254 100644
ab86b0
--- a/lib/label/label.c
ab86b0
+++ b/lib/label/label.c
ab86b0
@@ -1443,7 +1443,7 @@ void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv
ab86b0
 	if (lv_info(cmd, lv, 0, &lvinfo, 0, 0) && lvinfo.exists) {
ab86b0
 		/* FIXME: Still unclear what is it supposed to find */
ab86b0
 		devt = MKDEV(lvinfo.major, lvinfo.minor);
ab86b0
-		if ((dev = dev_cache_get_by_devt(cmd, devt, NULL, NULL)))
ab86b0
+		if ((dev = dev_cache_get_by_devt(cmd, devt)))
ab86b0
 			label_scan_invalidate(dev);
ab86b0
 	}
ab86b0
 }
ab86b0
diff --git a/tools/pvscan.c b/tools/pvscan.c
ab86b0
index f60c4a2ca..160a2c9a0 100644
ab86b0
--- a/tools/pvscan.c
ab86b0
+++ b/tools/pvscan.c
ab86b0
@@ -857,7 +857,7 @@ static int _get_devs_from_saved_vg(struct cmd_context *cmd, const char *vgname,
ab86b0
 
ab86b0
 		devno = MKDEV(file_major, file_minor);
ab86b0
 
ab86b0
-		if (!(dev = dev_cache_get_by_devt(cmd, devno, NULL, NULL))) {
ab86b0
+		if (!(dev = dev_cache_get_by_devt(cmd, devno))) {
ab86b0
 			log_error_pvscan(cmd, "No device found for %d:%d PVID %s", file_major, file_minor, pvid);
ab86b0
 			goto bad;
ab86b0
 		}
ab86b0
@@ -1195,7 +1195,7 @@ static int _get_args_devs(struct cmd_context *cmd, struct dm_list *pvscan_args,
ab86b0
 		if (arg->devname)
ab86b0
 			arg->dev = dev_cache_get(cmd, arg->devname, NULL);
ab86b0
 		else if (arg->devno)
ab86b0
-			arg->dev = dev_cache_get_by_devt(cmd, arg->devno, NULL, NULL);
ab86b0
+			arg->dev = dev_cache_get_by_devt(cmd, arg->devno);
ab86b0
 		else
ab86b0
 			return_0;
ab86b0
 	}
ab86b0
@@ -1257,7 +1257,7 @@ static void _set_pv_devices_online(struct cmd_context *cmd, struct volume_group
ab86b0
 
ab86b0
 		devno = MKDEV(major, minor);
ab86b0
 
ab86b0
-		if (!(dev = dev_cache_get_by_devt(cmd, devno, NULL, NULL))) {
ab86b0
+		if (!(dev = dev_cache_get_by_devt(cmd, devno))) {
ab86b0
 			log_print_pvscan(cmd, "VG %s PV %s no device found for %d:%d",
ab86b0
 					 vg->name, pvid, major, minor);
ab86b0
 			pvl->pv->status |= MISSING_PV;
ab86b0
-- 
ab86b0
2.34.3
ab86b0