From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jason Wang <jasowang@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL v2 9/9] vhost-user: Improve -netdev/netdev_add/-net/... error reporting
Date: Tue, 9 Jun 2015 07:47:56 +0200 [thread overview]
Message-ID: <1433828876-10892-10-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1433828876-10892-1-git-send-email-armbru@redhat.com>
When -netdev vhost-user fails, it first reports a specific error, then
one or more generic ones, like this:
$ qemu-system-x86_64 -netdev vhost-user,id=foo,chardev=xxx
qemu-system-x86_64: -netdev vhost-user,id=foo,chardev=xxx: chardev "xxx" not found
qemu-system-x86_64: -netdev vhost-user,id=foo,chardev=xxx: No suitable chardev found
qemu-system-x86_64: -netdev vhost-user,id=foo,chardev=xxx: Device 'vhost-user' could not be initialized
With the command line, the messages go to stderr. In HMP, they go to
the monitor. In QMP, the last one becomes the error reply, and the
others go to stderr.
Convert net_init_vhost_user() and its helpers to Error. This
suppresses the unwanted unspecific error messages, and makes the
specific error the QMP error reply.
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
net/vhost-user.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 7e8a9ec..3930741 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -170,33 +170,34 @@ static int net_vhost_chardev_opts(void *opaque,
} else if (strcmp(name, "server") == 0) {
props->is_server = true;
} else {
- error_report("vhost-user does not support a chardev"
- " with the following option:\n %s = %s",
- name, value);
+ error_setg(errp,
+ "vhost-user does not support a chardev with option %s=%s",
+ name, value);
return -1;
}
return 0;
}
-static CharDriverState *net_vhost_parse_chardev(const NetdevVhostUserOptions *opts)
+static CharDriverState *net_vhost_parse_chardev(
+ const NetdevVhostUserOptions *opts, Error **errp)
{
CharDriverState *chr = qemu_chr_find(opts->chardev);
VhostUserChardevProps props;
if (chr == NULL) {
- error_report("chardev \"%s\" not found", opts->chardev);
+ error_setg(errp, "chardev \"%s\" not found", opts->chardev);
return NULL;
}
/* inspect chardev opts */
memset(&props, 0, sizeof(props));
- if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, NULL)) {
+ if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, errp)) {
return NULL;
}
if (!props.is_socket || !props.is_unix) {
- error_report("chardev \"%s\" is not a unix socket",
- opts->chardev);
+ error_setg(errp, "chardev \"%s\" is not a unix socket",
+ opts->chardev);
return NULL;
}
@@ -220,7 +221,7 @@ static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
if (strcmp(netdev, name) == 0 &&
strncmp(driver, virtio_name, strlen(virtio_name)) != 0) {
- error_report("vhost-user requires frontend driver virtio-net-*");
+ error_setg(errp, "vhost-user requires frontend driver virtio-net-*");
return -1;
}
@@ -230,7 +231,6 @@ static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
int net_init_vhost_user(const NetClientOptions *opts, const char *name,
NetClientState *peer, Error **errp)
{
- /* FIXME error_setg(errp, ...) on failure */
uint32_t queues;
const NetdevVhostUserOptions *vhost_user_opts;
CharDriverState *chr;
@@ -238,15 +238,14 @@ int net_init_vhost_user(const NetClientOptions *opts, const char *name,
assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
vhost_user_opts = opts->vhost_user;
- chr = net_vhost_parse_chardev(vhost_user_opts);
+ chr = net_vhost_parse_chardev(vhost_user_opts, errp);
if (!chr) {
- error_report("No suitable chardev found");
return -1;
}
/* verify net frontend */
if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
- (char *)name, NULL)) {
+ (char *)name, errp)) {
return -1;
}
--
1.9.3
next prev parent reply other threads:[~2015-06-09 5:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-09 5:47 [Qemu-devel] [PULL v2 0/9] Error reporting patches Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 1/9] vl: Report failure to sandbox at most once Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 2/9] vl: Print -device help " Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 3/9] vl: Fail right after first bad -object Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 4/9] QemuOpts: Drop qemu_opts_foreach() parameter abort_on_failure Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 5/9] QemuOpts: Convert qemu_opts_foreach() to Error Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 6/9] blkdebug: Simplify passing of Error through qemu_opts_foreach() Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 7/9] QemuOpts: Drop qemu_opt_foreach() parameter abort_on_failure Markus Armbruster
2015-06-09 5:47 ` [Qemu-devel] [PULL v2 8/9] QemuOpts: Convert qemu_opt_foreach() to Error Markus Armbruster
2015-06-09 5:47 ` Markus Armbruster [this message]
2015-06-09 10:07 ` [Qemu-devel] [PULL v2 0/9] Error reporting 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=1433828876-10892-10-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).