From b929f4a5b03bfe9056d87bf451dc5b14025b9a04 Mon Sep 17 00:00:00 2001 From: Colin McCabe Date: Tue, 12 Aug 2014 23:03:43 +0000 Subject: [PATCH] HADOOP-10962. Flags for posix_fadvise are not valid in some architectures (David Villegas via Colin Patrick McCabe) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1617622 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../org/apache/hadoop/io/nativeio/NativeIO.c | 31 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 78c7ecdbe5c..f964fbd1197 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -128,6 +128,9 @@ Release 2.6.0 - UNRELEASED HADOOP-10851. NetgroupCache does not remove group memberships. (Benoy Antony via Arpit Agarwal) + HADOOP-10962. Flags for posix_fadvise are not valid in some architectures + (David Villegas via Colin Patrick McCabe) + Release 2.5.0 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c index 95bb987602f..45fa7025f42 100644 --- a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c +++ b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c @@ -171,6 +171,35 @@ static void nioe_deinit(JNIEnv *env) { nioe_ctor = NULL; } +/* + * Compatibility mapping for fadvise flags. Return the proper value from fnctl.h. + * If the value is not known, return the argument unchanged. + */ +static int map_fadvise_flag(jint flag) { + switch(flag) { + case org_apache_hadoop_io_nativeio_NativeIO_POSIX_POSIX_FADV_NORMAL: + return POSIX_FADV_NORMAL; + break; + case org_apache_hadoop_io_nativeio_NativeIO_POSIX_POSIX_FADV_RANDOM: + return POSIX_FADV_RANDOM; + break; + case org_apache_hadoop_io_nativeio_NativeIO_POSIX_POSIX_FADV_SEQUENTIAL: + return POSIX_FADV_SEQUENTIAL; + break; + case org_apache_hadoop_io_nativeio_NativeIO_POSIX_POSIX_FADV_WILLNEED: + return POSIX_FADV_WILLNEED; + break; + case org_apache_hadoop_io_nativeio_NativeIO_POSIX_POSIX_FADV_DONTNEED: + return POSIX_FADV_DONTNEED; + break; + case org_apache_hadoop_io_nativeio_NativeIO_POSIX_POSIX_FADV_NOREUSE: + return POSIX_FADV_NOREUSE; + break; + default: + return flag; + } +} + /* * private static native void initNative(); * @@ -303,7 +332,7 @@ Java_org_apache_hadoop_io_nativeio_NativeIO_00024POSIX_posix_1fadvise( PASS_EXCEPTIONS(env); int err = 0; - if ((err = posix_fadvise(fd, (off_t)offset, (off_t)len, flags))) { + if ((err = posix_fadvise(fd, (off_t)offset, (off_t)len, map_fadvise_flag(flags)))) { #ifdef __FreeBSD__ throw_ioe(env, errno); #else