From f0a1a1676b6cd2681df62a6a26ebf43cd86cfba1 Mon Sep 17 00:00:00 2001 From: Simon Bertron Date: Tue, 14 Apr 2026 15:49:18 -0400 Subject: [PATCH] SETUP: fix fallocate bug EOPNOTSUPP needs to be compared to errno, not the fallocate return value. Along the way, define a constant for the superblock size because it gets used a lot in that section. Signed-off-by: Simon Bertron --- src/platform_linux/laio.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/platform_linux/laio.c b/src/platform_linux/laio.c index 3e1f7e1e..2e2395a6 100644 --- a/src/platform_linux/laio.c +++ b/src/platform_linux/laio.c @@ -594,13 +594,16 @@ laio_handle_create(io_config *cfg, platform_heap_id hid) return NULL; } - if (S_ISREG(statbuf.st_mode) && statbuf.st_size < 128 * 1024) { - r = fallocate(io->fd, 0, 0, 128 * 1024); - if (r == EOPNOTSUPP) { + +#define SUPERBLOCK_SIZE 128 * 1024 + + if (S_ISREG(statbuf.st_mode) && statbuf.st_size < SUPERBLOCK_SIZE) { + r = fallocate(io->fd, 0, 0, SUPERBLOCK_SIZE); + if (r && errno == EOPNOTSUPP) { if (statbuf.st_size == 0) { - uint8_t zeroes[128 * 1024] = {0}; - r = pwrite(io->fd, &zeroes, 128 * 1024, 0); - if (r) { + uint8_t zeroes[SUPERBLOCK_SIZE] = {0}; + r = pwrite(io->fd, &zeroes, SUPERBLOCK_SIZE, 0); + if (r != SUPERBLOCK_SIZE) { platform_error_log("fallocate not supported by filesystem and " "fallback write failed: %s\n", strerror(errno)); @@ -626,6 +629,8 @@ laio_handle_create(io_config *cfg, platform_heap_id hid) } } +#undef SUPERBLOCK_SIZE + io->pecnode.termination = laio_process_termination_callback; io->pecnode.arg = io; platform_linux_add_process_event_callback(&io->pecnode);