aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2011-01-13 01:06:28 -0500
committerPaul Mundt <lethal@linux-sh.org>2011-01-13 01:06:28 -0500
commitf43dc23d5ea91fca257be02138a255f02d98e806 (patch)
treeb29722f6e965316e90ac97abf79923ced250dc21 /fs/nfs
parentf8e53553f452dcbf67cb89c8cba63a1cd6eb4cc0 (diff)
parent4162cf64973df51fc885825bc9ca4d055891c49f (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into common/serial-rework
Conflicts: arch/sh/kernel/cpu/sh2/setup-sh7619.c arch/sh/kernel/cpu/sh2a/setup-mxg.c arch/sh/kernel/cpu/sh2a/setup-sh7201.c arch/sh/kernel/cpu/sh2a/setup-sh7203.c arch/sh/kernel/cpu/sh2a/setup-sh7206.c arch/sh/kernel/cpu/sh3/setup-sh7705.c arch/sh/kernel/cpu/sh3/setup-sh770x.c arch/sh/kernel/cpu/sh3/setup-sh7710.c arch/sh/kernel/cpu/sh3/setup-sh7720.c arch/sh/kernel/cpu/sh4/setup-sh4-202.c arch/sh/kernel/cpu/sh4/setup-sh7750.c arch/sh/kernel/cpu/sh4/setup-sh7760.c arch/sh/kernel/cpu/sh4a/setup-sh7343.c arch/sh/kernel/cpu/sh4a/setup-sh7366.c arch/sh/kernel/cpu/sh4a/setup-sh7722.c arch/sh/kernel/cpu/sh4a/setup-sh7723.c arch/sh/kernel/cpu/sh4a/setup-sh7724.c arch/sh/kernel/cpu/sh4a/setup-sh7763.c arch/sh/kernel/cpu/sh4a/setup-sh7770.c arch/sh/kernel/cpu/sh4a/setup-sh7780.c arch/sh/kernel/cpu/sh4a/setup-sh7785.c arch/sh/kernel/cpu/sh4a/setup-sh7786.c arch/sh/kernel/cpu/sh4a/setup-shx3.c arch/sh/kernel/cpu/sh5/setup-sh5.c drivers/serial/sh-sci.c drivers/serial/sh-sci.h include/linux/serial_sci.h
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/Kconfig53
-rw-r--r--fs/nfs/Makefile7
-rw-r--r--fs/nfs/cache_lib.c141
-rw-r--r--fs/nfs/cache_lib.h27
-rw-r--r--fs/nfs/callback.c128
-rw-r--r--fs/nfs/callback.h77
-rw-r--r--fs/nfs/callback_proc.c477
-rw-r--r--fs/nfs/callback_xdr.c260
-rw-r--r--fs/nfs/client.c571
-rw-r--r--fs/nfs/delegation.c498
-rw-r--r--fs/nfs/delegation.h10
-rw-r--r--fs/nfs/dir.c1342
-rw-r--r--fs/nfs/direct.c59
-rw-r--r--fs/nfs/dns_resolve.c372
-rw-r--r--fs/nfs/dns_resolve.h26
-rw-r--r--fs/nfs/file.c267
-rw-r--r--fs/nfs/fscache.c48
-rw-r--r--fs/nfs/fscache.h6
-rw-r--r--fs/nfs/getroot.c201
-rw-r--r--fs/nfs/idmap.c217
-rw-r--r--fs/nfs/inode.c459
-rw-r--r--fs/nfs/internal.h129
-rw-r--r--fs/nfs/iostat.h34
-rw-r--r--fs/nfs/mount_clnt.c166
-rw-r--r--fs/nfs/namespace.c38
-rw-r--r--fs/nfs/nfs2xdr.c1344
-rw-r--r--fs/nfs/nfs3acl.c24
-rw-r--r--fs/nfs/nfs3proc.c186
-rw-r--r--fs/nfs/nfs3xdr.c2869
-rw-r--r--fs/nfs/nfs4_fs.h103
-rw-r--r--fs/nfs/nfs4filelayout.c280
-rw-r--r--fs/nfs/nfs4filelayout.h94
-rw-r--r--fs/nfs/nfs4filelayoutdev.c448
-rw-r--r--fs/nfs/nfs4namespace.c39
-rw-r--r--fs/nfs/nfs4proc.c2018
-rw-r--r--fs/nfs/nfs4renewd.c45
-rw-r--r--fs/nfs/nfs4state.c734
-rw-r--r--fs/nfs/nfs4xdr.c3599
-rw-r--r--fs/nfs/nfsroot.c568
-rw-r--r--fs/nfs/pagelist.c73
-rw-r--r--fs/nfs/pnfs.c965
-rw-r--r--fs/nfs/pnfs.h235
-rw-r--r--fs/nfs/proc.c225
-rw-r--r--fs/nfs/read.c31
-rw-r--r--fs/nfs/super.c1053
-rw-r--r--fs/nfs/symlink.c3
-rw-r--r--fs/nfs/sysctl.c26
-rw-r--r--fs/nfs/unlink.c267
-rw-r--r--fs/nfs/write.c456
49 files changed, 14782 insertions, 6516 deletions
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
index 2a77bc25d5af..ba306658a6db 100644
--- a/fs/nfs/Kconfig
+++ b/fs/nfs/Kconfig
@@ -61,9 +61,9 @@ config NFS_V3_ACL
61 If unsure, say N. 61 If unsure, say N.
62 62
63config NFS_V4 63config NFS_V4
64 bool "NFS client support for NFS version 4 (EXPERIMENTAL)" 64 bool "NFS client support for NFS version 4"
65 depends on NFS_FS && EXPERIMENTAL 65 depends on NFS_FS
66 select RPCSEC_GSS_KRB5 66 select SUNRPC_GSS
67 help 67 help
68 This option enables support for version 4 of the NFS protocol 68 This option enables support for version 4 of the NFS protocol
69 (RFC 3530) in the kernel's NFS client. 69 (RFC 3530) in the kernel's NFS client.
@@ -72,16 +72,20 @@ config NFS_V4
72 space programs which can be found in the Linux nfs-utils package, 72 space programs which can be found in the Linux nfs-utils package,
73 available from http://linux-nfs.org/. 73 available from http://linux-nfs.org/.
74 74
75 If unsure, say N. 75 If unsure, say Y.
76 76
77config NFS_V4_1 77config NFS_V4_1
78 bool "NFS client support for NFSv4.1 (DEVELOPER ONLY)" 78 bool "NFS client support for NFSv4.1 (EXPERIMENTAL)"
79 depends on NFS_V4 && EXPERIMENTAL 79 depends on NFS_FS && NFS_V4 && EXPERIMENTAL
80 select PNFS_FILE_LAYOUT
80 help 81 help
81 This option enables support for minor version 1 of the NFSv4 protocol 82 This option enables support for minor version 1 of the NFSv4 protocol
82 (draft-ietf-nfsv4-minorversion1) in the kernel's NFS client. 83 (RFC 5661) in the kernel's NFS client.
84
85 If unsure, say N.
83 86
84 Unless you're an NFS developer, say N. 87config PNFS_FILE_LAYOUT
88 tristate
85 89
86config ROOT_NFS 90config ROOT_NFS
87 bool "Root file system on NFS" 91 bool "Root file system on NFS"
@@ -90,14 +94,41 @@ config ROOT_NFS
90 If you want your system to mount its root file system via NFS, 94 If you want your system to mount its root file system via NFS,
91 choose Y here. This is common practice for managing systems 95 choose Y here. This is common practice for managing systems
92 without local permanent storage. For details, read 96 without local permanent storage. For details, read
93 <file:Documentation/filesystems/nfsroot.txt>. 97 <file:Documentation/filesystems/nfs/nfsroot.txt>.
94 98
95 Most people say N here. 99 Most people say N here.
96 100
97config NFS_FSCACHE 101config NFS_FSCACHE
98 bool "Provide NFS client caching support (EXPERIMENTAL)" 102 bool "Provide NFS client caching support"
99 depends on EXPERIMENTAL
100 depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y 103 depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y
101 help 104 help
102 Say Y here if you want NFS data to be cached locally on disc through 105 Say Y here if you want NFS data to be cached locally on disc through
103 the general filesystem cache manager 106 the general filesystem cache manager
107
108config NFS_USE_LEGACY_DNS
109 bool "Use the legacy NFS DNS resolver"
110 depends on NFS_V4
111 help
112 The kernel now provides a method for translating a host name into an
113 IP address. Select Y here if you would rather use your own DNS
114 resolver script.
115
116 If unsure, say N
117
118config NFS_USE_KERNEL_DNS
119 bool
120 depends on NFS_V4 && !NFS_USE_LEGACY_DNS
121 select DNS_RESOLVER
122 select KEYS
123 default y
124
125config NFS_USE_NEW_IDMAPPER
126 bool "Use the new idmapper upcall routine"
127 depends on NFS_V4 && KEYS
128 help
129 Say Y here if you want NFS to use the new idmapper upcall functions.
130 You will need /sbin/request-key (usually provided by the keyutils
131 package). For details, read
132 <file:Documentation/filesystems/nfs/idmapper.txt>.
133
134 If you are unsure, say N.
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index 845159814de2..4776ff9e3814 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -6,7 +6,8 @@ obj-$(CONFIG_NFS_FS) += nfs.o
6 6
7nfs-y := client.o dir.o file.o getroot.o inode.o super.o nfs2xdr.o \ 7nfs-y := client.o dir.o file.o getroot.o inode.o super.o nfs2xdr.o \
8 direct.o pagelist.o proc.o read.o symlink.o unlink.o \ 8 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
10nfs-$(CONFIG_ROOT_NFS) += nfsroot.o 11nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
11nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o 12nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o
12nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o 13nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o
@@ -14,5 +15,9 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \
14 delegation.o idmap.o \ 15 delegation.o idmap.o \
15 callback.o callback_xdr.o callback_proc.o \ 16 callback.o callback_xdr.o callback_proc.o \
16 nfs4namespace.o 17 nfs4namespace.o
18nfs-$(CONFIG_NFS_V4_1) += pnfs.o
17nfs-$(CONFIG_SYSCTL) += sysctl.o 19nfs-$(CONFIG_SYSCTL) += sysctl.o
18nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o 20nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
21
22obj-$(CONFIG_PNFS_FILE_LAYOUT) += nfs_layout_nfsv41_files.o
23nfs_layout_nfsv41_files-y := nfs4filelayout.o nfs4filelayoutdev.o
diff --git a/fs/nfs/cache_lib.c b/fs/nfs/cache_lib.c
new file mode 100644
index 000000000000..84690319e625
--- /dev/null
+++ b/fs/nfs/cache_lib.c
@@ -0,0 +1,141 @@
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/slab.h>
14#include <linux/sunrpc/cache.h>
15#include <linux/sunrpc/rpc_pipe_fs.h>
16
17#include "cache_lib.h"
18
19#define NFS_CACHE_UPCALL_PATHLEN 256
20#define NFS_CACHE_UPCALL_TIMEOUT 15
21
22static char nfs_cache_getent_prog[NFS_CACHE_UPCALL_PATHLEN] =
23 "/sbin/nfs_cache_getent";
24static unsigned long nfs_cache_getent_timeout = NFS_CACHE_UPCALL_TIMEOUT;
25
26module_param_string(cache_getent, nfs_cache_getent_prog,
27 sizeof(nfs_cache_getent_prog), 0600);
28MODULE_PARM_DESC(cache_getent, "Path to the client cache upcall program");
29module_param_named(cache_getent_timeout, nfs_cache_getent_timeout, ulong, 0600);
30MODULE_PARM_DESC(cache_getent_timeout, "Timeout (in seconds) after which "
31 "the cache upcall is assumed to have failed");
32
33int nfs_cache_upcall(struct cache_detail *cd, char *entry_name)
34{
35 static char *envp[] = { "HOME=/",
36 "TERM=linux",
37 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
38 NULL
39 };
40 char *argv[] = {
41 nfs_cache_getent_prog,
42 cd->name,
43 entry_name,
44 NULL
45 };
46 int ret = -EACCES;
47
48 if (nfs_cache_getent_prog[0] == '\0')
49 goto out;
50 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
51 /*
52 * Disable the upcall mechanism if we're getting an ENOENT or
53 * EACCES error. The admin can re-enable it on the fly by using
54 * sysfs to set the 'cache_getent' parameter once the problem
55 * has been fixed.
56 */
57 if (ret == -ENOENT || ret == -EACCES)
58 nfs_cache_getent_prog[0] = '\0';
59out:
60 return ret > 0 ? 0 : ret;
61}
62
63/*
64 * Deferred request handling
65 */
66void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq)
67{
68 if (atomic_dec_and_test(&dreq->count))
69 kfree(dreq);
70}
71
72static void nfs_dns_cache_revisit(struct cache_deferred_req *d, int toomany)
73{
74 struct nfs_cache_defer_req *dreq;
75
76 dreq = container_of(d, struct nfs_cache_defer_req, deferred_req);
77
78 complete_all(&dreq->completion);
79 nfs_cache_defer_req_put(dreq);
80}
81
82static struct cache_deferred_req *nfs_dns_cache_defer(struct cache_req *req)
83{
84 struct nfs_cache_defer_req *dreq;
85
86 dreq = container_of(req, struct nfs_cache_defer_req, req);
87 dreq->deferred_req.revisit = nfs_dns_cache_revisit;
88 atomic_inc(&dreq->count);
89
90 return &dreq->deferred_req;
91}
92
93struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void)
94{
95 struct nfs_cache_defer_req *dreq;
96
97 dreq = kzalloc(sizeof(*dreq), GFP_KERNEL);
98 if (dreq) {
99 init_completion(&dreq->completion);
100 atomic_set(&dreq->count, 1);
101 dreq->req.defer = nfs_dns_cache_defer;
102 }
103 return dreq;
104}
105
106int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq)
107{
108 if (wait_for_completion_timeout(&dreq->completion,
109 nfs_cache_getent_timeout * HZ) == 0)
110 return -ETIMEDOUT;
111 return 0;
112}
113
114int nfs_cache_register(struct cache_detail *cd)
115{
116 struct nameidata nd;
117 struct vfsmount *mnt;
118 int ret;
119
120 mnt = rpc_get_mount();
121 if (IS_ERR(mnt))
122 return PTR_ERR(mnt);
123 ret = vfs_path_lookup(mnt->mnt_root, mnt, "/cache", 0, &nd);
124 if (ret)
125 goto err;
126 ret = sunrpc_cache_register_pipefs(nd.path.dentry,
127 cd->name, 0600, cd);
128 path_put(&nd.path);
129 if (!ret)
130 return ret;
131err:
132 rpc_put_mount();
133 return ret;
134}
135
136void nfs_cache_unregister(struct cache_detail *cd)
137{
138 sunrpc_cache_unregister_pipefs(cd);
139 rpc_put_mount();
140}
141
diff --git a/fs/nfs/cache_lib.h b/fs/nfs/cache_lib.h
new file mode 100644
index 000000000000..76f856e284e4
--- /dev/null
+++ b/fs/nfs/cache_lib.h
@@ -0,0 +1,27 @@
1/*
2 * Helper routines for the NFS client caches
3 *
4 * Copyright (c) 2009 Trond Myklebust <Trond.Myklebust@netapp.com>
5 */
6
7#include <linux/completion.h>
8#include <linux/sunrpc/cache.h>
9#include <asm/atomic.h>
10
11/*
12 * Deferred request handling
13 */
14struct nfs_cache_defer_req {
15 struct cache_req req;
16 struct cache_deferred_req deferred_req;
17 struct completion completion;
18 atomic_t count;
19};
20
21extern int nfs_cache_upcall(struct cache_detail *cd, char *entry_name);
22extern struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void);
23extern void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq);
24extern int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq);
25
26extern int nfs_cache_register(struct cache_detail *cd);
27extern void nfs_cache_unregister(struct cache_detail *cd);
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 7f604c7941fb..199016528fcb 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -9,7 +9,6 @@
9#include <linux/completion.h> 9#include <linux/completion.h>
10#include <linux/ip.h> 10#include <linux/ip.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/smp_lock.h>
13#include <linux/sunrpc/svc.h> 12#include <linux/sunrpc/svc.h>
14#include <linux/sunrpc/svcsock.h> 13#include <linux/sunrpc/svcsock.h>
15#include <linux/nfs_fs.h> 14#include <linux/nfs_fs.h>
@@ -17,9 +16,7 @@
17#include <linux/freezer.h> 16#include <linux/freezer.h>
18#include <linux/kthread.h> 17#include <linux/kthread.h>
19#include <linux/sunrpc/svcauth_gss.h> 18#include <linux/sunrpc/svcauth_gss.h>
20#if defined(CONFIG_NFS_V4_1)
21#include <linux/sunrpc/bc_xprt.h> 19#include <linux/sunrpc/bc_xprt.h>
22#endif
23 20
24#include <net/inet_sock.h> 21#include <net/inet_sock.h>
25 22
@@ -43,21 +40,28 @@ static struct svc_program nfs4_callback_program;
43unsigned int nfs_callback_set_tcpport; 40unsigned int nfs_callback_set_tcpport;
44unsigned short nfs_callback_tcpport; 41unsigned short nfs_callback_tcpport;
45unsigned short nfs_callback_tcpport6; 42unsigned short nfs_callback_tcpport6;
46static const int nfs_set_port_min = 0; 43#define NFS_CALLBACK_MAXPORTNR (65535U)
47static const int nfs_set_port_max = 65535;
48 44
49static int param_set_port(const char *val, struct kernel_param *kp) 45static int param_set_portnr(const char *val, const struct kernel_param *kp)
50{ 46{
51 char *endp; 47 unsigned long num;
52 int num = simple_strtol(val, &endp, 0); 48 int ret;
53 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max) 49
50 if (!val)
51 return -EINVAL;
52 ret = strict_strtoul(val, 0, &num);
53 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
54 return -EINVAL; 54 return -EINVAL;
55 *((int *)kp->arg) = num; 55 *((unsigned int *)kp->arg) = num;
56 return 0; 56 return 0;
57} 57}
58static struct kernel_param_ops param_ops_portnr = {
59 .set = param_set_portnr,
60 .get = param_get_uint,
61};
62#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
58 63
59module_param_call(callback_tcpport, param_set_port, param_get_int, 64module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
60 &nfs_callback_set_tcpport, 0644);
61 65
62/* 66/*
63 * This is the NFSv4 callback kernel thread. 67 * This is the NFSv4 callback kernel thread.
@@ -70,11 +74,6 @@ nfs4_callback_svc(void *vrqstp)
70 74
71 set_freezable(); 75 set_freezable();
72 76
73 /*
74 * FIXME: do we really need to run this under the BKL? If so, please
75 * add a comment about what it's intended to protect.
76 */
77 lock_kernel();
78 while (!kthread_should_stop()) { 77 while (!kthread_should_stop()) {
79 /* 78 /*
80 * Listen for a request on the socket 79 * Listen for a request on the socket
@@ -96,7 +95,6 @@ nfs4_callback_svc(void *vrqstp)
96 preverr = err; 95 preverr = err;
97 svc_process(rqstp); 96 svc_process(rqstp);
98 } 97 }
99 unlock_kernel();
100 return 0; 98 return 0;
101} 99}
102 100
@@ -108,7 +106,7 @@ nfs4_callback_up(struct svc_serv *serv)
108{ 106{
109 int ret; 107 int ret;
110 108
111 ret = svc_create_xprt(serv, "tcp", PF_INET, 109 ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET,
112 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); 110 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
113 if (ret <= 0) 111 if (ret <= 0)
114 goto out_err; 112 goto out_err;
@@ -116,8 +114,7 @@ nfs4_callback_up(struct svc_serv *serv)
116 dprintk("NFS: Callback listener port = %u (af %u)\n", 114 dprintk("NFS: Callback listener port = %u (af %u)\n",
117 nfs_callback_tcpport, PF_INET); 115 nfs_callback_tcpport, PF_INET);
118 116
119#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 117 ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET6,
120 ret = svc_create_xprt(serv, "tcp", PF_INET6,
121 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); 118 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
122 if (ret > 0) { 119 if (ret > 0) {
123 nfs_callback_tcpport6 = ret; 120 nfs_callback_tcpport6 = ret;
@@ -127,7 +124,6 @@ nfs4_callback_up(struct svc_serv *serv)
127 ret = 0; 124 ret = 0;
128 else 125 else
129 goto out_err; 126 goto out_err;
130#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
131 127
132 return svc_prepare_thread(serv, &serv->sv_pools[0]); 128 return svc_prepare_thread(serv, &serv->sv_pools[0]);
133 129
@@ -139,6 +135,33 @@ out_err:
139 135
140#if defined(CONFIG_NFS_V4_1) 136#if defined(CONFIG_NFS_V4_1)
141/* 137/*
138 * * CB_SEQUENCE operations will fail until the callback sessionid is set.
139 * */
140int nfs4_set_callback_sessionid(struct nfs_client *clp)
141{
142 struct svc_serv *serv = clp->cl_rpcclient->cl_xprt->bc_serv;
143 struct nfs4_sessionid *bc_sid;
144
145 if (!serv->sv_bc_xprt)
146 return -EINVAL;
147
148 /* on success freed in xprt_free */
149 bc_sid = kmalloc(sizeof(struct nfs4_sessionid), GFP_KERNEL);
150 if (!bc_sid)
151 return -ENOMEM;
152 memcpy(bc_sid->data, &clp->cl_session->sess_id.data,
153 NFS4_MAX_SESSIONID_LEN);
154 spin_lock_bh(&serv->sv_cb_lock);
155 serv->sv_bc_xprt->xpt_bc_sid = bc_sid;
156 spin_unlock_bh(&serv->sv_cb_lock);
157 dprintk("%s set xpt_bc_sid=%u:%u:%u:%u for sv_bc_xprt %p\n", __func__,
158 ((u32 *)bc_sid->data)[0], ((u32 *)bc_sid->data)[1],
159 ((u32 *)bc_sid->data)[2], ((u32 *)bc_sid->data)[3],
160 serv->sv_bc_xprt);
161 return 0;
162}
163
164/*
142 * The callback service for NFSv4.1 callbacks 165 * The callback service for NFSv4.1 callbacks
143 */ 166 */
144static int 167static int
@@ -152,11 +175,6 @@ nfs41_callback_svc(void *vrqstp)
152 175
153 set_freezable(); 176 set_freezable();
154 177
155 /*
156 * FIXME: do we really need to run this under the BKL? If so, please
157 * add a comment about what it's intended to protect.
158 */
159 lock_kernel();
160 while (!kthread_should_stop()) { 178 while (!kthread_should_stop()) {
161 prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE); 179 prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE);
162 spin_lock_bh(&serv->sv_cb_lock); 180 spin_lock_bh(&serv->sv_cb_lock);
@@ -175,7 +193,6 @@ nfs41_callback_svc(void *vrqstp)
175 } 193 }
176 finish_wait(&serv->sv_cb_waitq, &wq); 194 finish_wait(&serv->sv_cb_waitq, &wq);
177 } 195 }
178 unlock_kernel();
179 return 0; 196 return 0;
180} 197}
181 198
@@ -185,30 +202,38 @@ nfs41_callback_svc(void *vrqstp)
185struct svc_rqst * 202struct svc_rqst *
186nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) 203nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
187{ 204{
188 struct svc_xprt *bc_xprt; 205 struct svc_rqst *rqstp;
189 struct svc_rqst *rqstp = ERR_PTR(-ENOMEM); 206 int ret;
190 207
191 dprintk("--> %s\n", __func__); 208 /*
192 /* Create a svc_sock for the service */ 209 * Create an svc_sock for the back channel service that shares the
193 bc_xprt = svc_sock_create(serv, xprt->prot); 210 * fore channel connection.
194 if (!bc_xprt) 211 * Returns the input port (0) and sets the svc_serv bc_xprt on success
212 */
213 ret = svc_create_xprt(serv, "tcp-bc", &init_net, PF_INET, 0,
214 SVC_SOCK_ANONYMOUS);
215 if (ret < 0) {
216 rqstp = ERR_PTR(ret);
195 goto out; 217 goto out;
218 }
196 219
197 /* 220 /*
198 * Save the svc_serv in the transport so that it can 221 * Save the svc_serv in the transport so that it can
199 * be referenced when the session backchannel is initialized 222 * be referenced when the session backchannel is initialized
200 */ 223 */
201 serv->bc_xprt = bc_xprt;
202 xprt->bc_serv = serv; 224 xprt->bc_serv = serv;
203 225
204 INIT_LIST_HEAD(&serv->sv_cb_list); 226 INIT_LIST_HEAD(&serv->sv_cb_list);
205 spin_lock_init(&serv->sv_cb_lock); 227 spin_lock_init(&serv->sv_cb_lock);
206 init_waitqueue_head(&serv->sv_cb_waitq); 228 init_waitqueue_head(&serv->sv_cb_waitq);
207 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]); 229 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]);
208 if (IS_ERR(rqstp)) 230 if (IS_ERR(rqstp)) {
209 svc_sock_destroy(bc_xprt); 231 svc_xprt_put(serv->sv_bc_xprt);
232 serv->sv_bc_xprt = NULL;
233 }
210out: 234out:
211 dprintk("--> %s return %p\n", __func__, rqstp); 235 dprintk("--> %s return %ld\n", __func__,
236 IS_ERR(rqstp) ? PTR_ERR(rqstp) : 0);
212 return rqstp; 237 return rqstp;
213} 238}
214 239
@@ -241,6 +266,10 @@ static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt,
241 struct nfs_callback_data *cb_info) 266 struct nfs_callback_data *cb_info)
242{ 267{
243} 268}
269int nfs4_set_callback_sessionid(struct nfs_client *clp)
270{
271 return 0;
272}
244#endif /* CONFIG_NFS_V4_1 */ 273#endif /* CONFIG_NFS_V4_1 */
245 274
246/* 275/*
@@ -336,6 +365,9 @@ static int check_gss_callback_principal(struct nfs_client *clp,
336 struct rpc_clnt *r = clp->cl_rpcclient; 365 struct rpc_clnt *r = clp->cl_rpcclient;
337 char *p = svc_gss_principal(rqstp); 366 char *p = svc_gss_principal(rqstp);
338 367
368 /* No RPC_AUTH_GSS on NFSv4.1 back channel yet */
369 if (clp->cl_minorversion != 0)
370 return SVC_DROP;
339 /* 371 /*
340 * It might just be a normal user principal, in which case 372 * It might just be a normal user principal, in which case
341 * userspace won't bother to tell us the name at all. 373 * userspace won't bother to tell us the name at all.
@@ -353,6 +385,23 @@ static int check_gss_callback_principal(struct nfs_client *clp,
353 return SVC_OK; 385 return SVC_OK;
354} 386}
355 387
388/* pg_authenticate method helper */
389static struct nfs_client *nfs_cb_find_client(struct svc_rqst *rqstp)
390{
391 struct nfs4_sessionid *sessionid = bc_xprt_sid(rqstp);
392 int is_cb_compound = rqstp->rq_proc == CB_COMPOUND ? 1 : 0;
393
394 dprintk("--> %s rq_proc %d\n", __func__, rqstp->rq_proc);
395 if (svc_is_backchannel(rqstp))
396 /* Sessionid (usually) set after CB_NULL ping */
397 return nfs4_find_client_sessionid(svc_addr(rqstp), sessionid,
398 is_cb_compound);
399 else
400 /* No callback identifier in pg_authenticate */
401 return nfs4_find_client_no_ident(svc_addr(rqstp));
402}
403
404/* pg_authenticate method for nfsv4 callback threads. */
356static int nfs_callback_authenticate(struct svc_rqst *rqstp) 405static int nfs_callback_authenticate(struct svc_rqst *rqstp)
357{ 406{
358 struct nfs_client *clp; 407 struct nfs_client *clp;
@@ -360,7 +409,7 @@ static int nfs_callback_authenticate(struct svc_rqst *rqstp)
360 int ret = SVC_OK; 409 int ret = SVC_OK;
361 410
362 /* Don't talk to strangers */ 411 /* Don't talk to strangers */
363 clp = nfs_find_client(svc_addr(rqstp), 4); 412 clp = nfs_cb_find_client(rqstp);
364 if (clp == NULL) 413 if (clp == NULL)
365 return SVC_DROP; 414 return SVC_DROP;
366 415
@@ -389,6 +438,7 @@ static int nfs_callback_authenticate(struct svc_rqst *rqstp)
389 */ 438 */
390static struct svc_version *nfs4_callback_version[] = { 439static struct svc_version *nfs4_callback_version[] = {
391 [1] = &nfs4_callback_version1, 440 [1] = &nfs4_callback_version1,
441 [4] = &nfs4_callback_version4,
392}; 442};
393 443
394static struct svc_stat nfs4_callback_stats; 444static struct svc_stat nfs4_callback_stats;
diff --git a/fs/nfs/callback.h b/fs/nfs/callback.h
index 07baa8254ca1..d3b44f9bd747 100644
--- a/fs/nfs/callback.h
+++ b/fs/nfs/callback.h
@@ -34,10 +34,17 @@ enum nfs4_callback_opnum {
34 OP_CB_ILLEGAL = 10044, 34 OP_CB_ILLEGAL = 10044,
35}; 35};
36 36
37struct cb_process_state {
38 __be32 drc_status;
39 struct nfs_client *clp;
40 struct nfs4_sessionid *svc_sid; /* v4.1 callback service sessionid */
41};
42
37struct cb_compound_hdr_arg { 43struct cb_compound_hdr_arg {
38 unsigned int taglen; 44 unsigned int taglen;
39 const char *tag; 45 const char *tag;
40 unsigned int minorversion; 46 unsigned int minorversion;
47 unsigned int cb_ident; /* v4.0 callback identifier */
41 unsigned nops; 48 unsigned nops;
42}; 49};
43 50
@@ -103,19 +110,77 @@ struct cb_sequenceres {
103 uint32_t csr_target_highestslotid; 110 uint32_t csr_target_highestslotid;
104}; 111};
105 112
106extern unsigned nfs4_callback_sequence(struct cb_sequenceargs *args, 113extern __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
107 struct cb_sequenceres *res); 114 struct cb_sequenceres *res,
115 struct cb_process_state *cps);
116
117extern int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation,
118 const nfs4_stateid *stateid);
119
120#define RCA4_TYPE_MASK_RDATA_DLG 0
121#define RCA4_TYPE_MASK_WDATA_DLG 1
122#define RCA4_TYPE_MASK_DIR_DLG 2
123#define RCA4_TYPE_MASK_FILE_LAYOUT 3
124#define RCA4_TYPE_MASK_BLK_LAYOUT 4
125#define RCA4_TYPE_MASK_OBJ_LAYOUT_MIN 8
126#define RCA4_TYPE_MASK_OBJ_LAYOUT_MAX 9
127#define RCA4_TYPE_MASK_OTHER_LAYOUT_MIN 12
128#define RCA4_TYPE_MASK_OTHER_LAYOUT_MAX 15
129#define RCA4_TYPE_MASK_ALL 0xf31f
130
131struct cb_recallanyargs {
132 struct sockaddr *craa_addr;
133 uint32_t craa_objs_to_keep;
134 uint32_t craa_type_mask;
135};
108 136
109#endif /* CONFIG_NFS_V4_1 */ 137extern __be32 nfs4_callback_recallany(struct cb_recallanyargs *args,
138 void *dummy,
139 struct cb_process_state *cps);
140
141struct cb_recallslotargs {
142 struct sockaddr *crsa_addr;
143 uint32_t crsa_target_max_slots;
144};
145extern __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args,
146 void *dummy,
147 struct cb_process_state *cps);
148
149struct cb_layoutrecallargs {
150 struct sockaddr *cbl_addr;
151 uint32_t cbl_recall_type;
152 uint32_t cbl_layout_type;
153 uint32_t cbl_layoutchanged;
154 union {
155 struct {
156 struct nfs_fh cbl_fh;
157 struct pnfs_layout_range cbl_range;
158 nfs4_stateid cbl_stateid;
159 };
160 struct nfs_fsid cbl_fsid;
161 };
162};
110 163
111extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res); 164extern unsigned nfs4_callback_layoutrecall(
112extern __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy); 165 struct cb_layoutrecallargs *args,
166 void *dummy, struct cb_process_state *cps);
113 167
168extern void nfs4_check_drain_bc_complete(struct nfs4_session *ses);
169extern void nfs4_cb_take_slot(struct nfs_client *clp);
170#endif /* CONFIG_NFS_V4_1 */
171
172extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
173 struct cb_getattrres *res,
174 struct cb_process_state *cps);
175extern __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
176 struct cb_process_state *cps);
114#ifdef CONFIG_NFS_V4 177#ifdef CONFIG_NFS_V4
115extern int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt); 178extern int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt);
116extern void nfs_callback_down(int minorversion); 179extern void nfs_callback_down(int minorversion);
180extern int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation,
181 const nfs4_stateid *stateid);
182extern int nfs4_set_callback_sessionid(struct nfs_client *clp);
117#endif /* CONFIG_NFS_V4 */ 183#endif /* CONFIG_NFS_V4 */
118
119/* 184/*
120 * nfs41: Callbacks are expected to not cause substantial latency, 185 * nfs41: Callbacks are expected to not cause substantial latency,
121 * so we limit their concurrency to 1 by setting up the maximum number 186 * so we limit their concurrency to 1 by setting up the maximum number
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index b7da1f54da68..4bb91cb2620d 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -7,37 +7,41 @@
7 */ 7 */
8#include <linux/nfs4.h> 8#include <linux/nfs4.h>
9#include <linux/nfs_fs.h> 9#include <linux/nfs_fs.h>
10#include <linux/slab.h>
10#include "nfs4_fs.h" 11#include "nfs4_fs.h"
11#include "callback.h" 12#include "callback.h"
12#include "delegation.h" 13#include "delegation.h"
13#include "internal.h" 14#include "internal.h"
15#include "pnfs.h"
14 16
15#ifdef NFS_DEBUG 17#ifdef NFS_DEBUG
16#define NFSDBG_FACILITY NFSDBG_CALLBACK 18#define NFSDBG_FACILITY NFSDBG_CALLBACK
17#endif 19#endif
18 20
19__be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res) 21__be32 nfs4_callback_getattr(struct cb_getattrargs *args,
22 struct cb_getattrres *res,
23 struct cb_process_state *cps)
20{ 24{
21 struct nfs_client *clp;
22 struct nfs_delegation *delegation; 25 struct nfs_delegation *delegation;
23 struct nfs_inode *nfsi; 26 struct nfs_inode *nfsi;
24 struct inode *inode; 27 struct inode *inode;
25 28
29 res->status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
30 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
31 goto out;
32
26 res->bitmap[0] = res->bitmap[1] = 0; 33 res->bitmap[0] = res->bitmap[1] = 0;
27 res->status = htonl(NFS4ERR_BADHANDLE); 34 res->status = htonl(NFS4ERR_BADHANDLE);
28 clp = nfs_find_client(args->addr, 4);
29 if (clp == NULL)
30 goto out;
31 35
32 dprintk("NFS: GETATTR callback request from %s\n", 36 dprintk("NFS: GETATTR callback request from %s\n",
33 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 37 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
34 38
35 inode = nfs_delegation_find_inode(clp, &args->fh); 39 inode = nfs_delegation_find_inode(cps->clp, &args->fh);
36 if (inode == NULL) 40 if (inode == NULL)
37 goto out_putclient; 41 goto out;
38 nfsi = NFS_I(inode); 42 nfsi = NFS_I(inode);
39 down_read(&nfsi->rwsem); 43 rcu_read_lock();
40 delegation = nfsi->delegation; 44 delegation = rcu_dereference(nfsi->delegation);
41 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0) 45 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
42 goto out_iput; 46 goto out_iput;
43 res->size = i_size_read(inode); 47 res->size = i_size_read(inode);
@@ -52,101 +56,254 @@ __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *
52 args->bitmap[1]; 56 args->bitmap[1];
53 res->status = 0; 57 res->status = 0;
54out_iput: 58out_iput:
55 up_read(&nfsi->rwsem); 59 rcu_read_unlock();
56 iput(inode); 60 iput(inode);
57out_putclient:
58 nfs_put_client(clp);
59out: 61out:
60 dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status)); 62 dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status));
61 return res->status; 63 return res->status;
62} 64}
63 65
64__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy) 66__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
67 struct cb_process_state *cps)
65{ 68{
66 struct nfs_client *clp;
67 struct inode *inode; 69 struct inode *inode;
68 __be32 res; 70 __be32 res;
69 71
70 res = htonl(NFS4ERR_BADHANDLE); 72 res = htonl(NFS4ERR_OP_NOT_IN_SESSION);
71 clp = nfs_find_client(args->addr, 4); 73 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
72 if (clp == NULL)
73 goto out; 74 goto out;
74 75
75 dprintk("NFS: RECALL callback request from %s\n", 76 dprintk("NFS: RECALL callback request from %s\n",
76 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 77 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
77 78
78 do { 79 res = htonl(NFS4ERR_BADHANDLE);
79 struct nfs_client *prev = clp; 80 inode = nfs_delegation_find_inode(cps->clp, &args->fh);
80 81 if (inode == NULL)
81 inode = nfs_delegation_find_inode(clp, &args->fh); 82 goto out;
82 if (inode != NULL) { 83 /* Set up a helper thread to actually return the delegation */
83 /* Set up a helper thread to actually return the delegation */ 84 switch (nfs_async_inode_return_delegation(inode, &args->stateid)) {
84 switch(nfs_async_inode_return_delegation(inode, &args->stateid)) { 85 case 0:
85 case 0: 86 res = 0;
86 res = 0; 87 break;
87 break; 88 case -ENOENT:
88 case -ENOENT: 89 if (res != 0)
89 if (res != 0) 90 res = htonl(NFS4ERR_BAD_STATEID);
90 res = htonl(NFS4ERR_BAD_STATEID); 91 break;
91 break; 92 default:
92 default: 93 res = htonl(NFS4ERR_RESOURCE);
93 res = htonl(NFS4ERR_RESOURCE); 94 }
94 } 95 iput(inode);
95 iput(inode);
96 }
97 clp = nfs_find_client_next(prev);
98 nfs_put_client(prev);
99 } while (clp != NULL);
100out: 96out:
101 dprintk("%s: exit with status = %d\n", __func__, ntohl(res)); 97 dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
102 return res; 98 return res;
103} 99}
104 100
101int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
102{
103 if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data,
104 sizeof(delegation->stateid.data)) != 0)
105 return 0;
106 return 1;
107}
108
105#if defined(CONFIG_NFS_V4_1) 109#if defined(CONFIG_NFS_V4_1)
106 110
111static u32 initiate_file_draining(struct nfs_client *clp,
112 struct cb_layoutrecallargs *args)
113{
114 struct pnfs_layout_hdr *lo;
115 struct inode *ino;
116 bool found = false;
117 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
118 LIST_HEAD(free_me_list);
119
120 spin_lock(&clp->cl_lock);
121 list_for_each_entry(lo, &clp->cl_layouts, plh_layouts) {
122 if (nfs_compare_fh(&args->cbl_fh,
123 &NFS_I(lo->plh_inode)->fh))
124 continue;
125 ino = igrab(lo->plh_inode);
126 if (!ino)
127 continue;
128 found = true;
129 /* Without this, layout can be freed as soon
130 * as we release cl_lock.
131 */
132 get_layout_hdr(lo);
133 break;
134 }
135 spin_unlock(&clp->cl_lock);
136 if (!found)
137 return NFS4ERR_NOMATCHING_LAYOUT;
138
139 spin_lock(&ino->i_lock);
140 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
141 mark_matching_lsegs_invalid(lo, &free_me_list,
142 args->cbl_range.iomode))
143 rv = NFS4ERR_DELAY;
144 else
145 rv = NFS4ERR_NOMATCHING_LAYOUT;
146 pnfs_set_layout_stateid(lo, &args->cbl_stateid, true);
147 spin_unlock(&ino->i_lock);
148 pnfs_free_lseg_list(&free_me_list);
149 put_layout_hdr(lo);
150 iput(ino);
151 return rv;
152}
153
154static u32 initiate_bulk_draining(struct nfs_client *clp,
155 struct cb_layoutrecallargs *args)
156{
157 struct pnfs_layout_hdr *lo;
158 struct inode *ino;
159 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
160 struct pnfs_layout_hdr *tmp;
161 LIST_HEAD(recall_list);
162 LIST_HEAD(free_me_list);
163 struct pnfs_layout_range range = {
164 .iomode = IOMODE_ANY,
165 .offset = 0,
166 .length = NFS4_MAX_UINT64,
167 };
168
169 spin_lock(&clp->cl_lock);
170 list_for_each_entry(lo, &clp->cl_layouts, plh_layouts) {
171 if ((args->cbl_recall_type == RETURN_FSID) &&
172 memcmp(&NFS_SERVER(lo->plh_inode)->fsid,
173 &args->cbl_fsid, sizeof(struct nfs_fsid)))
174 continue;
175 if (!igrab(lo->plh_inode))
176 continue;
177 get_layout_hdr(lo);
178 BUG_ON(!list_empty(&lo->plh_bulk_recall));
179 list_add(&lo->plh_bulk_recall, &recall_list);
180 }
181 spin_unlock(&clp->cl_lock);
182 list_for_each_entry_safe(lo, tmp,
183 &recall_list, plh_bulk_recall) {
184 ino = lo->plh_inode;
185 spin_lock(&ino->i_lock);
186 set_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
187 if (mark_matching_lsegs_invalid(lo, &free_me_list, range.iomode))
188 rv = NFS4ERR_DELAY;
189 list_del_init(&lo->plh_bulk_recall);
190 spin_unlock(&ino->i_lock);
191 put_layout_hdr(lo);
192 iput(ino);
193 }
194 pnfs_free_lseg_list(&free_me_list);
195 return rv;
196}
197
198static u32 do_callback_layoutrecall(struct nfs_client *clp,
199 struct cb_layoutrecallargs *args)
200{
201 u32 res = NFS4ERR_DELAY;
202
203 dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type);
204 if (test_and_set_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state))
205 goto out;
206 if (args->cbl_recall_type == RETURN_FILE)
207 res = initiate_file_draining(clp, args);
208 else
209 res = initiate_bulk_draining(clp, args);
210 clear_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state);
211out:
212 dprintk("%s returning %i\n", __func__, res);
213 return res;
214
215}
216
217__be32 nfs4_callback_layoutrecall(struct cb_layoutrecallargs *args,
218 void *dummy, struct cb_process_state *cps)
219{
220 u32 res;
221
222 dprintk("%s: -->\n", __func__);
223
224 if (cps->clp)
225 res = do_callback_layoutrecall(cps->clp, args);
226 else
227 res = NFS4ERR_OP_NOT_IN_SESSION;
228
229 dprintk("%s: exit with status = %d\n", __func__, res);
230 return cpu_to_be32(res);
231}
232
233static void pnfs_recall_all_layouts(struct nfs_client *clp)
234{
235 struct cb_layoutrecallargs args;
236
237 /* Pretend we got a CB_LAYOUTRECALL(ALL) */
238 memset(&args, 0, sizeof(args));
239 args.cbl_recall_type = RETURN_ALL;
240 /* FIXME we ignore errors, what should we do? */
241 do_callback_layoutrecall(clp, &args);
242}
243
244int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
245{
246 if (delegation == NULL)
247 return 0;
248
249 if (stateid->stateid.seqid != 0)
250 return 0;
251 if (memcmp(&delegation->stateid.stateid.other,
252 &stateid->stateid.other,
253 NFS4_STATEID_OTHER_SIZE))
254 return 0;
255
256 return 1;
257}
258
107/* 259/*
108 * Validate the sequenceID sent by the server. 260 * Validate the sequenceID sent by the server.
109 * Return success if the sequenceID is one more than what we last saw on 261 * Return success if the sequenceID is one more than what we last saw on
110 * this slot, accounting for wraparound. Increments the slot's sequence. 262 * this slot, accounting for wraparound. Increments the slot's sequence.
111 * 263 *
112 * We don't yet implement a duplicate request cache, so at this time 264 * We don't yet implement a duplicate request cache, instead we set the
113 * we will log replays, and process them as if we had not seen them before, 265 * back channel ca_maxresponsesize_cached to zero. This is OK for now
114 * but we don't bump the sequence in the slot. Not too worried about it,
115 * since we only currently implement idempotent callbacks anyway. 266 * since we only currently implement idempotent callbacks anyway.
116 * 267 *
117 * We have a single slot backchannel at this time, so we don't bother 268 * We have a single slot backchannel at this time, so we don't bother
118 * checking the used_slots bit array on the table. The lower layer guarantees 269 * checking the used_slots bit array on the table. The lower layer guarantees
119 * a single outstanding callback request at a time. 270 * a single outstanding callback request at a time.
120 */ 271 */
121static int 272static __be32
122validate_seqid(struct nfs4_slot_table *tbl, u32 slotid, u32 seqid) 273validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args)
123{ 274{
124 struct nfs4_slot *slot; 275 struct nfs4_slot *slot;
125 276
126 dprintk("%s enter. slotid %d seqid %d\n", 277 dprintk("%s enter. slotid %d seqid %d\n",
127 __func__, slotid, seqid); 278 __func__, args->csa_slotid, args->csa_sequenceid);
128 279
129 if (slotid > NFS41_BC_MAX_CALLBACKS) 280 if (args->csa_slotid > NFS41_BC_MAX_CALLBACKS)
130 return htonl(NFS4ERR_BADSLOT); 281 return htonl(NFS4ERR_BADSLOT);
131 282
132 slot = tbl->slots + slotid; 283 slot = tbl->slots + args->csa_slotid;
133 dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr); 284 dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr);
134 285
135 /* Normal */ 286 /* Normal */
136 if (likely(seqid == slot->seq_nr + 1)) { 287 if (likely(args->csa_sequenceid == slot->seq_nr + 1)) {
137 slot->seq_nr++; 288 slot->seq_nr++;
138 return htonl(NFS4_OK); 289 return htonl(NFS4_OK);
139 } 290 }
140 291
141 /* Replay */ 292 /* Replay */
142 if (seqid == slot->seq_nr) { 293 if (args->csa_sequenceid == slot->seq_nr) {
143 dprintk("%s seqid %d is a replay - no DRC available\n", 294 dprintk("%s seqid %d is a replay\n",
144 __func__, seqid); 295 __func__, args->csa_sequenceid);
145 return htonl(NFS4_OK); 296 /* Signal process_op to set this error on next op */
297 if (args->csa_cachethis == 0)
298 return htonl(NFS4ERR_RETRY_UNCACHED_REP);
299
300 /* The ca_maxresponsesize_cached is 0 with no DRC */
301 else if (args->csa_cachethis == 1)
302 return htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE);
146 } 303 }
147 304
148 /* Wraparound */ 305 /* Wraparound */
149 if (seqid == 1 && (slot->seq_nr + 1) == 0) { 306 if (args->csa_sequenceid == 1 && (slot->seq_nr + 1) == 0) {
150 slot->seq_nr = 1; 307 slot->seq_nr = 1;
151 return htonl(NFS4_OK); 308 return htonl(NFS4_OK);
152 } 309 }
@@ -156,61 +313,99 @@ validate_seqid(struct nfs4_slot_table *tbl, u32 slotid, u32 seqid)
156} 313}
157 314
158/* 315/*
159 * Returns a pointer to a held 'struct nfs_client' that matches the server's 316 * For each referring call triple, check the session's slot table for
160 * address, major version number, and session ID. It is the caller's 317 * a match. If the slot is in use and the sequence numbers match, the
161 * responsibility to release the returned reference. 318 * client is still waiting for a response to the original request.
162 *
163 * Returns NULL if there are no connections with sessions, or if no session
164 * matches the one of interest.
165 */ 319 */
166 static struct nfs_client *find_client_with_session( 320static bool referring_call_exists(struct nfs_client *clp,
167 const struct sockaddr *addr, u32 nfsversion, 321 uint32_t nrclists,
168 struct nfs4_sessionid *sessionid) 322 struct referring_call_list *rclists)
169{ 323{
170 struct nfs_client *clp; 324 bool status = 0;
325 int i, j;
326 struct nfs4_session *session;
327 struct nfs4_slot_table *tbl;
328 struct referring_call_list *rclist;
329 struct referring_call *ref;
171 330
172 clp = nfs_find_client(addr, 4); 331 /*
173 if (clp == NULL) 332 * XXX When client trunking is implemented, this becomes
174 return NULL; 333 * a session lookup from within the loop
175 334 */
176 do { 335 session = clp->cl_session;
177 struct nfs_client *prev = clp; 336 tbl = &session->fc_slot_table;
178 337
179 if (clp->cl_session != NULL) { 338 for (i = 0; i < nrclists; i++) {
180 if (memcmp(clp->cl_session->sess_id.data, 339 rclist = &rclists[i];
181 sessionid->data, 340 if (memcmp(session->sess_id.data,
182 NFS4_MAX_SESSIONID_LEN) == 0) { 341 rclist->rcl_sessionid.data,
183 /* Returns a held reference to clp */ 342 NFS4_MAX_SESSIONID_LEN) != 0)
184 return clp; 343 continue;
185 } 344
345 for (j = 0; j < rclist->rcl_nrefcalls; j++) {
346 ref = &rclist->rcl_refcalls[j];
347
348 dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u "
349 "slotid %u\n", __func__,
350 ((u32 *)&rclist->rcl_sessionid.data)[0],
351 ((u32 *)&rclist->rcl_sessionid.data)[1],
352 ((u32 *)&rclist->rcl_sessionid.data)[2],
353 ((u32 *)&rclist->rcl_sessionid.data)[3],
354 ref->rc_sequenceid, ref->rc_slotid);
355
356 spin_lock(&tbl->slot_tbl_lock);
357 status = (test_bit(ref->rc_slotid, tbl->used_slots) &&
358 tbl->slots[ref->rc_slotid].seq_nr ==
359 ref->rc_sequenceid);
360 spin_unlock(&tbl->slot_tbl_lock);
361 if (status)
362 goto out;
186 } 363 }
187 clp = nfs_find_client_next(prev); 364 }
188 nfs_put_client(prev);
189 } while (clp != NULL);
190 365
191 return NULL; 366out:
367 return status;
192} 368}
193 369
194/* FIXME: referring calls should be processed */ 370__be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
195unsigned nfs4_callback_sequence(struct cb_sequenceargs *args, 371 struct cb_sequenceres *res,
196 struct cb_sequenceres *res) 372 struct cb_process_state *cps)
197{ 373{
198 struct nfs_client *clp; 374 struct nfs_client *clp;
199 int i, status; 375 int i;
376 __be32 status;
200 377
201 for (i = 0; i < args->csa_nrclists; i++) 378 cps->clp = NULL;
202 kfree(args->csa_rclists[i].rcl_refcalls);
203 kfree(args->csa_rclists);
204 379
205 status = htonl(NFS4ERR_BADSESSION); 380 status = htonl(NFS4ERR_BADSESSION);
206 clp = find_client_with_session(args->csa_addr, 4, &args->csa_sessionid); 381 /* Incoming session must match the callback session */
382 if (memcmp(&args->csa_sessionid, cps->svc_sid, NFS4_MAX_SESSIONID_LEN))
383 goto out;
384
385 clp = nfs4_find_client_sessionid(args->csa_addr,
386 &args->csa_sessionid, 1);
207 if (clp == NULL) 387 if (clp == NULL)
208 goto out; 388 goto out;
209 389
210 status = validate_seqid(&clp->cl_session->bc_slot_table, 390 /* state manager is resetting the session */
211 args->csa_slotid, args->csa_sequenceid); 391 if (test_bit(NFS4_SESSION_DRAINING, &clp->cl_session->session_state)) {
392 status = NFS4ERR_DELAY;
393 goto out;
394 }
395
396 status = validate_seqid(&clp->cl_session->bc_slot_table, args);
212 if (status) 397 if (status)
213 goto out_putclient; 398 goto out;
399
400 /*
401 * Check for pending referring calls. If a match is found, a
402 * related callback was received before the response to the original
403 * call.
404 */
405 if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) {
406 status = htonl(NFS4ERR_DELAY);
407 goto out;
408 }
214 409
215 memcpy(&res->csr_sessionid, &args->csa_sessionid, 410 memcpy(&res->csr_sessionid, &args->csa_sessionid,
216 sizeof(res->csr_sessionid)); 411 sizeof(res->csr_sessionid));
@@ -218,13 +413,95 @@ unsigned nfs4_callback_sequence(struct cb_sequenceargs *args,
218 res->csr_slotid = args->csa_slotid; 413 res->csr_slotid = args->csa_slotid;
219 res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; 414 res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
220 res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; 415 res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
416 nfs4_cb_take_slot(clp);
417 cps->clp = clp; /* put in nfs4_callback_compound */
418
419out:
420 for (i = 0; i < args->csa_nrclists; i++)
421 kfree(args->csa_rclists[i].rcl_refcalls);
422 kfree(args->csa_rclists);
423
424 if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) {
425 cps->drc_status = status;
426 status = 0;
427 } else
428 res->csr_status = status;
429
430 dprintk("%s: exit with status = %d res->csr_status %d\n", __func__,
431 ntohl(status), ntohl(res->csr_status));
432 return status;
433}
434
435static bool
436validate_bitmap_values(unsigned long mask)
437{
438 return (mask & ~RCA4_TYPE_MASK_ALL) == 0;
439}
440
441__be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy,
442 struct cb_process_state *cps)
443{
444 __be32 status;
445 fmode_t flags = 0;
446
447 status = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
448 if (!cps->clp) /* set in cb_sequence */
449 goto out;
450
451 dprintk("NFS: RECALL_ANY callback request from %s\n",
452 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
453
454 status = cpu_to_be32(NFS4ERR_INVAL);
455 if (!validate_bitmap_values(args->craa_type_mask))
456 goto out;
221 457
222out_putclient: 458 status = cpu_to_be32(NFS4_OK);
223 nfs_put_client(clp); 459 if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *)
460 &args->craa_type_mask))
461 flags = FMODE_READ;
462 if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *)
463 &args->craa_type_mask))
464 flags |= FMODE_WRITE;
465 if (test_bit(RCA4_TYPE_MASK_FILE_LAYOUT, (const unsigned long *)
466 &args->craa_type_mask))
467 pnfs_recall_all_layouts(cps->clp);
468 if (flags)
469 nfs_expire_all_delegation_types(cps->clp, flags);
224out: 470out:
225 dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); 471 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
226 res->csr_status = status; 472 return status;
227 return res->csr_status;
228} 473}
229 474
475/* Reduce the fore channel's max_slots to the target value */
476__be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy,
477 struct cb_process_state *cps)
478{
479 struct nfs4_slot_table *fc_tbl;
480 __be32 status;
481
482 status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
483 if (!cps->clp) /* set in cb_sequence */
484 goto out;
485
486 dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
487 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
488 args->crsa_target_max_slots);
489
490 fc_tbl = &cps->clp->cl_session->fc_slot_table;
491
492 status = htonl(NFS4ERR_BAD_HIGH_SLOT);
493 if (args->crsa_target_max_slots > fc_tbl->max_slots ||
494 args->crsa_target_max_slots < 1)
495 goto out;
496
497 status = htonl(NFS4_OK);
498 if (args->crsa_target_max_slots == fc_tbl->max_slots)
499 goto out;
500
501 fc_tbl->target_max_slots = args->crsa_target_max_slots;
502 nfs41_handle_recall_slot(cps->clp);
503out:
504 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
505 return status;
506}
230#endif /* CONFIG_NFS_V4_1 */ 507#endif /* CONFIG_NFS_V4_1 */
diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
index e5a2dac5f715..23112c263f81 100644
--- a/fs/nfs/callback_xdr.c
+++ b/fs/nfs/callback_xdr.c
@@ -9,8 +9,11 @@
9#include <linux/sunrpc/svc.h> 9#include <linux/sunrpc/svc.h>
10#include <linux/nfs4.h> 10#include <linux/nfs4.h>
11#include <linux/nfs_fs.h> 11#include <linux/nfs_fs.h>
12#include <linux/slab.h>
13#include <linux/sunrpc/bc_xprt.h>
12#include "nfs4_fs.h" 14#include "nfs4_fs.h"
13#include "callback.h" 15#include "callback.h"
16#include "internal.h"
14 17
15#define CB_OP_TAGLEN_MAXSZ (512) 18#define CB_OP_TAGLEN_MAXSZ (512)
16#define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ) 19#define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ)
@@ -21,13 +24,20 @@
21#define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 24#define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
22 25
23#if defined(CONFIG_NFS_V4_1) 26#if defined(CONFIG_NFS_V4_1)
27#define CB_OP_LAYOUTRECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
24#define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ 28#define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \
25 4 + 1 + 3) 29 4 + 1 + 3)
30#define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
31#define CB_OP_RECALLSLOT_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
26#endif /* CONFIG_NFS_V4_1 */ 32#endif /* CONFIG_NFS_V4_1 */
27 33
28#define NFSDBG_FACILITY NFSDBG_CALLBACK 34#define NFSDBG_FACILITY NFSDBG_CALLBACK
29 35
30typedef __be32 (*callback_process_op_t)(void *, void *); 36/* Internal error code */
37#define NFS4ERR_RESOURCE_HDR 11050
38
39typedef __be32 (*callback_process_op_t)(void *, void *,
40 struct cb_process_state *);
31typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *); 41typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *);
32typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *); 42typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *);
33 43
@@ -154,7 +164,7 @@ static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound
154 hdr->minorversion = ntohl(*p++); 164 hdr->minorversion = ntohl(*p++);
155 /* Check minor version is zero or one. */ 165 /* Check minor version is zero or one. */
156 if (hdr->minorversion <= 1) { 166 if (hdr->minorversion <= 1) {
157 p++; /* skip callback_ident */ 167 hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */
158 } else { 168 } else {
159 printk(KERN_WARNING "%s: NFSv4 server callback with " 169 printk(KERN_WARNING "%s: NFSv4 server callback with "
160 "illegal minor version %u!\n", 170 "illegal minor version %u!\n",
@@ -172,7 +182,7 @@ static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
172 __be32 *p; 182 __be32 *p;
173 p = read_buf(xdr, 4); 183 p = read_buf(xdr, 4);
174 if (unlikely(p == NULL)) 184 if (unlikely(p == NULL))
175 return htonl(NFS4ERR_RESOURCE); 185 return htonl(NFS4ERR_RESOURCE_HDR);
176 *op = ntohl(*p); 186 *op = ntohl(*p);
177 return 0; 187 return 0;
178} 188}
@@ -214,26 +224,86 @@ out:
214 224
215#if defined(CONFIG_NFS_V4_1) 225#if defined(CONFIG_NFS_V4_1)
216 226
217static unsigned decode_sessionid(struct xdr_stream *xdr, 227static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp,
228 struct xdr_stream *xdr,
229 struct cb_layoutrecallargs *args)
230{
231 __be32 *p;
232 __be32 status = 0;
233 uint32_t iomode;
234
235 args->cbl_addr = svc_addr(rqstp);
236 p = read_buf(xdr, 4 * sizeof(uint32_t));
237 if (unlikely(p == NULL)) {
238 status = htonl(NFS4ERR_BADXDR);
239 goto out;
240 }
241
242 args->cbl_layout_type = ntohl(*p++);
243 /* Depite the spec's xdr, iomode really belongs in the FILE switch,
244 * as it is unuseable and ignored with the other types.
245 */
246 iomode = ntohl(*p++);
247 args->cbl_layoutchanged = ntohl(*p++);
248 args->cbl_recall_type = ntohl(*p++);
249
250 if (args->cbl_recall_type == RETURN_FILE) {
251 args->cbl_range.iomode = iomode;
252 status = decode_fh(xdr, &args->cbl_fh);
253 if (unlikely(status != 0))
254 goto out;
255
256 p = read_buf(xdr, 2 * sizeof(uint64_t));
257 if (unlikely(p == NULL)) {
258 status = htonl(NFS4ERR_BADXDR);
259 goto out;
260 }
261 p = xdr_decode_hyper(p, &args->cbl_range.offset);
262 p = xdr_decode_hyper(p, &args->cbl_range.length);
263 status = decode_stateid(xdr, &args->cbl_stateid);
264 if (unlikely(status != 0))
265 goto out;
266 } else if (args->cbl_recall_type == RETURN_FSID) {
267 p = read_buf(xdr, 2 * sizeof(uint64_t));
268 if (unlikely(p == NULL)) {
269 status = htonl(NFS4ERR_BADXDR);
270 goto out;
271 }
272 p = xdr_decode_hyper(p, &args->cbl_fsid.major);
273 p = xdr_decode_hyper(p, &args->cbl_fsid.minor);
274 } else if (args->cbl_recall_type != RETURN_ALL) {
275 status = htonl(NFS4ERR_BADXDR);
276 goto out;
277 }
278 dprintk("%s: ltype 0x%x iomode %d changed %d recall_type %d\n",
279 __func__,
280 args->cbl_layout_type, iomode,
281 args->cbl_layoutchanged, args->cbl_recall_type);
282out:
283 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
284 return status;
285}
286
287static __be32 decode_sessionid(struct xdr_stream *xdr,
218 struct nfs4_sessionid *sid) 288 struct nfs4_sessionid *sid)
219{ 289{
220 uint32_t *p; 290 __be32 *p;
221 int len = NFS4_MAX_SESSIONID_LEN; 291 int len = NFS4_MAX_SESSIONID_LEN;
222 292
223 p = read_buf(xdr, len); 293 p = read_buf(xdr, len);
224 if (unlikely(p == NULL)) 294 if (unlikely(p == NULL))
225 return htonl(NFS4ERR_RESOURCE);; 295 return htonl(NFS4ERR_RESOURCE);
226 296
227 memcpy(sid->data, p, len); 297 memcpy(sid->data, p, len);
228 return 0; 298 return 0;
229} 299}
230 300
231static unsigned decode_rc_list(struct xdr_stream *xdr, 301static __be32 decode_rc_list(struct xdr_stream *xdr,
232 struct referring_call_list *rc_list) 302 struct referring_call_list *rc_list)
233{ 303{
234 uint32_t *p; 304 __be32 *p;
235 int i; 305 int i;
236 unsigned status; 306 __be32 status;
237 307
238 status = decode_sessionid(xdr, &rc_list->rcl_sessionid); 308 status = decode_sessionid(xdr, &rc_list->rcl_sessionid);
239 if (status) 309 if (status)
@@ -266,13 +336,13 @@ out:
266 return status; 336 return status;
267} 337}
268 338
269static unsigned decode_cb_sequence_args(struct svc_rqst *rqstp, 339static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp,
270 struct xdr_stream *xdr, 340 struct xdr_stream *xdr,
271 struct cb_sequenceargs *args) 341 struct cb_sequenceargs *args)
272{ 342{
273 uint32_t *p; 343 __be32 *p;
274 int i; 344 int i;
275 unsigned status; 345 __be32 status;
276 346
277 status = decode_sessionid(xdr, &args->csa_sessionid); 347 status = decode_sessionid(xdr, &args->csa_sessionid);
278 if (status) 348 if (status)
@@ -326,6 +396,39 @@ out_free:
326 goto out; 396 goto out;
327} 397}
328 398
399static __be32 decode_recallany_args(struct svc_rqst *rqstp,
400 struct xdr_stream *xdr,
401 struct cb_recallanyargs *args)
402{
403 __be32 *p;
404
405 args->craa_addr = svc_addr(rqstp);
406 p = read_buf(xdr, 4);
407 if (unlikely(p == NULL))
408 return htonl(NFS4ERR_BADXDR);
409 args->craa_objs_to_keep = ntohl(*p++);
410 p = read_buf(xdr, 4);
411 if (unlikely(p == NULL))
412 return htonl(NFS4ERR_BADXDR);
413 args->craa_type_mask = ntohl(*p);
414
415 return 0;
416}
417
418static __be32 decode_recallslot_args(struct svc_rqst *rqstp,
419 struct xdr_stream *xdr,
420 struct cb_recallslotargs *args)
421{
422 __be32 *p;
423
424 args->crsa_addr = svc_addr(rqstp);
425 p = read_buf(xdr, 4);
426 if (unlikely(p == NULL))
427 return htonl(NFS4ERR_BADXDR);
428 args->crsa_target_max_slots = ntohl(*p++);
429 return 0;
430}
431
329#endif /* CONFIG_NFS_V4_1 */ 432#endif /* CONFIG_NFS_V4_1 */
330 433
331static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 434static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
@@ -445,7 +548,7 @@ static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res)
445 548
446 p = xdr_reserve_space(xdr, 8); 549 p = xdr_reserve_space(xdr, 8);
447 if (unlikely(p == NULL)) 550 if (unlikely(p == NULL))
448 return htonl(NFS4ERR_RESOURCE); 551 return htonl(NFS4ERR_RESOURCE_HDR);
449 *p++ = htonl(op); 552 *p++ = htonl(op);
450 *p = res; 553 *p = res;
451 return 0; 554 return 0;
@@ -479,10 +582,10 @@ out:
479 582
480#if defined(CONFIG_NFS_V4_1) 583#if defined(CONFIG_NFS_V4_1)
481 584
482static unsigned encode_sessionid(struct xdr_stream *xdr, 585static __be32 encode_sessionid(struct xdr_stream *xdr,
483 const struct nfs4_sessionid *sid) 586 const struct nfs4_sessionid *sid)
484{ 587{
485 uint32_t *p; 588 __be32 *p;
486 int len = NFS4_MAX_SESSIONID_LEN; 589 int len = NFS4_MAX_SESSIONID_LEN;
487 590
488 p = xdr_reserve_space(xdr, len); 591 p = xdr_reserve_space(xdr, len);
@@ -493,11 +596,11 @@ static unsigned encode_sessionid(struct xdr_stream *xdr,
493 return 0; 596 return 0;
494} 597}
495 598
496static unsigned encode_cb_sequence_res(struct svc_rqst *rqstp, 599static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp,
497 struct xdr_stream *xdr, 600 struct xdr_stream *xdr,
498 const struct cb_sequenceres *res) 601 const struct cb_sequenceres *res)
499{ 602{
500 uint32_t *p; 603 __be32 *p;
501 unsigned status = res->csr_status; 604 unsigned status = res->csr_status;
502 605
503 if (unlikely(status != 0)) 606 if (unlikely(status != 0))
@@ -533,16 +636,16 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
533 case OP_CB_GETATTR: 636 case OP_CB_GETATTR:
534 case OP_CB_RECALL: 637 case OP_CB_RECALL:
535 case OP_CB_SEQUENCE: 638 case OP_CB_SEQUENCE:
639 case OP_CB_RECALL_ANY:
640 case OP_CB_RECALL_SLOT:
641 case OP_CB_LAYOUTRECALL:
536 *op = &callback_ops[op_nr]; 642 *op = &callback_ops[op_nr];
537 break; 643 break;
538 644
539 case OP_CB_LAYOUTRECALL:
540 case OP_CB_NOTIFY_DEVICEID: 645 case OP_CB_NOTIFY_DEVICEID:
541 case OP_CB_NOTIFY: 646 case OP_CB_NOTIFY:
542 case OP_CB_PUSH_DELEG: 647 case OP_CB_PUSH_DELEG:
543 case OP_CB_RECALL_ANY:
544 case OP_CB_RECALLABLE_OBJ_AVAIL: 648 case OP_CB_RECALLABLE_OBJ_AVAIL:
545 case OP_CB_RECALL_SLOT:
546 case OP_CB_WANTS_CANCELLED: 649 case OP_CB_WANTS_CANCELLED:
547 case OP_CB_NOTIFY_LOCK: 650 case OP_CB_NOTIFY_LOCK:
548 return htonl(NFS4ERR_NOTSUPP); 651 return htonl(NFS4ERR_NOTSUPP);
@@ -554,6 +657,37 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
554 return htonl(NFS_OK); 657 return htonl(NFS_OK);
555} 658}
556 659
660static void nfs4_callback_free_slot(struct nfs4_session *session)
661{
662 struct nfs4_slot_table *tbl = &session->bc_slot_table;
663
664 spin_lock(&tbl->slot_tbl_lock);
665 /*
666 * Let the state manager know callback processing done.
667 * A single slot, so highest used slotid is either 0 or -1
668 */
669 tbl->highest_used_slotid--;
670 nfs4_check_drain_bc_complete(session);
671 spin_unlock(&tbl->slot_tbl_lock);
672}
673
674static void nfs4_cb_free_slot(struct nfs_client *clp)
675{
676 if (clp && clp->cl_session)
677 nfs4_callback_free_slot(clp->cl_session);
678}
679
680/* A single slot, so highest used slotid is either 0 or -1 */
681void nfs4_cb_take_slot(struct nfs_client *clp)
682{
683 struct nfs4_slot_table *tbl = &clp->cl_session->bc_slot_table;
684
685 spin_lock(&tbl->slot_tbl_lock);
686 tbl->highest_used_slotid++;
687 BUG_ON(tbl->highest_used_slotid != 0);
688 spin_unlock(&tbl->slot_tbl_lock);
689}
690
557#else /* CONFIG_NFS_V4_1 */ 691#else /* CONFIG_NFS_V4_1 */
558 692
559static __be32 693static __be32
@@ -562,6 +696,9 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
562 return htonl(NFS4ERR_MINOR_VERS_MISMATCH); 696 return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
563} 697}
564 698
699static void nfs4_cb_free_slot(struct nfs_client *clp)
700{
701}
565#endif /* CONFIG_NFS_V4_1 */ 702#endif /* CONFIG_NFS_V4_1 */
566 703
567static __be32 704static __be32
@@ -582,20 +719,19 @@ preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op)
582static __be32 process_op(uint32_t minorversion, int nop, 719static __be32 process_op(uint32_t minorversion, int nop,
583 struct svc_rqst *rqstp, 720 struct svc_rqst *rqstp,
584 struct xdr_stream *xdr_in, void *argp, 721 struct xdr_stream *xdr_in, void *argp,
585 struct xdr_stream *xdr_out, void *resp) 722 struct xdr_stream *xdr_out, void *resp,
723 struct cb_process_state *cps)
586{ 724{
587 struct callback_op *op = &callback_ops[0]; 725 struct callback_op *op = &callback_ops[0];
588 unsigned int op_nr = OP_CB_ILLEGAL; 726 unsigned int op_nr;
589 __be32 status; 727 __be32 status;
590 long maxlen; 728 long maxlen;
591 __be32 res; 729 __be32 res;
592 730
593 dprintk("%s: start\n", __func__); 731 dprintk("%s: start\n", __func__);
594 status = decode_op_hdr(xdr_in, &op_nr); 732 status = decode_op_hdr(xdr_in, &op_nr);
595 if (unlikely(status)) { 733 if (unlikely(status))
596 status = htonl(NFS4ERR_OP_ILLEGAL); 734 return status;
597 goto out;
598 }
599 735
600 dprintk("%s: minorversion=%d nop=%d op_nr=%u\n", 736 dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
601 __func__, minorversion, nop, op_nr); 737 __func__, minorversion, nop, op_nr);
@@ -604,19 +740,26 @@ static __be32 process_op(uint32_t minorversion, int nop,
604 preprocess_nfs4_op(op_nr, &op); 740 preprocess_nfs4_op(op_nr, &op);
605 if (status == htonl(NFS4ERR_OP_ILLEGAL)) 741 if (status == htonl(NFS4ERR_OP_ILLEGAL))
606 op_nr = OP_CB_ILLEGAL; 742 op_nr = OP_CB_ILLEGAL;
607out: 743 if (status)
744 goto encode_hdr;
745
746 if (cps->drc_status) {
747 status = cps->drc_status;
748 goto encode_hdr;
749 }
750
608 maxlen = xdr_out->end - xdr_out->p; 751 maxlen = xdr_out->end - xdr_out->p;
609 if (maxlen > 0 && maxlen < PAGE_SIZE) { 752 if (maxlen > 0 && maxlen < PAGE_SIZE) {
610 if (likely(status == 0 && op->decode_args != NULL)) 753 status = op->decode_args(rqstp, xdr_in, argp);
611 status = op->decode_args(rqstp, xdr_in, argp); 754 if (likely(status == 0))
612 if (likely(status == 0 && op->process_op != NULL)) 755 status = op->process_op(argp, resp, cps);
613 status = op->process_op(argp, resp);
614 } else 756 } else
615 status = htonl(NFS4ERR_RESOURCE); 757 status = htonl(NFS4ERR_RESOURCE);
616 758
759encode_hdr:
617 res = encode_op_hdr(xdr_out, op_nr, status); 760 res = encode_op_hdr(xdr_out, op_nr, status);
618 if (status == 0) 761 if (unlikely(res))
619 status = res; 762 return res;
620 if (op->encode_res != NULL && status == 0) 763 if (op->encode_res != NULL && status == 0)
621 status = op->encode_res(rqstp, xdr_out, resp); 764 status = op->encode_res(rqstp, xdr_out, resp);
622 dprintk("%s: done, status = %d\n", __func__, ntohl(status)); 765 dprintk("%s: done, status = %d\n", __func__, ntohl(status));
@@ -631,8 +774,11 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
631 struct cb_compound_hdr_arg hdr_arg = { 0 }; 774 struct cb_compound_hdr_arg hdr_arg = { 0 };
632 struct cb_compound_hdr_res hdr_res = { NULL }; 775 struct cb_compound_hdr_res hdr_res = { NULL };
633 struct xdr_stream xdr_in, xdr_out; 776 struct xdr_stream xdr_in, xdr_out;
634 __be32 *p; 777 __be32 *p, status;
635 __be32 status; 778 struct cb_process_state cps = {
779 .drc_status = 0,
780 .clp = NULL,
781 };
636 unsigned int nops = 0; 782 unsigned int nops = 0;
637 783
638 dprintk("%s: start\n", __func__); 784 dprintk("%s: start\n", __func__);
@@ -646,19 +792,35 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
646 if (status == __constant_htonl(NFS4ERR_RESOURCE)) 792 if (status == __constant_htonl(NFS4ERR_RESOURCE))
647 return rpc_garbage_args; 793 return rpc_garbage_args;
648 794
795 if (hdr_arg.minorversion == 0) {
796 cps.clp = nfs4_find_client_ident(hdr_arg.cb_ident);
797 if (!cps.clp)
798 return rpc_drop_reply;
799 } else
800 cps.svc_sid = bc_xprt_sid(rqstp);
801
649 hdr_res.taglen = hdr_arg.taglen; 802 hdr_res.taglen = hdr_arg.taglen;
650 hdr_res.tag = hdr_arg.tag; 803 hdr_res.tag = hdr_arg.tag;
651 if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) 804 if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0)
652 return rpc_system_err; 805 return rpc_system_err;
653 806
654 while (status == 0 && nops != hdr_arg.nops) { 807 while (status == 0 && nops != hdr_arg.nops) {
655 status = process_op(hdr_arg.minorversion, nops, 808 status = process_op(hdr_arg.minorversion, nops, rqstp,
656 rqstp, &xdr_in, argp, &xdr_out, resp); 809 &xdr_in, argp, &xdr_out, resp, &cps);
657 nops++; 810 nops++;
658 } 811 }
659 812
813 /* Buffer overflow in decode_ops_hdr or encode_ops_hdr. Return
814 * resource error in cb_compound status without returning op */
815 if (unlikely(status == htonl(NFS4ERR_RESOURCE_HDR))) {
816 status = htonl(NFS4ERR_RESOURCE);
817 nops--;
818 }
819
660 *hdr_res.status = status; 820 *hdr_res.status = status;
661 *hdr_res.nops = htonl(nops); 821 *hdr_res.nops = htonl(nops);
822 nfs4_cb_free_slot(cps.clp);
823 nfs_put_client(cps.clp);
662 dprintk("%s: done, status = %u\n", __func__, ntohl(status)); 824 dprintk("%s: done, status = %u\n", __func__, ntohl(status));
663 return rpc_success; 825 return rpc_success;
664} 826}
@@ -682,12 +844,28 @@ static struct callback_op callback_ops[] = {
682 .res_maxsize = CB_OP_RECALL_RES_MAXSZ, 844 .res_maxsize = CB_OP_RECALL_RES_MAXSZ,
683 }, 845 },
684#if defined(CONFIG_NFS_V4_1) 846#if defined(CONFIG_NFS_V4_1)
847 [OP_CB_LAYOUTRECALL] = {
848 .process_op = (callback_process_op_t)nfs4_callback_layoutrecall,
849 .decode_args =
850 (callback_decode_arg_t)decode_layoutrecall_args,
851 .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ,
852 },
685 [OP_CB_SEQUENCE] = { 853 [OP_CB_SEQUENCE] = {
686 .process_op = (callback_process_op_t)nfs4_callback_sequence, 854 .process_op = (callback_process_op_t)nfs4_callback_sequence,
687 .decode_args = (callback_decode_arg_t)decode_cb_sequence_args, 855 .decode_args = (callback_decode_arg_t)decode_cb_sequence_args,
688 .encode_res = (callback_encode_res_t)encode_cb_sequence_res, 856 .encode_res = (callback_encode_res_t)encode_cb_sequence_res,
689 .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ, 857 .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ,
690 }, 858 },
859 [OP_CB_RECALL_ANY] = {
860 .process_op = (callback_process_op_t)nfs4_callback_recallany,
861 .decode_args = (callback_decode_arg_t)decode_recallany_args,
862 .res_maxsize = CB_OP_RECALLANY_RES_MAXSZ,
863 },
864 [OP_CB_RECALL_SLOT] = {
865 .process_op = (callback_process_op_t)nfs4_callback_recallslot,
866 .decode_args = (callback_decode_arg_t)decode_recallslot_args,
867 .res_maxsize = CB_OP_RECALLSLOT_RES_MAXSZ,
868 },
691#endif /* CONFIG_NFS_V4_1 */ 869#endif /* CONFIG_NFS_V4_1 */
692}; 870};
693 871
@@ -716,5 +894,13 @@ struct svc_version nfs4_callback_version1 = {
716 .vs_proc = nfs4_callback_procedures1, 894 .vs_proc = nfs4_callback_procedures1,
717 .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, 895 .vs_xdrsize = NFS4_CALLBACK_XDRSIZE,
718 .vs_dispatch = NULL, 896 .vs_dispatch = NULL,
897 .vs_hidden = 1,
719}; 898};
720 899
900struct svc_version nfs4_callback_version4 = {
901 .vs_vers = 4,
902 .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1),
903 .vs_proc = nfs4_callback_procedures1,
904 .vs_xdrsize = NFS4_CALLBACK_XDRSIZE,
905 .vs_dispatch = NULL,
906};
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index c2d061675d80..192f2f860265 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -35,6 +35,7 @@
35#include <linux/vfs.h> 35#include <linux/vfs.h>
36#include <linux/inet.h> 36#include <linux/inet.h>
37#include <linux/in6.h> 37#include <linux/in6.h>
38#include <linux/slab.h>
38#include <net/ipv6.h> 39#include <net/ipv6.h>
39#include <linux/nfs_xdr.h> 40#include <linux/nfs_xdr.h>
40#include <linux/sunrpc/bc_xprt.h> 41#include <linux/sunrpc/bc_xprt.h>
@@ -47,6 +48,7 @@
47#include "iostat.h" 48#include "iostat.h"
48#include "internal.h" 49#include "internal.h"
49#include "fscache.h" 50#include "fscache.h"
51#include "pnfs.h"
50 52
51#define NFSDBG_FACILITY NFSDBG_CLIENT 53#define NFSDBG_FACILITY NFSDBG_CLIENT
52 54
@@ -54,6 +56,30 @@ static DEFINE_SPINLOCK(nfs_client_lock);
54static LIST_HEAD(nfs_client_list); 56static LIST_HEAD(nfs_client_list);
55static LIST_HEAD(nfs_volume_list); 57static LIST_HEAD(nfs_volume_list);
56static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); 58static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
59#ifdef CONFIG_NFS_V4
60static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
61
62/*
63 * Get a unique NFSv4.0 callback identifier which will be used
64 * by the V4.0 callback service to lookup the nfs_client struct
65 */
66static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
67{
68 int ret = 0;
69
70 if (clp->rpc_ops->version != 4 || minorversion != 0)
71 return ret;
72retry:
73 if (!idr_pre_get(&cb_ident_idr, GFP_KERNEL))
74 return -ENOMEM;
75 spin_lock(&nfs_client_lock);
76 ret = idr_get_new(&cb_ident_idr, clp, &clp->cl_cb_ident);
77 spin_unlock(&nfs_client_lock);
78 if (ret == -EAGAIN)
79 goto retry;
80 return ret;
81}
82#endif /* CONFIG_NFS_V4 */
57 83
58/* 84/*
59 * RPC cruft for NFS 85 * RPC cruft for NFS
@@ -142,18 +168,24 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
142 clp->cl_proto = cl_init->proto; 168 clp->cl_proto = cl_init->proto;
143 169
144#ifdef CONFIG_NFS_V4 170#ifdef CONFIG_NFS_V4
145 INIT_LIST_HEAD(&clp->cl_delegations); 171 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
172 if (err)
173 goto error_cleanup;
174
146 spin_lock_init(&clp->cl_lock); 175 spin_lock_init(&clp->cl_lock);
147 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); 176 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
148 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); 177 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
149 clp->cl_boot_time = CURRENT_TIME; 178 clp->cl_boot_time = CURRENT_TIME;
150 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; 179 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
151 clp->cl_minorversion = cl_init->minorversion; 180 clp->cl_minorversion = cl_init->minorversion;
181 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
152#endif 182#endif
153 cred = rpc_lookup_machine_cred(); 183 cred = rpc_lookup_machine_cred();
154 if (!IS_ERR(cred)) 184 if (!IS_ERR(cred))
155 clp->cl_machine_cred = cred; 185 clp->cl_machine_cred = cred;
156 186#if defined(CONFIG_NFS_V4_1)
187 INIT_LIST_HEAD(&clp->cl_layouts);
188#endif
157 nfs_fscache_get_client_cookie(clp); 189 nfs_fscache_get_client_cookie(clp);
158 190
159 return clp; 191 return clp;
@@ -164,48 +196,77 @@ error_0:
164 return ERR_PTR(err); 196 return ERR_PTR(err);
165} 197}
166 198
199#ifdef CONFIG_NFS_V4
200#ifdef CONFIG_NFS_V4_1
201static void nfs4_shutdown_session(struct nfs_client *clp)
202{
203 if (nfs4_has_session(clp))
204 nfs4_destroy_session(clp->cl_session);
205}
206#else /* CONFIG_NFS_V4_1 */
207static void nfs4_shutdown_session(struct nfs_client *clp)
208{
209}
210#endif /* CONFIG_NFS_V4_1 */
211
212/*
213 * Destroy the NFS4 callback service
214 */
215static void nfs4_destroy_callback(struct nfs_client *clp)
216{
217 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
218 nfs_callback_down(clp->cl_mvops->minor_version);
219}
220
167static void nfs4_shutdown_client(struct nfs_client *clp) 221static void nfs4_shutdown_client(struct nfs_client *clp)
168{ 222{
169#ifdef CONFIG_NFS_V4
170 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) 223 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
171 nfs4_kill_renewd(clp); 224 nfs4_kill_renewd(clp);
172 BUG_ON(!RB_EMPTY_ROOT(&clp->cl_state_owners)); 225 nfs4_shutdown_session(clp);
226 nfs4_destroy_callback(clp);
173 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) 227 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
174 nfs_idmap_delete(clp); 228 nfs_idmap_delete(clp);
175 229
176 rpc_destroy_wait_queue(&clp->cl_rpcwaitq); 230 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
177#endif
178} 231}
179 232
180/* 233/* idr_remove_all is not needed as all id's are removed by nfs_put_client */
181 * Destroy the NFS4 callback service 234void nfs_cleanup_cb_ident_idr(void)
182 */
183static void nfs4_destroy_callback(struct nfs_client *clp)
184{ 235{
185#ifdef CONFIG_NFS_V4 236 idr_destroy(&cb_ident_idr);
186 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
187 nfs_callback_down(clp->cl_minorversion);
188#endif /* CONFIG_NFS_V4 */
189} 237}
190 238
191/* 239/* nfs_client_lock held */
192 * Clears/puts all minor version specific parts from an nfs_client struct 240static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
193 * reverting it to minorversion 0.
194 */
195static void nfs4_clear_client_minor_version(struct nfs_client *clp)
196{ 241{
197#ifdef CONFIG_NFS_V4_1 242 if (clp->cl_cb_ident)
198 if (nfs4_has_session(clp)) { 243 idr_remove(&cb_ident_idr, clp->cl_cb_ident);
199 nfs4_destroy_session(clp->cl_session); 244}
200 clp->cl_session = NULL;
201 }
202 245
203 clp->cl_call_sync = _nfs4_call_sync; 246static void pnfs_init_server(struct nfs_server *server)
204#endif /* CONFIG_NFS_V4_1 */ 247{
248 rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC");
249}
205 250
206 nfs4_destroy_callback(clp); 251#else
252static void nfs4_shutdown_client(struct nfs_client *clp)
253{
207} 254}
208 255
256void nfs_cleanup_cb_ident_idr(void)
257{
258}
259
260static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
261{
262}
263
264static void pnfs_init_server(struct nfs_server *server)
265{
266}
267
268#endif /* CONFIG_NFS_V4 */
269
209/* 270/*
210 * Destroy a shared client record 271 * Destroy a shared client record
211 */ 272 */
@@ -213,7 +274,6 @@ static void nfs_free_client(struct nfs_client *clp)
213{ 274{
214 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version); 275 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
215 276
216 nfs4_clear_client_minor_version(clp);
217 nfs4_shutdown_client(clp); 277 nfs4_shutdown_client(clp);
218 278
219 nfs_fscache_release_client_cookie(clp); 279 nfs_fscache_release_client_cookie(clp);
@@ -243,6 +303,7 @@ void nfs_put_client(struct nfs_client *clp)
243 303
244 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { 304 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
245 list_del(&clp->cl_share_link); 305 list_del(&clp->cl_share_link);
306 nfs_cb_idr_remove_locked(clp);
246 spin_unlock(&nfs_client_lock); 307 spin_unlock(&nfs_client_lock);
247 308
248 BUG_ON(!list_empty(&clp->cl_superblocks)); 309 BUG_ON(!list_empty(&clp->cl_superblocks));
@@ -250,6 +311,7 @@ void nfs_put_client(struct nfs_client *clp)
250 nfs_free_client(clp); 311 nfs_free_client(clp);
251 } 312 }
252} 313}
314EXPORT_SYMBOL_GPL(nfs_put_client);
253 315
254#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 316#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
255/* 317/*
@@ -273,7 +335,7 @@ static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
273 sin1->sin6_scope_id != sin2->sin6_scope_id) 335 sin1->sin6_scope_id != sin2->sin6_scope_id)
274 return 0; 336 return 0;
275 337
276 return ipv6_addr_equal(&sin1->sin6_addr, &sin1->sin6_addr); 338 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
277} 339}
278#else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */ 340#else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
279static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, 341static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
@@ -357,70 +419,28 @@ static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
357 return 0; 419 return 0;
358} 420}
359 421
360/* 422/* Common match routine for v4.0 and v4.1 callback services */
361 * Find a client by IP address and protocol version 423bool
362 * - returns NULL if no such client 424nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp,
363 */ 425 u32 minorversion)
364struct nfs_client *nfs_find_client(const struct sockaddr *addr, u32 nfsversion)
365{
366 struct nfs_client *clp;
367
368 spin_lock(&nfs_client_lock);
369 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
370 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
371
372 /* Don't match clients that failed to initialise properly */
373 if (!(clp->cl_cons_state == NFS_CS_READY ||
374 clp->cl_cons_state == NFS_CS_SESSION_INITING))
375 continue;
376
377 /* Different NFS versions cannot share the same nfs_client */
378 if (clp->rpc_ops->version != nfsversion)
379 continue;
380
381 /* Match only the IP address, not the port number */
382 if (!nfs_sockaddr_match_ipaddr(addr, clap))
383 continue;
384
385 atomic_inc(&clp->cl_count);
386 spin_unlock(&nfs_client_lock);
387 return clp;
388 }
389 spin_unlock(&nfs_client_lock);
390 return NULL;
391}
392
393/*
394 * Find a client by IP address and protocol version
395 * - returns NULL if no such client
396 */
397struct nfs_client *nfs_find_client_next(struct nfs_client *clp)
398{ 426{
399 struct sockaddr *sap = (struct sockaddr *)&clp->cl_addr; 427 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
400 u32 nfsvers = clp->rpc_ops->version;
401
402 spin_lock(&nfs_client_lock);
403 list_for_each_entry_continue(clp, &nfs_client_list, cl_share_link) {
404 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
405 428
406 /* Don't match clients that failed to initialise properly */ 429 /* Don't match clients that failed to initialise */
407 if (clp->cl_cons_state != NFS_CS_READY) 430 if (!(clp->cl_cons_state == NFS_CS_READY ||
408 continue; 431 clp->cl_cons_state == NFS_CS_SESSION_INITING))
432 return false;
409 433
410 /* Different NFS versions cannot share the same nfs_client */ 434 /* Match the version and minorversion */
411 if (clp->rpc_ops->version != nfsvers) 435 if (clp->rpc_ops->version != 4 ||
412 continue; 436 clp->cl_minorversion != minorversion)
437 return false;
413 438
414 /* Match only the IP address, not the port number */ 439 /* Match only the IP address, not the port number */
415 if (!nfs_sockaddr_match_ipaddr(sap, clap)) 440 if (!nfs_sockaddr_match_ipaddr(addr, clap))
416 continue; 441 return false;
417 442
418 atomic_inc(&clp->cl_count); 443 return true;
419 spin_unlock(&nfs_client_lock);
420 return clp;
421 }
422 spin_unlock(&nfs_client_lock);
423 return NULL;
424} 444}
425 445
426/* 446/*
@@ -599,6 +619,7 @@ static int nfs_create_rpc_client(struct nfs_client *clp,
599{ 619{
600 struct rpc_clnt *clnt = NULL; 620 struct rpc_clnt *clnt = NULL;
601 struct rpc_create_args args = { 621 struct rpc_create_args args = {
622 .net = &init_net,
602 .protocol = clp->cl_proto, 623 .protocol = clp->cl_proto,
603 .address = (struct sockaddr *)&clp->cl_addr, 624 .address = (struct sockaddr *)&clp->cl_addr,
604 .addrsize = clp->cl_addrlen, 625 .addrsize = clp->cl_addrlen,
@@ -633,7 +654,8 @@ static int nfs_create_rpc_client(struct nfs_client *clp,
633 */ 654 */
634static void nfs_destroy_server(struct nfs_server *server) 655static void nfs_destroy_server(struct nfs_server *server)
635{ 656{
636 if (!(server->flags & NFS_MOUNT_NONLM)) 657 if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) ||
658 !(server->flags & NFS_MOUNT_LOCAL_FCNTL))
637 nlmclnt_done(server->nlm_host); 659 nlmclnt_done(server->nlm_host);
638} 660}
639 661
@@ -648,8 +670,6 @@ static int nfs_start_lockd(struct nfs_server *server)
648 .hostname = clp->cl_hostname, 670 .hostname = clp->cl_hostname,
649 .address = (struct sockaddr *)&clp->cl_addr, 671 .address = (struct sockaddr *)&clp->cl_addr,
650 .addrlen = clp->cl_addrlen, 672 .addrlen = clp->cl_addrlen,
651 .protocol = server->flags & NFS_MOUNT_TCP ?
652 IPPROTO_TCP : IPPROTO_UDP,
653 .nfs_version = clp->rpc_ops->version, 673 .nfs_version = clp->rpc_ops->version,
654 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? 674 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
655 1 : 0, 675 1 : 0,
@@ -657,9 +677,18 @@ static int nfs_start_lockd(struct nfs_server *server)
657 677
658 if (nlm_init.nfs_version > 3) 678 if (nlm_init.nfs_version > 3)
659 return 0; 679 return 0;
660 if (server->flags & NFS_MOUNT_NONLM) 680 if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) &&
681 (server->flags & NFS_MOUNT_LOCAL_FCNTL))
661 return 0; 682 return 0;
662 683
684 switch (clp->cl_proto) {
685 default:
686 nlm_init.protocol = IPPROTO_TCP;
687 break;
688 case XPRT_TRANSPORT_UDP:
689 nlm_init.protocol = IPPROTO_UDP;
690 }
691
663 host = nlmclnt_init(&nlm_init); 692 host = nlmclnt_init(&nlm_init);
664 if (IS_ERR(host)) 693 if (IS_ERR(host))
665 return PTR_ERR(host); 694 return PTR_ERR(host);
@@ -787,7 +816,7 @@ static int nfs_init_server(struct nfs_server *server,
787 dprintk("--> nfs_init_server()\n"); 816 dprintk("--> nfs_init_server()\n");
788 817
789#ifdef CONFIG_NFS_V3 818#ifdef CONFIG_NFS_V3
790 if (data->flags & NFS_MOUNT_VER3) 819 if (data->version == 3)
791 cl_init.rpc_ops = &nfs_v3_clientops; 820 cl_init.rpc_ops = &nfs_v3_clientops;
792#endif 821#endif
793 822
@@ -809,6 +838,9 @@ static int nfs_init_server(struct nfs_server *server,
809 /* Initialise the client representation from the mount data */ 838 /* Initialise the client representation from the mount data */
810 server->flags = data->flags; 839 server->flags = data->flags;
811 server->options = data->options; 840 server->options = data->options;
841 server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
842 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP|
843 NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME;
812 844
813 if (data->rsize) 845 if (data->rsize)
814 server->rsize = nfs_block_size(data->rsize, NULL); 846 server->rsize = nfs_block_size(data->rsize, NULL);
@@ -879,6 +911,7 @@ static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *
879 server->rsize = NFS_MAX_FILE_IO_SIZE; 911 server->rsize = NFS_MAX_FILE_IO_SIZE;
880 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 912 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
881 913
914 server->backing_dev_info.name = "nfs";
882 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; 915 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
883 916
884 if (server->wsize > max_rpc_payload) 917 if (server->wsize > max_rpc_payload)
@@ -886,11 +919,13 @@ static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *
886 if (server->wsize > NFS_MAX_FILE_IO_SIZE) 919 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
887 server->wsize = NFS_MAX_FILE_IO_SIZE; 920 server->wsize = NFS_MAX_FILE_IO_SIZE;
888 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 921 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
922 set_pnfs_layoutdriver(server, fsinfo->layouttype);
923
889 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); 924 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
890 925
891 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); 926 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
892 if (server->dtsize > PAGE_CACHE_SIZE) 927 if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES)
893 server->dtsize = PAGE_CACHE_SIZE; 928 server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES;
894 if (server->dtsize > server->rsize) 929 if (server->dtsize > server->rsize)
895 server->dtsize = server->rsize; 930 server->dtsize = server->rsize;
896 931
@@ -901,6 +936,8 @@ static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *
901 936
902 server->maxfilesize = fsinfo->maxfilesize; 937 server->maxfilesize = fsinfo->maxfilesize;
903 938
939 server->time_delta = fsinfo->time_delta;
940
904 /* We're airborne Set socket buffersize */ 941 /* We're airborne Set socket buffersize */
905 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); 942 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
906} 943}
@@ -923,16 +960,12 @@ static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, str
923 } 960 }
924 961
925 fsinfo.fattr = fattr; 962 fsinfo.fattr = fattr;
926 nfs_fattr_init(fattr); 963 fsinfo.layouttype = 0;
927 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); 964 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
928 if (error < 0) 965 if (error < 0)
929 goto out_error; 966 goto out_error;
930 967
931 nfs_server_set_fsinfo(server, &fsinfo); 968 nfs_server_set_fsinfo(server, &fsinfo);
932 error = bdi_init(&server->backing_dev_info);
933 if (error)
934 goto out_error;
935
936 969
937 /* Get some general file system info */ 970 /* Get some general file system info */
938 if (server->namelen == 0) { 971 if (server->namelen == 0) {
@@ -959,11 +992,35 @@ out_error:
959static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) 992static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
960{ 993{
961 target->flags = source->flags; 994 target->flags = source->flags;
995 target->rsize = source->rsize;
996 target->wsize = source->wsize;
962 target->acregmin = source->acregmin; 997 target->acregmin = source->acregmin;
963 target->acregmax = source->acregmax; 998 target->acregmax = source->acregmax;
964 target->acdirmin = source->acdirmin; 999 target->acdirmin = source->acdirmin;
965 target->acdirmax = source->acdirmax; 1000 target->acdirmax = source->acdirmax;
966 target->caps = source->caps; 1001 target->caps = source->caps;
1002 target->options = source->options;
1003}
1004
1005static void nfs_server_insert_lists(struct nfs_server *server)
1006{
1007 struct nfs_client *clp = server->nfs_client;
1008
1009 spin_lock(&nfs_client_lock);
1010 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
1011 list_add_tail(&server->master_link, &nfs_volume_list);
1012 spin_unlock(&nfs_client_lock);
1013
1014}
1015
1016static void nfs_server_remove_lists(struct nfs_server *server)
1017{
1018 spin_lock(&nfs_client_lock);
1019 list_del_rcu(&server->client_link);
1020 list_del(&server->master_link);
1021 spin_unlock(&nfs_client_lock);
1022
1023 synchronize_rcu();
967} 1024}
968 1025
969/* 1026/*
@@ -982,6 +1039,7 @@ static struct nfs_server *nfs_alloc_server(void)
982 /* Zero out the NFS state stuff */ 1039 /* Zero out the NFS state stuff */
983 INIT_LIST_HEAD(&server->client_link); 1040 INIT_LIST_HEAD(&server->client_link);
984 INIT_LIST_HEAD(&server->master_link); 1041 INIT_LIST_HEAD(&server->master_link);
1042 INIT_LIST_HEAD(&server->delegations);
985 1043
986 atomic_set(&server->active, 0); 1044 atomic_set(&server->active, 0);
987 1045
@@ -991,6 +1049,14 @@ static struct nfs_server *nfs_alloc_server(void)
991 return NULL; 1049 return NULL;
992 } 1050 }
993 1051
1052 if (bdi_init(&server->backing_dev_info)) {
1053 nfs_free_iostats(server->io_stats);
1054 kfree(server);
1055 return NULL;
1056 }
1057
1058 pnfs_init_server(server);
1059
994 return server; 1060 return server;
995} 1061}
996 1062
@@ -1001,10 +1067,8 @@ void nfs_free_server(struct nfs_server *server)
1001{ 1067{
1002 dprintk("--> nfs_free_server()\n"); 1068 dprintk("--> nfs_free_server()\n");
1003 1069
1004 spin_lock(&nfs_client_lock); 1070 nfs_server_remove_lists(server);
1005 list_del(&server->client_link); 1071 unset_pnfs_layoutdriver(server);
1006 list_del(&server->master_link);
1007 spin_unlock(&nfs_client_lock);
1008 1072
1009 if (server->destroy != NULL) 1073 if (server->destroy != NULL)
1010 server->destroy(server); 1074 server->destroy(server);
@@ -1031,13 +1095,18 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
1031 struct nfs_fh *mntfh) 1095 struct nfs_fh *mntfh)
1032{ 1096{
1033 struct nfs_server *server; 1097 struct nfs_server *server;
1034 struct nfs_fattr fattr; 1098 struct nfs_fattr *fattr;
1035 int error; 1099 int error;
1036 1100
1037 server = nfs_alloc_server(); 1101 server = nfs_alloc_server();
1038 if (!server) 1102 if (!server)
1039 return ERR_PTR(-ENOMEM); 1103 return ERR_PTR(-ENOMEM);
1040 1104
1105 error = -ENOMEM;
1106 fattr = nfs_alloc_fattr();
1107 if (fattr == NULL)
1108 goto error;
1109
1041 /* Get a client representation */ 1110 /* Get a client representation */
1042 error = nfs_init_server(server, data); 1111 error = nfs_init_server(server, data);
1043 if (error < 0) 1112 if (error < 0)
@@ -1048,7 +1117,7 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
1048 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); 1117 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1049 1118
1050 /* Probe the root fh to retrieve its FSID */ 1119 /* Probe the root fh to retrieve its FSID */
1051 error = nfs_probe_fsinfo(server, mntfh, &fattr); 1120 error = nfs_probe_fsinfo(server, mntfh, fattr);
1052 if (error < 0) 1121 if (error < 0)
1053 goto error; 1122 goto error;
1054 if (server->nfs_client->rpc_ops->version == 3) { 1123 if (server->nfs_client->rpc_ops->version == 3) {
@@ -1061,38 +1130,127 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
1061 server->namelen = NFS2_MAXNAMLEN; 1130 server->namelen = NFS2_MAXNAMLEN;
1062 } 1131 }
1063 1132
1064 if (!(fattr.valid & NFS_ATTR_FATTR)) { 1133 if (!(fattr->valid & NFS_ATTR_FATTR)) {
1065 error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr); 1134 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
1066 if (error < 0) { 1135 if (error < 0) {
1067 dprintk("nfs_create_server: getattr error = %d\n", -error); 1136 dprintk("nfs_create_server: getattr error = %d\n", -error);
1068 goto error; 1137 goto error;
1069 } 1138 }
1070 } 1139 }
1071 memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid)); 1140 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
1072 1141
1073 dprintk("Server FSID: %llx:%llx\n", 1142 dprintk("Server FSID: %llx:%llx\n",
1074 (unsigned long long) server->fsid.major, 1143 (unsigned long long) server->fsid.major,
1075 (unsigned long long) server->fsid.minor); 1144 (unsigned long long) server->fsid.minor);
1076 1145
1077 BUG_ON(!server->nfs_client); 1146 nfs_server_insert_lists(server);
1078 BUG_ON(!server->nfs_client->rpc_ops);
1079 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1080
1081 spin_lock(&nfs_client_lock);
1082 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1083 list_add_tail(&server->master_link, &nfs_volume_list);
1084 spin_unlock(&nfs_client_lock);
1085
1086 server->mount_time = jiffies; 1147 server->mount_time = jiffies;
1148 nfs_free_fattr(fattr);
1087 return server; 1149 return server;
1088 1150
1089error: 1151error:
1152 nfs_free_fattr(fattr);
1090 nfs_free_server(server); 1153 nfs_free_server(server);
1091 return ERR_PTR(error); 1154 return ERR_PTR(error);
1092} 1155}
1093 1156
1094#ifdef CONFIG_NFS_V4 1157#ifdef CONFIG_NFS_V4
1095/* 1158/*
1159 * NFSv4.0 callback thread helper
1160 *
1161 * Find a client by IP address, protocol version, and minorversion
1162 *
1163 * Called from the pg_authenticate method. The callback identifier
1164 * is not used as it has not been decoded.
1165 *
1166 * Returns NULL if no such client
1167 */
1168struct nfs_client *
1169nfs4_find_client_no_ident(const struct sockaddr *addr)
1170{
1171 struct nfs_client *clp;
1172
1173 spin_lock(&nfs_client_lock);
1174 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1175 if (nfs4_cb_match_client(addr, clp, 0) == false)
1176 continue;
1177 atomic_inc(&clp->cl_count);
1178 spin_unlock(&nfs_client_lock);
1179 return clp;
1180 }
1181 spin_unlock(&nfs_client_lock);
1182 return NULL;
1183}
1184
1185/*
1186 * NFSv4.0 callback thread helper
1187 *
1188 * Find a client by callback identifier
1189 */
1190struct nfs_client *
1191nfs4_find_client_ident(int cb_ident)
1192{
1193 struct nfs_client *clp;
1194
1195 spin_lock(&nfs_client_lock);
1196 clp = idr_find(&cb_ident_idr, cb_ident);
1197 if (clp)
1198 atomic_inc(&clp->cl_count);
1199 spin_unlock(&nfs_client_lock);
1200 return clp;
1201}
1202
1203#if defined(CONFIG_NFS_V4_1)
1204/*
1205 * NFSv4.1 callback thread helper
1206 * For CB_COMPOUND calls, find a client by IP address, protocol version,
1207 * minorversion, and sessionID
1208 *
1209 * CREATE_SESSION triggers a CB_NULL ping from servers. The callback service
1210 * sessionid can only be set after the CREATE_SESSION return, so a CB_NULL
1211 * can arrive before the callback sessionid is set. For CB_NULL calls,
1212 * find a client by IP address protocol version, and minorversion.
1213 *
1214 * Returns NULL if no such client
1215 */
1216struct nfs_client *
1217nfs4_find_client_sessionid(const struct sockaddr *addr,
1218 struct nfs4_sessionid *sid, int is_cb_compound)
1219{
1220 struct nfs_client *clp;
1221
1222 spin_lock(&nfs_client_lock);
1223 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1224 if (nfs4_cb_match_client(addr, clp, 1) == false)
1225 continue;
1226
1227 if (!nfs4_has_session(clp))
1228 continue;
1229
1230 /* Match sessionid unless cb_null call*/
1231 if (is_cb_compound && (memcmp(clp->cl_session->sess_id.data,
1232 sid->data, NFS4_MAX_SESSIONID_LEN) != 0))
1233 continue;
1234
1235 atomic_inc(&clp->cl_count);
1236 spin_unlock(&nfs_client_lock);
1237 return clp;
1238 }
1239 spin_unlock(&nfs_client_lock);
1240 return NULL;
1241}
1242
1243#else /* CONFIG_NFS_V4_1 */
1244
1245struct nfs_client *
1246nfs4_find_client_sessionid(const struct sockaddr *addr,
1247 struct nfs4_sessionid *sid, int is_cb_compound)
1248{
1249 return NULL;
1250}
1251#endif /* CONFIG_NFS_V4_1 */
1252
1253/*
1096 * Initialize the NFS4 callback service 1254 * Initialize the NFS4 callback service
1097 */ 1255 */
1098static int nfs4_init_callback(struct nfs_client *clp) 1256static int nfs4_init_callback(struct nfs_client *clp)
@@ -1108,7 +1266,7 @@ static int nfs4_init_callback(struct nfs_client *clp)
1108 return error; 1266 return error;
1109 } 1267 }
1110 1268
1111 error = nfs_callback_up(clp->cl_minorversion, 1269 error = nfs_callback_up(clp->cl_mvops->minor_version,
1112 clp->cl_rpcclient->cl_xprt); 1270 clp->cl_rpcclient->cl_xprt);
1113 if (error < 0) { 1271 if (error < 0) {
1114 dprintk("%s: failed to start callback. Error = %d\n", 1272 dprintk("%s: failed to start callback. Error = %d\n",
@@ -1125,10 +1283,8 @@ static int nfs4_init_callback(struct nfs_client *clp)
1125 */ 1283 */
1126static int nfs4_init_client_minor_version(struct nfs_client *clp) 1284static int nfs4_init_client_minor_version(struct nfs_client *clp)
1127{ 1285{
1128 clp->cl_call_sync = _nfs4_call_sync;
1129
1130#if defined(CONFIG_NFS_V4_1) 1286#if defined(CONFIG_NFS_V4_1)
1131 if (clp->cl_minorversion) { 1287 if (clp->cl_mvops->minor_version) {
1132 struct nfs4_session *session = NULL; 1288 struct nfs4_session *session = NULL;
1133 /* 1289 /*
1134 * Create the session and mark it expired. 1290 * Create the session and mark it expired.
@@ -1140,7 +1296,13 @@ static int nfs4_init_client_minor_version(struct nfs_client *clp)
1140 return -ENOMEM; 1296 return -ENOMEM;
1141 1297
1142 clp->cl_session = session; 1298 clp->cl_session = session;
1143 clp->cl_call_sync = _nfs4_call_sync_session; 1299 /*
1300 * The create session reply races with the server back
1301 * channel probe. Mark the client NFS_CS_SESSION_INITING
1302 * so that the client back channel can find the
1303 * nfs_client struct
1304 */
1305 clp->cl_cons_state = NFS_CS_SESSION_INITING;
1144 } 1306 }
1145#endif /* CONFIG_NFS_V4_1 */ 1307#endif /* CONFIG_NFS_V4_1 */
1146 1308
@@ -1171,7 +1333,7 @@ static int nfs4_init_client(struct nfs_client *clp,
1171 1, flags & NFS_MOUNT_NORESVPORT); 1333 1, flags & NFS_MOUNT_NORESVPORT);
1172 if (error < 0) 1334 if (error < 0)
1173 goto error; 1335 goto error;
1174 memcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); 1336 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
1175 1337
1176 error = nfs_idmap_new(clp); 1338 error = nfs_idmap_new(clp);
1177 if (error < 0) { 1339 if (error < 0) {
@@ -1242,20 +1404,6 @@ error:
1242 return error; 1404 return error;
1243} 1405}
1244 1406
1245/*
1246 * Initialize a session.
1247 * Note: save the mount rsize and wsize for create_server negotiation.
1248 */
1249static void nfs4_init_session(struct nfs_client *clp,
1250 unsigned int wsize, unsigned int rsize)
1251{
1252#if defined(CONFIG_NFS_V4_1)
1253 if (nfs4_has_session(clp)) {
1254 clp->cl_session->fc_attrs.max_rqst_sz = wsize;
1255 clp->cl_session->fc_attrs.max_resp_sz = rsize;
1256 }
1257#endif /* CONFIG_NFS_V4_1 */
1258}
1259 1407
1260/* 1408/*
1261 * Session has been established, and the client marked ready. 1409 * Session has been established, and the client marked ready.
@@ -1265,13 +1413,68 @@ static void nfs4_init_session(struct nfs_client *clp,
1265static void nfs4_session_set_rwsize(struct nfs_server *server) 1413static void nfs4_session_set_rwsize(struct nfs_server *server)
1266{ 1414{
1267#ifdef CONFIG_NFS_V4_1 1415#ifdef CONFIG_NFS_V4_1
1416 struct nfs4_session *sess;
1417 u32 server_resp_sz;
1418 u32 server_rqst_sz;
1419
1268 if (!nfs4_has_session(server->nfs_client)) 1420 if (!nfs4_has_session(server->nfs_client))
1269 return; 1421 return;
1270 server->rsize = server->nfs_client->cl_session->fc_attrs.max_resp_sz; 1422 sess = server->nfs_client->cl_session;
1271 server->wsize = server->nfs_client->cl_session->fc_attrs.max_rqst_sz; 1423 server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
1424 server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
1425
1426 if (server->rsize > server_resp_sz)
1427 server->rsize = server_resp_sz;
1428 if (server->wsize > server_rqst_sz)
1429 server->wsize = server_rqst_sz;
1272#endif /* CONFIG_NFS_V4_1 */ 1430#endif /* CONFIG_NFS_V4_1 */
1273} 1431}
1274 1432
1433static int nfs4_server_common_setup(struct nfs_server *server,
1434 struct nfs_fh *mntfh)
1435{
1436 struct nfs_fattr *fattr;
1437 int error;
1438
1439 BUG_ON(!server->nfs_client);
1440 BUG_ON(!server->nfs_client->rpc_ops);
1441 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1442
1443 fattr = nfs_alloc_fattr();
1444 if (fattr == NULL)
1445 return -ENOMEM;
1446
1447 /* We must ensure the session is initialised first */
1448 error = nfs4_init_session(server);
1449 if (error < 0)
1450 goto out;
1451
1452 /* Probe the root fh to retrieve its FSID and filehandle */
1453 error = nfs4_get_rootfh(server, mntfh);
1454 if (error < 0)
1455 goto out;
1456
1457 dprintk("Server FSID: %llx:%llx\n",
1458 (unsigned long long) server->fsid.major,
1459 (unsigned long long) server->fsid.minor);
1460 dprintk("Mount FH: %d\n", mntfh->size);
1461
1462 nfs4_session_set_rwsize(server);
1463
1464 error = nfs_probe_fsinfo(server, mntfh, fattr);
1465 if (error < 0)
1466 goto out;
1467
1468 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1469 server->namelen = NFS4_MAXNAMLEN;
1470
1471 nfs_server_insert_lists(server);
1472 server->mount_time = jiffies;
1473out:
1474 nfs_free_fattr(fattr);
1475 return error;
1476}
1477
1275/* 1478/*
1276 * Create a version 4 volume record 1479 * Create a version 4 volume record
1277 */ 1480 */
@@ -1288,7 +1491,9 @@ static int nfs4_init_server(struct nfs_server *server,
1288 1491
1289 /* Initialise the client representation from the mount data */ 1492 /* Initialise the client representation from the mount data */
1290 server->flags = data->flags; 1493 server->flags = data->flags;
1291 server->caps |= NFS_CAP_ATOMIC_OPEN; 1494 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK;
1495 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1496 server->caps |= NFS_CAP_READDIRPLUS;
1292 server->options = data->options; 1497 server->options = data->options;
1293 1498
1294 /* Get a client record */ 1499 /* Get a client record */
@@ -1331,7 +1536,6 @@ error:
1331struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, 1536struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
1332 struct nfs_fh *mntfh) 1537 struct nfs_fh *mntfh)
1333{ 1538{
1334 struct nfs_fattr fattr;
1335 struct nfs_server *server; 1539 struct nfs_server *server;
1336 int error; 1540 int error;
1337 1541
@@ -1346,41 +1550,10 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
1346 if (error < 0) 1550 if (error < 0)
1347 goto error; 1551 goto error;
1348 1552
1349 BUG_ON(!server->nfs_client); 1553 error = nfs4_server_common_setup(server, mntfh);
1350 BUG_ON(!server->nfs_client->rpc_ops);
1351 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1352
1353 nfs4_init_session(server->nfs_client, server->wsize, server->rsize);
1354
1355 /* Probe the root fh to retrieve its FSID */
1356 error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path);
1357 if (error < 0) 1554 if (error < 0)
1358 goto error; 1555 goto error;
1359 1556
1360 dprintk("Server FSID: %llx:%llx\n",
1361 (unsigned long long) server->fsid.major,
1362 (unsigned long long) server->fsid.minor);
1363 dprintk("Mount FH: %d\n", mntfh->size);
1364
1365 nfs4_session_set_rwsize(server);
1366
1367 error = nfs_probe_fsinfo(server, mntfh, &fattr);
1368 if (error < 0)
1369 goto error;
1370
1371 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1372 server->namelen = NFS4_MAXNAMLEN;
1373
1374 BUG_ON(!server->nfs_client);
1375 BUG_ON(!server->nfs_client->rpc_ops);
1376 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1377
1378 spin_lock(&nfs_client_lock);
1379 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1380 list_add_tail(&server->master_link, &nfs_volume_list);
1381 spin_unlock(&nfs_client_lock);
1382
1383 server->mount_time = jiffies;
1384 dprintk("<-- nfs4_create_server() = %p\n", server); 1557 dprintk("<-- nfs4_create_server() = %p\n", server);
1385 return server; 1558 return server;
1386 1559
@@ -1398,7 +1571,6 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1398{ 1571{
1399 struct nfs_client *parent_client; 1572 struct nfs_client *parent_client;
1400 struct nfs_server *server, *parent_server; 1573 struct nfs_server *server, *parent_server;
1401 struct nfs_fattr fattr;
1402 int error; 1574 int error;
1403 1575
1404 dprintk("--> nfs4_create_referral_server()\n"); 1576 dprintk("--> nfs4_create_referral_server()\n");
@@ -1412,7 +1584,7 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1412 1584
1413 /* Initialise the client representation from the parent server */ 1585 /* Initialise the client representation from the parent server */
1414 nfs_server_copy_userdata(server, parent_server); 1586 nfs_server_copy_userdata(server, parent_server);
1415 server->caps |= NFS_CAP_ATOMIC_OPEN; 1587 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR;
1416 1588
1417 /* Get a client representation. 1589 /* Get a client representation.
1418 * Note: NFSv4 always uses TCP, */ 1590 * Note: NFSv4 always uses TCP, */
@@ -1423,7 +1595,7 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1423 data->authflavor, 1595 data->authflavor,
1424 parent_server->client->cl_xprt->prot, 1596 parent_server->client->cl_xprt->prot,
1425 parent_server->client->cl_timeout, 1597 parent_server->client->cl_timeout,
1426 parent_client->cl_minorversion); 1598 parent_client->cl_mvops->minor_version);
1427 if (error < 0) 1599 if (error < 0)
1428 goto error; 1600 goto error;
1429 1601
@@ -1431,34 +1603,10 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1431 if (error < 0) 1603 if (error < 0)
1432 goto error; 1604 goto error;
1433 1605
1434 BUG_ON(!server->nfs_client); 1606 error = nfs4_server_common_setup(server, mntfh);
1435 BUG_ON(!server->nfs_client->rpc_ops);
1436 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1437
1438 /* Probe the root fh to retrieve its FSID and filehandle */
1439 error = nfs4_path_walk(server, mntfh, data->mnt_path);
1440 if (error < 0)
1441 goto error;
1442
1443 /* probe the filesystem info for this server filesystem */
1444 error = nfs_probe_fsinfo(server, mntfh, &fattr);
1445 if (error < 0) 1607 if (error < 0)
1446 goto error; 1608 goto error;
1447 1609
1448 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1449 server->namelen = NFS4_MAXNAMLEN;
1450
1451 dprintk("Referral FSID: %llx:%llx\n",
1452 (unsigned long long) server->fsid.major,
1453 (unsigned long long) server->fsid.minor);
1454
1455 spin_lock(&nfs_client_lock);
1456 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1457 list_add_tail(&server->master_link, &nfs_volume_list);
1458 spin_unlock(&nfs_client_lock);
1459
1460 server->mount_time = jiffies;
1461
1462 dprintk("<-- nfs_create_referral_server() = %p\n", server); 1610 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1463 return server; 1611 return server;
1464 1612
@@ -1478,7 +1626,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
1478 struct nfs_fattr *fattr) 1626 struct nfs_fattr *fattr)
1479{ 1627{
1480 struct nfs_server *server; 1628 struct nfs_server *server;
1481 struct nfs_fattr fattr_fsinfo; 1629 struct nfs_fattr *fattr_fsinfo;
1482 int error; 1630 int error;
1483 1631
1484 dprintk("--> nfs_clone_server(,%llx:%llx,)\n", 1632 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
@@ -1489,6 +1637,11 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
1489 if (!server) 1637 if (!server)
1490 return ERR_PTR(-ENOMEM); 1638 return ERR_PTR(-ENOMEM);
1491 1639
1640 error = -ENOMEM;
1641 fattr_fsinfo = nfs_alloc_fattr();
1642 if (fattr_fsinfo == NULL)
1643 goto out_free_server;
1644
1492 /* Copy data from the source */ 1645 /* Copy data from the source */
1493 server->nfs_client = source->nfs_client; 1646 server->nfs_client = source->nfs_client;
1494 atomic_inc(&server->nfs_client->cl_count); 1647 atomic_inc(&server->nfs_client->cl_count);
@@ -1505,7 +1658,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
1505 nfs_init_server_aclclient(server); 1658 nfs_init_server_aclclient(server);
1506 1659
1507 /* probe the filesystem info for this server filesystem */ 1660 /* probe the filesystem info for this server filesystem */
1508 error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo); 1661 error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
1509 if (error < 0) 1662 if (error < 0)
1510 goto out_free_server; 1663 goto out_free_server;
1511 1664
@@ -1520,17 +1673,15 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
1520 if (error < 0) 1673 if (error < 0)
1521 goto out_free_server; 1674 goto out_free_server;
1522 1675
1523 spin_lock(&nfs_client_lock); 1676 nfs_server_insert_lists(server);
1524 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1525 list_add_tail(&server->master_link, &nfs_volume_list);
1526 spin_unlock(&nfs_client_lock);
1527
1528 server->mount_time = jiffies; 1677 server->mount_time = jiffies;
1529 1678
1679 nfs_free_fattr(fattr_fsinfo);
1530 dprintk("<-- nfs_clone_server() = %p\n", server); 1680 dprintk("<-- nfs_clone_server() = %p\n", server);
1531 return server; 1681 return server;
1532 1682
1533out_free_server: 1683out_free_server:
1684 nfs_free_fattr(fattr_fsinfo);
1534 nfs_free_server(server); 1685 nfs_free_server(server);
1535 dprintk("<-- nfs_clone_server() = error %d\n", error); 1686 dprintk("<-- nfs_clone_server() = error %d\n", error);
1536 return ERR_PTR(error); 1687 return ERR_PTR(error);
@@ -1545,7 +1696,7 @@ static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1545static void nfs_server_list_stop(struct seq_file *p, void *v); 1696static void nfs_server_list_stop(struct seq_file *p, void *v);
1546static int nfs_server_list_show(struct seq_file *m, void *v); 1697static int nfs_server_list_show(struct seq_file *m, void *v);
1547 1698
1548static struct seq_operations nfs_server_list_ops = { 1699static const struct seq_operations nfs_server_list_ops = {
1549 .start = nfs_server_list_start, 1700 .start = nfs_server_list_start,
1550 .next = nfs_server_list_next, 1701 .next = nfs_server_list_next,
1551 .stop = nfs_server_list_stop, 1702 .stop = nfs_server_list_stop,
@@ -1566,7 +1717,7 @@ static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1566static void nfs_volume_list_stop(struct seq_file *p, void *v); 1717static void nfs_volume_list_stop(struct seq_file *p, void *v);
1567static int nfs_volume_list_show(struct seq_file *m, void *v); 1718static int nfs_volume_list_show(struct seq_file *m, void *v);
1568 1719
1569static struct seq_operations nfs_volume_list_ops = { 1720static const struct seq_operations nfs_volume_list_ops = {
1570 .start = nfs_volume_list_start, 1721 .start = nfs_volume_list_start,
1571 .next = nfs_volume_list_next, 1722 .next = nfs_volume_list_next,
1572 .stop = nfs_volume_list_stop, 1723 .stop = nfs_volume_list_stop,
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index af05b918cb5b..364e4328f392 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -10,6 +10,7 @@
10#include <linux/kthread.h> 10#include <linux/kthread.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/slab.h>
13#include <linux/spinlock.h> 14#include <linux/spinlock.h>
14 15
15#include <linux/nfs4.h> 16#include <linux/nfs4.h>
@@ -22,6 +23,8 @@
22 23
23static void nfs_do_free_delegation(struct nfs_delegation *delegation) 24static void nfs_do_free_delegation(struct nfs_delegation *delegation)
24{ 25{
26 if (delegation->cred)
27 put_rpccred(delegation->cred);
25 kfree(delegation); 28 kfree(delegation);
26} 29}
27 30
@@ -34,20 +37,26 @@ static void nfs_free_delegation_callback(struct rcu_head *head)
34 37
35static void nfs_free_delegation(struct nfs_delegation *delegation) 38static void nfs_free_delegation(struct nfs_delegation *delegation)
36{ 39{
37 struct rpc_cred *cred;
38
39 cred = rcu_dereference(delegation->cred);
40 rcu_assign_pointer(delegation->cred, NULL);
41 call_rcu(&delegation->rcu, nfs_free_delegation_callback); 40 call_rcu(&delegation->rcu, nfs_free_delegation_callback);
42 if (cred)
43 put_rpccred(cred);
44} 41}
45 42
43/**
44 * nfs_mark_delegation_referenced - set delegation's REFERENCED flag
45 * @delegation: delegation to process
46 *
47 */
46void nfs_mark_delegation_referenced(struct nfs_delegation *delegation) 48void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
47{ 49{
48 set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags); 50 set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags);
49} 51}
50 52
53/**
54 * nfs_have_delegation - check if inode has a delegation
55 * @inode: inode to check
56 * @flags: delegation types to check for
57 *
58 * Returns one if inode has the indicated delegation, otherwise zero.
59 */
51int nfs_have_delegation(struct inode *inode, fmode_t flags) 60int nfs_have_delegation(struct inode *inode, fmode_t flags)
52{ 61{
53 struct nfs_delegation *delegation; 62 struct nfs_delegation *delegation;
@@ -73,25 +82,25 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_
73 if (inode->i_flock == NULL) 82 if (inode->i_flock == NULL)
74 goto out; 83 goto out;
75 84
76 /* Protect inode->i_flock using the BKL */ 85 /* Protect inode->i_flock using the file locks lock */
77 lock_kernel(); 86 lock_flocks();
78 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 87 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
79 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) 88 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
80 continue; 89 continue;
81 if (nfs_file_open_context(fl->fl_file) != ctx) 90 if (nfs_file_open_context(fl->fl_file) != ctx)
82 continue; 91 continue;
83 unlock_kernel(); 92 unlock_flocks();
84 status = nfs4_lock_delegation_recall(state, fl); 93 status = nfs4_lock_delegation_recall(state, fl);
85 if (status < 0) 94 if (status < 0)
86 goto out; 95 goto out;
87 lock_kernel(); 96 lock_flocks();
88 } 97 }
89 unlock_kernel(); 98 unlock_flocks();
90out: 99out:
91 return status; 100 return status;
92} 101}
93 102
94static void nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid) 103static int nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid)
95{ 104{
96 struct nfs_inode *nfsi = NFS_I(inode); 105 struct nfs_inode *nfsi = NFS_I(inode);
97 struct nfs_open_context *ctx; 106 struct nfs_open_context *ctx;
@@ -115,32 +124,52 @@ again:
115 err = nfs_delegation_claim_locks(ctx, state); 124 err = nfs_delegation_claim_locks(ctx, state);
116 put_nfs_open_context(ctx); 125 put_nfs_open_context(ctx);
117 if (err != 0) 126 if (err != 0)
118 return; 127 return err;
119 goto again; 128 goto again;
120 } 129 }
121 spin_unlock(&inode->i_lock); 130 spin_unlock(&inode->i_lock);
131 return 0;
122} 132}
123 133
124/* 134/**
125 * Set up a delegation on an inode 135 * nfs_inode_reclaim_delegation - process a delegation reclaim request
136 * @inode: inode to process
137 * @cred: credential to use for request
138 * @res: new delegation state from server
139 *
126 */ 140 */
127void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) 141void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
142 struct nfs_openres *res)
128{ 143{
129 struct nfs_delegation *delegation = NFS_I(inode)->delegation; 144 struct nfs_delegation *delegation;
130 struct rpc_cred *oldcred; 145 struct rpc_cred *oldcred = NULL;
131 146
132 if (delegation == NULL) 147 rcu_read_lock();
133 return; 148 delegation = rcu_dereference(NFS_I(inode)->delegation);
134 memcpy(delegation->stateid.data, res->delegation.data, 149 if (delegation != NULL) {
135 sizeof(delegation->stateid.data)); 150 spin_lock(&delegation->lock);
136 delegation->type = res->delegation_type; 151 if (delegation->inode != NULL) {
137 delegation->maxsize = res->maxsize; 152 memcpy(delegation->stateid.data, res->delegation.data,
138 oldcred = delegation->cred; 153 sizeof(delegation->stateid.data));
139 delegation->cred = get_rpccred(cred); 154 delegation->type = res->delegation_type;
140 clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); 155 delegation->maxsize = res->maxsize;
141 NFS_I(inode)->delegation_state = delegation->type; 156 oldcred = delegation->cred;
142 smp_wmb(); 157 delegation->cred = get_rpccred(cred);
143 put_rpccred(oldcred); 158 clear_bit(NFS_DELEGATION_NEED_RECLAIM,
159 &delegation->flags);
160 NFS_I(inode)->delegation_state = delegation->type;
161 spin_unlock(&delegation->lock);
162 put_rpccred(oldcred);
163 rcu_read_unlock();
164 } else {
165 /* We appear to have raced with a delegation return. */
166 spin_unlock(&delegation->lock);
167 rcu_read_unlock();
168 nfs_inode_set_delegation(inode, cred, res);
169 }
170 } else {
171 rcu_read_unlock();
172 }
144} 173}
145 174
146static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync) 175static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
@@ -163,40 +192,58 @@ static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation
163 return inode; 192 return inode;
164} 193}
165 194
166static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, const nfs4_stateid *stateid) 195static struct nfs_delegation *
196nfs_detach_delegation_locked(struct nfs_inode *nfsi,
197 struct nfs_server *server)
167{ 198{
168 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation); 199 struct nfs_delegation *delegation =
200 rcu_dereference_protected(nfsi->delegation,
201 lockdep_is_held(&server->nfs_client->cl_lock));
169 202
170 if (delegation == NULL) 203 if (delegation == NULL)
171 goto nomatch; 204 goto nomatch;
205
172 spin_lock(&delegation->lock); 206 spin_lock(&delegation->lock);
173 if (stateid != NULL && memcmp(delegation->stateid.data, stateid->data,
174 sizeof(delegation->stateid.data)) != 0)
175 goto nomatch_unlock;
176 list_del_rcu(&delegation->super_list); 207 list_del_rcu(&delegation->super_list);
177 delegation->inode = NULL; 208 delegation->inode = NULL;
178 nfsi->delegation_state = 0; 209 nfsi->delegation_state = 0;
179 rcu_assign_pointer(nfsi->delegation, NULL); 210 rcu_assign_pointer(nfsi->delegation, NULL);
180 spin_unlock(&delegation->lock); 211 spin_unlock(&delegation->lock);
181 return delegation; 212 return delegation;
182nomatch_unlock:
183 spin_unlock(&delegation->lock);
184nomatch: 213nomatch:
185 return NULL; 214 return NULL;
186} 215}
187 216
188/* 217static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi,
189 * Set up a delegation on an inode 218 struct nfs_server *server)
219{
220 struct nfs_client *clp = server->nfs_client;
221 struct nfs_delegation *delegation;
222
223 spin_lock(&clp->cl_lock);
224 delegation = nfs_detach_delegation_locked(nfsi, server);
225 spin_unlock(&clp->cl_lock);
226 return delegation;
227}
228
229/**
230 * nfs_inode_set_delegation - set up a delegation on an inode
231 * @inode: inode to which delegation applies
232 * @cred: cred to use for subsequent delegation processing
233 * @res: new delegation state from server
234 *
235 * Returns zero on success, or a negative errno value.
190 */ 236 */
191int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) 237int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
192{ 238{
193 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 239 struct nfs_server *server = NFS_SERVER(inode);
240 struct nfs_client *clp = server->nfs_client;
194 struct nfs_inode *nfsi = NFS_I(inode); 241 struct nfs_inode *nfsi = NFS_I(inode);
195 struct nfs_delegation *delegation; 242 struct nfs_delegation *delegation, *old_delegation;
196 struct nfs_delegation *freeme = NULL; 243 struct nfs_delegation *freeme = NULL;
197 int status = 0; 244 int status = 0;
198 245
199 delegation = kmalloc(sizeof(*delegation), GFP_KERNEL); 246 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
200 if (delegation == NULL) 247 if (delegation == NULL)
201 return -ENOMEM; 248 return -ENOMEM;
202 memcpy(delegation->stateid.data, res->delegation.data, 249 memcpy(delegation->stateid.data, res->delegation.data,
@@ -210,10 +257,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
210 spin_lock_init(&delegation->lock); 257 spin_lock_init(&delegation->lock);
211 258
212 spin_lock(&clp->cl_lock); 259 spin_lock(&clp->cl_lock);
213 if (rcu_dereference(nfsi->delegation) != NULL) { 260 old_delegation = rcu_dereference_protected(nfsi->delegation,
214 if (memcmp(&delegation->stateid, &nfsi->delegation->stateid, 261 lockdep_is_held(&clp->cl_lock));
215 sizeof(delegation->stateid)) == 0 && 262 if (old_delegation != NULL) {
216 delegation->type == nfsi->delegation->type) { 263 if (memcmp(&delegation->stateid, &old_delegation->stateid,
264 sizeof(old_delegation->stateid)) == 0 &&
265 delegation->type == old_delegation->type) {
217 goto out; 266 goto out;
218 } 267 }
219 /* 268 /*
@@ -223,14 +272,14 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
223 dfprintk(FILE, "%s: server %s handed out " 272 dfprintk(FILE, "%s: server %s handed out "
224 "a duplicate delegation!\n", 273 "a duplicate delegation!\n",
225 __func__, clp->cl_hostname); 274 __func__, clp->cl_hostname);
226 if (delegation->type <= nfsi->delegation->type) { 275 if (delegation->type <= old_delegation->type) {
227 freeme = delegation; 276 freeme = delegation;
228 delegation = NULL; 277 delegation = NULL;
229 goto out; 278 goto out;
230 } 279 }
231 freeme = nfs_detach_delegation_locked(nfsi, NULL); 280 freeme = nfs_detach_delegation_locked(nfsi, server);
232 } 281 }
233 list_add_rcu(&delegation->super_list, &clp->cl_delegations); 282 list_add_rcu(&delegation->super_list, &server->delegations);
234 nfsi->delegation_state = delegation->type; 283 nfsi->delegation_state = delegation->type;
235 rcu_assign_pointer(nfsi->delegation, delegation); 284 rcu_assign_pointer(nfsi->delegation, delegation);
236 delegation = NULL; 285 delegation = NULL;
@@ -249,153 +298,211 @@ out:
249 return status; 298 return status;
250} 299}
251 300
252/* Sync all data to disk upon delegation return */
253static void nfs_msync_inode(struct inode *inode)
254{
255 filemap_fdatawrite(inode->i_mapping);
256 nfs_wb_all(inode);
257 filemap_fdatawait(inode->i_mapping);
258}
259
260/* 301/*
261 * Basic procedure for returning a delegation to the server 302 * Basic procedure for returning a delegation to the server
262 */ 303 */
263static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation) 304static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
264{ 305{
265 struct nfs_inode *nfsi = NFS_I(inode); 306 struct nfs_inode *nfsi = NFS_I(inode);
307 int err;
266 308
267 nfs_msync_inode(inode);
268 /* 309 /*
269 * Guard against new delegated open/lock/unlock calls and against 310 * Guard against new delegated open/lock/unlock calls and against
270 * state recovery 311 * state recovery
271 */ 312 */
272 down_write(&nfsi->rwsem); 313 down_write(&nfsi->rwsem);
273 nfs_delegation_claim_opens(inode, &delegation->stateid); 314 err = nfs_delegation_claim_opens(inode, &delegation->stateid);
274 up_write(&nfsi->rwsem); 315 up_write(&nfsi->rwsem);
275 nfs_msync_inode(inode); 316 if (err)
317 goto out;
276 318
277 return nfs_do_return_delegation(inode, delegation, 1); 319 err = nfs_do_return_delegation(inode, delegation, issync);
320out:
321 return err;
278} 322}
279 323
280/* 324/**
281 * Return all delegations that have been marked for return 325 * nfs_client_return_marked_delegations - return previously marked delegations
326 * @clp: nfs_client to process
327 *
328 * Returns zero on success, or a negative errno value.
282 */ 329 */
283void nfs_client_return_marked_delegations(struct nfs_client *clp) 330int nfs_client_return_marked_delegations(struct nfs_client *clp)
284{ 331{
285 struct nfs_delegation *delegation; 332 struct nfs_delegation *delegation;
333 struct nfs_server *server;
286 struct inode *inode; 334 struct inode *inode;
335 int err = 0;
287 336
288restart: 337restart:
289 rcu_read_lock(); 338 rcu_read_lock();
290 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { 339 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
291 if (!test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) 340 list_for_each_entry_rcu(delegation, &server->delegations,
292 continue; 341 super_list) {
293 inode = nfs_delegation_grab_inode(delegation); 342 if (!test_and_clear_bit(NFS_DELEGATION_RETURN,
294 if (inode == NULL) 343 &delegation->flags))
295 continue; 344 continue;
296 spin_lock(&clp->cl_lock); 345 inode = nfs_delegation_grab_inode(delegation);
297 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL); 346 if (inode == NULL)
298 spin_unlock(&clp->cl_lock); 347 continue;
299 rcu_read_unlock(); 348 delegation = nfs_detach_delegation(NFS_I(inode),
300 if (delegation != NULL) 349 server);
301 __nfs_inode_return_delegation(inode, delegation); 350 rcu_read_unlock();
302 iput(inode); 351
303 goto restart; 352 if (delegation != NULL) {
353 filemap_flush(inode->i_mapping);
354 err = __nfs_inode_return_delegation(inode,
355 delegation, 0);
356 }
357 iput(inode);
358 if (!err)
359 goto restart;
360 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
361 return err;
362 }
304 } 363 }
305 rcu_read_unlock(); 364 rcu_read_unlock();
365 return 0;
306} 366}
307 367
308/* 368/**
309 * This function returns the delegation without reclaiming opens 369 * nfs_inode_return_delegation_noreclaim - return delegation, don't reclaim opens
310 * or protecting against delegation reclaims. 370 * @inode: inode to process
311 * It is therefore really only safe to be called from 371 *
312 * nfs4_clear_inode() 372 * Does not protect against delegation reclaims, therefore really only safe
373 * to be called from nfs4_clear_inode().
313 */ 374 */
314void nfs_inode_return_delegation_noreclaim(struct inode *inode) 375void nfs_inode_return_delegation_noreclaim(struct inode *inode)
315{ 376{
316 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 377 struct nfs_server *server = NFS_SERVER(inode);
317 struct nfs_inode *nfsi = NFS_I(inode); 378 struct nfs_inode *nfsi = NFS_I(inode);
318 struct nfs_delegation *delegation; 379 struct nfs_delegation *delegation;
319 380
320 if (rcu_dereference(nfsi->delegation) != NULL) { 381 if (rcu_access_pointer(nfsi->delegation) != NULL) {
321 spin_lock(&clp->cl_lock); 382 delegation = nfs_detach_delegation(nfsi, server);
322 delegation = nfs_detach_delegation_locked(nfsi, NULL);
323 spin_unlock(&clp->cl_lock);
324 if (delegation != NULL) 383 if (delegation != NULL)
325 nfs_do_return_delegation(inode, delegation, 0); 384 nfs_do_return_delegation(inode, delegation, 0);
326 } 385 }
327} 386}
328 387
388/**
389 * nfs_inode_return_delegation - synchronously return a delegation
390 * @inode: inode to process
391 *
392 * Returns zero on success, or a negative errno value.
393 */
329int nfs_inode_return_delegation(struct inode *inode) 394int nfs_inode_return_delegation(struct inode *inode)
330{ 395{
331 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 396 struct nfs_server *server = NFS_SERVER(inode);
332 struct nfs_inode *nfsi = NFS_I(inode); 397 struct nfs_inode *nfsi = NFS_I(inode);
333 struct nfs_delegation *delegation; 398 struct nfs_delegation *delegation;
334 int err = 0; 399 int err = 0;
335 400
336 if (rcu_dereference(nfsi->delegation) != NULL) { 401 if (rcu_access_pointer(nfsi->delegation) != NULL) {
337 spin_lock(&clp->cl_lock); 402 delegation = nfs_detach_delegation(nfsi, server);
338 delegation = nfs_detach_delegation_locked(nfsi, NULL); 403 if (delegation != NULL) {
339 spin_unlock(&clp->cl_lock); 404 nfs_wb_all(inode);
340 if (delegation != NULL) 405 err = __nfs_inode_return_delegation(inode, delegation, 1);
341 err = __nfs_inode_return_delegation(inode, delegation); 406 }
342 } 407 }
343 return err; 408 return err;
344} 409}
345 410
346static void nfs_mark_return_delegation(struct nfs_client *clp, struct nfs_delegation *delegation) 411static void nfs_mark_return_delegation(struct nfs_delegation *delegation)
347{ 412{
413 struct nfs_client *clp = NFS_SERVER(delegation->inode)->nfs_client;
414
348 set_bit(NFS_DELEGATION_RETURN, &delegation->flags); 415 set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
349 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); 416 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
350} 417}
351 418
352/* 419/**
353 * Return all delegations associated to a super block 420 * nfs_super_return_all_delegations - return delegations for one superblock
421 * @sb: sb to process
422 *
354 */ 423 */
355void nfs_super_return_all_delegations(struct super_block *sb) 424void nfs_super_return_all_delegations(struct super_block *sb)
356{ 425{
357 struct nfs_client *clp = NFS_SB(sb)->nfs_client; 426 struct nfs_server *server = NFS_SB(sb);
427 struct nfs_client *clp = server->nfs_client;
358 struct nfs_delegation *delegation; 428 struct nfs_delegation *delegation;
359 429
360 if (clp == NULL) 430 if (clp == NULL)
361 return; 431 return;
432
362 rcu_read_lock(); 433 rcu_read_lock();
363 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { 434 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
364 spin_lock(&delegation->lock); 435 spin_lock(&delegation->lock);
365 if (delegation->inode != NULL && delegation->inode->i_sb == sb) 436 set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
366 set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
367 spin_unlock(&delegation->lock); 437 spin_unlock(&delegation->lock);
368 } 438 }
369 rcu_read_unlock(); 439 rcu_read_unlock();
370 nfs_client_return_marked_delegations(clp); 440
441 if (nfs_client_return_marked_delegations(clp) != 0)
442 nfs4_schedule_state_manager(clp);
371} 443}
372 444
373static void nfs_client_mark_return_all_delegations(struct nfs_client *clp) 445static void nfs_mark_return_all_delegation_types(struct nfs_server *server,
446 fmode_t flags)
374{ 447{
375 struct nfs_delegation *delegation; 448 struct nfs_delegation *delegation;
376 449
377 rcu_read_lock(); 450 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
378 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { 451 if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE))
379 set_bit(NFS_DELEGATION_RETURN, &delegation->flags); 452 continue;
380 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); 453 if (delegation->type & flags)
454 nfs_mark_return_delegation(delegation);
381 } 455 }
456}
457
458static void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp,
459 fmode_t flags)
460{
461 struct nfs_server *server;
462
463 rcu_read_lock();
464 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
465 nfs_mark_return_all_delegation_types(server, flags);
382 rcu_read_unlock(); 466 rcu_read_unlock();
383} 467}
384 468
469static void nfs_client_mark_return_all_delegations(struct nfs_client *clp)
470{
471 nfs_client_mark_return_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
472}
473
385static void nfs_delegation_run_state_manager(struct nfs_client *clp) 474static void nfs_delegation_run_state_manager(struct nfs_client *clp)
386{ 475{
387 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) 476 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state))
388 nfs4_schedule_state_manager(clp); 477 nfs4_schedule_state_manager(clp);
389} 478}
390 479
391void nfs_expire_all_delegations(struct nfs_client *clp) 480/**
481 * nfs_expire_all_delegation_types
482 * @clp: client to process
483 * @flags: delegation types to expire
484 *
485 */
486void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags)
392{ 487{
393 nfs_client_mark_return_all_delegations(clp); 488 nfs_client_mark_return_all_delegation_types(clp, flags);
394 nfs_delegation_run_state_manager(clp); 489 nfs_delegation_run_state_manager(clp);
395} 490}
396 491
397/* 492/**
398 * Return all delegations following an NFS4ERR_CB_PATH_DOWN error. 493 * nfs_expire_all_delegations
494 * @clp: client to process
495 *
496 */
497void nfs_expire_all_delegations(struct nfs_client *clp)
498{
499 nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
500}
501
502/**
503 * nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
504 * @clp: client to process
505 *
399 */ 506 */
400void nfs_handle_cb_pathdown(struct nfs_client *clp) 507void nfs_handle_cb_pathdown(struct nfs_client *clp)
401{ 508{
@@ -404,56 +511,69 @@ void nfs_handle_cb_pathdown(struct nfs_client *clp)
404 nfs_client_mark_return_all_delegations(clp); 511 nfs_client_mark_return_all_delegations(clp);
405} 512}
406 513
407static void nfs_client_mark_return_unreferenced_delegations(struct nfs_client *clp) 514static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
408{ 515{
409 struct nfs_delegation *delegation; 516 struct nfs_delegation *delegation;
410 517
411 rcu_read_lock(); 518 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
412 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
413 if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags)) 519 if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags))
414 continue; 520 continue;
415 set_bit(NFS_DELEGATION_RETURN, &delegation->flags); 521 nfs_mark_return_delegation(delegation);
416 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
417 } 522 }
418 rcu_read_unlock();
419} 523}
420 524
525/**
526 * nfs_expire_unreferenced_delegations - Eliminate unused delegations
527 * @clp: nfs_client to process
528 *
529 */
421void nfs_expire_unreferenced_delegations(struct nfs_client *clp) 530void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
422{ 531{
423 nfs_client_mark_return_unreferenced_delegations(clp); 532 struct nfs_server *server;
533
534 rcu_read_lock();
535 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
536 nfs_mark_return_unreferenced_delegations(server);
537 rcu_read_unlock();
538
424 nfs_delegation_run_state_manager(clp); 539 nfs_delegation_run_state_manager(clp);
425} 540}
426 541
427/* 542/**
428 * Asynchronous delegation recall! 543 * nfs_async_inode_return_delegation - asynchronously return a delegation
544 * @inode: inode to process
545 * @stateid: state ID information from CB_RECALL arguments
546 *
547 * Returns zero on success, or a negative errno value.
429 */ 548 */
430int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid) 549int nfs_async_inode_return_delegation(struct inode *inode,
550 const nfs4_stateid *stateid)
431{ 551{
432 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 552 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
433 struct nfs_delegation *delegation; 553 struct nfs_delegation *delegation;
434 554
435 rcu_read_lock(); 555 rcu_read_lock();
436 delegation = rcu_dereference(NFS_I(inode)->delegation); 556 delegation = rcu_dereference(NFS_I(inode)->delegation);
437 if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data, 557
438 sizeof(delegation->stateid.data)) != 0) { 558 if (!clp->cl_mvops->validate_stateid(delegation, stateid)) {
439 rcu_read_unlock(); 559 rcu_read_unlock();
440 return -ENOENT; 560 return -ENOENT;
441 } 561 }
442 nfs_mark_return_delegation(clp, delegation); 562 nfs_mark_return_delegation(delegation);
443 rcu_read_unlock(); 563 rcu_read_unlock();
564
444 nfs_delegation_run_state_manager(clp); 565 nfs_delegation_run_state_manager(clp);
445 return 0; 566 return 0;
446} 567}
447 568
448/* 569static struct inode *
449 * Retrieve the inode associated with a delegation 570nfs_delegation_find_inode_server(struct nfs_server *server,
450 */ 571 const struct nfs_fh *fhandle)
451struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle)
452{ 572{
453 struct nfs_delegation *delegation; 573 struct nfs_delegation *delegation;
454 struct inode *res = NULL; 574 struct inode *res = NULL;
455 rcu_read_lock(); 575
456 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { 576 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
457 spin_lock(&delegation->lock); 577 spin_lock(&delegation->lock);
458 if (delegation->inode != NULL && 578 if (delegation->inode != NULL &&
459 nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) { 579 nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
@@ -463,49 +583,121 @@ struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs
463 if (res != NULL) 583 if (res != NULL)
464 break; 584 break;
465 } 585 }
586 return res;
587}
588
589/**
590 * nfs_delegation_find_inode - retrieve the inode associated with a delegation
591 * @clp: client state handle
592 * @fhandle: filehandle from a delegation recall
593 *
594 * Returns pointer to inode matching "fhandle," or NULL if a matching inode
595 * cannot be found.
596 */
597struct inode *nfs_delegation_find_inode(struct nfs_client *clp,
598 const struct nfs_fh *fhandle)
599{
600 struct nfs_server *server;
601 struct inode *res = NULL;
602
603 rcu_read_lock();
604 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
605 res = nfs_delegation_find_inode_server(server, fhandle);
606 if (res != NULL)
607 break;
608 }
466 rcu_read_unlock(); 609 rcu_read_unlock();
467 return res; 610 return res;
468} 611}
469 612
470/* 613static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
471 * Mark all delegations as needing to be reclaimed 614{
615 struct nfs_delegation *delegation;
616
617 list_for_each_entry_rcu(delegation, &server->delegations, super_list)
618 set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
619}
620
621/**
622 * nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed
623 * @clp: nfs_client to process
624 *
472 */ 625 */
473void nfs_delegation_mark_reclaim(struct nfs_client *clp) 626void nfs_delegation_mark_reclaim(struct nfs_client *clp)
474{ 627{
475 struct nfs_delegation *delegation; 628 struct nfs_server *server;
629
476 rcu_read_lock(); 630 rcu_read_lock();
477 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) 631 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
478 set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); 632 nfs_delegation_mark_reclaim_server(server);
479 rcu_read_unlock(); 633 rcu_read_unlock();
480} 634}
481 635
482/* 636/**
483 * Reap all unclaimed delegations after reboot recovery is done 637 * nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done
638 * @clp: nfs_client to process
639 *
484 */ 640 */
485void nfs_delegation_reap_unclaimed(struct nfs_client *clp) 641void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
486{ 642{
487 struct nfs_delegation *delegation; 643 struct nfs_delegation *delegation;
644 struct nfs_server *server;
488 struct inode *inode; 645 struct inode *inode;
646
489restart: 647restart:
490 rcu_read_lock(); 648 rcu_read_lock();
491 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { 649 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
492 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) 650 list_for_each_entry_rcu(delegation, &server->delegations,
493 continue; 651 super_list) {
494 inode = nfs_delegation_grab_inode(delegation); 652 if (test_bit(NFS_DELEGATION_NEED_RECLAIM,
495 if (inode == NULL) 653 &delegation->flags) == 0)
496 continue; 654 continue;
497 spin_lock(&clp->cl_lock); 655 inode = nfs_delegation_grab_inode(delegation);
498 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL); 656 if (inode == NULL)
499 spin_unlock(&clp->cl_lock); 657 continue;
500 rcu_read_unlock(); 658 delegation = nfs_detach_delegation(NFS_I(inode),
501 if (delegation != NULL) 659 server);
502 nfs_free_delegation(delegation); 660 rcu_read_unlock();
503 iput(inode); 661
504 goto restart; 662 if (delegation != NULL)
663 nfs_free_delegation(delegation);
664 iput(inode);
665 goto restart;
666 }
505 } 667 }
506 rcu_read_unlock(); 668 rcu_read_unlock();
507} 669}
508 670
671/**
672 * nfs_delegations_present - check for existence of delegations
673 * @clp: client state handle
674 *
675 * Returns one if there are any nfs_delegation structures attached
676 * to this nfs_client.
677 */
678int nfs_delegations_present(struct nfs_client *clp)
679{
680 struct nfs_server *server;
681 int ret = 0;
682
683 rcu_read_lock();
684 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
685 if (!list_empty(&server->delegations)) {
686 ret = 1;
687 break;
688 }
689 rcu_read_unlock();
690 return ret;
691}
692
693/**
694 * nfs4_copy_delegation_stateid - Copy inode's state ID information
695 * @dst: stateid data structure to fill in
696 * @inode: inode to check
697 *
698 * Returns one and fills in "dst->data" * if inode had a delegation,
699 * otherwise zero is returned.
700 */
509int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode) 701int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
510{ 702{
511 struct nfs_inode *nfsi = NFS_I(inode); 703 struct nfs_inode *nfsi = NFS_I(inode);
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index 09f383795174..d9322e490c56 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -40,9 +40,11 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode);
40struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle); 40struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle);
41void nfs_super_return_all_delegations(struct super_block *sb); 41void nfs_super_return_all_delegations(struct super_block *sb);
42void nfs_expire_all_delegations(struct nfs_client *clp); 42void nfs_expire_all_delegations(struct nfs_client *clp);
43void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags);
43void nfs_expire_unreferenced_delegations(struct nfs_client *clp); 44void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
44void nfs_handle_cb_pathdown(struct nfs_client *clp); 45void nfs_handle_cb_pathdown(struct nfs_client *clp);
45void nfs_client_return_marked_delegations(struct nfs_client *clp); 46int nfs_client_return_marked_delegations(struct nfs_client *clp);
47int nfs_delegations_present(struct nfs_client *clp);
46 48
47void nfs_delegation_mark_reclaim(struct nfs_client *clp); 49void nfs_delegation_mark_reclaim(struct nfs_client *clp);
48void nfs_delegation_reap_unclaimed(struct nfs_client *clp); 50void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
@@ -68,4 +70,10 @@ static inline int nfs_inode_return_delegation(struct inode *inode)
68} 70}
69#endif 71#endif
70 72
73static inline int nfs_have_delegated_attributes(struct inode *inode)
74{
75 return nfs_have_delegation(inode, FMODE_READ) &&
76 !(NFS_I(inode)->cache_validity & NFS_INO_REVAL_FORCED);
77}
78
71#endif 79#endif
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 89f98e9a024b..abe4f0c8dc5f 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -29,16 +29,17 @@
29#include <linux/nfs_fs.h> 29#include <linux/nfs_fs.h>
30#include <linux/nfs_mount.h> 30#include <linux/nfs_mount.h>
31#include <linux/pagemap.h> 31#include <linux/pagemap.h>
32#include <linux/smp_lock.h>
33#include <linux/pagevec.h> 32#include <linux/pagevec.h>
34#include <linux/namei.h> 33#include <linux/namei.h>
35#include <linux/mount.h> 34#include <linux/mount.h>
36#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/kmemleak.h>
37#include <linux/xattr.h>
37 38
38#include "nfs4_fs.h"
39#include "delegation.h" 39#include "delegation.h"
40#include "iostat.h" 40#include "iostat.h"
41#include "internal.h" 41#include "internal.h"
42#include "fscache.h"
42 43
43/* #define NFS_DEBUG_VERBOSE 1 */ 44/* #define NFS_DEBUG_VERBOSE 1 */
44 45
@@ -54,8 +55,9 @@ static int nfs_link(struct dentry *, struct inode *, struct dentry *);
54static int nfs_mknod(struct inode *, struct dentry *, int, dev_t); 55static int nfs_mknod(struct inode *, struct dentry *, int, dev_t);
55static int nfs_rename(struct inode *, struct dentry *, 56static int nfs_rename(struct inode *, struct dentry *,
56 struct inode *, struct dentry *); 57 struct inode *, struct dentry *);
57static int nfs_fsync_dir(struct file *, struct dentry *, int); 58static int nfs_fsync_dir(struct file *, int);
58static loff_t nfs_llseek_dir(struct file *, loff_t, int); 59static loff_t nfs_llseek_dir(struct file *, loff_t, int);
60static void nfs_readdir_clear_array(struct page*);
59 61
60const struct file_operations nfs_dir_operations = { 62const struct file_operations nfs_dir_operations = {
61 .llseek = nfs_llseek_dir, 63 .llseek = nfs_llseek_dir,
@@ -81,6 +83,10 @@ const struct inode_operations nfs_dir_inode_operations = {
81 .setattr = nfs_setattr, 83 .setattr = nfs_setattr,
82}; 84};
83 85
86const struct address_space_operations nfs_dir_aops = {
87 .freepage = nfs_readdir_clear_array,
88};
89
84#ifdef CONFIG_NFS_V3 90#ifdef CONFIG_NFS_V3
85const struct inode_operations nfs3_dir_inode_operations = { 91const struct inode_operations nfs3_dir_inode_operations = {
86 .create = nfs_create, 92 .create = nfs_create,
@@ -105,8 +111,9 @@ const struct inode_operations nfs3_dir_inode_operations = {
105#ifdef CONFIG_NFS_V4 111#ifdef CONFIG_NFS_V4
106 112
107static struct dentry *nfs_atomic_lookup(struct inode *, struct dentry *, struct nameidata *); 113static struct dentry *nfs_atomic_lookup(struct inode *, struct dentry *, struct nameidata *);
114static int nfs_open_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd);
108const struct inode_operations nfs4_dir_inode_operations = { 115const struct inode_operations nfs4_dir_inode_operations = {
109 .create = nfs_create, 116 .create = nfs_open_create,
110 .lookup = nfs_atomic_lookup, 117 .lookup = nfs_atomic_lookup,
111 .link = nfs_link, 118 .link = nfs_link,
112 .unlink = nfs_unlink, 119 .unlink = nfs_unlink,
@@ -118,9 +125,10 @@ const struct inode_operations nfs4_dir_inode_operations = {
118 .permission = nfs_permission, 125 .permission = nfs_permission,
119 .getattr = nfs_getattr, 126 .getattr = nfs_getattr,
120 .setattr = nfs_setattr, 127 .setattr = nfs_setattr,
121 .getxattr = nfs4_getxattr, 128 .getxattr = generic_getxattr,
122 .setxattr = nfs4_setxattr, 129 .setxattr = generic_setxattr,
123 .listxattr = nfs4_listxattr, 130 .listxattr = generic_listxattr,
131 .removexattr = generic_removexattr,
124}; 132};
125 133
126#endif /* CONFIG_NFS_V4 */ 134#endif /* CONFIG_NFS_V4 */
@@ -141,54 +149,219 @@ nfs_opendir(struct inode *inode, struct file *filp)
141 149
142 /* Call generic open code in order to cache credentials */ 150 /* Call generic open code in order to cache credentials */
143 res = nfs_open(inode, filp); 151 res = nfs_open(inode, filp);
152 if (filp->f_path.dentry == filp->f_path.mnt->mnt_root) {
153 /* This is a mountpoint, so d_revalidate will never
154 * have been called, so we need to refresh the
155 * inode (for close-open consistency) ourselves.
156 */
157 __nfs_revalidate_inode(NFS_SERVER(inode), inode);
158 }
144 return res; 159 return res;
145} 160}
146 161
147typedef __be32 * (*decode_dirent_t)(__be32 *, struct nfs_entry *, int); 162struct nfs_cache_array_entry {
163 u64 cookie;
164 u64 ino;
165 struct qstr string;
166 unsigned char d_type;
167};
168
169struct nfs_cache_array {
170 unsigned int size;
171 int eof_index;
172 u64 last_cookie;
173 struct nfs_cache_array_entry array[0];
174};
175
176typedef int (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, int);
148typedef struct { 177typedef struct {
149 struct file *file; 178 struct file *file;
150 struct page *page; 179 struct page *page;
151 unsigned long page_index; 180 unsigned long page_index;
152 __be32 *ptr;
153 u64 *dir_cookie; 181 u64 *dir_cookie;
182 u64 last_cookie;
154 loff_t current_index; 183 loff_t current_index;
155 struct nfs_entry *entry;
156 decode_dirent_t decode; 184 decode_dirent_t decode;
157 int plus; 185
158 unsigned long timestamp; 186 unsigned long timestamp;
159 unsigned long gencount; 187 unsigned long gencount;
160 int timestamp_valid; 188 unsigned int cache_entry_index;
189 unsigned int plus:1;
190 unsigned int eof:1;
161} nfs_readdir_descriptor_t; 191} nfs_readdir_descriptor_t;
162 192
163/* Now we cache directories properly, by stuffing the dirent 193/*
164 * data directly in the page cache. 194 * The caller is responsible for calling nfs_readdir_release_array(page)
165 *
166 * Inode invalidation due to refresh etc. takes care of
167 * _everything_, no sloppy entry flushing logic, no extraneous
168 * copying, network direct to page cache, the way it was meant
169 * to be.
170 *
171 * NOTE: Dirent information verification is done always by the
172 * page-in of the RPC reply, nowhere else, this simplies
173 * things substantially.
174 */ 195 */
175static 196static
176int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page) 197struct nfs_cache_array *nfs_readdir_get_array(struct page *page)
198{
199 void *ptr;
200 if (page == NULL)
201 return ERR_PTR(-EIO);
202 ptr = kmap(page);
203 if (ptr == NULL)
204 return ERR_PTR(-ENOMEM);
205 return ptr;
206}
207
208static
209void nfs_readdir_release_array(struct page *page)
210{
211 kunmap(page);
212}
213
214/*
215 * we are freeing strings created by nfs_add_to_readdir_array()
216 */
217static
218void nfs_readdir_clear_array(struct page *page)
219{
220 struct nfs_cache_array *array;
221 int i;
222
223 array = kmap_atomic(page, KM_USER0);
224 for (i = 0; i < array->size; i++)
225 kfree(array->array[i].string.name);
226 kunmap_atomic(array, KM_USER0);
227}
228
229/*
230 * the caller is responsible for freeing qstr.name
231 * when called by nfs_readdir_add_to_array, the strings will be freed in
232 * nfs_clear_readdir_array()
233 */
234static
235int nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int len)
236{
237 string->len = len;
238 string->name = kmemdup(name, len, GFP_KERNEL);
239 if (string->name == NULL)
240 return -ENOMEM;
241 /*
242 * Avoid a kmemleak false positive. The pointer to the name is stored
243 * in a page cache page which kmemleak does not scan.
244 */
245 kmemleak_not_leak(string->name);
246 string->hash = full_name_hash(name, len);
247 return 0;
248}
249
250static
251int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
252{
253 struct nfs_cache_array *array = nfs_readdir_get_array(page);
254 struct nfs_cache_array_entry *cache_entry;
255 int ret;
256
257 if (IS_ERR(array))
258 return PTR_ERR(array);
259
260 cache_entry = &array->array[array->size];
261
262 /* Check that this entry lies within the page bounds */
263 ret = -ENOSPC;
264 if ((char *)&cache_entry[1] - (char *)page_address(page) > PAGE_SIZE)
265 goto out;
266
267 cache_entry->cookie = entry->prev_cookie;
268 cache_entry->ino = entry->ino;
269 cache_entry->d_type = entry->d_type;
270 ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len);
271 if (ret)
272 goto out;
273 array->last_cookie = entry->cookie;
274 array->size++;
275 if (entry->eof != 0)
276 array->eof_index = array->size;
277out:
278 nfs_readdir_release_array(page);
279 return ret;
280}
281
282static
283int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descriptor_t *desc)
284{
285 loff_t diff = desc->file->f_pos - desc->current_index;
286 unsigned int index;
287
288 if (diff < 0)
289 goto out_eof;
290 if (diff >= array->size) {
291 if (array->eof_index >= 0)
292 goto out_eof;
293 desc->current_index += array->size;
294 return -EAGAIN;
295 }
296
297 index = (unsigned int)diff;
298 *desc->dir_cookie = array->array[index].cookie;
299 desc->cache_entry_index = index;
300 return 0;
301out_eof:
302 desc->eof = 1;
303 return -EBADCOOKIE;
304}
305
306static
307int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_descriptor_t *desc)
308{
309 int i;
310 int status = -EAGAIN;
311
312 for (i = 0; i < array->size; i++) {
313 if (array->array[i].cookie == *desc->dir_cookie) {
314 desc->cache_entry_index = i;
315 return 0;
316 }
317 }
318 if (array->eof_index >= 0) {
319 status = -EBADCOOKIE;
320 if (*desc->dir_cookie == array->last_cookie)
321 desc->eof = 1;
322 }
323 return status;
324}
325
326static
327int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
328{
329 struct nfs_cache_array *array;
330 int status;
331
332 array = nfs_readdir_get_array(desc->page);
333 if (IS_ERR(array)) {
334 status = PTR_ERR(array);
335 goto out;
336 }
337
338 if (*desc->dir_cookie == 0)
339 status = nfs_readdir_search_for_pos(array, desc);
340 else
341 status = nfs_readdir_search_for_cookie(array, desc);
342
343 if (status == -EAGAIN) {
344 desc->last_cookie = array->last_cookie;
345 desc->page_index++;
346 }
347 nfs_readdir_release_array(desc->page);
348out:
349 return status;
350}
351
352/* Fill a page with xdr information before transferring to the cache page */
353static
354int nfs_readdir_xdr_filler(struct page **pages, nfs_readdir_descriptor_t *desc,
355 struct nfs_entry *entry, struct file *file, struct inode *inode)
177{ 356{
178 struct file *file = desc->file;
179 struct inode *inode = file->f_path.dentry->d_inode;
180 struct rpc_cred *cred = nfs_file_cred(file); 357 struct rpc_cred *cred = nfs_file_cred(file);
181 unsigned long timestamp, gencount; 358 unsigned long timestamp, gencount;
182 int error; 359 int error;
183 360
184 dfprintk(DIRCACHE, "NFS: %s: reading cookie %Lu into page %lu\n",
185 __func__, (long long)desc->entry->cookie,
186 page->index);
187
188 again: 361 again:
189 timestamp = jiffies; 362 timestamp = jiffies;
190 gencount = nfs_inc_attr_generation_counter(); 363 gencount = nfs_inc_attr_generation_counter();
191 error = NFS_PROTO(inode)->readdir(file->f_path.dentry, cred, desc->entry->cookie, page, 364 error = NFS_PROTO(inode)->readdir(file->f_path.dentry, cred, entry->cookie, pages,
192 NFS_SERVER(inode)->dtsize, desc->plus); 365 NFS_SERVER(inode)->dtsize, desc->plus);
193 if (error < 0) { 366 if (error < 0) {
194 /* We requested READDIRPLUS, but the server doesn't grok it */ 367 /* We requested READDIRPLUS, but the server doesn't grok it */
@@ -202,199 +375,313 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
202 } 375 }
203 desc->timestamp = timestamp; 376 desc->timestamp = timestamp;
204 desc->gencount = gencount; 377 desc->gencount = gencount;
205 desc->timestamp_valid = 1; 378error:
206 SetPageUptodate(page); 379 return error;
207 /* Ensure consistent page alignment of the data.
208 * Note: assumes we have exclusive access to this mapping either
209 * through inode->i_mutex or some other mechanism.
210 */
211 if (invalidate_inode_pages2_range(inode->i_mapping, page->index + 1, -1) < 0) {
212 /* Should never happen */
213 nfs_zap_mapping(inode, inode->i_mapping);
214 }
215 unlock_page(page);
216 return 0;
217 error:
218 unlock_page(page);
219 return -EIO;
220} 380}
221 381
222static inline 382static int xdr_decode(nfs_readdir_descriptor_t *desc,
223int dir_decode(nfs_readdir_descriptor_t *desc) 383 struct nfs_entry *entry, struct xdr_stream *xdr)
224{ 384{
225 __be32 *p = desc->ptr; 385 int error;
226 p = desc->decode(p, desc->entry, desc->plus); 386
227 if (IS_ERR(p)) 387 error = desc->decode(xdr, entry, desc->plus);
228 return PTR_ERR(p); 388 if (error)
229 desc->ptr = p; 389 return error;
230 if (desc->timestamp_valid) { 390 entry->fattr->time_start = desc->timestamp;
231 desc->entry->fattr->time_start = desc->timestamp; 391 entry->fattr->gencount = desc->gencount;
232 desc->entry->fattr->gencount = desc->gencount;
233 } else
234 desc->entry->fattr->valid &= ~NFS_ATTR_FATTR;
235 return 0; 392 return 0;
236} 393}
237 394
238static inline 395static
239void dir_page_release(nfs_readdir_descriptor_t *desc) 396int nfs_same_file(struct dentry *dentry, struct nfs_entry *entry)
240{ 397{
241 kunmap(desc->page); 398 if (dentry->d_inode == NULL)
242 page_cache_release(desc->page); 399 goto different;
243 desc->page = NULL; 400 if (nfs_compare_fh(entry->fh, NFS_FH(dentry->d_inode)) != 0)
244 desc->ptr = NULL; 401 goto different;
402 return 1;
403different:
404 return 0;
245} 405}
246 406
247/* 407static
248 * Given a pointer to a buffer that has already been filled by a call 408void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
249 * to readdir, find the next entry with cookie '*desc->dir_cookie'.
250 *
251 * If the end of the buffer has been reached, return -EAGAIN, if not,
252 * return the offset within the buffer of the next entry to be
253 * read.
254 */
255static inline
256int find_dirent(nfs_readdir_descriptor_t *desc)
257{ 409{
258 struct nfs_entry *entry = desc->entry; 410 struct qstr filename = {
259 int loop_count = 0, 411 .len = entry->len,
260 status; 412 .name = entry->name,
413 };
414 struct dentry *dentry;
415 struct dentry *alias;
416 struct inode *dir = parent->d_inode;
417 struct inode *inode;
261 418
262 while((status = dir_decode(desc)) == 0) { 419 if (filename.name[0] == '.') {
263 dfprintk(DIRCACHE, "NFS: %s: examining cookie %Lu\n", 420 if (filename.len == 1)
264 __func__, (unsigned long long)entry->cookie); 421 return;
265 if (entry->prev_cookie == *desc->dir_cookie) 422 if (filename.len == 2 && filename.name[1] == '.')
266 break; 423 return;
267 if (loop_count++ > 200) { 424 }
268 loop_count = 0; 425 filename.hash = full_name_hash(filename.name, filename.len);
269 schedule(); 426
427 dentry = d_lookup(parent, &filename);
428 if (dentry != NULL) {
429 if (nfs_same_file(dentry, entry)) {
430 nfs_refresh_inode(dentry->d_inode, entry->fattr);
431 goto out;
432 } else {
433 d_drop(dentry);
434 dput(dentry);
270 } 435 }
271 } 436 }
272 return status; 437
438 dentry = d_alloc(parent, &filename);
439 if (dentry == NULL)
440 return;
441
442 d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops);
443 inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr);
444 if (IS_ERR(inode))
445 goto out;
446
447 alias = d_materialise_unique(dentry, inode);
448 if (IS_ERR(alias))
449 goto out;
450 else if (alias) {
451 nfs_set_verifier(alias, nfs_save_change_attribute(dir));
452 dput(alias);
453 } else
454 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
455
456out:
457 dput(dentry);
273} 458}
274 459
275/* 460/* Perform conversion from xdr to cache array */
276 * Given a pointer to a buffer that has already been filled by a call 461static
277 * to readdir, find the entry at offset 'desc->file->f_pos'. 462int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry,
278 * 463 struct page **xdr_pages, struct page *page, unsigned int buflen)
279 * If the end of the buffer has been reached, return -EAGAIN, if not,
280 * return the offset within the buffer of the next entry to be
281 * read.
282 */
283static inline
284int find_dirent_index(nfs_readdir_descriptor_t *desc)
285{ 464{
286 struct nfs_entry *entry = desc->entry; 465 struct xdr_stream stream;
287 int loop_count = 0, 466 struct xdr_buf buf = {
288 status; 467 .pages = xdr_pages,
468 .page_len = buflen,
469 .buflen = buflen,
470 .len = buflen,
471 };
472 struct page *scratch;
473 struct nfs_cache_array *array;
474 unsigned int count = 0;
475 int status;
289 476
290 for(;;) { 477 scratch = alloc_page(GFP_KERNEL);
291 status = dir_decode(desc); 478 if (scratch == NULL)
292 if (status) 479 return -ENOMEM;
293 break;
294 480
295 dfprintk(DIRCACHE, "NFS: found cookie %Lu at index %Ld\n", 481 xdr_init_decode(&stream, &buf, NULL);
296 (unsigned long long)entry->cookie, desc->current_index); 482 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
297 483
298 if (desc->file->f_pos == desc->current_index) { 484 do {
299 *desc->dir_cookie = entry->cookie; 485 status = xdr_decode(desc, entry, &stream);
486 if (status != 0) {
487 if (status == -EAGAIN)
488 status = 0;
300 break; 489 break;
301 } 490 }
302 desc->current_index++; 491
303 if (loop_count++ > 200) { 492 count++;
304 loop_count = 0; 493
305 schedule(); 494 if (desc->plus != 0)
306 } 495 nfs_prime_dcache(desc->file->f_path.dentry, entry);
496
497 status = nfs_readdir_add_to_array(entry, page);
498 if (status != 0)
499 break;
500 } while (!entry->eof);
501
502 if (count == 0 || (status == -EBADCOOKIE && entry->eof != 0)) {
503 array = nfs_readdir_get_array(page);
504 if (!IS_ERR(array)) {
505 array->eof_index = array->size;
506 status = 0;
507 nfs_readdir_release_array(page);
508 } else
509 status = PTR_ERR(array);
307 } 510 }
511
512 put_page(scratch);
308 return status; 513 return status;
309} 514}
310 515
516static
517void nfs_readdir_free_pagearray(struct page **pages, unsigned int npages)
518{
519 unsigned int i;
520 for (i = 0; i < npages; i++)
521 put_page(pages[i]);
522}
523
524static
525void nfs_readdir_free_large_page(void *ptr, struct page **pages,
526 unsigned int npages)
527{
528 nfs_readdir_free_pagearray(pages, npages);
529}
530
311/* 531/*
312 * Find the given page, and call find_dirent() or find_dirent_index in 532 * nfs_readdir_large_page will allocate pages that must be freed with a call
313 * order to try to return the next entry. 533 * to nfs_readdir_free_large_page
314 */ 534 */
315static inline 535static
316int find_dirent_page(nfs_readdir_descriptor_t *desc) 536int nfs_readdir_large_page(struct page **pages, unsigned int npages)
317{ 537{
318 struct inode *inode = desc->file->f_path.dentry->d_inode; 538 unsigned int i;
319 struct page *page; 539
320 int status; 540 for (i = 0; i < npages; i++) {
541 struct page *page = alloc_page(GFP_KERNEL);
542 if (page == NULL)
543 goto out_freepages;
544 pages[i] = page;
545 }
546 return 0;
321 547
322 dfprintk(DIRCACHE, "NFS: %s: searching page %ld for target %Lu\n", 548out_freepages:
323 __func__, desc->page_index, 549 nfs_readdir_free_pagearray(pages, i);
324 (long long) *desc->dir_cookie); 550 return -ENOMEM;
551}
325 552
326 /* If we find the page in the page_cache, we cannot be sure 553static
327 * how fresh the data is, so we will ignore readdir_plus attributes. 554int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page, struct inode *inode)
328 */ 555{
329 desc->timestamp_valid = 0; 556 struct page *pages[NFS_MAX_READDIR_PAGES];
330 page = read_cache_page(inode->i_mapping, desc->page_index, 557 void *pages_ptr = NULL;
331 (filler_t *)nfs_readdir_filler, desc); 558 struct nfs_entry entry;
332 if (IS_ERR(page)) { 559 struct file *file = desc->file;
333 status = PTR_ERR(page); 560 struct nfs_cache_array *array;
561 int status = -ENOMEM;
562 unsigned int array_size = ARRAY_SIZE(pages);
563
564 entry.prev_cookie = 0;
565 entry.cookie = desc->last_cookie;
566 entry.eof = 0;
567 entry.fh = nfs_alloc_fhandle();
568 entry.fattr = nfs_alloc_fattr();
569 entry.server = NFS_SERVER(inode);
570 if (entry.fh == NULL || entry.fattr == NULL)
571 goto out;
572
573 array = nfs_readdir_get_array(page);
574 if (IS_ERR(array)) {
575 status = PTR_ERR(array);
334 goto out; 576 goto out;
335 } 577 }
578 memset(array, 0, sizeof(struct nfs_cache_array));
579 array->eof_index = -1;
336 580
337 /* NOTE: Someone else may have changed the READDIRPLUS flag */ 581 status = nfs_readdir_large_page(pages, array_size);
338 desc->page = page;
339 desc->ptr = kmap(page); /* matching kunmap in nfs_do_filldir */
340 if (*desc->dir_cookie != 0)
341 status = find_dirent(desc);
342 else
343 status = find_dirent_index(desc);
344 if (status < 0) 582 if (status < 0)
345 dir_page_release(desc); 583 goto out_release_array;
346 out: 584 do {
347 dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __func__, status); 585 unsigned int pglen;
586 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode);
587
588 if (status < 0)
589 break;
590 pglen = status;
591 status = nfs_readdir_page_filler(desc, &entry, pages, page, pglen);
592 if (status < 0) {
593 if (status == -ENOSPC)
594 status = 0;
595 break;
596 }
597 } while (array->eof_index < 0);
598
599 nfs_readdir_free_large_page(pages_ptr, pages, array_size);
600out_release_array:
601 nfs_readdir_release_array(page);
602out:
603 nfs_free_fattr(entry.fattr);
604 nfs_free_fhandle(entry.fh);
348 return status; 605 return status;
349} 606}
350 607
351/* 608/*
352 * Recurse through the page cache pages, and return a 609 * Now we cache directories properly, by converting xdr information
353 * filled nfs_entry structure of the next directory entry if possible. 610 * to an array that can be used for lookups later. This results in
354 * 611 * fewer cache pages, since we can store more information on each page.
355 * The target for the search is '*desc->dir_cookie' if non-0, 612 * We only need to convert from xdr once so future lookups are much simpler
356 * 'desc->file->f_pos' otherwise
357 */ 613 */
358static inline 614static
359int readdir_search_pagecache(nfs_readdir_descriptor_t *desc) 615int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
360{ 616{
361 int loop_count = 0; 617 struct inode *inode = desc->file->f_path.dentry->d_inode;
362 int res; 618 int ret;
363 619
364 /* Always search-by-index from the beginning of the cache */ 620 ret = nfs_readdir_xdr_to_array(desc, page, inode);
365 if (*desc->dir_cookie == 0) { 621 if (ret < 0)
366 dfprintk(DIRCACHE, "NFS: readdir_search_pagecache() searching for offset %Ld\n", 622 goto error;
367 (long long)desc->file->f_pos); 623 SetPageUptodate(page);
368 desc->page_index = 0;
369 desc->entry->cookie = desc->entry->prev_cookie = 0;
370 desc->entry->eof = 0;
371 desc->current_index = 0;
372 } else
373 dfprintk(DIRCACHE, "NFS: readdir_search_pagecache() searching for cookie %Lu\n",
374 (unsigned long long)*desc->dir_cookie);
375 624
376 for (;;) { 625 if (invalidate_inode_pages2_range(inode->i_mapping, page->index + 1, -1) < 0) {
377 res = find_dirent_page(desc); 626 /* Should never happen */
378 if (res != -EAGAIN) 627 nfs_zap_mapping(inode, inode->i_mapping);
379 break;
380 /* Align to beginning of next page */
381 desc->page_index ++;
382 if (loop_count++ > 200) {
383 loop_count = 0;
384 schedule();
385 }
386 } 628 }
629 unlock_page(page);
630 return 0;
631 error:
632 unlock_page(page);
633 return ret;
634}
387 635
388 dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __func__, res); 636static
389 return res; 637void cache_page_release(nfs_readdir_descriptor_t *desc)
638{
639 if (!desc->page->mapping)
640 nfs_readdir_clear_array(desc->page);
641 page_cache_release(desc->page);
642 desc->page = NULL;
390} 643}
391 644
392static inline unsigned int dt_type(struct inode *inode) 645static
646struct page *get_cache_page(nfs_readdir_descriptor_t *desc)
647{
648 return read_cache_page(desc->file->f_path.dentry->d_inode->i_mapping,
649 desc->page_index, (filler_t *)nfs_readdir_filler, desc);
650}
651
652/*
653 * Returns 0 if desc->dir_cookie was found on page desc->page_index
654 */
655static
656int find_cache_page(nfs_readdir_descriptor_t *desc)
393{ 657{
394 return (inode->i_mode >> 12) & 15; 658 int res;
659
660 desc->page = get_cache_page(desc);
661 if (IS_ERR(desc->page))
662 return PTR_ERR(desc->page);
663
664 res = nfs_readdir_search_array(desc);
665 if (res != 0)
666 cache_page_release(desc);
667 return res;
395} 668}
396 669
397static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc); 670/* Search for desc->dir_cookie from the beginning of the page cache */
671static inline
672int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
673{
674 int res;
675
676 if (desc->page_index == 0) {
677 desc->current_index = 0;
678 desc->last_cookie = 0;
679 }
680 do {
681 res = find_cache_page(desc);
682 } while (res == -EAGAIN);
683 return res;
684}
398 685
399/* 686/*
400 * Once we've found the start of the dirent within a page: fill 'er up... 687 * Once we've found the start of the dirent within a page: fill 'er up...
@@ -404,51 +691,38 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
404 filldir_t filldir) 691 filldir_t filldir)
405{ 692{
406 struct file *file = desc->file; 693 struct file *file = desc->file;
407 struct nfs_entry *entry = desc->entry; 694 int i = 0;
408 struct dentry *dentry = NULL; 695 int res = 0;
409 u64 fileid; 696 struct nfs_cache_array *array = NULL;
410 int loop_count = 0,
411 res;
412
413 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling starting @ cookie %Lu\n",
414 (unsigned long long)entry->cookie);
415
416 for(;;) {
417 unsigned d_type = DT_UNKNOWN;
418 /* Note: entry->prev_cookie contains the cookie for
419 * retrieving the current dirent on the server */
420 fileid = entry->ino;
421
422 /* Get a dentry if we have one */
423 if (dentry != NULL)
424 dput(dentry);
425 dentry = nfs_readdir_lookup(desc);
426 697
427 /* Use readdirplus info */ 698 array = nfs_readdir_get_array(desc->page);
428 if (dentry != NULL && dentry->d_inode != NULL) { 699 if (IS_ERR(array)) {
429 d_type = dt_type(dentry->d_inode); 700 res = PTR_ERR(array);
430 fileid = NFS_FILEID(dentry->d_inode); 701 goto out;
431 } 702 }
432 703
433 res = filldir(dirent, entry->name, entry->len, 704 for (i = desc->cache_entry_index; i < array->size; i++) {
434 file->f_pos, nfs_compat_user_ino64(fileid), 705 struct nfs_cache_array_entry *ent;
435 d_type); 706
436 if (res < 0) 707 ent = &array->array[i];
437 break; 708 if (filldir(dirent, ent->string.name, ent->string.len,
438 file->f_pos++; 709 file->f_pos, nfs_compat_user_ino64(ent->ino),
439 *desc->dir_cookie = entry->cookie; 710 ent->d_type) < 0) {
440 if (dir_decode(desc) != 0) { 711 desc->eof = 1;
441 desc->page_index ++;
442 break; 712 break;
443 } 713 }
444 if (loop_count++ > 200) { 714 file->f_pos++;
445 loop_count = 0; 715 if (i < (array->size-1))
446 schedule(); 716 *desc->dir_cookie = array->array[i+1].cookie;
447 } 717 else
718 *desc->dir_cookie = array->last_cookie;
448 } 719 }
449 dir_page_release(desc); 720 if (array->eof_index >= 0)
450 if (dentry != NULL) 721 desc->eof = 1;
451 dput(dentry); 722
723 nfs_readdir_release_array(desc->page);
724out:
725 cache_page_release(desc);
452 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %Lu; returning = %d\n", 726 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %Lu; returning = %d\n",
453 (unsigned long long)*desc->dir_cookie, res); 727 (unsigned long long)*desc->dir_cookie, res);
454 return res; 728 return res;
@@ -470,12 +744,9 @@ static inline
470int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent, 744int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
471 filldir_t filldir) 745 filldir_t filldir)
472{ 746{
473 struct file *file = desc->file;
474 struct inode *inode = file->f_path.dentry->d_inode;
475 struct rpc_cred *cred = nfs_file_cred(file);
476 struct page *page = NULL; 747 struct page *page = NULL;
477 int status; 748 int status;
478 unsigned long timestamp, gencount; 749 struct inode *inode = desc->file->f_path.dentry->d_inode;
479 750
480 dfprintk(DIRCACHE, "NFS: uncached_readdir() searching for cookie %Lu\n", 751 dfprintk(DIRCACHE, "NFS: uncached_readdir() searching for cookie %Lu\n",
481 (unsigned long long)*desc->dir_cookie); 752 (unsigned long long)*desc->dir_cookie);
@@ -485,38 +756,23 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
485 status = -ENOMEM; 756 status = -ENOMEM;
486 goto out; 757 goto out;
487 } 758 }
488 timestamp = jiffies; 759
489 gencount = nfs_inc_attr_generation_counter(); 760 desc->page_index = 0;
490 status = NFS_PROTO(inode)->readdir(file->f_path.dentry, cred, 761 desc->last_cookie = *desc->dir_cookie;
491 *desc->dir_cookie, page,
492 NFS_SERVER(inode)->dtsize,
493 desc->plus);
494 desc->page = page; 762 desc->page = page;
495 desc->ptr = kmap(page); /* matching kunmap in nfs_do_filldir */ 763
496 if (status >= 0) { 764 status = nfs_readdir_xdr_to_array(desc, page, inode);
497 desc->timestamp = timestamp;
498 desc->gencount = gencount;
499 desc->timestamp_valid = 1;
500 if ((status = dir_decode(desc)) == 0)
501 desc->entry->prev_cookie = *desc->dir_cookie;
502 } else
503 status = -EIO;
504 if (status < 0) 765 if (status < 0)
505 goto out_release; 766 goto out_release;
506 767
507 status = nfs_do_filldir(desc, dirent, filldir); 768 status = nfs_do_filldir(desc, dirent, filldir);
508 769
509 /* Reset read descriptor so it searches the page cache from
510 * the start upon the next call to readdir_search_pagecache() */
511 desc->page_index = 0;
512 desc->entry->cookie = desc->entry->prev_cookie = 0;
513 desc->entry->eof = 0;
514 out: 770 out:
515 dfprintk(DIRCACHE, "NFS: %s: returns %d\n", 771 dfprintk(DIRCACHE, "NFS: %s: returns %d\n",
516 __func__, status); 772 __func__, status);
517 return status; 773 return status;
518 out_release: 774 out_release:
519 dir_page_release(desc); 775 cache_page_release(desc);
520 goto out; 776 goto out;
521} 777}
522 778
@@ -530,10 +786,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
530 struct inode *inode = dentry->d_inode; 786 struct inode *inode = dentry->d_inode;
531 nfs_readdir_descriptor_t my_desc, 787 nfs_readdir_descriptor_t my_desc,
532 *desc = &my_desc; 788 *desc = &my_desc;
533 struct nfs_entry my_entry; 789 int res;
534 struct nfs_fh fh;
535 struct nfs_fattr fattr;
536 long res;
537 790
538 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n", 791 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
539 dentry->d_parent->d_name.name, dentry->d_name.name, 792 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -553,53 +806,45 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
553 desc->decode = NFS_PROTO(inode)->decode_dirent; 806 desc->decode = NFS_PROTO(inode)->decode_dirent;
554 desc->plus = NFS_USE_READDIRPLUS(inode); 807 desc->plus = NFS_USE_READDIRPLUS(inode);
555 808
556 my_entry.cookie = my_entry.prev_cookie = 0;
557 my_entry.eof = 0;
558 my_entry.fh = &fh;
559 my_entry.fattr = &fattr;
560 nfs_fattr_init(&fattr);
561 desc->entry = &my_entry;
562
563 nfs_block_sillyrename(dentry); 809 nfs_block_sillyrename(dentry);
564 res = nfs_revalidate_mapping_nolock(inode, filp->f_mapping); 810 res = nfs_revalidate_mapping(inode, filp->f_mapping);
565 if (res < 0) 811 if (res < 0)
566 goto out; 812 goto out;
567 813
568 while(!desc->entry->eof) { 814 do {
569 res = readdir_search_pagecache(desc); 815 res = readdir_search_pagecache(desc);
570 816
571 if (res == -EBADCOOKIE) { 817 if (res == -EBADCOOKIE) {
818 res = 0;
572 /* This means either end of directory */ 819 /* This means either end of directory */
573 if (*desc->dir_cookie && desc->entry->cookie != *desc->dir_cookie) { 820 if (*desc->dir_cookie && desc->eof == 0) {
574 /* Or that the server has 'lost' a cookie */ 821 /* Or that the server has 'lost' a cookie */
575 res = uncached_readdir(desc, dirent, filldir); 822 res = uncached_readdir(desc, dirent, filldir);
576 if (res >= 0) 823 if (res == 0)
577 continue; 824 continue;
578 } 825 }
579 res = 0;
580 break; 826 break;
581 } 827 }
582 if (res == -ETOOSMALL && desc->plus) { 828 if (res == -ETOOSMALL && desc->plus) {
583 clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags); 829 clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
584 nfs_zap_caches(inode); 830 nfs_zap_caches(inode);
831 desc->page_index = 0;
585 desc->plus = 0; 832 desc->plus = 0;
586 desc->entry->eof = 0; 833 desc->eof = 0;
587 continue; 834 continue;
588 } 835 }
589 if (res < 0) 836 if (res < 0)
590 break; 837 break;
591 838
592 res = nfs_do_filldir(desc, dirent, filldir); 839 res = nfs_do_filldir(desc, dirent, filldir);
593 if (res < 0) { 840 if (res < 0)
594 res = 0;
595 break; 841 break;
596 } 842 } while (!desc->eof);
597 }
598out: 843out:
599 nfs_unblock_sillyrename(dentry); 844 nfs_unblock_sillyrename(dentry);
600 if (res > 0) 845 if (res > 0)
601 res = 0; 846 res = 0;
602 dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n", 847 dfprintk(FILE, "NFS: readdir(%s/%s) returns %d\n",
603 dentry->d_parent->d_name.name, dentry->d_name.name, 848 dentry->d_parent->d_name.name, dentry->d_name.name,
604 res); 849 res);
605 return res; 850 return res;
@@ -639,8 +884,10 @@ out:
639 * All directory operations under NFS are synchronous, so fsync() 884 * All directory operations under NFS are synchronous, so fsync()
640 * is a dummy operation. 885 * is a dummy operation.
641 */ 886 */
642static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync) 887static int nfs_fsync_dir(struct file *filp, int datasync)
643{ 888{
889 struct dentry *dentry = filp->f_path.dentry;
890
644 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n", 891 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n",
645 dentry->d_parent->d_name.name, dentry->d_name.name, 892 dentry->d_parent->d_name.name, dentry->d_name.name,
646 datasync); 893 datasync);
@@ -692,7 +939,8 @@ static int nfs_check_verifier(struct inode *dir, struct dentry *dentry)
692 * component of the path. 939 * component of the path.
693 * We check for this using LOOKUP_CONTINUE and LOOKUP_PARENT. 940 * We check for this using LOOKUP_CONTINUE and LOOKUP_PARENT.
694 */ 941 */
695static inline unsigned int nfs_lookup_check_intent(struct nameidata *nd, unsigned int mask) 942static inline unsigned int nfs_lookup_check_intent(struct nameidata *nd,
943 unsigned int mask)
696{ 944{
697 if (nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT)) 945 if (nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))
698 return 0; 946 return 0;
@@ -772,14 +1020,17 @@ int nfs_neg_need_reval(struct inode *dir, struct dentry *dentry,
772 * If the parent directory is seen to have changed, we throw out the 1020 * If the parent directory is seen to have changed, we throw out the
773 * cached dentry and do a new lookup. 1021 * cached dentry and do a new lookup.
774 */ 1022 */
775static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd) 1023static int nfs_lookup_revalidate(struct dentry *dentry, struct nameidata *nd)
776{ 1024{
777 struct inode *dir; 1025 struct inode *dir;
778 struct inode *inode; 1026 struct inode *inode;
779 struct dentry *parent; 1027 struct dentry *parent;
1028 struct nfs_fh *fhandle = NULL;
1029 struct nfs_fattr *fattr = NULL;
780 int error; 1030 int error;
781 struct nfs_fh fhandle; 1031
782 struct nfs_fattr fattr; 1032 if (nd->flags & LOOKUP_RCU)
1033 return -ECHILD;
783 1034
784 parent = dget_parent(dentry); 1035 parent = dget_parent(dentry);
785 dir = parent->d_inode; 1036 dir = parent->d_inode;
@@ -812,14 +1063,22 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
812 if (NFS_STALE(inode)) 1063 if (NFS_STALE(inode))
813 goto out_bad; 1064 goto out_bad;
814 1065
815 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr); 1066 error = -ENOMEM;
1067 fhandle = nfs_alloc_fhandle();
1068 fattr = nfs_alloc_fattr();
1069 if (fhandle == NULL || fattr == NULL)
1070 goto out_error;
1071
1072 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
816 if (error) 1073 if (error)
817 goto out_bad; 1074 goto out_bad;
818 if (nfs_compare_fh(NFS_FH(inode), &fhandle)) 1075 if (nfs_compare_fh(NFS_FH(inode), fhandle))
819 goto out_bad; 1076 goto out_bad;
820 if ((error = nfs_refresh_inode(inode, &fattr)) != 0) 1077 if ((error = nfs_refresh_inode(inode, fattr)) != 0)
821 goto out_bad; 1078 goto out_bad;
822 1079
1080 nfs_free_fattr(fattr);
1081 nfs_free_fhandle(fhandle);
823out_set_verifier: 1082out_set_verifier:
824 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1083 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
825 out_valid: 1084 out_valid:
@@ -838,20 +1097,32 @@ out_zap_parent:
838 /* If we have submounts, don't unhash ! */ 1097 /* If we have submounts, don't unhash ! */
839 if (have_submounts(dentry)) 1098 if (have_submounts(dentry))
840 goto out_valid; 1099 goto out_valid;
1100 if (dentry->d_flags & DCACHE_DISCONNECTED)
1101 goto out_valid;
841 shrink_dcache_parent(dentry); 1102 shrink_dcache_parent(dentry);
842 } 1103 }
843 d_drop(dentry); 1104 d_drop(dentry);
1105 nfs_free_fattr(fattr);
1106 nfs_free_fhandle(fhandle);
844 dput(parent); 1107 dput(parent);
845 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n", 1108 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
846 __func__, dentry->d_parent->d_name.name, 1109 __func__, dentry->d_parent->d_name.name,
847 dentry->d_name.name); 1110 dentry->d_name.name);
848 return 0; 1111 return 0;
1112out_error:
1113 nfs_free_fattr(fattr);
1114 nfs_free_fhandle(fhandle);
1115 dput(parent);
1116 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) lookup returned error %d\n",
1117 __func__, dentry->d_parent->d_name.name,
1118 dentry->d_name.name, error);
1119 return error;
849} 1120}
850 1121
851/* 1122/*
852 * This is called from dput() when d_count is going to 0. 1123 * This is called from dput() when d_count is going to 0.
853 */ 1124 */
854static int nfs_dentry_delete(struct dentry *dentry) 1125static int nfs_dentry_delete(const struct dentry *dentry)
855{ 1126{
856 dfprintk(VFS, "NFS: dentry_delete(%s/%s, %x)\n", 1127 dfprintk(VFS, "NFS: dentry_delete(%s/%s, %x)\n",
857 dentry->d_parent->d_name.name, dentry->d_name.name, 1128 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -910,9 +1181,9 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
910 struct dentry *res; 1181 struct dentry *res;
911 struct dentry *parent; 1182 struct dentry *parent;
912 struct inode *inode = NULL; 1183 struct inode *inode = NULL;
1184 struct nfs_fh *fhandle = NULL;
1185 struct nfs_fattr *fattr = NULL;
913 int error; 1186 int error;
914 struct nfs_fh fhandle;
915 struct nfs_fattr fattr;
916 1187
917 dfprintk(VFS, "NFS: lookup(%s/%s)\n", 1188 dfprintk(VFS, "NFS: lookup(%s/%s)\n",
918 dentry->d_parent->d_name.name, dentry->d_name.name); 1189 dentry->d_parent->d_name.name, dentry->d_name.name);
@@ -922,8 +1193,7 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
922 if (dentry->d_name.len > NFS_SERVER(dir)->namelen) 1193 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
923 goto out; 1194 goto out;
924 1195
925 res = ERR_PTR(-ENOMEM); 1196 d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops);
926 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
927 1197
928 /* 1198 /*
929 * If we're doing an exclusive create, optimize away the lookup 1199 * If we're doing an exclusive create, optimize away the lookup
@@ -935,18 +1205,24 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
935 goto out; 1205 goto out;
936 } 1206 }
937 1207
1208 res = ERR_PTR(-ENOMEM);
1209 fhandle = nfs_alloc_fhandle();
1210 fattr = nfs_alloc_fattr();
1211 if (fhandle == NULL || fattr == NULL)
1212 goto out;
1213
938 parent = dentry->d_parent; 1214 parent = dentry->d_parent;
939 /* Protect against concurrent sillydeletes */ 1215 /* Protect against concurrent sillydeletes */
940 nfs_block_sillyrename(parent); 1216 nfs_block_sillyrename(parent);
941 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr); 1217 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
942 if (error == -ENOENT) 1218 if (error == -ENOENT)
943 goto no_entry; 1219 goto no_entry;
944 if (error < 0) { 1220 if (error < 0) {
945 res = ERR_PTR(error); 1221 res = ERR_PTR(error);
946 goto out_unblock_sillyrename; 1222 goto out_unblock_sillyrename;
947 } 1223 }
948 inode = nfs_fhget(dentry->d_sb, &fhandle, &fattr); 1224 inode = nfs_fhget(dentry->d_sb, fhandle, fattr);
949 res = (struct dentry *)inode; 1225 res = ERR_CAST(inode);
950 if (IS_ERR(res)) 1226 if (IS_ERR(res))
951 goto out_unblock_sillyrename; 1227 goto out_unblock_sillyrename;
952 1228
@@ -961,6 +1237,8 @@ no_entry:
961out_unblock_sillyrename: 1237out_unblock_sillyrename:
962 nfs_unblock_sillyrename(parent); 1238 nfs_unblock_sillyrename(parent);
963out: 1239out:
1240 nfs_free_fattr(fattr);
1241 nfs_free_fhandle(fhandle);
964 return res; 1242 return res;
965} 1243}
966 1244
@@ -991,10 +1269,63 @@ static int is_atomic_open(struct nameidata *nd)
991 return 1; 1269 return 1;
992} 1270}
993 1271
1272static struct nfs_open_context *nameidata_to_nfs_open_context(struct dentry *dentry, struct nameidata *nd)
1273{
1274 struct path path = {
1275 .mnt = nd->path.mnt,
1276 .dentry = dentry,
1277 };
1278 struct nfs_open_context *ctx;
1279 struct rpc_cred *cred;
1280 fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
1281
1282 cred = rpc_lookup_cred();
1283 if (IS_ERR(cred))
1284 return ERR_CAST(cred);
1285 ctx = alloc_nfs_open_context(&path, cred, fmode);
1286 put_rpccred(cred);
1287 if (ctx == NULL)
1288 return ERR_PTR(-ENOMEM);
1289 return ctx;
1290}
1291
1292static int do_open(struct inode *inode, struct file *filp)
1293{
1294 nfs_fscache_set_inode_cookie(inode, filp);
1295 return 0;
1296}
1297
1298static int nfs_intent_set_file(struct nameidata *nd, struct nfs_open_context *ctx)
1299{
1300 struct file *filp;
1301 int ret = 0;
1302
1303 /* If the open_intent is for execute, we have an extra check to make */
1304 if (ctx->mode & FMODE_EXEC) {
1305 ret = nfs_may_open(ctx->path.dentry->d_inode,
1306 ctx->cred,
1307 nd->intent.open.flags);
1308 if (ret < 0)
1309 goto out;
1310 }
1311 filp = lookup_instantiate_filp(nd, ctx->path.dentry, do_open);
1312 if (IS_ERR(filp))
1313 ret = PTR_ERR(filp);
1314 else
1315 nfs_file_set_open_context(filp, ctx);
1316out:
1317 put_nfs_open_context(ctx);
1318 return ret;
1319}
1320
994static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 1321static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
995{ 1322{
1323 struct nfs_open_context *ctx;
1324 struct iattr attr;
996 struct dentry *res = NULL; 1325 struct dentry *res = NULL;
997 int error; 1326 struct inode *inode;
1327 int open_flags;
1328 int err;
998 1329
999 dfprintk(VFS, "NFS: atomic_lookup(%s/%ld), %s\n", 1330 dfprintk(VFS, "NFS: atomic_lookup(%s/%ld), %s\n",
1000 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); 1331 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name);
@@ -1007,7 +1338,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1007 res = ERR_PTR(-ENAMETOOLONG); 1338 res = ERR_PTR(-ENAMETOOLONG);
1008 goto out; 1339 goto out;
1009 } 1340 }
1010 dentry->d_op = NFS_PROTO(dir)->dentry_ops; 1341 d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops);
1011 1342
1012 /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash 1343 /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash
1013 * the dentry. */ 1344 * the dentry. */
@@ -1016,29 +1347,61 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1016 goto out; 1347 goto out;
1017 } 1348 }
1018 1349
1350 ctx = nameidata_to_nfs_open_context(dentry, nd);
1351 res = ERR_CAST(ctx);
1352 if (IS_ERR(ctx))
1353 goto out;
1354
1355 open_flags = nd->intent.open.flags;
1356 if (nd->flags & LOOKUP_CREATE) {
1357 attr.ia_mode = nd->intent.open.create_mode;
1358 attr.ia_valid = ATTR_MODE;
1359 attr.ia_mode &= ~current_umask();
1360 } else {
1361 open_flags &= ~(O_EXCL | O_CREAT);
1362 attr.ia_valid = 0;
1363 }
1364
1019 /* Open the file on the server */ 1365 /* Open the file on the server */
1020 res = nfs4_atomic_open(dir, dentry, nd); 1366 nfs_block_sillyrename(dentry->d_parent);
1021 if (IS_ERR(res)) { 1367 inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr);
1022 error = PTR_ERR(res); 1368 if (IS_ERR(inode)) {
1023 switch (error) { 1369 nfs_unblock_sillyrename(dentry->d_parent);
1370 put_nfs_open_context(ctx);
1371 switch (PTR_ERR(inode)) {
1024 /* Make a negative dentry */ 1372 /* Make a negative dentry */
1025 case -ENOENT: 1373 case -ENOENT:
1374 d_add(dentry, NULL);
1026 res = NULL; 1375 res = NULL;
1027 goto out; 1376 goto out;
1028 /* This turned out not to be a regular file */ 1377 /* This turned out not to be a regular file */
1029 case -EISDIR:
1030 case -ENOTDIR: 1378 case -ENOTDIR:
1031 goto no_open; 1379 goto no_open;
1032 case -ELOOP: 1380 case -ELOOP:
1033 if (!(nd->intent.open.flags & O_NOFOLLOW)) 1381 if (!(nd->intent.open.flags & O_NOFOLLOW))
1034 goto no_open; 1382 goto no_open;
1383 /* case -EISDIR: */
1035 /* case -EINVAL: */ 1384 /* case -EINVAL: */
1036 default: 1385 default:
1386 res = ERR_CAST(inode);
1037 goto out; 1387 goto out;
1038 } 1388 }
1039 } else if (res != NULL) 1389 }
1390 res = d_add_unique(dentry, inode);
1391 nfs_unblock_sillyrename(dentry->d_parent);
1392 if (res != NULL) {
1393 dput(ctx->path.dentry);
1394 ctx->path.dentry = dget(res);
1040 dentry = res; 1395 dentry = res;
1396 }
1397 err = nfs_intent_set_file(nd, ctx);
1398 if (err < 0) {
1399 if (res != NULL)
1400 dput(res);
1401 return ERR_PTR(err);
1402 }
1041out: 1403out:
1404 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1042 return res; 1405 return res;
1043no_open: 1406no_open:
1044 return nfs_lookup(dir, dentry, nd); 1407 return nfs_lookup(dir, dentry, nd);
@@ -1049,12 +1412,15 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1049 struct dentry *parent = NULL; 1412 struct dentry *parent = NULL;
1050 struct inode *inode = dentry->d_inode; 1413 struct inode *inode = dentry->d_inode;
1051 struct inode *dir; 1414 struct inode *dir;
1415 struct nfs_open_context *ctx;
1052 int openflags, ret = 0; 1416 int openflags, ret = 0;
1053 1417
1054 if (!is_atomic_open(nd)) 1418 if (!is_atomic_open(nd) || d_mountpoint(dentry))
1055 goto no_open; 1419 goto no_open;
1420
1056 parent = dget_parent(dentry); 1421 parent = dget_parent(dentry);
1057 dir = parent->d_inode; 1422 dir = parent->d_inode;
1423
1058 /* We can't create new files in nfs_open_revalidate(), so we 1424 /* We can't create new files in nfs_open_revalidate(), so we
1059 * optimize away revalidation of negative dentries. 1425 * optimize away revalidation of negative dentries.
1060 */ 1426 */
@@ -1072,101 +1438,98 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1072 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) 1438 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
1073 goto no_open_dput; 1439 goto no_open_dput;
1074 /* We can't create new files, or truncate existing ones here */ 1440 /* We can't create new files, or truncate existing ones here */
1075 openflags &= ~(O_CREAT|O_TRUNC); 1441 openflags &= ~(O_CREAT|O_EXCL|O_TRUNC);
1076 1442
1443 ctx = nameidata_to_nfs_open_context(dentry, nd);
1444 ret = PTR_ERR(ctx);
1445 if (IS_ERR(ctx))
1446 goto out;
1077 /* 1447 /*
1078 * Note: we're not holding inode->i_mutex and so may be racing with 1448 * Note: we're not holding inode->i_mutex and so may be racing with
1079 * operations that change the directory. We therefore save the 1449 * operations that change the directory. We therefore save the
1080 * change attribute *before* we do the RPC call. 1450 * change attribute *before* we do the RPC call.
1081 */ 1451 */
1082 ret = nfs4_open_revalidate(dir, dentry, openflags, nd); 1452 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, NULL);
1453 if (IS_ERR(inode)) {
1454 ret = PTR_ERR(inode);
1455 switch (ret) {
1456 case -EPERM:
1457 case -EACCES:
1458 case -EDQUOT:
1459 case -ENOSPC:
1460 case -EROFS:
1461 goto out_put_ctx;
1462 default:
1463 goto out_drop;
1464 }
1465 }
1466 iput(inode);
1467 if (inode != dentry->d_inode)
1468 goto out_drop;
1469
1470 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1471 ret = nfs_intent_set_file(nd, ctx);
1472 if (ret >= 0)
1473 ret = 1;
1083out: 1474out:
1084 dput(parent); 1475 dput(parent);
1085 if (!ret)
1086 d_drop(dentry);
1087 return ret; 1476 return ret;
1477out_drop:
1478 d_drop(dentry);
1479 ret = 0;
1480out_put_ctx:
1481 put_nfs_open_context(ctx);
1482 goto out;
1483
1088no_open_dput: 1484no_open_dput:
1089 dput(parent); 1485 dput(parent);
1090no_open: 1486no_open:
1091 return nfs_lookup_revalidate(dentry, nd); 1487 return nfs_lookup_revalidate(dentry, nd);
1092} 1488}
1093#endif /* CONFIG_NFSV4 */
1094 1489
1095static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc) 1490static int nfs_open_create(struct inode *dir, struct dentry *dentry, int mode,
1491 struct nameidata *nd)
1096{ 1492{
1097 struct dentry *parent = desc->file->f_path.dentry; 1493 struct nfs_open_context *ctx = NULL;
1098 struct inode *dir = parent->d_inode; 1494 struct iattr attr;
1099 struct nfs_entry *entry = desc->entry; 1495 int error;
1100 struct dentry *dentry, *alias; 1496 int open_flags = 0;
1101 struct qstr name = {
1102 .name = entry->name,
1103 .len = entry->len,
1104 };
1105 struct inode *inode;
1106 unsigned long verf = nfs_save_change_attribute(dir);
1107 1497
1108 switch (name.len) { 1498 dfprintk(VFS, "NFS: create(%s/%ld), %s\n",
1109 case 2: 1499 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name);
1110 if (name.name[0] == '.' && name.name[1] == '.')
1111 return dget_parent(parent);
1112 break;
1113 case 1:
1114 if (name.name[0] == '.')
1115 return dget(parent);
1116 }
1117 1500
1118 spin_lock(&dir->i_lock); 1501 attr.ia_mode = mode;
1119 if (NFS_I(dir)->cache_validity & NFS_INO_INVALID_DATA) { 1502 attr.ia_valid = ATTR_MODE;
1120 spin_unlock(&dir->i_lock);
1121 return NULL;
1122 }
1123 spin_unlock(&dir->i_lock);
1124 1503
1125 name.hash = full_name_hash(name.name, name.len); 1504 if ((nd->flags & LOOKUP_CREATE) != 0) {
1126 dentry = d_lookup(parent, &name); 1505 open_flags = nd->intent.open.flags;
1127 if (dentry != NULL) {
1128 /* Is this a positive dentry that matches the readdir info? */
1129 if (dentry->d_inode != NULL &&
1130 (NFS_FILEID(dentry->d_inode) == entry->ino ||
1131 d_mountpoint(dentry))) {
1132 if (!desc->plus || entry->fh->size == 0)
1133 return dentry;
1134 if (nfs_compare_fh(NFS_FH(dentry->d_inode),
1135 entry->fh) == 0)
1136 goto out_renew;
1137 }
1138 /* No, so d_drop to allow one to be created */
1139 d_drop(dentry);
1140 dput(dentry);
1141 }
1142 if (!desc->plus || !(entry->fattr->valid & NFS_ATTR_FATTR))
1143 return NULL;
1144 if (name.len > NFS_SERVER(dir)->namelen)
1145 return NULL;
1146 /* Note: caller is already holding the dir->i_mutex! */
1147 dentry = d_alloc(parent, &name);
1148 if (dentry == NULL)
1149 return NULL;
1150 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
1151 inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr);
1152 if (IS_ERR(inode)) {
1153 dput(dentry);
1154 return NULL;
1155 }
1156 1506
1157 alias = d_materialise_unique(dentry, inode); 1507 ctx = nameidata_to_nfs_open_context(dentry, nd);
1158 if (alias != NULL) { 1508 error = PTR_ERR(ctx);
1159 dput(dentry); 1509 if (IS_ERR(ctx))
1160 if (IS_ERR(alias)) 1510 goto out_err_drop;
1161 return NULL;
1162 dentry = alias;
1163 } 1511 }
1164 1512
1165out_renew: 1513 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, ctx);
1166 nfs_set_verifier(dentry, verf); 1514 if (error != 0)
1167 return dentry; 1515 goto out_put_ctx;
1516 if (ctx != NULL) {
1517 error = nfs_intent_set_file(nd, ctx);
1518 if (error < 0)
1519 goto out_err;
1520 }
1521 return 0;
1522out_put_ctx:
1523 if (ctx != NULL)
1524 put_nfs_open_context(ctx);
1525out_err_drop:
1526 d_drop(dentry);
1527out_err:
1528 return error;
1168} 1529}
1169 1530
1531#endif /* CONFIG_NFSV4 */
1532
1170/* 1533/*
1171 * Code common to create, mkdir, and mknod. 1534 * Code common to create, mkdir, and mknod.
1172 */ 1535 */
@@ -1220,7 +1583,6 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
1220{ 1583{
1221 struct iattr attr; 1584 struct iattr attr;
1222 int error; 1585 int error;
1223 int open_flags = 0;
1224 1586
1225 dfprintk(VFS, "NFS: create(%s/%ld), %s\n", 1587 dfprintk(VFS, "NFS: create(%s/%ld), %s\n",
1226 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); 1588 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name);
@@ -1228,10 +1590,7 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
1228 attr.ia_mode = mode; 1590 attr.ia_mode = mode;
1229 attr.ia_valid = ATTR_MODE; 1591 attr.ia_valid = ATTR_MODE;
1230 1592
1231 if ((nd->flags & LOOKUP_CREATE) != 0) 1593 error = NFS_PROTO(dir)->create(dir, dentry, &attr, 0, NULL);
1232 open_flags = nd->intent.open.flags;
1233
1234 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd);
1235 if (error != 0) 1594 if (error != 0)
1236 goto out_err; 1595 goto out_err;
1237 return 0; 1596 return 0;
@@ -1313,76 +1672,6 @@ static int nfs_rmdir(struct inode *dir, struct dentry *dentry)
1313 return error; 1672 return error;
1314} 1673}
1315 1674
1316static int nfs_sillyrename(struct inode *dir, struct dentry *dentry)
1317{
1318 static unsigned int sillycounter;
1319 const int fileidsize = sizeof(NFS_FILEID(dentry->d_inode))*2;
1320 const int countersize = sizeof(sillycounter)*2;
1321 const int slen = sizeof(".nfs")+fileidsize+countersize-1;
1322 char silly[slen+1];
1323 struct qstr qsilly;
1324 struct dentry *sdentry;
1325 int error = -EIO;
1326
1327 dfprintk(VFS, "NFS: silly-rename(%s/%s, ct=%d)\n",
1328 dentry->d_parent->d_name.name, dentry->d_name.name,
1329 atomic_read(&dentry->d_count));
1330 nfs_inc_stats(dir, NFSIOS_SILLYRENAME);
1331
1332 /*
1333 * We don't allow a dentry to be silly-renamed twice.
1334 */
1335 error = -EBUSY;
1336 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
1337 goto out;
1338
1339 sprintf(silly, ".nfs%*.*Lx",
1340 fileidsize, fileidsize,
1341 (unsigned long long)NFS_FILEID(dentry->d_inode));
1342
1343 /* Return delegation in anticipation of the rename */
1344 nfs_inode_return_delegation(dentry->d_inode);
1345
1346 sdentry = NULL;
1347 do {
1348 char *suffix = silly + slen - countersize;
1349
1350 dput(sdentry);
1351 sillycounter++;
1352 sprintf(suffix, "%*.*x", countersize, countersize, sillycounter);
1353
1354 dfprintk(VFS, "NFS: trying to rename %s to %s\n",
1355 dentry->d_name.name, silly);
1356
1357 sdentry = lookup_one_len(silly, dentry->d_parent, slen);
1358 /*
1359 * N.B. Better to return EBUSY here ... it could be
1360 * dangerous to delete the file while it's in use.
1361 */
1362 if (IS_ERR(sdentry))
1363 goto out;
1364 } while(sdentry->d_inode != NULL); /* need negative lookup */
1365
1366 qsilly.name = silly;
1367 qsilly.len = strlen(silly);
1368 if (dentry->d_inode) {
1369 error = NFS_PROTO(dir)->rename(dir, &dentry->d_name,
1370 dir, &qsilly);
1371 nfs_mark_for_revalidate(dentry->d_inode);
1372 } else
1373 error = NFS_PROTO(dir)->rename(dir, &dentry->d_name,
1374 dir, &qsilly);
1375 if (!error) {
1376 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1377 d_move(dentry, sdentry);
1378 error = nfs_async_unlink(dir, dentry);
1379 /* If we return 0 we don't unlink */
1380 }
1381 dput(sdentry);
1382out:
1383 return error;
1384}
1385
1386/* 1675/*
1387 * Remove a file after making sure there are no pending writes, 1676 * Remove a file after making sure there are no pending writes,
1388 * and after checking that the file has only one user. 1677 * and after checking that the file has only one user.
@@ -1433,11 +1722,9 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1433 dfprintk(VFS, "NFS: unlink(%s/%ld, %s)\n", dir->i_sb->s_id, 1722 dfprintk(VFS, "NFS: unlink(%s/%ld, %s)\n", dir->i_sb->s_id,
1434 dir->i_ino, dentry->d_name.name); 1723 dir->i_ino, dentry->d_name.name);
1435 1724
1436 spin_lock(&dcache_lock);
1437 spin_lock(&dentry->d_lock); 1725 spin_lock(&dentry->d_lock);
1438 if (atomic_read(&dentry->d_count) > 1) { 1726 if (dentry->d_count > 1) {
1439 spin_unlock(&dentry->d_lock); 1727 spin_unlock(&dentry->d_lock);
1440 spin_unlock(&dcache_lock);
1441 /* Start asynchronous writeout of the inode */ 1728 /* Start asynchronous writeout of the inode */
1442 write_inode_now(dentry->d_inode, 0); 1729 write_inode_now(dentry->d_inode, 0);
1443 error = nfs_sillyrename(dir, dentry); 1730 error = nfs_sillyrename(dir, dentry);
@@ -1448,7 +1735,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1448 need_rehash = 1; 1735 need_rehash = 1;
1449 } 1736 }
1450 spin_unlock(&dentry->d_lock); 1737 spin_unlock(&dentry->d_lock);
1451 spin_unlock(&dcache_lock);
1452 error = nfs_safe_remove(dentry); 1738 error = nfs_safe_remove(dentry);
1453 if (!error || error == -ENOENT) { 1739 if (!error || error == -ENOENT) {
1454 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1740 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
@@ -1537,10 +1823,12 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
1537 old_dentry->d_parent->d_name.name, old_dentry->d_name.name, 1823 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1538 dentry->d_parent->d_name.name, dentry->d_name.name); 1824 dentry->d_parent->d_name.name, dentry->d_name.name);
1539 1825
1826 nfs_inode_return_delegation(inode);
1827
1540 d_drop(dentry); 1828 d_drop(dentry);
1541 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name); 1829 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name);
1542 if (error == 0) { 1830 if (error == 0) {
1543 atomic_inc(&inode->i_count); 1831 ihold(inode);
1544 d_add(dentry, inode); 1832 d_add(dentry, inode);
1545 } 1833 }
1546 return error; 1834 return error;
@@ -1578,65 +1866,48 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1578 struct dentry *dentry = NULL, *rehash = NULL; 1866 struct dentry *dentry = NULL, *rehash = NULL;
1579 int error = -EBUSY; 1867 int error = -EBUSY;
1580 1868
1581 /*
1582 * To prevent any new references to the target during the rename,
1583 * we unhash the dentry and free the inode in advance.
1584 */
1585 if (!d_unhashed(new_dentry)) {
1586 d_drop(new_dentry);
1587 rehash = new_dentry;
1588 }
1589
1590 dfprintk(VFS, "NFS: rename(%s/%s -> %s/%s, ct=%d)\n", 1869 dfprintk(VFS, "NFS: rename(%s/%s -> %s/%s, ct=%d)\n",
1591 old_dentry->d_parent->d_name.name, old_dentry->d_name.name, 1870 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1592 new_dentry->d_parent->d_name.name, new_dentry->d_name.name, 1871 new_dentry->d_parent->d_name.name, new_dentry->d_name.name,
1593 atomic_read(&new_dentry->d_count)); 1872 new_dentry->d_count);
1594 1873
1595 /* 1874 /*
1596 * First check whether the target is busy ... we can't 1875 * For non-directories, check whether the target is busy and if so,
1597 * safely do _any_ rename if the target is in use. 1876 * make a copy of the dentry and then do a silly-rename. If the
1598 * 1877 * silly-rename succeeds, the copied dentry is hashed and becomes
1599 * For files, make a copy of the dentry and then do a 1878 * the new target.
1600 * silly-rename. If the silly-rename succeeds, the
1601 * copied dentry is hashed and becomes the new target.
1602 */ 1879 */
1603 if (!new_inode) 1880 if (new_inode && !S_ISDIR(new_inode->i_mode)) {
1604 goto go_ahead; 1881 /*
1605 if (S_ISDIR(new_inode->i_mode)) { 1882 * To prevent any new references to the target during the
1606 error = -EISDIR; 1883 * rename, we unhash the dentry in advance.
1607 if (!S_ISDIR(old_inode->i_mode)) 1884 */
1608 goto out; 1885 if (!d_unhashed(new_dentry)) {
1609 } else if (atomic_read(&new_dentry->d_count) > 2) { 1886 d_drop(new_dentry);
1610 int err; 1887 rehash = new_dentry;
1611 /* copy the target dentry's name */ 1888 }
1612 dentry = d_alloc(new_dentry->d_parent, 1889
1613 &new_dentry->d_name); 1890 if (new_dentry->d_count > 2) {
1614 if (!dentry) 1891 int err;
1615 goto out;
1616 1892
1617 /* silly-rename the existing target ... */ 1893 /* copy the target dentry's name */
1618 err = nfs_sillyrename(new_dir, new_dentry); 1894 dentry = d_alloc(new_dentry->d_parent,
1619 if (!err) { 1895 &new_dentry->d_name);
1620 new_dentry = rehash = dentry; 1896 if (!dentry)
1897 goto out;
1898
1899 /* silly-rename the existing target ... */
1900 err = nfs_sillyrename(new_dir, new_dentry);
1901 if (err)
1902 goto out;
1903
1904 new_dentry = dentry;
1905 rehash = NULL;
1621 new_inode = NULL; 1906 new_inode = NULL;
1622 /* instantiate the replacement target */ 1907 }
1623 d_instantiate(new_dentry, NULL);
1624 } else if (atomic_read(&new_dentry->d_count) > 1)
1625 /* dentry still busy? */
1626 goto out;
1627 } 1908 }
1628 1909
1629go_ahead:
1630 /*
1631 * ... prune child dentries and writebacks if needed.
1632 */
1633 if (atomic_read(&old_dentry->d_count) > 1) {
1634 if (S_ISREG(old_inode->i_mode))
1635 nfs_wb_all(old_inode);
1636 shrink_dcache_parent(old_dentry);
1637 }
1638 nfs_inode_return_delegation(old_inode); 1910 nfs_inode_return_delegation(old_inode);
1639
1640 if (new_inode != NULL) 1911 if (new_inode != NULL)
1641 nfs_inode_return_delegation(new_inode); 1912 nfs_inode_return_delegation(new_inode);
1642 1913
@@ -1674,28 +1945,33 @@ static void nfs_access_free_entry(struct nfs_access_entry *entry)
1674 smp_mb__after_atomic_dec(); 1945 smp_mb__after_atomic_dec();
1675} 1946}
1676 1947
1677int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask) 1948static void nfs_access_free_list(struct list_head *head)
1949{
1950 struct nfs_access_entry *cache;
1951
1952 while (!list_empty(head)) {
1953 cache = list_entry(head->next, struct nfs_access_entry, lru);
1954 list_del(&cache->lru);
1955 nfs_access_free_entry(cache);
1956 }
1957}
1958
1959int nfs_access_cache_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
1678{ 1960{
1679 LIST_HEAD(head); 1961 LIST_HEAD(head);
1680 struct nfs_inode *nfsi; 1962 struct nfs_inode *nfsi, *next;
1681 struct nfs_access_entry *cache; 1963 struct nfs_access_entry *cache;
1682 1964
1683restart: 1965 if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
1966 return (nr_to_scan == 0) ? 0 : -1;
1967
1684 spin_lock(&nfs_access_lru_lock); 1968 spin_lock(&nfs_access_lru_lock);
1685 list_for_each_entry(nfsi, &nfs_access_lru_list, access_cache_inode_lru) { 1969 list_for_each_entry_safe(nfsi, next, &nfs_access_lru_list, access_cache_inode_lru) {
1686 struct rw_semaphore *s_umount;
1687 struct inode *inode; 1970 struct inode *inode;
1688 1971
1689 if (nr_to_scan-- == 0) 1972 if (nr_to_scan-- == 0)
1690 break; 1973 break;
1691 s_umount = &nfsi->vfs_inode.i_sb->s_umount; 1974 inode = &nfsi->vfs_inode;
1692 if (!down_read_trylock(s_umount))
1693 continue;
1694 inode = igrab(&nfsi->vfs_inode);
1695 if (inode == NULL) {
1696 up_read(s_umount);
1697 continue;
1698 }
1699 spin_lock(&inode->i_lock); 1975 spin_lock(&inode->i_lock);
1700 if (list_empty(&nfsi->access_cache_entry_lru)) 1976 if (list_empty(&nfsi->access_cache_entry_lru))
1701 goto remove_lru_entry; 1977 goto remove_lru_entry;
@@ -1709,61 +1985,48 @@ restart:
1709 else { 1985 else {
1710remove_lru_entry: 1986remove_lru_entry:
1711 list_del_init(&nfsi->access_cache_inode_lru); 1987 list_del_init(&nfsi->access_cache_inode_lru);
1988 smp_mb__before_clear_bit();
1712 clear_bit(NFS_INO_ACL_LRU_SET, &nfsi->flags); 1989 clear_bit(NFS_INO_ACL_LRU_SET, &nfsi->flags);
1990 smp_mb__after_clear_bit();
1713 } 1991 }
1714 spin_unlock(&inode->i_lock); 1992 spin_unlock(&inode->i_lock);
1715 spin_unlock(&nfs_access_lru_lock);
1716 iput(inode);
1717 up_read(s_umount);
1718 goto restart;
1719 } 1993 }
1720 spin_unlock(&nfs_access_lru_lock); 1994 spin_unlock(&nfs_access_lru_lock);
1721 while (!list_empty(&head)) { 1995 nfs_access_free_list(&head);
1722 cache = list_entry(head.next, struct nfs_access_entry, lru);
1723 list_del(&cache->lru);
1724 nfs_access_free_entry(cache);
1725 }
1726 return (atomic_long_read(&nfs_access_nr_entries) / 100) * sysctl_vfs_cache_pressure; 1996 return (atomic_long_read(&nfs_access_nr_entries) / 100) * sysctl_vfs_cache_pressure;
1727} 1997}
1728 1998
1729static void __nfs_access_zap_cache(struct inode *inode) 1999static void __nfs_access_zap_cache(struct nfs_inode *nfsi, struct list_head *head)
1730{ 2000{
1731 struct nfs_inode *nfsi = NFS_I(inode);
1732 struct rb_root *root_node = &nfsi->access_cache; 2001 struct rb_root *root_node = &nfsi->access_cache;
1733 struct rb_node *n, *dispose = NULL; 2002 struct rb_node *n;
1734 struct nfs_access_entry *entry; 2003 struct nfs_access_entry *entry;
1735 2004
1736 /* Unhook entries from the cache */ 2005 /* Unhook entries from the cache */
1737 while ((n = rb_first(root_node)) != NULL) { 2006 while ((n = rb_first(root_node)) != NULL) {
1738 entry = rb_entry(n, struct nfs_access_entry, rb_node); 2007 entry = rb_entry(n, struct nfs_access_entry, rb_node);
1739 rb_erase(n, root_node); 2008 rb_erase(n, root_node);
1740 list_del(&entry->lru); 2009 list_move(&entry->lru, head);
1741 n->rb_left = dispose;
1742 dispose = n;
1743 } 2010 }
1744 nfsi->cache_validity &= ~NFS_INO_INVALID_ACCESS; 2011 nfsi->cache_validity &= ~NFS_INO_INVALID_ACCESS;
1745 spin_unlock(&inode->i_lock);
1746
1747 /* Now kill them all! */
1748 while (dispose != NULL) {
1749 n = dispose;
1750 dispose = n->rb_left;
1751 nfs_access_free_entry(rb_entry(n, struct nfs_access_entry, rb_node));
1752 }
1753} 2012}
1754 2013
1755void nfs_access_zap_cache(struct inode *inode) 2014void nfs_access_zap_cache(struct inode *inode)
1756{ 2015{
2016 LIST_HEAD(head);
2017
2018 if (test_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags) == 0)
2019 return;
1757 /* Remove from global LRU init */ 2020 /* Remove from global LRU init */
1758 if (test_and_clear_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) { 2021 spin_lock(&nfs_access_lru_lock);
1759 spin_lock(&nfs_access_lru_lock); 2022 if (test_and_clear_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags))
1760 list_del_init(&NFS_I(inode)->access_cache_inode_lru); 2023 list_del_init(&NFS_I(inode)->access_cache_inode_lru);
1761 spin_unlock(&nfs_access_lru_lock);
1762 }
1763 2024
1764 spin_lock(&inode->i_lock); 2025 spin_lock(&inode->i_lock);
1765 /* This will release the spinlock */ 2026 __nfs_access_zap_cache(NFS_I(inode), &head);
1766 __nfs_access_zap_cache(inode); 2027 spin_unlock(&inode->i_lock);
2028 spin_unlock(&nfs_access_lru_lock);
2029 nfs_access_free_list(&head);
1767} 2030}
1768 2031
1769static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, struct rpc_cred *cred) 2032static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, struct rpc_cred *cred)
@@ -1796,7 +2059,7 @@ static int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, str
1796 cache = nfs_access_search_rbtree(inode, cred); 2059 cache = nfs_access_search_rbtree(inode, cred);
1797 if (cache == NULL) 2060 if (cache == NULL)
1798 goto out; 2061 goto out;
1799 if (!nfs_have_delegation(inode, FMODE_READ) && 2062 if (!nfs_have_delegated_attributes(inode) &&
1800 !time_in_range_open(jiffies, cache->jiffies, cache->jiffies + nfsi->attrtimeo)) 2063 !time_in_range_open(jiffies, cache->jiffies, cache->jiffies + nfsi->attrtimeo))
1801 goto out_stale; 2064 goto out_stale;
1802 res->jiffies = cache->jiffies; 2065 res->jiffies = cache->jiffies;
@@ -1814,8 +2077,8 @@ out_stale:
1814 nfs_access_free_entry(cache); 2077 nfs_access_free_entry(cache);
1815 return -ENOENT; 2078 return -ENOENT;
1816out_zap: 2079out_zap:
1817 /* This will release the spinlock */ 2080 spin_unlock(&inode->i_lock);
1818 __nfs_access_zap_cache(inode); 2081 nfs_access_zap_cache(inode);
1819 return -ENOENT; 2082 return -ENOENT;
1820} 2083}
1821 2084
@@ -1870,9 +2133,11 @@ static void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *s
1870 smp_mb__after_atomic_inc(); 2133 smp_mb__after_atomic_inc();
1871 2134
1872 /* Add inode to global LRU list */ 2135 /* Add inode to global LRU list */
1873 if (!test_and_set_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) { 2136 if (!test_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) {
1874 spin_lock(&nfs_access_lru_lock); 2137 spin_lock(&nfs_access_lru_lock);
1875 list_add_tail(&NFS_I(inode)->access_cache_inode_lru, &nfs_access_lru_list); 2138 if (!test_and_set_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags))
2139 list_add_tail(&NFS_I(inode)->access_cache_inode_lru,
2140 &nfs_access_lru_list);
1876 spin_unlock(&nfs_access_lru_lock); 2141 spin_unlock(&nfs_access_lru_lock);
1877 } 2142 }
1878} 2143}
@@ -1924,17 +2189,20 @@ int nfs_may_open(struct inode *inode, struct rpc_cred *cred, int openflags)
1924 return nfs_do_access(inode, cred, nfs_open_permission_mask(openflags)); 2189 return nfs_do_access(inode, cred, nfs_open_permission_mask(openflags));
1925} 2190}
1926 2191
1927int nfs_permission(struct inode *inode, int mask) 2192int nfs_permission(struct inode *inode, int mask, unsigned int flags)
1928{ 2193{
1929 struct rpc_cred *cred; 2194 struct rpc_cred *cred;
1930 int res = 0; 2195 int res = 0;
1931 2196
2197 if (flags & IPERM_FLAG_RCU)
2198 return -ECHILD;
2199
1932 nfs_inc_stats(inode, NFSIOS_VFSACCESS); 2200 nfs_inc_stats(inode, NFSIOS_VFSACCESS);
1933 2201
1934 if ((mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == 0) 2202 if ((mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == 0)
1935 goto out; 2203 goto out;
1936 /* Is this sys_access() ? */ 2204 /* Is this sys_access() ? */
1937 if (mask & MAY_ACCESS) 2205 if (mask & (MAY_ACCESS | MAY_CHDIR))
1938 goto force_lookup; 2206 goto force_lookup;
1939 2207
1940 switch (inode->i_mode & S_IFMT) { 2208 switch (inode->i_mode & S_IFMT) {
@@ -1976,7 +2244,7 @@ out:
1976out_notsup: 2244out_notsup:
1977 res = nfs_revalidate_inode(NFS_SERVER(inode), inode); 2245 res = nfs_revalidate_inode(NFS_SERVER(inode), inode);
1978 if (res == 0) 2246 if (res == 0)
1979 res = generic_permission(inode, mask, NULL); 2247 res = generic_permission(inode, mask, flags, NULL);
1980 goto out; 2248 goto out;
1981} 2249}
1982 2250
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 489fc01a3204..e6ace0d93c71 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -44,6 +44,7 @@
44#include <linux/file.h> 44#include <linux/file.h>
45#include <linux/pagemap.h> 45#include <linux/pagemap.h>
46#include <linux/kref.h> 46#include <linux/kref.h>
47#include <linux/slab.h>
47 48
48#include <linux/nfs_fs.h> 49#include <linux/nfs_fs.h>
49#include <linux/nfs_page.h> 50#include <linux/nfs_page.h>
@@ -68,6 +69,7 @@ struct nfs_direct_req {
68 69
69 /* I/O parameters */ 70 /* I/O parameters */
70 struct nfs_open_context *ctx; /* file open context info */ 71 struct nfs_open_context *ctx; /* file open context info */
72 struct nfs_lock_context *l_ctx; /* Lock context info */
71 struct kiocb * iocb; /* controlling i/o request */ 73 struct kiocb * iocb; /* controlling i/o request */
72 struct inode * inode; /* target file of i/o */ 74 struct inode * inode; /* target file of i/o */
73 75
@@ -159,6 +161,7 @@ static inline struct nfs_direct_req *nfs_direct_req_alloc(void)
159 INIT_LIST_HEAD(&dreq->rewrite_list); 161 INIT_LIST_HEAD(&dreq->rewrite_list);
160 dreq->iocb = NULL; 162 dreq->iocb = NULL;
161 dreq->ctx = NULL; 163 dreq->ctx = NULL;
164 dreq->l_ctx = NULL;
162 spin_lock_init(&dreq->lock); 165 spin_lock_init(&dreq->lock);
163 atomic_set(&dreq->io_count, 0); 166 atomic_set(&dreq->io_count, 0);
164 dreq->count = 0; 167 dreq->count = 0;
@@ -172,6 +175,8 @@ static void nfs_direct_req_free(struct kref *kref)
172{ 175{
173 struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref); 176 struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref);
174 177
178 if (dreq->l_ctx != NULL)
179 nfs_put_lock_context(dreq->l_ctx);
175 if (dreq->ctx != NULL) 180 if (dreq->ctx != NULL)
176 put_nfs_open_context(dreq->ctx); 181 put_nfs_open_context(dreq->ctx);
177 kmem_cache_free(nfs_direct_cachep, dreq); 182 kmem_cache_free(nfs_direct_cachep, dreq);
@@ -255,7 +260,7 @@ static void nfs_direct_read_release(void *calldata)
255 260
256 if (put_dreq(dreq)) 261 if (put_dreq(dreq))
257 nfs_direct_complete(dreq); 262 nfs_direct_complete(dreq);
258 nfs_readdata_release(calldata); 263 nfs_readdata_free(data);
259} 264}
260 265
261static const struct rpc_call_ops nfs_read_direct_ops = { 266static const struct rpc_call_ops nfs_read_direct_ops = {
@@ -314,14 +319,14 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
314 data->npages, 1, 0, data->pagevec, NULL); 319 data->npages, 1, 0, data->pagevec, NULL);
315 up_read(&current->mm->mmap_sem); 320 up_read(&current->mm->mmap_sem);
316 if (result < 0) { 321 if (result < 0) {
317 nfs_readdata_release(data); 322 nfs_readdata_free(data);
318 break; 323 break;
319 } 324 }
320 if ((unsigned)result < data->npages) { 325 if ((unsigned)result < data->npages) {
321 bytes = result * PAGE_SIZE; 326 bytes = result * PAGE_SIZE;
322 if (bytes <= pgbase) { 327 if (bytes <= pgbase) {
323 nfs_direct_release_pages(data->pagevec, result); 328 nfs_direct_release_pages(data->pagevec, result);
324 nfs_readdata_release(data); 329 nfs_readdata_free(data);
325 break; 330 break;
326 } 331 }
327 bytes -= pgbase; 332 bytes -= pgbase;
@@ -334,7 +339,8 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
334 data->inode = inode; 339 data->inode = inode;
335 data->cred = msg.rpc_cred; 340 data->cred = msg.rpc_cred;
336 data->args.fh = NFS_FH(inode); 341 data->args.fh = NFS_FH(inode);
337 data->args.context = get_nfs_open_context(ctx); 342 data->args.context = ctx;
343 data->args.lock_context = dreq->l_ctx;
338 data->args.offset = pos; 344 data->args.offset = pos;
339 data->args.pgbase = pgbase; 345 data->args.pgbase = pgbase;
340 data->args.pages = data->pagevec; 346 data->args.pages = data->pagevec;
@@ -342,6 +348,7 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
342 data->res.fattr = &data->fattr; 348 data->res.fattr = &data->fattr;
343 data->res.eof = 0; 349 data->res.eof = 0;
344 data->res.count = bytes; 350 data->res.count = bytes;
351 nfs_fattr_init(&data->fattr);
345 msg.rpc_argp = &data->args; 352 msg.rpc_argp = &data->args;
346 msg.rpc_resp = &data->res; 353 msg.rpc_resp = &data->res;
347 354
@@ -414,24 +421,28 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
414static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov, 421static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
415 unsigned long nr_segs, loff_t pos) 422 unsigned long nr_segs, loff_t pos)
416{ 423{
417 ssize_t result = 0; 424 ssize_t result = -ENOMEM;
418 struct inode *inode = iocb->ki_filp->f_mapping->host; 425 struct inode *inode = iocb->ki_filp->f_mapping->host;
419 struct nfs_direct_req *dreq; 426 struct nfs_direct_req *dreq;
420 427
421 dreq = nfs_direct_req_alloc(); 428 dreq = nfs_direct_req_alloc();
422 if (!dreq) 429 if (dreq == NULL)
423 return -ENOMEM; 430 goto out;
424 431
425 dreq->inode = inode; 432 dreq->inode = inode;
426 dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); 433 dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
434 dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
435 if (dreq->l_ctx == NULL)
436 goto out_release;
427 if (!is_sync_kiocb(iocb)) 437 if (!is_sync_kiocb(iocb))
428 dreq->iocb = iocb; 438 dreq->iocb = iocb;
429 439
430 result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos); 440 result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos);
431 if (!result) 441 if (!result)
432 result = nfs_direct_wait(dreq); 442 result = nfs_direct_wait(dreq);
443out_release:
433 nfs_direct_req_release(dreq); 444 nfs_direct_req_release(dreq);
434 445out:
435 return result; 446 return result;
436} 447}
437 448
@@ -441,7 +452,7 @@ static void nfs_direct_free_writedata(struct nfs_direct_req *dreq)
441 struct nfs_write_data *data = list_entry(dreq->rewrite_list.next, struct nfs_write_data, pages); 452 struct nfs_write_data *data = list_entry(dreq->rewrite_list.next, struct nfs_write_data, pages);
442 list_del(&data->pages); 453 list_del(&data->pages);
443 nfs_direct_release_pages(data->pagevec, data->npages); 454 nfs_direct_release_pages(data->pagevec, data->npages);
444 nfs_writedata_release(data); 455 nfs_writedata_free(data);
445 } 456 }
446} 457}
447 458
@@ -457,6 +468,7 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
457 }; 468 };
458 struct rpc_task_setup task_setup_data = { 469 struct rpc_task_setup task_setup_data = {
459 .rpc_client = NFS_CLIENT(inode), 470 .rpc_client = NFS_CLIENT(inode),
471 .rpc_message = &msg,
460 .callback_ops = &nfs_write_direct_ops, 472 .callback_ops = &nfs_write_direct_ops,
461 .workqueue = nfsiod_workqueue, 473 .workqueue = nfsiod_workqueue,
462 .flags = RPC_TASK_ASYNC, 474 .flags = RPC_TASK_ASYNC,
@@ -534,7 +546,7 @@ static void nfs_direct_commit_release(void *calldata)
534 546
535 dprintk("NFS: %5u commit returned %d\n", data->task.tk_pid, status); 547 dprintk("NFS: %5u commit returned %d\n", data->task.tk_pid, status);
536 nfs_direct_write_complete(dreq, data->inode); 548 nfs_direct_write_complete(dreq, data->inode);
537 nfs_commitdata_release(calldata); 549 nfs_commit_free(data);
538} 550}
539 551
540static const struct rpc_call_ops nfs_commit_direct_ops = { 552static const struct rpc_call_ops nfs_commit_direct_ops = {
@@ -570,10 +582,12 @@ static void nfs_direct_commit_schedule(struct nfs_direct_req *dreq)
570 data->args.fh = NFS_FH(data->inode); 582 data->args.fh = NFS_FH(data->inode);
571 data->args.offset = 0; 583 data->args.offset = 0;
572 data->args.count = 0; 584 data->args.count = 0;
573 data->args.context = get_nfs_open_context(dreq->ctx); 585 data->args.context = dreq->ctx;
586 data->args.lock_context = dreq->l_ctx;
574 data->res.count = 0; 587 data->res.count = 0;
575 data->res.fattr = &data->fattr; 588 data->res.fattr = &data->fattr;
576 data->res.verf = &data->verf; 589 data->res.verf = &data->verf;
590 nfs_fattr_init(&data->fattr);
577 591
578 NFS_PROTO(data->inode)->commit_setup(data, &msg); 592 NFS_PROTO(data->inode)->commit_setup(data, &msg);
579 593
@@ -734,14 +748,14 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
734 data->npages, 0, 0, data->pagevec, NULL); 748 data->npages, 0, 0, data->pagevec, NULL);
735 up_read(&current->mm->mmap_sem); 749 up_read(&current->mm->mmap_sem);
736 if (result < 0) { 750 if (result < 0) {
737 nfs_writedata_release(data); 751 nfs_writedata_free(data);
738 break; 752 break;
739 } 753 }
740 if ((unsigned)result < data->npages) { 754 if ((unsigned)result < data->npages) {
741 bytes = result * PAGE_SIZE; 755 bytes = result * PAGE_SIZE;
742 if (bytes <= pgbase) { 756 if (bytes <= pgbase) {
743 nfs_direct_release_pages(data->pagevec, result); 757 nfs_direct_release_pages(data->pagevec, result);
744 nfs_writedata_release(data); 758 nfs_writedata_free(data);
745 break; 759 break;
746 } 760 }
747 bytes -= pgbase; 761 bytes -= pgbase;
@@ -756,7 +770,8 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
756 data->inode = inode; 770 data->inode = inode;
757 data->cred = msg.rpc_cred; 771 data->cred = msg.rpc_cred;
758 data->args.fh = NFS_FH(inode); 772 data->args.fh = NFS_FH(inode);
759 data->args.context = get_nfs_open_context(ctx); 773 data->args.context = ctx;
774 data->args.lock_context = dreq->l_ctx;
760 data->args.offset = pos; 775 data->args.offset = pos;
761 data->args.pgbase = pgbase; 776 data->args.pgbase = pgbase;
762 data->args.pages = data->pagevec; 777 data->args.pages = data->pagevec;
@@ -765,6 +780,7 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
765 data->res.fattr = &data->fattr; 780 data->res.fattr = &data->fattr;
766 data->res.count = bytes; 781 data->res.count = bytes;
767 data->res.verf = &data->verf; 782 data->res.verf = &data->verf;
783 nfs_fattr_init(&data->fattr);
768 784
769 task_setup_data.task = &data->task; 785 task_setup_data.task = &data->task;
770 task_setup_data.callback_data = data; 786 task_setup_data.callback_data = data;
@@ -840,7 +856,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
840 unsigned long nr_segs, loff_t pos, 856 unsigned long nr_segs, loff_t pos,
841 size_t count) 857 size_t count)
842{ 858{
843 ssize_t result = 0; 859 ssize_t result = -ENOMEM;
844 struct inode *inode = iocb->ki_filp->f_mapping->host; 860 struct inode *inode = iocb->ki_filp->f_mapping->host;
845 struct nfs_direct_req *dreq; 861 struct nfs_direct_req *dreq;
846 size_t wsize = NFS_SERVER(inode)->wsize; 862 size_t wsize = NFS_SERVER(inode)->wsize;
@@ -848,22 +864,26 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
848 864
849 dreq = nfs_direct_req_alloc(); 865 dreq = nfs_direct_req_alloc();
850 if (!dreq) 866 if (!dreq)
851 return -ENOMEM; 867 goto out;
852 nfs_alloc_commit_data(dreq); 868 nfs_alloc_commit_data(dreq);
853 869
854 if (dreq->commit_data == NULL || count < wsize) 870 if (dreq->commit_data == NULL || count <= wsize)
855 sync = NFS_FILE_SYNC; 871 sync = NFS_FILE_SYNC;
856 872
857 dreq->inode = inode; 873 dreq->inode = inode;
858 dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); 874 dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
875 dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
876 if (dreq->l_ctx == NULL)
877 goto out_release;
859 if (!is_sync_kiocb(iocb)) 878 if (!is_sync_kiocb(iocb))
860 dreq->iocb = iocb; 879 dreq->iocb = iocb;
861 880
862 result = nfs_direct_write_schedule_iovec(dreq, iov, nr_segs, pos, sync); 881 result = nfs_direct_write_schedule_iovec(dreq, iov, nr_segs, pos, sync);
863 if (!result) 882 if (!result)
864 result = nfs_direct_wait(dreq); 883 result = nfs_direct_wait(dreq);
884out_release:
865 nfs_direct_req_release(dreq); 885 nfs_direct_req_release(dreq);
866 886out:
867 return result; 887 return result;
868} 888}
869 889
@@ -934,9 +954,6 @@ out:
934 * back into its cache. We let the server do generic write 954 * back into its cache. We let the server do generic write
935 * parameter checking and report problems. 955 * parameter checking and report problems.
936 * 956 *
937 * We also avoid an unnecessary invocation of generic_osync_inode(),
938 * as it is fairly meaningless to sync the metadata of an NFS file.
939 *
940 * We eliminate local atime updates, see direct read above. 957 * We eliminate local atime updates, see direct read above.
941 * 958 *
942 * We avoid unnecessary page cache invalidations for normal cached 959 * We avoid unnecessary page cache invalidations for normal cached
diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
new file mode 100644
index 000000000000..a6e711ad130f
--- /dev/null
+++ b/fs/nfs/dns_resolve.c
@@ -0,0 +1,372 @@
1/*
2 * linux/fs/nfs/dns_resolve.c
3 *
4 * Copyright (c) 2009 Trond Myklebust <Trond.Myklebust@netapp.com>
5 *
6 * Resolves DNS hostnames into valid ip addresses
7 */
8
9#ifdef CONFIG_NFS_USE_KERNEL_DNS
10
11#include <linux/sunrpc/clnt.h>
12#include <linux/dns_resolver.h>
13
14ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
15 struct sockaddr *sa, size_t salen)
16{
17 ssize_t ret;
18 char *ip_addr = NULL;
19 int ip_len;
20
21 ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
22 if (ip_len > 0)
23 ret = rpc_pton(ip_addr, ip_len, sa, salen);
24 else
25 ret = -ESRCH;
26 kfree(ip_addr);
27 return ret;
28}
29
30#else
31
32#include <linux/hash.h>
33#include <linux/string.h>
34#include <linux/kmod.h>
35#include <linux/slab.h>
36#include <linux/module.h>
37#include <linux/socket.h>
38#include <linux/seq_file.h>
39#include <linux/inet.h>
40#include <linux/sunrpc/clnt.h>
41#include <linux/sunrpc/cache.h>
42#include <linux/sunrpc/svcauth.h>
43
44#include "dns_resolve.h"
45#include "cache_lib.h"
46
47#define NFS_DNS_HASHBITS 4
48#define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS)
49
50static struct cache_head *nfs_dns_table[NFS_DNS_HASHTBL_SIZE];
51
52struct nfs_dns_ent {
53 struct cache_head h;
54
55 char *hostname;
56 size_t namelen;
57
58 struct sockaddr_storage addr;
59 size_t addrlen;
60};
61
62
63static void nfs_dns_ent_update(struct cache_head *cnew,
64 struct cache_head *ckey)
65{
66 struct nfs_dns_ent *new;
67 struct nfs_dns_ent *key;
68
69 new = container_of(cnew, struct nfs_dns_ent, h);
70 key = container_of(ckey, struct nfs_dns_ent, h);
71
72 memcpy(&new->addr, &key->addr, key->addrlen);
73 new->addrlen = key->addrlen;
74}
75
76static void nfs_dns_ent_init(struct cache_head *cnew,
77 struct cache_head *ckey)
78{
79 struct nfs_dns_ent *new;
80 struct nfs_dns_ent *key;
81
82 new = container_of(cnew, struct nfs_dns_ent, h);
83 key = container_of(ckey, struct nfs_dns_ent, h);
84
85 kfree(new->hostname);
86 new->hostname = kstrndup(key->hostname, key->namelen, GFP_KERNEL);
87 if (new->hostname) {
88 new->namelen = key->namelen;
89 nfs_dns_ent_update(cnew, ckey);
90 } else {
91 new->namelen = 0;
92 new->addrlen = 0;
93 }
94}
95
96static void nfs_dns_ent_put(struct kref *ref)
97{
98 struct nfs_dns_ent *item;
99
100 item = container_of(ref, struct nfs_dns_ent, h.ref);
101 kfree(item->hostname);
102 kfree(item);
103}
104
105static struct cache_head *nfs_dns_ent_alloc(void)
106{
107 struct nfs_dns_ent *item = kmalloc(sizeof(*item), GFP_KERNEL);
108
109 if (item != NULL) {
110 item->hostname = NULL;
111 item->namelen = 0;
112 item->addrlen = 0;
113 return &item->h;
114 }
115 return NULL;
116};
117
118static unsigned int nfs_dns_hash(const struct nfs_dns_ent *key)
119{
120 return hash_str(key->hostname, NFS_DNS_HASHBITS);
121}
122
123static void nfs_dns_request(struct cache_detail *cd,
124 struct cache_head *ch,
125 char **bpp, int *blen)
126{
127 struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
128
129 qword_add(bpp, blen, key->hostname);
130 (*bpp)[-1] = '\n';
131}
132
133static int nfs_dns_upcall(struct cache_detail *cd,
134 struct cache_head *ch)
135{
136 struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
137 int ret;
138
139 ret = nfs_cache_upcall(cd, key->hostname);
140 if (ret)
141 ret = sunrpc_cache_pipe_upcall(cd, ch, nfs_dns_request);
142 return ret;
143}
144
145static int nfs_dns_match(struct cache_head *ca,
146 struct cache_head *cb)
147{
148 struct nfs_dns_ent *a;
149 struct nfs_dns_ent *b;
150
151 a = container_of(ca, struct nfs_dns_ent, h);
152 b = container_of(cb, struct nfs_dns_ent, h);
153
154 if (a->namelen == 0 || a->namelen != b->namelen)
155 return 0;
156 return memcmp(a->hostname, b->hostname, a->namelen) == 0;
157}
158
159static int nfs_dns_show(struct seq_file *m, struct cache_detail *cd,
160 struct cache_head *h)
161{
162 struct nfs_dns_ent *item;
163 long ttl;
164
165 if (h == NULL) {
166 seq_puts(m, "# ip address hostname ttl\n");
167 return 0;
168 }
169 item = container_of(h, struct nfs_dns_ent, h);
170 ttl = item->h.expiry_time - seconds_since_boot();
171 if (ttl < 0)
172 ttl = 0;
173
174 if (!test_bit(CACHE_NEGATIVE, &h->flags)) {
175 char buf[INET6_ADDRSTRLEN+IPV6_SCOPE_ID_LEN+1];
176
177 rpc_ntop((struct sockaddr *)&item->addr, buf, sizeof(buf));
178 seq_printf(m, "%15s ", buf);
179 } else
180 seq_puts(m, "<none> ");
181 seq_printf(m, "%15s %ld\n", item->hostname, ttl);
182 return 0;
183}
184
185static struct nfs_dns_ent *nfs_dns_lookup(struct cache_detail *cd,
186 struct nfs_dns_ent *key)
187{
188 struct cache_head *ch;
189
190 ch = sunrpc_cache_lookup(cd,
191 &key->h,
192 nfs_dns_hash(key));
193 if (!ch)
194 return NULL;
195 return container_of(ch, struct nfs_dns_ent, h);
196}
197
198static struct nfs_dns_ent *nfs_dns_update(struct cache_detail *cd,
199 struct nfs_dns_ent *new,
200 struct nfs_dns_ent *key)
201{
202 struct cache_head *ch;
203
204 ch = sunrpc_cache_update(cd,
205 &new->h, &key->h,
206 nfs_dns_hash(key));
207 if (!ch)
208 return NULL;
209 return container_of(ch, struct nfs_dns_ent, h);
210}
211
212static int nfs_dns_parse(struct cache_detail *cd, char *buf, int buflen)
213{
214 char buf1[NFS_DNS_HOSTNAME_MAXLEN+1];
215 struct nfs_dns_ent key, *item;
216 unsigned long ttl;
217 ssize_t len;
218 int ret = -EINVAL;
219
220 if (buf[buflen-1] != '\n')
221 goto out;
222 buf[buflen-1] = '\0';
223
224 len = qword_get(&buf, buf1, sizeof(buf1));
225 if (len <= 0)
226 goto out;
227 key.addrlen = rpc_pton(buf1, len,
228 (struct sockaddr *)&key.addr,
229 sizeof(key.addr));
230
231 len = qword_get(&buf, buf1, sizeof(buf1));
232 if (len <= 0)
233 goto out;
234
235 key.hostname = buf1;
236 key.namelen = len;
237 memset(&key.h, 0, sizeof(key.h));
238
239 ttl = get_expiry(&buf);
240 if (ttl == 0)
241 goto out;
242 key.h.expiry_time = ttl + seconds_since_boot();
243
244 ret = -ENOMEM;
245 item = nfs_dns_lookup(cd, &key);
246 if (item == NULL)
247 goto out;
248
249 if (key.addrlen == 0)
250 set_bit(CACHE_NEGATIVE, &key.h.flags);
251
252 item = nfs_dns_update(cd, &key, item);
253 if (item == NULL)
254 goto out;
255
256 ret = 0;
257 cache_put(&item->h, cd);
258out:
259 return ret;
260}
261
262static struct cache_detail nfs_dns_resolve = {
263 .owner = THIS_MODULE,
264 .hash_size = NFS_DNS_HASHTBL_SIZE,
265 .hash_table = nfs_dns_table,
266 .name = "dns_resolve",
267 .cache_put = nfs_dns_ent_put,
268 .cache_upcall = nfs_dns_upcall,
269 .cache_parse = nfs_dns_parse,
270 .cache_show = nfs_dns_show,
271 .match = nfs_dns_match,
272 .init = nfs_dns_ent_init,
273 .update = nfs_dns_ent_update,
274 .alloc = nfs_dns_ent_alloc,
275};
276
277static int do_cache_lookup(struct cache_detail *cd,
278 struct nfs_dns_ent *key,
279 struct nfs_dns_ent **item,
280 struct nfs_cache_defer_req *dreq)
281{
282 int ret = -ENOMEM;
283
284 *item = nfs_dns_lookup(cd, key);
285 if (*item) {
286 ret = cache_check(cd, &(*item)->h, &dreq->req);
287 if (ret)
288 *item = NULL;
289 }
290 return ret;
291}
292
293static int do_cache_lookup_nowait(struct cache_detail *cd,
294 struct nfs_dns_ent *key,
295 struct nfs_dns_ent **item)
296{
297 int ret = -ENOMEM;
298
299 *item = nfs_dns_lookup(cd, key);
300 if (!*item)
301 goto out_err;
302 ret = -ETIMEDOUT;
303 if (!test_bit(CACHE_VALID, &(*item)->h.flags)
304 || (*item)->h.expiry_time < seconds_since_boot()
305 || cd->flush_time > (*item)->h.last_refresh)
306 goto out_put;
307 ret = -ENOENT;
308 if (test_bit(CACHE_NEGATIVE, &(*item)->h.flags))
309 goto out_put;
310 return 0;
311out_put:
312 cache_put(&(*item)->h, cd);
313out_err:
314 *item = NULL;
315 return ret;
316}
317
318static int do_cache_lookup_wait(struct cache_detail *cd,
319 struct nfs_dns_ent *key,
320 struct nfs_dns_ent **item)
321{
322 struct nfs_cache_defer_req *dreq;
323 int ret = -ENOMEM;
324
325 dreq = nfs_cache_defer_req_alloc();
326 if (!dreq)
327 goto out;
328 ret = do_cache_lookup(cd, key, item, dreq);
329 if (ret == -EAGAIN) {
330 ret = nfs_cache_wait_for_upcall(dreq);
331 if (!ret)
332 ret = do_cache_lookup_nowait(cd, key, item);
333 }
334 nfs_cache_defer_req_put(dreq);
335out:
336 return ret;
337}
338
339ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
340 struct sockaddr *sa, size_t salen)
341{
342 struct nfs_dns_ent key = {
343 .hostname = name,
344 .namelen = namelen,
345 };
346 struct nfs_dns_ent *item = NULL;
347 ssize_t ret;
348
349 ret = do_cache_lookup_wait(&nfs_dns_resolve, &key, &item);
350 if (ret == 0) {
351 if (salen >= item->addrlen) {
352 memcpy(sa, &item->addr, item->addrlen);
353 ret = item->addrlen;
354 } else
355 ret = -EOVERFLOW;
356 cache_put(&item->h, &nfs_dns_resolve);
357 } else if (ret == -ENOENT)
358 ret = -ESRCH;
359 return ret;
360}
361
362int nfs_dns_resolver_init(void)
363{
364 return nfs_cache_register(&nfs_dns_resolve);
365}
366
367void nfs_dns_resolver_destroy(void)
368{
369 nfs_cache_unregister(&nfs_dns_resolve);
370}
371
372#endif
diff --git a/fs/nfs/dns_resolve.h b/fs/nfs/dns_resolve.h
new file mode 100644
index 000000000000..199bb5543a91
--- /dev/null
+++ b/fs/nfs/dns_resolve.h
@@ -0,0 +1,26 @@
1/*
2 * Resolve DNS hostnames into valid ip addresses
3 */
4#ifndef __LINUX_FS_NFS_DNS_RESOLVE_H
5#define __LINUX_FS_NFS_DNS_RESOLVE_H
6
7#define NFS_DNS_HOSTNAME_MAXLEN (128)
8
9
10#ifdef CONFIG_NFS_USE_KERNEL_DNS
11static inline int nfs_dns_resolver_init(void)
12{
13 return 0;
14}
15
16static inline void nfs_dns_resolver_destroy(void)
17{}
18#else
19extern int nfs_dns_resolver_init(void);
20extern void nfs_dns_resolver_destroy(void);
21#endif
22
23extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
24 struct sockaddr *sa, size_t salen);
25
26#endif
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 0055b813ec2c..7bf029ef4084 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -24,10 +24,10 @@
24#include <linux/nfs_fs.h> 24#include <linux/nfs_fs.h>
25#include <linux/nfs_mount.h> 25#include <linux/nfs_mount.h>
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/slab.h>
28#include <linux/pagemap.h> 27#include <linux/pagemap.h>
29#include <linux/smp_lock.h>
30#include <linux/aio.h> 28#include <linux/aio.h>
29#include <linux/gfp.h>
30#include <linux/swap.h>
31 31
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <asm/system.h> 33#include <asm/system.h>
@@ -36,6 +36,7 @@
36#include "internal.h" 36#include "internal.h"
37#include "iostat.h" 37#include "iostat.h"
38#include "fscache.h" 38#include "fscache.h"
39#include "pnfs.h"
39 40
40#define NFSDBG_FACILITY NFSDBG_FILE 41#define NFSDBG_FACILITY NFSDBG_FILE
41 42
@@ -54,13 +55,13 @@ static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe,
54static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov, 55static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov,
55 unsigned long nr_segs, loff_t pos); 56 unsigned long nr_segs, loff_t pos);
56static int nfs_file_flush(struct file *, fl_owner_t id); 57static int nfs_file_flush(struct file *, fl_owner_t id);
57static int nfs_file_fsync(struct file *, struct dentry *dentry, int datasync); 58static int nfs_file_fsync(struct file *, int datasync);
58static int nfs_check_flags(int flags); 59static int nfs_check_flags(int flags);
59static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl); 60static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl);
60static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl); 61static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl);
61static int nfs_setlease(struct file *file, long arg, struct file_lock **fl); 62static int nfs_setlease(struct file *file, long arg, struct file_lock **fl);
62 63
63static struct vm_operations_struct nfs_file_vm_ops; 64static const struct vm_operations_struct nfs_file_vm_ops;
64 65
65const struct file_operations nfs_file_operations = { 66const struct file_operations nfs_file_operations = {
66 .llseek = nfs_file_llseek, 67 .llseek = nfs_file_llseek,
@@ -124,11 +125,11 @@ nfs_file_open(struct inode *inode, struct file *filp)
124 filp->f_path.dentry->d_parent->d_name.name, 125 filp->f_path.dentry->d_parent->d_name.name,
125 filp->f_path.dentry->d_name.name); 126 filp->f_path.dentry->d_name.name);
126 127
128 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
127 res = nfs_check_flags(filp->f_flags); 129 res = nfs_check_flags(filp->f_flags);
128 if (res) 130 if (res)
129 return res; 131 return res;
130 132
131 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
132 res = nfs_open(inode, filp); 133 res = nfs_open(inode, filp);
133 return res; 134 return res;
134} 135}
@@ -162,14 +163,17 @@ static int nfs_revalidate_file_size(struct inode *inode, struct file *filp)
162 struct nfs_server *server = NFS_SERVER(inode); 163 struct nfs_server *server = NFS_SERVER(inode);
163 struct nfs_inode *nfsi = NFS_I(inode); 164 struct nfs_inode *nfsi = NFS_I(inode);
164 165
165 if (server->flags & NFS_MOUNT_NOAC) 166 if (nfs_have_delegated_attributes(inode))
166 goto force_reval; 167 goto out_noreval;
168
167 if (filp->f_flags & O_DIRECT) 169 if (filp->f_flags & O_DIRECT)
168 goto force_reval; 170 goto force_reval;
169 if (nfsi->npages != 0) 171 if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
170 return 0; 172 goto force_reval;
171 if (!(nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) && !nfs_attribute_timeout(inode)) 173 if (nfs_attribute_timeout(inode))
172 return 0; 174 goto force_reval;
175out_noreval:
176 return 0;
173force_reval: 177force_reval:
174 return __nfs_revalidate_inode(server, inode); 178 return __nfs_revalidate_inode(server, inode);
175} 179}
@@ -200,37 +204,11 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
200} 204}
201 205
202/* 206/*
203 * Helper for nfs_file_flush() and nfs_file_fsync()
204 *
205 * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
206 * disk, but it retrieves and clears ctx->error after synching, despite
207 * the two being set at the same time in nfs_context_set_write_error().
208 * This is because the former is used to notify the _next_ call to
209 * nfs_file_write() that a write error occured, and hence cause it to
210 * fall back to doing a synchronous write.
211 */
212static int nfs_do_fsync(struct nfs_open_context *ctx, struct inode *inode)
213{
214 int have_error, status;
215 int ret = 0;
216
217 have_error = test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
218 status = nfs_wb_all(inode);
219 have_error |= test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
220 if (have_error)
221 ret = xchg(&ctx->error, 0);
222 if (!ret)
223 ret = status;
224 return ret;
225}
226
227/*
228 * Flush all dirty pages, and check for write errors. 207 * Flush all dirty pages, and check for write errors.
229 */ 208 */
230static int 209static int
231nfs_file_flush(struct file *file, fl_owner_t id) 210nfs_file_flush(struct file *file, fl_owner_t id)
232{ 211{
233 struct nfs_open_context *ctx = nfs_file_open_context(file);
234 struct dentry *dentry = file->f_path.dentry; 212 struct dentry *dentry = file->f_path.dentry;
235 struct inode *inode = dentry->d_inode; 213 struct inode *inode = dentry->d_inode;
236 214
@@ -238,12 +216,12 @@ nfs_file_flush(struct file *file, fl_owner_t id)
238 dentry->d_parent->d_name.name, 216 dentry->d_parent->d_name.name,
239 dentry->d_name.name); 217 dentry->d_name.name);
240 218
219 nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
241 if ((file->f_mode & FMODE_WRITE) == 0) 220 if ((file->f_mode & FMODE_WRITE) == 0)
242 return 0; 221 return 0;
243 nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
244 222
245 /* Flush writes to the server and return any errors */ 223 /* Flush writes to the server and return any errors */
246 return nfs_do_fsync(ctx, inode); 224 return vfs_fsync(file, 0);
247} 225}
248 226
249static ssize_t 227static ssize_t
@@ -263,9 +241,11 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
263 (unsigned long) count, (unsigned long) pos); 241 (unsigned long) count, (unsigned long) pos);
264 242
265 result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping); 243 result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
266 nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count); 244 if (!result) {
267 if (!result)
268 result = generic_file_aio_read(iocb, iov, nr_segs, pos); 245 result = generic_file_aio_read(iocb, iov, nr_segs, pos);
246 if (result > 0)
247 nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result);
248 }
269 return result; 249 return result;
270} 250}
271 251
@@ -283,8 +263,11 @@ nfs_file_splice_read(struct file *filp, loff_t *ppos,
283 (unsigned long) count, (unsigned long long) *ppos); 263 (unsigned long) count, (unsigned long long) *ppos);
284 264
285 res = nfs_revalidate_mapping(inode, filp->f_mapping); 265 res = nfs_revalidate_mapping(inode, filp->f_mapping);
286 if (!res) 266 if (!res) {
287 res = generic_file_splice_read(filp, ppos, pipe, count, flags); 267 res = generic_file_splice_read(filp, ppos, pipe, count, flags);
268 if (res > 0)
269 nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, res);
270 }
288 return res; 271 return res;
289} 272}
290 273
@@ -313,19 +296,73 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
313 * Flush any dirty pages for this process, and check for write errors. 296 * Flush any dirty pages for this process, and check for write errors.
314 * The return status from this call provides a reliable indication of 297 * The return status from this call provides a reliable indication of
315 * whether any write errors occurred for this process. 298 * whether any write errors occurred for this process.
299 *
300 * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
301 * disk, but it retrieves and clears ctx->error after synching, despite
302 * the two being set at the same time in nfs_context_set_write_error().
303 * This is because the former is used to notify the _next_ call to
304 * nfs_file_write() that a write error occured, and hence cause it to
305 * fall back to doing a synchronous write.
316 */ 306 */
317static int 307static int
318nfs_file_fsync(struct file *file, struct dentry *dentry, int datasync) 308nfs_file_fsync(struct file *file, int datasync)
319{ 309{
310 struct dentry *dentry = file->f_path.dentry;
320 struct nfs_open_context *ctx = nfs_file_open_context(file); 311 struct nfs_open_context *ctx = nfs_file_open_context(file);
321 struct inode *inode = dentry->d_inode; 312 struct inode *inode = dentry->d_inode;
313 int have_error, status;
314 int ret = 0;
315
322 316
323 dprintk("NFS: fsync file(%s/%s) datasync %d\n", 317 dprintk("NFS: fsync file(%s/%s) datasync %d\n",
324 dentry->d_parent->d_name.name, dentry->d_name.name, 318 dentry->d_parent->d_name.name, dentry->d_name.name,
325 datasync); 319 datasync);
326 320
327 nfs_inc_stats(inode, NFSIOS_VFSFSYNC); 321 nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
328 return nfs_do_fsync(ctx, inode); 322 have_error = test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
323 status = nfs_commit_inode(inode, FLUSH_SYNC);
324 have_error |= test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
325 if (have_error)
326 ret = xchg(&ctx->error, 0);
327 if (!ret && status < 0)
328 ret = status;
329 return ret;
330}
331
332/*
333 * Decide whether a read/modify/write cycle may be more efficient
334 * then a modify/write/read cycle when writing to a page in the
335 * page cache.
336 *
337 * The modify/write/read cycle may occur if a page is read before
338 * being completely filled by the writer. In this situation, the
339 * page must be completely written to stable storage on the server
340 * before it can be refilled by reading in the page from the server.
341 * This can lead to expensive, small, FILE_SYNC mode writes being
342 * done.
343 *
344 * It may be more efficient to read the page first if the file is
345 * open for reading in addition to writing, the page is not marked
346 * as Uptodate, it is not dirty or waiting to be committed,
347 * indicating that it was previously allocated and then modified,
348 * that there were valid bytes of data in that range of the file,
349 * and that the new data won't completely replace the old data in
350 * that range of the file.
351 */
352static int nfs_want_read_modify_write(struct file *file, struct page *page,
353 loff_t pos, unsigned len)
354{
355 unsigned int pglen = nfs_page_length(page);
356 unsigned int offset = pos & (PAGE_CACHE_SIZE - 1);
357 unsigned int end = offset + len;
358
359 if ((file->f_mode & FMODE_READ) && /* open for read? */
360 !PageUptodate(page) && /* Uptodate? */
361 !PagePrivate(page) && /* i/o request already? */
362 pglen && /* valid bytes of file? */
363 (end < pglen || offset)) /* replace all valid bytes? */
364 return 1;
365 return 0;
329} 366}
330 367
331/* 368/*
@@ -341,15 +378,20 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
341 struct page **pagep, void **fsdata) 378 struct page **pagep, void **fsdata)
342{ 379{
343 int ret; 380 int ret;
344 pgoff_t index; 381 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
345 struct page *page; 382 struct page *page;
346 index = pos >> PAGE_CACHE_SHIFT; 383 int once_thru = 0;
347 384
348 dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n", 385 dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n",
349 file->f_path.dentry->d_parent->d_name.name, 386 file->f_path.dentry->d_parent->d_name.name,
350 file->f_path.dentry->d_name.name, 387 file->f_path.dentry->d_name.name,
351 mapping->host->i_ino, len, (long long) pos); 388 mapping->host->i_ino, len, (long long) pos);
352 389
390 pnfs_update_layout(mapping->host,
391 nfs_file_open_context(file),
392 IOMODE_RW);
393
394start:
353 /* 395 /*
354 * Prevent starvation issues if someone is doing a consistency 396 * Prevent starvation issues if someone is doing a consistency
355 * sync-to-disk 397 * sync-to-disk
@@ -368,6 +410,13 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
368 if (ret) { 410 if (ret) {
369 unlock_page(page); 411 unlock_page(page);
370 page_cache_release(page); 412 page_cache_release(page);
413 } else if (!once_thru &&
414 nfs_want_read_modify_write(file, page, pos, len)) {
415 once_thru = 1;
416 ret = nfs_readpage(file, page);
417 page_cache_release(page);
418 if (!ret)
419 goto start;
371 } 420 }
372 return ret; 421 return ret;
373} 422}
@@ -441,8 +490,19 @@ static void nfs_invalidate_page(struct page *page, unsigned long offset)
441 */ 490 */
442static int nfs_release_page(struct page *page, gfp_t gfp) 491static int nfs_release_page(struct page *page, gfp_t gfp)
443{ 492{
493 struct address_space *mapping = page->mapping;
494
444 dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page); 495 dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
445 496
497 /* Only do I/O if gfp is a superset of GFP_KERNEL */
498 if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL) {
499 int how = FLUSH_SYNC;
500
501 /* Don't let kswapd deadlock waiting for OOM RPC calls */
502 if (current_is_kswapd())
503 how = 0;
504 nfs_commit_inode(mapping->host, how);
505 }
446 /* If PagePrivate() is set, then the page is not freeable */ 506 /* If PagePrivate() is set, then the page is not freeable */
447 if (PagePrivate(page)) 507 if (PagePrivate(page))
448 return 0; 508 return 0;
@@ -480,7 +540,9 @@ const struct address_space_operations nfs_file_aops = {
480 .invalidatepage = nfs_invalidate_page, 540 .invalidatepage = nfs_invalidate_page,
481 .releasepage = nfs_release_page, 541 .releasepage = nfs_release_page,
482 .direct_IO = nfs_direct_IO, 542 .direct_IO = nfs_direct_IO,
543 .migratepage = nfs_migrate_page,
483 .launder_page = nfs_launder_page, 544 .launder_page = nfs_launder_page,
545 .error_remove_page = generic_error_remove_page,
484}; 546};
485 547
486/* 548/*
@@ -494,7 +556,7 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
494 struct file *filp = vma->vm_file; 556 struct file *filp = vma->vm_file;
495 struct dentry *dentry = filp->f_path.dentry; 557 struct dentry *dentry = filp->f_path.dentry;
496 unsigned pagelen; 558 unsigned pagelen;
497 int ret = -EINVAL; 559 int ret = VM_FAULT_NOPAGE;
498 struct address_space *mapping; 560 struct address_space *mapping;
499 561
500 dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%s/%s(%ld), offset %lld)\n", 562 dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%s/%s(%ld), offset %lld)\n",
@@ -510,24 +572,23 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
510 if (mapping != dentry->d_inode->i_mapping) 572 if (mapping != dentry->d_inode->i_mapping)
511 goto out_unlock; 573 goto out_unlock;
512 574
513 ret = 0;
514 pagelen = nfs_page_length(page); 575 pagelen = nfs_page_length(page);
515 if (pagelen == 0) 576 if (pagelen == 0)
516 goto out_unlock; 577 goto out_unlock;
517 578
518 ret = nfs_flush_incompatible(filp, page); 579 ret = VM_FAULT_LOCKED;
519 if (ret != 0) 580 if (nfs_flush_incompatible(filp, page) == 0 &&
520 goto out_unlock; 581 nfs_updatepage(filp, page, 0, pagelen) == 0)
582 goto out;
521 583
522 ret = nfs_updatepage(filp, page, 0, pagelen); 584 ret = VM_FAULT_SIGBUS;
523out_unlock: 585out_unlock:
524 if (!ret)
525 return VM_FAULT_LOCKED;
526 unlock_page(page); 586 unlock_page(page);
527 return VM_FAULT_SIGBUS; 587out:
588 return ret;
528} 589}
529 590
530static struct vm_operations_struct nfs_file_vm_ops = { 591static const struct vm_operations_struct nfs_file_vm_ops = {
531 .fault = filemap_fault, 592 .fault = filemap_fault,
532 .page_mkwrite = nfs_vm_page_mkwrite, 593 .page_mkwrite = nfs_vm_page_mkwrite,
533}; 594};
@@ -536,7 +597,7 @@ static int nfs_need_sync_write(struct file *filp, struct inode *inode)
536{ 597{
537 struct nfs_open_context *ctx; 598 struct nfs_open_context *ctx;
538 599
539 if (IS_SYNC(inode) || (filp->f_flags & O_SYNC)) 600 if (IS_SYNC(inode) || (filp->f_flags & O_DSYNC))
540 return 1; 601 return 1;
541 ctx = nfs_file_open_context(filp); 602 ctx = nfs_file_open_context(filp);
542 if (test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags)) 603 if (test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags))
@@ -549,6 +610,7 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
549{ 610{
550 struct dentry * dentry = iocb->ki_filp->f_path.dentry; 611 struct dentry * dentry = iocb->ki_filp->f_path.dentry;
551 struct inode * inode = dentry->d_inode; 612 struct inode * inode = dentry->d_inode;
613 unsigned long written = 0;
552 ssize_t result; 614 ssize_t result;
553 size_t count = iov_length(iov, nr_segs); 615 size_t count = iov_length(iov, nr_segs);
554 616
@@ -575,14 +637,18 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
575 if (!count) 637 if (!count)
576 goto out; 638 goto out;
577 639
578 nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
579 result = generic_file_aio_write(iocb, iov, nr_segs, pos); 640 result = generic_file_aio_write(iocb, iov, nr_segs, pos);
580 /* Return error values for O_SYNC and IS_SYNC() */ 641 if (result > 0)
642 written = result;
643
644 /* Return error values for O_DSYNC and IS_SYNC() */
581 if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) { 645 if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) {
582 int err = nfs_do_fsync(nfs_file_open_context(iocb->ki_filp), inode); 646 int err = vfs_fsync(iocb->ki_filp, 0);
583 if (err < 0) 647 if (err < 0)
584 result = err; 648 result = err;
585 } 649 }
650 if (result > 0)
651 nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
586out: 652out:
587 return result; 653 return result;
588 654
@@ -597,6 +663,7 @@ static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe,
597{ 663{
598 struct dentry *dentry = filp->f_path.dentry; 664 struct dentry *dentry = filp->f_path.dentry;
599 struct inode *inode = dentry->d_inode; 665 struct inode *inode = dentry->d_inode;
666 unsigned long written = 0;
600 ssize_t ret; 667 ssize_t ret;
601 668
602 dprintk("NFS splice_write(%s/%s, %lu@%llu)\n", 669 dprintk("NFS splice_write(%s/%s, %lu@%llu)\n",
@@ -607,21 +674,26 @@ static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe,
607 * The combination of splice and an O_APPEND destination is disallowed. 674 * The combination of splice and an O_APPEND destination is disallowed.
608 */ 675 */
609 676
610 nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
611
612 ret = generic_file_splice_write(pipe, filp, ppos, count, flags); 677 ret = generic_file_splice_write(pipe, filp, ppos, count, flags);
678 if (ret > 0)
679 written = ret;
680
613 if (ret >= 0 && nfs_need_sync_write(filp, inode)) { 681 if (ret >= 0 && nfs_need_sync_write(filp, inode)) {
614 int err = nfs_do_fsync(nfs_file_open_context(filp), inode); 682 int err = vfs_fsync(filp, 0);
615 if (err < 0) 683 if (err < 0)
616 ret = err; 684 ret = err;
617 } 685 }
686 if (ret > 0)
687 nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
618 return ret; 688 return ret;
619} 689}
620 690
621static int do_getlk(struct file *filp, int cmd, struct file_lock *fl) 691static int
692do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
622{ 693{
623 struct inode *inode = filp->f_mapping->host; 694 struct inode *inode = filp->f_mapping->host;
624 int status = 0; 695 int status = 0;
696 unsigned int saved_type = fl->fl_type;
625 697
626 /* Try local locking first */ 698 /* Try local locking first */
627 posix_test_lock(filp, fl); 699 posix_test_lock(filp, fl);
@@ -629,11 +701,12 @@ static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
629 /* found a conflict */ 701 /* found a conflict */
630 goto out; 702 goto out;
631 } 703 }
704 fl->fl_type = saved_type;
632 705
633 if (nfs_have_delegation(inode, FMODE_READ)) 706 if (nfs_have_delegation(inode, FMODE_READ))
634 goto out_noconflict; 707 goto out_noconflict;
635 708
636 if (NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM) 709 if (is_local)
637 goto out_noconflict; 710 goto out_noconflict;
638 711
639 status = NFS_PROTO(inode)->lock(filp, cmd, fl); 712 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
@@ -657,14 +730,11 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl)
657 default: 730 default:
658 BUG(); 731 BUG();
659 } 732 }
660 if (res < 0)
661 dprintk(KERN_WARNING "%s: VFS is out of sync with lock manager"
662 " - error %d!\n",
663 __func__, res);
664 return res; 733 return res;
665} 734}
666 735
667static int do_unlk(struct file *filp, int cmd, struct file_lock *fl) 736static int
737do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
668{ 738{
669 struct inode *inode = filp->f_mapping->host; 739 struct inode *inode = filp->f_mapping->host;
670 int status; 740 int status;
@@ -679,15 +749,24 @@ static int do_unlk(struct file *filp, int cmd, struct file_lock *fl)
679 * If we're signalled while cleaning up locks on process exit, we 749 * If we're signalled while cleaning up locks on process exit, we
680 * still need to complete the unlock. 750 * still need to complete the unlock.
681 */ 751 */
682 /* Use local locking if mounted with "-onolock" */ 752 /*
683 if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) 753 * Use local locking if mounted with "-onolock" or with appropriate
754 * "-olocal_lock="
755 */
756 if (!is_local)
684 status = NFS_PROTO(inode)->lock(filp, cmd, fl); 757 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
685 else 758 else
686 status = do_vfs_lock(filp, fl); 759 status = do_vfs_lock(filp, fl);
687 return status; 760 return status;
688} 761}
689 762
690static int do_setlk(struct file *filp, int cmd, struct file_lock *fl) 763static int
764is_time_granular(struct timespec *ts) {
765 return ((ts->tv_sec == 0) && (ts->tv_nsec <= 1000));
766}
767
768static int
769do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
691{ 770{
692 struct inode *inode = filp->f_mapping->host; 771 struct inode *inode = filp->f_mapping->host;
693 int status; 772 int status;
@@ -700,20 +779,31 @@ static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
700 if (status != 0) 779 if (status != 0)
701 goto out; 780 goto out;
702 781
703 /* Use local locking if mounted with "-onolock" */ 782 /*
704 if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) 783 * Use local locking if mounted with "-onolock" or with appropriate
784 * "-olocal_lock="
785 */
786 if (!is_local)
705 status = NFS_PROTO(inode)->lock(filp, cmd, fl); 787 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
706 else 788 else
707 status = do_vfs_lock(filp, fl); 789 status = do_vfs_lock(filp, fl);
708 if (status < 0) 790 if (status < 0)
709 goto out; 791 goto out;
792
710 /* 793 /*
711 * Make sure we clear the cache whenever we try to get the lock. 794 * Revalidate the cache if the server has time stamps granular
795 * enough to detect subsecond changes. Otherwise, clear the
796 * cache to prevent missing any changes.
797 *
712 * This makes locking act as a cache coherency point. 798 * This makes locking act as a cache coherency point.
713 */ 799 */
714 nfs_sync_mapping(filp->f_mapping); 800 nfs_sync_mapping(filp->f_mapping);
715 if (!nfs_have_delegation(inode, FMODE_READ)) 801 if (!nfs_have_delegation(inode, FMODE_READ)) {
716 nfs_zap_caches(inode); 802 if (is_time_granular(&NFS_SERVER(inode)->time_delta))
803 __nfs_revalidate_inode(NFS_SERVER(inode), inode);
804 else
805 nfs_zap_caches(inode);
806 }
717out: 807out:
718 return status; 808 return status;
719} 809}
@@ -725,6 +815,7 @@ static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
725{ 815{
726 struct inode *inode = filp->f_mapping->host; 816 struct inode *inode = filp->f_mapping->host;
727 int ret = -ENOLCK; 817 int ret = -ENOLCK;
818 int is_local = 0;
728 819
729 dprintk("NFS: lock(%s/%s, t=%x, fl=%x, r=%lld:%lld)\n", 820 dprintk("NFS: lock(%s/%s, t=%x, fl=%x, r=%lld:%lld)\n",
730 filp->f_path.dentry->d_parent->d_name.name, 821 filp->f_path.dentry->d_parent->d_name.name,
@@ -738,6 +829,9 @@ static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
738 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK) 829 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
739 goto out_err; 830 goto out_err;
740 831
832 if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FCNTL)
833 is_local = 1;
834
741 if (NFS_PROTO(inode)->lock_check_bounds != NULL) { 835 if (NFS_PROTO(inode)->lock_check_bounds != NULL) {
742 ret = NFS_PROTO(inode)->lock_check_bounds(fl); 836 ret = NFS_PROTO(inode)->lock_check_bounds(fl);
743 if (ret < 0) 837 if (ret < 0)
@@ -745,11 +839,11 @@ static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
745 } 839 }
746 840
747 if (IS_GETLK(cmd)) 841 if (IS_GETLK(cmd))
748 ret = do_getlk(filp, cmd, fl); 842 ret = do_getlk(filp, cmd, fl, is_local);
749 else if (fl->fl_type == F_UNLCK) 843 else if (fl->fl_type == F_UNLCK)
750 ret = do_unlk(filp, cmd, fl); 844 ret = do_unlk(filp, cmd, fl, is_local);
751 else 845 else
752 ret = do_setlk(filp, cmd, fl); 846 ret = do_setlk(filp, cmd, fl, is_local);
753out_err: 847out_err:
754 return ret; 848 return ret;
755} 849}
@@ -759,6 +853,9 @@ out_err:
759 */ 853 */
760static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl) 854static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
761{ 855{
856 struct inode *inode = filp->f_mapping->host;
857 int is_local = 0;
858
762 dprintk("NFS: flock(%s/%s, t=%x, fl=%x)\n", 859 dprintk("NFS: flock(%s/%s, t=%x, fl=%x)\n",
763 filp->f_path.dentry->d_parent->d_name.name, 860 filp->f_path.dentry->d_parent->d_name.name,
764 filp->f_path.dentry->d_name.name, 861 filp->f_path.dentry->d_name.name,
@@ -767,14 +864,17 @@ static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
767 if (!(fl->fl_flags & FL_FLOCK)) 864 if (!(fl->fl_flags & FL_FLOCK))
768 return -ENOLCK; 865 return -ENOLCK;
769 866
867 if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
868 is_local = 1;
869
770 /* We're simulating flock() locks using posix locks on the server */ 870 /* We're simulating flock() locks using posix locks on the server */
771 fl->fl_owner = (fl_owner_t)filp; 871 fl->fl_owner = (fl_owner_t)filp;
772 fl->fl_start = 0; 872 fl->fl_start = 0;
773 fl->fl_end = OFFSET_MAX; 873 fl->fl_end = OFFSET_MAX;
774 874
775 if (fl->fl_type == F_UNLCK) 875 if (fl->fl_type == F_UNLCK)
776 return do_unlk(filp, cmd, fl); 876 return do_unlk(filp, cmd, fl, is_local);
777 return do_setlk(filp, cmd, fl); 877 return do_setlk(filp, cmd, fl, is_local);
778} 878}
779 879
780/* 880/*
@@ -786,6 +886,5 @@ static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
786 dprintk("NFS: setlease(%s/%s, arg=%ld)\n", 886 dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
787 file->f_path.dentry->d_parent->d_name.name, 887 file->f_path.dentry->d_parent->d_name.name,
788 file->f_path.dentry->d_name.name, arg); 888 file->f_path.dentry->d_name.name, arg);
789
790 return -EINVAL; 889 return -EINVAL;
791} 890}
diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index 379be678cb7e..ce153a6b3aec 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -17,6 +17,7 @@
17#include <linux/nfs_fs_sb.h> 17#include <linux/nfs_fs_sb.h>
18#include <linux/in6.h> 18#include <linux/in6.h>
19#include <linux/seq_file.h> 19#include <linux/seq_file.h>
20#include <linux/slab.h>
20 21
21#include "internal.h" 22#include "internal.h"
22#include "iostat.h" 23#include "iostat.h"
@@ -58,17 +59,34 @@ void nfs_fscache_release_client_cookie(struct nfs_client *clp)
58/* 59/*
59 * Get the cache cookie for an NFS superblock. We have to handle 60 * Get the cache cookie for an NFS superblock. We have to handle
60 * uniquification here because the cache doesn't do it for us. 61 * uniquification here because the cache doesn't do it for us.
62 *
63 * The default uniquifier is just an empty string, but it may be overridden
64 * either by the 'fsc=xxx' option to mount, or by inheriting it from the parent
65 * superblock across an automount point of some nature.
61 */ 66 */
62void nfs_fscache_get_super_cookie(struct super_block *sb, 67void nfs_fscache_get_super_cookie(struct super_block *sb, const char *uniq,
63 struct nfs_parsed_mount_data *data) 68 struct nfs_clone_mount *mntdata)
64{ 69{
65 struct nfs_fscache_key *key, *xkey; 70 struct nfs_fscache_key *key, *xkey;
66 struct nfs_server *nfss = NFS_SB(sb); 71 struct nfs_server *nfss = NFS_SB(sb);
67 struct rb_node **p, *parent; 72 struct rb_node **p, *parent;
68 const char *uniq = data->fscache_uniq ?: "";
69 int diff, ulen; 73 int diff, ulen;
70 74
71 ulen = strlen(uniq); 75 if (uniq) {
76 ulen = strlen(uniq);
77 } else if (mntdata) {
78 struct nfs_server *mnt_s = NFS_SB(mntdata->sb);
79 if (mnt_s->fscache_key) {
80 uniq = mnt_s->fscache_key->key.uniquifier;
81 ulen = mnt_s->fscache_key->key.uniq_len;
82 }
83 }
84
85 if (!uniq) {
86 uniq = "";
87 ulen = 1;
88 }
89
72 key = kzalloc(sizeof(*key) + ulen, GFP_KERNEL); 90 key = kzalloc(sizeof(*key) + ulen, GFP_KERNEL);
73 if (!key) 91 if (!key)
74 return; 92 return;
@@ -337,22 +355,17 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
337 */ 355 */
338int nfs_fscache_release_page(struct page *page, gfp_t gfp) 356int nfs_fscache_release_page(struct page *page, gfp_t gfp)
339{ 357{
340 struct nfs_inode *nfsi = NFS_I(page->mapping->host);
341 struct fscache_cookie *cookie = nfsi->fscache;
342
343 BUG_ON(!cookie);
344
345 if (fscache_check_page_write(cookie, page)) {
346 if (!(gfp & __GFP_WAIT))
347 return 0;
348 fscache_wait_on_page_write(cookie, page);
349 }
350
351 if (PageFsCache(page)) { 358 if (PageFsCache(page)) {
359 struct nfs_inode *nfsi = NFS_I(page->mapping->host);
360 struct fscache_cookie *cookie = nfsi->fscache;
361
362 BUG_ON(!cookie);
352 dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n", 363 dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n",
353 cookie, page, nfsi); 364 cookie, page, nfsi);
354 365
355 fscache_uncache_page(cookie, page); 366 if (!fscache_maybe_release_page(cookie, page, gfp))
367 return 0;
368
356 nfs_add_fscache_stats(page->mapping->host, 369 nfs_add_fscache_stats(page->mapping->host,
357 NFSIOS_FSCACHE_PAGES_UNCACHED, 1); 370 NFSIOS_FSCACHE_PAGES_UNCACHED, 1);
358 } 371 }
@@ -454,7 +467,8 @@ int __nfs_readpages_from_fscache(struct nfs_open_context *ctx,
454 struct list_head *pages, 467 struct list_head *pages,
455 unsigned *nr_pages) 468 unsigned *nr_pages)
456{ 469{
457 int ret, npages = *nr_pages; 470 unsigned npages = *nr_pages;
471 int ret;
458 472
459 dfprintk(FSCACHE, "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n", 473 dfprintk(FSCACHE, "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n",
460 NFS_I(inode)->fscache, npages, inode); 474 NFS_I(inode)->fscache, npages, inode);
diff --git a/fs/nfs/fscache.h b/fs/nfs/fscache.h
index 6e809bb0ff08..b9c572d0679f 100644
--- a/fs/nfs/fscache.h
+++ b/fs/nfs/fscache.h
@@ -74,7 +74,8 @@ extern void nfs_fscache_get_client_cookie(struct nfs_client *);
74extern void nfs_fscache_release_client_cookie(struct nfs_client *); 74extern void nfs_fscache_release_client_cookie(struct nfs_client *);
75 75
76extern void nfs_fscache_get_super_cookie(struct super_block *, 76extern void nfs_fscache_get_super_cookie(struct super_block *,
77 struct nfs_parsed_mount_data *); 77 const char *,
78 struct nfs_clone_mount *);
78extern void nfs_fscache_release_super_cookie(struct super_block *); 79extern void nfs_fscache_release_super_cookie(struct super_block *);
79 80
80extern void nfs_fscache_init_inode_cookie(struct inode *); 81extern void nfs_fscache_init_inode_cookie(struct inode *);
@@ -173,7 +174,8 @@ static inline void nfs_fscache_release_client_cookie(struct nfs_client *clp) {}
173 174
174static inline void nfs_fscache_get_super_cookie( 175static inline void nfs_fscache_get_super_cookie(
175 struct super_block *sb, 176 struct super_block *sb,
176 struct nfs_parsed_mount_data *data) 177 const char *uniq,
178 struct nfs_clone_mount *mntdata)
177{ 179{
178} 180}
179static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {} 181static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index 46177cb87064..5596c6a2881e 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -30,7 +30,6 @@
30#include <linux/nfs_idmap.h> 30#include <linux/nfs_idmap.h>
31#include <linux/vfs.h> 31#include <linux/vfs.h>
32#include <linux/namei.h> 32#include <linux/namei.h>
33#include <linux/mnt_namespace.h>
34#include <linux/security.h> 33#include <linux/security.h>
35 34
36#include <asm/system.h> 35#include <asm/system.h>
@@ -55,8 +54,7 @@ static int nfs_superblock_set_dummy_root(struct super_block *sb, struct inode *i
55 iput(inode); 54 iput(inode);
56 return -ENOMEM; 55 return -ENOMEM;
57 } 56 }
58 /* Circumvent igrab(): we know the inode is not being freed */ 57 ihold(inode);
59 atomic_inc(&inode->i_count);
60 /* 58 /*
61 * Ensure that this dentry is invisible to d_find_alias(). 59 * Ensure that this dentry is invisible to d_find_alias().
62 * Otherwise, it may be spliced into the tree by 60 * Otherwise, it may be spliced into the tree by
@@ -65,9 +63,11 @@ static int nfs_superblock_set_dummy_root(struct super_block *sb, struct inode *i
65 * This again causes shrink_dcache_for_umount_subtree() to 63 * This again causes shrink_dcache_for_umount_subtree() to
66 * Oops, since the test for IS_ROOT() will fail. 64 * Oops, since the test for IS_ROOT() will fail.
67 */ 65 */
68 spin_lock(&dcache_lock); 66 spin_lock(&sb->s_root->d_inode->i_lock);
67 spin_lock(&sb->s_root->d_lock);
69 list_del_init(&sb->s_root->d_alias); 68 list_del_init(&sb->s_root->d_alias);
70 spin_unlock(&dcache_lock); 69 spin_unlock(&sb->s_root->d_lock);
70 spin_unlock(&sb->s_root->d_inode->i_lock);
71 } 71 }
72 return 0; 72 return 0;
73} 73}
@@ -79,159 +79,94 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
79{ 79{
80 struct nfs_server *server = NFS_SB(sb); 80 struct nfs_server *server = NFS_SB(sb);
81 struct nfs_fsinfo fsinfo; 81 struct nfs_fsinfo fsinfo;
82 struct nfs_fattr fattr; 82 struct dentry *ret;
83 struct dentry *mntroot;
84 struct inode *inode; 83 struct inode *inode;
85 int error; 84 int error;
86 85
87 /* get the actual root for this mount */ 86 /* get the actual root for this mount */
88 fsinfo.fattr = &fattr; 87 fsinfo.fattr = nfs_alloc_fattr();
88 if (fsinfo.fattr == NULL)
89 return ERR_PTR(-ENOMEM);
89 90
90 error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); 91 error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
91 if (error < 0) { 92 if (error < 0) {
92 dprintk("nfs_get_root: getattr error = %d\n", -error); 93 dprintk("nfs_get_root: getattr error = %d\n", -error);
93 return ERR_PTR(error); 94 ret = ERR_PTR(error);
95 goto out;
94 } 96 }
95 97
96 inode = nfs_fhget(sb, mntfh, fsinfo.fattr); 98 inode = nfs_fhget(sb, mntfh, fsinfo.fattr);
97 if (IS_ERR(inode)) { 99 if (IS_ERR(inode)) {
98 dprintk("nfs_get_root: get root inode failed\n"); 100 dprintk("nfs_get_root: get root inode failed\n");
99 return ERR_CAST(inode); 101 ret = ERR_CAST(inode);
102 goto out;
100 } 103 }
101 104
102 error = nfs_superblock_set_dummy_root(sb, inode); 105 error = nfs_superblock_set_dummy_root(sb, inode);
103 if (error != 0) 106 if (error != 0) {
104 return ERR_PTR(error); 107 ret = ERR_PTR(error);
108 goto out;
109 }
105 110
106 /* root dentries normally start off anonymous and get spliced in later 111 /* root dentries normally start off anonymous and get spliced in later
107 * if the dentry tree reaches them; however if the dentry already 112 * if the dentry tree reaches them; however if the dentry already
108 * exists, we'll pick it up at this point and use it as the root 113 * exists, we'll pick it up at this point and use it as the root
109 */ 114 */
110 mntroot = d_obtain_alias(inode); 115 ret = d_obtain_alias(inode);
111 if (IS_ERR(mntroot)) { 116 if (IS_ERR(ret)) {
112 dprintk("nfs_get_root: get root dentry failed\n"); 117 dprintk("nfs_get_root: get root dentry failed\n");
113 return mntroot; 118 goto out;
114 } 119 }
115 120
116 security_d_instantiate(mntroot, inode); 121 security_d_instantiate(ret, inode);
117
118 if (!mntroot->d_op)
119 mntroot->d_op = server->nfs_client->rpc_ops->dentry_ops;
120 122
121 return mntroot; 123 if (ret->d_op == NULL)
124 d_set_d_op(ret, server->nfs_client->rpc_ops->dentry_ops);
125out:
126 nfs_free_fattr(fsinfo.fattr);
127 return ret;
122} 128}
123 129
124#ifdef CONFIG_NFS_V4 130#ifdef CONFIG_NFS_V4
125 131
126/* 132int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh)
127 * Do a simple pathwalk from the root FH of the server to the nominated target
128 * of the mountpoint
129 * - give error on symlinks
130 * - give error on ".." occurring in the path
131 * - follow traversals
132 */
133int nfs4_path_walk(struct nfs_server *server,
134 struct nfs_fh *mntfh,
135 const char *path)
136{ 133{
137 struct nfs_fsinfo fsinfo; 134 struct nfs_fsinfo fsinfo;
138 struct nfs_fattr fattr; 135 int ret = -ENOMEM;
139 struct nfs_fh lastfh;
140 struct qstr name;
141 int ret;
142 136
143 dprintk("--> nfs4_path_walk(,,%s)\n", path); 137 dprintk("--> nfs4_get_rootfh()\n");
144 138
145 fsinfo.fattr = &fattr; 139 fsinfo.fattr = nfs_alloc_fattr();
146 nfs_fattr_init(&fattr); 140 if (fsinfo.fattr == NULL)
147 141 goto out;
148 /* Eat leading slashes */
149 while (*path == '/')
150 path++;
151 142
152 /* Start by getting the root filehandle from the server */ 143 /* Start by getting the root filehandle from the server */
153 ret = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); 144 ret = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
154 if (ret < 0) { 145 if (ret < 0) {
155 dprintk("nfs4_get_root: getroot error = %d\n", -ret); 146 dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
156 return ret; 147 goto out;
157 } 148 }
158 149
159 if (!S_ISDIR(fattr.mode)) { 150 if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
160 printk(KERN_ERR "nfs4_get_root:" 151 || !S_ISDIR(fsinfo.fattr->mode)) {
152 printk(KERN_ERR "nfs4_get_rootfh:"
161 " getroot encountered non-directory\n"); 153 " getroot encountered non-directory\n");
162 return -ENOTDIR; 154 ret = -ENOTDIR;
155 goto out;
163 } 156 }
164 157
165 /* FIXME: It is quite valid for the server to return a referral here */ 158 if (fsinfo.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
166 if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) { 159 printk(KERN_ERR "nfs4_get_rootfh:"
167 printk(KERN_ERR "nfs4_get_root:"
168 " getroot obtained referral\n"); 160 " getroot obtained referral\n");
169 return -EREMOTE; 161 ret = -EREMOTE;
170 } 162 goto out;
171
172next_component:
173 dprintk("Next: %s\n", path);
174
175 /* extract the next bit of the path */
176 if (!*path)
177 goto path_walk_complete;
178
179 name.name = path;
180 while (*path && *path != '/')
181 path++;
182 name.len = path - (const char *) name.name;
183
184 if (name.len > NFS4_MAXNAMLEN)
185 return -ENAMETOOLONG;
186
187eat_dot_dir:
188 while (*path == '/')
189 path++;
190
191 if (path[0] == '.' && (path[1] == '/' || !path[1])) {
192 path += 2;
193 goto eat_dot_dir;
194 }
195
196 /* FIXME: Why shouldn't the user be able to use ".." in the path? */
197 if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || !path[2])
198 ) {
199 printk(KERN_ERR "nfs4_get_root:"
200 " Mount path contains reference to \"..\"\n");
201 return -EINVAL;
202 } 163 }
203 164
204 /* lookup the next FH in the sequence */ 165 memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
205 memcpy(&lastfh, mntfh, sizeof(lastfh)); 166out:
206 167 nfs_free_fattr(fsinfo.fattr);
207 dprintk("LookupFH: %*.*s [%s]\n", name.len, name.len, name.name, path); 168 dprintk("<-- nfs4_get_rootfh() = %d\n", ret);
208 169 return ret;
209 ret = server->nfs_client->rpc_ops->lookupfh(server, &lastfh, &name,
210 mntfh, &fattr);
211 if (ret < 0) {
212 dprintk("nfs4_get_root: getroot error = %d\n", -ret);
213 return ret;
214 }
215
216 if (!S_ISDIR(fattr.mode)) {
217 printk(KERN_ERR "nfs4_get_root:"
218 " lookupfh encountered non-directory\n");
219 return -ENOTDIR;
220 }
221
222 /* FIXME: Referrals are quite valid here too */
223 if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) {
224 printk(KERN_ERR "nfs4_get_root:"
225 " lookupfh obtained referral\n");
226 return -EREMOTE;
227 }
228
229 goto next_component;
230
231path_walk_complete:
232 memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
233 dprintk("<-- nfs4_path_walk() = 0\n");
234 return 0;
235} 170}
236 171
237/* 172/*
@@ -240,8 +175,8 @@ path_walk_complete:
240struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh) 175struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
241{ 176{
242 struct nfs_server *server = NFS_SB(sb); 177 struct nfs_server *server = NFS_SB(sb);
243 struct nfs_fattr fattr; 178 struct nfs_fattr *fattr = NULL;
244 struct dentry *mntroot; 179 struct dentry *ret;
245 struct inode *inode; 180 struct inode *inode;
246 int error; 181 int error;
247 182
@@ -255,40 +190,50 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
255 return ERR_PTR(error); 190 return ERR_PTR(error);
256 } 191 }
257 192
193 fattr = nfs_alloc_fattr();
194 if (fattr == NULL)
195 return ERR_PTR(-ENOMEM);;
196
258 /* get the actual root for this mount */ 197 /* get the actual root for this mount */
259 error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr); 198 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
260 if (error < 0) { 199 if (error < 0) {
261 dprintk("nfs_get_root: getattr error = %d\n", -error); 200 dprintk("nfs_get_root: getattr error = %d\n", -error);
262 return ERR_PTR(error); 201 ret = ERR_PTR(error);
202 goto out;
263 } 203 }
264 204
265 inode = nfs_fhget(sb, mntfh, &fattr); 205 inode = nfs_fhget(sb, mntfh, fattr);
266 if (IS_ERR(inode)) { 206 if (IS_ERR(inode)) {
267 dprintk("nfs_get_root: get root inode failed\n"); 207 dprintk("nfs_get_root: get root inode failed\n");
268 return ERR_CAST(inode); 208 ret = ERR_CAST(inode);
209 goto out;
269 } 210 }
270 211
271 error = nfs_superblock_set_dummy_root(sb, inode); 212 error = nfs_superblock_set_dummy_root(sb, inode);
272 if (error != 0) 213 if (error != 0) {
273 return ERR_PTR(error); 214 ret = ERR_PTR(error);
215 goto out;
216 }
274 217
275 /* root dentries normally start off anonymous and get spliced in later 218 /* root dentries normally start off anonymous and get spliced in later
276 * if the dentry tree reaches them; however if the dentry already 219 * if the dentry tree reaches them; however if the dentry already
277 * exists, we'll pick it up at this point and use it as the root 220 * exists, we'll pick it up at this point and use it as the root
278 */ 221 */
279 mntroot = d_obtain_alias(inode); 222 ret = d_obtain_alias(inode);
280 if (IS_ERR(mntroot)) { 223 if (IS_ERR(ret)) {
281 dprintk("nfs_get_root: get root dentry failed\n"); 224 dprintk("nfs_get_root: get root dentry failed\n");
282 return mntroot; 225 goto out;
283 } 226 }
284 227
285 security_d_instantiate(mntroot, inode); 228 security_d_instantiate(ret, inode);
286 229
287 if (!mntroot->d_op) 230 if (ret->d_op == NULL)
288 mntroot->d_op = server->nfs_client->rpc_ops->dentry_ops; 231 d_set_d_op(ret, server->nfs_client->rpc_ops->dentry_ops);
289 232
233out:
234 nfs_free_fattr(fattr);
290 dprintk("<-- nfs4_get_root()\n"); 235 dprintk("<-- nfs4_get_root()\n");
291 return mntroot; 236 return ret;
292} 237}
293 238
294#endif /* CONFIG_NFS_V4 */ 239#endif /* CONFIG_NFS_V4 */
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 86147b0ab2cf..18696882f1c6 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -34,6 +34,212 @@
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
38
39#include <linux/slab.h>
40#include <linux/cred.h>
41#include <linux/nfs_idmap.h>
42#include <linux/keyctl.h>
43#include <linux/key-type.h>
44#include <linux/rcupdate.h>
45#include <linux/kernel.h>
46#include <linux/err.h>
47
48#include <keys/user-type.h>
49
50#define NFS_UINT_MAXLEN 11
51
52const struct cred *id_resolver_cache;
53
54struct key_type key_type_id_resolver = {
55 .name = "id_resolver",
56 .instantiate = user_instantiate,
57 .match = user_match,
58 .revoke = user_revoke,
59 .destroy = user_destroy,
60 .describe = user_describe,
61 .read = user_read,
62};
63
64int nfs_idmap_init(void)
65{
66 struct cred *cred;
67 struct key *keyring;
68 int ret = 0;
69
70 printk(KERN_NOTICE "Registering the %s key type\n", key_type_id_resolver.name);
71
72 cred = prepare_kernel_cred(NULL);
73 if (!cred)
74 return -ENOMEM;
75
76 keyring = key_alloc(&key_type_keyring, ".id_resolver", 0, 0, cred,
77 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
78 KEY_USR_VIEW | KEY_USR_READ,
79 KEY_ALLOC_NOT_IN_QUOTA);
80 if (IS_ERR(keyring)) {
81 ret = PTR_ERR(keyring);
82 goto failed_put_cred;
83 }
84
85 ret = key_instantiate_and_link(keyring, NULL, 0, NULL, NULL);
86 if (ret < 0)
87 goto failed_put_key;
88
89 ret = register_key_type(&key_type_id_resolver);
90 if (ret < 0)
91 goto failed_put_key;
92
93 cred->thread_keyring = keyring;
94 cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING;
95 id_resolver_cache = cred;
96 return 0;
97
98failed_put_key:
99 key_put(keyring);
100failed_put_cred:
101 put_cred(cred);
102 return ret;
103}
104
105void nfs_idmap_quit(void)
106{
107 key_revoke(id_resolver_cache->thread_keyring);
108 unregister_key_type(&key_type_id_resolver);
109 put_cred(id_resolver_cache);
110}
111
112/*
113 * Assemble the description to pass to request_key()
114 * This function will allocate a new string and update dest to point
115 * at it. The caller is responsible for freeing dest.
116 *
117 * On error 0 is returned. Otherwise, the length of dest is returned.
118 */
119static ssize_t nfs_idmap_get_desc(const char *name, size_t namelen,
120 const char *type, size_t typelen, char **desc)
121{
122 char *cp;
123 size_t desclen = typelen + namelen + 2;
124
125 *desc = kmalloc(desclen, GFP_KERNEL);
126 if (!*desc)
127 return -ENOMEM;
128
129 cp = *desc;
130 memcpy(cp, type, typelen);
131 cp += typelen;
132 *cp++ = ':';
133
134 memcpy(cp, name, namelen);
135 cp += namelen;
136 *cp = '\0';
137 return desclen;
138}
139
140static ssize_t nfs_idmap_request_key(const char *name, size_t namelen,
141 const char *type, void *data, size_t data_size)
142{
143 const struct cred *saved_cred;
144 struct key *rkey;
145 char *desc;
146 struct user_key_payload *payload;
147 ssize_t ret;
148
149 ret = nfs_idmap_get_desc(name, namelen, type, strlen(type), &desc);
150 if (ret <= 0)
151 goto out;
152
153 saved_cred = override_creds(id_resolver_cache);
154 rkey = request_key(&key_type_id_resolver, desc, "");
155 revert_creds(saved_cred);
156 kfree(desc);
157 if (IS_ERR(rkey)) {
158 ret = PTR_ERR(rkey);
159 goto out;
160 }
161
162 rcu_read_lock();
163 rkey->perm |= KEY_USR_VIEW;
164
165 ret = key_validate(rkey);
166 if (ret < 0)
167 goto out_up;
168
169 payload = rcu_dereference(rkey->payload.data);
170 if (IS_ERR_OR_NULL(payload)) {
171 ret = PTR_ERR(payload);
172 goto out_up;
173 }
174
175 ret = payload->datalen;
176 if (ret > 0 && ret <= data_size)
177 memcpy(data, payload->data, ret);
178 else
179 ret = -EINVAL;
180
181out_up:
182 rcu_read_unlock();
183 key_put(rkey);
184out:
185 return ret;
186}
187
188
189/* ID -> Name */
190static ssize_t nfs_idmap_lookup_name(__u32 id, const char *type, char *buf, size_t buflen)
191{
192 char id_str[NFS_UINT_MAXLEN];
193 int id_len;
194 ssize_t ret;
195
196 id_len = snprintf(id_str, sizeof(id_str), "%u", id);
197 ret = nfs_idmap_request_key(id_str, id_len, type, buf, buflen);
198 if (ret < 0)
199 return -EINVAL;
200 return ret;
201}
202
203/* Name -> ID */
204static int nfs_idmap_lookup_id(const char *name, size_t namelen,
205 const char *type, __u32 *id)
206{
207 char id_str[NFS_UINT_MAXLEN];
208 long id_long;
209 ssize_t data_size;
210 int ret = 0;
211
212 data_size = nfs_idmap_request_key(name, namelen, type, id_str, NFS_UINT_MAXLEN);
213 if (data_size <= 0) {
214 ret = -EINVAL;
215 } else {
216 ret = strict_strtol(id_str, 10, &id_long);
217 *id = (__u32)id_long;
218 }
219 return ret;
220}
221
222int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *uid)
223{
224 return nfs_idmap_lookup_id(name, namelen, "uid", uid);
225}
226
227int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *gid)
228{
229 return nfs_idmap_lookup_id(name, namelen, "gid", gid);
230}
231
232int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen)
233{
234 return nfs_idmap_lookup_name(uid, "user", buf, buflen);
235}
236int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t buflen)
237{
238 return nfs_idmap_lookup_name(gid, "group", buf, buflen);
239}
240
241#else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
242
37#include <linux/module.h> 243#include <linux/module.h>
38#include <linux/mutex.h> 244#include <linux/mutex.h>
39#include <linux/init.h> 245#include <linux/init.h>
@@ -101,7 +307,7 @@ static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *);
101 307
102static unsigned int fnvhash32(const void *, size_t); 308static unsigned int fnvhash32(const void *, size_t);
103 309
104static struct rpc_pipe_ops idmap_upcall_ops = { 310static const struct rpc_pipe_ops idmap_upcall_ops = {
105 .upcall = idmap_pipe_upcall, 311 .upcall = idmap_pipe_upcall,
106 .downcall = idmap_pipe_downcall, 312 .downcall = idmap_pipe_downcall,
107 .destroy_msg = idmap_pipe_destroy_msg, 313 .destroy_msg = idmap_pipe_destroy_msg,
@@ -119,8 +325,8 @@ nfs_idmap_new(struct nfs_client *clp)
119 if (idmap == NULL) 325 if (idmap == NULL)
120 return -ENOMEM; 326 return -ENOMEM;
121 327
122 idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_dentry, "idmap", 328 idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_path.dentry,
123 idmap, &idmap_upcall_ops, 0); 329 "idmap", idmap, &idmap_upcall_ops, 0);
124 if (IS_ERR(idmap->idmap_dentry)) { 330 if (IS_ERR(idmap->idmap_dentry)) {
125 error = PTR_ERR(idmap->idmap_dentry); 331 error = PTR_ERR(idmap->idmap_dentry);
126 kfree(idmap); 332 kfree(idmap);
@@ -503,16 +709,17 @@ int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namele
503 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid); 709 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid);
504} 710}
505 711
506int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf) 712int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen)
507{ 713{
508 struct idmap *idmap = clp->cl_idmap; 714 struct idmap *idmap = clp->cl_idmap;
509 715
510 return nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); 716 return nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf);
511} 717}
512int nfs_map_gid_to_group(struct nfs_client *clp, __u32 uid, char *buf) 718int nfs_map_gid_to_group(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen)
513{ 719{
514 struct idmap *idmap = clp->cl_idmap; 720 struct idmap *idmap = clp->cl_idmap;
515 721
516 return nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); 722 return nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf);
517} 723}
518 724
725#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 64f87194d390..ce00b704452c 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -30,13 +30,13 @@
30#include <linux/nfs_mount.h> 30#include <linux/nfs_mount.h>
31#include <linux/nfs4_mount.h> 31#include <linux/nfs4_mount.h>
32#include <linux/lockd/bind.h> 32#include <linux/lockd/bind.h>
33#include <linux/smp_lock.h>
34#include <linux/seq_file.h> 33#include <linux/seq_file.h>
35#include <linux/mount.h> 34#include <linux/mount.h>
36#include <linux/nfs_idmap.h> 35#include <linux/nfs_idmap.h>
37#include <linux/vfs.h> 36#include <linux/vfs.h>
38#include <linux/inet.h> 37#include <linux/inet.h>
39#include <linux/nfs_xdr.h> 38#include <linux/nfs_xdr.h>
39#include <linux/slab.h>
40 40
41#include <asm/system.h> 41#include <asm/system.h>
42#include <asm/uaccess.h> 42#include <asm/uaccess.h>
@@ -47,6 +47,8 @@
47#include "iostat.h" 47#include "iostat.h"
48#include "internal.h" 48#include "internal.h"
49#include "fscache.h" 49#include "fscache.h"
50#include "dns_resolve.h"
51#include "pnfs.h"
50 52
51#define NFSDBG_FACILITY NFSDBG_VFS 53#define NFSDBG_FACILITY NFSDBG_VFS
52 54
@@ -97,23 +99,7 @@ u64 nfs_compat_user_ino64(u64 fileid)
97 return ino; 99 return ino;
98} 100}
99 101
100int nfs_write_inode(struct inode *inode, int sync) 102static void nfs_clear_inode(struct inode *inode)
101{
102 int ret;
103
104 if (sync) {
105 ret = filemap_fdatawait(inode->i_mapping);
106 if (ret == 0)
107 ret = nfs_commit_inode(inode, FLUSH_SYNC);
108 } else
109 ret = nfs_commit_inode(inode, 0);
110 if (ret >= 0)
111 return 0;
112 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
113 return ret;
114}
115
116void nfs_clear_inode(struct inode *inode)
117{ 103{
118 /* 104 /*
119 * The following should never happen... 105 * The following should never happen...
@@ -125,21 +111,24 @@ void nfs_clear_inode(struct inode *inode)
125 nfs_fscache_release_inode_cookie(inode); 111 nfs_fscache_release_inode_cookie(inode);
126} 112}
127 113
114void nfs_evict_inode(struct inode *inode)
115{
116 truncate_inode_pages(&inode->i_data, 0);
117 end_writeback(inode);
118 nfs_clear_inode(inode);
119}
120
128/** 121/**
129 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk 122 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
130 */ 123 */
131int nfs_sync_mapping(struct address_space *mapping) 124int nfs_sync_mapping(struct address_space *mapping)
132{ 125{
133 int ret; 126 int ret = 0;
134 127
135 if (mapping->nrpages == 0) 128 if (mapping->nrpages != 0) {
136 return 0; 129 unmap_mapping_range(mapping, 0, 0, 0);
137 unmap_mapping_range(mapping, 0, 0, 0); 130 ret = nfs_wb_all(mapping->host);
138 ret = filemap_write_and_wait(mapping); 131 }
139 if (ret != 0)
140 goto out;
141 ret = nfs_wb_all(mapping->host);
142out:
143 return ret; 132 return ret;
144} 133}
145 134
@@ -246,9 +235,6 @@ nfs_init_locked(struct inode *inode, void *opaque)
246 return 0; 235 return 0;
247} 236}
248 237
249/* Don't use READDIRPLUS on directories that we believe are too large */
250#define NFS_LIMIT_READDIRPLUS (8*PAGE_SIZE)
251
252/* 238/*
253 * This is our front-end to iget that looks up inodes by file handle 239 * This is our front-end to iget that looks up inodes by file handle
254 * instead of inode number. 240 * instead of inode number.
@@ -287,6 +273,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
287 /* We can't support update_atime(), since the server will reset it */ 273 /* We can't support update_atime(), since the server will reset it */
288 inode->i_flags |= S_NOATIME|S_NOCMTIME; 274 inode->i_flags |= S_NOATIME|S_NOCMTIME;
289 inode->i_mode = fattr->mode; 275 inode->i_mode = fattr->mode;
276 if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0
277 && nfs_server_capable(inode, NFS_CAP_MODE))
278 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
279 | NFS_INO_INVALID_ACCESS
280 | NFS_INO_INVALID_ACL;
290 /* Why so? Because we want revalidate for devices/FIFOs, and 281 /* Why so? Because we want revalidate for devices/FIFOs, and
291 * that's precisely what we have in nfs_file_inode_operations. 282 * that's precisely what we have in nfs_file_inode_operations.
292 */ 283 */
@@ -298,8 +289,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
298 } else if (S_ISDIR(inode->i_mode)) { 289 } else if (S_ISDIR(inode->i_mode)) {
299 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops; 290 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
300 inode->i_fop = &nfs_dir_operations; 291 inode->i_fop = &nfs_dir_operations;
301 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS) 292 inode->i_data.a_ops = &nfs_dir_aops;
302 && fattr->size <= NFS_LIMIT_READDIRPLUS) 293 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS))
303 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags); 294 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
304 /* Deal with crossing mountpoints */ 295 /* Deal with crossing mountpoints */
305 if ((fattr->valid & NFS_ATTR_FATTR_FSID) 296 if ((fattr->valid & NFS_ATTR_FATTR_FSID)
@@ -331,20 +322,46 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
331 nfsi->attr_gencount = fattr->gencount; 322 nfsi->attr_gencount = fattr->gencount;
332 if (fattr->valid & NFS_ATTR_FATTR_ATIME) 323 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
333 inode->i_atime = fattr->atime; 324 inode->i_atime = fattr->atime;
325 else if (nfs_server_capable(inode, NFS_CAP_ATIME))
326 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
334 if (fattr->valid & NFS_ATTR_FATTR_MTIME) 327 if (fattr->valid & NFS_ATTR_FATTR_MTIME)
335 inode->i_mtime = fattr->mtime; 328 inode->i_mtime = fattr->mtime;
329 else if (nfs_server_capable(inode, NFS_CAP_MTIME))
330 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
331 | NFS_INO_INVALID_DATA;
336 if (fattr->valid & NFS_ATTR_FATTR_CTIME) 332 if (fattr->valid & NFS_ATTR_FATTR_CTIME)
337 inode->i_ctime = fattr->ctime; 333 inode->i_ctime = fattr->ctime;
334 else if (nfs_server_capable(inode, NFS_CAP_CTIME))
335 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
336 | NFS_INO_INVALID_ACCESS
337 | NFS_INO_INVALID_ACL;
338 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) 338 if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
339 nfsi->change_attr = fattr->change_attr; 339 nfsi->change_attr = fattr->change_attr;
340 else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR))
341 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
342 | NFS_INO_INVALID_DATA;
340 if (fattr->valid & NFS_ATTR_FATTR_SIZE) 343 if (fattr->valid & NFS_ATTR_FATTR_SIZE)
341 inode->i_size = nfs_size_to_loff_t(fattr->size); 344 inode->i_size = nfs_size_to_loff_t(fattr->size);
345 else
346 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
347 | NFS_INO_INVALID_DATA
348 | NFS_INO_REVAL_PAGECACHE;
342 if (fattr->valid & NFS_ATTR_FATTR_NLINK) 349 if (fattr->valid & NFS_ATTR_FATTR_NLINK)
343 inode->i_nlink = fattr->nlink; 350 inode->i_nlink = fattr->nlink;
351 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
352 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
344 if (fattr->valid & NFS_ATTR_FATTR_OWNER) 353 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
345 inode->i_uid = fattr->uid; 354 inode->i_uid = fattr->uid;
355 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
356 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
357 | NFS_INO_INVALID_ACCESS
358 | NFS_INO_INVALID_ACL;
346 if (fattr->valid & NFS_ATTR_FATTR_GROUP) 359 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
347 inode->i_gid = fattr->gid; 360 inode->i_gid = fattr->gid;
361 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
362 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
363 | NFS_INO_INVALID_ACCESS
364 | NFS_INO_INVALID_ACL;
348 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) 365 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
349 inode->i_blocks = fattr->du.nfs2.blocks; 366 inode->i_blocks = fattr->du.nfs2.blocks;
350 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { 367 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
@@ -381,8 +398,8 @@ int
381nfs_setattr(struct dentry *dentry, struct iattr *attr) 398nfs_setattr(struct dentry *dentry, struct iattr *attr)
382{ 399{
383 struct inode *inode = dentry->d_inode; 400 struct inode *inode = dentry->d_inode;
384 struct nfs_fattr fattr; 401 struct nfs_fattr *fattr;
385 int error; 402 int error = -ENOMEM;
386 403
387 nfs_inc_stats(inode, NFSIOS_VFSSETATTR); 404 nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
388 405
@@ -401,18 +418,22 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
401 return 0; 418 return 0;
402 419
403 /* Write all dirty data */ 420 /* Write all dirty data */
404 if (S_ISREG(inode->i_mode)) { 421 if (S_ISREG(inode->i_mode))
405 filemap_write_and_wait(inode->i_mapping);
406 nfs_wb_all(inode); 422 nfs_wb_all(inode);
407 } 423
424 fattr = nfs_alloc_fattr();
425 if (fattr == NULL)
426 goto out;
408 /* 427 /*
409 * Return any delegations if we're going to change ACLs 428 * Return any delegations if we're going to change ACLs
410 */ 429 */
411 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) 430 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
412 nfs_inode_return_delegation(inode); 431 nfs_inode_return_delegation(inode);
413 error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr); 432 error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
414 if (error == 0) 433 if (error == 0)
415 nfs_refresh_inode(inode, &fattr); 434 nfs_refresh_inode(inode, fattr);
435 nfs_free_fattr(fattr);
436out:
416 return error; 437 return error;
417} 438}
418 439
@@ -427,49 +448,21 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
427 */ 448 */
428static int nfs_vmtruncate(struct inode * inode, loff_t offset) 449static int nfs_vmtruncate(struct inode * inode, loff_t offset)
429{ 450{
430 if (i_size_read(inode) < offset) { 451 loff_t oldsize;
431 unsigned long limit; 452 int err;
432 453
433 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; 454 err = inode_newsize_ok(inode, offset);
434 if (limit != RLIM_INFINITY && offset > limit) 455 if (err)
435 goto out_sig; 456 goto out;
436 if (offset > inode->i_sb->s_maxbytes)
437 goto out_big;
438 spin_lock(&inode->i_lock);
439 i_size_write(inode, offset);
440 spin_unlock(&inode->i_lock);
441 } else {
442 struct address_space *mapping = inode->i_mapping;
443 457
444 /* 458 spin_lock(&inode->i_lock);
445 * truncation of in-use swapfiles is disallowed - it would 459 oldsize = inode->i_size;
446 * cause subsequent swapout to scribble on the now-freed 460 i_size_write(inode, offset);
447 * blocks. 461 spin_unlock(&inode->i_lock);
448 */
449 if (IS_SWAPFILE(inode))
450 return -ETXTBSY;
451 spin_lock(&inode->i_lock);
452 i_size_write(inode, offset);
453 spin_unlock(&inode->i_lock);
454 462
455 /* 463 truncate_pagecache(inode, oldsize, offset);
456 * unmap_mapping_range is called twice, first simply for 464out:
457 * efficiency so that truncate_inode_pages does fewer 465 return err;
458 * single-page unmaps. However after this first call, and
459 * before truncate_inode_pages finishes, it is possible for
460 * private pages to be COWed, which remain after
461 * truncate_inode_pages finishes, hence the second
462 * unmap_mapping_range call must be made for correctness.
463 */
464 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
465 truncate_inode_pages(mapping, offset);
466 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
467 }
468 return 0;
469out_sig:
470 send_sig(SIGXFSZ, current, 0);
471out_big:
472 return -EFBIG;
473} 466}
474 467
475/** 468/**
@@ -508,17 +501,11 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
508 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 501 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
509 int err; 502 int err;
510 503
511 /* 504 /* Flush out writes to the server in order to update c/mtime. */
512 * Flush out writes to the server in order to update c/mtime.
513 *
514 * Hold the i_mutex to suspend application writes temporarily;
515 * this prevents long-running writing applications from blocking
516 * nfs_wb_nocommit.
517 */
518 if (S_ISREG(inode->i_mode)) { 505 if (S_ISREG(inode->i_mode)) {
519 mutex_lock(&inode->i_mutex); 506 err = filemap_write_and_wait(inode->i_mapping);
520 nfs_wb_nocommit(inode); 507 if (err)
521 mutex_unlock(&inode->i_mutex); 508 goto out;
522 } 509 }
523 510
524 /* 511 /*
@@ -542,9 +529,72 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
542 generic_fillattr(inode, stat); 529 generic_fillattr(inode, stat);
543 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode)); 530 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
544 } 531 }
532out:
545 return err; 533 return err;
546} 534}
547 535
536static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
537{
538 atomic_set(&l_ctx->count, 1);
539 l_ctx->lockowner = current->files;
540 l_ctx->pid = current->tgid;
541 INIT_LIST_HEAD(&l_ctx->list);
542}
543
544static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
545{
546 struct nfs_lock_context *pos;
547
548 list_for_each_entry(pos, &ctx->lock_context.list, list) {
549 if (pos->lockowner != current->files)
550 continue;
551 if (pos->pid != current->tgid)
552 continue;
553 atomic_inc(&pos->count);
554 return pos;
555 }
556 return NULL;
557}
558
559struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
560{
561 struct nfs_lock_context *res, *new = NULL;
562 struct inode *inode = ctx->path.dentry->d_inode;
563
564 spin_lock(&inode->i_lock);
565 res = __nfs_find_lock_context(ctx);
566 if (res == NULL) {
567 spin_unlock(&inode->i_lock);
568 new = kmalloc(sizeof(*new), GFP_KERNEL);
569 if (new == NULL)
570 return NULL;
571 nfs_init_lock_context(new);
572 spin_lock(&inode->i_lock);
573 res = __nfs_find_lock_context(ctx);
574 if (res == NULL) {
575 list_add_tail(&new->list, &ctx->lock_context.list);
576 new->open_context = ctx;
577 res = new;
578 new = NULL;
579 }
580 }
581 spin_unlock(&inode->i_lock);
582 kfree(new);
583 return res;
584}
585
586void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
587{
588 struct nfs_open_context *ctx = l_ctx->open_context;
589 struct inode *inode = ctx->path.dentry->d_inode;
590
591 if (!atomic_dec_and_lock(&l_ctx->count, &inode->i_lock))
592 return;
593 list_del(&l_ctx->list);
594 spin_unlock(&inode->i_lock);
595 kfree(l_ctx);
596}
597
548/** 598/**
549 * nfs_close_context - Common close_context() routine NFSv2/v3 599 * nfs_close_context - Common close_context() routine NFSv2/v3
550 * @ctx: pointer to context 600 * @ctx: pointer to context
@@ -571,21 +621,23 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
571 nfs_revalidate_inode(server, inode); 621 nfs_revalidate_inode(server, inode);
572} 622}
573 623
574static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, struct dentry *dentry, struct rpc_cred *cred) 624struct nfs_open_context *alloc_nfs_open_context(struct path *path, struct rpc_cred *cred, fmode_t f_mode)
575{ 625{
576 struct nfs_open_context *ctx; 626 struct nfs_open_context *ctx;
577 627
578 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 628 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
579 if (ctx != NULL) { 629 if (ctx != NULL) {
580 ctx->path.dentry = dget(dentry); 630 ctx->path = *path;
581 ctx->path.mnt = mntget(mnt); 631 path_get(&ctx->path);
582 ctx->cred = get_rpccred(cred); 632 ctx->cred = get_rpccred(cred);
583 ctx->state = NULL; 633 ctx->state = NULL;
584 ctx->lockowner = current->files; 634 ctx->mode = f_mode;
585 ctx->flags = 0; 635 ctx->flags = 0;
586 ctx->error = 0; 636 ctx->error = 0;
587 ctx->dir_cookie = 0; 637 ctx->dir_cookie = 0;
588 atomic_set(&ctx->count, 1); 638 nfs_init_lock_context(&ctx->lock_context);
639 ctx->lock_context.open_context = ctx;
640 INIT_LIST_HEAD(&ctx->list);
589 } 641 }
590 return ctx; 642 return ctx;
591} 643}
@@ -593,7 +645,7 @@ static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, str
593struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx) 645struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
594{ 646{
595 if (ctx != NULL) 647 if (ctx != NULL)
596 atomic_inc(&ctx->count); 648 atomic_inc(&ctx->lock_context.count);
597 return ctx; 649 return ctx;
598} 650}
599 651
@@ -601,11 +653,15 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
601{ 653{
602 struct inode *inode = ctx->path.dentry->d_inode; 654 struct inode *inode = ctx->path.dentry->d_inode;
603 655
604 if (!atomic_dec_and_lock(&ctx->count, &inode->i_lock)) 656 if (!list_empty(&ctx->list)) {
657 if (!atomic_dec_and_lock(&ctx->lock_context.count, &inode->i_lock))
658 return;
659 list_del(&ctx->list);
660 spin_unlock(&inode->i_lock);
661 } else if (!atomic_dec_and_test(&ctx->lock_context.count))
605 return; 662 return;
606 list_del(&ctx->list); 663 if (inode != NULL)
607 spin_unlock(&inode->i_lock); 664 NFS_PROTO(inode)->close_context(ctx, is_sync);
608 NFS_PROTO(inode)->close_context(ctx, is_sync);
609 if (ctx->cred != NULL) 665 if (ctx->cred != NULL)
610 put_rpccred(ctx->cred); 666 put_rpccred(ctx->cred);
611 path_put(&ctx->path); 667 path_put(&ctx->path);
@@ -617,16 +673,11 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
617 __put_nfs_open_context(ctx, 0); 673 __put_nfs_open_context(ctx, 0);
618} 674}
619 675
620static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
621{
622 __put_nfs_open_context(ctx, 1);
623}
624
625/* 676/*
626 * Ensure that mmap has a recent RPC credential for use when writing out 677 * Ensure that mmap has a recent RPC credential for use when writing out
627 * shared pages 678 * shared pages
628 */ 679 */
629static void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx) 680void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
630{ 681{
631 struct inode *inode = filp->f_path.dentry->d_inode; 682 struct inode *inode = filp->f_path.dentry->d_inode;
632 struct nfs_inode *nfsi = NFS_I(inode); 683 struct nfs_inode *nfsi = NFS_I(inode);
@@ -649,10 +700,10 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_c
649 list_for_each_entry(pos, &nfsi->open_files, list) { 700 list_for_each_entry(pos, &nfsi->open_files, list) {
650 if (cred != NULL && pos->cred != cred) 701 if (cred != NULL && pos->cred != cred)
651 continue; 702 continue;
652 if ((pos->mode & mode) == mode) { 703 if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
653 ctx = get_nfs_open_context(pos); 704 continue;
654 break; 705 ctx = get_nfs_open_context(pos);
655 } 706 break;
656 } 707 }
657 spin_unlock(&inode->i_lock); 708 spin_unlock(&inode->i_lock);
658 return ctx; 709 return ctx;
@@ -668,7 +719,7 @@ static void nfs_file_clear_open_context(struct file *filp)
668 spin_lock(&inode->i_lock); 719 spin_lock(&inode->i_lock);
669 list_move_tail(&ctx->list, &NFS_I(inode)->open_files); 720 list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
670 spin_unlock(&inode->i_lock); 721 spin_unlock(&inode->i_lock);
671 put_nfs_open_context_sync(ctx); 722 __put_nfs_open_context(ctx, filp->f_flags & O_DIRECT ? 0 : 1);
672 } 723 }
673} 724}
674 725
@@ -683,11 +734,10 @@ int nfs_open(struct inode *inode, struct file *filp)
683 cred = rpc_lookup_cred(); 734 cred = rpc_lookup_cred();
684 if (IS_ERR(cred)) 735 if (IS_ERR(cred))
685 return PTR_ERR(cred); 736 return PTR_ERR(cred);
686 ctx = alloc_nfs_open_context(filp->f_path.mnt, filp->f_path.dentry, cred); 737 ctx = alloc_nfs_open_context(&filp->f_path, cred, filp->f_mode);
687 put_rpccred(cred); 738 put_rpccred(cred);
688 if (ctx == NULL) 739 if (ctx == NULL)
689 return -ENOMEM; 740 return -ENOMEM;
690 ctx->mode = filp->f_mode;
691 nfs_file_set_open_context(filp, ctx); 741 nfs_file_set_open_context(filp, ctx);
692 put_nfs_open_context(ctx); 742 put_nfs_open_context(ctx);
693 nfs_fscache_set_inode_cookie(inode, filp); 743 nfs_fscache_set_inode_cookie(inode, filp);
@@ -708,7 +758,7 @@ int
708__nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) 758__nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
709{ 759{
710 int status = -ESTALE; 760 int status = -ESTALE;
711 struct nfs_fattr fattr; 761 struct nfs_fattr *fattr = NULL;
712 struct nfs_inode *nfsi = NFS_I(inode); 762 struct nfs_inode *nfsi = NFS_I(inode);
713 763
714 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n", 764 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
@@ -719,8 +769,13 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
719 if (NFS_STALE(inode)) 769 if (NFS_STALE(inode))
720 goto out; 770 goto out;
721 771
772 status = -ENOMEM;
773 fattr = nfs_alloc_fattr();
774 if (fattr == NULL)
775 goto out;
776
722 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE); 777 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
723 status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), &fattr); 778 status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr);
724 if (status != 0) { 779 if (status != 0) {
725 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n", 780 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n",
726 inode->i_sb->s_id, 781 inode->i_sb->s_id,
@@ -733,7 +788,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
733 goto out; 788 goto out;
734 } 789 }
735 790
736 status = nfs_refresh_inode(inode, &fattr); 791 status = nfs_refresh_inode(inode, fattr);
737 if (status) { 792 if (status) {
738 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n", 793 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n",
739 inode->i_sb->s_id, 794 inode->i_sb->s_id,
@@ -749,6 +804,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
749 (long long)NFS_FILEID(inode)); 804 (long long)NFS_FILEID(inode));
750 805
751 out: 806 out:
807 nfs_free_fattr(fattr);
752 return status; 808 return status;
753} 809}
754 810
@@ -756,11 +812,16 @@ int nfs_attribute_timeout(struct inode *inode)
756{ 812{
757 struct nfs_inode *nfsi = NFS_I(inode); 813 struct nfs_inode *nfsi = NFS_I(inode);
758 814
759 if (nfs_have_delegation(inode, FMODE_READ))
760 return 0;
761 return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo); 815 return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
762} 816}
763 817
818static int nfs_attribute_cache_expired(struct inode *inode)
819{
820 if (nfs_have_delegated_attributes(inode))
821 return 0;
822 return nfs_attribute_timeout(inode);
823}
824
764/** 825/**
765 * nfs_revalidate_inode - Revalidate the inode attributes 826 * nfs_revalidate_inode - Revalidate the inode attributes
766 * @server - pointer to nfs_server struct 827 * @server - pointer to nfs_server struct
@@ -771,12 +832,12 @@ int nfs_attribute_timeout(struct inode *inode)
771int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) 832int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
772{ 833{
773 if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR) 834 if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
774 && !nfs_attribute_timeout(inode)) 835 && !nfs_attribute_cache_expired(inode))
775 return NFS_STALE(inode) ? -ESTALE : 0; 836 return NFS_STALE(inode) ? -ESTALE : 0;
776 return __nfs_revalidate_inode(server, inode); 837 return __nfs_revalidate_inode(server, inode);
777} 838}
778 839
779static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_space *mapping) 840static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
780{ 841{
781 struct nfs_inode *nfsi = NFS_I(inode); 842 struct nfs_inode *nfsi = NFS_I(inode);
782 843
@@ -797,49 +858,10 @@ static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_spa
797 return 0; 858 return 0;
798} 859}
799 860
800static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
801{
802 int ret = 0;
803
804 mutex_lock(&inode->i_mutex);
805 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_DATA) {
806 ret = nfs_sync_mapping(mapping);
807 if (ret == 0)
808 ret = nfs_invalidate_mapping_nolock(inode, mapping);
809 }
810 mutex_unlock(&inode->i_mutex);
811 return ret;
812}
813
814/**
815 * nfs_revalidate_mapping_nolock - Revalidate the pagecache
816 * @inode - pointer to host inode
817 * @mapping - pointer to mapping
818 */
819int nfs_revalidate_mapping_nolock(struct inode *inode, struct address_space *mapping)
820{
821 struct nfs_inode *nfsi = NFS_I(inode);
822 int ret = 0;
823
824 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
825 || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
826 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
827 if (ret < 0)
828 goto out;
829 }
830 if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
831 ret = nfs_invalidate_mapping_nolock(inode, mapping);
832out:
833 return ret;
834}
835
836/** 861/**
837 * nfs_revalidate_mapping - Revalidate the pagecache 862 * nfs_revalidate_mapping - Revalidate the pagecache
838 * @inode - pointer to host inode 863 * @inode - pointer to host inode
839 * @mapping - pointer to mapping 864 * @mapping - pointer to mapping
840 *
841 * This version of the function will take the inode->i_mutex and attempt to
842 * flush out all dirty data if it needs to invalidate the page cache.
843 */ 865 */
844int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) 866int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
845{ 867{
@@ -847,7 +869,8 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
847 int ret = 0; 869 int ret = 0;
848 870
849 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) 871 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
850 || nfs_attribute_timeout(inode) || NFS_STALE(inode)) { 872 || nfs_attribute_cache_expired(inode)
873 || NFS_STALE(inode)) {
851 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode); 874 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
852 if (ret < 0) 875 if (ret < 0)
853 goto out; 876 goto out;
@@ -981,6 +1004,26 @@ void nfs_fattr_init(struct nfs_fattr *fattr)
981 fattr->gencount = nfs_inc_attr_generation_counter(); 1004 fattr->gencount = nfs_inc_attr_generation_counter();
982} 1005}
983 1006
1007struct nfs_fattr *nfs_alloc_fattr(void)
1008{
1009 struct nfs_fattr *fattr;
1010
1011 fattr = kmalloc(sizeof(*fattr), GFP_NOFS);
1012 if (fattr != NULL)
1013 nfs_fattr_init(fattr);
1014 return fattr;
1015}
1016
1017struct nfs_fh *nfs_alloc_fhandle(void)
1018{
1019 struct nfs_fh *fh;
1020
1021 fh = kmalloc(sizeof(struct nfs_fh), GFP_NOFS);
1022 if (fh != NULL)
1023 fh->size = 0;
1024 return fh;
1025}
1026
984/** 1027/**
985 * nfs_inode_attrs_need_update - check if the inode attributes need updating 1028 * nfs_inode_attrs_need_update - check if the inode attributes need updating
986 * @inode - pointer to inode 1029 * @inode - pointer to inode
@@ -1146,6 +1189,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1146 loff_t cur_isize, new_isize; 1189 loff_t cur_isize, new_isize;
1147 unsigned long invalid = 0; 1190 unsigned long invalid = 0;
1148 unsigned long now = jiffies; 1191 unsigned long now = jiffies;
1192 unsigned long save_cache_validity;
1149 1193
1150 dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", 1194 dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
1151 __func__, inode->i_sb->s_id, inode->i_ino, 1195 __func__, inode->i_sb->s_id, inode->i_ino,
@@ -1172,10 +1216,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1172 */ 1216 */
1173 nfsi->read_cache_jiffies = fattr->time_start; 1217 nfsi->read_cache_jiffies = fattr->time_start;
1174 1218
1175 if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) || (fattr->valid & (NFS_ATTR_FATTR_MTIME|NFS_ATTR_FATTR_CTIME))) 1219 save_cache_validity = nfsi->cache_validity;
1176 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR 1220 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
1177 | NFS_INO_INVALID_ATIME 1221 | NFS_INO_INVALID_ATIME
1178 | NFS_INO_REVAL_PAGECACHE); 1222 | NFS_INO_REVAL_FORCED
1223 | NFS_INO_REVAL_PAGECACHE);
1179 1224
1180 /* Do atomic weak cache consistency updates */ 1225 /* Do atomic weak cache consistency updates */
1181 nfs_wcc_update_inode(inode, fattr); 1226 nfs_wcc_update_inode(inode, fattr);
@@ -1190,7 +1235,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1190 nfs_force_lookup_revalidate(inode); 1235 nfs_force_lookup_revalidate(inode);
1191 nfsi->change_attr = fattr->change_attr; 1236 nfsi->change_attr = fattr->change_attr;
1192 } 1237 }
1193 } 1238 } else if (server->caps & NFS_CAP_CHANGE_ATTR)
1239 invalid |= save_cache_validity;
1194 1240
1195 if (fattr->valid & NFS_ATTR_FATTR_MTIME) { 1241 if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
1196 /* NFSv2/v3: Check if the mtime agrees */ 1242 /* NFSv2/v3: Check if the mtime agrees */
@@ -1202,7 +1248,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1202 nfs_force_lookup_revalidate(inode); 1248 nfs_force_lookup_revalidate(inode);
1203 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); 1249 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1204 } 1250 }
1205 } 1251 } else if (server->caps & NFS_CAP_MTIME)
1252 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1253 | NFS_INO_INVALID_DATA
1254 | NFS_INO_REVAL_PAGECACHE
1255 | NFS_INO_REVAL_FORCED);
1256
1206 if (fattr->valid & NFS_ATTR_FATTR_CTIME) { 1257 if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
1207 /* If ctime has changed we should definitely clear access+acl caches */ 1258 /* If ctime has changed we should definitely clear access+acl caches */
1208 if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) { 1259 if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) {
@@ -1216,7 +1267,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1216 } 1267 }
1217 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); 1268 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1218 } 1269 }
1219 } 1270 } else if (server->caps & NFS_CAP_CTIME)
1271 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1272 | NFS_INO_INVALID_ACCESS
1273 | NFS_INO_INVALID_ACL
1274 | NFS_INO_REVAL_FORCED);
1220 1275
1221 /* Check if our cached file size is stale */ 1276 /* Check if our cached file size is stale */
1222 if (fattr->valid & NFS_ATTR_FATTR_SIZE) { 1277 if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
@@ -1232,30 +1287,52 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1232 dprintk("NFS: isize change on server for file %s/%ld\n", 1287 dprintk("NFS: isize change on server for file %s/%ld\n",
1233 inode->i_sb->s_id, inode->i_ino); 1288 inode->i_sb->s_id, inode->i_ino);
1234 } 1289 }
1235 } 1290 } else
1291 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1292 | NFS_INO_REVAL_PAGECACHE
1293 | NFS_INO_REVAL_FORCED);
1236 1294
1237 1295
1238 if (fattr->valid & NFS_ATTR_FATTR_ATIME) 1296 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
1239 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime)); 1297 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
1298 else if (server->caps & NFS_CAP_ATIME)
1299 invalid |= save_cache_validity & (NFS_INO_INVALID_ATIME
1300 | NFS_INO_REVAL_FORCED);
1240 1301
1241 if (fattr->valid & NFS_ATTR_FATTR_MODE) { 1302 if (fattr->valid & NFS_ATTR_FATTR_MODE) {
1242 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { 1303 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
1304 umode_t newmode = inode->i_mode & S_IFMT;
1305 newmode |= fattr->mode & S_IALLUGO;
1306 inode->i_mode = newmode;
1243 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1307 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1244 inode->i_mode = fattr->mode;
1245 } 1308 }
1246 } 1309 } else if (server->caps & NFS_CAP_MODE)
1310 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1311 | NFS_INO_INVALID_ACCESS
1312 | NFS_INO_INVALID_ACL
1313 | NFS_INO_REVAL_FORCED);
1314
1247 if (fattr->valid & NFS_ATTR_FATTR_OWNER) { 1315 if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
1248 if (inode->i_uid != fattr->uid) { 1316 if (inode->i_uid != fattr->uid) {
1249 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1317 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1250 inode->i_uid = fattr->uid; 1318 inode->i_uid = fattr->uid;
1251 } 1319 }
1252 } 1320 } else if (server->caps & NFS_CAP_OWNER)
1321 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1322 | NFS_INO_INVALID_ACCESS
1323 | NFS_INO_INVALID_ACL
1324 | NFS_INO_REVAL_FORCED);
1325
1253 if (fattr->valid & NFS_ATTR_FATTR_GROUP) { 1326 if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
1254 if (inode->i_gid != fattr->gid) { 1327 if (inode->i_gid != fattr->gid) {
1255 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1328 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1256 inode->i_gid = fattr->gid; 1329 inode->i_gid = fattr->gid;
1257 } 1330 }
1258 } 1331 } else if (server->caps & NFS_CAP_OWNER_GROUP)
1332 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1333 | NFS_INO_INVALID_ACCESS
1334 | NFS_INO_INVALID_ACL
1335 | NFS_INO_REVAL_FORCED);
1259 1336
1260 if (fattr->valid & NFS_ATTR_FATTR_NLINK) { 1337 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
1261 if (inode->i_nlink != fattr->nlink) { 1338 if (inode->i_nlink != fattr->nlink) {
@@ -1264,7 +1341,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1264 invalid |= NFS_INO_INVALID_DATA; 1341 invalid |= NFS_INO_INVALID_DATA;
1265 inode->i_nlink = fattr->nlink; 1342 inode->i_nlink = fattr->nlink;
1266 } 1343 }
1267 } 1344 } else if (server->caps & NFS_CAP_NLINK)
1345 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
1346 | NFS_INO_REVAL_FORCED);
1268 1347
1269 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { 1348 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
1270 /* 1349 /*
@@ -1294,9 +1373,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1294 || S_ISLNK(inode->i_mode))) 1373 || S_ISLNK(inode->i_mode)))
1295 invalid &= ~NFS_INO_INVALID_DATA; 1374 invalid &= ~NFS_INO_INVALID_DATA;
1296 if (!nfs_have_delegation(inode, FMODE_READ) || 1375 if (!nfs_have_delegation(inode, FMODE_READ) ||
1297 (nfsi->cache_validity & NFS_INO_REVAL_FORCED)) 1376 (save_cache_validity & NFS_INO_REVAL_FORCED))
1298 nfsi->cache_validity |= invalid; 1377 nfsi->cache_validity |= invalid;
1299 nfsi->cache_validity &= ~NFS_INO_REVAL_FORCED;
1300 1378
1301 return 0; 1379 return 0;
1302 out_changed: 1380 out_changed:
@@ -1330,8 +1408,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1330 * to open() calls that passed nfs_atomic_lookup, but failed to call 1408 * to open() calls that passed nfs_atomic_lookup, but failed to call
1331 * nfs_open(). 1409 * nfs_open().
1332 */ 1410 */
1333void nfs4_clear_inode(struct inode *inode) 1411void nfs4_evict_inode(struct inode *inode)
1334{ 1412{
1413 pnfs_destroy_layout(NFS_I(inode));
1414 truncate_inode_pages(&inode->i_data, 0);
1415 end_writeback(inode);
1335 /* If we are holding a delegation, return it! */ 1416 /* If we are holding a delegation, return it! */
1336 nfs_inode_return_delegation_noreclaim(inode); 1417 nfs_inode_return_delegation_noreclaim(inode);
1337 /* First call standard NFS clear_inode() code */ 1418 /* First call standard NFS clear_inode() code */
@@ -1357,11 +1438,18 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
1357 return &nfsi->vfs_inode; 1438 return &nfsi->vfs_inode;
1358} 1439}
1359 1440
1360void nfs_destroy_inode(struct inode *inode) 1441static void nfs_i_callback(struct rcu_head *head)
1361{ 1442{
1443 struct inode *inode = container_of(head, struct inode, i_rcu);
1444 INIT_LIST_HEAD(&inode->i_dentry);
1362 kmem_cache_free(nfs_inode_cachep, NFS_I(inode)); 1445 kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
1363} 1446}
1364 1447
1448void nfs_destroy_inode(struct inode *inode)
1449{
1450 call_rcu(&inode->i_rcu, nfs_i_callback);
1451}
1452
1365static inline void nfs4_init_once(struct nfs_inode *nfsi) 1453static inline void nfs4_init_once(struct nfs_inode *nfsi)
1366{ 1454{
1367#ifdef CONFIG_NFS_V4 1455#ifdef CONFIG_NFS_V4
@@ -1369,6 +1457,7 @@ static inline void nfs4_init_once(struct nfs_inode *nfsi)
1369 nfsi->delegation = NULL; 1457 nfsi->delegation = NULL;
1370 nfsi->delegation_state = 0; 1458 nfsi->delegation_state = 0;
1371 init_rwsem(&nfsi->rwsem); 1459 init_rwsem(&nfsi->rwsem);
1460 nfsi->layout = NULL;
1372#endif 1461#endif
1373} 1462}
1374 1463
@@ -1382,6 +1471,7 @@ static void init_once(void *foo)
1382 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru); 1471 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
1383 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC); 1472 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
1384 nfsi->npages = 0; 1473 nfsi->npages = 0;
1474 nfsi->ncommit = 0;
1385 atomic_set(&nfsi->silly_count, 1); 1475 atomic_set(&nfsi->silly_count, 1);
1386 INIT_HLIST_HEAD(&nfsi->silly_list); 1476 INIT_HLIST_HEAD(&nfsi->silly_list);
1387 init_waitqueue_head(&nfsi->waitqueue); 1477 init_waitqueue_head(&nfsi->waitqueue);
@@ -1415,7 +1505,7 @@ static int nfsiod_start(void)
1415{ 1505{
1416 struct workqueue_struct *wq; 1506 struct workqueue_struct *wq;
1417 dprintk("RPC: creating workqueue nfsiod\n"); 1507 dprintk("RPC: creating workqueue nfsiod\n");
1418 wq = create_singlethread_workqueue("nfsiod"); 1508 wq = alloc_workqueue("nfsiod", WQ_RESCUER, 0);
1419 if (wq == NULL) 1509 if (wq == NULL)
1420 return -ENOMEM; 1510 return -ENOMEM;
1421 nfsiod_workqueue = wq; 1511 nfsiod_workqueue = wq;
@@ -1443,6 +1533,14 @@ static int __init init_nfs_fs(void)
1443{ 1533{
1444 int err; 1534 int err;
1445 1535
1536 err = nfs_idmap_init();
1537 if (err < 0)
1538 goto out9;
1539
1540 err = nfs_dns_resolver_init();
1541 if (err < 0)
1542 goto out8;
1543
1446 err = nfs_fscache_register(); 1544 err = nfs_fscache_register();
1447 if (err < 0) 1545 if (err < 0)
1448 goto out7; 1546 goto out7;
@@ -1501,6 +1599,10 @@ out5:
1501out6: 1599out6:
1502 nfs_fscache_unregister(); 1600 nfs_fscache_unregister();
1503out7: 1601out7:
1602 nfs_dns_resolver_destroy();
1603out8:
1604 nfs_idmap_quit();
1605out9:
1504 return err; 1606 return err;
1505} 1607}
1506 1608
@@ -1512,9 +1614,12 @@ static void __exit exit_nfs_fs(void)
1512 nfs_destroy_inodecache(); 1614 nfs_destroy_inodecache();
1513 nfs_destroy_nfspagecache(); 1615 nfs_destroy_nfspagecache();
1514 nfs_fscache_unregister(); 1616 nfs_fscache_unregister();
1617 nfs_dns_resolver_destroy();
1618 nfs_idmap_quit();
1515#ifdef CONFIG_PROC_FS 1619#ifdef CONFIG_PROC_FS
1516 rpc_proc_unregister("nfs"); 1620 rpc_proc_unregister("nfs");
1517#endif 1621#endif
1622 nfs_cleanup_cb_ident_idr();
1518 unregister_nfs_fs(); 1623 unregister_nfs_fs();
1519 nfs_fs_proc_exit(); 1624 nfs_fs_proc_exit();
1520 nfsiod_stop(); 1625 nfsiod_stop();
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 7dd90a6769d0..bfa3a34af801 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -30,6 +30,15 @@ static inline int nfs4_has_session(const struct nfs_client *clp)
30 return 0; 30 return 0;
31} 31}
32 32
33static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
34{
35#ifdef CONFIG_NFS_V4_1
36 if (nfs4_has_session(clp))
37 return (clp->cl_session->flags & SESSION4_PERSIST);
38#endif /* CONFIG_NFS_V4_1 */
39 return 0;
40}
41
33struct nfs_clone_mount { 42struct nfs_clone_mount {
34 const struct super_block *sb; 43 const struct super_block *sb;
35 const struct dentry *dentry; 44 const struct dentry *dentry;
@@ -49,6 +58,17 @@ struct nfs_clone_mount {
49#define NFS_MAX_SECFLAVORS (12) 58#define NFS_MAX_SECFLAVORS (12)
50 59
51/* 60/*
61 * Value used if the user did not specify a port value.
62 */
63#define NFS_UNSPEC_PORT (-1)
64
65/*
66 * Maximum number of pages that readdir can use for creating
67 * a vmapped array of pages.
68 */
69#define NFS_MAX_READDIR_PAGES 8
70
71/*
52 * In-kernel mount arguments 72 * In-kernel mount arguments
53 */ 73 */
54struct nfs_parsed_mount_data { 74struct nfs_parsed_mount_data {
@@ -63,6 +83,7 @@ struct nfs_parsed_mount_data {
63 unsigned int auth_flavor_len; 83 unsigned int auth_flavor_len;
64 rpc_authflavor_t auth_flavors[1]; 84 rpc_authflavor_t auth_flavors[1];
65 char *client_address; 85 char *client_address;
86 unsigned int version;
66 unsigned int minorversion; 87 unsigned int minorversion;
67 char *fscache_uniq; 88 char *fscache_uniq;
68 89
@@ -71,7 +92,7 @@ struct nfs_parsed_mount_data {
71 size_t addrlen; 92 size_t addrlen;
72 char *hostname; 93 char *hostname;
73 u32 version; 94 u32 version;
74 unsigned short port; 95 int port;
75 unsigned short protocol; 96 unsigned short protocol;
76 } mount_server; 97 } mount_server;
77 98
@@ -80,7 +101,7 @@ struct nfs_parsed_mount_data {
80 size_t addrlen; 101 size_t addrlen;
81 char *hostname; 102 char *hostname;
82 char *export_path; 103 char *export_path;
83 unsigned short port; 104 int port;
84 unsigned short protocol; 105 unsigned short protocol;
85 } nfs_server; 106 } nfs_server;
86 107
@@ -102,13 +123,18 @@ struct nfs_mount_request {
102}; 123};
103 124
104extern int nfs_mount(struct nfs_mount_request *info); 125extern int nfs_mount(struct nfs_mount_request *info);
126extern void nfs_umount(const struct nfs_mount_request *info);
105 127
106/* client.c */ 128/* client.c */
107extern struct rpc_program nfs_program; 129extern struct rpc_program nfs_program;
108 130
131extern void nfs_cleanup_cb_ident_idr(void);
109extern void nfs_put_client(struct nfs_client *); 132extern void nfs_put_client(struct nfs_client *);
110extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); 133extern struct nfs_client *nfs4_find_client_no_ident(const struct sockaddr *);
111extern struct nfs_client *nfs_find_client_next(struct nfs_client *); 134extern struct nfs_client *nfs4_find_client_ident(int);
135extern struct nfs_client *
136nfs4_find_client_sessionid(const struct sockaddr *, struct nfs4_sessionid *,
137 int);
112extern struct nfs_server *nfs_create_server( 138extern struct nfs_server *nfs_create_server(
113 const struct nfs_parsed_mount_data *, 139 const struct nfs_parsed_mount_data *,
114 struct nfs_fh *); 140 struct nfs_fh *);
@@ -149,6 +175,7 @@ struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentr
149 175
150/* callback_xdr.c */ 176/* callback_xdr.c */
151extern struct svc_version nfs4_callback_version1; 177extern struct svc_version nfs4_callback_version1;
178extern struct svc_version nfs4_callback_version4;
152 179
153/* pagelist.c */ 180/* pagelist.c */
154extern int __init nfs_init_nfspagecache(void); 181extern int __init nfs_init_nfspagecache(void);
@@ -162,31 +189,24 @@ extern int __init nfs_init_directcache(void);
162extern void nfs_destroy_directcache(void); 189extern void nfs_destroy_directcache(void);
163 190
164/* nfs2xdr.c */ 191/* nfs2xdr.c */
165extern int nfs_stat_to_errno(int); 192extern int nfs_stat_to_errno(enum nfs_stat);
166extern struct rpc_procinfo nfs_procedures[]; 193extern struct rpc_procinfo nfs_procedures[];
167extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int); 194extern int nfs2_decode_dirent(struct xdr_stream *,
195 struct nfs_entry *, int);
168 196
169/* nfs3xdr.c */ 197/* nfs3xdr.c */
170extern struct rpc_procinfo nfs3_procedures[]; 198extern struct rpc_procinfo nfs3_procedures[];
171extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int); 199extern int nfs3_decode_dirent(struct xdr_stream *,
172 200 struct nfs_entry *, int);
173/* nfs4proc.c */
174static inline void nfs4_restart_rpc(struct rpc_task *task,
175 const struct nfs_client *clp)
176{
177#ifdef CONFIG_NFS_V4_1
178 if (nfs4_has_session(clp) &&
179 test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) {
180 rpc_restart_call_prepare(task);
181 return;
182 }
183#endif /* CONFIG_NFS_V4_1 */
184 rpc_restart_call(task);
185}
186 201
187/* nfs4xdr.c */ 202/* nfs4xdr.c */
188#ifdef CONFIG_NFS_V4 203#ifdef CONFIG_NFS_V4
189extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 204extern int nfs4_decode_dirent(struct xdr_stream *,
205 struct nfs_entry *, int);
206#endif
207#ifdef CONFIG_NFS_V4_1
208extern const u32 nfs41_maxread_overhead;
209extern const u32 nfs41_maxwrite_overhead;
190#endif 210#endif
191 211
192/* nfs4proc.c */ 212/* nfs4proc.c */
@@ -198,22 +218,22 @@ extern struct rpc_procinfo nfs4_procedures[];
198void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 218void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
199 219
200/* dir.c */ 220/* dir.c */
201extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 221extern int nfs_access_cache_shrinker(struct shrinker *shrink,
222 int nr_to_scan, gfp_t gfp_mask);
202 223
203/* inode.c */ 224/* inode.c */
204extern struct workqueue_struct *nfsiod_workqueue; 225extern struct workqueue_struct *nfsiod_workqueue;
205extern struct inode *nfs_alloc_inode(struct super_block *sb); 226extern struct inode *nfs_alloc_inode(struct super_block *sb);
206extern void nfs_destroy_inode(struct inode *); 227extern void nfs_destroy_inode(struct inode *);
207extern int nfs_write_inode(struct inode *,int); 228extern int nfs_write_inode(struct inode *, struct writeback_control *);
208extern void nfs_clear_inode(struct inode *); 229extern void nfs_evict_inode(struct inode *);
209#ifdef CONFIG_NFS_V4 230#ifdef CONFIG_NFS_V4
210extern void nfs4_clear_inode(struct inode *); 231extern void nfs4_evict_inode(struct inode *);
211#endif 232#endif
212void nfs_zap_acl_cache(struct inode *inode); 233void nfs_zap_acl_cache(struct inode *inode);
213extern int nfs_wait_bit_killable(void *word); 234extern int nfs_wait_bit_killable(void *word);
214 235
215/* super.c */ 236/* super.c */
216void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *);
217extern struct file_system_type nfs_xdev_fs_type; 237extern struct file_system_type nfs_xdev_fs_type;
218#ifdef CONFIG_NFS_V4 238#ifdef CONFIG_NFS_V4
219extern struct file_system_type nfs4_xdev_fs_type; 239extern struct file_system_type nfs4_xdev_fs_type;
@@ -238,9 +258,7 @@ extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
238#ifdef CONFIG_NFS_V4 258#ifdef CONFIG_NFS_V4
239extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *); 259extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
240 260
241extern int nfs4_path_walk(struct nfs_server *server, 261extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
242 struct nfs_fh *mntfh,
243 const char *path);
244#endif 262#endif
245 263
246/* read.c */ 264/* read.c */
@@ -248,6 +266,12 @@ extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
248 266
249/* write.c */ 267/* write.c */
250extern void nfs_write_prepare(struct rpc_task *task, void *calldata); 268extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
269#ifdef CONFIG_MIGRATION
270extern int nfs_migrate_page(struct address_space *,
271 struct page *, struct page *);
272#else
273#define nfs_migrate_page NULL
274#endif
251 275
252/* nfs4proc.c */ 276/* nfs4proc.c */
253extern int _nfs4_call_sync(struct nfs_server *server, 277extern int _nfs4_call_sync(struct nfs_server *server,
@@ -261,20 +285,6 @@ extern int _nfs4_call_sync_session(struct nfs_server *server,
261 struct nfs4_sequence_res *res, 285 struct nfs4_sequence_res *res,
262 int cache_reply); 286 int cache_reply);
263 287
264#ifdef CONFIG_NFS_V4_1
265extern void nfs41_sequence_free_slot(const struct nfs_client *,
266 struct nfs4_sequence_res *res);
267#endif /* CONFIG_NFS_V4_1 */
268
269static inline void nfs4_sequence_free_slot(const struct nfs_client *clp,
270 struct nfs4_sequence_res *res)
271{
272#ifdef CONFIG_NFS_V4_1
273 if (nfs4_has_session(clp))
274 nfs41_sequence_free_slot(clp, res);
275#endif /* CONFIG_NFS_V4_1 */
276}
277
278/* 288/*
279 * Determine the device name as a string 289 * Determine the device name as a string
280 */ 290 */
@@ -359,6 +369,15 @@ unsigned int nfs_page_length(struct page *page)
359} 369}
360 370
361/* 371/*
372 * Convert a umode to a dirent->d_type
373 */
374static inline
375unsigned char nfs_umode_to_dtype(umode_t mode)
376{
377 return (mode >> 12) & 15;
378}
379
380/*
362 * Determine the number of pages in an array of length 'len' and 381 * Determine the number of pages in an array of length 'len' and
363 * with a base offset of 'base' 382 * with a base offset of 'base'
364 */ 383 */
@@ -369,23 +388,13 @@ unsigned int nfs_page_array_len(unsigned int base, size_t len)
369 PAGE_SIZE - 1) >> PAGE_SHIFT; 388 PAGE_SIZE - 1) >> PAGE_SHIFT;
370} 389}
371 390
372#define IPV6_SCOPE_DELIMITER '%'
373
374/* 391/*
375 * Set the port number in an address. Be agnostic about the address 392 * Helper for restarting RPC calls in the possible presence of NFSv4.1
376 * family. 393 * sessions.
377 */ 394 */
378static inline void nfs_set_port(struct sockaddr *sap, unsigned short port) 395static inline int nfs_restart_rpc(struct rpc_task *task, const struct nfs_client *clp)
379{ 396{
380 struct sockaddr_in *ap = (struct sockaddr_in *)sap; 397 if (nfs4_has_session(clp))
381 struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap; 398 return rpc_restart_call_prepare(task);
382 399 return rpc_restart_call(task);
383 switch (sap->sa_family) {
384 case AF_INET:
385 ap->sin_port = htons(port);
386 break;
387 case AF_INET6:
388 ap6->sin6_port = htons(port);
389 break;
390 }
391} 400}
diff --git a/fs/nfs/iostat.h b/fs/nfs/iostat.h
index ceda50aad73c..c5832487c456 100644
--- a/fs/nfs/iostat.h
+++ b/fs/nfs/iostat.h
@@ -25,13 +25,7 @@ struct nfs_iostats {
25static inline void nfs_inc_server_stats(const struct nfs_server *server, 25static inline void nfs_inc_server_stats(const struct nfs_server *server,
26 enum nfs_stat_eventcounters stat) 26 enum nfs_stat_eventcounters stat)
27{ 27{
28 struct nfs_iostats *iostats; 28 this_cpu_inc(server->io_stats->events[stat]);
29 int cpu;
30
31 cpu = get_cpu();
32 iostats = per_cpu_ptr(server->io_stats, cpu);
33 iostats->events[stat]++;
34 put_cpu();
35} 29}
36 30
37static inline void nfs_inc_stats(const struct inode *inode, 31static inline void nfs_inc_stats(const struct inode *inode,
@@ -42,20 +36,14 @@ static inline void nfs_inc_stats(const struct inode *inode,
42 36
43static inline void nfs_add_server_stats(const struct nfs_server *server, 37static inline void nfs_add_server_stats(const struct nfs_server *server,
44 enum nfs_stat_bytecounters stat, 38 enum nfs_stat_bytecounters stat,
45 unsigned long addend) 39 long addend)
46{ 40{
47 struct nfs_iostats *iostats; 41 this_cpu_add(server->io_stats->bytes[stat], addend);
48 int cpu;
49
50 cpu = get_cpu();
51 iostats = per_cpu_ptr(server->io_stats, cpu);
52 iostats->bytes[stat] += addend;
53 put_cpu();
54} 42}
55 43
56static inline void nfs_add_stats(const struct inode *inode, 44static inline void nfs_add_stats(const struct inode *inode,
57 enum nfs_stat_bytecounters stat, 45 enum nfs_stat_bytecounters stat,
58 unsigned long addend) 46 long addend)
59{ 47{
60 nfs_add_server_stats(NFS_SERVER(inode), stat, addend); 48 nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
61} 49}
@@ -63,24 +51,18 @@ static inline void nfs_add_stats(const struct inode *inode,
63#ifdef CONFIG_NFS_FSCACHE 51#ifdef CONFIG_NFS_FSCACHE
64static inline void nfs_add_fscache_stats(struct inode *inode, 52static inline void nfs_add_fscache_stats(struct inode *inode,
65 enum nfs_stat_fscachecounters stat, 53 enum nfs_stat_fscachecounters stat,
66 unsigned long addend) 54 long addend)
67{ 55{
68 struct nfs_iostats *iostats; 56 this_cpu_add(NFS_SERVER(inode)->io_stats->fscache[stat], addend);
69 int cpu;
70
71 cpu = get_cpu();
72 iostats = per_cpu_ptr(NFS_SERVER(inode)->io_stats, cpu);
73 iostats->fscache[stat] += addend;
74 put_cpu();
75} 57}
76#endif 58#endif
77 59
78static inline struct nfs_iostats *nfs_alloc_iostats(void) 60static inline struct nfs_iostats __percpu *nfs_alloc_iostats(void)
79{ 61{
80 return alloc_percpu(struct nfs_iostats); 62 return alloc_percpu(struct nfs_iostats);
81} 63}
82 64
83static inline void nfs_free_iostats(struct nfs_iostats *stats) 65static inline void nfs_free_iostats(struct nfs_iostats __percpu *stats)
84{ 66{
85 if (stats != NULL) 67 if (stats != NULL)
86 free_percpu(stats); 68 free_percpu(stats);
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c
index 38ef9eaec407..d4c2d6b7507e 100644
--- a/fs/nfs/mount_clnt.c
+++ b/fs/nfs/mount_clnt.c
@@ -120,7 +120,7 @@ static struct {
120 { .status = MNT3ERR_INVAL, .errno = -EINVAL, }, 120 { .status = MNT3ERR_INVAL, .errno = -EINVAL, },
121 { .status = MNT3ERR_NAMETOOLONG, .errno = -ENAMETOOLONG, }, 121 { .status = MNT3ERR_NAMETOOLONG, .errno = -ENAMETOOLONG, },
122 { .status = MNT3ERR_NOTSUPP, .errno = -ENOTSUPP, }, 122 { .status = MNT3ERR_NOTSUPP, .errno = -ENOTSUPP, },
123 { .status = MNT3ERR_SERVERFAULT, .errno = -ESERVERFAULT, }, 123 { .status = MNT3ERR_SERVERFAULT, .errno = -EREMOTEIO, },
124}; 124};
125 125
126struct mountres { 126struct mountres {
@@ -153,6 +153,7 @@ int nfs_mount(struct nfs_mount_request *info)
153 .rpc_resp = &result, 153 .rpc_resp = &result,
154 }; 154 };
155 struct rpc_create_args args = { 155 struct rpc_create_args args = {
156 .net = &init_net,
156 .protocol = info->protocol, 157 .protocol = info->protocol,
157 .address = info->sap, 158 .address = info->sap,
158 .addrsize = info->salen, 159 .addrsize = info->salen,
@@ -209,33 +210,88 @@ out_mnt_err:
209 goto out; 210 goto out;
210} 211}
211 212
213/**
214 * nfs_umount - Notify a server that we have unmounted this export
215 * @info: pointer to umount request arguments
216 *
217 * MOUNTPROC_UMNT is advisory, so we set a short timeout, and always
218 * use UDP.
219 */
220void nfs_umount(const struct nfs_mount_request *info)
221{
222 static const struct rpc_timeout nfs_umnt_timeout = {
223 .to_initval = 1 * HZ,
224 .to_maxval = 3 * HZ,
225 .to_retries = 2,
226 };
227 struct rpc_create_args args = {
228 .net = &init_net,
229 .protocol = IPPROTO_UDP,
230 .address = info->sap,
231 .addrsize = info->salen,
232 .timeout = &nfs_umnt_timeout,
233 .servername = info->hostname,
234 .program = &mnt_program,
235 .version = info->version,
236 .authflavor = RPC_AUTH_UNIX,
237 .flags = RPC_CLNT_CREATE_NOPING,
238 };
239 struct rpc_message msg = {
240 .rpc_argp = info->dirpath,
241 };
242 struct rpc_clnt *clnt;
243 int status;
244
245 if (info->noresvport)
246 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
247
248 clnt = rpc_create(&args);
249 if (IS_ERR(clnt))
250 goto out_clnt_err;
251
252 dprintk("NFS: sending UMNT request for %s:%s\n",
253 (info->hostname ? info->hostname : "server"), info->dirpath);
254
255 if (info->version == NFS_MNT3_VERSION)
256 msg.rpc_proc = &clnt->cl_procinfo[MOUNTPROC3_UMNT];
257 else
258 msg.rpc_proc = &clnt->cl_procinfo[MOUNTPROC_UMNT];
259
260 status = rpc_call_sync(clnt, &msg, 0);
261 rpc_shutdown_client(clnt);
262
263 if (unlikely(status < 0))
264 goto out_call_err;
265
266 return;
267
268out_clnt_err:
269 dprintk("NFS: failed to create UMNT RPC client, status=%ld\n",
270 PTR_ERR(clnt));
271 return;
272
273out_call_err:
274 dprintk("NFS: UMNT request failed, status=%d\n", status);
275}
276
212/* 277/*
213 * XDR encode/decode functions for MOUNT 278 * XDR encode/decode functions for MOUNT
214 */ 279 */
215 280
216static int encode_mntdirpath(struct xdr_stream *xdr, const char *pathname) 281static void encode_mntdirpath(struct xdr_stream *xdr, const char *pathname)
217{ 282{
218 const u32 pathname_len = strlen(pathname); 283 const u32 pathname_len = strlen(pathname);
219 __be32 *p; 284 __be32 *p;
220 285
221 if (unlikely(pathname_len > MNTPATHLEN)) 286 BUG_ON(pathname_len > MNTPATHLEN);
222 return -EIO; 287 p = xdr_reserve_space(xdr, 4 + pathname_len);
223
224 p = xdr_reserve_space(xdr, sizeof(u32) + pathname_len);
225 if (unlikely(p == NULL))
226 return -EIO;
227 xdr_encode_opaque(p, pathname, pathname_len); 288 xdr_encode_opaque(p, pathname, pathname_len);
228
229 return 0;
230} 289}
231 290
232static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p, 291static void mnt_xdr_enc_dirpath(struct rpc_rqst *req, struct xdr_stream *xdr,
233 const char *dirpath) 292 const char *dirpath)
234{ 293{
235 struct xdr_stream xdr; 294 encode_mntdirpath(xdr, dirpath);
236
237 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
238 return encode_mntdirpath(&xdr, dirpath);
239} 295}
240 296
241/* 297/*
@@ -253,12 +309,12 @@ static int decode_status(struct xdr_stream *xdr, struct mountres *res)
253 u32 status; 309 u32 status;
254 __be32 *p; 310 __be32 *p;
255 311
256 p = xdr_inline_decode(xdr, sizeof(status)); 312 p = xdr_inline_decode(xdr, 4);
257 if (unlikely(p == NULL)) 313 if (unlikely(p == NULL))
258 return -EIO; 314 return -EIO;
259 status = ntohl(*p); 315 status = be32_to_cpup(p);
260 316
261 for (i = 0; i <= ARRAY_SIZE(mnt_errtbl); i++) { 317 for (i = 0; i < ARRAY_SIZE(mnt_errtbl); i++) {
262 if (mnt_errtbl[i].status == status) { 318 if (mnt_errtbl[i].status == status) {
263 res->errno = mnt_errtbl[i].errno; 319 res->errno = mnt_errtbl[i].errno;
264 return 0; 320 return 0;
@@ -284,18 +340,16 @@ static int decode_fhandle(struct xdr_stream *xdr, struct mountres *res)
284 return 0; 340 return 0;
285} 341}
286 342
287static int mnt_dec_mountres(struct rpc_rqst *req, __be32 *p, 343static int mnt_xdr_dec_mountres(struct rpc_rqst *req,
288 struct mountres *res) 344 struct xdr_stream *xdr,
345 struct mountres *res)
289{ 346{
290 struct xdr_stream xdr;
291 int status; 347 int status;
292 348
293 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 349 status = decode_status(xdr, res);
294
295 status = decode_status(&xdr, res);
296 if (unlikely(status != 0 || res->errno != 0)) 350 if (unlikely(status != 0 || res->errno != 0))
297 return status; 351 return status;
298 return decode_fhandle(&xdr, res); 352 return decode_fhandle(xdr, res);
299} 353}
300 354
301static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res) 355static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res)
@@ -304,12 +358,12 @@ static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res)
304 u32 status; 358 u32 status;
305 __be32 *p; 359 __be32 *p;
306 360
307 p = xdr_inline_decode(xdr, sizeof(status)); 361 p = xdr_inline_decode(xdr, 4);
308 if (unlikely(p == NULL)) 362 if (unlikely(p == NULL))
309 return -EIO; 363 return -EIO;
310 status = ntohl(*p); 364 status = be32_to_cpup(p);
311 365
312 for (i = 0; i <= ARRAY_SIZE(mnt3_errtbl); i++) { 366 for (i = 0; i < ARRAY_SIZE(mnt3_errtbl); i++) {
313 if (mnt3_errtbl[i].status == status) { 367 if (mnt3_errtbl[i].status == status) {
314 res->errno = mnt3_errtbl[i].errno; 368 res->errno = mnt3_errtbl[i].errno;
315 return 0; 369 return 0;
@@ -327,11 +381,11 @@ static int decode_fhandle3(struct xdr_stream *xdr, struct mountres *res)
327 u32 size; 381 u32 size;
328 __be32 *p; 382 __be32 *p;
329 383
330 p = xdr_inline_decode(xdr, sizeof(size)); 384 p = xdr_inline_decode(xdr, 4);
331 if (unlikely(p == NULL)) 385 if (unlikely(p == NULL))
332 return -EIO; 386 return -EIO;
333 387
334 size = ntohl(*p++); 388 size = be32_to_cpup(p);
335 if (size > NFS3_FHSIZE || size == 0) 389 if (size > NFS3_FHSIZE || size == 0)
336 return -EIO; 390 return -EIO;
337 391
@@ -354,15 +408,15 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res)
354 if (*count == 0) 408 if (*count == 0)
355 return 0; 409 return 0;
356 410
357 p = xdr_inline_decode(xdr, sizeof(entries)); 411 p = xdr_inline_decode(xdr, 4);
358 if (unlikely(p == NULL)) 412 if (unlikely(p == NULL))
359 return -EIO; 413 return -EIO;
360 entries = ntohl(*p); 414 entries = be32_to_cpup(p);
361 dprintk("NFS: received %u auth flavors\n", entries); 415 dprintk("NFS: received %u auth flavors\n", entries);
362 if (entries > NFS_MAX_SECFLAVORS) 416 if (entries > NFS_MAX_SECFLAVORS)
363 entries = NFS_MAX_SECFLAVORS; 417 entries = NFS_MAX_SECFLAVORS;
364 418
365 p = xdr_inline_decode(xdr, sizeof(u32) * entries); 419 p = xdr_inline_decode(xdr, 4 * entries);
366 if (unlikely(p == NULL)) 420 if (unlikely(p == NULL))
367 return -EIO; 421 return -EIO;
368 422
@@ -370,67 +424,79 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res)
370 entries = *count; 424 entries = *count;
371 425
372 for (i = 0; i < entries; i++) { 426 for (i = 0; i < entries; i++) {
373 flavors[i] = ntohl(*p++); 427 flavors[i] = be32_to_cpup(p++);
374 dprintk("NFS:\tflavor %u: %d\n", i, flavors[i]); 428 dprintk("NFS: auth flavor[%u]: %d\n", i, flavors[i]);
375 } 429 }
376 *count = i; 430 *count = i;
377 431
378 return 0; 432 return 0;
379} 433}
380 434
381static int mnt_dec_mountres3(struct rpc_rqst *req, __be32 *p, 435static int mnt_xdr_dec_mountres3(struct rpc_rqst *req,
382 struct mountres *res) 436 struct xdr_stream *xdr,
437 struct mountres *res)
383{ 438{
384 struct xdr_stream xdr;
385 int status; 439 int status;
386 440
387 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 441 status = decode_fhs_status(xdr, res);
388
389 status = decode_fhs_status(&xdr, res);
390 if (unlikely(status != 0 || res->errno != 0)) 442 if (unlikely(status != 0 || res->errno != 0))
391 return status; 443 return status;
392 status = decode_fhandle3(&xdr, res); 444 status = decode_fhandle3(xdr, res);
393 if (unlikely(status != 0)) { 445 if (unlikely(status != 0)) {
394 res->errno = -EBADHANDLE; 446 res->errno = -EBADHANDLE;
395 return 0; 447 return 0;
396 } 448 }
397 return decode_auth_flavors(&xdr, res); 449 return decode_auth_flavors(xdr, res);
398} 450}
399 451
400static struct rpc_procinfo mnt_procedures[] = { 452static struct rpc_procinfo mnt_procedures[] = {
401 [MOUNTPROC_MNT] = { 453 [MOUNTPROC_MNT] = {
402 .p_proc = MOUNTPROC_MNT, 454 .p_proc = MOUNTPROC_MNT,
403 .p_encode = (kxdrproc_t)mnt_enc_dirpath, 455 .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath,
404 .p_decode = (kxdrproc_t)mnt_dec_mountres, 456 .p_decode = (kxdrdproc_t)mnt_xdr_dec_mountres,
405 .p_arglen = MNT_enc_dirpath_sz, 457 .p_arglen = MNT_enc_dirpath_sz,
406 .p_replen = MNT_dec_mountres_sz, 458 .p_replen = MNT_dec_mountres_sz,
407 .p_statidx = MOUNTPROC_MNT, 459 .p_statidx = MOUNTPROC_MNT,
408 .p_name = "MOUNT", 460 .p_name = "MOUNT",
409 }, 461 },
462 [MOUNTPROC_UMNT] = {
463 .p_proc = MOUNTPROC_UMNT,
464 .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath,
465 .p_arglen = MNT_enc_dirpath_sz,
466 .p_statidx = MOUNTPROC_UMNT,
467 .p_name = "UMOUNT",
468 },
410}; 469};
411 470
412static struct rpc_procinfo mnt3_procedures[] = { 471static struct rpc_procinfo mnt3_procedures[] = {
413 [MOUNTPROC3_MNT] = { 472 [MOUNTPROC3_MNT] = {
414 .p_proc = MOUNTPROC3_MNT, 473 .p_proc = MOUNTPROC3_MNT,
415 .p_encode = (kxdrproc_t)mnt_enc_dirpath, 474 .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath,
416 .p_decode = (kxdrproc_t)mnt_dec_mountres3, 475 .p_decode = (kxdrdproc_t)mnt_xdr_dec_mountres3,
417 .p_arglen = MNT_enc_dirpath_sz, 476 .p_arglen = MNT_enc_dirpath_sz,
418 .p_replen = MNT_dec_mountres3_sz, 477 .p_replen = MNT_dec_mountres3_sz,
419 .p_statidx = MOUNTPROC3_MNT, 478 .p_statidx = MOUNTPROC3_MNT,
420 .p_name = "MOUNT", 479 .p_name = "MOUNT",
421 }, 480 },
481 [MOUNTPROC3_UMNT] = {
482 .p_proc = MOUNTPROC3_UMNT,
483 .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath,
484 .p_arglen = MNT_enc_dirpath_sz,
485 .p_statidx = MOUNTPROC3_UMNT,
486 .p_name = "UMOUNT",
487 },
422}; 488};
423 489
424 490
425static struct rpc_version mnt_version1 = { 491static struct rpc_version mnt_version1 = {
426 .number = 1, 492 .number = 1,
427 .nrprocs = 2, 493 .nrprocs = ARRAY_SIZE(mnt_procedures),
428 .procs = mnt_procedures, 494 .procs = mnt_procedures,
429}; 495};
430 496
431static struct rpc_version mnt_version3 = { 497static struct rpc_version mnt_version3 = {
432 .number = 3, 498 .number = 3,
433 .nrprocs = 2, 499 .nrprocs = ARRAY_SIZE(mnt3_procedures),
434 .procs = mnt3_procedures, 500 .procs = mnt3_procedures,
435}; 501};
436 502
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 40c766782891..74aaf3963c10 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/dcache.h> 10#include <linux/dcache.h>
11#include <linux/gfp.h>
11#include <linux/mount.h> 12#include <linux/mount.h>
12#include <linux/namei.h> 13#include <linux/namei.h>
13#include <linux/nfs_fs.h> 14#include <linux/nfs_fs.h>
@@ -48,12 +49,17 @@ char *nfs_path(const char *base,
48 const struct dentry *dentry, 49 const struct dentry *dentry,
49 char *buffer, ssize_t buflen) 50 char *buffer, ssize_t buflen)
50{ 51{
51 char *end = buffer+buflen; 52 char *end;
52 int namelen; 53 int namelen;
54 unsigned seq;
53 55
56rename_retry:
57 end = buffer+buflen;
54 *--end = '\0'; 58 *--end = '\0';
55 buflen--; 59 buflen--;
56 spin_lock(&dcache_lock); 60
61 seq = read_seqbegin(&rename_lock);
62 rcu_read_lock();
57 while (!IS_ROOT(dentry) && dentry != droot) { 63 while (!IS_ROOT(dentry) && dentry != droot) {
58 namelen = dentry->d_name.len; 64 namelen = dentry->d_name.len;
59 buflen -= namelen + 1; 65 buflen -= namelen + 1;
@@ -64,7 +70,9 @@ char *nfs_path(const char *base,
64 *--end = '/'; 70 *--end = '/';
65 dentry = dentry->d_parent; 71 dentry = dentry->d_parent;
66 } 72 }
67 spin_unlock(&dcache_lock); 73 rcu_read_unlock();
74 if (read_seqretry(&rename_lock, seq))
75 goto rename_retry;
68 if (*end != '/') { 76 if (*end != '/') {
69 if (--buflen < 0) 77 if (--buflen < 0)
70 goto Elong; 78 goto Elong;
@@ -81,7 +89,9 @@ char *nfs_path(const char *base,
81 memcpy(end, base, namelen); 89 memcpy(end, base, namelen);
82 return end; 90 return end;
83Elong_unlock: 91Elong_unlock:
84 spin_unlock(&dcache_lock); 92 rcu_read_unlock();
93 if (read_seqretry(&rename_lock, seq))
94 goto rename_retry;
85Elong: 95Elong:
86 return ERR_PTR(-ENAMETOOLONG); 96 return ERR_PTR(-ENAMETOOLONG);
87} 97}
@@ -104,8 +114,8 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
104 struct vfsmount *mnt; 114 struct vfsmount *mnt;
105 struct nfs_server *server = NFS_SERVER(dentry->d_inode); 115 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
106 struct dentry *parent; 116 struct dentry *parent;
107 struct nfs_fh fh; 117 struct nfs_fh *fh = NULL;
108 struct nfs_fattr fattr; 118 struct nfs_fattr *fattr = NULL;
109 int err; 119 int err;
110 120
111 dprintk("--> nfs_follow_mountpoint()\n"); 121 dprintk("--> nfs_follow_mountpoint()\n");
@@ -114,6 +124,12 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
114 if (IS_ROOT(dentry)) 124 if (IS_ROOT(dentry))
115 goto out_err; 125 goto out_err;
116 126
127 err = -ENOMEM;
128 fh = nfs_alloc_fhandle();
129 fattr = nfs_alloc_fattr();
130 if (fh == NULL || fattr == NULL)
131 goto out_err;
132
117 dprintk("%s: enter\n", __func__); 133 dprintk("%s: enter\n", __func__);
118 dput(nd->path.dentry); 134 dput(nd->path.dentry);
119 nd->path.dentry = dget(dentry); 135 nd->path.dentry = dget(dentry);
@@ -122,16 +138,16 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
122 parent = dget_parent(nd->path.dentry); 138 parent = dget_parent(nd->path.dentry);
123 err = server->nfs_client->rpc_ops->lookup(parent->d_inode, 139 err = server->nfs_client->rpc_ops->lookup(parent->d_inode,
124 &nd->path.dentry->d_name, 140 &nd->path.dentry->d_name,
125 &fh, &fattr); 141 fh, fattr);
126 dput(parent); 142 dput(parent);
127 if (err != 0) 143 if (err != 0)
128 goto out_err; 144 goto out_err;
129 145
130 if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) 146 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
131 mnt = nfs_do_refmount(nd->path.mnt, nd->path.dentry); 147 mnt = nfs_do_refmount(nd->path.mnt, nd->path.dentry);
132 else 148 else
133 mnt = nfs_do_submount(nd->path.mnt, nd->path.dentry, &fh, 149 mnt = nfs_do_submount(nd->path.mnt, nd->path.dentry, fh,
134 &fattr); 150 fattr);
135 err = PTR_ERR(mnt); 151 err = PTR_ERR(mnt);
136 if (IS_ERR(mnt)) 152 if (IS_ERR(mnt))
137 goto out_err; 153 goto out_err;
@@ -150,6 +166,8 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
150 nd->path.dentry = dget(mnt->mnt_root); 166 nd->path.dentry = dget(mnt->mnt_root);
151 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); 167 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
152out: 168out:
169 nfs_free_fattr(fattr);
170 nfs_free_fhandle(fh);
153 dprintk("%s: done, returned %d\n", __func__, err); 171 dprintk("%s: done, returned %d\n", __func__, err);
154 172
155 dprintk("<-- nfs_follow_mountpoint() = %d\n", err); 173 dprintk("<-- nfs_follow_mountpoint() = %d\n", err);
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index c862c9340f9a..792cb13a4304 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -12,8 +12,6 @@
12#include <linux/param.h> 12#include <linux/param.h>
13#include <linux/time.h> 13#include <linux/time.h>
14#include <linux/mm.h> 14#include <linux/mm.h>
15#include <linux/slab.h>
16#include <linux/utsname.h>
17#include <linux/errno.h> 15#include <linux/errno.h>
18#include <linux/string.h> 16#include <linux/string.h>
19#include <linux/in.h> 17#include <linux/in.h>
@@ -63,610 +61,1008 @@
63#define NFS_readdirres_sz (1) 61#define NFS_readdirres_sz (1)
64#define NFS_statfsres_sz (1+NFS_info_sz) 62#define NFS_statfsres_sz (1+NFS_info_sz)
65 63
64
66/* 65/*
67 * Common NFS XDR functions as inlines 66 * While encoding arguments, set up the reply buffer in advance to
67 * receive reply data directly into the page cache.
68 */ 68 */
69static inline __be32 * 69static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
70xdr_encode_fhandle(__be32 *p, const struct nfs_fh *fhandle) 70 unsigned int base, unsigned int len,
71 unsigned int bufsize)
71{ 72{
72 memcpy(p, fhandle->data, NFS2_FHSIZE); 73 struct rpc_auth *auth = req->rq_cred->cr_auth;
73 return p + XDR_QUADLEN(NFS2_FHSIZE); 74 unsigned int replen;
75
76 replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
77 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
74} 78}
75 79
76static inline __be32 * 80/*
77xdr_decode_fhandle(__be32 *p, struct nfs_fh *fhandle) 81 * Handle decode buffer overflows out-of-line.
82 */
83static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
78{ 84{
79 /* NFSv2 handles have a fixed length */ 85 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
80 fhandle->size = NFS2_FHSIZE; 86 "Remaining buffer length is %tu words.\n",
81 memcpy(fhandle->data, p, NFS2_FHSIZE); 87 func, xdr->end - xdr->p);
82 return p + XDR_QUADLEN(NFS2_FHSIZE);
83} 88}
84 89
85static inline __be32* 90
86xdr_encode_time(__be32 *p, struct timespec *timep) 91/*
92 * Encode/decode NFSv2 basic data types
93 *
94 * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
95 * "NFS: Network File System Protocol Specification".
96 *
97 * Not all basic data types have their own encoding and decoding
98 * functions. For run-time efficiency, some data types are encoded
99 * or decoded inline.
100 */
101
102/*
103 * typedef opaque nfsdata<>;
104 */
105static int decode_nfsdata(struct xdr_stream *xdr, struct nfs_readres *result)
87{ 106{
88 *p++ = htonl(timep->tv_sec); 107 u32 recvd, count;
89 /* Convert nanoseconds into microseconds */ 108 size_t hdrlen;
90 *p++ = htonl(timep->tv_nsec ? timep->tv_nsec / 1000 : 0); 109 __be32 *p;
110
111 p = xdr_inline_decode(xdr, 4);
112 if (unlikely(p == NULL))
113 goto out_overflow;
114 count = be32_to_cpup(p);
115 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
116 recvd = xdr->buf->len - hdrlen;
117 if (unlikely(count > recvd))
118 goto out_cheating;
119out:
120 xdr_read_pages(xdr, count);
121 result->eof = 0; /* NFSv2 does not pass EOF flag on the wire. */
122 result->count = count;
123 return count;
124out_cheating:
125 dprintk("NFS: server cheating in read result: "
126 "count %u > recvd %u\n", count, recvd);
127 count = recvd;
128 goto out;
129out_overflow:
130 print_overflow_msg(__func__, xdr);
131 return -EIO;
132}
133
134/*
135 * enum stat {
136 * NFS_OK = 0,
137 * NFSERR_PERM = 1,
138 * NFSERR_NOENT = 2,
139 * NFSERR_IO = 5,
140 * NFSERR_NXIO = 6,
141 * NFSERR_ACCES = 13,
142 * NFSERR_EXIST = 17,
143 * NFSERR_NODEV = 19,
144 * NFSERR_NOTDIR = 20,
145 * NFSERR_ISDIR = 21,
146 * NFSERR_FBIG = 27,
147 * NFSERR_NOSPC = 28,
148 * NFSERR_ROFS = 30,
149 * NFSERR_NAMETOOLONG = 63,
150 * NFSERR_NOTEMPTY = 66,
151 * NFSERR_DQUOT = 69,
152 * NFSERR_STALE = 70,
153 * NFSERR_WFLUSH = 99
154 * };
155 */
156static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status)
157{
158 __be32 *p;
159
160 p = xdr_inline_decode(xdr, 4);
161 if (unlikely(p == NULL))
162 goto out_overflow;
163 *status = be32_to_cpup(p);
164 return 0;
165out_overflow:
166 print_overflow_msg(__func__, xdr);
167 return -EIO;
168}
169
170/*
171 * 2.3.2. ftype
172 *
173 * enum ftype {
174 * NFNON = 0,
175 * NFREG = 1,
176 * NFDIR = 2,
177 * NFBLK = 3,
178 * NFCHR = 4,
179 * NFLNK = 5
180 * };
181 *
182 */
183static __be32 *xdr_decode_ftype(__be32 *p, u32 *type)
184{
185 *type = be32_to_cpup(p++);
186 if (unlikely(*type > NF2FIFO))
187 *type = NFBAD;
91 return p; 188 return p;
92} 189}
93 190
94static inline __be32* 191/*
95xdr_encode_current_server_time(__be32 *p, struct timespec *timep) 192 * 2.3.3. fhandle
193 *
194 * typedef opaque fhandle[FHSIZE];
195 */
196static void encode_fhandle(struct xdr_stream *xdr, const struct nfs_fh *fh)
96{ 197{
97 /* 198 __be32 *p;
98 * Passing the invalid value useconds=1000000 is a 199
99 * Sun convention for "set to current server time". 200 BUG_ON(fh->size != NFS2_FHSIZE);
100 * It's needed to make permissions checks for the 201 p = xdr_reserve_space(xdr, NFS2_FHSIZE);
101 * "touch" program across v2 mounts to Solaris and 202 memcpy(p, fh->data, NFS2_FHSIZE);
102 * Irix boxes work correctly. See description of 203}
103 * sattr in section 6.1 of "NFS Illustrated" by 204
104 * Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5 205static int decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh)
105 */ 206{
106 *p++ = htonl(timep->tv_sec); 207 __be32 *p;
107 *p++ = htonl(1000000); 208
209 p = xdr_inline_decode(xdr, NFS2_FHSIZE);
210 if (unlikely(p == NULL))
211 goto out_overflow;
212 fh->size = NFS2_FHSIZE;
213 memcpy(fh->data, p, NFS2_FHSIZE);
214 return 0;
215out_overflow:
216 print_overflow_msg(__func__, xdr);
217 return -EIO;
218}
219
220/*
221 * 2.3.4. timeval
222 *
223 * struct timeval {
224 * unsigned int seconds;
225 * unsigned int useconds;
226 * };
227 */
228static __be32 *xdr_encode_time(__be32 *p, const struct timespec *timep)
229{
230 *p++ = cpu_to_be32(timep->tv_sec);
231 if (timep->tv_nsec != 0)
232 *p++ = cpu_to_be32(timep->tv_nsec / NSEC_PER_USEC);
233 else
234 *p++ = cpu_to_be32(0);
235 return p;
236}
237
238/*
239 * Passing the invalid value useconds=1000000 is a Sun convention for
240 * "set to current server time". It's needed to make permissions checks
241 * for the "touch" program across v2 mounts to Solaris and Irix servers
242 * work correctly. See description of sattr in section 6.1 of "NFS
243 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
244 */
245static __be32 *xdr_encode_current_server_time(__be32 *p,
246 const struct timespec *timep)
247{
248 *p++ = cpu_to_be32(timep->tv_sec);
249 *p++ = cpu_to_be32(1000000);
108 return p; 250 return p;
109} 251}
110 252
111static inline __be32* 253static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep)
112xdr_decode_time(__be32 *p, struct timespec *timep)
113{ 254{
114 timep->tv_sec = ntohl(*p++); 255 timep->tv_sec = be32_to_cpup(p++);
115 /* Convert microseconds into nanoseconds */ 256 timep->tv_nsec = be32_to_cpup(p++) * NSEC_PER_USEC;
116 timep->tv_nsec = ntohl(*p++) * 1000;
117 return p; 257 return p;
118} 258}
119 259
120static __be32 * 260/*
121xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) 261 * 2.3.5. fattr
262 *
263 * struct fattr {
264 * ftype type;
265 * unsigned int mode;
266 * unsigned int nlink;
267 * unsigned int uid;
268 * unsigned int gid;
269 * unsigned int size;
270 * unsigned int blocksize;
271 * unsigned int rdev;
272 * unsigned int blocks;
273 * unsigned int fsid;
274 * unsigned int fileid;
275 * timeval atime;
276 * timeval mtime;
277 * timeval ctime;
278 * };
279 *
280 */
281static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
122{ 282{
123 u32 rdev, type; 283 u32 rdev, type;
124 type = ntohl(*p++); 284 __be32 *p;
125 fattr->mode = ntohl(*p++); 285
126 fattr->nlink = ntohl(*p++); 286 p = xdr_inline_decode(xdr, NFS_fattr_sz << 2);
127 fattr->uid = ntohl(*p++); 287 if (unlikely(p == NULL))
128 fattr->gid = ntohl(*p++); 288 goto out_overflow;
129 fattr->size = ntohl(*p++); 289
130 fattr->du.nfs2.blocksize = ntohl(*p++);
131 rdev = ntohl(*p++);
132 fattr->du.nfs2.blocks = ntohl(*p++);
133 fattr->fsid.major = ntohl(*p++);
134 fattr->fsid.minor = 0;
135 fattr->fileid = ntohl(*p++);
136 p = xdr_decode_time(p, &fattr->atime);
137 p = xdr_decode_time(p, &fattr->mtime);
138 p = xdr_decode_time(p, &fattr->ctime);
139 fattr->valid |= NFS_ATTR_FATTR_V2; 290 fattr->valid |= NFS_ATTR_FATTR_V2;
291
292 p = xdr_decode_ftype(p, &type);
293
294 fattr->mode = be32_to_cpup(p++);
295 fattr->nlink = be32_to_cpup(p++);
296 fattr->uid = be32_to_cpup(p++);
297 fattr->gid = be32_to_cpup(p++);
298 fattr->size = be32_to_cpup(p++);
299 fattr->du.nfs2.blocksize = be32_to_cpup(p++);
300
301 rdev = be32_to_cpup(p++);
140 fattr->rdev = new_decode_dev(rdev); 302 fattr->rdev = new_decode_dev(rdev);
141 if (type == NFCHR && rdev == NFS2_FIFO_DEV) { 303 if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) {
142 fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO; 304 fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
143 fattr->rdev = 0; 305 fattr->rdev = 0;
144 } 306 }
145 return p; 307
308 fattr->du.nfs2.blocks = be32_to_cpup(p++);
309 fattr->fsid.major = be32_to_cpup(p++);
310 fattr->fsid.minor = 0;
311 fattr->fileid = be32_to_cpup(p++);
312
313 p = xdr_decode_time(p, &fattr->atime);
314 p = xdr_decode_time(p, &fattr->mtime);
315 xdr_decode_time(p, &fattr->ctime);
316 return 0;
317out_overflow:
318 print_overflow_msg(__func__, xdr);
319 return -EIO;
146} 320}
147 321
148static inline __be32 * 322/*
149xdr_encode_sattr(__be32 *p, struct iattr *attr) 323 * 2.3.6. sattr
150{ 324 *
151 const __be32 not_set = __constant_htonl(0xFFFFFFFF); 325 * struct sattr {
326 * unsigned int mode;
327 * unsigned int uid;
328 * unsigned int gid;
329 * unsigned int size;
330 * timeval atime;
331 * timeval mtime;
332 * };
333 */
334
335#define NFS2_SATTR_NOT_SET (0xffffffff)
152 336
153 *p++ = (attr->ia_valid & ATTR_MODE) ? htonl(attr->ia_mode) : not_set; 337static __be32 *xdr_time_not_set(__be32 *p)
154 *p++ = (attr->ia_valid & ATTR_UID) ? htonl(attr->ia_uid) : not_set; 338{
155 *p++ = (attr->ia_valid & ATTR_GID) ? htonl(attr->ia_gid) : not_set; 339 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
156 *p++ = (attr->ia_valid & ATTR_SIZE) ? htonl(attr->ia_size) : not_set; 340 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
341 return p;
342}
157 343
158 if (attr->ia_valid & ATTR_ATIME_SET) { 344static void encode_sattr(struct xdr_stream *xdr, const struct iattr *attr)
345{
346 __be32 *p;
347
348 p = xdr_reserve_space(xdr, NFS_sattr_sz << 2);
349
350 if (attr->ia_valid & ATTR_MODE)
351 *p++ = cpu_to_be32(attr->ia_mode);
352 else
353 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
354 if (attr->ia_valid & ATTR_UID)
355 *p++ = cpu_to_be32(attr->ia_uid);
356 else
357 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
358 if (attr->ia_valid & ATTR_GID)
359 *p++ = cpu_to_be32(attr->ia_gid);
360 else
361 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
362 if (attr->ia_valid & ATTR_SIZE)
363 *p++ = cpu_to_be32((u32)attr->ia_size);
364 else
365 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
366
367 if (attr->ia_valid & ATTR_ATIME_SET)
159 p = xdr_encode_time(p, &attr->ia_atime); 368 p = xdr_encode_time(p, &attr->ia_atime);
160 } else if (attr->ia_valid & ATTR_ATIME) { 369 else if (attr->ia_valid & ATTR_ATIME)
161 p = xdr_encode_current_server_time(p, &attr->ia_atime); 370 p = xdr_encode_current_server_time(p, &attr->ia_atime);
162 } else { 371 else
163 *p++ = not_set; 372 p = xdr_time_not_set(p);
164 *p++ = not_set; 373 if (attr->ia_valid & ATTR_MTIME_SET)
165 } 374 xdr_encode_time(p, &attr->ia_mtime);
166 375 else if (attr->ia_valid & ATTR_MTIME)
167 if (attr->ia_valid & ATTR_MTIME_SET) { 376 xdr_encode_current_server_time(p, &attr->ia_mtime);
168 p = xdr_encode_time(p, &attr->ia_mtime); 377 else
169 } else if (attr->ia_valid & ATTR_MTIME) { 378 xdr_time_not_set(p);
170 p = xdr_encode_current_server_time(p, &attr->ia_mtime);
171 } else {
172 *p++ = not_set;
173 *p++ = not_set;
174 }
175 return p;
176} 379}
177 380
178/* 381/*
179 * NFS encode functions 382 * 2.3.7. filename
180 */ 383 *
181/* 384 * typedef string filename<MAXNAMLEN>;
182 * Encode file handle argument
183 * GETATTR, READLINK, STATFS
184 */ 385 */
185static int 386static void encode_filename(struct xdr_stream *xdr,
186nfs_xdr_fhandle(struct rpc_rqst *req, __be32 *p, struct nfs_fh *fh) 387 const char *name, u32 length)
187{ 388{
188 p = xdr_encode_fhandle(p, fh); 389 __be32 *p;
189 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 390
391 BUG_ON(length > NFS2_MAXNAMLEN);
392 p = xdr_reserve_space(xdr, 4 + length);
393 xdr_encode_opaque(p, name, length);
394}
395
396static int decode_filename_inline(struct xdr_stream *xdr,
397 const char **name, u32 *length)
398{
399 __be32 *p;
400 u32 count;
401
402 p = xdr_inline_decode(xdr, 4);
403 if (unlikely(p == NULL))
404 goto out_overflow;
405 count = be32_to_cpup(p);
406 if (count > NFS3_MAXNAMLEN)
407 goto out_nametoolong;
408 p = xdr_inline_decode(xdr, count);
409 if (unlikely(p == NULL))
410 goto out_overflow;
411 *name = (const char *)p;
412 *length = count;
190 return 0; 413 return 0;
414out_nametoolong:
415 dprintk("NFS: returned filename too long: %u\n", count);
416 return -ENAMETOOLONG;
417out_overflow:
418 print_overflow_msg(__func__, xdr);
419 return -EIO;
191} 420}
192 421
193/* 422/*
194 * Encode SETATTR arguments 423 * 2.3.8. path
424 *
425 * typedef string path<MAXPATHLEN>;
195 */ 426 */
196static int 427static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length)
197nfs_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs_sattrargs *args)
198{ 428{
199 p = xdr_encode_fhandle(p, args->fh); 429 __be32 *p;
200 p = xdr_encode_sattr(p, args->sattr); 430
201 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 431 BUG_ON(length > NFS2_MAXPATHLEN);
432 p = xdr_reserve_space(xdr, 4);
433 *p = cpu_to_be32(length);
434 xdr_write_pages(xdr, pages, 0, length);
435}
436
437static int decode_path(struct xdr_stream *xdr)
438{
439 u32 length, recvd;
440 size_t hdrlen;
441 __be32 *p;
442
443 p = xdr_inline_decode(xdr, 4);
444 if (unlikely(p == NULL))
445 goto out_overflow;
446 length = be32_to_cpup(p);
447 if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN))
448 goto out_size;
449 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
450 recvd = xdr->buf->len - hdrlen;
451 if (unlikely(length > recvd))
452 goto out_cheating;
453
454 xdr_read_pages(xdr, length);
455 xdr_terminate_string(xdr->buf, length);
202 return 0; 456 return 0;
457out_size:
458 dprintk("NFS: returned pathname too long: %u\n", length);
459 return -ENAMETOOLONG;
460out_cheating:
461 dprintk("NFS: server cheating in pathname result: "
462 "length %u > received %u\n", length, recvd);
463 return -EIO;
464out_overflow:
465 print_overflow_msg(__func__, xdr);
466 return -EIO;
203} 467}
204 468
205/* 469/*
206 * Encode directory ops argument 470 * 2.3.9. attrstat
207 * LOOKUP, RMDIR 471 *
472 * union attrstat switch (stat status) {
473 * case NFS_OK:
474 * fattr attributes;
475 * default:
476 * void;
477 * };
208 */ 478 */
209static int 479static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result)
210nfs_xdr_diropargs(struct rpc_rqst *req, __be32 *p, struct nfs_diropargs *args)
211{ 480{
212 p = xdr_encode_fhandle(p, args->fh); 481 enum nfs_stat status;
213 p = xdr_encode_array(p, args->name, args->len); 482 int error;
214 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 483
215 return 0; 484 error = decode_stat(xdr, &status);
485 if (unlikely(error))
486 goto out;
487 if (status != NFS_OK)
488 goto out_default;
489 error = decode_fattr(xdr, result);
490out:
491 return error;
492out_default:
493 return nfs_stat_to_errno(status);
216} 494}
217 495
218/* 496/*
219 * Encode REMOVE argument 497 * 2.3.10. diropargs
498 *
499 * struct diropargs {
500 * fhandle dir;
501 * filename name;
502 * };
220 */ 503 */
221static int 504static void encode_diropargs(struct xdr_stream *xdr, const struct nfs_fh *fh,
222nfs_xdr_removeargs(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) 505 const char *name, u32 length)
223{ 506{
224 p = xdr_encode_fhandle(p, args->fh); 507 encode_fhandle(xdr, fh);
225 p = xdr_encode_array(p, args->name.name, args->name.len); 508 encode_filename(xdr, name, length);
226 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
227 return 0;
228} 509}
229 510
230/* 511/*
231 * Arguments to a READ call. Since we read data directly into the page 512 * 2.3.11. diropres
232 * cache, we also set up the reply iovec here so that iov[1] points 513 *
233 * exactly to the page we want to fetch. 514 * union diropres switch (stat status) {
515 * case NFS_OK:
516 * struct {
517 * fhandle file;
518 * fattr attributes;
519 * } diropok;
520 * default:
521 * void;
522 * };
234 */ 523 */
235static int 524static int decode_diropok(struct xdr_stream *xdr, struct nfs_diropok *result)
236nfs_xdr_readargs(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
237{ 525{
238 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 526 int error;
239 unsigned int replen; 527
240 u32 offset = (u32)args->offset; 528 error = decode_fhandle(xdr, result->fh);
241 u32 count = args->count; 529 if (unlikely(error))
242 530 goto out;
243 p = xdr_encode_fhandle(p, args->fh); 531 error = decode_fattr(xdr, result->fattr);
244 *p++ = htonl(offset); 532out:
245 *p++ = htonl(count); 533 return error;
246 *p++ = htonl(count); 534}
247 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
248 535
249 /* Inline the page array */ 536static int decode_diropres(struct xdr_stream *xdr, struct nfs_diropok *result)
250 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readres_sz) << 2; 537{
251 xdr_inline_pages(&req->rq_rcv_buf, replen, 538 enum nfs_stat status;
252 args->pages, args->pgbase, count); 539 int error;
253 req->rq_rcv_buf.flags |= XDRBUF_READ; 540
254 return 0; 541 error = decode_stat(xdr, &status);
542 if (unlikely(error))
543 goto out;
544 if (status != NFS_OK)
545 goto out_default;
546 error = decode_diropok(xdr, result);
547out:
548 return error;
549out_default:
550 return nfs_stat_to_errno(status);
255} 551}
256 552
553
257/* 554/*
258 * Decode READ reply 555 * NFSv2 XDR encode functions
556 *
557 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
558 * "NFS: Network File System Protocol Specification".
259 */ 559 */
260static int
261nfs_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res)
262{
263 struct kvec *iov = req->rq_rcv_buf.head;
264 size_t hdrlen;
265 u32 count, recvd;
266 int status;
267
268 if ((status = ntohl(*p++)))
269 return nfs_stat_to_errno(status);
270 p = xdr_decode_fattr(p, res->fattr);
271
272 count = ntohl(*p++);
273 res->eof = 0;
274 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
275 if (iov->iov_len < hdrlen) {
276 dprintk("NFS: READ reply header overflowed:"
277 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
278 return -errno_NFSERR_IO;
279 } else if (iov->iov_len != hdrlen) {
280 dprintk("NFS: READ header is short. iovec will be shifted.\n");
281 xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen);
282 }
283 560
284 recvd = req->rq_rcv_buf.len - hdrlen; 561static void nfs2_xdr_enc_fhandle(struct rpc_rqst *req,
285 if (count > recvd) { 562 struct xdr_stream *xdr,
286 dprintk("NFS: server cheating in read reply: " 563 const struct nfs_fh *fh)
287 "count %u > recvd %u\n", count, recvd); 564{
288 count = recvd; 565 encode_fhandle(xdr, fh);
289 } 566}
290 567
291 dprintk("RPC: readres OK count %u\n", count); 568/*
292 if (count < res->count) 569 * 2.2.3. sattrargs
293 res->count = count; 570 *
571 * struct sattrargs {
572 * fhandle file;
573 * sattr attributes;
574 * };
575 */
576static void nfs2_xdr_enc_sattrargs(struct rpc_rqst *req,
577 struct xdr_stream *xdr,
578 const struct nfs_sattrargs *args)
579{
580 encode_fhandle(xdr, args->fh);
581 encode_sattr(xdr, args->sattr);
582}
294 583
295 return count; 584static void nfs2_xdr_enc_diropargs(struct rpc_rqst *req,
585 struct xdr_stream *xdr,
586 const struct nfs_diropargs *args)
587{
588 encode_diropargs(xdr, args->fh, args->name, args->len);
296} 589}
297 590
591static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req,
592 struct xdr_stream *xdr,
593 const struct nfs_readlinkargs *args)
594{
595 encode_fhandle(xdr, args->fh);
596 prepare_reply_buffer(req, args->pages, args->pgbase,
597 args->pglen, NFS_readlinkres_sz);
598}
298 599
299/* 600/*
300 * Write arguments. Splice the buffer to be written into the iovec. 601 * 2.2.7. readargs
602 *
603 * struct readargs {
604 * fhandle file;
605 * unsigned offset;
606 * unsigned count;
607 * unsigned totalcount;
608 * };
301 */ 609 */
302static int 610static void encode_readargs(struct xdr_stream *xdr,
303nfs_xdr_writeargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 611 const struct nfs_readargs *args)
304{ 612{
305 struct xdr_buf *sndbuf = &req->rq_snd_buf; 613 u32 offset = args->offset;
306 u32 offset = (u32)args->offset;
307 u32 count = args->count; 614 u32 count = args->count;
615 __be32 *p;
308 616
309 p = xdr_encode_fhandle(p, args->fh); 617 encode_fhandle(xdr, args->fh);
310 *p++ = htonl(offset);
311 *p++ = htonl(offset);
312 *p++ = htonl(count);
313 *p++ = htonl(count);
314 sndbuf->len = xdr_adjust_iovec(sndbuf->head, p);
315 618
316 /* Copy the page array */ 619 p = xdr_reserve_space(xdr, 4 + 4 + 4);
317 xdr_encode_pages(sndbuf, args->pages, args->pgbase, count); 620 *p++ = cpu_to_be32(offset);
318 sndbuf->flags |= XDRBUF_WRITE; 621 *p++ = cpu_to_be32(count);
319 return 0; 622 *p = cpu_to_be32(count);
320} 623}
321 624
322/* 625static void nfs2_xdr_enc_readargs(struct rpc_rqst *req,
323 * Encode create arguments 626 struct xdr_stream *xdr,
324 * CREATE, MKDIR 627 const struct nfs_readargs *args)
325 */
326static int
327nfs_xdr_createargs(struct rpc_rqst *req, __be32 *p, struct nfs_createargs *args)
328{ 628{
329 p = xdr_encode_fhandle(p, args->fh); 629 encode_readargs(xdr, args);
330 p = xdr_encode_array(p, args->name, args->len); 630 prepare_reply_buffer(req, args->pages, args->pgbase,
331 p = xdr_encode_sattr(p, args->sattr); 631 args->count, NFS_readres_sz);
332 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 632 req->rq_rcv_buf.flags |= XDRBUF_READ;
333 return 0;
334} 633}
335 634
336/* 635/*
337 * Encode RENAME arguments 636 * 2.2.9. writeargs
637 *
638 * struct writeargs {
639 * fhandle file;
640 * unsigned beginoffset;
641 * unsigned offset;
642 * unsigned totalcount;
643 * nfsdata data;
644 * };
338 */ 645 */
339static int 646static void encode_writeargs(struct xdr_stream *xdr,
340nfs_xdr_renameargs(struct rpc_rqst *req, __be32 *p, struct nfs_renameargs *args) 647 const struct nfs_writeargs *args)
341{ 648{
342 p = xdr_encode_fhandle(p, args->fromfh); 649 u32 offset = args->offset;
343 p = xdr_encode_array(p, args->fromname, args->fromlen); 650 u32 count = args->count;
344 p = xdr_encode_fhandle(p, args->tofh); 651 __be32 *p;
345 p = xdr_encode_array(p, args->toname, args->tolen); 652
346 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 653 encode_fhandle(xdr, args->fh);
347 return 0; 654
655 p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4);
656 *p++ = cpu_to_be32(offset);
657 *p++ = cpu_to_be32(offset);
658 *p++ = cpu_to_be32(count);
659
660 /* nfsdata */
661 *p = cpu_to_be32(count);
662 xdr_write_pages(xdr, args->pages, args->pgbase, count);
348} 663}
349 664
350/* 665static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req,
351 * Encode LINK arguments 666 struct xdr_stream *xdr,
352 */ 667 const struct nfs_writeargs *args)
353static int
354nfs_xdr_linkargs(struct rpc_rqst *req, __be32 *p, struct nfs_linkargs *args)
355{ 668{
356 p = xdr_encode_fhandle(p, args->fromfh); 669 encode_writeargs(xdr, args);
357 p = xdr_encode_fhandle(p, args->tofh); 670 xdr->buf->flags |= XDRBUF_WRITE;
358 p = xdr_encode_array(p, args->toname, args->tolen);
359 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
360 return 0;
361} 671}
362 672
363/* 673/*
364 * Encode SYMLINK arguments 674 * 2.2.10. createargs
675 *
676 * struct createargs {
677 * diropargs where;
678 * sattr attributes;
679 * };
365 */ 680 */
366static int 681static void nfs2_xdr_enc_createargs(struct rpc_rqst *req,
367nfs_xdr_symlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs_symlinkargs *args) 682 struct xdr_stream *xdr,
683 const struct nfs_createargs *args)
368{ 684{
369 struct xdr_buf *sndbuf = &req->rq_snd_buf; 685 encode_diropargs(xdr, args->fh, args->name, args->len);
370 size_t pad; 686 encode_sattr(xdr, args->sattr);
687}
371 688
372 p = xdr_encode_fhandle(p, args->fromfh); 689static void nfs2_xdr_enc_removeargs(struct rpc_rqst *req,
373 p = xdr_encode_array(p, args->fromname, args->fromlen); 690 struct xdr_stream *xdr,
374 *p++ = htonl(args->pathlen); 691 const struct nfs_removeargs *args)
375 sndbuf->len = xdr_adjust_iovec(sndbuf->head, p); 692{
693 encode_diropargs(xdr, args->fh, args->name.name, args->name.len);
694}
376 695
377 xdr_encode_pages(sndbuf, args->pages, 0, args->pathlen); 696/*
697 * 2.2.12. renameargs
698 *
699 * struct renameargs {
700 * diropargs from;
701 * diropargs to;
702 * };
703 */
704static void nfs2_xdr_enc_renameargs(struct rpc_rqst *req,
705 struct xdr_stream *xdr,
706 const struct nfs_renameargs *args)
707{
708 const struct qstr *old = args->old_name;
709 const struct qstr *new = args->new_name;
378 710
379 /* 711 encode_diropargs(xdr, args->old_dir, old->name, old->len);
380 * xdr_encode_pages may have added a few bytes to ensure the 712 encode_diropargs(xdr, args->new_dir, new->name, new->len);
381 * pathname ends on a 4-byte boundary. Start encoding the
382 * attributes after the pad bytes.
383 */
384 pad = sndbuf->tail->iov_len;
385 if (pad > 0)
386 p++;
387 p = xdr_encode_sattr(p, args->sattr);
388 sndbuf->len += xdr_adjust_iovec(sndbuf->tail, p) - pad;
389 return 0;
390} 713}
391 714
392/* 715/*
393 * Encode arguments to readdir call 716 * 2.2.13. linkargs
717 *
718 * struct linkargs {
719 * fhandle from;
720 * diropargs to;
721 * };
394 */ 722 */
395static int 723static void nfs2_xdr_enc_linkargs(struct rpc_rqst *req,
396nfs_xdr_readdirargs(struct rpc_rqst *req, __be32 *p, struct nfs_readdirargs *args) 724 struct xdr_stream *xdr,
725 const struct nfs_linkargs *args)
397{ 726{
398 struct rpc_task *task = req->rq_task; 727 encode_fhandle(xdr, args->fromfh);
399 struct rpc_auth *auth = task->tk_msg.rpc_cred->cr_auth; 728 encode_diropargs(xdr, args->tofh, args->toname, args->tolen);
400 unsigned int replen; 729}
401 u32 count = args->count;
402
403 p = xdr_encode_fhandle(p, args->fh);
404 *p++ = htonl(args->cookie);
405 *p++ = htonl(count); /* see above */
406 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
407 730
408 /* Inline the page array */ 731/*
409 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readdirres_sz) << 2; 732 * 2.2.14. symlinkargs
410 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, count); 733 *
411 return 0; 734 * struct symlinkargs {
735 * diropargs from;
736 * path to;
737 * sattr attributes;
738 * };
739 */
740static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst *req,
741 struct xdr_stream *xdr,
742 const struct nfs_symlinkargs *args)
743{
744 encode_diropargs(xdr, args->fromfh, args->fromname, args->fromlen);
745 encode_path(xdr, args->pages, args->pathlen);
746 encode_sattr(xdr, args->sattr);
412} 747}
413 748
414/* 749/*
415 * Decode the result of a readdir call. 750 * 2.2.17. readdirargs
416 * We're not really decoding anymore, we just leave the buffer untouched 751 *
417 * and only check that it is syntactically correct. 752 * struct readdirargs {
418 * The real decoding happens in nfs_decode_entry below, called directly 753 * fhandle dir;
419 * from nfs_readdir for each entry. 754 * nfscookie cookie;
755 * unsigned count;
756 * };
420 */ 757 */
421static int 758static void encode_readdirargs(struct xdr_stream *xdr,
422nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy) 759 const struct nfs_readdirargs *args)
423{ 760{
424 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 761 __be32 *p;
425 struct kvec *iov = rcvbuf->head;
426 struct page **page;
427 size_t hdrlen;
428 unsigned int pglen, recvd;
429 u32 len;
430 int status, nr = 0;
431 __be32 *end, *entry, *kaddr;
432
433 if ((status = ntohl(*p++)))
434 return nfs_stat_to_errno(status);
435
436 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
437 if (iov->iov_len < hdrlen) {
438 dprintk("NFS: READDIR reply header overflowed:"
439 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
440 return -errno_NFSERR_IO;
441 } else if (iov->iov_len != hdrlen) {
442 dprintk("NFS: READDIR header is short. iovec will be shifted.\n");
443 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
444 }
445 762
446 pglen = rcvbuf->page_len; 763 encode_fhandle(xdr, args->fh);
447 recvd = rcvbuf->len - hdrlen;
448 if (pglen > recvd)
449 pglen = recvd;
450 page = rcvbuf->pages;
451 kaddr = p = kmap_atomic(*page, KM_USER0);
452 end = (__be32 *)((char *)p + pglen);
453 entry = p;
454
455 /* Make sure the packet actually has a value_follows and EOF entry */
456 if ((entry + 1) > end)
457 goto short_pkt;
458
459 for (; *p++; nr++) {
460 if (p + 2 > end)
461 goto short_pkt;
462 p++; /* fileid */
463 len = ntohl(*p++);
464 p += XDR_QUADLEN(len) + 1; /* name plus cookie */
465 if (len > NFS2_MAXNAMLEN) {
466 dprintk("NFS: giant filename in readdir (len 0x%x)!\n",
467 len);
468 goto err_unmap;
469 }
470 if (p + 2 > end)
471 goto short_pkt;
472 entry = p;
473 }
474 764
475 /* 765 p = xdr_reserve_space(xdr, 4 + 4);
476 * Apparently some server sends responses that are a valid size, but 766 *p++ = cpu_to_be32(args->cookie);
477 * contain no entries, and have value_follows==0 and EOF==0. For 767 *p = cpu_to_be32(args->count);
478 * those, just set the EOF marker.
479 */
480 if (!nr && entry[1] == 0) {
481 dprintk("NFS: readdir reply truncated!\n");
482 entry[1] = 1;
483 }
484 out:
485 kunmap_atomic(kaddr, KM_USER0);
486 return nr;
487 short_pkt:
488 /*
489 * When we get a short packet there are 2 possibilities. We can
490 * return an error, or fix up the response to look like a valid
491 * response and return what we have so far. If there are no
492 * entries and the packet was short, then return -EIO. If there
493 * are valid entries in the response, return them and pretend that
494 * the call was successful, but incomplete. The caller can retry the
495 * readdir starting at the last cookie.
496 */
497 entry[0] = entry[1] = 0;
498 if (!nr)
499 nr = -errno_NFSERR_IO;
500 goto out;
501err_unmap:
502 nr = -errno_NFSERR_IO;
503 goto out;
504} 768}
505 769
506__be32 * 770static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req,
507nfs_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) 771 struct xdr_stream *xdr,
772 const struct nfs_readdirargs *args)
508{ 773{
509 if (!*p++) { 774 encode_readdirargs(xdr, args);
510 if (!*p) 775 prepare_reply_buffer(req, args->pages, 0,
511 return ERR_PTR(-EAGAIN); 776 args->count, NFS_readdirres_sz);
512 entry->eof = 1;
513 return ERR_PTR(-EBADCOOKIE);
514 }
515
516 entry->ino = ntohl(*p++);
517 entry->len = ntohl(*p++);
518 entry->name = (const char *) p;
519 p += XDR_QUADLEN(entry->len);
520 entry->prev_cookie = entry->cookie;
521 entry->cookie = ntohl(*p++);
522 entry->eof = !p[0] && p[1];
523
524 return p;
525} 777}
526 778
527/* 779/*
528 * NFS XDR decode functions 780 * NFSv2 XDR decode functions
529 */ 781 *
530/* 782 * NFSv2 result types are defined in section 2.2 of RFC 1094:
531 * Decode simple status reply 783 * "NFS: Network File System Protocol Specification".
532 */ 784 */
533static int 785
534nfs_xdr_stat(struct rpc_rqst *req, __be32 *p, void *dummy) 786static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr,
787 void *__unused)
788{
789 enum nfs_stat status;
790 int error;
791
792 error = decode_stat(xdr, &status);
793 if (unlikely(error))
794 goto out;
795 if (status != NFS_OK)
796 goto out_default;
797out:
798 return error;
799out_default:
800 return nfs_stat_to_errno(status);
801}
802
803static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr,
804 struct nfs_fattr *result)
535{ 805{
536 int status; 806 return decode_attrstat(xdr, result);
807}
537 808
538 if ((status = ntohl(*p++)) != 0) 809static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr,
539 status = nfs_stat_to_errno(status); 810 struct nfs_diropok *result)
540 return status; 811{
812 return decode_diropres(xdr, result);
541} 813}
542 814
543/* 815/*
544 * Decode attrstat reply 816 * 2.2.6. readlinkres
545 * GETATTR, SETATTR, WRITE 817 *
818 * union readlinkres switch (stat status) {
819 * case NFS_OK:
820 * path data;
821 * default:
822 * void;
823 * };
546 */ 824 */
547static int 825static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req,
548nfs_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) 826 struct xdr_stream *xdr, void *__unused)
549{ 827{
550 int status; 828 enum nfs_stat status;
551 829 int error;
552 if ((status = ntohl(*p++))) 830
553 return nfs_stat_to_errno(status); 831 error = decode_stat(xdr, &status);
554 xdr_decode_fattr(p, fattr); 832 if (unlikely(error))
555 return 0; 833 goto out;
834 if (status != NFS_OK)
835 goto out_default;
836 error = decode_path(xdr);
837out:
838 return error;
839out_default:
840 return nfs_stat_to_errno(status);
556} 841}
557 842
558/* 843/*
559 * Decode diropres reply 844 * 2.2.7. readres
560 * LOOKUP, CREATE, MKDIR 845 *
846 * union readres switch (stat status) {
847 * case NFS_OK:
848 * fattr attributes;
849 * nfsdata data;
850 * default:
851 * void;
852 * };
561 */ 853 */
562static int 854static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr,
563nfs_xdr_diropres(struct rpc_rqst *req, __be32 *p, struct nfs_diropok *res) 855 struct nfs_readres *result)
564{ 856{
565 int status; 857 enum nfs_stat status;
858 int error;
859
860 error = decode_stat(xdr, &status);
861 if (unlikely(error))
862 goto out;
863 if (status != NFS_OK)
864 goto out_default;
865 error = decode_fattr(xdr, result->fattr);
866 if (unlikely(error))
867 goto out;
868 error = decode_nfsdata(xdr, result);
869out:
870 return error;
871out_default:
872 return nfs_stat_to_errno(status);
873}
566 874
567 if ((status = ntohl(*p++))) 875static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr,
568 return nfs_stat_to_errno(status); 876 struct nfs_writeres *result)
569 p = xdr_decode_fhandle(p, res->fh); 877{
570 xdr_decode_fattr(p, res->fattr); 878 /* All NFSv2 writes are "file sync" writes */
571 return 0; 879 result->verf->committed = NFS_FILE_SYNC;
880 return decode_attrstat(xdr, result->fattr);
572} 881}
573 882
574/* 883/**
575 * Encode READLINK args 884 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
885 * the local page cache.
886 * @xdr: XDR stream where entry resides
887 * @entry: buffer to fill in with entry data
888 * @plus: boolean indicating whether this should be a readdirplus entry
889 *
890 * Returns zero if successful, otherwise a negative errno value is
891 * returned.
892 *
893 * This function is not invoked during READDIR reply decoding, but
894 * rather whenever an application invokes the getdents(2) system call
895 * on a directory already in our cache.
896 *
897 * 2.2.17. entry
898 *
899 * struct entry {
900 * unsigned fileid;
901 * filename name;
902 * nfscookie cookie;
903 * entry *nextentry;
904 * };
576 */ 905 */
577static int 906int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
578nfs_xdr_readlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs_readlinkargs *args) 907 int plus)
579{ 908{
580 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 909 __be32 *p;
581 unsigned int replen; 910 int error;
911
912 p = xdr_inline_decode(xdr, 4);
913 if (unlikely(p == NULL))
914 goto out_overflow;
915 if (*p++ == xdr_zero) {
916 p = xdr_inline_decode(xdr, 4);
917 if (unlikely(p == NULL))
918 goto out_overflow;
919 if (*p++ == xdr_zero)
920 return -EAGAIN;
921 entry->eof = 1;
922 return -EBADCOOKIE;
923 }
924
925 p = xdr_inline_decode(xdr, 4);
926 if (unlikely(p == NULL))
927 goto out_overflow;
928 entry->ino = be32_to_cpup(p);
929
930 error = decode_filename_inline(xdr, &entry->name, &entry->len);
931 if (unlikely(error))
932 return error;
933
934 /*
935 * The type (size and byte order) of nfscookie isn't defined in
936 * RFC 1094. This implementation assumes that it's an XDR uint32.
937 */
938 entry->prev_cookie = entry->cookie;
939 p = xdr_inline_decode(xdr, 4);
940 if (unlikely(p == NULL))
941 goto out_overflow;
942 entry->cookie = be32_to_cpup(p);
582 943
583 p = xdr_encode_fhandle(p, args->fh); 944 entry->d_type = DT_UNKNOWN;
584 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
585 945
586 /* Inline the page array */
587 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readlinkres_sz) << 2;
588 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, args->pgbase, args->pglen);
589 return 0; 946 return 0;
947
948out_overflow:
949 print_overflow_msg(__func__, xdr);
950 return -EAGAIN;
590} 951}
591 952
592/* 953/*
593 * Decode READLINK reply 954 * 2.2.17. readdirres
955 *
956 * union readdirres switch (stat status) {
957 * case NFS_OK:
958 * struct {
959 * entry *entries;
960 * bool eof;
961 * } readdirok;
962 * default:
963 * void;
964 * };
965 *
966 * Read the directory contents into the page cache, but don't
967 * touch them. The actual decoding is done by nfs2_decode_dirent()
968 * during subsequent nfs_readdir() calls.
594 */ 969 */
595static int 970static int decode_readdirok(struct xdr_stream *xdr)
596nfs_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, void *dummy)
597{ 971{
598 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 972 u32 recvd, pglen;
599 struct kvec *iov = rcvbuf->head;
600 size_t hdrlen; 973 size_t hdrlen;
601 u32 len, recvd;
602 char *kaddr;
603 int status;
604
605 if ((status = ntohl(*p++)))
606 return nfs_stat_to_errno(status);
607 /* Convert length of symlink */
608 len = ntohl(*p++);
609 if (len >= rcvbuf->page_len) {
610 dprintk("nfs: server returned giant symlink!\n");
611 return -ENAMETOOLONG;
612 }
613 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
614 if (iov->iov_len < hdrlen) {
615 dprintk("NFS: READLINK reply header overflowed:"
616 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
617 return -errno_NFSERR_IO;
618 } else if (iov->iov_len != hdrlen) {
619 dprintk("NFS: READLINK header is short. iovec will be shifted.\n");
620 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
621 }
622 recvd = req->rq_rcv_buf.len - hdrlen;
623 if (recvd < len) {
624 dprintk("NFS: server cheating in readlink reply: "
625 "count %u > recvd %u\n", len, recvd);
626 return -EIO;
627 }
628 974
629 /* NULL terminate the string we got */ 975 pglen = xdr->buf->page_len;
630 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); 976 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
631 kaddr[len+rcvbuf->page_base] = '\0'; 977 recvd = xdr->buf->len - hdrlen;
632 kunmap_atomic(kaddr, KM_USER0); 978 if (unlikely(pglen > recvd))
633 return 0; 979 goto out_cheating;
980out:
981 xdr_read_pages(xdr, pglen);
982 return pglen;
983out_cheating:
984 dprintk("NFS: server cheating in readdir result: "
985 "pglen %u > recvd %u\n", pglen, recvd);
986 pglen = recvd;
987 goto out;
634} 988}
635 989
636/* 990static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req,
637 * Decode WRITE reply 991 struct xdr_stream *xdr, void *__unused)
638 */
639static int
640nfs_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
641{ 992{
642 res->verf->committed = NFS_FILE_SYNC; 993 enum nfs_stat status;
643 return nfs_xdr_attrstat(req, p, res->fattr); 994 int error;
995
996 error = decode_stat(xdr, &status);
997 if (unlikely(error))
998 goto out;
999 if (status != NFS_OK)
1000 goto out_default;
1001 error = decode_readdirok(xdr);
1002out:
1003 return error;
1004out_default:
1005 return nfs_stat_to_errno(status);
644} 1006}
645 1007
646/* 1008/*
647 * Decode STATFS reply 1009 * 2.2.18. statfsres
1010 *
1011 * union statfsres (stat status) {
1012 * case NFS_OK:
1013 * struct {
1014 * unsigned tsize;
1015 * unsigned bsize;
1016 * unsigned blocks;
1017 * unsigned bfree;
1018 * unsigned bavail;
1019 * } info;
1020 * default:
1021 * void;
1022 * };
648 */ 1023 */
649static int 1024static int decode_info(struct xdr_stream *xdr, struct nfs2_fsstat *result)
650nfs_xdr_statfsres(struct rpc_rqst *req, __be32 *p, struct nfs2_fsstat *res)
651{ 1025{
652 int status; 1026 __be32 *p;
653 1027
654 if ((status = ntohl(*p++))) 1028 p = xdr_inline_decode(xdr, NFS_info_sz << 2);
655 return nfs_stat_to_errno(status); 1029 if (unlikely(p == NULL))
656 1030 goto out_overflow;
657 res->tsize = ntohl(*p++); 1031 result->tsize = be32_to_cpup(p++);
658 res->bsize = ntohl(*p++); 1032 result->bsize = be32_to_cpup(p++);
659 res->blocks = ntohl(*p++); 1033 result->blocks = be32_to_cpup(p++);
660 res->bfree = ntohl(*p++); 1034 result->bfree = be32_to_cpup(p++);
661 res->bavail = ntohl(*p++); 1035 result->bavail = be32_to_cpup(p);
662 return 0; 1036 return 0;
1037out_overflow:
1038 print_overflow_msg(__func__, xdr);
1039 return -EIO;
1040}
1041
1042static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr,
1043 struct nfs2_fsstat *result)
1044{
1045 enum nfs_stat status;
1046 int error;
1047
1048 error = decode_stat(xdr, &status);
1049 if (unlikely(error))
1050 goto out;
1051 if (status != NFS_OK)
1052 goto out_default;
1053 error = decode_info(xdr, result);
1054out:
1055 return error;
1056out_default:
1057 return nfs_stat_to_errno(status);
663} 1058}
664 1059
1060
665/* 1061/*
666 * We need to translate between nfs status return values and 1062 * We need to translate between nfs status return values and
667 * the local errno values which may not be the same. 1063 * the local errno values which may not be the same.
668 */ 1064 */
669static struct { 1065static const struct {
670 int stat; 1066 int stat;
671 int errno; 1067 int errno;
672} nfs_errtbl[] = { 1068} nfs_errtbl[] = {
@@ -700,34 +1096,36 @@ static struct {
700 { NFSERR_BAD_COOKIE, -EBADCOOKIE }, 1096 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
701 { NFSERR_NOTSUPP, -ENOTSUPP }, 1097 { NFSERR_NOTSUPP, -ENOTSUPP },
702 { NFSERR_TOOSMALL, -ETOOSMALL }, 1098 { NFSERR_TOOSMALL, -ETOOSMALL },
703 { NFSERR_SERVERFAULT, -ESERVERFAULT }, 1099 { NFSERR_SERVERFAULT, -EREMOTEIO },
704 { NFSERR_BADTYPE, -EBADTYPE }, 1100 { NFSERR_BADTYPE, -EBADTYPE },
705 { NFSERR_JUKEBOX, -EJUKEBOX }, 1101 { NFSERR_JUKEBOX, -EJUKEBOX },
706 { -1, -EIO } 1102 { -1, -EIO }
707}; 1103};
708 1104
709/* 1105/**
710 * Convert an NFS error code to a local one. 1106 * nfs_stat_to_errno - convert an NFS status code to a local errno
711 * This one is used jointly by NFSv2 and NFSv3. 1107 * @status: NFS status code to convert
1108 *
1109 * Returns a local errno value, or -EIO if the NFS status code is
1110 * not recognized. This function is used jointly by NFSv2 and NFSv3.
712 */ 1111 */
713int 1112int nfs_stat_to_errno(enum nfs_stat status)
714nfs_stat_to_errno(int stat)
715{ 1113{
716 int i; 1114 int i;
717 1115
718 for (i = 0; nfs_errtbl[i].stat != -1; i++) { 1116 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
719 if (nfs_errtbl[i].stat == stat) 1117 if (nfs_errtbl[i].stat == (int)status)
720 return nfs_errtbl[i].errno; 1118 return nfs_errtbl[i].errno;
721 } 1119 }
722 dprintk("nfs_stat_to_errno: bad nfs status return value: %d\n", stat); 1120 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
723 return nfs_errtbl[i].errno; 1121 return nfs_errtbl[i].errno;
724} 1122}
725 1123
726#define PROC(proc, argtype, restype, timer) \ 1124#define PROC(proc, argtype, restype, timer) \
727[NFSPROC_##proc] = { \ 1125[NFSPROC_##proc] = { \
728 .p_proc = NFSPROC_##proc, \ 1126 .p_proc = NFSPROC_##proc, \
729 .p_encode = (kxdrproc_t) nfs_xdr_##argtype, \ 1127 .p_encode = (kxdreproc_t)nfs2_xdr_enc_##argtype, \
730 .p_decode = (kxdrproc_t) nfs_xdr_##restype, \ 1128 .p_decode = (kxdrdproc_t)nfs2_xdr_dec_##restype, \
731 .p_arglen = NFS_##argtype##_sz, \ 1129 .p_arglen = NFS_##argtype##_sz, \
732 .p_replen = NFS_##restype##_sz, \ 1130 .p_replen = NFS_##restype##_sz, \
733 .p_timer = timer, \ 1131 .p_timer = timer, \
@@ -735,21 +1133,21 @@ nfs_stat_to_errno(int stat)
735 .p_name = #proc, \ 1133 .p_name = #proc, \
736 } 1134 }
737struct rpc_procinfo nfs_procedures[] = { 1135struct rpc_procinfo nfs_procedures[] = {
738 PROC(GETATTR, fhandle, attrstat, 1), 1136 PROC(GETATTR, fhandle, attrstat, 1),
739 PROC(SETATTR, sattrargs, attrstat, 0), 1137 PROC(SETATTR, sattrargs, attrstat, 0),
740 PROC(LOOKUP, diropargs, diropres, 2), 1138 PROC(LOOKUP, diropargs, diropres, 2),
741 PROC(READLINK, readlinkargs, readlinkres, 3), 1139 PROC(READLINK, readlinkargs, readlinkres, 3),
742 PROC(READ, readargs, readres, 3), 1140 PROC(READ, readargs, readres, 3),
743 PROC(WRITE, writeargs, writeres, 4), 1141 PROC(WRITE, writeargs, writeres, 4),
744 PROC(CREATE, createargs, diropres, 0), 1142 PROC(CREATE, createargs, diropres, 0),
745 PROC(REMOVE, removeargs, stat, 0), 1143 PROC(REMOVE, removeargs, stat, 0),
746 PROC(RENAME, renameargs, stat, 0), 1144 PROC(RENAME, renameargs, stat, 0),
747 PROC(LINK, linkargs, stat, 0), 1145 PROC(LINK, linkargs, stat, 0),
748 PROC(SYMLINK, symlinkargs, stat, 0), 1146 PROC(SYMLINK, symlinkargs, stat, 0),
749 PROC(MKDIR, createargs, diropres, 0), 1147 PROC(MKDIR, createargs, diropres, 0),
750 PROC(RMDIR, diropargs, stat, 0), 1148 PROC(RMDIR, diropargs, stat, 0),
751 PROC(READDIR, readdirargs, readdirres, 3), 1149 PROC(READDIR, readdirargs, readdirres, 3),
752 PROC(STATFS, fhandle, statfsres, 0), 1150 PROC(STATFS, fhandle, statfsres, 0),
753}; 1151};
754 1152
755struct rpc_version nfs_version2 = { 1153struct rpc_version nfs_version2 = {
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index bac60515a4b3..9f88c5f4c7e2 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -1,4 +1,5 @@
1#include <linux/fs.h> 1#include <linux/fs.h>
2#include <linux/gfp.h>
2#include <linux/nfs.h> 3#include <linux/nfs.h>
3#include <linux/nfs3.h> 4#include <linux/nfs3.h>
4#include <linux/nfs_fs.h> 5#include <linux/nfs_fs.h>
@@ -184,7 +185,6 @@ static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl,
184struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type) 185struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
185{ 186{
186 struct nfs_server *server = NFS_SERVER(inode); 187 struct nfs_server *server = NFS_SERVER(inode);
187 struct nfs_fattr fattr;
188 struct page *pages[NFSACL_MAXPAGES] = { }; 188 struct page *pages[NFSACL_MAXPAGES] = { };
189 struct nfs3_getaclargs args = { 189 struct nfs3_getaclargs args = {
190 .fh = NFS_FH(inode), 190 .fh = NFS_FH(inode),
@@ -192,7 +192,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
192 .pages = pages, 192 .pages = pages,
193 }; 193 };
194 struct nfs3_getaclres res = { 194 struct nfs3_getaclres res = {
195 .fattr = &fattr, 195 0
196 }; 196 };
197 struct rpc_message msg = { 197 struct rpc_message msg = {
198 .rpc_argp = &args, 198 .rpc_argp = &args,
@@ -227,7 +227,10 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
227 227
228 dprintk("NFS call getacl\n"); 228 dprintk("NFS call getacl\n");
229 msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL]; 229 msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL];
230 nfs_fattr_init(&fattr); 230 res.fattr = nfs_alloc_fattr();
231 if (res.fattr == NULL)
232 return ERR_PTR(-ENOMEM);
233
231 status = rpc_call_sync(server->client_acl, &msg, 0); 234 status = rpc_call_sync(server->client_acl, &msg, 0);
232 dprintk("NFS reply getacl: %d\n", status); 235 dprintk("NFS reply getacl: %d\n", status);
233 236
@@ -237,7 +240,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
237 240
238 switch (status) { 241 switch (status) {
239 case 0: 242 case 0:
240 status = nfs_refresh_inode(inode, &fattr); 243 status = nfs_refresh_inode(inode, res.fattr);
241 break; 244 break;
242 case -EPFNOSUPPORT: 245 case -EPFNOSUPPORT:
243 case -EPROTONOSUPPORT: 246 case -EPROTONOSUPPORT:
@@ -277,6 +280,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
277getout: 280getout:
278 posix_acl_release(res.acl_access); 281 posix_acl_release(res.acl_access);
279 posix_acl_release(res.acl_default); 282 posix_acl_release(res.acl_default);
283 nfs_free_fattr(res.fattr);
280 284
281 if (status != 0) { 285 if (status != 0) {
282 posix_acl_release(acl); 286 posix_acl_release(acl);
@@ -289,7 +293,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
289 struct posix_acl *dfacl) 293 struct posix_acl *dfacl)
290{ 294{
291 struct nfs_server *server = NFS_SERVER(inode); 295 struct nfs_server *server = NFS_SERVER(inode);
292 struct nfs_fattr fattr; 296 struct nfs_fattr *fattr;
293 struct page *pages[NFSACL_MAXPAGES]; 297 struct page *pages[NFSACL_MAXPAGES];
294 struct nfs3_setaclargs args = { 298 struct nfs3_setaclargs args = {
295 .inode = inode, 299 .inode = inode,
@@ -334,8 +338,13 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
334 } 338 }
335 339
336 dprintk("NFS call setacl\n"); 340 dprintk("NFS call setacl\n");
341 status = -ENOMEM;
342 fattr = nfs_alloc_fattr();
343 if (fattr == NULL)
344 goto out_freepages;
345
337 msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL]; 346 msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL];
338 nfs_fattr_init(&fattr); 347 msg.rpc_resp = fattr;
339 status = rpc_call_sync(server->client_acl, &msg, 0); 348 status = rpc_call_sync(server->client_acl, &msg, 0);
340 nfs_access_zap_cache(inode); 349 nfs_access_zap_cache(inode);
341 nfs_zap_acl_cache(inode); 350 nfs_zap_acl_cache(inode);
@@ -343,7 +352,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
343 352
344 switch (status) { 353 switch (status) {
345 case 0: 354 case 0:
346 status = nfs_refresh_inode(inode, &fattr); 355 status = nfs_refresh_inode(inode, fattr);
347 nfs3_cache_acls(inode, acl, dfacl); 356 nfs3_cache_acls(inode, acl, dfacl);
348 break; 357 break;
349 case -EPFNOSUPPORT: 358 case -EPFNOSUPPORT:
@@ -354,6 +363,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
354 case -ENOTSUPP: 363 case -ENOTSUPP:
355 status = -EOPNOTSUPP; 364 status = -EOPNOTSUPP;
356 } 365 }
366 nfs_free_fattr(fattr);
357out_freepages: 367out_freepages:
358 while (args.npages != 0) { 368 while (args.npages != 0) {
359 args.npages--; 369 args.npages--;
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index d0cc5ce0edfe..ce939c062a52 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -7,10 +7,10 @@
7 */ 7 */
8 8
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <linux/utsname.h>
11#include <linux/errno.h> 10#include <linux/errno.h>
12#include <linux/string.h> 11#include <linux/string.h>
13#include <linux/sunrpc/clnt.h> 12#include <linux/sunrpc/clnt.h>
13#include <linux/slab.h>
14#include <linux/nfs.h> 14#include <linux/nfs.h>
15#include <linux/nfs3.h> 15#include <linux/nfs3.h>
16#include <linux/nfs_fs.h> 16#include <linux/nfs_fs.h>
@@ -23,14 +23,14 @@
23 23
24#define NFSDBG_FACILITY NFSDBG_PROC 24#define NFSDBG_FACILITY NFSDBG_PROC
25 25
26/* A wrapper to handle the EJUKEBOX error message */ 26/* A wrapper to handle the EJUKEBOX and EKEYEXPIRED error messages */
27static int 27static int
28nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) 28nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
29{ 29{
30 int res; 30 int res;
31 do { 31 do {
32 res = rpc_call_sync(clnt, msg, flags); 32 res = rpc_call_sync(clnt, msg, flags);
33 if (res != -EJUKEBOX) 33 if (res != -EJUKEBOX && res != -EKEYEXPIRED)
34 break; 34 break;
35 schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME); 35 schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME);
36 res = -ERESTARTSYS; 36 res = -ERESTARTSYS;
@@ -43,9 +43,10 @@ nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
43static int 43static int
44nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode) 44nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
45{ 45{
46 if (task->tk_status != -EJUKEBOX) 46 if (task->tk_status != -EJUKEBOX && task->tk_status != -EKEYEXPIRED)
47 return 0; 47 return 0;
48 nfs_inc_stats(inode, NFSIOS_DELAY); 48 if (task->tk_status == -EJUKEBOX)
49 nfs_inc_stats(inode, NFSIOS_DELAY);
49 task->tk_status = 0; 50 task->tk_status = 0;
50 rpc_restart_call(task); 51 rpc_restart_call(task);
51 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); 52 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
@@ -143,14 +144,12 @@ static int
143nfs3_proc_lookup(struct inode *dir, struct qstr *name, 144nfs3_proc_lookup(struct inode *dir, struct qstr *name,
144 struct nfs_fh *fhandle, struct nfs_fattr *fattr) 145 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
145{ 146{
146 struct nfs_fattr dir_attr;
147 struct nfs3_diropargs arg = { 147 struct nfs3_diropargs arg = {
148 .fh = NFS_FH(dir), 148 .fh = NFS_FH(dir),
149 .name = name->name, 149 .name = name->name,
150 .len = name->len 150 .len = name->len
151 }; 151 };
152 struct nfs3_diropres res = { 152 struct nfs3_diropres res = {
153 .dir_attr = &dir_attr,
154 .fh = fhandle, 153 .fh = fhandle,
155 .fattr = fattr 154 .fattr = fattr
156 }; 155 };
@@ -162,29 +161,30 @@ nfs3_proc_lookup(struct inode *dir, struct qstr *name,
162 int status; 161 int status;
163 162
164 dprintk("NFS call lookup %s\n", name->name); 163 dprintk("NFS call lookup %s\n", name->name);
165 nfs_fattr_init(&dir_attr); 164 res.dir_attr = nfs_alloc_fattr();
165 if (res.dir_attr == NULL)
166 return -ENOMEM;
167
166 nfs_fattr_init(fattr); 168 nfs_fattr_init(fattr);
167 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 169 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
168 nfs_refresh_inode(dir, &dir_attr); 170 nfs_refresh_inode(dir, res.dir_attr);
169 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) { 171 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
170 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; 172 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
171 msg.rpc_argp = fhandle; 173 msg.rpc_argp = fhandle;
172 msg.rpc_resp = fattr; 174 msg.rpc_resp = fattr;
173 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 175 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
174 } 176 }
177 nfs_free_fattr(res.dir_attr);
175 dprintk("NFS reply lookup: %d\n", status); 178 dprintk("NFS reply lookup: %d\n", status);
176 return status; 179 return status;
177} 180}
178 181
179static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry) 182static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
180{ 183{
181 struct nfs_fattr fattr;
182 struct nfs3_accessargs arg = { 184 struct nfs3_accessargs arg = {
183 .fh = NFS_FH(inode), 185 .fh = NFS_FH(inode),
184 }; 186 };
185 struct nfs3_accessres res = { 187 struct nfs3_accessres res;
186 .fattr = &fattr,
187 };
188 struct rpc_message msg = { 188 struct rpc_message msg = {
189 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS], 189 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
190 .rpc_argp = &arg, 190 .rpc_argp = &arg,
@@ -192,7 +192,7 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
192 .rpc_cred = entry->cred, 192 .rpc_cred = entry->cred,
193 }; 193 };
194 int mode = entry->mask; 194 int mode = entry->mask;
195 int status; 195 int status = -ENOMEM;
196 196
197 dprintk("NFS call access\n"); 197 dprintk("NFS call access\n");
198 198
@@ -209,9 +209,13 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
209 if (mode & MAY_EXEC) 209 if (mode & MAY_EXEC)
210 arg.access |= NFS3_ACCESS_EXECUTE; 210 arg.access |= NFS3_ACCESS_EXECUTE;
211 } 211 }
212 nfs_fattr_init(&fattr); 212
213 res.fattr = nfs_alloc_fattr();
214 if (res.fattr == NULL)
215 goto out;
216
213 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 217 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
214 nfs_refresh_inode(inode, &fattr); 218 nfs_refresh_inode(inode, res.fattr);
215 if (status == 0) { 219 if (status == 0) {
216 entry->mask = 0; 220 entry->mask = 0;
217 if (res.access & NFS3_ACCESS_READ) 221 if (res.access & NFS3_ACCESS_READ)
@@ -221,6 +225,8 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
221 if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE)) 225 if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
222 entry->mask |= MAY_EXEC; 226 entry->mask |= MAY_EXEC;
223 } 227 }
228 nfs_free_fattr(res.fattr);
229out:
224 dprintk("NFS reply access: %d\n", status); 230 dprintk("NFS reply access: %d\n", status);
225 return status; 231 return status;
226} 232}
@@ -228,7 +234,7 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
228static int nfs3_proc_readlink(struct inode *inode, struct page *page, 234static int nfs3_proc_readlink(struct inode *inode, struct page *page,
229 unsigned int pgbase, unsigned int pglen) 235 unsigned int pgbase, unsigned int pglen)
230{ 236{
231 struct nfs_fattr fattr; 237 struct nfs_fattr *fattr;
232 struct nfs3_readlinkargs args = { 238 struct nfs3_readlinkargs args = {
233 .fh = NFS_FH(inode), 239 .fh = NFS_FH(inode),
234 .pgbase = pgbase, 240 .pgbase = pgbase,
@@ -238,14 +244,19 @@ static int nfs3_proc_readlink(struct inode *inode, struct page *page,
238 struct rpc_message msg = { 244 struct rpc_message msg = {
239 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK], 245 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
240 .rpc_argp = &args, 246 .rpc_argp = &args,
241 .rpc_resp = &fattr,
242 }; 247 };
243 int status; 248 int status = -ENOMEM;
244 249
245 dprintk("NFS call readlink\n"); 250 dprintk("NFS call readlink\n");
246 nfs_fattr_init(&fattr); 251 fattr = nfs_alloc_fattr();
252 if (fattr == NULL)
253 goto out;
254 msg.rpc_resp = fattr;
255
247 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 256 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
248 nfs_refresh_inode(inode, &fattr); 257 nfs_refresh_inode(inode, fattr);
258 nfs_free_fattr(fattr);
259out:
249 dprintk("NFS reply readlink: %d\n", status); 260 dprintk("NFS reply readlink: %d\n", status);
250 return status; 261 return status;
251} 262}
@@ -299,11 +310,10 @@ static void nfs3_free_createdata(struct nfs3_createdata *data)
299 310
300/* 311/*
301 * Create a regular file. 312 * Create a regular file.
302 * For now, we don't implement O_EXCL.
303 */ 313 */
304static int 314static int
305nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 315nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
306 int flags, struct nameidata *nd) 316 int flags, struct nfs_open_context *ctx)
307{ 317{
308 struct nfs3_createdata *data; 318 struct nfs3_createdata *data;
309 mode_t mode = sattr->ia_mode; 319 mode_t mode = sattr->ia_mode;
@@ -396,12 +406,17 @@ nfs3_proc_remove(struct inode *dir, struct qstr *name)
396 .rpc_argp = &arg, 406 .rpc_argp = &arg,
397 .rpc_resp = &res, 407 .rpc_resp = &res,
398 }; 408 };
399 int status; 409 int status = -ENOMEM;
400 410
401 dprintk("NFS call remove %s\n", name->name); 411 dprintk("NFS call remove %s\n", name->name);
402 nfs_fattr_init(&res.dir_attr); 412 res.dir_attr = nfs_alloc_fattr();
413 if (res.dir_attr == NULL)
414 goto out;
415
403 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 416 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
404 nfs_post_op_update_inode(dir, &res.dir_attr); 417 nfs_post_op_update_inode(dir, res.dir_attr);
418 nfs_free_fattr(res.dir_attr);
419out:
405 dprintk("NFS reply remove: %d\n", status); 420 dprintk("NFS reply remove: %d\n", status);
406 return status; 421 return status;
407} 422}
@@ -419,7 +434,28 @@ nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
419 if (nfs3_async_handle_jukebox(task, dir)) 434 if (nfs3_async_handle_jukebox(task, dir))
420 return 0; 435 return 0;
421 res = task->tk_msg.rpc_resp; 436 res = task->tk_msg.rpc_resp;
422 nfs_post_op_update_inode(dir, &res->dir_attr); 437 nfs_post_op_update_inode(dir, res->dir_attr);
438 return 1;
439}
440
441static void
442nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
443{
444 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
445}
446
447static int
448nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
449 struct inode *new_dir)
450{
451 struct nfs_renameres *res;
452
453 if (nfs3_async_handle_jukebox(task, old_dir))
454 return 0;
455 res = task->tk_msg.rpc_resp;
456
457 nfs_post_op_update_inode(old_dir, res->old_fattr);
458 nfs_post_op_update_inode(new_dir, res->new_fattr);
423 return 1; 459 return 1;
424} 460}
425 461
@@ -427,32 +463,33 @@ static int
427nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, 463nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
428 struct inode *new_dir, struct qstr *new_name) 464 struct inode *new_dir, struct qstr *new_name)
429{ 465{
430 struct nfs_fattr old_dir_attr, new_dir_attr; 466 struct nfs_renameargs arg = {
431 struct nfs3_renameargs arg = { 467 .old_dir = NFS_FH(old_dir),
432 .fromfh = NFS_FH(old_dir), 468 .old_name = old_name,
433 .fromname = old_name->name, 469 .new_dir = NFS_FH(new_dir),
434 .fromlen = old_name->len, 470 .new_name = new_name,
435 .tofh = NFS_FH(new_dir),
436 .toname = new_name->name,
437 .tolen = new_name->len
438 };
439 struct nfs3_renameres res = {
440 .fromattr = &old_dir_attr,
441 .toattr = &new_dir_attr
442 }; 471 };
472 struct nfs_renameres res;
443 struct rpc_message msg = { 473 struct rpc_message msg = {
444 .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME], 474 .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME],
445 .rpc_argp = &arg, 475 .rpc_argp = &arg,
446 .rpc_resp = &res, 476 .rpc_resp = &res,
447 }; 477 };
448 int status; 478 int status = -ENOMEM;
449 479
450 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name); 480 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
451 nfs_fattr_init(&old_dir_attr); 481
452 nfs_fattr_init(&new_dir_attr); 482 res.old_fattr = nfs_alloc_fattr();
483 res.new_fattr = nfs_alloc_fattr();
484 if (res.old_fattr == NULL || res.new_fattr == NULL)
485 goto out;
486
453 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); 487 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
454 nfs_post_op_update_inode(old_dir, &old_dir_attr); 488 nfs_post_op_update_inode(old_dir, res.old_fattr);
455 nfs_post_op_update_inode(new_dir, &new_dir_attr); 489 nfs_post_op_update_inode(new_dir, res.new_fattr);
490out:
491 nfs_free_fattr(res.old_fattr);
492 nfs_free_fattr(res.new_fattr);
456 dprintk("NFS reply rename: %d\n", status); 493 dprintk("NFS reply rename: %d\n", status);
457 return status; 494 return status;
458} 495}
@@ -460,30 +497,32 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
460static int 497static int
461nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) 498nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
462{ 499{
463 struct nfs_fattr dir_attr, fattr;
464 struct nfs3_linkargs arg = { 500 struct nfs3_linkargs arg = {
465 .fromfh = NFS_FH(inode), 501 .fromfh = NFS_FH(inode),
466 .tofh = NFS_FH(dir), 502 .tofh = NFS_FH(dir),
467 .toname = name->name, 503 .toname = name->name,
468 .tolen = name->len 504 .tolen = name->len
469 }; 505 };
470 struct nfs3_linkres res = { 506 struct nfs3_linkres res;
471 .dir_attr = &dir_attr,
472 .fattr = &fattr
473 };
474 struct rpc_message msg = { 507 struct rpc_message msg = {
475 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK], 508 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
476 .rpc_argp = &arg, 509 .rpc_argp = &arg,
477 .rpc_resp = &res, 510 .rpc_resp = &res,
478 }; 511 };
479 int status; 512 int status = -ENOMEM;
480 513
481 dprintk("NFS call link %s\n", name->name); 514 dprintk("NFS call link %s\n", name->name);
482 nfs_fattr_init(&dir_attr); 515 res.fattr = nfs_alloc_fattr();
483 nfs_fattr_init(&fattr); 516 res.dir_attr = nfs_alloc_fattr();
517 if (res.fattr == NULL || res.dir_attr == NULL)
518 goto out;
519
484 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 520 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
485 nfs_post_op_update_inode(dir, &dir_attr); 521 nfs_post_op_update_inode(dir, res.dir_attr);
486 nfs_post_op_update_inode(inode, &fattr); 522 nfs_post_op_update_inode(inode, res.fattr);
523out:
524 nfs_free_fattr(res.dir_attr);
525 nfs_free_fattr(res.fattr);
487 dprintk("NFS reply link: %d\n", status); 526 dprintk("NFS reply link: %d\n", status);
488 return status; 527 return status;
489} 528}
@@ -554,7 +593,7 @@ out:
554static int 593static int
555nfs3_proc_rmdir(struct inode *dir, struct qstr *name) 594nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
556{ 595{
557 struct nfs_fattr dir_attr; 596 struct nfs_fattr *dir_attr;
558 struct nfs3_diropargs arg = { 597 struct nfs3_diropargs arg = {
559 .fh = NFS_FH(dir), 598 .fh = NFS_FH(dir),
560 .name = name->name, 599 .name = name->name,
@@ -563,14 +602,19 @@ nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
563 struct rpc_message msg = { 602 struct rpc_message msg = {
564 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR], 603 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
565 .rpc_argp = &arg, 604 .rpc_argp = &arg,
566 .rpc_resp = &dir_attr,
567 }; 605 };
568 int status; 606 int status = -ENOMEM;
569 607
570 dprintk("NFS call rmdir %s\n", name->name); 608 dprintk("NFS call rmdir %s\n", name->name);
571 nfs_fattr_init(&dir_attr); 609 dir_attr = nfs_alloc_fattr();
610 if (dir_attr == NULL)
611 goto out;
612
613 msg.rpc_resp = dir_attr;
572 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 614 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
573 nfs_post_op_update_inode(dir, &dir_attr); 615 nfs_post_op_update_inode(dir, dir_attr);
616 nfs_free_fattr(dir_attr);
617out:
574 dprintk("NFS reply rmdir: %d\n", status); 618 dprintk("NFS reply rmdir: %d\n", status);
575 return status; 619 return status;
576} 620}
@@ -586,10 +630,9 @@ nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
586 */ 630 */
587static int 631static int
588nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 632nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
589 u64 cookie, struct page *page, unsigned int count, int plus) 633 u64 cookie, struct page **pages, unsigned int count, int plus)
590{ 634{
591 struct inode *dir = dentry->d_inode; 635 struct inode *dir = dentry->d_inode;
592 struct nfs_fattr dir_attr;
593 __be32 *verf = NFS_COOKIEVERF(dir); 636 __be32 *verf = NFS_COOKIEVERF(dir);
594 struct nfs3_readdirargs arg = { 637 struct nfs3_readdirargs arg = {
595 .fh = NFS_FH(dir), 638 .fh = NFS_FH(dir),
@@ -597,10 +640,9 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
597 .verf = {verf[0], verf[1]}, 640 .verf = {verf[0], verf[1]},
598 .plus = plus, 641 .plus = plus,
599 .count = count, 642 .count = count,
600 .pages = &page 643 .pages = pages
601 }; 644 };
602 struct nfs3_readdirres res = { 645 struct nfs3_readdirres res = {
603 .dir_attr = &dir_attr,
604 .verf = verf, 646 .verf = verf,
605 .plus = plus 647 .plus = plus
606 }; 648 };
@@ -610,7 +652,7 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
610 .rpc_resp = &res, 652 .rpc_resp = &res,
611 .rpc_cred = cred 653 .rpc_cred = cred
612 }; 654 };
613 int status; 655 int status = -ENOMEM;
614 656
615 if (plus) 657 if (plus)
616 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; 658 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
@@ -618,13 +660,19 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
618 dprintk("NFS call readdir%s %d\n", 660 dprintk("NFS call readdir%s %d\n",
619 plus? "plus" : "", (unsigned int) cookie); 661 plus? "plus" : "", (unsigned int) cookie);
620 662
621 nfs_fattr_init(&dir_attr); 663 res.dir_attr = nfs_alloc_fattr();
664 if (res.dir_attr == NULL)
665 goto out;
666
622 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 667 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
623 668
624 nfs_invalidate_atime(dir); 669 nfs_invalidate_atime(dir);
670 nfs_refresh_inode(dir, res.dir_attr);
625 671
626 nfs_refresh_inode(dir, &dir_attr); 672 nfs_free_fattr(res.dir_attr);
627 dprintk("NFS reply readdir: %d\n", status); 673out:
674 dprintk("NFS reply readdir%s: %d\n",
675 plus? "plus" : "", status);
628 return status; 676 return status;
629} 677}
630 678
@@ -694,7 +742,7 @@ nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
694 dprintk("NFS call fsstat\n"); 742 dprintk("NFS call fsstat\n");
695 nfs_fattr_init(stat->fattr); 743 nfs_fattr_init(stat->fattr);
696 status = rpc_call_sync(server->client, &msg, 0); 744 status = rpc_call_sync(server->client, &msg, 0);
697 dprintk("NFS reply statfs: %d\n", status); 745 dprintk("NFS reply fsstat: %d\n", status);
698 return status; 746 return status;
699} 747}
700 748
@@ -816,6 +864,8 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
816 .unlink_setup = nfs3_proc_unlink_setup, 864 .unlink_setup = nfs3_proc_unlink_setup,
817 .unlink_done = nfs3_proc_unlink_done, 865 .unlink_done = nfs3_proc_unlink_done,
818 .rename = nfs3_proc_rename, 866 .rename = nfs3_proc_rename,
867 .rename_setup = nfs3_proc_rename_setup,
868 .rename_done = nfs3_proc_rename_done,
819 .link = nfs3_proc_link, 869 .link = nfs3_proc_link,
820 .symlink = nfs3_proc_symlink, 870 .symlink = nfs3_proc_symlink,
821 .mkdir = nfs3_proc_mkdir, 871 .mkdir = nfs3_proc_mkdir,
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index 35869a4921f1..01c5e8b1941d 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -9,8 +9,6 @@
9#include <linux/param.h> 9#include <linux/param.h>
10#include <linux/time.h> 10#include <linux/time.h>
11#include <linux/mm.h> 11#include <linux/mm.h>
12#include <linux/slab.h>
13#include <linux/utsname.h>
14#include <linux/errno.h> 12#include <linux/errno.h>
15#include <linux/string.h> 13#include <linux/string.h>
16#include <linux/in.h> 14#include <linux/in.h>
@@ -39,18 +37,16 @@
39#define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2)) 37#define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
40#define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2)) 38#define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
41#define NFS3_fattr_sz (21) 39#define NFS3_fattr_sz (21)
42#define NFS3_wcc_attr_sz (6) 40#define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2)
41#define NFS3_wcc_attr_sz (6)
43#define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz) 42#define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
44#define NFS3_post_op_attr_sz (1+NFS3_fattr_sz) 43#define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
45#define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz) 44#define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
46#define NFS3_fsstat_sz
47#define NFS3_fsinfo_sz
48#define NFS3_pathconf_sz
49#define NFS3_entry_sz (NFS3_filename_sz+3)
50
51#define NFS3_sattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
52#define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz) 45#define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
53#define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz) 46
47#define NFS3_getattrargs_sz (NFS3_fh_sz)
48#define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
49#define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz)
54#define NFS3_accessargs_sz (NFS3_fh_sz+1) 50#define NFS3_accessargs_sz (NFS3_fh_sz+1)
55#define NFS3_readlinkargs_sz (NFS3_fh_sz) 51#define NFS3_readlinkargs_sz (NFS3_fh_sz)
56#define NFS3_readargs_sz (NFS3_fh_sz+3) 52#define NFS3_readargs_sz (NFS3_fh_sz+3)
@@ -59,14 +55,16 @@
59#define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz) 55#define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
60#define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz) 56#define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
61#define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz) 57#define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
58#define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
62#define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz) 59#define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
63#define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz) 60#define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
64#define NFS3_readdirargs_sz (NFS3_fh_sz+2) 61#define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3)
62#define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4)
65#define NFS3_commitargs_sz (NFS3_fh_sz+3) 63#define NFS3_commitargs_sz (NFS3_fh_sz+3)
66 64
67#define NFS3_attrstat_sz (1+NFS3_fattr_sz) 65#define NFS3_getattrres_sz (1+NFS3_fattr_sz)
68#define NFS3_wccstat_sz (1+NFS3_wcc_data_sz) 66#define NFS3_setattrres_sz (1+NFS3_wcc_data_sz)
69#define NFS3_removeres_sz (NFS3_wccstat_sz) 67#define NFS3_removeres_sz (NFS3_setattrres_sz)
70#define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz)) 68#define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
71#define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1) 69#define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
72#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1) 70#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1)
@@ -103,1074 +101,2361 @@ static const umode_t nfs_type2fmt[] = {
103}; 101};
104 102
105/* 103/*
106 * Common NFS XDR functions as inlines 104 * While encoding arguments, set up the reply buffer in advance to
105 * receive reply data directly into the page cache.
107 */ 106 */
108static inline __be32 * 107static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
109xdr_encode_fhandle(__be32 *p, const struct nfs_fh *fh) 108 unsigned int base, unsigned int len,
109 unsigned int bufsize)
110{ 110{
111 return xdr_encode_array(p, fh->data, fh->size); 111 struct rpc_auth *auth = req->rq_cred->cr_auth;
112 unsigned int replen;
113
114 replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
115 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
112} 116}
113 117
114static inline __be32 * 118/*
115xdr_decode_fhandle(__be32 *p, struct nfs_fh *fh) 119 * Handle decode buffer overflows out-of-line.
120 */
121static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
116{ 122{
117 if ((fh->size = ntohl(*p++)) <= NFS3_FHSIZE) { 123 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
118 memcpy(fh->data, p, fh->size); 124 "Remaining buffer length is %tu words.\n",
119 return p + XDR_QUADLEN(fh->size); 125 func, xdr->end - xdr->p);
120 }
121 return NULL;
122} 126}
123 127
128
124/* 129/*
125 * Encode/decode time. 130 * Encode/decode NFSv3 basic data types
131 *
132 * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
133 * "NFS Version 3 Protocol Specification".
134 *
135 * Not all basic data types have their own encoding and decoding
136 * functions. For run-time efficiency, some data types are encoded
137 * or decoded inline.
126 */ 138 */
127static inline __be32 * 139
128xdr_encode_time3(__be32 *p, struct timespec *timep) 140static void encode_uint32(struct xdr_stream *xdr, u32 value)
129{ 141{
130 *p++ = htonl(timep->tv_sec); 142 __be32 *p = xdr_reserve_space(xdr, 4);
131 *p++ = htonl(timep->tv_nsec); 143 *p = cpu_to_be32(value);
132 return p;
133} 144}
134 145
135static inline __be32 * 146static int decode_uint32(struct xdr_stream *xdr, u32 *value)
136xdr_decode_time3(__be32 *p, struct timespec *timep)
137{ 147{
138 timep->tv_sec = ntohl(*p++); 148 __be32 *p;
139 timep->tv_nsec = ntohl(*p++); 149
140 return p; 150 p = xdr_inline_decode(xdr, 4);
151 if (unlikely(p == NULL))
152 goto out_overflow;
153 *value = be32_to_cpup(p);
154 return 0;
155out_overflow:
156 print_overflow_msg(__func__, xdr);
157 return -EIO;
141} 158}
142 159
143static __be32 * 160static int decode_uint64(struct xdr_stream *xdr, u64 *value)
144xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
145{ 161{
146 unsigned int type, major, minor; 162 __be32 *p;
147 umode_t fmode;
148 163
149 type = ntohl(*p++); 164 p = xdr_inline_decode(xdr, 8);
150 if (type > NF3FIFO) 165 if (unlikely(p == NULL))
151 type = NF3NON; 166 goto out_overflow;
152 fmode = nfs_type2fmt[type]; 167 xdr_decode_hyper(p, value);
153 fattr->mode = (ntohl(*p++) & ~S_IFMT) | fmode; 168 return 0;
154 fattr->nlink = ntohl(*p++); 169out_overflow:
155 fattr->uid = ntohl(*p++); 170 print_overflow_msg(__func__, xdr);
156 fattr->gid = ntohl(*p++); 171 return -EIO;
157 p = xdr_decode_hyper(p, &fattr->size); 172}
158 p = xdr_decode_hyper(p, &fattr->du.nfs3.used);
159
160 /* Turn remote device info into Linux-specific dev_t */
161 major = ntohl(*p++);
162 minor = ntohl(*p++);
163 fattr->rdev = MKDEV(major, minor);
164 if (MAJOR(fattr->rdev) != major || MINOR(fattr->rdev) != minor)
165 fattr->rdev = 0;
166 173
167 p = xdr_decode_hyper(p, &fattr->fsid.major); 174/*
168 fattr->fsid.minor = 0; 175 * fileid3
169 p = xdr_decode_hyper(p, &fattr->fileid); 176 *
170 p = xdr_decode_time3(p, &fattr->atime); 177 * typedef uint64 fileid3;
171 p = xdr_decode_time3(p, &fattr->mtime); 178 */
172 p = xdr_decode_time3(p, &fattr->ctime); 179static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid)
180{
181 return xdr_decode_hyper(p, fileid);
182}
173 183
174 /* Update the mode bits */ 184static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid)
175 fattr->valid |= NFS_ATTR_FATTR_V3; 185{
176 return p; 186 return decode_uint64(xdr, fileid);
177} 187}
178 188
179static inline __be32 * 189/*
180xdr_encode_sattr(__be32 *p, struct iattr *attr) 190 * filename3
191 *
192 * typedef string filename3<>;
193 */
194static void encode_filename3(struct xdr_stream *xdr,
195 const char *name, u32 length)
181{ 196{
182 if (attr->ia_valid & ATTR_MODE) { 197 __be32 *p;
183 *p++ = xdr_one; 198
184 *p++ = htonl(attr->ia_mode & S_IALLUGO); 199 BUG_ON(length > NFS3_MAXNAMLEN);
185 } else { 200 p = xdr_reserve_space(xdr, 4 + length);
186 *p++ = xdr_zero; 201 xdr_encode_opaque(p, name, length);
187 }
188 if (attr->ia_valid & ATTR_UID) {
189 *p++ = xdr_one;
190 *p++ = htonl(attr->ia_uid);
191 } else {
192 *p++ = xdr_zero;
193 }
194 if (attr->ia_valid & ATTR_GID) {
195 *p++ = xdr_one;
196 *p++ = htonl(attr->ia_gid);
197 } else {
198 *p++ = xdr_zero;
199 }
200 if (attr->ia_valid & ATTR_SIZE) {
201 *p++ = xdr_one;
202 p = xdr_encode_hyper(p, (__u64) attr->ia_size);
203 } else {
204 *p++ = xdr_zero;
205 }
206 if (attr->ia_valid & ATTR_ATIME_SET) {
207 *p++ = xdr_two;
208 p = xdr_encode_time3(p, &attr->ia_atime);
209 } else if (attr->ia_valid & ATTR_ATIME) {
210 *p++ = xdr_one;
211 } else {
212 *p++ = xdr_zero;
213 }
214 if (attr->ia_valid & ATTR_MTIME_SET) {
215 *p++ = xdr_two;
216 p = xdr_encode_time3(p, &attr->ia_mtime);
217 } else if (attr->ia_valid & ATTR_MTIME) {
218 *p++ = xdr_one;
219 } else {
220 *p++ = xdr_zero;
221 }
222 return p;
223} 202}
224 203
225static inline __be32 * 204static int decode_inline_filename3(struct xdr_stream *xdr,
226xdr_decode_wcc_attr(__be32 *p, struct nfs_fattr *fattr) 205 const char **name, u32 *length)
227{ 206{
228 p = xdr_decode_hyper(p, &fattr->pre_size); 207 __be32 *p;
229 p = xdr_decode_time3(p, &fattr->pre_mtime); 208 u32 count;
230 p = xdr_decode_time3(p, &fattr->pre_ctime); 209
231 fattr->valid |= NFS_ATTR_FATTR_PRESIZE 210 p = xdr_inline_decode(xdr, 4);
232 | NFS_ATTR_FATTR_PREMTIME 211 if (unlikely(p == NULL))
233 | NFS_ATTR_FATTR_PRECTIME; 212 goto out_overflow;
234 return p; 213 count = be32_to_cpup(p);
214 if (count > NFS3_MAXNAMLEN)
215 goto out_nametoolong;
216 p = xdr_inline_decode(xdr, count);
217 if (unlikely(p == NULL))
218 goto out_overflow;
219 *name = (const char *)p;
220 *length = count;
221 return 0;
222
223out_nametoolong:
224 dprintk("NFS: returned filename too long: %u\n", count);
225 return -ENAMETOOLONG;
226out_overflow:
227 print_overflow_msg(__func__, xdr);
228 return -EIO;
235} 229}
236 230
237static inline __be32 * 231/*
238xdr_decode_post_op_attr(__be32 *p, struct nfs_fattr *fattr) 232 * nfspath3
233 *
234 * typedef string nfspath3<>;
235 */
236static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages,
237 const u32 length)
239{ 238{
240 if (*p++) 239 BUG_ON(length > NFS3_MAXPATHLEN);
241 p = xdr_decode_fattr(p, fattr); 240 encode_uint32(xdr, length);
242 return p; 241 xdr_write_pages(xdr, pages, 0, length);
243} 242}
244 243
245static inline __be32 * 244static int decode_nfspath3(struct xdr_stream *xdr)
246xdr_decode_pre_op_attr(__be32 *p, struct nfs_fattr *fattr)
247{ 245{
248 if (*p++) 246 u32 recvd, count;
249 return xdr_decode_wcc_attr(p, fattr); 247 size_t hdrlen;
250 return p; 248 __be32 *p;
249
250 p = xdr_inline_decode(xdr, 4);
251 if (unlikely(p == NULL))
252 goto out_overflow;
253 count = be32_to_cpup(p);
254 if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
255 goto out_nametoolong;
256 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
257 recvd = xdr->buf->len - hdrlen;
258 if (unlikely(count > recvd))
259 goto out_cheating;
260
261 xdr_read_pages(xdr, count);
262 xdr_terminate_string(xdr->buf, count);
263 return 0;
264
265out_nametoolong:
266 dprintk("NFS: returned pathname too long: %u\n", count);
267 return -ENAMETOOLONG;
268out_cheating:
269 dprintk("NFS: server cheating in pathname result: "
270 "count %u > recvd %u\n", count, recvd);
271 return -EIO;
272out_overflow:
273 print_overflow_msg(__func__, xdr);
274 return -EIO;
251} 275}
252 276
277/*
278 * cookie3
279 *
280 * typedef uint64 cookie3
281 */
282static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie)
283{
284 return xdr_encode_hyper(p, cookie);
285}
253 286
254static inline __be32 * 287static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie)
255xdr_decode_wcc_data(__be32 *p, struct nfs_fattr *fattr)
256{ 288{
257 p = xdr_decode_pre_op_attr(p, fattr); 289 return decode_uint64(xdr, cookie);
258 return xdr_decode_post_op_attr(p, fattr);
259} 290}
260 291
261/* 292/*
262 * NFS encode functions 293 * cookieverf3
294 *
295 * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
263 */ 296 */
297static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier)
298{
299 memcpy(p, verifier, NFS3_COOKIEVERFSIZE);
300 return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE);
301}
302
303static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier)
304{
305 __be32 *p;
306
307 p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
308 if (unlikely(p == NULL))
309 goto out_overflow;
310 memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
311 return 0;
312out_overflow:
313 print_overflow_msg(__func__, xdr);
314 return -EIO;
315}
264 316
265/* 317/*
266 * Encode file handle argument 318 * createverf3
319 *
320 * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
267 */ 321 */
268static int 322static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier)
269nfs3_xdr_fhandle(struct rpc_rqst *req, __be32 *p, struct nfs_fh *fh) 323{
324 __be32 *p;
325
326 p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE);
327 memcpy(p, verifier, NFS3_CREATEVERFSIZE);
328}
329
330static int decode_writeverf3(struct xdr_stream *xdr, __be32 *verifier)
270{ 331{
271 p = xdr_encode_fhandle(p, fh); 332 __be32 *p;
272 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 333
334 p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
335 if (unlikely(p == NULL))
336 goto out_overflow;
337 memcpy(verifier, p, NFS3_WRITEVERFSIZE);
273 return 0; 338 return 0;
339out_overflow:
340 print_overflow_msg(__func__, xdr);
341 return -EIO;
274} 342}
275 343
276/* 344/*
277 * Encode SETATTR arguments 345 * size3
346 *
347 * typedef uint64 size3;
278 */ 348 */
279static int 349static __be32 *xdr_decode_size3(__be32 *p, u64 *size)
280nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args) 350{
281{ 351 return xdr_decode_hyper(p, size);
282 p = xdr_encode_fhandle(p, args->fh);
283 p = xdr_encode_sattr(p, args->sattr);
284 *p++ = htonl(args->guard);
285 if (args->guard)
286 p = xdr_encode_time3(p, &args->guardtime);
287 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
288 return 0;
289} 352}
290 353
291/* 354/*
292 * Encode directory ops argument 355 * nfsstat3
356 *
357 * enum nfsstat3 {
358 * NFS3_OK = 0,
359 * ...
360 * }
293 */ 361 */
294static int 362#define NFS3_OK NFS_OK
295nfs3_xdr_diropargs(struct rpc_rqst *req, __be32 *p, struct nfs3_diropargs *args) 363
364static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
296{ 365{
297 p = xdr_encode_fhandle(p, args->fh); 366 __be32 *p;
298 p = xdr_encode_array(p, args->name, args->len); 367
299 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 368 p = xdr_inline_decode(xdr, 4);
369 if (unlikely(p == NULL))
370 goto out_overflow;
371 *status = be32_to_cpup(p);
300 return 0; 372 return 0;
373out_overflow:
374 print_overflow_msg(__func__, xdr);
375 return -EIO;
301} 376}
302 377
303/* 378/*
304 * Encode REMOVE argument 379 * ftype3
380 *
381 * enum ftype3 {
382 * NF3REG = 1,
383 * NF3DIR = 2,
384 * NF3BLK = 3,
385 * NF3CHR = 4,
386 * NF3LNK = 5,
387 * NF3SOCK = 6,
388 * NF3FIFO = 7
389 * };
305 */ 390 */
306static int 391static void encode_ftype3(struct xdr_stream *xdr, const u32 type)
307nfs3_xdr_removeargs(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
308{ 392{
309 p = xdr_encode_fhandle(p, args->fh); 393 BUG_ON(type > NF3FIFO);
310 p = xdr_encode_array(p, args->name.name, args->name.len); 394 encode_uint32(xdr, type);
311 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 395}
312 return 0; 396
397static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode)
398{
399 u32 type;
400
401 type = be32_to_cpup(p++);
402 if (type > NF3FIFO)
403 type = NF3NON;
404 *mode = nfs_type2fmt[type];
405 return p;
313} 406}
314 407
315/* 408/*
316 * Encode access() argument 409 * specdata3
410 *
411 * struct specdata3 {
412 * uint32 specdata1;
413 * uint32 specdata2;
414 * };
317 */ 415 */
318static int 416static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev)
319nfs3_xdr_accessargs(struct rpc_rqst *req, __be32 *p, struct nfs3_accessargs *args)
320{ 417{
321 p = xdr_encode_fhandle(p, args->fh); 418 __be32 *p;
322 *p++ = htonl(args->access); 419
323 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 420 p = xdr_reserve_space(xdr, 8);
324 return 0; 421 *p++ = cpu_to_be32(MAJOR(rdev));
422 *p = cpu_to_be32(MINOR(rdev));
423}
424
425static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev)
426{
427 unsigned int major, minor;
428
429 major = be32_to_cpup(p++);
430 minor = be32_to_cpup(p++);
431 *rdev = MKDEV(major, minor);
432 if (MAJOR(*rdev) != major || MINOR(*rdev) != minor)
433 *rdev = 0;
434 return p;
325} 435}
326 436
327/* 437/*
328 * Arguments to a READ call. Since we read data directly into the page 438 * nfs_fh3
329 * cache, we also set up the reply iovec here so that iov[1] points 439 *
330 * exactly to the page we want to fetch. 440 * struct nfs_fh3 {
441 * opaque data<NFS3_FHSIZE>;
442 * };
331 */ 443 */
332static int 444static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh)
333nfs3_xdr_readargs(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
334{ 445{
335 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 446 __be32 *p;
336 unsigned int replen;
337 u32 count = args->count;
338 447
339 p = xdr_encode_fhandle(p, args->fh); 448 BUG_ON(fh->size > NFS3_FHSIZE);
340 p = xdr_encode_hyper(p, args->offset); 449 p = xdr_reserve_space(xdr, 4 + fh->size);
341 *p++ = htonl(count); 450 xdr_encode_opaque(p, fh->data, fh->size);
342 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 451}
343 452
344 /* Inline the page array */ 453static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
345 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS3_readres_sz) << 2; 454{
346 xdr_inline_pages(&req->rq_rcv_buf, replen, 455 u32 length;
347 args->pages, args->pgbase, count); 456 __be32 *p;
348 req->rq_rcv_buf.flags |= XDRBUF_READ; 457
458 p = xdr_inline_decode(xdr, 4);
459 if (unlikely(p == NULL))
460 goto out_overflow;
461 length = be32_to_cpup(p++);
462 if (unlikely(length > NFS3_FHSIZE))
463 goto out_toobig;
464 p = xdr_inline_decode(xdr, length);
465 if (unlikely(p == NULL))
466 goto out_overflow;
467 fh->size = length;
468 memcpy(fh->data, p, length);
349 return 0; 469 return 0;
470out_toobig:
471 dprintk("NFS: file handle size (%u) too big\n", length);
472 return -E2BIG;
473out_overflow:
474 print_overflow_msg(__func__, xdr);
475 return -EIO;
476}
477
478static void zero_nfs_fh3(struct nfs_fh *fh)
479{
480 memset(fh, 0, sizeof(*fh));
350} 481}
351 482
352/* 483/*
353 * Write arguments. Splice the buffer to be written into the iovec. 484 * nfstime3
485 *
486 * struct nfstime3 {
487 * uint32 seconds;
488 * uint32 nseconds;
489 * };
354 */ 490 */
355static int 491static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep)
356nfs3_xdr_writeargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
357{ 492{
358 struct xdr_buf *sndbuf = &req->rq_snd_buf; 493 *p++ = cpu_to_be32(timep->tv_sec);
359 u32 count = args->count; 494 *p++ = cpu_to_be32(timep->tv_nsec);
495 return p;
496}
360 497
361 p = xdr_encode_fhandle(p, args->fh); 498static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep)
362 p = xdr_encode_hyper(p, args->offset); 499{
363 *p++ = htonl(count); 500 timep->tv_sec = be32_to_cpup(p++);
364 *p++ = htonl(args->stable); 501 timep->tv_nsec = be32_to_cpup(p++);
365 *p++ = htonl(count); 502 return p;
366 sndbuf->len = xdr_adjust_iovec(sndbuf->head, p);
367
368 /* Copy the page array */
369 xdr_encode_pages(sndbuf, args->pages, args->pgbase, count);
370 sndbuf->flags |= XDRBUF_WRITE;
371 return 0;
372} 503}
373 504
374/* 505/*
375 * Encode CREATE arguments 506 * sattr3
507 *
508 * enum time_how {
509 * DONT_CHANGE = 0,
510 * SET_TO_SERVER_TIME = 1,
511 * SET_TO_CLIENT_TIME = 2
512 * };
513 *
514 * union set_mode3 switch (bool set_it) {
515 * case TRUE:
516 * mode3 mode;
517 * default:
518 * void;
519 * };
520 *
521 * union set_uid3 switch (bool set_it) {
522 * case TRUE:
523 * uid3 uid;
524 * default:
525 * void;
526 * };
527 *
528 * union set_gid3 switch (bool set_it) {
529 * case TRUE:
530 * gid3 gid;
531 * default:
532 * void;
533 * };
534 *
535 * union set_size3 switch (bool set_it) {
536 * case TRUE:
537 * size3 size;
538 * default:
539 * void;
540 * };
541 *
542 * union set_atime switch (time_how set_it) {
543 * case SET_TO_CLIENT_TIME:
544 * nfstime3 atime;
545 * default:
546 * void;
547 * };
548 *
549 * union set_mtime switch (time_how set_it) {
550 * case SET_TO_CLIENT_TIME:
551 * nfstime3 mtime;
552 * default:
553 * void;
554 * };
555 *
556 * struct sattr3 {
557 * set_mode3 mode;
558 * set_uid3 uid;
559 * set_gid3 gid;
560 * set_size3 size;
561 * set_atime atime;
562 * set_mtime mtime;
563 * };
376 */ 564 */
377static int 565static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
378nfs3_xdr_createargs(struct rpc_rqst *req, __be32 *p, struct nfs3_createargs *args)
379{ 566{
380 p = xdr_encode_fhandle(p, args->fh); 567 u32 nbytes;
381 p = xdr_encode_array(p, args->name, args->len); 568 __be32 *p;
569
570 /*
571 * In order to make only a single xdr_reserve_space() call,
572 * pre-compute the total number of bytes to be reserved.
573 * Six boolean values, one for each set_foo field, are always
574 * present in the encoded result, so start there.
575 */
576 nbytes = 6 * 4;
577 if (attr->ia_valid & ATTR_MODE)
578 nbytes += 4;
579 if (attr->ia_valid & ATTR_UID)
580 nbytes += 4;
581 if (attr->ia_valid & ATTR_GID)
582 nbytes += 4;
583 if (attr->ia_valid & ATTR_SIZE)
584 nbytes += 8;
585 if (attr->ia_valid & ATTR_ATIME_SET)
586 nbytes += 8;
587 if (attr->ia_valid & ATTR_MTIME_SET)
588 nbytes += 8;
589 p = xdr_reserve_space(xdr, nbytes);
382 590
383 *p++ = htonl(args->createmode); 591 if (attr->ia_valid & ATTR_MODE) {
384 if (args->createmode == NFS3_CREATE_EXCLUSIVE) { 592 *p++ = xdr_one;
385 *p++ = args->verifier[0]; 593 *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
386 *p++ = args->verifier[1];
387 } else 594 } else
388 p = xdr_encode_sattr(p, args->sattr); 595 *p++ = xdr_zero;
389 596
390 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 597 if (attr->ia_valid & ATTR_UID) {
391 return 0; 598 *p++ = xdr_one;
599 *p++ = cpu_to_be32(attr->ia_uid);
600 } else
601 *p++ = xdr_zero;
602
603 if (attr->ia_valid & ATTR_GID) {
604 *p++ = xdr_one;
605 *p++ = cpu_to_be32(attr->ia_gid);
606 } else
607 *p++ = xdr_zero;
608
609 if (attr->ia_valid & ATTR_SIZE) {
610 *p++ = xdr_one;
611 p = xdr_encode_hyper(p, (u64)attr->ia_size);
612 } else
613 *p++ = xdr_zero;
614
615 if (attr->ia_valid & ATTR_ATIME_SET) {
616 *p++ = xdr_two;
617 p = xdr_encode_nfstime3(p, &attr->ia_atime);
618 } else if (attr->ia_valid & ATTR_ATIME) {
619 *p++ = xdr_one;
620 } else
621 *p++ = xdr_zero;
622
623 if (attr->ia_valid & ATTR_MTIME_SET) {
624 *p++ = xdr_two;
625 xdr_encode_nfstime3(p, &attr->ia_mtime);
626 } else if (attr->ia_valid & ATTR_MTIME) {
627 *p = xdr_one;
628 } else
629 *p = xdr_zero;
392} 630}
393 631
394/* 632/*
395 * Encode MKDIR arguments 633 * fattr3
634 *
635 * struct fattr3 {
636 * ftype3 type;
637 * mode3 mode;
638 * uint32 nlink;
639 * uid3 uid;
640 * gid3 gid;
641 * size3 size;
642 * size3 used;
643 * specdata3 rdev;
644 * uint64 fsid;
645 * fileid3 fileid;
646 * nfstime3 atime;
647 * nfstime3 mtime;
648 * nfstime3 ctime;
649 * };
396 */ 650 */
397static int 651static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr)
398nfs3_xdr_mkdirargs(struct rpc_rqst *req, __be32 *p, struct nfs3_mkdirargs *args)
399{ 652{
400 p = xdr_encode_fhandle(p, args->fh); 653 umode_t fmode;
401 p = xdr_encode_array(p, args->name, args->len); 654 __be32 *p;
402 p = xdr_encode_sattr(p, args->sattr); 655
403 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 656 p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
657 if (unlikely(p == NULL))
658 goto out_overflow;
659
660 p = xdr_decode_ftype3(p, &fmode);
661
662 fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
663 fattr->nlink = be32_to_cpup(p++);
664 fattr->uid = be32_to_cpup(p++);
665 fattr->gid = be32_to_cpup(p++);
666
667 p = xdr_decode_size3(p, &fattr->size);
668 p = xdr_decode_size3(p, &fattr->du.nfs3.used);
669 p = xdr_decode_specdata3(p, &fattr->rdev);
670
671 p = xdr_decode_hyper(p, &fattr->fsid.major);
672 fattr->fsid.minor = 0;
673
674 p = xdr_decode_fileid3(p, &fattr->fileid);
675 p = xdr_decode_nfstime3(p, &fattr->atime);
676 p = xdr_decode_nfstime3(p, &fattr->mtime);
677 xdr_decode_nfstime3(p, &fattr->ctime);
678
679 fattr->valid |= NFS_ATTR_FATTR_V3;
404 return 0; 680 return 0;
681out_overflow:
682 print_overflow_msg(__func__, xdr);
683 return -EIO;
405} 684}
406 685
407/* 686/*
408 * Encode SYMLINK arguments 687 * post_op_attr
688 *
689 * union post_op_attr switch (bool attributes_follow) {
690 * case TRUE:
691 * fattr3 attributes;
692 * case FALSE:
693 * void;
694 * };
409 */ 695 */
410static int 696static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
411nfs3_xdr_symlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs3_symlinkargs *args)
412{ 697{
413 p = xdr_encode_fhandle(p, args->fromfh); 698 __be32 *p;
414 p = xdr_encode_array(p, args->fromname, args->fromlen);
415 p = xdr_encode_sattr(p, args->sattr);
416 *p++ = htonl(args->pathlen);
417 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
418 699
419 /* Copy the page */ 700 p = xdr_inline_decode(xdr, 4);
420 xdr_encode_pages(&req->rq_snd_buf, args->pages, 0, args->pathlen); 701 if (unlikely(p == NULL))
702 goto out_overflow;
703 if (*p != xdr_zero)
704 return decode_fattr3(xdr, fattr);
421 return 0; 705 return 0;
706out_overflow:
707 print_overflow_msg(__func__, xdr);
708 return -EIO;
422} 709}
423 710
424/* 711/*
425 * Encode MKNOD arguments 712 * wcc_attr
713 * struct wcc_attr {
714 * size3 size;
715 * nfstime3 mtime;
716 * nfstime3 ctime;
717 * };
426 */ 718 */
427static int 719static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
428nfs3_xdr_mknodargs(struct rpc_rqst *req, __be32 *p, struct nfs3_mknodargs *args) 720{
429{ 721 __be32 *p;
430 p = xdr_encode_fhandle(p, args->fh); 722
431 p = xdr_encode_array(p, args->name, args->len); 723 p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
432 *p++ = htonl(args->type); 724 if (unlikely(p == NULL))
433 p = xdr_encode_sattr(p, args->sattr); 725 goto out_overflow;
434 if (args->type == NF3CHR || args->type == NF3BLK) { 726
435 *p++ = htonl(MAJOR(args->rdev)); 727 fattr->valid |= NFS_ATTR_FATTR_PRESIZE
436 *p++ = htonl(MINOR(args->rdev)); 728 | NFS_ATTR_FATTR_PREMTIME
437 } 729 | NFS_ATTR_FATTR_PRECTIME;
730
731 p = xdr_decode_size3(p, &fattr->pre_size);
732 p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
733 xdr_decode_nfstime3(p, &fattr->pre_ctime);
438 734
439 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
440 return 0; 735 return 0;
736out_overflow:
737 print_overflow_msg(__func__, xdr);
738 return -EIO;
441} 739}
442 740
443/* 741/*
444 * Encode RENAME arguments 742 * pre_op_attr
743 * union pre_op_attr switch (bool attributes_follow) {
744 * case TRUE:
745 * wcc_attr attributes;
746 * case FALSE:
747 * void;
748 * };
749 *
750 * wcc_data
751 *
752 * struct wcc_data {
753 * pre_op_attr before;
754 * post_op_attr after;
755 * };
445 */ 756 */
446static int 757static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
447nfs3_xdr_renameargs(struct rpc_rqst *req, __be32 *p, struct nfs3_renameargs *args) 758{
448{ 759 __be32 *p;
449 p = xdr_encode_fhandle(p, args->fromfh); 760
450 p = xdr_encode_array(p, args->fromname, args->fromlen); 761 p = xdr_inline_decode(xdr, 4);
451 p = xdr_encode_fhandle(p, args->tofh); 762 if (unlikely(p == NULL))
452 p = xdr_encode_array(p, args->toname, args->tolen); 763 goto out_overflow;
453 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 764 if (*p != xdr_zero)
765 return decode_wcc_attr(xdr, fattr);
454 return 0; 766 return 0;
767out_overflow:
768 print_overflow_msg(__func__, xdr);
769 return -EIO;
455} 770}
456 771
457/* 772static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr)
458 * Encode LINK arguments
459 */
460static int
461nfs3_xdr_linkargs(struct rpc_rqst *req, __be32 *p, struct nfs3_linkargs *args)
462{ 773{
463 p = xdr_encode_fhandle(p, args->fromfh); 774 int error;
464 p = xdr_encode_fhandle(p, args->tofh); 775
465 p = xdr_encode_array(p, args->toname, args->tolen); 776 error = decode_pre_op_attr(xdr, fattr);
466 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 777 if (unlikely(error))
467 return 0; 778 goto out;
779 error = decode_post_op_attr(xdr, fattr);
780out:
781 return error;
468} 782}
469 783
470/* 784/*
471 * Encode arguments to readdir call 785 * post_op_fh3
786 *
787 * union post_op_fh3 switch (bool handle_follows) {
788 * case TRUE:
789 * nfs_fh3 handle;
790 * case FALSE:
791 * void;
792 * };
472 */ 793 */
473static int 794static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
474nfs3_xdr_readdirargs(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirargs *args)
475{ 795{
476 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 796 __be32 *p = xdr_inline_decode(xdr, 4);
477 unsigned int replen; 797 if (unlikely(p == NULL))
478 u32 count = args->count; 798 goto out_overflow;
479 799 if (*p != xdr_zero)
480 p = xdr_encode_fhandle(p, args->fh); 800 return decode_nfs_fh3(xdr, fh);
481 p = xdr_encode_hyper(p, args->cookie); 801 zero_nfs_fh3(fh);
482 *p++ = args->verf[0];
483 *p++ = args->verf[1];
484 if (args->plus) {
485 /* readdirplus: need dircount + buffer size.
486 * We just make sure we make dircount big enough */
487 *p++ = htonl(count >> 3);
488 }
489 *p++ = htonl(count);
490 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
491
492 /* Inline the page array */
493 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS3_readdirres_sz) << 2;
494 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, count);
495 return 0; 802 return 0;
803out_overflow:
804 print_overflow_msg(__func__, xdr);
805 return -EIO;
496} 806}
497 807
498/* 808/*
499 * Decode the result of a readdir call. 809 * diropargs3
500 * We just check for syntactical correctness. 810 *
811 * struct diropargs3 {
812 * nfs_fh3 dir;
813 * filename3 name;
814 * };
501 */ 815 */
502static int 816static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
503nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res) 817 const char *name, u32 length)
504{ 818{
505 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 819 encode_nfs_fh3(xdr, fh);
506 struct kvec *iov = rcvbuf->head; 820 encode_filename3(xdr, name, length);
507 struct page **page; 821}
508 size_t hdrlen;
509 u32 len, recvd, pglen;
510 int status, nr = 0;
511 __be32 *entry, *end, *kaddr;
512
513 status = ntohl(*p++);
514 /* Decode post_op_attrs */
515 p = xdr_decode_post_op_attr(p, res->dir_attr);
516 if (status)
517 return nfs_stat_to_errno(status);
518 /* Decode verifier cookie */
519 if (res->verf) {
520 res->verf[0] = *p++;
521 res->verf[1] = *p++;
522 } else {
523 p += 2;
524 }
525
526 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
527 if (iov->iov_len < hdrlen) {
528 dprintk("NFS: READDIR reply header overflowed:"
529 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
530 return -errno_NFSERR_IO;
531 } else if (iov->iov_len != hdrlen) {
532 dprintk("NFS: READDIR header is short. iovec will be shifted.\n");
533 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
534 }
535 822
536 pglen = rcvbuf->page_len;
537 recvd = rcvbuf->len - hdrlen;
538 if (pglen > recvd)
539 pglen = recvd;
540 page = rcvbuf->pages;
541 kaddr = p = kmap_atomic(*page, KM_USER0);
542 end = (__be32 *)((char *)p + pglen);
543 entry = p;
544
545 /* Make sure the packet actually has a value_follows and EOF entry */
546 if ((entry + 1) > end)
547 goto short_pkt;
548
549 for (; *p++; nr++) {
550 if (p + 3 > end)
551 goto short_pkt;
552 p += 2; /* inode # */
553 len = ntohl(*p++); /* string length */
554 p += XDR_QUADLEN(len) + 2; /* name + cookie */
555 if (len > NFS3_MAXNAMLEN) {
556 dprintk("NFS: giant filename in readdir (len 0x%x)!\n",
557 len);
558 goto err_unmap;
559 }
560
561 if (res->plus) {
562 /* post_op_attr */
563 if (p + 2 > end)
564 goto short_pkt;
565 if (*p++) {
566 p += 21;
567 if (p + 1 > end)
568 goto short_pkt;
569 }
570 /* post_op_fh3 */
571 if (*p++) {
572 if (p + 1 > end)
573 goto short_pkt;
574 len = ntohl(*p++);
575 if (len > NFS3_FHSIZE) {
576 dprintk("NFS: giant filehandle in "
577 "readdir (len 0x%x)!\n", len);
578 goto err_unmap;
579 }
580 p += XDR_QUADLEN(len);
581 }
582 }
583 823
584 if (p + 2 > end) 824/*
585 goto short_pkt; 825 * NFSv3 XDR encode functions
586 entry = p; 826 *
587 } 827 * NFSv3 argument types are defined in section 3.3 of RFC 1813:
828 * "NFS Version 3 Protocol Specification".
829 */
588 830
589 /* 831/*
590 * Apparently some server sends responses that are a valid size, but 832 * 3.3.1 GETATTR3args
591 * contain no entries, and have value_follows==0 and EOF==0. For 833 *
592 * those, just set the EOF marker. 834 * struct GETATTR3args {
593 */ 835 * nfs_fh3 object;
594 if (!nr && entry[1] == 0) { 836 * };
595 dprintk("NFS: readdir reply truncated!\n"); 837 */
596 entry[1] = 1; 838static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
597 } 839 struct xdr_stream *xdr,
598 out: 840 const struct nfs_fh *fh)
599 kunmap_atomic(kaddr, KM_USER0); 841{
600 return nr; 842 encode_nfs_fh3(xdr, fh);
601 short_pkt:
602 /*
603 * When we get a short packet there are 2 possibilities. We can
604 * return an error, or fix up the response to look like a valid
605 * response and return what we have so far. If there are no
606 * entries and the packet was short, then return -EIO. If there
607 * are valid entries in the response, return them and pretend that
608 * the call was successful, but incomplete. The caller can retry the
609 * readdir starting at the last cookie.
610 */
611 entry[0] = entry[1] = 0;
612 if (!nr)
613 nr = -errno_NFSERR_IO;
614 goto out;
615err_unmap:
616 nr = -errno_NFSERR_IO;
617 goto out;
618} 843}
619 844
620__be32 * 845/*
621nfs3_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) 846 * 3.3.2 SETATTR3args
847 *
848 * union sattrguard3 switch (bool check) {
849 * case TRUE:
850 * nfstime3 obj_ctime;
851 * case FALSE:
852 * void;
853 * };
854 *
855 * struct SETATTR3args {
856 * nfs_fh3 object;
857 * sattr3 new_attributes;
858 * sattrguard3 guard;
859 * };
860 */
861static void encode_sattrguard3(struct xdr_stream *xdr,
862 const struct nfs3_sattrargs *args)
622{ 863{
623 struct nfs_entry old = *entry; 864 __be32 *p;
624
625 if (!*p++) {
626 if (!*p)
627 return ERR_PTR(-EAGAIN);
628 entry->eof = 1;
629 return ERR_PTR(-EBADCOOKIE);
630 }
631
632 p = xdr_decode_hyper(p, &entry->ino);
633 entry->len = ntohl(*p++);
634 entry->name = (const char *) p;
635 p += XDR_QUADLEN(entry->len);
636 entry->prev_cookie = entry->cookie;
637 p = xdr_decode_hyper(p, &entry->cookie);
638 865
639 if (plus) { 866 if (args->guard) {
640 entry->fattr->valid = 0; 867 p = xdr_reserve_space(xdr, 4 + 8);
641 p = xdr_decode_post_op_attr(p, entry->fattr); 868 *p++ = xdr_one;
642 /* In fact, a post_op_fh3: */ 869 xdr_encode_nfstime3(p, &args->guardtime);
643 if (*p++) { 870 } else {
644 p = xdr_decode_fhandle(p, entry->fh); 871 p = xdr_reserve_space(xdr, 4);
645 /* Ugh -- server reply was truncated */ 872 *p = xdr_zero;
646 if (p == NULL) {
647 dprintk("NFS: FH truncated\n");
648 *entry = old;
649 return ERR_PTR(-EAGAIN);
650 }
651 } else
652 memset((u8*)(entry->fh), 0, sizeof(*entry->fh));
653 } 873 }
874}
654 875
655 entry->eof = !p[0] && p[1]; 876static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
656 return p; 877 struct xdr_stream *xdr,
878 const struct nfs3_sattrargs *args)
879{
880 encode_nfs_fh3(xdr, args->fh);
881 encode_sattr3(xdr, args->sattr);
882 encode_sattrguard3(xdr, args);
657} 883}
658 884
659/* 885/*
660 * Encode COMMIT arguments 886 * 3.3.3 LOOKUP3args
887 *
888 * struct LOOKUP3args {
889 * diropargs3 what;
890 * };
661 */ 891 */
662static int 892static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
663nfs3_xdr_commitargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 893 struct xdr_stream *xdr,
894 const struct nfs3_diropargs *args)
664{ 895{
665 p = xdr_encode_fhandle(p, args->fh); 896 encode_diropargs3(xdr, args->fh, args->name, args->len);
666 p = xdr_encode_hyper(p, args->offset);
667 *p++ = htonl(args->count);
668 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
669 return 0;
670} 897}
671 898
672#ifdef CONFIG_NFS_V3_ACL
673/* 899/*
674 * Encode GETACL arguments 900 * 3.3.4 ACCESS3args
901 *
902 * struct ACCESS3args {
903 * nfs_fh3 object;
904 * uint32 access;
905 * };
675 */ 906 */
676static int 907static void encode_access3args(struct xdr_stream *xdr,
677nfs3_xdr_getaclargs(struct rpc_rqst *req, __be32 *p, 908 const struct nfs3_accessargs *args)
678 struct nfs3_getaclargs *args)
679{ 909{
680 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 910 encode_nfs_fh3(xdr, args->fh);
681 unsigned int replen; 911 encode_uint32(xdr, args->access);
912}
682 913
683 p = xdr_encode_fhandle(p, args->fh); 914static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
684 *p++ = htonl(args->mask); 915 struct xdr_stream *xdr,
685 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 916 const struct nfs3_accessargs *args)
917{
918 encode_access3args(xdr, args);
919}
686 920
687 if (args->mask & (NFS_ACL | NFS_DFACL)) { 921/*
688 /* Inline the page array */ 922 * 3.3.5 READLINK3args
689 replen = (RPC_REPHDRSIZE + auth->au_rslack + 923 *
690 ACL3_getaclres_sz) << 2; 924 * struct READLINK3args {
691 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, 925 * nfs_fh3 symlink;
692 NFSACL_MAXPAGES << PAGE_SHIFT); 926 * };
693 } 927 */
694 return 0; 928static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
929 struct xdr_stream *xdr,
930 const struct nfs3_readlinkargs *args)
931{
932 encode_nfs_fh3(xdr, args->fh);
933 prepare_reply_buffer(req, args->pages, args->pgbase,
934 args->pglen, NFS3_readlinkres_sz);
695} 935}
696 936
697/* 937/*
698 * Encode SETACL arguments 938 * 3.3.6 READ3args
939 *
940 * struct READ3args {
941 * nfs_fh3 file;
942 * offset3 offset;
943 * count3 count;
944 * };
699 */ 945 */
700static int 946static void encode_read3args(struct xdr_stream *xdr,
701nfs3_xdr_setaclargs(struct rpc_rqst *req, __be32 *p, 947 const struct nfs_readargs *args)
702 struct nfs3_setaclargs *args)
703{ 948{
704 struct xdr_buf *buf = &req->rq_snd_buf; 949 __be32 *p;
705 unsigned int base;
706 int err;
707 950
708 p = xdr_encode_fhandle(p, NFS_FH(args->inode)); 951 encode_nfs_fh3(xdr, args->fh);
709 *p++ = htonl(args->mask);
710 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
711 base = req->rq_slen;
712 952
713 if (args->npages != 0) 953 p = xdr_reserve_space(xdr, 8 + 4);
714 xdr_encode_pages(buf, args->pages, 0, args->len); 954 p = xdr_encode_hyper(p, args->offset);
715 else 955 *p = cpu_to_be32(args->count);
716 req->rq_slen = xdr_adjust_iovec(req->rq_svec, 956}
717 p + XDR_QUADLEN(args->len));
718 957
719 err = nfsacl_encode(buf, base, args->inode, 958static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
720 (args->mask & NFS_ACL) ? 959 struct xdr_stream *xdr,
721 args->acl_access : NULL, 1, 0); 960 const struct nfs_readargs *args)
722 if (err > 0) 961{
723 err = nfsacl_encode(buf, base + err, args->inode, 962 encode_read3args(xdr, args);
724 (args->mask & NFS_DFACL) ? 963 prepare_reply_buffer(req, args->pages, args->pgbase,
725 args->acl_default : NULL, 1, 964 args->count, NFS3_readres_sz);
726 NFS_ACL_DEFAULT); 965 req->rq_rcv_buf.flags |= XDRBUF_READ;
727 return (err > 0) ? 0 : err;
728} 966}
729#endif /* CONFIG_NFS_V3_ACL */
730 967
731/* 968/*
732 * NFS XDR decode functions 969 * 3.3.7 WRITE3args
970 *
971 * enum stable_how {
972 * UNSTABLE = 0,
973 * DATA_SYNC = 1,
974 * FILE_SYNC = 2
975 * };
976 *
977 * struct WRITE3args {
978 * nfs_fh3 file;
979 * offset3 offset;
980 * count3 count;
981 * stable_how stable;
982 * opaque data<>;
983 * };
733 */ 984 */
985static void encode_write3args(struct xdr_stream *xdr,
986 const struct nfs_writeargs *args)
987{
988 __be32 *p;
989
990 encode_nfs_fh3(xdr, args->fh);
991
992 p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4);
993 p = xdr_encode_hyper(p, args->offset);
994 *p++ = cpu_to_be32(args->count);
995 *p++ = cpu_to_be32(args->stable);
996 *p = cpu_to_be32(args->count);
997 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
998}
999
1000static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
1001 struct xdr_stream *xdr,
1002 const struct nfs_writeargs *args)
1003{
1004 encode_write3args(xdr, args);
1005 xdr->buf->flags |= XDRBUF_WRITE;
1006}
734 1007
735/* 1008/*
736 * Decode attrstat reply. 1009 * 3.3.8 CREATE3args
1010 *
1011 * enum createmode3 {
1012 * UNCHECKED = 0,
1013 * GUARDED = 1,
1014 * EXCLUSIVE = 2
1015 * };
1016 *
1017 * union createhow3 switch (createmode3 mode) {
1018 * case UNCHECKED:
1019 * case GUARDED:
1020 * sattr3 obj_attributes;
1021 * case EXCLUSIVE:
1022 * createverf3 verf;
1023 * };
1024 *
1025 * struct CREATE3args {
1026 * diropargs3 where;
1027 * createhow3 how;
1028 * };
737 */ 1029 */
738static int 1030static void encode_createhow3(struct xdr_stream *xdr,
739nfs3_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) 1031 const struct nfs3_createargs *args)
740{ 1032{
741 int status; 1033 encode_uint32(xdr, args->createmode);
1034 switch (args->createmode) {
1035 case NFS3_CREATE_UNCHECKED:
1036 case NFS3_CREATE_GUARDED:
1037 encode_sattr3(xdr, args->sattr);
1038 break;
1039 case NFS3_CREATE_EXCLUSIVE:
1040 encode_createverf3(xdr, args->verifier);
1041 break;
1042 default:
1043 BUG();
1044 }
1045}
742 1046
743 if ((status = ntohl(*p++))) 1047static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
744 return nfs_stat_to_errno(status); 1048 struct xdr_stream *xdr,
745 xdr_decode_fattr(p, fattr); 1049 const struct nfs3_createargs *args)
746 return 0; 1050{
1051 encode_diropargs3(xdr, args->fh, args->name, args->len);
1052 encode_createhow3(xdr, args);
747} 1053}
748 1054
749/* 1055/*
750 * Decode status+wcc_data reply 1056 * 3.3.9 MKDIR3args
751 * SATTR, REMOVE, RMDIR 1057 *
1058 * struct MKDIR3args {
1059 * diropargs3 where;
1060 * sattr3 attributes;
1061 * };
752 */ 1062 */
753static int 1063static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
754nfs3_xdr_wccstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) 1064 struct xdr_stream *xdr,
1065 const struct nfs3_mkdirargs *args)
755{ 1066{
756 int status; 1067 encode_diropargs3(xdr, args->fh, args->name, args->len);
1068 encode_sattr3(xdr, args->sattr);
1069}
757 1070
758 if ((status = ntohl(*p++))) 1071/*
759 status = nfs_stat_to_errno(status); 1072 * 3.3.10 SYMLINK3args
760 xdr_decode_wcc_data(p, fattr); 1073 *
761 return status; 1074 * struct symlinkdata3 {
1075 * sattr3 symlink_attributes;
1076 * nfspath3 symlink_data;
1077 * };
1078 *
1079 * struct SYMLINK3args {
1080 * diropargs3 where;
1081 * symlinkdata3 symlink;
1082 * };
1083 */
1084static void encode_symlinkdata3(struct xdr_stream *xdr,
1085 const struct nfs3_symlinkargs *args)
1086{
1087 encode_sattr3(xdr, args->sattr);
1088 encode_nfspath3(xdr, args->pages, args->pathlen);
762} 1089}
763 1090
764static int 1091static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
765nfs3_xdr_removeres(struct rpc_rqst *req, __be32 *p, struct nfs_removeres *res) 1092 struct xdr_stream *xdr,
1093 const struct nfs3_symlinkargs *args)
766{ 1094{
767 return nfs3_xdr_wccstat(req, p, &res->dir_attr); 1095 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
1096 encode_symlinkdata3(xdr, args);
768} 1097}
769 1098
770/* 1099/*
771 * Decode LOOKUP reply 1100 * 3.3.11 MKNOD3args
1101 *
1102 * struct devicedata3 {
1103 * sattr3 dev_attributes;
1104 * specdata3 spec;
1105 * };
1106 *
1107 * union mknoddata3 switch (ftype3 type) {
1108 * case NF3CHR:
1109 * case NF3BLK:
1110 * devicedata3 device;
1111 * case NF3SOCK:
1112 * case NF3FIFO:
1113 * sattr3 pipe_attributes;
1114 * default:
1115 * void;
1116 * };
1117 *
1118 * struct MKNOD3args {
1119 * diropargs3 where;
1120 * mknoddata3 what;
1121 * };
772 */ 1122 */
773static int 1123static void encode_devicedata3(struct xdr_stream *xdr,
774nfs3_xdr_lookupres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res) 1124 const struct nfs3_mknodargs *args)
775{ 1125{
776 int status; 1126 encode_sattr3(xdr, args->sattr);
1127 encode_specdata3(xdr, args->rdev);
1128}
777 1129
778 if ((status = ntohl(*p++))) { 1130static void encode_mknoddata3(struct xdr_stream *xdr,
779 status = nfs_stat_to_errno(status); 1131 const struct nfs3_mknodargs *args)
780 } else { 1132{
781 if (!(p = xdr_decode_fhandle(p, res->fh))) 1133 encode_ftype3(xdr, args->type);
782 return -errno_NFSERR_IO; 1134 switch (args->type) {
783 p = xdr_decode_post_op_attr(p, res->fattr); 1135 case NF3CHR:
1136 case NF3BLK:
1137 encode_devicedata3(xdr, args);
1138 break;
1139 case NF3SOCK:
1140 case NF3FIFO:
1141 encode_sattr3(xdr, args->sattr);
1142 break;
1143 case NF3REG:
1144 case NF3DIR:
1145 break;
1146 default:
1147 BUG();
784 } 1148 }
785 xdr_decode_post_op_attr(p, res->dir_attr); 1149}
786 return status; 1150
1151static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
1152 struct xdr_stream *xdr,
1153 const struct nfs3_mknodargs *args)
1154{
1155 encode_diropargs3(xdr, args->fh, args->name, args->len);
1156 encode_mknoddata3(xdr, args);
787} 1157}
788 1158
789/* 1159/*
790 * Decode ACCESS reply 1160 * 3.3.12 REMOVE3args
1161 *
1162 * struct REMOVE3args {
1163 * diropargs3 object;
1164 * };
791 */ 1165 */
792static int 1166static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
793nfs3_xdr_accessres(struct rpc_rqst *req, __be32 *p, struct nfs3_accessres *res) 1167 struct xdr_stream *xdr,
1168 const struct nfs_removeargs *args)
794{ 1169{
795 int status = ntohl(*p++); 1170 encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
1171}
796 1172
797 p = xdr_decode_post_op_attr(p, res->fattr); 1173/*
798 if (status) 1174 * 3.3.14 RENAME3args
799 return nfs_stat_to_errno(status); 1175 *
800 res->access = ntohl(*p++); 1176 * struct RENAME3args {
801 return 0; 1177 * diropargs3 from;
1178 * diropargs3 to;
1179 * };
1180 */
1181static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
1182 struct xdr_stream *xdr,
1183 const struct nfs_renameargs *args)
1184{
1185 const struct qstr *old = args->old_name;
1186 const struct qstr *new = args->new_name;
1187
1188 encode_diropargs3(xdr, args->old_dir, old->name, old->len);
1189 encode_diropargs3(xdr, args->new_dir, new->name, new->len);
802} 1190}
803 1191
804static int 1192/*
805nfs3_xdr_readlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs3_readlinkargs *args) 1193 * 3.3.15 LINK3args
1194 *
1195 * struct LINK3args {
1196 * nfs_fh3 file;
1197 * diropargs3 link;
1198 * };
1199 */
1200static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
1201 struct xdr_stream *xdr,
1202 const struct nfs3_linkargs *args)
806{ 1203{
807 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 1204 encode_nfs_fh3(xdr, args->fromfh);
808 unsigned int replen; 1205 encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
1206}
809 1207
810 p = xdr_encode_fhandle(p, args->fh); 1208/*
811 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 1209 * 3.3.16 READDIR3args
1210 *
1211 * struct READDIR3args {
1212 * nfs_fh3 dir;
1213 * cookie3 cookie;
1214 * cookieverf3 cookieverf;
1215 * count3 count;
1216 * };
1217 */
1218static void encode_readdir3args(struct xdr_stream *xdr,
1219 const struct nfs3_readdirargs *args)
1220{
1221 __be32 *p;
812 1222
813 /* Inline the page array */ 1223 encode_nfs_fh3(xdr, args->fh);
814 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS3_readlinkres_sz) << 2; 1224
815 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, args->pgbase, args->pglen); 1225 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
816 return 0; 1226 p = xdr_encode_cookie3(p, args->cookie);
1227 p = xdr_encode_cookieverf3(p, args->verf);
1228 *p = cpu_to_be32(args->count);
1229}
1230
1231static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
1232 struct xdr_stream *xdr,
1233 const struct nfs3_readdirargs *args)
1234{
1235 encode_readdir3args(xdr, args);
1236 prepare_reply_buffer(req, args->pages, 0,
1237 args->count, NFS3_readdirres_sz);
817} 1238}
818 1239
819/* 1240/*
820 * Decode READLINK reply 1241 * 3.3.17 READDIRPLUS3args
1242 *
1243 * struct READDIRPLUS3args {
1244 * nfs_fh3 dir;
1245 * cookie3 cookie;
1246 * cookieverf3 cookieverf;
1247 * count3 dircount;
1248 * count3 maxcount;
1249 * };
821 */ 1250 */
822static int 1251static void encode_readdirplus3args(struct xdr_stream *xdr,
823nfs3_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) 1252 const struct nfs3_readdirargs *args)
824{ 1253{
825 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 1254 __be32 *p;
826 struct kvec *iov = rcvbuf->head;
827 size_t hdrlen;
828 u32 len, recvd;
829 char *kaddr;
830 int status;
831 1255
832 status = ntohl(*p++); 1256 encode_nfs_fh3(xdr, args->fh);
833 p = xdr_decode_post_op_attr(p, fattr);
834 1257
835 if (status != 0) 1258 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
836 return nfs_stat_to_errno(status); 1259 p = xdr_encode_cookie3(p, args->cookie);
1260 p = xdr_encode_cookieverf3(p, args->verf);
837 1261
838 /* Convert length of symlink */ 1262 /*
839 len = ntohl(*p++); 1263 * readdirplus: need dircount + buffer size.
840 if (len >= rcvbuf->page_len) { 1264 * We just make sure we make dircount big enough
841 dprintk("nfs: server returned giant symlink!\n"); 1265 */
842 return -ENAMETOOLONG; 1266 *p++ = cpu_to_be32(args->count >> 3);
843 }
844 1267
845 hdrlen = (u8 *) p - (u8 *) iov->iov_base; 1268 *p = cpu_to_be32(args->count);
846 if (iov->iov_len < hdrlen) { 1269}
847 dprintk("NFS: READLINK reply header overflowed:"
848 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
849 return -errno_NFSERR_IO;
850 } else if (iov->iov_len != hdrlen) {
851 dprintk("NFS: READLINK header is short. "
852 "iovec will be shifted.\n");
853 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
854 }
855 recvd = req->rq_rcv_buf.len - hdrlen;
856 if (recvd < len) {
857 dprintk("NFS: server cheating in readlink reply: "
858 "count %u > recvd %u\n", len, recvd);
859 return -EIO;
860 }
861 1270
862 /* NULL terminate the string we got */ 1271static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
863 kaddr = (char*)kmap_atomic(rcvbuf->pages[0], KM_USER0); 1272 struct xdr_stream *xdr,
864 kaddr[len+rcvbuf->page_base] = '\0'; 1273 const struct nfs3_readdirargs *args)
865 kunmap_atomic(kaddr, KM_USER0); 1274{
866 return 0; 1275 encode_readdirplus3args(xdr, args);
1276 prepare_reply_buffer(req, args->pages, 0,
1277 args->count, NFS3_readdirres_sz);
867} 1278}
868 1279
869/* 1280/*
870 * Decode READ reply 1281 * 3.3.21 COMMIT3args
1282 *
1283 * struct COMMIT3args {
1284 * nfs_fh3 file;
1285 * offset3 offset;
1286 * count3 count;
1287 * };
871 */ 1288 */
872static int 1289static void encode_commit3args(struct xdr_stream *xdr,
873nfs3_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res) 1290 const struct nfs_writeargs *args)
874{ 1291{
875 struct kvec *iov = req->rq_rcv_buf.head; 1292 __be32 *p;
876 size_t hdrlen;
877 u32 count, ocount, recvd;
878 int status;
879 1293
880 status = ntohl(*p++); 1294 encode_nfs_fh3(xdr, args->fh);
881 p = xdr_decode_post_op_attr(p, res->fattr);
882 1295
883 if (status != 0) 1296 p = xdr_reserve_space(xdr, 8 + 4);
884 return nfs_stat_to_errno(status); 1297 p = xdr_encode_hyper(p, args->offset);
1298 *p = cpu_to_be32(args->count);
1299}
885 1300
886 /* Decode reply count and EOF flag. NFSv3 is somewhat redundant 1301static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
887 * in that it puts the count both in the res struct and in the 1302 struct xdr_stream *xdr,
888 * opaque data count. */ 1303 const struct nfs_writeargs *args)
889 count = ntohl(*p++); 1304{
890 res->eof = ntohl(*p++); 1305 encode_commit3args(xdr, args);
891 ocount = ntohl(*p++); 1306}
892 1307
893 if (ocount != count) { 1308#ifdef CONFIG_NFS_V3_ACL
894 dprintk("NFS: READ count doesn't match RPC opaque count.\n");
895 return -errno_NFSERR_IO;
896 }
897 1309
898 hdrlen = (u8 *) p - (u8 *) iov->iov_base; 1310static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
899 if (iov->iov_len < hdrlen) { 1311 struct xdr_stream *xdr,
900 dprintk("NFS: READ reply header overflowed:" 1312 const struct nfs3_getaclargs *args)
901 "length %Zu > %Zu\n", hdrlen, iov->iov_len); 1313{
902 return -errno_NFSERR_IO; 1314 encode_nfs_fh3(xdr, args->fh);
903 } else if (iov->iov_len != hdrlen) { 1315 encode_uint32(xdr, args->mask);
904 dprintk("NFS: READ header is short. iovec will be shifted.\n"); 1316 if (args->mask & (NFS_ACL | NFS_DFACL))
905 xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen); 1317 prepare_reply_buffer(req, args->pages, 0,
906 } 1318 NFSACL_MAXPAGES << PAGE_SHIFT,
1319 ACL3_getaclres_sz);
1320}
907 1321
908 recvd = req->rq_rcv_buf.len - hdrlen; 1322static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
909 if (count > recvd) { 1323 struct xdr_stream *xdr,
910 dprintk("NFS: server cheating in read reply: " 1324 const struct nfs3_setaclargs *args)
911 "count %u > recvd %u\n", count, recvd); 1325{
912 count = recvd; 1326 unsigned int base;
913 res->eof = 0; 1327 int error;
914 }
915 1328
916 if (count < res->count) 1329 encode_nfs_fh3(xdr, NFS_FH(args->inode));
917 res->count = count; 1330 encode_uint32(xdr, args->mask);
1331 if (args->npages != 0)
1332 xdr_write_pages(xdr, args->pages, 0, args->len);
918 1333
919 return count; 1334 base = req->rq_slen;
1335 error = nfsacl_encode(xdr->buf, base, args->inode,
1336 (args->mask & NFS_ACL) ?
1337 args->acl_access : NULL, 1, 0);
1338 BUG_ON(error < 0);
1339 error = nfsacl_encode(xdr->buf, base + error, args->inode,
1340 (args->mask & NFS_DFACL) ?
1341 args->acl_default : NULL, 1,
1342 NFS_ACL_DEFAULT);
1343 BUG_ON(error < 0);
920} 1344}
921 1345
1346#endif /* CONFIG_NFS_V3_ACL */
1347
922/* 1348/*
923 * Decode WRITE response 1349 * NFSv3 XDR decode functions
1350 *
1351 * NFSv3 result types are defined in section 3.3 of RFC 1813:
1352 * "NFS Version 3 Protocol Specification".
924 */ 1353 */
925static int
926nfs3_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
927{
928 int status;
929 1354
930 status = ntohl(*p++); 1355/*
931 p = xdr_decode_wcc_data(p, res->fattr); 1356 * 3.3.1 GETATTR3res
1357 *
1358 * struct GETATTR3resok {
1359 * fattr3 obj_attributes;
1360 * };
1361 *
1362 * union GETATTR3res switch (nfsstat3 status) {
1363 * case NFS3_OK:
1364 * GETATTR3resok resok;
1365 * default:
1366 * void;
1367 * };
1368 */
1369static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
1370 struct xdr_stream *xdr,
1371 struct nfs_fattr *result)
1372{
1373 enum nfs_stat status;
1374 int error;
1375
1376 error = decode_nfsstat3(xdr, &status);
1377 if (unlikely(error))
1378 goto out;
1379 if (status != NFS3_OK)
1380 goto out_default;
1381 error = decode_fattr3(xdr, result);
1382out:
1383 return error;
1384out_default:
1385 return nfs_stat_to_errno(status);
1386}
932 1387
933 if (status != 0) 1388/*
934 return nfs_stat_to_errno(status); 1389 * 3.3.2 SETATTR3res
1390 *
1391 * struct SETATTR3resok {
1392 * wcc_data obj_wcc;
1393 * };
1394 *
1395 * struct SETATTR3resfail {
1396 * wcc_data obj_wcc;
1397 * };
1398 *
1399 * union SETATTR3res switch (nfsstat3 status) {
1400 * case NFS3_OK:
1401 * SETATTR3resok resok;
1402 * default:
1403 * SETATTR3resfail resfail;
1404 * };
1405 */
1406static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
1407 struct xdr_stream *xdr,
1408 struct nfs_fattr *result)
1409{
1410 enum nfs_stat status;
1411 int error;
1412
1413 error = decode_nfsstat3(xdr, &status);
1414 if (unlikely(error))
1415 goto out;
1416 error = decode_wcc_data(xdr, result);
1417 if (unlikely(error))
1418 goto out;
1419 if (status != NFS3_OK)
1420 goto out_status;
1421out:
1422 return error;
1423out_status:
1424 return nfs_stat_to_errno(status);
1425}
935 1426
936 res->count = ntohl(*p++); 1427/*
937 res->verf->committed = (enum nfs3_stable_how)ntohl(*p++); 1428 * 3.3.3 LOOKUP3res
938 res->verf->verifier[0] = *p++; 1429 *
939 res->verf->verifier[1] = *p++; 1430 * struct LOOKUP3resok {
1431 * nfs_fh3 object;
1432 * post_op_attr obj_attributes;
1433 * post_op_attr dir_attributes;
1434 * };
1435 *
1436 * struct LOOKUP3resfail {
1437 * post_op_attr dir_attributes;
1438 * };
1439 *
1440 * union LOOKUP3res switch (nfsstat3 status) {
1441 * case NFS3_OK:
1442 * LOOKUP3resok resok;
1443 * default:
1444 * LOOKUP3resfail resfail;
1445 * };
1446 */
1447static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
1448 struct xdr_stream *xdr,
1449 struct nfs3_diropres *result)
1450{
1451 enum nfs_stat status;
1452 int error;
1453
1454 error = decode_nfsstat3(xdr, &status);
1455 if (unlikely(error))
1456 goto out;
1457 if (status != NFS3_OK)
1458 goto out_default;
1459 error = decode_nfs_fh3(xdr, result->fh);
1460 if (unlikely(error))
1461 goto out;
1462 error = decode_post_op_attr(xdr, result->fattr);
1463 if (unlikely(error))
1464 goto out;
1465 error = decode_post_op_attr(xdr, result->dir_attr);
1466out:
1467 return error;
1468out_default:
1469 error = decode_post_op_attr(xdr, result->dir_attr);
1470 if (unlikely(error))
1471 goto out;
1472 return nfs_stat_to_errno(status);
1473}
940 1474
941 return res->count; 1475/*
1476 * 3.3.4 ACCESS3res
1477 *
1478 * struct ACCESS3resok {
1479 * post_op_attr obj_attributes;
1480 * uint32 access;
1481 * };
1482 *
1483 * struct ACCESS3resfail {
1484 * post_op_attr obj_attributes;
1485 * };
1486 *
1487 * union ACCESS3res switch (nfsstat3 status) {
1488 * case NFS3_OK:
1489 * ACCESS3resok resok;
1490 * default:
1491 * ACCESS3resfail resfail;
1492 * };
1493 */
1494static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
1495 struct xdr_stream *xdr,
1496 struct nfs3_accessres *result)
1497{
1498 enum nfs_stat status;
1499 int error;
1500
1501 error = decode_nfsstat3(xdr, &status);
1502 if (unlikely(error))
1503 goto out;
1504 error = decode_post_op_attr(xdr, result->fattr);
1505 if (unlikely(error))
1506 goto out;
1507 if (status != NFS3_OK)
1508 goto out_default;
1509 error = decode_uint32(xdr, &result->access);
1510out:
1511 return error;
1512out_default:
1513 return nfs_stat_to_errno(status);
942} 1514}
943 1515
944/* 1516/*
945 * Decode a CREATE response 1517 * 3.3.5 READLINK3res
1518 *
1519 * struct READLINK3resok {
1520 * post_op_attr symlink_attributes;
1521 * nfspath3 data;
1522 * };
1523 *
1524 * struct READLINK3resfail {
1525 * post_op_attr symlink_attributes;
1526 * };
1527 *
1528 * union READLINK3res switch (nfsstat3 status) {
1529 * case NFS3_OK:
1530 * READLINK3resok resok;
1531 * default:
1532 * READLINK3resfail resfail;
1533 * };
946 */ 1534 */
947static int 1535static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
948nfs3_xdr_createres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res) 1536 struct xdr_stream *xdr,
949{ 1537 struct nfs_fattr *result)
950 int status; 1538{
951 1539 enum nfs_stat status;
952 status = ntohl(*p++); 1540 int error;
953 if (status == 0) { 1541
954 if (*p++) { 1542 error = decode_nfsstat3(xdr, &status);
955 if (!(p = xdr_decode_fhandle(p, res->fh))) 1543 if (unlikely(error))
956 return -errno_NFSERR_IO; 1544 goto out;
957 p = xdr_decode_post_op_attr(p, res->fattr); 1545 error = decode_post_op_attr(xdr, result);
958 } else { 1546 if (unlikely(error))
959 memset(res->fh, 0, sizeof(*res->fh)); 1547 goto out;
960 /* Do decode post_op_attr but set it to NULL */ 1548 if (status != NFS3_OK)
961 p = xdr_decode_post_op_attr(p, res->fattr); 1549 goto out_default;
962 res->fattr->valid = 0; 1550 error = decode_nfspath3(xdr);
963 } 1551out:
964 } else { 1552 return error;
965 status = nfs_stat_to_errno(status); 1553out_default:
966 } 1554 return nfs_stat_to_errno(status);
967 p = xdr_decode_wcc_data(p, res->dir_attr);
968 return status;
969} 1555}
970 1556
971/* 1557/*
972 * Decode RENAME reply 1558 * 3.3.6 READ3res
1559 *
1560 * struct READ3resok {
1561 * post_op_attr file_attributes;
1562 * count3 count;
1563 * bool eof;
1564 * opaque data<>;
1565 * };
1566 *
1567 * struct READ3resfail {
1568 * post_op_attr file_attributes;
1569 * };
1570 *
1571 * union READ3res switch (nfsstat3 status) {
1572 * case NFS3_OK:
1573 * READ3resok resok;
1574 * default:
1575 * READ3resfail resfail;
1576 * };
973 */ 1577 */
974static int 1578static int decode_read3resok(struct xdr_stream *xdr,
975nfs3_xdr_renameres(struct rpc_rqst *req, __be32 *p, struct nfs3_renameres *res) 1579 struct nfs_readres *result)
976{ 1580{
977 int status; 1581 u32 eof, count, ocount, recvd;
1582 size_t hdrlen;
1583 __be32 *p;
1584
1585 p = xdr_inline_decode(xdr, 4 + 4 + 4);
1586 if (unlikely(p == NULL))
1587 goto out_overflow;
1588 count = be32_to_cpup(p++);
1589 eof = be32_to_cpup(p++);
1590 ocount = be32_to_cpup(p++);
1591 if (unlikely(ocount != count))
1592 goto out_mismatch;
1593 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
1594 recvd = xdr->buf->len - hdrlen;
1595 if (unlikely(count > recvd))
1596 goto out_cheating;
1597
1598out:
1599 xdr_read_pages(xdr, count);
1600 result->eof = eof;
1601 result->count = count;
1602 return count;
1603out_mismatch:
1604 dprintk("NFS: READ count doesn't match length of opaque: "
1605 "count %u != ocount %u\n", count, ocount);
1606 return -EIO;
1607out_cheating:
1608 dprintk("NFS: server cheating in read result: "
1609 "count %u > recvd %u\n", count, recvd);
1610 count = recvd;
1611 eof = 0;
1612 goto out;
1613out_overflow:
1614 print_overflow_msg(__func__, xdr);
1615 return -EIO;
1616}
978 1617
979 if ((status = ntohl(*p++)) != 0) 1618static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
980 status = nfs_stat_to_errno(status); 1619 struct nfs_readres *result)
981 p = xdr_decode_wcc_data(p, res->fromattr); 1620{
982 p = xdr_decode_wcc_data(p, res->toattr); 1621 enum nfs_stat status;
983 return status; 1622 int error;
1623
1624 error = decode_nfsstat3(xdr, &status);
1625 if (unlikely(error))
1626 goto out;
1627 error = decode_post_op_attr(xdr, result->fattr);
1628 if (unlikely(error))
1629 goto out;
1630 if (status != NFS3_OK)
1631 goto out_status;
1632 error = decode_read3resok(xdr, result);
1633out:
1634 return error;
1635out_status:
1636 return nfs_stat_to_errno(status);
984} 1637}
985 1638
986/* 1639/*
987 * Decode LINK reply 1640 * 3.3.7 WRITE3res
1641 *
1642 * enum stable_how {
1643 * UNSTABLE = 0,
1644 * DATA_SYNC = 1,
1645 * FILE_SYNC = 2
1646 * };
1647 *
1648 * struct WRITE3resok {
1649 * wcc_data file_wcc;
1650 * count3 count;
1651 * stable_how committed;
1652 * writeverf3 verf;
1653 * };
1654 *
1655 * struct WRITE3resfail {
1656 * wcc_data file_wcc;
1657 * };
1658 *
1659 * union WRITE3res switch (nfsstat3 status) {
1660 * case NFS3_OK:
1661 * WRITE3resok resok;
1662 * default:
1663 * WRITE3resfail resfail;
1664 * };
988 */ 1665 */
989static int 1666static int decode_write3resok(struct xdr_stream *xdr,
990nfs3_xdr_linkres(struct rpc_rqst *req, __be32 *p, struct nfs3_linkres *res) 1667 struct nfs_writeres *result)
991{ 1668{
992 int status; 1669 __be32 *p;
1670
1671 p = xdr_inline_decode(xdr, 4 + 4 + NFS3_WRITEVERFSIZE);
1672 if (unlikely(p == NULL))
1673 goto out_overflow;
1674 result->count = be32_to_cpup(p++);
1675 result->verf->committed = be32_to_cpup(p++);
1676 if (unlikely(result->verf->committed > NFS_FILE_SYNC))
1677 goto out_badvalue;
1678 memcpy(result->verf->verifier, p, NFS3_WRITEVERFSIZE);
1679 return result->count;
1680out_badvalue:
1681 dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
1682 return -EIO;
1683out_overflow:
1684 print_overflow_msg(__func__, xdr);
1685 return -EIO;
1686}
993 1687
994 if ((status = ntohl(*p++)) != 0) 1688static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
995 status = nfs_stat_to_errno(status); 1689 struct nfs_writeres *result)
996 p = xdr_decode_post_op_attr(p, res->fattr); 1690{
997 p = xdr_decode_wcc_data(p, res->dir_attr); 1691 enum nfs_stat status;
998 return status; 1692 int error;
1693
1694 error = decode_nfsstat3(xdr, &status);
1695 if (unlikely(error))
1696 goto out;
1697 error = decode_wcc_data(xdr, result->fattr);
1698 if (unlikely(error))
1699 goto out;
1700 if (status != NFS3_OK)
1701 goto out_status;
1702 error = decode_write3resok(xdr, result);
1703out:
1704 return error;
1705out_status:
1706 return nfs_stat_to_errno(status);
999} 1707}
1000 1708
1001/* 1709/*
1002 * Decode FSSTAT reply 1710 * 3.3.8 CREATE3res
1711 *
1712 * struct CREATE3resok {
1713 * post_op_fh3 obj;
1714 * post_op_attr obj_attributes;
1715 * wcc_data dir_wcc;
1716 * };
1717 *
1718 * struct CREATE3resfail {
1719 * wcc_data dir_wcc;
1720 * };
1721 *
1722 * union CREATE3res switch (nfsstat3 status) {
1723 * case NFS3_OK:
1724 * CREATE3resok resok;
1725 * default:
1726 * CREATE3resfail resfail;
1727 * };
1003 */ 1728 */
1004static int 1729static int decode_create3resok(struct xdr_stream *xdr,
1005nfs3_xdr_fsstatres(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *res) 1730 struct nfs3_diropres *result)
1006{ 1731{
1007 int status; 1732 int error;
1008 1733
1009 status = ntohl(*p++); 1734 error = decode_post_op_fh3(xdr, result->fh);
1735 if (unlikely(error))
1736 goto out;
1737 error = decode_post_op_attr(xdr, result->fattr);
1738 if (unlikely(error))
1739 goto out;
1740 /* The server isn't required to return a file handle.
1741 * If it didn't, force the client to perform a LOOKUP
1742 * to determine the correct file handle and attribute
1743 * values for the new object. */
1744 if (result->fh->size == 0)
1745 result->fattr->valid = 0;
1746 error = decode_wcc_data(xdr, result->dir_attr);
1747out:
1748 return error;
1749}
1010 1750
1011 p = xdr_decode_post_op_attr(p, res->fattr); 1751static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
1012 if (status != 0) 1752 struct xdr_stream *xdr,
1013 return nfs_stat_to_errno(status); 1753 struct nfs3_diropres *result)
1754{
1755 enum nfs_stat status;
1756 int error;
1757
1758 error = decode_nfsstat3(xdr, &status);
1759 if (unlikely(error))
1760 goto out;
1761 if (status != NFS3_OK)
1762 goto out_default;
1763 error = decode_create3resok(xdr, result);
1764out:
1765 return error;
1766out_default:
1767 error = decode_wcc_data(xdr, result->dir_attr);
1768 if (unlikely(error))
1769 goto out;
1770 return nfs_stat_to_errno(status);
1771}
1014 1772
1015 p = xdr_decode_hyper(p, &res->tbytes); 1773/*
1016 p = xdr_decode_hyper(p, &res->fbytes); 1774 * 3.3.12 REMOVE3res
1017 p = xdr_decode_hyper(p, &res->abytes); 1775 *
1018 p = xdr_decode_hyper(p, &res->tfiles); 1776 * struct REMOVE3resok {
1019 p = xdr_decode_hyper(p, &res->ffiles); 1777 * wcc_data dir_wcc;
1020 p = xdr_decode_hyper(p, &res->afiles); 1778 * };
1779 *
1780 * struct REMOVE3resfail {
1781 * wcc_data dir_wcc;
1782 * };
1783 *
1784 * union REMOVE3res switch (nfsstat3 status) {
1785 * case NFS3_OK:
1786 * REMOVE3resok resok;
1787 * default:
1788 * REMOVE3resfail resfail;
1789 * };
1790 */
1791static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
1792 struct xdr_stream *xdr,
1793 struct nfs_removeres *result)
1794{
1795 enum nfs_stat status;
1796 int error;
1797
1798 error = decode_nfsstat3(xdr, &status);
1799 if (unlikely(error))
1800 goto out;
1801 error = decode_wcc_data(xdr, result->dir_attr);
1802 if (unlikely(error))
1803 goto out;
1804 if (status != NFS3_OK)
1805 goto out_status;
1806out:
1807 return error;
1808out_status:
1809 return nfs_stat_to_errno(status);
1810}
1021 1811
1022 /* ignore invarsec */ 1812/*
1023 return 0; 1813 * 3.3.14 RENAME3res
1814 *
1815 * struct RENAME3resok {
1816 * wcc_data fromdir_wcc;
1817 * wcc_data todir_wcc;
1818 * };
1819 *
1820 * struct RENAME3resfail {
1821 * wcc_data fromdir_wcc;
1822 * wcc_data todir_wcc;
1823 * };
1824 *
1825 * union RENAME3res switch (nfsstat3 status) {
1826 * case NFS3_OK:
1827 * RENAME3resok resok;
1828 * default:
1829 * RENAME3resfail resfail;
1830 * };
1831 */
1832static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
1833 struct xdr_stream *xdr,
1834 struct nfs_renameres *result)
1835{
1836 enum nfs_stat status;
1837 int error;
1838
1839 error = decode_nfsstat3(xdr, &status);
1840 if (unlikely(error))
1841 goto out;
1842 error = decode_wcc_data(xdr, result->old_fattr);
1843 if (unlikely(error))
1844 goto out;
1845 error = decode_wcc_data(xdr, result->new_fattr);
1846 if (unlikely(error))
1847 goto out;
1848 if (status != NFS3_OK)
1849 goto out_status;
1850out:
1851 return error;
1852out_status:
1853 return nfs_stat_to_errno(status);
1024} 1854}
1025 1855
1026/* 1856/*
1027 * Decode FSINFO reply 1857 * 3.3.15 LINK3res
1858 *
1859 * struct LINK3resok {
1860 * post_op_attr file_attributes;
1861 * wcc_data linkdir_wcc;
1862 * };
1863 *
1864 * struct LINK3resfail {
1865 * post_op_attr file_attributes;
1866 * wcc_data linkdir_wcc;
1867 * };
1868 *
1869 * union LINK3res switch (nfsstat3 status) {
1870 * case NFS3_OK:
1871 * LINK3resok resok;
1872 * default:
1873 * LINK3resfail resfail;
1874 * };
1028 */ 1875 */
1029static int 1876static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1030nfs3_xdr_fsinfores(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *res) 1877 struct nfs3_linkres *result)
1031{ 1878{
1032 int status; 1879 enum nfs_stat status;
1880 int error;
1881
1882 error = decode_nfsstat3(xdr, &status);
1883 if (unlikely(error))
1884 goto out;
1885 error = decode_post_op_attr(xdr, result->fattr);
1886 if (unlikely(error))
1887 goto out;
1888 error = decode_wcc_data(xdr, result->dir_attr);
1889 if (unlikely(error))
1890 goto out;
1891 if (status != NFS3_OK)
1892 goto out_status;
1893out:
1894 return error;
1895out_status:
1896 return nfs_stat_to_errno(status);
1897}
1033 1898
1034 status = ntohl(*p++); 1899/**
1900 * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
1901 * the local page cache
1902 * @xdr: XDR stream where entry resides
1903 * @entry: buffer to fill in with entry data
1904 * @plus: boolean indicating whether this should be a readdirplus entry
1905 *
1906 * Returns zero if successful, otherwise a negative errno value is
1907 * returned.
1908 *
1909 * This function is not invoked during READDIR reply decoding, but
1910 * rather whenever an application invokes the getdents(2) system call
1911 * on a directory already in our cache.
1912 *
1913 * 3.3.16 entry3
1914 *
1915 * struct entry3 {
1916 * fileid3 fileid;
1917 * filename3 name;
1918 * cookie3 cookie;
1919 * fhandle3 filehandle;
1920 * post_op_attr3 attributes;
1921 * entry3 *nextentry;
1922 * };
1923 *
1924 * 3.3.17 entryplus3
1925 * struct entryplus3 {
1926 * fileid3 fileid;
1927 * filename3 name;
1928 * cookie3 cookie;
1929 * post_op_attr name_attributes;
1930 * post_op_fh3 name_handle;
1931 * entryplus3 *nextentry;
1932 * };
1933 */
1934int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
1935 int plus)
1936{
1937 struct nfs_entry old = *entry;
1938 __be32 *p;
1939 int error;
1940
1941 p = xdr_inline_decode(xdr, 4);
1942 if (unlikely(p == NULL))
1943 goto out_overflow;
1944 if (*p == xdr_zero) {
1945 p = xdr_inline_decode(xdr, 4);
1946 if (unlikely(p == NULL))
1947 goto out_overflow;
1948 if (*p == xdr_zero)
1949 return -EAGAIN;
1950 entry->eof = 1;
1951 return -EBADCOOKIE;
1952 }
1953
1954 error = decode_fileid3(xdr, &entry->ino);
1955 if (unlikely(error))
1956 return error;
1957
1958 error = decode_inline_filename3(xdr, &entry->name, &entry->len);
1959 if (unlikely(error))
1960 return error;
1035 1961
1036 p = xdr_decode_post_op_attr(p, res->fattr); 1962 entry->prev_cookie = entry->cookie;
1037 if (status != 0) 1963 error = decode_cookie3(xdr, &entry->cookie);
1038 return nfs_stat_to_errno(status); 1964 if (unlikely(error))
1965 return error;
1966
1967 entry->d_type = DT_UNKNOWN;
1039 1968
1040 res->rtmax = ntohl(*p++); 1969 if (plus) {
1041 res->rtpref = ntohl(*p++); 1970 entry->fattr->valid = 0;
1042 res->rtmult = ntohl(*p++); 1971 error = decode_post_op_attr(xdr, entry->fattr);
1043 res->wtmax = ntohl(*p++); 1972 if (unlikely(error))
1044 res->wtpref = ntohl(*p++); 1973 return error;
1045 res->wtmult = ntohl(*p++); 1974 if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
1046 res->dtpref = ntohl(*p++); 1975 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
1047 p = xdr_decode_hyper(p, &res->maxfilesize); 1976
1977 /* In fact, a post_op_fh3: */
1978 p = xdr_inline_decode(xdr, 4);
1979 if (unlikely(p == NULL))
1980 goto out_overflow;
1981 if (*p != xdr_zero) {
1982 error = decode_nfs_fh3(xdr, entry->fh);
1983 if (unlikely(error)) {
1984 if (error == -E2BIG)
1985 goto out_truncated;
1986 return error;
1987 }
1988 } else
1989 zero_nfs_fh3(entry->fh);
1990 }
1048 1991
1049 /* ignore time_delta and properties */
1050 res->lease_time = 0;
1051 return 0; 1992 return 0;
1993
1994out_overflow:
1995 print_overflow_msg(__func__, xdr);
1996 return -EAGAIN;
1997out_truncated:
1998 dprintk("NFS: directory entry contains invalid file handle\n");
1999 *entry = old;
2000 return -EAGAIN;
1052} 2001}
1053 2002
1054/* 2003/*
1055 * Decode PATHCONF reply 2004 * 3.3.16 READDIR3res
2005 *
2006 * struct dirlist3 {
2007 * entry3 *entries;
2008 * bool eof;
2009 * };
2010 *
2011 * struct READDIR3resok {
2012 * post_op_attr dir_attributes;
2013 * cookieverf3 cookieverf;
2014 * dirlist3 reply;
2015 * };
2016 *
2017 * struct READDIR3resfail {
2018 * post_op_attr dir_attributes;
2019 * };
2020 *
2021 * union READDIR3res switch (nfsstat3 status) {
2022 * case NFS3_OK:
2023 * READDIR3resok resok;
2024 * default:
2025 * READDIR3resfail resfail;
2026 * };
2027 *
2028 * Read the directory contents into the page cache, but otherwise
2029 * don't touch them. The actual decoding is done by nfs3_decode_entry()
2030 * during subsequent nfs_readdir() calls.
1056 */ 2031 */
1057static int 2032static int decode_dirlist3(struct xdr_stream *xdr)
1058nfs3_xdr_pathconfres(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *res)
1059{ 2033{
1060 int status; 2034 u32 recvd, pglen;
2035 size_t hdrlen;
1061 2036
1062 status = ntohl(*p++); 2037 pglen = xdr->buf->page_len;
2038 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
2039 recvd = xdr->buf->len - hdrlen;
2040 if (unlikely(pglen > recvd))
2041 goto out_cheating;
2042out:
2043 xdr_read_pages(xdr, pglen);
2044 return pglen;
2045out_cheating:
2046 dprintk("NFS: server cheating in readdir result: "
2047 "pglen %u > recvd %u\n", pglen, recvd);
2048 pglen = recvd;
2049 goto out;
2050}
1063 2051
1064 p = xdr_decode_post_op_attr(p, res->fattr); 2052static int decode_readdir3resok(struct xdr_stream *xdr,
1065 if (status != 0) 2053 struct nfs3_readdirres *result)
1066 return nfs_stat_to_errno(status); 2054{
1067 res->max_link = ntohl(*p++); 2055 int error;
1068 res->max_namelen = ntohl(*p++); 2056
2057 error = decode_post_op_attr(xdr, result->dir_attr);
2058 if (unlikely(error))
2059 goto out;
2060 /* XXX: do we need to check if result->verf != NULL ? */
2061 error = decode_cookieverf3(xdr, result->verf);
2062 if (unlikely(error))
2063 goto out;
2064 error = decode_dirlist3(xdr);
2065out:
2066 return error;
2067}
1069 2068
1070 /* ignore remaining fields */ 2069static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
1071 return 0; 2070 struct xdr_stream *xdr,
2071 struct nfs3_readdirres *result)
2072{
2073 enum nfs_stat status;
2074 int error;
2075
2076 error = decode_nfsstat3(xdr, &status);
2077 if (unlikely(error))
2078 goto out;
2079 if (status != NFS3_OK)
2080 goto out_default;
2081 error = decode_readdir3resok(xdr, result);
2082out:
2083 return error;
2084out_default:
2085 error = decode_post_op_attr(xdr, result->dir_attr);
2086 if (unlikely(error))
2087 goto out;
2088 return nfs_stat_to_errno(status);
1072} 2089}
1073 2090
1074/* 2091/*
1075 * Decode COMMIT reply 2092 * 3.3.18 FSSTAT3res
2093 *
2094 * struct FSSTAT3resok {
2095 * post_op_attr obj_attributes;
2096 * size3 tbytes;
2097 * size3 fbytes;
2098 * size3 abytes;
2099 * size3 tfiles;
2100 * size3 ffiles;
2101 * size3 afiles;
2102 * uint32 invarsec;
2103 * };
2104 *
2105 * struct FSSTAT3resfail {
2106 * post_op_attr obj_attributes;
2107 * };
2108 *
2109 * union FSSTAT3res switch (nfsstat3 status) {
2110 * case NFS3_OK:
2111 * FSSTAT3resok resok;
2112 * default:
2113 * FSSTAT3resfail resfail;
2114 * };
1076 */ 2115 */
1077static int 2116static int decode_fsstat3resok(struct xdr_stream *xdr,
1078nfs3_xdr_commitres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res) 2117 struct nfs_fsstat *result)
1079{ 2118{
1080 int status; 2119 __be32 *p;
2120
2121 p = xdr_inline_decode(xdr, 8 * 6 + 4);
2122 if (unlikely(p == NULL))
2123 goto out_overflow;
2124 p = xdr_decode_size3(p, &result->tbytes);
2125 p = xdr_decode_size3(p, &result->fbytes);
2126 p = xdr_decode_size3(p, &result->abytes);
2127 p = xdr_decode_size3(p, &result->tfiles);
2128 p = xdr_decode_size3(p, &result->ffiles);
2129 xdr_decode_size3(p, &result->afiles);
2130 /* ignore invarsec */
2131 return 0;
2132out_overflow:
2133 print_overflow_msg(__func__, xdr);
2134 return -EIO;
2135}
1081 2136
1082 status = ntohl(*p++); 2137static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
1083 p = xdr_decode_wcc_data(p, res->fattr); 2138 struct xdr_stream *xdr,
1084 if (status != 0) 2139 struct nfs_fsstat *result)
1085 return nfs_stat_to_errno(status); 2140{
2141 enum nfs_stat status;
2142 int error;
2143
2144 error = decode_nfsstat3(xdr, &status);
2145 if (unlikely(error))
2146 goto out;
2147 error = decode_post_op_attr(xdr, result->fattr);
2148 if (unlikely(error))
2149 goto out;
2150 if (status != NFS3_OK)
2151 goto out_status;
2152 error = decode_fsstat3resok(xdr, result);
2153out:
2154 return error;
2155out_status:
2156 return nfs_stat_to_errno(status);
2157}
1086 2158
1087 res->verf->verifier[0] = *p++; 2159/*
1088 res->verf->verifier[1] = *p++; 2160 * 3.3.19 FSINFO3res
2161 *
2162 * struct FSINFO3resok {
2163 * post_op_attr obj_attributes;
2164 * uint32 rtmax;
2165 * uint32 rtpref;
2166 * uint32 rtmult;
2167 * uint32 wtmax;
2168 * uint32 wtpref;
2169 * uint32 wtmult;
2170 * uint32 dtpref;
2171 * size3 maxfilesize;
2172 * nfstime3 time_delta;
2173 * uint32 properties;
2174 * };
2175 *
2176 * struct FSINFO3resfail {
2177 * post_op_attr obj_attributes;
2178 * };
2179 *
2180 * union FSINFO3res switch (nfsstat3 status) {
2181 * case NFS3_OK:
2182 * FSINFO3resok resok;
2183 * default:
2184 * FSINFO3resfail resfail;
2185 * };
2186 */
2187static int decode_fsinfo3resok(struct xdr_stream *xdr,
2188 struct nfs_fsinfo *result)
2189{
2190 __be32 *p;
2191
2192 p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
2193 if (unlikely(p == NULL))
2194 goto out_overflow;
2195 result->rtmax = be32_to_cpup(p++);
2196 result->rtpref = be32_to_cpup(p++);
2197 result->rtmult = be32_to_cpup(p++);
2198 result->wtmax = be32_to_cpup(p++);
2199 result->wtpref = be32_to_cpup(p++);
2200 result->wtmult = be32_to_cpup(p++);
2201 result->dtpref = be32_to_cpup(p++);
2202 p = xdr_decode_size3(p, &result->maxfilesize);
2203 xdr_decode_nfstime3(p, &result->time_delta);
2204
2205 /* ignore properties */
2206 result->lease_time = 0;
1089 return 0; 2207 return 0;
2208out_overflow:
2209 print_overflow_msg(__func__, xdr);
2210 return -EIO;
2211}
2212
2213static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
2214 struct xdr_stream *xdr,
2215 struct nfs_fsinfo *result)
2216{
2217 enum nfs_stat status;
2218 int error;
2219
2220 error = decode_nfsstat3(xdr, &status);
2221 if (unlikely(error))
2222 goto out;
2223 error = decode_post_op_attr(xdr, result->fattr);
2224 if (unlikely(error))
2225 goto out;
2226 if (status != NFS3_OK)
2227 goto out_status;
2228 error = decode_fsinfo3resok(xdr, result);
2229out:
2230 return error;
2231out_status:
2232 return nfs_stat_to_errno(status);
1090} 2233}
1091 2234
1092#ifdef CONFIG_NFS_V3_ACL
1093/* 2235/*
1094 * Decode GETACL reply 2236 * 3.3.20 PATHCONF3res
2237 *
2238 * struct PATHCONF3resok {
2239 * post_op_attr obj_attributes;
2240 * uint32 linkmax;
2241 * uint32 name_max;
2242 * bool no_trunc;
2243 * bool chown_restricted;
2244 * bool case_insensitive;
2245 * bool case_preserving;
2246 * };
2247 *
2248 * struct PATHCONF3resfail {
2249 * post_op_attr obj_attributes;
2250 * };
2251 *
2252 * union PATHCONF3res switch (nfsstat3 status) {
2253 * case NFS3_OK:
2254 * PATHCONF3resok resok;
2255 * default:
2256 * PATHCONF3resfail resfail;
2257 * };
1095 */ 2258 */
1096static int 2259static int decode_pathconf3resok(struct xdr_stream *xdr,
1097nfs3_xdr_getaclres(struct rpc_rqst *req, __be32 *p, 2260 struct nfs_pathconf *result)
1098 struct nfs3_getaclres *res)
1099{ 2261{
1100 struct xdr_buf *buf = &req->rq_rcv_buf; 2262 __be32 *p;
1101 int status = ntohl(*p++);
1102 struct posix_acl **acl;
1103 unsigned int *aclcnt;
1104 int err, base;
1105
1106 if (status != 0)
1107 return nfs_stat_to_errno(status);
1108 p = xdr_decode_post_op_attr(p, res->fattr);
1109 res->mask = ntohl(*p++);
1110 if (res->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
1111 return -EINVAL;
1112 base = (char *)p - (char *)req->rq_rcv_buf.head->iov_base;
1113 2263
1114 acl = (res->mask & NFS_ACL) ? &res->acl_access : NULL; 2264 p = xdr_inline_decode(xdr, 4 * 6);
1115 aclcnt = (res->mask & NFS_ACLCNT) ? &res->acl_access_count : NULL; 2265 if (unlikely(p == NULL))
1116 err = nfsacl_decode(buf, base, aclcnt, acl); 2266 goto out_overflow;
2267 result->max_link = be32_to_cpup(p++);
2268 result->max_namelen = be32_to_cpup(p);
2269 /* ignore remaining fields */
2270 return 0;
2271out_overflow:
2272 print_overflow_msg(__func__, xdr);
2273 return -EIO;
2274}
1117 2275
1118 acl = (res->mask & NFS_DFACL) ? &res->acl_default : NULL; 2276static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
1119 aclcnt = (res->mask & NFS_DFACLCNT) ? &res->acl_default_count : NULL; 2277 struct xdr_stream *xdr,
1120 if (err > 0) 2278 struct nfs_pathconf *result)
1121 err = nfsacl_decode(buf, base + err, aclcnt, acl); 2279{
1122 return (err > 0) ? 0 : err; 2280 enum nfs_stat status;
2281 int error;
2282
2283 error = decode_nfsstat3(xdr, &status);
2284 if (unlikely(error))
2285 goto out;
2286 error = decode_post_op_attr(xdr, result->fattr);
2287 if (unlikely(error))
2288 goto out;
2289 if (status != NFS3_OK)
2290 goto out_status;
2291 error = decode_pathconf3resok(xdr, result);
2292out:
2293 return error;
2294out_status:
2295 return nfs_stat_to_errno(status);
1123} 2296}
1124 2297
1125/* 2298/*
1126 * Decode setacl reply. 2299 * 3.3.21 COMMIT3res
2300 *
2301 * struct COMMIT3resok {
2302 * wcc_data file_wcc;
2303 * writeverf3 verf;
2304 * };
2305 *
2306 * struct COMMIT3resfail {
2307 * wcc_data file_wcc;
2308 * };
2309 *
2310 * union COMMIT3res switch (nfsstat3 status) {
2311 * case NFS3_OK:
2312 * COMMIT3resok resok;
2313 * default:
2314 * COMMIT3resfail resfail;
2315 * };
1127 */ 2316 */
1128static int 2317static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
1129nfs3_xdr_setaclres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) 2318 struct xdr_stream *xdr,
2319 struct nfs_writeres *result)
1130{ 2320{
1131 int status = ntohl(*p++); 2321 enum nfs_stat status;
2322 int error;
2323
2324 error = decode_nfsstat3(xdr, &status);
2325 if (unlikely(error))
2326 goto out;
2327 error = decode_wcc_data(xdr, result->fattr);
2328 if (unlikely(error))
2329 goto out;
2330 if (status != NFS3_OK)
2331 goto out_status;
2332 error = decode_writeverf3(xdr, result->verf->verifier);
2333out:
2334 return error;
2335out_status:
2336 return nfs_stat_to_errno(status);
2337}
1132 2338
1133 if (status) 2339#ifdef CONFIG_NFS_V3_ACL
1134 return nfs_stat_to_errno(status); 2340
1135 xdr_decode_post_op_attr(p, fattr); 2341static inline int decode_getacl3resok(struct xdr_stream *xdr,
1136 return 0; 2342 struct nfs3_getaclres *result)
2343{
2344 struct posix_acl **acl;
2345 unsigned int *aclcnt;
2346 size_t hdrlen;
2347 int error;
2348
2349 error = decode_post_op_attr(xdr, result->fattr);
2350 if (unlikely(error))
2351 goto out;
2352 error = decode_uint32(xdr, &result->mask);
2353 if (unlikely(error))
2354 goto out;
2355 error = -EINVAL;
2356 if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
2357 goto out;
2358
2359 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
2360
2361 acl = NULL;
2362 if (result->mask & NFS_ACL)
2363 acl = &result->acl_access;
2364 aclcnt = NULL;
2365 if (result->mask & NFS_ACLCNT)
2366 aclcnt = &result->acl_access_count;
2367 error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
2368 if (unlikely(error <= 0))
2369 goto out;
2370
2371 acl = NULL;
2372 if (result->mask & NFS_DFACL)
2373 acl = &result->acl_default;
2374 aclcnt = NULL;
2375 if (result->mask & NFS_DFACLCNT)
2376 aclcnt = &result->acl_default_count;
2377 error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
2378 if (unlikely(error <= 0))
2379 return error;
2380 error = 0;
2381out:
2382 return error;
2383}
2384
2385static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
2386 struct xdr_stream *xdr,
2387 struct nfs3_getaclres *result)
2388{
2389 enum nfs_stat status;
2390 int error;
2391
2392 error = decode_nfsstat3(xdr, &status);
2393 if (unlikely(error))
2394 goto out;
2395 if (status != NFS3_OK)
2396 goto out_default;
2397 error = decode_getacl3resok(xdr, result);
2398out:
2399 return error;
2400out_default:
2401 return nfs_stat_to_errno(status);
1137} 2402}
2403
2404static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
2405 struct xdr_stream *xdr,
2406 struct nfs_fattr *result)
2407{
2408 enum nfs_stat status;
2409 int error;
2410
2411 error = decode_nfsstat3(xdr, &status);
2412 if (unlikely(error))
2413 goto out;
2414 if (status != NFS3_OK)
2415 goto out_default;
2416 error = decode_post_op_attr(xdr, result);
2417out:
2418 return error;
2419out_default:
2420 return nfs_stat_to_errno(status);
2421}
2422
1138#endif /* CONFIG_NFS_V3_ACL */ 2423#endif /* CONFIG_NFS_V3_ACL */
1139 2424
1140#define PROC(proc, argtype, restype, timer) \ 2425#define PROC(proc, argtype, restype, timer) \
1141[NFS3PROC_##proc] = { \ 2426[NFS3PROC_##proc] = { \
1142 .p_proc = NFS3PROC_##proc, \ 2427 .p_proc = NFS3PROC_##proc, \
1143 .p_encode = (kxdrproc_t) nfs3_xdr_##argtype, \ 2428 .p_encode = (kxdreproc_t)nfs3_xdr_enc_##argtype##3args, \
1144 .p_decode = (kxdrproc_t) nfs3_xdr_##restype, \ 2429 .p_decode = (kxdrdproc_t)nfs3_xdr_dec_##restype##3res, \
1145 .p_arglen = NFS3_##argtype##_sz, \ 2430 .p_arglen = NFS3_##argtype##args_sz, \
1146 .p_replen = NFS3_##restype##_sz, \ 2431 .p_replen = NFS3_##restype##res_sz, \
1147 .p_timer = timer, \ 2432 .p_timer = timer, \
1148 .p_statidx = NFS3PROC_##proc, \ 2433 .p_statidx = NFS3PROC_##proc, \
1149 .p_name = #proc, \ 2434 .p_name = #proc, \
1150 } 2435 }
1151 2436
1152struct rpc_procinfo nfs3_procedures[] = { 2437struct rpc_procinfo nfs3_procedures[] = {
1153 PROC(GETATTR, fhandle, attrstat, 1), 2438 PROC(GETATTR, getattr, getattr, 1),
1154 PROC(SETATTR, sattrargs, wccstat, 0), 2439 PROC(SETATTR, setattr, setattr, 0),
1155 PROC(LOOKUP, diropargs, lookupres, 2), 2440 PROC(LOOKUP, lookup, lookup, 2),
1156 PROC(ACCESS, accessargs, accessres, 1), 2441 PROC(ACCESS, access, access, 1),
1157 PROC(READLINK, readlinkargs, readlinkres, 3), 2442 PROC(READLINK, readlink, readlink, 3),
1158 PROC(READ, readargs, readres, 3), 2443 PROC(READ, read, read, 3),
1159 PROC(WRITE, writeargs, writeres, 4), 2444 PROC(WRITE, write, write, 4),
1160 PROC(CREATE, createargs, createres, 0), 2445 PROC(CREATE, create, create, 0),
1161 PROC(MKDIR, mkdirargs, createres, 0), 2446 PROC(MKDIR, mkdir, create, 0),
1162 PROC(SYMLINK, symlinkargs, createres, 0), 2447 PROC(SYMLINK, symlink, create, 0),
1163 PROC(MKNOD, mknodargs, createres, 0), 2448 PROC(MKNOD, mknod, create, 0),
1164 PROC(REMOVE, removeargs, removeres, 0), 2449 PROC(REMOVE, remove, remove, 0),
1165 PROC(RMDIR, diropargs, wccstat, 0), 2450 PROC(RMDIR, lookup, setattr, 0),
1166 PROC(RENAME, renameargs, renameres, 0), 2451 PROC(RENAME, rename, rename, 0),
1167 PROC(LINK, linkargs, linkres, 0), 2452 PROC(LINK, link, link, 0),
1168 PROC(READDIR, readdirargs, readdirres, 3), 2453 PROC(READDIR, readdir, readdir, 3),
1169 PROC(READDIRPLUS, readdirargs, readdirres, 3), 2454 PROC(READDIRPLUS, readdirplus, readdir, 3),
1170 PROC(FSSTAT, fhandle, fsstatres, 0), 2455 PROC(FSSTAT, getattr, fsstat, 0),
1171 PROC(FSINFO, fhandle, fsinfores, 0), 2456 PROC(FSINFO, getattr, fsinfo, 0),
1172 PROC(PATHCONF, fhandle, pathconfres, 0), 2457 PROC(PATHCONF, getattr, pathconf, 0),
1173 PROC(COMMIT, commitargs, commitres, 5), 2458 PROC(COMMIT, commit, commit, 5),
1174}; 2459};
1175 2460
1176struct rpc_version nfs_version3 = { 2461struct rpc_version nfs_version3 = {
@@ -1183,8 +2468,8 @@ struct rpc_version nfs_version3 = {
1183static struct rpc_procinfo nfs3_acl_procedures[] = { 2468static struct rpc_procinfo nfs3_acl_procedures[] = {
1184 [ACLPROC3_GETACL] = { 2469 [ACLPROC3_GETACL] = {
1185 .p_proc = ACLPROC3_GETACL, 2470 .p_proc = ACLPROC3_GETACL,
1186 .p_encode = (kxdrproc_t) nfs3_xdr_getaclargs, 2471 .p_encode = (kxdreproc_t)nfs3_xdr_enc_getacl3args,
1187 .p_decode = (kxdrproc_t) nfs3_xdr_getaclres, 2472 .p_decode = (kxdrdproc_t)nfs3_xdr_dec_getacl3res,
1188 .p_arglen = ACL3_getaclargs_sz, 2473 .p_arglen = ACL3_getaclargs_sz,
1189 .p_replen = ACL3_getaclres_sz, 2474 .p_replen = ACL3_getaclres_sz,
1190 .p_timer = 1, 2475 .p_timer = 1,
@@ -1192,8 +2477,8 @@ static struct rpc_procinfo nfs3_acl_procedures[] = {
1192 }, 2477 },
1193 [ACLPROC3_SETACL] = { 2478 [ACLPROC3_SETACL] = {
1194 .p_proc = ACLPROC3_SETACL, 2479 .p_proc = ACLPROC3_SETACL,
1195 .p_encode = (kxdrproc_t) nfs3_xdr_setaclargs, 2480 .p_encode = (kxdreproc_t)nfs3_xdr_enc_setacl3args,
1196 .p_decode = (kxdrproc_t) nfs3_xdr_setaclres, 2481 .p_decode = (kxdrdproc_t)nfs3_xdr_dec_setacl3res,
1197 .p_arglen = ACL3_setaclargs_sz, 2482 .p_arglen = ACL3_setaclargs_sz,
1198 .p_replen = ACL3_setaclres_sz, 2483 .p_replen = ACL3_setaclres_sz,
1199 .p_timer = 0, 2484 .p_timer = 0,
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 61bc3a32e1e2..7a7474073148 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -44,7 +44,29 @@ enum nfs4_client_state {
44 NFS4CLNT_RECLAIM_REBOOT, 44 NFS4CLNT_RECLAIM_REBOOT,
45 NFS4CLNT_RECLAIM_NOGRACE, 45 NFS4CLNT_RECLAIM_NOGRACE,
46 NFS4CLNT_DELEGRETURN, 46 NFS4CLNT_DELEGRETURN,
47 NFS4CLNT_SESSION_SETUP, 47 NFS4CLNT_LAYOUTRECALL,
48 NFS4CLNT_SESSION_RESET,
49 NFS4CLNT_RECALL_SLOT,
50};
51
52enum nfs4_session_state {
53 NFS4_SESSION_INITING,
54 NFS4_SESSION_DRAINING,
55};
56
57struct nfs4_minor_version_ops {
58 u32 minor_version;
59
60 int (*call_sync)(struct nfs_server *server,
61 struct rpc_message *msg,
62 struct nfs4_sequence_args *args,
63 struct nfs4_sequence_res *res,
64 int cache_reply);
65 int (*validate_stateid)(struct nfs_delegation *,
66 const nfs4_stateid *);
67 const struct nfs4_state_recovery_ops *reboot_recovery_ops;
68 const struct nfs4_state_recovery_ops *nograce_recovery_ops;
69 const struct nfs4_state_maintenance_ops *state_renewal_ops;
48}; 70};
49 71
50/* 72/*
@@ -87,9 +109,8 @@ struct nfs_unique_id {
87 */ 109 */
88struct nfs4_state_owner { 110struct nfs4_state_owner {
89 struct nfs_unique_id so_owner_id; 111 struct nfs_unique_id so_owner_id;
90 struct nfs_client *so_client;
91 struct nfs_server *so_server; 112 struct nfs_server *so_server;
92 struct rb_node so_client_node; 113 struct rb_node so_server_node;
93 114
94 struct rpc_cred *so_cred; /* Associated cred */ 115 struct rpc_cred *so_cred; /* Associated cred */
95 116
@@ -97,7 +118,6 @@ struct nfs4_state_owner {
97 atomic_t so_count; 118 atomic_t so_count;
98 unsigned long so_flags; 119 unsigned long so_flags;
99 struct list_head so_states; 120 struct list_head so_states;
100 struct list_head so_delegations;
101 struct nfs_seqid_counter so_seqid; 121 struct nfs_seqid_counter so_seqid;
102 struct rpc_sequence so_sequence; 122 struct rpc_sequence so_sequence;
103}; 123};
@@ -107,6 +127,10 @@ enum {
107 NFS_OWNER_RECLAIM_NOGRACE 127 NFS_OWNER_RECLAIM_NOGRACE
108}; 128};
109 129
130#define NFS_LOCK_NEW 0
131#define NFS_LOCK_RECLAIM 1
132#define NFS_LOCK_EXPIRED 2
133
110/* 134/*
111 * struct nfs4_state maintains the client-side state for a given 135 * struct nfs4_state maintains the client-side state for a given
112 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK). 136 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
@@ -119,10 +143,20 @@ enum {
119 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN) 143 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
120 */ 144 */
121 145
146struct nfs4_lock_owner {
147 unsigned int lo_type;
148#define NFS4_ANY_LOCK_TYPE (0U)
149#define NFS4_FLOCK_LOCK_TYPE (1U << 0)
150#define NFS4_POSIX_LOCK_TYPE (1U << 1)
151 union {
152 fl_owner_t posix_owner;
153 pid_t flock_owner;
154 } lo_u;
155};
156
122struct nfs4_lock_state { 157struct nfs4_lock_state {
123 struct list_head ls_locks; /* Other lock stateids */ 158 struct list_head ls_locks; /* Other lock stateids */
124 struct nfs4_state * ls_state; /* Pointer to open state */ 159 struct nfs4_state * ls_state; /* Pointer to open state */
125 fl_owner_t ls_owner; /* POSIX lock owner */
126#define NFS_LOCK_INITIALIZED 1 160#define NFS_LOCK_INITIALIZED 1
127 int ls_flags; 161 int ls_flags;
128 struct nfs_seqid_counter ls_seqid; 162 struct nfs_seqid_counter ls_seqid;
@@ -130,6 +164,7 @@ struct nfs4_lock_state {
130 struct nfs_unique_id ls_id; 164 struct nfs_unique_id ls_id;
131 nfs4_stateid ls_stateid; 165 nfs4_stateid ls_stateid;
132 atomic_t ls_count; 166 atomic_t ls_count;
167 struct nfs4_lock_owner ls_owner;
133}; 168};
134 169
135/* bits for nfs4_state->flags */ 170/* bits for nfs4_state->flags */
@@ -141,6 +176,7 @@ enum {
141 NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 176 NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */
142 NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 177 NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */
143 NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 178 NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */
179 NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */
144}; 180};
145 181
146struct nfs4_state { 182struct nfs4_state {
@@ -180,6 +216,7 @@ struct nfs4_state_recovery_ops {
180 int (*recover_lock)(struct nfs4_state *, struct file_lock *); 216 int (*recover_lock)(struct nfs4_state *, struct file_lock *);
181 int (*establish_clid)(struct nfs_client *, struct rpc_cred *); 217 int (*establish_clid)(struct nfs_client *, struct rpc_cred *);
182 struct rpc_cred * (*get_clid_cred)(struct nfs_client *); 218 struct rpc_cred * (*get_clid_cred)(struct nfs_client *);
219 int (*reclaim_complete)(struct nfs_client *);
183}; 220};
184 221
185struct nfs4_state_maintenance_ops { 222struct nfs4_state_maintenance_ops {
@@ -191,45 +228,57 @@ struct nfs4_state_maintenance_ops {
191extern const struct dentry_operations nfs4_dentry_operations; 228extern const struct dentry_operations nfs4_dentry_operations;
192extern const struct inode_operations nfs4_dir_inode_operations; 229extern const struct inode_operations nfs4_dir_inode_operations;
193 230
194/* inode.c */
195extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
196extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
197extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
198
199
200/* nfs4proc.c */ 231/* nfs4proc.c */
201extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *); 232extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
202extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct rpc_cred *); 233extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
234extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
203extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *); 235extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *);
204extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *); 236extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *);
205extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); 237extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
206extern int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait); 238extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
207extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); 239extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc);
208extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
209extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 240extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
210extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 241extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
211 struct nfs4_fs_locations *fs_locations, struct page *page); 242 struct nfs4_fs_locations *fs_locations, struct page *page);
243extern void nfs4_release_lockowner(const struct nfs4_lock_state *);
244extern const struct xattr_handler *nfs4_xattr_handlers[];
212 245
213extern struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[];
214extern struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[];
215#if defined(CONFIG_NFS_V4_1) 246#if defined(CONFIG_NFS_V4_1)
216extern int nfs4_setup_sequence(struct nfs_client *clp, 247static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
248{
249 return server->nfs_client->cl_session;
250}
251
252extern int nfs4_setup_sequence(const struct nfs_server *server,
217 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 253 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
218 int cache_reply, struct rpc_task *task); 254 int cache_reply, struct rpc_task *task);
219extern void nfs4_destroy_session(struct nfs4_session *session); 255extern void nfs4_destroy_session(struct nfs4_session *session);
220extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp); 256extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
221extern int nfs4_proc_create_session(struct nfs_client *, int reset); 257extern int nfs4_proc_create_session(struct nfs_client *);
222extern int nfs4_proc_destroy_session(struct nfs4_session *); 258extern int nfs4_proc_destroy_session(struct nfs4_session *);
259extern int nfs4_init_session(struct nfs_server *server);
260extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
261 struct nfs_fsinfo *fsinfo);
223#else /* CONFIG_NFS_v4_1 */ 262#else /* CONFIG_NFS_v4_1 */
224static inline int nfs4_setup_sequence(struct nfs_client *clp, 263static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
264{
265 return NULL;
266}
267
268static inline int nfs4_setup_sequence(const struct nfs_server *server,
225 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 269 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
226 int cache_reply, struct rpc_task *task) 270 int cache_reply, struct rpc_task *task)
227{ 271{
228 return 0; 272 return 0;
229} 273}
274
275static inline int nfs4_init_session(struct nfs_server *server)
276{
277 return 0;
278}
230#endif /* CONFIG_NFS_V4_1 */ 279#endif /* CONFIG_NFS_V4_1 */
231 280
232extern struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[]; 281extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
233 282
234extern const u32 nfs4_fattr_bitmap[2]; 283extern const u32 nfs4_fattr_bitmap[2];
235extern const u32 nfs4_statfs_bitmap[2]; 284extern const u32 nfs4_statfs_bitmap[2];
@@ -261,26 +310,30 @@ extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
261extern void nfs4_schedule_state_recovery(struct nfs_client *); 310extern void nfs4_schedule_state_recovery(struct nfs_client *);
262extern void nfs4_schedule_state_manager(struct nfs_client *); 311extern void nfs4_schedule_state_manager(struct nfs_client *);
263extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state); 312extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state);
313extern int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state);
314extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
315extern void nfs41_handle_recall_slot(struct nfs_client *clp);
264extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 316extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
265extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 317extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
266extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); 318extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t, pid_t);
267 319
268extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter); 320extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
269extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 321extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
270extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); 322extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
271extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); 323extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
324extern void nfs_release_seqid(struct nfs_seqid *seqid);
272extern void nfs_free_seqid(struct nfs_seqid *seqid); 325extern void nfs_free_seqid(struct nfs_seqid *seqid);
273 326
274extern const nfs4_stateid zero_stateid; 327extern const nfs4_stateid zero_stateid;
275 328
276/* nfs4xdr.c */ 329/* nfs4xdr.c */
277extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
278extern struct rpc_procinfo nfs4_procedures[]; 330extern struct rpc_procinfo nfs4_procedures[];
279 331
280struct nfs4_mount_data; 332struct nfs4_mount_data;
281 333
282/* callback_xdr.c */ 334/* callback_xdr.c */
283extern struct svc_version nfs4_callback_version1; 335extern struct svc_version nfs4_callback_version1;
336extern struct svc_version nfs4_callback_version4;
284 337
285#else 338#else
286 339
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
new file mode 100644
index 000000000000..23f930caf1e2
--- /dev/null
+++ b/fs/nfs/nfs4filelayout.c
@@ -0,0 +1,280 @@
1/*
2 * Module for the pnfs nfs4 file layout driver.
3 * Defines all I/O and Policy interface operations, plus code
4 * to register itself with the pNFS client.
5 *
6 * Copyright (c) 2002
7 * The Regents of the University of Michigan
8 * All Rights Reserved
9 *
10 * Dean Hildebrand <dhildebz@umich.edu>
11 *
12 * Permission is granted to use, copy, create derivative works, and
13 * redistribute this software and such derivative works for any purpose,
14 * so long as the name of the University of Michigan is not used in
15 * any advertising or publicity pertaining to the use or distribution
16 * of this software without specific, written prior authorization. If
17 * the above copyright notice or any other identification of the
18 * University of Michigan is included in any copy of any portion of
19 * this software, then the disclaimer below must also be included.
20 *
21 * This software is provided as is, without representation or warranty
22 * of any kind either express or implied, including without limitation
23 * the implied warranties of merchantability, fitness for a particular
24 * purpose, or noninfringement. The Regents of the University of
25 * Michigan shall not be liable for any damages, including special,
26 * indirect, incidental, or consequential damages, with respect to any
27 * claim arising out of or in connection with the use of the software,
28 * even if it has been or is hereafter advised of the possibility of
29 * such damages.
30 */
31
32#include <linux/nfs_fs.h>
33
34#include "internal.h"
35#include "nfs4filelayout.h"
36
37#define NFSDBG_FACILITY NFSDBG_PNFS_LD
38
39MODULE_LICENSE("GPL");
40MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
41MODULE_DESCRIPTION("The NFSv4 file layout driver");
42
43static int
44filelayout_set_layoutdriver(struct nfs_server *nfss)
45{
46 int status = pnfs_alloc_init_deviceid_cache(nfss->nfs_client,
47 nfs4_fl_free_deviceid_callback);
48 if (status) {
49 printk(KERN_WARNING "%s: deviceid cache could not be "
50 "initialized\n", __func__);
51 return status;
52 }
53 dprintk("%s: deviceid cache has been initialized successfully\n",
54 __func__);
55 return 0;
56}
57
58/* Clear out the layout by destroying its device list */
59static int
60filelayout_clear_layoutdriver(struct nfs_server *nfss)
61{
62 dprintk("--> %s\n", __func__);
63
64 if (nfss->nfs_client->cl_devid_cache)
65 pnfs_put_deviceid_cache(nfss->nfs_client);
66 return 0;
67}
68
69/*
70 * filelayout_check_layout()
71 *
72 * Make sure layout segment parameters are sane WRT the device.
73 * At this point no generic layer initialization of the lseg has occurred,
74 * and nothing has been added to the layout_hdr cache.
75 *
76 */
77static int
78filelayout_check_layout(struct pnfs_layout_hdr *lo,
79 struct nfs4_filelayout_segment *fl,
80 struct nfs4_layoutget_res *lgr,
81 struct nfs4_deviceid *id)
82{
83 struct nfs4_file_layout_dsaddr *dsaddr;
84 int status = -EINVAL;
85 struct nfs_server *nfss = NFS_SERVER(lo->plh_inode);
86
87 dprintk("--> %s\n", __func__);
88
89 if (fl->pattern_offset > lgr->range.offset) {
90 dprintk("%s pattern_offset %lld to large\n",
91 __func__, fl->pattern_offset);
92 goto out;
93 }
94
95 if (fl->stripe_unit % PAGE_SIZE) {
96 dprintk("%s Stripe unit (%u) not page aligned\n",
97 __func__, fl->stripe_unit);
98 goto out;
99 }
100
101 /* find and reference the deviceid */
102 dsaddr = nfs4_fl_find_get_deviceid(nfss->nfs_client, id);
103 if (dsaddr == NULL) {
104 dsaddr = get_device_info(lo->plh_inode, id);
105 if (dsaddr == NULL)
106 goto out;
107 }
108 fl->dsaddr = dsaddr;
109
110 if (fl->first_stripe_index < 0 ||
111 fl->first_stripe_index >= dsaddr->stripe_count) {
112 dprintk("%s Bad first_stripe_index %d\n",
113 __func__, fl->first_stripe_index);
114 goto out_put;
115 }
116
117 if ((fl->stripe_type == STRIPE_SPARSE &&
118 fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
119 (fl->stripe_type == STRIPE_DENSE &&
120 fl->num_fh != dsaddr->stripe_count)) {
121 dprintk("%s num_fh %u not valid for given packing\n",
122 __func__, fl->num_fh);
123 goto out_put;
124 }
125
126 if (fl->stripe_unit % nfss->rsize || fl->stripe_unit % nfss->wsize) {
127 dprintk("%s Stripe unit (%u) not aligned with rsize %u "
128 "wsize %u\n", __func__, fl->stripe_unit, nfss->rsize,
129 nfss->wsize);
130 }
131
132 status = 0;
133out:
134 dprintk("--> %s returns %d\n", __func__, status);
135 return status;
136out_put:
137 pnfs_put_deviceid(nfss->nfs_client->cl_devid_cache, &dsaddr->deviceid);
138 goto out;
139}
140
141static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl)
142{
143 int i;
144
145 for (i = 0; i < fl->num_fh; i++) {
146 if (!fl->fh_array[i])
147 break;
148 kfree(fl->fh_array[i]);
149 }
150 kfree(fl->fh_array);
151 fl->fh_array = NULL;
152}
153
154static void
155_filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
156{
157 filelayout_free_fh_array(fl);
158 kfree(fl);
159}
160
161static int
162filelayout_decode_layout(struct pnfs_layout_hdr *flo,
163 struct nfs4_filelayout_segment *fl,
164 struct nfs4_layoutget_res *lgr,
165 struct nfs4_deviceid *id)
166{
167 uint32_t *p = (uint32_t *)lgr->layout.buf;
168 uint32_t nfl_util;
169 int i;
170
171 dprintk("%s: set_layout_map Begin\n", __func__);
172
173 memcpy(id, p, sizeof(*id));
174 p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
175 print_deviceid(id);
176
177 nfl_util = be32_to_cpup(p++);
178 if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
179 fl->commit_through_mds = 1;
180 if (nfl_util & NFL4_UFLG_DENSE)
181 fl->stripe_type = STRIPE_DENSE;
182 else
183 fl->stripe_type = STRIPE_SPARSE;
184 fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
185
186 fl->first_stripe_index = be32_to_cpup(p++);
187 p = xdr_decode_hyper(p, &fl->pattern_offset);
188 fl->num_fh = be32_to_cpup(p++);
189
190 dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
191 __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
192 fl->pattern_offset);
193
194 fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *),
195 GFP_KERNEL);
196 if (!fl->fh_array)
197 return -ENOMEM;
198
199 for (i = 0; i < fl->num_fh; i++) {
200 /* Do we want to use a mempool here? */
201 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), GFP_KERNEL);
202 if (!fl->fh_array[i]) {
203 filelayout_free_fh_array(fl);
204 return -ENOMEM;
205 }
206 fl->fh_array[i]->size = be32_to_cpup(p++);
207 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
208 printk(KERN_ERR "Too big fh %d received %d\n",
209 i, fl->fh_array[i]->size);
210 filelayout_free_fh_array(fl);
211 return -EIO;
212 }
213 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
214 p += XDR_QUADLEN(fl->fh_array[i]->size);
215 dprintk("DEBUG: %s: fh len %d\n", __func__,
216 fl->fh_array[i]->size);
217 }
218
219 return 0;
220}
221
222static struct pnfs_layout_segment *
223filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
224 struct nfs4_layoutget_res *lgr)
225{
226 struct nfs4_filelayout_segment *fl;
227 int rc;
228 struct nfs4_deviceid id;
229
230 dprintk("--> %s\n", __func__);
231 fl = kzalloc(sizeof(*fl), GFP_KERNEL);
232 if (!fl)
233 return NULL;
234
235 rc = filelayout_decode_layout(layoutid, fl, lgr, &id);
236 if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id)) {
237 _filelayout_free_lseg(fl);
238 return NULL;
239 }
240 return &fl->generic_hdr;
241}
242
243static void
244filelayout_free_lseg(struct pnfs_layout_segment *lseg)
245{
246 struct nfs_server *nfss = NFS_SERVER(lseg->pls_layout->plh_inode);
247 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
248
249 dprintk("--> %s\n", __func__);
250 pnfs_put_deviceid(nfss->nfs_client->cl_devid_cache,
251 &fl->dsaddr->deviceid);
252 _filelayout_free_lseg(fl);
253}
254
255static struct pnfs_layoutdriver_type filelayout_type = {
256 .id = LAYOUT_NFSV4_1_FILES,
257 .name = "LAYOUT_NFSV4_1_FILES",
258 .owner = THIS_MODULE,
259 .set_layoutdriver = filelayout_set_layoutdriver,
260 .clear_layoutdriver = filelayout_clear_layoutdriver,
261 .alloc_lseg = filelayout_alloc_lseg,
262 .free_lseg = filelayout_free_lseg,
263};
264
265static int __init nfs4filelayout_init(void)
266{
267 printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
268 __func__);
269 return pnfs_register_layoutdriver(&filelayout_type);
270}
271
272static void __exit nfs4filelayout_exit(void)
273{
274 printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
275 __func__);
276 pnfs_unregister_layoutdriver(&filelayout_type);
277}
278
279module_init(nfs4filelayout_init);
280module_exit(nfs4filelayout_exit);
diff --git a/fs/nfs/nfs4filelayout.h b/fs/nfs/nfs4filelayout.h
new file mode 100644
index 000000000000..bbf60dd2ab9d
--- /dev/null
+++ b/fs/nfs/nfs4filelayout.h
@@ -0,0 +1,94 @@
1/*
2 * NFSv4 file layout driver data structures.
3 *
4 * Copyright (c) 2002
5 * The Regents of the University of Michigan
6 * All Rights Reserved
7 *
8 * Dean Hildebrand <dhildebz@umich.edu>
9 *
10 * Permission is granted to use, copy, create derivative works, and
11 * redistribute this software and such derivative works for any purpose,
12 * so long as the name of the University of Michigan is not used in
13 * any advertising or publicity pertaining to the use or distribution
14 * of this software without specific, written prior authorization. If
15 * the above copyright notice or any other identification of the
16 * University of Michigan is included in any copy of any portion of
17 * this software, then the disclaimer below must also be included.
18 *
19 * This software is provided as is, without representation or warranty
20 * of any kind either express or implied, including without limitation
21 * the implied warranties of merchantability, fitness for a particular
22 * purpose, or noninfringement. The Regents of the University of
23 * Michigan shall not be liable for any damages, including special,
24 * indirect, incidental, or consequential damages, with respect to any
25 * claim arising out of or in connection with the use of the software,
26 * even if it has been or is hereafter advised of the possibility of
27 * such damages.
28 */
29
30#ifndef FS_NFS_NFS4FILELAYOUT_H
31#define FS_NFS_NFS4FILELAYOUT_H
32
33#include "pnfs.h"
34
35/*
36 * Field testing shows we need to support upto 4096 stripe indices.
37 * We store each index as a u8 (u32 on the wire) to keep the memory footprint
38 * reasonable. This in turn means we support a maximum of 256
39 * RFC 5661 multipath_list4 structures.
40 */
41#define NFS4_PNFS_MAX_STRIPE_CNT 4096
42#define NFS4_PNFS_MAX_MULTI_CNT 256 /* 256 fit into a u8 stripe_index */
43
44enum stripetype4 {
45 STRIPE_SPARSE = 1,
46 STRIPE_DENSE = 2
47};
48
49/* Individual ip address */
50struct nfs4_pnfs_ds {
51 struct list_head ds_node; /* nfs4_pnfs_dev_hlist dev_dslist */
52 u32 ds_ip_addr;
53 u32 ds_port;
54 struct nfs_client *ds_clp;
55 atomic_t ds_count;
56};
57
58struct nfs4_file_layout_dsaddr {
59 struct pnfs_deviceid_node deviceid;
60 u32 stripe_count;
61 u8 *stripe_indices;
62 u32 ds_num;
63 struct nfs4_pnfs_ds *ds_list[1];
64};
65
66struct nfs4_filelayout_segment {
67 struct pnfs_layout_segment generic_hdr;
68 u32 stripe_type;
69 u32 commit_through_mds;
70 u32 stripe_unit;
71 u32 first_stripe_index;
72 u64 pattern_offset;
73 struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */
74 unsigned int num_fh;
75 struct nfs_fh **fh_array;
76};
77
78static inline struct nfs4_filelayout_segment *
79FILELAYOUT_LSEG(struct pnfs_layout_segment *lseg)
80{
81 return container_of(lseg,
82 struct nfs4_filelayout_segment,
83 generic_hdr);
84}
85
86extern void nfs4_fl_free_deviceid_callback(struct pnfs_deviceid_node *);
87extern void print_ds(struct nfs4_pnfs_ds *ds);
88extern void print_deviceid(struct nfs4_deviceid *dev_id);
89extern struct nfs4_file_layout_dsaddr *
90nfs4_fl_find_get_deviceid(struct nfs_client *, struct nfs4_deviceid *dev_id);
91struct nfs4_file_layout_dsaddr *
92get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id);
93
94#endif /* FS_NFS_NFS4FILELAYOUT_H */
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
new file mode 100644
index 000000000000..51fe64ace55a
--- /dev/null
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -0,0 +1,448 @@
1/*
2 * Device operations for the pnfs nfs4 file layout driver.
3 *
4 * Copyright (c) 2002
5 * The Regents of the University of Michigan
6 * All Rights Reserved
7 *
8 * Dean Hildebrand <dhildebz@umich.edu>
9 * Garth Goodson <Garth.Goodson@netapp.com>
10 *
11 * Permission is granted to use, copy, create derivative works, and
12 * redistribute this software and such derivative works for any purpose,
13 * so long as the name of the University of Michigan is not used in
14 * any advertising or publicity pertaining to the use or distribution
15 * of this software without specific, written prior authorization. If
16 * the above copyright notice or any other identification of the
17 * University of Michigan is included in any copy of any portion of
18 * this software, then the disclaimer below must also be included.
19 *
20 * This software is provided as is, without representation or warranty
21 * of any kind either express or implied, including without limitation
22 * the implied warranties of merchantability, fitness for a particular
23 * purpose, or noninfringement. The Regents of the University of
24 * Michigan shall not be liable for any damages, including special,
25 * indirect, incidental, or consequential damages, with respect to any
26 * claim arising out of or in connection with the use of the software,
27 * even if it has been or is hereafter advised of the possibility of
28 * such damages.
29 */
30
31#include <linux/nfs_fs.h>
32#include <linux/vmalloc.h>
33
34#include "internal.h"
35#include "nfs4filelayout.h"
36
37#define NFSDBG_FACILITY NFSDBG_PNFS_LD
38
39/*
40 * Data server cache
41 *
42 * Data servers can be mapped to different device ids.
43 * nfs4_pnfs_ds reference counting
44 * - set to 1 on allocation
45 * - incremented when a device id maps a data server already in the cache.
46 * - decremented when deviceid is removed from the cache.
47 */
48DEFINE_SPINLOCK(nfs4_ds_cache_lock);
49static LIST_HEAD(nfs4_data_server_cache);
50
51/* Debug routines */
52void
53print_ds(struct nfs4_pnfs_ds *ds)
54{
55 if (ds == NULL) {
56 printk("%s NULL device\n", __func__);
57 return;
58 }
59 printk(" ip_addr %x port %hu\n"
60 " ref count %d\n"
61 " client %p\n"
62 " cl_exchange_flags %x\n",
63 ntohl(ds->ds_ip_addr), ntohs(ds->ds_port),
64 atomic_read(&ds->ds_count), ds->ds_clp,
65 ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0);
66}
67
68void
69print_ds_list(struct nfs4_file_layout_dsaddr *dsaddr)
70{
71 int i;
72
73 ifdebug(FACILITY) {
74 printk("%s dsaddr->ds_num %d\n", __func__,
75 dsaddr->ds_num);
76 for (i = 0; i < dsaddr->ds_num; i++)
77 print_ds(dsaddr->ds_list[i]);
78 }
79}
80
81void print_deviceid(struct nfs4_deviceid *id)
82{
83 u32 *p = (u32 *)id;
84
85 dprintk("%s: device id= [%x%x%x%x]\n", __func__,
86 p[0], p[1], p[2], p[3]);
87}
88
89/* nfs4_ds_cache_lock is held */
90static struct nfs4_pnfs_ds *
91_data_server_lookup_locked(u32 ip_addr, u32 port)
92{
93 struct nfs4_pnfs_ds *ds;
94
95 dprintk("_data_server_lookup: ip_addr=%x port=%hu\n",
96 ntohl(ip_addr), ntohs(port));
97
98 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) {
99 if (ds->ds_ip_addr == ip_addr &&
100 ds->ds_port == port) {
101 return ds;
102 }
103 }
104 return NULL;
105}
106
107static void
108destroy_ds(struct nfs4_pnfs_ds *ds)
109{
110 dprintk("--> %s\n", __func__);
111 ifdebug(FACILITY)
112 print_ds(ds);
113
114 if (ds->ds_clp)
115 nfs_put_client(ds->ds_clp);
116 kfree(ds);
117}
118
119static void
120nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
121{
122 struct nfs4_pnfs_ds *ds;
123 int i;
124
125 print_deviceid(&dsaddr->deviceid.de_id);
126
127 for (i = 0; i < dsaddr->ds_num; i++) {
128 ds = dsaddr->ds_list[i];
129 if (ds != NULL) {
130 if (atomic_dec_and_lock(&ds->ds_count,
131 &nfs4_ds_cache_lock)) {
132 list_del_init(&ds->ds_node);
133 spin_unlock(&nfs4_ds_cache_lock);
134 destroy_ds(ds);
135 }
136 }
137 }
138 kfree(dsaddr->stripe_indices);
139 kfree(dsaddr);
140}
141
142void
143nfs4_fl_free_deviceid_callback(struct pnfs_deviceid_node *device)
144{
145 struct nfs4_file_layout_dsaddr *dsaddr =
146 container_of(device, struct nfs4_file_layout_dsaddr, deviceid);
147
148 nfs4_fl_free_deviceid(dsaddr);
149}
150
151static struct nfs4_pnfs_ds *
152nfs4_pnfs_ds_add(struct inode *inode, u32 ip_addr, u32 port)
153{
154 struct nfs4_pnfs_ds *tmp_ds, *ds;
155
156 ds = kzalloc(sizeof(*tmp_ds), GFP_KERNEL);
157 if (!ds)
158 goto out;
159
160 spin_lock(&nfs4_ds_cache_lock);
161 tmp_ds = _data_server_lookup_locked(ip_addr, port);
162 if (tmp_ds == NULL) {
163 ds->ds_ip_addr = ip_addr;
164 ds->ds_port = port;
165 atomic_set(&ds->ds_count, 1);
166 INIT_LIST_HEAD(&ds->ds_node);
167 ds->ds_clp = NULL;
168 list_add(&ds->ds_node, &nfs4_data_server_cache);
169 dprintk("%s add new data server ip 0x%x\n", __func__,
170 ds->ds_ip_addr);
171 } else {
172 kfree(ds);
173 atomic_inc(&tmp_ds->ds_count);
174 dprintk("%s data server found ip 0x%x, inc'ed ds_count to %d\n",
175 __func__, tmp_ds->ds_ip_addr,
176 atomic_read(&tmp_ds->ds_count));
177 ds = tmp_ds;
178 }
179 spin_unlock(&nfs4_ds_cache_lock);
180out:
181 return ds;
182}
183
184/*
185 * Currently only support ipv4, and one multi-path address.
186 */
187static struct nfs4_pnfs_ds *
188decode_and_add_ds(__be32 **pp, struct inode *inode)
189{
190 struct nfs4_pnfs_ds *ds = NULL;
191 char *buf;
192 const char *ipend, *pstr;
193 u32 ip_addr, port;
194 int nlen, rlen, i;
195 int tmp[2];
196 __be32 *r_netid, *r_addr, *p = *pp;
197
198 /* r_netid */
199 nlen = be32_to_cpup(p++);
200 r_netid = p;
201 p += XDR_QUADLEN(nlen);
202
203 /* r_addr */
204 rlen = be32_to_cpup(p++);
205 r_addr = p;
206 p += XDR_QUADLEN(rlen);
207 *pp = p;
208
209 /* Check that netid is "tcp" */
210 if (nlen != 3 || memcmp((char *)r_netid, "tcp", 3)) {
211 dprintk("%s: ERROR: non ipv4 TCP r_netid\n", __func__);
212 goto out_err;
213 }
214
215 /* ipv6 length plus port is legal */
216 if (rlen > INET6_ADDRSTRLEN + 8) {
217 dprintk("%s Invalid address, length %d\n", __func__,
218 rlen);
219 goto out_err;
220 }
221 buf = kmalloc(rlen + 1, GFP_KERNEL);
222 buf[rlen] = '\0';
223 memcpy(buf, r_addr, rlen);
224
225 /* replace the port dots with dashes for the in4_pton() delimiter*/
226 for (i = 0; i < 2; i++) {
227 char *res = strrchr(buf, '.');
228 *res = '-';
229 }
230
231 /* Currently only support ipv4 address */
232 if (in4_pton(buf, rlen, (u8 *)&ip_addr, '-', &ipend) == 0) {
233 dprintk("%s: Only ipv4 addresses supported\n", __func__);
234 goto out_free;
235 }
236
237 /* port */
238 pstr = ipend;
239 sscanf(pstr, "-%d-%d", &tmp[0], &tmp[1]);
240 port = htons((tmp[0] << 8) | (tmp[1]));
241
242 ds = nfs4_pnfs_ds_add(inode, ip_addr, port);
243 dprintk("%s Decoded address and port %s\n", __func__, buf);
244out_free:
245 kfree(buf);
246out_err:
247 return ds;
248}
249
250/* Decode opaque device data and return the result */
251static struct nfs4_file_layout_dsaddr*
252decode_device(struct inode *ino, struct pnfs_device *pdev)
253{
254 int i, dummy;
255 u32 cnt, num;
256 u8 *indexp;
257 __be32 *p = (__be32 *)pdev->area, *indicesp;
258 struct nfs4_file_layout_dsaddr *dsaddr;
259
260 /* Get the stripe count (number of stripe index) */
261 cnt = be32_to_cpup(p++);
262 dprintk("%s stripe count %d\n", __func__, cnt);
263 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
264 printk(KERN_WARNING "%s: stripe count %d greater than "
265 "supported maximum %d\n", __func__,
266 cnt, NFS4_PNFS_MAX_STRIPE_CNT);
267 goto out_err;
268 }
269
270 /* Check the multipath list count */
271 indicesp = p;
272 p += XDR_QUADLEN(cnt << 2);
273 num = be32_to_cpup(p++);
274 dprintk("%s ds_num %u\n", __func__, num);
275 if (num > NFS4_PNFS_MAX_MULTI_CNT) {
276 printk(KERN_WARNING "%s: multipath count %d greater than "
277 "supported maximum %d\n", __func__,
278 num, NFS4_PNFS_MAX_MULTI_CNT);
279 goto out_err;
280 }
281 dsaddr = kzalloc(sizeof(*dsaddr) +
282 (sizeof(struct nfs4_pnfs_ds *) * (num - 1)),
283 GFP_KERNEL);
284 if (!dsaddr)
285 goto out_err;
286
287 dsaddr->stripe_indices = kzalloc(sizeof(u8) * cnt, GFP_KERNEL);
288 if (!dsaddr->stripe_indices)
289 goto out_err_free;
290
291 dsaddr->stripe_count = cnt;
292 dsaddr->ds_num = num;
293
294 memcpy(&dsaddr->deviceid.de_id, &pdev->dev_id, sizeof(pdev->dev_id));
295
296 /* Go back an read stripe indices */
297 p = indicesp;
298 indexp = &dsaddr->stripe_indices[0];
299 for (i = 0; i < dsaddr->stripe_count; i++) {
300 *indexp = be32_to_cpup(p++);
301 if (*indexp >= num)
302 goto out_err_free;
303 indexp++;
304 }
305 /* Skip already read multipath list count */
306 p++;
307
308 for (i = 0; i < dsaddr->ds_num; i++) {
309 int j;
310
311 dummy = be32_to_cpup(p++); /* multipath count */
312 if (dummy > 1) {
313 printk(KERN_WARNING
314 "%s: Multipath count %d not supported, "
315 "skipping all greater than 1\n", __func__,
316 dummy);
317 }
318 for (j = 0; j < dummy; j++) {
319 if (j == 0) {
320 dsaddr->ds_list[i] = decode_and_add_ds(&p, ino);
321 if (dsaddr->ds_list[i] == NULL)
322 goto out_err_free;
323 } else {
324 u32 len;
325 /* skip extra multipath */
326 len = be32_to_cpup(p++);
327 p += XDR_QUADLEN(len);
328 len = be32_to_cpup(p++);
329 p += XDR_QUADLEN(len);
330 continue;
331 }
332 }
333 }
334 return dsaddr;
335
336out_err_free:
337 nfs4_fl_free_deviceid(dsaddr);
338out_err:
339 dprintk("%s ERROR: returning NULL\n", __func__);
340 return NULL;
341}
342
343/*
344 * Decode the opaque device specified in 'dev'
345 * and add it to the list of available devices.
346 * If the deviceid is already cached, nfs4_add_deviceid will return
347 * a pointer to the cached struct and throw away the new.
348 */
349static struct nfs4_file_layout_dsaddr*
350decode_and_add_device(struct inode *inode, struct pnfs_device *dev)
351{
352 struct nfs4_file_layout_dsaddr *dsaddr;
353 struct pnfs_deviceid_node *d;
354
355 dsaddr = decode_device(inode, dev);
356 if (!dsaddr) {
357 printk(KERN_WARNING "%s: Could not decode or add device\n",
358 __func__);
359 return NULL;
360 }
361
362 d = pnfs_add_deviceid(NFS_SERVER(inode)->nfs_client->cl_devid_cache,
363 &dsaddr->deviceid);
364
365 return container_of(d, struct nfs4_file_layout_dsaddr, deviceid);
366}
367
368/*
369 * Retrieve the information for dev_id, add it to the list
370 * of available devices, and return it.
371 */
372struct nfs4_file_layout_dsaddr *
373get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id)
374{
375 struct pnfs_device *pdev = NULL;
376 u32 max_resp_sz;
377 int max_pages;
378 struct page **pages = NULL;
379 struct nfs4_file_layout_dsaddr *dsaddr = NULL;
380 int rc, i;
381 struct nfs_server *server = NFS_SERVER(inode);
382
383 /*
384 * Use the session max response size as the basis for setting
385 * GETDEVICEINFO's maxcount
386 */
387 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
388 max_pages = max_resp_sz >> PAGE_SHIFT;
389 dprintk("%s inode %p max_resp_sz %u max_pages %d\n",
390 __func__, inode, max_resp_sz, max_pages);
391
392 pdev = kzalloc(sizeof(struct pnfs_device), GFP_KERNEL);
393 if (pdev == NULL)
394 return NULL;
395
396 pages = kzalloc(max_pages * sizeof(struct page *), GFP_KERNEL);
397 if (pages == NULL) {
398 kfree(pdev);
399 return NULL;
400 }
401 for (i = 0; i < max_pages; i++) {
402 pages[i] = alloc_page(GFP_KERNEL);
403 if (!pages[i])
404 goto out_free;
405 }
406
407 /* set pdev->area */
408 pdev->area = vmap(pages, max_pages, VM_MAP, PAGE_KERNEL);
409 if (!pdev->area)
410 goto out_free;
411
412 memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id));
413 pdev->layout_type = LAYOUT_NFSV4_1_FILES;
414 pdev->pages = pages;
415 pdev->pgbase = 0;
416 pdev->pglen = PAGE_SIZE * max_pages;
417 pdev->mincount = 0;
418
419 rc = nfs4_proc_getdeviceinfo(server, pdev);
420 dprintk("%s getdevice info returns %d\n", __func__, rc);
421 if (rc)
422 goto out_free;
423
424 /*
425 * Found new device, need to decode it and then add it to the
426 * list of known devices for this mountpoint.
427 */
428 dsaddr = decode_and_add_device(inode, pdev);
429out_free:
430 if (pdev->area != NULL)
431 vunmap(pdev->area);
432 for (i = 0; i < max_pages; i++)
433 __free_page(pages[i]);
434 kfree(pages);
435 kfree(pdev);
436 dprintk("<-- %s dsaddr %p\n", __func__, dsaddr);
437 return dsaddr;
438}
439
440struct nfs4_file_layout_dsaddr *
441nfs4_fl_find_get_deviceid(struct nfs_client *clp, struct nfs4_deviceid *id)
442{
443 struct pnfs_deviceid_node *d;
444
445 d = pnfs_find_get_deviceid(clp->cl_devid_cache, id);
446 return (d == NULL) ? NULL :
447 container_of(d, struct nfs4_file_layout_dsaddr, deviceid);
448}
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 2a2a0a7143ad..3c2a1724fbd2 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -11,12 +11,14 @@
11#include <linux/mount.h> 11#include <linux/mount.h>
12#include <linux/namei.h> 12#include <linux/namei.h>
13#include <linux/nfs_fs.h> 13#include <linux/nfs_fs.h>
14#include <linux/slab.h>
14#include <linux/string.h> 15#include <linux/string.h>
15#include <linux/sunrpc/clnt.h> 16#include <linux/sunrpc/clnt.h>
16#include <linux/vfs.h> 17#include <linux/vfs.h>
17#include <linux/inet.h> 18#include <linux/inet.h>
18#include "internal.h" 19#include "internal.h"
19#include "nfs4_fs.h" 20#include "nfs4_fs.h"
21#include "dns_resolve.h"
20 22
21#define NFSDBG_FACILITY NFSDBG_VFS 23#define NFSDBG_FACILITY NFSDBG_VFS
22 24
@@ -95,10 +97,25 @@ static int nfs4_validate_fspath(const struct vfsmount *mnt_parent,
95 return 0; 97 return 0;
96} 98}
97 99
100static size_t nfs_parse_server_name(char *string, size_t len,
101 struct sockaddr *sa, size_t salen)
102{
103 ssize_t ret;
104
105 ret = rpc_pton(string, len, sa, salen);
106 if (ret == 0) {
107 ret = nfs_dns_resolve_name(string, len, sa, salen);
108 if (ret < 0)
109 ret = 0;
110 }
111 return ret;
112}
113
98static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, 114static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
99 char *page, char *page2, 115 char *page, char *page2,
100 const struct nfs4_fs_location *location) 116 const struct nfs4_fs_location *location)
101{ 117{
118 const size_t addr_bufsize = sizeof(struct sockaddr_storage);
102 struct vfsmount *mnt = ERR_PTR(-ENOENT); 119 struct vfsmount *mnt = ERR_PTR(-ENOENT);
103 char *mnt_path; 120 char *mnt_path;
104 unsigned int maxbuflen; 121 unsigned int maxbuflen;
@@ -106,26 +123,29 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
106 123
107 mnt_path = nfs4_pathname_string(&location->rootpath, page2, PAGE_SIZE); 124 mnt_path = nfs4_pathname_string(&location->rootpath, page2, PAGE_SIZE);
108 if (IS_ERR(mnt_path)) 125 if (IS_ERR(mnt_path))
109 return mnt; 126 return ERR_CAST(mnt_path);
110 mountdata->mnt_path = mnt_path; 127 mountdata->mnt_path = mnt_path;
111 maxbuflen = mnt_path - 1 - page2; 128 maxbuflen = mnt_path - 1 - page2;
112 129
130 mountdata->addr = kmalloc(addr_bufsize, GFP_KERNEL);
131 if (mountdata->addr == NULL)
132 return ERR_PTR(-ENOMEM);
133
113 for (s = 0; s < location->nservers; s++) { 134 for (s = 0; s < location->nservers; s++) {
114 const struct nfs4_string *buf = &location->servers[s]; 135 const struct nfs4_string *buf = &location->servers[s];
115 struct sockaddr_storage addr;
116 136
117 if (buf->len <= 0 || buf->len >= maxbuflen) 137 if (buf->len <= 0 || buf->len >= maxbuflen)
118 continue; 138 continue;
119 139
120 mountdata->addr = (struct sockaddr *)&addr;
121
122 if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len)) 140 if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len))
123 continue; 141 continue;
124 nfs_parse_ip_address(buf->data, buf->len, 142
125 mountdata->addr, &mountdata->addrlen); 143 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len,
126 if (mountdata->addr->sa_family == AF_UNSPEC) 144 mountdata->addr, addr_bufsize);
145 if (mountdata->addrlen == 0)
127 continue; 146 continue;
128 nfs_set_port(mountdata->addr, NFS_PORT); 147
148 rpc_set_port(mountdata->addr, NFS_PORT);
129 149
130 memcpy(page2, buf->data, buf->len); 150 memcpy(page2, buf->data, buf->len);
131 page2[buf->len] = '\0'; 151 page2[buf->len] = '\0';
@@ -139,6 +159,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
139 if (!IS_ERR(mnt)) 159 if (!IS_ERR(mnt))
140 break; 160 break;
141 } 161 }
162 kfree(mountdata->addr);
142 return mnt; 163 return mnt;
143} 164}
144 165
@@ -204,8 +225,8 @@ out:
204 225
205/* 226/*
206 * nfs_do_refmount - handle crossing a referral on server 227 * nfs_do_refmount - handle crossing a referral on server
228 * @mnt_parent - mountpoint of referral
207 * @dentry - dentry of referral 229 * @dentry - dentry of referral
208 * @nd - nameidata info
209 * 230 *
210 */ 231 */
211struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 232struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 92ce43517814..9d992b0346e3 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -36,48 +36,60 @@
36 */ 36 */
37 37
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/utsname.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/errno.h> 40#include <linux/errno.h>
42#include <linux/string.h> 41#include <linux/string.h>
42#include <linux/slab.h>
43#include <linux/sunrpc/clnt.h> 43#include <linux/sunrpc/clnt.h>
44#include <linux/nfs.h> 44#include <linux/nfs.h>
45#include <linux/nfs4.h> 45#include <linux/nfs4.h>
46#include <linux/nfs_fs.h> 46#include <linux/nfs_fs.h>
47#include <linux/nfs_page.h> 47#include <linux/nfs_page.h>
48#include <linux/smp_lock.h>
49#include <linux/namei.h> 48#include <linux/namei.h>
50#include <linux/mount.h> 49#include <linux/mount.h>
51#include <linux/module.h> 50#include <linux/module.h>
52#include <linux/sunrpc/bc_xprt.h> 51#include <linux/sunrpc/bc_xprt.h>
52#include <linux/xattr.h>
53 53
54#include "nfs4_fs.h" 54#include "nfs4_fs.h"
55#include "delegation.h" 55#include "delegation.h"
56#include "internal.h" 56#include "internal.h"
57#include "iostat.h" 57#include "iostat.h"
58#include "callback.h" 58#include "callback.h"
59#include "pnfs.h"
59 60
60#define NFSDBG_FACILITY NFSDBG_PROC 61#define NFSDBG_FACILITY NFSDBG_PROC
61 62
62#define NFS4_POLL_RETRY_MIN (HZ/10) 63#define NFS4_POLL_RETRY_MIN (HZ/10)
63#define NFS4_POLL_RETRY_MAX (15*HZ) 64#define NFS4_POLL_RETRY_MAX (15*HZ)
64 65
66#define NFS4_MAX_LOOP_ON_RECOVER (10)
67
65struct nfs4_opendata; 68struct nfs4_opendata;
66static int _nfs4_proc_open(struct nfs4_opendata *data); 69static int _nfs4_proc_open(struct nfs4_opendata *data);
70static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
67static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); 71static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
68static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); 72static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
69static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); 73static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
70static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); 74static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
75static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
76 struct nfs_fattr *fattr, struct iattr *sattr,
77 struct nfs4_state *state);
71 78
72/* Prevent leaks of NFSv4 errors into userland */ 79/* Prevent leaks of NFSv4 errors into userland */
73static int nfs4_map_errors(int err) 80static int nfs4_map_errors(int err)
74{ 81{
75 if (err < -1000) { 82 if (err >= -1000)
83 return err;
84 switch (err) {
85 case -NFS4ERR_RESOURCE:
86 return -EREMOTEIO;
87 default:
76 dprintk("%s could not handle NFSv4 error %d\n", 88 dprintk("%s could not handle NFSv4 error %d\n",
77 __func__, -err); 89 __func__, -err);
78 return -EIO; 90 break;
79 } 91 }
80 return err; 92 return -EIO;
81} 93}
82 94
83/* 95/*
@@ -119,7 +131,8 @@ const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
119 | FATTR4_WORD0_MAXREAD 131 | FATTR4_WORD0_MAXREAD
120 | FATTR4_WORD0_MAXWRITE 132 | FATTR4_WORD0_MAXWRITE
121 | FATTR4_WORD0_LEASE_TIME, 133 | FATTR4_WORD0_LEASE_TIME,
122 0 134 FATTR4_WORD1_TIME_DELTA
135 | FATTR4_WORD1_FS_LAYOUT_TYPES
123}; 136};
124 137
125const u32 nfs4_fs_locations_bitmap[2] = { 138const u32 nfs4_fs_locations_bitmap[2] = {
@@ -243,19 +256,12 @@ static int nfs4_handle_exception(const struct nfs_server *server, int errorcode,
243 if (state == NULL) 256 if (state == NULL)
244 break; 257 break;
245 nfs4_state_mark_reclaim_nograce(clp, state); 258 nfs4_state_mark_reclaim_nograce(clp, state);
246 case -NFS4ERR_STALE_CLIENTID: 259 goto do_state_recovery;
247 case -NFS4ERR_STALE_STATEID: 260 case -NFS4ERR_STALE_STATEID:
261 case -NFS4ERR_STALE_CLIENTID:
248 case -NFS4ERR_EXPIRED: 262 case -NFS4ERR_EXPIRED:
249 nfs4_schedule_state_recovery(clp); 263 goto do_state_recovery;
250 ret = nfs4_wait_clnt_recover(clp); 264#if defined(CONFIG_NFS_V4_1)
251 if (ret == 0)
252 exception->retry = 1;
253#if !defined(CONFIG_NFS_V4_1)
254 break;
255#else /* !defined(CONFIG_NFS_V4_1) */
256 if (!nfs4_has_session(server->nfs_client))
257 break;
258 /* FALLTHROUGH */
259 case -NFS4ERR_BADSESSION: 265 case -NFS4ERR_BADSESSION:
260 case -NFS4ERR_BADSLOT: 266 case -NFS4ERR_BADSLOT:
261 case -NFS4ERR_BAD_HIGH_SLOT: 267 case -NFS4ERR_BAD_HIGH_SLOT:
@@ -265,13 +271,21 @@ static int nfs4_handle_exception(const struct nfs_server *server, int errorcode,
265 case -NFS4ERR_SEQ_MISORDERED: 271 case -NFS4ERR_SEQ_MISORDERED:
266 dprintk("%s ERROR: %d Reset session\n", __func__, 272 dprintk("%s ERROR: %d Reset session\n", __func__,
267 errorcode); 273 errorcode);
268 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 274 nfs4_schedule_state_recovery(clp);
269 exception->retry = 1; 275 exception->retry = 1;
270 /* FALLTHROUGH */ 276 break;
271#endif /* !defined(CONFIG_NFS_V4_1) */ 277#endif /* defined(CONFIG_NFS_V4_1) */
272 case -NFS4ERR_FILE_OPEN: 278 case -NFS4ERR_FILE_OPEN:
279 if (exception->timeout > HZ) {
280 /* We have retried a decent amount, time to
281 * fail
282 */
283 ret = -EBUSY;
284 break;
285 }
273 case -NFS4ERR_GRACE: 286 case -NFS4ERR_GRACE:
274 case -NFS4ERR_DELAY: 287 case -NFS4ERR_DELAY:
288 case -EKEYEXPIRED:
275 ret = nfs4_delay(server->client, &exception->timeout); 289 ret = nfs4_delay(server->client, &exception->timeout);
276 if (ret != 0) 290 if (ret != 0)
277 break; 291 break;
@@ -280,18 +294,28 @@ static int nfs4_handle_exception(const struct nfs_server *server, int errorcode,
280 } 294 }
281 /* We failed to handle the error */ 295 /* We failed to handle the error */
282 return nfs4_map_errors(ret); 296 return nfs4_map_errors(ret);
297do_state_recovery:
298 nfs4_schedule_state_recovery(clp);
299 ret = nfs4_wait_clnt_recover(clp);
300 if (ret == 0)
301 exception->retry = 1;
302 return ret;
283} 303}
284 304
285 305
286static void renew_lease(const struct nfs_server *server, unsigned long timestamp) 306static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
287{ 307{
288 struct nfs_client *clp = server->nfs_client;
289 spin_lock(&clp->cl_lock); 308 spin_lock(&clp->cl_lock);
290 if (time_before(clp->cl_last_renewal,timestamp)) 309 if (time_before(clp->cl_last_renewal,timestamp))
291 clp->cl_last_renewal = timestamp; 310 clp->cl_last_renewal = timestamp;
292 spin_unlock(&clp->cl_lock); 311 spin_unlock(&clp->cl_lock);
293} 312}
294 313
314static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
315{
316 do_renew_lease(server->nfs_client, timestamp);
317}
318
295#if defined(CONFIG_NFS_V4_1) 319#if defined(CONFIG_NFS_V4_1)
296 320
297/* 321/*
@@ -306,58 +330,87 @@ static void renew_lease(const struct nfs_server *server, unsigned long timestamp
306 * so we need to scan down from highest_used_slotid to 0 looking for the now 330 * so we need to scan down from highest_used_slotid to 0 looking for the now
307 * highest slotid in use. 331 * highest slotid in use.
308 * If none found, highest_used_slotid is set to -1. 332 * If none found, highest_used_slotid is set to -1.
333 *
334 * Must be called while holding tbl->slot_tbl_lock
309 */ 335 */
310static void 336static void
311nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) 337nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot)
312{ 338{
339 int free_slotid = free_slot - tbl->slots;
313 int slotid = free_slotid; 340 int slotid = free_slotid;
314 341
315 spin_lock(&tbl->slot_tbl_lock); 342 BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE);
316 /* clear used bit in bitmap */ 343 /* clear used bit in bitmap */
317 __clear_bit(slotid, tbl->used_slots); 344 __clear_bit(slotid, tbl->used_slots);
318 345
319 /* update highest_used_slotid when it is freed */ 346 /* update highest_used_slotid when it is freed */
320 if (slotid == tbl->highest_used_slotid) { 347 if (slotid == tbl->highest_used_slotid) {
321 slotid = find_last_bit(tbl->used_slots, tbl->max_slots); 348 slotid = find_last_bit(tbl->used_slots, tbl->max_slots);
322 if (slotid >= 0 && slotid < tbl->max_slots) 349 if (slotid < tbl->max_slots)
323 tbl->highest_used_slotid = slotid; 350 tbl->highest_used_slotid = slotid;
324 else 351 else
325 tbl->highest_used_slotid = -1; 352 tbl->highest_used_slotid = -1;
326 } 353 }
327 rpc_wake_up_next(&tbl->slot_tbl_waitq);
328 spin_unlock(&tbl->slot_tbl_lock);
329 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, 354 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__,
330 free_slotid, tbl->highest_used_slotid); 355 free_slotid, tbl->highest_used_slotid);
331} 356}
332 357
333void nfs41_sequence_free_slot(const struct nfs_client *clp, 358/*
334 struct nfs4_sequence_res *res) 359 * Signal state manager thread if session fore channel is drained
360 */
361static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
335{ 362{
336 struct nfs4_slot_table *tbl; 363 struct rpc_task *task;
337 364
338 if (!nfs4_has_session(clp)) { 365 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
339 dprintk("%s: No session\n", __func__); 366 task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq);
367 if (task)
368 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
340 return; 369 return;
341 } 370 }
342 tbl = &clp->cl_session->fc_slot_table; 371
343 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) { 372 if (ses->fc_slot_table.highest_used_slotid != -1)
344 dprintk("%s: No slot\n", __func__); 373 return;
374
375 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__);
376 complete(&ses->fc_slot_table.complete);
377}
378
379/*
380 * Signal state manager thread if session back channel is drained
381 */
382void nfs4_check_drain_bc_complete(struct nfs4_session *ses)
383{
384 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) ||
385 ses->bc_slot_table.highest_used_slotid != -1)
386 return;
387 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__);
388 complete(&ses->bc_slot_table.complete);
389}
390
391static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
392{
393 struct nfs4_slot_table *tbl;
394
395 tbl = &res->sr_session->fc_slot_table;
396 if (!res->sr_slot) {
345 /* just wake up the next guy waiting since 397 /* just wake up the next guy waiting since
346 * we may have not consumed a slot after all */ 398 * we may have not consumed a slot after all */
347 rpc_wake_up_next(&tbl->slot_tbl_waitq); 399 dprintk("%s: No slot\n", __func__);
348 return; 400 return;
349 } 401 }
350 nfs4_free_slot(tbl, res->sr_slotid); 402
351 res->sr_slotid = NFS4_MAX_SLOT_TABLE; 403 spin_lock(&tbl->slot_tbl_lock);
404 nfs4_free_slot(tbl, res->sr_slot);
405 nfs4_check_drain_fc_complete(res->sr_session);
406 spin_unlock(&tbl->slot_tbl_lock);
407 res->sr_slot = NULL;
352} 408}
353 409
354static void nfs41_sequence_done(struct nfs_client *clp, 410static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
355 struct nfs4_sequence_res *res,
356 int rpc_status)
357{ 411{
358 unsigned long timestamp; 412 unsigned long timestamp;
359 struct nfs4_slot_table *tbl; 413 struct nfs_client *clp;
360 struct nfs4_slot *slot;
361 414
362 /* 415 /*
363 * sr_status remains 1 if an RPC level error occurred. The server 416 * sr_status remains 1 if an RPC level error occurred. The server
@@ -369,26 +422,53 @@ static void nfs41_sequence_done(struct nfs_client *clp,
369 res->sr_status = NFS_OK; 422 res->sr_status = NFS_OK;
370 423
371 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ 424 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
372 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) 425 if (!res->sr_slot)
373 goto out; 426 goto out;
374 427
375 tbl = &clp->cl_session->fc_slot_table; 428 /* Check the SEQUENCE operation status */
376 slot = tbl->slots + res->sr_slotid; 429 switch (res->sr_status) {
377 430 case 0:
378 if (res->sr_status == 0) {
379 /* Update the slot's sequence and clientid lease timer */ 431 /* Update the slot's sequence and clientid lease timer */
380 ++slot->seq_nr; 432 ++res->sr_slot->seq_nr;
381 timestamp = res->sr_renewal_time; 433 timestamp = res->sr_renewal_time;
382 spin_lock(&clp->cl_lock); 434 clp = res->sr_session->clp;
383 if (time_before(clp->cl_last_renewal, timestamp)) 435 do_renew_lease(clp, timestamp);
384 clp->cl_last_renewal = timestamp; 436 /* Check sequence flags */
385 spin_unlock(&clp->cl_lock); 437 if (atomic_read(&clp->cl_count) > 1)
386 return; 438 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
439 break;
440 case -NFS4ERR_DELAY:
441 /* The server detected a resend of the RPC call and
442 * returned NFS4ERR_DELAY as per Section 2.10.6.2
443 * of RFC5661.
444 */
445 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
446 __func__,
447 res->sr_slot - res->sr_session->fc_slot_table.slots,
448 res->sr_slot->seq_nr);
449 goto out_retry;
450 default:
451 /* Just update the slot sequence no. */
452 ++res->sr_slot->seq_nr;
387 } 453 }
388out: 454out:
389 /* The session may be reset by one of the error handlers. */ 455 /* The session may be reset by one of the error handlers. */
390 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); 456 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
391 nfs41_sequence_free_slot(clp, res); 457 nfs41_sequence_free_slot(res);
458 return 1;
459out_retry:
460 if (!rpc_restart_call(task))
461 goto out;
462 rpc_delay(task, NFS4_POLL_RETRY_MAX);
463 return 0;
464}
465
466static int nfs4_sequence_done(struct rpc_task *task,
467 struct nfs4_sequence_res *res)
468{
469 if (res->sr_session == NULL)
470 return 1;
471 return nfs41_sequence_done(task, res);
392} 472}
393 473
394/* 474/*
@@ -402,7 +482,7 @@ out:
402 * Note: must be called with under the slot_tbl_lock. 482 * Note: must be called with under the slot_tbl_lock.
403 */ 483 */
404static u8 484static u8
405nfs4_find_slot(struct nfs4_slot_table *tbl, struct rpc_task *task) 485nfs4_find_slot(struct nfs4_slot_table *tbl)
406{ 486{
407 int slotid; 487 int slotid;
408 u8 ret_id = NFS4_MAX_SLOT_TABLE; 488 u8 ret_id = NFS4_MAX_SLOT_TABLE;
@@ -424,22 +504,6 @@ out:
424 return ret_id; 504 return ret_id;
425} 505}
426 506
427static int nfs4_recover_session(struct nfs4_session *session)
428{
429 struct nfs_client *clp = session->clp;
430 int ret;
431
432 for (;;) {
433 ret = nfs4_wait_clnt_recover(clp);
434 if (ret != 0)
435 return ret;
436 if (!test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state))
437 break;
438 nfs4_schedule_state_manager(clp);
439 }
440 return 0;
441}
442
443static int nfs41_setup_sequence(struct nfs4_session *session, 507static int nfs41_setup_sequence(struct nfs4_session *session,
444 struct nfs4_sequence_args *args, 508 struct nfs4_sequence_args *args,
445 struct nfs4_sequence_res *res, 509 struct nfs4_sequence_res *res,
@@ -448,37 +512,37 @@ static int nfs41_setup_sequence(struct nfs4_session *session,
448{ 512{
449 struct nfs4_slot *slot; 513 struct nfs4_slot *slot;
450 struct nfs4_slot_table *tbl; 514 struct nfs4_slot_table *tbl;
451 int status = 0;
452 u8 slotid; 515 u8 slotid;
453 516
454 dprintk("--> %s\n", __func__); 517 dprintk("--> %s\n", __func__);
455 /* slot already allocated? */ 518 /* slot already allocated? */
456 if (res->sr_slotid != NFS4_MAX_SLOT_TABLE) 519 if (res->sr_slot != NULL)
457 return 0; 520 return 0;
458 521
459 memset(res, 0, sizeof(*res));
460 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
461 tbl = &session->fc_slot_table; 522 tbl = &session->fc_slot_table;
462 523
463 spin_lock(&tbl->slot_tbl_lock); 524 spin_lock(&tbl->slot_tbl_lock);
464 if (test_bit(NFS4CLNT_SESSION_SETUP, &session->clp->cl_state)) { 525 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
465 if (tbl->highest_used_slotid != -1) { 526 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
466 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 527 /*
467 spin_unlock(&tbl->slot_tbl_lock); 528 * The state manager will wait until the slot table is empty.
468 dprintk("<-- %s: Session reset: draining\n", __func__); 529 * Schedule the reset thread
469 return -EAGAIN; 530 */
470 } 531 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
532 spin_unlock(&tbl->slot_tbl_lock);
533 dprintk("%s Schedule Session Reset\n", __func__);
534 return -EAGAIN;
535 }
471 536
472 /* The slot table is empty; start the reset thread */ 537 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
473 dprintk("%s Session Reset\n", __func__); 538 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
539 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
474 spin_unlock(&tbl->slot_tbl_lock); 540 spin_unlock(&tbl->slot_tbl_lock);
475 status = nfs4_recover_session(session); 541 dprintk("%s enforce FIFO order\n", __func__);
476 if (status) 542 return -EAGAIN;
477 return status;
478 spin_lock(&tbl->slot_tbl_lock);
479 } 543 }
480 544
481 slotid = nfs4_find_slot(tbl, task); 545 slotid = nfs4_find_slot(tbl);
482 if (slotid == NFS4_MAX_SLOT_TABLE) { 546 if (slotid == NFS4_MAX_SLOT_TABLE) {
483 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 547 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
484 spin_unlock(&tbl->slot_tbl_lock); 548 spin_unlock(&tbl->slot_tbl_lock);
@@ -487,6 +551,7 @@ static int nfs41_setup_sequence(struct nfs4_session *session,
487 } 551 }
488 spin_unlock(&tbl->slot_tbl_lock); 552 spin_unlock(&tbl->slot_tbl_lock);
489 553
554 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
490 slot = tbl->slots + slotid; 555 slot = tbl->slots + slotid;
491 args->sa_session = session; 556 args->sa_session = session;
492 args->sa_slotid = slotid; 557 args->sa_slotid = slotid;
@@ -495,8 +560,9 @@ static int nfs41_setup_sequence(struct nfs4_session *session,
495 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); 560 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
496 561
497 res->sr_session = session; 562 res->sr_session = session;
498 res->sr_slotid = slotid; 563 res->sr_slot = slot;
499 res->sr_renewal_time = jiffies; 564 res->sr_renewal_time = jiffies;
565 res->sr_status_flags = 0;
500 /* 566 /*
501 * sr_status is only set in decode_sequence, and so will remain 567 * sr_status is only set in decode_sequence, and so will remain
502 * set to 1 if an rpc level failure occurs. 568 * set to 1 if an rpc level failure occurs.
@@ -505,33 +571,34 @@ static int nfs41_setup_sequence(struct nfs4_session *session,
505 return 0; 571 return 0;
506} 572}
507 573
508int nfs4_setup_sequence(struct nfs_client *clp, 574int nfs4_setup_sequence(const struct nfs_server *server,
509 struct nfs4_sequence_args *args, 575 struct nfs4_sequence_args *args,
510 struct nfs4_sequence_res *res, 576 struct nfs4_sequence_res *res,
511 int cache_reply, 577 int cache_reply,
512 struct rpc_task *task) 578 struct rpc_task *task)
513{ 579{
580 struct nfs4_session *session = nfs4_get_session(server);
514 int ret = 0; 581 int ret = 0;
515 582
516 dprintk("--> %s clp %p session %p sr_slotid %d\n", 583 if (session == NULL) {
517 __func__, clp, clp->cl_session, res->sr_slotid); 584 args->sa_session = NULL;
518 585 res->sr_session = NULL;
519 if (!nfs4_has_session(clp))
520 goto out; 586 goto out;
521 ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply,
522 task);
523 if (ret != -EAGAIN) {
524 /* terminate rpc task */
525 task->tk_status = ret;
526 task->tk_action = NULL;
527 } 587 }
588
589 dprintk("--> %s clp %p session %p sr_slot %td\n",
590 __func__, session->clp, session, res->sr_slot ?
591 res->sr_slot - session->fc_slot_table.slots : -1);
592
593 ret = nfs41_setup_sequence(session, args, res, cache_reply,
594 task);
528out: 595out:
529 dprintk("<-- %s status=%d\n", __func__, ret); 596 dprintk("<-- %s status=%d\n", __func__, ret);
530 return ret; 597 return ret;
531} 598}
532 599
533struct nfs41_call_sync_data { 600struct nfs41_call_sync_data {
534 struct nfs_client *clp; 601 const struct nfs_server *seq_server;
535 struct nfs4_sequence_args *seq_args; 602 struct nfs4_sequence_args *seq_args;
536 struct nfs4_sequence_res *seq_res; 603 struct nfs4_sequence_res *seq_res;
537 int cache_reply; 604 int cache_reply;
@@ -541,20 +608,25 @@ static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
541{ 608{
542 struct nfs41_call_sync_data *data = calldata; 609 struct nfs41_call_sync_data *data = calldata;
543 610
544 dprintk("--> %s data->clp->cl_session %p\n", __func__, 611 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
545 data->clp->cl_session); 612
546 if (nfs4_setup_sequence(data->clp, data->seq_args, 613 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
547 data->seq_res, data->cache_reply, task)) 614 data->seq_res, data->cache_reply, task))
548 return; 615 return;
549 rpc_call_start(task); 616 rpc_call_start(task);
550} 617}
551 618
619static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
620{
621 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
622 nfs41_call_sync_prepare(task, calldata);
623}
624
552static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) 625static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
553{ 626{
554 struct nfs41_call_sync_data *data = calldata; 627 struct nfs41_call_sync_data *data = calldata;
555 628
556 nfs41_sequence_done(data->clp, data->seq_res, task->tk_status); 629 nfs41_sequence_done(task, data->seq_res);
557 nfs41_sequence_free_slot(data->clp, data->seq_res);
558} 630}
559 631
560struct rpc_call_ops nfs41_call_sync_ops = { 632struct rpc_call_ops nfs41_call_sync_ops = {
@@ -562,29 +634,36 @@ struct rpc_call_ops nfs41_call_sync_ops = {
562 .rpc_call_done = nfs41_call_sync_done, 634 .rpc_call_done = nfs41_call_sync_done,
563}; 635};
564 636
565static int nfs4_call_sync_sequence(struct nfs_client *clp, 637struct rpc_call_ops nfs41_call_priv_sync_ops = {
566 struct rpc_clnt *clnt, 638 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
639 .rpc_call_done = nfs41_call_sync_done,
640};
641
642static int nfs4_call_sync_sequence(struct nfs_server *server,
567 struct rpc_message *msg, 643 struct rpc_message *msg,
568 struct nfs4_sequence_args *args, 644 struct nfs4_sequence_args *args,
569 struct nfs4_sequence_res *res, 645 struct nfs4_sequence_res *res,
570 int cache_reply) 646 int cache_reply,
647 int privileged)
571{ 648{
572 int ret; 649 int ret;
573 struct rpc_task *task; 650 struct rpc_task *task;
574 struct nfs41_call_sync_data data = { 651 struct nfs41_call_sync_data data = {
575 .clp = clp, 652 .seq_server = server,
576 .seq_args = args, 653 .seq_args = args,
577 .seq_res = res, 654 .seq_res = res,
578 .cache_reply = cache_reply, 655 .cache_reply = cache_reply,
579 }; 656 };
580 struct rpc_task_setup task_setup = { 657 struct rpc_task_setup task_setup = {
581 .rpc_client = clnt, 658 .rpc_client = server->client,
582 .rpc_message = msg, 659 .rpc_message = msg,
583 .callback_ops = &nfs41_call_sync_ops, 660 .callback_ops = &nfs41_call_sync_ops,
584 .callback_data = &data 661 .callback_data = &data
585 }; 662 };
586 663
587 res->sr_slotid = NFS4_MAX_SLOT_TABLE; 664 res->sr_slot = NULL;
665 if (privileged)
666 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
588 task = rpc_run_task(&task_setup); 667 task = rpc_run_task(&task_setup);
589 if (IS_ERR(task)) 668 if (IS_ERR(task))
590 ret = PTR_ERR(task); 669 ret = PTR_ERR(task);
@@ -601,10 +680,15 @@ int _nfs4_call_sync_session(struct nfs_server *server,
601 struct nfs4_sequence_res *res, 680 struct nfs4_sequence_res *res,
602 int cache_reply) 681 int cache_reply)
603{ 682{
604 return nfs4_call_sync_sequence(server->nfs_client, server->client, 683 return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0);
605 msg, args, res, cache_reply);
606} 684}
607 685
686#else
687static int nfs4_sequence_done(struct rpc_task *task,
688 struct nfs4_sequence_res *res)
689{
690 return 1;
691}
608#endif /* CONFIG_NFS_V4_1 */ 692#endif /* CONFIG_NFS_V4_1 */
609 693
610int _nfs4_call_sync(struct nfs_server *server, 694int _nfs4_call_sync(struct nfs_server *server,
@@ -618,27 +702,9 @@ int _nfs4_call_sync(struct nfs_server *server,
618} 702}
619 703
620#define nfs4_call_sync(server, msg, args, res, cache_reply) \ 704#define nfs4_call_sync(server, msg, args, res, cache_reply) \
621 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \ 705 (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \
622 &(res)->seq_res, (cache_reply)) 706 &(res)->seq_res, (cache_reply))
623 707
624static void nfs4_sequence_done(const struct nfs_server *server,
625 struct nfs4_sequence_res *res, int rpc_status)
626{
627#ifdef CONFIG_NFS_V4_1
628 if (nfs4_has_session(server->nfs_client))
629 nfs41_sequence_done(server->nfs_client, res, rpc_status);
630#endif /* CONFIG_NFS_V4_1 */
631}
632
633/* no restart, therefore free slot here */
634static void nfs4_sequence_done_free_slot(const struct nfs_server *server,
635 struct nfs4_sequence_res *res,
636 int rpc_status)
637{
638 nfs4_sequence_done(server, res, rpc_status);
639 nfs4_sequence_free_slot(server->nfs_client, res);
640}
641
642static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) 708static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
643{ 709{
644 struct nfs_inode *nfsi = NFS_I(dir); 710 struct nfs_inode *nfsi = NFS_I(dir);
@@ -680,26 +746,26 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p)
680 p->o_res.server = p->o_arg.server; 746 p->o_res.server = p->o_arg.server;
681 nfs_fattr_init(&p->f_attr); 747 nfs_fattr_init(&p->f_attr);
682 nfs_fattr_init(&p->dir_attr); 748 nfs_fattr_init(&p->dir_attr);
683 p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
684} 749}
685 750
686static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, 751static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
687 struct nfs4_state_owner *sp, fmode_t fmode, int flags, 752 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
688 const struct iattr *attrs) 753 const struct iattr *attrs,
754 gfp_t gfp_mask)
689{ 755{
690 struct dentry *parent = dget_parent(path->dentry); 756 struct dentry *parent = dget_parent(path->dentry);
691 struct inode *dir = parent->d_inode; 757 struct inode *dir = parent->d_inode;
692 struct nfs_server *server = NFS_SERVER(dir); 758 struct nfs_server *server = NFS_SERVER(dir);
693 struct nfs4_opendata *p; 759 struct nfs4_opendata *p;
694 760
695 p = kzalloc(sizeof(*p), GFP_KERNEL); 761 p = kzalloc(sizeof(*p), gfp_mask);
696 if (p == NULL) 762 if (p == NULL)
697 goto err; 763 goto err;
698 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); 764 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
699 if (p->o_arg.seqid == NULL) 765 if (p->o_arg.seqid == NULL)
700 goto err_free; 766 goto err_free;
701 p->path.mnt = mntget(path->mnt); 767 path_get(path);
702 p->path.dentry = dget(path->dentry); 768 p->path = *path;
703 p->dir = parent; 769 p->dir = parent;
704 p->owner = sp; 770 p->owner = sp;
705 atomic_inc(&sp->so_count); 771 atomic_inc(&sp->so_count);
@@ -712,13 +778,14 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
712 p->o_arg.server = server; 778 p->o_arg.server = server;
713 p->o_arg.bitmask = server->attr_bitmask; 779 p->o_arg.bitmask = server->attr_bitmask;
714 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; 780 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
715 if (flags & O_EXCL) { 781 if (flags & O_CREAT) {
716 u32 *s = (u32 *) p->o_arg.u.verifier.data; 782 u32 *s;
717 s[0] = jiffies; 783
718 s[1] = current->pid;
719 } else if (flags & O_CREAT) {
720 p->o_arg.u.attrs = &p->attrs; 784 p->o_arg.u.attrs = &p->attrs;
721 memcpy(&p->attrs, attrs, sizeof(p->attrs)); 785 memcpy(&p->attrs, attrs, sizeof(p->attrs));
786 s = (u32 *) p->o_arg.u.verifier.data;
787 s[0] = jiffies;
788 s[1] = current->pid;
722 } 789 }
723 p->c_arg.fh = &p->o_res.fh; 790 p->c_arg.fh = &p->o_res.fh;
724 p->c_arg.stateid = &p->o_res.stateid; 791 p->c_arg.stateid = &p->o_res.stateid;
@@ -769,13 +836,16 @@ static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode
769 goto out; 836 goto out;
770 switch (mode & (FMODE_READ|FMODE_WRITE)) { 837 switch (mode & (FMODE_READ|FMODE_WRITE)) {
771 case FMODE_READ: 838 case FMODE_READ:
772 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0; 839 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
840 && state->n_rdonly != 0;
773 break; 841 break;
774 case FMODE_WRITE: 842 case FMODE_WRITE:
775 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0; 843 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
844 && state->n_wronly != 0;
776 break; 845 break;
777 case FMODE_READ|FMODE_WRITE: 846 case FMODE_READ|FMODE_WRITE:
778 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0; 847 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
848 && state->n_rdwr != 0;
779 } 849 }
780out: 850out:
781 return ret; 851 return ret;
@@ -1022,7 +1092,7 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context
1022{ 1092{
1023 struct nfs4_opendata *opendata; 1093 struct nfs4_opendata *opendata;
1024 1094
1025 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL); 1095 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS);
1026 if (opendata == NULL) 1096 if (opendata == NULL)
1027 return ERR_PTR(-ENOMEM); 1097 return ERR_PTR(-ENOMEM);
1028 opendata->state = state; 1098 opendata->state = state;
@@ -1040,7 +1110,7 @@ static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmod
1040 memset(&opendata->o_res, 0, sizeof(opendata->o_res)); 1110 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1041 memset(&opendata->c_res, 0, sizeof(opendata->c_res)); 1111 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1042 nfs4_init_opendata_res(opendata); 1112 nfs4_init_opendata_res(opendata);
1043 ret = _nfs4_proc_open(opendata); 1113 ret = _nfs4_recover_proc_open(opendata);
1044 if (ret != 0) 1114 if (ret != 0)
1045 return ret; 1115 return ret;
1046 newstate = nfs4_opendata_to_nfs4_state(opendata); 1116 newstate = nfs4_opendata_to_nfs4_state(opendata);
@@ -1060,6 +1130,7 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
1060 clear_bit(NFS_DELEGATED_STATE, &state->flags); 1130 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1061 smp_rmb(); 1131 smp_rmb();
1062 if (state->n_rdwr != 0) { 1132 if (state->n_rdwr != 0) {
1133 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1063 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); 1134 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1064 if (ret != 0) 1135 if (ret != 0)
1065 return ret; 1136 return ret;
@@ -1067,6 +1138,7 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
1067 return -ESTALE; 1138 return -ESTALE;
1068 } 1139 }
1069 if (state->n_wronly != 0) { 1140 if (state->n_wronly != 0) {
1141 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1070 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); 1142 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1071 if (ret != 0) 1143 if (ret != 0)
1072 return ret; 1144 return ret;
@@ -1074,6 +1146,7 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
1074 return -ESTALE; 1146 return -ESTALE;
1075 } 1147 }
1076 if (state->n_rdonly != 0) { 1148 if (state->n_rdonly != 0) {
1149 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1077 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); 1150 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1078 if (ret != 0) 1151 if (ret != 0)
1079 return ret; 1152 return ret;
@@ -1176,6 +1249,14 @@ int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state
1176 case -ENOENT: 1249 case -ENOENT:
1177 case -ESTALE: 1250 case -ESTALE:
1178 goto out; 1251 goto out;
1252 case -NFS4ERR_BADSESSION:
1253 case -NFS4ERR_BADSLOT:
1254 case -NFS4ERR_BAD_HIGH_SLOT:
1255 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1256 case -NFS4ERR_DEADSESSION:
1257 nfs4_schedule_state_recovery(
1258 server->nfs_client);
1259 goto out;
1179 case -NFS4ERR_STALE_CLIENTID: 1260 case -NFS4ERR_STALE_CLIENTID:
1180 case -NFS4ERR_STALE_STATEID: 1261 case -NFS4ERR_STALE_STATEID:
1181 case -NFS4ERR_EXPIRED: 1262 case -NFS4ERR_EXPIRED:
@@ -1190,6 +1271,13 @@ int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state
1190 case -NFS4ERR_ADMIN_REVOKED: 1271 case -NFS4ERR_ADMIN_REVOKED:
1191 case -NFS4ERR_BAD_STATEID: 1272 case -NFS4ERR_BAD_STATEID:
1192 nfs4_state_mark_reclaim_nograce(server->nfs_client, state); 1273 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
1274 case -EKEYEXPIRED:
1275 /*
1276 * User RPCSEC_GSS context has expired.
1277 * We cannot recover this stateid now, so
1278 * skip it and allow recovery thread to
1279 * proceed.
1280 */
1193 case -ENOMEM: 1281 case -ENOMEM:
1194 err = 0; 1282 err = 0;
1195 goto out; 1283 goto out;
@@ -1205,8 +1293,6 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1205 struct nfs4_opendata *data = calldata; 1293 struct nfs4_opendata *data = calldata;
1206 1294
1207 data->rpc_status = task->tk_status; 1295 data->rpc_status = task->tk_status;
1208 if (RPC_ASSASSINATED(task))
1209 return;
1210 if (data->rpc_status == 0) { 1296 if (data->rpc_status == 0) {
1211 memcpy(data->o_res.stateid.data, data->c_res.stateid.data, 1297 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
1212 sizeof(data->o_res.stateid.data)); 1298 sizeof(data->o_res.stateid.data));
@@ -1306,13 +1392,13 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1306 } 1392 }
1307 /* Update sequence id. */ 1393 /* Update sequence id. */
1308 data->o_arg.id = sp->so_owner_id.id; 1394 data->o_arg.id = sp->so_owner_id.id;
1309 data->o_arg.clientid = sp->so_client->cl_clientid; 1395 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1310 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { 1396 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1311 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; 1397 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1312 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); 1398 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1313 } 1399 }
1314 data->timestamp = jiffies; 1400 data->timestamp = jiffies;
1315 if (nfs4_setup_sequence(data->o_arg.server->nfs_client, 1401 if (nfs4_setup_sequence(data->o_arg.server,
1316 &data->o_arg.seq_args, 1402 &data->o_arg.seq_args,
1317 &data->o_res.seq_res, 1, task)) 1403 &data->o_res.seq_res, 1, task))
1318 return; 1404 return;
@@ -1323,17 +1409,21 @@ out_no_action:
1323 1409
1324} 1410}
1325 1411
1412static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1413{
1414 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1415 nfs4_open_prepare(task, calldata);
1416}
1417
1326static void nfs4_open_done(struct rpc_task *task, void *calldata) 1418static void nfs4_open_done(struct rpc_task *task, void *calldata)
1327{ 1419{
1328 struct nfs4_opendata *data = calldata; 1420 struct nfs4_opendata *data = calldata;
1329 1421
1330 data->rpc_status = task->tk_status; 1422 data->rpc_status = task->tk_status;
1331 1423
1332 nfs4_sequence_done_free_slot(data->o_arg.server, &data->o_res.seq_res, 1424 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1333 task->tk_status);
1334
1335 if (RPC_ASSASSINATED(task))
1336 return; 1425 return;
1426
1337 if (task->tk_status == 0) { 1427 if (task->tk_status == 0) {
1338 switch (data->o_res.f_attr->mode & S_IFMT) { 1428 switch (data->o_res.f_attr->mode & S_IFMT) {
1339 case S_IFREG: 1429 case S_IFREG:
@@ -1381,10 +1471,13 @@ static const struct rpc_call_ops nfs4_open_ops = {
1381 .rpc_release = nfs4_open_release, 1471 .rpc_release = nfs4_open_release,
1382}; 1472};
1383 1473
1384/* 1474static const struct rpc_call_ops nfs4_recover_open_ops = {
1385 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata 1475 .rpc_call_prepare = nfs4_recover_open_prepare,
1386 */ 1476 .rpc_call_done = nfs4_open_done,
1387static int _nfs4_proc_open(struct nfs4_opendata *data) 1477 .rpc_release = nfs4_open_release,
1478};
1479
1480static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1388{ 1481{
1389 struct inode *dir = data->dir->d_inode; 1482 struct inode *dir = data->dir->d_inode;
1390 struct nfs_server *server = NFS_SERVER(dir); 1483 struct nfs_server *server = NFS_SERVER(dir);
@@ -1411,27 +1504,65 @@ static int _nfs4_proc_open(struct nfs4_opendata *data)
1411 data->rpc_done = 0; 1504 data->rpc_done = 0;
1412 data->rpc_status = 0; 1505 data->rpc_status = 0;
1413 data->cancelled = 0; 1506 data->cancelled = 0;
1507 if (isrecover)
1508 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1414 task = rpc_run_task(&task_setup_data); 1509 task = rpc_run_task(&task_setup_data);
1415 if (IS_ERR(task)) 1510 if (IS_ERR(task))
1416 return PTR_ERR(task); 1511 return PTR_ERR(task);
1417 status = nfs4_wait_for_completion_rpc_task(task); 1512 status = nfs4_wait_for_completion_rpc_task(task);
1418 if (status != 0) { 1513 if (status != 0) {
1419 data->cancelled = 1; 1514 data->cancelled = 1;
1420 smp_wmb(); 1515 smp_wmb();
1421 } else 1516 } else
1422 status = data->rpc_status; 1517 status = data->rpc_status;
1423 rpc_put_task(task); 1518 rpc_put_task(task);
1519
1520 return status;
1521}
1522
1523static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1524{
1525 struct inode *dir = data->dir->d_inode;
1526 struct nfs_openres *o_res = &data->o_res;
1527 int status;
1528
1529 status = nfs4_run_open_task(data, 1);
1424 if (status != 0 || !data->rpc_done) 1530 if (status != 0 || !data->rpc_done)
1425 return status; 1531 return status;
1426 1532
1427 if (o_res->fh.size == 0) 1533 nfs_refresh_inode(dir, o_res->dir_attr);
1428 _nfs4_proc_lookup(dir, o_arg->name, &o_res->fh, o_res->f_attr); 1534
1535 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1536 status = _nfs4_proc_open_confirm(data);
1537 if (status != 0)
1538 return status;
1539 }
1540
1541 return status;
1542}
1543
1544/*
1545 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1546 */
1547static int _nfs4_proc_open(struct nfs4_opendata *data)
1548{
1549 struct inode *dir = data->dir->d_inode;
1550 struct nfs_server *server = NFS_SERVER(dir);
1551 struct nfs_openargs *o_arg = &data->o_arg;
1552 struct nfs_openres *o_res = &data->o_res;
1553 int status;
1554
1555 status = nfs4_run_open_task(data, 0);
1556 if (status != 0 || !data->rpc_done)
1557 return status;
1429 1558
1430 if (o_arg->open_flags & O_CREAT) { 1559 if (o_arg->open_flags & O_CREAT) {
1431 update_changeattr(dir, &o_res->cinfo); 1560 update_changeattr(dir, &o_res->cinfo);
1432 nfs_post_op_update_inode(dir, o_res->dir_attr); 1561 nfs_post_op_update_inode(dir, o_res->dir_attr);
1433 } else 1562 } else
1434 nfs_refresh_inode(dir, o_res->dir_attr); 1563 nfs_refresh_inode(dir, o_res->dir_attr);
1564 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1565 server->caps &= ~NFS_CAP_POSIX_LOCK;
1435 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { 1566 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1436 status = _nfs4_proc_open_confirm(data); 1567 status = _nfs4_proc_open_confirm(data);
1437 if (status != 0) 1568 if (status != 0)
@@ -1445,18 +1576,20 @@ static int _nfs4_proc_open(struct nfs4_opendata *data)
1445static int nfs4_recover_expired_lease(struct nfs_server *server) 1576static int nfs4_recover_expired_lease(struct nfs_server *server)
1446{ 1577{
1447 struct nfs_client *clp = server->nfs_client; 1578 struct nfs_client *clp = server->nfs_client;
1579 unsigned int loop;
1448 int ret; 1580 int ret;
1449 1581
1450 for (;;) { 1582 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1451 ret = nfs4_wait_clnt_recover(clp); 1583 ret = nfs4_wait_clnt_recover(clp);
1452 if (ret != 0) 1584 if (ret != 0)
1453 return ret; 1585 break;
1454 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && 1586 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1455 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) 1587 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1456 break; 1588 break;
1457 nfs4_schedule_state_recovery(clp); 1589 nfs4_schedule_state_recovery(clp);
1590 ret = -EIO;
1458 } 1591 }
1459 return 0; 1592 return ret;
1460} 1593}
1461 1594
1462/* 1595/*
@@ -1479,7 +1612,7 @@ static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *s
1479 return ret; 1612 return ret;
1480} 1613}
1481 1614
1482static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) 1615static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1483{ 1616{
1484 struct nfs_server *server = NFS_SERVER(state->inode); 1617 struct nfs_server *server = NFS_SERVER(state->inode);
1485 struct nfs4_exception exception = { }; 1618 struct nfs4_exception exception = { };
@@ -1487,10 +1620,16 @@ static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4
1487 1620
1488 do { 1621 do {
1489 err = _nfs4_open_expired(ctx, state); 1622 err = _nfs4_open_expired(ctx, state);
1490 if (err != -NFS4ERR_DELAY) 1623 switch (err) {
1491 break; 1624 default:
1492 nfs4_handle_exception(server, err, &exception); 1625 goto out;
1626 case -NFS4ERR_GRACE:
1627 case -NFS4ERR_DELAY:
1628 nfs4_handle_exception(server, err, &exception);
1629 err = 0;
1630 }
1493 } while (exception.retry); 1631 } while (exception.retry);
1632out:
1494 return err; 1633 return err;
1495} 1634}
1496 1635
@@ -1546,7 +1685,7 @@ static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, in
1546 if (path->dentry->d_inode != NULL) 1685 if (path->dentry->d_inode != NULL)
1547 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); 1686 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
1548 status = -ENOMEM; 1687 status = -ENOMEM;
1549 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr); 1688 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL);
1550 if (opendata == NULL) 1689 if (opendata == NULL)
1551 goto err_put_state_owner; 1690 goto err_put_state_owner;
1552 1691
@@ -1557,13 +1696,24 @@ static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, in
1557 if (status != 0) 1696 if (status != 0)
1558 goto err_opendata_put; 1697 goto err_opendata_put;
1559 1698
1560 if (opendata->o_arg.open_flags & O_EXCL)
1561 nfs4_exclusive_attrset(opendata, sattr);
1562
1563 state = nfs4_opendata_to_nfs4_state(opendata); 1699 state = nfs4_opendata_to_nfs4_state(opendata);
1564 status = PTR_ERR(state); 1700 status = PTR_ERR(state);
1565 if (IS_ERR(state)) 1701 if (IS_ERR(state))
1566 goto err_opendata_put; 1702 goto err_opendata_put;
1703 if (server->caps & NFS_CAP_POSIX_LOCK)
1704 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1705
1706 if (opendata->o_arg.open_flags & O_EXCL) {
1707 nfs4_exclusive_attrset(opendata, sattr);
1708
1709 nfs_fattr_init(opendata->o_res.f_attr);
1710 status = nfs4_do_setattr(state->inode, cred,
1711 opendata->o_res.f_attr, sattr,
1712 state);
1713 if (status == 0)
1714 nfs_setattr_update_inode(state->inode, sattr);
1715 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
1716 }
1567 nfs4_opendata_put(opendata); 1717 nfs4_opendata_put(opendata);
1568 nfs4_put_state_owner(sp); 1718 nfs4_put_state_owner(sp);
1569 *res = state; 1719 *res = state;
@@ -1656,7 +1806,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1656 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { 1806 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1657 /* Use that stateid */ 1807 /* Use that stateid */
1658 } else if (state != NULL) { 1808 } else if (state != NULL) {
1659 nfs4_copy_stateid(&arg.stateid, state, current->files); 1809 nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid);
1660 } else 1810 } else
1661 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); 1811 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
1662 1812
@@ -1689,6 +1839,8 @@ struct nfs4_closedata {
1689 struct nfs_closeres res; 1839 struct nfs_closeres res;
1690 struct nfs_fattr fattr; 1840 struct nfs_fattr fattr;
1691 unsigned long timestamp; 1841 unsigned long timestamp;
1842 bool roc;
1843 u32 roc_barrier;
1692}; 1844};
1693 1845
1694static void nfs4_free_closedata(void *data) 1846static void nfs4_free_closedata(void *data)
@@ -1696,6 +1848,8 @@ static void nfs4_free_closedata(void *data)
1696 struct nfs4_closedata *calldata = data; 1848 struct nfs4_closedata *calldata = data;
1697 struct nfs4_state_owner *sp = calldata->state->owner; 1849 struct nfs4_state_owner *sp = calldata->state->owner;
1698 1850
1851 if (calldata->roc)
1852 pnfs_roc_release(calldata->state->inode);
1699 nfs4_put_open_state(calldata->state); 1853 nfs4_put_open_state(calldata->state);
1700 nfs_free_seqid(calldata->arg.seqid); 1854 nfs_free_seqid(calldata->arg.seqid);
1701 nfs4_put_state_owner(sp); 1855 nfs4_put_state_owner(sp);
@@ -1703,22 +1857,38 @@ static void nfs4_free_closedata(void *data)
1703 kfree(calldata); 1857 kfree(calldata);
1704} 1858}
1705 1859
1860static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
1861 fmode_t fmode)
1862{
1863 spin_lock(&state->owner->so_lock);
1864 if (!(fmode & FMODE_READ))
1865 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1866 if (!(fmode & FMODE_WRITE))
1867 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1868 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1869 spin_unlock(&state->owner->so_lock);
1870}
1871
1706static void nfs4_close_done(struct rpc_task *task, void *data) 1872static void nfs4_close_done(struct rpc_task *task, void *data)
1707{ 1873{
1708 struct nfs4_closedata *calldata = data; 1874 struct nfs4_closedata *calldata = data;
1709 struct nfs4_state *state = calldata->state; 1875 struct nfs4_state *state = calldata->state;
1710 struct nfs_server *server = NFS_SERVER(calldata->inode); 1876 struct nfs_server *server = NFS_SERVER(calldata->inode);
1711 1877
1712 nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status); 1878 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
1713 if (RPC_ASSASSINATED(task))
1714 return; 1879 return;
1715 /* hmm. we are done with the inode, and in the process of freeing 1880 /* hmm. we are done with the inode, and in the process of freeing
1716 * the state_owner. we keep this around to process errors 1881 * the state_owner. we keep this around to process errors
1717 */ 1882 */
1718 switch (task->tk_status) { 1883 switch (task->tk_status) {
1719 case 0: 1884 case 0:
1885 if (calldata->roc)
1886 pnfs_roc_set_barrier(state->inode,
1887 calldata->roc_barrier);
1720 nfs_set_open_stateid(state, &calldata->res.stateid, 0); 1888 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
1721 renew_lease(server, calldata->timestamp); 1889 renew_lease(server, calldata->timestamp);
1890 nfs4_close_clear_stateid_flags(state,
1891 calldata->arg.fmode);
1722 break; 1892 break;
1723 case -NFS4ERR_STALE_STATEID: 1893 case -NFS4ERR_STALE_STATEID:
1724 case -NFS4ERR_OLD_STATEID: 1894 case -NFS4ERR_OLD_STATEID:
@@ -1727,12 +1897,10 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
1727 if (calldata->arg.fmode == 0) 1897 if (calldata->arg.fmode == 0)
1728 break; 1898 break;
1729 default: 1899 default:
1730 if (nfs4_async_handle_error(task, server, state) == -EAGAIN) { 1900 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
1731 nfs4_restart_rpc(task, server->nfs_client); 1901 rpc_restart_call_prepare(task);
1732 return;
1733 }
1734 } 1902 }
1735 nfs4_sequence_free_slot(server->nfs_client, &calldata->res.seq_res); 1903 nfs_release_seqid(calldata->arg.seqid);
1736 nfs_refresh_inode(calldata->inode, calldata->res.fattr); 1904 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
1737} 1905}
1738 1906
@@ -1740,40 +1908,48 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
1740{ 1908{
1741 struct nfs4_closedata *calldata = data; 1909 struct nfs4_closedata *calldata = data;
1742 struct nfs4_state *state = calldata->state; 1910 struct nfs4_state *state = calldata->state;
1743 int clear_rd, clear_wr, clear_rdwr; 1911 int call_close = 0;
1744 1912
1745 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) 1913 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1746 return; 1914 return;
1747 1915
1748 clear_rd = clear_wr = clear_rdwr = 0; 1916 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
1917 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
1749 spin_lock(&state->owner->so_lock); 1918 spin_lock(&state->owner->so_lock);
1750 /* Calculate the change in open mode */ 1919 /* Calculate the change in open mode */
1751 if (state->n_rdwr == 0) { 1920 if (state->n_rdwr == 0) {
1752 if (state->n_rdonly == 0) { 1921 if (state->n_rdonly == 0) {
1753 clear_rd |= test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags); 1922 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
1754 clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags); 1923 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1924 calldata->arg.fmode &= ~FMODE_READ;
1755 } 1925 }
1756 if (state->n_wronly == 0) { 1926 if (state->n_wronly == 0) {
1757 clear_wr |= test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags); 1927 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
1758 clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags); 1928 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1929 calldata->arg.fmode &= ~FMODE_WRITE;
1759 } 1930 }
1760 } 1931 }
1761 spin_unlock(&state->owner->so_lock); 1932 spin_unlock(&state->owner->so_lock);
1762 if (!clear_rd && !clear_wr && !clear_rdwr) { 1933
1934 if (!call_close) {
1763 /* Note: exit _without_ calling nfs4_close_done */ 1935 /* Note: exit _without_ calling nfs4_close_done */
1764 task->tk_action = NULL; 1936 task->tk_action = NULL;
1765 return; 1937 return;
1766 } 1938 }
1767 nfs_fattr_init(calldata->res.fattr); 1939
1768 if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0) { 1940 if (calldata->arg.fmode == 0) {
1769 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; 1941 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
1770 calldata->arg.fmode = FMODE_READ; 1942 if (calldata->roc &&
1771 } else if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0) { 1943 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) {
1772 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; 1944 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq,
1773 calldata->arg.fmode = FMODE_WRITE; 1945 task, NULL);
1946 return;
1947 }
1774 } 1948 }
1949
1950 nfs_fattr_init(calldata->res.fattr);
1775 calldata->timestamp = jiffies; 1951 calldata->timestamp = jiffies;
1776 if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client, 1952 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode),
1777 &calldata->arg.seq_args, &calldata->res.seq_res, 1953 &calldata->arg.seq_args, &calldata->res.seq_res,
1778 1, task)) 1954 1, task))
1779 return; 1955 return;
@@ -1797,7 +1973,7 @@ static const struct rpc_call_ops nfs4_close_ops = {
1797 * 1973 *
1798 * NOTE: Caller must be holding the sp->so_owner semaphore! 1974 * NOTE: Caller must be holding the sp->so_owner semaphore!
1799 */ 1975 */
1800int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait) 1976int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc)
1801{ 1977{
1802 struct nfs_server *server = NFS_SERVER(state->inode); 1978 struct nfs_server *server = NFS_SERVER(state->inode);
1803 struct nfs4_closedata *calldata; 1979 struct nfs4_closedata *calldata;
@@ -1816,17 +1992,15 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1816 }; 1992 };
1817 int status = -ENOMEM; 1993 int status = -ENOMEM;
1818 1994
1819 calldata = kzalloc(sizeof(*calldata), GFP_KERNEL); 1995 calldata = kzalloc(sizeof(*calldata), gfp_mask);
1820 if (calldata == NULL) 1996 if (calldata == NULL)
1821 goto out; 1997 goto out;
1822 calldata->inode = state->inode; 1998 calldata->inode = state->inode;
1823 calldata->state = state; 1999 calldata->state = state;
1824 calldata->arg.fh = NFS_FH(state->inode); 2000 calldata->arg.fh = NFS_FH(state->inode);
1825 calldata->arg.stateid = &state->open_stateid; 2001 calldata->arg.stateid = &state->open_stateid;
1826 if (nfs4_has_session(server->nfs_client))
1827 memset(calldata->arg.stateid->data, 0, 4); /* clear seqid */
1828 /* Serialization for the sequence id */ 2002 /* Serialization for the sequence id */
1829 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); 2003 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
1830 if (calldata->arg.seqid == NULL) 2004 if (calldata->arg.seqid == NULL)
1831 goto out_free_calldata; 2005 goto out_free_calldata;
1832 calldata->arg.fmode = 0; 2006 calldata->arg.fmode = 0;
@@ -1834,12 +2008,12 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1834 calldata->res.fattr = &calldata->fattr; 2008 calldata->res.fattr = &calldata->fattr;
1835 calldata->res.seqid = calldata->arg.seqid; 2009 calldata->res.seqid = calldata->arg.seqid;
1836 calldata->res.server = server; 2010 calldata->res.server = server;
1837 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; 2011 calldata->roc = roc;
1838 calldata->path.mnt = mntget(path->mnt); 2012 path_get(path);
1839 calldata->path.dentry = dget(path->dentry); 2013 calldata->path = *path;
1840 2014
1841 msg.rpc_argp = &calldata->arg, 2015 msg.rpc_argp = &calldata->arg;
1842 msg.rpc_resp = &calldata->res, 2016 msg.rpc_resp = &calldata->res;
1843 task_setup_data.callback_data = calldata; 2017 task_setup_data.callback_data = calldata;
1844 task = rpc_run_task(&task_setup_data); 2018 task = rpc_run_task(&task_setup_data);
1845 if (IS_ERR(task)) 2019 if (IS_ERR(task))
@@ -1852,127 +2026,27 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1852out_free_calldata: 2026out_free_calldata:
1853 kfree(calldata); 2027 kfree(calldata);
1854out: 2028out:
2029 if (roc)
2030 pnfs_roc_release(state->inode);
1855 nfs4_put_open_state(state); 2031 nfs4_put_open_state(state);
1856 nfs4_put_state_owner(sp); 2032 nfs4_put_state_owner(sp);
1857 return status; 2033 return status;
1858} 2034}
1859 2035
1860static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode) 2036static struct inode *
2037nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
1861{ 2038{
1862 struct file *filp;
1863 int ret;
1864
1865 /* If the open_intent is for execute, we have an extra check to make */
1866 if (fmode & FMODE_EXEC) {
1867 ret = nfs_may_open(state->inode,
1868 state->owner->so_cred,
1869 nd->intent.open.flags);
1870 if (ret < 0)
1871 goto out_close;
1872 }
1873 filp = lookup_instantiate_filp(nd, path->dentry, NULL);
1874 if (!IS_ERR(filp)) {
1875 struct nfs_open_context *ctx;
1876 ctx = nfs_file_open_context(filp);
1877 ctx->state = state;
1878 return 0;
1879 }
1880 ret = PTR_ERR(filp);
1881out_close:
1882 nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE));
1883 return ret;
1884}
1885
1886struct dentry *
1887nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1888{
1889 struct path path = {
1890 .mnt = nd->path.mnt,
1891 .dentry = dentry,
1892 };
1893 struct dentry *parent;
1894 struct iattr attr;
1895 struct rpc_cred *cred;
1896 struct nfs4_state *state; 2039 struct nfs4_state *state;
1897 struct dentry *res;
1898 fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
1899
1900 if (nd->flags & LOOKUP_CREATE) {
1901 attr.ia_mode = nd->intent.open.create_mode;
1902 attr.ia_valid = ATTR_MODE;
1903 if (!IS_POSIXACL(dir))
1904 attr.ia_mode &= ~current_umask();
1905 } else {
1906 attr.ia_valid = 0;
1907 BUG_ON(nd->intent.open.flags & O_CREAT);
1908 }
1909 2040
1910 cred = rpc_lookup_cred();
1911 if (IS_ERR(cred))
1912 return (struct dentry *)cred;
1913 parent = dentry->d_parent;
1914 /* Protect against concurrent sillydeletes */ 2041 /* Protect against concurrent sillydeletes */
1915 nfs_block_sillyrename(parent); 2042 state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred);
1916 state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred); 2043 if (IS_ERR(state))
1917 put_rpccred(cred); 2044 return ERR_CAST(state);
1918 if (IS_ERR(state)) { 2045 ctx->state = state;
1919 if (PTR_ERR(state) == -ENOENT) { 2046 return igrab(state->inode);
1920 d_add(dentry, NULL);
1921 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1922 }
1923 nfs_unblock_sillyrename(parent);
1924 return (struct dentry *)state;
1925 }
1926 res = d_add_unique(dentry, igrab(state->inode));
1927 if (res != NULL)
1928 path.dentry = res;
1929 nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir));
1930 nfs_unblock_sillyrename(parent);
1931 nfs4_intent_set_file(nd, &path, state, fmode);
1932 return res;
1933}
1934
1935int
1936nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
1937{
1938 struct path path = {
1939 .mnt = nd->path.mnt,
1940 .dentry = dentry,
1941 };
1942 struct rpc_cred *cred;
1943 struct nfs4_state *state;
1944 fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE);
1945
1946 cred = rpc_lookup_cred();
1947 if (IS_ERR(cred))
1948 return PTR_ERR(cred);
1949 state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred);
1950 put_rpccred(cred);
1951 if (IS_ERR(state)) {
1952 switch (PTR_ERR(state)) {
1953 case -EPERM:
1954 case -EACCES:
1955 case -EDQUOT:
1956 case -ENOSPC:
1957 case -EROFS:
1958 lookup_instantiate_filp(nd, (struct dentry *)state, NULL);
1959 return 1;
1960 default:
1961 goto out_drop;
1962 }
1963 }
1964 if (state->inode == dentry->d_inode) {
1965 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1966 nfs4_intent_set_file(nd, &path, state, fmode);
1967 return 1;
1968 }
1969 nfs4_close_sync(&path, state, fmode);
1970out_drop:
1971 d_drop(dentry);
1972 return 0;
1973} 2047}
1974 2048
1975void nfs4_close_context(struct nfs_open_context *ctx, int is_sync) 2049static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
1976{ 2050{
1977 if (ctx->state == NULL) 2051 if (ctx->state == NULL)
1978 return; 2052 return;
@@ -1998,12 +2072,34 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
1998 status = nfs4_call_sync(server, &msg, &args, &res, 0); 2072 status = nfs4_call_sync(server, &msg, &args, &res, 0);
1999 if (status == 0) { 2073 if (status == 0) {
2000 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); 2074 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2075 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2076 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2077 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2078 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2079 NFS_CAP_CTIME|NFS_CAP_MTIME);
2001 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) 2080 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2002 server->caps |= NFS_CAP_ACLS; 2081 server->caps |= NFS_CAP_ACLS;
2003 if (res.has_links != 0) 2082 if (res.has_links != 0)
2004 server->caps |= NFS_CAP_HARDLINKS; 2083 server->caps |= NFS_CAP_HARDLINKS;
2005 if (res.has_symlinks != 0) 2084 if (res.has_symlinks != 0)
2006 server->caps |= NFS_CAP_SYMLINKS; 2085 server->caps |= NFS_CAP_SYMLINKS;
2086 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2087 server->caps |= NFS_CAP_FILEID;
2088 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2089 server->caps |= NFS_CAP_MODE;
2090 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2091 server->caps |= NFS_CAP_NLINK;
2092 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2093 server->caps |= NFS_CAP_OWNER;
2094 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2095 server->caps |= NFS_CAP_OWNER_GROUP;
2096 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2097 server->caps |= NFS_CAP_ATIME;
2098 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2099 server->caps |= NFS_CAP_CTIME;
2100 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2101 server->caps |= NFS_CAP_MTIME;
2102
2007 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); 2103 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2008 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; 2104 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2009 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 2105 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
@@ -2041,15 +2137,9 @@ static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2041 .rpc_argp = &args, 2137 .rpc_argp = &args,
2042 .rpc_resp = &res, 2138 .rpc_resp = &res,
2043 }; 2139 };
2044 int status;
2045 2140
2046 nfs_fattr_init(info->fattr); 2141 nfs_fattr_init(info->fattr);
2047 status = nfs4_recover_expired_lease(server); 2142 return nfs4_call_sync(server, &msg, &args, &res, 0);
2048 if (!status)
2049 status = nfs4_check_client_ready(server->nfs_client);
2050 if (!status)
2051 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2052 return status;
2053} 2143}
2054 2144
2055static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, 2145static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
@@ -2117,8 +2207,7 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct
2117out: 2207out:
2118 if (page) 2208 if (page)
2119 __free_page(page); 2209 __free_page(page);
2120 if (locations) 2210 kfree(locations);
2121 kfree(locations);
2122 return status; 2211 return status;
2123} 2212}
2124 2213
@@ -2274,14 +2363,12 @@ static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh
2274static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) 2363static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2275{ 2364{
2276 struct nfs_server *server = NFS_SERVER(inode); 2365 struct nfs_server *server = NFS_SERVER(inode);
2277 struct nfs_fattr fattr;
2278 struct nfs4_accessargs args = { 2366 struct nfs4_accessargs args = {
2279 .fh = NFS_FH(inode), 2367 .fh = NFS_FH(inode),
2280 .bitmask = server->attr_bitmask, 2368 .bitmask = server->attr_bitmask,
2281 }; 2369 };
2282 struct nfs4_accessres res = { 2370 struct nfs4_accessres res = {
2283 .server = server, 2371 .server = server,
2284 .fattr = &fattr,
2285 }; 2372 };
2286 struct rpc_message msg = { 2373 struct rpc_message msg = {
2287 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], 2374 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
@@ -2308,7 +2395,11 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
2308 if (mode & MAY_EXEC) 2395 if (mode & MAY_EXEC)
2309 args.access |= NFS4_ACCESS_EXECUTE; 2396 args.access |= NFS4_ACCESS_EXECUTE;
2310 } 2397 }
2311 nfs_fattr_init(&fattr); 2398
2399 res.fattr = nfs_alloc_fattr();
2400 if (res.fattr == NULL)
2401 return -ENOMEM;
2402
2312 status = nfs4_call_sync(server, &msg, &args, &res, 0); 2403 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2313 if (!status) { 2404 if (!status) {
2314 entry->mask = 0; 2405 entry->mask = 0;
@@ -2318,8 +2409,9 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
2318 entry->mask |= MAY_WRITE; 2409 entry->mask |= MAY_WRITE;
2319 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) 2410 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2320 entry->mask |= MAY_EXEC; 2411 entry->mask |= MAY_EXEC;
2321 nfs_refresh_inode(inode, &fattr); 2412 nfs_refresh_inode(inode, res.fattr);
2322 } 2413 }
2414 nfs_free_fattr(res.fattr);
2323 return status; 2415 return status;
2324} 2416}
2325 2417
@@ -2408,43 +2500,35 @@ static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2408 2500
2409static int 2501static int
2410nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 2502nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2411 int flags, struct nameidata *nd) 2503 int flags, struct nfs_open_context *ctx)
2412{ 2504{
2413 struct path path = { 2505 struct path my_path = {
2414 .mnt = nd->path.mnt,
2415 .dentry = dentry, 2506 .dentry = dentry,
2416 }; 2507 };
2508 struct path *path = &my_path;
2417 struct nfs4_state *state; 2509 struct nfs4_state *state;
2418 struct rpc_cred *cred; 2510 struct rpc_cred *cred = NULL;
2419 fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE); 2511 fmode_t fmode = 0;
2420 int status = 0; 2512 int status = 0;
2421 2513
2422 cred = rpc_lookup_cred(); 2514 if (ctx != NULL) {
2423 if (IS_ERR(cred)) { 2515 cred = ctx->cred;
2424 status = PTR_ERR(cred); 2516 path = &ctx->path;
2425 goto out; 2517 fmode = ctx->mode;
2426 } 2518 }
2427 state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred); 2519 sattr->ia_mode &= ~current_umask();
2520 state = nfs4_do_open(dir, path, fmode, flags, sattr, cred);
2428 d_drop(dentry); 2521 d_drop(dentry);
2429 if (IS_ERR(state)) { 2522 if (IS_ERR(state)) {
2430 status = PTR_ERR(state); 2523 status = PTR_ERR(state);
2431 goto out_putcred; 2524 goto out;
2432 } 2525 }
2433 d_add(dentry, igrab(state->inode)); 2526 d_add(dentry, igrab(state->inode));
2434 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 2527 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2435 if (flags & O_EXCL) { 2528 if (ctx != NULL)
2436 struct nfs_fattr fattr; 2529 ctx->state = state;
2437 status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state);
2438 if (status == 0)
2439 nfs_setattr_update_inode(state->inode, sattr);
2440 nfs_post_op_update_inode(state->inode, &fattr);
2441 }
2442 if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
2443 status = nfs4_intent_set_file(nd, &path, state, fmode);
2444 else 2530 else
2445 nfs4_close_sync(&path, state, fmode); 2531 nfs4_close_sync(path, state, fmode);
2446out_putcred:
2447 put_rpccred(cred);
2448out: 2532out:
2449 return status; 2533 return status;
2450} 2534}
@@ -2466,14 +2550,19 @@ static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2466 .rpc_argp = &args, 2550 .rpc_argp = &args,
2467 .rpc_resp = &res, 2551 .rpc_resp = &res,
2468 }; 2552 };
2469 int status; 2553 int status = -ENOMEM;
2554
2555 res.dir_attr = nfs_alloc_fattr();
2556 if (res.dir_attr == NULL)
2557 goto out;
2470 2558
2471 nfs_fattr_init(&res.dir_attr);
2472 status = nfs4_call_sync(server, &msg, &args, &res, 1); 2559 status = nfs4_call_sync(server, &msg, &args, &res, 1);
2473 if (status == 0) { 2560 if (status == 0) {
2474 update_changeattr(dir, &res.cinfo); 2561 update_changeattr(dir, &res.cinfo);
2475 nfs_post_op_update_inode(dir, &res.dir_attr); 2562 nfs_post_op_update_inode(dir, res.dir_attr);
2476 } 2563 }
2564 nfs_free_fattr(res.dir_attr);
2565out:
2477 return status; 2566 return status;
2478} 2567}
2479 2568
@@ -2497,6 +2586,7 @@ static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2497 2586
2498 args->bitmask = server->cache_consistency_bitmask; 2587 args->bitmask = server->cache_consistency_bitmask;
2499 res->server = server; 2588 res->server = server;
2589 res->seq_res.sr_slot = NULL;
2500 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; 2590 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2501} 2591}
2502 2592
@@ -2504,12 +2594,40 @@ static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2504{ 2594{
2505 struct nfs_removeres *res = task->tk_msg.rpc_resp; 2595 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2506 2596
2507 nfs4_sequence_done(res->server, &res->seq_res, task->tk_status); 2597 if (!nfs4_sequence_done(task, &res->seq_res))
2598 return 0;
2508 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) 2599 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2509 return 0; 2600 return 0;
2510 nfs4_sequence_free_slot(res->server->nfs_client, &res->seq_res);
2511 update_changeattr(dir, &res->cinfo); 2601 update_changeattr(dir, &res->cinfo);
2512 nfs_post_op_update_inode(dir, &res->dir_attr); 2602 nfs_post_op_update_inode(dir, res->dir_attr);
2603 return 1;
2604}
2605
2606static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
2607{
2608 struct nfs_server *server = NFS_SERVER(dir);
2609 struct nfs_renameargs *arg = msg->rpc_argp;
2610 struct nfs_renameres *res = msg->rpc_resp;
2611
2612 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
2613 arg->bitmask = server->attr_bitmask;
2614 res->server = server;
2615}
2616
2617static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
2618 struct inode *new_dir)
2619{
2620 struct nfs_renameres *res = task->tk_msg.rpc_resp;
2621
2622 if (!nfs4_sequence_done(task, &res->seq_res))
2623 return 0;
2624 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2625 return 0;
2626
2627 update_changeattr(old_dir, &res->old_cinfo);
2628 nfs_post_op_update_inode(old_dir, res->old_fattr);
2629 update_changeattr(new_dir, &res->new_cinfo);
2630 nfs_post_op_update_inode(new_dir, res->new_fattr);
2513 return 1; 2631 return 1;
2514} 2632}
2515 2633
@@ -2517,36 +2635,38 @@ static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2517 struct inode *new_dir, struct qstr *new_name) 2635 struct inode *new_dir, struct qstr *new_name)
2518{ 2636{
2519 struct nfs_server *server = NFS_SERVER(old_dir); 2637 struct nfs_server *server = NFS_SERVER(old_dir);
2520 struct nfs4_rename_arg arg = { 2638 struct nfs_renameargs arg = {
2521 .old_dir = NFS_FH(old_dir), 2639 .old_dir = NFS_FH(old_dir),
2522 .new_dir = NFS_FH(new_dir), 2640 .new_dir = NFS_FH(new_dir),
2523 .old_name = old_name, 2641 .old_name = old_name,
2524 .new_name = new_name, 2642 .new_name = new_name,
2525 .bitmask = server->attr_bitmask, 2643 .bitmask = server->attr_bitmask,
2526 }; 2644 };
2527 struct nfs_fattr old_fattr, new_fattr; 2645 struct nfs_renameres res = {
2528 struct nfs4_rename_res res = {
2529 .server = server, 2646 .server = server,
2530 .old_fattr = &old_fattr,
2531 .new_fattr = &new_fattr,
2532 }; 2647 };
2533 struct rpc_message msg = { 2648 struct rpc_message msg = {
2534 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], 2649 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
2535 .rpc_argp = &arg, 2650 .rpc_argp = &arg,
2536 .rpc_resp = &res, 2651 .rpc_resp = &res,
2537 }; 2652 };
2538 int status; 2653 int status = -ENOMEM;
2539 2654
2540 nfs_fattr_init(res.old_fattr); 2655 res.old_fattr = nfs_alloc_fattr();
2541 nfs_fattr_init(res.new_fattr); 2656 res.new_fattr = nfs_alloc_fattr();
2542 status = nfs4_call_sync(server, &msg, &arg, &res, 1); 2657 if (res.old_fattr == NULL || res.new_fattr == NULL)
2658 goto out;
2543 2659
2660 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2544 if (!status) { 2661 if (!status) {
2545 update_changeattr(old_dir, &res.old_cinfo); 2662 update_changeattr(old_dir, &res.old_cinfo);
2546 nfs_post_op_update_inode(old_dir, res.old_fattr); 2663 nfs_post_op_update_inode(old_dir, res.old_fattr);
2547 update_changeattr(new_dir, &res.new_cinfo); 2664 update_changeattr(new_dir, &res.new_cinfo);
2548 nfs_post_op_update_inode(new_dir, res.new_fattr); 2665 nfs_post_op_update_inode(new_dir, res.new_fattr);
2549 } 2666 }
2667out:
2668 nfs_free_fattr(res.new_fattr);
2669 nfs_free_fattr(res.old_fattr);
2550 return status; 2670 return status;
2551} 2671}
2552 2672
@@ -2573,28 +2693,30 @@ static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *
2573 .name = name, 2693 .name = name,
2574 .bitmask = server->attr_bitmask, 2694 .bitmask = server->attr_bitmask,
2575 }; 2695 };
2576 struct nfs_fattr fattr, dir_attr;
2577 struct nfs4_link_res res = { 2696 struct nfs4_link_res res = {
2578 .server = server, 2697 .server = server,
2579 .fattr = &fattr,
2580 .dir_attr = &dir_attr,
2581 }; 2698 };
2582 struct rpc_message msg = { 2699 struct rpc_message msg = {
2583 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], 2700 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
2584 .rpc_argp = &arg, 2701 .rpc_argp = &arg,
2585 .rpc_resp = &res, 2702 .rpc_resp = &res,
2586 }; 2703 };
2587 int status; 2704 int status = -ENOMEM;
2705
2706 res.fattr = nfs_alloc_fattr();
2707 res.dir_attr = nfs_alloc_fattr();
2708 if (res.fattr == NULL || res.dir_attr == NULL)
2709 goto out;
2588 2710
2589 nfs_fattr_init(res.fattr);
2590 nfs_fattr_init(res.dir_attr);
2591 status = nfs4_call_sync(server, &msg, &arg, &res, 1); 2711 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2592 if (!status) { 2712 if (!status) {
2593 update_changeattr(dir, &res.cinfo); 2713 update_changeattr(dir, &res.cinfo);
2594 nfs_post_op_update_inode(dir, res.dir_attr); 2714 nfs_post_op_update_inode(dir, res.dir_attr);
2595 nfs_post_op_update_inode(inode, res.fattr); 2715 nfs_post_op_update_inode(inode, res.fattr);
2596 } 2716 }
2597 2717out:
2718 nfs_free_fattr(res.dir_attr);
2719 nfs_free_fattr(res.fattr);
2598 return status; 2720 return status;
2599} 2721}
2600 2722
@@ -2725,6 +2847,8 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2725{ 2847{
2726 struct nfs4_exception exception = { }; 2848 struct nfs4_exception exception = { };
2727 int err; 2849 int err;
2850
2851 sattr->ia_mode &= ~current_umask();
2728 do { 2852 do {
2729 err = nfs4_handle_exception(NFS_SERVER(dir), 2853 err = nfs4_handle_exception(NFS_SERVER(dir),
2730 _nfs4_proc_mkdir(dir, dentry, sattr), 2854 _nfs4_proc_mkdir(dir, dentry, sattr),
@@ -2734,15 +2858,16 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2734} 2858}
2735 2859
2736static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 2860static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2737 u64 cookie, struct page *page, unsigned int count, int plus) 2861 u64 cookie, struct page **pages, unsigned int count, int plus)
2738{ 2862{
2739 struct inode *dir = dentry->d_inode; 2863 struct inode *dir = dentry->d_inode;
2740 struct nfs4_readdir_arg args = { 2864 struct nfs4_readdir_arg args = {
2741 .fh = NFS_FH(dir), 2865 .fh = NFS_FH(dir),
2742 .pages = &page, 2866 .pages = pages,
2743 .pgbase = 0, 2867 .pgbase = 0,
2744 .count = count, 2868 .count = count,
2745 .bitmask = NFS_SERVER(dentry->d_inode)->cache_consistency_bitmask, 2869 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2870 .plus = plus,
2746 }; 2871 };
2747 struct nfs4_readdir_res res; 2872 struct nfs4_readdir_res res;
2748 struct rpc_message msg = { 2873 struct rpc_message msg = {
@@ -2760,8 +2885,10 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2760 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); 2885 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2761 res.pgbase = args.pgbase; 2886 res.pgbase = args.pgbase;
2762 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); 2887 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2763 if (status == 0) 2888 if (status >= 0) {
2764 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); 2889 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2890 status += args.pgbase;
2891 }
2765 2892
2766 nfs_invalidate_atime(dir); 2893 nfs_invalidate_atime(dir);
2767 2894
@@ -2770,14 +2897,14 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2770} 2897}
2771 2898
2772static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 2899static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2773 u64 cookie, struct page *page, unsigned int count, int plus) 2900 u64 cookie, struct page **pages, unsigned int count, int plus)
2774{ 2901{
2775 struct nfs4_exception exception = { }; 2902 struct nfs4_exception exception = { };
2776 int err; 2903 int err;
2777 do { 2904 do {
2778 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), 2905 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2779 _nfs4_proc_readdir(dentry, cred, cookie, 2906 _nfs4_proc_readdir(dentry, cred, cookie,
2780 page, count, plus), 2907 pages, count, plus),
2781 &exception); 2908 &exception);
2782 } while (exception.retry); 2909 } while (exception.retry);
2783 return err; 2910 return err;
@@ -2822,6 +2949,8 @@ static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2822{ 2949{
2823 struct nfs4_exception exception = { }; 2950 struct nfs4_exception exception = { };
2824 int err; 2951 int err;
2952
2953 sattr->ia_mode &= ~current_umask();
2825 do { 2954 do {
2826 err = nfs4_handle_exception(NFS_SERVER(dir), 2955 err = nfs4_handle_exception(NFS_SERVER(dir),
2827 _nfs4_proc_mknod(dir, dentry, sattr, rdev), 2956 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
@@ -2946,11 +3075,11 @@ static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
2946 3075
2947 dprintk("--> %s\n", __func__); 3076 dprintk("--> %s\n", __func__);
2948 3077
2949 /* nfs4_sequence_free_slot called in the read rpc_call_done */ 3078 if (!nfs4_sequence_done(task, &data->res.seq_res))
2950 nfs4_sequence_done(server, &data->res.seq_res, task->tk_status); 3079 return -EAGAIN;
2951 3080
2952 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { 3081 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
2953 nfs4_restart_rpc(task, server->nfs_client); 3082 nfs_restart_rpc(task, server->nfs_client);
2954 return -EAGAIN; 3083 return -EAGAIN;
2955 } 3084 }
2956 3085
@@ -2970,12 +3099,11 @@ static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
2970{ 3099{
2971 struct inode *inode = data->inode; 3100 struct inode *inode = data->inode;
2972 3101
2973 /* slot is freed in nfs_writeback_done */ 3102 if (!nfs4_sequence_done(task, &data->res.seq_res))
2974 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, 3103 return -EAGAIN;
2975 task->tk_status);
2976 3104
2977 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { 3105 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
2978 nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client); 3106 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
2979 return -EAGAIN; 3107 return -EAGAIN;
2980 } 3108 }
2981 if (task->tk_status >= 0) { 3109 if (task->tk_status >= 0) {
@@ -3000,14 +3128,13 @@ static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
3000{ 3128{
3001 struct inode *inode = data->inode; 3129 struct inode *inode = data->inode;
3002 3130
3003 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, 3131 if (!nfs4_sequence_done(task, &data->res.seq_res))
3004 task->tk_status); 3132 return -EAGAIN;
3133
3005 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { 3134 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3006 nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client); 3135 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3007 return -EAGAIN; 3136 return -EAGAIN;
3008 } 3137 }
3009 nfs4_sequence_free_slot(NFS_SERVER(inode)->nfs_client,
3010 &data->res.seq_res);
3011 nfs_refresh_inode(inode, data->res.fattr); 3138 nfs_refresh_inode(inode, data->res.fattr);
3012 return 0; 3139 return 0;
3013} 3140}
@@ -3021,14 +3148,31 @@ static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_messa
3021 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; 3148 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3022} 3149}
3023 3150
3151struct nfs4_renewdata {
3152 struct nfs_client *client;
3153 unsigned long timestamp;
3154};
3155
3024/* 3156/*
3025 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special 3157 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3026 * standalone procedure for queueing an asynchronous RENEW. 3158 * standalone procedure for queueing an asynchronous RENEW.
3027 */ 3159 */
3028static void nfs4_renew_done(struct rpc_task *task, void *data) 3160static void nfs4_renew_release(void *calldata)
3029{ 3161{
3030 struct nfs_client *clp = (struct nfs_client *)task->tk_msg.rpc_argp; 3162 struct nfs4_renewdata *data = calldata;
3031 unsigned long timestamp = (unsigned long)data; 3163 struct nfs_client *clp = data->client;
3164
3165 if (atomic_read(&clp->cl_count) > 1)
3166 nfs4_schedule_state_renewal(clp);
3167 nfs_put_client(clp);
3168 kfree(data);
3169}
3170
3171static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3172{
3173 struct nfs4_renewdata *data = calldata;
3174 struct nfs_client *clp = data->client;
3175 unsigned long timestamp = data->timestamp;
3032 3176
3033 if (task->tk_status < 0) { 3177 if (task->tk_status < 0) {
3034 /* Unless we're shutting down, schedule state recovery! */ 3178 /* Unless we're shutting down, schedule state recovery! */
@@ -3036,17 +3180,12 @@ static void nfs4_renew_done(struct rpc_task *task, void *data)
3036 nfs4_schedule_state_recovery(clp); 3180 nfs4_schedule_state_recovery(clp);
3037 return; 3181 return;
3038 } 3182 }
3039 spin_lock(&clp->cl_lock); 3183 do_renew_lease(clp, timestamp);
3040 if (time_before(clp->cl_last_renewal,timestamp))
3041 clp->cl_last_renewal = timestamp;
3042 spin_unlock(&clp->cl_lock);
3043 dprintk("%s calling put_rpccred on rpc_cred %p\n", __func__,
3044 task->tk_msg.rpc_cred);
3045 put_rpccred(task->tk_msg.rpc_cred);
3046} 3184}
3047 3185
3048static const struct rpc_call_ops nfs4_renew_ops = { 3186static const struct rpc_call_ops nfs4_renew_ops = {
3049 .rpc_call_done = nfs4_renew_done, 3187 .rpc_call_done = nfs4_renew_done,
3188 .rpc_release = nfs4_renew_release,
3050}; 3189};
3051 3190
3052int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred) 3191int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
@@ -3056,9 +3195,17 @@ int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
3056 .rpc_argp = clp, 3195 .rpc_argp = clp,
3057 .rpc_cred = cred, 3196 .rpc_cred = cred,
3058 }; 3197 };
3198 struct nfs4_renewdata *data;
3059 3199
3200 if (!atomic_inc_not_zero(&clp->cl_count))
3201 return -EIO;
3202 data = kmalloc(sizeof(*data), GFP_KERNEL);
3203 if (data == NULL)
3204 return -ENOMEM;
3205 data->client = clp;
3206 data->timestamp = jiffies;
3060 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, 3207 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3061 &nfs4_renew_ops, (void *)jiffies); 3208 &nfs4_renew_ops, data);
3062} 3209}
3063 3210
3064int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) 3211int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
@@ -3074,10 +3221,7 @@ int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3074 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); 3221 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3075 if (status < 0) 3222 if (status < 0)
3076 return status; 3223 return status;
3077 spin_lock(&clp->cl_lock); 3224 do_renew_lease(clp, now);
3078 if (time_before(clp->cl_last_renewal,now))
3079 clp->cl_last_renewal = now;
3080 spin_unlock(&clp->cl_lock);
3081 return 0; 3225 return 0;
3082} 3226}
3083 3227
@@ -3252,6 +3396,8 @@ static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3252 ret = nfs_revalidate_inode(server, inode); 3396 ret = nfs_revalidate_inode(server, inode);
3253 if (ret < 0) 3397 if (ret < 0)
3254 return ret; 3398 return ret;
3399 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
3400 nfs_zap_acl_cache(inode);
3255 ret = nfs4_read_cached_acl(inode, buf, buflen); 3401 ret = nfs4_read_cached_acl(inode, buf, buflen);
3256 if (ret != -ENOENT) 3402 if (ret != -ENOENT)
3257 return ret; 3403 return ret;
@@ -3280,6 +3426,13 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl
3280 nfs_inode_return_delegation(inode); 3426 nfs_inode_return_delegation(inode);
3281 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); 3427 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3282 ret = nfs4_call_sync(server, &msg, &arg, &res, 1); 3428 ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
3429 /*
3430 * Acl update can result in inode attribute update.
3431 * so mark the attribute cache invalid.
3432 */
3433 spin_lock(&inode->i_lock);
3434 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
3435 spin_unlock(&inode->i_lock);
3283 nfs_access_zap_cache(inode); 3436 nfs_access_zap_cache(inode);
3284 nfs_zap_acl_cache(inode); 3437 nfs_zap_acl_cache(inode);
3285 return ret; 3438 return ret;
@@ -3298,9 +3451,11 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
3298} 3451}
3299 3452
3300static int 3453static int
3301_nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state) 3454nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3302{ 3455{
3303 if (!clp || task->tk_status >= 0) 3456 struct nfs_client *clp = server->nfs_client;
3457
3458 if (task->tk_status >= 0)
3304 return 0; 3459 return 0;
3305 switch(task->tk_status) { 3460 switch(task->tk_status) {
3306 case -NFS4ERR_ADMIN_REVOKED: 3461 case -NFS4ERR_ADMIN_REVOKED:
@@ -3309,15 +3464,11 @@ _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
3309 if (state == NULL) 3464 if (state == NULL)
3310 break; 3465 break;
3311 nfs4_state_mark_reclaim_nograce(clp, state); 3466 nfs4_state_mark_reclaim_nograce(clp, state);
3312 case -NFS4ERR_STALE_CLIENTID: 3467 goto do_state_recovery;
3313 case -NFS4ERR_STALE_STATEID: 3468 case -NFS4ERR_STALE_STATEID:
3469 case -NFS4ERR_STALE_CLIENTID:
3314 case -NFS4ERR_EXPIRED: 3470 case -NFS4ERR_EXPIRED:
3315 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); 3471 goto do_state_recovery;
3316 nfs4_schedule_state_recovery(clp);
3317 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3318 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3319 task->tk_status = 0;
3320 return -EAGAIN;
3321#if defined(CONFIG_NFS_V4_1) 3472#if defined(CONFIG_NFS_V4_1)
3322 case -NFS4ERR_BADSESSION: 3473 case -NFS4ERR_BADSESSION:
3323 case -NFS4ERR_BADSLOT: 3474 case -NFS4ERR_BADSLOT:
@@ -3328,14 +3479,14 @@ _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
3328 case -NFS4ERR_SEQ_MISORDERED: 3479 case -NFS4ERR_SEQ_MISORDERED:
3329 dprintk("%s ERROR %d, Reset session\n", __func__, 3480 dprintk("%s ERROR %d, Reset session\n", __func__,
3330 task->tk_status); 3481 task->tk_status);
3331 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 3482 nfs4_schedule_state_recovery(clp);
3332 task->tk_status = 0; 3483 task->tk_status = 0;
3333 return -EAGAIN; 3484 return -EAGAIN;
3334#endif /* CONFIG_NFS_V4_1 */ 3485#endif /* CONFIG_NFS_V4_1 */
3335 case -NFS4ERR_DELAY: 3486 case -NFS4ERR_DELAY:
3336 if (server) 3487 nfs_inc_server_stats(server, NFSIOS_DELAY);
3337 nfs_inc_server_stats(server, NFSIOS_DELAY);
3338 case -NFS4ERR_GRACE: 3488 case -NFS4ERR_GRACE:
3489 case -EKEYEXPIRED:
3339 rpc_delay(task, NFS4_POLL_RETRY_MAX); 3490 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3340 task->tk_status = 0; 3491 task->tk_status = 0;
3341 return -EAGAIN; 3492 return -EAGAIN;
@@ -3345,25 +3496,29 @@ _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
3345 } 3496 }
3346 task->tk_status = nfs4_map_errors(task->tk_status); 3497 task->tk_status = nfs4_map_errors(task->tk_status);
3347 return 0; 3498 return 0;
3499do_state_recovery:
3500 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3501 nfs4_schedule_state_recovery(clp);
3502 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3503 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3504 task->tk_status = 0;
3505 return -EAGAIN;
3348} 3506}
3349 3507
3350static int 3508int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3351nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) 3509 unsigned short port, struct rpc_cred *cred,
3352{ 3510 struct nfs4_setclientid_res *res)
3353 return _nfs4_async_handle_error(task, server, server->nfs_client, state);
3354}
3355
3356int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred)
3357{ 3511{
3358 nfs4_verifier sc_verifier; 3512 nfs4_verifier sc_verifier;
3359 struct nfs4_setclientid setclientid = { 3513 struct nfs4_setclientid setclientid = {
3360 .sc_verifier = &sc_verifier, 3514 .sc_verifier = &sc_verifier,
3361 .sc_prog = program, 3515 .sc_prog = program,
3516 .sc_cb_ident = clp->cl_cb_ident,
3362 }; 3517 };
3363 struct rpc_message msg = { 3518 struct rpc_message msg = {
3364 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], 3519 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
3365 .rpc_argp = &setclientid, 3520 .rpc_argp = &setclientid,
3366 .rpc_resp = clp, 3521 .rpc_resp = res,
3367 .rpc_cred = cred, 3522 .rpc_cred = cred,
3368 }; 3523 };
3369 __be32 *p; 3524 __be32 *p;
@@ -3398,7 +3553,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short po
3398 if (signalled()) 3553 if (signalled())
3399 break; 3554 break;
3400 if (loop++ & 1) 3555 if (loop++ & 1)
3401 ssleep(clp->cl_lease_time + 1); 3556 ssleep(clp->cl_lease_time / HZ + 1);
3402 else 3557 else
3403 if (++clp->cl_id_uniquifier == 0) 3558 if (++clp->cl_id_uniquifier == 0)
3404 break; 3559 break;
@@ -3406,12 +3561,14 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short po
3406 return status; 3561 return status;
3407} 3562}
3408 3563
3409static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) 3564static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3565 struct nfs4_setclientid_res *arg,
3566 struct rpc_cred *cred)
3410{ 3567{
3411 struct nfs_fsinfo fsinfo; 3568 struct nfs_fsinfo fsinfo;
3412 struct rpc_message msg = { 3569 struct rpc_message msg = {
3413 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], 3570 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
3414 .rpc_argp = clp, 3571 .rpc_argp = arg,
3415 .rpc_resp = &fsinfo, 3572 .rpc_resp = &fsinfo,
3416 .rpc_cred = cred, 3573 .rpc_cred = cred,
3417 }; 3574 };
@@ -3429,12 +3586,14 @@ static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cre
3429 return status; 3586 return status;
3430} 3587}
3431 3588
3432int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) 3589int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3590 struct nfs4_setclientid_res *arg,
3591 struct rpc_cred *cred)
3433{ 3592{
3434 long timeout = 0; 3593 long timeout = 0;
3435 int err; 3594 int err;
3436 do { 3595 do {
3437 err = _nfs4_proc_setclientid_confirm(clp, cred); 3596 err = _nfs4_proc_setclientid_confirm(clp, arg, cred);
3438 switch (err) { 3597 switch (err) {
3439 case 0: 3598 case 0:
3440 return err; 3599 return err;
@@ -3461,12 +3620,23 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
3461{ 3620{
3462 struct nfs4_delegreturndata *data = calldata; 3621 struct nfs4_delegreturndata *data = calldata;
3463 3622
3464 nfs4_sequence_done_free_slot(data->res.server, &data->res.seq_res, 3623 if (!nfs4_sequence_done(task, &data->res.seq_res))
3465 task->tk_status); 3624 return;
3466 3625
3467 data->rpc_status = task->tk_status; 3626 switch (task->tk_status) {
3468 if (data->rpc_status == 0) 3627 case -NFS4ERR_STALE_STATEID:
3628 case -NFS4ERR_EXPIRED:
3629 case 0:
3469 renew_lease(data->res.server, data->timestamp); 3630 renew_lease(data->res.server, data->timestamp);
3631 break;
3632 default:
3633 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
3634 -EAGAIN) {
3635 nfs_restart_rpc(task, data->res.server->nfs_client);
3636 return;
3637 }
3638 }
3639 data->rpc_status = task->tk_status;
3470} 3640}
3471 3641
3472static void nfs4_delegreturn_release(void *calldata) 3642static void nfs4_delegreturn_release(void *calldata)
@@ -3481,7 +3651,7 @@ static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3481 3651
3482 d_data = (struct nfs4_delegreturndata *)data; 3652 d_data = (struct nfs4_delegreturndata *)data;
3483 3653
3484 if (nfs4_setup_sequence(d_data->res.server->nfs_client, 3654 if (nfs4_setup_sequence(d_data->res.server,
3485 &d_data->args.seq_args, 3655 &d_data->args.seq_args,
3486 &d_data->res.seq_res, 1, task)) 3656 &d_data->res.seq_res, 1, task))
3487 return; 3657 return;
@@ -3514,7 +3684,7 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
3514 }; 3684 };
3515 int status = 0; 3685 int status = 0;
3516 3686
3517 data = kzalloc(sizeof(*data), GFP_KERNEL); 3687 data = kzalloc(sizeof(*data), GFP_NOFS);
3518 if (data == NULL) 3688 if (data == NULL)
3519 return -ENOMEM; 3689 return -ENOMEM;
3520 data->args.fhandle = &data->fh; 3690 data->args.fhandle = &data->fh;
@@ -3524,14 +3694,13 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
3524 memcpy(&data->stateid, stateid, sizeof(data->stateid)); 3694 memcpy(&data->stateid, stateid, sizeof(data->stateid));
3525 data->res.fattr = &data->fattr; 3695 data->res.fattr = &data->fattr;
3526 data->res.server = server; 3696 data->res.server = server;
3527 data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3528 nfs_fattr_init(data->res.fattr); 3697 nfs_fattr_init(data->res.fattr);
3529 data->timestamp = jiffies; 3698 data->timestamp = jiffies;
3530 data->rpc_status = 0; 3699 data->rpc_status = 0;
3531 3700
3532 task_setup_data.callback_data = data; 3701 task_setup_data.callback_data = data;
3533 msg.rpc_argp = &data->args, 3702 msg.rpc_argp = &data->args;
3534 msg.rpc_resp = &data->res, 3703 msg.rpc_resp = &data->res;
3535 task = rpc_run_task(&task_setup_data); 3704 task = rpc_run_task(&task_setup_data);
3536 if (IS_ERR(task)) 3705 if (IS_ERR(task))
3537 return PTR_ERR(task); 3706 return PTR_ERR(task);
@@ -3610,6 +3779,7 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
3610 goto out; 3779 goto out;
3611 lsp = request->fl_u.nfs4_fl.owner; 3780 lsp = request->fl_u.nfs4_fl.owner;
3612 arg.lock_owner.id = lsp->ls_id.id; 3781 arg.lock_owner.id = lsp->ls_id.id;
3782 arg.lock_owner.s_dev = server->s_dev;
3613 status = nfs4_call_sync(server, &msg, &arg, &res, 1); 3783 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
3614 switch (status) { 3784 switch (status) {
3615 case 0: 3785 case 0:
@@ -3670,14 +3840,13 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
3670 struct nfs4_unlockdata *p; 3840 struct nfs4_unlockdata *p;
3671 struct inode *inode = lsp->ls_state->inode; 3841 struct inode *inode = lsp->ls_state->inode;
3672 3842
3673 p = kzalloc(sizeof(*p), GFP_KERNEL); 3843 p = kzalloc(sizeof(*p), GFP_NOFS);
3674 if (p == NULL) 3844 if (p == NULL)
3675 return NULL; 3845 return NULL;
3676 p->arg.fh = NFS_FH(inode); 3846 p->arg.fh = NFS_FH(inode);
3677 p->arg.fl = &p->fl; 3847 p->arg.fl = &p->fl;
3678 p->arg.seqid = seqid; 3848 p->arg.seqid = seqid;
3679 p->res.seqid = seqid; 3849 p->res.seqid = seqid;
3680 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3681 p->arg.stateid = &lsp->ls_stateid; 3850 p->arg.stateid = &lsp->ls_stateid;
3682 p->lsp = lsp; 3851 p->lsp = lsp;
3683 atomic_inc(&lsp->ls_count); 3852 atomic_inc(&lsp->ls_count);
@@ -3701,9 +3870,7 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
3701{ 3870{
3702 struct nfs4_unlockdata *calldata = data; 3871 struct nfs4_unlockdata *calldata = data;
3703 3872
3704 nfs4_sequence_done(calldata->server, &calldata->res.seq_res, 3873 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
3705 task->tk_status);
3706 if (RPC_ASSASSINATED(task))
3707 return; 3874 return;
3708 switch (task->tk_status) { 3875 switch (task->tk_status) {
3709 case 0: 3876 case 0:
@@ -3719,11 +3886,9 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
3719 break; 3886 break;
3720 default: 3887 default:
3721 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) 3888 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
3722 nfs4_restart_rpc(task, 3889 nfs_restart_rpc(task,
3723 calldata->server->nfs_client); 3890 calldata->server->nfs_client);
3724 } 3891 }
3725 nfs4_sequence_free_slot(calldata->server->nfs_client,
3726 &calldata->res.seq_res);
3727} 3892}
3728 3893
3729static void nfs4_locku_prepare(struct rpc_task *task, void *data) 3894static void nfs4_locku_prepare(struct rpc_task *task, void *data)
@@ -3738,7 +3903,7 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data)
3738 return; 3903 return;
3739 } 3904 }
3740 calldata->timestamp = jiffies; 3905 calldata->timestamp = jiffies;
3741 if (nfs4_setup_sequence(calldata->server->nfs_client, 3906 if (nfs4_setup_sequence(calldata->server,
3742 &calldata->arg.seq_args, 3907 &calldata->arg.seq_args,
3743 &calldata->res.seq_res, 1, task)) 3908 &calldata->res.seq_res, 1, task))
3744 return; 3909 return;
@@ -3780,8 +3945,8 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
3780 return ERR_PTR(-ENOMEM); 3945 return ERR_PTR(-ENOMEM);
3781 } 3946 }
3782 3947
3783 msg.rpc_argp = &data->arg, 3948 msg.rpc_argp = &data->arg;
3784 msg.rpc_resp = &data->res, 3949 msg.rpc_resp = &data->res;
3785 task_setup_data.callback_data = data; 3950 task_setup_data.callback_data = data;
3786 return rpc_run_task(&task_setup_data); 3951 return rpc_run_task(&task_setup_data);
3787} 3952}
@@ -3810,7 +3975,7 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
3810 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) 3975 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
3811 goto out; 3976 goto out;
3812 lsp = request->fl_u.nfs4_fl.owner; 3977 lsp = request->fl_u.nfs4_fl.owner;
3813 seqid = nfs_alloc_seqid(&lsp->ls_seqid); 3978 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
3814 status = -ENOMEM; 3979 status = -ENOMEM;
3815 if (seqid == NULL) 3980 if (seqid == NULL)
3816 goto out; 3981 goto out;
@@ -3838,29 +4003,30 @@ struct nfs4_lockdata {
3838}; 4003};
3839 4004
3840static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, 4005static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
3841 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp) 4006 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4007 gfp_t gfp_mask)
3842{ 4008{
3843 struct nfs4_lockdata *p; 4009 struct nfs4_lockdata *p;
3844 struct inode *inode = lsp->ls_state->inode; 4010 struct inode *inode = lsp->ls_state->inode;
3845 struct nfs_server *server = NFS_SERVER(inode); 4011 struct nfs_server *server = NFS_SERVER(inode);
3846 4012
3847 p = kzalloc(sizeof(*p), GFP_KERNEL); 4013 p = kzalloc(sizeof(*p), gfp_mask);
3848 if (p == NULL) 4014 if (p == NULL)
3849 return NULL; 4015 return NULL;
3850 4016
3851 p->arg.fh = NFS_FH(inode); 4017 p->arg.fh = NFS_FH(inode);
3852 p->arg.fl = &p->fl; 4018 p->arg.fl = &p->fl;
3853 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid); 4019 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
3854 if (p->arg.open_seqid == NULL) 4020 if (p->arg.open_seqid == NULL)
3855 goto out_free; 4021 goto out_free;
3856 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); 4022 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
3857 if (p->arg.lock_seqid == NULL) 4023 if (p->arg.lock_seqid == NULL)
3858 goto out_free_seqid; 4024 goto out_free_seqid;
3859 p->arg.lock_stateid = &lsp->ls_stateid; 4025 p->arg.lock_stateid = &lsp->ls_stateid;
3860 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; 4026 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
3861 p->arg.lock_owner.id = lsp->ls_id.id; 4027 p->arg.lock_owner.id = lsp->ls_id.id;
4028 p->arg.lock_owner.s_dev = server->s_dev;
3862 p->res.lock_seqid = p->arg.lock_seqid; 4029 p->res.lock_seqid = p->arg.lock_seqid;
3863 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3864 p->lsp = lsp; 4030 p->lsp = lsp;
3865 p->server = server; 4031 p->server = server;
3866 atomic_inc(&lsp->ls_count); 4032 atomic_inc(&lsp->ls_count);
@@ -3892,25 +4058,30 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
3892 } else 4058 } else
3893 data->arg.new_lock_owner = 0; 4059 data->arg.new_lock_owner = 0;
3894 data->timestamp = jiffies; 4060 data->timestamp = jiffies;
3895 if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args, 4061 if (nfs4_setup_sequence(data->server,
4062 &data->arg.seq_args,
3896 &data->res.seq_res, 1, task)) 4063 &data->res.seq_res, 1, task))
3897 return; 4064 return;
3898 rpc_call_start(task); 4065 rpc_call_start(task);
3899 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); 4066 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
3900} 4067}
3901 4068
4069static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4070{
4071 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4072 nfs4_lock_prepare(task, calldata);
4073}
4074
3902static void nfs4_lock_done(struct rpc_task *task, void *calldata) 4075static void nfs4_lock_done(struct rpc_task *task, void *calldata)
3903{ 4076{
3904 struct nfs4_lockdata *data = calldata; 4077 struct nfs4_lockdata *data = calldata;
3905 4078
3906 dprintk("%s: begin!\n", __func__); 4079 dprintk("%s: begin!\n", __func__);
3907 4080
3908 nfs4_sequence_done_free_slot(data->server, &data->res.seq_res, 4081 if (!nfs4_sequence_done(task, &data->res.seq_res))
3909 task->tk_status); 4082 return;
3910 4083
3911 data->rpc_status = task->tk_status; 4084 data->rpc_status = task->tk_status;
3912 if (RPC_ASSASSINATED(task))
3913 goto out;
3914 if (data->arg.new_lock_owner != 0) { 4085 if (data->arg.new_lock_owner != 0) {
3915 if (data->rpc_status == 0) 4086 if (data->rpc_status == 0)
3916 nfs_confirm_seqid(&data->lsp->ls_seqid, 0); 4087 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
@@ -3954,7 +4125,35 @@ static const struct rpc_call_ops nfs4_lock_ops = {
3954 .rpc_release = nfs4_lock_release, 4125 .rpc_release = nfs4_lock_release,
3955}; 4126};
3956 4127
3957static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int reclaim) 4128static const struct rpc_call_ops nfs4_recover_lock_ops = {
4129 .rpc_call_prepare = nfs4_recover_lock_prepare,
4130 .rpc_call_done = nfs4_lock_done,
4131 .rpc_release = nfs4_lock_release,
4132};
4133
4134static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4135{
4136 struct nfs_client *clp = server->nfs_client;
4137 struct nfs4_state *state = lsp->ls_state;
4138
4139 switch (error) {
4140 case -NFS4ERR_ADMIN_REVOKED:
4141 case -NFS4ERR_BAD_STATEID:
4142 case -NFS4ERR_EXPIRED:
4143 if (new_lock_owner != 0 ||
4144 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4145 nfs4_state_mark_reclaim_nograce(clp, state);
4146 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4147 break;
4148 case -NFS4ERR_STALE_STATEID:
4149 if (new_lock_owner != 0 ||
4150 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4151 nfs4_state_mark_reclaim_reboot(clp, state);
4152 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4153 };
4154}
4155
4156static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
3958{ 4157{
3959 struct nfs4_lockdata *data; 4158 struct nfs4_lockdata *data;
3960 struct rpc_task *task; 4159 struct rpc_task *task;
@@ -3973,15 +4172,19 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
3973 4172
3974 dprintk("%s: begin!\n", __func__); 4173 dprintk("%s: begin!\n", __func__);
3975 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), 4174 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
3976 fl->fl_u.nfs4_fl.owner); 4175 fl->fl_u.nfs4_fl.owner,
4176 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
3977 if (data == NULL) 4177 if (data == NULL)
3978 return -ENOMEM; 4178 return -ENOMEM;
3979 if (IS_SETLKW(cmd)) 4179 if (IS_SETLKW(cmd))
3980 data->arg.block = 1; 4180 data->arg.block = 1;
3981 if (reclaim != 0) 4181 if (recovery_type > NFS_LOCK_NEW) {
3982 data->arg.reclaim = 1; 4182 if (recovery_type == NFS_LOCK_RECLAIM)
3983 msg.rpc_argp = &data->arg, 4183 data->arg.reclaim = NFS_LOCK_RECLAIM;
3984 msg.rpc_resp = &data->res, 4184 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4185 }
4186 msg.rpc_argp = &data->arg;
4187 msg.rpc_resp = &data->res;
3985 task_setup_data.callback_data = data; 4188 task_setup_data.callback_data = data;
3986 task = rpc_run_task(&task_setup_data); 4189 task = rpc_run_task(&task_setup_data);
3987 if (IS_ERR(task)) 4190 if (IS_ERR(task))
@@ -3989,6 +4192,9 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
3989 ret = nfs4_wait_for_completion_rpc_task(task); 4192 ret = nfs4_wait_for_completion_rpc_task(task);
3990 if (ret == 0) { 4193 if (ret == 0) {
3991 ret = data->rpc_status; 4194 ret = data->rpc_status;
4195 if (ret)
4196 nfs4_handle_setlk_error(data->server, data->lsp,
4197 data->arg.new_lock_owner, ret);
3992 } else 4198 } else
3993 data->cancelled = 1; 4199 data->cancelled = 1;
3994 rpc_put_task(task); 4200 rpc_put_task(task);
@@ -4006,7 +4212,7 @@ static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request
4006 /* Cache the lock if possible... */ 4212 /* Cache the lock if possible... */
4007 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) 4213 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4008 return 0; 4214 return 0;
4009 err = _nfs4_do_setlk(state, F_SETLK, request, 1); 4215 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4010 if (err != -NFS4ERR_DELAY) 4216 if (err != -NFS4ERR_DELAY)
4011 break; 4217 break;
4012 nfs4_handle_exception(server, err, &exception); 4218 nfs4_handle_exception(server, err, &exception);
@@ -4026,11 +4232,17 @@ static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request
4026 do { 4232 do {
4027 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) 4233 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4028 return 0; 4234 return 0;
4029 err = _nfs4_do_setlk(state, F_SETLK, request, 0); 4235 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4030 if (err != -NFS4ERR_DELAY) 4236 switch (err) {
4031 break; 4237 default:
4032 nfs4_handle_exception(server, err, &exception); 4238 goto out;
4239 case -NFS4ERR_GRACE:
4240 case -NFS4ERR_DELAY:
4241 nfs4_handle_exception(server, err, &exception);
4242 err = 0;
4243 }
4033 } while (exception.retry); 4244 } while (exception.retry);
4245out:
4034 return err; 4246 return err;
4035} 4247}
4036 4248
@@ -4038,8 +4250,11 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
4038{ 4250{
4039 struct nfs_inode *nfsi = NFS_I(state->inode); 4251 struct nfs_inode *nfsi = NFS_I(state->inode);
4040 unsigned char fl_flags = request->fl_flags; 4252 unsigned char fl_flags = request->fl_flags;
4041 int status; 4253 int status = -ENOLCK;
4042 4254
4255 if ((fl_flags & FL_POSIX) &&
4256 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4257 goto out;
4043 /* Is this a delegated open? */ 4258 /* Is this a delegated open? */
4044 status = nfs4_set_lock_state(state, request); 4259 status = nfs4_set_lock_state(state, request);
4045 if (status != 0) 4260 if (status != 0)
@@ -4056,7 +4271,7 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
4056 status = do_vfs_lock(request->fl_file, request); 4271 status = do_vfs_lock(request->fl_file, request);
4057 goto out_unlock; 4272 goto out_unlock;
4058 } 4273 }
4059 status = _nfs4_do_setlk(state, cmd, request, 0); 4274 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4060 if (status != 0) 4275 if (status != 0)
4061 goto out_unlock; 4276 goto out_unlock;
4062 /* Note: we always want to sleep here! */ 4277 /* Note: we always want to sleep here! */
@@ -4100,15 +4315,23 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4100 if (request->fl_start < 0 || request->fl_end < 0) 4315 if (request->fl_start < 0 || request->fl_end < 0)
4101 return -EINVAL; 4316 return -EINVAL;
4102 4317
4103 if (IS_GETLK(cmd)) 4318 if (IS_GETLK(cmd)) {
4104 return nfs4_proc_getlk(state, F_GETLK, request); 4319 if (state != NULL)
4320 return nfs4_proc_getlk(state, F_GETLK, request);
4321 return 0;
4322 }
4105 4323
4106 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) 4324 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4107 return -EINVAL; 4325 return -EINVAL;
4108 4326
4109 if (request->fl_type == F_UNLCK) 4327 if (request->fl_type == F_UNLCK) {
4110 return nfs4_proc_unlck(state, cmd, request); 4328 if (state != NULL)
4329 return nfs4_proc_unlck(state, cmd, request);
4330 return 0;
4331 }
4111 4332
4333 if (state == NULL)
4334 return -ENOLCK;
4112 do { 4335 do {
4113 status = nfs4_proc_setlk(state, cmd, request); 4336 status = nfs4_proc_setlk(state, cmd, request);
4114 if ((status != -EAGAIN) || IS_SETLK(cmd)) 4337 if ((status != -EAGAIN) || IS_SETLK(cmd))
@@ -4131,7 +4354,7 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4131 if (err != 0) 4354 if (err != 0)
4132 goto out; 4355 goto out;
4133 do { 4356 do {
4134 err = _nfs4_do_setlk(state, F_SETLK, fl, 0); 4357 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4135 switch (err) { 4358 switch (err) {
4136 default: 4359 default:
4137 printk(KERN_ERR "%s: unhandled error %d.\n", 4360 printk(KERN_ERR "%s: unhandled error %d.\n",
@@ -4142,6 +4365,11 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4142 case -NFS4ERR_EXPIRED: 4365 case -NFS4ERR_EXPIRED:
4143 case -NFS4ERR_STALE_CLIENTID: 4366 case -NFS4ERR_STALE_CLIENTID:
4144 case -NFS4ERR_STALE_STATEID: 4367 case -NFS4ERR_STALE_STATEID:
4368 case -NFS4ERR_BADSESSION:
4369 case -NFS4ERR_BADSLOT:
4370 case -NFS4ERR_BAD_HIGH_SLOT:
4371 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4372 case -NFS4ERR_DEADSESSION:
4145 nfs4_schedule_state_recovery(server->nfs_client); 4373 nfs4_schedule_state_recovery(server->nfs_client);
4146 goto out; 4374 goto out;
4147 case -ERESTARTSYS: 4375 case -ERESTARTSYS:
@@ -4155,6 +4383,15 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4155 nfs4_state_mark_reclaim_nograce(server->nfs_client, state); 4383 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
4156 err = 0; 4384 err = 0;
4157 goto out; 4385 goto out;
4386 case -EKEYEXPIRED:
4387 /*
4388 * User RPCSEC_GSS context has expired.
4389 * We cannot recover this stateid now, so
4390 * skip it and allow recovery thread to
4391 * proceed.
4392 */
4393 err = 0;
4394 goto out;
4158 case -ENOMEM: 4395 case -ENOMEM:
4159 case -NFS4ERR_DENIED: 4396 case -NFS4ERR_DENIED:
4160 /* kill_proc(fl->fl_pid, SIGLOST, 1); */ 4397 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
@@ -4169,44 +4406,67 @@ out:
4169 return err; 4406 return err;
4170} 4407}
4171 4408
4172#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" 4409static void nfs4_release_lockowner_release(void *calldata)
4173
4174int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
4175 size_t buflen, int flags)
4176{ 4410{
4177 struct inode *inode = dentry->d_inode; 4411 kfree(calldata);
4412}
4178 4413
4179 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) 4414const struct rpc_call_ops nfs4_release_lockowner_ops = {
4180 return -EOPNOTSUPP; 4415 .rpc_release = nfs4_release_lockowner_release,
4416};
4417
4418void nfs4_release_lockowner(const struct nfs4_lock_state *lsp)
4419{
4420 struct nfs_server *server = lsp->ls_state->owner->so_server;
4421 struct nfs_release_lockowner_args *args;
4422 struct rpc_message msg = {
4423 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
4424 };
4181 4425
4182 return nfs4_proc_set_acl(inode, buf, buflen); 4426 if (server->nfs_client->cl_mvops->minor_version != 0)
4427 return;
4428 args = kmalloc(sizeof(*args), GFP_NOFS);
4429 if (!args)
4430 return;
4431 args->lock_owner.clientid = server->nfs_client->cl_clientid;
4432 args->lock_owner.id = lsp->ls_id.id;
4433 args->lock_owner.s_dev = server->s_dev;
4434 msg.rpc_argp = args;
4435 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args);
4183} 4436}
4184 4437
4185/* The getxattr man page suggests returning -ENODATA for unknown attributes, 4438#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4186 * and that's what we'll do for e.g. user attributes that haven't been set. 4439
4187 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported 4440static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
4188 * attributes in kernel-managed attribute namespaces. */ 4441 const void *buf, size_t buflen,
4189ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, 4442 int flags, int type)
4190 size_t buflen)
4191{ 4443{
4192 struct inode *inode = dentry->d_inode; 4444 if (strcmp(key, "") != 0)
4445 return -EINVAL;
4193 4446
4194 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) 4447 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
4195 return -EOPNOTSUPP; 4448}
4196 4449
4197 return nfs4_proc_get_acl(inode, buf, buflen); 4450static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
4451 void *buf, size_t buflen, int type)
4452{
4453 if (strcmp(key, "") != 0)
4454 return -EINVAL;
4455
4456 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
4198} 4457}
4199 4458
4200ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) 4459static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
4460 size_t list_len, const char *name,
4461 size_t name_len, int type)
4201{ 4462{
4202 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; 4463 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
4203 4464
4204 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) 4465 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
4205 return 0; 4466 return 0;
4206 if (buf && buflen < len) 4467
4207 return -ERANGE; 4468 if (list && len <= list_len)
4208 if (buf) 4469 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
4209 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
4210 return len; 4470 return len;
4211} 4471}
4212 4472
@@ -4259,6 +4519,25 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4259 4519
4260#ifdef CONFIG_NFS_V4_1 4520#ifdef CONFIG_NFS_V4_1
4261/* 4521/*
4522 * Check the exchange flags returned by the server for invalid flags, having
4523 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4524 * DS flags set.
4525 */
4526static int nfs4_check_cl_exchange_flags(u32 flags)
4527{
4528 if (flags & ~EXCHGID4_FLAG_MASK_R)
4529 goto out_inval;
4530 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
4531 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
4532 goto out_inval;
4533 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
4534 goto out_inval;
4535 return NFS_OK;
4536out_inval:
4537 return -NFS4ERR_INVAL;
4538}
4539
4540/*
4262 * nfs4_proc_exchange_id() 4541 * nfs4_proc_exchange_id()
4263 * 4542 *
4264 * Since the clientid has expired, all compounds using sessions 4543 * Since the clientid has expired, all compounds using sessions
@@ -4266,12 +4545,12 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4266 * NFS4ERR_BADSESSION in the sequence operation, and will therefore 4545 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4267 * be in some phase of session reset. 4546 * be in some phase of session reset.
4268 */ 4547 */
4269static int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) 4548int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4270{ 4549{
4271 nfs4_verifier verifier; 4550 nfs4_verifier verifier;
4272 struct nfs41_exchange_id_args args = { 4551 struct nfs41_exchange_id_args args = {
4273 .client = clp, 4552 .client = clp,
4274 .flags = clp->cl_exchange_flags, 4553 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
4275 }; 4554 };
4276 struct nfs41_exchange_id_res res = { 4555 struct nfs41_exchange_id_res res = {
4277 .client = clp, 4556 .client = clp,
@@ -4303,7 +4582,7 @@ static int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4303 4582
4304 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); 4583 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
4305 4584
4306 if (status != NFS4ERR_CLID_INUSE) 4585 if (status != -NFS4ERR_CLID_INUSE)
4307 break; 4586 break;
4308 4587
4309 if (signalled()) 4588 if (signalled())
@@ -4313,6 +4592,7 @@ static int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4313 break; 4592 break;
4314 } 4593 }
4315 4594
4595 status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
4316 dprintk("<-- %s status= %d\n", __func__, status); 4596 dprintk("<-- %s status= %d\n", __func__, status);
4317 return status; 4597 return status;
4318} 4598}
@@ -4331,11 +4611,12 @@ static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4331 (struct nfs4_get_lease_time_data *)calldata; 4611 (struct nfs4_get_lease_time_data *)calldata;
4332 4612
4333 dprintk("--> %s\n", __func__); 4613 dprintk("--> %s\n", __func__);
4614 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4334 /* just setup sequence, do not trigger session recovery 4615 /* just setup sequence, do not trigger session recovery
4335 since we're invoked within one */ 4616 since we're invoked within one */
4336 ret = nfs41_setup_sequence(data->clp->cl_session, 4617 ret = nfs41_setup_sequence(data->clp->cl_session,
4337 &data->args->la_seq_args, 4618 &data->args->la_seq_args,
4338 &data->res->lr_seq_res, 0, task); 4619 &data->res->lr_seq_res, 0, task);
4339 4620
4340 BUG_ON(ret == -EAGAIN); 4621 BUG_ON(ret == -EAGAIN);
4341 rpc_call_start(task); 4622 rpc_call_start(task);
@@ -4352,17 +4633,17 @@ static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4352 (struct nfs4_get_lease_time_data *)calldata; 4633 (struct nfs4_get_lease_time_data *)calldata;
4353 4634
4354 dprintk("--> %s\n", __func__); 4635 dprintk("--> %s\n", __func__);
4355 nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status); 4636 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
4637 return;
4356 switch (task->tk_status) { 4638 switch (task->tk_status) {
4357 case -NFS4ERR_DELAY: 4639 case -NFS4ERR_DELAY:
4358 case -NFS4ERR_GRACE: 4640 case -NFS4ERR_GRACE:
4359 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); 4641 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
4360 rpc_delay(task, NFS4_POLL_RETRY_MIN); 4642 rpc_delay(task, NFS4_POLL_RETRY_MIN);
4361 task->tk_status = 0; 4643 task->tk_status = 0;
4362 nfs4_restart_rpc(task, data->clp); 4644 nfs_restart_rpc(task, data->clp);
4363 return; 4645 return;
4364 } 4646 }
4365 nfs41_sequence_free_slot(data->clp, &data->res->lr_seq_res);
4366 dprintk("<-- %s\n", __func__); 4647 dprintk("<-- %s\n", __func__);
4367} 4648}
4368 4649
@@ -4396,7 +4677,6 @@ int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4396 }; 4677 };
4397 int status; 4678 int status;
4398 4679
4399 res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4400 dprintk("--> %s\n", __func__); 4680 dprintk("--> %s\n", __func__);
4401 task = rpc_run_task(&task_setup); 4681 task = rpc_run_task(&task_setup);
4402 4682
@@ -4414,28 +4694,33 @@ int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4414/* 4694/*
4415 * Reset a slot table 4695 * Reset a slot table
4416 */ 4696 */
4417static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, int max_slots, 4697static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
4418 int old_max_slots, int ivalue) 4698 int ivalue)
4419{ 4699{
4700 struct nfs4_slot *new = NULL;
4420 int i; 4701 int i;
4421 int ret = 0; 4702 int ret = 0;
4422 4703
4423 dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__, max_slots, tbl); 4704 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
4705 max_reqs, tbl->max_slots);
4424 4706
4425 /* 4707 /* Does the newly negotiated max_reqs match the existing slot table? */
4426 * Until we have dynamic slot table adjustment, insist 4708 if (max_reqs != tbl->max_slots) {
4427 * upon the same slot table size 4709 ret = -ENOMEM;
4428 */ 4710 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
4429 if (max_slots != old_max_slots) { 4711 GFP_NOFS);
4430 dprintk("%s reset slot table does't match old\n", 4712 if (!new)
4431 __func__); 4713 goto out;
4432 ret = -EINVAL; /*XXX NFS4ERR_REQ_TOO_BIG ? */ 4714 ret = 0;
4433 goto out; 4715 kfree(tbl->slots);
4434 } 4716 }
4435 spin_lock(&tbl->slot_tbl_lock); 4717 spin_lock(&tbl->slot_tbl_lock);
4436 for (i = 0; i < max_slots; ++i) 4718 if (new) {
4719 tbl->slots = new;
4720 tbl->max_slots = max_reqs;
4721 }
4722 for (i = 0; i < tbl->max_slots; ++i)
4437 tbl->slots[i].seq_nr = ivalue; 4723 tbl->slots[i].seq_nr = ivalue;
4438 tbl->highest_used_slotid = -1;
4439 spin_unlock(&tbl->slot_tbl_lock); 4724 spin_unlock(&tbl->slot_tbl_lock);
4440 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, 4725 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4441 tbl, tbl->slots, tbl->max_slots); 4726 tbl, tbl->slots, tbl->max_slots);
@@ -4452,16 +4737,12 @@ static int nfs4_reset_slot_tables(struct nfs4_session *session)
4452 int status; 4737 int status;
4453 4738
4454 status = nfs4_reset_slot_table(&session->fc_slot_table, 4739 status = nfs4_reset_slot_table(&session->fc_slot_table,
4455 session->fc_attrs.max_reqs, 4740 session->fc_attrs.max_reqs, 1);
4456 session->fc_slot_table.max_slots,
4457 1);
4458 if (status) 4741 if (status)
4459 return status; 4742 return status;
4460 4743
4461 status = nfs4_reset_slot_table(&session->bc_slot_table, 4744 status = nfs4_reset_slot_table(&session->bc_slot_table,
4462 session->bc_attrs.max_reqs, 4745 session->bc_attrs.max_reqs, 0);
4463 session->bc_slot_table.max_slots,
4464 0);
4465 return status; 4746 return status;
4466} 4747}
4467 4748
@@ -4485,7 +4766,6 @@ static void nfs4_destroy_slot_tables(struct nfs4_session *session)
4485static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, 4766static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4486 int max_slots, int ivalue) 4767 int max_slots, int ivalue)
4487{ 4768{
4488 int i;
4489 struct nfs4_slot *slot; 4769 struct nfs4_slot *slot;
4490 int ret = -ENOMEM; 4770 int ret = -ENOMEM;
4491 4771
@@ -4493,21 +4773,12 @@ static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4493 4773
4494 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); 4774 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
4495 4775
4496 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL); 4776 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS);
4497 if (!slot) 4777 if (!slot)
4498 goto out; 4778 goto out;
4499 for (i = 0; i < max_slots; ++i)
4500 slot[i].seq_nr = ivalue;
4501 ret = 0; 4779 ret = 0;
4502 4780
4503 spin_lock(&tbl->slot_tbl_lock); 4781 spin_lock(&tbl->slot_tbl_lock);
4504 if (tbl->slots != NULL) {
4505 spin_unlock(&tbl->slot_tbl_lock);
4506 dprintk("%s: slot table already initialized. tbl=%p slots=%p\n",
4507 __func__, tbl, tbl->slots);
4508 WARN_ON(1);
4509 goto out_free;
4510 }
4511 tbl->max_slots = max_slots; 4782 tbl->max_slots = max_slots;
4512 tbl->slots = slot; 4783 tbl->slots = slot;
4513 tbl->highest_used_slotid = -1; /* no slot is currently used */ 4784 tbl->highest_used_slotid = -1; /* no slot is currently used */
@@ -4517,10 +4788,6 @@ static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4517out: 4788out:
4518 dprintk("<-- %s: return %d\n", __func__, ret); 4789 dprintk("<-- %s: return %d\n", __func__, ret);
4519 return ret; 4790 return ret;
4520
4521out_free:
4522 kfree(slot);
4523 goto out;
4524} 4791}
4525 4792
4526/* 4793/*
@@ -4528,17 +4795,24 @@ out_free:
4528 */ 4795 */
4529static int nfs4_init_slot_tables(struct nfs4_session *session) 4796static int nfs4_init_slot_tables(struct nfs4_session *session)
4530{ 4797{
4531 int status; 4798 struct nfs4_slot_table *tbl;
4799 int status = 0;
4532 4800
4533 status = nfs4_init_slot_table(&session->fc_slot_table, 4801 tbl = &session->fc_slot_table;
4534 session->fc_attrs.max_reqs, 1); 4802 if (tbl->slots == NULL) {
4535 if (status) 4803 status = nfs4_init_slot_table(tbl,
4536 return status; 4804 session->fc_attrs.max_reqs, 1);
4805 if (status)
4806 return status;
4807 }
4537 4808
4538 status = nfs4_init_slot_table(&session->bc_slot_table, 4809 tbl = &session->bc_slot_table;
4539 session->bc_attrs.max_reqs, 0); 4810 if (tbl->slots == NULL) {
4540 if (status) 4811 status = nfs4_init_slot_table(tbl,
4541 nfs4_destroy_slot_tables(session); 4812 session->bc_attrs.max_reqs, 0);
4813 if (status)
4814 nfs4_destroy_slot_tables(session);
4815 }
4542 4816
4543 return status; 4817 return status;
4544} 4818}
@@ -4548,26 +4822,23 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
4548 struct nfs4_session *session; 4822 struct nfs4_session *session;
4549 struct nfs4_slot_table *tbl; 4823 struct nfs4_slot_table *tbl;
4550 4824
4551 session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL); 4825 session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
4552 if (!session) 4826 if (!session)
4553 return NULL; 4827 return NULL;
4554 4828
4555 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
4556 /*
4557 * The create session reply races with the server back
4558 * channel probe. Mark the client NFS_CS_SESSION_INITING
4559 * so that the client back channel can find the
4560 * nfs_client struct
4561 */
4562 clp->cl_cons_state = NFS_CS_SESSION_INITING;
4563
4564 tbl = &session->fc_slot_table; 4829 tbl = &session->fc_slot_table;
4830 tbl->highest_used_slotid = -1;
4565 spin_lock_init(&tbl->slot_tbl_lock); 4831 spin_lock_init(&tbl->slot_tbl_lock);
4566 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); 4832 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
4833 init_completion(&tbl->complete);
4567 4834
4568 tbl = &session->bc_slot_table; 4835 tbl = &session->bc_slot_table;
4836 tbl->highest_used_slotid = -1;
4569 spin_lock_init(&tbl->slot_tbl_lock); 4837 spin_lock_init(&tbl->slot_tbl_lock);
4570 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); 4838 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
4839 init_completion(&tbl->complete);
4840
4841 session->session_state = 1<<NFS4_SESSION_INITING;
4571 4842
4572 session->clp = clp; 4843 session->clp = clp;
4573 return session; 4844 return session;
@@ -4607,16 +4878,14 @@ static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
4607 args->fc_attrs.headerpadsz = 0; 4878 args->fc_attrs.headerpadsz = 0;
4608 args->fc_attrs.max_rqst_sz = mxrqst_sz; 4879 args->fc_attrs.max_rqst_sz = mxrqst_sz;
4609 args->fc_attrs.max_resp_sz = mxresp_sz; 4880 args->fc_attrs.max_resp_sz = mxresp_sz;
4610 args->fc_attrs.max_resp_sz_cached = mxresp_sz;
4611 args->fc_attrs.max_ops = NFS4_MAX_OPS; 4881 args->fc_attrs.max_ops = NFS4_MAX_OPS;
4612 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; 4882 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
4613 4883
4614 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " 4884 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4615 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", 4885 "max_ops=%u max_reqs=%u\n",
4616 __func__, 4886 __func__,
4617 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, 4887 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
4618 args->fc_attrs.max_resp_sz_cached, args->fc_attrs.max_ops, 4888 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
4619 args->fc_attrs.max_reqs);
4620 4889
4621 /* Back channel attributes */ 4890 /* Back channel attributes */
4622 args->bc_attrs.headerpadsz = 0; 4891 args->bc_attrs.headerpadsz = 0;
@@ -4634,49 +4903,56 @@ static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
4634 args->bc_attrs.max_reqs); 4903 args->bc_attrs.max_reqs);
4635} 4904}
4636 4905
4637static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd) 4906static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
4638{ 4907{
4639 if (rcvd <= sent) 4908 struct nfs4_channel_attrs *sent = &args->fc_attrs;
4640 return 0; 4909 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
4641 printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. " 4910
4642 "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd); 4911 if (rcvd->headerpadsz > sent->headerpadsz)
4643 return -EINVAL; 4912 return -EINVAL;
4913 if (rcvd->max_resp_sz > sent->max_resp_sz)
4914 return -EINVAL;
4915 /*
4916 * Our requested max_ops is the minimum we need; we're not
4917 * prepared to break up compounds into smaller pieces than that.
4918 * So, no point even trying to continue if the server won't
4919 * cooperate:
4920 */
4921 if (rcvd->max_ops < sent->max_ops)
4922 return -EINVAL;
4923 if (rcvd->max_reqs == 0)
4924 return -EINVAL;
4925 return 0;
4644} 4926}
4645 4927
4646#define _verify_fore_channel_attr(_name_) \ 4928static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
4647 _verify_channel_attr("fore", #_name_, \ 4929{
4648 args->fc_attrs._name_, \ 4930 struct nfs4_channel_attrs *sent = &args->bc_attrs;
4649 session->fc_attrs._name_) 4931 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
4650 4932
4651#define _verify_back_channel_attr(_name_) \ 4933 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
4652 _verify_channel_attr("back", #_name_, \ 4934 return -EINVAL;
4653 args->bc_attrs._name_, \ 4935 if (rcvd->max_resp_sz < sent->max_resp_sz)
4654 session->bc_attrs._name_) 4936 return -EINVAL;
4937 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
4938 return -EINVAL;
4939 /* These would render the backchannel useless: */
4940 if (rcvd->max_ops == 0)
4941 return -EINVAL;
4942 if (rcvd->max_reqs == 0)
4943 return -EINVAL;
4944 return 0;
4945}
4655 4946
4656/*
4657 * The server is not allowed to increase the fore channel header pad size,
4658 * maximum response size, or maximum number of operations.
4659 *
4660 * The back channel attributes are only negotiatied down: We send what the
4661 * (back channel) server insists upon.
4662 */
4663static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, 4947static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
4664 struct nfs4_session *session) 4948 struct nfs4_session *session)
4665{ 4949{
4666 int ret = 0; 4950 int ret;
4667
4668 ret |= _verify_fore_channel_attr(headerpadsz);
4669 ret |= _verify_fore_channel_attr(max_resp_sz);
4670 ret |= _verify_fore_channel_attr(max_ops);
4671
4672 ret |= _verify_back_channel_attr(headerpadsz);
4673 ret |= _verify_back_channel_attr(max_rqst_sz);
4674 ret |= _verify_back_channel_attr(max_resp_sz);
4675 ret |= _verify_back_channel_attr(max_resp_sz_cached);
4676 ret |= _verify_back_channel_attr(max_ops);
4677 ret |= _verify_back_channel_attr(max_reqs);
4678 4951
4679 return ret; 4952 ret = nfs4_verify_fore_channel_attrs(args, session);
4953 if (ret)
4954 return ret;
4955 return nfs4_verify_back_channel_attrs(args, session);
4680} 4956}
4681 4957
4682static int _nfs4_proc_create_session(struct nfs_client *clp) 4958static int _nfs4_proc_create_session(struct nfs_client *clp)
@@ -4717,11 +4993,10 @@ static int _nfs4_proc_create_session(struct nfs_client *clp)
4717 * It is the responsibility of the caller to verify the session is 4993 * It is the responsibility of the caller to verify the session is
4718 * expired before calling this routine. 4994 * expired before calling this routine.
4719 */ 4995 */
4720int nfs4_proc_create_session(struct nfs_client *clp, int reset) 4996int nfs4_proc_create_session(struct nfs_client *clp)
4721{ 4997{
4722 int status; 4998 int status;
4723 unsigned *ptr; 4999 unsigned *ptr;
4724 struct nfs_fsinfo fsinfo;
4725 struct nfs4_session *session = clp->cl_session; 5000 struct nfs4_session *session = clp->cl_session;
4726 5001
4727 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); 5002 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
@@ -4730,35 +5005,19 @@ int nfs4_proc_create_session(struct nfs_client *clp, int reset)
4730 if (status) 5005 if (status)
4731 goto out; 5006 goto out;
4732 5007
4733 /* Init or reset the fore channel */ 5008 /* Init and reset the fore channel */
4734 if (reset) 5009 status = nfs4_init_slot_tables(session);
4735 status = nfs4_reset_slot_tables(session); 5010 dprintk("slot table initialization returned %d\n", status);
4736 else 5011 if (status)
4737 status = nfs4_init_slot_tables(session); 5012 goto out;
4738 dprintk("fore channel slot table initialization returned %d\n", status); 5013 status = nfs4_reset_slot_tables(session);
5014 dprintk("slot table reset returned %d\n", status);
4739 if (status) 5015 if (status)
4740 goto out; 5016 goto out;
4741 5017
4742 ptr = (unsigned *)&session->sess_id.data[0]; 5018 ptr = (unsigned *)&session->sess_id.data[0];
4743 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, 5019 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
4744 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); 5020 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
4745
4746 if (reset)
4747 /* Lease time is aleady set */
4748 goto out;
4749
4750 /* Get the lease time */
4751 status = nfs4_proc_get_lease_time(clp, &fsinfo);
4752 if (status == 0) {
4753 /* Update lease time and schedule renewal */
4754 spin_lock(&clp->cl_lock);
4755 clp->cl_lease_time = fsinfo.lease_time * HZ;
4756 clp->cl_last_renewal = jiffies;
4757 clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
4758 spin_unlock(&clp->cl_lock);
4759
4760 nfs4_schedule_state_renewal(clp);
4761 }
4762out: 5021out:
4763 dprintk("<-- %s\n", __func__); 5022 dprintk("<-- %s\n", __func__);
4764 return status; 5023 return status;
@@ -4794,63 +5053,102 @@ int nfs4_proc_destroy_session(struct nfs4_session *session)
4794 return status; 5053 return status;
4795} 5054}
4796 5055
5056int nfs4_init_session(struct nfs_server *server)
5057{
5058 struct nfs_client *clp = server->nfs_client;
5059 struct nfs4_session *session;
5060 unsigned int rsize, wsize;
5061 int ret;
5062
5063 if (!nfs4_has_session(clp))
5064 return 0;
5065
5066 session = clp->cl_session;
5067 if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state))
5068 return 0;
5069
5070 rsize = server->rsize;
5071 if (rsize == 0)
5072 rsize = NFS_MAX_FILE_IO_SIZE;
5073 wsize = server->wsize;
5074 if (wsize == 0)
5075 wsize = NFS_MAX_FILE_IO_SIZE;
5076
5077 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5078 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5079
5080 ret = nfs4_recover_expired_lease(server);
5081 if (!ret)
5082 ret = nfs4_check_client_ready(clp);
5083 return ret;
5084}
5085
4797/* 5086/*
4798 * Renew the cl_session lease. 5087 * Renew the cl_session lease.
4799 */ 5088 */
4800static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) 5089struct nfs4_sequence_data {
4801{ 5090 struct nfs_client *clp;
4802 struct nfs4_sequence_args args; 5091 struct nfs4_sequence_args args;
4803 struct nfs4_sequence_res res; 5092 struct nfs4_sequence_res res;
5093};
4804 5094
4805 struct rpc_message msg = { 5095static void nfs41_sequence_release(void *data)
4806 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], 5096{
4807 .rpc_argp = &args, 5097 struct nfs4_sequence_data *calldata = data;
4808 .rpc_resp = &res, 5098 struct nfs_client *clp = calldata->clp;
4809 .rpc_cred = cred,
4810 };
4811 5099
4812 args.sa_cache_this = 0; 5100 if (atomic_read(&clp->cl_count) > 1)
5101 nfs4_schedule_state_renewal(clp);
5102 nfs_put_client(clp);
5103 kfree(calldata);
5104}
4813 5105
4814 return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args, 5106static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
4815 &res, 0); 5107{
5108 switch(task->tk_status) {
5109 case -NFS4ERR_DELAY:
5110 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5111 return -EAGAIN;
5112 default:
5113 nfs4_schedule_state_recovery(clp);
5114 }
5115 return 0;
4816} 5116}
4817 5117
4818void nfs41_sequence_call_done(struct rpc_task *task, void *data) 5118static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
4819{ 5119{
4820 struct nfs_client *clp = (struct nfs_client *)data; 5120 struct nfs4_sequence_data *calldata = data;
5121 struct nfs_client *clp = calldata->clp;
4821 5122
4822 nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status); 5123 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
5124 return;
4823 5125
4824 if (task->tk_status < 0) { 5126 if (task->tk_status < 0) {
4825 dprintk("%s ERROR %d\n", __func__, task->tk_status); 5127 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5128 if (atomic_read(&clp->cl_count) == 1)
5129 goto out;
4826 5130
4827 if (_nfs4_async_handle_error(task, NULL, clp, NULL) 5131 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
4828 == -EAGAIN) { 5132 rpc_restart_call_prepare(task);
4829 nfs4_restart_rpc(task, clp);
4830 return; 5133 return;
4831 } 5134 }
4832 } 5135 }
4833 nfs41_sequence_free_slot(clp, task->tk_msg.rpc_resp);
4834 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); 5136 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
4835 5137out:
4836 put_rpccred(task->tk_msg.rpc_cred);
4837 kfree(task->tk_msg.rpc_argp);
4838 kfree(task->tk_msg.rpc_resp);
4839
4840 dprintk("<-- %s\n", __func__); 5138 dprintk("<-- %s\n", __func__);
4841} 5139}
4842 5140
4843static void nfs41_sequence_prepare(struct rpc_task *task, void *data) 5141static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
4844{ 5142{
4845 struct nfs_client *clp; 5143 struct nfs4_sequence_data *calldata = data;
5144 struct nfs_client *clp = calldata->clp;
4846 struct nfs4_sequence_args *args; 5145 struct nfs4_sequence_args *args;
4847 struct nfs4_sequence_res *res; 5146 struct nfs4_sequence_res *res;
4848 5147
4849 clp = (struct nfs_client *)data;
4850 args = task->tk_msg.rpc_argp; 5148 args = task->tk_msg.rpc_argp;
4851 res = task->tk_msg.rpc_resp; 5149 res = task->tk_msg.rpc_resp;
4852 5150
4853 if (nfs4_setup_sequence(clp, args, res, 0, task)) 5151 if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task))
4854 return; 5152 return;
4855 rpc_call_start(task); 5153 rpc_call_start(task);
4856} 5154}
@@ -4858,33 +5156,320 @@ static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
4858static const struct rpc_call_ops nfs41_sequence_ops = { 5156static const struct rpc_call_ops nfs41_sequence_ops = {
4859 .rpc_call_done = nfs41_sequence_call_done, 5157 .rpc_call_done = nfs41_sequence_call_done,
4860 .rpc_call_prepare = nfs41_sequence_prepare, 5158 .rpc_call_prepare = nfs41_sequence_prepare,
5159 .rpc_release = nfs41_sequence_release,
4861}; 5160};
4862 5161
4863static int nfs41_proc_async_sequence(struct nfs_client *clp, 5162static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
4864 struct rpc_cred *cred)
4865{ 5163{
4866 struct nfs4_sequence_args *args; 5164 struct nfs4_sequence_data *calldata;
4867 struct nfs4_sequence_res *res;
4868 struct rpc_message msg = { 5165 struct rpc_message msg = {
4869 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], 5166 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
4870 .rpc_cred = cred, 5167 .rpc_cred = cred,
4871 }; 5168 };
5169 struct rpc_task_setup task_setup_data = {
5170 .rpc_client = clp->cl_rpcclient,
5171 .rpc_message = &msg,
5172 .callback_ops = &nfs41_sequence_ops,
5173 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
5174 };
4872 5175
4873 args = kzalloc(sizeof(*args), GFP_KERNEL); 5176 if (!atomic_inc_not_zero(&clp->cl_count))
4874 if (!args) 5177 return ERR_PTR(-EIO);
4875 return -ENOMEM; 5178 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
4876 res = kzalloc(sizeof(*res), GFP_KERNEL); 5179 if (calldata == NULL) {
4877 if (!res) { 5180 nfs_put_client(clp);
4878 kfree(args); 5181 return ERR_PTR(-ENOMEM);
5182 }
5183 msg.rpc_argp = &calldata->args;
5184 msg.rpc_resp = &calldata->res;
5185 calldata->clp = clp;
5186 task_setup_data.callback_data = calldata;
5187
5188 return rpc_run_task(&task_setup_data);
5189}
5190
5191static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5192{
5193 struct rpc_task *task;
5194 int ret = 0;
5195
5196 task = _nfs41_proc_sequence(clp, cred);
5197 if (IS_ERR(task))
5198 ret = PTR_ERR(task);
5199 else
5200 rpc_put_task(task);
5201 dprintk("<-- %s status=%d\n", __func__, ret);
5202 return ret;
5203}
5204
5205static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5206{
5207 struct rpc_task *task;
5208 int ret;
5209
5210 task = _nfs41_proc_sequence(clp, cred);
5211 if (IS_ERR(task)) {
5212 ret = PTR_ERR(task);
5213 goto out;
5214 }
5215 ret = rpc_wait_for_completion_task(task);
5216 if (!ret)
5217 ret = task->tk_status;
5218 rpc_put_task(task);
5219out:
5220 dprintk("<-- %s status=%d\n", __func__, ret);
5221 return ret;
5222}
5223
5224struct nfs4_reclaim_complete_data {
5225 struct nfs_client *clp;
5226 struct nfs41_reclaim_complete_args arg;
5227 struct nfs41_reclaim_complete_res res;
5228};
5229
5230static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5231{
5232 struct nfs4_reclaim_complete_data *calldata = data;
5233
5234 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5235 if (nfs41_setup_sequence(calldata->clp->cl_session,
5236 &calldata->arg.seq_args,
5237 &calldata->res.seq_res, 0, task))
5238 return;
5239
5240 rpc_call_start(task);
5241}
5242
5243static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5244{
5245 switch(task->tk_status) {
5246 case 0:
5247 case -NFS4ERR_COMPLETE_ALREADY:
5248 case -NFS4ERR_WRONG_CRED: /* What to do here? */
5249 break;
5250 case -NFS4ERR_DELAY:
5251 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5252 return -EAGAIN;
5253 default:
5254 nfs4_schedule_state_recovery(clp);
5255 }
5256 return 0;
5257}
5258
5259static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
5260{
5261 struct nfs4_reclaim_complete_data *calldata = data;
5262 struct nfs_client *clp = calldata->clp;
5263 struct nfs4_sequence_res *res = &calldata->res.seq_res;
5264
5265 dprintk("--> %s\n", __func__);
5266 if (!nfs41_sequence_done(task, res))
5267 return;
5268
5269 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
5270 rpc_restart_call_prepare(task);
5271 return;
5272 }
5273 dprintk("<-- %s\n", __func__);
5274}
5275
5276static void nfs4_free_reclaim_complete_data(void *data)
5277{
5278 struct nfs4_reclaim_complete_data *calldata = data;
5279
5280 kfree(calldata);
5281}
5282
5283static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
5284 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
5285 .rpc_call_done = nfs4_reclaim_complete_done,
5286 .rpc_release = nfs4_free_reclaim_complete_data,
5287};
5288
5289/*
5290 * Issue a global reclaim complete.
5291 */
5292static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5293{
5294 struct nfs4_reclaim_complete_data *calldata;
5295 struct rpc_task *task;
5296 struct rpc_message msg = {
5297 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
5298 };
5299 struct rpc_task_setup task_setup_data = {
5300 .rpc_client = clp->cl_rpcclient,
5301 .rpc_message = &msg,
5302 .callback_ops = &nfs4_reclaim_complete_call_ops,
5303 .flags = RPC_TASK_ASYNC,
5304 };
5305 int status = -ENOMEM;
5306
5307 dprintk("--> %s\n", __func__);
5308 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5309 if (calldata == NULL)
5310 goto out;
5311 calldata->clp = clp;
5312 calldata->arg.one_fs = 0;
5313
5314 msg.rpc_argp = &calldata->arg;
5315 msg.rpc_resp = &calldata->res;
5316 task_setup_data.callback_data = calldata;
5317 task = rpc_run_task(&task_setup_data);
5318 if (IS_ERR(task)) {
5319 status = PTR_ERR(task);
5320 goto out;
5321 }
5322 rpc_put_task(task);
5323 return 0;
5324out:
5325 dprintk("<-- %s status=%d\n", __func__, status);
5326 return status;
5327}
5328
5329static void
5330nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
5331{
5332 struct nfs4_layoutget *lgp = calldata;
5333 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
5334
5335 dprintk("--> %s\n", __func__);
5336 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5337 * right now covering the LAYOUTGET we are about to send.
5338 * However, that is not so catastrophic, and there seems
5339 * to be no way to prevent it completely.
5340 */
5341 if (nfs4_setup_sequence(server, &lgp->args.seq_args,
5342 &lgp->res.seq_res, 0, task))
5343 return;
5344 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
5345 NFS_I(lgp->args.inode)->layout,
5346 lgp->args.ctx->state)) {
5347 rpc_exit(task, NFS4_OK);
5348 return;
5349 }
5350 rpc_call_start(task);
5351}
5352
5353static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
5354{
5355 struct nfs4_layoutget *lgp = calldata;
5356 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
5357
5358 dprintk("--> %s\n", __func__);
5359
5360 if (!nfs4_sequence_done(task, &lgp->res.seq_res))
5361 return;
5362
5363 switch (task->tk_status) {
5364 case 0:
5365 break;
5366 case -NFS4ERR_LAYOUTTRYLATER:
5367 case -NFS4ERR_RECALLCONFLICT:
5368 task->tk_status = -NFS4ERR_DELAY;
5369 /* Fall through */
5370 default:
5371 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
5372 rpc_restart_call_prepare(task);
5373 return;
5374 }
5375 }
5376 dprintk("<-- %s\n", __func__);
5377}
5378
5379static void nfs4_layoutget_release(void *calldata)
5380{
5381 struct nfs4_layoutget *lgp = calldata;
5382
5383 dprintk("--> %s\n", __func__);
5384 if (lgp->res.layout.buf != NULL)
5385 free_page((unsigned long) lgp->res.layout.buf);
5386 put_nfs_open_context(lgp->args.ctx);
5387 kfree(calldata);
5388 dprintk("<-- %s\n", __func__);
5389}
5390
5391static const struct rpc_call_ops nfs4_layoutget_call_ops = {
5392 .rpc_call_prepare = nfs4_layoutget_prepare,
5393 .rpc_call_done = nfs4_layoutget_done,
5394 .rpc_release = nfs4_layoutget_release,
5395};
5396
5397int nfs4_proc_layoutget(struct nfs4_layoutget *lgp)
5398{
5399 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
5400 struct rpc_task *task;
5401 struct rpc_message msg = {
5402 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
5403 .rpc_argp = &lgp->args,
5404 .rpc_resp = &lgp->res,
5405 };
5406 struct rpc_task_setup task_setup_data = {
5407 .rpc_client = server->client,
5408 .rpc_message = &msg,
5409 .callback_ops = &nfs4_layoutget_call_ops,
5410 .callback_data = lgp,
5411 .flags = RPC_TASK_ASYNC,
5412 };
5413 int status = 0;
5414
5415 dprintk("--> %s\n", __func__);
5416
5417 lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS);
5418 if (lgp->res.layout.buf == NULL) {
5419 nfs4_layoutget_release(lgp);
4879 return -ENOMEM; 5420 return -ENOMEM;
4880 } 5421 }
4881 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
4882 msg.rpc_argp = args;
4883 msg.rpc_resp = res;
4884 5422
4885 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, 5423 lgp->res.seq_res.sr_slot = NULL;
4886 &nfs41_sequence_ops, (void *)clp); 5424 task = rpc_run_task(&task_setup_data);
5425 if (IS_ERR(task))
5426 return PTR_ERR(task);
5427 status = nfs4_wait_for_completion_rpc_task(task);
5428 if (status == 0)
5429 status = task->tk_status;
5430 if (status == 0)
5431 status = pnfs_layout_process(lgp);
5432 rpc_put_task(task);
5433 dprintk("<-- %s status=%d\n", __func__, status);
5434 return status;
5435}
5436
5437static int
5438_nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
5439{
5440 struct nfs4_getdeviceinfo_args args = {
5441 .pdev = pdev,
5442 };
5443 struct nfs4_getdeviceinfo_res res = {
5444 .pdev = pdev,
5445 };
5446 struct rpc_message msg = {
5447 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
5448 .rpc_argp = &args,
5449 .rpc_resp = &res,
5450 };
5451 int status;
5452
5453 dprintk("--> %s\n", __func__);
5454 status = nfs4_call_sync(server, &msg, &args, &res, 0);
5455 dprintk("<-- %s status=%d\n", __func__, status);
5456
5457 return status;
5458}
5459
5460int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
5461{
5462 struct nfs4_exception exception = { };
5463 int err;
5464
5465 do {
5466 err = nfs4_handle_exception(server,
5467 _nfs4_proc_getdeviceinfo(server, pdev),
5468 &exception);
5469 } while (exception.retry);
5470 return err;
4887} 5471}
5472EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
4888 5473
4889#endif /* CONFIG_NFS_V4_1 */ 5474#endif /* CONFIG_NFS_V4_1 */
4890 5475
@@ -4903,8 +5488,9 @@ struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
4903 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 5488 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
4904 .recover_open = nfs4_open_reclaim, 5489 .recover_open = nfs4_open_reclaim,
4905 .recover_lock = nfs4_lock_reclaim, 5490 .recover_lock = nfs4_lock_reclaim,
4906 .establish_clid = nfs4_proc_exchange_id, 5491 .establish_clid = nfs41_init_clientid,
4907 .get_clid_cred = nfs4_get_exchange_id_cred, 5492 .get_clid_cred = nfs4_get_exchange_id_cred,
5493 .reclaim_complete = nfs41_proc_reclaim_complete,
4908}; 5494};
4909#endif /* CONFIG_NFS_V4_1 */ 5495#endif /* CONFIG_NFS_V4_1 */
4910 5496
@@ -4923,7 +5509,7 @@ struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
4923 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 5509 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
4924 .recover_open = nfs4_open_expired, 5510 .recover_open = nfs4_open_expired,
4925 .recover_lock = nfs4_lock_expired, 5511 .recover_lock = nfs4_lock_expired,
4926 .establish_clid = nfs4_proc_exchange_id, 5512 .establish_clid = nfs41_init_clientid,
4927 .get_clid_cred = nfs4_get_exchange_id_cred, 5513 .get_clid_cred = nfs4_get_exchange_id_cred,
4928}; 5514};
4929#endif /* CONFIG_NFS_V4_1 */ 5515#endif /* CONFIG_NFS_V4_1 */
@@ -4942,28 +5528,30 @@ struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
4942}; 5528};
4943#endif 5529#endif
4944 5530
4945/* 5531static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
4946 * Per minor version reboot and network partition recovery ops 5532 .minor_version = 0,
4947 */ 5533 .call_sync = _nfs4_call_sync,
4948 5534 .validate_stateid = nfs4_validate_delegation_stateid,
4949struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = { 5535 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
4950 &nfs40_reboot_recovery_ops, 5536 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
4951#if defined(CONFIG_NFS_V4_1) 5537 .state_renewal_ops = &nfs40_state_renewal_ops,
4952 &nfs41_reboot_recovery_ops,
4953#endif
4954}; 5538};
4955 5539
4956struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = {
4957 &nfs40_nograce_recovery_ops,
4958#if defined(CONFIG_NFS_V4_1) 5540#if defined(CONFIG_NFS_V4_1)
4959 &nfs41_nograce_recovery_ops, 5541static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
4960#endif 5542 .minor_version = 1,
5543 .call_sync = _nfs4_call_sync_session,
5544 .validate_stateid = nfs41_validate_delegation_stateid,
5545 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
5546 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
5547 .state_renewal_ops = &nfs41_state_renewal_ops,
4961}; 5548};
5549#endif
4962 5550
4963struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = { 5551const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
4964 &nfs40_state_renewal_ops, 5552 [0] = &nfs_v4_0_minor_ops,
4965#if defined(CONFIG_NFS_V4_1) 5553#if defined(CONFIG_NFS_V4_1)
4966 &nfs41_state_renewal_ops, 5554 [1] = &nfs_v4_1_minor_ops,
4967#endif 5555#endif
4968}; 5556};
4969 5557
@@ -4971,9 +5559,10 @@ static const struct inode_operations nfs4_file_inode_operations = {
4971 .permission = nfs_permission, 5559 .permission = nfs_permission,
4972 .getattr = nfs_getattr, 5560 .getattr = nfs_getattr,
4973 .setattr = nfs_setattr, 5561 .setattr = nfs_setattr,
4974 .getxattr = nfs4_getxattr, 5562 .getxattr = generic_getxattr,
4975 .setxattr = nfs4_setxattr, 5563 .setxattr = generic_setxattr,
4976 .listxattr = nfs4_listxattr, 5564 .listxattr = generic_listxattr,
5565 .removexattr = generic_removexattr,
4977}; 5566};
4978 5567
4979const struct nfs_rpc_ops nfs_v4_clientops = { 5568const struct nfs_rpc_ops nfs_v4_clientops = {
@@ -4993,6 +5582,8 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
4993 .unlink_setup = nfs4_proc_unlink_setup, 5582 .unlink_setup = nfs4_proc_unlink_setup,
4994 .unlink_done = nfs4_proc_unlink_done, 5583 .unlink_done = nfs4_proc_unlink_done,
4995 .rename = nfs4_proc_rename, 5584 .rename = nfs4_proc_rename,
5585 .rename_setup = nfs4_proc_rename_setup,
5586 .rename_done = nfs4_proc_rename_done,
4996 .link = nfs4_proc_link, 5587 .link = nfs4_proc_link,
4997 .symlink = nfs4_proc_symlink, 5588 .symlink = nfs4_proc_symlink,
4998 .mkdir = nfs4_proc_mkdir, 5589 .mkdir = nfs4_proc_mkdir,
@@ -5013,6 +5604,19 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
5013 .lock = nfs4_proc_lock, 5604 .lock = nfs4_proc_lock,
5014 .clear_acl_cache = nfs4_zap_acl_attr, 5605 .clear_acl_cache = nfs4_zap_acl_attr,
5015 .close_context = nfs4_close_context, 5606 .close_context = nfs4_close_context,
5607 .open_context = nfs4_atomic_open,
5608};
5609
5610static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
5611 .prefix = XATTR_NAME_NFSV4_ACL,
5612 .list = nfs4_xattr_list_nfs4_acl,
5613 .get = nfs4_xattr_get_nfs4_acl,
5614 .set = nfs4_xattr_set_nfs4_acl,
5615};
5616
5617const struct xattr_handler *nfs4_xattr_handlers[] = {
5618 &nfs4_xattr_nfs4_acl_handler,
5619 NULL
5016}; 5620};
5017 5621
5018/* 5622/*
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index e27c6cef18f2..402143d75fc5 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -36,11 +36,6 @@
36 * as an rpc_task, not a real kernel thread, so it always runs in rpciod's 36 * as an rpc_task, not a real kernel thread, so it always runs in rpciod's
37 * context. There is one renewd per nfs_server. 37 * context. There is one renewd per nfs_server.
38 * 38 *
39 * TODO: If the send queue gets backlogged (e.g., if the server goes down),
40 * we will keep filling the queue with periodic RENEW requests. We need a
41 * mechanism for ensuring that if renewd successfully sends off a request,
42 * then it only wakes up when the request is finished. Maybe use the
43 * child task framework of the RPC layer?
44 */ 39 */
45 40
46#include <linux/mm.h> 41#include <linux/mm.h>
@@ -59,29 +54,33 @@
59void 54void
60nfs4_renew_state(struct work_struct *work) 55nfs4_renew_state(struct work_struct *work)
61{ 56{
62 struct nfs4_state_maintenance_ops *ops; 57 const struct nfs4_state_maintenance_ops *ops;
63 struct nfs_client *clp = 58 struct nfs_client *clp =
64 container_of(work, struct nfs_client, cl_renewd.work); 59 container_of(work, struct nfs_client, cl_renewd.work);
65 struct rpc_cred *cred; 60 struct rpc_cred *cred;
66 long lease, timeout; 61 long lease;
67 unsigned long last, now; 62 unsigned long last, now;
68 63
69 ops = nfs4_state_renewal_ops[clp->cl_minorversion]; 64 ops = clp->cl_mvops->state_renewal_ops;
70 dprintk("%s: start\n", __func__); 65 dprintk("%s: start\n", __func__);
71 /* Are there any active superblocks? */ 66
72 if (list_empty(&clp->cl_superblocks)) 67 rcu_read_lock();
68 if (list_empty(&clp->cl_superblocks)) {
69 rcu_read_unlock();
73 goto out; 70 goto out;
71 }
72 rcu_read_unlock();
73
74 spin_lock(&clp->cl_lock); 74 spin_lock(&clp->cl_lock);
75 lease = clp->cl_lease_time; 75 lease = clp->cl_lease_time;
76 last = clp->cl_last_renewal; 76 last = clp->cl_last_renewal;
77 now = jiffies; 77 now = jiffies;
78 timeout = (2 * lease) / 3 + (long)last - (long)now;
79 /* Are we close to a lease timeout? */ 78 /* Are we close to a lease timeout? */
80 if (time_after(now, last + lease/3)) { 79 if (time_after(now, last + lease/3)) {
81 cred = ops->get_state_renewal_cred_locked(clp); 80 cred = ops->get_state_renewal_cred_locked(clp);
82 spin_unlock(&clp->cl_lock); 81 spin_unlock(&clp->cl_lock);
83 if (cred == NULL) { 82 if (cred == NULL) {
84 if (list_empty(&clp->cl_delegations)) { 83 if (!nfs_delegations_present(clp)) {
85 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 84 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
86 goto out; 85 goto out;
87 } 86 }
@@ -90,19 +89,15 @@ nfs4_renew_state(struct work_struct *work)
90 /* Queue an asynchronous RENEW. */ 89 /* Queue an asynchronous RENEW. */
91 ops->sched_state_renewal(clp, cred); 90 ops->sched_state_renewal(clp, cred);
92 put_rpccred(cred); 91 put_rpccred(cred);
92 goto out_exp;
93 } 93 }
94 timeout = (2 * lease) / 3; 94 } else {
95 spin_lock(&clp->cl_lock);
96 } else
97 dprintk("%s: failed to call renewd. Reason: lease not expired \n", 95 dprintk("%s: failed to call renewd. Reason: lease not expired \n",
98 __func__); 96 __func__);
99 if (timeout < 5 * HZ) /* safeguard */ 97 spin_unlock(&clp->cl_lock);
100 timeout = 5 * HZ; 98 }
101 dprintk("%s: requeueing work. Lease period = %ld\n", 99 nfs4_schedule_state_renewal(clp);
102 __func__, (timeout + HZ - 1) / HZ); 100out_exp:
103 cancel_delayed_work(&clp->cl_renewd);
104 schedule_delayed_work(&clp->cl_renewd, timeout);
105 spin_unlock(&clp->cl_lock);
106 nfs_expire_unreferenced_delegations(clp); 101 nfs_expire_unreferenced_delegations(clp);
107out: 102out:
108 dprintk("%s: done\n", __func__); 103 dprintk("%s: done\n", __func__);
@@ -127,12 +122,6 @@ nfs4_schedule_state_renewal(struct nfs_client *clp)
127} 122}
128 123
129void 124void
130nfs4_renewd_prepare_shutdown(struct nfs_server *server)
131{
132 cancel_delayed_work(&server->nfs_client->cl_renewd);
133}
134
135void
136nfs4_kill_renewd(struct nfs_client *clp) 125nfs4_kill_renewd(struct nfs_client *clp)
137{ 126{
138 cancel_delayed_work_sync(&clp->cl_renewd); 127 cancel_delayed_work_sync(&clp->cl_renewd);
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index b73c5a728655..2336d532cf66 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -40,12 +40,13 @@
40 40
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/smp_lock.h> 43#include <linux/fs.h>
44#include <linux/nfs_fs.h> 44#include <linux/nfs_fs.h>
45#include <linux/nfs_idmap.h> 45#include <linux/nfs_idmap.h>
46#include <linux/kthread.h> 46#include <linux/kthread.h>
47#include <linux/module.h> 47#include <linux/module.h>
48#include <linux/random.h> 48#include <linux/random.h>
49#include <linux/ratelimit.h>
49#include <linux/workqueue.h> 50#include <linux/workqueue.h>
50#include <linux/bitops.h> 51#include <linux/bitops.h>
51 52
@@ -53,6 +54,7 @@
53#include "callback.h" 54#include "callback.h"
54#include "delegation.h" 55#include "delegation.h"
55#include "internal.h" 56#include "internal.h"
57#include "pnfs.h"
56 58
57#define OPENOWNER_POOL_SIZE 8 59#define OPENOWNER_POOL_SIZE 8
58 60
@@ -62,6 +64,7 @@ static LIST_HEAD(nfs4_clientid_list);
62 64
63int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) 65int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
64{ 66{
67 struct nfs4_setclientid_res clid;
65 unsigned short port; 68 unsigned short port;
66 int status; 69 int status;
67 70
@@ -69,11 +72,15 @@ int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
69 if (clp->cl_addr.ss_family == AF_INET6) 72 if (clp->cl_addr.ss_family == AF_INET6)
70 port = nfs_callback_tcpport6; 73 port = nfs_callback_tcpport6;
71 74
72 status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred); 75 status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred, &clid);
73 if (status == 0) 76 if (status != 0)
74 status = nfs4_proc_setclientid_confirm(clp, cred); 77 goto out;
75 if (status == 0) 78 status = nfs4_proc_setclientid_confirm(clp, &clid, cred);
76 nfs4_schedule_state_renewal(clp); 79 if (status != 0)
80 goto out;
81 clp->cl_clientid = clid.clientid;
82 nfs4_schedule_state_renewal(clp);
83out:
77 return status; 84 return status;
78} 85}
79 86
@@ -98,14 +105,17 @@ static void nfs4_clear_machine_cred(struct nfs_client *clp)
98 put_rpccred(cred); 105 put_rpccred(cred);
99} 106}
100 107
101struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) 108static struct rpc_cred *
109nfs4_get_renew_cred_server_locked(struct nfs_server *server)
102{ 110{
111 struct rpc_cred *cred = NULL;
103 struct nfs4_state_owner *sp; 112 struct nfs4_state_owner *sp;
104 struct rb_node *pos; 113 struct rb_node *pos;
105 struct rpc_cred *cred = NULL;
106 114
107 for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { 115 for (pos = rb_first(&server->state_owners);
108 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 116 pos != NULL;
117 pos = rb_next(pos)) {
118 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
109 if (list_empty(&sp->so_states)) 119 if (list_empty(&sp->so_states))
110 continue; 120 continue;
111 cred = get_rpccred(sp->so_cred); 121 cred = get_rpccred(sp->so_cred);
@@ -114,8 +124,126 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
114 return cred; 124 return cred;
115} 125}
116 126
127/**
128 * nfs4_get_renew_cred_locked - Acquire credential for a renew operation
129 * @clp: client state handle
130 *
131 * Returns an rpc_cred with reference count bumped, or NULL.
132 * Caller must hold clp->cl_lock.
133 */
134struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
135{
136 struct rpc_cred *cred = NULL;
137 struct nfs_server *server;
138
139 rcu_read_lock();
140 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
141 cred = nfs4_get_renew_cred_server_locked(server);
142 if (cred != NULL)
143 break;
144 }
145 rcu_read_unlock();
146 return cred;
147}
148
117#if defined(CONFIG_NFS_V4_1) 149#if defined(CONFIG_NFS_V4_1)
118 150
151static int nfs41_setup_state_renewal(struct nfs_client *clp)
152{
153 int status;
154 struct nfs_fsinfo fsinfo;
155
156 status = nfs4_proc_get_lease_time(clp, &fsinfo);
157 if (status == 0) {
158 /* Update lease time and schedule renewal */
159 spin_lock(&clp->cl_lock);
160 clp->cl_lease_time = fsinfo.lease_time * HZ;
161 clp->cl_last_renewal = jiffies;
162 spin_unlock(&clp->cl_lock);
163
164 nfs4_schedule_state_renewal(clp);
165 }
166
167 return status;
168}
169
170/*
171 * Back channel returns NFS4ERR_DELAY for new requests when
172 * NFS4_SESSION_DRAINING is set so there is no work to be done when draining
173 * is ended.
174 */
175static void nfs4_end_drain_session(struct nfs_client *clp)
176{
177 struct nfs4_session *ses = clp->cl_session;
178 int max_slots;
179
180 if (ses == NULL)
181 return;
182 if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
183 spin_lock(&ses->fc_slot_table.slot_tbl_lock);
184 max_slots = ses->fc_slot_table.max_slots;
185 while (max_slots--) {
186 struct rpc_task *task;
187
188 task = rpc_wake_up_next(&ses->fc_slot_table.
189 slot_tbl_waitq);
190 if (!task)
191 break;
192 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
193 }
194 spin_unlock(&ses->fc_slot_table.slot_tbl_lock);
195 }
196}
197
198static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl)
199{
200 spin_lock(&tbl->slot_tbl_lock);
201 if (tbl->highest_used_slotid != -1) {
202 INIT_COMPLETION(tbl->complete);
203 spin_unlock(&tbl->slot_tbl_lock);
204 return wait_for_completion_interruptible(&tbl->complete);
205 }
206 spin_unlock(&tbl->slot_tbl_lock);
207 return 0;
208}
209
210static int nfs4_begin_drain_session(struct nfs_client *clp)
211{
212 struct nfs4_session *ses = clp->cl_session;
213 int ret = 0;
214
215 set_bit(NFS4_SESSION_DRAINING, &ses->session_state);
216 /* back channel */
217 ret = nfs4_wait_on_slot_tbl(&ses->bc_slot_table);
218 if (ret)
219 return ret;
220 /* fore channel */
221 return nfs4_wait_on_slot_tbl(&ses->fc_slot_table);
222}
223
224int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
225{
226 int status;
227
228 nfs4_begin_drain_session(clp);
229 status = nfs4_proc_exchange_id(clp, cred);
230 if (status != 0)
231 goto out;
232 status = nfs4_proc_create_session(clp);
233 if (status != 0)
234 goto out;
235 status = nfs4_set_callback_sessionid(clp);
236 if (status != 0) {
237 printk(KERN_WARNING "Sessionid not set. No callback service\n");
238 nfs_callback_down(1);
239 status = 0;
240 }
241 nfs41_setup_state_renewal(clp);
242 nfs_mark_client_ready(clp, NFS_CS_READY);
243out:
244 return status;
245}
246
119struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp) 247struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)
120{ 248{
121 struct rpc_cred *cred; 249 struct rpc_cred *cred;
@@ -128,28 +256,56 @@ struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)
128 256
129#endif /* CONFIG_NFS_V4_1 */ 257#endif /* CONFIG_NFS_V4_1 */
130 258
131struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp) 259static struct rpc_cred *
260nfs4_get_setclientid_cred_server(struct nfs_server *server)
132{ 261{
262 struct nfs_client *clp = server->nfs_client;
263 struct rpc_cred *cred = NULL;
133 struct nfs4_state_owner *sp; 264 struct nfs4_state_owner *sp;
134 struct rb_node *pos; 265 struct rb_node *pos;
266
267 spin_lock(&clp->cl_lock);
268 pos = rb_first(&server->state_owners);
269 if (pos != NULL) {
270 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
271 cred = get_rpccred(sp->so_cred);
272 }
273 spin_unlock(&clp->cl_lock);
274 return cred;
275}
276
277/**
278 * nfs4_get_setclientid_cred - Acquire credential for a setclientid operation
279 * @clp: client state handle
280 *
281 * Returns an rpc_cred with reference count bumped, or NULL.
282 */
283struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp)
284{
285 struct nfs_server *server;
135 struct rpc_cred *cred; 286 struct rpc_cred *cred;
136 287
137 spin_lock(&clp->cl_lock); 288 spin_lock(&clp->cl_lock);
138 cred = nfs4_get_machine_cred_locked(clp); 289 cred = nfs4_get_machine_cred_locked(clp);
290 spin_unlock(&clp->cl_lock);
139 if (cred != NULL) 291 if (cred != NULL)
140 goto out; 292 goto out;
141 pos = rb_first(&clp->cl_state_owners); 293
142 if (pos != NULL) { 294 rcu_read_lock();
143 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 295 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
144 cred = get_rpccred(sp->so_cred); 296 cred = nfs4_get_setclientid_cred_server(server);
297 if (cred != NULL)
298 break;
145 } 299 }
300 rcu_read_unlock();
301
146out: 302out:
147 spin_unlock(&clp->cl_lock);
148 return cred; 303 return cred;
149} 304}
150 305
151static void nfs_alloc_unique_id(struct rb_root *root, struct nfs_unique_id *new, 306static void nfs_alloc_unique_id_locked(struct rb_root *root,
152 __u64 minval, int maxbits) 307 struct nfs_unique_id *new,
308 __u64 minval, int maxbits)
153{ 309{
154 struct rb_node **p, *parent; 310 struct rb_node **p, *parent;
155 struct nfs_unique_id *pos; 311 struct nfs_unique_id *pos;
@@ -204,16 +360,15 @@ static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id)
204} 360}
205 361
206static struct nfs4_state_owner * 362static struct nfs4_state_owner *
207nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred) 363nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred)
208{ 364{
209 struct nfs_client *clp = server->nfs_client; 365 struct rb_node **p = &server->state_owners.rb_node,
210 struct rb_node **p = &clp->cl_state_owners.rb_node,
211 *parent = NULL; 366 *parent = NULL;
212 struct nfs4_state_owner *sp, *res = NULL; 367 struct nfs4_state_owner *sp, *res = NULL;
213 368
214 while (*p != NULL) { 369 while (*p != NULL) {
215 parent = *p; 370 parent = *p;
216 sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); 371 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
217 372
218 if (server < sp->so_server) { 373 if (server < sp->so_server) {
219 p = &parent->rb_left; 374 p = &parent->rb_left;
@@ -237,24 +392,17 @@ nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred)
237} 392}
238 393
239static struct nfs4_state_owner * 394static struct nfs4_state_owner *
240nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new) 395nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
241{ 396{
242 struct rb_node **p = &clp->cl_state_owners.rb_node, 397 struct nfs_server *server = new->so_server;
398 struct rb_node **p = &server->state_owners.rb_node,
243 *parent = NULL; 399 *parent = NULL;
244 struct nfs4_state_owner *sp; 400 struct nfs4_state_owner *sp;
245 401
246 while (*p != NULL) { 402 while (*p != NULL) {
247 parent = *p; 403 parent = *p;
248 sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); 404 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
249 405
250 if (new->so_server < sp->so_server) {
251 p = &parent->rb_left;
252 continue;
253 }
254 if (new->so_server > sp->so_server) {
255 p = &parent->rb_right;
256 continue;
257 }
258 if (new->so_cred < sp->so_cred) 406 if (new->so_cred < sp->so_cred)
259 p = &parent->rb_left; 407 p = &parent->rb_left;
260 else if (new->so_cred > sp->so_cred) 408 else if (new->so_cred > sp->so_cred)
@@ -264,18 +412,21 @@ nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new)
264 return sp; 412 return sp;
265 } 413 }
266 } 414 }
267 nfs_alloc_unique_id(&clp->cl_openowner_id, &new->so_owner_id, 1, 64); 415 nfs_alloc_unique_id_locked(&server->openowner_id,
268 rb_link_node(&new->so_client_node, parent, p); 416 &new->so_owner_id, 1, 64);
269 rb_insert_color(&new->so_client_node, &clp->cl_state_owners); 417 rb_link_node(&new->so_server_node, parent, p);
418 rb_insert_color(&new->so_server_node, &server->state_owners);
270 return new; 419 return new;
271} 420}
272 421
273static void 422static void
274nfs4_remove_state_owner(struct nfs_client *clp, struct nfs4_state_owner *sp) 423nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
275{ 424{
276 if (!RB_EMPTY_NODE(&sp->so_client_node)) 425 struct nfs_server *server = sp->so_server;
277 rb_erase(&sp->so_client_node, &clp->cl_state_owners); 426
278 nfs_free_unique_id(&clp->cl_openowner_id, &sp->so_owner_id); 427 if (!RB_EMPTY_NODE(&sp->so_server_node))
428 rb_erase(&sp->so_server_node, &server->state_owners);
429 nfs_free_unique_id(&server->openowner_id, &sp->so_owner_id);
279} 430}
280 431
281/* 432/*
@@ -288,12 +439,11 @@ nfs4_alloc_state_owner(void)
288{ 439{
289 struct nfs4_state_owner *sp; 440 struct nfs4_state_owner *sp;
290 441
291 sp = kzalloc(sizeof(*sp),GFP_KERNEL); 442 sp = kzalloc(sizeof(*sp),GFP_NOFS);
292 if (!sp) 443 if (!sp)
293 return NULL; 444 return NULL;
294 spin_lock_init(&sp->so_lock); 445 spin_lock_init(&sp->so_lock);
295 INIT_LIST_HEAD(&sp->so_states); 446 INIT_LIST_HEAD(&sp->so_states);
296 INIT_LIST_HEAD(&sp->so_delegations);
297 rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); 447 rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue");
298 sp->so_seqid.sequence = &sp->so_sequence; 448 sp->so_seqid.sequence = &sp->so_sequence;
299 spin_lock_init(&sp->so_sequence.lock); 449 spin_lock_init(&sp->so_sequence.lock);
@@ -305,34 +455,42 @@ nfs4_alloc_state_owner(void)
305static void 455static void
306nfs4_drop_state_owner(struct nfs4_state_owner *sp) 456nfs4_drop_state_owner(struct nfs4_state_owner *sp)
307{ 457{
308 if (!RB_EMPTY_NODE(&sp->so_client_node)) { 458 if (!RB_EMPTY_NODE(&sp->so_server_node)) {
309 struct nfs_client *clp = sp->so_client; 459 struct nfs_server *server = sp->so_server;
460 struct nfs_client *clp = server->nfs_client;
310 461
311 spin_lock(&clp->cl_lock); 462 spin_lock(&clp->cl_lock);
312 rb_erase(&sp->so_client_node, &clp->cl_state_owners); 463 rb_erase(&sp->so_server_node, &server->state_owners);
313 RB_CLEAR_NODE(&sp->so_client_node); 464 RB_CLEAR_NODE(&sp->so_server_node);
314 spin_unlock(&clp->cl_lock); 465 spin_unlock(&clp->cl_lock);
315 } 466 }
316} 467}
317 468
318struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct rpc_cred *cred) 469/**
470 * nfs4_get_state_owner - Look up a state owner given a credential
471 * @server: nfs_server to search
472 * @cred: RPC credential to match
473 *
474 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL.
475 */
476struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
477 struct rpc_cred *cred)
319{ 478{
320 struct nfs_client *clp = server->nfs_client; 479 struct nfs_client *clp = server->nfs_client;
321 struct nfs4_state_owner *sp, *new; 480 struct nfs4_state_owner *sp, *new;
322 481
323 spin_lock(&clp->cl_lock); 482 spin_lock(&clp->cl_lock);
324 sp = nfs4_find_state_owner(server, cred); 483 sp = nfs4_find_state_owner_locked(server, cred);
325 spin_unlock(&clp->cl_lock); 484 spin_unlock(&clp->cl_lock);
326 if (sp != NULL) 485 if (sp != NULL)
327 return sp; 486 return sp;
328 new = nfs4_alloc_state_owner(); 487 new = nfs4_alloc_state_owner();
329 if (new == NULL) 488 if (new == NULL)
330 return NULL; 489 return NULL;
331 new->so_client = clp;
332 new->so_server = server; 490 new->so_server = server;
333 new->so_cred = cred; 491 new->so_cred = cred;
334 spin_lock(&clp->cl_lock); 492 spin_lock(&clp->cl_lock);
335 sp = nfs4_insert_state_owner(clp, new); 493 sp = nfs4_insert_state_owner_locked(new);
336 spin_unlock(&clp->cl_lock); 494 spin_unlock(&clp->cl_lock);
337 if (sp == new) 495 if (sp == new)
338 get_rpccred(cred); 496 get_rpccred(cred);
@@ -343,14 +501,19 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
343 return sp; 501 return sp;
344} 502}
345 503
504/**
505 * nfs4_put_state_owner - Release a nfs4_state_owner
506 * @sp: state owner data to release
507 *
508 */
346void nfs4_put_state_owner(struct nfs4_state_owner *sp) 509void nfs4_put_state_owner(struct nfs4_state_owner *sp)
347{ 510{
348 struct nfs_client *clp = sp->so_client; 511 struct nfs_client *clp = sp->so_server->nfs_client;
349 struct rpc_cred *cred = sp->so_cred; 512 struct rpc_cred *cred = sp->so_cred;
350 513
351 if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock)) 514 if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock))
352 return; 515 return;
353 nfs4_remove_state_owner(clp, sp); 516 nfs4_remove_state_owner_locked(sp);
354 spin_unlock(&clp->cl_lock); 517 spin_unlock(&clp->cl_lock);
355 rpc_destroy_wait_queue(&sp->so_sequence.wait); 518 rpc_destroy_wait_queue(&sp->so_sequence.wait);
356 put_rpccred(cred); 519 put_rpccred(cred);
@@ -362,7 +525,7 @@ nfs4_alloc_open_state(void)
362{ 525{
363 struct nfs4_state *state; 526 struct nfs4_state *state;
364 527
365 state = kzalloc(sizeof(*state), GFP_KERNEL); 528 state = kzalloc(sizeof(*state), GFP_NOFS);
366 if (!state) 529 if (!state)
367 return NULL; 530 return NULL;
368 atomic_set(&state->count, 1); 531 atomic_set(&state->count, 1);
@@ -464,7 +627,8 @@ void nfs4_put_open_state(struct nfs4_state *state)
464/* 627/*
465 * Close the current file. 628 * Close the current file.
466 */ 629 */
467static void __nfs4_close(struct path *path, struct nfs4_state *state, fmode_t fmode, int wait) 630static void __nfs4_close(struct path *path, struct nfs4_state *state,
631 fmode_t fmode, gfp_t gfp_mask, int wait)
468{ 632{
469 struct nfs4_state_owner *owner = state->owner; 633 struct nfs4_state_owner *owner = state->owner;
470 int call_close = 0; 634 int call_close = 0;
@@ -504,18 +668,21 @@ static void __nfs4_close(struct path *path, struct nfs4_state *state, fmode_t fm
504 if (!call_close) { 668 if (!call_close) {
505 nfs4_put_open_state(state); 669 nfs4_put_open_state(state);
506 nfs4_put_state_owner(owner); 670 nfs4_put_state_owner(owner);
507 } else 671 } else {
508 nfs4_do_close(path, state, wait); 672 bool roc = pnfs_roc(state->inode);
673
674 nfs4_do_close(path, state, gfp_mask, wait, roc);
675 }
509} 676}
510 677
511void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode) 678void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode)
512{ 679{
513 __nfs4_close(path, state, fmode, 0); 680 __nfs4_close(path, state, fmode, GFP_NOFS, 0);
514} 681}
515 682
516void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode) 683void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode)
517{ 684{
518 __nfs4_close(path, state, fmode, 1); 685 __nfs4_close(path, state, fmode, GFP_KERNEL, 1);
519} 686}
520 687
521/* 688/*
@@ -523,12 +690,21 @@ void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode)
523 * that is compatible with current->files 690 * that is compatible with current->files
524 */ 691 */
525static struct nfs4_lock_state * 692static struct nfs4_lock_state *
526__nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) 693__nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type)
527{ 694{
528 struct nfs4_lock_state *pos; 695 struct nfs4_lock_state *pos;
529 list_for_each_entry(pos, &state->lock_states, ls_locks) { 696 list_for_each_entry(pos, &state->lock_states, ls_locks) {
530 if (pos->ls_owner != fl_owner) 697 if (type != NFS4_ANY_LOCK_TYPE && pos->ls_owner.lo_type != type)
531 continue; 698 continue;
699 switch (pos->ls_owner.lo_type) {
700 case NFS4_POSIX_LOCK_TYPE:
701 if (pos->ls_owner.lo_u.posix_owner != fl_owner)
702 continue;
703 break;
704 case NFS4_FLOCK_LOCK_TYPE:
705 if (pos->ls_owner.lo_u.flock_owner != fl_pid)
706 continue;
707 }
532 atomic_inc(&pos->ls_count); 708 atomic_inc(&pos->ls_count);
533 return pos; 709 return pos;
534 } 710 }
@@ -540,12 +716,13 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
540 * exists, return an uninitialized one. 716 * exists, return an uninitialized one.
541 * 717 *
542 */ 718 */
543static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) 719static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type)
544{ 720{
545 struct nfs4_lock_state *lsp; 721 struct nfs4_lock_state *lsp;
546 struct nfs_client *clp = state->owner->so_client; 722 struct nfs_server *server = state->owner->so_server;
723 struct nfs_client *clp = server->nfs_client;
547 724
548 lsp = kzalloc(sizeof(*lsp), GFP_KERNEL); 725 lsp = kzalloc(sizeof(*lsp), GFP_NOFS);
549 if (lsp == NULL) 726 if (lsp == NULL)
550 return NULL; 727 return NULL;
551 rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue"); 728 rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue");
@@ -553,9 +730,21 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
553 INIT_LIST_HEAD(&lsp->ls_sequence.list); 730 INIT_LIST_HEAD(&lsp->ls_sequence.list);
554 lsp->ls_seqid.sequence = &lsp->ls_sequence; 731 lsp->ls_seqid.sequence = &lsp->ls_sequence;
555 atomic_set(&lsp->ls_count, 1); 732 atomic_set(&lsp->ls_count, 1);
556 lsp->ls_owner = fl_owner; 733 lsp->ls_state = state;
734 lsp->ls_owner.lo_type = type;
735 switch (lsp->ls_owner.lo_type) {
736 case NFS4_FLOCK_LOCK_TYPE:
737 lsp->ls_owner.lo_u.flock_owner = fl_pid;
738 break;
739 case NFS4_POSIX_LOCK_TYPE:
740 lsp->ls_owner.lo_u.posix_owner = fl_owner;
741 break;
742 default:
743 kfree(lsp);
744 return NULL;
745 }
557 spin_lock(&clp->cl_lock); 746 spin_lock(&clp->cl_lock);
558 nfs_alloc_unique_id(&clp->cl_lockowner_id, &lsp->ls_id, 1, 64); 747 nfs_alloc_unique_id_locked(&server->lockowner_id, &lsp->ls_id, 1, 64);
559 spin_unlock(&clp->cl_lock); 748 spin_unlock(&clp->cl_lock);
560 INIT_LIST_HEAD(&lsp->ls_locks); 749 INIT_LIST_HEAD(&lsp->ls_locks);
561 return lsp; 750 return lsp;
@@ -563,10 +752,11 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
563 752
564static void nfs4_free_lock_state(struct nfs4_lock_state *lsp) 753static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
565{ 754{
566 struct nfs_client *clp = lsp->ls_state->owner->so_client; 755 struct nfs_server *server = lsp->ls_state->owner->so_server;
756 struct nfs_client *clp = server->nfs_client;
567 757
568 spin_lock(&clp->cl_lock); 758 spin_lock(&clp->cl_lock);
569 nfs_free_unique_id(&clp->cl_lockowner_id, &lsp->ls_id); 759 nfs_free_unique_id(&server->lockowner_id, &lsp->ls_id);
570 spin_unlock(&clp->cl_lock); 760 spin_unlock(&clp->cl_lock);
571 rpc_destroy_wait_queue(&lsp->ls_sequence.wait); 761 rpc_destroy_wait_queue(&lsp->ls_sequence.wait);
572 kfree(lsp); 762 kfree(lsp);
@@ -577,17 +767,16 @@ static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
577 * exists, return an uninitialized one. 767 * exists, return an uninitialized one.
578 * 768 *
579 */ 769 */
580static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) 770static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner, pid_t pid, unsigned int type)
581{ 771{
582 struct nfs4_lock_state *lsp, *new = NULL; 772 struct nfs4_lock_state *lsp, *new = NULL;
583 773
584 for(;;) { 774 for(;;) {
585 spin_lock(&state->state_lock); 775 spin_lock(&state->state_lock);
586 lsp = __nfs4_find_lock_state(state, owner); 776 lsp = __nfs4_find_lock_state(state, owner, pid, type);
587 if (lsp != NULL) 777 if (lsp != NULL)
588 break; 778 break;
589 if (new != NULL) { 779 if (new != NULL) {
590 new->ls_state = state;
591 list_add(&new->ls_locks, &state->lock_states); 780 list_add(&new->ls_locks, &state->lock_states);
592 set_bit(LK_STATE_IN_USE, &state->flags); 781 set_bit(LK_STATE_IN_USE, &state->flags);
593 lsp = new; 782 lsp = new;
@@ -595,7 +784,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_
595 break; 784 break;
596 } 785 }
597 spin_unlock(&state->state_lock); 786 spin_unlock(&state->state_lock);
598 new = nfs4_alloc_lock_state(state, owner); 787 new = nfs4_alloc_lock_state(state, owner, pid, type);
599 if (new == NULL) 788 if (new == NULL)
600 return NULL; 789 return NULL;
601 } 790 }
@@ -622,6 +811,8 @@ void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
622 if (list_empty(&state->lock_states)) 811 if (list_empty(&state->lock_states))
623 clear_bit(LK_STATE_IN_USE, &state->flags); 812 clear_bit(LK_STATE_IN_USE, &state->flags);
624 spin_unlock(&state->state_lock); 813 spin_unlock(&state->state_lock);
814 if (lsp->ls_flags & NFS_LOCK_INITIALIZED)
815 nfs4_release_lockowner(lsp);
625 nfs4_free_lock_state(lsp); 816 nfs4_free_lock_state(lsp);
626} 817}
627 818
@@ -638,7 +829,7 @@ static void nfs4_fl_release_lock(struct file_lock *fl)
638 nfs4_put_lock_state(fl->fl_u.nfs4_fl.owner); 829 nfs4_put_lock_state(fl->fl_u.nfs4_fl.owner);
639} 830}
640 831
641static struct file_lock_operations nfs4_fl_lock_ops = { 832static const struct file_lock_operations nfs4_fl_lock_ops = {
642 .fl_copy_lock = nfs4_fl_copy_lock, 833 .fl_copy_lock = nfs4_fl_copy_lock,
643 .fl_release_private = nfs4_fl_release_lock, 834 .fl_release_private = nfs4_fl_release_lock,
644}; 835};
@@ -649,7 +840,12 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
649 840
650 if (fl->fl_ops != NULL) 841 if (fl->fl_ops != NULL)
651 return 0; 842 return 0;
652 lsp = nfs4_get_lock_state(state, fl->fl_owner); 843 if (fl->fl_flags & FL_POSIX)
844 lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE);
845 else if (fl->fl_flags & FL_FLOCK)
846 lsp = nfs4_get_lock_state(state, 0, fl->fl_pid, NFS4_FLOCK_LOCK_TYPE);
847 else
848 return -EINVAL;
653 if (lsp == NULL) 849 if (lsp == NULL)
654 return -ENOMEM; 850 return -ENOMEM;
655 fl->fl_u.nfs4_fl.owner = lsp; 851 fl->fl_u.nfs4_fl.owner = lsp;
@@ -661,7 +857,7 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
661 * Byte-range lock aware utility to initialize the stateid of read/write 857 * Byte-range lock aware utility to initialize the stateid of read/write
662 * requests. 858 * requests.
663 */ 859 */
664void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner) 860void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
665{ 861{
666 struct nfs4_lock_state *lsp; 862 struct nfs4_lock_state *lsp;
667 int seq; 863 int seq;
@@ -674,18 +870,18 @@ void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t f
674 return; 870 return;
675 871
676 spin_lock(&state->state_lock); 872 spin_lock(&state->state_lock);
677 lsp = __nfs4_find_lock_state(state, fl_owner); 873 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
678 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) 874 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
679 memcpy(dst, &lsp->ls_stateid, sizeof(*dst)); 875 memcpy(dst, &lsp->ls_stateid, sizeof(*dst));
680 spin_unlock(&state->state_lock); 876 spin_unlock(&state->state_lock);
681 nfs4_put_lock_state(lsp); 877 nfs4_put_lock_state(lsp);
682} 878}
683 879
684struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter) 880struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask)
685{ 881{
686 struct nfs_seqid *new; 882 struct nfs_seqid *new;
687 883
688 new = kmalloc(sizeof(*new), GFP_KERNEL); 884 new = kmalloc(sizeof(*new), gfp_mask);
689 if (new != NULL) { 885 if (new != NULL) {
690 new->sequence = counter; 886 new->sequence = counter;
691 INIT_LIST_HEAD(&new->list); 887 INIT_LIST_HEAD(&new->list);
@@ -693,16 +889,21 @@ struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter)
693 return new; 889 return new;
694} 890}
695 891
696void nfs_free_seqid(struct nfs_seqid *seqid) 892void nfs_release_seqid(struct nfs_seqid *seqid)
697{ 893{
698 if (!list_empty(&seqid->list)) { 894 if (!list_empty(&seqid->list)) {
699 struct rpc_sequence *sequence = seqid->sequence->sequence; 895 struct rpc_sequence *sequence = seqid->sequence->sequence;
700 896
701 spin_lock(&sequence->lock); 897 spin_lock(&sequence->lock);
702 list_del(&seqid->list); 898 list_del_init(&seqid->list);
703 spin_unlock(&sequence->lock); 899 spin_unlock(&sequence->lock);
704 rpc_wake_up(&sequence->wait); 900 rpc_wake_up(&sequence->wait);
705 } 901 }
902}
903
904void nfs_free_seqid(struct nfs_seqid *seqid)
905{
906 nfs_release_seqid(seqid);
706 kfree(seqid); 907 kfree(seqid);
707} 908}
708 909
@@ -823,7 +1024,7 @@ void nfs4_schedule_state_recovery(struct nfs_client *clp)
823 nfs4_schedule_state_manager(clp); 1024 nfs4_schedule_state_manager(clp);
824} 1025}
825 1026
826static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) 1027int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
827{ 1028{
828 1029
829 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); 1030 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
@@ -859,13 +1060,13 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
859 /* Guard against delegation returns and new lock/unlock calls */ 1060 /* Guard against delegation returns and new lock/unlock calls */
860 down_write(&nfsi->rwsem); 1061 down_write(&nfsi->rwsem);
861 /* Protect inode->i_flock using the BKL */ 1062 /* Protect inode->i_flock using the BKL */
862 lock_kernel(); 1063 lock_flocks();
863 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 1064 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
864 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) 1065 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
865 continue; 1066 continue;
866 if (nfs_file_open_context(fl->fl_file)->state != state) 1067 if (nfs_file_open_context(fl->fl_file)->state != state)
867 continue; 1068 continue;
868 unlock_kernel(); 1069 unlock_flocks();
869 status = ops->recover_lock(state, fl); 1070 status = ops->recover_lock(state, fl);
870 switch (status) { 1071 switch (status) {
871 case 0: 1072 case 0:
@@ -877,6 +1078,10 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
877 case -NFS4ERR_EXPIRED: 1078 case -NFS4ERR_EXPIRED:
878 case -NFS4ERR_NO_GRACE: 1079 case -NFS4ERR_NO_GRACE:
879 case -NFS4ERR_STALE_CLIENTID: 1080 case -NFS4ERR_STALE_CLIENTID:
1081 case -NFS4ERR_BADSESSION:
1082 case -NFS4ERR_BADSLOT:
1083 case -NFS4ERR_BAD_HIGH_SLOT:
1084 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
880 goto out; 1085 goto out;
881 default: 1086 default:
882 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", 1087 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n",
@@ -888,9 +1093,9 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
888 /* kill_proc(fl->fl_pid, SIGLOST, 1); */ 1093 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
889 status = 0; 1094 status = 0;
890 } 1095 }
891 lock_kernel(); 1096 lock_flocks();
892 } 1097 }
893 unlock_kernel(); 1098 unlock_flocks();
894out: 1099out:
895 up_write(&nfsi->rwsem); 1100 up_write(&nfsi->rwsem);
896 return status; 1101 return status;
@@ -948,17 +1153,29 @@ restart:
948 /* Mark the file as being 'closed' */ 1153 /* Mark the file as being 'closed' */
949 state->state = 0; 1154 state->state = 0;
950 break; 1155 break;
1156 case -EKEYEXPIRED:
1157 /*
1158 * User RPCSEC_GSS context has expired.
1159 * We cannot recover this stateid now, so
1160 * skip it and allow recovery thread to
1161 * proceed.
1162 */
1163 break;
951 case -NFS4ERR_ADMIN_REVOKED: 1164 case -NFS4ERR_ADMIN_REVOKED:
952 case -NFS4ERR_STALE_STATEID: 1165 case -NFS4ERR_STALE_STATEID:
953 case -NFS4ERR_BAD_STATEID: 1166 case -NFS4ERR_BAD_STATEID:
954 case -NFS4ERR_RECLAIM_BAD: 1167 case -NFS4ERR_RECLAIM_BAD:
955 case -NFS4ERR_RECLAIM_CONFLICT: 1168 case -NFS4ERR_RECLAIM_CONFLICT:
956 nfs4_state_mark_reclaim_nograce(sp->so_client, state); 1169 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
957 break; 1170 break;
958 case -NFS4ERR_EXPIRED: 1171 case -NFS4ERR_EXPIRED:
959 case -NFS4ERR_NO_GRACE: 1172 case -NFS4ERR_NO_GRACE:
960 nfs4_state_mark_reclaim_nograce(sp->so_client, state); 1173 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
961 case -NFS4ERR_STALE_CLIENTID: 1174 case -NFS4ERR_STALE_CLIENTID:
1175 case -NFS4ERR_BADSESSION:
1176 case -NFS4ERR_BADSLOT:
1177 case -NFS4ERR_BAD_HIGH_SLOT:
1178 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
962 goto out_err; 1179 goto out_err;
963 } 1180 }
964 nfs4_put_open_state(state); 1181 nfs4_put_open_state(state);
@@ -985,15 +1202,19 @@ static void nfs4_clear_open_state(struct nfs4_state *state)
985 } 1202 }
986} 1203}
987 1204
988static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp, int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) 1205static void nfs4_reset_seqids(struct nfs_server *server,
1206 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
989{ 1207{
1208 struct nfs_client *clp = server->nfs_client;
990 struct nfs4_state_owner *sp; 1209 struct nfs4_state_owner *sp;
991 struct rb_node *pos; 1210 struct rb_node *pos;
992 struct nfs4_state *state; 1211 struct nfs4_state *state;
993 1212
994 /* Reset all sequence ids to zero */ 1213 spin_lock(&clp->cl_lock);
995 for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { 1214 for (pos = rb_first(&server->state_owners);
996 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 1215 pos != NULL;
1216 pos = rb_next(pos)) {
1217 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
997 sp->so_seqid.flags = 0; 1218 sp->so_seqid.flags = 0;
998 spin_lock(&sp->so_lock); 1219 spin_lock(&sp->so_lock);
999 list_for_each_entry(state, &sp->so_states, open_states) { 1220 list_for_each_entry(state, &sp->so_states, open_states) {
@@ -1002,6 +1223,18 @@ static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp, int (*mark_re
1002 } 1223 }
1003 spin_unlock(&sp->so_lock); 1224 spin_unlock(&sp->so_lock);
1004 } 1225 }
1226 spin_unlock(&clp->cl_lock);
1227}
1228
1229static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp,
1230 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
1231{
1232 struct nfs_server *server;
1233
1234 rcu_read_lock();
1235 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
1236 nfs4_reset_seqids(server, mark_reclaim);
1237 rcu_read_unlock();
1005} 1238}
1006 1239
1007static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp) 1240static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
@@ -1011,27 +1244,59 @@ static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
1011 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot); 1244 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot);
1012} 1245}
1013 1246
1014static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp) 1247static void nfs4_reclaim_complete(struct nfs_client *clp,
1248 const struct nfs4_state_recovery_ops *ops)
1249{
1250 /* Notify the server we're done reclaiming our state */
1251 if (ops->reclaim_complete)
1252 (void)ops->reclaim_complete(clp);
1253}
1254
1255static void nfs4_clear_reclaim_server(struct nfs_server *server)
1015{ 1256{
1257 struct nfs_client *clp = server->nfs_client;
1016 struct nfs4_state_owner *sp; 1258 struct nfs4_state_owner *sp;
1017 struct rb_node *pos; 1259 struct rb_node *pos;
1018 struct nfs4_state *state; 1260 struct nfs4_state *state;
1019 1261
1020 if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) 1262 spin_lock(&clp->cl_lock);
1021 return; 1263 for (pos = rb_first(&server->state_owners);
1022 1264 pos != NULL;
1023 for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { 1265 pos = rb_next(pos)) {
1024 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 1266 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
1025 spin_lock(&sp->so_lock); 1267 spin_lock(&sp->so_lock);
1026 list_for_each_entry(state, &sp->so_states, open_states) { 1268 list_for_each_entry(state, &sp->so_states, open_states) {
1027 if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags)) 1269 if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT,
1270 &state->flags))
1028 continue; 1271 continue;
1029 nfs4_state_mark_reclaim_nograce(clp, state); 1272 nfs4_state_mark_reclaim_nograce(clp, state);
1030 } 1273 }
1031 spin_unlock(&sp->so_lock); 1274 spin_unlock(&sp->so_lock);
1032 } 1275 }
1276 spin_unlock(&clp->cl_lock);
1277}
1278
1279static int nfs4_state_clear_reclaim_reboot(struct nfs_client *clp)
1280{
1281 struct nfs_server *server;
1282
1283 if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
1284 return 0;
1285
1286 rcu_read_lock();
1287 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
1288 nfs4_clear_reclaim_server(server);
1289 rcu_read_unlock();
1033 1290
1034 nfs_delegation_reap_unclaimed(clp); 1291 nfs_delegation_reap_unclaimed(clp);
1292 return 1;
1293}
1294
1295static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
1296{
1297 if (!nfs4_state_clear_reclaim_reboot(clp))
1298 return;
1299 nfs4_reclaim_complete(clp, clp->cl_mvops->reboot_recovery_ops);
1035} 1300}
1036 1301
1037static void nfs_delegation_clear_all(struct nfs_client *clp) 1302static void nfs_delegation_clear_all(struct nfs_client *clp)
@@ -1046,25 +1311,33 @@ static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
1046 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce); 1311 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
1047} 1312}
1048 1313
1049static void nfs4_state_end_reclaim_nograce(struct nfs_client *clp) 1314static void nfs4_warn_keyexpired(const char *s)
1050{ 1315{
1051 clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state); 1316 printk_ratelimited(KERN_WARNING "Error: state manager"
1317 " encountered RPCSEC_GSS session"
1318 " expired against NFSv4 server %s.\n",
1319 s);
1052} 1320}
1053 1321
1054static void nfs4_recovery_handle_error(struct nfs_client *clp, int error) 1322static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1055{ 1323{
1056 switch (error) { 1324 switch (error) {
1057 case -NFS4ERR_CB_PATH_DOWN: 1325 case -NFS4ERR_CB_PATH_DOWN:
1058 nfs_handle_cb_pathdown(clp); 1326 nfs_handle_cb_pathdown(clp);
1059 break; 1327 return 0;
1328 case -NFS4ERR_NO_GRACE:
1329 nfs4_state_end_reclaim_reboot(clp);
1330 return 0;
1060 case -NFS4ERR_STALE_CLIENTID: 1331 case -NFS4ERR_STALE_CLIENTID:
1061 case -NFS4ERR_LEASE_MOVED: 1332 case -NFS4ERR_LEASE_MOVED:
1062 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1333 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1334 nfs4_state_clear_reclaim_reboot(clp);
1063 nfs4_state_start_reclaim_reboot(clp); 1335 nfs4_state_start_reclaim_reboot(clp);
1064 break; 1336 break;
1065 case -NFS4ERR_EXPIRED: 1337 case -NFS4ERR_EXPIRED:
1066 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1338 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1067 nfs4_state_start_reclaim_nograce(clp); 1339 nfs4_state_start_reclaim_nograce(clp);
1340 break;
1068 case -NFS4ERR_BADSESSION: 1341 case -NFS4ERR_BADSESSION:
1069 case -NFS4ERR_BADSLOT: 1342 case -NFS4ERR_BADSLOT:
1070 case -NFS4ERR_BAD_HIGH_SLOT: 1343 case -NFS4ERR_BAD_HIGH_SLOT:
@@ -1072,42 +1345,61 @@ static void nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1072 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: 1345 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1073 case -NFS4ERR_SEQ_FALSE_RETRY: 1346 case -NFS4ERR_SEQ_FALSE_RETRY:
1074 case -NFS4ERR_SEQ_MISORDERED: 1347 case -NFS4ERR_SEQ_MISORDERED:
1075 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 1348 set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1349 /* Zero session reset errors */
1350 return 0;
1351 case -EKEYEXPIRED:
1352 /* Nothing we can do */
1353 nfs4_warn_keyexpired(clp->cl_hostname);
1354 return 0;
1076 } 1355 }
1356 return error;
1077} 1357}
1078 1358
1079static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops) 1359static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops)
1080{ 1360{
1361 struct nfs4_state_owner *sp;
1362 struct nfs_server *server;
1081 struct rb_node *pos; 1363 struct rb_node *pos;
1082 int status = 0; 1364 int status = 0;
1083 1365
1084restart: 1366restart:
1085 spin_lock(&clp->cl_lock); 1367 rcu_read_lock();
1086 for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { 1368 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
1087 struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 1369 spin_lock(&clp->cl_lock);
1088 if (!test_and_clear_bit(ops->owner_flag_bit, &sp->so_flags)) 1370 for (pos = rb_first(&server->state_owners);
1089 continue; 1371 pos != NULL;
1090 atomic_inc(&sp->so_count); 1372 pos = rb_next(pos)) {
1091 spin_unlock(&clp->cl_lock); 1373 sp = rb_entry(pos,
1092 status = nfs4_reclaim_open_state(sp, ops); 1374 struct nfs4_state_owner, so_server_node);
1093 if (status < 0) { 1375 if (!test_and_clear_bit(ops->owner_flag_bit,
1094 set_bit(ops->owner_flag_bit, &sp->so_flags); 1376 &sp->so_flags))
1377 continue;
1378 atomic_inc(&sp->so_count);
1379 spin_unlock(&clp->cl_lock);
1380 rcu_read_unlock();
1381
1382 status = nfs4_reclaim_open_state(sp, ops);
1383 if (status < 0) {
1384 set_bit(ops->owner_flag_bit, &sp->so_flags);
1385 nfs4_put_state_owner(sp);
1386 return nfs4_recovery_handle_error(clp, status);
1387 }
1388
1095 nfs4_put_state_owner(sp); 1389 nfs4_put_state_owner(sp);
1096 nfs4_recovery_handle_error(clp, status); 1390 goto restart;
1097 return status;
1098 } 1391 }
1099 nfs4_put_state_owner(sp); 1392 spin_unlock(&clp->cl_lock);
1100 goto restart;
1101 } 1393 }
1102 spin_unlock(&clp->cl_lock); 1394 rcu_read_unlock();
1103 return status; 1395 return status;
1104} 1396}
1105 1397
1106static int nfs4_check_lease(struct nfs_client *clp) 1398static int nfs4_check_lease(struct nfs_client *clp)
1107{ 1399{
1108 struct rpc_cred *cred; 1400 struct rpc_cred *cred;
1109 struct nfs4_state_maintenance_ops *ops = 1401 const struct nfs4_state_maintenance_ops *ops =
1110 nfs4_state_renewal_ops[clp->cl_minorversion]; 1402 clp->cl_mvops->state_renewal_ops;
1111 int status = -NFS4ERR_EXPIRED; 1403 int status = -NFS4ERR_EXPIRED;
1112 1404
1113 /* Is the client already known to have an expired lease? */ 1405 /* Is the client already known to have an expired lease? */
@@ -1124,15 +1416,14 @@ static int nfs4_check_lease(struct nfs_client *clp)
1124 status = ops->renew_lease(clp, cred); 1416 status = ops->renew_lease(clp, cred);
1125 put_rpccred(cred); 1417 put_rpccred(cred);
1126out: 1418out:
1127 nfs4_recovery_handle_error(clp, status); 1419 return nfs4_recovery_handle_error(clp, status);
1128 return status;
1129} 1420}
1130 1421
1131static int nfs4_reclaim_lease(struct nfs_client *clp) 1422static int nfs4_reclaim_lease(struct nfs_client *clp)
1132{ 1423{
1133 struct rpc_cred *cred; 1424 struct rpc_cred *cred;
1134 struct nfs4_state_recovery_ops *ops = 1425 const struct nfs4_state_recovery_ops *ops =
1135 nfs4_reboot_recovery_ops[clp->cl_minorversion]; 1426 clp->cl_mvops->reboot_recovery_ops;
1136 int status = -ENOENT; 1427 int status = -ENOENT;
1137 1428
1138 cred = ops->get_clid_cred(clp); 1429 cred = ops->get_clid_cred(clp);
@@ -1151,55 +1442,127 @@ static int nfs4_reclaim_lease(struct nfs_client *clp)
1151} 1442}
1152 1443
1153#ifdef CONFIG_NFS_V4_1 1444#ifdef CONFIG_NFS_V4_1
1154static void nfs4_session_recovery_handle_error(struct nfs_client *clp, int err) 1445void nfs41_handle_recall_slot(struct nfs_client *clp)
1446{
1447 set_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
1448 nfs4_schedule_state_recovery(clp);
1449}
1450
1451static void nfs4_reset_all_state(struct nfs_client *clp)
1452{
1453 if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
1454 clp->cl_boot_time = CURRENT_TIME;
1455 nfs4_state_start_reclaim_nograce(clp);
1456 nfs4_schedule_state_recovery(clp);
1457 }
1458}
1459
1460static void nfs41_handle_server_reboot(struct nfs_client *clp)
1155{ 1461{
1156 switch (err) { 1462 if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
1157 case -NFS4ERR_STALE_CLIENTID: 1463 nfs4_state_start_reclaim_reboot(clp);
1158 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1464 nfs4_schedule_state_recovery(clp);
1159 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
1160 } 1465 }
1161} 1466}
1162 1467
1468static void nfs41_handle_state_revoked(struct nfs_client *clp)
1469{
1470 /* Temporary */
1471 nfs4_reset_all_state(clp);
1472}
1473
1474static void nfs41_handle_recallable_state_revoked(struct nfs_client *clp)
1475{
1476 /* This will need to handle layouts too */
1477 nfs_expire_all_delegations(clp);
1478}
1479
1480static void nfs41_handle_cb_path_down(struct nfs_client *clp)
1481{
1482 nfs_expire_all_delegations(clp);
1483 if (test_and_set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) == 0)
1484 nfs4_schedule_state_recovery(clp);
1485}
1486
1487void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags)
1488{
1489 if (!flags)
1490 return;
1491 else if (flags & SEQ4_STATUS_RESTART_RECLAIM_NEEDED)
1492 nfs41_handle_server_reboot(clp);
1493 else if (flags & (SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED |
1494 SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED |
1495 SEQ4_STATUS_ADMIN_STATE_REVOKED |
1496 SEQ4_STATUS_LEASE_MOVED))
1497 nfs41_handle_state_revoked(clp);
1498 else if (flags & SEQ4_STATUS_RECALLABLE_STATE_REVOKED)
1499 nfs41_handle_recallable_state_revoked(clp);
1500 else if (flags & (SEQ4_STATUS_CB_PATH_DOWN |
1501 SEQ4_STATUS_BACKCHANNEL_FAULT |
1502 SEQ4_STATUS_CB_PATH_DOWN_SESSION))
1503 nfs41_handle_cb_path_down(clp);
1504}
1505
1163static int nfs4_reset_session(struct nfs_client *clp) 1506static int nfs4_reset_session(struct nfs_client *clp)
1164{ 1507{
1165 int status; 1508 int status;
1166 1509
1510 nfs4_begin_drain_session(clp);
1167 status = nfs4_proc_destroy_session(clp->cl_session); 1511 status = nfs4_proc_destroy_session(clp->cl_session);
1168 if (status && status != -NFS4ERR_BADSESSION && 1512 if (status && status != -NFS4ERR_BADSESSION &&
1169 status != -NFS4ERR_DEADSESSION) { 1513 status != -NFS4ERR_DEADSESSION) {
1170 nfs4_session_recovery_handle_error(clp, status); 1514 status = nfs4_recovery_handle_error(clp, status);
1171 goto out; 1515 goto out;
1172 } 1516 }
1173 1517
1174 memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN); 1518 memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN);
1175 status = nfs4_proc_create_session(clp, 1); 1519 status = nfs4_proc_create_session(clp);
1176 if (status) 1520 if (status) {
1177 nfs4_session_recovery_handle_error(clp, status); 1521 status = nfs4_recovery_handle_error(clp, status);
1178 /* fall through*/ 1522 goto out;
1523 }
1524 /* create_session negotiated new slot table */
1525 clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
1526
1527 /* Let the state manager reestablish state */
1528 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1529 nfs41_setup_state_renewal(clp);
1179out: 1530out:
1180 /* Wake up the next rpc task even on error */
1181 rpc_wake_up_next(&clp->cl_session->fc_slot_table.slot_tbl_waitq);
1182 return status; 1531 return status;
1183} 1532}
1184 1533
1185static int nfs4_initialize_session(struct nfs_client *clp) 1534static int nfs4_recall_slot(struct nfs_client *clp)
1186{ 1535{
1187 int status; 1536 struct nfs4_slot_table *fc_tbl = &clp->cl_session->fc_slot_table;
1537 struct nfs4_channel_attrs *fc_attrs = &clp->cl_session->fc_attrs;
1538 struct nfs4_slot *new, *old;
1539 int i;
1540
1541 nfs4_begin_drain_session(clp);
1542 new = kmalloc(fc_tbl->target_max_slots * sizeof(struct nfs4_slot),
1543 GFP_NOFS);
1544 if (!new)
1545 return -ENOMEM;
1188 1546
1189 status = nfs4_proc_create_session(clp, 0); 1547 spin_lock(&fc_tbl->slot_tbl_lock);
1190 if (!status) { 1548 for (i = 0; i < fc_tbl->target_max_slots; i++)
1191 nfs_mark_client_ready(clp, NFS_CS_READY); 1549 new[i].seq_nr = fc_tbl->slots[i].seq_nr;
1192 } else if (status == -NFS4ERR_STALE_CLIENTID) { 1550 old = fc_tbl->slots;
1193 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1551 fc_tbl->slots = new;
1194 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 1552 fc_tbl->max_slots = fc_tbl->target_max_slots;
1195 } else { 1553 fc_tbl->target_max_slots = 0;
1196 nfs_mark_client_ready(clp, status); 1554 fc_attrs->max_reqs = fc_tbl->max_slots;
1197 } 1555 spin_unlock(&fc_tbl->slot_tbl_lock);
1198 return status; 1556
1557 kfree(old);
1558 nfs4_end_drain_session(clp);
1559 return 0;
1199} 1560}
1561
1200#else /* CONFIG_NFS_V4_1 */ 1562#else /* CONFIG_NFS_V4_1 */
1201static int nfs4_reset_session(struct nfs_client *clp) { return 0; } 1563static int nfs4_reset_session(struct nfs_client *clp) { return 0; }
1202static int nfs4_initialize_session(struct nfs_client *clp) { return 0; } 1564static int nfs4_end_drain_session(struct nfs_client *clp) { return 0; }
1565static int nfs4_recall_slot(struct nfs_client *clp) { return 0; }
1203#endif /* CONFIG_NFS_V4_1 */ 1566#endif /* CONFIG_NFS_V4_1 */
1204 1567
1205/* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors 1568/* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
@@ -1214,6 +1577,8 @@ static void nfs4_set_lease_expired(struct nfs_client *clp, int status)
1214 case -EAGAIN: 1577 case -EAGAIN:
1215 break; 1578 break;
1216 1579
1580 case -EKEYEXPIRED:
1581 nfs4_warn_keyexpired(clp->cl_hostname);
1217 case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery 1582 case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery
1218 * in nfs4_exchange_id */ 1583 * in nfs4_exchange_id */
1219 default: 1584 default:
@@ -1234,7 +1599,8 @@ static void nfs4_state_manager(struct nfs_client *clp)
1234 status = nfs4_reclaim_lease(clp); 1599 status = nfs4_reclaim_lease(clp);
1235 if (status) { 1600 if (status) {
1236 nfs4_set_lease_expired(clp, status); 1601 nfs4_set_lease_expired(clp, status);
1237 if (status == -EAGAIN) 1602 if (test_bit(NFS4CLNT_LEASE_EXPIRED,
1603 &clp->cl_state))
1238 continue; 1604 continue;
1239 if (clp->cl_cons_state == 1605 if (clp->cl_cons_state ==
1240 NFS_CS_SESSION_INITING) 1606 NFS_CS_SESSION_INITING)
@@ -1242,61 +1608,68 @@ static void nfs4_state_manager(struct nfs_client *clp)
1242 goto out_error; 1608 goto out_error;
1243 } 1609 }
1244 clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); 1610 clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1611 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
1612 pnfs_destroy_all_layouts(clp);
1245 } 1613 }
1246 1614
1247 if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) { 1615 if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) {
1248 status = nfs4_check_lease(clp); 1616 status = nfs4_check_lease(clp);
1249 if (status != 0) 1617 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1250 continue; 1618 continue;
1619 if (status < 0 && status != -NFS4ERR_CB_PATH_DOWN)
1620 goto out_error;
1251 } 1621 }
1622
1252 /* Initialize or reset the session */ 1623 /* Initialize or reset the session */
1253 if (nfs4_has_session(clp) && 1624 if (test_and_clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)
1254 test_and_clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) { 1625 && nfs4_has_session(clp)) {
1255 if (clp->cl_cons_state == NFS_CS_SESSION_INITING) 1626 status = nfs4_reset_session(clp);
1256 status = nfs4_initialize_session(clp); 1627 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1257 else 1628 continue;
1258 status = nfs4_reset_session(clp); 1629 if (status < 0)
1259 if (status) {
1260 if (status == -NFS4ERR_STALE_CLIENTID)
1261 continue;
1262 goto out_error; 1630 goto out_error;
1263 }
1264 } 1631 }
1632
1265 /* First recover reboot state... */ 1633 /* First recover reboot state... */
1266 if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) { 1634 if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
1267 status = nfs4_do_reclaim(clp, 1635 status = nfs4_do_reclaim(clp,
1268 nfs4_reboot_recovery_ops[clp->cl_minorversion]); 1636 clp->cl_mvops->reboot_recovery_ops);
1269 if (status == -NFS4ERR_STALE_CLIENTID) 1637 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
1270 continue; 1638 test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
1271 if (test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state))
1272 continue; 1639 continue;
1273 nfs4_state_end_reclaim_reboot(clp); 1640 nfs4_state_end_reclaim_reboot(clp);
1274 continue; 1641 if (test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state))
1642 continue;
1643 if (status < 0)
1644 goto out_error;
1275 } 1645 }
1276 1646
1277 /* Now recover expired state... */ 1647 /* Now recover expired state... */
1278 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) { 1648 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
1279 status = nfs4_do_reclaim(clp, 1649 status = nfs4_do_reclaim(clp,
1280 nfs4_nograce_recovery_ops[clp->cl_minorversion]); 1650 clp->cl_mvops->nograce_recovery_ops);
1281 if (status < 0) { 1651 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
1282 set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state); 1652 test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) ||
1283 if (status == -NFS4ERR_STALE_CLIENTID) 1653 test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
1284 continue; 1654 continue;
1285 if (status == -NFS4ERR_EXPIRED) 1655 if (status < 0)
1286 continue;
1287 if (test_bit(NFS4CLNT_SESSION_SETUP,
1288 &clp->cl_state))
1289 continue;
1290 goto out_error; 1656 goto out_error;
1291 } else
1292 nfs4_state_end_reclaim_nograce(clp);
1293 continue;
1294 } 1657 }
1295 1658
1659 nfs4_end_drain_session(clp);
1296 if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) { 1660 if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) {
1297 nfs_client_return_marked_delegations(clp); 1661 nfs_client_return_marked_delegations(clp);
1298 continue; 1662 continue;
1299 } 1663 }
1664 /* Recall session slots */
1665 if (test_and_clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state)
1666 && nfs4_has_session(clp)) {
1667 status = nfs4_recall_slot(clp);
1668 if (status < 0)
1669 goto out_error;
1670 continue;
1671 }
1672
1300 1673
1301 nfs4_clear_state_manager_bit(clp); 1674 nfs4_clear_state_manager_bit(clp);
1302 /* Did we race with an attempt to give us more work? */ 1675 /* Did we race with an attempt to give us more work? */
@@ -1309,8 +1682,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
1309out_error: 1682out_error:
1310 printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s" 1683 printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s"
1311 " with error %d\n", clp->cl_hostname, -status); 1684 " with error %d\n", clp->cl_hostname, -status);
1312 if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) 1685 nfs4_end_drain_session(clp);
1313 nfs4_state_end_reclaim_reboot(clp);
1314 nfs4_clear_state_manager_bit(clp); 1686 nfs4_clear_state_manager_bit(clp);
1315} 1687}
1316 1688
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 617273e7d47f..2ab8e5cb8f59 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -38,8 +38,6 @@
38#include <linux/param.h> 38#include <linux/param.h>
39#include <linux/time.h> 39#include <linux/time.h>
40#include <linux/mm.h> 40#include <linux/mm.h>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h> 41#include <linux/errno.h>
44#include <linux/string.h> 42#include <linux/string.h>
45#include <linux/in.h> 43#include <linux/in.h>
@@ -47,11 +45,14 @@
47#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
48#include <linux/kdev_t.h> 46#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h> 47#include <linux/sunrpc/clnt.h>
48#include <linux/sunrpc/msg_prot.h>
50#include <linux/nfs.h> 49#include <linux/nfs.h>
51#include <linux/nfs4.h> 50#include <linux/nfs4.h>
52#include <linux/nfs_fs.h> 51#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h> 52#include <linux/nfs_idmap.h>
54#include "nfs4_fs.h" 53#include "nfs4_fs.h"
54#include "internal.h"
55#include "pnfs.h"
55 56
56#define NFSDBG_FACILITY NFSDBG_XDR 57#define NFSDBG_FACILITY NFSDBG_XDR
57 58
@@ -70,8 +71,8 @@ static int nfs4_stat_to_errno(int);
70/* lock,open owner id: 71/* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 72 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
72 */ 73 */
73#define open_owner_id_maxsz (1 + 4) 74#define open_owner_id_maxsz (1 + 1 + 4)
74#define lock_owner_id_maxsz (1 + 4) 75#define lock_owner_id_maxsz (1 + 1 + 4)
75#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 76#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 77#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 78#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
@@ -135,7 +136,7 @@ static int nfs4_stat_to_errno(int);
135#define decode_lookup_maxsz (op_decode_hdr_maxsz) 136#define decode_lookup_maxsz (op_decode_hdr_maxsz)
136#define encode_share_access_maxsz \ 137#define encode_share_access_maxsz \
137 (2) 138 (2)
138#define encode_createmode_maxsz (1 + encode_attrs_maxsz) 139#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
139#define encode_opentype_maxsz (1 + encode_createmode_maxsz) 140#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 141#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \ 142#define encode_open_maxsz (op_encode_hdr_maxsz + \
@@ -202,14 +203,17 @@ static int nfs4_stat_to_errno(int);
202#define encode_link_maxsz (op_encode_hdr_maxsz + \ 203#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz) 204 nfs4_name_maxsz)
204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 205#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
206#define encode_lockowner_maxsz (7)
205#define encode_lock_maxsz (op_encode_hdr_maxsz + \ 207#define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 7 + \ 208 7 + \
207 1 + encode_stateid_maxsz + 8) 209 1 + encode_stateid_maxsz + 1 + \
210 encode_lockowner_maxsz)
208#define decode_lock_denied_maxsz \ 211#define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz) 212 (8 + decode_lockowner_maxsz)
210#define decode_lock_maxsz (op_decode_hdr_maxsz + \ 213#define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz) 214 decode_lock_denied_maxsz)
212#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12) 215#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
216 encode_lockowner_maxsz)
213#define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 217#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz) 218 decode_lock_denied_maxsz)
215#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 219#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
@@ -217,6 +221,11 @@ static int nfs4_stat_to_errno(int);
217 4) 221 4)
218#define decode_locku_maxsz (op_decode_hdr_maxsz + \ 222#define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz) 223 decode_stateid_maxsz)
224#define encode_release_lockowner_maxsz \
225 (op_encode_hdr_maxsz + \
226 encode_lockowner_maxsz)
227#define decode_release_lockowner_maxsz \
228 (op_decode_hdr_maxsz)
220#define encode_access_maxsz (op_encode_hdr_maxsz + 1) 229#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221#define decode_access_maxsz (op_decode_hdr_maxsz + 2) 230#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 231#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
@@ -300,6 +309,21 @@ static int nfs4_stat_to_errno(int);
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 309 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301#define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 310#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
302 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 311 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
312#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
313#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
314#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
315 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
316#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
317 1 /* layout type */ + \
318 1 /* opaque devaddr4 length */ + \
319 /* devaddr4 payload is read into page */ \
320 1 /* notification bitmap length */ + \
321 1 /* notification bitmap */)
322#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
323 encode_stateid_maxsz)
324#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
325 decode_stateid_maxsz + \
326 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
303#else /* CONFIG_NFS_V4_1 */ 327#else /* CONFIG_NFS_V4_1 */
304#define encode_sequence_maxsz 0 328#define encode_sequence_maxsz 0
305#define decode_sequence_maxsz 0 329#define decode_sequence_maxsz 0
@@ -469,6 +493,12 @@ static int nfs4_stat_to_errno(int);
469 decode_sequence_maxsz + \ 493 decode_sequence_maxsz + \
470 decode_putfh_maxsz + \ 494 decode_putfh_maxsz + \
471 decode_locku_maxsz) 495 decode_locku_maxsz)
496#define NFS4_enc_release_lockowner_sz \
497 (compound_encode_hdr_maxsz + \
498 encode_lockowner_maxsz)
499#define NFS4_dec_release_lockowner_sz \
500 (compound_decode_hdr_maxsz + \
501 decode_lockowner_maxsz)
472#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 502#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
473 encode_sequence_maxsz + \ 503 encode_sequence_maxsz + \
474 encode_putfh_maxsz + \ 504 encode_putfh_maxsz + \
@@ -677,6 +707,39 @@ static int nfs4_stat_to_errno(int);
677 decode_sequence_maxsz + \ 707 decode_sequence_maxsz + \
678 decode_putrootfh_maxsz + \ 708 decode_putrootfh_maxsz + \
679 decode_fsinfo_maxsz) 709 decode_fsinfo_maxsz)
710#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_reclaim_complete_maxsz)
713#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
714 decode_sequence_maxsz + \
715 decode_reclaim_complete_maxsz)
716#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
717 encode_sequence_maxsz +\
718 encode_getdeviceinfo_maxsz)
719#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
720 decode_sequence_maxsz + \
721 decode_getdeviceinfo_maxsz)
722#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
725 encode_layoutget_maxsz)
726#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
729 decode_layoutget_maxsz)
730
731const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
732 compound_encode_hdr_maxsz +
733 encode_sequence_maxsz +
734 encode_putfh_maxsz +
735 encode_getattr_maxsz) *
736 XDR_UNIT);
737
738const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
739 compound_decode_hdr_maxsz +
740 decode_sequence_maxsz +
741 decode_putfh_maxsz) *
742 XDR_UNIT);
680#endif /* CONFIG_NFS_V4_1 */ 743#endif /* CONFIG_NFS_V4_1 */
681 744
682static const umode_t nfs_type2fmt[] = { 745static const umode_t nfs_type2fmt[] = {
@@ -702,29 +765,12 @@ struct compound_hdr {
702 u32 minorversion; 765 u32 minorversion;
703}; 766};
704 767
705/* 768static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
706 * START OF "GENERIC" ENCODE ROUTINES. 769{
707 * These may look a little ugly since they are imported from a "generic" 770 __be32 *p = xdr_reserve_space(xdr, nbytes);
708 * set of XDR encode/decode routines which are intended to be shared by 771 BUG_ON(!p);
709 * all of our NFSv4 implementations (OpenBSD, MacOS X...). 772 return p;
710 * 773}
711 * If the pain of reading these is too great, it should be a straightforward
712 * task to translate them into Linux-specific versions which are more
713 * consistent with the style used in NFSv2/v3...
714 */
715#define WRITE32(n) *p++ = htonl(n)
716#define WRITE64(n) do { \
717 *p++ = htonl((uint32_t)((n) >> 32)); \
718 *p++ = htonl((uint32_t)(n)); \
719} while (0)
720#define WRITEMEM(ptr,nbytes) do { \
721 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
722} while (0)
723
724#define RESERVE_SPACE(nbytes) do { \
725 p = xdr_reserve_space(xdr, nbytes); \
726 BUG_ON(!p); \
727} while (0)
728 774
729static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 775static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
730{ 776{
@@ -740,7 +786,7 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
740 struct compound_hdr *hdr) 786 struct compound_hdr *hdr)
741{ 787{
742 __be32 *p; 788 __be32 *p;
743 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; 789 struct rpc_auth *auth = req->rq_cred->cr_auth;
744 790
745 /* initialize running count of expected bytes in reply. 791 /* initialize running count of expected bytes in reply.
746 * NOTE: the replied tag SHOULD be the same is the one sent, 792 * NOTE: the replied tag SHOULD be the same is the one sent,
@@ -749,12 +795,11 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
749 795
750 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); 796 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
751 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 797 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
752 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2)); 798 p = reserve_space(xdr, 4 + hdr->taglen + 8);
753 WRITE32(hdr->taglen); 799 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
754 WRITEMEM(hdr->tag, hdr->taglen); 800 *p++ = cpu_to_be32(hdr->minorversion);
755 WRITE32(hdr->minorversion);
756 hdr->nops_p = p; 801 hdr->nops_p = p;
757 WRITE32(hdr->nops); 802 *p = cpu_to_be32(hdr->nops);
758} 803}
759 804
760static void encode_nops(struct compound_hdr *hdr) 805static void encode_nops(struct compound_hdr *hdr)
@@ -799,7 +844,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
799 if (iap->ia_valid & ATTR_MODE) 844 if (iap->ia_valid & ATTR_MODE)
800 len += 4; 845 len += 4;
801 if (iap->ia_valid & ATTR_UID) { 846 if (iap->ia_valid & ATTR_UID) {
802 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name); 847 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
803 if (owner_namelen < 0) { 848 if (owner_namelen < 0) {
804 dprintk("nfs: couldn't resolve uid %d to string\n", 849 dprintk("nfs: couldn't resolve uid %d to string\n",
805 iap->ia_uid); 850 iap->ia_uid);
@@ -811,7 +856,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
811 len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 856 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
812 } 857 }
813 if (iap->ia_valid & ATTR_GID) { 858 if (iap->ia_valid & ATTR_GID) {
814 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group); 859 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
815 if (owner_grouplen < 0) { 860 if (owner_grouplen < 0) {
816 dprintk("nfs: couldn't resolve gid %d to string\n", 861 dprintk("nfs: couldn't resolve gid %d to string\n",
817 iap->ia_gid); 862 iap->ia_gid);
@@ -829,55 +874,53 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
829 len += 16; 874 len += 16;
830 else if (iap->ia_valid & ATTR_MTIME) 875 else if (iap->ia_valid & ATTR_MTIME)
831 len += 4; 876 len += 4;
832 RESERVE_SPACE(len); 877 p = reserve_space(xdr, len);
833 878
834 /* 879 /*
835 * We write the bitmap length now, but leave the bitmap and the attribute 880 * We write the bitmap length now, but leave the bitmap and the attribute
836 * buffer length to be backfilled at the end of this routine. 881 * buffer length to be backfilled at the end of this routine.
837 */ 882 */
838 WRITE32(2); 883 *p++ = cpu_to_be32(2);
839 q = p; 884 q = p;
840 p += 3; 885 p += 3;
841 886
842 if (iap->ia_valid & ATTR_SIZE) { 887 if (iap->ia_valid & ATTR_SIZE) {
843 bmval0 |= FATTR4_WORD0_SIZE; 888 bmval0 |= FATTR4_WORD0_SIZE;
844 WRITE64(iap->ia_size); 889 p = xdr_encode_hyper(p, iap->ia_size);
845 } 890 }
846 if (iap->ia_valid & ATTR_MODE) { 891 if (iap->ia_valid & ATTR_MODE) {
847 bmval1 |= FATTR4_WORD1_MODE; 892 bmval1 |= FATTR4_WORD1_MODE;
848 WRITE32(iap->ia_mode & S_IALLUGO); 893 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
849 } 894 }
850 if (iap->ia_valid & ATTR_UID) { 895 if (iap->ia_valid & ATTR_UID) {
851 bmval1 |= FATTR4_WORD1_OWNER; 896 bmval1 |= FATTR4_WORD1_OWNER;
852 WRITE32(owner_namelen); 897 p = xdr_encode_opaque(p, owner_name, owner_namelen);
853 WRITEMEM(owner_name, owner_namelen);
854 } 898 }
855 if (iap->ia_valid & ATTR_GID) { 899 if (iap->ia_valid & ATTR_GID) {
856 bmval1 |= FATTR4_WORD1_OWNER_GROUP; 900 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
857 WRITE32(owner_grouplen); 901 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
858 WRITEMEM(owner_group, owner_grouplen);
859 } 902 }
860 if (iap->ia_valid & ATTR_ATIME_SET) { 903 if (iap->ia_valid & ATTR_ATIME_SET) {
861 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 904 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
862 WRITE32(NFS4_SET_TO_CLIENT_TIME); 905 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
863 WRITE32(0); 906 *p++ = cpu_to_be32(0);
864 WRITE32(iap->ia_mtime.tv_sec); 907 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
865 WRITE32(iap->ia_mtime.tv_nsec); 908 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
866 } 909 }
867 else if (iap->ia_valid & ATTR_ATIME) { 910 else if (iap->ia_valid & ATTR_ATIME) {
868 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 911 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
869 WRITE32(NFS4_SET_TO_SERVER_TIME); 912 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
870 } 913 }
871 if (iap->ia_valid & ATTR_MTIME_SET) { 914 if (iap->ia_valid & ATTR_MTIME_SET) {
872 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 915 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
873 WRITE32(NFS4_SET_TO_CLIENT_TIME); 916 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
874 WRITE32(0); 917 *p++ = cpu_to_be32(0);
875 WRITE32(iap->ia_mtime.tv_sec); 918 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
876 WRITE32(iap->ia_mtime.tv_nsec); 919 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
877 } 920 }
878 else if (iap->ia_valid & ATTR_MTIME) { 921 else if (iap->ia_valid & ATTR_MTIME) {
879 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 922 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
880 WRITE32(NFS4_SET_TO_SERVER_TIME); 923 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
881 } 924 }
882 925
883 /* 926 /*
@@ -891,7 +934,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
891 len = (char *)p - (char *)q - 12; 934 len = (char *)p - (char *)q - 12;
892 *q++ = htonl(bmval0); 935 *q++ = htonl(bmval0);
893 *q++ = htonl(bmval1); 936 *q++ = htonl(bmval1);
894 *q++ = htonl(len); 937 *q = htonl(len);
895 938
896/* out: */ 939/* out: */
897} 940}
@@ -900,9 +943,9 @@ static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hd
900{ 943{
901 __be32 *p; 944 __be32 *p;
902 945
903 RESERVE_SPACE(8); 946 p = reserve_space(xdr, 8);
904 WRITE32(OP_ACCESS); 947 *p++ = cpu_to_be32(OP_ACCESS);
905 WRITE32(access); 948 *p = cpu_to_be32(access);
906 hdr->nops++; 949 hdr->nops++;
907 hdr->replen += decode_access_maxsz; 950 hdr->replen += decode_access_maxsz;
908} 951}
@@ -911,10 +954,10 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg
911{ 954{
912 __be32 *p; 955 __be32 *p;
913 956
914 RESERVE_SPACE(8+NFS4_STATEID_SIZE); 957 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
915 WRITE32(OP_CLOSE); 958 *p++ = cpu_to_be32(OP_CLOSE);
916 WRITE32(arg->seqid->sequence->counter); 959 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
917 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE); 960 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
918 hdr->nops++; 961 hdr->nops++;
919 hdr->replen += decode_close_maxsz; 962 hdr->replen += decode_close_maxsz;
920} 963}
@@ -923,10 +966,10 @@ static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *ar
923{ 966{
924 __be32 *p; 967 __be32 *p;
925 968
926 RESERVE_SPACE(16); 969 p = reserve_space(xdr, 16);
927 WRITE32(OP_COMMIT); 970 *p++ = cpu_to_be32(OP_COMMIT);
928 WRITE64(args->offset); 971 p = xdr_encode_hyper(p, args->offset);
929 WRITE32(args->count); 972 *p = cpu_to_be32(args->count);
930 hdr->nops++; 973 hdr->nops++;
931 hdr->replen += decode_commit_maxsz; 974 hdr->replen += decode_commit_maxsz;
932} 975}
@@ -935,30 +978,28 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
935{ 978{
936 __be32 *p; 979 __be32 *p;
937 980
938 RESERVE_SPACE(8); 981 p = reserve_space(xdr, 8);
939 WRITE32(OP_CREATE); 982 *p++ = cpu_to_be32(OP_CREATE);
940 WRITE32(create->ftype); 983 *p = cpu_to_be32(create->ftype);
941 984
942 switch (create->ftype) { 985 switch (create->ftype) {
943 case NF4LNK: 986 case NF4LNK:
944 RESERVE_SPACE(4); 987 p = reserve_space(xdr, 4);
945 WRITE32(create->u.symlink.len); 988 *p = cpu_to_be32(create->u.symlink.len);
946 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 989 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
947 break; 990 break;
948 991
949 case NF4BLK: case NF4CHR: 992 case NF4BLK: case NF4CHR:
950 RESERVE_SPACE(8); 993 p = reserve_space(xdr, 8);
951 WRITE32(create->u.device.specdata1); 994 *p++ = cpu_to_be32(create->u.device.specdata1);
952 WRITE32(create->u.device.specdata2); 995 *p = cpu_to_be32(create->u.device.specdata2);
953 break; 996 break;
954 997
955 default: 998 default:
956 break; 999 break;
957 } 1000 }
958 1001
959 RESERVE_SPACE(4 + create->name->len); 1002 encode_string(xdr, create->name->len, create->name->name);
960 WRITE32(create->name->len);
961 WRITEMEM(create->name->name, create->name->len);
962 hdr->nops++; 1003 hdr->nops++;
963 hdr->replen += decode_create_maxsz; 1004 hdr->replen += decode_create_maxsz;
964 1005
@@ -969,10 +1010,10 @@ static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct c
969{ 1010{
970 __be32 *p; 1011 __be32 *p;
971 1012
972 RESERVE_SPACE(12); 1013 p = reserve_space(xdr, 12);
973 WRITE32(OP_GETATTR); 1014 *p++ = cpu_to_be32(OP_GETATTR);
974 WRITE32(1); 1015 *p++ = cpu_to_be32(1);
975 WRITE32(bitmap); 1016 *p = cpu_to_be32(bitmap);
976 hdr->nops++; 1017 hdr->nops++;
977 hdr->replen += decode_getattr_maxsz; 1018 hdr->replen += decode_getattr_maxsz;
978} 1019}
@@ -981,11 +1022,11 @@ static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm
981{ 1022{
982 __be32 *p; 1023 __be32 *p;
983 1024
984 RESERVE_SPACE(16); 1025 p = reserve_space(xdr, 16);
985 WRITE32(OP_GETATTR); 1026 *p++ = cpu_to_be32(OP_GETATTR);
986 WRITE32(2); 1027 *p++ = cpu_to_be32(2);
987 WRITE32(bm0); 1028 *p++ = cpu_to_be32(bm0);
988 WRITE32(bm1); 1029 *p = cpu_to_be32(bm1);
989 hdr->nops++; 1030 hdr->nops++;
990 hdr->replen += decode_getattr_maxsz; 1031 hdr->replen += decode_getattr_maxsz;
991} 1032}
@@ -1012,8 +1053,8 @@ static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1012{ 1053{
1013 __be32 *p; 1054 __be32 *p;
1014 1055
1015 RESERVE_SPACE(4); 1056 p = reserve_space(xdr, 4);
1016 WRITE32(OP_GETFH); 1057 *p = cpu_to_be32(OP_GETFH);
1017 hdr->nops++; 1058 hdr->nops++;
1018 hdr->replen += decode_getfh_maxsz; 1059 hdr->replen += decode_getfh_maxsz;
1019} 1060}
@@ -1022,10 +1063,9 @@ static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct
1022{ 1063{
1023 __be32 *p; 1064 __be32 *p;
1024 1065
1025 RESERVE_SPACE(8 + name->len); 1066 p = reserve_space(xdr, 8 + name->len);
1026 WRITE32(OP_LINK); 1067 *p++ = cpu_to_be32(OP_LINK);
1027 WRITE32(name->len); 1068 xdr_encode_opaque(p, name->name, name->len);
1028 WRITEMEM(name->name, name->len);
1029 hdr->nops++; 1069 hdr->nops++;
1030 hdr->replen += decode_link_maxsz; 1070 hdr->replen += decode_link_maxsz;
1031} 1071}
@@ -1044,6 +1084,18 @@ static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1044 return fl->fl_end - fl->fl_start + 1; 1084 return fl->fl_end - fl->fl_start + 1;
1045} 1085}
1046 1086
1087static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1088{
1089 __be32 *p;
1090
1091 p = reserve_space(xdr, 32);
1092 p = xdr_encode_hyper(p, lowner->clientid);
1093 *p++ = cpu_to_be32(20);
1094 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1095 *p++ = cpu_to_be32(lowner->s_dev);
1096 xdr_encode_hyper(p, lowner->id);
1097}
1098
1047/* 1099/*
1048 * opcode,type,reclaim,offset,length,new_lock_owner = 32 1100 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1049 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 1101 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
@@ -1052,27 +1104,24 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
1052{ 1104{
1053 __be32 *p; 1105 __be32 *p;
1054 1106
1055 RESERVE_SPACE(32); 1107 p = reserve_space(xdr, 32);
1056 WRITE32(OP_LOCK); 1108 *p++ = cpu_to_be32(OP_LOCK);
1057 WRITE32(nfs4_lock_type(args->fl, args->block)); 1109 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1058 WRITE32(args->reclaim); 1110 *p++ = cpu_to_be32(args->reclaim);
1059 WRITE64(args->fl->fl_start); 1111 p = xdr_encode_hyper(p, args->fl->fl_start);
1060 WRITE64(nfs4_lock_length(args->fl)); 1112 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1061 WRITE32(args->new_lock_owner); 1113 *p = cpu_to_be32(args->new_lock_owner);
1062 if (args->new_lock_owner){ 1114 if (args->new_lock_owner){
1063 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32); 1115 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1064 WRITE32(args->open_seqid->sequence->counter); 1116 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1065 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE); 1117 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1066 WRITE32(args->lock_seqid->sequence->counter); 1118 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1067 WRITE64(args->lock_owner.clientid); 1119 encode_lockowner(xdr, &args->lock_owner);
1068 WRITE32(16);
1069 WRITEMEM("lock id:", 8);
1070 WRITE64(args->lock_owner.id);
1071 } 1120 }
1072 else { 1121 else {
1073 RESERVE_SPACE(NFS4_STATEID_SIZE+4); 1122 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1074 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE); 1123 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1075 WRITE32(args->lock_seqid->sequence->counter); 1124 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1076 } 1125 }
1077 hdr->nops++; 1126 hdr->nops++;
1078 hdr->replen += decode_lock_maxsz; 1127 hdr->replen += decode_lock_maxsz;
@@ -1082,15 +1131,12 @@ static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *ar
1082{ 1131{
1083 __be32 *p; 1132 __be32 *p;
1084 1133
1085 RESERVE_SPACE(52); 1134 p = reserve_space(xdr, 24);
1086 WRITE32(OP_LOCKT); 1135 *p++ = cpu_to_be32(OP_LOCKT);
1087 WRITE32(nfs4_lock_type(args->fl, 0)); 1136 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1088 WRITE64(args->fl->fl_start); 1137 p = xdr_encode_hyper(p, args->fl->fl_start);
1089 WRITE64(nfs4_lock_length(args->fl)); 1138 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1090 WRITE64(args->lock_owner.clientid); 1139 encode_lockowner(xdr, &args->lock_owner);
1091 WRITE32(16);
1092 WRITEMEM("lock id:", 8);
1093 WRITE64(args->lock_owner.id);
1094 hdr->nops++; 1140 hdr->nops++;
1095 hdr->replen += decode_lockt_maxsz; 1141 hdr->replen += decode_lockt_maxsz;
1096} 1142}
@@ -1099,26 +1145,36 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
1099{ 1145{
1100 __be32 *p; 1146 __be32 *p;
1101 1147
1102 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16); 1148 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1103 WRITE32(OP_LOCKU); 1149 *p++ = cpu_to_be32(OP_LOCKU);
1104 WRITE32(nfs4_lock_type(args->fl, 0)); 1150 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1105 WRITE32(args->seqid->sequence->counter); 1151 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1106 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE); 1152 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1107 WRITE64(args->fl->fl_start); 1153 p = xdr_encode_hyper(p, args->fl->fl_start);
1108 WRITE64(nfs4_lock_length(args->fl)); 1154 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1109 hdr->nops++; 1155 hdr->nops++;
1110 hdr->replen += decode_locku_maxsz; 1156 hdr->replen += decode_locku_maxsz;
1111} 1157}
1112 1158
1159static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1160{
1161 __be32 *p;
1162
1163 p = reserve_space(xdr, 4);
1164 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1165 encode_lockowner(xdr, lowner);
1166 hdr->nops++;
1167 hdr->replen += decode_release_lockowner_maxsz;
1168}
1169
1113static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1170static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1114{ 1171{
1115 int len = name->len; 1172 int len = name->len;
1116 __be32 *p; 1173 __be32 *p;
1117 1174
1118 RESERVE_SPACE(8 + len); 1175 p = reserve_space(xdr, 8 + len);
1119 WRITE32(OP_LOOKUP); 1176 *p++ = cpu_to_be32(OP_LOOKUP);
1120 WRITE32(len); 1177 xdr_encode_opaque(p, name->name, len);
1121 WRITEMEM(name->name, len);
1122 hdr->nops++; 1178 hdr->nops++;
1123 hdr->replen += decode_lookup_maxsz; 1179 hdr->replen += decode_lookup_maxsz;
1124} 1180}
@@ -1127,21 +1183,21 @@ static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1127{ 1183{
1128 __be32 *p; 1184 __be32 *p;
1129 1185
1130 RESERVE_SPACE(8); 1186 p = reserve_space(xdr, 8);
1131 switch (fmode & (FMODE_READ|FMODE_WRITE)) { 1187 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1132 case FMODE_READ: 1188 case FMODE_READ:
1133 WRITE32(NFS4_SHARE_ACCESS_READ); 1189 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1134 break; 1190 break;
1135 case FMODE_WRITE: 1191 case FMODE_WRITE:
1136 WRITE32(NFS4_SHARE_ACCESS_WRITE); 1192 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1137 break; 1193 break;
1138 case FMODE_READ|FMODE_WRITE: 1194 case FMODE_READ|FMODE_WRITE:
1139 WRITE32(NFS4_SHARE_ACCESS_BOTH); 1195 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1140 break; 1196 break;
1141 default: 1197 default:
1142 WRITE32(0); 1198 *p++ = cpu_to_be32(0);
1143 } 1199 }
1144 WRITE32(0); /* for linux, share_deny = 0 always */ 1200 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1145} 1201}
1146 1202
1147static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 1203static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
@@ -1151,30 +1207,47 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
1151 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 1207 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1152 * owner 4 = 32 1208 * owner 4 = 32
1153 */ 1209 */
1154 RESERVE_SPACE(8); 1210 p = reserve_space(xdr, 8);
1155 WRITE32(OP_OPEN); 1211 *p++ = cpu_to_be32(OP_OPEN);
1156 WRITE32(arg->seqid->sequence->counter); 1212 *p = cpu_to_be32(arg->seqid->sequence->counter);
1157 encode_share_access(xdr, arg->fmode); 1213 encode_share_access(xdr, arg->fmode);
1158 RESERVE_SPACE(28); 1214 p = reserve_space(xdr, 32);
1159 WRITE64(arg->clientid); 1215 p = xdr_encode_hyper(p, arg->clientid);
1160 WRITE32(16); 1216 *p++ = cpu_to_be32(20);
1161 WRITEMEM("open id:", 8); 1217 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1162 WRITE64(arg->id); 1218 *p++ = cpu_to_be32(arg->server->s_dev);
1219 xdr_encode_hyper(p, arg->id);
1163} 1220}
1164 1221
1165static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 1222static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1166{ 1223{
1167 __be32 *p; 1224 __be32 *p;
1225 struct nfs_client *clp;
1168 1226
1169 RESERVE_SPACE(4); 1227 p = reserve_space(xdr, 4);
1170 switch(arg->open_flags & O_EXCL) { 1228 switch(arg->open_flags & O_EXCL) {
1171 case 0: 1229 case 0:
1172 WRITE32(NFS4_CREATE_UNCHECKED); 1230 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1173 encode_attrs(xdr, arg->u.attrs, arg->server); 1231 encode_attrs(xdr, arg->u.attrs, arg->server);
1174 break; 1232 break;
1175 default: 1233 default:
1176 WRITE32(NFS4_CREATE_EXCLUSIVE); 1234 clp = arg->server->nfs_client;
1177 encode_nfs4_verifier(xdr, &arg->u.verifier); 1235 if (clp->cl_mvops->minor_version > 0) {
1236 if (nfs4_has_persistent_session(clp)) {
1237 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1238 encode_attrs(xdr, arg->u.attrs, arg->server);
1239 } else {
1240 struct iattr dummy;
1241
1242 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1243 encode_nfs4_verifier(xdr, &arg->u.verifier);
1244 dummy.ia_valid = 0;
1245 encode_attrs(xdr, &dummy, arg->server);
1246 }
1247 } else {
1248 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1249 encode_nfs4_verifier(xdr, &arg->u.verifier);
1250 }
1178 } 1251 }
1179} 1252}
1180 1253
@@ -1182,14 +1255,14 @@ static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *a
1182{ 1255{
1183 __be32 *p; 1256 __be32 *p;
1184 1257
1185 RESERVE_SPACE(4); 1258 p = reserve_space(xdr, 4);
1186 switch (arg->open_flags & O_CREAT) { 1259 switch (arg->open_flags & O_CREAT) {
1187 case 0: 1260 case 0:
1188 WRITE32(NFS4_OPEN_NOCREATE); 1261 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1189 break; 1262 break;
1190 default: 1263 default:
1191 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 1264 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1192 WRITE32(NFS4_OPEN_CREATE); 1265 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1193 encode_createmode(xdr, arg); 1266 encode_createmode(xdr, arg);
1194 } 1267 }
1195} 1268}
@@ -1198,16 +1271,16 @@ static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delega
1198{ 1271{
1199 __be32 *p; 1272 __be32 *p;
1200 1273
1201 RESERVE_SPACE(4); 1274 p = reserve_space(xdr, 4);
1202 switch (delegation_type) { 1275 switch (delegation_type) {
1203 case 0: 1276 case 0:
1204 WRITE32(NFS4_OPEN_DELEGATE_NONE); 1277 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1205 break; 1278 break;
1206 case FMODE_READ: 1279 case FMODE_READ:
1207 WRITE32(NFS4_OPEN_DELEGATE_READ); 1280 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1208 break; 1281 break;
1209 case FMODE_WRITE|FMODE_READ: 1282 case FMODE_WRITE|FMODE_READ:
1210 WRITE32(NFS4_OPEN_DELEGATE_WRITE); 1283 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1211 break; 1284 break;
1212 default: 1285 default:
1213 BUG(); 1286 BUG();
@@ -1218,8 +1291,8 @@ static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *
1218{ 1291{
1219 __be32 *p; 1292 __be32 *p;
1220 1293
1221 RESERVE_SPACE(4); 1294 p = reserve_space(xdr, 4);
1222 WRITE32(NFS4_OPEN_CLAIM_NULL); 1295 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1223 encode_string(xdr, name->len, name->name); 1296 encode_string(xdr, name->len, name->name);
1224} 1297}
1225 1298
@@ -1227,8 +1300,8 @@ static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1227{ 1300{
1228 __be32 *p; 1301 __be32 *p;
1229 1302
1230 RESERVE_SPACE(4); 1303 p = reserve_space(xdr, 4);
1231 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS); 1304 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1232 encode_delegation_type(xdr, type); 1305 encode_delegation_type(xdr, type);
1233} 1306}
1234 1307
@@ -1236,9 +1309,9 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
1236{ 1309{
1237 __be32 *p; 1310 __be32 *p;
1238 1311
1239 RESERVE_SPACE(4+NFS4_STATEID_SIZE); 1312 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1240 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1313 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1241 WRITEMEM(stateid->data, NFS4_STATEID_SIZE); 1314 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1242 encode_string(xdr, name->len, name->name); 1315 encode_string(xdr, name->len, name->name);
1243} 1316}
1244 1317
@@ -1267,10 +1340,10 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co
1267{ 1340{
1268 __be32 *p; 1341 __be32 *p;
1269 1342
1270 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4); 1343 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1271 WRITE32(OP_OPEN_CONFIRM); 1344 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1272 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE); 1345 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1273 WRITE32(arg->seqid->sequence->counter); 1346 *p = cpu_to_be32(arg->seqid->sequence->counter);
1274 hdr->nops++; 1347 hdr->nops++;
1275 hdr->replen += decode_open_confirm_maxsz; 1348 hdr->replen += decode_open_confirm_maxsz;
1276} 1349}
@@ -1279,10 +1352,10 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
1279{ 1352{
1280 __be32 *p; 1353 __be32 *p;
1281 1354
1282 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4); 1355 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1283 WRITE32(OP_OPEN_DOWNGRADE); 1356 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1284 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE); 1357 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1285 WRITE32(arg->seqid->sequence->counter); 1358 *p = cpu_to_be32(arg->seqid->sequence->counter);
1286 encode_share_access(xdr, arg->fmode); 1359 encode_share_access(xdr, arg->fmode);
1287 hdr->nops++; 1360 hdr->nops++;
1288 hdr->replen += decode_open_downgrade_maxsz; 1361 hdr->replen += decode_open_downgrade_maxsz;
@@ -1294,10 +1367,9 @@ encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hd
1294 int len = fh->size; 1367 int len = fh->size;
1295 __be32 *p; 1368 __be32 *p;
1296 1369
1297 RESERVE_SPACE(8 + len); 1370 p = reserve_space(xdr, 8 + len);
1298 WRITE32(OP_PUTFH); 1371 *p++ = cpu_to_be32(OP_PUTFH);
1299 WRITE32(len); 1372 xdr_encode_opaque(p, fh->data, len);
1300 WRITEMEM(fh->data, len);
1301 hdr->nops++; 1373 hdr->nops++;
1302 hdr->replen += decode_putfh_maxsz; 1374 hdr->replen += decode_putfh_maxsz;
1303} 1375}
@@ -1306,63 +1378,74 @@ static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1306{ 1378{
1307 __be32 *p; 1379 __be32 *p;
1308 1380
1309 RESERVE_SPACE(4); 1381 p = reserve_space(xdr, 4);
1310 WRITE32(OP_PUTROOTFH); 1382 *p = cpu_to_be32(OP_PUTROOTFH);
1311 hdr->nops++; 1383 hdr->nops++;
1312 hdr->replen += decode_putrootfh_maxsz; 1384 hdr->replen += decode_putrootfh_maxsz;
1313} 1385}
1314 1386
1315static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx) 1387static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
1316{ 1388{
1317 nfs4_stateid stateid; 1389 nfs4_stateid stateid;
1318 __be32 *p; 1390 __be32 *p;
1319 1391
1320 RESERVE_SPACE(NFS4_STATEID_SIZE); 1392 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1321 if (ctx->state != NULL) { 1393 if (ctx->state != NULL) {
1322 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner); 1394 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1323 WRITEMEM(stateid.data, NFS4_STATEID_SIZE); 1395 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1324 } else 1396 } else
1325 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE); 1397 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1326} 1398}
1327 1399
1328static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 1400static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1329{ 1401{
1330 __be32 *p; 1402 __be32 *p;
1331 1403
1332 RESERVE_SPACE(4); 1404 p = reserve_space(xdr, 4);
1333 WRITE32(OP_READ); 1405 *p = cpu_to_be32(OP_READ);
1334 1406
1335 encode_stateid(xdr, args->context); 1407 encode_stateid(xdr, args->context, args->lock_context);
1336 1408
1337 RESERVE_SPACE(12); 1409 p = reserve_space(xdr, 12);
1338 WRITE64(args->offset); 1410 p = xdr_encode_hyper(p, args->offset);
1339 WRITE32(args->count); 1411 *p = cpu_to_be32(args->count);
1340 hdr->nops++; 1412 hdr->nops++;
1341 hdr->replen += decode_read_maxsz; 1413 hdr->replen += decode_read_maxsz;
1342} 1414}
1343 1415
1344static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 1416static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1345{ 1417{
1346 uint32_t attrs[2] = { 1418 uint32_t attrs[2] = {0, 0};
1347 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, 1419 uint32_t dircount = readdir->count >> 1;
1348 FATTR4_WORD1_MOUNTED_ON_FILEID,
1349 };
1350 __be32 *p; 1420 __be32 *p;
1351 1421
1352 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20); 1422 if (readdir->plus) {
1353 WRITE32(OP_READDIR); 1423 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1354 WRITE64(readdir->cookie); 1424 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1355 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE); 1425 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1356 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */ 1426 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1357 WRITE32(readdir->count); 1427 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1358 WRITE32(2); 1428 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1429 dircount >>= 1;
1430 }
1431 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1432 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
1359 /* Switch to mounted_on_fileid if the server supports it */ 1433 /* Switch to mounted_on_fileid if the server supports it */
1360 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) 1434 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1361 attrs[0] &= ~FATTR4_WORD0_FILEID; 1435 attrs[0] &= ~FATTR4_WORD0_FILEID;
1362 else 1436 else
1363 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 1437 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1364 WRITE32(attrs[0] & readdir->bitmask[0]); 1438
1365 WRITE32(attrs[1] & readdir->bitmask[1]); 1439 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1440 *p++ = cpu_to_be32(OP_READDIR);
1441 p = xdr_encode_hyper(p, readdir->cookie);
1442 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1443 *p++ = cpu_to_be32(dircount);
1444 *p++ = cpu_to_be32(readdir->count);
1445 *p++ = cpu_to_be32(2);
1446
1447 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1448 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1366 hdr->nops++; 1449 hdr->nops++;
1367 hdr->replen += decode_readdir_maxsz; 1450 hdr->replen += decode_readdir_maxsz;
1368 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 1451 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
@@ -1378,8 +1461,8 @@ static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *
1378{ 1461{
1379 __be32 *p; 1462 __be32 *p;
1380 1463
1381 RESERVE_SPACE(4); 1464 p = reserve_space(xdr, 4);
1382 WRITE32(OP_READLINK); 1465 *p = cpu_to_be32(OP_READLINK);
1383 hdr->nops++; 1466 hdr->nops++;
1384 hdr->replen += decode_readlink_maxsz; 1467 hdr->replen += decode_readlink_maxsz;
1385} 1468}
@@ -1388,10 +1471,9 @@ static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struc
1388{ 1471{
1389 __be32 *p; 1472 __be32 *p;
1390 1473
1391 RESERVE_SPACE(8 + name->len); 1474 p = reserve_space(xdr, 8 + name->len);
1392 WRITE32(OP_REMOVE); 1475 *p++ = cpu_to_be32(OP_REMOVE);
1393 WRITE32(name->len); 1476 xdr_encode_opaque(p, name->name, name->len);
1394 WRITEMEM(name->name, name->len);
1395 hdr->nops++; 1477 hdr->nops++;
1396 hdr->replen += decode_remove_maxsz; 1478 hdr->replen += decode_remove_maxsz;
1397} 1479}
@@ -1400,14 +1482,10 @@ static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, co
1400{ 1482{
1401 __be32 *p; 1483 __be32 *p;
1402 1484
1403 RESERVE_SPACE(8 + oldname->len); 1485 p = reserve_space(xdr, 4);
1404 WRITE32(OP_RENAME); 1486 *p = cpu_to_be32(OP_RENAME);
1405 WRITE32(oldname->len); 1487 encode_string(xdr, oldname->len, oldname->name);
1406 WRITEMEM(oldname->name, oldname->len); 1488 encode_string(xdr, newname->len, newname->name);
1407
1408 RESERVE_SPACE(4 + newname->len);
1409 WRITE32(newname->len);
1410 WRITEMEM(newname->name, newname->len);
1411 hdr->nops++; 1489 hdr->nops++;
1412 hdr->replen += decode_rename_maxsz; 1490 hdr->replen += decode_rename_maxsz;
1413} 1491}
@@ -1416,9 +1494,9 @@ static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client
1416{ 1494{
1417 __be32 *p; 1495 __be32 *p;
1418 1496
1419 RESERVE_SPACE(12); 1497 p = reserve_space(xdr, 12);
1420 WRITE32(OP_RENEW); 1498 *p++ = cpu_to_be32(OP_RENEW);
1421 WRITE64(client_stateid->cl_clientid); 1499 xdr_encode_hyper(p, client_stateid->cl_clientid);
1422 hdr->nops++; 1500 hdr->nops++;
1423 hdr->replen += decode_renew_maxsz; 1501 hdr->replen += decode_renew_maxsz;
1424} 1502}
@@ -1428,31 +1506,29 @@ encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1428{ 1506{
1429 __be32 *p; 1507 __be32 *p;
1430 1508
1431 RESERVE_SPACE(4); 1509 p = reserve_space(xdr, 4);
1432 WRITE32(OP_RESTOREFH); 1510 *p = cpu_to_be32(OP_RESTOREFH);
1433 hdr->nops++; 1511 hdr->nops++;
1434 hdr->replen += decode_restorefh_maxsz; 1512 hdr->replen += decode_restorefh_maxsz;
1435} 1513}
1436 1514
1437static int 1515static void
1438encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 1516encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1439{ 1517{
1440 __be32 *p; 1518 __be32 *p;
1441 1519
1442 RESERVE_SPACE(4+NFS4_STATEID_SIZE); 1520 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1443 WRITE32(OP_SETATTR); 1521 *p++ = cpu_to_be32(OP_SETATTR);
1444 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE); 1522 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1445 RESERVE_SPACE(2*4); 1523 p = reserve_space(xdr, 2*4);
1446 WRITE32(1); 1524 *p++ = cpu_to_be32(1);
1447 WRITE32(FATTR4_WORD0_ACL); 1525 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1448 if (arg->acl_len % 4) 1526 BUG_ON(arg->acl_len % 4);
1449 return -EINVAL; 1527 p = reserve_space(xdr, 4);
1450 RESERVE_SPACE(4); 1528 *p = cpu_to_be32(arg->acl_len);
1451 WRITE32(arg->acl_len);
1452 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 1529 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1453 hdr->nops++; 1530 hdr->nops++;
1454 hdr->replen += decode_setacl_maxsz; 1531 hdr->replen += decode_setacl_maxsz;
1455 return 0;
1456} 1532}
1457 1533
1458static void 1534static void
@@ -1460,8 +1536,8 @@ encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1460{ 1536{
1461 __be32 *p; 1537 __be32 *p;
1462 1538
1463 RESERVE_SPACE(4); 1539 p = reserve_space(xdr, 4);
1464 WRITE32(OP_SAVEFH); 1540 *p = cpu_to_be32(OP_SAVEFH);
1465 hdr->nops++; 1541 hdr->nops++;
1466 hdr->replen += decode_savefh_maxsz; 1542 hdr->replen += decode_savefh_maxsz;
1467} 1543}
@@ -1470,9 +1546,9 @@ static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs
1470{ 1546{
1471 __be32 *p; 1547 __be32 *p;
1472 1548
1473 RESERVE_SPACE(4+NFS4_STATEID_SIZE); 1549 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1474 WRITE32(OP_SETATTR); 1550 *p++ = cpu_to_be32(OP_SETATTR);
1475 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE); 1551 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1476 hdr->nops++; 1552 hdr->nops++;
1477 hdr->replen += decode_setattr_maxsz; 1553 hdr->replen += decode_setattr_maxsz;
1478 encode_attrs(xdr, arg->iap, server); 1554 encode_attrs(xdr, arg->iap, server);
@@ -1482,29 +1558,29 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
1482{ 1558{
1483 __be32 *p; 1559 __be32 *p;
1484 1560
1485 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE); 1561 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1486 WRITE32(OP_SETCLIENTID); 1562 *p++ = cpu_to_be32(OP_SETCLIENTID);
1487 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE); 1563 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1488 1564
1489 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 1565 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1490 RESERVE_SPACE(4); 1566 p = reserve_space(xdr, 4);
1491 WRITE32(setclientid->sc_prog); 1567 *p = cpu_to_be32(setclientid->sc_prog);
1492 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 1568 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1493 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 1569 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1494 RESERVE_SPACE(4); 1570 p = reserve_space(xdr, 4);
1495 WRITE32(setclientid->sc_cb_ident); 1571 *p = cpu_to_be32(setclientid->sc_cb_ident);
1496 hdr->nops++; 1572 hdr->nops++;
1497 hdr->replen += decode_setclientid_maxsz; 1573 hdr->replen += decode_setclientid_maxsz;
1498} 1574}
1499 1575
1500static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr) 1576static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1501{ 1577{
1502 __be32 *p; 1578 __be32 *p;
1503 1579
1504 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE); 1580 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1505 WRITE32(OP_SETCLIENTID_CONFIRM); 1581 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1506 WRITE64(client_state->cl_clientid); 1582 p = xdr_encode_hyper(p, arg->clientid);
1507 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE); 1583 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1508 hdr->nops++; 1584 hdr->nops++;
1509 hdr->replen += decode_setclientid_confirm_maxsz; 1585 hdr->replen += decode_setclientid_confirm_maxsz;
1510} 1586}
@@ -1513,15 +1589,15 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
1513{ 1589{
1514 __be32 *p; 1590 __be32 *p;
1515 1591
1516 RESERVE_SPACE(4); 1592 p = reserve_space(xdr, 4);
1517 WRITE32(OP_WRITE); 1593 *p = cpu_to_be32(OP_WRITE);
1518 1594
1519 encode_stateid(xdr, args->context); 1595 encode_stateid(xdr, args->context, args->lock_context);
1520 1596
1521 RESERVE_SPACE(16); 1597 p = reserve_space(xdr, 16);
1522 WRITE64(args->offset); 1598 p = xdr_encode_hyper(p, args->offset);
1523 WRITE32(args->stable); 1599 *p++ = cpu_to_be32(args->stable);
1524 WRITE32(args->count); 1600 *p = cpu_to_be32(args->count);
1525 1601
1526 xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 1602 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1527 hdr->nops++; 1603 hdr->nops++;
@@ -1532,10 +1608,10 @@ static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *state
1532{ 1608{
1533 __be32 *p; 1609 __be32 *p;
1534 1610
1535 RESERVE_SPACE(4+NFS4_STATEID_SIZE); 1611 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1536 1612
1537 WRITE32(OP_DELEGRETURN); 1613 *p++ = cpu_to_be32(OP_DELEGRETURN);
1538 WRITEMEM(stateid->data, NFS4_STATEID_SIZE); 1614 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1539 hdr->nops++; 1615 hdr->nops++;
1540 hdr->replen += decode_delegreturn_maxsz; 1616 hdr->replen += decode_delegreturn_maxsz;
1541} 1617}
@@ -1548,16 +1624,16 @@ static void encode_exchange_id(struct xdr_stream *xdr,
1548{ 1624{
1549 __be32 *p; 1625 __be32 *p;
1550 1626
1551 RESERVE_SPACE(4 + sizeof(args->verifier->data)); 1627 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1552 WRITE32(OP_EXCHANGE_ID); 1628 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1553 WRITEMEM(args->verifier->data, sizeof(args->verifier->data)); 1629 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1554 1630
1555 encode_string(xdr, args->id_len, args->id); 1631 encode_string(xdr, args->id_len, args->id);
1556 1632
1557 RESERVE_SPACE(12); 1633 p = reserve_space(xdr, 12);
1558 WRITE32(args->flags); 1634 *p++ = cpu_to_be32(args->flags);
1559 WRITE32(0); /* zero length state_protect4_a */ 1635 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1560 WRITE32(0); /* zero length implementation id array */ 1636 *p = cpu_to_be32(0); /* zero length implementation id array */
1561 hdr->nops++; 1637 hdr->nops++;
1562 hdr->replen += decode_exchange_id_maxsz; 1638 hdr->replen += decode_exchange_id_maxsz;
1563} 1639}
@@ -1570,56 +1646,52 @@ static void encode_create_session(struct xdr_stream *xdr,
1570 char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1646 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1571 uint32_t len; 1647 uint32_t len;
1572 struct nfs_client *clp = args->client; 1648 struct nfs_client *clp = args->client;
1649 u32 max_resp_sz_cached;
1573 1650
1574 RESERVE_SPACE(4); 1651 /*
1575 WRITE32(OP_CREATE_SESSION); 1652 * Assumes OPEN is the biggest non-idempotent compound.
1653 * 2 is the verifier.
1654 */
1655 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1656 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1576 1657
1577 RESERVE_SPACE(8); 1658 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1578 WRITE64(clp->cl_ex_clid); 1659 clp->cl_ipaddr);
1579 1660
1580 RESERVE_SPACE(8); 1661 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1581 WRITE32(clp->cl_seqid); /*Sequence id */ 1662 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1582 WRITE32(args->flags); /*flags */ 1663 p = xdr_encode_hyper(p, clp->cl_ex_clid);
1664 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1665 *p++ = cpu_to_be32(args->flags); /*flags */
1583 1666
1584 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1585 /* Fore Channel */ 1667 /* Fore Channel */
1586 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */ 1668 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1587 WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */ 1669 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1588 WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */ 1670 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1589 WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1671 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1590 WRITE32(args->fc_attrs.max_ops); /* max operations */ 1672 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1591 WRITE32(args->fc_attrs.max_reqs); /* max requests */ 1673 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1592 WRITE32(0); /* rdmachannel_attrs */ 1674 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1593 1675
1594 /* Back Channel */ 1676 /* Back Channel */
1595 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */ 1677 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1596 WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */ 1678 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1597 WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */ 1679 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1598 WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1680 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1599 WRITE32(args->bc_attrs.max_ops); /* max operations */ 1681 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1600 WRITE32(args->bc_attrs.max_reqs); /* max requests */ 1682 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1601 WRITE32(0); /* rdmachannel_attrs */ 1683 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1602 1684
1603 RESERVE_SPACE(4); 1685 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1604 WRITE32(args->cb_program); /* cb_program */ 1686 *p++ = cpu_to_be32(1);
1605 1687 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1606 RESERVE_SPACE(4); /* # of security flavors */
1607 WRITE32(1);
1608
1609 RESERVE_SPACE(4);
1610 WRITE32(RPC_AUTH_UNIX); /* auth_sys */
1611 1688
1612 /* authsys_parms rfc1831 */ 1689 /* authsys_parms rfc1831 */
1613 RESERVE_SPACE(4); 1690 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1614 WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ 1691 p = xdr_encode_opaque(p, machine_name, len);
1615 len = scnprintf(machine_name, sizeof(machine_name), "%s", 1692 *p++ = cpu_to_be32(0); /* UID */
1616 clp->cl_ipaddr); 1693 *p++ = cpu_to_be32(0); /* GID */
1617 RESERVE_SPACE(16 + len); 1694 *p = cpu_to_be32(0); /* No more gids */
1618 WRITE32(len);
1619 WRITEMEM(machine_name, len);
1620 WRITE32(0); /* UID */
1621 WRITE32(0); /* GID */
1622 WRITE32(0); /* No more gids */
1623 hdr->nops++; 1695 hdr->nops++;
1624 hdr->replen += decode_create_session_maxsz; 1696 hdr->replen += decode_create_session_maxsz;
1625} 1697}
@@ -1629,12 +1701,25 @@ static void encode_destroy_session(struct xdr_stream *xdr,
1629 struct compound_hdr *hdr) 1701 struct compound_hdr *hdr)
1630{ 1702{
1631 __be32 *p; 1703 __be32 *p;
1632 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN); 1704 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1633 WRITE32(OP_DESTROY_SESSION); 1705 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1634 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1706 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1635 hdr->nops++; 1707 hdr->nops++;
1636 hdr->replen += decode_destroy_session_maxsz; 1708 hdr->replen += decode_destroy_session_maxsz;
1637} 1709}
1710
1711static void encode_reclaim_complete(struct xdr_stream *xdr,
1712 struct nfs41_reclaim_complete_args *args,
1713 struct compound_hdr *hdr)
1714{
1715 __be32 *p;
1716
1717 p = reserve_space(xdr, 8);
1718 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1719 *p++ = cpu_to_be32(args->one_fs);
1720 hdr->nops++;
1721 hdr->replen += decode_reclaim_complete_maxsz;
1722}
1638#endif /* CONFIG_NFS_V4_1 */ 1723#endif /* CONFIG_NFS_V4_1 */
1639 1724
1640static void encode_sequence(struct xdr_stream *xdr, 1725static void encode_sequence(struct xdr_stream *xdr,
@@ -1655,8 +1740,8 @@ static void encode_sequence(struct xdr_stream *xdr,
1655 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1740 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1656 slot = tp->slots + args->sa_slotid; 1741 slot = tp->slots + args->sa_slotid;
1657 1742
1658 RESERVE_SPACE(4); 1743 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1659 WRITE32(OP_SEQUENCE); 1744 *p++ = cpu_to_be32(OP_SEQUENCE);
1660 1745
1661 /* 1746 /*
1662 * Sessionid + seqid + slotid + max slotid + cache_this 1747 * Sessionid + seqid + slotid + max slotid + cache_this
@@ -1670,17 +1755,65 @@ static void encode_sequence(struct xdr_stream *xdr,
1670 ((u32 *)session->sess_id.data)[3], 1755 ((u32 *)session->sess_id.data)[3],
1671 slot->seq_nr, args->sa_slotid, 1756 slot->seq_nr, args->sa_slotid,
1672 tp->highest_used_slotid, args->sa_cache_this); 1757 tp->highest_used_slotid, args->sa_cache_this);
1673 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16); 1758 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1674 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1759 *p++ = cpu_to_be32(slot->seq_nr);
1675 WRITE32(slot->seq_nr); 1760 *p++ = cpu_to_be32(args->sa_slotid);
1676 WRITE32(args->sa_slotid); 1761 *p++ = cpu_to_be32(tp->highest_used_slotid);
1677 WRITE32(tp->highest_used_slotid); 1762 *p = cpu_to_be32(args->sa_cache_this);
1678 WRITE32(args->sa_cache_this);
1679 hdr->nops++; 1763 hdr->nops++;
1680 hdr->replen += decode_sequence_maxsz; 1764 hdr->replen += decode_sequence_maxsz;
1681#endif /* CONFIG_NFS_V4_1 */ 1765#endif /* CONFIG_NFS_V4_1 */
1682} 1766}
1683 1767
1768#ifdef CONFIG_NFS_V4_1
1769static void
1770encode_getdeviceinfo(struct xdr_stream *xdr,
1771 const struct nfs4_getdeviceinfo_args *args,
1772 struct compound_hdr *hdr)
1773{
1774 __be32 *p;
1775
1776 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1777 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1778 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1779 NFS4_DEVICEID4_SIZE);
1780 *p++ = cpu_to_be32(args->pdev->layout_type);
1781 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1782 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1783 hdr->nops++;
1784 hdr->replen += decode_getdeviceinfo_maxsz;
1785}
1786
1787static void
1788encode_layoutget(struct xdr_stream *xdr,
1789 const struct nfs4_layoutget_args *args,
1790 struct compound_hdr *hdr)
1791{
1792 __be32 *p;
1793
1794 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1795 *p++ = cpu_to_be32(OP_LAYOUTGET);
1796 *p++ = cpu_to_be32(0); /* Signal layout available */
1797 *p++ = cpu_to_be32(args->type);
1798 *p++ = cpu_to_be32(args->range.iomode);
1799 p = xdr_encode_hyper(p, args->range.offset);
1800 p = xdr_encode_hyper(p, args->range.length);
1801 p = xdr_encode_hyper(p, args->minlength);
1802 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1803 *p = cpu_to_be32(args->maxcount);
1804
1805 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1806 __func__,
1807 args->type,
1808 args->range.iomode,
1809 (unsigned long)args->range.offset,
1810 (unsigned long)args->range.length,
1811 args->maxcount);
1812 hdr->nops++;
1813 hdr->replen += decode_layoutget_maxsz;
1814}
1815#endif /* CONFIG_NFS_V4_1 */
1816
1684/* 1817/*
1685 * END OF "GENERIC" ENCODE ROUTINES. 1818 * END OF "GENERIC" ENCODE ROUTINES.
1686 */ 1819 */
@@ -1689,7 +1822,7 @@ static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1689{ 1822{
1690#if defined(CONFIG_NFS_V4_1) 1823#if defined(CONFIG_NFS_V4_1)
1691 if (args->sa_session) 1824 if (args->sa_session)
1692 return args->sa_session->clp->cl_minorversion; 1825 return args->sa_session->clp->cl_mvops->minor_version;
1693#endif /* CONFIG_NFS_V4_1 */ 1826#endif /* CONFIG_NFS_V4_1 */
1694 return 0; 1827 return 0;
1695} 1828}
@@ -1697,379 +1830,362 @@ static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1697/* 1830/*
1698 * Encode an ACCESS request 1831 * Encode an ACCESS request
1699 */ 1832 */
1700static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args) 1833static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1834 const struct nfs4_accessargs *args)
1701{ 1835{
1702 struct xdr_stream xdr;
1703 struct compound_hdr hdr = { 1836 struct compound_hdr hdr = {
1704 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1837 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1705 }; 1838 };
1706 1839
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1840 encode_compound_hdr(xdr, req, &hdr);
1708 encode_compound_hdr(&xdr, req, &hdr); 1841 encode_sequence(xdr, &args->seq_args, &hdr);
1709 encode_sequence(&xdr, &args->seq_args, &hdr); 1842 encode_putfh(xdr, args->fh, &hdr);
1710 encode_putfh(&xdr, args->fh, &hdr); 1843 encode_access(xdr, args->access, &hdr);
1711 encode_access(&xdr, args->access, &hdr); 1844 encode_getfattr(xdr, args->bitmask, &hdr);
1712 encode_getfattr(&xdr, args->bitmask, &hdr);
1713 encode_nops(&hdr); 1845 encode_nops(&hdr);
1714 return 0;
1715} 1846}
1716 1847
1717/* 1848/*
1718 * Encode LOOKUP request 1849 * Encode LOOKUP request
1719 */ 1850 */
1720static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args) 1851static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1852 const struct nfs4_lookup_arg *args)
1721{ 1853{
1722 struct xdr_stream xdr;
1723 struct compound_hdr hdr = { 1854 struct compound_hdr hdr = {
1724 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1855 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1725 }; 1856 };
1726 1857
1727 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1858 encode_compound_hdr(xdr, req, &hdr);
1728 encode_compound_hdr(&xdr, req, &hdr); 1859 encode_sequence(xdr, &args->seq_args, &hdr);
1729 encode_sequence(&xdr, &args->seq_args, &hdr); 1860 encode_putfh(xdr, args->dir_fh, &hdr);
1730 encode_putfh(&xdr, args->dir_fh, &hdr); 1861 encode_lookup(xdr, args->name, &hdr);
1731 encode_lookup(&xdr, args->name, &hdr); 1862 encode_getfh(xdr, &hdr);
1732 encode_getfh(&xdr, &hdr); 1863 encode_getfattr(xdr, args->bitmask, &hdr);
1733 encode_getfattr(&xdr, args->bitmask, &hdr);
1734 encode_nops(&hdr); 1864 encode_nops(&hdr);
1735 return 0;
1736} 1865}
1737 1866
1738/* 1867/*
1739 * Encode LOOKUP_ROOT request 1868 * Encode LOOKUP_ROOT request
1740 */ 1869 */
1741static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args) 1870static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1871 struct xdr_stream *xdr,
1872 const struct nfs4_lookup_root_arg *args)
1742{ 1873{
1743 struct xdr_stream xdr;
1744 struct compound_hdr hdr = { 1874 struct compound_hdr hdr = {
1745 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1875 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1746 }; 1876 };
1747 1877
1748 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1878 encode_compound_hdr(xdr, req, &hdr);
1749 encode_compound_hdr(&xdr, req, &hdr); 1879 encode_sequence(xdr, &args->seq_args, &hdr);
1750 encode_sequence(&xdr, &args->seq_args, &hdr); 1880 encode_putrootfh(xdr, &hdr);
1751 encode_putrootfh(&xdr, &hdr); 1881 encode_getfh(xdr, &hdr);
1752 encode_getfh(&xdr, &hdr); 1882 encode_getfattr(xdr, args->bitmask, &hdr);
1753 encode_getfattr(&xdr, args->bitmask, &hdr);
1754 encode_nops(&hdr); 1883 encode_nops(&hdr);
1755 return 0;
1756} 1884}
1757 1885
1758/* 1886/*
1759 * Encode REMOVE request 1887 * Encode REMOVE request
1760 */ 1888 */
1761static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) 1889static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1890 const struct nfs_removeargs *args)
1762{ 1891{
1763 struct xdr_stream xdr;
1764 struct compound_hdr hdr = { 1892 struct compound_hdr hdr = {
1765 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1893 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1766 }; 1894 };
1767 1895
1768 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1896 encode_compound_hdr(xdr, req, &hdr);
1769 encode_compound_hdr(&xdr, req, &hdr); 1897 encode_sequence(xdr, &args->seq_args, &hdr);
1770 encode_sequence(&xdr, &args->seq_args, &hdr); 1898 encode_putfh(xdr, args->fh, &hdr);
1771 encode_putfh(&xdr, args->fh, &hdr); 1899 encode_remove(xdr, &args->name, &hdr);
1772 encode_remove(&xdr, &args->name, &hdr); 1900 encode_getfattr(xdr, args->bitmask, &hdr);
1773 encode_getfattr(&xdr, args->bitmask, &hdr);
1774 encode_nops(&hdr); 1901 encode_nops(&hdr);
1775 return 0;
1776} 1902}
1777 1903
1778/* 1904/*
1779 * Encode RENAME request 1905 * Encode RENAME request
1780 */ 1906 */
1781static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args) 1907static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1908 const struct nfs_renameargs *args)
1782{ 1909{
1783 struct xdr_stream xdr;
1784 struct compound_hdr hdr = { 1910 struct compound_hdr hdr = {
1785 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1911 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1786 }; 1912 };
1787 1913
1788 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1914 encode_compound_hdr(xdr, req, &hdr);
1789 encode_compound_hdr(&xdr, req, &hdr); 1915 encode_sequence(xdr, &args->seq_args, &hdr);
1790 encode_sequence(&xdr, &args->seq_args, &hdr); 1916 encode_putfh(xdr, args->old_dir, &hdr);
1791 encode_putfh(&xdr, args->old_dir, &hdr); 1917 encode_savefh(xdr, &hdr);
1792 encode_savefh(&xdr, &hdr); 1918 encode_putfh(xdr, args->new_dir, &hdr);
1793 encode_putfh(&xdr, args->new_dir, &hdr); 1919 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1794 encode_rename(&xdr, args->old_name, args->new_name, &hdr); 1920 encode_getfattr(xdr, args->bitmask, &hdr);
1795 encode_getfattr(&xdr, args->bitmask, &hdr); 1921 encode_restorefh(xdr, &hdr);
1796 encode_restorefh(&xdr, &hdr); 1922 encode_getfattr(xdr, args->bitmask, &hdr);
1797 encode_getfattr(&xdr, args->bitmask, &hdr);
1798 encode_nops(&hdr); 1923 encode_nops(&hdr);
1799 return 0;
1800} 1924}
1801 1925
1802/* 1926/*
1803 * Encode LINK request 1927 * Encode LINK request
1804 */ 1928 */
1805static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args) 1929static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1930 const struct nfs4_link_arg *args)
1806{ 1931{
1807 struct xdr_stream xdr;
1808 struct compound_hdr hdr = { 1932 struct compound_hdr hdr = {
1809 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1810 }; 1934 };
1811 1935
1812 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1936 encode_compound_hdr(xdr, req, &hdr);
1813 encode_compound_hdr(&xdr, req, &hdr); 1937 encode_sequence(xdr, &args->seq_args, &hdr);
1814 encode_sequence(&xdr, &args->seq_args, &hdr); 1938 encode_putfh(xdr, args->fh, &hdr);
1815 encode_putfh(&xdr, args->fh, &hdr); 1939 encode_savefh(xdr, &hdr);
1816 encode_savefh(&xdr, &hdr); 1940 encode_putfh(xdr, args->dir_fh, &hdr);
1817 encode_putfh(&xdr, args->dir_fh, &hdr); 1941 encode_link(xdr, args->name, &hdr);
1818 encode_link(&xdr, args->name, &hdr); 1942 encode_getfattr(xdr, args->bitmask, &hdr);
1819 encode_getfattr(&xdr, args->bitmask, &hdr); 1943 encode_restorefh(xdr, &hdr);
1820 encode_restorefh(&xdr, &hdr); 1944 encode_getfattr(xdr, args->bitmask, &hdr);
1821 encode_getfattr(&xdr, args->bitmask, &hdr);
1822 encode_nops(&hdr); 1945 encode_nops(&hdr);
1823 return 0;
1824} 1946}
1825 1947
1826/* 1948/*
1827 * Encode CREATE request 1949 * Encode CREATE request
1828 */ 1950 */
1829static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) 1951static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
1952 const struct nfs4_create_arg *args)
1830{ 1953{
1831 struct xdr_stream xdr;
1832 struct compound_hdr hdr = { 1954 struct compound_hdr hdr = {
1833 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1834 }; 1956 };
1835 1957
1836 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1958 encode_compound_hdr(xdr, req, &hdr);
1837 encode_compound_hdr(&xdr, req, &hdr); 1959 encode_sequence(xdr, &args->seq_args, &hdr);
1838 encode_sequence(&xdr, &args->seq_args, &hdr); 1960 encode_putfh(xdr, args->dir_fh, &hdr);
1839 encode_putfh(&xdr, args->dir_fh, &hdr); 1961 encode_savefh(xdr, &hdr);
1840 encode_savefh(&xdr, &hdr); 1962 encode_create(xdr, args, &hdr);
1841 encode_create(&xdr, args, &hdr); 1963 encode_getfh(xdr, &hdr);
1842 encode_getfh(&xdr, &hdr); 1964 encode_getfattr(xdr, args->bitmask, &hdr);
1843 encode_getfattr(&xdr, args->bitmask, &hdr); 1965 encode_restorefh(xdr, &hdr);
1844 encode_restorefh(&xdr, &hdr); 1966 encode_getfattr(xdr, args->bitmask, &hdr);
1845 encode_getfattr(&xdr, args->bitmask, &hdr);
1846 encode_nops(&hdr); 1967 encode_nops(&hdr);
1847 return 0;
1848} 1968}
1849 1969
1850/* 1970/*
1851 * Encode SYMLINK request 1971 * Encode SYMLINK request
1852 */ 1972 */
1853static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) 1973static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
1974 const struct nfs4_create_arg *args)
1854{ 1975{
1855 return nfs4_xdr_enc_create(req, p, args); 1976 nfs4_xdr_enc_create(req, xdr, args);
1856} 1977}
1857 1978
1858/* 1979/*
1859 * Encode GETATTR request 1980 * Encode GETATTR request
1860 */ 1981 */
1861static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args) 1982static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1983 const struct nfs4_getattr_arg *args)
1862{ 1984{
1863 struct xdr_stream xdr;
1864 struct compound_hdr hdr = { 1985 struct compound_hdr hdr = {
1865 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1866 }; 1987 };
1867 1988
1868 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1989 encode_compound_hdr(xdr, req, &hdr);
1869 encode_compound_hdr(&xdr, req, &hdr); 1990 encode_sequence(xdr, &args->seq_args, &hdr);
1870 encode_sequence(&xdr, &args->seq_args, &hdr); 1991 encode_putfh(xdr, args->fh, &hdr);
1871 encode_putfh(&xdr, args->fh, &hdr); 1992 encode_getfattr(xdr, args->bitmask, &hdr);
1872 encode_getfattr(&xdr, args->bitmask, &hdr);
1873 encode_nops(&hdr); 1993 encode_nops(&hdr);
1874 return 0;
1875} 1994}
1876 1995
1877/* 1996/*
1878 * Encode a CLOSE request 1997 * Encode a CLOSE request
1879 */ 1998 */
1880static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) 1999static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2000 struct nfs_closeargs *args)
1881{ 2001{
1882 struct xdr_stream xdr;
1883 struct compound_hdr hdr = { 2002 struct compound_hdr hdr = {
1884 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2003 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1885 }; 2004 };
1886 2005
1887 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2006 encode_compound_hdr(xdr, req, &hdr);
1888 encode_compound_hdr(&xdr, req, &hdr); 2007 encode_sequence(xdr, &args->seq_args, &hdr);
1889 encode_sequence(&xdr, &args->seq_args, &hdr); 2008 encode_putfh(xdr, args->fh, &hdr);
1890 encode_putfh(&xdr, args->fh, &hdr); 2009 encode_close(xdr, args, &hdr);
1891 encode_close(&xdr, args, &hdr); 2010 encode_getfattr(xdr, args->bitmask, &hdr);
1892 encode_getfattr(&xdr, args->bitmask, &hdr);
1893 encode_nops(&hdr); 2011 encode_nops(&hdr);
1894 return 0;
1895} 2012}
1896 2013
1897/* 2014/*
1898 * Encode an OPEN request 2015 * Encode an OPEN request
1899 */ 2016 */
1900static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) 2017static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2018 struct nfs_openargs *args)
1901{ 2019{
1902 struct xdr_stream xdr;
1903 struct compound_hdr hdr = { 2020 struct compound_hdr hdr = {
1904 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1905 }; 2022 };
1906 2023
1907 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2024 encode_compound_hdr(xdr, req, &hdr);
1908 encode_compound_hdr(&xdr, req, &hdr); 2025 encode_sequence(xdr, &args->seq_args, &hdr);
1909 encode_sequence(&xdr, &args->seq_args, &hdr); 2026 encode_putfh(xdr, args->fh, &hdr);
1910 encode_putfh(&xdr, args->fh, &hdr); 2027 encode_savefh(xdr, &hdr);
1911 encode_savefh(&xdr, &hdr); 2028 encode_open(xdr, args, &hdr);
1912 encode_open(&xdr, args, &hdr); 2029 encode_getfh(xdr, &hdr);
1913 encode_getfh(&xdr, &hdr); 2030 encode_getfattr(xdr, args->bitmask, &hdr);
1914 encode_getfattr(&xdr, args->bitmask, &hdr); 2031 encode_restorefh(xdr, &hdr);
1915 encode_restorefh(&xdr, &hdr); 2032 encode_getfattr(xdr, args->bitmask, &hdr);
1916 encode_getfattr(&xdr, args->bitmask, &hdr);
1917 encode_nops(&hdr); 2033 encode_nops(&hdr);
1918 return 0;
1919} 2034}
1920 2035
1921/* 2036/*
1922 * Encode an OPEN_CONFIRM request 2037 * Encode an OPEN_CONFIRM request
1923 */ 2038 */
1924static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args) 2039static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2040 struct xdr_stream *xdr,
2041 struct nfs_open_confirmargs *args)
1925{ 2042{
1926 struct xdr_stream xdr;
1927 struct compound_hdr hdr = { 2043 struct compound_hdr hdr = {
1928 .nops = 0, 2044 .nops = 0,
1929 }; 2045 };
1930 2046
1931 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2047 encode_compound_hdr(xdr, req, &hdr);
1932 encode_compound_hdr(&xdr, req, &hdr); 2048 encode_putfh(xdr, args->fh, &hdr);
1933 encode_putfh(&xdr, args->fh, &hdr); 2049 encode_open_confirm(xdr, args, &hdr);
1934 encode_open_confirm(&xdr, args, &hdr);
1935 encode_nops(&hdr); 2050 encode_nops(&hdr);
1936 return 0;
1937} 2051}
1938 2052
1939/* 2053/*
1940 * Encode an OPEN request with no attributes. 2054 * Encode an OPEN request with no attributes.
1941 */ 2055 */
1942static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) 2056static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2057 struct xdr_stream *xdr,
2058 struct nfs_openargs *args)
1943{ 2059{
1944 struct xdr_stream xdr;
1945 struct compound_hdr hdr = { 2060 struct compound_hdr hdr = {
1946 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1947 }; 2062 };
1948 2063
1949 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2064 encode_compound_hdr(xdr, req, &hdr);
1950 encode_compound_hdr(&xdr, req, &hdr); 2065 encode_sequence(xdr, &args->seq_args, &hdr);
1951 encode_sequence(&xdr, &args->seq_args, &hdr); 2066 encode_putfh(xdr, args->fh, &hdr);
1952 encode_putfh(&xdr, args->fh, &hdr); 2067 encode_open(xdr, args, &hdr);
1953 encode_open(&xdr, args, &hdr); 2068 encode_getfattr(xdr, args->bitmask, &hdr);
1954 encode_getfattr(&xdr, args->bitmask, &hdr);
1955 encode_nops(&hdr); 2069 encode_nops(&hdr);
1956 return 0;
1957} 2070}
1958 2071
1959/* 2072/*
1960 * Encode an OPEN_DOWNGRADE request 2073 * Encode an OPEN_DOWNGRADE request
1961 */ 2074 */
1962static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) 2075static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2076 struct xdr_stream *xdr,
2077 struct nfs_closeargs *args)
1963{ 2078{
1964 struct xdr_stream xdr;
1965 struct compound_hdr hdr = { 2079 struct compound_hdr hdr = {
1966 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1967 }; 2081 };
1968 2082
1969 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2083 encode_compound_hdr(xdr, req, &hdr);
1970 encode_compound_hdr(&xdr, req, &hdr); 2084 encode_sequence(xdr, &args->seq_args, &hdr);
1971 encode_sequence(&xdr, &args->seq_args, &hdr); 2085 encode_putfh(xdr, args->fh, &hdr);
1972 encode_putfh(&xdr, args->fh, &hdr); 2086 encode_open_downgrade(xdr, args, &hdr);
1973 encode_open_downgrade(&xdr, args, &hdr); 2087 encode_getfattr(xdr, args->bitmask, &hdr);
1974 encode_getfattr(&xdr, args->bitmask, &hdr);
1975 encode_nops(&hdr); 2088 encode_nops(&hdr);
1976 return 0;
1977} 2089}
1978 2090
1979/* 2091/*
1980 * Encode a LOCK request 2092 * Encode a LOCK request
1981 */ 2093 */
1982static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args) 2094static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 struct nfs_lock_args *args)
1983{ 2096{
1984 struct xdr_stream xdr;
1985 struct compound_hdr hdr = { 2097 struct compound_hdr hdr = {
1986 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1987 }; 2099 };
1988 2100
1989 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2101 encode_compound_hdr(xdr, req, &hdr);
1990 encode_compound_hdr(&xdr, req, &hdr); 2102 encode_sequence(xdr, &args->seq_args, &hdr);
1991 encode_sequence(&xdr, &args->seq_args, &hdr); 2103 encode_putfh(xdr, args->fh, &hdr);
1992 encode_putfh(&xdr, args->fh, &hdr); 2104 encode_lock(xdr, args, &hdr);
1993 encode_lock(&xdr, args, &hdr);
1994 encode_nops(&hdr); 2105 encode_nops(&hdr);
1995 return 0;
1996} 2106}
1997 2107
1998/* 2108/*
1999 * Encode a LOCKT request 2109 * Encode a LOCKT request
2000 */ 2110 */
2001static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args) 2111static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 struct nfs_lockt_args *args)
2002{ 2113{
2003 struct xdr_stream xdr;
2004 struct compound_hdr hdr = { 2114 struct compound_hdr hdr = {
2005 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2006 }; 2116 };
2007 2117
2008 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2118 encode_compound_hdr(xdr, req, &hdr);
2009 encode_compound_hdr(&xdr, req, &hdr); 2119 encode_sequence(xdr, &args->seq_args, &hdr);
2010 encode_sequence(&xdr, &args->seq_args, &hdr); 2120 encode_putfh(xdr, args->fh, &hdr);
2011 encode_putfh(&xdr, args->fh, &hdr); 2121 encode_lockt(xdr, args, &hdr);
2012 encode_lockt(&xdr, args, &hdr);
2013 encode_nops(&hdr); 2122 encode_nops(&hdr);
2014 return 0;
2015} 2123}
2016 2124
2017/* 2125/*
2018 * Encode a LOCKU request 2126 * Encode a LOCKU request
2019 */ 2127 */
2020static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args) 2128static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2129 struct nfs_locku_args *args)
2021{ 2130{
2022 struct xdr_stream xdr;
2023 struct compound_hdr hdr = { 2131 struct compound_hdr hdr = {
2024 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2025 }; 2133 };
2026 2134
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2135 encode_compound_hdr(xdr, req, &hdr);
2028 encode_compound_hdr(&xdr, req, &hdr); 2136 encode_sequence(xdr, &args->seq_args, &hdr);
2029 encode_sequence(&xdr, &args->seq_args, &hdr); 2137 encode_putfh(xdr, args->fh, &hdr);
2030 encode_putfh(&xdr, args->fh, &hdr); 2138 encode_locku(xdr, args, &hdr);
2031 encode_locku(&xdr, args, &hdr); 2139 encode_nops(&hdr);
2140}
2141
2142static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2143 struct xdr_stream *xdr,
2144 struct nfs_release_lockowner_args *args)
2145{
2146 struct compound_hdr hdr = {
2147 .minorversion = 0,
2148 };
2149
2150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2032 encode_nops(&hdr); 2152 encode_nops(&hdr);
2033 return 0;
2034} 2153}
2035 2154
2036/* 2155/*
2037 * Encode a READLINK request 2156 * Encode a READLINK request
2038 */ 2157 */
2039static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args) 2158static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs4_readlink *args)
2040{ 2160{
2041 struct xdr_stream xdr;
2042 struct compound_hdr hdr = { 2161 struct compound_hdr hdr = {
2043 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2044 }; 2163 };
2045 2164
2046 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2165 encode_compound_hdr(xdr, req, &hdr);
2047 encode_compound_hdr(&xdr, req, &hdr); 2166 encode_sequence(xdr, &args->seq_args, &hdr);
2048 encode_sequence(&xdr, &args->seq_args, &hdr); 2167 encode_putfh(xdr, args->fh, &hdr);
2049 encode_putfh(&xdr, args->fh, &hdr); 2168 encode_readlink(xdr, args, req, &hdr);
2050 encode_readlink(&xdr, args, req, &hdr);
2051 2169
2052 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2170 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2053 args->pgbase, args->pglen); 2171 args->pgbase, args->pglen);
2054 encode_nops(&hdr); 2172 encode_nops(&hdr);
2055 return 0;
2056} 2173}
2057 2174
2058/* 2175/*
2059 * Encode a READDIR request 2176 * Encode a READDIR request
2060 */ 2177 */
2061static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args) 2178static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs4_readdir_arg *args)
2062{ 2180{
2063 struct xdr_stream xdr;
2064 struct compound_hdr hdr = { 2181 struct compound_hdr hdr = {
2065 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2066 }; 2183 };
2067 2184
2068 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2185 encode_compound_hdr(xdr, req, &hdr);
2069 encode_compound_hdr(&xdr, req, &hdr); 2186 encode_sequence(xdr, &args->seq_args, &hdr);
2070 encode_sequence(&xdr, &args->seq_args, &hdr); 2187 encode_putfh(xdr, args->fh, &hdr);
2071 encode_putfh(&xdr, args->fh, &hdr); 2188 encode_readdir(xdr, args, req, &hdr);
2072 encode_readdir(&xdr, args, req, &hdr);
2073 2189
2074 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2190 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2075 args->pgbase, args->count); 2191 args->pgbase, args->count);
@@ -2077,457 +2193,463 @@ static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nf
2077 __func__, hdr.replen << 2, args->pages, 2193 __func__, hdr.replen << 2, args->pages,
2078 args->pgbase, args->count); 2194 args->pgbase, args->count);
2079 encode_nops(&hdr); 2195 encode_nops(&hdr);
2080 return 0;
2081} 2196}
2082 2197
2083/* 2198/*
2084 * Encode a READ request 2199 * Encode a READ request
2085 */ 2200 */
2086static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) 2201static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2202 struct nfs_readargs *args)
2087{ 2203{
2088 struct xdr_stream xdr;
2089 struct compound_hdr hdr = { 2204 struct compound_hdr hdr = {
2090 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2205 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2091 }; 2206 };
2092 2207
2093 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2208 encode_compound_hdr(xdr, req, &hdr);
2094 encode_compound_hdr(&xdr, req, &hdr); 2209 encode_sequence(xdr, &args->seq_args, &hdr);
2095 encode_sequence(&xdr, &args->seq_args, &hdr); 2210 encode_putfh(xdr, args->fh, &hdr);
2096 encode_putfh(&xdr, args->fh, &hdr); 2211 encode_read(xdr, args, &hdr);
2097 encode_read(&xdr, args, &hdr);
2098 2212
2099 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 2213 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2100 args->pages, args->pgbase, args->count); 2214 args->pages, args->pgbase, args->count);
2101 req->rq_rcv_buf.flags |= XDRBUF_READ; 2215 req->rq_rcv_buf.flags |= XDRBUF_READ;
2102 encode_nops(&hdr); 2216 encode_nops(&hdr);
2103 return 0;
2104} 2217}
2105 2218
2106/* 2219/*
2107 * Encode an SETATTR request 2220 * Encode an SETATTR request
2108 */ 2221 */
2109static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args) 2222static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2223 struct nfs_setattrargs *args)
2110{ 2224{
2111 struct xdr_stream xdr;
2112 struct compound_hdr hdr = { 2225 struct compound_hdr hdr = {
2113 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2114 }; 2227 };
2115 2228
2116 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2229 encode_compound_hdr(xdr, req, &hdr);
2117 encode_compound_hdr(&xdr, req, &hdr); 2230 encode_sequence(xdr, &args->seq_args, &hdr);
2118 encode_sequence(&xdr, &args->seq_args, &hdr); 2231 encode_putfh(xdr, args->fh, &hdr);
2119 encode_putfh(&xdr, args->fh, &hdr); 2232 encode_setattr(xdr, args, args->server, &hdr);
2120 encode_setattr(&xdr, args, args->server, &hdr); 2233 encode_getfattr(xdr, args->bitmask, &hdr);
2121 encode_getfattr(&xdr, args->bitmask, &hdr);
2122 encode_nops(&hdr); 2234 encode_nops(&hdr);
2123 return 0;
2124} 2235}
2125 2236
2126/* 2237/*
2127 * Encode a GETACL request 2238 * Encode a GETACL request
2128 */ 2239 */
2129static int 2240static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2130nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p, 2241 struct nfs_getaclargs *args)
2131 struct nfs_getaclargs *args)
2132{ 2242{
2133 struct xdr_stream xdr;
2134 struct compound_hdr hdr = { 2243 struct compound_hdr hdr = {
2135 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2136 }; 2245 };
2137 uint32_t replen; 2246 uint32_t replen;
2138 2247
2139 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2248 encode_compound_hdr(xdr, req, &hdr);
2140 encode_compound_hdr(&xdr, req, &hdr); 2249 encode_sequence(xdr, &args->seq_args, &hdr);
2141 encode_sequence(&xdr, &args->seq_args, &hdr); 2250 encode_putfh(xdr, args->fh, &hdr);
2142 encode_putfh(&xdr, args->fh, &hdr); 2251 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2143 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1; 2252 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2144 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2145 2253
2146 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2254 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2147 args->acl_pages, args->acl_pgbase, args->acl_len); 2255 args->acl_pages, args->acl_pgbase, args->acl_len);
2148 encode_nops(&hdr); 2256 encode_nops(&hdr);
2149 return 0;
2150} 2257}
2151 2258
2152/* 2259/*
2153 * Encode a WRITE request 2260 * Encode a WRITE request
2154 */ 2261 */
2155static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 2262static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2263 struct nfs_writeargs *args)
2156{ 2264{
2157 struct xdr_stream xdr;
2158 struct compound_hdr hdr = { 2265 struct compound_hdr hdr = {
2159 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2266 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2160 }; 2267 };
2161 2268
2162 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2269 encode_compound_hdr(xdr, req, &hdr);
2163 encode_compound_hdr(&xdr, req, &hdr); 2270 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_sequence(&xdr, &args->seq_args, &hdr); 2271 encode_putfh(xdr, args->fh, &hdr);
2165 encode_putfh(&xdr, args->fh, &hdr); 2272 encode_write(xdr, args, &hdr);
2166 encode_write(&xdr, args, &hdr);
2167 req->rq_snd_buf.flags |= XDRBUF_WRITE; 2273 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2168 encode_getfattr(&xdr, args->bitmask, &hdr); 2274 encode_getfattr(xdr, args->bitmask, &hdr);
2169 encode_nops(&hdr); 2275 encode_nops(&hdr);
2170 return 0;
2171} 2276}
2172 2277
2173/* 2278/*
2174 * a COMMIT request 2279 * a COMMIT request
2175 */ 2280 */
2176static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 2281static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2282 struct nfs_writeargs *args)
2177{ 2283{
2178 struct xdr_stream xdr;
2179 struct compound_hdr hdr = { 2284 struct compound_hdr hdr = {
2180 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2181 }; 2286 };
2182 2287
2183 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2288 encode_compound_hdr(xdr, req, &hdr);
2184 encode_compound_hdr(&xdr, req, &hdr); 2289 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_sequence(&xdr, &args->seq_args, &hdr); 2290 encode_putfh(xdr, args->fh, &hdr);
2186 encode_putfh(&xdr, args->fh, &hdr); 2291 encode_commit(xdr, args, &hdr);
2187 encode_commit(&xdr, args, &hdr); 2292 encode_getfattr(xdr, args->bitmask, &hdr);
2188 encode_getfattr(&xdr, args->bitmask, &hdr);
2189 encode_nops(&hdr); 2293 encode_nops(&hdr);
2190 return 0;
2191} 2294}
2192 2295
2193/* 2296/*
2194 * FSINFO request 2297 * FSINFO request
2195 */ 2298 */
2196static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args) 2299static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2300 struct nfs4_fsinfo_arg *args)
2197{ 2301{
2198 struct xdr_stream xdr;
2199 struct compound_hdr hdr = { 2302 struct compound_hdr hdr = {
2200 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2303 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2201 }; 2304 };
2202 2305
2203 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2306 encode_compound_hdr(xdr, req, &hdr);
2204 encode_compound_hdr(&xdr, req, &hdr); 2307 encode_sequence(xdr, &args->seq_args, &hdr);
2205 encode_sequence(&xdr, &args->seq_args, &hdr); 2308 encode_putfh(xdr, args->fh, &hdr);
2206 encode_putfh(&xdr, args->fh, &hdr); 2309 encode_fsinfo(xdr, args->bitmask, &hdr);
2207 encode_fsinfo(&xdr, args->bitmask, &hdr);
2208 encode_nops(&hdr); 2310 encode_nops(&hdr);
2209 return 0;
2210} 2311}
2211 2312
2212/* 2313/*
2213 * a PATHCONF request 2314 * a PATHCONF request
2214 */ 2315 */
2215static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args) 2316static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2317 const struct nfs4_pathconf_arg *args)
2216{ 2318{
2217 struct xdr_stream xdr;
2218 struct compound_hdr hdr = { 2319 struct compound_hdr hdr = {
2219 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2220 }; 2321 };
2221 2322
2222 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2323 encode_compound_hdr(xdr, req, &hdr);
2223 encode_compound_hdr(&xdr, req, &hdr); 2324 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_sequence(&xdr, &args->seq_args, &hdr); 2325 encode_putfh(xdr, args->fh, &hdr);
2225 encode_putfh(&xdr, args->fh, &hdr); 2326 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2226 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2227 &hdr); 2327 &hdr);
2228 encode_nops(&hdr); 2328 encode_nops(&hdr);
2229 return 0;
2230} 2329}
2231 2330
2232/* 2331/*
2233 * a STATFS request 2332 * a STATFS request
2234 */ 2333 */
2235static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args) 2334static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2335 const struct nfs4_statfs_arg *args)
2236{ 2336{
2237 struct xdr_stream xdr;
2238 struct compound_hdr hdr = { 2337 struct compound_hdr hdr = {
2239 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2338 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2240 }; 2339 };
2241 2340
2242 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2341 encode_compound_hdr(xdr, req, &hdr);
2243 encode_compound_hdr(&xdr, req, &hdr); 2342 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_sequence(&xdr, &args->seq_args, &hdr); 2343 encode_putfh(xdr, args->fh, &hdr);
2245 encode_putfh(&xdr, args->fh, &hdr); 2344 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2246 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2247 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2345 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2248 encode_nops(&hdr); 2346 encode_nops(&hdr);
2249 return 0;
2250} 2347}
2251 2348
2252/* 2349/*
2253 * GETATTR_BITMAP request 2350 * GETATTR_BITMAP request
2254 */ 2351 */
2255static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, 2352static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2256 struct nfs4_server_caps_arg *args) 2353 struct xdr_stream *xdr,
2354 struct nfs4_server_caps_arg *args)
2257{ 2355{
2258 struct xdr_stream xdr;
2259 struct compound_hdr hdr = { 2356 struct compound_hdr hdr = {
2260 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2261 }; 2358 };
2262 2359
2263 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2360 encode_compound_hdr(xdr, req, &hdr);
2264 encode_compound_hdr(&xdr, req, &hdr); 2361 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_sequence(&xdr, &args->seq_args, &hdr); 2362 encode_putfh(xdr, args->fhandle, &hdr);
2266 encode_putfh(&xdr, args->fhandle, &hdr); 2363 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2267 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2268 FATTR4_WORD0_LINK_SUPPORT| 2364 FATTR4_WORD0_LINK_SUPPORT|
2269 FATTR4_WORD0_SYMLINK_SUPPORT| 2365 FATTR4_WORD0_SYMLINK_SUPPORT|
2270 FATTR4_WORD0_ACLSUPPORT, &hdr); 2366 FATTR4_WORD0_ACLSUPPORT, &hdr);
2271 encode_nops(&hdr); 2367 encode_nops(&hdr);
2272 return 0;
2273} 2368}
2274 2369
2275/* 2370/*
2276 * a RENEW request 2371 * a RENEW request
2277 */ 2372 */
2278static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) 2373static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2374 struct nfs_client *clp)
2279{ 2375{
2280 struct xdr_stream xdr;
2281 struct compound_hdr hdr = { 2376 struct compound_hdr hdr = {
2282 .nops = 0, 2377 .nops = 0,
2283 }; 2378 };
2284 2379
2285 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2380 encode_compound_hdr(xdr, req, &hdr);
2286 encode_compound_hdr(&xdr, req, &hdr); 2381 encode_renew(xdr, clp, &hdr);
2287 encode_renew(&xdr, clp, &hdr);
2288 encode_nops(&hdr); 2382 encode_nops(&hdr);
2289 return 0;
2290} 2383}
2291 2384
2292/* 2385/*
2293 * a SETCLIENTID request 2386 * a SETCLIENTID request
2294 */ 2387 */
2295static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc) 2388static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2389 struct xdr_stream *xdr,
2390 struct nfs4_setclientid *sc)
2296{ 2391{
2297 struct xdr_stream xdr;
2298 struct compound_hdr hdr = { 2392 struct compound_hdr hdr = {
2299 .nops = 0, 2393 .nops = 0,
2300 }; 2394 };
2301 2395
2302 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2396 encode_compound_hdr(xdr, req, &hdr);
2303 encode_compound_hdr(&xdr, req, &hdr); 2397 encode_setclientid(xdr, sc, &hdr);
2304 encode_setclientid(&xdr, sc, &hdr);
2305 encode_nops(&hdr); 2398 encode_nops(&hdr);
2306 return 0;
2307} 2399}
2308 2400
2309/* 2401/*
2310 * a SETCLIENTID_CONFIRM request 2402 * a SETCLIENTID_CONFIRM request
2311 */ 2403 */
2312static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) 2404static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2405 struct xdr_stream *xdr,
2406 struct nfs4_setclientid_res *arg)
2313{ 2407{
2314 struct xdr_stream xdr;
2315 struct compound_hdr hdr = { 2408 struct compound_hdr hdr = {
2316 .nops = 0, 2409 .nops = 0,
2317 }; 2410 };
2318 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; 2411 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2319 2412
2320 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2413 encode_compound_hdr(xdr, req, &hdr);
2321 encode_compound_hdr(&xdr, req, &hdr); 2414 encode_setclientid_confirm(xdr, arg, &hdr);
2322 encode_setclientid_confirm(&xdr, clp, &hdr); 2415 encode_putrootfh(xdr, &hdr);
2323 encode_putrootfh(&xdr, &hdr); 2416 encode_fsinfo(xdr, lease_bitmap, &hdr);
2324 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2325 encode_nops(&hdr); 2417 encode_nops(&hdr);
2326 return 0;
2327} 2418}
2328 2419
2329/* 2420/*
2330 * DELEGRETURN request 2421 * DELEGRETURN request
2331 */ 2422 */
2332static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args) 2423static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2424 struct xdr_stream *xdr,
2425 const struct nfs4_delegreturnargs *args)
2333{ 2426{
2334 struct xdr_stream xdr;
2335 struct compound_hdr hdr = { 2427 struct compound_hdr hdr = {
2336 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2428 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2337 }; 2429 };
2338 2430
2339 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2431 encode_compound_hdr(xdr, req, &hdr);
2340 encode_compound_hdr(&xdr, req, &hdr); 2432 encode_sequence(xdr, &args->seq_args, &hdr);
2341 encode_sequence(&xdr, &args->seq_args, &hdr); 2433 encode_putfh(xdr, args->fhandle, &hdr);
2342 encode_putfh(&xdr, args->fhandle, &hdr); 2434 encode_delegreturn(xdr, args->stateid, &hdr);
2343 encode_delegreturn(&xdr, args->stateid, &hdr); 2435 encode_getfattr(xdr, args->bitmask, &hdr);
2344 encode_getfattr(&xdr, args->bitmask, &hdr);
2345 encode_nops(&hdr); 2436 encode_nops(&hdr);
2346 return 0;
2347} 2437}
2348 2438
2349/* 2439/*
2350 * Encode FS_LOCATIONS request 2440 * Encode FS_LOCATIONS request
2351 */ 2441 */
2352static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args) 2442static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2443 struct xdr_stream *xdr,
2444 struct nfs4_fs_locations_arg *args)
2353{ 2445{
2354 struct xdr_stream xdr;
2355 struct compound_hdr hdr = { 2446 struct compound_hdr hdr = {
2356 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2447 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2357 }; 2448 };
2358 uint32_t replen; 2449 uint32_t replen;
2359 2450
2360 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2451 encode_compound_hdr(xdr, req, &hdr);
2361 encode_compound_hdr(&xdr, req, &hdr); 2452 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_sequence(&xdr, &args->seq_args, &hdr); 2453 encode_putfh(xdr, args->dir_fh, &hdr);
2363 encode_putfh(&xdr, args->dir_fh, &hdr); 2454 encode_lookup(xdr, args->name, &hdr);
2364 encode_lookup(&xdr, args->name, &hdr);
2365 replen = hdr.replen; /* get the attribute into args->page */ 2455 replen = hdr.replen; /* get the attribute into args->page */
2366 encode_fs_locations(&xdr, args->bitmask, &hdr); 2456 encode_fs_locations(xdr, args->bitmask, &hdr);
2367 2457
2368 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2458 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2369 0, PAGE_SIZE); 2459 0, PAGE_SIZE);
2370 encode_nops(&hdr); 2460 encode_nops(&hdr);
2371 return 0;
2372} 2461}
2373 2462
2374#if defined(CONFIG_NFS_V4_1) 2463#if defined(CONFIG_NFS_V4_1)
2375/* 2464/*
2376 * EXCHANGE_ID request 2465 * EXCHANGE_ID request
2377 */ 2466 */
2378static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p, 2467static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2379 struct nfs41_exchange_id_args *args) 2468 struct xdr_stream *xdr,
2469 struct nfs41_exchange_id_args *args)
2380{ 2470{
2381 struct xdr_stream xdr;
2382 struct compound_hdr hdr = { 2471 struct compound_hdr hdr = {
2383 .minorversion = args->client->cl_minorversion, 2472 .minorversion = args->client->cl_mvops->minor_version,
2384 }; 2473 };
2385 2474
2386 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2475 encode_compound_hdr(xdr, req, &hdr);
2387 encode_compound_hdr(&xdr, req, &hdr); 2476 encode_exchange_id(xdr, args, &hdr);
2388 encode_exchange_id(&xdr, args, &hdr);
2389 encode_nops(&hdr); 2477 encode_nops(&hdr);
2390 return 0;
2391} 2478}
2392 2479
2393/* 2480/*
2394 * a CREATE_SESSION request 2481 * a CREATE_SESSION request
2395 */ 2482 */
2396static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p, 2483static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2397 struct nfs41_create_session_args *args) 2484 struct xdr_stream *xdr,
2485 struct nfs41_create_session_args *args)
2398{ 2486{
2399 struct xdr_stream xdr;
2400 struct compound_hdr hdr = { 2487 struct compound_hdr hdr = {
2401 .minorversion = args->client->cl_minorversion, 2488 .minorversion = args->client->cl_mvops->minor_version,
2402 }; 2489 };
2403 2490
2404 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2491 encode_compound_hdr(xdr, req, &hdr);
2405 encode_compound_hdr(&xdr, req, &hdr); 2492 encode_create_session(xdr, args, &hdr);
2406 encode_create_session(&xdr, args, &hdr);
2407 encode_nops(&hdr); 2493 encode_nops(&hdr);
2408 return 0;
2409} 2494}
2410 2495
2411/* 2496/*
2412 * a DESTROY_SESSION request 2497 * a DESTROY_SESSION request
2413 */ 2498 */
2414static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p, 2499static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2415 struct nfs4_session *session) 2500 struct xdr_stream *xdr,
2501 struct nfs4_session *session)
2416{ 2502{
2417 struct xdr_stream xdr;
2418 struct compound_hdr hdr = { 2503 struct compound_hdr hdr = {
2419 .minorversion = session->clp->cl_minorversion, 2504 .minorversion = session->clp->cl_mvops->minor_version,
2420 }; 2505 };
2421 2506
2422 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2507 encode_compound_hdr(xdr, req, &hdr);
2423 encode_compound_hdr(&xdr, req, &hdr); 2508 encode_destroy_session(xdr, session, &hdr);
2424 encode_destroy_session(&xdr, session, &hdr);
2425 encode_nops(&hdr); 2509 encode_nops(&hdr);
2426 return 0;
2427} 2510}
2428 2511
2429/* 2512/*
2430 * a SEQUENCE request 2513 * a SEQUENCE request
2431 */ 2514 */
2432static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p, 2515static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2433 struct nfs4_sequence_args *args) 2516 struct nfs4_sequence_args *args)
2434{ 2517{
2435 struct xdr_stream xdr;
2436 struct compound_hdr hdr = { 2518 struct compound_hdr hdr = {
2437 .minorversion = nfs4_xdr_minorversion(args), 2519 .minorversion = nfs4_xdr_minorversion(args),
2438 }; 2520 };
2439 2521
2440 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2522 encode_compound_hdr(xdr, req, &hdr);
2441 encode_compound_hdr(&xdr, req, &hdr); 2523 encode_sequence(xdr, args, &hdr);
2442 encode_sequence(&xdr, args, &hdr);
2443 encode_nops(&hdr); 2524 encode_nops(&hdr);
2444 return 0;
2445} 2525}
2446 2526
2447/* 2527/*
2448 * a GET_LEASE_TIME request 2528 * a GET_LEASE_TIME request
2449 */ 2529 */
2450static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p, 2530static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2451 struct nfs4_get_lease_time_args *args) 2531 struct xdr_stream *xdr,
2532 struct nfs4_get_lease_time_args *args)
2452{ 2533{
2453 struct xdr_stream xdr;
2454 struct compound_hdr hdr = { 2534 struct compound_hdr hdr = {
2455 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 2535 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2456 }; 2536 };
2457 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; 2537 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2458 2538
2459 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2539 encode_compound_hdr(xdr, req, &hdr);
2460 encode_compound_hdr(&xdr, req, &hdr); 2540 encode_sequence(xdr, &args->la_seq_args, &hdr);
2461 encode_sequence(&xdr, &args->la_seq_args, &hdr); 2541 encode_putrootfh(xdr, &hdr);
2462 encode_putrootfh(&xdr, &hdr); 2542 encode_fsinfo(xdr, lease_bitmap, &hdr);
2463 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2464 encode_nops(&hdr); 2543 encode_nops(&hdr);
2465 return 0;
2466} 2544}
2467#endif /* CONFIG_NFS_V4_1 */
2468 2545
2469/* 2546/*
2470 * START OF "GENERIC" DECODE ROUTINES. 2547 * a RECLAIM_COMPLETE request
2471 * These may look a little ugly since they are imported from a "generic" 2548 */
2472 * set of XDR encode/decode routines which are intended to be shared by 2549static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2473 * all of our NFSv4 implementations (OpenBSD, MacOS X...). 2550 struct xdr_stream *xdr,
2474 * 2551 struct nfs41_reclaim_complete_args *args)
2475 * If the pain of reading these is too great, it should be a straightforward 2552{
2476 * task to translate them into Linux-specific versions which are more 2553 struct compound_hdr hdr = {
2477 * consistent with the style used in NFSv2/v3... 2554 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2555 };
2556
2557 encode_compound_hdr(xdr, req, &hdr);
2558 encode_sequence(xdr, &args->seq_args, &hdr);
2559 encode_reclaim_complete(xdr, args, &hdr);
2560 encode_nops(&hdr);
2561}
2562
2563/*
2564 * Encode GETDEVICEINFO request
2565 */
2566static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2567 struct xdr_stream *xdr,
2568 struct nfs4_getdeviceinfo_args *args)
2569{
2570 struct compound_hdr hdr = {
2571 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2572 };
2573
2574 encode_compound_hdr(xdr, req, &hdr);
2575 encode_sequence(xdr, &args->seq_args, &hdr);
2576 encode_getdeviceinfo(xdr, args, &hdr);
2577
2578 /* set up reply kvec. Subtract notification bitmap max size (2)
2579 * so that notification bitmap is put in xdr_buf tail */
2580 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2581 args->pdev->pages, args->pdev->pgbase,
2582 args->pdev->pglen);
2583
2584 encode_nops(&hdr);
2585}
2586
2587/*
2588 * Encode LAYOUTGET request
2478 */ 2589 */
2479#define READ32(x) (x) = ntohl(*p++) 2590static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2480#define READ64(x) do { \ 2591 struct xdr_stream *xdr,
2481 (x) = (u64)ntohl(*p++) << 32; \ 2592 struct nfs4_layoutget_args *args)
2482 (x) |= ntohl(*p++); \ 2593{
2483} while (0) 2594 struct compound_hdr hdr = {
2484#define READTIME(x) do { \ 2595 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2485 p++; \ 2596 };
2486 (x.tv_sec) = ntohl(*p++); \ 2597
2487 (x.tv_nsec) = ntohl(*p++); \ 2598 encode_compound_hdr(xdr, req, &hdr);
2488} while (0) 2599 encode_sequence(xdr, &args->seq_args, &hdr);
2489#define COPYMEM(x,nbytes) do { \ 2600 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2490 memcpy((x), p, nbytes); \ 2601 encode_layoutget(xdr, args, &hdr);
2491 p += XDR_QUADLEN(nbytes); \ 2602 encode_nops(&hdr);
2492} while (0) 2603}
2493 2604#endif /* CONFIG_NFS_V4_1 */
2494#define READ_BUF(nbytes) do { \ 2605
2495 p = xdr_inline_decode(xdr, nbytes); \ 2606static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2496 if (unlikely(!p)) { \ 2607{
2497 dprintk("nfs: %s: prematurely hit end of receive" \ 2608 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2498 " buffer\n", __func__); \ 2609 "Remaining buffer length is %tu words.\n",
2499 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \ 2610 func, xdr->end - xdr->p);
2500 __func__, xdr->p, nbytes, xdr->end); \ 2611}
2501 return -EIO; \
2502 } \
2503} while (0)
2504 2612
2505static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 2613static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2506{ 2614{
2507 __be32 *p; 2615 __be32 *p;
2508 2616
2509 READ_BUF(4); 2617 p = xdr_inline_decode(xdr, 4);
2510 READ32(*len); 2618 if (unlikely(!p))
2511 READ_BUF(*len); 2619 goto out_overflow;
2620 *len = be32_to_cpup(p);
2621 p = xdr_inline_decode(xdr, *len);
2622 if (unlikely(!p))
2623 goto out_overflow;
2512 *string = (char *)p; 2624 *string = (char *)p;
2513 return 0; 2625 return 0;
2626out_overflow:
2627 print_overflow_msg(__func__, xdr);
2628 return -EIO;
2514} 2629}
2515 2630
2516static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 2631static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2517{ 2632{
2518 __be32 *p; 2633 __be32 *p;
2519 2634
2520 READ_BUF(8); 2635 p = xdr_inline_decode(xdr, 8);
2521 READ32(hdr->status); 2636 if (unlikely(!p))
2522 READ32(hdr->taglen); 2637 goto out_overflow;
2638 hdr->status = be32_to_cpup(p++);
2639 hdr->taglen = be32_to_cpup(p);
2523 2640
2524 READ_BUF(hdr->taglen + 4); 2641 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2642 if (unlikely(!p))
2643 goto out_overflow;
2525 hdr->tag = (char *)p; 2644 hdr->tag = (char *)p;
2526 p += XDR_QUADLEN(hdr->taglen); 2645 p += XDR_QUADLEN(hdr->taglen);
2527 READ32(hdr->nops); 2646 hdr->nops = be32_to_cpup(p);
2528 if (unlikely(hdr->nops < 1)) 2647 if (unlikely(hdr->nops < 1))
2529 return nfs4_stat_to_errno(hdr->status); 2648 return nfs4_stat_to_errno(hdr->status);
2530 return 0; 2649 return 0;
2650out_overflow:
2651 print_overflow_msg(__func__, xdr);
2652 return -EIO;
2531} 2653}
2532 2654
2533static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 2655static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
@@ -2536,18 +2658,23 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2536 uint32_t opnum; 2658 uint32_t opnum;
2537 int32_t nfserr; 2659 int32_t nfserr;
2538 2660
2539 READ_BUF(8); 2661 p = xdr_inline_decode(xdr, 8);
2540 READ32(opnum); 2662 if (unlikely(!p))
2663 goto out_overflow;
2664 opnum = be32_to_cpup(p++);
2541 if (opnum != expected) { 2665 if (opnum != expected) {
2542 dprintk("nfs: Server returned operation" 2666 dprintk("nfs: Server returned operation"
2543 " %d but we issued a request for %d\n", 2667 " %d but we issued a request for %d\n",
2544 opnum, expected); 2668 opnum, expected);
2545 return -EIO; 2669 return -EIO;
2546 } 2670 }
2547 READ32(nfserr); 2671 nfserr = be32_to_cpup(p);
2548 if (nfserr != NFS_OK) 2672 if (nfserr != NFS_OK)
2549 return nfs4_stat_to_errno(nfserr); 2673 return nfs4_stat_to_errno(nfserr);
2550 return 0; 2674 return 0;
2675out_overflow:
2676 print_overflow_msg(__func__, xdr);
2677 return -EIO;
2551} 2678}
2552 2679
2553/* Dummy routine */ 2680/* Dummy routine */
@@ -2557,8 +2684,11 @@ static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2557 unsigned int strlen; 2684 unsigned int strlen;
2558 char *str; 2685 char *str;
2559 2686
2560 READ_BUF(12); 2687 p = xdr_inline_decode(xdr, 12);
2561 return decode_opaque_inline(xdr, &strlen, &str); 2688 if (likely(p))
2689 return decode_opaque_inline(xdr, &strlen, &str);
2690 print_overflow_msg(__func__, xdr);
2691 return -EIO;
2562} 2692}
2563 2693
2564static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 2694static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
@@ -2566,33 +2696,48 @@ static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2566 uint32_t bmlen; 2696 uint32_t bmlen;
2567 __be32 *p; 2697 __be32 *p;
2568 2698
2569 READ_BUF(4); 2699 p = xdr_inline_decode(xdr, 4);
2570 READ32(bmlen); 2700 if (unlikely(!p))
2701 goto out_overflow;
2702 bmlen = be32_to_cpup(p);
2571 2703
2572 bitmap[0] = bitmap[1] = 0; 2704 bitmap[0] = bitmap[1] = 0;
2573 READ_BUF((bmlen << 2)); 2705 p = xdr_inline_decode(xdr, (bmlen << 2));
2706 if (unlikely(!p))
2707 goto out_overflow;
2574 if (bmlen > 0) { 2708 if (bmlen > 0) {
2575 READ32(bitmap[0]); 2709 bitmap[0] = be32_to_cpup(p++);
2576 if (bmlen > 1) 2710 if (bmlen > 1)
2577 READ32(bitmap[1]); 2711 bitmap[1] = be32_to_cpup(p);
2578 } 2712 }
2579 return 0; 2713 return 0;
2714out_overflow:
2715 print_overflow_msg(__func__, xdr);
2716 return -EIO;
2580} 2717}
2581 2718
2582static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 2719static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2583{ 2720{
2584 __be32 *p; 2721 __be32 *p;
2585 2722
2586 READ_BUF(4); 2723 p = xdr_inline_decode(xdr, 4);
2587 READ32(*attrlen); 2724 if (unlikely(!p))
2725 goto out_overflow;
2726 *attrlen = be32_to_cpup(p);
2588 *savep = xdr->p; 2727 *savep = xdr->p;
2589 return 0; 2728 return 0;
2729out_overflow:
2730 print_overflow_msg(__func__, xdr);
2731 return -EIO;
2590} 2732}
2591 2733
2592static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 2734static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2593{ 2735{
2594 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 2736 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2595 decode_attr_bitmap(xdr, bitmask); 2737 int ret;
2738 ret = decode_attr_bitmap(xdr, bitmask);
2739 if (unlikely(ret < 0))
2740 return ret;
2596 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 2741 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2597 } else 2742 } else
2598 bitmask[0] = bitmask[1] = 0; 2743 bitmask[0] = bitmask[1] = 0;
@@ -2609,8 +2754,10 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
2609 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2610 return -EIO; 2755 return -EIO;
2611 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 2756 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2612 READ_BUF(4); 2757 p = xdr_inline_decode(xdr, 4);
2613 READ32(*type); 2758 if (unlikely(!p))
2759 goto out_overflow;
2760 *type = be32_to_cpup(p);
2614 if (*type < NF4REG || *type > NF4NAMEDATTR) { 2761 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2615 dprintk("%s: bad type %d\n", __func__, *type); 2762 dprintk("%s: bad type %d\n", __func__, *type);
2616 return -EIO; 2763 return -EIO;
@@ -2620,6 +2767,9 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
2620 } 2767 }
2621 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 2768 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2622 return ret; 2769 return ret;
2770out_overflow:
2771 print_overflow_msg(__func__, xdr);
2772 return -EIO;
2623} 2773}
2624 2774
2625static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 2775static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
@@ -2631,14 +2781,19 @@ static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
2631 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 2781 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2632 return -EIO; 2782 return -EIO;
2633 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 2783 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2634 READ_BUF(8); 2784 p = xdr_inline_decode(xdr, 8);
2635 READ64(*change); 2785 if (unlikely(!p))
2786 goto out_overflow;
2787 xdr_decode_hyper(p, change);
2636 bitmap[0] &= ~FATTR4_WORD0_CHANGE; 2788 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2637 ret = NFS_ATTR_FATTR_CHANGE; 2789 ret = NFS_ATTR_FATTR_CHANGE;
2638 } 2790 }
2639 dprintk("%s: change attribute=%Lu\n", __func__, 2791 dprintk("%s: change attribute=%Lu\n", __func__,
2640 (unsigned long long)*change); 2792 (unsigned long long)*change);
2641 return ret; 2793 return ret;
2794out_overflow:
2795 print_overflow_msg(__func__, xdr);
2796 return -EIO;
2642} 2797}
2643 2798
2644static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 2799static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
@@ -2650,13 +2805,18 @@ static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *
2650 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 2805 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2651 return -EIO; 2806 return -EIO;
2652 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 2807 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2653 READ_BUF(8); 2808 p = xdr_inline_decode(xdr, 8);
2654 READ64(*size); 2809 if (unlikely(!p))
2810 goto out_overflow;
2811 xdr_decode_hyper(p, size);
2655 bitmap[0] &= ~FATTR4_WORD0_SIZE; 2812 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2656 ret = NFS_ATTR_FATTR_SIZE; 2813 ret = NFS_ATTR_FATTR_SIZE;
2657 } 2814 }
2658 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 2815 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2659 return ret; 2816 return ret;
2817out_overflow:
2818 print_overflow_msg(__func__, xdr);
2819 return -EIO;
2660} 2820}
2661 2821
2662static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2822static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2667,12 +2827,17 @@ static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, ui
2667 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 2827 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2668 return -EIO; 2828 return -EIO;
2669 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 2829 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2670 READ_BUF(4); 2830 p = xdr_inline_decode(xdr, 4);
2671 READ32(*res); 2831 if (unlikely(!p))
2832 goto out_overflow;
2833 *res = be32_to_cpup(p);
2672 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 2834 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2673 } 2835 }
2674 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 2836 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2675 return 0; 2837 return 0;
2838out_overflow:
2839 print_overflow_msg(__func__, xdr);
2840 return -EIO;
2676} 2841}
2677 2842
2678static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2843static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2683,12 +2848,17 @@ static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap,
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 2848 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2684 return -EIO; 2849 return -EIO;
2685 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 2850 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2686 READ_BUF(4); 2851 p = xdr_inline_decode(xdr, 4);
2687 READ32(*res); 2852 if (unlikely(!p))
2853 goto out_overflow;
2854 *res = be32_to_cpup(p);
2688 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 2855 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2689 } 2856 }
2690 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 2857 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2691 return 0; 2858 return 0;
2859out_overflow:
2860 print_overflow_msg(__func__, xdr);
2861 return -EIO;
2692} 2862}
2693 2863
2694static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 2864static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
@@ -2701,9 +2871,11 @@ static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs
2701 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 2871 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2702 return -EIO; 2872 return -EIO;
2703 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 2873 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2704 READ_BUF(16); 2874 p = xdr_inline_decode(xdr, 16);
2705 READ64(fsid->major); 2875 if (unlikely(!p))
2706 READ64(fsid->minor); 2876 goto out_overflow;
2877 p = xdr_decode_hyper(p, &fsid->major);
2878 xdr_decode_hyper(p, &fsid->minor);
2707 bitmap[0] &= ~FATTR4_WORD0_FSID; 2879 bitmap[0] &= ~FATTR4_WORD0_FSID;
2708 ret = NFS_ATTR_FATTR_FSID; 2880 ret = NFS_ATTR_FATTR_FSID;
2709 } 2881 }
@@ -2711,6 +2883,9 @@ static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs
2711 (unsigned long long)fsid->major, 2883 (unsigned long long)fsid->major,
2712 (unsigned long long)fsid->minor); 2884 (unsigned long long)fsid->minor);
2713 return ret; 2885 return ret;
2886out_overflow:
2887 print_overflow_msg(__func__, xdr);
2888 return -EIO;
2714} 2889}
2715 2890
2716static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2891static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2721,12 +2896,67 @@ static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint
2721 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 2896 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2722 return -EIO; 2897 return -EIO;
2723 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 2898 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2724 READ_BUF(4); 2899 p = xdr_inline_decode(xdr, 4);
2725 READ32(*res); 2900 if (unlikely(!p))
2901 goto out_overflow;
2902 *res = be32_to_cpup(p);
2726 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 2903 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2727 } 2904 }
2728 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 2905 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2729 return 0; 2906 return 0;
2907out_overflow:
2908 print_overflow_msg(__func__, xdr);
2909 return -EIO;
2910}
2911
2912static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2913{
2914 __be32 *p;
2915
2916 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2917 return -EIO;
2918 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2919 p = xdr_inline_decode(xdr, 4);
2920 if (unlikely(!p))
2921 goto out_overflow;
2922 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2923 }
2924 return 0;
2925out_overflow:
2926 print_overflow_msg(__func__, xdr);
2927 return -EIO;
2928}
2929
2930static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2931{
2932 __be32 *p;
2933 int len;
2934
2935 if (fh != NULL)
2936 memset(fh, 0, sizeof(*fh));
2937
2938 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2939 return -EIO;
2940 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2941 p = xdr_inline_decode(xdr, 4);
2942 if (unlikely(!p))
2943 goto out_overflow;
2944 len = be32_to_cpup(p);
2945 if (len > NFS4_FHSIZE)
2946 return -EIO;
2947 p = xdr_inline_decode(xdr, len);
2948 if (unlikely(!p))
2949 goto out_overflow;
2950 if (fh != NULL) {
2951 memcpy(fh->data, p, len);
2952 fh->size = len;
2953 }
2954 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2955 }
2956 return 0;
2957out_overflow:
2958 print_overflow_msg(__func__, xdr);
2959 return -EIO;
2730} 2960}
2731 2961
2732static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2962static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2737,12 +2967,17 @@ static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint
2737 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 2967 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2738 return -EIO; 2968 return -EIO;
2739 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 2969 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2740 READ_BUF(4); 2970 p = xdr_inline_decode(xdr, 4);
2741 READ32(*res); 2971 if (unlikely(!p))
2972 goto out_overflow;
2973 *res = be32_to_cpup(p);
2742 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 2974 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2743 } 2975 }
2744 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 2976 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2745 return 0; 2977 return 0;
2978out_overflow:
2979 print_overflow_msg(__func__, xdr);
2980 return -EIO;
2746} 2981}
2747 2982
2748static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 2983static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
@@ -2754,13 +2989,18 @@ static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 2989 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2755 return -EIO; 2990 return -EIO;
2756 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 2991 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2757 READ_BUF(8); 2992 p = xdr_inline_decode(xdr, 8);
2758 READ64(*fileid); 2993 if (unlikely(!p))
2994 goto out_overflow;
2995 xdr_decode_hyper(p, fileid);
2759 bitmap[0] &= ~FATTR4_WORD0_FILEID; 2996 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2760 ret = NFS_ATTR_FATTR_FILEID; 2997 ret = NFS_ATTR_FATTR_FILEID;
2761 } 2998 }
2762 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 2999 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2763 return ret; 3000 return ret;
3001out_overflow:
3002 print_overflow_msg(__func__, xdr);
3003 return -EIO;
2764} 3004}
2765 3005
2766static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 3006static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
@@ -2772,13 +3012,18 @@ static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitma
2772 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 3012 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2773 return -EIO; 3013 return -EIO;
2774 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3014 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2775 READ_BUF(8); 3015 p = xdr_inline_decode(xdr, 8);
2776 READ64(*fileid); 3016 if (unlikely(!p))
3017 goto out_overflow;
3018 xdr_decode_hyper(p, fileid);
2777 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 3019 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2778 ret = NFS_ATTR_FATTR_FILEID; 3020 ret = NFS_ATTR_FATTR_FILEID;
2779 } 3021 }
2780 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3022 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2781 return ret; 3023 return ret;
3024out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
2782} 3027}
2783 3028
2784static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3029static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -2790,12 +3035,17 @@ static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
2790 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 3035 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2791 return -EIO; 3036 return -EIO;
2792 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3037 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2793 READ_BUF(8); 3038 p = xdr_inline_decode(xdr, 8);
2794 READ64(*res); 3039 if (unlikely(!p))
3040 goto out_overflow;
3041 xdr_decode_hyper(p, res);
2795 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 3042 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2796 } 3043 }
2797 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 3044 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2798 return status; 3045 return status;
3046out_overflow:
3047 print_overflow_msg(__func__, xdr);
3048 return -EIO;
2799} 3049}
2800 3050
2801static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3051static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -2807,12 +3057,17 @@ static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
2807 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 3057 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2808 return -EIO; 3058 return -EIO;
2809 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3059 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2810 READ_BUF(8); 3060 p = xdr_inline_decode(xdr, 8);
2811 READ64(*res); 3061 if (unlikely(!p))
3062 goto out_overflow;
3063 xdr_decode_hyper(p, res);
2812 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 3064 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2813 } 3065 }
2814 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 3066 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2815 return status; 3067 return status;
3068out_overflow:
3069 print_overflow_msg(__func__, xdr);
3070 return -EIO;
2816} 3071}
2817 3072
2818static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3073static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -2824,12 +3079,17 @@ static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
2824 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 3079 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2825 return -EIO; 3080 return -EIO;
2826 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3081 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2827 READ_BUF(8); 3082 p = xdr_inline_decode(xdr, 8);
2828 READ64(*res); 3083 if (unlikely(!p))
3084 goto out_overflow;
3085 xdr_decode_hyper(p, res);
2829 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 3086 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2830 } 3087 }
2831 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 3088 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2832 return status; 3089 return status;
3090out_overflow:
3091 print_overflow_msg(__func__, xdr);
3092 return -EIO;
2833} 3093}
2834 3094
2835static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 3095static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
@@ -2838,8 +3098,10 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2838 __be32 *p; 3098 __be32 *p;
2839 int status = 0; 3099 int status = 0;
2840 3100
2841 READ_BUF(4); 3101 p = xdr_inline_decode(xdr, 4);
2842 READ32(n); 3102 if (unlikely(!p))
3103 goto out_overflow;
3104 n = be32_to_cpup(p);
2843 if (n == 0) 3105 if (n == 0)
2844 goto root_path; 3106 goto root_path;
2845 dprintk("path "); 3107 dprintk("path ");
@@ -2873,6 +3135,9 @@ out_eio:
2873 dprintk(" status %d", status); 3135 dprintk(" status %d", status);
2874 status = -EIO; 3136 status = -EIO;
2875 goto out; 3137 goto out;
3138out_overflow:
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
2876} 3141}
2877 3142
2878static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3143static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
@@ -2890,8 +3155,10 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
2890 status = decode_pathname(xdr, &res->fs_path); 3155 status = decode_pathname(xdr, &res->fs_path);
2891 if (unlikely(status != 0)) 3156 if (unlikely(status != 0))
2892 goto out; 3157 goto out;
2893 READ_BUF(4); 3158 p = xdr_inline_decode(xdr, 4);
2894 READ32(n); 3159 if (unlikely(!p))
3160 goto out_overflow;
3161 n = be32_to_cpup(p);
2895 if (n <= 0) 3162 if (n <= 0)
2896 goto out_eio; 3163 goto out_eio;
2897 res->nlocations = 0; 3164 res->nlocations = 0;
@@ -2899,8 +3166,10 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
2899 u32 m; 3166 u32 m;
2900 struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3167 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2901 3168
2902 READ_BUF(4); 3169 p = xdr_inline_decode(xdr, 4);
2903 READ32(m); 3170 if (unlikely(!p))
3171 goto out_overflow;
3172 m = be32_to_cpup(p);
2904 3173
2905 loc->nservers = 0; 3174 loc->nservers = 0;
2906 dprintk("%s: servers ", __func__); 3175 dprintk("%s: servers ", __func__);
@@ -2939,6 +3208,8 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
2939out: 3208out:
2940 dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3209 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2941 return status; 3210 return status;
3211out_overflow:
3212 print_overflow_msg(__func__, xdr);
2942out_eio: 3213out_eio:
2943 status = -EIO; 3214 status = -EIO;
2944 goto out; 3215 goto out;
@@ -2953,12 +3224,17 @@ static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uin
2953 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 3224 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2954 return -EIO; 3225 return -EIO;
2955 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3226 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2956 READ_BUF(8); 3227 p = xdr_inline_decode(xdr, 8);
2957 READ64(*res); 3228 if (unlikely(!p))
3229 goto out_overflow;
3230 xdr_decode_hyper(p, res);
2958 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 3231 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2959 } 3232 }
2960 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 3233 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2961 return status; 3234 return status;
3235out_overflow:
3236 print_overflow_msg(__func__, xdr);
3237 return -EIO;
2962} 3238}
2963 3239
2964static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 3240static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
@@ -2970,12 +3246,17 @@ static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
2970 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 3246 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2971 return -EIO; 3247 return -EIO;
2972 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3248 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2973 READ_BUF(4); 3249 p = xdr_inline_decode(xdr, 4);
2974 READ32(*maxlink); 3250 if (unlikely(!p))
3251 goto out_overflow;
3252 *maxlink = be32_to_cpup(p);
2975 bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 3253 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2976 } 3254 }
2977 dprintk("%s: maxlink=%u\n", __func__, *maxlink); 3255 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2978 return status; 3256 return status;
3257out_overflow:
3258 print_overflow_msg(__func__, xdr);
3259 return -EIO;
2979} 3260}
2980 3261
2981static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 3262static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
@@ -2987,12 +3268,17 @@ static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
2987 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 3268 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2988 return -EIO; 3269 return -EIO;
2989 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3270 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2990 READ_BUF(4); 3271 p = xdr_inline_decode(xdr, 4);
2991 READ32(*maxname); 3272 if (unlikely(!p))
3273 goto out_overflow;
3274 *maxname = be32_to_cpup(p);
2992 bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 3275 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2993 } 3276 }
2994 dprintk("%s: maxname=%u\n", __func__, *maxname); 3277 dprintk("%s: maxname=%u\n", __func__, *maxname);
2995 return status; 3278 return status;
3279out_overflow:
3280 print_overflow_msg(__func__, xdr);
3281 return -EIO;
2996} 3282}
2997 3283
2998static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 3284static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -3005,8 +3291,10 @@ static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
3005 return -EIO; 3291 return -EIO;
3006 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 3292 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3007 uint64_t maxread; 3293 uint64_t maxread;
3008 READ_BUF(8); 3294 p = xdr_inline_decode(xdr, 8);
3009 READ64(maxread); 3295 if (unlikely(!p))
3296 goto out_overflow;
3297 xdr_decode_hyper(p, &maxread);
3010 if (maxread > 0x7FFFFFFF) 3298 if (maxread > 0x7FFFFFFF)
3011 maxread = 0x7FFFFFFF; 3299 maxread = 0x7FFFFFFF;
3012 *res = (uint32_t)maxread; 3300 *res = (uint32_t)maxread;
@@ -3014,6 +3302,9 @@ static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
3014 } 3302 }
3015 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 3303 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3016 return status; 3304 return status;
3305out_overflow:
3306 print_overflow_msg(__func__, xdr);
3307 return -EIO;
3017} 3308}
3018 3309
3019static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 3310static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -3026,8 +3317,10 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
3026 return -EIO; 3317 return -EIO;
3027 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 3318 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3028 uint64_t maxwrite; 3319 uint64_t maxwrite;
3029 READ_BUF(8); 3320 p = xdr_inline_decode(xdr, 8);
3030 READ64(maxwrite); 3321 if (unlikely(!p))
3322 goto out_overflow;
3323 xdr_decode_hyper(p, &maxwrite);
3031 if (maxwrite > 0x7FFFFFFF) 3324 if (maxwrite > 0x7FFFFFFF)
3032 maxwrite = 0x7FFFFFFF; 3325 maxwrite = 0x7FFFFFFF;
3033 *res = (uint32_t)maxwrite; 3326 *res = (uint32_t)maxwrite;
@@ -3035,6 +3328,9 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
3035 } 3328 }
3036 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 3329 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3037 return status; 3330 return status;
3331out_overflow:
3332 print_overflow_msg(__func__, xdr);
3333 return -EIO;
3038} 3334}
3039 3335
3040static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 3336static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
@@ -3047,14 +3343,19 @@ static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *m
3047 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 3343 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3048 return -EIO; 3344 return -EIO;
3049 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3345 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3050 READ_BUF(4); 3346 p = xdr_inline_decode(xdr, 4);
3051 READ32(tmp); 3347 if (unlikely(!p))
3348 goto out_overflow;
3349 tmp = be32_to_cpup(p);
3052 *mode = tmp & ~S_IFMT; 3350 *mode = tmp & ~S_IFMT;
3053 bitmap[1] &= ~FATTR4_WORD1_MODE; 3351 bitmap[1] &= ~FATTR4_WORD1_MODE;
3054 ret = NFS_ATTR_FATTR_MODE; 3352 ret = NFS_ATTR_FATTR_MODE;
3055 } 3353 }
3056 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3354 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3057 return ret; 3355 return ret;
3356out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
3058} 3359}
3059 3360
3060static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 3361static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
@@ -3066,16 +3367,22 @@ static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t
3066 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 3367 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3067 return -EIO; 3368 return -EIO;
3068 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3369 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3069 READ_BUF(4); 3370 p = xdr_inline_decode(xdr, 4);
3070 READ32(*nlink); 3371 if (unlikely(!p))
3372 goto out_overflow;
3373 *nlink = be32_to_cpup(p);
3071 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3374 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3072 ret = NFS_ATTR_FATTR_NLINK; 3375 ret = NFS_ATTR_FATTR_NLINK;
3073 } 3376 }
3074 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3377 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3075 return ret; 3378 return ret;
3379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
3076} 3382}
3077 3383
3078static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid) 3384static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3385 struct nfs_client *clp, uint32_t *uid, int may_sleep)
3079{ 3386{
3080 uint32_t len; 3387 uint32_t len;
3081 __be32 *p; 3388 __be32 *p;
@@ -3085,10 +3392,16 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
3085 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 3392 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3086 return -EIO; 3393 return -EIO;
3087 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3394 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3088 READ_BUF(4); 3395 p = xdr_inline_decode(xdr, 4);
3089 READ32(len); 3396 if (unlikely(!p))
3090 READ_BUF(len); 3397 goto out_overflow;
3091 if (len < XDR_MAX_NETOBJ) { 3398 len = be32_to_cpup(p);
3399 p = xdr_inline_decode(xdr, len);
3400 if (unlikely(!p))
3401 goto out_overflow;
3402 if (!may_sleep) {
3403 /* do nothing */
3404 } else if (len < XDR_MAX_NETOBJ) {
3092 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0) 3405 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3093 ret = NFS_ATTR_FATTR_OWNER; 3406 ret = NFS_ATTR_FATTR_OWNER;
3094 else 3407 else
@@ -3101,9 +3414,13 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
3101 } 3414 }
3102 dprintk("%s: uid=%d\n", __func__, (int)*uid); 3415 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3103 return ret; 3416 return ret;
3417out_overflow:
3418 print_overflow_msg(__func__, xdr);
3419 return -EIO;
3104} 3420}
3105 3421
3106static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid) 3422static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3423 struct nfs_client *clp, uint32_t *gid, int may_sleep)
3107{ 3424{
3108 uint32_t len; 3425 uint32_t len;
3109 __be32 *p; 3426 __be32 *p;
@@ -3113,10 +3430,16 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
3113 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 3430 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3114 return -EIO; 3431 return -EIO;
3115 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3432 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3116 READ_BUF(4); 3433 p = xdr_inline_decode(xdr, 4);
3117 READ32(len); 3434 if (unlikely(!p))
3118 READ_BUF(len); 3435 goto out_overflow;
3119 if (len < XDR_MAX_NETOBJ) { 3436 len = be32_to_cpup(p);
3437 p = xdr_inline_decode(xdr, len);
3438 if (unlikely(!p))
3439 goto out_overflow;
3440 if (!may_sleep) {
3441 /* do nothing */
3442 } else if (len < XDR_MAX_NETOBJ) {
3120 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0) 3443 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3121 ret = NFS_ATTR_FATTR_GROUP; 3444 ret = NFS_ATTR_FATTR_GROUP;
3122 else 3445 else
@@ -3129,6 +3452,9 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
3129 } 3452 }
3130 dprintk("%s: gid=%d\n", __func__, (int)*gid); 3453 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3131 return ret; 3454 return ret;
3455out_overflow:
3456 print_overflow_msg(__func__, xdr);
3457 return -EIO;
3132} 3458}
3133 3459
3134static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 3460static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
@@ -3143,9 +3469,11 @@ static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rde
3143 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 3469 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3144 dev_t tmp; 3470 dev_t tmp;
3145 3471
3146 READ_BUF(8); 3472 p = xdr_inline_decode(xdr, 8);
3147 READ32(major); 3473 if (unlikely(!p))
3148 READ32(minor); 3474 goto out_overflow;
3475 major = be32_to_cpup(p++);
3476 minor = be32_to_cpup(p);
3149 tmp = MKDEV(major, minor); 3477 tmp = MKDEV(major, minor);
3150 if (MAJOR(tmp) == major && MINOR(tmp) == minor) 3478 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3151 *rdev = tmp; 3479 *rdev = tmp;
@@ -3154,6 +3482,9 @@ static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rde
3154 } 3482 }
3155 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3483 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3156 return ret; 3484 return ret;
3485out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
3157} 3488}
3158 3489
3159static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3490static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -3165,12 +3496,17 @@ static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
3165 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 3496 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3166 return -EIO; 3497 return -EIO;
3167 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3498 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3168 READ_BUF(8); 3499 p = xdr_inline_decode(xdr, 8);
3169 READ64(*res); 3500 if (unlikely(!p))
3501 goto out_overflow;
3502 xdr_decode_hyper(p, res);
3170 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 3503 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3171 } 3504 }
3172 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 3505 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3173 return status; 3506 return status;
3507out_overflow:
3508 print_overflow_msg(__func__, xdr);
3509 return -EIO;
3174} 3510}
3175 3511
3176static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3512static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -3182,12 +3518,17 @@ static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
3182 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 3518 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3183 return -EIO; 3519 return -EIO;
3184 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3520 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3185 READ_BUF(8); 3521 p = xdr_inline_decode(xdr, 8);
3186 READ64(*res); 3522 if (unlikely(!p))
3523 goto out_overflow;
3524 xdr_decode_hyper(p, res);
3187 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 3525 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3188 } 3526 }
3189 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 3527 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3190 return status; 3528 return status;
3529out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
3191} 3532}
3192 3533
3193static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3534static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -3199,12 +3540,17 @@ static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
3199 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 3540 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3200 return -EIO; 3541 return -EIO;
3201 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3542 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3202 READ_BUF(8); 3543 p = xdr_inline_decode(xdr, 8);
3203 READ64(*res); 3544 if (unlikely(!p))
3545 goto out_overflow;
3546 xdr_decode_hyper(p, res);
3204 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 3547 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3205 } 3548 }
3206 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 3549 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3207 return status; 3550 return status;
3551out_overflow:
3552 print_overflow_msg(__func__, xdr);
3553 return -EIO;
3208} 3554}
3209 3555
3210static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 3556static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
@@ -3216,14 +3562,19 @@ static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint
3216 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 3562 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3217 return -EIO; 3563 return -EIO;
3218 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3564 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3219 READ_BUF(8); 3565 p = xdr_inline_decode(xdr, 8);
3220 READ64(*used); 3566 if (unlikely(!p))
3567 goto out_overflow;
3568 xdr_decode_hyper(p, used);
3221 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3569 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3222 ret = NFS_ATTR_FATTR_SPACE_USED; 3570 ret = NFS_ATTR_FATTR_SPACE_USED;
3223 } 3571 }
3224 dprintk("%s: space used=%Lu\n", __func__, 3572 dprintk("%s: space used=%Lu\n", __func__,
3225 (unsigned long long)*used); 3573 (unsigned long long)*used);
3226 return ret; 3574 return ret;
3575out_overflow:
3576 print_overflow_msg(__func__, xdr);
3577 return -EIO;
3227} 3578}
3228 3579
3229static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 3580static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
@@ -3232,12 +3583,17 @@ static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3232 uint64_t sec; 3583 uint64_t sec;
3233 uint32_t nsec; 3584 uint32_t nsec;
3234 3585
3235 READ_BUF(12); 3586 p = xdr_inline_decode(xdr, 12);
3236 READ64(sec); 3587 if (unlikely(!p))
3237 READ32(nsec); 3588 goto out_overflow;
3589 p = xdr_decode_hyper(p, &sec);
3590 nsec = be32_to_cpup(p);
3238 time->tv_sec = (time_t)sec; 3591 time->tv_sec = (time_t)sec;
3239 time->tv_nsec = (long)nsec; 3592 time->tv_nsec = (long)nsec;
3240 return 0; 3593 return 0;
3594out_overflow:
3595 print_overflow_msg(__func__, xdr);
3596 return -EIO;
3241} 3597}
3242 3598
3243static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 3599static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
@@ -3276,6 +3632,24 @@ static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, s
3276 return status; 3632 return status;
3277} 3633}
3278 3634
3635static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3636 struct timespec *time)
3637{
3638 int status = 0;
3639
3640 time->tv_sec = 0;
3641 time->tv_nsec = 0;
3642 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3643 return -EIO;
3644 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3645 status = decode_attr_time(xdr, time);
3646 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3647 }
3648 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3649 (long)time->tv_nsec);
3650 return status;
3651}
3652
3279static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 3653static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3280{ 3654{
3281 int status = 0; 3655 int status = 0;
@@ -3315,11 +3689,16 @@ static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *c
3315{ 3689{
3316 __be32 *p; 3690 __be32 *p;
3317 3691
3318 READ_BUF(20); 3692 p = xdr_inline_decode(xdr, 20);
3319 READ32(cinfo->atomic); 3693 if (unlikely(!p))
3320 READ64(cinfo->before); 3694 goto out_overflow;
3321 READ64(cinfo->after); 3695 cinfo->atomic = be32_to_cpup(p++);
3696 p = xdr_decode_hyper(p, &cinfo->before);
3697 xdr_decode_hyper(p, &cinfo->after);
3322 return 0; 3698 return 0;
3699out_overflow:
3700 print_overflow_msg(__func__, xdr);
3701 return -EIO;
3323} 3702}
3324 3703
3325static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 3704static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
@@ -3331,40 +3710,62 @@ static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3331 status = decode_op_hdr(xdr, OP_ACCESS); 3710 status = decode_op_hdr(xdr, OP_ACCESS);
3332 if (status) 3711 if (status)
3333 return status; 3712 return status;
3334 READ_BUF(8); 3713 p = xdr_inline_decode(xdr, 8);
3335 READ32(supp); 3714 if (unlikely(!p))
3336 READ32(acc); 3715 goto out_overflow;
3716 supp = be32_to_cpup(p++);
3717 acc = be32_to_cpup(p);
3337 access->supported = supp; 3718 access->supported = supp;
3338 access->access = acc; 3719 access->access = acc;
3339 return 0; 3720 return 0;
3721out_overflow:
3722 print_overflow_msg(__func__, xdr);
3723 return -EIO;
3340} 3724}
3341 3725
3342static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 3726static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
3343{ 3727{
3344 __be32 *p; 3728 __be32 *p;
3729
3730 p = xdr_inline_decode(xdr, len);
3731 if (likely(p)) {
3732 memcpy(buf, p, len);
3733 return 0;
3734 }
3735 print_overflow_msg(__func__, xdr);
3736 return -EIO;
3737}
3738
3739static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3740{
3741 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
3742}
3743
3744static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3745{
3345 int status; 3746 int status;
3346 3747
3347 status = decode_op_hdr(xdr, OP_CLOSE); 3748 status = decode_op_hdr(xdr, OP_CLOSE);
3348 if (status != -EIO) 3749 if (status != -EIO)
3349 nfs_increment_open_seqid(status, res->seqid); 3750 nfs_increment_open_seqid(status, res->seqid);
3350 if (status) 3751 if (!status)
3351 return status; 3752 status = decode_stateid(xdr, &res->stateid);
3352 READ_BUF(NFS4_STATEID_SIZE); 3753 return status;
3353 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); 3754}
3354 return 0; 3755
3756static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3757{
3758 return decode_opaque_fixed(xdr, verifier, 8);
3355} 3759}
3356 3760
3357static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 3761static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3358{ 3762{
3359 __be32 *p;
3360 int status; 3763 int status;
3361 3764
3362 status = decode_op_hdr(xdr, OP_COMMIT); 3765 status = decode_op_hdr(xdr, OP_COMMIT);
3363 if (status) 3766 if (!status)
3364 return status; 3767 status = decode_verifier(xdr, res->verf->verifier);
3365 READ_BUF(8); 3768 return status;
3366 COPYMEM(res->verf->verifier, 8);
3367 return 0;
3368} 3769}
3369 3770
3370static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 3771static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
@@ -3378,10 +3779,16 @@ static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3378 return status; 3779 return status;
3379 if ((status = decode_change_info(xdr, cinfo))) 3780 if ((status = decode_change_info(xdr, cinfo)))
3380 return status; 3781 return status;
3381 READ_BUF(4); 3782 p = xdr_inline_decode(xdr, 4);
3382 READ32(bmlen); 3783 if (unlikely(!p))
3383 READ_BUF(bmlen << 2); 3784 goto out_overflow;
3384 return 0; 3785 bmlen = be32_to_cpup(p);
3786 p = xdr_inline_decode(xdr, bmlen << 2);
3787 if (likely(p))
3788 return 0;
3789out_overflow:
3790 print_overflow_msg(__func__, xdr);
3791 return -EIO;
3385} 3792}
3386 3793
3387static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 3794static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
@@ -3466,28 +3873,14 @@ xdr_error:
3466 return status; 3873 return status;
3467} 3874}
3468 3875
3469static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server) 3876static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3877 struct nfs_fattr *fattr, struct nfs_fh *fh,
3878 const struct nfs_server *server, int may_sleep)
3470{ 3879{
3471 __be32 *savep;
3472 uint32_t attrlen,
3473 bitmap[2] = {0},
3474 type;
3475 int status; 3880 int status;
3476 umode_t fmode = 0; 3881 umode_t fmode = 0;
3477 uint64_t fileid; 3882 uint64_t fileid;
3478 3883 uint32_t type;
3479 status = decode_op_hdr(xdr, OP_GETATTR);
3480 if (status < 0)
3481 goto xdr_error;
3482
3483 status = decode_attr_bitmap(xdr, bitmap);
3484 if (status < 0)
3485 goto xdr_error;
3486
3487 status = decode_attr_length(xdr, &attrlen, &savep);
3488 if (status < 0)
3489 goto xdr_error;
3490
3491 3884
3492 status = decode_attr_type(xdr, bitmap, &type); 3885 status = decode_attr_type(xdr, bitmap, &type);
3493 if (status < 0) 3886 if (status < 0)
@@ -3513,6 +3906,14 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
3513 goto xdr_error; 3906 goto xdr_error;
3514 fattr->valid |= status; 3907 fattr->valid |= status;
3515 3908
3909 status = decode_attr_error(xdr, bitmap);
3910 if (status < 0)
3911 goto xdr_error;
3912
3913 status = decode_attr_filehandle(xdr, bitmap, fh);
3914 if (status < 0)
3915 goto xdr_error;
3916
3516 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 3917 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3517 if (status < 0) 3918 if (status < 0)
3518 goto xdr_error; 3919 goto xdr_error;
@@ -3538,12 +3939,14 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
3538 goto xdr_error; 3939 goto xdr_error;
3539 fattr->valid |= status; 3940 fattr->valid |= status;
3540 3941
3541 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid); 3942 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3943 &fattr->uid, may_sleep);
3542 if (status < 0) 3944 if (status < 0)
3543 goto xdr_error; 3945 goto xdr_error;
3544 fattr->valid |= status; 3946 fattr->valid |= status;
3545 3947
3546 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid); 3948 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3949 &fattr->gid, may_sleep);
3547 if (status < 0) 3950 if (status < 0)
3548 goto xdr_error; 3951 goto xdr_error;
3549 fattr->valid |= status; 3952 fattr->valid |= status;
@@ -3581,12 +3984,101 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
3581 fattr->valid |= status; 3984 fattr->valid |= status;
3582 } 3985 }
3583 3986
3987xdr_error:
3988 dprintk("%s: xdr returned %d\n", __func__, -status);
3989 return status;
3990}
3991
3992static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3993 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3994{
3995 __be32 *savep;
3996 uint32_t attrlen,
3997 bitmap[2] = {0};
3998 int status;
3999
4000 status = decode_op_hdr(xdr, OP_GETATTR);
4001 if (status < 0)
4002 goto xdr_error;
4003
4004 status = decode_attr_bitmap(xdr, bitmap);
4005 if (status < 0)
4006 goto xdr_error;
4007
4008 status = decode_attr_length(xdr, &attrlen, &savep);
4009 if (status < 0)
4010 goto xdr_error;
4011
4012 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4013 if (status < 0)
4014 goto xdr_error;
4015
3584 status = verify_attr_len(xdr, savep, attrlen); 4016 status = verify_attr_len(xdr, savep, attrlen);
3585xdr_error: 4017xdr_error:
3586 dprintk("%s: xdr returned %d\n", __func__, -status); 4018 dprintk("%s: xdr returned %d\n", __func__, -status);
3587 return status; 4019 return status;
3588} 4020}
3589 4021
4022static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4023 const struct nfs_server *server, int may_sleep)
4024{
4025 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4026}
4027
4028/*
4029 * Decode potentially multiple layout types. Currently we only support
4030 * one layout driver per file system.
4031 */
4032static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4033 uint32_t *layouttype)
4034{
4035 uint32_t *p;
4036 int num;
4037
4038 p = xdr_inline_decode(xdr, 4);
4039 if (unlikely(!p))
4040 goto out_overflow;
4041 num = be32_to_cpup(p);
4042
4043 /* pNFS is not supported by the underlying file system */
4044 if (num == 0) {
4045 *layouttype = 0;
4046 return 0;
4047 }
4048 if (num > 1)
4049 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4050 "per filesystem not supported\n", __func__);
4051
4052 /* Decode and set first layout type, move xdr->p past unused types */
4053 p = xdr_inline_decode(xdr, num * 4);
4054 if (unlikely(!p))
4055 goto out_overflow;
4056 *layouttype = be32_to_cpup(p);
4057 return 0;
4058out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
4061}
4062
4063/*
4064 * The type of file system exported.
4065 * Note we must ensure that layouttype is set in any non-error case.
4066 */
4067static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4068 uint32_t *layouttype)
4069{
4070 int status = 0;
4071
4072 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4073 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4074 return -EIO;
4075 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4076 status = decode_first_pnfs_layout_type(xdr, layouttype);
4077 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4078 } else
4079 *layouttype = 0;
4080 return status;
4081}
3590 4082
3591static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 4083static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3592{ 4084{
@@ -3613,6 +4105,12 @@ static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3613 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 4105 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3614 goto xdr_error; 4106 goto xdr_error;
3615 fsinfo->wtpref = fsinfo->wtmax; 4107 fsinfo->wtpref = fsinfo->wtmax;
4108 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4109 if (status != 0)
4110 goto xdr_error;
4111 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4112 if (status != 0)
4113 goto xdr_error;
3616 4114
3617 status = verify_attr_len(xdr, savep, attrlen); 4115 status = verify_attr_len(xdr, savep, attrlen);
3618xdr_error: 4116xdr_error:
@@ -3633,14 +4131,21 @@ static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3633 if (status) 4131 if (status)
3634 return status; 4132 return status;
3635 4133
3636 READ_BUF(4); 4134 p = xdr_inline_decode(xdr, 4);
3637 READ32(len); 4135 if (unlikely(!p))
4136 goto out_overflow;
4137 len = be32_to_cpup(p);
3638 if (len > NFS4_FHSIZE) 4138 if (len > NFS4_FHSIZE)
3639 return -EIO; 4139 return -EIO;
3640 fh->size = len; 4140 fh->size = len;
3641 READ_BUF(len); 4141 p = xdr_inline_decode(xdr, len);
3642 COPYMEM(fh->data, len); 4142 if (unlikely(!p))
4143 goto out_overflow;
4144 memcpy(fh->data, p, len);
3643 return 0; 4145 return 0;
4146out_overflow:
4147 print_overflow_msg(__func__, xdr);
4148 return -EIO;
3644} 4149}
3645 4150
3646static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 4151static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
@@ -3662,11 +4167,13 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3662 __be32 *p; 4167 __be32 *p;
3663 uint32_t namelen, type; 4168 uint32_t namelen, type;
3664 4169
3665 READ_BUF(32); 4170 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
3666 READ64(offset); 4171 if (unlikely(!p))
3667 READ64(length); 4172 goto out_overflow;
3668 READ32(type); 4173 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
3669 if (fl != NULL) { 4174 p = xdr_decode_hyper(p, &length);
4175 type = be32_to_cpup(p++); /* 4 byte read */
4176 if (fl != NULL) { /* manipulate file lock */
3670 fl->fl_start = (loff_t)offset; 4177 fl->fl_start = (loff_t)offset;
3671 fl->fl_end = fl->fl_start + (loff_t)length - 1; 4178 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3672 if (length == ~(uint64_t)0) 4179 if (length == ~(uint64_t)0)
@@ -3676,23 +4183,27 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3676 fl->fl_type = F_RDLCK; 4183 fl->fl_type = F_RDLCK;
3677 fl->fl_pid = 0; 4184 fl->fl_pid = 0;
3678 } 4185 }
3679 READ64(clientid); 4186 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
3680 READ32(namelen); 4187 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
3681 READ_BUF(namelen); 4188 p = xdr_inline_decode(xdr, namelen); /* variable size field */
3682 return -NFS4ERR_DENIED; 4189 if (likely(p))
4190 return -NFS4ERR_DENIED;
4191out_overflow:
4192 print_overflow_msg(__func__, xdr);
4193 return -EIO;
3683} 4194}
3684 4195
3685static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 4196static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3686{ 4197{
3687 __be32 *p;
3688 int status; 4198 int status;
3689 4199
3690 status = decode_op_hdr(xdr, OP_LOCK); 4200 status = decode_op_hdr(xdr, OP_LOCK);
3691 if (status == -EIO) 4201 if (status == -EIO)
3692 goto out; 4202 goto out;
3693 if (status == 0) { 4203 if (status == 0) {
3694 READ_BUF(NFS4_STATEID_SIZE); 4204 status = decode_stateid(xdr, &res->stateid);
3695 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); 4205 if (unlikely(status))
4206 goto out;
3696 } else if (status == -NFS4ERR_DENIED) 4207 } else if (status == -NFS4ERR_DENIED)
3697 status = decode_lock_denied(xdr, NULL); 4208 status = decode_lock_denied(xdr, NULL);
3698 if (res->open_seqid != NULL) 4209 if (res->open_seqid != NULL)
@@ -3713,19 +4224,21 @@ static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3713 4224
3714static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 4225static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3715{ 4226{
3716 __be32 *p;
3717 int status; 4227 int status;
3718 4228
3719 status = decode_op_hdr(xdr, OP_LOCKU); 4229 status = decode_op_hdr(xdr, OP_LOCKU);
3720 if (status != -EIO) 4230 if (status != -EIO)
3721 nfs_increment_lock_seqid(status, res->seqid); 4231 nfs_increment_lock_seqid(status, res->seqid);
3722 if (status == 0) { 4232 if (status == 0)
3723 READ_BUF(NFS4_STATEID_SIZE); 4233 status = decode_stateid(xdr, &res->stateid);
3724 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3725 }
3726 return status; 4234 return status;
3727} 4235}
3728 4236
4237static int decode_release_lockowner(struct xdr_stream *xdr)
4238{
4239 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4240}
4241
3729static int decode_lookup(struct xdr_stream *xdr) 4242static int decode_lookup(struct xdr_stream *xdr)
3730{ 4243{
3731 return decode_op_hdr(xdr, OP_LOOKUP); 4244 return decode_op_hdr(xdr, OP_LOOKUP);
@@ -3737,34 +4250,46 @@ static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3737 __be32 *p; 4250 __be32 *p;
3738 uint32_t limit_type, nblocks, blocksize; 4251 uint32_t limit_type, nblocks, blocksize;
3739 4252
3740 READ_BUF(12); 4253 p = xdr_inline_decode(xdr, 12);
3741 READ32(limit_type); 4254 if (unlikely(!p))
4255 goto out_overflow;
4256 limit_type = be32_to_cpup(p++);
3742 switch (limit_type) { 4257 switch (limit_type) {
3743 case 1: 4258 case 1:
3744 READ64(*maxsize); 4259 xdr_decode_hyper(p, maxsize);
3745 break; 4260 break;
3746 case 2: 4261 case 2:
3747 READ32(nblocks); 4262 nblocks = be32_to_cpup(p++);
3748 READ32(blocksize); 4263 blocksize = be32_to_cpup(p);
3749 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 4264 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3750 } 4265 }
3751 return 0; 4266 return 0;
4267out_overflow:
4268 print_overflow_msg(__func__, xdr);
4269 return -EIO;
3752} 4270}
3753 4271
3754static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 4272static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3755{ 4273{
3756 __be32 *p; 4274 __be32 *p;
3757 uint32_t delegation_type; 4275 uint32_t delegation_type;
4276 int status;
3758 4277
3759 READ_BUF(4); 4278 p = xdr_inline_decode(xdr, 4);
3760 READ32(delegation_type); 4279 if (unlikely(!p))
4280 goto out_overflow;
4281 delegation_type = be32_to_cpup(p);
3761 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 4282 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3762 res->delegation_type = 0; 4283 res->delegation_type = 0;
3763 return 0; 4284 return 0;
3764 } 4285 }
3765 READ_BUF(NFS4_STATEID_SIZE+4); 4286 status = decode_stateid(xdr, &res->delegation);
3766 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE); 4287 if (unlikely(status))
3767 READ32(res->do_recall); 4288 return status;
4289 p = xdr_inline_decode(xdr, 4);
4290 if (unlikely(!p))
4291 goto out_overflow;
4292 res->do_recall = be32_to_cpup(p);
3768 4293
3769 switch (delegation_type) { 4294 switch (delegation_type) {
3770 case NFS4_OPEN_DELEGATE_READ: 4295 case NFS4_OPEN_DELEGATE_READ:
@@ -3776,6 +4301,9 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3776 return -EIO; 4301 return -EIO;
3777 } 4302 }
3778 return decode_ace(xdr, NULL, res->server->nfs_client); 4303 return decode_ace(xdr, NULL, res->server->nfs_client);
4304out_overflow:
4305 print_overflow_msg(__func__, xdr);
4306 return -EIO;
3779} 4307}
3780 4308
3781static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 4309static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
@@ -3787,23 +4315,27 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3787 status = decode_op_hdr(xdr, OP_OPEN); 4315 status = decode_op_hdr(xdr, OP_OPEN);
3788 if (status != -EIO) 4316 if (status != -EIO)
3789 nfs_increment_open_seqid(status, res->seqid); 4317 nfs_increment_open_seqid(status, res->seqid);
3790 if (status) 4318 if (!status)
4319 status = decode_stateid(xdr, &res->stateid);
4320 if (unlikely(status))
3791 return status; 4321 return status;
3792 READ_BUF(NFS4_STATEID_SIZE);
3793 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3794 4322
3795 decode_change_info(xdr, &res->cinfo); 4323 decode_change_info(xdr, &res->cinfo);
3796 4324
3797 READ_BUF(8); 4325 p = xdr_inline_decode(xdr, 8);
3798 READ32(res->rflags); 4326 if (unlikely(!p))
3799 READ32(bmlen); 4327 goto out_overflow;
4328 res->rflags = be32_to_cpup(p++);
4329 bmlen = be32_to_cpup(p);
3800 if (bmlen > 10) 4330 if (bmlen > 10)
3801 goto xdr_error; 4331 goto xdr_error;
3802 4332
3803 READ_BUF(bmlen << 2); 4333 p = xdr_inline_decode(xdr, bmlen << 2);
4334 if (unlikely(!p))
4335 goto out_overflow;
3804 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4336 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3805 for (i = 0; i < savewords; ++i) 4337 for (i = 0; i < savewords; ++i)
3806 READ32(res->attrset[i]); 4338 res->attrset[i] = be32_to_cpup(p++);
3807 for (; i < NFS4_BITMAP_SIZE; i++) 4339 for (; i < NFS4_BITMAP_SIZE; i++)
3808 res->attrset[i] = 0; 4340 res->attrset[i] = 0;
3809 4341
@@ -3811,36 +4343,33 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3811xdr_error: 4343xdr_error:
3812 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 4344 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3813 return -EIO; 4345 return -EIO;
4346out_overflow:
4347 print_overflow_msg(__func__, xdr);
4348 return -EIO;
3814} 4349}
3815 4350
3816static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 4351static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3817{ 4352{
3818 __be32 *p;
3819 int status; 4353 int status;
3820 4354
3821 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4355 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3822 if (status != -EIO) 4356 if (status != -EIO)
3823 nfs_increment_open_seqid(status, res->seqid); 4357 nfs_increment_open_seqid(status, res->seqid);
3824 if (status) 4358 if (!status)
3825 return status; 4359 status = decode_stateid(xdr, &res->stateid);
3826 READ_BUF(NFS4_STATEID_SIZE); 4360 return status;
3827 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3828 return 0;
3829} 4361}
3830 4362
3831static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 4363static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3832{ 4364{
3833 __be32 *p;
3834 int status; 4365 int status;
3835 4366
3836 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4367 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3837 if (status != -EIO) 4368 if (status != -EIO)
3838 nfs_increment_open_seqid(status, res->seqid); 4369 nfs_increment_open_seqid(status, res->seqid);
3839 if (status) 4370 if (!status)
3840 return status; 4371 status = decode_stateid(xdr, &res->stateid);
3841 READ_BUF(NFS4_STATEID_SIZE); 4372 return status;
3842 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3843 return 0;
3844} 4373}
3845 4374
3846static int decode_putfh(struct xdr_stream *xdr) 4375static int decode_putfh(struct xdr_stream *xdr)
@@ -3863,10 +4392,12 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_
3863 status = decode_op_hdr(xdr, OP_READ); 4392 status = decode_op_hdr(xdr, OP_READ);
3864 if (status) 4393 if (status)
3865 return status; 4394 return status;
3866 READ_BUF(8); 4395 p = xdr_inline_decode(xdr, 8);
3867 READ32(eof); 4396 if (unlikely(!p))
3868 READ32(count); 4397 goto out_overflow;
3869 hdrlen = (u8 *) p - (u8 *) iov->iov_base; 4398 eof = be32_to_cpup(p++);
4399 count = be32_to_cpup(p);
4400 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
3870 recvd = req->rq_rcv_buf.len - hdrlen; 4401 recvd = req->rq_rcv_buf.len - hdrlen;
3871 if (count > recvd) { 4402 if (count > recvd) {
3872 dprintk("NFS: server cheating in read reply: " 4403 dprintk("NFS: server cheating in read reply: "
@@ -3878,101 +4409,38 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_
3878 res->eof = eof; 4409 res->eof = eof;
3879 res->count = count; 4410 res->count = count;
3880 return 0; 4411 return 0;
4412out_overflow:
4413 print_overflow_msg(__func__, xdr);
4414 return -EIO;
3881} 4415}
3882 4416
3883static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 4417static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3884{ 4418{
3885 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 4419 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3886 struct page *page = *rcvbuf->pages;
3887 struct kvec *iov = rcvbuf->head; 4420 struct kvec *iov = rcvbuf->head;
3888 size_t hdrlen; 4421 size_t hdrlen;
3889 u32 recvd, pglen = rcvbuf->page_len; 4422 u32 recvd, pglen = rcvbuf->page_len;
3890 __be32 *end, *entry, *p, *kaddr;
3891 unsigned int nr = 0;
3892 int status; 4423 int status;
3893 4424
3894 status = decode_op_hdr(xdr, OP_READDIR); 4425 status = decode_op_hdr(xdr, OP_READDIR);
3895 if (status) 4426 if (!status)
4427 status = decode_verifier(xdr, readdir->verifier.data);
4428 if (unlikely(status))
3896 return status; 4429 return status;
3897 READ_BUF(8);
3898 COPYMEM(readdir->verifier.data, 8);
3899 dprintk("%s: verifier = %08x:%08x\n", 4430 dprintk("%s: verifier = %08x:%08x\n",
3900 __func__, 4431 __func__,
3901 ((u32 *)readdir->verifier.data)[0], 4432 ((u32 *)readdir->verifier.data)[0],
3902 ((u32 *)readdir->verifier.data)[1]); 4433 ((u32 *)readdir->verifier.data)[1]);
3903 4434
3904 4435
3905 hdrlen = (char *) p - (char *) iov->iov_base; 4436 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3906 recvd = rcvbuf->len - hdrlen; 4437 recvd = rcvbuf->len - hdrlen;
3907 if (pglen > recvd) 4438 if (pglen > recvd)
3908 pglen = recvd; 4439 pglen = recvd;
3909 xdr_read_pages(xdr, pglen); 4440 xdr_read_pages(xdr, pglen);
3910 4441
3911 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); 4442
3912 kaddr = p = kmap_atomic(page, KM_USER0); 4443 return pglen;
3913 end = p + ((pglen + readdir->pgbase) >> 2);
3914 entry = p;
3915
3916 /* Make sure the packet actually has a value_follows and EOF entry */
3917 if ((entry + 1) > end)
3918 goto short_pkt;
3919
3920 for (; *p++; nr++) {
3921 u32 len, attrlen, xlen;
3922 if (end - p < 3)
3923 goto short_pkt;
3924 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3925 p += 2; /* cookie */
3926 len = ntohl(*p++); /* filename length */
3927 if (len > NFS4_MAXNAMLEN) {
3928 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3929 len);
3930 goto err_unmap;
3931 }
3932 xlen = XDR_QUADLEN(len);
3933 if (end - p < xlen + 1)
3934 goto short_pkt;
3935 dprintk("filename = %*s\n", len, (char *)p);
3936 p += xlen;
3937 len = ntohl(*p++); /* bitmap length */
3938 if (end - p < len + 1)
3939 goto short_pkt;
3940 p += len;
3941 attrlen = XDR_QUADLEN(ntohl(*p++));
3942 if (end - p < attrlen + 2)
3943 goto short_pkt;
3944 p += attrlen; /* attributes */
3945 entry = p;
3946 }
3947 /*
3948 * Apparently some server sends responses that are a valid size, but
3949 * contain no entries, and have value_follows==0 and EOF==0. For
3950 * those, just set the EOF marker.
3951 */
3952 if (!nr && entry[1] == 0) {
3953 dprintk("NFS: readdir reply truncated!\n");
3954 entry[1] = 1;
3955 }
3956out:
3957 kunmap_atomic(kaddr, KM_USER0);
3958 return 0;
3959short_pkt:
3960 /*
3961 * When we get a short packet there are 2 possibilities. We can
3962 * return an error, or fix up the response to look like a valid
3963 * response and return what we have so far. If there are no
3964 * entries and the packet was short, then return -EIO. If there
3965 * are valid entries in the response, return them and pretend that
3966 * the call was successful, but incomplete. The caller can retry the
3967 * readdir starting at the last cookie.
3968 */
3969 dprintk("%s: short packet at entry %d\n", __func__, nr);
3970 entry[0] = entry[1] = 0;
3971 if (nr)
3972 goto out;
3973err_unmap:
3974 kunmap_atomic(kaddr, KM_USER0);
3975 return -errno_NFSERR_IO;
3976} 4444}
3977 4445
3978static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 4446static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
@@ -3982,7 +4450,6 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3982 size_t hdrlen; 4450 size_t hdrlen;
3983 u32 len, recvd; 4451 u32 len, recvd;
3984 __be32 *p; 4452 __be32 *p;
3985 char *kaddr;
3986 int status; 4453 int status;
3987 4454
3988 status = decode_op_hdr(xdr, OP_READLINK); 4455 status = decode_op_hdr(xdr, OP_READLINK);
@@ -3990,8 +4457,10 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3990 return status; 4457 return status;
3991 4458
3992 /* Convert length of symlink */ 4459 /* Convert length of symlink */
3993 READ_BUF(4); 4460 p = xdr_inline_decode(xdr, 4);
3994 READ32(len); 4461 if (unlikely(!p))
4462 goto out_overflow;
4463 len = be32_to_cpup(p);
3995 if (len >= rcvbuf->page_len || len <= 0) { 4464 if (len >= rcvbuf->page_len || len <= 0) {
3996 dprintk("nfs: server returned giant symlink!\n"); 4465 dprintk("nfs: server returned giant symlink!\n");
3997 return -ENAMETOOLONG; 4466 return -ENAMETOOLONG;
@@ -4011,10 +4480,11 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4011 * and and null-terminate the text (the VFS expects 4480 * and and null-terminate the text (the VFS expects
4012 * null-termination). 4481 * null-termination).
4013 */ 4482 */
4014 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); 4483 xdr_terminate_string(rcvbuf, len);
4015 kaddr[len+rcvbuf->page_base] = '\0';
4016 kunmap_atomic(kaddr, KM_USER0);
4017 return 0; 4484 return 0;
4485out_overflow:
4486 print_overflow_msg(__func__, xdr);
4487 return -EIO;
4018} 4488}
4019 4489
4020static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 4490static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
@@ -4112,47 +4582,68 @@ static int decode_setattr(struct xdr_stream *xdr)
4112 status = decode_op_hdr(xdr, OP_SETATTR); 4582 status = decode_op_hdr(xdr, OP_SETATTR);
4113 if (status) 4583 if (status)
4114 return status; 4584 return status;
4115 READ_BUF(4); 4585 p = xdr_inline_decode(xdr, 4);
4116 READ32(bmlen); 4586 if (unlikely(!p))
4117 READ_BUF(bmlen << 2); 4587 goto out_overflow;
4118 return 0; 4588 bmlen = be32_to_cpup(p);
4589 p = xdr_inline_decode(xdr, bmlen << 2);
4590 if (likely(p))
4591 return 0;
4592out_overflow:
4593 print_overflow_msg(__func__, xdr);
4594 return -EIO;
4119} 4595}
4120 4596
4121static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp) 4597static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4122{ 4598{
4123 __be32 *p; 4599 __be32 *p;
4124 uint32_t opnum; 4600 uint32_t opnum;
4125 int32_t nfserr; 4601 int32_t nfserr;
4126 4602
4127 READ_BUF(8); 4603 p = xdr_inline_decode(xdr, 8);
4128 READ32(opnum); 4604 if (unlikely(!p))
4605 goto out_overflow;
4606 opnum = be32_to_cpup(p++);
4129 if (opnum != OP_SETCLIENTID) { 4607 if (opnum != OP_SETCLIENTID) {
4130 dprintk("nfs: decode_setclientid: Server returned operation" 4608 dprintk("nfs: decode_setclientid: Server returned operation"
4131 " %d\n", opnum); 4609 " %d\n", opnum);
4132 return -EIO; 4610 return -EIO;
4133 } 4611 }
4134 READ32(nfserr); 4612 nfserr = be32_to_cpup(p);
4135 if (nfserr == NFS_OK) { 4613 if (nfserr == NFS_OK) {
4136 READ_BUF(8 + NFS4_VERIFIER_SIZE); 4614 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4137 READ64(clp->cl_clientid); 4615 if (unlikely(!p))
4138 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE); 4616 goto out_overflow;
4617 p = xdr_decode_hyper(p, &res->clientid);
4618 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4139 } else if (nfserr == NFSERR_CLID_INUSE) { 4619 } else if (nfserr == NFSERR_CLID_INUSE) {
4140 uint32_t len; 4620 uint32_t len;
4141 4621
4142 /* skip netid string */ 4622 /* skip netid string */
4143 READ_BUF(4); 4623 p = xdr_inline_decode(xdr, 4);
4144 READ32(len); 4624 if (unlikely(!p))
4145 READ_BUF(len); 4625 goto out_overflow;
4626 len = be32_to_cpup(p);
4627 p = xdr_inline_decode(xdr, len);
4628 if (unlikely(!p))
4629 goto out_overflow;
4146 4630
4147 /* skip uaddr string */ 4631 /* skip uaddr string */
4148 READ_BUF(4); 4632 p = xdr_inline_decode(xdr, 4);
4149 READ32(len); 4633 if (unlikely(!p))
4150 READ_BUF(len); 4634 goto out_overflow;
4635 len = be32_to_cpup(p);
4636 p = xdr_inline_decode(xdr, len);
4637 if (unlikely(!p))
4638 goto out_overflow;
4151 return -NFSERR_CLID_INUSE; 4639 return -NFSERR_CLID_INUSE;
4152 } else 4640 } else
4153 return nfs4_stat_to_errno(nfserr); 4641 return nfs4_stat_to_errno(nfserr);
4154 4642
4155 return 0; 4643 return 0;
4644out_overflow:
4645 print_overflow_msg(__func__, xdr);
4646 return -EIO;
4156} 4647}
4157 4648
4158static int decode_setclientid_confirm(struct xdr_stream *xdr) 4649static int decode_setclientid_confirm(struct xdr_stream *xdr)
@@ -4169,11 +4660,16 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4169 if (status) 4660 if (status)
4170 return status; 4661 return status;
4171 4662
4172 READ_BUF(16); 4663 p = xdr_inline_decode(xdr, 16);
4173 READ32(res->count); 4664 if (unlikely(!p))
4174 READ32(res->verf->committed); 4665 goto out_overflow;
4175 COPYMEM(res->verf->verifier, 8); 4666 res->count = be32_to_cpup(p++);
4667 res->verf->committed = be32_to_cpup(p++);
4668 memcpy(res->verf->verifier, p, 8);
4176 return 0; 4669 return 0;
4670out_overflow:
4671 print_overflow_msg(__func__, xdr);
4672 return -EIO;
4177} 4673}
4178 4674
4179static int decode_delegreturn(struct xdr_stream *xdr) 4675static int decode_delegreturn(struct xdr_stream *xdr)
@@ -4187,6 +4683,7 @@ static int decode_exchange_id(struct xdr_stream *xdr,
4187{ 4683{
4188 __be32 *p; 4684 __be32 *p;
4189 uint32_t dummy; 4685 uint32_t dummy;
4686 char *dummy_str;
4190 int status; 4687 int status;
4191 struct nfs_client *clp = res->client; 4688 struct nfs_client *clp = res->client;
4192 4689
@@ -4194,36 +4691,45 @@ static int decode_exchange_id(struct xdr_stream *xdr,
4194 if (status) 4691 if (status)
4195 return status; 4692 return status;
4196 4693
4197 READ_BUF(8); 4694 p = xdr_inline_decode(xdr, 8);
4198 READ64(clp->cl_ex_clid); 4695 if (unlikely(!p))
4199 READ_BUF(12); 4696 goto out_overflow;
4200 READ32(clp->cl_seqid); 4697 xdr_decode_hyper(p, &clp->cl_ex_clid);
4201 READ32(clp->cl_exchange_flags); 4698 p = xdr_inline_decode(xdr, 12);
4699 if (unlikely(!p))
4700 goto out_overflow;
4701 clp->cl_seqid = be32_to_cpup(p++);
4702 clp->cl_exchange_flags = be32_to_cpup(p++);
4202 4703
4203 /* We ask for SP4_NONE */ 4704 /* We ask for SP4_NONE */
4204 READ32(dummy); 4705 dummy = be32_to_cpup(p);
4205 if (dummy != SP4_NONE) 4706 if (dummy != SP4_NONE)
4206 return -EIO; 4707 return -EIO;
4207 4708
4208 /* Throw away minor_id */ 4709 /* Throw away minor_id */
4209 READ_BUF(8); 4710 p = xdr_inline_decode(xdr, 8);
4711 if (unlikely(!p))
4712 goto out_overflow;
4210 4713
4211 /* Throw away Major id */ 4714 /* Throw away Major id */
4212 READ_BUF(4); 4715 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4213 READ32(dummy); 4716 if (unlikely(status))
4214 READ_BUF(dummy); 4717 return status;
4215 4718
4216 /* Throw away server_scope */ 4719 /* Throw away server_scope */
4217 READ_BUF(4); 4720 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4218 READ32(dummy); 4721 if (unlikely(status))
4219 READ_BUF(dummy); 4722 return status;
4220 4723
4221 /* Throw away Implementation id array */ 4724 /* Throw away Implementation id array */
4222 READ_BUF(4); 4725 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4223 READ32(dummy); 4726 if (unlikely(status))
4224 READ_BUF(dummy); 4727 return status;
4225 4728
4226 return 0; 4729 return 0;
4730out_overflow:
4731 print_overflow_msg(__func__, xdr);
4732 return -EIO;
4227} 4733}
4228 4734
4229static int decode_chan_attrs(struct xdr_stream *xdr, 4735static int decode_chan_attrs(struct xdr_stream *xdr,
@@ -4232,22 +4738,35 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
4232 __be32 *p; 4738 __be32 *p;
4233 u32 nr_attrs; 4739 u32 nr_attrs;
4234 4740
4235 READ_BUF(28); 4741 p = xdr_inline_decode(xdr, 28);
4236 READ32(attrs->headerpadsz); 4742 if (unlikely(!p))
4237 READ32(attrs->max_rqst_sz); 4743 goto out_overflow;
4238 READ32(attrs->max_resp_sz); 4744 attrs->headerpadsz = be32_to_cpup(p++);
4239 READ32(attrs->max_resp_sz_cached); 4745 attrs->max_rqst_sz = be32_to_cpup(p++);
4240 READ32(attrs->max_ops); 4746 attrs->max_resp_sz = be32_to_cpup(p++);
4241 READ32(attrs->max_reqs); 4747 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4242 READ32(nr_attrs); 4748 attrs->max_ops = be32_to_cpup(p++);
4749 attrs->max_reqs = be32_to_cpup(p++);
4750 nr_attrs = be32_to_cpup(p);
4243 if (unlikely(nr_attrs > 1)) { 4751 if (unlikely(nr_attrs > 1)) {
4244 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", 4752 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4245 __func__, nr_attrs); 4753 __func__, nr_attrs);
4246 return -EINVAL; 4754 return -EINVAL;
4247 } 4755 }
4248 if (nr_attrs == 1) 4756 if (nr_attrs == 1) {
4249 READ_BUF(4); /* skip rdma_attrs */ 4757 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4758 if (unlikely(!p))
4759 goto out_overflow;
4760 }
4250 return 0; 4761 return 0;
4762out_overflow:
4763 print_overflow_msg(__func__, xdr);
4764 return -EIO;
4765}
4766
4767static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4768{
4769 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
4251} 4770}
4252 4771
4253static int decode_create_session(struct xdr_stream *xdr, 4772static int decode_create_session(struct xdr_stream *xdr,
@@ -4259,30 +4778,37 @@ static int decode_create_session(struct xdr_stream *xdr,
4259 struct nfs4_session *session = clp->cl_session; 4778 struct nfs4_session *session = clp->cl_session;
4260 4779
4261 status = decode_op_hdr(xdr, OP_CREATE_SESSION); 4780 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4262 4781 if (!status)
4263 if (status) 4782 status = decode_sessionid(xdr, &session->sess_id);
4783 if (unlikely(status))
4264 return status; 4784 return status;
4265 4785
4266 /* sessionid */
4267 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4268 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4269
4270 /* seqid, flags */ 4786 /* seqid, flags */
4271 READ_BUF(8); 4787 p = xdr_inline_decode(xdr, 8);
4272 READ32(clp->cl_seqid); 4788 if (unlikely(!p))
4273 READ32(session->flags); 4789 goto out_overflow;
4790 clp->cl_seqid = be32_to_cpup(p++);
4791 session->flags = be32_to_cpup(p);
4274 4792
4275 /* Channel attributes */ 4793 /* Channel attributes */
4276 status = decode_chan_attrs(xdr, &session->fc_attrs); 4794 status = decode_chan_attrs(xdr, &session->fc_attrs);
4277 if (!status) 4795 if (!status)
4278 status = decode_chan_attrs(xdr, &session->bc_attrs); 4796 status = decode_chan_attrs(xdr, &session->bc_attrs);
4279 return status; 4797 return status;
4798out_overflow:
4799 print_overflow_msg(__func__, xdr);
4800 return -EIO;
4280} 4801}
4281 4802
4282static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 4803static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4283{ 4804{
4284 return decode_op_hdr(xdr, OP_DESTROY_SESSION); 4805 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4285} 4806}
4807
4808static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4809{
4810 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4811}
4286#endif /* CONFIG_NFS_V4_1 */ 4812#endif /* CONFIG_NFS_V4_1 */
4287 4813
4288static int decode_sequence(struct xdr_stream *xdr, 4814static int decode_sequence(struct xdr_stream *xdr,
@@ -4290,7 +4816,6 @@ static int decode_sequence(struct xdr_stream *xdr,
4290 struct rpc_rqst *rqstp) 4816 struct rpc_rqst *rqstp)
4291{ 4817{
4292#if defined(CONFIG_NFS_V4_1) 4818#if defined(CONFIG_NFS_V4_1)
4293 struct nfs4_slot *slot;
4294 struct nfs4_sessionid id; 4819 struct nfs4_sessionid id;
4295 u32 dummy; 4820 u32 dummy;
4296 int status; 4821 int status;
@@ -4300,50 +4825,186 @@ static int decode_sequence(struct xdr_stream *xdr,
4300 return 0; 4825 return 0;
4301 4826
4302 status = decode_op_hdr(xdr, OP_SEQUENCE); 4827 status = decode_op_hdr(xdr, OP_SEQUENCE);
4303 if (status) 4828 if (!status)
4829 status = decode_sessionid(xdr, &id);
4830 if (unlikely(status))
4304 goto out_err; 4831 goto out_err;
4305 4832
4306 /* 4833 /*
4307 * If the server returns different values for sessionID, slotID or 4834 * If the server returns different values for sessionID, slotID or
4308 * sequence number, the server is looney tunes. 4835 * sequence number, the server is looney tunes.
4309 */ 4836 */
4310 status = -ESERVERFAULT; 4837 status = -EREMOTEIO;
4311 4838
4312 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
4313 READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
4314 COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
4315 if (memcmp(id.data, res->sr_session->sess_id.data, 4839 if (memcmp(id.data, res->sr_session->sess_id.data,
4316 NFS4_MAX_SESSIONID_LEN)) { 4840 NFS4_MAX_SESSIONID_LEN)) {
4317 dprintk("%s Invalid session id\n", __func__); 4841 dprintk("%s Invalid session id\n", __func__);
4318 goto out_err; 4842 goto out_err;
4319 } 4843 }
4844
4845 p = xdr_inline_decode(xdr, 20);
4846 if (unlikely(!p))
4847 goto out_overflow;
4848
4320 /* seqid */ 4849 /* seqid */
4321 READ32(dummy); 4850 dummy = be32_to_cpup(p++);
4322 if (dummy != slot->seq_nr) { 4851 if (dummy != res->sr_slot->seq_nr) {
4323 dprintk("%s Invalid sequence number\n", __func__); 4852 dprintk("%s Invalid sequence number\n", __func__);
4324 goto out_err; 4853 goto out_err;
4325 } 4854 }
4326 /* slot id */ 4855 /* slot id */
4327 READ32(dummy); 4856 dummy = be32_to_cpup(p++);
4328 if (dummy != res->sr_slotid) { 4857 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
4329 dprintk("%s Invalid slot id\n", __func__); 4858 dprintk("%s Invalid slot id\n", __func__);
4330 goto out_err; 4859 goto out_err;
4331 } 4860 }
4332 /* highest slot id - currently not processed */ 4861 /* highest slot id - currently not processed */
4333 READ32(dummy); 4862 dummy = be32_to_cpup(p++);
4334 /* target highest slot id - currently not processed */ 4863 /* target highest slot id - currently not processed */
4335 READ32(dummy); 4864 dummy = be32_to_cpup(p++);
4336 /* result flags - currently not processed */ 4865 /* result flags */
4337 READ32(dummy); 4866 res->sr_status_flags = be32_to_cpup(p);
4338 status = 0; 4867 status = 0;
4339out_err: 4868out_err:
4340 res->sr_status = status; 4869 res->sr_status = status;
4341 return status; 4870 return status;
4871out_overflow:
4872 print_overflow_msg(__func__, xdr);
4873 status = -EIO;
4874 goto out_err;
4342#else /* CONFIG_NFS_V4_1 */ 4875#else /* CONFIG_NFS_V4_1 */
4343 return 0; 4876 return 0;
4344#endif /* CONFIG_NFS_V4_1 */ 4877#endif /* CONFIG_NFS_V4_1 */
4345} 4878}
4346 4879
4880#if defined(CONFIG_NFS_V4_1)
4881
4882static int decode_getdeviceinfo(struct xdr_stream *xdr,
4883 struct pnfs_device *pdev)
4884{
4885 __be32 *p;
4886 uint32_t len, type;
4887 int status;
4888
4889 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4890 if (status) {
4891 if (status == -ETOOSMALL) {
4892 p = xdr_inline_decode(xdr, 4);
4893 if (unlikely(!p))
4894 goto out_overflow;
4895 pdev->mincount = be32_to_cpup(p);
4896 dprintk("%s: Min count too small. mincnt = %u\n",
4897 __func__, pdev->mincount);
4898 }
4899 return status;
4900 }
4901
4902 p = xdr_inline_decode(xdr, 8);
4903 if (unlikely(!p))
4904 goto out_overflow;
4905 type = be32_to_cpup(p++);
4906 if (type != pdev->layout_type) {
4907 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4908 __func__, pdev->layout_type, type);
4909 return -EINVAL;
4910 }
4911 /*
4912 * Get the length of the opaque device_addr4. xdr_read_pages places
4913 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4914 * and places the remaining xdr data in xdr_buf->tail
4915 */
4916 pdev->mincount = be32_to_cpup(p);
4917 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4918
4919 /* Parse notification bitmap, verifying that it is zero. */
4920 p = xdr_inline_decode(xdr, 4);
4921 if (unlikely(!p))
4922 goto out_overflow;
4923 len = be32_to_cpup(p);
4924 if (len) {
4925 uint32_t i;
4926
4927 p = xdr_inline_decode(xdr, 4 * len);
4928 if (unlikely(!p))
4929 goto out_overflow;
4930 for (i = 0; i < len; i++, p++) {
4931 if (be32_to_cpup(p)) {
4932 dprintk("%s: notifications not supported\n",
4933 __func__);
4934 return -EIO;
4935 }
4936 }
4937 }
4938 return 0;
4939out_overflow:
4940 print_overflow_msg(__func__, xdr);
4941 return -EIO;
4942}
4943
4944static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
4945 struct nfs4_layoutget_res *res)
4946{
4947 __be32 *p;
4948 int status;
4949 u32 layout_count;
4950
4951 status = decode_op_hdr(xdr, OP_LAYOUTGET);
4952 if (status)
4953 return status;
4954 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
4955 if (unlikely(!p))
4956 goto out_overflow;
4957 res->return_on_close = be32_to_cpup(p++);
4958 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
4959 layout_count = be32_to_cpup(p);
4960 if (!layout_count) {
4961 dprintk("%s: server responded with empty layout array\n",
4962 __func__);
4963 return -EINVAL;
4964 }
4965
4966 p = xdr_inline_decode(xdr, 24);
4967 if (unlikely(!p))
4968 goto out_overflow;
4969 p = xdr_decode_hyper(p, &res->range.offset);
4970 p = xdr_decode_hyper(p, &res->range.length);
4971 res->range.iomode = be32_to_cpup(p++);
4972 res->type = be32_to_cpup(p++);
4973
4974 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
4975 if (unlikely(status))
4976 return status;
4977
4978 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
4979 __func__,
4980 (unsigned long)res->range.offset,
4981 (unsigned long)res->range.length,
4982 res->range.iomode,
4983 res->type,
4984 res->layout.len);
4985
4986 /* nfs4_proc_layoutget allocated a single page */
4987 if (res->layout.len > PAGE_SIZE)
4988 return -ENOMEM;
4989 memcpy(res->layout.buf, p, res->layout.len);
4990
4991 if (layout_count > 1) {
4992 /* We only handle a length one array at the moment. Any
4993 * further entries are just ignored. Note that this means
4994 * the client may see a response that is less than the
4995 * minimum it requested.
4996 */
4997 dprintk("%s: server responded with %d layouts, dropping tail\n",
4998 __func__, layout_count);
4999 }
5000
5001 return 0;
5002out_overflow:
5003 print_overflow_msg(__func__, xdr);
5004 return -EIO;
5005}
5006#endif /* CONFIG_NFS_V4_1 */
5007
4347/* 5008/*
4348 * END OF "GENERIC" DECODE ROUTINES. 5009 * END OF "GENERIC" DECODE ROUTINES.
4349 */ 5010 */
@@ -4351,26 +5012,27 @@ out_err:
4351/* 5012/*
4352 * Decode OPEN_DOWNGRADE response 5013 * Decode OPEN_DOWNGRADE response
4353 */ 5014 */
4354static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) 5015static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5016 struct xdr_stream *xdr,
5017 struct nfs_closeres *res)
4355{ 5018{
4356 struct xdr_stream xdr;
4357 struct compound_hdr hdr; 5019 struct compound_hdr hdr;
4358 int status; 5020 int status;
4359 5021
4360 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5022 status = decode_compound_hdr(xdr, &hdr);
4361 status = decode_compound_hdr(&xdr, &hdr);
4362 if (status) 5023 if (status)
4363 goto out; 5024 goto out;
4364 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5025 status = decode_sequence(xdr, &res->seq_res, rqstp);
4365 if (status) 5026 if (status)
4366 goto out; 5027 goto out;
4367 status = decode_putfh(&xdr); 5028 status = decode_putfh(xdr);
4368 if (status) 5029 if (status)
4369 goto out; 5030 goto out;
4370 status = decode_open_downgrade(&xdr, res); 5031 status = decode_open_downgrade(xdr, res);
4371 if (status != 0) 5032 if (status != 0)
4372 goto out; 5033 goto out;
4373 decode_getfattr(&xdr, res->fattr, res->server); 5034 decode_getfattr(xdr, res->fattr, res->server,
5035 !RPC_IS_ASYNC(rqstp->rq_task));
4374out: 5036out:
4375 return status; 5037 return status;
4376} 5038}
@@ -4378,26 +5040,26 @@ out:
4378/* 5040/*
4379 * Decode ACCESS response 5041 * Decode ACCESS response
4380 */ 5042 */
4381static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res) 5043static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5044 struct nfs4_accessres *res)
4382{ 5045{
4383 struct xdr_stream xdr;
4384 struct compound_hdr hdr; 5046 struct compound_hdr hdr;
4385 int status; 5047 int status;
4386 5048
4387 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5049 status = decode_compound_hdr(xdr, &hdr);
4388 status = decode_compound_hdr(&xdr, &hdr);
4389 if (status) 5050 if (status)
4390 goto out; 5051 goto out;
4391 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5052 status = decode_sequence(xdr, &res->seq_res, rqstp);
4392 if (status) 5053 if (status)
4393 goto out; 5054 goto out;
4394 status = decode_putfh(&xdr); 5055 status = decode_putfh(xdr);
4395 if (status != 0) 5056 if (status != 0)
4396 goto out; 5057 goto out;
4397 status = decode_access(&xdr, res); 5058 status = decode_access(xdr, res);
4398 if (status != 0) 5059 if (status != 0)
4399 goto out; 5060 goto out;
4400 decode_getfattr(&xdr, res->fattr, res->server); 5061 decode_getfattr(xdr, res->fattr, res->server,
5062 !RPC_IS_ASYNC(rqstp->rq_task));
4401out: 5063out:
4402 return status; 5064 return status;
4403} 5065}
@@ -4405,26 +5067,29 @@ out:
4405/* 5067/*
4406 * Decode LOOKUP response 5068 * Decode LOOKUP response
4407 */ 5069 */
4408static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) 5070static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5071 struct nfs4_lookup_res *res)
4409{ 5072{
4410 struct xdr_stream xdr;
4411 struct compound_hdr hdr; 5073 struct compound_hdr hdr;
4412 int status; 5074 int status;
4413 5075
4414 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5076 status = decode_compound_hdr(xdr, &hdr);
4415 status = decode_compound_hdr(&xdr, &hdr);
4416 if (status) 5077 if (status)
4417 goto out; 5078 goto out;
4418 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5079 status = decode_sequence(xdr, &res->seq_res, rqstp);
4419 if (status) 5080 if (status)
4420 goto out; 5081 goto out;
4421 if ((status = decode_putfh(&xdr)) != 0) 5082 status = decode_putfh(xdr);
5083 if (status)
4422 goto out; 5084 goto out;
4423 if ((status = decode_lookup(&xdr)) != 0) 5085 status = decode_lookup(xdr);
5086 if (status)
4424 goto out; 5087 goto out;
4425 if ((status = decode_getfh(&xdr, res->fh)) != 0) 5088 status = decode_getfh(xdr, res->fh);
5089 if (status)
4426 goto out; 5090 goto out;
4427 status = decode_getfattr(&xdr, res->fattr, res->server); 5091 status = decode_getfattr(xdr, res->fattr, res->server
5092 ,!RPC_IS_ASYNC(rqstp->rq_task));
4428out: 5093out:
4429 return status; 5094 return status;
4430} 5095}
@@ -4432,23 +5097,26 @@ out:
4432/* 5097/*
4433 * Decode LOOKUP_ROOT response 5098 * Decode LOOKUP_ROOT response
4434 */ 5099 */
4435static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) 5100static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5101 struct xdr_stream *xdr,
5102 struct nfs4_lookup_res *res)
4436{ 5103{
4437 struct xdr_stream xdr;
4438 struct compound_hdr hdr; 5104 struct compound_hdr hdr;
4439 int status; 5105 int status;
4440 5106
4441 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5107 status = decode_compound_hdr(xdr, &hdr);
4442 status = decode_compound_hdr(&xdr, &hdr);
4443 if (status) 5108 if (status)
4444 goto out; 5109 goto out;
4445 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5110 status = decode_sequence(xdr, &res->seq_res, rqstp);
4446 if (status) 5111 if (status)
4447 goto out; 5112 goto out;
4448 if ((status = decode_putrootfh(&xdr)) != 0) 5113 status = decode_putrootfh(xdr);
5114 if (status)
4449 goto out; 5115 goto out;
4450 if ((status = decode_getfh(&xdr, res->fh)) == 0) 5116 status = decode_getfh(xdr, res->fh);
4451 status = decode_getfattr(&xdr, res->fattr, res->server); 5117 if (status == 0)
5118 status = decode_getfattr(xdr, res->fattr, res->server,
5119 !RPC_IS_ASYNC(rqstp->rq_task));
4452out: 5120out:
4453 return status; 5121 return status;
4454} 5122}
@@ -4456,24 +5124,26 @@ out:
4456/* 5124/*
4457 * Decode REMOVE response 5125 * Decode REMOVE response
4458 */ 5126 */
4459static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res) 5127static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5128 struct nfs_removeres *res)
4460{ 5129{
4461 struct xdr_stream xdr;
4462 struct compound_hdr hdr; 5130 struct compound_hdr hdr;
4463 int status; 5131 int status;
4464 5132
4465 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5133 status = decode_compound_hdr(xdr, &hdr);
4466 status = decode_compound_hdr(&xdr, &hdr);
4467 if (status) 5134 if (status)
4468 goto out; 5135 goto out;
4469 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5136 status = decode_sequence(xdr, &res->seq_res, rqstp);
4470 if (status) 5137 if (status)
4471 goto out; 5138 goto out;
4472 if ((status = decode_putfh(&xdr)) != 0) 5139 status = decode_putfh(xdr);
5140 if (status)
4473 goto out; 5141 goto out;
4474 if ((status = decode_remove(&xdr, &res->cinfo)) != 0) 5142 status = decode_remove(xdr, &res->cinfo);
5143 if (status)
4475 goto out; 5144 goto out;
4476 decode_getfattr(&xdr, &res->dir_attr, res->server); 5145 decode_getfattr(xdr, res->dir_attr, res->server,
5146 !RPC_IS_ASYNC(rqstp->rq_task));
4477out: 5147out:
4478 return status; 5148 return status;
4479} 5149}
@@ -4481,33 +5151,39 @@ out:
4481/* 5151/*
4482 * Decode RENAME response 5152 * Decode RENAME response
4483 */ 5153 */
4484static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res) 5154static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5155 struct nfs_renameres *res)
4485{ 5156{
4486 struct xdr_stream xdr;
4487 struct compound_hdr hdr; 5157 struct compound_hdr hdr;
4488 int status; 5158 int status;
4489 5159
4490 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5160 status = decode_compound_hdr(xdr, &hdr);
4491 status = decode_compound_hdr(&xdr, &hdr);
4492 if (status) 5161 if (status)
4493 goto out; 5162 goto out;
4494 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5163 status = decode_sequence(xdr, &res->seq_res, rqstp);
4495 if (status) 5164 if (status)
4496 goto out; 5165 goto out;
4497 if ((status = decode_putfh(&xdr)) != 0) 5166 status = decode_putfh(xdr);
5167 if (status)
4498 goto out; 5168 goto out;
4499 if ((status = decode_savefh(&xdr)) != 0) 5169 status = decode_savefh(xdr);
5170 if (status)
4500 goto out; 5171 goto out;
4501 if ((status = decode_putfh(&xdr)) != 0) 5172 status = decode_putfh(xdr);
5173 if (status)
4502 goto out; 5174 goto out;
4503 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) 5175 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5176 if (status)
4504 goto out; 5177 goto out;
4505 /* Current FH is target directory */ 5178 /* Current FH is target directory */
4506 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0) 5179 if (decode_getfattr(xdr, res->new_fattr, res->server,
5180 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4507 goto out; 5181 goto out;
4508 if ((status = decode_restorefh(&xdr)) != 0) 5182 status = decode_restorefh(xdr);
5183 if (status)
4509 goto out; 5184 goto out;
4510 decode_getfattr(&xdr, res->old_fattr, res->server); 5185 decode_getfattr(xdr, res->old_fattr, res->server,
5186 !RPC_IS_ASYNC(rqstp->rq_task));
4511out: 5187out:
4512 return status; 5188 return status;
4513} 5189}
@@ -4515,36 +5191,42 @@ out:
4515/* 5191/*
4516 * Decode LINK response 5192 * Decode LINK response
4517 */ 5193 */
4518static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res) 5194static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5195 struct nfs4_link_res *res)
4519{ 5196{
4520 struct xdr_stream xdr;
4521 struct compound_hdr hdr; 5197 struct compound_hdr hdr;
4522 int status; 5198 int status;
4523 5199
4524 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5200 status = decode_compound_hdr(xdr, &hdr);
4525 status = decode_compound_hdr(&xdr, &hdr);
4526 if (status) 5201 if (status)
4527 goto out; 5202 goto out;
4528 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5203 status = decode_sequence(xdr, &res->seq_res, rqstp);
4529 if (status) 5204 if (status)
4530 goto out; 5205 goto out;
4531 if ((status = decode_putfh(&xdr)) != 0) 5206 status = decode_putfh(xdr);
5207 if (status)
4532 goto out; 5208 goto out;
4533 if ((status = decode_savefh(&xdr)) != 0) 5209 status = decode_savefh(xdr);
5210 if (status)
4534 goto out; 5211 goto out;
4535 if ((status = decode_putfh(&xdr)) != 0) 5212 status = decode_putfh(xdr);
5213 if (status)
4536 goto out; 5214 goto out;
4537 if ((status = decode_link(&xdr, &res->cinfo)) != 0) 5215 status = decode_link(xdr, &res->cinfo);
5216 if (status)
4538 goto out; 5217 goto out;
4539 /* 5218 /*
4540 * Note order: OP_LINK leaves the directory as the current 5219 * Note order: OP_LINK leaves the directory as the current
4541 * filehandle. 5220 * filehandle.
4542 */ 5221 */
4543 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0) 5222 if (decode_getfattr(xdr, res->dir_attr, res->server,
5223 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4544 goto out; 5224 goto out;
4545 if ((status = decode_restorefh(&xdr)) != 0) 5225 status = decode_restorefh(xdr);
5226 if (status)
4546 goto out; 5227 goto out;
4547 decode_getfattr(&xdr, res->fattr, res->server); 5228 decode_getfattr(xdr, res->fattr, res->server,
5229 !RPC_IS_ASYNC(rqstp->rq_task));
4548out: 5230out:
4549 return status; 5231 return status;
4550} 5232}
@@ -4552,32 +5234,38 @@ out:
4552/* 5234/*
4553 * Decode CREATE response 5235 * Decode CREATE response
4554 */ 5236 */
4555static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) 5237static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5238 struct nfs4_create_res *res)
4556{ 5239{
4557 struct xdr_stream xdr;
4558 struct compound_hdr hdr; 5240 struct compound_hdr hdr;
4559 int status; 5241 int status;
4560 5242
4561 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5243 status = decode_compound_hdr(xdr, &hdr);
4562 status = decode_compound_hdr(&xdr, &hdr);
4563 if (status) 5244 if (status)
4564 goto out; 5245 goto out;
4565 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5246 status = decode_sequence(xdr, &res->seq_res, rqstp);
4566 if (status) 5247 if (status)
4567 goto out; 5248 goto out;
4568 if ((status = decode_putfh(&xdr)) != 0) 5249 status = decode_putfh(xdr);
5250 if (status)
4569 goto out; 5251 goto out;
4570 if ((status = decode_savefh(&xdr)) != 0) 5252 status = decode_savefh(xdr);
5253 if (status)
4571 goto out; 5254 goto out;
4572 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) 5255 status = decode_create(xdr, &res->dir_cinfo);
5256 if (status)
4573 goto out; 5257 goto out;
4574 if ((status = decode_getfh(&xdr, res->fh)) != 0) 5258 status = decode_getfh(xdr, res->fh);
5259 if (status)
4575 goto out; 5260 goto out;
4576 if (decode_getfattr(&xdr, res->fattr, res->server) != 0) 5261 if (decode_getfattr(xdr, res->fattr, res->server,
5262 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4577 goto out; 5263 goto out;
4578 if ((status = decode_restorefh(&xdr)) != 0) 5264 status = decode_restorefh(xdr);
5265 if (status)
4579 goto out; 5266 goto out;
4580 decode_getfattr(&xdr, res->dir_fattr, res->server); 5267 decode_getfattr(xdr, res->dir_fattr, res->server,
5268 !RPC_IS_ASYNC(rqstp->rq_task));
4581out: 5269out:
4582 return status; 5270 return status;
4583} 5271}
@@ -4585,31 +5273,32 @@ out:
4585/* 5273/*
4586 * Decode SYMLINK response 5274 * Decode SYMLINK response
4587 */ 5275 */
4588static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) 5276static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5277 struct nfs4_create_res *res)
4589{ 5278{
4590 return nfs4_xdr_dec_create(rqstp, p, res); 5279 return nfs4_xdr_dec_create(rqstp, xdr, res);
4591} 5280}
4592 5281
4593/* 5282/*
4594 * Decode GETATTR response 5283 * Decode GETATTR response
4595 */ 5284 */
4596static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res) 5285static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5286 struct nfs4_getattr_res *res)
4597{ 5287{
4598 struct xdr_stream xdr;
4599 struct compound_hdr hdr; 5288 struct compound_hdr hdr;
4600 int status; 5289 int status;
4601 5290
4602 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5291 status = decode_compound_hdr(xdr, &hdr);
4603 status = decode_compound_hdr(&xdr, &hdr);
4604 if (status) 5292 if (status)
4605 goto out; 5293 goto out;
4606 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5294 status = decode_sequence(xdr, &res->seq_res, rqstp);
4607 if (status) 5295 if (status)
4608 goto out; 5296 goto out;
4609 status = decode_putfh(&xdr); 5297 status = decode_putfh(xdr);
4610 if (status) 5298 if (status)
4611 goto out; 5299 goto out;
4612 status = decode_getfattr(&xdr, res->fattr, res->server); 5300 status = decode_getfattr(xdr, res->fattr, res->server,
5301 !RPC_IS_ASYNC(rqstp->rq_task));
4613out: 5302out:
4614 return status; 5303 return status;
4615} 5304}
@@ -4617,46 +5306,40 @@ out:
4617/* 5306/*
4618 * Encode an SETACL request 5307 * Encode an SETACL request
4619 */ 5308 */
4620static int 5309static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
4621nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args) 5310 struct nfs_setaclargs *args)
4622{ 5311{
4623 struct xdr_stream xdr;
4624 struct compound_hdr hdr = { 5312 struct compound_hdr hdr = {
4625 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 5313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
4626 }; 5314 };
4627 int status;
4628 5315
4629 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 5316 encode_compound_hdr(xdr, req, &hdr);
4630 encode_compound_hdr(&xdr, req, &hdr); 5317 encode_sequence(xdr, &args->seq_args, &hdr);
4631 encode_sequence(&xdr, &args->seq_args, &hdr); 5318 encode_putfh(xdr, args->fh, &hdr);
4632 encode_putfh(&xdr, args->fh, &hdr); 5319 encode_setacl(xdr, args, &hdr);
4633 status = encode_setacl(&xdr, args, &hdr);
4634 encode_nops(&hdr); 5320 encode_nops(&hdr);
4635 return status;
4636} 5321}
4637 5322
4638/* 5323/*
4639 * Decode SETACL response 5324 * Decode SETACL response
4640 */ 5325 */
4641static int 5326static int
4642nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, 5327nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
4643 struct nfs_setaclres *res) 5328 struct nfs_setaclres *res)
4644{ 5329{
4645 struct xdr_stream xdr;
4646 struct compound_hdr hdr; 5330 struct compound_hdr hdr;
4647 int status; 5331 int status;
4648 5332
4649 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5333 status = decode_compound_hdr(xdr, &hdr);
4650 status = decode_compound_hdr(&xdr, &hdr);
4651 if (status) 5334 if (status)
4652 goto out; 5335 goto out;
4653 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5336 status = decode_sequence(xdr, &res->seq_res, rqstp);
4654 if (status) 5337 if (status)
4655 goto out; 5338 goto out;
4656 status = decode_putfh(&xdr); 5339 status = decode_putfh(xdr);
4657 if (status) 5340 if (status)
4658 goto out; 5341 goto out;
4659 status = decode_setattr(&xdr); 5342 status = decode_setattr(xdr);
4660out: 5343out:
4661 return status; 5344 return status;
4662} 5345}
@@ -4665,24 +5348,22 @@ out:
4665 * Decode GETACL response 5348 * Decode GETACL response
4666 */ 5349 */
4667static int 5350static int
4668nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, 5351nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
4669 struct nfs_getaclres *res) 5352 struct nfs_getaclres *res)
4670{ 5353{
4671 struct xdr_stream xdr;
4672 struct compound_hdr hdr; 5354 struct compound_hdr hdr;
4673 int status; 5355 int status;
4674 5356
4675 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5357 status = decode_compound_hdr(xdr, &hdr);
4676 status = decode_compound_hdr(&xdr, &hdr);
4677 if (status) 5358 if (status)
4678 goto out; 5359 goto out;
4679 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5360 status = decode_sequence(xdr, &res->seq_res, rqstp);
4680 if (status) 5361 if (status)
4681 goto out; 5362 goto out;
4682 status = decode_putfh(&xdr); 5363 status = decode_putfh(xdr);
4683 if (status) 5364 if (status)
4684 goto out; 5365 goto out;
4685 status = decode_getacl(&xdr, rqstp, &res->acl_len); 5366 status = decode_getacl(xdr, rqstp, &res->acl_len);
4686 5367
4687out: 5368out:
4688 return status; 5369 return status;
@@ -4691,23 +5372,22 @@ out:
4691/* 5372/*
4692 * Decode CLOSE response 5373 * Decode CLOSE response
4693 */ 5374 */
4694static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) 5375static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5376 struct nfs_closeres *res)
4695{ 5377{
4696 struct xdr_stream xdr;
4697 struct compound_hdr hdr; 5378 struct compound_hdr hdr;
4698 int status; 5379 int status;
4699 5380
4700 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5381 status = decode_compound_hdr(xdr, &hdr);
4701 status = decode_compound_hdr(&xdr, &hdr);
4702 if (status) 5382 if (status)
4703 goto out; 5383 goto out;
4704 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5384 status = decode_sequence(xdr, &res->seq_res, rqstp);
4705 if (status) 5385 if (status)
4706 goto out; 5386 goto out;
4707 status = decode_putfh(&xdr); 5387 status = decode_putfh(xdr);
4708 if (status) 5388 if (status)
4709 goto out; 5389 goto out;
4710 status = decode_close(&xdr, res); 5390 status = decode_close(xdr, res);
4711 if (status != 0) 5391 if (status != 0)
4712 goto out; 5392 goto out;
4713 /* 5393 /*
@@ -4716,7 +5396,8 @@ static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_clos
4716 * an ESTALE error. Shouldn't be a problem, 5396 * an ESTALE error. Shouldn't be a problem,
4717 * though, since fattr->valid will remain unset. 5397 * though, since fattr->valid will remain unset.
4718 */ 5398 */
4719 decode_getfattr(&xdr, res->fattr, res->server); 5399 decode_getfattr(xdr, res->fattr, res->server,
5400 !RPC_IS_ASYNC(rqstp->rq_task));
4720out: 5401out:
4721 return status; 5402 return status;
4722} 5403}
@@ -4724,35 +5405,36 @@ out:
4724/* 5405/*
4725 * Decode OPEN response 5406 * Decode OPEN response
4726 */ 5407 */
4727static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) 5408static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5409 struct nfs_openres *res)
4728{ 5410{
4729 struct xdr_stream xdr;
4730 struct compound_hdr hdr; 5411 struct compound_hdr hdr;
4731 int status; 5412 int status;
4732 5413
4733 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5414 status = decode_compound_hdr(xdr, &hdr);
4734 status = decode_compound_hdr(&xdr, &hdr);
4735 if (status) 5415 if (status)
4736 goto out; 5416 goto out;
4737 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5417 status = decode_sequence(xdr, &res->seq_res, rqstp);
4738 if (status) 5418 if (status)
4739 goto out; 5419 goto out;
4740 status = decode_putfh(&xdr); 5420 status = decode_putfh(xdr);
4741 if (status) 5421 if (status)
4742 goto out; 5422 goto out;
4743 status = decode_savefh(&xdr); 5423 status = decode_savefh(xdr);
4744 if (status) 5424 if (status)
4745 goto out; 5425 goto out;
4746 status = decode_open(&xdr, res); 5426 status = decode_open(xdr, res);
4747 if (status) 5427 if (status)
4748 goto out; 5428 goto out;
4749 if (decode_getfh(&xdr, &res->fh) != 0) 5429 if (decode_getfh(xdr, &res->fh) != 0)
4750 goto out; 5430 goto out;
4751 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0) 5431 if (decode_getfattr(xdr, res->f_attr, res->server,
5432 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4752 goto out; 5433 goto out;
4753 if (decode_restorefh(&xdr) != 0) 5434 if (decode_restorefh(xdr) != 0)
4754 goto out; 5435 goto out;
4755 decode_getfattr(&xdr, res->dir_attr, res->server); 5436 decode_getfattr(xdr, res->dir_attr, res->server,
5437 !RPC_IS_ASYNC(rqstp->rq_task));
4756out: 5438out:
4757 return status; 5439 return status;
4758} 5440}
@@ -4760,20 +5442,20 @@ out:
4760/* 5442/*
4761 * Decode OPEN_CONFIRM response 5443 * Decode OPEN_CONFIRM response
4762 */ 5444 */
4763static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res) 5445static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5446 struct xdr_stream *xdr,
5447 struct nfs_open_confirmres *res)
4764{ 5448{
4765 struct xdr_stream xdr;
4766 struct compound_hdr hdr; 5449 struct compound_hdr hdr;
4767 int status; 5450 int status;
4768 5451
4769 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5452 status = decode_compound_hdr(xdr, &hdr);
4770 status = decode_compound_hdr(&xdr, &hdr);
4771 if (status) 5453 if (status)
4772 goto out; 5454 goto out;
4773 status = decode_putfh(&xdr); 5455 status = decode_putfh(xdr);
4774 if (status) 5456 if (status)
4775 goto out; 5457 goto out;
4776 status = decode_open_confirm(&xdr, res); 5458 status = decode_open_confirm(xdr, res);
4777out: 5459out:
4778 return status; 5460 return status;
4779} 5461}
@@ -4781,26 +5463,27 @@ out:
4781/* 5463/*
4782 * Decode OPEN response 5464 * Decode OPEN response
4783 */ 5465 */
4784static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) 5466static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5467 struct xdr_stream *xdr,
5468 struct nfs_openres *res)
4785{ 5469{
4786 struct xdr_stream xdr;
4787 struct compound_hdr hdr; 5470 struct compound_hdr hdr;
4788 int status; 5471 int status;
4789 5472
4790 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5473 status = decode_compound_hdr(xdr, &hdr);
4791 status = decode_compound_hdr(&xdr, &hdr);
4792 if (status) 5474 if (status)
4793 goto out; 5475 goto out;
4794 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5476 status = decode_sequence(xdr, &res->seq_res, rqstp);
4795 if (status) 5477 if (status)
4796 goto out; 5478 goto out;
4797 status = decode_putfh(&xdr); 5479 status = decode_putfh(xdr);
4798 if (status) 5480 if (status)
4799 goto out; 5481 goto out;
4800 status = decode_open(&xdr, res); 5482 status = decode_open(xdr, res);
4801 if (status) 5483 if (status)
4802 goto out; 5484 goto out;
4803 decode_getfattr(&xdr, res->f_attr, res->server); 5485 decode_getfattr(xdr, res->f_attr, res->server,
5486 !RPC_IS_ASYNC(rqstp->rq_task));
4804out: 5487out:
4805 return status; 5488 return status;
4806} 5489}
@@ -4808,26 +5491,27 @@ out:
4808/* 5491/*
4809 * Decode SETATTR response 5492 * Decode SETATTR response
4810 */ 5493 */
4811static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res) 5494static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5495 struct xdr_stream *xdr,
5496 struct nfs_setattrres *res)
4812{ 5497{
4813 struct xdr_stream xdr;
4814 struct compound_hdr hdr; 5498 struct compound_hdr hdr;
4815 int status; 5499 int status;
4816 5500
4817 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5501 status = decode_compound_hdr(xdr, &hdr);
4818 status = decode_compound_hdr(&xdr, &hdr);
4819 if (status) 5502 if (status)
4820 goto out; 5503 goto out;
4821 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5504 status = decode_sequence(xdr, &res->seq_res, rqstp);
4822 if (status) 5505 if (status)
4823 goto out; 5506 goto out;
4824 status = decode_putfh(&xdr); 5507 status = decode_putfh(xdr);
4825 if (status) 5508 if (status)
4826 goto out; 5509 goto out;
4827 status = decode_setattr(&xdr); 5510 status = decode_setattr(xdr);
4828 if (status) 5511 if (status)
4829 goto out; 5512 goto out;
4830 decode_getfattr(&xdr, res->fattr, res->server); 5513 decode_getfattr(xdr, res->fattr, res->server,
5514 !RPC_IS_ASYNC(rqstp->rq_task));
4831out: 5515out:
4832 return status; 5516 return status;
4833} 5517}
@@ -4835,23 +5519,22 @@ out:
4835/* 5519/*
4836 * Decode LOCK response 5520 * Decode LOCK response
4837 */ 5521 */
4838static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res) 5522static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5523 struct nfs_lock_res *res)
4839{ 5524{
4840 struct xdr_stream xdr;
4841 struct compound_hdr hdr; 5525 struct compound_hdr hdr;
4842 int status; 5526 int status;
4843 5527
4844 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5528 status = decode_compound_hdr(xdr, &hdr);
4845 status = decode_compound_hdr(&xdr, &hdr);
4846 if (status) 5529 if (status)
4847 goto out; 5530 goto out;
4848 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5531 status = decode_sequence(xdr, &res->seq_res, rqstp);
4849 if (status) 5532 if (status)
4850 goto out; 5533 goto out;
4851 status = decode_putfh(&xdr); 5534 status = decode_putfh(xdr);
4852 if (status) 5535 if (status)
4853 goto out; 5536 goto out;
4854 status = decode_lock(&xdr, res); 5537 status = decode_lock(xdr, res);
4855out: 5538out:
4856 return status; 5539 return status;
4857} 5540}
@@ -4859,23 +5542,22 @@ out:
4859/* 5542/*
4860 * Decode LOCKT response 5543 * Decode LOCKT response
4861 */ 5544 */
4862static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res) 5545static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5546 struct nfs_lockt_res *res)
4863{ 5547{
4864 struct xdr_stream xdr;
4865 struct compound_hdr hdr; 5548 struct compound_hdr hdr;
4866 int status; 5549 int status;
4867 5550
4868 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5551 status = decode_compound_hdr(xdr, &hdr);
4869 status = decode_compound_hdr(&xdr, &hdr);
4870 if (status) 5552 if (status)
4871 goto out; 5553 goto out;
4872 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5554 status = decode_sequence(xdr, &res->seq_res, rqstp);
4873 if (status) 5555 if (status)
4874 goto out; 5556 goto out;
4875 status = decode_putfh(&xdr); 5557 status = decode_putfh(xdr);
4876 if (status) 5558 if (status)
4877 goto out; 5559 goto out;
4878 status = decode_lockt(&xdr, res); 5560 status = decode_lockt(xdr, res);
4879out: 5561out:
4880 return status; 5562 return status;
4881} 5563}
@@ -4883,48 +5565,58 @@ out:
4883/* 5565/*
4884 * Decode LOCKU response 5566 * Decode LOCKU response
4885 */ 5567 */
4886static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res) 5568static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5569 struct nfs_locku_res *res)
4887{ 5570{
4888 struct xdr_stream xdr;
4889 struct compound_hdr hdr; 5571 struct compound_hdr hdr;
4890 int status; 5572 int status;
4891 5573
4892 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5574 status = decode_compound_hdr(xdr, &hdr);
4893 status = decode_compound_hdr(&xdr, &hdr);
4894 if (status) 5575 if (status)
4895 goto out; 5576 goto out;
4896 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5577 status = decode_sequence(xdr, &res->seq_res, rqstp);
4897 if (status) 5578 if (status)
4898 goto out; 5579 goto out;
4899 status = decode_putfh(&xdr); 5580 status = decode_putfh(xdr);
4900 if (status) 5581 if (status)
4901 goto out; 5582 goto out;
4902 status = decode_locku(&xdr, res); 5583 status = decode_locku(xdr, res);
4903out: 5584out:
4904 return status; 5585 return status;
4905} 5586}
4906 5587
5588static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5589 struct xdr_stream *xdr, void *dummy)
5590{
5591 struct compound_hdr hdr;
5592 int status;
5593
5594 status = decode_compound_hdr(xdr, &hdr);
5595 if (!status)
5596 status = decode_release_lockowner(xdr);
5597 return status;
5598}
5599
4907/* 5600/*
4908 * Decode READLINK response 5601 * Decode READLINK response
4909 */ 5602 */
4910static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, 5603static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5604 struct xdr_stream *xdr,
4911 struct nfs4_readlink_res *res) 5605 struct nfs4_readlink_res *res)
4912{ 5606{
4913 struct xdr_stream xdr;
4914 struct compound_hdr hdr; 5607 struct compound_hdr hdr;
4915 int status; 5608 int status;
4916 5609
4917 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5610 status = decode_compound_hdr(xdr, &hdr);
4918 status = decode_compound_hdr(&xdr, &hdr);
4919 if (status) 5611 if (status)
4920 goto out; 5612 goto out;
4921 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5613 status = decode_sequence(xdr, &res->seq_res, rqstp);
4922 if (status) 5614 if (status)
4923 goto out; 5615 goto out;
4924 status = decode_putfh(&xdr); 5616 status = decode_putfh(xdr);
4925 if (status) 5617 if (status)
4926 goto out; 5618 goto out;
4927 status = decode_readlink(&xdr, rqstp); 5619 status = decode_readlink(xdr, rqstp);
4928out: 5620out:
4929 return status; 5621 return status;
4930} 5622}
@@ -4932,23 +5624,22 @@ out:
4932/* 5624/*
4933 * Decode READDIR response 5625 * Decode READDIR response
4934 */ 5626 */
4935static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res) 5627static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5628 struct nfs4_readdir_res *res)
4936{ 5629{
4937 struct xdr_stream xdr;
4938 struct compound_hdr hdr; 5630 struct compound_hdr hdr;
4939 int status; 5631 int status;
4940 5632
4941 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5633 status = decode_compound_hdr(xdr, &hdr);
4942 status = decode_compound_hdr(&xdr, &hdr);
4943 if (status) 5634 if (status)
4944 goto out; 5635 goto out;
4945 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5636 status = decode_sequence(xdr, &res->seq_res, rqstp);
4946 if (status) 5637 if (status)
4947 goto out; 5638 goto out;
4948 status = decode_putfh(&xdr); 5639 status = decode_putfh(xdr);
4949 if (status) 5640 if (status)
4950 goto out; 5641 goto out;
4951 status = decode_readdir(&xdr, rqstp, res); 5642 status = decode_readdir(xdr, rqstp, res);
4952out: 5643out:
4953 return status; 5644 return status;
4954} 5645}
@@ -4956,23 +5647,22 @@ out:
4956/* 5647/*
4957 * Decode Read response 5648 * Decode Read response
4958 */ 5649 */
4959static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res) 5650static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5651 struct nfs_readres *res)
4960{ 5652{
4961 struct xdr_stream xdr;
4962 struct compound_hdr hdr; 5653 struct compound_hdr hdr;
4963 int status; 5654 int status;
4964 5655
4965 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5656 status = decode_compound_hdr(xdr, &hdr);
4966 status = decode_compound_hdr(&xdr, &hdr);
4967 if (status) 5657 if (status)
4968 goto out; 5658 goto out;
4969 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5659 status = decode_sequence(xdr, &res->seq_res, rqstp);
4970 if (status) 5660 if (status)
4971 goto out; 5661 goto out;
4972 status = decode_putfh(&xdr); 5662 status = decode_putfh(xdr);
4973 if (status) 5663 if (status)
4974 goto out; 5664 goto out;
4975 status = decode_read(&xdr, rqstp, res); 5665 status = decode_read(xdr, rqstp, res);
4976 if (!status) 5666 if (!status)
4977 status = res->count; 5667 status = res->count;
4978out: 5668out:
@@ -4982,26 +5672,26 @@ out:
4982/* 5672/*
4983 * Decode WRITE response 5673 * Decode WRITE response
4984 */ 5674 */
4985static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) 5675static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5676 struct nfs_writeres *res)
4986{ 5677{
4987 struct xdr_stream xdr;
4988 struct compound_hdr hdr; 5678 struct compound_hdr hdr;
4989 int status; 5679 int status;
4990 5680
4991 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5681 status = decode_compound_hdr(xdr, &hdr);
4992 status = decode_compound_hdr(&xdr, &hdr);
4993 if (status) 5682 if (status)
4994 goto out; 5683 goto out;
4995 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5684 status = decode_sequence(xdr, &res->seq_res, rqstp);
4996 if (status) 5685 if (status)
4997 goto out; 5686 goto out;
4998 status = decode_putfh(&xdr); 5687 status = decode_putfh(xdr);
4999 if (status) 5688 if (status)
5000 goto out; 5689 goto out;
5001 status = decode_write(&xdr, res); 5690 status = decode_write(xdr, res);
5002 if (status) 5691 if (status)
5003 goto out; 5692 goto out;
5004 decode_getfattr(&xdr, res->fattr, res->server); 5693 decode_getfattr(xdr, res->fattr, res->server,
5694 !RPC_IS_ASYNC(rqstp->rq_task));
5005 if (!status) 5695 if (!status)
5006 status = res->count; 5696 status = res->count;
5007out: 5697out:
@@ -5011,112 +5701,107 @@ out:
5011/* 5701/*
5012 * Decode COMMIT response 5702 * Decode COMMIT response
5013 */ 5703 */
5014static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) 5704static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5705 struct nfs_writeres *res)
5015{ 5706{
5016 struct xdr_stream xdr;
5017 struct compound_hdr hdr; 5707 struct compound_hdr hdr;
5018 int status; 5708 int status;
5019 5709
5020 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5710 status = decode_compound_hdr(xdr, &hdr);
5021 status = decode_compound_hdr(&xdr, &hdr);
5022 if (status) 5711 if (status)
5023 goto out; 5712 goto out;
5024 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5713 status = decode_sequence(xdr, &res->seq_res, rqstp);
5025 if (status) 5714 if (status)
5026 goto out; 5715 goto out;
5027 status = decode_putfh(&xdr); 5716 status = decode_putfh(xdr);
5028 if (status) 5717 if (status)
5029 goto out; 5718 goto out;
5030 status = decode_commit(&xdr, res); 5719 status = decode_commit(xdr, res);
5031 if (status) 5720 if (status)
5032 goto out; 5721 goto out;
5033 decode_getfattr(&xdr, res->fattr, res->server); 5722 decode_getfattr(xdr, res->fattr, res->server,
5723 !RPC_IS_ASYNC(rqstp->rq_task));
5034out: 5724out:
5035 return status; 5725 return status;
5036} 5726}
5037 5727
5038/* 5728/*
5039 * FSINFO request 5729 * Decode FSINFO response
5040 */ 5730 */
5041static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, 5731static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
5042 struct nfs4_fsinfo_res *res) 5732 struct nfs4_fsinfo_res *res)
5043{ 5733{
5044 struct xdr_stream xdr;
5045 struct compound_hdr hdr; 5734 struct compound_hdr hdr;
5046 int status; 5735 int status;
5047 5736
5048 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5737 status = decode_compound_hdr(xdr, &hdr);
5049 status = decode_compound_hdr(&xdr, &hdr);
5050 if (!status) 5738 if (!status)
5051 status = decode_sequence(&xdr, &res->seq_res, req); 5739 status = decode_sequence(xdr, &res->seq_res, req);
5052 if (!status) 5740 if (!status)
5053 status = decode_putfh(&xdr); 5741 status = decode_putfh(xdr);
5054 if (!status) 5742 if (!status)
5055 status = decode_fsinfo(&xdr, res->fsinfo); 5743 status = decode_fsinfo(xdr, res->fsinfo);
5056 return status; 5744 return status;
5057} 5745}
5058 5746
5059/* 5747/*
5060 * PATHCONF request 5748 * Decode PATHCONF response
5061 */ 5749 */
5062static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, 5750static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
5063 struct nfs4_pathconf_res *res) 5751 struct nfs4_pathconf_res *res)
5064{ 5752{
5065 struct xdr_stream xdr;
5066 struct compound_hdr hdr; 5753 struct compound_hdr hdr;
5067 int status; 5754 int status;
5068 5755
5069 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5756 status = decode_compound_hdr(xdr, &hdr);
5070 status = decode_compound_hdr(&xdr, &hdr);
5071 if (!status) 5757 if (!status)
5072 status = decode_sequence(&xdr, &res->seq_res, req); 5758 status = decode_sequence(xdr, &res->seq_res, req);
5073 if (!status) 5759 if (!status)
5074 status = decode_putfh(&xdr); 5760 status = decode_putfh(xdr);
5075 if (!status) 5761 if (!status)
5076 status = decode_pathconf(&xdr, res->pathconf); 5762 status = decode_pathconf(xdr, res->pathconf);
5077 return status; 5763 return status;
5078} 5764}
5079 5765
5080/* 5766/*
5081 * STATFS request 5767 * Decode STATFS response
5082 */ 5768 */
5083static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, 5769static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
5084 struct nfs4_statfs_res *res) 5770 struct nfs4_statfs_res *res)
5085{ 5771{
5086 struct xdr_stream xdr;
5087 struct compound_hdr hdr; 5772 struct compound_hdr hdr;
5088 int status; 5773 int status;
5089 5774
5090 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5775 status = decode_compound_hdr(xdr, &hdr);
5091 status = decode_compound_hdr(&xdr, &hdr);
5092 if (!status) 5776 if (!status)
5093 status = decode_sequence(&xdr, &res->seq_res, req); 5777 status = decode_sequence(xdr, &res->seq_res, req);
5094 if (!status) 5778 if (!status)
5095 status = decode_putfh(&xdr); 5779 status = decode_putfh(xdr);
5096 if (!status) 5780 if (!status)
5097 status = decode_statfs(&xdr, res->fsstat); 5781 status = decode_statfs(xdr, res->fsstat);
5098 return status; 5782 return status;
5099} 5783}
5100 5784
5101/* 5785/*
5102 * GETATTR_BITMAP request 5786 * Decode GETATTR_BITMAP response
5103 */ 5787 */
5104static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res) 5788static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5789 struct xdr_stream *xdr,
5790 struct nfs4_server_caps_res *res)
5105{ 5791{
5106 struct xdr_stream xdr;
5107 struct compound_hdr hdr; 5792 struct compound_hdr hdr;
5108 int status; 5793 int status;
5109 5794
5110 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5795 status = decode_compound_hdr(xdr, &hdr);
5111 status = decode_compound_hdr(&xdr, &hdr);
5112 if (status) 5796 if (status)
5113 goto out; 5797 goto out;
5114 status = decode_sequence(&xdr, &res->seq_res, req); 5798 status = decode_sequence(xdr, &res->seq_res, req);
5115 if (status) 5799 if (status)
5116 goto out; 5800 goto out;
5117 if ((status = decode_putfh(&xdr)) != 0) 5801 status = decode_putfh(xdr);
5802 if (status)
5118 goto out; 5803 goto out;
5119 status = decode_server_caps(&xdr, res); 5804 status = decode_server_caps(xdr, res);
5120out: 5805out:
5121 return status; 5806 return status;
5122} 5807}
@@ -5124,217 +5809,304 @@ out:
5124/* 5809/*
5125 * Decode RENEW response 5810 * Decode RENEW response
5126 */ 5811 */
5127static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy) 5812static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5813 void *__unused)
5128{ 5814{
5129 struct xdr_stream xdr;
5130 struct compound_hdr hdr; 5815 struct compound_hdr hdr;
5131 int status; 5816 int status;
5132 5817
5133 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5818 status = decode_compound_hdr(xdr, &hdr);
5134 status = decode_compound_hdr(&xdr, &hdr);
5135 if (!status) 5819 if (!status)
5136 status = decode_renew(&xdr); 5820 status = decode_renew(xdr);
5137 return status; 5821 return status;
5138} 5822}
5139 5823
5140/* 5824/*
5141 * a SETCLIENTID request 5825 * Decode SETCLIENTID response
5142 */ 5826 */
5143static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p, 5827static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5144 struct nfs_client *clp) 5828 struct xdr_stream *xdr,
5829 struct nfs4_setclientid_res *res)
5145{ 5830{
5146 struct xdr_stream xdr;
5147 struct compound_hdr hdr; 5831 struct compound_hdr hdr;
5148 int status; 5832 int status;
5149 5833
5150 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5834 status = decode_compound_hdr(xdr, &hdr);
5151 status = decode_compound_hdr(&xdr, &hdr);
5152 if (!status) 5835 if (!status)
5153 status = decode_setclientid(&xdr, clp); 5836 status = decode_setclientid(xdr, res);
5154 return status; 5837 return status;
5155} 5838}
5156 5839
5157/* 5840/*
5158 * a SETCLIENTID_CONFIRM request 5841 * Decode SETCLIENTID_CONFIRM response
5159 */ 5842 */
5160static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) 5843static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5844 struct xdr_stream *xdr,
5845 struct nfs_fsinfo *fsinfo)
5161{ 5846{
5162 struct xdr_stream xdr;
5163 struct compound_hdr hdr; 5847 struct compound_hdr hdr;
5164 int status; 5848 int status;
5165 5849
5166 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5850 status = decode_compound_hdr(xdr, &hdr);
5167 status = decode_compound_hdr(&xdr, &hdr);
5168 if (!status) 5851 if (!status)
5169 status = decode_setclientid_confirm(&xdr); 5852 status = decode_setclientid_confirm(xdr);
5170 if (!status) 5853 if (!status)
5171 status = decode_putrootfh(&xdr); 5854 status = decode_putrootfh(xdr);
5172 if (!status) 5855 if (!status)
5173 status = decode_fsinfo(&xdr, fsinfo); 5856 status = decode_fsinfo(xdr, fsinfo);
5174 return status; 5857 return status;
5175} 5858}
5176 5859
5177/* 5860/*
5178 * DELEGRETURN request 5861 * Decode DELEGRETURN response
5179 */ 5862 */
5180static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res) 5863static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5864 struct xdr_stream *xdr,
5865 struct nfs4_delegreturnres *res)
5181{ 5866{
5182 struct xdr_stream xdr;
5183 struct compound_hdr hdr; 5867 struct compound_hdr hdr;
5184 int status; 5868 int status;
5185 5869
5186 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5870 status = decode_compound_hdr(xdr, &hdr);
5187 status = decode_compound_hdr(&xdr, &hdr);
5188 if (status) 5871 if (status)
5189 goto out; 5872 goto out;
5190 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5873 status = decode_sequence(xdr, &res->seq_res, rqstp);
5191 if (status) 5874 if (status)
5192 goto out; 5875 goto out;
5193 status = decode_putfh(&xdr); 5876 status = decode_putfh(xdr);
5877 if (status != 0)
5878 goto out;
5879 status = decode_delegreturn(xdr);
5194 if (status != 0) 5880 if (status != 0)
5195 goto out; 5881 goto out;
5196 status = decode_delegreturn(&xdr); 5882 decode_getfattr(xdr, res->fattr, res->server,
5197 decode_getfattr(&xdr, res->fattr, res->server); 5883 !RPC_IS_ASYNC(rqstp->rq_task));
5198out: 5884out:
5199 return status; 5885 return status;
5200} 5886}
5201 5887
5202/* 5888/*
5203 * FS_LOCATIONS request 5889 * Decode FS_LOCATIONS response
5204 */ 5890 */
5205static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, 5891static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
5892 struct xdr_stream *xdr,
5206 struct nfs4_fs_locations_res *res) 5893 struct nfs4_fs_locations_res *res)
5207{ 5894{
5208 struct xdr_stream xdr;
5209 struct compound_hdr hdr; 5895 struct compound_hdr hdr;
5210 int status; 5896 int status;
5211 5897
5212 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5898 status = decode_compound_hdr(xdr, &hdr);
5213 status = decode_compound_hdr(&xdr, &hdr);
5214 if (status) 5899 if (status)
5215 goto out; 5900 goto out;
5216 status = decode_sequence(&xdr, &res->seq_res, req); 5901 status = decode_sequence(xdr, &res->seq_res, req);
5217 if (status) 5902 if (status)
5218 goto out; 5903 goto out;
5219 if ((status = decode_putfh(&xdr)) != 0) 5904 status = decode_putfh(xdr);
5905 if (status)
5220 goto out; 5906 goto out;
5221 if ((status = decode_lookup(&xdr)) != 0) 5907 status = decode_lookup(xdr);
5908 if (status)
5222 goto out; 5909 goto out;
5223 xdr_enter_page(&xdr, PAGE_SIZE); 5910 xdr_enter_page(xdr, PAGE_SIZE);
5224 status = decode_getfattr(&xdr, &res->fs_locations->fattr, 5911 status = decode_getfattr(xdr, &res->fs_locations->fattr,
5225 res->fs_locations->server); 5912 res->fs_locations->server,
5913 !RPC_IS_ASYNC(req->rq_task));
5226out: 5914out:
5227 return status; 5915 return status;
5228} 5916}
5229 5917
5230#if defined(CONFIG_NFS_V4_1) 5918#if defined(CONFIG_NFS_V4_1)
5231/* 5919/*
5232 * EXCHANGE_ID request 5920 * Decode EXCHANGE_ID response
5233 */ 5921 */
5234static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p, 5922static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
5923 struct xdr_stream *xdr,
5235 void *res) 5924 void *res)
5236{ 5925{
5237 struct xdr_stream xdr;
5238 struct compound_hdr hdr; 5926 struct compound_hdr hdr;
5239 int status; 5927 int status;
5240 5928
5241 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5929 status = decode_compound_hdr(xdr, &hdr);
5242 status = decode_compound_hdr(&xdr, &hdr);
5243 if (!status) 5930 if (!status)
5244 status = decode_exchange_id(&xdr, res); 5931 status = decode_exchange_id(xdr, res);
5245 return status; 5932 return status;
5246} 5933}
5247 5934
5248/* 5935/*
5249 * a CREATE_SESSION request 5936 * Decode CREATE_SESSION response
5250 */ 5937 */
5251static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p, 5938static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
5939 struct xdr_stream *xdr,
5252 struct nfs41_create_session_res *res) 5940 struct nfs41_create_session_res *res)
5253{ 5941{
5254 struct xdr_stream xdr;
5255 struct compound_hdr hdr; 5942 struct compound_hdr hdr;
5256 int status; 5943 int status;
5257 5944
5258 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5945 status = decode_compound_hdr(xdr, &hdr);
5259 status = decode_compound_hdr(&xdr, &hdr);
5260 if (!status) 5946 if (!status)
5261 status = decode_create_session(&xdr, res); 5947 status = decode_create_session(xdr, res);
5262 return status; 5948 return status;
5263} 5949}
5264 5950
5265/* 5951/*
5266 * a DESTROY_SESSION request 5952 * Decode DESTROY_SESSION response
5267 */ 5953 */
5268static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p, 5954static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
5269 void *dummy) 5955 struct xdr_stream *xdr,
5956 void *res)
5270{ 5957{
5271 struct xdr_stream xdr;
5272 struct compound_hdr hdr; 5958 struct compound_hdr hdr;
5273 int status; 5959 int status;
5274 5960
5275 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5961 status = decode_compound_hdr(xdr, &hdr);
5276 status = decode_compound_hdr(&xdr, &hdr);
5277 if (!status) 5962 if (!status)
5278 status = decode_destroy_session(&xdr, dummy); 5963 status = decode_destroy_session(xdr, res);
5279 return status; 5964 return status;
5280} 5965}
5281 5966
5282/* 5967/*
5283 * a SEQUENCE request 5968 * Decode SEQUENCE response
5284 */ 5969 */
5285static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p, 5970static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
5971 struct xdr_stream *xdr,
5286 struct nfs4_sequence_res *res) 5972 struct nfs4_sequence_res *res)
5287{ 5973{
5288 struct xdr_stream xdr;
5289 struct compound_hdr hdr; 5974 struct compound_hdr hdr;
5290 int status; 5975 int status;
5291 5976
5292 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5977 status = decode_compound_hdr(xdr, &hdr);
5293 status = decode_compound_hdr(&xdr, &hdr);
5294 if (!status) 5978 if (!status)
5295 status = decode_sequence(&xdr, res, rqstp); 5979 status = decode_sequence(xdr, res, rqstp);
5296 return status; 5980 return status;
5297} 5981}
5298 5982
5299/* 5983/*
5300 * a GET_LEASE_TIME request 5984 * Decode GET_LEASE_TIME response
5301 */ 5985 */
5302static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p, 5986static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
5987 struct xdr_stream *xdr,
5303 struct nfs4_get_lease_time_res *res) 5988 struct nfs4_get_lease_time_res *res)
5304{ 5989{
5305 struct xdr_stream xdr;
5306 struct compound_hdr hdr; 5990 struct compound_hdr hdr;
5307 int status; 5991 int status;
5308 5992
5309 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5993 status = decode_compound_hdr(xdr, &hdr);
5310 status = decode_compound_hdr(&xdr, &hdr); 5994 if (!status)
5995 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
5311 if (!status) 5996 if (!status)
5312 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp); 5997 status = decode_putrootfh(xdr);
5998 if (!status)
5999 status = decode_fsinfo(xdr, res->lr_fsinfo);
6000 return status;
6001}
6002
6003/*
6004 * Decode RECLAIM_COMPLETE response
6005 */
6006static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6007 struct xdr_stream *xdr,
6008 struct nfs41_reclaim_complete_res *res)
6009{
6010 struct compound_hdr hdr;
6011 int status;
6012
6013 status = decode_compound_hdr(xdr, &hdr);
5313 if (!status) 6014 if (!status)
5314 status = decode_putrootfh(&xdr); 6015 status = decode_sequence(xdr, &res->seq_res, rqstp);
5315 if (!status) 6016 if (!status)
5316 status = decode_fsinfo(&xdr, res->lr_fsinfo); 6017 status = decode_reclaim_complete(xdr, (void *)NULL);
6018 return status;
6019}
6020
6021/*
6022 * Decode GETDEVINFO response
6023 */
6024static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6025 struct xdr_stream *xdr,
6026 struct nfs4_getdeviceinfo_res *res)
6027{
6028 struct compound_hdr hdr;
6029 int status;
6030
6031 status = decode_compound_hdr(xdr, &hdr);
6032 if (status != 0)
6033 goto out;
6034 status = decode_sequence(xdr, &res->seq_res, rqstp);
6035 if (status != 0)
6036 goto out;
6037 status = decode_getdeviceinfo(xdr, res->pdev);
6038out:
6039 return status;
6040}
6041
6042/*
6043 * Decode LAYOUTGET response
6044 */
6045static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6046 struct xdr_stream *xdr,
6047 struct nfs4_layoutget_res *res)
6048{
6049 struct compound_hdr hdr;
6050 int status;
6051
6052 status = decode_compound_hdr(xdr, &hdr);
6053 if (status)
6054 goto out;
6055 status = decode_sequence(xdr, &res->seq_res, rqstp);
6056 if (status)
6057 goto out;
6058 status = decode_putfh(xdr);
6059 if (status)
6060 goto out;
6061 status = decode_layoutget(xdr, rqstp, res);
6062out:
5317 return status; 6063 return status;
5318} 6064}
5319#endif /* CONFIG_NFS_V4_1 */ 6065#endif /* CONFIG_NFS_V4_1 */
5320 6066
5321__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) 6067/**
6068 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6069 * the local page cache.
6070 * @xdr: XDR stream where entry resides
6071 * @entry: buffer to fill in with entry data
6072 * @plus: boolean indicating whether this should be a readdirplus entry
6073 *
6074 * Returns zero if successful, otherwise a negative errno value is
6075 * returned.
6076 *
6077 * This function is not invoked during READDIR reply decoding, but
6078 * rather whenever an application invokes the getdents(2) system call
6079 * on a directory already in our cache.
6080 */
6081int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6082 int plus)
5322{ 6083{
5323 uint32_t bitmap[2] = {0}; 6084 uint32_t bitmap[2] = {0};
5324 uint32_t len; 6085 uint32_t len;
5325 6086 __be32 *p = xdr_inline_decode(xdr, 4);
5326 if (!*p++) { 6087 if (unlikely(!p))
5327 if (!*p) 6088 goto out_overflow;
5328 return ERR_PTR(-EAGAIN); 6089 if (!ntohl(*p++)) {
6090 p = xdr_inline_decode(xdr, 4);
6091 if (unlikely(!p))
6092 goto out_overflow;
6093 if (!ntohl(*p++))
6094 return -EAGAIN;
5329 entry->eof = 1; 6095 entry->eof = 1;
5330 return ERR_PTR(-EBADCOOKIE); 6096 return -EBADCOOKIE;
5331 } 6097 }
5332 6098
6099 p = xdr_inline_decode(xdr, 12);
6100 if (unlikely(!p))
6101 goto out_overflow;
5333 entry->prev_cookie = entry->cookie; 6102 entry->prev_cookie = entry->cookie;
5334 p = xdr_decode_hyper(p, &entry->cookie); 6103 p = xdr_decode_hyper(p, &entry->cookie);
5335 entry->len = ntohl(*p++); 6104 entry->len = ntohl(*p++);
6105
6106 p = xdr_inline_decode(xdr, entry->len);
6107 if (unlikely(!p))
6108 goto out_overflow;
5336 entry->name = (const char *) p; 6109 entry->name = (const char *) p;
5337 p += XDR_QUADLEN(entry->len);
5338 6110
5339 /* 6111 /*
5340 * In case the server doesn't return an inode number, 6112 * In case the server doesn't return an inode number,
@@ -5342,32 +6114,32 @@ __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
5342 * since glibc seems to choke on it...) 6114 * since glibc seems to choke on it...)
5343 */ 6115 */
5344 entry->ino = 1; 6116 entry->ino = 1;
6117 entry->fattr->valid = 0;
5345 6118
5346 len = ntohl(*p++); /* bitmap length */ 6119 if (decode_attr_bitmap(xdr, bitmap) < 0)
5347 if (len-- > 0) { 6120 goto out_overflow;
5348 bitmap[0] = ntohl(*p++);
5349 if (len-- > 0) {
5350 bitmap[1] = ntohl(*p++);
5351 p += len;
5352 }
5353 }
5354 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5355 if (len > 0) {
5356 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5357 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5358 /* Ignore the return value of rdattr_error for now */
5359 p++;
5360 len--;
5361 }
5362 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5363 xdr_decode_hyper(p, &entry->ino);
5364 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5365 xdr_decode_hyper(p, &entry->ino);
5366 p += len;
5367 }
5368 6121
5369 entry->eof = !p[0] && p[1]; 6122 if (decode_attr_length(xdr, &len, &p) < 0)
5370 return p; 6123 goto out_overflow;
6124
6125 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6126 entry->server, 1) < 0)
6127 goto out_overflow;
6128 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6129 entry->ino = entry->fattr->fileid;
6130
6131 entry->d_type = DT_UNKNOWN;
6132 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6133 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6134
6135 if (verify_attr_len(xdr, p, len) < 0)
6136 goto out_overflow;
6137
6138 return 0;
6139
6140out_overflow:
6141 print_overflow_msg(__func__, xdr);
6142 return -EAGAIN;
5371} 6143}
5372 6144
5373/* 6145/*
@@ -5403,10 +6175,9 @@ static struct {
5403 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 6175 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5404 { NFS4ERR_NOTSUPP, -ENOTSUPP }, 6176 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5405 { NFS4ERR_TOOSMALL, -ETOOSMALL }, 6177 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5406 { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, 6178 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
5407 { NFS4ERR_BADTYPE, -EBADTYPE }, 6179 { NFS4ERR_BADTYPE, -EBADTYPE },
5408 { NFS4ERR_LOCKED, -EAGAIN }, 6180 { NFS4ERR_LOCKED, -EAGAIN },
5409 { NFS4ERR_RESOURCE, -EREMOTEIO },
5410 { NFS4ERR_SYMLINK, -ELOOP }, 6181 { NFS4ERR_SYMLINK, -ELOOP },
5411 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 6182 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5412 { NFS4ERR_DEADLOCK, -EDEADLK }, 6183 { NFS4ERR_DEADLOCK, -EDEADLK },
@@ -5431,7 +6202,7 @@ nfs4_stat_to_errno(int stat)
5431 } 6202 }
5432 if (stat <= 10000 || stat > 10100) { 6203 if (stat <= 10000 || stat > 10100) {
5433 /* The server is looney tunes. */ 6204 /* The server is looney tunes. */
5434 return -ESERVERFAULT; 6205 return -EREMOTEIO;
5435 } 6206 }
5436 /* If we cannot translate the error, the recovery routines should 6207 /* If we cannot translate the error, the recovery routines should
5437 * handle it. 6208 * handle it.
@@ -5444,8 +6215,8 @@ nfs4_stat_to_errno(int stat)
5444#define PROC(proc, argtype, restype) \ 6215#define PROC(proc, argtype, restype) \
5445[NFSPROC4_CLNT_##proc] = { \ 6216[NFSPROC4_CLNT_##proc] = { \
5446 .p_proc = NFSPROC4_COMPOUND, \ 6217 .p_proc = NFSPROC4_COMPOUND, \
5447 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ 6218 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
5448 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ 6219 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
5449 .p_arglen = NFS4_##argtype##_sz, \ 6220 .p_arglen = NFS4_##argtype##_sz, \
5450 .p_replen = NFS4_##restype##_sz, \ 6221 .p_replen = NFS4_##restype##_sz, \
5451 .p_statidx = NFSPROC4_CLNT_##proc, \ 6222 .p_statidx = NFSPROC4_CLNT_##proc, \
@@ -5453,46 +6224,50 @@ nfs4_stat_to_errno(int stat)
5453} 6224}
5454 6225
5455struct rpc_procinfo nfs4_procedures[] = { 6226struct rpc_procinfo nfs4_procedures[] = {
5456 PROC(READ, enc_read, dec_read), 6227 PROC(READ, enc_read, dec_read),
5457 PROC(WRITE, enc_write, dec_write), 6228 PROC(WRITE, enc_write, dec_write),
5458 PROC(COMMIT, enc_commit, dec_commit), 6229 PROC(COMMIT, enc_commit, dec_commit),
5459 PROC(OPEN, enc_open, dec_open), 6230 PROC(OPEN, enc_open, dec_open),
5460 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 6231 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5461 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 6232 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5462 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 6233 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5463 PROC(CLOSE, enc_close, dec_close), 6234 PROC(CLOSE, enc_close, dec_close),
5464 PROC(SETATTR, enc_setattr, dec_setattr), 6235 PROC(SETATTR, enc_setattr, dec_setattr),
5465 PROC(FSINFO, enc_fsinfo, dec_fsinfo), 6236 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5466 PROC(RENEW, enc_renew, dec_renew), 6237 PROC(RENEW, enc_renew, dec_renew),
5467 PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 6238 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5468 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 6239 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5469 PROC(LOCK, enc_lock, dec_lock), 6240 PROC(LOCK, enc_lock, dec_lock),
5470 PROC(LOCKT, enc_lockt, dec_lockt), 6241 PROC(LOCKT, enc_lockt, dec_lockt),
5471 PROC(LOCKU, enc_locku, dec_locku), 6242 PROC(LOCKU, enc_locku, dec_locku),
5472 PROC(ACCESS, enc_access, dec_access), 6243 PROC(ACCESS, enc_access, dec_access),
5473 PROC(GETATTR, enc_getattr, dec_getattr), 6244 PROC(GETATTR, enc_getattr, dec_getattr),
5474 PROC(LOOKUP, enc_lookup, dec_lookup), 6245 PROC(LOOKUP, enc_lookup, dec_lookup),
5475 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 6246 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5476 PROC(REMOVE, enc_remove, dec_remove), 6247 PROC(REMOVE, enc_remove, dec_remove),
5477 PROC(RENAME, enc_rename, dec_rename), 6248 PROC(RENAME, enc_rename, dec_rename),
5478 PROC(LINK, enc_link, dec_link), 6249 PROC(LINK, enc_link, dec_link),
5479 PROC(SYMLINK, enc_symlink, dec_symlink), 6250 PROC(SYMLINK, enc_symlink, dec_symlink),
5480 PROC(CREATE, enc_create, dec_create), 6251 PROC(CREATE, enc_create, dec_create),
5481 PROC(PATHCONF, enc_pathconf, dec_pathconf), 6252 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5482 PROC(STATFS, enc_statfs, dec_statfs), 6253 PROC(STATFS, enc_statfs, dec_statfs),
5483 PROC(READLINK, enc_readlink, dec_readlink), 6254 PROC(READLINK, enc_readlink, dec_readlink),
5484 PROC(READDIR, enc_readdir, dec_readdir), 6255 PROC(READDIR, enc_readdir, dec_readdir),
5485 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 6256 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5486 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 6257 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
5487 PROC(GETACL, enc_getacl, dec_getacl), 6258 PROC(GETACL, enc_getacl, dec_getacl),
5488 PROC(SETACL, enc_setacl, dec_setacl), 6259 PROC(SETACL, enc_setacl, dec_setacl),
5489 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 6260 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6261 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
5490#if defined(CONFIG_NFS_V4_1) 6262#if defined(CONFIG_NFS_V4_1)
5491 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 6263 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
5492 PROC(CREATE_SESSION, enc_create_session, dec_create_session), 6264 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
5493 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 6265 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
5494 PROC(SEQUENCE, enc_sequence, dec_sequence), 6266 PROC(SEQUENCE, enc_sequence, dec_sequence),
5495 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 6267 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6268 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6269 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6270 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
5496#endif /* CONFIG_NFS_V4_1 */ 6271#endif /* CONFIG_NFS_V4_1 */
5497}; 6272};
5498 6273
diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
index 8c55b27c0de4..903908a20023 100644
--- a/fs/nfs/nfsroot.c
+++ b/fs/nfs/nfsroot.c
@@ -3,9 +3,10 @@
3 * 3 *
4 * Allow an NFS filesystem to be mounted as root. The way this works is: 4 * Allow an NFS filesystem to be mounted as root. The way this works is:
5 * (1) Use the IP autoconfig mechanism to set local IP addresses and routes. 5 * (1) Use the IP autoconfig mechanism to set local IP addresses and routes.
6 * (2) Handle RPC negotiation with the system which replied to RARP or 6 * (2) Construct the device string and the options string using DHCP
7 * was reported as a boot server by BOOTP or manually. 7 * option 17 and/or kernel command line options.
8 * (3) The actual mounting is done later, when init() is running. 8 * (3) When mount_root() sets up the root file system, pass these strings
9 * to the NFS client's regular mount interface via sys_mount().
9 * 10 *
10 * 11 *
11 * Changes: 12 * Changes:
@@ -65,468 +66,245 @@
65 * Hua Qin : Support for mounting root file system via 66 * Hua Qin : Support for mounting root file system via
66 * NFS over TCP. 67 * NFS over TCP.
67 * Fabian Frederick: Option parser rebuilt (using parser lib) 68 * Fabian Frederick: Option parser rebuilt (using parser lib)
68*/ 69 * Chuck Lever : Use super.c's text-based mount option parsing
70 * Chuck Lever : Add "nfsrootdebug".
71 */
69 72
70#include <linux/types.h> 73#include <linux/types.h>
71#include <linux/string.h> 74#include <linux/string.h>
72#include <linux/kernel.h>
73#include <linux/time.h>
74#include <linux/fs.h>
75#include <linux/init.h> 75#include <linux/init.h>
76#include <linux/sunrpc/clnt.h>
77#include <linux/sunrpc/xprtsock.h>
78#include <linux/nfs.h> 76#include <linux/nfs.h>
79#include <linux/nfs_fs.h> 77#include <linux/nfs_fs.h>
80#include <linux/nfs_mount.h>
81#include <linux/in.h>
82#include <linux/major.h>
83#include <linux/utsname.h> 78#include <linux/utsname.h>
84#include <linux/inet.h>
85#include <linux/root_dev.h> 79#include <linux/root_dev.h>
86#include <net/ipconfig.h> 80#include <net/ipconfig.h>
87#include <linux/parser.h>
88 81
89#include "internal.h" 82#include "internal.h"
90 83
91/* Define this to allow debugging output */
92#undef NFSROOT_DEBUG
93#define NFSDBG_FACILITY NFSDBG_ROOT 84#define NFSDBG_FACILITY NFSDBG_ROOT
94 85
95/* Default port to use if server is not running a portmapper */
96#define NFS_MNT_PORT 627
97
98/* Default path we try to mount. "%s" gets replaced by our IP address */ 86/* Default path we try to mount. "%s" gets replaced by our IP address */
99#define NFS_ROOT "/tftpboot/%s" 87#define NFS_ROOT "/tftpboot/%s"
100 88
101/* Parameters passed from the kernel command line */ 89/* Parameters passed from the kernel command line */
102static char nfs_root_name[256] __initdata = ""; 90static char nfs_root_parms[256] __initdata = "";
91
92/* Text-based mount options passed to super.c */
93static char nfs_root_options[256] __initdata = "";
103 94
104/* Address of NFS server */ 95/* Address of NFS server */
105static __be32 servaddr __initdata = 0; 96static __be32 servaddr __initdata = htonl(INADDR_NONE);
106 97
107/* Name of directory to mount */ 98/* Name of directory to mount */
108static char nfs_export_path[NFS_MAXPATHLEN] __initdata = { 0, }; 99static char nfs_export_path[NFS_MAXPATHLEN + 1] __initdata = "";
109
110/* NFS-related data */
111static struct nfs_mount_data nfs_data __initdata = { 0, };/* NFS mount info */
112static int nfs_port __initdata = 0; /* Port to connect to for NFS */
113static int mount_port __initdata = 0; /* Mount daemon port number */
114
115
116/***************************************************************************
117
118 Parsing of options
119
120 ***************************************************************************/
121
122enum {
123 /* Options that take integer arguments */
124 Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
125 Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
126 /* Options that take no arguments */
127 Opt_soft, Opt_hard, Opt_intr,
128 Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac,
129 Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
130 Opt_acl, Opt_noacl,
131 /* Error token */
132 Opt_err
133};
134
135static const match_table_t tokens __initconst = {
136 {Opt_port, "port=%u"},
137 {Opt_rsize, "rsize=%u"},
138 {Opt_wsize, "wsize=%u"},
139 {Opt_timeo, "timeo=%u"},
140 {Opt_retrans, "retrans=%u"},
141 {Opt_acregmin, "acregmin=%u"},
142 {Opt_acregmax, "acregmax=%u"},
143 {Opt_acdirmin, "acdirmin=%u"},
144 {Opt_acdirmax, "acdirmax=%u"},
145 {Opt_soft, "soft"},
146 {Opt_hard, "hard"},
147 {Opt_intr, "intr"},
148 {Opt_nointr, "nointr"},
149 {Opt_posix, "posix"},
150 {Opt_noposix, "noposix"},
151 {Opt_cto, "cto"},
152 {Opt_nocto, "nocto"},
153 {Opt_ac, "ac"},
154 {Opt_noac, "noac"},
155 {Opt_lock, "lock"},
156 {Opt_nolock, "nolock"},
157 {Opt_v2, "nfsvers=2"},
158 {Opt_v2, "v2"},
159 {Opt_v3, "nfsvers=3"},
160 {Opt_v3, "v3"},
161 {Opt_udp, "proto=udp"},
162 {Opt_udp, "udp"},
163 {Opt_tcp, "proto=tcp"},
164 {Opt_tcp, "tcp"},
165 {Opt_acl, "acl"},
166 {Opt_noacl, "noacl"},
167 {Opt_err, NULL}
168
169};
170
171/*
172 * Parse option string.
173 */
174 100
175static int __init root_nfs_parse(char *name, char *buf) 101/* server:export path string passed to super.c */
176{ 102static char nfs_root_device[NFS_MAXPATHLEN + 1] __initdata = "";
177
178 char *p;
179 substring_t args[MAX_OPT_ARGS];
180 int option;
181
182 if (!name)
183 return 1;
184
185 /* Set the NFS remote path */
186 p = strsep(&name, ",");
187 if (p[0] != '\0' && strcmp(p, "default") != 0)
188 strlcpy(buf, p, NFS_MAXPATHLEN);
189
190 while ((p = strsep (&name, ",")) != NULL) {
191 int token;
192 if (!*p)
193 continue;
194 token = match_token(p, tokens, args);
195
196 /* %u tokens only. Beware if you add new tokens! */
197 if (token < Opt_soft && match_int(&args[0], &option))
198 return 0;
199 switch (token) {
200 case Opt_port:
201 nfs_port = option;
202 break;
203 case Opt_rsize:
204 nfs_data.rsize = option;
205 break;
206 case Opt_wsize:
207 nfs_data.wsize = option;
208 break;
209 case Opt_timeo:
210 nfs_data.timeo = option;
211 break;
212 case Opt_retrans:
213 nfs_data.retrans = option;
214 break;
215 case Opt_acregmin:
216 nfs_data.acregmin = option;
217 break;
218 case Opt_acregmax:
219 nfs_data.acregmax = option;
220 break;
221 case Opt_acdirmin:
222 nfs_data.acdirmin = option;
223 break;
224 case Opt_acdirmax:
225 nfs_data.acdirmax = option;
226 break;
227 case Opt_soft:
228 nfs_data.flags |= NFS_MOUNT_SOFT;
229 break;
230 case Opt_hard:
231 nfs_data.flags &= ~NFS_MOUNT_SOFT;
232 break;
233 case Opt_intr:
234 case Opt_nointr:
235 break;
236 case Opt_posix:
237 nfs_data.flags |= NFS_MOUNT_POSIX;
238 break;
239 case Opt_noposix:
240 nfs_data.flags &= ~NFS_MOUNT_POSIX;
241 break;
242 case Opt_cto:
243 nfs_data.flags &= ~NFS_MOUNT_NOCTO;
244 break;
245 case Opt_nocto:
246 nfs_data.flags |= NFS_MOUNT_NOCTO;
247 break;
248 case Opt_ac:
249 nfs_data.flags &= ~NFS_MOUNT_NOAC;
250 break;
251 case Opt_noac:
252 nfs_data.flags |= NFS_MOUNT_NOAC;
253 break;
254 case Opt_lock:
255 nfs_data.flags &= ~NFS_MOUNT_NONLM;
256 break;
257 case Opt_nolock:
258 nfs_data.flags |= NFS_MOUNT_NONLM;
259 break;
260 case Opt_v2:
261 nfs_data.flags &= ~NFS_MOUNT_VER3;
262 break;
263 case Opt_v3:
264 nfs_data.flags |= NFS_MOUNT_VER3;
265 break;
266 case Opt_udp:
267 nfs_data.flags &= ~NFS_MOUNT_TCP;
268 break;
269 case Opt_tcp:
270 nfs_data.flags |= NFS_MOUNT_TCP;
271 break;
272 case Opt_acl:
273 nfs_data.flags &= ~NFS_MOUNT_NOACL;
274 break;
275 case Opt_noacl:
276 nfs_data.flags |= NFS_MOUNT_NOACL;
277 break;
278 default:
279 printk(KERN_WARNING "Root-NFS: unknown "
280 "option: %s\n", p);
281 return 0;
282 }
283 }
284
285 return 1;
286}
287 103
104#ifdef RPC_DEBUG
288/* 105/*
289 * Prepare the NFS data structure and parse all options. 106 * When the "nfsrootdebug" kernel command line option is specified,
107 * enable debugging messages for NFSROOT.
290 */ 108 */
291static int __init root_nfs_name(char *name) 109static int __init nfs_root_debug(char *__unused)
292{ 110{
293 static char buf[NFS_MAXPATHLEN] __initdata; 111 nfs_debug |= NFSDBG_ROOT | NFSDBG_MOUNT;
294 char *cp;
295
296 /* Set some default values */
297 memset(&nfs_data, 0, sizeof(nfs_data));
298 nfs_port = -1;
299 nfs_data.version = NFS_MOUNT_VERSION;
300 nfs_data.flags = NFS_MOUNT_NONLM; /* No lockd in nfs root yet */
301 nfs_data.rsize = NFS_DEF_FILE_IO_SIZE;
302 nfs_data.wsize = NFS_DEF_FILE_IO_SIZE;
303 nfs_data.acregmin = NFS_DEF_ACREGMIN;
304 nfs_data.acregmax = NFS_DEF_ACREGMAX;
305 nfs_data.acdirmin = NFS_DEF_ACDIRMIN;
306 nfs_data.acdirmax = NFS_DEF_ACDIRMAX;
307 strcpy(buf, NFS_ROOT);
308
309 /* Process options received from the remote server */
310 root_nfs_parse(root_server_path, buf);
311
312 /* Override them by options set on kernel command-line */
313 root_nfs_parse(name, buf);
314
315 cp = utsname()->nodename;
316 if (strlen(buf) + strlen(cp) > NFS_MAXPATHLEN) {
317 printk(KERN_ERR "Root-NFS: Pathname for remote directory too long.\n");
318 return -1;
319 }
320 sprintf(nfs_export_path, buf, cp);
321
322 return 1; 112 return 1;
323} 113}
324 114
325 115__setup("nfsrootdebug", nfs_root_debug);
326/*
327 * Get NFS server address.
328 */
329static int __init root_nfs_addr(void)
330{
331 if ((servaddr = root_server_addr) == htonl(INADDR_NONE)) {
332 printk(KERN_ERR "Root-NFS: No NFS server available, giving up.\n");
333 return -1;
334 }
335
336 snprintf(nfs_data.hostname, sizeof(nfs_data.hostname),
337 "%pI4", &servaddr);
338 return 0;
339}
340
341/*
342 * Tell the user what's going on.
343 */
344#ifdef NFSROOT_DEBUG
345static void __init root_nfs_print(void)
346{
347 printk(KERN_NOTICE "Root-NFS: Mounting %s on server %s as root\n",
348 nfs_export_path, nfs_data.hostname);
349 printk(KERN_NOTICE "Root-NFS: rsize = %d, wsize = %d, timeo = %d, retrans = %d\n",
350 nfs_data.rsize, nfs_data.wsize, nfs_data.timeo, nfs_data.retrans);
351 printk(KERN_NOTICE "Root-NFS: acreg (min,max) = (%d,%d), acdir (min,max) = (%d,%d)\n",
352 nfs_data.acregmin, nfs_data.acregmax,
353 nfs_data.acdirmin, nfs_data.acdirmax);
354 printk(KERN_NOTICE "Root-NFS: nfsd port = %d, mountd port = %d, flags = %08x\n",
355 nfs_port, mount_port, nfs_data.flags);
356}
357#endif
358
359
360static int __init root_nfs_init(void)
361{
362#ifdef NFSROOT_DEBUG
363 nfs_debug |= NFSDBG_ROOT;
364#endif 116#endif
365 117
366 /*
367 * Decode the root directory path name and NFS options from
368 * the kernel command line. This has to go here in order to
369 * be able to use the client IP address for the remote root
370 * directory (necessary for pure RARP booting).
371 */
372 if (root_nfs_name(nfs_root_name) < 0 ||
373 root_nfs_addr() < 0)
374 return -1;
375
376#ifdef NFSROOT_DEBUG
377 root_nfs_print();
378#endif
379
380 return 0;
381}
382
383
384/* 118/*
385 * Parse NFS server and directory information passed on the kernel 119 * Parse NFS server and directory information passed on the kernel
386 * command line. 120 * command line.
121 *
122 * nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
123 *
124 * If there is a "%s" token in the <root-dir> string, it is replaced
125 * by the ASCII-representation of the client's IP address.
387 */ 126 */
388static int __init nfs_root_setup(char *line) 127static int __init nfs_root_setup(char *line)
389{ 128{
390 ROOT_DEV = Root_NFS; 129 ROOT_DEV = Root_NFS;
130
391 if (line[0] == '/' || line[0] == ',' || (line[0] >= '0' && line[0] <= '9')) { 131 if (line[0] == '/' || line[0] == ',' || (line[0] >= '0' && line[0] <= '9')) {
392 strlcpy(nfs_root_name, line, sizeof(nfs_root_name)); 132 strlcpy(nfs_root_parms, line, sizeof(nfs_root_parms));
393 } else { 133 } else {
394 int n = strlen(line) + sizeof(NFS_ROOT) - 1; 134 size_t n = strlen(line) + sizeof(NFS_ROOT) - 1;
395 if (n >= sizeof(nfs_root_name)) 135 if (n >= sizeof(nfs_root_parms))
396 line[sizeof(nfs_root_name) - sizeof(NFS_ROOT) - 2] = '\0'; 136 line[sizeof(nfs_root_parms) - sizeof(NFS_ROOT) - 2] = '\0';
397 sprintf(nfs_root_name, NFS_ROOT, line); 137 sprintf(nfs_root_parms, NFS_ROOT, line);
398 } 138 }
399 root_server_addr = root_nfs_parse_addr(nfs_root_name); 139
140 /*
141 * Extract the IP address of the NFS server containing our
142 * root file system, if one was specified.
143 *
144 * Note: root_nfs_parse_addr() removes the server-ip from
145 * nfs_root_parms, if it exists.
146 */
147 root_server_addr = root_nfs_parse_addr(nfs_root_parms);
148
400 return 1; 149 return 1;
401} 150}
402 151
403__setup("nfsroot=", nfs_root_setup); 152__setup("nfsroot=", nfs_root_setup);
404 153
405/*************************************************************************** 154static int __init root_nfs_copy(char *dest, const char *src,
406 155 const size_t destlen)
407 Routines to actually mount the root directory 156{
408 157 if (strlcpy(dest, src, destlen) > destlen)
409 ***************************************************************************/ 158 return -1;
159 return 0;
160}
410 161
411/* 162static int __init root_nfs_cat(char *dest, const char *src,
412 * Construct sockaddr_in from address and port number. 163 const size_t destlen)
413 */
414static inline void
415set_sockaddr(struct sockaddr_in *sin, __be32 addr, __be16 port)
416{ 164{
417 sin->sin_family = AF_INET; 165 if (strlcat(dest, src, destlen) > destlen)
418 sin->sin_addr.s_addr = addr; 166 return -1;
419 sin->sin_port = port; 167 return 0;
420} 168}
421 169
422/* 170/*
423 * Query server portmapper for the port of a daemon program. 171 * Parse out root export path and mount options from
172 * passed-in string @incoming.
173 *
174 * Copy the export path into @exppath.
424 */ 175 */
425static int __init root_nfs_getport(int program, int version, int proto) 176static int __init root_nfs_parse_options(char *incoming, char *exppath,
177 const size_t exppathlen)
426{ 178{
427 struct sockaddr_in sin; 179 char *p;
428 180
429 printk(KERN_NOTICE "Looking up port of RPC %d/%d on %pI4\n", 181 /*
430 program, version, &servaddr); 182 * Set the NFS remote path
431 set_sockaddr(&sin, servaddr, 0); 183 */
432 return rpcb_getport_sync(&sin, program, version, proto); 184 p = strsep(&incoming, ",");
433} 185 if (*p != '\0' && strcmp(p, "default") != 0)
186 if (root_nfs_copy(exppath, p, exppathlen))
187 return -1;
188
189 /*
190 * @incoming now points to the rest of the string; if it
191 * contains something, append it to our root options buffer
192 */
193 if (incoming != NULL && *incoming != '\0')
194 if (root_nfs_cat(nfs_root_options, incoming,
195 sizeof(nfs_root_options)))
196 return -1;
434 197
198 /*
199 * Possibly prepare for more options to be appended
200 */
201 if (nfs_root_options[0] != '\0' &&
202 nfs_root_options[strlen(nfs_root_options)] != ',')
203 if (root_nfs_cat(nfs_root_options, ",",
204 sizeof(nfs_root_options)))
205 return -1;
206
207 return 0;
208}
435 209
436/* 210/*
437 * Use portmapper to find mountd and nfsd port numbers if not overriden 211 * Decode the export directory path name and NFS options from
438 * by the user. Use defaults if portmapper is not available. 212 * the kernel command line. This has to be done late in order to
439 * XXX: Is there any nfs server with no portmapper? 213 * use a dynamically acquired client IP address for the remote
214 * root directory path.
215 *
216 * Returns zero if successful; otherwise -1 is returned.
440 */ 217 */
441static int __init root_nfs_ports(void) 218static int __init root_nfs_data(char *cmdline)
442{ 219{
443 int port; 220 char addr_option[sizeof("nolock,addr=") + INET_ADDRSTRLEN + 1];
444 int nfsd_ver, mountd_ver; 221 int len, retval = -1;
445 int nfsd_port, mountd_port; 222 char *tmp = NULL;
446 int proto; 223 const size_t tmplen = sizeof(nfs_export_path);
447 224
448 if (nfs_data.flags & NFS_MOUNT_VER3) { 225 tmp = kzalloc(tmplen, GFP_KERNEL);
449 nfsd_ver = NFS3_VERSION; 226 if (tmp == NULL)
450 mountd_ver = NFS_MNT3_VERSION; 227 goto out_nomem;
451 nfsd_port = NFS_PORT; 228 strcpy(tmp, NFS_ROOT);
452 mountd_port = NFS_MNT_PORT; 229
453 } else { 230 if (root_server_path[0] != '\0') {
454 nfsd_ver = NFS2_VERSION; 231 dprintk("Root-NFS: DHCPv4 option 17: %s\n",
455 mountd_ver = NFS_MNT_VERSION; 232 root_server_path);
456 nfsd_port = NFS_PORT; 233 if (root_nfs_parse_options(root_server_path, tmp, tmplen))
457 mountd_port = NFS_MNT_PORT; 234 goto out_optionstoolong;
458 } 235 }
459 236
460 proto = (nfs_data.flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP; 237 if (cmdline[0] != '\0') {
461 238 dprintk("Root-NFS: nfsroot=%s\n", cmdline);
462 if (nfs_port < 0) { 239 if (root_nfs_parse_options(cmdline, tmp, tmplen))
463 if ((port = root_nfs_getport(NFS_PROGRAM, nfsd_ver, proto)) < 0) { 240 goto out_optionstoolong;
464 printk(KERN_ERR "Root-NFS: Unable to get nfsd port "
465 "number from server, using default\n");
466 port = nfsd_port;
467 }
468 nfs_port = port;
469 dprintk("Root-NFS: Portmapper on server returned %d "
470 "as nfsd port\n", port);
471 } 241 }
472 242
473 if ((port = root_nfs_getport(NFS_MNT_PROGRAM, mountd_ver, proto)) < 0) { 243 /*
474 printk(KERN_ERR "Root-NFS: Unable to get mountd port " 244 * Append mandatory options for nfsroot so they override
475 "number from server, using default\n"); 245 * what has come before
476 port = mountd_port; 246 */
477 } 247 snprintf(addr_option, sizeof(addr_option), "nolock,addr=%pI4",
478 mount_port = port; 248 &servaddr);
479 dprintk("Root-NFS: mountd port is %d\n", port); 249 if (root_nfs_cat(nfs_root_options, addr_option,
250 sizeof(nfs_root_options)))
251 goto out_optionstoolong;
480 252
481 return 0; 253 /*
254 * Set up nfs_root_device. For NFS mounts, this looks like
255 *
256 * server:/path
257 *
258 * At this point, utsname()->nodename contains our local
259 * IP address or hostname, set by ipconfig. If "%s" exists
260 * in tmp, substitute the nodename, then shovel the whole
261 * mess into nfs_root_device.
262 */
263 len = snprintf(nfs_export_path, sizeof(nfs_export_path),
264 tmp, utsname()->nodename);
265 if (len > (int)sizeof(nfs_export_path))
266 goto out_devnametoolong;
267 len = snprintf(nfs_root_device, sizeof(nfs_root_device),
268 "%pI4:%s", &servaddr, nfs_export_path);
269 if (len > (int)sizeof(nfs_root_device))
270 goto out_devnametoolong;
271
272 retval = 0;
273
274out:
275 kfree(tmp);
276 return retval;
277out_nomem:
278 printk(KERN_ERR "Root-NFS: could not allocate memory\n");
279 goto out;
280out_optionstoolong:
281 printk(KERN_ERR "Root-NFS: mount options string too long\n");
282 goto out;
283out_devnametoolong:
284 printk(KERN_ERR "Root-NFS: root device name too long.\n");
285 goto out;
482} 286}
483 287
484 288/**
485/* 289 * nfs_root_data - Return prepared 'data' for NFSROOT mount
486 * Get a file handle from the server for the directory which is to be 290 * @root_device: OUT: address of string containing NFSROOT device
487 * mounted. 291 * @root_data: OUT: address of string containing NFSROOT mount options
292 *
293 * Returns zero and sets @root_device and @root_data if successful,
294 * otherwise -1 is returned.
488 */ 295 */
489static int __init root_nfs_get_handle(void) 296int __init nfs_root_data(char **root_device, char **root_data)
490{ 297{
491 struct nfs_fh fh; 298 servaddr = root_server_addr;
492 struct sockaddr_in sin; 299 if (servaddr == htonl(INADDR_NONE)) {
493 unsigned int auth_flav_len = 0; 300 printk(KERN_ERR "Root-NFS: no NFS server address\n");
494 struct nfs_mount_request request = { 301 return -1;
495 .sap = (struct sockaddr *)&sin,
496 .salen = sizeof(sin),
497 .dirpath = nfs_export_path,
498 .version = (nfs_data.flags & NFS_MOUNT_VER3) ?
499 NFS_MNT3_VERSION : NFS_MNT_VERSION,
500 .protocol = (nfs_data.flags & NFS_MOUNT_TCP) ?
501 XPRT_TRANSPORT_TCP : XPRT_TRANSPORT_UDP,
502 .fh = &fh,
503 .auth_flav_len = &auth_flav_len,
504 };
505 int status;
506
507 set_sockaddr(&sin, servaddr, htons(mount_port));
508 status = nfs_mount(&request);
509 if (status < 0)
510 printk(KERN_ERR "Root-NFS: Server returned error %d "
511 "while mounting %s\n", status, nfs_export_path);
512 else {
513 nfs_data.root.size = fh.size;
514 memcpy(nfs_data.root.data, fh.data, fh.size);
515 } 302 }
516 303
517 return status; 304 if (root_nfs_data(nfs_root_parms) < 0)
518} 305 return -1;
519 306
520/* 307 *root_device = nfs_root_device;
521 * Get the NFS port numbers and file handle, and return the prepared 'data' 308 *root_data = nfs_root_options;
522 * argument for mount() if everything went OK. Return NULL otherwise. 309 return 0;
523 */
524void * __init nfs_root_data(void)
525{
526 if (root_nfs_init() < 0
527 || root_nfs_ports() < 0
528 || root_nfs_get_handle() < 0)
529 return NULL;
530 set_sockaddr((struct sockaddr_in *) &nfs_data.addr, servaddr, htons(nfs_port));
531 return (void*)&nfs_data;
532} 310}
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index e2975939126a..e1164e3f9e69 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -26,12 +26,9 @@ static struct kmem_cache *nfs_page_cachep;
26static inline struct nfs_page * 26static inline struct nfs_page *
27nfs_page_alloc(void) 27nfs_page_alloc(void)
28{ 28{
29 struct nfs_page *p; 29 struct nfs_page *p = kmem_cache_zalloc(nfs_page_cachep, GFP_KERNEL);
30 p = kmem_cache_alloc(nfs_page_cachep, GFP_KERNEL); 30 if (p)
31 if (p) {
32 memset(p, 0, sizeof(*p));
33 INIT_LIST_HEAD(&p->wb_list); 31 INIT_LIST_HEAD(&p->wb_list);
34 }
35 return p; 32 return p;
36} 33}
37 34
@@ -60,15 +57,16 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
60{ 57{
61 struct nfs_page *req; 58 struct nfs_page *req;
62 59
63 for (;;) { 60 /* try to allocate the request struct */
64 /* try to allocate the request struct */ 61 req = nfs_page_alloc();
65 req = nfs_page_alloc(); 62 if (req == NULL)
66 if (req != NULL) 63 return ERR_PTR(-ENOMEM);
67 break;
68 64
69 if (fatal_signal_pending(current)) 65 /* get lock context early so we can deal with alloc failures */
70 return ERR_PTR(-ERESTARTSYS); 66 req->wb_lock_context = nfs_get_lock_context(ctx);
71 yield(); 67 if (req->wb_lock_context == NULL) {
68 nfs_page_free(req);
69 return ERR_PTR(-ENOMEM);
72 } 70 }
73 71
74 /* Initialize the request struct. Initially, we assume a 72 /* Initialize the request struct. Initially, we assume a
@@ -112,12 +110,10 @@ void nfs_unlock_request(struct nfs_page *req)
112 */ 110 */
113int nfs_set_page_tag_locked(struct nfs_page *req) 111int nfs_set_page_tag_locked(struct nfs_page *req)
114{ 112{
115 struct nfs_inode *nfsi = NFS_I(req->wb_context->path.dentry->d_inode);
116
117 if (!nfs_lock_request_dontget(req)) 113 if (!nfs_lock_request_dontget(req))
118 return 0; 114 return 0;
119 if (req->wb_page != NULL) 115 if (test_bit(PG_MAPPED, &req->wb_flags))
120 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED); 116 radix_tree_tag_set(&NFS_I(req->wb_context->path.dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
121 return 1; 117 return 1;
122} 118}
123 119
@@ -126,10 +122,10 @@ int nfs_set_page_tag_locked(struct nfs_page *req)
126 */ 122 */
127void nfs_clear_page_tag_locked(struct nfs_page *req) 123void nfs_clear_page_tag_locked(struct nfs_page *req)
128{ 124{
129 struct inode *inode = req->wb_context->path.dentry->d_inode; 125 if (test_bit(PG_MAPPED, &req->wb_flags)) {
130 struct nfs_inode *nfsi = NFS_I(inode); 126 struct inode *inode = req->wb_context->path.dentry->d_inode;
127 struct nfs_inode *nfsi = NFS_I(inode);
131 128
132 if (req->wb_page != NULL) {
133 spin_lock(&inode->i_lock); 129 spin_lock(&inode->i_lock);
134 radix_tree_tag_clear(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED); 130 radix_tree_tag_clear(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
135 nfs_unlock_request(req); 131 nfs_unlock_request(req);
@@ -142,16 +138,27 @@ void nfs_clear_page_tag_locked(struct nfs_page *req)
142 * nfs_clear_request - Free up all resources allocated to the request 138 * nfs_clear_request - Free up all resources allocated to the request
143 * @req: 139 * @req:
144 * 140 *
145 * Release page resources associated with a write request after it 141 * Release page and open context resources associated with a read/write
146 * has completed. 142 * request after it has completed.
147 */ 143 */
148void nfs_clear_request(struct nfs_page *req) 144void nfs_clear_request(struct nfs_page *req)
149{ 145{
150 struct page *page = req->wb_page; 146 struct page *page = req->wb_page;
147 struct nfs_open_context *ctx = req->wb_context;
148 struct nfs_lock_context *l_ctx = req->wb_lock_context;
149
151 if (page != NULL) { 150 if (page != NULL) {
152 page_cache_release(page); 151 page_cache_release(page);
153 req->wb_page = NULL; 152 req->wb_page = NULL;
154 } 153 }
154 if (l_ctx != NULL) {
155 nfs_put_lock_context(l_ctx);
156 req->wb_lock_context = NULL;
157 }
158 if (ctx != NULL) {
159 put_nfs_open_context(ctx);
160 req->wb_context = NULL;
161 }
155} 162}
156 163
157 164
@@ -165,9 +172,8 @@ static void nfs_free_request(struct kref *kref)
165{ 172{
166 struct nfs_page *req = container_of(kref, struct nfs_page, wb_kref); 173 struct nfs_page *req = container_of(kref, struct nfs_page, wb_kref);
167 174
168 /* Release struct file or cached credential */ 175 /* Release struct file and open context */
169 nfs_clear_request(req); 176 nfs_clear_request(req);
170 put_nfs_open_context(req->wb_context);
171 nfs_page_free(req); 177 nfs_page_free(req);
172} 178}
173 179
@@ -176,6 +182,12 @@ void nfs_release_request(struct nfs_page *req)
176 kref_put(&req->wb_kref, nfs_free_request); 182 kref_put(&req->wb_kref, nfs_free_request);
177} 183}
178 184
185static int nfs_wait_bit_uninterruptible(void *word)
186{
187 io_schedule();
188 return 0;
189}
190
179/** 191/**
180 * nfs_wait_on_request - Wait for a request to complete. 192 * nfs_wait_on_request - Wait for a request to complete.
181 * @req: request to wait upon. 193 * @req: request to wait upon.
@@ -186,14 +198,9 @@ void nfs_release_request(struct nfs_page *req)
186int 198int
187nfs_wait_on_request(struct nfs_page *req) 199nfs_wait_on_request(struct nfs_page *req)
188{ 200{
189 int ret = 0; 201 return wait_on_bit(&req->wb_flags, PG_BUSY,
190 202 nfs_wait_bit_uninterruptible,
191 if (!test_bit(PG_BUSY, &req->wb_flags)) 203 TASK_UNINTERRUPTIBLE);
192 goto out;
193 ret = out_of_line_wait_on_bit(&req->wb_flags, PG_BUSY,
194 nfs_wait_bit_killable, TASK_KILLABLE);
195out:
196 return ret;
197} 204}
198 205
199/** 206/**
@@ -237,7 +244,7 @@ static int nfs_can_coalesce_requests(struct nfs_page *prev,
237{ 244{
238 if (req->wb_context->cred != prev->wb_context->cred) 245 if (req->wb_context->cred != prev->wb_context->cred)
239 return 0; 246 return 0;
240 if (req->wb_context->lockowner != prev->wb_context->lockowner) 247 if (req->wb_lock_context->lockowner != prev->wb_lock_context->lockowner)
241 return 0; 248 return 0;
242 if (req->wb_context->state != prev->wb_context->state) 249 if (req->wb_context->state != prev->wb_context->state)
243 return 0; 250 return 0;
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
new file mode 100644
index 000000000000..bc4089769735
--- /dev/null
+++ b/fs/nfs/pnfs.c
@@ -0,0 +1,965 @@
1/*
2 * pNFS functions to call and manage layout drivers.
3 *
4 * Copyright (c) 2002 [year of first publication]
5 * The Regents of the University of Michigan
6 * All Rights Reserved
7 *
8 * Dean Hildebrand <dhildebz@umich.edu>
9 *
10 * Permission is granted to use, copy, create derivative works, and
11 * redistribute this software and such derivative works for any purpose,
12 * so long as the name of the University of Michigan is not used in
13 * any advertising or publicity pertaining to the use or distribution
14 * of this software without specific, written prior authorization. If
15 * the above copyright notice or any other identification of the
16 * University of Michigan is included in any copy of any portion of
17 * this software, then the disclaimer below must also be included.
18 *
19 * This software is provided as is, without representation or warranty
20 * of any kind either express or implied, including without limitation
21 * the implied warranties of merchantability, fitness for a particular
22 * purpose, or noninfringement. The Regents of the University of
23 * Michigan shall not be liable for any damages, including special,
24 * indirect, incidental, or consequential damages, with respect to any
25 * claim arising out of or in connection with the use of the software,
26 * even if it has been or is hereafter advised of the possibility of
27 * such damages.
28 */
29
30#include <linux/nfs_fs.h>
31#include "internal.h"
32#include "pnfs.h"
33
34#define NFSDBG_FACILITY NFSDBG_PNFS
35
36/* Locking:
37 *
38 * pnfs_spinlock:
39 * protects pnfs_modules_tbl.
40 */
41static DEFINE_SPINLOCK(pnfs_spinlock);
42
43/*
44 * pnfs_modules_tbl holds all pnfs modules
45 */
46static LIST_HEAD(pnfs_modules_tbl);
47
48/* Return the registered pnfs layout driver module matching given id */
49static struct pnfs_layoutdriver_type *
50find_pnfs_driver_locked(u32 id)
51{
52 struct pnfs_layoutdriver_type *local;
53
54 list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid)
55 if (local->id == id)
56 goto out;
57 local = NULL;
58out:
59 dprintk("%s: Searching for id %u, found %p\n", __func__, id, local);
60 return local;
61}
62
63static struct pnfs_layoutdriver_type *
64find_pnfs_driver(u32 id)
65{
66 struct pnfs_layoutdriver_type *local;
67
68 spin_lock(&pnfs_spinlock);
69 local = find_pnfs_driver_locked(id);
70 spin_unlock(&pnfs_spinlock);
71 return local;
72}
73
74void
75unset_pnfs_layoutdriver(struct nfs_server *nfss)
76{
77 if (nfss->pnfs_curr_ld) {
78 nfss->pnfs_curr_ld->clear_layoutdriver(nfss);
79 module_put(nfss->pnfs_curr_ld->owner);
80 }
81 nfss->pnfs_curr_ld = NULL;
82}
83
84/*
85 * Try to set the server's pnfs module to the pnfs layout type specified by id.
86 * Currently only one pNFS layout driver per filesystem is supported.
87 *
88 * @id layout type. Zero (illegal layout type) indicates pNFS not in use.
89 */
90void
91set_pnfs_layoutdriver(struct nfs_server *server, u32 id)
92{
93 struct pnfs_layoutdriver_type *ld_type = NULL;
94
95 if (id == 0)
96 goto out_no_driver;
97 if (!(server->nfs_client->cl_exchange_flags &
98 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
99 printk(KERN_ERR "%s: id %u cl_exchange_flags 0x%x\n", __func__,
100 id, server->nfs_client->cl_exchange_flags);
101 goto out_no_driver;
102 }
103 ld_type = find_pnfs_driver(id);
104 if (!ld_type) {
105 request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id);
106 ld_type = find_pnfs_driver(id);
107 if (!ld_type) {
108 dprintk("%s: No pNFS module found for %u.\n",
109 __func__, id);
110 goto out_no_driver;
111 }
112 }
113 if (!try_module_get(ld_type->owner)) {
114 dprintk("%s: Could not grab reference on module\n", __func__);
115 goto out_no_driver;
116 }
117 server->pnfs_curr_ld = ld_type;
118 if (ld_type->set_layoutdriver(server)) {
119 printk(KERN_ERR
120 "%s: Error initializing mount point for layout driver %u.\n",
121 __func__, id);
122 module_put(ld_type->owner);
123 goto out_no_driver;
124 }
125 dprintk("%s: pNFS module for %u set\n", __func__, id);
126 return;
127
128out_no_driver:
129 dprintk("%s: Using NFSv4 I/O\n", __func__);
130 server->pnfs_curr_ld = NULL;
131}
132
133int
134pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
135{
136 int status = -EINVAL;
137 struct pnfs_layoutdriver_type *tmp;
138
139 if (ld_type->id == 0) {
140 printk(KERN_ERR "%s id 0 is reserved\n", __func__);
141 return status;
142 }
143 if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
144 printk(KERN_ERR "%s Layout driver must provide "
145 "alloc_lseg and free_lseg.\n", __func__);
146 return status;
147 }
148
149 spin_lock(&pnfs_spinlock);
150 tmp = find_pnfs_driver_locked(ld_type->id);
151 if (!tmp) {
152 list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl);
153 status = 0;
154 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
155 ld_type->name);
156 } else {
157 printk(KERN_ERR "%s Module with id %d already loaded!\n",
158 __func__, ld_type->id);
159 }
160 spin_unlock(&pnfs_spinlock);
161
162 return status;
163}
164EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver);
165
166void
167pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
168{
169 dprintk("%s Deregistering id:%u\n", __func__, ld_type->id);
170 spin_lock(&pnfs_spinlock);
171 list_del(&ld_type->pnfs_tblid);
172 spin_unlock(&pnfs_spinlock);
173}
174EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver);
175
176/*
177 * pNFS client layout cache
178 */
179
180/* Need to hold i_lock if caller does not already hold reference */
181void
182get_layout_hdr(struct pnfs_layout_hdr *lo)
183{
184 atomic_inc(&lo->plh_refcount);
185}
186
187static void
188destroy_layout_hdr(struct pnfs_layout_hdr *lo)
189{
190 dprintk("%s: freeing layout cache %p\n", __func__, lo);
191 BUG_ON(!list_empty(&lo->plh_layouts));
192 NFS_I(lo->plh_inode)->layout = NULL;
193 kfree(lo);
194}
195
196static void
197put_layout_hdr_locked(struct pnfs_layout_hdr *lo)
198{
199 if (atomic_dec_and_test(&lo->plh_refcount))
200 destroy_layout_hdr(lo);
201}
202
203void
204put_layout_hdr(struct pnfs_layout_hdr *lo)
205{
206 struct inode *inode = lo->plh_inode;
207
208 if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
209 destroy_layout_hdr(lo);
210 spin_unlock(&inode->i_lock);
211 }
212}
213
214static void
215init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg)
216{
217 INIT_LIST_HEAD(&lseg->pls_list);
218 atomic_set(&lseg->pls_refcount, 1);
219 smp_mb();
220 set_bit(NFS_LSEG_VALID, &lseg->pls_flags);
221 lseg->pls_layout = lo;
222}
223
224static void free_lseg(struct pnfs_layout_segment *lseg)
225{
226 struct inode *ino = lseg->pls_layout->plh_inode;
227
228 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
229 /* Matched by get_layout_hdr in pnfs_insert_layout */
230 put_layout_hdr(NFS_I(ino)->layout);
231}
232
233/* The use of tmp_list is necessary because pnfs_curr_ld->free_lseg
234 * could sleep, so must be called outside of the lock.
235 * Returns 1 if object was removed, otherwise return 0.
236 */
237static int
238put_lseg_locked(struct pnfs_layout_segment *lseg,
239 struct list_head *tmp_list)
240{
241 dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg,
242 atomic_read(&lseg->pls_refcount),
243 test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
244 if (atomic_dec_and_test(&lseg->pls_refcount)) {
245 struct inode *ino = lseg->pls_layout->plh_inode;
246
247 BUG_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
248 list_del(&lseg->pls_list);
249 if (list_empty(&lseg->pls_layout->plh_segs)) {
250 struct nfs_client *clp;
251
252 clp = NFS_SERVER(ino)->nfs_client;
253 spin_lock(&clp->cl_lock);
254 /* List does not take a reference, so no need for put here */
255 list_del_init(&lseg->pls_layout->plh_layouts);
256 spin_unlock(&clp->cl_lock);
257 clear_bit(NFS_LAYOUT_BULK_RECALL, &lseg->pls_layout->plh_flags);
258 }
259 rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq);
260 list_add(&lseg->pls_list, tmp_list);
261 return 1;
262 }
263 return 0;
264}
265
266static bool
267should_free_lseg(u32 lseg_iomode, u32 recall_iomode)
268{
269 return (recall_iomode == IOMODE_ANY ||
270 lseg_iomode == recall_iomode);
271}
272
273/* Returns 1 if lseg is removed from list, 0 otherwise */
274static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
275 struct list_head *tmp_list)
276{
277 int rv = 0;
278
279 if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) {
280 /* Remove the reference keeping the lseg in the
281 * list. It will now be removed when all
282 * outstanding io is finished.
283 */
284 rv = put_lseg_locked(lseg, tmp_list);
285 }
286 return rv;
287}
288
289/* Returns count of number of matching invalid lsegs remaining in list
290 * after call.
291 */
292int
293mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
294 struct list_head *tmp_list,
295 u32 iomode)
296{
297 struct pnfs_layout_segment *lseg, *next;
298 int invalid = 0, removed = 0;
299
300 dprintk("%s:Begin lo %p\n", __func__, lo);
301
302 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
303 if (should_free_lseg(lseg->pls_range.iomode, iomode)) {
304 dprintk("%s: freeing lseg %p iomode %d "
305 "offset %llu length %llu\n", __func__,
306 lseg, lseg->pls_range.iomode, lseg->pls_range.offset,
307 lseg->pls_range.length);
308 invalid++;
309 removed += mark_lseg_invalid(lseg, tmp_list);
310 }
311 dprintk("%s:Return %i\n", __func__, invalid - removed);
312 return invalid - removed;
313}
314
315void
316pnfs_free_lseg_list(struct list_head *free_me)
317{
318 struct pnfs_layout_segment *lseg, *tmp;
319
320 list_for_each_entry_safe(lseg, tmp, free_me, pls_list) {
321 list_del(&lseg->pls_list);
322 free_lseg(lseg);
323 }
324}
325
326void
327pnfs_destroy_layout(struct nfs_inode *nfsi)
328{
329 struct pnfs_layout_hdr *lo;
330 LIST_HEAD(tmp_list);
331
332 spin_lock(&nfsi->vfs_inode.i_lock);
333 lo = nfsi->layout;
334 if (lo) {
335 set_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags);
336 mark_matching_lsegs_invalid(lo, &tmp_list, IOMODE_ANY);
337 /* Matched by refcount set to 1 in alloc_init_layout_hdr */
338 put_layout_hdr_locked(lo);
339 }
340 spin_unlock(&nfsi->vfs_inode.i_lock);
341 pnfs_free_lseg_list(&tmp_list);
342}
343
344/*
345 * Called by the state manger to remove all layouts established under an
346 * expired lease.
347 */
348void
349pnfs_destroy_all_layouts(struct nfs_client *clp)
350{
351 struct pnfs_layout_hdr *lo;
352 LIST_HEAD(tmp_list);
353
354 spin_lock(&clp->cl_lock);
355 list_splice_init(&clp->cl_layouts, &tmp_list);
356 spin_unlock(&clp->cl_lock);
357
358 while (!list_empty(&tmp_list)) {
359 lo = list_entry(tmp_list.next, struct pnfs_layout_hdr,
360 plh_layouts);
361 dprintk("%s freeing layout for inode %lu\n", __func__,
362 lo->plh_inode->i_ino);
363 pnfs_destroy_layout(NFS_I(lo->plh_inode));
364 }
365}
366
367/* update lo->plh_stateid with new if is more recent */
368void
369pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
370 bool update_barrier)
371{
372 u32 oldseq, newseq;
373
374 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
375 newseq = be32_to_cpu(new->stateid.seqid);
376 if ((int)(newseq - oldseq) > 0) {
377 memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid));
378 if (update_barrier) {
379 u32 new_barrier = be32_to_cpu(new->stateid.seqid);
380
381 if ((int)(new_barrier - lo->plh_barrier))
382 lo->plh_barrier = new_barrier;
383 } else {
384 /* Because of wraparound, we want to keep the barrier
385 * "close" to the current seqids. It needs to be
386 * within 2**31 to count as "behind", so if it
387 * gets too near that limit, give us a litle leeway
388 * and bring it to within 2**30.
389 * NOTE - and yes, this is all unsigned arithmetic.
390 */
391 if (unlikely((newseq - lo->plh_barrier) > (3 << 29)))
392 lo->plh_barrier = newseq - (1 << 30);
393 }
394 }
395}
396
397/* lget is set to 1 if called from inside send_layoutget call chain */
398static bool
399pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
400 int lget)
401{
402 if ((stateid) &&
403 (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0)
404 return true;
405 return lo->plh_block_lgets ||
406 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
407 (list_empty(&lo->plh_segs) &&
408 (atomic_read(&lo->plh_outstanding) > lget));
409}
410
411int
412pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
413 struct nfs4_state *open_state)
414{
415 int status = 0;
416
417 dprintk("--> %s\n", __func__);
418 spin_lock(&lo->plh_inode->i_lock);
419 if (pnfs_layoutgets_blocked(lo, NULL, 1)) {
420 status = -EAGAIN;
421 } else if (list_empty(&lo->plh_segs)) {
422 int seq;
423
424 do {
425 seq = read_seqbegin(&open_state->seqlock);
426 memcpy(dst->data, open_state->stateid.data,
427 sizeof(open_state->stateid.data));
428 } while (read_seqretry(&open_state->seqlock, seq));
429 } else
430 memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data));
431 spin_unlock(&lo->plh_inode->i_lock);
432 dprintk("<-- %s\n", __func__);
433 return status;
434}
435
436/*
437* Get layout from server.
438* for now, assume that whole file layouts are requested.
439* arg->offset: 0
440* arg->length: all ones
441*/
442static struct pnfs_layout_segment *
443send_layoutget(struct pnfs_layout_hdr *lo,
444 struct nfs_open_context *ctx,
445 u32 iomode)
446{
447 struct inode *ino = lo->plh_inode;
448 struct nfs_server *server = NFS_SERVER(ino);
449 struct nfs4_layoutget *lgp;
450 struct pnfs_layout_segment *lseg = NULL;
451
452 dprintk("--> %s\n", __func__);
453
454 BUG_ON(ctx == NULL);
455 lgp = kzalloc(sizeof(*lgp), GFP_KERNEL);
456 if (lgp == NULL)
457 return NULL;
458 lgp->args.minlength = NFS4_MAX_UINT64;
459 lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE;
460 lgp->args.range.iomode = iomode;
461 lgp->args.range.offset = 0;
462 lgp->args.range.length = NFS4_MAX_UINT64;
463 lgp->args.type = server->pnfs_curr_ld->id;
464 lgp->args.inode = ino;
465 lgp->args.ctx = get_nfs_open_context(ctx);
466 lgp->lsegpp = &lseg;
467
468 /* Synchronously retrieve layout information from server and
469 * store in lseg.
470 */
471 nfs4_proc_layoutget(lgp);
472 if (!lseg) {
473 /* remember that LAYOUTGET failed and suspend trying */
474 set_bit(lo_fail_bit(iomode), &lo->plh_flags);
475 }
476 return lseg;
477}
478
479bool pnfs_roc(struct inode *ino)
480{
481 struct pnfs_layout_hdr *lo;
482 struct pnfs_layout_segment *lseg, *tmp;
483 LIST_HEAD(tmp_list);
484 bool found = false;
485
486 spin_lock(&ino->i_lock);
487 lo = NFS_I(ino)->layout;
488 if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) ||
489 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags))
490 goto out_nolayout;
491 list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list)
492 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
493 mark_lseg_invalid(lseg, &tmp_list);
494 found = true;
495 }
496 if (!found)
497 goto out_nolayout;
498 lo->plh_block_lgets++;
499 get_layout_hdr(lo); /* matched in pnfs_roc_release */
500 spin_unlock(&ino->i_lock);
501 pnfs_free_lseg_list(&tmp_list);
502 return true;
503
504out_nolayout:
505 spin_unlock(&ino->i_lock);
506 return false;
507}
508
509void pnfs_roc_release(struct inode *ino)
510{
511 struct pnfs_layout_hdr *lo;
512
513 spin_lock(&ino->i_lock);
514 lo = NFS_I(ino)->layout;
515 lo->plh_block_lgets--;
516 put_layout_hdr_locked(lo);
517 spin_unlock(&ino->i_lock);
518}
519
520void pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
521{
522 struct pnfs_layout_hdr *lo;
523
524 spin_lock(&ino->i_lock);
525 lo = NFS_I(ino)->layout;
526 if ((int)(barrier - lo->plh_barrier) > 0)
527 lo->plh_barrier = barrier;
528 spin_unlock(&ino->i_lock);
529}
530
531bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
532{
533 struct nfs_inode *nfsi = NFS_I(ino);
534 struct pnfs_layout_segment *lseg;
535 bool found = false;
536
537 spin_lock(&ino->i_lock);
538 list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list)
539 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
540 found = true;
541 break;
542 }
543 if (!found) {
544 struct pnfs_layout_hdr *lo = nfsi->layout;
545 u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid);
546
547 /* Since close does not return a layout stateid for use as
548 * a barrier, we choose the worst-case barrier.
549 */
550 *barrier = current_seqid + atomic_read(&lo->plh_outstanding);
551 }
552 spin_unlock(&ino->i_lock);
553 return found;
554}
555
556/*
557 * Compare two layout segments for sorting into layout cache.
558 * We want to preferentially return RW over RO layouts, so ensure those
559 * are seen first.
560 */
561static s64
562cmp_layout(u32 iomode1, u32 iomode2)
563{
564 /* read > read/write */
565 return (int)(iomode2 == IOMODE_READ) - (int)(iomode1 == IOMODE_READ);
566}
567
568static void
569pnfs_insert_layout(struct pnfs_layout_hdr *lo,
570 struct pnfs_layout_segment *lseg)
571{
572 struct pnfs_layout_segment *lp;
573 int found = 0;
574
575 dprintk("%s:Begin\n", __func__);
576
577 assert_spin_locked(&lo->plh_inode->i_lock);
578 list_for_each_entry(lp, &lo->plh_segs, pls_list) {
579 if (cmp_layout(lp->pls_range.iomode, lseg->pls_range.iomode) > 0)
580 continue;
581 list_add_tail(&lseg->pls_list, &lp->pls_list);
582 dprintk("%s: inserted lseg %p "
583 "iomode %d offset %llu length %llu before "
584 "lp %p iomode %d offset %llu length %llu\n",
585 __func__, lseg, lseg->pls_range.iomode,
586 lseg->pls_range.offset, lseg->pls_range.length,
587 lp, lp->pls_range.iomode, lp->pls_range.offset,
588 lp->pls_range.length);
589 found = 1;
590 break;
591 }
592 if (!found) {
593 list_add_tail(&lseg->pls_list, &lo->plh_segs);
594 dprintk("%s: inserted lseg %p "
595 "iomode %d offset %llu length %llu at tail\n",
596 __func__, lseg, lseg->pls_range.iomode,
597 lseg->pls_range.offset, lseg->pls_range.length);
598 }
599 get_layout_hdr(lo);
600
601 dprintk("%s:Return\n", __func__);
602}
603
604static struct pnfs_layout_hdr *
605alloc_init_layout_hdr(struct inode *ino)
606{
607 struct pnfs_layout_hdr *lo;
608
609 lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL);
610 if (!lo)
611 return NULL;
612 atomic_set(&lo->plh_refcount, 1);
613 INIT_LIST_HEAD(&lo->plh_layouts);
614 INIT_LIST_HEAD(&lo->plh_segs);
615 INIT_LIST_HEAD(&lo->plh_bulk_recall);
616 lo->plh_inode = ino;
617 return lo;
618}
619
620static struct pnfs_layout_hdr *
621pnfs_find_alloc_layout(struct inode *ino)
622{
623 struct nfs_inode *nfsi = NFS_I(ino);
624 struct pnfs_layout_hdr *new = NULL;
625
626 dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout);
627
628 assert_spin_locked(&ino->i_lock);
629 if (nfsi->layout) {
630 if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags))
631 return NULL;
632 else
633 return nfsi->layout;
634 }
635 spin_unlock(&ino->i_lock);
636 new = alloc_init_layout_hdr(ino);
637 spin_lock(&ino->i_lock);
638
639 if (likely(nfsi->layout == NULL)) /* Won the race? */
640 nfsi->layout = new;
641 else
642 kfree(new);
643 return nfsi->layout;
644}
645
646/*
647 * iomode matching rules:
648 * iomode lseg match
649 * ----- ----- -----
650 * ANY READ true
651 * ANY RW true
652 * RW READ false
653 * RW RW true
654 * READ READ true
655 * READ RW true
656 */
657static int
658is_matching_lseg(struct pnfs_layout_segment *lseg, u32 iomode)
659{
660 return (iomode != IOMODE_RW || lseg->pls_range.iomode == IOMODE_RW);
661}
662
663/*
664 * lookup range in layout
665 */
666static struct pnfs_layout_segment *
667pnfs_find_lseg(struct pnfs_layout_hdr *lo, u32 iomode)
668{
669 struct pnfs_layout_segment *lseg, *ret = NULL;
670
671 dprintk("%s:Begin\n", __func__);
672
673 assert_spin_locked(&lo->plh_inode->i_lock);
674 list_for_each_entry(lseg, &lo->plh_segs, pls_list) {
675 if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) &&
676 is_matching_lseg(lseg, iomode)) {
677 ret = lseg;
678 break;
679 }
680 if (cmp_layout(iomode, lseg->pls_range.iomode) > 0)
681 break;
682 }
683
684 dprintk("%s:Return lseg %p ref %d\n",
685 __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0);
686 return ret;
687}
688
689/*
690 * Layout segment is retreived from the server if not cached.
691 * The appropriate layout segment is referenced and returned to the caller.
692 */
693struct pnfs_layout_segment *
694pnfs_update_layout(struct inode *ino,
695 struct nfs_open_context *ctx,
696 enum pnfs_iomode iomode)
697{
698 struct nfs_inode *nfsi = NFS_I(ino);
699 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
700 struct pnfs_layout_hdr *lo;
701 struct pnfs_layout_segment *lseg = NULL;
702
703 if (!pnfs_enabled_sb(NFS_SERVER(ino)))
704 return NULL;
705 spin_lock(&ino->i_lock);
706 lo = pnfs_find_alloc_layout(ino);
707 if (lo == NULL) {
708 dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__);
709 goto out_unlock;
710 }
711
712 /* Do we even need to bother with this? */
713 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) ||
714 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
715 dprintk("%s matches recall, use MDS\n", __func__);
716 goto out_unlock;
717 }
718 /* Check to see if the layout for the given range already exists */
719 lseg = pnfs_find_lseg(lo, iomode);
720 if (lseg)
721 goto out_unlock;
722
723 /* if LAYOUTGET already failed once we don't try again */
724 if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags))
725 goto out_unlock;
726
727 if (pnfs_layoutgets_blocked(lo, NULL, 0))
728 goto out_unlock;
729 atomic_inc(&lo->plh_outstanding);
730
731 get_layout_hdr(lo);
732 if (list_empty(&lo->plh_segs)) {
733 /* The lo must be on the clp list if there is any
734 * chance of a CB_LAYOUTRECALL(FILE) coming in.
735 */
736 spin_lock(&clp->cl_lock);
737 BUG_ON(!list_empty(&lo->plh_layouts));
738 list_add_tail(&lo->plh_layouts, &clp->cl_layouts);
739 spin_unlock(&clp->cl_lock);
740 }
741 spin_unlock(&ino->i_lock);
742
743 lseg = send_layoutget(lo, ctx, iomode);
744 if (!lseg) {
745 spin_lock(&ino->i_lock);
746 if (list_empty(&lo->plh_segs)) {
747 spin_lock(&clp->cl_lock);
748 list_del_init(&lo->plh_layouts);
749 spin_unlock(&clp->cl_lock);
750 clear_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
751 }
752 spin_unlock(&ino->i_lock);
753 }
754 atomic_dec(&lo->plh_outstanding);
755 put_layout_hdr(lo);
756out:
757 dprintk("%s end, state 0x%lx lseg %p\n", __func__,
758 nfsi->layout->plh_flags, lseg);
759 return lseg;
760out_unlock:
761 spin_unlock(&ino->i_lock);
762 goto out;
763}
764
765int
766pnfs_layout_process(struct nfs4_layoutget *lgp)
767{
768 struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout;
769 struct nfs4_layoutget_res *res = &lgp->res;
770 struct pnfs_layout_segment *lseg;
771 struct inode *ino = lo->plh_inode;
772 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
773 int status = 0;
774
775 /* Verify we got what we asked for.
776 * Note that because the xdr parsing only accepts a single
777 * element array, this can fail even if the server is behaving
778 * correctly.
779 */
780 if (lgp->args.range.iomode > res->range.iomode ||
781 res->range.offset != 0 ||
782 res->range.length != NFS4_MAX_UINT64) {
783 status = -EINVAL;
784 goto out;
785 }
786 /* Inject layout blob into I/O device driver */
787 lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res);
788 if (!lseg || IS_ERR(lseg)) {
789 if (!lseg)
790 status = -ENOMEM;
791 else
792 status = PTR_ERR(lseg);
793 dprintk("%s: Could not allocate layout: error %d\n",
794 __func__, status);
795 goto out;
796 }
797
798 spin_lock(&ino->i_lock);
799 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) ||
800 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
801 dprintk("%s forget reply due to recall\n", __func__);
802 goto out_forget_reply;
803 }
804
805 if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) {
806 dprintk("%s forget reply due to state\n", __func__);
807 goto out_forget_reply;
808 }
809 init_lseg(lo, lseg);
810 lseg->pls_range = res->range;
811 *lgp->lsegpp = lseg;
812 pnfs_insert_layout(lo, lseg);
813
814 if (res->return_on_close) {
815 set_bit(NFS_LSEG_ROC, &lseg->pls_flags);
816 set_bit(NFS_LAYOUT_ROC, &lo->plh_flags);
817 }
818
819 /* Done processing layoutget. Set the layout stateid */
820 pnfs_set_layout_stateid(lo, &res->stateid, false);
821 spin_unlock(&ino->i_lock);
822out:
823 return status;
824
825out_forget_reply:
826 spin_unlock(&ino->i_lock);
827 lseg->pls_layout = lo;
828 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
829 goto out;
830}
831
832/*
833 * Device ID cache. Currently supports one layout type per struct nfs_client.
834 * Add layout type to the lookup key to expand to support multiple types.
835 */
836int
837pnfs_alloc_init_deviceid_cache(struct nfs_client *clp,
838 void (*free_callback)(struct pnfs_deviceid_node *))
839{
840 struct pnfs_deviceid_cache *c;
841
842 c = kzalloc(sizeof(struct pnfs_deviceid_cache), GFP_KERNEL);
843 if (!c)
844 return -ENOMEM;
845 spin_lock(&clp->cl_lock);
846 if (clp->cl_devid_cache != NULL) {
847 atomic_inc(&clp->cl_devid_cache->dc_ref);
848 dprintk("%s [kref [%d]]\n", __func__,
849 atomic_read(&clp->cl_devid_cache->dc_ref));
850 kfree(c);
851 } else {
852 /* kzalloc initializes hlists */
853 spin_lock_init(&c->dc_lock);
854 atomic_set(&c->dc_ref, 1);
855 c->dc_free_callback = free_callback;
856 clp->cl_devid_cache = c;
857 dprintk("%s [new]\n", __func__);
858 }
859 spin_unlock(&clp->cl_lock);
860 return 0;
861}
862EXPORT_SYMBOL_GPL(pnfs_alloc_init_deviceid_cache);
863
864/*
865 * Called from pnfs_layoutdriver_type->free_lseg
866 * last layout segment reference frees deviceid
867 */
868void
869pnfs_put_deviceid(struct pnfs_deviceid_cache *c,
870 struct pnfs_deviceid_node *devid)
871{
872 struct nfs4_deviceid *id = &devid->de_id;
873 struct pnfs_deviceid_node *d;
874 struct hlist_node *n;
875 long h = nfs4_deviceid_hash(id);
876
877 dprintk("%s [%d]\n", __func__, atomic_read(&devid->de_ref));
878 if (!atomic_dec_and_lock(&devid->de_ref, &c->dc_lock))
879 return;
880
881 hlist_for_each_entry_rcu(d, n, &c->dc_deviceids[h], de_node)
882 if (!memcmp(&d->de_id, id, sizeof(*id))) {
883 hlist_del_rcu(&d->de_node);
884 spin_unlock(&c->dc_lock);
885 synchronize_rcu();
886 c->dc_free_callback(devid);
887 return;
888 }
889 spin_unlock(&c->dc_lock);
890 /* Why wasn't it found in the list? */
891 BUG();
892}
893EXPORT_SYMBOL_GPL(pnfs_put_deviceid);
894
895/* Find and reference a deviceid */
896struct pnfs_deviceid_node *
897pnfs_find_get_deviceid(struct pnfs_deviceid_cache *c, struct nfs4_deviceid *id)
898{
899 struct pnfs_deviceid_node *d;
900 struct hlist_node *n;
901 long hash = nfs4_deviceid_hash(id);
902
903 dprintk("--> %s hash %ld\n", __func__, hash);
904 rcu_read_lock();
905 hlist_for_each_entry_rcu(d, n, &c->dc_deviceids[hash], de_node) {
906 if (!memcmp(&d->de_id, id, sizeof(*id))) {
907 if (!atomic_inc_not_zero(&d->de_ref)) {
908 goto fail;
909 } else {
910 rcu_read_unlock();
911 return d;
912 }
913 }
914 }
915fail:
916 rcu_read_unlock();
917 return NULL;
918}
919EXPORT_SYMBOL_GPL(pnfs_find_get_deviceid);
920
921/*
922 * Add a deviceid to the cache.
923 * GETDEVICEINFOs for same deviceid can race. If deviceid is found, discard new
924 */
925struct pnfs_deviceid_node *
926pnfs_add_deviceid(struct pnfs_deviceid_cache *c, struct pnfs_deviceid_node *new)
927{
928 struct pnfs_deviceid_node *d;
929 long hash = nfs4_deviceid_hash(&new->de_id);
930
931 dprintk("--> %s hash %ld\n", __func__, hash);
932 spin_lock(&c->dc_lock);
933 d = pnfs_find_get_deviceid(c, &new->de_id);
934 if (d) {
935 spin_unlock(&c->dc_lock);
936 dprintk("%s [discard]\n", __func__);
937 c->dc_free_callback(new);
938 return d;
939 }
940 INIT_HLIST_NODE(&new->de_node);
941 atomic_set(&new->de_ref, 1);
942 hlist_add_head_rcu(&new->de_node, &c->dc_deviceids[hash]);
943 spin_unlock(&c->dc_lock);
944 dprintk("%s [new]\n", __func__);
945 return new;
946}
947EXPORT_SYMBOL_GPL(pnfs_add_deviceid);
948
949void
950pnfs_put_deviceid_cache(struct nfs_client *clp)
951{
952 struct pnfs_deviceid_cache *local = clp->cl_devid_cache;
953
954 dprintk("--> %s cl_devid_cache %p\n", __func__, clp->cl_devid_cache);
955 if (atomic_dec_and_lock(&local->dc_ref, &clp->cl_lock)) {
956 int i;
957 /* Verify cache is empty */
958 for (i = 0; i < NFS4_DEVICE_ID_HASH_SIZE; i++)
959 BUG_ON(!hlist_empty(&local->dc_deviceids[i]));
960 clp->cl_devid_cache = NULL;
961 spin_unlock(&clp->cl_lock);
962 kfree(local);
963 }
964}
965EXPORT_SYMBOL_GPL(pnfs_put_deviceid_cache);
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
new file mode 100644
index 000000000000..e2612ea0cbed
--- /dev/null
+++ b/fs/nfs/pnfs.h
@@ -0,0 +1,235 @@
1/*
2 * pNFS client data structures.
3 *
4 * Copyright (c) 2002
5 * The Regents of the University of Michigan
6 * All Rights Reserved
7 *
8 * Dean Hildebrand <dhildebz@umich.edu>
9 *
10 * Permission is granted to use, copy, create derivative works, and
11 * redistribute this software and such derivative works for any purpose,
12 * so long as the name of the University of Michigan is not used in
13 * any advertising or publicity pertaining to the use or distribution
14 * of this software without specific, written prior authorization. If
15 * the above copyright notice or any other identification of the
16 * University of Michigan is included in any copy of any portion of
17 * this software, then the disclaimer below must also be included.
18 *
19 * This software is provided as is, without representation or warranty
20 * of any kind either express or implied, including without limitation
21 * the implied warranties of merchantability, fitness for a particular
22 * purpose, or noninfringement. The Regents of the University of
23 * Michigan shall not be liable for any damages, including special,
24 * indirect, incidental, or consequential damages, with respect to any
25 * claim arising out of or in connection with the use of the software,
26 * even if it has been or is hereafter advised of the possibility of
27 * such damages.
28 */
29
30#ifndef FS_NFS_PNFS_H
31#define FS_NFS_PNFS_H
32
33enum {
34 NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */
35 NFS_LSEG_ROC, /* roc bit received from server */
36};
37
38struct pnfs_layout_segment {
39 struct list_head pls_list;
40 struct pnfs_layout_range pls_range;
41 atomic_t pls_refcount;
42 unsigned long pls_flags;
43 struct pnfs_layout_hdr *pls_layout;
44};
45
46#ifdef CONFIG_NFS_V4_1
47
48#define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4"
49
50enum {
51 NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */
52 NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */
53 NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */
54 NFS_LAYOUT_ROC, /* some lseg had roc bit set */
55 NFS_LAYOUT_DESTROYED, /* no new use of layout allowed */
56};
57
58/* Per-layout driver specific registration structure */
59struct pnfs_layoutdriver_type {
60 struct list_head pnfs_tblid;
61 const u32 id;
62 const char *name;
63 struct module *owner;
64 int (*set_layoutdriver) (struct nfs_server *);
65 int (*clear_layoutdriver) (struct nfs_server *);
66 struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr);
67 void (*free_lseg) (struct pnfs_layout_segment *lseg);
68};
69
70struct pnfs_layout_hdr {
71 atomic_t plh_refcount;
72 struct list_head plh_layouts; /* other client layouts */
73 struct list_head plh_bulk_recall; /* clnt list of bulk recalls */
74 struct list_head plh_segs; /* layout segments list */
75 nfs4_stateid plh_stateid;
76 atomic_t plh_outstanding; /* number of RPCs out */
77 unsigned long plh_block_lgets; /* block LAYOUTGET if >0 */
78 u32 plh_barrier; /* ignore lower seqids */
79 unsigned long plh_flags;
80 struct inode *plh_inode;
81};
82
83struct pnfs_device {
84 struct nfs4_deviceid dev_id;
85 unsigned int layout_type;
86 unsigned int mincount;
87 struct page **pages;
88 void *area;
89 unsigned int pgbase;
90 unsigned int pglen;
91};
92
93/*
94 * Device ID RCU cache. A device ID is unique per client ID and layout type.
95 */
96#define NFS4_DEVICE_ID_HASH_BITS 5
97#define NFS4_DEVICE_ID_HASH_SIZE (1 << NFS4_DEVICE_ID_HASH_BITS)
98#define NFS4_DEVICE_ID_HASH_MASK (NFS4_DEVICE_ID_HASH_SIZE - 1)
99
100static inline u32
101nfs4_deviceid_hash(struct nfs4_deviceid *id)
102{
103 unsigned char *cptr = (unsigned char *)id->data;
104 unsigned int nbytes = NFS4_DEVICEID4_SIZE;
105 u32 x = 0;
106
107 while (nbytes--) {
108 x *= 37;
109 x += *cptr++;
110 }
111 return x & NFS4_DEVICE_ID_HASH_MASK;
112}
113
114struct pnfs_deviceid_node {
115 struct hlist_node de_node;
116 struct nfs4_deviceid de_id;
117 atomic_t de_ref;
118};
119
120struct pnfs_deviceid_cache {
121 spinlock_t dc_lock;
122 atomic_t dc_ref;
123 void (*dc_free_callback)(struct pnfs_deviceid_node *);
124 struct hlist_head dc_deviceids[NFS4_DEVICE_ID_HASH_SIZE];
125};
126
127extern int pnfs_alloc_init_deviceid_cache(struct nfs_client *,
128 void (*free_callback)(struct pnfs_deviceid_node *));
129extern void pnfs_put_deviceid_cache(struct nfs_client *);
130extern struct pnfs_deviceid_node *pnfs_find_get_deviceid(
131 struct pnfs_deviceid_cache *,
132 struct nfs4_deviceid *);
133extern struct pnfs_deviceid_node *pnfs_add_deviceid(
134 struct pnfs_deviceid_cache *,
135 struct pnfs_deviceid_node *);
136extern void pnfs_put_deviceid(struct pnfs_deviceid_cache *c,
137 struct pnfs_deviceid_node *devid);
138
139extern int pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *);
140extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
141
142/* nfs4proc.c */
143extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
144 struct pnfs_device *dev);
145extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp);
146
147/* pnfs.c */
148void get_layout_hdr(struct pnfs_layout_hdr *lo);
149struct pnfs_layout_segment *
150pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
151 enum pnfs_iomode access_type);
152void set_pnfs_layoutdriver(struct nfs_server *, u32 id);
153void unset_pnfs_layoutdriver(struct nfs_server *);
154int pnfs_layout_process(struct nfs4_layoutget *lgp);
155void pnfs_free_lseg_list(struct list_head *tmp_list);
156void pnfs_destroy_layout(struct nfs_inode *);
157void pnfs_destroy_all_layouts(struct nfs_client *);
158void put_layout_hdr(struct pnfs_layout_hdr *lo);
159void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo,
160 const nfs4_stateid *new,
161 bool update_barrier);
162int pnfs_choose_layoutget_stateid(nfs4_stateid *dst,
163 struct pnfs_layout_hdr *lo,
164 struct nfs4_state *open_state);
165int mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
166 struct list_head *tmp_list,
167 u32 iomode);
168bool pnfs_roc(struct inode *ino);
169void pnfs_roc_release(struct inode *ino);
170void pnfs_roc_set_barrier(struct inode *ino, u32 barrier);
171bool pnfs_roc_drain(struct inode *ino, u32 *barrier);
172
173
174static inline int lo_fail_bit(u32 iomode)
175{
176 return iomode == IOMODE_RW ?
177 NFS_LAYOUT_RW_FAILED : NFS_LAYOUT_RO_FAILED;
178}
179
180/* Return true if a layout driver is being used for this mountpoint */
181static inline int pnfs_enabled_sb(struct nfs_server *nfss)
182{
183 return nfss->pnfs_curr_ld != NULL;
184}
185
186#else /* CONFIG_NFS_V4_1 */
187
188static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
189{
190}
191
192static inline void pnfs_destroy_layout(struct nfs_inode *nfsi)
193{
194}
195
196static inline struct pnfs_layout_segment *
197pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
198 enum pnfs_iomode access_type)
199{
200 return NULL;
201}
202
203static inline bool
204pnfs_roc(struct inode *ino)
205{
206 return false;
207}
208
209static inline void
210pnfs_roc_release(struct inode *ino)
211{
212}
213
214static inline void
215pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
216{
217}
218
219static inline bool
220pnfs_roc_drain(struct inode *ino, u32 *barrier)
221{
222 return false;
223}
224
225static inline void set_pnfs_layoutdriver(struct nfs_server *s, u32 id)
226{
227}
228
229static inline void unset_pnfs_layoutdriver(struct nfs_server *s)
230{
231}
232
233#endif /* CONFIG_NFS_V4_1 */
234
235#endif /* FS_NFS_PNFS_H */
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 7be72d90d49d..77d5e21c4ad6 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -29,10 +29,8 @@
29 29
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/param.h> 31#include <linux/param.h>
32#include <linux/slab.h>
33#include <linux/time.h> 32#include <linux/time.h>
34#include <linux/mm.h> 33#include <linux/mm.h>
35#include <linux/utsname.h>
36#include <linux/errno.h> 34#include <linux/errno.h>
37#include <linux/string.h> 35#include <linux/string.h>
38#include <linux/in.h> 36#include <linux/in.h>
@@ -48,6 +46,39 @@
48#define NFSDBG_FACILITY NFSDBG_PROC 46#define NFSDBG_FACILITY NFSDBG_PROC
49 47
50/* 48/*
49 * wrapper to handle the -EKEYEXPIRED error message. This should generally
50 * only happen if using krb5 auth and a user's TGT expires. NFSv2 doesn't
51 * support the NFSERR_JUKEBOX error code, but we handle this situation in the
52 * same way that we handle that error with NFSv3.
53 */
54static int
55nfs_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
56{
57 int res;
58 do {
59 res = rpc_call_sync(clnt, msg, flags);
60 if (res != -EKEYEXPIRED)
61 break;
62 schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME);
63 res = -ERESTARTSYS;
64 } while (!fatal_signal_pending(current));
65 return res;
66}
67
68#define rpc_call_sync(clnt, msg, flags) nfs_rpc_wrapper(clnt, msg, flags)
69
70static int
71nfs_async_handle_expired_key(struct rpc_task *task)
72{
73 if (task->tk_status != -EKEYEXPIRED)
74 return 0;
75 task->tk_status = 0;
76 rpc_restart_call(task);
77 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
78 return 1;
79}
80
81/*
51 * Bare-bones access to getattr: this is for nfs_read_super. 82 * Bare-bones access to getattr: this is for nfs_read_super.
52 */ 83 */
53static int 84static int
@@ -193,35 +224,60 @@ static int nfs_proc_readlink(struct inode *inode, struct page *page,
193 return status; 224 return status;
194} 225}
195 226
227struct nfs_createdata {
228 struct nfs_createargs arg;
229 struct nfs_diropok res;
230 struct nfs_fh fhandle;
231 struct nfs_fattr fattr;
232};
233
234static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
235 struct dentry *dentry, struct iattr *sattr)
236{
237 struct nfs_createdata *data;
238
239 data = kmalloc(sizeof(*data), GFP_KERNEL);
240
241 if (data != NULL) {
242 data->arg.fh = NFS_FH(dir);
243 data->arg.name = dentry->d_name.name;
244 data->arg.len = dentry->d_name.len;
245 data->arg.sattr = sattr;
246 nfs_fattr_init(&data->fattr);
247 data->fhandle.size = 0;
248 data->res.fh = &data->fhandle;
249 data->res.fattr = &data->fattr;
250 }
251 return data;
252};
253
254static void nfs_free_createdata(const struct nfs_createdata *data)
255{
256 kfree(data);
257}
258
196static int 259static int
197nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 260nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
198 int flags, struct nameidata *nd) 261 int flags, struct nfs_open_context *ctx)
199{ 262{
200 struct nfs_fh fhandle; 263 struct nfs_createdata *data;
201 struct nfs_fattr fattr;
202 struct nfs_createargs arg = {
203 .fh = NFS_FH(dir),
204 .name = dentry->d_name.name,
205 .len = dentry->d_name.len,
206 .sattr = sattr
207 };
208 struct nfs_diropok res = {
209 .fh = &fhandle,
210 .fattr = &fattr
211 };
212 struct rpc_message msg = { 264 struct rpc_message msg = {
213 .rpc_proc = &nfs_procedures[NFSPROC_CREATE], 265 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
214 .rpc_argp = &arg,
215 .rpc_resp = &res,
216 }; 266 };
217 int status; 267 int status = -ENOMEM;
218 268
219 nfs_fattr_init(&fattr);
220 dprintk("NFS call create %s\n", dentry->d_name.name); 269 dprintk("NFS call create %s\n", dentry->d_name.name);
270 data = nfs_alloc_createdata(dir, dentry, sattr);
271 if (data == NULL)
272 goto out;
273 msg.rpc_argp = &data->arg;
274 msg.rpc_resp = &data->res;
221 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 275 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
222 nfs_mark_for_revalidate(dir); 276 nfs_mark_for_revalidate(dir);
223 if (status == 0) 277 if (status == 0)
224 status = nfs_instantiate(dentry, &fhandle, &fattr); 278 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
279 nfs_free_createdata(data);
280out:
225 dprintk("NFS reply create: %d\n", status); 281 dprintk("NFS reply create: %d\n", status);
226 return status; 282 return status;
227} 283}
@@ -233,24 +289,12 @@ static int
233nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 289nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
234 dev_t rdev) 290 dev_t rdev)
235{ 291{
236 struct nfs_fh fhandle; 292 struct nfs_createdata *data;
237 struct nfs_fattr fattr;
238 struct nfs_createargs arg = {
239 .fh = NFS_FH(dir),
240 .name = dentry->d_name.name,
241 .len = dentry->d_name.len,
242 .sattr = sattr
243 };
244 struct nfs_diropok res = {
245 .fh = &fhandle,
246 .fattr = &fattr
247 };
248 struct rpc_message msg = { 293 struct rpc_message msg = {
249 .rpc_proc = &nfs_procedures[NFSPROC_CREATE], 294 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
250 .rpc_argp = &arg,
251 .rpc_resp = &res,
252 }; 295 };
253 int status, mode; 296 umode_t mode;
297 int status = -ENOMEM;
254 298
255 dprintk("NFS call mknod %s\n", dentry->d_name.name); 299 dprintk("NFS call mknod %s\n", dentry->d_name.name);
256 300
@@ -263,17 +307,24 @@ nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
263 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */ 307 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
264 } 308 }
265 309
266 nfs_fattr_init(&fattr); 310 data = nfs_alloc_createdata(dir, dentry, sattr);
311 if (data == NULL)
312 goto out;
313 msg.rpc_argp = &data->arg;
314 msg.rpc_resp = &data->res;
315
267 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 316 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
268 nfs_mark_for_revalidate(dir); 317 nfs_mark_for_revalidate(dir);
269 318
270 if (status == -EINVAL && S_ISFIFO(mode)) { 319 if (status == -EINVAL && S_ISFIFO(mode)) {
271 sattr->ia_mode = mode; 320 sattr->ia_mode = mode;
272 nfs_fattr_init(&fattr); 321 nfs_fattr_init(data->res.fattr);
273 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 322 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
274 } 323 }
275 if (status == 0) 324 if (status == 0)
276 status = nfs_instantiate(dentry, &fhandle, &fattr); 325 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
326 nfs_free_createdata(data);
327out:
277 dprintk("NFS reply mknod: %d\n", status); 328 dprintk("NFS reply mknod: %d\n", status);
278 return status; 329 return status;
279} 330}
@@ -308,21 +359,38 @@ nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
308 359
309static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) 360static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
310{ 361{
362 if (nfs_async_handle_expired_key(task))
363 return 0;
311 nfs_mark_for_revalidate(dir); 364 nfs_mark_for_revalidate(dir);
312 return 1; 365 return 1;
313} 366}
314 367
368static void
369nfs_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
370{
371 msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
372}
373
374static int
375nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
376 struct inode *new_dir)
377{
378 if (nfs_async_handle_expired_key(task))
379 return 0;
380 nfs_mark_for_revalidate(old_dir);
381 nfs_mark_for_revalidate(new_dir);
382 return 1;
383}
384
315static int 385static int
316nfs_proc_rename(struct inode *old_dir, struct qstr *old_name, 386nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
317 struct inode *new_dir, struct qstr *new_name) 387 struct inode *new_dir, struct qstr *new_name)
318{ 388{
319 struct nfs_renameargs arg = { 389 struct nfs_renameargs arg = {
320 .fromfh = NFS_FH(old_dir), 390 .old_dir = NFS_FH(old_dir),
321 .fromname = old_name->name, 391 .old_name = old_name,
322 .fromlen = old_name->len, 392 .new_dir = NFS_FH(new_dir),
323 .tofh = NFS_FH(new_dir), 393 .new_name = new_name,
324 .toname = new_name->name,
325 .tolen = new_name->len
326 }; 394 };
327 struct rpc_message msg = { 395 struct rpc_message msg = {
328 .rpc_proc = &nfs_procedures[NFSPROC_RENAME], 396 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
@@ -365,8 +433,8 @@ static int
365nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, 433nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
366 unsigned int len, struct iattr *sattr) 434 unsigned int len, struct iattr *sattr)
367{ 435{
368 struct nfs_fh fhandle; 436 struct nfs_fh *fh;
369 struct nfs_fattr fattr; 437 struct nfs_fattr *fattr;
370 struct nfs_symlinkargs arg = { 438 struct nfs_symlinkargs arg = {
371 .fromfh = NFS_FH(dir), 439 .fromfh = NFS_FH(dir),
372 .fromname = dentry->d_name.name, 440 .fromname = dentry->d_name.name,
@@ -379,12 +447,18 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
379 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK], 447 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
380 .rpc_argp = &arg, 448 .rpc_argp = &arg,
381 }; 449 };
382 int status; 450 int status = -ENAMETOOLONG;
451
452 dprintk("NFS call symlink %s\n", dentry->d_name.name);
383 453
384 if (len > NFS2_MAXPATHLEN) 454 if (len > NFS2_MAXPATHLEN)
385 return -ENAMETOOLONG; 455 goto out;
386 456
387 dprintk("NFS call symlink %s\n", dentry->d_name.name); 457 fh = nfs_alloc_fhandle();
458 fattr = nfs_alloc_fattr();
459 status = -ENOMEM;
460 if (fh == NULL || fattr == NULL)
461 goto out_free;
388 462
389 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 463 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
390 nfs_mark_for_revalidate(dir); 464 nfs_mark_for_revalidate(dir);
@@ -394,12 +468,13 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
394 * filehandle size to zero indicates to nfs_instantiate that it 468 * filehandle size to zero indicates to nfs_instantiate that it
395 * should fill in the data with a LOOKUP call on the wire. 469 * should fill in the data with a LOOKUP call on the wire.
396 */ 470 */
397 if (status == 0) { 471 if (status == 0)
398 nfs_fattr_init(&fattr); 472 status = nfs_instantiate(dentry, fh, fattr);
399 fhandle.size = 0;
400 status = nfs_instantiate(dentry, &fhandle, &fattr);
401 }
402 473
474out_free:
475 nfs_free_fattr(fattr);
476 nfs_free_fhandle(fh);
477out:
403 dprintk("NFS reply symlink: %d\n", status); 478 dprintk("NFS reply symlink: %d\n", status);
404 return status; 479 return status;
405} 480}
@@ -407,31 +482,25 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
407static int 482static int
408nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) 483nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
409{ 484{
410 struct nfs_fh fhandle; 485 struct nfs_createdata *data;
411 struct nfs_fattr fattr;
412 struct nfs_createargs arg = {
413 .fh = NFS_FH(dir),
414 .name = dentry->d_name.name,
415 .len = dentry->d_name.len,
416 .sattr = sattr
417 };
418 struct nfs_diropok res = {
419 .fh = &fhandle,
420 .fattr = &fattr
421 };
422 struct rpc_message msg = { 486 struct rpc_message msg = {
423 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR], 487 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
424 .rpc_argp = &arg,
425 .rpc_resp = &res,
426 }; 488 };
427 int status; 489 int status = -ENOMEM;
428 490
429 dprintk("NFS call mkdir %s\n", dentry->d_name.name); 491 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
430 nfs_fattr_init(&fattr); 492 data = nfs_alloc_createdata(dir, dentry, sattr);
493 if (data == NULL)
494 goto out;
495 msg.rpc_argp = &data->arg;
496 msg.rpc_resp = &data->res;
497
431 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 498 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
432 nfs_mark_for_revalidate(dir); 499 nfs_mark_for_revalidate(dir);
433 if (status == 0) 500 if (status == 0)
434 status = nfs_instantiate(dentry, &fhandle, &fattr); 501 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
502 nfs_free_createdata(data);
503out:
435 dprintk("NFS reply mkdir: %d\n", status); 504 dprintk("NFS reply mkdir: %d\n", status);
436 return status; 505 return status;
437} 506}
@@ -466,14 +535,14 @@ nfs_proc_rmdir(struct inode *dir, struct qstr *name)
466 */ 535 */
467static int 536static int
468nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 537nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
469 u64 cookie, struct page *page, unsigned int count, int plus) 538 u64 cookie, struct page **pages, unsigned int count, int plus)
470{ 539{
471 struct inode *dir = dentry->d_inode; 540 struct inode *dir = dentry->d_inode;
472 struct nfs_readdirargs arg = { 541 struct nfs_readdirargs arg = {
473 .fh = NFS_FH(dir), 542 .fh = NFS_FH(dir),
474 .cookie = cookie, 543 .cookie = cookie,
475 .count = count, 544 .count = count,
476 .pages = &page, 545 .pages = pages,
477 }; 546 };
478 struct rpc_message msg = { 547 struct rpc_message msg = {
479 .rpc_proc = &nfs_procedures[NFSPROC_READDIR], 548 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
@@ -561,6 +630,9 @@ nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
561 630
562static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data) 631static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
563{ 632{
633 if (nfs_async_handle_expired_key(task))
634 return -EAGAIN;
635
564 nfs_invalidate_atime(data->inode); 636 nfs_invalidate_atime(data->inode);
565 if (task->tk_status >= 0) { 637 if (task->tk_status >= 0) {
566 nfs_refresh_inode(data->inode, data->res.fattr); 638 nfs_refresh_inode(data->inode, data->res.fattr);
@@ -580,6 +652,9 @@ static void nfs_proc_read_setup(struct nfs_read_data *data, struct rpc_message *
580 652
581static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data) 653static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
582{ 654{
655 if (nfs_async_handle_expired_key(task))
656 return -EAGAIN;
657
583 if (task->tk_status >= 0) 658 if (task->tk_status >= 0)
584 nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr); 659 nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
585 return 0; 660 return 0;
@@ -646,6 +721,8 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
646 .unlink_setup = nfs_proc_unlink_setup, 721 .unlink_setup = nfs_proc_unlink_setup,
647 .unlink_done = nfs_proc_unlink_done, 722 .unlink_done = nfs_proc_unlink_done,
648 .rename = nfs_proc_rename, 723 .rename = nfs_proc_rename,
724 .rename_setup = nfs_proc_rename_setup,
725 .rename_done = nfs_proc_rename_done,
649 .link = nfs_proc_link, 726 .link = nfs_proc_link,
650 .symlink = nfs_proc_symlink, 727 .symlink = nfs_proc_symlink,
651 .mkdir = nfs_proc_mkdir, 728 .mkdir = nfs_proc_mkdir,
@@ -655,7 +732,7 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
655 .statfs = nfs_proc_statfs, 732 .statfs = nfs_proc_statfs,
656 .fsinfo = nfs_proc_fsinfo, 733 .fsinfo = nfs_proc_fsinfo,
657 .pathconf = nfs_proc_pathconf, 734 .pathconf = nfs_proc_pathconf,
658 .decode_dirent = nfs_decode_dirent, 735 .decode_dirent = nfs2_decode_dirent,
659 .read_setup = nfs_proc_read_setup, 736 .read_setup = nfs_proc_read_setup,
660 .read_done = nfs_read_done, 737 .read_done = nfs_read_done,
661 .write_setup = nfs_proc_write_setup, 738 .write_setup = nfs_proc_write_setup,
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 96c4ebfa46f4..aedcaa7f291f 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -18,7 +18,6 @@
18#include <linux/sunrpc/clnt.h> 18#include <linux/sunrpc/clnt.h>
19#include <linux/nfs_fs.h> 19#include <linux/nfs_fs.h>
20#include <linux/nfs_page.h> 20#include <linux/nfs_page.h>
21#include <linux/smp_lock.h>
22 21
23#include <asm/system.h> 22#include <asm/system.h>
24 23
@@ -26,6 +25,7 @@
26#include "internal.h" 25#include "internal.h"
27#include "iostat.h" 26#include "iostat.h"
28#include "fscache.h" 27#include "fscache.h"
28#include "pnfs.h"
29 29
30#define NFSDBG_FACILITY NFSDBG_PAGECACHE 30#define NFSDBG_FACILITY NFSDBG_PAGECACHE
31 31
@@ -41,17 +41,16 @@ static mempool_t *nfs_rdata_mempool;
41 41
42struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount) 42struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
43{ 43{
44 struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, GFP_NOFS); 44 struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, GFP_KERNEL);
45 45
46 if (p) { 46 if (p) {
47 memset(p, 0, sizeof(*p)); 47 memset(p, 0, sizeof(*p));
48 INIT_LIST_HEAD(&p->pages); 48 INIT_LIST_HEAD(&p->pages);
49 p->npages = pagecount; 49 p->npages = pagecount;
50 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
51 if (pagecount <= ARRAY_SIZE(p->page_array)) 50 if (pagecount <= ARRAY_SIZE(p->page_array))
52 p->pagevec = p->page_array; 51 p->pagevec = p->page_array;
53 else { 52 else {
54 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS); 53 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
55 if (!p->pagevec) { 54 if (!p->pagevec) {
56 mempool_free(p, nfs_rdata_mempool); 55 mempool_free(p, nfs_rdata_mempool);
57 p = NULL; 56 p = NULL;
@@ -61,17 +60,15 @@ struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
61 return p; 60 return p;
62} 61}
63 62
64static void nfs_readdata_free(struct nfs_read_data *p) 63void nfs_readdata_free(struct nfs_read_data *p)
65{ 64{
66 if (p && (p->pagevec != &p->page_array[0])) 65 if (p && (p->pagevec != &p->page_array[0]))
67 kfree(p->pagevec); 66 kfree(p->pagevec);
68 mempool_free(p, nfs_rdata_mempool); 67 mempool_free(p, nfs_rdata_mempool);
69} 68}
70 69
71void nfs_readdata_release(void *data) 70static void nfs_readdata_release(struct nfs_read_data *rdata)
72{ 71{
73 struct nfs_read_data *rdata = data;
74
75 put_nfs_open_context(rdata->args.context); 72 put_nfs_open_context(rdata->args.context);
76 nfs_readdata_free(rdata); 73 nfs_readdata_free(rdata);
77} 74}
@@ -124,6 +121,7 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
124 len = nfs_page_length(page); 121 len = nfs_page_length(page);
125 if (len == 0) 122 if (len == 0)
126 return nfs_return_empty_page(page); 123 return nfs_return_empty_page(page);
124 pnfs_update_layout(inode, ctx, IOMODE_READ);
127 new = nfs_create_request(ctx, inode, page, 0, len); 125 new = nfs_create_request(ctx, inode, page, 0, len);
128 if (IS_ERR(new)) { 126 if (IS_ERR(new)) {
129 unlock_page(page); 127 unlock_page(page);
@@ -154,7 +152,6 @@ static void nfs_readpage_release(struct nfs_page *req)
154 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), 152 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
155 req->wb_bytes, 153 req->wb_bytes,
156 (long long)req_offset(req)); 154 (long long)req_offset(req));
157 nfs_clear_request(req);
158 nfs_release_request(req); 155 nfs_release_request(req);
159} 156}
160 157
@@ -193,6 +190,7 @@ static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
193 data->args.pages = data->pagevec; 190 data->args.pages = data->pagevec;
194 data->args.count = count; 191 data->args.count = count;
195 data->args.context = get_nfs_open_context(req->wb_context); 192 data->args.context = get_nfs_open_context(req->wb_context);
193 data->args.lock_context = req->wb_lock_context;
196 194
197 data->res.fattr = &data->fattr; 195 data->res.fattr = &data->fattr;
198 data->res.count = count; 196 data->res.count = count;
@@ -359,25 +357,19 @@ static void nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data
359 struct nfs_readres *resp = &data->res; 357 struct nfs_readres *resp = &data->res;
360 358
361 if (resp->eof || resp->count == argp->count) 359 if (resp->eof || resp->count == argp->count)
362 goto out; 360 return;
363 361
364 /* This is a short read! */ 362 /* This is a short read! */
365 nfs_inc_stats(data->inode, NFSIOS_SHORTREAD); 363 nfs_inc_stats(data->inode, NFSIOS_SHORTREAD);
366 /* Has the server at least made some progress? */ 364 /* Has the server at least made some progress? */
367 if (resp->count == 0) 365 if (resp->count == 0)
368 goto out; 366 return;
369 367
370 /* Yes, so retry the read at the end of the data */ 368 /* Yes, so retry the read at the end of the data */
371 argp->offset += resp->count; 369 argp->offset += resp->count;
372 argp->pgbase += resp->count; 370 argp->pgbase += resp->count;
373 argp->count -= resp->count; 371 argp->count -= resp->count;
374 nfs4_restart_rpc(task, NFS_SERVER(data->inode)->nfs_client); 372 nfs_restart_rpc(task, NFS_SERVER(data->inode)->nfs_client);
375 return;
376out:
377 nfs4_sequence_free_slot(NFS_SERVER(data->inode)->nfs_client,
378 &data->res.seq_res);
379 return;
380
381} 373}
382 374
383/* 375/*
@@ -419,7 +411,7 @@ void nfs_read_prepare(struct rpc_task *task, void *calldata)
419{ 411{
420 struct nfs_read_data *data = calldata; 412 struct nfs_read_data *data = calldata;
421 413
422 if (nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, 414 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
423 &data->args.seq_args, &data->res.seq_res, 415 &data->args.seq_args, &data->res.seq_res,
424 0, task)) 416 0, task))
425 return; 417 return;
@@ -633,6 +625,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
633 if (ret == 0) 625 if (ret == 0)
634 goto read_complete; /* all pages were read */ 626 goto read_complete; /* all pages were read */
635 627
628 pnfs_update_layout(inode, desc.ctx, IOMODE_READ);
636 if (rsize < PAGE_CACHE_SIZE) 629 if (rsize < PAGE_CACHE_SIZE)
637 nfs_pageio_init(&pgio, inode, nfs_pagein_multi, rsize, 0); 630 nfs_pageio_init(&pgio, inode, nfs_pagein_multi, rsize, 0);
638 else 631 else
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 0b4cbdc60abd..0f9ea73e7789 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -39,7 +39,6 @@
39#include <linux/nfs_mount.h> 39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h> 40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h> 41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h> 42#include <linux/seq_file.h>
44#include <linux/mount.h> 43#include <linux/mount.h>
45#include <linux/mnt_namespace.h> 44#include <linux/mnt_namespace.h>
@@ -48,6 +47,7 @@
48#include <linux/vfs.h> 47#include <linux/vfs.h>
49#include <linux/inet.h> 48#include <linux/inet.h>
50#include <linux/in6.h> 49#include <linux/in6.h>
50#include <linux/slab.h>
51#include <net/ipv6.h> 51#include <net/ipv6.h>
52#include <linux/netdevice.h> 52#include <linux/netdevice.h>
53#include <linux/nfs_xdr.h> 53#include <linux/nfs_xdr.h>
@@ -66,6 +66,12 @@
66 66
67#define NFSDBG_FACILITY NFSDBG_VFS 67#define NFSDBG_FACILITY NFSDBG_VFS
68 68
69#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
69enum { 75enum {
70 /* Mount options that take no arguments */ 76 /* Mount options that take no arguments */
71 Opt_soft, Opt_hard, 77 Opt_soft, Opt_hard,
@@ -73,7 +79,7 @@ enum {
73 Opt_cto, Opt_nocto, 79 Opt_cto, Opt_nocto,
74 Opt_ac, Opt_noac, 80 Opt_ac, Opt_noac,
75 Opt_lock, Opt_nolock, 81 Opt_lock, Opt_nolock,
76 Opt_v2, Opt_v3, 82 Opt_v2, Opt_v3, Opt_v4,
77 Opt_udp, Opt_tcp, Opt_rdma, 83 Opt_udp, Opt_tcp, Opt_rdma,
78 Opt_acl, Opt_noacl, 84 Opt_acl, Opt_noacl,
79 Opt_rdirplus, Opt_nordirplus, 85 Opt_rdirplus, Opt_nordirplus,
@@ -99,6 +105,7 @@ enum {
99 Opt_addr, Opt_mountaddr, Opt_clientaddr, 105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
100 Opt_lookupcache, 106 Opt_lookupcache,
101 Opt_fscache_uniq, 107 Opt_fscache_uniq,
108 Opt_local_lock,
102 109
103 /* Special mount options */ 110 /* Special mount options */
104 Opt_userspace, Opt_deprecated, Opt_sloppy, 111 Opt_userspace, Opt_deprecated, Opt_sloppy,
@@ -127,6 +134,7 @@ static const match_table_t nfs_mount_option_tokens = {
127 { Opt_nolock, "nolock" }, 134 { Opt_nolock, "nolock" },
128 { Opt_v2, "v2" }, 135 { Opt_v2, "v2" },
129 { Opt_v3, "v3" }, 136 { Opt_v3, "v3" },
137 { Opt_v4, "v4" },
130 { Opt_udp, "udp" }, 138 { Opt_udp, "udp" },
131 { Opt_tcp, "tcp" }, 139 { Opt_tcp, "tcp" },
132 { Opt_rdma, "rdma" }, 140 { Opt_rdma, "rdma" },
@@ -139,7 +147,6 @@ static const match_table_t nfs_mount_option_tokens = {
139 { Opt_resvport, "resvport" }, 147 { Opt_resvport, "resvport" },
140 { Opt_noresvport, "noresvport" }, 148 { Opt_noresvport, "noresvport" },
141 { Opt_fscache, "fsc" }, 149 { Opt_fscache, "fsc" },
142 { Opt_fscache_uniq, "fsc=%s" },
143 { Opt_nofscache, "nofsc" }, 150 { Opt_nofscache, "nofsc" },
144 151
145 { Opt_port, "port=%s" }, 152 { Opt_port, "port=%s" },
@@ -158,7 +165,7 @@ static const match_table_t nfs_mount_option_tokens = {
158 { Opt_mountvers, "mountvers=%s" }, 165 { Opt_mountvers, "mountvers=%s" },
159 { Opt_nfsvers, "nfsvers=%s" }, 166 { Opt_nfsvers, "nfsvers=%s" },
160 { Opt_nfsvers, "vers=%s" }, 167 { Opt_nfsvers, "vers=%s" },
161 { Opt_minorversion, "minorversion=%u" }, 168 { Opt_minorversion, "minorversion=%s" },
162 169
163 { Opt_sec, "sec=%s" }, 170 { Opt_sec, "sec=%s" },
164 { Opt_proto, "proto=%s" }, 171 { Opt_proto, "proto=%s" },
@@ -169,19 +176,23 @@ static const match_table_t nfs_mount_option_tokens = {
169 { Opt_mountaddr, "mountaddr=%s" }, 176 { Opt_mountaddr, "mountaddr=%s" },
170 177
171 { Opt_lookupcache, "lookupcache=%s" }, 178 { Opt_lookupcache, "lookupcache=%s" },
179 { Opt_fscache_uniq, "fsc=%s" },
180 { Opt_local_lock, "local_lock=%s" },
172 181
173 { Opt_err, NULL } 182 { Opt_err, NULL }
174}; 183};
175 184
176enum { 185enum {
177 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma, 186 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
178 187
179 Opt_xprt_err 188 Opt_xprt_err
180}; 189};
181 190
182static const match_table_t nfs_xprt_protocol_tokens = { 191static const match_table_t nfs_xprt_protocol_tokens = {
183 { Opt_xprt_udp, "udp" }, 192 { Opt_xprt_udp, "udp" },
193 { Opt_xprt_udp6, "udp6" },
184 { Opt_xprt_tcp, "tcp" }, 194 { Opt_xprt_tcp, "tcp" },
195 { Opt_xprt_tcp6, "tcp6" },
185 { Opt_xprt_rdma, "rdma" }, 196 { Opt_xprt_rdma, "rdma" },
186 197
187 { Opt_xprt_err, NULL } 198 { Opt_xprt_err, NULL }
@@ -232,14 +243,31 @@ static match_table_t nfs_lookupcache_tokens = {
232 { Opt_lookupcache_err, NULL } 243 { Opt_lookupcache_err, NULL }
233}; 244};
234 245
246enum {
247 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
248 Opt_local_lock_none,
249
250 Opt_local_lock_err
251};
252
253static match_table_t nfs_local_lock_tokens = {
254 { Opt_local_lock_all, "all" },
255 { Opt_local_lock_flock, "flock" },
256 { Opt_local_lock_posix, "posix" },
257 { Opt_local_lock_none, "none" },
258
259 { Opt_local_lock_err, NULL }
260};
261
235 262
236static void nfs_umount_begin(struct super_block *); 263static void nfs_umount_begin(struct super_block *);
237static int nfs_statfs(struct dentry *, struct kstatfs *); 264static int nfs_statfs(struct dentry *, struct kstatfs *);
238static int nfs_show_options(struct seq_file *, struct vfsmount *); 265static int nfs_show_options(struct seq_file *, struct vfsmount *);
239static int nfs_show_stats(struct seq_file *, struct vfsmount *); 266static int nfs_show_stats(struct seq_file *, struct vfsmount *);
240static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *); 267static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
241static int nfs_xdev_get_sb(struct file_system_type *fs_type, 268static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
242 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 269 int flags, const char *dev_name, void *raw_data);
270static void nfs_put_super(struct super_block *);
243static void nfs_kill_super(struct super_block *); 271static void nfs_kill_super(struct super_block *);
244static int nfs_remount(struct super_block *sb, int *flags, char *raw_data); 272static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
245 273
@@ -254,7 +282,7 @@ static struct file_system_type nfs_fs_type = {
254struct file_system_type nfs_xdev_fs_type = { 282struct file_system_type nfs_xdev_fs_type = {
255 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
256 .name = "nfs", 284 .name = "nfs",
257 .get_sb = nfs_xdev_get_sb, 285 .mount = nfs_xdev_mount,
258 .kill_sb = nfs_kill_super, 286 .kill_sb = nfs_kill_super,
259 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, 287 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
260}; 288};
@@ -263,8 +291,9 @@ static const struct super_operations nfs_sops = {
263 .alloc_inode = nfs_alloc_inode, 291 .alloc_inode = nfs_alloc_inode,
264 .destroy_inode = nfs_destroy_inode, 292 .destroy_inode = nfs_destroy_inode,
265 .write_inode = nfs_write_inode, 293 .write_inode = nfs_write_inode,
294 .put_super = nfs_put_super,
266 .statfs = nfs_statfs, 295 .statfs = nfs_statfs,
267 .clear_inode = nfs_clear_inode, 296 .evict_inode = nfs_evict_inode,
268 .umount_begin = nfs_umount_begin, 297 .umount_begin = nfs_umount_begin,
269 .show_options = nfs_show_options, 298 .show_options = nfs_show_options,
270 .show_stats = nfs_show_stats, 299 .show_stats = nfs_show_stats,
@@ -272,16 +301,20 @@ static const struct super_operations nfs_sops = {
272}; 301};
273 302
274#ifdef CONFIG_NFS_V4 303#ifdef CONFIG_NFS_V4
304static int nfs4_validate_text_mount_data(void *options,
305 struct nfs_parsed_mount_data *args, const char *dev_name);
306static int nfs4_try_mount(int flags, const char *dev_name,
307 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
275static int nfs4_get_sb(struct file_system_type *fs_type, 308static int nfs4_get_sb(struct file_system_type *fs_type,
276 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 309 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
277static int nfs4_remote_get_sb(struct file_system_type *fs_type, 310static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
278 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 311 int flags, const char *dev_name, void *raw_data);
279static int nfs4_xdev_get_sb(struct file_system_type *fs_type, 312static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
280 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 313 int flags, const char *dev_name, void *raw_data);
281static int nfs4_referral_get_sb(struct file_system_type *fs_type, 314static int nfs4_referral_get_sb(struct file_system_type *fs_type,
282 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 315 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
283static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type, 316static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
284 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 317 int flags, const char *dev_name, void *raw_data);
285static void nfs4_kill_super(struct super_block *sb); 318static void nfs4_kill_super(struct super_block *sb);
286 319
287static struct file_system_type nfs4_fs_type = { 320static struct file_system_type nfs4_fs_type = {
@@ -295,7 +328,7 @@ static struct file_system_type nfs4_fs_type = {
295static struct file_system_type nfs4_remote_fs_type = { 328static struct file_system_type nfs4_remote_fs_type = {
296 .owner = THIS_MODULE, 329 .owner = THIS_MODULE,
297 .name = "nfs4", 330 .name = "nfs4",
298 .get_sb = nfs4_remote_get_sb, 331 .mount = nfs4_remote_mount,
299 .kill_sb = nfs4_kill_super, 332 .kill_sb = nfs4_kill_super,
300 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, 333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
301}; 334};
@@ -303,7 +336,7 @@ static struct file_system_type nfs4_remote_fs_type = {
303struct file_system_type nfs4_xdev_fs_type = { 336struct file_system_type nfs4_xdev_fs_type = {
304 .owner = THIS_MODULE, 337 .owner = THIS_MODULE,
305 .name = "nfs4", 338 .name = "nfs4",
306 .get_sb = nfs4_xdev_get_sb, 339 .mount = nfs4_xdev_mount,
307 .kill_sb = nfs4_kill_super, 340 .kill_sb = nfs4_kill_super,
308 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, 341 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
309}; 342};
@@ -311,7 +344,7 @@ struct file_system_type nfs4_xdev_fs_type = {
311static struct file_system_type nfs4_remote_referral_fs_type = { 344static struct file_system_type nfs4_remote_referral_fs_type = {
312 .owner = THIS_MODULE, 345 .owner = THIS_MODULE,
313 .name = "nfs4", 346 .name = "nfs4",
314 .get_sb = nfs4_remote_referral_get_sb, 347 .mount = nfs4_remote_referral_mount,
315 .kill_sb = nfs4_kill_super, 348 .kill_sb = nfs4_kill_super,
316 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, 349 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
317}; 350};
@@ -328,8 +361,9 @@ static const struct super_operations nfs4_sops = {
328 .alloc_inode = nfs_alloc_inode, 361 .alloc_inode = nfs_alloc_inode,
329 .destroy_inode = nfs_destroy_inode, 362 .destroy_inode = nfs_destroy_inode,
330 .write_inode = nfs_write_inode, 363 .write_inode = nfs_write_inode,
364 .put_super = nfs_put_super,
331 .statfs = nfs_statfs, 365 .statfs = nfs_statfs,
332 .clear_inode = nfs4_clear_inode, 366 .evict_inode = nfs4_evict_inode,
333 .umount_begin = nfs_umount_begin, 367 .umount_begin = nfs_umount_begin,
334 .show_options = nfs_show_options, 368 .show_options = nfs_show_options,
335 .show_stats = nfs_show_stats, 369 .show_stats = nfs_show_stats,
@@ -412,15 +446,27 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
412 unsigned char blockbits; 446 unsigned char blockbits;
413 unsigned long blockres; 447 unsigned long blockres;
414 struct nfs_fh *fh = NFS_FH(dentry->d_inode); 448 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
415 struct nfs_fattr fattr; 449 struct nfs_fsstat res;
416 struct nfs_fsstat res = { 450 int error = -ENOMEM;
417 .fattr = &fattr, 451
418 }; 452 res.fattr = nfs_alloc_fattr();
419 int error; 453 if (res.fattr == NULL)
454 goto out_err;
420 455
421 error = server->nfs_client->rpc_ops->statfs(server, fh, &res); 456 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
457 if (unlikely(error == -ESTALE)) {
458 struct dentry *pd_dentry;
459
460 pd_dentry = dget_parent(dentry);
461 if (pd_dentry != NULL) {
462 nfs_zap_caches(pd_dentry->d_inode);
463 dput(pd_dentry);
464 }
465 }
466 nfs_free_fattr(res.fattr);
422 if (error < 0) 467 if (error < 0)
423 goto out_err; 468 goto out_err;
469
424 buf->f_type = NFS_SUPER_MAGIC; 470 buf->f_type = NFS_SUPER_MAGIC;
425 471
426 /* 472 /*
@@ -487,11 +533,53 @@ static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
487 return sec_flavours[i].str; 533 return sec_flavours[i].str;
488} 534}
489 535
536static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
537 int showdefaults)
538{
539 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
540
541 seq_printf(m, ",mountproto=");
542 switch (sap->sa_family) {
543 case AF_INET:
544 switch (nfss->mountd_protocol) {
545 case IPPROTO_UDP:
546 seq_printf(m, RPCBIND_NETID_UDP);
547 break;
548 case IPPROTO_TCP:
549 seq_printf(m, RPCBIND_NETID_TCP);
550 break;
551 default:
552 if (showdefaults)
553 seq_printf(m, "auto");
554 }
555 break;
556 case AF_INET6:
557 switch (nfss->mountd_protocol) {
558 case IPPROTO_UDP:
559 seq_printf(m, RPCBIND_NETID_UDP6);
560 break;
561 case IPPROTO_TCP:
562 seq_printf(m, RPCBIND_NETID_TCP6);
563 break;
564 default:
565 if (showdefaults)
566 seq_printf(m, "auto");
567 }
568 break;
569 default:
570 if (showdefaults)
571 seq_printf(m, "auto");
572 }
573}
574
490static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss, 575static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
491 int showdefaults) 576 int showdefaults)
492{ 577{
493 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address; 578 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
494 579
580 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
581 return;
582
495 switch (sap->sa_family) { 583 switch (sap->sa_family) {
496 case AF_INET: { 584 case AF_INET: {
497 struct sockaddr_in *sin = (struct sockaddr_in *)sap; 585 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
@@ -500,7 +588,7 @@ static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
500 } 588 }
501 case AF_INET6: { 589 case AF_INET6: {
502 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; 590 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
503 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr); 591 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
504 break; 592 break;
505 } 593 }
506 default: 594 default:
@@ -510,22 +598,30 @@ static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
510 598
511 if (nfss->mountd_version || showdefaults) 599 if (nfss->mountd_version || showdefaults)
512 seq_printf(m, ",mountvers=%u", nfss->mountd_version); 600 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
513 if (nfss->mountd_port || showdefaults) 601 if ((nfss->mountd_port &&
602 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
603 showdefaults)
514 seq_printf(m, ",mountport=%u", nfss->mountd_port); 604 seq_printf(m, ",mountport=%u", nfss->mountd_port);
515 605
516 switch (nfss->mountd_protocol) { 606 nfs_show_mountd_netid(m, nfss, showdefaults);
517 case IPPROTO_UDP:
518 seq_printf(m, ",mountproto=udp");
519 break;
520 case IPPROTO_TCP:
521 seq_printf(m, ",mountproto=tcp");
522 break;
523 default:
524 if (showdefaults)
525 seq_printf(m, ",mountproto=auto");
526 }
527} 607}
528 608
609#ifdef CONFIG_NFS_V4
610static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
611 int showdefaults)
612{
613 struct nfs_client *clp = nfss->nfs_client;
614
615 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
616 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
617}
618#else
619static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
620 int showdefaults)
621{
622}
623#endif
624
529/* 625/*
530 * Describe the mount options in force on this server representation 626 * Describe the mount options in force on this server representation
531 */ 627 */
@@ -551,6 +647,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
551 const struct proc_nfs_info *nfs_infop; 647 const struct proc_nfs_info *nfs_infop;
552 struct nfs_client *clp = nfss->nfs_client; 648 struct nfs_client *clp = nfss->nfs_client;
553 u32 version = clp->rpc_ops->version; 649 u32 version = clp->rpc_ops->version;
650 int local_flock, local_fcntl;
554 651
555 seq_printf(m, ",vers=%u", version); 652 seq_printf(m, ",vers=%u", version);
556 seq_printf(m, ",rsize=%u", nfss->rsize); 653 seq_printf(m, ",rsize=%u", nfss->rsize);
@@ -573,7 +670,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
573 seq_puts(m, nfs_infop->nostr); 670 seq_puts(m, nfs_infop->nostr);
574 } 671 }
575 seq_printf(m, ",proto=%s", 672 seq_printf(m, ",proto=%s",
576 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO)); 673 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
577 if (version == 4) { 674 if (version == 4) {
578 if (nfss->port != NFS_PORT) 675 if (nfss->port != NFS_PORT)
579 seq_printf(m, ",port=%u", nfss->port); 676 seq_printf(m, ",port=%u", nfss->port);
@@ -587,13 +684,30 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
587 684
588 if (version != 4) 685 if (version != 4)
589 nfs_show_mountd_options(m, nfss, showdefaults); 686 nfs_show_mountd_options(m, nfss, showdefaults);
687 else
688 nfs_show_nfsv4_options(m, nfss, showdefaults);
590 689
591#ifdef CONFIG_NFS_V4
592 if (clp->rpc_ops->version == 4)
593 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
594#endif
595 if (nfss->options & NFS_OPTION_FSCACHE) 690 if (nfss->options & NFS_OPTION_FSCACHE)
596 seq_printf(m, ",fsc"); 691 seq_printf(m, ",fsc");
692
693 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
694 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
695 seq_printf(m, ",lookupcache=none");
696 else
697 seq_printf(m, ",lookupcache=pos");
698 }
699
700 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
701 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
702
703 if (!local_flock && !local_fcntl)
704 seq_printf(m, ",local_lock=none");
705 else if (local_flock && local_fcntl)
706 seq_printf(m, ",local_lock=all");
707 else if (local_flock)
708 seq_printf(m, ",local_lock=flock");
709 else
710 seq_printf(m, ",local_lock=posix");
597} 711}
598 712
599/* 713/*
@@ -709,8 +823,6 @@ static void nfs_umount_begin(struct super_block *sb)
709 struct nfs_server *server; 823 struct nfs_server *server;
710 struct rpc_clnt *rpc; 824 struct rpc_clnt *rpc;
711 825
712 lock_kernel();
713
714 server = NFS_SB(sb); 826 server = NFS_SB(sb);
715 /* -EIO all pending I/O */ 827 /* -EIO all pending I/O */
716 rpc = server->client_acl; 828 rpc = server->client_acl;
@@ -719,8 +831,27 @@ static void nfs_umount_begin(struct super_block *sb)
719 rpc = server->client; 831 rpc = server->client;
720 if (!IS_ERR(rpc)) 832 if (!IS_ERR(rpc))
721 rpc_killall_tasks(rpc); 833 rpc_killall_tasks(rpc);
834}
835
836static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
837{
838 struct nfs_parsed_mount_data *data;
722 839
723 unlock_kernel(); 840 data = kzalloc(sizeof(*data), GFP_KERNEL);
841 if (data) {
842 data->acregmin = NFS_DEF_ACREGMIN;
843 data->acregmax = NFS_DEF_ACREGMAX;
844 data->acdirmin = NFS_DEF_ACDIRMIN;
845 data->acdirmax = NFS_DEF_ACDIRMAX;
846 data->mount_server.port = NFS_UNSPEC_PORT;
847 data->nfs_server.port = NFS_UNSPEC_PORT;
848 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
849 data->auth_flavors[0] = RPC_AUTH_UNIX;
850 data->auth_flavor_len = 1;
851 data->version = version;
852 data->minorversion = 0;
853 }
854 return data;
724} 855}
725 856
726/* 857/*
@@ -742,127 +873,21 @@ static int nfs_verify_server_address(struct sockaddr *addr)
742 } 873 }
743 } 874 }
744 875
876 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
745 return 0; 877 return 0;
746} 878}
747 879
748static void nfs_parse_ipv4_address(char *string, size_t str_len,
749 struct sockaddr *sap, size_t *addr_len)
750{
751 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
752 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
753
754 if (str_len <= INET_ADDRSTRLEN) {
755 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
756 (int)str_len, string);
757
758 sin->sin_family = AF_INET;
759 *addr_len = sizeof(*sin);
760 if (in4_pton(string, str_len, addr, '\0', NULL))
761 return;
762 }
763
764 sap->sa_family = AF_UNSPEC;
765 *addr_len = 0;
766}
767
768#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
769static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
770 const char *delim,
771 struct sockaddr_in6 *sin6)
772{
773 char *p;
774 size_t len;
775
776 if ((string + str_len) == delim)
777 return 1;
778
779 if (*delim != IPV6_SCOPE_DELIMITER)
780 return 0;
781
782 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
783 return 0;
784
785 len = (string + str_len) - delim - 1;
786 p = kstrndup(delim + 1, len, GFP_KERNEL);
787 if (p) {
788 unsigned long scope_id = 0;
789 struct net_device *dev;
790
791 dev = dev_get_by_name(&init_net, p);
792 if (dev != NULL) {
793 scope_id = dev->ifindex;
794 dev_put(dev);
795 } else {
796 if (strict_strtoul(p, 10, &scope_id) == 0) {
797 kfree(p);
798 return 0;
799 }
800 }
801
802 kfree(p);
803
804 sin6->sin6_scope_id = scope_id;
805 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
806 return 1;
807 }
808
809 return 0;
810}
811
812static void nfs_parse_ipv6_address(char *string, size_t str_len,
813 struct sockaddr *sap, size_t *addr_len)
814{
815 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
816 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
817 const char *delim;
818
819 if (str_len <= INET6_ADDRSTRLEN) {
820 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
821 (int)str_len, string);
822
823 sin6->sin6_family = AF_INET6;
824 *addr_len = sizeof(*sin6);
825 if (in6_pton(string, str_len, addr,
826 IPV6_SCOPE_DELIMITER, &delim) != 0) {
827 if (nfs_parse_ipv6_scope_id(string, str_len,
828 delim, sin6) != 0)
829 return;
830 }
831 }
832
833 sap->sa_family = AF_UNSPEC;
834 *addr_len = 0;
835}
836#else
837static void nfs_parse_ipv6_address(char *string, size_t str_len,
838 struct sockaddr *sap, size_t *addr_len)
839{
840 sap->sa_family = AF_UNSPEC;
841 *addr_len = 0;
842}
843#endif
844
845/* 880/*
846 * Construct a sockaddr based on the contents of a string that contains 881 * Select between a default port value and a user-specified port value.
847 * an IP address in presentation format. 882 * If a zero value is set, then autobind will be used.
848 *
849 * If there is a problem constructing the new sockaddr, set the address
850 * family to AF_UNSPEC.
851 */ 883 */
852void nfs_parse_ip_address(char *string, size_t str_len, 884static void nfs_set_port(struct sockaddr *sap, int *port,
853 struct sockaddr *sap, size_t *addr_len) 885 const unsigned short default_port)
854{ 886{
855 unsigned int i, colons; 887 if (*port == NFS_UNSPEC_PORT)
856 888 *port = default_port;
857 colons = 0;
858 for (i = 0; i < str_len; i++)
859 if (string[i] == ':')
860 colons++;
861 889
862 if (colons >= 2) 890 rpc_set_port(sap, *port);
863 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
864 else
865 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
866} 891}
867 892
868/* 893/*
@@ -904,8 +929,6 @@ static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
904 929
905/* 930/*
906 * Parse the value of the 'sec=' option. 931 * Parse the value of the 'sec=' option.
907 *
908 * The flavor_len setting is for v4 mounts.
909 */ 932 */
910static int nfs_parse_security_flavors(char *value, 933static int nfs_parse_security_flavors(char *value,
911 struct nfs_parsed_mount_data *mnt) 934 struct nfs_parsed_mount_data *mnt)
@@ -916,53 +939,43 @@ static int nfs_parse_security_flavors(char *value,
916 939
917 switch (match_token(value, nfs_secflavor_tokens, args)) { 940 switch (match_token(value, nfs_secflavor_tokens, args)) {
918 case Opt_sec_none: 941 case Opt_sec_none:
919 mnt->auth_flavor_len = 0;
920 mnt->auth_flavors[0] = RPC_AUTH_NULL; 942 mnt->auth_flavors[0] = RPC_AUTH_NULL;
921 break; 943 break;
922 case Opt_sec_sys: 944 case Opt_sec_sys:
923 mnt->auth_flavor_len = 0;
924 mnt->auth_flavors[0] = RPC_AUTH_UNIX; 945 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
925 break; 946 break;
926 case Opt_sec_krb5: 947 case Opt_sec_krb5:
927 mnt->auth_flavor_len = 1;
928 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; 948 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
929 break; 949 break;
930 case Opt_sec_krb5i: 950 case Opt_sec_krb5i:
931 mnt->auth_flavor_len = 1;
932 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; 951 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
933 break; 952 break;
934 case Opt_sec_krb5p: 953 case Opt_sec_krb5p:
935 mnt->auth_flavor_len = 1;
936 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; 954 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
937 break; 955 break;
938 case Opt_sec_lkey: 956 case Opt_sec_lkey:
939 mnt->auth_flavor_len = 1;
940 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; 957 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
941 break; 958 break;
942 case Opt_sec_lkeyi: 959 case Opt_sec_lkeyi:
943 mnt->auth_flavor_len = 1;
944 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; 960 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
945 break; 961 break;
946 case Opt_sec_lkeyp: 962 case Opt_sec_lkeyp:
947 mnt->auth_flavor_len = 1;
948 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; 963 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
949 break; 964 break;
950 case Opt_sec_spkm: 965 case Opt_sec_spkm:
951 mnt->auth_flavor_len = 1;
952 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; 966 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
953 break; 967 break;
954 case Opt_sec_spkmi: 968 case Opt_sec_spkmi:
955 mnt->auth_flavor_len = 1;
956 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; 969 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
957 break; 970 break;
958 case Opt_sec_spkmp: 971 case Opt_sec_spkmp:
959 mnt->auth_flavor_len = 1;
960 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; 972 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
961 break; 973 break;
962 default: 974 default:
963 return 0; 975 return 0;
964 } 976 }
965 977
978 mnt->auth_flavor_len = 1;
966 return 1; 979 return 1;
967} 980}
968 981
@@ -977,6 +990,8 @@ static int nfs_parse_mount_options(char *raw,
977{ 990{
978 char *p, *string, *secdata; 991 char *p, *string, *secdata;
979 int rc, sloppy = 0, invalid_option = 0; 992 int rc, sloppy = 0, invalid_option = 0;
993 unsigned short protofamily = AF_UNSPEC;
994 unsigned short mountfamily = AF_UNSPEC;
980 995
981 if (!raw) { 996 if (!raw) {
982 dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); 997 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
@@ -1001,7 +1016,6 @@ static int nfs_parse_mount_options(char *raw,
1001 while ((p = strsep(&raw, ",")) != NULL) { 1016 while ((p = strsep(&raw, ",")) != NULL) {
1002 substring_t args[MAX_OPT_ARGS]; 1017 substring_t args[MAX_OPT_ARGS];
1003 unsigned long option; 1018 unsigned long option;
1004 int int_option;
1005 int token; 1019 int token;
1006 1020
1007 if (!*p) 1021 if (!*p)
@@ -1041,15 +1055,25 @@ static int nfs_parse_mount_options(char *raw,
1041 break; 1055 break;
1042 case Opt_lock: 1056 case Opt_lock:
1043 mnt->flags &= ~NFS_MOUNT_NONLM; 1057 mnt->flags &= ~NFS_MOUNT_NONLM;
1058 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1059 NFS_MOUNT_LOCAL_FCNTL);
1044 break; 1060 break;
1045 case Opt_nolock: 1061 case Opt_nolock:
1046 mnt->flags |= NFS_MOUNT_NONLM; 1062 mnt->flags |= NFS_MOUNT_NONLM;
1063 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1064 NFS_MOUNT_LOCAL_FCNTL);
1047 break; 1065 break;
1048 case Opt_v2: 1066 case Opt_v2:
1049 mnt->flags &= ~NFS_MOUNT_VER3; 1067 mnt->flags &= ~NFS_MOUNT_VER3;
1068 mnt->version = 2;
1050 break; 1069 break;
1051 case Opt_v3: 1070 case Opt_v3:
1052 mnt->flags |= NFS_MOUNT_VER3; 1071 mnt->flags |= NFS_MOUNT_VER3;
1072 mnt->version = 3;
1073 break;
1074 case Opt_v4:
1075 mnt->flags &= ~NFS_MOUNT_VER3;
1076 mnt->version = 4;
1053 break; 1077 break;
1054 case Opt_udp: 1078 case Opt_udp:
1055 mnt->flags &= ~NFS_MOUNT_TCP; 1079 mnt->flags &= ~NFS_MOUNT_TCP;
@@ -1098,14 +1122,6 @@ static int nfs_parse_mount_options(char *raw,
1098 kfree(mnt->fscache_uniq); 1122 kfree(mnt->fscache_uniq);
1099 mnt->fscache_uniq = NULL; 1123 mnt->fscache_uniq = NULL;
1100 break; 1124 break;
1101 case Opt_fscache_uniq:
1102 string = match_strdup(args);
1103 if (!string)
1104 goto out_nomem;
1105 kfree(mnt->fscache_uniq);
1106 mnt->fscache_uniq = string;
1107 mnt->options |= NFS_OPTION_FSCACHE;
1108 break;
1109 1125
1110 /* 1126 /*
1111 * options that take numeric values 1127 * options that take numeric values
@@ -1116,7 +1132,7 @@ static int nfs_parse_mount_options(char *raw,
1116 goto out_nomem; 1132 goto out_nomem;
1117 rc = strict_strtoul(string, 10, &option); 1133 rc = strict_strtoul(string, 10, &option);
1118 kfree(string); 1134 kfree(string);
1119 if (rc != 0 || option > USHORT_MAX) 1135 if (rc != 0 || option > USHRT_MAX)
1120 goto out_invalid_value; 1136 goto out_invalid_value;
1121 mnt->nfs_server.port = option; 1137 mnt->nfs_server.port = option;
1122 break; 1138 break;
@@ -1237,7 +1253,7 @@ static int nfs_parse_mount_options(char *raw,
1237 goto out_nomem; 1253 goto out_nomem;
1238 rc = strict_strtoul(string, 10, &option); 1254 rc = strict_strtoul(string, 10, &option);
1239 kfree(string); 1255 kfree(string);
1240 if (rc != 0 || option > USHORT_MAX) 1256 if (rc != 0 || option > USHRT_MAX)
1241 goto out_invalid_value; 1257 goto out_invalid_value;
1242 mnt->mount_server.port = option; 1258 mnt->mount_server.port = option;
1243 break; 1259 break;
@@ -1264,20 +1280,31 @@ static int nfs_parse_mount_options(char *raw,
1264 switch (option) { 1280 switch (option) {
1265 case NFS2_VERSION: 1281 case NFS2_VERSION:
1266 mnt->flags &= ~NFS_MOUNT_VER3; 1282 mnt->flags &= ~NFS_MOUNT_VER3;
1283 mnt->version = 2;
1267 break; 1284 break;
1268 case NFS3_VERSION: 1285 case NFS3_VERSION:
1269 mnt->flags |= NFS_MOUNT_VER3; 1286 mnt->flags |= NFS_MOUNT_VER3;
1287 mnt->version = 3;
1288 break;
1289 case NFS4_VERSION:
1290 mnt->flags &= ~NFS_MOUNT_VER3;
1291 mnt->version = 4;
1270 break; 1292 break;
1271 default: 1293 default:
1272 goto out_invalid_value; 1294 goto out_invalid_value;
1273 } 1295 }
1274 break; 1296 break;
1275 case Opt_minorversion: 1297 case Opt_minorversion:
1276 if (match_int(args, &int_option)) 1298 string = match_strdup(args);
1277 return 0; 1299 if (string == NULL)
1278 if (int_option < 0 || int_option > NFS4_MAX_MINOR_VERSION) 1300 goto out_nomem;
1279 return 0; 1301 rc = strict_strtoul(string, 10, &option);
1280 mnt->minorversion = int_option; 1302 kfree(string);
1303 if (rc != 0)
1304 goto out_invalid_value;
1305 if (option > NFS4_MAX_MINOR_VERSION)
1306 goto out_invalid_value;
1307 mnt->minorversion = option;
1281 break; 1308 break;
1282 1309
1283 /* 1310 /*
@@ -1302,12 +1329,17 @@ static int nfs_parse_mount_options(char *raw,
1302 token = match_token(string, 1329 token = match_token(string,
1303 nfs_xprt_protocol_tokens, args); 1330 nfs_xprt_protocol_tokens, args);
1304 1331
1332 protofamily = AF_INET;
1305 switch (token) { 1333 switch (token) {
1334 case Opt_xprt_udp6:
1335 protofamily = AF_INET6;
1306 case Opt_xprt_udp: 1336 case Opt_xprt_udp:
1307 mnt->flags &= ~NFS_MOUNT_TCP; 1337 mnt->flags &= ~NFS_MOUNT_TCP;
1308 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; 1338 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1309 kfree(string); 1339 kfree(string);
1310 break; 1340 break;
1341 case Opt_xprt_tcp6:
1342 protofamily = AF_INET6;
1311 case Opt_xprt_tcp: 1343 case Opt_xprt_tcp:
1312 mnt->flags |= NFS_MOUNT_TCP; 1344 mnt->flags |= NFS_MOUNT_TCP;
1313 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; 1345 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
@@ -1323,6 +1355,7 @@ static int nfs_parse_mount_options(char *raw,
1323 default: 1355 default:
1324 dfprintk(MOUNT, "NFS: unrecognized " 1356 dfprintk(MOUNT, "NFS: unrecognized "
1325 "transport protocol\n"); 1357 "transport protocol\n");
1358 kfree(string);
1326 return 0; 1359 return 0;
1327 } 1360 }
1328 break; 1361 break;
@@ -1334,10 +1367,15 @@ static int nfs_parse_mount_options(char *raw,
1334 nfs_xprt_protocol_tokens, args); 1367 nfs_xprt_protocol_tokens, args);
1335 kfree(string); 1368 kfree(string);
1336 1369
1370 mountfamily = AF_INET;
1337 switch (token) { 1371 switch (token) {
1372 case Opt_xprt_udp6:
1373 mountfamily = AF_INET6;
1338 case Opt_xprt_udp: 1374 case Opt_xprt_udp:
1339 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; 1375 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1340 break; 1376 break;
1377 case Opt_xprt_tcp6:
1378 mountfamily = AF_INET6;
1341 case Opt_xprt_tcp: 1379 case Opt_xprt_tcp:
1342 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; 1380 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1343 break; 1381 break;
@@ -1352,11 +1390,14 @@ static int nfs_parse_mount_options(char *raw,
1352 string = match_strdup(args); 1390 string = match_strdup(args);
1353 if (string == NULL) 1391 if (string == NULL)
1354 goto out_nomem; 1392 goto out_nomem;
1355 nfs_parse_ip_address(string, strlen(string), 1393 mnt->nfs_server.addrlen =
1356 (struct sockaddr *) 1394 rpc_pton(string, strlen(string),
1357 &mnt->nfs_server.address, 1395 (struct sockaddr *)
1358 &mnt->nfs_server.addrlen); 1396 &mnt->nfs_server.address,
1397 sizeof(mnt->nfs_server.address));
1359 kfree(string); 1398 kfree(string);
1399 if (mnt->nfs_server.addrlen == 0)
1400 goto out_invalid_address;
1360 break; 1401 break;
1361 case Opt_clientaddr: 1402 case Opt_clientaddr:
1362 string = match_strdup(args); 1403 string = match_strdup(args);
@@ -1376,11 +1417,14 @@ static int nfs_parse_mount_options(char *raw,
1376 string = match_strdup(args); 1417 string = match_strdup(args);
1377 if (string == NULL) 1418 if (string == NULL)
1378 goto out_nomem; 1419 goto out_nomem;
1379 nfs_parse_ip_address(string, strlen(string), 1420 mnt->mount_server.addrlen =
1380 (struct sockaddr *) 1421 rpc_pton(string, strlen(string),
1381 &mnt->mount_server.address, 1422 (struct sockaddr *)
1382 &mnt->mount_server.addrlen); 1423 &mnt->mount_server.address,
1424 sizeof(mnt->mount_server.address));
1383 kfree(string); 1425 kfree(string);
1426 if (mnt->mount_server.addrlen == 0)
1427 goto out_invalid_address;
1384 break; 1428 break;
1385 case Opt_lookupcache: 1429 case Opt_lookupcache:
1386 string = match_strdup(args); 1430 string = match_strdup(args);
@@ -1406,6 +1450,42 @@ static int nfs_parse_mount_options(char *raw,
1406 return 0; 1450 return 0;
1407 }; 1451 };
1408 break; 1452 break;
1453 case Opt_fscache_uniq:
1454 string = match_strdup(args);
1455 if (string == NULL)
1456 goto out_nomem;
1457 kfree(mnt->fscache_uniq);
1458 mnt->fscache_uniq = string;
1459 mnt->options |= NFS_OPTION_FSCACHE;
1460 break;
1461 case Opt_local_lock:
1462 string = match_strdup(args);
1463 if (string == NULL)
1464 goto out_nomem;
1465 token = match_token(string, nfs_local_lock_tokens,
1466 args);
1467 kfree(string);
1468 switch (token) {
1469 case Opt_local_lock_all:
1470 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1471 NFS_MOUNT_LOCAL_FCNTL);
1472 break;
1473 case Opt_local_lock_flock:
1474 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1475 break;
1476 case Opt_local_lock_posix:
1477 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1478 break;
1479 case Opt_local_lock_none:
1480 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1481 NFS_MOUNT_LOCAL_FCNTL);
1482 break;
1483 default:
1484 dfprintk(MOUNT, "NFS: invalid "
1485 "local_lock argument\n");
1486 return 0;
1487 };
1488 break;
1409 1489
1410 /* 1490 /*
1411 * Special options 1491 * Special options
@@ -1430,10 +1510,38 @@ static int nfs_parse_mount_options(char *raw,
1430 if (!sloppy && invalid_option) 1510 if (!sloppy && invalid_option)
1431 return 0; 1511 return 0;
1432 1512
1513 /*
1514 * verify that any proto=/mountproto= options match the address
1515 * familiies in the addr=/mountaddr= options.
1516 */
1517 if (protofamily != AF_UNSPEC &&
1518 protofamily != mnt->nfs_server.address.ss_family)
1519 goto out_proto_mismatch;
1520
1521 if (mountfamily != AF_UNSPEC) {
1522 if (mnt->mount_server.addrlen) {
1523 if (mountfamily != mnt->mount_server.address.ss_family)
1524 goto out_mountproto_mismatch;
1525 } else {
1526 if (mountfamily != mnt->nfs_server.address.ss_family)
1527 goto out_mountproto_mismatch;
1528 }
1529 }
1530
1433 return 1; 1531 return 1;
1434 1532
1533out_mountproto_mismatch:
1534 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1535 "option\n");
1536 return 0;
1537out_proto_mismatch:
1538 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1539 return 0;
1540out_invalid_address:
1541 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1542 return 0;
1435out_invalid_value: 1543out_invalid_value:
1436 printk(KERN_INFO "NFS: bad mount option value specified: %s \n", p); 1544 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1437 return 0; 1545 return 0;
1438out_nomem: 1546out_nomem:
1439 printk(KERN_INFO "NFS: not enough memory to parse option\n"); 1547 printk(KERN_INFO "NFS: not enough memory to parse option\n");
@@ -1445,13 +1553,60 @@ out_security_failure:
1445} 1553}
1446 1554
1447/* 1555/*
1556 * Match the requested auth flavors with the list returned by
1557 * the server. Returns zero and sets the mount's authentication
1558 * flavor on success; returns -EACCES if server does not support
1559 * the requested flavor.
1560 */
1561static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1562 struct nfs_mount_request *request)
1563{
1564 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1565
1566 /*
1567 * Certain releases of Linux's mountd return an empty
1568 * flavor list. To prevent behavioral regression with
1569 * these servers (ie. rejecting mounts that used to
1570 * succeed), revert to pre-2.6.32 behavior (no checking)
1571 * if the returned flavor list is empty.
1572 */
1573 if (server_authlist_len == 0)
1574 return 0;
1575
1576 /*
1577 * We avoid sophisticated negotiating here, as there are
1578 * plenty of cases where we can get it wrong, providing
1579 * either too little or too much security.
1580 *
1581 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1582 * flavor listed first. However, some servers list
1583 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1584 * preferred default, in args->auth_flavors[0] if user
1585 * didn't specify sec= mount option.
1586 */
1587 for (i = 0; i < args->auth_flavor_len; i++)
1588 for (j = 0; j < server_authlist_len; j++)
1589 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1590 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1591 request->auth_flavs[j]);
1592 args->auth_flavors[0] = request->auth_flavs[j];
1593 return 0;
1594 }
1595
1596 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1597 nfs_umount(request);
1598 return -EACCES;
1599}
1600
1601/*
1448 * Use the remote server's MOUNT service to request the NFS file handle 1602 * Use the remote server's MOUNT service to request the NFS file handle
1449 * corresponding to the provided path. 1603 * corresponding to the provided path.
1450 */ 1604 */
1451static int nfs_try_mount(struct nfs_parsed_mount_data *args, 1605static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1452 struct nfs_fh *root_fh) 1606 struct nfs_fh *root_fh)
1453{ 1607{
1454 unsigned int auth_flavor_len = 0; 1608 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1609 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1455 struct nfs_mount_request request = { 1610 struct nfs_mount_request request = {
1456 .sap = (struct sockaddr *) 1611 .sap = (struct sockaddr *)
1457 &args->mount_server.address, 1612 &args->mount_server.address,
@@ -1459,15 +1614,19 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1459 .protocol = args->mount_server.protocol, 1614 .protocol = args->mount_server.protocol,
1460 .fh = root_fh, 1615 .fh = root_fh,
1461 .noresvport = args->flags & NFS_MOUNT_NORESVPORT, 1616 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1462 .auth_flav_len = &auth_flavor_len, 1617 .auth_flav_len = &server_authlist_len,
1618 .auth_flavs = server_authlist,
1463 }; 1619 };
1464 int status; 1620 int status;
1465 1621
1466 if (args->mount_server.version == 0) { 1622 if (args->mount_server.version == 0) {
1467 if (args->flags & NFS_MOUNT_VER3) 1623 switch (args->version) {
1468 args->mount_server.version = NFS_MNT3_VERSION; 1624 default:
1469 else 1625 args->mount_server.version = NFS_MNT3_VERSION;
1470 args->mount_server.version = NFS_MNT_VERSION; 1626 break;
1627 case 2:
1628 args->mount_server.version = NFS_MNT_VERSION;
1629 }
1471 } 1630 }
1472 request.version = args->mount_server.version; 1631 request.version = args->mount_server.version;
1473 1632
@@ -1485,23 +1644,25 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1485 args->mount_server.addrlen = args->nfs_server.addrlen; 1644 args->mount_server.addrlen = args->nfs_server.addrlen;
1486 } 1645 }
1487 request.salen = args->mount_server.addrlen; 1646 request.salen = args->mount_server.addrlen;
1488 1647 nfs_set_port(request.sap, &args->mount_server.port, 0);
1489 /*
1490 * autobind will be used if mount_server.port == 0
1491 */
1492 nfs_set_port(request.sap, args->mount_server.port);
1493 1648
1494 /* 1649 /*
1495 * Now ask the mount server to map our export path 1650 * Now ask the mount server to map our export path
1496 * to a file handle. 1651 * to a file handle.
1497 */ 1652 */
1498 status = nfs_mount(&request); 1653 status = nfs_mount(&request);
1499 if (status == 0) 1654 if (status != 0) {
1500 return 0; 1655 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1656 request.hostname, status);
1657 return status;
1658 }
1501 1659
1502 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n", 1660 /*
1503 request.hostname, status); 1661 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1504 return status; 1662 */
1663 if (args->mount_server.version != NFS_MNT3_VERSION)
1664 return 0;
1665 return nfs_walk_authlist(args, &request);
1505} 1666}
1506 1667
1507static int nfs_parse_simple_hostname(const char *dev_name, 1668static int nfs_parse_simple_hostname(const char *dev_name,
@@ -1661,22 +1822,11 @@ static int nfs_validate_mount_data(void *options,
1661 const char *dev_name) 1822 const char *dev_name)
1662{ 1823{
1663 struct nfs_mount_data *data = (struct nfs_mount_data *)options; 1824 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1825 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1664 1826
1665 if (data == NULL) 1827 if (data == NULL)
1666 goto out_no_data; 1828 goto out_no_data;
1667 1829
1668 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1669 args->rsize = NFS_MAX_FILE_IO_SIZE;
1670 args->wsize = NFS_MAX_FILE_IO_SIZE;
1671 args->acregmin = NFS_DEF_ACREGMIN;
1672 args->acregmax = NFS_DEF_ACREGMAX;
1673 args->acdirmin = NFS_DEF_ACDIRMIN;
1674 args->acdirmax = NFS_DEF_ACDIRMAX;
1675 args->mount_server.port = 0; /* autobind unless user sets port */
1676 args->nfs_server.port = 0; /* autobind unless user sets port */
1677 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1678 args->auth_flavors[0] = RPC_AUTH_UNIX;
1679
1680 switch (data->version) { 1830 switch (data->version) {
1681 case 1: 1831 case 1:
1682 data->namlen = 0; 1832 data->namlen = 0;
@@ -1697,8 +1847,11 @@ static int nfs_validate_mount_data(void *options,
1697 if (data->root.size > NFS3_FHSIZE || data->root.size == 0) 1847 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1698 goto out_invalid_fh; 1848 goto out_invalid_fh;
1699 mntfh->size = data->root.size; 1849 mntfh->size = data->root.size;
1700 } else 1850 args->version = 3;
1851 } else {
1701 mntfh->size = NFS2_FHSIZE; 1852 mntfh->size = NFS2_FHSIZE;
1853 args->version = 2;
1854 }
1702 1855
1703 1856
1704 memcpy(mntfh->data, data->root.data, mntfh->size); 1857 memcpy(mntfh->data, data->root.data, mntfh->size);
@@ -1711,6 +1864,7 @@ static int nfs_validate_mount_data(void *options,
1711 * can deal with. 1864 * can deal with.
1712 */ 1865 */
1713 args->flags = data->flags & NFS_MOUNT_FLAGMASK; 1866 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1867 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1714 args->rsize = data->rsize; 1868 args->rsize = data->rsize;
1715 args->wsize = data->wsize; 1869 args->wsize = data->wsize;
1716 args->timeo = data->timeo; 1870 args->timeo = data->timeo;
@@ -1720,11 +1874,9 @@ static int nfs_validate_mount_data(void *options,
1720 args->acdirmin = data->acdirmin; 1874 args->acdirmin = data->acdirmin;
1721 args->acdirmax = data->acdirmax; 1875 args->acdirmax = data->acdirmax;
1722 1876
1723 memcpy(&args->nfs_server.address, &data->addr, 1877 memcpy(sap, &data->addr, sizeof(data->addr));
1724 sizeof(data->addr));
1725 args->nfs_server.addrlen = sizeof(data->addr); 1878 args->nfs_server.addrlen = sizeof(data->addr);
1726 if (!nfs_verify_server_address((struct sockaddr *) 1879 if (!nfs_verify_server_address(sap))
1727 &args->nfs_server.address))
1728 goto out_no_address; 1880 goto out_no_address;
1729 1881
1730 if (!(data->flags & NFS_MOUNT_TCP)) 1882 if (!(data->flags & NFS_MOUNT_TCP))
@@ -1739,6 +1891,12 @@ static int nfs_validate_mount_data(void *options,
1739 if (!args->nfs_server.hostname) 1891 if (!args->nfs_server.hostname)
1740 goto out_nomem; 1892 goto out_nomem;
1741 1893
1894 if (!(data->flags & NFS_MOUNT_NONLM))
1895 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1896 NFS_MOUNT_LOCAL_FCNTL);
1897 else
1898 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1899 NFS_MOUNT_LOCAL_FCNTL);
1742 /* 1900 /*
1743 * The legacy version 6 binary mount data from userspace has a 1901 * The legacy version 6 binary mount data from userspace has a
1744 * field used only to transport selinux information into the 1902 * field used only to transport selinux information into the
@@ -1772,12 +1930,18 @@ static int nfs_validate_mount_data(void *options,
1772 if (nfs_parse_mount_options((char *)options, args) == 0) 1930 if (nfs_parse_mount_options((char *)options, args) == 0)
1773 return -EINVAL; 1931 return -EINVAL;
1774 1932
1775 if (!nfs_verify_server_address((struct sockaddr *) 1933 if (!nfs_verify_server_address(sap))
1776 &args->nfs_server.address))
1777 goto out_no_address; 1934 goto out_no_address;
1778 1935
1779 nfs_set_port((struct sockaddr *)&args->nfs_server.address, 1936 if (args->version == 4)
1780 args->nfs_server.port); 1937#ifdef CONFIG_NFS_V4
1938 return nfs4_validate_text_mount_data(options,
1939 args, dev_name);
1940#else
1941 goto out_v4_not_compiled;
1942#endif
1943
1944 nfs_set_port(sap, &args->nfs_server.port, 0);
1781 1945
1782 nfs_set_mount_transport_protocol(args); 1946 nfs_set_mount_transport_protocol(args);
1783 1947
@@ -1800,7 +1964,7 @@ static int nfs_validate_mount_data(void *options,
1800 } 1964 }
1801 1965
1802#ifndef CONFIG_NFS_V3 1966#ifndef CONFIG_NFS_V3
1803 if (args->flags & NFS_MOUNT_VER3) 1967 if (args->version == 3)
1804 goto out_v3_not_compiled; 1968 goto out_v3_not_compiled;
1805#endif /* !CONFIG_NFS_V3 */ 1969#endif /* !CONFIG_NFS_V3 */
1806 1970
@@ -1825,6 +1989,12 @@ out_v3_not_compiled:
1825 return -EPROTONOSUPPORT; 1989 return -EPROTONOSUPPORT;
1826#endif /* !CONFIG_NFS_V3 */ 1990#endif /* !CONFIG_NFS_V3 */
1827 1991
1992#ifndef CONFIG_NFS_V4
1993out_v4_not_compiled:
1994 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1995 return -EPROTONOSUPPORT;
1996#endif /* !CONFIG_NFS_V4 */
1997
1828out_nomem: 1998out_nomem:
1829 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n"); 1999 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1830 return -ENOMEM; 2000 return -ENOMEM;
@@ -1852,9 +2022,10 @@ nfs_compare_remount_data(struct nfs_server *nfss,
1852 data->acdirmin != nfss->acdirmin / HZ || 2022 data->acdirmin != nfss->acdirmin / HZ ||
1853 data->acdirmax != nfss->acdirmax / HZ || 2023 data->acdirmax != nfss->acdirmax / HZ ||
1854 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || 2024 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2025 data->nfs_server.port != nfss->port ||
1855 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || 2026 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1856 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr, 2027 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1857 data->nfs_server.addrlen) != 0) 2028 (struct sockaddr *)&nfss->nfs_client->cl_addr))
1858 return -EINVAL; 2029 return -EINVAL;
1859 2030
1860 return 0; 2031 return 0;
@@ -1885,7 +2056,6 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1885 if (data == NULL) 2056 if (data == NULL)
1886 return -ENOMEM; 2057 return -ENOMEM;
1887 2058
1888 lock_kernel();
1889 /* fill out struct with values from existing mount */ 2059 /* fill out struct with values from existing mount */
1890 data->flags = nfss->flags; 2060 data->flags = nfss->flags;
1891 data->rsize = nfss->rsize; 2061 data->rsize = nfss->rsize;
@@ -1897,6 +2067,7 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1897 data->acdirmin = nfss->acdirmin / HZ; 2067 data->acdirmin = nfss->acdirmin / HZ;
1898 data->acdirmax = nfss->acdirmax / HZ; 2068 data->acdirmax = nfss->acdirmax / HZ;
1899 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; 2069 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2070 data->nfs_server.port = nfss->port;
1900 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; 2071 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1901 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, 2072 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1902 data->nfs_server.addrlen); 2073 data->nfs_server.addrlen);
@@ -1910,7 +2081,6 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1910 error = nfs_compare_remount_data(nfss, data); 2081 error = nfs_compare_remount_data(nfss, data);
1911out: 2082out:
1912 kfree(data); 2083 kfree(data);
1913 unlock_kernel();
1914 return error; 2084 return error;
1915} 2085}
1916 2086
@@ -1934,6 +2104,8 @@ static inline void nfs_initialise_sb(struct super_block *sb)
1934 if (server->flags & NFS_MOUNT_NOAC) 2104 if (server->flags & NFS_MOUNT_NOAC)
1935 sb->s_flags |= MS_SYNCHRONOUS; 2105 sb->s_flags |= MS_SYNCHRONOUS;
1936 2106
2107 sb->s_bdi = &server->backing_dev_info;
2108
1937 nfs_super_set_maxbytes(sb, server->maxfilesize); 2109 nfs_super_set_maxbytes(sb, server->maxfilesize);
1938} 2110}
1939 2111
@@ -1950,7 +2122,7 @@ static void nfs_fill_super(struct super_block *sb,
1950 if (data->bsize) 2122 if (data->bsize)
1951 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); 2123 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1952 2124
1953 if (server->flags & NFS_MOUNT_VER3) { 2125 if (server->nfs_client->rpc_ops->version == 3) {
1954 /* The VFS shouldn't apply the umask to mode bits. We will do 2126 /* The VFS shouldn't apply the umask to mode bits. We will do
1955 * so ourselves when necessary. 2127 * so ourselves when necessary.
1956 */ 2128 */
@@ -1974,7 +2146,7 @@ static void nfs_clone_super(struct super_block *sb,
1974 sb->s_blocksize = old_sb->s_blocksize; 2146 sb->s_blocksize = old_sb->s_blocksize;
1975 sb->s_maxbytes = old_sb->s_maxbytes; 2147 sb->s_maxbytes = old_sb->s_maxbytes;
1976 2148
1977 if (server->flags & NFS_MOUNT_VER3) { 2149 if (server->nfs_client->rpc_ops->version == 3) {
1978 /* The VFS shouldn't apply the umask to mode bits. We will do 2150 /* The VFS shouldn't apply the umask to mode bits. We will do
1979 * so ourselves when necessary. 2151 * so ourselves when necessary.
1980 */ 2152 */
@@ -2108,8 +2280,8 @@ static int nfs_get_sb(struct file_system_type *fs_type,
2108 }; 2280 };
2109 int error = -ENOMEM; 2281 int error = -ENOMEM;
2110 2282
2111 data = kzalloc(sizeof(*data), GFP_KERNEL); 2283 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2112 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); 2284 mntfh = nfs_alloc_fhandle();
2113 if (data == NULL || mntfh == NULL) 2285 if (data == NULL || mntfh == NULL)
2114 goto out_free_fh; 2286 goto out_free_fh;
2115 2287
@@ -2120,6 +2292,15 @@ static int nfs_get_sb(struct file_system_type *fs_type,
2120 if (error < 0) 2292 if (error < 0)
2121 goto out; 2293 goto out;
2122 2294
2295#ifdef CONFIG_NFS_V4
2296 if (data->version == 4) {
2297 error = nfs4_try_mount(flags, dev_name, data, mnt);
2298 kfree(data->client_address);
2299 kfree(data->nfs_server.export_path);
2300 goto out;
2301 }
2302#endif /* CONFIG_NFS_V4 */
2303
2123 /* Get a volume representation */ 2304 /* Get a volume representation */
2124 server = nfs_create_server(data, mntfh); 2305 server = nfs_create_server(data, mntfh);
2125 if (IS_ERR(server)) { 2306 if (IS_ERR(server)) {
@@ -2144,13 +2325,14 @@ static int nfs_get_sb(struct file_system_type *fs_type,
2144 } else { 2325 } else {
2145 error = nfs_bdi_register(server); 2326 error = nfs_bdi_register(server);
2146 if (error) 2327 if (error)
2147 goto error_splat_super; 2328 goto error_splat_bdi;
2148 } 2329 }
2149 2330
2150 if (!s->s_root) { 2331 if (!s->s_root) {
2151 /* initial superblock/root creation */ 2332 /* initial superblock/root creation */
2152 nfs_fill_super(s, data); 2333 nfs_fill_super(s, data);
2153 nfs_fscache_get_super_cookie(s, data); 2334 nfs_fscache_get_super_cookie(
2335 s, data ? data->fscache_uniq : NULL, NULL);
2154 } 2336 }
2155 2337
2156 mntroot = nfs_get_root(s, mntfh); 2338 mntroot = nfs_get_root(s, mntfh);
@@ -2174,7 +2356,7 @@ out:
2174 kfree(data->fscache_uniq); 2356 kfree(data->fscache_uniq);
2175 security_free_mnt_opts(&data->lsm_opts); 2357 security_free_mnt_opts(&data->lsm_opts);
2176out_free_fh: 2358out_free_fh:
2177 kfree(mntfh); 2359 nfs_free_fhandle(mntfh);
2178 kfree(data); 2360 kfree(data);
2179 return error; 2361 return error;
2180 2362
@@ -2185,18 +2367,31 @@ out_err_nosb:
2185error_splat_root: 2367error_splat_root:
2186 dput(mntroot); 2368 dput(mntroot);
2187error_splat_super: 2369error_splat_super:
2370 if (server && !s->s_root)
2371 bdi_unregister(&server->backing_dev_info);
2372error_splat_bdi:
2188 deactivate_locked_super(s); 2373 deactivate_locked_super(s);
2189 goto out; 2374 goto out;
2190} 2375}
2191 2376
2192/* 2377/*
2378 * Ensure that we unregister the bdi before kill_anon_super
2379 * releases the device name
2380 */
2381static void nfs_put_super(struct super_block *s)
2382{
2383 struct nfs_server *server = NFS_SB(s);
2384
2385 bdi_unregister(&server->backing_dev_info);
2386}
2387
2388/*
2193 * Destroy an NFS2/3 superblock 2389 * Destroy an NFS2/3 superblock
2194 */ 2390 */
2195static void nfs_kill_super(struct super_block *s) 2391static void nfs_kill_super(struct super_block *s)
2196{ 2392{
2197 struct nfs_server *server = NFS_SB(s); 2393 struct nfs_server *server = NFS_SB(s);
2198 2394
2199 bdi_unregister(&server->backing_dev_info);
2200 kill_anon_super(s); 2395 kill_anon_super(s);
2201 nfs_fscache_release_super_cookie(s); 2396 nfs_fscache_release_super_cookie(s);
2202 nfs_free_server(server); 2397 nfs_free_server(server);
@@ -2205,9 +2400,9 @@ static void nfs_kill_super(struct super_block *s)
2205/* 2400/*
2206 * Clone an NFS2/3 server record on xdev traversal (FSID-change) 2401 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2207 */ 2402 */
2208static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, 2403static struct dentry *
2209 const char *dev_name, void *raw_data, 2404nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2210 struct vfsmount *mnt) 2405 const char *dev_name, void *raw_data)
2211{ 2406{
2212 struct nfs_clone_mount *data = raw_data; 2407 struct nfs_clone_mount *data = raw_data;
2213 struct super_block *s; 2408 struct super_block *s;
@@ -2219,7 +2414,7 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2219 }; 2414 };
2220 int error; 2415 int error;
2221 2416
2222 dprintk("--> nfs_xdev_get_sb()\n"); 2417 dprintk("--> nfs_xdev_mount()\n");
2223 2418
2224 /* create a new volume representation */ 2419 /* create a new volume representation */
2225 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); 2420 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
@@ -2245,12 +2440,13 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2245 } else { 2440 } else {
2246 error = nfs_bdi_register(server); 2441 error = nfs_bdi_register(server);
2247 if (error) 2442 if (error)
2248 goto error_splat_super; 2443 goto error_splat_bdi;
2249 } 2444 }
2250 2445
2251 if (!s->s_root) { 2446 if (!s->s_root) {
2252 /* initial superblock/root creation */ 2447 /* initial superblock/root creation */
2253 nfs_clone_super(s, data->sb); 2448 nfs_clone_super(s, data->sb);
2449 nfs_fscache_get_super_cookie(s, NULL, data);
2254 } 2450 }
2255 2451
2256 mntroot = nfs_get_root(s, data->fh); 2452 mntroot = nfs_get_root(s, data->fh);
@@ -2265,25 +2461,26 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2265 } 2461 }
2266 2462
2267 s->s_flags |= MS_ACTIVE; 2463 s->s_flags |= MS_ACTIVE;
2268 mnt->mnt_sb = s;
2269 mnt->mnt_root = mntroot;
2270 2464
2271 /* clone any lsm security options from the parent to the new sb */ 2465 /* clone any lsm security options from the parent to the new sb */
2272 security_sb_clone_mnt_opts(data->sb, s); 2466 security_sb_clone_mnt_opts(data->sb, s);
2273 2467
2274 dprintk("<-- nfs_xdev_get_sb() = 0\n"); 2468 dprintk("<-- nfs_xdev_mount() = 0\n");
2275 return 0; 2469 return mntroot;
2276 2470
2277out_err_nosb: 2471out_err_nosb:
2278 nfs_free_server(server); 2472 nfs_free_server(server);
2279out_err_noserver: 2473out_err_noserver:
2280 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); 2474 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2281 return error; 2475 return ERR_PTR(error);
2282 2476
2283error_splat_super: 2477error_splat_super:
2478 if (server && !s->s_root)
2479 bdi_unregister(&server->backing_dev_info);
2480error_splat_bdi:
2284 deactivate_locked_super(s); 2481 deactivate_locked_super(s);
2285 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); 2482 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2286 return error; 2483 return ERR_PTR(error);
2287} 2484}
2288 2485
2289#ifdef CONFIG_NFS_V4 2486#ifdef CONFIG_NFS_V4
@@ -2299,7 +2496,13 @@ static void nfs4_clone_super(struct super_block *sb,
2299 sb->s_maxbytes = old_sb->s_maxbytes; 2496 sb->s_maxbytes = old_sb->s_maxbytes;
2300 sb->s_time_gran = 1; 2497 sb->s_time_gran = 1;
2301 sb->s_op = old_sb->s_op; 2498 sb->s_op = old_sb->s_op;
2302 nfs_initialise_sb(sb); 2499 /*
2500 * The VFS shouldn't apply the umask to mode bits. We will do
2501 * so ourselves when necessary.
2502 */
2503 sb->s_flags |= MS_POSIXACL;
2504 sb->s_xattr = old_sb->s_xattr;
2505 nfs_initialise_sb(sb);
2303} 2506}
2304 2507
2305/* 2508/*
@@ -2309,12 +2512,56 @@ static void nfs4_fill_super(struct super_block *sb)
2309{ 2512{
2310 sb->s_time_gran = 1; 2513 sb->s_time_gran = 1;
2311 sb->s_op = &nfs4_sops; 2514 sb->s_op = &nfs4_sops;
2515 /*
2516 * The VFS shouldn't apply the umask to mode bits. We will do
2517 * so ourselves when necessary.
2518 */
2519 sb->s_flags |= MS_POSIXACL;
2520 sb->s_xattr = nfs4_xattr_handlers;
2312 nfs_initialise_sb(sb); 2521 nfs_initialise_sb(sb);
2313} 2522}
2314 2523
2315static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args) 2524static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2316{ 2525{
2317 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3); 2526 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2527 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2528}
2529
2530static int nfs4_validate_text_mount_data(void *options,
2531 struct nfs_parsed_mount_data *args,
2532 const char *dev_name)
2533{
2534 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2535
2536 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2537
2538 nfs_validate_transport_protocol(args);
2539
2540 nfs4_validate_mount_flags(args);
2541
2542 if (args->version != 4) {
2543 dfprintk(MOUNT,
2544 "NFS4: Illegal mount version\n");
2545 return -EINVAL;
2546 }
2547
2548 if (args->auth_flavor_len > 1) {
2549 dfprintk(MOUNT,
2550 "NFS4: Too many RPC auth flavours specified\n");
2551 return -EINVAL;
2552 }
2553
2554 if (args->client_address == NULL) {
2555 dfprintk(MOUNT,
2556 "NFS4: mount program didn't pass callback address\n");
2557 return -EINVAL;
2558 }
2559
2560 return nfs_parse_devname(dev_name,
2561 &args->nfs_server.hostname,
2562 NFS4_MAXNAMLEN,
2563 &args->nfs_server.export_path,
2564 NFS4_MAXPATHLEN);
2318} 2565}
2319 2566
2320/* 2567/*
@@ -2324,36 +2571,23 @@ static int nfs4_validate_mount_data(void *options,
2324 struct nfs_parsed_mount_data *args, 2571 struct nfs_parsed_mount_data *args,
2325 const char *dev_name) 2572 const char *dev_name)
2326{ 2573{
2327 struct sockaddr_in *ap; 2574 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2328 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; 2575 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2329 char *c; 2576 char *c;
2330 2577
2331 if (data == NULL) 2578 if (data == NULL)
2332 goto out_no_data; 2579 goto out_no_data;
2333 2580
2334 args->rsize = NFS_MAX_FILE_IO_SIZE;
2335 args->wsize = NFS_MAX_FILE_IO_SIZE;
2336 args->acregmin = NFS_DEF_ACREGMIN;
2337 args->acregmax = NFS_DEF_ACREGMAX;
2338 args->acdirmin = NFS_DEF_ACDIRMIN;
2339 args->acdirmax = NFS_DEF_ACDIRMAX;
2340 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
2341 args->auth_flavors[0] = RPC_AUTH_UNIX;
2342 args->auth_flavor_len = 0;
2343 args->minorversion = 0;
2344
2345 switch (data->version) { 2581 switch (data->version) {
2346 case 1: 2582 case 1:
2347 ap = (struct sockaddr_in *)&args->nfs_server.address;
2348 if (data->host_addrlen > sizeof(args->nfs_server.address)) 2583 if (data->host_addrlen > sizeof(args->nfs_server.address))
2349 goto out_no_address; 2584 goto out_no_address;
2350 if (data->host_addrlen == 0) 2585 if (data->host_addrlen == 0)
2351 goto out_no_address; 2586 goto out_no_address;
2352 args->nfs_server.addrlen = data->host_addrlen; 2587 args->nfs_server.addrlen = data->host_addrlen;
2353 if (copy_from_user(ap, data->host_addr, data->host_addrlen)) 2588 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2354 return -EFAULT; 2589 return -EFAULT;
2355 if (!nfs_verify_server_address((struct sockaddr *) 2590 if (!nfs_verify_server_address(sap))
2356 &args->nfs_server.address))
2357 goto out_no_address; 2591 goto out_no_address;
2358 2592
2359 if (data->auth_flavourlen) { 2593 if (data->auth_flavourlen) {
@@ -2399,39 +2633,14 @@ static int nfs4_validate_mount_data(void *options,
2399 nfs_validate_transport_protocol(args); 2633 nfs_validate_transport_protocol(args);
2400 2634
2401 break; 2635 break;
2402 default: { 2636 default:
2403 int status;
2404
2405 if (nfs_parse_mount_options((char *)options, args) == 0) 2637 if (nfs_parse_mount_options((char *)options, args) == 0)
2406 return -EINVAL; 2638 return -EINVAL;
2407 2639
2408 if (!nfs_verify_server_address((struct sockaddr *) 2640 if (!nfs_verify_server_address(sap))
2409 &args->nfs_server.address))
2410 return -EINVAL; 2641 return -EINVAL;
2411 2642
2412 nfs_set_port((struct sockaddr *)&args->nfs_server.address, 2643 return nfs4_validate_text_mount_data(options, args, dev_name);
2413 args->nfs_server.port);
2414
2415 nfs_validate_transport_protocol(args);
2416
2417 nfs4_validate_mount_flags(args);
2418
2419 if (args->auth_flavor_len > 1)
2420 goto out_inval_auth;
2421
2422 if (args->client_address == NULL)
2423 goto out_no_client_address;
2424
2425 status = nfs_parse_devname(dev_name,
2426 &args->nfs_server.hostname,
2427 NFS4_MAXNAMLEN,
2428 &args->nfs_server.export_path,
2429 NFS4_MAXPATHLEN);
2430 if (status < 0)
2431 return status;
2432
2433 break;
2434 }
2435 } 2644 }
2436 2645
2437 return 0; 2646 return 0;
@@ -2448,17 +2657,14 @@ out_inval_auth:
2448out_no_address: 2657out_no_address:
2449 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); 2658 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2450 return -EINVAL; 2659 return -EINVAL;
2451
2452out_no_client_address:
2453 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2454 return -EINVAL;
2455} 2660}
2456 2661
2457/* 2662/*
2458 * Get the superblock for the NFS4 root partition 2663 * Get the superblock for the NFS4 root partition
2459 */ 2664 */
2460static int nfs4_remote_get_sb(struct file_system_type *fs_type, 2665static struct dentry *
2461 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) 2666nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2667 const char *dev_name, void *raw_data)
2462{ 2668{
2463 struct nfs_parsed_mount_data *data = raw_data; 2669 struct nfs_parsed_mount_data *data = raw_data;
2464 struct super_block *s; 2670 struct super_block *s;
@@ -2471,7 +2677,7 @@ static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2471 }; 2677 };
2472 int error = -ENOMEM; 2678 int error = -ENOMEM;
2473 2679
2474 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); 2680 mntfh = nfs_alloc_fhandle();
2475 if (data == NULL || mntfh == NULL) 2681 if (data == NULL || mntfh == NULL)
2476 goto out_free_fh; 2682 goto out_free_fh;
2477 2683
@@ -2501,13 +2707,14 @@ static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2501 } else { 2707 } else {
2502 error = nfs_bdi_register(server); 2708 error = nfs_bdi_register(server);
2503 if (error) 2709 if (error)
2504 goto error_splat_super; 2710 goto error_splat_bdi;
2505 } 2711 }
2506 2712
2507 if (!s->s_root) { 2713 if (!s->s_root) {
2508 /* initial superblock/root creation */ 2714 /* initial superblock/root creation */
2509 nfs4_fill_super(s); 2715 nfs4_fill_super(s);
2510 nfs_fscache_get_super_cookie(s, data); 2716 nfs_fscache_get_super_cookie(
2717 s, data ? data->fscache_uniq : NULL, NULL);
2511 } 2718 }
2512 2719
2513 mntroot = nfs4_get_root(s, mntfh); 2720 mntroot = nfs4_get_root(s, mntfh);
@@ -2521,15 +2728,16 @@ static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2521 goto error_splat_root; 2728 goto error_splat_root;
2522 2729
2523 s->s_flags |= MS_ACTIVE; 2730 s->s_flags |= MS_ACTIVE;
2524 mnt->mnt_sb = s; 2731
2525 mnt->mnt_root = mntroot; 2732 security_free_mnt_opts(&data->lsm_opts);
2526 error = 0; 2733 nfs_free_fhandle(mntfh);
2734 return mntroot;
2527 2735
2528out: 2736out:
2529 security_free_mnt_opts(&data->lsm_opts); 2737 security_free_mnt_opts(&data->lsm_opts);
2530out_free_fh: 2738out_free_fh:
2531 kfree(mntfh); 2739 nfs_free_fhandle(mntfh);
2532 return error; 2740 return ERR_PTR(error);
2533 2741
2534out_free: 2742out_free:
2535 nfs_free_server(server); 2743 nfs_free_server(server);
@@ -2538,6 +2746,9 @@ out_free:
2538error_splat_root: 2746error_splat_root:
2539 dput(mntroot); 2747 dput(mntroot);
2540error_splat_super: 2748error_splat_super:
2749 if (server && !s->s_root)
2750 bdi_unregister(&server->backing_dev_info);
2751error_splat_bdi:
2541 deactivate_locked_super(s); 2752 deactivate_locked_super(s);
2542 goto out; 2753 goto out;
2543} 2754}
@@ -2569,7 +2780,7 @@ static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2569 devname = nfs_path(path->mnt->mnt_devname, 2780 devname = nfs_path(path->mnt->mnt_devname,
2570 path->mnt->mnt_root, path->dentry, 2781 path->mnt->mnt_root, path->dentry,
2571 page, PAGE_SIZE); 2782 page, PAGE_SIZE);
2572 if (devname == NULL) 2783 if (IS_ERR(devname))
2573 goto out_freepage; 2784 goto out_freepage;
2574 tmp = kstrdup(devname, GFP_KERNEL); 2785 tmp = kstrdup(devname, GFP_KERNEL);
2575 if (tmp == NULL) 2786 if (tmp == NULL)
@@ -2580,44 +2791,151 @@ out_freepage:
2580 free_page((unsigned long)page); 2791 free_page((unsigned long)page);
2581} 2792}
2582 2793
2794struct nfs_referral_count {
2795 struct list_head list;
2796 const struct task_struct *task;
2797 unsigned int referral_count;
2798};
2799
2800static LIST_HEAD(nfs_referral_count_list);
2801static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2802
2803static struct nfs_referral_count *nfs_find_referral_count(void)
2804{
2805 struct nfs_referral_count *p;
2806
2807 list_for_each_entry(p, &nfs_referral_count_list, list) {
2808 if (p->task == current)
2809 return p;
2810 }
2811 return NULL;
2812}
2813
2814#define NFS_MAX_NESTED_REFERRALS 2
2815
2816static int nfs_referral_loop_protect(void)
2817{
2818 struct nfs_referral_count *p, *new;
2819 int ret = -ENOMEM;
2820
2821 new = kmalloc(sizeof(*new), GFP_KERNEL);
2822 if (!new)
2823 goto out;
2824 new->task = current;
2825 new->referral_count = 1;
2826
2827 ret = 0;
2828 spin_lock(&nfs_referral_count_list_lock);
2829 p = nfs_find_referral_count();
2830 if (p != NULL) {
2831 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2832 ret = -ELOOP;
2833 else
2834 p->referral_count++;
2835 } else {
2836 list_add(&new->list, &nfs_referral_count_list);
2837 new = NULL;
2838 }
2839 spin_unlock(&nfs_referral_count_list_lock);
2840 kfree(new);
2841out:
2842 return ret;
2843}
2844
2845static void nfs_referral_loop_unprotect(void)
2846{
2847 struct nfs_referral_count *p;
2848
2849 spin_lock(&nfs_referral_count_list_lock);
2850 p = nfs_find_referral_count();
2851 p->referral_count--;
2852 if (p->referral_count == 0)
2853 list_del(&p->list);
2854 else
2855 p = NULL;
2856 spin_unlock(&nfs_referral_count_list_lock);
2857 kfree(p);
2858}
2859
2583static int nfs_follow_remote_path(struct vfsmount *root_mnt, 2860static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2584 const char *export_path, struct vfsmount *mnt_target) 2861 const char *export_path, struct vfsmount *mnt_target)
2585{ 2862{
2863 struct nameidata *nd = NULL;
2586 struct mnt_namespace *ns_private; 2864 struct mnt_namespace *ns_private;
2587 struct nameidata nd;
2588 struct super_block *s; 2865 struct super_block *s;
2589 int ret; 2866 int ret;
2590 2867
2868 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2869 if (nd == NULL)
2870 return -ENOMEM;
2871
2591 ns_private = create_mnt_ns(root_mnt); 2872 ns_private = create_mnt_ns(root_mnt);
2592 ret = PTR_ERR(ns_private); 2873 ret = PTR_ERR(ns_private);
2593 if (IS_ERR(ns_private)) 2874 if (IS_ERR(ns_private))
2594 goto out_mntput; 2875 goto out_mntput;
2595 2876
2877 ret = nfs_referral_loop_protect();
2878 if (ret != 0)
2879 goto out_put_mnt_ns;
2880
2596 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, 2881 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2597 export_path, LOOKUP_FOLLOW, &nd); 2882 export_path, LOOKUP_FOLLOW, nd);
2598 2883
2884 nfs_referral_loop_unprotect();
2599 put_mnt_ns(ns_private); 2885 put_mnt_ns(ns_private);
2600 2886
2601 if (ret != 0) 2887 if (ret != 0)
2602 goto out_err; 2888 goto out_err;
2603 2889
2604 s = nd.path.mnt->mnt_sb; 2890 s = nd->path.mnt->mnt_sb;
2605 atomic_inc(&s->s_active); 2891 atomic_inc(&s->s_active);
2606 mnt_target->mnt_sb = s; 2892 mnt_target->mnt_sb = s;
2607 mnt_target->mnt_root = dget(nd.path.dentry); 2893 mnt_target->mnt_root = dget(nd->path.dentry);
2608 2894
2609 /* Correct the device pathname */ 2895 /* Correct the device pathname */
2610 nfs_fix_devname(&nd.path, mnt_target); 2896 nfs_fix_devname(&nd->path, mnt_target);
2611 2897
2612 path_put(&nd.path); 2898 path_put(&nd->path);
2899 kfree(nd);
2613 down_write(&s->s_umount); 2900 down_write(&s->s_umount);
2614 return 0; 2901 return 0;
2902out_put_mnt_ns:
2903 put_mnt_ns(ns_private);
2615out_mntput: 2904out_mntput:
2616 mntput(root_mnt); 2905 mntput(root_mnt);
2617out_err: 2906out_err:
2907 kfree(nd);
2618 return ret; 2908 return ret;
2619} 2909}
2620 2910
2911static int nfs4_try_mount(int flags, const char *dev_name,
2912 struct nfs_parsed_mount_data *data,
2913 struct vfsmount *mnt)
2914{
2915 char *export_path;
2916 struct vfsmount *root_mnt;
2917 int error;
2918
2919 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2920
2921 export_path = data->nfs_server.export_path;
2922 data->nfs_server.export_path = "/";
2923 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2924 data->nfs_server.hostname);
2925 data->nfs_server.export_path = export_path;
2926
2927 error = PTR_ERR(root_mnt);
2928 if (IS_ERR(root_mnt))
2929 goto out;
2930
2931 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2932
2933out:
2934 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2935 error != 0 ? " [error]" : "");
2936 return error;
2937}
2938
2621/* 2939/*
2622 * Get the superblock for an NFS4 mountpoint 2940 * Get the superblock for an NFS4 mountpoint
2623 */ 2941 */
@@ -2625,11 +2943,9 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
2625 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) 2943 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2626{ 2944{
2627 struct nfs_parsed_mount_data *data; 2945 struct nfs_parsed_mount_data *data;
2628 char *export_path;
2629 struct vfsmount *root_mnt;
2630 int error = -ENOMEM; 2946 int error = -ENOMEM;
2631 2947
2632 data = kzalloc(sizeof(*data), GFP_KERNEL); 2948 data = nfs_alloc_parsed_mount_data(4);
2633 if (data == NULL) 2949 if (data == NULL)
2634 goto out_free_data; 2950 goto out_free_data;
2635 2951
@@ -2638,17 +2954,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
2638 if (error < 0) 2954 if (error < 0)
2639 goto out; 2955 goto out;
2640 2956
2641 export_path = data->nfs_server.export_path; 2957 error = nfs4_try_mount(flags, dev_name, data, mnt);
2642 data->nfs_server.export_path = "/";
2643 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2644 data->nfs_server.hostname);
2645 data->nfs_server.export_path = export_path;
2646
2647 error = PTR_ERR(root_mnt);
2648 if (IS_ERR(root_mnt))
2649 goto out;
2650
2651 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2652 2958
2653out: 2959out:
2654 kfree(data->client_address); 2960 kfree(data->client_address);
@@ -2669,7 +2975,6 @@ static void nfs4_kill_super(struct super_block *sb)
2669 dprintk("--> %s\n", __func__); 2975 dprintk("--> %s\n", __func__);
2670 nfs_super_return_all_delegations(sb); 2976 nfs_super_return_all_delegations(sb);
2671 kill_anon_super(sb); 2977 kill_anon_super(sb);
2672 nfs4_renewd_prepare_shutdown(server);
2673 nfs_fscache_release_super_cookie(sb); 2978 nfs_fscache_release_super_cookie(sb);
2674 nfs_free_server(server); 2979 nfs_free_server(server);
2675 dprintk("<-- %s\n", __func__); 2980 dprintk("<-- %s\n", __func__);
@@ -2678,9 +2983,9 @@ static void nfs4_kill_super(struct super_block *sb)
2678/* 2983/*
2679 * Clone an NFS4 server record on xdev traversal (FSID-change) 2984 * Clone an NFS4 server record on xdev traversal (FSID-change)
2680 */ 2985 */
2681static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, 2986static struct dentry *
2682 const char *dev_name, void *raw_data, 2987nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2683 struct vfsmount *mnt) 2988 const char *dev_name, void *raw_data)
2684{ 2989{
2685 struct nfs_clone_mount *data = raw_data; 2990 struct nfs_clone_mount *data = raw_data;
2686 struct super_block *s; 2991 struct super_block *s;
@@ -2692,7 +2997,7 @@ static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2692 }; 2997 };
2693 int error; 2998 int error;
2694 2999
2695 dprintk("--> nfs4_xdev_get_sb()\n"); 3000 dprintk("--> nfs4_xdev_mount()\n");
2696 3001
2697 /* create a new volume representation */ 3002 /* create a new volume representation */
2698 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); 3003 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
@@ -2718,12 +3023,13 @@ static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2718 } else { 3023 } else {
2719 error = nfs_bdi_register(server); 3024 error = nfs_bdi_register(server);
2720 if (error) 3025 if (error)
2721 goto error_splat_super; 3026 goto error_splat_bdi;
2722 } 3027 }
2723 3028
2724 if (!s->s_root) { 3029 if (!s->s_root) {
2725 /* initial superblock/root creation */ 3030 /* initial superblock/root creation */
2726 nfs4_clone_super(s, data->sb); 3031 nfs4_clone_super(s, data->sb);
3032 nfs_fscache_get_super_cookie(s, NULL, data);
2727 } 3033 }
2728 3034
2729 mntroot = nfs4_get_root(s, data->fh); 3035 mntroot = nfs4_get_root(s, data->fh);
@@ -2738,45 +3044,50 @@ static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2738 } 3044 }
2739 3045
2740 s->s_flags |= MS_ACTIVE; 3046 s->s_flags |= MS_ACTIVE;
2741 mnt->mnt_sb = s;
2742 mnt->mnt_root = mntroot;
2743 3047
2744 security_sb_clone_mnt_opts(data->sb, s); 3048 security_sb_clone_mnt_opts(data->sb, s);
2745 3049
2746 dprintk("<-- nfs4_xdev_get_sb() = 0\n"); 3050 dprintk("<-- nfs4_xdev_mount() = 0\n");
2747 return 0; 3051 return mntroot;
2748 3052
2749out_err_nosb: 3053out_err_nosb:
2750 nfs_free_server(server); 3054 nfs_free_server(server);
2751out_err_noserver: 3055out_err_noserver:
2752 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); 3056 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2753 return error; 3057 return ERR_PTR(error);
2754 3058
2755error_splat_super: 3059error_splat_super:
3060 if (server && !s->s_root)
3061 bdi_unregister(&server->backing_dev_info);
3062error_splat_bdi:
2756 deactivate_locked_super(s); 3063 deactivate_locked_super(s);
2757 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); 3064 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2758 return error; 3065 return ERR_PTR(error);
2759} 3066}
2760 3067
2761static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type, 3068static struct dentry *
2762 int flags, const char *dev_name, void *raw_data, 3069nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2763 struct vfsmount *mnt) 3070 const char *dev_name, void *raw_data)
2764{ 3071{
2765 struct nfs_clone_mount *data = raw_data; 3072 struct nfs_clone_mount *data = raw_data;
2766 struct super_block *s; 3073 struct super_block *s;
2767 struct nfs_server *server; 3074 struct nfs_server *server;
2768 struct dentry *mntroot; 3075 struct dentry *mntroot;
2769 struct nfs_fh mntfh; 3076 struct nfs_fh *mntfh;
2770 int (*compare_super)(struct super_block *, void *) = nfs_compare_super; 3077 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2771 struct nfs_sb_mountdata sb_mntdata = { 3078 struct nfs_sb_mountdata sb_mntdata = {
2772 .mntflags = flags, 3079 .mntflags = flags,
2773 }; 3080 };
2774 int error; 3081 int error = -ENOMEM;
2775 3082
2776 dprintk("--> nfs4_referral_get_sb()\n"); 3083 dprintk("--> nfs4_referral_get_sb()\n");
2777 3084
3085 mntfh = nfs_alloc_fhandle();
3086 if (mntfh == NULL)
3087 goto out_err_nofh;
3088
2778 /* create a new volume representation */ 3089 /* create a new volume representation */
2779 server = nfs4_create_referral_server(data, &mntfh); 3090 server = nfs4_create_referral_server(data, mntfh);
2780 if (IS_ERR(server)) { 3091 if (IS_ERR(server)) {
2781 error = PTR_ERR(server); 3092 error = PTR_ERR(server);
2782 goto out_err_noserver; 3093 goto out_err_noserver;
@@ -2799,15 +3110,16 @@ static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2799 } else { 3110 } else {
2800 error = nfs_bdi_register(server); 3111 error = nfs_bdi_register(server);
2801 if (error) 3112 if (error)
2802 goto error_splat_super; 3113 goto error_splat_bdi;
2803 } 3114 }
2804 3115
2805 if (!s->s_root) { 3116 if (!s->s_root) {
2806 /* initial superblock/root creation */ 3117 /* initial superblock/root creation */
2807 nfs4_fill_super(s); 3118 nfs4_fill_super(s);
3119 nfs_fscache_get_super_cookie(s, NULL, data);
2808 } 3120 }
2809 3121
2810 mntroot = nfs4_get_root(s, &mntfh); 3122 mntroot = nfs4_get_root(s, mntfh);
2811 if (IS_ERR(mntroot)) { 3123 if (IS_ERR(mntroot)) {
2812 error = PTR_ERR(mntroot); 3124 error = PTR_ERR(mntroot);
2813 goto error_splat_super; 3125 goto error_splat_super;
@@ -2819,24 +3131,29 @@ static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2819 } 3131 }
2820 3132
2821 s->s_flags |= MS_ACTIVE; 3133 s->s_flags |= MS_ACTIVE;
2822 mnt->mnt_sb = s;
2823 mnt->mnt_root = mntroot;
2824 3134
2825 security_sb_clone_mnt_opts(data->sb, s); 3135 security_sb_clone_mnt_opts(data->sb, s);
2826 3136
3137 nfs_free_fhandle(mntfh);
2827 dprintk("<-- nfs4_referral_get_sb() = 0\n"); 3138 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2828 return 0; 3139 return mntroot;
2829 3140
2830out_err_nosb: 3141out_err_nosb:
2831 nfs_free_server(server); 3142 nfs_free_server(server);
2832out_err_noserver: 3143out_err_noserver:
3144 nfs_free_fhandle(mntfh);
3145out_err_nofh:
2833 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); 3146 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2834 return error; 3147 return ERR_PTR(error);
2835 3148
2836error_splat_super: 3149error_splat_super:
3150 if (server && !s->s_root)
3151 bdi_unregister(&server->backing_dev_info);
3152error_splat_bdi:
2837 deactivate_locked_super(s); 3153 deactivate_locked_super(s);
3154 nfs_free_fhandle(mntfh);
2838 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); 3155 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2839 return error; 3156 return ERR_PTR(error);
2840} 3157}
2841 3158
2842/* 3159/*
diff --git a/fs/nfs/symlink.c b/fs/nfs/symlink.c
index 412738dbfbc7..05c9e02f4153 100644
--- a/fs/nfs/symlink.c
+++ b/fs/nfs/symlink.c
@@ -19,7 +19,6 @@
19#include <linux/pagemap.h> 19#include <linux/pagemap.h>
20#include <linux/stat.h> 20#include <linux/stat.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/slab.h>
23#include <linux/string.h> 22#include <linux/string.h>
24#include <linux/namei.h> 23#include <linux/namei.h>
25 24
@@ -50,7 +49,7 @@ static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50 struct page *page; 49 struct page *page;
51 void *err; 50 void *err;
52 51
53 err = ERR_PTR(nfs_revalidate_mapping_nolock(inode, inode->i_mapping)); 52 err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
54 if (err) 53 if (err)
55 goto read_failed; 54 goto read_failed;
56 page = read_cache_page(&inode->i_data, 0, 55 page = read_cache_page(&inode->i_data, 0,
diff --git a/fs/nfs/sysctl.c b/fs/nfs/sysctl.c
index b62481dabae9..978aaeb8a093 100644
--- a/fs/nfs/sysctl.c
+++ b/fs/nfs/sysctl.c
@@ -15,70 +15,66 @@
15 15
16#include "callback.h" 16#include "callback.h"
17 17
18#ifdef CONFIG_NFS_V4
18static const int nfs_set_port_min = 0; 19static const int nfs_set_port_min = 0;
19static const int nfs_set_port_max = 65535; 20static const int nfs_set_port_max = 65535;
21#endif
20static struct ctl_table_header *nfs_callback_sysctl_table; 22static struct ctl_table_header *nfs_callback_sysctl_table;
21 23
22static ctl_table nfs_cb_sysctls[] = { 24static ctl_table nfs_cb_sysctls[] = {
23#ifdef CONFIG_NFS_V4 25#ifdef CONFIG_NFS_V4
24 { 26 {
25 .ctl_name = CTL_UNNUMBERED,
26 .procname = "nfs_callback_tcpport", 27 .procname = "nfs_callback_tcpport",
27 .data = &nfs_callback_set_tcpport, 28 .data = &nfs_callback_set_tcpport,
28 .maxlen = sizeof(int), 29 .maxlen = sizeof(int),
29 .mode = 0644, 30 .mode = 0644,
30 .proc_handler = &proc_dointvec_minmax, 31 .proc_handler = proc_dointvec_minmax,
31 .extra1 = (int *)&nfs_set_port_min, 32 .extra1 = (int *)&nfs_set_port_min,
32 .extra2 = (int *)&nfs_set_port_max, 33 .extra2 = (int *)&nfs_set_port_max,
33 }, 34 },
35#ifndef CONFIG_NFS_USE_NEW_IDMAPPER
34 { 36 {
35 .ctl_name = CTL_UNNUMBERED,
36 .procname = "idmap_cache_timeout", 37 .procname = "idmap_cache_timeout",
37 .data = &nfs_idmap_cache_timeout, 38 .data = &nfs_idmap_cache_timeout,
38 .maxlen = sizeof(int), 39 .maxlen = sizeof(int),
39 .mode = 0644, 40 .mode = 0644,
40 .proc_handler = &proc_dointvec_jiffies, 41 .proc_handler = proc_dointvec_jiffies,
41 .strategy = &sysctl_jiffies,
42 }, 42 },
43#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
43#endif 44#endif
44 { 45 {
45 .ctl_name = CTL_UNNUMBERED,
46 .procname = "nfs_mountpoint_timeout", 46 .procname = "nfs_mountpoint_timeout",
47 .data = &nfs_mountpoint_expiry_timeout, 47 .data = &nfs_mountpoint_expiry_timeout,
48 .maxlen = sizeof(nfs_mountpoint_expiry_timeout), 48 .maxlen = sizeof(nfs_mountpoint_expiry_timeout),
49 .mode = 0644, 49 .mode = 0644,
50 .proc_handler = &proc_dointvec_jiffies, 50 .proc_handler = proc_dointvec_jiffies,
51 .strategy = &sysctl_jiffies,
52 }, 51 },
53 { 52 {
54 .ctl_name = CTL_UNNUMBERED,
55 .procname = "nfs_congestion_kb", 53 .procname = "nfs_congestion_kb",
56 .data = &nfs_congestion_kb, 54 .data = &nfs_congestion_kb,
57 .maxlen = sizeof(nfs_congestion_kb), 55 .maxlen = sizeof(nfs_congestion_kb),
58 .mode = 0644, 56 .mode = 0644,
59 .proc_handler = &proc_dointvec, 57 .proc_handler = proc_dointvec,
60 }, 58 },
61 { .ctl_name = 0 } 59 { }
62}; 60};
63 61
64static ctl_table nfs_cb_sysctl_dir[] = { 62static ctl_table nfs_cb_sysctl_dir[] = {
65 { 63 {
66 .ctl_name = CTL_UNNUMBERED,
67 .procname = "nfs", 64 .procname = "nfs",
68 .mode = 0555, 65 .mode = 0555,
69 .child = nfs_cb_sysctls, 66 .child = nfs_cb_sysctls,
70 }, 67 },
71 { .ctl_name = 0 } 68 { }
72}; 69};
73 70
74static ctl_table nfs_cb_sysctl_root[] = { 71static ctl_table nfs_cb_sysctl_root[] = {
75 { 72 {
76 .ctl_name = CTL_FS,
77 .procname = "fs", 73 .procname = "fs",
78 .mode = 0555, 74 .mode = 0555,
79 .child = nfs_cb_sysctl_dir, 75 .child = nfs_cb_sysctl_dir,
80 }, 76 },
81 { .ctl_name = 0 } 77 { }
82}; 78};
83 79
84int nfs_register_sysctl(void) 80int nfs_register_sysctl(void)
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index 1064c91ae810..e313a51acdd1 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -13,9 +13,12 @@
13#include <linux/nfs_fs.h> 13#include <linux/nfs_fs.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/wait.h> 15#include <linux/wait.h>
16#include <linux/namei.h>
16 17
17#include "internal.h" 18#include "internal.h"
18#include "nfs4_fs.h" 19#include "nfs4_fs.h"
20#include "iostat.h"
21#include "delegation.h"
19 22
20struct nfs_unlinkdata { 23struct nfs_unlinkdata {
21 struct hlist_node list; 24 struct hlist_node list;
@@ -23,6 +26,7 @@ struct nfs_unlinkdata {
23 struct nfs_removeres res; 26 struct nfs_removeres res;
24 struct inode *dir; 27 struct inode *dir;
25 struct rpc_cred *cred; 28 struct rpc_cred *cred;
29 struct nfs_fattr dir_attr;
26}; 30};
27 31
28/** 32/**
@@ -83,7 +87,7 @@ static void nfs_async_unlink_done(struct rpc_task *task, void *calldata)
83 struct inode *dir = data->dir; 87 struct inode *dir = data->dir;
84 88
85 if (!NFS_PROTO(dir)->unlink_done(task, dir)) 89 if (!NFS_PROTO(dir)->unlink_done(task, dir))
86 nfs4_restart_rpc(task, NFS_SERVER(dir)->nfs_client); 90 nfs_restart_rpc(task, NFS_SERVER(dir)->nfs_client);
87} 91}
88 92
89/** 93/**
@@ -109,7 +113,7 @@ void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
109 struct nfs_unlinkdata *data = calldata; 113 struct nfs_unlinkdata *data = calldata;
110 struct nfs_server *server = NFS_SERVER(data->dir); 114 struct nfs_server *server = NFS_SERVER(data->dir);
111 115
112 if (nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, 116 if (nfs4_setup_sequence(server, &data->args.seq_args,
113 &data->res.seq_res, 1, task)) 117 &data->res.seq_res, 1, task))
114 return; 118 return;
115 rpc_call_start(task); 119 rpc_call_start(task);
@@ -169,7 +173,7 @@ static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct n
169 } 173 }
170 nfs_sb_active(dir->i_sb); 174 nfs_sb_active(dir->i_sb);
171 data->args.fh = NFS_FH(dir); 175 data->args.fh = NFS_FH(dir);
172 nfs_fattr_init(&data->res.dir_attr); 176 nfs_fattr_init(data->res.dir_attr);
173 177
174 NFS_PROTO(dir)->unlink_setup(&msg, dir); 178 NFS_PROTO(dir)->unlink_setup(&msg, dir);
175 179
@@ -243,7 +247,7 @@ void nfs_unblock_sillyrename(struct dentry *dentry)
243 * @dir: parent directory of dentry 247 * @dir: parent directory of dentry
244 * @dentry: dentry to unlink 248 * @dentry: dentry to unlink
245 */ 249 */
246int 250static int
247nfs_async_unlink(struct inode *dir, struct dentry *dentry) 251nfs_async_unlink(struct inode *dir, struct dentry *dentry)
248{ 252{
249 struct nfs_unlinkdata *data; 253 struct nfs_unlinkdata *data;
@@ -258,7 +262,7 @@ nfs_async_unlink(struct inode *dir, struct dentry *dentry)
258 status = PTR_ERR(data->cred); 262 status = PTR_ERR(data->cred);
259 goto out_free; 263 goto out_free;
260 } 264 }
261 data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; 265 data->res.dir_attr = &data->dir_attr;
262 266
263 status = -EBUSY; 267 status = -EBUSY;
264 spin_lock(&dentry->d_lock); 268 spin_lock(&dentry->d_lock);
@@ -301,3 +305,256 @@ nfs_complete_unlink(struct dentry *dentry, struct inode *inode)
301 if (data != NULL && (NFS_STALE(inode) || !nfs_call_unlink(dentry, data))) 305 if (data != NULL && (NFS_STALE(inode) || !nfs_call_unlink(dentry, data)))
302 nfs_free_unlinkdata(data); 306 nfs_free_unlinkdata(data);
303} 307}
308
309/* Cancel a queued async unlink. Called when a sillyrename run fails. */
310static void
311nfs_cancel_async_unlink(struct dentry *dentry)
312{
313 spin_lock(&dentry->d_lock);
314 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
315 struct nfs_unlinkdata *data = dentry->d_fsdata;
316
317 dentry->d_flags &= ~DCACHE_NFSFS_RENAMED;
318 spin_unlock(&dentry->d_lock);
319 nfs_free_unlinkdata(data);
320 return;
321 }
322 spin_unlock(&dentry->d_lock);
323}
324
325struct nfs_renamedata {
326 struct nfs_renameargs args;
327 struct nfs_renameres res;
328 struct rpc_cred *cred;
329 struct inode *old_dir;
330 struct dentry *old_dentry;
331 struct nfs_fattr old_fattr;
332 struct inode *new_dir;
333 struct dentry *new_dentry;
334 struct nfs_fattr new_fattr;
335};
336
337/**
338 * nfs_async_rename_done - Sillyrename post-processing
339 * @task: rpc_task of the sillyrename
340 * @calldata: nfs_renamedata for the sillyrename
341 *
342 * Do the directory attribute updates and the d_move
343 */
344static void nfs_async_rename_done(struct rpc_task *task, void *calldata)
345{
346 struct nfs_renamedata *data = calldata;
347 struct inode *old_dir = data->old_dir;
348 struct inode *new_dir = data->new_dir;
349
350 if (!NFS_PROTO(old_dir)->rename_done(task, old_dir, new_dir)) {
351 nfs_restart_rpc(task, NFS_SERVER(old_dir)->nfs_client);
352 return;
353 }
354
355 if (task->tk_status != 0) {
356 nfs_cancel_async_unlink(data->old_dentry);
357 return;
358 }
359
360 nfs_set_verifier(data->old_dentry, nfs_save_change_attribute(old_dir));
361 d_move(data->old_dentry, data->new_dentry);
362}
363
364/**
365 * nfs_async_rename_release - Release the sillyrename data.
366 * @calldata: the struct nfs_renamedata to be released
367 */
368static void nfs_async_rename_release(void *calldata)
369{
370 struct nfs_renamedata *data = calldata;
371 struct super_block *sb = data->old_dir->i_sb;
372
373 if (data->old_dentry->d_inode)
374 nfs_mark_for_revalidate(data->old_dentry->d_inode);
375
376 dput(data->old_dentry);
377 dput(data->new_dentry);
378 iput(data->old_dir);
379 iput(data->new_dir);
380 nfs_sb_deactive(sb);
381 put_rpccred(data->cred);
382 kfree(data);
383}
384
385#if defined(CONFIG_NFS_V4_1)
386static void nfs_rename_prepare(struct rpc_task *task, void *calldata)
387{
388 struct nfs_renamedata *data = calldata;
389 struct nfs_server *server = NFS_SERVER(data->old_dir);
390
391 if (nfs4_setup_sequence(server, &data->args.seq_args,
392 &data->res.seq_res, 1, task))
393 return;
394 rpc_call_start(task);
395}
396#endif /* CONFIG_NFS_V4_1 */
397
398static const struct rpc_call_ops nfs_rename_ops = {
399 .rpc_call_done = nfs_async_rename_done,
400 .rpc_release = nfs_async_rename_release,
401#if defined(CONFIG_NFS_V4_1)
402 .rpc_call_prepare = nfs_rename_prepare,
403#endif /* CONFIG_NFS_V4_1 */
404};
405
406/**
407 * nfs_async_rename - perform an asynchronous rename operation
408 * @old_dir: directory that currently holds the dentry to be renamed
409 * @new_dir: target directory for the rename
410 * @old_dentry: original dentry to be renamed
411 * @new_dentry: dentry to which the old_dentry should be renamed
412 *
413 * It's expected that valid references to the dentries and inodes are held
414 */
415static struct rpc_task *
416nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
417 struct dentry *old_dentry, struct dentry *new_dentry)
418{
419 struct nfs_renamedata *data;
420 struct rpc_message msg = { };
421 struct rpc_task_setup task_setup_data = {
422 .rpc_message = &msg,
423 .callback_ops = &nfs_rename_ops,
424 .workqueue = nfsiod_workqueue,
425 .rpc_client = NFS_CLIENT(old_dir),
426 .flags = RPC_TASK_ASYNC,
427 };
428
429 data = kzalloc(sizeof(*data), GFP_KERNEL);
430 if (data == NULL)
431 return ERR_PTR(-ENOMEM);
432 task_setup_data.callback_data = data;
433
434 data->cred = rpc_lookup_cred();
435 if (IS_ERR(data->cred)) {
436 struct rpc_task *task = ERR_CAST(data->cred);
437 kfree(data);
438 return task;
439 }
440
441 msg.rpc_argp = &data->args;
442 msg.rpc_resp = &data->res;
443 msg.rpc_cred = data->cred;
444
445 /* set up nfs_renamedata */
446 data->old_dir = old_dir;
447 ihold(old_dir);
448 data->new_dir = new_dir;
449 ihold(new_dir);
450 data->old_dentry = dget(old_dentry);
451 data->new_dentry = dget(new_dentry);
452 nfs_fattr_init(&data->old_fattr);
453 nfs_fattr_init(&data->new_fattr);
454
455 /* set up nfs_renameargs */
456 data->args.old_dir = NFS_FH(old_dir);
457 data->args.old_name = &old_dentry->d_name;
458 data->args.new_dir = NFS_FH(new_dir);
459 data->args.new_name = &new_dentry->d_name;
460
461 /* set up nfs_renameres */
462 data->res.old_fattr = &data->old_fattr;
463 data->res.new_fattr = &data->new_fattr;
464
465 nfs_sb_active(old_dir->i_sb);
466
467 NFS_PROTO(data->old_dir)->rename_setup(&msg, old_dir);
468
469 return rpc_run_task(&task_setup_data);
470}
471
472/**
473 * nfs_sillyrename - Perform a silly-rename of a dentry
474 * @dir: inode of directory that contains dentry
475 * @dentry: dentry to be sillyrenamed
476 *
477 * NFSv2/3 is stateless and the server doesn't know when the client is
478 * holding a file open. To prevent application problems when a file is
479 * unlinked while it's still open, the client performs a "silly-rename".
480 * That is, it renames the file to a hidden file in the same directory,
481 * and only performs the unlink once the last reference to it is put.
482 *
483 * The final cleanup is done during dentry_iput.
484 */
485int
486nfs_sillyrename(struct inode *dir, struct dentry *dentry)
487{
488 static unsigned int sillycounter;
489 const int fileidsize = sizeof(NFS_FILEID(dentry->d_inode))*2;
490 const int countersize = sizeof(sillycounter)*2;
491 const int slen = sizeof(".nfs")+fileidsize+countersize-1;
492 char silly[slen+1];
493 struct dentry *sdentry;
494 struct rpc_task *task;
495 int error = -EIO;
496
497 dfprintk(VFS, "NFS: silly-rename(%s/%s, ct=%d)\n",
498 dentry->d_parent->d_name.name, dentry->d_name.name,
499 dentry->d_count);
500 nfs_inc_stats(dir, NFSIOS_SILLYRENAME);
501
502 /*
503 * We don't allow a dentry to be silly-renamed twice.
504 */
505 error = -EBUSY;
506 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
507 goto out;
508
509 sprintf(silly, ".nfs%*.*Lx",
510 fileidsize, fileidsize,
511 (unsigned long long)NFS_FILEID(dentry->d_inode));
512
513 /* Return delegation in anticipation of the rename */
514 nfs_inode_return_delegation(dentry->d_inode);
515
516 sdentry = NULL;
517 do {
518 char *suffix = silly + slen - countersize;
519
520 dput(sdentry);
521 sillycounter++;
522 sprintf(suffix, "%*.*x", countersize, countersize, sillycounter);
523
524 dfprintk(VFS, "NFS: trying to rename %s to %s\n",
525 dentry->d_name.name, silly);
526
527 sdentry = lookup_one_len(silly, dentry->d_parent, slen);
528 /*
529 * N.B. Better to return EBUSY here ... it could be
530 * dangerous to delete the file while it's in use.
531 */
532 if (IS_ERR(sdentry))
533 goto out;
534 } while (sdentry->d_inode != NULL); /* need negative lookup */
535
536 /* queue unlink first. Can't do this from rpc_release as it
537 * has to allocate memory
538 */
539 error = nfs_async_unlink(dir, dentry);
540 if (error)
541 goto out_dput;
542
543 /* run the rename task, undo unlink if it fails */
544 task = nfs_async_rename(dir, dir, dentry, sdentry);
545 if (IS_ERR(task)) {
546 error = -EBUSY;
547 nfs_cancel_async_unlink(dentry);
548 goto out_dput;
549 }
550
551 /* wait for the RPC task to complete, unless a SIGKILL intervenes */
552 error = rpc_wait_for_completion_task(task);
553 if (error == 0)
554 error = task->tk_status;
555 rpc_put_task(task);
556out_dput:
557 dput(sdentry);
558out:
559 return error;
560}
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index ce728829f79a..10d648ea128b 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -13,6 +13,7 @@
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/writeback.h> 14#include <linux/writeback.h>
15#include <linux/swap.h> 15#include <linux/swap.h>
16#include <linux/migrate.h>
16 17
17#include <linux/sunrpc/clnt.h> 18#include <linux/sunrpc/clnt.h>
18#include <linux/nfs_fs.h> 19#include <linux/nfs_fs.h>
@@ -26,6 +27,7 @@
26#include "internal.h" 27#include "internal.h"
27#include "iostat.h" 28#include "iostat.h"
28#include "nfs4_fs.h" 29#include "nfs4_fs.h"
30#include "fscache.h"
29 31
30#define NFSDBG_FACILITY NFSDBG_PAGECACHE 32#define NFSDBG_FACILITY NFSDBG_PAGECACHE
31 33
@@ -53,7 +55,6 @@ struct nfs_write_data *nfs_commitdata_alloc(void)
53 if (p) { 55 if (p) {
54 memset(p, 0, sizeof(*p)); 56 memset(p, 0, sizeof(*p));
55 INIT_LIST_HEAD(&p->pages); 57 INIT_LIST_HEAD(&p->pages);
56 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
57 } 58 }
58 return p; 59 return p;
59} 60}
@@ -73,7 +74,6 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
73 memset(p, 0, sizeof(*p)); 74 memset(p, 0, sizeof(*p));
74 INIT_LIST_HEAD(&p->pages); 75 INIT_LIST_HEAD(&p->pages);
75 p->npages = pagecount; 76 p->npages = pagecount;
76 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
77 if (pagecount <= ARRAY_SIZE(p->page_array)) 77 if (pagecount <= ARRAY_SIZE(p->page_array))
78 p->pagevec = p->page_array; 78 p->pagevec = p->page_array;
79 else { 79 else {
@@ -87,17 +87,15 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
87 return p; 87 return p;
88} 88}
89 89
90static void nfs_writedata_free(struct nfs_write_data *p) 90void nfs_writedata_free(struct nfs_write_data *p)
91{ 91{
92 if (p && (p->pagevec != &p->page_array[0])) 92 if (p && (p->pagevec != &p->page_array[0]))
93 kfree(p->pagevec); 93 kfree(p->pagevec);
94 mempool_free(p, nfs_wdata_mempool); 94 mempool_free(p, nfs_wdata_mempool);
95} 95}
96 96
97void nfs_writedata_release(void *data) 97static void nfs_writedata_release(struct nfs_write_data *wdata)
98{ 98{
99 struct nfs_write_data *wdata = data;
100
101 put_nfs_open_context(wdata->args.context); 99 put_nfs_open_context(wdata->args.context);
102 nfs_writedata_free(wdata); 100 nfs_writedata_free(wdata);
103} 101}
@@ -178,7 +176,7 @@ static int wb_priority(struct writeback_control *wbc)
178{ 176{
179 if (wbc->for_reclaim) 177 if (wbc->for_reclaim)
180 return FLUSH_HIGHPRI | FLUSH_STABLE; 178 return FLUSH_HIGHPRI | FLUSH_STABLE;
181 if (wbc->for_kupdate) 179 if (wbc->for_kupdate || wbc->for_background)
182 return FLUSH_LOWPRI; 180 return FLUSH_LOWPRI;
183 return 0; 181 return 0;
184} 182}
@@ -201,9 +199,12 @@ static int nfs_set_page_writeback(struct page *page)
201 struct inode *inode = page->mapping->host; 199 struct inode *inode = page->mapping->host;
202 struct nfs_server *nfss = NFS_SERVER(inode); 200 struct nfs_server *nfss = NFS_SERVER(inode);
203 201
202 page_cache_get(page);
204 if (atomic_long_inc_return(&nfss->writeback) > 203 if (atomic_long_inc_return(&nfss->writeback) >
205 NFS_CONGESTION_ON_THRESH) 204 NFS_CONGESTION_ON_THRESH) {
206 set_bdi_congested(&nfss->backing_dev_info, WRITE); 205 set_bdi_congested(&nfss->backing_dev_info,
206 BLK_RW_ASYNC);
207 }
207 } 208 }
208 return ret; 209 return ret;
209} 210}
@@ -214,28 +215,22 @@ static void nfs_end_page_writeback(struct page *page)
214 struct nfs_server *nfss = NFS_SERVER(inode); 215 struct nfs_server *nfss = NFS_SERVER(inode);
215 216
216 end_page_writeback(page); 217 end_page_writeback(page);
218 page_cache_release(page);
217 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH) 219 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
218 clear_bdi_congested(&nfss->backing_dev_info, WRITE); 220 clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC);
219} 221}
220 222
221/* 223static struct nfs_page *nfs_find_and_lock_request(struct page *page, bool nonblock)
222 * Find an associated nfs write request, and prepare to flush it out
223 * May return an error if the user signalled nfs_wait_on_request().
224 */
225static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
226 struct page *page)
227{ 224{
228 struct inode *inode = page->mapping->host; 225 struct inode *inode = page->mapping->host;
229 struct nfs_page *req; 226 struct nfs_page *req;
230 int ret; 227 int ret;
231 228
232 spin_lock(&inode->i_lock); 229 spin_lock(&inode->i_lock);
233 for(;;) { 230 for (;;) {
234 req = nfs_page_find_request_locked(page); 231 req = nfs_page_find_request_locked(page);
235 if (req == NULL) { 232 if (req == NULL)
236 spin_unlock(&inode->i_lock); 233 break;
237 return 0;
238 }
239 if (nfs_set_page_tag_locked(req)) 234 if (nfs_set_page_tag_locked(req))
240 break; 235 break;
241 /* Note: If we hold the page lock, as is the case in nfs_writepage, 236 /* Note: If we hold the page lock, as is the case in nfs_writepage,
@@ -244,37 +239,63 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
244 * request as dirty (in which case we don't care). 239 * request as dirty (in which case we don't care).
245 */ 240 */
246 spin_unlock(&inode->i_lock); 241 spin_unlock(&inode->i_lock);
247 ret = nfs_wait_on_request(req); 242 if (!nonblock)
243 ret = nfs_wait_on_request(req);
244 else
245 ret = -EAGAIN;
248 nfs_release_request(req); 246 nfs_release_request(req);
249 if (ret != 0) 247 if (ret != 0)
250 return ret; 248 return ERR_PTR(ret);
251 spin_lock(&inode->i_lock); 249 spin_lock(&inode->i_lock);
252 } 250 }
253 if (test_bit(PG_CLEAN, &req->wb_flags)) {
254 spin_unlock(&inode->i_lock);
255 BUG();
256 }
257 if (nfs_set_page_writeback(page) != 0) {
258 spin_unlock(&inode->i_lock);
259 BUG();
260 }
261 spin_unlock(&inode->i_lock); 251 spin_unlock(&inode->i_lock);
252 return req;
253}
254
255/*
256 * Find an associated nfs write request, and prepare to flush it out
257 * May return an error if the user signalled nfs_wait_on_request().
258 */
259static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
260 struct page *page, bool nonblock)
261{
262 struct nfs_page *req;
263 int ret = 0;
264
265 req = nfs_find_and_lock_request(page, nonblock);
266 if (!req)
267 goto out;
268 ret = PTR_ERR(req);
269 if (IS_ERR(req))
270 goto out;
271
272 ret = nfs_set_page_writeback(page);
273 BUG_ON(ret != 0);
274 BUG_ON(test_bit(PG_CLEAN, &req->wb_flags));
275
262 if (!nfs_pageio_add_request(pgio, req)) { 276 if (!nfs_pageio_add_request(pgio, req)) {
263 nfs_redirty_request(req); 277 nfs_redirty_request(req);
264 return pgio->pg_error; 278 ret = pgio->pg_error;
265 } 279 }
266 return 0; 280out:
281 return ret;
267} 282}
268 283
269static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio) 284static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio)
270{ 285{
271 struct inode *inode = page->mapping->host; 286 struct inode *inode = page->mapping->host;
287 int ret;
272 288
273 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE); 289 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
274 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1); 290 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1);
275 291
276 nfs_pageio_cond_complete(pgio, page->index); 292 nfs_pageio_cond_complete(pgio, page->index);
277 return nfs_page_async_flush(pgio, page); 293 ret = nfs_page_async_flush(pgio, page, wbc->sync_mode == WB_SYNC_NONE);
294 if (ret == -EAGAIN) {
295 redirty_page_for_writepage(wbc, page);
296 ret = 0;
297 }
298 return ret;
278} 299}
279 300
280/* 301/*
@@ -369,6 +390,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
369 if (nfs_have_delegation(inode, FMODE_WRITE)) 390 if (nfs_have_delegation(inode, FMODE_WRITE))
370 nfsi->change_attr++; 391 nfsi->change_attr++;
371 } 392 }
393 set_bit(PG_MAPPED, &req->wb_flags);
372 SetPagePrivate(req->wb_page); 394 SetPagePrivate(req->wb_page);
373 set_page_private(req->wb_page, (unsigned long)req); 395 set_page_private(req->wb_page, (unsigned long)req);
374 nfsi->npages++; 396 nfsi->npages++;
@@ -394,6 +416,7 @@ static void nfs_inode_remove_request(struct nfs_page *req)
394 spin_lock(&inode->i_lock); 416 spin_lock(&inode->i_lock);
395 set_page_private(req->wb_page, 0); 417 set_page_private(req->wb_page, 0);
396 ClearPagePrivate(req->wb_page); 418 ClearPagePrivate(req->wb_page);
419 clear_bit(PG_MAPPED, &req->wb_flags);
397 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index); 420 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
398 nfsi->npages--; 421 nfsi->npages--;
399 if (!nfsi->npages) { 422 if (!nfsi->npages) {
@@ -401,7 +424,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
401 iput(inode); 424 iput(inode);
402 } else 425 } else
403 spin_unlock(&inode->i_lock); 426 spin_unlock(&inode->i_lock);
404 nfs_clear_request(req);
405 nfs_release_request(req); 427 nfs_release_request(req);
406} 428}
407 429
@@ -409,6 +431,7 @@ static void
409nfs_mark_request_dirty(struct nfs_page *req) 431nfs_mark_request_dirty(struct nfs_page *req)
410{ 432{
411 __set_page_dirty_nobuffers(req->wb_page); 433 __set_page_dirty_nobuffers(req->wb_page);
434 __mark_inode_dirty(req->wb_page->mapping->host, I_DIRTY_DATASYNC);
412} 435}
413 436
414#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 437#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
@@ -426,6 +449,7 @@ nfs_mark_request_commit(struct nfs_page *req)
426 radix_tree_tag_set(&nfsi->nfs_page_tree, 449 radix_tree_tag_set(&nfsi->nfs_page_tree,
427 req->wb_index, 450 req->wb_index,
428 NFS_PAGE_TAG_COMMIT); 451 NFS_PAGE_TAG_COMMIT);
452 nfsi->ncommit++;
429 spin_unlock(&inode->i_lock); 453 spin_unlock(&inode->i_lock);
430 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 454 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
431 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE); 455 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
@@ -489,57 +513,6 @@ int nfs_reschedule_unstable_write(struct nfs_page *req)
489} 513}
490#endif 514#endif
491 515
492/*
493 * Wait for a request to complete.
494 *
495 * Interruptible by fatal signals only.
496 */
497static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, unsigned int npages)
498{
499 struct nfs_inode *nfsi = NFS_I(inode);
500 struct nfs_page *req;
501 pgoff_t idx_end, next;
502 unsigned int res = 0;
503 int error;
504
505 if (npages == 0)
506 idx_end = ~0;
507 else
508 idx_end = idx_start + npages - 1;
509
510 next = idx_start;
511 while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_LOCKED)) {
512 if (req->wb_index > idx_end)
513 break;
514
515 next = req->wb_index + 1;
516 BUG_ON(!NFS_WBACK_BUSY(req));
517
518 kref_get(&req->wb_kref);
519 spin_unlock(&inode->i_lock);
520 error = nfs_wait_on_request(req);
521 nfs_release_request(req);
522 spin_lock(&inode->i_lock);
523 if (error < 0)
524 return error;
525 res++;
526 }
527 return res;
528}
529
530static void nfs_cancel_commit_list(struct list_head *head)
531{
532 struct nfs_page *req;
533
534 while(!list_empty(head)) {
535 req = nfs_list_entry(head->next);
536 nfs_list_remove_request(req);
537 nfs_clear_request_commit(req);
538 nfs_inode_remove_request(req);
539 nfs_unlock_request(req);
540 }
541}
542
543#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 516#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
544static int 517static int
545nfs_need_commit(struct nfs_inode *nfsi) 518nfs_need_commit(struct nfs_inode *nfsi)
@@ -561,11 +534,17 @@ static int
561nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 534nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages)
562{ 535{
563 struct nfs_inode *nfsi = NFS_I(inode); 536 struct nfs_inode *nfsi = NFS_I(inode);
537 int ret;
564 538
565 if (!nfs_need_commit(nfsi)) 539 if (!nfs_need_commit(nfsi))
566 return 0; 540 return 0;
567 541
568 return nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT); 542 ret = nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT);
543 if (ret > 0)
544 nfsi->ncommit -= ret;
545 if (nfs_need_commit(NFS_I(inode)))
546 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
547 return ret;
569} 548}
570#else 549#else
571static inline int nfs_need_commit(struct nfs_inode *nfsi) 550static inline int nfs_need_commit(struct nfs_inode *nfsi)
@@ -630,9 +609,10 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
630 spin_lock(&inode->i_lock); 609 spin_lock(&inode->i_lock);
631 } 610 }
632 611
633 if (nfs_clear_request_commit(req)) 612 if (nfs_clear_request_commit(req) &&
634 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree, 613 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree,
635 req->wb_index, NFS_PAGE_TAG_COMMIT); 614 req->wb_index, NFS_PAGE_TAG_COMMIT) != NULL)
615 NFS_I(inode)->ncommit--;
636 616
637 /* Okay, the request matches. Update the region */ 617 /* Okay, the request matches. Update the region */
638 if (offset < req->wb_offset) { 618 if (offset < req->wb_offset) {
@@ -691,9 +671,11 @@ static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
691 req = nfs_setup_write_request(ctx, page, offset, count); 671 req = nfs_setup_write_request(ctx, page, offset, count);
692 if (IS_ERR(req)) 672 if (IS_ERR(req))
693 return PTR_ERR(req); 673 return PTR_ERR(req);
674 nfs_mark_request_dirty(req);
694 /* Update file length */ 675 /* Update file length */
695 nfs_grow_file(page, offset, count); 676 nfs_grow_file(page, offset, count);
696 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes); 677 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
678 nfs_mark_request_dirty(req);
697 nfs_clear_page_tag_locked(req); 679 nfs_clear_page_tag_locked(req);
698 return 0; 680 return 0;
699} 681}
@@ -715,7 +697,9 @@ int nfs_flush_incompatible(struct file *file, struct page *page)
715 req = nfs_page_find_request(page); 697 req = nfs_page_find_request(page);
716 if (req == NULL) 698 if (req == NULL)
717 return 0; 699 return 0;
718 do_flush = req->wb_page != page || req->wb_context != ctx; 700 do_flush = req->wb_page != page || req->wb_context != ctx ||
701 req->wb_lock_context->lockowner != current->files ||
702 req->wb_lock_context->pid != current->tgid;
719 nfs_release_request(req); 703 nfs_release_request(req);
720 if (!do_flush) 704 if (!do_flush)
721 return 0; 705 return 0;
@@ -762,7 +746,7 @@ int nfs_updatepage(struct file *file, struct page *page,
762 */ 746 */
763 if (nfs_write_pageuptodate(page, inode) && 747 if (nfs_write_pageuptodate(page, inode) &&
764 inode->i_flock == NULL && 748 inode->i_flock == NULL &&
765 !(file->f_flags & O_SYNC)) { 749 !(file->f_flags & O_DSYNC)) {
766 count = max(count + offset, nfs_page_length(page)); 750 count = max(count + offset, nfs_page_length(page));
767 offset = 0; 751 offset = 0;
768 } 752 }
@@ -770,8 +754,6 @@ int nfs_updatepage(struct file *file, struct page *page,
770 status = nfs_writepage_setup(ctx, page, offset, count); 754 status = nfs_writepage_setup(ctx, page, offset, count);
771 if (status < 0) 755 if (status < 0)
772 nfs_set_pageerror(page); 756 nfs_set_pageerror(page);
773 else
774 __set_page_dirty_nobuffers(page);
775 757
776 dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n", 758 dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n",
777 status, (long long)i_size_read(inode)); 759 status, (long long)i_size_read(inode));
@@ -780,13 +762,12 @@ int nfs_updatepage(struct file *file, struct page *page,
780 762
781static void nfs_writepage_release(struct nfs_page *req) 763static void nfs_writepage_release(struct nfs_page *req)
782{ 764{
765 struct page *page = req->wb_page;
783 766
784 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) { 767 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req))
785 nfs_end_page_writeback(req->wb_page);
786 nfs_inode_remove_request(req); 768 nfs_inode_remove_request(req);
787 } else
788 nfs_end_page_writeback(req->wb_page);
789 nfs_clear_page_tag_locked(req); 769 nfs_clear_page_tag_locked(req);
770 nfs_end_page_writeback(page);
790} 771}
791 772
792static int flush_task_priority(int how) 773static int flush_task_priority(int how)
@@ -810,7 +791,6 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
810 int how) 791 int how)
811{ 792{
812 struct inode *inode = req->wb_context->path.dentry->d_inode; 793 struct inode *inode = req->wb_context->path.dentry->d_inode;
813 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
814 int priority = flush_task_priority(how); 794 int priority = flush_task_priority(how);
815 struct rpc_task *task; 795 struct rpc_task *task;
816 struct rpc_message msg = { 796 struct rpc_message msg = {
@@ -825,9 +805,10 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
825 .callback_ops = call_ops, 805 .callback_ops = call_ops,
826 .callback_data = data, 806 .callback_data = data,
827 .workqueue = nfsiod_workqueue, 807 .workqueue = nfsiod_workqueue,
828 .flags = flags, 808 .flags = RPC_TASK_ASYNC,
829 .priority = priority, 809 .priority = priority,
830 }; 810 };
811 int ret = 0;
831 812
832 /* Set up the RPC argument and reply structs 813 /* Set up the RPC argument and reply structs
833 * NB: take care not to mess about with data->commit et al. */ 814 * NB: take care not to mess about with data->commit et al. */
@@ -842,6 +823,7 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
842 data->args.pages = data->pagevec; 823 data->args.pages = data->pagevec;
843 data->args.count = count; 824 data->args.count = count;
844 data->args.context = get_nfs_open_context(req->wb_context); 825 data->args.context = get_nfs_open_context(req->wb_context);
826 data->args.lock_context = req->wb_lock_context;
845 data->args.stable = NFS_UNSTABLE; 827 data->args.stable = NFS_UNSTABLE;
846 if (how & FLUSH_STABLE) { 828 if (how & FLUSH_STABLE) {
847 data->args.stable = NFS_DATA_SYNC; 829 data->args.stable = NFS_DATA_SYNC;
@@ -866,10 +848,18 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
866 (unsigned long long)data->args.offset); 848 (unsigned long long)data->args.offset);
867 849
868 task = rpc_run_task(&task_setup_data); 850 task = rpc_run_task(&task_setup_data);
869 if (IS_ERR(task)) 851 if (IS_ERR(task)) {
870 return PTR_ERR(task); 852 ret = PTR_ERR(task);
853 goto out;
854 }
855 if (how & FLUSH_SYNC) {
856 ret = rpc_wait_for_completion_task(task);
857 if (ret == 0)
858 ret = task->tk_status;
859 }
871 rpc_put_task(task); 860 rpc_put_task(task);
872 return 0; 861out:
862 return ret;
873} 863}
874 864
875/* If a nfs_flush_* function fails, it should remove reqs from @head and 865/* If a nfs_flush_* function fails, it should remove reqs from @head and
@@ -878,9 +868,11 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
878 */ 868 */
879static void nfs_redirty_request(struct nfs_page *req) 869static void nfs_redirty_request(struct nfs_page *req)
880{ 870{
871 struct page *page = req->wb_page;
872
881 nfs_mark_request_dirty(req); 873 nfs_mark_request_dirty(req);
882 nfs_end_page_writeback(req->wb_page);
883 nfs_clear_page_tag_locked(req); 874 nfs_clear_page_tag_locked(req);
875 nfs_end_page_writeback(page);
884} 876}
885 877
886/* 878/*
@@ -1055,9 +1047,9 @@ out:
1055void nfs_write_prepare(struct rpc_task *task, void *calldata) 1047void nfs_write_prepare(struct rpc_task *task, void *calldata)
1056{ 1048{
1057 struct nfs_write_data *data = calldata; 1049 struct nfs_write_data *data = calldata;
1058 struct nfs_client *clp = (NFS_SERVER(data->inode))->nfs_client;
1059 1050
1060 if (nfs4_setup_sequence(clp, &data->args.seq_args, 1051 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
1052 &data->args.seq_args,
1061 &data->res.seq_res, 1, task)) 1053 &data->res.seq_res, 1, task))
1062 return; 1054 return;
1063 rpc_call_start(task); 1055 rpc_call_start(task);
@@ -1115,16 +1107,15 @@ static void nfs_writeback_release_full(void *calldata)
1115 if (nfs_write_need_commit(data)) { 1107 if (nfs_write_need_commit(data)) {
1116 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf)); 1108 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1117 nfs_mark_request_commit(req); 1109 nfs_mark_request_commit(req);
1118 nfs_end_page_writeback(page);
1119 dprintk(" marked for commit\n"); 1110 dprintk(" marked for commit\n");
1120 goto next; 1111 goto next;
1121 } 1112 }
1122 dprintk(" OK\n"); 1113 dprintk(" OK\n");
1123remove_request: 1114remove_request:
1124 nfs_end_page_writeback(page);
1125 nfs_inode_remove_request(req); 1115 nfs_inode_remove_request(req);
1126 next: 1116 next:
1127 nfs_clear_page_tag_locked(req); 1117 nfs_clear_page_tag_locked(req);
1118 nfs_end_page_writeback(page);
1128 } 1119 }
1129 nfs_writedata_release(calldata); 1120 nfs_writedata_release(calldata);
1130} 1121}
@@ -1204,7 +1195,7 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1204 */ 1195 */
1205 argp->stable = NFS_FILE_SYNC; 1196 argp->stable = NFS_FILE_SYNC;
1206 } 1197 }
1207 nfs4_restart_rpc(task, server->nfs_client); 1198 nfs_restart_rpc(task, server->nfs_client);
1208 return -EAGAIN; 1199 return -EAGAIN;
1209 } 1200 }
1210 if (time_before(complain, jiffies)) { 1201 if (time_before(complain, jiffies)) {
@@ -1216,13 +1207,31 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1216 /* Can't do anything about it except throw an error. */ 1207 /* Can't do anything about it except throw an error. */
1217 task->tk_status = -EIO; 1208 task->tk_status = -EIO;
1218 } 1209 }
1219 nfs4_sequence_free_slot(server->nfs_client, &data->res.seq_res);
1220 return 0; 1210 return 0;
1221} 1211}
1222 1212
1223 1213
1224#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 1214#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1225void nfs_commitdata_release(void *data) 1215static int nfs_commit_set_lock(struct nfs_inode *nfsi, int may_wait)
1216{
1217 if (!test_and_set_bit(NFS_INO_COMMIT, &nfsi->flags))
1218 return 1;
1219 if (may_wait && !out_of_line_wait_on_bit_lock(&nfsi->flags,
1220 NFS_INO_COMMIT, nfs_wait_bit_killable,
1221 TASK_KILLABLE))
1222 return 1;
1223 return 0;
1224}
1225
1226static void nfs_commit_clear_lock(struct nfs_inode *nfsi)
1227{
1228 clear_bit(NFS_INO_COMMIT, &nfsi->flags);
1229 smp_mb__after_clear_bit();
1230 wake_up_bit(&nfsi->flags, NFS_INO_COMMIT);
1231}
1232
1233
1234static void nfs_commitdata_release(void *data)
1226{ 1235{
1227 struct nfs_write_data *wdata = data; 1236 struct nfs_write_data *wdata = data;
1228 1237
@@ -1239,7 +1248,6 @@ static int nfs_commit_rpcsetup(struct list_head *head,
1239{ 1248{
1240 struct nfs_page *first = nfs_list_entry(head->next); 1249 struct nfs_page *first = nfs_list_entry(head->next);
1241 struct inode *inode = first->wb_context->path.dentry->d_inode; 1250 struct inode *inode = first->wb_context->path.dentry->d_inode;
1242 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
1243 int priority = flush_task_priority(how); 1251 int priority = flush_task_priority(how);
1244 struct rpc_task *task; 1252 struct rpc_task *task;
1245 struct rpc_message msg = { 1253 struct rpc_message msg = {
@@ -1254,7 +1262,7 @@ static int nfs_commit_rpcsetup(struct list_head *head,
1254 .callback_ops = &nfs_commit_ops, 1262 .callback_ops = &nfs_commit_ops,
1255 .callback_data = data, 1263 .callback_data = data,
1256 .workqueue = nfsiod_workqueue, 1264 .workqueue = nfsiod_workqueue,
1257 .flags = flags, 1265 .flags = RPC_TASK_ASYNC,
1258 .priority = priority, 1266 .priority = priority,
1259 }; 1267 };
1260 1268
@@ -1314,6 +1322,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1314 BDI_RECLAIMABLE); 1322 BDI_RECLAIMABLE);
1315 nfs_clear_page_tag_locked(req); 1323 nfs_clear_page_tag_locked(req);
1316 } 1324 }
1325 nfs_commit_clear_lock(NFS_I(inode));
1317 return -ENOMEM; 1326 return -ENOMEM;
1318} 1327}
1319 1328
@@ -1369,6 +1378,7 @@ static void nfs_commit_release(void *calldata)
1369 next: 1378 next:
1370 nfs_clear_page_tag_locked(req); 1379 nfs_clear_page_tag_locked(req);
1371 } 1380 }
1381 nfs_commit_clear_lock(NFS_I(data->inode));
1372 nfs_commitdata_release(calldata); 1382 nfs_commitdata_release(calldata);
1373} 1383}
1374 1384
@@ -1383,8 +1393,11 @@ static const struct rpc_call_ops nfs_commit_ops = {
1383int nfs_commit_inode(struct inode *inode, int how) 1393int nfs_commit_inode(struct inode *inode, int how)
1384{ 1394{
1385 LIST_HEAD(head); 1395 LIST_HEAD(head);
1386 int res; 1396 int may_wait = how & FLUSH_SYNC;
1397 int res = 0;
1387 1398
1399 if (!nfs_commit_set_lock(NFS_I(inode), may_wait))
1400 goto out_mark_dirty;
1388 spin_lock(&inode->i_lock); 1401 spin_lock(&inode->i_lock);
1389 res = nfs_scan_commit(inode, &head, 0, 0); 1402 res = nfs_scan_commit(inode, &head, 0, 0);
1390 spin_unlock(&inode->i_lock); 1403 spin_unlock(&inode->i_lock);
@@ -1392,96 +1405,66 @@ int nfs_commit_inode(struct inode *inode, int how)
1392 int error = nfs_commit_list(inode, &head, how); 1405 int error = nfs_commit_list(inode, &head, how);
1393 if (error < 0) 1406 if (error < 0)
1394 return error; 1407 return error;
1395 } 1408 if (may_wait)
1409 wait_on_bit(&NFS_I(inode)->flags, NFS_INO_COMMIT,
1410 nfs_wait_bit_killable,
1411 TASK_KILLABLE);
1412 else
1413 goto out_mark_dirty;
1414 } else
1415 nfs_commit_clear_lock(NFS_I(inode));
1416 return res;
1417 /* Note: If we exit without ensuring that the commit is complete,
1418 * we must mark the inode as dirty. Otherwise, future calls to
1419 * sync_inode() with the WB_SYNC_ALL flag set will fail to ensure
1420 * that the data is on the disk.
1421 */
1422out_mark_dirty:
1423 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1396 return res; 1424 return res;
1397} 1425}
1398#else
1399static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1400{
1401 return 0;
1402}
1403#endif
1404 1426
1405long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how) 1427static int nfs_commit_unstable_pages(struct inode *inode, struct writeback_control *wbc)
1406{ 1428{
1407 struct inode *inode = mapping->host; 1429 struct nfs_inode *nfsi = NFS_I(inode);
1408 pgoff_t idx_start, idx_end; 1430 int flags = FLUSH_SYNC;
1409 unsigned int npages = 0; 1431 int ret = 0;
1410 LIST_HEAD(head); 1432
1411 int nocommit = how & FLUSH_NOCOMMIT; 1433 if (wbc->sync_mode == WB_SYNC_NONE) {
1412 long pages, ret; 1434 /* Don't commit yet if this is a non-blocking flush and there
1413 1435 * are a lot of outstanding writes for this mapping.
1414 /* FIXME */ 1436 */
1415 if (wbc->range_cyclic) 1437 if (nfsi->ncommit <= (nfsi->npages >> 1))
1416 idx_start = 0; 1438 goto out_mark_dirty;
1417 else { 1439
1418 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT; 1440 /* don't wait for the COMMIT response */
1419 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT; 1441 flags = 0;
1420 if (idx_end > idx_start) {
1421 pgoff_t l_npages = 1 + idx_end - idx_start;
1422 npages = l_npages;
1423 if (sizeof(npages) != sizeof(l_npages) &&
1424 (pgoff_t)npages != l_npages)
1425 npages = 0;
1426 }
1427 } 1442 }
1428 how &= ~FLUSH_NOCOMMIT;
1429 spin_lock(&inode->i_lock);
1430 do {
1431 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1432 if (ret != 0)
1433 continue;
1434 if (nocommit)
1435 break;
1436 pages = nfs_scan_commit(inode, &head, idx_start, npages);
1437 if (pages == 0)
1438 break;
1439 if (how & FLUSH_INVALIDATE) {
1440 spin_unlock(&inode->i_lock);
1441 nfs_cancel_commit_list(&head);
1442 ret = pages;
1443 spin_lock(&inode->i_lock);
1444 continue;
1445 }
1446 pages += nfs_scan_commit(inode, &head, 0, 0);
1447 spin_unlock(&inode->i_lock);
1448 ret = nfs_commit_list(inode, &head, how);
1449 spin_lock(&inode->i_lock);
1450 1443
1451 } while (ret >= 0); 1444 ret = nfs_commit_inode(inode, flags);
1452 spin_unlock(&inode->i_lock); 1445 if (ret >= 0) {
1446 if (wbc->sync_mode == WB_SYNC_NONE) {
1447 if (ret < wbc->nr_to_write)
1448 wbc->nr_to_write -= ret;
1449 else
1450 wbc->nr_to_write = 0;
1451 }
1452 return 0;
1453 }
1454out_mark_dirty:
1455 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1453 return ret; 1456 return ret;
1454} 1457}
1455 1458#else
1456static int __nfs_write_mapping(struct address_space *mapping, struct writeback_control *wbc, int how) 1459static int nfs_commit_unstable_pages(struct inode *inode, struct writeback_control *wbc)
1457{ 1460{
1458 int ret;
1459
1460 ret = nfs_writepages(mapping, wbc);
1461 if (ret < 0)
1462 goto out;
1463 ret = nfs_sync_mapping_wait(mapping, wbc, how);
1464 if (ret < 0)
1465 goto out;
1466 return 0; 1461 return 0;
1467out:
1468 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
1469 return ret;
1470} 1462}
1463#endif
1471 1464
1472/* Two pass sync: first using WB_SYNC_NONE, then WB_SYNC_ALL */ 1465int nfs_write_inode(struct inode *inode, struct writeback_control *wbc)
1473static int nfs_write_mapping(struct address_space *mapping, int how)
1474{ 1466{
1475 struct writeback_control wbc = { 1467 return nfs_commit_unstable_pages(inode, wbc);
1476 .bdi = mapping->backing_dev_info,
1477 .sync_mode = WB_SYNC_ALL,
1478 .nr_to_write = LONG_MAX,
1479 .range_start = 0,
1480 .range_end = LLONG_MAX,
1481 .for_writepages = 1,
1482 };
1483
1484 return __nfs_write_mapping(mapping, &wbc, how);
1485} 1468}
1486 1469
1487/* 1470/*
@@ -1489,37 +1472,27 @@ static int nfs_write_mapping(struct address_space *mapping, int how)
1489 */ 1472 */
1490int nfs_wb_all(struct inode *inode) 1473int nfs_wb_all(struct inode *inode)
1491{ 1474{
1492 return nfs_write_mapping(inode->i_mapping, 0); 1475 struct writeback_control wbc = {
1493} 1476 .sync_mode = WB_SYNC_ALL,
1477 .nr_to_write = LONG_MAX,
1478 .range_start = 0,
1479 .range_end = LLONG_MAX,
1480 };
1494 1481
1495int nfs_wb_nocommit(struct inode *inode) 1482 return sync_inode(inode, &wbc);
1496{
1497 return nfs_write_mapping(inode->i_mapping, FLUSH_NOCOMMIT);
1498} 1483}
1499 1484
1500int nfs_wb_page_cancel(struct inode *inode, struct page *page) 1485int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1501{ 1486{
1502 struct nfs_page *req; 1487 struct nfs_page *req;
1503 loff_t range_start = page_offset(page);
1504 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1505 struct writeback_control wbc = {
1506 .bdi = page->mapping->backing_dev_info,
1507 .sync_mode = WB_SYNC_ALL,
1508 .nr_to_write = LONG_MAX,
1509 .range_start = range_start,
1510 .range_end = range_end,
1511 };
1512 int ret = 0; 1488 int ret = 0;
1513 1489
1514 BUG_ON(!PageLocked(page)); 1490 BUG_ON(!PageLocked(page));
1515 for (;;) { 1491 for (;;) {
1492 wait_on_page_writeback(page);
1516 req = nfs_page_find_request(page); 1493 req = nfs_page_find_request(page);
1517 if (req == NULL) 1494 if (req == NULL)
1518 goto out;
1519 if (test_bit(PG_CLEAN, &req->wb_flags)) {
1520 nfs_release_request(req);
1521 break; 1495 break;
1522 }
1523 if (nfs_lock_request_dontget(req)) { 1496 if (nfs_lock_request_dontget(req)) {
1524 nfs_inode_remove_request(req); 1497 nfs_inode_remove_request(req);
1525 /* 1498 /*
@@ -1531,54 +1504,81 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1531 break; 1504 break;
1532 } 1505 }
1533 ret = nfs_wait_on_request(req); 1506 ret = nfs_wait_on_request(req);
1507 nfs_release_request(req);
1534 if (ret < 0) 1508 if (ret < 0)
1535 goto out; 1509 break;
1536 } 1510 }
1537 if (!PagePrivate(page))
1538 return 0;
1539 ret = nfs_sync_mapping_wait(page->mapping, &wbc, FLUSH_INVALIDATE);
1540out:
1541 return ret; 1511 return ret;
1542} 1512}
1543 1513
1544static int nfs_wb_page_priority(struct inode *inode, struct page *page, 1514/*
1545 int how) 1515 * Write back all requests on one page - we do this before reading it.
1516 */
1517int nfs_wb_page(struct inode *inode, struct page *page)
1546{ 1518{
1547 loff_t range_start = page_offset(page); 1519 loff_t range_start = page_offset(page);
1548 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1); 1520 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1549 struct writeback_control wbc = { 1521 struct writeback_control wbc = {
1550 .bdi = page->mapping->backing_dev_info,
1551 .sync_mode = WB_SYNC_ALL, 1522 .sync_mode = WB_SYNC_ALL,
1552 .nr_to_write = LONG_MAX, 1523 .nr_to_write = 0,
1553 .range_start = range_start, 1524 .range_start = range_start,
1554 .range_end = range_end, 1525 .range_end = range_end,
1555 }; 1526 };
1556 int ret; 1527 int ret;
1557 1528
1558 do { 1529 for (;;) {
1530 wait_on_page_writeback(page);
1559 if (clear_page_dirty_for_io(page)) { 1531 if (clear_page_dirty_for_io(page)) {
1560 ret = nfs_writepage_locked(page, &wbc); 1532 ret = nfs_writepage_locked(page, &wbc);
1561 if (ret < 0) 1533 if (ret < 0)
1562 goto out_error; 1534 goto out_error;
1563 } else if (!PagePrivate(page)) 1535 continue;
1536 }
1537 if (!PagePrivate(page))
1564 break; 1538 break;
1565 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how); 1539 ret = nfs_commit_inode(inode, FLUSH_SYNC);
1566 if (ret < 0) 1540 if (ret < 0)
1567 goto out_error; 1541 goto out_error;
1568 } while (PagePrivate(page)); 1542 }
1569 return 0; 1543 return 0;
1570out_error: 1544out_error:
1571 __mark_inode_dirty(inode, I_DIRTY_PAGES);
1572 return ret; 1545 return ret;
1573} 1546}
1574 1547
1575/* 1548#ifdef CONFIG_MIGRATION
1576 * Write back all requests on one page - we do this before reading it. 1549int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
1577 */ 1550 struct page *page)
1578int nfs_wb_page(struct inode *inode, struct page* page)
1579{ 1551{
1580 return nfs_wb_page_priority(inode, page, FLUSH_STABLE); 1552 struct nfs_page *req;
1553 int ret;
1554
1555 nfs_fscache_release_page(page, GFP_KERNEL);
1556
1557 req = nfs_find_and_lock_request(page, false);
1558 ret = PTR_ERR(req);
1559 if (IS_ERR(req))
1560 goto out;
1561
1562 ret = migrate_page(mapping, newpage, page);
1563 if (!req)
1564 goto out;
1565 if (ret)
1566 goto out_unlock;
1567 page_cache_get(newpage);
1568 spin_lock(&mapping->host->i_lock);
1569 req->wb_page = newpage;
1570 SetPagePrivate(newpage);
1571 set_page_private(newpage, (unsigned long)req);
1572 ClearPagePrivate(page);
1573 set_page_private(page, 0);
1574 spin_unlock(&mapping->host->i_lock);
1575 page_cache_release(page);
1576out_unlock:
1577 nfs_clear_page_tag_locked(req);
1578out:
1579 return ret;
1581} 1580}
1581#endif
1582 1582
1583int __init nfs_init_writepagecache(void) 1583int __init nfs_init_writepagecache(void)
1584{ 1584{