8171452: (ch) linux io_util_md: Operation not supported exception after 8168628
authorbpb
Tue, 20 Dec 2016 10:11:05 -0800
changeset 43001 f007095ec898
parent 43000 fa648bd4286b
child 43002 6d505224e787
8171452: (ch) linux io_util_md: Operation not supported exception after 8168628 Summary: On Linux, fall back to ftruncate64() if fallocate64() fails Reviewed-by: mdoerr, alanb
jdk/src/java.base/unix/native/libjava/io_util_md.c
jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
--- a/jdk/src/java.base/unix/native/libjava/io_util_md.c	Thu Jan 05 23:19:26 2017 +0800
+++ b/jdk/src/java.base/unix/native/libjava/io_util_md.c	Tue Dec 20 10:11:05 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -226,7 +226,12 @@
 
     if (fstat64(fd, &sb) == 0 && length > sb.st_blocks*512) {
         RESTARTABLE(fallocate64(fd, 0, 0, length), result);
-        return result;
+        // Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
+        if (result == 0) {
+            return 0;
+        } else if (errno != EOPNOTSUPP && errno != ENOSYS) {
+            return result;
+        }
     }
 #endif
     RESTARTABLE(ftruncate64(fd, length), result);
--- a/jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c	Thu Jan 05 23:19:26 2017 +0800
+++ b/jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c	Tue Dec 20 10:11:05 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -197,14 +197,17 @@
      * any blocks which can cause a SIGBUS error if the file is subsequently
      * memory-mapped.
      */
-    return handle(env,
-                  fallocate64(fdval(env, fdo), 0, 0, size),
-                  "Allocation failed");
-#else
+    // Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
+    int result = fallocate64(fdval(env, fdo), 0, 0, size);
+    if (result == 0) {
+        return 0;
+    } else if (errno != EOPNOTSUPP && errno != ENOSYS) {
+        return handle(env, result, "Allocation failed");
+    }
+#endif
     return handle(env,
                   ftruncate64(fdval(env, fdo), size),
                   "Truncation failed");
-#endif
 }
 
 JNIEXPORT jlong JNICALL