[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and Blo
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions |
Date: |
Wed, 9 Jun 2021 12:12:04 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
08.06.2021 10:33, Emanuele Giuseppe Esposito wrote:
As done in BlockCopyCallState, categorize BlockCopyTask
and BlockCopyState in IN, State and OUT fields.
This is just to understand which field has to be protected with a lock.
.sleep_state is handled in the series "coroutine: new sleep/wake API"
and thus here left as TODO.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block/block-copy.c | 47 ++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/block/block-copy.c b/block/block-copy.c
index d58051288b..b3533a3003 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -56,25 +56,33 @@ typedef struct BlockCopyCallState {
QLIST_ENTRY(BlockCopyCallState) list;
/* State */
Why previous @list field is not in the state? For sure it's not an IN parameter
and should be protected somehow.
- int ret;
bool finished;
- QemuCoSleep sleep;
- bool cancelled;
+ QemuCoSleep sleep; /* TODO: protect API with a lock */
/* OUT parameters */
+ bool cancelled;
bool error_is_read;
+ int ret;
} BlockCopyCallState;
typedef struct BlockCopyTask {
AioTask task;
+ /*
+ * IN parameters. Initialized in block_copy_task_create()
+ * and never changed.
+ */
BlockCopyState *s;
BlockCopyCallState *call_state;
int64_t offset;
- int64_t bytes;
- BlockCopyMethod method;
- QLIST_ENTRY(BlockCopyTask) list;
+ int64_t bytes; /* only re-set in task_shrink, before running the task */
+ BlockCopyMethod method; /* initialized in block_copy_dirty_clusters() */
hmm. to be precise method is initialized in block_copy_task_create.
And after block_copy_task_create finished, task is in the list and can be read
by parallel block_copy_dirty_clusters(). So, @bytes is part of State, we must
protect it..
method is only read by block_copy_task_entry(), so can be modified without any
protection before running the task.
+
+ /* State */
CoQueue wait_queue; /* coroutines blocked on this task */
+
+ /* To reference all call states from BlockCopyState */
That's a misleading comment.. not all sates but all tasks. I don't think we
need this new comment, just keep @list in State section.
+ QLIST_ENTRY(BlockCopyTask) list;
} BlockCopyTask;
static int64_t task_end(BlockCopyTask *task)
@@ -90,15 +98,25 @@ typedef struct BlockCopyState {
*/
BdrvChild *source;
BdrvChild *target;
- BdrvDirtyBitmap *copy_bitmap;
+
+ /* State */
int64_t in_flight_bytes;
- int64_t cluster_size;
BlockCopyMethod method;
- int64_t max_transfer;
- uint64_t len;
QLIST_HEAD(, BlockCopyTask) tasks; /* All tasks from all block-copy calls
*/
QLIST_HEAD(, BlockCopyCallState) calls;
+ /* State fields that use a thread-safe API */
+ BdrvDirtyBitmap *copy_bitmap;
+ ProgressMeter *progress;
+ SharedResource *mem;
+ RateLimit rate_limit;
+ /*
+ * IN parameters. Initialized in block_copy_state_new()
+ * and never changed.
+ */
+ int64_t cluster_size;
+ int64_t max_transfer;
+ uint64_t len;
BdrvRequestFlags write_flags;
/*
@@ -114,14 +132,11 @@ typedef struct BlockCopyState {
* In this case, block_copy() will query the source’s allocation status,
* skip unallocated regions, clear them in the copy_bitmap, and invoke
* block_copy_reset_unallocated() every time it does.
+ *
+ * This field is set in backup_run() before coroutines are run,
+ * therefore is an IN.
*/
bool skip_unallocated;
-
- ProgressMeter *progress;
-
- SharedResource *mem;
-
- RateLimit rate_limit;
} BlockCopyState;
static BlockCopyTask *find_conflicting_task(BlockCopyState *s,
--
Best regards,
Vladimir
- [PATCH v3 0/5] block-copy: protect block-copy internal structures, Emanuele Giuseppe Esposito, 2021/06/08
- [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Emanuele Giuseppe Esposito, 2021/06/08
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions,
Vladimir Sementsov-Ogievskiy <=
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Emanuele Giuseppe Esposito, 2021/06/10
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Vladimir Sementsov-Ogievskiy, 2021/06/10
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Emanuele Giuseppe Esposito, 2021/06/10
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Vladimir Sementsov-Ogievskiy, 2021/06/10
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Emanuele Giuseppe Esposito, 2021/06/10
- Re: [PATCH v3 2/5] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions, Vladimir Sementsov-Ogievskiy, 2021/06/10
[PATCH v3 3/5] block-copy: move progress_set_remaining in block_copy_task_end, Emanuele Giuseppe Esposito, 2021/06/08
[PATCH v3 4/5] block-copy: add a CoMutex, Emanuele Giuseppe Esposito, 2021/06/08