mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-16 01:03:31 +00:00
block/backup: simplify backup_incremental_init_copy_bitmap
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> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-id: 20190429090842.57910-2-vsementsov@virtuozzo.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
8ac0f15f33
commit
c2da3413c0
|
@ -394,43 +394,27 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
|
||||||
/* init copy_bitmap from sync_bitmap */
|
/* init copy_bitmap from sync_bitmap */
|
||||||
static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
|
static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
|
||||||
{
|
{
|
||||||
BdrvDirtyBitmapIter *dbi;
|
uint64_t offset = 0;
|
||||||
int64_t offset;
|
uint64_t bytes = job->len;
|
||||||
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 (bdrv_dirty_bitmap_next_dirty_area(job->sync_bitmap,
|
||||||
while ((offset = bdrv_dirty_iter_next(dbi)) != -1) {
|
&offset, &bytes))
|
||||||
int64_t cluster = offset / job->cluster_size;
|
{
|
||||||
int64_t next_cluster;
|
uint64_t cluster = offset / job->cluster_size;
|
||||||
|
uint64_t end_cluster = DIV_ROUND_UP(offset + bytes, job->cluster_size);
|
||||||
|
|
||||||
offset += bdrv_dirty_bitmap_granularity(job->sync_bitmap);
|
hbitmap_set(job->copy_bitmap, cluster, end_cluster - cluster);
|
||||||
if (offset >= bdrv_dirty_bitmap_size(job->sync_bitmap)) {
|
|
||||||
hbitmap_set(job->copy_bitmap, cluster, end - cluster);
|
offset = end_cluster * job->cluster_size;
|
||||||
|
if (offset >= job->len) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
bytes = job->len - offset;
|
||||||
offset = bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset,
|
|
||||||
UINT64_MAX);
|
|
||||||
if (offset == -1) {
|
|
||||||
hbitmap_set(job->copy_bitmap, cluster, end - cluster);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_cluster = DIV_ROUND_UP(offset, job->cluster_size);
|
|
||||||
hbitmap_set(job->copy_bitmap, cluster, next_cluster - cluster);
|
|
||||||
if (next_cluster >= end) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdrv_set_dirty_iter(dbi, next_cluster * job->cluster_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO job_progress_set_remaining() would make more sense */
|
/* TODO job_progress_set_remaining() would make more sense */
|
||||||
job_progress_update(&job->common.job,
|
job_progress_update(&job->common.job,
|
||||||
job->len - hbitmap_count(job->copy_bitmap) * job->cluster_size);
|
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)
|
static int coroutine_fn backup_run(Job *job, Error **errp)
|
||||||
|
|
Loading…
Reference in a new issue