If we updated the key and then failed, restore the old key.

Signed-off-by: Benjamin Marzinski <[email protected]>
Reviewed-by: Martin Wilck <[email protected]>
---
 libmpathpersist/mpath_persist_int.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libmpathpersist/mpath_persist_int.c 
b/libmpathpersist/mpath_persist_int.c
index 3819c0d7..c575e3b5 100644
--- a/libmpathpersist/mpath_persist_int.c
+++ b/libmpathpersist/mpath_persist_int.c
@@ -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:
-- 
2.50.1


Reply via email to