From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beULo-0004g6-RN for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:44:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beULm-0002J3-Mt for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:44:15 -0400 From: Pavel Butsykin Date: Mon, 29 Aug 2016 20:10:01 +0300 Message-ID: <20160829171021.4902-3-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 02/22] block/pcache: add own AIOCB block 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 Signed-off-by: Pavel Butsykin --- block/pcache.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 770bbc0..74a4bc4 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -24,12 +24,22 @@ #include "qemu/osdep.h" #include "block/block_int.h" +#include "block/raw-aio.h" #include "qapi/error.h" #include "qapi/qmp/qstring.h" +typedef struct PrefCacheAIOCB { + BlockAIOCB common; + + QEMUIOVector *qiov; + uint64_t sector_num; + uint32_t nb_sectors; + int aio_type; + int ret; +} PrefCacheAIOCB; static const AIOCBInfo pcache_aiocb_info = { - .aiocb_size = sizeof(BlockAIOCB), + .aiocb_size = sizeof(PrefCacheAIOCB), }; static QemuOptsList runtime_opts = { @@ -47,14 +57,29 @@ static QemuOptsList runtime_opts = { static void pcache_aio_cb(void *opaque, int ret) { + PrefCacheAIOCB *acb = opaque; - BlockAIOCB *acb = opaque; - - acb->cb(acb->opaque, ret); + acb->common.cb(acb->common.opaque, ret); qemu_aio_unref(acb); } +static PrefCacheAIOCB *pcache_aio_get(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *qiov, int nb_sectors, + BlockCompletionFunc *cb, void *opaque, + int type) +{ + PrefCacheAIOCB *acb = qemu_aio_get(&pcache_aiocb_info, bs, cb, opaque); + + acb->sector_num = sector_num; + acb->nb_sectors = nb_sectors; + acb->qiov = qiov; + acb->aio_type = type; + acb->ret = 0; + + return acb; +} + static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, @@ -62,11 +87,12 @@ static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque) { - BlockAIOCB *acb = qemu_aio_get(&pcache_aiocb_info, bs, cb, opaque); + PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, + opaque, QEMU_AIO_READ); bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, pcache_aio_cb, acb); - return acb; + return &acb->common; } static BlockAIOCB *pcache_aio_writev(BlockDriverState *bs, @@ -76,11 +102,12 @@ static BlockAIOCB *pcache_aio_writev(BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque) { - BlockAIOCB *acb = qemu_aio_get(&pcache_aiocb_info, bs, cb, opaque); + PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, + opaque, QEMU_AIO_WRITE); bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, pcache_aio_cb, acb); - return acb; + return &acb->common; } static int pcache_file_open(BlockDriverState *bs, QDict *options, int flags, -- 2.8.3