Skip to content

Commit

Permalink
fvec: fix posix_fallocate for unsupported filesystems
Browse files Browse the repository at this point in the history
we use ftruncate if posix_fallocate does not work
  • Loading branch information
sebsura committed Feb 12, 2024
1 parent 4806ac8 commit ea3256a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/src/stored/backends/dedup/fvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,18 @@ template <typename T> class fvec : access {
{
if (auto err = posix_fallocate(fd, 0, new_size); err != 0) {
// posix_fallocate does not set errno
throw std::system_error(
err, std::generic_category(),
"posix_fallocate (new size = " + std::to_string(new_size) + ")");
if (err == EINVAL || err == EOPNOTSUPP) {
// some filesystems do not support posix_fallocate. In these cases
// we fall back to ftruncate
if (ftruncate(fd, new_size) != 0) {
throw error("ftruncate/allocate (new size = "
+ std::to_string(new_size) + ")");
}
} else {
throw std::system_error(
err, std::generic_category(),
"posix_fallocate (new size = " + std::to_string(new_size) + ")");
}
}
}

Expand Down

0 comments on commit ea3256a

Please sign in to comment.