QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, jsnow@redhat.com,
	qemu-stable@nongnu.org, qemu-block@nongnu.org,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PULL 11/36] block/backup: upgrade copy_bitmap to BdrvDirtyBitmap
Date: Fri, 16 Aug 2019 19:12:53 -0400
Message-ID: <20190816231318.8650-12-jsnow@redhat.com> (raw)
In-Reply-To: <20190816231318.8650-1-jsnow@redhat.com>

This simplifies some interface matters; namely the initialization and
(later) merging the manifest back into the sync_bitmap if it was
provided.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190709232550.10724-12-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
 block/backup.c | 84 ++++++++++++++++++++++++++------------------------
 1 file changed, 44 insertions(+), 40 deletions(-)

diff --git a/block/backup.c b/block/backup.c
index d07b838930f..474f8eeae29 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -38,7 +38,10 @@ typedef struct CowRequest {
 typedef struct BackupBlockJob {
     BlockJob common;
     BlockBackend *target;
+
     BdrvDirtyBitmap *sync_bitmap;
+    BdrvDirtyBitmap *copy_bitmap;
+
     MirrorSyncMode sync_mode;
     BitmapSyncMode bitmap_mode;
     BlockdevOnError on_source_error;
@@ -51,7 +54,6 @@ typedef struct BackupBlockJob {
     NotifierWithReturn before_write;
     QLIST_HEAD(, CowRequest) inflight_reqs;
 
-    HBitmap *copy_bitmap;
     bool use_copy_range;
     int64_t copy_range_size;
 
@@ -113,7 +115,7 @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
     int write_flags = job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0;
 
     assert(QEMU_IS_ALIGNED(start, job->cluster_size));
-    hbitmap_reset(job->copy_bitmap, start, job->cluster_size);
+    bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size);
     nbytes = MIN(job->cluster_size, job->len - start);
     if (!*bounce_buffer) {
         *bounce_buffer = blk_blockalign(blk, job->cluster_size);
@@ -146,7 +148,7 @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
 
     return nbytes;
 fail:
-    hbitmap_set(job->copy_bitmap, start, job->cluster_size);
+    bdrv_set_dirty_bitmap(job->copy_bitmap, start, job->cluster_size);
     return ret;
 
 }
@@ -169,12 +171,14 @@ static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job,
     assert(QEMU_IS_ALIGNED(start, job->cluster_size));
     nbytes = MIN(job->copy_range_size, end - start);
     nr_clusters = DIV_ROUND_UP(nbytes, job->cluster_size);
-    hbitmap_reset(job->copy_bitmap, start, job->cluster_size * nr_clusters);
+    bdrv_reset_dirty_bitmap(job->copy_bitmap, start,
+                            job->cluster_size * nr_clusters);
     ret = blk_co_copy_range(blk, start, job->target, start, nbytes,
                             read_flags, write_flags);
     if (ret < 0) {
         trace_backup_do_cow_copy_range_fail(job, start, ret);
-        hbitmap_set(job->copy_bitmap, start, job->cluster_size * nr_clusters);
+        bdrv_set_dirty_bitmap(job->copy_bitmap, start,
+                              job->cluster_size * nr_clusters);
         return ret;
     }
 
@@ -204,13 +208,14 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job,
     while (start < end) {
         int64_t dirty_end;
 
-        if (!hbitmap_get(job->copy_bitmap, start)) {
+        if (!bdrv_dirty_bitmap_get(job->copy_bitmap, start)) {
             trace_backup_do_cow_skip(job, start);
             start += job->cluster_size;
             continue; /* already copied */
         }
 
-        dirty_end = hbitmap_next_zero(job->copy_bitmap, start, (end - start));
+        dirty_end = bdrv_dirty_bitmap_next_zero(job->copy_bitmap, start,
+                                                (end - start));
         if (dirty_end < 0) {
             dirty_end = end;
         }
@@ -307,14 +312,16 @@ static void backup_abort(Job *job)
 static void backup_clean(Job *job)
 {
     BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
+    BlockDriverState *bs = blk_bs(s->common.blk);
+
+    if (s->copy_bitmap) {
+        bdrv_release_dirty_bitmap(bs, s->copy_bitmap);
+        s->copy_bitmap = NULL;
+    }
+
     assert(s->target);
     blk_unref(s->target);
     s->target = NULL;
-
-    if (s->copy_bitmap) {
-        hbitmap_free(s->copy_bitmap);
-        s->copy_bitmap = NULL;
-    }
 }
 
 void backup_do_checkpoint(BlockJob *job, Error **errp)
@@ -329,7 +336,7 @@ void backup_do_checkpoint(BlockJob *job, Error **errp)
         return;
     }
 
-    hbitmap_set(backup_job->copy_bitmap, 0, backup_job->len);
+    bdrv_set_dirty_bitmap(backup_job->copy_bitmap, 0, backup_job->len);
 }
 
 static void backup_drain(BlockJob *job)
@@ -398,59 +405,52 @@ static bool bdrv_is_unallocated_range(BlockDriverState *bs,
 
 static int coroutine_fn backup_loop(BackupBlockJob *job)
 {
-    int ret;
     bool error_is_read;
     int64_t offset;
-    HBitmapIter hbi;
+    BdrvDirtyBitmapIter *bdbi;
     BlockDriverState *bs = blk_bs(job->common.blk);
+    int ret = 0;
 
-    hbitmap_iter_init(&hbi, job->copy_bitmap, 0);
-    while ((offset = hbitmap_iter_next(&hbi)) != -1) {
+    bdbi = bdrv_dirty_iter_new(job->copy_bitmap);
+    while ((offset = bdrv_dirty_iter_next(bdbi)) != -1) {
         if (job->sync_mode == MIRROR_SYNC_MODE_TOP &&
             bdrv_is_unallocated_range(bs, offset, job->cluster_size))
         {
-            hbitmap_reset(job->copy_bitmap, offset, job->cluster_size);
+            bdrv_reset_dirty_bitmap(job->copy_bitmap, offset,
+                                    job->cluster_size);
             continue;
         }
 
         do {
             if (yield_and_check(job)) {
-                return 0;
+                goto out;
             }
             ret = backup_do_cow(job, offset,
                                 job->cluster_size, &error_is_read, false);
             if (ret < 0 && backup_error_action(job, error_is_read, -ret) ==
                            BLOCK_ERROR_ACTION_REPORT)
             {
-                return ret;
+                goto out;
             }
         } while (ret < 0);
     }
 
-    return 0;
+ out:
+    bdrv_dirty_iter_free(bdbi);
+    return ret;
 }
 
 /* init copy_bitmap from sync_bitmap */
 static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
 {
-    uint64_t offset = 0;
-    uint64_t bytes = job->len;
-
-    while (bdrv_dirty_bitmap_next_dirty_area(job->sync_bitmap,
-                                             &offset, &bytes))
-    {
-        hbitmap_set(job->copy_bitmap, offset, bytes);
-
-        offset += bytes;
-        if (offset >= job->len) {
-            break;
-        }
-        bytes = job->len - offset;
-    }
+    bool ret = bdrv_dirty_bitmap_merge_internal(job->copy_bitmap,
+                                                job->sync_bitmap,
+                                                NULL, true);
+    assert(ret);
 
     /* TODO job_progress_set_remaining() would make more sense */
     job_progress_update(&job->common.job,
-        job->len - hbitmap_count(job->copy_bitmap));
+                        job->len - bdrv_get_dirty_count(job->copy_bitmap));
 }
 
 static int coroutine_fn backup_run(Job *job, Error **errp)
@@ -467,7 +467,7 @@ static int coroutine_fn backup_run(Job *job, Error **errp)
     if (s->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
         backup_incremental_init_copy_bitmap(s);
     } else {
-        hbitmap_set(s->copy_bitmap, 0, s->len);
+        bdrv_set_dirty_bitmap(s->copy_bitmap, 0, s->len);
     }
 
     s->before_write.notify = backup_before_write_notify;
@@ -560,7 +560,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
     BackupBlockJob *job = NULL;
     int ret;
     int64_t cluster_size;
-    HBitmap *copy_bitmap = NULL;
+    BdrvDirtyBitmap *copy_bitmap = NULL;
 
     assert(bs);
     assert(target);
@@ -630,7 +630,11 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
         goto error;
     }
 
-    copy_bitmap = hbitmap_alloc(len, ctz32(cluster_size));
+    copy_bitmap = bdrv_create_dirty_bitmap(bs, cluster_size, NULL, errp);
+    if (!copy_bitmap) {
+        goto error;
+    }
+    bdrv_disable_dirty_bitmap(copy_bitmap);
 
     /* job->len is fixed, so we can't allow resize */
     job = block_job_create(job_id, &backup_job_driver, txn, bs,
@@ -682,7 +686,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
  error:
     if (copy_bitmap) {
         assert(!job || !job->copy_bitmap);
-        hbitmap_free(copy_bitmap);
+        bdrv_release_dirty_bitmap(bs, copy_bitmap);
     }
     if (sync_bitmap) {
         bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);
-- 
2.21.0



  parent reply index

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 23:12 [Qemu-devel] [PULL 00/36] Bitmaps patches John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 01/36] qapi/block-core: Introduce BackupCommon John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 02/36] drive-backup: create do_backup_common John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 03/36] blockdev-backup: utilize do_backup_common John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 04/36] qapi: add BitmapSyncMode enum John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 05/36] block/backup: Add mirror sync mode 'bitmap' John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 06/36] block/backup: add 'never' policy to bitmap sync mode John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 07/36] hbitmap: Fix merge when b is empty, and result is not an alias of a John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 08/36] hbitmap: enable merging across granularities John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 09/36] block/dirty-bitmap: add bdrv_dirty_bitmap_merge_internal John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 10/36] block/dirty-bitmap: add bdrv_dirty_bitmap_get John Snow
2019-08-16 23:12 ` John Snow [this message]
2019-08-16 23:12 ` [Qemu-devel] [PULL 12/36] block/backup: add 'always' bitmap sync policy John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 13/36] iotests: add testing shim for script-style python tests John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 14/36] iotests: teach run_job to cancel pending jobs John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 15/36] iotests: teach FilePath to produce multiple paths John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 16/36] iotests: Add virtio-scsi device helper John Snow
2019-08-16 23:12 ` [Qemu-devel] [PULL 17/36] iotests: add test 257 for bitmap-mode backups John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 18/36] block/backup: loosen restriction on readonly bitmaps John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 19/36] blockdev: reduce aio_context locked sections in bitmap add/remove John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 20/36] qapi: implement block-dirty-bitmap-remove transaction action John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 21/36] iotests: test bitmap moving inside 254 John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 22/36] iotests/257: add Pattern class John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 23/36] iotests/257: add EmulatedBitmap class John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 24/36] iotests/257: Refactor backup helpers John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 25/36] block/backup: hoist bitmap check into QMP interface John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 26/36] iotests/257: test API failures John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 27/36] block/backup: improve sync=bitmap work estimates John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 28/36] block/backup: centralize copy_bitmap initialization John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 29/36] block/backup: add backup_is_cluster_allocated John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 30/36] block/backup: teach TOP to never copy unallocated regions John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 31/36] block/backup: support bitmap sync modes for non-bitmap backups John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 32/36] iotests/257: test traditional sync modes John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 33/36] qapi: add dirty-bitmaps to query-named-block-nodes result John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 34/36] block/backup: deal with zero detection John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 35/36] block/backup: refactor write_flags John Snow
2019-08-16 23:13 ` [Qemu-devel] [PULL 36/36] tests/test-hbitmap: test next_zero and _next_dirty_area after truncate John Snow
2019-08-19 11:32 ` [Qemu-devel] [PULL 00/36] Bitmaps patches Peter Maydell

Reply instructions:

You may reply publically 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=20190816231318.8650-12-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /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

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git