Skip to content

Commit e31f686

Browse files
ebblakekevmw
authored andcommitted
block: Support byte-based aio callbacks
We are gradually moving away from sector-based interfaces, towards byte-based. Add new sector-based aio callbacks for read and write, to match the fact that bdrv_aio_pdiscard is already byte-based. Ideally, drivers should be converted to use coroutine callbacks rather than aio; but that is not quite as trivial (and if we were to do that conversion, the null-aio driver would disappear), so for the short term, converting the signature but keeping things with aio is easier. However, we CAN declare that a driver that uses the byte-based aio interfaces now defaults to byte-based operations, and must explicitly provide a refresh_limits override to stick with larger alignments (making the alignment issues more obvious directly in the drivers touched in the next few patches). Once all drivers are converted, the sector-based aio callbacks will be removed; in the meantime, a FIXME comment is added due to a slight inefficiency that will be touched up as part of that later cleanup. Simplify some instances of 'bs->drv' into 'drv' while touching this, since the local variable already exists to reduce typing. Signed-off-by: Eric Blake <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 7803696 commit e31f686

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

block/io.c

+29-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
9292
}
9393

9494
/* Default alignment based on whether driver has byte interface */
95-
bs->bl.request_alignment = drv->bdrv_co_preadv ? 1 : 512;
95+
bs->bl.request_alignment = (drv->bdrv_co_preadv ||
96+
drv->bdrv_aio_preadv) ? 1 : 512;
9697

9798
/* Take some limits from the children as a default */
9899
if (bs->file) {
@@ -924,12 +925,15 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
924925
return drv->bdrv_co_preadv(bs, offset, bytes, qiov, flags);
925926
}
926927

928+
/* FIXME - no need to calculate these if .bdrv_aio_preadv exists */
927929
sector_num = offset >> BDRV_SECTOR_BITS;
928930
nb_sectors = bytes >> BDRV_SECTOR_BITS;
929931

930-
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
931-
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
932-
assert((bytes >> BDRV_SECTOR_BITS) <= BDRV_REQUEST_MAX_SECTORS);
932+
if (!drv->bdrv_aio_preadv) {
933+
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
934+
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
935+
assert((bytes >> BDRV_SECTOR_BITS) <= BDRV_REQUEST_MAX_SECTORS);
936+
}
933937

934938
if (drv->bdrv_co_readv) {
935939
return drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
@@ -939,8 +943,13 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
939943
.coroutine = qemu_coroutine_self(),
940944
};
941945

942-
acb = bs->drv->bdrv_aio_readv(bs, sector_num, qiov, nb_sectors,
946+
if (drv->bdrv_aio_preadv) {
947+
acb = drv->bdrv_aio_preadv(bs, offset, bytes, qiov, flags,
948+
bdrv_co_io_em_complete, &co);
949+
} else {
950+
acb = drv->bdrv_aio_readv(bs, sector_num, qiov, nb_sectors,
943951
bdrv_co_io_em_complete, &co);
952+
}
944953
if (acb == NULL) {
945954
return -EIO;
946955
} else {
@@ -972,12 +981,15 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs,
972981
goto emulate_flags;
973982
}
974983

984+
/* FIXME - no need to calculate these if .bdrv_aio_pwritev exists */
975985
sector_num = offset >> BDRV_SECTOR_BITS;
976986
nb_sectors = bytes >> BDRV_SECTOR_BITS;
977987

978-
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
979-
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
980-
assert((bytes >> BDRV_SECTOR_BITS) <= BDRV_REQUEST_MAX_SECTORS);
988+
if (!drv->bdrv_aio_pwritev) {
989+
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
990+
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
991+
assert((bytes >> BDRV_SECTOR_BITS) <= BDRV_REQUEST_MAX_SECTORS);
992+
}
981993

982994
if (drv->bdrv_co_writev_flags) {
983995
ret = drv->bdrv_co_writev_flags(bs, sector_num, nb_sectors, qiov,
@@ -992,8 +1004,16 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs,
9921004
.coroutine = qemu_coroutine_self(),
9931005
};
9941006

995-
acb = bs->drv->bdrv_aio_writev(bs, sector_num, qiov, nb_sectors,
1007+
if (drv->bdrv_aio_pwritev) {
1008+
acb = drv->bdrv_aio_pwritev(bs, offset, bytes, qiov,
1009+
flags & bs->supported_write_flags,
1010+
bdrv_co_io_em_complete, &co);
1011+
flags &= ~bs->supported_write_flags;
1012+
} else {
1013+
assert(!bs->supported_write_flags);
1014+
acb = drv->bdrv_aio_writev(bs, sector_num, qiov, nb_sectors,
9961015
bdrv_co_io_em_complete, &co);
1016+
}
9971017
if (acb == NULL) {
9981018
ret = -EIO;
9991019
} else {

include/block/block_int.h

+6
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,15 @@ struct BlockDriver {
144144
BlockAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs,
145145
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
146146
BlockCompletionFunc *cb, void *opaque);
147+
BlockAIOCB *(*bdrv_aio_preadv)(BlockDriverState *bs,
148+
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags,
149+
BlockCompletionFunc *cb, void *opaque);
147150
BlockAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs,
148151
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
149152
BlockCompletionFunc *cb, void *opaque);
153+
BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs,
154+
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags,
155+
BlockCompletionFunc *cb, void *opaque);
150156
BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
151157
BlockCompletionFunc *cb, void *opaque);
152158
BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs,

0 commit comments

Comments
 (0)