qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 03/17] net: Permit incremental conversion of init functions to Error
Date: Wed, 27 May 2015 11:02:54 +0100	[thread overview]
Message-ID: <1432720988-20200-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1432720988-20200-1-git-send-email-stefanha@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

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>
---
 net/clients.h    | 20 ++++++++++----------
 net/dump.c       |  3 ++-
 net/hub.c        |  2 +-
 net/l2tpv3.c     |  5 ++---
 net/net.c        | 15 +++++++++------
 net/netmap.c     |  3 ++-
 net/slirp.c      |  3 ++-
 net/socket.c     |  3 ++-
 net/tap-win32.c  |  3 ++-
 net/tap.c        |  6 ++++--
 net/vde.c        |  3 ++-
 net/vhost-user.c |  3 ++-
 12 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/net/clients.h b/net/clients.h
index 2e8feda..d47530e 100644
--- a/net/clients.h
+++ b/net/clients.h
@@ -28,38 +28,38 @@
 #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 */
diff --git a/net/dump.c b/net/dump.c
index 9d3a09e..214e88a 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -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];
diff --git a/net/hub.c b/net/hub.c
index 261f8cc..3047f12 100644
--- 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;
 
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
index 8c598b0..ed395dc 100644
--- a/net/l2tpv3.c
+++ b/net/l2tpv3.c
@@ -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;
diff --git a/net/net.c b/net/net.c
index d9aaeb5..3295741 100644
--- 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;
         }
     }
diff --git a/net/netmap.c b/net/netmap.c
index 0c1772b..69300eb 100644
--- a/net/netmap.c
+++ b/net/netmap.c
@@ -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;
diff --git a/net/slirp.c b/net/slirp.c
index 9bbed74..0e15cf6 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -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;
diff --git a/net/socket.c b/net/socket.c
index c30e03f..5a19aa1 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -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;
 
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 8aee611..f6fc961 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -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);
diff --git a/net/tap.c b/net/tap.c
index 968df46..8f06cb7 100644
--- 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 */
diff --git a/net/vde.c b/net/vde.c
index 2a619fb..dacaa64 100644
--- 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);
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 1d86a2b..11899c5 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -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;
 
-- 
2.4.1

  parent reply	other threads:[~2015-05-27 10:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 10:02 [Qemu-devel] [PULL 00/17] Net patches Stefan Hajnoczi
2015-05-27 10:02 ` [Qemu-devel] [PULL 01/17] net: Change help text to list -netdev instead of -net by default Stefan Hajnoczi
2015-05-27 10:02 ` [Qemu-devel] [PULL 02/17] net: Improve error message for -net hubport a bit Stefan Hajnoczi
2015-05-27 10:02 ` Stefan Hajnoczi [this message]
2015-05-27 10:02 ` [Qemu-devel] [PULL 04/17] net: Improve -net nic error reporting Stefan Hajnoczi
2015-05-27 10:02 ` [Qemu-devel] [PULL 05/17] net/dump: Improve -net/host_net_add dump " Stefan Hajnoczi
2015-05-27 10:02 ` [Qemu-devel] [PULL 06/17] tap: net_tap_fd_init() can't fail, drop dead error handling Stefan Hajnoczi
2015-05-27 10:02 ` [Qemu-devel] [PULL 07/17] tap: Improve -netdev/netdev_add/-net/... bridge error reporting Stefan Hajnoczi
2015-05-27 10:02 ` [Qemu-devel] [PULL 08/17] tap: Convert tap_set_sndbuf() to Error Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 09/17] tap: Convert net_init_tap_one() " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 10/17] tap: Convert launch_script() " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 11/17] tap: Permit incremental conversion of tap_open() " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 12/17] tap-linux: Convert " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 13/17] tap-bsd: " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 14/17] tap-solaris: " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 15/17] tap: Finish conversion of " Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 16/17] tap: Improve -netdev/netdev_add/-net/... tap error reporting Stefan Hajnoczi
2015-05-27 10:03 ` [Qemu-devel] [PULL 17/17] net/net: Record usage status of mac address Stefan Hajnoczi
2015-05-28 11:26 ` [Qemu-devel] [PULL 00/17] Net patches Peter Maydell

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=1432720988-20200-4-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=armbru@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).