This patch introduces a new event type for the QMP event WAKEUP: VIR_DOMAIN_EVENT_ID_WAKEUP The event doesn't take any data. Thus the callback definition is: typedef void (*virConnectDomainEventWakeupCallback)(virConnectPtr conn, virDomainPtr dom, void *opaque); --- daemon/remote.c | 24 ++++++++++ examples/domain-events/events-c/event-test.c | 19 +++++++- examples/domain-events/events-python/event-test.py | 4 ++ include/libvirt/libvirt.h.in | 16 +++++++ python/libvirt-override-virConnect.py | 8 +++ python/libvirt-override.c | 48 ++++++++++++++++++++ src/conf/domain_event.c | 31 +++++++++++++ src/conf/domain_event.h | 2 + src/libvirt_private.syms | 2 + src/qemu/qemu_monitor.c | 12 +++++ src/qemu/qemu_monitor.h | 4 ++ src/qemu/qemu_monitor_json.c | 10 ++++- src/qemu/qemu_process.c | 21 +++++++++ src/remote/remote_driver.c | 32 +++++++++++++ src/remote/remote_protocol.x | 7 +++- src/remote_protocol-structs | 7 ++- 16 files changed, 242 insertions(+), 5 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index cc464fd..548faab 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -537,6 +537,29 @@ static int remoteRelayDomainEventTrayMoved(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } +static int remoteRelayDomainEventWakeup(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + void *opaque) { + virNetServerClientPtr client = opaque; + remote_domain_event_wakeup_msg data; + + if (!client) + return -1; + + VIR_DEBUG("Relaying domain %s %d system wakeup", dom->name, dom->id); + + /* build return data */ + memset(&data, 0, sizeof data); + make_nonnull_domain(&data.dom, dom); + + remoteDispatchDomainEventSend(client, remoteProgram, + REMOTE_PROC_DOMAIN_EVENT_WAKEUP, + (xdrproc_t)xdr_remote_domain_event_wakeup_msg, &data); + + return 0; +} + + static virConnectDomainEventGenericCallback domainEventCallbacks[] = { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot), @@ -549,6 +572,7 @@ static virConnectDomainEventGenericCallback domainEventCallbacks[] = { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockJob), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayMoved), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventWakeup), }; verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST); diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c index c7bcaeb..15cf5b3 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -325,6 +325,15 @@ static int myDomainEventTrayMovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } +static int myDomainEventWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + void *opaque ATTRIBUTE_UNUSED) +{ + printf("%s EVENT: Domain %s(%d) system wakeup", + __func__, virDomainGetName(dom), virDomainGetID(dom)); + return 0; +} + static void myFreeFunc(void *opaque) { char *str = opaque; @@ -361,6 +370,7 @@ int main(int argc, char **argv) int callback8ret = -1; int callback9ret = -1; int callback10ret = -1; + int callback11ret = -1; struct sigaction action_stop; memset(&action_stop, 0, sizeof action_stop); @@ -436,6 +446,11 @@ int main(int argc, char **argv) VIR_DOMAIN_EVENT_ID_TRAY_MOVED, VIR_DOMAIN_EVENT_CALLBACK(myDomainEventTrayMovedCallback), strdup("tray moved"), myFreeFunc); + callback11ret = virConnectDomainEventRegisterAny(dconn, + NULL, + VIR_DOMAIN_EVENT_ID_WAKEUP, + VIR_DOMAIN_EVENT_CALLBACK(myDomainEventWakeupCallback), + strdup("system wakeup"), myFreeFunc); if ((callback1ret != -1) && (callback2ret != -1) && @@ -445,7 +460,8 @@ int main(int argc, char **argv) (callback6ret != -1) && (callback7ret != -1) && (callback9ret != -1) && - (callback10ret != -1)) { + (callback10ret != -1) && + (callback11ret != -1)) { if (virConnectSetKeepAlive(dconn, 5, 3) < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Failed to start keepalive protocol: %s\n", @@ -471,6 +487,7 @@ int main(int argc, char **argv) virConnectDomainEventDeregisterAny(dconn, callback7ret); virConnectDomainEventDeregisterAny(dconn, callback9ret); virConnectDomainEventDeregisterAny(dconn, callback10ret); + virConnectDomainEventDeregisterAny(dconn, callback11ret); if (callback8ret != -1) virConnectDomainEventDeregisterAny(dconn, callback8ret); } diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py index f2f5597..d70ab0a 100644 --- a/examples/domain-events/events-python/event-test.py +++ b/examples/domain-events/events-python/event-test.py @@ -477,6 +477,9 @@ def myDomainEventDiskChangeCallback(conn, dom, oldSrcPath, newSrcPath, devAlias, def myDomainEventTrayMovedCallback(conn, dom, devAlias, trayOpened, opaque): print "myDomainEventTrayMovedCallback: Domain %s(%s) tray moved devAlias: %s trayOpened: %d" % ( dom.name(), dom.ID(), devAlias, trayOpened) +def myDomainEventWakeupCallback(conn, dom, opaque): + print "myDomainEventWakeupCallback: Domain %s(%s) system wakeup" % ( + dom.name(), dom.ID()) def usage(out=sys.stderr): print >>out, "usage: "+os.path.basename(sys.argv[0])+" [-hdl] [uri]" print >>out, " uri will default to qemu:///system" @@ -536,6 +539,7 @@ def main(): vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback, None) vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE, myDomainEventDiskChangeCallback, None) vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_TRAY_MOVED, myDomainEventTrayMovedCallback, None) + vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_WAKEUP, myDomainEventWakeupCallback, None) vc.setKeepAlive(5, 3) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 730f2a3..775a0c7 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -3662,6 +3662,21 @@ typedef void (*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn, unsigned int trayOpened, void *opaque); +/** + * virConnectDomainEventWakeupCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @opaque: application specified data + * + * This callback occurs when the guest is waken up. + * + * The callback signature to use when registering for an event of type + * VIR_DOMAIN_EVENT_ID_WAKEUP with virConnectDomainEventRegisterAny() + */ +typedef void (*virConnectDomainEventWakeupCallback)(virConnectPtr conn, + virDomainPtr dom, + void *opaque); + /** * VIR_DOMAIN_EVENT_CALLBACK: @@ -3684,6 +3699,7 @@ typedef enum { VIR_DOMAIN_EVENT_ID_BLOCK_JOB = 8, /* virConnectDomainEventBlockJobCallback */ VIR_DOMAIN_EVENT_ID_DISK_CHANGE = 9, /* virConnectDomainEventDiskChangeCallback */ VIR_DOMAIN_EVENT_ID_TRAY_MOVED = 10, /* virConnectDomainEventTrayMovedCallback */ + VIR_DOMAIN_EVENT_ID_WAKEUP = 11, /* virConnectDomainEventWakeupCallback */ #ifdef VIR_ENUM_SENTINELS /* diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py index e93efa7..323bb18 100644 --- a/python/libvirt-override-virConnect.py +++ b/python/libvirt-override-virConnect.py @@ -143,6 +143,14 @@ cb(self, virDomain(self, _obj=dom), devAlias, trayOpened, opaque) return 0; + def _dispatchDomainEventWakeupCallback(self, dom, cbData): + """Dispatches event to python user domain wakeup event callbacks + """ + cb = cbData["cb"] + opaque = cbData["opaque"] + + cb(self, virDomain(self, _obj=dom), opaque) + return 0; def domainEventDeregisterAny(self, callbackID): """Removes a Domain Event Callback. De-registering for a diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 976c5d8..3b439a4 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -4974,6 +4974,51 @@ libvirt_virConnectDomainEventTrayMovedCallback(virConnectPtr conn ATTRIBUTE_UNUS return ret; } +static int +libvirt_virConnectDomainEventWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + void *opaque) +{ + PyObject *pyobj_cbData = (PyObject*)opaque; + PyObject *pyobj_dom; + PyObject *pyobj_ret; + PyObject *pyobj_conn; + PyObject *dictKey; + int ret = -1; + + LIBVIRT_ENSURE_THREAD_STATE; + /* Create a python instance of this virDomainPtr */ + virDomainRef(dom); + + pyobj_dom = libvirt_virDomainPtrWrap(dom); + Py_INCREF(pyobj_cbData); + + dictKey = libvirt_constcharPtrWrap("conn"); + pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey); + Py_DECREF(dictKey); + + /* Call the Callback Dispatcher */ + pyobj_ret = PyObject_CallMethod(pyobj_conn, + (char*)"_dispatchDomainEventWakeupCallback", + (char*)"OO", + pyobj_dom, + pyobj_cbData); + + Py_DECREF(pyobj_cbData); + Py_DECREF(pyobj_dom); + + if(!pyobj_ret) { + DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret); + PyErr_Print(); + } else { + Py_DECREF(pyobj_ret); + ret = 0; + } + + LIBVIRT_RELEASE_THREAD_STATE; + return ret; +} + static PyObject * libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) @@ -5037,6 +5082,9 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, case VIR_DOMAIN_EVENT_ID_TRAY_MOVED: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayMovedCallback); break; + case VIR_DOMAIN_EVENT_ID_WAKEUP: + cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWakeupCallback); + break; } if (!cb) { diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index dbd1bf1..956d3c2 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -121,6 +121,9 @@ struct _virDomainEvent { char *devAlias; unsigned int trayOpened :1; } trayMoved; + struct { + int reason; + } wakeup; } data; }; @@ -1094,6 +1097,30 @@ virDomainEventPtr virDomainEventTrayMovedNewFromDom(virDomainPtr dom, devAlias, trayOpened); } +static virDomainEventPtr +virDomainEventWakeupNew(int id, const char *name, + unsigned char *uuid) +{ + virDomainEventPtr ev = + virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_WAKEUP, + id, name, uuid); + return ev; +} + +virDomainEventPtr +virDomainEventWakeupNewFromObj(virDomainObjPtr obj) +{ + return virDomainEventWakeupNew(obj->def->id, + obj->def->name, + obj->def->uuid); +} + +virDomainEventPtr +virDomainEventWakeupNewFromDom(virDomainPtr dom) +{ + return virDomainEventWakeupNew(dom->id, dom->name, dom->uuid); +} + /** * virDomainEventQueuePush: @@ -1225,6 +1252,10 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, cbopaque); break; + case VIR_DOMAIN_EVENT_ID_WAKEUP: + (cb)(conn, dom, cbopaque); + break; + default: VIR_WARN("Unexpected event ID %d", event->eventID); break; diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index 3351be0..51b6570 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -120,6 +120,8 @@ virDomainEventPtr virDomainEventTrayMovedNewFromObj(virDomainObjPtr obj, virDomainEventPtr virDomainEventTrayMovedNewFromDom(virDomainPtr dom, const char *devAlias, unsigned int trayOpened); +virDomainEventPtr virDomainEventWakeupNewFromObj(virDomainObjPtr obj); +virDomainEventPtr virDomainEventWakeupNewFromDom(virDomainPtr dom); void virDomainEventFree(virDomainEventPtr event); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 27d4ad3..e2e34ca 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -512,6 +512,8 @@ virDomainEventStateRegisterID; virDomainEventStateFree; virDomainEventStateNew; virDomainEventStateQueue; +virDomainEventWakeupNewFromDom; +virDomainEventWakeupNewFromObj; virDomainEventTrayMovedNewFromDom; virDomainEventTrayMovedNewFromObj; virDomainEventWatchdogNewFromDom; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index dfa2960..bf51bdd 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1053,6 +1053,18 @@ int qemuMonitorEmitTrayMoved(qemuMonitorPtr mon, return ret; } +int +qemuMonitorEmitWakeup(qemuMonitorPtr mon) + +{ + int ret = -1; + VIR_DEBUG("mon=%p", mon); + + QEMU_MONITOR_CALLBACK(mon, ret, domainWakeup, mon->vm); + + return ret; +} + int qemuMonitorEmitBlockJob(qemuMonitorPtr mon, const char *diskAlias, int type, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 18e6801..08f1d7a 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -128,6 +128,9 @@ struct _qemuMonitorCallbacks { virDomainObjPtr vm, const char *devAlias, unsigned int trayOpened); + int (*domainWakeup)(qemuMonitorPtr mon, + virDomainObjPtr vm); + }; @@ -198,6 +201,7 @@ int qemuMonitorEmitGraphics(qemuMonitorPtr mon, int qemuMonitorEmitTrayMoved(qemuMonitorPtr mon, const char *devAlias, unsigned int trayOpened); +int qemuMonitorEmitWakeup(qemuMonitorPtr mon); int qemuMonitorEmitBlockJob(qemuMonitorPtr mon, const char *diskAlias, int type, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ac6b02c..19cda44 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -60,6 +60,7 @@ static void qemuMonitorJSONHandleVNCInitialize(qemuMonitorPtr mon, virJSONValueP static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleBlockJob(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleTrayMoved(qemuMonitorPtr mon, virJSONValuePtr data); +static void qemuMonitorJSONHandleWakeup(qemuMonitorPtr mon, virJSONValuePtr data); static struct { const char *type; @@ -77,6 +78,7 @@ static struct { { "VNC_DISCONNECTED", qemuMonitorJSONHandleVNCDisconnect, }, { "BLOCK_JOB_COMPLETED", qemuMonitorJSONHandleBlockJob, }, { "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayMoved, }, + { "WAKEUP", qemuMonitorJSONHandleWakeup, }, }; @@ -582,7 +584,6 @@ VIR_ENUM_DECL(qemuMonitorIOErrorAction) VIR_ENUM_IMPL(qemuMonitorIOErrorAction, VIR_DOMAIN_EVENT_IO_ERROR_LAST, "ignore", "stop", "report"); - static void qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, virJSONValuePtr data) { const char *device; @@ -744,6 +745,13 @@ static void qemuMonitorJSONHandleTrayMoved(qemuMonitorPtr mon, virJSONValuePtr d qemuMonitorEmitTrayMoved(mon, devAlias, (unsigned int)trayOpened); } +static void +qemuMonitorJSONHandleWakeup(qemuMonitorPtr mon, + virJSONValuePtr data ATTRIBUTE_UNUSED) +{ + qemuMonitorEmitWakeup(mon); +} + int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon, const char *cmd_str, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a75209d..de173bd 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1058,6 +1058,26 @@ qemuProcessHandleTrayMoved(qemuMonitorPtr mon ATTRIBUTE_UNUSED, return 0; } +static int +qemuProcessHandleWakeup(qemuMonitorPtr mon ATTRIBUTE_UNUSED, + virDomainObjPtr vm) +{ + struct qemud_driver *driver = qemu_driver; + virDomainEventPtr event = NULL; + + virDomainObjLock(vm); + event = virDomainEventWakeupNewFromObj(vm); + + virDomainObjUnlock(vm); + + if (event) { + qemuDriverLock(driver); + qemuDomainEventQueue(driver, event); + qemuDriverUnlock(driver); + } + + return 0; +} static qemuMonitorCallbacks monitorCallbacks = { .destroy = qemuProcessHandleMonitorDestroy, @@ -1073,6 +1093,7 @@ static qemuMonitorCallbacks monitorCallbacks = { .domainGraphics = qemuProcessHandleGraphics, .domainBlockJob = qemuProcessHandleBlockJob, .domainTrayMoved = qemuProcessHandleTrayMoved, + .domainWakeup = qemuProcessHandleWakeup, }; static int diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 31d09a9..dd68738 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -243,6 +243,11 @@ remoteDomainBuildEventTrayMoved(virNetClientProgramPtr prog, virNetClientPtr client, void *evdata, void *opaque); +static void +remoteDomainBuildEventWakeup(virNetClientProgramPtr prog, + virNetClientPtr client, + void *evdata, void *opaque); + static virNetClientProgramEvent remoteDomainEvents[] = { { REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE, remoteDomainBuildEventRTCChange, @@ -288,6 +293,10 @@ static virNetClientProgramEvent remoteDomainEvents[] = { remoteDomainBuildEventTrayMoved, sizeof(remote_domain_event_tray_moved_msg), (xdrproc_t)xdr_remote_domain_event_tray_moved_msg }, + { REMOTE_PROC_DOMAIN_EVENT_WAKEUP, + remoteDomainBuildEventWakeup, + sizeof(remote_domain_event_wakeup_msg), + (xdrproc_t)xdr_remote_domain_event_wakeup_msg }, }; enum virDrvOpenRemoteFlags { @@ -3677,6 +3686,29 @@ remoteDomainBuildEventTrayMoved(virNetClientProgramPtr prog ATTRIBUTE_UNUSED, } +static void +remoteDomainBuildEventWakeup(virNetClientProgramPtr prog ATTRIBUTE_UNUSED, + virNetClientPtr client ATTRIBUTE_UNUSED, + void *evdata, void *opaque) +{ + virConnectPtr conn = opaque; + struct private_data *priv = conn->privateData; + remote_domain_event_wakeup_msg *msg = evdata; + virDomainPtr dom; + virDomainEventPtr event = NULL; + + dom = get_nonnull_domain(conn, msg->dom); + if (!dom) + return; + + event = virDomainEventWakeupNewFromDom(dom); + + virDomainFree(dom); + + remoteDomainEventQueue(priv, event); +} + + static virDrvOpenStatus ATTRIBUTE_NONNULL (1) remoteSecretOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 73e554c..5695fa2 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2184,6 +2184,10 @@ struct remote_domain_event_tray_moved_msg { unsigned int trayOpened; }; +struct remote_domain_event_wakeup_msg { + remote_nonnull_domain dom; +}; + struct remote_domain_managed_save_args { remote_nonnull_domain dom; unsigned int flags; @@ -2772,7 +2776,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_METADATA = 265, /* autogen autogen */ REMOTE_PROC_DOMAIN_BLOCK_REBASE = 266, /* autogen autogen */ REMOTE_PROC_DOMAIN_PM_WAKEUP = 267, /* autogen autogen */ - REMOTE_PROC_DOMAIN_EVENT_TRAY_MOVED = 268 /* autogen autogen */ + REMOTE_PROC_DOMAIN_EVENT_TRAY_MOVED = 268, /* autogen autogen */ + REMOTE_PROC_DOMAIN_EVENT_WAKEUP = 269 /* autogen autogen */ /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index aad8654..2911610 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1653,8 +1653,11 @@ struct remote_domain_event_disk_change_msg { struct remote_domain_event_tray_moved_msg { remote_nonnull_domain dom; remote_nonnull_string devAlias; - U_int trayOpened; -} + u_int trayOpened; +}; +struct remote_domain_event_wakeup_msg { + remote_nonnull_domain dom; +}; struct remote_domain_managed_save_args { remote_nonnull_domain dom; u_int flags; -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list