[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 34/36] block/file-posix: Unaligned O_DIRECT block-s
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 34/36] block/file-posix: Unaligned O_DIRECT block-status |
Date: |
Tue, 23 Jul 2019 12:01:02 -0500 |
From: Max Reitz <address@hidden>
Currently, qemu crashes whenever someone queries the block status of an
unaligned image tail of an O_DIRECT image:
$ echo > foo
$ qemu-img map --image-opts driver=file,filename=foo,cache.direct=on
Offset Length Mapped to File
qemu-img: block/io.c:2093: bdrv_co_block_status: Assertion `*pnum &&
QEMU_IS_ALIGNED(*pnum, align) && align > offset - aligned_offset'
failed.
This is because bdrv_co_block_status() checks that the result returned
by the driver's implementation is aligned to the request_alignment, but
file-posix can fail to do so, which is actually mentioned in a comment
there: "[...] possibly including a partial sector at EOF".
Fix this by rounding up those partial sectors.
There are two possible alternative fixes:
(1) We could refuse to open unaligned image files with O_DIRECT
altogether. That sounds reasonable until you realize that qcow2
does necessarily not fill up its metadata clusters, and that nobody
runs qemu-img create with O_DIRECT. Therefore, unpreallocated qcow2
files usually have an unaligned image tail.
(2) bdrv_co_block_status() could ignore unaligned tails. It actually
throws away everything past the EOF already, so that sounds
reasonable.
Unfortunately, the block layer knows file lengths only with a
granularity of BDRV_SECTOR_SIZE, so bdrv_co_block_status() usually
would have to guess whether its file length information is inexact
or whether the driver is broken.
Fixing what raw_co_block_status() returns is the safest thing to do.
There seems to be no other block driver that sets request_alignment and
does not make sure that it always returns aligned values.
Cc: address@hidden
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
(cherry picked from commit 9c3db310ff0b7473272ae8dce5e04e2f8a825390)
Signed-off-by: Michael Roth <address@hidden>
---
block/file-posix.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/block/file-posix.c b/block/file-posix.c
index 07bbdab953..df467f510b 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2461,6 +2461,8 @@ static int coroutine_fn
raw_co_block_status(BlockDriverState *bs,
off_t data = 0, hole = 0;
int ret;
+ assert(QEMU_IS_ALIGNED(offset | bytes, bs->bl.request_alignment));
+
ret = fd_open(bs);
if (ret < 0) {
return ret;
@@ -2486,6 +2488,20 @@ static int coroutine_fn
raw_co_block_status(BlockDriverState *bs,
/* On a data extent, compute bytes to the end of the extent,
* possibly including a partial sector at EOF. */
*pnum = MIN(bytes, hole - offset);
+
+ /*
+ * We are not allowed to return partial sectors, though, so
+ * round up if necessary.
+ */
+ if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) {
+ int64_t file_length = raw_getlength(bs);
+ if (file_length > 0) {
+ /* Ignore errors, this is just a safeguard */
+ assert(hole == file_length);
+ }
+ *pnum = ROUND_UP(*pnum, bs->bl.request_alignment);
+ }
+
ret = BDRV_BLOCK_DATA;
} else {
/* On a hole, compute bytes to the beginning of the next extent. */
--
2.17.1
- [Qemu-stable] [PATCH 22/36] mac_oldworld: use node name instead of alias name for hd device in FWPathProvider, (continued)
- [Qemu-stable] [PATCH 22/36] mac_oldworld: use node name instead of alias name for hd device in FWPathProvider, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 01/36] i2c: Move typedef of bitbang_i2c_interface to i2c.h, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 03/36] Changes requirement for "vsubsbs" instruction, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 02/36] iotests: make 235 work on s390 (and others), Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 06/36] hw/s390x: Fix bad mask in time2tod(), Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 33/36] iotests: Filter second BLOCK_JOB_ERROR from 229, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 05/36] pc:piix4: Update smbus I/O space after a migration, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 31/36] s390x/cpumodel: ignore csske for expansion, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 34/36] block/file-posix: Unaligned O_DIRECT block-status,
Michael Roth <=
- [Qemu-stable] [PATCH 32/36] megasas: fix mapped frame size, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 35/36] iotests: Test unaligned raw images with O_DIRECT, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 36/36] vhost: fix vhost_log size overflow during migration, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 08/36] s390x: Return specification exception for unimplemented diag 308 subcodes, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 04/36] pcie: set link state inactive/active after hot unplug/plug, Michael Roth, 2019/07/23
- [Qemu-stable] [PATCH 07/36] linux-user: make pwrite64/pread64(fd, NULL, 0, offset) return 0, Michael Roth, 2019/07/23
- Re: [Qemu-stable] [Qemu-devel] [PATCH 00/36] Patch Round-up for stable 3.1.1, freeze on 2019-07-29, Aleksandar Markovic, 2019/07/23
- Re: [Qemu-stable] [PATCH 00/36] Patch Round-up for stable 3.1.1, freeze on 2019-07-29, Michael Roth, 2019/07/23