162306a36Sopenharmony_ci==========
262306a36Sopenharmony_ciNFS Client
362306a36Sopenharmony_ci==========
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciThe NFS client
662306a36Sopenharmony_ci==============
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThe NFS version 2 protocol was first documented in RFC1094 (March 1989).
962306a36Sopenharmony_ciSince then two more major releases of NFS have been published, with NFSv3
1062306a36Sopenharmony_cibeing documented in RFC1813 (June 1995), and NFSv4 in RFC3530 (April
1162306a36Sopenharmony_ci2003).
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciThe Linux NFS client currently supports all the above published versions,
1462306a36Sopenharmony_ciand work is in progress on adding support for minor version 1 of the NFSv4
1562306a36Sopenharmony_ciprotocol.
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciThe purpose of this document is to provide information on some of the
1862306a36Sopenharmony_cispecial features of the NFS client that can be configured by system
1962306a36Sopenharmony_ciadministrators.
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciThe nfs4_unique_id parameter
2362306a36Sopenharmony_ci============================
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciNFSv4 requires clients to identify themselves to servers with a unique
2662306a36Sopenharmony_cistring.  File open and lock state shared between one client and one server
2762306a36Sopenharmony_ciis associated with this identity.  To support robust NFSv4 state recovery
2862306a36Sopenharmony_ciand transparent state migration, this identity string must not change
2962306a36Sopenharmony_ciacross client reboots.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciWithout any other intervention, the Linux client uses a string that contains
3262306a36Sopenharmony_cithe local system's node name.  System administrators, however, often do not
3362306a36Sopenharmony_citake care to ensure that node names are fully qualified and do not change
3462306a36Sopenharmony_ciover the lifetime of a client system.  Node names can have other
3562306a36Sopenharmony_ciadministrative requirements that require particular behavior that does not
3662306a36Sopenharmony_ciwork well as part of an nfs_client_id4 string.
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciThe nfs.nfs4_unique_id boot parameter specifies a unique string that can be
3962306a36Sopenharmony_ciused together with  a system's node name when an NFS client identifies itself to
4062306a36Sopenharmony_cia server.  Thus, if the system's node name is not unique, its
4162306a36Sopenharmony_cinfs.nfs4_unique_id can help prevent collisions with other clients.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciThe nfs.nfs4_unique_id string is typically a UUID, though it can contain
4462306a36Sopenharmony_cianything that is believed to be unique across all NFS clients.  An
4562306a36Sopenharmony_cinfs4_unique_id string should be chosen when a client system is installed,
4662306a36Sopenharmony_cijust as a system's root file system gets a fresh UUID in its label at
4762306a36Sopenharmony_ciinstall time.
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ciThe string should remain fixed for the lifetime of the client.  It can be
5062306a36Sopenharmony_cichanged safely if care is taken that the client shuts down cleanly and all
5162306a36Sopenharmony_cioutstanding NFSv4 state has expired, to prevent loss of NFSv4 state.
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ciThis string can be stored in an NFS client's grub.conf, or it can be provided
5462306a36Sopenharmony_civia a net boot facility such as PXE.  It may also be specified as an nfs.ko
5562306a36Sopenharmony_cimodule parameter.
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciThis uniquifier string will be the same for all NFS clients running in
5862306a36Sopenharmony_cicontainers unless it is overridden by a value written to
5962306a36Sopenharmony_ci/sys/fs/nfs/net/nfs_client/identifier which will be local to the network
6062306a36Sopenharmony_cinamespace of the process which writes.
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciThe DNS resolver
6462306a36Sopenharmony_ci================
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ciNFSv4 allows for one server to refer the NFS client to data that has been
6762306a36Sopenharmony_cimigrated onto another server by means of the special "fs_locations"
6862306a36Sopenharmony_ciattribute. See `RFC3530 Section 6: Filesystem Migration and Replication`_ and
6962306a36Sopenharmony_ci`Implementation Guide for Referrals in NFSv4`_.
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci.. _RFC3530 Section 6\: Filesystem Migration and Replication: https://tools.ietf.org/html/rfc3530#section-6
7262306a36Sopenharmony_ci.. _Implementation Guide for Referrals in NFSv4: https://tools.ietf.org/html/draft-ietf-nfsv4-referrals-00
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciThe fs_locations information can take the form of either an ip address and
7562306a36Sopenharmony_cia path, or a DNS hostname and a path. The latter requires the NFS client to
7662306a36Sopenharmony_cido a DNS lookup in order to mount the new volume, and hence the need for an
7762306a36Sopenharmony_ciupcall to allow userland to provide this service.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciAssuming that the user has the 'rpc_pipefs' filesystem mounted in the usual
8062306a36Sopenharmony_ci/var/lib/nfs/rpc_pipefs, the upcall consists of the following steps:
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci   (1) The process checks the dns_resolve cache to see if it contains a
8362306a36Sopenharmony_ci       valid entry. If so, it returns that entry and exits.
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci   (2) If no valid entry exists, the helper script '/sbin/nfs_cache_getent'
8662306a36Sopenharmony_ci       (may be changed using the 'nfs.cache_getent' kernel boot parameter)
8762306a36Sopenharmony_ci       is run, with two arguments:
8862306a36Sopenharmony_ci       - the cache name, "dns_resolve"
8962306a36Sopenharmony_ci       - the hostname to resolve
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci   (3) After looking up the corresponding ip address, the helper script
9262306a36Sopenharmony_ci       writes the result into the rpc_pipefs pseudo-file
9362306a36Sopenharmony_ci       '/var/lib/nfs/rpc_pipefs/cache/dns_resolve/channel'
9462306a36Sopenharmony_ci       in the following (text) format:
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci		"<ip address> <hostname> <ttl>\n"
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci       Where <ip address> is in the usual IPv4 (123.456.78.90) or IPv6
9962306a36Sopenharmony_ci       (ffee:ddcc:bbaa:9988:7766:5544:3322:1100, ffee::1100, ...) format.
10062306a36Sopenharmony_ci       <hostname> is identical to the second argument of the helper
10162306a36Sopenharmony_ci       script, and <ttl> is the 'time to live' of this cache entry (in
10262306a36Sopenharmony_ci       units of seconds).
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci       .. note::
10562306a36Sopenharmony_ci            If <ip address> is invalid, say the string "0", then a negative
10662306a36Sopenharmony_ci            entry is created, which will cause the kernel to treat the hostname
10762306a36Sopenharmony_ci            as having no valid DNS translation.
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciA basic sample /sbin/nfs_cache_getent
11362306a36Sopenharmony_ci=====================================
11462306a36Sopenharmony_ci.. code-block:: sh
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci    #!/bin/bash
11762306a36Sopenharmony_ci    #
11862306a36Sopenharmony_ci    ttl=600
11962306a36Sopenharmony_ci    #
12062306a36Sopenharmony_ci    cut=/usr/bin/cut
12162306a36Sopenharmony_ci    getent=/usr/bin/getent
12262306a36Sopenharmony_ci    rpc_pipefs=/var/lib/nfs/rpc_pipefs
12362306a36Sopenharmony_ci    #
12462306a36Sopenharmony_ci    die()
12562306a36Sopenharmony_ci    {
12662306a36Sopenharmony_ci        echo "Usage: $0 cache_name entry_name"
12762306a36Sopenharmony_ci        exit 1
12862306a36Sopenharmony_ci    }
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci    [ $# -lt 2 ] && die
13162306a36Sopenharmony_ci    cachename="$1"
13262306a36Sopenharmony_ci    cache_path=${rpc_pipefs}/cache/${cachename}/channel
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci    case "${cachename}" in
13562306a36Sopenharmony_ci        dns_resolve)
13662306a36Sopenharmony_ci            name="$2"
13762306a36Sopenharmony_ci            result="$(${getent} hosts ${name} | ${cut} -f1 -d\ )"
13862306a36Sopenharmony_ci            [ -z "${result}" ] && result="0"
13962306a36Sopenharmony_ci            ;;
14062306a36Sopenharmony_ci        *)
14162306a36Sopenharmony_ci            die
14262306a36Sopenharmony_ci            ;;
14362306a36Sopenharmony_ci    esac
14462306a36Sopenharmony_ci    echo "${result} ${name} ${ttl}" >${cache_path}
145