From patchwork Thu Jul 13 15:46:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 787849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3x7gGB5DCCz9t1Z for ; Fri, 14 Jul 2017 01:48:34 +1000 (AEST) Received: from localhost ([::1]:60797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVgLw-0004pN-K6 for incoming@patchwork.ozlabs.org; Thu, 13 Jul 2017 11:48:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVgL2-0004fX-Kr for qemu-devel@nongnu.org; Thu, 13 Jul 2017 11:47:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVgL1-0005mC-RW for qemu-devel@nongnu.org; Thu, 13 Jul 2017 11:47:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVgKz-0005i9-7y; Thu, 13 Jul 2017 11:47:33 -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 E0A008123D; Thu, 13 Jul 2017 15:47:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E0A008123D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E0A008123D Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86E3170A03; Thu, 13 Jul 2017 15:47:30 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 10:46:53 -0500 Message-Id: <20170713154711.32374-6-eblake@redhat.com> In-Reply-To: <20170713154711.32374-1-eblake@redhat.com> References: <20170713154711.32374-1-eblake@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.25]); Thu, 13 Jul 2017 15:47:32 +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 v3 05/23] 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, famz@redhat.com, qemu-block@nongnu.org, el13635@mail.ntua.gr, Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- v3: no change v2: rebase to earlier changes --- block/io.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index 13a2f27..37a9714 100644 --- a/block/io.c +++ b/block/io.c @@ -669,38 +669,38 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, */ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) { - int64_t target_sectors, ret, nb_sectors, sector_num = 0; + int64_t target_size, ret, bytes, offset = 0; BlockDriverState *bs = child->bs; - int n; + int n; /* sectors */ - target_sectors = bdrv_nb_sectors(bs); - if (target_sectors < 0) { - return target_sectors; + target_size = bdrv_getlength(bs); + if (target_size < 0) { + return target_size; } for (;;) { - nb_sectors = MIN(target_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); - if (nb_sectors <= 0) { + bytes = MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <= 0) { return 0; } - ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &n, NULL); + ret = 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 += n; + offset += n * BDRV_SECTOR_BITS; continue; } - ret = bdrv_pwrite_zeroes(child, sector_num << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, flags); + ret = bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, flags); 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 += n; + offset += n * BDRV_SECTOR_SIZE; } }