qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: famz@redhat.com, stefanha@redhat.com, jcody@redhat.com,
	mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
	den@openvz.org, eblake@redhat.com
Subject: [Qemu-devel] [PATCH v4 01/11] block/backup: simplify backup_incremental_init_copy_bitmap
Date: Mon, 15 Oct 2018 19:06:23 +0300	[thread overview]
Message-ID: <20181015160633.63130-2-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20181015160633.63130-1-vsementsov@virtuozzo.com>

Simplify backup_incremental_init_copy_bitmap using the function
bdrv_dirty_bitmap_next_dirty_area.

Note: move to job->len instead of bitmap size: it should not matter but
less code.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/backup.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)

diff --git a/block/backup.c b/block/backup.c
index 435414e964..fbe7ce19e1 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -406,43 +406,27 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
 /* init copy_bitmap from sync_bitmap */
 static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
 {
-    BdrvDirtyBitmapIter *dbi;
-    int64_t offset;
-    int64_t end = DIV_ROUND_UP(bdrv_dirty_bitmap_size(job->sync_bitmap),
-                               job->cluster_size);
-
-    dbi = bdrv_dirty_iter_new(job->sync_bitmap);
-    while ((offset = bdrv_dirty_iter_next(dbi)) != -1) {
-        int64_t cluster = offset / job->cluster_size;
-        int64_t next_cluster;
-
-        offset += bdrv_dirty_bitmap_granularity(job->sync_bitmap);
-        if (offset >= bdrv_dirty_bitmap_size(job->sync_bitmap)) {
-            hbitmap_set(job->copy_bitmap, cluster, end - cluster);
-            break;
-        }
+    uint64_t offset = 0;
+    uint64_t bytes = job->len;
 
-        offset = bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset,
-                                             UINT64_MAX);
-        if (offset == -1) {
-            hbitmap_set(job->copy_bitmap, cluster, end - cluster);
-            break;
-        }
+    while (bdrv_dirty_bitmap_next_dirty_area(job->sync_bitmap,
+                                             &offset, &bytes))
+    {
+        uint64_t cluster = offset / job->cluster_size;
+        uint64_t last_cluster = (offset + bytes) / job->cluster_size;
 
-        next_cluster = DIV_ROUND_UP(offset, job->cluster_size);
-        hbitmap_set(job->copy_bitmap, cluster, next_cluster - cluster);
-        if (next_cluster >= end) {
+        hbitmap_set(job->copy_bitmap, cluster, last_cluster - cluster + 1);
+
+        offset = (last_cluster + 1) * job->cluster_size;
+        if (offset >= job->len) {
             break;
         }
-
-        bdrv_set_dirty_iter(dbi, next_cluster * job->cluster_size);
+        bytes = job->len - offset;
     }
 
     /* TODO job_progress_set_remaining() would make more sense */
     job_progress_update(&job->common.job,
         job->len - hbitmap_count(job->copy_bitmap) * job->cluster_size);
-
-    bdrv_dirty_iter_free(dbi);
 }
 
 static int coroutine_fn backup_run(Job *job, Error **errp)
-- 
2.18.0

  reply	other threads:[~2018-10-15 16:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-15 16:06 [Qemu-devel] [PATCH v4 00/11] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` Vladimir Sementsov-Ogievskiy [this message]
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 02/11] block/backup: move to copy_bitmap with granularity Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 03/11] block: allow serialized reads to intersect Vladimir Sementsov-Ogievskiy
2018-11-06 17:57   ` Kevin Wolf
2018-11-07 10:08     ` Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 04/11] block: improve should_update_child Vladimir Sementsov-Ogievskiy
2018-11-06 18:09   ` Kevin Wolf
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 05/11] iotests: handle -f argument correctly for qemu_io_silent Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 06/11] iotests: allow resume_drive by node name Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 07/11] iotests: prepare 055 to graph changes during backup job Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 08/11] block: introduce backup-top filter driver Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 09/11] block: add lock/unlock range functions Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 10/11] block/backup: tiny refactor backup_job_create Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 11/11] block/backup: use backup-top instead of write notifiers Vladimir Sementsov-Ogievskiy
2018-11-06 17:35   ` Kevin Wolf
2018-11-02 16:41 ` [Qemu-devel] ping Re: [PATCH v4 00/11] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2018-11-06 17:21   ` Kevin Wolf
2018-11-06 22:35     ` [Qemu-devel] [Qemu-block] " John Snow
2018-11-07 10:16       ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181015160633.63130-2-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).