]> err.no Git - linux-2.6/commitdiff
[SCSI] esp: tidy up target reference counting
authorJames Bottomley <James.Bottomley@HansenPartnership.com>
Mon, 23 Jun 2008 19:52:09 +0000 (14:52 -0500)
committerJames Bottomley <James.Bottomley@HansenPartnership.com>
Wed, 25 Jun 2008 17:36:13 +0000 (12:36 -0500)
The esp driver currently does hand rolled reference counting of its
target.  It's much easier to do what it needs to do if it's plugged into
the mid-layer callbacks (target_alloc and target_destroy) which were
designed for this case, so do it this way and get rid of the internal
target reference count.

Acked-by: David S. Miller <davem@davemloft.net>
Cc: Stable Tree <stable@kernel.org>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
drivers/scsi/esp_scsi.c
drivers/scsi/esp_scsi.h

index 305eddef5ca18fc16bf7bcac55eff9b8af101e05..59fbef08d690763920af4b7fac52752f30be0570 100644 (file)
@@ -2359,6 +2359,24 @@ void scsi_esp_unregister(struct esp *esp)
 }
 EXPORT_SYMBOL(scsi_esp_unregister);
 
+static int esp_target_alloc(struct scsi_target *starget)
+{
+       struct esp *esp = shost_priv(dev_to_shost(&starget->dev));
+       struct esp_target_data *tp = &esp->target[starget->id];
+
+       tp->starget = starget;
+
+       return 0;
+}
+
+static void esp_target_destroy(struct scsi_target *starget)
+{
+       struct esp *esp = shost_priv(dev_to_shost(&starget->dev));
+       struct esp_target_data *tp = &esp->target[starget->id];
+
+       tp->starget = NULL;
+}
+
 static int esp_slave_alloc(struct scsi_device *dev)
 {
        struct esp *esp = shost_priv(dev->host);
@@ -2370,9 +2388,6 @@ static int esp_slave_alloc(struct scsi_device *dev)
                return -ENOMEM;
        dev->hostdata = lp;
 
-       tp->starget = dev->sdev_target;
-       tp->starget_ref++;
-
        spi_min_period(tp->starget) = esp->min_period;
        spi_max_offset(tp->starget) = 15;
 
@@ -2426,17 +2441,10 @@ static int esp_slave_configure(struct scsi_device *dev)
 
 static void esp_slave_destroy(struct scsi_device *dev)
 {
-       struct esp *esp = shost_priv(dev->host);
-       struct esp_target_data *tp = &esp->target[dev->id];
        struct esp_lun_data *lp = dev->hostdata;
 
        kfree(lp);
        dev->hostdata = NULL;
-
-       BUG_ON(tp->starget_ref <= 0);
-
-       if (!--tp->starget_ref)
-               tp->starget = NULL;
 }
 
 static int esp_eh_abort_handler(struct scsi_cmnd *cmd)
@@ -2616,6 +2624,8 @@ struct scsi_host_template scsi_esp_template = {
        .name                   = "esp",
        .info                   = esp_info,
        .queuecommand           = esp_queuecommand,
+       .target_alloc           = esp_target_alloc,
+       .target_destroy         = esp_target_destroy,
        .slave_alloc            = esp_slave_alloc,
        .slave_configure        = esp_slave_configure,
        .slave_destroy          = esp_slave_destroy,
index 655e0b2240bf497eb9529723beea4c3e2118b542..bb43a138818805d6d3ca683c2c75ce27cef4d87e 100644 (file)
@@ -322,7 +322,6 @@ struct esp_target_data {
        u8                      nego_goal_tags;
 
        struct scsi_target      *starget;
-       int                     starget_ref;
 };
 
 struct esp_event_ent {