From nobody Mon Feb 9 23:01:10 2026 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@gnu.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@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150695528061823.877697283141742; Mon, 2 Oct 2017 07:41:20 -0700 (PDT) Received: from localhost ([::1]:52639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz1uG-0002rQ-LR for importer@patchew.org; Mon, 02 Oct 2017 10:41:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz1sX-0001YF-HL for qemu-devel@nongnu.org; Mon, 02 Oct 2017 10:39:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dz1sW-000326-Ei for qemu-devel@nongnu.org; Mon, 02 Oct 2017 10:39:29 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:24581 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dz1sW-00031R-21 for qemu-devel@nongnu.org; Mon, 02 Oct 2017 10:39:28 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v92EdJQ7007920; Mon, 2 Oct 2017 17:39:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 2 Oct 2017 17:39:17 +0300 Message-Id: <20171002143919.207741-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20171002143919.207741-1-vsementsov@virtuozzo.com> References: <20171002143919.207741-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 3/5] backup: init copy_bitmap from sync_bitmap for incremental X-BeenThere: qemu-devel@gnu.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, vsementsov@virtuozzo.com, famz@redhat.com, jcody@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.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" We should not copy non-dirty clusters in write notifiers. So, initialize copy_bitmap from sync_bitmap. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/block/backup.c b/block/backup.c index 08efec639f..07f4ae846b 100644 --- a/block/backup.c +++ b/block/backup.c @@ -422,6 +422,43 @@ out: return ret; } =20 +/* init copy_bitmap from sync_bitmap */ +static void backup_incremental_init_copy_bitmap(BackupBlockJob *job) +{ + BdrvDirtyBitmapIter *dbi; + int64_t offset; + int64_t end =3D DIV_ROUND_UP(bdrv_dirty_bitmap_size(job->sync_bitmap), + job->cluster_size); + + dbi =3D bdrv_dirty_iter_new(job->sync_bitmap); + while ((offset =3D bdrv_dirty_iter_next(dbi)) !=3D -1) { + int64_t cluster =3D offset / job->cluster_size; + int64_t next_cluster; + + offset +=3D bdrv_dirty_bitmap_granularity(job->sync_bitmap); + if (offset >=3D bdrv_dirty_bitmap_size(job->sync_bitmap)) { + hbitmap_set(job->copy_bitmap, cluster, end - cluster); + break; + } + + offset =3D bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset); + if (offset =3D=3D -1) { + hbitmap_set(job->copy_bitmap, cluster, end - cluster); + break; + } + + next_cluster =3D DIV_ROUND_UP(offset, job->cluster_size); + hbitmap_set(job->copy_bitmap, cluster, next_cluster - cluster); + if (next_cluster >=3D end) { + break; + } + + bdrv_set_dirty_iter(dbi, next_cluster * job->cluster_size); + } + + bdrv_dirty_iter_free(dbi); +} + static void coroutine_fn backup_run(void *opaque) { BackupBlockJob *job =3D opaque; @@ -435,20 +472,26 @@ static void coroutine_fn backup_run(void *opaque) =20 nb_clusters =3D DIV_ROUND_UP(job->common.len, job->cluster_size); job->copy_bitmap =3D hbitmap_alloc(nb_clusters, 0); - hbitmap_set(job->copy_bitmap, 0, nb_clusters); =20 job->before_write.notify =3D backup_before_write_notify; bdrv_add_before_write_notifier(bs, &job->before_write); =20 if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { + /* Here we set all bits in job->copy_bitmap to allow copying clust= ers + * which are going to be changed (none-mode semantics). It doesn't= mean + * that we want to copy _all_ clusters. + */ + hbitmap_set(job->copy_bitmap, 0, nb_clusters); while (!block_job_is_cancelled(&job->common)) { /* Yield until the job is cancelled. We just let our before_w= rite * notify callback service CoW requests. */ block_job_yield(&job->common); } } else if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_INCREMENTAL) { + backup_incremental_init_copy_bitmap(job); ret =3D backup_run_incremental(job); } else { + hbitmap_set(job->copy_bitmap, 0, nb_clusters); /* Both FULL and TOP SYNC_MODE's require copying.. */ for (offset =3D 0; offset < job->common.len; offset +=3D job->cluster_size) { --=20 2.11.1