[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 09/21] block/backup: simplify backup_incremental_init
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 09/21] block/backup: simplify backup_incremental_init_copy_bitmap |
Date: |
Tue, 28 May 2019 21:28:35 +0200 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
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 <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/backup.c | 40 ++++++++++++----------------------------
1 file changed, 12 insertions(+), 28 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 916817d8b1..db83b09a0b 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -394,43 +394,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 end_cluster = DIV_ROUND_UP(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, end_cluster - cluster);
+
+ offset = end_cluster * 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.21.0
- [Qemu-block] [PULL 03/21] qcow2-threads: use thread_pool_submit_co, (continued)
- [Qemu-block] [PULL 03/21] qcow2-threads: use thread_pool_submit_co, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 05/21] qcow2-threads: split out generic path, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 02/21] qcow2: add separate file for threaded data processing functions, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 13/21] block/backup: refactor: split out backup_calculate_cluster_size, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 16/21] qemu-img: rebase: Reuse parent BlockDriverState, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 07/21] qcow2: bdrv_co_pwritev: move encryption code out of the lock, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 06/21] qcow2: qcow2_co_preadv: improve locking, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 14/21] block: Use bdrv_unref_child() for all children in bdrv_close(), Max Reitz, 2019/05/28
- [Qemu-block] [PULL 10/21] block/backup: move to copy_bitmap with granularity, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 15/21] block: Make bdrv_root_attach_child() unref child_bs on failure, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 09/21] block/backup: simplify backup_incremental_init_copy_bitmap,
Max Reitz <=
- [Qemu-block] [PULL 08/21] qcow2: do encryption in threads, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 21/21] blockdev: loosen restrictions on drive-backup source node, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 18/21] qemu-img: rebase: Reuse in-chain BlockDriverState, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 17/21] qemu-img: rebase: Reduce reads on in-chain rebase, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 11/21] block/backup: refactor and tolerate unallocated cluster skipping, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 20/21] qcow2-bitmap: initialize bitmap directory alignment, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 12/21] block/backup: unify different modes code path, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 19/21] qcow2: skip writing zero buffers to empty COW areas, Max Reitz, 2019/05/28
- Re: [Qemu-block] [PULL 00/21] Block patches, Peter Maydell, 2019/05/30