Skip to content

Commit 86d7101

Browse files
committed
Merge git://git.linux-nfs.org/projects/trondmy/nfs-2.6
* git://git.linux-nfs.org/projects/trondmy/nfs-2.6: (87 commits) NFSv4: Disallow 'mount -t nfs4 -overs=2' and 'mount -t nfs4 -overs=3' NFS: Allow the "nfs" file system type to support NFSv4 NFS: Move details of nfs4_get_sb() to a helper NFS: Refactor NFSv4 text-based mount option validation NFS: Mount option parser should detect missing "port=" NFS: out of date comment regarding O_EXCL above nfs3_proc_create() NFS: Handle a zero-length auth flavor list SUNRPC: Ensure that sunrpc gets initialised before nfs, lockd, etc... nfs: fix compile error in rpc_pipefs.h nfs: Remove reference to generic_osync_inode from a comment SUNRPC: cache must take a reference to the cache detail's module on open() NFS: Use the DNS resolver in the mount code. NFS: Add a dns resolver for use with NFSv4 referrals and migration SUNRPC: Fix a typo in cache_pipefs_files nfs: nfs4xdr: optimize low level decoding nfs: nfs4xdr: get rid of READ_BUF nfs: nfs4xdr: simplify decode_exchange_id by reusing decode_opaque_inline nfs: nfs4xdr: get rid of COPYMEM nfs: nfs4xdr: introduce decode_sessionid helper nfs: nfs4xdr: introduce decode_verifier helper ...
2 parents 8637343 + ab3bbaa commit 86d7101

48 files changed

Lines changed: 4064 additions & 1805 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/filesystems/nfs.txt‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
The NFS client
3+
==============
4+
5+
The NFS version 2 protocol was first documented in RFC1094 (March 1989).
6+
Since then two more major releases of NFS have been published, with NFSv3
7+
being documented in RFC1813 (June 1995), and NFSv4 in RFC3530 (April
8+
2003).
9+
10+
The Linux NFS client currently supports all the above published versions,
11+
and work is in progress on adding support for minor version 1 of the NFSv4
12+
protocol.
13+
14+
The purpose of this document is to provide information on some of the
15+
upcall interfaces that are used in order to provide the NFS client with
16+
some of the information that it requires in order to fully comply with
17+
the NFS spec.
18+
19+
The DNS resolver
20+
================
21+
22+
NFSv4 allows for one server to refer the NFS client to data that has been
23+
migrated onto another server by means of the special "fs_locations"
24+
attribute. See
25+
http://tools.ietf.org/html/rfc3530#section-6
26+
and
27+
http://tools.ietf.org/html/draft-ietf-nfsv4-referrals-00
28+
29+
The fs_locations information can take the form of either an ip address and
30+
a path, or a DNS hostname and a path. The latter requires the NFS client to
31+
do a DNS lookup in order to mount the new volume, and hence the need for an
32+
upcall to allow userland to provide this service.
33+
34+
Assuming that the user has the 'rpc_pipefs' filesystem mounted in the usual
35+
/var/lib/nfs/rpc_pipefs, the upcall consists of the following steps:
36+
37+
(1) The process checks the dns_resolve cache to see if it contains a
38+
valid entry. If so, it returns that entry and exits.
39+
40+
(2) If no valid entry exists, the helper script '/sbin/nfs_cache_getent'
41+
(may be changed using the 'nfs.cache_getent' kernel boot parameter)
42+
is run, with two arguments:
43+
- the cache name, "dns_resolve"
44+
- the hostname to resolve
45+
46+
(3) After looking up the corresponding ip address, the helper script
47+
writes the result into the rpc_pipefs pseudo-file
48+
'/var/lib/nfs/rpc_pipefs/cache/dns_resolve/channel'
49+
in the following (text) format:
50+
51+
"<ip address> <hostname> <ttl>\n"
52+
53+
Where <ip address> is in the usual IPv4 (123.456.78.90) or IPv6
54+
(ffee:ddcc:bbaa:9988:7766:5544:3322:1100, ffee::1100, ...) format.
55+
<hostname> is identical to the second argument of the helper
56+
script, and <ttl> is the 'time to live' of this cache entry (in
57+
units of seconds).
58+
59+
Note: If <ip address> is invalid, say the string "0", then a negative
60+
entry is created, which will cause the kernel to treat the hostname
61+
as having no valid DNS translation.
62+
63+
64+
65+
66+
A basic sample /sbin/nfs_cache_getent
67+
=====================================
68+
69+
#!/bin/bash
70+
#
71+
ttl=600
72+
#
73+
cut=/usr/bin/cut
74+
getent=/usr/bin/getent
75+
rpc_pipefs=/var/lib/nfs/rpc_pipefs
76+
#
77+
die()
78+
{
79+
echo "Usage: $0 cache_name entry_name"
80+
exit 1
81+
}
82+
83+
[ $# -lt 2 ] && die
84+
cachename="$1"
85+
cache_path=${rpc_pipefs}/cache/${cachename}/channel
86+
87+
case "${cachename}" in
88+
dns_resolve)
89+
name="$2"
90+
result="$(${getent} hosts ${name} | ${cut} -f1 -d\ )"
91+
[ -z "${result}" ] && result="0"
92+
;;
93+
*)
94+
die
95+
;;
96+
esac
97+
echo "${result} ${name} ${ttl}" >${cache_path}
98+

‎Documentation/kernel-parameters.txt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,14 @@ and is between 256 and 4096 characters. It is defined in the file
15031503
[NFS] set the TCP port on which the NFSv4 callback
15041504
channel should listen.
15051505

1506+
nfs.cache_getent=
1507+
[NFS] sets the pathname to the program which is used
1508+
to update the NFS client cache entries.
1509+
1510+
nfs.cache_getent_timeout=
1511+
[NFS] sets the timeout after which an attempt to
1512+
update a cache entry is deemed to have failed.
1513+
15061514
nfs.idmap_cache_timeout=
15071515
[NFS] set the maximum lifetime for idmapper cache
15081516
entries.
@@ -2395,6 +2403,18 @@ and is between 256 and 4096 characters. It is defined in the file
23952403
stifb= [HW]
23962404
Format: bpp:<bpp1>[:<bpp2>[:<bpp3>...]]
23972405

2406+
sunrpc.min_resvport=
2407+
sunrpc.max_resvport=
2408+
[NFS,SUNRPC]
2409+
SunRPC servers often require that client requests
2410+
originate from a privileged port (i.e. a port in the
2411+
range 0 < portnr < 1024).
2412+
An administrator who wishes to reserve some of these
2413+
ports for other uses may adjust the range that the
2414+
kernel's sunrpc client considers to be privileged
2415+
using these two parameters to set the minimum and
2416+
maximum port values.
2417+
23982418
sunrpc.pool_mode=
23992419
[NFS]
24002420
Control how the NFS server code allocates CPUs to
@@ -2411,6 +2431,15 @@ and is between 256 and 4096 characters. It is defined in the file
24112431
pernode one pool for each NUMA node (equivalent
24122432
to global on non-NUMA machines)
24132433

2434+
sunrpc.tcp_slot_table_entries=
2435+
sunrpc.udp_slot_table_entries=
2436+
[NFS,SUNRPC]
2437+
Sets the upper limit on the number of simultaneous
2438+
RPC calls that can be sent from the client to a
2439+
server. Increasing these values may allow you to
2440+
improve throughput, but will also increase the
2441+
amount of memory reserved for use by the client.
2442+
24142443
swiotlb= [IA-64] Number of I/O TLB slabs
24152444

24162445
switches= [HW,M68k]

‎fs/lockd/host.c‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ static unsigned int nlm_hash_address(const struct sockaddr *sap)
8787
return hash & (NLM_HOST_NRHASH - 1);
8888
}
8989

90-
static void nlm_clear_port(struct sockaddr *sap)
91-
{
92-
switch (sap->sa_family) {
93-
case AF_INET:
94-
((struct sockaddr_in *)sap)->sin_port = 0;
95-
break;
96-
case AF_INET6:
97-
((struct sockaddr_in6 *)sap)->sin6_port = 0;
98-
break;
99-
}
100-
}
101-
10290
/*
10391
* Common host lookup routine for server & client
10492
*/
@@ -177,7 +165,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
177165
host->h_addrbuf = nsm->sm_addrbuf;
178166
memcpy(nlm_addr(host), ni->sap, ni->salen);
179167
host->h_addrlen = ni->salen;
180-
nlm_clear_port(nlm_addr(host));
168+
rpc_set_port(nlm_addr(host), 0);
181169
memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len);
182170
host->h_version = ni->version;
183171
host->h_proto = ni->protocol;

‎fs/lockd/mon.c‎

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,6 @@ static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm)
6161
return (struct sockaddr *)&nsm->sm_addr;
6262
}
6363

64-
static void nsm_display_ipv4_address(const struct sockaddr *sap, char *buf,
65-
const size_t len)
66-
{
67-
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
68-
snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr);
69-
}
70-
71-
static void nsm_display_ipv6_address(const struct sockaddr *sap, char *buf,
72-
const size_t len)
73-
{
74-
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
75-
76-
if (ipv6_addr_v4mapped(&sin6->sin6_addr))
77-
snprintf(buf, len, "%pI4", &sin6->sin6_addr.s6_addr32[3]);
78-
else if (sin6->sin6_scope_id != 0)
79-
snprintf(buf, len, "%pI6%%%u", &sin6->sin6_addr,
80-
sin6->sin6_scope_id);
81-
else
82-
snprintf(buf, len, "%pI6", &sin6->sin6_addr);
83-
}
84-
85-
static void nsm_display_address(const struct sockaddr *sap,
86-
char *buf, const size_t len)
87-
{
88-
switch (sap->sa_family) {
89-
case AF_INET:
90-
nsm_display_ipv4_address(sap, buf, len);
91-
break;
92-
case AF_INET6:
93-
nsm_display_ipv6_address(sap, buf, len);
94-
break;
95-
default:
96-
snprintf(buf, len, "unsupported address family");
97-
break;
98-
}
99-
}
100-
10164
static struct rpc_clnt *nsm_create(void)
10265
{
10366
struct sockaddr_in sin = {
@@ -307,8 +270,11 @@ static struct nsm_handle *nsm_create_handle(const struct sockaddr *sap,
307270
memcpy(nsm_addr(new), sap, salen);
308271
new->sm_addrlen = salen;
309272
nsm_init_private(new);
310-
nsm_display_address((const struct sockaddr *)&new->sm_addr,
311-
new->sm_addrbuf, sizeof(new->sm_addrbuf));
273+
274+
if (rpc_ntop(nsm_addr(new), new->sm_addrbuf,
275+
sizeof(new->sm_addrbuf)) == 0)
276+
(void)snprintf(new->sm_addrbuf, sizeof(new->sm_addrbuf),
277+
"unsupported address family");
312278
memcpy(new->sm_name, hostname, hostname_len);
313279
new->sm_name[hostname_len] = '\0';
314280

‎fs/nfs/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ obj-$(CONFIG_NFS_FS) += nfs.o
66

77
nfs-y := client.o dir.o file.o getroot.o inode.o super.o nfs2xdr.o \
88
direct.o pagelist.o proc.o read.o symlink.o unlink.o \
9-
write.o namespace.o mount_clnt.o
9+
write.o namespace.o mount_clnt.o \
10+
dns_resolve.o cache_lib.o
1011
nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
1112
nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o
1213
nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o

‎fs/nfs/cache_lib.c‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* linux/fs/nfs/cache_lib.c
3+
*
4+
* Helper routines for the NFS client caches
5+
*
6+
* Copyright (c) 2009 Trond Myklebust <Trond.Myklebust@netapp.com>
7+
*/
8+
#include <linux/kmod.h>
9+
#include <linux/module.h>
10+
#include <linux/moduleparam.h>
11+
#include <linux/mount.h>
12+
#include <linux/namei.h>
13+
#include <linux/sunrpc/cache.h>
14+
#include <linux/sunrpc/rpc_pipe_fs.h>
15+
16+
#include "cache_lib.h"
17+
18+
#define NFS_CACHE_UPCALL_PATHLEN 256
19+
#define NFS_CACHE_UPCALL_TIMEOUT 15
20+
21+
static char nfs_cache_getent_prog[NFS_CACHE_UPCALL_PATHLEN] =
22+
"/sbin/nfs_cache_getent";
23+
static unsigned long nfs_cache_getent_timeout = NFS_CACHE_UPCALL_TIMEOUT;
24+
25+
module_param_string(cache_getent, nfs_cache_getent_prog,
26+
sizeof(nfs_cache_getent_prog), 0600);
27+
MODULE_PARM_DESC(cache_getent, "Path to the client cache upcall program");
28+
module_param_named(cache_getent_timeout, nfs_cache_getent_timeout, ulong, 0600);
29+
MODULE_PARM_DESC(cache_getent_timeout, "Timeout (in seconds) after which "
30+
"the cache upcall is assumed to have failed");
31+
32+
int nfs_cache_upcall(struct cache_detail *cd, char *entry_name)
33+
{
34+
static char *envp[] = { "HOME=/",
35+
"TERM=linux",
36+
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
37+
NULL
38+
};
39+
char *argv[] = {
40+
nfs_cache_getent_prog,
41+
cd->name,
42+
entry_name,
43+
NULL
44+
};
45+
int ret = -EACCES;
46+
47+
if (nfs_cache_getent_prog[0] == '\0')
48+
goto out;
49+
ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
50+
/*
51+
* Disable the upcall mechanism if we're getting an ENOENT or
52+
* EACCES error. The admin can re-enable it on the fly by using
53+
* sysfs to set the 'cache_getent' parameter once the problem
54+
* has been fixed.
55+
*/
56+
if (ret == -ENOENT || ret == -EACCES)
57+
nfs_cache_getent_prog[0] = '\0';
58+
out:
59+
return ret > 0 ? 0 : ret;
60+
}
61+
62+
/*
63+
* Deferred request handling
64+
*/
65+
void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq)
66+
{
67+
if (atomic_dec_and_test(&dreq->count))
68+
kfree(dreq);
69+
}
70+
71+
static void nfs_dns_cache_revisit(struct cache_deferred_req *d, int toomany)
72+
{
73+
struct nfs_cache_defer_req *dreq;
74+
75+
dreq = container_of(d, struct nfs_cache_defer_req, deferred_req);
76+
77+
complete_all(&dreq->completion);
78+
nfs_cache_defer_req_put(dreq);
79+
}
80+
81+
static struct cache_deferred_req *nfs_dns_cache_defer(struct cache_req *req)
82+
{
83+
struct nfs_cache_defer_req *dreq;
84+
85+
dreq = container_of(req, struct nfs_cache_defer_req, req);
86+
dreq->deferred_req.revisit = nfs_dns_cache_revisit;
87+
atomic_inc(&dreq->count);
88+
89+
return &dreq->deferred_req;
90+
}
91+
92+
struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void)
93+
{
94+
struct nfs_cache_defer_req *dreq;
95+
96+
dreq = kzalloc(sizeof(*dreq), GFP_KERNEL);
97+
if (dreq) {
98+
init_completion(&dreq->completion);
99+
atomic_set(&dreq->count, 1);
100+
dreq->req.defer = nfs_dns_cache_defer;
101+
}
102+
return dreq;
103+
}
104+
105+
int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq)
106+
{
107+
if (wait_for_completion_timeout(&dreq->completion,
108+
nfs_cache_getent_timeout * HZ) == 0)
109+
return -ETIMEDOUT;
110+
return 0;
111+
}
112+
113+
int nfs_cache_register(struct cache_detail *cd)
114+
{
115+
struct nameidata nd;
116+
struct vfsmount *mnt;
117+
int ret;
118+
119+
mnt = rpc_get_mount();
120+
if (IS_ERR(mnt))
121+
return PTR_ERR(mnt);
122+
ret = vfs_path_lookup(mnt->mnt_root, mnt, "/cache", 0, &nd);
123+
if (ret)
124+
goto err;
125+
ret = sunrpc_cache_register_pipefs(nd.path.dentry,
126+
cd->name, 0600, cd);
127+
path_put(&nd.path);
128+
if (!ret)
129+
return ret;
130+
err:
131+
rpc_put_mount();
132+
return ret;
133+
}
134+
135+
void nfs_cache_unregister(struct cache_detail *cd)
136+
{
137+
sunrpc_cache_unregister_pipefs(cd);
138+
rpc_put_mount();
139+
}
140+

0 commit comments

Comments
 (0)