0

Consider the following short program, where /nfsmount/merlin is an NFS-mounted directory.

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

public class Main{ 
    public static void main(String[] args) throws Exception { 
        String evilFile = "/nfsmount/merlin/foobar"; 
        RandomAccessFile raf = new RandomAccessFile(evilFile, "rw"); 
        FileChannel chan = raf.getChannel(); 
        FileLock lock = chan.tryLock(); 
    } 
} 

The NFS server has two IP addresses. When it is mounted over the first IP, the program above works fine. However, when it is mounted over the second IP, the program gives the following error.

Exception in thread "main" java.io.IOException: No locks available
    at sun.nio.ch.FileDispatcherImpl.lock0(Native Method)
    at sun.nio.ch.FileDispatcherImpl.lock(FileDispatcherImpl.java:91)
    at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1095)
    at java.nio.channels.FileChannel.tryLock(FileChannel.java:1154)
    at Main.main(Main.java:11)

A quick search leads to this question, which seems to indicate that there's something wrong with lockd. The fact that the program works on one IP would imply that lockd is only bound to one IP.

How can I configure it so that lockd works correctly over multiple IP's?

2
  • are you sure that there are no firewall involved? To find out to which interface lockd bound: netstat -tln | grep rpcinfo -p | grep 100021 | grep tcp | awk '{ print $4 }' | uniq
    – kofemann
    Nov 17, 2015 at 11:05
  • There is no firewall on the nfs server. I will try the command you provided. Thanks!
    – merlin2011
    Nov 17, 2015 at 19:55

0

You must log in to answer this question.

Browse other questions tagged .