Fix incomplete aio_preadv byte conversion in mirroring
v2 cover Fix incomplete aio_preadv byte conversion in mirroring
v2: Split the bug fix from the addition of assertions, add a BDRV_REQ_MASK constant [famz], stick assertions at the more common entry points
Eric Blake (2):
block: Avoid bogus flags during mirroring
block: Assert that flags are in range
include/block/block.h | 3 +++ block/io.c | 6 ++++++ block/mirror.c | 6 ++---- 3 files changed, 11 insertions(+), 4 deletions(-)
Signature · 1 line
2.5.5
PATCH v2 1/2 block: Avoid bogus flags during mirroring
Commit e253f4b8 converted mirroring from sector-based bdrv_aio_* to byte-based blk_aio_*, but failed to account for the subtle difference in signatures (the former takes a semi-redundant length, the latter takes a flags parameter). Since all of our flags are currently smaller in size than BDRV_SECTOR_SIZE, it has no ill effects until we either perform sub-sector mirroring, or we start asserting that no unexpected flags are set. I found it while testing new asserts when qemu-iotests 132 started warning about an unknown flag 0x200000.
--- block/mirror.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
block/mirror.c +2 -4
@@ -157,8 +157,7 @@ static void mirror_read_complete(void *opaque, int ret)return ; }blk_aio_pwritev (s->target, op->sector_num *BDRV_SECTOR_SIZE , &op->qiov, - op->nb_sectors *BDRV_SECTOR_SIZE , - mirror_write_complete, op); +0 , mirror_write_complete, op); } static inline void mirror_clip_sectors(MirrorBlockJob *s,
@@ -275,8 +274,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num, s->sectors_in_flight += nb_sectors;trace_mirror_one_iteration (s, sector_num, nb_sectors); -blk_aio_preadv (source, sector_num *BDRV_SECTOR_SIZE , &op->qiov, - nb_sectors *BDRV_SECTOR_SIZE , +blk_aio_preadv (source, sector_num *BDRV_SECTOR_SIZE , &op->qiov,0 , mirror_read_complete, op);return ret; }
Signature · 1 line
2.5.5
PATCH v2 2/2 block: Assert that flags are in range
In reply to Eric BlakeAdd a new BDRV_REQ_MASK constant, and use it to make sure that caller flags are always valid.
Tested with 'make check' and with qemu-iotests on both '-raw' and '-qcow2'; the only failure turned up was fixed in the previous commit.
--- include/block/block.h | 3 +++ block/io.c | 6 ++++++ 2 files changed, 9 insertions(+)
include/block/block.h +3 -0
@@ -65,6 +65,9 @@ typedef enum {BDRV_REQ_MAY_UNMAP =0x4 ,BDRV_REQ_NO_SERIALISING =0x8 ,BDRV_REQ_FUA =0x10 , + +/* Mask of valid flags */ +BDRV_REQ_MASK =0x1f , } BdrvRequestFlags; typedef struct BlockSizes {
block/io.c +6 -0
@@ -802,6 +802,8 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,int64_t sector_num;unsigned int nb_sectors; +assert (!(flags & ~BDRV_REQ_MASK )); +if (drv->bdrv_co_preadv) {return drv->bdrv_co_preadv (bs, offset, bytes, qiov, flags); }
@@ -841,6 +843,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs,unsigned int nb_sectors;int ret; +assert (!(flags & ~BDRV_REQ_MASK )); +if (drv->bdrv_co_pwritev) { ret = drv->bdrv_co_pwritev (bs, offset, bytes, qiov, flags & bs->supported_write_flags);
@@ -967,6 +971,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,assert (!qiov || bytes == qiov->size);assert ((bs->open_flags &BDRV_O_NO_IO ) ==0 ); +assert (!(flags & ~BDRV_REQ_MASK ));/* Handle Copy on Read and associated serialisation */ if (flags &BDRV_REQ_COPY_ON_READ ) {
@@ -1246,6 +1251,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,assert (!qiov || bytes == qiov->size);assert ((bs->open_flags &BDRV_O_NO_IO ) ==0 ); +assert (!(flags & ~BDRV_REQ_MASK )); waited =wait_serialising_requests (req);assert (!waited || !req->serialising);
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH v2 2/2] block: Assert that flags are in range
Quoted 7 lines · Eric Blake
Add a new
BDRV_REQ_MASKconstant, and use it to make sure that caller flags are always valid.Tested with 'make check' and with qemu-iotests on both '-raw' and '-qcow2'; the only failure turned up was fixed in the previous commit.
Quoted 5 lines
Signed-off-by Eric Blake <[email protected]>--- include/block/block.h | 3 +++ block/io.c | 6 ++++++ 2 files changed, 9 insertions(+)
Kevin Wolf
AppliedAm 13.06.2016 um 20:56 hat Eric Blake geschrieben:
Quoted 3 lines
v2: Split the bug fix from the addition of assertions, add a
BDRV_REQ_MASKconstant [famz], stick assertions at the more common entry points
Thanks, applied to the block branch.
Kevin