Fix muitpath/multipathd flush issue
Benjamin Marzinski
maintainercover Fix muitpath/multipathd flush issue
If a multipath device is removed, and check_path() checks one of its paths before multipathd processes either the uevent or the dm event from removing it, multipathd will recreate the removed device. This happens because check_path() will continute to check the removed device's former paths until an event arrives removing the device. A missing multpath device will cause the update_multipath_strings() call to fail, setting pp->dmstate to PSTATE_UNDEF. If the path is up, this dmstate will cause reinstate_path() to be called, which will also fail, because the multipath device doesn't exist. This will trigger a reload, restoring the recently removed device.
This patchset handles this is two ways. The first two patches directly fix these issues in check_path(), so that a missing multipath device will no longer get recreated when checking one of its former paths.
The other 5 patches add a "multipathd del maps" command, and make the mutipath command delegate flush operations to multipathd so multipathd's state remains in sync with the kernel's, while doing removes.
One source of complexity in these patches is that multipath suspends the device with flushing before removing it, while multipathd doesn't. It does seem possible that the suspend could hang for a while, so I can understand multipathd not using it. However, that would take the multipath device getting opened and IO being issued, between the time when _dm_flush_map() verifies that the device isn't opened, and when it suspends the device. But more importantly, I don't understand how suspending the device is useful. If the device were to be opened between when _dm_flush_map() checks the usage, and when it tries to delete the device, device-mapper would simply fail the remove. And if the device isn't in use, there can't be any outstanding IO to flush. When this code was added in commit 9a4ff93, there was no check if the device was in use, and disabling queue_if_no_path could cause anything that had the device open to error out and close it. But now that multipath checks first if the device is open, I don't see the benefit to doing this anymore. Removing it would allow multipathd and multipath to use the same code to remove maps. Any thoughts?
Benjamin Marzinski (7):
libmultipath: change do_get_info returns
multipathd: fix check_path errors with removed map
libmultipath: make dm_flush_maps only return 0 on success
multipathd: add "del maps" multipathd command
multipath: make flushing maps work like other commands
multipath: delegate flushing maps to multipathd
multipath: add option to skip multipathd delegation
libmultipath/config.h | 4 ++- libmultipath/configure.h | 3 --- libmultipath/devmapper.c | 41 ++++++++++++++++++------------- libmultipath/devmapper.h | 3 ++- multipath/main.c | 51 +++++++++++++++++++++++++++------------ multipath/multipath.8 | 16 ++++++++---- multipathd/cli.c | 1 + multipathd/cli_handlers.c | 19 +++++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 39 ++++++++++++------------------ multipathd/main.h | 1 + 11 files changed, 114 insertions(+), 65 deletions(-)
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH 1/7 libmultipath: change do_get_info returns
Make do_get_info() differentiate between dm failures and missing devices, and update callers to retain their current behavior. Also, rename it and make it external. These changes will be used by future commits.
--- libmultipath/devmapper.c | 29 ++++++++++++++++------------- libmultipath/devmapper.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-)
libmultipath/devmapper.c +16 -13
@@ -496,8 +496,14 @@ int dm_addmap_reload(struct multipath *mpp, char *params, int flush)return 0 ; } -static int -do_get_info (const char *name,struct dm_info *info) +/* +* Returns: +* -1: Error +* 0: device does not exist +* 1: device exists +*/ +int +do_dm_get_info (const char *name,struct dm_info *info) {int r =-1 ;struct dm_task *dmt;
@@ -516,10 +522,7 @@ do_get_info(const char *name, struct dm_info *info)if (!dm_task_get_info (dmt, info)) goto out; -if (!info->exists) - goto out; - - r =0 ; + r = !!info->exists; out:dm_task_destroy (dmt);return r;
@@ -529,7 +532,7 @@ int dm_map_present(const char * str) {struct dm_info info; -return (do_get_info (str, &info) ==0 ); +return (do_dm_get_info (str, &info) ==1 ); }int dm_get_map (const char *name,unsigned long long *size,char *outparams)
@@ -820,7 +823,7 @@ dm_dev_t (const char * mapname, char * dev_t, int len) {struct dm_info info; -if (do_get_info (mapname, &info) !=0 ) +if (do_dm_get_info (mapname, &info) !=1 )return 1 ;if (snprintf (dev_t, len,"%i:%i" , info.major, info.minor) > len)
@@ -862,7 +865,7 @@ dm_get_major_minor(const char *name, int *major, int *minor) {struct dm_info info; -if (do_get_info (name, &info) !=0 ) +if (do_dm_get_info (name, &info) !=1 )return -1 ; *major = info.major;
@@ -1199,7 +1202,7 @@ dm_geteventnr (const char *name) {struct dm_info info; -if (do_get_info (name, &info) !=0 ) +if (do_dm_get_info (name, &info) !=1 )return -1 ;return info.event_nr;
@@ -1210,7 +1213,7 @@ dm_is_suspended(const char *name) {struct dm_info info; -if (do_get_info (name, &info) !=0 ) +if (do_dm_get_info (name, &info) !=1 )return -1 ;return info.suspended;
@@ -1383,7 +1386,7 @@ dm_get_deferred_remove (const char * mapname) {struct dm_info info; -if (do_get_info (mapname, &info) !=0 ) +if (do_dm_get_info (mapname, &info) !=1 )return -1 ;return info.deferred_remove;
@@ -1442,7 +1445,7 @@ dm_get_info (const char * mapname, struct dm_info ** dmi)if (!*dmi)return 1 ; -if (do_get_info (mapname, *dmi) !=0 ) { +if (do_dm_get_info (mapname, *dmi) !=1 ) {memset (*dmi,0 ,sizeof (struct dm_info ));FREE (*dmi); *dmi =NULL ;
libmultipath/devmapper.h +1 -0
@@ -66,6 +66,7 @@ char * dm_mapname(int major, int minor);int dm_remove_partmaps (const char * mapname,int need_sync,int deferred_remove);int dm_get_uuid (const char *name,char *uuid,int uuid_len); +int do_dm_get_info (const char *,struct dm_info *);int dm_get_info (const char * mapname,struct dm_info ** dmi);int dm_rename (const char * old,char * new,char * delim,int skip_kpartx);int dm_reassign (const char * mapname);
Signature · 1 line
2.17.2
Re: [PATCH 1/7] libmultipath: change do_get_info returns
Quoted 18 lines · Benjamin Marzinski
Make
do_get_info()differentiate between dm failures and missing devices, and update callers to retain their current behavior. Also, rename it and make it external. These changes will be used by future commits.Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 29 ++++++++++++++++------------- libmultipath/devmapper.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-)libmultipath/devmapper.c +0
-0@@ -496,8 +496,14 @@ int dm_addmap_reload(struct multipath *mpp, char *params, int flush)return 0 ;
libmultipath/devmapper.c int dm_addmap_reload(struct multipath *mpp, char · line 505
Quoted 10 lines
libmultipath/devmapper.c +6
-2} -static int -do_get_info (const char *name,struct dm_info *info) +/* +* Returns: +* -1: Error +* 0: device does not exist +* 1: device exists +*/
Can we use symbolic values here please? In particular as you have changed the "success" return value from 0 to 1...
One day we should come up with a proper return value scheme for libmultipath, defining specific enums for every function doesn't scale. But do it here for now nonetheless, please.
Apart from that, ok.
Regards
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 1/7] libmultipath: change do_get_info returns
Quoted 33 lines · Martin Wilck
Quoted 18 lines · Benjamin Marzinski
Make
do_get_info()differentiate between dm failures and missing devices, and update callers to retain their current behavior. Also, rename it and make it external. These changes will be used by future commits.Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 29 ++++++++++++++++------------- libmultipath/devmapper.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-)libmultipath/devmapper.c +0
-0@@ -496,8 +496,14 @@ int dm_addmap_reload(struct multipath *mpp, char *params, int flush)return 0 ;libmultipath/devmapper.c int dm_addmap_reload(struct multipath *mpp, char · line 505
Quoted 10 lines
libmultipath/devmapper.c +6
-2} -static int -do_get_info (const char *name,struct dm_info *info) +/* +* Returns: +* -1: Error +* 0: device does not exist +* 1: device exists +*/ Can we use symbolic values here please? In particular as you have changed the "success" return value from 0 to 1...
Quoted 3 lines
One day we should come up with a proper return value scheme for libmultipath, defining specific enums for every function doesn't scale. But do it here for now nonetheless, please.
Sure
-Ben
Quoted 12 lines
Apart from that, ok.
Regards
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 2/7 multipathd: fix check_path errors with removed map
In reply to Benjamin MarzinskiIf a multipath device is removed during, or immediately before the call to check_path(), multipathd can behave incorrectly. A missing multpath device will cause update_multipath_strings() to fail, setting pp->dmstate to PSTATE_UNDEF. If the path is up, this state will cause reinstate_path() to be called, which will also fail. This will trigger a reload, restoring the recently removed device.
If update_multipath_strings() fails because there is no multipath device, check_path should just quit, since the remove dmevent and uevent are likely already queued up. Also, I don't see any reason to reload the multipath device if reinstate fails. This code was added by fac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate could fail if the path was disabled. Looking through the current kernel code, I can't see any reason why a reinstate would fail, where a reload would help. If the path was missing from the multipath device, update_multipath_strings() would already catch that, and quit check_path() early, which make more sense to me than reloading does.
--- multipathd/main.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
multipathd/main.c +14 -22
@@ -1611,22 +1611,18 @@ fail_path (struct path * pp, int del_active)/* * caller must have locked the path list before calling that function */ -static int +static void reinstate_path (struct path * pp) { -int ret =0 ; -if (!pp->mpp) -return 0 ; +return ; -if (dm_reinstate_path (pp->mpp->alias, pp->dev_t)) { +if (dm_reinstate_path (pp->mpp->alias, pp->dev_t))condlog (0 ,"%s: reinstate failed" , pp->dev_t); - ret =1 ; - }else { +else {condlog (2 ,"%s: reinstated" , pp->dev_t);update_queue_mode_add_path (pp->mpp); } -return ret; } static void
@@ -2088,8 +2084,13 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)* Synchronize with kernel state */ if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +struct dm_info info;condlog (1 ,"%s: Could not synchronize with kernel state" , pp->dev); +if (pp->mpp && pp->mpp->alias && +do_dm_get_info (pp->mpp->alias, &info) ==0 ) +/* multipath device missing. Likely removed */ +return 0 ; pp->dmstate =PSTATE_UNDEF ; }/* if update_multipath_strings orphaned the path, quit early */
@@ -2179,12 +2180,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * reinstate this path */ -if (!disable_reinstate &&reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } +if (!disable_reinstate) +reinstate_path (pp); new_path_up =1 ;if (oldchkrstate !=PATH_UP && oldchkrstate !=PATH_GHOST )
@@ -2200,15 +2197,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)else if (newstate ==PATH_UP || newstate ==PATH_GHOST ) {if ((pp->dmstate ==PSTATE_FAILED || pp->dmstate ==PSTATE_UNDEF ) && - !disable_reinstate) { + !disable_reinstate)/* Clear IO errors */ -if (reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } - }else { +reinstate_path (pp); +else {LOG_MSG (4 , verbosity, pp);if (pp->checkint != max_checkint) {/*
Signature · 1 line
2.17.2
Re: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 11 lines · Benjamin Marzinski
If a multipath device is removed during, or immediately before the call
tocheck_path(), multipathd can behave incorrectly. A missing multpath
device will causeupdate_multipath_strings()to fail, settingpp->dmstatetoPSTATE_UNDEF. If the path is up, this state will causereinstate_path()to be called, which will also fail. This will trigger
a reload, restoring the recently removed device.
Quoted 15 lines
If
update_multipath_strings()fails because there is no multipath device,check_pathshould just quit, since the remove dmevent and uevent
are likely already queued up. Also, I don't see any reason to reload the
multipath device if reinstate fails. This code was added byfac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate
could fail if the path was disabled. Looking through the current kernel
code, I can't see any reason why a reinstate would fail, where a reload
would help. If the path was missing from the multipath device,update_multipath_strings()would already catch that, and quitcheck_path()early, which make more sense to me than reloading does.
fac68d7 is related to the famous "dm-multipath: Accept failed paths for multipath maps" patch (e.g.
https://patchwork.kernel.org/patch/3368381/#7193001), which never made it upstream. SUSE kernels have shipped this patch for a long time, but we don't apply it any more in recent kernels.
With this patch, The reinstate_path() failure would occur if multipathd had created a table with a "disabled" device (one which would be present in a dm map even though the actual block device didn't exist), and then tried to reinstate such a path. It sounds unlikely, but it might be possible if devices are coming and going in quick succession. In that situation, and with the "accept failed path" patch applied, a reload makes some sense, because reload (unlike reinstate) would not fail (at least not for this reason) and would actually add that just- reinstated path. OTOH, it's not likely that the reload would improve matters, either. After all, multipathd is just trying to reinstate a non-existing path. So, I'm fine with skipping the reload.
Quoted 41 lines
Signed-off-by Benjamin Marzinski <[email protected]>--- multipathd/main.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)multipathd/main.c +0
-0@@ -1611,22 +1611,18 @@ fail_path (struct path * pp, int del_active)/* * caller must have locked the path list before calling that function
*/multipathd/main.c +4
-8-static int +static void reinstate_path (struct path * pp) { -int ret =0 ; -if (!pp->mpp) -return 0 ; +return ; -if (dm_reinstate_path (pp->mpp->alias, pp->dev_t)) { +if (dm_reinstate_path (pp->mpp->alias, pp->dev_t))condlog (0 ,"%s: reinstate failed" , pp->dev_t); - ret =1 ; - }else { +else {condlog (2 ,"%s: reinstated" , pp->dev_t);update_queue_mode_add_path (pp->mpp); } -return ret; } static void@@ -2088,8 +2084,13 @@ check_path (struct vectors * vecs, struct path* pp, unsigned int ticks) * Synchronize with kernel state */
multipathd/main.c check_path (struct vectors * vecs, struct path · line 2096
Quoted 10 lines
multipathd/main.c +5
-0if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +struct dm_info info;condlog (1 ,"%s: Could not synchronize with kernel state", pp->dev); +if (pp->mpp && pp->mpp->alias && +do_dm_get_info (pp->mpp->alias, &info) ==0 ) +/* multipath device missing. Likely removed */ +return 0 ; pp->dmstate =PSTATE_UNDEF ;
It would be more elegant if we could distinguish different failure modes from update_multipath_strings() directly, without having to call do_dm_get_info() again.
Quoted 39 lines
multipathd/main.c +2
-6}/* if update_multipath_strings orphaned the path, quit early */ @@ -2179,12 +2180,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * reinstate this path */ -if (!disable_reinstate &&reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } +if (!disable_reinstate) +reinstate_path (pp); new_path_up =1 ;if (oldchkrstate !=
PATH_UP&& oldchkrstate !=PATH_GHOST)multipathd/main.c +3
-8@@ -2200,15 +2197,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) else if (newstate == PATH_UP || newstate == PATH_GHOST) {if ((pp->dmstate ==PSTATE_FAILED || pp->dmstate ==PSTATE_UNDEF ) && - !disable_reinstate) { + !disable_reinstate)/* Clear IO errors */ -if (reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } - }else { +reinstate_path (pp); +else {LOG_MSG (4 , verbosity, pp);if (pp->checkint != max_checkint) {/*
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 93 lines · Martin Wilck
Quoted 11 lines · Benjamin Marzinski
If a multipath device is removed during, or immediately before the call
tocheck_path(), multipathd can behave incorrectly. A missing multpath
device will causeupdate_multipath_strings()to fail, settingpp->dmstatetoPSTATE_UNDEF. If the path is up, this state will causereinstate_path()to be called, which will also fail. This will trigger
a reload, restoring the recently removed device.Quoted 15 lines
If
update_multipath_strings()fails because there is no multipath device,check_pathshould just quit, since the remove dmevent and uevent
are likely already queued up. Also, I don't see any reason to reload the
multipath device if reinstate fails. This code was added byfac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate
could fail if the path was disabled. Looking through the current kernel
code, I can't see any reason why a reinstate would fail, where a reload
would help. If the path was missing from the multipath device,update_multipath_strings()would already catch that, and quitcheck_path()early, which make more sense to me than reloading does.fac68d7 is related to the famous "dm-multipath: Accept failed paths for multipath maps" patch (e.g.
https://patchwork.kernel.org/patch/3368381/#7193001), which never made it upstream. SUSE kernels have shipped this patch for a long time, but we don't apply it any more in recent kernels.With this patch, The
reinstate_path()failure would occur if multipathd had created a table with a "disabled" device (one which would be present in a dm map even though the actual block device didn't exist), and then tried to reinstate such a path. It sounds unlikely, but it might be possible if devices are coming and going in quick succession. In that situation, and with the "accept failed path" patch applied, a reload makes some sense, because reload (unlike reinstate) would not fail (at least not for this reason) and would actually add that just- reinstated path. OTOH, it's not likely that the reload would improve matters, either. After all, multipathd is just trying to reinstate a non-existing path. So, I'm fine with skipping the reload.Quoted 47 lines
Signed-off-by Benjamin Marzinski <[email protected]>--- multipathd/main.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)multipathd/main.c +0
-0@@ -1611,22 +1611,18 @@ fail_path (struct path * pp, int del_active)/* * caller must have locked the path list before calling that function
*/multipathd/main.c +6
-8-static int +static void reinstate_path (struct path * pp) { -int ret =0 ; -if (!pp->mpp) -return 0 ; +return ; -if (dm_reinstate_path (pp->mpp->alias, pp->dev_t)) { +if (dm_reinstate_path (pp->mpp->alias, pp->dev_t))condlog (0 ,"%s: reinstate failed" , pp->dev_t); - ret =1 ; - }else { +else {condlog (2 ,"%s: reinstated" , pp->dev_t);update_queue_mode_add_path (pp->mpp); } -return ret; } static void@@ -2088,8 +2084,13 @@ check_path (struct vectors * vecs, struct path* pp, unsigned int ticks) * Synchronize with kernel state */ if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +struct dm_info info;condlog (1 ,"%s: Could not synchronize with kernel state", pp->dev); + if (pp->mpp && pp->mpp->alias &&
Quoted 8 lines
multipathd/main.c check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) · line 2094
Quoted 4 lines
multipathd/main.c +3
-0+ do_dm_get_info(pp->mpp->alias, &info) == 0) +/* multipath device missing. Likely removed */ +return 0 ; pp->dmstate =PSTATE_UNDEF ;It would be more elegant if we could distinguish different failure modes from
update_multipath_strings()directly, without having to calldo_dm_get_info()again.
Seems reasonable. I'll take a look at that.
-Ben
Quoted 46 lines
Quoted 39 lines
multipathd/main.c +2
-6}/* if update_multipath_strings orphaned the path, quit early */ @@ -2179,12 +2180,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * reinstate this path */ -if (!disable_reinstate &&reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } +if (!disable_reinstate) +reinstate_path (pp); new_path_up =1 ;if (oldchkrstate !=
PATH_UP&& oldchkrstate !=PATH_GHOST)multipathd/main.c +3
-8@@ -2200,15 +2197,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) else if (newstate == PATH_UP || newstate == PATH_GHOST) {if ((pp->dmstate ==PSTATE_FAILED || pp->dmstate ==PSTATE_UNDEF ) && - !disable_reinstate) { + !disable_reinstate)/* Clear IO errors */ -if (reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } - }else { +reinstate_path (pp); +else {LOG_MSG (4 , verbosity, pp);if (pp->checkint != max_checkint) {/*
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Re: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 35 lines · Benjamin Marzinski
Quoted 34 lines · Martin Wilck
Quoted 11 lines · Benjamin Marzinski
If a multipath device is removed during, or immediately before the call
tocheck_path(), multipathd can behave incorrectly. A missing multpath
device will causeupdate_multipath_strings()to fail, settingpp->dmstatetoPSTATE_UNDEF. If the path is up, this state will causereinstate_path()to be called, which will also fail. This will trigger
a reload, restoring the recently removed device.Quoted 15 lines
If
update_multipath_strings()fails because there is no multipath device,check_pathshould just quit, since the remove dmevent and uevent
are likely already queued up. Also, I don't see any reason to reload the
multipath device if reinstate fails. This code was added byfac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate
could fail if the path was disabled. Looking through the current kernel
code, I can't see any reason why a reinstate would fail, where a reload
would help. If the path was missing from the multipath device,update_multipath_strings()would already catch that, and quitcheck_path()early, which make more sense to me than reloading does.fac68d7 is related to the famous "dm-multipath: Accept failed paths for multipath maps" patch (e.g.
https://patchwork.kernel.org/patch/3368381/#7193001), which never made it upstream. SUSE kernels have shipped this patch for a long time, but we don't apply it any more in recent kernels.
Quoted 12 lines
Quoted 12 lines
With this patch, The
reinstate_path()failure would occur if multipathd had created a table with a "disabled" device (one which would be present in a dm map even though the actual block device didn't exist), and then tried to reinstate such a path. It sounds unlikely, but it might be possible if devices are coming and going in quick succession. In that situation, and with the "accept failed path" patch applied, a reload makes some sense, because reload (unlike reinstate) would not fail (at least not for this reason) and would actually add that just- reinstated path. OTOH, it's not likely that the reload would improve matters, either. After all, multipathd is just trying to reinstate a non-existing path. So, I'm fine with skipping the reload.
It's actually _not_ unlikely, but a direct result of multipathd listening to uevents.
If you have a map with four paths, and all four of them are going down, you end up getting four events. And multipath will be processing each event _individually_, causing it to generate a reload sequence like:
[a b c d]
[b c d]
[c d]
[d]
[]
Of which only the last is valid, as all the intermediate ones contain invalid paths.
And _that_ is the scenario I was referring to when creating the patch.
Cheers,
Hannes
Signature · 10 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerRe: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 33 lines · Hannes Reinecke
Quoted 7 lines
Quoted 7 lines
fac68d7 is related to the famous "dm-multipath: Accept failed paths for multipath maps" patch (e.g.
https://patchwork.kernel.org/patch/3368381/#7193001), which never made it upstream. SUSE kernels have shipped this patch for a long time, but we don't apply it any more in recent kernels.Quoted 12 lines
Quoted 12 lines
With this patch, The
reinstate_path()failure would occur if multipathd had created a table with a "disabled" device (one which would be present in a dm map even though the actual block device didn't exist), and then tried to reinstate such a path. It sounds unlikely, but it might be possible if devices are coming and going in quick succession. In that situation, and with the "accept failed path" patch applied, a reload makes some sense, because reload (unlike reinstate) would not fail (at least not for this reason) and would actually add that just- reinstated path. OTOH, it's not likely that the reload would improve matters, either. After all, multipathd is just trying to reinstate a non-existing path. So, I'm fine with skipping the reload.It's actually _not_ unlikely, but a direct result of multipathd listening to uevents.
If you have a map with four paths, and all four of them are going down, you end up getting four events.
And multipath will be processing each event _individually_, causing it to generate a reload sequence like:[a b c d]
[b c d]
[c d]
[d]
[]
Quoted 4 lines
Of which only the last is valid, as all the intermediate ones contain invalid paths.
And _that_ is the scenario I was referring to when creating the patch.
But even still, I'm not in favor of calling ev_add_path() with the code as it currently is. In the case you point out, it will presumably fail when adopt_paths() calls pathinfo(). That will orphan the path, which is good. But if the map got removed (intentionally) instead of the path, ev_add_path() will recreate the map, which is bad. Also, it seems more likely for a path to still exist and be usable while the multipath device is gone (the bad case), than for the path to pass the checker function and then disappear before mutipathd tries to reinstate it immediately afterwards (the good case). Further, the bad result, where a deleted multipath device reappears, is actually a problem for users. Having multipathd take a bit of time and pointless effort to catch up after multiple changes happen at once doesn't effect users noticeably.
Since the checkerloop thread spends the vast majority of it's not not checking any specific path, if a path goes away, it is most likely to be caught by the path_offline() function. I we want to do something to proactively deal with a path that has been removed, we should do it there.
-Ben
Quoted 8 lines
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 76 lines · Benjamin Marzinski
Quoted 48 lines · Hannes Reinecke
Quoted 23 lines
Quoted 23 lines
fac68d7 is related to the famous "dm-multipath: Accept failed paths for
multipath maps" patch (e.g.
https://patchwork.kernel.org/patch/3368381/#7193001), which never made
it upstream. SUSE kernels have shipped this patch for a long time, but
we don't apply it any more in recent kernels.With this patch, The
reinstate_path()failure would occur if multipathd
had created a table with a "disabled" device (one which would be
present in a dm map even though the actual block device didn't exist),
and then tried to reinstate such a path. It sounds unlikely, but it
might be possible if devices are coming and going in quick succession.
In that situation, and with the "accept failed path" patch applied, a
reload makes some sense, because reload (unlike reinstate) would notQuoted 8 lines
Quoted 8 lines
fail (at least not for this reason) and would actually add that just-
reinstated path. OTOH, it's not likely that the reload would improve
matters, either. After all, multipathd is just trying to reinstate a
non-existing path. So, I'm fine with skipping the reload.It's actually _not_ unlikely, but a direct result of multipathd listening to
uevents.If you have a map with four paths, and all four of them are going down, you
end up getting four events.
And multipath will be processing each event _individually_, causing it to
generate a reload sequence like:[a b c d]
[b c d]
[c d]
[d]
[]Quoted 6 lines
Of which only the last is valid, as all the intermediate ones contain
invalid paths.And _that_ is the scenario I was referring to when creating the patch.
But even still, I'm not in favor of calling
ev_add_path()with the code
as it currently is. In the case you point out, it will presumably fail
whenadopt_paths()callspathinfo(). That will orphan the path, which is
good. But if the map got removed (intentionally) instead of the path,ev_add_path()will recreate the map, which is bad. Also, it seems more
likely for a path to still exist and be usable while the multipath device is gone (the bad case), than for the path to pass the checker function and then disappear before mutipathd tries to reinstate it immediately afterwards (the good case). Further, the bad result, where
a deleted multipath device reappears, is actually a problem for users.
Having multipathd take a bit of time and pointless effort to catch up after multiple changes happen at once doesn't effect users noticeably.
Quoted 5 lines
Since the checkerloop thread spends the vast majority of it's not not checking any specific path, if a path goes away, it is most likely to be
caught by thepath_offline()function. I we want to do something to proactively deal with a path that has been removed, we should do it
Hannes and I discussed about this, and he agreed that calling ev_add_path() in the situation at hand wasn't helpful. Hence his suggestion with pp->mpp that we discussed in the other sub-thread.
Regards,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Re: [PATCH 2/7] multipathd: fix check_path errors with removed map
In reply to Benjamin MarzinskiQuoted 25 lines · Benjamin Marzinski
Quoted 15 lines · Martin Wilck
Quoted 14 lines · Benjamin Marzinski
static void
(quoted diff) +0
-0@@ -2088,8 +2084,13 @@ check_path (struct vectors * vecs, structpath
* pp, unsigned int ticks)multipathd/main.c +1
-0* Synchronize with kernel state */ if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +struct dm_info info; condlog(1, "%s: Could not synchronize with kernelstate",
multipathd/main.c +2
-0pp->dev); +if (pp->mpp && pp->mpp->alias && +do_dm_get_info (pp->mpp->alias, &info) ==0 )Quoted 8 lines
multipathd/main.c check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) · line 2094
Quoted 3 lines
multipathd/main.c +2
-0+/* multipath device missing. Likely removed */ +return 0 ; pp->dmstate =PSTATE_UNDEF ;It would be more elegant if we could distinguish different failure modes from
update_multipath_strings()directly, without having to calldo_dm_get_info()again.
Quoted 1 line
Seems reasonable. I'll take a look at that.
Yet another idea: I just discussed this with Hannes, and he pointed out that right below this code, we have
/* if update_multipath_strings orphaned the path, quit early */ if (!pp->mpp) return 0;
... which could have the same effect, if pp->mpp was reloaded. Probably that doesn't happen because the pp->mpp dereference is cached in a register, but we could simply add a READ_ONCE there.
Choose what you prefer.
Regards,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 31 lines · Martin Wilck
Quoted 25 lines · Benjamin Marzinski
Quoted 15 lines · Martin Wilck
Quoted 14 lines · Benjamin Marzinski
static void
(quoted diff) +0
-0@@ -2088,8 +2084,13 @@ check_path (struct vectors * vecs, structpath
* pp, unsigned int ticks)multipathd/main.c +1
-0* Synchronize with kernel state */ if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +struct dm_info info; condlog(1, "%s: Could not synchronize with kernelstate",
multipathd/main.c +2
-0pp->dev); +if (pp->mpp && pp->mpp->alias && +do_dm_get_info (pp->mpp->alias, &info) ==0 )Quoted 8 lines
multipathd/main.c check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) · line 2094
Quoted 3 lines
multipathd/main.c +2
-0+/* multipath device missing. Likely removed */ +return 0 ; pp->dmstate =PSTATE_UNDEF ;It would be more elegant if we could distinguish different failure modes from
update_multipath_strings()directly, without having to calldo_dm_get_info()again.Quoted 1 line
Seems reasonable. I'll take a look at that.
Yet another idea: I just discussed this with Hannes, and he pointed out that right below this code, we have
Quoted 7 lines
/* if update_multipath_strings orphaned the path, quit early */ if (!pp->mpp) return 0;... which could have the same effect, if
pp->mppwas reloaded. Probably that doesn't happen because thepp->mppdereference is cached in a register, but we could simply add aREAD_ONCEthere.
When update_multipath_strings() calls update_multipath_table() it will fail because the table no longer exists. If we differentiate between a dm error and not finding the map, we can exit early without having to call do_dm_get_info() again. But right now, if the map is gone, but we haven't got the uevent removing it, then nothing will clear pp->mpp. If we did get the uevent, then it must have grabbed the vecs lock. That better have caused a memory barrier, which will guarantee that check_path() sees the updated value.
-Ben
Quoted 11 lines
Choose what you prefer.
Regards,
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Re: [PATCH 2/7] multipathd: fix check_path errors with removed map
Quoted 26 lines · Benjamin Marzinski
Quoted 16 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski
Quoted 7 lines · Martin Wilck
It would be more elegant if we could distinguish different failure
modes fromupdate_multipath_strings()directly, without having to
calldo_dm_get_info()again.Seems reasonable. I'll take a look at that.
Yet another idea: I just discussed this with Hannes, and he pointed out
that right below this code, we haveQuoted 8 lines
/* if update_multipath_strings orphaned the path, quit early */ if (!pp->mpp) return 0;... which could have the same effect, if
pp->mppwas reloaded. Probably
that doesn't happen because thepp->mppdereference is cached in a register, but we could simply add aREAD_ONCEthere.
Quoted 8 lines
When
update_multipath_strings()callsupdate_multipath_table()it will
fail because the table no longer exists. If we differentiate between a dm error and not finding the map, we can exit early without having to
calldo_dm_get_info()again. But right now, if the map is gone, but we
haven't got the uevent removing it, then nothing will clearpp->mpp.
You're right. Let's "differentiate", then :-)
Quoted 4 lines
If
we did get the uevent, then it must have grabbed the vecs lock. That better have caused a memory barrier, which will guarantee thatcheck_path()sees the updated value.
It could hardly have grabbed the lock while check_path() was running. Anyway, this wasn't the right suggestion then, and "differentiating" is better anyway. Sorry for the confusion.
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 3/7 libmultipath: make dm_flush_maps only return 0 on success
In reply to Benjamin Marzinskidm_flush_maps() returned both 0 and 1 on error, depending on which part of the function it was in, but the caller was always treating 0 as a success. Make dm_flush_maps() always return 1 on error and 0 on success.
--- libmultipath/devmapper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +3 -2
@@ -993,13 +993,13 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)int dm_flush_maps (int retries) { -int r =0 ; +int r =1 ;struct dm_task *dmt;struct dm_names *names;unsigned next =0 ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_LIST ))) -return 0 ; +return r;dm_task_no_open_count (dmt);
@@ -1012,6 +1012,7 @@ int dm_flush_maps (int retries)if (!names->dev) goto out; + r =0 ; do { r |= dm_suspend_and_flush_map(names->name, retries); next = names->next;
Signature · 1 line
2.17.2
Re: [PATCH 3/7] libmultipath: make dm_flush_maps only return 0 on success
Quoted 11 lines · Benjamin Marzinski
dm_flush_maps()returned both 0 and 1 on error, depending on which part
of the function it was in, but the caller was always treating 0 as a success. Makedm_flush_maps()always return 1 on error and 0 on success.Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 4/7 multipathd: add "del maps" multipathd command
In reply to Benjamin MarzinskiThis will flush all multipath devices.
--- libmultipath/devmapper.c | 7 +++++-- libmultipath/devmapper.h | 2 +- multipath/main.c | 2 +- multipathd/cli.c | 1 + multipathd/cli_handlers.c | 19 +++++++++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 3 ++- multipathd/main.h | 1 + 8 files changed, 31 insertions(+), 5 deletions(-)
libmultipath/devmapper.c +5 -2
@@ -991,7 +991,7 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)#endif -int dm_flush_maps (int retries) +int dm_flush_maps (int need_suspend,int retries) {int r =1 ;struct dm_task *dmt;
@@ -1014,7 +1014,10 @@ int dm_flush_maps (int retries) r =0 ;do { - r |=dm_suspend_and_flush_map (names->name, retries); +if (need_suspend) + r |=dm_suspend_and_flush_map (names->name, retries); +else + r |=dm_flush_map (names->name); next = names->next; names = (void *) names + next; }while (next);
libmultipath/devmapper.h +1 -1
@@ -51,7 +51,7 @@ int dm_flush_map_nopaths(const char * mapname, int deferred_remove);#define dm_suspend_and_flush_map (mapname, retries) \ _dm_flush_map(mapname, 1, 0, 1, retries)int dm_cancel_deferred_remove (struct multipath *mpp); -int dm_flush_maps (int retries); +int dm_flush_maps (int need_suspend,int retries);int dm_fail_path (const char * mapname,char * path);int dm_reinstate_path (const char * mapname,char * path);int dm_queue_if_no_path (const char *mapname,int enable);
multipath/main.c +1 -1
@@ -1096,7 +1096,7 @@ main (int argc, char *argv[]) goto out; }else if (conf->remove ==FLUSH_ALL ) { - r =dm_flush_maps (retries) ?RTVL_FAIL :RTVL_OK ; + r =dm_flush_maps (1 , retries) ?RTVL_FAIL :RTVL_OK ; goto out; }while ((r =configure (conf, cmd, dev_type, dev)) ==RTVL_RETRY )
multipathd/cli.c +1 -0
@@ -568,6 +568,7 @@ cli_init (void) {add_handler (DEL +PATH ,NULL );add_handler (ADD +MAP ,NULL );add_handler (DEL +MAP ,NULL ); +add_handler (DEL +MAPS ,NULL );add_handler (SWITCH +MAP +GROUP ,NULL );add_handler (RECONFIGURE ,NULL );add_handler (SUSPEND +MAP ,NULL );
multipathd/cli_handlers.c +19 -0
@@ -852,6 +852,25 @@ cli_del_map (void * v, char ** reply, int * len, void * data)return rc; } +int +cli_del_maps (void *v,char **reply,int *len,void *data) +{ +struct vectors * vecs = (struct vectors *)data; +struct multipath *mpp; +int i, ret =0 ; + +condlog (2 ,"remove maps (operator)" ); + vector_foreach_slot(vecs->mpvec, mpp, i) { +if (flush_map (mpp, vecs,0 )) + ret++; +else + i--; + } +/* flush any multipath maps that aren't currently known by multipathd */ + ret |=dm_flush_maps (0 ,0 ); +return ret; +} +int cli_reload (void *v,char **reply,int *len,void *data) {
multipathd/cli_handlers.h +1 -0
@@ -26,6 +26,7 @@ int cli_add_path (void * v, char ** reply, int * len, void * data);int cli_del_path (void * v,char ** reply,int * len,void * data);int cli_add_map (void * v,char ** reply,int * len,void * data);int cli_del_map (void * v,char ** reply,int * len,void * data); +int cli_del_maps (void * v,char ** reply,int * len,void * data);int cli_switch_group (void * v,char ** reply,int * len,void * data);int cli_reconfigure (void * v,char ** reply,int * len,void * data);int cli_resize (void * v,char ** reply,int * len,void * data);
multipathd/main.c +2 -1
@@ -631,7 +631,7 @@ sync_maps_state(vector mpvec)sync_map_state (mpp); } -static int +int flush_map (struct multipath * mpp,struct vectors * vecs,int nopaths) {int r;
@@ -1551,6 +1551,7 @@ uxlsnrloop (void * ap)set_handler_callback (DEL +PATH , cli_del_path);set_handler_callback (ADD +MAP , cli_add_map);set_handler_callback (DEL +MAP , cli_del_map); +set_handler_callback (DEL +MAPS , cli_del_maps);set_handler_callback (SWITCH +MAP +GROUP , cli_switch_group);set_unlocked_handler_callback (RECONFIGURE , cli_reconfigure);set_handler_callback (SUSPEND +MAP , cli_suspend);
multipathd/main.h +1 -0
@@ -28,6 +28,7 @@ int ev_add_path (struct path *, struct vectors *, int);int ev_remove_path (struct path *,struct vectors *,int );int ev_add_map (char *,const char *,struct vectors *);int ev_remove_map (char *,char *,int ,struct vectors *); +int flush_map (struct multipath *,struct vectors *,int );int set_config_state (enum daemon_status );void *mpath_alloc_prin_response (int prin_sa); int prin_do_scsi_ioctl(char *, int rq_servact, struct prin_resp * resp,
Signature · 1 line
2.17.2
Re: [PATCH 4/7] multipathd: add "del maps" multipathd command
Quoted 29 lines · Benjamin Marzinski
This will flush all multipath devices.
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 7 +++++-- libmultipath/devmapper.h | 2 +- multipath/main.c | 2 +- multipathd/cli.c | 1 + multipathd/cli_handlers.c | 19 +++++++++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 3 ++- multipathd/main.h | 1 + 8 files changed, 31 insertions(+), 5 deletions(-)libmultipath/devmapper.c +1
-1@@ -991,7 +991,7 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)#endif -int dm_flush_maps (int retries) +int dm_flush_maps (int need_suspend,int retries) {int r =1 ;libmultipath/devmapper.c +0
-0struct dm_task *dmt;
libmultipath/devmapper.c int dm_flush_maps (int retries) · line 1021
Quoted 9 lines
libmultipath/devmapper.c +4
-1@@ -1014,7 +1014,10 @@ int dm_flush_maps (int retries) r =0 ; do { - r |= dm_suspend_and_flush_map(names->name, retries); + if (need_suspend) + r |= dm_suspend_and_flush_map(names->name, retries); + else + r |= dm_flush_map(names->name);
This is fine, but considering the previous discussion, I'd prefer to get rid of need_suspend and dm_suspend_and_flush_map() entirely. It would simplify the _dm_flush_map code path significantly.
As we determined that we use the suspend/resume only in multipath anyway, we could add it there in the "non-delegated" code path.
Thanks,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 4/7] multipathd: add "del maps" multipathd command
Quoted 44 lines · Martin Wilck
Quoted 29 lines · Benjamin Marzinski
This will flush all multipath devices.
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 7 +++++-- libmultipath/devmapper.h | 2 +- multipath/main.c | 2 +- multipathd/cli.c | 1 + multipathd/cli_handlers.c | 19 +++++++++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 3 ++- multipathd/main.h | 1 + 8 files changed, 31 insertions(+), 5 deletions(-)libmultipath/devmapper.c +1
-1@@ -991,7 +991,7 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)#endif -int dm_flush_maps (int retries) +int dm_flush_maps (int need_suspend,int retries) {int r =1 ;libmultipath/devmapper.c +0
-0struct dm_task *dmt;libmultipath/devmapper.c int dm_flush_maps (int retries) · line 1021
Quoted 9 lines
libmultipath/devmapper.c +4
-1@@ -1014,7 +1014,10 @@ int dm_flush_maps (int retries) r =0 ; do { - r |= dm_suspend_and_flush_map(names->name, retries); + if (need_suspend) + r |= dm_suspend_and_flush_map(names->name, retries); + else + r |= dm_flush_map(names->name);This is fine, but considering the previous discussion, I'd prefer to get rid of
need_suspendanddm_suspend_and_flush_map()entirely. It would simplify the_dm_flush_mapcode path significantly.
Quoted 2 lines
As we determined that we use the suspend/resume only in multipath anyway, we could add it there in the "non-delegated" code path.
I'm confused. dm_flush_maps() is also called in the non-delegated code path, where it uses the dm_suspend_and_flush_map(). Are you proposing an alternative version of dm_flush_maps() for multipath?
-Ben
Quoted 9 lines
Thanks,
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Re: [PATCH 4/7] multipathd: add "del maps" multipathd command
Quoted 23 lines · Benjamin Marzinski
Quoted 22 lines · Martin Wilck
Quoted 7 lines
libmultipath/devmapper.c +1
-1-int dm_flush_maps (int retries) +int dm_flush_maps (int need_suspend,int retries) {int r =1 ;struct dm_task *dmt;libmultipath/devmapper.c int dm_flush_maps (int retries) · line 1021
Quoted 9 lines
libmultipath/devmapper.c +4
-1@@ -1014,7 +1014,10 @@ int dm_flush_maps (int retries) r =0 ; do { - r |= dm_suspend_and_flush_map(names->name, retries); + if (need_suspend) + r |= dm_suspend_and_flush_map(names->name, retries); + else + r |= dm_flush_map(names->name);This is fine, but considering the previous discussion, I'd prefer to
get rid ofneed_suspendanddm_suspend_and_flush_map()entirely. It would simplify the_dm_flush_mapcode path significantly.
Quoted 7 lines
Quoted 2 lines
As we determined that we use the suspend/resume only in multipath anyway, we could add it there in the "non-delegated" code path.
I'm confused.
dm_flush_maps()is also called in the non-delegated code
path, where it uses thedm_suspend_and_flush_map(). Are you proposing an alternative version ofdm_flush_maps()for multipath?
No, just a different error handling in multipath. Instead of calling just calling dm_flush_maps() again from multipath with need_suspend=1, we could suspend / resume directly in the error path, and then call dm_flush_map again. Which would allow us to get rid of need_suspend, as no callers would set it any more.
IOW, move the handling of this multipath-specific error situation out of libmultipath, into the multipath-specific code.
Just an idea, I don't insist on it.
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 5/7 multipath: make flushing maps work like other commands
In reply to Benjamin MarzinskiThe config structure doesn't need a special variable just for removes. Multipath can just use the cmd variable, like it does for the other commands.
--- libmultipath/config.h | 3 ++- libmultipath/configure.h | 3 --- multipath/main.c | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-)
libmultipath/config.h +2 -1
@@ -38,6 +38,8 @@ enum mpath_cmds {CMD_ADD_WWID ,CMD_USABLE_PATHS ,CMD_DUMP_CONFIG , +CMD_FLUSH_ONE , + CMD_FLUSH_ALL, }; enum force_reload_types {
@@ -142,7 +144,6 @@ struct config {unsigned int max_checkint;bool use_watchdog;int pgfailback; -int remove;int rr_weight;int no_path_retry;int user_friendly_names;
libmultipath/configure.h +0 -3
@@ -45,9 +45,6 @@ enum { CP_RETRY, }; -#define FLUSH_ONE 1 -#define FLUSH_ALL 2 -struct vectors ; int setup_map (struct multipath * mpp, char * params, int params_size,
multipath/main.c +10 -10
@@ -909,10 +909,10 @@ main (int argc, char *argv[]) cmd =CMD_DRY_RUN ;break ;case 'f' : - conf->remove =FLUSH_ONE ; + cmd =CMD_FLUSH_ONE ;break ;case 'F' : - conf->remove =FLUSH_ALL ; + cmd =CMD_FLUSH_ALL ;break ;case 'l' :if (optarg && !strncmp (optarg,"l" ,1 ))
@@ -1053,6 +1053,10 @@ main (int argc, char *argv[])condlog (0 ,"the -w option requires a device" ); goto out; } +if (cmd ==CMD_FLUSH_ONE && dev_type !=DEV_DEVMAP ) { +condlog (0 ,"the -f option requires a map name to remove" ); + goto out; + }switch (delegate_to_multipathd (cmd, dev, dev_type, conf)) {case DELEGATE_OK :
@@ -1086,16 +1090,12 @@ main (int argc, char *argv[]) }if (retries <0 ) retries = conf->remove_retries; -if (conf->remove ==FLUSH_ONE ) { -if (dev_type ==DEV_DEVMAP ) { - r =dm_suspend_and_flush_map (dev, retries) ? -RTVL_FAIL :RTVL_OK ; - }else -condlog (0 ,"must provide a map name to remove" ); - +if (cmd ==CMD_FLUSH_ONE ) { + r =dm_suspend_and_flush_map (dev, retries) ? +RTVL_FAIL :RTVL_OK ; goto out; } -else if (conf->remove ==FLUSH_ALL ) { +else if (cmd ==CMD_FLUSH_ALL ) { r =dm_flush_maps (1 , retries) ?RTVL_FAIL :RTVL_OK ; goto out; }
Signature · 1 line
2.17.2
Re: [PATCH 5/7] multipath: make flushing maps work like other commands
Quoted 6 lines · Benjamin Marzinski
The config structure doesn't need a special variable just for removes.
Multipath can just use the cmd variable, like it does for the other commands.Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 6/7 multipath: delegate flushing maps to multipathd
In reply to Benjamin MarzinskiSince there can be problems with removing maps outside of multipathd, multipath should attempt to delegate this command to multipathd. However, multipathd doesn't attempt to suspend the device, in order to avoid potential hangs. If delegating to multipathd fails, multipath should try the remove itself.
--- multipath/main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
multipath/main.c +14 -0
@@ -820,6 +820,20 @@ int delegate_to_multipathd(enum mpath_cmds cmd,if (cmd ==CMD_CREATE && conf->force_reload ==FORCE_RELOAD_YES ) { p +=snprintf (p, n,"reconfigure" ); } +else if (cmd ==CMD_FLUSH_ONE && dev && dev_type ==DEV_DEVMAP ) { + p +=snprintf (p, n,"del map %s" , dev); +/* multipathd doesn't try as hard, to avoid potentially +* hanging. If it fails, retry with the regular multipath +* command */ + r =NOT_DELEGATED ; + } +else if (cmd ==CMD_FLUSH_ALL ) { + p +=snprintf (p, n,"del maps" ); +/* multipathd doesn't try as hard, to avoid potentially +* hanging. If it fails, retry with the regular multipath +* command */ + r =NOT_DELEGATED ; + }/* Add other translations here */ if (strlen (command) ==0 )
Signature · 1 line
2.17.2
Re: [PATCH 6/7] multipath: delegate flushing maps to multipathd
Quoted 8 lines · Benjamin Marzinski
Since there can be problems with removing maps outside of multipathd, multipath should attempt to delegate this command to multipathd. However, multipathd doesn't attempt to suspend the device, in order to avoid potential hangs. If delegating to multipathd fails, multipath
should try the remove itself.Signed-off-by Benjamin Marzinski <[email protected]>
(but see remark on patch 4/7).
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 7/7 multipath: add option to skip multipathd delegation
In reply to Benjamin MarzinskiAdd the -D option to allow users to skip delegating commands to multipathd.
--- libmultipath/config.h | 1 + multipath/main.c | 15 +++++++++++---- multipath/multipath.8 | 16 +++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-)
libmultipath/config.h +1 -0
@@ -190,6 +190,7 @@ struct config {int ghost_delay;int find_multipaths_timeout;int marginal_pathgroups; +int skip_delegate;unsigned int version[3 ];unsigned int sequence_nr;
multipath/main.c +11 -4
@@ -130,9 +130,9 @@ usage (char * progname) {fprintf (stderr,VERSION_STRING );fprintf (stderr,"Usage:\n" ); -fprintf (stderr," %s [-v level] [-B|-d|-i|-q|-r] [-b file] [-p policy] [device]\n" , progname); -fprintf (stderr," %s [-v level] [-R retries] -f device\n" , progname); -fprintf (stderr," %s [-v level] [-R retries] -F\n" , progname); +fprintf (stderr," %s [-v level] [-B|-d|-D|-i|-q|-r] [-b file] [-p policy] [device]\n" , progname); +fprintf (stderr," %s [-v level] [-D|-R retries] -f device\n" , progname); +fprintf (stderr," %s [-v level] [-D|-R retries] -F\n" , progname);fprintf (stderr," %s [-v level] [-l|-ll] [device]\n" , progname);fprintf (stderr," %s [-v level] [-a|-w] device\n" , progname);fprintf (stderr," %s [-v level] -W\n" , progname);
@@ -153,6 +153,7 @@ usage (char * progname)" -C check if a multipath device has usable paths\n" " -q allow queue_if_no_path when multipathd is not running\n" " -d dry run, do not create or update devmaps\n" +" -D Do not delegate command to multipathd\n" " -t display the currently used multipathd configuration\n" " -T display the multipathd configuration without builtin defaults\n" " -r force devmap reload\n"
@@ -817,6 +818,9 @@ int delegate_to_multipathd(enum mpath_cmds cmd, *p ='\0' ; n =sizeof (command); +if (conf->skip_delegate) +return NOT_DELEGATED ; +if (cmd ==CMD_CREATE && conf->force_reload ==FORCE_RELOAD_YES ) { p +=snprintf (p, n,"reconfigure" ); }
@@ -890,7 +894,7 @@ main (int argc, char *argv[]) multipath_conf = conf; conf->retrigger_tries =0 ; conf->force_sync =1 ; -while ((arg =getopt (argc, argv,":adcChl::eFfM:v:p:b:BrR:itTquUwW" )) !=EOF ) { +while ((arg =getopt (argc, argv,":adDcChl::eFfM:v:p:b:BrR:itTquUwW" )) !=EOF ) {switch (arg) {case 1 :printf ("optarg : %s\n" ,optarg);break ;
@@ -922,6 +926,9 @@ main (int argc, char *argv[])if (cmd ==CMD_CREATE ) cmd =CMD_DRY_RUN ;break ; +case 'D' : + conf->skip_delegate =1 ; +break ;case 'f' : cmd =CMD_FLUSH_ONE ;break ;
multipath/multipath.8 +11 -5
@@ -22,7 +22,7 @@ multipath \- Device mapper target autoconfig. .B multipath .RB [\| \-v\ \c .IR level \|] -.RB [\| \-B | \-d | \-i | \-q | \-r \|] +.RB [\| \-B | \-d | \-D | \-i | \-q | \-r \|] .RB [\| \-b\ \c .IR file \|] .RB [\| \-p\ \c
@@ -33,7 +33,7 @@ multipath \- Device mapper target autoconfig. .B multipath .RB [\| \-v\ \c .IR level \|] -.RB [\| \-R\ \c +.RB [\| \-D | \-R\ \c .IR retries \|] .B \-f device .
@@ -41,7 +41,7 @@ multipath \- Device mapper target autoconfig. .B multipath .RB [\| \-v\ \c .IR level \|] -.RB [\| \-R\ \c +.RB [\| \-D | \-R\ \c .IR retries \|] .B \-F .
@@ -125,11 +125,11 @@ the system. Other operation modes are chosen by using one of the following command line switches: .TP .B \-f -Flush (remove) a multipath device map specified as parameter, if unused. +Flush (remove) a multipath device map specified as parameter, if unused. This operation is delegated to the multipathd daemon if it's running. . .TP .B \-F -Flush (remove) all unused multipath device maps. +Flush (remove) all unused multipath device maps. This operation is delegated to the multipathd daemon if it's running. . .TP .B \-l
@@ -223,6 +223,12 @@ The verbosity level also controls the level of log and debug messages printed to Dry run, do not create or update devmaps. . .TP +.B \-D +Do not delegate operation to multipathd. By default, multipath delegates +forced reloads and flushes (removes) to multipathd. Setting this option will +cause the multipath command to execute these operations itself. +. +.TP .B \-e Enable all foreign libraries. This overrides the .I enable_foreign
Signature · 1 line
2.17.2
Re: [PATCH 7/7] multipath: add option to skip multipathd delegation
Quoted 10 lines · Benjamin Marzinski
Add the -D option to allow users to skip delegating commands to multipathd.
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/config.h | 1 + multipath/main.c | 15 +++++++++++---- multipath/multipath.8 | 16 +++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-)
I wonder if we really need this. We fall back to NOT_DELEGATED anyway. If users really, really want this, they can run multipath while multipathd is stopped.
I'm not saying it's totally useless, but the presence of this option suggests to users that they may want to use it, which I doubt. Perhaps we want to have it, for debugging or expert usage purpose, as a hidden/undocumented option?
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 7/7] multipath: add option to skip multipathd delegation
Quoted 12 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski
Add the -D option to allow users to skip delegating commands to multipathd.
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/config.h | 1 + multipath/main.c | 15 +++++++++++---- multipath/multipath.8 | 16 +++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-)
Quoted 8 lines
I wonder if we really need this. We fall back to
NOT_DELEGATEDanyway. If users really, really want this, they can run multipath while multipathd is stopped.I'm not saying it's totally useless, but the presence of this option suggests to users that they may want to use it, which I doubt. Perhaps we want to have it, for debugging or expert usage purpose, as a hidden/undocumented option?
I'm fine with having it as an undocumented option.
-Ben
Quoted 9 lines
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Quoted 12 lines · Benjamin Marzinski
One source of complexity in these patches is that multipath suspends the
device with flushing before removing it, while multipathd doesn't. It
does seem possible that the suspend could hang for a while, so I can understand multipathd not using it. However, that would take the multipath device getting opened and IO being issued, between the time when_dm_flush_map()verifies that the device isn't opened, and when it
suspends the device. But more importantly, I don't understand how suspending the device is useful.
I've looked up the origin of 9a4ff93 in SUSE bugzilla. The problem that the patch tried to solve was that if map without healthy paths and with queue_if_no_path set was removed, the removal might fail with "map is in use". Hannes' comment at the time was this:
"Problem is that we're not waiting for all outstanding I/Os to complete. So the check for 'map in use' might trigger a false positive, as the outstanding I/O will keep the map busy. Once it's finished we can remove the map."
"I'll add an explicit 'suspend/resume' cycle here, which will wait for all outstanding I/O to finish. That should resolve the situation."
Thus setting queue_if_no_paths = 0 and doing a suspend/resume was basically a trick to force dm to flush outstanding IO.
Quoted 7 lines
If the device were to be opened
between when_dm_flush_map()checks the usage, and when it tries to delete the device, device-mapper would simply fail the remove. And if
the device isn't in use, there can't be any outstanding IO to flush. When this code was added in commit 9a4ff93, there was no check if the device was in use,
Hm, I see this in the code preceding 9a4ff93:
extern int_dm_flush_map (const char * mapname, int need_sync) {
[...]
if (dm_get_opencount(mapname)) {
condlog(2, "%s: map in use", mapname);
return 1;
}... so it seems that there was a check, even back then.
Quoted 7 lines
and disabling
queue_if_no_pathcould cause anything
that had the device open to error out and close it. But now that multipath checks first if the device is open, I don't see the benefit to
doing this anymore. Removing it would allow multipathd and multipath to
use the same code to remove maps. Any thoughts?
With queue_if_no_paths, there could be outstanding IO even if the opencount was 0. This IO must be flushed somehow before the map can be removed. Apparently just setting queue_if_no_path = 0 was not enough, that's why Hannes added the suspend/resume. Maybe today we have some better way to force the flush? libdm has the _error_device() function (aka dmsetup wipe_table) that replaces the map's table by the error target. But this does a map reload, which implies a suspend, too. Perhaps simply an fsync() on the dm device, or just wait a while until all outstanding IO has errored out? But these alternatives don't actually look better to me than Hannes' suspend/resume, they will take at least as much time. Do you have a better idea?
multipathd
Regards
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerQuoted 24 lines · Martin Wilck
Quoted 12 lines · Benjamin Marzinski
One source of complexity in these patches is that multipath suspends the
device with flushing before removing it, while multipathd doesn't. It
does seem possible that the suspend could hang for a while, so I can understand multipathd not using it. However, that would take the multipath device getting opened and IO being issued, between the time when_dm_flush_map()verifies that the device isn't opened, and when it
suspends the device. But more importantly, I don't understand how suspending the device is useful.I've looked up the origin of 9a4ff93 in SUSE bugzilla. The problem that the patch tried to solve was that if map without healthy paths and with
queue_if_no_pathset was removed, the removal might fail with "map is in use". Hannes' comment at the time was this:"Problem is that we're not waiting for all outstanding I/Os to complete. So the check for 'map in use' might trigger a false positive, as the outstanding I/O will keep the map busy. Once it's finished we can remove the map."
Quoted 5 lines
"I'll add an explicit 'suspend/resume' cycle here, which will wait for all outstanding I/O to finish. That should resolve the situation."
Thus setting
queue_if_no_paths= 0 and doing a suspend/resume was basically a trick to force dm to flush outstanding IO.
I get the intention, I just don't think it currently is doing anything.
Quoted 14 lines
Quoted 7 lines
If the device were to be opened
between when_dm_flush_map()checks the usage, and when it tries to delete the device, device-mapper would simply fail the remove. And if
the device isn't in use, there can't be any outstanding IO to flush. When this code was added in commit 9a4ff93, there was no check if the device was in use,Hm, I see this in the code preceding 9a4ff93:
extern int
_dm_flush_map(const char * mapname, intneed_sync) {
[...]
Quoted 6 lines
if (dm_get_opencount(mapname)) { condlog(2, "%s: map in use", mapname); return 1; }... so it seems that there was a check, even back then.
oops. I missed that.
Quoted 10 lines
Quoted 7 lines
and disabling
queue_if_no_pathcould cause anything
that had the device open to error out and close it. But now that multipath checks first if the device is open, I don't see the benefit to
doing this anymore. Removing it would allow multipathd and multipath to
use the same code to remove maps. Any thoughts?With
queue_if_no_paths, there could be outstanding IO even if the opencount was 0.
This is what I don't accept at face value. I wrote a little test program that fired off an async read, closed the fd without waiting for a response, and then tried to exit. running this on a queueing multipath device causes the exit to hang like this
cat /proc/22655/task/22655/stack
[<0>] exit_aio+0xdc/0xf0 [<0>] mmput+0x33/0x130 [<0>] do_exit+0x27f/0xb30 [<0>] do_group_exit+0x3a/0xa0 [<0>] __x64_sys_exit_group+0x14/0x20 [<0>] do_syscall_64+0x5b/0x160 [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[<0>] 0xffffffffffffffff
and the multipath device to remain in use
# dmsetup info mpathb Name: mpathb State: ACTIVE Read Ahead: 256 Tables present: LIVE Open count: 0 Event number: 7 Major, minor: 253, 5 Number of targets: 1 UUID: mpath-3600d0230000000000e13954ed5f89301
I've asked around, and device-mapper is certainly supposed to flush all IO before the last close. Of course, there may be a corner case where it doesn't. If you know of one, that would be worth sharing.
What I think that flush previously accomplished is that, just like the flush_on_last_del code, if you stop queueing and error out the IO, then whatever is waiting on it will get those errors, and likely close the device soon after, hopefully in time for multipath to remove the device.
However, since multipath now checks if the device is in use before disabling queue_if_no_path, it don't think this code is actually helpful right now.
Quoted 10 lines
This IO must be flushed somehow before the map can be removed. Apparently just setting
queue_if_no_path= 0 was not enough, that's why Hannes added the suspend/resume. Maybe today we have some better way to force the flush? libdm has the_error_device()function (aka dmsetupwipe_table) that replaces the map's table by the error target. But this does a map reload, which implies a suspend, too. Perhaps simply anfsync()on the dm device, or just wait a while until all outstanding IO has errored out? But these alternatives don't actually look better to me than Hannes' suspend/resume, they will take at least as much time. Do you have a better idea?
To go back to the old behavior, we would need to move the check if the device is in use until after we suspended the device. Or we can keep the current behavior, and simply remove the flushing and suspending.
Quoted 11 lines
multipathd
Regards
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Quoted 23 lines · Benjamin Marzinski
Quoted 3 lines · Martin Wilck
With
queue_if_no_paths, there could be outstanding IO even if the opencount was 0.This is what I don't accept at face value. I wrote a little test program that fired off an async read, closed the fd without waiting for
a response, and then tried to exit. running this on a queueing multipath device causes the exit to hang like thiscat
/proc/22655/task/22655/stack[<0>] exit_aio+0xdc/0xf0 [<0>] mmput+0x33/0x130 [<0>] do_exit+0x27f/0xb30 [<0>] do_group_exit+0x3a/0xa0 [<0>] __x64_sys_exit_group+0x14/0x20 [<0>] do_syscall_64+0x5b/0x160 [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9[<0>]
0xffffffffffffffffand the multipath device to remain in use
Quoted 11 lines
# dmsetup info mpathb Name: mpathb State: ACTIVE Read Ahead: 256 Tables present: LIVE Open count: 0 Event number: 7 Major, minor: 253, 5 Number of targets: 1 UUID: mpath-3600d0230000000000e13954ed5f89301
The open count is 0. Wouldn't this be exactly the situation that Hannes' patch was targeting - opencount 0, but still unable to flush/close because of outstanding IO? If multipath was trying to flush the map in this situation, it would disable queueing. Your process would get an IO error sooner or later, and exit. But depending on the amount of outstanding IO and the weather, this might not happen before multipath had attempted to flush the map, and the flush attempt would fail. By inserting the synchronous flush operation after disabling queueing, multipath avoids that failure. Am I misunderstanding something?
Quoted 35 lines
I've asked around, and device-mapper is certainly supposed to flush all
IO before the last close. Of course, there may be a corner case where it
doesn't. If you know of one, that would be worth sharing.What I think that flush previously accomplished is that, just like the
flush_on_last_delcode, if you stop queueing and error out the IO, then
whatever is waiting on it will get those errors, and likely close the device soon after, hopefully in time for multipath to remove the device.However, since multipath now checks if the device is in use before disabling
queue_if_no_path, it don't think this code is actually helpful
right now.Quoted 7 lines
This IO must be flushed somehow before the map can be removed. Apparently just setting
queue_if_no_path= 0 was not enough,
that's why Hannes added the suspend/resume. Maybe today we have some
better way to force the flush? libdm has the_error_device()functionQuoted 8 lines
(aka dmsetup
wipe_table) that replaces the map's table by the error target. But this does a map reload, which implies a suspend, too. Perhaps simply anfsync()on the dm device, or just wait a while until
all outstanding IO has errored out? But these alternatives don't actually look better to me than Hannes' suspend/resume, they will take
at least as much time. Do you have a better idea?
Quoted 6 lines
To go back to the old behavior, we would need to move the check if the
device is in use until after we suspended the device. Or we can keep the
current behavior, and simply remove the flushing and suspending.
AFAICS the "in use" check looks at the opencount, and according to your output above, it can be 0 while IO is outstanding. I haven't checked this myself yet. But I can confirm that there was an actual bug (map removal failing) that was allegedly fixed by the suspend/resume. It was long ago, I can't tell with confidence if it could still happen.
Don't get me wrong, I'm not generally opposed to the removal of the flush/suspend. I just wanted to clarify why it was there. It has been used in multipath only, anyway. If we delegate to multipathd, it makes sense to handle the situation in multipathd's manner. If we want to make sure the user experience for "multipath -f" users is unchanged, we could handle failure accordingly (suspend, resume, and retry flushing the map).
Best,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerQuoted 36 lines · Martin Wilck
Quoted 23 lines · Benjamin Marzinski
Quoted 3 lines · Martin Wilck
With
queue_if_no_paths, there could be outstanding IO even if the opencount was 0.This is what I don't accept at face value. I wrote a little test program that fired off an async read, closed the fd without waiting for
a response, and then tried to exit. running this on a queueing multipath device causes the exit to hang like thiscat
/proc/22655/task/22655/stack[<0>] exit_aio+0xdc/0xf0 [<0>] mmput+0x33/0x130 [<0>] do_exit+0x27f/0xb30 [<0>] do_group_exit+0x3a/0xa0 [<0>] __x64_sys_exit_group+0x14/0x20 [<0>] do_syscall_64+0x5b/0x160 [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9[<0>]
0xffffffffffffffffand the multipath device to remain in use
Quoted 11 lines
# dmsetup info mpathb Name: mpathb State: ACTIVE Read Ahead: 256 Tables present: LIVE Open count: 0 Event number: 7 Major, minor: 253, 5 Number of targets: 1 UUID: mpath-3600d0230000000000e13954ed5f89301
Quoted 1 line
The open count is 0.
Whoops. I copied the output from after I restored the path, and the program exitted. While it is hung, you see this:
# dmsetup info mpathb Name: mpathb State: ACTIVE Read Ahead: 256 Tables present: LIVE Open count: 1 Event number: 8 Major, minor: 253, 5 Number of targets: 1 UUID: mpath-3600d0230000000000e13954ed5f89301
I uploaded the test program, aio_test:
https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no active paths and an open count of 0. It will hang with the device open. Restore a path, and it will exit, and the open count will go to 0.
-Ben
Quoted 77 lines
Wouldn't this be exactly the situation that
Hannes' patch was targeting - opencount 0, but still unable to flush/close because of outstanding IO? If multipath was trying to flush the map in this situation, it would disable queueing. Your process would get an IO error sooner or later, and exit. But depending on the amount of outstanding IO and the weather, this might not happen before multipath had attempted to flush the map, and the flush attempt would fail. By inserting the synchronous flush operation after disabling queueing, multipath avoids that failure. Am I misunderstanding something?Quoted 35 lines
I've asked around, and device-mapper is certainly supposed to flush all
IO before the last close. Of course, there may be a corner case where it
doesn't. If you know of one, that would be worth sharing.What I think that flush previously accomplished is that, just like the
flush_on_last_delcode, if you stop queueing and error out the IO, then
whatever is waiting on it will get those errors, and likely close the device soon after, hopefully in time for multipath to remove the device.However, since multipath now checks if the device is in use before disabling
queue_if_no_path, it don't think this code is actually helpful
right now.Quoted 7 lines
This IO must be flushed somehow before the map can be removed. Apparently just setting
queue_if_no_path= 0 was not enough,
that's why Hannes added the suspend/resume. Maybe today we have some
better way to force the flush? libdm has the_error_device()functionQuoted 8 lines
(aka dmsetup
wipe_table) that replaces the map's table by the error target. But this does a map reload, which implies a suspend, too. Perhaps simply anfsync()on the dm device, or just wait a while until
all outstanding IO has errored out? But these alternatives don't actually look better to me than Hannes' suspend/resume, they will take
at least as much time. Do you have a better idea?Quoted 6 lines
To go back to the old behavior, we would need to move the check if the
device is in use until after we suspended the device. Or we can keep the
current behavior, and simply remove the flushing and suspending.AFAICS the "in use" check looks at the opencount, and according to your output above, it can be 0 while IO is outstanding. I haven't checked this myself yet. But I can confirm that there was an actual bug (map removal failing) that was allegedly fixed by the suspend/resume. It was long ago, I can't tell with confidence if it could still happen.
Don't get me wrong, I'm not generally opposed to the removal of the flush/suspend. I just wanted to clarify why it was there. It has been used in multipath only, anyway. If we delegate to multipathd, it makes sense to handle the situation in multipathd's manner. If we want to make sure the user experience for "multipath -f" users is unchanged, we could handle failure accordingly (suspend, resume, and retry flushing the map).
Best,
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Quoted 9 lines · Benjamin Marzinski
I uploaded the test program,
aio_test:https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no active paths and an open count of 0. It will hang with the device open. Restore
a path, and it will exit, and the open count will go to 0.
Tried it now, it behaves as you say. I admit I can't imagine how the suspend/resume would improve anything here. Indeed, as you say, it opens up a race window. Another process might open the device while it's suspended. Worse perhaps, once the device is resumed, an uevent will be generated, and stacked devices might (in principle at least) be recreated before we get down to flush the map.
MAYBE the suspend/resume was necessary in the past because some earlier kernels wouldn't immediately fail all outstanding commands when queue_if_no_path was deactivated? (just speculating, I don't know if this is the case).
Regards,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerQuoted 18 lines · Martin Wilck
Quoted 9 lines · Benjamin Marzinski
I uploaded the test program,
aio_test:https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no active paths and an open count of 0. It will hang with the device open. Restore
a path, and it will exit, and the open count will go to 0.Tried it now, it behaves as you say. I admit I can't imagine how the suspend/resume would improve anything here. Indeed, as you say, it opens up a race window. Another process might open the device while it's suspended. Worse perhaps, once the device is resumed, an uevent will be generated, and stacked devices might (in principle at least) be recreated before we get down to flush the map.
Quoted 4 lines
MAYBE the suspend/resume was necessary in the past because some earlier kernels wouldn't immediately fail all outstanding commands when
queue_if_no_pathwas deactivated? (just speculating, I don't know if this is the case).
If you disable queue_if_no_path and then do a suspend with flushing, you are guaranteed that the supend won't return until all the IO has completed or failed. This would allow anything that was waiting on queued IO to have the IO failback, which could allow it to close the device in time for multipath to be able to remove it (obviously this is racey). However, this assumes that you do your open checks after the suspend, which multipath no longer does. I realize that multipath can't suspend until after it tries to remove the partition devices, otherwise those can get stuck. But there probably is some order that gets this all right-ish.
So, for a while now, the suspending has been doing nothing for us. We could either try to reorder things so that we actually try to flush the queued IOs back first (with or without suspending), or we could just remove suspending and say that things are working fine the way they currently are.
-Ben
Quoted 10 lines
Regards,
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Quoted 30 lines · Benjamin Marzinski
Quoted 22 lines · Martin Wilck
Quoted 9 lines · Benjamin Marzinski
I uploaded the test program,
aio_test:https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no active
paths and an open count of 0. It will hang with the device open. Restore
a path, and it will exit, and the open count will go to 0.Tried it now, it behaves as you say. I admit I can't imagine how the
suspend/resume would improve anything here. Indeed, as you say, it opens
up a race window. Another process might open the device while it's suspended. Worse perhaps, once the device is resumed, an uevent will be
generated, and stacked devices might (in principle at least) be recreated
before we get down to flush the map.Quoted 6 lines
MAYBE the suspend/resume was necessary in the past because some earlier
kernels wouldn't immediately fail all outstanding commands whenqueue_if_no_pathwas deactivated? (just speculating, I don't know if this
is the case).
Quoted 4 lines
If you disable
queue_if_no_pathand then do a suspend with flushing, you
are guaranteed that the supend won't return until all the IO has completed or failed.
I just realized that if we suspend, we don't even need disable queue_if_no_path, because the kernel does that automatically if a "suspend with flush" is issued, and has been doing so basically forever.
Quoted 4 lines
This would allow anything that was waiting on
queued IO to have the IO failback, which could allow it to close the device in time for multipath to be able to remove it (obviously this is
Quoted 8 lines
racey). However, this assumes that you do your open checks after the suspend, which multipath no longer does.
I realize that multipath can't
suspend until after it tries to remove the partition devices, otherwise
those can get stuck. But there probably is some order that gets this all
right-ish.
Our code is currently racy. IMO we should
0 unset queue_if_no_path
1 remove partition mappings
2 open(O_EXCL|O_RDONLY) the device
3 If this fails, in multipath, try again after a suspend/resume cycle.
In multipathd, I think we should just fail for now; perhaps later we could handle the explicit "remove map" command like multipath.
4 If it fails again, bail out (in multipath, retry if asked to do so) 5 run a "deferred remove" ioctl
6 close the fd, the dm device will now be removed "atomically".
This cuts down the race window to the minimum possible - after (2), no mounts / kpartx / lvm operations won't be possible any more.
When we remove the partition mappings, we could use the same technique to avoid races on that layer. Unfortunately, a pending "deferred remove" operation doesn't cause new open() or mount() calls to fail; if it did, we could use a simpler approach.
Quoted 7 lines
So, for a while now, the suspending has been doing nothing for us. We
could either try to reorder things so that we actually try to flush the
queued IOs back first (with or without suspending), or we could just remove suspending and say that things are working fine the way they currently are.
What else can we do except suspend/resume to avoid racing with pending close(), umount() or similar operations? Well, I guess if we open the device anyway as I proposed, we could do an fsync() on it. That might actually be better because it avoids the uevent being sent on resume.
We definitely can't suspend the map before we remove the partitions. We could try a suspend/resume on the partition devices themselves (or fsync()) if the opencount is > 0.
Regards,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerQuoted 66 lines · Martin Wilck
Quoted 30 lines · Benjamin Marzinski
Quoted 22 lines · Martin Wilck
Quoted 9 lines · Benjamin Marzinski
I uploaded the test program,
aio_test:https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no active
paths and an open count of 0. It will hang with the device open. Restore
a path, and it will exit, and the open count will go to 0.Tried it now, it behaves as you say. I admit I can't imagine how the
suspend/resume would improve anything here. Indeed, as you say, it opens
up a race window. Another process might open the device while it's suspended. Worse perhaps, once the device is resumed, an uevent will be
generated, and stacked devices might (in principle at least) be recreated
before we get down to flush the map.Quoted 6 lines
MAYBE the suspend/resume was necessary in the past because some earlier
kernels wouldn't immediately fail all outstanding commands whenqueue_if_no_pathwas deactivated? (just speculating, I don't know if this
is the case).Quoted 4 lines
If you disable
queue_if_no_pathand then do a suspend with flushing, you
are guaranteed that the supend won't return until all the IO has completed or failed.I just realized that if we suspend, we don't even need disable
queue_if_no_path, because the kernel does that automatically if a "suspend with flush" is issued, and has been doing so basically forever.Quoted 4 lines
This would allow anything that was waiting on
queued IO to have the IO failback, which could allow it to close the device in time for multipath to be able to remove it (obviously this isQuoted 8 lines
racey). However, this assumes that you do your open checks after the suspend, which multipath no longer does.
I realize that multipath can't
suspend until after it tries to remove the partition devices, otherwise
those can get stuck. But there probably is some order that gets this all
right-ish.Our code is currently racy. IMO we should
0 unset
queue_if_no_path
1 remove partition mappings
2open(O_EXCL|O_RDONLY)the device
3 If this fails, in multipath, try again after a suspend/resume cycle.
In multipathd, I think we should just fail for now; perhaps later we could handle the explicit "remove map" command like multipath.
4 If it fails again, bail out (in multipath, retry if asked to do so) 5 run a "deferred remove" ioctl
6 close the fd, the dm device will now be removed "atomically".
Quoted 2 lines
This cuts down the race window to the minimum possible - after (2), no mounts / kpartx / lvm operations won't be possible any more.
I wasn't actually worried about someone wanting to use the device. In that case the remove should fail. I was worried about things that would close the device, but couldn't because of queued IO. The race I was talking about is that after whatever has the device open gets the IO error, it might not close the device before multipath checks the open count.
Also, I'm not sure that resume helps us, since that will trigger uevents, which will open the device again.
Quoted 13 lines
When we remove the partition mappings, we could use the same technique to avoid races on that layer. Unfortunately, a pending "deferred remove" operation doesn't cause new
open()ormount()calls to fail; if it did, we could use a simpler approach.Quoted 7 lines
So, for a while now, the suspending has been doing nothing for us. We
could either try to reorder things so that we actually try to flush the
queued IOs back first (with or without suspending), or we could just remove suspending and say that things are working fine the way they currently are.
Quoted 4 lines
What else can we do except suspend/resume to avoid racing with pending
close(),umount()or similar operations? Well, I guess if we open the device anyway as I proposed, we could do anfsync()on it. That might actually be better because it avoids the uevent being sent on resume.
yeah. I think that simply disabling queueing and doing an fsync() is probably better than suspending. If new IO comes in after that, then something IS using the device, and we don't want to remove it. In multipath, maybe:
1. disable queueing
2. remove partition mappings
3. open device
4. flush
5. check if we are the only opener.
If not, and there are retries left... goto 4? sleep and recheck? we don't want to wait if the answer is that they device really is in use.
6. close device
7. remove device
Possibly the solution to not wanting to wait when a device is in use is that we could add an option to multipath to distinguish between the way flushing works now, where we check early if the device is in use, and just bail if it is, and a more aggressive attempt at remove that might take longer if used on devices that are in use.
-Ben
Quoted 13 lines
We definitely can't suspend the map before we remove the partitions. We could try a suspend/resume on the partition devices themselves (or
fsync()) if the opencount is > 0.Regards,
MartinSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Quoted 86 lines · Benjamin Marzinski
Quoted 81 lines · Martin Wilck
Quoted 36 lines · Benjamin Marzinski
Quoted 26 lines · Martin Wilck
Quoted 11 lines · Benjamin Marzinski
I uploaded the test program,
aio_test:https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no
active
paths and an open count of 0. It will hang with the device open.
Restore
a path, and it will exit, and the open count will go to 0.Tried it now, it behaves as you say. I admit I can't imagine how
the
suspend/resume would improve anything here. Indeed, as you say, it
opens
up a race window. Another process might open the device while it's suspended. Worse perhaps, once the device is resumed, an uevent will be
generated, and stacked devices might (in principle at least) be recreated
before we get down to flush the map.Quoted 8 lines
MAYBE the suspend/resume was necessary in the past because some earlier
kernels wouldn't immediately fail all outstanding commands whenqueue_if_no_pathwas deactivated? (just speculating, I don't know
if this
is the case).Quoted 5 lines
If you disable
queue_if_no_pathand then do a suspend with flushing,
you
are guaranteed that the supend won't return until all the IO has completed or failed.I just realized that if we suspend, we don't even need disable
queue_if_no_path, because the kernel does that automatically if a "suspend with flush" is issued, and has been doing so basically forever.Quoted 8 lines
This would allow anything that was waiting on
queued IO to have the IO failback, which could allow it to close the
device in time for multipath to be able to remove it (obviously this
is
racey). However, this assumes that you do your open checks after theQuoted 8 lines
suspend, which multipath no longer does.
I realize that multipath can't
suspend until after it tries to remove the partition devices, otherwise
those can get stuck. But there probably is some order that gets this
all
right-ish.Our code is currently racy. IMO we should
0 unset
queue_if_no_path
1 remove partition mappings
2open(O_EXCL|O_RDONLY)the device
3 If this fails, in multipath, try again after a suspend/resume
cycle.
In multipathd, I think we should just fail for now; perhaps
later
we could handle the explicit "remove map" command like
multipath.
4 If it fails again, bail out (in multipath, retry if asked to do
so)
5 run a "deferred remove" ioctl
6 close the fd, the dm device will now be removed "atomically".Quoted 3 lines
This cuts down the race window to the minimum possible - after (2), no
mounts / kpartx / lvm operations won't be possible any more.
Quoted 8 lines
I wasn't actually worried about someone wanting to use the device. In that case the remove should fail. I was worried about things that would
close the device, but couldn't because of queued IO.
The race I was
talking about is that after whatever has the device open gets the IO error, it might not close the device before multipath checks the open count.
Understood.
Quoted 2 lines
Also, I'm not sure that resume helps us, since that will trigger uevents, which will open the device again.
Not sure if I understand correctly: It's possible to just suspend/flush and then remove the device, without resuming. But that's dangerous, because if some process opens the device while it's resumed, even if it's just for reading a single block (think blkid), the open will succeed, the IO will hang, the opencount will be increased, and the REMOVE ioctl will fail. Therefore I think *if* we suspend we should also resume. But I concur wrt the uevent, of course.
Quoted 44 lines
Quoted 18 lines
When we remove the partition mappings, we could use the same technique
to avoid races on that layer. Unfortunately, a pending "deferred remove" operation doesn't cause newopen()ormount()calls to fail; if
it did, we could use a simpler approach.Quoted 10 lines
So, for a while now, the suspending has been doing nothing for us. We
could either try to reorder things so that we actually try to flush
the
queued IOs back first (with or without suspending), or we could just
remove suspending and say that things are working fine the way they
currently are.Quoted 8 lines
What else can we do except suspend/resume to avoid racing with pending
close(),umount()or similar operations? Well, I guess if we open the
device anyway as I proposed, we could do anfsync()on it. That might
actually be better because it avoids the uevent being sent on resume.yeah. I think that simply disabling queueing and doing an
fsync()is probably better than suspending. If new IO comes in after that, then something IS using the device, and we don't want to remove it. In multipath, maybe:1. disable queueing
2. remove partition mappings
3. open device
4. flush
5. check if we are the only opener.
If not, and there are retries left... goto 4? sleep and
recheck?
we don't want to wait if the answer is that they device really is in use.
6. close device
7. remove device
Quoted 8 lines
Possibly the solution to not wanting to wait when a device is in use is
that we could add an option to multipath to distinguish between the way
flushing works now, where we check early if the device is in use, and just bail if it is, and a more aggressive attempt at remove that might
take longer if used on devices that are in use.
What's wrong with deferred remove? After all, the user explicitly asked for a flush. As long as some other process has the device open, it won't be removed. That's why I like the O_EXCL idea, which will allow small programs like blkid to access the device, but will cause all attempts to mount or add stacked devices to fail until the device is actually removed. I see no reason no to do this, as it's a race anyway if some other process opens the device when we're supposed to flush it and the opencount already dropped to 0. By using O_EXCL, we just increase multipathd's chances to win the race and do what the user asked for.
To make sure we're on the same boat: this is a topic for a separate patch set IMO, I'm not expecting you to fix it in a v3.
Cheers,
Martin
Benjamin Marzinski
maintainerQuoted 101 lines · Martin Wilck
Quoted 86 lines · Benjamin Marzinski
Quoted 81 lines · Martin Wilck
Quoted 36 lines · Benjamin Marzinski
Quoted 26 lines · Martin Wilck
Quoted 11 lines · Benjamin Marzinski
I uploaded the test program,
aio_test:https://github.com/bmarzins/test_programs.git
You just need to run in on a queueing multipath device with no
active
paths and an open count of 0. It will hang with the device open.
Restore
a path, and it will exit, and the open count will go to 0.Tried it now, it behaves as you say. I admit I can't imagine how
the
suspend/resume would improve anything here. Indeed, as you say, it
opens
up a race window. Another process might open the device while it's suspended. Worse perhaps, once the device is resumed, an uevent will be
generated, and stacked devices might (in principle at least) be recreated
before we get down to flush the map.Quoted 8 lines
MAYBE the suspend/resume was necessary in the past because some earlier
kernels wouldn't immediately fail all outstanding commands whenqueue_if_no_pathwas deactivated? (just speculating, I don't know
if this
is the case).Quoted 5 lines
If you disable
queue_if_no_pathand then do a suspend with flushing,
you
are guaranteed that the supend won't return until all the IO has completed or failed.I just realized that if we suspend, we don't even need disable
queue_if_no_path, because the kernel does that automatically if a "suspend with flush" is issued, and has been doing so basically forever.Quoted 8 lines
This would allow anything that was waiting on
queued IO to have the IO failback, which could allow it to close the
device in time for multipath to be able to remove it (obviously this
is
racey). However, this assumes that you do your open checks after theQuoted 8 lines
suspend, which multipath no longer does.
I realize that multipath can't
suspend until after it tries to remove the partition devices, otherwise
those can get stuck. But there probably is some order that gets this
all
right-ish.Our code is currently racy. IMO we should
0 unset
queue_if_no_path
1 remove partition mappings
2open(O_EXCL|O_RDONLY)the device
3 If this fails, in multipath, try again after a suspend/resume
cycle.
In multipathd, I think we should just fail for now; perhaps
later
we could handle the explicit "remove map" command like
multipath.
4 If it fails again, bail out (in multipath, retry if asked to do
so)
5 run a "deferred remove" ioctl
6 close the fd, the dm device will now be removed "atomically".Quoted 3 lines
This cuts down the race window to the minimum possible - after (2), no
mounts / kpartx / lvm operations won't be possible any more.Quoted 8 lines
I wasn't actually worried about someone wanting to use the device. In that case the remove should fail. I was worried about things that would
close the device, but couldn't because of queued IO.
The race I was
talking about is that after whatever has the device open gets the IO error, it might not close the device before multipath checks the open count.Understood.
Quoted 2 lines
Also, I'm not sure that resume helps us, since that will trigger uevents, which will open the device again.
Quoted 7 lines
Not sure if I understand correctly: It's possible to just suspend/flush and then remove the device, without resuming. But that's dangerous, because if some process opens the device while it's resumed, even if it's just for reading a single block (think blkid), the open will succeed, the IO will hang, the opencount will be increased, and the REMOVE ioctl will fail. Therefore I think *if* we suspend we should also resume. But I concur wrt the uevent, of course.
We obviously need to resume if the remove fails. I just an not sure we want to resume before deciding the remove has failed, since it will just add openers that we don't care about.
Quoted 53 lines
Quoted 44 lines
Quoted 18 lines
When we remove the partition mappings, we could use the same technique
to avoid races on that layer. Unfortunately, a pending "deferred remove" operation doesn't cause newopen()ormount()calls to fail; if
it did, we could use a simpler approach.Quoted 10 lines
So, for a while now, the suspending has been doing nothing for us. We
could either try to reorder things so that we actually try to flush
the
queued IOs back first (with or without suspending), or we could just
remove suspending and say that things are working fine the way they
currently are.Quoted 8 lines
What else can we do except suspend/resume to avoid racing with pending
close(),umount()or similar operations? Well, I guess if we open the
device anyway as I proposed, we could do anfsync()on it. That might
actually be better because it avoids the uevent being sent on resume.yeah. I think that simply disabling queueing and doing an
fsync()is probably better than suspending. If new IO comes in after that, then something IS using the device, and we don't want to remove it. In multipath, maybe:1. disable queueing
2. remove partition mappings
3. open device
4. flush
5. check if we are the only opener.
If not, and there are retries left... goto 4? sleep and
recheck?
we don't want to wait if the answer is that they device really is in use.
6. close device
7. remove deviceQuoted 8 lines
Possibly the solution to not wanting to wait when a device is in use is
that we could add an option to multipath to distinguish between the way
flushing works now, where we check early if the device is in use, and just bail if it is, and a more aggressive attempt at remove that might
take longer if used on devices that are in use.
Quoted 10 lines
What's wrong with deferred remove? After all, the user explicitly asked for a flush. As long as some other process has the device open, it won't be removed. That's why I like the
O_EXCLidea, which will allow small programs like blkid to access the device, but will cause all attempts to mount or add stacked devices to fail until the device is actually removed. I see no reason no to do this, as it's a race anyway if some other process opens the device when we're supposed to flush it and the opencount already dropped to 0. By usingO_EXCL, we just increase multipathd's chances to win the race and do what the user asked for.
I'm not actually a fan of deferred remove in general. It leaves the device in this weird state were it is there but no longer openable. I wish I had originally dealt with deferred removes by having multipathd occasionally try to flush devices with no paths, or possibly listen for notifications that the device has been closed, and flush then.
My specific objections here are that not all things that open a device for longer than an instant do so with O_EXCL. So it's very possible that you run "multipath -F", it returns having removed a number of unused devices. But some of the devices it didn't remove were opened without O_EXCL, and they will stick around for a while, and then suddenly disappear. Even if they don't say around for that long, this is a can still effect scripts or other programs that are expecting to check the device state immediately after calling multipath -F, and having it not change a second or so later. So far multipath -f/-F will not return until it has removed all the removeable devices (and waited for them to be removed from udev). I think it should stay this way.
Quoted 2 lines
To make sure we're on the same boat: this is a topic for a separate patch set IMO, I'm not expecting you to fix it in a v3.
Yep. It's future work.
Quoted 3 lines
Cheers,
Martin
Quoted 18 lines · Benjamin Marzinski
Quoted 16 lines · Martin Wilck
What's wrong with deferred remove? After all, the user explicitly asked
for a flush. As long as some other process has the device open, it won't be removed. That's why I like theO_EXCLidea, which will allow
small programs like blkid to access the device, but will cause all attempts to mount or add stacked devices to fail until the device is
actually removed. I see no reason no to do this, as it's a race anyway
if some other process opens the device when we're supposed to flush it
and the opencount already dropped to 0. By usingO_EXCL, we just increase multipathd's chances to win the race and do what the user asked for.
Quoted 2 lines
I'm not actually a fan of deferred remove in general. It leaves the device in this weird state were it is there but no longer openable.
Ok, I didn't expect that ;-)
AFAICS, devices in DEFERRED REMOVE state are actually still openable. I just tested this once more on a 5.3 kernel.
As long as the device is opened by some process and thus not removed, it can be opened by other processes, and is not deleted until the last opener closes it. It's even possible to create new device mapper layers like kpartx partitions on top of a DM device in DEFERRED REMOVE state.
Quoted 7 lines
I
wish I had originally dealt with deferred removes by having multipathd
occasionally try to flush devices with no paths, or possibly listen for
notifications that the device has been closed, and flush then.
Quoted 15 lines
My specific objections here are that not all things that open a device
for longer than an instant do so withO_EXCL. So it's very possible that you run "multipath -F", it returns having removed a number of unused devices. But some of the devices it didn't remove were opened withoutO_EXCL, and they will stick around for a while, and then suddenly disappear. Even if they don't say around for that long, this
is a can still effect scripts or other programs that are expecting to check the device state immediately after calling multipath -F, and having it not change a second or so later. So far multipath -f/-F will
not return until it has removed all the removeable devices (and waited
for them to be removed from udev). I think it should stay this way.
I see. That's a valid point. IMHO it'd be better if the kernel didn't allow any new access to devices in "deferred remove" state, and possibly sent a REMOVE uevent and hide the device immediately after the deferred remove ioctl.
That would also be closer to how "lazy umount" (umount -l) behaves. But I'm certainly overlooking some subtle semantic issues.
@Mike, Zdenek: perhaps you can explain why "deferred remove" behaves like this?
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Quoted 60 lines · Martin Wilck
Quoted 18 lines · Benjamin Marzinski
Quoted 16 lines · Martin Wilck
What's wrong with deferred remove? After all, the user explicitly asked
for a flush. As long as some other process has the device open, it won't be removed. That's why I like theO_EXCLidea, which will allow
small programs like blkid to access the device, but will cause all attempts to mount or add stacked devices to fail until the device is
actually removed. I see no reason no to do this, as it's a race anyway
if some other process opens the device when we're supposed to flush it
and the opencount already dropped to 0. By usingO_EXCL, we just increase multipathd's chances to win the race and do what the user asked for.Quoted 2 lines
I'm not actually a fan of deferred remove in general. It leaves the device in this weird state were it is there but no longer openable.
Ok, I didn't expect that ;-)
AFAICS, devices in DEFERRED REMOVE state are actually still openable. I just tested this once more on a 5.3 kernel.
As long as the device is opened by some process and thus not removed, it can be opened by other processes, and is not deleted until the last opener closes it. It's even possible to create new device mapper layers like kpartx partitions on top of a DM device in DEFERRED REMOVE state.
Quoted 7 lines
I
wish I had originally dealt with deferred removes by having multipathd
occasionally try to flush devices with no paths, or possibly listen for
notifications that the device has been closed, and flush then.Quoted 15 lines
My specific objections here are that not all things that open a device
for longer than an instant do so withO_EXCL. So it's very possible that you run "multipath -F", it returns having removed a number of unused devices. But some of the devices it didn't remove were opened withoutO_EXCL, and they will stick around for a while, and then suddenly disappear. Even if they don't say around for that long, this
is a can still effect scripts or other programs that are expecting to check the device state immediately after calling multipath -F, and having it not change a second or so later. So far multipath -f/-F will
not return until it has removed all the removeable devices (and waited
for them to be removed from udev). I think it should stay this way.I see. That's a valid point. IMHO it'd be better if the kernel didn't allow any new access to devices in "deferred remove" state, and possibly sent a REMOVE uevent and hide the device immediately after the deferred remove ioctl.
Quoted 5 lines
That would also be closer to how "lazy umount" (umount -l) behaves. But I'm certainly overlooking some subtle semantic issues.
@Mike, Zdenek: perhaps you can explain why "deferred remove" behaves like this?
"deferred remove" was introduced with commits:
2c140a246dc dm: allow remove to be deferredacfe0ad74d2 dm: allocate a special workqueue for deferred device removal
The feature was developed to cater to the docker "devicemapper" graph driver [1][2] that uses DM thin provisioning in the backend (Red Hat's openshift once used a docker that used thinp in production for thinp's snapshot capabilities. overlayfs is now used instead because it allows page cache sharing which results in the ability to support vastly more containers that all are layered on snapshots of the same "device").
Anyway, back to deferred remove: docker's Go-lang based implementation and storage graph driver interface were clumsily written to require this lazy removal of used resources. As such, we had to adapt and the result was "deferred device" remove that really could be used by any DM device.
Docker couldn't have later opens fail due to a pending removal -- it'd break their app. So if you want it to do what you'd have imagined it to be; we'll need to introduce a new flag that alters the behavior (maybe as a module param off of DM core's dm-mod.ko). Patches welcome -- but you'll need a pretty good reason (not read back far enough but maybe you have one?).
Thanks,
Mike
[1] https://docs.docker.com/storage/storagedriver/device-mapper-driver/
[2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_atomic_host/7/html/managing_containers/managing_storage_with_docker_formatted_containers
Quoted 11 lines · Mike Snitzer
Docker couldn't have later opens fail due to a pending removal -- it'd
break their app. So if you want it to do what you'd have imagined it to
be; we'll need to introduce a new flag that alters the behavior (maybe
as a module param off of DM core's dm-mod.ko). Patches welcome -- but
you'll need a pretty good reason (not read back far enough but maybe you have one?).
Thanks a lot for the explanation. I don't think I'm going write patches and reason about it. We were just looking for the best way to safely flush maps in multipath-tools, and I'd considered deferred remove as one option, which it most likely is not. Anyway, I like to understand why thinks are the way they are, so thanks again.
Cheers,
Martin
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer