RFR: 8294068: Unconditional and eager load of nio library since JDK-8264744

YuHui936 duke at openjdk.org
Tue Apr 8 11:27:31 UTC 2025


On Tue, 20 Sep 2022 16:47:09 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Move `LinuxFileSystem` native code to `LinuxNativeDispatcher`.

Files.copy() fails with EOPNOTSUPP on NFS when copy_file_range is unsupported by kernel

Detailed Description
**Environment:**
 - JDK Version: OpenJDK 21.0.3 
 - OS: Alpine Linux 3.20 (kernel 3.10) 
 - Filesystem: NFS 
 - Glibc: 2.36 (supports `copy_file_range` syscall) 
 - Container Environment: Alpine 3.20 with kernel 3.10 (lacks `copy_file_range` support)  
 **Problem:** When invoking `Files.copy(Path, Path, CopyOption)` on an NFS filesystem, the operation fails with:   
 `java.io.IOException: Operation not supported` due to error code `EOPNOTSUPP`.  
 **Root Cause Analysis:** 
 - JDK 21's `LinuxNativeDispatcher.directCopy0` attempts to use the `copy_file_range` syscall.   
 - The NFS driver in older kernels (e.g., 3.10) returns `EOPNOTSUPP` (indicating unsupported operation).   
 - JDK currently handles `EINVAL`, `ENOSYS`, and `EXDEV` by falling back to `sendfile64`, but **ignores `EOPNOTSUPP`**, leading to an unchecked exception.    **Expected Behavior:**   JDK should RESTARTABLE to `sendfile64`  when encountering `EOPNOTSUPP`.  
 **Steps to Reproduce:** 
 1. Mount an NFS filesystem in an Alpine 3.20 container (kernel 3.10).   
 2. Run the following Java code with JDK 21:      ```java    Path src = Path.of("/nfs/src.txt");    Path dst = Path.of("/nfs/dst.txt");    Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING); 
 3. Observe the exception:     java.io.IOException: Operation not supported         at java.base/sun.nio.fs.LinuxNativeDispatcher.directCopy0(Native Method)         ... (full stack trace)

Additional Context
Attach the full exception stack trace (provided in the problem description). Relevant kernel code snippet (from nfs42_proc_copy):     if (!nfs_server_capable(file_inode(dst), NFS_CAP_COPY))         return -EOPNOTSUPP; // Kernel returns EOPNOTSUPP for unsupported copy

Suggested Fix
Extend error handling in directCopy0 to catch EOPNOTSUPP.
![1](https://github.com/user-attachments/assets/781f420a-87c7-4168-8b29-d657ca28fa90)
![2](https://github.com/user-attachments/assets/84fc840f-1e4e-45bc-9426-734585414745)
![3](https://github.com/user-attachments/assets/7dc6d0ce-0fb7-444a-9590-7d10c685bed3)
![4](https://github.com/user-attachments/assets/e3bda0cd-46cd-4676-99d2-5f1683142082)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/10362#issuecomment-2786106876


More information about the nio-dev mailing list