When 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().

Signed-off-by: Benjamin Marzinski <[email protected]>
Reviewed-by: Martin Wilck <[email protected]>
---
 multipathd/cli_handlers.c | 10 ++++------
 multipathd/main.c         | 34 ++++++++++++++++++++--------------
 multipathd/main.h         |  2 ++
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index 36552c24..0c65e7d2 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -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;
diff --git a/multipathd/main.c b/multipathd/main.c
index 394fd47a..11beaf4e 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -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);
 
diff --git a/multipathd/main.h b/multipathd/main.h
index c94362e4..29b57e3d 100644
--- a/multipathd/main.h
+++ b/multipathd/main.h
@@ -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 */
-- 
2.50.1


Reply via email to