Add 0035-libmpathpersist-fix-memory-leak-in-mpath_prout_rel.patch Add 0036-libmpathpersist-retry-commands-on-other-paths-in-mpa.patch Add 0037-libmpathpersist-check-released-key-against-the-reser.patch Add 0038-multipathd-remove-thread-from-mpath_pr_event_handle.patch Add 0039-libmpathpersist-remove-uneeded-wrapper-function.patch Add 0040-libmpathpersist-reduce-log-level-for-persistent-rese.patch Add 0041-libmpathpersist-remove-pointless-update_map_pr-ret-v.patch Add 0042-multipathd-use-update_map_pr-in-mpath_pr_event_handl.patch Add 0043-libmpathpersist-limit-changing-prflag-in-update_map_.patch Add 0044-multipathd-Don-t-call-update_map_pr-unnecessarily.patch Add 0045-libmpathpersist-remove-useless-function-send_prout_a.patch Add 0046-libmpathpersist-redesign-failed-release-workaround.patch Add 0047-libmpathpersist-fail-the-release-if-all-threads-fail.patch Add 0048-libmpathpersist-Handle-changing-key-corner-case.patch Add 0049-libmpathpersist-Handle-REGISTER-AND-IGNORE-changing-.patch Add 0050-libmultipath-rename-prflag_value-enums.patch Add 0051-libmpathpersist-use-a-switch-statement-for-prout-com.patch Add 0052-libmpathpersist-Add-safety-check-for-preempting-on-k.patch Add 0053-libmpathpersist-remove-update_map_pr-code-for-NULL-p.patch Add 0054-libmpathpersist-move-update_map_pr-to-multipathd.patch Add 0055-multipathd-clean-up-update_map_pr-and-mpath_pr_event.patch Add 0056-libmpathpersist-clean-up-duplicate-function-declarat.patch Add 0057-multipathd-wrap-setting-and-unsetting-prflag.patch Add 0058-multipathd-unregister-PR-key-when-path-is-restored-i.patch Add 0059-libmpathpersist-Fix-up-reservation_key-checking.patch Add 0060-libmpathpersist-change-how-reservation-conflicts-are.patch Add 0061-libmpathpersist-Clear-prkey-in-multipathd-before-unr.patch Add 0062-libmpathpersist-only-clear-the-key-if-we-are-using-t.patch Add 0063-libmpathpersist-Restore-old-reservation-key-on-failu.patch Add 0064-libmpathpersist-update-reservation-key-before-checki.patch Add 0065-libmpathpersist-retry-on-conflicts-in-mpath_prout_co.patch Add 0066-libmpathpersist-Don-t-always-fail-registrations-for-.patch Add 0067-libmpathpersist-Don-t-try-release-workaround-for-inv.patch Add 0068-libmpathpersist-Don-t-fail-RESERVE-commands-unnecess.patch Add 0069-libmpathpersist-reregister-keys-when-self-preempting.patch Add 0070-libmpathpersist-handle-updating-key-race-condition.patch Add 0071-libmpathpersist-handle-preempting-all-registrants-re.patch Add 0072-libmpathpersist-Fix-REGISTER-AND-IGNORE-while-holdin.patch Add 0073-libmpathpersist-Handle-RESERVE-with-reservation-held.patch Add 0074-libmpathpersist-use-check_holding_reservation-in-mpa.patch Add 0075-libmpathpersist-Fix-unregistering-while-holding-the-.patch Add 0076-libmpathpersist-Fix-race-between-restoring-a-path-an.patch Add 0077-multipathd-Fix-tracking-of-old-PR-key.patch * Fixes RHEL-118720 ("There are many bugs in multipath's persistent reservation handling [rhel-10]") Resolves: RHEL-118720
294 lines
11 KiB
Diff
294 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
Date: Thu, 10 Jul 2025 14:10:54 -0400
|
|
Subject: [PATCH] libmpathpersist: redesign failed release workaround
|
|
|
|
The 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.
|
|
|
|
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
---
|
|
libmpathpersist/mpath_persist_int.c | 182 +++++++++++++---------------
|
|
libmultipath/libmultipath.version | 5 +
|
|
2 files changed, 87 insertions(+), 100 deletions(-)
|
|
|
|
diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c
|
|
index d8f757b7..36743d41 100644
|
|
--- a/libmpathpersist/mpath_persist_int.c
|
|
+++ b/libmpathpersist/mpath_persist_int.c
|
|
@@ -373,9 +373,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;
|
|
@@ -394,6 +395,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;
|
|
}
|
|
@@ -414,14 +417,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;
|
|
@@ -511,104 +512,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);
|
|
- }
|
|
-
|
|
- 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);
|
|
+ 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;
|
|
}
|
|
|
|
- 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;
|
|
- }
|
|
-
|
|
-
|
|
+ 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 (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;
|
|
}
|
|
|
|
@@ -629,6 +604,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,
|
|
conf = get_multipath_config();
|
|
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);
|
|
@@ -665,7 +646,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);
|
|
diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version
|
|
index 0b7a1a2b..db125779 100644
|
|
--- a/libmultipath/libmultipath.version
|
|
+++ b/libmultipath/libmultipath.version
|
|
@@ -246,3 +246,8 @@ LIBMULTIPATH_24.0.1 {
|
|
global:
|
|
can_recheck_wwid;
|
|
} LIBMULTIPATH_24.0.0;
|
|
+
|
|
+LIBMULTIPATH_24.0.2 {
|
|
+global:
|
|
+ select_skip_kpartx;
|
|
+} LIBMULTIPATH_24.0.1;
|