diff mbox series

[v2] libmpathpersist: set mpp->mpe before selecting reservation_key

Message ID 20240724181712.2565138-1-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: Benjamin Marzinski
Headers show
Series [v2] libmpathpersist: set mpp->mpe before selecting reservation_key | expand

Commit Message

Benjamin Marzinski July 24, 2024, 6:17 p.m. UTC
libmpathpersist was not setting mpp->mpe before calling
select_reservation_key(). This means that if the reservation key was set
in the multipaths sections, it wasn't being selected.

This appeared to work for many commands because of an error in checking
if the correct reservation key was used. If mpp->reservation key was
unset, then it would considered to match if either the RK or SARK was
unset in the command. mpathpersist should fail if it doesn't find a
configured mpp->resevation key, with one exception. To make it easier to
remove old keys, if --register-ignore is called, and the command SARK is
0x0 so the device is being unregistered, allow mpp->reservation_key to
be unset. The code already allows mpp->reservation_key to not match the
command RK in this case.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---

Changes in v2:
Actually base patch on mwilck/tip

 libmpathpersist/mpath_persist_int.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Martin Wilck Aug. 6, 2024, 6:56 p.m. UTC | #1
On Wed, 2024-07-24 at 14:17 -0400, Benjamin Marzinski wrote:
> libmpathpersist was not setting mpp->mpe before calling
> select_reservation_key(). This means that if the reservation key was
> set
> in the multipaths sections, it wasn't being selected.
> 
> This appeared to work for many commands because of an error in
> checking
> if the correct reservation key was used. If mpp->reservation key was
> unset, then it would considered to match if either the RK or SARK was
> unset in the command. mpathpersist should fail if it doesn't find a
> configured mpp->resevation key, with one exception. To make it easier
> to
> remove old keys, if --register-ignore is called, and the command SARK
> is
> 0x0 so the device is being unregistered, allow mpp->reservation_key
> to
> be unset. The code already allows mpp->reservation_key to not match
> the
> command RK in this case.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>
diff mbox series

Patch

diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c
index f4d9e7c8..95bbdcd8 100644
--- a/libmpathpersist/mpath_persist_int.c
+++ b/libmpathpersist/mpath_persist_int.c
@@ -652,6 +652,7 @@  int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,
 		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);
 	put_multipath_config(conf);
@@ -671,6 +672,12 @@  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)) {