nfs.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. upcall interfaces that are used in order to provide the NFS client with
  12. some of the information that it requires in order to fully comply with
  13. the NFS spec.
  14. The DNS resolver
  15. ================
  16. NFSv4 allows for one server to refer the NFS client to data that has been
  17. migrated onto another server by means of the special "fs_locations"
  18. attribute. See
  19. http://tools.ietf.org/html/rfc3530#section-6
  20. and
  21. http://tools.ietf.org/html/draft-ietf-nfsv4-referrals-00
  22. The fs_locations information can take the form of either an ip address and
  23. a path, or a DNS hostname and a path. The latter requires the NFS client to
  24. do a DNS lookup in order to mount the new volume, and hence the need for an
  25. upcall to allow userland to provide this service.
  26. Assuming that the user has the 'rpc_pipefs' filesystem mounted in the usual
  27. /var/lib/nfs/rpc_pipefs, the upcall consists of the following steps:
  28. (1) The process checks the dns_resolve cache to see if it contains a
  29. valid entry. If so, it returns that entry and exits.
  30. (2) If no valid entry exists, the helper script '/sbin/nfs_cache_getent'
  31. (may be changed using the 'nfs.cache_getent' kernel boot parameter)
  32. is run, with two arguments:
  33. - the cache name, "dns_resolve"
  34. - the hostname to resolve
  35. (3) After looking up the corresponding ip address, the helper script
  36. writes the result into the rpc_pipefs pseudo-file
  37. '/var/lib/nfs/rpc_pipefs/cache/dns_resolve/channel'
  38. in the following (text) format:
  39. "<ip address> <hostname> <ttl>\n"
  40. Where <ip address> is in the usual IPv4 (123.456.78.90) or IPv6
  41. (ffee:ddcc:bbaa:9988:7766:5544:3322:1100, ffee::1100, ...) format.
  42. <hostname> is identical to the second argument of the helper
  43. script, and <ttl> is the 'time to live' of this cache entry (in
  44. units of seconds).
  45. Note: If <ip address> is invalid, say the string "0", then a negative
  46. entry is created, which will cause the kernel to treat the hostname
  47. as having no valid DNS translation.
  48. A basic sample /sbin/nfs_cache_getent
  49. =====================================
  50. #!/bin/bash
  51. #
  52. ttl=600
  53. #
  54. cut=/usr/bin/cut
  55. getent=/usr/bin/getent
  56. rpc_pipefs=/var/lib/nfs/rpc_pipefs
  57. #
  58. die()
  59. {
  60. echo "Usage: $0 cache_name entry_name"
  61. exit 1
  62. }
  63. [ $# -lt 2 ] && die
  64. cachename="$1"
  65. cache_path=${rpc_pipefs}/cache/${cachename}/channel
  66. case "${cachename}" in
  67. dns_resolve)
  68. name="$2"
  69. result="$(${getent} hosts ${name} | ${cut} -f1 -d\ )"
  70. [ -z "${result}" ] && result="0"
  71. ;;
  72. *)
  73. die
  74. ;;
  75. esac
  76. echo "${result} ${name} ${ttl}" >${cache_path}