1*4882a593Smuzhiyun========== 2*4882a593SmuzhiyunNFS Client 3*4882a593Smuzhiyun========== 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunThe NFS client 6*4882a593Smuzhiyun============== 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunThe NFS version 2 protocol was first documented in RFC1094 (March 1989). 9*4882a593SmuzhiyunSince then two more major releases of NFS have been published, with NFSv3 10*4882a593Smuzhiyunbeing documented in RFC1813 (June 1995), and NFSv4 in RFC3530 (April 11*4882a593Smuzhiyun2003). 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunThe Linux NFS client currently supports all the above published versions, 14*4882a593Smuzhiyunand work is in progress on adding support for minor version 1 of the NFSv4 15*4882a593Smuzhiyunprotocol. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunThe purpose of this document is to provide information on some of the 18*4882a593Smuzhiyunspecial features of the NFS client that can be configured by system 19*4882a593Smuzhiyunadministrators. 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunThe nfs4_unique_id parameter 23*4882a593Smuzhiyun============================ 24*4882a593Smuzhiyun 25*4882a593SmuzhiyunNFSv4 requires clients to identify themselves to servers with a unique 26*4882a593Smuzhiyunstring. File open and lock state shared between one client and one server 27*4882a593Smuzhiyunis associated with this identity. To support robust NFSv4 state recovery 28*4882a593Smuzhiyunand transparent state migration, this identity string must not change 29*4882a593Smuzhiyunacross client reboots. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunWithout any other intervention, the Linux client uses a string that contains 32*4882a593Smuzhiyunthe local system's node name. System administrators, however, often do not 33*4882a593Smuzhiyuntake care to ensure that node names are fully qualified and do not change 34*4882a593Smuzhiyunover the lifetime of a client system. Node names can have other 35*4882a593Smuzhiyunadministrative requirements that require particular behavior that does not 36*4882a593Smuzhiyunwork well as part of an nfs_client_id4 string. 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunThe nfs.nfs4_unique_id boot parameter specifies a unique string that can be 39*4882a593Smuzhiyunused instead of a system's node name when an NFS client identifies itself to 40*4882a593Smuzhiyuna server. Thus, if the system's node name is not unique, or it changes, its 41*4882a593Smuzhiyunnfs.nfs4_unique_id stays the same, preventing collision with other clients 42*4882a593Smuzhiyunor loss of state during NFS reboot recovery or transparent state migration. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunThe nfs.nfs4_unique_id string is typically a UUID, though it can contain 45*4882a593Smuzhiyunanything that is believed to be unique across all NFS clients. An 46*4882a593Smuzhiyunnfs4_unique_id string should be chosen when a client system is installed, 47*4882a593Smuzhiyunjust as a system's root file system gets a fresh UUID in its label at 48*4882a593Smuzhiyuninstall time. 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunThe string should remain fixed for the lifetime of the client. It can be 51*4882a593Smuzhiyunchanged safely if care is taken that the client shuts down cleanly and all 52*4882a593Smuzhiyunoutstanding NFSv4 state has expired, to prevent loss of NFSv4 state. 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunThis string can be stored in an NFS client's grub.conf, or it can be provided 55*4882a593Smuzhiyunvia a net boot facility such as PXE. It may also be specified as an nfs.ko 56*4882a593Smuzhiyunmodule parameter. Specifying a uniquifier string is not support for NFS 57*4882a593Smuzhiyunclients running in containers. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunThe DNS resolver 61*4882a593Smuzhiyun================ 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunNFSv4 allows for one server to refer the NFS client to data that has been 64*4882a593Smuzhiyunmigrated onto another server by means of the special "fs_locations" 65*4882a593Smuzhiyunattribute. See `RFC3530 Section 6: Filesystem Migration and Replication`_ and 66*4882a593Smuzhiyun`Implementation Guide for Referrals in NFSv4`_. 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun.. _RFC3530 Section 6\: Filesystem Migration and Replication: https://tools.ietf.org/html/rfc3530#section-6 69*4882a593Smuzhiyun.. _Implementation Guide for Referrals in NFSv4: https://tools.ietf.org/html/draft-ietf-nfsv4-referrals-00 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunThe fs_locations information can take the form of either an ip address and 72*4882a593Smuzhiyuna path, or a DNS hostname and a path. The latter requires the NFS client to 73*4882a593Smuzhiyundo a DNS lookup in order to mount the new volume, and hence the need for an 74*4882a593Smuzhiyunupcall to allow userland to provide this service. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunAssuming that the user has the 'rpc_pipefs' filesystem mounted in the usual 77*4882a593Smuzhiyun/var/lib/nfs/rpc_pipefs, the upcall consists of the following steps: 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun (1) The process checks the dns_resolve cache to see if it contains a 80*4882a593Smuzhiyun valid entry. If so, it returns that entry and exits. 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun (2) If no valid entry exists, the helper script '/sbin/nfs_cache_getent' 83*4882a593Smuzhiyun (may be changed using the 'nfs.cache_getent' kernel boot parameter) 84*4882a593Smuzhiyun is run, with two arguments: 85*4882a593Smuzhiyun - the cache name, "dns_resolve" 86*4882a593Smuzhiyun - the hostname to resolve 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun (3) After looking up the corresponding ip address, the helper script 89*4882a593Smuzhiyun writes the result into the rpc_pipefs pseudo-file 90*4882a593Smuzhiyun '/var/lib/nfs/rpc_pipefs/cache/dns_resolve/channel' 91*4882a593Smuzhiyun in the following (text) format: 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun "<ip address> <hostname> <ttl>\n" 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun Where <ip address> is in the usual IPv4 (123.456.78.90) or IPv6 96*4882a593Smuzhiyun (ffee:ddcc:bbaa:9988:7766:5544:3322:1100, ffee::1100, ...) format. 97*4882a593Smuzhiyun <hostname> is identical to the second argument of the helper 98*4882a593Smuzhiyun script, and <ttl> is the 'time to live' of this cache entry (in 99*4882a593Smuzhiyun units of seconds). 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun .. note:: 102*4882a593Smuzhiyun If <ip address> is invalid, say the string "0", then a negative 103*4882a593Smuzhiyun entry is created, which will cause the kernel to treat the hostname 104*4882a593Smuzhiyun as having no valid DNS translation. 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun 109*4882a593SmuzhiyunA basic sample /sbin/nfs_cache_getent 110*4882a593Smuzhiyun===================================== 111*4882a593Smuzhiyun.. code-block:: sh 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun #!/bin/bash 114*4882a593Smuzhiyun # 115*4882a593Smuzhiyun ttl=600 116*4882a593Smuzhiyun # 117*4882a593Smuzhiyun cut=/usr/bin/cut 118*4882a593Smuzhiyun getent=/usr/bin/getent 119*4882a593Smuzhiyun rpc_pipefs=/var/lib/nfs/rpc_pipefs 120*4882a593Smuzhiyun # 121*4882a593Smuzhiyun die() 122*4882a593Smuzhiyun { 123*4882a593Smuzhiyun echo "Usage: $0 cache_name entry_name" 124*4882a593Smuzhiyun exit 1 125*4882a593Smuzhiyun } 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun [ $# -lt 2 ] && die 128*4882a593Smuzhiyun cachename="$1" 129*4882a593Smuzhiyun cache_path=${rpc_pipefs}/cache/${cachename}/channel 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun case "${cachename}" in 132*4882a593Smuzhiyun dns_resolve) 133*4882a593Smuzhiyun name="$2" 134*4882a593Smuzhiyun result="$(${getent} hosts ${name} | ${cut} -f1 -d\ )" 135*4882a593Smuzhiyun [ -z "${result}" ] && result="0" 136*4882a593Smuzhiyun ;; 137*4882a593Smuzhiyun *) 138*4882a593Smuzhiyun die 139*4882a593Smuzhiyun ;; 140*4882a593Smuzhiyun esac 141*4882a593Smuzhiyun echo "${result} ${name} ${ttl}" >${cache_path} 142