All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, pbonzini@redhat.com,
	stefanha@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 27/29] qed: Simplify request handling
Date: Fri, 26 May 2017 22:22:08 +0200	[thread overview]
Message-ID: <1495830130-30611-28-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1495830130-30611-1-git-send-email-kwolf@redhat.com>

Now that we process a request in the same coroutine from beginning to
end and don't drop out of it any more, we can look like a proper
coroutine-based driver and simply call qed_aio_next_io() and get a
return value from it instead of spawning an additional coroutine that
reenters the parent when it's done.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qed.c | 106 ++++++++++++++++--------------------------------------------
 block/qed.h |   3 +-
 2 files changed, 28 insertions(+), 81 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index 2eee451..d3f7d0c 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -21,10 +21,6 @@
 #include "qapi/qmp/qerror.h"
 #include "sysemu/block-backend.h"
 
-static const AIOCBInfo qed_aiocb_info = {
-    .aiocb_size         = sizeof(QEDAIOCB),
-};
-
 static int bdrv_qed_probe(const uint8_t *buf, int buf_size,
                           const char *filename)
 {
@@ -253,13 +249,6 @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *s)
     return l2_table;
 }
 
-static void qed_aio_next_io(QEDAIOCB *acb);
-
-static void qed_aio_start_io(QEDAIOCB *acb)
-{
-    qed_aio_next_io(acb);
-}
-
 static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
 {
     assert(!s->allocating_write_reqs_plugged);
@@ -751,7 +740,7 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs,
 
 static BDRVQEDState *acb_to_s(QEDAIOCB *acb)
 {
-    return acb->common.bs->opaque;
+    return acb->bs->opaque;
 }
 
 /**
@@ -888,27 +877,9 @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int index,
     }
 }
 
-static void qed_aio_complete_bh(void *opaque)
+static void qed_aio_complete(QEDAIOCB *acb)
 {
-    QEDAIOCB *acb = opaque;
     BDRVQEDState *s = acb_to_s(acb);
-    BlockCompletionFunc *cb = acb->common.cb;
-    void *user_opaque = acb->common.opaque;
-    int ret = acb->bh_ret;
-
-    qemu_aio_unref(acb);
-
-    /* Invoke callback */
-    qed_acquire(s);
-    cb(user_opaque, ret);
-    qed_release(s);
-}
-
-static void qed_aio_complete(QEDAIOCB *acb, int ret)
-{
-    BDRVQEDState *s = acb_to_s(acb);
-
-    trace_qed_aio_complete(s, acb, ret);
 
     /* Free resources */
     qemu_iovec_destroy(&acb->cur_qiov);
@@ -920,11 +891,6 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
         acb->qiov->iov[0].iov_base = NULL;
     }
 
-    /* Arrange for a bh to invoke the completion function */
-    acb->bh_ret = ret;
-    aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
-                            qed_aio_complete_bh, acb);
-
     /* Start next allocating write request waiting behind this one.  Note that
      * requests enqueue themselves when they first hit an unallocated cluster
      * but they wait until the entire request is finished before waking up the
@@ -1172,7 +1138,7 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
         struct iovec *iov = acb->qiov->iov;
 
         if (!iov->iov_base) {
-            iov->iov_base = qemu_try_blockalign(acb->common.bs, iov->iov_len);
+            iov->iov_base = qemu_try_blockalign(acb->bs, iov->iov_len);
             if (iov->iov_base == NULL) {
                 return -ENOMEM;
             }
@@ -1235,7 +1201,7 @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
 {
     QEDAIOCB *acb = opaque;
     BDRVQEDState *s = acb_to_s(acb);
-    BlockDriverState *bs = acb->common.bs;
+    BlockDriverState *bs = acb->bs;
 
     /* Adjust offset into cluster */
     offset += qed_offset_into_cluster(s, acb->cur_pos);
@@ -1264,7 +1230,7 @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
 /**
  * Begin next I/O or complete the request
  */
-static void qed_aio_next_io(QEDAIOCB *acb)
+static int qed_aio_next_io(QEDAIOCB *acb)
 {
     BDRVQEDState *s = acb_to_s(acb);
     uint64_t offset;
@@ -1286,16 +1252,15 @@ static void qed_aio_next_io(QEDAIOCB *acb)
 
         /* Complete request */
         if (acb->cur_pos >= acb->end_pos) {
-            qed_aio_complete(acb, 0);
-            return;
+            ret = 0;
+            break;
         }
 
         /* Find next cluster and start I/O */
         len = acb->end_pos - acb->cur_pos;
         ret = qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &offset);
         if (ret < 0) {
-            qed_aio_complete(acb, ret);
-            return;
+            break;
         }
 
         if (acb->flags & QED_AIOCB_WRITE) {
@@ -1305,55 +1270,38 @@ static void qed_aio_next_io(QEDAIOCB *acb)
         }
 
         if (ret < 0 && ret != -EAGAIN) {
-            qed_aio_complete(acb, ret);
-            return;
+            break;
         }
     }
-}
-
-typedef struct QEDRequestCo {
-    Coroutine *co;
-    bool done;
-    int ret;
-} QEDRequestCo;
 
-static void coroutine_fn qed_co_request_cb(void *opaque, int ret)
-{
-    QEDRequestCo *co = opaque;
-
-    co->done = true;
-    co->ret = ret;
-    qemu_coroutine_enter_if_inactive(co->co);
+    trace_qed_aio_complete(s, acb, ret);
+    qed_aio_complete(acb);
+    return ret;
 }
 
 static int qed_co_request(BlockDriverState *bs, int64_t sector_num,
                           QEMUIOVector *qiov, int nb_sectors, int flags)
 {
-    QEDRequestCo co = {
-        .co     = qemu_coroutine_self(),
-        .done   = false,
-    };
-    QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, qed_co_request_cb, &co);
-
-    trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flags);
+    QEDAIOCB *acb;
+    int ret;
 
-    acb->flags = flags;
-    acb->qiov = qiov;
-    acb->qiov_offset = 0;
-    acb->cur_pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE;
-    acb->end_pos = acb->cur_pos + nb_sectors * BDRV_SECTOR_SIZE;
-    acb->backing_qiov = NULL;
-    acb->request.l2_table = NULL;
+    acb = g_new(QEDAIOCB, 1);
+    *acb = (QEDAIOCB) {
+        .bs         = bs,
+        .cur_pos    = (uint64_t) sector_num * BDRV_SECTOR_SIZE,
+        .end_pos    = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE,
+        .qiov       = qiov,
+        .flags      = flags,
+    };
     qemu_iovec_init(&acb->cur_qiov, qiov->niov);
 
-    /* Start request */
-    qed_aio_start_io(acb);
+    trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, NULL, flags);
 
-    if (!co.done) {
-        qemu_coroutine_yield();
-    }
+    /* Start request */
+    ret = qed_aio_next_io(acb);
 
-    return co.ret;
+    g_free(acb);
+    return ret;
 }
 
 static int bdrv_qed_co_readv(BlockDriverState *bs, int64_t sector_num,
diff --git a/block/qed.h b/block/qed.h
index 37558e4..fb80943 100644
--- a/block/qed.h
+++ b/block/qed.h
@@ -129,8 +129,7 @@ enum {
 };
 
 typedef struct QEDAIOCB {
-    BlockAIOCB common;
-    int bh_ret;                     /* final return status for completion bh */
+    BlockDriverState *bs;
     QSIMPLEQ_ENTRY(QEDAIOCB) next;  /* next request */
     int flags;                      /* QED_AIOCB_* bits ORed together */
     uint64_t end_pos;               /* request end on block device, in bytes */
-- 
1.8.3.1

  parent reply	other threads:[~2017-05-26 20:23 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 20:21 [Qemu-devel] [PATCH 00/29] qed: Convert to coroutines Kevin Wolf
2017-05-26 20:21 ` [Qemu-devel] [PATCH 01/29] qed: Use bottom half to resume waiting requests Kevin Wolf
2017-05-26 20:40   ` Eric Blake
2017-05-31 12:16   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 02/29] qed: Make qed_read_table() synchronous Kevin Wolf
2017-05-26 21:04   ` Eric Blake
2017-05-31 12:16   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 03/29] qed: Remove callback from qed_read_table() Kevin Wolf
2017-05-26 21:10   ` Eric Blake
2017-05-31 12:18   ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 04/29] qed: Remove callback from qed_read_l2_table() Kevin Wolf
2017-05-26 21:16   ` Eric Blake
2017-05-31 12:20   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 05/29] qed: Remove callback from qed_find_cluster() Kevin Wolf
2017-05-26 21:31   ` Eric Blake
2017-05-31 12:24   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 06/29] qed: Make qed_read_backing_file() synchronous Kevin Wolf
2017-05-26 21:33   ` Eric Blake
2017-05-31 12:25   ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 07/29] qed: Make qed_copy_from_backing_file() synchronous Kevin Wolf
2017-05-26 21:41   ` Eric Blake
2017-05-31 12:26   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 08/29] qed: Remove callback from qed_copy_from_backing_file() Kevin Wolf
2017-05-26 21:51   ` Eric Blake
2017-05-31 12:29   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 09/29] qed: Make qed_write_header() synchronous Kevin Wolf
2017-05-26 21:53   ` Eric Blake
2017-05-31 12:30   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 10/29] qed: Remove callback from qed_write_header() Kevin Wolf
2017-05-31 12:32   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-06-01 15:59     ` Kevin Wolf
2017-06-01 16:04       ` Paolo Bonzini
2017-06-02 16:03         ` Stefan Hajnoczi
2017-06-02 16:04       ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 11/29] qed: Make qed_write_table() synchronous Kevin Wolf
2017-05-31 12:35   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 12/29] qed: Remove GenericCB Kevin Wolf
2017-05-31 12:35   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 13/29] qed: Remove callback from qed_write_table() Kevin Wolf
2017-05-31 12:36   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 14/29] qed: Make qed_aio_read_data() synchronous Kevin Wolf
2017-05-31 12:36   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 15/29] qed: Make qed_aio_write_main() synchronous Kevin Wolf
2017-05-31 12:38   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 16/29] qed: Inline qed_commit_l2_update() Kevin Wolf
2017-05-31 12:38   ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 17/29] qed: Add return value to qed_aio_write_l1_update() Kevin Wolf
2017-05-31 12:40   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 18/29] qed: Add return value to qed_aio_write_l2_update() Kevin Wolf
2017-05-31 12:40   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 19/29] qed: Add return value to qed_aio_write_main() Kevin Wolf
2017-05-31 12:41   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 20/29] qed: Add return value to qed_aio_write_cow() Kevin Wolf
2017-05-31 12:42   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 21/29] qed: Add return value to qed_aio_write_inplace/alloc() Kevin Wolf
2017-05-31 12:43   ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 22/29] qed: Add return value to qed_aio_read/write_data() Kevin Wolf
2017-05-31 12:45   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 23/29] qed: Remove ret argument from qed_aio_next_io() Kevin Wolf
2017-05-31 12:45   ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 24/29] qed: Remove recursion in qed_aio_next_io() Kevin Wolf
2017-05-31 12:46   ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 25/29] qed: Implement .bdrv_co_readv/writev Kevin Wolf
2017-05-31 12:49   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 26/29] qed: Use CoQueue for serialising allocations Kevin Wolf
2017-05-31 12:53   ` Stefan Hajnoczi
2017-05-26 20:22 ` Kevin Wolf [this message]
2017-05-31 12:54   ` [Qemu-devel] [PATCH 27/29] qed: Simplify request handling Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 28/29] qed: Use a coroutine for need_check_timer Kevin Wolf
2017-05-31 12:56   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 29/29] block: Remove bdrv_aio_readv/writev_flush() Kevin Wolf
2017-05-31 12:57   ` Stefan Hajnoczi
2017-05-29 11:22 ` [Qemu-devel] [Qemu-block] [PATCH 00/29] qed: Convert to coroutines Paolo Bonzini
2017-06-01 16:28   ` Kevin Wolf
2017-06-01 16:40     ` Paolo Bonzini
2017-06-01 17:08       ` Kevin Wolf
2017-06-02  8:06         ` Paolo Bonzini

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=1495830130-30611-28-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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 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.