Reliability

The NFS4 has an inherent weakness: If a client is off the network for too long its locks on files on NFS4 shares will expire. In this case another client can theoretically lock one of these files, make changes to it and unlock it again. If the client is back on the network it will get the lock back but the file has changed without the client realising it. This could lead to data corruption.

The Linux kernel provides the nfs.recover_lost_locks parameter to deal with locked files for which the lock was lost as described above:

  • If set to 0 (the default) attempting to read from or write to an open file with a lost lock will fail with EIO.
  • If set to 1 the kernel NFS4 client will attempt to reclaim the lock and assume the file was not changed in the meantime.

The default behaviour causes applications to crash with NFS4 home directories, for instance web browsers or mail clients, if the server is not reachable for a few minutes.

For Linux systems that mainly use home directories and project shares from NFS4 servers we recommend setting nfs.recover_lost_locks to 1.

Configuration for All Recent Linux Distributions

To immediately activate the change without rebooting execute the following command:

echo Y > /sys/module/nfs/parameters/recover_lost_locks

To persistently set the parameter create a file /etc/modprobe.d/nfs4-locks.conf as root with the following content:

options nfs recover_lost_locks=1

Page URL: https://isg.inf.ethz.ch/bin/view/Main/HelpDesktopsAndLaptopsLinuxNfs4Reliability
2024-12-21
© 2024 Eidgenössische Technische Hochschule Zürich