mirror of https://gitee.com/openkylin/qemu.git
block: Don't parse 'filename' option
When using the QDict option 'filename', it is supposed to be interpreted literally. The code did correctly avoid guessing the protocol from any string before the first colon, but it still called bdrv_parse_filename() which would, for example, incorrectly remove a 'file:' prefix in the raw-posix driver. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
8885eadedd
commit
e3fa4bfa72
8
block.c
8
block.c
|
@ -968,7 +968,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename,
|
||||||
{
|
{
|
||||||
BlockDriver *drv;
|
BlockDriver *drv;
|
||||||
const char *drvname;
|
const char *drvname;
|
||||||
bool allow_protocol_prefix = false;
|
bool parse_filename = false;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -977,7 +977,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename,
|
||||||
filename = qdict_get_try_str(*options, "filename");
|
filename = qdict_get_try_str(*options, "filename");
|
||||||
} else if (filename && !qdict_haskey(*options, "filename")) {
|
} else if (filename && !qdict_haskey(*options, "filename")) {
|
||||||
qdict_put(*options, "filename", qstring_from_str(filename));
|
qdict_put(*options, "filename", qstring_from_str(filename));
|
||||||
allow_protocol_prefix = true;
|
parse_filename = true;
|
||||||
} else {
|
} else {
|
||||||
error_setg(errp, "Can't specify 'file' and 'filename' options at the "
|
error_setg(errp, "Can't specify 'file' and 'filename' options at the "
|
||||||
"same time");
|
"same time");
|
||||||
|
@ -994,7 +994,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename,
|
||||||
}
|
}
|
||||||
qdict_del(*options, "driver");
|
qdict_del(*options, "driver");
|
||||||
} else if (filename) {
|
} else if (filename) {
|
||||||
drv = bdrv_find_protocol(filename, allow_protocol_prefix);
|
drv = bdrv_find_protocol(filename, parse_filename);
|
||||||
if (!drv) {
|
if (!drv) {
|
||||||
error_setg(errp, "Unknown protocol");
|
error_setg(errp, "Unknown protocol");
|
||||||
}
|
}
|
||||||
|
@ -1010,7 +1010,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the filename and open it */
|
/* Parse the filename and open it */
|
||||||
if (drv->bdrv_parse_filename && filename) {
|
if (drv->bdrv_parse_filename && parse_filename) {
|
||||||
drv->bdrv_parse_filename(filename, *options, &local_err);
|
drv->bdrv_parse_filename(filename, *options, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
|
|
|
@ -204,6 +204,10 @@ run_qemu -hda foo:bar
|
||||||
run_qemu -drive file=foo:bar
|
run_qemu -drive file=foo:bar
|
||||||
run_qemu -drive file.filename=foo:bar
|
run_qemu -drive file.filename=foo:bar
|
||||||
|
|
||||||
|
run_qemu -hda "file:$TEST_IMG"
|
||||||
|
run_qemu -drive file="file:$TEST_IMG"
|
||||||
|
run_qemu -drive file.filename="file:$TEST_IMG"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo === Snapshot mode ===
|
echo === Snapshot mode ===
|
||||||
echo
|
echo
|
||||||
|
|
|
@ -275,6 +275,17 @@ QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown proto
|
||||||
Testing: -drive file.filename=foo:bar
|
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 'foo:bar': No such file or directory
|
||||||
|
|
||||||
|
Testing: -hda file:TEST_DIR/t.qcow2
|
||||||
|
QEMU X.Y.Z monitor - type 'help' for more information
|
||||||
|
(qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K
|
||||||
|
|
||||||
|
Testing: -drive file=file:TEST_DIR/t.qcow2
|
||||||
|
QEMU X.Y.Z monitor - type 'help' for more information
|
||||||
|
(qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K
|
||||||
|
|
||||||
|
Testing: -drive file.filename=file:TEST_DIR/t.qcow2
|
||||||
|
QEMU_PROG: -drive file.filename=file:TEST_DIR/t.qcow2: could not open disk image ide0-hd0: Could not open 'file:TEST_DIR/t.qcow2': No such file or directory
|
||||||
|
|
||||||
|
|
||||||
=== Snapshot mode ===
|
=== Snapshot mode ===
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue