From: Stefan Hajnoczi <stefanha@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 08/16] blockjob: introduce .drain callback for jobs
Date: Wed, 16 Mar 2016 17:56:52 +0000 [thread overview]
Message-ID: <20160316175652.GB2012@stefanha-x1.localdomain> (raw)
In-Reply-To: <1455645388-32401-9-git-send-email-pbonzini@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 5443 bytes --]
On Tue, Feb 16, 2016 at 06:56:20PM +0100, Paolo Bonzini wrote:
> This is required to decouple block jobs from running in an
> AioContext. With multiqueue block devices, a BlockDriverState
> does not really belong to a single AioContext.
>
> The solution is to first wait until all I/O operations are
> complete; then loop in the main thread for the block job to
> complete entirely.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block/backup.c | 7 +++++++
> block/mirror.c | 12 ++++++++++--
> blockjob.c | 16 +++++++++++++---
> include/block/blockjob.h | 7 +++++++
> 4 files changed, 37 insertions(+), 5 deletions(-)
>
> diff --git a/block/backup.c b/block/backup.c
> index 00cafdb..2edb895 100644
> --- a/block/backup.c
> +++ b/block/backup.c
> @@ -251,6 +251,12 @@ static void backup_abort(BlockJob *job)
> }
> }
>
> +static void backup_drain(BlockJob *job)
> +{
> + BackupBlockJob *s = container_of(job, BackupBlockJob, common);
> + bdrv_drain(s->target);
> +}
> +
> static const BlockJobDriver backup_job_driver = {
> .instance_size = sizeof(BackupBlockJob),
> .job_type = BLOCK_JOB_TYPE_BACKUP,
> @@ -258,6 +264,7 @@ static const BlockJobDriver backup_job_driver = {
> .iostatus_reset = backup_iostatus_reset,
> .commit = backup_commit,
> .abort = backup_abort,
> + .drain = backup_drain,
> };
>
> static BlockErrorAction backup_error_action(BackupBlockJob *job,
> diff --git a/block/mirror.c b/block/mirror.c
> index 3f163b8..b473a1b 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -358,7 +358,7 @@ static void mirror_free_init(MirrorBlockJob *s)
> }
> }
>
> -static void mirror_drain(MirrorBlockJob *s)
> +static void mirror_wait_for_completion(MirrorBlockJob *s)
> {
> while (s->in_flight > 0) {
> s->waiting_for_io = true;
> @@ -627,7 +627,7 @@ immediate_exit:
> * the target is a copy of the source.
> */
> assert(ret < 0 || (!s->synced && block_job_is_cancelled(&s->common)));
> - mirror_drain(s);
> + mirror_wait_for_completion(s);
> }
>
> assert(s->in_flight == 0);
> @@ -708,12 +708,19 @@ static void mirror_complete(BlockJob *job, Error **errp)
> block_job_enter(&s->common);
> }
>
> +static void mirror_drain(BlockJob *job)
> +{
> + MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
> + bdrv_drain(s->target);
> +}
> +
> static const BlockJobDriver mirror_job_driver = {
> .instance_size = sizeof(MirrorBlockJob),
> .job_type = BLOCK_JOB_TYPE_MIRROR,
> .set_speed = mirror_set_speed,
> .iostatus_reset= mirror_iostatus_reset,
> .complete = mirror_complete,
> + .drain = mirror_drain,
> };
>
> static const BlockJobDriver commit_active_job_driver = {
> @@ -723,6 +730,7 @@ static const BlockJobDriver commit_active_job_driver = {
> .iostatus_reset
> = mirror_iostatus_reset,
> .complete = mirror_complete,
> + .drain = mirror_drain,
> };
>
> static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
> diff --git a/blockjob.c b/blockjob.c
> index 9fc37ca..5bb6f9b 100644
> --- a/blockjob.c
> +++ b/blockjob.c
> @@ -289,16 +289,26 @@ static int block_job_finish_sync(BlockJob *job,
> assert(bs->job == job);
>
> block_job_ref(job);
> +
> + /* finish will call block_job_enter (see e.g. block_job_cancel,
> + * or mirror_complete in block/mirror.c). Barring bugs in the
> + * job coroutine, bdrv_drain should be enough to induce progress
> + * until the job completes or moves to the main thread.
> + */
> finish(job, &local_err);
> if (local_err) {
> error_propagate(errp, local_err);
> block_job_unref(job);
> return -EBUSY;
> }
> + while (!job->deferred_to_main_loop && !job->completed) {
> + bdrv_drain(bs);
> + if (job->driver->drain) {
> + job->driver->drain(job);
> + }
> + }
> while (!job->completed) {
> - aio_poll(job->deferred_to_main_loop ? qemu_get_aio_context() :
> - bdrv_get_aio_context(bs),
> - true);
> + aio_poll(qemu_get_aio_context(), true);
> }
This adds the assumption that block_job_defer_to_main_loop() is only
used to complete the block job. If we really need to make this
assumption then we could rename it complete_in_main_loop() or similar so
that is clear.
> ret = (job->cancelled && job->ret == 0) ? -ECANCELED : job->ret;
> block_job_unref(job);
> diff --git a/include/block/blockjob.h b/include/block/blockjob.h
> index 8bedc49..8e564df 100644
> --- a/include/block/blockjob.h
> +++ b/include/block/blockjob.h
> @@ -70,6 +70,13 @@ typedef struct BlockJobDriver {
> * never both.
> */
> void (*abort)(BlockJob *job);
> +
> + /**
> + * If the callback is not NULL, it will be invoked when the job has to be
> + * synchronously cancelled or completed; it should drain BlockDriverStates
> + * as required to ensure progress.
> + */
> + void (*drain)(BlockJob *job);
> } BlockJobDriver;
>
> /**
> --
> 2.5.0
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2016-03-16 17:57 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 17:56 [Qemu-devel] [PATCH 00/16] AioContext fine-grained locking, part 1 of 3, including bdrv_drain rewrite Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 01/16] block: make bdrv_start_throttled_reqs return void Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 02/16] block: move restarting of throttled reqs to block/throttle-groups.c Paolo Bonzini
2016-03-09 1:26 ` Fam Zheng
2016-03-09 7:37 ` Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 03/16] block: introduce bdrv_no_throttling_begin/end Paolo Bonzini
2016-03-09 1:45 ` Fam Zheng
2016-03-09 7:40 ` Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 04/16] block: plug whole tree at once, introduce bdrv_io_unplugged_begin/end Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 05/16] mirror: use bottom half to re-enter coroutine Paolo Bonzini
2016-03-09 3:19 ` Fam Zheng
2016-03-09 7:41 ` Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 06/16] block: add BDS field to count in-flight requests Paolo Bonzini
2016-03-09 3:35 ` Fam Zheng
2016-03-09 7:43 ` Paolo Bonzini
2016-03-09 8:00 ` Fam Zheng
2016-03-09 8:22 ` Paolo Bonzini
2016-03-09 8:33 ` Fam Zheng
2016-02-16 17:56 ` [Qemu-devel] [PATCH 07/16] block: change drain to look only at one child at a time Paolo Bonzini
2016-03-09 3:41 ` Fam Zheng
2016-03-09 7:49 ` Paolo Bonzini
2016-03-16 16:39 ` Stefan Hajnoczi
2016-03-16 17:41 ` Paolo Bonzini
2016-03-17 0:57 ` Fam Zheng
2016-02-16 17:56 ` [Qemu-devel] [PATCH 08/16] blockjob: introduce .drain callback for jobs Paolo Bonzini
2016-03-16 17:56 ` Stefan Hajnoczi [this message]
2016-02-16 17:56 ` [Qemu-devel] [PATCH 09/16] block: wait for all pending I/O when doing synchronous requests Paolo Bonzini
2016-03-09 8:13 ` Fam Zheng
2016-03-09 8:23 ` Paolo Bonzini
2016-03-16 18:04 ` Stefan Hajnoczi
2016-02-16 17:56 ` [Qemu-devel] [PATCH 10/16] nfs: replace aio_poll with bdrv_drain Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 11/16] sheepdog: disable dataplane Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 12/16] aio: introduce aio_context_in_iothread Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 13/16] block: only call aio_poll from iothread Paolo Bonzini
2016-03-09 8:30 ` Fam Zheng
2016-03-09 8:55 ` Paolo Bonzini
2016-03-09 9:10 ` Paolo Bonzini
2016-03-09 9:27 ` Fam Zheng
2016-02-16 17:56 ` [Qemu-devel] [PATCH 14/16] iothread: release AioContext around aio_poll Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 15/16] qemu-thread: introduce QemuRecMutex Paolo Bonzini
2016-02-16 17:56 ` [Qemu-devel] [PATCH 16/16] aio: convert from RFifoLock to QemuRecMutex Paolo Bonzini
2016-03-08 17:51 ` [Qemu-devel] [PATCH 00/16] AioContext fine-grained locking, part 1 of 3, including bdrv_drain rewrite Paolo Bonzini
2016-03-09 8:46 ` Fam Zheng
2016-03-16 18:18 ` Stefan Hajnoczi
2016-03-16 22:29 ` Paolo Bonzini
2016-03-17 13:44 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-03-17 13:48 ` Paolo Bonzini
2016-03-18 15:49 ` 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=20160316175652.GB2012@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=pbonzini@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).