提交 b7d5a5b8 编写于 作者: S Stefan Hajnoczi 提交者: Kevin Wolf

qed: convert to .bdrv_co_is_allocated()

The bdrv_qed_is_allocated() function is a synchronous wrapper around
qed_find_cluster(), which performs the cluster lookup.  In order to
convert the synchronous function to a coroutine function we yield
instead of using qemu_aio_wait().  Note that QED's cache is already safe
for parallel requests so no locking is needed.
Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 376ae3f1
...@@ -661,6 +661,7 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options) ...@@ -661,6 +661,7 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options)
} }
typedef struct { typedef struct {
Coroutine *co;
int is_allocated; int is_allocated;
int *pnum; int *pnum;
} QEDIsAllocatedCB; } QEDIsAllocatedCB;
...@@ -670,9 +671,13 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l ...@@ -670,9 +671,13 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l
QEDIsAllocatedCB *cb = opaque; QEDIsAllocatedCB *cb = opaque;
*cb->pnum = len / BDRV_SECTOR_SIZE; *cb->pnum = len / BDRV_SECTOR_SIZE;
cb->is_allocated = (ret == QED_CLUSTER_FOUND || ret == QED_CLUSTER_ZERO); cb->is_allocated = (ret == QED_CLUSTER_FOUND || ret == QED_CLUSTER_ZERO);
if (cb->co) {
qemu_coroutine_enter(cb->co, NULL);
}
} }
static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num, static int coroutine_fn bdrv_qed_co_is_allocated(BlockDriverState *bs,
int64_t sector_num,
int nb_sectors, int *pnum) int nb_sectors, int *pnum)
{ {
BDRVQEDState *s = bs->opaque; BDRVQEDState *s = bs->opaque;
...@@ -686,8 +691,10 @@ static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num, ...@@ -686,8 +691,10 @@ static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num,
qed_find_cluster(s, &request, pos, len, qed_is_allocated_cb, &cb); qed_find_cluster(s, &request, pos, len, qed_is_allocated_cb, &cb);
/* Now sleep if the callback wasn't invoked immediately */
while (cb.is_allocated == -1) { while (cb.is_allocated == -1) {
qemu_aio_wait(); cb.co = qemu_coroutine_self();
qemu_coroutine_yield();
} }
qed_unref_l2_cache_entry(request.l2_table); qed_unref_l2_cache_entry(request.l2_table);
...@@ -1485,7 +1492,7 @@ static BlockDriver bdrv_qed = { ...@@ -1485,7 +1492,7 @@ static BlockDriver bdrv_qed = {
.bdrv_open = bdrv_qed_open, .bdrv_open = bdrv_qed_open,
.bdrv_close = bdrv_qed_close, .bdrv_close = bdrv_qed_close,
.bdrv_create = bdrv_qed_create, .bdrv_create = bdrv_qed_create,
.bdrv_is_allocated = bdrv_qed_is_allocated, .bdrv_co_is_allocated = bdrv_qed_co_is_allocated,
.bdrv_make_empty = bdrv_qed_make_empty, .bdrv_make_empty = bdrv_qed_make_empty,
.bdrv_aio_readv = bdrv_qed_aio_readv, .bdrv_aio_readv = bdrv_qed_aio_readv,
.bdrv_aio_writev = bdrv_qed_aio_writev, .bdrv_aio_writev = bdrv_qed_aio_writev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册