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>
This commit is contained in:
parent
f6513529c6
commit
a8165d2d66
@ -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;
|
||||
}
|
||||
|
||||
qed_read_l2_table(s, request, l2_offset,
|
||||
qed_find_cluster_cb, find_cluster_cb);
|
||||
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));
|
||||
|
||||
out:
|
||||
cb(opaque, ret, offset, len);
|
||||
qed_release(s);
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user