From 2930dcbb3329bdd0e2832b678b54b344b2a0adaf Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Sat, 1 Apr 2023 00:38:40 +0000 Subject: [PATCH] util/disk_cache: fall back to ftruncate if posix_fallocate isn't supported posix_fallocate isn't supported on ZFS. FreeBSD returns EINVAL while Linux returns EOPNOTSUPP. Fixes: 88d074cb8f38 ("util/disk_cache: use posix_fallocate() for index files") --- src/util/disk_cache_os.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index e3596f2b4b02b..0d683196589f2 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -1021,18 +1021,18 @@ disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache, if (sb.st_size != size) { #if HAVE_POSIX_FALLOCATE /* posix_fallocate() ensures disk space is allocated otherwise it - * fails if there is not enough space on the disk. + * fails if there is not enough space on the disk. If not supported + * by the filesystem fall back to ftruncate(). */ - if (posix_fallocate(fd, 0, size) != 0) + if ((errno = posix_fallocate(fd, 0, size)) != 0 && errno != EINVAL && errno != EOPNOTSUPP) goto path_fail; -#else +#endif /* ftruncate() allocates disk space lazily. If the disk is full * and it is unable to allocate disk space when accessed via * mmap, it will crash with a SIGBUS. */ if (ftruncate(fd, size) == -1) goto path_fail; -#endif } /* We map this shared so that other processes see updates that we -- GitLab