[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [RFC PATCH 27/41] block: Add bdrv_new_open_driver()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [RFC PATCH 27/41] block: Add bdrv_new_open_driver() |
Date: |
Mon, 13 Feb 2017 18:22:49 +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>
---
block.c | 31 ++++++++++++++++++++++++++++++-
include/block/block.h | 2 ++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 9c80cba..7d84d43 100644
--- a/block.c
+++ b/block.c
@@ -948,13 +948,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) {
@@ -995,6 +998,32 @@ free_and_fail:
return ret;
}
+int bdrv_new_open_driver(BlockDriver *drv, BlockDriverState **result,
+ 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 ret;
+ }
+
+ *result = bs;
+ return 0;
+}
+
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 93812df..3238850 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);
+int bdrv_new_open_driver(BlockDriver *drv, BlockDriverState **result,
+ 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
- Re: [Qemu-block] [RFC PATCH 20/41] hw/block: Introduce share-rw qdev property, (continued)
[Qemu-block] [RFC PATCH 21/41] blockjob: Add permissions to block_job_create(), Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 22/41] block: Add BdrvChildRole.get_link_name(), Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 23/41] block: Include details on permission errors in message, Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 24/41] block: Add BdrvChildRole.stay_at_node, Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 25/41] blockjob: Add permissions to block_job_add_bdrv(), Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 27/41] block: Add bdrv_new_open_driver(),
Kevin Wolf <=
[Qemu-block] [RFC PATCH 28/41] commit: Use real permissions in commit block job, Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 29/41] commit: Use real permissions for HMP 'commit', Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 30/41] backup: Use real permissions in backup block job, Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 33/41] block: Allow backing file links in change_parent_backing_link(), Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 36/41] hmp: Request permissions in qemu-io, Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 38/41] nbd/server: Use real permissions for NBD exports, Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 26/41] block: Factor out bdrv_open_driver(), Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 31/41] block: Fix pending requests check in bdrv_append(), Kevin Wolf, 2017/02/13
[Qemu-block] [RFC PATCH 32/41] block: BdrvChildRole.attach/detach() callbacks, Kevin Wolf, 2017/02/13