qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: [PATCH 7/7] monitor/net: introduce 'info netdev' with Q


From: Luiz Capitulino
Subject: [Qemu-devel] Re: [PATCH 7/7] monitor/net: introduce 'info netdev' with QMP support
Date: Mon, 28 Jun 2010 19:00:00 -0300

On Wed, 23 Jun 2010 12:40:03 -0300
Miguel Di Ciurcio Filho <address@hidden> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <address@hidden>
> ---
>  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 via email to

[Prev in Thread] Current Thread [Next in Thread]