From: John Snow <jsnow@redhat.com>
To: Jeff Cody <jcody@redhat.com>
Cc: kwolf@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org,
Markus Armbruster <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 02/21] jobs: add exit shim
Date: Wed, 8 Aug 2018 09:55:34 -0400 [thread overview]
Message-ID: <d9dcee87-d879-166b-695f-c8eca203f6a3@redhat.com> (raw)
In-Reply-To: <20180808040253.GE755222@localhost.localdomain>
On 08/08/2018 12:02 AM, Jeff Cody wrote:
> On Tue, Aug 07, 2018 at 12:33:30AM -0400, John Snow wrote:
>> Most jobs do the same thing when they leave their running loop:
>> - Store the return code in a structure
>> - wait to receive this structure in the main thread
>> - signal job completion via job_completed
>>
>> More seriously, when we utilize job_defer_to_main_loop_bh to call
>> a function that calls job_completed, job_finalize_single will run
>> in a context where it has recursively taken the aio_context lock,
>> which can cause hangs if it puts down a reference that causes a flush.
>>
>> The job infrastructure is perfectly capable of registering job
>> completion itself when we leave the job's entry point. In this
>> context, we can signal job completion from outside of the aio_context,
>> which should allow for job cleanup code to run with only one lock.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>
> I like the simplification, both in SLOC and in exit logic (as seen in
> patches 3-7).
>
>> ---
>> include/qemu/job.h | 7 +++++++
>> job.c | 19 +++++++++++++++++++
>> 2 files changed, 26 insertions(+)
>>
>> diff --git a/include/qemu/job.h b/include/qemu/job.h
>> index 845ad00c03..0c24e8704f 100644
>> --- a/include/qemu/job.h
>> +++ b/include/qemu/job.h
>> @@ -204,6 +204,13 @@ struct JobDriver {
>> */
>> void (*drain)(Job *job);
>>
>> + /**
>> + * If the callback is not NULL, exit will be invoked from the main thread
>> + * when the job's coroutine has finished, but before transactional
>> + * convergence; before @prepare or @abort.
>> + */
>> + void (*exit)(Job *job);
>> +
>> /**
>> * If the callback is not NULL, prepare will be invoked when all the jobs
>> * belonging to the same transaction complete; or upon this job's completion
>> diff --git a/job.c b/job.c
>> index b281f30375..cc5ac9ac30 100644
>> --- a/job.c
>> +++ b/job.c
>> @@ -535,6 +535,19 @@ void job_drain(Job *job)
>> }
>> }
>>
>> +static void job_exit(void *opaque)
>> +{
>> + Job *job = (Job *)opaque;
>> + AioContext *aio_context = job->aio_context;
>> +
>> + if (job->driver->exit) {
>> + aio_context_acquire(aio_context);
>> + job->driver->exit(job);
>> + aio_context_release(aio_context);
>> + }
>> + job_completed(job, job->ret);
>> +}
>> +
>> /**
>> * All jobs must allow a pause point before entering their job proper. This
>> * ensures that jobs can be paused prior to being started, then resumed later.
>> @@ -546,6 +559,12 @@ static void coroutine_fn job_co_entry(void *opaque)
>> assert(job && job->driver && job->driver->start);
>> job_pause_point(job);
>> job->driver->start(job);
>
> One nit-picky observation here, that is unrelated to this patch: reading
> through, it may not be so obvious that 'start' is really a 'run' or
> 'execute', (linguistically, to me 'start' implies a kick-off rather than
> ongoing execution).
>
> Just some bike-shedding again, though, and not even for this patch. So
> nothing to do here :)
>
> Reviewed-by: Jeff Cody <jcody@redhat.com>
I agree with you and thought the same as I was going through these
changes. I think with patch 12 in particular where I really solidify the
idea that this is the main execution loop for the coroutine makes it
obvious that it should be named .run or similar.
Also, while we're bikeshedding naming, it's weird that the flow here is:
.run/.start
.exit
.prepare
.commit
.abort
.clean
...I might want to emphasize a few points here:
(A) exit occurs prior to "finalization" and should not modify the graph
(B) "prepare" really means "prepare to finalize"
I just don't always have good terminology.
>
>
>> + if (!job->deferred_to_main_loop) {
>> + job->deferred_to_main_loop = true;
>> + aio_bh_schedule_oneshot(qemu_get_aio_context(),
>> + job_exit,
>> + job);
>> + }
>> }
>>
>>
>> --
>> 2.14.4
>>
>
next prev parent reply other threads:[~2018-08-08 13:55 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-07 4:33 [Qemu-devel] [PATCH 00/21] jobs: defer graph changes until finalize John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 01/21] jobs: canonize Error object John Snow
2018-08-08 14:57 ` Kevin Wolf
2018-08-08 15:50 ` John Snow
2018-08-08 16:02 ` Kevin Wolf
2018-08-07 4:33 ` [Qemu-devel] [PATCH 02/21] jobs: add exit shim John Snow
2018-08-08 4:02 ` Jeff Cody
2018-08-08 13:55 ` John Snow [this message]
2018-08-08 15:23 ` Kevin Wolf
2018-08-08 15:38 ` John Snow
2018-08-08 15:47 ` Kevin Wolf
2018-08-07 4:33 ` [Qemu-devel] [PATCH 03/21] block/backup: utilize job_exit shim John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 04/21] block/commit: " John Snow
2018-08-08 3:41 ` Jeff Cody
2018-08-08 14:00 ` John Snow
2018-08-08 16:29 ` Kevin Wolf
2018-08-15 20:52 ` John Snow
2018-08-16 6:41 ` Kevin Wolf
2018-08-07 4:33 ` [Qemu-devel] [PATCH 05/21] block/mirror: " John Snow
2018-08-08 3:47 ` Jeff Cody
2018-08-07 4:33 ` [Qemu-devel] [PATCH 06/21] block/stream: " John Snow
2018-08-08 3:47 ` Jeff Cody
2018-08-07 4:33 ` [Qemu-devel] [PATCH 07/21] block/create: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 08/21] tests/test-blockjob-txn: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 09/21] tests/test-blockjob: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 10/21] tests/test-bdrv-drain: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 11/21] jobs: remove job_defer_to_main_loop John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 12/21] jobs: allow entrypoints to return status code John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 13/21] block/commit: add block job creation flags John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 14/21] block/mirror: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 15/21] block/stream: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 16/21] block/commit: refactor commit to use job callbacks John Snow
2018-08-09 15:12 ` Kevin Wolf
2018-08-09 16:22 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2018-08-15 21:17 ` [Qemu-devel] " John Snow
2018-08-16 6:52 ` Kevin Wolf
2018-08-07 4:33 ` [Qemu-devel] [PATCH 17/21] block/mirror: conservative mirror_exit refactor John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 18/21] block/commit: refactor stream to use job callbacks John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 19/21] qapi/block-commit: expose new job properties John Snow
2018-08-07 14:52 ` Eric Blake
2018-08-07 18:11 ` John Snow
2018-08-10 11:47 ` Kevin Wolf
2018-08-07 4:33 ` [Qemu-devel] [PATCH 20/21] qapi/block-mirror: " John Snow
2018-08-07 4:33 ` [Qemu-devel] [PATCH 21/21] qapi/block-stream: " John Snow
2018-08-15 14:44 ` [Qemu-devel] [Qemu-block] [PATCH 00/21] jobs: defer graph changes until finalize Peter Krempa
2018-08-15 15:00 ` Kevin Wolf
2018-08-15 15:04 ` Peter Krempa
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=d9dcee87-d879-166b-695f-c8eca203f6a3@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).