Add a qemu_system_exec_request() hook that causes the main loop to exit and exec a command using the specified arguments. This will be used during CPR to exec a new version of QEMU.
Signed-off-by: Steve Sistare <steven.sist...@oracle.com> --- include/sysemu/runstate.h | 3 +++ system/runstate.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 0117d24..cb669cf 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -80,6 +80,8 @@ typedef enum WakeupReason { QEMU_WAKEUP_REASON_OTHER, } WakeupReason; +typedef void (*qemu_exec_func)(char **exec_argv); + void qemu_system_reset_request(ShutdownCause reason); void qemu_system_suspend_request(void); void qemu_register_suspend_notifier(Notifier *notifier); @@ -91,6 +93,7 @@ void qemu_register_wakeup_support(void); void qemu_system_shutdown_request_with_code(ShutdownCause reason, int exit_code); void qemu_system_shutdown_request(ShutdownCause reason); +void qemu_system_exec_request(qemu_exec_func func, const strList *args); void qemu_system_powerdown_request(void); void qemu_register_powerdown_notifier(Notifier *notifier); void qemu_register_shutdown_notifier(Notifier *notifier); diff --git a/system/runstate.c b/system/runstate.c index ec32e27..afc56e4 100644 --- a/system/runstate.c +++ b/system/runstate.c @@ -40,6 +40,7 @@ #include "qapi/error.h" #include "qapi/qapi-commands-run-state.h" #include "qapi/qapi-events-run-state.h" +#include "qapi/type-helpers.h" #include "qemu/accel.h" #include "qemu/error-report.h" #include "qemu/job.h" @@ -400,6 +401,8 @@ static NotifierList wakeup_notifiers = static NotifierList shutdown_notifiers = NOTIFIER_LIST_INITIALIZER(shutdown_notifiers); static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); +qemu_exec_func exec_func; +static char **exec_argv; ShutdownCause qemu_shutdown_requested_get(void) { @@ -416,6 +419,11 @@ static int qemu_shutdown_requested(void) return qatomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); } +static int qemu_exec_requested(void) +{ + return exec_argv != NULL; +} + static void qemu_kill_report(void) { if (!qtest_driver() && shutdown_signal) { @@ -693,6 +701,23 @@ void qemu_system_shutdown_request(ShutdownCause reason) qemu_notify_event(); } +static void qemu_system_exec(void) +{ + exec_func(exec_argv); + + /* exec failed */ + g_strfreev(exec_argv); + exec_argv = NULL; + exec_func = NULL; +} + +void qemu_system_exec_request(qemu_exec_func func, const strList *args) +{ + exec_func = func; + exec_argv = strv_from_str_list(args); + qemu_notify_event(); +} + static void qemu_system_powerdown(void) { qapi_event_send_powerdown(); @@ -739,6 +764,10 @@ static bool main_loop_should_exit(int *status) if (qemu_suspend_requested()) { qemu_system_suspend(); } + if (qemu_exec_requested()) { + qemu_system_exec(); + return false; + } request = qemu_shutdown_requested(); if (request) { qemu_kill_report(); -- 1.8.3.1