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>
48 #include <linux/slab.h>
51 #include <asm/pgtable.h>
52 #include <asm/xen/hypervisor.h>
55 #include <xen/xenbus.h>
56 #include <xen/events.h>
59 #include "xenbus_comms.h"
60 #include "xenbus_probe.h"
64 EXPORT_SYMBOL(xen_store_evtchn
);
66 struct xenstore_domain_interface
*xen_store_interface
;
67 static unsigned long xen_store_mfn
;
69 static BLOCKING_NOTIFIER_HEAD(xenstore_chain
);
71 static void wait_for_devices(struct xenbus_driver
*xendrv
);
73 static int xenbus_probe_frontend(const char *type
, const char *name
);
75 static void xenbus_dev_shutdown(struct device
*_dev
);
77 static int xenbus_dev_suspend(struct device
*dev
, pm_message_t state
);
78 static int xenbus_dev_resume(struct device
*dev
);
80 /* If something in array of ids matches this device, return it. */
81 static const struct xenbus_device_id
*
82 match_device(const struct xenbus_device_id
*arr
, struct xenbus_device
*dev
)
84 for (; *arr
->devicetype
!= '\0'; arr
++) {
85 if (!strcmp(arr
->devicetype
, dev
->devicetype
))
91 int xenbus_match(struct device
*_dev
, struct device_driver
*_drv
)
93 struct xenbus_driver
*drv
= to_xenbus_driver(_drv
);
98 return match_device(drv
->ids
, to_xenbus_device(_dev
)) != NULL
;
101 static int xenbus_uevent(struct device
*_dev
, struct kobj_uevent_env
*env
)
103 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
105 if (add_uevent_var(env
, "MODALIAS=xen:%s", dev
->devicetype
))
111 /* device/<type>/<id> => <type>-<id> */
112 static int frontend_bus_id(char bus_id
[XEN_BUS_ID_SIZE
], const char *nodename
)
114 nodename
= strchr(nodename
, '/');
115 if (!nodename
|| strlen(nodename
+ 1) >= XEN_BUS_ID_SIZE
) {
116 printk(KERN_WARNING
"XENBUS: bad frontend %s\n", nodename
);
120 strlcpy(bus_id
, nodename
+ 1, XEN_BUS_ID_SIZE
);
121 if (!strchr(bus_id
, '/')) {
122 printk(KERN_WARNING
"XENBUS: bus_id %s no slash\n", bus_id
);
125 *strchr(bus_id
, '/') = '-';
130 static void free_otherend_details(struct xenbus_device
*dev
)
132 kfree(dev
->otherend
);
133 dev
->otherend
= NULL
;
137 static void free_otherend_watch(struct xenbus_device
*dev
)
139 if (dev
->otherend_watch
.node
) {
140 unregister_xenbus_watch(&dev
->otherend_watch
);
141 kfree(dev
->otherend_watch
.node
);
142 dev
->otherend_watch
.node
= NULL
;
147 int read_otherend_details(struct xenbus_device
*xendev
,
148 char *id_node
, char *path_node
)
150 int err
= xenbus_gather(XBT_NIL
, xendev
->nodename
,
151 id_node
, "%i", &xendev
->otherend_id
,
152 path_node
, NULL
, &xendev
->otherend
,
155 xenbus_dev_fatal(xendev
, err
,
156 "reading other end details from %s",
160 if (strlen(xendev
->otherend
) == 0 ||
161 !xenbus_exists(XBT_NIL
, xendev
->otherend
, "")) {
162 xenbus_dev_fatal(xendev
, -ENOENT
,
163 "unable to read other end from %s. "
164 "missing or inaccessible.",
166 free_otherend_details(xendev
);
174 static int read_backend_details(struct xenbus_device
*xendev
)
176 return read_otherend_details(xendev
, "backend-id", "backend");
179 static struct device_attribute xenbus_dev_attrs
[] = {
183 /* Bus type for frontend drivers. */
184 static struct xen_bus_type xenbus_frontend
= {
186 .levels
= 2, /* device/type/<id> */
187 .get_bus_id
= frontend_bus_id
,
188 .probe
= xenbus_probe_frontend
,
191 .match
= xenbus_match
,
192 .uevent
= xenbus_uevent
,
193 .probe
= xenbus_dev_probe
,
194 .remove
= xenbus_dev_remove
,
195 .shutdown
= xenbus_dev_shutdown
,
196 .dev_attrs
= xenbus_dev_attrs
,
198 .suspend
= xenbus_dev_suspend
,
199 .resume
= xenbus_dev_resume
,
203 static void otherend_changed(struct xenbus_watch
*watch
,
204 const char **vec
, unsigned int len
)
206 struct xenbus_device
*dev
=
207 container_of(watch
, struct xenbus_device
, otherend_watch
);
208 struct xenbus_driver
*drv
= to_xenbus_driver(dev
->dev
.driver
);
209 enum xenbus_state state
;
211 /* Protect us against watches firing on old details when the otherend
212 details change, say immediately after a resume. */
213 if (!dev
->otherend
||
214 strncmp(dev
->otherend
, vec
[XS_WATCH_PATH
],
215 strlen(dev
->otherend
))) {
216 dev_dbg(&dev
->dev
, "Ignoring watch at %s\n",
221 state
= xenbus_read_driver_state(dev
->otherend
);
223 dev_dbg(&dev
->dev
, "state is %d, (%s), %s, %s\n",
224 state
, xenbus_strstate(state
), dev
->otherend_watch
.node
,
228 * Ignore xenbus transitions during shutdown. This prevents us doing
229 * work that can fail e.g., when the rootfs is gone.
231 if (system_state
> SYSTEM_RUNNING
) {
232 struct xen_bus_type
*bus
= bus
;
233 bus
= container_of(dev
->dev
.bus
, struct xen_bus_type
, bus
);
234 /* If we're frontend, drive the state machine to Closed. */
235 /* This should cause the backend to release our resources. */
236 if ((bus
== &xenbus_frontend
) && (state
== XenbusStateClosing
))
237 xenbus_frontend_closed(dev
);
241 if (drv
->otherend_changed
)
242 drv
->otherend_changed(dev
, state
);
246 static int talk_to_otherend(struct xenbus_device
*dev
)
248 struct xenbus_driver
*drv
= to_xenbus_driver(dev
->dev
.driver
);
250 free_otherend_watch(dev
);
251 free_otherend_details(dev
);
253 return drv
->read_otherend_details(dev
);
257 static int watch_otherend(struct xenbus_device
*dev
)
259 return xenbus_watch_pathfmt(dev
, &dev
->otherend_watch
, otherend_changed
,
260 "%s/%s", dev
->otherend
, "state");
264 int xenbus_dev_probe(struct device
*_dev
)
266 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
267 struct xenbus_driver
*drv
= to_xenbus_driver(_dev
->driver
);
268 const struct xenbus_device_id
*id
;
271 DPRINTK("%s", dev
->nodename
);
278 id
= match_device(drv
->ids
, dev
);
284 err
= talk_to_otherend(dev
);
286 dev_warn(&dev
->dev
, "talk_to_otherend on %s failed.\n",
291 err
= drv
->probe(dev
, id
);
295 err
= watch_otherend(dev
);
297 dev_warn(&dev
->dev
, "watch_otherend on %s failed.\n",
304 xenbus_dev_error(dev
, err
, "xenbus_dev_probe on %s", dev
->nodename
);
305 xenbus_switch_state(dev
, XenbusStateClosed
);
309 int xenbus_dev_remove(struct device
*_dev
)
311 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
312 struct xenbus_driver
*drv
= to_xenbus_driver(_dev
->driver
);
314 DPRINTK("%s", dev
->nodename
);
316 free_otherend_watch(dev
);
317 free_otherend_details(dev
);
322 xenbus_switch_state(dev
, XenbusStateClosed
);
326 static void xenbus_dev_shutdown(struct device
*_dev
)
328 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
329 unsigned long timeout
= 5*HZ
;
331 DPRINTK("%s", dev
->nodename
);
333 get_device(&dev
->dev
);
334 if (dev
->state
!= XenbusStateConnected
) {
335 printk(KERN_INFO
"%s: %s: %s != Connected, skipping\n", __func__
,
336 dev
->nodename
, xenbus_strstate(dev
->state
));
339 xenbus_switch_state(dev
, XenbusStateClosing
);
340 timeout
= wait_for_completion_timeout(&dev
->down
, timeout
);
342 printk(KERN_INFO
"%s: %s timeout closing device\n",
343 __func__
, dev
->nodename
);
345 put_device(&dev
->dev
);
348 int xenbus_register_driver_common(struct xenbus_driver
*drv
,
349 struct xen_bus_type
*bus
,
350 struct module
*owner
,
351 const char *mod_name
)
353 drv
->driver
.name
= drv
->name
;
354 drv
->driver
.bus
= &bus
->bus
;
355 drv
->driver
.owner
= owner
;
356 drv
->driver
.mod_name
= mod_name
;
358 return driver_register(&drv
->driver
);
361 int __xenbus_register_frontend(struct xenbus_driver
*drv
,
362 struct module
*owner
, const char *mod_name
)
366 drv
->read_otherend_details
= read_backend_details
;
368 ret
= xenbus_register_driver_common(drv
, &xenbus_frontend
,
373 /* If this driver is loaded as a module wait for devices to attach. */
374 wait_for_devices(drv
);
378 EXPORT_SYMBOL_GPL(__xenbus_register_frontend
);
380 void xenbus_unregister_driver(struct xenbus_driver
*drv
)
382 driver_unregister(&drv
->driver
);
384 EXPORT_SYMBOL_GPL(xenbus_unregister_driver
);
388 struct xenbus_device
*dev
;
389 const char *nodename
;
392 static int cmp_dev(struct device
*dev
, void *data
)
394 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
395 struct xb_find_info
*info
= data
;
397 if (!strcmp(xendev
->nodename
, info
->nodename
)) {
405 struct xenbus_device
*xenbus_device_find(const char *nodename
,
406 struct bus_type
*bus
)
408 struct xb_find_info info
= { .dev
= NULL
, .nodename
= nodename
};
410 bus_for_each_dev(bus
, NULL
, &info
, cmp_dev
);
414 static int cleanup_dev(struct device
*dev
, void *data
)
416 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
417 struct xb_find_info
*info
= data
;
418 int len
= strlen(info
->nodename
);
420 DPRINTK("%s", info
->nodename
);
422 /* Match the info->nodename path, or any subdirectory of that path. */
423 if (strncmp(xendev
->nodename
, info
->nodename
, len
))
426 /* If the node name is longer, ensure it really is a subdirectory. */
427 if ((strlen(xendev
->nodename
) > len
) && (xendev
->nodename
[len
] != '/'))
435 static void xenbus_cleanup_devices(const char *path
, struct bus_type
*bus
)
437 struct xb_find_info info
= { .nodename
= path
};
441 bus_for_each_dev(bus
, NULL
, &info
, cleanup_dev
);
443 device_unregister(&info
.dev
->dev
);
444 put_device(&info
.dev
->dev
);
449 static void xenbus_dev_release(struct device
*dev
)
452 kfree(to_xenbus_device(dev
));
455 static ssize_t
xendev_show_nodename(struct device
*dev
,
456 struct device_attribute
*attr
, char *buf
)
458 return sprintf(buf
, "%s\n", to_xenbus_device(dev
)->nodename
);
460 static DEVICE_ATTR(nodename
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_nodename
, NULL
);
462 static ssize_t
xendev_show_devtype(struct device
*dev
,
463 struct device_attribute
*attr
, char *buf
)
465 return sprintf(buf
, "%s\n", to_xenbus_device(dev
)->devicetype
);
467 static DEVICE_ATTR(devtype
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_devtype
, NULL
);
469 static ssize_t
xendev_show_modalias(struct device
*dev
,
470 struct device_attribute
*attr
, char *buf
)
472 return sprintf(buf
, "xen:%s\n", to_xenbus_device(dev
)->devicetype
);
474 static DEVICE_ATTR(modalias
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_modalias
, NULL
);
476 int xenbus_probe_node(struct xen_bus_type
*bus
,
478 const char *nodename
)
480 char devname
[XEN_BUS_ID_SIZE
];
482 struct xenbus_device
*xendev
;
486 enum xenbus_state state
= xenbus_read_driver_state(nodename
);
488 if (state
!= XenbusStateInitialising
) {
489 /* Device is not new, so ignore it. This can happen if a
490 device is going away after switching to Closed. */
494 stringlen
= strlen(nodename
) + 1 + strlen(type
) + 1;
495 xendev
= kzalloc(sizeof(*xendev
) + stringlen
, GFP_KERNEL
);
499 xendev
->state
= XenbusStateInitialising
;
501 /* Copy the strings into the extra space. */
503 tmpstring
= (char *)(xendev
+ 1);
504 strcpy(tmpstring
, nodename
);
505 xendev
->nodename
= tmpstring
;
507 tmpstring
+= strlen(tmpstring
) + 1;
508 strcpy(tmpstring
, type
);
509 xendev
->devicetype
= tmpstring
;
510 init_completion(&xendev
->down
);
512 xendev
->dev
.bus
= &bus
->bus
;
513 xendev
->dev
.release
= xenbus_dev_release
;
515 err
= bus
->get_bus_id(devname
, xendev
->nodename
);
519 dev_set_name(&xendev
->dev
, devname
);
521 /* Register with generic device framework. */
522 err
= device_register(&xendev
->dev
);
526 err
= device_create_file(&xendev
->dev
, &dev_attr_nodename
);
528 goto fail_unregister
;
530 err
= device_create_file(&xendev
->dev
, &dev_attr_devtype
);
532 goto fail_remove_nodename
;
534 err
= device_create_file(&xendev
->dev
, &dev_attr_modalias
);
536 goto fail_remove_devtype
;
540 device_remove_file(&xendev
->dev
, &dev_attr_devtype
);
541 fail_remove_nodename
:
542 device_remove_file(&xendev
->dev
, &dev_attr_nodename
);
544 device_unregister(&xendev
->dev
);
550 /* device/<typename>/<name> */
551 static int xenbus_probe_frontend(const char *type
, const char *name
)
556 nodename
= kasprintf(GFP_KERNEL
, "%s/%s/%s",
557 xenbus_frontend
.root
, type
, name
);
561 DPRINTK("%s", nodename
);
563 err
= xenbus_probe_node(&xenbus_frontend
, type
, nodename
);
568 static int xenbus_probe_device_type(struct xen_bus_type
*bus
, const char *type
)
572 unsigned int dir_n
= 0;
575 dir
= xenbus_directory(XBT_NIL
, bus
->root
, type
, &dir_n
);
579 for (i
= 0; i
< dir_n
; i
++) {
580 err
= bus
->probe(type
, dir
[i
]);
588 int xenbus_probe_devices(struct xen_bus_type
*bus
)
592 unsigned int i
, dir_n
;
594 dir
= xenbus_directory(XBT_NIL
, bus
->root
, "", &dir_n
);
598 for (i
= 0; i
< dir_n
; i
++) {
599 err
= xenbus_probe_device_type(bus
, dir
[i
]);
607 static unsigned int char_count(const char *str
, char c
)
609 unsigned int i
, ret
= 0;
611 for (i
= 0; str
[i
]; i
++)
617 static int strsep_len(const char *str
, char c
, unsigned int len
)
621 for (i
= 0; str
[i
]; i
++)
627 return (len
== 0) ? i
: -ERANGE
;
630 void xenbus_dev_changed(const char *node
, struct xen_bus_type
*bus
)
633 struct xenbus_device
*dev
;
634 char type
[XEN_BUS_ID_SIZE
];
635 const char *p
, *root
;
637 if (char_count(node
, '/') < 2)
640 exists
= xenbus_exists(XBT_NIL
, node
, "");
642 xenbus_cleanup_devices(node
, &bus
->bus
);
646 /* backend/<type>/... or device/<type>/... */
647 p
= strchr(node
, '/') + 1;
648 snprintf(type
, XEN_BUS_ID_SIZE
, "%.*s", (int)strcspn(p
, "/"), p
);
649 type
[XEN_BUS_ID_SIZE
-1] = '\0';
651 rootlen
= strsep_len(node
, '/', bus
->levels
);
654 root
= kasprintf(GFP_KERNEL
, "%.*s", rootlen
, node
);
658 dev
= xenbus_device_find(root
, &bus
->bus
);
660 xenbus_probe_node(bus
, type
, root
);
662 put_device(&dev
->dev
);
666 EXPORT_SYMBOL_GPL(xenbus_dev_changed
);
668 static void frontend_changed(struct xenbus_watch
*watch
,
669 const char **vec
, unsigned int len
)
673 xenbus_dev_changed(vec
[XS_WATCH_PATH
], &xenbus_frontend
);
676 /* We watch for devices appearing and vanishing. */
677 static struct xenbus_watch fe_watch
= {
679 .callback
= frontend_changed
,
682 static int xenbus_dev_suspend(struct device
*dev
, pm_message_t state
)
685 struct xenbus_driver
*drv
;
686 struct xenbus_device
*xdev
;
690 if (dev
->driver
== NULL
)
692 drv
= to_xenbus_driver(dev
->driver
);
693 xdev
= container_of(dev
, struct xenbus_device
, dev
);
695 err
= drv
->suspend(xdev
, state
);
698 "xenbus: suspend %s failed: %i\n", dev_name(dev
), err
);
702 static int xenbus_dev_resume(struct device
*dev
)
705 struct xenbus_driver
*drv
;
706 struct xenbus_device
*xdev
;
710 if (dev
->driver
== NULL
)
713 drv
= to_xenbus_driver(dev
->driver
);
714 xdev
= container_of(dev
, struct xenbus_device
, dev
);
716 err
= talk_to_otherend(xdev
);
719 "xenbus: resume (talk_to_otherend) %s failed: %i\n",
724 xdev
->state
= XenbusStateInitialising
;
727 err
= drv
->resume(xdev
);
730 "xenbus: resume %s failed: %i\n",
736 err
= watch_otherend(xdev
);
739 "xenbus_probe: resume (watch_otherend) %s failed: "
740 "%d.\n", dev_name(dev
), err
);
747 /* A flag to determine if xenstored is 'ready' (i.e. has started) */
748 int xenstored_ready
= 0;
751 int register_xenstore_notifier(struct notifier_block
*nb
)
755 if (xenstored_ready
> 0)
756 ret
= nb
->notifier_call(nb
, 0, NULL
);
758 blocking_notifier_chain_register(&xenstore_chain
, nb
);
762 EXPORT_SYMBOL_GPL(register_xenstore_notifier
);
764 void unregister_xenstore_notifier(struct notifier_block
*nb
)
766 blocking_notifier_chain_unregister(&xenstore_chain
, nb
);
768 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier
);
770 void xenbus_probe(struct work_struct
*unused
)
772 BUG_ON((xenstored_ready
<= 0));
774 /* Enumerate devices in xenstore and watch for changes. */
775 xenbus_probe_devices(&xenbus_frontend
);
776 register_xenbus_watch(&fe_watch
);
777 xenbus_backend_probe_and_watch();
779 /* Notify others that xenstore is up */
780 blocking_notifier_call_chain(&xenstore_chain
, 0, NULL
);
783 static int __init
xenbus_probe_init(void)
793 /* Register ourselves with the kernel bus subsystem */
794 err
= bus_register(&xenbus_frontend
.bus
);
798 err
= xenbus_backend_bus_register();
800 goto out_unreg_front
;
803 * Domain0 doesn't have a store_evtchn or store_mfn yet.
805 if (xen_initial_domain()) {
806 /* dom0 not yet supported */
809 xen_store_evtchn
= xen_start_info
->store_evtchn
;
810 xen_store_mfn
= xen_start_info
->store_mfn
;
812 xen_store_interface
= mfn_to_virt(xen_store_mfn
);
814 /* Initialize the interface to xenstore. */
818 "XENBUS: Error initializing xenstore comms: %i\n", err
);
822 if (!xen_initial_domain())
825 #ifdef CONFIG_XEN_COMPAT_XENFS
827 * Create xenfs mountpoint in /proc for compatibility with
828 * utilities that expect to find "xenbus" under "/proc/xen".
830 proc_mkdir("xen", NULL
);
836 xenbus_backend_bus_unregister();
839 bus_unregister(&xenbus_frontend
.bus
);
845 postcore_initcall(xenbus_probe_init
);
847 MODULE_LICENSE("GPL");
849 static int is_device_connecting(struct device
*dev
, void *data
)
851 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
852 struct device_driver
*drv
= data
;
853 struct xenbus_driver
*xendrv
;
856 * A device with no driver will never connect. We care only about
857 * devices which should currently be in the process of connecting.
862 /* Is this search limited to a particular driver? */
863 if (drv
&& (dev
->driver
!= drv
))
866 xendrv
= to_xenbus_driver(dev
->driver
);
867 return (xendev
->state
< XenbusStateConnected
||
868 (xendev
->state
== XenbusStateConnected
&&
869 xendrv
->is_ready
&& !xendrv
->is_ready(xendev
)));
872 static int exists_connecting_device(struct device_driver
*drv
)
874 return bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, drv
,
875 is_device_connecting
);
878 static int print_device_status(struct device
*dev
, void *data
)
880 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
881 struct device_driver
*drv
= data
;
883 /* Is this operation limited to a particular driver? */
884 if (drv
&& (dev
->driver
!= drv
))
888 /* Information only: is this too noisy? */
889 printk(KERN_INFO
"XENBUS: Device with no driver: %s\n",
891 } else if (xendev
->state
< XenbusStateConnected
) {
892 enum xenbus_state rstate
= XenbusStateUnknown
;
893 if (xendev
->otherend
)
894 rstate
= xenbus_read_driver_state(xendev
->otherend
);
895 printk(KERN_WARNING
"XENBUS: Timeout connecting "
896 "to device: %s (local state %d, remote state %d)\n",
897 xendev
->nodename
, xendev
->state
, rstate
);
903 /* We only wait for device setup after most initcalls have run. */
904 static int ready_to_wait_for_devices
;
907 * On a 5-minute timeout, wait for all devices currently configured. We need
908 * to do this to guarantee that the filesystems and / or network devices
909 * needed for boot are available, before we can allow the boot to proceed.
911 * This needs to be on a late_initcall, to happen after the frontend device
912 * drivers have been initialised, but before the root fs is mounted.
914 * A possible improvement here would be to have the tools add a per-device
915 * flag to the store entry, indicating whether it is needed at boot time.
916 * This would allow people who knew what they were doing to accelerate their
917 * boot slightly, but of course needs tools or manual intervention to set up
918 * those flags correctly.
920 static void wait_for_devices(struct xenbus_driver
*xendrv
)
922 unsigned long start
= jiffies
;
923 struct device_driver
*drv
= xendrv
? &xendrv
->driver
: NULL
;
924 unsigned int seconds_waited
= 0;
926 if (!ready_to_wait_for_devices
|| !xen_domain())
929 while (exists_connecting_device(drv
)) {
930 if (time_after(jiffies
, start
+ (seconds_waited
+5)*HZ
)) {
932 printk(KERN_WARNING
"XENBUS: Waiting for "
933 "devices to initialise: ");
935 printk("%us...", 300 - seconds_waited
);
936 if (seconds_waited
== 300)
940 schedule_timeout_interruptible(HZ
/10);
946 bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, drv
,
947 print_device_status
);
951 static int __init
boot_wait_for_devices(void)
953 ready_to_wait_for_devices
= 1;
954 wait_for_devices(NULL
);
958 late_initcall(boot_wait_for_devices
);