diff mbox

[RFC,v2,13/22] block/pcache: add generic request complete

Message ID 20160829171021.4902-14-pbutsykin@virtuozzo.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pavel Butsykin Aug. 29, 2016, 5:10 p.m. UTC
his change  allow us to generalize the completion of all requests.

Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
---
 block/pcache.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff mbox

Patch

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);