[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/7] block/block-copy: block_copy(): add timeout_ns parameter
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 5/7] block/block-copy: block_copy(): add timeout_ns parameter |
Date: |
Fri, 1 Apr 2022 12:19:18 +0300 |
Add possibility to limit block_copy() call in time. To be used in the
next commit.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
---
block/block-copy.c | 26 +++++++++++++++++++-------
block/copy-before-write.c | 2 +-
include/block/block-copy.h | 2 +-
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/block/block-copy.c b/block/block-copy.c
index ec46775ea5..b47cb188dd 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -883,10 +883,18 @@ static int coroutine_fn
block_copy_common(BlockCopyCallState *call_state)
return ret;
}
+static void coroutine_fn block_copy_async_co_entry(void *opaque)
+{
+ block_copy_common(opaque);
+}
+
int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
- bool ignore_ratelimit)
+ bool ignore_ratelimit, uint64_t timeout_ns)
{
- BlockCopyCallState call_state = {
+ int ret;
+ BlockCopyCallState *call_state = g_new(BlockCopyCallState, 1);
+
+ *call_state = (BlockCopyCallState) {
.s = s,
.offset = start,
.bytes = bytes,
@@ -894,12 +902,16 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t
start, int64_t bytes,
.max_workers = BLOCK_COPY_MAX_WORKERS,
};
- return block_copy_common(&call_state);
-}
+ ret = qemu_co_timeout(block_copy_async_co_entry, call_state, timeout_ns,
+ g_free);
+ if (ret < 0) {
+ /* Timeout. 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;
+
+ return ret;
}
BlockCopyCallState *block_copy_async(BlockCopyState *s,
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 0614c3d08b..7ef3f9f4c1 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -107,7 +107,7 @@ static coroutine_fn int
cbw_do_copy_before_write(BlockDriverState *bs,
off = QEMU_ALIGN_DOWN(offset, cluster_size);
end = QEMU_ALIGN_UP(offset + bytes, cluster_size);
- ret = block_copy(s->bcs, off, end - off, true);
+ ret = block_copy(s->bcs, off, end - off, true, 0);
if (ret < 0 && s->on_cbw_error == ON_CBW_ERROR_BREAK_GUEST_WRITE) {
return ret;
}
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
index 68bbd344b2..1c9616cdee 100644
--- a/include/block/block-copy.h
+++ b/include/block/block-copy.h
@@ -40,7 +40,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
int64_t offset, int64_t *count);
int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
- bool ignore_ratelimit);
+ bool ignore_ratelimit, uint64_t timeout_ns);
/*
* Run block-copy in a coroutine, create corresponding BlockCopyCallState
--
2.35.1
[PATCH v2 1/7] block/copy-before-write: refactor option parsing, Vladimir Sementsov-Ogievskiy, 2022/04/01
[PATCH v2 4/7] util: add qemu-co-timeout, Vladimir Sementsov-Ogievskiy, 2022/04/01