From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58705 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLe33-0001il-UR for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:15:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLe31-0002eN-DF for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:15:33 -0400 Received: from mail-iw0-f173.google.com ([209.85.214.173]:48155) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLe31-0002eB-7Z for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:15:31 -0400 Received: by iwn41 with SMTP id 41so3600074iwn.4 for ; Mon, 07 Jun 2010 08:15:30 -0700 (PDT) Message-ID: <4C0D0D0E.2030707@codemonkey.ws> Date: Mon, 07 Jun 2010 10:15:26 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 16/19] Add a query-netdev command to QMP References: <1275921752-29420-1-git-send-email-berrange@redhat.com> <1275921752-29420-17-git-send-email-berrange@redhat.com> In-Reply-To: <1275921752-29420-17-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org On 06/07/2010 09:42 AM, Daniel P. Berrange wrote: > This adds a new QMP command called query-netdev to provide information > about the available netdev backends in the QEMU binary. There is no > existing '-netdev ?' support, but if there was, this would obsolete it > > The data format looks like > > [ > { > "name": "user", > "props": [ > { > "name": "type", > "help": "net client type (nic, tap etc.)", > "type": "string" > }, > I'm not sure it's a good idea to expose the help text. That bakes it into the ABI which seems bad. Regards, Anthony Liguori > { > "name": "name", > "help": "identifier for monitor commands", > "type": "string" > }, > { > "name": "hostname", > "help": "client hostname reported by the builtin DHCP server", > "type": "string" > }, > ... > ] > } > { > "name": "tap", > "props": [ > { > "name": "type", > "help": "net client type (nic, tap etc.)", > "type": "string" > }, > { > "name": "ifname", > "help": "interface name", > "type": "string" > }, > ... > ] > } > ... > ] > > Signed-off-by: Daniel P. Berrange > --- > monitor.c | 8 ++++++++ > net.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > net.h | 2 ++ > qemu-option.c | 4 ++++ > qemu-option.h | 4 ++++ > 5 files changed, 67 insertions(+), 0 deletions(-) > > diff --git a/monitor.c b/monitor.c > index 1c5157d..19f42f3 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -2552,6 +2552,14 @@ static const mon_cmd_t info_cmds[] = { > .mhandler.info_new = do_info_argv, > }, > { > + .name = "netdev", > + .args_type = "", > + .params = "", > + .help = "list valid netdev backend types", > + .user_print = monitor_user_noop, > + .mhandler.info_new = do_info_netdev, > + }, > + { > .name = "network", > .args_type = "", > .params = "", > diff --git a/net.c b/net.c > index 5349001..90929d4 100644 > --- a/net.c > +++ b/net.c > @@ -36,6 +36,8 @@ > #include "qemu-common.h" > #include "qemu_socket.h" > #include "hw/qdev.h" > +#include "qjson.h" > +#include "qlist.h" > > static QTAILQ_HEAD(, VLANState) vlans; > static QTAILQ_HEAD(, VLANClientState) non_vlan_clients; > @@ -1080,6 +1082,53 @@ static const struct { > }; > verify(ARRAY_SIZE(net_client_types) == NET_CLIENT_LAST); > > + > +void do_info_netdev(Monitor *mon, QObject **data) > +{ > + QList *backends = qlist_new(); > + int i, j; > + > + for (i = 0; i< ARRAY_SIZE(net_client_types) ; i++) { > + QObject *backend; > + QList *props = qlist_new(); > + > + if (i == NET_CLIENT_NIC || > + i == NET_CLIENT_DUMP|| > + i == NET_CLIENT_NONE) > + continue; > + > + for (j = 0 ; net_client_types[i].desc[j].name != NULL ; j++) { > + const QemuOptDesc *desc = net_client_types[i].desc + j; > + QObject *prop; > + > + if (strcmp(desc->name, "vlan") == 0) > + continue; > + > + if (desc->help) { > + prop = qobject_from_jsonf("{ 'name': %s, 'type': %s, 'help': %s }", > + desc->name, > + qemu_opt_type_to_string(desc->type), > + desc->help); > + } else { > + prop = qobject_from_jsonf("{ 'name': %s, 'type': %s }", > + desc->name, > + qemu_opt_type_to_string(desc->type)); > + } > + > + qlist_append_obj(props, prop); > + } > + > + backend = qobject_from_jsonf("{ 'name': %s, 'props': %p }", > + qemu_net_type_to_string(i), > + props); > + > + qlist_append_obj(backends, backend); > + } > + > + *data = qobject_from_jsonf("{ 'backends': %p }", backends); > +} > + > + > int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) > { > const char *name; > diff --git a/net.h b/net.h > index b83f615..9c0e385 100644 > --- a/net.h > +++ b/net.h > @@ -167,6 +167,8 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict); > int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data); > int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data); > > +void do_info_netdev(Monitor *mon, QObject **data); > + > #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" > #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" > #ifdef __sun__ > diff --git a/qemu-option.c b/qemu-option.c > index bb9cc43..f132a9b 100644 > --- a/qemu-option.c > +++ b/qemu-option.c > @@ -32,6 +32,10 @@ > #include "qemu-option.h" > #include "qerror.h" > > +QEMU_ENUM_IMPL(qemu_opt_type, QEMU_OPT_LAST, > + "string", "bool", "number", > + "size", "enum"); > + > /* > * Extracts the name of an option from the parameter string (p points at the > * first byte of the option name) > diff --git a/qemu-option.h b/qemu-option.h > index 3540a9b..9382cc3 100644 > --- a/qemu-option.h > +++ b/qemu-option.h > @@ -28,6 +28,7 @@ > > #include > #include "qemu-queue.h" > +#include "qemu-enum.h" > #include "qdict.h" > > enum QEMUOptionParType { > @@ -90,7 +91,10 @@ enum QemuOptType { > QEMU_OPT_NUMBER, /* simple number */ > QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */ > QEMU_OPT_ENUM, /* int, from user string validated against an enum */ > + > + QEMU_OPT_LAST, > }; > +QEMU_ENUM_DECL(qemu_opt_type); > > typedef struct QemuOptDesc { > const char *name; >