Yet Another path checker refactor
Benjamin Marzinski
maintainerv2 cover Yet Another path checker refactor
This patchset cleans up some of the ugly code from my last refactor, and speeds up multipathd path checking, by refactoring how paths are checked.
multipathd previously ran the checker on a path, waited briefly for it to complete, and if it did, updated the path and the priorities for the multipath device and possibly reloaded it.
This had multiple issues.
1. All the paths waited for their checkers to complete serially. This wasted time with no benefit. It also meant that it wasn't that uncommon for a checker to not finish in time, and get marked pending.
2. The prioritiers could get run on paths multiple times during a checker loop if multiple paths were restored at the same time, which is a common occurance.
3. In an effort to keep a multipath device's state consistent despite the delays introduced by waiting for the path checkers, paths were checked by multipath device. However checking the paths could involve reloading a multipath device table, or even removing a multipath device. This added some ugly backout and retry logic to the path check code.
With this patchset, the code now first starts the path checkers on all devices due for a path check. If there are path checkers that need waiting it then unocks the vecs lock and waits 5ms. Next, it goes back and updates the state of all the path devices. Once all of the paths have been updated, it goes through each multipath device, updating path priorities and reloading the device as necessary.
This allows multipathd to spend less time and do less redundant work while checking paths, while making paths more likely to not spend a checker cycle marked as pending. Since multipathd drops the vecs lock while waiting, uevents and user commands can be processed while its waiting.
Since there isn't a delay waiting for the previous checker before starting the next one, the path checker code has reverted to checking all paths in pathvec order, instead of by multipath device. Updating the paths in pathvec order simplifies the code, since the multipath devices can change during path updates. Starting the checkers in pathvec order keeps a path from having its checker started towards the end of the list of paths but checking for the result towards the start of the list of paths.
Changes since v1:
The original patches have been updated based on suggestions from Martin Wilck (patches listed using their original numbering):
- Moved checker path_state initialization code from 06 to 01
- Check for NULL before dereference in checker_get_state() in 04
- Moved adding start_checker to version file from 07 to 06
- Renamed check_path_state() to get_new_state() in 08. updated 09, 11, and 12 to deal with the name change.
- Added new patch before 13 ('fix "fail path" and "reinstate path" commands') to fix issues with manually failing and reinstating paths between when the checkers are run and the paths are updated
- Fixed check in update_paths in 13
- Split patch 13 into three patches, one to move priority updating out of the individual path updating code, and two others to clean up some of the logic about updating priorities and path groups.
After the now 18 patches from the original patchset, four new patches have been added to move the waiting for pending paths out from checker_get_state() and into the existing waiting code in checkerloop(). Doing the waiting outside of the checkers (in fact, outside of the vecs lock completely) means that we can't wait till a checker has completed. We must just pick a time and wait for all of it. On Martin's suggestion I picked 5ms. Since multipathd isn't sleeping with the vecs lock held, it's much less critical to do this quickly.
For checker run in pathinfo, I kept the previous timeout of 1ms, but I waffled on whether to wait at all here, and I'd be perfectly fine with removing the wait altogether, and just let the paths be pending when called from multipathd with async checkers.
Also, I've just added these patches to the end of the patchset to make it easier to see the changes from v1, but if people want less churn in the checker code commits, I'd be find with resending this patchset with these patches refactored into the earlier patches.
Benjamin Marzinski (22):
libmultipath: store checker_check() result in checker struct
libmultipath: add missing checker function prototypes
libmultipath: split out the code to wait for pending checkers
libmultipath: remove pending wait code from libcheck_check calls multipath-tools tests: fix up directio tests
libmultipath: split get_state into two functions
libmultipath: change path_offline to path_sysfs_state
multipathd: split check_path_state into two functions
multipathd: split do_checker_path
multipathd: split check_path into two functions
multipathd: split handle_uninitialized_path into two functions
multipathd: split check_paths into two functions
multipathd: fix "fail path" and "reinstate path" commands
multipathd: update priority once after updating all paths
multipathd: simplify checking for followover_should_failback
multipathd: only refresh prios on PATH_UP and PATH_GHOST
multipathd: remove pointless check
multipathd: fix deferred_failback_tick for reload removes
libmultipath: add libcheck_need_wait checker function
libmultipath: don't wait in libcheck_pending
multipathd: wait for checkers to complete multipath-tools tests: fix up directio tests
libmultipath/checkers.c | 47 ++-- libmultipath/checkers.h | 10 +- libmultipath/checkers/directio.c | 144 +++++++---- libmultipath/checkers/tur.c | 78 +++--- libmultipath/discovery.c | 97 +++++--- libmultipath/discovery.h | 6 +- libmultipath/libmultipath.version | 4 +- libmultipath/print.c | 2 +- libmultipath/propsel.c | 1 + libmultipath/structs.h | 21 +- multipathd/cli_handlers.c | 1 + multipathd/main.c | 399 ++++++++++++++++++------------ tests/directio.c | 182 ++++++++++---- 13 files changed, 643 insertions(+), 349 deletions(-)
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 1/22 libmultipath: store checker_check() result in checker struct
checker_check() is now a void function that stores the path state in the checker struct. It can be retrieved later using checker_get_state(). Right now, this is called immediately after checker_check(), but in the future, it can be deferred to another time.
--- libmultipath/checkers.c | 26 +++++++++++++------------- libmultipath/checkers.h | 4 +++- libmultipath/discovery.c | 3 ++- libmultipath/propsel.c | 1 + 4 files changed, 19 insertions(+), 15 deletions(-)
libmultipath/checkers.c +13 -13
@@ -299,28 +299,28 @@ void checker_put (struct checker * dst)free_checker_class (src); } -int checker_check (struct checker * c,int path_state) +int checker_get_state (struct checker *c) { -int r; +return c ? c->path_state :PATH_UNCHECKED ; +} +void checker_check (struct checker * c,int path_state) +{if (!c) -return PATH_WILD ; +return ; c->msgid =CHECKER_MSGID_NONE ;if (c->disable) { c->msgid =CHECKER_MSGID_DISABLED ; -return PATH_UNCHECKED ; - } -if (!strncmp (c->cls->name,NONE ,4 )) -return path_state; - -if (c->fd <0 ) { + c->path_state =PATH_UNCHECKED ; + }else if (!strncmp (c->cls->name,NONE ,4 )) { + c->path_state = path_state; + }else if (c->fd <0 ) { c->msgid =CHECKER_MSGID_NO_FD ; -return PATH_WILD ; + c->path_state =PATH_WILD ; + }else { + c->path_state = c->cls->check (c); } - r = c->cls->check (c); - -return r; }const char *checker_name (const struct checker *c)
libmultipath/checkers.h +3 -1
@@ -123,6 +123,7 @@ struct checker {int fd;unsigned int timeout;int disable; +int path_state;short msgid;/* checker-internal extra status */ void * context;/* store for persistent data */ void ** mpcontext;/* store for persistent data shared
@@ -169,7 +170,8 @@ struct checker_context { };int start_checker_thread (pthread_t *thread,const pthread_attr_t *attr,struct checker_context *ctx); -int checker_check (struct checker *,int ); +int checker_get_state (struct checker *c); +void checker_check (struct checker *,int );int checker_is_sync (const struct checker *);const char *checker_name (const struct checker *);void reset_checker_classes (void );
libmultipath/discovery.c +2 -1
@@ -2007,7 +2007,8 @@ get_state (struct path * pp, struct config *conf, int daemon, int oldstate)checker_set_async (c); elsechecker_set_sync (c ); - state =checker_check (c, oldstate); +checker_check (c, oldstate); + state =checker_get_state (c);condlog (3 ,"%s: %s state = %s" , pp->dev,checker_name (c),checker_state_name (state)); if (state != PATH_UP && state != PATH_GHOST &&
libmultipath/propsel.c +1 -0
@@ -700,6 +700,7 @@ out:condlog (3 ,"%s: path_checker = %s %s" , pp->dev,checker_name (c), origin); c->timeout = pp->checker_timeout; + c->path_state =PATH_UNCHECKED ;return 0 ; }
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 2/22 libmultipath: add missing checker function prototypes
In reply to Benjamin Marzinski--- libmultipath/checkers.h | 3 +++ 1 file changed, 3 insertions(+)
libmultipath/checkers.h +3 -0
@@ -188,6 +188,9 @@ int libcheck_check(struct checker *);int libcheck_init (struct checker *);void libcheck_free (struct checker *);void *libcheck_thread (struct checker_context *ctx); +void libcheck_reset (void ); +int libcheck_mp_init (struct checker *); +/* * msgid => message map.
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 3/22 libmultipath: split out the code to wait for pending checkers
In reply to Benjamin MarzinskiThis patch adds a new optional symbol for the dynamic path checker libraries, libcheck_pending. This is currently unused, but can be called on pending checkers to check if they've completed and return their value. The "tur" and "directio" checkers are the only ones which can return PATH_PENDING. They now implement libcheck_pending() as a wrapper around the code that libcheck_check uses to wait for pending paths, which has been broken out into its own function.
--- libmultipath/checkers.c | 4 +- libmultipath/checkers.h | 1 + libmultipath/checkers/directio.c | 86 ++++++++++++++++++++++---------- libmultipath/checkers/tur.c | 65 ++++++++++++++++-------- 4 files changed, 109 insertions(+), 47 deletions(-)
libmultipath/checkers.c +3 -1
@@ -26,6 +26,7 @@ struct checker_class {void (*free)(struct checker *);/* to free the context */ void (*reset)(void );/* to reset the global variables */ void *(*thread)(void *);/* async thread entry point */ +int (*pending)(struct checker *);/* to recheck pending paths */ const char **msgtable;short msgtable_size; };
@@ -180,7 +181,8 @@ static struct checker_class *add_checker_class(const char *name) c->mp_init = (int (*)(struct checker *))dlsym (c->handle,"libcheck_mp_init" ); c->reset = (void (*)(void ))dlsym (c->handle,"libcheck_reset" ); c->thread = (void *(*)(void *))dlsym (c->handle,"libcheck_thread" ); -/* These 3 functions can be NULL. call dlerror() to clear out any + c->pending = (int (*)(struct checker *))dlsym (c->handle,"libcheck_pending" ); +/* These 4 functions can be NULL. call dlerror() to clear out any * error string */ dlerror ();
libmultipath/checkers.h +1 -0
@@ -190,6 +190,7 @@ void libcheck_free(struct checker *);void *libcheck_thread (struct checker_context *ctx);void libcheck_reset (void );int libcheck_mp_init (struct checker *); +int libcheck_pending (struct checker *c);/*
libmultipath/checkers/directio.c +61 -25
118 lines not on this page · raw message
libmultipath/checkers/tur.c +44 -21
77 lines not on this page · raw message
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 4/22 libmultipath: remove pending wait code from libcheck_check calls
In reply to Benjamin MarzinskiWhen the tur and directio checkers start an asynchronous checker, they now immediately return with the path in PATH_PENDING, instead of waiting in checker_check(). Instead the wait now happens in checker_get_state().
Additionally, the directio checker now waits for 1 ms, like the tur checker does. Also like the tur checker it now only waits once. If it is still pending after the first call to checker_get_state(). It will not wait at all on future calls, and will just process the already completed IOs.
--- libmultipath/checkers.c | 7 +++- libmultipath/checkers/directio.c | 57 +++++++++++++++++--------------- libmultipath/checkers/tur.c | 13 +++----- 3 files changed, 41 insertions(+), 36 deletions(-)
libmultipath/checkers.c +6 -1
@@ -303,7 +303,12 @@ void checker_put (struct checker * dst)int checker_get_state (struct checker *c) { -return c ? c->path_state :PATH_UNCHECKED ; +if (!c || !c->cls) +return PATH_UNCHECKED ; +if (c->path_state !=PATH_PENDING || !c->cls->pending) +return c->path_state; + c->path_state = c->cls->pending (c); +return c->path_state; }void checker_check (struct checker * c,int path_state)
libmultipath/checkers/directio.c +30 -27
111 lines not on this page · raw message
libmultipath/checkers/tur.c +5 -8
@@ -58,6 +58,7 @@ struct tur_checker_context {int msgid;struct checker_context ctx;unsigned int nr_timeouts; +struct timespec endtime; };int libcheck_init (struct checker * c)
@@ -323,7 +324,7 @@ static int tur_check_async_timeout(struct checker *c)return (now.tv_sec > ct->time); } -int check_pending (struct checker *c,struct timespec endtime) +int check_pending (struct checker *c) {struct tur_checker_context *ct = c->context;int r, tur_status =PATH_PENDING ;
@@ -333,7 +334,7 @@ int check_pending(struct checker *c, struct timespec endtime)for (r =0 ; r ==0 && ct->state ==PATH_PENDING && ct->msgid ==MSG_TUR_RUNNING ; - r =pthread_cond_timedwait (&ct->active, &ct->lock, &endtime)); + r =pthread_cond_timedwait (&ct->active, &ct->lock, &ct->endtime));if (!r) { tur_status = ct->state;
@@ -355,21 +356,18 @@ int check_pending(struct checker *c, struct timespec endtime)int libcheck_pending (struct checker *c) { -struct timespec endtime;struct tur_checker_context *ct = c->context;/* The if path checker isn't running, just return the exiting value. */ if (!ct || !ct->thread)return c->path_state; -get_monotonic_time (&endtime); -return check_pending (c, endtime); +return check_pending (c); }int libcheck_check (struct checker * c) {struct tur_checker_context *ct = c->context; -struct timespec tsp;pthread_attr_t attr;int tur_status, r;
@@ -479,8 +477,7 @@ int libcheck_check(struct checker * c) " sync mode", major(ct->devt), minor(ct->devt));return tur_check (c->fd, c->timeout, &c->msgid); } -tur_timeout (&tsp); - tur_status =check_pending (c, tsp); +tur_timeout (&ct->endtime); }return tur_status;
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 5/22 multipath-tools tests: fix up directio tests
In reply to Benjamin MarzinskiMake the directio tests work with libcheck_pending() being separate from libcheck_check
--- tests/directio.c | 133 +++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 51 deletions(-)
tests/directio.c +82 -51
@@ -219,13 +219,22 @@ static void return_io_getevents_nr(struct timespec *ts, int nr, ev_off += i; } -void do_check_state (struct checker *c,int sync,int timeout,int chk_state) +void do_check_state (struct checker *c,int sync,int chk_state) {struct directio_context * ct = (struct directio_context *)c->context;if (!ct->running)will_return (__wrap_io_submit,1 ); -assert_int_equal (check_state (test_fd, ct, sync, timeout), chk_state); +assert_int_equal (check_state (test_fd, ct, sync, c->timeout), chk_state); +if (sync) { +assert_int_equal (ev_off,0 ); +memset (mock_events,0 ,sizeof (mock_events)); + } +} + +void do_libcheck_pending (struct checker *c,int chk_state) +{ +assert_int_equal (libcheck_pending (c), chk_state);assert_int_equal (ev_off,0 );memset (mock_events,0 ,sizeof (mock_events)); }
@@ -245,12 +254,13 @@ void do_libcheck_reset(int nr_aio_grps)assert_int_equal (ioctx_count,0 ); } -static void do_libcheck_init (struct checker *c,int blocksize, +static void do_libcheck_init (struct checker *c,int blocksize,int timeout,struct async_req **req) {struct directio_context * ct; c->fd = test_fd; + c->timeout = timeout;wrap_will_return (WRAP_IOCTL , blocksize);assert_int_equal (libcheck_init (c),0 ); ct = (struct directio_context *)c->context;
@@ -305,7 +315,7 @@ static void test_init_reset_init(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c,4096 ,NULL ); +do_libcheck_init (&c,4096 ,0 ,NULL ); aio_grp =get_aio_grp (&c);check_aio_grp (aio_grp,1 ,0 );list_for_each_entry (tmp_grp, &aio_grp_list, node)
@@ -314,7 +324,7 @@ static void test_init_reset_init(void **state)check_aio_grp (aio_grp,0 ,0 );do_libcheck_reset (1 );will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c,4096 ,NULL ); +do_libcheck_init (&c,4096 ,0 ,NULL ); aio_grp =get_aio_grp (&c);check_aio_grp (aio_grp,1 ,0 );list_for_each_entry (tmp_grp, &aio_grp_list, node)
@@ -340,11 +350,11 @@ static void test_init_free(void **state)struct directio_context * ct;if (i %3 ==0 ) -do_libcheck_init (&c[i],512 ,NULL ); +do_libcheck_init (&c[i],512 ,0 ,NULL );else if (i %3 ==1 ) -do_libcheck_init (&c[i],1024 ,NULL ); +do_libcheck_init (&c[i],1024 ,0 ,NULL );else -do_libcheck_init (&c[i],4096 ,NULL ); +do_libcheck_init (&c[i],4096 ,0 ,NULL ); ct = (struct directio_context *)c[i].context;assert_non_null (ct->aio_grp);if ((i &1023 ) ==0 )
@@ -385,7 +395,7 @@ static void test_multi_init_free(void **state)for (count =0 , i =0 ; i <4096 ; count++) {/* usually init, but occasionally free checkers */ if (count ==0 || (count %5 !=0 && count %7 !=0 )) { -do_libcheck_init (&c[i],4096 ,NULL ); +do_libcheck_init (&c[i],4096 ,0 ,NULL ); i++; }else { i--;
@@ -404,7 +414,7 @@ static void test_multi_init_free(void **state) i--;libcheck_free (&c[i]); }else { -do_libcheck_init (&c[i],4096 ,NULL ); +do_libcheck_init (&c[i],4096 ,0 ,NULL ); i++; } }
@@ -420,9 +430,9 @@ static void test_check_state_simple(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c,4096 , &req); +do_libcheck_init (&c,4096 ,30 , &req);return_io_getevents_nr (NULL ,1 , &req, &res); -do_check_state (&c,1 ,30 ,PATH_UP ); +do_check_state (&c,1 ,PATH_UP );libcheck_free (&c);do_libcheck_reset (1 ); }
@@ -435,10 +445,10 @@ static void test_check_state_timeout(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c,4096 ,NULL ); +do_libcheck_init (&c,4096 ,30 ,NULL ); aio_grp =get_aio_grp (&c);return_io_getevents_none (); -do_check_state (&c,1 ,30 ,PATH_DOWN ); +do_check_state (&c,1 ,PATH_DOWN );check_aio_grp (aio_grp,1 ,0 );libcheck_free (&c);do_libcheck_reset (1 );
@@ -452,16 +462,20 @@ static void test_check_state_async_timeout(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c,4096 ,NULL ); +do_libcheck_init (&c,4096 ,3 ,NULL ); aio_grp =get_aio_grp (&c); +do_check_state (&c,0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c,0 ,3 ,PATH_PENDING ); +do_libcheck_pending (&c,PATH_PENDING ); +do_check_state (&c,0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c,0 ,3 ,PATH_PENDING ); +do_libcheck_pending (&c,PATH_PENDING ); +do_check_state (&c,0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c,0 ,3 ,PATH_PENDING ); +do_libcheck_pending (&c,PATH_PENDING ); +do_check_state (&c,0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c,0 ,3 ,PATH_DOWN ); +do_libcheck_pending (&c,PATH_DOWN );check_aio_grp (aio_grp,1 ,0 );libcheck_free (&c);do_libcheck_reset (1 );
@@ -477,14 +491,16 @@ static void test_free_with_pending(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c[0 ],4096 , &req); -do_libcheck_init (&c[1 ],4096 ,NULL ); +do_libcheck_init (&c[0 ],4096 ,30 , &req); +do_libcheck_init (&c[1 ],4096 ,30 ,NULL ); aio_grp =get_aio_grp (c); +do_check_state (&c[0 ],0 ,PATH_PENDING ); +do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[0 ],0 ,30 ,PATH_PENDING ); +do_libcheck_pending (&c[0 ],PATH_PENDING );return_io_getevents_nr (NULL ,1 , &req, &res);return_io_getevents_none (); -do_check_state (&c[1 ],0 ,30 ,PATH_PENDING ); +do_libcheck_pending (&c[1 ],PATH_PENDING );assert_true (is_checker_running (&c[0 ]));assert_true (is_checker_running (&c[1 ]));check_aio_grp (aio_grp,2 ,0 );
@@ -505,9 +521,10 @@ static void test_orphaned_aio_group(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );for (i =0 ; i <AIO_GROUP_SIZE ; i++) { -do_libcheck_init (&c[i],4096 ,NULL ); +do_libcheck_init (&c[i],4096 ,30 ,NULL ); +do_check_state (&c[i],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[i],0 ,30 ,PATH_PENDING ); +do_libcheck_pending (&c[i],PATH_PENDING ); } aio_grp =get_aio_grp (c);check_aio_grp (aio_grp,AIO_GROUP_SIZE ,0 );
@@ -539,19 +556,19 @@ static void test_timeout_cancel_failed(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );for (i =0 ; i <2 ; i++) -do_libcheck_init (&c[i],4096 , &reqs[i]); +do_libcheck_init (&c[i],4096 ,30 , &reqs[i]); aio_grp =get_aio_grp (c);return_io_getevents_none (); -do_check_state (&c[0 ],1 ,30 ,PATH_DOWN ); +do_check_state (&c[0 ],1 ,PATH_DOWN );assert_true (is_checker_running (&c[0 ]));check_aio_grp (aio_grp,2 ,0 );return_io_getevents_none (); -do_check_state (&c[0 ],1 ,30 ,PATH_DOWN ); +do_check_state (&c[0 ],1 ,PATH_DOWN );assert_true (is_checker_running (&c[0 ]));return_io_getevents_nr (NULL ,1 , &reqs[0 ], &res[0 ]);return_io_getevents_nr (NULL ,1 , &reqs[1 ], &res[1 ]); -do_check_state (&c[1 ],1 ,30 ,PATH_UP ); -do_check_state (&c[0 ],1 ,30 ,PATH_UP ); +do_check_state (&c[1 ],1 ,PATH_UP ); +do_check_state (&c[0 ],1 ,PATH_UP );for (i =0 ; i <2 ; i++) {assert_false (is_checker_running (&c[i]));libcheck_free (&c[i]);
@@ -571,28 +588,37 @@ static void test_async_timeout_cancel_failed(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );for (i =0 ; i <2 ; i++) -do_libcheck_init (&c[i],4096 , &reqs[i]); +do_libcheck_init (&c[i],4096 ,2 , &reqs[i]); +do_check_state (&c[0 ],0 ,PATH_PENDING ); +do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[0 ],0 ,2 ,PATH_PENDING ); +do_libcheck_pending (&c[0 ],PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[1 ],0 ,2 ,PATH_PENDING ); +do_libcheck_pending (&c[1 ],PATH_PENDING ); +do_check_state (&c[0 ],0 ,PATH_PENDING ); +do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[0 ],0 ,2 ,PATH_PENDING ); +do_libcheck_pending (&c[0 ],PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[1 ],0 ,2 ,PATH_PENDING ); +do_libcheck_pending (&c[1 ],PATH_PENDING ); +do_check_state (&c[0 ],0 ,PATH_PENDING ); +do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[0 ],0 ,2 ,PATH_DOWN ); +do_libcheck_pending (&c[0 ],PATH_DOWN );if (!test_dev) {/* can't pick which even gets returned on real devices */ return_io_getevents_nr (NULL ,1 , &reqs[1 ], &res[1 ]); -do_check_state (&c[1 ],0 ,2 ,PATH_UP ); +do_libcheck_pending (&c[1 ],PATH_UP ); } +do_check_state (&c[0 ],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[0 ],0 ,2 ,PATH_DOWN ); +do_libcheck_pending (&c[0 ],PATH_DOWN );assert_true (is_checker_running (&c[0 ])); +do_check_state (&c[1 ],0 ,PATH_PENDING ); +do_check_state (&c[0 ],0 ,PATH_PENDING );return_io_getevents_nr (NULL ,2 , reqs, res); -do_check_state (&c[1 ],0 ,2 ,PATH_UP ); -do_check_state (&c[0 ],0 ,2 ,PATH_UP ); +do_libcheck_pending (&c[1 ],PATH_UP ); +do_libcheck_pending (&c[0 ],PATH_UP );for (i =0 ; i <2 ; i++) {assert_false (is_checker_running (&c[i]));libcheck_free (&c[i]);
@@ -612,15 +638,17 @@ static void test_orphan_checker_cleanup(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );for (i =0 ; i <2 ; i++) -do_libcheck_init (&c[i],4096 , &reqs[i]); +do_libcheck_init (&c[i],4096 ,30 , &reqs[i]); aio_grp =get_aio_grp (c); +do_check_state (&c[0 ],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[0 ],0 ,30 ,PATH_PENDING ); +do_libcheck_pending (&c[0 ],PATH_PENDING );check_aio_grp (aio_grp,2 ,0 );libcheck_free (&c[0 ]);check_aio_grp (aio_grp,2 ,1 ); +do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_nr (NULL ,2 , reqs, res); -do_check_state (&c[1 ],0 ,2 ,PATH_UP ); +do_libcheck_pending (&c[1 ],PATH_UP );check_aio_grp (aio_grp,1 ,0 );libcheck_free (&c[1 ]);check_aio_grp (aio_grp,0 ,0 );
@@ -636,10 +664,11 @@ static void test_orphan_reset_cleanup(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 ); -do_libcheck_init (&c,4096 ,NULL ); +do_libcheck_init (&c,4096 ,30 ,NULL ); orphan_aio_grp =get_aio_grp (&c); +do_check_state (&c,0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c,0 ,30 ,PATH_PENDING ); +do_libcheck_pending (&c,PATH_PENDING );check_aio_grp (orphan_aio_grp,1 ,0 );libcheck_free (&c);check_aio_grp (orphan_aio_grp,1 ,1 );
@@ -671,10 +700,10 @@ static void test_check_state_blksize(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );for (i =0 ; i <3 ; i++) -do_libcheck_init (&c[i], blksize[i], &reqs[i]); +do_libcheck_init (&c[i], blksize[i],30 , &reqs[i]);for (i =0 ; i <3 ; i++) {return_io_getevents_nr (NULL ,1 , &reqs[i], &res[i]); -do_check_state (&c[i],1 ,30 , chk_state[i]); +do_check_state (&c[i],1 , chk_state[i]); }for (i =0 ; i <3 ; i++) {assert_false (is_checker_running (&c[i]));
@@ -695,19 +724,21 @@ static void test_check_state_async(void **state)assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );for (i =0 ; i <257 ; i++) -do_libcheck_init (&c[i],4096 , &reqs[i]); +do_libcheck_init (&c[i],4096 ,30 , &reqs[i]);for (i =0 ; i <256 ; i++) { +do_check_state (&c[i],0 ,PATH_PENDING );return_io_getevents_none (); -do_check_state (&c[i],0 ,30 ,PATH_PENDING ); +do_libcheck_pending (&c[i],PATH_PENDING );assert_true (is_checker_running (&c[i])); } +do_check_state (&c[256 ],0 ,PATH_PENDING );return_io_getevents_nr (&full_timeout,256 , reqs, res);return_io_getevents_nr (NULL ,1 , &reqs[256 ], &res[256 ]); -do_check_state (&c[256 ],0 ,30 ,PATH_UP ); +do_libcheck_pending (&c[256 ],PATH_UP );assert_false (is_checker_running (&c[256 ]));libcheck_free (&c[256 ]);for (i =0 ; i <256 ; i++) { -do_check_state (&c[i],0 ,30 ,PATH_UP ); +do_check_state (&c[i],0 ,PATH_UP );assert_false (is_checker_running (&c[i]));libcheck_free (&c[i]); }
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 6/22 libmultipath: split get_state into two functions
In reply to Benjamin Marzinskiget_state() is now split into start_checker(), which runs the checker but doesn't wait for async checkers, and get_state(), which returns the state from the checker, after waiting for async checkers if necessary.
--- libmultipath/discovery.c | 22 ++++++++++++++++------ libmultipath/discovery.h | 4 +++- libmultipath/libmultipath.version | 1 + multipathd/main.c | 4 +++- 4 files changed, 23 insertions(+), 8 deletions(-)
libmultipath/discovery.c +16 -6
@@ -1974,30 +1974,29 @@ cciss_ioctl_pathinfo(struct path *pp) }int -get_state (struct path * pp,struct config *conf,int daemon,int oldstate) +start_checker (struct path * pp,struct config *conf,int daemon,int oldstate) {struct checker * c = &pp->checker; -int state;if (!checker_selected (c)) {if (daemon) {if (pathinfo (pp, conf,DI_SYSFS ) !=PATHINFO_OK ) {condlog (3 ,"%s: couldn't get sysfs pathinfo" , pp->dev); -return PATH_UNCHECKED ; +return -1 ; } }select_detect_checker (conf, pp);select_checker (conf, pp);if (!checker_selected (c)) {condlog (3 ,"%s: No checker selected" , pp->dev); -return PATH_UNCHECKED ; +return -1 ; }checker_set_fd (c, pp->fd);if (checker_init (c, pp->mpp?&pp->mpp->mpcontext:NULL )) {checker_clear (c);condlog (3 ,"%s: checker init failed" , pp->dev); -return PATH_UNCHECKED ; +return -1 ; } }if (pp->mpp && !c->mpcontext)
@@ -2008,6 +2007,15 @@ get_state (struct path * pp, struct config *conf, int daemon, int oldstate)else checker_set_sync (c);checker_check (c, oldstate); +return 0 ; +} + +int +get_state (struct path * pp) +{ +struct checker * c = &pp->checker; +int state; + state =checker_get_state (c);condlog (3 ,"%s: %s state = %s" , pp->dev,checker_name (c),checker_state_name (state));
@@ -2455,7 +2463,9 @@ int pathinfo(struct path *pp, struct config *conf, int mask)if (mask &DI_CHECKER ) {if (path_state ==PATH_UP ) { -int newstate =get_state (pp, conf,0 , path_state); +int newstate =PATH_UNCHECKED ; +if (start_checker (pp, conf,0 , path_state) ==0 ) + newstate =get_state (pp);if (newstate !=PATH_PENDING || pp->state ==PATH_UNCHECKED || pp->state ==PATH_WILD )
libmultipath/discovery.h +3 -1
@@ -34,7 +34,9 @@ int path_discovery (vector pathvec, int flag);int path_get_tpgs (struct path *pp);/* This function never returns TPGS_UNDEF */ int do_tur (char *);int path_offline (struct path *); -int get_state (struct path * pp,struct config * conf,int daemon,int state); +int start_checker (struct path * pp,struct config * conf,int daemon, +int state); +int get_state (struct path * pp);int get_vpd_sgio (int fd,int pg,int vend_id,char * str,int maxlen);int pathinfo (struct path * pp,struct config * conf,int mask); int alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
libmultipath/libmultipath.version +1 -0
@@ -160,6 +160,7 @@ global: remove_wwid; replace_wwids; reset_checker_classes; + start_checker; select_all_tg_pt; select_action; select_find_multipaths_timeout;
multipathd/main.c +3 -1
@@ -2324,7 +2324,9 @@ check_path_state(struct path *pp)if (newstate ==PATH_UP ) { conf =get_multipath_config ();pthread_cleanup_push (put_multipath_config, conf); - newstate =get_state (pp, conf,1 , newstate); + newstate =PATH_UNCHECKED ; +if (start_checker (pp, conf,1 , newstate) ==0 ) + newstate =get_state (pp);pthread_cleanup_pop (1 ); }else {checker_clear_message (&pp->checker);
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 7/22 libmultipath: change path_offline to path_sysfs_state
In reply to Benjamin MarzinskiInstead of pp->offline being a binary value, change it to show the actual result of looking at the sysfs state, and rename it to pp->sysfs_state. Also change the function name from path_offline() to path_sysfs_state(). Adapt the tests for pp->offline. This should not change how multipath currently works. pp->sysfs_state will be used in future patches.
--- libmultipath/discovery.c | 65 ++++++++++++++++--------------- libmultipath/discovery.h | 2 +- libmultipath/libmultipath.version | 2 +- libmultipath/print.c | 2 +- libmultipath/structs.h | 2 +- multipathd/main.c | 4 +- 6 files changed, 40 insertions(+), 37 deletions(-)
libmultipath/discovery.c +34 -31
@@ -1076,18 +1076,16 @@ detect_alua(struct path * pp)return ; } -if (pp->fd ==-1 || pp->offline) +if (pp->fd ==-1 || pp->sysfs_state ==PATH_DOWN )return ; ret =get_target_port_group (pp);if (ret <0 ||get_asymmetric_access_state (pp, ret) <0 ) { -int state; -if (ret == -RTPG_INQUIRY_FAILED )return ; - state =path_offline (pp); -if (state !=PATH_UP ) +path_sysfs_state (pp); +if (pp->sysfs_state !=PATH_UP )return ; pp->tpgs =TPGS_NONE ;
@@ -1800,7 +1798,7 @@ common_sysfs_pathinfo (struct path * pp) }int -path_offline (struct path * pp) +path_sysfs_state (struct path * pp) {struct udev_device * parent;char buff[SCSI_STATE_SIZE ];
@@ -1814,7 +1812,8 @@ path_offline (struct path * pp) subsys_type ="nvme" ; }else { -return PATH_UP ; + pp->sysfs_state =PATH_UP ; + goto out; } parent = pp->udev;
@@ -1827,16 +1826,18 @@ path_offline (struct path * pp)if (!parent) {condlog (1 ,"%s: failed to get sysfs information" , pp->dev); -return PATH_REMOVED ; + pp->sysfs_state =PATH_REMOVED ; + goto out; }memset (buff,0x0 ,SCSI_STATE_SIZE ); err =sysfs_attr_get_value (parent,"state" , buff,sizeof (buff));if (!sysfs_attr_value_ok (err,sizeof (buff))) {if (err == -ENXIO ) -return PATH_REMOVED ; + pp->sysfs_state =PATH_REMOVED ;else -return PATH_DOWN ; + pp->sysfs_state =PATH_DOWN ; + goto out; }
@@ -1844,31 +1845,34 @@ path_offline (struct path * pp)if (pp->bus ==SYSFS_BUS_SCSI ) {if (!strncmp (buff,"offline" ,7 )) { - pp->offline =1 ; -return PATH_DOWN ; + pp->sysfs_state =PATH_DOWN ; + goto out; + }else if (!strncmp (buff,"blocked" ,7 ) || + !strncmp (buff,"quiesce" ,7 )) { + pp->sysfs_state =PATH_PENDING ; + goto out; + }else if (!strncmp (buff,"running" ,7 )) { + pp->sysfs_state =PATH_UP ; + goto out; } - pp->offline =0 ; -if (!strncmp (buff,"blocked" ,7 ) || - !strncmp (buff,"quiesce" ,7 )) -return PATH_PENDING ; -else if (!strncmp (buff,"running" ,7 )) -return PATH_UP ; }else if (pp->bus ==SYSFS_BUS_NVME ) {if (!strncmp (buff,"dead" ,4 )) { - pp->offline =1 ; -return PATH_DOWN ; + pp->sysfs_state =PATH_DOWN ; + goto out; + }else if (!strncmp (buff,"new" ,3 ) || + !strncmp (buff,"deleting" ,8 )) { + pp->sysfs_state =PATH_PENDING ; + goto out; + }else if (!strncmp (buff,"live" ,4 )) { + pp->sysfs_state =PATH_UP ; + goto out; } - pp->offline =0 ; -if (!strncmp (buff,"new" ,3 ) || - !strncmp (buff,"deleting" ,8 )) -return PATH_PENDING ; -else if (!strncmp (buff,"live" ,4 )) -return PATH_UP ; } - -return PATH_DOWN ; + pp->sysfs_state =PATH_DOWN ; +out: +return pp->sysfs_state; } static int
@@ -2052,8 +2056,7 @@ get_prio (struct path * pp) old_prio = pp->priority; pp->priority =prio_getprio (p, pp);if (pp->priority <0 ) { -/* this changes pp->offline, but why not */ -int state =path_offline (pp); +int state =path_sysfs_state (pp);if (state ==PATH_DOWN || state ==PATH_PENDING ) { pp->priority = old_prio;
@@ -2424,7 +2427,7 @@ int pathinfo(struct path *pp, struct config *conf, int mask)return PATHINFO_SKIPPED ; } - path_state =path_offline (pp); + path_state =path_sysfs_state (pp);if (path_state ==PATH_REMOVED ) goto blank;else if (mask &DI_NOIO ) {
libmultipath/discovery.h +1 -1
@@ -33,7 +33,7 @@ struct config;int path_discovery (vector pathvec,int flag);int path_get_tpgs (struct path *pp);/* This function never returns TPGS_UNDEF */ int do_tur (char *); -int path_offline (struct path *); +int path_sysfs_state (struct path *);int start_checker (struct path * pp,struct config * conf,int daemon,int state);int get_state (struct path * pp);
libmultipath/libmultipath.version +1 -1
@@ -146,7 +146,7 @@ global: path_discovery; path_get_tpgs; pathinfo; - path_offline; + path_sysfs_state; print_all_paths; print_foreign_topology; print_multipath_topology__;
libmultipath/print.c +1 -1
@@ -514,7 +514,7 @@ snprint_offline (struct strbuf *buff, const struct path * pp) {if (!pp || !pp->mpp)return append_strbuf_str (buff,"unknown" ); -else if (pp->offline) +else if (pp->sysfs_state ==PATH_DOWN )return append_strbuf_str (buff,"offline" );else return append_strbuf_str (buff,"running" );
libmultipath/structs.h +1 -1
@@ -362,7 +362,7 @@ struct path {unsigned int tick;unsigned int pending_ticks;int bus; -int offline; +int sysfs_state;int state;int dmstate;int chkrstate;
multipathd/main.c +2 -2
@@ -96,7 +96,7 @@ void * mpath_pr_event_handler_fn (void * ); do { \ if (pp->mpp && checker_selected(&pp->checker) && \ lvl <= libmp_verbosity) { \ - if (pp->offline) \ + if (pp->sysfs_state == PATH_DOWN) \ condlog(lvl, "%s: %s - path offline", \ pp->mpp->alias, pp->dev); \ else { \
@@ -2320,7 +2320,7 @@ check_path_state(struct path *pp)int newstate;struct config *conf; - newstate =path_offline (pp); + newstate =path_sysfs_state (pp);if (newstate ==PATH_UP ) { conf =get_multipath_config ();pthread_cleanup_push (put_multipath_config, conf);
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 8/22 multipathd: split check_path_state into two functions
In reply to Benjamin Marzinskicheck_path_state() is now split into start_path_check(), which calls path_sysfs_state() and if the path is up also calls start_checker(), and get_new_state() which gets the new state from either pp->sysfs_state or get_state().
--- multipathd/main.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
multipathd/main.c +19 -11
@@ -2314,25 +2314,31 @@ should_skip_path(struct path *pp){return 0 ; } -static int -check_path_state (struct path *pp) +static void +start_path_check (struct path *pp) { -int newstate;struct config *conf; - newstate =path_sysfs_state (pp); -if (newstate ==PATH_UP ) { +if (path_sysfs_state (pp) ==PATH_UP ) { conf =get_multipath_config ();pthread_cleanup_push (put_multipath_config, conf); - newstate =PATH_UNCHECKED ; -if (start_checker (pp, conf,1 , newstate) ==0 ) - newstate =get_state (pp); +start_checker (pp, conf,1 ,PATH_UNCHECKED );pthread_cleanup_pop (1 ); }else {checker_clear_message (&pp->checker);condlog (3 ,"%s: state %s, checker not called" , - pp->dev,checker_state_name (newstate)); + pp->dev,checker_state_name (pp->sysfs_state)); } +} + +static int +get_new_state (struct path *pp) +{ +int newstate = pp->sysfs_state; +struct config *conf; + +if (newstate ==PATH_UP ) + newstate =get_state (pp);/* * Wait for uevent for removed paths; * some LLDDs like zfcp keep paths unavailable
@@ -2413,7 +2419,8 @@ do_check_path (struct vectors * vecs, struct path * pp) pp->checkint = checkint; }; - newstate =check_path_state (pp); +start_path_check (pp); + newstate =get_new_state (pp);if (newstate ==PATH_WILD || newstate ==PATH_UNCHECKED )return CHECK_PATH_SKIPPED ;/*
@@ -2752,7 +2759,8 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, } } - newstate =check_path_state (pp); +start_path_check (pp); + newstate =get_new_state (pp); if (!strlen(pp->wwid) && (pp->initialized == INIT_FAILED || pp->initialized == INIT_NEW) &&
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 9/22 multipathd: split do_checker_path
In reply to Benjamin MarzinskiMove the code that starts the path checker from do_check_path() into check_path(), rename the remainder of do_check_path() to update_path_state() and call that from check_path().
--- multipathd/main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
multipathd/main.c +11 -10
@@ -2396,7 +2396,7 @@ enum check_path_return { };static int -do_check_path (struct vectors * vecs,struct path * pp) +update_path_state (struct vectors * vecs,struct path * pp) {int newstate;int new_path_up =0 ;
@@ -2414,12 +2414,6 @@ do_check_path (struct vectors * vecs, struct path * pp) marginal_pathgroups = conf->marginal_pathgroups;put_multipath_config (conf); -if (pp->checkint ==CHECKINT_UNDEF ) { -condlog (0 ,"%s: BUG: checkint is not set" , pp->dev); - pp->checkint = checkint; - }; - -start_path_check (pp); newstate =get_new_state (pp);if (newstate ==PATH_WILD || newstate ==PATH_UNCHECKED )return CHECK_PATH_SKIPPED ;
@@ -2639,7 +2633,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, time_t start_secs) {int r; -unsigned int adjust_int, max_checkint; +unsigned int adjust_int, checkint, max_checkint;struct config *conf;time_t next_idx, goal_idx;
@@ -2652,14 +2646,21 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks,return CHECK_PATH_SKIPPED ; conf =get_multipath_config (); + checkint = conf->checkint; max_checkint = conf->max_checkint; adjust_int = conf->adjust_int;put_multipath_config (conf); - r =do_check_path (vecs, pp); +if (pp->checkint ==CHECKINT_UNDEF ) { +condlog (0 ,"%s: BUG: checkint is not set" , pp->dev); + pp->checkint = checkint; + } + +start_path_check (pp); + r =update_path_state (vecs, pp);/* -* do_check_path() removed or orphaned the path. +* update_path() removed or orphaned the path. */ if (r ==CHECK_PATH_REMOVED || !pp->mpp)return r;
Signature · 1 line
2.45.0
Re: [PATCH v2 09/22] multipathd: split do_checker_path
Nit: the subject should refer to "do_check_path".
Also, the word "split" is somewhat confusing as you've been using it for actually splitting one function into two elsewhere in this set.
Perhaps just call the patch "rename do_check_path to update_path_state".
Quoted 66 lines · Benjamin Marzinski
Move the code that starts the path checker from
do_check_path()intocheck_path(), rename the remainder ofdo_check_path()toupdate_path_state()and call that fromcheck_path().Signed-off-by Benjamin Marzinski <[email protected]>---
multipathd/main.c | 21 +++++++++++----------1 file changed, 11 insertions(+), 10 deletions(-)multipathd/main.c +0
-0@@ -2396,7 +2396,7 @@ enum check_path_return { };
static intmultipathd/main.c +1
-1-do_check_path (struct vectors * vecs, struct path * pp) +update_path_state (struct vectors * vecs, struct path * pp){
int newstate;
intnew_path_up= 0;multipathd/main.c +0
-0@@ -2414,12 +2414,6 @@ do_check_path (struct vectors * vecs, struct path * pp) marginal_pathgroups = conf->marginal_pathgroups; put_multipath_config(conf);multipathd/main.c +0
-6-if (pp->checkint ==CHECKINT_UNDEF ) { -condlog (0 ,"%s: BUG: checkint is not set" , pp->dev); - pp->checkint = checkint; - }; - -start_path_check (pp);newstate =
get_new_state(pp);
if (newstate ==PATH_WILD|| newstate ==PATH_UNCHECKED) returnCHECK_PATH_SKIPPED;multipathd/main.c +1
-1@@ -2639,7 +2633,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, time_t start_secs) { int r; -unsigned int adjust_int, max_checkint; +unsigned int adjust_int, checkint, max_checkint; struct config *conf; time_t next_idx, goal_idx;multipathd/main.c +0
-0@@ -2652,14 +2646,21 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, return CHECK_PATH_SKIPPED;
conf =get_multipath_config();multipathd/main.c +1
-0+ checkint = conf->checkint;
max_checkint=conf->max_checkint;
adjust_int=conf->adjust_int;
put_multipath_config(conf);multipathd/main.c +7
-1- r =do_check_path (vecs, pp); +if (pp->checkint ==CHECKINT_UNDEF ) { +condlog (0 ,"%s: BUG: checkint is not set" , pp->dev); + pp->checkint = checkint; + } + +start_path_check (pp); + r =update_path_state (vecs, pp);
/*
multipathd/main.c check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, · line 2663
Quoted 2 lines
multipathd/main.c +1
-1-* do_check_path() removed or orphaned the path. +* update_path() removed or orphaned the path.
Nit: update_path() is introduced in the follow-up patch. Should this be update_path_state()?
Martin
Quoted 3 lines
*/
if (r ==CHECK_PATH_REMOVED|| !pp->mpp)
return r;
Benjamin Marzinski
maintainerRe: [PATCH v2 09/22] multipathd: split do_checker_path
Quoted 6 lines · Martin Wilck
Nit: the subject should refer to "
do_check_path".
Also, the word "split" is somewhat confusing as you've been using it for actually splitting one function into two elsewhere in this set.Perhaps just call the patch "rename
do_check_pathtoupdate_path_state".
Sure.
Quoted 65 lines · Benjamin Marzinski
Quoted 63 lines
Move the code that starts the path checker from
do_check_path()intocheck_path(), rename the remainder ofdo_check_path()toupdate_path_state()and call that fromcheck_path().Signed-off-by Benjamin Marzinski <[email protected]>---
multipathd/main.c | 21 +++++++++++----------1 file changed, 11 insertions(+), 10 deletions(-)multipathd/main.c +0
-0@@ -2396,7 +2396,7 @@ enum check_path_return { };
static intmultipathd/main.c +1
-1-do_check_path (struct vectors * vecs, struct path * pp) +update_path_state (struct vectors * vecs, struct path * pp){
int newstate;
intnew_path_up= 0;multipathd/main.c +0
-0@@ -2414,12 +2414,6 @@ do_check_path (struct vectors * vecs, struct path * pp) marginal_pathgroups = conf->marginal_pathgroups; put_multipath_config(conf);multipathd/main.c +0
-6-if (pp->checkint ==CHECKINT_UNDEF ) { -condlog (0 ,"%s: BUG: checkint is not set" , pp->dev); - pp->checkint = checkint; - }; - -start_path_check (pp);newstate =
get_new_state(pp);
if (newstate ==PATH_WILD|| newstate ==PATH_UNCHECKED) returnCHECK_PATH_SKIPPED;multipathd/main.c +1
-1@@ -2639,7 +2633,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, time_t start_secs) { int r; -unsigned int adjust_int, max_checkint; +unsigned int adjust_int, checkint, max_checkint; struct config *conf; time_t next_idx, goal_idx;multipathd/main.c +0
-0@@ -2652,14 +2646,21 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, return CHECK_PATH_SKIPPED;
conf =get_multipath_config();multipathd/main.c +1
-0+ checkint = conf->checkint;
max_checkint=conf->max_checkint;
adjust_int=conf->adjust_int;
put_multipath_config(conf);multipathd/main.c +6
-1- r =do_check_path (vecs, pp); +if (pp->checkint ==CHECKINT_UNDEF ) { +condlog (0 ,"%s: BUG: checkint is not set" , pp->dev); + pp->checkint = checkint; + } + +start_path_check (pp);
Quoted 8 lines
multipathd/main.c check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, · line 2663
Quoted 5 lines
multipathd/main.c +1
-0+ r =update_path_state (vecs, pp);
/*multipathd/main.c +1
-1-* do_check_path() removed or orphaned the path. +* update_path() removed or orphaned the path. Nit:
update_path()is introduced in the follow-up patch. Should this beupdate_path_state()?
Oops. Yep.
-Ben
Quoted 7 lines
Martin
Quoted 3 lines
*/
if (r ==CHECK_PATH_REMOVED|| !pp->mpp)
return r;
Benjamin Marzinski
maintainerPATCH v2 10/22 multipathd: split check_path into two functions
In reply to Benjamin MarzinskiSplit out the code that updates a path's state and sets up the next check time into its own function, update_path().
--- multipathd/main.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
multipathd/main.c +22 -9
@@ -2390,6 +2390,7 @@ sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) }enum check_path_return { +CHECK_PATH_STARTED ,CHECK_PATH_CHECKED ,CHECK_PATH_SKIPPED ,CHECK_PATH_REMOVED ,
@@ -2629,13 +2630,10 @@ update_path_state (struct vectors * vecs, struct path * pp) }static int -check_path (struct vectors * vecs,struct path * pp,unsigned int ticks, -time_t start_secs) +check_path (struct path * pp,unsigned int ticks) { -int r; -unsigned int adjust_int, checkint, max_checkint; +unsigned int checkint;struct config *conf; -time_t next_idx, goal_idx;if (pp->initialized ==INIT_REMOVED )return CHECK_PATH_SKIPPED ;
@@ -2647,8 +2645,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, conf =get_multipath_config (); checkint = conf->checkint; - max_checkint = conf->max_checkint; - adjust_int = conf->adjust_int;put_multipath_config (conf);if (pp->checkint ==CHECKINT_UNDEF ) {
@@ -2657,6 +2653,17 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, }start_path_check (pp); +return CHECK_PATH_STARTED ; +} + +static int +update_path (struct vectors * vecs,struct path * pp,time_t start_secs) +{ +int r; +unsigned int adjust_int, max_checkint; +struct config *conf; +time_t next_idx, goal_idx; + r =update_path_state (vecs, pp);/*
@@ -2685,6 +2692,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks,if (pp->tick ==1 )return r; + conf =get_multipath_config (); + max_checkint = conf->max_checkint; + adjust_int = conf->adjust_int; +put_multipath_config (conf);/* * every mpp has a goal_idx in the range of * 0 <= goal_idx < conf->max_checkint
@@ -2818,8 +2829,10 @@ check_paths(struct vectors *vecs, unsigned int ticks, int *num_paths_p)if (!pp->mpp || pp->is_checked)continue ; pp->is_checked = true; - rc =check_path (vecs, pp, ticks, - start_time.tv_sec); + rc =check_path (pp, ticks); +if (rc ==CHECK_PATH_STARTED ) + rc =update_path (vecs, pp, + start_time.tv_sec);if (rc ==CHECK_PATH_CHECKED ) (*num_paths_p)++;if (++paths_checked %128 ==0 )
Signature · 1 line
2.45.0
Re: [PATCH v2 10/22] multipathd: split check_path into two functions
Quoted 46 lines · Benjamin Marzinski
Split out the code that updates a path's state and sets up the next check time into its own function,
update_path().Signed-off-by Benjamin Marzinski <[email protected]>---
multipathd/main.c | 31 ++++++++++++++++++++++---------1 file changed, 22 insertions(+), 9 deletions(-)multipathd/main.c +0
-0@@ -2390,6 +2390,7 @@ sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) }
enumcheck_path_return{multipathd/main.c +1
-0+ CHECK_PATH_STARTED,
CHECK_PATH_CHECKED,
CHECK_PATH_SKIPPED,
CHECK_PATH_REMOVED,multipathd/main.c +0
-0@@ -2629,13 +2630,10 @@ update_path_state (struct vectors * vecs, struct path * pp) }
static int
-check_path (struct vectors * vecs, struct path * pp, unsigned int ticks,multipathd/main.c +1
-1- time_t start_secs) +check_path (struct path * pp, unsigned int ticks){
multipathd/main.c +1
-2-int r; -unsigned int adjust_int, checkint, max_checkint; +unsigned int checkint;struct config *conf;
multipathd/main.c +0
-1-time_t next_idx, goal_idx;
if (pp->initialized==INIT_REMOVED)
returnCHECK_PATH_SKIPPED;multipathd/main.c +0
-0@@ -2647,8 +2645,6 @@ check_path (struct vectors * vecs, struct path* pp, unsigned int ticks,
conf =get_multipath_config();
checkint =conf->checkint;multipathd/main.c +0
-2- max_checkint = conf->max_checkint; - adjust_int = conf->adjust_int;
Quoted 2 lines
put_multipath_config(conf);
After this change, we set only checking in this RCU critical section, and checkint is only used in the if clause below. Perhaps move the critical section into the if block?
Martin
Benjamin Marzinski
maintainerRe: [PATCH v2 10/22] multipathd: split check_path into two functions
Quoted 45 lines · Martin Wilck
Quoted 44 lines · Benjamin Marzinski
Split out the code that updates a path's state and sets up the next check time into its own function,
update_path().Signed-off-by Benjamin Marzinski <[email protected]>---
multipathd/main.c | 31 ++++++++++++++++++++++---------1 file changed, 22 insertions(+), 9 deletions(-)multipathd/main.c +0
-0@@ -2390,6 +2390,7 @@ sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) }
enumcheck_path_return{multipathd/main.c +1
-0+ CHECK_PATH_STARTED,
CHECK_PATH_CHECKED,
CHECK_PATH_SKIPPED,
CHECK_PATH_REMOVED,multipathd/main.c +0
-0@@ -2629,13 +2630,10 @@ update_path_state (struct vectors * vecs, struct path * pp) }
static int
-check_path (struct vectors * vecs, struct path * pp, unsigned int ticks,multipathd/main.c +1
-1- time_t start_secs) +check_path (struct path * pp, unsigned int ticks){
multipathd/main.c +1
-2-int r; -unsigned int adjust_int, checkint, max_checkint; +unsigned int checkint;struct config *conf;
multipathd/main.c +0
-1-time_t next_idx, goal_idx;
if (pp->initialized==INIT_REMOVED)
returnCHECK_PATH_SKIPPED;multipathd/main.c +0
-0@@ -2647,8 +2645,6 @@ check_path (struct vectors * vecs, struct path* pp, unsigned int ticks,
conf =get_multipath_config();
checkint =conf->checkint;
Quoted 8 lines
Quoted 4 lines
multipathd/main.c +0
-2- max_checkint = conf->max_checkint; - adjust_int = conf->adjust_int;
put_multipath_config(conf);After this change, we set only checking in this RCU critical section, and checkint is only used in the if clause below. Perhaps move the critical section into the if block?
Makes sense. Sure.
-Ben
Quoted 2 lines
Martin
Benjamin Marzinski
maintainerPATCH v2 11/22 multipathd: split handle_uninitialized_path into two functions
In reply to Benjamin MarzinskiSplit handle_uninitialized_path() into check_uninitialized_path, which handles udev retriggers for INIT_MISSING_UDEV paths and starts the path checker for INIT_FAILED and INIT_NEW paths, and update_uninitialized_path() which gets the path checker result and reruns pathinfo if the path is up.
--- multipathd/main.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
multipathd/main.c +13 -5
@@ -2718,13 +2718,10 @@ update_path(struct vectors * vecs, struct path * pp, time_t start_secs) }static int -handle_uninitialized_path (struct vectors * vecs,struct path * pp, -unsigned int ticks) +check_uninitialized_path (struct path * pp,unsigned int ticks) { -int newstate;int retrigger_tries;struct config *conf; -int ret;if (pp->initialized !=INIT_NEW && pp->initialized !=INIT_FAILED && pp->initialized !=INIT_MISSING_UDEV )
@@ -2772,6 +2769,15 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, }start_path_check (pp); +return CHECK_PATH_STARTED ; +} + +static int +update_uninitialized_path (struct vectors * vecs,struct path * pp) +{ +int newstate, ret; +struct config *conf; + newstate =get_new_state (pp); if (!strlen(pp->wwid) &&
@@ -2862,7 +2868,9 @@ next_mpp:continue ; pp->is_checked = true; - rc =handle_uninitialized_path (vecs, pp, ticks); + rc =check_uninitialized_path (pp, ticks); +if (rc ==CHECK_PATH_STARTED ) + rc =update_uninitialized_path (vecs, pp);if (rc ==CHECK_PATH_REMOVED ) i--;else if (rc ==CHECK_PATH_CHECKED )
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 12/22 multipathd: split check_paths into two functions
In reply to Benjamin MarzinskiInstead of checking and updating each path, the checkerloop now starts the checkers on all the paths in check_paths(), and then goes back and updates all the paths in update_paths(). Since the async checkers use an absolute time to wait for before returning PATH_PENDING, only one checker actually needs to be waited for in update_paths(). The rest will already have reached their timeout when update_path() is called for them.
The check_paths() and update_paths() loop over the pathvec instead of looping through the multipath device paths to avoid having to restart checking of the device paths when the multipath device needs to be resynced while updating the paths.
--- libmultipath/structs.h | 10 +++- multipathd/main.c | 105 +++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 58 deletions(-)
libmultipath/structs.h +9 -1
@@ -314,6 +314,14 @@ enum recheck_wwid_states { RECHECK_WWID_ON = YNU_YES, }; +enum check_path_states { +CHECK_PATH_UNCHECKED , +CHECK_PATH_STARTED , +CHECK_PATH_CHECKED , +CHECK_PATH_SKIPPED , +CHECK_PATH_REMOVED , +}; +struct vpd_vendor_page {int pg;const char *name;
@@ -395,7 +403,7 @@ struct path {int fast_io_fail;unsigned int dev_loss;int eh_deadline; -bool is_checked; +enum check_path_states is_checked;bool can_use_env_uid;unsigned int checker_timeout;/* configlet pointers */
multipathd/main.c +48 -57
163 lines not on this page · raw message
Signature · 1 line
2.45.0
Re: [PATCH v2 12/22] multipathd: split check_paths into two functions
Quoted 90 lines · Benjamin Marzinski
Instead of checking and updating each path, the checkerloop now starts
the checkers on all the paths incheck_paths(), and then goes back and
updates all the paths inupdate_paths(). Since the async checkers use an
absolute time to wait for before returningPATH_PENDING, only one checker actually needs to be waited for inupdate_paths(). The rest will
already have reached their timeout whenupdate_path()is called for them.The
check_paths()andupdate_paths()loop over the pathvec instead of looping through the multipath device paths to avoid having to restart checking of the device paths when the multipath device needs to be resynced while updating the paths.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/structs.h | 10 +++-
multipathd/main.c | 105 +++++++++++++++++++-------------------- --2 files changed, 57 insertions(+), 58 deletions(-)libmultipath/structs.h +0
-0@@ -314,6 +314,14 @@ enum recheck_wwid_states { RECHECK_WWID_ON = YNU_YES, };libmultipath/structs.h +8
-0+enum check_path_states { +CHECK_PATH_UNCHECKED , +CHECK_PATH_STARTED , +CHECK_PATH_CHECKED , +CHECK_PATH_SKIPPED , +CHECK_PATH_REMOVED , +}; +struct
vpd_vendor_page{
int pg;
const char *name;libmultipath/structs.h +1
-1@@ -395,7 +403,7 @@ struct path { int fast_io_fail; unsigned int dev_loss; int eh_deadline; -bool is_checked; +enum check_path_states is_checked; bool can_use_env_uid; unsigned int checker_timeout; /* configlet pointers */multipathd/main.c +0
-0@@ -2389,13 +2389,6 @@ sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) do_sync_mpp(vecs, mpp); }multipathd/main.c +0
-7-enum check_path_return { -CHECK_PATH_STARTED , -CHECK_PATH_CHECKED , -CHECK_PATH_SKIPPED , -CHECK_PATH_REMOVED , -}; -static int
update_path_state (struct vectors * vecs, struct path * pp) {multipathd/main.c +1
-0@@ -2735,6 +2728,7 @@ check_uninitialized_path(struct path * pp, unsigned int ticks) conf = get_multipath_config(); retrigger_tries = conf->retrigger_tries; pp->tick = conf->max_checkint; + pp->checkint = conf->checkint; put_multipath_config(conf);
if (pp->initialized==INIT_MISSING_UDEV) {multipathd/main.c +0
-0@@ -2778,6 +2772,10 @@ update_uninitialized_path(struct vectors * vecs, struct path * pp) int newstate, ret; struct config *conf;multipathd/main.c +1
-0+ if (pp->initialized != INIT_NEW && pp->initialized !=
INIT_FAILED&&multipathd/main.c +3
-0+ pp->initialized != INIT_MISSING_UDEV) +return CHECK_PATH_SKIPPED ; +
Quoted 2 lines
newstate =
get_new_state(pp);
It seems to me that this hunk and the previous one belong into 11/22.
Martin
Benjamin Marzinski
maintainerRe: [PATCH v2 12/22] multipathd: split check_paths into two functions
Quoted 87 lines · Martin Wilck
Quoted 86 lines · Benjamin Marzinski
Instead of checking and updating each path, the checkerloop now starts
the checkers on all the paths incheck_paths(), and then goes back and
updates all the paths inupdate_paths(). Since the async checkers use an
absolute time to wait for before returningPATH_PENDING, only one checker actually needs to be waited for inupdate_paths(). The rest will
already have reached their timeout whenupdate_path()is called for them.The
check_paths()andupdate_paths()loop over the pathvec instead of looping through the multipath device paths to avoid having to restart checking of the device paths when the multipath device needs to be resynced while updating the paths.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/structs.h | 10 +++-
multipathd/main.c | 105 +++++++++++++++++++-------------------- --2 files changed, 57 insertions(+), 58 deletions(-)libmultipath/structs.h +0
-0@@ -314,6 +314,14 @@ enum recheck_wwid_states { RECHECK_WWID_ON = YNU_YES, };libmultipath/structs.h +8
-0+enum check_path_states { +CHECK_PATH_UNCHECKED , +CHECK_PATH_STARTED , +CHECK_PATH_CHECKED , +CHECK_PATH_SKIPPED , +CHECK_PATH_REMOVED , +}; +struct
vpd_vendor_page{
int pg;
const char *name;libmultipath/structs.h +1
-1@@ -395,7 +403,7 @@ struct path { int fast_io_fail; unsigned int dev_loss; int eh_deadline; -bool is_checked; +enum check_path_states is_checked; bool can_use_env_uid; unsigned int checker_timeout; /* configlet pointers */multipathd/main.c +0
-0@@ -2389,13 +2389,6 @@ sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) do_sync_mpp(vecs, mpp); }multipathd/main.c +0
-7-enum check_path_return { -CHECK_PATH_STARTED , -CHECK_PATH_CHECKED , -CHECK_PATH_SKIPPED , -CHECK_PATH_REMOVED , -}; -static int
update_path_state (struct vectors * vecs, struct path * pp) {multipathd/main.c +1
-0@@ -2735,6 +2728,7 @@ check_uninitialized_path(struct path * pp, unsigned int ticks) conf = get_multipath_config(); retrigger_tries = conf->retrigger_tries; pp->tick = conf->max_checkint; + pp->checkint = conf->checkint; put_multipath_config(conf);
if (pp->initialized==INIT_MISSING_UDEV) {multipathd/main.c +0
-0@@ -2778,6 +2772,10 @@ update_uninitialized_path(struct vectors * vecs, struct path * pp) int newstate, ret; struct config *conf;multipathd/main.c +1
-0+ if (pp->initialized != INIT_NEW && pp->initialized !=
Quoted 8 lines
Quoted 6 lines
INIT_FAILED&&multipathd/main.c +3
-0+ pp->initialized != INIT_MISSING_UDEV) +return CHECK_PATH_SKIPPED ; +newstate =
get_new_state(pp);It seems to me that this hunk and the previous one belong into 11/22.
Setting pp->checkint could certainly go in the earlier patch. It's just there to match check_path(), although to be honest, I'm still not sure that there is any way for either check_path() or check_uninitialized_path() to get called with pp->checkint unset.
The checking the path->initialized state in update_uninitialized_path() makes less sense. That code is already in check_unintialized_path(). In 11/22, update_uninitialized_path() is always called immediately after check_unintialized_path() if it's called at all, and pp->initialized never has a chance to change.
In this patch, check_unintialized_path() is called in check_paths(), and it's possible that path checking takes too long, and we need take a break and yield to other vecs lock waiters before we call update_paths(), where update_uninitialized_path() is called. In this case, it's possible that a uevent got processed and changed pp->initialized, so we need to recheck it in update_uninitialized_path().
-Ben
Quoted 1 line
Martin
Benjamin Marzinski
maintainerPATCH v2 13/22 multipathd: fix "fail path" and "reinstate path" commands
In reply to Benjamin MarzinskiNow that multipathd can drop the vecs lock and sleep in-between when the checker runs and when the path gets updated, it is possible for the user to either fail or reinstate the path in this window.
If a path gets manually failed in the window between when the checker starts and the path is updated, the checker will have already been started, on the path, and if multipathd read the results like normal, it could simply reinstate the path. To avoid this, when a path checker is disabled, the checker path_state and message are updated, just like they are when checker_check() is run on a disabled path, so that when checker_get_state() is called, it will always return the same results for a disabled checker, regardless of when it was disabled.
Reinstating the path doesn't cause many problems, but still can be improved. Since the checker was disabled when it would have been started, it didn't run during this cycle, only the kernel state will get updated. The rest of the path update changes won't happen until the next time the checker runs. This is the case regardless of whether or not the path was reinstated in the window between when the checker starts and the path is updated. To make reinstated paths get updated sooner, pp->tick is now set to 1 when the path is reinstated.
--- libmultipath/checkers.c | 2 ++ multipathd/cli_handlers.c | 1 + 2 files changed, 3 insertions(+)
libmultipath/checkers.c +2 -0
@@ -251,6 +251,8 @@ void checker_disable (struct checker * c)if (!c)return ; c->disable =1 ; + c->msgid =CHECKER_MSGID_DISABLED ; + c->path_state =PATH_UNCHECKED ; }int checker_init (struct checker * c,void ** mpctxt_addr)
multipathd/cli_handlers.c +1 -0
@@ -1108,6 +1108,7 @@ cli_reinstate(void * v, struct strbuf *reply, void * data) pp->mpp->alias, pp->dev_t);checker_enable (&pp->checker); + pp->tick =1 ;return dm_reinstate_path (pp->mpp->alias, pp->dev_t); }
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 14/22 multipathd: update priority once after updating all paths
In reply to Benjamin MarzinskiInstead of updating the path priorities and possibly reloading the multipath device when each path is updated, wait till all paths have been updated, and then go through the multipath devices updating the priorities once, reloading if necessary.
--- libmultipath/structs.h | 9 +++ multipathd/main.c | 169 ++++++++++++++++++++++++++--------------- 2 files changed, 118 insertions(+), 60 deletions(-)
libmultipath/structs.h +9 -0
@@ -318,6 +318,7 @@ enum check_path_states {CHECK_PATH_UNCHECKED ,CHECK_PATH_STARTED ,CHECK_PATH_CHECKED , +CHECK_PATH_NEW_UP ,CHECK_PATH_SKIPPED , CHECK_PATH_REMOVED, };
@@ -421,6 +422,13 @@ enum prflag_value { PRFLAG_SET, }; +enum prio_update_type { +PRIO_UPDATE_NONE , +PRIO_UPDATE_NORMAL , +PRIO_UPDATE_NEW_PATH , +PRIO_UPDATE_MARGINAL , +}; +struct multipath {char wwid[WWID_SIZE ];char alias_old[WWID_SIZE ];
@@ -464,6 +472,7 @@ struct multipath {int queue_mode;unsigned int sync_tick;int synced_count; +enum prio_update_type prio_update;uid_t uid;gid_t gid;mode_t mode;
multipathd/main.c +109 -60
265 lines not on this page · raw message
Signature · 1 line
2.45.0
Re: [PATCH v2 14/22] multipathd: update priority once after updating all paths
Quoted 119 lines · Benjamin Marzinski
Instead of updating the path priorities and possibly reloading the multipath device when each path is updated, wait till all paths have been updated, and then go through the multipath devices updating the priorities once, reloading if necessary.
Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/structs.h | 9 +++
multipathd/main.c | 169 ++++++++++++++++++++++++++------------- --2 files changed, 118 insertions(+), 60 deletions(-)libmultipath/structs.h +1
-0@@ -318,6 +318,7 @@ enum check_path_states { CHECK_PATH_UNCHECKED, CHECK_PATH_STARTED, CHECK_PATH_CHECKED, +CHECK_PATH_NEW_UP , CHECK_PATH_SKIPPED, CHECK_PATH_REMOVED, };@@ -421,6 +422,13 @@ enum prflag_value { PRFLAG_SET, };libmultipath/structs.h +7
-0+enum prio_update_type { +PRIO_UPDATE_NONE , +PRIO_UPDATE_NORMAL , +PRIO_UPDATE_NEW_PATH , +PRIO_UPDATE_MARGINAL , +}; +struct multipath {
char wwid[WWID_SIZE];
char alias_old[WWID_SIZE];libmultipath/structs.h +1
-0@@ -464,6 +472,7 @@ struct multipath { int queue_mode; unsigned int sync_tick; int synced_count; +enum prio_update_type prio_update; uid_t uid; gid_t gid; mode_t mode;multipathd/main.c +0
-0@@ -1996,15 +1996,13 @@ mpvec_garbage_collector (struct vectors * vecs) * best pathgroup, and this is the first path in the pathgroup tocome back
* up, then switch to this pathgroup */
static intmultipathd/main.c +1
-1-followover_should_failback(struct path * pp) +do_followover_should_failback(struct path * pp){
struct pathgroup * pgp;
struct path *pp1;
int i;multipathd/main.c +1
-3-if (pp->mpp->pgfailback != -FAILBACK_FOLLOWOVER || - !pp->mpp->pg || !pp->pgindex || - pp->pgindex != pp->mpp->bestpg) +if (!pp->pgindex || pp->pgindex != pp->mpp->bestpg)return 0;
pgp =VECTOR_SLOT(pp->mpp->pg, pp->pgindex - 1);multipathd/main.c +0
-0@@ -2017,6 +2015,26 @@ followover_should_failback(struct path * pp) return 1; }multipathd/main.c +20
-0+static int +followover_should_failback (struct multipath *mpp) +{ +struct path *pp; +struct pathgroup * pgp; +int i, j; + +if (mpp->pgfailback != -FAILBACK_FOLLOWOVER || !mpp->pg) +return 0 ; + + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { +if (pp->is_checked ==CHECK_PATH_NEW_UP && + do_followover_should_failback(pp)) +return 1 ; + } + } +return 0 ; +} +static void
missing_uev_wait_tick(struct vectors *vecs)
{multipathd/main.c +0
-0@@ -2132,41 +2150,53 @@ partial_retrigger_tick(vector pathvec) } }multipathd/main.c +1
-1-static int update_prio (struct path *pp,int force_refresh_all) +static bool update_prio (struct multipath *mpp,bool refresh_all){
int oldpriority;multipathd/main.c +1
-1-struct path *pp1; +struct path *pp;struct pathgroup * pgp;
multipathd/main.c +3
-1-int i, j, changed =0 ; +int i, j; +bool changed = false; +bool skipped_path = false;struct config *conf;
multipathd/main.c +0
-5- oldpriority = pp->priority; -if (pp->state !=PATH_DOWN ) { - conf =get_multipath_config (); -pthread_cleanup_push (put_multipath_config, conf); -pathinfo (pp, conf,DI_PRIO );
multipathd/main.c partial_retrigger_tick(vector pathvec) · line 2171
Quoted 10 lines
multipathd/main.c +9
-1-pthread_cleanup_pop (1 ); + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { +if (pp->state ==PATH_DOWN ) +continue ; +if (!refresh_all && + pp->is_checked != CHECK_PATH_CHECKED) { + skipped_path = true; +continue ; + }
Nit: My first thought here was that this would skip paths for which pp->is_checked == CHECK_PATH_NEW_UP. Then I realized that if there was a new path up, refresh_all would be set, which is not immediately obvious. Can you add a comment?
Martin
Benjamin Marzinski
maintainerRe: [PATCH v2 14/22] multipathd: update priority once after updating all paths
Quoted 127 lines · Martin Wilck
Quoted 126 lines · Benjamin Marzinski
Instead of updating the path priorities and possibly reloading the multipath device when each path is updated, wait till all paths have been updated, and then go through the multipath devices updating the priorities once, reloading if necessary.
Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/structs.h | 9 +++
multipathd/main.c | 169 ++++++++++++++++++++++++++------------- --2 files changed, 118 insertions(+), 60 deletions(-)libmultipath/structs.h +1
-0@@ -318,6 +318,7 @@ enum check_path_states { CHECK_PATH_UNCHECKED, CHECK_PATH_STARTED, CHECK_PATH_CHECKED, +CHECK_PATH_NEW_UP , CHECK_PATH_SKIPPED, CHECK_PATH_REMOVED, };@@ -421,6 +422,13 @@ enum prflag_value { PRFLAG_SET, };libmultipath/structs.h +7
-0+enum prio_update_type { +PRIO_UPDATE_NONE , +PRIO_UPDATE_NORMAL , +PRIO_UPDATE_NEW_PATH , +PRIO_UPDATE_MARGINAL , +}; +struct multipath {
char wwid[WWID_SIZE];
char alias_old[WWID_SIZE];libmultipath/structs.h +1
-0@@ -464,6 +472,7 @@ struct multipath { int queue_mode; unsigned int sync_tick; int synced_count; +enum prio_update_type prio_update; uid_t uid; gid_t gid; mode_t mode;multipathd/main.c +0
-0@@ -1996,15 +1996,13 @@ mpvec_garbage_collector (struct vectors * vecs) * best pathgroup, and this is the first path in the pathgroup tocome back
* up, then switch to this pathgroup */
static intmultipathd/main.c +1
-1-followover_should_failback(struct path * pp) +do_followover_should_failback(struct path * pp){
struct pathgroup * pgp;
struct path *pp1;
int i;multipathd/main.c +1
-3-if (pp->mpp->pgfailback != -FAILBACK_FOLLOWOVER || - !pp->mpp->pg || !pp->pgindex || - pp->pgindex != pp->mpp->bestpg) +if (!pp->pgindex || pp->pgindex != pp->mpp->bestpg)return 0;
pgp =VECTOR_SLOT(pp->mpp->pg, pp->pgindex - 1);multipathd/main.c +0
-0@@ -2017,6 +2015,26 @@ followover_should_failback(struct path * pp) return 1; }multipathd/main.c +20
-0+static int +followover_should_failback (struct multipath *mpp) +{ +struct path *pp; +struct pathgroup * pgp; +int i, j; + +if (mpp->pgfailback != -FAILBACK_FOLLOWOVER || !mpp->pg) +return 0 ; + + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { +if (pp->is_checked ==CHECK_PATH_NEW_UP && + do_followover_should_failback(pp)) +return 1 ; + } + } +return 0 ; +} +static void
missing_uev_wait_tick(struct vectors *vecs)
{multipathd/main.c +0
-0@@ -2132,41 +2150,53 @@ partial_retrigger_tick(vector pathvec) } }multipathd/main.c +1
-1-static int update_prio (struct path *pp,int force_refresh_all) +static bool update_prio (struct multipath *mpp,bool refresh_all){
int oldpriority;multipathd/main.c +1
-1-struct path *pp1; +struct path *pp;struct pathgroup * pgp;
multipathd/main.c +3
-1-int i, j, changed =0 ; +int i, j; +bool changed = false; +bool skipped_path = false;struct config *conf;
multipathd/main.c +6
-6- oldpriority = pp->priority; -if (pp->state !=PATH_DOWN ) { - conf =get_multipath_config (); -pthread_cleanup_push (put_multipath_config, conf); -pathinfo (pp, conf,DI_PRIO ); -pthread_cleanup_pop (1 ); + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { +if (pp->state ==PATH_DOWN ) +continue ; +if (!refresh_all && + pp->is_checked != CHECK_PATH_CHECKED) {
Quoted 8 lines
multipathd/main.c partial_retrigger_tick(vector pathvec) · line 2171
Quoted 3 lines
multipathd/main.c +3
-0+ skipped_path = true; +continue ; + }Nit: My first thought here was that this would skip paths for which
pp->is_checked==CHECK_PATH_NEW_UP. Then I realized that if there was a new path up,refresh_allwould be set, which is not immediately obvious. Can you add a comment?
Sure.
Quoted 2 lines
Martin
Benjamin Marzinski
maintainerPATCH v2 15/22 multipathd: simplify checking for followover_should_failback
In reply to Benjamin MarzinskiThe code needs to check that pp->pgindex equals pp->mpp->bestpg and that they aren't both 0 (which is an invalid pathgroup id). Since we're already checking that they are equal, we only need to check one of them to see if it's non-zero. Instead of checking if pp->pgindex is non-zero for every path, just check mpp->bestpg once for the multipath device and return immediately if it's zero.
--- multipathd/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
multipathd/main.c +2 -2
@@ -2002,7 +2002,7 @@ do_followover_should_failback(struct path * pp)struct path *pp1;int i; -if (!pp->pgindex || pp->pgindex != pp->mpp->bestpg) +if (pp->pgindex != pp->mpp->bestpg)return 0 ; pgp =VECTOR_SLOT (pp->mpp->pg, pp->pgindex -1 );
@@ -2022,7 +2022,7 @@ followover_should_failback(struct multipath *mpp)struct pathgroup * pgp;int i, j; -if (mpp->pgfailback != -FAILBACK_FOLLOWOVER || !mpp->pg) +if (mpp->pgfailback != -FAILBACK_FOLLOWOVER || !mpp->pg || !mpp->bestpg)return 0 ; vector_foreach_slot (mpp->pg, pgp, i) {
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 16/22 multipathd: only refresh prios on PATH_UP and PATH_GHOST
In reply to Benjamin MarzinskiThe way that multipathd was handling priority refreshes had some issues. Some of the multipath prioritizers can hang when run on a failed path. Multipathd was only skipping paths in PATH_DOWN, but there are other states where the prioritizer is also likely to hang, such as PATH_TIMEOUT, PATH_SHAKY, and to a lesser extent, PATH_DELAYED.
Also, before the recent patch splitting the priority updating from the path checking, multipathd wasn't consistent with which states would cause
paths to get their priorities updated. If a path changed its state to anything other than PATH_UP or PATH_GHOST, it wouldn't get its priority updated. But if a path kept the same state its priority would get updated as long at the state wasn't PATH_DOWN.
For safety's sake, a path's priority should only get refreshed when its in the PATH_UP or PATH_GHOST state. This shouldn't cause problems. Only paths that are in the PATH_UP or PATH_GHOST state are usable by the kenel and contibute to the pathgroup's priority.
--- multipathd/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
multipathd/main.c +2 -2
@@ -2162,7 +2162,7 @@ static bool update_prio(struct multipath *mpp, bool refresh_all) vector_foreach_slot (mpp->pg, pgp, i) { vector_foreach_slot (pgp->paths, pp, j) { -if (pp->state ==PATH_DOWN ) +if (pp->state !=PATH_UP && pp->state !=PATH_GHOST )continue ;if (!refresh_all && pp->is_checked !=CHECK_PATH_CHECKED ) {
@@ -2186,7 +2186,7 @@ static bool update_prio(struct multipath *mpp, bool refresh_all)*/ vector_foreach_slot (mpp->pg, pgp, i) { vector_foreach_slot (pgp->paths, pp, j) { -if (pp->state ==PATH_DOWN ) +if (pp->state !=PATH_UP && pp->state !=PATH_GHOST )continue ;if (pp->is_checked ==CHECK_PATH_CHECKED )continue ;
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 17/22 multipathd: remove pointless check
In reply to Benjamin MarzinskiSince we just returned if newstate wasn't PATH_UP or PATH_GHOST, it must obviously be PATH_UP or PATH_GHOST at this point in the code. We don't even wrap all the code for dealing with a path that just came up in this if-block, It's only the persistent resrvation code.
--- multipathd/main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
multipathd/main.c +13 -13
@@ -2545,19 +2545,19 @@ update_path_state (struct vectors * vecs, struct path * pp)return CHECK_PATH_CHECKED ; } -if (newstate ==PATH_UP || newstate ==PATH_GHOST ) { -if (pp->mpp->prflag !=PRFLAG_UNSET ) { -int prflag = pp->mpp->prflag; -/* -* Check Persistent Reservation. -*/ -condlog (2 ,"%s: checking persistent " -"reservation registration" , pp->dev); -mpath_pr_event_handle (pp); -if (pp->mpp->prflag ==PRFLAG_SET && - prflag !=PRFLAG_SET ) -pr_register_active_paths (pp->mpp); - } +/* newstate == PATH_UP || newstate == PATH_GHOST */ + +if (pp->mpp->prflag !=PRFLAG_UNSET ) { +int prflag = pp->mpp->prflag; +/* +* Check Persistent Reservation. +*/ +condlog (2 ,"%s: checking persistent " +"reservation registration" , pp->dev); +mpath_pr_event_handle (pp); +if (pp->mpp->prflag ==PRFLAG_SET && + prflag !=PRFLAG_SET ) +pr_register_active_paths (pp->mpp); }/*
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 18/22 multipathd: fix deferred_failback_tick for reload removes
In reply to Benjamin MarzinskiIf reload_and_sync_map() removes the multipath device, deferred_failback_tick() needs to decrement the counter so that it doesn't skip the following device.
--- multipathd/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
multipathd/main.c +6 -3
@@ -2098,9 +2098,12 @@ deferred_failback_tick (struct vectors *vecs)if (!mpp->failback_tick &&need_switch_pathgroup (mpp, &need_reload)) { -if (need_reload) -reload_and_sync_map (mpp, vecs); -else +if (need_reload) { +if (reload_and_sync_map (mpp, vecs) ==2 ) { +/* multipath device removed */ + i--; + } + }else switch_pathgroup (mpp); } }
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 19/22 libmultipath: add libcheck_need_wait checker function
In reply to Benjamin MarzinskiAdd a new optional checker class function, libcheck_need_wait() and a new function to call it, checker_need_wait(). This can be used to see if a path_checker is currently running. This will be used to determine if there are pending checkers that need to be waited for.
--- libmultipath/checkers.c | 12 +++++++++++- libmultipath/checkers.h | 4 +++- libmultipath/checkers/directio.c | 10 ++++++++++ libmultipath/checkers/tur.c | 10 ++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-)
libmultipath/checkers.c +11 -1
@@ -27,6 +27,7 @@ struct checker_class {void (*reset)(void );/* to reset the global variables */ void *(*thread)(void *);/* async thread entry point */ int (*pending)(struct checker *);/* to recheck pending paths */ +bool (*need_wait)(struct checker *);/* checker needs waiting for */ const char **msgtable;short msgtable_size; };
@@ -182,7 +183,8 @@ static struct checker_class *add_checker_class(const char *name) c->reset = (void (*)(void ))dlsym (c->handle,"libcheck_reset" ); c->thread = (void *(*)(void *))dlsym (c->handle,"libcheck_thread" ); c->pending = (int (*)(struct checker *))dlsym (c->handle,"libcheck_pending" ); -/* These 4 functions can be NULL. call dlerror() to clear out any + c->need_wait = (bool (*)(struct checker *))dlsym (c->handle,"libcheck_need_wait" ); +/* These 5 functions can be NULL. call dlerror() to clear out any * error string */ dlerror ();
@@ -313,6 +315,14 @@ int checker_get_state(struct checker *c)return c->path_state; } +bool checker_need_wait (struct checker *c) +{ +if (!c || !c->cls || c->path_state !=PATH_PENDING || + !c->cls->need_wait) +return false; +return c->cls->need_wait (c); +} +void checker_check (struct checker * c,int path_state) {if (!c)
libmultipath/checkers.h +3 -1
@@ -2,6 +2,7 @@#define CHECKERS_H_INCLUDED #include <pthread.h> +#include <stdbool.h> #include "list.h" #include "defaults.h"
@@ -171,6 +172,7 @@ struct checker_context {int start_checker_thread (pthread_t *thread,const pthread_attr_t *attr,struct checker_context *ctx);int checker_get_state (struct checker *c); +bool checker_need_wait (struct checker *c);void checker_check (struct checker *,int );int checker_is_sync (const struct checker *);const char *checker_name (const struct checker *);
@@ -191,7 +193,7 @@ void *libcheck_thread(struct checker_context *ctx);void libcheck_reset (void );int libcheck_mp_init (struct checker *);int libcheck_pending (struct checker *c); - +bool libcheck_need_wait (struct checker *c);/* * msgid => message map.
libmultipath/checkers/directio.c +10 -0
@@ -65,6 +65,7 @@ struct directio_context {struct aio_group *aio_grp;struct async_req *req;struct timespec endtime; +bool waited_for; }; static struct aio_group *
@@ -295,6 +296,7 @@ check_pending(struct directio_context *ct, struct timespec endtime)int r;struct timespec currtime, timeout; + ct->waited_for = true;while (1 ) {get_monotonic_time (&currtime);timespecsub (&endtime, &currtime, &timeout);
@@ -346,6 +348,7 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)get_monotonic_time (&ct->endtime); ct->endtime.tv_nsec +=1000 *1000 ;normalize_timespec (&ct->endtime); + ct->waited_for = false; } ct->running++;if (!sync)
@@ -386,6 +389,13 @@ static void set_msgid(struct checker *c, int state) } } +bool libcheck_need_wait (struct checker *c) +{ +struct directio_context *ct = (struct directio_context *)c->context; +return (ct && ct->running && ct->req->state ==PATH_PENDING && + !ct->waited_for); +} +int libcheck_pending (struct checker *c) {int rc;
libmultipath/checkers/tur.c +10 -0
@@ -59,6 +59,7 @@ struct tur_checker_context {struct checker_context ctx;unsigned int nr_timeouts;struct timespec endtime; +bool waited_for; };int libcheck_init (struct checker * c)
@@ -351,9 +352,17 @@ int check_pending(struct checker *c) ct->thread =0 ; } + ct->waited_for = true;return tur_status; } +bool libcheck_need_wait (struct checker *c) +{ +struct tur_checker_context *ct = c->context; +return (ct && ct->thread &&uatomic_read (&ct->running) !=0 && + !ct->waited_for); +} +int libcheck_pending (struct checker *c) {struct tur_checker_context *ct = c->context;
@@ -463,6 +472,7 @@ int libcheck_check(struct checker * c)pthread_mutex_unlock (&ct->lock); ct->fd = c->fd; ct->timeout = c->timeout; + ct->waited_for = false;uatomic_add (&ct->holders,1 );uatomic_set (&ct->running,1 );tur_set_async_timeout (c);
Signature · 1 line
2.45.0
Re: [PATCH v2 19/22] libmultipath: add libcheck_need_wait checker function
Quoted 112 lines · Benjamin Marzinski
Add a new optional checker class function,
libcheck_need_wait()and a new function to call it,checker_need_wait(). This can be used to see if
apath_checkeris currently running. This will be used to determine if
there are pending checkers that need to be waited for.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/checkers.c | 12 +++++++++++- libmultipath/checkers.h | 4 +++-libmultipath/checkers/directio.c| 10 ++++++++++ libmultipath/checkers/tur.c | 10 ++++++++++4 files changed, 34 insertions(+), 2 deletions(-)libmultipath/checkers.c +0
-0@@ -27,6 +27,7 @@ struct checker_class {void (*reset)(void); /* to reset the global
variables */
void *(*thread)(void *); /* async thread entry
point */
int (*pending)(struct checker *); /* to recheck pending paths */libmultipath/checkers.c +1
-0+bool (*need_wait)(struct checker *);/* checker needs waiting for */
const char **msgtable;
shortmsgtable_size;
};libmultipath/checkers.c +0
-1@@ -182,7 +183,8 @@ static struct checker_class *add_checker_class(const char *name) c->reset = (void (*)(void)) dlsym(c->handle,"libcheck_reset" ); c->thread = (void *(*)(void*)) dlsym(c->handle,"libcheck_thread" ); c->pending = (int (*)(struct checker *)) dlsym(c->handle,"libcheck_pending" ); -/* These 4 functions can be NULL. call dlerror() to clear out any
libmultipath/checkers.c +1
-0+ c->need_wait = (bool (*)(struct checker *)) dlsym(c->handle,"
libcheck_need_wait");libmultipath/checkers.c +1
-0+/* These 5 functions can be NULL. call dlerror() to clear out any
* error string */
dlerror();libmultipath/checkers.c +0
-0@@ -313,6 +315,14 @@ int checker_get_state(struct checker *c) return c->path_state; }libmultipath/checkers.c +8
-0+bool checker_need_wait (struct checker *c) +{ +if (!c || !c->cls || c->path_state !=PATH_PENDING || + !c->cls->need_wait) +return false; +return c->cls->need_wait (c); +} +void
checker_check(struct checker * c, intpath_state) {
if (!c)libmultipath/checkers.h +0
-0@@ -2,6 +2,7 @@ #define CHECKERS_H_INCLUDED
#include <pthread.h>
+#include <stdbool.h>
#include "list.h"
#include "defaults.h"libmultipath/checkers.h +0
-0@@ -171,6 +172,7 @@ struct checker_context {int
start_checker_thread(pthread_t*thread, constpthread_attr_t*attr,
structchecker_context*ctx); intchecker_get_state(struct checker *c);
+boolchecker_need_wait(struct checker *c);
voidchecker_check(struct checker *, int);
intchecker_is_sync(const struct checker *);
const char*checker_name(const struct checker *);libmultipath/checkers.h +1
-1@@ -191,7 +193,7 @@ void *libcheck_thread(struct checker_context *ctx); void libcheck_reset(void); int libcheck_mp_init(struct checker *); int libcheck_pending(struct checker *c); - +bool libcheck_need_wait (struct checker *c);
/*
* msgid => message map.libmultipath/checkers/directio.c +1
-0@@ -65,6 +65,7 @@ struct directio_context { struct aio_group *aio_grp; struct async_req *req; struct timespec endtime; +bool waited_for; };
static structaio_group*libmultipath/checkers/directio.c +0
-0@@ -295,6 +296,7 @@ check_pending(struct directio_context *ct, struct timespec endtime) int r; struct timespec currtime, timeout;
libmultipath/checkers/directio.c
Quoted 1 line
libmultipath/checkers/directio.c +1
-0+ ct->waited_for = true;
Not sure if it's important, but strictly speaking, we have only waited for the checker if the endtime was in the future, which is often not the case. Otherwise we'd just have polled.
Martin
Quoted 69 lines
while(1) {
get_monotonic_time(&currtime);timespecsub(&endtime, &currtime, &timeout);libmultipath/checkers/directio.c +1
-0@@ -346,6 +348,7 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs) get_monotonic_time(&ct->endtime); ct->endtime.tv_nsec += 1000 * 1000; normalize_timespec(&ct->endtime); + ct->waited_for = false; } ct->running++;if (!sync)
libmultipath/checkers/directio.c +0
-0@@ -386,6 +389,13 @@ static void set_msgid(struct checker *c, int state) } }libmultipath/checkers/directio.c +3
-0+bool libcheck_need_wait (struct checker *c) +{ + struct directio_context *ct = (struct directio_context *)c-Quoted 1 line
context;
libmultipath/checkers/directio.c +1
-0+ return (ct && ct->running && ct->req->state == PATH_PENDING&&
libmultipath/checkers/directio.c +3
-0+ !ct->waited_for); +} +int
libcheck_pending(struct checker *c)
{
int rc;libmultipath/checkers/tur.c +1
-0@@ -59,6 +59,7 @@ struct tur_checker_context { struct checker_context ctx; unsigned int nr_timeouts; struct timespec endtime; +bool waited_for; };
intlibcheck_init(struct checker * c)libmultipath/checkers/tur.c +0
-0@@ -351,9 +352,17 @@ int check_pending(struct checker *c) ct->thread = 0; }libmultipath/checkers/tur.c +1
-0+ ct->waited_for = true;return
tur_status;
}libmultipath/checkers/tur.c +4
-0+bool libcheck_need_wait (struct checker *c) +{ +struct tur_checker_context *ct = c->context; + return (ct && ct->thread && uatomic_read(&ct->running) != 0&&
libmultipath/checkers/tur.c +3
-0+ !ct->waited_for); +} +int
libcheck_pending(struct checker *c)
{
structtur_checker_context*ct =c->context;libmultipath/checkers/tur.c +1
-0@@ -463,6 +472,7 @@ int libcheck_check(struct checker * c) pthread_mutex_unlock(&ct->lock); ct->fd = c->fd; ct->timeout = c->timeout; + ct->waited_for = false; uatomic_add(&ct->holders, 1); uatomic_set(&ct->running, 1); tur_set_async_timeout(c);
Benjamin Marzinski
maintainerRe: [PATCH v2 19/22] libmultipath: add libcheck_need_wait checker function
Quoted 110 lines · Martin Wilck
Quoted 109 lines · Benjamin Marzinski
Add a new optional checker class function,
libcheck_need_wait()and a new function to call it,checker_need_wait(). This can be used to see if
apath_checkeris currently running. This will be used to determine if
there are pending checkers that need to be waited for.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/checkers.c | 12 +++++++++++- libmultipath/checkers.h | 4 +++-libmultipath/checkers/directio.c| 10 ++++++++++ libmultipath/checkers/tur.c | 10 ++++++++++4 files changed, 34 insertions(+), 2 deletions(-)libmultipath/checkers.c +0
-0@@ -27,6 +27,7 @@ struct checker_class {void (*reset)(void); /* to reset the global
variables */
void *(*thread)(void *); /* async thread entry
point */
int (*pending)(struct checker *); /* to recheck pending paths */libmultipath/checkers.c +1
-0+bool (*need_wait)(struct checker *);/* checker needs waiting for */
const char **msgtable;
shortmsgtable_size;
};libmultipath/checkers.c +0
-1@@ -182,7 +183,8 @@ static struct checker_class *add_checker_class(const char *name) c->reset = (void (*)(void)) dlsym(c->handle,"libcheck_reset" ); c->thread = (void *(*)(void*)) dlsym(c->handle,"libcheck_thread" ); c->pending = (int (*)(struct checker *)) dlsym(c->handle,"libcheck_pending" ); -/* These 4 functions can be NULL. call dlerror() to clear out any
libmultipath/checkers.c +1
-0+ c->need_wait = (bool (*)(struct checker *)) dlsym(c->handle,"
libcheck_need_wait");libmultipath/checkers.c +1
-0+/* These 5 functions can be NULL. call dlerror() to clear out any
* error string */
dlerror();libmultipath/checkers.c +0
-0@@ -313,6 +315,14 @@ int checker_get_state(struct checker *c) return c->path_state; }libmultipath/checkers.c +8
-0+bool checker_need_wait (struct checker *c) +{ +if (!c || !c->cls || c->path_state !=PATH_PENDING || + !c->cls->need_wait) +return false; +return c->cls->need_wait (c); +} +void
checker_check(struct checker * c, intpath_state) {
if (!c)libmultipath/checkers.h +0
-0@@ -2,6 +2,7 @@ #define CHECKERS_H_INCLUDED
#include <pthread.h>
+#include <stdbool.h>
#include "list.h"
#include "defaults.h"libmultipath/checkers.h +0
-0@@ -171,6 +172,7 @@ struct checker_context {int
start_checker_thread(pthread_t*thread, constpthread_attr_t*attr,
structchecker_context*ctx); intchecker_get_state(struct checker *c);
+boolchecker_need_wait(struct checker *c);
voidchecker_check(struct checker *, int);
intchecker_is_sync(const struct checker *);
const char*checker_name(const struct checker *);libmultipath/checkers.h +1
-1@@ -191,7 +193,7 @@ void *libcheck_thread(struct checker_context *ctx); void libcheck_reset(void); int libcheck_mp_init(struct checker *); int libcheck_pending(struct checker *c); - +bool libcheck_need_wait (struct checker *c);
/*
* msgid => message map.libmultipath/checkers/directio.c +1
-0@@ -65,6 +65,7 @@ struct directio_context { struct aio_group *aio_grp; struct async_req *req; struct timespec endtime; +bool waited_for; };
static structaio_group*libmultipath/checkers/directio.c +0
-0@@ -295,6 +296,7 @@ check_pending(struct directio_context *ct, struct timespec endtime)
Quoted 8 lines
libmultipath/checkers/directio.c
Quoted 4 lines
libmultipath/checkers/directio.c +0
-0int r; struct timespec currtime, timeout;libmultipath/checkers/directio.c +1
-0+ ct->waited_for = true;Not sure if it's important, but strictly speaking, we have only waited for the checker if the endtime was in the future, which is often not the case. Otherwise we'd just have polled.
But we always set the endtime in the future when we're starting a new request, so the first time the we call check_pending() we don't return till we either get an answer or endtime has passed, which is what we want waited_for to check (that we've give the checker till endtime to respond).
-Ben
Quoted 73 lines
Martin
Quoted 69 lines
while(1) {
get_monotonic_time(&currtime);timespecsub(&endtime, &currtime, &timeout);libmultipath/checkers/directio.c +1
-0@@ -346,6 +348,7 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs) get_monotonic_time(&ct->endtime); ct->endtime.tv_nsec += 1000 * 1000; normalize_timespec(&ct->endtime); + ct->waited_for = false; } ct->running++;if (!sync)
libmultipath/checkers/directio.c +0
-0@@ -386,6 +389,13 @@ static void set_msgid(struct checker *c, int state) } }libmultipath/checkers/directio.c +3
-0+bool libcheck_need_wait (struct checker *c) +{ + struct directio_context *ct = (struct directio_context *)c-Quoted 1 line
context;
libmultipath/checkers/directio.c +1
-0+ return (ct && ct->running && ct->req->state == PATH_PENDING&&
libmultipath/checkers/directio.c +3
-0+ !ct->waited_for); +} +int
libcheck_pending(struct checker *c)
{
int rc;libmultipath/checkers/tur.c +1
-0@@ -59,6 +59,7 @@ struct tur_checker_context { struct checker_context ctx; unsigned int nr_timeouts; struct timespec endtime; +bool waited_for; };
intlibcheck_init(struct checker * c)libmultipath/checkers/tur.c +0
-0@@ -351,9 +352,17 @@ int check_pending(struct checker *c) ct->thread = 0; }libmultipath/checkers/tur.c +1
-0+ ct->waited_for = true;return
tur_status;
}libmultipath/checkers/tur.c +4
-0+bool libcheck_need_wait (struct checker *c) +{ +struct tur_checker_context *ct = c->context; + return (ct && ct->thread && uatomic_read(&ct->running) != 0&&
libmultipath/checkers/tur.c +3
-0+ !ct->waited_for); +} +int
libcheck_pending(struct checker *c)
{
structtur_checker_context*ct =c->context;libmultipath/checkers/tur.c +1
-0@@ -463,6 +472,7 @@ int libcheck_check(struct checker * c) pthread_mutex_unlock(&ct->lock); ct->fd = c->fd; ct->timeout = c->timeout; + ct->waited_for = false; uatomic_add(&ct->holders, 1); uatomic_set(&ct->running, 1); tur_set_async_timeout(c);
Re: [PATCH v2 19/22] libmultipath: add libcheck_need_wait checker function
Quoted 134 lines · Benjamin Marzinski
Quoted 124 lines · Martin Wilck
Quoted 123 lines · Benjamin Marzinski
Add a new optional checker class function,
libcheck_need_wait()and a
new function to call it,checker_need_wait(). This can be used to see
if
apath_checkeris currently running. This will be used to determine
if
there are pending checkers that need to be waited for.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/checkers.c | 12 +++++++++++- libmultipath/checkers.h | 4 +++-libmultipath/checkers/directio.c| 10 ++++++++++ libmultipath/checkers/tur.c | 10 ++++++++++4 files changed, 34 insertions(+), 2 deletions(-)libmultipath/checkers.c +0
-0@@ -27,6 +27,7 @@ struct checker_class {void (*reset)(void); /* to reset the
global
variables */
void *(*thread)(void *); /* async thread
entry
point */
int (*pending)(struct checker *); /* to recheck pending
paths */libmultipath/checkers.c +1
-0+bool (*need_wait)(struct checker *);/* checker needs waiting for */
const char **msgtable;
shortmsgtable_size;
};libmultipath/checkers.c +0
-0@@ -182,7 +183,8 @@ static struct checker_class *add_checker_class(const char *name) c->reset = (void (*)(void)) dlsym(c->handle,"libcheck_reset" ); c->thread = (void *(*)(void*)) dlsym(c->handle,"libcheck_thread" );
c->pending= (int (*)(struct checker *)) dlsym(c-Quoted 1 line
handle,
"
libcheck_pending");libmultipath/checkers.c +0
-1-/* These 4 functions can be NULL. call dlerror() to clear
out anylibmultipath/checkers.c +1
-0+ c->need_wait = (bool (*)(struct checker *)) dlsym(c-Quoted 1 line
handle,
"
libcheck_need_wait");libmultipath/checkers.c +1
-0+/* These 5 functions can be NULL. call dlerror() to clear
out any
* error string */
dlerror();libmultipath/checkers.c +0
-0@@ -313,6 +315,14 @@ int checker_get_state(struct checker *c) return c->path_state; }libmultipath/checkers.c +8
-0+bool checker_need_wait (struct checker *c) +{ +if (!c || !c->cls || c->path_state !=PATH_PENDING || + !c->cls->need_wait) +return false; +return c->cls->need_wait (c); +} +void
checker_check(struct checker * c, intpath_state) {
if (!c)libmultipath/checkers.h +0
-0@@ -2,6 +2,7 @@ #define CHECKERS_H_INCLUDED
#include <pthread.h>
+#include <stdbool.h>
#include "list.h"
#include "defaults.h"libmultipath/checkers.h +0
-0@@ -171,6 +172,7 @@ struct checker_context {int
start_checker_thread(pthread_t*thread, constpthread_attr_t
*attr,
structchecker_context*ctx); intchecker_get_state(struct checker *c); +boolchecker_need_wait(struct checker *c); voidchecker_check(struct checker *, int); intchecker_is_sync(const struct checker *); const char*checker_name(const struct checker *);libmultipath/checkers.h +1
-1@@ -191,7 +193,7 @@ void *libcheck_thread(struct checker_context *ctx); void libcheck_reset(void); int libcheck_mp_init(struct checker *); int libcheck_pending(struct checker *c); - +bool libcheck_need_wait (struct checker *c);
/*
* msgid => message map.libmultipath/checkers/directio.c +1
-0@@ -65,6 +65,7 @@ struct directio_context { struct aio_group *aio_grp; struct async_req *req; struct timespec endtime; +bool waited_for; };
static structaio_group*libmultipath/checkers/directio.c +0
-0@@ -295,6 +296,7 @@ check_pending(struct directio_context *ct,struct
timespec endtime)
int r;
struct timespec currtime, timeout;Quoted 8 lines
libmultipath/checkers/directio.c
Quoted 2 lines
libmultipath/checkers/directio.c +1
-0+ ct->waited_for = true;Not sure if it's important, but strictly speaking, we have only waited
for the checker if the endtime was in the future, which is often not
the case. Otherwise we'd just have polled.
Quoted 6 lines
But we always set the endtime in the future when we're starting a new request, so the first time the we call
check_pending()we don't return
till we either get an answer or endtime has passed, which is what we wantwaited_forto check (that we've give the checker till endtime to respond).
That holds for this patch. But right in the next patch, the code is changed such that libcheck_pending doesn't actually wait at all. So "ct->waited_for" is a really confusing name. It just means that we have polled for the state once. In theory that can happen very quickly after starting the checker.
Regards
Martin
Benjamin Marzinski
maintainerRe: [PATCH v2 19/22] libmultipath: add libcheck_need_wait checker function
Quoted 3 lines · Martin Wilck
Quoted 2 lines · Benjamin Marzinski
Quoted 1 line · Martin Wilck
On Thu, 2024-09-12 at 17:49 -0400, Benjamin Marzinski wrote:
<snip>
Quoted 34 lines
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
libmultipath/checkers/directio.c +1
-0@@ -65,6 +65,7 @@ struct directio_context { struct aio_group *aio_grp; struct async_req *req; struct timespec endtime; +bool waited_for; };
static structaio_group*libmultipath/checkers/directio.c +0
-0@@ -295,6 +296,7 @@ check_pending(struct directio_context *ct,struct
timespec endtime)
int r;
struct timespec currtime, timeout;Quoted 8 lines
libmultipath/checkers/directio.c
Quoted 2 lines
libmultipath/checkers/directio.c +1
-0+ ct->waited_for = true;Not sure if it's important, but strictly speaking, we have only waited
for the checker if the endtime was in the future, which is often not
the case. Otherwise we'd just have polled.Quoted 6 lines
But we always set the endtime in the future when we're starting a new request, so the first time the we call
check_pending()we don't return
till we either get an answer or endtime has passed, which is what we wantwaited_forto check (that we've give the checker till endtime to respond).
Quoted 5 lines
That holds for this patch. But right in the next patch, the code is changed such that
libcheck_pendingdoesn't actually wait at all. So "ct->waited_for" is a really confusing name. It just means that we have polled for the state once. In theory that can happen very quickly after starting the checker.
Oh. Yeah. I can change the of the variable to something like is_unpolled, and the calling function to checker_is_unpolled(), which matches what we're actually asking for.
-Ben
Quoted 2 lines
Regards
Martin
Benjamin Marzinski
maintainerRe: [PATCH v2 19/22] libmultipath: add libcheck_need_wait checker function
Quoted 47 lines · Benjamin Marzinski
Quoted 3 lines · Martin Wilck
Quoted 2 lines · Benjamin Marzinski
Quoted 1 line · Martin Wilck
On Thu, 2024-09-12 at 17:49 -0400, Benjamin Marzinski wrote:
<snip>
Quoted 34 lines
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
libmultipath/checkers/directio.c +1
-0@@ -65,6 +65,7 @@ struct directio_context { struct aio_group *aio_grp; struct async_req *req; struct timespec endtime; +bool waited_for; };
static structaio_group*libmultipath/checkers/directio.c +0
-0@@ -295,6 +296,7 @@ check_pending(struct directio_context *ct,struct
timespec endtime)
int r;
struct timespec currtime, timeout;Quoted 8 lines
libmultipath/checkers/directio.c
Quoted 2 lines
libmultipath/checkers/directio.c +1
-0+ ct->waited_for = true;Not sure if it's important, but strictly speaking, we have only waited
for the checker if the endtime was in the future, which is often not
the case. Otherwise we'd just have polled.Quoted 6 lines
But we always set the endtime in the future when we're starting a new request, so the first time the we call
check_pending()we don't return
till we either get an answer or endtime has passed, which is what we wantwaited_forto check (that we've give the checker till endtime to respond).Quoted 5 lines
That holds for this patch. But right in the next patch, the code is changed such that
libcheck_pendingdoesn't actually wait at all. So "ct->waited_for" is a really confusing name. It just means that we have polled for the state once. In theory that can happen very quickly after starting the checker.
Quoted 3 lines
Oh. Yeah. I can change the of the variable to something like
is_unpolled, and the calling function tochecker_is_unpolled(), which matches what we're actually asking for.
Actually, I'm going to leave the calling functon as checker_need_wait(), since the question we're asking the checker is whether or not we need to wait. Even if the checker is unpolled, if it's not pending, there's no point in waiting. Inside the checkers, I'll change the variable name to checked_state, which makes more sense than is_unpolled in the initial patch, where you're still waiting instead of just polling.
-Ben
Quoted 5 lines
-Ben
Quoted 2 lines
Regards
Martin
Benjamin Marzinski
maintainerPATCH v2 20/22 libmultipath: don't wait in libcheck_pending
In reply to Benjamin MarzinskiDisable waiting in the libcheck_pending() checker class functions. Instead, they now just check if the checker has already completed. A future patch will re-add waiting outside of libcheck_pending().
--- libmultipath/checkers/directio.c | 41 ++++++++++++++++---------------- libmultipath/checkers/tur.c | 20 +++------------- 2 files changed, 23 insertions(+), 38 deletions(-)
libmultipath/checkers/directio.c +20 -21
@@ -64,7 +64,6 @@ struct directio_context {int reset_flags;struct aio_group *aio_grp;struct async_req *req; -struct timespec endtime;bool waited_for; };
@@ -291,18 +290,17 @@ get_events(struct aio_group *aio_grp, struct timespec *timeout) }static void -check_pending (struct directio_context *ct,struct timespec endtime) +check_pending (struct directio_context *ct,struct timespec timeout) {int r; -struct timespec currtime, timeout; +struct timespec endtime, currtime; ct->waited_for = true; +get_monotonic_time (&endtime); + endtime.tv_sec += timeout.tv_sec; + endtime.tv_nsec += timeout.tv_nsec; +normalize_timespec (&endtime);while (1 ) { -get_monotonic_time (&currtime); -timespecsub (&endtime, &currtime, &timeout); -if (timeout.tv_sec <0 ) - timeout.tv_sec = timeout.tv_nsec =0 ; - r =get_events (ct->aio_grp, &timeout);if (ct->req->state !=PATH_PENDING ) {
@@ -311,6 +309,10 @@ check_pending(struct directio_context *ct, struct timespec endtime) }else if (r ==0 || (timeout.tv_sec ==0 && timeout.tv_nsec ==0 ))return ; +get_monotonic_time (&currtime); +timespecsub (&endtime, &currtime, &timeout); +if (timeout.tv_sec <0 ) + timeout.tv_sec = timeout.tv_nsec =0 ; } }
@@ -320,7 +322,7 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)struct stat sb;int rc;struct io_event event; -struct timespec endtime; +struct timespec timeout = { .tv_sec = timeout_secs };if (fstat (fd, &sb) ==0 ) {LOG (4 ,"called for %x" , (unsigned ) sb.st_rdev);
@@ -345,20 +347,13 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)LOG (3 ,"io_submit error %i" , -rc);return PATH_UNCHECKED ; } -get_monotonic_time (&ct->endtime); - ct->endtime.tv_nsec +=1000 *1000 ; -normalize_timespec (&ct->endtime); ct->waited_for = false; } ct->running++;if (!sync)return PATH_PENDING ; -get_monotonic_time (&endtime); - endtime.tv_sec += timeout_secs; -normalize_timespec (&endtime); - -check_pending (ct, endtime); +check_pending (ct, timeout);if (ct->req->state !=PATH_PENDING )return ct->req->state;
@@ -401,13 +396,16 @@ int libcheck_pending(struct checker *c)int rc;struct io_event event;struct directio_context *ct = (struct directio_context *)c->context; +struct timespec no_wait = { .tv_sec =0 };/* The if path checker isn't running, just return the exiting value. */ -if (!ct || !ct->running) -return c->path_state; +if (!ct || !ct->running) { + rc = c->path_state; + goto out; + }if (ct->req->state ==PATH_PENDING ) -check_pending (ct, ct->endtime); +check_pending (ct, no_wait);else ct->running =0 ; rc = ct->req->state;
@@ -420,8 +418,9 @@ int libcheck_pending(struct checker *c)else LOG (4 ,"async io pending" ); } -set_msgid (c, rc); +out: +set_msgid (c, rc);return rc; }
libmultipath/checkers/tur.c +3 -17
@@ -58,7 +58,6 @@ struct tur_checker_context {int msgid;struct checker_context ctx;unsigned int nr_timeouts; -struct timespec endtime;bool waited_for; };
@@ -299,14 +298,6 @@ void *libcheck_thread(struct checker_context *ctx)return ((void *)0 ); } - -static void tur_timeout (struct timespec *tsp) -{ -get_monotonic_time (tsp); - tsp->tv_nsec +=1000 *1000 ;/* 1 millisecond */ -normalize_timespec (tsp); -} -static void tur_set_async_timeout (struct checker *c) {struct tur_checker_context *ct = c->context;
@@ -328,16 +319,12 @@ static int tur_check_async_timeout(struct checker *c)int check_pending (struct checker *c) {struct tur_checker_context *ct = c->context; -int r, tur_status =PATH_PENDING ; +int tur_status =PATH_PENDING ;pthread_mutex_lock (&ct->lock); -for (r =0 ; - r ==0 && ct->state ==PATH_PENDING && - ct->msgid ==MSG_TUR_RUNNING ; - r =pthread_cond_timedwait (&ct->active, &ct->lock, &ct->endtime)); - -if (!r) { +if (ct->state !=PATH_PENDING || ct->msgid !=MSG_TUR_RUNNING ) + { tur_status = ct->state; c->msgid = ct->msgid; }
@@ -487,7 +474,6 @@ int libcheck_check(struct checker * c) " sync mode", major(ct->devt), minor(ct->devt));return tur_check (c->fd, c->timeout, &c->msgid); } -tur_timeout (&ct->endtime); }return tur_status;
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 21/22 multipathd: wait for checkers to complete
In reply to Benjamin MarzinskiMultipath again waits for running checkers to complete. In pathinfo(), mutipath will just wait 1ms if the checker is running. In checkerloop(), if there are running checkers, multipathd will drop the vecs lock and wait for 5ms. The difference it wait times is because multipathd cannot drop the vecs lock in pathinfo.
--- libmultipath/discovery.c | 9 ++++++++- libmultipath/libmultipath.version | 1 + multipathd/main.c | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-)
libmultipath/discovery.c +8 -1
@@ -2467,8 +2467,15 @@ int pathinfo(struct path *pp, struct config *conf, int mask)if (mask &DI_CHECKER ) {if (path_state ==PATH_UP ) {int newstate =PATH_UNCHECKED ; -if (start_checker (pp, conf,0 , path_state) ==0 ) +if (start_checker (pp, conf,0 , path_state) ==0 ) { +if (checker_need_wait (&pp->checker)) { +struct timespec wait = { + .tv_nsec =1000 *1000 , + }; +nanosleep (&wait,NULL ); + } newstate =get_state (pp); + }if (newstate !=PATH_PENDING || pp->state ==PATH_UNCHECKED || pp->state ==PATH_WILD )
libmultipath/libmultipath.version +1 -0
@@ -62,6 +62,7 @@ global: checker_enable; checker_message; checker_name; + checker_need_wait; checker_state_name; check_foreign; cleanup_bindings;
multipathd/main.c +11 -1
@@ -2848,6 +2848,7 @@ update_uninitialized_path(struct vectors * vecs, struct path * pp)enum checker_state {CHECKER_STARTING ,CHECKER_CHECKING_PATHS , +CHECKER_WAITING_FOR_PATHS ,CHECKER_UPDATING_PATHS ,CHECKER_FINISHED , };
@@ -2859,6 +2860,7 @@ check_paths(struct vectors *vecs, unsigned int ticks)struct timespec diff_time, start_time, end_time;struct path *pp;int i; +bool need_wait = false;get_monotonic_time (&start_time);
@@ -2869,6 +2871,9 @@ check_paths(struct vectors *vecs, unsigned int ticks) pp->is_checked =check_path (pp, ticks); else pp->is_checked = check_uninitialized_path(pp, ticks); +if (pp->is_checked ==CHECK_PATH_STARTED && +checker_need_wait (&pp->checker)) + need_wait = true;if (++paths_checked %128 ==0 && (lock_has_waiters (&vecs->lock) ||waiting_clients ())) {get_monotonic_time (&end_time);
@@ -2877,7 +2882,7 @@ check_paths(struct vectors *vecs, unsigned int ticks)return CHECKER_CHECKING_PATHS ; } } -return CHECKER_UPDATING_PATHS ; +return need_wait ?CHECKER_WAITING_FOR_PATHS :CHECKER_UPDATING_PATHS ; } static enum checker_state
@@ -2999,6 +3004,11 @@ checkerloop (void *ap)if (checker_state !=CHECKER_FINISHED ) {/* Yield to waiters */ struct timespec wait = { .tv_nsec =10000 , }; +if (checker_state ==CHECKER_WAITING_FOR_PATHS ) { +/* wait 5ms */ + wait.tv_nsec =5 *1000 *1000 ; + checker_state =CHECKER_UPDATING_PATHS ; + }nanosleep (&wait,NULL ); } }
Signature · 1 line
2.45.0
Benjamin Marzinski
maintainerPATCH v2 22/22 multipath-tools tests: fix up directio tests
In reply to Benjamin MarzinskiMake the directio tests work with no waiting in the libcheck_pending() and the new libcheck_need_wait() call.
--- tests/directio.c | 49 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-)
tests/directio.c +46 -3
@@ -313,23 +313,28 @@ static void test_init_reset_init(void **state)struct checker c = {.cls =NULL };struct aio_group *aio_grp, *tmp_grp; +assert_int_equal (libcheck_need_wait (&c), false);assert_true (list_empty (&aio_grp_list));will_return (__wrap_io_setup,0 );do_libcheck_init (&c,4096 ,0 ,NULL ); +assert_int_equal (libcheck_need_wait (&c), false); aio_grp =get_aio_grp (&c);check_aio_grp (aio_grp,1 ,0 );list_for_each_entry (tmp_grp, &aio_grp_list, node)assert_ptr_equal (aio_grp, tmp_grp);libcheck_free (&c); +assert_int_equal (libcheck_need_wait (&c), false);check_aio_grp (aio_grp,0 ,0 );do_libcheck_reset (1 );will_return (__wrap_io_setup,0 );do_libcheck_init (&c,4096 ,0 ,NULL ); +assert_int_equal (libcheck_need_wait (&c), false); aio_grp =get_aio_grp (&c);check_aio_grp (aio_grp,1 ,0 );list_for_each_entry (tmp_grp, &aio_grp_list, node)assert_ptr_equal (aio_grp, tmp_grp);libcheck_free (&c); +assert_int_equal (libcheck_need_wait (&c), false);check_aio_grp (aio_grp,0 ,0 );do_libcheck_reset (1 ); }
@@ -433,6 +438,7 @@ static void test_check_state_simple(void **state)do_libcheck_init (&c,4096 ,30 , &req);return_io_getevents_nr (NULL ,1 , &req, &res);do_check_state (&c,1 ,PATH_UP ); +assert_int_equal (libcheck_need_wait (&c), false);libcheck_free (&c);do_libcheck_reset (1 ); }
@@ -465,17 +471,25 @@ static void test_check_state_async_timeout(void **state)do_libcheck_init (&c,4096 ,3 ,NULL ); aio_grp =get_aio_grp (&c);do_check_state (&c,0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), true);return_io_getevents_none ();do_libcheck_pending (&c,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);do_check_state (&c,0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);return_io_getevents_none ();do_libcheck_pending (&c,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);do_check_state (&c,0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);return_io_getevents_none ();do_libcheck_pending (&c,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);do_check_state (&c,0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);return_io_getevents_none ();do_libcheck_pending (&c,PATH_DOWN ); +assert_int_equal (libcheck_need_wait (&c), false);check_aio_grp (aio_grp,1 ,0 );libcheck_free (&c);do_libcheck_reset (1 );
@@ -496,11 +510,16 @@ static void test_free_with_pending(void **state) aio_grp =get_aio_grp (c);do_check_state (&c[0 ],0 ,PATH_PENDING );do_check_state (&c[1 ],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), true); +assert_int_equal (libcheck_need_wait (&c[1 ]), true);return_io_getevents_none ();do_libcheck_pending (&c[0 ],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false); +assert_int_equal (libcheck_need_wait (&c[1 ]), true);return_io_getevents_nr (NULL ,1 , &req, &res); -return_io_getevents_none ();do_libcheck_pending (&c[1 ],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false); +assert_int_equal (libcheck_need_wait (&c[1 ]), false);assert_true (is_checker_running (&c[0 ]));assert_true (is_checker_running (&c[1 ]));check_aio_grp (aio_grp,2 ,0 );
@@ -523,8 +542,10 @@ static void test_orphaned_aio_group(void **state)for (i =0 ; i <AIO_GROUP_SIZE ; i++) {do_libcheck_init (&c[i],4096 ,30 ,NULL );do_check_state (&c[i],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[i]), true);return_io_getevents_none ();do_libcheck_pending (&c[i],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[i]), false); } aio_grp =get_aio_grp (c);check_aio_grp (aio_grp,AIO_GROUP_SIZE ,0 );
@@ -560,15 +581,19 @@ static void test_timeout_cancel_failed(void **state) aio_grp =get_aio_grp (c);return_io_getevents_none ();do_check_state (&c[0 ],1 ,PATH_DOWN ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);assert_true (is_checker_running (&c[0 ]));check_aio_grp (aio_grp,2 ,0 );return_io_getevents_none ();do_check_state (&c[0 ],1 ,PATH_DOWN ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);assert_true (is_checker_running (&c[0 ]));return_io_getevents_nr (NULL ,1 , &reqs[0 ], &res[0 ]);return_io_getevents_nr (NULL ,1 , &reqs[1 ], &res[1 ]);do_check_state (&c[1 ],1 ,PATH_UP ); +assert_int_equal (libcheck_need_wait (&c[1 ]), false);do_check_state (&c[0 ],1 ,PATH_UP ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);for (i =0 ; i <2 ; i++) {assert_false (is_checker_running (&c[i]));libcheck_free (&c[i]);
@@ -590,11 +615,15 @@ static void test_async_timeout_cancel_failed(void **state)for (i =0 ; i <2 ; i++)do_libcheck_init (&c[i],4096 ,2 , &reqs[i]);do_check_state (&c[0 ],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), true);do_check_state (&c[1 ],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[1 ]), true);return_io_getevents_none ();do_libcheck_pending (&c[0 ],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);return_io_getevents_none ();do_libcheck_pending (&c[1 ],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[1 ]), false);do_check_state (&c[0 ],0 ,PATH_PENDING );do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_none ();
@@ -605,10 +634,12 @@ static void test_async_timeout_cancel_failed(void **state)do_check_state (&c[1 ],0 ,PATH_PENDING );return_io_getevents_none ();do_libcheck_pending (&c[0 ],PATH_DOWN ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);if (!test_dev) {/* can't pick which even gets returned on real devices */ return_io_getevents_nr (NULL ,1 , &reqs[1 ], &res[1 ]);do_libcheck_pending (&c[1 ],PATH_UP ); +assert_int_equal (libcheck_need_wait (&c[1 ]), false); }do_check_state (&c[0 ],0 ,PATH_PENDING );return_io_getevents_none ();
@@ -641,14 +672,19 @@ static void test_orphan_checker_cleanup(void **state)do_libcheck_init (&c[i],4096 ,30 , &reqs[i]); aio_grp =get_aio_grp (c);do_check_state (&c[0 ],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), true);return_io_getevents_none ();do_libcheck_pending (&c[0 ],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);check_aio_grp (aio_grp,2 ,0 );libcheck_free (&c[0 ]); +assert_int_equal (libcheck_need_wait (&c[0 ]), false);check_aio_grp (aio_grp,2 ,1 );do_check_state (&c[1 ],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[1 ]), true);return_io_getevents_nr (NULL ,2 , reqs, res);do_libcheck_pending (&c[1 ],PATH_UP ); +assert_int_equal (libcheck_need_wait (&c[1 ]), false);check_aio_grp (aio_grp,1 ,0 );libcheck_free (&c[1 ]);check_aio_grp (aio_grp,0 ,0 );
@@ -667,8 +703,10 @@ static void test_orphan_reset_cleanup(void **state)do_libcheck_init (&c,4096 ,30 ,NULL ); orphan_aio_grp =get_aio_grp (&c);do_check_state (&c,0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), true);return_io_getevents_none ();do_libcheck_pending (&c,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c), false);check_aio_grp (orphan_aio_grp,1 ,0 );libcheck_free (&c);check_aio_grp (orphan_aio_grp,1 ,1 );
@@ -704,6 +742,7 @@ static void test_check_state_blksize(void **state)for (i =0 ; i <3 ; i++) {return_io_getevents_nr (NULL ,1 , &reqs[i], &res[i]);do_check_state (&c[i],1 , chk_state[i]); +assert_int_equal (libcheck_need_wait (&c[i]), false); }for (i =0 ; i <3 ; i++) {assert_false (is_checker_running (&c[i]));
@@ -727,18 +766,22 @@ static void test_check_state_async(void **state)do_libcheck_init (&c[i],4096 ,30 , &reqs[i]);for (i =0 ; i <256 ; i++) {do_check_state (&c[i],0 ,PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[i]), true);return_io_getevents_none ();do_libcheck_pending (&c[i],PATH_PENDING ); +assert_int_equal (libcheck_need_wait (&c[i]), false);assert_true (is_checker_running (&c[i])); }do_check_state (&c[256 ],0 ,PATH_PENDING ); -return_io_getevents_nr (&full_timeout,256 , reqs, res); -return_io_getevents_nr (NULL ,1 , &reqs[256 ], &res[256 ]); +assert_int_equal (libcheck_need_wait (&c[256 ]), true); +return_io_getevents_nr (&full_timeout,257 , reqs, res);do_libcheck_pending (&c[256 ],PATH_UP ); +assert_int_equal (libcheck_need_wait (&c[256 ]), false);assert_false (is_checker_running (&c[256 ]));libcheck_free (&c[256 ]);for (i =0 ; i <256 ; i++) {do_check_state (&c[i],0 ,PATH_UP ); +assert_int_equal (libcheck_need_wait (&c[i]), false);assert_false (is_checker_running (&c[i]));libcheck_free (&c[i]); }
Signature · 1 line
2.45.0
Quoted 5 lines · Benjamin Marzinski
This patchset cleans up some of the ugly code from my last refactor, and
speeds up multipathd path checking, by refactoring how paths are checked.
I haven't started reviewing this yet, but I'm seeing a CI problem with the sysfs test, only with clang 18 on Fedora 40:
https://github.com/openSUSE/multipath-tools/actions/runs/10845899189
Martin
Benjamin Marzinski
maintainerQuoted 10 lines · Martin Wilck
Quoted 5 lines · Benjamin Marzinski
This patchset cleans up some of the ugly code from my last refactor, and
speeds up multipathd path checking, by refactoring how paths are checked.I haven't started reviewing this yet, but I'm seeing a CI problem with the sysfs test, only with clang 18 on Fedora 40:
https://github.com/openSUSE/multipath-tools/actions/runs/10845899189
I'm not sure what this is and I've been entirely unable to reproduce it using Fedora 40 and clang 18.1.8 (the current f40 version of clang). It seems pretty obvious that I has nothing to do with my patchset. It looks like it's related to the renaming open() issues. Given the
"%s() has remaining non-returned values."
and
"__wrap___open64_2: '%s' parameter still has values that haven't been checked."
messages, I'm guessing something other than __open64_2() was called. But like I said, I can't reproduce this.
-Ben
Quoted 2 lines
Martin
Quoted 10 lines · Benjamin Marzinski
I'm not sure what this is and I've been entirely unable to reproduce it
using Fedora 40 and clang 18.1.8 (the current f40 version of clang). It
seems pretty obvious that I has nothing to do with my patchset. It looks like it's related to the renamingopen()issues. Given the"%s() has remaining non-returned values."
Quoted 8 lines
and
"
__wrap___open64_2: '%s' parameter still has values that haven't been checked."messages, I'm guessing something other than
__open64_2()was called. But
like I said, I can't reproduce this.
OK, I'll double check. I don't recall seeing this before your patch set, but that can have multiple reasons.
Martin
Quoted 100 lines · Benjamin Marzinski
This patchset cleans up some of the ugly code from my last refactor, and
speeds up multipathd path checking, by refactoring how paths are checked.multipathd previously ran the checker on a path, waited briefly for it
to complete, and if it did, updated the path and the priorities for the
multipath device and possibly reloaded it.This had multiple issues.
1. All the paths waited for their checkers to complete serially. This wasted time with no benefit. It also meant that it wasn't that uncommon
for a checker to not finish in time, and get marked pending.2. The prioritiers could get run on paths multiple times during a checker loop if multiple paths were restored at the same time, which is
a common occurance.3. In an effort to keep a multipath device's state consistent despite the delays introduced by waiting for the path checkers, paths were checked by multipath device. However checking the paths could involve reloading a multipath device table, or even removing a multipath device.
This added some ugly backout and retry logic to the path check code.With this patchset, the code now first starts the path checkers on all
devices due for a path check. If there are path checkers that need waiting it then unocks the vecs lock and waits 5ms. Next, it goes back
and updates the state of all the path devices. Once all of the paths have been updated, it goes through each multipath device, updating path
priorities and reloading the device as necessary.This allows multipathd to spend less time and do less redundant work while checking paths, while making paths more likely to not spend a checker cycle marked as pending. Since multipathd drops the vecs lock while waiting, uevents and user commands can be processed while its waiting.
Since there isn't a delay waiting for the previous checker before starting the next one, the path checker code has reverted to checking all paths in pathvec order, instead of by multipath device. Updating the
paths in pathvec order simplifies the code, since the multipath devices
can change during path updates. Starting the checkers in pathvec order
keeps a path from having its checker started towards the end of the list
of paths but checking for the result towards the start of the list of paths.Changes since v1:
The original patches have been updated based on suggestions from Martin
Wilck (patches listed using their original numbering):- Moved checker
path_stateinitialization code from 06 to 01
- Check for NULL before dereference inchecker_get_state()in 04
- Moved addingstart_checkerto version file from 07 to 06
- Renamedcheck_path_state()toget_new_state()in 08. updated 09, 11,
and 12 to deal with the name change.
- Added new patch before 13 ('fix "fail path" and "reinstate path" commands') to fix issues with manually failing and reinstating paths
between when the checkers are run and the paths are updated
- Fixed check inupdate_pathsin 13
- Split patch 13 into three patches, one to move priority updating out
of the individual path updating code, and two others to clean up some
of the logic about updating priorities and path groups.After the now 18 patches from the original patchset, four new patches have been added to move the waiting for pending paths out from
checker_get_state()and into the existing waiting code incheckerloop().
Doing the waiting outside of the checkers (in fact, outside of the vecs lock completely) means that we can't wait till a checker has completed. We must just pick a time and wait for all of it. On Martin's
suggestion I picked 5ms. Since multipathd isn't sleeping with the vecs
lock held, it's much less critical to do this quickly.For checker run in pathinfo, I kept the previous timeout of 1ms, but I
waffled on whether to wait at all here, and I'd be perfectly fine with
removing the wait altogether, and just let the paths be pending when called from multipathd with async checkers.
Quoted 7 lines
Also, I've just added these patches to the end of the patchset to make
it easier to see the changes from v1, but if people want less churn in
the checker code commits, I'd be find with resending this patchset with
these patches refactored into the earlier patches.
Except for the few minor nits in my previous replies: