his change allow us to generalize the completion of all requests. Signed-off-by: Pavel Butsykin <pbutsy...@virtuozzo.com> --- block/pcache.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/block/pcache.c b/block/pcache.c index 435f2b4..1ff4c6a 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -105,6 +105,7 @@ typedef struct PrefCacheAIOCB { CoMutex lock; uint32_t cnt; } requests; + uint32_t ref; QEMUBH *bh; int ret; } PrefCacheAIOCB; @@ -505,9 +506,11 @@ static void pcache_aio_bh(void *opaque) static void complete_aio_request(PrefCacheAIOCB *acb) { - acb->bh = aio_bh_new(bdrv_get_aio_context(acb->common.bs), - pcache_aio_bh, acb); - qemu_bh_schedule(acb->bh); + if (atomic_dec_fetch(&acb->ref) == 0) { + acb->bh = aio_bh_new(bdrv_get_aio_context(acb->common.bs), + pcache_aio_bh, acb); + qemu_bh_schedule(acb->bh); + } } static void pcache_node_submit(PrefCachePartReq *req) @@ -585,9 +588,7 @@ static void pcache_aio_cb(void *opaque, int ret) pcache_merge_requests(acb); } - acb->common.cb(acb->common.opaque, ret); - - qemu_aio_unref(acb); + complete_aio_request(acb); } static PrefCacheAIOCB *pcache_aio_get(BlockDriverState *bs, int64_t sector_num, @@ -603,6 +604,7 @@ static PrefCacheAIOCB *pcache_aio_get(BlockDriverState *bs, int64_t sector_num, acb->requests.cnt = 0; acb->qiov = qiov; acb->aio_type = type; + acb->ref = 1; acb->ret = 0; QTAILQ_INIT(&acb->requests.list); -- 2.8.3