From nobody Wed Oct 29 17:29:48 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525296899089371.76266987307247; Wed, 2 May 2018 14:34:59 -0700 (PDT) Received: from localhost ([::1]:52633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzOi-0000Gf-7V for importer@patchew.org; Wed, 02 May 2018 17:34:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMZ-0007TE-5p for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMX-0000LY-TM for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47078 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 1fDzMT-0000Ik-De; Wed, 02 May 2018 17:32:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61D7C40704AD; Wed, 2 May 2018 21:32:26 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C9781117657; Wed, 2 May 2018 21:32:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:13 +0200 Message-Id: <20180502213219.7842-2-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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 02 May 2018 21:32:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 02 May 2018 21:32:27 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 1/7] qdict: Add 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" Signed-off-by: Max Reitz --- include/qapi/qmp/qdict.h | 1 + qobject/qdict.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 2cc3e906f7..a6fb89302d 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -69,6 +69,7 @@ const char *qdict_get_try_str(const QDict *qdict, const c= har *key); =20 void qdict_copy_default(QDict *dst, QDict *src, const char *key); void qdict_set_default_str(QDict *dst, const char *key, const char *val); +void qdict_set_default_bool(QDict *dst, const char *key, bool val); =20 QDict *qdict_clone_shallow(const QDict *src); void qdict_flatten(QDict *qdict); diff --git a/qobject/qdict.c b/qobject/qdict.c index d1997a0d8a..5c25da36b3 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -498,6 +498,19 @@ void qdict_set_default_str(QDict *dst, const char *key= , const char *val) qdict_put_str(dst, key, val); } =20 +/** + * qdict_set_default_bool(): If no entry mapped by 'key' exists in + * 'dst' yet, a new QBool initialized by 'val' is put there. + */ +void qdict_set_default_bool(QDict *dst, const char *key, bool val) +{ + if (qdict_haskey(dst, key)) { + return; + } + + qdict_put_bool(dst, key, val); +} + static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix); =20 --=20 2.14.3 From nobody Wed Oct 29 17:29:48 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 1525296908172513.3851399361514; Wed, 2 May 2018 14:35:08 -0700 (PDT) Received: from localhost ([::1]:52635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzOx-0000Uc-3j for importer@patchew.org; Wed, 02 May 2018 17:35:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMZ-0007TX-EX for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMY-0000Ll-BC for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47888 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 1fDzMU-0000J6-Fk; Wed, 02 May 2018 17:32:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6900C76FBA; Wed, 2 May 2018 21:32:28 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F70983B6A; Wed, 2 May 2018 21:32:27 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:14 +0200 Message-Id: <20180502213219.7842-3-mreitz@redhat.com> In-Reply-To: <20180502213219.7842-1-mreitz@redhat.com> References: <20180502213219.7842-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 02 May 2018 21:32:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 02 May 2018 21:32:29 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 2/7] block: Let change-medium add detect-zeroes as 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" There is no reason to use the wrong type here. Signed-off-by: Max Reitz --- blockdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index c31bf3d98d..76f811c415 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2654,7 +2654,7 @@ void qmp_blockdev_change_medium(bool has_device, cons= t char *device, =20 options =3D qdict_new(); detect_zeroes =3D blk_get_detect_zeroes_from_root_state(blk); - qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off"); + qdict_put_bool(options, "detect-zeroes", detect_zeroes); =20 if (has_format) { qdict_put_str(options, "driver", format); --=20 2.14.3 From nobody Wed Oct 29 17:29:48 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 From nobody Wed Oct 29 17:29:48 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 152529705406358.5082434561906; Wed, 2 May 2018 14:37:34 -0700 (PDT) Received: from localhost ([::1]:52652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzRN-0002rr-1B for importer@patchew.org; Wed, 02 May 2018 17:37:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMb-0007Vk-J3 for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMa-0000NA-FI for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47080 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 1fDzMX-0000KQ-1w; Wed, 02 May 2018 17:32:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8198A406EA4F; Wed, 2 May 2018 21:32:32 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 256872022EE0; Wed, 2 May 2018 21:32:31 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:16 +0200 Message-Id: <20180502213219.7842-5-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.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 02 May 2018 21:32:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 02 May 2018 21:32:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 4/7] block: Add bdrv_open_string_opts() 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" This function is to be used by callers that cannot guarantee that all values in @options are correctly typed. In the future, we would like this function to be gone, of course, but for now it at least lets us begin a proper separation of legacy interfaces. Signed-off-by: Max Reitz --- include/block/block.h | 2 ++ block.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 3894edda9d..5335fa8c20 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -261,6 +261,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_open_string_opts(const char *filename, QDict *optio= ns, + 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, diff --git a/block.c b/block.c index 8a8d9c02a9..1969fa303f 100644 --- a/block.c +++ b/block.c @@ -35,6 +35,7 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/qnull.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qapi/qapi-visit-block-core.h" #include "sysemu/block-backend.h" @@ -77,6 +78,8 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, const BdrvChildRole *child_role, Error **errp); =20 +static QDict *bdrv_type_blockdev_opts(QDict *options); + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; =20 @@ -1465,9 +1468,7 @@ static QDict *parse_json_filename(const char *filenam= e, Error **errp) return NULL; } =20 - qdict_flatten(options); - - return options; + return bdrv_type_blockdev_opts(options); } =20 static void parse_json_protocol(QDict *options, const char **pfilename, @@ -2801,6 +2802,83 @@ BlockDriverState *bdrv_open(const char *filename, co= nst char *reference, NULL, errp); } =20 +/* + * Take a blockdev @options QDict and convert its values to the + * correct type. This function takes ownership of @options. + * + * On both success and failure, @options is flattened. On success, + * its refcount is decreased and a new well typed flattened QDict is + * returned. On failure, @options is returned. + * + * TODO: Currently, this function cannot cope with partially typed + * dicts. If everything is typed correctly, the keyval visitor will + * complain and we will return the original @options -- which is + * correct. If all values are strings, the visitor will convert them + * to the correct type (if possible). But if both are mixed, the + * visitor will fail and the partially typed @options is returned. In + * practice, this should only be an issue with json:{} filenames, + * though. + * + * TODO: If @options does not conform to the schema, that should be a + * real error. + * + * TODO: Ideally, bdrv_open() should take BlockdevOptions, and the BDS + * should only contain BlockdevOptions. But this is not possible + * until this function really rejects anything it does not recognize + * (without breaking existing interfaces). + */ +static QDict *bdrv_type_blockdev_opts(QDict *options) +{ + Visitor *v; + BlockdevOptions *blockdev_options =3D NULL; + QObject *typed_opts, *crumpled_opts =3D NULL; + Error *local_err =3D NULL; + + if (!options) { + return NULL; + } + + qdict_flatten(options); + crumpled_opts =3D qdict_crumple(options, &local_err); + if (local_err) { + goto done; + } + + v =3D qobject_input_visitor_new_keyval(crumpled_opts); + visit_type_BlockdevOptions(v, NULL, &blockdev_options, &local_err); + visit_free(v); + if (local_err) { + goto done; + } + + v =3D qobject_output_visitor_new(&typed_opts); + visit_type_BlockdevOptions(v, NULL, &blockdev_options, &local_err); + if (!local_err) { + visit_complete(v, &typed_opts); + } + visit_free(v); + if (local_err) { + goto done; + } + + QDECREF(options); + options =3D qobject_to(QDict, typed_opts); + qdict_flatten(options); + +done: + error_free(local_err); + qapi_free_BlockdevOptions(blockdev_options); + qobject_decref(crumpled_opts); + return options; +} + +BlockDriverState *bdrv_open_string_opts(const char *filename, QDict *optio= ns, + int flags, Error **errp) +{ + return bdrv_open_inherit(filename, NULL, bdrv_type_blockdev_opts(optio= ns), + flags, NULL, NULL, errp); +} + /* * Adds a BlockDriverState to a simple queue for an atomic, transactional * reopen of multiple devices. --=20 2.14.3 From nobody Wed Oct 29 17:29:48 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 1525297045732739.4031173819029; Wed, 2 May 2018 14:37:25 -0700 (PDT) Received: from localhost ([::1]:52651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzRE-0002k8-R7 for importer@patchew.org; Wed, 02 May 2018 17:37:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMc-0007X5-JY for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMb-0000OC-Ml for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39920 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 1fDzMZ-0000M3-1o; Wed, 02 May 2018 17:32:35 -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 67F32406C78A; Wed, 2 May 2018 21:32:34 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 147802166BAD; Wed, 2 May 2018 21:32:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:17 +0200 Message-Id: <20180502213219.7842-6-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:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 02 May 2018 21:32:34 +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 5/7] block: Add blk_new_open_string_opts() 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" This is an interface to bdrv_open_string_opts(). Signed-off-by: Max Reitz --- 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 *option= s, + 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 =3D { static void drive_info_del(DriveInfo *dinfo); static BlockBackend *bdrv_first_blk(BlockDriverState *bs); =20 +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 =3D QTAILQ_HEAD_INITIALIZER(block_backends); @@ -348,6 +353,24 @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_p= erm) */ 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, err= p); +} + +/* + * 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 *option= s, + 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, } =20 blk =3D blk_new(perm, BLK_PERM_ALL); - bs =3D bdrv_open(filename, reference, options, flags, errp); + if (string_opts) { + assert(!reference); + bs =3D bdrv_open_string_opts(filename, options, flags, errp); + } else { + bs =3D bdrv_open(filename, reference, options, flags, errp); + } if (!bs) { blk_unref(blk); return NULL; --=20 2.14.3 From nobody Wed Oct 29 17:29:48 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525296904883341.0781782419323; Wed, 2 May 2018 14:35:04 -0700 (PDT) Received: from localhost ([::1]:52634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzOw-0000UC-R1 for importer@patchew.org; Wed, 02 May 2018 17:35:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMg-0007bx-RN for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMf-0000Pg-Ja for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47090 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 1fDzMa-0000NF-Sz; Wed, 02 May 2018 17:32:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 529A2406E973; Wed, 2 May 2018 21:32:36 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F083E83B67; Wed, 2 May 2018 21:32:35 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:18 +0200 Message-Id: <20180502213219.7842-7-mreitz@redhat.com> In-Reply-To: <20180502213219.7842-1-mreitz@redhat.com> References: <20180502213219.7842-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 02 May 2018 21:32:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 02 May 2018 21:32:36 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 6/7] block: Use {blk_new, bdrv}_open_string_opts() 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" This patch makes every caller of blk_new_open() and bdrv_open() instead call blk_new_open_string_opts() or bdrv_open_string_opts(), respectively, when needed. That is the case when the blockdev options QDict may contain incorrectly typed string values. In fact, all callers converted in this patch pass dicts that contain string values only; and after this patch, all remaining callers of blk_new_open() and bdrv_open() indeed guarantee that the dicts contain only values that are correctly typed. Signed-off-by: Max Reitz --- Assuming that bdrv_open_inherit() always receives correctly typed options and that parse_json_filename() always returns a correctly typed dict, bs->options will always be correctly typed after this patch (as far as I can see, that is). All other callers of bdrv_open_inherit() besides bdrv_open() and bdrv_open_string_opts() will inductively fulfill these conditions, if they are met before them. Now, of course both assumptions are wrong in the general case. parse_json_filename() will only return a correctly typed dict if the user used the correct types, or if all values were strings (which can be converted with bdrv_type_blockdev_opts()). Forbidding all other cases could be seen as a bug fix, though. But even more importantly, bdrv_open_string_opts() may receive a dict that does not match the schema because there are string values that do not match it. --- blockdev.c | 8 ++++++-- qemu-img.c | 3 ++- qemu-io.c | 2 +- qemu-nbd.c | 2 +- tests/test-replication.c | 6 +++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9d4955f23e..3e1125cbfa 100644 --- a/blockdev.c +++ b/blockdev.c @@ -595,7 +595,7 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, bdrv_flags |=3D BDRV_O_INACTIVE; } =20 - blk =3D blk_new_open(file, NULL, bs_opts, bdrv_flags, errp); + blk =3D blk_new_open_string_opts(file, bs_opts, bdrv_flags, errp); if (!blk) { goto err_no_bs_opts; } @@ -670,7 +670,11 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts,= bool string_opts, bdrv_flags |=3D BDRV_O_INACTIVE; } =20 - return bdrv_open(NULL, NULL, bs_opts, bdrv_flags, errp); + if (string_opts) { + return bdrv_open_string_opts(NULL, bs_opts, bdrv_flags, errp); + } else { + return bdrv_open(NULL, NULL, bs_opts, bdrv_flags, errp); + } } =20 void blockdev_close_all_bdrv_states(void) diff --git a/qemu-img.c b/qemu-img.c index 42b60917b0..a29d76797f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -284,7 +284,7 @@ static BlockBackend *img_open_opts(const char *optstr, } qdict_put_str(options, BDRV_OPT_FORCE_SHARE, "on"); } - blk =3D blk_new_open(NULL, NULL, options, flags, &local_err); + blk =3D blk_new_open_string_opts(NULL, options, flags, &local_err); if (!blk) { error_reportf_err(local_err, "Could not open '%s': ", optstr); return NULL; @@ -294,6 +294,7 @@ static BlockBackend *img_open_opts(const char *optstr, return blk; } =20 +/* @options must be correctly typed */ static BlockBackend *img_open_file(const char *filename, QDict *options, const char *fmt, int flags, diff --git a/qemu-io.c b/qemu-io.c index 0755a30447..544e47b7fc 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -102,7 +102,7 @@ static int openfile(char *name, int flags, bool writeth= rough, bool force_share, } qdict_put_str(opts, BDRV_OPT_FORCE_SHARE, "on"); } - qemuio_blk =3D blk_new_open(name, NULL, opts, flags, &local_err); + qemuio_blk =3D blk_new_open_string_opts(name, opts, flags, &local_err); if (!qemuio_blk) { error_reportf_err(local_err, "can't open%s%s: ", name ? " device " : "", name ?: ""); diff --git a/qemu-nbd.c b/qemu-nbd.c index 0af0560ad1..e5e1877106 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -944,7 +944,7 @@ int main(int argc, char **argv) } options =3D qemu_opts_to_qdict(opts, NULL); qemu_opts_reset(&file_opts); - blk =3D blk_new_open(NULL, NULL, options, flags, &local_err); + blk =3D blk_new_open_string_opts(NULL, options, flags, &local_err); } else { if (fmt) { options =3D qdict_new(); diff --git a/tests/test-replication.c b/tests/test-replication.c index 68c0d04f2a..5a2bae66fd 100644 --- a/tests/test-replication.c +++ b/tests/test-replication.c @@ -191,7 +191,7 @@ static BlockBackend *start_primary(void) qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); =20 - blk =3D blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &local_err); + blk =3D blk_new_open_string_opts(NULL, qdict, BDRV_O_RDWR, &local_err); g_assert(blk); g_assert(!local_err); =20 @@ -323,7 +323,7 @@ static BlockBackend *start_secondary(void) qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); =20 - blk =3D blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &local_err); + blk =3D blk_new_open_string_opts(NULL, qdict, BDRV_O_RDWR, &local_err); assert(blk); monitor_add_blk(blk, S_LOCAL_DISK_ID, &local_err); g_assert(!local_err); @@ -350,7 +350,7 @@ static BlockBackend *start_secondary(void) qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); =20 - blk =3D blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &local_err); + blk =3D blk_new_open_string_opts(NULL, qdict, BDRV_O_RDWR, &local_err); assert(blk); monitor_add_blk(blk, S_ID, &local_err); g_assert(!local_err); --=20 2.14.3 From nobody Wed Oct 29 17:29:48 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 1525297167594256.27692826380155; Wed, 2 May 2018 14:39:27 -0700 (PDT) Received: from localhost ([::1]:52667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzTC-0004tV-Vs for importer@patchew.org; Wed, 02 May 2018 17:39:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDzMh-0007cp-Dz for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDzMg-0000Py-GD for qemu-devel@nongnu.org; Wed, 02 May 2018 17:32:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47890 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 1fDzMc-0000Oq-KW; Wed, 02 May 2018 17:32:38 -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 3DACBF1207; Wed, 2 May 2018 21:32:38 +0000 (UTC) Received: from localhost (unknown [10.40.205.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBC602166BAD; Wed, 2 May 2018 21:32:37 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 2 May 2018 23:32:19 +0200 Message-Id: <20180502213219.7842-8-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.1]); Wed, 02 May 2018 21:32:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 02 May 2018 21:32:38 +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 7/7] iotests: Test internal option typing 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" It would be nice if qemu used the correct types for blockdev options internally, even if the user specified string values (either through -drive or by being not so nice and using json:{} with string values). This patch adds a test verifying that fact. Signed-off-by: Max Reitz --- tests/qemu-iotests/089 | 12 ++++++++++++ tests/qemu-iotests/089.out | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089 index aa1ba4a98e..640ecbfa2a 100755 --- a/tests/qemu-iotests/089 +++ b/tests/qemu-iotests/089 @@ -145,6 +145,18 @@ $QEMU_IO -c "open -o driver=3Dqcow2 json:{\"file.filen= ame\":\"$TEST_IMG\"}" \ $QEMU_IO -c "open -o driver=3Dqcow2 json:{\"driver\":\"raw\",\"file.filena= me\":\"$TEST_IMG\"}" \ -c "info" 2>&1 | _filter_img_info =20 +echo +echo "=3D=3D=3D Testing option typing =3D=3D=3D" +echo + +# json:{} accepts both strings and correctly typed values (even mixed, +# although we probably do not want to support that...), but when +# creating a json:{} filename, it should be correctly typed. +# Therefore, both of these should make the "size" value an integer. + +TEST_IMG=3D"json:{'driver': 'null-co', 'size': 42 }" _img_info | grep '^i= mage' +TEST_IMG=3D"json:{'driver': 'null-co', 'size': '42'}" _img_info | grep '^i= mage' + =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out index 89e3e4340a..d880fd76f7 100644 --- a/tests/qemu-iotests/089.out +++ b/tests/qemu-iotests/089.out @@ -49,4 +49,9 @@ vm state offset: 512 MiB format name: IMGFMT cluster size: 64 KiB vm state offset: 512 MiB + +=3D=3D=3D Testing option typing =3D=3D=3D + +image: json:{"driver": "null-co", "size": 42} +image: json:{"driver": "null-co", "size": 42} *** done --=20 2.14.3