block/file-posix.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
In case we're truncating an image opened with O_DIRECT, we might get
-EINVAL on write with unaligned buffer. In particular, when running
iotests/298 with '-nocache' we get:
qemu-io: Failed to resize underlying file: Could not write zeros for
preallocation: Invalid argument
Let's just allocate the buffer using qemu_blockalign0() instead.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
iotests/298 with '-nocache' is still failing, so sending this once more.
v1 -> v2: use QEMU_AUTO_VFREE (Vladimir)
v1: https://lore.kernel.org/qemu-devel/20231211105559.316897-1-andrey.drobyshev@virtuozzo.com/
block/file-posix.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 9aad156aad4..39d6a34456c 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2366,7 +2366,7 @@ static int handle_aiocb_truncate(void *opaque)
RawPosixAIOData *aiocb = opaque;
int result = 0;
int64_t current_length = 0;
- char *buf = NULL;
+ QEMU_AUTO_VFREE char *buf = NULL;
struct stat st;
int fd = aiocb->aio_fildes;
int64_t offset = aiocb->aio_offset;
@@ -2433,7 +2433,7 @@ static int handle_aiocb_truncate(void *opaque)
goto out;
}
- buf = g_malloc0(65536);
+ buf = qemu_blockalign0(aiocb->bs, 65536);
seek_result = lseek(fd, current_length, SEEK_SET);
if (seek_result < 0) {
@@ -2492,7 +2492,6 @@ out:
}
}
- g_free(buf);
return result;
}
--
2.47.1
Am 23.09.2026 um 18:22 hat Andrey Drobyshev geschrieben: > In case we're truncating an image opened with O_DIRECT, we might get > -EINVAL on write with unaligned buffer. In particular, when running > iotests/298 with '-nocache' we get: > > qemu-io: Failed to resize underlying file: Could not write zeros for > preallocation: Invalid argument > > Let's just allocate the buffer using qemu_blockalign0() instead. > > Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> > Reviewed-by: Denis V. Lunev <den@openvz.org> > Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Thanks, applied to the block branch. Kevin
© 2016 - 2026 Red Hat, Inc.