mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 11:04:58 -06:00
blockdev: Disentangle BlockDriverState and DriveInfo creation
blockdev_init() mixes up BlockDriverState and DriveInfo initialization Finish the BlockDriverState job before starting to mess with DriveInfo. Easier on the eyes. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Benoît Canet <benoit.canet@nodalink.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
d4362d642e
commit
a0f1eab157
1 changed files with 20 additions and 17 deletions
37
blockdev.c
37
blockdev.c
|
@ -301,6 +301,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
int ro = 0;
|
int ro = 0;
|
||||||
int bdrv_flags = 0;
|
int bdrv_flags = 0;
|
||||||
int on_read_error, on_write_error;
|
int on_read_error, on_write_error;
|
||||||
|
BlockDriverState *bs;
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo;
|
||||||
ThrottleConfig cfg;
|
ThrottleConfig cfg;
|
||||||
int snapshot = 0;
|
int snapshot = 0;
|
||||||
|
@ -456,26 +457,27 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
dinfo = g_malloc0(sizeof(*dinfo));
|
bs = bdrv_new(qemu_opts_id(opts), errp);
|
||||||
dinfo->id = g_strdup(qemu_opts_id(opts));
|
if (!bs) {
|
||||||
dinfo->bdrv = bdrv_new(dinfo->id, &error);
|
goto early_err;
|
||||||
if (error) {
|
|
||||||
error_propagate(errp, error);
|
|
||||||
goto bdrv_new_err;
|
|
||||||
}
|
}
|
||||||
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
bs->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
||||||
dinfo->bdrv->read_only = ro;
|
bs->read_only = ro;
|
||||||
dinfo->bdrv->detect_zeroes = detect_zeroes;
|
bs->detect_zeroes = detect_zeroes;
|
||||||
QTAILQ_INSERT_TAIL(&drives, dinfo, next);
|
|
||||||
|
|
||||||
bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error);
|
bdrv_set_on_error(bs, on_read_error, on_write_error);
|
||||||
|
|
||||||
/* disk I/O throttling */
|
/* disk I/O throttling */
|
||||||
if (throttle_enabled(&cfg)) {
|
if (throttle_enabled(&cfg)) {
|
||||||
bdrv_io_limits_enable(dinfo->bdrv);
|
bdrv_io_limits_enable(bs);
|
||||||
bdrv_set_io_limits(dinfo->bdrv, &cfg);
|
bdrv_set_io_limits(bs, &cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dinfo = g_malloc0(sizeof(*dinfo));
|
||||||
|
dinfo->id = g_strdup(qemu_opts_id(opts));
|
||||||
|
dinfo->bdrv = bs;
|
||||||
|
QTAILQ_INSERT_TAIL(&drives, dinfo, next);
|
||||||
|
|
||||||
if (!file || !*file) {
|
if (!file || !*file) {
|
||||||
if (has_driver_specific_opts) {
|
if (has_driver_specific_opts) {
|
||||||
file = NULL;
|
file = NULL;
|
||||||
|
@ -502,7 +504,8 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
||||||
|
|
||||||
QINCREF(bs_opts);
|
QINCREF(bs_opts);
|
||||||
ret = bdrv_open(&dinfo->bdrv, file, NULL, bs_opts, bdrv_flags, drv, &error);
|
ret = bdrv_open(&bs, file, NULL, bs_opts, bdrv_flags, drv, &error);
|
||||||
|
assert(bs == dinfo->bdrv);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg(errp, "could not open disk image %s: %s",
|
error_setg(errp, "could not open disk image %s: %s",
|
||||||
|
@ -511,8 +514,9 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bdrv_key_required(dinfo->bdrv))
|
if (bdrv_key_required(bs)) {
|
||||||
autostart = 0;
|
autostart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
QDECREF(bs_opts);
|
QDECREF(bs_opts);
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
|
@ -520,9 +524,8 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
return dinfo;
|
return dinfo;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
bdrv_unref(dinfo->bdrv);
|
bdrv_unref(bs);
|
||||||
QTAILQ_REMOVE(&drives, dinfo, next);
|
QTAILQ_REMOVE(&drives, dinfo, next);
|
||||||
bdrv_new_err:
|
|
||||||
g_free(dinfo->id);
|
g_free(dinfo->id);
|
||||||
g_free(dinfo);
|
g_free(dinfo);
|
||||||
early_err:
|
early_err:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue