From: Zdenek Kabelac Date: Mon, 11 Apr 2016 08:08:16 +0000 (+0200) Subject: devcache: do not insert devices without device node X-Git-Tag: v2_02_151~76 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=fe65a86cbc98bb38014b238266a7732de42d0aa1;p=lvm2.git devcache: do not insert devices without device node When not obtaining device from udev, we are doing deep devdir scan, and at the same time we try to insert everything what /sys/dev/block knows about. However in case lvm2 is configured to use nonstardard devdir this way it will see (and scan) devices from a real system. lvm2 test suite is using its own test devdir with its own device nodes. To avoid touching real /dev devices, validate the device node exist in give dir and do not insert such device into a cache. With obtain list from udev this patch has no effect (the normal user path). --- diff --git a/WHATS_NEW b/WHATS_NEW index 777c44ee3..f4eb6ad5f 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.151 ================================= + When not obtaining devs from udev, check they exist before caching them. Detect device mismatch also when compiling without udev support. Version 2.02.150 - 9th April 2016 diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 84471ab41..6abb6a7f7 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -433,6 +433,8 @@ static struct dm_list *_get_or_add_list_by_index_key(struct dm_hash_table *idx, static struct device *_insert_sysfs_dev(dev_t devno, const char *devname) { + static struct device _fake_dev = { .flags = DEV_USED_FOR_LV }; + struct stat stat0; char path[PATH_MAX]; char *path_copy; struct device *dev; @@ -442,6 +444,13 @@ static struct device *_insert_sysfs_dev(dev_t devno, const char *devname) return NULL; } + if (lstat(path, &stat0) < 0) { + /* When device node does not exist return fake entry. + * This may happen when i.e. lvm2 device dir != /dev */ + log_debug("%s: Not available device node", path); + return &_fake_dev; + } + if (!(dev = _dev_create(devno))) return_NULL;