[9] RFR of 8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X

Brian Burkhalter brian.burkhalter at oracle.com
Wed May 20 21:10:48 UTC 2015


On May 20, 2015, at 7:31 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:

> 
> On May 19, 2015, at 1:03 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
>> On 19/05/2015 19:33, Brian Burkhalter wrote:
>>> :
>>> 
>>> Perhaps this is a safer approach.
>> Is F_FULLSYNC not guaranteed to be defined on all supported OS X versions? Just wondering if  #if defined(F_FULLSYNC) is really needed. It otherwise looks okay as it doesn't compile in the current implementation that choose fsync or fdatasync.
>> 
>> -Alan
> 
> I was inferring from the online information that Robert sent and some other scattered information. You have a point though: if we build on a system for which F_FULLSYNC is defined and some earlier system where it is not tries to run the code there will be an error. On that basis it makes sense to remove it unless some kind of dynamic check could be performed.
> 
> Brian

How about the patch below instead?

Thanks,

Brian

--- a/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
+++ b/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
@@ -144,14 +144,21 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this,
                                           jobject fdo, jboolean md)
 {
     jint fd = fdval(env, fdo);
     int result = 0;
 
+#ifdef MACOSX
+    result = fcntl(fd, F_FULLFSYNC);
+    if (result == -1 && errno == ENOTSUP) {
+        /* Try fsync() in case F_FULLSYUNC is not implemented on the file system. */
+        result = fsync(fd);
+    }
+#else /* end MACOSX, begin not-MACOSX */
     if (md == JNI_FALSE) {
         result = fdatasync(fd);
     } else {
 #ifdef _AIX
         /* On AIX, calling fsync on a file descriptor that is opened only for
          * reading results in an error ("EBADF: The FileDescriptor parameter is
          * not a valid file descriptor open for writing.").
@@ -159,17 +166,18 @@
          * 'writable' attribute of the corresponding file channel so we have to
          * use 'fcntl'.
          */
         int getfl = fcntl(fd, F_GETFL);
         if (getfl >= 0 && (getfl & O_ACCMODE) == O_RDONLY) {
             return 0;
         }
-#endif
+#endif /* _AIX */
         result = fsync(fd);
     }
+#endif /* not-MACOSX */
     return handle(env, result, "Force failed");
 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20150520/e293ef33/attachment-0001.html>


More information about the nio-dev mailing list