]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e4defrag: choose the best available posix_fadvise variant
authorBaruch Siach <baruch@tkos.co.il>
Thu, 2 Jan 2014 18:05:37 +0000 (13:05 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 6 Jan 2014 03:55:10 +0000 (22:55 -0500)
Use posix_fadvise64() when available.  This allows 64bit offsets on
32bit systems.

[ Modified by tytso to try to use fadvise64() as well, and to remove
  the attempt to call the syscall directly, since because and
  complexities caused by required dummy arguments on some
  architectures, it's not worth the hair.  ]

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
configure
configure.in
lib/config.h.in
misc/e4defrag.c

index 6f8f1ab73553dba0f301cb87e1b700ec9ba6b4ef..5943849fbf0d1387a8484c3b33fcc8e423c1c4e1 100755 (executable)
--- a/configure
+++ b/configure
@@ -11051,7 +11051,7 @@ if test "$ac_res" != no; then :
 fi
 
 fi
-for ac_func in         __secure_getenv         backtrace       blkid_probe_get_topology        chflags         fallocate       fallocate64     fchown  fdatasync       fstat64         ftruncate64     futimes         getdtablesize   getmntinfo      getpwuid_r      getrlimit       getrusage       jrand48         llseek  lseek64         mallinfo        mbstowcs        memalign        mmap    msync   nanosleep       open64  pathconf        posix_fadvise   posix_memalign  prctl   secure_getenv   setmntent       setresgid       setresuid       srandom         strcasecmp      strdup  strnlen         strptime        strtoull        sync_file_range         sysconf         usleep  utime   valloc
+for ac_func in         __secure_getenv         backtrace       blkid_probe_get_topology        chflags         fadvise64       fallocate       fallocate64     fchown  fdatasync       fstat64         ftruncate64     futimes         getdtablesize   getmntinfo      getpwuid_r      getrlimit       getrusage       jrand48         llseek  lseek64         mallinfo        mbstowcs        memalign        mmap    msync   nanosleep       open64  pathconf        posix_fadvise   posix_fadvise64         posix_memalign  prctl   secure_getenv   setmntent       setresgid       setresuid       srandom         strcasecmp      strdup  strnlen         strptime        strtoull        sync_file_range         sysconf         usleep  utime   valloc
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index b70a3f9a949bf30560b5e295eded43160fb66880..214d3f69703b874dcde93352a387a06114438d5a 100644 (file)
@@ -1026,6 +1026,7 @@ AC_CHECK_FUNCS(m4_flatten([
        backtrace
        blkid_probe_get_topology
        chflags
+       fadvise64
        fallocate
        fallocate64
        fchown
@@ -1050,6 +1051,7 @@ AC_CHECK_FUNCS(m4_flatten([
        open64
        pathconf
        posix_fadvise
+       posix_fadvise64
        posix_memalign
        prctl
        secure_getenv
index ef2e6647d371fda9e11859e333be19c89f5330e8..0197b560ce17b40cf707edb5b2340f2e758bab37 100644 (file)
 /* Define to 1 if Ext2 ioctls present */
 #undef HAVE_EXT2_IOCTLS
 
+/* Define to 1 if you have the `fadvise64' function. */
+#undef HAVE_FADVISE64
+
 /* Define to 1 if you have the `fallocate' function. */
 #undef HAVE_FALLOCATE
 
 /* Define to 1 if you have the `posix_fadvise' function. */
 #undef HAVE_POSIX_FADVISE
 
+/* Define to 1 if you have the `posix_fadvise64' function. */
+#undef HAVE_POSIX_FADVISE64
+
 /* Define to 1 if you have the `posix_memalign' function. */
 #undef HAVE_POSIX_MEMALIGN
 
index c6a5f0daef96dd1c7b65830343ab0f6ad3ee55fd..c2695e825d6b2211b079f44a9b91e68e02b0a5cb 100644 (file)
@@ -34,7 +34,6 @@
 #include <unistd.h>
 #include <ext2fs/ext2_types.h>
 #include <ext2fs/ext2fs.h>
-#include <linux/fs.h>
 #include <sys/ioctl.h>
 #include <ext2fs/fiemap.h>
 #include <sys/mman.h>
@@ -183,29 +182,21 @@ static ext4_fsblk_t       files_block_count;
 static struct frag_statistic_ino       frag_rank[SHOW_FRAG_FILES];
 
 
-/* Local definitions of some syscalls glibc may not yet have */
-
-#ifndef HAVE_POSIX_FADVISE
-#warning Using locally defined posix_fadvise interface.
-
-#ifndef __NR_fadvise64_64
-#error Your kernel headers dont define __NR_fadvise64_64
+/*
+ * We prefer posix_fadvise64 when available, as it allows 64bit offset on
+ * 32bit systems
+ */
+#if defined(HAVE_POSIX_FADVISE64)
+#define posix_fadvise  posix_fadvise64
+#elif defined(HAVE_FADVISE64)
+#define posix_fadvise  fadvise64
+#elif !defined(HAVE_POSIX_FADVISE)
+#error posix_fadvise not available!
 #endif
 
 /*
- * fadvise() -         Give advice about file access.
- *
- * @fd:                        defrag target file's descriptor.
- * @offset:            file offset.
- * @len:               area length.
- * @advise:            process flag.
+ * Local definitions of some syscalls glibc may not yet have
  */
-static int posix_fadvise(int fd, loff_t offset, size_t len, int advise)
-{
-       return syscall(__NR_fadvise64_64, fd, offset, len, advise);
-}
-#endif /* ! HAVE_FADVISE64_64 */
-
 #ifndef HAVE_SYNC_FILE_RANGE
 #warning Using locally defined sync_file_range interface.