Allow transport classes to attach to host, target or device
RFC 1/1 Allow transport classes to attach to host, target or device
This is a nice simple patch that makes the transport class a combination of up to three sysfs classes, attaching to host, transport or device. So that the attributes it's exporting may be attached to the correct place.
I also got rid of the cleanup methods since the users of the class make it obvious that these are totally unnecessary (cleanup is done as part of the class release instead).
This compiles and runs, but is really only a sketch of what's planned.
James
drivers/scsi/hosts.c +2 -0
@@ -82,6 +82,8 @@set_bit (SHOST_DEL , &shost->shost_state);class_device_unregister (&shost->shost_classdev); +if (shost->transport_classdev.class) +class_device_unregister (&shost->transport_classdev);device_del (&shost->shost_gendev); }
drivers/scsi/scsi_priv.h +5 -1
@@ -66,13 +66,17 @@struct scsi_target {struct scsi_device *starget_sdev_user;struct device dev; -}; +struct class_device transport_classdev; +unsigned long transport_data[0 ]; +} __attribute__((aligned (sizeof (unsigned long ))));#define to_scsi_target (d) container_of(d, struct scsi_target, dev)static inline struct scsi_target *scsi_target (struct scsi_device *sdev) {return to_scsi_target (sdev->sdev_gendev.parent); } +#define transport_classdev_to_starget (class_dev) \ + container_of(class_dev, struct scsi_target, transport_classdev)/* hosts.c */ extern int scsi_init_hosts (void );
drivers/scsi/scsi_scan.c +5 -11
@@ -205,7 +205,8 @@struct scsi_device *sdev, *device;unsigned long flags; - sdev =kmalloc (sizeof (*sdev) + shost->transportt->size,GFP_ATOMIC ); + sdev =kmalloc (sizeof (*sdev) + shost->transportt->device_size, +GFP_ATOMIC );if (!sdev) goto out;
@@ -256,14 +257,14 @@ goto out_free_queue; } -if (shost->transportt->setup) { -if (shost->transportt->setup (sdev)) +if (shost->transportt->device_setup) { +if (shost->transportt->device_setup (sdev)) goto out_cleanup_slave; }if (get_device (&sdev->host->shost_gendev) ==NULL ||scsi_sysfs_device_initialize (sdev) !=0 ) - goto out_cleanup_transport; + goto out_cleanup_slave;/* * If there are any same target siblings, add this to the
@@ -292,9 +293,6 @@spin_unlock_irqrestore (shost->host_lock, flags);return sdev; -out_cleanup_transport: -if (shost->transportt->cleanup) - shost->transportt->cleanup (sdev); out_cleanup_slave:if (shost->hostt->slave_destroy) shost->hostt->slave_destroy (sdev);
@@ -733,8 +731,6 @@ }else {if (sdev->host->hostt->slave_destroy) sdev->host->hostt->slave_destroy (sdev); -if (sdev->host->transportt->cleanup) - sdev->host->transportt->cleanup (sdev);put_device (&sdev->sdev_gendev); } out:
@@ -1293,7 +1289,5 @@if (sdev->host->hostt->slave_destroy) sdev->host->hostt->slave_destroy (sdev); -if (sdev->host->transportt->cleanup) - sdev->host->transportt->cleanup (sdev);put_device (&sdev->sdev_gendev); }
drivers/scsi/scsi_sysfs.c +42 -8
110 lines not on this page · raw message
drivers/scsi/scsi_transport_fc.c +4 -4
@@ -156,10 +156,10 @@memset (i,0 ,sizeof (struct fc_internal )); - i->t.attrs = &i->attrs[0 ]; - i->t.class = &fc_transport_class; - i->t.setup = &fc_setup_transport_attrs; - i->t.size =sizeof (struct fc_transport_attrs ); + i->t.device_attrs = &i->attrs[0 ]; + i->t.device_class = &fc_transport_class; + i->t.device_setup = &fc_setup_transport_attrs; + i->t.device_size =sizeof (struct fc_transport_attrs ); i->f = ft;SETUP_ATTRIBUTE_RD (port_id);
drivers/scsi/scsi_transport_spi.c +4 -4
@@ -666,10 +666,10 @@memset (i,0 ,sizeof (struct spi_internal )); - i->t.attrs = &i->attrs[0 ]; - i->t.class = &spi_transport_class; - i->t.setup = &spi_setup_transport_attrs; - i->t.size =sizeof (struct spi_transport_attrs ); + i->t.device_attrs = &i->attrs[0 ]; + i->t.device_class = &spi_transport_class; + i->t.device_setup = &spi_setup_transport_attrs; + i->t.device_size =sizeof (struct spi_transport_attrs ); i->f = ft;SETUP_ATTRIBUTE (period);
include/scsi/scsi_host.h +10 -0
@@ -511,6 +511,13 @@struct list_head sht_legacy_list;/* +* Points to the transport data (if any) which is allocated +* separately +*/ +void *transport_data; +struct class_device transport_classdev; + +/* * We should ensure that this is aligned, both for better performance * and also because some compilers (m68k) don't automatically force * alignment to a long boundary.
@@ -522,6 +529,9 @@ container_of(d, struct Scsi_Host, shost_gendev)#define class_to_shost (d) \ container_of(d, struct Scsi_Host, shost_classdev) +#define transport_classdev_to_shost (class_dev) \ + container_of(class_dev, struct Scsi_Host, transport_classdev) +extern struct Scsi_Host *scsi_host_alloc (struct scsi_host_template *,int );extern int scsi_add_host (struct Scsi_Host *,struct device *);
include/scsi/scsi_transport.h +15 -7
@@ -24,18 +24,26 @@/* The NULL terminated list of transport attributes * that should be exported. */ -struct class_device_attribute **attrs; +struct class_device_attribute **device_attrs; +struct class_device_attribute **target_attrs; +struct class_device_attribute **host_attrs; +/* The transport class that the device is in */ -struct class *class; +struct class *device_class; +struct class *target_class; +struct class *host_class; + +/* Constructor functions */ +int (*device_setup)(struct scsi_device *); +int (*target_setup)(struct scsi_target *); +int (*host_setup)(struct Scsi_Host *); -/* Constructor/Destructor functions */ -int (* setup)(struct scsi_device *); -void (* cleanup)(struct scsi_device *);/* The size of the specific transport attribute structure (a * space of this size will be left at the end of the -* scsi_device structure */ - int size; +* scsi_* structure */ +int device_size; + int target_size; };#endif /* SCSI_TRANSPORT_H */