From patchwork Fri Dec 7 11:53:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10718027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4BC413BF for ; Fri, 7 Dec 2018 11:56:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2C332AB06 for ; Fri, 7 Dec 2018 11:56:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B666C2B232; Fri, 7 Dec 2018 11:56:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A09B2AB06 for ; Fri, 7 Dec 2018 11:56:09 +0000 (UTC) Received: from localhost ([::1]:45570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVEjp-00009H-1y for patchwork-qemu-devel@patchwork.kernel.org; Fri, 07 Dec 2018 06:56:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVEhz-0007Ak-Bk for qemu-devel@nongnu.org; Fri, 07 Dec 2018 06:54:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVEhx-0006HI-Qg for qemu-devel@nongnu.org; Fri, 07 Dec 2018 06:54:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gVEhs-0005jQ-Iz; Fri, 07 Dec 2018 06:54:08 -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 72FC03081D88; Fri, 7 Dec 2018 11:54:06 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-248.ams2.redhat.com [10.36.117.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id E183E6BC2F; Fri, 7 Dec 2018 11:54:01 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Dec 2018 12:53:43 +0100 Message-Id: <20181207115343.6747-6-kwolf@redhat.com> In-Reply-To: <20181207115343.6747-1-kwolf@redhat.com> References: <20181207115343.6747-1-kwolf@redhat.com> MIME-Version: 1.0 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.43]); Fri, 07 Dec 2018 11:54:06 +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 v4 5/5] 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, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 0793550cf2..afdd2f89a2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4068,7 +4068,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 = virtual_size / 2GB. +# calculated as extent_number = virtual_size / 2GB. Providing +# more extents than will be used is an error. # @subformat The subformat of the VMDK image. Default: "monolithicSparse". # @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 size, { int extent_idx; BlockBackend *blk = NULL; + BlockBackend *extent_blk; Error *local_err = NULL; char *desc = NULL; int ret = 0; @@ -2107,7 +2108,6 @@ static int coroutine_fn vmdk_co_do_create(int64_t size, } extent_idx = 1; while (created_size < size) { - BlockBackend *extent_blk; int64_t cur_size = MIN(size - created_size, extent_size); extent_blk = extent_fn(cur_size, extent_idx, flat, split, compress, zeroed_grain, opaque, errp); @@ -2121,6 +2121,17 @@ static int coroutine_fn vmdk_co_do_create(int64_t size, extent_idx++; blk_unref(extent_blk); } + + /* Check whether we got excess extents */ + extent_blk = 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 = -EINVAL; + goto exit; + } + /* generate descriptor file */ desc = 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 = NULL; char *rel_filename = NULL; + /* We're done, don't create excess extents. */ + if (size == -1) { + assert(errp == NULL); + return NULL; + } + if (idx == 0) { rel_filename = g_strdup_printf("%s%s", data->prefix, data->postfix); } 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); - ret = vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp); - if (ret) { - blk_unref(blk); - blk = NULL; + if (size != -1) { + ret = vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp); + if (ret) { + blk_unref(blk); + blk = 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 . # +import math import iotests from iotests import imgfmt @@ -222,12 +223,15 @@ with iotests.FilePath('t.vmdk') as disk_path, \ iotests.log("= %s %d =" % (subfmt, size)) iotests.log("") + num_extents = math.ceil(size / 2.0**31) + extents = [ "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() 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 {"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 512, "subformat": "monolithicFlat"}}} {"return": {}} +Job failed: List of extents contains unused extents {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -161,7 +162,7 @@ Job failed: Extent [0] not specified = twoGbMaxExtentFlat 512 = -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 512, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 512, "subformat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -181,7 +182,7 @@ Format specific information: = twoGbMaxExtentSparse 512 = -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 512, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 512, "subformat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -203,7 +204,7 @@ Format specific information: = twoGbMaxExtentFlat 1073741824 = -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 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: = twoGbMaxExtentSparse 1073741824 = -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 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: = twoGbMaxExtentFlat 2147483648 = -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 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: = twoGbMaxExtentSparse 2147483648 = -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "size": 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": {}}