Received: from eggs.gnu.org ([2001:4830:134:3::10]:40602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy9E-0005eM-2L for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHy98-0005a3-0n for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy97-0005Zt-PS for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:29 -0400 From: Stefan Hajnoczi Date: Fri, 6 Sep 2013 17:38:55 +0200 Message-Id: <1378481953-23099-25-git-send-email-stefanha@redhat.com> In-Reply-To: <1378481953-23099-1-git-send-email-stefanha@redhat.com> References: <1378481953-23099-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 24/42] block: do not use ->total_sectors in bdrv_co_is_allocated List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Stefan Hajnoczi , Anthony Liguori From: Paolo Bonzini This is more robust when the device has removable media. Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- block.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index f27bab6..4a10fb1 100644 --- a/block.c +++ b/block.c @@ -3065,9 +3065,15 @@ static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { + int64_t length; int64_t n; - if (sector_num >= bs->total_sectors) { + length = bdrv_getlength(bs); + if (length < 0) { + return length; + } + + if (sector_num >= (length >> BDRV_SECTOR_BITS)) { *pnum = 0; return 0; } -- 1.8.3.1