1 /******************************************************************************
2 * Talks to Xen Store to figure out what devices we have.
4 * Copyright (C) 2005 Rusty Russell, IBM Corporation
5 * Copyright (C) 2005 Mike Wray, Hewlett-Packard
6 * Copyright (C) 2005, 2006 XenSource Ltd
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation; or, when distributed
11 * separately from the Linux kernel or incorporated into other
12 * software packages, subject to the following license:
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this source file (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use, copy, modify,
17 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18 * and to permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 #define DPRINTK(fmt, args...) \
34 pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \
35 __func__, __LINE__, ##args)
37 #include <linux/kernel.h>
38 #include <linux/err.h>
39 #include <linux/string.h>
40 #include <linux/ctype.h>
41 #include <linux/fcntl.h>
43 #include <linux/proc_fs.h>
44 #include <linux/notifier.h>
45 #include <linux/kthread.h>
46 #include <linux/mutex.h>
50 #include <asm/pgtable.h>
51 #include <asm/xen/hypervisor.h>
52 #include <xen/xenbus.h>
53 #include <xen/events.h>
56 #include "xenbus_comms.h"
57 #include "xenbus_probe.h"
61 EXPORT_SYMBOL(xen_store_evtchn
);
63 struct xenstore_domain_interface
*xen_store_interface
;
64 static unsigned long xen_store_mfn
;
66 static BLOCKING_NOTIFIER_HEAD(xenstore_chain
);
68 static void wait_for_devices(struct xenbus_driver
*xendrv
);
70 static int xenbus_probe_frontend(const char *type
, const char *name
);
72 static void xenbus_dev_shutdown(struct device
*_dev
);
74 /* If something in array of ids matches this device, return it. */
75 static const struct xenbus_device_id
*
76 match_device(const struct xenbus_device_id
*arr
, struct xenbus_device
*dev
)
78 for (; *arr
->devicetype
!= '\0'; arr
++) {
79 if (!strcmp(arr
->devicetype
, dev
->devicetype
))
85 int xenbus_match(struct device
*_dev
, struct device_driver
*_drv
)
87 struct xenbus_driver
*drv
= to_xenbus_driver(_drv
);
92 return match_device(drv
->ids
, to_xenbus_device(_dev
)) != NULL
;
95 static int xenbus_uevent(struct device
*_dev
, struct kobj_uevent_env
*env
)
97 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
99 if (add_uevent_var(env
, "MODALIAS=xen:%s", dev
->devicetype
))
105 /* device/<type>/<id> => <type>-<id> */
106 static int frontend_bus_id(char bus_id
[XEN_BUS_ID_SIZE
], const char *nodename
)
108 nodename
= strchr(nodename
, '/');
109 if (!nodename
|| strlen(nodename
+ 1) >= XEN_BUS_ID_SIZE
) {
110 printk(KERN_WARNING
"XENBUS: bad frontend %s\n", nodename
);
114 strlcpy(bus_id
, nodename
+ 1, XEN_BUS_ID_SIZE
);
115 if (!strchr(bus_id
, '/')) {
116 printk(KERN_WARNING
"XENBUS: bus_id %s no slash\n", bus_id
);
119 *strchr(bus_id
, '/') = '-';
124 static void free_otherend_details(struct xenbus_device
*dev
)
126 kfree(dev
->otherend
);
127 dev
->otherend
= NULL
;
131 static void free_otherend_watch(struct xenbus_device
*dev
)
133 if (dev
->otherend_watch
.node
) {
134 unregister_xenbus_watch(&dev
->otherend_watch
);
135 kfree(dev
->otherend_watch
.node
);
136 dev
->otherend_watch
.node
= NULL
;
141 int read_otherend_details(struct xenbus_device
*xendev
,
142 char *id_node
, char *path_node
)
144 int err
= xenbus_gather(XBT_NIL
, xendev
->nodename
,
145 id_node
, "%i", &xendev
->otherend_id
,
146 path_node
, NULL
, &xendev
->otherend
,
149 xenbus_dev_fatal(xendev
, err
,
150 "reading other end details from %s",
154 if (strlen(xendev
->otherend
) == 0 ||
155 !xenbus_exists(XBT_NIL
, xendev
->otherend
, "")) {
156 xenbus_dev_fatal(xendev
, -ENOENT
,
157 "unable to read other end from %s. "
158 "missing or inaccessible.",
160 free_otherend_details(xendev
);
168 static int read_backend_details(struct xenbus_device
*xendev
)
170 return read_otherend_details(xendev
, "backend-id", "backend");
173 static struct device_attribute xenbus_dev_attrs
[] = {
177 /* Bus type for frontend drivers. */
178 static struct xen_bus_type xenbus_frontend
= {
180 .levels
= 2, /* device/type/<id> */
181 .get_bus_id
= frontend_bus_id
,
182 .probe
= xenbus_probe_frontend
,
185 .match
= xenbus_match
,
186 .uevent
= xenbus_uevent
,
187 .probe
= xenbus_dev_probe
,
188 .remove
= xenbus_dev_remove
,
189 .shutdown
= xenbus_dev_shutdown
,
190 .dev_attrs
= xenbus_dev_attrs
,
194 static void otherend_changed(struct xenbus_watch
*watch
,
195 const char **vec
, unsigned int len
)
197 struct xenbus_device
*dev
=
198 container_of(watch
, struct xenbus_device
, otherend_watch
);
199 struct xenbus_driver
*drv
= to_xenbus_driver(dev
->dev
.driver
);
200 enum xenbus_state state
;
202 /* Protect us against watches firing on old details when the otherend
203 details change, say immediately after a resume. */
204 if (!dev
->otherend
||
205 strncmp(dev
->otherend
, vec
[XS_WATCH_PATH
],
206 strlen(dev
->otherend
))) {
207 dev_dbg(&dev
->dev
, "Ignoring watch at %s\n",
212 state
= xenbus_read_driver_state(dev
->otherend
);
214 dev_dbg(&dev
->dev
, "state is %d, (%s), %s, %s\n",
215 state
, xenbus_strstate(state
), dev
->otherend_watch
.node
,
219 * Ignore xenbus transitions during shutdown. This prevents us doing
220 * work that can fail e.g., when the rootfs is gone.
222 if (system_state
> SYSTEM_RUNNING
) {
223 struct xen_bus_type
*bus
= bus
;
224 bus
= container_of(dev
->dev
.bus
, struct xen_bus_type
, bus
);
225 /* If we're frontend, drive the state machine to Closed. */
226 /* This should cause the backend to release our resources. */
227 if ((bus
== &xenbus_frontend
) && (state
== XenbusStateClosing
))
228 xenbus_frontend_closed(dev
);
232 if (drv
->otherend_changed
)
233 drv
->otherend_changed(dev
, state
);
237 static int talk_to_otherend(struct xenbus_device
*dev
)
239 struct xenbus_driver
*drv
= to_xenbus_driver(dev
->dev
.driver
);
241 free_otherend_watch(dev
);
242 free_otherend_details(dev
);
244 return drv
->read_otherend_details(dev
);
248 static int watch_otherend(struct xenbus_device
*dev
)
250 return xenbus_watch_pathfmt(dev
, &dev
->otherend_watch
, otherend_changed
,
251 "%s/%s", dev
->otherend
, "state");
255 int xenbus_dev_probe(struct device
*_dev
)
257 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
258 struct xenbus_driver
*drv
= to_xenbus_driver(_dev
->driver
);
259 const struct xenbus_device_id
*id
;
262 DPRINTK("%s", dev
->nodename
);
269 id
= match_device(drv
->ids
, dev
);
275 err
= talk_to_otherend(dev
);
277 dev_warn(&dev
->dev
, "talk_to_otherend on %s failed.\n",
282 err
= drv
->probe(dev
, id
);
286 err
= watch_otherend(dev
);
288 dev_warn(&dev
->dev
, "watch_otherend on %s failed.\n",
295 xenbus_dev_error(dev
, err
, "xenbus_dev_probe on %s", dev
->nodename
);
296 xenbus_switch_state(dev
, XenbusStateClosed
);
300 int xenbus_dev_remove(struct device
*_dev
)
302 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
303 struct xenbus_driver
*drv
= to_xenbus_driver(_dev
->driver
);
305 DPRINTK("%s", dev
->nodename
);
307 free_otherend_watch(dev
);
308 free_otherend_details(dev
);
313 xenbus_switch_state(dev
, XenbusStateClosed
);
317 static void xenbus_dev_shutdown(struct device
*_dev
)
319 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
320 unsigned long timeout
= 5*HZ
;
322 DPRINTK("%s", dev
->nodename
);
324 get_device(&dev
->dev
);
325 if (dev
->state
!= XenbusStateConnected
) {
326 printk(KERN_INFO
"%s: %s: %s != Connected, skipping\n", __func__
,
327 dev
->nodename
, xenbus_strstate(dev
->state
));
330 xenbus_switch_state(dev
, XenbusStateClosing
);
331 timeout
= wait_for_completion_timeout(&dev
->down
, timeout
);
333 printk(KERN_INFO
"%s: %s timeout closing device\n",
334 __func__
, dev
->nodename
);
336 put_device(&dev
->dev
);
339 int xenbus_register_driver_common(struct xenbus_driver
*drv
,
340 struct xen_bus_type
*bus
,
341 struct module
*owner
,
342 const char *mod_name
)
344 drv
->driver
.name
= drv
->name
;
345 drv
->driver
.bus
= &bus
->bus
;
346 drv
->driver
.owner
= owner
;
347 drv
->driver
.mod_name
= mod_name
;
349 return driver_register(&drv
->driver
);
352 int __xenbus_register_frontend(struct xenbus_driver
*drv
,
353 struct module
*owner
, const char *mod_name
)
357 drv
->read_otherend_details
= read_backend_details
;
359 ret
= xenbus_register_driver_common(drv
, &xenbus_frontend
,
364 /* If this driver is loaded as a module wait for devices to attach. */
365 wait_for_devices(drv
);
369 EXPORT_SYMBOL_GPL(__xenbus_register_frontend
);
371 void xenbus_unregister_driver(struct xenbus_driver
*drv
)
373 driver_unregister(&drv
->driver
);
375 EXPORT_SYMBOL_GPL(xenbus_unregister_driver
);
379 struct xenbus_device
*dev
;
380 const char *nodename
;
383 static int cmp_dev(struct device
*dev
, void *data
)
385 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
386 struct xb_find_info
*info
= data
;
388 if (!strcmp(xendev
->nodename
, info
->nodename
)) {
396 struct xenbus_device
*xenbus_device_find(const char *nodename
,
397 struct bus_type
*bus
)
399 struct xb_find_info info
= { .dev
= NULL
, .nodename
= nodename
};
401 bus_for_each_dev(bus
, NULL
, &info
, cmp_dev
);
405 static int cleanup_dev(struct device
*dev
, void *data
)
407 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
408 struct xb_find_info
*info
= data
;
409 int len
= strlen(info
->nodename
);
411 DPRINTK("%s", info
->nodename
);
413 /* Match the info->nodename path, or any subdirectory of that path. */
414 if (strncmp(xendev
->nodename
, info
->nodename
, len
))
417 /* If the node name is longer, ensure it really is a subdirectory. */
418 if ((strlen(xendev
->nodename
) > len
) && (xendev
->nodename
[len
] != '/'))
426 static void xenbus_cleanup_devices(const char *path
, struct bus_type
*bus
)
428 struct xb_find_info info
= { .nodename
= path
};
432 bus_for_each_dev(bus
, NULL
, &info
, cleanup_dev
);
434 device_unregister(&info
.dev
->dev
);
435 put_device(&info
.dev
->dev
);
440 static void xenbus_dev_release(struct device
*dev
)
443 kfree(to_xenbus_device(dev
));
446 static ssize_t
xendev_show_nodename(struct device
*dev
,
447 struct device_attribute
*attr
, char *buf
)
449 return sprintf(buf
, "%s\n", to_xenbus_device(dev
)->nodename
);
451 DEVICE_ATTR(nodename
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_nodename
, NULL
);
453 static ssize_t
xendev_show_devtype(struct device
*dev
,
454 struct device_attribute
*attr
, char *buf
)
456 return sprintf(buf
, "%s\n", to_xenbus_device(dev
)->devicetype
);
458 DEVICE_ATTR(devtype
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_devtype
, NULL
);
460 static ssize_t
xendev_show_modalias(struct device
*dev
,
461 struct device_attribute
*attr
, char *buf
)
463 return sprintf(buf
, "xen:%s\n", to_xenbus_device(dev
)->devicetype
);
465 DEVICE_ATTR(modalias
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_modalias
, NULL
);
467 int xenbus_probe_node(struct xen_bus_type
*bus
,
469 const char *nodename
)
471 char devname
[XEN_BUS_ID_SIZE
];
473 struct xenbus_device
*xendev
;
477 enum xenbus_state state
= xenbus_read_driver_state(nodename
);
479 if (state
!= XenbusStateInitialising
) {
480 /* Device is not new, so ignore it. This can happen if a
481 device is going away after switching to Closed. */
485 stringlen
= strlen(nodename
) + 1 + strlen(type
) + 1;
486 xendev
= kzalloc(sizeof(*xendev
) + stringlen
, GFP_KERNEL
);
490 xendev
->state
= XenbusStateInitialising
;
492 /* Copy the strings into the extra space. */
494 tmpstring
= (char *)(xendev
+ 1);
495 strcpy(tmpstring
, nodename
);
496 xendev
->nodename
= tmpstring
;
498 tmpstring
+= strlen(tmpstring
) + 1;
499 strcpy(tmpstring
, type
);
500 xendev
->devicetype
= tmpstring
;
501 init_completion(&xendev
->down
);
503 xendev
->dev
.bus
= &bus
->bus
;
504 xendev
->dev
.release
= xenbus_dev_release
;
506 err
= bus
->get_bus_id(devname
, xendev
->nodename
);
510 dev_set_name(&xendev
->dev
, devname
);
512 /* Register with generic device framework. */
513 err
= device_register(&xendev
->dev
);
517 err
= device_create_file(&xendev
->dev
, &dev_attr_nodename
);
519 goto fail_unregister
;
521 err
= device_create_file(&xendev
->dev
, &dev_attr_devtype
);
523 goto fail_remove_nodename
;
525 err
= device_create_file(&xendev
->dev
, &dev_attr_modalias
);
527 goto fail_remove_devtype
;
531 device_remove_file(&xendev
->dev
, &dev_attr_devtype
);
532 fail_remove_nodename
:
533 device_remove_file(&xendev
->dev
, &dev_attr_nodename
);
535 device_unregister(&xendev
->dev
);
541 /* device/<typename>/<name> */
542 static int xenbus_probe_frontend(const char *type
, const char *name
)
547 nodename
= kasprintf(GFP_KERNEL
, "%s/%s/%s",
548 xenbus_frontend
.root
, type
, name
);
552 DPRINTK("%s", nodename
);
554 err
= xenbus_probe_node(&xenbus_frontend
, type
, nodename
);
559 static int xenbus_probe_device_type(struct xen_bus_type
*bus
, const char *type
)
563 unsigned int dir_n
= 0;
566 dir
= xenbus_directory(XBT_NIL
, bus
->root
, type
, &dir_n
);
570 for (i
= 0; i
< dir_n
; i
++) {
571 err
= bus
->probe(type
, dir
[i
]);
579 int xenbus_probe_devices(struct xen_bus_type
*bus
)
583 unsigned int i
, dir_n
;
585 dir
= xenbus_directory(XBT_NIL
, bus
->root
, "", &dir_n
);
589 for (i
= 0; i
< dir_n
; i
++) {
590 err
= xenbus_probe_device_type(bus
, dir
[i
]);
598 static unsigned int char_count(const char *str
, char c
)
600 unsigned int i
, ret
= 0;
602 for (i
= 0; str
[i
]; i
++)
608 static int strsep_len(const char *str
, char c
, unsigned int len
)
612 for (i
= 0; str
[i
]; i
++)
618 return (len
== 0) ? i
: -ERANGE
;
621 void xenbus_dev_changed(const char *node
, struct xen_bus_type
*bus
)
624 struct xenbus_device
*dev
;
625 char type
[XEN_BUS_ID_SIZE
];
626 const char *p
, *root
;
628 if (char_count(node
, '/') < 2)
631 exists
= xenbus_exists(XBT_NIL
, node
, "");
633 xenbus_cleanup_devices(node
, &bus
->bus
);
637 /* backend/<type>/... or device/<type>/... */
638 p
= strchr(node
, '/') + 1;
639 snprintf(type
, XEN_BUS_ID_SIZE
, "%.*s", (int)strcspn(p
, "/"), p
);
640 type
[XEN_BUS_ID_SIZE
-1] = '\0';
642 rootlen
= strsep_len(node
, '/', bus
->levels
);
645 root
= kasprintf(GFP_KERNEL
, "%.*s", rootlen
, node
);
649 dev
= xenbus_device_find(root
, &bus
->bus
);
651 xenbus_probe_node(bus
, type
, root
);
653 put_device(&dev
->dev
);
658 static void frontend_changed(struct xenbus_watch
*watch
,
659 const char **vec
, unsigned int len
)
663 xenbus_dev_changed(vec
[XS_WATCH_PATH
], &xenbus_frontend
);
666 /* We watch for devices appearing and vanishing. */
667 static struct xenbus_watch fe_watch
= {
669 .callback
= frontend_changed
,
672 static int suspend_dev(struct device
*dev
, void *data
)
675 struct xenbus_driver
*drv
;
676 struct xenbus_device
*xdev
;
680 if (dev
->driver
== NULL
)
682 drv
= to_xenbus_driver(dev
->driver
);
683 xdev
= container_of(dev
, struct xenbus_device
, dev
);
685 err
= drv
->suspend(xdev
);
688 "xenbus: suspend %s failed: %i\n", dev_name(dev
), err
);
692 static int suspend_cancel_dev(struct device
*dev
, void *data
)
695 struct xenbus_driver
*drv
;
696 struct xenbus_device
*xdev
;
700 if (dev
->driver
== NULL
)
702 drv
= to_xenbus_driver(dev
->driver
);
703 xdev
= container_of(dev
, struct xenbus_device
, dev
);
704 if (drv
->suspend_cancel
)
705 err
= drv
->suspend_cancel(xdev
);
708 "xenbus: suspend_cancel %s failed: %i\n",
713 static int resume_dev(struct device
*dev
, void *data
)
716 struct xenbus_driver
*drv
;
717 struct xenbus_device
*xdev
;
721 if (dev
->driver
== NULL
)
724 drv
= to_xenbus_driver(dev
->driver
);
725 xdev
= container_of(dev
, struct xenbus_device
, dev
);
727 err
= talk_to_otherend(xdev
);
730 "xenbus: resume (talk_to_otherend) %s failed: %i\n",
735 xdev
->state
= XenbusStateInitialising
;
738 err
= drv
->resume(xdev
);
741 "xenbus: resume %s failed: %i\n",
747 err
= watch_otherend(xdev
);
750 "xenbus_probe: resume (watch_otherend) %s failed: "
751 "%d.\n", dev_name(dev
), err
);
758 void xenbus_suspend(void)
762 bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, NULL
, suspend_dev
);
763 xenbus_backend_suspend(suspend_dev
);
766 EXPORT_SYMBOL_GPL(xenbus_suspend
);
768 void xenbus_resume(void)
772 bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, NULL
, resume_dev
);
773 xenbus_backend_resume(resume_dev
);
775 EXPORT_SYMBOL_GPL(xenbus_resume
);
777 void xenbus_suspend_cancel(void)
780 bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, NULL
, suspend_cancel_dev
);
781 xenbus_backend_resume(suspend_cancel_dev
);
783 EXPORT_SYMBOL_GPL(xenbus_suspend_cancel
);
785 /* A flag to determine if xenstored is 'ready' (i.e. has started) */
786 int xenstored_ready
= 0;
789 int register_xenstore_notifier(struct notifier_block
*nb
)
793 if (xenstored_ready
> 0)
794 ret
= nb
->notifier_call(nb
, 0, NULL
);
796 blocking_notifier_chain_register(&xenstore_chain
, nb
);
800 EXPORT_SYMBOL_GPL(register_xenstore_notifier
);
802 void unregister_xenstore_notifier(struct notifier_block
*nb
)
804 blocking_notifier_chain_unregister(&xenstore_chain
, nb
);
806 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier
);
808 void xenbus_probe(struct work_struct
*unused
)
810 BUG_ON((xenstored_ready
<= 0));
812 /* Enumerate devices in xenstore and watch for changes. */
813 xenbus_probe_devices(&xenbus_frontend
);
814 register_xenbus_watch(&fe_watch
);
815 xenbus_backend_probe_and_watch();
817 /* Notify others that xenstore is up */
818 blocking_notifier_call_chain(&xenstore_chain
, 0, NULL
);
821 static int __init
xenbus_probe_init(void)
831 /* Register ourselves with the kernel bus subsystem */
832 err
= bus_register(&xenbus_frontend
.bus
);
836 err
= xenbus_backend_bus_register();
838 goto out_unreg_front
;
841 * Domain0 doesn't have a store_evtchn or store_mfn yet.
843 if (xen_initial_domain()) {
844 /* dom0 not yet supported */
847 xen_store_evtchn
= xen_start_info
->store_evtchn
;
848 xen_store_mfn
= xen_start_info
->store_mfn
;
850 xen_store_interface
= mfn_to_virt(xen_store_mfn
);
852 /* Initialize the interface to xenstore. */
856 "XENBUS: Error initializing xenstore comms: %i\n", err
);
860 if (!xen_initial_domain())
863 #ifdef CONFIG_XEN_COMPAT_XENFS
865 * Create xenfs mountpoint in /proc for compatibility with
866 * utilities that expect to find "xenbus" under "/proc/xen".
868 proc_mkdir("xen", NULL
);
874 xenbus_backend_bus_unregister();
877 bus_unregister(&xenbus_frontend
.bus
);
883 postcore_initcall(xenbus_probe_init
);
885 MODULE_LICENSE("GPL");
887 static int is_disconnected_device(struct device
*dev
, void *data
)
889 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
890 struct device_driver
*drv
= data
;
891 struct xenbus_driver
*xendrv
;
894 * A device with no driver will never connect. We care only about
895 * devices which should currently be in the process of connecting.
900 /* Is this search limited to a particular driver? */
901 if (drv
&& (dev
->driver
!= drv
))
904 xendrv
= to_xenbus_driver(dev
->driver
);
905 return (xendev
->state
!= XenbusStateConnected
||
906 (xendrv
->is_ready
&& !xendrv
->is_ready(xendev
)));
909 static int exists_disconnected_device(struct device_driver
*drv
)
911 return bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, drv
,
912 is_disconnected_device
);
915 static int print_device_status(struct device
*dev
, void *data
)
917 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
918 struct device_driver
*drv
= data
;
920 /* Is this operation limited to a particular driver? */
921 if (drv
&& (dev
->driver
!= drv
))
925 /* Information only: is this too noisy? */
926 printk(KERN_INFO
"XENBUS: Device with no driver: %s\n",
928 } else if (xendev
->state
!= XenbusStateConnected
) {
929 printk(KERN_WARNING
"XENBUS: Timeout connecting "
930 "to device: %s (state %d)\n",
931 xendev
->nodename
, xendev
->state
);
937 /* We only wait for device setup after most initcalls have run. */
938 static int ready_to_wait_for_devices
;
941 * On a 10 second timeout, wait for all devices currently configured. We need
942 * to do this to guarantee that the filesystems and / or network devices
943 * needed for boot are available, before we can allow the boot to proceed.
945 * This needs to be on a late_initcall, to happen after the frontend device
946 * drivers have been initialised, but before the root fs is mounted.
948 * A possible improvement here would be to have the tools add a per-device
949 * flag to the store entry, indicating whether it is needed at boot time.
950 * This would allow people who knew what they were doing to accelerate their
951 * boot slightly, but of course needs tools or manual intervention to set up
952 * those flags correctly.
954 static void wait_for_devices(struct xenbus_driver
*xendrv
)
956 unsigned long timeout
= jiffies
+ 10*HZ
;
957 struct device_driver
*drv
= xendrv
? &xendrv
->driver
: NULL
;
959 if (!ready_to_wait_for_devices
|| !xen_domain())
962 while (exists_disconnected_device(drv
)) {
963 if (time_after(jiffies
, timeout
))
965 schedule_timeout_interruptible(HZ
/10);
968 bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, drv
,
969 print_device_status
);
973 static int __init
boot_wait_for_devices(void)
975 ready_to_wait_for_devices
= 1;
976 wait_for_devices(NULL
);
980 late_initcall(boot_wait_for_devices
);