All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Wen Congyang <wencongyang2@huawei.com>,
	Xie Changlong <xiechanglong.d@gmail.com>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v8 06/20] job.h: define functions called without job lock held
Date: Wed, 6 Jul 2022 10:22:52 +0200	[thread overview]
Message-ID: <a015b31a-a195-c146-576b-754517f3614a@redhat.com> (raw)
In-Reply-To: <b96f9001-66d3-3c4e-617b-c515982336de@yandex-team.ru>



Am 05/07/2022 um 12:53 schrieb Vladimir Sementsov-Ogievskiy:
> On 6/29/22 17:15, Emanuele Giuseppe Esposito wrote:
>> These functions don't need a _locked() counterpart, since
>> they are all called outside job.c and take the lock only
>> internally.
>>
>> Update also the comments in blockjob.c (and move them in job.c).
> 
> Still, that would be better as a separate patch.
> 
>>
>> Note: at this stage, job_{lock/unlock} and job lock guard macros
>> are *nop*.
>>
>> No functional change intended.
>>
>> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
>> ---
>>   blockjob.c         | 20 --------------------
>>   include/qemu/job.h | 37 ++++++++++++++++++++++++++++++++++---
>>   job.c              | 15 +++++++++++++++
>>   3 files changed, 49 insertions(+), 23 deletions(-)
>>
>> diff --git a/blockjob.c b/blockjob.c
>> index 4868453d74..7da59a1f1c 100644
>> --- a/blockjob.c
>> +++ b/blockjob.c
>> @@ -36,21 +36,6 @@
>>   #include "qemu/main-loop.h"
>>   #include "qemu/timer.h"
>>   -/*
>> - * The block job API is composed of two categories of functions.
>> - *
>> - * The first includes functions used by the monitor.  The monitor is
>> - * peculiar in that it accesses the block job list with
>> block_job_get, and
>> - * therefore needs consistency across block_job_get and the actual
>> operation
>> - * (e.g. block_job_set_speed).  The consistency is achieved with
>> - * aio_context_acquire/release.  These functions are declared in
>> blockjob.h.
>> - *
>> - * The second includes functions used by the block job drivers and
>> sometimes
>> - * by the core block layer.  These do not care about locking, because
>> the
>> - * whole coroutine runs under the AioContext lock, and are declared in
>> - * blockjob_int.h.
>> - */
>> -
>>   static bool is_block_job(Job *job)
>>   {
>>       return job_type(job) == JOB_TYPE_BACKUP ||
>> @@ -433,11 +418,6 @@ static void block_job_event_ready(Notifier *n,
>> void *opaque)
>>   }
>>     -/*
>> - * API for block job drivers and the block layer.  These functions are
>> - * declared in blockjob_int.h.
>> - */
>> -
>>   void *block_job_create(const char *job_id, const BlockJobDriver
>> *driver,
>>                          JobTxn *txn, BlockDriverState *bs, uint64_t
>> perm,
>>                          uint64_t shared_perm, int64_t speed, int flags,
>> diff --git a/include/qemu/job.h b/include/qemu/job.h
>> index 99960cc9a3..b714236c1a 100644
>> --- a/include/qemu/job.h
>> +++ b/include/qemu/job.h
>> @@ -363,6 +363,7 @@ void job_txn_unref_locked(JobTxn *txn);
>>     /**
>>    * Create a new long-running job and return it.
>> + * Called with job_mutex *not* held.
>>    *
>>    * @job_id: The id of the newly-created job, or %NULL for internal jobs
>>    * @driver: The class object for the newly-created job.
>> @@ -400,6 +401,8 @@ void job_unref_locked(Job *job);
>>    * @done: How much progress the job made since the last call
>>    *
>>    * Updates the progress counter of the job.
>> + *
>> + * Progress API is thread safe.
> 
> This tell nothing for function user. Finally the whole job_ API will be
> thread safe, isn't it?
> 
> I think here we need simply "called with mutex not held". (Or even "may
> be called with mutex held or not held" if we need it, or just nothing)
> 
> and note about progress API should be somewhere in job.c, as that's
> implementation details.

What about "Progress API is thread safe. Can be called with job mutex
held or not"?

> 
[...]
> 
> I'd merge all new comments in job.h to the previous commit, as they are
> related to the questions risen by it.

I disagree, I think it will be a mess of functions again if we mix these
one that don't need the lock held and the ones that need it.

You understand it because you got the logic of this serie, but others
may not.

> 
> 
>>   void job_cancel_sync_all(void);
>>     /**
>> diff --git a/job.c b/job.c
>> index dd44fac8dd..7a3cc93f66 100644
>> --- a/job.c
>> +++ b/job.c
>> @@ -32,12 +32,27 @@
>>   #include "trace/trace-root.h"
>>   #include "qapi/qapi-events-job.h"
>>   +/*
>> + * The job API is composed of two categories of functions.
>> + *
>> + * The first includes functions used by the monitor.  The monitor is
>> + * peculiar in that it accesses the block job list with job_get, and
>> + * therefore needs consistency across job_get and the actual operation
>> + * (e.g. job_user_cancel). To achieve this consistency, the caller
>> + * calls job_lock/job_unlock itself around the whole operation.
>> + *
>> + *
>> + * The second includes functions used by the block job drivers and
>> sometimes
>> + * by the core block layer. These delegate the locking to the callee
>> instead.
>> + */
>> +
>>   /*
>>    * job_mutex protects the jobs list, but also makes the
>>    * struct job fields thread-safe.
>>    */
>>   QemuMutex job_mutex;
>>   +/* Protected by job_mutex */
>>   static QLIST_HEAD(, Job) jobs = QLIST_HEAD_INITIALIZER(jobs);
>>     /* Job State Transition Table */
> 
> 
> So the logic is: the function that doesn't have public _locked
> counterpart has explicit comment that mutex should be not held. OK.
> 



  reply	other threads:[~2022-07-06  8:38 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29 14:15 [PATCH v8 00/20] job: replace AioContext lock with job_mutex Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 01/20] job.c: make job_mutex and job_lock/unlock() public Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 02/20] job.h: categorize fields in struct Job Emanuele Giuseppe Esposito
2022-07-05  7:29   ` Stefan Hajnoczi
2022-06-29 14:15 ` [PATCH v8 03/20] job.c: API functions not used outside should be static Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 04/20] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 05/20] job.c: add job_lock/unlock while keeping job.h intact Emanuele Giuseppe Esposito
2022-07-05  7:39   ` Stefan Hajnoczi
2022-07-05  8:07     ` Emanuele Giuseppe Esposito
2022-07-06 10:09       ` Stefan Hajnoczi
2022-07-05  7:39   ` Stefan Hajnoczi
2022-07-05 10:23   ` Vladimir Sementsov-Ogievskiy
2022-06-29 14:15 ` [PATCH v8 06/20] job.h: define functions called without job lock held Emanuele Giuseppe Esposito
2022-07-05  7:43   ` Stefan Hajnoczi
2022-07-05 10:53   ` Vladimir Sementsov-Ogievskiy
2022-07-06  8:22     ` Emanuele Giuseppe Esposito [this message]
2022-07-06  9:48       ` Vladimir Sementsov-Ogievskiy
2022-07-05 10:54   ` Vladimir Sementsov-Ogievskiy
2022-07-06  8:23     ` Emanuele Giuseppe Esposito
2022-07-06  9:51       ` Vladimir Sementsov-Ogievskiy
2022-06-29 14:15 ` [PATCH v8 07/20] job.h: add _locked public functions Emanuele Giuseppe Esposito
2022-07-05  7:44   ` Stefan Hajnoczi
2022-07-05 10:58   ` Vladimir Sementsov-Ogievskiy
2022-06-29 14:15 ` [PATCH v8 08/20] blockjob.h: introduce block_job _locked() APIs Emanuele Giuseppe Esposito
2022-07-05  7:58   ` Stefan Hajnoczi
2022-07-05  8:12     ` Emanuele Giuseppe Esposito
2022-07-05 15:01   ` Vladimir Sementsov-Ogievskiy
2022-07-06 12:05     ` Emanuele Giuseppe Esposito
2022-07-06 12:23       ` Vladimir Sementsov-Ogievskiy
2022-07-06 12:36         ` Emanuele Giuseppe Esposito
2022-07-06 12:59           ` Emanuele Giuseppe Esposito
2022-07-06 17:23             ` Vladimir Sementsov-Ogievskiy
2022-06-29 14:15 ` [PATCH v8 09/20] blockjob: rename notifier callbacks as _locked Emanuele Giuseppe Esposito
2022-07-05  8:00   ` Stefan Hajnoczi
2022-06-29 14:15 ` [PATCH v8 10/20] jobs: add job lock in find_* functions Emanuele Giuseppe Esposito
2022-07-05  8:03   ` Stefan Hajnoczi
2022-06-29 14:15 ` [PATCH v8 11/20] jobs: use job locks also in the unit tests Emanuele Giuseppe Esposito
2022-07-05  8:04   ` Stefan Hajnoczi
2022-06-29 14:15 ` [PATCH v8 12/20] block/mirror.c: use of job helpers in drivers to avoid TOC/TOU Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 13/20] jobs: group together API calls under the same job lock Emanuele Giuseppe Esposito
2022-07-05  8:14   ` Stefan Hajnoczi
2022-07-05  8:17     ` Emanuele Giuseppe Esposito
2022-07-05 13:01       ` Emanuele Giuseppe Esposito
2022-07-05 13:22         ` Vladimir Sementsov-Ogievskiy
2022-07-06 10:13           ` Stefan Hajnoczi
2022-07-05 14:55   ` Vladimir Sementsov-Ogievskiy
2022-06-29 14:15 ` [PATCH v8 14/20] commit and mirror: create new nodes using bdrv_get_aio_context, and not the job aiocontext Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 15/20] job: detect change of aiocontext within job coroutine Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 16/20] jobs: protect job.aio_context with BQL and job_mutex Emanuele Giuseppe Esposito
2022-07-05 12:44   ` Stefan Hajnoczi
2022-06-29 14:15 ` [PATCH v8 17/20] job.c: enable job lock/unlock and remove Aiocontext locks Emanuele Giuseppe Esposito
2022-07-05 13:07   ` Stefan Hajnoczi
2022-07-06 21:29     ` Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 18/20] block_job_query: remove atomic read Emanuele Giuseppe Esposito
2022-06-29 14:15 ` [PATCH v8 19/20] blockjob: remove unused functions Emanuele Giuseppe Esposito
2022-07-05 13:10   ` Stefan Hajnoczi
2022-06-29 14:15 ` [PATCH v8 20/20] job: " Emanuele Giuseppe Esposito
2022-07-05 13:11   ` Stefan Hajnoczi
2022-07-05 13:12 ` [PATCH v8 00/20] job: replace AioContext lock with job_mutex Stefan Hajnoczi

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=a015b31a-a195-c146-576b-754517f3614a@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=vsementsov@yandex-team.ru \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.