[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 17/19] block: Add bdrv_new_open_driver()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 17/19] block: Add bdrv_new_open_driver() |
Date: |
Fri, 24 Feb 2017 19:17:08 +0100 |
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 <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 30 +++++++++++++++++++++++++++++-
include/block/block.h | 2 ++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index f96d26b..1368cf5 100644
--- a/block.c
+++ b/block.c
@@ -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),
diff --git a/include/block/block.h b/include/block/block.h
index a4cd06f..bde5ebd 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -215,6 +215,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*parent_options,
const char *bdref_key, Error **errp);
BlockDriverState *bdrv_open(const char *filename, const char *reference,
QDict *options, int flags, Error **errp);
+BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_name,
+ int flags, Error **errp);
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
BlockDriverState *bs,
QDict *options, int flags);
--
1.8.3.1
- [Qemu-block] [PULL 05/19] qemu-img: Add tests for raw image preallocation, (continued)
- [Qemu-block] [PULL 05/19] qemu-img: Add tests for raw image preallocation, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 06/19] qemu-img: Truncate before full preallocation, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 07/19] qemu-img: Improve documentation for PREALLOC_MODE_FALLOC, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 08/19] iotests: Fix another race in 030, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 10/19] qcow2: Use BB for resizing in qcow2_amend_options(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 09/19] blockdev: Use BlockBackend to resize in qmp_block_resize(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 11/19] mirror: Resize active commit base in mirror_run(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 13/19] block: Attach bs->file only during .bdrv_open(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 12/19] block: Pass BdrvChild to bdrv_truncate(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 16/19] block: Factor out bdrv_open_driver(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 17/19] block: Add bdrv_new_open_driver(),
Kevin Wolf <=
- [Qemu-block] [PULL 18/19] vvfat: Use opened node as backing file, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 14/19] block: Factor out bdrv_open_child_bs(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 15/19] block: Use BlockBackend for image probing, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 19/19] tests: Use opened block node for block job tests, Kevin Wolf, 2017/02/24
- Re: [Qemu-block] [Qemu-devel] [PULL 00/19] Block layer patches, no-reply, 2017/02/24
- Re: [Qemu-block] [Qemu-devel] [PULL 00/19] Block layer patches, Peter Maydell, 2017/02/26