diff mbox

[v2,2/2] block: Assert that flags are in range

Message ID 1465844195-25911-3-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake June 13, 2016, 6:56 p.m. UTC
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>
---
 include/block/block.h | 3 +++
 block/io.c            | 6 ++++++
 2 files changed, 9 insertions(+)

Comments

Stefan Hajnoczi June 14, 2016, 9:11 a.m. UTC | #1
On Mon, Jun 13, 2016 at 12:56:35PM -0600, Eric Blake wrote:
> 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>
> ---
>  include/block/block.h | 3 +++
>  block/io.c            | 6 ++++++
>  2 files changed, 9 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox

Patch

diff --git a/include/block/block.h b/include/block/block.h
index a158575..733a8ec 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -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 {
diff --git a/block/io.c b/block/io.c
index d504443..b4f1235 100644
--- a/block/io.c
+++ b/block/io.c
@@ -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);