ia64/xen-unstable

changeset 5918:3be03cd7cd4c

Simplify code by making in and out pointers internal to xenbus_xs.c
Signed-off-by: Rusty Russel <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Jul 28 12:25:13 2005 +0000 (2005-07-28)
parents c02e5214247e
children d24e1970c205
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Wed Jul 27 18:41:49 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Thu Jul 28 12:25:13 2005 +0000
     1.3 @@ -47,6 +47,17 @@ struct ringbuf_head
     1.4  
     1.5  DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
     1.6  
     1.7 +static inline struct ringbuf_head *outbuf(void)
     1.8 +{
     1.9 +	return machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT);
    1.10 +}
    1.11 +
    1.12 +static inline struct ringbuf_head *inbuf(void)
    1.13 +{
    1.14 +	return machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT)
    1.15 +		+ PAGE_SIZE/2;
    1.16 +}
    1.17 +
    1.18  static irqreturn_t wake_waiting(int irq, void *unused, struct pt_regs *regs)
    1.19  {
    1.20  	wake_up(&xb_waitq);
    1.21 @@ -108,9 +119,10 @@ static int output_avail(struct ringbuf_h
    1.22  	return avail != 0;
    1.23  }
    1.24  
    1.25 -int xb_write(struct ringbuf_head *out, const void *data, unsigned len)
    1.26 +int xb_write(const void *data, unsigned len)
    1.27  {
    1.28  	struct ringbuf_head h;
    1.29 +	struct ringbuf_head *out = outbuf();
    1.30  
    1.31  	do {
    1.32  		void *dst;
    1.33 @@ -141,24 +153,26 @@ int xb_write(struct ringbuf_head *out, c
    1.34  	return 0;
    1.35  }
    1.36  
    1.37 -int xs_input_avail(struct ringbuf_head *in)
    1.38 +int xs_input_avail(void)
    1.39  {
    1.40  	unsigned int avail;
    1.41 +	struct ringbuf_head *in = inbuf();
    1.42  
    1.43  	get_input_chunk(in, in->buf, &avail);
    1.44  	return avail != 0;
    1.45  }
    1.46  
    1.47 -int xb_read(struct ringbuf_head *in, void *data, unsigned len)
    1.48 +int xb_read(void *data, unsigned len)
    1.49  {
    1.50  	struct ringbuf_head h;
    1.51 +	struct ringbuf_head *in = inbuf();
    1.52  	int was_full;
    1.53  
    1.54  	while (len != 0) {
    1.55  		unsigned int avail;
    1.56  		const char *src;
    1.57  
    1.58 -		wait_event(xb_waitq, xs_input_avail(in));
    1.59 +		wait_event(xb_waitq, xs_input_avail());
    1.60  		h = *in;
    1.61  		mb();
    1.62  		if (!check_buffer(&h)) {
    1.63 @@ -182,14 +196,14 @@ int xb_read(struct ringbuf_head *in, voi
    1.64  	}
    1.65  
    1.66  	/* If we left something, wake watch thread to deal with it. */
    1.67 -	if (xs_input_avail(in))
    1.68 +	if (xs_input_avail())
    1.69  		wake_up(&xb_waitq);
    1.70  
    1.71  	return 0;
    1.72  }
    1.73  
    1.74  /* Set up interrpt handler off store event channel. */
    1.75 -int xb_init_comms(void **in, void **out)
    1.76 +int xb_init_comms(void)
    1.77  {
    1.78  	int err, irq;
    1.79  
    1.80 @@ -202,11 +216,9 @@ int xb_init_comms(void **in, void **out)
    1.81  		return err;
    1.82  	}
    1.83  
    1.84 -	*out = machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT);
    1.85 -	*in = *out + PAGE_SIZE / 2;
    1.86 -
    1.87  	/* FIXME zero out page -- domain builder should probably do this*/
    1.88 -	memset(*out, 0, PAGE_SIZE);
    1.89 +	memset(machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT),
    1.90 +	       0, PAGE_SIZE);
    1.91  
    1.92  	return 0;
    1.93  }
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h	Wed Jul 27 18:41:49 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h	Thu Jul 28 12:25:13 2005 +0000
     2.3 @@ -2,13 +2,12 @@
     2.4  #ifndef _XENBUS_COMMS_H
     2.5  #define _XENBUS_COMMS_H
     2.6  int xs_init(void);
     2.7 -int xb_init_comms(void **in, void **out);
     2.8 +int xb_init_comms(void);
     2.9  
    2.10  /* Low level routines. */
    2.11 -struct ringbuf_head;
    2.12 -int xb_write(struct ringbuf_head *out, const void *data, unsigned len);
    2.13 -int xb_read(struct ringbuf_head *in, void *data, unsigned len);
    2.14 -int xs_input_avail(struct ringbuf_head *in);
    2.15 +int xb_write(const void *data, unsigned len);
    2.16 +int xb_read(void *data, unsigned len);
    2.17 +int xs_input_avail(void);
    2.18  extern wait_queue_head_t xb_waitq;
    2.19  
    2.20  #endif /* _XENBUS_COMMS_H */
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Wed Jul 27 18:41:49 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Thu Jul 28 12:25:13 2005 +0000
     3.3 @@ -44,7 +44,6 @@
     3.4  #define streq(a, b) (strcmp((a), (b)) == 0)
     3.5  
     3.6  static char printf_buffer[4096];
     3.7 -static void *xs_in, *xs_out;
     3.8  static LIST_HEAD(watches);
     3.9  DECLARE_MUTEX(xenbus_lock);
    3.10  
    3.11 @@ -69,7 +68,7 @@ static void *read_reply(enum xsd_sockmsg
    3.12  	void *ret;
    3.13  	int err;
    3.14  
    3.15 -	err = xb_read(xs_in, &msg, sizeof(msg));
    3.16 +	err = xb_read(&msg, sizeof(msg));
    3.17  	if (err)
    3.18  		return ERR_PTR(err);
    3.19  
    3.20 @@ -77,7 +76,7 @@ static void *read_reply(enum xsd_sockmsg
    3.21  	if (!ret)
    3.22  		return ERR_PTR(-ENOMEM);
    3.23  
    3.24 -	err = xb_read(xs_in, ret, msg.len);
    3.25 +	err = xb_read(ret, msg.len);
    3.26  	if (err) {
    3.27  		kfree(ret);
    3.28  		return ERR_PTR(err);
    3.29 @@ -94,15 +93,14 @@ static void *read_reply(enum xsd_sockmsg
    3.30  void xenbus_debug_write(const char *str, unsigned int count)
    3.31  {
    3.32  	struct xsd_sockmsg msg;
    3.33 -	void *out = machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT);
    3.34  
    3.35  	msg.type = XS_DEBUG;
    3.36  	msg.len = sizeof("print") + count + 1;
    3.37  
    3.38 -	xb_write(out, &msg, sizeof(msg));
    3.39 -	xb_write(out, "print", sizeof("print"));
    3.40 -	xb_write(out, str, count);
    3.41 -	xb_write(out, "", 1);
    3.42 +	xb_write(&msg, sizeof(msg));
    3.43 +	xb_write("print", sizeof("print"));
    3.44 +	xb_write(str, count);
    3.45 +	xb_write("", 1);
    3.46  }
    3.47  
    3.48  /* Send message to xs, get kmalloc'ed reply.  ERR_PTR() on error. */
    3.49 @@ -123,12 +121,12 @@ static void *xs_talkv(enum xsd_sockmsg_t
    3.50  	for (i = 0; i < num_vecs; i++)
    3.51  		msg.len += iovec[i].iov_len;
    3.52  
    3.53 -	err = xb_write(xs_out, &msg, sizeof(msg));
    3.54 +	err = xb_write(&msg, sizeof(msg));
    3.55  	if (err)
    3.56  		return ERR_PTR(err);
    3.57  
    3.58  	for (i = 0; i < num_vecs; i++) {
    3.59 -		err = xb_write(xs_out, iovec[i].iov_base, iovec[i].iov_len);;
    3.60 +		err = xb_write(iovec[i].iov_base, iovec[i].iov_len);;
    3.61  		if (err)
    3.62  			return ERR_PTR(err);
    3.63  	}
    3.64 @@ -509,14 +507,14 @@ static int watch_thread(void *unused)
    3.65  		char *token;
    3.66  		char *node = NULL;
    3.67  
    3.68 -		wait_event(xb_waitq, xs_input_avail(xs_in));
    3.69 +		wait_event(xb_waitq, xs_input_avail());
    3.70  
    3.71  		/* If this is a spurious wakeup caused by someone
    3.72  		 * doing an op, they'll hold the lock and the buffer
    3.73  		 * will be empty by the time we get there.		 
    3.74  		 */
    3.75  		down(&xenbus_lock);
    3.76 -		if (xs_input_avail(xs_in))
    3.77 +		if (xs_input_avail())
    3.78  			node = xs_read_watch(&token);
    3.79  
    3.80  		if (node && !IS_ERR(node)) {
    3.81 @@ -548,7 +546,7 @@ int xs_init(void)
    3.82  	int err;
    3.83  	struct task_struct *watcher;
    3.84  
    3.85 -	err = xb_init_comms(&xs_in, &xs_out);
    3.86 +	err = xb_init_comms();
    3.87  	if (err)
    3.88  		return err;
    3.89