diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-12 11:37:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-12 11:37:35 -0500 |
commit | 94d4c4cd563aeff4d498168f1c8444074160d0e7 (patch) | |
tree | f12b08ef94db4f8510f0bdd97ca89e196ae310e9 /drivers/xen | |
parent | 2818ef50c4dc103ce52e12d14ce2dfbde5268120 (diff) | |
parent | 329620a878cf89184b28500d37fa33cc870a3357 (diff) |
Merge branch 'stable/xenbus' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen
* 'stable/xenbus' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen:
xen/xenbus: making backend support modular is too complex
xen/pci: Make xen-pcifront be dependent on XEN_XENBUS_FRONTEND
xen/xenbus: fixup checkpatch issues in xenbus_probe*
xen/netfront: select XEN_XENBUS_FRONTEND
xen/xenbus: clean up noise in xenbus_probe_frontend.c
xen/xenbus: clean up noise in xenbus_probe_backend.c
xen/xenbus: clean up noise in xenbus_probe.c
xen/xenbus: cleanup debug noise in xenbus_comms.c
xen/xenbus: clean up error handling
xen/xenbus: make frontend bus GPL
xen/xenbus: make sure backend bus is registered earlier
xenbus/frontend: register bus earlier
xen: remove xen/evtchn.h
xen: add backend driver support
xen: separate out frontend xenbus
Diffstat (limited to 'drivers/xen')
-rw-r--r-- | drivers/xen/Kconfig | 11 | ||||
-rw-r--r-- | drivers/xen/xenbus/Makefile | 5 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe.c | 351 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe.h | 31 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe_backend.c | 276 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe_frontend.c | 294 |
6 files changed, 657 insertions, 311 deletions
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index 6e6180ccd726..5a48ce996dea 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig | |||
@@ -29,6 +29,14 @@ config XEN_DEV_EVTCHN | |||
29 | firing. | 29 | firing. |
30 | If in doubt, say yes. | 30 | If in doubt, say yes. |
31 | 31 | ||
32 | config XEN_BACKEND | ||
33 | bool "Backend driver support" | ||
34 | depends on XEN_DOM0 | ||
35 | default y | ||
36 | help | ||
37 | Support for backend device drivers that provide I/O services | ||
38 | to other virtual machines. | ||
39 | |||
32 | config XENFS | 40 | config XENFS |
33 | tristate "Xen filesystem" | 41 | tristate "Xen filesystem" |
34 | default y | 42 | default y |
@@ -62,6 +70,9 @@ config XEN_SYS_HYPERVISOR | |||
62 | virtual environment, /sys/hypervisor will still be present, | 70 | virtual environment, /sys/hypervisor will still be present, |
63 | but will have no xen contents. | 71 | but will have no xen contents. |
64 | 72 | ||
73 | config XEN_XENBUS_FRONTEND | ||
74 | tristate | ||
75 | |||
65 | config XEN_PLATFORM_PCI | 76 | config XEN_PLATFORM_PCI |
66 | tristate "xen platform pci device driver" | 77 | tristate "xen platform pci device driver" |
67 | depends on XEN_PVHVM | 78 | depends on XEN_PVHVM |
diff --git a/drivers/xen/xenbus/Makefile b/drivers/xen/xenbus/Makefile index 5571f5b84223..8dca685358b4 100644 --- a/drivers/xen/xenbus/Makefile +++ b/drivers/xen/xenbus/Makefile | |||
@@ -5,3 +5,8 @@ xenbus-objs += xenbus_client.o | |||
5 | xenbus-objs += xenbus_comms.o | 5 | xenbus-objs += xenbus_comms.o |
6 | xenbus-objs += xenbus_xs.o | 6 | xenbus-objs += xenbus_xs.o |
7 | xenbus-objs += xenbus_probe.o | 7 | xenbus-objs += xenbus_probe.o |
8 | |||
9 | xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o | ||
10 | xenbus-objs += $(xenbus-be-objs-y) | ||
11 | |||
12 | obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o | ||
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index deb9c4ba3a93..baa65e7fbbc7 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" |
@@ -73,15 +72,6 @@ static unsigned long xen_store_mfn; | |||
73 | 72 | ||
74 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); | 73 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); |
75 | 74 | ||
76 | static void wait_for_devices(struct xenbus_driver *xendrv); | ||
77 | |||
78 | static int xenbus_probe_frontend(const char *type, const char *name); | ||
79 | |||
80 | static void xenbus_dev_shutdown(struct device *_dev); | ||
81 | |||
82 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state); | ||
83 | static int xenbus_dev_resume(struct device *dev); | ||
84 | |||
85 | /* If something in array of ids matches this device, return it. */ | 75 | /* If something in array of ids matches this device, return it. */ |
86 | static const struct xenbus_device_id * | 76 | static const struct xenbus_device_id * |
87 | 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) |
@@ -102,34 +92,7 @@ int xenbus_match(struct device *_dev, struct device_driver *_drv) | |||
102 | 92 | ||
103 | return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; | 93 | return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; |
104 | } | 94 | } |
105 | 95 | EXPORT_SYMBOL_GPL(xenbus_match); | |
106 | static int xenbus_uevent(struct device *_dev, struct kobj_uevent_env *env) | ||
107 | { | ||
108 | struct xenbus_device *dev = to_xenbus_device(_dev); | ||
109 | |||
110 | if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype)) | ||
111 | return -ENOMEM; | ||
112 | |||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | /* device/<type>/<id> => <type>-<id> */ | ||
117 | static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) | ||
118 | { | ||
119 | nodename = strchr(nodename, '/'); | ||
120 | if (!nodename || strlen(nodename + 1) >= XEN_BUS_ID_SIZE) { | ||
121 | printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename); | ||
122 | return -EINVAL; | ||
123 | } | ||
124 | |||
125 | strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE); | ||
126 | if (!strchr(bus_id, '/')) { | ||
127 | printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id); | ||
128 | return -EINVAL; | ||
129 | } | ||
130 | *strchr(bus_id, '/') = '-'; | ||
131 | return 0; | ||
132 | } | ||
133 | 96 | ||
134 | 97 | ||
135 | static void free_otherend_details(struct xenbus_device *dev) | 98 | static void free_otherend_details(struct xenbus_device *dev) |
@@ -149,7 +112,30 @@ static void free_otherend_watch(struct xenbus_device *dev) | |||
149 | } | 112 | } |
150 | 113 | ||
151 | 114 | ||
152 | 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, | ||
153 | char *id_node, char *path_node) | 139 | char *id_node, char *path_node) |
154 | { | 140 | { |
155 | int err = xenbus_gather(XBT_NIL, xendev->nodename, | 141 | int err = xenbus_gather(XBT_NIL, xendev->nodename, |
@@ -174,39 +160,11 @@ int read_otherend_details(struct xenbus_device *xendev, | |||
174 | 160 | ||
175 | return 0; | 161 | return 0; |
176 | } | 162 | } |
163 | EXPORT_SYMBOL_GPL(xenbus_read_otherend_details); | ||
177 | 164 | ||
178 | 165 | void xenbus_otherend_changed(struct xenbus_watch *watch, | |
179 | static int read_backend_details(struct xenbus_device *xendev) | 166 | const char **vec, unsigned int len, |
180 | { | 167 | int ignore_on_shutdown) |
181 | return read_otherend_details(xendev, "backend-id", "backend"); | ||
182 | } | ||
183 | |||
184 | static struct device_attribute xenbus_dev_attrs[] = { | ||
185 | __ATTR_NULL | ||
186 | }; | ||
187 | |||
188 | /* Bus type for frontend drivers. */ | ||
189 | static struct xen_bus_type xenbus_frontend = { | ||
190 | .root = "device", | ||
191 | .levels = 2, /* device/type/<id> */ | ||
192 | .get_bus_id = frontend_bus_id, | ||
193 | .probe = xenbus_probe_frontend, | ||
194 | .bus = { | ||
195 | .name = "xen", | ||
196 | .match = xenbus_match, | ||
197 | .uevent = xenbus_uevent, | ||
198 | .probe = xenbus_dev_probe, | ||
199 | .remove = xenbus_dev_remove, | ||
200 | .shutdown = xenbus_dev_shutdown, | ||
201 | .dev_attrs = xenbus_dev_attrs, | ||
202 | |||
203 | .suspend = xenbus_dev_suspend, | ||
204 | .resume = xenbus_dev_resume, | ||
205 | }, | ||
206 | }; | ||
207 | |||
208 | static void otherend_changed(struct xenbus_watch *watch, | ||
209 | const char **vec, unsigned int len) | ||
210 | { | 168 | { |
211 | struct xenbus_device *dev = | 169 | struct xenbus_device *dev = |
212 | container_of(watch, struct xenbus_device, otherend_watch); | 170 | container_of(watch, struct xenbus_device, otherend_watch); |
@@ -234,11 +192,7 @@ static void otherend_changed(struct xenbus_watch *watch, | |||
234 | * work that can fail e.g., when the rootfs is gone. | 192 | * work that can fail e.g., when the rootfs is gone. |
235 | */ | 193 | */ |
236 | if (system_state > SYSTEM_RUNNING) { | 194 | if (system_state > SYSTEM_RUNNING) { |
237 | struct xen_bus_type *bus = bus; | 195 | if (ignore_on_shutdown && (state == XenbusStateClosing)) |
238 | bus = container_of(dev->dev.bus, struct xen_bus_type, bus); | ||
239 | /* If we're frontend, drive the state machine to Closed. */ | ||
240 | /* This should cause the backend to release our resources. */ | ||
241 | if ((bus == &xenbus_frontend) && (state == XenbusStateClosing)) | ||
242 | xenbus_frontend_closed(dev); | 196 | xenbus_frontend_closed(dev); |
243 | return; | 197 | return; |
244 | } | 198 | } |
@@ -246,25 +200,7 @@ static void otherend_changed(struct xenbus_watch *watch, | |||
246 | if (drv->otherend_changed) | 200 | if (drv->otherend_changed) |
247 | drv->otherend_changed(dev, state); | 201 | drv->otherend_changed(dev, state); |
248 | } | 202 | } |
249 | 203 | EXPORT_SYMBOL_GPL(xenbus_otherend_changed); | |
250 | |||
251 | static int talk_to_otherend(struct xenbus_device *dev) | ||
252 | { | ||
253 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); | ||
254 | |||
255 | free_otherend_watch(dev); | ||
256 | free_otherend_details(dev); | ||
257 | |||
258 | return drv->read_otherend_details(dev); | ||
259 | } | ||
260 | |||
261 | |||
262 | static int watch_otherend(struct xenbus_device *dev) | ||
263 | { | ||
264 | return xenbus_watch_pathfmt(dev, &dev->otherend_watch, otherend_changed, | ||
265 | "%s/%s", dev->otherend, "state"); | ||
266 | } | ||
267 | |||
268 | 204 | ||
269 | int xenbus_dev_probe(struct device *_dev) | 205 | int xenbus_dev_probe(struct device *_dev) |
270 | { | 206 | { |
@@ -308,8 +244,9 @@ int xenbus_dev_probe(struct device *_dev) | |||
308 | fail: | 244 | fail: |
309 | 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); |
310 | xenbus_switch_state(dev, XenbusStateClosed); | 246 | xenbus_switch_state(dev, XenbusStateClosed); |
311 | return -ENODEV; | 247 | return err; |
312 | } | 248 | } |
249 | EXPORT_SYMBOL_GPL(xenbus_dev_probe); | ||
313 | 250 | ||
314 | int xenbus_dev_remove(struct device *_dev) | 251 | int xenbus_dev_remove(struct device *_dev) |
315 | { | 252 | { |
@@ -327,8 +264,9 @@ int xenbus_dev_remove(struct device *_dev) | |||
327 | xenbus_switch_state(dev, XenbusStateClosed); | 264 | xenbus_switch_state(dev, XenbusStateClosed); |
328 | return 0; | 265 | return 0; |
329 | } | 266 | } |
267 | EXPORT_SYMBOL_GPL(xenbus_dev_remove); | ||
330 | 268 | ||
331 | static void xenbus_dev_shutdown(struct device *_dev) | 269 | void xenbus_dev_shutdown(struct device *_dev) |
332 | { | 270 | { |
333 | struct xenbus_device *dev = to_xenbus_device(_dev); | 271 | struct xenbus_device *dev = to_xenbus_device(_dev); |
334 | unsigned long timeout = 5*HZ; | 272 | unsigned long timeout = 5*HZ; |
@@ -349,6 +287,7 @@ static void xenbus_dev_shutdown(struct device *_dev) | |||
349 | out: | 287 | out: |
350 | put_device(&dev->dev); | 288 | put_device(&dev->dev); |
351 | } | 289 | } |
290 | EXPORT_SYMBOL_GPL(xenbus_dev_shutdown); | ||
352 | 291 | ||
353 | int xenbus_register_driver_common(struct xenbus_driver *drv, | 292 | int xenbus_register_driver_common(struct xenbus_driver *drv, |
354 | struct xen_bus_type *bus, | 293 | struct xen_bus_type *bus, |
@@ -362,25 +301,7 @@ int xenbus_register_driver_common(struct xenbus_driver *drv, | |||
362 | 301 | ||
363 | return driver_register(&drv->driver); | 302 | return driver_register(&drv->driver); |
364 | } | 303 | } |
365 | 304 | EXPORT_SYMBOL_GPL(xenbus_register_driver_common); | |
366 | int __xenbus_register_frontend(struct xenbus_driver *drv, | ||
367 | struct module *owner, const char *mod_name) | ||
368 | { | ||
369 | int ret; | ||
370 | |||
371 | drv->read_otherend_details = read_backend_details; | ||
372 | |||
373 | ret = xenbus_register_driver_common(drv, &xenbus_frontend, | ||
374 | owner, mod_name); | ||
375 | if (ret) | ||
376 | return ret; | ||
377 | |||
378 | /* If this driver is loaded as a module wait for devices to attach. */ | ||
379 | wait_for_devices(drv); | ||
380 | |||
381 | return 0; | ||
382 | } | ||
383 | EXPORT_SYMBOL_GPL(__xenbus_register_frontend); | ||
384 | 305 | ||
385 | void xenbus_unregister_driver(struct xenbus_driver *drv) | 306 | void xenbus_unregister_driver(struct xenbus_driver *drv) |
386 | { | 307 | { |
@@ -551,24 +472,7 @@ fail: | |||
551 | kfree(xendev); | 472 | kfree(xendev); |
552 | return err; | 473 | return err; |
553 | } | 474 | } |
554 | 475 | EXPORT_SYMBOL_GPL(xenbus_probe_node); | |
555 | /* device/<typename>/<name> */ | ||
556 | static int xenbus_probe_frontend(const char *type, const char *name) | ||
557 | { | ||
558 | char *nodename; | ||
559 | int err; | ||
560 | |||
561 | nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", | ||
562 | xenbus_frontend.root, type, name); | ||
563 | if (!nodename) | ||
564 | return -ENOMEM; | ||
565 | |||
566 | DPRINTK("%s", nodename); | ||
567 | |||
568 | err = xenbus_probe_node(&xenbus_frontend, type, nodename); | ||
569 | kfree(nodename); | ||
570 | return err; | ||
571 | } | ||
572 | 476 | ||
573 | 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) |
574 | { | 478 | { |
@@ -582,10 +486,11 @@ static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) | |||
582 | return PTR_ERR(dir); | 486 | return PTR_ERR(dir); |
583 | 487 | ||
584 | for (i = 0; i < dir_n; i++) { | 488 | for (i = 0; i < dir_n; i++) { |
585 | err = bus->probe(type, dir[i]); | 489 | err = bus->probe(bus, type, dir[i]); |
586 | if (err) | 490 | if (err) |
587 | break; | 491 | break; |
588 | } | 492 | } |
493 | |||
589 | kfree(dir); | 494 | kfree(dir); |
590 | return err; | 495 | return err; |
591 | } | 496 | } |
@@ -605,9 +510,11 @@ int xenbus_probe_devices(struct xen_bus_type *bus) | |||
605 | if (err) | 510 | if (err) |
606 | break; | 511 | break; |
607 | } | 512 | } |
513 | |||
608 | kfree(dir); | 514 | kfree(dir); |
609 | return err; | 515 | return err; |
610 | } | 516 | } |
517 | EXPORT_SYMBOL_GPL(xenbus_probe_devices); | ||
611 | 518 | ||
612 | static unsigned int char_count(const char *str, char c) | 519 | static unsigned int char_count(const char *str, char c) |
613 | { | 520 | { |
@@ -670,32 +577,18 @@ void xenbus_dev_changed(const char *node, struct xen_bus_type *bus) | |||
670 | } | 577 | } |
671 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); | 578 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); |
672 | 579 | ||
673 | static void frontend_changed(struct xenbus_watch *watch, | 580 | int xenbus_dev_suspend(struct device *dev, pm_message_t state) |
674 | const char **vec, unsigned int len) | ||
675 | { | ||
676 | DPRINTK(""); | ||
677 | |||
678 | xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend); | ||
679 | } | ||
680 | |||
681 | /* We watch for devices appearing and vanishing. */ | ||
682 | static struct xenbus_watch fe_watch = { | ||
683 | .node = "device", | ||
684 | .callback = frontend_changed, | ||
685 | }; | ||
686 | |||
687 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state) | ||
688 | { | 581 | { |
689 | int err = 0; | 582 | int err = 0; |
690 | struct xenbus_driver *drv; | 583 | struct xenbus_driver *drv; |
691 | struct xenbus_device *xdev; | 584 | struct xenbus_device *xdev |
585 | = container_of(dev, struct xenbus_device, dev); | ||
692 | 586 | ||
693 | DPRINTK(""); | 587 | DPRINTK("%s", xdev->nodename); |
694 | 588 | ||
695 | if (dev->driver == NULL) | 589 | if (dev->driver == NULL) |
696 | return 0; | 590 | return 0; |
697 | drv = to_xenbus_driver(dev->driver); | 591 | drv = to_xenbus_driver(dev->driver); |
698 | xdev = container_of(dev, struct xenbus_device, dev); | ||
699 | if (drv->suspend) | 592 | if (drv->suspend) |
700 | err = drv->suspend(xdev, state); | 593 | err = drv->suspend(xdev, state); |
701 | if (err) | 594 | if (err) |
@@ -703,21 +596,20 @@ static int xenbus_dev_suspend(struct device *dev, pm_message_t state) | |||
703 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); | 596 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); |
704 | return 0; | 597 | return 0; |
705 | } | 598 | } |
599 | EXPORT_SYMBOL_GPL(xenbus_dev_suspend); | ||
706 | 600 | ||
707 | static int xenbus_dev_resume(struct device *dev) | 601 | int xenbus_dev_resume(struct device *dev) |
708 | { | 602 | { |
709 | int err; | 603 | int err; |
710 | struct xenbus_driver *drv; | 604 | struct xenbus_driver *drv; |
711 | struct xenbus_device *xdev; | 605 | struct xenbus_device *xdev |
606 | = container_of(dev, struct xenbus_device, dev); | ||
712 | 607 | ||
713 | DPRINTK(""); | 608 | DPRINTK("%s", xdev->nodename); |
714 | 609 | ||
715 | if (dev->driver == NULL) | 610 | if (dev->driver == NULL) |
716 | return 0; | 611 | return 0; |
717 | |||
718 | drv = to_xenbus_driver(dev->driver); | 612 | drv = to_xenbus_driver(dev->driver); |
719 | xdev = container_of(dev, struct xenbus_device, dev); | ||
720 | |||
721 | err = talk_to_otherend(xdev); | 613 | err = talk_to_otherend(xdev); |
722 | if (err) { | 614 | if (err) { |
723 | printk(KERN_WARNING | 615 | printk(KERN_WARNING |
@@ -748,6 +640,7 @@ static int xenbus_dev_resume(struct device *dev) | |||
748 | 640 | ||
749 | return 0; | 641 | return 0; |
750 | } | 642 | } |
643 | EXPORT_SYMBOL_GPL(xenbus_dev_resume); | ||
751 | 644 | ||
752 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ | 645 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ |
753 | int xenstored_ready = 0; | 646 | int xenstored_ready = 0; |
@@ -776,11 +669,6 @@ void xenbus_probe(struct work_struct *unused) | |||
776 | { | 669 | { |
777 | xenstored_ready = 1; | 670 | xenstored_ready = 1; |
778 | 671 | ||
779 | /* Enumerate devices in xenstore and watch for changes. */ | ||
780 | xenbus_probe_devices(&xenbus_frontend); | ||
781 | register_xenbus_watch(&fe_watch); | ||
782 | xenbus_backend_probe_and_watch(); | ||
783 | |||
784 | /* Notify others that xenstore is up */ | 672 | /* Notify others that xenstore is up */ |
785 | blocking_notifier_call_chain(&xenstore_chain, 0, NULL); | 673 | blocking_notifier_call_chain(&xenstore_chain, 0, NULL); |
786 | } | 674 | } |
@@ -809,16 +697,7 @@ static int __init xenbus_init(void) | |||
809 | 697 | ||
810 | err = -ENODEV; | 698 | err = -ENODEV; |
811 | if (!xen_domain()) | 699 | if (!xen_domain()) |
812 | goto out_error; | 700 | return err; |
813 | |||
814 | /* Register ourselves with the kernel bus subsystem */ | ||
815 | err = bus_register(&xenbus_frontend.bus); | ||
816 | if (err) | ||
817 | goto out_error; | ||
818 | |||
819 | err = xenbus_backend_bus_register(); | ||
820 | if (err) | ||
821 | goto out_unreg_front; | ||
822 | 701 | ||
823 | /* | 702 | /* |
824 | * Domain0 doesn't have a store_evtchn or store_mfn yet. | 703 | * Domain0 doesn't have a store_evtchn or store_mfn yet. |
@@ -874,7 +753,7 @@ static int __init xenbus_init(void) | |||
874 | if (err) { | 753 | if (err) { |
875 | printk(KERN_WARNING | 754 | printk(KERN_WARNING |
876 | "XENBUS: Error initializing xenstore comms: %i\n", err); | 755 | "XENBUS: Error initializing xenstore comms: %i\n", err); |
877 | goto out_unreg_back; | 756 | goto out_error; |
878 | } | 757 | } |
879 | 758 | ||
880 | #ifdef CONFIG_XEN_COMPAT_XENFS | 759 | #ifdef CONFIG_XEN_COMPAT_XENFS |
@@ -887,133 +766,13 @@ static int __init xenbus_init(void) | |||
887 | 766 | ||
888 | return 0; | 767 | return 0; |
889 | 768 | ||
890 | out_unreg_back: | ||
891 | xenbus_backend_bus_unregister(); | ||
892 | |||
893 | out_unreg_front: | ||
894 | bus_unregister(&xenbus_frontend.bus); | ||
895 | |||
896 | out_error: | 769 | out_error: |
897 | if (page != 0) | 770 | if (page != 0) |
898 | free_page(page); | 771 | free_page(page); |
772 | |||
899 | return err; | 773 | return err; |
900 | } | 774 | } |
901 | 775 | ||
902 | postcore_initcall(xenbus_init); | 776 | postcore_initcall(xenbus_init); |
903 | 777 | ||
904 | MODULE_LICENSE("GPL"); | 778 | MODULE_LICENSE("GPL"); |
905 | |||
906 | static int is_device_connecting(struct device *dev, void *data) | ||
907 | { | ||
908 | struct xenbus_device *xendev = to_xenbus_device(dev); | ||
909 | struct device_driver *drv = data; | ||
910 | struct xenbus_driver *xendrv; | ||
911 | |||
912 | /* | ||
913 | * A device with no driver will never connect. We care only about | ||
914 | * devices which should currently be in the process of connecting. | ||
915 | */ | ||
916 | if (!dev->driver) | ||
917 | return 0; | ||
918 | |||
919 | /* Is this search limited to a particular driver? */ | ||
920 | if (drv && (dev->driver != drv)) | ||
921 | return 0; | ||
922 | |||
923 | xendrv = to_xenbus_driver(dev->driver); | ||
924 | return (xendev->state < XenbusStateConnected || | ||
925 | (xendev->state == XenbusStateConnected && | ||
926 | xendrv->is_ready && !xendrv->is_ready(xendev))); | ||
927 | } | ||
928 | |||
929 | static int exists_connecting_device(struct device_driver *drv) | ||
930 | { | ||
931 | return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, | ||
932 | is_device_connecting); | ||
933 | } | ||
934 | |||
935 | static int print_device_status(struct device *dev, void *data) | ||
936 | { | ||
937 | struct xenbus_device *xendev = to_xenbus_device(dev); | ||
938 | struct device_driver *drv = data; | ||
939 | |||
940 | /* Is this operation limited to a particular driver? */ | ||
941 | if (drv && (dev->driver != drv)) | ||
942 | return 0; | ||
943 | |||
944 | if (!dev->driver) { | ||
945 | /* Information only: is this too noisy? */ | ||
946 | printk(KERN_INFO "XENBUS: Device with no driver: %s\n", | ||
947 | xendev->nodename); | ||
948 | } else if (xendev->state < XenbusStateConnected) { | ||
949 | enum xenbus_state rstate = XenbusStateUnknown; | ||
950 | if (xendev->otherend) | ||
951 | rstate = xenbus_read_driver_state(xendev->otherend); | ||
952 | printk(KERN_WARNING "XENBUS: Timeout connecting " | ||
953 | "to device: %s (local state %d, remote state %d)\n", | ||
954 | xendev->nodename, xendev->state, rstate); | ||
955 | } | ||
956 | |||
957 | return 0; | ||
958 | } | ||
959 | |||
960 | /* We only wait for device setup after most initcalls have run. */ | ||
961 | static int ready_to_wait_for_devices; | ||
962 | |||
963 | /* | ||
964 | * On a 5-minute timeout, wait for all devices currently configured. We need | ||
965 | * to do this to guarantee that the filesystems and / or network devices | ||
966 | * needed for boot are available, before we can allow the boot to proceed. | ||
967 | * | ||
968 | * This needs to be on a late_initcall, to happen after the frontend device | ||
969 | * drivers have been initialised, but before the root fs is mounted. | ||
970 | * | ||
971 | * A possible improvement here would be to have the tools add a per-device | ||
972 | * flag to the store entry, indicating whether it is needed at boot time. | ||
973 | * This would allow people who knew what they were doing to accelerate their | ||
974 | * boot slightly, but of course needs tools or manual intervention to set up | ||
975 | * those flags correctly. | ||
976 | */ | ||
977 | static void wait_for_devices(struct xenbus_driver *xendrv) | ||
978 | { | ||
979 | unsigned long start = jiffies; | ||
980 | struct device_driver *drv = xendrv ? &xendrv->driver : NULL; | ||
981 | unsigned int seconds_waited = 0; | ||
982 | |||
983 | if (!ready_to_wait_for_devices || !xen_domain()) | ||
984 | return; | ||
985 | |||
986 | while (exists_connecting_device(drv)) { | ||
987 | if (time_after(jiffies, start + (seconds_waited+5)*HZ)) { | ||
988 | if (!seconds_waited) | ||
989 | printk(KERN_WARNING "XENBUS: Waiting for " | ||
990 | "devices to initialise: "); | ||
991 | seconds_waited += 5; | ||
992 | printk("%us...", 300 - seconds_waited); | ||
993 | if (seconds_waited == 300) | ||
994 | break; | ||
995 | } | ||
996 | |||
997 | schedule_timeout_interruptible(HZ/10); | ||
998 | } | ||
999 | |||
1000 | if (seconds_waited) | ||
1001 | printk("\n"); | ||
1002 | |||
1003 | bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, | ||
1004 | print_device_status); | ||
1005 | } | ||
1006 | |||
1007 | #ifndef MODULE | ||
1008 | static int __init boot_wait_for_devices(void) | ||
1009 | { | ||
1010 | if (xen_hvm_domain() && !xen_platform_pci_unplug) | ||
1011 | return -ENODEV; | ||
1012 | |||
1013 | ready_to_wait_for_devices = 1; | ||
1014 | wait_for_devices(NULL); | ||
1015 | return 0; | ||
1016 | } | ||
1017 | |||
1018 | late_initcall(boot_wait_for_devices); | ||
1019 | #endif | ||
diff --git a/drivers/xen/xenbus/xenbus_probe.h b/drivers/xen/xenbus/xenbus_probe.h index 6c5e3185a6a2..24665812316a 100644 --- a/drivers/xen/xenbus/xenbus_probe.h +++ b/drivers/xen/xenbus/xenbus_probe.h | |||
@@ -36,26 +36,15 @@ | |||
36 | 36 | ||
37 | #define XEN_BUS_ID_SIZE 20 | 37 | #define XEN_BUS_ID_SIZE 20 |
38 | 38 | ||
39 | #ifdef CONFIG_XEN_BACKEND | ||
40 | extern void xenbus_backend_suspend(int (*fn)(struct device *, void *)); | ||
41 | extern void xenbus_backend_resume(int (*fn)(struct device *, void *)); | ||
42 | extern void xenbus_backend_probe_and_watch(void); | ||
43 | extern int xenbus_backend_bus_register(void); | ||
44 | extern void xenbus_backend_bus_unregister(void); | ||
45 | #else | ||
46 | static inline void xenbus_backend_suspend(int (*fn)(struct device *, void *)) {} | ||
47 | static inline void xenbus_backend_resume(int (*fn)(struct device *, void *)) {} | ||
48 | static inline void xenbus_backend_probe_and_watch(void) {} | ||
49 | static inline int xenbus_backend_bus_register(void) { return 0; } | ||
50 | static inline void xenbus_backend_bus_unregister(void) {} | ||
51 | #endif | ||
52 | |||
53 | struct xen_bus_type | 39 | struct xen_bus_type |
54 | { | 40 | { |
55 | char *root; | 41 | char *root; |
56 | unsigned int levels; | 42 | unsigned int levels; |
57 | int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename); | 43 | int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename); |
58 | int (*probe)(const char *type, const char *dir); | 44 | int (*probe)(struct xen_bus_type *bus, const char *type, |
45 | const char *dir); | ||
46 | void (*otherend_changed)(struct xenbus_watch *watch, const char **vec, | ||
47 | unsigned int len); | ||
59 | struct bus_type bus; | 48 | struct bus_type bus; |
60 | }; | 49 | }; |
61 | 50 | ||
@@ -73,4 +62,16 @@ extern int xenbus_probe_devices(struct xen_bus_type *bus); | |||
73 | 62 | ||
74 | extern void xenbus_dev_changed(const char *node, struct xen_bus_type *bus); | 63 | extern void xenbus_dev_changed(const char *node, struct xen_bus_type *bus); |
75 | 64 | ||
65 | extern void xenbus_dev_shutdown(struct device *_dev); | ||
66 | |||
67 | extern int xenbus_dev_suspend(struct device *dev, pm_message_t state); | ||
68 | extern int xenbus_dev_resume(struct device *dev); | ||
69 | |||
70 | extern void xenbus_otherend_changed(struct xenbus_watch *watch, | ||
71 | const char **vec, unsigned int len, | ||
72 | int ignore_on_shutdown); | ||
73 | |||
74 | extern int xenbus_read_otherend_details(struct xenbus_device *xendev, | ||
75 | char *id_node, char *path_node); | ||
76 | |||
76 | #endif | 77 | #endif |
diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c new file mode 100644 index 000000000000..6cf467bf63ec --- /dev/null +++ b/drivers/xen/xenbus/xenbus_probe_backend.c | |||
@@ -0,0 +1,276 @@ | |||
1 | /****************************************************************************** | ||
2 | * Talks to Xen Store to figure out what devices we have (backend half). | ||
3 | * | ||
4 | * Copyright (C) 2005 Rusty Russell, IBM Corporation | ||
5 | * Copyright (C) 2005 Mike Wray, Hewlett-Packard | ||
6 | * Copyright (C) 2005, 2006 XenSource Ltd | ||
7 | * Copyright (C) 2007 Solarflare Communications, Inc. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License version 2 | ||
11 | * as published by the Free Software Foundation; or, when distributed | ||
12 | * separately from the Linux kernel or incorporated into other | ||
13 | * software packages, subject to the following license: | ||
14 | * | ||
15 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
16 | * of this source file (the "Software"), to deal in the Software without | ||
17 | * restriction, including without limitation the rights to use, copy, modify, | ||
18 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
19 | * and to permit persons to whom the Software is furnished to do so, subject to | ||
20 | * the following conditions: | ||
21 | * | ||
22 | * The above copyright notice and this permission notice shall be included in | ||
23 | * all copies or substantial portions of the Software. | ||
24 | * | ||
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
30 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
31 | * IN THE SOFTWARE. | ||
32 | */ | ||
33 | |||
34 | #define DPRINTK(fmt, args...) \ | ||
35 | pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \ | ||
36 | __func__, __LINE__, ##args) | ||
37 | |||
38 | #include <linux/kernel.h> | ||
39 | #include <linux/err.h> | ||
40 | #include <linux/string.h> | ||
41 | #include <linux/ctype.h> | ||
42 | #include <linux/fcntl.h> | ||
43 | #include <linux/mm.h> | ||
44 | #include <linux/notifier.h> | ||
45 | |||
46 | #include <asm/page.h> | ||
47 | #include <asm/pgtable.h> | ||
48 | #include <asm/xen/hypervisor.h> | ||
49 | #include <asm/hypervisor.h> | ||
50 | #include <xen/xenbus.h> | ||
51 | #include <xen/features.h> | ||
52 | |||
53 | #include "xenbus_comms.h" | ||
54 | #include "xenbus_probe.h" | ||
55 | |||
56 | /* backend/<type>/<fe-uuid>/<id> => <type>-<fe-domid>-<id> */ | ||
57 | static int backend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) | ||
58 | { | ||
59 | int domid, err; | ||
60 | const char *devid, *type, *frontend; | ||
61 | unsigned int typelen; | ||
62 | |||
63 | type = strchr(nodename, '/'); | ||
64 | if (!type) | ||
65 | return -EINVAL; | ||
66 | type++; | ||
67 | typelen = strcspn(type, "/"); | ||
68 | if (!typelen || type[typelen] != '/') | ||
69 | return -EINVAL; | ||
70 | |||
71 | devid = strrchr(nodename, '/') + 1; | ||
72 | |||
73 | err = xenbus_gather(XBT_NIL, nodename, "frontend-id", "%i", &domid, | ||
74 | "frontend", NULL, &frontend, | ||
75 | NULL); | ||
76 | if (err) | ||
77 | return err; | ||
78 | if (strlen(frontend) == 0) | ||
79 | err = -ERANGE; | ||
80 | if (!err && !xenbus_exists(XBT_NIL, frontend, "")) | ||
81 | err = -ENOENT; | ||
82 | kfree(frontend); | ||
83 | |||
84 | if (err) | ||
85 | return err; | ||
86 | |||
87 | if (snprintf(bus_id, XEN_BUS_ID_SIZE, "%.*s-%i-%s", | ||
88 | typelen, type, domid, devid) >= XEN_BUS_ID_SIZE) | ||
89 | return -ENOSPC; | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static int xenbus_uevent_backend(struct device *dev, | ||
94 | struct kobj_uevent_env *env) | ||
95 | { | ||
96 | struct xenbus_device *xdev; | ||
97 | struct xenbus_driver *drv; | ||
98 | struct xen_bus_type *bus; | ||
99 | |||
100 | DPRINTK(""); | ||
101 | |||
102 | if (dev == NULL) | ||
103 | return -ENODEV; | ||
104 | |||
105 | xdev = to_xenbus_device(dev); | ||
106 | bus = container_of(xdev->dev.bus, struct xen_bus_type, bus); | ||
107 | if (xdev == NULL) | ||
108 | return -ENODEV; | ||
109 | |||
110 | /* stuff we want to pass to /sbin/hotplug */ | ||
111 | if (add_uevent_var(env, "XENBUS_TYPE=%s", xdev->devicetype)) | ||
112 | return -ENOMEM; | ||
113 | |||
114 | if (add_uevent_var(env, "XENBUS_PATH=%s", xdev->nodename)) | ||
115 | return -ENOMEM; | ||
116 | |||
117 | if (add_uevent_var(env, "XENBUS_BASE_PATH=%s", bus->root)) | ||
118 | return -ENOMEM; | ||
119 | |||
120 | if (dev->driver) { | ||
121 | drv = to_xenbus_driver(dev->driver); | ||
122 | if (drv && drv->uevent) | ||
123 | return drv->uevent(xdev, env); | ||
124 | } | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | /* backend/<typename>/<frontend-uuid>/<name> */ | ||
130 | static int xenbus_probe_backend_unit(struct xen_bus_type *bus, | ||
131 | const char *dir, | ||
132 | const char *type, | ||
133 | const char *name) | ||
134 | { | ||
135 | char *nodename; | ||
136 | int err; | ||
137 | |||
138 | nodename = kasprintf(GFP_KERNEL, "%s/%s", dir, name); | ||
139 | if (!nodename) | ||
140 | return -ENOMEM; | ||
141 | |||
142 | DPRINTK("%s\n", nodename); | ||
143 | |||
144 | err = xenbus_probe_node(bus, type, nodename); | ||
145 | kfree(nodename); | ||
146 | return err; | ||
147 | } | ||
148 | |||
149 | /* backend/<typename>/<frontend-domid> */ | ||
150 | static int xenbus_probe_backend(struct xen_bus_type *bus, const char *type, | ||
151 | const char *domid) | ||
152 | { | ||
153 | char *nodename; | ||
154 | int err = 0; | ||
155 | char **dir; | ||
156 | unsigned int i, dir_n = 0; | ||
157 | |||
158 | DPRINTK(""); | ||
159 | |||
160 | nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", bus->root, type, domid); | ||
161 | if (!nodename) | ||
162 | return -ENOMEM; | ||
163 | |||
164 | dir = xenbus_directory(XBT_NIL, nodename, "", &dir_n); | ||
165 | if (IS_ERR(dir)) { | ||
166 | kfree(nodename); | ||
167 | return PTR_ERR(dir); | ||
168 | } | ||
169 | |||
170 | for (i = 0; i < dir_n; i++) { | ||
171 | err = xenbus_probe_backend_unit(bus, nodename, type, dir[i]); | ||
172 | if (err) | ||
173 | break; | ||
174 | } | ||
175 | kfree(dir); | ||
176 | kfree(nodename); | ||
177 | return err; | ||
178 | } | ||
179 | |||
180 | static void frontend_changed(struct xenbus_watch *watch, | ||
181 | const char **vec, unsigned int len) | ||
182 | { | ||
183 | xenbus_otherend_changed(watch, vec, len, 0); | ||
184 | } | ||
185 | |||
186 | static struct device_attribute xenbus_backend_dev_attrs[] = { | ||
187 | __ATTR_NULL | ||
188 | }; | ||
189 | |||
190 | static struct xen_bus_type xenbus_backend = { | ||
191 | .root = "backend", | ||
192 | .levels = 3, /* backend/type/<frontend>/<id> */ | ||
193 | .get_bus_id = backend_bus_id, | ||
194 | .probe = xenbus_probe_backend, | ||
195 | .otherend_changed = frontend_changed, | ||
196 | .bus = { | ||
197 | .name = "xen-backend", | ||
198 | .match = xenbus_match, | ||
199 | .uevent = xenbus_uevent_backend, | ||
200 | .probe = xenbus_dev_probe, | ||
201 | .remove = xenbus_dev_remove, | ||
202 | .shutdown = xenbus_dev_shutdown, | ||
203 | .dev_attrs = xenbus_backend_dev_attrs, | ||
204 | }, | ||
205 | }; | ||
206 | |||
207 | static void backend_changed(struct xenbus_watch *watch, | ||
208 | const char **vec, unsigned int len) | ||
209 | { | ||
210 | DPRINTK(""); | ||
211 | |||
212 | xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_backend); | ||
213 | } | ||
214 | |||
215 | static struct xenbus_watch be_watch = { | ||
216 | .node = "backend", | ||
217 | .callback = backend_changed, | ||
218 | }; | ||
219 | |||
220 | static int read_frontend_details(struct xenbus_device *xendev) | ||
221 | { | ||
222 | return xenbus_read_otherend_details(xendev, "frontend-id", "frontend"); | ||
223 | } | ||
224 | |||
225 | int xenbus_dev_is_online(struct xenbus_device *dev) | ||
226 | { | ||
227 | int rc, val; | ||
228 | |||
229 | rc = xenbus_scanf(XBT_NIL, dev->nodename, "online", "%d", &val); | ||
230 | if (rc != 1) | ||
231 | val = 0; /* no online node present */ | ||
232 | |||
233 | return val; | ||
234 | } | ||
235 | EXPORT_SYMBOL_GPL(xenbus_dev_is_online); | ||
236 | |||
237 | int __xenbus_register_backend(struct xenbus_driver *drv, | ||
238 | struct module *owner, const char *mod_name) | ||
239 | { | ||
240 | drv->read_otherend_details = read_frontend_details; | ||
241 | |||
242 | return xenbus_register_driver_common(drv, &xenbus_backend, | ||
243 | owner, mod_name); | ||
244 | } | ||
245 | EXPORT_SYMBOL_GPL(__xenbus_register_backend); | ||
246 | |||
247 | static int backend_probe_and_watch(struct notifier_block *notifier, | ||
248 | unsigned long event, | ||
249 | void *data) | ||
250 | { | ||
251 | /* Enumerate devices in xenstore and watch for changes. */ | ||
252 | xenbus_probe_devices(&xenbus_backend); | ||
253 | register_xenbus_watch(&be_watch); | ||
254 | |||
255 | return NOTIFY_DONE; | ||
256 | } | ||
257 | |||
258 | static int __init xenbus_probe_backend_init(void) | ||
259 | { | ||
260 | static struct notifier_block xenstore_notifier = { | ||
261 | .notifier_call = backend_probe_and_watch | ||
262 | }; | ||
263 | int err; | ||
264 | |||
265 | DPRINTK(""); | ||
266 | |||
267 | /* Register ourselves with the kernel bus subsystem */ | ||
268 | err = bus_register(&xenbus_backend.bus); | ||
269 | if (err) | ||
270 | return err; | ||
271 | |||
272 | register_xenstore_notifier(&xenstore_notifier); | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | subsys_initcall(xenbus_probe_backend_init); | ||
diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c new file mode 100644 index 000000000000..5bcc2d6cf129 --- /dev/null +++ b/drivers/xen/xenbus/xenbus_probe_frontend.c | |||
@@ -0,0 +1,294 @@ | |||
1 | #define DPRINTK(fmt, args...) \ | ||
2 | pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \ | ||
3 | __func__, __LINE__, ##args) | ||
4 | |||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/err.h> | ||
7 | #include <linux/string.h> | ||
8 | #include <linux/ctype.h> | ||
9 | #include <linux/fcntl.h> | ||
10 | #include <linux/mm.h> | ||
11 | #include <linux/proc_fs.h> | ||
12 | #include <linux/notifier.h> | ||
13 | #include <linux/kthread.h> | ||
14 | #include <linux/mutex.h> | ||
15 | #include <linux/io.h> | ||
16 | |||
17 | #include <asm/page.h> | ||
18 | #include <asm/pgtable.h> | ||
19 | #include <asm/xen/hypervisor.h> | ||
20 | #include <xen/xenbus.h> | ||
21 | #include <xen/events.h> | ||
22 | #include <xen/page.h> | ||
23 | |||
24 | #include <xen/platform_pci.h> | ||
25 | |||
26 | #include "xenbus_comms.h" | ||
27 | #include "xenbus_probe.h" | ||
28 | |||
29 | |||
30 | /* device/<type>/<id> => <type>-<id> */ | ||
31 | static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) | ||
32 | { | ||
33 | nodename = strchr(nodename, '/'); | ||
34 | if (!nodename || strlen(nodename + 1) >= XEN_BUS_ID_SIZE) { | ||
35 | printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename); | ||
36 | return -EINVAL; | ||
37 | } | ||
38 | |||
39 | strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE); | ||
40 | if (!strchr(bus_id, '/')) { | ||
41 | printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id); | ||
42 | return -EINVAL; | ||
43 | } | ||
44 | *strchr(bus_id, '/') = '-'; | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | /* device/<typename>/<name> */ | ||
49 | static int xenbus_probe_frontend(struct xen_bus_type *bus, const char *type, | ||
50 | const char *name) | ||
51 | { | ||
52 | char *nodename; | ||
53 | int err; | ||
54 | |||
55 | nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", bus->root, type, name); | ||
56 | if (!nodename) | ||
57 | return -ENOMEM; | ||
58 | |||
59 | DPRINTK("%s", nodename); | ||
60 | |||
61 | err = xenbus_probe_node(bus, type, nodename); | ||
62 | kfree(nodename); | ||
63 | return err; | ||
64 | } | ||
65 | |||
66 | static int xenbus_uevent_frontend(struct device *_dev, | ||
67 | struct kobj_uevent_env *env) | ||
68 | { | ||
69 | struct xenbus_device *dev = to_xenbus_device(_dev); | ||
70 | |||
71 | if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype)) | ||
72 | return -ENOMEM; | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | |||
78 | static void backend_changed(struct xenbus_watch *watch, | ||
79 | const char **vec, unsigned int len) | ||
80 | { | ||
81 | xenbus_otherend_changed(watch, vec, len, 1); | ||
82 | } | ||
83 | |||
84 | static struct device_attribute xenbus_frontend_dev_attrs[] = { | ||
85 | __ATTR_NULL | ||
86 | }; | ||
87 | |||
88 | static struct xen_bus_type xenbus_frontend = { | ||
89 | .root = "device", | ||
90 | .levels = 2, /* device/type/<id> */ | ||
91 | .get_bus_id = frontend_bus_id, | ||
92 | .probe = xenbus_probe_frontend, | ||
93 | .otherend_changed = backend_changed, | ||
94 | .bus = { | ||
95 | .name = "xen", | ||
96 | .match = xenbus_match, | ||
97 | .uevent = xenbus_uevent_frontend, | ||
98 | .probe = xenbus_dev_probe, | ||
99 | .remove = xenbus_dev_remove, | ||
100 | .shutdown = xenbus_dev_shutdown, | ||
101 | .dev_attrs = xenbus_frontend_dev_attrs, | ||
102 | |||
103 | .suspend = xenbus_dev_suspend, | ||
104 | .resume = xenbus_dev_resume, | ||
105 | }, | ||
106 | }; | ||
107 | |||
108 | static void frontend_changed(struct xenbus_watch *watch, | ||
109 | const char **vec, unsigned int len) | ||
110 | { | ||
111 | DPRINTK(""); | ||
112 | |||
113 | xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend); | ||
114 | } | ||
115 | |||
116 | |||
117 | /* We watch for devices appearing and vanishing. */ | ||
118 | static struct xenbus_watch fe_watch = { | ||
119 | .node = "device", | ||
120 | .callback = frontend_changed, | ||
121 | }; | ||
122 | |||
123 | static int read_backend_details(struct xenbus_device *xendev) | ||
124 | { | ||
125 | return xenbus_read_otherend_details(xendev, "backend-id", "backend"); | ||
126 | } | ||
127 | |||
128 | static int is_device_connecting(struct device *dev, void *data) | ||
129 | { | ||
130 | struct xenbus_device *xendev = to_xenbus_device(dev); | ||
131 | struct device_driver *drv = data; | ||
132 | struct xenbus_driver *xendrv; | ||
133 | |||
134 | /* | ||
135 | * A device with no driver will never connect. We care only about | ||
136 | * devices which should currently be in the process of connecting. | ||
137 | */ | ||
138 | if (!dev->driver) | ||
139 | return 0; | ||
140 | |||
141 | /* Is this search limited to a particular driver? */ | ||
142 | if (drv && (dev->driver != drv)) | ||
143 | return 0; | ||
144 | |||
145 | xendrv = to_xenbus_driver(dev->driver); | ||
146 | return (xendev->state < XenbusStateConnected || | ||
147 | (xendev->state == XenbusStateConnected && | ||
148 | xendrv->is_ready && !xendrv->is_ready(xendev))); | ||
149 | } | ||
150 | |||
151 | static int exists_connecting_device(struct device_driver *drv) | ||
152 | { | ||
153 | return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, | ||
154 | is_device_connecting); | ||
155 | } | ||
156 | |||
157 | static int print_device_status(struct device *dev, void *data) | ||
158 | { | ||
159 | struct xenbus_device *xendev = to_xenbus_device(dev); | ||
160 | struct device_driver *drv = data; | ||
161 | |||
162 | /* Is this operation limited to a particular driver? */ | ||
163 | if (drv && (dev->driver != drv)) | ||
164 | return 0; | ||
165 | |||
166 | if (!dev->driver) { | ||
167 | /* Information only: is this too noisy? */ | ||
168 | printk(KERN_INFO "XENBUS: Device with no driver: %s\n", | ||
169 | xendev->nodename); | ||
170 | } else if (xendev->state < XenbusStateConnected) { | ||
171 | enum xenbus_state rstate = XenbusStateUnknown; | ||
172 | if (xendev->otherend) | ||
173 | rstate = xenbus_read_driver_state(xendev->otherend); | ||
174 | printk(KERN_WARNING "XENBUS: Timeout connecting " | ||
175 | "to device: %s (local state %d, remote state %d)\n", | ||
176 | xendev->nodename, xendev->state, rstate); | ||
177 | } | ||
178 | |||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | /* We only wait for device setup after most initcalls have run. */ | ||
183 | static int ready_to_wait_for_devices; | ||
184 | |||
185 | /* | ||
186 | * On a 5-minute timeout, wait for all devices currently configured. We need | ||
187 | * to do this to guarantee that the filesystems and / or network devices | ||
188 | * needed for boot are available, before we can allow the boot to proceed. | ||
189 | * | ||
190 | * This needs to be on a late_initcall, to happen after the frontend device | ||
191 | * drivers have been initialised, but before the root fs is mounted. | ||
192 | * | ||
193 | * A possible improvement here would be to have the tools add a per-device | ||
194 | * flag to the store entry, indicating whether it is needed at boot time. | ||
195 | * This would allow people who knew what they were doing to accelerate their | ||
196 | * boot slightly, but of course needs tools or manual intervention to set up | ||
197 | * those flags correctly. | ||
198 | */ | ||
199 | static void wait_for_devices(struct xenbus_driver *xendrv) | ||
200 | { | ||
201 | unsigned long start = jiffies; | ||
202 | struct device_driver *drv = xendrv ? &xendrv->driver : NULL; | ||
203 | unsigned int seconds_waited = 0; | ||
204 | |||
205 | if (!ready_to_wait_for_devices || !xen_domain()) | ||
206 | return; | ||
207 | |||
208 | while (exists_connecting_device(drv)) { | ||
209 | if (time_after(jiffies, start + (seconds_waited+5)*HZ)) { | ||
210 | if (!seconds_waited) | ||
211 | printk(KERN_WARNING "XENBUS: Waiting for " | ||
212 | "devices to initialise: "); | ||
213 | seconds_waited += 5; | ||
214 | printk("%us...", 300 - seconds_waited); | ||
215 | if (seconds_waited == 300) | ||
216 | break; | ||
217 | } | ||
218 | |||
219 | schedule_timeout_interruptible(HZ/10); | ||
220 | } | ||
221 | |||
222 | if (seconds_waited) | ||
223 | printk("\n"); | ||
224 | |||
225 | bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, | ||
226 | print_device_status); | ||
227 | } | ||
228 | |||
229 | int __xenbus_register_frontend(struct xenbus_driver *drv, | ||
230 | struct module *owner, const char *mod_name) | ||
231 | { | ||
232 | int ret; | ||
233 | |||
234 | drv->read_otherend_details = read_backend_details; | ||
235 | |||
236 | ret = xenbus_register_driver_common(drv, &xenbus_frontend, | ||
237 | owner, mod_name); | ||
238 | if (ret) | ||
239 | return ret; | ||
240 | |||
241 | /* If this driver is loaded as a module wait for devices to attach. */ | ||
242 | wait_for_devices(drv); | ||
243 | |||
244 | return 0; | ||
245 | } | ||
246 | EXPORT_SYMBOL_GPL(__xenbus_register_frontend); | ||
247 | |||
248 | static int frontend_probe_and_watch(struct notifier_block *notifier, | ||
249 | unsigned long event, | ||
250 | void *data) | ||
251 | { | ||
252 | /* Enumerate devices in xenstore and watch for changes. */ | ||
253 | xenbus_probe_devices(&xenbus_frontend); | ||
254 | register_xenbus_watch(&fe_watch); | ||
255 | |||
256 | return NOTIFY_DONE; | ||
257 | } | ||
258 | |||
259 | |||
260 | static int __init xenbus_probe_frontend_init(void) | ||
261 | { | ||
262 | static struct notifier_block xenstore_notifier = { | ||
263 | .notifier_call = frontend_probe_and_watch | ||
264 | }; | ||
265 | int err; | ||
266 | |||
267 | DPRINTK(""); | ||
268 | |||
269 | /* Register ourselves with the kernel bus subsystem */ | ||
270 | err = bus_register(&xenbus_frontend.bus); | ||
271 | if (err) | ||
272 | return err; | ||
273 | |||
274 | register_xenstore_notifier(&xenstore_notifier); | ||
275 | |||
276 | return 0; | ||
277 | } | ||
278 | subsys_initcall(xenbus_probe_frontend_init); | ||
279 | |||
280 | #ifndef MODULE | ||
281 | static int __init boot_wait_for_devices(void) | ||
282 | { | ||
283 | if (xen_hvm_domain() && !xen_platform_pci_unplug) | ||
284 | return -ENODEV; | ||
285 | |||
286 | ready_to_wait_for_devices = 1; | ||
287 | wait_for_devices(NULL); | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | late_initcall(boot_wait_for_devices); | ||
292 | #endif | ||
293 | |||
294 | MODULE_LICENSE("GPL"); | ||