ia64/xen-unstable

changeset 9609:d2705953c6d2

More simplifications to blkback:
1. Remove blkif->status field as it's really not needed.
2. Simplify connection logic.
3. Get rid of atomic_t io_pending. There's no need for
atomic r-m-w updates to the work-to-do flag, so replace
with an integer and add barriers where serialisation is
required.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Apr 06 11:34:14 2006 +0100 (2006-04-06)
parents 8031bf331472
children 67de34c062b5
files linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c 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/blkback.c	Thu Apr 06 11:13:33 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Apr 06 11:34:14 2006 +0100
     1.3 @@ -225,16 +225,16 @@ int blkif_schedule(void *arg)
     1.4  	while (!kthread_should_stop()) {
     1.5  		wait_event_interruptible(
     1.6  			blkif->wq,
     1.7 -			atomic_read(&blkif->io_pending) ||
     1.8 -			kthread_should_stop());
     1.9 +			blkif->waiting_reqs || kthread_should_stop());
    1.10  		wait_event_interruptible(
    1.11  			pending_free_wq,
    1.12 -			!list_empty(&pending_free) ||
    1.13 -			kthread_should_stop());
    1.14 +			!list_empty(&pending_free) || kthread_should_stop());
    1.15  
    1.16 -		atomic_set(&blkif->io_pending, 0);
    1.17 +		blkif->waiting_reqs = 0;
    1.18 +		smp_mb(); /* clear flag *before* checking for work */
    1.19 +
    1.20  		if (do_block_io_op(blkif))
    1.21 -			atomic_inc(&blkif->io_pending);
    1.22 +			blkif->waiting_reqs = 1;
    1.23  		unplug_queue(blkif);
    1.24  
    1.25  		if (log_stats && time_after(jiffies, blkif->st_print))
    1.26 @@ -287,12 +287,15 @@ static int end_block_io_op(struct bio *b
    1.27   * NOTIFICATION FROM GUEST OS.
    1.28   */
    1.29  
    1.30 +void blkif_notify_work(blkif_t *blkif)
    1.31 +{
    1.32 +	blkif->waiting_reqs = 1;
    1.33 +	wake_up(&blkif->wq);
    1.34 +}
    1.35 +
    1.36  irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs)
    1.37  {
    1.38 -	blkif_t *blkif = dev_id;
    1.39 -
    1.40 -	atomic_inc(&blkif->io_pending);
    1.41 -	wake_up(&blkif->wq);
    1.42 +	blkif_notify_work(dev_id);
    1.43  	return IRQ_HANDLED;
    1.44  }
    1.45  
    1.46 @@ -512,10 +515,8 @@ static void make_response(blkif_t *blkif
    1.47  	}
    1.48  	spin_unlock_irqrestore(&blkif->blk_ring_lock, flags);
    1.49  
    1.50 -	if (more_to_do) {
    1.51 -		atomic_inc(&blkif->io_pending);
    1.52 -		wake_up(&blkif->wq);
    1.53 -	}
    1.54 +	if (more_to_do)
    1.55 +		blkif_notify_work(blkif);
    1.56  	if (notify)
    1.57  		notify_remote_via_irq(blkif->irq);
    1.58  }
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Thu Apr 06 11:13:33 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Thu Apr 06 11:34:14 2006 +0100
     2.3 @@ -72,7 +72,6 @@ typedef struct blkif_st {
     2.4  	/* Back pointer to the backend_info. */
     2.5  	struct backend_info *be; 
     2.6  	/* Private fields. */
     2.7 -	enum { DISCONNECTED, CONNECTED } status;
     2.8  #ifdef CONFIG_XEN_BLKDEV_TAP_BE
     2.9  	/* Is this a blktap frontend */
    2.10  	unsigned int     is_blktap;
    2.11 @@ -82,7 +81,7 @@ typedef struct blkif_st {
    2.12  
    2.13  	wait_queue_head_t   wq;
    2.14  	struct task_struct  *xenblkd;
    2.15 -	atomic_t            io_pending;
    2.16 +	unsigned int        waiting_reqs;
    2.17  	request_queue_t     *plug;
    2.18  
    2.19  	/* statistics */
    2.20 @@ -130,11 +129,10 @@ void blkif_interface_init(void);
    2.21  
    2.22  void blkif_xenbus_init(void);
    2.23  
    2.24 +void blkif_notify_work(blkif_t *blkif);
    2.25  irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs);
    2.26  int blkif_schedule(void *arg);
    2.27  
    2.28 -void update_blkif_status(blkif_t *blkif); 
    2.29 -
    2.30  #endif /* __BLKIF__BACKEND__COMMON_H__ */
    2.31  
    2.32  /*
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Thu Apr 06 11:13:33 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Thu Apr 06 11:34:14 2006 +0100
     3.3 @@ -45,7 +45,6 @@ blkif_t *alloc_blkif(domid_t domid)
     3.4  
     3.5  	memset(blkif, 0, sizeof(*blkif));
     3.6  	blkif->domid = domid;
     3.7 -	blkif->status = DISCONNECTED;
     3.8  	spin_lock_init(&blkif->blk_ring_lock);
     3.9  	atomic_set(&blkif->refcnt, 1);
    3.10  	init_waitqueue_head(&blkif->wq);
    3.11 @@ -138,9 +137,6 @@ int blkif_map(blkif_t *blkif, unsigned l
    3.12  	blkif->irq = bind_evtchn_to_irqhandler(
    3.13  		blkif->evtchn, blkif_be_int, 0, "blkif-backend", blkif);
    3.14  
    3.15 -	/* We're potentially connected now */
    3.16 -	update_blkif_status(blkif); 
    3.17 -
    3.18  	return 0;
    3.19  }
    3.20  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Thu Apr 06 11:13:33 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Thu Apr 06 11:34:14 2006 +0100
     4.3 @@ -17,7 +17,6 @@
     4.4      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     4.5  */
     4.6  
     4.7 -
     4.8  #include <stdarg.h>
     4.9  #include <linux/module.h>
    4.10  #include <linux/kthread.h>
    4.11 @@ -25,36 +24,33 @@
    4.12  #include "common.h"
    4.13  
    4.14  #undef DPRINTK
    4.15 -#define DPRINTK(fmt, args...) \
    4.16 -    pr_debug("blkback/xenbus (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, ##args)
    4.17 -
    4.18 +#define DPRINTK(fmt, args...)				\
    4.19 +	pr_debug("blkback/xenbus (%s:%d) " fmt ".\n",	\
    4.20 +		 __FUNCTION__, __LINE__, ##args)
    4.21  
    4.22  struct backend_info
    4.23  {
    4.24  	struct xenbus_device *dev;
    4.25  	blkif_t *blkif;
    4.26  	struct xenbus_watch backend_watch;
    4.27 -
    4.28  	unsigned major;
    4.29  	unsigned minor;
    4.30  	char *mode;
    4.31  };
    4.32  
    4.33 -
    4.34 -static void maybe_connect(struct backend_info *);
    4.35  static void connect(struct backend_info *);
    4.36  static int connect_ring(struct backend_info *);
    4.37  static void backend_changed(struct xenbus_watch *, const char **,
    4.38  			    unsigned int);
    4.39  
    4.40  
    4.41 -void update_blkif_status(blkif_t *blkif)
    4.42 +static void update_blkif_status(blkif_t *blkif)
    4.43  { 
    4.44 -	if(blkif->irq && blkif->vbd.bdev) {
    4.45 -		blkif->status = CONNECTED; 
    4.46 -		(void)blkif_be_int(0, blkif, NULL); 
    4.47 +	if (blkif->irq && blkif->vbd.bdev &&
    4.48 +	    (blkif->be->dev->state != XenbusStateConnected)) {
    4.49 +		connect(blkif->be);
    4.50 +		blkif_notify_work(blkif);
    4.51  	}
    4.52 -	maybe_connect(blkif->be); 
    4.53  }
    4.54  
    4.55  
    4.56 @@ -91,7 +87,6 @@ static int blkback_remove(struct xenbus_
    4.57  		be->backend_watch.node = NULL;
    4.58  	}
    4.59  	if (be->blkif) {
    4.60 -		be->blkif->status = DISCONNECTED; 
    4.61  		if (be->blkif->xenblkd)
    4.62  			kthread_stop(be->blkif->xenblkd);
    4.63  		blkif_put(be->blkif);
    4.64 @@ -185,8 +180,8 @@ static void backend_changed(struct xenbu
    4.65  		return;
    4.66  	}
    4.67  
    4.68 -	if (be->major && be->minor &&
    4.69 -	    (be->major != major || be->minor != minor)) {
    4.70 +	if ((be->major || be->minor) &&
    4.71 +	    ((be->major != major) || (be->minor != minor))) {
    4.72  		printk(KERN_WARNING
    4.73  		       "blkback: changing physical device (from %x:%x to "
    4.74  		       "%x:%x) not supported.\n", be->major, be->minor,
    4.75 @@ -290,14 +285,6 @@ static void frontend_changed(struct xenb
    4.76  /* ** Connection ** */
    4.77  
    4.78  
    4.79 -static void maybe_connect(struct backend_info *be)
    4.80 -{
    4.81 -	if ((be->major != 0 || be->minor != 0) &&
    4.82 -	    be->blkif->status == CONNECTED)
    4.83 -		connect(be);
    4.84 -}
    4.85 -
    4.86 -
    4.87  /**
    4.88   * Write the physical details regarding the block device to the store, and
    4.89   * switch to Connected state.