Received: from eggs.gnu.org ([2001:4830:134:3::10]:53952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2mO-0006dn-GE for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VF2mE-00085j-Ib for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:00:56 -0400 Received: from mail-ee0-x22a.google.com ([2a00:1450:4013:c00::22a]:48715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2mD-00085R-Pj for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:00:46 -0400 Received: by mail-ee0-f42.google.com with SMTP id b45so267683eek.15 for ; Thu, 29 Aug 2013 07:00:44 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 29 Aug 2013 16:00:06 +0200 Message-Id: <1377784821-29561-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> References: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v4 06/21] 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: kwolf@redhat.com, stefanha@redhat.com This is more robust when the device has removable media. Signed-off-by: Paolo Bonzini --- block.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index fc5ea56..bef7d37 100644 --- a/block.c +++ b/block.c @@ -2991,9 +2991,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