Skip to contentSkip to conversation

master - pvscan: check sysfs dev entry before rescan

PATCH Zdenek Kabelac 1 participant 1 message Mar 18, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=32a6c11877946bfc34a7af0821a793fd62f6bb36
Commit:        32a6c11877946bfc34a7af0821a793fd62f6bb36
Parent:        1260b86b2b76f5b1ab5fa6c0c324d8d6f3ba2173
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Wed Mar 18 16:19:58 2015 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Wed Mar 18 16:19:58 2015 +0100

pvscan: check sysfs dev entry before rescan

When pvscan --cache --major --minor command is issued from udev REMOVE event, it basically resulted into a whole device scan since the device was missing. So avoid such scan and first check via /sysfs (when available) if such device actually exists.

---
 WHATS_NEW              |    1 +
 lib/device/dev-cache.c |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)
WHATS_NEW +1 -0
index 51307cb..7d0038a 100644
@@ -1,5 +1,6 @@
 Version 2.02.118 - 
 =================================
+  Avoid rescan of all devices when requested pvscan for removed device.
   Measure configuration timestamps with nanoseconds when available.
   Disable lvchange of major and minor of pool LVs.
   Fix pvscan --cache to not scan and read ignored metadata areas on PVs.
lib/device/dev-cache.c +19 -0
index 7ad9fb8..d594dd4 100644
@@ -986,12 +986,31 @@ static struct device *_dev_cache_seek_devt(dev_t dev)
  */
 struct device *dev_cache_get_by_devt(dev_t dev, struct dev_filter *f)
 {
+	char path[PATH_MAX];
+	const char *sysfs_dir;
+	struct stat info;
 	struct device *d = _dev_cache_seek_devt(dev);
 
 	if (d && (d->flags & DEV_REGULAR))
 		return d;
 
 	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), "%s/dev/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.",
+					  (int)MAJOR(dev), (int)MINOR(dev));
+				return NULL;
+			}
+		}
+
 		_full_scan(0);
 		d = _dev_cache_seek_devt(dev);
 	}