From nobody Wed Apr 16 08:03:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499448868427423.86762025522467; Fri, 7 Jul 2017 10:34:28 -0700 (PDT) Received: from localhost ([::1]:57827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX97-00029D-V2 for importer@patchew.org; Fri, 07 Jul 2017 13:34:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlT-0005K7-Dx for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlS-0008CO-2l for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlL-00086F-At; Fri, 07 Jul 2017 13:09:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DE663680F; Fri, 7 Jul 2017 17:09:50 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74E2B61F23; Fri, 7 Jul 2017 17:09:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5DE663680F Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5DE663680F From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:49 +0200 Message-Id: <1499447335-6125-35-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:09:50 +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] [PULL 034/100] 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake 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 Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/block/backup.c b/block/backup.c index 06431ac..4e64710 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 =3D NULL; int ret =3D 0; int64_t sectors_per_cluster =3D cluster_size_sectors(job); - int64_t bytes_per_cluster =3D sectors_per_cluster * BDRV_SECTOR_SIZE; - int64_t start, end; - int n; + int64_t start, end; /* clusters */ + int n; /* bytes */ =20 qemu_co_rwlock_rdlock(&job->flush_rwlock); =20 start =3D sector_num / sectors_per_cluster; end =3D DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); =20 - 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); =20 @@ -120,28 +119,27 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, =20 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 */ } =20 - trace_backup_do_cow_process(job, start * bytes_per_cluster); + trace_backup_do_cow_process(job, start * job->cluster_size); =20 - n =3D MIN(sectors_per_cluster, - job->common.len / BDRV_SECTOR_SIZE - - start * sectors_per_cluster); + n =3D MIN(job->cluster_size, + job->common.len - start * job->cluster_size); =20 if (!bounce_buffer) { bounce_buffer =3D blk_blockalign(blk, job->cluster_size); } iov.iov_base =3D bounce_buffer; - iov.iov_len =3D n * BDRV_SECTOR_SIZE; + iov.iov_len =3D n; qemu_iovec_init_external(&bounce_qiov, &iov, 1); =20 ret =3D 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 =3D true; } @@ -157,7 +155,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, 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 =3D false; } @@ -169,8 +167,8 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, /* Publish progress, guest I/O counts as progress too. Note that = the * offset field is an opaque progress value, it is not a disk offs= et. */ - job->sectors_read +=3D n; - job->common.offset +=3D n * BDRV_SECTOR_SIZE; + job->bytes_read +=3D n; + job->common.offset +=3D n; } =20 out: @@ -363,9 +361,8 @@ static bool coroutine_fn yield_and_check(BackupBlockJob= *job) */ if (job->common.speed) { uint64_t delay_ns =3D ratelimit_calculate_delay(&job->limit, - job->sectors_read * - BDRV_SECTOR_SIZE); - job->sectors_read =3D 0; + job->bytes_read); + job->bytes_read =3D 0; block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, delay_ns); } else { block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, 0); --=20 1.8.3.1