[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/20] block/block-copy: More explicit call_state
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 04/20] block/block-copy: More explicit call_state |
Date: |
Mon, 1 Jun 2020 21:11:02 +0300 |
Refactor common path to use BlockCopyCallState pointer as parameter, to
prepare it for use in asynchronous block-copy (at least, we'll need to
run block-copy in a coroutine, passing the whole parameters as one
pointer).
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/block-copy.c | 51 ++++++++++++++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 13 deletions(-)
diff --git a/block/block-copy.c b/block/block-copy.c
index 43a018d190..75882a094c 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -30,7 +30,15 @@
static coroutine_fn int block_copy_task_entry(AioTask *task);
typedef struct BlockCopyCallState {
+ /* IN parameters */
+ BlockCopyState *s;
+ int64_t offset;
+ int64_t bytes;
+
+ /* State */
bool failed;
+
+ /* OUT parameters */
bool error_is_read;
} BlockCopyCallState;
@@ -541,15 +549,17 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
* Returns 1 if dirty clusters found and successfully copied, 0 if no dirty
* clusters found and -errno on failure.
*/
-static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s,
- int64_t offset, int64_t
bytes,
- bool *error_is_read)
+static int coroutine_fn
+block_copy_dirty_clusters(BlockCopyCallState *call_state)
{
+ BlockCopyState *s = call_state->s;
+ int64_t offset = call_state->offset;
+ int64_t bytes = call_state->bytes;
+
int ret = 0;
bool found_dirty = false;
int64_t end = offset + bytes;
AioTaskPool *aio = NULL;
- BlockCopyCallState call_state = {false, false};
/*
* block_copy() user is responsible for keeping source and target in same
@@ -565,7 +575,7 @@ static int coroutine_fn
block_copy_dirty_clusters(BlockCopyState *s,
BlockCopyTask *task;
int64_t status_bytes;
- task = block_copy_task_create(s, &call_state, offset, bytes);
+ task = block_copy_task_create(s, call_state, offset, bytes);
if (!task) {
/* No more dirty bits in the bitmap */
trace_block_copy_skip_range(s, offset, bytes);
@@ -630,15 +640,12 @@ out:
aio_task_pool_free(aio);
}
- if (error_is_read && ret < 0) {
- *error_is_read = call_state.error_is_read;
- }
return ret < 0 ? ret : found_dirty;
}
/*
- * block_copy
+ * block_copy_common
*
* Copy requested region, accordingly to dirty bitmap.
* Collaborate with parallel block_copy requests: if they succeed it will help
@@ -646,16 +653,16 @@ out:
* it means that some I/O operation failed in context of _this_ block_copy
call,
* not some parallel operation.
*/
-int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
- bool *error_is_read)
+static int coroutine_fn block_copy_common(BlockCopyCallState *call_state)
{
int ret;
do {
- ret = block_copy_dirty_clusters(s, offset, bytes, error_is_read);
+ ret = block_copy_dirty_clusters(call_state);
if (ret == 0) {
- ret = block_copy_wait_one(s, offset, bytes);
+ ret = block_copy_wait_one(call_state->s, call_state->offset,
+ call_state->bytes);
}
/*
@@ -672,6 +679,24 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t
offset, int64_t bytes,
return ret;
}
+int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
+ bool *error_is_read)
+{
+ BlockCopyCallState call_state = {
+ .s = s,
+ .offset = start,
+ .bytes = bytes,
+ };
+
+ int ret = block_copy_common(&call_state);
+
+ if (error_is_read && ret < 0) {
+ *error_is_read = call_state.error_is_read;
+ }
+
+ return ret;
+}
+
BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s)
{
return s->copy_bitmap;
--
2.21.0
- [PATCH v2 00/20] backup performance: block_status + async, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 01/20] block/block-copy: block_copy_dirty_clusters: fix failure check, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 02/20] iotests: 129 don't check backup "busy", Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 04/20] block/block-copy: More explicit call_state,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v2 03/20] qapi: backup: add x-use-copy-range parameter, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 05/20] block/block-copy: implement block_copy_async, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 06/20] block/block-copy: add max_chunk and max_workers parameters, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 07/20] block/block-copy: add ratelimit to block-copy, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 08/20] block/block-copy: add block_copy_cancel, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 09/20] blockjob: add set_speed to BlockJobDriver, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 10/20] job: call job_enter from job_user_pause, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 12/20] iotests: 56: prepare for backup over block-copy, Vladimir Sementsov-Ogievskiy, 2020/06/01
- [PATCH v2 11/20] qapi: backup: add x-max-chunk and x-max-workers parameters, Vladimir Sementsov-Ogievskiy, 2020/06/01