Skip to content

Commit

Permalink
qed: Remove callback from qed_read_l2_table()
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
kevmw committed Jun 26, 2017
1 parent f651352 commit a8165d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 76 deletions.
94 changes: 31 additions & 63 deletions block/qed-cluster.c
Expand Up @@ -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
*
Expand All @@ -137,8 +84,11 @@ static void qed_find_cluster_cb(void *opaque, int ret)
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.
Expand All @@ -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);
}
15 changes: 4 additions & 11 deletions block/qed-table.c
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions block/qed.h
Expand Up @@ -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);
Expand Down

0 comments on commit a8165d2

Please sign in to comment.