From: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, lcapitulino@redhat.com,
Miguel Di Ciurcio Filho <miguel.filho@gmail.com>,
avi@redhat.com
Subject: [Qemu-devel] [PATCH 8/8] monitor/net: introduce 'info netdev' with QMP support
Date: Thu, 10 Jun 2010 18:37:05 -0300 [thread overview]
Message-ID: <1276205825-1922-9-git-send-email-miguel.filho@gmail.com> (raw)
In-Reply-To: <1276205825-1922-1-git-send-email-miguel.filho@gmail.com>
Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
monitor.c | 8 +++++
net.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
net.h | 2 +
3 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/monitor.c b/monitor.c
index 15b53b9..0038214 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2425,6 +2425,14 @@ static const mon_cmd_t info_cmds[] = {
.mhandler.info = do_info_network,
},
{
+ .name = "netdev",
+ .args_type = "",
+ .params = "",
+ .help = "show information about network backend devices",
+ .user_print = do_info_netdev_print,
+ .mhandler.info_new = do_info_netdev,
+ },
+ {
.name = "chardev",
.args_type = "",
.params = "",
diff --git a/net.c b/net.c
index 4cb93ed..ed68b61 100644
--- a/net.c
+++ b/net.c
@@ -36,6 +36,8 @@
#include "qemu-common.h"
#include "qemu_socket.h"
#include "hw/qdev.h"
+#include "qdict.h"
+#include "qjson.h"
static QTAILQ_HEAD(, VLANState) vlans;
static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
@@ -1252,6 +1254,100 @@ void do_info_network(Monitor *mon)
}
}
+static void netdev_iter(QObject *obj, void *opaque)
+{
+
+ Monitor *mon = opaque;
+ QDict *net_device = qobject_to_qdict(obj);
+
+ monitor_printf(mon, "%s: ", qdict_get_str(net_device, "id"));
+
+ monitor_printf(mon, "type=%s,", qdict_get_str(net_device, "type"));
+
+ if (qdict_haskey(net_device, "vlan")) {
+ monitor_printf(mon, "vlan=%d,", (int)qdict_get_int(net_device, "vlan"));
+ }
+
+ if (qdict_haskey(net_device, "peer")) {
+ monitor_printf(mon, "peer=%s,", qdict_get_str(net_device, "peer"));
+ }
+
+ monitor_printf(mon,
+ qstring_get_str(qdict_to_qstring(qdict_get_qdict(net_device,
+"info"), ",")));
+
+ monitor_printf(mon, "\n");
+
+}
+
+void do_info_netdev_print(Monitor *mon, const QObject *ret_data)
+{
+
+ QList *net_devices;
+
+ net_devices = qobject_to_qlist(ret_data);
+
+ qlist_iter(net_devices, netdev_iter, mon);
+
+}
+
+void do_info_netdev(Monitor *mon, QObject **ret_data)
+{
+ VLANState *vlan;
+ VLANClientState *vc;
+ QDict *net_device;
+ QList *device_list;
+ device_list = qlist_new();
+ QObject *obj;
+
+ QTAILQ_FOREACH(vlan, &vlans, next) {
+
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
+
+ if (vc->info->type == NET_CLIENT_TYPE_NONE ||
+ vc->info->type == NET_CLIENT_TYPE_NIC ||
+ vc->info->type == NET_CLIENT_TYPE_DUMP) {
+ continue;
+ }
+
+ obj = qobject_from_jsonf("{ 'vlan': %d, 'id': %s, 'type': %s}", vlan->id,
+ vc->name, vc->model);
+
+ net_device = qobject_to_qdict(obj);
+
+ QINCREF(vc->info_dict);
+ qdict_put(net_device, "info", vc->info_dict);
+
+ qlist_append(device_list, net_device);
+ }
+ }
+
+ QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
+
+ if (vc->info->type == NET_CLIENT_TYPE_NONE ||
+ vc->info->type == NET_CLIENT_TYPE_NIC ||
+ vc->info->type == NET_CLIENT_TYPE_DUMP) {
+ continue;
+ }
+
+ obj = qobject_from_jsonf("{'id': %s, 'type': %s}",
+ vc->name, vc->model);
+
+ net_device = qobject_to_qdict(obj);
+
+ QINCREF(vc->info_dict);
+ qdict_put(net_device, "info", vc->info_dict);
+
+ if (vc->peer) {
+ qdict_put(net_device, "peer", qstring_from_str(vc->peer->name));
+ }
+
+ qlist_append(device_list, net_device);
+ }
+
+ *ret_data = QOBJECT(device_list);
+}
+
int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
VLANState *vlan;
diff --git a/net.h b/net.h
index acc1645..65bbf27 100644
--- a/net.h
+++ b/net.h
@@ -119,6 +119,8 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
const char *default_model);
void do_info_network(Monitor *mon);
+void do_info_netdev_print(Monitor *mon, const QObject *ret_data);
+void do_info_netdev(Monitor *mon, QObject **ret_data);
int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
/* NIC info */
--
1.7.1
next prev parent reply other threads:[~2010-06-10 21:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
2010-06-10 21:36 ` [Qemu-devel] [PATCH 1/8] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-06-10 21:36 ` [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
2010-06-11 11:37 ` Markus Armbruster
2010-06-11 11:47 ` Miguel Di Ciurcio Filho
2010-06-16 17:39 ` [Qemu-devel] " Luiz Capitulino
2010-06-16 21:55 ` Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 3/8] net: Introduce VLANClientState->info_dict Miguel Di Ciurcio Filho
2010-06-16 17:40 ` [Qemu-devel] " Luiz Capitulino
2010-06-10 21:37 ` [Qemu-devel] [PATCH 4/8] net: tap/tap-win32: introduce info_dict Miguel Di Ciurcio Filho
2010-06-16 17:41 ` [Qemu-devel] " Luiz Capitulino
2010-06-10 21:37 ` [Qemu-devel] [PATCH 5/8] net: vde: " Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 6/8] net: socket: " Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 7/8] net: slirp: " Miguel Di Ciurcio Filho
2010-06-10 21:37 ` Miguel Di Ciurcio Filho [this message]
2010-06-16 17:44 ` [Qemu-devel] Re: [PATCH 0/8] QMP: Introduce query-netdev Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1276205825-1922-9-git-send-email-miguel.filho@gmail.com \
--to=miguel.filho@gmail.com \
--cc=armbru@redhat.com \
--cc=avi@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).