ia64/xen-unstable

changeset 5879:2e6e1eb66c5e

Major xenbus cleanup
1) Make xenbus_* functions first-class citizens, evict xs_ prefix.
2) Add xenbus_scanf and xenbus_printf instead of multiple functions
3) Remove unused code from xenbus.c
4) Use standard debugging macros.
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 16:59:40 2005 +0000 (2005-07-26)
parents 62e13cae2f58
children 42e8937a93f0
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c 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_probe.c	Tue Jul 26 15:57:18 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Jul 26 16:59:40 2005 +0000
     1.3 @@ -26,6 +26,8 @@
     1.4   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     1.5   * IN THE SOFTWARE.
     1.6   */
     1.7 +#define DEBUG
     1.8 +
     1.9  #include <asm-xen/hypervisor.h>
    1.10  #include <asm-xen/xenbus.h>
    1.11  #include <linux/kernel.h>
    1.12 @@ -39,149 +41,10 @@
    1.13  /* Name of field containing device type. */
    1.14  #define XENBUS_DEVICE_TYPE "type"
    1.15  
    1.16 -#define DEBUG
    1.17 -
    1.18 -#ifdef DEBUG
    1.19 -#define dprintf(_fmt, _args...) \
    1.20 -printk(KERN_INFO __stringify(KBUILD_MODNAME) " [DBG] %s"    _fmt, __FUNCTION__, ##_args)
    1.21 -#else
    1.22 -#define dprintf(_fmt, _args...) do { } while(0)
    1.23 -#endif
    1.24 -
    1.25  static int xs_init_done = 0;
    1.26  
    1.27 -/* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
    1.28 -int xenbus_gather(const char *dir, ...)
    1.29 -{
    1.30 -	va_list ap;
    1.31 -	const char *name;
    1.32 -	int ret = 0;
    1.33 -
    1.34 -	va_start(ap, dir);
    1.35 -	while (ret == 0 && (name = va_arg(ap, char *)) != NULL) {
    1.36 -		const char *fmt = va_arg(ap, char *);
    1.37 -		void *result = va_arg(ap, void *);
    1.38 -		char *p;
    1.39 -
    1.40 -		p = xenbus_read(dir, name, NULL);
    1.41 -		if (IS_ERR(p)) {
    1.42 -			ret = PTR_ERR(p);
    1.43 -			break;
    1.44 -		}
    1.45 -		if (sscanf(p, fmt, result) == 0)
    1.46 -			ret = -EINVAL;
    1.47 -		kfree(p);
    1.48 -	}
    1.49 -	va_end(ap);
    1.50 -	return ret;
    1.51 -}
    1.52 -
    1.53 -/* Return the path to dir with /name appended.
    1.54 - * If name is null or empty returns a copy of dir.
    1.55 - */ 
    1.56 -char *xenbus_path(const char *dir, const char *name)
    1.57 -{
    1.58 -	char *ret;
    1.59 -	int len;
    1.60 -
    1.61 -	len = strlen(dir) + 1;
    1.62 -	if (name)
    1.63 -		len += strlen(name) + 1;
    1.64 -	ret = kmalloc(len, GFP_KERNEL);
    1.65 -	if (ret == NULL)
    1.66 -	    return NULL;
    1.67 -	strcpy(ret, dir);
    1.68 -	if (name) {
    1.69 -		strcat(ret, "/");
    1.70 -		strcat(ret, name);
    1.71 -	}
    1.72 -	return ret;
    1.73 -}
    1.74 -
    1.75  #define streq(a, b) (strcmp((a), (b)) == 0)
    1.76  
    1.77 -char *xenbus_read(const char *dir, const char *name, unsigned int *data_n)
    1.78 -{
    1.79 -	int err = 0;
    1.80 -	char *data = NULL;
    1.81 -	char *path = xenbus_path(dir, name);
    1.82 -	int n = 0;
    1.83 -
    1.84 -	if (!path) {
    1.85 -		err = -ENOMEM;
    1.86 -		goto out;
    1.87 -	}
    1.88 -	data = xs_read(path, &n);
    1.89 -	if (IS_ERR(data)) {
    1.90 -		err = PTR_ERR(data);
    1.91 -		if (err == -EISDIR)
    1.92 -			err = -ENOENT;
    1.93 -	} else if (n == 0) {
    1.94 -		err = -ENOENT;
    1.95 -		kfree(data);
    1.96 -	}
    1.97 -	kfree(path);
    1.98 -  out:
    1.99 -	if (data_n)
   1.100 -		*data_n = n;
   1.101 -	return (err ? ERR_PTR(err) : data);
   1.102 -}
   1.103 -
   1.104 -int xenbus_write(const char *dir, const char *name, const char *data, int data_n)
   1.105 -{
   1.106 -	int err = 0;
   1.107 -	char *path = xenbus_path(dir, name);
   1.108 -
   1.109 -	if (!path)
   1.110 -		return -ENOMEM;
   1.111 -	err = xs_write(path, data, data_n, O_CREAT);
   1.112 -	kfree(path);
   1.113 -	return err;
   1.114 -}
   1.115 -
   1.116 -int xenbus_read_string(const char *dir, const char *name, char **val)
   1.117 -{
   1.118 -	int err = 0;
   1.119 -
   1.120 -	*val = xenbus_read(dir, name, NULL);
   1.121 -	if (IS_ERR(*val)) {
   1.122 -		err = PTR_ERR(*val);
   1.123 -		*val = NULL;
   1.124 -	}
   1.125 -	return err;
   1.126 -}
   1.127 -
   1.128 -int xenbus_write_string(const char *dir, const char *name, const char *val)
   1.129 -{
   1.130 -	return xenbus_write(dir, name, val, strlen(val));
   1.131 -}
   1.132 -
   1.133 -int xenbus_read_ulong(const char *dir, const char *name, unsigned long *val)
   1.134 -{
   1.135 -	return xenbus_gather(dir, name, "%lu", val, NULL);
   1.136 -}
   1.137 -
   1.138 -int xenbus_write_ulong(const char *dir, const char *name, unsigned long val)
   1.139 -{
   1.140 -	char data[32] = {};
   1.141 -
   1.142 -	snprintf(data, sizeof(data), "%lu", val);
   1.143 -	return xenbus_write(dir, name, data, strlen(data));
   1.144 -}
   1.145 -
   1.146 -int xenbus_read_long(const char *dir, const char *name, long *val)
   1.147 -{
   1.148 -	return xenbus_gather(dir, name, "%li", val, NULL);
   1.149 -}
   1.150 -
   1.151 -int xenbus_write_long(const char *dir, const char *name, long val)
   1.152 -{
   1.153 -	char data[32] = {};
   1.154 -
   1.155 -	snprintf(data, sizeof(data), "%li", val);
   1.156 -	return xenbus_write(dir, name, data, strlen(data));
   1.157 -}
   1.158 -
   1.159  /* If something in array of ids matches this device, return it. */
   1.160  static const struct xenbus_device_id *
   1.161  match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev)
   1.162 @@ -214,68 +77,6 @@ static struct bus_type xenbus_type = {
   1.163  	.match = xenbus_match,
   1.164  };
   1.165  
   1.166 -
   1.167 -/* Bus type for backend drivers. */
   1.168 -static struct bus_type xenback_type = {
   1.169 -	.name  = "xenback",
   1.170 -	.match = xenbus_match,
   1.171 -};
   1.172 -
   1.173 -struct xenbus_for_dev {
   1.174 -	int (*fn)(struct xenbus_device *, void *);
   1.175 -	void *data;
   1.176 -};
   1.177 -
   1.178 -static int for_dev(struct device *_dev, void *_data)
   1.179 -{
   1.180 -	struct xenbus_device *dev = to_xenbus_device(_dev);
   1.181 -	struct xenbus_for_dev *data = _data;
   1.182 -	dev = to_xenbus_device(_dev);
   1.183 -	return data->fn(dev, data->data);
   1.184 -}
   1.185 -
   1.186 -int xenbus_for_each_dev(struct xenbus_device * start, void * data,
   1.187 -			int (*fn)(struct xenbus_device *, void *))
   1.188 -{
   1.189 -	struct xenbus_for_dev for_data = {
   1.190 -		.fn = fn,
   1.191 -		.data = data,
   1.192 -	};
   1.193 -	if (!fn)
   1.194 -		return -EINVAL;
   1.195 -	printk("%s> data=%p fn=%p for_data=%p\n", __FUNCTION__,
   1.196 -	       data, fn, &for_data);
   1.197 -	return bus_for_each_dev(&xenbus_type, 
   1.198 -				(start ? &start->dev : NULL),
   1.199 -				&for_data, for_dev);
   1.200 -}
   1.201 -
   1.202 -struct xenbus_for_drv {
   1.203 -	int (*fn)(struct xenbus_driver *, void *);
   1.204 -	void *data;
   1.205 -};
   1.206 -
   1.207 -static int for_drv(struct device_driver *_drv, void *_data)
   1.208 -{
   1.209 -	struct xenbus_driver *drv = to_xenbus_driver(_drv);
   1.210 -	struct xenbus_for_drv *data = _data;
   1.211 -	return data->fn(drv, data->data);
   1.212 -}
   1.213 -
   1.214 -int xenbus_for_each_drv(struct xenbus_driver * start, void * data,
   1.215 -			int (*fn)(struct xenbus_driver *, void *))
   1.216 -{
   1.217 -	struct xenbus_for_drv for_data = {
   1.218 -		.fn = fn,
   1.219 -		.data = data,
   1.220 -	};
   1.221 -	if (!fn)
   1.222 -		return -EINVAL;
   1.223 -	return bus_for_each_drv(&xenbus_type,
   1.224 -				(start ? &start->driver: NULL),
   1.225 -				&for_data, for_drv);
   1.226 -}
   1.227 -
   1.228  static int xenbus_dev_probe(struct device *_dev)
   1.229  {
   1.230  	struct xenbus_device *dev = to_xenbus_device(_dev);
   1.231 @@ -309,23 +110,13 @@ static int xenbus_dev_remove(struct devi
   1.232  
   1.233  int xenbus_register_driver(struct xenbus_driver *drv)
   1.234  {
   1.235 -	int err = 0;
   1.236 -
   1.237 -	printk("%s> frontend driver %p %s\n", __FUNCTION__,
   1.238 -	       drv, drv->name);
   1.239  	drv->driver.name = drv->name;
   1.240  	drv->driver.bus = &xenbus_type;
   1.241  	drv->driver.owner = drv->owner;
   1.242  	drv->driver.probe = xenbus_dev_probe;
   1.243  	drv->driver.remove = xenbus_dev_remove;
   1.244  
   1.245 -	err = driver_register(&drv->driver);
   1.246 -	if (err == 0 && xs_init_done && drv->connect) {
   1.247 -		printk("%s> connecting driver %p %s\n", __FUNCTION__,
   1.248 -		       drv, drv->name);
   1.249 -		drv->connect(drv);
   1.250 -	}
   1.251 -	return err;
   1.252 +	return driver_register(&drv->driver);
   1.253  }
   1.254  
   1.255  void xenbus_unregister_driver(struct xenbus_driver *drv)
   1.256 @@ -333,39 +124,36 @@ void xenbus_unregister_driver(struct xen
   1.257  	driver_unregister(&drv->driver);
   1.258  }
   1.259  
   1.260 -static int xenbus_probe_device(const char *dir, const char *name, const char *devicetype)
   1.261 +/* devices/<typename>/<name> */
   1.262 +static int xenbus_probe_device(const char *typename, const char *name)
   1.263  {
   1.264  	int err;
   1.265  	struct xenbus_device *xendev;
   1.266 -	unsigned int xendev_n;
   1.267 -	char *nodename;
   1.268 +	unsigned int stringlen;
   1.269  
   1.270 -	dprintf("> dir=%s name=%s\n", dir, name);
   1.271 -	nodename = xenbus_path(dir, name);
   1.272 -	if (!nodename)
   1.273 -		return -ENOMEM;
   1.274 +	pr_debug("> dir=%s name=%s\n", typename, name);
   1.275  
   1.276  	/* FIXME: This could be a rescan. Don't re-register existing devices. */
   1.277  
   1.278 -	/* Add space for the strings. */
   1.279 -	xendev_n = sizeof(*xendev) + strlen(nodename) + strlen(devicetype) + 2;
   1.280 -	xendev = kmalloc(xendev_n, GFP_KERNEL);
   1.281 -	if (!xendev) {
   1.282 -		err = -ENOMEM;
   1.283 -		goto free_nodename;
   1.284 -	}
   1.285 -	memset(xendev, 0, xendev_n);
   1.286 +	/* Nodename: /device/<typename>/<name>/ */
   1.287 +	stringlen = strlen("device") + strlen(typename) + strlen(name) + 3;
   1.288 +	/* Typename */
   1.289 +	stringlen += strlen(typename) + 1;
   1.290  
   1.291 -	snprintf(xendev->dev.bus_id, BUS_ID_SIZE, "%s-%s", devicetype, name);
   1.292 -	xendev->dev.bus = &xenbus_type;
   1.293 +	xendev = kmalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
   1.294 +	if (!xendev)
   1.295 +		return -ENOMEM;
   1.296  
   1.297 -	xendev->id = simple_strtol(name, NULL, 0);
   1.298 -
   1.299 +	memset(xendev, 0, sizeof(*xendev));
   1.300  	/* Copy the strings into the extra space. */
   1.301  	xendev->nodename = (char *)(xendev + 1);
   1.302 -	strcpy(xendev->nodename, nodename);
   1.303 +	sprintf(xendev->nodename, "%s/%s/%s", "device", typename, name);
   1.304  	xendev->devicetype = xendev->nodename + strlen(xendev->nodename) + 1;
   1.305 -	strcpy(xendev->devicetype, devicetype);
   1.306 +	strcpy(xendev->devicetype, typename);
   1.307 +
   1.308 +	/* FIXME: look for "subtype" field. */
   1.309 +	snprintf(xendev->dev.bus_id, BUS_ID_SIZE, "%s-%s", typename, name);
   1.310 +	xendev->dev.bus = &xenbus_type;
   1.311  
   1.312  	/* Register with generic device framework. */
   1.313  	printk("XENBUS: Registering device %s\n", xendev->dev.bus_id);
   1.314 @@ -376,204 +164,62 @@ static int xenbus_probe_device(const cha
   1.315  		kfree(xendev);
   1.316  	}
   1.317  
   1.318 -free_nodename:
   1.319 -	kfree(nodename);
   1.320 -	dprintf("< err=%i\n", err);
   1.321 +	pr_debug("< err=%i\n", err);
   1.322  	return err;
   1.323  }
   1.324  
   1.325 -static int xenbus_probe_device_type(const char *dirpath, const char *typename)
   1.326 +/* /device/<typename> */
   1.327 +static int xenbus_probe_device_type(const char *typename)
   1.328  {
   1.329  	int err = 0;
   1.330  	char **dir;
   1.331 -	char *path;
   1.332  	unsigned int dir_n = 0;
   1.333  	int i;
   1.334  
   1.335 -	dprintf("> dirpath=%s typename=%s\n", dirpath, typename);
   1.336 -	path = xenbus_path(dirpath, typename);
   1.337 -	if (!path)
   1.338 -		return -ENOMEM;
   1.339 -
   1.340 -	dir = xs_directory(path, &dir_n);
   1.341 +	dir = xenbus_directory("device", typename, &dir_n);
   1.342 +	printk("dir %s has %u entries\n", typename, dir_n);
   1.343  	if (IS_ERR(dir)) {
   1.344 -		err = PTR_ERR(dir);
   1.345 -		goto out;
   1.346 +		printk("dir %s returned %li\n", typename, PTR_ERR(dir));
   1.347 +		return PTR_ERR(dir);
   1.348  	}
   1.349  
   1.350  	for (i = 0; i < dir_n; i++) {
   1.351 -		err = xenbus_probe_device(path, dir[i], typename);
   1.352 +		printk("Probing %s/%s\n", dir[i], typename);
   1.353 +		err = xenbus_probe_device(dir[i], typename);
   1.354  		if (err)
   1.355  			break;
   1.356  	}
   1.357  	kfree(dir);
   1.358 -out:
   1.359 -	kfree(path);
   1.360 -	dprintf("< err=%i\n", err);
   1.361 +	pr_debug("< err=%i\n", err);
   1.362  	return err;
   1.363  }
   1.364  
   1.365 -static int xenbus_probe_devices(const char *path)
   1.366 +static int xenbus_probe_devices(void)
   1.367  {
   1.368  	int err = 0;
   1.369  	char **dir;
   1.370  	unsigned int i, dir_n;
   1.371  
   1.372 -	dprintf("> path=%s\n", path);
   1.373 -	down(&xs_lock);
   1.374 -	dir = xs_directory(path, &dir_n);
   1.375 +	down(&xenbus_lock);
   1.376 +	dir = xenbus_directory("device", "", &dir_n);
   1.377  	if (IS_ERR(dir)) {
   1.378  		err = PTR_ERR(dir);
   1.379  		goto unlock;
   1.380  	}
   1.381  	for (i = 0; i < dir_n; i++) {
   1.382 -		err = xenbus_probe_device_type(path, dir[i]);
   1.383 -		if (err)
   1.384 +		err = xenbus_probe_device_type(dir[i]);
   1.385 +		if (err) {
   1.386 +			printk("xenbus: error %i probing device %s\n",
   1.387 +			       -err, dir[i]);
   1.388  			break;
   1.389 +		}
   1.390  	}
   1.391  	kfree(dir);
   1.392  unlock:
   1.393 -	up(&xs_lock);
   1.394 -	dprintf("< err=%i\n", err);
   1.395 -	return err;
   1.396 -}
   1.397 -
   1.398 -
   1.399 -static int xenbus_probe_backend(const char *dir, const char *name)
   1.400 -{
   1.401 -	int err = 0;
   1.402 -	struct xenbus_device *xendev = NULL;
   1.403 -	unsigned int xendev_n = 0;
   1.404 -	char *nodename = NULL, *devicetype = NULL;
   1.405 -	unsigned int devicetype_n = 0;
   1.406 -
   1.407 -	dprintf("> dir=%s name=%s\n", dir, name);
   1.408 -	nodename = xenbus_path(dir, name);
   1.409 -	if (!nodename)
   1.410 -		return -ENOMEM;
   1.411 -
   1.412 -	devicetype = xenbus_read(nodename, XENBUS_DEVICE_TYPE, &devicetype_n);
   1.413 -	if (IS_ERR(devicetype)) {
   1.414 -		err = PTR_ERR(devicetype);
   1.415 -		goto free_nodename;
   1.416 -	}
   1.417 -
   1.418 -	dprintf("> devicetype='%s'\n", devicetype);
   1.419 -	/* FIXME: This could be a rescan. Don't re-register existing devices. */
   1.420 -
   1.421 -	/* Add space for the strings. */
   1.422 -	xendev_n = sizeof(*xendev) + strlen(nodename) + strlen(devicetype) + 2;
   1.423 -	xendev = kmalloc(xendev_n, GFP_KERNEL);
   1.424 -	if (!xendev) {
   1.425 -		err = -ENOMEM;
   1.426 -		goto free_devicetype;
   1.427 -	}
   1.428 -	memset(xendev, 0, xendev_n);
   1.429 -
   1.430 -	snprintf(xendev->dev.bus_id, BUS_ID_SIZE, "%s", devicetype);
   1.431 -	xendev->dev.bus = &xenback_type;
   1.432 -
   1.433 -	/* Copy the strings into the extra space. */
   1.434 -	xendev->nodename = (char *)(xendev + 1);
   1.435 -	strcpy(xendev->nodename, nodename);
   1.436 -	xendev->devicetype = xendev->nodename + strlen(xendev->nodename) + 1;
   1.437 -	strcpy(xendev->devicetype, devicetype);
   1.438 -
   1.439 -	/* Register with generic device framework. */
   1.440 -	printk("XENBUS: Registering backend %s\n", xendev->dev.bus_id);
   1.441 -	err = device_register(&xendev->dev);
   1.442 -	if (err) {
   1.443 -		printk("XENBUS: Registering device %s: error %i\n",
   1.444 -		       xendev->dev.bus_id, err);
   1.445 -		kfree(xendev);
   1.446 -	}
   1.447 -
   1.448 -free_devicetype:
   1.449 -	kfree(devicetype);
   1.450 -free_nodename:
   1.451 -	kfree(nodename);
   1.452 -	dprintf("< err=%i\n", err);
   1.453 +	up(&xenbus_lock);
   1.454  	return err;
   1.455  }
   1.456  
   1.457 -static int xenbus_probe_backends(const char *path)
   1.458 -{
   1.459 -	int err = 0;
   1.460 -	char **dir;
   1.461 -	unsigned int i, dir_n;
   1.462 -
   1.463 -	dprintf("> path=%s\n", path);
   1.464 -	down(&xs_lock);
   1.465 -	dir = xs_directory(path, &dir_n);
   1.466 -	if (IS_ERR(dir)) {
   1.467 -		err = PTR_ERR(dir);
   1.468 -		goto unlock;
   1.469 -	}
   1.470 -	for (i = 0; i < dir_n; i++) {
   1.471 -		err = xenbus_probe_backend(path, dir[i]);
   1.472 -		if (err)
   1.473 -			break;
   1.474 -	}
   1.475 -	kfree(dir);
   1.476 -unlock:
   1.477 -	up(&xs_lock);
   1.478 -	dprintf("< err=%i\n", err);
   1.479 -	return err;
   1.480 -}
   1.481 -
   1.482 -int xenbus_register_backend(struct xenbus_driver *drv)
   1.483 -{
   1.484 -	int err = 0;
   1.485 -
   1.486 -	printk("%s> backend driver %p %s\n", __FUNCTION__,
   1.487 -	       drv, drv->name);
   1.488 -	drv->driver.name = drv->name;
   1.489 -	drv->driver.bus = &xenback_type;
   1.490 -	drv->driver.owner = drv->owner;
   1.491 -	drv->driver.probe = xenbus_dev_probe;
   1.492 -	drv->driver.remove = xenbus_dev_remove;
   1.493 -
   1.494 -	err = driver_register(&drv->driver);
   1.495 -	if (err == 0 && xs_init_done && drv->connect) {
   1.496 -		printk("%s> connecting driver %p %s\n", __FUNCTION__,
   1.497 -		       drv, drv->name);
   1.498 -		drv->connect(drv);
   1.499 -	}
   1.500 -	return err;
   1.501 -}
   1.502 -
   1.503 -void xenbus_unregister_backend(struct xenbus_driver *drv)
   1.504 -{
   1.505 -	driver_unregister(&drv->driver);
   1.506 -}
   1.507 -
   1.508 -int xenbus_for_each_backend(struct xenbus_driver * start, void * data,
   1.509 -			    int (*fn)(struct xenbus_driver *, void *))
   1.510 -{
   1.511 -	struct xenbus_for_drv for_data = {
   1.512 -		.fn = fn,
   1.513 -		.data = data,
   1.514 -	};
   1.515 -	if (!fn)
   1.516 -		return -EINVAL;
   1.517 -	return bus_for_each_drv(&xenback_type,
   1.518 -				(start ? &start->driver: NULL),
   1.519 -				&for_data, for_drv);
   1.520 -}
   1.521 -
   1.522 -static int xenbus_driver_connect(struct xenbus_driver *drv, void *data)
   1.523 -{
   1.524 -	printk("%s> driver %p %s\n", __FUNCTION__, drv, drv->name);
   1.525 -	if (drv->connect) {
   1.526 -		printk("%s> connecting driver %p %s\n", __FUNCTION__,
   1.527 -		       drv, drv->name);
   1.528 -		drv->connect(drv);
   1.529 -	}
   1.530 -	printk("%s< driver %p %s\n", __FUNCTION__, drv, drv->name);
   1.531 -	return 0;
   1.532 -}
   1.533 -
   1.534 -
   1.535  /* called from a thread in privcmd/privcmd.c */
   1.536  int do_xenbus_probe(void *unused)
   1.537  {
   1.538 @@ -592,15 +238,8 @@ int do_xenbus_probe(void *unused)
   1.539  	}
   1.540  	xs_init_done = 1;
   1.541  
   1.542 -	/* Notify drivers that xenstore has connected. */
   1.543 -	printk("%s> connect drivers...\n", __FUNCTION__);
   1.544 -	xenbus_for_each_drv(NULL, NULL, xenbus_driver_connect);
   1.545 -	printk("%s> connect backends...\n", __FUNCTION__);
   1.546 -	xenbus_for_each_backend(NULL, NULL, xenbus_driver_connect);
   1.547 -	
   1.548 -	/* Enumerate devices and backends in xenstore. */
   1.549 -	xenbus_probe_devices("device");
   1.550 -	xenbus_probe_backends("backend");
   1.551 +	/* Enumerate devices in xenstore. */
   1.552 +	xenbus_probe_devices();
   1.553  
   1.554  exit:
   1.555  	printk("%s< err=%d\n", __FUNCTION__, err);
   1.556 @@ -610,7 +249,6 @@ exit:
   1.557  static int __init xenbus_probe_init(void)
   1.558  {
   1.559  	bus_register(&xenbus_type);
   1.560 -	bus_register(&xenback_type);
   1.561  
   1.562  	if (!xen_start_info.store_evtchn)
   1.563  		return 0;
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Jul 26 15:57:18 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Jul 26 16:59:40 2005 +0000
     2.3 @@ -2,7 +2,7 @@
     2.4   * xenbus_xs.c
     2.5   *
     2.6   * This is the kernel equivalent of the "xs" library.  We don't need everything
     2.7 - * and we use xenbus_comms to communication.
     2.8 + * and we use xenbus_comms for communication.
     2.9   *
    2.10   * Copyright (C) 2005 Rusty Russell, IBM Corporation
    2.11   * 
    2.12 @@ -45,7 +45,7 @@
    2.13  
    2.14  static void *xs_in, *xs_out;
    2.15  static LIST_HEAD(watches);
    2.16 -DECLARE_MUTEX(xs_lock);
    2.17 +DECLARE_MUTEX(xenbus_lock);
    2.18  
    2.19  static int get_error(const char *errorstring)
    2.20  {
    2.21 @@ -90,7 +90,7 @@ static void *read_reply(enum xsd_sockmsg
    2.22  }
    2.23  
    2.24  /* Emergency write. */
    2.25 -void xs_debug_write(const char *str, unsigned int count)
    2.26 +void xenbus_debug_write(const char *str, unsigned int count)
    2.27  {
    2.28  	struct xsd_sockmsg msg;
    2.29  	void *out = (void *)xen_start_info.store_page;
    2.30 @@ -115,7 +115,7 @@ static void *xs_talkv(enum xsd_sockmsg_t
    2.31  	unsigned int i;
    2.32  	int err;
    2.33  
    2.34 -	WARN_ON(down_trylock(&xs_lock) == 0);
    2.35 +	WARN_ON(down_trylock(&xenbus_lock) == 0);
    2.36  
    2.37  	msg.type = type;
    2.38  	msg.len = 0;
    2.39 @@ -182,12 +182,28 @@ static unsigned int count_strings(const 
    2.40  	return num;
    2.41  }
    2.42  
    2.43 -char **xs_directory(const char *path, unsigned int *num)
    2.44 +/* Return the path to dir with /name appended. */ 
    2.45 +static char *join(const char *dir, const char *name)
    2.46 +{
    2.47 +	static char buffer[4096];
    2.48 +
    2.49 +	BUG_ON(down_trylock(&xenbus_lock) == 0);
    2.50 +	BUG_ON(strlen(dir) + strlen("/") + strlen(name) + 1 > sizeof(buffer));
    2.51 +
    2.52 +	strcpy(buffer, dir);
    2.53 +	if (!streq(name, "")) {
    2.54 +		strcat(buffer, "/");
    2.55 +		strcat(buffer, name);
    2.56 +	}
    2.57 +	return buffer;
    2.58 +}
    2.59 +
    2.60 +char **xenbus_directory(const char *dir, const char *node, unsigned int *num)
    2.61  {
    2.62  	char *strings, *p, **ret;
    2.63  	unsigned int len;
    2.64  
    2.65 -	strings = xs_single(XS_DIRECTORY, path, &len);
    2.66 +	strings = xs_single(XS_DIRECTORY, join(dir, node), &len);
    2.67  	if (IS_ERR(strings))
    2.68  		return (char **)strings;
    2.69  
    2.70 @@ -210,67 +226,37 @@ char **xs_directory(const char *path, un
    2.71  }
    2.72  
    2.73  /* Check if a path exists. Return 1 if it does. */
    2.74 -int xs_exists(const char *path)
    2.75 +int xenbus_exists(const char *dir, const char *node)
    2.76  {
    2.77 -	char **dir;
    2.78 +	char **d;
    2.79  	int dir_n;
    2.80  
    2.81 -	dir = xs_directory(path, &dir_n);
    2.82 -	if (IS_ERR(dir))
    2.83 +	d = xenbus_directory(path, node, &dir_n);
    2.84 +	if (IS_ERR(d))
    2.85  		return 0;
    2.86 -	kfree(dir);
    2.87 +	kfree(d);
    2.88  	return 1;
    2.89  }
    2.90  
    2.91 -/* Make a directory, creating dirs on the path to it if necessary.
    2.92 - * Return 0 on success, error code otherwise.
    2.93 - */
    2.94 -int xs_mkdirs(const char *path)
    2.95 -{
    2.96 -	int err = 0;
    2.97 -	char s[strlen(path) + 1], *p = s;
    2.98 -
    2.99 -	if (xs_exists(path))
   2.100 -		goto out;
   2.101 -	strcpy(p, path);
   2.102 -	if (*p == '/')
   2.103 -		p++;
   2.104 -	for (;;) {
   2.105 -		p = strchr(p, '/');
   2.106 -		if (p)
   2.107 -			*p = '\0';
   2.108 -		if (!xs_exists(s)) {
   2.109 -			err = xs_mkdir(s);
   2.110 -			if (err)
   2.111 -				goto out;
   2.112 -		}
   2.113 -		if (!p)
   2.114 -			break;
   2.115 -		*p++ = '/';
   2.116 -	}
   2.117 - out:
   2.118 -	return err;
   2.119 -}
   2.120 -
   2.121 -
   2.122  /* Get the value of a single file.
   2.123   * Returns a kmalloced value: call free() on it after use.
   2.124   * len indicates length in bytes.
   2.125   */
   2.126 -void *xs_read(const char *path, unsigned int *len)
   2.127 +void *xenbus_read(const char *dir, const char *node, unsigned int *len)
   2.128  {
   2.129 -	return xs_single(XS_READ, path, len);
   2.130 +	return xs_single(XS_READ, join(dir, node), len);
   2.131  }
   2.132  
   2.133  /* Write the value of a single file.
   2.134   * Returns -err on failure.  createflags can be 0, O_CREAT, or O_CREAT|O_EXCL.
   2.135   */
   2.136 -int xs_write(const char *path,
   2.137 -	      const void *data, unsigned int len, int createflags)
   2.138 +int xenbus_write(const char *dir, const char *node,
   2.139 +		 const char *string, int createflags)
   2.140  {
   2.141 -	const char *flags;
   2.142 +	const char *flags, *path;
   2.143  	struct kvec iovec[3];
   2.144  
   2.145 +	path = join(dir, node);
   2.146  	/* Format: Flags (as string), path, data. */
   2.147  	if (createflags == 0)
   2.148  		flags = XS_WRITE_NONE;
   2.149 @@ -285,22 +271,22 @@ int xs_write(const char *path,
   2.150  	iovec[0].iov_len = strlen(path) + 1;
   2.151  	iovec[1].iov_base = (void *)flags;
   2.152  	iovec[1].iov_len = strlen(flags) + 1;
   2.153 -	iovec[2].iov_base = (void *)data;
   2.154 -	iovec[2].iov_len = len;
   2.155 +	iovec[2].iov_base = (void *)string;
   2.156 +	iovec[2].iov_len = strlen(string);
   2.157  
   2.158  	return xs_error(xs_talkv(XS_WRITE, iovec, ARRAY_SIZE(iovec), NULL));
   2.159  }
   2.160  
   2.161  /* Create a new directory. */
   2.162 -int xs_mkdir(const char *path)
   2.163 +int xenbus_mkdir(const char *dir, const char *node)
   2.164  {
   2.165 -	return xs_error(xs_single(XS_MKDIR, path, NULL));
   2.166 +	return xs_error(xs_single(XS_MKDIR, join(dir, node), NULL));
   2.167  }
   2.168  
   2.169  /* Destroy a file or directory (directories must be empty). */
   2.170 -int xs_rm(const char *path)
   2.171 +int xenbus_rm(const char *dir, const char *node)
   2.172  {
   2.173 -	return xs_error(xs_single(XS_RM, path, NULL));
   2.174 +	return xs_error(xs_single(XS_RM, join(dir, node), NULL));
   2.175  }
   2.176  
   2.177  /* Start a transaction: changes by others will not be seen during this
   2.178 @@ -308,7 +294,7 @@ int xs_rm(const char *path)
   2.179   * Transaction only applies to the given subtree.
   2.180   * You can only have one transaction at any time.
   2.181   */
   2.182 -int xs_transaction_start(const char *subtree)
   2.183 +int xenbus_transaction_start(const char *subtree)
   2.184  {
   2.185  	return xs_error(xs_single(XS_TRANSACTION_START, subtree, NULL));
   2.186  }
   2.187 @@ -316,7 +302,7 @@ int xs_transaction_start(const char *sub
   2.188  /* End a transaction.
   2.189   * If abandon is true, transaction is discarded instead of committed.
   2.190   */
   2.191 -int xs_transaction_end(int abort)
   2.192 +int xenbus_transaction_end(int abort)
   2.193  {
   2.194  	char abortstr[2];
   2.195  
   2.196 @@ -327,12 +313,68 @@ int xs_transaction_end(int abort)
   2.197  	return xs_error(xs_single(XS_TRANSACTION_END, abortstr, NULL));
   2.198  }
   2.199  
   2.200 -char *xs_get_domain_path(domid_t domid)
   2.201 +/* Single read and scanf: returns -errno or num scanned. */
   2.202 +int xenbus_scanf(const char *dir, const char *node, const char *fmt, ...)
   2.203 +{
   2.204 +	va_list ap;
   2.205 +	int ret;
   2.206 +	char *val;
   2.207 +
   2.208 +	val = xenbus_read(dir, node, NULL);
   2.209 +	if (IS_ERR(val))
   2.210 +		return PTR_ERR(val);
   2.211 +
   2.212 +	va_start(ap, fmt);
   2.213 +	ret = vsscanf(val, fmt, ap);
   2.214 +	va_end(ap);
   2.215 +	kfree(val);
   2.216 +	/* Distinctive errno. */
   2.217 +	if (ret == 0)
   2.218 +		return -ERANGE;
   2.219 +	return ret;
   2.220 +}
   2.221 +
   2.222 +/* Single printf and write: returns -errno or 0. */
   2.223 +int xenbus_printf(const char *dir, const char *node, const char *fmt, ...)
   2.224  {
   2.225 -	char domid_str[32];
   2.226 +	va_list ap;
   2.227 +	int ret;
   2.228 +	static char buffer[4096];
   2.229 +
   2.230 +	BUG_ON(down_trylock(&xenbus_lock) == 0);
   2.231 +	va_start(ap, fmt);
   2.232 +	ret = vsnprintf(buffer, sizeof(buffer), fmt, ap);
   2.233 +	va_end(ap);
   2.234 +
   2.235 +	BUG_ON(ret > sizeof(buffer)-1);
   2.236 +
   2.237 +	return xenbus_write(dir, node, buffer, ret+1);
   2.238 +}
   2.239  
   2.240 -	sprintf(domid_str, "%u", domid);
   2.241 -	return xs_single(XS_GETDOMAINPATH, domid_str, NULL);
   2.242 +/* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
   2.243 +int xenbus_gather(const char *dir, ...)
   2.244 +{
   2.245 +	va_list ap;
   2.246 +	const char *name;
   2.247 +	int ret = 0;
   2.248 +
   2.249 +	va_start(ap, dir);
   2.250 +	while (ret == 0 && (name = va_arg(ap, char *)) != NULL) {
   2.251 +		const char *fmt = va_arg(ap, char *);
   2.252 +		void *result = va_arg(ap, void *);
   2.253 +		char *p;
   2.254 +
   2.255 +		p = xenbus_read(dir, name, NULL);
   2.256 +		if (IS_ERR(p)) {
   2.257 +			ret = PTR_ERR(p);
   2.258 +			break;
   2.259 +		}
   2.260 +		if (sscanf(p, fmt, result) == 0)
   2.261 +			ret = -EINVAL;
   2.262 +		kfree(p);
   2.263 +	}
   2.264 +	va_end(ap);
   2.265 +	return ret;
   2.266  }
   2.267  
   2.268  static int xs_watch(const char *path, const char *token, unsigned int priority)
   2.269 @@ -429,7 +471,6 @@ void unregister_xenbus_watch(struct xenb
   2.270  
   2.271  static int watch_thread(void *unused)
   2.272  {
   2.273 -
   2.274  	for (;;) {
   2.275  		char *token;
   2.276  		char *node = NULL;
   2.277 @@ -440,7 +481,7 @@ static int watch_thread(void *unused)
   2.278  		 * doing an op, they'll hold the lock and the buffer
   2.279  		 * will be empty by the time we get there.		 
   2.280  		 */
   2.281 -		down(&xs_lock);
   2.282 +		down(&xenbus_lock);
   2.283  		if (xs_input_avail(xs_in))
   2.284  			node = xs_read_watch(&token);
   2.285  
   2.286 @@ -461,7 +502,7 @@ static int watch_thread(void *unused)
   2.287  		} else
   2.288  			printk(KERN_WARNING "XENBUS xs_read_watch: %li\n",
   2.289  			       PTR_ERR(node));
   2.290 -		up(&xs_lock);
   2.291 +		up(&xenbus_lock);
   2.292  	}
   2.293  }
   2.294  
     3.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Tue Jul 26 15:57:18 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Tue Jul 26 16:59:40 2005 +0000
     3.3 @@ -36,7 +36,6 @@ struct xenbus_device {
     3.4  	char *devicetype;
     3.5  	char *subtype;
     3.6  	char *nodename;
     3.7 -	int id;
     3.8  	struct device dev;
     3.9  	void *data;
    3.10  };
    3.11 @@ -58,23 +57,13 @@ struct xenbus_driver {
    3.12  	char *name;
    3.13  	struct module *owner;
    3.14  	const struct xenbus_device_id *ids;
    3.15 -        /* Called when xenstore is connected. */
    3.16 -        int  (*connect) (struct xenbus_driver * drv);
    3.17 -
    3.18 -	int  (*probe)    (struct xenbus_device * dev, const struct xenbus_device_id * id);
    3.19 +	int  (*probe)    (struct xenbus_device * dev,
    3.20 +			  const struct xenbus_device_id * id);
    3.21          int  (*remove)   (struct xenbus_device * dev);
    3.22 -        int  (*configure)(struct xenbus_device * dev);
    3.23  
    3.24  	struct device_driver driver;
    3.25  };
    3.26  
    3.27 -struct xenbus_evtchn {
    3.28 -        unsigned long dom1;
    3.29 -        unsigned long port1;
    3.30 -        unsigned long dom2;
    3.31 -        unsigned long port2;
    3.32 -};
    3.33 -
    3.34  static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
    3.35  {
    3.36  	return container_of(drv, struct xenbus_driver, driver);
    3.37 @@ -83,36 +72,31 @@ static inline struct xenbus_driver *to_x
    3.38  int xenbus_register_driver(struct xenbus_driver *drv);
    3.39  void xenbus_unregister_driver(struct xenbus_driver *drv);
    3.40  
    3.41 -int xenbus_register_backend(struct xenbus_driver *drv);
    3.42 -void xenbus_unregister_backend(struct xenbus_driver *drv);
    3.43 -
    3.44 -/* Iterator over xenbus devices (frontend). */
    3.45 -int xenbus_for_each_dev(struct xenbus_device * start, void * data,
    3.46 -                        int (*fn)(struct xenbus_device *, void *));
    3.47 -
    3.48 -/* Iterator over xenbus drivers (frontend). */
    3.49 -int xenbus_for_each_drv(struct xenbus_driver * start, void * data,
    3.50 -                        int (*fn)(struct xenbus_driver *, void *));
    3.51 -
    3.52 -/* Iterator over xenbus drivers (backend). */
    3.53 -int xenbus_for_each_backend(struct xenbus_driver * start, void * data,
    3.54 -                            int (*fn)(struct xenbus_driver *, void *));
    3.55 -
    3.56  /* Caller must hold this lock to call these functions: it's also held
    3.57   * across watch callbacks. */
    3.58 -extern struct semaphore xs_lock;
    3.59 +extern struct semaphore xenbus_lock;
    3.60 +
    3.61 +char **xenbus_directory(const char *dir, const char *node, unsigned int *num);
    3.62 +void *xenbus_read(const char *dir, const char *node, unsigned int *len);
    3.63 +int xenbus_write(const char *dir, const char *node,
    3.64 +		 const char *string, int createflags);
    3.65 +int xenbus_mkdir(const char *dir, const char *node);
    3.66 +int xenbus_exists(const char *dir, const char *node);
    3.67 +int xenbus_rm(const char *dir, const char *node);
    3.68 +int xenbus_transaction_start(const char *subtree);
    3.69 +int xenbus_transaction_end(int abort);
    3.70  
    3.71 -char **xs_directory(const char *path, unsigned int *num);
    3.72 -void *xs_read(const char *path, unsigned int *len);
    3.73 -int xs_write(const char *path,
    3.74 -	     const void *data, unsigned int len, int createflags);
    3.75 -int xs_mkdir(const char *path);
    3.76 -int xs_exists(const char *path);
    3.77 -int xs_mkdirs(const char *path);
    3.78 -int xs_rm(const char *path);
    3.79 -int xs_transaction_start(const char *subtree);
    3.80 -int xs_transaction_end(int abort);
    3.81 -char *xs_get_domain_path(domid_t domid);
    3.82 +/* Single read and scanf: returns -errno or num scanned if > 0. */
    3.83 +int xenbus_scanf(const char *dir, const char *node, const char *fmt, ...)
    3.84 +	__attribute__((format(scanf, 3, 4)));
    3.85 +
    3.86 +/* Single printf and write: returns -errno or 0. */
    3.87 +int xenbus_printf(const char *dir, const char *node, const char *fmt, ...)
    3.88 +	__attribute__((format(printf, 3, 4)));
    3.89 +
    3.90 +/* Generic read function: NULL-terminated triples of name,
    3.91 + * sprintf-style type string, and pointer. Returns 0 or errno.*/
    3.92 +int xenbus_gather(const char *dir, ...);
    3.93  
    3.94  /* Register callback to watch this node. */
    3.95  struct xenbus_watch
    3.96 @@ -126,20 +110,4 @@ struct xenbus_watch
    3.97  int register_xenbus_watch(struct xenbus_watch *watch);
    3.98  void unregister_xenbus_watch(struct xenbus_watch *watch);
    3.99  
   3.100 -/* Generic read function: NULL-terminated triples of name,
   3.101 - * sprintf-style type string, and pointer. */
   3.102 -int xenbus_gather(const char *dir, ...);
   3.103 -
   3.104 -char *xenbus_path(const char *dir, const char *name);
   3.105 -char *xenbus_read(const char *dir, const char *name, unsigned int *data_n);
   3.106 -int xenbus_write(const char *dir, const char *name,
   3.107 -                 const char *data, int data_n);
   3.108 -
   3.109 -int xenbus_read_string(const char *dir, const char *name, char **val);
   3.110 -int xenbus_write_string(const char *dir, const char *name, const char *val);
   3.111 -int xenbus_read_ulong(const char *dir, const char *name, unsigned long *val);
   3.112 -int xenbus_write_ulong(const char *dir, const char *name, unsigned long val);
   3.113 -int xenbus_read_long(const char *dir, const char *name, long *val);
   3.114 -int xenbus_write_long(const char *dir, const char *name, long val);
   3.115 -
   3.116  #endif /* _ASM_XEN_XENBUS_H */