RPC.STATD(8)

πŸ“¦
version 3.1.1 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– rpc.statd(8) β€” NSM service daemon πŸ’–

okay bestie, gather round 🫢 this is the manual page for rpc.statd, and yes it lives in the System Manager's Manual, section 8, as you can probably tell from the whole RPC.STATD(8) energy at the top of the original. It's the NSM service daemon and it is, lowkey, holding your NFS locks together. Let's get into it πŸ’…


✨ NAME ✨

rpc.statd β€” NSM service daemon πŸ‘‘


🌸 SYNOPSIS 🌸

rpc.statd [-dh?FLNvV] [-H prog] [-n my-name] [-o outgoing-port]
          [-p listener-port] [-P path]
          [--nlm-port port] [--nlm-udp-port port]

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea, and it's important: file locks are not part of persistent file system state. Meaning? When a host reboots, that lock state is just… gone. Poof. πŸ’€

And network file systems have to be able to tell when lock state is lost because a remote host rebooted. Like:

  • After an NFS client reboots, an NFS server has to release all the file locks that were held by applications running on that client.
  • After an NFS server reboots, a client has to remind that server about the file locks held by applications running on the client.

For NFS version 2 [RFC1094] and NFS version 3 [RFC1813], the Network Status Monitor protocol (NSM for short, slay) is what notifies NFS peers about reboots. On Linux, the NSM service is made up of two separate user-space components:

  • rpc.statd β€” the daemon that listens for reboot notifications from other hosts, and manages the list of hosts that need to be notified when the local system reboots. She's the listener. She's the keeper of the list. She's the main character πŸ’…
  • sm-notify β€” the helper program that notifies NFS peers after the local system reboots. The messenger 🧚

Here's how the gossip travels: the local NFS lock manager alerts its local rpc.statd about each remote peer that should be monitored. When the local system reboots, the sm-notify command notifies the NSM service on all the monitored peers that a reboot happened. And when a remote reboots? That peer notifies the local rpc.statd, which passes the reboot notification right back to the local NFS lock manager. Full circle, no cap πŸ”₯


πŸ‘‘ NSM OPERATION IN DETAIL πŸ‘‘

The very first file locking interaction between an NFS client and server makes the NFS lock managers on both peers contact their local NSM service to store info about the opposite peer. On Linux, the local lock manager contacts rpc.statd. Obviously πŸ’–

rpc.statd records information about every monitored NFS peer on persistent storage. And what does that info cover? Three things, bestie:

  • how to contact a remote peer in case the local system reboots,
  • how to recognize which monitored peer is reporting a reboot,
  • and how to notify the local lock manager when a monitored peer indicates it has rebooted.

An NFS client sends a hostname in each file lock request β€” this is known as the client's caller_name. An NFS server can use this hostname to send asynchronous GRANT calls to a client, or to notify the client that it has rebooted.

The Linux NFS server can hand the client's caller_name or the client's network address to rpc.statd. For the purposes of the NSM protocol, this name or address is known as the monitored peer's mon_name. And on top of that, the local lock manager tells rpc.statd what it thinks its own hostname is β€” and for NSM purposes, that hostname is known as my_name.

Now here's a lil gap in the system: there is no equivalent interaction between an NFS server and a client to inform the client of the server's caller_name. So NFS clients genuinely do not know what mon_name an NFS server might use in an SM_NOTIFY request. Instead, the Linux NFS client uses the server hostname from the mount command to identify rebooting NFS servers. It's giving workaround but it works 😭

πŸ’« Reboot notification πŸ’«

When the local system reboots, the sm-notify command reads the list of monitored peers from persistent storage and sends an SM_NOTIFY request to the NSM service on each listed remote peer. It uses the mon_name string as the destination 🎯

To identify which host has rebooted, sm-notify sends the my_name string that was recorded when that remote was monitored. The remote rpc.statd then matches incoming SM_NOTIFY requests β€” using this string, or the caller's network address β€” to one or more peers on its own monitor list.

If rpc.statd does not find a peer on its monitor list that matches an incoming SM_NOTIFY request, the notification is not forwarded to the local lock manager. πŸ™ˆ

Also, every peer has its own NSM state number: a 32-bit integer that gets bumped after each reboot by the sm-notify command. rpc.statd uses this number to tell the difference between actual reboots and replayed notifications. Very "we check the receipts" of it ✨

And part of NFS lock recovery is rediscovering which peers need to be monitored again. The sm-notify command clears the monitor list on persistent storage after each reboot. Fresh slate, clean vibe check 🌈


πŸ’… OPTIONS πŸ’…

  • -d, --no-syslog β€” makes rpc.statd write log messages to stderr instead of to the system log… but only if the -F option was also specified. Both or nothing, bestie.
  • -F, --foreground β€” keeps rpc.statd attached to its controlling terminal, so you can watch NSM operation directly or run it under a debugger πŸ‘€. If you don't specify this, rpc.statd backgrounds itself soon after it starts.
  • -h, -?, --help β€” makes rpc.statd display usage information on stderr and then exit. Classic.
  • -H, --ha-callout prog β€” specifies a high availability callout program. If you don't specify this option, no callouts are performed. See the High-availability callouts section below for the details.
  • -L, --no-notify β€” stops rpc.statd from running the sm-notify command when it starts up, which preserves the existing NSM state number and monitor list 🫢
Note: the sm-notify command contains a check to ensure it runs only once after each system reboot. This prevents spurious reboot notification if rpc.statd restarts without the -L option.
  • -n, --name ipaddr | hostname β€” this string is only used by the sm-notify command, as the source address from which to send reboot notification requests.

The ipaddr form can be expressed as either an IPv4 or an IPv6 presentation address. If this option is not specified, rpc.statd uses a wildcard address as the transport bind address. See sm-notify(8) for details.

  • -N β€” makes rpc.statd run the sm-notify command, and then exit. And since the sm-notify command can also be run directly… yeah, this option is deprecated. We don't gatekeep, but we do note it πŸ’€
  • -o, --outgoing-port port β€” specifies the source port number the sm-notify command should use when sending reboot notifications. See sm-notify(8) for details.
  • -p, --port port β€” specifies the port number used for RPC listener sockets. If this option is not specified, rpc.statd will try to consult /etc/services, and if getting the port succeeds, it sets the same port for all listener sockets; otherwise it chooses a random ephemeral port for each listener socket.

You'd use this option to fix the port value of its listeners when SM_NOTIFY requests must traverse a firewall between clients and servers. Firewall bestie behavior 🧱

  • -T, --nlm-port port β€” specifies the port number that lockd should listen on for NLM requests. This sets both the TCP and UDP ports unless the UDP port is set separately.
  • -U, --nlm-udp-port port β€” specifies the UDP port number that lockd should listen on for NLM requests.
  • -P, --state-directory-path pathname β€” specifies the pathname of the parent directory where NSM state information lives. If this option is not specified, rpc.statd uses /var/lib/nfs by default.

After starting, rpc.statd attempts to set its effective UID and GID to the owner and group of the subdirectory sm of this directory. After changing the effective ids, rpc.statd only needs to access files in sm and sm.bak within the state-directory-path. Efficient. Obsessed ✨

  • -v, -V, --version β€” makes rpc.statd display version information on stderr and then exit.

πŸŽ€ CONFIGURATION FILE πŸŽ€

A lot of the options you can set on the command line can also be controlled through values set in the [statd] section of the /etc/nfs.conf configuration file β€” or, in some cases, the [lockd] section.

Values recognized in the [statd] section include:

  • port
  • outgoing-port
  • name
  • state-directory-path
  • ha-callout

…and each one has the same effect as the option with the same name πŸ’…

The values recognized in the [lockd] section include:

  • port β€” same effect as the --nlm-port option
  • udp-port β€” same effect as the --nlm-udp-port option

πŸ”₯ SECURITY πŸ”₯

The rpc.statd daemon must be started as root to acquire the privileges needed to create sockets with privileged source ports, and to access the state information database. That's just the requirement, no way around it.

But β€” and this is the responsible queen behavior β€” because rpc.statd maintains a long-running network service, it drops root privileges as soon as it starts up to reduce the risk of a privilege escalation attack. Safety first, always 🫢

During normal operation, the effective user ID it chooses is the owner of the state directory. That's how it can keep accessing files in that directory after dropping its root privileges. And if you want to control which user ID rpc.statd picks? Just use chown(1) to set the owner of the state directory. Simple as that.

You can also protect your rpc.statd listeners using the tcp_wrapper library or iptables(8). To use the tcp_wrapper library, add the hostnames of peers that should be allowed access to /etc/hosts.allow. And heads up: use the daemon name statd even if the rpc.statd binary has a different filename. Don't get caught slipping on that one πŸ™ˆ

For further information, see the tcpd(8) and hosts_access(5) man pages.

🌈 ADDITIONAL NOTES 🌈

Lock recovery after a reboot is critical to keeping your data integrity intact and stopping unnecessary application hangs. To help rpc.statd match SM_NOTIFY requests to NLM requests, there are a bunch of best practices you should observe, including:

  • The UTS nodename of your systems should match the DNS names that NFS peers use to contact them
  • The UTS nodenames of your systems should always be fully qualified domain names
  • The forward and reverse DNS mapping of the UTS nodenames should be consistent
  • The hostname the client uses to mount the server should match the server's mon_name in SM_NOTIFY requests it sends

Unmounting an NFS file system does not necessarily stop either the NFS client or server from monitoring each other. Both may continue monitoring each other for a time in case subsequent NFS traffic between the two results in fresh mounts and additional file locking.

On Linux, if the lockd kernel module is unloaded during normal operation, all remote NFS peers are unmonitored. This can happen on an NFS client, for example, if an automounter removes all NFS mount points due to inactivity.

πŸ’… High-availability callouts πŸ’…

rpc.statd can exec a special callout program during processing of successful SM_MON, SM_UNMON, and SM_UNMON_ALL requests, or when it receives SM_NOTIFY. Such a program may be used in High Availability NFS (HA-NFS) environments to track lock state that may need to be migrated after a system reboot.

The name of the callout program is specified with the -H option. The program is run with 3 arguments: The first is either add-client, del-client, or sm-notify depending on the reason for the callout. The second is the mon_name of the monitored peer. The third is the caller_name of the requesting lock manager for add-client or del-client, otherwise it is IP_address of the caller sending SM_NOTIFY. The forth is the state_value in the SM_NOTIFY request.

πŸ¦‹ IPv6 and TI-RPC support πŸ¦‹

TI-RPC is a pre-requisite for supporting NFS on IPv6. If TI-RPC support is built into rpc.statd, it attempts to start listeners on network transports marked 'visible' in /etc/netconfig. As long as at least one network transport listener starts successfully, rpc.statd will operate.

🌸 ENVIRONMENT 🌸

  • RPC_STATD_NO_NOTIFY= β€” If set to a positive integer, has the same effect as --no-notify.

πŸŽ€ FILES πŸŽ€

  • /var/lib/nfs/sm β€” directory containing monitor list
  • /var/lib/nfs/sm.bak β€” directory containing notify list
  • /var/lib/nfs/state β€” NSM state number for this host
  • /run/run.statd.pid β€” pid file
  • /etc/netconfig β€” network transport capability database

πŸ‘‘ SEE ALSO πŸ‘‘

πŸ’œ AUTHORS πŸ’œ

  • Jeff Uphoff <juphoff@users.sourceforge.net>
  • Olaf Kirch <okir@monad.swb.de>
  • H.J. Lu <hjl@gnu.org>
  • Lon Hohberger <hohberger@missioncriticallinux.com>
  • Paul Clements <paul.clements@steeleye.com>
  • Chuck Lever <chuck.lever@oracle.com>

That's the whole page, bestie. This is from the RPC.STATD(8) manual, dated 1 November 2009. Stay iconic. πŸ’…βœ¨