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 07/17] tap: Improve -netdev/netdev_add/-net/... bridge error reporting
Date: Wed, 27 May 2015 11:02:58 +0100	[thread overview]
Message-ID: <1432720988-20200-8-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>

When -netdev bridge fails, it first reports a specific error, then a
generic one, like this:

    $ qemu-system-x86_64 -netdev bridge,id=foo
    failed to launch bridge helper
    qemu-system-x86_64: -netdev bridge,id=foo: Device 'bridge' could not be initialized

The first message goes to stderr.  Wrong for HMP, because errors need
to go to the monitor there.

The second message goes to stderr for -netdev, to the monitor for HMP
netdev_add, and becomes the error reply for QMP netdev_add.

Convert net_bridge_run_helper() to Error, and propagate its errors
through net_init_bridge().  This ensures the error gets reported where
the user is, and suppresses the unwanted second message.

While there, improve the error messages a bit.

The above example becomes:

    $ qemu-system-x86_64 -netdev bridge,id=foo
    qemu-system-x86_64: -netdev bridge,id=foo: bridge helper failed

net_init_tap() also uses net_bridge_run_helper().  Propagate its
errors there as well.  Improves reporting these errors with -netdev
tap & friends.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1431691143-1015-7-git-send-email-armbru@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 net/tap.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index adb1022..23c81fa 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -437,7 +437,8 @@ static int recv_fd(int c)
     return len;
 }
 
-static int net_bridge_run_helper(const char *helper, const char *bridge)
+static int net_bridge_run_helper(const char *helper, const char *bridge,
+                                 Error **errp)
 {
     sigset_t oldmask, mask;
     int pid, status;
@@ -450,11 +451,16 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
     sigprocmask(SIG_BLOCK, &mask, &oldmask);
 
     if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
+        error_setg_errno(errp, errno, "socketpair() failed");
         return -1;
     }
 
     /* try to launch bridge helper */
     pid = fork();
+    if (pid < 0) {
+        error_setg_errno(errp, errno, "Can't fork bridge helper");
+        return -1;
+    }
     if (pid == 0) {
         int open_max = sysconf(_SC_OPEN_MAX), i;
         char fd_buf[6+10];
@@ -502,14 +508,16 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
         }
         _exit(1);
 
-    } else if (pid > 0) {
+    } else {
         int fd;
+        int saved_errno;
 
         close(sv[1]);
 
         do {
             fd = recv_fd(sv[0]);
         } while (fd == -1 && errno == EINTR);
+        saved_errno = errno;
 
         close(sv[0]);
 
@@ -518,22 +526,21 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
         }
         sigprocmask(SIG_SETMASK, &oldmask, NULL);
         if (fd < 0) {
-            fprintf(stderr, "failed to recv file descriptor\n");
+            error_setg_errno(errp, saved_errno,
+                             "failed to recv file descriptor");
             return -1;
         }
-
-        if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
-            return fd;
+        if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+            error_setg(errp, "bridge helper failed");
+            return -1;
         }
+        return fd;
     }
-    fprintf(stderr, "failed to launch bridge helper\n");
-    return -1;
 }
 
 int net_init_bridge(const NetClientOptions *opts, const char *name,
                     NetClientState *peer, Error **errp)
 {
-    /* FIXME error_setg(errp, ...) on failure */
     const NetdevBridgeOptions *bridge;
     const char *helper, *br;
     TAPState *s;
@@ -545,7 +552,7 @@ int net_init_bridge(const NetClientOptions *opts, const char *name,
     helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
     br     = bridge->has_br     ? bridge->br     : DEFAULT_BRIDGE_INTERFACE;
 
-    fd = net_bridge_run_helper(helper, br);
+    fd = net_bridge_run_helper(helper, br, errp);
     if (fd == -1) {
         return -1;
     }
@@ -792,7 +799,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
             return -1;
         }
 
-        fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE);
+        fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE,
+                                   errp);
         if (fd == -1) {
             return -1;
         }
-- 
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 ` [Qemu-devel] [PULL 03/17] net: Permit incremental conversion of init functions to Error Stefan Hajnoczi
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 ` Stefan Hajnoczi [this message]
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-8-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).