Add support for an explicit watchdog event

This introduces a new event type

   VIR_DOMAIN_EVENT_ID_WATCHDOG

This event includes the action that is about to be taken
as a result of the watchdog triggering

 typedef enum {
     VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
     VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
     VIR_DOMAIN_EVENT_WATCHDOG_RESET,
     VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
     VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
     VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
 } virDomainEventWatchdogAction;

Thus there is a new callback definition for this event type

 typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
                                                       virDomainPtr dom,
                                                       int action,
                                                       void *opaque);

* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
  watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
  and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
  src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
  for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
  events to application
* src/remote/remote_protocol.x: Wire protocol definition for
  watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
  from QEMU monitor
This commit is contained in:
Daniel P. Berrange 2010-03-18 19:07:48 +00:00
parent 32e6ac9c26
commit c5728cd618
16 changed files with 252 additions and 3 deletions

View File

@ -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);

View File

@ -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,
},

View File

@ -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");

View File

@ -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

View File

@ -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",
}

View File

@ -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;

View File

@ -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);

View File

@ -218,6 +218,8 @@ virDomainEventRebootNewFromDom;
virDomainEventRebootNewFromObj;
virDomainEventRTCChangeNewFromDom;
virDomainEventRTCChangeNewFromObj;
virDomainEventWatchdogNewFromDom;
virDomainEventWatchdogNewFromObj;
virDomainEventFree;
virDomainEventDispatchDefaultFunc;
virDomainEventDispatch;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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;

View File

@ -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)
{

View File

@ -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 ();

View File

@ -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 ?