From nobody Mon Feb 9 05:19:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563235409; cv=none; d=zoho.com; s=zohoarc; b=f7VB47Yb/5ypWUG1clZf9gNeOM/Mc3pFSqzWHcpPB8XCt/TnvXmQ/7aaT9fKXxlFzZJbPstsUOcMB320aP0xCZG3fbrJ0szhfq1HDJmAIClP+R3Jd0dCqH3z7lIxIfMFrd0wivsydm6/OQodl7FqowsWvGhziEGb031ndi5CxGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563235409; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=c1LsbU9ekR7yn2xbQ2Zisg6+8j3+hEgs8t8ZBYSI8LA=; b=AlQUllH6p4fp1U5MVXSrmz04AoxLh/UZlbwX7kQ7mnnoCg+oNGDExMbOmci/pf5TJoMto3hRhgRmqwDzHKkT51VVAM2nY18uTAQjyYyFdGxsGSMCc/K3fHzZx7JfZmWOj8d3JMh0zSb8N6Y55yAvUDQCwYcKQCXhDo1N3N7+nfU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563235409259723.375733720844; Mon, 15 Jul 2019 17:03:29 -0700 (PDT) Received: from localhost ([::1]:44470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAwG-0006Pl-4C for importer@patchew.org; Mon, 15 Jul 2019 20:03:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44681) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAuV-0007DN-5B for qemu-devel@nongnu.org; Mon, 15 Jul 2019 20:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnAuT-0007a0-Gd for qemu-devel@nongnu.org; Mon, 15 Jul 2019 20:01:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51574) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnAuQ-0007WE-JF; Mon, 15 Jul 2019 20:01:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D849CC057F30; Tue, 16 Jul 2019 00:01:29 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-130.bos.redhat.com [10.18.17.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0389A6085B; Tue, 16 Jul 2019 00:01:28 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 15 Jul 2019 20:01:14 -0400 Message-Id: <20190716000117.25219-9-jsnow@redhat.com> In-Reply-To: <20190716000117.25219-1-jsnow@redhat.com> References: <20190716000117.25219-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 16 Jul 2019 00:01:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 08/11] block/backup: add backup_is_cluster_allocated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Markus Armbruster , Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Modify the existing bdrv_is_unallocated_range to utilize the pnum return from bdrv_is_allocated; optionally returning a full number of clusters that share the same allocation status. This will be used to carefully toggle bits in the bitmap for sync=3Dtop initialization in the following commits. Signed-off-by: John Snow Reviewed-by: Max Reitz --- block/backup.c | 62 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/block/backup.c b/block/backup.c index c88a70fe10..b407d57954 100644 --- a/block/backup.c +++ b/block/backup.c @@ -185,6 +185,48 @@ static int coroutine_fn backup_cow_with_offload(Backup= BlockJob *job, return nbytes; } =20 +/* + * Check if the cluster starting at offset is allocated or not. + * return via pnum the number of contiguous clusters sharing this allocati= on. + */ +static int backup_is_cluster_allocated(BackupBlockJob *s, int64_t offset, + int64_t *pnum) +{ + BlockDriverState *bs =3D blk_bs(s->common.blk); + int64_t count, total_count =3D 0; + int64_t bytes =3D s->len - offset; + int ret; + + assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); + + while (true) { + ret =3D bdrv_is_allocated(bs, offset, bytes, &count); + if (ret < 0) { + return ret; + } + + total_count +=3D count; + + if (ret || count =3D=3D 0) { + /* + * ret: partial segment(s) are considered allocated. + * otherwise: unallocated tail is treated as an entire segment. + */ + *pnum =3D DIV_ROUND_UP(total_count, s->cluster_size); + return ret; + } + + /* Unallocated segment(s) with uncertain following segment(s) */ + if (total_count >=3D s->cluster_size) { + *pnum =3D total_count / s->cluster_size; + return 0; + } + + offset +=3D count; + bytes -=3D count; + } +} + static int coroutine_fn backup_do_cow(BackupBlockJob *job, int64_t offset, uint64_t bytes, bool *error_is_read, @@ -388,34 +430,18 @@ static bool coroutine_fn yield_and_check(BackupBlockJ= ob *job) return false; } =20 -static bool bdrv_is_unallocated_range(BlockDriverState *bs, - int64_t offset, int64_t bytes) -{ - int64_t end =3D offset + bytes; - - while (offset < end && !bdrv_is_allocated(bs, offset, bytes, &bytes)) { - if (bytes =3D=3D 0) { - return true; - } - offset +=3D bytes; - bytes =3D end - offset; - } - - return offset >=3D end; -} - static int coroutine_fn backup_loop(BackupBlockJob *job) { bool error_is_read; int64_t offset; BdrvDirtyBitmapIter *bdbi; - BlockDriverState *bs =3D blk_bs(job->common.blk); int ret =3D 0; + int64_t dummy; =20 bdbi =3D bdrv_dirty_iter_new(job->copy_bitmap); while ((offset =3D bdrv_dirty_iter_next(bdbi)) !=3D -1) { if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP && - bdrv_is_unallocated_range(bs, offset, job->cluster_size)) + !backup_is_cluster_allocated(job, offset, &dummy)) { bdrv_reset_dirty_bitmap(job->copy_bitmap, offset, job->cluster_size); --=20 2.21.0