qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 07/19] Convert netdev client types to use an enu


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] [PATCH 07/19] Convert netdev client types to use an enumeration
Date: Mon, 7 Jun 2010 16:13:31 +0100
User-agent: Mutt/1.4.1i

On Mon, Jun 07, 2010 at 10:09:02AM -0500, Anthony Liguori wrote:
> On 06/07/2010 09:42 AM, Daniel P. Berrange wrote:
> >Declare an enumeration for all netdev client types, values
> >matching indexes in the net_client_types array. Use the
> >enum helpers for the string<->  int conversion of client types.
> >
> >Before:
> >
> >   $ qemu -net type=foo,sfs
> >   qemu: -net type=foo,sfs: Parameter 'type' expects a network client type
> >
> >After:
> >
> >   $ qemu -net type=foo,sfs
> >   qemu: -net type=foo,sfs: Parameter 'type' expects none, nic, user, tap, 
> >   socket, dump
> >
> >Signed-off-by: Daniel P. Berrange<address@hidden>
> >---
> >  net.c |  124 
> >  ++++++++++++++++++++++++++++++++++++++--------------------------
> >  1 files changed, 74 insertions(+), 50 deletions(-)
> >
> >diff --git a/net.c b/net.c
> >index efa8b3d..5349001 100644
> >--- a/net.c
> >+++ b/net.c
> >@@ -42,6 +42,36 @@ static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
> >
> >  int default_net = 1;
> >
> >+enum {
> >+    NET_CLIENT_NONE,
> >+    NET_CLIENT_NIC,
> >+#ifdef CONFIG_SLIRP
> >+    NET_CLIENT_USER,
> >+#endif
> >+    NET_CLIENT_TAP,
> >+    NET_CLIENT_SOCKET,
> >+#ifdef CONFIG_VDE
> >+    NET_CLIENT_VDE,
> >+#endif
> >+    NET_CLIENT_DUMP,
> >+
> >+    NET_CLIENT_LAST
> >+};
> >+
> >+QEMU_ENUM_DECL(qemu_net_type);
> >+QEMU_ENUM_IMPL(qemu_net_type, NET_CLIENT_LAST,
> >+           "none",
> >+           "nic",
> >+#ifdef CONFIG_SLIRP
> >+           "user",
> >+#endif
> >+           "tap",
> >+           "socket",
> >+#ifdef CONFIG_VDE
> >+           "vde",
> >+#endif
> >+           "dump");
> >+
> >  /***********************************************************/
> >  /* network device redirectors */
> >
> >@@ -844,18 +874,15 @@ typedef int (*net_client_init_func)(QemuOpts *opts,
> >  #define NET_MAX_DESC 20
> >
> >  static const struct {
> >-    const char *type;
> >      net_client_init_func init;
> >      QemuOptDesc desc[NET_MAX_DESC];
> >  } net_client_types[] = {
> >   
> 
> I think:
> 
>  [NET_CLIENT_NONE] = {
>             .desc = {...}
> },
> 
> Would be a bit more robust than relying on explicit ordering.

Ah, I didn't know you could do that for array initializers. That
should result in even stronger compile time validation which is always
nice.

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|



reply via email to

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