[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [RFC 5/7] block: Add blk_new_open_string_opts()
From: |
Max Reitz |
Subject: |
[Qemu-block] [RFC 5/7] block: Add blk_new_open_string_opts() |
Date: |
Wed, 2 May 2018 23:32:17 +0200 |
This is an interface to bdrv_open_string_opts().
Signed-off-by: Max Reitz <address@hidden>
---
include/sysemu/block-backend.h | 2 ++
block/block-backend.c | 30 +++++++++++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 92ab624fac..1ad002fa7e 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -79,6 +79,8 @@ typedef struct BlockBackendPublic {
BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm);
BlockBackend *blk_new_open(const char *filename, const char *reference,
QDict *options, int flags, Error **errp);
+BlockBackend *blk_new_open_string_opts(const char *filename, QDict *options,
+ int flags, Error **errp);
int blk_get_refcnt(BlockBackend *blk);
void blk_ref(BlockBackend *blk);
void blk_unref(BlockBackend *blk);
diff --git a/block/block-backend.c b/block/block-backend.c
index 89f47b00ea..fd3024602a 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -105,6 +105,11 @@ static const AIOCBInfo block_backend_aiocb_info = {
static void drive_info_del(DriveInfo *dinfo);
static BlockBackend *bdrv_first_blk(BlockDriverState *bs);
+static BlockBackend *blk_do_new_open(const char *filename,
+ const char *reference, QDict *options,
+ int flags, bool string_opts,
+ Error **errp);
+
/* All BlockBackends */
static QTAILQ_HEAD(, BlockBackend) block_backends =
QTAILQ_HEAD_INITIALIZER(block_backends);
@@ -348,6 +353,24 @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm)
*/
BlockBackend *blk_new_open(const char *filename, const char *reference,
QDict *options, int flags, Error **errp)
+{
+ return blk_do_new_open(filename, reference, options, flags, false, errp);
+}
+
+/*
+ * Like blk_new_open(), but accepts an @options QDict where some (or
+ * all) values are strings instead of their correct type.
+ */
+BlockBackend *blk_new_open_string_opts(const char *filename, QDict *options,
+ int flags, Error **errp)
+{
+ return blk_do_new_open(filename, NULL, options, flags, true, errp);
+}
+
+static BlockBackend *blk_do_new_open(const char *filename,
+ const char *reference, QDict *options,
+ int flags, bool string_opts,
+ Error **errp)
{
BlockBackend *blk;
BlockDriverState *bs;
@@ -372,7 +395,12 @@ BlockBackend *blk_new_open(const char *filename, const
char *reference,
}
blk = blk_new(perm, BLK_PERM_ALL);
- bs = bdrv_open(filename, reference, options, flags, errp);
+ if (string_opts) {
+ assert(!reference);
+ bs = bdrv_open_string_opts(filename, options, flags, errp);
+ } else {
+ bs = bdrv_open(filename, reference, options, flags, errp);
+ }
if (!bs) {
blk_unref(blk);
return NULL;
--
2.14.3
- [Qemu-block] [RFC 0/7] block: Try to use correctly typed blockdev options, Max Reitz, 2018/05/02
- [Qemu-block] [RFC 1/7] qdict: Add qdict_set_default_bool(), Max Reitz, 2018/05/02
- [Qemu-block] [RFC 2/7] block: Let change-medium add detect-zeroes as bool, Max Reitz, 2018/05/02
- [Qemu-block] [RFC 4/7] block: Add bdrv_open_string_opts(), Max Reitz, 2018/05/02
- [Qemu-block] [RFC 3/7] block: Make use of qdict_set_default_bool(), Max Reitz, 2018/05/02
- [Qemu-block] [RFC 5/7] block: Add blk_new_open_string_opts(),
Max Reitz <=
- [Qemu-block] [RFC 6/7] block: Use {blk_new, bdrv}_open_string_opts(), Max Reitz, 2018/05/02
- [Qemu-block] [RFC 7/7] iotests: Test internal option typing, Max Reitz, 2018/05/02
- Re: [Qemu-block] [RFC 0/7] block: Try to use correctly typed blockdev options, Max Reitz, 2018/05/02
- Re: [Qemu-block] [Qemu-devel] [RFC 0/7] block: Try to use correctly typed blockdev options, Markus Armbruster, 2018/05/03