]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Make scsi_free_queue() kill pending SCSI commands
authorBart Van Assche <bvanassche@acm.org>
Fri, 23 Sep 2011 17:48:18 +0000 (19:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 11 Feb 2012 14:37:55 +0000 (15:37 +0100)
commit 3308511c93e6ad0d3c58984ecd6e5e57f96b12c8 upstream.

Make sure that SCSI device removal via scsi_remove_host() does finish
all pending SCSI commands. Currently that's not the case and hence
removal of a SCSI host during I/O can cause a deadlock. See also
"blkdev_issue_discard() hangs forever if underlying storage device is
removed" (http://bugzilla.kernel.org/show_bug.cgi?id=40472). See also
http://lkml.org/lkml/2011/8/27/6.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/scsi/hosts.c
drivers/scsi/scsi_lib.c

index fed0b02ebc1d35ecba7c19b534956edf939eb7a6..35953bfac2c34e02922a181eb923c2005a869707 100644 (file)
@@ -269,14 +269,17 @@ static void scsi_host_dev_release(struct device *dev)
 {
        struct Scsi_Host *shost = dev_to_shost(dev);
        struct device *parent = dev->parent;
+       struct request_queue *q;
 
        if (shost->ehandler)
                kthread_stop(shost->ehandler);
        if (shost->work_q)
                destroy_workqueue(shost->work_q);
-       if (shost->uspace_req_q) {
-               kfree(shost->uspace_req_q->queuedata);
-               scsi_free_queue(shost->uspace_req_q);
+       q = shost->uspace_req_q;
+       if (q) {
+               kfree(q->queuedata);
+               q->queuedata = NULL;
+               scsi_free_queue(q);
        }
 
        scsi_destroy_command_freelist(shost);
index 62307bd794a924c1f04d6b6822aa61dd2ef875c3..e34afc5a8779076b0d8a7babcde47134acf35cee 100644 (file)
@@ -1680,6 +1680,15 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
 
 void scsi_free_queue(struct request_queue *q)
 {
+       unsigned long flags;
+
+       WARN_ON(q->queuedata);
+
+       /* cause scsi_request_fn() to kill all non-finished requests */
+       spin_lock_irqsave(q->queue_lock, flags);
+       q->request_fn(q);
+       spin_unlock_irqrestore(q->queue_lock, flags);
+
        blk_cleanup_queue(q);
 }