Hatena::ブログ(Diary)

ablog このページをアンテナに追加 RSSフィード Twitter

2016-01-30

NFS on Linux でロックを解放する方法

NFSクライアントがクラッシュしてNFSサーバにロックが残った場合、Solaris は clear_locks コマンドで解放できるようだが、Linux はないのかな。

ロックやアンロックは /fs/lockd/clntproc.c でやっているぽい。

11.3.3. Clearing lock state

The most likely cause of the lock not getting released is that the holding NFS client has crashed. You can take the list of hosts from the /var/statmon/sm directory and check if any are dead, or not responding due to a network partition. Once you determine which are dead, you can use Solaris's clear_locks command to clear lock state. Let's suppose you determine that gonzo is dead. Then you would do:

spike# clear_locks gonzo
Troubleshooting locking problems (Managing NFS and NIS, 2nd Edition)

メモ

$ perl -MFcntl -e '$locked=pack("ssL",Fcntl::F_WRLCK,q/SEEK_SET/,0);open(FH,">> ./test2.txt") and fcntl(FH, F_SETLK, $locked) and sleep(300)' &        
[3] 7297
$ lsof +f g -- /home/oracle/nfs/remote                                                                                                                 
COMMAND  PID USER   FD   TYPE       FILE-FLAG DEVICE SIZE/OFF      NODE NAME
bash    5309 root  cwd    DIR                   0,34       82 268435611 /home/oracle/nfs/remote (ggt.oracle.com:/home/oracle/nfs/local)
perl    5410 root  cwd    DIR                   0,34       82 268435611 /home/oracle/nfs/remote (ggt.oracle.com:/home/oracle/nfs/local)
perl    5410 root    3wW  REG W,AP,LG,0x80000   0,34        0 268440149 /home/oracle/nfs/remote/test1.txt (ggt.oracle.com:/home/oracle/nfs/local)
perl    7221 root  cwd    DIR                   0,34       82 268435611 /home/oracle/nfs/remote (ggt.oracle.com:/home/oracle/nfs/local)
perl    7221 root    3wW  REG W,AP,LG,0x80000   0,34        0 268440148 /home/oracle/nfs/remote/test2.txt (ggt.oracle.com:/home/oracle/nfs/local)
lsof    7306 root  cwd    DIR                   0,34       82 268435611 /home/oracle/nfs/remote (ggt.oracle.com:/home/oracle/nfs/local)
lsof    7307 root  cwd    DIR                   0,34       82 268435611 /home/oracle/nfs/remote (ggt.oracle.com:/home/oracle/nfs/local)
d fcntl(FH, F_SETLK, $locked) and sleep(300)'
$  perl -MFcntl -e '$locked=pack("ssL", Fcntl::F_UNLCK, 'SEEK_SET', 0);open(FH,">> ./test2.txt") and fcntl(FH, F_SETLK, $locked)'      

Linuxプログラミングインタフェース

Linuxプログラミングインタフェース

55.5 /proc/locks

$ cat /proc/locks                                                                                                                                     
1: POSIX  ADVISORY  WRITE 23915 fc:02:271151215 0 EOF
2: POSIX  ADVISORY  WRITE 23915 fc:02:271151214 0 EOF
3: POSIX  ADVISORY  READ  23901 fc:02:3425 0 EOF
4: POSIX  ADVISORY  READ  23889 fc:02:3425 0 EOF
5: POSIX  ADVISORY  READ  23891 fc:02:3425 0 EOF



参考