nfs.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. The NFS client
  2. ==============
  3. The NFS version 2 protocol was first documented in RFC1094 (March 1989).
  4. Since then two more major releases of NFS have been published, with NFSv3
  5. being documented in RFC1813 (June 1995), and NFSv4 in RFC3530 (April
  6. 2003).
  7. The Linux NFS client currently supports all the above published versions,
  8. and work is in progress on adding support for minor version 1 of the NFSv4
  9. protocol.
  10. The purpose of this document is to provide information on some of the
  11. special features of the NFS client that can be configured by system
  12. administrators.
  13. The nfs4_unique_id parameter
  14. ============================
  15. NFSv4 requires clients to identify themselves to servers with a unique
  16. string. File open and lock state shared between one client and one server
  17. is associated with this identity. To support robust NFSv4 state recovery
  18. and transparent state migration, this identity string must not change
  19. across client reboots.
  20. Without any other intervention, the Linux client uses a string that contains
  21. the local system's node name. System administrators, however, often do not
  22. take care to ensure that node names are fully qualified and do not change
  23. over the lifetime of a client system. Node names can have other
  24. administrative requirements that require particular behavior that does not
  25. work well as part of an nfs_client_id4 string.
  26. The nfs.nfs4_unique_id boot parameter specifies a unique string that can be
  27. used instead of a system's node name when an NFS client identifies itself to
  28. a server. Thus, if the system's node name is not unique, or it changes, its
  29. nfs.nfs4_unique_id stays the same, preventing collision with other clients
  30. or loss of state during NFS reboot recovery or transparent state migration.
  31. The nfs.nfs4_unique_id string is typically a UUID, though it can contain
  32. anything that is believed to be unique across all NFS clients. An
  33. nfs4_unique_id string should be chosen when a client system is installed,
  34. just as a system's root file system gets a fresh UUID in its label at
  35. install time.
  36. The string should remain fixed for the lifetime of the client. It can be
  37. changed safely if care is taken that the client shuts down cleanly and all
  38. outstanding NFSv4 state has expired, to prevent loss of NFSv4 state.
  39. This string can be stored in an NFS client's grub.conf, or it can be provided
  40. via a net boot facility such as PXE. It may also be specified as an nfs.ko
  41. module parameter. Specifying a uniquifier string is not support for NFS
  42. clients running in containers.
  43. The DNS resolver
  44. ================
  45. NFSv4 allows for one server to refer the NFS client to data that has been
  46. migrated onto another server by means of the special "fs_locations"
  47. attribute. See
  48. http://tools.ietf.org/html/rfc3530#section-6
  49. and
  50. http://tools.ietf.org/html/draft-ietf-nfsv4-referrals-00
  51. The fs_locations information can take the form of either an ip address and
  52. a path, or a DNS hostname and a path. The latter requires the NFS client to
  53. do a DNS lookup in order to mount the new volume, and hence the need for an
  54. upcall to allow userland to provide this service.
  55. Assuming that the user has the 'rpc_pipefs' filesystem mounted in the usual
  56. /var/lib/nfs/rpc_pipefs, the upcall consists of the following steps:
  57. (1) The process checks the dns_resolve cache to see if it contains a
  58. valid entry. If so, it returns that entry and exits.
  59. (2) If no valid entry exists, the helper script '/sbin/nfs_cache_getent'
  60. (may be changed using the 'nfs.cache_getent' kernel boot parameter)
  61. is run, with two arguments:
  62. - the cache name, "dns_resolve"
  63. - the hostname to resolve
  64. (3) After looking up the corresponding ip address, the helper script
  65. writes the result into the rpc_pipefs pseudo-file
  66. '/var/lib/nfs/rpc_pipefs/cache/dns_resolve/channel'
  67. in the following (text) format:
  68. "<ip address> <hostname> <ttl>\n"
  69. Where <ip address> is in the usual IPv4 (123.456.78.90) or IPv6
  70. (ffee:ddcc:bbaa:9988:7766:5544:3322:1100, ffee::1100, ...) format.
  71. <hostname> is identical to the second argument of the helper
  72. script, and <ttl> is the 'time to live' of this cache entry (in
  73. units of seconds).
  74. Note: If <ip address> is invalid, say the string "0", then a negative
  75. entry is created, which will cause the kernel to treat the hostname
  76. as having no valid DNS translation.
  77. A basic sample /sbin/nfs_cache_getent
  78. =====================================
  79. #!/bin/bash
  80. #
  81. ttl=600
  82. #
  83. cut=/usr/bin/cut
  84. getent=/usr/bin/getent
  85. rpc_pipefs=/var/lib/nfs/rpc_pipefs
  86. #
  87. die()
  88. {
  89. echo "Usage: $0 cache_name entry_name"
  90. exit 1
  91. }
  92. [ $# -lt 2 ] && die
  93. cachename="$1"
  94. cache_path=${rpc_pipefs}/cache/${cachename}/channel
  95. case "${cachename}" in
  96. dns_resolve)
  97. name="$2"
  98. result="$(${getent} hosts ${name} | ${cut} -f1 -d\ )"
  99. [ -z "${result}" ] && result="0"
  100. ;;
  101. *)
  102. die
  103. ;;
  104. esac
  105. echo "${result} ${name} ${ttl}" >${cache_path}