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 22/29] qed: Add return value to qed_aio_read/write_data()
Date: Fri, 26 May 2017 22:22:03 +0200	[thread overview]
Message-ID: <1495830130-30611-23-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1495830130-30611-1-git-send-email-kwolf@redhat.com>

Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but
just return an error code and let the caller handle it.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qed.c | 72 ++++++++++++++++++++++++++-----------------------------------
 block/qed.h | 21 ------------------
 2 files changed, 31 insertions(+), 62 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index 7880df8..3a26fdf 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1205,15 +1205,14 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
  * Write data cluster
  *
  * @opaque:     Write request
- * @ret:        QED_CLUSTER_FOUND, QED_CLUSTER_L2, QED_CLUSTER_L1,
- *              or -errno
+ * @ret:        QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1
  * @offset:     Cluster offset in bytes
  * @len:        Length in bytes
  *
  * Callback from qed_find_cluster().
  */
-static void qed_aio_write_data(void *opaque, int ret,
-                               uint64_t offset, size_t len)
+static int qed_aio_write_data(void *opaque, int ret,
+                              uint64_t offset, size_t len)
 {
     QEDAIOCB *acb = opaque;
 
@@ -1223,42 +1222,29 @@ static void qed_aio_write_data(void *opaque, int ret,
 
     switch (ret) {
     case QED_CLUSTER_FOUND:
-        ret = qed_aio_write_inplace(acb, offset, len);
-        break;
+        return qed_aio_write_inplace(acb, offset, len);
 
     case QED_CLUSTER_L2:
     case QED_CLUSTER_L1:
     case QED_CLUSTER_ZERO:
-        ret = qed_aio_write_alloc(acb, len);
-        break;
+        return qed_aio_write_alloc(acb, len);
 
     default:
-        assert(ret < 0);
-        break;
-    }
-
-    if (ret < 0) {
-        if (ret != -EINPROGRESS) {
-            qed_aio_complete(acb, ret);
-        }
-        return;
+        g_assert_not_reached();
     }
-    qed_aio_next_io(acb, 0);
 }
 
 /**
  * Read data cluster
  *
  * @opaque:     Read request
- * @ret:        QED_CLUSTER_FOUND, QED_CLUSTER_L2, QED_CLUSTER_L1,
- *              or -errno
+ * @ret:        QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1
  * @offset:     Cluster offset in bytes
  * @len:        Length in bytes
  *
  * Callback from qed_find_cluster().
  */
-static void qed_aio_read_data(void *opaque, int ret,
-                              uint64_t offset, size_t len)
+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);
@@ -1269,34 +1255,23 @@ static void qed_aio_read_data(void *opaque, int ret,
 
     trace_qed_aio_read_data(s, acb, ret, offset, len);
 
-    if (ret < 0) {
-        goto err;
-    }
-
     qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len);
 
     /* Handle zero cluster and backing file reads */
     if (ret == QED_CLUSTER_ZERO) {
         qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size);
-        qed_aio_start_io(acb);
-        return;
+        return 0;
     } else if (ret != QED_CLUSTER_FOUND) {
-        ret = qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov,
-                                    &acb->backing_qiov);
-        qed_aio_next_io(acb, ret);
-        return;
+        return qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov,
+                                     &acb->backing_qiov);
     }
 
     BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
     ret = bdrv_preadv(bs->file, offset, &acb->cur_qiov);
     if (ret < 0) {
-        goto err;
+        return ret;
     }
-    qed_aio_next_io(acb, 0);
-    return;
-
-err:
-    qed_aio_complete(acb, ret);
+    return 0;
 }
 
 /**
@@ -1305,8 +1280,6 @@ err:
 static void qed_aio_next_io(QEDAIOCB *acb, int ret)
 {
     BDRVQEDState *s = acb_to_s(acb);
-    QEDFindClusterFunc *io_fn = (acb->flags & QED_AIOCB_WRITE) ?
-                                qed_aio_write_data : qed_aio_read_data;
     uint64_t offset;
     size_t len;
 
@@ -1337,7 +1310,24 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
     /* 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);
-    io_fn(acb, ret, offset, len);
+    if (ret < 0) {
+        qed_aio_complete(acb, ret);
+        return;
+    }
+
+    if (acb->flags & QED_AIOCB_WRITE) {
+        ret = qed_aio_write_data(acb, ret, offset, len);
+    } else {
+        ret = qed_aio_read_data(acb, ret, offset, len);
+    }
+
+    if (ret < 0) {
+        if (ret != -EINPROGRESS) {
+            qed_aio_complete(acb, ret);
+        }
+        return;
+    }
+    qed_aio_next_io(acb, 0);
 }
 
 static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
diff --git a/block/qed.h b/block/qed.h
index 51443fa..8644fed 100644
--- a/block/qed.h
+++ b/block/qed.h
@@ -177,27 +177,6 @@ enum {
     QED_CLUSTER_L1,            /* cluster missing in L1 */
 };
 
-/**
- * qed_find_cluster() completion callback
- *
- * @opaque:     User data for completion callback
- * @ret:        QED_CLUSTER_FOUND   Success
- *              QED_CLUSTER_L2      Data cluster unallocated in L2
- *              QED_CLUSTER_L1      L2 unallocated in L1
- *              -errno              POSIX error occurred
- * @offset:     Data cluster offset
- * @len:        Contiguous bytes starting from cluster offset
- *
- * This function is invoked when qed_find_cluster() completes.
- *
- * On success ret is QED_CLUSTER_FOUND and offset/len are a contiguous range
- * in the image file.
- *
- * On failure ret is QED_CLUSTER_L2 or QED_CLUSTER_L1 for missing L2 or L1
- * table offset, respectively.  len is number of contiguous unallocated bytes.
- */
-typedef void QEDFindClusterFunc(void *opaque, int ret, uint64_t offset, size_t len);
-
 void qed_acquire(BDRVQEDState *s);
 void qed_release(BDRVQEDState *s);
 
-- 
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 ` Kevin Wolf [this message]
2017-05-31 12:45   ` [Qemu-devel] [Qemu-block] [PATCH 22/29] qed: Add return value to qed_aio_read/write_data() 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 ` [Qemu-devel] [PATCH 27/29] qed: Simplify request handling Kevin Wolf
2017-05-31 12:54   ` 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-23-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.