]> sourceware.org Git - lvm2.git/commitdiff
dev-cache: skip VGID/LVID indexing if /sys/dev/block is not present
authorPeter Rajnoha <prajnoha@redhat.com>
Fri, 1 Apr 2016 15:04:11 +0000 (17:04 +0200)
committerPeter Rajnoha <prajnoha@redhat.com>
Fri, 1 Apr 2016 15:09:15 +0000 (17:09 +0200)
/sys/dev/block is available since kernel version 2.2.26 (~ 2008):
https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-dev

The VGID/LVID indexing code relies on this feature so skip indexing
if it's not available to avoid error messages about inability to open
/sys/dev/block directory.

We're not going to provide fallback code to read the /sys/block/
instead in this case as that's not that efficient - it needs extra
reads for getting major:minor and reading partitions would also
pose further reads and that's not worth it.

lib/device/dev-cache.c

index 84bd85b1282df96e4cbfb3e7352eee8229c0f8e4..8461f40a22d42a0ea63e3dcf31a587a39d60caf5 100644 (file)
@@ -818,9 +818,8 @@ static int _dev_cache_iterate_devs_for_index(void)
        return r;
 }
 
-static int _dev_cache_iterate_sysfs_for_index(void)
+static int _dev_cache_iterate_sysfs_for_index(const char *path)
 {
-       char path[PATH_MAX];
        char devname[PATH_MAX];
        DIR *d;
        struct dirent *dirent;
@@ -830,11 +829,6 @@ static int _dev_cache_iterate_sysfs_for_index(void)
        int partial_failure = 0;
        int r = 0;
 
-       if (dm_snprintf(path, sizeof(path), "%sdev/block", dm_sysfs_dir()) < 0) {
-               log_error("_dev_cache_iterate_sysfs_for_index: dm_snprintf failed.");
-               return 0;
-       }
-
        if (!(d = opendir(path))) {
                log_sys_error("opendir", path);
                return 0;
@@ -876,11 +870,36 @@ static int _dev_cache_iterate_sysfs_for_index(void)
 
 int dev_cache_index_devs(void)
 {
+       static int sysfs_has_dev_block = -1;
+       char path[PATH_MAX];
+
+       if (dm_snprintf(path, sizeof(path), "%sdev/block", dm_sysfs_dir()) < 0) {
+               log_error("dev_cache_index_devs: dm_snprintf failed.");
+               return 0;
+       }
+
+       /* Skip indexing if /sys/dev/block is not available.*/
+       if (sysfs_has_dev_block == -1) {
+               struct stat info;
+               if (stat(path, &info) == 0)
+                       sysfs_has_dev_block = 1;
+               else {
+                       if (errno == ENOENT) {
+                               sysfs_has_dev_block = 0;
+                               return 1;
+                       } else {
+                               log_sys_error("stat", path);
+                               return 0;
+                       }
+               }
+       } else if (!sysfs_has_dev_block)
+               return 1;
+
        int with_udev = obtain_device_list_from_udev() &&
                        udev_get_library_context();
 
        return with_udev ? _dev_cache_iterate_devs_for_index()
-                        : _dev_cache_iterate_sysfs_for_index();
+                        : _dev_cache_iterate_sysfs_for_index(path);
 }
 
 #ifdef UDEV_SYNC_SUPPORT
This page took 0.042916 seconds and 5 git commands to generate.