libmpathpersist: fix code for skipping multipathd path registration
Benjamin Marzinski
maintainerPATCH v3 1/1 libmpathpersist: fix code for skipping multipathd path registration
When libmpathpersist notifies multipathd that a key has been registered, cli_setprstatus() calls pr_register_active_paths() with a flag to let it know that the paths are likely already registered, and it can skip re-registering them, as long as the number of active paths matches the number of registered keys. This shortcut can fail, causing multipathd to not register needed paths, if either a path becomes usable and another becomes unusable while libmpathpersist is running or if there already were registered keys for I_T Nexus's that don't correspond to path devices.
To make this shortcut work in cases like that, this commit adds a new multipathd command "setprstatus map <map> pathlist <pathlist>", where <pathlist> is a quoted, whitespace separated list of scsi path devices. libmpathpersist will send out the list of paths it registered the key on. pr_register_active_paths() will skip calling mpath_pr_event_handle() for paths on that list.
In order to deal with the possiblity of a preempt occuring while libmpathpersist was running, the code still needs to check that it has the expected number of keys.
---
Changes in v3:
- make pathlist in be a list of dev_t devices in update_prflag() and pr_register_active_paths()
- Add automatic cleanup for the registered_paths vector in cli_setprstatus_list() using cleanup_reset_vec()
- fixed formatting issues.
Changes in v2:
- added a semi-colon after the "skip" label to make clang happy.
v1 was patch 4/4 of "multipath-tools: Yet Another PR fix"
libmpathpersist/mpath_persist_int.c | 6 +-- libmpathpersist/mpath_updatepr.c | 47 ++++++++++++++++----- libmpathpersist/mpathpr.h | 4 +- multipathd/callbacks.c | 2 + multipathd/cli.c | 1 + multipathd/cli.h | 2 + multipathd/cli_handlers.c | 35 ++++++++++++++-- multipathd/main.c | 63 +++++++++++++++++++---------- multipathd/main.h | 4 +- multipathd/multipathd.8.in | 6 +++ 10 files changed, 129 insertions(+), 41 deletions(-)
libmpathpersist/mpath_persist_int.c +3 -3
@@ -1001,12 +1001,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,case MPATH_PROUT_REG_SA :case MPATH_PROUT_REG_IGN_SA :if (unregistering) -update_prflag (mpp->alias,0 ); +update_prflag (mpp,0 );else -update_prflag (mpp->alias,1 ); +update_prflag (mpp,1 );break ;case MPATH_PROUT_CLEAR_SA : -update_prflag (mpp->alias,0 ); +update_prflag (mpp,0 );if (mpp->prkey_source ==PRKEY_SOURCE_FILE )update_prkey (mpp->alias,0 );break ;
libmpathpersist/mpath_updatepr.c +36 -11
77 lines not on this page · raw message
libmpathpersist/mpathpr.h +3 -1
@@ -1,12 +1,14 @@#ifndef MPATHPR_H_INCLUDED #define MPATHPR_H_INCLUDED +#include "structs.h" +/* * This header file contains symbols that are only used by * libmpathpersist internally. */ -int update_prflag (char *mapname,int set); +int update_prflag (struct multipath *mpp,int set);int update_prkey_flags (char *mapname,uint64_t prkey,uint8_t sa_flags);int get_prflag (char *mapname);int get_prhold (char *mapname);
multipathd/callbacks.c +2 -0
@@ -59,6 +59,8 @@ void init_handler_callbacks(void)set_unlocked_handler_callback (VRB_SHUTDOWN ,HANDLER (cli_shutdown));set_handler_callback (VRB_GETPRSTATUS |Q1_MAP ,HANDLER (cli_getprstatus));set_handler_callback (VRB_SETPRSTATUS |Q1_MAP ,HANDLER (cli_setprstatus)); +set_handler_callback (VRB_SETPRSTATUS |Q1_MAP |Q2_PATHLIST , +HANDLER (cli_setprstatus_list));set_handler_callback (VRB_UNSETPRSTATUS |Q1_MAP ,HANDLER (cli_unsetprstatus));set_handler_callback (VRB_FORCEQ |Q1_DAEMON ,HANDLER (cli_force_no_daemon_q));set_handler_callback (VRB_RESTOREQ |Q1_DAEMON ,HANDLER (cli_restore_no_daemon_q));
multipathd/cli.c +1 -0
@@ -227,6 +227,7 @@ load_keys (void) r +=add_key (keys,"getprhold" ,VRB_GETPRHOLD ,0 ); r +=add_key (keys,"setprhold" ,VRB_SETPRHOLD ,0 ); r +=add_key (keys,"unsetprhold" ,VRB_UNSETPRHOLD ,0 ); + r +=add_key (keys,"pathlist" ,KEY_PATHLIST ,1 );if (r) {free_keys (keys);
multipathd/cli.h +2 -0
@@ -62,6 +62,7 @@ enum {KEY_LOCAL =81 ,KEY_GROUP =82 ,KEY_KEY =83 , + KEY_PATHLIST = 84, };/*
@@ -94,6 +95,7 @@ enum {Q2_LOCAL =KEY_LOCAL <<16 ,Q2_GROUP =KEY_GROUP <<16 ,Q2_KEY =KEY_KEY <<16 , +Q2_PATHLIST =KEY_PATHLIST <<16 ,/* byte 3: qualifier 3 */ Q3_FMT = KEY_FMT << 24,
multipathd/cli_handlers.c +32 -3
@@ -31,6 +31,7 @@#include "foreign.h" #include "strbuf.h" #include "cli_handlers.h" +#include <ctype.h> static struct path * find_path_by_str(const struct vector_s *pathvec, const char *str,
@@ -1276,8 +1277,8 @@ cli_getprstatus (void * v, struct strbuf *reply, void * data)return 0 ; } -static int -cli_setprstatus (void * v,struct strbuf *reply,void * data) +static int do_setprstatus (void *v,struct strbuf *reply,void *data, +const struct vector_s *registered_paths) {struct multipath * mpp;struct vectors * vecs = (struct vectors *)data;
@@ -1291,7 +1292,7 @@ cli_setprstatus(void * v, struct strbuf *reply, void * data)if (mpp->prflag !=PR_SET ) {set_pr (mpp); -pr_register_active_paths (mpp, true); +pr_register_active_paths (mpp, registered_paths);if (mpp->prflag ==PR_SET )condlog (2 ,"%s: prflag set" , param);else
@@ -1302,6 +1303,34 @@ cli_setprstatus(void * v, struct strbuf *reply, void * data)return 0 ; } +static int cli_setprstatus (void *v,struct strbuf *reply,void *data) +{ +return do_setprstatus (v, reply, data,NULL ); +} + +static int cli_setprstatus_list (void *v,struct strbuf *reply,void *data) +{ +int r; +struct vector_s registered_paths_vec = {.allocated =0 }; + vector registered_paths + __attribute__((cleanup(cleanup_reset_vec))) = ®istered_paths_vec; +char *ptr =get_keyparam (v,KEY_PATHLIST ); + +while (isspace (*ptr)) + ptr++; +while (*ptr) { +if (!vector_alloc_slot (registered_paths)) +return -ENOMEM ; +vector_set_slot (registered_paths, ptr); +while (*ptr && !isspace (*ptr)) + ptr++; +while (isspace (*ptr)) + *ptr++ ='\0' ; + } + r =do_setprstatus (v, reply, data, registered_paths); +return r; +} +static int cli_unsetprstatus (void * v,struct strbuf *reply,void * data) {
multipathd/main.c +41 -22
120 lines not on this page · raw message
multipathd/main.h +3 -1
@@ -54,5 +54,7 @@ int resize_map(struct multipath *mpp, unsigned long long size, struct vectors *vecs);void set_pr (struct multipath *mpp);void unset_pr (struct multipath *mpp); -void pr_register_active_paths (struct multipath *mpp,bool check_active_nr); +void pr_register_active_paths (struct multipath *mpp, +const struct vector_s *registered_paths); +void cleanup_reset_vec (struct vector_s **v);#endif /* MAIN_H_INCLUDED */
multipathd/multipathd.8.in +6 -0
@@ -348,6 +348,12 @@ Restores configured queue_without_daemon mode. Enable persistent reservation management on $map. . .TP +.B setprstatus map|multipath $map pathlist $pathlist +Enable persistent reservation management on $map, and notify multipathd of +the paths that have been registered, so it doesn't attempt to re-register +them. +. +.TP .B unsetprstatus map|multipath $map Disable persistent reservation management on $map. .
Signature · 1 line
2.50.1
Quoted 24 lines · Benjamin Marzinski
When libmpathpersist notifies multipathd that a key has been registered,
cli_setprstatus()callspr_register_active_paths()with a flag to let it
know that the paths are likely already registered, and it can skip re-registering them, as long as the number of active paths matches the
number of registered keys. This shortcut can fail, causing multipathd to
not register needed paths, if either a path becomes usable and another
becomes unusable while libmpathpersist is running or if there already were registered keys forI_TNexus's that don't correspond to path devices.To make this shortcut work in cases like that, this commit adds a new multipathd command "setprstatus map <map> pathlist <pathlist>", where <pathlist> is a quoted, whitespace separated list of scsi path devices.
libmpathpersist will send out the list of paths it registered the key on.pr_register_active_paths()will skip callingmpath_pr_event_handle()
for paths on that list.
Quoted 7 lines
In order to deal with the possiblity of a preempt occuring while libmpathpersist was running, the code still needs to check that it has
the expected number of keys.Fixes f7d6cd17 ("multipathd: Fix race while registering PR key")Signed-off-by Benjamin Marzinski <[email protected]>
Git clang-format applied a few minor changes, and I needed to add a spelling exception. I'll apply to my queue branch with these changes.