From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxDfv-0007u1-9I for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:46:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxDfr-0004Ru-Ep for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:46:27 -0400 From: Kevin Wolf Date: Thu, 20 Oct 2016 15:46:01 +0200 Message-Id: <1476971169-31604-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1476971169-31604-1-git-send-email-kwolf@redhat.com> References: <1476971169-31604-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/9] block: Use blk_co_flush() for all BB level flushes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org All read/write functions already have a single coroutine-based function on the BlockBackend level through which all requests go (no matter what API style the external caller used) and which passes the requests down to the block node level. This patch extends this mode of operation to flushes. Signed-off-by: Kevin Wolf --- block/block-backend.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 1a724a8..96bb634 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1099,14 +1099,19 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, blk_aio_write_entry, flags, cb, opaque); } +static void blk_aio_flush_entry(void *opaque) +{ + BlkAioEmAIOCB *acb = opaque; + BlkRwCo *rwco = &acb->rwco; + + rwco->ret = blk_co_flush(rwco->blk); + blk_aio_complete(acb); +} + BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque) { - if (!blk_is_available(blk)) { - return blk_abort_aio_request(blk, cb, opaque, -ENOMEDIUM); - } - - return bdrv_aio_flush(blk_bs(blk), cb, opaque); + return blk_aio_prwv(blk, 0, 0, NULL, blk_aio_flush_entry, 0, cb, opaque); } BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, @@ -1169,13 +1174,15 @@ int blk_co_flush(BlockBackend *blk) return bdrv_co_flush(blk_bs(blk)); } -int blk_flush(BlockBackend *blk) +static void blk_flush_entry(void *opaque) { - if (!blk_is_available(blk)) { - return -ENOMEDIUM; - } + BlkRwCo *rwco = opaque; + rwco->ret = blk_co_flush(rwco->blk); +} - return bdrv_flush(blk_bs(blk)); +int blk_flush(BlockBackend *blk) +{ + return blk_prw(blk, 0, NULL, 0, blk_flush_entry, 0); } void blk_drain(BlockBackend *blk) -- 1.8.3.1