aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'block.c')
-rw-r--r--block.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/block.c b/block.c
index 183fec8aa5..b56024113b 100644
--- a/block.c
+++ b/block.c
@@ -417,7 +417,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
{
BlockDriver *drv;
- drv = bdrv_find_protocol(filename);
+ drv = bdrv_find_protocol(filename, true);
if (drv == NULL) {
return -ENOENT;
}
@@ -482,7 +482,8 @@ static BlockDriver *find_hdev_driver(const char *filename)
return drv;
}
-BlockDriver *bdrv_find_protocol(const char *filename)
+BlockDriver *bdrv_find_protocol(const char *filename,
+ bool allow_protocol_prefix)
{
BlockDriver *drv1;
char protocol[128];
@@ -503,9 +504,10 @@ BlockDriver *bdrv_find_protocol(const char *filename)
return drv1;
}
- if (!path_has_protocol(filename)) {
+ if (!path_has_protocol(filename) || !allow_protocol_prefix) {
return bdrv_find_format("file");
}
+
p = strchr(filename, ':');
assert(p != NULL);
len = p - filename;
@@ -784,6 +786,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
BlockDriverState *bs;
BlockDriver *drv;
const char *drvname;
+ bool allow_protocol_prefix = false;
int ret;
/* NULL means an empty set of options */
@@ -800,6 +803,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
filename = qdict_get_try_str(options, "filename");
} else if (filename && !qdict_haskey(options, "filename")) {
qdict_put(options, "filename", qstring_from_str(filename));
+ allow_protocol_prefix = true;
} else {
qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't specify 'file' and "
"'filename' options at the same time");
@@ -813,7 +817,10 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
qdict_del(options, "driver");
} else if (filename) {
- drv = bdrv_find_protocol(filename);
+ drv = bdrv_find_protocol(filename, allow_protocol_prefix);
+ if (!drv) {
+ qerror_report(ERROR_CLASS_GENERIC_ERROR, "Unknown protocol");
+ }
} else {
qerror_report(ERROR_CLASS_GENERIC_ERROR,
"Must specify either driver or file");
@@ -2903,13 +2910,19 @@ int bdrv_get_flags(BlockDriverState *bs)
return bs->open_flags;
}
-void bdrv_flush_all(void)
+int bdrv_flush_all(void)
{
BlockDriverState *bs;
+ int result = 0;
QTAILQ_FOREACH(bs, &bdrv_states, list) {
- bdrv_flush(bs);
+ int ret = bdrv_flush(bs);
+ if (ret < 0 && !result) {
+ result = ret;
+ }
}
+
+ return result;
}
int bdrv_has_zero_init_1(BlockDriverState *bs)
@@ -4452,7 +4465,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
return;
}
- proto_drv = bdrv_find_protocol(filename);
+ proto_drv = bdrv_find_protocol(filename, true);
if (!proto_drv) {
error_setg(errp, "Unknown protocol '%s'", filename);
return;