mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
block/block-copy: block_copy(): add timeout_ns parameter
Add possibility to limit block_copy() call in time. To be used in the next commit. As timed-out block_copy() call will continue in background anyway (we can't immediately cancel IO operation), it's important also give user a possibility to pass a callback, to do some additional actions on block-copy call finish. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
This commit is contained in:
parent
e1878eb5f0
commit
15df6e6987
3 changed files with 31 additions and 10 deletions
|
@ -883,23 +883,42 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
|
||||
bool ignore_ratelimit)
|
||||
static void coroutine_fn block_copy_async_co_entry(void *opaque)
|
||||
{
|
||||
BlockCopyCallState call_state = {
|
||||
block_copy_common(opaque);
|
||||
}
|
||||
|
||||
int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
|
||||
bool ignore_ratelimit, uint64_t timeout_ns,
|
||||
BlockCopyAsyncCallbackFunc cb,
|
||||
void *cb_opaque)
|
||||
{
|
||||
int ret;
|
||||
BlockCopyCallState *call_state = g_new(BlockCopyCallState, 1);
|
||||
|
||||
*call_state = (BlockCopyCallState) {
|
||||
.s = s,
|
||||
.offset = start,
|
||||
.bytes = bytes,
|
||||
.ignore_ratelimit = ignore_ratelimit,
|
||||
.max_workers = BLOCK_COPY_MAX_WORKERS,
|
||||
.cb = cb,
|
||||
.cb_opaque = cb_opaque,
|
||||
};
|
||||
|
||||
return block_copy_common(&call_state);
|
||||
}
|
||||
ret = qemu_co_timeout(block_copy_async_co_entry, call_state, timeout_ns,
|
||||
g_free);
|
||||
if (ret < 0) {
|
||||
assert(ret == -ETIMEDOUT);
|
||||
block_copy_call_cancel(call_state);
|
||||
/* call_state will be freed by running coroutine. */
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void coroutine_fn block_copy_async_co_entry(void *opaque)
|
||||
{
|
||||
block_copy_common(opaque);
|
||||
ret = call_state->ret;
|
||||
g_free(call_state);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BlockCopyCallState *block_copy_async(BlockCopyState *s,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue