|
|
cce96bf |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
cce96bf |
Date: Tue, 9 Jun 2015 10:45:16 +0200
|
|
|
cce96bf |
Subject: [PATCH] raw-posix: Fix .bdrv_co_get_block_status() for unaligned
|
|
|
cce96bf |
image size
|
|
|
cce96bf |
|
|
|
cce96bf |
Image files with an unaligned image size have a final hole that starts
|
|
|
cce96bf |
at EOF, i.e. in the middle of a sector. Currently, *pnum == 0 is
|
|
|
cce96bf |
returned when checking the status of this sector. In qemu-img, this
|
|
|
cce96bf |
triggers an assertion failure.
|
|
|
cce96bf |
|
|
|
cce96bf |
In order to fix this, one type for the sector that contains EOF must be
|
|
|
cce96bf |
found. Treating a hole as data is safe, so this patch rounds the
|
|
|
cce96bf |
calculated number of data sectors up, so that a partial sector at EOF is
|
|
|
cce96bf |
treated as a full data sector.
|
|
|
cce96bf |
|
|
|
cce96bf |
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1229394
|
|
|
cce96bf |
|
|
|
cce96bf |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
cce96bf |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
cce96bf |
Tested-by: Cole Robinson <crobinso@redhat.com>
|
|
|
cce96bf |
(cherry picked from commit b8684454e152ca2e100f4b59d80de2be27186206)
|
|
|
cce96bf |
---
|
|
|
cce96bf |
block/raw-posix.c | 5 +++--
|
|
|
cce96bf |
1 file changed, 3 insertions(+), 2 deletions(-)
|
|
|
cce96bf |
|
|
|
cce96bf |
diff --git a/block/raw-posix.c b/block/raw-posix.c
|
|
|
cce96bf |
index 24d8582..88f0462 100644
|
|
|
cce96bf |
--- a/block/raw-posix.c
|
|
|
cce96bf |
+++ b/block/raw-posix.c
|
|
|
cce96bf |
@@ -1846,8 +1846,9 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
|
|
|
cce96bf |
*pnum = nb_sectors;
|
|
|
cce96bf |
ret = BDRV_BLOCK_DATA;
|
|
|
cce96bf |
} else if (data == start) {
|
|
|
cce96bf |
- /* On a data extent, compute sectors to the end of the extent. */
|
|
|
cce96bf |
- *pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE);
|
|
|
cce96bf |
+ /* On a data extent, compute sectors to the end of the extent,
|
|
|
cce96bf |
+ * possibly including a partial sector at EOF. */
|
|
|
cce96bf |
+ *pnum = MIN(nb_sectors, DIV_ROUND_UP(hole - start, BDRV_SECTOR_SIZE));
|
|
|
cce96bf |
ret = BDRV_BLOCK_DATA;
|
|
|
cce96bf |
} else {
|
|
|
cce96bf |
/* On a hole, compute sectors to the beginning of the next extent. */
|