JDK-4948095 : API method FileChannel.lock() works wrong in SuSE SLES 8
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux_suse_sles_8
  • CPU: generic
  • Submitted: 2003-11-04
  • Updated: 2004-01-08
  • Resolved: 2004-01-08
Related Reports
Relates :  
Description
Platform: i586, AMD64
OS: SuSE SLES 8 (x86 & AMD64), SuSE Linux 8.2 (i586)

Fix for Bug# 4854085 did not fix the problem in SuSE Linux. Running the following code throws IOException.

-------------------- test.java ----------------------
import java.io.*;
import java.nio.channels.*;
public class test {
    public static void main(String[] args) {
	FileLock fl = null;
	try {
	    FileOutputStream fos = new FileOutputStream("testFile.tmp");
	    fos.write(new byte[128]);
            FileChannel ch = fos.getChannel();
	    fl = ch.lock();
        } catch (IOException e) {
	    System.out.println("Unexpected exception: "+e);
            e.printStackTrace();
	    System.exit(0);
        }
        System.out.println("PASSED.");
    }
}
------------------- example output ------------------

scorpius$% uname -a
Linux scorpius 2.4.20-4GB #1 Mon Mar 17 17:54:44 UTC 2003 i686 unknown unknown GNU/Linux
scorpius$% 
scorpius$% cat /etc/SuSE-release 
SuSE Linux 8.2 (i586)
VERSION = 8.2
scorpius$% /net/koori/onestop/jdk/1.5.0/latest/binaries/linux-i586/bin/java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b26)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b26, mixed mode)
scorpius$% 
scorpius$% /net/koori/onestop/jdk/1.5.0/latest/binaries/linux-i586/bin/java testUnexpected exception: java.io.IOException: No locks available
java.io.IOException: No locks available
	at sun.nio.ch.FileChannelImpl.lock0(Native Method)
	at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:778)
	at java.nio.channels.FileChannel.lock(FileChannel.java:865)
	at test.main(test.java:10)
scorpius$% 
--------------------------------------------------------------

please fix this

###@###.### 2003-11-03

Comments
WORK AROUND This occurs on files accessed over NFS. Local files work okay. Changing the config of the NFS utils can circumvent this problem, such as using "-o nolocks" when mounting the NFS directory to avoid using the lock manager, or configuring the lock manager to accept lock requests like this. ###@###.### 2003-11-10
10-11-2003

EVALUATION This problem appears only on files accessed over NFS. The OS error causing this is ENOLCK, whose causes are documented to include > cmd is F_SETLK or F_SETLKW, the type of lock > (l_type) is a read lock (F_RDLCK) or write lock > (F_WRLCK) and the file is an NFS file with access > bits set for enforcement mode. > > cmd is F_GETLK, F_SETLK, or F_SETLKW, the file is > an NFS file, and a system error occurred on the > remote node. When the operating system is configured in such a way as to refuse lock requests over NFS, there is nothing we can do since the locking facility relies upon the operating system to lock files via fcntl. We cannot work around this, in fact to do so would be a violation of the OS security settings. It appears that configuring SuSE to allow lock requests over NFS can be tricky, as I have seen a lot of people discussing it on various parts of the web. ###@###.### 2003-11-10
10-11-2003