From patchwork Wed Sep 28 14:44:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 116805 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 975841007D2 for ; Thu, 29 Sep 2011 00:46:57 +1000 (EST) Received: from localhost ([::1]:51393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8vPA-0005mu-Or for incoming@patchwork.ozlabs.org; Wed, 28 Sep 2011 10:46:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8vNu-0002u2-SB for qemu-devel@nongnu.org; Wed, 28 Sep 2011 10:45:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8vNm-0004x0-G6 for qemu-devel@nongnu.org; Wed, 28 Sep 2011 10:45:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8vNm-0004wN-70 for qemu-devel@nongnu.org; Wed, 28 Sep 2011 10:45:10 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8SEj8GX003591 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Sep 2011 10:45:08 -0400 Received: from localhost (ovpn-113-147.phx2.redhat.com [10.3.113.147]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8SEj7LW027190; Wed, 28 Sep 2011 10:45:07 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 28 Sep 2011 11:44:35 -0300 Message-Id: <1317221085-5825-12-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1317221085-5825-1-git-send-email-lcapitulino@redhat.com> References: <1317221085-5825-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 11/21] qapi: convert query-name 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 From: Anthony Liguori A simple example conversion 'info name'. This also adds the new files for QMP and HMP. Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- Makefile.objs | 1 + hmp.c | 26 ++++++++++++++++++++++++++ hmp.h | 22 ++++++++++++++++++++++ monitor.c | 31 +++---------------------------- qapi-schema.json | 22 ++++++++++++++++++++++ qmp-commands.hx | 6 ++++++ qmp.c | 28 ++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 28 deletions(-) create mode 100644 hmp.c create mode 100644 hmp.h create mode 100644 qmp.c diff --git a/Makefile.objs b/Makefile.objs index 441d797..c90a3cb 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -407,6 +407,7 @@ qapi-nested-y += qmp-registry.o qmp-dispatch.o qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) +common-obj-y += qmp.o hmp.o ###################################################################### # guest agent diff --git a/hmp.c b/hmp.c new file mode 100644 index 0000000..47e1ff7 --- /dev/null +++ b/hmp.c @@ -0,0 +1,26 @@ +/* + * Human Monitor Interface + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#include "hmp.h" +#include "qmp-commands.h" + +void hmp_info_name(Monitor *mon) +{ + NameInfo *info; + + info = qmp_query_name(NULL); + if (info->has_name) { + monitor_printf(mon, "%s\n", info->name); + } + qapi_free_NameInfo(info); +} diff --git a/hmp.h b/hmp.h new file mode 100644 index 0000000..5fe73f1 --- /dev/null +++ b/hmp.h @@ -0,0 +1,22 @@ +/* + * Human Monitor Interface + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef HMP_H +#define HMP_H + +#include "qemu-common.h" +#include "qapi-types.h" + +void hmp_info_name(Monitor *mon); + +#endif diff --git a/monitor.c b/monitor.c index 150fe45..8af0e27 100644 --- a/monitor.c +++ b/monitor.c @@ -63,6 +63,8 @@ #endif #include "trace/control.h" #include "ui/qemu-spice.h" +#include "qmp-commands.h" +#include "hmp.h" //#define DEBUG //#define DEBUG_COMPLETION @@ -759,24 +761,6 @@ static void do_info_version(Monitor *mon, QObject **ret_data) 'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION); } -static void do_info_name_print(Monitor *mon, const QObject *data) -{ - QDict *qdict; - - qdict = qobject_to_qdict(data); - if (qdict_size(qdict) == 0) { - return; - } - - monitor_printf(mon, "%s\n", qdict_get_str(qdict, "name")); -} - -static void do_info_name(Monitor *mon, QObject **ret_data) -{ - *ret_data = qemu_name ? qobject_from_jsonf("{'name': %s }", qemu_name) : - qobject_from_jsonf("{}"); -} - static QObject *get_cmd_dict(const char *name) { const char *p; @@ -3081,8 +3065,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = do_info_name, + .mhandler.info = hmp_info_name, }, { .name = "uuid", @@ -3274,14 +3257,6 @@ static const mon_cmd_t qmp_query_cmds[] = { }, #endif { - .name = "name", - .args_type = "", - .params = "", - .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = do_info_name, - }, - { .name = "uuid", .args_type = "", .params = "", diff --git a/qapi-schema.json b/qapi-schema.json index 7fcefdb..3585324 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1,3 +1,25 @@ # -*- Mode: Python -*- # # QAPI Schema + +## +# @NameInfo: +# +# Guest name information. +# +# @name: #optional The name of the guest +# +# Since 0.14.0 +## +{ 'type': 'NameInfo', 'data': {'*name': 'str'} } + +## +# @query-name: +# +# Return the name information of a guest. +# +# Returns: @NameInfo of the guest +# +# Since 0.14.0 +## +{ 'command': 'query-name', 'returns': 'NameInfo' } diff --git a/qmp-commands.hx b/qmp-commands.hx index d83bce5..7b3839e 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1780,6 +1780,12 @@ Example: EQMP + { + .name = "query-name", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_name, + }, + SQMP query-uuid ---------- diff --git a/qmp.c b/qmp.c new file mode 100644 index 0000000..8aa9c66 --- /dev/null +++ b/qmp.c @@ -0,0 +1,28 @@ +/* + * QEMU Management Protocol + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#include "qemu-common.h" +#include "sysemu.h" +#include "qmp-commands.h" + +NameInfo *qmp_query_name(Error **errp) +{ + NameInfo *info = g_malloc0(sizeof(*info)); + + if (qemu_name) { + info->has_name = true; + info->name = g_strdup(qemu_name); + } + + return info; +}