ia64/xen-unstable

changeset 5890:26e4e952c385

Implement xenbus_dev_error() and xenbus_dev_ok() functions
for better error reporting using the store.
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 Tue Jul 26 17:25:57 2005 +0000 (2005-07-26)
parents a9a956748997
children 5f0446907501
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/asm-xen/xenbus.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Jul 26 17:24:22 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Jul 26 17:25:57 2005 +0000
     1.3 @@ -43,6 +43,7 @@
     1.4  
     1.5  #define streq(a, b) (strcmp((a), (b)) == 0)
     1.6  
     1.7 +static char printf_buffer[4096];
     1.8  static void *xs_in, *xs_out;
     1.9  static LIST_HEAD(watches);
    1.10  DECLARE_MUTEX(xenbus_lock);
    1.11 @@ -339,17 +340,49 @@ int xenbus_printf(const char *dir, const
    1.12  {
    1.13  	va_list ap;
    1.14  	int ret;
    1.15 -	static char buffer[4096];
    1.16  
    1.17  	BUG_ON(down_trylock(&xenbus_lock) == 0);
    1.18  	va_start(ap, fmt);
    1.19 -	ret = vsnprintf(buffer, sizeof(buffer), fmt, ap);
    1.20 +	ret = vsnprintf(printf_buffer, sizeof(printf_buffer), fmt, ap);
    1.21  	va_end(ap);
    1.22  
    1.23 -	BUG_ON(ret > sizeof(buffer)-1);
    1.24 -	return xenbus_write(dir, node, buffer, O_CREAT);
    1.25 +	BUG_ON(ret > sizeof(printf_buffer)-1);
    1.26 +	return xenbus_write(dir, node, printf_buffer, O_CREAT);
    1.27  }
    1.28  
    1.29 +/* Report a (negative) errno into the store, with explanation. */
    1.30 +void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...)
    1.31 +{
    1.32 +	va_list ap;
    1.33 +	int ret;
    1.34 +	unsigned int len;
    1.35 +
    1.36 +	BUG_ON(down_trylock(&xenbus_lock) == 0);
    1.37 +
    1.38 +	len = sprintf(printf_buffer, "%i ", -err);
    1.39 +	va_start(ap, fmt);
    1.40 +	ret = vsnprintf(printf_buffer+len, sizeof(printf_buffer)-len, fmt, ap);
    1.41 +	va_end(ap);
    1.42 +
    1.43 +	BUG_ON(len + ret > sizeof(printf_buffer)-1);
    1.44 +	dev->has_error = 1;
    1.45 +	if (xenbus_write(dev->nodename, "error", printf_buffer, O_CREAT) != 0)
    1.46 +		printk("xenbus: failed to write error node for %s (%s)\n",
    1.47 +		       dev->nodename, printf_buffer);
    1.48 +}
    1.49 +
    1.50 +/* Clear any error. */
    1.51 +void xenbus_dev_ok(struct xenbus_device *dev)
    1.52 +{
    1.53 +	if (dev->has_error) {
    1.54 +		if (xenbus_rm(dev->nodename, "error") != 0)
    1.55 +			printk("xenbus: failed to clear error node for %s\n",
    1.56 +			       dev->nodename);
    1.57 +		else
    1.58 +			dev->has_error = 0;
    1.59 +	}
    1.60 +}
    1.61 +	
    1.62  /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
    1.63  int xenbus_gather(const char *dir, ...)
    1.64  {
     2.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Tue Jul 26 17:24:22 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Tue Jul 26 17:25:57 2005 +0000
     2.3 @@ -37,6 +37,7 @@ struct xenbus_device {
     2.4  	char *subtype;
     2.5  	char *nodename;
     2.6  	struct device dev;
     2.7 +	int has_error;
     2.8  	void *data;
     2.9  };
    2.10  
    2.11 @@ -97,6 +98,12 @@ int xenbus_printf(const char *dir, const
    2.12   * sprintf-style type string, and pointer. Returns 0 or errno.*/
    2.13  int xenbus_gather(const char *dir, ...);
    2.14  
    2.15 +/* Report a (negative) errno into the store, with explanation. */
    2.16 +void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,...);
    2.17 +
    2.18 +/* Clear any error. */
    2.19 +void xenbus_dev_ok(struct xenbus_device *dev);
    2.20 +
    2.21  /* Register callback to watch this node. */
    2.22  struct xenbus_watch
    2.23  {