Skip to content

Commit

Permalink
block/block-copy: add max_chunk and max_workers parameters
Browse files Browse the repository at this point in the history
They will be used for backup.

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Max Reitz <[email protected]>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and XanClic committed Jan 26, 2021
1 parent de4641b commit 26be9d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions block/block-copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ typedef struct BlockCopyCallState {
BlockCopyState *s;
int64_t offset;
int64_t bytes;
int max_workers;
int64_t max_chunk;
BlockCopyAsyncCallbackFunc cb;
void *cb_opaque;

Expand Down Expand Up @@ -148,10 +150,11 @@ static BlockCopyTask *block_copy_task_create(BlockCopyState *s,
int64_t offset, int64_t bytes)
{
BlockCopyTask *task;
int64_t max_chunk = MIN_NON_ZERO(s->copy_size, call_state->max_chunk);

if (!bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap,
offset, offset + bytes,
s->copy_size, &offset, &bytes))
max_chunk, &offset, &bytes))
{
return NULL;
}
Expand Down Expand Up @@ -623,7 +626,7 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
bytes = end - offset;

if (!aio && bytes) {
aio = aio_task_pool_new(BLOCK_COPY_MAX_WORKERS);
aio = aio_task_pool_new(call_state->max_workers);
}

ret = block_copy_task_run(aio, task);
Expand Down Expand Up @@ -701,6 +704,7 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
.s = s,
.offset = start,
.bytes = bytes,
.max_workers = BLOCK_COPY_MAX_WORKERS,
};

int ret = block_copy_common(&call_state);
Expand All @@ -719,6 +723,7 @@ static void coroutine_fn block_copy_async_co_entry(void *opaque)

BlockCopyCallState *block_copy_async(BlockCopyState *s,
int64_t offset, int64_t bytes,
int max_workers, int64_t max_chunk,
BlockCopyAsyncCallbackFunc cb,
void *cb_opaque)
{
Expand All @@ -728,6 +733,8 @@ BlockCopyCallState *block_copy_async(BlockCopyState *s,
.s = s,
.offset = offset,
.bytes = bytes,
.max_workers = max_workers,
.max_chunk = max_chunk,
.cb = cb,
.cb_opaque = cb_opaque,

Expand Down
6 changes: 6 additions & 0 deletions include/block/block-copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
*
* Caller is responsible to call block_copy_call_free() to free
* BlockCopyCallState object.
*
* @max_workers means maximum of parallel coroutines to execute sub-requests,
* must be > 0.
*
* @max_chunk means maximum length for one IO operation. Zero means unlimited.
*/
BlockCopyCallState *block_copy_async(BlockCopyState *s,
int64_t offset, int64_t bytes,
int max_workers, int64_t max_chunk,
BlockCopyAsyncCallbackFunc cb,
void *cb_opaque);

Expand Down

0 comments on commit 26be9d6

Please sign in to comment.