multipath: Stop extra scans on stacked devices
Subsystems (2)
Benjamin Marzinski
maintainercover multipath: Stop extra scans on stacked devices
Whenever there is a DM_DEVICE_RESUME ioctl, a uevent is generated. Right now, when multipath is reloading existing devices do to paths going or coming, lvmetad will rescan those devices. This is unnecessary, and can cause a lot of overhead. Also, multipath devices with no working paths will get scanned. These patches make multipath set a new flag, DM_SUBSYSTEM_UDEV_FLAG0, when it is reloading devices due to path changes, and lvmetad can safely ignore it. They also add a new udev rules file, 11-dm-mpath.rules, to disable scanning when it would not be useful.
Benjamin Marzinski (2):
New udev rules to deal with stacked devices
Mark reloads with udev flag
Makefile.inc | 1 + kpartx/devmapper.c | 4 ++-- kpartx/devmapper.h | 8 +++++++- kpartx/kpartx.c | 8 ++++---- libmultipath/configure.c | 4 ++-- libmultipath/devmapper.c | 26 ++++++++++++++------------ libmultipath/devmapper.h | 10 ++++++++-- multipath/11-dm-mpath.rules | 34 ++++++++++++++++++++++++++++++++++ multipath/Makefile | 3 +++ multipathd/cli_handlers.c | 4 ++-- 10 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 multipath/11-dm-mpath.rules
Signature · 1 line
1.8.4.2
Benjamin Marzinski
maintainerPATCH 1/2 New udev rules to deal with stacked devices
This new rules file sets some DM_* udev environment variables to keep device mapper for doing unnecessary work on multipath device uevents. Previously, devices with no valid paths were being scanned. Also devices were being rescanned on uevents caused by paths being added or removed. These are now avoided.
--- Makefile.inc | 1 + multipath/11-dm-mpath.rules | 34 ++++++++++++++++++++++++++++++++++ multipath/Makefile | 3 +++ 3 files changed, 38 insertions(+) create mode 100644 multipath/11-dm-mpath.rules
Makefile.inc +1 -0
@@ -31,6 +31,7 @@ prefix = exec_prefix = $(prefix) bindir = $(exec_prefix)/sbin libudevdir = ${prefix}/lib/udev +udevrulesdir = $(libudevdir)/rules.d multipathdir = $(TOPDIR)/libmultipath mandir = $(prefix)/usr/share/man/man8 man5dir = $(prefix)/usr/share/man/man5
multipath/11-dm-mpath.rules new file +34 -0
@@ -0,0 +1,34 @@ +ACTION!="add|change", GOTO="mpath_end" +ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="mpath_end" +ENV{DM_UUID}!="mpath-?*", GOTO="mpath_end" + +# Do not initiate scanning if no path is available, +# otherwise there would be a hang or IO error on access. +# We'd like to avoid this, especially within udev processing. +ENV{DM_NR_VALID_PATHS}!="?*", IMPORT{db}="DM_NR_VALID_PATHS" +ENV{DM_NR_VALID_PATHS}=="0", ENV{DM_NOSCAN}="1" + +# Also skip all foreign rules if no path is available. +# Remember the original value of DM_DISABLE_OTHER_RULES_FLAG +# and restore it back once we have at least one path available. +IMPORT{db}="DM_DISABLE_OTHER_RULES_FLAG_OLD" +ENV{DM_ACTION}=="PATH_FAILED",\ + ENV{DM_NR_VALID_PATHS}=="0",\ + ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}=="",\ + ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}="$env{DM_UDEV_DISABLE_OTHER_RULES_FLAG}",\ + ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1" +ENV{DM_ACTION}=="PATH_REINSTATED",\ + ENV{DM_NR_VALID_PATHS}=="1",\ + ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="$env{DM_DISABLE_OTHER_RULES_FLAG_OLD}",\ + ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}="",\ + ENV{DM_ACTIVATION}="1" + +# DM_SUBSYSTEM_UDEV_FLAG0 is the "RELOAD" flag for multipath subsystem. +# Drop the DM_ACTIVATION flag here as mpath reloads tables if any of its +# paths are lost/recovered. For any stack above the mpath device, this is not +# something that should be reacted upon since it would be useless extra work. +# It's exactly mpath's job to provide *seamless* device access to any of the +# paths that are available underneath. +ENV{DM_SUBSYSTEM_UDEV_FLAG0}=="1", ENV{DM_ACTIVATION}="0" + +LABEL="mpath_end"
multipath/Makefile +3 -0
@@ -21,6 +21,8 @@ $(EXEC): $(OBJS) install: $(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir) $(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)/ + $(INSTALL_PROGRAM) -d $(DESTDIR)$(udevrulesdir) + $(INSTALL_PROGRAM) -m 644 11-dm-mpath.rules $(DESTDIR)$(udevrulesdir) $(INSTALL_PROGRAM) -d $(DESTDIR)$(mandir) $(INSTALL_PROGRAM) -m 644 $(EXEC).8.gz $(DESTDIR)$(mandir) $(INSTALL_PROGRAM) -d $(DESTDIR)$(man5dir)
@@ -28,6 +30,7 @@ install: uninstall: rm $(DESTDIR)$(bindir)/$(EXEC) + rm $(DESTDIR)$(udevrulesdir)/11-dm-mpath.rules rm $(DESTDIR)$(mandir)/$(EXEC).8.gz rm $(DESTDIR)$(man5dir)/$(EXEC).conf.5.gz
Signature · 1 line
1.8.4.2
Benjamin Marzinski
maintainerPATCH 2/2 Mark reloads with udev flag
In reply to Benjamin MarzinskiIn order for the udev rules to be able to distinguish uevents generated by reloads instead of creates, multipath now tags all the reload resumes with MPATH_UDEV_RELOAD_FLAG, which is defined as the first multipath dm subsystem udev flag. 11-dm-mpath.rules watches for multipath events tag.
--- kpartx/devmapper.c | 4 ++-- kpartx/devmapper.h | 8 +++++++- kpartx/kpartx.c | 8 ++++---- libmultipath/configure.c | 4 ++-- libmultipath/devmapper.c | 26 ++++++++++++++------------ libmultipath/devmapper.h | 10 ++++++++-- multipathd/cli_handlers.c | 4 ++-- 7 files changed, 39 insertions(+), 25 deletions(-)
kpartx/devmapper.c +2 -2
@@ -60,7 +60,7 @@ dm_prereq (char * str, int x, int y, int z) }extern int -dm_simplecmd (int task,const char *name,int no_flush,uint32_t *cookie) { +dm_simplecmd (int task,const char *name,int no_flush,uint32_t *cookie,uint16_t udev_flags) {int r =0 ;int udev_wait_flag = (task ==DM_DEVICE_RESUME || task ==DM_DEVICE_REMOVE );
@@ -78,7 +78,7 @@ dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie) {if (no_flush)dm_task_no_flush (dmt); -if (udev_wait_flag && !dm_task_set_cookie (dmt, cookie, (udev_sync)?0 :DM_UDEV_DISABLE_LIBRARY_FALLBACK )) +if (udev_wait_flag && !dm_task_set_cookie (dmt, cookie, ((udev_sync)?0 :DM_UDEV_DISABLE_LIBRARY_FALLBACK ) | udev_flags)) goto out; r =dm_task_run (dmt);
kpartx/devmapper.h +7 -1
@@ -2,10 +2,16 @@#define MINOR (dev) ((dev & 0xff) | ((dev >> 12) & 0xfff00))#define MKDEV (ma,mi) ((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12)) +#ifdef DM_SUBSYSTEM_UDEV_FLAG0 +#define MPATH_UDEV_RELOAD_FLAG DM_SUBSYSTEM_UDEV_FLAG0 +#else +#define MPATH_UDEV_RELOAD_FLAG 0 +#endif +extern int udev_sync;int dm_prereq (char *,int ,int ,int ); -int dm_simplecmd (int ,const char *,int ,uint32_t *); +int dm_simplecmd (int ,const char *,int ,uint32_t *,uint16_t );int dm_addmap (int ,const char *,const char *,const char *,uint64_t ,int ,const char *,int ,mode_t ,uid_t ,gid_t ,uint32_t *);int dm_map_present (char *);
kpartx/kpartx.c +4 -4
@@ -440,7 +440,7 @@ main(int argc, char **argv){continue ;if (!dm_simplecmd (DM_DEVICE_REMOVE , partname, -0 , &cookie)) { +0 , &cookie,0 )) { r++;continue ; }
@@ -498,7 +498,7 @@ main(int argc, char **argv){ }if (op ==DM_DEVICE_RELOAD && !dm_simplecmd (DM_DEVICE_RESUME , partname, -1 , &cookie)) { +1 , &cookie,MPATH_UDEV_RELOAD_FLAG )) {fprintf (stderr,"resume failed on %s\n" , partname); r++;
@@ -560,7 +560,7 @@ main(int argc, char **argv){if (op ==DM_DEVICE_RELOAD )dm_simplecmd (DM_DEVICE_RESUME , partname,1 , - &cookie); + &cookie,MPATH_UDEV_RELOAD_FLAG );dm_devn (partname, &slices[j].major, &slices[j].minor);
@@ -593,7 +593,7 @@ main(int argc, char **argv){continue ;if (!dm_simplecmd (DM_DEVICE_REMOVE , - partname,1 , &cookie)) { + partname,1 , &cookie,0 )) { r++;continue ; }
libmultipath/configure.c +2 -2
@@ -389,13 +389,13 @@ domap (struct multipath * mpp, char * params)case ACT_RELOAD : r =dm_addmap_reload (mpp, params);if (r) - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias); + r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias,MPATH_UDEV_RELOAD_FLAG );break ;case ACT_RESIZE : r =dm_addmap_reload (mpp, params);if (r) - r =dm_simplecmd_flush (DM_DEVICE_RESUME , mpp->alias,1 ); + r =dm_simplecmd_flush (DM_DEVICE_RESUME , mpp->alias,1 ,0 );break ;case ACT_RENAME :
libmultipath/devmapper.c +14 -12
@@ -105,7 +105,9 @@ dm_lib_prereq (void) {char version[64 ];int v[3 ]; -#ifdef LIBDM_API_COOKIE +#if defined(DM_SUBSYSTEM_UDEV_FLAG0 ) +int minv[3 ] = {1 ,2 ,82 }; +#elif defined(LIBDM_API_COOKIE )int minv[3 ] = {1 ,2 ,38 };#else int minv[3 ] = {1 ,2 ,8 };
@@ -202,7 +204,7 @@ dm_prereq (void) }static int -dm_simplecmd (int task,const char *name,int no_flush,int need_sync) { +dm_simplecmd (int task,const char *name,int no_flush,int need_sync,uint16_t udev_flags) {int r =0 ;int udev_wait_flag = (need_sync && (task ==DM_DEVICE_RESUME || task ==DM_DEVICE_REMOVE ));
@@ -221,7 +223,7 @@ dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {dm_task_no_flush (dmt);/* for DM_DEVICE_SUSPEND/RESUME */ #endif -if (udev_wait_flag && !dm_task_set_cookie (dmt, &conf->cookie, (conf->daemon)?DM_UDEV_DISABLE_LIBRARY_FALLBACK :0 )) +if (udev_wait_flag && !dm_task_set_cookie (dmt, &conf->cookie, ((conf->daemon)?DM_UDEV_DISABLE_LIBRARY_FALLBACK :0 ) | udev_flags)) goto out; r =dm_task_run (dmt);
@@ -231,13 +233,13 @@ dm_simplecmd (int task, const char *name, int no_flush, int need_sync) { }extern int -dm_simplecmd_flush (int task,const char *name,int needsync) { -return dm_simplecmd (task, name,0 , needsync); +dm_simplecmd_flush (int task,const char *name,int needsync,uint16_t udev_flags) { +return dm_simplecmd (task, name,0 , needsync, udev_flags); }extern int -dm_simplecmd_noflush (int task,const char *name) { -return dm_simplecmd (task, name,1 ,1 ); +dm_simplecmd_noflush (int task,const char *name,uint16_t udev_flags) { +return dm_simplecmd (task, name,1 ,1 , udev_flags); } extern int
@@ -672,7 +674,7 @@ _dm_flush_map (const char * mapname, int need_sync)return 1 ; } - r =dm_simplecmd_flush (DM_DEVICE_REMOVE , mapname, need_sync); + r =dm_simplecmd_flush (DM_DEVICE_REMOVE , mapname, need_sync,0 );if (r) {condlog (4 ,"multipath map %s removed" , mapname);
@@ -705,14 +707,14 @@ dm_suspend_and_flush_map (const char * mapname)if (s) queue_if_no_path =0 ;else - s =dm_simplecmd_flush (DM_DEVICE_SUSPEND , mapname,0 ); + s =dm_simplecmd_flush (DM_DEVICE_SUSPEND , mapname,0 ,0 );if (!dm_flush_map (mapname)) {condlog (4 ,"multipath map %s removed" , mapname);return 0 ; }condlog (2 ,"failed to remove multipath map %s" , mapname); -dm_simplecmd_noflush (DM_DEVICE_RESUME , mapname); +dm_simplecmd_noflush (DM_DEVICE_RESUME , mapname,0 );if (queue_if_no_path) s =dm_queue_if_no_path ((char *)mapname,1 );return 1 ;
@@ -1069,7 +1071,7 @@ dm_remove_partmaps (const char * mapname, int need_sync)condlog (4 ,"partition map %s removed" , names->name);dm_simplecmd_flush (DM_DEVICE_REMOVE , names->name, - need_sync); + need_sync,0 ); } next = names->next;
@@ -1297,7 +1299,7 @@ int dm_reassign_table(const char *name, char *old, char *new)condlog (3 ,"%s: failed to reassign targets" , name); goto out_reload; } -dm_simplecmd_noflush (DM_DEVICE_RESUME , name); +dm_simplecmd_noflush (DM_DEVICE_RESUME , name,MPATH_UDEV_RELOAD_FLAG ); } r =1 ;
libmultipath/devmapper.h +8 -2
@@ -6,11 +6,17 @@#define TGT_MPATH "multipath"#define TGT_PART "linear" +#ifdef DM_SUBSYSTEM_UDEV_FLAG0 +#define MPATH_UDEV_RELOAD_FLAG DM_SUBSYSTEM_UDEV_FLAG0 +#else +#define MPATH_UDEV_RELOAD_FLAG 0 +#endif +void dm_init (void );int dm_prereq (void );int dm_drv_version (unsigned int * version,char * str); -int dm_simplecmd_flush (int ,const char *,int ); -int dm_simplecmd_noflush (int ,const char *); +int dm_simplecmd_flush (int ,const char *,int ,uint16_t ); +int dm_simplecmd_noflush (int ,const char *,uint16_t );int dm_addmap_create (struct multipath *mpp,char *params);int dm_addmap_reload (struct multipath *mpp,char *params);int dm_map_present (const char *);
multipathd/cli_handlers.c +2 -2
@@ -785,7 +785,7 @@ cli_suspend(void * v, char ** reply, int * len, void * data) {struct vectors * vecs = (struct vectors *)data;char * param =get_keyparam (v,MAP ); -int r =dm_simplecmd_noflush (DM_DEVICE_SUSPEND , param); +int r =dm_simplecmd_noflush (DM_DEVICE_SUSPEND , param,0 ); param =convert_dev (param,0 );condlog (2 ,"%s: suspend (operator)" , param);
@@ -807,7 +807,7 @@ cli_resume(void * v, char ** reply, int * len, void * data) {struct vectors * vecs = (struct vectors *)data;char * param =get_keyparam (v,MAP ); -int r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param); +int r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,0 ); param =convert_dev (param,0 );condlog (2 ,"%s: resume (operator)" , param);
Signature · 1 line
1.8.4.2