From 44acfa21837219a20d4fc1ad9072a6f6a00e8654 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 14 Feb 2012 11:14:03 +0100 Subject: [PATCH 38/99] block: Add bdrv_co_readv/writev RH-Author: Kevin Wolf Message-id: <1329218101-24213-39-git-send-email-kwolf@redhat.com> Patchwork-id: 37232 O-Subject: [RHEL-6.3 qemu-kvm PATCH v2 38/96] block: Add bdrv_co_readv/writev Bugzilla: 783950 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Laszlo Ersek Bugzilla: 783950 Add new block driver callbacks bdrv_co_readv/writev, which work on a QEMUIOVector like bdrv_aio_*, but don't need a callback. The function may only be called inside a coroutine, so a block driver implementing this interface can yield instead of blocking during I/O. Signed-off-by: Kevin Wolf (cherry picked from commit da1fa91d6cca8a6d3da9c2b222fa485429db297c) Conflicts: Makefile.objs block_int.h trace-events Signed-off-by: Kevin Wolf --- Makefile.objs | 2 +- block.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ block.h | 5 +++++ block_int.h | 6 ++++++ trace-events | 2 ++ 5 files changed, 59 insertions(+), 1 deletions(-) Signed-off-by: Michal Novotny --- Makefile.objs | 2 +- block.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ block.h | 5 +++++ block_int.h | 6 ++++++ trace-events | 2 ++ 5 files changed, 59 insertions(+), 1 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 23696c1..c6c3fce 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -15,6 +15,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o qemu-progress.o +block-obj-y += $(coroutine-obj-y) block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-obj-$(CONFIG_POSIX) += compatfd.o @@ -65,7 +66,6 @@ common-obj-y += qemu-thread.o common-obj-y += blockdev.o common-obj-y += $(net-obj-y) common-obj-y += readline.o console.o cursor.o -common-obj-y += $(coroutine-obj-y) common-obj-y += tcg-runtime.o host-utils.o common-obj-y += irq.o ioport.o diff --git a/block.c b/block.c index ab67d74..7cebbba 100644 --- a/block.c +++ b/block.c @@ -1141,6 +1141,51 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, return 0; } +int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, QEMUIOVector *qiov) +{ + BlockDriver *drv = bs->drv; + + trace_bdrv_co_readv(bs, sector_num, nb_sectors); + + if (!drv) { + return -ENOMEDIUM; + } + if (bdrv_check_request(bs, sector_num, nb_sectors)) { + return -EIO; + } + + return drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov); +} + +int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, QEMUIOVector *qiov) +{ + BlockDriver *drv = bs->drv; + + trace_bdrv_co_writev(bs, sector_num, nb_sectors); + + if (!bs->drv) { + return -ENOMEDIUM; + } + if (bs->read_only) { + return -EACCES; + } + if (bdrv_check_request(bs, sector_num, nb_sectors)) { + return -EIO; + } + + if (bs->dirty_bitmap) { + set_dirty_bitmap(bs, sector_num, nb_sectors, 1); + } + + if (bs->wr_highest_sector < sector_num + nb_sectors - 1) { + bs->wr_highest_sector = sector_num + nb_sectors - 1; + } + + return drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov); +} + /** * Truncate file to 'offset' bytes (needed only for file protocols) */ diff --git a/block.h b/block.h index 921436c..183aef6 100644 --- a/block.h +++ b/block.h @@ -4,6 +4,7 @@ #include "qemu-aio.h" #include "qemu-common.h" #include "qemu-option.h" +#include "qemu-coroutine.h" #include "qobject.h" /* block.c */ @@ -132,6 +133,10 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, const void *buf, int count); int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, const void *buf, int count); +int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, QEMUIOVector *qiov); +int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, QEMUIOVector *qiov); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); diff --git a/block_int.h b/block_int.h index d91ae6b..fa2875c 100644 --- a/block_int.h +++ b/block_int.h @@ -27,6 +27,7 @@ #include "block.h" #include "qemu-option.h" #include "qemu-queue.h" +#include "qemu-coroutine.h" #include "qemu-timer.h" #define BLOCK_FLAG_ENCRYPT 1 @@ -79,6 +80,11 @@ struct BlockDriver { int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); + int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); + int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); + int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs, int num_reqs); int (*bdrv_merge_requests)(BlockDriverState *bs, BlockRequest* a, diff --git a/trace-events b/trace-events index 63f1c3e..a569a9f 100644 --- a/trace-events +++ b/trace-events @@ -55,6 +55,8 @@ disable bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p" disable bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" disable bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" disable bdrv_lock_medium(void *bs, int locked) "bs %p locked %d" +disable bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" +disable bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" # hw/virtio-blk.c disable virtio_blk_req_complete(void *req, int status) "req %p status %d" -- 1.7.7.5