Blame SOURCES/kvm-block-do-not-use-total_sectors-in-bdrv_co_is_allocat.patch

218e99
From 0dbbdb969ae54cf3042ec60f740e9c4773726013 Mon Sep 17 00:00:00 2001
218e99
From: Paolo Bonzini <pbonzini@redhat.com>
218e99
Date: Fri, 18 Oct 2013 08:14:31 +0200
218e99
Subject: [PATCH 06/81] block: do not use ->total_sectors in bdrv_co_is_allocated
218e99
218e99
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
218e99
Message-id: <1382084091-16636-7-git-send-email-pbonzini@redhat.com>
218e99
Patchwork-id: 54989
218e99
O-Subject: [RHEL 7.0 qemu-kvm PATCH 06/26] block: do not use ->total_sectors in bdrv_co_is_allocated
218e99
Bugzilla: 989646
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
218e99
This is more robust when the device has removable media.
218e99
218e99
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
(cherry picked from commit 617ccb466e1937a5c99332ce77a47ebd29861ae4)
218e99
---
218e99
 block.c | 8 +++++++-
218e99
 1 file changed, 7 insertions(+), 1 deletion(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block.c |    8 +++++++-
218e99
 1 files changed, 7 insertions(+), 1 deletions(-)
218e99
218e99
diff --git a/block.c b/block.c
218e99
index 0607cc6..9ea8221 100644
218e99
--- a/block.c
218e99
+++ b/block.c
218e99
@@ -3031,9 +3031,15 @@ static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs,
218e99
                                              int64_t sector_num,
218e99
                                              int nb_sectors, int *pnum)
218e99
 {
218e99
+    int64_t length;
218e99
     int64_t n;
218e99
 
218e99
-    if (sector_num >= bs->total_sectors) {
218e99
+    length = bdrv_getlength(bs);
218e99
+    if (length < 0) {
218e99
+        return length;
218e99
+    }
218e99
+
218e99
+    if (sector_num >= (length >> BDRV_SECTOR_BITS)) {
218e99
         *pnum = 0;
218e99
         return 0;
218e99
     }
218e99
-- 
218e99
1.7.1
218e99