Add a core version of alua_check_tpgs() from scsi_sh_alua.c

Signed-off-by: John Garry <[email protected]>
---
 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


Reply via email to