fix hot unplug vs async scan race
[pandora-kernel.git] / drivers / scsi / scsi_sysfs.c
index 04c2a27..bb7c482 100644 (file)
@@ -971,11 +971,8 @@ void __scsi_remove_device(struct scsi_device *sdev)
                sdev->host->hostt->slave_destroy(sdev);
        transport_destroy_device(dev);
 
-       /* cause the request function to reject all I/O requests */
-       sdev->request_queue->queuedata = NULL;
-
        /* Freeing the queue signals to block that we're done */
-       scsi_free_queue(sdev->request_queue);
+       blk_cleanup_queue(sdev->request_queue);
        put_device(dev);
 }
 
@@ -1000,7 +997,6 @@ static void __scsi_remove_target(struct scsi_target *starget)
        struct scsi_device *sdev;
 
        spin_lock_irqsave(shost->host_lock, flags);
-       starget->reap_ref++;
  restart:
        list_for_each_entry(sdev, &shost->__devices, siblings) {
                if (sdev->channel != starget->channel ||
@@ -1014,14 +1010,6 @@ static void __scsi_remove_target(struct scsi_target *starget)
                goto restart;
        }
        spin_unlock_irqrestore(shost->host_lock, flags);
-       scsi_target_reap(starget);
-}
-
-static int __remove_child (struct device * dev, void * data)
-{
-       if (scsi_is_target_device(dev))
-               __scsi_remove_target(to_scsi_target(dev));
-       return 0;
 }
 
 /**
@@ -1034,14 +1022,34 @@ static int __remove_child (struct device * dev, void * data)
  */
 void scsi_remove_target(struct device *dev)
 {
-       if (scsi_is_target_device(dev)) {
-               __scsi_remove_target(to_scsi_target(dev));
-               return;
+       struct Scsi_Host *shost = dev_to_shost(dev->parent);
+       struct scsi_target *starget, *found;
+       unsigned long flags;
+
+ restart:
+       found = NULL;
+       spin_lock_irqsave(shost->host_lock, flags);
+       list_for_each_entry(starget, &shost->__targets, siblings) {
+               if (starget->state == STARGET_DEL)
+                       continue;
+               if (starget->dev.parent == dev || &starget->dev == dev) {
+                       found = starget;
+                       found->reap_ref++;
+                       break;
+               }
        }
+       spin_unlock_irqrestore(shost->host_lock, flags);
 
-       get_device(dev);
-       device_for_each_child(dev, NULL, __remove_child);
-       put_device(dev);
+       if (found) {
+               __scsi_remove_target(found);
+               scsi_target_reap(found);
+               /* in the case where @dev has multiple starget children,
+                * continue removing.
+                *
+                * FIXME: does such a case exist?
+                */
+               goto restart;
+       }
 }
 EXPORT_SYMBOL(scsi_remove_target);