Nfs – Can open files be unlinked on NFS mounted volumes while applications that still have them open read/write


Does NFS allow me to unlink/delete open files like I can do with local file systems?

The reason I ask is that I'm developing something that runs on multiple servers and may access NFS as a back end. It simplifies things somewhat if I can do an unlink on a file that is open.

This is a nice feature of the linux (unix?) filesystems that you can unlink a file that is open. It simply removes the directory entry. The file is still available to a process that holds it open as long as it is open. Once closed the inode is destroyed.

Does that same functionality hold true for files opened on NFS mounts?

Best Answer

The short answer is yes with caveats.

Since NFSv3 is stateless, the NFS client driver accomplishes this with something called "silly rename", where the deleted file is renamed to something like .nfsXXXXXXXXXX. This generally works, but there are a few caveats compared to a local filesystem. For instance, if the client crashes then those .nfsXXXX files will not be deleted, and you'll have to clean them up manually.

I think as of NFSv4.1 the protocol has the required features to implement delete-on-last-close without silly rename, but I don't know if any clients/server yet implement this.