]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
net: Permit incremental conversion of init functions to Error
authorMarkus Armbruster <armbru@redhat.com>
Fri, 15 May 2015 11:58:50 +0000 (13:58 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Wed, 27 May 2015 08:51:04 +0000 (09:51 +0100)
Error reporting for netdev_add is broken: the net_client_init_fun[]
report the actual errors with (at best) error_report(), and their
caller net_client_init1() makes up a generic error on top.

For command line and HMP, this produces an mildly ugly error cascade.

In QMP, the actual errors go to stderr, and the generic error becomes
the command's error reply.

To fix this, we need to convert the net_client_init_fun[] to Error.

To permit fixing them one by one, add an Error ** parameter to the
net_client_init_fun[].  If the call fails without returning an Error,
make up the same generic Error as before.  But if it returns one, use
that instead.  Since none of them does so far, no functional change.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1431691143-1015-3-git-send-email-armbru@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12 files changed:
net/clients.h
net/dump.c
net/hub.c
net/l2tpv3.c
net/net.c
net/netmap.c
net/slirp.c
net/socket.c
net/tap-win32.c
net/tap.c
net/vde.c
net/vhost-user.c

index 2e8fedad8d1997f245a3cca5af3ee327434c878f..d47530e82fef54f4901b64f90f9b9920ed2cc586 100644 (file)
 #include "qapi-types.h"
 
 int net_init_dump(const NetClientOptions *opts, const char *name,
-                  NetClientState *peer);
+                  NetClientState *peer, Error **errp);
 
 #ifdef CONFIG_SLIRP
 int net_init_slirp(const NetClientOptions *opts, const char *name,
-                   NetClientState *peer);
+                   NetClientState *peer, Error **errp);
 #endif
 
 int net_init_hubport(const NetClientOptions *opts, const char *name,
-                     NetClientState *peer);
+                     NetClientState *peer, Error **errp);
 
 int net_init_socket(const NetClientOptions *opts, const char *name,
-                    NetClientState *peer);
+                    NetClientState *peer, Error **errp);
 
 int net_init_tap(const NetClientOptions *opts, const char *name,
-                 NetClientState *peer);
+                 NetClientState *peer, Error **errp);
 
 int net_init_bridge(const NetClientOptions *opts, const char *name,
-                    NetClientState *peer);
+                    NetClientState *peer, Error **errp);
 
 int net_init_l2tpv3(const NetClientOptions *opts, const char *name,
-                    NetClientState *peer);
+                    NetClientState *peer, Error **errp);
 #ifdef CONFIG_VDE
 int net_init_vde(const NetClientOptions *opts, const char *name,
-                 NetClientState *peer);
+                 NetClientState *peer, Error **errp);
 #endif
 
 #ifdef CONFIG_NETMAP
 int net_init_netmap(const NetClientOptions *opts, const char *name,
-                    NetClientState *peer);
+                    NetClientState *peer, Error **errp);
 #endif
 
 int net_init_vhost_user(const NetClientOptions *opts, const char *name,
-                        NetClientState *peer);
+                        NetClientState *peer, Error **errp);
 
 #endif /* QEMU_NET_CLIENTS_H */
index 9d3a09e3341af6ad8958fe960991be5a945cc16b..214e88a7687f15a5db88f3f504b04572a1841f18 100644 (file)
@@ -146,8 +146,9 @@ static int net_dump_init(NetClientState *peer, const char *device,
 }
 
 int net_init_dump(const NetClientOptions *opts, const char *name,
-                  NetClientState *peer)
+                  NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     int len;
     const char *file;
     char def_file[128];
index 261f8ccc3f4555e9a4dda5307cb278b6eabbe2a2..3047f12766886d7a50a8acab26800e05c82803bc 100644 (file)
--- a/net/hub.c
+++ b/net/hub.c
@@ -281,7 +281,7 @@ int net_hub_id_for_client(NetClientState *nc, int *id)
 }
 
 int net_init_hubport(const NetClientOptions *opts, const char *name,
-                     NetClientState *peer)
+                     NetClientState *peer, Error **errp)
 {
     const NetdevHubPortOptions *hubport;
 
index 8c598b09bc2fccb3044be434532f076ebee29854..ed395dc126bbf737f573ad33785120817190948a 100644 (file)
@@ -536,10 +536,9 @@ static NetClientInfo net_l2tpv3_info = {
 
 int net_init_l2tpv3(const NetClientOptions *opts,
                     const char *name,
-                    NetClientState *peer)
+                    NetClientState *peer, Error **errp)
 {
-
-
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevL2TPv3Options *l2tpv3;
     NetL2TPV3State *s;
     NetClientState *nc;
index d9aaeb5341ba058ea44466a6c868a748dd1ac34d..3295741d1d2761bcb32afdaf8994d373178955db 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -740,8 +740,9 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
 }
 
 static int net_init_nic(const NetClientOptions *opts, const char *name,
-                        NetClientState *peer)
+                        NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     int idx;
     NICInfo *nd;
     const NetLegacyNicOptions *nic;
@@ -809,7 +810,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
 static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
     const NetClientOptions *opts,
     const char *name,
-    NetClientState *peer) = {
+    NetClientState *peer, Error **errp) = {
         [NET_CLIENT_OPTIONS_KIND_NIC]       = net_init_nic,
 #ifdef CONFIG_SLIRP
         [NET_CLIENT_OPTIONS_KIND_USER]      = net_init_slirp,
@@ -902,10 +903,12 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
             peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
         }
 
-        if (net_client_init_fun[opts->kind](opts, name, peer) < 0) {
-            /* TODO push error reporting into init() methods */
-            error_set(errp, QERR_DEVICE_INIT_FAILED,
-                      NetClientOptionsKind_lookup[opts->kind]);
+        if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) {
+            /* FIXME drop when all init functions store an Error */
+            if (errp && !*errp) {
+                error_set(errp, QERR_DEVICE_INIT_FAILED,
+                          NetClientOptionsKind_lookup[opts->kind]);
+            }
             return -1;
         }
     }
index 0c1772b03f75deba82c0e1b430e21ae156a6d5da..69300eb1aef69187605a872cbc8804fc37cba53a 100644 (file)
@@ -446,8 +446,9 @@ static NetClientInfo net_netmap_info = {
  * ... -net netmap,ifname="..."
  */
 int net_init_netmap(const NetClientOptions *opts,
-        const char *name, NetClientState *peer)
+                    const char *name, NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevNetmapOptions *netmap_opts = opts->netmap;
     NetClientState *nc;
     NetmapPriv me;
index 9bbed7447add9763ee6b86d4530ac5dfffdf0bfd..0e15cf67503100a4e3c371aeaf71936e54b9b898 100644 (file)
@@ -737,8 +737,9 @@ static const char **slirp_dnssearch(const StringList *dnsname)
 }
 
 int net_init_slirp(const NetClientOptions *opts, const char *name,
-                   NetClientState *peer)
+                   NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     struct slirp_config_str *config;
     char *vnet;
     int ret;
index c30e03f5ae1fa0ddb25061eb12c1ffd0610dab8e..5a19aa18816f2f353f3b13164aee28634e7d14d2 100644 (file)
@@ -693,8 +693,9 @@ static int net_socket_udp_init(NetClientState *peer,
 }
 
 int net_init_socket(const NetClientOptions *opts, const char *name,
-                    NetClientState *peer)
+                    NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     Error *err = NULL;
     const NetdevSocketOptions *sock;
 
index 8aee611f7d25cf632af14a7ca7d26118e29cf29d..f6fc9610a7dcc49075982eed334604d249ada379 100644 (file)
@@ -752,8 +752,9 @@ static int tap_win32_init(NetClientState *peer, const char *model,
 }
 
 int net_init_tap(const NetClientOptions *opts, const char *name,
-                 NetClientState *peer)
+                 NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevTapOptions *tap;
 
     assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
index 968df46c8c1e5db13f3af5febf4936ea7be22378..8f06cb738253620503345ba411dee4a2f5cd8702 100644 (file)
--- a/net/tap.c
+++ b/net/tap.c
@@ -531,8 +531,9 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
 }
 
 int net_init_bridge(const NetClientOptions *opts, const char *name,
-                    NetClientState *peer)
+                    NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevBridgeOptions *bridge;
     const char *helper, *br;
 
@@ -699,8 +700,9 @@ static int get_fds(char *str, char *fds[], int max)
 }
 
 int net_init_tap(const NetClientOptions *opts, const char *name,
-                 NetClientState *peer)
+                 NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevTapOptions *tap;
     int fd, vnet_hdr = 0, i = 0, queues;
     /* for the no-fd, no-helper case */
index 2a619fbc813b3e2fe8b508f347348a6d115ab381..dacaa64b477769e54be4dea4c8d16f8c92091ffb 100644 (file)
--- a/net/vde.c
+++ b/net/vde.c
@@ -110,8 +110,9 @@ static int net_vde_init(NetClientState *peer, const char *model,
 }
 
 int net_init_vde(const NetClientOptions *opts, const char *name,
-                 NetClientState *peer)
+                 NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevVdeOptions *vde;
 
     assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
index 1d86a2be11b5fed25e12330f398d8a8a3be15513..11899c53c039153b30dc6e902f0d8345166333b2 100644 (file)
@@ -223,8 +223,9 @@ static int net_vhost_check_net(QemuOpts *opts, void *opaque)
 }
 
 int net_init_vhost_user(const NetClientOptions *opts, const char *name,
-                        NetClientState *peer)
+                        NetClientState *peer, Error **errp)
 {
+    /* FIXME error_setg(errp, ...) on failure */
     const NetdevVhostUserOptions *vhost_user_opts;
     CharDriverState *chr;