Commit 0f4b02b7 authored by Vladimir Sementsov-Ogievskiy's avatar Vladimir Sementsov-Ogievskiy Committed by Max Reitz
Browse files

block/block-copy: split block_copy_set_callbacks function



Split block_copy_set_callbacks out of block_copy_state_new. It's needed
for further commit: block-copy will use BdrvChildren of backup-top
filter, so it will be created from backup-top filter creation function.
But callbacks will still belong to backup job and will be set in
separate.

Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-4-vsementsov@virtuozzo.com
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent 843670f3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -478,8 +478,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
    job->bitmap_mode = bitmap_mode;

    job->bcs = block_copy_state_new(bs, target, cluster_size, write_flags,
                                    backup_progress_bytes_callback,
                                    backup_progress_reset_callback, job, errp);
                                    errp);
    if (!job->bcs) {
        goto error;
    }
@@ -487,6 +486,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
    job->cluster_size = cluster_size;
    job->len = len;

    block_copy_set_callbacks(job->bcs, backup_progress_bytes_callback,
                             backup_progress_reset_callback, job);

    /* Required permissions are already taken by block-copy-state target */
    block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
                       &error_abort);
+15 −9
Original line number Diff line number Diff line
@@ -66,12 +66,10 @@ void block_copy_state_free(BlockCopyState *s)
    g_free(s);
}

BlockCopyState *block_copy_state_new(
        BlockDriverState *source, BlockDriverState *target,
        int64_t cluster_size, BdrvRequestFlags write_flags,
        ProgressBytesCallbackFunc progress_bytes_callback,
        ProgressResetCallbackFunc progress_reset_callback,
        void *progress_opaque, Error **errp)
BlockCopyState *block_copy_state_new(BlockDriverState *source,
                                     BlockDriverState *target,
                                     int64_t cluster_size,
                                     BdrvRequestFlags write_flags, Error **errp)
{
    BlockCopyState *s;
    int ret;
@@ -95,9 +93,6 @@ BlockCopyState *block_copy_state_new(
        .cluster_size = cluster_size,
        .len = bdrv_dirty_bitmap_size(copy_bitmap),
        .write_flags = write_flags,
        .progress_bytes_callback = progress_bytes_callback,
        .progress_reset_callback = progress_reset_callback,
        .progress_opaque = progress_opaque,
    };

    s->copy_range_size = QEMU_ALIGN_DOWN(MIN(blk_get_max_transfer(s->source),
@@ -144,6 +139,17 @@ fail:
    return NULL;
}

void block_copy_set_callbacks(
        BlockCopyState *s,
        ProgressBytesCallbackFunc progress_bytes_callback,
        ProgressResetCallbackFunc progress_reset_callback,
        void *progress_opaque)
{
    s->progress_bytes_callback = progress_bytes_callback;
    s->progress_reset_callback = progress_reset_callback;
    s->progress_opaque = progress_opaque;
}

/*
 * Copy range to target with a bounce buffer and return the bytes copied. If
 * error occurred, return a negative error number
+9 −4
Original line number Diff line number Diff line
@@ -66,12 +66,17 @@ typedef struct BlockCopyState {
    void *progress_opaque;
} BlockCopyState;

BlockCopyState *block_copy_state_new(
        BlockDriverState *source, BlockDriverState *target,
        int64_t cluster_size, BdrvRequestFlags write_flags,
BlockCopyState *block_copy_state_new(BlockDriverState *source,
                                     BlockDriverState *target,
                                     int64_t cluster_size,
                                     BdrvRequestFlags write_flags,
                                     Error **errp);

void block_copy_set_callbacks(
        BlockCopyState *s,
        ProgressBytesCallbackFunc progress_bytes_callback,
        ProgressResetCallbackFunc progress_reset_callback,
        void *progress_opaque, Error **errp);
        void *progress_opaque);

void block_copy_state_free(BlockCopyState *s);