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 1/9] block: Add bdrv_aio_cancel_async
Date: Thu, 21 Aug 2014 19:56:48 +0800 [thread overview]
Message-ID: <1408622216-9578-2-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1408622216-9578-1-git-send-email-famz@redhat.com>
This is the async version of bdrv_aio_cancel, which doesn't block the
caller. It guarantees that the cb is called either before returning or
some time later.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block.c | 35 +++++++++++++++++++++++++++++++++++
include/block/aio.h | 2 ++
include/block/block.h | 1 +
3 files changed, 38 insertions(+)
diff --git a/block.c b/block.c
index 6fa0201..1cc8926 100644
--- a/block.c
+++ b/block.c
@@ -4607,6 +4607,41 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb)
acb->aiocb_info->cancel(acb);
}
+static void bdrv_aio_cancel_async_cb(void *opaque, int ret)
+{
+ BlockDriverAIOCB *acb = opaque;
+
+ acb->cb = acb->cancel_acb_save->cb;
+ acb->opaque = acb->cancel_acb_save->opaque;
+ g_free(acb->cancel_acb_save);
+ acb->cancel_acb_save = NULL;
+ acb->cb(acb->opaque, -ECANCELED);
+}
+
+/* Async version of aio cancel. The caller is not blocked if the acb implements
+ * cancel_async, otherwise fall back to bdrv_aio_cancel. In both cases, acb->cb
+ * is guarenteed to be called, before or after function returns. */
+void bdrv_aio_cancel_async(BlockDriverAIOCB *acb)
+{
+ if (acb->aiocb_info->cancel_async) {
+ acb->aiocb_info->cancel_async(acb);
+ } else {
+ BlockDriverAIOCB *save = g_new(BlockDriverAIOCB, 1);
+ save->cb = acb->cb;
+ save->opaque = acb->opaque;
+ acb->cb = bdrv_aio_cancel_async_cb;
+ acb->opaque = acb;
+ acb->cancel_acb_save = save;
+
+ /* Use the synchronous version and hope our cb is called. */
+ acb->aiocb_info->cancel(acb);
+ if (acb->cancel_acb_save) {
+ /* cb is not called yet, let's call it */
+ bdrv_aio_cancel_async_cb(acb->opaque, -ECANCELED);
+ }
+ }
+}
+
/**************************************************************/
/* async block device emulation */
diff --git a/include/block/aio.h b/include/block/aio.h
index c23de3c..fcc5c87 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -27,6 +27,7 @@ typedef void BlockDriverCompletionFunc(void *opaque, int ret);
typedef struct AIOCBInfo {
void (*cancel)(BlockDriverAIOCB *acb);
+ void (*cancel_async)(BlockDriverAIOCB *acb);
size_t aiocb_size;
} AIOCBInfo;
@@ -35,6 +36,7 @@ struct BlockDriverAIOCB {
BlockDriverState *bs;
BlockDriverCompletionFunc *cb;
void *opaque;
+ BlockDriverAIOCB *cancel_acb_save;
};
void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs,
diff --git a/include/block/block.h b/include/block/block.h
index e94b701..ed2a3a8 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -335,6 +335,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
int64_t sector_num, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque);
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
+void bdrv_aio_cancel_async(BlockDriverAIOCB *acb);
typedef struct BlockRequest {
/* Fields to be filled by multiwrite caller */
--
2.0.3
next prev parent reply other threads:[~2014-08-21 11:56 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 ` Fam Zheng [this message]
2014-08-21 12:14 ` [Qemu-devel] [RFC PATCH 1/9] block: Add bdrv_aio_cancel_async 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 ` [Qemu-devel] [RFC PATCH 7/9] dma: " Fam Zheng
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-2-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).