diff mbox

[4/5] scsi_dh_alua: add 'state' callback function

Message ID 1436353788-104911-5-git-send-email-hare@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Hannes Reinecke July 8, 2015, 11:09 a.m. UTC
Add a 'state' callback function to display the current path
status in sysfs.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/device_handler/scsi_dh_alua.c | 47 ++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

Comments

Christoph Hellwig July 24, 2015, 2:42 p.m. UTC | #1
As per the comment on patch 3 I'd rather expose the ALUA state in the core
SCSI code.  But having this alua_state attribute in core SCSI code sounds
fine to me.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hannes Reinecke July 25, 2015, 3:42 p.m. UTC | #2
On 07/24/2015 04:42 PM, Christoph Hellwig wrote:
> As per the comment on patch 3 I'd rather expose the ALUA state in the core
> SCSI code.  But having this alua_state attribute in core SCSI code sounds
> fine to me.
> 
Sure, we can have an attribute 'alua_state' in the core code; after all,
ALUA is pretty much standard by now.

Cheers,

Hannes
diff mbox

Patch

diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 5b52017..99c4b0f 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -1182,6 +1182,52 @@  static void alua_check(struct scsi_device *sdev, bool force)
 }
 
 /*
+ * alua_state - report path status
+ * @sdev: device on the path to be checked
+ *
+ * Check the device status
+ */
+static int alua_state(struct scsi_device *sdev)
+{
+	struct alua_dh_data *h = sdev->handler_data;
+	struct alua_port_group *pg = NULL;
+	int access_state = SCSI_ACCESS_STATE_UNKNOWN;
+
+	rcu_read_lock();
+	if (h)
+		pg = rcu_dereference(h->pg);
+	if (pg) {
+		switch (pg->state) {
+		case TPGS_STATE_OPTIMIZED:
+			access_state = SCSI_ACCESS_STATE_OPTIMAL;
+			break;
+		case TPGS_STATE_NONOPTIMIZED:
+			access_state = SCSI_ACCESS_STATE_ACTIVE;
+			break;
+		case TPGS_STATE_STANDBY:
+			access_state = SCSI_ACCESS_STATE_PASSIVE;
+			break;
+		case TPGS_STATE_UNAVAILABLE:
+			access_state = SCSI_ACCESS_STATE_UNAVAILABLE;
+			break;
+		case TPGS_STATE_LBA_DEPENDENT:
+			access_state = SCSI_ACCESS_STATE_LBA;
+			break;
+		case TPGS_STATE_OFFLINE:
+			access_state = SCSI_ACCESS_STATE_OFFLINE;
+			break;
+		case TPGS_STATE_TRANSITIONING:
+			access_state = SCSI_ACCESS_STATE_TRANSITIONING;
+			break;
+		}
+		if (pg->pref)
+			access_state |= SCSI_ACCESS_STATE_PREFERRED;
+	}
+	rcu_read_unlock();
+	return access_state;
+}
+
+/*
  * alua_prep_fn - request callback
  *
  * Fail I/O to all paths not in state
@@ -1288,6 +1334,7 @@  static struct scsi_device_handler alua_dh = {
 	.activate = alua_activate,
 	.rescan = alua_rescan,
 	.set_params = alua_set_params,
+	.state = alua_state,
 };
 
 static int __init alua_init(void)