[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 26/30] sheepdog: cancel aio requests if possible
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 26/30] sheepdog: cancel aio requests if possible |
Date: |
Thu, 31 Oct 2013 16:48:40 +0100 |
From: MORITA Kazutaka <address@hidden>
This patch tries to cancel aio requests in pending queue and failed
queue. When the sheepdog driver cannot cancel the requests, it waits
for them to be completed.
Signed-off-by: MORITA Kazutaka <address@hidden>
Tested-by: Liu Yuan <address@hidden>
Reviewed-by: Liu Yuan <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/sheepdog.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 59 insertions(+), 11 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 8790494..eebb5fe 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -299,7 +299,8 @@ struct SheepdogAIOCB {
Coroutine *coroutine;
void (*aio_done_func)(SheepdogAIOCB *);
- bool canceled;
+ bool cancelable;
+ bool *finished;
int nr_pending;
};
@@ -418,6 +419,7 @@ static inline void free_aio_req(BDRVSheepdogState *s,
AIOReq *aio_req)
{
SheepdogAIOCB *acb = aio_req->aiocb;
+ acb->cancelable = false;
QLIST_REMOVE(aio_req, aio_siblings);
g_free(aio_req);
@@ -426,23 +428,68 @@ static inline void free_aio_req(BDRVSheepdogState *s,
AIOReq *aio_req)
static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb)
{
- if (!acb->canceled) {
- qemu_coroutine_enter(acb->coroutine, NULL);
+ qemu_coroutine_enter(acb->coroutine, NULL);
+ if (acb->finished) {
+ *acb->finished = true;
}
qemu_aio_release(acb);
}
+/*
+ * Check whether the specified acb can be canceled
+ *
+ * We can cancel aio when any request belonging to the acb is:
+ * - Not processed by the sheepdog server.
+ * - Not linked to the inflight queue.
+ */
+static bool sd_acb_cancelable(const SheepdogAIOCB *acb)
+{
+ BDRVSheepdogState *s = acb->common.bs->opaque;
+ AIOReq *aioreq;
+
+ if (!acb->cancelable) {
+ return false;
+ }
+
+ QLIST_FOREACH(aioreq, &s->inflight_aio_head, aio_siblings) {
+ if (aioreq->aiocb == acb) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static void sd_aio_cancel(BlockDriverAIOCB *blockacb)
{
SheepdogAIOCB *acb = (SheepdogAIOCB *)blockacb;
+ BDRVSheepdogState *s = acb->common.bs->opaque;
+ AIOReq *aioreq, *next;
+ bool finished = false;
+
+ acb->finished = &finished;
+ while (!finished) {
+ if (sd_acb_cancelable(acb)) {
+ /* Remove outstanding requests from pending and failed queues. */
+ QLIST_FOREACH_SAFE(aioreq, &s->pending_aio_head, aio_siblings,
+ next) {
+ if (aioreq->aiocb == acb) {
+ free_aio_req(s, aioreq);
+ }
+ }
+ QLIST_FOREACH_SAFE(aioreq, &s->failed_aio_head, aio_siblings,
+ next) {
+ if (aioreq->aiocb == acb) {
+ free_aio_req(s, aioreq);
+ }
+ }
- /*
- * Sheepdog cannot cancel the requests which are already sent to
- * the servers, so we just complete the request with -EIO here.
- */
- acb->ret = -EIO;
- qemu_coroutine_enter(acb->coroutine, NULL);
- acb->canceled = true;
+ assert(acb->nr_pending == 0);
+ sd_finish_aiocb(acb);
+ return;
+ }
+ qemu_aio_wait();
+ }
}
static const AIOCBInfo sd_aiocb_info = {
@@ -463,7 +510,8 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs,
QEMUIOVector *qiov,
acb->nb_sectors = nb_sectors;
acb->aio_done_func = NULL;
- acb->canceled = false;
+ acb->cancelable = true;
+ acb->finished = NULL;
acb->coroutine = qemu_coroutine_self();
acb->ret = 0;
acb->nr_pending = 0;
--
1.8.1.4
- [Qemu-devel] [PULL 17/30] qemu-iotests: Fix 051 reference output, (continued)
- [Qemu-devel] [PULL 17/30] qemu-iotests: Fix 051 reference output, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 18/30] qemu-iotests: drop duplicated "create_image", Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 19/30] qemu-iotests: Test case for backing file deletion, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 20/30] sheepdog: check return values of qemu_co_recv/send correctly, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 21/30] sheepdog: handle vdi objects in resend_aio_req, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 22/30] sheepdog: reload inode outside of resend_aioreq, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 23/30] coroutine: add co_aio_sleep_ns() to allow sleep in block drivers, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 24/30] sheepdog: try to reconnect to sheepdog after network error, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 25/30] sheepdog: make add_aio_request and send_aioreq void functions, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 27/30] sheepdog: check simultaneous create in resend_aioreq, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 26/30] sheepdog: cancel aio requests if possible,
Kevin Wolf <=
- [Qemu-devel] [PULL 28/30] qemu-iotests: prefill some data to test image, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 29/30] qapi: Add optional field 'compressed' to ImageInfo, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 30/30] vmdk: Implment bdrv_get_specific_info, Kevin Wolf, 2013/10/31
- Re: [Qemu-devel] [PULL v2 00/30] Block patches, Anthony Liguori, 2013/10/31