Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
[qemu/kevin.git] / hw / xen / xen_backend.c
blobbab79b19126cc7304465e60abe75ac8226191a52
1 /*
2 * xen backend driver infrastructure
3 * (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; under version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Contributions after 2012-01-13 are licensed under the terms of the
18 * GNU GPL, version 2 or (at your option) any later version.
22 * TODO: add some xenbus / xenstore concepts overview here.
25 #include "qemu/osdep.h"
26 #include <sys/signal.h>
28 #include "hw/hw.h"
29 #include "hw/sysbus.h"
30 #include "sysemu/char.h"
31 #include "qemu/log.h"
32 #include "hw/xen/xen_backend.h"
34 #include <xen/grant_table.h>
36 #define TYPE_XENSYSDEV "xensysdev"
38 DeviceState *xen_sysdev;
40 /* ------------------------------------------------------------- */
42 /* public */
43 xc_interface *xen_xc = NULL;
44 xenforeignmemory_handle *xen_fmem = NULL;
45 struct xs_handle *xenstore = NULL;
46 const char *xen_protocol;
48 /* private */
49 struct xs_dirs {
50 char *xs_dir;
51 QTAILQ_ENTRY(xs_dirs) list;
53 static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup =
54 QTAILQ_HEAD_INITIALIZER(xs_cleanup);
56 static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs);
57 static int debug = 0;
59 /* ------------------------------------------------------------- */
61 static void xenstore_cleanup_dir(char *dir)
63 struct xs_dirs *d;
65 d = g_malloc(sizeof(*d));
66 d->xs_dir = dir;
67 QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
70 void xen_config_cleanup(void)
72 struct xs_dirs *d;
74 QTAILQ_FOREACH(d, &xs_cleanup, list) {
75 xs_rm(xenstore, 0, d->xs_dir);
79 int xenstore_write_str(const char *base, const char *node, const char *val)
81 char abspath[XEN_BUFSIZE];
83 snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
84 if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
85 return -1;
87 return 0;
90 char *xenstore_read_str(const char *base, const char *node)
92 char abspath[XEN_BUFSIZE];
93 unsigned int len;
94 char *str, *ret = NULL;
96 snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
97 str = xs_read(xenstore, 0, abspath, &len);
98 if (str != NULL) {
99 /* move to qemu-allocated memory to make sure
100 * callers can savely g_free() stuff. */
101 ret = g_strdup(str);
102 free(str);
104 return ret;
107 int xenstore_mkdir(char *path, int p)
109 struct xs_permissions perms[2] = {
111 .id = 0, /* set owner: dom0 */
112 }, {
113 .id = xen_domid,
114 .perms = p,
118 if (!xs_mkdir(xenstore, 0, path)) {
119 xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path);
120 return -1;
122 xenstore_cleanup_dir(g_strdup(path));
124 if (!xs_set_permissions(xenstore, 0, path, perms, 2)) {
125 xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path);
126 return -1;
128 return 0;
131 int xenstore_write_int(const char *base, const char *node, int ival)
133 char val[12];
135 snprintf(val, sizeof(val), "%d", ival);
136 return xenstore_write_str(base, node, val);
139 int xenstore_write_int64(const char *base, const char *node, int64_t ival)
141 char val[21];
143 snprintf(val, sizeof(val), "%"PRId64, ival);
144 return xenstore_write_str(base, node, val);
147 int xenstore_read_int(const char *base, const char *node, int *ival)
149 char *val;
150 int rc = -1;
152 val = xenstore_read_str(base, node);
153 if (val && 1 == sscanf(val, "%d", ival)) {
154 rc = 0;
156 g_free(val);
157 return rc;
160 int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval)
162 char *val;
163 int rc = -1;
165 val = xenstore_read_str(base, node);
166 if (val && 1 == sscanf(val, "%"SCNu64, uval)) {
167 rc = 0;
169 g_free(val);
170 return rc;
173 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val)
175 return xenstore_write_str(xendev->be, node, val);
178 int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival)
180 return xenstore_write_int(xendev->be, node, ival);
183 int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival)
185 return xenstore_write_int64(xendev->be, node, ival);
188 char *xenstore_read_be_str(struct XenDevice *xendev, const char *node)
190 return xenstore_read_str(xendev->be, node);
193 int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival)
195 return xenstore_read_int(xendev->be, node, ival);
198 char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node)
200 return xenstore_read_str(xendev->fe, node);
203 int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival)
205 return xenstore_read_int(xendev->fe, node, ival);
208 int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval)
210 return xenstore_read_uint64(xendev->fe, node, uval);
213 /* ------------------------------------------------------------- */
215 const char *xenbus_strstate(enum xenbus_state state)
217 static const char *const name[] = {
218 [ XenbusStateUnknown ] = "Unknown",
219 [ XenbusStateInitialising ] = "Initialising",
220 [ XenbusStateInitWait ] = "InitWait",
221 [ XenbusStateInitialised ] = "Initialised",
222 [ XenbusStateConnected ] = "Connected",
223 [ XenbusStateClosing ] = "Closing",
224 [ XenbusStateClosed ] = "Closed",
226 return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
229 int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
231 int rc;
233 rc = xenstore_write_be_int(xendev, "state", state);
234 if (rc < 0) {
235 return rc;
237 xen_be_printf(xendev, 1, "backend state: %s -> %s\n",
238 xenbus_strstate(xendev->be_state), xenbus_strstate(state));
239 xendev->be_state = state;
240 return 0;
243 /* ------------------------------------------------------------- */
245 struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev)
247 struct XenDevice *xendev;
249 QTAILQ_FOREACH(xendev, &xendevs, next) {
250 if (xendev->dom != dom) {
251 continue;
253 if (xendev->dev != dev) {
254 continue;
256 if (strcmp(xendev->type, type) != 0) {
257 continue;
259 return xendev;
261 return NULL;
265 * get xen backend device, allocate a new one if it doesn't exist.
267 static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
268 struct XenDevOps *ops)
270 struct XenDevice *xendev;
272 xendev = xen_be_find_xendev(type, dom, dev);
273 if (xendev) {
274 return xendev;
277 /* init new xendev */
278 xendev = g_malloc0(ops->size);
279 xendev->type = type;
280 xendev->dom = dom;
281 xendev->dev = dev;
282 xendev->ops = ops;
284 snprintf(xendev->be, sizeof(xendev->be), "backend/%s/%d/%d",
285 xendev->type, xendev->dom, xendev->dev);
286 snprintf(xendev->name, sizeof(xendev->name), "%s-%d",
287 xendev->type, xendev->dev);
289 xendev->debug = debug;
290 xendev->local_port = -1;
292 xendev->evtchndev = xenevtchn_open(NULL, 0);
293 if (xendev->evtchndev == NULL) {
294 xen_be_printf(NULL, 0, "can't open evtchn device\n");
295 g_free(xendev);
296 return NULL;
298 fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
300 if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
301 xendev->gnttabdev = xengnttab_open(NULL, 0);
302 if (xendev->gnttabdev == NULL) {
303 xen_be_printf(NULL, 0, "can't open gnttab device\n");
304 xenevtchn_close(xendev->evtchndev);
305 g_free(xendev);
306 return NULL;
308 } else {
309 xendev->gnttabdev = NULL;
312 QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
314 if (xendev->ops->alloc) {
315 xendev->ops->alloc(xendev);
318 return xendev;
322 * release xen backend device.
324 static struct XenDevice *xen_be_del_xendev(int dom, int dev)
326 struct XenDevice *xendev, *xnext;
329 * This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but
330 * we save the next pointer in xnext because we might free xendev.
332 xnext = xendevs.tqh_first;
333 while (xnext) {
334 xendev = xnext;
335 xnext = xendev->next.tqe_next;
337 if (xendev->dom != dom) {
338 continue;
340 if (xendev->dev != dev && dev != -1) {
341 continue;
344 if (xendev->ops->free) {
345 xendev->ops->free(xendev);
348 if (xendev->fe) {
349 char token[XEN_BUFSIZE];
350 snprintf(token, sizeof(token), "fe:%p", xendev);
351 xs_unwatch(xenstore, xendev->fe, token);
352 g_free(xendev->fe);
355 if (xendev->evtchndev != NULL) {
356 xenevtchn_close(xendev->evtchndev);
358 if (xendev->gnttabdev != NULL) {
359 xengnttab_close(xendev->gnttabdev);
362 QTAILQ_REMOVE(&xendevs, xendev, next);
363 g_free(xendev);
365 return NULL;
369 * Sync internal data structures on xenstore updates.
370 * Node specifies the changed field. node = NULL means
371 * update all fields (used for initialization).
373 static void xen_be_backend_changed(struct XenDevice *xendev, const char *node)
375 if (node == NULL || strcmp(node, "online") == 0) {
376 if (xenstore_read_be_int(xendev, "online", &xendev->online) == -1) {
377 xendev->online = 0;
381 if (node) {
382 xen_be_printf(xendev, 2, "backend update: %s\n", node);
383 if (xendev->ops->backend_changed) {
384 xendev->ops->backend_changed(xendev, node);
389 static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node)
391 int fe_state;
393 if (node == NULL || strcmp(node, "state") == 0) {
394 if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) {
395 fe_state = XenbusStateUnknown;
397 if (xendev->fe_state != fe_state) {
398 xen_be_printf(xendev, 1, "frontend state: %s -> %s\n",
399 xenbus_strstate(xendev->fe_state),
400 xenbus_strstate(fe_state));
402 xendev->fe_state = fe_state;
404 if (node == NULL || strcmp(node, "protocol") == 0) {
405 g_free(xendev->protocol);
406 xendev->protocol = xenstore_read_fe_str(xendev, "protocol");
407 if (xendev->protocol) {
408 xen_be_printf(xendev, 1, "frontend protocol: %s\n", xendev->protocol);
412 if (node) {
413 xen_be_printf(xendev, 2, "frontend update: %s\n", node);
414 if (xendev->ops->frontend_changed) {
415 xendev->ops->frontend_changed(xendev, node);
420 /* ------------------------------------------------------------- */
421 /* Check for possible state transitions and perform them. */
424 * Initial xendev setup. Read frontend path, register watch for it.
425 * Should succeed once xend finished setting up the backend device.
427 * Also sets initial state (-> Initializing) when done. Which
428 * only affects the xendev->be_state variable as xenbus should
429 * already be put into that state by xend.
431 static int xen_be_try_setup(struct XenDevice *xendev)
433 char token[XEN_BUFSIZE];
434 int be_state;
436 if (xenstore_read_be_int(xendev, "state", &be_state) == -1) {
437 xen_be_printf(xendev, 0, "reading backend state failed\n");
438 return -1;
441 if (be_state != XenbusStateInitialising) {
442 xen_be_printf(xendev, 0, "initial backend state is wrong (%s)\n",
443 xenbus_strstate(be_state));
444 return -1;
447 xendev->fe = xenstore_read_be_str(xendev, "frontend");
448 if (xendev->fe == NULL) {
449 xen_be_printf(xendev, 0, "reading frontend path failed\n");
450 return -1;
453 /* setup frontend watch */
454 snprintf(token, sizeof(token), "fe:%p", xendev);
455 if (!xs_watch(xenstore, xendev->fe, token)) {
456 xen_be_printf(xendev, 0, "watching frontend path (%s) failed\n",
457 xendev->fe);
458 return -1;
460 xen_be_set_state(xendev, XenbusStateInitialising);
462 xen_be_backend_changed(xendev, NULL);
463 xen_be_frontend_changed(xendev, NULL);
464 return 0;
468 * Try initialize xendev. Prepare everything the backend can do
469 * without synchronizing with the frontend. Fakes hotplug-status. No
470 * hotplug involved here because this is about userspace drivers, thus
471 * there are kernel backend devices which could invoke hotplug.
473 * Goes to InitWait on success.
475 static int xen_be_try_init(struct XenDevice *xendev)
477 int rc = 0;
479 if (!xendev->online) {
480 xen_be_printf(xendev, 1, "not online\n");
481 return -1;
484 if (xendev->ops->init) {
485 rc = xendev->ops->init(xendev);
487 if (rc != 0) {
488 xen_be_printf(xendev, 1, "init() failed\n");
489 return rc;
492 xenstore_write_be_str(xendev, "hotplug-status", "connected");
493 xen_be_set_state(xendev, XenbusStateInitWait);
494 return 0;
498 * Try to initialise xendev. Depends on the frontend being ready
499 * for it (shared ring and evtchn info in xenstore, state being
500 * Initialised or Connected).
502 * Goes to Connected on success.
504 static int xen_be_try_initialise(struct XenDevice *xendev)
506 int rc = 0;
508 if (xendev->fe_state != XenbusStateInitialised &&
509 xendev->fe_state != XenbusStateConnected) {
510 if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
511 xen_be_printf(xendev, 2, "frontend not ready, ignoring\n");
512 } else {
513 xen_be_printf(xendev, 2, "frontend not ready (yet)\n");
514 return -1;
518 if (xendev->ops->initialise) {
519 rc = xendev->ops->initialise(xendev);
521 if (rc != 0) {
522 xen_be_printf(xendev, 0, "initialise() failed\n");
523 return rc;
526 xen_be_set_state(xendev, XenbusStateConnected);
527 return 0;
531 * Try to let xendev know that it is connected. Depends on the
532 * frontend being Connected. Note that this may be called more
533 * than once since the backend state is not modified.
535 static void xen_be_try_connected(struct XenDevice *xendev)
537 if (!xendev->ops->connected) {
538 return;
541 if (xendev->fe_state != XenbusStateConnected) {
542 if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
543 xen_be_printf(xendev, 2, "frontend not ready, ignoring\n");
544 } else {
545 xen_be_printf(xendev, 2, "frontend not ready (yet)\n");
546 return;
550 xendev->ops->connected(xendev);
554 * Teardown connection.
556 * Goes to Closed when done.
558 static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)
560 if (xendev->be_state != XenbusStateClosing &&
561 xendev->be_state != XenbusStateClosed &&
562 xendev->ops->disconnect) {
563 xendev->ops->disconnect(xendev);
565 if (xendev->be_state != state) {
566 xen_be_set_state(xendev, state);
571 * Try to reset xendev, for reconnection by another frontend instance.
573 static int xen_be_try_reset(struct XenDevice *xendev)
575 if (xendev->fe_state != XenbusStateInitialising) {
576 return -1;
579 xen_be_printf(xendev, 1, "device reset (for re-connect)\n");
580 xen_be_set_state(xendev, XenbusStateInitialising);
581 return 0;
585 * state change dispatcher function
587 void xen_be_check_state(struct XenDevice *xendev)
589 int rc = 0;
591 /* frontend may request shutdown from almost anywhere */
592 if (xendev->fe_state == XenbusStateClosing ||
593 xendev->fe_state == XenbusStateClosed) {
594 xen_be_disconnect(xendev, xendev->fe_state);
595 return;
598 /* check for possible backend state transitions */
599 for (;;) {
600 switch (xendev->be_state) {
601 case XenbusStateUnknown:
602 rc = xen_be_try_setup(xendev);
603 break;
604 case XenbusStateInitialising:
605 rc = xen_be_try_init(xendev);
606 break;
607 case XenbusStateInitWait:
608 rc = xen_be_try_initialise(xendev);
609 break;
610 case XenbusStateConnected:
611 /* xendev->be_state doesn't change */
612 xen_be_try_connected(xendev);
613 rc = -1;
614 break;
615 case XenbusStateClosed:
616 rc = xen_be_try_reset(xendev);
617 break;
618 default:
619 rc = -1;
621 if (rc != 0) {
622 break;
627 /* ------------------------------------------------------------- */
629 static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
631 struct XenDevice *xendev;
632 char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
633 char **dev = NULL;
634 unsigned int cdev, j;
636 /* setup watch */
637 snprintf(token, sizeof(token), "be:%p:%d:%p", type, dom, ops);
638 snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
639 if (!xs_watch(xenstore, path, token)) {
640 xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
641 return -1;
644 /* look for backends */
645 dev = xs_directory(xenstore, 0, path, &cdev);
646 if (!dev) {
647 return 0;
649 for (j = 0; j < cdev; j++) {
650 xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops);
651 if (xendev == NULL) {
652 continue;
654 xen_be_check_state(xendev);
656 free(dev);
657 return 0;
660 static void xenstore_update_be(char *watch, char *type, int dom,
661 struct XenDevOps *ops)
663 struct XenDevice *xendev;
664 char path[XEN_BUFSIZE], *bepath;
665 unsigned int len, dev;
667 len = snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
668 if (strncmp(path, watch, len) != 0) {
669 return;
671 if (sscanf(watch+len, "/%u/%255s", &dev, path) != 2) {
672 strcpy(path, "");
673 if (sscanf(watch+len, "/%u", &dev) != 1) {
674 dev = -1;
677 if (dev == -1) {
678 return;
681 xendev = xen_be_get_xendev(type, dom, dev, ops);
682 if (xendev != NULL) {
683 bepath = xs_read(xenstore, 0, xendev->be, &len);
684 if (bepath == NULL) {
685 xen_be_del_xendev(dom, dev);
686 } else {
687 free(bepath);
688 xen_be_backend_changed(xendev, path);
689 xen_be_check_state(xendev);
694 static void xenstore_update_fe(char *watch, struct XenDevice *xendev)
696 char *node;
697 unsigned int len;
699 len = strlen(xendev->fe);
700 if (strncmp(xendev->fe, watch, len) != 0) {
701 return;
703 if (watch[len] != '/') {
704 return;
706 node = watch + len + 1;
708 xen_be_frontend_changed(xendev, node);
709 xen_be_check_state(xendev);
712 static void xenstore_update(void *unused)
714 char **vec = NULL;
715 intptr_t type, ops, ptr;
716 unsigned int dom, count;
718 vec = xs_read_watch(xenstore, &count);
719 if (vec == NULL) {
720 goto cleanup;
723 if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR,
724 &type, &dom, &ops) == 3) {
725 xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops);
727 if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) {
728 xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr);
731 cleanup:
732 free(vec);
735 static void xen_be_evtchn_event(void *opaque)
737 struct XenDevice *xendev = opaque;
738 evtchn_port_t port;
740 port = xenevtchn_pending(xendev->evtchndev);
741 if (port != xendev->local_port) {
742 xen_be_printf(xendev, 0,
743 "xenevtchn_pending returned %d (expected %d)\n",
744 port, xendev->local_port);
745 return;
747 xenevtchn_unmask(xendev->evtchndev, port);
749 if (xendev->ops->event) {
750 xendev->ops->event(xendev);
754 /* -------------------------------------------------------------------- */
756 int xen_be_init(void)
758 xenstore = xs_daemon_open();
759 if (!xenstore) {
760 xen_be_printf(NULL, 0, "can't connect to xenstored\n");
761 return -1;
764 qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL);
766 if (xen_xc == NULL || xen_fmem == NULL) {
767 /* Check if xen_init() have been called */
768 goto err;
771 xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
772 qdev_init_nofail(xen_sysdev);
774 return 0;
776 err:
777 qemu_set_fd_handler(xs_fileno(xenstore), NULL, NULL, NULL);
778 xs_daemon_close(xenstore);
779 xenstore = NULL;
781 return -1;
784 int xen_be_register(const char *type, struct XenDevOps *ops)
786 char path[50];
787 int rc;
789 if (ops->backend_register) {
790 rc = ops->backend_register();
791 if (rc) {
792 return rc;
796 snprintf(path, sizeof(path), "device-model/%u/backends/%s", xen_domid,
797 type);
798 xenstore_mkdir(path, XS_PERM_NONE);
800 return xenstore_scan(type, xen_domid, ops);
803 int xen_be_bind_evtchn(struct XenDevice *xendev)
805 if (xendev->local_port != -1) {
806 return 0;
808 xendev->local_port = xenevtchn_bind_interdomain
809 (xendev->evtchndev, xendev->dom, xendev->remote_port);
810 if (xendev->local_port == -1) {
811 xen_be_printf(xendev, 0, "xenevtchn_bind_interdomain failed\n");
812 return -1;
814 xen_be_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
815 qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev),
816 xen_be_evtchn_event, NULL, xendev);
817 return 0;
820 void xen_be_unbind_evtchn(struct XenDevice *xendev)
822 if (xendev->local_port == -1) {
823 return;
825 qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL);
826 xenevtchn_unbind(xendev->evtchndev, xendev->local_port);
827 xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port);
828 xendev->local_port = -1;
831 int xen_be_send_notify(struct XenDevice *xendev)
833 return xenevtchn_notify(xendev->evtchndev, xendev->local_port);
837 * msg_level:
838 * 0 == errors (stderr + logfile).
839 * 1 == informative debug messages (logfile only).
840 * 2 == noisy debug messages (logfile only).
841 * 3 == will flood your log (logfile only).
843 void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...)
845 va_list args;
847 if (xendev) {
848 if (msg_level > xendev->debug) {
849 return;
851 qemu_log("xen be: %s: ", xendev->name);
852 if (msg_level == 0) {
853 fprintf(stderr, "xen be: %s: ", xendev->name);
855 } else {
856 if (msg_level > debug) {
857 return;
859 qemu_log("xen be core: ");
860 if (msg_level == 0) {
861 fprintf(stderr, "xen be core: ");
864 va_start(args, fmt);
865 qemu_log_vprintf(fmt, args);
866 va_end(args);
867 if (msg_level == 0) {
868 va_start(args, fmt);
869 vfprintf(stderr, fmt, args);
870 va_end(args);
872 qemu_log_flush();
875 static int xen_sysdev_init(SysBusDevice *dev)
877 return 0;
880 static Property xen_sysdev_properties[] = {
881 {/* end of property list */},
884 static void xen_sysdev_class_init(ObjectClass *klass, void *data)
886 DeviceClass *dc = DEVICE_CLASS(klass);
887 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
889 k->init = xen_sysdev_init;
890 dc->props = xen_sysdev_properties;
893 static const TypeInfo xensysdev_info = {
894 .name = TYPE_XENSYSDEV,
895 .parent = TYPE_SYS_BUS_DEVICE,
896 .instance_size = sizeof(SysBusDevice),
897 .class_init = xen_sysdev_class_init,
900 static void xenbe_register_types(void)
902 type_register_static(&xensysdev_info);
905 type_init(xenbe_register_types);