handle maps that need reloading
Benjamin Marzinski
maintainercover handle maps that need reloading
This patchset comes out of my review of Martin's 01ec4fa ("multipathd:
reload maps in do_sync_mpp() if necessary") patch to deal with
https://github.com/opensvc/multipath-tools/issues/105
I noticed some unrelated issues while reviewing it. Also, Patch 0002 is a slightly different version of Martin's 01ec4fa patch.
Benjamin Marzinski (3):
libmultipath: Don't skip set_path_max_sectors_kb()
multipathd: reload maps in checkerloop() if necessary.
multipathd: Don't call select_action in reload_map
libmultipath/structs_vec.c | 3 +-- multipathd/cli_handlers.c | 1 + multipathd/main.c | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.46.2
Benjamin Marzinski
maintainerPATCH 1/3 libmultipath: Don't skip set_path_max_sectors_kb()
If a multipath device already has need_reload set when a path is adopted, it won't call set_path_max_sectors_kb() because of short-circuit evaluation. This isn't what's intended.
--- libmultipath/structs_vec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libmultipath/structs_vec.c +1 -2
@@ -335,8 +335,7 @@ int adopt_paths(vector pathvec, struct multipath *mpp,*/ if (!current_mpp || !mp_find_path_by_devt (current_mpp, pp->dev_t)) - mpp->need_reload = mpp->need_reload || -set_path_max_sectors_kb (pp, mpp->max_sectors_kb); + mpp->need_reload =set_path_max_sectors_kb (pp, mpp->max_sectors_kb) || mpp->need_reload; } pp->mpp = mpp;
Signature · 1 line
2.46.2
Re: [PATCH 1/3] libmultipath: Don't skip set_path_max_sectors_kb()
Quoted 25 lines · Benjamin Marzinski
If a multipath device already has
need_reloadset when a path is adopted, it won't callset_path_max_sectors_kb()because of short-circuit evaluation. This isn't what's intended.Fixes e5e20c7b ("libmultipath: set max_sectors_kb in adopt_paths()")Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/structs_vec.c | 3 +--1 file changed, 1 insertion(+), 2 deletions(-)libmultipath/structs_vec.c +0
-0@@ -335,8 +335,7 @@ int adopt_paths(vector pathvec, struct multipath*mpp, */ if (!current_mpp ||
!mp_find_path_by_devt(current_mpp,pp->dev_t))libmultipath/structs_vec.c +0
-1- mpp->need_reload = mpp-Quoted 1 line
need_reload||-
set_path_max_sectors_kb(pp, mpp->max_sectors_kb);libmultipath/structs_vec.c +1
-0+ mpp->need_reload =
Quoted 4 lines
set_path_max_sectors_kb(pp, mpp->max_sectors_kb)||mpp->need_reload; }
pp->mpp= mpp;
Benjamin Marzinski
maintainerPATCH 2/3 multipathd: reload maps in checkerloop() if necessary.
In reply to Benjamin Marzinskiupdate_pathvec_from_dm() may set mpp->need_reload if it finds inconsistent settings. In this case, the map should be reloaded, but so far we don't do this reliably. Add a call to reload_and_sync_map() when updating the maps at the end of a loop in checkerloop().
--- multipathd/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
multipathd/main.c +4 -1
@@ -3038,7 +3038,10 @@ checkerloop (void *ap) start_time.tv_sec);if (checker_state ==CHECKER_FINISHED ) { vector_foreach_slot(vecs->mpvec, mpp, i) { -if (update_mpp_prio (vecs, mpp) ==2 ) { +if (update_mpp_prio (vecs, mpp) ==2 || + (mpp->need_reload && + mpp->synced_count >0 && +reload_and_sync_map (mpp, vecs) ==2 )) {/* multipath device deleted */ i--; }
Signature · 1 line
2.46.2
Re: [PATCH 2/3] multipathd: reload maps in checkerloop() if necessary.
Quoted 30 lines · Benjamin Marzinski
update_pathvec_from_dm()may setmpp->need_reloadif it finds inconsistent settings. In this case, the map should be reloaded, but so
far we don't do this reliably. Add a call toreload_and_sync_map()when updating the maps at the end of a loop incheckerloop().Suggested-by Martin Wilck <[email protected]>Signed-off-by Benjamin Marzinski <[email protected]>---
multipathd/main.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)multipathd/main.c +0
-0@@ -3038,7 +3038,10 @@ checkerloop (void *ap)
start_time.tv_sec);
if (checker_state==CHECKER_FINISHED) {vector_foreach_slot(vecs->mpvec, mpp, i){multipathd/main.c +0
-1- if (update_mpp_prio(vecs,mpp) == 2) {
multipathd/main.c +1
-0+ if (update_mpp_prio(vecs,mpp) == 2 ||
multipathd/main.c +2
-0+ (mpp->need_reload && + mpp->synced_count > 0&&
multipathd/main.c +1
-0+
Quoted 5 lines
reload_and_sync_map(mpp, vecs)== 2)) {
/* multipath device deleted */
i--;
The general logic is ok, but as noted on
https://github.com/opensvc/multipath-tools/issues/105), I believe that do_sync_mpp() is the more natural point in the code to attempt the reload, but I think it doesn't hurt to do both.
What I don't like so much about this patch is that from this point in the code, we can call reload_and_sync_map() directly, or indirectly through update_mpp_prio(). I find that confusing. I think we should change update_mpp_prio() to just set the need_reload() flag, and then simply look at the flag in checkerloop(). The "minor" actions in update_mpp_prio, such as switching path group, can still be done directly from there.
I can send a patch on top of yours if that's ok with you.
I have some questions. I've spent some time today pulling my hair over the many functions in the multipath-tools code that are related to syncing states. I'm kind of wound up in my own thinking, perhaps you can help me break out of the loop :-)
1) I observe that update_map() and reload_and_sync_map() are very similar. They both set up the map from multipathd's internal state, reload it, and then update multipathd's state. The differences are as follows:
- update_map() calls adopt_paths() and verify_paths() beforesetup_map(), while reload_map() only calls update_mpp_paths().
- It looks like an oversight to me that we don't callupdate_mpp_paths() in update_map(), what do you think?
- What about verify_paths(), why do we call it only in theupdate_map() code path?
- update_map() retries, while reload_and_sync_map() does not.
- update_map() calls the persistent-reservation related code.
These differences are few enough I think update_map() could actually call reload_and_sync_map() as a helper.
2) update_map() is called from missing_uev_wait_tick() and ghost_delay_tick(), while deferred_failback_tick() and the update_mpp_prio() code path above "only" call reload_and_sync_map(). Is this intentional? If yes, I am missing the rationale (I believe that just calling reload_and_sync_map() from all the _tick() functions would be sufficient, but I may be overlooking something).
I'd love it if we could integrate the various _tick() calls with the rest of the map-reload logic. Ideally the checkerloop and the tick() functions would just set the need_reload flag, and then we'd do the reload once at the end of the loop.
Regards,
Martin
Re: [PATCH 2/3] multipathd: reload maps in checkerloop() if necessary.
In reply to Benjamin MarzinskiQuoted 8 lines · Benjamin Marzinski
update_pathvec_from_dm()may setmpp->need_reloadif it finds inconsistent settings. In this case, the map should be reloaded, but so
far we don't do this reliably. Add a call toreload_and_sync_map()when updating the maps at the end of a loop incheckerloop().Suggested-by Martin Wilck <[email protected]>Signed-off-by Benjamin Marzinski <[email protected]>
(I'll send a couple of patches on top of yours)
Benjamin Marzinski
maintainerPATCH 3/3 multipathd: Don't call select_action in reload_map
In reply to Benjamin Marzinskireload_map() was calling select_action() with force_reload set. Since mpp will always be a member of vecs->mpvec when reload_map() is called, when cmpp and cmpp_by_name are looked up in select_action(), they will just point to mpp. This means that none of the early checks related to cmpp in select_action() will do anything, and the action will always end up being ACT_RELOAD. So we can just set ACT_RELOAD in reload_map() and skip the work.
Additionally, calling select_action() with force_reload set will set force_udev_reload. This isn't necessary for any of the reload_map() callers, and will just cause udev to do extra work. I did set force_udev_reload in cli_reload(), so that it works like calling "multipath -r", which does force udev to rescan the device.
--- multipathd/cli_handlers.c | 1 + multipathd/main.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
multipathd/cli_handlers.c +1 -0
@@ -818,6 +818,7 @@ cli_reload(void *v, struct strbuf *reply, void *data)return 1 ; } + mpp->force_udev_reload =1 ;return reload_and_sync_map (mpp, vecs); }
multipathd/main.c +1 -1
@@ -2273,7 +2273,7 @@ static int reload_map(struct vectors *vecs, struct multipath *mpp,condlog (0 ,"%s: failed to setup map" , mpp->alias);return 1 ; } -select_action (mpp, vecs->mpvec,1 ); + mpp->action =ACT_RELOAD ; r =domap (mpp, params, is_daemon);if (r ==DOMAP_FAIL || r ==DOMAP_RETRY ) {
Signature · 1 line
2.46.2
Re: [PATCH 3/3] multipathd: Don't call select_action in reload_map
Quoted 12 lines · Benjamin Marzinski
reload_map()was callingselect_action()withforce_reloadset. Since mpp will always be a member ofvecs->mpvecwhenreload_map()is called,
when cmpp andcmpp_by_nameare looked up inselect_action(), they will
just point to mpp. This means that none of the early checks related to
cmpp inselect_action()will do anything, and the action will always end up beingACT_RELOAD. So we can just setACT_RELOADinreload_map()
and skip the work.
Quoted 7 lines
Additionally, calling
select_action()withforce_reloadset will setforce_udev_reload. This isn't necessary for any of thereload_map()callers, and will just cause udev to do extra work. I did setforce_udev_reloadincli_reload(), so that it works like calling "multipath -r", which does force udev to rescan the device.Signed-off-by Benjamin Marzinski <[email protected]>