From nobody Tue Apr 15 06:10:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15490402464791010.0122285526912; Fri, 1 Feb 2019 08:57:26 -0800 (PST) Received: from localhost ([127.0.0.1]:58045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc83-0007XR-1s for importer@patchew.org; Fri, 01 Feb 2019 11:57:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbno-0007Qs-D3 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbng-0008Hf-Un for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnT-00087q-Gj; Fri, 01 Feb 2019 11:36:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 899F37AE95; Fri, 1 Feb 2019 16:35:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 536F5608C6; Fri, 1 Feb 2019 16:35:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:03 +0100 Message-Id: <20190201163518.31157-13-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/27] vmdk: Reject excess extents in blockdev-create 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Clarify that the number of extents provided in BlockdevCreateOptionsVmdk must match the number of extents that will actually be used. Providing more extents will result in an error now. This requires adapting the test case to provide the right number of extents. Signed-off-by: Kevin Wolf Reviewed-by: Markus Armbruster --- qapi/block-core.json | 3 ++- block/vmdk.c | 29 ++++++++++++++++++++++++----- tests/qemu-iotests/237 | 6 +++++- tests/qemu-iotests/237.out | 13 +++++++------ 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index a5924b40af..5f17d67d71 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4184,7 +4184,8 @@ # twoGbMaxExtentSparse and twoGbMaxExtentFlat formats. For # monolithicFlat, only one entry is required; for # twoGbMaxExtent* formats, the number of entries required is -# calculated as extent_number =3D virtual_size / 2GB. +# calculated as extent_number =3D virtual_size / 2GB. Provid= ing +# more extents than will be used is an error. # @subformat The subformat of the VMDK image. Default: "monolithicSpars= e". # @backing-file The path of backing file. Default: no backing file is used. # @adapter-type The adapter type used to fill in the descriptor. Default: = ide. diff --git a/block/vmdk.c b/block/vmdk.c index 5a162ee85c..682ad93aa1 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1970,6 +1970,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t siz= e, { int extent_idx; BlockBackend *blk =3D NULL; + BlockBackend *extent_blk; Error *local_err =3D NULL; char *desc =3D NULL; int ret =3D 0; @@ -2107,7 +2108,6 @@ static int coroutine_fn vmdk_co_do_create(int64_t siz= e, } extent_idx =3D 1; while (created_size < size) { - BlockBackend *extent_blk; int64_t cur_size =3D MIN(size - created_size, extent_size); extent_blk =3D extent_fn(cur_size, extent_idx, flat, split, compre= ss, zeroed_grain, opaque, errp); @@ -2121,6 +2121,17 @@ static int coroutine_fn vmdk_co_do_create(int64_t si= ze, extent_idx++; blk_unref(extent_blk); } + + /* Check whether we got excess extents */ + extent_blk =3D extent_fn(-1, extent_idx, flat, split, compress, zeroed= _grain, + opaque, NULL); + if (extent_blk) { + blk_unref(extent_blk); + error_setg(errp, "List of extents contains unused extents"); + ret =3D -EINVAL; + goto exit; + } + /* generate descriptor file */ desc =3D g_strdup_printf(desc_template, g_random_int(), @@ -2181,6 +2192,12 @@ static BlockBackend *vmdk_co_create_opts_cb(int64_t = size, int idx, char *ext_filename =3D NULL; char *rel_filename =3D NULL; =20 + /* We're done, don't create excess extents. */ + if (size =3D=3D -1) { + assert(errp =3D=3D NULL); + return NULL; + } + if (idx =3D=3D 0) { rel_filename =3D g_strdup_printf("%s%s", data->prefix, data->postf= ix); } else if (split) { @@ -2342,10 +2359,12 @@ static BlockBackend *vmdk_co_create_cb(int64_t size= , int idx, blk_set_allow_write_beyond_eof(blk, true); bdrv_unref(bs); =20 - ret =3D vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp= ); - if (ret) { - blk_unref(blk); - blk =3D NULL; + if (size !=3D -1) { + ret =3D vmdk_init_extent(blk, size, flat, compress, zeroed_grain, = errp); + if (ret) { + blk_unref(blk); + blk =3D NULL; + } } return blk; } diff --git a/tests/qemu-iotests/237 b/tests/qemu-iotests/237 index e04a1ac6be..251771d7fb 100755 --- a/tests/qemu-iotests/237 +++ b/tests/qemu-iotests/237 @@ -20,6 +20,7 @@ # along with this program. If not, see . # =20 +import math import iotests from iotests import imgfmt =20 @@ -222,12 +223,15 @@ with iotests.FilePath('t.vmdk') as disk_path, \ iotests.log("=3D %s %d =3D" % (subfmt, size)) iotests.log("") =20 + num_extents =3D math.ceil(size / 2.0**31) + extents =3D [ "ext%d" % (i) for i in range(1, num_extents + 1)= ] + vm.launch() blockdev_create(vm, { 'driver': imgfmt, 'file': 'node0', 'size': size, 'subformat': subfmt, - 'extents': ['ext1', 'ext2', 'ext3'] }) + 'extents': extents }) vm.shutdown() =20 iotests.img_info_log(disk_path) diff --git a/tests/qemu-iotests/237.out b/tests/qemu-iotests/237.out index 1aa9aad349..241c864369 100644 --- a/tests/qemu-iotests/237.out +++ b/tests/qemu-iotests/237.out @@ -154,6 +154,7 @@ Job failed: Extent [0] not specified =20 {"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "monolithicFlat"}}} {"return": {}} +Job failed: List of extents contains unused extents {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 @@ -161,7 +162,7 @@ Job failed: Extent [0] not specified =20 =3D twoGbMaxExtentFlat 512 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 512, "subf= ormat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -181,7 +182,7 @@ Format specific information: =20 =3D twoGbMaxExtentSparse 512 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 512, "subf= ormat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -203,7 +204,7 @@ Format specific information: =20 =3D twoGbMaxExtentFlat 1073741824 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 1073741824, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 1073741824= , "subformat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -223,7 +224,7 @@ Format specific information: =20 =3D twoGbMaxExtentSparse 1073741824 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 1073741824, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 1073741824= , "subformat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -245,7 +246,7 @@ Format specific information: =20 =3D twoGbMaxExtentFlat 2147483648 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 2147483648, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 2147483648= , "subformat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -265,7 +266,7 @@ Format specific information: =20 =3D twoGbMaxExtentSparse 2147483648 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 2147483648, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 2147483648= , "subformat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} --=20 2.20.1