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 10/10] sheepdog: check simultaneous create in resend_aioreq
Date: Thu, 25 Jul 2013 17:32:05 +0900	[thread overview]
Message-ID: <1374741125-31859-11-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>

After reconnection happens, all the inflight requests are moved to the
failed request list.  As a result, sd_co_rw_vector() can send another
create request before resend_aioreq() resends a create request from
the failed list.

This patch adds a helper function check_simultaneous_create() and
checks simultaneous create requests more strictly in resend_aioreq().

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
---
 block/sheepdog.c | 64 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 7bf882a..46821df 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1292,6 +1292,29 @@ out:
     return ret;
 }
 
+/* Return true if the specified request is linked to the pending list. */
+static bool check_simultaneous_create(BDRVSheepdogState *s, AIOReq *aio_req)
+{
+    AIOReq *areq;
+    QLIST_FOREACH(areq, &s->inflight_aio_head, aio_siblings) {
+        if (areq != aio_req && areq->oid == aio_req->oid) {
+            /*
+             * Sheepdog cannot handle simultaneous create requests to the same
+             * object, so we cannot send the request until the previous request
+             * finishes.
+             */
+            dprintf("simultaneous create to %" PRIx64 "\n", aio_req->oid);
+            aio_req->flags = 0;
+            aio_req->base_oid = 0;
+            QLIST_REMOVE(aio_req, aio_siblings);
+            QLIST_INSERT_HEAD(&s->pending_aio_head, aio_req, aio_siblings);
+            return true;
+        }
+    }
+
+    return false;
+}
+
 static void coroutine_fn resend_aioreq(BDRVSheepdogState *s, AIOReq *aio_req)
 {
     SheepdogAIOCB *acb = aio_req->aiocb;
@@ -1300,29 +1323,19 @@ static void coroutine_fn resend_aioreq(BDRVSheepdogState *s, AIOReq *aio_req)
     /* check whether this request becomes a CoW one */
     if (acb->aiocb_type == AIOCB_WRITE_UDATA && is_data_obj(aio_req->oid)) {
         int idx = data_oid_to_idx(aio_req->oid);
-        AIOReq *areq;
 
-        if (s->inode.data_vdi_id[idx] == 0) {
-            create = true;
-            goto out;
-        }
         if (is_data_obj_writable(&s->inode, idx)) {
             goto out;
         }
 
-        /* link to the pending list if there is another CoW request to
-         * the same object */
-        QLIST_FOREACH(areq, &s->inflight_aio_head, aio_siblings) {
-            if (areq != aio_req && areq->oid == aio_req->oid) {
-                dprintf("simultaneous CoW to %" PRIx64 "\n", aio_req->oid);
-                QLIST_REMOVE(aio_req, aio_siblings);
-                QLIST_INSERT_HEAD(&s->pending_aio_head, aio_req, aio_siblings);
-                return;
-            }
+        if (check_simultaneous_create(s, aio_req)) {
+            return;
         }
 
-        aio_req->base_oid = vid_to_data_oid(s->inode.data_vdi_id[idx], idx);
-        aio_req->flags |= SD_FLAG_CMD_COW;
+        if (s->inode.data_vdi_id[idx]) {
+            aio_req->base_oid = vid_to_data_oid(s->inode.data_vdi_id[idx], idx);
+            aio_req->flags |= SD_FLAG_CMD_COW;
+        }
         create = true;
     }
 out:
@@ -1936,27 +1949,14 @@ static int coroutine_fn sd_co_rw_vector(void *p)
         }
 
         aio_req = alloc_aio_req(s, acb, oid, len, offset, flags, old_oid, done);
+        QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
 
         if (create) {
-            AIOReq *areq;
-            QLIST_FOREACH(areq, &s->inflight_aio_head, aio_siblings) {
-                if (areq->oid == oid) {
-                    /*
-                     * Sheepdog cannot handle simultaneous create
-                     * requests to the same object.  So we cannot send
-                     * the request until the previous request
-                     * finishes.
-                     */
-                    aio_req->flags = 0;
-                    aio_req->base_oid = 0;
-                    QLIST_INSERT_HEAD(&s->pending_aio_head, aio_req,
-                                      aio_siblings);
-                    goto done;
-                }
+            if (check_simultaneous_create(s, aio_req)) {
+                goto done;
             }
         }
 
-        QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
         add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov, create,
                         acb->aiocb_type);
     done:
-- 
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 ` [Qemu-devel] [PATCH v3 09/10] sheepdog: cancel aio requests if possible MORITA Kazutaka
2013-07-25  9:04   ` Liu Yuan
2013-07-25 12:54     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-07-25  8:32 ` MORITA Kazutaka [this message]

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-11-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.