From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Wen Congyang <wencongyang2@huawei.com>,
Xie Changlong <xiechanglong.d@gmail.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>
Subject: Re: [RFC PATCH v2 05/14] block/mirror.c: use of job helpers in drivers to avoid TOC/TOU
Date: Thu, 23 Dec 2021 12:37:51 +0100 [thread overview]
Message-ID: <7b5a36d8-ad3b-9d70-93e2-ea43638d2cf9@redhat.com> (raw)
In-Reply-To: <bed1cd66-2fe0-e619-fd08-d80dcafdd867@virtuozzo.com>
On 20/12/2021 11:47, Vladimir Sementsov-Ogievskiy wrote:
> 20.12.2021 13:34, Emanuele Giuseppe Esposito wrote:
>>
>>
>> On 18/12/2021 12:53, Vladimir Sementsov-Ogievskiy wrote:
>>> 04.11.2021 17:53, Emanuele Giuseppe Esposito wrote:
>>>> Once job lock is used and aiocontext is removed, mirror has
>>>> to perform job operations under the same critical section,
>>>> using the helpers prepared in previous commit.
>>>>
>>>> Note: at this stage, job_{lock/unlock} and job lock guard macros
>>>> are *nop*.
>>>>
>>>> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
>>>> ---
>>>> block/mirror.c | 8 +++-----
>>>> 1 file changed, 3 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/block/mirror.c b/block/mirror.c
>>>> index 00089e519b..f22fa7da6e 100644
>>>> --- a/block/mirror.c
>>>> +++ b/block/mirror.c
>>>> @@ -653,7 +653,7 @@ static int mirror_exit_common(Job *job)
>>>> BlockDriverState *target_bs;
>>>> BlockDriverState *mirror_top_bs;
>>>> Error *local_err = NULL;
>>>> - bool abort = job->ret < 0;
>>>> + bool abort = job_has_failed(job);
>>>> int ret = 0;
>>>> if (s->prepared) {
>>>> @@ -1161,9 +1161,7 @@ static void mirror_complete(Job *job, Error
>>>> **errp)
>>>> s->should_complete = true;
>>>> /* If the job is paused, it will be re-entered when it is
>>>> resumed */
>>>> - if (!job->paused) {
>>>> - job_enter(job);
>>>> - }
>>>> + job_enter_not_paused(job);
>>>> }
>>>> static void coroutine_fn mirror_pause(Job *job)
>>>> @@ -1182,7 +1180,7 @@ static bool mirror_drained_poll(BlockJob *job)
>>>> * from one of our own drain sections, to avoid a deadlock
>>>> waiting for
>>>> * ourselves.
>>>> */
>>>> - if (!s->common.job.paused && !job_is_cancelled(&job->job) &&
>>>> !s->in_drain) {
>>>> + if (job_not_paused_nor_cancelled(&s->common.job) &&
>>>> !s->in_drain) {
>>>> return true;
>>>> }
>>>>
>>>
>>> Why to introduce a separate API function for every use case?
>>>
>>> Could we instead just use WITH_JOB_LOCK_GUARD() ?
>>>
>>
>> This implies making the struct job_mutex public. Is that ok for you?
>>
>
> Yes, I think it's OK.
>
> Alternatively, you can use job_lock() / job_unlock(), or even rewrite
> WITH_JOB_LOCK_GUARD() macro using job_lock/job_unlock, to keep mutex
> private.. But I don't think it really worth it now.
>
> Note that struct Job is already public, so if we'll use per-job mutex in
> future it still is not a problem. Only when we decide to make struct Job
> private, we'll have to decide something about JOB_LOCK_GUARD(), and at
> this point we'll just rewrite it to work through some helper function
> instead of directly touching the mutex.
>
>
Ok I will do that. Just FYI the initial idea was that drivers like
monitor would not need to know about job_mutex lock, that is why I made
the helpers in mirror.c.
Thank you,
Emanuele
next prev parent reply other threads:[~2021-12-23 11:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 14:53 [RFC PATCH v2 00/14] job: replace AioContext lock with job_mutex Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 01/14] job.c: make job_lock/unlock public Emanuele Giuseppe Esposito
2021-12-16 16:18 ` Stefan Hajnoczi
2021-11-04 14:53 ` [RFC PATCH v2 02/14] job.h: categorize fields in struct Job Emanuele Giuseppe Esposito
2021-12-16 16:21 ` Stefan Hajnoczi
2021-12-21 14:23 ` Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 03/14] job.h: define locked functions Emanuele Giuseppe Esposito
2021-12-16 16:48 ` Stefan Hajnoczi
2021-12-16 17:11 ` Vladimir Sementsov-Ogievskiy
2021-12-20 10:15 ` Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 04/14] job.h: define unlocked functions Emanuele Giuseppe Esposito
2021-12-16 16:51 ` Stefan Hajnoczi
2021-11-04 14:53 ` [RFC PATCH v2 05/14] block/mirror.c: use of job helpers in drivers to avoid TOC/TOU Emanuele Giuseppe Esposito
2021-12-18 11:53 ` Vladimir Sementsov-Ogievskiy
2021-12-20 10:34 ` Emanuele Giuseppe Esposito
2021-12-20 10:47 ` Vladimir Sementsov-Ogievskiy
2021-12-23 11:37 ` Emanuele Giuseppe Esposito [this message]
2021-11-04 14:53 ` [RFC PATCH v2 06/14] job.c: make job_event_* functions static Emanuele Giuseppe Esposito
2021-12-16 16:54 ` Stefan Hajnoczi
2021-11-04 14:53 ` [RFC PATCH v2 07/14] job.c: move inner aiocontext lock in callbacks Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 08/14] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 09/14] jobs: remove aiocontext locks since the functions are under BQL Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 10/14] jobs: protect jobs with job_lock/unlock Emanuele Giuseppe Esposito
2021-12-18 11:57 ` Vladimir Sementsov-Ogievskiy
2021-11-04 14:53 ` [RFC PATCH v2 11/14] block_job_query: remove atomic read Emanuele Giuseppe Esposito
2021-12-18 12:07 ` Vladimir Sementsov-Ogievskiy
2021-12-23 11:37 ` Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 12/14] jobs: use job locks and helpers also in the unit tests Emanuele Giuseppe Esposito
2021-11-04 14:53 ` [RFC PATCH v2 13/14] jobs: add job lock in find_* functions Emanuele Giuseppe Esposito
2021-12-18 12:11 ` Vladimir Sementsov-Ogievskiy
2021-12-18 12:22 ` Vladimir Sementsov-Ogievskiy
2021-11-04 14:53 ` [RFC PATCH v2 14/14] job.c: enable job lock/unlock and remove Aiocontext locks Emanuele Giuseppe Esposito
2021-12-18 12:24 ` Vladimir Sementsov-Ogievskiy
2021-12-23 14:59 ` Emanuele Giuseppe Esposito
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=7b5a36d8-ad3b-9d70-93e2-ea43638d2cf9@redhat.com \
--to=eesposit@redhat.com \
--cc=armbru@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
--cc=wencongyang2@huawei.com \
--cc=xiechanglong.d@gmail.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).