* [PATCH v2] block: allocate aligned write buffer for 'truncate -m full'
@ 2026-09-23 16:22 Andrey Drobyshev
2026-09-25 13:25 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Andrey Drobyshev @ 2026-09-23 16:22 UTC (permalink / raw)
To: qemu-block; +Cc: qemu-devel, kwolf, hreitz, vsementsov, den, andrey.drobyshev
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] block: allocate aligned write buffer for 'truncate -m full'
2026-09-23 16:22 [PATCH v2] block: allocate aligned write buffer for 'truncate -m full' Andrey Drobyshev
@ 2026-09-25 13:25 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2026-09-25 13:25 UTC (permalink / raw)
To: Andrey Drobyshev; +Cc: qemu-block, qemu-devel, hreitz, vsementsov, den
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-25 13:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 16:22 [PATCH v2] block: allocate aligned write buffer for 'truncate -m full' Andrey Drobyshev
2026-09-25 13:25 ` Kevin Wolf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.