mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 14:53:54 -06:00
blockdev: Use blk_new_open() in blockdev_init()
Due to different error propagation, this breaks tests 051 and 087; fix their output. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1423162705-32065-6-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
80495fdf44
commit
e4342ce5a2
3 changed files with 78 additions and 86 deletions
94
blockdev.c
94
blockdev.c
|
@ -354,13 +354,11 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
|||
ThrottleConfig cfg;
|
||||
int snapshot = 0;
|
||||
bool copy_on_read;
|
||||
int ret;
|
||||
Error *error = NULL;
|
||||
QemuOpts *opts;
|
||||
const char *id;
|
||||
bool has_driver_specific_opts;
|
||||
BlockdevDetectZeroesOptions detect_zeroes;
|
||||
BlockDriver *drv = NULL;
|
||||
|
||||
/* Check common options by copying from bs_opts to opts, all other options
|
||||
* stay in bs_opts for processing by bdrv_open(). */
|
||||
|
@ -426,11 +424,11 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
|||
goto early_err;
|
||||
}
|
||||
|
||||
drv = bdrv_find_format(buf);
|
||||
if (!drv) {
|
||||
error_setg(errp, "'%s' invalid format", buf);
|
||||
if (qdict_haskey(bs_opts, "driver")) {
|
||||
error_setg(errp, "Cannot specify both 'driver' and 'format'");
|
||||
goto early_err;
|
||||
}
|
||||
qdict_put(bs_opts, "driver", qstring_from_str(buf));
|
||||
}
|
||||
|
||||
/* disk I/O throttling */
|
||||
|
@ -505,13 +503,46 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
|||
}
|
||||
|
||||
/* init */
|
||||
blk = blk_new_with_bs(qemu_opts_id(opts), errp);
|
||||
if (!blk) {
|
||||
goto early_err;
|
||||
if ((!file || !*file) && !has_driver_specific_opts) {
|
||||
blk = blk_new_with_bs(qemu_opts_id(opts), errp);
|
||||
if (!blk) {
|
||||
goto early_err;
|
||||
}
|
||||
|
||||
bs = blk_bs(blk);
|
||||
bs->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
||||
bs->read_only = ro;
|
||||
|
||||
QDECREF(bs_opts);
|
||||
} else {
|
||||
if (file && !*file) {
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
if (snapshot) {
|
||||
/* always use cache=unsafe with snapshot */
|
||||
bdrv_flags &= ~BDRV_O_CACHE_MASK;
|
||||
bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH);
|
||||
}
|
||||
|
||||
if (copy_on_read) {
|
||||
bdrv_flags |= BDRV_O_COPY_ON_READ;
|
||||
}
|
||||
|
||||
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
||||
bdrv_flags |= BDRV_O_INCOMING;
|
||||
}
|
||||
|
||||
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
||||
|
||||
blk = blk_new_open(qemu_opts_id(opts), file, NULL, bs_opts, bdrv_flags,
|
||||
errp);
|
||||
if (!blk) {
|
||||
goto err_no_bs_opts;
|
||||
}
|
||||
bs = blk_bs(blk);
|
||||
}
|
||||
bs = blk_bs(blk);
|
||||
bs->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
||||
bs->read_only = ro;
|
||||
|
||||
bs->detect_zeroes = detect_zeroes;
|
||||
|
||||
bdrv_set_on_error(bs, on_read_error, on_write_error);
|
||||
|
@ -522,53 +553,14 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
|||
bdrv_set_io_limits(bs, &cfg);
|
||||
}
|
||||
|
||||
if (!file || !*file) {
|
||||
if (has_driver_specific_opts) {
|
||||
file = NULL;
|
||||
} else {
|
||||
QDECREF(bs_opts);
|
||||
qemu_opts_del(opts);
|
||||
return blk;
|
||||
}
|
||||
}
|
||||
if (snapshot) {
|
||||
/* always use cache=unsafe with snapshot */
|
||||
bdrv_flags &= ~BDRV_O_CACHE_MASK;
|
||||
bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH);
|
||||
}
|
||||
|
||||
if (copy_on_read) {
|
||||
bdrv_flags |= BDRV_O_COPY_ON_READ;
|
||||
}
|
||||
|
||||
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
||||
bdrv_flags |= BDRV_O_INCOMING;
|
||||
}
|
||||
|
||||
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
||||
|
||||
QINCREF(bs_opts);
|
||||
ret = bdrv_open(&bs, file, NULL, bs_opts, bdrv_flags, drv, &error);
|
||||
assert(bs == blk_bs(blk));
|
||||
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "could not open disk image %s: %s",
|
||||
file ?: blk_name(blk), error_get_pretty(error));
|
||||
error_free(error);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (bdrv_key_required(bs)) {
|
||||
autostart = 0;
|
||||
}
|
||||
|
||||
QDECREF(bs_opts);
|
||||
err_no_bs_opts:
|
||||
qemu_opts_del(opts);
|
||||
|
||||
return blk;
|
||||
|
||||
err:
|
||||
blk_unref(blk);
|
||||
early_err:
|
||||
qemu_opts_del(opts);
|
||||
err_no_opts:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue