Lines Matching +full:closed +full:- +full:loop

5  * See the COPYING file in the top-level directory.
9 #include "qemu/main-loop.h"
12 #include "hw/qdev-properties.h"
15 #include "hw/xen/xen-backend.h"
16 #include "hw/xen/xen-legacy-backend.h" /* xen_be_init() */
17 #include "hw/xen/xen-bus.h"
18 #include "hw/xen/xen-bus-helper.h"
31 const char *backend = xendev_class->backend; in xen_device_get_backend_path()
38 xenbus->backend_id, backend, xendev->frontend_id, in xen_device_get_backend_path()
39 xendev->name); in xen_device_get_backend_path()
46 const char *device = xendev_class->device; in xen_device_get_frontend_path()
53 xendev->frontend_id, device, xendev->name); in xen_device_get_frontend_path()
63 trace_xen_device_unplug(type, xendev->name); in xen_device_unplug()
67 tid = qemu_xen_xs_transaction_start(xenbus->xsh); in xen_device_unplug()
73 xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "online", in xen_device_unplug()
79 xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "state", in xen_device_unplug()
85 if (!qemu_xen_xs_transaction_end(xenbus->xsh, tid, false)) { in xen_device_unplug()
100 qemu_xen_xs_transaction_end(xenbus->xsh, tid, true); in xen_device_unplug()
108 indent, "", xendev->name, xendev->frontend_id); in xen_bus_print_dev()
129 tid = qemu_xen_xs_transaction_start(xenbus->xsh); in xen_bus_backend_create()
135 key = qemu_xen_xs_directory(xenbus->xsh, tid, path, &n); in xen_bus_backend_create()
137 if (!qemu_xen_xs_transaction_end(xenbus->xsh, tid, true)) { in xen_bus_backend_create()
155 !strcmp(key[i], "frontend-id") || in xen_bus_backend_create()
156 !strcmp(key[i], "hotplug-status")) in xen_bus_backend_create()
159 val = xs_node_read(xenbus->xsh, tid, NULL, NULL, "%s/%s", path, key[i]); in xen_bus_backend_create()
168 if (!qemu_xen_xs_transaction_end(xenbus->xsh, tid, false)) { in xen_bus_backend_create()
195 backend = qemu_xen_xs_directory(xenbus->xsh, XBT_NULL, domain_path, &n); in xen_bus_type_enumerate()
206 if (xs_node_scanf(xenbus->xsh, XBT_NULL, backend_path, "state", in xen_bus_type_enumerate()
210 if (xs_node_scanf(xenbus->xsh, XBT_NULL, backend_path, "online", in xen_bus_type_enumerate()
241 type = qemu_xen_xs_directory(xenbus->xsh, XBT_NULL, "backend", &n); in xen_bus_enumerate()
258 trace_xen_bus_device_cleanup(type, xendev->name); in xen_bus_device_cleanup()
260 g_assert(!xendev->backend_online); in xen_bus_device_cleanup()
277 QLIST_FOREACH_SAFE(xendev, &xenbus->inactive_devices, list, next) { in xen_bus_cleanup()
278 g_assert(xendev->inactive); in xen_bus_cleanup()
298 if (xenbus->backend_watch) { in xen_bus_unrealize()
301 for (i = 0; i < xenbus->backend_types; i++) { in xen_bus_unrealize()
302 if (xenbus->backend_watch[i]) { in xen_bus_unrealize()
303 xs_node_unwatch(xenbus->xsh, xenbus->backend_watch[i]); in xen_bus_unrealize()
307 g_free(xenbus->backend_watch); in xen_bus_unrealize()
308 xenbus->backend_watch = NULL; in xen_bus_unrealize()
311 if (xenbus->xsh) { in xen_bus_unrealize()
312 qemu_xen_xs_close(xenbus->xsh); in xen_bus_unrealize()
327 xenbus->xsh = qemu_xen_xs_open(); in xen_bus_realize()
328 if (!xenbus->xsh) { in xen_bus_realize()
336 if (xs_node_scanf(xenbus->xsh, XBT_NULL, "", /* domain root node */ in xen_bus_realize()
338 xenbus->backend_id = domid; in xen_bus_realize()
340 xenbus->backend_id = 0; /* Assume lack of node means dom0 */ in xen_bus_realize()
345 type = xen_backend_get_types(&xenbus->backend_types); in xen_bus_realize()
346 xenbus->backend_watch = g_new(struct qemu_xs_watch *, in xen_bus_realize()
347 xenbus->backend_types); in xen_bus_realize()
349 for (i = 0; i < xenbus->backend_types; i++) { in xen_bus_realize()
352 xenbus->backend_watch[i] = in xen_bus_realize()
353 xs_node_watch(xenbus->xsh, node, key, xen_bus_backend_changed, in xen_bus_realize()
388 bus_class->print_dev = xen_bus_print_dev; in xen_bus_class_init()
389 bus_class->get_dev_path = xen_bus_get_dev_path; in xen_bus_class_init()
390 bus_class->realize = xen_bus_realize; in xen_bus_class_init()
391 bus_class->unrealize = xen_bus_unrealize; in xen_bus_class_init()
393 hotplug_class->unplug_request = xen_bus_unplug_request; in xen_bus_class_init()
415 g_assert(xenbus->xsh); in xen_device_backend_printf()
418 xs_node_vprintf(xenbus->xsh, XBT_NULL, xendev->backend_path, key, in xen_device_backend_printf()
435 g_assert(xenbus->xsh); in xen_device_backend_scanf()
438 rc = xs_node_vscanf(xenbus->xsh, XBT_NULL, xendev->backend_path, key, in xen_device_backend_scanf()
450 if (xendev->backend_state == state) { in xen_device_backend_set_state()
454 trace_xen_device_backend_state(type, xendev->name, in xen_device_backend_set_state()
457 xendev->backend_state = state; in xen_device_backend_set_state()
463 return xendev->backend_state; in xen_device_backend_get_state()
470 if (xendev->backend_online == online) { in xen_device_backend_set_online()
474 trace_xen_device_backend_online(type, xendev->name, online); in xen_device_backend_set_online()
476 xendev->backend_online = online; in xen_device_backend_set_online()
486 switch (xendev->frontend_state) { in xen_device_frontend_is_active()
504 trace_xen_device_backend_changed(type, xendev->name); in xen_device_backend_changed()
521 * backend state to Closed. in xen_device_backend_changed()
537 !xendev->inactive) { in xen_device_backend_changed()
540 xendev->inactive = true; in xen_device_backend_changed()
541 QLIST_INSERT_HEAD(&xenbus->inactive_devices, xendev, list); in xen_device_backend_changed()
544 * Re-write the state to cause a XenBus backend_watch notification, in xen_device_backend_changed()
556 xendev->backend_path = xen_device_get_backend_path(xendev); in xen_device_backend_create()
558 g_assert(xenbus->xsh); in xen_device_backend_create()
560 xs_node_create(xenbus->xsh, XBT_NULL, xendev->backend_path, in xen_device_backend_create()
561 xenbus->backend_id, xendev->frontend_id, XS_PERM_READ, errp); in xen_device_backend_create()
567 xendev->backend_state_watch = in xen_device_backend_create()
568 xs_node_watch(xendev->xsh, xendev->backend_path, in xen_device_backend_create()
576 xendev->backend_online_watch = in xen_device_backend_create()
577 xs_node_watch(xendev->xsh, xendev->backend_path, in xen_device_backend_create()
591 if (xendev->backend_online_watch) { in xen_device_backend_destroy()
592 xs_node_unwatch(xendev->xsh, xendev->backend_online_watch); in xen_device_backend_destroy()
593 xendev->backend_online_watch = NULL; in xen_device_backend_destroy()
596 if (xendev->backend_state_watch) { in xen_device_backend_destroy()
597 xs_node_unwatch(xendev->xsh, xendev->backend_state_watch); in xen_device_backend_destroy()
598 xendev->backend_state_watch = NULL; in xen_device_backend_destroy()
601 if (!xendev->backend_path) { in xen_device_backend_destroy()
605 g_assert(xenbus->xsh); in xen_device_backend_destroy()
607 xs_node_destroy(xenbus->xsh, XBT_NULL, xendev->backend_path, in xen_device_backend_destroy()
609 g_free(xendev->backend_path); in xen_device_backend_destroy()
610 xendev->backend_path = NULL; in xen_device_backend_destroy()
624 g_assert(xenbus->xsh); in xen_device_frontend_printf()
627 xs_node_vprintf(xenbus->xsh, XBT_NULL, xendev->frontend_path, key, in xen_device_frontend_printf()
643 g_assert(xenbus->xsh); in xen_device_frontend_scanf()
646 rc = xs_node_vscanf(xenbus->xsh, XBT_NULL, xendev->frontend_path, key, in xen_device_frontend_scanf()
657 g_assert(xenbus->xsh); in xen_device_frontend_read()
659 return xs_node_read(xenbus->xsh, XBT_NULL, NULL, NULL, "%s/%s", in xen_device_frontend_read()
660 xendev->frontend_path, key); in xen_device_frontend_read()
669 if (xendev->frontend_state == state) { in xen_device_frontend_set_state()
673 trace_xen_device_frontend_state(type, xendev->name, in xen_device_frontend_set_state()
676 xendev->frontend_state = state; in xen_device_frontend_set_state()
689 trace_xen_device_frontend_changed(type, xendev->name); in xen_device_frontend_changed()
698 xendev->backend_state == XenbusStateClosed && in xen_device_frontend_changed()
699 xendev->backend_online) { in xen_device_frontend_changed()
701 * The frontend is re-initializing so switch back to in xen_device_frontend_changed()
708 if (xendev_class->frontend_changed) { in xen_device_frontend_changed()
711 xendev_class->frontend_changed(xendev, state, &local_err); in xen_device_frontend_changed()
732 if (xendev_class->get_frontend_path) { in xen_device_frontend_create()
733 xendev->frontend_path = xendev_class->get_frontend_path(xendev, errp); in xen_device_frontend_create()
734 if (!xendev->frontend_path) { in xen_device_frontend_create()
739 xendev->frontend_path = xen_device_get_frontend_path(xendev); in xen_device_frontend_create()
747 g_assert(xenbus->xsh); in xen_device_frontend_create()
749 xs_node_create(xenbus->xsh, XBT_NULL, xendev->frontend_path, in xen_device_frontend_create()
750 xendev->frontend_id, xenbus->backend_id, in xen_device_frontend_create()
758 xendev->frontend_state_watch = in xen_device_frontend_create()
759 xs_node_watch(xendev->xsh, xendev->frontend_path, "state", in xen_device_frontend_create()
771 if (xendev->frontend_state_watch) { in xen_device_frontend_destroy()
772 xs_node_unwatch(xendev->xsh, xendev->frontend_state_watch); in xen_device_frontend_destroy()
773 xendev->frontend_state_watch = NULL; in xen_device_frontend_destroy()
776 if (!xendev->frontend_path) { in xen_device_frontend_destroy()
780 g_assert(xenbus->xsh); in xen_device_frontend_destroy()
782 xs_node_destroy(xenbus->xsh, XBT_NULL, xendev->frontend_path, in xen_device_frontend_destroy()
784 g_free(xendev->frontend_path); in xen_device_frontend_destroy()
785 xendev->frontend_path = NULL; in xen_device_frontend_destroy()
795 if (qemu_xen_gnttab_set_max_grants(xendev->xgth, nr_refs)) { in xen_device_set_max_grant_refs()
804 void *map = qemu_xen_gnttab_map_refs(xendev->xgth, nr_refs, in xen_device_map_grant_refs()
805 xendev->frontend_id, refs, prot); in xen_device_map_grant_refs()
818 if (qemu_xen_gnttab_unmap(xendev->xgth, map, refs, nr_refs)) { in xen_device_unmap_grant_refs()
827 qemu_xen_gnttab_grant_copy(xendev->xgth, to_domain, xendev->frontend_id, in xen_device_copy_grant_refs()
844 return channel->handler(channel->opaque); in xen_device_poll()
850 unsigned long port = qemu_xen_evtchn_pending(channel->xeh); in xen_device_event()
852 if (port == channel->local_port) { in xen_device_event()
855 qemu_xen_evtchn_unmask(channel->xeh, port); in xen_device_event()
869 if (channel->ctx) in xen_device_set_event_channel_context()
870 aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), in xen_device_set_event_channel_context()
873 channel->ctx = ctx; in xen_device_set_event_channel_context()
875 aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), in xen_device_set_event_channel_context()
889 channel->xeh = qemu_xen_evtchn_open(); in xen_device_bind_event_channel()
890 if (!channel->xeh) { in xen_device_bind_event_channel()
895 local_port = qemu_xen_evtchn_bind_interdomain(channel->xeh, in xen_device_bind_event_channel()
896 xendev->frontend_id, in xen_device_bind_event_channel()
903 channel->local_port = local_port; in xen_device_bind_event_channel()
904 channel->handler = handler; in xen_device_bind_event_channel()
905 channel->opaque = opaque; in xen_device_bind_event_channel()
912 QLIST_INSERT_HEAD(&xendev->event_channels, channel, list); in xen_device_bind_event_channel()
917 if (channel->xeh) { in xen_device_bind_event_channel()
918 qemu_xen_evtchn_close(channel->xeh); in xen_device_bind_event_channel()
935 if (qemu_xen_evtchn_notify(channel->xeh, channel->local_port) < 0) { in xen_device_notify_event_channel()
942 return channel->local_port; in xen_event_channel_get_local_port()
956 if (channel->ctx) { in xen_device_unbind_event_channel()
957 aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), in xen_device_unbind_event_channel()
961 if (qemu_xen_evtchn_unbind(channel->xeh, channel->local_port) < 0) { in xen_device_unbind_event_channel()
965 qemu_xen_evtchn_close(channel->xeh); in xen_device_unbind_event_channel()
976 if (!xendev->name) { in xen_device_unrealize()
980 trace_xen_device_unrealize(type, xendev->name); in xen_device_unrealize()
982 if (xendev->exit.notify) { in xen_device_unrealize()
983 qemu_remove_exit_notifier(&xendev->exit); in xen_device_unrealize()
984 xendev->exit.notify = NULL; in xen_device_unrealize()
987 if (xendev_class->unrealize) { in xen_device_unrealize()
988 xendev_class->unrealize(xendev); in xen_device_unrealize()
992 QLIST_FOREACH_SAFE(channel, &xendev->event_channels, list, next) { in xen_device_unrealize()
999 if (xendev->xgth) { in xen_device_unrealize()
1000 qemu_xen_gnttab_close(xendev->xgth); in xen_device_unrealize()
1001 xendev->xgth = NULL; in xen_device_unrealize()
1004 if (xendev->xsh) { in xen_device_unrealize()
1005 qemu_xen_xs_close(xendev->xsh); in xen_device_unrealize()
1006 xendev->xsh = NULL; in xen_device_unrealize()
1009 g_free(xendev->name); in xen_device_unrealize()
1010 xendev->name = NULL; in xen_device_unrealize()
1028 if (xendev->frontend_id == DOMID_INVALID) { in xen_device_realize()
1029 xendev->frontend_id = xen_domid; in xen_device_realize()
1032 if (xendev->frontend_id >= DOMID_FIRST_RESERVED) { in xen_device_realize()
1033 error_setg(errp, "invalid frontend-id"); in xen_device_realize()
1037 if (!xendev_class->get_name) { in xen_device_realize()
1042 xendev->name = xendev_class->get_name(xendev, errp); in xen_device_realize()
1048 trace_xen_device_realize(type, xendev->name); in xen_device_realize()
1050 xendev->xsh = qemu_xen_xs_open(); in xen_device_realize()
1051 if (!xendev->xsh) { in xen_device_realize()
1056 xendev->xgth = qemu_xen_gnttab_open(); in xen_device_realize()
1057 if (!xendev->xgth) { in xen_device_realize()
1073 xendev->frontend_path); in xen_device_realize()
1074 xen_device_backend_printf(xendev, "frontend-id", "%u", in xen_device_realize()
1075 xendev->frontend_id); in xen_device_realize()
1076 xen_device_backend_printf(xendev, "hotplug-status", "connected"); in xen_device_realize()
1083 xendev->backend_path); in xen_device_realize()
1084 xen_device_frontend_printf(xendev, "backend-id", "%u", in xen_device_realize()
1085 xenbus->backend_id); in xen_device_realize()
1090 if (xendev_class->realize) { in xen_device_realize()
1091 xendev_class->realize(xendev, errp); in xen_device_realize()
1097 xendev->exit.notify = xen_device_exit; in xen_device_realize()
1098 qemu_add_exit_notifier(&xendev->exit); in xen_device_realize()
1106 DEFINE_PROP_UINT16("frontend-id", XenDevice, frontend_id,
1114 dev_class->realize = xen_device_realize; in xen_device_class_init()
1115 dev_class->unrealize = xen_device_unrealize; in xen_device_class_init()
1117 dev_class->bus_type = TYPE_XEN_BUS; in xen_device_class_init()
1133 #define TYPE_XEN_BRIDGE "xen-bridge"
1158 qemu_create_nic_bus_devices(bus, TYPE_XEN_DEVICE, "xen-net-device", in type_init()
1159 "xen", "xen-net-device"); in type_init()