qemu-devel.nongnu.org archive mirror
 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 04/29] qed: Remove callback from qed_read_l2_table()
Date: Fri, 26 May 2017 22:21:45 +0200	[thread overview]
Message-ID: <1495830130-30611-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1495830130-30611-1-git-send-email-kwolf@redhat.com>

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qed-cluster.c | 94 ++++++++++++++++++-----------------------------------
 block/qed-table.c   | 15 +++------
 block/qed.h         |  3 +-
 3 files changed, 36 insertions(+), 76 deletions(-)

diff --git a/block/qed-cluster.c b/block/qed-cluster.c
index 8f5da74..d279944 100644
--- a/block/qed-cluster.c
+++ b/block/qed-cluster.c
@@ -61,59 +61,6 @@ static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
     return i - index;
 }
 
-typedef struct {
-    BDRVQEDState *s;
-    uint64_t pos;
-    size_t len;
-
-    QEDRequest *request;
-
-    /* User callback */
-    QEDFindClusterFunc *cb;
-    void *opaque;
-} QEDFindClusterCB;
-
-static void qed_find_cluster_cb(void *opaque, int ret)
-{
-    QEDFindClusterCB *find_cluster_cb = opaque;
-    BDRVQEDState *s = find_cluster_cb->s;
-    QEDRequest *request = find_cluster_cb->request;
-    uint64_t offset = 0;
-    size_t len = 0;
-    unsigned int index;
-    unsigned int n;
-
-    qed_acquire(s);
-    if (ret) {
-        goto out;
-    }
-
-    index = qed_l2_index(s, find_cluster_cb->pos);
-    n = qed_bytes_to_clusters(s,
-                              qed_offset_into_cluster(s, find_cluster_cb->pos) +
-                              find_cluster_cb->len);
-    n = qed_count_contiguous_clusters(s, request->l2_table->table,
-                                      index, n, &offset);
-
-    if (qed_offset_is_unalloc_cluster(offset)) {
-        ret = QED_CLUSTER_L2;
-    } else if (qed_offset_is_zero_cluster(offset)) {
-        ret = QED_CLUSTER_ZERO;
-    } else if (qed_check_cluster_offset(s, offset)) {
-        ret = QED_CLUSTER_FOUND;
-    } else {
-        ret = -EINVAL;
-    }
-
-    len = MIN(find_cluster_cb->len, n * s->header.cluster_size -
-              qed_offset_into_cluster(s, find_cluster_cb->pos));
-
-out:
-    find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len);
-    qed_release(s);
-    g_free(find_cluster_cb);
-}
-
 /**
  * Find the offset of a data cluster
  *
@@ -137,8 +84,11 @@ out:
 void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
                       size_t len, QEDFindClusterFunc *cb, void *opaque)
 {
-    QEDFindClusterCB *find_cluster_cb;
     uint64_t l2_offset;
+    uint64_t offset = 0;
+    unsigned int index;
+    unsigned int n;
+    int ret;
 
     /* Limit length to L2 boundary.  Requests are broken up at the L2 boundary
      * so that a request acts on one L2 table at a time.
@@ -155,14 +105,32 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
         return;
     }
 
-    find_cluster_cb = g_malloc(sizeof(*find_cluster_cb));
-    find_cluster_cb->s = s;
-    find_cluster_cb->pos = pos;
-    find_cluster_cb->len = len;
-    find_cluster_cb->cb = cb;
-    find_cluster_cb->opaque = opaque;
-    find_cluster_cb->request = request;
+    ret = qed_read_l2_table(s, request, l2_offset);
+    qed_acquire(s);
+    if (ret) {
+        goto out;
+    }
+
+    index = qed_l2_index(s, pos);
+    n = qed_bytes_to_clusters(s,
+                              qed_offset_into_cluster(s, pos) + len);
+    n = qed_count_contiguous_clusters(s, request->l2_table->table,
+                                      index, n, &offset);
+
+    if (qed_offset_is_unalloc_cluster(offset)) {
+        ret = QED_CLUSTER_L2;
+    } else if (qed_offset_is_zero_cluster(offset)) {
+        ret = QED_CLUSTER_ZERO;
+    } else if (qed_check_cluster_offset(s, offset)) {
+        ret = QED_CLUSTER_FOUND;
+    } else {
+        ret = -EINVAL;
+    }
+
+    len = MIN(len,
+              n * s->header.cluster_size - qed_offset_into_cluster(s, pos));
 
-    qed_read_l2_table(s, request, l2_offset,
-                      qed_find_cluster_cb, find_cluster_cb);
+out:
+    cb(opaque, ret, offset, len);
+    qed_release(s);
 }
diff --git a/block/qed-table.c b/block/qed-table.c
index 4270003..ffecbea 100644
--- a/block/qed-table.c
+++ b/block/qed-table.c
@@ -177,8 +177,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
     return ret;
 }
 
-void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
-                       BlockCompletionFunc *cb, void *opaque)
+int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset)
 {
     int ret;
 
@@ -187,8 +186,7 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
     /* Check for cached L2 entry */
     request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset);
     if (request->l2_table) {
-        cb(opaque, 0);
-        return;
+        return 0;
     }
 
     request->l2_table = qed_alloc_l2_cache_entry(&s->l2_cache);
@@ -215,17 +213,12 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
     }
     qed_release(s);
 
-    cb(opaque, ret);
+    return ret;
 }
 
 int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset)
 {
-    int ret = -EINPROGRESS;
-
-    qed_read_l2_table(s, request, offset, qed_sync_cb, &ret);
-    BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS);
-
-    return ret;
+    return qed_read_l2_table(s, request, offset);
 }
 
 void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
diff --git a/block/qed.h b/block/qed.h
index ce8c314..c715058 100644
--- a/block/qed.h
+++ b/block/qed.h
@@ -237,8 +237,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
                             unsigned int n);
 int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
                            uint64_t offset);
-void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
-                       BlockCompletionFunc *cb, void *opaque);
+int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset);
 void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
                         unsigned int index, unsigned int n, bool flush,
                         BlockCompletionFunc *cb, void *opaque);
-- 
1.8.3.1

  parent reply	other threads:[~2017-05-26 20:22 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 ` Kevin Wolf [this message]
2017-05-26 21:16   ` [Qemu-devel] [PATCH 04/29] qed: Remove callback from qed_read_l2_table() 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 ` [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-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).