Clean 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.
Signed-off-by: Benjamin Marzinski <bmarz...@redhat.com> --- libmpathpersist/libmpathpersist.version | 2 +- libmpathpersist/mpath_persist_int.c | 21 +++++--- libmpathpersist/mpath_persist_int.h | 2 +- multipathd/main.c | 68 ++++--------------------- 4 files changed, 25 insertions(+), 68 deletions(-) diff --git a/libmpathpersist/libmpathpersist.version b/libmpathpersist/libmpathpersist.version index eed66aa0..b31237db 100644 --- a/libmpathpersist/libmpathpersist.version +++ b/libmpathpersist/libmpathpersist.version @@ -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; diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index f2c81fa0..92c3ea7e 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -720,7 +720,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; @@ -733,7 +733,7 @@ int update_map_pr(struct multipath *mpp) /* Nothing to do. Assuming pr mgmt feature is disabled*/ mpp->prflag = PRFLAG_UNSET; 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); @@ -742,14 +742,18 @@ 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 ) { @@ -784,8 +788,11 @@ 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); diff --git a/libmpathpersist/mpath_persist_int.h b/libmpathpersist/mpath_persist_int.h index 7819823c..7b32c1e2 100644 --- a/libmpathpersist/mpath_persist_int.h +++ b/libmpathpersist/mpath_persist_int.h @@ -20,6 +20,6 @@ int prin_do_scsi_ioctl(char * dev, int rq_servact, struct prin_resp * resp, int 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); +int update_map_pr(struct multipath *mpp, struct path *pp); #endif /* MPATH_PERSIST_INT_H_INCLUDED */ diff --git a/multipathd/main.c b/multipathd/main.c index 46eef222..ace278f1 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -727,7 +727,7 @@ fail: sync_map_state(mpp, false); if (mpp->prflag != PRFLAG_SET) - update_map_pr(mpp); + update_map_pr(mpp, NULL); if (mpp->prflag == PRFLAG_SET) pr_register_active_paths(mpp); @@ -1403,7 +1403,7 @@ rescan: if (retries >= 0) { if (start_waiter) - update_map_pr(mpp); + update_map_pr(mpp, NULL); if (mpp->prflag == PRFLAG_SET && prflag != PRFLAG_SET) pr_register_active_paths(mpp); condlog(2, "%s [%s]: path added to devmap %s", @@ -3312,7 +3312,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); + update_map_pr(mpp, NULL); if (mpp->prflag == PRFLAG_SET) pr_register_active_paths(mpp); } @@ -4230,70 +4230,24 @@ main (int argc, char *argv[]) static void mpath_pr_event_handle(struct path *pp) { - struct multipath * mpp; - unsigned int i; - int ret, isFound; + struct multipath *mpp = pp->mpp; + int ret; struct prout_param_descriptor *param; - struct prin_resp *resp; - mpp = pp->mpp; if (pp->bus != SYSFS_BUS_SCSI) { mpp->prflag = PRFLAG_UNSET; return; } - if (!get_be64(mpp->reservation_key)) { - mpp->prflag = PRFLAG_UNSET; + if (update_map_pr(mpp, pp) != MPATH_PR_SUCCESS) return; - } - - resp = mpath_alloc_prin_response(MPATH_PRIN_RKEY_SA); - if (!resp){ - condlog(0,"%s Alloc failed for prin response", pp->dev); - goto out; - } - - mpp->prflag = PRFLAG_UNSET; - ret = prin_do_scsi_ioctl(pp->dev, MPATH_PRIN_RKEY_SA, resp, 0); - if (ret != MPATH_PR_SUCCESS ) - { - condlog(0,"%s : pr in read keys service action failed. Error=%d", pp->dev, ret); - goto out; - } - - condlog(3, " event pr=%d addlen=%d",resp->prin_descriptor.prin_readkeys.prgeneration, - resp->prin_descriptor.prin_readkeys.additional_length ); - - if (resp->prin_descriptor.prin_readkeys.additional_length == 0 ) - { - condlog(1, "%s: No key found. Device may not be registered.", pp->dev); - goto out; - } - condlog(2, "Multipath reservation_key: 0x%" PRIx64 " ", - get_be64(mpp->reservation_key)); - isFound =0; - for (i = 0; i < resp->prin_descriptor.prin_readkeys.additional_length/8; i++ ) - { - condlog(2, "PR IN READKEYS[%d] reservation key:",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: pr key found in prin readkeys response", mpp->alias); - isFound =1; - break; - } - } - if (!isFound) - { - condlog(0, "%s: Either device not registered or ", pp->dev); - condlog(0, "host is not authorised for registration. Skip path"); - goto out; - } + if (mpp->prflag != PRFLAG_SET) + return; param = (struct prout_param_descriptor *)calloc(1, sizeof(struct prout_param_descriptor)); if (!param) - goto out; + return; param->sa_flags = mpp->sa_flags; memcpy(param->sa_key, &mpp->reservation_key, 8); @@ -4306,10 +4260,6 @@ static void mpath_pr_event_handle(struct path *pp) { condlog(0,"%s: Reservation registration failed. Error: %d", pp->dev, ret); } - mpp->prflag = PRFLAG_SET; free(param); -out: - if (resp) - free(resp); } -- 2.48.1