diff --git a/daemon/remote.c b/daemon/remote.c index 61079b17c6..4bc7a45fc6 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -187,10 +187,41 @@ static int remoteRelayDomainEventRTCChange(virConnectPtr conn ATTRIBUTE_UNUSED, } +static int remoteRelayDomainEventWatchdog(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + int action, + void *opaque) +{ + struct qemud_client *client = opaque; + remote_domain_event_watchdog_msg data; + + if (!client) + return -1; + + REMOTE_DEBUG("Relaying domain watchdog event %s %d %d", dom->name, dom->id, action); + + virMutexLock(&client->lock); + + /* build return data */ + memset(&data, 0, sizeof data); + make_nonnull_domain (&data.dom, dom); + data.action = action; + + remoteDispatchDomainEventSend (client, + REMOTE_PROC_DOMAIN_EVENT_WATCHDOG, + (xdrproc_t)xdr_remote_domain_event_watchdog_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), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventWatchdog), }; verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST); diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h index 13e407e696..a0a74fe711 100644 --- a/daemon/remote_dispatch_table.h +++ b/daemon/remote_dispatch_table.h @@ -857,3 +857,8 @@ .args_filter = (xdrproc_t) xdr_void, .ret_filter = (xdrproc_t) xdr_void, }, +{ /* Async event DomainEventWatchdog => 171 */ + .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 97b37def7e..997af63e9f 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -193,6 +193,17 @@ static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } +static int myDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + int action, + void *opaque ATTRIBUTE_UNUSED) +{ + printf("%s EVENT: Domain %s(%d) watchdog action=%d\n", __func__, virDomainGetName(dom), + virDomainGetID(dom), action); + + return 0; +} + static void myFreeFunc(void *opaque) { char *str = opaque; @@ -312,6 +323,7 @@ int main(int argc, char **argv) int callback2ret = -1; int callback3ret = -1; int callback4ret = -1; + int callback5ret = -1; struct sigaction action_stop = { .sa_handler = stop @@ -359,11 +371,17 @@ int main(int argc, char **argv) VIR_DOMAIN_EVENT_ID_RTC_CHANGE, VIR_DOMAIN_EVENT_CALLBACK(myDomainEventRTCChangeCallback), strdup("callback rtcchange"), myFreeFunc); + callback5ret = virConnectDomainEventRegisterAny(dconn, + NULL, + VIR_DOMAIN_EVENT_ID_WATCHDOG, + VIR_DOMAIN_EVENT_CALLBACK(myDomainEventWatchdogCallback), + strdup("callback watchdog"), myFreeFunc); if ((callback1ret != -1) && (callback2ret != -1) && (callback3ret != -1) && - (callback4ret != -1)) { + (callback4ret != -1) && + (callback5ret != -1)) { while(run) { struct pollfd pfd = { .fd = h_fd, .events = h_event, @@ -403,7 +421,7 @@ int main(int argc, char **argv) virConnectDomainEventDeregisterAny(dconn, callback2ret); virConnectDomainEventDeregisterAny(dconn, callback3ret); virConnectDomainEventDeregisterAny(dconn, callback4ret); - + virConnectDomainEventDeregisterAny(dconn, callback5ret); } DEBUG0("Closing connection"); diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index aed1b72a39..dace68fe3f 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1878,6 +1878,36 @@ typedef void (*virConnectDomainEventRTCChangeCallback)(virConnectPtr conn, long long utcoffset, void *opaque); +/** + * virDomainEventWatchdogAction: + * + * The action that is to be taken due to the watchdog device firing + */ +typedef enum { + VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0, /* No action, watchdog ignored */ + VIR_DOMAIN_EVENT_WATCHDOG_PAUSE, /* Guest CPUs are paused */ + VIR_DOMAIN_EVENT_WATCHDOG_RESET, /* Guest CPUs are reset */ + VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF, /* Guest is forcably powered off */ + VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN, /* Guest is requested to gracefully shutdown */ + VIR_DOMAIN_EVENT_WATCHDOG_DEBUG, /* No action, a debug message logged */ +} virDomainEventWatchdogAction; + +/** + * virConnectDomainEventWatchdogCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @action: action that is to be taken due to watchdog firing + * @opaque: application specified data + * + * The callback signature to use when registering for an event of type + * VIR_DOMAIN_EVENT_ID_WATCHDOG with virConnectDomainEventRegisterAny() + * + */ +typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn, + virDomainPtr dom, + int action, + void *opaque); + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -1891,6 +1921,7 @@ typedef enum { VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0, /* virConnectDomainEventCallback */ VIR_DOMAIN_EVENT_ID_REBOOT = 1, /* virConnectDomainEventGenericCallback */ VIR_DOMAIN_EVENT_ID_RTC_CHANGE = 2, /* virConnectDomainEventRTCChangeCallback */ + VIR_DOMAIN_EVENT_ID_WATCHDOG = 3, /* virConnectDomainEventWatchdogCallback */ /* * NB: this enum value will increase over time as new events are diff --git a/python/generator.py b/python/generator.py index 1446924b5d..95884464b4 100755 --- a/python/generator.py +++ b/python/generator.py @@ -171,6 +171,7 @@ skipped_types = { 'virConnectDomainEventCallback': "No function types in python", 'virConnectDomainEventGenericCallback': "No function types in python", 'virConnectDomainEventRTCChangeCallback': "No function types in python", + 'virConnectDomainEventWatchdogCallback': "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 ee6691e3cb..8e4678d96d 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -67,6 +67,9 @@ struct _virDomainEvent { struct { long long offset; } rtcChange; + struct { + int action; + } watchdog; } data; }; @@ -562,6 +565,31 @@ virDomainEventPtr virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, return ev; } +virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom, + int action) +{ + virDomainEventPtr ev = + virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_WATCHDOG, + dom->id, dom->name, dom->uuid); + + if (ev) + ev->data.watchdog.action = action; + + return ev; +} +virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, + int action) +{ + virDomainEventPtr ev = + virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_WATCHDOG, + obj->def->id, obj->def->name, obj->def->uuid); + + if (ev) + ev->data.watchdog.action = action; + + return ev; +} + /** * virDomainEventQueueFree: * @queue: pointer to the queue @@ -678,6 +706,12 @@ void virDomainEventDispatchDefaultFunc(virConnectPtr conn, cbopaque); break; + case VIR_DOMAIN_EVENT_ID_WATCHDOG: + ((virConnectDomainEventWatchdogCallback)cb)(conn, dom, + event->data.watchdog.action, + 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 1024d02b52..8f6a764c58 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -118,6 +118,9 @@ virDomainEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj); virDomainEventPtr virDomainEventRTCChangeNewFromDom(virDomainPtr dom, long long offset); virDomainEventPtr virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, long long offset); +virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action); +virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int action); + int virDomainEventQueuePush(virDomainEventQueuePtr evtQueue, virDomainEventPtr event); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e42410ffd2..ebe029b6be 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -218,6 +218,8 @@ virDomainEventRebootNewFromDom; virDomainEventRebootNewFromObj; virDomainEventRTCChangeNewFromDom; virDomainEventRTCChangeNewFromObj; +virDomainEventWatchdogNewFromDom; +virDomainEventWatchdogNewFromObj; virDomainEventFree; virDomainEventDispatchDefaultFunc; virDomainEventDispatch; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 286b6693a1..9e6d7470a2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -915,11 +915,34 @@ qemuHandleDomainRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, } +static int +qemuHandleDomainWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED, + virDomainObjPtr vm, + int action) +{ + struct qemud_driver *driver = qemu_driver; + virDomainEventPtr event; + + virDomainObjLock(vm); + event = virDomainEventWatchdogNewFromObj(vm, action); + virDomainObjUnlock(vm); + + if (event) { + qemuDriverLock(driver); + qemuDomainEventQueue(driver, event); + qemuDriverUnlock(driver); + } + + return 0; +} + + static qemuMonitorCallbacks monitorCallbacks = { .eofNotify = qemuHandleMonitorEOF, .diskSecretLookup = findVolumeQcowPassphrase, .domainReset = qemuHandleDomainReset, .domainRTCChange = qemuHandleDomainRTCChange, + .domainWatchdog = qemuHandleDomainWatchdog, }; static int diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 69b2dc38b9..8e2eb00ace 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -806,6 +806,21 @@ int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset) } +int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action) +{ + int ret = -1; + VIR_DEBUG("mon=%p", mon); + + qemuMonitorRef(mon); + qemuMonitorUnlock(mon); + if (mon->cb && mon->cb->domainWatchdog) + ret = mon->cb->domainWatchdog(mon, mon->vm, action); + 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 46252ca6c7..9349eaa41b 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -89,6 +89,9 @@ struct _qemuMonitorCallbacks { int (*domainRTCChange)(qemuMonitorPtr mon, virDomainObjPtr vm, long long offset); + int (*domainWatchdog)(qemuMonitorPtr mon, + virDomainObjPtr vm, + int action); }; @@ -126,6 +129,7 @@ int qemuMonitorEmitReset(qemuMonitorPtr mon); int qemuMonitorEmitPowerdown(qemuMonitorPtr mon); int qemuMonitorEmitStop(qemuMonitorPtr mon); int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset); +int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action); int qemuMonitorStartCPUs(qemuMonitorPtr mon, virConnectPtr conn); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 55f8431132..767a4764c9 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -50,6 +50,7 @@ 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); +static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr data); struct { const char *type; @@ -60,6 +61,7 @@ struct { { "POWERDOWN", qemuMonitorJSONHandlePowerdown, }, { "STOP", qemuMonitorJSONHandleStop, }, { "RTC_CHANGE", qemuMonitorJSONHandleRTCChange, }, + { "WATCHDOG", qemuMonitorJSONHandleWatchdog, }, }; @@ -507,6 +509,28 @@ static void qemuMonitorJSONHandleRTCChange(qemuMonitorPtr mon, virJSONValuePtr d qemuMonitorEmitRTCChange(mon, offset); } +VIR_ENUM_DECL(qemuMonitorWatchdogAction) +VIR_ENUM_IMPL(qemuMonitorWatchdogAction, VIR_DOMAIN_EVENT_WATCHDOG_DEBUG, + "none", "pause", "reset", "poweroff" "shutdown", "debug"); + +static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr data) +{ + const char *action; + int actionID; + if (!(action = virJSONValueObjectGetString(data, "action"))) { + VIR_WARN0("missing action in watchdog event"); + } + if (action) { + if ((actionID = qemuMonitorWatchdogActionTypeFromString(action)) < 0) { + VIR_WARN("unknown action %s in watchdog event", action); + actionID = VIR_DOMAIN_EVENT_WATCHDOG_NONE; + } + } else { + actionID = VIR_DOMAIN_EVENT_WATCHDOG_NONE; + } + qemuMonitorEmitRTCChange(mon, actionID); +} + int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index baa3118ab6..b3cb36a0e9 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -6967,6 +6967,33 @@ remoteDomainReadEventRTCChange(virConnectPtr conn, XDR *xdr) } +static virDomainEventPtr +remoteDomainReadEventWatchdog(virConnectPtr conn, XDR *xdr) +{ + remote_domain_event_watchdog_msg msg; + virDomainPtr dom; + virDomainEventPtr event = NULL; + memset (&msg, 0, sizeof msg); + + /* unmarshall parameters, and process it*/ + if (! xdr_remote_domain_event_watchdog_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 = virDomainEventWatchdogNewFromDom(dom, msg.action); + xdr_free ((xdrproc_t) &xdr_remote_domain_event_watchdog_msg, (char *) &msg); + + virDomainFree(dom); + return event; +} + + static virDrvOpenStatus ATTRIBUTE_NONNULL (1) remoteSecretOpen (virConnectPtr conn, virConnectAuthPtr auth, @@ -8518,6 +8545,10 @@ processCallDispatchMessage(virConnectPtr conn, struct private_data *priv, event = remoteDomainReadEventRTCChange(conn, xdr); break; + case REMOTE_PROC_DOMAIN_EVENT_WATCHDOG: + event = remoteDomainReadEventWatchdog(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 c22a72cd2e..e022235cab 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -3070,6 +3070,17 @@ xdr_remote_domain_event_rtc_change_msg (XDR *xdrs, remote_domain_event_rtc_chang return TRUE; } +bool_t +xdr_remote_domain_event_watchdog_msg (XDR *xdrs, remote_domain_event_watchdog_msg *objp) +{ + + if (!xdr_remote_nonnull_domain (xdrs, &objp->dom)) + return FALSE; + if (!xdr_int (xdrs, &objp->action)) + 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 27aac5e756..0d7eec5a8b 100644 --- a/src/remote/remote_protocol.h +++ b/src/remote/remote_protocol.h @@ -1738,6 +1738,12 @@ struct remote_domain_event_rtc_change_msg { int64_t offset; }; typedef struct remote_domain_event_rtc_change_msg remote_domain_event_rtc_change_msg; + +struct remote_domain_event_watchdog_msg { + remote_nonnull_domain dom; + int action; +}; +typedef struct remote_domain_event_watchdog_msg remote_domain_event_watchdog_msg; #define REMOTE_PROGRAM 0x20008086 #define REMOTE_PROTOCOL_VERSION 1 @@ -1912,6 +1918,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 168, REMOTE_PROC_DOMAIN_EVENT_REBOOT = 169, REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE = 170, + REMOTE_PROC_DOMAIN_EVENT_WATCHDOG = 171, }; typedef enum remote_procedure remote_procedure; @@ -2227,6 +2234,7 @@ extern bool_t xdr_remote_domain_events_register_any_args (XDR *, remote_domain_ 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_domain_event_watchdog_msg (XDR *, remote_domain_event_watchdog_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*); @@ -2516,6 +2524,7 @@ 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_domain_event_watchdog_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 7d45c7094f..b3f622e1bd 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1545,6 +1545,11 @@ struct remote_domain_event_rtc_change_msg { hyper offset; }; +struct remote_domain_event_watchdog_msg { + remote_nonnull_domain dom; + int action; +}; + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -1737,7 +1742,9 @@ 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 + REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE = 170, + + REMOTE_PROC_DOMAIN_EVENT_WATCHDOG = 171 /* * Notice how the entries are grouped in sets of 10 ?