qemu-devel.nongnu.org archive mirror
 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 v2 4/8] linux-aio: Implement .cancel_async
Date: Tue, 26 Aug 2014 14:08:14 +0800	[thread overview]
Message-ID: <1409033298-5720-5-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1409033298-5720-1-git-send-email-famz@redhat.com>

Just call io_cancel (2), if it fails, it means the request is not
canceled, so the event loop will eventually call
qemu_laio_process_completion.

In qemu_laio_process_completion, change to call the cb unconditionally.
It is required by .cancel_async, and also acceptable by .cancel.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/linux-aio.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/block/linux-aio.c b/block/linux-aio.c
index 7ac7e8c..adf3b2e 100644
--- a/block/linux-aio.c
+++ b/block/linux-aio.c
@@ -79,9 +79,8 @@ static void qemu_laio_process_completion(struct qemu_laio_state *s,
                 ret = -EINVAL;
             }
         }
-
-        laiocb->common.cb(laiocb->common.opaque, ret);
     }
+    laiocb->common.cb(laiocb->common.opaque, ret);
 
     qemu_aio_release(laiocb);
 }
@@ -110,6 +109,22 @@ static void qemu_laio_completion_cb(EventNotifier *e)
     }
 }
 
+static void laio_cancel_async(BlockDriverAIOCB *blockacb)
+{
+    struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb;
+    struct io_event event;
+    int ret;
+
+    ret = io_cancel(laiocb->ctx->ctx, &laiocb->iocb, &event);
+    laiocb->ret = -ECANCELED;
+    if (!ret) {
+        /* iocb is not cancelled, cb will be called by the event loop later */
+        return;
+    }
+
+    laiocb->common.cb(laiocb->common.opaque, laiocb->ret);
+}
+
 static void laio_cancel(BlockDriverAIOCB *blockacb)
 {
     struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb;
@@ -145,6 +160,7 @@ static void laio_cancel(BlockDriverAIOCB *blockacb)
 static const AIOCBInfo laio_aiocb_info = {
     .aiocb_size         = sizeof(struct qemu_laiocb),
     .cancel             = laio_cancel,
+    .cancel_async       = laio_cancel_async,
 };
 
 static void ioq_init(LaioQueue *io_q)
-- 
2.1.0

  parent reply	other threads:[~2014-08-26  6:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26  6:08 [Qemu-devel] [RFC PATCH v2 0/8] block: Asynchronous request cancellation Fam Zheng
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 1/8] block: Add refcnt in BlockDriverAIOCB Fam Zheng
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 2/8] block: Add bdrv_aio_cancel_async Fam Zheng
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 3/8] tests: Add testing code for bdrv_aio_cancel_async Fam Zheng
2014-08-26  6:08 ` Fam Zheng [this message]
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 5/8] thread-pool: Implement .cancel_async Fam Zheng
2014-08-26  8:42   ` Paolo Bonzini
2014-08-26  9:26     ` Fam Zheng
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 6/8] dma: " Fam Zheng
2014-08-26  8:46   ` Paolo Bonzini
2014-08-26  9:21     ` Fam Zheng
2014-08-26  9:57       ` Paolo Bonzini
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 7/8] block: Implement bdrv_em_co_aiocb_info.cancel_async Fam Zheng
2014-08-26  6:08 ` [Qemu-devel] [RFC PATCH v2 8/8] iscsi: Implement .cancel_async in acb info 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=1409033298-5720-5-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 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).