Browse Source

scsi_transport_sas: add is_sas_attached() function

Adds a function designed to be callable any time (regardless of
whether the transport attributes are configured or not) which returns
true if the device is attached over a SAS transport.  The design of
this function is that transport specific functions can be embedded
within a

if (is_sas_attached(sdev)) {
	...
}

which would be compiled out (and thus eliminate the symbols) if SAS is
not configured.

Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
James Bottomley 9 years ago
parent
commit
3b91d09c1c
2 changed files with 25 additions and 0 deletions
  1. 16 0
      drivers/scsi/scsi_transport_sas.c
  2. 9 0
      include/scsi/scsi_transport_sas.h

+ 16 - 0
drivers/scsi/scsi_transport_sas.c

@@ -340,6 +340,22 @@ static int do_sas_phy_delete(struct device *dev, void *data)
 	return 0;
 }
 
+/**
+ * is_sas_attached - check if device is SAS attached
+ * @sdev: scsi device to check
+ *
+ * returns true if the device is SAS attached
+ */
+int is_sas_attached(struct scsi_device *sdev)
+{
+	struct Scsi_Host *shost = sdev->host;
+
+	return shost->transportt->host_attrs.ac.class ==
+		&sas_host_class.class;
+}
+EXPORT_SYMBOL(is_sas_attached);
+
+
 /**
  * sas_remove_children  -  tear down a devices SAS data structures
  * @dev:	device belonging to the sas object

+ 9 - 0
include/scsi/scsi_transport_sas.h

@@ -10,6 +10,15 @@ struct scsi_transport_template;
 struct sas_rphy;
 struct request;
 
+#if !IS_ENABLED(CONFIG_SCSI_SAS_ATTRS)
+static inline int is_sas_attached(struct scsi_device *sdev)
+{
+	return 0;
+}
+#else
+extern int is_sas_attached(struct scsi_device *sdev);
+#endif
+
 static inline int sas_protocol_ata(enum sas_protocol proto)
 {
 	return ((proto & SAS_PROTOCOL_SATA) ||