[openib-general] SRP [PATCH 4/4] show_srp_state

Ishai Rabinovitz ishai at mellanox.co.il
Mon Jun 5 08:36:06 PDT 2006


Add query for srp_state in sysfs.
Signed-off-by: Ishai Rabinovitz <ishai at mellanox.co.il>
Index: last_stable/drivers/infiniband/ulp/srp/ib_srp.c
===================================================================
--- last_stable.orig/drivers/infiniband/ulp/srp/ib_srp.c	2006-05-31 18:52:14.000000000 +0300
+++ last_stable/drivers/infiniband/ulp/srp/ib_srp.c	2006-06-04 14:21:52.000000000 +0300
@@ -1362,6 +1362,26 @@ static int srp_reset_host(struct scsi_cm
 	return ret;
 }
 
+static ssize_t show_srp_state(struct class_device *cdev, char *buf)
+{
+	struct srp_target_port *target = host_to_target(class_to_shost(cdev));
+	enum srp_target_state target_state = target->state;
+
+	static const char *state_name[] = {
+		[SRP_TARGET_LIVE]		= "LIVE",
+		[SRP_TARGET_CONNECTING]		= "CONNECTING",
+		[SRP_TARGET_DISCONNECTING]	= "DISCONNECTING",
+		[SRP_TARGET_DISCONNECTED]	= "DISCONNECTED",
+		[SRP_TARGET_DEAD]		= "DEAD",
+		[SRP_TARGET_REMOVED]		= "REMOVED",
+	};
+
+	if (target_state >= 0 && target_state < ARRAY_SIZE(state_name))
+		return sprintf(buf, "%s\n", state_name[target_state]);
+
+	return sprintf(buf, "UNKNOWN\n");
+}
+
 static ssize_t show_id_ext(struct class_device *cdev, char *buf)
 {
 	struct srp_target_port *target = host_to_target(class_to_shost(cdev));
@@ -1439,6 +1459,7 @@ static ssize_t show_zero_req_lim(struct 
 
 static CLASS_DEVICE_ATTR(remove_target,  S_IWUSR, NULL, srp_remove_target);
 static CLASS_DEVICE_ATTR(restore_target, S_IWUSR, NULL, srp_restore_target);
+static CLASS_DEVICE_ATTR(srp_state,	 S_IRUGO, show_srp_state,	NULL);
 static CLASS_DEVICE_ATTR(id_ext,	 S_IRUGO, show_id_ext,		NULL);
 static CLASS_DEVICE_ATTR(ioc_guid,	 S_IRUGO, show_ioc_guid,	NULL);
 static CLASS_DEVICE_ATTR(service_id,	 S_IRUGO, show_service_id,	NULL);
@@ -1447,6 +1468,7 @@ static CLASS_DEVICE_ATTR(dgid,		S_IRUGO,
 static struct class_device_attribute *srp_host_attrs[] = {
 	&class_device_attr_remove_target,
 	&class_device_attr_restore_target,
+	&class_device_attr_srp_state,
 	&class_device_attr_id_ext,
 	&class_device_attr_ioc_guid,
 	&class_device_attr_service_id,
-- 
Ishai Rabinovitz



More information about the general mailing list