33 #define DPRINTK(fmt, args...) \
34 pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \
35 __func__, __LINE__, ##args)
37 #include <linux/kernel.h>
39 #include <linux/string.h>
40 #include <linux/ctype.h>
41 #include <linux/fcntl.h>
48 #include <linux/slab.h>
49 #include <linux/module.h>
52 #include <asm/pgtable.h>
53 #include <asm/xen/hypervisor.h>
57 #include <xen/events.h>
72 static unsigned long xen_store_mfn;
94 return match_device(drv->
ids, to_xenbus_device(_dev)) !=
NULL;
120 free_otherend_watch(dev);
121 free_otherend_details(dev);
140 char *id_node,
char *path_node)
148 "reading other end details from %s",
155 "unable to read other end from %s. "
156 "missing or inaccessible.",
158 free_otherend_details(xendev);
167 const char **vec,
unsigned int len,
168 int ignore_on_shutdown)
187 dev_dbg(&dev->
dev,
"state is %d, (%s), %s, %s\n",
220 id = match_device(drv->
ids, dev);
226 err = talk_to_otherend(dev);
228 dev_warn(&dev->
dev,
"talk_to_otherend on %s failed.\n",
233 err = drv->
probe(dev,
id);
237 err = watch_otherend(dev);
239 dev_warn(&dev->
dev,
"watch_otherend on %s failed.\n",
259 free_otherend_watch(dev);
264 free_otherend_details(dev);
314 static int cmp_dev(
struct device *dev,
void *
data)
336 static int cleanup_dev(
struct device *dev,
void *
data)
357 static void xenbus_cleanup_devices(
const char *
path,
struct bus_type *
bus)
371 static void xenbus_dev_release(
struct device *dev)
374 kfree(to_xenbus_device(dev));
392 return sprintf(buf,
"%s:%s\n", dev->
bus->name,
406 const char *nodename)
423 xendev = kzalloc(
sizeof(*xendev) + stringlen,
GFP_KERNEL);
431 tmpstring = (
char *)(xendev + 1);
432 strcpy(tmpstring, nodename);
435 tmpstring +=
strlen(tmpstring) + 1;
438 init_completion(&xendev->
down);
440 xendev->
dev.bus = &bus->
bus;
441 xendev->
dev.release = xenbus_dev_release;
461 static int xenbus_probe_device_type(
struct xen_bus_type *bus,
const char *
type)
465 unsigned int dir_n = 0;
472 for (i = 0; i < dir_n; i++) {
473 err = bus->
probe(bus, type, dir[i]);
486 unsigned int i, dir_n;
492 for (i = 0; i < dir_n; i++) {
493 err = xenbus_probe_device_type(bus, dir[i]);
503 static unsigned int char_count(
const char *
str,
char c)
505 unsigned int i,
ret = 0;
507 for (i = 0; str[
i]; i++)
513 static int strsep_len(
const char *str,
char c,
unsigned int len)
517 for (i = 0; str[
i]; i++)
523 return (len == 0) ? i : -
ERANGE;
531 const char *
p, *
root;
533 if (char_count(node,
'/') < 2)
538 xenbus_cleanup_devices(node, &bus->
bus);
543 p =
strchr(node,
'/') + 1;
547 rootlen = strsep_len(node,
'/', bus->
levels);
554 dev = xenbus_device_find(root, &bus->
bus);
575 drv = to_xenbus_driver(dev->
driver);
580 "xenbus: suspend %s failed: %i\n", dev_name(dev), err);
596 drv = to_xenbus_driver(dev->
driver);
597 err = talk_to_otherend(xdev);
600 "xenbus: resume (talk_to_otherend) %s failed: %i\n",
611 "xenbus: resume %s failed: %i\n",
617 err = watch_otherend(xdev);
620 "xenbus_probe: resume (watch_otherend) %s failed: "
621 "%d.\n", dev_name(dev), err);
645 if (xenstored_ready > 0)
669 static int __init xenbus_probe_initcall(
void)
686 static int __init xenstored_local_init(
void)
689 unsigned long page = 0;
728 static int __init xenbus_init(
void)
752 err = xenstored_local_init();
770 xen_store_mfn = (
unsigned long)v;
771 xen_store_interface =
775 pr_warn(
"Xenstore state unknown\n");
783 "XENBUS: Error initializing xenstore comms: %i\n", err);
787 #ifdef CONFIG_XEN_COMPAT_XENFS