diff options
author | Kevin Wolf <kwolf@redhat.com> | 2017-01-18 17:16:41 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-02-24 16:09:23 +0100 |
commit | 680c7f96062e8c9fcc560eaf06fce164e2a564bc (patch) | |
tree | d180f4d65892ba211c5b7c30b7a0cd08014fbf42 /block.c | |
parent | 01a5650179a914a7603c77ccf0de9617064541ee (diff) |
block: Add bdrv_new_open_driver()
This function allows to create more or less normal BlockDriverStates
even for BlockDrivers that aren't globally registered (e.g. helper
filters for block jobs).
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -939,13 +939,16 @@ static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, } bs->drv = drv; + bs->read_only = !(bs->open_flags & BDRV_O_RDWR); bs->opaque = g_malloc0(drv->instance_size); if (drv->bdrv_file_open) { assert(!drv->bdrv_needs_filename || bs->filename[0]); ret = drv->bdrv_file_open(bs, options, open_flags, &local_err); - } else { + } else if (drv->bdrv_open) { ret = drv->bdrv_open(bs, options, open_flags, &local_err); + } else { + ret = 0; } if (ret < 0) { @@ -986,6 +989,31 @@ free_and_fail: return ret; } +BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_name, + int flags, Error **errp) +{ + BlockDriverState *bs; + int ret; + + bs = bdrv_new(); + bs->open_flags = flags; + bs->explicit_options = qdict_new(); + bs->options = qdict_new(); + bs->opaque = NULL; + + update_options_from_flags(bs->options, flags); + + ret = bdrv_open_driver(bs, drv, node_name, bs->options, flags, errp); + if (ret < 0) { + QDECREF(bs->explicit_options); + QDECREF(bs->options); + bdrv_unref(bs); + return NULL; + } + + return bs; +} + QemuOptsList bdrv_runtime_opts = { .name = "bdrv_common", .head = QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head), |