JDK-5083626 : nio NFS file Locking is failing on some Suse Linux systems
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0,5.0u1
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux_suse_sles_8
  • CPU: x86
  • Submitted: 2004-08-06
  • Updated: 2012-10-09
  • Resolved: 2005-09-01
Related Reports
Duplicate :  
Description
4-5 test case related to java.util.prefs and java.nio.channel
are failing, seeing the error code, it is related to file locking.

Tested these tests on Build-59

Sample Code for java.util.prefs

import java.util.prefs.*;
import java.util.*;
 

public class Test20 {
     
    public void check1() {
         try {
           Preferences userRoot = Preferences.userRoot();
           userRoot.put("Test","Libs");
           userRoot.flush();
           System.out.println("The vale got back is :"+userRoot.get("Test","Default"));
          } catch(Exception e) {
            e.printStackTrace();
          }
       
    }  
    
 
    
    public static void main(String[] args) throws Exception {
      Test20 ref = new Test20();
      ref.check1();
      
     } 
 

}


Sample code for File Locking
Before Running this test create any file by name Sample.txt

import java.io.*;
import java.nio.channels.*;
import java.nio.*;

public class Test21 {

   public boolean check() throws Exception {
        boolean bReturn = true;
        RandomAccessFile raf = null;
        FileChannel c = null;
        File tempFile = new File("Sample.txt");
        tempFile.deleteOnExit();
        try {
           raf = new RandomAccessFile(tempFile,"rw");
           c = raf.getChannel();
           FileLock fl1 = c.lock(0,c.size(),true);
	   FileChannel fc = fl1.channel();
	   if(!fc.equals(c)) {
 		bReturn = false;
                System.out.println("channelTest01: FAIL.");
           }
	   fl1.release();
	   c.close();
        } catch (Exception e) {
           bReturn = false;
           e.printStackTrace();
        }

        return bReturn;
       
   }
   
    
   
   public static void main(String args[]) {
       Test21 ref = new Test21();
       try {
         System.out.println("Test For File Channel Passed "+ref.check());
       } catch(Exception e) {
          e.printStackTrace();
       }  
   }
}


----------------------------------------------
I executed both the test cases on AMD64 with RH AS-3
Red Hat Enterprise Linux AS release 3 (Taroon)
Kernel 2.4.21-4.EL on an x86_64

Both the test cases passed,
On Intel arch with RH AS-3 it works fine.

I am seeing the failure on ALSES-8

In addition to above information:-
Test case Test21 passes on AMD64 SLES-8
if we copy the test case to local directory
over the NFS it fails.

Whereas the test case Test20 fails even if copied
and executed from local directory.
SQE:-
Jitender Singh.

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

Comments
EVALUATION The test programs seem to work for us on linux-amd64 and solaris-sparc. What is the exact failure mode? Is this bug SuSE-specific or can it be reproduced on Red Hat systems as well? ###@###.### 2004-08-06 After further investigation, I have found that: - Linux file locking always succeeds on local (non-NFS) files. - When working with NFS files, not all Linux systems have the appropriate level of support. I believe NFS V4 support is necessary. I have tested a system with a 2.6 kernel and it works fine there. So this is an operating system limitation and NFS file locking is simply not available on the submitter's test system. The exception, while it could be clearer, is appropriate. I intend to close this as Not A Bug. ###@###.### 2004-08-11 Here is a good summary from the Net (Bob Vickers): http://ohno.mrbill.net/pipermail/linuxmanagers/2003-May/001174.html It would be really useful if people with access to SuSE 8.2 NFS clients could run my program to establish whether the problem is universal or if there is something unusual about my configuration. Here is my experience: (1) Attempts to lock a file on a SuSE 8.2 NFS client always fail. The kernels concerned are k_deflt-2.4.20-39 and k_smp-2.4.20-40 (vanilla kernels from SuSE 8.2 distro). (2) Locking worked on these clients before they were upgraded. (3) The NFS servers (both Linux and Tru64) succesfully support locking for a variety of other clients including Tru64, Solaris and SuSE 8.0 (4) As an experiment I tried putting ALL: ALL in the client's /etc/hosts.allow. It made no difference (5) It still fails if the lock file is world-writable. (6) /proc/mounts confirms that the file systems are mounted with the 'lock' option (7) rpcinfo reports udp nlockmgr running on both client and server To run my test do the following: $ cd somewhere-on-an-NFS-file-system $ gcc -o getlock getlock.c $ touch mylockfile $ ./getlock And here is the program: #include <stdio.h> #include <fcntl.h> #include <sys/types.h> #include <unistd.h> main() { int fd, stat; struct flock lck; lck.l_type = F_WRLCK; /* setting a write lock */ lck.l_whence = 0; /* offset l_start from beginning of file */ lck.l_start = 0; lck.l_len = 1; fd=open("mylockfile", O_RDWR, 0); if ( fd < 0 ) { perror ("Open failed"); } else { stat=fcntl (fd, F_SETLK, &lck); if ( stat == -1 ) { perror ("SETLK failed"); } else { printf ("SETLK worked\n"); } } } ###@###.### 2004-08-12
12-08-2004