thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 69fe324e32aad7e1afc6ad14021a6a08ad52646c Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Sat, 13 Jun 2015 16:22:27 +0200
9ae3a8
Subject: [PATCH 33/42] block: Respect underlying file's EOF
9ae3a8
9ae3a8
Message-id: <1434212556-3927-34-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 66052
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH 33/42] block: Respect underlying file's EOF
9ae3a8
Bugzilla: 1129893
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1129893
9ae3a8
9ae3a8
When falling through to the underlying file in
9ae3a8
bdrv_co_get_block_status(), if it returns that the query offset is
9ae3a8
beyond the file end (by setting *pnum to 0), return the range to be
9ae3a8
zero and do not let the number of sectors for which information could be
9ae3a8
obtained be overwritten.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 59c9a95fd29cfb3296ee58e8a446df251d14a459)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c | 15 +++++++++++++--
9ae3a8
 1 file changed, 13 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 22ab762..fa6e192 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -3797,13 +3797,24 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
9ae3a8
     if (bs->file &&
9ae3a8
         (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
9ae3a8
         (ret & BDRV_BLOCK_OFFSET_VALID)) {
9ae3a8
+        int file_pnum;
9ae3a8
+
9ae3a8
         ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS,
9ae3a8
-                                        *pnum, pnum);
9ae3a8
+                                        *pnum, &file_pnum);
9ae3a8
         if (ret2 >= 0) {
9ae3a8
             /* Ignore errors.  This is just providing extra information, it
9ae3a8
              * is useful but not necessary.
9ae3a8
              */
9ae3a8
-            ret |= (ret2 & BDRV_BLOCK_ZERO);
9ae3a8
+            if (!file_pnum) {
9ae3a8
+                /* !file_pnum indicates an offset at or beyond the EOF; it is
9ae3a8
+                 * perfectly valid for the format block driver to point to such
9ae3a8
+                 * offsets, so catch it and mark everything as zero */
9ae3a8
+                ret |= BDRV_BLOCK_ZERO;
9ae3a8
+            } else {
9ae3a8
+                /* Limit request to the range reported by the protocol driver */
9ae3a8
+                *pnum = file_pnum;
9ae3a8
+                ret |= (ret2 & BDRV_BLOCK_ZERO);
9ae3a8
+            }
9ae3a8
         }
9ae3a8
     }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8