[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 3/9] qed: convert to .bdrv_co_is_allocated()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v2 3/9] qed: convert to .bdrv_co_is_allocated() |
Date: |
Mon, 14 Nov 2011 12:44:20 +0000 |
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: Stefan Hajnoczi <address@hidden>
---
block/qed.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index d032a45..8a05445 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -651,6 +651,7 @@ static int bdrv_qed_create(const char *filename,
QEMUOptionParameter *options)
}
typedef struct {
+ Coroutine *co;
int is_allocated;
int *pnum;
} QEDIsAllocatedCB;
@@ -660,10 +661,14 @@ static void qed_is_allocated_cb(void *opaque, int ret,
uint64_t offset, size_t l
QEDIsAllocatedCB *cb = opaque;
*cb->pnum = len / BDRV_SECTOR_SIZE;
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,
- int nb_sectors, int *pnum)
+static int coroutine_fn bdrv_qed_co_is_allocated(BlockDriverState *bs,
+ int64_t sector_num,
+ int nb_sectors, int *pnum)
{
BDRVQEDState *s = bs->opaque;
uint64_t pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE;
@@ -676,8 +681,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);
+ /* Now sleep if the callback wasn't invoked immediately */
while (cb.is_allocated == -1) {
- qemu_aio_wait();
+ cb.co = qemu_coroutine_self();
+ qemu_coroutine_yield();
}
qed_unref_l2_cache_entry(request.l2_table);
@@ -1475,7 +1482,7 @@ static BlockDriver bdrv_qed = {
.bdrv_open = bdrv_qed_open,
.bdrv_close = bdrv_qed_close,
.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_aio_readv = bdrv_qed_aio_readv,
.bdrv_aio_writev = bdrv_qed_aio_writev,
--
1.7.7.1
- [Qemu-devel] [PATCH v2 0/9] block: replace .bdrv_is_allocated() with .bdrv_co_is_allocated(), Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 3/9] qed: convert to .bdrv_co_is_allocated(),
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v2 2/9] block: add .bdrv_co_is_allocated(), Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 9/9] block: add bdrv_co_is_allocated() interface, Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 5/9] vvfat: convert to .bdrv_co_is_allocated(), Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 6/9] vdi: convert to .bdrv_co_is_allocated(), Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 4/9] block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated(), Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 1/9] block: use public bdrv_is_allocated() interface, Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 8/9] block: drop .bdrv_is_allocated() interface, Stefan Hajnoczi, 2011/11/14
- [Qemu-devel] [PATCH v2 7/9] cow: convert to .bdrv_co_is_allocated(), Stefan Hajnoczi, 2011/11/14
- Re: [Qemu-devel] [PATCH v2 0/9] block: replace .bdrv_is_allocated() with .bdrv_co_is_allocated(), Kevin Wolf, 2011/11/23