This introduces a new event type VIR_DOMAIN_EVENT_ID_RTC_CHANGE This event includes the new UTC offset measured in seconds. Thus there is a new callback definition for this event type typedef void (*virConnectDomainEventRTCChangeCallback)(virConnectPtr conn, virDomainPtr dom, long long utcoffset, void *opaque); If the guest XML configuration for the <clock> is set to offset='variable', then the XML will automatically be updated with the new UTC offset value. This ensures that during migration/save/restore the new offset is preserved. * daemon/remote.c: Dispatch RTC change events to client * examples/domain-events/events-c/event-test.c: Watch for RTC change events * include/libvirt/libvirt.h.in: Define new RTC change event ID and callback signature * src/conf/domain_event.c, src/conf/domain_event.h, src/libvirt_private.syms: Extend API to handle RTC change events * src/qemu/qemu_driver.c: Connect to the QEMU monitor event for RTC changes and emit a libvirt RTC change event * src/remote/remote_driver.c: Receive and dispatch RTC change events to application * src/remote/remote_protocol.x: Wire protocol definition for RTC change events * src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h, src/qemu/qemu_monitor_json.c: Watch for RTC_CHANGE event from QEMU monitor --- daemon/remote.c | 31 +++++++++++++++++++++++ daemon/remote_dispatch_table.h | 5 ++++ examples/domain-events/events-c/event-test.c | 21 +++++++++++++++- include/libvirt/libvirt.h.in | 5 ++++ src/conf/domain_event.c | 34 ++++++++++++++++++++++++++ src/conf/domain_event.h | 3 ++ src/libvirt_private.syms | 2 + src/qemu/qemu_driver.c | 30 ++++++++++++++++++++++ src/qemu/qemu_monitor.c | 15 +++++++++++ src/qemu/qemu_monitor.h | 4 +++ src/qemu/qemu_monitor_json.c | 12 +++++++++ src/remote/remote_driver.c | 31 +++++++++++++++++++++++ src/remote/remote_protocol.c | 11 ++++++++ src/remote/remote_protocol.h | 9 +++++++ src/remote/remote_protocol.x | 8 +++++- 15 files changed, 219 insertions(+), 2 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index f86c102..ac62f43 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 990e95c..e5cc724 100644 --- a/daemon/remote_dispatch_table.h +++ b/daemon/remote_dispatch_table.h @@ -842,3 +842,8 @@ .args_filter = (xdrproc_t) xdr_void, .ret_filter = (xdrproc_t) xdr_void, }, +{ /* Async event DomainEventRtcChange => 168 */ + .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 c7da0c0..97b37de 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 4b55ded..edb0a6e 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1842,6 +1842,10 @@ int virDomainAbortJob(virDomainPtr dom); typedef void (*virConnectDomainEventGenericCallback)(virConnectPtr conn, virDomainPtr dom, void *opaque); +typedef void (*virConnectDomainEventRTCChangeCallback)(virConnectPtr conn, + virDomainPtr dom, + long long utcoffset, + void *opaque); /* Use this to cast the event specific callback into the generic one * for use for virDomainEventRegister */ @@ -1851,6 +1855,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/src/conf/domain_event.c b/src/conf/domain_event.c index bc16d97..79dfbac 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 d9c950d..8517ffe 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 38dc0a4..582a98e 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 9dfc77e..a5cf246 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -877,10 +877,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 acc841b..c0e2384 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 cfb76b6..86d6b87 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 7a263cb..ce7796a 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 1a64749..afaa26c 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -6914,6 +6914,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, @@ -8431,6 +8458,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 f2a59c7..f78bea0 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -3036,6 +3036,17 @@ xdr_remote_domain_event_reboot_msg (XDR *xdrs, remote_domain_event_reboot_msg *o } 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_uint64_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 900a8b8..4afd5f3 100644 --- a/src/remote/remote_protocol.h +++ b/src/remote/remote_protocol.h @@ -1719,6 +1719,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; + uint64_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 @@ -1890,6 +1896,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY = 165, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 166, REMOTE_PROC_DOMAIN_EVENT_REBOOT = 167, + REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE = 168, }; typedef enum remote_procedure remote_procedure; @@ -2202,6 +2209,7 @@ extern bool_t xdr_remote_domain_abort_job_args (XDR *, remote_domain_abort_job_ 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*); @@ -2488,6 +2496,7 @@ extern bool_t xdr_remote_domain_abort_job_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 72fe5b3..0e0d59a 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1529,6 +1529,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. */ @@ -1718,7 +1723,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_ABORT_JOB = 164, REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY = 165, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 166, - REMOTE_PROC_DOMAIN_EVENT_REBOOT = 167 + REMOTE_PROC_DOMAIN_EVENT_REBOOT = 167, + REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE = 168 /* * Notice how the entries are grouped in sets of 10 ? -- 1.6.6.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list