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: qemu-devel@nongnu.org, armbru@redhat.com
Subject: [Qemu-devel] Re: [PATCH 22/22] monitor/net: Convert do_info_network() to QObject/QMP
Date: Fri, 9 Apr 2010 14:52:20 -0300	[thread overview]
Message-ID: <20100409145220.7ba3854f@redhat.com> (raw)
In-Reply-To: <1270757799-31891-23-git-send-email-miguel.filho@gmail.com>

On Thu,  8 Apr 2010 17:16:39 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Each device is represented by a QDict. The returned QObject is a QList
> of all devices.
> 
> This commit slightly changes the monitor output when 'info network' is used.
> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  monitor.c |    3 +-
>  net.c     |  133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
>  net.h     |    6 ++-
>  3 files changed, 126 insertions(+), 16 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index 822dc27..0b3fdfc 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2604,7 +2604,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 ad01732..c59ae5b 100644
> --- a/net.c
> +++ b/net.c
> @@ -33,10 +33,10 @@
>  #include "net/util.h"
>  #include "monitor.h"
>  #include "sysemu.h"
> +#include "qstring.h"
>  #include "qemu-common.h"
>  #include "qemu_socket.h"
> -#include "qdict.h"
> -#include "qstring.h"
> +#include "qemu-objects.h"
>  #include "hw/qdev.h"
>  
>  static QTAILQ_HEAD(, VLANState) vlans;
> @@ -174,7 +174,7 @@ void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])
>      snprintf(mac, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
>               macaddr[0], macaddr[1], macaddr[2],
>               macaddr[3], macaddr[4], macaddr[5]);
> -
> +            
>      qdict_put(vc->info_dict, "macaddr", qstring_from_str(mac));
>      qdict_put(vc->info_dict, "model", qstring_from_str(vc->model));
>  }
> @@ -1224,26 +1224,131 @@ void net_set_boot_mask(int net_boot_mask)
>      }
>  }
>  
> -void do_info_network(Monitor *mon)
> +void vlan_devices_iter(QObject *obj, void *opaque)
> +{
> +
> +    Monitor *mon = opaque;
> +    QDict *net_device = qobject_to_qdict(obj);
> +        
> +    if (!qdict_haskey(net_device, "vlan"))
> +        return;
> +
> +    monitor_printf(mon, "  %s: vlan=%d ", qdict_get_str(net_device, "name"),
> +        (int)qdict_get_int(net_device, "vlan"));
> +    monitor_printf(mon,
> +        qstring_get_str(qdict_to_qstring(qdict_get_qdict(net_device, "info"))));
> +    
> +    monitor_printf(mon, " \n");
> +}
> +
> +void non_vlan_devices_iter(QObject *obj, void *opaque)
> +{
> +
> +    Monitor *mon = opaque;
> +    QDict *net_device = qobject_to_qdict(obj);
> +    
> +    if (qdict_haskey(net_device, "vlan"))
> +        return;
> +    
> +    monitor_printf(mon, "  %s: ", qdict_get_str(net_device, "name"));
> +    
> +    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");
> +        
> +}

 The iterators can be private, I think.

> +
> +void do_info_network_print(Monitor *mon, const QObject *ret_data)
> +{
> +    QList *qlist;
> +    
> +    qlist = qobject_to_qlist(ret_data);
> +    
> +    monitor_printf(mon, "Devices on VLANs:\n");
> +
> +    qlist_iter(qlist, vlan_devices_iter, mon);
> +
> +    monitor_printf(mon, "Devices not on any VLAN:\n");
> +    
> +    qlist_iter(qlist, non_vlan_devices_iter, mon);
> +    
> +}
> +
> +/**
> + * do_network_info(): Network information
> + *
> + * Each network device information is stored in a QDict and the
> + * returned QObject is a QList of all devices.
> + *
> + * The QDict contains the following:
> + *
> + * - "name": device name
> + * - "vlan": only present if the device is attached to a VLAN, it is the id
> + * of the VLAN
> + * - "info": it is a QDict containing any of the following: 
> + *          - "model": type of the device
> + *          - "macaddr": MAC address
> + *          - "script": path to script used to configure the device
> + *          - "downscript": path to script used to deconfigure the device
> + *          - "fd": handle to the device
> + *          - "ifname": name of the host device connected to the guest device
> + *          - "mcast": multicast address
> + *          - "cloned": true if the device is multicast clone
> + *          - "connection_from": IP/port pair of an incomming connection
> + *          - "connect_to": IP/port pair of an outgoing connection

 Any of them are mandatory or all of them are optional, meaning that
they depend on the device? If so, maybe it's better to explain a bit more.

> + *
> + * Example:
> + *
> + * [ { "name": "tap.0", "vlan": 0, 
> +       "info": { "script": "/etc/kvm/kvm-ifup", "downscript": "/etc/qemu-ifdown", 
> +       "ifname": "tap0" } }, 
> +     { "name": "e1000.0", "vlan": 1,
> +      "info": { "model": "e1000", "macaddr": "52:54:00:12:34:56" } } ]
> + */
> +void do_info_network(Monitor *mon, QObject **ret_data)
>  {
>      VLANState *vlan;
>      VLANClientState *vc;
> -
> +    QDict *net_device;
> +    QList *device_list;
> +    device_list = qlist_new();
> +        
>      QTAILQ_FOREACH(vlan, &vlans, next) {
> -        monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
> -
> +        QObject *obj;
> +        
>          QTAILQ_FOREACH(vc, &vlan->clients, next) {
> -            monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
> +
> +            obj = qobject_from_jsonf("{ 'vlan': %d, 'name': %s }", vlan->id, vc->name);
> +            net_device = qobject_to_qdict(obj);
> +            
> +            QINCREF(vc->info_dict);
> +            qdict_put(net_device, "info", vc->info_dict);
> +
> +            qlist_append(device_list, qobject_to_qdict(obj));
> +
>          }
>      }
> -    monitor_printf(mon, "Devices not on any VLAN:\n");
> +
>      QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
> -        monitor_printf(mon, "  %s: %s", vc->name, vc->info_str);
> -        if (vc->peer) {
> -            monitor_printf(mon, " peer=%s", vc->peer->name);
> -        }
> -        monitor_printf(mon, "\n");
> +        QObject *obj;
> +        
> +        obj = qobject_from_jsonf("{ 'name': %s", vc->name);
> +        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);
>  }
>  
>  void do_set_link(Monitor *mon, const QDict *qdict)
> diff --git a/net.h b/net.h
> index b744294..d1cf6ab 100644
> --- a/net.h
> +++ b/net.h
> @@ -6,6 +6,7 @@
>  #include "qemu-common.h"
>  #include "qdict.h"
>  #include "qemu-option.h"
> +#include "qobject.h"
>  #include "net/queue.h"
>  
>  struct MACAddr {
> @@ -117,7 +118,10 @@ 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 vlan_devices_iter(QObject *obj, void *opaque);
> +void non_vlan_devices_iter(QObject *obj, void *opaque);
> +void do_info_network_print(Monitor *mon, const QObject *ret_data);
> +void do_info_network(Monitor *mon, QObject **ret_data);
>  void do_set_link(Monitor *mon, const QDict *qdict);
>  
>  /* NIC info */

  reply	other threads:[~2010-04-09 17:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-08 20:16 [Qemu-devel] [PATCH 0/22] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 01/22] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-04-09 17:26   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 02/22] net: replace qemu_nic_format_info_str and VLANClientState->info_str by QDicts Miguel Di Ciurcio Filho
2010-04-09 17:41   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 03/22] net: dp8393x: replace qemu_format_nic_info_str by qemu_format_nic_info_dict Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 04/22] net: e1000: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 05/22] net: eepro100: " Miguel Di Ciurcio Filho
2010-04-09 17:42   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 06/22] net: ne2000: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 07/22] net: pcnet: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 08/22] net: lan9118: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 09/22] net: mcf_fec: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 10/22] net: mipsnet: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 11/22] net: rtl8139: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 12/22] net: smc91c111: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 13/22] net: stellaris_enet: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 14/22] net: usb-net: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 15/22] net: virtio-net: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 16/22] net: xilinx_ethlite: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 17/22] net: dump: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 18/22] net: slirp: " Miguel Di Ciurcio Filho
2010-04-09 17:42   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 19/22] net: socket: " Miguel Di Ciurcio Filho
2010-04-09 17:47   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 20/22] net: tap: replace qemu_format_nic_info_str by info_dict Miguel Di Ciurcio Filho
2010-04-09 17:48   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 21/22] net: vde: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 22/22] monitor/net: Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
2010-04-09 17:52   ` Luiz Capitulino [this message]
2010-04-09 17:25 ` [Qemu-devel] Re: [PATCH 0/22] " 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=20100409145220.7ba3854f@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=armbru@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).