From nobody Thu Oct 30 05:17:45 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