From f8d6c32546fb03078b3fa876bacd476fce951844 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Mon, 22 Mar 2010 17:44:56 -0300 Subject: [PATCH 28/29] QMP: Introduce WATCHDOG event RH-Author: Luiz Capitulino Message-id: <1269279896-26330-9-git-send-email-lcapitulino@redhat.com> Patchwork-id: 8019 O-Subject: [PATCH 8/8] QMP: Introduce WATCHDOG event Bugzilla: 557083 RH-Acked-by: Richard Jones RH-Acked-by: Kevin Wolf RH-Acked-by: Markus Armbruster RH-Acked-by: Juan Quintela Bugzilla: 557083 It's emitted whenever the watchdog device's timer expires. The action taken is provided in the 'data' member. Signed-off-by: Luiz Capitulino Signed-off-by: Anthony Liguori (cherry picked from commit 9eedeb3b88173d84d438557cada237346a764e0b) --- QMP/qmp-events.txt | 19 +++++++++++++++++++ hw/watchdog.c | 17 +++++++++++++++++ monitor.c | 3 +++ monitor.h | 1 + 4 files changed, 40 insertions(+), 0 deletions(-) Signed-off-by: Eduardo Habkost --- QMP/qmp-events.txt | 19 +++++++++++++++++++ hw/watchdog.c | 17 +++++++++++++++++ monitor.c | 3 +++ monitor.h | 1 + 4 files changed, 40 insertions(+), 0 deletions(-) diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt index 72920f6..a94e9b4 100644 --- a/QMP/qmp-events.txt +++ b/QMP/qmp-events.txt @@ -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. diff --git a/hw/watchdog.c b/hw/watchdog.c index 6a3d1b4..aebb08a 100644 --- a/hw/watchdog.c +++ b/hw/watchdog.c @@ -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" @@ -98,6 +100,15 @@ 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. */ @@ -105,26 +116,32 @@ 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; } } diff --git a/monitor.c b/monitor.c index 3aec08f..971ec0b 100644 --- a/monitor.c +++ b/monitor.c @@ -405,6 +405,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; diff --git a/monitor.h b/monitor.h index ee412eb..edda125 100644 --- a/monitor.h +++ b/monitor.h @@ -26,6 +26,7 @@ typedef enum MonitorEvent { QEVENT_SPICE_DISCONNECTED, QEVENT_BLOCK_IO_ERROR, QEVENT_RTC_CHANGE, + QEVENT_WATCHDOG, QEVENT_MAX, } MonitorEvent; -- 1.7.0.3