From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgxOq-0004Xk-NZ for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:00:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgxOj-0000VH-6F for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:00:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60745) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgxOi-0000Uy-Uc for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:00:25 -0400 From: Max Reitz Date: Wed, 22 Oct 2014 17:00:15 +0200 Message-Id: <1413990017-19213-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1413990017-19213-1-git-send-email-mreitz@redhat.com> References: <1413990017-19213-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 1/3] block: Respect underlying file's EOF List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , Max Reitz When falling through to the underlying file in bdrv_co_get_block_status(), if it returns that the query offset is beyond the file end (by setting *pnum to 0), return the range to be zero and do not let the number of sectors for which information could be obtained be overwritten. Signed-off-by: Max Reitz --- block.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index bbb04e7..88f6d9b 100644 --- a/block.c +++ b/block.c @@ -3954,13 +3954,24 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, if (bs->file && (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID)) { + int file_pnum; + ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS, - *pnum, pnum); + *pnum, &file_pnum); if (ret2 >= 0) { /* Ignore errors. This is just providing extra information, it * is useful but not necessary. */ - ret |= (ret2 & BDRV_BLOCK_ZERO); + if (!file_pnum) { + /* !file_pnum indicates an offset at or beyond the EOF; it is + * perfectly valid for the format block driver to point to such + * offsets, so catch it and mark everything as zero */ + ret |= BDRV_BLOCK_ZERO; + } else { + /* Limit request to the range reported by the protocol driver */ + *pnum = file_pnum; + ret |= (ret2 & BDRV_BLOCK_ZERO); + } } } -- 1.9.3