[PATCH 08/13] scsi: alua: Add scsi_alua_check_tpgs()

John Garry posted 13 patches 2 weeks, 6 days ago
[PATCH 08/13] scsi: alua: Add scsi_alua_check_tpgs()
Posted by John Garry 2 weeks, 6 days ago
Add a core version of alua_check_tpgs() from scsi_sh_alua.c

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/scsi/scsi_alua.c | 53 ++++++++++++++++++++++++++++++++++++++++
 include/scsi/scsi_alua.h |  6 +++++
 2 files changed, 59 insertions(+)

diff --git a/drivers/scsi/scsi_alua.c b/drivers/scsi/scsi_alua.c
index 4e20a537a4ad6..9c317e60d031e 100644
--- a/drivers/scsi/scsi_alua.c
+++ b/drivers/scsi/scsi_alua.c
@@ -128,6 +128,59 @@ static int submit_stpg(struct scsi_device *sdev,
 				ALUA_FAILOVER_RETRIES, &exec_args);
 }
 
+/*
+ * scsi_alua_check_tpgs - Evaluate TPGS setting
+ * @sdev: device to be checked
+ *
+ * Examine the TPGS setting of the sdev to find out if ALUA
+ * is supported.
+ */
+int scsi_alua_check_tpgs(struct scsi_device *sdev)
+{
+	int tpgs = TPGS_MODE_NONE;
+
+	/*
+	 * ALUA support for non-disk devices is fraught with
+	 * difficulties, so disable it for now.
+	 */
+	if (sdev->type != TYPE_DISK) {
+		sdev_printk(KERN_INFO, sdev,
+			    "%s: disable for non-disk devices\n",
+			    DRV_NAME);
+		return tpgs;
+	}
+
+	tpgs = scsi_device_tpgs(sdev);
+	switch (tpgs) {
+	case TPGS_MODE_EXPLICIT|TPGS_MODE_IMPLICIT:
+		sdev_printk(KERN_INFO, sdev,
+			    "%s: supports implicit and explicit TPGS\n",
+			    DRV_NAME);
+		break;
+	case TPGS_MODE_EXPLICIT:
+		sdev_printk(KERN_INFO, sdev, "%s: supports explicit TPGS\n",
+			    DRV_NAME);
+		break;
+	case TPGS_MODE_IMPLICIT:
+		sdev_printk(KERN_INFO, sdev, "%s: supports implicit TPGS\n",
+			    DRV_NAME);
+		break;
+	case TPGS_MODE_NONE:
+		sdev_printk(KERN_INFO, sdev, "%s: not supported\n",
+			    DRV_NAME);
+		break;
+	default:
+		sdev_printk(KERN_INFO, sdev,
+			    "%s: unsupported TPGS setting %d\n",
+			    DRV_NAME, tpgs);
+		tpgs = TPGS_MODE_NONE;
+		break;
+	}
+
+	return tpgs;
+}
+EXPORT_SYMBOL_GPL(scsi_alua_check_tpgs);
+
 static char print_alua_state(unsigned char state)
 {
 	switch (state) {
diff --git a/include/scsi/scsi_alua.h b/include/scsi/scsi_alua.h
index 6e4f262bbfbc0..2e664f20d9681 100644
--- a/include/scsi/scsi_alua.h
+++ b/include/scsi/scsi_alua.h
@@ -30,6 +30,8 @@ struct alua_data {
 int scsi_alua_sdev_init(struct scsi_device *sdev);
 void scsi_alua_sdev_exit(struct scsi_device *sdev);
 
+int scsi_alua_check_tpgs(struct scsi_device *sdev);
+
 int scsi_alua_rtpg_run(struct scsi_device *sdev);
 int scsi_alua_stpg_run(struct scsi_device *sdev, bool optimize);
 
@@ -37,6 +39,10 @@ int scsi_alua_init(void);
 void scsi_exit_alua(void);
 #else //CONFIG_SCSI_ALUA
 
+static inline int scsi_alua_check_tpgs(struct scsi_device *sdev)
+{
+	return 0;
+}
 static inline int scsi_alua_rtpg_run(struct scsi_device *sdev)
 {
 	return 0;
-- 
2.43.5
Re: [PATCH 08/13] scsi: alua: Add scsi_alua_check_tpgs()
Posted by Hannes Reinecke 2 weeks, 5 days ago
On 3/17/26 13:06, John Garry wrote:
> Add a core version of alua_check_tpgs() from scsi_sh_alua.c
> 
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>   drivers/scsi/scsi_alua.c | 53 ++++++++++++++++++++++++++++++++++++++++
>   include/scsi/scsi_alua.h |  6 +++++
>   2 files changed, 59 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich