From nobody Mon Apr 29 22:32:12 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510352164206673.7357217257044; Fri, 10 Nov 2017 14:16:04 -0800 (PST) Received: from localhost ([::1]:43667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDHab-0006H6-Al for importer@patchew.org; Fri, 10 Nov 2017 17:15:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDHYS-0004ii-D4 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 17:13:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDHYR-0005YN-JV for qemu-devel@nongnu.org; Fri, 10 Nov 2017 17:13:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDHYN-0005WX-E5; Fri, 10 Nov 2017 17:13:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FFB3820ED; Fri, 10 Nov 2017 22:13:34 +0000 (UTC) Received: from localhost (ovpn-204-126.brq.redhat.com [10.40.204.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36AF36F45E; Fri, 10 Nov 2017 22:13:34 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 10 Nov 2017 23:13:27 +0100 Message-Id: <20171110221329.24176-2-mreitz@redhat.com> In-Reply-To: <20171110221329.24176-1-mreitz@redhat.com> References: <20171110221329.24176-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 10 Nov 2017 22:13:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.12 1/3] qapi: Add qdict_is_null() 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 Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- include/qapi/qmp/qdict.h | 1 + qobject/qdict.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index fc218e7be6..c65ebfc748 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -76,6 +76,7 @@ int64_t qdict_get_try_int(const QDict *qdict, const char = *key, int64_t def_value); bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_valu= e); const char *qdict_get_try_str(const QDict *qdict, const char *key); +bool qdict_is_qnull(const QDict *qdict, const char *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); diff --git a/qobject/qdict.c b/qobject/qdict.c index e8f15f1132..a032ea629a 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -294,6 +294,16 @@ const char *qdict_get_try_str(const QDict *qdict, cons= t char *key) } =20 /** + * qdict_is_qnull(): Return true if the value for 'key' is QNull + */ +bool qdict_is_qnull(const QDict *qdict, const char *key) +{ + QObject *value =3D qdict_get(qdict, key); + + return value && value->type =3D=3D QTYPE_QNULL; +} + +/** * qdict_iter(): Iterate over all the dictionary's stored values. * * This function allows the user to provide an iterator, which will be --=20 2.13.6 From nobody Mon Apr 29 22:32:12 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510352313552944.540551758711; Fri, 10 Nov 2017 14:18:33 -0800 (PST) Received: from localhost ([::1]:43680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDHcu-0007w3-KW for importer@patchew.org; Fri, 10 Nov 2017 17:18:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDHYT-0004jZ-HO for qemu-devel@nongnu.org; Fri, 10 Nov 2017 17:13:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDHYS-0005Z4-D8 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 17:13:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDHYP-0005X0-Pa; Fri, 10 Nov 2017 17:13:37 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D46272FE9; Fri, 10 Nov 2017 22:13:37 +0000 (UTC) Received: from localhost (ovpn-204-126.brq.redhat.com [10.40.204.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93FCD5D99A; Fri, 10 Nov 2017 22:13:36 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 10 Nov 2017 23:13:28 +0100 Message-Id: <20171110221329.24176-3-mreitz@redhat.com> In-Reply-To: <20171110221329.24176-1-mreitz@redhat.com> References: <20171110221329.24176-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 10 Nov 2017 22:13:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.12 2/3] block: Handle null backing link 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_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of converting all "backing": null instances into "backing": "", handle a null value directly in bdrv_open_inherit(). This enables explicitly null backing links for json:{} filenames. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- block.c | 2 +- blockdev.c | 14 -------------- tests/qemu-iotests/089 | 20 ++++++++++++++++++++ tests/qemu-iotests/089.out | 8 ++++++++ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 85427df577..bc92ddd5a0 100644 --- a/block.c +++ b/block.c @@ -2558,7 +2558,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, =20 /* See cautionary note on accessing @options above */ backing =3D qdict_get_try_str(options, "backing"); - if (backing && *backing =3D=3D '\0') { + if (qdict_is_qnull(options, "backing") || (backing && *backing =3D=3D = '\0')) { flags |=3D BDRV_O_NO_BACKING; qdict_del(options, "backing"); } diff --git a/blockdev.c b/blockdev.c index 56a6b24a0b..99ef618b39 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3885,7 +3885,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Error= **errp) QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); QDict *qdict; - const QDictEntry *ent; Error *local_err =3D NULL; =20 visit_type_BlockdevOptions(v, NULL, &options, &local_err); @@ -3899,19 +3898,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Erro= r **errp) =20 qdict_flatten(qdict); =20 - /* - * Rewrite "backing": null to "backing": "" - * TODO Rewrite "" to null instead, and perhaps not even here - */ - for (ent =3D qdict_first(qdict); ent; ent =3D qdict_next(qdict, ent)) { - char *dot =3D strrchr(ent->key, '.'); - - if (!strcmp(dot ? dot + 1 : ent->key, "backing") - && qobject_type(ent->value) =3D=3D QTYPE_QNULL) { - qdict_put(qdict, ent->key, qstring_new()); - } - } - if (!qdict_get_try_str(qdict, "node-name")) { error_setg(errp, "'node-name' must be specified for the root node"= ); goto fail; diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089 index 9bfe2307b3..832eac1248 100755 --- a/tests/qemu-iotests/089 +++ b/tests/qemu-iotests/089 @@ -82,6 +82,26 @@ $QEMU_IO_PROG --cache $CACHEMODE \ $QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io =20 =20 +echo +echo "=3D=3D=3D Testing correct handling of 'backing':null =3D=3D=3D" +echo + +_make_test_img -b "$TEST_IMG.base" $IMG_SIZE + +# This should read 42 +$QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io + +# This should read 0 +$QEMU_IO -c 'read -P 0 0 512' "json:{\ + 'driver': '$IMGFMT', + 'file': { + 'driver': 'file', + 'filename': '$TEST_IMG' + }, + 'backing': null +}" | _filter_qemu_io + + # Taken from test 071 echo echo "=3D=3D=3D Testing blkdebug =3D=3D=3D" diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out index 18f5fdda7a..607a9c6d9c 100644 --- a/tests/qemu-iotests/089.out +++ b/tests/qemu-iotests/089.out @@ -19,6 +19,14 @@ Pattern verification failed at offset 0, 512 bytes read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 +=3D=3D=3D Testing correct handling of 'backing':null =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + =3D=3D=3D Testing blkdebug =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 --=20 2.13.6 From nobody Mon Apr 29 22:32:12 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510352151845870.4068270606787; Fri, 10 Nov 2017 14:15:51 -0800 (PST) Received: from localhost ([::1]:43662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDHaG-0005ut-Sh for importer@patchew.org; Fri, 10 Nov 2017 17:15:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDHYW-0004mq-81 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 17:13:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDHYV-0005aD-0E for qemu-devel@nongnu.org; Fri, 10 Nov 2017 17:13:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDHYS-0005Yv-Nf; Fri, 10 Nov 2017 17:13:40 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D83368765E; Fri, 10 Nov 2017 22:13:39 +0000 (UTC) Received: from localhost (ovpn-204-126.brq.redhat.com [10.40.204.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6896F63620; Fri, 10 Nov 2017 22:13:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 10 Nov 2017 23:13:29 +0100 Message-Id: <20171110221329.24176-4-mreitz@redhat.com> In-Reply-To: <20171110221329.24176-1-mreitz@redhat.com> References: <20171110221329.24176-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 10 Nov 2017 22:13:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.12 3/3] block: Deprecate "backing": "" 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_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have a clear replacement, so let's deprecate it. Signed-off-by: Max Reitz Reviewed-by: Markus Armbruster --- qapi/block-core.json | 4 ++-- block.c | 4 ++++ qemu-doc.texi | 7 +++++++ qemu-options.hx | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 76bf50f813..dfe4d3650c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1090,7 +1090,7 @@ # @overlay: reference to the existing block device that will become # the overlay of @node, as part of creating the snapshot. # It must not have a current backing file (this can be -# achieved by passing "backing": "" to blockdev-add). +# achieved by passing "backing": null to blockdev-add). # # Since: 2.5 ## @@ -1238,7 +1238,7 @@ # "node-name": "node1534", # "file": { "driver": "file", # "filename": "hd1.qcow2" }, -# "backing": "" } } +# "backing": null } } # # <- { "return": {} } # diff --git a/block.c b/block.c index bc92ddd5a0..463c4de25b 100644 --- a/block.c +++ b/block.c @@ -2559,6 +2559,10 @@ static BlockDriverState *bdrv_open_inherit(const cha= r *filename, /* See cautionary note on accessing @options above */ backing =3D qdict_get_try_str(options, "backing"); if (qdict_is_qnull(options, "backing") || (backing && *backing =3D=3D = '\0')) { + if (backing) { + warn_report("Use of \"backing\": \"\" is deprecated; " + "use \"backing\": null instead"); + } flags |=3D BDRV_O_NO_BACKING; qdict_del(options, "backing"); } diff --git a/qemu-doc.texi b/qemu-doc.texi index 8c10956a66..8f57d9ad21 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2537,6 +2537,13 @@ or ``ivshmem-doorbell`` device types. The ``spapr-pci-vfio-host-bridge'' device type is replaced by the ``spapr-pci-host-bridge'' device type. =20 +@section Block device options + +@subsection "backing": "" (since 2.12.0) + +In order to prevent QEMU from automatically opening an image's backing +chain, use ``"backing": null'' instead. + @node License @appendix License =20 diff --git a/qemu-options.hx b/qemu-options.hx index 3728e9b4dd..0ee1a04d00 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -731,8 +731,8 @@ Reference to or definition of the data source block dri= ver node =20 @item backing Reference to or definition of the backing file block device (default is ta= ken -from the image file). It is allowed to pass an empty string here in order = to -disable the default backing file. +from the image file). It is allowed to pass @code{null} here in order to d= isable +the default backing file. =20 @item lazy-refcounts Whether to enable the lazy refcounts feature (on/off; default is taken fro= m the --=20 2.13.6