ia64/xen-unstable

changeset 10547:8a89c0ff3f87

[LINUX][BLKBACK] Support temporary disconnection from frontend.
Signed-off-by: Steven Smith <sos22@cam.ac.uk>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 27 18:08:46 2006 +0100 (2006-06-27)
parents ab0cae84cfec
children 1da8f53ce65b
files linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Tue Jun 27 15:38:32 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Tue Jun 27 18:08:46 2006 +0100
     1.3 @@ -95,6 +95,7 @@ typedef struct blkif_st {
     1.4  } blkif_t;
     1.5  
     1.6  blkif_t *blkif_alloc(domid_t domid);
     1.7 +void blkif_disconnect(blkif_t *blkif);
     1.8  void blkif_free(blkif_t *blkif);
     1.9  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
    1.10  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Jun 27 15:38:32 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Jun 27 18:08:46 2006 +0100
     2.3 @@ -32,6 +32,7 @@
     2.4  
     2.5  #include "common.h"
     2.6  #include <xen/evtchn.h>
     2.7 +#include <linux/kthread.h>
     2.8  
     2.9  static kmem_cache_t *blkif_cachep;
    2.10  
    2.11 @@ -139,22 +140,33 @@ int blkif_map(blkif_t *blkif, unsigned l
    2.12  	return 0;
    2.13  }
    2.14  
    2.15 -void blkif_free(blkif_t *blkif)
    2.16 +void blkif_disconnect(blkif_t *blkif)
    2.17  {
    2.18 +	if (blkif->xenblkd) {
    2.19 +		kthread_stop(blkif->xenblkd);
    2.20 +		blkif->xenblkd = NULL;
    2.21 +	}
    2.22 +
    2.23  	atomic_dec(&blkif->refcnt);
    2.24  	wait_event(blkif->waiting_to_free, atomic_read(&blkif->refcnt) == 0);
    2.25 +	atomic_inc(&blkif->refcnt);
    2.26  
    2.27 -	/* Already disconnected? */
    2.28 -	if (blkif->irq)
    2.29 +	if (blkif->irq) {
    2.30  		unbind_from_irqhandler(blkif->irq, blkif);
    2.31 -
    2.32 -	vbd_free(&blkif->vbd);
    2.33 +		blkif->irq = 0;
    2.34 +	}
    2.35  
    2.36  	if (blkif->blk_ring.sring) {
    2.37  		unmap_frontend_page(blkif);
    2.38  		free_vm_area(blkif->blk_ring_area);
    2.39 +		blkif->blk_ring.sring = NULL;
    2.40  	}
    2.41 +}
    2.42  
    2.43 +void blkif_free(blkif_t *blkif)
    2.44 +{
    2.45 +	if (!atomic_dec_and_test(&blkif->refcnt))
    2.46 +		BUG();
    2.47  	kmem_cache_free(blkif_cachep, blkif);
    2.48  }
    2.49  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Tue Jun 27 15:38:32 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Tue Jun 27 18:08:46 2006 +0100
     3.3 @@ -105,9 +105,10 @@ static int blkback_remove(struct xenbus_
     3.4  		kfree(be->backend_watch.node);
     3.5  		be->backend_watch.node = NULL;
     3.6  	}
     3.7 +
     3.8  	if (be->blkif) {
     3.9 -		if (be->blkif->xenblkd)
    3.10 -			kthread_stop(be->blkif->xenblkd);
    3.11 +		blkif_disconnect(be->blkif);
    3.12 +		vbd_free(&be->blkif->vbd);
    3.13  		blkif_free(be->blkif);
    3.14  		be->blkif = NULL;
    3.15  	}
    3.16 @@ -273,6 +274,7 @@ static void frontend_changed(struct xenb
    3.17  		break;
    3.18  
    3.19  	case XenbusStateClosing:
    3.20 +		blkif_disconnect(be->blkif);
    3.21  		xenbus_switch_state(dev, XenbusStateClosing);
    3.22  		break;
    3.23