qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/5] dma-helpers: rewrite completion/cancellation
Date: Fri, 9 Sep 2011 08:43:25 -0400 (EDT)	[thread overview]
Message-ID: <1024719509.1142051.1315572205133.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com> (raw)
In-Reply-To: <4E6A031B.40905@redhat.com>

> > @@ -120,9 +132,8 @@ static void dma_bdrv_cb(void *opaque, int ret)
> >      dbs->acb = dbs->io_func(dbs->bs, dbs->sector_num, &dbs->iov,
> >                              dbs->iov.size / 512, dma_bdrv_cb, dbs);
> >      if (!dbs->acb) {
> > -        dma_bdrv_unmap(dbs);
> > -        qemu_iovec_destroy(&dbs->iov);
> > -        return;
> > +        dbs->common.cb = NULL;
> > +        dma_complete(dbs, -ENOMEM);
> 
> Why don't we call the callback here? I know that it already was this
> way before your patch, but isn't that a bug?
> 
> Also, I think it should be -EIO instead of -ENOMEM (even though it
> doesn't make any difference if we don't call the callback)

If I understood the code correctly, dbs->io_func can only fail if it
fails to get an AIOCB, which is basically out-of-memory.  By the way, I
remember reading (from you?) that this is bogus and it would be cleaner
if callers of functions returning an AIOCB just assumed the return value
to be non-NULL.

I checked now, and the following block drivers can return a NULL AIOCB
even if qemu_aio_get succeeds:

* blkdebug (easily fixed ;))

* curl (seems like it also boils down to out-of-memory)

* rbd (can fail in librbd; might defer completion with an error to a
bottom half instead)

* linux-aio (when io_submit fails; might fall back to posix-aio-compat
instead).


> > @@ -131,8 +142,12 @@ static void dma_aio_cancel(BlockDriverAIOCB
> > *acb)
> >      DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common);
> >
> >      if (dbs->acb) {
> > -        bdrv_aio_cancel(dbs->acb);
> > +        BlockDriverAIOCB *acb = dbs->acb;
> > +        dbs->acb = NULL;
> > +        bdrv_aio_cancel(acb);
> >      }
> > +    dbs->common.cb = NULL;
> > +    dma_complete(dbs, 0);
> 
> Did you consider that there are block drivers that implement
> bdrv_aio_cancel() as waiting for completion of outstanding requests? I
> think in that case dma_complete() may be called twice. For most of it,
> this shouldn't be a problem, but I think it doesn't work with the
> qemu_aio_release(dbs).

Right.  But then what to do (short of inventing reference counting
of some sort for AIOCBs) with those that don't?  Leaking should not
be acceptable, should it?

In short, this patch can be dropped, but it shows more problems. :)

Paolo

  reply	other threads:[~2011-09-09 12:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-07 15:20 [Qemu-devel] [PATCH 0/5] block: preparatory patches for scatter/gather support Paolo Bonzini
2011-09-07 15:20 ` [Qemu-devel] [PATCH 1/5] dma-helpers: rename is_write to to_dev Paolo Bonzini
2011-09-09 11:31   ` Kevin Wolf
2011-09-07 15:20 ` [Qemu-devel] [PATCH 2/5] dma-helpers: allow including from target-independent code Paolo Bonzini
2011-09-09 11:39   ` Kevin Wolf
2011-09-09 11:53     ` Paolo Bonzini
2011-09-07 15:21 ` [Qemu-devel] [PATCH 3/5] dma-helpers: rewrite completion/cancellation Paolo Bonzini
2011-09-09 12:14   ` Kevin Wolf
2011-09-09 12:43     ` Paolo Bonzini [this message]
2011-09-09 12:59       ` Kevin Wolf
2011-09-09 13:12         ` Paolo Bonzini
2011-09-09 13:34           ` Kevin Wolf
2011-09-09 13:43             ` Paolo Bonzini
2011-09-07 15:21 ` [Qemu-devel] [PATCH 4/5] scsi-disk: commonize iovec creation between reads and writes Paolo Bonzini
2011-09-07 15:21 ` [Qemu-devel] [PATCH 5/5] scsi-disk: lazily allocate bounce buffer Paolo Bonzini

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=1024719509.1142051.1315572205133.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --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).