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