Query udev database to avoid stat-ing and opening inappropriate devices in /dev
PATCH 1/1 Query udev database to avoid stat-ing and opening inappropriate devices in /dev
We can use udev database to iterate over block devices (together with all related symlinks) and use this to fill the cache during _full_scan call. This way, we can avoid stat-ing and opening inappropriate devices and directories (see also https://bugzilla.redhat.com/show_bug.cgi?id=682018).
There's also a new "enumerate_udev_device_directory" setting in lvm.conf with which we can turn this feature on or off.
Keep in mind that when we use udev, then any nodes created manually will be ignored (since they won't be recorded in udev database). If there are any other directories used that differ from udev directory, the scan operation fallbacks to normal non-udev way...
PS: I've used "+LVMINTERNAL_LIBS = -llvm-internal $(DL_LIBS) -ludev" for now in
make.tmpl.in. But there should be a better place for this - but I wanted to test this quickly for now :)
Peter
---
doc/example.conf.in | 9 ++++ lib/commands/toolcontext.c | 4 ++ lib/config/defaults.h | 1 + lib/device/dev-cache.c | 90 +++++++++++++++++++++++++++++++++++++++++--- lib/misc/lvm-globals.c | 11 +++++ lib/misc/lvm-globals.h | 2 + make.tmpl.in | 2 +- 7 files changed, 112 insertions(+), 7 deletions(-)
doc/example.conf.in +9 -0
@@ -19,6 +19,15 @@ devices { # to use with LVM2. scan = [ "/dev" ] + # If set, the cache of block device nodes with all associated symlinks + # will be constructed out of the existing udev database content. + # This avoids using and opening any inapplicable non-block devices or + # subdirectories found in the device directory. This setting is applied + # to udev-managed device directory only, other directories will be scanned + # fully. N.B. Any device node or symlink not managed by udev in udev + # directory will be ignored with this setting on. + enumerate_udev_device_directory = 1 + # If several entries in the scanned directories correspond to the # same block device and the tools need to display a name for device, # all the pathnames are matched against each item in the following
lib/commands/toolcontext.c +4 -0
@@ -592,6 +592,10 @@ static int _init_dev_cache(struct cmd_context *cmd)return 1 ; } +init_enumerate_udev_dev_dir ( +find_config_tree_bool (cmd,"devices/enumerate_udev_device_directory" , +DEFAULT_ENUMERATE_UDEV_DEV_DIR )); +for (cv = cn->v; cv; cv = cv->next) {if (cv->type !=CFG_STRING ) { log_error("Invalid string in config file: "
lib/config/defaults.h +1 -0
@@ -29,6 +29,7 @@#define DEFAULT_DEV_DIR "/dev"#define DEFAULT_PROC_DIR "/proc" +#define DEFAULT_ENUMERATE_UDEV_DEV_DIR 1#define DEFAULT_SYSFS_SCAN 1#define DEFAULT_MD_COMPONENT_DETECTION 1#define DEFAULT_MD_CHUNK_ALIGNMENT 1
lib/device/dev-cache.c +84 -6
136 lines not on this page · raw message
lib/misc/lvm-globals.c +11 -0
@@ -28,6 +28,7 @@ static int _test = 0;static int _md_filtering =0 ;static int _pvmove =0 ;static int _full_scan_done =0 ;/* Restrict to one full scan during each cmd */ +static int _enumerate_udev_dev_dir =DEFAULT_ENUMERATE_UDEV_DEV_DIR ;static int _trust_cache =0 ;/* Don't scan when incomplete VGs encountered */ static int _debug_level =0 ;static int _log_cmd_name =0 ;
@@ -72,6 +73,11 @@ void init_full_scan_done(int level) _full_scan_done = level; } +void init_enumerate_udev_dev_dir (int enumerate) +{ + _enumerate_udev_dev_dir = enumerate; +} +void init_trust_cache (int trustcache) { _trust_cache = trustcache;
@@ -185,6 +191,11 @@ int full_scan_done()return _full_scan_done; } +int enumerate_udev_dev_dir () +{ +return _enumerate_udev_dev_dir; +} +int trust_cache () {return _trust_cache;
lib/misc/lvm-globals.h +2 -0
@@ -25,6 +25,7 @@ void init_test(int level);void init_md_filtering (int level);void init_pvmove (int level);void init_full_scan_done (int level); +void init_enumerate_udev_dev_dir (int enumerate);void init_trust_cache (int trustcache);void init_debug (int level);void init_cmd_name (int status);
@@ -48,6 +49,7 @@ int test_mode(void);int md_filtering (void );int pvmove_mode (void );int full_scan_done (void ); +int enumerate_udev_dev_dir (void );int trust_cache (void );int verbose_level (void );int debug_level (void );
make.tmpl.in +1 -1
@@ -38,7 +38,7 @@ CLDFLAGS += @CLDFLAGS@ LDDEPS += @LDDEPS@ LDFLAGS += @LDFLAGS@ LIB_SUFFIX = @LIB_SUFFIX@ -LVMINTERNAL_LIBS = -llvm-internal $(DL_LIBS) +LVMINTERNAL_LIBS = -llvm-internal $(DL_LIBS) -ludev DL_LIBS = @DL_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@ READLINE_LIBS = @READLINE_LIBS@