From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGS3-0002cD-L9 for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHGRv-00064k-7a for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:07 -0400 Received: from mail-qc0-x232.google.com ([2607:f8b0:400d:c01::232]:63124) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGRv-00064e-2y for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:00:59 -0400 Received: by mail-qc0-f178.google.com with SMTP id r5so319933qcx.9 for ; Wed, 04 Sep 2013 10:00:58 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Sep 2013 19:00:23 +0200 Message-Id: <1378314038-15525-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> References: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v5 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: 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 0e95b47..410d5dd 100644 --- a/block.c +++ b/block.c @@ -3045,9 +3045,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