mirror of https://github.com/xemu-project/xemu.git
qed: Remove callback from qed_find_cluster()
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
a8165d2d66
commit
0f21b7a1b7
|
@ -67,22 +67,27 @@ static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
|
||||||
* @s: QED state
|
* @s: QED state
|
||||||
* @request: L2 cache entry
|
* @request: L2 cache entry
|
||||||
* @pos: Byte position in device
|
* @pos: Byte position in device
|
||||||
* @len: Number of bytes
|
* @len: Number of bytes (may be shortened on return)
|
||||||
* @cb: Completion function
|
* @img_offset: Contains offset in the image file on success
|
||||||
* @opaque: User data for completion function
|
|
||||||
*
|
*
|
||||||
* This function translates a position in the block device to an offset in the
|
* This function translates a position in the block device to an offset in the
|
||||||
* image file. It invokes the cb completion callback to report back the
|
* image file. The translated offset or unallocated range in the image file is
|
||||||
* translated offset or unallocated range in the image file.
|
* reported back in *img_offset and *len.
|
||||||
*
|
*
|
||||||
* If the L2 table exists, request->l2_table points to the L2 table cache entry
|
* If the L2 table exists, request->l2_table points to the L2 table cache entry
|
||||||
* and the caller must free the reference when they are finished. The cache
|
* and the caller must free the reference when they are finished. The cache
|
||||||
* entry is exposed in this way to avoid callers having to read the L2 table
|
* entry is exposed in this way to avoid callers having to read the L2 table
|
||||||
* again later during request processing. If request->l2_table is non-NULL it
|
* again later during request processing. If request->l2_table is non-NULL it
|
||||||
* will be unreferenced before taking on the new cache entry.
|
* will be unreferenced before taking on the new cache entry.
|
||||||
|
*
|
||||||
|
* On success QED_CLUSTER_FOUND is returned and img_offset/len are a contiguous
|
||||||
|
* range in the image file.
|
||||||
|
*
|
||||||
|
* On failure QED_CLUSTER_L2 or QED_CLUSTER_L1 is returned for missing L2 or L1
|
||||||
|
* table offset, respectively. len is number of contiguous unallocated bytes.
|
||||||
*/
|
*/
|
||||||
void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
||||||
size_t len, QEDFindClusterFunc *cb, void *opaque)
|
size_t *len, uint64_t *img_offset)
|
||||||
{
|
{
|
||||||
uint64_t l2_offset;
|
uint64_t l2_offset;
|
||||||
uint64_t offset = 0;
|
uint64_t offset = 0;
|
||||||
|
@ -93,16 +98,16 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
||||||
/* Limit length to L2 boundary. Requests are broken up at the L2 boundary
|
/* 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.
|
* so that a request acts on one L2 table at a time.
|
||||||
*/
|
*/
|
||||||
len = MIN(len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos);
|
*len = MIN(*len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos);
|
||||||
|
|
||||||
l2_offset = s->l1_table->offsets[qed_l1_index(s, pos)];
|
l2_offset = s->l1_table->offsets[qed_l1_index(s, pos)];
|
||||||
if (qed_offset_is_unalloc_cluster(l2_offset)) {
|
if (qed_offset_is_unalloc_cluster(l2_offset)) {
|
||||||
cb(opaque, QED_CLUSTER_L1, 0, len);
|
*img_offset = 0;
|
||||||
return;
|
return QED_CLUSTER_L1;
|
||||||
}
|
}
|
||||||
if (!qed_check_table_offset(s, l2_offset)) {
|
if (!qed_check_table_offset(s, l2_offset)) {
|
||||||
cb(opaque, -EINVAL, 0, 0);
|
*img_offset = *len = 0;
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qed_read_l2_table(s, request, l2_offset);
|
ret = qed_read_l2_table(s, request, l2_offset);
|
||||||
|
@ -112,8 +117,7 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
||||||
}
|
}
|
||||||
|
|
||||||
index = qed_l2_index(s, pos);
|
index = qed_l2_index(s, pos);
|
||||||
n = qed_bytes_to_clusters(s,
|
n = qed_bytes_to_clusters(s, qed_offset_into_cluster(s, pos) + *len);
|
||||||
qed_offset_into_cluster(s, pos) + len);
|
|
||||||
n = qed_count_contiguous_clusters(s, request->l2_table->table,
|
n = qed_count_contiguous_clusters(s, request->l2_table->table,
|
||||||
index, n, &offset);
|
index, n, &offset);
|
||||||
|
|
||||||
|
@ -127,10 +131,11 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = MIN(len,
|
*len = MIN(*len,
|
||||||
n * s->header.cluster_size - qed_offset_into_cluster(s, pos));
|
n * s->header.cluster_size - qed_offset_into_cluster(s, pos));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
cb(opaque, ret, offset, len);
|
*img_offset = offset;
|
||||||
qed_release(s);
|
qed_release(s);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
24
block/qed.c
24
block/qed.c
|
@ -776,14 +776,14 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs,
|
||||||
.file = file,
|
.file = file,
|
||||||
};
|
};
|
||||||
QEDRequest request = { .l2_table = NULL };
|
QEDRequest request = { .l2_table = NULL };
|
||||||
|
uint64_t offset;
|
||||||
|
int ret;
|
||||||
|
|
||||||
qed_find_cluster(s, &request, cb.pos, len, qed_is_allocated_cb, &cb);
|
ret = qed_find_cluster(s, &request, cb.pos, &len, &offset);
|
||||||
|
qed_is_allocated_cb(&cb, ret, offset, len);
|
||||||
|
|
||||||
/* Now sleep if the callback wasn't invoked immediately */
|
/* The callback was invoked immediately */
|
||||||
while (cb.status == BDRV_BLOCK_OFFSET_MASK) {
|
assert(cb.status != BDRV_BLOCK_OFFSET_MASK);
|
||||||
cb.co = qemu_coroutine_self();
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
qed_unref_l2_cache_entry(request.l2_table);
|
qed_unref_l2_cache_entry(request.l2_table);
|
||||||
|
|
||||||
|
@ -1306,8 +1306,6 @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
|
||||||
* or -errno
|
* or -errno
|
||||||
* @offset: Cluster offset in bytes
|
* @offset: Cluster offset in bytes
|
||||||
* @len: Length in bytes
|
* @len: Length in bytes
|
||||||
*
|
|
||||||
* Callback from qed_find_cluster().
|
|
||||||
*/
|
*/
|
||||||
static void qed_aio_write_data(void *opaque, int ret,
|
static void qed_aio_write_data(void *opaque, int ret,
|
||||||
uint64_t offset, size_t len)
|
uint64_t offset, size_t len)
|
||||||
|
@ -1343,8 +1341,6 @@ static void qed_aio_write_data(void *opaque, int ret,
|
||||||
* or -errno
|
* or -errno
|
||||||
* @offset: Cluster offset in bytes
|
* @offset: Cluster offset in bytes
|
||||||
* @len: Length in bytes
|
* @len: Length in bytes
|
||||||
*
|
|
||||||
* Callback from qed_find_cluster().
|
|
||||||
*/
|
*/
|
||||||
static void qed_aio_read_data(void *opaque, int ret,
|
static void qed_aio_read_data(void *opaque, int ret,
|
||||||
uint64_t offset, size_t len)
|
uint64_t offset, size_t len)
|
||||||
|
@ -1393,6 +1389,8 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
|
||||||
BDRVQEDState *s = acb_to_s(acb);
|
BDRVQEDState *s = acb_to_s(acb);
|
||||||
QEDFindClusterFunc *io_fn = (acb->flags & QED_AIOCB_WRITE) ?
|
QEDFindClusterFunc *io_fn = (acb->flags & QED_AIOCB_WRITE) ?
|
||||||
qed_aio_write_data : qed_aio_read_data;
|
qed_aio_write_data : qed_aio_read_data;
|
||||||
|
uint64_t offset;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
trace_qed_aio_next_io(s, acb, ret, acb->cur_pos + acb->cur_qiov.size);
|
trace_qed_aio_next_io(s, acb, ret, acb->cur_pos + acb->cur_qiov.size);
|
||||||
|
|
||||||
|
@ -1419,9 +1417,9 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find next cluster and start I/O */
|
/* Find next cluster and start I/O */
|
||||||
qed_find_cluster(s, &acb->request,
|
len = acb->end_pos - acb->cur_pos;
|
||||||
acb->cur_pos, acb->end_pos - acb->cur_pos,
|
ret = qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &offset);
|
||||||
io_fn, acb);
|
io_fn(acb, ret, offset, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
|
static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
|
||||||
|
|
|
@ -247,8 +247,8 @@ int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
|
||||||
/**
|
/**
|
||||||
* Cluster functions
|
* Cluster functions
|
||||||
*/
|
*/
|
||||||
void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
||||||
size_t len, QEDFindClusterFunc *cb, void *opaque);
|
size_t *len, uint64_t *img_offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consistency check
|
* Consistency check
|
||||||
|
|
Loading…
Reference in New Issue