All of lore.kernel.org
 help / color / mirror / Atom feed
From: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
To: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	sheepdog@lists.wpkg.org, Liu Yuan <namei.unix@gmail.com>
Subject: [Qemu-devel] [PATCH v3 09/10] sheepdog: cancel aio requests if possible
Date: Thu, 25 Jul 2013 17:32:04 +0900	[thread overview]
Message-ID: <1374741125-31859-10-git-send-email-morita.kazutaka@lab.ntt.co.jp> (raw)
In-Reply-To: <1374741125-31859-1-git-send-email-morita.kazutaka@lab.ntt.co.jp>

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 <morita.kazutaka@lab.ntt.co.jp>
---
 block/sheepdog.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 9f3fa89..7bf882a 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -294,7 +294,8 @@ struct SheepdogAIOCB {
     Coroutine *coroutine;
     void (*aio_done_func)(SheepdogAIOCB *);
 
-    bool canceled;
+    bool cancelable;
+    bool *finished;
     int nr_pending;
 };
 
@@ -411,6 +412,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);
 
@@ -419,23 +421,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 false;
+}
+
 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 = {
@@ -456,7 +503,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.3.566.gaa39828

  parent reply	other threads:[~2013-07-25  8:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25  8:31 [Qemu-devel] [PATCH v3 00/10] sheepdog: reconnect server after connection failure MORITA Kazutaka
2013-07-25  8:31 ` [Qemu-devel] [PATCH v3 01/10] ignore SIGPIPE in qemu-img and qemu-io MORITA Kazutaka
2013-07-25  8:31 ` [Qemu-devel] [PATCH v3 02/10] iov: handle EOF in iov_send_recv MORITA Kazutaka
2013-07-25  8:31 ` [Qemu-devel] [PATCH v3 03/10] sheepdog: check return values of qemu_co_recv/send correctly MORITA Kazutaka
2013-07-25  8:46   ` Liu Yuan
2013-07-25  8:53     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-07-25  8:56     ` [Qemu-devel] " Liu Yuan
2013-07-25  8:31 ` [Qemu-devel] [PATCH v3 04/10] sheepdog: handle vdi objects in resend_aio_req MORITA Kazutaka
2013-07-25  8:32 ` [Qemu-devel] [PATCH v3 05/10] sheepdog: reload inode outside of resend_aioreq MORITA Kazutaka
2013-07-25  8:32 ` [Qemu-devel] [PATCH v3 06/10] coroutine: add co_aio_sleep_ns() to allow sleep in block drivers MORITA Kazutaka
2013-07-25  8:32 ` [Qemu-devel] [PATCH v3 07/10] sheepdog: try to reconnect to sheepdog after network error MORITA Kazutaka
2013-07-25  9:13   ` Liu Yuan
2013-07-25 12:53     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-07-25 13:20       ` Liu Yuan
2013-07-26  5:53         ` MORITA Kazutaka
2013-07-25  8:32 ` [Qemu-devel] [PATCH v3 08/10] sheepdog: make add_aio_request and send_aioreq void functions MORITA Kazutaka
2013-07-25  8:32 ` MORITA Kazutaka [this message]
2013-07-25  9:04   ` [Qemu-devel] [PATCH v3 09/10] sheepdog: cancel aio requests if possible Liu Yuan
2013-07-25 12:54     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-07-25  8:32 ` [Qemu-devel] [PATCH v3 10/10] sheepdog: check simultaneous create in resend_aioreq MORITA Kazutaka

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=1374741125-31859-10-git-send-email-morita.kazutaka@lab.ntt.co.jp \
    --to=morita.kazutaka@lab.ntt.co.jp \
    --cc=kwolf@redhat.com \
    --cc=namei.unix@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sheepdog@lists.wpkg.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.