block: Assertions for resize permission
authorKevin Wolf <kwolf@redhat.com>
Fri, 17 Feb 2017 13:52:00 +0000 (14:52 +0100)
committerKevin Wolf <kwolf@redhat.com>
Tue, 28 Feb 2017 19:47:50 +0000 (20:47 +0100)
This adds an assertion that ensures that the necessary resize permission
has been granted before bdrv_truncate() is called.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Acked-by: Fam Zheng <famz@redhat.com>
block.c
block/io.c

diff --git a/block.c b/block.c
index 79d9ad0ad607fbc6e7cd11b81ab465fff4486d73..74ac7dcf741dd1338e0c8829ac5fe7321994f634 100644 (file)
--- a/block.c
+++ b/block.c
@@ -3122,6 +3122,9 @@ int bdrv_truncate(BdrvChild *child, int64_t offset)
     BlockDriverState *bs = child->bs;
     BlockDriver *drv = bs->drv;
     int ret;
+
+    assert(child->perm & BLK_PERM_RESIZE);
+
     if (!drv)
         return -ENOMEDIUM;
     if (!drv->bdrv_truncate)
index 4c797454a4ed8315306ee1e09628f38e3fd22a67..8f38d46de008297f6ea453da38f0d17c21ae5dbb 100644 (file)
@@ -1339,6 +1339,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
     assert(req->overlap_offset <= offset);
     assert(offset + bytes <= req->overlap_offset + req->overlap_bytes);
     assert(child->perm & BLK_PERM_WRITE);
+    assert(end_sector <= bs->total_sectors || child->perm & BLK_PERM_RESIZE);
 
     ret = notifier_with_return_list_notify(&bs->before_write_notifiers, req);