changeset 16415:8b55846dd69d

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
author bpb
date Tue, 20 Dec 2016 10:11:05 -0800
parents d6258c65d466
children fa55c031213b
files src/java.base/unix/native/libjava/io_util_md.c src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
diffstat 2 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/unix/native/libjava/io_util_md.c	Thu Jan 05 23:19:26 2017 +0800
+++ b/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/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c	Thu Jan 05 23:19:26 2017 +0800
+++ b/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