From: Brian Bunker <brian@purestorage.com>
To: linux-scsi@vger.kernel.org
Cc: James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, hare@suse.de, bvanassche@acm.org,
krishna.kant@purestorage.com
Subject: [PATCH v5 5/5] scsi: core: Handle reprobe for existing devices during SCSI scan
Date: Thu, 18 Jun 2026 16:35:04 -0700 [thread overview]
Message-ID: <20260618233508.97960-6-brian@purestorage.com> (raw)
In-Reply-To: <20260618233508.97960-1-brian@purestorage.com>
Complement scsi_rescan_device() reprobe by handling the scan path.
Update INQUIRY data and reprobe existing devices when standard INQUIRY
data changed.
Co-developed-by: Krishna Kant <krishna.kant@purestorage.com>
Signed-off-by: Krishna Kant <krishna.kant@purestorage.com>
Signed-off-by: Brian Bunker <brian@purestorage.com>
---
drivers/scsi/scsi_scan.c | 91 ++++++++++++++++++++++++++++++++++++----
1 file changed, 83 insertions(+), 8 deletions(-)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index e03a209b7bc2..81c12f557bba 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1207,6 +1207,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
blist_flags_t bflags;
int res = SCSI_SCAN_NO_RESPONSE, result_len = 256;
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
+ bool is_reprobe = false;
/*
* The rescan flag is used as an optimization, the first scan of a
@@ -1214,7 +1215,32 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
*/
sdev = scsi_device_lookup_by_target(starget, lun);
if (sdev) {
- if (rescan != SCSI_SCAN_INITIAL || !scsi_device_created(sdev)) {
+ if (rescan == SCSI_SCAN_INITIAL && scsi_device_created(sdev)) {
+ /*
+ * Initial scan found device in CREATED state (being probed
+ * by another thread). Drop reference and allocate new -
+ * the other thread will complete setup of the original.
+ */
+ scsi_device_put(sdev);
+ sdev = scsi_alloc_sdev(starget, lun, hostdata);
+ if (!sdev)
+ goto out;
+ } else if (rescan != SCSI_SCAN_INITIAL && !scsi_device_created(sdev)) {
+ /*
+ * Manual rescan of fully initialized device.
+ * Reprobe to detect peripheral qualifier or device type
+ * changes (e.g., ALUA state transitions).
+ */
+ SCSI_LOG_SCAN_BUS(3, sdev_printk(KERN_INFO, sdev,
+ "scsi scan: device exists (type %d, PQ %d), reprobing\n",
+ sdev->type, sdev->inq_periph_qual));
+ is_reprobe = true;
+ } else {
+ /*
+ * Either initial scan with fully initialized device,
+ * or manual rescan with device still in CREATED state.
+ * Return that device exists.
+ */
SCSI_LOG_SCAN_BUS(3, sdev_printk(KERN_INFO, sdev,
"scsi scan: device exists on %s\n",
dev_name(&sdev->sdev_gendev)));
@@ -1229,11 +1255,11 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
sdev->model);
return SCSI_SCAN_LUN_PRESENT;
}
- scsi_device_put(sdev);
- } else
+ } else {
sdev = scsi_alloc_sdev(starget, lun, hostdata);
- if (!sdev)
- goto out;
+ if (!sdev)
+ goto out;
+ }
if (scsi_device_is_pseudo_dev(sdev)) {
if (bflagsp)
@@ -1248,6 +1274,40 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
if (scsi_probe_lun(sdev, result, result_len, &bflags))
goto out_free_result;
+ /*
+ * For reprobe scenarios, update the inquiry data with fresh
+ * INQUIRY results. The device already exists in sysfs, so we
+ * don't call scsi_add_lun() which would try to add it again.
+ */
+ if (is_reprobe) {
+ bool need_reprobe = false;
+ int update_ret = __scsi_reprobe_inquiry(sdev, result, result_len,
+ &need_reprobe);
+
+ if (update_ret < 0) {
+ res = SCSI_SCAN_NO_RESPONSE;
+ goto out_free_result;
+ }
+
+ if (bflagsp)
+ *bflagsp = bflags;
+
+ /*
+ * If type or PQ changed, reprobe to update driver attachment.
+ * Reprobe failure is not fatal - device exists, just may have
+ * wrong driver attached.
+ */
+ if (need_reprobe) {
+ if (device_reprobe(&sdev->sdev_gendev) < 0)
+ sdev_printk(KERN_WARNING, sdev,
+ "device reprobe failed\n");
+ }
+
+ /* Device already exists, just return success */
+ res = SCSI_SCAN_LUN_PRESENT;
+ goto out_free_result;
+ }
+
if (bflagsp)
*bflagsp = bflags;
/*
@@ -1330,12 +1390,27 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
if (scsi_device_get(sdev) == 0) {
*sdevp = sdev;
} else {
- __scsi_remove_device(sdev);
+ if (!is_reprobe)
+ __scsi_remove_device(sdev);
res = SCSI_SCAN_NO_RESPONSE;
}
}
- } else
- __scsi_remove_device(sdev);
+ /*
+ * For reprobe case, we held a reference from
+ * scsi_device_lookup_by_target(), release it now.
+ */
+ if (is_reprobe)
+ scsi_device_put(sdev);
+ } else {
+ /*
+ * For reprobe, device already exists - don't remove it.
+ * Just release the reference we got from lookup.
+ */
+ if (is_reprobe)
+ scsi_device_put(sdev);
+ else
+ __scsi_remove_device(sdev);
+ }
out:
return res;
}
--
2.54.0
next prev parent reply other threads:[~2026-06-18 23:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 23:34 [PATCH v5 0/5] scsi: Refresh INQUIRY data and reprobe on rescan Brian Bunker
2026-06-18 23:35 ` [PATCH v5 1/5] scsi: core: Protect INQUIRY sysfs attributes with mutex Brian Bunker
2026-06-18 23:35 ` [PATCH v5 2/5] scsi: core: Add scsi_update_inquiry_data() for updating INQUIRY data Brian Bunker
2026-06-18 23:35 ` [PATCH v5 3/5] scsi: core: Refactor scsi_add_lun() to use scsi_update_inquiry_data() Brian Bunker
2026-06-19 6:00 ` Hannes Reinecke
2026-06-18 23:35 ` [PATCH v5 4/5] scsi: core: Add device reprobe support to scsi_rescan_device() Brian Bunker
2026-06-19 6:01 ` Hannes Reinecke
2026-06-18 23:35 ` Brian Bunker [this message]
2026-06-19 6:01 ` [PATCH v5 5/5] scsi: core: Handle reprobe for existing devices during SCSI scan Hannes Reinecke
2026-07-12 21:31 ` [PATCH v5 0/5] scsi: Refresh INQUIRY data and reprobe on rescan Martin K. Petersen
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=20260618233508.97960-6-brian@purestorage.com \
--to=brian@purestorage.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=krishna.kant@purestorage.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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