From patchwork Wed Oct 5 13:22:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 117845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B2F5B6FA6 for ; Thu, 6 Oct 2011 00:57:14 +1100 (EST) Received: from localhost ([::1]:44120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBRyB-0003v0-1W for incoming@patchwork.ozlabs.org; Wed, 05 Oct 2011 09:57:11 -0400 Received: from eggs.gnu.org ([140.186.70.92]:52017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBRR2-0004gw-BI for qemu-devel@nongnu.org; Wed, 05 Oct 2011 09:23:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RBRQx-00023g-2t for qemu-devel@nongnu.org; Wed, 05 Oct 2011 09:22:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBRQw-000220-BL for qemu-devel@nongnu.org; Wed, 05 Oct 2011 09:22:50 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p95DMnIm012006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 5 Oct 2011 09:22:49 -0400 Received: from localhost (ovpn-113-108.phx2.redhat.com [10.3.113.108]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p95DMmR4020695; Wed, 5 Oct 2011 09:22:49 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Wed, 5 Oct 2011 10:22:04 -0300 Message-Id: <1317820931-25872-20-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1317820931-25872-1-git-send-email-lcapitulino@redhat.com> References: <1317820931-25872-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 19/26] qapi: Convert query-status X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Please, note that the RunState type as defined in sysemu.h and its runstate_as_string() function are being dropped in favor of the RunState type generated by the QAPI. Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- hmp.c | 19 +++++++++++++++ hmp.h | 1 + monitor.c | 41 +-------------------------------- qapi-schema.json | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 6 +++++ sysemu.h | 19 +-------------- vl.c | 32 +++++++++----------------- 7 files changed, 106 insertions(+), 79 deletions(-) diff --git a/hmp.c b/hmp.c index 94a7f74..30925b0 100644 --- a/hmp.c +++ b/hmp.c @@ -53,3 +53,22 @@ void hmp_info_kvm(Monitor *mon) qapi_free_KvmInfo(info); } +void hmp_info_status(Monitor *mon) +{ + StatusInfo *info; + + info = qmp_query_status(NULL); + + monitor_printf(mon, "VM status: %s%s", + info->running ? "running" : "paused", + info->singlestep ? " (single step mode)" : ""); + + if (!info->running && info->status != RUN_STATE_PAUSED) { + monitor_printf(mon, " (%s)", RunState_lookup[info->status]); + } + + monitor_printf(mon, "\n"); + + qapi_free_StatusInfo(info); +} + diff --git a/hmp.h b/hmp.h index a93ac1f..df4242f 100644 --- a/hmp.h +++ b/hmp.h @@ -20,5 +20,6 @@ void hmp_info_name(Monitor *mon); void hmp_info_version(Monitor *mon); void hmp_info_kvm(Monitor *mon); +void hmp_info_status(Monitor *mon); #endif diff --git a/monitor.c b/monitor.c index da729ce..e68f2e2 100644 --- a/monitor.c +++ b/monitor.c @@ -2550,36 +2550,6 @@ static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data) } #endif -static void do_info_status_print(Monitor *mon, const QObject *data) -{ - QDict *qdict; - const char *status; - - qdict = qobject_to_qdict(data); - - monitor_printf(mon, "VM status: "); - if (qdict_get_bool(qdict, "running")) { - monitor_printf(mon, "running"); - if (qdict_get_bool(qdict, "singlestep")) { - monitor_printf(mon, " (single step mode)"); - } - } else { - monitor_printf(mon, "paused"); - } - - status = qdict_get_str(qdict, "status"); - if (strcmp(status, "paused") && strcmp(status, "running")) { - monitor_printf(mon, " (%s)", status); - } - - monitor_printf(mon, "\n"); -} - -static void do_info_status(Monitor *mon, QObject **ret_data) -{ - *ret_data = qobject_from_jsonf("{ 'running': %i, 'singlestep': %i, 'status': %s }", runstate_is_running(), singlestep, runstate_as_string()); -} - static qemu_acl *find_acl(Monitor *mon, const char *name) { qemu_acl *acl = qemu_acl_find(name); @@ -2979,8 +2949,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM status (running|paused)", - .user_print = do_info_status_print, - .mhandler.info_new = do_info_status, + .mhandler.info = hmp_info_status, }, { .name = "pcmcia", @@ -3162,14 +3131,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .mhandler.info_new = do_pci_info, }, { - .name = "status", - .args_type = "", - .params = "", - .help = "show the current VM status (running|paused)", - .user_print = do_info_status_print, - .mhandler.info_new = do_info_status, - }, - { .name = "mice", .args_type = "", .params = "", diff --git a/qapi-schema.json b/qapi-schema.json index 641f12d..0e59c71 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -85,3 +85,70 @@ ## { 'command': 'query-kvm', 'returns': 'KvmInfo' } +## +# @RunState +# +# An enumation of VM run states. +# +# @debug: QEMU is running on a debugger +# +# @inmigrate: guest is paused waiting for an incoming migration +# +# @internal-error: An internal error that prevents further guest execution +# has occurred +# +# @io-error: the last IOP has failed and the device is configured to pause +# on I/O errors +# +# @paused: guest has been paused via the 'stop' command +# +# @postmigrate: guest is paused following a successful 'migrate' +# +# @prelaunch: QEMU was started with -S and guest has not started +# +# @finish-migrate: guest is paused to finish the migration process +# +# @restore-vm: guest is paused to restore VM state +# +# @running: guest is actively running +# +# @save-vm: guest is paused to save the VM state +# +# @shutdown: guest is shut down (and -no-shutdown is in use) +# +# @watchdog: the watchdog action is configured to pause and has been triggered +## +{ 'enum': 'RunState', + 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', + 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', + 'running', 'save-vm', 'shutdown', 'watchdog' ] } + +## +# @StatusInfo: +# +# Information about VCPU run state +# +# @running: true if all VCPUs are runnable, false if not runnable +# +# @singlestep: true if VCPUs are in single-step mode +# +# @status: the virtual machine @RunState +# +# Since: 0.14.0 +# +# Notes: @singlestep is enabled through the GDB stub +## +{ 'type': 'StatusInfo', + 'data': {'running': 'bool', 'singlestep': 'bool', 'status': 'RunState'} } + +## +# @query-status: +# +# Query the run status of all VCPUs +# +# Returns: @StatusInfo reflecting all VCPUs +# +# Since: 0.14.0 +## +{ 'command': 'query-status', 'returns': 'StatusInfo' } + diff --git a/qmp-commands.hx b/qmp-commands.hx index 9f9751d..afa95bd 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1609,6 +1609,12 @@ Example: <- { "return": { "running": true, "singlestep": false, "status": "running" } } EQMP + + { + .name = "query-status", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_status, + }, SQMP query-mice diff --git a/sysemu.h b/sysemu.h index 5d1fed2..a889d90 100644 --- a/sysemu.h +++ b/sysemu.h @@ -6,27 +6,11 @@ #include "qemu-option.h" #include "qemu-queue.h" #include "qemu-timer.h" +#include "qapi-types.h" #include "notify.h" /* vl.c */ -typedef enum { - RUN_STATE_DEBUG, /* qemu is running under gdb */ - RUN_STATE_INMIGRATE, /* paused waiting for an incoming migration */ - RUN_STATE_INTERNAL_ERROR, /* paused due to an internal error */ - RUN_STATE_IO_ERROR, /* paused due to an I/O error */ - RUN_STATE_PAUSED, /* paused by the user (ie. the 'stop' command) */ - RUN_STATE_POSTMIGRATE, /* paused following a successful migration */ - RUN_STATE_PRELAUNCH, /* qemu was started with -S and haven't started */ - RUN_STATE_FINISH_MIGRATE, /* paused preparing to finish migrate */ - RUN_STATE_RESTORE_VM, /* paused restoring the VM state */ - RUN_STATE_RUNNING, /* qemu is running */ - RUN_STATE_SAVE_VM, /* paused saving VM state */ - RUN_STATE_SHUTDOWN, /* guest shut down and -no-shutdown is in use */ - RUN_STATE_WATCHDOG, /* watchdog fired and qemu is configured to pause */ - RUN_STATE_MAX -} RunState; - extern const char *bios_name; extern const char *qemu_name; @@ -38,7 +22,6 @@ void runstate_init(void); bool runstate_check(RunState state); void runstate_set(RunState new_state); int runstate_is_running(void); -const char *runstate_as_string(void); typedef struct vm_change_state_entry VMChangeStateEntry; typedef void VMChangeStateHandler(void *opaque, int running, RunState state); diff --git a/vl.c b/vl.c index ba4a151..dbf7778 100644 --- a/vl.c +++ b/vl.c @@ -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 @@ -375,22 +376,6 @@ static const RunStateTransition runstate_transitions_def[] = { static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX]; -static const char *const runstate_name_tbl[RUN_STATE_MAX] = { - [RUN_STATE_DEBUG] = "debug", - [RUN_STATE_INMIGRATE] = "incoming-migration", - [RUN_STATE_INTERNAL_ERROR] = "internal-error", - [RUN_STATE_IO_ERROR] = "io-error", - [RUN_STATE_PAUSED] = "paused", - [RUN_STATE_POSTMIGRATE] = "post-migrate", - [RUN_STATE_PRELAUNCH] = "prelaunch", - [RUN_STATE_FINISH_MIGRATE] = "finish-migrate", - [RUN_STATE_RESTORE_VM] = "restore-vm", - [RUN_STATE_RUNNING] = "running", - [RUN_STATE_SAVE_VM] = "save-vm", - [RUN_STATE_SHUTDOWN] = "shutdown", - [RUN_STATE_WATCHDOG] = "watchdog", -}; - bool runstate_check(RunState state) { return current_run_state == state; @@ -419,15 +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 < RUN_STATE_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(RUN_STATE_RUNNING); + StatusInfo *info = g_malloc0(sizeof(*info)); + + info->running = runstate_is_running(); + info->singlestep = singlestep; + info->status = current_run_state; + + return info; } /***********************************************************/