diff options
Diffstat (limited to 'drivers/xen/xenbus/xenbus_probe.c')
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe.c | 394 |
1 files changed, 95 insertions, 299 deletions
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index d409495876f1..739769551e33 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c | |||
@@ -56,7 +56,6 @@ | |||
56 | #include <xen/events.h> | 56 | #include <xen/events.h> |
57 | #include <xen/page.h> | 57 | #include <xen/page.h> |
58 | 58 | ||
59 | #include <xen/platform_pci.h> | ||
60 | #include <xen/hvm.h> | 59 | #include <xen/hvm.h> |
61 | 60 | ||
62 | #include "xenbus_comms.h" | 61 | #include "xenbus_comms.h" |
@@ -64,22 +63,15 @@ | |||
64 | 63 | ||
65 | 64 | ||
66 | int xen_store_evtchn; | 65 | int xen_store_evtchn; |
67 | EXPORT_SYMBOL(xen_store_evtchn); | 66 | EXPORT_SYMBOL_GPL(xen_store_evtchn); |
68 | 67 | ||
69 | struct xenstore_domain_interface *xen_store_interface; | 68 | struct xenstore_domain_interface *xen_store_interface; |
69 | EXPORT_SYMBOL_GPL(xen_store_interface); | ||
70 | |||
70 | static unsigned long xen_store_mfn; | 71 | static unsigned long xen_store_mfn; |
71 | 72 | ||
72 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); | 73 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); |
73 | 74 | ||
74 | static void wait_for_devices(struct xenbus_driver *xendrv); | ||
75 | |||
76 | static int xenbus_probe_frontend(const char *type, const char *name); | ||
77 | |||
78 | static void xenbus_dev_shutdown(struct device *_dev); | ||
79 | |||
80 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state); | ||
81 | static int xenbus_dev_resume(struct device *dev); | ||
82 | |||
83 | /* If something in array of ids matches this device, return it. */ | 75 | /* If something in array of ids matches this device, return it. */ |
84 | static const struct xenbus_device_id * | 76 | static const struct xenbus_device_id * |
85 | match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) | 77 | match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) |
@@ -100,34 +92,7 @@ int xenbus_match(struct device *_dev, struct device_driver *_drv) | |||
100 | 92 | ||
101 | return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; | 93 | return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; |
102 | } | 94 | } |
103 | 95 | EXPORT_SYMBOL_GPL(xenbus_match); | |
104 | static int xenbus_uevent(struct device *_dev, struct kobj_uevent_env *env) | ||
105 | { | ||
106 | struct xenbus_device *dev = to_xenbus_device(_dev); | ||
107 | |||
108 | if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype)) | ||
109 | return -ENOMEM; | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | /* device/<type>/<id> => <type>-<id> */ | ||
115 | static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) | ||
116 | { | ||
117 | nodename = strchr(nodename, '/'); | ||
118 | if (!nodename || strlen(nodename + 1) >= XEN_BUS_ID_SIZE) { | ||
119 | printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename); | ||
120 | return -EINVAL; | ||
121 | } | ||
122 | |||
123 | strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE); | ||
124 | if (!strchr(bus_id, '/')) { | ||
125 | printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id); | ||
126 | return -EINVAL; | ||
127 | } | ||
128 | *strchr(bus_id, '/') = '-'; | ||
129 | return 0; | ||
130 | } | ||
131 | 96 | ||
132 | 97 | ||
133 | static void free_otherend_details(struct xenbus_device *dev) | 98 | static void free_otherend_details(struct xenbus_device *dev) |
@@ -147,7 +112,30 @@ static void free_otherend_watch(struct xenbus_device *dev) | |||
147 | } | 112 | } |
148 | 113 | ||
149 | 114 | ||
150 | int read_otherend_details(struct xenbus_device *xendev, | 115 | static int talk_to_otherend(struct xenbus_device *dev) |
116 | { | ||
117 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); | ||
118 | |||
119 | free_otherend_watch(dev); | ||
120 | free_otherend_details(dev); | ||
121 | |||
122 | return drv->read_otherend_details(dev); | ||
123 | } | ||
124 | |||
125 | |||
126 | |||
127 | static int watch_otherend(struct xenbus_device *dev) | ||
128 | { | ||
129 | struct xen_bus_type *bus = | ||
130 | container_of(dev->dev.bus, struct xen_bus_type, bus); | ||
131 | |||
132 | return xenbus_watch_pathfmt(dev, &dev->otherend_watch, | ||
133 | bus->otherend_changed, | ||
134 | "%s/%s", dev->otherend, "state"); | ||
135 | } | ||
136 | |||
137 | |||
138 | int xenbus_read_otherend_details(struct xenbus_device *xendev, | ||
151 | char *id_node, char *path_node) | 139 | char *id_node, char *path_node) |
152 | { | 140 | { |
153 | int err = xenbus_gather(XBT_NIL, xendev->nodename, | 141 | int err = xenbus_gather(XBT_NIL, xendev->nodename, |
@@ -172,39 +160,11 @@ int read_otherend_details(struct xenbus_device *xendev, | |||
172 | 160 | ||
173 | return 0; | 161 | return 0; |
174 | } | 162 | } |
163 | EXPORT_SYMBOL_GPL(xenbus_read_otherend_details); | ||
175 | 164 | ||
176 | 165 | void xenbus_otherend_changed(struct xenbus_watch *watch, | |
177 | static int read_backend_details(struct xenbus_device *xendev) | 166 | const char **vec, unsigned int len, |
178 | { | 167 | int ignore_on_shutdown) |
179 | return read_otherend_details(xendev, "backend-id", "backend"); | ||
180 | } | ||
181 | |||
182 | static struct device_attribute xenbus_dev_attrs[] = { | ||
183 | __ATTR_NULL | ||
184 | }; | ||
185 | |||
186 | /* Bus type for frontend drivers. */ | ||
187 | static struct xen_bus_type xenbus_frontend = { | ||
188 | .root = "device", | ||
189 | .levels = 2, /* device/type/<id> */ | ||
190 | .get_bus_id = frontend_bus_id, | ||
191 | .probe = xenbus_probe_frontend, | ||
192 | .bus = { | ||
193 | .name = "xen", | ||
194 | .match = xenbus_match, | ||
195 | .uevent = xenbus_uevent, | ||
196 | .probe = xenbus_dev_probe, | ||
197 | .remove = xenbus_dev_remove, | ||
198 | .shutdown = xenbus_dev_shutdown, | ||
199 | .dev_attrs = xenbus_dev_attrs, | ||
200 | |||
201 | .suspend = xenbus_dev_suspend, | ||
202 | .resume = xenbus_dev_resume, | ||
203 | }, | ||
204 | }; | ||
205 | |||
206 | static void otherend_changed(struct xenbus_watch *watch, | ||
207 | const char **vec, unsigned int len) | ||
208 | { | 168 | { |
209 | struct xenbus_device *dev = | 169 | struct xenbus_device *dev = |
210 | container_of(watch, struct xenbus_device, otherend_watch); | 170 | container_of(watch, struct xenbus_device, otherend_watch); |
@@ -232,11 +192,7 @@ static void otherend_changed(struct xenbus_watch *watch, | |||
232 | * work that can fail e.g., when the rootfs is gone. | 192 | * work that can fail e.g., when the rootfs is gone. |
233 | */ | 193 | */ |
234 | if (system_state > SYSTEM_RUNNING) { | 194 | if (system_state > SYSTEM_RUNNING) { |
235 | struct xen_bus_type *bus = bus; | 195 | if (ignore_on_shutdown && (state == XenbusStateClosing)) |
236 | bus = container_of(dev->dev.bus, struct xen_bus_type, bus); | ||
237 | /* If we're frontend, drive the state machine to Closed. */ | ||
238 | /* This should cause the backend to release our resources. */ | ||
239 | if ((bus == &xenbus_frontend) && (state == XenbusStateClosing)) | ||
240 | xenbus_frontend_closed(dev); | 196 | xenbus_frontend_closed(dev); |
241 | return; | 197 | return; |
242 | } | 198 | } |
@@ -244,25 +200,7 @@ static void otherend_changed(struct xenbus_watch *watch, | |||
244 | if (drv->otherend_changed) | 200 | if (drv->otherend_changed) |
245 | drv->otherend_changed(dev, state); | 201 | drv->otherend_changed(dev, state); |
246 | } | 202 | } |
247 | 203 | EXPORT_SYMBOL_GPL(xenbus_otherend_changed); | |
248 | |||
249 | static int talk_to_otherend(struct xenbus_device *dev) | ||
250 | { | ||
251 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); | ||
252 | |||
253 | free_otherend_watch(dev); | ||
254 | free_otherend_details(dev); | ||
255 | |||
256 | return drv->read_otherend_details(dev); | ||
257 | } | ||
258 | |||
259 | |||
260 | static int watch_otherend(struct xenbus_device *dev) | ||
261 | { | ||
262 | return xenbus_watch_pathfmt(dev, &dev->otherend_watch, otherend_changed, | ||
263 | "%s/%s", dev->otherend, "state"); | ||
264 | } | ||
265 | |||
266 | 204 | ||
267 | int xenbus_dev_probe(struct device *_dev) | 205 | int xenbus_dev_probe(struct device *_dev) |
268 | { | 206 | { |
@@ -306,8 +244,9 @@ int xenbus_dev_probe(struct device *_dev) | |||
306 | fail: | 244 | fail: |
307 | xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); | 245 | xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); |
308 | xenbus_switch_state(dev, XenbusStateClosed); | 246 | xenbus_switch_state(dev, XenbusStateClosed); |
309 | return -ENODEV; | 247 | return err; |
310 | } | 248 | } |
249 | EXPORT_SYMBOL_GPL(xenbus_dev_probe); | ||
311 | 250 | ||
312 | int xenbus_dev_remove(struct device *_dev) | 251 | int xenbus_dev_remove(struct device *_dev) |
313 | { | 252 | { |
@@ -325,8 +264,9 @@ int xenbus_dev_remove(struct device *_dev) | |||
325 | xenbus_switch_state(dev, XenbusStateClosed); | 264 | xenbus_switch_state(dev, XenbusStateClosed); |
326 | return 0; | 265 | return 0; |
327 | } | 266 | } |
267 | EXPORT_SYMBOL_GPL(xenbus_dev_remove); | ||
328 | 268 | ||
329 | static void xenbus_dev_shutdown(struct device *_dev) | 269 | void xenbus_dev_shutdown(struct device *_dev) |
330 | { | 270 | { |
331 | struct xenbus_device *dev = to_xenbus_device(_dev); | 271 | struct xenbus_device *dev = to_xenbus_device(_dev); |
332 | unsigned long timeout = 5*HZ; | 272 | unsigned long timeout = 5*HZ; |
@@ -347,6 +287,7 @@ static void xenbus_dev_shutdown(struct device *_dev) | |||
347 | out: | 287 | out: |
348 | put_device(&dev->dev); | 288 | put_device(&dev->dev); |
349 | } | 289 | } |
290 | EXPORT_SYMBOL_GPL(xenbus_dev_shutdown); | ||
350 | 291 | ||
351 | int xenbus_register_driver_common(struct xenbus_driver *drv, | 292 | int xenbus_register_driver_common(struct xenbus_driver *drv, |
352 | struct xen_bus_type *bus, | 293 | struct xen_bus_type *bus, |
@@ -360,25 +301,7 @@ int xenbus_register_driver_common(struct xenbus_driver *drv, | |||
360 | 301 | ||
361 | return driver_register(&drv->driver); | 302 | return driver_register(&drv->driver); |
362 | } | 303 | } |
363 | 304 | EXPORT_SYMBOL_GPL(xenbus_register_driver_common); | |
364 | int __xenbus_register_frontend(struct xenbus_driver *drv, | ||
365 | struct module *owner, const char *mod_name) | ||
366 | { | ||
367 | int ret; | ||
368 | |||
369 | drv->read_otherend_details = read_backend_details; | ||
370 | |||
371 | ret = xenbus_register_driver_common(drv, &xenbus_frontend, | ||
372 | owner, mod_name); | ||
373 | if (ret) | ||
374 | return ret; | ||
375 | |||
376 | /* If this driver is loaded as a module wait for devices to attach. */ | ||
377 | wait_for_devices(drv); | ||
378 | |||
379 | return 0; | ||
380 | } | ||
381 | EXPORT_SYMBOL_GPL(__xenbus_register_frontend); | ||
382 | 305 | ||
383 | void xenbus_unregister_driver(struct xenbus_driver *drv) | 306 | void xenbus_unregister_driver(struct xenbus_driver *drv) |
384 | { | 307 | { |
@@ -549,24 +472,7 @@ fail: | |||
549 | kfree(xendev); | 472 | kfree(xendev); |
550 | return err; | 473 | return err; |
551 | } | 474 | } |
552 | 475 | EXPORT_SYMBOL_GPL(xenbus_probe_node); | |
553 | /* device/<typename>/<name> */ | ||
554 | static int xenbus_probe_frontend(const char *type, const char *name) | ||
555 | { | ||
556 | char *nodename; | ||
557 | int err; | ||
558 | |||
559 | nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", | ||
560 | xenbus_frontend.root, type, name); | ||
561 | if (!nodename) | ||
562 | return -ENOMEM; | ||
563 | |||
564 | DPRINTK("%s", nodename); | ||
565 | |||
566 | err = xenbus_probe_node(&xenbus_frontend, type, nodename); | ||
567 | kfree(nodename); | ||
568 | return err; | ||
569 | } | ||
570 | 476 | ||
571 | static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) | 477 | static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) |
572 | { | 478 | { |
@@ -580,10 +486,11 @@ static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) | |||
580 | return PTR_ERR(dir); | 486 | return PTR_ERR(dir); |
581 | 487 | ||
582 | for (i = 0; i < dir_n; i++) { | 488 | for (i = 0; i < dir_n; i++) { |
583 | err = bus->probe(type, dir[i]); | 489 | err = bus->probe(bus, type, dir[i]); |
584 | if (err) | 490 | if (err) |
585 | break; | 491 | break; |
586 | } | 492 | } |
493 | |||
587 | kfree(dir); | 494 | kfree(dir); |
588 | return err; | 495 | return err; |
589 | } | 496 | } |
@@ -603,9 +510,11 @@ int xenbus_probe_devices(struct xen_bus_type *bus) | |||
603 | if (err) | 510 | if (err) |
604 | break; | 511 | break; |
605 | } | 512 | } |
513 | |||
606 | kfree(dir); | 514 | kfree(dir); |
607 | return err; | 515 | return err; |
608 | } | 516 | } |
517 | EXPORT_SYMBOL_GPL(xenbus_probe_devices); | ||
609 | 518 | ||
610 | static unsigned int char_count(const char *str, char c) | 519 | static unsigned int char_count(const char *str, char c) |
611 | { | 520 | { |
@@ -668,54 +577,39 @@ void xenbus_dev_changed(const char *node, struct xen_bus_type *bus) | |||
668 | } | 577 | } |
669 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); | 578 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); |
670 | 579 | ||
671 | static void frontend_changed(struct xenbus_watch *watch, | 580 | int xenbus_dev_suspend(struct device *dev) |
672 | const char **vec, unsigned int len) | ||
673 | { | ||
674 | DPRINTK(""); | ||
675 | |||
676 | xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend); | ||
677 | } | ||
678 | |||
679 | /* We watch for devices appearing and vanishing. */ | ||
680 | static struct xenbus_watch fe_watch = { | ||
681 | .node = "device", | ||
682 | .callback = frontend_changed, | ||
683 | }; | ||
684 | |||
685 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state) | ||
686 | { | 581 | { |
687 | int err = 0; | 582 | int err = 0; |
688 | struct xenbus_driver *drv; | 583 | struct xenbus_driver *drv; |
689 | struct xenbus_device *xdev; | 584 | struct xenbus_device *xdev |
585 | = container_of(dev, struct xenbus_device, dev); | ||
690 | 586 | ||
691 | DPRINTK(""); | 587 | DPRINTK("%s", xdev->nodename); |
692 | 588 | ||
693 | if (dev->driver == NULL) | 589 | if (dev->driver == NULL) |
694 | return 0; | 590 | return 0; |
695 | drv = to_xenbus_driver(dev->driver); | 591 | drv = to_xenbus_driver(dev->driver); |
696 | xdev = container_of(dev, struct xenbus_device, dev); | ||
697 | if (drv->suspend) | 592 | if (drv->suspend) |
698 | err = drv->suspend(xdev, state); | 593 | err = drv->suspend(xdev); |
699 | if (err) | 594 | if (err) |
700 | printk(KERN_WARNING | 595 | printk(KERN_WARNING |
701 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); | 596 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); |
702 | return 0; | 597 | return 0; |
703 | } | 598 | } |
599 | EXPORT_SYMBOL_GPL(xenbus_dev_suspend); | ||
704 | 600 | ||
705 | static int xenbus_dev_resume(struct device *dev) | 601 | int xenbus_dev_resume(struct device *dev) |
706 | { | 602 | { |
707 | int err; | 603 | int err; |
708 | struct xenbus_driver *drv; | 604 | struct xenbus_driver *drv; |
709 | struct xenbus_device *xdev; | 605 | struct xenbus_device *xdev |
606 | = container_of(dev, struct xenbus_device, dev); | ||
710 | 607 | ||
711 | DPRINTK(""); | 608 | DPRINTK("%s", xdev->nodename); |
712 | 609 | ||
713 | if (dev->driver == NULL) | 610 | if (dev->driver == NULL) |
714 | return 0; | 611 | return 0; |
715 | |||
716 | drv = to_xenbus_driver(dev->driver); | 612 | drv = to_xenbus_driver(dev->driver); |
717 | xdev = container_of(dev, struct xenbus_device, dev); | ||
718 | |||
719 | err = talk_to_otherend(xdev); | 613 | err = talk_to_otherend(xdev); |
720 | if (err) { | 614 | if (err) { |
721 | printk(KERN_WARNING | 615 | printk(KERN_WARNING |
@@ -746,6 +640,15 @@ static int xenbus_dev_resume(struct device *dev) | |||
746 | 640 | ||
747 | return 0; | 641 | return 0; |
748 | } | 642 | } |
643 | EXPORT_SYMBOL_GPL(xenbus_dev_resume); | ||
644 | |||
645 | int xenbus_dev_cancel(struct device *dev) | ||
646 | { | ||
647 | /* Do nothing */ | ||
648 | DPRINTK("cancel"); | ||
649 | return 0; | ||
650 | } | ||
651 | EXPORT_SYMBOL_GPL(xenbus_dev_cancel); | ||
749 | 652 | ||
750 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ | 653 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ |
751 | int xenstored_ready = 0; | 654 | int xenstored_ready = 0; |
@@ -774,11 +677,6 @@ void xenbus_probe(struct work_struct *unused) | |||
774 | { | 677 | { |
775 | xenstored_ready = 1; | 678 | xenstored_ready = 1; |
776 | 679 | ||
777 | /* Enumerate devices in xenstore and watch for changes. */ | ||
778 | xenbus_probe_devices(&xenbus_frontend); | ||
779 | register_xenbus_watch(&fe_watch); | ||
780 | xenbus_backend_probe_and_watch(); | ||
781 | |||
782 | /* Notify others that xenstore is up */ | 680 | /* Notify others that xenstore is up */ |
783 | blocking_notifier_call_chain(&xenstore_chain, 0, NULL); | 681 | blocking_notifier_call_chain(&xenstore_chain, 0, NULL); |
784 | } | 682 | } |
@@ -801,27 +699,43 @@ device_initcall(xenbus_probe_initcall); | |||
801 | static int __init xenbus_init(void) | 699 | static int __init xenbus_init(void) |
802 | { | 700 | { |
803 | int err = 0; | 701 | int err = 0; |
702 | unsigned long page = 0; | ||
804 | 703 | ||
805 | DPRINTK(""); | 704 | DPRINTK(""); |
806 | 705 | ||
807 | err = -ENODEV; | 706 | err = -ENODEV; |
808 | if (!xen_domain()) | 707 | if (!xen_domain()) |
809 | goto out_error; | 708 | return err; |
810 | |||
811 | /* Register ourselves with the kernel bus subsystem */ | ||
812 | err = bus_register(&xenbus_frontend.bus); | ||
813 | if (err) | ||
814 | goto out_error; | ||
815 | |||
816 | err = xenbus_backend_bus_register(); | ||
817 | if (err) | ||
818 | goto out_unreg_front; | ||
819 | 709 | ||
820 | /* | 710 | /* |
821 | * Domain0 doesn't have a store_evtchn or store_mfn yet. | 711 | * Domain0 doesn't have a store_evtchn or store_mfn yet. |
822 | */ | 712 | */ |
823 | if (xen_initial_domain()) { | 713 | if (xen_initial_domain()) { |
824 | /* dom0 not yet supported */ | 714 | struct evtchn_alloc_unbound alloc_unbound; |
715 | |||
716 | /* Allocate Xenstore page */ | ||
717 | page = get_zeroed_page(GFP_KERNEL); | ||
718 | if (!page) | ||
719 | goto out_error; | ||
720 | |||
721 | xen_store_mfn = xen_start_info->store_mfn = | ||
722 | pfn_to_mfn(virt_to_phys((void *)page) >> | ||
723 | PAGE_SHIFT); | ||
724 | |||
725 | /* Next allocate a local port which xenstored can bind to */ | ||
726 | alloc_unbound.dom = DOMID_SELF; | ||
727 | alloc_unbound.remote_dom = 0; | ||
728 | |||
729 | err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, | ||
730 | &alloc_unbound); | ||
731 | if (err == -ENOSYS) | ||
732 | goto out_error; | ||
733 | |||
734 | BUG_ON(err); | ||
735 | xen_store_evtchn = xen_start_info->store_evtchn = | ||
736 | alloc_unbound.port; | ||
737 | |||
738 | xen_store_interface = mfn_to_virt(xen_store_mfn); | ||
825 | } else { | 739 | } else { |
826 | if (xen_hvm_domain()) { | 740 | if (xen_hvm_domain()) { |
827 | uint64_t v = 0; | 741 | uint64_t v = 0; |
@@ -847,7 +761,7 @@ static int __init xenbus_init(void) | |||
847 | if (err) { | 761 | if (err) { |
848 | printk(KERN_WARNING | 762 | printk(KERN_WARNING |
849 | "XENBUS: Error initializing xenstore comms: %i\n", err); | 763 | "XENBUS: Error initializing xenstore comms: %i\n", err); |
850 | goto out_unreg_back; | 764 | goto out_error; |
851 | } | 765 | } |
852 | 766 | ||
853 | #ifdef CONFIG_XEN_COMPAT_XENFS | 767 | #ifdef CONFIG_XEN_COMPAT_XENFS |
@@ -860,131 +774,13 @@ static int __init xenbus_init(void) | |||
860 | 774 | ||
861 | return 0; | 775 | return 0; |
862 | 776 | ||
863 | out_unreg_back: | ||
864 | xenbus_backend_bus_unregister(); | ||
865 | |||
866 | out_unreg_front: | ||
867 | bus_unregister(&xenbus_frontend.bus); | ||
868 | |||
869 | out_error: | 777 | out_error: |
778 | if (page != 0) | ||
779 | free_page(page); | ||
780 | |||
870 | return err; | 781 | return err; |
871 | } | 782 | } |
872 | 783 | ||
873 | postcore_initcall(xenbus_init); | 784 | postcore_initcall(xenbus_init); |
874 | 785 | ||
875 | MODULE_LICENSE("GPL"); | 786 | MODULE_LICENSE("GPL"); |
876 | |||
877 | static int is_device_connecting(struct device *dev, void *data) | ||
878 | { | ||
879 | struct xenbus_device *xendev = to_xenbus_device(dev); | ||
880 | struct device_driver *drv = data; | ||
881 | struct xenbus_driver *xendrv; | ||
882 | |||
883 | /* | ||
884 | * A device with no driver will never connect. We care only about | ||
885 | * devices which should currently be in the process of connecting. | ||
886 | */ | ||
887 | if (!dev->driver) | ||
888 | return 0; | ||
889 | |||
890 | /* Is this search limited to a particular driver? */ | ||
891 | if (drv && (dev->driver != drv)) | ||
892 | return 0; | ||
893 | |||
894 | xendrv = to_xenbus_driver(dev->driver); | ||
895 | return (xendev->state < XenbusStateConnected || | ||
896 | (xendev->state == XenbusStateConnected && | ||
897 | xendrv->is_ready && !xendrv->is_ready(xendev))); | ||
898 | } | ||
899 | |||
900 | static int exists_connecting_device(struct device_driver *drv) | ||
901 | { | ||
902 | return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, | ||
903 | is_device_connecting); | ||
904 | } | ||
905 | |||
906 | static int print_device_status(struct device *dev, void *data) | ||
907 | { | ||
908 | struct xenbus_device *xendev = to_xenbus_device(dev); | ||
909 | struct device_driver *drv = data; | ||
910 | |||
911 | /* Is this operation limited to a particular driver? */ | ||
912 | if (drv && (dev->driver != drv)) | ||
913 | return 0; | ||
914 | |||
915 | if (!dev->driver) { | ||
916 | /* Information only: is this too noisy? */ | ||
917 | printk(KERN_INFO "XENBUS: Device with no driver: %s\n", | ||
918 | xendev->nodename); | ||
919 | } else if (xendev->state < XenbusStateConnected) { | ||
920 | enum xenbus_state rstate = XenbusStateUnknown; | ||
921 | if (xendev->otherend) | ||
922 | rstate = xenbus_read_driver_state(xendev->otherend); | ||
923 | printk(KERN_WARNING "XENBUS: Timeout connecting " | ||
924 | "to device: %s (local state %d, remote state %d)\n", | ||
925 | xendev->nodename, xendev->state, rstate); | ||
926 | } | ||
927 | |||
928 | return 0; | ||
929 | } | ||
930 | |||
931 | /* We only wait for device setup after most initcalls have run. */ | ||
932 | static int ready_to_wait_for_devices; | ||
933 | |||
934 | /* | ||
935 | * On a 5-minute timeout, wait for all devices currently configured. We need | ||
936 | * to do this to guarantee that the filesystems and / or network devices | ||
937 | * needed for boot are available, before we can allow the boot to proceed. | ||
938 | * | ||
939 | * This needs to be on a late_initcall, to happen after the frontend device | ||
940 | * drivers have been initialised, but before the root fs is mounted. | ||
941 | * | ||
942 | * A possible improvement here would be to have the tools add a per-device | ||
943 | * flag to the store entry, indicating whether it is needed at boot time. | ||
944 | * This would allow people who knew what they were doing to accelerate their | ||
945 | * boot slightly, but of course needs tools or manual intervention to set up | ||
946 | * those flags correctly. | ||
947 | */ | ||
948 | static void wait_for_devices(struct xenbus_driver *xendrv) | ||
949 | { | ||
950 | unsigned long start = jiffies; | ||
951 | struct device_driver *drv = xendrv ? &xendrv->driver : NULL; | ||
952 | unsigned int seconds_waited = 0; | ||
953 | |||
954 | if (!ready_to_wait_for_devices || !xen_domain()) | ||
955 | return; | ||
956 | |||
957 | while (exists_connecting_device(drv)) { | ||
958 | if (time_after(jiffies, start + (seconds_waited+5)*HZ)) { | ||
959 | if (!seconds_waited) | ||
960 | printk(KERN_WARNING "XENBUS: Waiting for " | ||
961 | "devices to initialise: "); | ||
962 | seconds_waited += 5; | ||
963 | printk("%us...", 300 - seconds_waited); | ||
964 | if (seconds_waited == 300) | ||
965 | break; | ||
966 | } | ||
967 | |||
968 | schedule_timeout_interruptible(HZ/10); | ||
969 | } | ||
970 | |||
971 | if (seconds_waited) | ||
972 | printk("\n"); | ||
973 | |||
974 | bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, | ||
975 | print_device_status); | ||
976 | } | ||
977 | |||
978 | #ifndef MODULE | ||
979 | static int __init boot_wait_for_devices(void) | ||
980 | { | ||
981 | if (xen_hvm_domain() && !xen_platform_pci_unplug) | ||
982 | return -ENODEV; | ||
983 | |||
984 | ready_to_wait_for_devices = 1; | ||
985 | wait_for_devices(NULL); | ||
986 | return 0; | ||
987 | } | ||
988 | |||
989 | late_initcall(boot_wait_for_devices); | ||
990 | #endif | ||