Add a function to run stpg and handle error codes - it does equivalent
handling as in alua_rtpg_work() from scsi_dh_alua.c

Signed-off-by: John Garry <[email protected]>
---
 drivers/scsi/scsi_alua.c | 20 +++++++++++++++++++-
 include/scsi/scsi_alua.h |  5 +++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_alua.c b/drivers/scsi/scsi_alua.c
index e4cb43ba645fa..4e20a537a4ad6 100644
--- a/drivers/scsi/scsi_alua.c
+++ b/drivers/scsi/scsi_alua.c
@@ -428,7 +428,6 @@ EXPORT_SYMBOL_GPL(scsi_alua_rtpg_run);
  * a re-evaluation of the target group state or SCSI_DH_OK
  * if no further action needs to be taken.
  */
-__maybe_unused
 static int scsi_alua_stpg(struct scsi_device *sdev, bool optimize)
 {
        struct alua_data *alua = sdev->alua;
@@ -480,6 +479,25 @@ static int scsi_alua_stpg(struct scsi_device *sdev, bool 
optimize)
        return -EAGAIN;//SCSI_DH_RETRY;
 }
 
+int scsi_alua_stpg_run(struct scsi_device *sdev, bool optimize)
+{
+       struct alua_data *alua = sdev->alua;
+       unsigned long flags;
+       int err;
+
+       err = scsi_alua_stpg(sdev, optimize);
+       spin_lock_irqsave(&alua->lock, flags);
+       if (err == EAGAIN) {
+               alua->interval = 0;
+               spin_unlock_irqrestore(&alua->lock, flags);
+               return -EAGAIN;
+       }
+       spin_unlock_irqrestore(&alua->lock, flags);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(scsi_alua_stpg_run);
+
 int scsi_alua_sdev_init(struct scsi_device *sdev)
 {
        int rel_port, ret, tpgs;
diff --git a/include/scsi/scsi_alua.h b/include/scsi/scsi_alua.h
index 1eb5481f40bd4..6e4f262bbfbc0 100644
--- a/include/scsi/scsi_alua.h
+++ b/include/scsi/scsi_alua.h
@@ -31,6 +31,7 @@ int scsi_alua_sdev_init(struct scsi_device *sdev);
 void scsi_alua_sdev_exit(struct scsi_device *sdev);
 
 int scsi_alua_rtpg_run(struct scsi_device *sdev);
+int scsi_alua_stpg_run(struct scsi_device *sdev, bool optimize);
 
 int scsi_alua_init(void);
 void scsi_exit_alua(void);
@@ -40,6 +41,10 @@ static inline int scsi_alua_rtpg_run(struct scsi_device 
*sdev)
 {
        return 0;
 }
+static inline int scsi_alua_stpg_run(struct scsi_device *sdev, bool optimize)
+{
+       return 0;
+}
 static inline int scsi_alua_sdev_init(struct scsi_device *sdev)
 {
        return 0;
-- 
2.43.5


Reply via email to