From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com,
mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 17/17] blockdev: blockdev_init() error conversion
Date: Fri, 20 Sep 2013 13:54:30 +0200 [thread overview]
Message-ID: <1379678070-14346-18-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1379678070-14346-1-git-send-email-kwolf@redhat.com>
This gives us meaningful error messages for the blockdev-add QMP
command.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
blockdev.c | 59 +++++++++++++++++++++++++++++++++--------------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index ef00c6d..fd2ef7a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -269,7 +269,7 @@ static void bdrv_put_ref_bh_schedule(BlockDriverState *bs)
qemu_bh_schedule(s->bh);
}
-static int parse_block_error_action(const char *buf, bool is_read)
+static int parse_block_error_action(const char *buf, bool is_read, Error **errp)
{
if (!strcmp(buf, "ignore")) {
return BLOCKDEV_ON_ERROR_IGNORE;
@@ -280,8 +280,8 @@ static int parse_block_error_action(const char *buf, bool is_read)
} else if (!strcmp(buf, "report")) {
return BLOCKDEV_ON_ERROR_REPORT;
} else {
- error_report("'%s' invalid %s error action",
- buf, is_read ? "read" : "write");
+ error_setg(errp, "'%s' invalid %s error action",
+ buf, is_read ? "read" : "write");
return -1;
}
}
@@ -306,7 +306,8 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
/* Takes the ownership of bs_opts */
static DriveInfo *blockdev_init(QDict *bs_opts,
- BlockInterfaceType type)
+ BlockInterfaceType type,
+ Error **errp)
{
const char *buf;
const char *file = NULL;
@@ -330,15 +331,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
id = qdict_get_try_str(bs_opts, "id");
opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
if (error_is_set(&error)) {
- qerror_report_err(error);
- error_free(error);
+ error_propagate(errp, error);
return NULL;
}
qemu_opts_absorb_qdict(opts, bs_opts, &error);
if (error_is_set(&error)) {
- qerror_report_err(error);
- error_free(error);
+ error_propagate(errp, error);
return NULL;
}
@@ -358,7 +357,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
- error_report("invalid discard option");
+ error_setg(errp, "invalid discard option");
return NULL;
}
}
@@ -380,7 +379,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
} else if (!strcmp(buf, "threads")) {
/* this is the default */
} else {
- error_report("invalid aio option");
+ error_setg(errp, "invalid aio option");
return NULL;
}
}
@@ -397,9 +396,10 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
drv = bdrv_find_whitelisted_format(buf, ro);
if (!drv) {
if (!ro && bdrv_find_whitelisted_format(buf, !ro)) {
- error_report("'%s' can be only used as read-only device.", buf);
+ error_setg(errp, "'%s' can be only used as read-only device.",
+ buf);
} else {
- error_report("'%s' invalid format", buf);
+ error_setg(errp, "'%s' invalid format", buf);
}
return NULL;
}
@@ -436,20 +436,20 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
cfg.op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0);
if (!check_throttle_config(&cfg, &error)) {
- error_report("%s", error_get_pretty(error));
- error_free(error);
+ error_propagate(errp, error);
return NULL;
}
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) {
- error_report("werror is not supported by this bus type");
+ error_setg(errp, "werror is not supported by this bus type");
return NULL;
}
- on_write_error = parse_block_error_action(buf, 0);
- if (on_write_error < 0) {
+ on_write_error = parse_block_error_action(buf, 0, &error);
+ if (error_is_set(&error)) {
+ error_propagate(errp, error);
return NULL;
}
}
@@ -461,8 +461,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
return NULL;
}
- on_read_error = parse_block_error_action(buf, 1);
- if (on_read_error < 0) {
+ on_read_error = parse_block_error_action(buf, 1, &error);
+ if (error_is_set(&error)) {
+ error_propagate(errp, error);
return NULL;
}
}
@@ -515,8 +516,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
if (ret < 0) {
- error_report("could not open disk image %s: %s",
- file ?: dinfo->id, error_get_pretty(error));
+ error_setg(errp, "could not open disk image %s: %s",
+ file ?: dinfo->id, error_get_pretty(error));
+ error_free(error);
goto err;
}
@@ -863,9 +865,15 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
}
/* Actual block device init: Functionality shared with blockdev-add */
- dinfo = blockdev_init(bs_opts, type);
+ dinfo = blockdev_init(bs_opts, type, &local_err);
if (dinfo == NULL) {
+ if (error_is_set(&local_err)) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ }
goto fail;
+ } else {
+ assert(!error_is_set(&local_err));
}
/* Set legacy DriveInfo fields */
@@ -2152,7 +2160,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
QmpOutputVisitor *ov = qmp_output_visitor_new();
QObject *obj;
QDict *qdict;
- DriveInfo *dinfo;
Error *local_err = NULL;
/* Require an ID in the top level */
@@ -2186,9 +2193,9 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
qdict_flatten(qdict);
- dinfo = blockdev_init(qdict, IF_NONE);
- if (!dinfo) {
- error_setg(errp, "Could not open image");
+ blockdev_init(qdict, IF_NONE, &local_err);
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
goto fail;
}
--
1.8.1.4
next prev parent reply other threads:[~2013-09-20 11:55 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-20 11:54 [Qemu-devel] [PATCH 00/17] blockdev-add QMP command Kevin Wolf
2013-09-20 11:54 ` [Qemu-devel] [PATCH 01/17] qapi-types/visit.py: Pass whole expr dict for structs Kevin Wolf
2013-09-20 13:32 ` Max Reitz
2013-09-20 14:51 ` Eric Blake
2013-09-20 11:54 ` [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance " Kevin Wolf
2013-09-20 13:33 ` Max Reitz
2013-09-20 14:19 ` Kevin Wolf
2013-09-20 14:58 ` Eric Blake
2013-09-20 11:54 ` [Qemu-devel] [PATCH 03/17] blockdev: Introduce DriveInfo.enable_auto_del Kevin Wolf
2013-09-20 15:03 ` Eric Blake
2013-09-20 15:12 ` Kevin Wolf
2013-09-20 15:25 ` Eric Blake
2013-09-30 5:05 ` Wenchao Xia
2013-09-20 11:54 ` [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command Kevin Wolf
2013-09-20 13:34 ` Max Reitz
2013-09-20 14:57 ` Kevin Wolf
2013-09-20 14:01 ` Benoît Canet
2013-09-24 10:41 ` Paolo Bonzini
2013-09-24 11:10 ` Kevin Wolf
2013-09-20 15:22 ` Eric Blake
2013-09-20 15:34 ` Kevin Wolf
2013-09-24 5:18 ` Fam Zheng
2013-09-24 8:01 ` Kevin Wolf
2013-09-24 10:39 ` Paolo Bonzini
2013-09-20 11:54 ` [Qemu-devel] [PATCH 05/17] blockdev: Separate ID generation from DriveInfo creation Kevin Wolf
2013-09-23 9:01 ` Max Reitz
2013-09-23 15:45 ` Eric Blake
2013-09-30 5:24 ` Wenchao Xia
2013-09-20 11:54 ` [Qemu-devel] [PATCH 06/17] blockdev: Pass QDict to blockdev_init() Kevin Wolf
2013-09-20 14:11 ` Benoît Canet
2013-09-25 6:25 ` Fam Zheng
2013-09-20 11:54 ` [Qemu-devel] [PATCH 07/17] blockdev: Move parsing of 'media' option to drive_init Kevin Wolf
2013-09-20 14:28 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 08/17] blockdev: Move parsing of 'if' " Kevin Wolf
2013-09-20 14:47 ` Max Reitz
2013-09-20 15:04 ` Kevin Wolf
2013-09-20 14:50 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 09/17] blockdev: Moving parsing of geometry options " Kevin Wolf
2013-09-20 15:04 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 10/17] blockdev: Move parsing of 'boot' option " Kevin Wolf
2013-09-20 15:05 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 11/17] blockdev: Move bus/unit/index processing " Kevin Wolf
2013-09-23 9:03 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 12/17] blockdev: Move virtio-blk device creation " Kevin Wolf
2013-09-23 9:04 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 13/17] blockdev: Remove IF_* check for read-only blockdev_init Kevin Wolf
2013-09-23 8:00 ` Max Reitz
2013-09-23 8:08 ` Kevin Wolf
2013-09-20 11:54 ` [Qemu-devel] [PATCH 14/17] qemu-iotests: Check autodel behaviour for device_del Kevin Wolf
2013-09-23 9:06 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 15/17] blockdev: Remove 'media' parameter from blockdev_init() Kevin Wolf
2013-09-23 9:06 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 16/17] blockdev: Don't disable COR automatically with blockdev-add Kevin Wolf
2013-09-23 9:07 ` Max Reitz
2013-09-20 11:54 ` Kevin Wolf [this message]
2013-09-23 9:08 ` [Qemu-devel] [PATCH 17/17] blockdev: blockdev_init() error conversion Max Reitz
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=1379678070-14346-18-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=mreitz@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).