qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Klaus Jensen <its@irrelevant.dk>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH RFC 1/4] hw/block/nvme: convert dsm to aiocb
Date: Tue, 9 Mar 2021 16:03:38 +0000	[thread overview]
Message-ID: <YEecWpaChyb883Ut@stefanha-x1.localdomain> (raw)
In-Reply-To: <YEZndKMdZcMvDKck@apples.localdomain>

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

On Mon, Mar 08, 2021 at 07:05:40PM +0100, Klaus Jensen wrote:
> On Mar  8 16:37, Stefan Hajnoczi wrote:
> > On Tue, Mar 02, 2021 at 12:10:37PM +0100, Klaus Jensen wrote:
> > > +static void nvme_dsm_cancel(BlockAIOCB *aiocb)
> > > +{
> > > +    NvmeDSMAIOCB *iocb = container_of(aiocb, NvmeDSMAIOCB, common);
> > > +
> > > +    /* break loop */
> > > +    iocb->curr.len = 0;
> > > +    iocb->curr.idx = iocb->nr;
> > > +
> > > +    iocb->ret = -ECANCELED;
> > > +
> > > +    if (iocb->aiocb) {
> > > +        blk_aio_cancel_async(iocb->aiocb);
> > > +        iocb->aiocb = NULL;
> > > +    }
> > > +}
> > 
> > Is the case where iocb->aiocb == NULL just in case nvme_dsm_cancel() is
> > called after the last discard has completed but before the BH runs? I
> > want to make sure there are no other cases because nothing would call
> > iocb->common.cb().
> > 
> 
> Yes - that case *can* happen, right?
> 
> I modeled this after the appoach in the ide trim code (hw/ide/core.c).

Yes, nvme_dsm_bh() may run after other event loop activity. Therefore we
have to take the iocb->aiocb == NULL case into account because some
event loop activity could call nvme_dsm_cancel() before the BH runs.

Another (wild?) possibility is that nvme_dsm_cancel() is called twice.
That's okay, nvme_dsm_cancel() supports that nicely.

But I wasn't sure if there are any other cases where iocb->aiocb can be
NULL? It could be nice to include an assertion or comment to clarify
this. For example:

  if (iocb->aiocb) {
      blk_aio_cancel_async(iocb->aiocb);
      iocb->aiocb = NULL;
  } else {
      /*
       * We only get here if nvme_dsm_cancel() was already called or
       * nvme_dsm_bh() is about to run.
       */
      assert(iocb->curr.idx == iocb->nr);
  }

  /* break loop */
  iocb->curr.len = 0;
  iocb->curr.idx = iocb->nr;

  iocb->ret = -ECANCELED;

(I'm not sure if my assert is correct, but hopefully this explains what
I mean.)

The reason why this assertion is important is because nvme_dsm_cancel()
does not support other iocb->aiocb = NULL cases. The cancelled request
could hang if nothing completes it. The assertion will complain loudly
if this every happens (may not now, but if someone changes the code in
the future).

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2021-03-09 16:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02 11:10 [PATCH RFC 0/4] hw/block/nvme: convert ad-hoc aio tracking to aiocbs Klaus Jensen
2021-03-02 11:10 ` [PATCH RFC 1/4] hw/block/nvme: convert dsm to aiocb Klaus Jensen
2021-03-08 16:37   ` Stefan Hajnoczi
2021-03-08 18:05     ` Klaus Jensen
2021-03-09 16:03       ` Stefan Hajnoczi [this message]
2021-03-09 18:27         ` Klaus Jensen
2021-03-02 11:10 ` [PATCH RFC 2/4] hw/block/nvme: convert copy " Klaus Jensen
2021-03-02 11:10 ` [PATCH RFC 3/4] hw/block/nvme: convert flush " Klaus Jensen
2021-03-02 11:10 ` [PATCH RFC 4/4] hw/block/nvme: convert zone reset " Klaus Jensen
2021-03-08 16:38 ` [PATCH RFC 0/4] hw/block/nvme: convert ad-hoc aio tracking to aiocbs 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=YEecWpaChyb883Ut@stefanha-x1.localdomain \
    --to=stefanha@redhat.com \
    --cc=its@irrelevant.dk \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --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).