From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>
Subject: Re: [PATCH v4 3/6] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions
Date: Mon, 21 Jun 2021 09:59:42 +0200 [thread overview]
Message-ID: <6e031269-3ecb-f2f2-9833-eef4073cf5e0@redhat.com> (raw)
In-Reply-To: <3ac5e749-2a8b-e2d2-f1a2-04452b4277a0@virtuozzo.com>
On 19/06/2021 17:23, Vladimir Sementsov-Ogievskiy wrote:
> 14.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 | 49 +++++++++++++++++++++++++++++-----------------
>> 1 file changed, 31 insertions(+), 18 deletions(-)
>>
>> diff --git a/block/block-copy.c b/block/block-copy.c
>> index 3f26be8ddc..5ff7764e87 100644
>> --- a/block/block-copy.c
>> +++ b/block/block-copy.c
>> @@ -52,29 +52,35 @@ typedef struct BlockCopyCallState {
>> /* Coroutine where async block-copy is running */
>> Coroutine *co;
>> - /* To reference all call states from BlockCopyState */
>> - QLIST_ENTRY(BlockCopyCallState) list;
>> -
>> /* State */
>> - int ret;
>> bool finished;
>> - QemuCoSleep sleep;
>> - bool cancelled;
>> + QemuCoSleep sleep; /* TODO: protect API with a lock */
>> +
>> + /* To reference all call states from BlockCopyState */
>> + QLIST_ENTRY(BlockCopyCallState) list;
>> /* 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.
>> + */
>
> That's just not true for method field :(
You're right, because it is modified later in the while loop of
block_copy_dirty_clusters, but the task is already in the list.
Will move it to state field.
>
>> BlockCopyState *s;
>> BlockCopyCallState *call_state;
>> int64_t offset;
>> - int64_t bytes;
>> BlockCopyMethod method;
>> - QLIST_ENTRY(BlockCopyTask) list;
>> +
>> + /* State */
>> CoQueue wait_queue; /* coroutines blocked on this task */
>> + int64_t bytes;
>> + QLIST_ENTRY(BlockCopyTask) list;
>> } BlockCopyTask;
>> static int64_t task_end(BlockCopyTask *task)
>> @@ -90,15 +96,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 +130,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.
>
> That's not true: it is modified from backup_run, when block-copy already
> initialized, and block_copy() calls may be done from backup-top filter.
>
Ok, I am not very familiar with the backup code, so I did not see it.
This means we need to protect this field too.
At this point, I think we can increase the granularity of the lock in
block_copy_dirty_clusters:
instead of having in each while loop
block_copy_task_create(); // locks and releases internally
block_copy_block_status(); // no lock used, but uses skip_unallocated so
it will need one
if()
block_copy_task_shrink(); // locks and releases internally
if(s->skip_unallocated) // will need lock
block_copy_task_end(); // locks and releases internally
[..]
if()
task->method = COPY_WRITE_ZEROS; // needs lock
[..]
we can just lock the while section and eventually create _locked()
version of task_end and similar functions that are also used in
non-locked code blocks.
Emanuele
>> */
>> bool skip_unallocated;
>> -
>> - ProgressMeter *progress;
>> -
>> - SharedResource *mem;
>> -
>> - RateLimit rate_limit;
>> } BlockCopyState;
>> static BlockCopyTask *find_conflicting_task(BlockCopyState *s,
>>
>
>
next prev parent reply other threads:[~2021-06-21 8:01 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-14 7:33 [PATCH v4 0/6] block-copy: protect block-copy internal structures Emanuele Giuseppe Esposito
2021-06-14 7:33 ` [PATCH v4 1/6] block-copy: small refactor in block_copy_task_entry and block_copy_common Emanuele Giuseppe Esposito
2021-06-19 14:33 ` Vladimir Sementsov-Ogievskiy
2021-06-14 7:33 ` [PATCH v4 2/6] block-copy: streamline choice of copy_range vs. read/write Emanuele Giuseppe Esposito
2021-06-19 15:05 ` Vladimir Sementsov-Ogievskiy
2021-06-19 18:23 ` Vladimir Sementsov-Ogievskiy
2021-06-14 7:33 ` [PATCH v4 3/6] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions Emanuele Giuseppe Esposito
2021-06-19 15:23 ` Vladimir Sementsov-Ogievskiy
2021-06-19 18:31 ` Vladimir Sementsov-Ogievskiy
2021-06-21 8:13 ` Emanuele Giuseppe Esposito
2021-06-22 9:20 ` Vladimir Sementsov-Ogievskiy
2021-06-21 7:59 ` Emanuele Giuseppe Esposito [this message]
2021-06-22 9:16 ` Vladimir Sementsov-Ogievskiy
2021-06-19 17:27 ` Vladimir Sementsov-Ogievskiy
2021-06-21 8:21 ` Emanuele Giuseppe Esposito
2021-06-19 18:53 ` Vladimir Sementsov-Ogievskiy
2021-06-21 8:28 ` Emanuele Giuseppe Esposito
2021-06-14 7:33 ` [PATCH v4 4/6] block-copy: move progress_set_remaining in block_copy_task_end Emanuele Giuseppe Esposito
2021-06-14 7:33 ` [PATCH v4 5/6] block-copy: add a CoMutex Emanuele Giuseppe Esposito
2021-06-19 19:34 ` Vladimir Sementsov-Ogievskiy
2021-06-14 7:33 ` [PATCH v4 6/6] block-copy: atomic .cancelled and .finished fields in BlockCopyCallState Emanuele Giuseppe Esposito
2021-06-19 20:06 ` Vladimir Sementsov-Ogievskiy
2021-06-21 9:30 ` Emanuele Giuseppe Esposito
2021-06-22 9:56 ` Vladimir Sementsov-Ogievskiy
2021-06-22 8:15 ` Paolo Bonzini
2021-06-22 9:36 ` Vladimir Sementsov-Ogievskiy
2021-06-22 10:20 ` Paolo Bonzini
2021-06-22 10:39 ` Vladimir Sementsov-Ogievskiy
2021-06-22 20:57 ` Emanuele Giuseppe Esposito
2021-06-23 10:06 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6e031269-3ecb-f2f2-9833-eef4073cf5e0@redhat.com \
--to=eesposit@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).