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