From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
Kevin Wolf <kwolf@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [RFC 3/7] block: Make use of qdict_set_default_bool()
Date: Wed, 2 May 2018 23:32:15 +0200 [thread overview]
Message-ID: <20180502213219.7842-4-mreitz@redhat.com> (raw)
In-Reply-To: <20180502213219.7842-1-mreitz@redhat.com>
When dealing with blockdev option QDicts that contain purely string
values, it is not really advisable to break that by adding non-string
values. But it does make sense to use the correct type for QDicts that
may contain non-string values already, so do that.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 12 ++++++------
block/vvfat.c | 4 ++--
blockdev.c | 23 ++++++++++++++++-------
3 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/block.c b/block.c
index a2caadf0a0..8a8d9c02a9 100644
--- a/block.c
+++ b/block.c
@@ -856,8 +856,8 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
*child_flags = (parent_flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY;
/* For temporary files, unconditional cache=unsafe is fine */
- qdict_set_default_str(child_options, BDRV_OPT_CACHE_DIRECT, "off");
- qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on");
+ qdict_set_default_bool(child_options, BDRV_OPT_CACHE_DIRECT, false);
+ qdict_set_default_bool(child_options, BDRV_OPT_CACHE_NO_FLUSH, true);
/* Copy the read-only option from the parent */
qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY);
@@ -1005,7 +1005,7 @@ static void bdrv_backing_options(int *child_flags, QDict *child_options,
qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
/* backing files always opened read-only */
- qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on");
+ qdict_set_default_bool(child_options, BDRV_OPT_READ_ONLY, true);
flags &= ~BDRV_O_COPY_ON_READ;
/* snapshot=on is handled on the top layer */
@@ -2440,9 +2440,9 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
/* bdrv_open_inherit() defaults to the values in bdrv_flags (for
* compatibility with other callers) rather than what we want as the
* real defaults. Apply the defaults here instead. */
- qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off");
- qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off");
- qdict_set_default_str(qdict, BDRV_OPT_READ_ONLY, "off");
+ qdict_set_default_bool(qdict, BDRV_OPT_CACHE_DIRECT, false);
+ qdict_set_default_bool(qdict, BDRV_OPT_CACHE_NO_FLUSH, false);
+ qdict_set_default_bool(qdict, BDRV_OPT_READ_ONLY, false);
}
bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp);
diff --git a/block/vvfat.c b/block/vvfat.c
index 1569783b0f..177b179ed2 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -3128,8 +3128,8 @@ static BlockDriver vvfat_write_target = {
static void vvfat_qcow_options(int *child_flags, QDict *child_options,
int parent_flags, QDict *parent_options)
{
- qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "off");
- qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on");
+ qdict_set_default_bool(child_options, BDRV_OPT_READ_ONLY, false);
+ qdict_set_default_bool(child_options, BDRV_OPT_CACHE_NO_FLUSH, true);
}
static const BdrvChildRole child_vvfat_qcow = {
diff --git a/blockdev.c b/blockdev.c
index 76f811c415..9d4955f23e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -645,17 +645,26 @@ err_no_opts:
return NULL;
}
-/* Takes the ownership of bs_opts */
-static BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp)
+/* Takes the ownership of bs_opts.
+ * If @string_opts is true, @bs_opts contains purely string values.
+ * Otherwise, all values are correctly typed. */
+static BlockDriverState *bds_tree_init(QDict *bs_opts, bool string_opts,
+ Error **errp)
{
int bdrv_flags = 0;
/* bdrv_open() defaults to the values in bdrv_flags (for compatibility
* with other callers) rather than what we want as the real defaults.
* Apply the defaults here instead. */
- qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_DIRECT, "off");
- qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off");
- qdict_set_default_str(bs_opts, BDRV_OPT_READ_ONLY, "off");
+ if (string_opts) {
+ qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_DIRECT, "off");
+ qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off");
+ qdict_set_default_str(bs_opts, BDRV_OPT_READ_ONLY, "off");
+ } else {
+ qdict_set_default_bool(bs_opts, BDRV_OPT_CACHE_DIRECT, false);
+ qdict_set_default_bool(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, false);
+ qdict_set_default_bool(bs_opts, BDRV_OPT_READ_ONLY, false);
+ }
if (runstate_check(RUN_STATE_INMIGRATE)) {
bdrv_flags |= BDRV_O_INACTIVE;
@@ -4027,7 +4036,7 @@ void hmp_drive_add_node(Monitor *mon, const char *optstr)
goto out;
}
- BlockDriverState *bs = bds_tree_init(qdict, &local_err);
+ BlockDriverState *bs = bds_tree_init(qdict, true, &local_err);
if (!bs) {
error_report_err(local_err);
goto out;
@@ -4063,7 +4072,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
goto fail;
}
- bs = bds_tree_init(qdict, errp);
+ bs = bds_tree_init(qdict, false, errp);
if (!bs) {
goto fail;
}
--
2.14.3
next prev parent reply other threads:[~2018-05-02 21:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 21:32 [Qemu-devel] [RFC 0/7] block: Try to use correctly typed blockdev options Max Reitz
2018-05-02 21:32 ` [Qemu-devel] [RFC 1/7] qdict: Add qdict_set_default_bool() Max Reitz
2018-05-02 21:32 ` [Qemu-devel] [RFC 2/7] block: Let change-medium add detect-zeroes as bool Max Reitz
2018-05-02 21:32 ` Max Reitz [this message]
2018-05-02 21:32 ` [Qemu-devel] [RFC 4/7] block: Add bdrv_open_string_opts() Max Reitz
2018-05-02 21:32 ` [Qemu-devel] [RFC 5/7] block: Add blk_new_open_string_opts() Max Reitz
2018-05-02 21:32 ` [Qemu-devel] [RFC 6/7] block: Use {blk_new, bdrv}_open_string_opts() Max Reitz
2018-05-02 21:32 ` [Qemu-devel] [RFC 7/7] iotests: Test internal option typing Max Reitz
2018-05-02 21:36 ` [Qemu-devel] [Qemu-block] [RFC 0/7] block: Try to use correctly typed blockdev options Max Reitz
2018-05-03 8:16 ` [Qemu-devel] " Markus Armbruster
2018-05-04 15:53 ` Max Reitz
2018-05-04 16:11 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180502213219.7842-4-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).