Skip to content

Commit

Permalink
QMP: Introduce WATCHDOG event
Browse files Browse the repository at this point in the history
It's emitted whenever the watchdog device's timer expires. The action
taken is provided in the 'data' member.

Signed-off-by: Luiz Capitulino <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
Luiz Capitulino authored and Anthony Liguori committed Mar 9, 2010
1 parent 2d75389 commit 9eedeb3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions QMP/qmp-events.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,22 @@ Example:
"client": { "family": "ipv4", "service": "46089",
"host": "127.0.0.1", "sasl_username": "luiz" } },
"timestamp": { "seconds": 1263475302, "microseconds": 150772 } }

WATCHDOG
--------

Emitted when the watchdog device's timer is expired.

Data:

- "action": Action that has been taken, it's one of the following (json-string):
"reset", "shutdown", "poweroff", "pause", "debug", or "none"

Example:

{ "event": "WATCHDOG",
"data": { "action": "reset" },
"timestamp": { "seconds": 1267061043, "microseconds": 959568 } }

Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is
followed respectively by the RESET, SHUTDOWN, or STOP events.
17 changes: 17 additions & 0 deletions hw/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "qemu-option.h"
#include "qemu-config.h"
#include "qemu-queue.h"
#include "qemu-objects.h"
#include "monitor.h"
#include "sysemu.h"
#include "hw/watchdog.h"

Expand Down Expand Up @@ -98,33 +100,48 @@ int select_watchdog_action(const char *p)
return 0;
}

static void watchdog_mon_event(const char *action)
{
QObject *data;

data = qobject_from_jsonf("{ 'action': %s }", action);
monitor_protocol_event(QEVENT_WATCHDOG, data);
qobject_decref(data);
}

/* This actually performs the "action" once a watchdog has expired,
* ie. reboot, shutdown, exit, etc.
*/
void watchdog_perform_action(void)
{
switch(watchdog_action) {
case WDT_RESET: /* same as 'system_reset' in monitor */
watchdog_mon_event("reset");
qemu_system_reset_request();
break;

case WDT_SHUTDOWN: /* same as 'system_powerdown' in monitor */
watchdog_mon_event("shutdown");
qemu_system_powerdown_request();
break;

case WDT_POWEROFF: /* same as 'quit' command in monitor */
watchdog_mon_event("poweroff");
exit(0);
break;

case WDT_PAUSE: /* same as 'stop' command in monitor */
watchdog_mon_event("pause");
vm_stop(0);
break;

case WDT_DEBUG:
watchdog_mon_event("debug");
fprintf(stderr, "watchdog: timer fired\n");
break;

case WDT_NONE:
watchdog_mon_event("none");
break;
}
}
3 changes: 3 additions & 0 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
case QEVENT_RTC_CHANGE:
event_name = "RTC_CHANGE";
break;
case QEVENT_WATCHDOG:
event_name = "WATCHDOG";
break;
default:
abort();
break;
Expand Down
1 change: 1 addition & 0 deletions monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum MonitorEvent {
QEVENT_VNC_DISCONNECTED,
QEVENT_BLOCK_IO_ERROR,
QEVENT_RTC_CHANGE,
QEVENT_WATCHDOG,
QEVENT_MAX,
} MonitorEvent;

Expand Down

0 comments on commit 9eedeb3

Please sign in to comment.