Skip to content

Commit

Permalink
block: Assert that flags are in range
Browse files Browse the repository at this point in the history
Add 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.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
ebblake authored and kevmw committed Jun 16, 2016
1 parent 73698c3 commit fa16653
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions block/io.c
Expand Up @@ -776,6 +776,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);
}
Expand Down Expand Up @@ -815,6 +817,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);
Expand Down Expand Up @@ -953,6 +957,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
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) {
Expand Down Expand Up @@ -1242,6 +1247,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
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);
Expand Down
3 changes: 3 additions & 0 deletions include/block/block.h
Expand Up @@ -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 {
Expand Down

0 comments on commit fa16653

Please sign in to comment.