From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58112 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLe1G-0000Mo-AT for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:13:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLe1D-0002EV-RA for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:13:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9070) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLe1D-0002EC-Kb for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:13:39 -0400 Date: Mon, 7 Jun 2010 16:13:31 +0100 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] [PATCH 07/19] Convert netdev client types to use an enumeration Message-ID: <20100607151331.GD27291@redhat.com> References: <1275921752-29420-1-git-send-email-berrange@redhat.com> <1275921752-29420-8-git-send-email-berrange@redhat.com> <4C0D0B8E.30501@codemonkey.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4C0D0B8E.30501@codemonkey.ws> Reply-To: "Daniel P. Berrange" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org 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 > >--- > > 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 :|