From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
Sachin Sant <sachinp@linux.ibm.com>,
Hannes Reinecke <hare@suse.de>, Martin Wilck <mwilck@suse.com>
Subject: [PATCH] scsi: alua: Fix alua_rtpg_queue()
Date: Tue, 15 Nov 2022 14:49:03 -0800 [thread overview]
Message-ID: <20221115224903.2325529-1-bvanassche@acm.org> (raw)
Modify alua_rtpg_queue() such that it only requests the caller to drop
the sdev reference if necessary. This patch fixes a recently introduced
regression.
Cc: Sachin Sant <sachinp@linux.ibm.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Martin Wilck <mwilck@suse.com>
Reported-by: Sachin Sant <sachinp@linux.ibm.com>
Fixes: 0b25e17e9018 ("scsi: alua: Move a scsi_device_put() call out of alua_check_vpd()")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/device_handler/scsi_dh_alua.c | 31 ++++++++++++++--------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 693cd827e138..c1bf75673e89 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -102,7 +102,7 @@ struct alua_queue_data {
static void alua_rtpg_work(struct work_struct *work);
static bool alua_rtpg_queue(struct alua_port_group *pg,
- struct scsi_device *sdev,
+ struct scsi_device *sdev, bool *put_sdev,
struct alua_queue_data *qdata, bool force);
static void alua_check(struct scsi_device *sdev, bool force);
@@ -374,9 +374,9 @@ static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h,
list_add_rcu(&h->node, &pg->dh_list);
spin_unlock_irqrestore(&pg->lock, flags);
- put_sdev = alua_rtpg_queue(rcu_dereference_protected(h->pg,
+ alua_rtpg_queue(rcu_dereference_protected(h->pg,
lockdep_is_held(&h->pg_lock)),
- sdev, NULL, true);
+ sdev, &put_sdev, NULL, true);
spin_unlock(&h->pg_lock);
if (put_sdev)
@@ -983,17 +983,23 @@ static void alua_rtpg_work(struct work_struct *work)
*
* Returns true if and only if alua_rtpg_work() will be called asynchronously.
* That function is responsible for calling @qdata->fn(). If this function
- * returns true, the caller is responsible for invoking scsi_device_put(@sdev).
+ * sets *put_sdev to true, the caller is responsible for calling
+ * scsi_device_put(@sdev).
*/
-static bool __must_check alua_rtpg_queue(struct alua_port_group *pg,
- struct scsi_device *sdev,
+static bool alua_rtpg_queue(struct alua_port_group *pg,
+ struct scsi_device *sdev, bool *put_sdev,
struct alua_queue_data *qdata, bool force)
{
int start_queue = 0;
unsigned long flags;
+
+ *put_sdev = false;
+
if (WARN_ON_ONCE(!pg) || scsi_device_get(sdev))
return false;
+ *put_sdev = true;
+
spin_lock_irqsave(&pg->lock, flags);
if (qdata) {
list_add_tail(&qdata->entry, &pg->rtpg_list);
@@ -1020,7 +1026,7 @@ static bool __must_check alua_rtpg_queue(struct alua_port_group *pg,
if (start_queue) {
if (queue_delayed_work(kaluad_wq, &pg->rtpg_work,
msecs_to_jiffies(ALUA_RTPG_DELAY_MSECS)))
- sdev = NULL;
+ *put_sdev = false;
else
kref_put(&pg->kref, release_port_group);
}
@@ -1108,6 +1114,7 @@ static int alua_activate(struct scsi_device *sdev,
int err = SCSI_DH_OK;
struct alua_queue_data *qdata;
struct alua_port_group *pg;
+ bool put_sdev;
qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
if (!qdata) {
@@ -1130,8 +1137,9 @@ static int alua_activate(struct scsi_device *sdev,
rcu_read_unlock();
mutex_unlock(&h->init_mutex);
- if (alua_rtpg_queue(pg, sdev, qdata, true)) {
- scsi_device_put(sdev);
+ if (alua_rtpg_queue(pg, sdev, &put_sdev, qdata, true)) {
+ if (put_sdev)
+ scsi_device_put(sdev);
fn = NULL;
} else {
err = SCSI_DH_DEV_OFFLINED;
@@ -1153,6 +1161,7 @@ static void alua_check(struct scsi_device *sdev, bool force)
{
struct alua_dh_data *h = sdev->handler_data;
struct alua_port_group *pg;
+ bool put_sdev;
rcu_read_lock();
pg = rcu_dereference(h->pg);
@@ -1161,8 +1170,8 @@ static void alua_check(struct scsi_device *sdev, bool force)
return;
}
rcu_read_unlock();
-
- if (alua_rtpg_queue(pg, sdev, NULL, force))
+ alua_rtpg_queue(pg, sdev, &put_sdev, NULL, force);
+ if (put_sdev)
scsi_device_put(sdev);
kref_put(&pg->kref, release_port_group);
}
next reply other threads:[~2022-11-15 22:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 22:49 Bart Van Assche [this message]
2022-11-16 10:32 ` [PATCH] scsi: alua: Fix alua_rtpg_queue() Martin Wilck
2022-11-16 21:22 ` Bart Van Assche
2022-11-17 7:03 ` Martin Wilck
2022-11-17 17:57 ` Bart Van Assche
2022-11-17 17:57 ` Benjamin Block
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221115224903.2325529-1-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mwilck@suse.com \
--cc=sachinp@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox