[SCSI] zfcp: Add port_state attribute to sysfs
authorSven Schuetz <sven@linux.vnet.ibm.com>
Tue, 10 Jun 2008 16:20:59 +0000 (18:20 +0200)
committerJames Bottomley <James.Bottomley@HansenPartnership.com>
Sat, 12 Jul 2008 13:22:26 +0000 (08:22 -0500)
The sysfs attribute /sys/class/fc_host/hostX/port_state was not set by
zfcp so far.

Now, the appropriate members of the fc_function_template struct are
set during its initialziation. The first is a boolean to show the port
state. The second is a function pointer to the function
zfcp_get_host_port_state, which reads the port state from our adapter
status bits and calls fc_host_port_state with the approriate port
state afterwards.

Signed-off-by: Sven Schuetz <sven@linux.vnet.ibm.com>
Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
drivers/s390/scsi/zfcp_scsi.c

index a96e5c3b9460cdbe9d3f0e9158e79509bd6a07a6..446fb1da25df36fb25978e4a042a03e694e85812 100644 (file)
@@ -704,6 +704,23 @@ zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
        }
 }
 
+static void zfcp_get_host_port_state(struct Scsi_Host *shost)
+{
+       struct zfcp_adapter *adapter =
+               (struct zfcp_adapter *)shost->hostdata[0];
+       int status = atomic_read(&adapter->status);
+
+       if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
+           !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED))
+               fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
+       else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
+               fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
+       else if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
+               fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
+       else
+               fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
+}
+
 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
 {
        rport->dev_loss_tmo = timeout;
@@ -726,6 +743,8 @@ struct fc_function_template zfcp_transport_functions = {
        .get_fc_host_stats = zfcp_get_fc_host_stats,
        .reset_fc_host_stats = zfcp_reset_fc_host_stats,
        .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
+       .get_host_port_state = zfcp_get_host_port_state,
+       .show_host_port_state = 1,
        /* no functions registered for following dynamic attributes but
           directly set by LLDD */
        .show_host_port_type = 1,