]> sourceware.org Git - lvm2.git/commitdiff
filter-sysfs: support old kernels without sys/dev/block
authorDavid Teigland <teigland@redhat.com>
Tue, 9 Nov 2021 17:54:48 +0000 (11:54 -0600)
committerDavid Teigland <teigland@redhat.com>
Tue, 9 Nov 2021 17:54:48 +0000 (11:54 -0600)
rhel5 for example doesn't have /sys/dev/block

lib/filters/filter-sysfs.c

index 67221105704f1474cc6789044d1d130bb1fb60a8..d8de7940bbdd27fe0c3b5bbb88084c5ef9771ea2 100644 (file)
@@ -15,6 +15,8 @@
 #include "lib/misc/lib.h"
 #include "lib/filters/filter.h"
 
+static int _sys_dev_block_found;
+
 #ifdef __linux__
 
 static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev, const char *use_filter_name)
@@ -23,6 +25,9 @@ static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct devic
        const char *sysfs_dir;
        struct stat info;
 
+       if (!_sys_dev_block_found)
+               return 1;
+
        dev->filtered_flags &= ~DEV_FILTERED_SYSFS;
 
        /*
@@ -57,6 +62,26 @@ static void _destroy(struct dev_filter *f)
        free(f);
 }
 
+static void _check_sys_dev_block(void)
+{
+       char path[PATH_MAX];
+       const char *sysfs_dir;
+       struct stat info;
+
+       sysfs_dir = dm_sysfs_dir();
+       if (sysfs_dir && *sysfs_dir) {
+               if (dm_snprintf(path, sizeof(path), "%sdev/block", sysfs_dir) < 0)
+                       return;
+
+               if (lstat(path, &info)) {
+                       log_debug("filter-sysfs disabled: /sys/dev/block not found");
+                       _sys_dev_block_found = 0;
+               } else {
+                       _sys_dev_block_found = 1;
+               }
+       }
+}
+
 struct dev_filter *sysfs_filter_create(void)
 {
        const char *sysfs_dir = dm_sysfs_dir();
@@ -67,6 +92,9 @@ struct dev_filter *sysfs_filter_create(void)
                return NULL;
        }
 
+       /* support old kernels that don't have this */
+       _check_sys_dev_block();
+
        if (!(f = zalloc(sizeof(*f))))
                goto_bad;
 
This page took 0.034336 seconds and 5 git commands to generate.