multipathd 'cookie' handling rework
v2 cover multipathd 'cookie' handling rework
Hi all,
here's now the second attempt to fixup the 'cookie' handling in multipath-tools.
I've removed the patch to pass in a cookie as an argument for dm_addmap_reload() and dm_simplecmd().
And I've removed all instances where we had been calling dm_udev_complete() after failing to set the cookie to a task.
As usual, reviews and comments are welcome.
Hannes Reinecke (7):
devmapper: do not flush I/O for DM_DEVICE_CREATE
devmapper: do not call dm_udev_complete if dm_task_set_cookie() failed
configure: Rename ACT_RENAME2 to ACT_FORCERENAME
devmapper: wait for udev in dm_simplecmd_noflush()
multipathd: wait for udev in cli_resume()
devmapper: remove 'udev_sync' argument from dm_simplecmd_noflush()
libmultipath: Fixup 'DM_DEVICE_RELOAD' handling
libmultipath/configure.c | 20 ++++--------- libmultipath/configure.h | 2 +- libmultipath/devmapper.c | 75 +++++++++++++++++++++++++++++++---------------- libmultipath/devmapper.h | 4 +-- multipathd/cli_handlers.c | 4 +-- 5 files changed, 60 insertions(+), 45 deletions(-)
Signature · 1 line
2.6.6
PATCH v2 1/7 devmapper: do not flush I/O for DM_DEVICE_CREATE
DM_DEVICE_CREATE loads a new table, so there cannot be any I/O pending. Hence we should be setting the 'no flush' and 'skip lockfs' flag to avoid delays during creation.
--- libmultipath/devmapper.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
libmultipath/devmapper.c +16 -9
@@ -285,16 +285,23 @@ dm_addmap (int task, const char *target, struct multipath *mpp,if (ro)dm_task_set_ro (dmt); -if ((task ==DM_DEVICE_CREATE ) &&strlen (mpp->wwid) >0 ){ - prefixed_uuid =MALLOC (UUID_PREFIX_LEN +strlen (mpp->wwid) +1 ); -if (!prefixed_uuid) { -condlog (0 ,"cannot create prefixed uuid : %s" , -strerror (errno)); - goto addout; +if (task ==DM_DEVICE_CREATE ) { +if (strlen (mpp->wwid) >0 ) { + prefixed_uuid =MALLOC (UUID_PREFIX_LEN + +strlen (mpp->wwid) +1 ); +if (!prefixed_uuid) { +condlog (0 ,"cannot create prefixed uuid : %s" , +strerror (errno)); + goto addout; + } +sprintf (prefixed_uuid,UUID_PREFIX "%s" , mpp->wwid); +if (!dm_task_set_uuid (dmt, prefixed_uuid)) + goto freeout; } -sprintf (prefixed_uuid,UUID_PREFIX "%s" , mpp->wwid); -if (!dm_task_set_uuid (dmt, prefixed_uuid)) - goto freeout; +dm_task_skip_lockfs (dmt); +#ifdef LIBDM_API_FLUSH +dm_task_no_flush (dmt); +#endif } if (mpp->attribute_flags & (1 << ATTR_MODE) &&
Signature · 1 line
2.6.6
PATCH v2 2/7 devmapper: do not call dm_udev_complete if dm_task_set_cookie() failed
In reply to Hannes ReineckeAs per Benjamin Marzinski libdevice-mapper will take care of cleaning up the cookie for us.
So there's no need to call dm_udev_complete() if dm_task_set_cookie() fails.
--- libmultipath/devmapper.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
libmultipath/devmapper.c +4 -6
@@ -232,10 +232,9 @@ dm_simplecmd (int task, const char *name, int no_flush, int need_sync, uint16_t#endif if (udev_wait_flag && !dm_task_set_cookie (dmt, &cookie, -DM_UDEV_DISABLE_LIBRARY_FALLBACK | udev_flags)) { -dm_udev_complete (cookie); +DM_UDEV_DISABLE_LIBRARY_FALLBACK | udev_flags)) goto out; - } + r =dm_task_run (dmt);if (udev_wait_flag) {
@@ -320,10 +319,9 @@ dm_addmap (int task, const char *target, struct multipath *mpp,if (task ==DM_DEVICE_CREATE && !dm_task_set_cookie (dmt, &cookie, -DM_UDEV_DISABLE_LIBRARY_FALLBACK )) { -dm_udev_complete (cookie); +DM_UDEV_DISABLE_LIBRARY_FALLBACK )) goto freeout; - } + r =dm_task_run (dmt);if (task ==DM_DEVICE_CREATE ) {
Signature · 1 line
2.6.6
PATCH v2 3/7 configure: Rename ACT_RENAME2 to ACT_FORCERENAME
In reply to Hannes ReineckeUse a more descriptive name instead of 'ACT_RENAME2'.
--- libmultipath/configure.c | 4 ++-- libmultipath/configure.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
libmultipath/configure.c +2 -2
@@ -398,7 +398,7 @@ select_action (struct multipath * mpp, vector curmp, int force_reload)strncpy (mpp->alias_old, cmpp->alias,WWID_SIZE ); mpp->action =ACT_RENAME ;if (force_reload) - mpp->action =ACT_RENAME2 ; + mpp->action =ACT_FORCERENAME ;return ; } mpp->action =ACT_CREATE ;
@@ -641,7 +641,7 @@ domap (struct multipath * mpp, char * params) r =dm_rename (mpp->alias_old, mpp->alias);break ; -case ACT_RENAME2 : +case ACT_FORCERENAME : r =dm_rename (mpp->alias_old, mpp->alias);if (r) { r =dm_addmap_reload (mpp, params);
libmultipath/configure.h +1 -1
@@ -18,7 +18,7 @@ enum actions {ACT_RENAME ,ACT_CREATE ,ACT_RESIZE , - ACT_RENAME2, + ACT_FORCERENAME, };#define FLUSH_ONE 1
Signature · 1 line
2.6.6
PATCH v2 4/7 devmapper: wait for udev in dm_simplecmd_noflush()
In reply to Hannes ReineckeWhen calling dm_simplecmd_noflush() with udev_flags set we need to set the 'need_sync' flag otherwise the udev flags will never be set.
--- libmultipath/configure.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libmultipath/configure.c +4 -2
@@ -628,7 +628,7 @@ domap (struct multipath * mpp, char * params) r =dm_addmap_reload (mpp, params);if (r) r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, -0 ,MPATH_UDEV_RELOAD_FLAG ); +1 ,MPATH_UDEV_RELOAD_FLAG );break ;case ACT_RESIZE :
@@ -646,7 +646,9 @@ domap (struct multipath * mpp, char * params)if (r) { r =dm_addmap_reload (mpp, params);if (r) - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias,0 ,MPATH_UDEV_RELOAD_FLAG ); + r =dm_simplecmd_noflush (DM_DEVICE_RESUME , + mpp->alias,1 , +MPATH_UDEV_RELOAD_FLAG ); }break ;
Signature · 1 line
2.6.6
PATCH v2 5/7 multipathd: wait for udev in cli_resume()
In reply to Hannes ReineckeWhen calling 'cli_resume()' we should be waiting for udev to ensure the device really has been resumed.
--- multipathd/cli_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
multipathd/cli_handlers.c +1 -1
@@ -967,7 +967,7 @@ cli_resume(void * v, char ** reply, int * len, void * data)return 1 ; } - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,0 ,0 ); + r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,1 ,0 );condlog (2 ,"%s: resume (operator)" , param);
Signature · 1 line
2.6.6
PATCH v2 6/7 devmapper: remove 'udev_sync' argument from dm_simplecmd_noflush()
In reply to Hannes ReineckeThe 'udev_sync' argument is always '1', so we can remove it.
--- libmultipath/configure.c | 4 ++-- libmultipath/devmapper.c | 9 +++++---- libmultipath/devmapper.h | 2 +- multipathd/cli_handlers.c | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-)
libmultipath/configure.c +2 -2
@@ -628,7 +628,7 @@ domap (struct multipath * mpp, char * params) r =dm_addmap_reload (mpp, params);if (r) r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, -1 ,MPATH_UDEV_RELOAD_FLAG ); +MPATH_UDEV_RELOAD_FLAG );break ;case ACT_RESIZE :
@@ -647,7 +647,7 @@ domap (struct multipath * mpp, char * params) r =dm_addmap_reload (mpp, params);if (r) r =dm_simplecmd_noflush (DM_DEVICE_RESUME , - mpp->alias,1 , + mpp->alias,MPATH_UDEV_RELOAD_FLAG ); }break ;
libmultipath/devmapper.c +5 -4
@@ -254,8 +254,8 @@ dm_simplecmd_flush (int task, const char *name, uint16_t udev_flags) { }extern int -dm_simplecmd_noflush (int task,const char *name,int needsync,uint16_t udev_flags) { -return dm_simplecmd (task, name,1 , needsync, udev_flags,0 ); +dm_simplecmd_noflush (int task,const char *name,uint16_t udev_flags) { +return dm_simplecmd (task, name,1 ,1 , udev_flags,0 ); } static int
@@ -847,7 +847,7 @@ dm_suspend_and_flush_map (const char * mapname)return 0 ; }condlog (2 ,"failed to remove multipath map %s" , mapname); -dm_simplecmd_noflush (DM_DEVICE_RESUME , mapname,1 ,0 ); +dm_simplecmd_noflush (DM_DEVICE_RESUME , mapname,0 );if (queue_if_no_path) s =dm_queue_if_no_path ((char *)mapname,1 );return 1 ;
@@ -1486,7 +1486,8 @@ 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,1 ,MPATH_UDEV_RELOAD_FLAG ); +dm_simplecmd_noflush (DM_DEVICE_RESUME , name, +MPATH_UDEV_RELOAD_FLAG ); } r =1 ;
libmultipath/devmapper.h +1 -1
@@ -16,7 +16,7 @@ void dm_init(void);int dm_prereq (void );int dm_drv_version (unsigned int * version,char * str);int dm_simplecmd_flush (int ,const char *,uint16_t ); -int dm_simplecmd_noflush (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
@@ -937,7 +937,7 @@ cli_suspend(void * v, char ** reply, int * len, void * data)return 1 ; } - r =dm_simplecmd_noflush (DM_DEVICE_SUSPEND , param,0 ,0 ); + r =dm_simplecmd_noflush (DM_DEVICE_SUSPEND , param,0 );condlog (2 ,"%s: suspend (operator)" , param);
@@ -967,7 +967,7 @@ cli_resume(void * v, char ** reply, int * len, void * data)return 1 ; } - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,1 ,0 ); + r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,0 );condlog (2 ,"%s: resume (operator)" , param);
Signature · 1 line
2.6.6
PATCH v2 7/7 libmultipath: Fixup 'DM_DEVICE_RELOAD' handling
In reply to Hannes Reineckelibdevmapper has the 'quirk' that DM_DEVICE_CREATE is translated internally into a create/load/resume sequence, and the associated cookie will wait for the last 'resume' to complete. However, DM_DEVICE_RELOAD has no such translation, so if there is a cookie assigned to it the caller _cannot_ wait for it, as the cookie will only ever be completed upon the next DM_DEVICE_RESUME.
multipathd already has some provisions for that (but even there the cookie handling is dodgy), but 'multipath -r' doesn't know about this.
So to avoid any future irritations this patch updates the dm_addmad_reload() call to handle the call to DM_DEVICE_RESUME correctly and removes the special handling from domap().
--- libmultipath/configure.c | 18 ++++-------------- libmultipath/devmapper.c | 31 ++++++++++++++++++++++++------- libmultipath/devmapper.h | 2 +- 3 files changed, 29 insertions(+), 22 deletions(-)
libmultipath/configure.c +4 -14
@@ -625,16 +625,11 @@ domap (struct multipath * mpp, char * params)break ;case ACT_RELOAD : - r =dm_addmap_reload (mpp, params); -if (r) - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, -MPATH_UDEV_RELOAD_FLAG ); + r =dm_addmap_reload (mpp, params,0 );break ;case ACT_RESIZE : - r =dm_addmap_reload (mpp, params); -if (r) - r =dm_simplecmd_flush (DM_DEVICE_RESUME , mpp->alias,0 ); + r =dm_addmap_reload (mpp, params,1 );break ;case ACT_RENAME :
@@ -643,13 +638,8 @@ domap (struct multipath * mpp, char * params)case ACT_FORCERENAME : r =dm_rename (mpp->alias_old, mpp->alias); -if (r) { - r =dm_addmap_reload (mpp, params); -if (r) - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , - mpp->alias, -MPATH_UDEV_RELOAD_FLAG ); - } +if (r) + r =dm_addmap_reload (mpp, params,0 );break ;default :
libmultipath/devmapper.c +24 -7
@@ -312,7 +312,8 @@ dm_addmap (int task, const char *target, struct multipath *mpp,if (mpp->attribute_flags & (1 <<ATTR_GID ) && !dm_task_set_gid (dmt, mpp->gid)) goto freeout; -condlog (4 ,"%s: addmap [0 %llu %s %s]" , mpp->alias, mpp->size, +condlog (4 ,"%s: %s [0 %llu %s %s]" , mpp->alias, + task ==DM_DEVICE_RELOAD ?"reload" :"addmap" , mpp->size, target, params);dm_task_no_open_count (dmt);
@@ -371,12 +372,28 @@ dm_addmap_create (struct multipath *mpp, char * params) {#define ADDMAP_RO 1extern int -dm_addmap_reload (struct multipath *mpp,char *params) { -if (dm_addmap (DM_DEVICE_RELOAD ,TGT_MPATH , mpp, params,ADDMAP_RW )) -return 1 ; -if (errno !=EROFS ) -return 0 ; -return dm_addmap (DM_DEVICE_RELOAD ,TGT_MPATH , mpp, params,ADDMAP_RO ); +dm_addmap_reload (struct multipath *mpp,char *params,int flush) +{ +int r; +uint16_t udev_flags = flush ?0 :MPATH_UDEV_RELOAD_FLAG ; + +/* +* DM_DEVICE_RELOAD cannot wait on a cookie, as +* the cookie will only ever be released after an +* DM_DEVICE_RESUME. So call DM_DEVICE_RESUME +* after each successful call to DM_DEVICE_RELOAD. +*/ + r =dm_addmap (DM_DEVICE_RELOAD ,TGT_MPATH , mpp, params,ADDMAP_RW ); +if (!r) { +if (errno !=EROFS ) +return 0 ; + r =dm_addmap (DM_DEVICE_RELOAD ,TGT_MPATH , mpp, + params,ADDMAP_RO ); + } +if (r) + r =dm_simplecmd (DM_DEVICE_RESUME , mpp->alias, flush, +1 , udev_flags,0 ); +return r; } extern int
libmultipath/devmapper.h +1 -1
@@ -18,7 +18,7 @@ int dm_drv_version (unsigned int * version, char * str);int dm_simplecmd_flush (int ,const char *,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_addmap_reload (struct multipath *mpp,char *params,int flush);int dm_map_present (const char *);int dm_get_map (const char *,unsigned long long *,char *);int dm_get_status (char *,char *);
Signature · 1 line
2.6.6
Benjamin Marzinski
maintainerRe: [PATCH 4/7] devmapper: wait for udev in dm_simplecmd_noflush()
In reply to Hannes ReineckeQuoted 3 lines · Hannes Reinecke
When calling
dm_simplecmd_noflush()withudev_flagsset we need to set the 'need_sync' flag otherwise the udev flags will never be set.
The other possibility here would be to temporarily disable udev sync support, and then restore it afterwards. That way we could still pass the flags, but we wouldn't need to wait on these table reloads. Either that or to get libdevmapper to give us a cookie flag that says, "while, I do have sync support enabled, for this one command, I'd like to skip it". But neither of those options has any significant benefit over this solution.
ACK.
-Ben
Quoted 32 lines
Signed-off-by Hannes Reinecke <[email protected]>--- libmultipath/configure.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)libmultipath/configure.c +4
-2@@ -628,7 +628,7 @@ domap (struct multipath * mpp, char * params) r =dm_addmap_reload (mpp, params);if (r) r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, -0 ,MPATH_UDEV_RELOAD_FLAG ); +1 ,MPATH_UDEV_RELOAD_FLAG );break ;case ACT_RESIZE :@@ -646,7 +646,9 @@ domap (struct multipath * mpp, char * params)if (r) { r =dm_addmap_reload (mpp, params);if (r) - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias,0 ,MPATH_UDEV_RELOAD_FLAG ); + r =dm_simplecmd_noflush (DM_DEVICE_RESUME , + mpp->alias,1 , +MPATH_UDEV_RELOAD_FLAG ); }break ;Signature · 1 line
2.6.6
Benjamin Marzinski
maintainerRe: [PATCH 5/7] multipathd: wait for udev in cli_resume()
In reply to Hannes ReineckeQuoted 2 lines · Hannes Reinecke
When calling '
cli_resume()' we should be waiting for udev to ensure the device really has been resumed.
Since multipathd has udev sync support disabled, this change doesn't do anything (which is fine, since I don't see any need to wait for udev here). It does allow your next patch to remove the need_sync option, which is (I assume) the bigger point.
ACK
-Ben
Quoted 21 lines
Signed-off-by Hannes Reinecke <[email protected]>--- multipathd/cli_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)multipathd/cli_handlers.c +1
-1@@ -967,7 +967,7 @@ cli_resume(void * v, char ** reply, int * len, void * data)return 1 ; } - r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,0 ,0 ); + r =dm_simplecmd_noflush (DM_DEVICE_RESUME , param,1 ,0 );condlog (2 ,"%s: resume (operator)" , param);Signature · 1 line
2.6.6
Benjamin Marzinski
maintainerQuoted 10 lines · Hannes Reinecke
Hi all,
here's now the second attempt to fixup the 'cookie' handling in multipath-tools.
I've removed the patch to pass in a cookie as an argument fordm_addmap_reload()anddm_simplecmd().
And I've removed all instances where we had been callingdm_udev_complete()after failing to set the cookie to a task.As usual, reviews and comments are welcome.
ACK for the whole set.
Thanks for working through all this.
-Ben
Quoted 19 lines
Hannes Reinecke (7):
devmapper: do not flush I/O forDM_DEVICE_CREATE
devmapper: do not calldm_udev_completeifdm_task_set_cookie()failed
configure: RenameACT_RENAME2toACT_FORCERENAME
devmapper: wait for udev indm_simplecmd_noflush()
multipathd: wait for udev incli_resume()
devmapper: remove 'udev_sync' argument fromdm_simplecmd_noflush()
libmultipath: Fixup 'DM_DEVICE_RELOAD' handlinglibmultipath/configure.c | 20 ++++--------- libmultipath/configure.h | 2 +- libmultipath/devmapper.c | 75 +++++++++++++++++++++++++++++++---------------- libmultipath/devmapper.h | 4 +-- multipathd/cli_handlers.c | 4 +-- 5 files changed, 60 insertions(+), 45 deletions(-)Signature · 1 line
2.6.6
Merged.
multipath.conf.* are dropped.
the version code is bumped to 0.6.1
Thanks,
Christophe Varoqui
www.opensvc.com
Quoted 38 lines · Benjamin Marzinski
Quoted 10 lines · Hannes Reinecke
Hi all,
here's now the second attempt to fixup the 'cookie' handling in multipath-tools.
I've removed the patch to pass in a cookie as an argument fordm_addmap_reload()anddm_simplecmd().
And I've removed all instances where we had been callingdm_udev_complete()after failing to set the cookie to a task.As usual, reviews and comments are welcome.
ACK for the whole set.
Thanks for working through all this.
-BenQuoted 10 lines
Hannes Reinecke (7):
devmapper: do not flush I/O forDM_DEVICE_CREATE
devmapper: do not calldm_udev_completeifdm_task_set_cookie()failed
configure: RenameACT_RENAME2toACT_FORCERENAME
devmapper: wait for udev indm_simplecmd_noflush()
multipathd: wait for udev incli_resume()
devmapper: remove 'udev_sync' argument fromdm_simplecmd_noflush()
libmultipath: Fixup 'DM_DEVICE_RELOAD' handlingQuoted 3 lines
libmultipath/configure.c | 20 ++++--------- libmultipath/configure.h | 2 +- libmultipath/devmapper.c | 75+++++++++++++++++++++++++++++++----------------
Quoted 6 lines
libmultipath/devmapper.h | 4 +-- multipathd/cli_handlers.c | 4 +-- 5 files changed, 60 insertions(+), 45 deletions(-)--
2.6.6