Provide callbacks for .is_disabled, .is_optimized, and .available_path.

These all use scsi_device.sdev_state and scsi_device.access_state.

Member scsi_device.access_state will be driven by ALUA. Currently
only device handlers support this, and in future we will have core
SCSI support for implicit ALUA (not relying on device handlers).

Signed-off-by: John Garry <[email protected]>
---
 drivers/scsi/scsi_multipath.c | 46 +++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c
index f22e3677cf2ad..d8ea9ffe8942c 100644
--- a/drivers/scsi/scsi_multipath.c
+++ b/drivers/scsi/scsi_multipath.c
@@ -301,7 +301,53 @@ static struct bio *scsi_mpath_clone_bio(struct bio *bio)
        return clone;
 }
 
+static bool scsi_mpath_is_disabled(struct mpath_device *mpath_device)
+{
+       struct scsi_mpath_device *scsi_mpath_dev =
+                               to_scsi_mpath_device(mpath_device);
+       struct scsi_device *sdev = scsi_mpath_dev->sdev;
+       unsigned char access_state = READ_ONCE(sdev->access_state);
+
+       if (sdev->sdev_state != SDEV_RUNNING)
+               return true;
+
+       if (access_state == SCSI_ACCESS_STATE_OPTIMAL ||
+           access_state == SCSI_ACCESS_STATE_ACTIVE)
+               return false;
+
+       return true;
+}
+
+static bool scsi_mpath_is_optimized(struct mpath_device *mpath_device)
+{
+       struct scsi_mpath_device *scsi_mpath_dev =
+                               to_scsi_mpath_device(mpath_device);
+       struct scsi_device *sdev = scsi_mpath_dev->sdev;
+
+       if (sdev->sdev_state != SDEV_RUNNING)
+               return false;
+
+       return READ_ONCE(sdev->access_state) == SCSI_ACCESS_STATE_OPTIMAL;
+}
+
+static bool scsi_mpath_available_path(struct mpath_device *mpath_device)
+{
+       struct scsi_mpath_device *scsi_mpath_dev =
+                               to_scsi_mpath_device(mpath_device);
+       struct scsi_device *sdev = scsi_mpath_dev->sdev;
+       enum scsi_device_state sdev_state = sdev->sdev_state;
+
+       if (sdev_state == SDEV_RUNNING || sdev_state == SDEV_QUIESCE ||
+           sdev_state == SDEV_BLOCK || sdev_state == SDEV_CREATED_BLOCK)
+               return true;
+
+       return false;
+}
+
 static struct mpath_head_template smpdt = {
+       .is_disabled = scsi_mpath_is_disabled,
+       .is_optimized = scsi_mpath_is_optimized,
+       .available_path = scsi_mpath_available_path,
        .clone_bio = scsi_mpath_clone_bio,
 };
 
-- 
2.43.7


Reply via email to