[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 08/69] block: Introduce bdrv_driver_preadv()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 08/69] block: Introduce bdrv_driver_preadv() |
Date: |
Thu, 12 May 2016 16:34:48 +0200 |
This is a function that simply calls into the block driver for doing a
read, providing the byte granularity interface we want to eventually
have everywhere, and using whatever interface that driver supports.
For now, this is just a wrapper for calling bs->drv->bdrv_co_readv().
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
---
block/io.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/block/io.c b/block/io.c
index b903270..d3617fe 100644
--- a/block/io.c
+++ b/block/io.c
@@ -797,6 +797,21 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
return 0;
}
+static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
+ uint64_t offset, uint64_t bytes,
+ QEMUIOVector *qiov, int flags)
+{
+ BlockDriver *drv = bs->drv;
+ int64_t sector_num = offset >> BDRV_SECTOR_BITS;
+ unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS;
+
+ assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
+ assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
+ assert((bytes >> BDRV_SECTOR_BITS) <= BDRV_REQUEST_MAX_SECTORS);
+
+ return drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+}
+
static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
{
@@ -833,8 +848,9 @@ static int coroutine_fn
bdrv_co_do_copy_on_readv(BlockDriverState *bs,
qemu_iovec_init_external(&bounce_qiov, &iov, 1);
- ret = drv->bdrv_co_readv(bs, cluster_sector_num, cluster_nb_sectors,
- &bounce_qiov);
+ ret = bdrv_driver_preadv(bs, cluster_sector_num * BDRV_SECTOR_SIZE,
+ cluster_nb_sectors * BDRV_SECTOR_SIZE,
+ &bounce_qiov, 0);
if (ret < 0) {
goto err;
}
@@ -877,7 +893,6 @@ static int coroutine_fn
bdrv_aligned_preadv(BlockDriverState *bs,
BdrvTrackedRequest *req, int64_t offset, unsigned int bytes,
int64_t align, QEMUIOVector *qiov, int flags)
{
- BlockDriver *drv = bs->drv;
int ret;
int64_t sector_num = offset >> BDRV_SECTOR_BITS;
@@ -918,7 +933,7 @@ static int coroutine_fn
bdrv_aligned_preadv(BlockDriverState *bs,
/* Forward the request to the BlockDriver */
if (!bs->zero_beyond_eof) {
- ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+ ret = bdrv_driver_preadv(bs, offset, bytes, qiov, 0);
} else {
/* Read zeros after EOF */
int64_t total_sectors, max_nb_sectors;
@@ -932,7 +947,7 @@ static int coroutine_fn
bdrv_aligned_preadv(BlockDriverState *bs,
max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num),
align >> BDRV_SECTOR_BITS);
if (nb_sectors < max_nb_sectors) {
- ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+ ret = bdrv_driver_preadv(bs, offset, bytes, qiov, 0);
} else if (max_nb_sectors > 0) {
QEMUIOVector local_qiov;
@@ -940,8 +955,9 @@ static int coroutine_fn
bdrv_aligned_preadv(BlockDriverState *bs,
qemu_iovec_concat(&local_qiov, qiov, 0,
max_nb_sectors * BDRV_SECTOR_SIZE);
- ret = drv->bdrv_co_readv(bs, sector_num, max_nb_sectors,
- &local_qiov);
+ ret = bdrv_driver_preadv(bs, offset,
+ max_nb_sectors * BDRV_SECTOR_SIZE,
+ &local_qiov, 0);
qemu_iovec_destroy(&local_qiov);
} else {
--
1.8.3.1
- [Qemu-block] [PULL 00/69] Block layer patches, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 04/69] block: extract bdrv_drain_poll/bdrv_co_yield_to_drain from bdrv_drain/bdrv_co_drain, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 01/69] block: Don't disable I/O throttling on sync requests, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 03/69] block: move restarting of throttled reqs to block/throttle-groups.c, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 02/69] block: make bdrv_start_throttled_reqs return void, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 06/69] block: plug whole tree at once, introduce bdrv_io_unplugged_begin/end, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 09/69] block: Introduce bdrv_driver_pwritev(), Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 07/69] linux-aio: make it more type safe, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 05/69] block: introduce bdrv_no_throttling_begin/end, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 11/69] block: Rename bdrv_co_do_preadv/writev to bdrv_co_preadv/writev, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 08/69] block: Introduce bdrv_driver_preadv(),
Kevin Wolf <=
- [Qemu-block] [PULL 10/69] block: Support AIO drivers in bdrv_driver_preadv/pwritev(), Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 12/69] block: Introduce .bdrv_co_preadv/pwritev BlockDriver function, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 13/69] bochs: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 16/69] vdi: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 15/69] dmg: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 17/69] vdi: Implement .bdrv_co_pwritev() interface, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 24/69] block: Remove BlockDriver.bdrv_read/write, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 18/69] vmdk: Add vmdk_find_offset_in_cluster(), Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 26/69] block: always compile-check debug prints, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 14/69] cloop: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12