From patchwork Thu May 11 02:20:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9720821 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 45CAB6035D for ; Thu, 11 May 2017 02:25:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50432285F0 for ; Thu, 11 May 2017 02:25:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 452BC285F3; Thu, 11 May 2017 02:25:07 +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 D725F285F0 for ; Thu, 11 May 2017 02:25:06 +0000 (UTC) Received: from localhost ([::1]:45574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8dmr-0005iV-RH for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 May 2017 22:25:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8dio-0002w9-Li for qemu-devel@nongnu.org; Wed, 10 May 2017 22:20:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8din-0005BH-2H for qemu-devel@nongnu.org; Wed, 10 May 2017 22:20:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d8dij-00056p-CS; Wed, 10 May 2017 22:20:49 -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 4628C13A60; Thu, 11 May 2017 02:20:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4628C13A60 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4628C13A60 Received: from red.redhat.com (ovpn-120-208.rdu2.redhat.com [10.10.120.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id E86F7179DA; Thu, 11 May 2017 02:20:46 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 10 May 2017 21:20:20 -0500 Message-Id: <20170511022036.32225-5-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.29]); Thu, 11 May 2017 02:20:48 +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 04/20] stream: Switch stream_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 streaming 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/stream.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/block/stream.c b/block/stream.c index 5acef6d..3ed4fef 100644 --- a/block/stream.c +++ b/block/stream.c @@ -108,12 +108,11 @@ static void coroutine_fn stream_run(void *opaque) BlockBackend *blk = s->common.blk; BlockDriverState *bs = blk_bs(blk); BlockDriverState *base = s->base; - int64_t sector_num = 0; - int64_t end = -1; + int64_t offset = 0; uint64_t delay_ns = 0; int error = 0; int ret = 0; - int n = 0; + int n = 0; /* sectors */ void *buf; if (!bs->backing) { @@ -126,7 +125,6 @@ static void coroutine_fn stream_run(void *opaque) goto out; } - end = s->common.len >> BDRV_SECTOR_BITS; buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE); /* Turn on copy-on-read for the whole block device so that guest read @@ -138,7 +136,7 @@ static void coroutine_fn stream_run(void *opaque) bdrv_enable_copy_on_read(bs); } - for (sector_num = 0; sector_num < end; sector_num += n) { + for ( ; offset < s->common.len; offset += n * BDRV_SECTOR_SIZE) { bool copy; /* Note that even when no rate limit is applied we need to yield @@ -151,28 +149,26 @@ static void coroutine_fn stream_run(void *opaque) copy = false; - ret = bdrv_is_allocated(bs, sector_num, + ret = bdrv_is_allocated(bs, offset / BDRV_SECTOR_SIZE, STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); if (ret == 1) { /* Allocated in the top, no need to copy. */ } else if (ret >= 0) { /* Copy if allocated in the intermediate images. Limit to the - * known-unallocated area [sector_num, sector_num+n). */ + * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE). */ ret = bdrv_is_allocated_above(backing_bs(bs), base, - sector_num, n, &n); + offset / BDRV_SECTOR_SIZE, n, &n); /* Finish early if end of backing file has been reached */ if (ret == 0 && n == 0) { - n = end - sector_num; + n = (s->common.len - offset) / BDRV_SECTOR_SIZE; } copy = (ret == 1); } - trace_stream_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, - n * BDRV_SECTOR_SIZE, ret); + trace_stream_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret); if (copy) { - ret = stream_populate(blk, sector_num * BDRV_SECTOR_SIZE, - n * BDRV_SECTOR_SIZE, buf); + ret = stream_populate(blk, offset, n * BDRV_SECTOR_SIZE, buf); } if (ret < 0) { BlockErrorAction action = @@ -211,7 +207,7 @@ out: /* Modify backing chain and close BDSes in main loop */ data = g_malloc(sizeof(*data)); data->ret = ret; - data->reached_end = sector_num == end; + data->reached_end = offset == s->common.len; block_job_defer_to_main_loop(&s->common, stream_complete, data); }