qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
Cc: avi@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com
Subject: [Qemu-devel] Re: [PATCH 7/7] monitor/net: introduce 'info netdev' with QMP support
Date: Mon, 28 Jun 2010 19:00:00 -0300	[thread overview]
Message-ID: <20100628190000.2a89aa29@redhat.com> (raw)
In-Reply-To: <1277307603-28960-8-git-send-email-miguel.filho@gmail.com>

On Wed, 23 Jun 2010 12:40:03 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  monitor.c |    8 +++++++
>  net.c     |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  net.h     |    2 +
>  3 files changed, 80 insertions(+), 0 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index 170b269..b44768c 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2314,6 +2314,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 7daf253..5e0eb0c 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;
> @@ -1249,6 +1251,74 @@ 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, "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"), ",")));

The string returned by qdict_to_qstring() is leaking.

> +
> +    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)
> +{
> +    VLANClientState *vc;
> +    QDict *net_device;
> +    QList *device_list;
> +    device_list = qlist_new();
> +    QObject *obj;
> +
> +    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_SOCKET ||
> +            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 cfe837f..69a3c9f 100644
> --- a/net.h
> +++ b/net.h
> @@ -118,6 +118,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 */

  reply	other threads:[~2010-06-28 22:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-23 15:39 [Qemu-devel] [PATCH 0/7] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
2010-06-23 15:39 ` [Qemu-devel] [PATCH 1/7] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
2010-06-23 15:39 ` [Qemu-devel] [PATCH 2/7] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-06-23 15:39 ` [Qemu-devel] [PATCH 3/7] net: Introduce VLANClientState->info_dict Miguel Di Ciurcio Filho
2010-06-28 21:59   ` [Qemu-devel] " Luiz Capitulino
2010-06-23 15:40 ` [Qemu-devel] [PATCH 4/7] net: tap/tap-win32: introduce info_dict Miguel Di Ciurcio Filho
2010-06-23 15:40 ` [Qemu-devel] [PATCH 5/7] net: vde: " Miguel Di Ciurcio Filho
2010-06-23 15:40 ` [Qemu-devel] [PATCH 6/7] net: slirp: " Miguel Di Ciurcio Filho
2010-06-23 15:40 ` [Qemu-devel] [PATCH 7/7] monitor/net: introduce 'info netdev' with QMP support Miguel Di Ciurcio Filho
2010-06-28 22:00   ` Luiz Capitulino [this message]
2010-06-28 22:01 ` [Qemu-devel] Re: [PATCH 0/7] 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=20100628190000.2a89aa29@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=armbru@redhat.com \
    --cc=avi@redhat.com \
    --cc=miguel.filho@gmail.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).