From nobody Tue Apr 15 09:53:06 2025 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 1509024457929166.48842997046313; Thu, 26 Oct 2017 06:27:37 -0700 (PDT) Received: from localhost ([::1]:52905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7iBt-0007V4-VB for importer@patchew.org; Thu, 26 Oct 2017 09:27:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7i38-0000Pf-VR for qemu-devel@nongnu.org; Thu, 26 Oct 2017 09:18:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7i32-0001q4-Qb for qemu-devel@nongnu.org; Thu, 26 Oct 2017 09:18:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56126) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e7i2v-0001kB-UB; Thu, 26 Oct 2017 09:18:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DE997E3A6; Thu, 26 Oct 2017 13:18:05 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A7F77F5FF; Thu, 26 Oct 2017 13:18:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0DE997E3A6 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 26 Oct 2017 15:17:14 +0200 Message-Id: <20171026131741.5059-9-kwolf@redhat.com> In-Reply-To: <20171026131741.5059-1-kwolf@redhat.com> References: <20171026131741.5059-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 26 Oct 2017 13:18:05 +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] [PULL 08/35] qemu-img: Switch get_block_status() to byte-based 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 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Continue by converting an internal function (no semantic change), and simplifying its caller accordingly. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- qemu-img.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e9c7b30c91..af3effdec5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2671,14 +2671,16 @@ static void dump_map_entry(OutputFormat output_form= at, MapEntry *e, } } =20 -static int get_block_status(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, MapEntry *e) +static int get_block_status(BlockDriverState *bs, int64_t offset, + int64_t bytes, MapEntry *e) { int64_t ret; int depth; BlockDriverState *file; bool has_offset; + int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; =20 + assert(bytes < INT_MAX); /* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same * range repeatedly. @@ -2686,8 +2688,8 @@ static int get_block_status(BlockDriverState *bs, int= 64_t sector_num, =20 depth =3D 0; for (;;) { - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &nb_sect= ors, - &file); + ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_s= ectors, + &nb_sectors, &file); if (ret < 0) { return ret; } @@ -2707,7 +2709,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t sector_num, has_offset =3D !!(ret & BDRV_BLOCK_OFFSET_VALID); =20 *e =3D (MapEntry) { - .start =3D sector_num * BDRV_SECTOR_SIZE, + .start =3D offset, .length =3D nb_sectors * BDRV_SECTOR_SIZE, .data =3D !!(ret & BDRV_BLOCK_DATA), .zero =3D !!(ret & BDRV_BLOCK_ZERO), @@ -2837,16 +2839,12 @@ static int img_map(int argc, char **argv) =20 length =3D blk_getlength(blk); while (curr.start + curr.length < length) { - int64_t nsectors_left; - int64_t sector_num; - int n; - - sector_num =3D (curr.start + curr.length) >> BDRV_SECTOR_BITS; + int64_t offset =3D curr.start + curr.length; + int64_t n; =20 /* Probe up to 1 GiB at a time. */ - nsectors_left =3D DIV_ROUND_UP(length, BDRV_SECTOR_SIZE) - sector_= num; - n =3D MIN(1 << (30 - BDRV_SECTOR_BITS), nsectors_left); - ret =3D get_block_status(bs, sector_num, n, &next); + n =3D QEMU_ALIGN_DOWN(MIN(1 << 30, length - offset), BDRV_SECTOR_S= IZE); + ret =3D get_block_status(bs, offset, n, &next); =20 if (ret < 0) { error_report("Could not read file metadata: %s", strerror(-ret= )); --=20 2.13.6