From nobody Thu Oct 30 05:19:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525297065281477.958225253598; Wed, 2 May 2018 14:37:45 -0700 (PDT) Received: from localhost ([::1]:52653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzRY-000334-G3 for importer@patchew.org; Wed, 02 May 2018 17:37:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMa-0007Ur-Qk for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMZ-0000Mo-MG for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39918 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDzMW-0000Ju-7K; Wed, 02 May 2018 17:32:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93808406C795; Wed, 2 May 2018 21:32:30 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 065362166BAD; Wed, 2 May 2018 21:32:29 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:15 +0200 Message-Id: <20180502213219.7842-4-mreitz@redhat.com> In-Reply-To: <20180502213219.7842-1-mreitz@redhat.com> References: <20180502213219.7842-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 02 May 2018 21:32:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 02 May 2018 21:32:31 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC 3/7] block: Make use of qdict_set_default_bool() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D (parent_flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY; =20 /* For temporary files, unconditional cache=3Dunsafe 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); =20 /* 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, QD= ict *child_options, qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE= ); =20 /* 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 &=3D ~BDRV_O_COPY_ON_READ; =20 /* snapshot=3Don 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 t= he * 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); } =20 bs =3D 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 =3D { 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); } =20 static const BdrvChildRole child_vvfat_qcow =3D { 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; } =20 -/* 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 =3D 0; =20 /* 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); + } =20 if (runstate_check(RUN_STATE_INMIGRATE)) { bdrv_flags |=3D BDRV_O_INACTIVE; @@ -4027,7 +4036,7 @@ void hmp_drive_add_node(Monitor *mon, const char *opt= str) goto out; } =20 - BlockDriverState *bs =3D bds_tree_init(qdict, &local_err); + BlockDriverState *bs =3D 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; } =20 - bs =3D bds_tree_init(qdict, errp); + bs =3D bds_tree_init(qdict, false, errp); if (!bs) { goto fail; } --=20 2.14.3