The commands to show a multipath device are supposed to return its current state without updating it. Even when reset is 0, update_multipath() still can update the device. To fix this, split __setup_multipath() into two functions: refresh_multipath(), that updates the table and status, and setup_multipath(), which works as before but now calls refresh_multipath(). Make the multipathd show commands call refresh_multipath() instead of update_multipath(). With the show commands calling refresh_multipath(), all callers of update_multipath() set the reset argument, so remove it and always call setup_multipath() from update_multipath(). Signed-off-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> --- multipathd/cli_handlers.c | 10 +++++----- multipathd/dmevents.c | 2 +- multipathd/main.c | 25 ++++++++++++++----------- multipathd/main.h | 7 +++---- multipathd/waiter.c | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 420d75df..b1dff202 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -76,7 +76,7 @@ static int show_map_topology (struct strbuf *reply, struct multipath *mpp, struct vectors *vecs, const fieldwidth_t *width) { - if (update_multipath(vecs, mpp->alias, 0)) + if (refresh_multipath(vecs, mpp)) return 1; if (snprint_multipath_topology(reply, mpp, 2, width) < 0) @@ -98,7 +98,7 @@ show_maps_topology (struct strbuf *reply, struct vectors * vecs) foreign_path_layout(p_width); vector_foreach_slot(vecs->mpvec, mpp, i) { - if (update_multipath(vecs, mpp->alias, 0)) { + if (refresh_multipath(vecs, mpp)) { i--; continue; } @@ -118,7 +118,7 @@ show_maps_json (struct strbuf *reply, struct vectors * vecs) struct multipath * mpp; vector_foreach_slot(vecs->mpvec, mpp, i) { - if (update_multipath(vecs, mpp->alias, 0)) { + if (refresh_multipath(vecs, mpp)) { return 1; } } @@ -133,7 +133,7 @@ static int show_map_json (struct strbuf *reply, struct multipath * mpp, struct vectors * vecs) { - if (update_multipath(vecs, mpp->alias, 0)) + if (refresh_multipath(vecs, mpp)) return 1; if (snprint_multipath_map_json(reply, mpp) < 0) @@ -365,7 +365,7 @@ show_maps (struct strbuf *reply, struct vectors *vecs, char *style, return 1; vector_foreach_slot(vecs->mpvec, mpp, i) { - if (update_multipath(vecs, mpp->alias, 0)) { + if (refresh_multipath(vecs, mpp)) { i--; continue; } diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index 3a859691..5657000c 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -361,7 +361,7 @@ static int dmevent_loop (void) if (curr_dev.action == EVENT_REMOVE) remove_map_by_alias(curr_dev.name, waiter->vecs); else - r = update_multipath(waiter->vecs, curr_dev.name, 1); + r = update_multipath(waiter->vecs, curr_dev.name); pthread_cleanup_pop(1); if (r) { diff --git a/multipathd/main.c b/multipathd/main.c index 230c9d10..c7476ff0 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -500,8 +500,7 @@ remove_maps_and_stop_waiters(struct vectors *vecs) remove_maps(vecs); } -int __setup_multipath(struct vectors *vecs, struct multipath *mpp, - int reset) +int refresh_multipath(struct vectors *vecs, struct multipath *mpp) { if (dm_get_info(mpp->alias, &mpp->dmi)) { /* Error accessing table */ @@ -513,20 +512,24 @@ int __setup_multipath(struct vectors *vecs, struct multipath *mpp, condlog(0, "%s: failed to setup multipath", mpp->alias); goto out; } - - if (reset) { - set_no_path_retry(mpp); - if (VECTOR_SIZE(mpp->paths) != 0) - dm_cancel_deferred_remove(mpp); - } - return 0; out: remove_map_and_stop_waiter(mpp, vecs); return 1; } -int update_multipath (struct vectors *vecs, char *mapname, int reset) +int setup_multipath(struct vectors *vecs, struct multipath *mpp) +{ + if (refresh_multipath(vecs, mpp) != 0) + return 1; + + set_no_path_retry(mpp); + if (VECTOR_SIZE(mpp->paths) != 0) + dm_cancel_deferred_remove(mpp); + return 0; +} + +int update_multipath (struct vectors *vecs, char *mapname) { struct multipath *mpp; struct pathgroup *pgp; @@ -540,7 +543,7 @@ int update_multipath (struct vectors *vecs, char *mapname, int reset) return 2; } - if (__setup_multipath(vecs, mpp, reset)) + if (setup_multipath(vecs, mpp)) return 1; /* mpp freed in setup_multipath */ /* diff --git a/multipathd/main.h b/multipathd/main.h index 8a178c0b..194f8776 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -43,10 +43,9 @@ int ev_remove_map (char *, char *, int, struct vectors *); int flush_map(struct multipath *, struct vectors *, int); void handle_signals(bool); -int __setup_multipath (struct vectors * vecs, struct multipath * mpp, - int reset); -#define setup_multipath(vecs, mpp) __setup_multipath(vecs, mpp, 1) -int update_multipath (struct vectors *vecs, char *mapname, int reset); +int refresh_multipath(struct vectors * vecs, struct multipath * mpp); +int setup_multipath(struct vectors * vecs, struct multipath * mpp); +int update_multipath(struct vectors *vecs, char *mapname); int reload_and_sync_map(struct multipath *mpp, struct vectors *vecs); void handle_path_wwid_change(struct path *pp, struct vectors *vecs); diff --git a/multipathd/waiter.c b/multipathd/waiter.c index 52793698..d1f344b6 100644 --- a/multipathd/waiter.c +++ b/multipathd/waiter.c @@ -156,7 +156,7 @@ static int waiteventloop (struct event_thread *waiter) pthread_cleanup_push(cleanup_lock, &waiter->vecs->lock); lock(&waiter->vecs->lock); pthread_testcancel(); - r = update_multipath(waiter->vecs, waiter->mapname, 1); + r = update_multipath(waiter->vecs, waiter->mapname); lock_cleanup_pop(waiter->vecs->lock); if (r) { -- 2.41.0