diff --git a/daemon/remote.c b/daemon/remote.c index 284e47cf8bf9961e4c2add281a7c20deb7ffcea8..61079b17c614047a5cf56aebdb0acac80fafb55a 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -157,9 +157,40 @@ static int remoteRelayDomainEventReboot(virConnectPtr conn ATTRIBUTE_UNUSED, } +static int remoteRelayDomainEventRTCChange(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + long long offset, + void *opaque) +{ + struct qemud_client *client = opaque; + remote_domain_event_rtc_change_msg data; + + if (!client) + return -1; + + REMOTE_DEBUG("Relaying domain rtc change event %s %d %lld", dom->name, dom->id, offset); + + virMutexLock(&client->lock); + + /* build return data */ + memset(&data, 0, sizeof data); + make_nonnull_domain (&data.dom, dom); + data.offset = offset; + + remoteDispatchDomainEventSend (client, + REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE, + (xdrproc_t)xdr_remote_domain_event_rtc_change_msg, &data); + + virMutexUnlock(&client->lock); + + return 0; +} + + static virConnectDomainEventGenericCallback domainEventCallbacks[] = { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventRTCChange), }; verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST); diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h index 13a853cd5eaca3bc29982143e24e460d952fde29..13e407e696020258dbe3e1716cc51919ff776878 100644 --- a/daemon/remote_dispatch_table.h +++ b/daemon/remote_dispatch_table.h @@ -852,3 +852,8 @@ .args_filter = (xdrproc_t) xdr_void, .ret_filter = (xdrproc_t) xdr_void, }, +{ /* Async event DomainEventRtcChange => 170 */ + .fn = NULL, + .args_filter = (xdrproc_t) xdr_void, + .ret_filter = (xdrproc_t) xdr_void, +}, diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c index c7da0c0fe8be9158412b51485130cdb258481910..97b37def7e20ee99ba000f93ee14978a012b9ee3 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -182,6 +182,17 @@ static int myDomainEventRebootCallback(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } +static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + long long offset, + void *opaque ATTRIBUTE_UNUSED) +{ + printf("%s EVENT: Domain %s(%d) rtc change %lld\n", __func__, virDomainGetName(dom), + virDomainGetID(dom), offset); + + return 0; +} + static void myFreeFunc(void *opaque) { char *str = opaque; @@ -300,6 +311,7 @@ int main(int argc, char **argv) int callback1ret = -1; int callback2ret = -1; int callback3ret = -1; + int callback4ret = -1; struct sigaction action_stop = { .sa_handler = stop @@ -342,10 +354,16 @@ int main(int argc, char **argv) VIR_DOMAIN_EVENT_ID_REBOOT, VIR_DOMAIN_EVENT_CALLBACK(myDomainEventRebootCallback), strdup("callback reboot"), myFreeFunc); + callback4ret = virConnectDomainEventRegisterAny(dconn, + NULL, + VIR_DOMAIN_EVENT_ID_RTC_CHANGE, + VIR_DOMAIN_EVENT_CALLBACK(myDomainEventRTCChangeCallback), + strdup("callback rtcchange"), myFreeFunc); if ((callback1ret != -1) && (callback2ret != -1) && - (callback3ret != -1)) { + (callback3ret != -1) && + (callback4ret != -1)) { while(run) { struct pollfd pfd = { .fd = h_fd, .events = h_event, @@ -384,6 +402,7 @@ int main(int argc, char **argv) virConnectDomainEventDeregister(dconn, myDomainEventCallback1); virConnectDomainEventDeregisterAny(dconn, callback2ret); virConnectDomainEventDeregisterAny(dconn, callback3ret); + virConnectDomainEventDeregisterAny(dconn, callback4ret); } diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 39970da4b17b0b9b09b45d84851662b09da989ef..aed1b72a397ee37dbd011a7985bcab8aacee52ec 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1863,6 +1863,21 @@ typedef void (*virConnectDomainEventGenericCallback)(virConnectPtr conn, virDomainPtr dom, void *opaque); +/** + * virConnectDomainEventRTCChangeCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @utcoffset: the new RTC offset from UTC, measured in seconds + * @opaque: application specified data + * + * The callback signature to use when registering for an event of type + * VIR_DOMAIN_EVENT_ID_RTC_CHANGE with virConnectDomainEventRegisterAny() + */ +typedef void (*virConnectDomainEventRTCChangeCallback)(virConnectPtr conn, + virDomainPtr dom, + long long utcoffset, + void *opaque); + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -1875,6 +1890,7 @@ typedef void (*virConnectDomainEventGenericCallback)(virConnectPtr conn, typedef enum { VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0, /* virConnectDomainEventCallback */ VIR_DOMAIN_EVENT_ID_REBOOT = 1, /* virConnectDomainEventGenericCallback */ + VIR_DOMAIN_EVENT_ID_RTC_CHANGE = 2, /* virConnectDomainEventRTCChangeCallback */ /* * NB: this enum value will increase over time as new events are diff --git a/python/generator.py b/python/generator.py index d8a44c76f51f4caa7baaabed17b2d6f49334cd87..1446924b5d54f1d912e0ee7b2d1adb3a67ff0bfd 100755 --- a/python/generator.py +++ b/python/generator.py @@ -170,6 +170,7 @@ skipped_types = { # 'int *': "usually a return type", 'virConnectDomainEventCallback': "No function types in python", 'virConnectDomainEventGenericCallback': "No function types in python", + 'virConnectDomainEventRTCChangeCallback': "No function types in python", 'virEventAddHandleFunc': "No function types in python", } diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 57fd8516518780218491115ced4ca97f17657ff0..ee6691e3cb1fd59a176f0d679768a52f582b9ba9 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -64,6 +64,9 @@ struct _virDomainEvent { int type; int detail; } lifecycle; + struct { + long long offset; + } rtcChange; } data; }; @@ -534,6 +537,31 @@ virDomainEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj) obj->def->id, obj->def->name, obj->def->uuid); } +virDomainEventPtr virDomainEventRTCChangeNewFromDom(virDomainPtr dom, + long long offset) +{ + virDomainEventPtr ev = + virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_RTC_CHANGE, + dom->id, dom->name, dom->uuid); + + if (ev) + ev->data.rtcChange.offset = offset; + + return ev; +} +virDomainEventPtr virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, + long long offset) +{ + virDomainEventPtr ev = + virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_RTC_CHANGE, + obj->def->id, obj->def->name, obj->def->uuid); + + if (ev) + ev->data.rtcChange.offset = offset; + + return ev; +} + /** * virDomainEventQueueFree: * @queue: pointer to the queue @@ -644,6 +672,12 @@ void virDomainEventDispatchDefaultFunc(virConnectPtr conn, cbopaque); break; + case VIR_DOMAIN_EVENT_ID_RTC_CHANGE: + ((virConnectDomainEventRTCChangeCallback)cb)(conn, dom, + event->data.rtcChange.offset, + 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 7fb0928d27b51867b5980003d86b9ee1e3e449c7..1024d02b5211253a49acfa3771b3db5242f8cad3 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -115,6 +115,9 @@ virDomainEventPtr virDomainEventNewFromDef(virDomainDefPtr def, int type, int de virDomainEventPtr virDomainEventRebootNewFromDom(virDomainPtr dom); virDomainEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj); +virDomainEventPtr virDomainEventRTCChangeNewFromDom(virDomainPtr dom, long long offset); +virDomainEventPtr virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, long long offset); + int virDomainEventQueuePush(virDomainEventQueuePtr evtQueue, virDomainEventPtr event); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 471ea1b41af6bffefb972c3ab97bd04f3cdac3f1..e42410ffd292428b6849f96fbe439172bbf5a983 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -216,6 +216,8 @@ virDomainEventNewFromObj; virDomainEventNewFromDef; virDomainEventRebootNewFromDom; virDomainEventRebootNewFromObj; +virDomainEventRTCChangeNewFromDom; +virDomainEventRTCChangeNewFromObj; virDomainEventFree; virDomainEventDispatchDefaultFunc; virDomainEventDispatch; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6ab170a7771204288b615dcf9893a9a330940c5c..286b6693a144eb125cc6bbb0dcd514c33a5f2cac 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -886,10 +886,40 @@ qemuHandleDomainReset(qemuMonitorPtr mon ATTRIBUTE_UNUSED, } +static int +qemuHandleDomainRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, + virDomainObjPtr vm, + long long offset) +{ + struct qemud_driver *driver = qemu_driver; + virDomainEventPtr event; + + virDomainObjLock(vm); + event = virDomainEventRTCChangeNewFromObj(vm, offset); + + if (vm->def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) + vm->def->clock.data.adjustment = offset; + + if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + VIR_WARN0("unable to save domain status with RTC change"); + + virDomainObjUnlock(vm); + + if (event) { + qemuDriverLock(driver); + qemuDomainEventQueue(driver, event); + qemuDriverUnlock(driver); + } + + return 0; +} + + static qemuMonitorCallbacks monitorCallbacks = { .eofNotify = qemuHandleMonitorEOF, .diskSecretLookup = findVolumeQcowPassphrase, .domainReset = qemuHandleDomainReset, + .domainRTCChange = qemuHandleDomainRTCChange, }; static int diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 6b68db83071b7fb636adaf3cf46b20b8a4aebd6a..69b2dc38b9609a25d24f0f558cd8e02def816f0d 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -791,6 +791,21 @@ int qemuMonitorEmitStop(qemuMonitorPtr mon) } +int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset) +{ + int ret = -1; + VIR_DEBUG("mon=%p", mon); + + qemuMonitorRef(mon); + qemuMonitorUnlock(mon); + if (mon->cb && mon->cb->domainRTCChange) + ret = mon->cb->domainRTCChange(mon, mon->vm, offset); + qemuMonitorLock(mon); + qemuMonitorUnref(mon); + return ret; +} + + int qemuMonitorSetCapabilities(qemuMonitorPtr mon) { int ret; diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2557fb9ec439db8822527f9bc65a4e3e6bba15fa..46252ca6c798886822f3e0a5681f96b865545139 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -86,6 +86,9 @@ struct _qemuMonitorCallbacks { virDomainObjPtr vm); int (*domainStop)(qemuMonitorPtr mon, virDomainObjPtr vm); + int (*domainRTCChange)(qemuMonitorPtr mon, + virDomainObjPtr vm, + long long offset); }; @@ -122,6 +125,7 @@ int qemuMonitorEmitShutdown(qemuMonitorPtr mon); int qemuMonitorEmitReset(qemuMonitorPtr mon); int qemuMonitorEmitPowerdown(qemuMonitorPtr mon); int qemuMonitorEmitStop(qemuMonitorPtr mon); +int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset); int qemuMonitorStartCPUs(qemuMonitorPtr mon, virConnectPtr conn); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 4ae8093b7e758518c83f6dbb695b7976f1d5aefa..55f8431132583ab74c5549a101e6bf2b64654765 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -49,6 +49,7 @@ static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr da static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandlePowerdown(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleStop(qemuMonitorPtr mon, virJSONValuePtr data); +static void qemuMonitorJSONHandleRTCChange(qemuMonitorPtr mon, virJSONValuePtr data); struct { const char *type; @@ -58,6 +59,7 @@ struct { { "RESET", qemuMonitorJSONHandleReset, }, { "POWERDOWN", qemuMonitorJSONHandlePowerdown, }, { "STOP", qemuMonitorJSONHandleStop, }, + { "RTC_CHANGE", qemuMonitorJSONHandleRTCChange, }, }; @@ -495,6 +497,16 @@ static void qemuMonitorJSONHandleStop(qemuMonitorPtr mon, virJSONValuePtr data A qemuMonitorEmitStop(mon); } +static void qemuMonitorJSONHandleRTCChange(qemuMonitorPtr mon, virJSONValuePtr data) +{ + long long offset = 0; + if (virJSONValueObjectGetNumberLong(data, "offset", &offset) < 0) { + VIR_WARN0("missing offset in RTC change event"); + offset = 0; + } + qemuMonitorEmitRTCChange(mon, offset); +} + int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 17d61138d65b58abeb1601118f44d41b5b83a839..baa3118ab6749270a9abe1bede0f8b09e041524e 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -6940,6 +6940,33 @@ remoteDomainReadEventReboot(virConnectPtr conn, XDR *xdr) } +static virDomainEventPtr +remoteDomainReadEventRTCChange(virConnectPtr conn, XDR *xdr) +{ + remote_domain_event_rtc_change_msg msg; + virDomainPtr dom; + virDomainEventPtr event = NULL; + memset (&msg, 0, sizeof msg); + + /* unmarshall parameters, and process it*/ + if (! xdr_remote_domain_event_rtc_change_msg(xdr, &msg) ) { + error (conn, VIR_ERR_RPC, + _("unable to demarshall reboot event")); + return NULL; + } + + dom = get_nonnull_domain(conn,msg.dom); + if (!dom) + return NULL; + + event = virDomainEventRTCChangeNewFromDom(dom, msg.offset); + xdr_free ((xdrproc_t) &xdr_remote_domain_event_rtc_change_msg, (char *) &msg); + + virDomainFree(dom); + return event; +} + + static virDrvOpenStatus ATTRIBUTE_NONNULL (1) remoteSecretOpen (virConnectPtr conn, virConnectAuthPtr auth, @@ -8487,6 +8514,10 @@ processCallDispatchMessage(virConnectPtr conn, struct private_data *priv, event = remoteDomainReadEventReboot(conn, xdr); break; + case REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE: + event = remoteDomainReadEventRTCChange(conn, xdr); + break; + default: DEBUG("Unexpected event proc %d", hdr->proc); break; diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c index af56c259e447f889206dbbf27623ba45ee407e52..c22a72cd2ed33c94d31006a269d6d35372fefce2 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -3059,6 +3059,17 @@ xdr_remote_domain_event_reboot_msg (XDR *xdrs, remote_domain_event_reboot_msg *o return TRUE; } +bool_t +xdr_remote_domain_event_rtc_change_msg (XDR *xdrs, remote_domain_event_rtc_change_msg *objp) +{ + + if (!xdr_remote_nonnull_domain (xdrs, &objp->dom)) + return FALSE; + if (!xdr_int64_t (xdrs, &objp->offset)) + return FALSE; + return TRUE; +} + bool_t xdr_remote_procedure (XDR *xdrs, remote_procedure *objp) { diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h index 8266294f8b7d028aa0a06c7a4c130044925abeb7..27aac5e756c57b02e3b715cfe0b0dfa957c998cb 100644 --- a/src/remote/remote_protocol.h +++ b/src/remote/remote_protocol.h @@ -1732,6 +1732,12 @@ struct remote_domain_event_reboot_msg { remote_nonnull_domain dom; }; typedef struct remote_domain_event_reboot_msg remote_domain_event_reboot_msg; + +struct remote_domain_event_rtc_change_msg { + remote_nonnull_domain dom; + int64_t offset; +}; +typedef struct remote_domain_event_rtc_change_msg remote_domain_event_rtc_change_msg; #define REMOTE_PROGRAM 0x20008086 #define REMOTE_PROTOCOL_VERSION 1 @@ -1905,6 +1911,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY = 167, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 168, REMOTE_PROC_DOMAIN_EVENT_REBOOT = 169, + REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE = 170, }; typedef enum remote_procedure remote_procedure; @@ -2219,6 +2226,7 @@ extern bool_t xdr_remote_domain_migrate_set_max_downtime_args (XDR *, remote_do extern bool_t xdr_remote_domain_events_register_any_args (XDR *, remote_domain_events_register_any_args*); extern bool_t xdr_remote_domain_events_deregister_any_args (XDR *, remote_domain_events_deregister_any_args*); extern bool_t xdr_remote_domain_event_reboot_msg (XDR *, remote_domain_event_reboot_msg*); +extern bool_t xdr_remote_domain_event_rtc_change_msg (XDR *, remote_domain_event_rtc_change_msg*); extern bool_t xdr_remote_procedure (XDR *, remote_procedure*); extern bool_t xdr_remote_message_type (XDR *, remote_message_type*); extern bool_t xdr_remote_message_status (XDR *, remote_message_status*); @@ -2507,6 +2515,7 @@ extern bool_t xdr_remote_domain_migrate_set_max_downtime_args (); extern bool_t xdr_remote_domain_events_register_any_args (); extern bool_t xdr_remote_domain_events_deregister_any_args (); extern bool_t xdr_remote_domain_event_reboot_msg (); +extern bool_t xdr_remote_domain_event_rtc_change_msg (); extern bool_t xdr_remote_procedure (); extern bool_t xdr_remote_message_type (); extern bool_t xdr_remote_message_status (); diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 0419e7b32622f6bf61380c455765e3c3762466e7..7d45c7094f0f4a2ba14509ce6468f091cd248174 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1540,6 +1540,11 @@ struct remote_domain_event_reboot_msg { remote_nonnull_domain dom; }; +struct remote_domain_event_rtc_change_msg { + remote_nonnull_domain dom; + hyper offset; +}; + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -1731,7 +1736,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_DOWNTIME = 166, REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY = 167, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 168, - REMOTE_PROC_DOMAIN_EVENT_REBOOT = 169 + REMOTE_PROC_DOMAIN_EVENT_REBOOT = 169, + REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE = 170 /* * Notice how the entries are grouped in sets of 10 ?