aboutsummaryrefslogtreecommitdiff
path: root/block/qed-cluster.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-11-14 16:26:14 +0100
committerKevin Wolf <kwolf@redhat.com>2017-06-26 14:51:14 +0200
commita8165d2d6619a29b99451fd0a310d64693d86c3f (patch)
tree5d827b8c21c3fb0b4d265cfb956fcf2226bbd271 /block/qed-cluster.c
parentf6513529c67509264fc602c4a537ec24bcb7b26f (diff)
qed: Remove callback from qed_read_l2_table()
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/qed-cluster.c')
-rw-r--r--block/qed-cluster.c94
1 files changed, 31 insertions, 63 deletions
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
index 8f5da74c4d..d2799446b3 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);
}