[LINUX][BLK] front: More care over device teardown.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 14 Jun 2006 10:19:53 +0000 (11:19 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 14 Jun 2006 10:19:53 +0000 (11:19 +0100)
 1. We must ensure gnttab callbacks are disabled and all work
    flushed before tearing down device state. A new gnttab interface
    call is added for this purpose.
 2. blkif_free() must check for a request_queue before deref'ing it.
Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
linux-2.6-xen-sparse/drivers/xen/core/gnttab.c
linux-2.6-xen-sparse/include/xen/gnttab.h

index 1a2156600d74e7ba5d8850f588095b212bb2df9f..20e5ad63b8d324b76a6d5a16824a232190d49523 100644 (file)
@@ -342,9 +342,21 @@ static void connect(struct blkfront_info *info)
 static void blkfront_closing(struct xenbus_device *dev)
 {
        struct blkfront_info *info = dev->dev.driver_data;
+       unsigned long flags;
 
        DPRINTK("blkfront_closing: %s removed\n", dev->nodename);
 
+       if (info->rq == NULL)
+               return;
+
+       spin_lock_irqsave(&blkif_io_lock, flags);
+       /* No more blkif_request(). */
+       blk_stop_queue(info->rq);
+       /* No more gnttab callback work. */
+       gnttab_cancel_free_callback(&info->callback);
+       flush_scheduled_work();
+       spin_unlock_irqrestore(&blkif_io_lock, flags);
+
        xlvbd_del(info);
 
        xenbus_switch_state(dev, XenbusStateClosed);
@@ -696,7 +708,12 @@ static void blkif_free(struct blkfront_info *info, int suspend)
        spin_lock_irq(&blkif_io_lock);
        info->connected = suspend ?
                BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED;
-       blk_stop_queue(info->rq); /* no more blkif_request() */
+       /* No more blkif_request(). */
+       if (info->rq)
+               blk_stop_queue(info->rq);
+       /* No more gnttab callback work. */
+       gnttab_cancel_free_callback(&info->callback);
+       flush_scheduled_work();
        spin_unlock_irq(&blkif_io_lock);
 
        /* Free resources associated with old device channel. */
index f97d659f07bae712a6fc4d9e78dc546d392b709c..765dfa931ff8451d04cf4fb451f653ec5f3e965f 100644 (file)
@@ -334,6 +334,21 @@ out:
 }
 EXPORT_SYMBOL_GPL(gnttab_request_free_callback);
 
+void gnttab_cancel_free_callback(struct gnttab_free_callback *callback)
+{
+       struct gnttab_free_callback **pcb;
+       unsigned long flags;
+
+       spin_lock_irqsave(&gnttab_list_lock, flags);
+       for (pcb = &gnttab_free_callback_list; *pcb; pcb = &(*pcb)->next) {
+               if (*pcb == callback) {
+                       *pcb = callback->next;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&gnttab_list_lock, flags);
+}
+
 #ifndef __ia64__
 static int map_pte_fn(pte_t *pte, struct page *pmd_page,
                      unsigned long addr, void *data)
index b9207b17e1b45a7ace78db423de1f200aab646c0..676fca5054beea953ec2a6ec282199a2b96a2759 100644 (file)
@@ -100,6 +100,7 @@ void gnttab_release_grant_reference(grant_ref_t *private_head,
 
 void gnttab_request_free_callback(struct gnttab_free_callback *callback,
                                  void (*fn)(void *), void *arg, u16 count);
+void gnttab_cancel_free_callback(struct gnttab_free_callback *callback);
 
 void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
                                     unsigned long frame, int readonly);