Skip to content

Commit

Permalink
block: Assertions for resize permission
Browse files Browse the repository at this point in the history
This adds an assertion that ensures that the necessary resize permission
has been granted before bdrv_truncate() is called.

Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Acked-by: Fam Zheng <[email protected]>
  • Loading branch information
kevmw committed Feb 28, 2017
1 parent afa4b29 commit c8f6d58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions block/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c8f6d58

Please sign in to comment.