Description of problem: glibc misses sync_file_range syscall interface. The header file and man page both say 'sync_file_range' should exist. From man page, sync_file_range should exist sinc kernel-2.6.17 Version-Release number of selected component (if applicable): RHEL-5.3 glibc-2.5-34 How reproducible: 100% Steps to Reproduce: 1. use nm to detect symbol ~]# nm -D /lib64/*.so* | fgrep sync_file_range nothing found. 2. use gcc to detect symbol ~]# cat s.cc #define __GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> char buffer[10000]; int main() { int fd = open("./xxx", O_RDWR|O_CREAT, 0666); if (fd < 0) { perror("open"); exit(1); } if (write(fd, &buffer, sizeof(buffer)) <= 0) { perror("write"); exit(1); } if (sync_file_range(fd, 0, 8192, SYNC_FILE_RANGE_WRITE) < 0) { perror("sync_file_range"); exit(1); } } ~]# g++ s.cc -lrt -lpthread -lcrypt -lutil -lresolv -lm -lnsl -lanl -lcidn /tmp/ccOaK6Vj.o: In function `main': s.cc:(.text+0x81): undefined reference to `sync_file_range' collect2: ld returned 1 exit status Actual results: nm found no .so contains sync_file_range Expected results: Additional info:
It has only been added to glibc 2.6, and cannot be backported due to ABI breakage. You can always fall back to syscall(3).
Can give me a example how to use syscall(3) to call sync_file_range?
As comment #1 says, no chance to backport this. See the syscall man page for instructions.
then why document it if it's broken and you're not going to fix it? .. might want to FTFM over at sync_file_range(2) - in the meantime - borrowing from glibc 2.6 .. any thoughts on this implementation for a hacky workaround for those still on your "ancient releases" .. (eg: RHEL5.3)?: #ifdef ULI_WONT_FIX_THIS_IN_GLIBC2.5 #define NR_sync_file_range 277 int sync_file_range (int fd, __off64_t from, __off64_t to, unsigned int flags) { return syscall (NR_sync_file_range, fd, __LONG_LONG_PAIR ((long) (from >> 32), (long) from), __LONG_LONG_PAIR ((long) (to >> 32), (long) to), flags); } #endif assuming of course that you're on an x86_64 and include/asm-x86_64/unistd.h has the correct entry (fwiw - fio is starting to use this now)