On 3/17/26 13:07, John Garry wrote:
Add a core version of alua_prep_fn() from scsi_dh_alua.c

Signed-off-by: John Garry <[email protected]>
---
  drivers/scsi/scsi_alua.c | 23 +++++++++++++++++++++++
  include/scsi/scsi_alua.h |  8 ++++++++
  2 files changed, 31 insertions(+)

diff --git a/drivers/scsi/scsi_alua.c b/drivers/scsi/scsi_alua.c
index d19d1845bc324..c269105dbae4a 100644
--- a/drivers/scsi/scsi_alua.c
+++ b/drivers/scsi/scsi_alua.c
@@ -608,6 +608,29 @@ void scsi_alua_sdev_exit(struct scsi_device *sdev)
        sdev->alua = NULL;
  }
+blk_status_t scsi_alua_prep_fn(struct scsi_device *sdev, struct request *req)
+{
+       struct alua_data *alua = sdev->alua;
+       unsigned long flags;
+       unsigned char state;
+
+       spin_lock_irqsave(&alua->lock, flags);
+       state = alua->state;
+       spin_unlock_irqrestore(&alua->lock, flags);
+
+       switch (state) {
+       case SCSI_ACCESS_STATE_OPTIMAL:
+       case SCSI_ACCESS_STATE_ACTIVE:
+       case SCSI_ACCESS_STATE_LBA:
+       case SCSI_ACCESS_STATE_TRANSITIONING:
+               return BLK_STS_OK;
+       default:
+               req->rq_flags |= RQF_QUIET;
+               return BLK_STS_IOERR;
+       }
+}
+EXPORT_SYMBOL_GPL(scsi_alua_prep_fn);
+
  int scsi_alua_init(void)
  {
        kalua_wq = alloc_workqueue("kalua", WQ_MEM_RECLAIM | WQ_PERCPU, 0);
diff --git a/include/scsi/scsi_alua.h b/include/scsi/scsi_alua.h
index 5b3a12861658f..c16d4adc915ec 100644
--- a/include/scsi/scsi_alua.h
+++ b/include/scsi/scsi_alua.h
@@ -8,6 +8,7 @@
  #ifndef _SCSI_ALUA_H
  #define _SCSI_ALUA_H
+#include <linux/blk-mq.h>
  #include <scsi/scsi.h>
  #include <scsi/scsi_device.h>
@@ -37,6 +38,8 @@ 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);
+blk_status_t scsi_alua_prep_fn(struct scsi_device *sdev, struct request *req);
+
  int scsi_alua_init(void);
  void scsi_exit_alua(void);
  #else //CONFIG_SCSI_ALUA
@@ -56,6 +59,11 @@ static inline int scsi_alua_stpg_run(struct scsi_device 
*sdev, bool optimize)
  {
        return 0;
  }
+static inline
+blk_status_t scsi_alua_prep_fn(struct scsi_device *sdev, struct request *req)
+{
+       return BLK_STS_OK;
+}
  static inline int scsi_alua_sdev_init(struct scsi_device *sdev)
  {
        return 0;

Hmm. The 'prep_fn' thingie was implemented such that other drivers (like scsi_dh) could intercept the scsi prep function and inject their own
stuff. But now with this patchset the functionality is in the scsi core,
so really we should do away with the prep_fn here and call the functions
directly.

Cheers,

Hannes
--
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +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

Reply via email to