From patchwork Thu May 11 02:20:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9720817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 524AD6035D for ; Thu, 11 May 2017 02:24:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BFDB285EB for ; Thu, 11 May 2017 02:24:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50A59285F2; Thu, 11 May 2017 02:24:18 +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=-6.9 required=2.0 tests=BAYES_00,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 DF721285EB for ; Thu, 11 May 2017 02:24:17 +0000 (UTC) Received: from localhost ([::1]:45568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8dm4-0004zd-TB for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 May 2017 22:24:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8dir-0002yx-H8 for qemu-devel@nongnu.org; Wed, 10 May 2017 22:20:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8diq-0005DZ-Bn for qemu-devel@nongnu.org; Wed, 10 May 2017 22:20:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d8din-0005BX-Pr; Wed, 10 May 2017 22:20:54 -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 EC3F176FF; Thu, 11 May 2017 02:20:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EC3F176FF Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EC3F176FF Received: from red.redhat.com (ovpn-120-208.rdu2.redhat.com [10.10.120.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 907137815F; Thu, 11 May 2017 02:20:51 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 10 May 2017 21:20:22 -0500 Message-Id: <20170511022036.32225-7-eblake@redhat.com> In-Reply-To: <20170511022036.32225-1-eblake@redhat.com> References: <20170511022036.32225-1-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.38]); Thu, 11 May 2017 02:20:53 +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 v2 06/20] commit: Switch commit_run() 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: Kevin Wolf , Jeff Cody , jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of committing 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: John Snow --- v2: no change --- block/commit.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/block/commit.c b/block/commit.c index d244c62..b7d3e60 100644 --- a/block/commit.c +++ b/block/commit.c @@ -129,17 +129,16 @@ static void coroutine_fn commit_run(void *opaque) { CommitBlockJob *s = opaque; CommitCompleteData *data; - int64_t sector_num, end; + int64_t offset; uint64_t delay_ns = 0; int ret = 0; - int n = 0; + int n = 0; /* sectors */ void *buf = NULL; int bytes_written = 0; int64_t base_len; ret = s->common.len = blk_getlength(s->top); - if (s->common.len < 0) { goto out; } @@ -156,10 +155,9 @@ static void coroutine_fn commit_run(void *opaque) } } - end = s->common.len >> BDRV_SECTOR_BITS; buf = blk_blockalign(s->top, COMMIT_BUFFER_SIZE); - for (sector_num = 0; sector_num < end; sector_num += n) { + for (offset = 0; offset < s->common.len; offset += n * BDRV_SECTOR_SIZE) { bool copy; /* Note that even when no rate limit is applied we need to yield @@ -171,15 +169,13 @@ static void coroutine_fn commit_run(void *opaque) } /* Copy if allocated above the base */ ret = bdrv_is_allocated_above(blk_bs(s->top), blk_bs(s->base), - sector_num, + offset / BDRV_SECTOR_SIZE, COMMIT_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); copy = (ret == 1); - trace_commit_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, - n * BDRV_SECTOR_SIZE, ret); + trace_commit_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret); if (copy) { - ret = commit_populate(s->top, s->base, - sector_num * BDRV_SECTOR_SIZE, + ret = commit_populate(s->top, s->base, offset, n * BDRV_SECTOR_SIZE, buf); bytes_written += n * BDRV_SECTOR_SIZE; }