From patchwork Tue Apr 11 22:29:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9676165 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 618B860234 for ; Tue, 11 Apr 2017 22:42:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A32328562 for ; Tue, 11 Apr 2017 22:42:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CF8828589; Tue, 11 Apr 2017 22:42:41 +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 CCCC128562 for ; Tue, 11 Apr 2017 22:42:40 +0000 (UTC) Received: from localhost ([::1]:41392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy4Uh-0006q2-Bd for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Apr 2017 18:42:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy4Ih-0006MA-6D for qemu-devel@nongnu.org; Tue, 11 Apr 2017 18:30:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cy4Ig-0004lP-7f for qemu-devel@nongnu.org; Tue, 11 Apr 2017 18:30:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cy4Ia-0004iK-Su; Tue, 11 Apr 2017 18:30:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECCB3CA00B; Tue, 11 Apr 2017 22:30:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ECCB3CA00B Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ECCB3CA00B Received: from red.redhat.com (ovpn-122-61.rdu2.redhat.com [10.10.122.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id A170E5C465; Tue, 11 Apr 2017 22:30:06 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 11 Apr 2017 17:29:40 -0500 Message-Id: <20170411222945.11741-13-eblake@redhat.com> In-Reply-To: <20170411222945.11741-1-eblake@redhat.com> References: <20170411222945.11741-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 11 Apr 2017 22:30:08 +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 12/17] backup: Switch BackupBlockJob 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 , 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. Continue by converting an internal structure (no semantic change), and all references to tracking progress. Drop a redundant local variable bytes_per_cluster. Signed-off-by: Eric Blake --- block/backup.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/block/backup.c b/block/backup.c index b28df8c..a64a162 100644 --- a/block/backup.c +++ b/block/backup.c @@ -39,7 +39,7 @@ typedef struct BackupBlockJob { BlockdevOnError on_source_error; BlockdevOnError on_target_error; CoRwlock flush_rwlock; - uint64_t sectors_read; + uint64_t bytes_read; unsigned long *done_bitmap; int64_t cluster_size; bool compress; @@ -102,16 +102,15 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, void *bounce_buffer = NULL; int ret = 0; int64_t sectors_per_cluster = cluster_size_sectors(job); - int64_t bytes_per_cluster = sectors_per_cluster * BDRV_SECTOR_SIZE; - int64_t start, end; - int n; + int64_t start, end; /* clusters */ + int n; /* bytes */ qemu_co_rwlock_rdlock(&job->flush_rwlock); start = sector_num / sectors_per_cluster; end = DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); - trace_backup_do_cow_enter(job, start * bytes_per_cluster, + trace_backup_do_cow_enter(job, start * job->cluster_size, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); @@ -120,28 +119,27 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, for (; start < end; start++) { if (test_bit(start, job->done_bitmap)) { - trace_backup_do_cow_skip(job, start * bytes_per_cluster); + trace_backup_do_cow_skip(job, start * job->cluster_size); continue; /* already copied */ } - trace_backup_do_cow_process(job, start * bytes_per_cluster); + trace_backup_do_cow_process(job, start * job->cluster_size); - n = MIN(sectors_per_cluster, - job->common.len / BDRV_SECTOR_SIZE - - start * sectors_per_cluster); + n = MIN(job->cluster_size, + job->common.len - start * job->cluster_size); if (!bounce_buffer) { bounce_buffer = blk_blockalign(blk, job->cluster_size); } iov.iov_base = bounce_buffer; - iov.iov_len = n * BDRV_SECTOR_SIZE; + iov.iov_len = n; qemu_iovec_init_external(&bounce_qiov, &iov, 1); ret = blk_co_preadv(blk, start * job->cluster_size, bounce_qiov.size, &bounce_qiov, is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0); if (ret < 0) { - trace_backup_do_cow_read_fail(job, start * bytes_per_cluster, ret); + trace_backup_do_cow_read_fail(job, start * job->cluster_size, ret); if (error_is_read) { *error_is_read = true; } @@ -157,7 +155,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); } if (ret < 0) { - trace_backup_do_cow_write_fail(job, start * bytes_per_cluster, ret); + trace_backup_do_cow_write_fail(job, start * job->cluster_size, ret); if (error_is_read) { *error_is_read = false; } @@ -169,8 +167,8 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, /* Publish progress, guest I/O counts as progress too. Note that the * offset field is an opaque progress value, it is not a disk offset. */ - job->sectors_read += n; - job->common.offset += n * BDRV_SECTOR_SIZE; + job->bytes_read += n; + job->common.offset += n; } out: @@ -363,9 +361,8 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job) */ if (job->common.speed) { uint64_t delay_ns = ratelimit_calculate_delay(&job->limit, - job->sectors_read * - BDRV_SECTOR_SIZE); - job->sectors_read = 0; + job->bytes_read); + job->bytes_read = 0; block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, delay_ns); } else { block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, 0);