qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Alberto Garcia <berto@igalia.com>
Cc: pbonzini@redhat.com, Fam Zheng <famz@redhat.com>,
	qemu-block@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] block: Pause block jobs in bdrv_drain_all
Date: Thu, 9 Apr 2015 11:34:04 +0100	[thread overview]
Message-ID: <20150409103404.GA2783@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <20150408145614.GA2140@igalia.com>

[-- Attachment #1: Type: text/plain, Size: 2285 bytes --]

On Wed, Apr 08, 2015 at 04:56:14PM +0200, Alberto Garcia wrote:
> On Wed, Apr 08, 2015 at 11:37:52AM +0100, Stefan Hajnoczi wrote:
> 
> > > +    QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
> > > +        AioContext *aio_context = bdrv_get_aio_context(bs);
> > > +
> > > +        aio_context_acquire(aio_context);
> > > +        if (bs->job) {
> > > +            block_job_pause(bs->job);
> > > +        }
> > > +        aio_context_release(aio_context);
> > > +    }
> > > +
> > >      while (busy) {
> > >          busy = false;
> > >  
> > > @@ -2044,6 +2054,16 @@ void bdrv_drain_all(void)
> > >              aio_context_release(aio_context);
> > >          }
> > >      }
> > > +
> > > +    QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
> > > +        AioContext *aio_context = bdrv_get_aio_context(bs);
> > > +
> > > +        aio_context_acquire(aio_context);
> > > +        if (bs->job) {
> > > +            block_job_resume(bs->job);
> > > +        }
> > > +        aio_context_release(aio_context);
> > > +    }
> > >  }
> > 
> > There is a tiny chance that we pause a job (which actually just sets
> > job->paused = true but there's no guarantee the job's coroutine
> > reacts to this) right before it terminates.  Then aio_poll() enters
> > the coroutine one last time and the job terminates.
> > 
> > We then reach the resume portion of bdrv_drain_all() and the job no
> > longer exists.  Hopefully nothing started a new job in the meantime.
> > bs->job should either be the original block job or NULL.
> > 
> > This code seems under current assumptions, but I just wanted to
> > raise these issues in case someone sees problems that I've missed.
> 
> Is it possible that a new job is started in the meantime? If that's
> the case this will hit the assertion in block_job_resume().

That is currently not possible since the QEMU monitor does not run while
we're waiting in aio_poll().

Therefore no block job monitor commands could spawn a new job.

If code is added that spawns a job based on an AioContext timer or due
to some other event, then this assumption no longer holds and there is a
problem because block_job_resume() is called on a job that never paused.

But for now there is no problem.

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2015-04-09 10:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03 14:05 [Qemu-devel] [PATCH v2 0/4] Fix "stop" draining block jobs Fam Zheng
2015-04-03 14:05 ` [Qemu-devel] [PATCH v2 1/4] blockjob: Allow nested pause Fam Zheng
2015-04-03 14:13   ` Paolo Bonzini
2015-04-20 17:11     ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-04-08  7:25   ` [Qemu-devel] " Alberto Garcia
2015-04-08 10:31   ` Stefan Hajnoczi
2015-04-03 14:05 ` [Qemu-devel] [PATCH v2 2/4] block: Pause block jobs in bdrv_drain_all Fam Zheng
2015-04-07 13:59   ` Alberto Garcia
2015-04-08 10:37   ` Stefan Hajnoczi
2015-04-08 14:56     ` Alberto Garcia
2015-04-09 10:34       ` Stefan Hajnoczi [this message]
2015-04-03 14:05 ` [Qemu-devel] [PATCH v2 3/4] qemu-iotests: Test that "stop" doesn't drain block jobs Fam Zheng
2015-04-07 14:46   ` Alberto Garcia
2015-04-08 10:39   ` Stefan Hajnoczi
2015-04-24 15:43   ` [Qemu-devel] [Qemu-block] " Max Reitz
2015-04-27  5:14     ` Fam Zheng
2015-04-27 11:08       ` Max Reitz
2015-04-03 14:05 ` [Qemu-devel] [PATCH v2 4/4] blockjob: Update function name in comments Fam Zheng
2015-04-07 14:46   ` Alberto Garcia
2015-04-08 10:40 ` [Qemu-devel] [PATCH v2 0/4] Fix "stop" draining block jobs Stefan Hajnoczi
2015-04-20 15:38 ` [Qemu-devel] [Qemu-block] " 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=20150409103404.GA2783@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=berto@igalia.com \
    --cc=famz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).