All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, stefanha@gmail.com,
	jcody@redhat.com, Peter Lieven <pl@kamp.de>,
	jsnow@redhat.com
Subject: [Qemu-devel] [PATCH V4 4/6] ide: orphan all buffered requests on DMA cancel
Date: Thu, 12 Nov 2015 17:30:44 +0100	[thread overview]
Message-ID: <1447345846-15624-5-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1447345846-15624-1-git-send-email-pl@kamp.de>

If the guests canceles a DMA request we can prematurely
invoke all callbacks of buffered requests and flag all them
as orphaned. Ideally this avoids the need for draining all
requests. For CDROM devices this works in 100% of all cases.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 hw/ide/pci.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 9c54b37..37dbc29 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -233,6 +233,22 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val)
     /* Ignore writes to SSBM if it keeps the old value */
     if ((val & BM_CMD_START) != (bm->cmd & BM_CMD_START)) {
         if (!(val & BM_CMD_START)) {
+            /* First invoke the callbacks of all buffered requests
+             * and flag those requests as orphaned. Ideally there
+             * are no unbuffered (Scatter Gather DMA Requests or
+             * write requests) pending and we can avoid to drain. */
+            IDEBufferedRequest *req;
+            IDEState *s = idebus_active_if(bm->bus);
+            QLIST_FOREACH(req, &s->buffered_requests, list) {
+                if (!req->orphaned) {
+#ifdef DEBUG_IDE
+                    printf("%s: invoking cb %p of buffered request %p with"
+                           " -ECANCELED\n", __func__, req->original_cb, req);
+#endif
+                    req->original_cb(req->original_opaque, -ECANCELED);
+                }
+                req->orphaned = true;
+            }
             /*
              * We can't cancel Scatter Gather DMA in the middle of the
              * operation or a partial (not full) DMA transfer would reach
@@ -246,6 +262,9 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val)
              * aio operation with preadv/pwritev.
              */
             if (bm->bus->dma->aiocb) {
+#ifdef DEBUG_IDE
+                printf("%s: draining all remaining requests", __func__);
+#endif
                 blk_drain_all();
                 assert(bm->bus->dma->aiocb == NULL);
             }
-- 
1.9.1

  parent reply	other threads:[~2015-11-12 16:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-12 16:30 [Qemu-devel] [PATCH V4 0/6] ide: avoid main-loop hang on CDROM/NFS failure Peter Lieven
2015-11-12 16:30 ` [Qemu-devel] [PATCH V4 1/6] ide/atapi: make PIO read requests async Peter Lieven
2015-11-13 22:42   ` John Snow
2015-11-13 23:00     ` Peter Lieven
2015-11-12 16:30 ` [Qemu-devel] [PATCH V4 2/6] block: add blk_abort_aio_request Peter Lieven
2015-11-12 16:30 ` [Qemu-devel] [PATCH V4 3/6] ide: add support for IDEBufferedRequest Peter Lieven
2015-11-12 16:30 ` Peter Lieven [this message]
2015-11-12 16:30 ` [Qemu-devel] [PATCH V4 5/6] ide: enable buffered requests for ATAPI devices Peter Lieven
2015-11-12 16:30 ` [Qemu-devel] [PATCH V4 6/6] ide: enable buffered requests for PIO read requests Peter Lieven
2015-11-13 11:13 ` [Qemu-devel] [PATCH V4 0/6] ide: avoid main-loop hang on CDROM/NFS failure Mark Cave-Ayland
2015-11-13 17:18   ` John Snow
2015-11-13 22:44 ` John Snow
2015-11-16  6:17   ` Fam Zheng
2015-11-16  6:48     ` Peter Lieven
2015-11-16 19:24     ` John Snow
2015-11-17  4:17       ` Fam Zheng

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=1447345846-15624-5-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.