From nobody Sat May 4 06:29:33 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.zoho.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 1492551339879607.5637256156492; Tue, 18 Apr 2017 14:35:39 -0700 (PDT) Received: from localhost ([::1]:44769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0amf-00025b-NF for importer@patchew.org; Tue, 18 Apr 2017 17:35:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0alR-0001NG-RY for qemu-devel@nongnu.org; Tue, 18 Apr 2017 17:34:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0alR-0002QJ-2B for qemu-devel@nongnu.org; Tue, 18 Apr 2017 17:34:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0alK-0002ND-AY; Tue, 18 Apr 2017 17:34:14 -0400 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 3AF76804E4; Tue, 18 Apr 2017 21:34:13 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76EB8779FC; Tue, 18 Apr 2017 21:34:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3AF76804E4 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3AF76804E4 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 18 Apr 2017 16:34:04 -0500 Message-Id: <20170418213404.6455-1-eblake@redhat.com> In-Reply-To: <20170418013356.3578-7-eblake@redhat.com> References: <20170418013356.3578-7-eblake@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.27]); Tue, 18 Apr 2017 21:34:13 +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 v1.5 06.5/31] fixup! block: Convert bdrv_get_block_status() to bytes 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, famz@redhat.com, Stefan Hajnoczi , qemu-block@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" [adjust a paragraph of the original commit message] ... Note that we have an inherent limitation in the BDRV_BLOCK_* return values: BDRV_BLOCK_OFFSET_VALID can only return the start of a sector, even if we later relax the interface to query for the status starting at an intermediate byte; document the obvious interpretation that valid offsets are always sector-relative. Furthermore, note that many callers are expecting sector-aligned answers, especially since bdrv_getlength() is sector-aligned even when it exceeds the actual file size; so we intentionally lie and state that any partial sector at the end of a file has the same status for the entire sector, rather than a literal interpretation of a hole starting at a mid-sector location due to end-of-file. ... Signed-off-by: Eric Blake --- This was sufficient to avoid failure of qemu-iotests 109 after patch 13/31 adjusts file-posix.c to clamp EOF numbers to mid-sector locations. block/io.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/io.c b/block/io.c index 361eeb8..bee6c71 100644 --- a/block/io.c +++ b/block/io.c @@ -1769,6 +1769,14 @@ static int64_t coroutine_fn bdrv_co_block_status(Blo= ckDriverState *bs, bs->bl.request_alignment) - aligned_offse= t; ret =3D bs->drv->bdrv_co_block_status(bs, aligned_offset, aligned_= bytes, &n, file); + + /* total_size is always sector-aligned, by sometimes exceeding act= ual + * file size. Expand n if it lands mid-sector due to end-of-file. = */ + if (ret >=3D 0 && QEMU_ALIGN_UP(n + aligned_offset, + BDRV_SECTOR_SIZE) =3D=3D total_size)= { + n =3D total_size - aligned_offset; + } + /* Clamp pnum and ret to original request */ if (aligned_offset !=3D offset && ret >=3D 0) { int sectors =3D DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) - --=20 2.9.3