From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciRe4-0000ri-Ud for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:11:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciRe4-0003v2-0b for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:11:44 -0500 From: Kevin Wolf Date: Mon, 27 Feb 2017 21:09:42 +0100 Message-Id: <1488226184-9044-42-git-send-email-kwolf@redhat.com> In-Reply-To: <1488226184-9044-1-git-send-email-kwolf@redhat.com> References: <1488226184-9044-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2 41/43] block: Assertions for resize permission List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, jcody@redhat.com, famz@redhat.com, qemu-devel@nongnu.org This adds an assertion that ensures that the necessary resize permission has been granted before bdrv_truncate() is called. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 3 +++ block/io.c | 1 + 2 files changed, 4 insertions(+) diff --git a/block.c b/block.c index af2b8ff..5118828 100644 --- a/block.c +++ b/block.c @@ -3110,6 +3110,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) diff --git a/block/io.c b/block/io.c index 4c79745..8f38d46 100644 --- a/block/io.c +++ b/block/io.c @@ -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); -- 1.8.3.1