|
|
9ae3a8 |
From 8d4ddeff8f248b561affa518acc19739b76e2f08 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 4 Nov 2013 22:32:11 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 18/87] block: Error parameter for open functions
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383604354-12743-21-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55320
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 20/43] block: Error parameter for open functions
|
|
|
9ae3a8 |
Bugzilla: 1026524
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: 1026524
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Add an Error ** parameter to bdrv_open, bdrv_file_open and associated
|
|
|
9ae3a8 |
functions to allow more specific error messages.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 34b5d2c68eb4082c288e70fb99c61af8f7b96fde)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
block/blkverify.c
|
|
|
9ae3a8 |
block/vmdk.c
|
|
|
9ae3a8 |
block/vvfat.c
|
|
|
9ae3a8 |
blockdev.c
|
|
|
9ae3a8 |
hw/block/xen_disk.c
|
|
|
9ae3a8 |
qemu-io.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
All files conflict because the series "Implement reference count for
|
|
|
9ae3a8 |
BlockDriverState" has not yet been backported which "replaces"
|
|
|
9ae3a8 |
bdrv_delete by bdrv_unref.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
blockdev.c conflicts because the series "block: drive-backup live backup
|
|
|
9ae3a8 |
command command" has not yet been backported.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
qemu-io.c conflicts because the series "Make qemu-io commands available
|
|
|
9ae3a8 |
in the monitor" has not yet been backported (esp. commit 734c3b85c).
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 100 ++++++++++++++++++++++++++++++++------------------
|
|
|
9ae3a8 |
block/blkdebug.c | 4 +-
|
|
|
9ae3a8 |
block/blkverify.c | 8 +++-
|
|
|
9ae3a8 |
block/cow.c | 5 ++-
|
|
|
9ae3a8 |
block/mirror.c | 5 ++-
|
|
|
9ae3a8 |
block/qcow.c | 5 ++-
|
|
|
9ae3a8 |
block/qcow2.c | 4 +-
|
|
|
9ae3a8 |
block/qed.c | 6 ++-
|
|
|
9ae3a8 |
block/sheepdog.c | 10 ++++-
|
|
|
9ae3a8 |
block/vmdk.c | 11 +++++-
|
|
|
9ae3a8 |
block/vvfat.c | 6 ++-
|
|
|
9ae3a8 |
blockdev.c | 26 ++++++-------
|
|
|
9ae3a8 |
hw/block/xen_disk.c | 7 +++-
|
|
|
9ae3a8 |
include/block/block.h | 6 +--
|
|
|
9ae3a8 |
qemu-img.c | 21 +++++++----
|
|
|
9ae3a8 |
qemu-io.c | 14 +++++--
|
|
|
9ae3a8 |
qemu-nbd.c | 6 ++-
|
|
|
9ae3a8 |
17 files changed, 161 insertions(+), 83 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 100 +++++++++++++++++++++++++++++++-----------------
|
|
|
9ae3a8 |
block/blkdebug.c | 4 +-
|
|
|
9ae3a8 |
block/blkverify.c | 8 +++-
|
|
|
9ae3a8 |
block/cow.c | 5 ++-
|
|
|
9ae3a8 |
block/mirror.c | 5 +-
|
|
|
9ae3a8 |
block/qcow.c | 5 ++-
|
|
|
9ae3a8 |
block/qcow2.c | 4 +-
|
|
|
9ae3a8 |
block/qed.c | 6 ++-
|
|
|
9ae3a8 |
block/sheepdog.c | 10 ++++-
|
|
|
9ae3a8 |
block/vmdk.c | 11 ++++-
|
|
|
9ae3a8 |
block/vvfat.c | 6 ++-
|
|
|
9ae3a8 |
blockdev.c | 26 +++++-------
|
|
|
9ae3a8 |
hw/block/xen_disk.c | 7 +++-
|
|
|
9ae3a8 |
include/block/block.h | 6 +-
|
|
|
9ae3a8 |
qemu-img.c | 21 +++++++---
|
|
|
9ae3a8 |
qemu-io.c | 14 +++++--
|
|
|
9ae3a8 |
qemu-nbd.c | 6 ++-
|
|
|
9ae3a8 |
17 files changed, 161 insertions(+), 83 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index 0cb5ac9..cb99faf 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -524,7 +524,7 @@ BlockDriver *bdrv_find_protocol(const char *filename,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int find_image_format(BlockDriverState *bs, const char *filename,
|
|
|
9ae3a8 |
- BlockDriver **pdrv)
|
|
|
9ae3a8 |
+ BlockDriver **pdrv, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int score, score_max;
|
|
|
9ae3a8 |
BlockDriver *drv1, *drv;
|
|
|
9ae3a8 |
@@ -535,6 +535,7 @@ static int find_image_format(BlockDriverState *bs, const char *filename,
|
|
|
9ae3a8 |
if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {
|
|
|
9ae3a8 |
drv = bdrv_find_format("raw");
|
|
|
9ae3a8 |
if (!drv) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Could not find raw image format");
|
|
|
9ae3a8 |
ret = -ENOENT;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
*pdrv = drv;
|
|
|
9ae3a8 |
@@ -543,6 +544,8 @@ static int find_image_format(BlockDriverState *bs, const char *filename,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read image for determining its "
|
|
|
9ae3a8 |
+ "format");
|
|
|
9ae3a8 |
*pdrv = NULL;
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -559,6 +562,8 @@ static int find_image_format(BlockDriverState *bs, const char *filename,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (!drv) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Could not determine image format: No compatible "
|
|
|
9ae3a8 |
+ "driver found");
|
|
|
9ae3a8 |
ret = -ENOENT;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
*pdrv = drv;
|
|
|
9ae3a8 |
@@ -678,10 +683,11 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
|
|
|
9ae3a8 |
* Removes all processed options from *options.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
|
|
|
9ae3a8 |
- QDict *options, int flags, BlockDriver *drv)
|
|
|
9ae3a8 |
+ QDict *options, int flags, BlockDriver *drv, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret, open_flags;
|
|
|
9ae3a8 |
const char *filename;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
assert(drv != NULL);
|
|
|
9ae3a8 |
assert(bs->file == NULL);
|
|
|
9ae3a8 |
@@ -710,6 +716,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
|
|
|
9ae3a8 |
bs->read_only = !(open_flags & BDRV_O_RDWR);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Driver '%s' is not whitelisted", drv->format_name);
|
|
|
9ae3a8 |
return -ENOTSUP;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -733,26 +740,33 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
|
|
|
9ae3a8 |
if (drv->bdrv_file_open) {
|
|
|
9ae3a8 |
assert(file == NULL);
|
|
|
9ae3a8 |
assert(drv->bdrv_parse_filename || filename != NULL);
|
|
|
9ae3a8 |
- ret = drv->bdrv_file_open(bs, options, open_flags, NULL);
|
|
|
9ae3a8 |
+ ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
if (file == NULL) {
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't use '%s' as a "
|
|
|
9ae3a8 |
- "block driver for the protocol level",
|
|
|
9ae3a8 |
- drv->format_name);
|
|
|
9ae3a8 |
+ error_setg(errp, "Can't use '%s' as a block driver for the "
|
|
|
9ae3a8 |
+ "protocol level", drv->format_name);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto free_and_fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
assert(file != NULL);
|
|
|
9ae3a8 |
bs->file = file;
|
|
|
9ae3a8 |
- ret = drv->bdrv_open(bs, options, open_flags, NULL);
|
|
|
9ae3a8 |
+ ret = drv->bdrv_open(bs, options, open_flags, &local_err);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
+ } else if (filename) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not open '%s'", filename);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not open image");
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
goto free_and_fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = refresh_total_sectors(bs, bs->total_sectors);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not refresh total sector count");
|
|
|
9ae3a8 |
goto free_and_fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -781,12 +795,13 @@ free_and_fail:
|
|
|
9ae3a8 |
* dictionary, it needs to use QINCREF() before calling bdrv_file_open.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
int bdrv_file_open(BlockDriverState **pbs, const char *filename,
|
|
|
9ae3a8 |
- QDict *options, int flags)
|
|
|
9ae3a8 |
+ QDict *options, int flags, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BlockDriverState *bs;
|
|
|
9ae3a8 |
BlockDriver *drv;
|
|
|
9ae3a8 |
const char *drvname;
|
|
|
9ae3a8 |
bool allow_protocol_prefix = false;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* NULL means an empty set of options */
|
|
|
9ae3a8 |
@@ -805,8 +820,8 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
|
|
|
9ae3a8 |
qdict_put(options, "filename", qstring_from_str(filename));
|
|
|
9ae3a8 |
allow_protocol_prefix = true;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't specify 'file' and "
|
|
|
9ae3a8 |
- "'filename' options at the same time");
|
|
|
9ae3a8 |
+ error_setg(errp, "Can't specify 'file' and 'filename' options at the "
|
|
|
9ae3a8 |
+ "same time");
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -815,53 +830,53 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
|
|
|
9ae3a8 |
drvname = qdict_get_try_str(options, "driver");
|
|
|
9ae3a8 |
if (drvname) {
|
|
|
9ae3a8 |
drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
|
|
|
9ae3a8 |
+ if (!drv) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Unknown driver '%s'", drvname);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
qdict_del(options, "driver");
|
|
|
9ae3a8 |
} else if (filename) {
|
|
|
9ae3a8 |
drv = bdrv_find_protocol(filename, allow_protocol_prefix);
|
|
|
9ae3a8 |
if (!drv) {
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Unknown protocol");
|
|
|
9ae3a8 |
+ error_setg(errp, "Unknown protocol");
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR,
|
|
|
9ae3a8 |
- "Must specify either driver or file");
|
|
|
9ae3a8 |
+ error_setg(errp, "Must specify either driver or file");
|
|
|
9ae3a8 |
drv = NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (!drv) {
|
|
|
9ae3a8 |
+ /* errp has been set already */
|
|
|
9ae3a8 |
ret = -ENOENT;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Parse the filename and open it */
|
|
|
9ae3a8 |
if (drv->bdrv_parse_filename && filename) {
|
|
|
9ae3a8 |
- Error *local_err = NULL;
|
|
|
9ae3a8 |
drv->bdrv_parse_filename(filename, options, &local_err);
|
|
|
9ae3a8 |
if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
- qerror_report_err(local_err);
|
|
|
9ae3a8 |
- error_free(local_err);
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
qdict_del(options, "filename");
|
|
|
9ae3a8 |
} else if (!drv->bdrv_parse_filename && !filename) {
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR,
|
|
|
9ae3a8 |
- "The '%s' block driver requires a file name",
|
|
|
9ae3a8 |
- drv->format_name);
|
|
|
9ae3a8 |
+ error_setg(errp, "The '%s' block driver requires a file name",
|
|
|
9ae3a8 |
+ drv->format_name);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_open_common(bs, NULL, options, flags, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Check if any unknown options were used */
|
|
|
9ae3a8 |
if (qdict_size(options) != 0) {
|
|
|
9ae3a8 |
const QDictEntry *entry = qdict_first(options);
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Block protocol '%s' doesn't "
|
|
|
9ae3a8 |
- "support the option '%s'",
|
|
|
9ae3a8 |
- drv->format_name, entry->key);
|
|
|
9ae3a8 |
+ error_setg(errp, "Block protocol '%s' doesn't support the option '%s'",
|
|
|
9ae3a8 |
+ drv->format_name, entry->key);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -888,11 +903,12 @@ fail:
|
|
|
9ae3a8 |
* function (even on failure), so if the caller intends to reuse the dictionary,
|
|
|
9ae3a8 |
* it needs to use QINCREF() before calling bdrv_file_open.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
-int bdrv_open_backing_file(BlockDriverState *bs, QDict *options)
|
|
|
9ae3a8 |
+int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
char backing_filename[PATH_MAX];
|
|
|
9ae3a8 |
int back_flags, ret;
|
|
|
9ae3a8 |
BlockDriver *back_drv = NULL;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (bs->backing_hd != NULL) {
|
|
|
9ae3a8 |
QDECREF(options);
|
|
|
9ae3a8 |
@@ -925,11 +941,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_open(bs->backing_hd,
|
|
|
9ae3a8 |
*backing_filename ? backing_filename : NULL, options,
|
|
|
9ae3a8 |
- back_flags, back_drv);
|
|
|
9ae3a8 |
+ back_flags, back_drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
bdrv_delete(bs->backing_hd);
|
|
|
9ae3a8 |
bs->backing_hd = NULL;
|
|
|
9ae3a8 |
bs->open_flags |= BDRV_O_NO_BACKING;
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
@@ -963,7 +980,7 @@ static void extract_subqdict(QDict *src, QDict **dst, const char *start)
|
|
|
9ae3a8 |
* dictionary, it needs to use QINCREF() before calling bdrv_open.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
- int flags, BlockDriver *drv)
|
|
|
9ae3a8 |
+ int flags, BlockDriver *drv, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
/* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
|
|
|
9ae3a8 |
@@ -971,6 +988,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
BlockDriverState *file = NULL;
|
|
|
9ae3a8 |
QDict *file_options = NULL;
|
|
|
9ae3a8 |
const char *drvname;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* NULL means an empty set of options */
|
|
|
9ae3a8 |
if (options == NULL) {
|
|
|
9ae3a8 |
@@ -989,7 +1007,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
char backing_filename[PATH_MAX];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (qdict_size(options) != 0) {
|
|
|
9ae3a8 |
- error_report("Can't use snapshot=on with driver-specific options");
|
|
|
9ae3a8 |
+ error_setg(errp, "Can't use snapshot=on with driver-specific options");
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1000,7 +1018,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* if there is a backing file, use it */
|
|
|
9ae3a8 |
bs1 = bdrv_new("");
|
|
|
9ae3a8 |
- ret = bdrv_open(bs1, filename, NULL, 0, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
bdrv_delete(bs1);
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
@@ -1011,6 +1029,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not get temporary filename");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1019,6 +1038,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
snprintf(backing_filename, sizeof(backing_filename),
|
|
|
9ae3a8 |
"%s", filename);
|
|
|
9ae3a8 |
} else if (!realpath(filename, backing_filename)) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
|
|
|
9ae3a8 |
ret = -errno;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1038,6 +1058,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options);
|
|
|
9ae3a8 |
free_option_parameters(create_options);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not create temporary overlay "
|
|
|
9ae3a8 |
+ "'%s'", tmp_filename);
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1054,7 +1076,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
extract_subqdict(options, &file_options, "file.");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_file_open(&file, filename, file_options,
|
|
|
9ae3a8 |
- bdrv_open_flags(bs, flags | BDRV_O_UNMAP));
|
|
|
9ae3a8 |
+ bdrv_open_flags(bs, flags | BDRV_O_UNMAP), &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1067,7 +1089,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (!drv) {
|
|
|
9ae3a8 |
- ret = find_image_format(file, filename, &drv;;
|
|
|
9ae3a8 |
+ ret = find_image_format(file, filename, &drv, &local_err);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (!drv) {
|
|
|
9ae3a8 |
@@ -1075,7 +1097,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Open the image */
|
|
|
9ae3a8 |
- ret = bdrv_open_common(bs, file, options, flags, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open_common(bs, file, options, flags, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
goto unlink_and_fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1090,7 +1112,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
QDict *backing_options;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
extract_subqdict(options, &backing_options, "backing.");
|
|
|
9ae3a8 |
- ret = bdrv_open_backing_file(bs, backing_options);
|
|
|
9ae3a8 |
+ ret = bdrv_open_backing_file(bs, backing_options, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
goto close_and_fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1099,9 +1121,9 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
/* Check if any unknown options were used */
|
|
|
9ae3a8 |
if (qdict_size(options) != 0) {
|
|
|
9ae3a8 |
const QDictEntry *entry = qdict_first(options);
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Block format '%s' used by "
|
|
|
9ae3a8 |
- "device '%s' doesn't support the option '%s'",
|
|
|
9ae3a8 |
- drv->format_name, bs->device_name, entry->key);
|
|
|
9ae3a8 |
+ error_setg(errp, "Block format '%s' used by device '%s' doesn't "
|
|
|
9ae3a8 |
+ "support the option '%s'", drv->format_name, bs->device_name,
|
|
|
9ae3a8 |
+ entry->key);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto close_and_fail;
|
|
|
9ae3a8 |
@@ -1130,11 +1152,17 @@ fail:
|
|
|
9ae3a8 |
QDECREF(bs->options);
|
|
|
9ae3a8 |
QDECREF(options);
|
|
|
9ae3a8 |
bs->options = NULL;
|
|
|
9ae3a8 |
+ if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
close_and_fail:
|
|
|
9ae3a8 |
bdrv_close(bs);
|
|
|
9ae3a8 |
QDECREF(options);
|
|
|
9ae3a8 |
+ if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -4813,7 +4841,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
|
|
9ae3a8 |
bs = bdrv_new("");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
|
|
|
9ae3a8 |
- backing_drv);
|
|
|
9ae3a8 |
+ backing_drv, NULL);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
error_setg_errno(errp, -ret, "Could not open '%s'",
|
|
|
9ae3a8 |
backing_file->value.s);
|
|
|
9ae3a8 |
diff --git a/block/blkdebug.c b/block/blkdebug.c
|
|
|
9ae3a8 |
index 114c4c9..eda2810 100644
|
|
|
9ae3a8 |
--- a/block/blkdebug.c
|
|
|
9ae3a8 |
+++ b/block/blkdebug.c
|
|
|
9ae3a8 |
@@ -384,8 +384,10 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs->file, filename, NULL, flags);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs->file, filename, NULL, flags, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/blkverify.c b/block/blkverify.c
|
|
|
9ae3a8 |
index 5d716bb..cceb88f 100644
|
|
|
9ae3a8 |
--- a/block/blkverify.c
|
|
|
9ae3a8 |
+++ b/block/blkverify.c
|
|
|
9ae3a8 |
@@ -141,8 +141,10 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs->file, raw, NULL, flags);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs->file, raw, NULL, flags, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -154,8 +156,10 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
s->test_file = bdrv_new("");
|
|
|
9ae3a8 |
- ret = bdrv_open(s->test_file, filename, NULL, flags, NULL);
|
|
|
9ae3a8 |
+ ret = bdrv_open(s->test_file, filename, NULL, flags, NULL, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
bdrv_delete(s->test_file);
|
|
|
9ae3a8 |
s->test_file = NULL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
diff --git a/block/cow.c b/block/cow.c
|
|
|
9ae3a8 |
index c1d2dc8..8e00f8f 100644
|
|
|
9ae3a8 |
--- a/block/cow.c
|
|
|
9ae3a8 |
+++ b/block/cow.c
|
|
|
9ae3a8 |
@@ -302,6 +302,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
struct stat st;
|
|
|
9ae3a8 |
int64_t image_sectors = 0;
|
|
|
9ae3a8 |
const char *image_filename = NULL;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
BlockDriverState *cow_bs;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -320,8 +321,10 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
9ae3a8 |
index dad1e3e..6fa733e 100644
|
|
|
9ae3a8 |
--- a/block/mirror.c
|
|
|
9ae3a8 |
+++ b/block/mirror.c
|
|
|
9ae3a8 |
@@ -505,14 +505,15 @@ static void mirror_iostatus_reset(BlockJob *job)
|
|
|
9ae3a8 |
static void mirror_complete(BlockJob *job, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_open_backing_file(s->target, NULL);
|
|
|
9ae3a8 |
+ ret = bdrv_open_backing_file(s->target, NULL, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
char backing_filename[PATH_MAX];
|
|
|
9ae3a8 |
bdrv_get_full_backing_filename(s->target, backing_filename,
|
|
|
9ae3a8 |
sizeof(backing_filename));
|
|
|
9ae3a8 |
- error_setg_file_open(errp, -ret, backing_filename);
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (!s->synced) {
|
|
|
9ae3a8 |
diff --git a/block/qcow.c b/block/qcow.c
|
|
|
9ae3a8 |
index 1a6926f..41a578c 100644
|
|
|
9ae3a8 |
--- a/block/qcow.c
|
|
|
9ae3a8 |
+++ b/block/qcow.c
|
|
|
9ae3a8 |
@@ -668,6 +668,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
int64_t total_size = 0;
|
|
|
9ae3a8 |
const char *backing_file = NULL;
|
|
|
9ae3a8 |
int flags = 0;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
BlockDriverState *qcow_bs;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -688,8 +689,10 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
9ae3a8 |
index b6e50af..a2fca7a 100644
|
|
|
9ae3a8 |
--- a/block/qcow2.c
|
|
|
9ae3a8 |
+++ b/block/qcow2.c
|
|
|
9ae3a8 |
@@ -1369,7 +1369,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, NULL);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1422,7 +1422,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
BlockDriver* drv = bdrv_find_format("qcow2");
|
|
|
9ae3a8 |
assert(drv != NULL);
|
|
|
9ae3a8 |
ret = bdrv_open(bs, filename, NULL,
|
|
|
9ae3a8 |
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv);
|
|
|
9ae3a8 |
+ BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, NULL);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/block/qed.c b/block/qed.c
|
|
|
9ae3a8 |
index c56b5e2..fa35fe2 100644
|
|
|
9ae3a8 |
--- a/block/qed.c
|
|
|
9ae3a8 |
+++ b/block/qed.c
|
|
|
9ae3a8 |
@@ -551,6 +551,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
|
|
|
9ae3a8 |
QEDHeader le_header;
|
|
|
9ae3a8 |
uint8_t *l1_table = NULL;
|
|
|
9ae3a8 |
size_t l1_size = header.cluster_size * header.table_size;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret = 0;
|
|
|
9ae3a8 |
BlockDriverState *bs = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -559,8 +560,11 @@ static int qed_create(const char *filename, uint32_t cluster_size,
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB,
|
|
|
9ae3a8 |
+ &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/sheepdog.c b/block/sheepdog.c
|
|
|
9ae3a8 |
index 952d703..e7c4448 100644
|
|
|
9ae3a8 |
--- a/block/sheepdog.c
|
|
|
9ae3a8 |
+++ b/block/sheepdog.c
|
|
|
9ae3a8 |
@@ -1418,10 +1418,13 @@ static int sd_prealloc(const char *filename)
|
|
|
9ae3a8 |
uint32_t idx, max_idx;
|
|
|
9ae3a8 |
int64_t vdi_size;
|
|
|
9ae3a8 |
void *buf = g_malloc0(SD_DATA_OBJ_SIZE);
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1466,6 +1469,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
|
|
|
9ae3a8 |
uint32_t snapid;
|
|
|
9ae3a8 |
bool prealloc = false;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
s = g_malloc0(sizeof(BDRVSheepdogState));
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1519,8 +1523,10 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs, backing_file, NULL, 0);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs, backing_file, NULL, 0, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vmdk.c b/block/vmdk.c
|
|
|
9ae3a8 |
index fa64f05..213901f 100644
|
|
|
9ae3a8 |
--- a/block/vmdk.c
|
|
|
9ae3a8 |
+++ b/block/vmdk.c
|
|
|
9ae3a8 |
@@ -697,6 +697,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
int64_t flat_offset;
|
|
|
9ae3a8 |
char extent_path[PATH_MAX];
|
|
|
9ae3a8 |
BlockDriverState *extent_file;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
while (*p) {
|
|
|
9ae3a8 |
/* parse extent line:
|
|
|
9ae3a8 |
@@ -726,8 +727,11 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
path_combine(extent_path, sizeof(extent_path),
|
|
|
9ae3a8 |
desc_file_path, fname);
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,
|
|
|
9ae3a8 |
+ &local_err);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1591,6 +1595,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
"ddb.geometry.heads = \"%d\"\n"
|
|
|
9ae3a8 |
"ddb.geometry.sectors = \"63\"\n"
|
|
|
9ae3a8 |
"ddb.adapterType = \"%s\"\n";
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (filename_decompose(filename, path, prefix, postfix, PATH_MAX)) {
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
@@ -1653,8 +1658,10 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (backing_file) {
|
|
|
9ae3a8 |
BlockDriverState *bs = bdrv_new("");
|
|
|
9ae3a8 |
- ret = bdrv_open(bs, backing_file, NULL, 0, NULL);
|
|
|
9ae3a8 |
+ ret = bdrv_open(bs, backing_file, NULL, 0, NULL, &local_err);
|
|
|
9ae3a8 |
if (ret != 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
bdrv_delete(bs);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/block/vvfat.c b/block/vvfat.c
|
|
|
9ae3a8 |
index bb3b0b6..a385b6f 100644
|
|
|
9ae3a8 |
--- a/block/vvfat.c
|
|
|
9ae3a8 |
+++ b/block/vvfat.c
|
|
|
9ae3a8 |
@@ -2910,6 +2910,7 @@ static int enable_write_target(BDRVVVFATState *s)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BlockDriver *bdrv_qcow;
|
|
|
9ae3a8 |
QEMUOptionParameter *options;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
int size = sector2cluster(s, s->sector_count);
|
|
|
9ae3a8 |
s->used_clusters = calloc(size, 1);
|
|
|
9ae3a8 |
@@ -2935,8 +2936,11 @@ static int enable_write_target(BDRVVVFATState *s)
|
|
|
9ae3a8 |
s->qcow = bdrv_new("");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_open(s->qcow, s->qcow_filename, NULL,
|
|
|
9ae3a8 |
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow);
|
|
|
9ae3a8 |
+ BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow,
|
|
|
9ae3a8 |
+ &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ qerror_report_err(local_err);
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
bdrv_delete(s->qcow);
|
|
|
9ae3a8 |
goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/blockdev.c b/blockdev.c
|
|
|
9ae3a8 |
index a6563fa..2fb6d83 100644
|
|
|
9ae3a8 |
--- a/blockdev.c
|
|
|
9ae3a8 |
+++ b/blockdev.c
|
|
|
9ae3a8 |
@@ -707,17 +707,11 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
QINCREF(bs_opts);
|
|
|
9ae3a8 |
- ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
- if (ret == -EMEDIUMTYPE) {
|
|
|
9ae3a8 |
- error_report("could not open disk image %s: not in %s format",
|
|
|
9ae3a8 |
- file ?: dinfo->id, drv ? drv->format_name :
|
|
|
9ae3a8 |
- qdict_get_str(bs_opts, "driver"));
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- error_report("could not open disk image %s: %s",
|
|
|
9ae3a8 |
- file ?: dinfo->id, strerror(-ret));
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ error_report("could not open disk image %s: %s",
|
|
|
9ae3a8 |
+ file ?: dinfo->id, error_get_pretty(error));
|
|
|
9ae3a8 |
goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -958,9 +952,9 @@ static void external_snapshot_prepare(BlkTransactionStates *common,
|
|
|
9ae3a8 |
/* TODO Inherit bs->options or only take explicit options with an
|
|
|
9ae3a8 |
* extended QMP command? */
|
|
|
9ae3a8 |
ret = bdrv_open(states->new_bs, new_image_file, NULL,
|
|
|
9ae3a8 |
- flags | BDRV_O_NO_BACKING, drv);
|
|
|
9ae3a8 |
+ flags | BDRV_O_NO_BACKING, drv, &local_err);
|
|
|
9ae3a8 |
if (ret != 0) {
|
|
|
9ae3a8 |
- error_setg_file_open(errp, -ret, new_image_file);
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1124,11 +1118,12 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
|
|
|
9ae3a8 |
int bdrv_flags, BlockDriver *drv,
|
|
|
9ae3a8 |
const char *password, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_open(bs, filename, NULL, bdrv_flags, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open(bs, filename, NULL, bdrv_flags, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
- error_setg_file_open(errp, -ret, filename);
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1538,10 +1533,11 @@ void qmp_drive_mirror(const char *device, const char *target,
|
|
|
9ae3a8 |
* file.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
target_bs = bdrv_new("");
|
|
|
9ae3a8 |
- ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv,
|
|
|
9ae3a8 |
+ &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
bdrv_delete(target_bs);
|
|
|
9ae3a8 |
- error_setg_file_open(errp, -ret, target);
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
|
|
|
9ae3a8 |
index 247f32f..2d4d263 100644
|
|
|
9ae3a8 |
--- a/hw/block/xen_disk.c
|
|
|
9ae3a8 |
+++ b/hw/block/xen_disk.c
|
|
|
9ae3a8 |
@@ -797,10 +797,15 @@ static int blk_connect(struct XenDevice *xendev)
|
|
|
9ae3a8 |
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
|
|
|
9ae3a8 |
blkdev->bs = bdrv_new(blkdev->dev);
|
|
|
9ae3a8 |
if (blkdev->bs) {
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
BlockDriver *drv = bdrv_find_whitelisted_format(blkdev->fileproto,
|
|
|
9ae3a8 |
readonly);
|
|
|
9ae3a8 |
if (bdrv_open(blkdev->bs,
|
|
|
9ae3a8 |
- blkdev->filename, NULL, qflags, drv) != 0) {
|
|
|
9ae3a8 |
+ blkdev->filename, NULL, qflags, drv, &local_err) != 0)
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ xen_be_printf(&blkdev->xendev, 0, "error: %s\n",
|
|
|
9ae3a8 |
+ error_get_pretty(local_err));
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
bdrv_delete(blkdev->bs);
|
|
|
9ae3a8 |
blkdev->bs = NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/include/block/block.h b/include/block/block.h
|
|
|
9ae3a8 |
index 39770a3..168d8a8 100644
|
|
|
9ae3a8 |
--- a/include/block/block.h
|
|
|
9ae3a8 |
+++ b/include/block/block.h
|
|
|
9ae3a8 |
@@ -162,10 +162,10 @@ void bdrv_delete(BlockDriverState *bs);
|
|
|
9ae3a8 |
int bdrv_parse_cache_flags(const char *mode, int *flags);
|
|
|
9ae3a8 |
int bdrv_parse_discard_flags(const char *mode, int *flags);
|
|
|
9ae3a8 |
int bdrv_file_open(BlockDriverState **pbs, const char *filename,
|
|
|
9ae3a8 |
- QDict *options, int flags);
|
|
|
9ae3a8 |
-int bdrv_open_backing_file(BlockDriverState *bs, QDict *options);
|
|
|
9ae3a8 |
+ QDict *options, int flags, Error **errp);
|
|
|
9ae3a8 |
+int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
|
|
|
9ae3a8 |
int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
- int flags, BlockDriver *drv);
|
|
|
9ae3a8 |
+ int flags, BlockDriver *drv, Error **errp);
|
|
|
9ae3a8 |
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
|
|
|
9ae3a8 |
BlockDriverState *bs, int flags);
|
|
|
9ae3a8 |
int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp);
|
|
|
9ae3a8 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
9ae3a8 |
index 8fcea44..d7d1244 100644
|
|
|
9ae3a8 |
--- a/qemu-img.c
|
|
|
9ae3a8 |
+++ b/qemu-img.c
|
|
|
9ae3a8 |
@@ -264,6 +264,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
|
|
|
9ae3a8 |
BlockDriverState *bs;
|
|
|
9ae3a8 |
BlockDriver *drv;
|
|
|
9ae3a8 |
char password[256];
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bs = bdrv_new("image");
|
|
|
9ae3a8 |
@@ -278,9 +279,11 @@ static BlockDriverState *bdrv_new_open(const char *filename,
|
|
|
9ae3a8 |
drv = NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_open(bs, filename, NULL, flags, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open(bs, filename, NULL, flags, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
- error_report("Could not open '%s': %s", filename, strerror(-ret));
|
|
|
9ae3a8 |
+ error_report("Could not open '%s': %s", filename,
|
|
|
9ae3a8 |
+ error_get_pretty(local_err));
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -2266,6 +2269,7 @@ static int img_rebase(int argc, char **argv)
|
|
|
9ae3a8 |
int unsafe = 0;
|
|
|
9ae3a8 |
int progress = 0;
|
|
|
9ae3a8 |
bool quiet = false;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Parse commandline parameters */
|
|
|
9ae3a8 |
fmt = NULL;
|
|
|
9ae3a8 |
@@ -2369,18 +2373,21 @@ static int img_rebase(int argc, char **argv)
|
|
|
9ae3a8 |
bs_old_backing = bdrv_new("old_backing");
|
|
|
9ae3a8 |
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
|
|
|
9ae3a8 |
ret = bdrv_open(bs_old_backing, backing_name, NULL, BDRV_O_FLAGS,
|
|
|
9ae3a8 |
- old_backing_drv);
|
|
|
9ae3a8 |
+ old_backing_drv, &local_err);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
- error_report("Could not open old backing file '%s'", backing_name);
|
|
|
9ae3a8 |
+ error_report("Could not open old backing file '%s': %s",
|
|
|
9ae3a8 |
+ backing_name, error_get_pretty(local_err));
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (out_baseimg[0]) {
|
|
|
9ae3a8 |
bs_new_backing = bdrv_new("new_backing");
|
|
|
9ae3a8 |
ret = bdrv_open(bs_new_backing, out_baseimg, NULL, BDRV_O_FLAGS,
|
|
|
9ae3a8 |
- new_backing_drv);
|
|
|
9ae3a8 |
+ new_backing_drv, &local_err);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
- error_report("Could not open new backing file '%s'",
|
|
|
9ae3a8 |
- out_baseimg);
|
|
|
9ae3a8 |
+ error_report("Could not open new backing file '%s': %s",
|
|
|
9ae3a8 |
+ out_baseimg, error_get_pretty(local_err));
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/qemu-io.c b/qemu-io.c
|
|
|
9ae3a8 |
index bdcce7f..116bb1b 100644
|
|
|
9ae3a8 |
--- a/qemu-io.c
|
|
|
9ae3a8 |
+++ b/qemu-io.c
|
|
|
9ae3a8 |
@@ -1764,21 +1764,27 @@ static const cmdinfo_t close_cmd = {
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int openfile(char *name, int flags, int growable)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if (bs) {
|
|
|
9ae3a8 |
fprintf(stderr, "file open already, try 'help close'\n");
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (growable) {
|
|
|
9ae3a8 |
- if (bdrv_file_open(&bs, name, NULL, flags)) {
|
|
|
9ae3a8 |
- fprintf(stderr, "%s: can't open device %s\n", progname, name);
|
|
|
9ae3a8 |
+ if (bdrv_file_open(&bs, name, NULL, flags, &local_err)) {
|
|
|
9ae3a8 |
+ fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
|
|
|
9ae3a8 |
+ error_get_pretty(local_err));
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
bs = bdrv_new("hda");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (bdrv_open(bs, name, NULL, flags, NULL) < 0) {
|
|
|
9ae3a8 |
- fprintf(stderr, "%s: can't open device %s\n", progname, name);
|
|
|
9ae3a8 |
+ if (bdrv_open(bs, name, NULL, flags, NULL, &local_err) < 0) {
|
|
|
9ae3a8 |
+ fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
|
|
|
9ae3a8 |
+ error_get_pretty(local_err));
|
|
|
9ae3a8 |
+ error_free(local_err);
|
|
|
9ae3a8 |
bdrv_delete(bs);
|
|
|
9ae3a8 |
bs = NULL;
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
diff --git a/qemu-nbd.c b/qemu-nbd.c
|
|
|
9ae3a8 |
index 9c31d45..c1b395d 100644
|
|
|
9ae3a8 |
--- a/qemu-nbd.c
|
|
|
9ae3a8 |
+++ b/qemu-nbd.c
|
|
|
9ae3a8 |
@@ -354,6 +354,7 @@ int main(int argc, char **argv)
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
pthread_t client_thread;
|
|
|
9ae3a8 |
const char *fmt = NULL;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* The client thread uses SIGTERM to interrupt the server. A signal
|
|
|
9ae3a8 |
* handler ensures that "qemu-nbd -v -c" exits with a nice status code.
|
|
|
9ae3a8 |
@@ -572,10 +573,11 @@ int main(int argc, char **argv)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bs = bdrv_new("hda");
|
|
|
9ae3a8 |
srcpath = argv[optind];
|
|
|
9ae3a8 |
- ret = bdrv_open(bs, srcpath, NULL, flags, drv);
|
|
|
9ae3a8 |
+ ret = bdrv_open(bs, srcpath, NULL, flags, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
errno = -ret;
|
|
|
9ae3a8 |
- err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
|
|
|
9ae3a8 |
+ err(EXIT_FAILURE, "Failed to bdrv_open '%s': %s", argv[optind],
|
|
|
9ae3a8 |
+ error_get_pretty(local_err));
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
fd_size = bdrv_getlength(bs);
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|