From patchwork Tue Nov 17 20:32:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 38701 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 05CDFB6F1C for ; Wed, 18 Nov 2009 10:35:50 +1100 (EST) Received: from localhost ([127.0.0.1]:49767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAVC4-0002Zs-Ql for incoming@patchwork.ozlabs.org; Tue, 17 Nov 2009 16:02:32 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAUjo-0004h3-M5 for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:33:21 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAUjd-0004b3-MN for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:33:14 -0500 Received: from [199.232.76.173] (port=34696 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAUjd-0004aw-Hi for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:33:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14148) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAUjc-0008Az-UE for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:33:09 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAHKX8QA026171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Nov 2009 15:33:08 -0500 Received: from localhost (vpn-11-203.rdu.redhat.com [10.11.11.203]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAHKX62b032674 for ; Tue, 17 Nov 2009 15:33:07 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 17 Nov 2009 18:32:23 -0200 Message-Id: <1258489944-12159-17-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1258489944-12159-1-git-send-email-lcapitulino@redhat.com> References: <1258489944-12159-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 16/17] net: Convert do_info_network() to QObject X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Each VLAN is represented by a QDict, the returned QObject is a QList of all VLANs. This commit should not change user output. Signed-off-by: Luiz Capitulino --- monitor.c | 3 +- net.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- net.h | 3 +- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index fb2f1c8..de7a0f1 100644 --- a/monitor.c +++ b/monitor.c @@ -2033,7 +2033,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the network state", - .mhandler.info = do_info_network, + .user_print = do_info_network_print, + .mhandler.info_new = do_info_network, }, { .name = "chardev", diff --git a/net.c b/net.c index 9ea66e3..a0312af 100644 --- a/net.c +++ b/net.c @@ -106,6 +106,7 @@ #include "qemu_socket.h" #include "qemu-log.h" #include "qemu-config.h" +#include "qemu-objects.h" #include "slirp/libslirp.h" @@ -2740,19 +2741,82 @@ void net_set_boot_mask(int net_boot_mask) } } -void do_info_network(Monitor *mon) +static void info_clients_iter(QObject *data, void *opaque) { + QDict *qdict; + Monitor *mon = opaque; + + qdict = qobject_to_qdict(data); + monitor_printf(mon, " %s: %s\n", qdict_get_str(qdict, "name"), + qdict_get_str(qdict, "info")); +} + +static void info_network_iter(QObject *data, void *opaque) +{ + QDict *qdict; + Monitor *mon = opaque; + + qdict = qobject_to_qdict(data); + monitor_printf(mon, "VLAN %" PRId64 " devices:\n", + qdict_get_int(qdict, "id")); + + qlist_iter(qdict_get_qlist(qdict, "devices"), info_clients_iter, opaque); +} + +void do_info_network_print(Monitor *mon, const QObject *data) +{ + qlist_iter(qobject_to_qlist(data), info_network_iter, mon); +} + +/** + * do_info_network(): Show VLANs and associated devices information + * + * Each VLAN is represented by a QDict, the returned QObject is a QList + * of all VLANs. + * + * Devices are also represented by a QDict and each VLAN contains a QList + * of its devices. + * + * The VLAN QDict contains the following: + * + * - "id": VLAN id + * - "devices": a QList of all devices + * + * The device QDict contains the following: + * + * - "name": device's name + * - "info": device's specific info string + * + * Example: + * + * [ { "id": 1, "devices": [ + * { "name": "e1000.1", "info": "model=e1000,macaddr=52:54:00:12:34:56" }, + * { "name": "socket.0", "info": "socket: connect to 127.0.0.1:8010" } ] } ] + */ +void do_info_network(Monitor *mon, QObject **ret_data) +{ + QObject *obj; VLANState *vlan; + QList *vlan_list; + + vlan_list = qlist_new(); QTAILQ_FOREACH(vlan, &vlans, next) { VLANClientState *vc; - - monitor_printf(mon, "VLAN %d devices:\n", vlan->id); + QList *clients = qlist_new(); QTAILQ_FOREACH(vc, &vlan->clients, next) { - monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str); + obj = qobject_from_jsonf("{ 'name': %s, 'info': %s }", + vc->name, vc->info_str); + qlist_append_obj(clients, obj); } + + obj = qobject_from_jsonf("{ 'id': %d, 'devices': %p }", + vlan->id, QOBJECT(clients)); + qlist_append_obj(vlan_list, obj); } + + *ret_data = QOBJECT(vlan_list); } void do_set_link(Monitor *mon, const QDict *qdict) diff --git a/net.h b/net.h index 4ffce91..66da212 100644 --- a/net.h +++ b/net.h @@ -105,7 +105,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *model); int qemu_find_nic_model(NICInfo *nd, const char * const *models, const char *default_model); -void do_info_network(Monitor *mon); +void do_info_network_print(Monitor *mon, const QObject *data); +void do_info_network(Monitor *mon, QObject **ret_data); void do_set_link(Monitor *mon, const QDict *qdict); void do_info_usernet(Monitor *mon);