Received: from eggs.gnu.org ([2001:4830:134:3::10]:33286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beWAy-0003XT-Vt for qemu-devel@nongnu.org; Mon, 29 Aug 2016 19:41:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beWAy-0003i5-2W for qemu-devel@nongnu.org; Mon, 29 Aug 2016 19:41:13 -0400 From: Pavel Butsykin Date: Mon, 29 Aug 2016 20:10:12 +0300 Message-ID: <20160829171021.4902-14-pbutsykin@virtuozzo.com> In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH RFC v2 13/22] block/pcache: add generic request complete List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com, eblake@redhat.com, famz@redhat.com his change allow us to generalize the completion of all requests. Signed-off-by: Pavel Butsykin --- 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