Multiple mpathpersist improvements
Benjamin Marzinski
maintainerv2 cover Multiple mpathpersist improvements
The mpathpersist code has many areas where it does a poor job of mimicking the behavior of setting up persistent reservations on an individual device, especially if paths to the multipath device are missing or unusable. This patchset is aimed at fixing a number of them. It is a combination of my two previous patchsets:
[PATCH 00/15] Improve mpathpersist's unavailable path handling and
[PATCH 00/14] Additional fixes and cleanups
along with additional patches.
Issues handled by the patchset are:
- Changing or unregistering a key held by an unavailable path that also holds the reservation. This is done by preempting the old key (after verifying that the multipath device is holding the reservation)
- Releasing a reservation held by an unavailable path. This has always had code to handle it, but it relied on optional Persistent Reservation features. The new code preempts the key and then restores the removed registered keys (while the device is suspended).
- Handling removal of keys from paths that were down when the multipath device was unregistered.
- Changing how conflicts on key registration are handled. Instead of the current rollback method (which was broken anyways), libmpathpersist now retries with REGISTER AND IGNORE as long as the REGISTER command completed successfully down some of the paths.
- Changing when the reservation key is set to fix corner cases on failure and registration while paths are coming up.
- Retrying on conflicts in mpath_prout_common to fix corner cases when a path is coming up while a doing a reserve, preempt or clear.
- Allowing registrations to succeed when there are retryable errors, if the paths are actually down.
- Fixing the reservation key validation code
Changes in V2:
First set (as suggested by Martin Wilck)
0009: Added a comment explaining the select_skip_kpartx() 0010: use all_threads_fail variable instead of rc.
Second set
0003 (now 0018): Remove noisy variable from update_map_pr 0007 (new 0022): Added comment explaining why we won't fail syntax error
checks after updating the reservation key, as suggested by Martin Wilck (for patch 0012, but it made more sense to change it here)
0030 new patch to not attempt workaround when a release fails due to a
mismatched type.
0031 new patch to fix an issue with issuing a RESERVE command to the
path that doesn't hold the reservation.
0032 new patch to fix an issue with a multipath device preempting its
own reservation key.
Benjamin Marzinski (32):
multipathd: remove thread from mpath_pr_event_handle
libmpathpersist: remove uneeded wrapper function.
libmpathpersist: reduce log level for persistent reservation checking
libmpathpersist: remove pointless update_map_pr ret value code
multipathd: use update_map_pr in mpath_pr_event_handle
libmpathpersist: limit changing prflag in update_map_pr
multipathd: Don't call update_map_pr unnecessarily
libmpathpersist: remove useless function send_prout_activepath
libmpathpersist: redesign failed release workaround
libmpathpersist: fail the release if all threads fail
libmpathpersist: Handle changing key corner case
libmpathpersist: Handle REGISTER AND IGNORE changing key corner case
libmultipath: rename prflag_value enums
libmpathpersist: use a switch statement for prout command finalizing
libmpathpersist: Add safety check for preempting on key change
libmpathpersist: remove update_map_pr code for NULL pp
libmpathpersist: move update_map_pr to multipathd
multipathd: clean up update_map_pr and mpath_pr_event_handle
libmpathpersist: clean up duplicate function declarations
multipathd: wrap setting and unsetting prflag
multipathd: unregister PR key when path is restored if necessary
libmpathpersist: Fix-up reservation_key checking
libmpathpersist: change how reservation conflicts are handled
libmpathpersist: Clear prkey in multipathd before unregistering
libmpathpersist: only clear the key if we are using the prkeys file
libmpathpersist: Restore old reservation key on failure
libmpathpersist: update reservation key before checking paths
libmpathpersist: retry on conflicts in mpath_prout_common
libmpathpersist: Don't always fail registrations for retryable errors
libmpathpersist: Don't try release workaround for invalid type
libmpathpersist: Don't fail RESERVE commands unnecessarily
libmpathpersist: reregister keys when self preempting
libmpathpersist/libmpathpersist.version | 3 +- libmpathpersist/mpath_persist_int.c | 817 ++++++++++++++---------- libmpathpersist/mpath_persist_int.h | 4 +- libmpathpersist/mpath_pr_ioctl.c | 12 +- libmpathpersist/mpath_updatepr.c | 74 ++- libmpathpersist/mpathpr.h | 3 + libmultipath/libmultipath.version | 1 + libmultipath/structs.h | 12 +- mpathpersist/main.c | 2 - multipathd/callbacks.c | 3 + multipathd/cli.c | 4 +- multipathd/cli.h | 3 + multipathd/cli_handlers.c | 66 +- multipathd/main.c | 237 ++++--- multipathd/main.h | 2 + 15 files changed, 755 insertions(+), 488 deletions(-)
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 1/32 multipathd: remove thread from mpath_pr_event_handle
mpath_pr_event_handle() creates a separate thread to do the persistent reservation work, but it doesn't take any advantage of the work being done in another thread. Merge mpath_pr_event_handle() and mpath_pr_event_handler_fn() into a single function with no separate thread.
--- multipathd/main.c | 50 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 39 deletions(-)
multipathd/main.c +11 -39
@@ -89,8 +89,7 @@#define CMDSIZE 160#define MSG_SIZE 32 -int mpath_pr_event_handle (struct path *pp); -void *mpath_pr_event_handler_fn (void * ); +static void mpath_pr_event_handle (struct path *pp);#define LOG_MSG (lvl, pp) \ do { \
@@ -4229,17 +4228,24 @@ main (int argc, char *argv[])return (child (NULL )); } -void *mpath_pr_event_handler_fn (void * pathp ) +static void mpath_pr_event_handle (struct path *pp) {struct multipath * mpp;unsigned int i;int ret, isFound; -struct path * pp = (struct path *)pathp;struct prout_param_descriptor *param;struct prin_resp *resp; -rcu_register_thread (); mpp = pp->mpp; +if (pp->bus !=SYSFS_BUS_SCSI ) { + mpp->prflag =PRFLAG_UNSET ; +return ; + } + +if (!get_be64 (mpp->reservation_key)) { + mpp->prflag =PRFLAG_UNSET ; +return ; + } resp =mpath_alloc_prin_response (MPATH_PRIN_RKEY_SA );if (!resp){
@@ -4306,38 +4312,4 @@ void * mpath_pr_event_handler_fn (void * pathp ) out:if (resp)free (resp); -rcu_unregister_thread (); -return NULL ; -} - -int mpath_pr_event_handle (struct path *pp) -{ -pthread_t thread; -int rc; -pthread_attr_t attr; -struct multipath * mpp; - -if (pp->bus !=SYSFS_BUS_SCSI ) - goto no_pr; - - mpp = pp->mpp; - -if (!get_be64 (mpp->reservation_key)) - goto no_pr; - -pthread_attr_init (&attr); -pthread_attr_setdetachstate (&attr,PTHREAD_CREATE_JOINABLE ); - - rc =pthread_create (&thread,NULL , mpath_pr_event_handler_fn, pp); -if (rc) { -condlog (0 ,"%s: ERROR; return code from pthread_create() is %d" , pp->dev, rc); -return -1 ; - } -pthread_attr_destroy (&attr); - rc =pthread_join (thread,NULL ); -return 0 ; - -no_pr: - pp->mpp->prflag =PRFLAG_UNSET ; -return 0 ; }
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 2/32 libmpathpersist: remove uneeded wrapper function.
In reply to Benjamin Marzinskimpath_send_prin_activepath() just calls prin_do_scsi_ioctl() with exactly the same arguments that it is passed, and returns the same return. remove it.
--- libmpathpersist/mpath_persist_int.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
libmpathpersist/mpath_persist_int.c +1 -13
@@ -49,17 +49,6 @@ struct threadinfo {struct prout_param param; }; -static int mpath_send_prin_activepath (char * dev,int rq_servact, -struct prin_resp * resp,int noisy) -{ - -int rc; - - rc =prin_do_scsi_ioctl (dev, rq_servact, resp, noisy); - -return (rc); -} -static int mpath_prin_activepath (struct multipath *mpp,int rq_servact,struct prin_resp * resp,int noisy) {
@@ -80,8 +69,7 @@ static int mpath_prin_activepath (struct multipath *mpp, int rq_servact,condlog (3 ,"%s: sending pr in command to %s " , mpp->wwid, pp->dev); - ret =mpath_send_prin_activepath (pp->dev, rq_servact, - resp, noisy); + ret =prin_do_scsi_ioctl (pp->dev, rq_servact, resp, noisy);switch (ret) {case MPATH_PR_SUCCESS :
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 3/32 libmpathpersist: reduce log level for persistent reservation checking
In reply to Benjamin MarzinskiMove logging of minor expected behavior to INFO level. Modify the log level of some messages by whether or not mpp->prflag changed values.
--- libmpathpersist/mpath_persist_int.c | 34 +++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-)
libmpathpersist/mpath_persist_int.c +22 -12
@@ -60,7 +60,7 @@ static int mpath_prin_activepath (struct multipath *mpp, int rq_servact, vector_foreach_slot (pgp->paths, pp, i){if (!((pp->state ==PATH_UP ) || (pp->state ==PATH_GHOST ))){ -condlog (2 ,"%s: %s not available. Skip." , +condlog (3 ,"%s: %s not available. Skip." , mpp->wwid, pp->dev);condlog (3 ,"%s: status = %d." , mpp->wwid, pp->state);
@@ -725,12 +725,14 @@ int update_map_pr(struct multipath *mpp)struct prin_resp *resp;unsigned int i;int ret =MPATH_PR_OTHER , isFound; +bool was_set = (mpp->prflag ==PRFLAG_SET );if (!get_be64 (mpp->reservation_key)) {/* Nothing to do. Assuming pr mgmt feature is disabled*/ mpp->prflag =PRFLAG_UNSET ; -condlog (4 ,"%s: reservation_key not set in multipath.conf" , +condlog (was_set ?2 :4 , +"%s: reservation_key not set in multipath.conf" , mpp->alias);return MPATH_PR_SUCCESS ; }
@@ -743,8 +745,7 @@ int update_map_pr(struct multipath *mpp) }if (count_active_paths (mpp) ==0 ) { -condlog (0 ,"%s: No available paths to check pr status" , - mpp->alias); +condlog (2 ,"%s: No available paths to check pr status" , mpp->alias); goto out; } mpp->prflag =PRFLAG_UNSET ;
@@ -760,22 +761,31 @@ int update_map_pr(struct multipath *mpp)if (resp->prin_descriptor.prin_readkeys.additional_length ==0 ) { -condlog (3 ,"%s: No key found. Device may not be registered. " , mpp->alias); +condlog (was_set ?1 :3 , +"%s: No key found. Device may not be registered. " , + mpp->alias); goto out; } -condlog (2 ,"%s: Multipath reservation_key: 0x%" PRIx64" " , mpp->alias, +condlog (3 ,"%s: Multipath reservation_key: 0x%" PRIx64" " , mpp->alias,get_be64 (mpp->reservation_key)); isFound =0 ;for (i =0 ; i < resp->prin_descriptor.prin_readkeys.additional_length/8 ; i++ ) { -condlog (2 ,"%s: PR IN READKEYS[%d] reservation key:" , mpp->alias, i); -dumpHex ((char *)&resp->prin_descriptor.prin_readkeys.key_list[i*8 ],8 ,1 ); +if (libmp_verbosity >=3 ) { +condlog (3 ,"%s: PR IN READKEYS[%d] reservation key:" , + mpp->alias, i); +dumpHex ((char *)&resp->prin_descriptor.prin_readkeys + .key_list[i *8 ], +8 ,1 ); + } -if (!memcmp (&mpp->reservation_key, &resp->prin_descriptor.prin_readkeys.key_list[i*8 ],8 )) - { -condlog (2 ,"%s: reservation key found in pr in readkeys response" , mpp->alias); +if (!memcmp (&mpp->reservation_key, + &resp->prin_descriptor.prin_readkeys.key_list[i *8 ], +8 )) { +condlog (3 ,"%s: reservation key found in pr in readkeys response" , + mpp->alias); isFound =1 ; } }
@@ -783,7 +793,7 @@ int update_map_pr(struct multipath *mpp)if (isFound) { mpp->prflag =PRFLAG_SET ; -condlog (2 ,"%s: prflag flag set." , mpp->alias ); +condlog (was_set ?3 :2 ,"%s: prflag flag set." , mpp->alias); } out:
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 4/32 libmpathpersist: remove pointless update_map_pr ret value code
In reply to Benjamin MarzinskiDon't set ret to MPATH_PR_SUCCESS, after the code just made sure that it was already set to MPATH_PR_SUCCESS.
--- libmpathpersist/mpath_persist_int.c | 2 -- 1 file changed, 2 deletions(-)
libmpathpersist/mpath_persist_int.c +0 -2
@@ -757,8 +757,6 @@ int update_map_pr(struct multipath *mpp) goto out; } - ret =MPATH_PR_SUCCESS ; -if (resp->prin_descriptor.prin_readkeys.additional_length ==0 ) { condlog(was_set ? 1 : 3,
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 5/32 multipathd: use update_map_pr in mpath_pr_event_handle
In reply to Benjamin MarzinskiClean up the duplicate code in mpath_pr_event_handle() and update_map_pr() by making update_map_pr() take an optional path device to use for its check, instead of checking all path devices and make mpath_pr_event_handle() call update_map_pr() to do its checking.
--- libmpathpersist/libmpathpersist.version | 2 +- libmpathpersist/mpath_persist_int.c | 18 ++++--- libmpathpersist/mpath_persist_int.h | 2 +- multipathd/main.c | 68 ++++--------------------- 4 files changed, 22 insertions(+), 68 deletions(-)
libmpathpersist/libmpathpersist.version +1 -1
@@ -34,7 +34,7 @@ global: mpath_persistent_reserve_out__; } LIBMPATHPERSIST_2.1.0; -__LIBMPATHPERSIST_INT_1.1.0 { +__LIBMPATHPERSIST_INT_2.0.0 { /* Internal use by multipath-tools */ dumpHex; mpath_alloc_prin_response;
libmpathpersist/mpath_persist_int.c +11 -7
@@ -719,7 +719,7 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,return ret; } -int update_map_pr (struct multipath *mpp) +int update_map_pr (struct multipath *mpp,struct path *pp) {int noisy=0 ;struct prin_resp *resp;
@@ -734,7 +734,7 @@ int update_map_pr(struct multipath *mpp)condlog (was_set ?2 :4 ,"%s: reservation_key not set in multipath.conf" , mpp->alias); -return MPATH_PR_SUCCESS ; +return MPATH_PR_SKIP ; } resp =mpath_alloc_prin_response (MPATH_PRIN_RKEY_SA );
@@ -743,13 +743,15 @@ int update_map_pr(struct multipath *mpp)condlog (0 ,"%s : failed to alloc resp in update_map_pr" , mpp->alias);return MPATH_PR_OTHER ; } -if (count_active_paths (mpp) ==0 ) - { +if (!pp &&count_active_paths (mpp) ==0 ) {condlog (2 ,"%s: No available paths to check pr status" , mpp->alias); goto out; } mpp->prflag =PRFLAG_UNSET ; - ret =mpath_prin_activepath (mpp,MPATH_PRIN_RKEY_SA , resp, noisy); +if (pp) + ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , resp, noisy); +else + ret =mpath_prin_activepath (mpp,MPATH_PRIN_RKEY_SA , resp, noisy);if (ret !=MPATH_PR_SUCCESS ) {
@@ -791,8 +793,10 @@ int update_map_pr(struct multipath *mpp)if (isFound) { mpp->prflag =PRFLAG_SET ; -condlog (was_set ?3 :2 ,"%s: prflag flag set." , mpp->alias); - } +condlog (was_set ?3 :2 ,"%s: key found. prflag set." , mpp->alias); + }else +condlog (was_set ?1 :3 ,"%s: key not found. prflag unset." , + mpp->alias); out:free (resp);
libmpathpersist/mpath_persist_int.h +1 -1
@@ -20,6 +20,6 @@ int prin_do_scsi_ioctl(char * dev, int rq_servact, struct prin_resp * resp, intint prout_do_scsi_ioctl (char * dev,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor *paramp,int noisy);void dumpHex (const char * ,int len,int no_ascii); -int update_map_pr (struct multipath *mpp); +int update_map_pr (struct multipath *mpp,struct path *pp);#endif /* MPATH_PERSIST_INT_H_INCLUDED */
multipathd/main.c +9 -59
110 lines not on this page · raw message
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 6/32 libmpathpersist: limit changing prflag in update_map_pr
In reply to Benjamin MarzinskiDo not unset mpp->prflag in update_map_pr() unless the device doesn't support persistent reservations or it successfully reads the registered keys and discovers that the device's key is not there. Also, nothing in the libmpathpersist ever returns MPATH_PR_SENSE_INVALID_OP. It instead returns MPATH_PR_ILLEGAL_REQ if the device doesn't support persistent reservations, so check for that instead.
Also, do not even check for the registered keys in update_map_pr() if mpp->prflag is unset. Otherwise, multipathd will set mpp->prflag if the key was unregistered (and thus prflag was unset) while a path is down (and thus could not have its key unregistered) and then that path comes back up. I should note that the above issue can only occur if multipath is defining PR keys in /etc/multipath.conf, instead of the prkeys file.
If a device has no registered keys, it must unset prflag, since that means it's no longer registered. Possibly its registration was removed by a CLEAR or PREEMPT action. But if a device has a registered key but it is supposed to be unregistered, it should remain unregistered, since that key is likely one that libmpathpersist could not unregister at the time.
--- libmpathpersist/mpath_persist_int.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
libmpathpersist/mpath_persist_int.c +8 -2
@@ -73,7 +73,7 @@ static int mpath_prin_activepath (struct multipath *mpp, int rq_servact,switch (ret) {case MPATH_PR_SUCCESS : -case MPATH_PR_SENSE_INVALID_OP : +case MPATH_PR_ILLEGAL_REQ :return ret;default :continue ;
@@ -727,6 +727,10 @@ int update_map_pr(struct multipath *mpp, struct path *pp)int ret =MPATH_PR_OTHER , isFound;bool was_set = (mpp->prflag ==PRFLAG_SET ); +/* If pr is explicitly unset, it must be manually set */ +if (mpp->prflag ==PRFLAG_UNSET ) +return MPATH_PR_SKIP ; +if (!get_be64 (mpp->reservation_key)) {/* Nothing to do. Assuming pr mgmt feature is disabled*/
@@ -747,7 +751,6 @@ int update_map_pr(struct multipath *mpp, struct path *pp)condlog (2 ,"%s: No available paths to check pr status" , mpp->alias); goto out; } - mpp->prflag =PRFLAG_UNSET ;if (pp) ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , resp, noisy);else
@@ -755,9 +758,12 @@ int update_map_pr(struct multipath *mpp, struct path *pp)if (ret !=MPATH_PR_SUCCESS ) { +if (ret ==MPATH_PR_ILLEGAL_REQ ) + mpp->prflag =PRFLAG_UNSET ;condlog (0 ,"%s : pr in read keys service action failed Error=%d" , mpp->alias, ret); goto out; } + mpp->prflag =PRFLAG_UNSET ;if (resp->prin_descriptor.prin_readkeys.additional_length ==0 ) {
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 7/32 multipathd: Don't call update_map_pr unnecessarily
In reply to Benjamin MarzinskiNone of the calls to update_map_pr() outside of mpath_pr_event_handle() add any benefit. When update_map_pr() is called without a path, it tries to read the pr keys list on each usable path until it succeeds, and then checks the keys to see if they include the configured key.
In all cases where update_map_pr() is called outside of mpath_pr_event_handle(), after it is called, pr_register_active_paths() is called if a matching key was found. pr_register_active_paths() calls mpath_pr_event_handle() on each usable path, which calls update_map_pr() with a path, so it only checks that path. If a matching key is found, it registers a key on the current path. The result is that after pr_register_active_paths() is called, update_map_pr() will be called for each usable path, just like update_map_pr() did. So calling update_map_pr() first doesn't change the results for multipathd, it just adds duplicate work, so remove those calls.
--- multipathd/main.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
multipathd/main.c +7 -11
@@ -637,6 +637,8 @@ pr_register_active_paths(struct multipath *mpp) vector_foreach_slot (mpp->pg, pgp, i) { vector_foreach_slot (pgp->paths, pp, j) { +if (mpp->prflag ==PRFLAG_UNSET ) +return ;if ((pp->state ==PATH_UP ) || (pp->state ==PATH_GHOST ))mpath_pr_event_handle (pp); }
@@ -726,10 +728,7 @@ fail:sync_map_state (mpp, false); -if (mpp->prflag !=PRFLAG_SET ) -update_map_pr (mpp,NULL ); -if (mpp->prflag ==PRFLAG_SET ) -pr_register_active_paths (mpp); +pr_register_active_paths (mpp);if (VECTOR_SIZE (offline_paths) !=0 )handle_orphaned_offline_paths (offline_paths);
@@ -1402,10 +1401,9 @@ rescan:sync_map_state (mpp, false);if (retries >=0 ) { -if (start_waiter) -update_map_pr (mpp,NULL ); -if (mpp->prflag ==PRFLAG_SET && prflag !=PRFLAG_SET ) -pr_register_active_paths (mpp); +if ((mpp->prflag ==PRFLAG_SET && prflag !=PRFLAG_SET ) || + start_waiter) +pr_register_active_paths (mpp);condlog (2 ,"%s [%s]: path added to devmap %s" , pp->dev, pp->dev_t, mpp->alias);return 0 ;
@@ -3312,9 +3310,7 @@ configure (struct vectors * vecs, enum force_reload_types reload_type) vector_foreach_slot(mpvec, mpp, i){if (remember_wwid (mpp->wwid) ==1 )trigger_paths_udev_change (mpp, true); -update_map_pr (mpp,NULL ); -if (mpp->prflag ==PRFLAG_SET ) -pr_register_active_paths (mpp); +pr_register_active_paths (mpp); }/*
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 8/32 libmpathpersist: remove useless function send_prout_activepath
In reply to Benjamin Marzinskisend_prout_activepath() creates a single separate thread that just calls prout_do_scsi_ioctl() and it doesn't take any advantage of the work being done in another thread. Remove the function and call prout_do_scsi_ioctl() directly.
--- libmpathpersist/mpath_persist_int.c | 39 ++--------------------------- 1 file changed, 2 insertions(+), 37 deletions(-)
libmpathpersist/mpath_persist_int.c +2 -37
@@ -363,40 +363,6 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; } -static int send_prout_activepath (char *dev,int rq_servact,int rq_scope, -unsigned int rq_type, -struct prout_param_descriptor * paramp,int noisy) -{ -struct prout_param param; - param.rq_servact = rq_servact; - param.rq_scope = rq_scope; - param.rq_type = rq_type; - param.paramp = paramp; - param.noisy = noisy; - param.status =-1 ; - -pthread_t thread; -pthread_attr_t attr; -int rc; - -memset (&thread,0 ,sizeof (thread)); -strlcpy (param.dev, dev,FILE_NAME_SIZE ); -/* Initialize and set thread joinable attribute */ -pthread_attr_init (&attr); -pthread_attr_setdetachstate (&attr,PTHREAD_CREATE_JOINABLE ); - - rc =pthread_create (&thread, &attr, mpath_prout_pthread_fn, (void *)(¶m)); -if (rc){ -condlog (3 ,"%s: failed to create thread %d" , dev, rc); -return MPATH_PR_THREAD_ERROR ; - } -/* Free attribute and wait for the other threads */ -pthread_attr_destroy (&attr); - rc =pthread_join (thread,NULL ); - -return (param.status); -} -static int mpath_prout_common (struct multipath *mpp,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor * paramp,int noisy)
@@ -416,9 +382,8 @@ static int mpath_prout_common(struct multipath *mpp,int rq_servact, int rq_scopecondlog (3 ,"%s: sending pr out command to %s" , mpp->wwid, pp->dev); found = true; - ret =send_prout_activepath (pp->dev, rq_servact, - rq_scope, rq_type, - paramp, noisy); + ret =prout_do_scsi_ioctl (pp->dev, rq_servact, rq_scope, + rq_type, paramp, noisy);if (ret !=MPATH_PR_RETRYABLE_ERROR )return ret; }
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 9/32 libmpathpersist: redesign failed release workaround
In reply to Benjamin MarzinskiThe workaround for releasing a reservation held by a failed path (clearing all persistent reservation data and then reregistering all the keys) has several problems. It requires devices that support the READ FULL STATUS command and are capable of specifying TransportIDs with REGISTRATION commands (SIP_C), neither of which are mandatory to support SCSI Persistent Reservations. Non SIP_C devices will be left with no registered keys. Also, not all cleared keys are registered, just the ones going to the Target Port receiving the REGISTRATION command. To reregister all the keys, the code would have to also use the "All Target Ports" flag to register keys on different Target Ports, but this could end up registering keys on paths they aren't supposed to be on (for instance if one of the registered keys was only there because the path was down and it couldn't be released).
The redesign avoids these issues by only using mandatory Persistent Reservation commands, without extra optional parameters or flags, and only effects the keys of the multipath device it is being issued on. The new workaround is:
1. Suspend the multipath device to prevent I/O
2. Preempt the key to move the reservation to an available path. This also removes the registered keys from every path except the path issuing the PREEMPT command. Since the device is suspended, not I/O can go to these unregisted paths and fail.
3. Release the reservation on the path that now holds it.
4. Resume the device (since it no longer matters that most of the paths no longer have a registered key)
5. Reregister the keys on all the paths.
If steps 3 or 4 fail, the code will attempt to reregister the keys, and then attempt (or possibly re-attempt) the resume.
--- libmpathpersist/mpath_persist_int.c | 182 +++++++++++++--------------- libmultipath/libmultipath.version | 1 + 2 files changed, 83 insertions(+), 100 deletions(-)
libmpathpersist/mpath_persist_int.c +82 -100
@@ -363,9 +363,10 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; } -static int mpath_prout_common (struct multipath *mpp,int rq_servact,int rq_scope, -unsigned int rq_type, -struct prout_param_descriptor * paramp,int noisy) +static int +mpath_prout_common (struct multipath *mpp,int rq_servact,int rq_scope, +unsigned int rq_type,struct prout_param_descriptor *paramp, +int noisy,struct path **pptr) {int i,j, ret;struct pathgroup *pgp =NULL ;
@@ -384,6 +385,8 @@ static int mpath_prout_common(struct multipath *mpp,int rq_servact, int rq_scope found = true; ret =prout_do_scsi_ioctl (pp->dev, rq_servact, rq_scope, rq_type, paramp, noisy); +if (ret ==MPATH_PR_SUCCESS && pptr) + *pptr = pp;if (ret !=MPATH_PR_RETRYABLE_ERROR )return ret; }
@@ -404,14 +407,12 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,struct path *pp =NULL ;int active_pathcount =0 ;pthread_attr_t attr; -int rc, found =0 ; +int rc;int count =0 ;int status =MPATH_PR_SUCCESS ; -struct prin_resp resp; -struct prout_param_descriptor *pamp =NULL ; -struct prin_resp *pr_buff; -int length; -struct transportid *pptr =NULL ; +struct prin_resp resp = {{{.prgeneration =0 }}}; +uint16_t udev_flags = (mpp->skip_kpartx) ?MPATH_UDEV_NO_KPARTX_FLAG :0 ; +bool did_resume = false;if (!mpp)return MPATH_PR_DMMP_ERROR ;
@@ -501,104 +502,78 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope, }condlog (2 ,"%s: Path holding reservation is not available." , mpp->wwid); - - pr_buff =mpath_alloc_prin_response (MPATH_PRIN_RFSTAT_SA ); -if (!pr_buff){ -condlog (0 ,"%s: failed to alloc pr in response buffer." , mpp->wwid); +/* +* Cannot free the reservation because the path that is holding it +* is not usable. Workaround this by: +* 1. Suspending the device +* 2. Preempting the reservation to move it to a usable path +* (this removes the registered keys on all paths except the +* preempting one. Since the device is suspended, no IO can +* go to these unregistered paths and fail). +* 3. Releasing the reservation on the path that now holds it. +* 4. Resuming the device (since it no longer matters that most of +* that paths no longer have a registered key) +* 5. Reregistering keys on all the paths +*/ + +if (!dm_simplecmd_noflush (DM_DEVICE_SUSPEND , mpp->alias,0 )) { +condlog (0 ,"%s: release: failed to suspend dm device." , mpp->wwid);return MPATH_PR_OTHER ; } - status =mpath_prin_activepath (mpp,MPATH_PRIN_RFSTAT_SA , pr_buff, noisy); - -if (status !=MPATH_PR_SUCCESS ){ -condlog (0 ,"%s: pr in read full status command failed." , mpp->wwid); - goto out; - } - - num = pr_buff->prin_descriptor.prin_readfd.number_of_descriptor; -if (0 == num){ - goto out; - } - length =sizeof (struct prout_param_descriptor ) + (sizeof (struct transportid *)); - - pamp = (struct prout_param_descriptor *)malloc (length); -if (!pamp){ -condlog (0 ,"%s: failed to alloc pr out parameter." , mpp->wwid); - goto out; - } - -memset (pamp,0 , length); - - pamp->trnptid_list[0 ] = (struct transportid *)malloc (sizeof (struct transportid )); -if (!pamp->trnptid_list[0 ]){ -condlog (0 ,"%s: failed to alloc pr out transportid." , mpp->wwid); - goto out1; - } - pptr = pamp->trnptid_list[0 ]; - -if (get_be64 (mpp->reservation_key)){ -memcpy (pamp->key, &mpp->reservation_key,8 ); -condlog (3 ,"%s: reservation key set." , mpp->wwid); +memset (paramp,0 ,sizeof (*paramp)); +memcpy (paramp->key, &mpp->reservation_key,8 ); +memcpy (paramp->sa_key, &mpp->reservation_key,8 ); + status =mpath_prout_common (mpp,MPATH_PROUT_PREE_SA , rq_scope, + rq_type, paramp, noisy, &pp); +if (status !=MPATH_PR_SUCCESS ) { +condlog (0 ,"%s: release: pr preempt command failed." , mpp->wwid); + goto fail_resume; } - status =mpath_prout_common (mpp,MPATH_PROUT_CLEAR_SA , - rq_scope, rq_type, pamp, noisy); - -if (status) { -condlog (0 ,"%s: failed to send CLEAR_SA" , mpp->wwid); - goto out2; +memset (paramp,0 ,sizeof (*paramp)); +memcpy (paramp->key, &mpp->reservation_key,8 ); + status =prout_do_scsi_ioctl (pp->dev,MPATH_PROUT_REL_SA , rq_scope, + rq_type, paramp, noisy); +if (status !=MPATH_PR_SUCCESS ) { +condlog (0 ,"%s: release on alternate path failed." , mpp->wwid); + goto out_reregister; } - pamp->num_transportid =1 ; - -for (i =0 ; i < num; i++){ -if (get_be64 (mpp->reservation_key) && -memcmp (pr_buff->prin_descriptor.prin_readfd.descriptors[i]->key, - &mpp->reservation_key,8 )){ -/*register with transport id*/ -memset (pamp,0 , length); - pamp->trnptid_list[0 ] = pptr; -memset (pamp->trnptid_list[0 ],0 ,sizeof (struct transportid )); -memcpy (pamp->sa_key, - pr_buff->prin_descriptor.prin_readfd.descriptors[i]->key,8 ); - pamp->sa_flags =MPATH_F_SPEC_I_PT_MASK ; - pamp->num_transportid =1 ; - -memcpy (pamp->trnptid_list[0 ], - &pr_buff->prin_descriptor.prin_readfd.descriptors[i]->trnptid, -sizeof (struct transportid )); - status =mpath_prout_common (mpp,MPATH_PROUT_REG_SA ,0 , rq_type, - pamp, noisy); - - pamp->sa_flags =0 ; -memcpy (pamp->key, pr_buff->prin_descriptor.prin_readfd.descriptors[i]->key,8 ); -memset (pamp->sa_key,0 ,8 ); - pamp->num_transportid =0 ; - status =mpath_prout_common (mpp,MPATH_PROUT_REG_SA ,0 , rq_type, - pamp, noisy); - } -else - { -if (get_be64 (mpp->reservation_key)) - found =1 ; - } - - - } - -if (found){ -memset (pamp,0 , length); -memcpy (pamp->sa_key, &mpp->reservation_key,8 ); -memset (pamp->key,0 ,8 ); - status =mpath_prout_reg (mpp,MPATH_PROUT_REG_SA , rq_scope, rq_type, pamp, noisy); +if (!dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, udev_flags)) { +condlog (0 ,"%s release: failed to resume dm device." , mpp->wwid); +/* +* leave status set to MPATH_PR_SUCCESS, we will have another +* chance to resume the device. +*/ + goto out_reregister; + } + did_resume = true; + +out_reregister: +memset (paramp,0 ,sizeof (*paramp)); +memcpy (paramp->sa_key, &mpp->reservation_key,8 ); + rc =mpath_prout_reg (mpp,MPATH_PROUT_REG_IGN_SA , rq_scope, rq_type, + paramp, noisy); +if (rc !=MPATH_PR_SUCCESS ) +condlog (0 ,"%s: release: failed to reregister paths." , mpp->wwid); + +/* +* If we failed releasing the reservation or resuming earlier +* try resuming now. Otherwise, return with the reregistering status +* This means we will report failure, even though the resevation +* has been released, since the keys were not reregistered. +*/ +if (did_resume) +return rc; +else if (status ==MPATH_PR_SUCCESS ) + status = rc; +fail_resume: +if (!dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, udev_flags)) { +condlog (0 ,"%s: release: failed to resume dm device." , mpp->wwid); +if (status ==MPATH_PR_SUCCESS ) + status =MPATH_PR_OTHER ; } - -out2: -free (pptr); -out1: -free (pamp); -out: -free (pr_buff);return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; }
@@ -619,6 +594,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, mpp->mpe =find_mpe (conf->mptable, mpp->wwid);select_reservation_key (conf, mpp);select_all_tg_pt (conf, mpp); +/* +* If a device preempts itself, it will need to suspend and resume. +* Set mpp->skip_kpartx to make sure we set the flags to skip kpartx +* if necessary, when doing this. +*/ +select_skip_kpartx (conf, mpp);put_multipath_config (conf);memcpy (&prkey, paramp->sa_key,8 );
@@ -660,7 +641,8 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,case MPATH_PROUT_PREE_SA :case MPATH_PROUT_PREE_AB_SA :case MPATH_PROUT_CLEAR_SA : - ret =mpath_prout_common (mpp, rq_servact, rq_scope, rq_type, paramp, noisy); + ret =mpath_prout_common (mpp, rq_servact, rq_scope, rq_type, + paramp, noisy,NULL );break ;case MPATH_PROUT_REL_SA : ret =mpath_prout_rel (mpp, rq_servact, rq_scope, rq_type, paramp, noisy);
libmultipath/libmultipath.version +1 -0
@@ -249,4 +249,5 @@ local: LIBMULTIPATH_29.1.0 { global: can_recheck_wwid; + select_skip_kpartx; } LIBMULTIPATH_29.0.0;
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 10/32 libmpathpersist: fail the release if all threads fail
In reply to Benjamin MarzinskiIf none of the threads succeeds in issuing the release, simply return failure, instead of trying the workaround.
--- libmpathpersist/mpath_persist_int.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
libmpathpersist/mpath_persist_int.c +11 -3
@@ -413,6 +413,7 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,struct prin_resp resp = {{{.prgeneration =0 }}};uint16_t udev_flags = (mpp->skip_kpartx) ?MPATH_UDEV_NO_KPARTX_FLAG :0 ;bool did_resume = false; +bool all_threads_failed;if (!mpp)return MPATH_PR_DMMP_ERROR ;
@@ -474,15 +475,22 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope, } } + all_threads_failed = true;for (i =0 ; i < count; i++){/* check thread status here and return the status */ -if (thread[i].param.status ==MPATH_PR_RESERV_CONFLICT ) +if (thread[i].param.status ==MPATH_PR_SUCCESS ) + all_threads_failed = false; +else if (thread[i].param.status ==MPATH_PR_RESERV_CONFLICT ) status =MPATH_PR_RESERV_CONFLICT ; -else if (status ==MPATH_PR_SUCCESS - && thread[i].param.status !=MPATH_PR_RESERV_CONFLICT ) +else if (status ==MPATH_PR_SUCCESS ) status = thread[i].param.status; } +if (all_threads_failed) { +condlog (0 ,"%s: all threads failed to release reservation." , + mpp->wwid); +return status; + } status =mpath_prin_activepath (mpp,MPATH_PRIN_RRES_SA , &resp, noisy);if (status !=MPATH_PR_SUCCESS ){
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 11/32 libmpathpersist: Handle changing key corner case
In reply to Benjamin MarzinskiWhen you change the reservation key of a registered multipath device, some of paths might be down or even deleted since you originally registered the key. libmpathpersist won't be able to change these registrations. This can be a problem if the path that is down is holding the reservation. Other nodes will assume that the reservation is now under your new key, when it is still under the old one. If they try to preempt the reservation, they will succeed. But they will just unregister all the paths with the new key. They won't take over the reservation, and if the path holding it comes back up, it will still be able to write to the device.
To avoid this, after libmpathpersist changes the key of a registered device, it now checks to see if its old key is still holding the reservation. If it is, limpathpersist preempts the reservation. Currently this only works on REGISTER commands, not REGISTER AND IGNORE ones. A future patch will add that capability. This patch also moves mpath_prout_common() up, without changing it at all.
I should note that this relies on the fact that libmpathpersist has never worked correctly if two nodes use the same reservation key for the same device. If another node used the same key, it could be the one holding the reservation, and preempting the reservation would deregister it. However, multipathd has always relied on the fact that two nodes will not use the same registration key to know if it is safe to register a key on a path that was just added or just came back up. If there is already a registered key matching the configured key, multipathd assumes that the device has not been preempted, and registers the key on the path. If there are no keys matching the configured key, multipathd assumes that the device has been preempted, and won't register a key. Again, if another node shared the same key, multipathd could registered paths on a node that had been preempted.
--- libmpathpersist/mpath_persist_int.c | 127 ++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 34 deletions(-)
libmpathpersist/mpath_persist_int.c +93 -34
@@ -220,6 +220,97 @@ static void *mpath_prout_pthread_fn(void *p)pthread_exit (NULL ); } +static int +mpath_prout_common (struct multipath *mpp,int rq_servact,int rq_scope, +unsigned int rq_type,struct prout_param_descriptor *paramp, +int noisy,struct path **pptr) +{ +int i, j, ret; +struct pathgroup *pgp =NULL ; +struct path *pp =NULL ; +bool found = false; + + vector_foreach_slot (mpp->pg, pgp, j) { + vector_foreach_slot (pgp->paths, pp, i) { +if (!((pp->state ==PATH_UP ) || (pp->state ==PATH_GHOST ))) { +condlog (1 ,"%s: %s path not up. Skip" , + mpp->wwid, pp->dev); +continue ; + } + +condlog (3 ,"%s: sending pr out command to %s" , + mpp->wwid, pp->dev); + found = true; + ret =prout_do_scsi_ioctl (pp->dev, rq_servact, rq_scope, + rq_type, paramp, noisy); +if (ret ==MPATH_PR_SUCCESS && pptr) + *pptr = pp; +if (ret !=MPATH_PR_RETRYABLE_ERROR ) +return ret; + } + } +if (found) +return MPATH_PR_OTHER ; +condlog (0 ,"%s: no path available" , mpp->wwid); +return MPATH_PR_DMMP_ERROR ; +} + +/* +* If you are changing the key registered to a device, and that device is +* holding the reservation on a path that couldn't get its key updated, +* either because it is down or no longer part of the multipath device, +* you need to preempt the reservation to a usable path with the new key +*/ +void preempt_missing_path (struct multipath *mpp,uint8_t *key,uint8_t *sa_key, +int noisy) +{ +uint8_t zero[8 ] = {0 }; +struct prin_resp resp = {{{.prgeneration =0 }}}; +int rq_scope; +unsigned int rq_type; +struct prout_param_descriptor paramp = {.sa_flags =0 }; +int status; + +/* +* If you previously didn't have a key registered or you didn't +* switch to a different key, there's no need to preempt. Also, you +* can't preempt if you no longer have a registered key +*/ +if (memcmp (key, zero,8 ) ==0 ||memcmp (sa_key, zero,8 ) ==0 || +memcmp (key, sa_key,8 ) ==0 ) +return ; + + status =mpath_prin_activepath (mpp,MPATH_PRIN_RRES_SA , &resp, noisy); +if (status !=MPATH_PR_SUCCESS ) { +condlog (0 ,"%s: register: pr in read reservation command failed." , + mpp->wwid); +return ; + } +/* If there is no reservation, there's nothing to preempt */ +if (!resp.prin_descriptor.prin_readresv.additional_length) +return ; +/* +* If there reservation is not held by the old key, you don't +* want to preempt it +*/ +if (memcmp (key, resp.prin_descriptor.prin_readresv.key,8 ) !=0 ) +return ; +/* Assume this key is being held by an inaccessable path on this +* node. libmpathpersist has never worked if multiple nodes share +* the same reservation key for a device +*/ + rq_type = resp.prin_descriptor.prin_readresv.scope_type &MPATH_PR_TYPE_MASK ; + rq_scope = (resp.prin_descriptor.prin_readresv.scope_type & +MPATH_PR_SCOPE_MASK ) >> +4 ; +memcpy (paramp.key, sa_key,8 ); +memcpy (paramp.sa_key, key,8 ); + status =mpath_prout_common (mpp,MPATH_PROUT_PREE_SA , rq_scope, + rq_type, ¶mp, noisy,NULL ); +if (status !=MPATH_PR_SUCCESS ) +condlog (0 ,"%s: register: pr preempt command failed." , mpp->wwid); +} +static int mpath_prout_reg (struct multipath *mpp,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor * paramp,int noisy)
@@ -360,43 +451,11 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, }pthread_attr_destroy (&attr); +if (status ==MPATH_PR_SUCCESS ) +preempt_missing_path (mpp, paramp->key, paramp->sa_key, noisy);return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; } -static int -mpath_prout_common (struct multipath *mpp,int rq_servact,int rq_scope, -unsigned int rq_type,struct prout_param_descriptor *paramp, -int noisy,struct path **pptr) -{ -int i,j, ret; -struct pathgroup *pgp =NULL ; -struct path *pp =NULL ; -bool found = false; - - vector_foreach_slot (mpp->pg, pgp, j){ - vector_foreach_slot (pgp->paths, pp, i){ -if (!((pp->state ==PATH_UP ) || (pp->state ==PATH_GHOST ))){ -condlog (1 ,"%s: %s path not up. Skip" , - mpp->wwid, pp->dev); -continue ; - } - -condlog (3 ,"%s: sending pr out command to %s" , mpp->wwid, pp->dev); - found = true; - ret =prout_do_scsi_ioctl (pp->dev, rq_servact, rq_scope, - rq_type, paramp, noisy); -if (ret ==MPATH_PR_SUCCESS && pptr) - *pptr = pp; -if (ret !=MPATH_PR_RETRYABLE_ERROR ) -return ret; - } - } -if (found) -return MPATH_PR_OTHER ; -condlog (0 ,"%s: no path available" , mpp->wwid); -return MPATH_PR_DMMP_ERROR ; -} -static int mpath_prout_rel (struct multipath *mpp,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor * paramp,int noisy)
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 12/32 libmpathpersist: Handle REGISTER AND IGNORE changing key corner case
In reply to Benjamin MarzinskiWhen you use REGISTER to change the reservation key of a registered multipath device, where the path holding the reservation is down, libmpathpersist will PREEMPT the failed path to move the reservation to a usable path, so the reservation key will be updated. However, when you use REGISTER AND IGNORE, you don't pass in the old key, so libmpathpersist can't use it to check against the key holding the reservation, which is necessary to know if it needs to PREEMPT.
Since the SCSI spec says that devices must ignore any passed-in key on REGISTER AND IGNORE, libmpathpersist can still use it to pass in the old key value. But unlike with REGISTER, the command won't fail if device isn't actually registered with the old key, so libmpathpersist needs to check that itself. To do this, it calls update_map_pr() just like multipathd does to check that the device is registered before registering new paths. However, libmpathpersist doesn't track the persistent reservation state like multipathd, so it needs to ask multipathd if it thinks the device is registered, using the "get prstatus map <map>" command.
--- libmpathpersist/mpath_persist_int.c | 20 ++++++++++ libmpathpersist/mpath_updatepr.c | 59 +++++++++++++++++++++-------- libmpathpersist/mpathpr.h | 1 + 3 files changed, 65 insertions(+), 15 deletions(-)
libmpathpersist/mpath_persist_int.c +20 -0
@@ -644,6 +644,23 @@ fail_resume:return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; } +/* +* for MPATH_PROUT_REG_IGN_SA, we use the ignored paramp->key to store the +* currently registered key. +*/ +static void set_ignored_key (struct multipath *mpp,uint8_t *key) +{ +memset (key,0 ,8 ); +if (!get_be64 (mpp->reservation_key)) +return ; +if (get_prflag (mpp->alias) ==PRFLAG_UNSET ) +return ; +update_map_pr (mpp,NULL ); +if (mpp->prflag !=PRFLAG_SET ) +return ; +memcpy (key, &mpp->reservation_key,8 ); +} +int do_mpath_persistent_reserve_out (vector curmp,vector pathvec,int fd,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor *paramp,int noisy)
@@ -669,6 +686,9 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,select_skip_kpartx (conf, mpp);put_multipath_config (conf); +if (rq_servact ==MPATH_PROUT_REG_IGN_SA ) +set_ignored_key (mpp, paramp->key); +memcpy (&prkey, paramp->sa_key,8 ); if (mpp->prkey_source == PRKEY_SOURCE_FILE && prkey && (rq_servact == MPATH_PROUT_REG_IGN_SA ||
libmpathpersist/mpath_updatepr.c +44 -15
92 lines not on this page · raw message
libmpathpersist/mpathpr.h +1 -0
@@ -8,6 +8,7 @@int update_prflag (char *mapname,int set);int update_prkey_flags (char *mapname,uint64_t prkey,uint8_t sa_flags); +int get_prflag (char *mapname);#define update_prkey (mapname, prkey) update_prkey_flags(mapname, prkey, 0)#endif
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 13/32 libmultipath: rename prflag_value enums
In reply to Benjamin MarzinskiThese will also be used by another variable, so make their name more generic.
--- libmpathpersist/mpath_persist_int.c | 16 ++++++++-------- libmpathpersist/mpath_updatepr.c | 8 ++++---- libmultipath/structs.h | 9 ++++----- multipathd/cli_handlers.c | 22 +++++++++++----------- multipathd/main.c | 16 +++++++--------- 5 files changed, 34 insertions(+), 37 deletions(-)
libmpathpersist/mpath_persist_int.c +8 -8
@@ -653,10 +653,10 @@ static void set_ignored_key(struct multipath *mpp, uint8_t *key)memset (key,0 ,8 );if (!get_be64 (mpp->reservation_key))return ; -if (get_prflag (mpp->alias) ==PRFLAG_UNSET ) +if (get_prflag (mpp->alias) ==PR_UNSET )return ;update_map_pr (mpp,NULL ); -if (mpp->prflag !=PRFLAG_SET ) +if (mpp->prflag !=PR_SET )return ;memcpy (key, &mpp->reservation_key,8 ); }
@@ -759,16 +759,16 @@ int update_map_pr(struct multipath *mpp, struct path *pp)struct prin_resp *resp;unsigned int i;int ret =MPATH_PR_OTHER , isFound; -bool was_set = (mpp->prflag ==PRFLAG_SET ); +bool was_set = (mpp->prflag ==PR_SET );/* If pr is explicitly unset, it must be manually set */ -if (mpp->prflag ==PRFLAG_UNSET ) +if (mpp->prflag ==PR_UNSET )return MPATH_PR_SKIP ;if (!get_be64 (mpp->reservation_key)) {/* Nothing to do. Assuming pr mgmt feature is disabled*/ - mpp->prflag =PRFLAG_UNSET ; + mpp->prflag =PR_UNSET ;condlog (was_set ?2 :4 ,"%s: reservation_key not set in multipath.conf" , mpp->alias);
@@ -793,11 +793,11 @@ int update_map_pr(struct multipath *mpp, struct path *pp)if (ret !=MPATH_PR_SUCCESS ) {if (ret ==MPATH_PR_ILLEGAL_REQ ) - mpp->prflag =PRFLAG_UNSET ; + mpp->prflag =PR_UNSET ;condlog (0 ,"%s : pr in read keys service action failed Error=%d" , mpp->alias, ret); goto out; } - mpp->prflag =PRFLAG_UNSET ; + mpp->prflag =PR_UNSET ;if (resp->prin_descriptor.prin_readkeys.additional_length ==0 ) {
@@ -832,7 +832,7 @@ int update_map_pr(struct multipath *mpp, struct path *pp)if (isFound) { - mpp->prflag =PRFLAG_SET ; + mpp->prflag =PR_SET ;condlog (was_set ?3 :2 ,"%s: key found. prflag set." , mpp->alias); }else condlog(was_set ? 1 : 3, "%s: key not found. prflag unset.",
libmpathpersist/mpath_updatepr.c +4 -4
@@ -84,13 +84,13 @@ int get_prflag(char *mapname)snprintf (str,sizeof (str),"getprstatus map %s" , mapname); reply =do_pr (mapname, str);if (!reply) - prflag =PRFLAG_UNKNOWN ; + prflag =PR_UNKNOWN ;else if (strncmp (reply,"unset" ,5 ) ==0 ) - prflag =PRFLAG_UNSET ; + prflag =PR_UNSET ;else if (strncmp (reply,"set" ,3 ) ==0 ) - prflag =PRFLAG_SET ; + prflag =PR_SET ;else - prflag =PRFLAG_UNKNOWN ; + prflag =PR_UNKNOWN ;free (reply);return prflag;
libmultipath/structs.h +4 -5
@@ -424,11 +424,10 @@ struct path {typedef int (pgpolicyfn ) (struct multipath *,vector ); - -enum prflag_value { -PRFLAG_UNKNOWN , -PRFLAG_UNSET , -PRFLAG_SET , +enum pr_value { +PR_UNKNOWN , +PR_UNSET , +PR_SET , };enum prio_update_type {
multipathd/cli_handlers.c +11 -11
@@ -1250,14 +1250,15 @@ cli_shutdown (void * v, struct strbuf *reply, void * data)return 0 ; } +static const char *const pr_str[] = { + [PR_UNKNOWN ] ="unknown\n" , + [PR_UNSET ] ="unset\n" , + [PR_SET ] ="set\n" , +}; +static int cli_getprstatus (void * v,struct strbuf *reply,void * data) { -static const char *const prflag_str[] = { - [PRFLAG_UNKNOWN ] ="unknown\n" , - [PRFLAG_UNSET ] ="unset\n" , - [PRFLAG_SET ] ="set\n" , - };struct multipath * mpp;struct vectors * vecs = (struct vectors *)data;char * param =get_keyparam (v,KEY_MAP );
@@ -1268,7 +1269,7 @@ cli_getprstatus (void * v, struct strbuf *reply, void * data)if (!mpp)return -ENODEV ; -append_strbuf_str (reply, prflag_str[mpp->prflag]); +append_strbuf_str (reply, pr_str[mpp->prflag]);condlog (3 ,"%s: reply = %s" , param,get_strbuf_str (reply));
@@ -1288,12 +1289,11 @@ cli_setprstatus(void * v, struct strbuf *reply, void * data)if (!mpp)return -ENODEV ; -if (mpp->prflag !=PRFLAG_SET ) { - mpp->prflag =PRFLAG_SET ; +if (mpp->prflag !=PR_SET ) { + mpp->prflag =PR_SET ;condlog (2 ,"%s: prflag set" , param); } -return 0 ; }
@@ -1310,8 +1310,8 @@ cli_unsetprstatus(void * v, struct strbuf *reply, void * data)if (!mpp)return -ENODEV ; -if (mpp->prflag !=PRFLAG_UNSET ) { - mpp->prflag =PRFLAG_UNSET ; +if (mpp->prflag !=PR_UNSET ) { + mpp->prflag =PR_UNSET ;condlog (2 ,"%s: prflag unset" , param); }
multipathd/main.c +7 -9
@@ -637,7 +637,7 @@ pr_register_active_paths(struct multipath *mpp) vector_foreach_slot (mpp->pg, pgp, i) { vector_foreach_slot (pgp->paths, pp, j) { -if (mpp->prflag ==PRFLAG_UNSET ) +if (mpp->prflag ==PR_UNSET )return ;if ((pp->state ==PATH_UP ) || (pp->state ==PATH_GHOST ))mpath_pr_event_handle (pp);
@@ -1273,7 +1273,7 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)int start_waiter =0 ;int ret;int ro; -unsigned char prflag =PRFLAG_UNSET ; +unsigned char prflag =PR_UNSET ;/* * need path UID to go any further
@@ -1401,8 +1401,7 @@ rescan:sync_map_state (mpp, false);if (retries >=0 ) { -if ((mpp->prflag ==PRFLAG_SET && prflag !=PRFLAG_SET ) || - start_waiter) +if ((mpp->prflag ==PR_SET && prflag !=PR_SET ) || start_waiter)pr_register_active_paths (mpp);condlog (2 ,"%s [%s]: path added to devmap %s" , pp->dev, pp->dev_t, mpp->alias);
@@ -2639,7 +2638,7 @@ update_path_state (struct vectors * vecs, struct path * pp)/* newstate == PATH_UP || newstate == PATH_GHOST */ -if (pp->mpp->prflag !=PRFLAG_UNSET ) { +if (pp->mpp->prflag !=PR_UNSET ) {int prflag = pp->mpp->prflag;/* * Check Persistent Reservation.
@@ -2647,8 +2646,7 @@ update_path_state (struct vectors * vecs, struct path * pp)condlog (2 ,"%s: checking persistent " "reservation registration" , pp->dev);mpath_pr_event_handle (pp); -if (pp->mpp->prflag ==PRFLAG_SET && - prflag !=PRFLAG_SET ) +if (pp->mpp->prflag ==PR_SET && prflag !=PR_SET )pr_register_active_paths (pp->mpp); }
@@ -4231,14 +4229,14 @@ static void mpath_pr_event_handle(struct path *pp)struct prout_param_descriptor *param;if (pp->bus !=SYSFS_BUS_SCSI ) { - mpp->prflag =PRFLAG_UNSET ; + mpp->prflag =PR_UNSET ;return ; }if (update_map_pr (mpp, pp) !=MPATH_PR_SUCCESS )return ; -if (mpp->prflag !=PRFLAG_SET ) +if (mpp->prflag !=PR_SET )return ; param = (struct prout_param_descriptor *)calloc (1 ,sizeof (struct prout_param_descriptor ));
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 14/32 libmpathpersist: use a switch statement for prout command finalizing
In reply to Benjamin MarzinskiChange the code at the end of do_mpath_persistent_reserve_out() to use a switch statement instead of multiple if statements. A future patch will add more actions here, and a switch statement looks cleaner.
--- libmpathpersist/mpath_persist_int.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
libmpathpersist/mpath_persist_int.c +8 -4
@@ -738,15 +738,19 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,return MPATH_PR_OTHER ; } -if ((ret ==MPATH_PR_SUCCESS ) && ((rq_servact ==MPATH_PROUT_REG_SA ) || - (rq_servact ==MPATH_PROUT_REG_IGN_SA ))) - { +if (ret !=MPATH_PR_SUCCESS ) +return ret; + +switch (rq_servact) { +case MPATH_PROUT_REG_SA : +case MPATH_PROUT_REG_IGN_SA :if (prkey ==0 ) {update_prflag (mpp->alias,0 );update_prkey (mpp->alias,0 ); }else update_prflag (mpp->alias,1 ); - }else if ((ret ==MPATH_PR_SUCCESS ) && (rq_servact ==MPATH_PROUT_CLEAR_SA )) { +break ; +case MPATH_PROUT_CLEAR_SA :update_prflag (mpp->alias,0 );update_prkey (mpp->alias,0 ); }
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 15/32 libmpathpersist: Add safety check for preempting on key change
In reply to Benjamin MarzinskiWhen a reservation key is changed from one non-zero value to another, libmpathpersist checks if the old key is still holding the reservation, and preempts it if it is. This was only safe if two nodes never share the same key. If a node uses the same key as another node that is holding the reservation, and switches keys so that it no longer matches, it will end up preempting the reservation. This is clearly unexpected behavior, and it can come about by a simple accident of registering a device with the wrong key, and then immediately fixing it.
To handle this, add code to track if a device is the reservation holder to multipathd. multipathd now has three new commands "getprhold", "setprhold", and "unsetprhold". These commands work like the equivalent *prstatus commands. libmpathpersist calls setprhold on RESERVE commands and PREEMPT commands when the preempted key is holding the reservation and unsetprhold on RELEASE commands. Also, calling unsetprflag causes prhold to be unset as well, so CLEAR commands and REGISTER commands with a 0x0 service action key will also unset prhold. libmpathpersist() will also unset prhold if it notices that the device cannot be holding a reservation in preempt_missing_path().
When a new multipath device is created, its initial prhold state is PR_UNKNOWN until it checks the current reservation, just like with prflag. If multipathd ever finds that a device's registration has been preempted or cleared in update_map_pr(), it unsets prhold, just like with prflag.
Now, before libmpathpersist preempts a reservation when changing keys it also checks if multipathd thinks that the device is holding the reservation. If it does not, then libmpathpersist won't preempt the key. It will assume that another node is holding the reservation with the same key.
I should note that this safety check only stops a node not holding the reservation from preempting the node holding the reservation. If the node holding the reservation changes its key, but it fails to change the resevation key, because that path is down or gone, it will still issue the preempt to move the reservation to a usable path, even if another node is using the same key. This will remove the registrations for that other node. It also will not work correctly if multipathd stops tracking a device for some reason. It's only a best-effort safety check.
--- libmpathpersist/mpath_persist_int.c | 85 ++++++++++++++++++++++++----- libmpathpersist/mpath_updatepr.c | 19 ++++++- libmpathpersist/mpathpr.h | 2 + libmultipath/structs.h | 1 + multipathd/callbacks.c | 3 + multipathd/cli.c | 4 +- multipathd/cli.h | 3 + multipathd/cli_handlers.c | 46 ++++++++++++++++ multipathd/main.c | 34 +++++++++++- 9 files changed, 179 insertions(+), 18 deletions(-)
libmpathpersist/mpath_persist_int.c +71 -14
@@ -260,6 +260,10 @@ mpath_prout_common(struct multipath *mpp, int rq_servact, int rq_scope,* holding the reservation on a path that couldn't get its key updated, * either because it is down or no longer part of the multipath device, * you need to preempt the reservation to a usable path with the new key +* +* Also, it's possible that the reservation was preempted, and the device +* is being re-registered. If it appears that is the case, clear +* mpp->prhold in multipathd. */ void preempt_missing_path (struct multipath *mpp,uint8_t *key,uint8_t *sa_key,int noisy)
@@ -272,12 +276,19 @@ void preempt_missing_path(struct multipath *mpp, uint8_t *key, uint8_t *sa_key,int status;/* -* If you previously didn't have a key registered or you didn't -* switch to a different key, there's no need to preempt. Also, you -* can't preempt if you no longer have a registered key +* If you previously didn't have a key registered, you can't +* be holding the reservation. Also, you can't preempt if you +* no longer have a registered key */ -if (memcmp (key, zero,8 ) ==0 ||memcmp (sa_key, zero,8 ) ==0 || -memcmp (key, sa_key,8 ) ==0 ) +if (memcmp (key, zero,8 ) ==0 ||memcmp (sa_key, zero,8 ) ==0 ) { +update_prhold (mpp->alias, false); +return ; + } +/* +* If you didn't switch to a different key, there is no need to +* preempt. +*/ +if (memcmp (key, sa_key,8 ) ==0 )return ; status =mpath_prin_activepath (mpp,MPATH_PRIN_RRES_SA , &resp, noisy);
@@ -287,13 +298,29 @@ void preempt_missing_path(struct multipath *mpp, uint8_t *key, uint8_t *sa_key,return ; }/* If there is no reservation, there's nothing to preempt */ -if (!resp.prin_descriptor.prin_readresv.additional_length) +if (!resp.prin_descriptor.prin_readresv.additional_length) { +update_prhold (mpp->alias, false);return ; + }/* * If there reservation is not held by the old key, you don't * want to preempt it */ -if (memcmp (key, resp.prin_descriptor.prin_readresv.key,8 ) !=0 ) +if (memcmp (key, resp.prin_descriptor.prin_readresv.key,8 ) !=0 ) { +/* +* If reservation key doesn't match either the old or +* the new key, then clear prhold. +*/ +if (memcmp (sa_key, resp.prin_descriptor.prin_readresv.key,8 ) !=0 ) +update_prhold (mpp->alias, false); +return ; + } + +/* +* If multipathd doesn't think it is holding the reservation, don't +* preempt it +*/ +if (get_prhold (mpp->alias) !=PR_SET )return ;/* Assume this key is being held by an inaccessable path on this * node. libmpathpersist has never worked if multiple nodes share
@@ -644,19 +671,36 @@ fail_resume:return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; } +static int reservation_key_matches (struct multipath *mpp,uint8_t *key,int noisy) +{ +struct prin_resp resp = {{{.prgeneration =0 }}}; +int status; + + status =mpath_prin_activepath (mpp,MPATH_PRIN_RRES_SA , &resp, noisy); +if (status !=MPATH_PR_SUCCESS ) { +condlog (0 ,"%s: pr in read reservation command failed." , mpp->wwid); +return YNU_UNDEF ; + } +if (!resp.prin_descriptor.prin_readresv.additional_length) +return YNU_NO ; +if (memcmp (key, resp.prin_descriptor.prin_readresv.key,8 ) ==0 ) +return YNU_YES ; +return YNU_NO ; +} +/* * for MPATH_PROUT_REG_IGN_SA, we use the ignored paramp->key to store the -* currently registered key. +* currently registered key for use in preempt_missing_path(), but only if +* the key is holding the reservation. */ static void set_ignored_key (struct multipath *mpp,uint8_t *key) {memset (key,0 ,8 );if (!get_be64 (mpp->reservation_key))return ; -if (get_prflag (mpp->alias) ==PR_UNSET ) +if (get_prhold (mpp->alias) ==PR_UNSET )return ; -update_map_pr (mpp,NULL ); -if (mpp->prflag !=PR_SET ) +if (reservation_key_matches (mpp, key,0 ) ==YNU_NO )return ;memcpy (key, &mpp->reservation_key,8 ); }
@@ -669,6 +713,7 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,int ret;uint64_t prkey;struct config *conf; +bool preempting_reservation = false; ret =mpath_get_map (curmp, pathvec, fd, &mpp);if (ret !=MPATH_PR_SUCCESS )
@@ -724,9 +769,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,case MPATH_PROUT_REG_IGN_SA : ret=mpath_prout_reg (mpp, rq_servact, rq_scope, rq_type, paramp, noisy);break ; -case MPATH_PROUT_RES_SA : -case MPATH_PROUT_PREE_SA : -case MPATH_PROUT_PREE_AB_SA : +case MPATH_PROUT_PREE_SA : +case MPATH_PROUT_PREE_AB_SA : +if (reservation_key_matches (mpp, paramp->sa_key, noisy) ==YNU_YES ) + preempting_reservation = true; +/* fallthrough */ +case MPATH_PROUT_RES_SA :case MPATH_PROUT_CLEAR_SA : ret =mpath_prout_common (mpp, rq_servact, rq_scope, rq_type, paramp, noisy,NULL );
@@ -753,6 +801,15 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,case MPATH_PROUT_CLEAR_SA :update_prflag (mpp->alias,0 );update_prkey (mpp->alias,0 ); +break ; +case MPATH_PROUT_RES_SA : +case MPATH_PROUT_REL_SA : +update_prhold (mpp->alias, (rq_servact ==MPATH_PROUT_RES_SA )); +break ; +case MPATH_PROUT_PREE_SA : +case MPATH_PROUT_PREE_AB_SA : +if (preempting_reservation) +update_prhold (mpp->alias, true); }return ret; }
libmpathpersist/mpath_updatepr.c +17 -2
@@ -75,13 +75,13 @@ static int do_update_pr(char *alias, char *cmd, char *key)return ret; } -int get_prflag (char *mapname) +static int do_get_pr (char *mapname,const char *cmd) {char str[256 ];char *reply;int prflag; -snprintf (str,sizeof (str),"getprstatus map %s" , mapname); +snprintf (str,sizeof (str),"%s map %s" , cmd, mapname); reply =do_pr (mapname, str);if (!reply) prflag =PR_UNKNOWN ;
@@ -96,11 +96,26 @@ int get_prflag(char *mapname)return prflag; } +int get_prflag (char *mapname) +{ +return do_get_pr (mapname,"getprstatus" ); +} + +int get_prhold (char *mapname) +{ +return do_get_pr (mapname,"getprhold" ); +} +int update_prflag (char *mapname,int set) {return do_update_pr (mapname, (set)?"setprstatus" :"unsetprstatus" ,NULL ); } +int update_prhold (char *mapname,bool set) +{ +return do_update_pr (mapname, (set) ?"setprhold" :"unsetprhold" ,NULL ); +} +int update_prkey_flags (char *mapname,uint64_t prkey,uint8_t sa_flags) {char str[256 ];
libmpathpersist/mpathpr.h +2 -0
@@ -9,6 +9,8 @@int update_prflag (char *mapname,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); +int update_prhold (char *mapname,bool set);#define update_prkey (mapname, prkey) update_prkey_flags(mapname, prkey, 0)#endif
libmultipath/structs.h +1 -0
@@ -522,6 +522,7 @@ struct multipath {struct be64 reservation_key;uint8_t sa_flags;int prflag; +int prhold;int all_tg_pt;struct gen_multipath generic_mp;bool fpin_must_reload;
multipathd/callbacks.c +3 -0
@@ -69,4 +69,7 @@ void init_handler_callbacks(void)set_handler_callback (VRB_UNSETMARGINAL |Q1_PATH ,HANDLER (cli_unset_marginal));set_handler_callback (VRB_UNSETMARGINAL |Q1_MAP ,HANDLER (cli_unset_all_marginal)); +set_handler_callback (VRB_GETPRHOLD |Q1_MAP ,HANDLER (cli_getprhold)); +set_handler_callback (VRB_SETPRHOLD |Q1_MAP ,HANDLER (cli_setprhold)); +set_handler_callback (VRB_UNSETPRHOLD |Q1_MAP ,HANDLER (cli_unsetprhold)); }
multipathd/cli.c +3 -1
@@ -224,7 +224,9 @@ load_keys (void) r +=add_key (keys,"setmarginal" ,VRB_SETMARGINAL ,0 ); r +=add_key (keys,"unsetmarginal" ,VRB_UNSETMARGINAL ,0 ); r +=add_key (keys,"all" ,KEY_ALL ,0 ); - + r +=add_key (keys,"getprhold" ,VRB_GETPRHOLD ,0 ); + r +=add_key (keys,"setprhold" ,VRB_SETPRHOLD ,0 ); + r +=add_key (keys,"unsetprhold" ,VRB_UNSETPRHOLD ,0 );if (r) {free_keys (keys);
multipathd/cli.h +3 -0
@@ -38,6 +38,9 @@ enum {VRB_UNSETMARGINAL =23 ,VRB_SHUTDOWN =24 ,VRB_QUIT =25 , +VRB_GETPRHOLD =26 , +VRB_SETPRHOLD =27 , +VRB_UNSETPRHOLD =28 ,/* Qualifiers, values must be different from verbs */ KEY_PATH = 65,
multipathd/cli_handlers.c +46 -0
58 lines not on this page · raw message
multipathd/main.c +33 -1
@@ -4222,6 +4222,33 @@ main (int argc, char *argv[])return (child (NULL )); } +static void check_prhold (struct multipath *mpp,struct path *pp) +{ +struct prin_resp resp = {{{.prgeneration =0 }}}; +int status; + +if (mpp->prflag ==PR_UNSET ) { + mpp->prhold =PR_UNSET ; +return ; + } +if (mpp->prflag !=PR_SET || mpp->prhold !=PR_UNKNOWN ) +return ; + + status =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RRES_SA , &resp,0 ); +if (status !=MPATH_PR_SUCCESS ) { +condlog (0 ,"%s: pr in read reservation command failed: %d" , + mpp->wwid, status); +return ; + } + mpp->prhold =PR_UNSET ; +if (!resp.prin_descriptor.prin_readresv.additional_length) +return ; + +if (memcmp (&mpp->reservation_key, + resp.prin_descriptor.prin_readresv.key,8 ) ==0 ) + mpp->prhold =PR_SET ; +} +static void mpath_pr_event_handle (struct path *pp) {struct multipath *mpp = pp->mpp;
@@ -4233,8 +4260,13 @@ static void mpath_pr_event_handle(struct path *pp)return ; } -if (update_map_pr (mpp, pp) !=MPATH_PR_SUCCESS ) +if (update_map_pr (mpp, pp) !=MPATH_PR_SUCCESS ) { +if (mpp->prflag ==PR_UNSET ) + mpp->prhold =PR_UNSET ;return ; + } + +check_prhold (mpp, pp);if (mpp->prflag !=PR_SET )return ;
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 16/32 libmpathpersist: remove update_map_pr code for NULL pp
In reply to Benjamin MarzinskiSince update_map_pr is always called with pp set now, remove the code to handle being called with NULL pp.
--- libmpathpersist/mpath_persist_int.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
libmpathpersist/mpath_persist_int.c +1 -8
@@ -842,15 +842,8 @@ int update_map_pr(struct multipath *mpp, struct path *pp)condlog (0 ,"%s : failed to alloc resp in update_map_pr" , mpp->alias);return MPATH_PR_OTHER ; } -if (!pp &&count_active_paths (mpp) ==0 ) { -condlog (2 ,"%s: No available paths to check pr status" , mpp->alias); - goto out; - } -if (pp) - ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , resp, noisy); -else - ret =mpath_prin_activepath (mpp,MPATH_PRIN_RKEY_SA , resp, noisy); + ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , resp, noisy);if (ret !=MPATH_PR_SUCCESS ) {if (ret ==MPATH_PR_ILLEGAL_REQ )
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 17/32 libmpathpersist: move update_map_pr to multipathd
In reply to Benjamin Marzinskimultipathd is now the only program that calls update_map_pr(), so move it there, and make it static. There are no other code changes.
--- libmpathpersist/libmpathpersist.version | 1 - libmpathpersist/mpath_persist_int.c | 83 ------------------------- libmpathpersist/mpath_persist_int.h | 3 +- multipathd/main.c | 80 ++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 86 deletions(-)
libmpathpersist/libmpathpersist.version +0 -1
@@ -40,5 +40,4 @@ __LIBMPATHPERSIST_INT_2.0.0 { mpath_alloc_prin_response; prin_do_scsi_ioctl; prout_do_scsi_ioctl; - update_map_pr; };
libmpathpersist/mpath_persist_int.c +0 -83
86 lines not on this page · raw message
libmpathpersist/mpath_persist_int.h +1 -2
@@ -19,7 +19,6 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,int prin_do_scsi_ioctl (char * dev,int rq_servact,struct prin_resp * resp,int noisy);int prout_do_scsi_ioctl (char * dev,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor *paramp,int noisy); -void dumpHex (const char * ,int len,int no_ascii); -int update_map_pr (struct multipath *mpp,struct path *pp); +void dumpHex (const char *,int len,int no_ascii);#endif /* MPATH_PERSIST_INT_H_INCLUDED */
multipathd/main.c +80 -0
86 lines not on this page · raw message
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 18/32 multipathd: clean up update_map_pr and mpath_pr_event_handle
In reply to Benjamin MarzinskiStore the READ KEYS response and the prout_param_descriptor on the stack to avoid having to fail these functions for allocation reasons. Don't explicitly check for additional_length == 0, since the for-loop already handles that. Also cleanup formatting issues,remove redundant messages, and reduce the log level of others.
--- multipathd/main.c | 62 +++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-)
multipathd/main.c +19 -43
@@ -4251,8 +4251,7 @@ static void check_prhold(struct multipath *mpp, struct path *pp)static int update_map_pr (struct multipath *mpp,struct path *pp) { -int noisy =0 ; -struct prin_resp *resp; +struct prin_resp resp;unsigned int i;int ret =MPATH_PR_OTHER , isFound;bool was_set = (mpp->prflag ==PR_SET );
@@ -4270,51 +4269,34 @@ static int update_map_pr(struct multipath *mpp, struct path *pp)return MPATH_PR_SKIP ; } - resp =mpath_alloc_prin_response (MPATH_PRIN_RKEY_SA ); -if (!resp) { -condlog (0 ,"%s : failed to alloc resp in update_map_pr" , - mpp->alias); -return MPATH_PR_OTHER ; - } +memset (&resp,0 ,sizeof (resp)); - ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , resp, noisy); + ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , &resp,0 );if (ret !=MPATH_PR_SUCCESS ) {if (ret ==MPATH_PR_ILLEGAL_REQ ) mpp->prflag =PR_UNSET ;condlog (0 ,"%s : pr in read keys service action failed Error=%d" , mpp->alias, ret); - goto out; +return ret; } mpp->prflag =PR_UNSET ; -if (resp->prin_descriptor.prin_readkeys.additional_length ==0 ) { -condlog (was_set ?1 :3 , -"%s: No key found. Device may not be registered. " , - mpp->alias); - goto out; - } - -condlog (3 ,"%s: Multipath reservation_key: 0x%" PRIx64" " , mpp->alias, +condlog (4 ,"%s: Multipath reservation_key: 0x%" PRIx64" " , mpp->alias,get_be64 (mpp->reservation_key)); isFound =0 ;for (i =0 ; - i < resp->prin_descriptor.prin_readkeys.additional_length /8 ; i++) { -if (libmp_verbosity >=3 ) { -condlog (3 ,"%s: PR IN READKEYS[%d] reservation key:" , + i < resp.prin_descriptor.prin_readkeys.additional_length /8 ; i++) { +uint8_t *keyp = &resp.prin_descriptor.prin_readkeys.key_list[i *8 ]; + +if (libmp_verbosity >=4 ) { +condlog (4 ,"%s: PR IN READKEYS[%d] reservation key:" , mpp->alias, i); -dumpHex ((char *)&resp->prin_descriptor.prin_readkeys - .key_list[i *8 ], -8 ,1 ); +dumpHex ((char *)keyp,8 ,1 ); } -if (!memcmp (&mpp->reservation_key, - &resp->prin_descriptor.prin_readkeys.key_list[i *8 ], -8 )) { -condlog (3 ,"%s: reservation key found in pr in readkeys response" , - mpp->alias); +if (!memcmp (&mpp->reservation_key, keyp,8 )) isFound =1 ; - } }if (isFound) {
@@ -4324,16 +4306,14 @@ static int update_map_pr(struct multipath *mpp, struct path *pp)condlog (was_set ?1 :3 ,"%s: key not found. prflag unset." , mpp->alias); -out: -free (resp); -return ret; +return MPATH_PR_SUCCESS ; }static void mpath_pr_event_handle (struct path *pp) {struct multipath *mpp = pp->mpp;int ret; -struct prout_param_descriptor *param; +struct prout_param_descriptor param;if (pp->bus !=SYSFS_BUS_SCSI ) { mpp->prflag =PR_UNSET ;
@@ -4351,21 +4331,17 @@ static void mpath_pr_event_handle(struct path *pp)if (mpp->prflag !=PR_SET )return ; - param = (struct prout_param_descriptor *)calloc (1 ,sizeof (struct prout_param_descriptor )); -if (!param) -return ; +memset (¶m,0 ,sizeof (param)); - param->sa_flags = mpp->sa_flags; -memcpy (param->sa_key, &mpp->reservation_key,8 ); - param->num_transportid =0 ; + param.sa_flags = mpp->sa_flags; +memcpy (param.sa_key, &mpp->reservation_key,8 ); + param.num_transportid =0 ;condlog (3 ,"device %s:%s" , pp->dev, pp->mpp->wwid); - ret =prout_do_scsi_ioctl (pp->dev,MPATH_PROUT_REG_IGN_SA ,0 ,0 , param,0 ); + ret =prout_do_scsi_ioctl (pp->dev,MPATH_PROUT_REG_IGN_SA ,0 ,0 , ¶m,0 );if (ret !=MPATH_PR_SUCCESS ) {condlog (0 ,"%s: Reservation registration failed. Error: %d" , pp->dev, ret); } - -free (param); }
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 19/32 libmpathpersist: clean up duplicate function declarations
In reply to Benjamin Marzinski--- libmpathpersist/mpath_persist_int.h | 1 - libmpathpersist/mpath_pr_ioctl.c | 10 +++------- mpathpersist/main.c | 2 -- 3 files changed, 3 insertions(+), 10 deletions(-)
libmpathpersist/mpath_persist_int.h +0 -1
@@ -6,7 +6,6 @@* but aren't part of the public libmpathpersist API. */ -void *mpath_alloc_prin_response (int prin_sa);int do_mpath_persistent_reserve_in (vector curmp,vector pathvec,int fd,int rq_servact,struct prin_resp *resp,int noisy);
libmpathpersist/mpath_pr_ioctl.c +3 -7
@@ -14,19 +14,15 @@#include "mpath_pr_ioctl.h" #include "mpath_persist.h" #include "unaligned.h" -#include "debug.h" #include "structs.h" /* FILE_NAME_SIZE */ +#include "mpath_persist_int.h" #define TIMEOUT 2000#define MAXRETRY 5 -int prin_do_scsi_ioctl (char * dev,int rq_servact,struct prin_resp *resp,int noisy); -int mpath_translate_response (char * dev,struct sg_io_hdr io_hdr, -SenseData_t *Sensedata); -void dumpHex (const char * str,int len,int no_ascii); -int prout_do_scsi_ioctl (char * dev,int rq_servact,int rq_scope, -unsigned int rq_type,struct prout_param_descriptor *paramp,int noisy); +int mpath_translate_response (char *dev,struct sg_io_hdr io_hdr, +SenseData_t *Sensedata);uint32_t format_transportids (struct prout_param_descriptor *paramp);void convert_be32_to_cpu (uint32_t *num);void convert_be16_to_cpu (uint16_t *num);
mpathpersist/main.c +0 -2
@@ -38,8 +38,6 @@ void mpath_print_buf_readcap(struct prin_resp *pr_buff);void mpath_print_buf_readfullstat (struct prin_resp *pr_buff);void mpath_print_buf_readresv (struct prin_resp *pr_buff);void mpath_print_buf_readkeys (struct prin_resp *pr_buff); -void dumpHex (const char * str,int len,int no_ascii); -void *mpath_alloc_prin_response (int prin_sa);void mpath_print_transport_id (struct prin_fulldescr *fdesc);int construct_transportid (const char * inp,struct transportid transid[],int num_transportids);
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 20/32 multipathd: wrap setting and unsetting prflag
In reply to Benjamin MarzinskiWhen prflag is unset, prhold and sa_flags should also be unset. A future patch will add another variable to be set when prflag is set. Wrap all these actions in set_pr() and unset_pr().
--- multipathd/cli_handlers.c | 10 ++++------ multipathd/main.c | 34 ++++++++++++++++++++-------------- multipathd/main.h | 2 ++ 3 files changed, 26 insertions(+), 20 deletions(-)
multipathd/cli_handlers.c +4 -6
@@ -1290,7 +1290,7 @@ cli_setprstatus(void * v, struct strbuf *reply, void * data)return -ENODEV ;if (mpp->prflag !=PR_SET ) { - mpp->prflag =PR_SET ; +set_pr (mpp);condlog (2 ,"%s: prflag set" , param); }
@@ -1311,12 +1311,10 @@ cli_unsetprstatus(void * v, struct strbuf *reply, void * data)return -ENODEV ;if (mpp->prflag !=PR_UNSET ) { - mpp->prflag =PR_UNSET ;condlog (2 ,"%s: prflag unset" , param); - } -if (mpp->prhold !=PR_UNSET ) { - mpp->prhold =PR_UNSET ; -condlog (2 ,"%s: prhold unset (by clearing prflag)" , param); +if (mpp->prhold !=PR_UNSET ) +condlog (2 ,"%s: prhold unset (by clearing prflag)" , param); +unset_pr (mpp); }return 0 ;
multipathd/main.c +20 -14
@@ -4227,10 +4227,6 @@ static void check_prhold(struct multipath *mpp, struct path *pp)struct prin_resp resp = {{{.prgeneration =0 }}};int status; -if (mpp->prflag ==PR_UNSET ) { - mpp->prhold =PR_UNSET ; -return ; - }if (mpp->prflag !=PR_SET || mpp->prhold !=PR_UNKNOWN )return ;
@@ -4249,6 +4245,18 @@ static void check_prhold(struct multipath *mpp, struct path *pp) mpp->prhold =PR_SET ; } +void set_pr (struct multipath *mpp) +{ + mpp->prflag =PR_SET ; +} + +void unset_pr (struct multipath *mpp) +{ + mpp->prflag =PR_UNSET ; + mpp->prhold =PR_UNSET ; + mpp->sa_flags =0 ; +} +static int update_map_pr (struct multipath *mpp,struct path *pp) {struct prin_resp resp;
@@ -4262,7 +4270,7 @@ static int update_map_pr(struct multipath *mpp, struct path *pp)if (!get_be64 (mpp->reservation_key)) {/* Nothing to do. Assuming pr mgmt feature is disabled*/ - mpp->prflag =PR_UNSET ; +unset_pr (mpp);condlog (was_set ?2 :4 ,"%s: reservation_key not set in multipath.conf" , mpp->alias);
@@ -4274,12 +4282,11 @@ static int update_map_pr(struct multipath *mpp, struct path *pp) ret =prin_do_scsi_ioctl (pp->dev,MPATH_PRIN_RKEY_SA , &resp,0 );if (ret !=MPATH_PR_SUCCESS ) {if (ret ==MPATH_PR_ILLEGAL_REQ ) - mpp->prflag =PR_UNSET ; +unset_pr (mpp);condlog (0 ,"%s : pr in read keys service action failed Error=%d" , mpp->alias, ret);return ret; } - mpp->prflag =PR_UNSET ;condlog (4 ,"%s: Multipath reservation_key: 0x%" PRIx64" " , mpp->alias,get_be64 (mpp->reservation_key));
@@ -4300,11 +4307,13 @@ static int update_map_pr(struct multipath *mpp, struct path *pp) }if (isFound) { - mpp->prflag =PR_SET ; +set_pr (mpp);condlog (was_set ?3 :2 ,"%s: key found. prflag set." , mpp->alias); - }else + }else { +unset_pr (mpp);condlog (was_set ?1 :3 ,"%s: key not found. prflag unset." , mpp->alias); + }return MPATH_PR_SUCCESS ; }
@@ -4316,15 +4325,12 @@ static void mpath_pr_event_handle(struct path *pp)struct prout_param_descriptor param;if (pp->bus !=SYSFS_BUS_SCSI ) { - mpp->prflag =PR_UNSET ; +unset_pr (mpp);return ; } -if (update_map_pr (mpp, pp) !=MPATH_PR_SUCCESS ) { -if (mpp->prflag ==PR_UNSET ) - mpp->prhold =PR_UNSET ; +if (update_map_pr (mpp, pp) !=MPATH_PR_SUCCESS )return ; - }check_prhold (mpp, pp);
multipathd/main.h +2 -0
@@ -52,4 +52,6 @@ bool check_path_wwid_change(struct path *pp);int finish_path_init (struct path *pp,struct vectors * vecs);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);#endif /* MAIN_H_INCLUDED */
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 21/32 multipathd: unregister PR key when path is restored if necessary
In reply to Benjamin MarzinskiIt is possible that a path was unavailable and either the registered PR key was removed or the registered PR key was changed and then that new key was preempted. In both of these situations, this path will still have a registered key (just not one that matches mpp->reservation_key) but it should not have one. If the path becomes usable again in this state, it may allow the multipath device to access storage that it shouldn't be allowed to access.
To deal with this, track if a multipath device ever had a registered PR key. If so, and the device no longer has a registered key, explicitly clear the key when paths get restored.
--- libmultipath/structs.h | 2 ++ multipathd/main.c | 45 +++++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-)
libmultipath/structs.h +2 -0
@@ -524,6 +524,8 @@ struct multipath {int prflag;int prhold;int all_tg_pt; +bool ever_registered_pr; +struct gen_multipath generic_mp;bool fpin_must_reload; };
multipathd/main.c +34 -11
96 lines not on this page · raw message
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 22/32 libmpathpersist: Fix-up reservation_key checking
In reply to Benjamin MarzinskiThe reservation key checking in do_mpath_persistent_reserve_out() was slightly wrong. It allowed invalid keys for preempting. It now correctly checks the reservation key for the preempt commands.
It also was a little overly strict in some places. Formerly, it only allowed registering from any key to the configured key or registering from the configured key to any key (as long as you use the prkeys file). Now it also allows unregistering from any key and registering an unregistered device to any key (as long as you use the prkeys file).
Also, clarify the code by replacing prkey with a bool tracking if you are registering or unregistering.
--- libmpathpersist/mpath_persist_int.c | 55 ++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 17 deletions(-)
libmpathpersist/mpath_persist_int.c +38 -17
@@ -711,9 +711,9 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, {struct multipath *mpp;int ret; -uint64_t prkey; +uint64_t zerokey =0 ;struct config *conf; -bool preempting_reservation = false; +bool unregistering, preempting_reservation = false; ret =mpath_get_map (curmp, pathvec, fd, &mpp);if (ret !=MPATH_PR_SUCCESS )
@@ -734,11 +734,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,if (rq_servact ==MPATH_PROUT_REG_IGN_SA )set_ignored_key (mpp, paramp->key); -memcpy (&prkey, paramp->sa_key,8 ); -if (mpp->prkey_source ==PRKEY_SOURCE_FILE && prkey && + unregistering = (memcmp (&zerokey, paramp->sa_key,8 ) ==0 ); +if (mpp->prkey_source ==PRKEY_SOURCE_FILE && !unregistering && (rq_servact ==MPATH_PROUT_REG_IGN_SA || (rq_servact ==MPATH_PROUT_REG_SA && (!get_be64 (mpp->reservation_key) || +memcmp (paramp->key, &zerokey,8 ) ==0 ||memcmp (paramp->key, &mpp->reservation_key,8 ) ==0 )))) {memcpy (&mpp->reservation_key, paramp->sa_key,8 ); if (update_prkey_flags(mpp->alias, get_be64(mpp->reservation_key),
@@ -749,18 +750,38 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, } } -if (!get_be64 (mpp->reservation_key) && - (prkey || rq_servact !=MPATH_PROUT_REG_IGN_SA )) { -condlog (0 ,"%s: no configured reservation key" , mpp->alias); -return MPATH_PR_SYNTAX_ERROR ; - } - -if (memcmp (paramp->key, &mpp->reservation_key,8 ) && -memcmp (paramp->sa_key, &mpp->reservation_key,8 ) && - (prkey || rq_servact !=MPATH_PROUT_REG_IGN_SA )) { -condlog (0 ,"%s: configured reservation key doesn't match: 0x%" PRIx64, - mpp->alias,get_be64 (mpp->reservation_key)); -return MPATH_PR_SYNTAX_ERROR ; +/* +* If you are registering a non-zero key, mpp->reservation_key +* must be set and must equal paramp->sa_key. +* If you're not registering a key, mpp->reservation_key must be +* set, and must equal paramp->key +* If you updated the reservation key above, then you cannot fail +* these checks, since mpp->reservation_key has already been set +* to match paramp->sa_key, and if you are registering a non-zero +* key, then it must be set to a non-zero value. +*/ +if ((rq_servact ==MPATH_PROUT_REG_IGN_SA || + rq_servact ==MPATH_PROUT_REG_SA )) { +if (!unregistering && !get_be64 (mpp->reservation_key)) { +condlog (0 ,"%s: no configured reservation key" , mpp->alias); +return MPATH_PR_SYNTAX_ERROR ; + } +if (!unregistering && +memcmp (paramp->sa_key, &mpp->reservation_key,8 )) { +condlog (0 ,"%s: configured reservation key doesn't match: 0x%" PRIx64, + mpp->alias,get_be64 (mpp->reservation_key)); +return MPATH_PR_SYNTAX_ERROR ; + } + }else { +if (!get_be64 (mpp->reservation_key)) { +condlog (0 ,"%s: no configured reservation key" , mpp->alias); +return MPATH_PR_SYNTAX_ERROR ; + } +if (memcmp (paramp->key, &mpp->reservation_key,8 )) { +condlog (0 ,"%s: configured reservation key doesn't match: 0x%" PRIx64, + mpp->alias,get_be64 (mpp->reservation_key)); +return MPATH_PR_SYNTAX_ERROR ; + } } switch(rq_servact)
@@ -792,7 +813,7 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,switch (rq_servact) {case MPATH_PROUT_REG_SA :case MPATH_PROUT_REG_IGN_SA : -if (prkey ==0 ) { +if (unregistering) {update_prflag (mpp->alias,0 );update_prkey (mpp->alias,0 ); }else
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 23/32 libmpathpersist: change how reservation conflicts are handled
In reply to Benjamin MarzinskiIf registering a key on a path fails with a reservation conflict in mpath_prout_reg(), libmpathpersist currently tries to roll back the registration. This code doesn't always make much sense. First, it updates the configured key, but doesn't fix it if it does a rollback. Second, it always rolls the key back to 0x0, unregistering paths that may have been previously registered. These rollback only happen on the paths where the registration succeeded, meaning that they were in the expected state when the command was run. The paths where the command failed, that were in an unexpected state, remain in that state.
The code no longer attempts to rollback registrations that failed with a reservation conflict. Instead, it checks that at least one path was in the expected state and was successfully registered. If so, then it assumes that the registration command was a resonable one and retries it on the paths that failed with a reservation conflict. But instead of using MPATH_PROUT_REG_SA, it uses MPATH_PROUT_REG_IGN_SA so that it will ignore the current key. This will keep it from failing with a reservation conflict because the path doesn't have the expected key registered on it. If path reservations failed for reasons other than a reservation conflict, the command still returns failure.
--- libmpathpersist/mpath_persist_int.c | 71 ++++++++++++++++++----------- 1 file changed, 45 insertions(+), 26 deletions(-)
libmpathpersist/mpath_persist_int.c +45 -26
@@ -346,13 +346,13 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,int i, j, k;struct pathgroup *pgp =NULL ;struct path *pp =NULL ; -int rollback =0 ; +bool can_retry = false; +bool need_retry = false;int active_pathcount=0 ;int rc;int count=0 ;int status =MPATH_PR_SUCCESS ;int all_tg_pt; -uint64_t sa_key =0 ;if (!mpp)return MPATH_PR_DMMP_ERROR ;
@@ -441,43 +441,62 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,condlog (0 ,"%s: Thread[%d] failed to join thread %d" , mpp->wwid, i, rc); } } -if (!rollback && (thread[i].param.status ==MPATH_PR_RESERV_CONFLICT )){ - rollback =1 ; - sa_key =get_unaligned_be64 (¶mp->sa_key[0 ]); - status =MPATH_PR_RESERV_CONFLICT ; - } -if (!rollback && (status ==MPATH_PR_SUCCESS )){ +/* +* We only retry if there is at least one registration that +* returned a reservation conflict (which we need to retry) +* and at least one registration the return success, so we +* know that the command worked on some of the paths. If +* the registation fails on all paths, then it wasn't a +* valid request, so there's no need to retry. +*/ +if (thread[i].param.status ==MPATH_PR_RESERV_CONFLICT ) + need_retry = true; +else if (thread[i].param.status ==MPATH_PR_SUCCESS ) + can_retry = true; +else if (status ==MPATH_PR_SUCCESS ) status = thread[i].param.status; - } } -if (rollback && ((rq_servact ==MPATH_PROUT_REG_SA ) && sa_key !=0 )){ -condlog (3 ,"%s: ERROR: initiating pr out rollback" , mpp->wwid); -memcpy (¶mp->key, ¶mp->sa_key,8 ); -memset (¶mp->sa_key,0 ,8 ); -for ( i=0 ; i < count ; i++){ -if (thread[i].param.status ==MPATH_PR_SUCCESS ) { - rc =pthread_create (&thread[i].id, &attr, mpath_prout_pthread_fn, - (void *)(&thread[i].param)); -if (rc){ -condlog (0 ,"%s: failed to create thread for rollback. %d" , mpp->wwid, rc); - thread[i].param.status =MPATH_PR_THREAD_ERROR ; - } - }else +if (need_retry && can_retry && rq_servact ==MPATH_PROUT_REG_SA && + status ==MPATH_PR_SUCCESS ) { +condlog (3 ,"%s: ERROR: initiating pr out retry" , mpp->wwid); +for (i =0 ; i < count; i++) { +if (thread[i].param.status !=MPATH_PR_RESERV_CONFLICT ) { thread[i].param.status =MPATH_PR_SKIP ; +continue ; + } +/* +* retry using MPATH_PROUT_REG_IGN_SA to avoid +* conflicts. We already know that some paths +* succeeded using MPATH_PROUT_REG_SA. +*/ + thread[i].param.rq_servact =MPATH_PROUT_REG_IGN_SA ; + rc =pthread_create (&thread[i].id, &attr, + mpath_prout_pthread_fn, + (void *)(&thread[i].param)); +if (rc) { +condlog (0 ,"%s: failed to create thread for retry. %d" , + mpp->wwid, rc); + thread[i].param.status =MPATH_PR_THREAD_ERROR ; + } } -for (i=0 ; i < count ; i++){ +for (i =0 ; i < count; i++) {if (thread[i].param.status !=MPATH_PR_SKIP && thread[i].param.status !=MPATH_PR_THREAD_ERROR ) { rc =pthread_join (thread[i].id,NULL ); -if (rc){ -condlog (3 ,"%s: failed to join thread while rolling back %d" , - mpp->wwid, i); +if (rc) { +condlog (3 ,"%s: failed to join thread while retrying %d" , + mpp->wwid, i); } +if (status ==MPATH_PR_SUCCESS ) + status = thread[i].param.status; } } + need_retry = false; }pthread_attr_destroy (&attr); +if (need_retry) + status =MPATH_PR_RESERV_CONFLICT ;if (status ==MPATH_PR_SUCCESS )preempt_missing_path (mpp, paramp->key, paramp->sa_key, noisy);return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status;
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 24/32 libmpathpersist: Clear prkey in multipathd before unregistering
In reply to Benjamin MarzinskiWhen you register or switch keys in libmpathpersist, it updates mpp->reservation_key in multipathd before doing the registration. This means that any paths that come online while you are doing the registration get the new key registered. libmpathpersist didn't do this when unregistering a key. This could cause the same problem. A path that got restored while unregistering the device could end up getting the old key registered on it. Fix this by unsetting the key before doing the unregister, instead of afterwards.
There is still a race condition associated with updating mpp->reservation_key before doing the registration (but not on unregistration). This will be dealt with by a future patch.
--- libmpathpersist/mpath_persist_int.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
libmpathpersist/mpath_persist_int.c +3 -4
@@ -754,7 +754,7 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,set_ignored_key (mpp, paramp->key); unregistering = (memcmp (&zerokey, paramp->sa_key,8 ) ==0 ); - if (mpp->prkey_source == PRKEY_SOURCE_FILE && !unregistering && + if (mpp->prkey_source == PRKEY_SOURCE_FILE && (rq_servact == MPATH_PROUT_REG_IGN_SA || (rq_servact == MPATH_PROUT_REG_SA && (!get_be64(mpp->reservation_key) ||
@@ -832,10 +832,9 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,switch (rq_servact) {case MPATH_PROUT_REG_SA :case MPATH_PROUT_REG_IGN_SA : -if (unregistering) { +if (unregistering)update_prflag (mpp->alias,0 ); -update_prkey (mpp->alias,0 ); - }else +else update_prflag (mpp->alias,1 );break ;case MPATH_PROUT_CLEAR_SA :
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 25/32 libmpathpersist: only clear the key if we are using the prkeys file
In reply to Benjamin MarzinskiOtherwise this request will create a useless prkeys file.
--- libmpathpersist/mpath_persist_int.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libmpathpersist/mpath_persist_int.c +2 -1
@@ -839,7 +839,8 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,break ;case MPATH_PROUT_CLEAR_SA :update_prflag (mpp->alias,0 ); -update_prkey (mpp->alias,0 ); +if (mpp->prkey_source ==PRKEY_SOURCE_FILE ) +update_prkey (mpp->alias,0 );break ;case MPATH_PROUT_RES_SA :case MPATH_PROUT_REL_SA :
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 26/32 libmpathpersist: Restore old reservation key on failure
In reply to Benjamin MarzinskiIf we updated the key and then failed, restore the old key.
--- libmpathpersist/mpath_persist_int.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
libmpathpersist/mpath_persist_int.c +9 -1
@@ -731,8 +731,10 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,struct multipath *mpp;int ret;uint64_t zerokey =0 ; +struct be64 oldkey = {0 };struct config *conf;bool unregistering, preempting_reservation = false; +bool updated_prkey = false; ret =mpath_get_map (curmp, pathvec, fd, &mpp);if (ret !=MPATH_PR_SUCCESS )
@@ -760,6 +762,8 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, (!get_be64 (mpp->reservation_key) ||memcmp (paramp->key, &zerokey,8 ) ==0 || memcmp(paramp->key, &mpp->reservation_key, 8) == 0)))) { + updated_prkey = true; +memcpy (&oldkey, &mpp->reservation_key,8 );memcpy (&mpp->reservation_key, paramp->sa_key,8 );if (update_prkey_flags (mpp->alias,get_be64 (mpp->reservation_key), paramp->sa_flags)) {
@@ -826,8 +830,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,return MPATH_PR_OTHER ; } -if (ret !=MPATH_PR_SUCCESS ) +if (ret !=MPATH_PR_SUCCESS ) { +if (updated_prkey) +update_prkey_flags (mpp->alias,get_be64 (oldkey), + mpp->sa_flags);return ret; + }switch (rq_servact) {case MPATH_PROUT_REG_SA :
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 27/32 libmpathpersist: update reservation key before checking paths
In reply to Benjamin MarzinskiThere is a race condition when changing reservation keys where a failed path could come back online after libmpathpersist checks the paths, but before it updates the reservation key. In this case, the path would come up and get reregistered with the old key by multipathd, and libmpathpersist would not update its key, because the path was down when it checked.
To fix this, check the paths after updating the key, so any path that comes up after getting checked will use the updated key.
--- libmpathpersist/mpath_persist_int.c | 80 ++++++++++++----------------- 1 file changed, 34 insertions(+), 46 deletions(-)
libmpathpersist/mpath_persist_int.c +34 -46
@@ -110,39 +110,18 @@ void *mpath_alloc_prin_response(int prin_sa)return ptr; } -static int get_mpvec (vector curmp,vector pathvec,char *refwwid) +static int get_path_info (struct multipath *mpp,vector pathvec) { -int i; -struct multipath *mpp; - - vector_foreach_slot (curmp, mpp, i){ -/* -* discard out of scope maps -*/ -if (!mpp->alias) { -condlog (0 ,"%s: map with empty alias!" , __func__); -continue ; - } - -if (mpp->pg !=NULL ) -/* Already seen this one */ -continue ; - -if (refwwid &&strncmp (mpp->alias, refwwid,WWID_SIZE -1 )) -continue ; - -if (update_multipath_table (mpp, pathvec,DI_CHECKER ) !=DMP_OK || -update_mpp_paths (mpp, pathvec)) { -condlog (1 ,"error parsing map %s" , mpp->wwid); -remove_map (mpp, pathvec, curmp); - i--; - }else -extract_hwe_from_path (mpp); +if (update_multipath_table (mpp, pathvec,DI_CHECKER ) !=DMP_OK || +update_mpp_paths (mpp, pathvec)) { +condlog (0 ,"error parsing map %s" , mpp->wwid); +return MPATH_PR_DMMP_ERROR ; } +extract_hwe_from_path (mpp);return MPATH_PR_SUCCESS ; } -static int mpath_get_map (vector curmp,vector pathvec,int fd,struct multipath **pmpp) +static int mpath_get_map (vector curmp,int fd,struct multipath **pmpp) {int rc;struct stat info;
@@ -174,12 +153,6 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipathcondlog (4 ,"alias = %s" , alias); -/* get info of all paths from the dm device */ -if (get_mpvec (curmp, pathvec, alias)) { -condlog (0 ,"%s: failed to get device info." , alias); -return MPATH_PR_DMMP_ERROR ; - } - mpp =find_mp_by_alias (curmp, alias);if (!mpp) {
@@ -200,7 +173,11 @@ int do_mpath_persistent_reserve_in(vector curmp, vector pathvec,struct multipath *mpp;int ret; - ret =mpath_get_map (curmp, pathvec, fd, &mpp); + ret =mpath_get_map (curmp, fd, &mpp); +if (ret !=MPATH_PR_SUCCESS ) +return ret; + + ret =get_path_info (mpp, pathvec);if (ret !=MPATH_PR_SUCCESS )return ret;
@@ -736,25 +713,15 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,bool unregistering, preempting_reservation = false;bool updated_prkey = false; - ret =mpath_get_map (curmp, pathvec, fd, &mpp); + ret =mpath_get_map (curmp, fd, &mpp);if (ret !=MPATH_PR_SUCCESS )return ret; conf =get_multipath_config (); mpp->mpe =find_mpe (conf->mptable, mpp->wwid);select_reservation_key (conf, mpp); -select_all_tg_pt (conf, mpp); -/* -* If a device preempts itself, it will need to suspend and resume. -* Set mpp->skip_kpartx to make sure we set the flags to skip kpartx -* if necessary, when doing this. -*/ -select_skip_kpartx (conf, mpp);put_multipath_config (conf); -if (rq_servact ==MPATH_PROUT_REG_IGN_SA ) -set_ignored_key (mpp, paramp->key); - unregistering = (memcmp (&zerokey, paramp->sa_key,8 ) ==0 ); if (mpp->prkey_source == PRKEY_SOURCE_FILE && (rq_servact == MPATH_PROUT_REG_IGN_SA ||
@@ -807,6 +774,27 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, } } + ret =get_path_info (mpp, pathvec); +if (ret !=MPATH_PR_SUCCESS ) { +if (updated_prkey) +update_prkey_flags (mpp->alias,get_be64 (oldkey), + mpp->sa_flags); +return ret; + } + + conf =get_multipath_config (); +select_all_tg_pt (conf, mpp); +/* +* If a device preempts itself, it will need to suspend and resume. +* Set mpp->skip_kpartx to make sure we set the flags to skip kpartx +* if necessary, when doing this. +*/ +select_skip_kpartx (conf, mpp); +put_multipath_config (conf); + +if (rq_servact ==MPATH_PROUT_REG_IGN_SA ) +set_ignored_key (mpp, paramp->key); +switch (rq_servact) {case MPATH_PROUT_REG_SA :
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 28/32 libmpathpersist: retry on conflicts in mpath_prout_common
In reply to Benjamin Marzinskimpath_prout_common() just needs to execute a prout command down one path. If it uses a path that was down when the key was changed and has since been restored, but multipathd hasn't noticed yet, that path will still be using the old key. This was causing mpath_prout_common() to fail with MPATH_PR_RESERV_CONFLICT, even if there were other paths that would work.
Now, if prout command fails with MPATH_PR_RESERV_CONFLICT, mpath_prout_common() checks if pp->dmstate is PSTATE_FAILED. If it is, mpath_prout_common() assumes that multipathd has not yet noticed that the path is back online and it might still have and old key, so it doesn't immediately return. If it can't successfully send the command down another path, it will still return MPATH_PR_RESERV_CONFLICT.
Also, make sure prout_do_scsi_ioctl() always returns a MPATH_PR_* type error.
--- libmpathpersist/mpath_persist_int.c | 14 +++++++++++++- libmpathpersist/mpath_pr_ioctl.c | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-)
libmpathpersist/mpath_persist_int.c +13 -1
@@ -206,6 +206,7 @@ mpath_prout_common(struct multipath *mpp, int rq_servact, int rq_scope,struct pathgroup *pgp =NULL ;struct path *pp =NULL ;bool found = false; +bool conflict = false; vector_foreach_slot (mpp->pg, pgp, j) { vector_foreach_slot (pgp->paths, pp, i) {
@@ -222,12 +223,23 @@ mpath_prout_common(struct multipath *mpp, int rq_servact, int rq_scope, rq_type, paramp, noisy);if (ret ==MPATH_PR_SUCCESS && pptr) *pptr = pp; +/* +* If this path is considered down by the kernel, +* it may have just come back up, and multipathd +* may not have had time to update the key. Allow +* reservation conflicts. +*/ +if (ret ==MPATH_PR_RESERV_CONFLICT && + pp->dmstate ==PSTATE_FAILED ) { + conflict = true; +continue ; + }if (ret !=MPATH_PR_RETRYABLE_ERROR )return ret; } }if (found) -return MPATH_PR_OTHER ; +return conflict ?MPATH_PR_RESERV_CONFLICT :MPATH_PR_OTHER ;condlog (0 ,"%s: no path available" , mpp->wwid);return MPATH_PR_DMMP_ERROR ; }
libmpathpersist/mpath_pr_ioctl.c +1 -1
@@ -103,7 +103,7 @@ retry : {condlog (0 ,"%s: ioctl failed %d" , dev, ret);close (fd); -return ret; +return MPATH_PR_OTHER ; }condlog (4 ,"%s: Duration=%u (ms)" , dev, io_hdr.duration);
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 29/32 libmpathpersist: Don't always fail registrations for retryable errors
In reply to Benjamin MarzinskiWhen libmpathpersist registers a key, it's possible that a path fails between when it checks the path's status, and when it tries to do the registrations on the path. In this case, the registration will fail with a retryable error. If the registration was allowed to succeed, multipathd would update the now failed path's key when it came back online, and everything would work correctly. However it is possible for a registration to fail with a retryable error on a path that is still usable.
Libmpathpersist needs to avoid the case where it does not update the key of a usable path. Otherwise the path might be able to write to storage it shouldn't be allowed to. Or it could fail writing to storage that it should be allowed to write to. So if a registration would succeed except for retryable errors, libmpathpersist now rechecks all those paths to see if they are still usable. If they are, then it fails the registration as before. If they are not, then the registration succeeds.
Also, rename can_retry to had_success, since it is used for checking more than retries now.
--- libmpathpersist/mpath_persist_int.c | 72 ++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 7 deletions(-)
libmpathpersist/mpath_persist_int.c +65 -7
@@ -327,6 +327,48 @@ void preempt_missing_path(struct multipath *mpp, uint8_t *key, uint8_t *sa_key,condlog (0 ,"%s: register: pr preempt command failed." , mpp->wwid); } +/* +* If libmpathpersist fails at updating the key on a path with a retryable +* error, it has probably failed. But there is a chance that the path is +* still usable. To make sure a path isn't active without a key, when it +* should have one, or with a key, when it shouldn't have one, check if +* the path is still usable. If it is, we must fail the registration. +*/ +static int +check_failed_paths (struct multipath *mpp,struct threadinfo *thread,int count) +{ +int i, j, k; +int ret; +struct pathgroup *pgp; +struct path *pp; +struct config *conf; + +for (i =0 ; i < count; i++) { +if (thread[i].param.status !=MPATH_PR_RETRYABLE_ERROR ) +continue ; + vector_foreach_slot (mpp->pg, pgp, j) { + vector_foreach_slot (pgp->paths, pp, k) { +if (strncmp (pp->dev, thread[i].param.dev, +FILE_NAME_SIZE ) ==0 ) + goto match; + } + } +/* no match. This shouldn't ever happen. */ +condlog (0 ,"%s: Error: can't find path %s" , mpp->wwid, + thread[i].param.dev); +continue ; + match: + conf =get_multipath_config (); + ret =pathinfo (pp, conf,DI_CHECKER ); +put_multipath_config (conf); +/* If pathinfo fails, or if the path is active, return error */ +if (ret !=PATHINFO_OK || pp->state ==PATH_UP || + pp->state ==PATH_GHOST ) +return MPATH_PR_OTHER ; + } +return MPATH_PR_SUCCESS ; +} +static int mpath_prout_reg (struct multipath *mpp,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor * paramp,int noisy)
@@ -335,8 +377,9 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,int i, j, k;struct pathgroup *pgp =NULL ;struct path *pp =NULL ; -bool can_retry = false; +bool had_success = false;bool need_retry = false; +bool retryable_error = false;int active_pathcount=0 ;int rc;int count=0 ;
@@ -440,16 +483,21 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,*/ if (thread[i].param.status ==MPATH_PR_RESERV_CONFLICT ) need_retry = true; +else if (thread[i].param.status ==MPATH_PR_RETRYABLE_ERROR ) + retryable_error = true;else if (thread[i].param.status ==MPATH_PR_SUCCESS ) - can_retry = true; + had_success = true;else if (status ==MPATH_PR_SUCCESS ) status = thread[i].param.status; } -if (need_retry && can_retry && rq_servact ==MPATH_PROUT_REG_SA && +if (need_retry && had_success && rq_servact ==MPATH_PROUT_REG_SA && status ==MPATH_PR_SUCCESS ) {condlog (3 ,"%s: ERROR: initiating pr out retry" , mpp->wwid); + retryable_error = false;for (i =0 ; i < count; i++) { -if (thread[i].param.status !=MPATH_PR_RESERV_CONFLICT ) { +/* retry retryable errors and conflicts */ +if (thread[i].param.status !=MPATH_PR_RESERV_CONFLICT && + thread[i].param.status !=MPATH_PR_RETRYABLE_ERROR ) { thread[i].param.status =MPATH_PR_SKIP ;continue ; }
@@ -476,7 +524,10 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,condlog (3 ,"%s: failed to join thread while retrying %d" , mpp->wwid, i); } -if (status ==MPATH_PR_SUCCESS ) +if (thread[i].param.status == +MPATH_PR_RETRYABLE_ERROR ) + retryable_error = true; +else if (status ==MPATH_PR_SUCCESS ) status = thread[i].param.status; } }
@@ -485,10 +536,17 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,pthread_attr_destroy (&attr);if (need_retry) - status =MPATH_PR_RESERV_CONFLICT ; +return MPATH_PR_RESERV_CONFLICT ; +if (status !=MPATH_PR_SUCCESS ) +return status; +/* If you had retryable errors on all paths, fail the registration */ +if (!had_success) +return MPATH_PR_OTHER ; +if (retryable_error) + status =check_failed_paths (mpp, thread, count);if (status ==MPATH_PR_SUCCESS )preempt_missing_path (mpp, paramp->key, paramp->sa_key, noisy); -return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; +return status; } static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 30/32 libmpathpersist: Don't try release workaround for invalid type
In reply to Benjamin MarzinskiWhen trying to release a reservation, if the user specified the wrong reservation type, libmpathpersist would try to preempt the reservation, because the reservation key matched the device key, but it was not removed. In this case, the preemption would also fail because it also requires a matching type.
Check if the reservation type matches, to avoid attempting the workaround in this case.
--- libmpathpersist/mpath_persist_int.c | 8 ++++++++ 1 file changed, 8 insertions(+)
libmpathpersist/mpath_persist_int.c +8 -0
@@ -566,6 +566,7 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,uint16_t udev_flags = (mpp->skip_kpartx) ?MPATH_UDEV_NO_KPARTX_FLAG :0 ;bool did_resume = false;bool all_threads_failed; +unsigned int scope_type;if (!mpp)return MPATH_PR_DMMP_ERROR ;
@@ -661,6 +662,13 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,return MPATH_PR_SUCCESS ; } + scope_type = resp.prin_descriptor.prin_readresv.scope_type; +if ((scope_type &MPATH_PR_TYPE_MASK ) != rq_type) { +condlog (2 ,"%s: --prout_type %u doesn't match reservation %u" , + mpp->wwid, rq_type, scope_type &MPATH_PR_TYPE_MASK ); +return MPATH_PR_RESERV_CONFLICT ; + } +condlog (2 ,"%s: Path holding reservation is not available." , mpp->wwid);/* * Cannot free the reservation because the path that is holding it
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 31/32 libmpathpersist: Don't fail RESERVE commands unnecessarily
In reply to Benjamin MarzinskiIf you issue a RESERVE to a regular SCSI device that already holds the reservation, it succeeds (and does nothing). If you issue a RESERVE to a multipath device that already holds the reservation, it can fail with a reservation conflict error if you issue the RESERVE to a path that isn't holding the reservation. Instead, it should try all paths and succeed if the reservation command succeeds on any of them.
--- libmpathpersist/mpath_persist_int.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
libmpathpersist/mpath_persist_int.c +12 -1
@@ -228,9 +228,20 @@ mpath_prout_common(struct multipath *mpp, int rq_servact, int rq_scope,* it may have just come back up, and multipathd * may not have had time to update the key. Allow * reservation conflicts. +* +* If you issue a RESERVE to a regular scsi device +* that already holds the reservation, it succeeds +* (and does nothing). A multipath device that +* holds the reservation should not return a +* reservation conflict on a RESERVE command, just +* because it issued the RESERVE to a path that +* isn't holding the reservation. It should instead +* keep trying to see if it succeeds on another +* path. */ if (ret ==MPATH_PR_RESERV_CONFLICT && - pp->dmstate ==PSTATE_FAILED ) { + (pp->dmstate ==PSTATE_FAILED || + rq_servact ==MPATH_PROUT_RES_SA )) { conflict = true;continue ; }
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerPATCH v2 32/32 libmpathpersist: reregister keys when self preempting
In reply to Benjamin MarzinskiWhen a SCSI device preempts its own reservation key, it will remove the registered keys from all other devices with that reservation key, but retain its registered key (and possibly acquire the reservation). If a multipath device preempts its own reservation key, it will also remove the registered keys from all its paths except the one issuing the reservation. This means that IO to the device can fail if it goes to one of these unregistered paths.
To avoid this, whenever a multipath device preempts itself, it must first suspend, then do the preemption and reregister the removed keys, and finally resume the device. This is already what libmpathpersist does if a release fails because the path holding the reservation is currently unavailable, with the addition of releasing the reservation after preempting it. This commit refactors that code into a separate function, makes the release optional, and calls the new function, preempt_self(), whenever a device preempts itself.
--- libmpathpersist/mpath_persist_int.c | 133 ++++++++++++++-------------- 1 file changed, 68 insertions(+), 65 deletions(-)
libmpathpersist/mpath_persist_int.c +68 -65
@@ -560,6 +560,65 @@ static int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,return status; } +/* +* Called to make a multipath device preempt its own reservation (and +* optionally release the reservation). Doing this causes the reservation +* keys to be removed from all the device paths except that path used to issue +* the preempt, so they need to be restored. To avoid the chance that IO +* goes to these paths when they don't have a registered key, the device +* is suspended before issuing the preemption, and the keys are reregistered +* before resuming it. +*/ +static int preempt_self (struct multipath *mpp,int rq_servact,int rq_scope, +unsigned int rq_type,int noisy,bool do_release) +{ +int status, rel_status =MPATH_PR_SUCCESS ; +struct path *pp =NULL ; +struct prout_param_descriptor paramp = {.sa_flags =0 }; +uint16_t udev_flags = (mpp->skip_kpartx) ?MPATH_UDEV_NO_KPARTX_FLAG :0 ; + +if (!dm_simplecmd_noflush (DM_DEVICE_SUSPEND , mpp->alias,0 )) { +condlog (0 ,"%s: self preempt failed to suspend device." , mpp->wwid); +return MPATH_PR_OTHER ; + } + +memcpy (paramp.key, &mpp->reservation_key,8 ); +memcpy (paramp.sa_key, &mpp->reservation_key,8 ); + status =mpath_prout_common (mpp, rq_servact, rq_scope, rq_type, + ¶mp, noisy, &pp); +if (status !=MPATH_PR_SUCCESS ) { +condlog (0 ,"%s: self preempt command failed." , mpp->wwid); + goto fail_resume; + } + +if (do_release) { +memset (¶mp,0 ,sizeof (paramp)); +memcpy (paramp.key, &mpp->reservation_key,8 ); + rel_status =prout_do_scsi_ioctl (pp->dev,MPATH_PROUT_REL_SA , + rq_scope, rq_type, ¶mp, noisy); +if (rel_status !=MPATH_PR_SUCCESS ) +condlog (0 ,"%s: release on alternate path failed." , + mpp->wwid); + } + +memset (¶mp,0 ,sizeof (paramp)); +memcpy (paramp.sa_key, &mpp->reservation_key,8 ); + status =mpath_prout_reg (mpp,MPATH_PROUT_REG_IGN_SA , rq_scope, + rq_type, ¶mp, noisy); +if (status !=MPATH_PR_SUCCESS ) +condlog (0 ,"%s: self preempt failed to reregister paths." , + mpp->wwid); + +fail_resume: +if (!dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, udev_flags)) { +condlog (0 ,"%s: self preempt failed to resume device." , mpp->wwid); +if (status ==MPATH_PR_SUCCESS ) + status =MPATH_PR_OTHER ; + } +/* return the first error we encountered */ +return (rel_status !=MPATH_PR_SUCCESS ) ? rel_status : status; +} +static int mpath_prout_rel (struct multipath *mpp,int rq_servact,int rq_scope,unsigned int rq_type,struct prout_param_descriptor * paramp,int noisy)
@@ -574,8 +633,6 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,int count =0 ;int status =MPATH_PR_SUCCESS ;struct prin_resp resp = {{{.prgeneration =0 }}}; -uint16_t udev_flags = (mpp->skip_kpartx) ?MPATH_UDEV_NO_KPARTX_FLAG :0 ; -bool did_resume = false;bool all_threads_failed;unsigned int scope_type;
@@ -690,70 +747,10 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,* preempting one. Since the device is suspended, no IO can * go to these unregistered paths and fail). * 3. Releasing the reservation on the path that now holds it. -* 4. Resuming the device (since it no longer matters that most of -* that paths no longer have a registered key) -* 5. Reregistering keys on all the paths +* 4. Reregistering keys on all the paths +* 5. Resuming the device */ - -if (!dm_simplecmd_noflush (DM_DEVICE_SUSPEND , mpp->alias,0 )) { -condlog (0 ,"%s: release: failed to suspend dm device." , mpp->wwid); -return MPATH_PR_OTHER ; - } - -memset (paramp,0 ,sizeof (*paramp)); -memcpy (paramp->key, &mpp->reservation_key,8 ); -memcpy (paramp->sa_key, &mpp->reservation_key,8 ); - status =mpath_prout_common (mpp,MPATH_PROUT_PREE_SA , rq_scope, - rq_type, paramp, noisy, &pp); -if (status !=MPATH_PR_SUCCESS ) { -condlog (0 ,"%s: release: pr preempt command failed." , mpp->wwid); - goto fail_resume; - } - -memset (paramp,0 ,sizeof (*paramp)); -memcpy (paramp->key, &mpp->reservation_key,8 ); - status =prout_do_scsi_ioctl (pp->dev,MPATH_PROUT_REL_SA , rq_scope, - rq_type, paramp, noisy); -if (status !=MPATH_PR_SUCCESS ) { -condlog (0 ,"%s: release on alternate path failed." , mpp->wwid); - goto out_reregister; - } - -if (!dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, udev_flags)) { -condlog (0 ,"%s release: failed to resume dm device." , mpp->wwid); -/* -* leave status set to MPATH_PR_SUCCESS, we will have another -* chance to resume the device. -*/ - goto out_reregister; - } - did_resume = true; - -out_reregister: -memset (paramp,0 ,sizeof (*paramp)); -memcpy (paramp->sa_key, &mpp->reservation_key,8 ); - rc =mpath_prout_reg (mpp,MPATH_PROUT_REG_IGN_SA , rq_scope, rq_type, - paramp, noisy); -if (rc !=MPATH_PR_SUCCESS ) -condlog (0 ,"%s: release: failed to reregister paths." , mpp->wwid); - -/* -* If we failed releasing the reservation or resuming earlier -* try resuming now. Otherwise, return with the reregistering status -* This means we will report failure, even though the resevation -* has been released, since the keys were not reregistered. -*/ -if (did_resume) -return rc; -else if (status ==MPATH_PR_SUCCESS ) - status = rc; -fail_resume: -if (!dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias, udev_flags)) { -condlog (0 ,"%s: release: failed to resume dm device." , mpp->wwid); -if (status ==MPATH_PR_SUCCESS ) - status =MPATH_PR_OTHER ; - } -return (status ==MPATH_PR_RETRYABLE_ERROR ) ?MPATH_PR_OTHER : status; +return preempt_self (mpp,MPATH_PROUT_PREE_SA , rq_scope, rq_type, noisy, true); }static int reservation_key_matches (struct multipath *mpp,uint8_t *key,int noisy)
@@ -894,6 +891,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,case MPATH_PROUT_PREE_AB_SA :if (reservation_key_matches (mpp, paramp->sa_key, noisy) ==YNU_YES ) preempting_reservation = true; +/* if we are preempting ourself */ +if (memcmp (paramp->sa_key, paramp->key,8 ) ==0 ) { + ret =preempt_self (mpp, rq_servact, rq_scope, rq_type, + noisy, false); +break ; + }/* fallthrough */ case MPATH_PROUT_RES_SA :case MPATH_PROUT_CLEAR_SA :
Signature · 1 line
2.50.1
Quoted 114 lines · Benjamin Marzinski
The mpathpersist code has many areas where it does a poor job of mimicking the behavior of setting up persistent reservations on an individual device, especially if paths to the multipath device are missing or unusable. This patchset is aimed at fixing a number of them. It is a combination of my two previous patchsets:
[PATCH 00/15] Improve mpathpersist's unavailable path handling and
[PATCH 00/14] Additional fixes and cleanups
along with additional patches.Issues handled by the patchset are:
- Changing or unregistering a key held by an unavailable path that also
holds the reservation. This is done by preempting the old key (after verifying that the multipath device is holding the reservation)
- Releasing a reservation held by an unavailable path. This has always
had code to handle it, but it relied on optional Persistent Reservation features. The new code preempts the key and then restores
the removed registered keys (while the device is suspended).
- Handling removal of keys from paths that were down when the multipath
device was unregistered.
- Changing how conflicts on key registration are handled. Instead of the current rollback method (which was broken anyways), libmpathpersist now retries with REGISTER AND IGNORE as long as the REGISTER command completed successfully down some of the paths.
- Changing when the reservation key is set to fix corner cases on failure and registration while paths are coming up.
- Retrying on conflicts inmpath_prout_commonto fix corner cases when
a path is coming up while a doing a reserve, preempt or clear.
- Allowing registrations to succeed when there are retryable errors, if the paths are actually down.
- Fixing the reservation key validation codeChanges in V2:
First set (as suggested by Martin Wilck)
0009: Added a comment explaining theselect_skip_kpartx()0010: useall_threads_failvariable instead of rc.Second set
0003 (now 0018): Remove noisy variable fromupdate_map_pr0007 (new 0022): Added comment explaining why we won't fail syntax error
checks after updating the reservation key, as suggested by Martin
Wilck (for patch 0012, but it made more sense to change it here)0030 new patch to not attempt workaround when a release fails due to a
mismatched type.
0031 new patch to fix an issue with issuing a RESERVE command to the path that doesn't hold the reservation.
0032 new patch to fix an issue with a multipath device preempting its own reservation key.Benjamin Marzinski (32):
multipathd: remove thread frommpath_pr_event_handle
libmpathpersist: remove uneeded wrapper function.
libmpathpersist: reduce log level for persistent reservation checking
libmpathpersist: remove pointlessupdate_map_prret value code
multipathd: useupdate_map_prinmpath_pr_event_handle
libmpathpersist: limit changing prflag inupdate_map_pr
multipathd: Don't callupdate_map_prunnecessarily
libmpathpersist: remove useless functionsend_prout_activepath
libmpathpersist: redesign failed release workaround
libmpathpersist: fail the release if all threads fail
libmpathpersist: Handle changing key corner case
libmpathpersist: Handle REGISTER AND IGNORE changing key corner case
libmultipath: renameprflag_valueenums
libmpathpersist: use a switch statement for prout command finalizing
libmpathpersist: Add safety check for preempting on key change
libmpathpersist: removeupdate_map_prcode for NULL pp
libmpathpersist: moveupdate_map_prto multipathd
multipathd: clean upupdate_map_prandmpath_pr_event_handle
libmpathpersist: clean up duplicate function declarations
multipathd: wrap setting and unsetting prflag
multipathd: unregister PR key when path is restored if necessary
libmpathpersist: Fix-upreservation_keychecking
libmpathpersist: change how reservation conflicts are handled
libmpathpersist: Clear prkey in multipathd before unregistering
libmpathpersist: only clear the key if we are using the prkeys file
libmpathpersist: Restore old reservation key on failure
libmpathpersist: update reservation key before checking paths
libmpathpersist: retry on conflicts inmpath_prout_common
libmpathpersist: Don't always fail registrations for retryable errors
libmpathpersist: Don't try release workaround for invalid type
libmpathpersist: Don't fail RESERVE commands unnecessarily
libmpathpersist: reregister keys when self preemptinglibmpathpersist/libmpathpersist.version | 3 +- libmpathpersist/mpath_persist_int.c | 817 ++++++++++++++-------- --
libmpathpersist/mpath_persist_int.h | 4 +- libmpathpersist/mpath_pr_ioctl.c | 12 +- libmpathpersist/mpath_updatepr.c | 74 ++- libmpathpersist/mpathpr.h | 3 + libmultipath/libmultipath.version | 1 + libmultipath/structs.h | 12 +- mpathpersist/main.c | 2 - multipathd/callbacks.c | 3 + multipathd/cli.c | 4 +- multipathd/cli.h | 3 + multipathd/cli_handlers.c | 66 +- multipathd/main.c | 237 ++++--- multipathd/main.h | 2 +
Quoted 1 line
15 files changed, 755 insertions(+), 488 deletions(-)
For the series: