[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 02/23] block/block-copy: More explicit call_state
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v4 02/23] block/block-copy: More explicit call_state |
Date: |
Sun, 17 Jan 2021 00:46:44 +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>
Reviewed-by: Max Reitz <mreitz@redhat.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 63398a171c..6ea55f1f9a 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;
@@ -544,15 +552,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
@@ -568,7 +578,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);
@@ -633,15 +643,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
@@ -649,16 +656,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);
}
/*
@@ -675,6 +682,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.29.2
- [PATCH v4 00/23] backup performance: block_status + async, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 01/23] qapi: backup: add perf.use-copy-range parameter, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 02/23] block/block-copy: More explicit call_state,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v4 03/23] block/block-copy: implement block_copy_async, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 06/23] block/block-copy: add ratelimit to block-copy, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 05/23] block/block-copy: add list of all call-states, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 09/23] job: call job_enter from job_pause, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 10/23] qapi: backup: add max-chunk and max-workers to x-perf struct, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 04/23] block/block-copy: add max_chunk and max_workers parameters, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 07/23] block/block-copy: add block_copy_cancel, Vladimir Sementsov-Ogievskiy, 2021/01/16
- [PATCH v4 11/23] iotests: 56: prepare for backup over block-copy, Vladimir Sementsov-Ogievskiy, 2021/01/16