diff --git a/util/file_allocator.cpp b/util/file_allocator.cpp index b0572f9..567de10 100644 --- a/util/file_allocator.cpp +++ b/util/file_allocator.cpp @@ -23,6 +23,11 @@ #include #endif +#if defined(__linux__) +#include +#include +#endif + #include "timer.h" #include "mongoutils/str.h" using namespace mongoutils; @@ -142,6 +147,19 @@ namespace mongo { void FileAllocator::ensureLength(int fd , long size) { #if defined(__linux__) + { + // Detect NFS and use ftruncate rather than fallocate + struct statfs fs_stats; + int ret = fstatfs(fd, &fs_stats); + uassert(15933, "fstatfs failed: " + errnoWithDescription(), ret == 0); + + if (fs_stats.f_type == NFS_SUPER_MAGIC) { + ret = ftruncate(fd, size); + uassert(15934, "ftruncate failed: " + errnoWithDescription(), ret == 0); + return; + } + } + int ret = posix_fallocate(fd,0,size); if ( ret == 0 ) return;