[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 24/27] file-posix: Fix no-op bdrv_truncate() with fa
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 24/27] file-posix: Fix no-op bdrv_truncate() with falloc preallocation |
Date: |
Thu, 8 Feb 2018 20:23:25 +0100 |
If bdrv_truncate() is called, but the requested size is the same as
before, don't call posix_fallocate(), which returns -EINVAL for length
zero and would therefore make bdrv_truncate() fail.
The problem can be triggered by creating a zero-sized raw image with
'falloc' preallocation mode.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/file-posix.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 9ae5b7dcdf..15819a00b9 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1683,11 +1683,15 @@ static int raw_regular_truncate(int fd, int64_t offset,
PreallocMode prealloc,
* file systems that do not support fallocate(), trying to check if a
* block is allocated before allocating it, so don't do that here.
*/
- result = -posix_fallocate(fd, current_length, offset - current_length);
- if (result != 0) {
- /* posix_fallocate() doesn't set errno. */
- error_setg_errno(errp, -result,
- "Could not preallocate new data");
+ if (offset != current_length) {
+ result = -posix_fallocate(fd, current_length, offset -
current_length);
+ if (result != 0) {
+ /* posix_fallocate() doesn't set errno. */
+ error_setg_errno(errp, -result,
+ "Could not preallocate new data");
+ }
+ } else {
+ result = 0;
}
goto out;
#endif
--
2.13.6
- [Qemu-devel] [PATCH 18/27] sheepdog: QAPIfy "redundacy" create option, (continued)
- [Qemu-devel] [PATCH 18/27] sheepdog: QAPIfy "redundacy" create option, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 19/27] sheepdog: Support .bdrv_co_create, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 20/27] ssh: Use QAPI BlockdevOptionsSsh object, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 21/27] ssh: QAPIfy host-key-check option, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 22/27] ssh: Pass BlockdevOptionsSsh to connect_to_ssh(), Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 24/27] file-posix: Fix no-op bdrv_truncate() with falloc preallocation,
Kevin Wolf <=
- [Qemu-devel] [PATCH 23/27] ssh: Support .bdrv_co_create, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 25/27] block: Fail bdrv_truncate() with negative size, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 26/27] qemu-iotests: Test qcow2 over file image creation with QMP, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 27/27] qemu-iotests: Test ssh image creation over QMP, Kevin Wolf, 2018/02/08