Fix compile on older systems that don't have fallocate() on Linux
authorJens Axboe <jaxboe@fusionio.com>
Tue, 12 Jul 2011 18:49:46 +0000 (20:49 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Tue, 12 Jul 2011 18:49:46 +0000 (20:49 +0200)
Commit a596f047 broke build en eg CentOS 5:

filesetup.c:17:26: error: linux/falloc.h: No such file or directory
filesetup.c: In function 'extend_file':
filesetup.c:95: warning: implicit declaration of function 'fallocate'
filesetup.c:95: error: 'FALLOC_FL_KEEP_SIZE' undeclared (first use in this function)
filesetup.c:95: error: (Each undeclared identifier is reported only once
filesetup.c:95: error: for each function it appears in.)
make: *** [filesetup.o] Error 1

Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
helpers.c
helpers.h
os/os-linux.h

index 1b6dea8e19b684862233a9814c82e9f299fb71c9..95625672b3417f0146e2f0c492a93ac4d54c54c0 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -9,6 +9,12 @@
 #include "arch/arch.h"
 #include "os/os.h"
 
+int _weak fallocate(int fd, int mode, off_t offset, off_t len)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
 #ifndef __NR_fallocate
 int _weak posix_fallocate(int fd, off_t offset, off_t len)
 {
index 7b1ad3493c60624863e60f67602b03cab86aa145..da20a6bac38465438437c7b376611f892ac9e735 100644 (file)
--- a/helpers.h
+++ b/helpers.h
@@ -7,6 +7,7 @@
 
 struct in_addr;
 
+extern int _weak fallocate(int fd, int mode, off_t offset, off_t len);
 extern int _weak posix_memalign(void **ptr, size_t align, size_t size);
 extern int _weak posix_fallocate(int fd, off_t offset, off_t len);
 extern int _weak inet_aton(const char *cp, struct in_addr *inp);
index 024ef89ae23d1d4548b6c4a7982de9db1b6913b2..34a7cc53fb33d680e6750bd16c20e127ed51df89 100644 (file)
@@ -32,7 +32,6 @@
 #define FIO_HAVE_BLKTRACE
 #define FIO_HAVE_STRSEP
 #define FIO_HAVE_FALLOCATE
-#define FIO_HAVE_LINUX_FALLOCATE
 #define FIO_HAVE_POSIXAIO_FSYNC
 #define FIO_HAVE_PSHARED_MUTEX
 #define FIO_HAVE_CL_SIZE
 #define FIO_HAVE_BINJECT
 #define FIO_HAVE_CLOCK_MONOTONIC
 
+/*
+ * Can only enable this for newer glibcs, or the header and defines are
+ * missing
+ */
+#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 6
+#define FIO_HAVE_LINUX_FALLOCATE
+#endif
+
 #ifdef SYNC_FILE_RANGE_WAIT_BEFORE
 #define FIO_HAVE_SYNC_FILE_RANGE
 #endif