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);