7

Scenario:

We are using an NFS share to allow clients to upload raw video material. The files are then polled from the directory on the (NFS) server in order to be processed. Since we do not want to process files which have not finished uploading yet, I want to determine in the server-side script (Bash), if the file is still in use.

As the man pages say, both fuser and lsof -N shall allow for detecting in-use files on NFS shares. However, I do not "see" the files as in use on the server which results in corrupt files later in the processing.

Setup:

My NFS /etc/exports contains these settings (UID and GID being the owner of the shared directory on the server, line wrapped for better display):

/export/foo 10.3.2.0/255.255.255.0 
    (rw,sync,no_subtree_check,all_squash,anonuid=1001,anongid=1001)

The client mounts this share using:

10.3.2.197:/export/foo  /data002/  nfs  defaults        0 0

The server is a Ubuntu 10.04 using "nfs-kernel-server 1:1.2.0-4ubuntu4", the client is an SLES 10 SP2

When I open a file on the client (inside the shared directory), using

echo "Hello" > test.txt && tail -f foo.txt

and then check (still on the client) if the file is in use

fuser foo.txt

I can see that the file is in use. However, when checking on the server side (both fuser foo.txt and lsof -N | grep foo.txt) I do not get any usage information.

How can I check on the server if a file on the NFS share is currently in use (regardless if locally or remote)? Or what am I doing wrong in my current setup?

Axel Knauf
  • 1,620
  • 1
  • 11
  • 12

2 Answers2

6

lsof will only show you which resources are being used by your local system, in no case it'll show any foreign resource acquisition, but there's a way around that...

All remote usage will be tracked by the lockd daemon on the NFS server and it'll issue a lock on the file if you try to access it while being written by another node, so if you're using this (your mount options kinda point that way) you can in that case use lsof to show if a file is locked.

lynxman
  • 9,597
0

In the future where NFSv4 is a thing, lockd and most of the rpc-* daemons appear to be more or less irrelevant.

The command nfsdclnts (man 8 nfsdclnts) will create a nicely-formatted table of exactly which files your NFSv4 server currently considers to be locked by an NFSv4 client.

Learn more than you care to about NFS locking in RFC 7530, but the gist is that you're looking for rows where the type is either "open" or "deleg". You can specify which with the -t option, eg. -t open.

pyansharp
  • 111