From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 37/61] block/raw-posix: Employ error parameter
Date: Fri, 11 Oct 2013 17:05:27 +0200 [thread overview]
Message-ID: <1381503951-27985-38-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1381503951-27985-1-git-send-email-kwolf@redhat.com>
From: Max Reitz <mreitz@redhat.com>
Make use of the error parameter in the opening and creating functions in
block/raw-posix.c.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/raw-posix.c | 72 ++++++++++++++++++++++++++++++++++++----------
tests/qemu-iotests/051.out | 2 +-
2 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index f7f102d..6f03fbf 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -276,7 +276,7 @@ static QemuOptsList raw_runtime_opts = {
};
static int raw_open_common(BlockDriverState *bs, QDict *options,
- int bdrv_flags, int open_flags)
+ int bdrv_flags, int open_flags, Error **errp)
{
BDRVRawState *s = bs->opaque;
QemuOpts *opts;
@@ -287,8 +287,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
opts = qemu_opts_create_nofail(&raw_runtime_opts);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (error_is_set(&local_err)) {
- qerror_report_err(local_err);
- error_free(local_err);
+ error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
}
@@ -297,6 +296,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
ret = raw_normalize_devicepath(&filename);
if (ret != 0) {
+ error_setg_errno(errp, -ret, "Could not normalize device path");
goto fail;
}
@@ -310,6 +310,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
if (ret == -EROFS) {
ret = -EACCES;
}
+ error_setg_errno(errp, -ret, "Could not open file");
goto fail;
}
s->fd = fd;
@@ -318,6 +319,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
if (raw_set_aio(&s->aio_ctx, &s->use_aio, bdrv_flags)) {
qemu_close(fd);
ret = -errno;
+ error_setg_errno(errp, -ret, "Could not set AIO state");
goto fail;
}
#endif
@@ -339,9 +341,15 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
+ Error *local_err = NULL;
+ int ret;
s->type = FTYPE_FILE;
- return raw_open_common(bs, options, flags, 0);
+ ret = raw_open_common(bs, options, flags, 0, &local_err);
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
+ }
+ return ret;
}
static int raw_reopen_prepare(BDRVReopenState *state,
@@ -366,6 +374,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
* valid in the 'false' condition even if aio_ctx is set, and raw_set_aio()
* won't override aio_ctx if aio_ctx is non-NULL */
if (raw_set_aio(&s->aio_ctx, &raw_s->use_aio, state->flags)) {
+ error_setg(errp, "Could not set AIO state");
return -1;
}
#endif
@@ -417,6 +426,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
assert(!(raw_s->open_flags & O_CREAT));
raw_s->fd = qemu_open(state->bs->filename, raw_s->open_flags);
if (raw_s->fd == -1) {
+ error_setg_errno(errp, errno, "Could not reopen file");
ret = -1;
}
}
@@ -1060,12 +1070,15 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
0644);
if (fd < 0) {
result = -errno;
+ error_setg_errno(errp, -result, "Could not create file");
} else {
if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
result = -errno;
+ error_setg_errno(errp, -result, "Could not resize file");
}
if (qemu_close(fd) != 0) {
result = -errno;
+ error_setg_errno(errp, -result, "Could not close the new file");
}
}
return result;
@@ -1338,6 +1351,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
+ Error *local_err = NULL;
int ret;
const char *filename = qdict_get_str(options, "filename");
@@ -1381,8 +1395,11 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
}
#endif
- ret = raw_open_common(bs, options, flags, 0);
+ ret = raw_open_common(bs, options, flags, 0, &local_err);
if (ret < 0) {
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
+ }
return ret;
}
@@ -1390,6 +1407,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
ret = check_hdev_writable(s);
if (ret < 0) {
raw_close(bs);
+ error_setg_errno(errp, -ret, "The device is not writable");
return ret;
}
}
@@ -1525,15 +1543,23 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
}
fd = qemu_open(filename, O_WRONLY | O_BINARY);
- if (fd < 0)
- return -errno;
+ if (fd < 0) {
+ ret = -errno;
+ error_setg_errno(errp, -ret, "Could not open device");
+ return ret;
+ }
- if (fstat(fd, &stat_buf) < 0)
+ if (fstat(fd, &stat_buf) < 0) {
ret = -errno;
- else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode))
+ error_setg_errno(errp, -ret, "Could not stat device");
+ } else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode)) {
+ error_setg(errp,
+ "The given file is neither a block nor a character device");
ret = -ENODEV;
- else if (lseek(fd, 0, SEEK_END) < total_size * BDRV_SECTOR_SIZE)
+ } else if (lseek(fd, 0, SEEK_END) < total_size * BDRV_SECTOR_SIZE) {
+ error_setg(errp, "Device is too small");
ret = -ENOSPC;
+ }
qemu_close(fd);
return ret;
@@ -1575,14 +1601,19 @@ static int floppy_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
+ Error *local_err = NULL;
int ret;
s->type = FTYPE_FD;
/* open will not fail even if no floppy is inserted, so add O_NONBLOCK */
- ret = raw_open_common(bs, options, flags, O_NONBLOCK);
- if (ret)
+ ret = raw_open_common(bs, options, flags, O_NONBLOCK, &local_err);
+ if (ret) {
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
+ }
return ret;
+ }
/* close fd so that we can reopen it as needed */
qemu_close(s->fd);
@@ -1698,11 +1729,17 @@ static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
+ Error *local_err = NULL;
+ int ret;
s->type = FTYPE_CD;
/* open will not fail even if no CD is inserted, so add O_NONBLOCK */
- return raw_open_common(bs, options, flags, O_NONBLOCK);
+ ret = raw_open_common(bs, options, flags, O_NONBLOCK, &local_err);
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
+ }
+ return ret;
}
static int cdrom_probe_device(const char *filename)
@@ -1806,13 +1843,18 @@ static BlockDriver bdrv_host_cdrom = {
static int cdrom_open(BlockDriverState *bs, QDict *options, int flags)
{
BDRVRawState *s = bs->opaque;
+ Error *local_err = NULL;
int ret;
s->type = FTYPE_CD;
- ret = raw_open_common(bs, options, flags, 0);
- if (ret)
+ ret = raw_open_common(bs, options, flags, 0, &local_err);
+ if (ret) {
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
+ }
return ret;
+ }
/* make sure the door isn't locked at this time */
ioctl(s->fd, CDIOCALLOW);
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index 04bb236..e58776a 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -223,6 +223,6 @@ Testing: -drive file=foo:bar
QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown protocol
Testing: -drive file.filename=foo:bar
-QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open 'foo:bar': No such file or directory
+QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open file: No such file or directory
*** done
--
1.8.1.4
next prev parent reply other threads:[~2013-10-11 15:07 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-11 15:04 [Qemu-devel] [PULL 00/61] Block patches Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 01/61] blockjob: rename BlockJobType to BlockJobDriver Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 02/61] qapi: Introduce enum BlockJobType Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 03/61] qapi: make use of new BlockJobType Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 04/61] qapi: Add ImageInfoSpecific type Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 05/61] block: Add bdrv_get_specific_info Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 06/61] block/qapi: Human-readable ImageInfoSpecific dump Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 07/61] qcow2: Add support for ImageInfoSpecific Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 08/61] qemu-iotests: Discard specific info in _img_info Kevin Wolf
2013-10-11 15:04 ` [Qemu-devel] [PULL 09/61] qemu-iotests: Additional info from qemu-img info Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 10/61] qcow2: Alignment of snapshot table entries Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 11/61] qcow2: Use pread for inactive L1 in overlap check Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 12/61] qcow2: Free preallocated zero clusters Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 13/61] qcow2: Always use error path on writing snapshots Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 14/61] qcow2: Free allocated snapshot table on error Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 15/61] qcow2: Assert against snapshot name/ID overflow Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 16/61] block/get_block_status: avoid redundant callouts on raw devices Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 17/61] block: Add BlockDriver.bdrv_check_ext_snapshot Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 18/61] qemu-iotests: Discard preallocated zero clusters Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 19/61] ahci: set ahci mode on reset Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 20/61] block: qemu-iotests for vhdx, read sample dynamic image Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 21/61] qcow2: Add missing space in error message Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 22/61] qcow2: Remove wrong metadata overlap check Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 23/61] qcow2: Fix snapshot restoration in snapshot_create Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 24/61] qcow2: Use better type for numerical snapshot ID Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 25/61] block: Improve driver whitelist checks Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 26/61] qcow2: Use negated overflow check mask Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 27/61] qcow2: Make overlap check mask variable Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 28/61] qcow2: Add overlap-check options Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 29/61] qcow2: Array assigning options to OL check bits Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 30/61] qcow2: Add more overlap check bitmask macros Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 31/61] qcow2: Evaluate overlap check options Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 32/61] block/raw_bsd: Employ error parameter Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 33/61] block/raw-win32: " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 34/61] blkdebug: " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 35/61] blkverify: " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 36/61] qemu-iotests: move blank lines of output in case 059 Kevin Wolf
2013-10-11 15:05 ` Kevin Wolf [this message]
2013-10-11 15:05 ` [Qemu-devel] [PULL 38/61] tests: build the helper program by default Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 39/61] build: add command check-clean Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 40/61] vmdk: convert error code to use errp Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 41/61] vmdk: refuse enabling zeroed grain with flat images Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 42/61] qapi-types/visit.py: Pass whole expr dict for structs Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 43/61] qapi-types/visit.py: Inheritance " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 44/61] blockdev: Introduce DriveInfo.enable_auto_del Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 45/61] blockdev: 'blockdev-add' QMP command Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 46/61] blockdev: Separate ID generation from DriveInfo creation Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 47/61] blockdev: Pass QDict to blockdev_init() Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 48/61] blockdev: Move parsing of 'media' option to drive_init Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 49/61] blockdev: Move parsing of 'if' " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 50/61] blockdev: Moving parsing of geometry options " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 51/61] blockdev: Move parsing of 'boot' option " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 52/61] blockdev: Move bus/unit/index processing " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 53/61] blockdev: Move virtio-blk device creation " Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 54/61] blockdev: Remove IF_* check for read-only blockdev_init Kevin Wolf
2013-10-15 15:53 ` Stefan Weil
2013-10-15 15:59 ` Kevin Wolf
2013-10-15 16:02 ` Stefan Weil
2013-10-11 15:05 ` [Qemu-devel] [PULL 55/61] qemu-iotests: Check autodel behaviour for device_del Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 56/61] blockdev: Remove 'media' parameter from blockdev_init() Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 57/61] blockdev: Don't disable COR automatically with blockdev-add Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 58/61] blockdev: blockdev_init() error conversion Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 59/61] vmdk: Fix vmdk_parse_extents Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 60/61] qemu-io: Let "open" pass options to block driver Kevin Wolf
2013-10-11 15:05 ` [Qemu-devel] [PULL 61/61] qemu-iotests: Add test for inactive L2 overlap Kevin Wolf
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=1381503951-27985-38-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--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).