From: Brian Bunker <brian@purestorage.com>
To: linux-scsi@vger.kernel.org
Cc: "Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
Hannes Reinecke <hare@kernel.org>,
Bart Van Assche <bvanassche@acm.org>,
Krishna Kant <krishna.kant@purestorage.com>
Subject: [PATCH v2 1/4] scsi: core: Move REPORT TARGET PORT GROUPS into the SCSI core
Date: Wed, 28 Oct 2026 16:08:04 -0700 [thread overview]
Message-ID: <20261028230807.61578-2-brian@purestorage.com> (raw)
In-Reply-To: <20261028230807.61578-1-brian@purestorage.com>
ALUA is a standard SCSI feature, independent of multipathing, but only
the ALUA device handler can currently send REPORT TARGET PORT GROUPS.
Move submit_rtpg() into the SCSI core as scsi_report_tpgs(), together
with the resubmission with a larger buffer that alua_rtpg() did when
the parameter data did not fit, so that the core can read the ALUA
state of a device itself. The parameter data format definitions move to
scsi_proto.h with it.
scsi_dh_alua calls scsi_report_tpgs() with the same timeout, retries
and parameter data format as before.
No functional change.
Suggested-by: Hannes Reinecke <hare@kernel.org>
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/device_handler/scsi_dh_alua.c | 63 ++++++----------------
drivers/scsi/scsi_lib.c | 52 ++++++++++++++++++
include/scsi/scsi_device.h | 3 ++
include/scsi/scsi_proto.h | 3 ++
4 files changed, 73 insertions(+), 48 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 87ac0a6d63e5..06eb35cc9d7c 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -29,9 +29,6 @@
#define TPGS_SUPPORT_TRANSITION 0x80
#define TPGS_SUPPORT_ALL 0xdf
-#define RTPG_FMT_MASK 0x70
-#define RTPG_FMT_EXT_HDR 0x10
-
#define TPGS_MODE_UNINITIALIZED -1
#define TPGS_MODE_NONE 0x0
#define TPGS_MODE_IMPLICIT 0x1
@@ -120,34 +117,6 @@ static void release_port_group(struct kref *kref)
kfree_rcu(pg, rcu);
}
-/*
- * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
- * @sdev: sdev the command should be sent to
- */
-static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff,
- int bufflen, struct scsi_sense_hdr *sshdr, int flags)
-{
- u8 cdb[MAX_COMMAND_SIZE];
- blk_opf_t opf = REQ_OP_DRV_IN | REQ_FAILFAST_DEV |
- REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER;
- const struct scsi_exec_args exec_args = {
- .sshdr = sshdr,
- };
-
- /* Prepare the command. */
- memset(cdb, 0x0, MAX_COMMAND_SIZE);
- cdb[0] = MAINTENANCE_IN;
- if (!(flags & ALUA_RTPG_EXT_HDR_UNSUPP))
- cdb[1] = MI_REPORT_TARGET_PGS | MI_EXT_HDR_PARAM_FMT;
- else
- cdb[1] = MI_REPORT_TARGET_PGS;
- put_unaligned_be32(bufflen, &cdb[6]);
-
- return scsi_execute_cmd(sdev, cdb, opf, buff, bufflen,
- ALUA_FAILOVER_TIMEOUT * HZ,
- ALUA_FAILOVER_RETRIES, &exec_args);
-}
-
/*
* submit_stpg - Issue a SET TARGET PORT GROUP command
*
@@ -518,6 +487,9 @@ static int alua_tur(struct scsi_device *sdev)
static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
{
struct scsi_sense_hdr sense_hdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sense_hdr,
+ };
struct alua_port_group *tmp_pg;
int len, k, off, bufflen = ALUA_RTPG_SIZE;
int group_id_old, state_old, pref_old, valid_states_old;
@@ -549,7 +521,17 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
retry:
err = 0;
- retval = submit_rtpg(sdev, buff, bufflen, &sense_hdr, pg->flags);
+ retval = scsi_report_tpgs(sdev, &buff, &bufflen,
+ !(pg->flags & ALUA_RTPG_EXT_HDR_UNSUPP),
+ ALUA_FAILOVER_TIMEOUT * HZ,
+ ALUA_FAILOVER_RETRIES, &exec_args);
+ if (!buff) {
+ sdev_printk(KERN_WARNING, sdev,
+ "%s: kmalloc buffer failed\n", __func__);
+ /* Temporary failure, bypass */
+ pg->expiry = 0;
+ return SCSI_DH_DEV_TEMP_BUSY;
+ }
if (retval) {
/*
@@ -581,7 +563,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
}
/*
- * submit_rtpg() has failed on existing arrays
+ * scsi_report_tpgs() has failed on existing arrays
* when requesting extended header info, and
* the array doesn't support extended headers,
* even though it shouldn't according to T10.
@@ -629,21 +611,6 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
len = get_unaligned_be32(&buff[0]) + 4;
- if (len > bufflen) {
- /* Resubmit with the correct length */
- kfree(buff);
- bufflen = len;
- buff = kmalloc(bufflen, GFP_KERNEL);
- if (!buff) {
- sdev_printk(KERN_WARNING, sdev,
- "%s: kmalloc buffer failed\n",__func__);
- /* Temporary failure, bypass */
- pg->expiry = 0;
- return SCSI_DH_DEV_TEMP_BUSY;
- }
- goto retry;
- }
-
orig_transition_tmo = pg->transition_tmo;
if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && buff[5] != 0)
pg->transition_tmo = buff[5];
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f695a6605815..ebbfe3238d97 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3581,6 +3581,58 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
}
EXPORT_SYMBOL(scsi_vpd_tpg_id);
+/**
+ * scsi_report_tpgs - Issue a REPORT TARGET PORT GROUPS command
+ * @sdev: SCSI device to send the command to
+ * @buff: buffer for the parameter data, replaced if it is too small
+ * @bufflen: length of @buff
+ * @ext_hdr: request the extended header parameter data format
+ * @timeout: command timeout in jiffies
+ * @retries: number of times to retry the command in the midlayer
+ * @args: optional arguments for scsi_execute_cmd()
+ *
+ * Resend the command with a larger buffer if the parameter data does not
+ * fit.
+ *
+ * Return: the result of the last command, or -ENOMEM with *@buff set to
+ * NULL if a larger buffer could not be allocated.
+ */
+int scsi_report_tpgs(struct scsi_device *sdev, unsigned char **buff,
+ int *bufflen, bool ext_hdr, int timeout, int retries,
+ const struct scsi_exec_args *args)
+{
+ blk_opf_t opf = REQ_OP_DRV_IN | REQ_FAILFAST_DEV |
+ REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER;
+ u8 cdb[MAX_COMMAND_SIZE] = { };
+ int ret, len;
+
+ cdb[0] = MAINTENANCE_IN;
+ cdb[1] = MI_REPORT_TARGET_PGS;
+ if (ext_hdr)
+ cdb[1] |= MI_EXT_HDR_PARAM_FMT;
+
+ retry:
+ put_unaligned_be32(*bufflen, &cdb[6]);
+ ret = scsi_execute_cmd(sdev, cdb, opf, *buff, *bufflen, timeout,
+ retries, args);
+ if (ret)
+ return ret;
+
+ len = get_unaligned_be32(&(*buff)[0]) + 4;
+ if (len > *bufflen) {
+ /* Resubmit with the correct length */
+ kfree(*buff);
+ *bufflen = len;
+ *buff = kmalloc(len, GFP_KERNEL);
+ if (!*buff)
+ return -ENOMEM;
+ goto retry;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(scsi_report_tpgs);
+
/**
* scsi_set_sense - build sense data for a command
* @scmd: scsi command for which the sense should be formatted
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index e6fd6bc30644..691275db0677 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -583,6 +583,9 @@ extern void sdev_enable_disk_events(struct scsi_device *sdev);
extern int scsi_vpd_lun_id(struct scsi_device *, char *, size_t);
extern int scsi_vpd_lun_serial(struct scsi_device *, char *, size_t);
extern int scsi_vpd_tpg_id(struct scsi_device *, int *);
+int scsi_report_tpgs(struct scsi_device *sdev, unsigned char **buff,
+ int *bufflen, bool ext_hdr, int timeout, int retries,
+ const struct scsi_exec_args *args);
#ifdef CONFIG_PM
extern int scsi_autopm_get_device(struct scsi_device *);
diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h
index 9c7d31aa6bae..6826f2d74407 100644
--- a/include/scsi/scsi_proto.h
+++ b/include/scsi/scsi_proto.h
@@ -145,6 +145,9 @@
#define MI_MANAGEMENT_PROTOCOL_IN 0x10
/* value for MI_REPORT_TARGET_PGS ext header */
#define MI_EXT_HDR_PARAM_FMT 0x20
+/* format field in byte 4 of the REPORT TARGET PORT GROUPS parameter data */
+#define RTPG_FMT_MASK 0x70
+#define RTPG_FMT_EXT_HDR 0x10
/* values for maintenance out */
#define MO_SET_IDENTIFYING_INFORMATION 0x06
#define MO_SET_TARGET_PGS 0x0a
--
2.56.0
next prev parent reply other threads:[~2026-10-28 23:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 23:08 [PATCH v2 0/4] scsi: Bind sd to LUs in the ALUA unavailable state Brian Bunker
2026-10-28 23:08 ` Brian Bunker [this message]
2026-10-28 23:08 ` [PATCH v2 2/4] scsi: core: Read the ALUA access state when a device is scanned Brian Bunker
2026-10-28 23:08 ` [PATCH v2 3/4] scsi: scsi_dh_alua: Start a port group in the scanned access state Brian Bunker
2026-10-28 23:19 ` sashiko-bot
2026-10-28 23:08 ` [PATCH v2 4/4] scsi: core: Match ULDs to logical units in the ALUA unavailable state Brian Bunker
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=20261028230807.61578-2-brian@purestorage.com \
--to=brian@purestorage.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bvanassche@acm.org \
--cc=hare@kernel.org \
--cc=krishna.kant@purestorage.com \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
/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