diff options
Diffstat (limited to 'vl.c')
-rw-r--r-- | vl.c | 133 |
1 files changed, 61 insertions, 72 deletions
@@ -147,6 +147,7 @@ int main(int argc, char **argv) #include "qemu-config.h" #include "qemu-objects.h" #include "qemu-options.h" +#include "qmp-commands.h" #ifdef CONFIG_VIRTFS #include "fsdev/qemu-fsdev.h" #endif @@ -323,7 +324,7 @@ static int default_driver_check(QemuOpts *opts, void *opaque) /***********************************************************/ /* QEMU state */ -static RunState current_run_state = RSTATE_NO_STATE; +static RunState current_run_state = RUN_STATE_PRELAUNCH; typedef struct { RunState from; @@ -332,67 +333,48 @@ typedef struct { static const RunStateTransition runstate_transitions_def[] = { /* from -> to */ - { RSTATE_NO_STATE, RSTATE_RUNNING }, - { RSTATE_NO_STATE, RSTATE_IN_MIGRATE }, - { RSTATE_NO_STATE, RSTATE_PRE_LAUNCH }, + { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, - { RSTATE_DEBUG, RSTATE_RUNNING }, + { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, + { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH }, - { RSTATE_IN_MIGRATE, RSTATE_RUNNING }, - { RSTATE_IN_MIGRATE, RSTATE_PRE_LAUNCH }, + { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, - { RSTATE_PANICKED, RSTATE_PAUSED }, + { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, - { RSTATE_IO_ERROR, RSTATE_RUNNING }, + { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, - { RSTATE_PAUSED, RSTATE_RUNNING }, + { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, - { RSTATE_POST_MIGRATE, RSTATE_RUNNING }, + { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, + { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, + { RUN_STATE_PRELAUNCH, RUN_STATE_POSTMIGRATE }, - { RSTATE_PRE_LAUNCH, RSTATE_RUNNING }, - { RSTATE_PRE_LAUNCH, RSTATE_POST_MIGRATE }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, - { RSTATE_PRE_MIGRATE, RSTATE_RUNNING }, - { RSTATE_PRE_MIGRATE, RSTATE_POST_MIGRATE }, + { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, - { RSTATE_RESTORE, RSTATE_RUNNING }, + { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, + { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, + { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, + { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, + { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, + { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, + { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, + { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, - { RSTATE_RUNNING, RSTATE_DEBUG }, - { RSTATE_RUNNING, RSTATE_PANICKED }, - { RSTATE_RUNNING, RSTATE_IO_ERROR }, - { RSTATE_RUNNING, RSTATE_PAUSED }, - { RSTATE_RUNNING, RSTATE_PRE_MIGRATE }, - { RSTATE_RUNNING, RSTATE_RESTORE }, - { RSTATE_RUNNING, RSTATE_SAVEVM }, - { RSTATE_RUNNING, RSTATE_SHUTDOWN }, - { RSTATE_RUNNING, RSTATE_WATCHDOG }, + { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, - { RSTATE_SAVEVM, RSTATE_RUNNING }, + { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, - { RSTATE_SHUTDOWN, RSTATE_PAUSED }, + { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, - { RSTATE_WATCHDOG, RSTATE_RUNNING }, - - { RSTATE_MAX, RSTATE_MAX }, + { RUN_STATE_MAX, RUN_STATE_MAX }, }; -static bool runstate_valid_transitions[RSTATE_MAX][RSTATE_MAX]; - -static const char *const runstate_name_tbl[RSTATE_MAX] = { - [RSTATE_DEBUG] = "debug", - [RSTATE_IN_MIGRATE] = "incoming-migration", - [RSTATE_PANICKED] = "internal-error", - [RSTATE_IO_ERROR] = "io-error", - [RSTATE_PAUSED] = "paused", - [RSTATE_POST_MIGRATE] = "post-migrate", - [RSTATE_PRE_LAUNCH] = "prelaunch", - [RSTATE_PRE_MIGRATE] = "finish-migrate", - [RSTATE_RESTORE] = "restore-vm", - [RSTATE_RUNNING] = "running", - [RSTATE_SAVEVM] = "save-vm", - [RSTATE_SHUTDOWN] = "shutdown", - [RSTATE_WATCHDOG] = "watchdog", -}; +static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX]; bool runstate_check(RunState state) { @@ -405,7 +387,7 @@ void runstate_init(void) memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); - for (p = &runstate_transitions_def[0]; p->from != RSTATE_MAX; p++) { + for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) { runstate_valid_transitions[p->from][p->to] = true; } } @@ -413,7 +395,7 @@ void runstate_init(void) /* This function will abort() on invalid state transitions */ void runstate_set(RunState new_state) { - if (new_state >= RSTATE_MAX || + if (new_state >= RUN_STATE_MAX || !runstate_valid_transitions[current_run_state][new_state]) { fprintf(stderr, "invalid runstate transition\n"); abort(); @@ -422,16 +404,20 @@ void runstate_set(RunState new_state) current_run_state = new_state; } -const char *runstate_as_string(void) +int runstate_is_running(void) { - assert(current_run_state > RSTATE_NO_STATE && - current_run_state < RSTATE_MAX); - return runstate_name_tbl[current_run_state]; + return runstate_check(RUN_STATE_RUNNING); } -int runstate_is_running(void) +StatusInfo *qmp_query_status(Error **errp) { - return runstate_check(RSTATE_RUNNING); + StatusInfo *info = g_malloc0(sizeof(*info)); + + info->running = runstate_is_running(); + info->singlestep = singlestep; + info->status = current_run_state; + + return info; } /***********************************************************/ @@ -1272,8 +1258,8 @@ void vm_start(void) { if (!runstate_is_running()) { cpu_enable_ticks(); - runstate_set(RSTATE_RUNNING); - vm_state_notify(1, RSTATE_RUNNING); + runstate_set(RUN_STATE_RUNNING); + vm_state_notify(1, RUN_STATE_RUNNING); resume_all_vcpus(); monitor_protocol_event(QEVENT_RESUME, NULL); } @@ -1294,7 +1280,7 @@ static int shutdown_requested, shutdown_signal = -1; static pid_t shutdown_pid; static int powerdown_requested; static int debug_requested; -static RunState vmstop_requested = RSTATE_NO_STATE; +static RunState vmstop_requested = RUN_STATE_MAX; int qemu_shutdown_requested_get(void) { @@ -1350,11 +1336,16 @@ static int qemu_debug_requested(void) return r; } -static RunState qemu_vmstop_requested(void) +/* We use RUN_STATE_MAX but any invalid value will do */ +static bool qemu_vmstop_requested(RunState *r) { - RunState s = vmstop_requested; - vmstop_requested = RSTATE_NO_STATE; - return s; + if (vmstop_requested < RUN_STATE_MAX) { + *r = vmstop_requested; + vmstop_requested = RUN_STATE_MAX; + return true; + } + + return false; } void qemu_register_reset(QEMUResetHandler *func, void *opaque) @@ -1567,7 +1558,7 @@ static void main_loop(void) #ifdef CONFIG_PROFILER int64_t ti; #endif - int r; + RunState r; qemu_main_loop_start(); @@ -1582,13 +1573,13 @@ static void main_loop(void) #endif if (qemu_debug_requested()) { - vm_stop(RSTATE_DEBUG); + vm_stop(RUN_STATE_DEBUG); } if (qemu_shutdown_requested()) { qemu_kill_report(); monitor_protocol_event(QEVENT_SHUTDOWN, NULL); if (no_shutdown) { - vm_stop(RSTATE_SHUTDOWN); + vm_stop(RUN_STATE_SHUTDOWN); } else break; } @@ -1597,16 +1588,16 @@ static void main_loop(void) cpu_synchronize_all_states(); qemu_system_reset(VMRESET_REPORT); resume_all_vcpus(); - if (runstate_check(RSTATE_PANICKED) || - runstate_check(RSTATE_SHUTDOWN)) { - runstate_set(RSTATE_PAUSED); + if (runstate_check(RUN_STATE_INTERNAL_ERROR) || + runstate_check(RUN_STATE_SHUTDOWN)) { + runstate_set(RUN_STATE_PAUSED); } } if (qemu_powerdown_requested()) { monitor_protocol_event(QEVENT_POWERDOWN, NULL); qemu_irq_raise(qemu_system_powerdown); } - if ((r = qemu_vmstop_requested())) { + if (qemu_vmstop_requested(&r)) { vm_stop(r); } } @@ -3556,7 +3547,7 @@ int main(int argc, char **argv, char **envp) } if (incoming) { - runstate_set(RSTATE_IN_MIGRATE); + runstate_set(RUN_STATE_INMIGRATE); int ret = qemu_start_incoming_migration(incoming); if (ret < 0) { fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n", @@ -3565,8 +3556,6 @@ int main(int argc, char **argv, char **envp) } } else if (autostart) { vm_start(); - } else { - runstate_set(RSTATE_PRE_LAUNCH); } os_setup_post(); |