[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 52/65] block: Add Error parameter to bdrv_find_pro
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL v2 52/65] block: Add Error parameter to bdrv_find_protocol() |
Date: |
Mon, 16 Feb 2015 15:46:17 +0000 |
From: Max Reitz <address@hidden>
The argument given to bdrv_find_protocol() is just a file name, which
makes it difficult for the caller to reconstruct what protocol
bdrv_find_protocol() was hoping to find. This patch adds an Error
parameter to that function to solve this issue.
Suggested-by: Eric Blake <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block.c | 14 +++++++-------
block/sheepdog.c | 2 +-
include/block/block.h | 3 ++-
qemu-img.c | 11 +++++++----
tests/qemu-iotests/051.out | 4 ++--
5 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/block.c b/block.c
index 210fd5f..2edff6c 100644
--- a/block.c
+++ b/block.c
@@ -508,9 +508,8 @@ int bdrv_create_file(const char *filename, QemuOpts *opts,
Error **errp)
Error *local_err = NULL;
int ret;
- drv = bdrv_find_protocol(filename, true);
+ drv = bdrv_find_protocol(filename, true, errp);
if (drv == NULL) {
- error_setg(errp, "Could not find protocol for file '%s'", filename);
return -ENOENT;
}
@@ -628,7 +627,8 @@ static BlockDriver *find_hdev_driver(const char *filename)
}
BlockDriver *bdrv_find_protocol(const char *filename,
- bool allow_protocol_prefix)
+ bool allow_protocol_prefix,
+ Error **errp)
{
BlockDriver *drv1;
char protocol[128];
@@ -666,6 +666,8 @@ BlockDriver *bdrv_find_protocol(const char *filename,
return drv1;
}
}
+
+ error_setg(errp, "Unknown protocol '%s'", protocol);
return NULL;
}
@@ -1136,9 +1138,8 @@ static int bdrv_fill_options(QDict **options, const char
**pfilename, int flags,
} else {
if (!drvname && protocol) {
if (filename) {
- drv = bdrv_find_protocol(filename, parse_filename);
+ drv = bdrv_find_protocol(filename, parse_filename, errp);
if (!drv) {
- error_setg(errp, "Unknown protocol");
return -EINVAL;
}
@@ -5623,9 +5624,8 @@ void bdrv_img_create(const char *filename, const char
*fmt,
return;
}
- proto_drv = bdrv_find_protocol(filename, true);
+ proto_drv = bdrv_find_protocol(filename, true, errp);
if (!proto_drv) {
- error_setg(errp, "Unknown protocol '%s'", filename);
return;
}
diff --git a/block/sheepdog.c b/block/sheepdog.c
index be3176f..e9b0ca1 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1730,7 +1730,7 @@ static int sd_create(const char *filename, QemuOpts *opts,
BlockDriver *drv;
/* Currently, only Sheepdog backing image is supported. */
- drv = bdrv_find_protocol(backing_file, true);
+ drv = bdrv_find_protocol(backing_file, true, NULL);
if (!drv || strcmp(drv->protocol_name, "sheepdog") != 0) {
error_setg(errp, "backing_file must be a sheepdog image");
ret = -EINVAL;
diff --git a/include/block/block.h b/include/block/block.h
index 321295e..471d11d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -168,7 +168,8 @@ void bdrv_io_limits_disable(BlockDriverState *bs);
void bdrv_init(void);
void bdrv_init_with_whitelist(void);
BlockDriver *bdrv_find_protocol(const char *filename,
- bool allow_protocol_prefix);
+ bool allow_protocol_prefix,
+ Error **errp);
BlockDriver *bdrv_find_format(const char *format_name);
BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
bool readonly);
diff --git a/qemu-img.c b/qemu-img.c
index 26ec3c1..8790546 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -261,6 +261,7 @@ static int print_block_option_help(const char *filename,
const char *fmt)
{
BlockDriver *drv, *proto_drv;
QemuOptsList *create_opts = NULL;
+ Error *local_err = NULL;
/* Find driver and parse its options */
drv = bdrv_find_format(fmt);
@@ -271,9 +272,10 @@ static int print_block_option_help(const char *filename,
const char *fmt)
create_opts = qemu_opts_append(create_opts, drv->create_opts);
if (filename) {
- proto_drv = bdrv_find_protocol(filename, true);
+ proto_drv = bdrv_find_protocol(filename, true, &local_err);
if (!proto_drv) {
- error_report("Unknown protocol '%s'", filename);
+ qerror_report_err(local_err);
+ error_free(local_err);
qemu_opts_free(create_opts);
return 1;
}
@@ -1524,9 +1526,10 @@ static int img_convert(int argc, char **argv)
goto out;
}
- proto_drv = bdrv_find_protocol(out_filename, true);
+ proto_drv = bdrv_find_protocol(out_filename, true, &local_err);
if (!proto_drv) {
- error_report("Unknown protocol '%s'", out_filename);
+ qerror_report_err(local_err);
+ error_free(local_err);
ret = -1;
goto out;
}
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index f497c57..9596e20 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -323,10 +323,10 @@ QEMU_PROG: -drive
file=TEST_DIR/t.qcow2,readonly=on,read-only=off: 'read-only' a
=== Parsing protocol from file name ===
Testing: -hda foo:bar
-QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: Unknown protocol
+QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: Unknown protocol
'foo'
Testing: -drive file=foo:bar
-QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown
protocol
+QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown
protocol 'foo'
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
--
2.1.0
- [Qemu-devel] [PULL v2 40/65] savevm: Improve error message for blocked migration, (continued)
- [Qemu-devel] [PULL v2 40/65] savevm: Improve error message for blocked migration, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 39/65] nbd: fix the co_queue multi-adding bug, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 42/65] qtest: Fix deadloop by running main loop AIO context's timers, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 44/65] qtest: Add scripts/qtest.py, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 37/65] qtest/ahci: Assert sector size in identify test, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 45/65] qemu-iotests: Add VM method qtest() to iotests.py, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 46/65] qemu-iotests: Allow caller to disable underscore convertion for qmp, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 47/65] qemu-iotests: Add 093 for IO throttling, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 50/65] block: Lift some BDS functions to the BlockBackend, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 49/65] iotests: Add test for qemu-img convert to NBD, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 52/65] block: Add Error parameter to bdrv_find_protocol(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL v2 53/65] iotests: Add test for driver=qcow2, format=qcow2, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 48/65] qemu-img: Fix qemu-img convert -n, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 51/65] block: Add blk_new_open(), Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 56/65] qemu-img: Use blk_new_open() in img_open(), Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 54/65] blockdev: Use blk_new_open() in blockdev_init(), Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 57/65] qemu-img: Use blk_new_open() in img_rebase(), Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 55/65] block/xen: Use blk_new_open() in blk_connect(), Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 58/65] qemu-img: Use BlockBackend as far as possible, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 59/65] qemu-nbd: Use blk_new_open() in main(), Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 63/65] block: Clamp BlockBackend requests, Stefan Hajnoczi, 2015/02/16