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 16/17] tap: Improve -netdev/netdev_add/-net/... tap error reporting
Date: Wed, 27 May 2015 11:03:07 +0100	[thread overview]
Message-ID: <1432720988-20200-17-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 tap fails, it first reports a specific error, then a
generic one, like this:

    $ qemu-system-x86_64 -netdev tap,id=foo
    qemu-system-x86_64: -netdev tap,id=foo: could not configure /dev/net/tun: Operation not permitted
    qemu-system-x86_64: -netdev tap,id=foo: Device 'tap' could not be initialized

With the command line, the messages go to stderr.  In HMP, they go to
the monitor.  In QMP, the second one becomes the error reply, and the
first one goes to stderr.

Convert net_init_tap() to Error.  This suppresses the unwanted second
message, and makes the specific error the QMP error reply.

[Dropped duplicate "and" from error message as suggested by Eric Blake:
"ifname=, script=, downscript=, and vnet_hdr=, "
"queues=, and vhostfds= are invalid with helper="
--Stefan]

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

diff --git a/net/tap.c b/net/tap.c
index c1ee4f1..d1ca314 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -713,7 +713,6 @@ static int get_fds(char *str, char *fds[], int max)
 int net_init_tap(const NetClientOptions *opts, const char *name,
                  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 */
@@ -731,7 +730,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
     /* QEMU vlans does not support multiqueue tap, in this case peer is set.
      * For -netdev, peer is always NULL. */
     if (peer && (tap->has_queues || tap->has_fds || tap->has_vhostfds)) {
-        error_report("Multiqueue tap cannot be used with QEMU vlans");
+        error_setg(errp, "Multiqueue tap cannot be used with QEMU vlans");
         return -1;
     }
 
@@ -739,15 +738,15 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
             tap->has_fds || tap->has_vhostfds) {
-            error_report("ifname=, script=, downscript=, vnet_hdr=, "
-                         "helper=, queues=, fds=, and vhostfds= "
-                         "are invalid with fd=");
+            error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
+                       "helper=, queues=, fds=, and vhostfds= "
+                       "are invalid with fd=");
             return -1;
         }
 
         fd = monitor_fd_param(cur_mon, tap->fd, &err);
         if (fd == -1) {
-            error_report_err(err);
+            error_propagate(errp, err);
             return -1;
         }
 
@@ -759,7 +758,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
                          script, downscript,
                          vhostfdname, vnet_hdr, fd, &err);
         if (err) {
-            error_report_err(err);
+            error_propagate(errp, err);
             return -1;
         }
     } else if (tap->has_fds) {
@@ -770,9 +769,9 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
             tap->has_vhostfd) {
-            error_report("ifname=, script=, downscript=, vnet_hdr=, "
-                         "helper=, queues=, and vhostfd= "
-                         "are invalid with fds=");
+            error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
+                       "helper=, queues=, and vhostfd= "
+                       "are invalid with fds=");
             return -1;
         }
 
@@ -780,8 +779,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
         if (tap->has_vhostfds) {
             nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
             if (nfds != nvhosts) {
-                error_report("The number of fds passed does not match the "
-                             "number of vhostfds passed");
+                error_setg(errp, "The number of fds passed does not match "
+                           "the number of vhostfds passed");
                 return -1;
             }
         }
@@ -789,7 +788,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
         for (i = 0; i < nfds; i++) {
             fd = monitor_fd_param(cur_mon, fds[i], &err);
             if (fd == -1) {
-                error_report_err(err);
+                error_propagate(errp, err);
                 return -1;
             }
 
@@ -798,7 +797,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
             if (i == 0) {
                 vnet_hdr = tap_probe_vnet_hdr(fd);
             } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
-                error_report("vnet_hdr not consistent across given tap fds");
+                error_setg(errp,
+                           "vnet_hdr not consistent across given tap fds");
                 return -1;
             }
 
@@ -807,15 +807,15 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
                              tap->has_vhostfds ? vhost_fds[i] : NULL,
                              vnet_hdr, fd, &err);
             if (err) {
-                error_report_err(err);
+                error_propagate(errp, err);
                 return -1;
             }
         }
     } else if (tap->has_helper) {
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {
-            error_report("ifname=, script=, downscript=, and vnet_hdr= "
-                         "queues=, and vhostfds= are invalid with helper=");
+            error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
+                       "queues=, and vhostfds= are invalid with helper=");
             return -1;
         }
 
@@ -832,13 +832,13 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
                          script, downscript, vhostfdname,
                          vnet_hdr, fd, &err);
         if (err) {
-            error_report_err(err);
+            error_propagate(errp, err);
             close(fd);
             return -1;
         }
     } else {
         if (tap->has_vhostfds) {
-            error_report("vhostfds= is invalid if fds= wasn't specified");
+            error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
             return -1;
         }
         script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
@@ -853,15 +853,14 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
 
         for (i = 0; i < queues; i++) {
             fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
-                              ifname, sizeof ifname, queues > 1, &err);
+                              ifname, sizeof ifname, queues > 1, errp);
             if (fd == -1) {
-                error_report_err(err);
                 return -1;
             }
 
             if (queues > 1 && i == 0 && !tap->has_ifname) {
                 if (tap_fd_get_ifname(fd, ifname)) {
-                    error_report("Fail to get ifname");
+                    error_setg(errp, "Fail to get ifname");
                     close(fd);
                     return -1;
                 }
@@ -872,7 +871,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
                              i >= 1 ? "no" : downscript,
                              vhostfdname, vnet_hdr, fd, &err);
             if (err) {
-                error_report_err(err);
+                error_propagate(errp, err);
                 close(fd);
                 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 ` [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 ` Stefan Hajnoczi [this message]
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-17-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).