All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [RFC PATCH 7/9] dma: Implement .cancel_async
Date: Thu, 21 Aug 2014 19:56:54 +0800	[thread overview]
Message-ID: <1408622216-9578-8-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1408622216-9578-1-git-send-email-famz@redhat.com>

Just forward the request to bdrv_aio_cancel_async. Use a flag to fix the
ret value in completion code. Also check memory address before calling
dma_memory_unmap.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 dma-helpers.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/dma-helpers.c b/dma-helpers.c
index 499b52b..4a03e18 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -74,6 +74,7 @@ typedef struct {
     uint64_t sector_num;
     DMADirection dir;
     bool in_cancel;
+    bool cancelled;
     int sg_cur_index;
     dma_addr_t sg_cur_byte;
     QEMUIOVector iov;
@@ -105,6 +106,9 @@ static void dma_bdrv_unmap(DMAAIOCB *dbs)
     int i;
 
     for (i = 0; i < dbs->iov.niov; ++i) {
+        if (!(dbs->iov.iov[i].iov_base && dbs->iov.iov[i].iov_len)) {
+            break;
+        }
         dma_memory_unmap(dbs->sg->as, dbs->iov.iov[i].iov_base,
                          dbs->iov.iov[i].iov_len, dbs->dir,
                          dbs->iov.iov[i].iov_len);
@@ -116,6 +120,9 @@ static void dma_complete(DMAAIOCB *dbs, int ret)
 {
     trace_dma_complete(dbs, ret, dbs->common.cb);
 
+    if (dbs->cancelled) {
+        ret = -ECANCELED;
+    }
     dma_bdrv_unmap(dbs);
     if (dbs->common.cb) {
         dbs->common.cb(dbs->common.opaque, ret);
@@ -141,6 +148,9 @@ static void dma_bdrv_cb(void *opaque, int ret)
 
     trace_dma_bdrv_cb(dbs, ret);
 
+    if (dbs->cancelled) {
+        ret = -ECANCELED;
+    }
     dbs->acb = NULL;
     dbs->sector_num += dbs->iov.size / 512;
 
@@ -185,6 +195,7 @@ static void dma_aio_cancel(BlockDriverAIOCB *acb)
 
     trace_dma_aio_cancel(dbs);
 
+    dbs->cancelled = true;
     if (dbs->acb) {
         BlockDriverAIOCB *acb = dbs->acb;
         dbs->acb = NULL;
@@ -196,9 +207,25 @@ static void dma_aio_cancel(BlockDriverAIOCB *acb)
     dma_complete(dbs, 0);
 }
 
+static void dma_aio_cancel_async(BlockDriverAIOCB *acb)
+{
+    DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common);
+
+    trace_dma_aio_cancel(dbs);
+
+    dbs->cancelled = true;
+    if (dbs->acb) {
+        acb = dbs->acb;
+        dbs->acb = NULL;
+        bdrv_aio_cancel_async(acb);
+    }
+}
+
+
 static const AIOCBInfo dma_aiocb_info = {
     .aiocb_size         = sizeof(DMAAIOCB),
     .cancel             = dma_aio_cancel,
+    .cancel_async       = dma_aio_cancel_async,
 };
 
 BlockDriverAIOCB *dma_bdrv_io(
@@ -218,6 +245,7 @@ BlockDriverAIOCB *dma_bdrv_io(
     dbs->sg_cur_byte = 0;
     dbs->dir = dir;
     dbs->in_cancel = false;
+    dbs->cancelled = false;
     dbs->io_func = io_func;
     dbs->bh = NULL;
     qemu_iovec_init(&dbs->iov, sg->nsg);
-- 
2.0.3

  parent reply	other threads:[~2014-08-21 11:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-21 11:56 [Qemu-devel] [RFC PATCH 0/9] scsi, block: Asynchronous request cancellation Fam Zheng
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 1/9] block: Add bdrv_aio_cancel_async Fam Zheng
2014-08-21 12:14   ` Paolo Bonzini
2014-08-22  1:23     ` Fam Zheng
2014-08-22  8:14       ` Paolo Bonzini
2014-08-22  9:37         ` Fam Zheng
2014-08-22 10:10           ` Paolo Bonzini
2014-08-22 10:51             ` Fam Zheng
2014-08-21 13:44   ` Stefan Hajnoczi
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 2/9] tests: Add testing code for bdrv_aio_cancel_async Fam Zheng
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 3/9] iscsi: Implement .cancel_async in acb info Fam Zheng
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 4/9] linux-aio: Implement .cancel_async Fam Zheng
2014-08-21 16:31   ` Stefan Hajnoczi
2014-08-22  4:56     ` Fam Zheng
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 5/9] thread-pool: " Fam Zheng
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 6/9] blkdebug: " Fam Zheng
2014-08-21 16:52   ` Stefan Hajnoczi
2014-08-22  4:29     ` Fam Zheng
2014-08-21 11:56 ` Fam Zheng [this message]
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 8/9] block: Implement stub bdrv_em_co_aiocb_info.cancel_async Fam Zheng
2014-08-21 17:01   ` Stefan Hajnoczi
2014-08-22  4:28     ` Fam Zheng
2014-08-21 11:56 ` [Qemu-devel] [RFC PATCH 9/9] scsi: Cancel request asynchronously Fam Zheng
2014-08-21 12:19   ` Paolo Bonzini
2014-08-22  4:57     ` 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=1408622216-9578-8-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --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 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.