Blame SOURCES/kvm-raw-posix-Fix-.bdrv_co_get_block_status-for-unaligne.patch

34b321
From 4237964a9f433faaf643166a8ce9c070dc4cf165 Mon Sep 17 00:00:00 2001
95f32b
From: Max Reitz <mreitz@redhat.com>
34b321
Date: Thu, 14 Jan 2016 15:10:31 +0100
95f32b
Subject: [PATCH] raw-posix: Fix .bdrv_co_get_block_status() for unaligned
95f32b
 image size
95f32b
34b321
Message-id: <1452784231-14211-2-git-send-email-mreitz@redhat.com>
34b321
Patchwork-id: 68756
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH 1/1] raw-posix: Fix .bdrv_co_get_block_status() for unaligned image size
34b321
Bugzilla: 1283116
95f32b
RH-Acked-by: Fam Zheng <famz@redhat.com>
95f32b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
95f32b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
95f32b
95f32b
From: Kevin Wolf <kwolf@redhat.com>
95f32b
95f32b
Image files with an unaligned image size have a final hole that starts
95f32b
at EOF, i.e. in the middle of a sector. Currently, *pnum == 0 is
95f32b
returned when checking the status of this sector. In qemu-img, this
95f32b
triggers an assertion failure.
95f32b
95f32b
In order to fix this, one type for the sector that contains EOF must be
95f32b
found. Treating a hole as data is safe, so this patch rounds the
95f32b
calculated number of data sectors up, so that a partial sector at EOF is
95f32b
treated as a full data sector.
95f32b
95f32b
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1229394
95f32b
95f32b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
95f32b
Reviewed-by: Eric Blake <eblake@redhat.com>
95f32b
Tested-by: Cole Robinson <crobinso@redhat.com>
95f32b
(cherry picked from commit b8684454e152ca2e100f4b59d80de2be27186206)
95f32b
Signed-off-by: Max Reitz <mreitz@redhat.com>
95f32b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
95f32b
---
95f32b
 block/raw-posix.c | 5 +++--
95f32b
 1 file changed, 3 insertions(+), 2 deletions(-)
95f32b
95f32b
diff --git a/block/raw-posix.c b/block/raw-posix.c
95f32b
index 72a9dc0..1f5275f 100644
95f32b
--- a/block/raw-posix.c
95f32b
+++ b/block/raw-posix.c
95f32b
@@ -1452,8 +1452,9 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
95f32b
         *pnum = nb_sectors;
95f32b
         ret = BDRV_BLOCK_DATA;
95f32b
     } else if (data == start) {
95f32b
-        /* On a data extent, compute sectors to the end of the extent.  */
95f32b
-        *pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE);
95f32b
+        /* On a data extent, compute sectors to the end of the extent,
95f32b
+         * possibly including a partial sector at EOF. */
95f32b
+        *pnum = MIN(nb_sectors, DIV_ROUND_UP(hole - start, BDRV_SECTOR_SIZE));
95f32b
         ret = BDRV_BLOCK_DATA;
95f32b
     } else {
95f32b
         /* On a hole, compute sectors to the beginning of the next extent.  */
95f32b
-- 
95f32b
1.8.3.1
95f32b