From patchwork Wed Oct 5 13:22:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 117866 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 177CCB6FA1 for ; Thu, 6 Oct 2011 01:36:47 +1100 (EST) Received: from localhost ([::1]:35700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBSaN-0006Gj-Dp for incoming@patchwork.ozlabs.org; Wed, 05 Oct 2011 10:36:39 -0400 Received: from eggs.gnu.org ([140.186.70.92]:52040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBRR4-0004na-8A for qemu-devel@nongnu.org; Wed, 05 Oct 2011 09:23:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RBRQz-00027Z-Q6 for qemu-devel@nongnu.org; Wed, 05 Oct 2011 09:22:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40519) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBRQz-000261-Fg for qemu-devel@nongnu.org; Wed, 05 Oct 2011 09:22:53 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p95DMqdu030921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 5 Oct 2011 09:22:52 -0400 Received: from localhost (ovpn-113-108.phx2.redhat.com [10.3.113.108]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p95DMpw3004512; Wed, 5 Oct 2011 09:22:52 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Wed, 5 Oct 2011 10:22:06 -0300 Message-Id: <1317820931-25872-22-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.67 on 10.5.11.11 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 21/26] qapi: Convert query-chardev 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 Reviewed-by: Michael Roth Tested-by: Michael Roth Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- hmp.c | 13 +++++++++++++ hmp.h | 1 + monitor.c | 11 +---------- qapi-schema.json | 26 ++++++++++++++++++++++++++ qemu-char.c | 35 +++++++++++------------------------ qmp-commands.hx | 6 ++++++ 6 files changed, 58 insertions(+), 34 deletions(-) diff --git a/hmp.c b/hmp.c index 25302f5..30c6cc9 100644 --- a/hmp.c +++ b/hmp.c @@ -80,3 +80,16 @@ void hmp_info_uuid(Monitor *mon) monitor_printf(mon, "%s\n", info->UUID); qapi_free_UuidInfo(info); } + +void hmp_info_chardev(Monitor *mon) +{ + ChardevInfoList *char_info, *info; + + char_info = qmp_query_chardev(NULL); + for (info = char_info; info; info = info->next) { + monitor_printf(mon, "%s: filename=%s\n", info->value->label, + info->value->filename); + } + + qapi_free_ChardevInfoList(char_info); +} diff --git a/hmp.h b/hmp.h index 49a5971..7388f9a 100644 --- a/hmp.h +++ b/hmp.h @@ -22,5 +22,6 @@ void hmp_info_version(Monitor *mon); void hmp_info_kvm(Monitor *mon); void hmp_info_status(Monitor *mon); void hmp_info_uuid(Monitor *mon); +void hmp_info_chardev(Monitor *mon); #endif diff --git a/monitor.c b/monitor.c index 4e9ecdf..86a0dad 100644 --- a/monitor.c +++ b/monitor.c @@ -2783,8 +2783,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .user_print = qemu_chr_info_print, - .mhandler.info_new = qemu_chr_info, + .mhandler.info = hmp_info_chardev, }, { .name = "block", @@ -3073,14 +3072,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .mhandler.info_new = do_info_commands, }, { - .name = "chardev", - .args_type = "", - .params = "", - .help = "show the character devices", - .user_print = qemu_chr_info_print, - .mhandler.info_new = qemu_chr_info, - }, - { .name = "block", .args_type = "", .params = "", diff --git a/qapi-schema.json b/qapi-schema.json index b717491..cf55504 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -176,3 +176,29 @@ ## { 'command': 'query-uuid', 'returns': 'UuidInfo' } +## +# @ChardevInfo: +# +# Information about a character device. +# +# @label: the label of the character device +# +# @filename: the filename of the character device +# +# Notes: @filename is encoded using the QEMU command line character device +# encoding. See the QEMU man page for details. +# +# Since: 0.14.0 +## +{ 'type': 'ChardevInfo', 'data': {'label': 'str', 'filename': 'str'} } + +## +# @query-chardev: +# +# Returns information about current character devices. +# +# Returns: a list of @ChardevInfo +# +# Since: 0.14.0 +## +{ 'command': 'query-chardev', 'returns': ['ChardevInfo'] } diff --git a/qemu-char.c b/qemu-char.c index 09d2309..8bdbcfd 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -31,7 +31,7 @@ #include "hw/usb.h" #include "hw/baum.h" #include "hw/msmouse.h" -#include "qemu-objects.h" +#include "qmp-commands.h" #include #include @@ -2650,35 +2650,22 @@ void qemu_chr_delete(CharDriverState *chr) g_free(chr); } -static void qemu_chr_qlist_iter(QObject *obj, void *opaque) +ChardevInfoList *qmp_query_chardev(Error **errp) { - QDict *chr_dict; - Monitor *mon = opaque; - - chr_dict = qobject_to_qdict(obj); - monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"), - qdict_get_str(chr_dict, "filename")); -} - -void qemu_chr_info_print(Monitor *mon, const QObject *ret_data) -{ - qlist_iter(qobject_to_qlist(ret_data), qemu_chr_qlist_iter, mon); -} - -void qemu_chr_info(Monitor *mon, QObject **ret_data) -{ - QList *chr_list; + ChardevInfoList *chr_list = NULL; CharDriverState *chr; - chr_list = qlist_new(); - QTAILQ_FOREACH(chr, &chardevs, next) { - QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }", - chr->label, chr->filename); - qlist_append_obj(chr_list, obj); + ChardevInfoList *info = g_malloc0(sizeof(*info)); + info->value = g_malloc0(sizeof(*info->value)); + info->value->label = g_strdup(chr->label); + info->value->filename = g_strdup(chr->filename); + + info->next = chr_list; + chr_list = info; } - *ret_data = QOBJECT(chr_list); + return chr_list; } CharDriverState *qemu_chr_find(const char *name) diff --git a/qmp-commands.hx b/qmp-commands.hx index 4fef25f..dfc02af 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1120,6 +1120,12 @@ Example: EQMP + { + .name = "query-chardev", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_chardev, + }, + SQMP query-block -----------