From patchwork Tue Jun 27 19:24:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9812993 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 5B2C96020A for ; Tue, 27 Jun 2017 19:27:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0402808F for ; Tue, 27 Jun 2017 19:27:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 433B028426; Tue, 27 Jun 2017 19:27:02 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 D27E22808F for ; Tue, 27 Jun 2017 19:27:01 +0000 (UTC) Received: from localhost ([::1]:57818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPw8a-0006G2-UL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Jun 2017 15:27:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPw6y-0005xe-Ei for qemu-devel@nongnu.org; Tue, 27 Jun 2017 15:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPw6x-0006le-JR for qemu-devel@nongnu.org; Tue, 27 Jun 2017 15:25:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46108) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPw6v-0006ka-GH; Tue, 27 Jun 2017 15:25:17 -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 62E1D7F408; Tue, 27 Jun 2017 19:25:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 62E1D7F408 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 62E1D7F408 Received: from red.redhat.com (ovpn-123-78.rdu2.redhat.com [10.10.123.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCEAF17A48; Tue, 27 Jun 2017 19:25:13 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 27 Jun 2017 14:24:44 -0500 Message-Id: <20170627192458.15519-7-eblake@redhat.com> In-Reply-To: <20170627192458.15519-1-eblake@redhat.com> References: <20170627192458.15519-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]); Tue, 27 Jun 2017 19:25:16 +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 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: kwolf@redhat.com, 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 Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf --- 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 6f67d78..c3a7bca 100644 --- a/block/commit.c +++ b/block/commit.c @@ -143,17 +143,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; } @@ -170,10 +169,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 @@ -185,15 +183,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; }