From nobody Tue Apr 15 09:53:07 2025 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 1509024201891827.5971720994704; Thu, 26 Oct 2017 06:23:21 -0700 (PDT) Received: from localhost ([::1]:52883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7i7t-000453-Uj for importer@patchew.org; Thu, 26 Oct 2017 09:23:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7i35-0000MA-IB for qemu-devel@nongnu.org; Thu, 26 Oct 2017 09:18:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7i34-0001rH-G3 for qemu-devel@nongnu.org; Thu, 26 Oct 2017 09:18:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4271) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e7i2u-0001iH-1t; Thu, 26 Oct 2017 09:18:04 -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 24869C0733F4; Thu, 26 Oct 2017 13:18:03 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B64027F7E5; Thu, 26 Oct 2017 13:18:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 24869C0733F4 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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:13 +0200 Message-Id: <20171026131741.5059-8-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.31]); Thu, 26 Oct 2017 13:18:03 +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 07/35] block: Switch bdrv_make_zero() 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_0 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. Change the internal loop iteration of zeroing a device to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are sector-aligned). Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/io.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index db8dc59c94..ad84d84888 100644 --- a/block/io.c +++ b/block/io.c @@ -716,38 +716,38 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offs= et, */ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) { - int64_t target_sectors, ret, nb_sectors, sector_num =3D 0; + int64_t target_size, ret, bytes, offset =3D 0; BlockDriverState *bs =3D child->bs; - int n; + int n; /* sectors */ =20 - target_sectors =3D bdrv_nb_sectors(bs); - if (target_sectors < 0) { - return target_sectors; + target_size =3D bdrv_getlength(bs); + if (target_size < 0) { + return target_size; } =20 for (;;) { - nb_sectors =3D MIN(target_sectors - sector_num, BDRV_REQUEST_MAX_S= ECTORS); - if (nb_sectors <=3D 0) { + bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <=3D 0) { return 0; } - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &n, NULL= ); + ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &n, NULL); if (ret < 0) { - error_report("error getting block status at sector %" PRId64 "= : %s", - sector_num, strerror(-ret)); + error_report("error getting block status at offset %" PRId64 "= : %s", + offset, strerror(-ret)); return ret; } if (ret & BDRV_BLOCK_ZERO) { - sector_num +=3D n; + offset +=3D n * BDRV_SECTOR_BITS; continue; } - ret =3D bdrv_pwrite_zeroes(child, sector_num << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, flags); + ret =3D bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, fl= ags); if (ret < 0) { - error_report("error writing zeroes at sector %" PRId64 ": %s", - sector_num, strerror(-ret)); + error_report("error writing zeroes at offset %" PRId64 ": %s", + offset, strerror(-ret)); return ret; } - sector_num +=3D n; + offset +=3D n * BDRV_SECTOR_SIZE; } } =20 --=20 2.13.6