Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_monitor.c | 16 ++++++++ src/qemu/qemu_monitor.h | 49 ++++++++++++++++++++++ src/qemu/qemu_monitor_json.c | 79 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 7 ++++ tests/qemumonitorjsontest.c | 6 +++ 5 files changed, 157 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 14fb605e92..42846349c4 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4609,3 +4609,19 @@ qemuMonitorQueryDirtyRate(qemuMonitor *mon, return qemuMonitorJSONQueryDirtyRate(mon, info); } + + +int +qemuMonitorSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic) +{ + VIR_DEBUG("shutdown=%u, reboot=%u, watchdog=%u panic=%u", + shutdown, reboot, watchdog, panic); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONSetAction(mon, shutdown, reboot, watchdog, panic); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8af271dc96..2f08357c0c 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -101,6 +101,48 @@ struct _qemuMonitorRdmaGidStatus { }; +typedef enum { + QEMU_MONITOR_ACTION_SHUTDOWN_KEEP, /* do not change the current setting */ + QEMU_MONITOR_ACTION_SHUTDOWN_POWEROFF, + QEMU_MONITOR_ACTION_SHUTDOWN_PAUSE, + + QEMU_MONITOR_ACTION_SHUTDOWN_LAST +} qemuMonitorActionShutdown; + + +typedef enum { + QEMU_MONITOR_ACTION_REBOOT_KEEP, /* do not change the current setting */ + QEMU_MONITOR_ACTION_REBOOT_RESET, + QEMU_MONITOR_ACTION_REBOOT_SHUTDOWN, + + QEMU_MONITOR_ACTION_REBOOT_LAST +} qemuMonitorActionReboot; + + +typedef enum { + QEMU_MONITOR_ACTION_WATCHDOG_KEEP, /* do not change the current setting */ + QEMU_MONITOR_ACTION_WATCHDOG_RESET, + QEMU_MONITOR_ACTION_WATCHDOG_SHUTDOWN, + QEMU_MONITOR_ACTION_WATCHDOG_POWEROFF, + QEMU_MONITOR_ACTION_WATCHDOG_PAUSE, + QEMU_MONITOR_ACTION_WATCHDOG_DEBUG, + QEMU_MONITOR_ACTION_WATCHDOG_NONE, + QEMU_MONITOR_ACTION_WATCHDOG_INJECT_NMI, + + QEMU_MONITOR_ACTION_WATCHDOG_LAST +} qemuMonitorActionWatchdog; + + +typedef enum { + QEMU_MONITOR_ACTION_PANIC_KEEP, /* do not change the current setting */ + QEMU_MONITOR_ACTION_PANIC_PAUSE, + QEMU_MONITOR_ACTION_PANIC_SHUTDOWN, + QEMU_MONITOR_ACTION_PANIC_NONE, + + QEMU_MONITOR_ACTION_PANIC_LAST +} qemuMonitorActionPanic; + + typedef enum { QEMU_MONITOR_JOB_TYPE_UNKNOWN, /* internal value, not exposed by qemu */ QEMU_MONITOR_JOB_TYPE_COMMIT, @@ -1488,3 +1530,10 @@ struct _qemuMonitorDirtyRateInfo { int qemuMonitorQueryDirtyRate(qemuMonitor *mon, qemuMonitorDirtyRateInfo *info); + +int +qemuMonitorSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8fb2bf4dc3..8d3c4031a6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9325,3 +9325,82 @@ qemuMonitorJSONQueryDirtyRate(qemuMonitor *mon, return qemuMonitorJSONExtractDirtyRateInfo(data, info); } + + +VIR_ENUM_DECL(qemuMonitorActionShutdown); +VIR_ENUM_IMPL(qemuMonitorActionShutdown, + QEMU_MONITOR_ACTION_SHUTDOWN_LAST, + "", + "poweroff", + "pause"); + +VIR_ENUM_DECL(qemuMonitorActionReboot); +VIR_ENUM_IMPL(qemuMonitorActionReboot, + QEMU_MONITOR_ACTION_REBOOT_LAST, + "", + "reset", + "shutdown"); + +VIR_ENUM_DECL(qemuMonitorActionWatchdog); +VIR_ENUM_IMPL(qemuMonitorActionWatchdog, + QEMU_MONITOR_ACTION_WATCHDOG_LAST, + "", + "reset", + "shutdown", + "poweroff", + "pause", + "debug", + "none", + "inject-nmi"); + +VIR_ENUM_DECL(qemuMonitorActionPanic); +VIR_ENUM_IMPL(qemuMonitorActionPanic, + QEMU_MONITOR_ACTION_PANIC_LAST, + "", + "pause", + "shutdown", + "none"); + + +int +qemuMonitorJSONSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic) +{ + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + const char *actionShutdown = NULL; + const char *actionReboot = NULL; + const char *actionWatchdog = NULL; + const char *actionPanic = NULL; + + if (shutdown != QEMU_MONITOR_ACTION_SHUTDOWN_KEEP) + actionShutdown = qemuMonitorActionShutdownTypeToString(shutdown); + + if (reboot != QEMU_MONITOR_ACTION_REBOOT_KEEP) + actionReboot = qemuMonitorActionRebootTypeToString(reboot); + + if (watchdog != QEMU_MONITOR_ACTION_WATCHDOG_KEEP) + actionWatchdog = qemuMonitorActionWatchdogTypeToString(watchdog); + + if (panic != QEMU_MONITOR_ACTION_PANIC_KEEP) + actionPanic = qemuMonitorActionPanicTypeToString(panic); + + if (!(cmd = qemuMonitorJSONMakeCommand("set-action", + "S:shutdown", actionShutdown, + "S:reboot", actionReboot, + "S:watchdog", actionWatchdog, + "S:panic", actionPanic, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index fbeab2bf6d..c8cf734a1c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -703,3 +703,10 @@ qemuMonitorJSONStartDirtyRateCalc(qemuMonitor *mon, int qemuMonitorJSONQueryDirtyRate(qemuMonitor *mon, qemuMonitorDirtyRateInfo *info); + +int +qemuMonitorJSONSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 6d7ecb0ab1..9ec5f06981 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1204,6 +1204,11 @@ GEN_TEST_FUNC(qemuMonitorJSONBitmapRemove, "foodev", "newnode") GEN_TEST_FUNC(qemuMonitorJSONJobDismiss, "jobname") GEN_TEST_FUNC(qemuMonitorJSONJobComplete, "jobname") GEN_TEST_FUNC(qemuMonitorJSONBlockJobCancel, "jobname", true) +GEN_TEST_FUNC(qemuMonitorJSONSetAction, + QEMU_MONITOR_ACTION_SHUTDOWN_PAUSE, + QEMU_MONITOR_ACTION_REBOOT_RESET, + QEMU_MONITOR_ACTION_WATCHDOG_SHUTDOWN, + QEMU_MONITOR_ACTION_PANIC_SHUTDOWN) static int testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque) @@ -3067,6 +3072,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONJobDismiss); DO_TEST_GEN(qemuMonitorJSONJobComplete); DO_TEST_GEN(qemuMonitorJSONBlockJobCancel); + DO_TEST_GEN(qemuMonitorJSONSetAction); DO_TEST(qemuMonitorJSONGetBalloonInfo); DO_TEST(qemuMonitorJSONGetBlockInfo); DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo); -- 2.31.1