diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c72b3de3d8..38bef36de7 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -566,6 +566,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 23513bfd66..fa95047394 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