aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ceph/caps.c4
-rw-r--r--fs/ceph/dir.c4
-rw-r--r--fs/ceph/mds_client.c10
-rw-r--r--fs/ceph/mds_client.h7
-rw-r--r--fs/ceph/xattr.c4
-rw-r--r--fs/lockd/clnt4xdr.c2
-rw-r--r--fs/lockd/clntlock.c3
-rw-r--r--fs/lockd/clntxdr.c8
-rw-r--r--fs/lockd/host.c42
-rw-r--r--fs/lockd/mon.c21
-rw-r--r--fs/lockd/netns.h12
-rw-r--r--fs/lockd/svc.c117
-rw-r--r--fs/lockd/svclock.c59
-rw-r--r--fs/logfs/dev_mtd.c6
-rw-r--r--fs/nfs/Kconfig29
-rw-r--r--fs/nfs/blocklayout/blocklayout.c161
-rw-r--r--fs/nfs/blocklayout/blocklayout.h11
-rw-r--r--fs/nfs/blocklayout/blocklayoutdev.c46
-rw-r--r--fs/nfs/blocklayout/blocklayoutdm.c33
-rw-r--r--fs/nfs/blocklayout/extents.c2
-rw-r--r--fs/nfs/cache_lib.c61
-rw-r--r--fs/nfs/cache_lib.h10
-rw-r--r--fs/nfs/callback.c19
-rw-r--r--fs/nfs/callback.h3
-rw-r--r--fs/nfs/callback_proc.c99
-rw-r--r--fs/nfs/callback_xdr.c21
-rw-r--r--fs/nfs/client.c246
-rw-r--r--fs/nfs/delegation.c68
-rw-r--r--fs/nfs/delegation.h4
-rw-r--r--fs/nfs/dir.c27
-rw-r--r--fs/nfs/direct.c6
-rw-r--r--fs/nfs/dns_resolve.c130
-rw-r--r--fs/nfs/dns_resolve.h14
-rw-r--r--fs/nfs/file.c2
-rw-r--r--fs/nfs/fscache.c2
-rw-r--r--fs/nfs/idmap.c733
-rw-r--r--fs/nfs/inode.c119
-rw-r--r--fs/nfs/internal.h15
-rw-r--r--fs/nfs/mount_clnt.c16
-rw-r--r--fs/nfs/namespace.c5
-rw-r--r--fs/nfs/netns.h27
-rw-r--r--fs/nfs/nfs2xdr.c2
-rw-r--r--fs/nfs/nfs3acl.c2
-rw-r--r--fs/nfs/nfs3proc.c24
-rw-r--r--fs/nfs/nfs3xdr.c4
-rw-r--r--fs/nfs/nfs4_fs.h58
-rw-r--r--fs/nfs/nfs4filelayout.c272
-rw-r--r--fs/nfs/nfs4filelayout.h7
-rw-r--r--fs/nfs/nfs4filelayoutdev.c90
-rw-r--r--fs/nfs/nfs4namespace.c10
-rw-r--r--fs/nfs/nfs4proc.c687
-rw-r--r--fs/nfs/nfs4state.c353
-rw-r--r--fs/nfs/nfs4xdr.c702
-rw-r--r--fs/nfs/nfsroot.c2
-rw-r--r--fs/nfs/objlayout/objio_osd.c54
-rw-r--r--fs/nfs/objlayout/objlayout.c142
-rw-r--r--fs/nfs/objlayout/objlayout.h2
-rw-r--r--fs/nfs/pagelist.c92
-rw-r--r--fs/nfs/pnfs.c46
-rw-r--r--fs/nfs/pnfs.h98
-rw-r--r--fs/nfs/pnfs_dev.c4
-rw-r--r--fs/nfs/proc.c24
-rw-r--r--fs/nfs/read.c14
-rw-r--r--fs/nfs/super.c167
-rw-r--r--fs/nfs/sysctl.c2
-rw-r--r--fs/nfs/unlink.c45
-rw-r--r--fs/nfs/write.c213
-rw-r--r--fs/nfsd/nfs4callback.c8
-rw-r--r--fs/nfsd/nfs4state.c2
-rw-r--r--fs/nfsd/nfsctl.c6
-rw-r--r--fs/nfsd/nfssvc.c4
-rw-r--r--fs/nfsd/stats.c5
-rw-r--r--fs/proc/base.c126
73 files changed, 3232 insertions, 2243 deletions
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index b60fc8bfb3e9..620daad201db 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -641,10 +641,10 @@ static int __cap_is_valid(struct ceph_cap *cap)
641 unsigned long ttl; 641 unsigned long ttl;
642 u32 gen; 642 u32 gen;
643 643
644 spin_lock(&cap->session->s_cap_lock); 644 spin_lock(&cap->session->s_gen_ttl_lock);
645 gen = cap->session->s_cap_gen; 645 gen = cap->session->s_cap_gen;
646 ttl = cap->session->s_cap_ttl; 646 ttl = cap->session->s_cap_ttl;
647 spin_unlock(&cap->session->s_cap_lock); 647 spin_unlock(&cap->session->s_gen_ttl_lock);
648 648
649 if (cap->cap_gen < gen || time_after_eq(jiffies, ttl)) { 649 if (cap->cap_gen < gen || time_after_eq(jiffies, ttl)) {
650 dout("__cap_is_valid %p cap %p issued %s " 650 dout("__cap_is_valid %p cap %p issued %s "
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 618246bc2196..3e8094be4604 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -975,10 +975,10 @@ static int dentry_lease_is_valid(struct dentry *dentry)
975 di = ceph_dentry(dentry); 975 di = ceph_dentry(dentry);
976 if (di->lease_session) { 976 if (di->lease_session) {
977 s = di->lease_session; 977 s = di->lease_session;
978 spin_lock(&s->s_cap_lock); 978 spin_lock(&s->s_gen_ttl_lock);
979 gen = s->s_cap_gen; 979 gen = s->s_cap_gen;
980 ttl = s->s_cap_ttl; 980 ttl = s->s_cap_ttl;
981 spin_unlock(&s->s_cap_lock); 981 spin_unlock(&s->s_gen_ttl_lock);
982 982
983 if (di->lease_gen == gen && 983 if (di->lease_gen == gen &&
984 time_before(jiffies, dentry->d_time) && 984 time_before(jiffies, dentry->d_time) &&
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 23ab6a3f1825..866e8d7ca37d 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -262,6 +262,7 @@ static int parse_reply_info(struct ceph_msg *msg,
262 /* trace */ 262 /* trace */
263 ceph_decode_32_safe(&p, end, len, bad); 263 ceph_decode_32_safe(&p, end, len, bad);
264 if (len > 0) { 264 if (len > 0) {
265 ceph_decode_need(&p, end, len, bad);
265 err = parse_reply_info_trace(&p, p+len, info, features); 266 err = parse_reply_info_trace(&p, p+len, info, features);
266 if (err < 0) 267 if (err < 0)
267 goto out_bad; 268 goto out_bad;
@@ -270,6 +271,7 @@ static int parse_reply_info(struct ceph_msg *msg,
270 /* extra */ 271 /* extra */
271 ceph_decode_32_safe(&p, end, len, bad); 272 ceph_decode_32_safe(&p, end, len, bad);
272 if (len > 0) { 273 if (len > 0) {
274 ceph_decode_need(&p, end, len, bad);
273 err = parse_reply_info_extra(&p, p+len, info, features); 275 err = parse_reply_info_extra(&p, p+len, info, features);
274 if (err < 0) 276 if (err < 0)
275 goto out_bad; 277 goto out_bad;
@@ -398,9 +400,11 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
398 s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS; 400 s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS;
399 s->s_con.peer_name.num = cpu_to_le64(mds); 401 s->s_con.peer_name.num = cpu_to_le64(mds);
400 402
401 spin_lock_init(&s->s_cap_lock); 403 spin_lock_init(&s->s_gen_ttl_lock);
402 s->s_cap_gen = 0; 404 s->s_cap_gen = 0;
403 s->s_cap_ttl = 0; 405 s->s_cap_ttl = 0;
406
407 spin_lock_init(&s->s_cap_lock);
404 s->s_renew_requested = 0; 408 s->s_renew_requested = 0;
405 s->s_renew_seq = 0; 409 s->s_renew_seq = 0;
406 INIT_LIST_HEAD(&s->s_caps); 410 INIT_LIST_HEAD(&s->s_caps);
@@ -2326,10 +2330,10 @@ static void handle_session(struct ceph_mds_session *session,
2326 case CEPH_SESSION_STALE: 2330 case CEPH_SESSION_STALE:
2327 pr_info("mds%d caps went stale, renewing\n", 2331 pr_info("mds%d caps went stale, renewing\n",
2328 session->s_mds); 2332 session->s_mds);
2329 spin_lock(&session->s_cap_lock); 2333 spin_lock(&session->s_gen_ttl_lock);
2330 session->s_cap_gen++; 2334 session->s_cap_gen++;
2331 session->s_cap_ttl = 0; 2335 session->s_cap_ttl = 0;
2332 spin_unlock(&session->s_cap_lock); 2336 spin_unlock(&session->s_gen_ttl_lock);
2333 send_renew_caps(mdsc, session); 2337 send_renew_caps(mdsc, session);
2334 break; 2338 break;
2335 2339
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index a50ca0e39475..8c7c04ebb595 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -117,10 +117,13 @@ struct ceph_mds_session {
117 void *s_authorizer_buf, *s_authorizer_reply_buf; 117 void *s_authorizer_buf, *s_authorizer_reply_buf;
118 size_t s_authorizer_buf_len, s_authorizer_reply_buf_len; 118 size_t s_authorizer_buf_len, s_authorizer_reply_buf_len;
119 119
120 /* protected by s_cap_lock */ 120 /* protected by s_gen_ttl_lock */
121 spinlock_t s_cap_lock; 121 spinlock_t s_gen_ttl_lock;
122 u32 s_cap_gen; /* inc each time we get mds stale msg */ 122 u32 s_cap_gen; /* inc each time we get mds stale msg */
123 unsigned long s_cap_ttl; /* when session caps expire */ 123 unsigned long s_cap_ttl; /* when session caps expire */
124
125 /* protected by s_cap_lock */
126 spinlock_t s_cap_lock;
124 struct list_head s_caps; /* all caps issued by this session */ 127 struct list_head s_caps; /* all caps issued by this session */
125 int s_nr_caps, s_trim_caps; 128 int s_nr_caps, s_trim_caps;
126 int s_num_cap_releases; 129 int s_num_cap_releases;
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 857214ae8c08..a76f697303d9 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -111,8 +111,10 @@ static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
111} 111}
112 112
113static struct ceph_vxattr_cb ceph_file_vxattrs[] = { 113static struct ceph_vxattr_cb ceph_file_vxattrs[] = {
114 { true, "ceph.file.layout", ceph_vxattrcb_layout},
115 /* The following extended attribute name is deprecated */
114 { true, "ceph.layout", ceph_vxattrcb_layout}, 116 { true, "ceph.layout", ceph_vxattrcb_layout},
115 { NULL, NULL } 117 { true, NULL, NULL }
116}; 118};
117 119
118static struct ceph_vxattr_cb *ceph_inode_vxattrs(struct inode *inode) 120static struct ceph_vxattr_cb *ceph_inode_vxattrs(struct inode *inode)
diff --git a/fs/lockd/clnt4xdr.c b/fs/lockd/clnt4xdr.c
index f848b52c67b1..3ddcbb1c0a43 100644
--- a/fs/lockd/clnt4xdr.c
+++ b/fs/lockd/clnt4xdr.c
@@ -598,7 +598,7 @@ static struct rpc_procinfo nlm4_procedures[] = {
598 PROC(GRANTED_RES, res, norep), 598 PROC(GRANTED_RES, res, norep),
599}; 599};
600 600
601struct rpc_version nlm_version4 = { 601const struct rpc_version nlm_version4 = {
602 .number = 4, 602 .number = 4,
603 .nrprocs = ARRAY_SIZE(nlm4_procedures), 603 .nrprocs = ARRAY_SIZE(nlm4_procedures),
604 .procs = nlm4_procedures, 604 .procs = nlm4_procedures,
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
index 8d4ea8351e3d..ba1dc2eebd1e 100644
--- a/fs/lockd/clntlock.c
+++ b/fs/lockd/clntlock.c
@@ -62,7 +62,8 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
62 62
63 host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen, 63 host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen,
64 nlm_init->protocol, nlm_version, 64 nlm_init->protocol, nlm_version,
65 nlm_init->hostname, nlm_init->noresvport); 65 nlm_init->hostname, nlm_init->noresvport,
66 nlm_init->net);
66 if (host == NULL) { 67 if (host == NULL) {
67 lockd_down(); 68 lockd_down();
68 return ERR_PTR(-ENOLCK); 69 return ERR_PTR(-ENOLCK);
diff --git a/fs/lockd/clntxdr.c b/fs/lockd/clntxdr.c
index 180ac34feb9a..3d35e3e80c1c 100644
--- a/fs/lockd/clntxdr.c
+++ b/fs/lockd/clntxdr.c
@@ -596,19 +596,19 @@ static struct rpc_procinfo nlm_procedures[] = {
596 PROC(GRANTED_RES, res, norep), 596 PROC(GRANTED_RES, res, norep),
597}; 597};
598 598
599static struct rpc_version nlm_version1 = { 599static const struct rpc_version nlm_version1 = {
600 .number = 1, 600 .number = 1,
601 .nrprocs = ARRAY_SIZE(nlm_procedures), 601 .nrprocs = ARRAY_SIZE(nlm_procedures),
602 .procs = nlm_procedures, 602 .procs = nlm_procedures,
603}; 603};
604 604
605static struct rpc_version nlm_version3 = { 605static const struct rpc_version nlm_version3 = {
606 .number = 3, 606 .number = 3,
607 .nrprocs = ARRAY_SIZE(nlm_procedures), 607 .nrprocs = ARRAY_SIZE(nlm_procedures),
608 .procs = nlm_procedures, 608 .procs = nlm_procedures,
609}; 609};
610 610
611static struct rpc_version *nlm_versions[] = { 611static const struct rpc_version *nlm_versions[] = {
612 [1] = &nlm_version1, 612 [1] = &nlm_version1,
613 [3] = &nlm_version3, 613 [3] = &nlm_version3,
614#ifdef CONFIG_LOCKD_V4 614#ifdef CONFIG_LOCKD_V4
@@ -618,7 +618,7 @@ static struct rpc_version *nlm_versions[] = {
618 618
619static struct rpc_stat nlm_rpc_stats; 619static struct rpc_stat nlm_rpc_stats;
620 620
621struct rpc_program nlm_program = { 621const struct rpc_program nlm_program = {
622 .name = "lockd", 622 .name = "lockd",
623 .number = NLM_PROGRAM, 623 .number = NLM_PROGRAM,
624 .nrvers = ARRAY_SIZE(nlm_versions), 624 .nrvers = ARRAY_SIZE(nlm_versions),
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 6f29836ec0cb..eb75ca7c2d6e 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -17,6 +17,8 @@
17#include <linux/lockd/lockd.h> 17#include <linux/lockd/lockd.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19 19
20#include <linux/sunrpc/svc_xprt.h>
21
20#include <net/ipv6.h> 22#include <net/ipv6.h>
21 23
22#define NLMDBG_FACILITY NLMDBG_HOSTCACHE 24#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
@@ -54,6 +56,7 @@ struct nlm_lookup_host_info {
54 const char *hostname; /* remote's hostname */ 56 const char *hostname; /* remote's hostname */
55 const size_t hostname_len; /* it's length */ 57 const size_t hostname_len; /* it's length */
56 const int noresvport; /* use non-priv port */ 58 const int noresvport; /* use non-priv port */
59 struct net *net; /* network namespace to bind */
57}; 60};
58 61
59/* 62/*
@@ -155,6 +158,7 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
155 INIT_LIST_HEAD(&host->h_reclaim); 158 INIT_LIST_HEAD(&host->h_reclaim);
156 host->h_nsmhandle = nsm; 159 host->h_nsmhandle = nsm;
157 host->h_addrbuf = nsm->sm_addrbuf; 160 host->h_addrbuf = nsm->sm_addrbuf;
161 host->net = ni->net;
158 162
159out: 163out:
160 return host; 164 return host;
@@ -206,7 +210,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
206 const unsigned short protocol, 210 const unsigned short protocol,
207 const u32 version, 211 const u32 version,
208 const char *hostname, 212 const char *hostname,
209 int noresvport) 213 int noresvport,
214 struct net *net)
210{ 215{
211 struct nlm_lookup_host_info ni = { 216 struct nlm_lookup_host_info ni = {
212 .server = 0, 217 .server = 0,
@@ -217,6 +222,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
217 .hostname = hostname, 222 .hostname = hostname,
218 .hostname_len = strlen(hostname), 223 .hostname_len = strlen(hostname),
219 .noresvport = noresvport, 224 .noresvport = noresvport,
225 .net = net,
220 }; 226 };
221 struct hlist_head *chain; 227 struct hlist_head *chain;
222 struct hlist_node *pos; 228 struct hlist_node *pos;
@@ -231,6 +237,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
231 237
232 chain = &nlm_client_hosts[nlm_hash_address(sap)]; 238 chain = &nlm_client_hosts[nlm_hash_address(sap)];
233 hlist_for_each_entry(host, pos, chain, h_hash) { 239 hlist_for_each_entry(host, pos, chain, h_hash) {
240 if (host->net != net)
241 continue;
234 if (!rpc_cmp_addr(nlm_addr(host), sap)) 242 if (!rpc_cmp_addr(nlm_addr(host), sap))
235 continue; 243 continue;
236 244
@@ -318,6 +326,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
318 struct nsm_handle *nsm = NULL; 326 struct nsm_handle *nsm = NULL;
319 struct sockaddr *src_sap = svc_daddr(rqstp); 327 struct sockaddr *src_sap = svc_daddr(rqstp);
320 size_t src_len = rqstp->rq_daddrlen; 328 size_t src_len = rqstp->rq_daddrlen;
329 struct net *net = rqstp->rq_xprt->xpt_net;
321 struct nlm_lookup_host_info ni = { 330 struct nlm_lookup_host_info ni = {
322 .server = 1, 331 .server = 1,
323 .sap = svc_addr(rqstp), 332 .sap = svc_addr(rqstp),
@@ -326,6 +335,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
326 .version = rqstp->rq_vers, 335 .version = rqstp->rq_vers,
327 .hostname = hostname, 336 .hostname = hostname,
328 .hostname_len = hostname_len, 337 .hostname_len = hostname_len,
338 .net = net,
329 }; 339 };
330 340
331 dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__, 341 dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
@@ -339,6 +349,8 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
339 349
340 chain = &nlm_server_hosts[nlm_hash_address(ni.sap)]; 350 chain = &nlm_server_hosts[nlm_hash_address(ni.sap)];
341 hlist_for_each_entry(host, pos, chain, h_hash) { 351 hlist_for_each_entry(host, pos, chain, h_hash) {
352 if (host->net != net)
353 continue;
342 if (!rpc_cmp_addr(nlm_addr(host), ni.sap)) 354 if (!rpc_cmp_addr(nlm_addr(host), ni.sap))
343 continue; 355 continue;
344 356
@@ -431,7 +443,7 @@ nlm_bind_host(struct nlm_host *host)
431 .to_retries = 5U, 443 .to_retries = 5U,
432 }; 444 };
433 struct rpc_create_args args = { 445 struct rpc_create_args args = {
434 .net = &init_net, 446 .net = host->net,
435 .protocol = host->h_proto, 447 .protocol = host->h_proto,
436 .address = nlm_addr(host), 448 .address = nlm_addr(host),
437 .addrsize = host->h_addrlen, 449 .addrsize = host->h_addrlen,
@@ -553,12 +565,8 @@ void nlm_host_rebooted(const struct nlm_reboot *info)
553 nsm_release(nsm); 565 nsm_release(nsm);
554} 566}
555 567
556/*
557 * Shut down the hosts module.
558 * Note that this routine is called only at server shutdown time.
559 */
560void 568void
561nlm_shutdown_hosts(void) 569nlm_shutdown_hosts_net(struct net *net)
562{ 570{
563 struct hlist_head *chain; 571 struct hlist_head *chain;
564 struct hlist_node *pos; 572 struct hlist_node *pos;
@@ -570,6 +578,8 @@ nlm_shutdown_hosts(void)
570 /* First, make all hosts eligible for gc */ 578 /* First, make all hosts eligible for gc */
571 dprintk("lockd: nuking all hosts...\n"); 579 dprintk("lockd: nuking all hosts...\n");
572 for_each_host(host, pos, chain, nlm_server_hosts) { 580 for_each_host(host, pos, chain, nlm_server_hosts) {
581 if (net && host->net != net)
582 continue;
573 host->h_expires = jiffies - 1; 583 host->h_expires = jiffies - 1;
574 if (host->h_rpcclnt) { 584 if (host->h_rpcclnt) {
575 rpc_shutdown_client(host->h_rpcclnt); 585 rpc_shutdown_client(host->h_rpcclnt);
@@ -580,15 +590,29 @@ nlm_shutdown_hosts(void)
580 /* Then, perform a garbage collection pass */ 590 /* Then, perform a garbage collection pass */
581 nlm_gc_hosts(); 591 nlm_gc_hosts();
582 mutex_unlock(&nlm_host_mutex); 592 mutex_unlock(&nlm_host_mutex);
593}
594
595/*
596 * Shut down the hosts module.
597 * Note that this routine is called only at server shutdown time.
598 */
599void
600nlm_shutdown_hosts(void)
601{
602 struct hlist_head *chain;
603 struct hlist_node *pos;
604 struct nlm_host *host;
605
606 nlm_shutdown_hosts_net(NULL);
583 607
584 /* complain if any hosts are left */ 608 /* complain if any hosts are left */
585 if (nrhosts != 0) { 609 if (nrhosts != 0) {
586 printk(KERN_WARNING "lockd: couldn't shutdown host module!\n"); 610 printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
587 dprintk("lockd: %lu hosts left:\n", nrhosts); 611 dprintk("lockd: %lu hosts left:\n", nrhosts);
588 for_each_host(host, pos, chain, nlm_server_hosts) { 612 for_each_host(host, pos, chain, nlm_server_hosts) {
589 dprintk(" %s (cnt %d use %d exp %ld)\n", 613 dprintk(" %s (cnt %d use %d exp %ld net %p)\n",
590 host->h_name, atomic_read(&host->h_count), 614 host->h_name, atomic_read(&host->h_count),
591 host->h_inuse, host->h_expires); 615 host->h_inuse, host->h_expires, host->net);
592 } 616 }
593 } 617 }
594} 618}
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index 65ba36b80a9e..7ef14b3c5bee 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -47,7 +47,7 @@ struct nsm_res {
47 u32 state; 47 u32 state;
48}; 48};
49 49
50static struct rpc_program nsm_program; 50static const struct rpc_program nsm_program;
51static LIST_HEAD(nsm_handles); 51static LIST_HEAD(nsm_handles);
52static DEFINE_SPINLOCK(nsm_lock); 52static DEFINE_SPINLOCK(nsm_lock);
53 53
@@ -62,14 +62,14 @@ static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm)
62 return (struct sockaddr *)&nsm->sm_addr; 62 return (struct sockaddr *)&nsm->sm_addr;
63} 63}
64 64
65static struct rpc_clnt *nsm_create(void) 65static struct rpc_clnt *nsm_create(struct net *net)
66{ 66{
67 struct sockaddr_in sin = { 67 struct sockaddr_in sin = {
68 .sin_family = AF_INET, 68 .sin_family = AF_INET,
69 .sin_addr.s_addr = htonl(INADDR_LOOPBACK), 69 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
70 }; 70 };
71 struct rpc_create_args args = { 71 struct rpc_create_args args = {
72 .net = &init_net, 72 .net = net,
73 .protocol = XPRT_TRANSPORT_UDP, 73 .protocol = XPRT_TRANSPORT_UDP,
74 .address = (struct sockaddr *)&sin, 74 .address = (struct sockaddr *)&sin,
75 .addrsize = sizeof(sin), 75 .addrsize = sizeof(sin),
@@ -83,7 +83,8 @@ static struct rpc_clnt *nsm_create(void)
83 return rpc_create(&args); 83 return rpc_create(&args);
84} 84}
85 85
86static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res) 86static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res,
87 struct net *net)
87{ 88{
88 struct rpc_clnt *clnt; 89 struct rpc_clnt *clnt;
89 int status; 90 int status;
@@ -99,7 +100,7 @@ static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res)
99 .rpc_resp = res, 100 .rpc_resp = res,
100 }; 101 };
101 102
102 clnt = nsm_create(); 103 clnt = nsm_create(net);
103 if (IS_ERR(clnt)) { 104 if (IS_ERR(clnt)) {
104 status = PTR_ERR(clnt); 105 status = PTR_ERR(clnt);
105 dprintk("lockd: failed to create NSM upcall transport, " 106 dprintk("lockd: failed to create NSM upcall transport, "
@@ -149,7 +150,7 @@ int nsm_monitor(const struct nlm_host *host)
149 */ 150 */
150 nsm->sm_mon_name = nsm_use_hostnames ? nsm->sm_name : nsm->sm_addrbuf; 151 nsm->sm_mon_name = nsm_use_hostnames ? nsm->sm_name : nsm->sm_addrbuf;
151 152
152 status = nsm_mon_unmon(nsm, NSMPROC_MON, &res); 153 status = nsm_mon_unmon(nsm, NSMPROC_MON, &res, host->net);
153 if (unlikely(res.status != 0)) 154 if (unlikely(res.status != 0))
154 status = -EIO; 155 status = -EIO;
155 if (unlikely(status < 0)) { 156 if (unlikely(status < 0)) {
@@ -183,7 +184,7 @@ void nsm_unmonitor(const struct nlm_host *host)
183 && nsm->sm_monitored && !nsm->sm_sticky) { 184 && nsm->sm_monitored && !nsm->sm_sticky) {
184 dprintk("lockd: nsm_unmonitor(%s)\n", nsm->sm_name); 185 dprintk("lockd: nsm_unmonitor(%s)\n", nsm->sm_name);
185 186
186 status = nsm_mon_unmon(nsm, NSMPROC_UNMON, &res); 187 status = nsm_mon_unmon(nsm, NSMPROC_UNMON, &res, host->net);
187 if (res.status != 0) 188 if (res.status != 0)
188 status = -EIO; 189 status = -EIO;
189 if (status < 0) 190 if (status < 0)
@@ -534,19 +535,19 @@ static struct rpc_procinfo nsm_procedures[] = {
534 }, 535 },
535}; 536};
536 537
537static struct rpc_version nsm_version1 = { 538static const struct rpc_version nsm_version1 = {
538 .number = 1, 539 .number = 1,
539 .nrprocs = ARRAY_SIZE(nsm_procedures), 540 .nrprocs = ARRAY_SIZE(nsm_procedures),
540 .procs = nsm_procedures 541 .procs = nsm_procedures
541}; 542};
542 543
543static struct rpc_version * nsm_version[] = { 544static const struct rpc_version *nsm_version[] = {
544 [1] = &nsm_version1, 545 [1] = &nsm_version1,
545}; 546};
546 547
547static struct rpc_stat nsm_stats; 548static struct rpc_stat nsm_stats;
548 549
549static struct rpc_program nsm_program = { 550static const struct rpc_program nsm_program = {
550 .name = "statd", 551 .name = "statd",
551 .number = NSM_PROGRAM, 552 .number = NSM_PROGRAM,
552 .nrvers = ARRAY_SIZE(nsm_version), 553 .nrvers = ARRAY_SIZE(nsm_version),
diff --git a/fs/lockd/netns.h b/fs/lockd/netns.h
new file mode 100644
index 000000000000..ce227e0fbc5c
--- /dev/null
+++ b/fs/lockd/netns.h
@@ -0,0 +1,12 @@
1#ifndef __LOCKD_NETNS_H__
2#define __LOCKD_NETNS_H__
3
4#include <net/netns/generic.h>
5
6struct lockd_net {
7 unsigned int nlmsvc_users;
8};
9
10extern int lockd_net_id;
11
12#endif
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index 2444780f5cfa..f49b9afc4436 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -35,6 +35,8 @@
35#include <linux/lockd/lockd.h> 35#include <linux/lockd/lockd.h>
36#include <linux/nfs.h> 36#include <linux/nfs.h>
37 37
38#include "netns.h"
39
38#define NLMDBG_FACILITY NLMDBG_SVC 40#define NLMDBG_FACILITY NLMDBG_SVC
39#define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE) 41#define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE)
40#define ALLOWED_SIGS (sigmask(SIGKILL)) 42#define ALLOWED_SIGS (sigmask(SIGKILL))
@@ -50,6 +52,8 @@ static struct task_struct *nlmsvc_task;
50static struct svc_rqst *nlmsvc_rqst; 52static struct svc_rqst *nlmsvc_rqst;
51unsigned long nlmsvc_timeout; 53unsigned long nlmsvc_timeout;
52 54
55int lockd_net_id;
56
53/* 57/*
54 * These can be set at insmod time (useful for NFS as root filesystem), 58 * These can be set at insmod time (useful for NFS as root filesystem),
55 * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003 59 * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003
@@ -189,27 +193,29 @@ lockd(void *vrqstp)
189} 193}
190 194
191static int create_lockd_listener(struct svc_serv *serv, const char *name, 195static int create_lockd_listener(struct svc_serv *serv, const char *name,
192 const int family, const unsigned short port) 196 struct net *net, const int family,
197 const unsigned short port)
193{ 198{
194 struct svc_xprt *xprt; 199 struct svc_xprt *xprt;
195 200
196 xprt = svc_find_xprt(serv, name, family, 0); 201 xprt = svc_find_xprt(serv, name, net, family, 0);
197 if (xprt == NULL) 202 if (xprt == NULL)
198 return svc_create_xprt(serv, name, &init_net, family, port, 203 return svc_create_xprt(serv, name, net, family, port,
199 SVC_SOCK_DEFAULTS); 204 SVC_SOCK_DEFAULTS);
200 svc_xprt_put(xprt); 205 svc_xprt_put(xprt);
201 return 0; 206 return 0;
202} 207}
203 208
204static int create_lockd_family(struct svc_serv *serv, const int family) 209static int create_lockd_family(struct svc_serv *serv, struct net *net,
210 const int family)
205{ 211{
206 int err; 212 int err;
207 213
208 err = create_lockd_listener(serv, "udp", family, nlm_udpport); 214 err = create_lockd_listener(serv, "udp", net, family, nlm_udpport);
209 if (err < 0) 215 if (err < 0)
210 return err; 216 return err;
211 217
212 return create_lockd_listener(serv, "tcp", family, nlm_tcpport); 218 return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport);
213} 219}
214 220
215/* 221/*
@@ -222,16 +228,16 @@ static int create_lockd_family(struct svc_serv *serv, const int family)
222 * Returns zero if all listeners are available; otherwise a 228 * Returns zero if all listeners are available; otherwise a
223 * negative errno value is returned. 229 * negative errno value is returned.
224 */ 230 */
225static int make_socks(struct svc_serv *serv) 231static int make_socks(struct svc_serv *serv, struct net *net)
226{ 232{
227 static int warned; 233 static int warned;
228 int err; 234 int err;
229 235
230 err = create_lockd_family(serv, PF_INET); 236 err = create_lockd_family(serv, net, PF_INET);
231 if (err < 0) 237 if (err < 0)
232 goto out_err; 238 goto out_err;
233 239
234 err = create_lockd_family(serv, PF_INET6); 240 err = create_lockd_family(serv, net, PF_INET6);
235 if (err < 0 && err != -EAFNOSUPPORT) 241 if (err < 0 && err != -EAFNOSUPPORT)
236 goto out_err; 242 goto out_err;
237 243
@@ -245,6 +251,47 @@ out_err:
245 return err; 251 return err;
246} 252}
247 253
254static int lockd_up_net(struct net *net)
255{
256 struct lockd_net *ln = net_generic(net, lockd_net_id);
257 struct svc_serv *serv = nlmsvc_rqst->rq_server;
258 int error;
259
260 if (ln->nlmsvc_users)
261 return 0;
262
263 error = svc_rpcb_setup(serv, net);
264 if (error)
265 goto err_rpcb;
266
267 error = make_socks(serv, net);
268 if (error < 0)
269 goto err_socks;
270 return 0;
271
272err_socks:
273 svc_rpcb_cleanup(serv, net);
274err_rpcb:
275 return error;
276}
277
278static void lockd_down_net(struct net *net)
279{
280 struct lockd_net *ln = net_generic(net, lockd_net_id);
281 struct svc_serv *serv = nlmsvc_rqst->rq_server;
282
283 if (ln->nlmsvc_users) {
284 if (--ln->nlmsvc_users == 0) {
285 nlm_shutdown_hosts_net(net);
286 svc_shutdown_net(serv, net);
287 }
288 } else {
289 printk(KERN_ERR "lockd_down_net: no users! task=%p, net=%p\n",
290 nlmsvc_task, net);
291 BUG();
292 }
293}
294
248/* 295/*
249 * Bring up the lockd process if it's not already up. 296 * Bring up the lockd process if it's not already up.
250 */ 297 */
@@ -252,13 +299,16 @@ int lockd_up(void)
252{ 299{
253 struct svc_serv *serv; 300 struct svc_serv *serv;
254 int error = 0; 301 int error = 0;
302 struct net *net = current->nsproxy->net_ns;
255 303
256 mutex_lock(&nlmsvc_mutex); 304 mutex_lock(&nlmsvc_mutex);
257 /* 305 /*
258 * Check whether we're already up and running. 306 * Check whether we're already up and running.
259 */ 307 */
260 if (nlmsvc_rqst) 308 if (nlmsvc_rqst) {
309 error = lockd_up_net(net);
261 goto out; 310 goto out;
311 }
262 312
263 /* 313 /*
264 * Sanity check: if there's no pid, 314 * Sanity check: if there's no pid,
@@ -275,7 +325,7 @@ int lockd_up(void)
275 goto out; 325 goto out;
276 } 326 }
277 327
278 error = make_socks(serv); 328 error = make_socks(serv, net);
279 if (error < 0) 329 if (error < 0)
280 goto destroy_and_out; 330 goto destroy_and_out;
281 331
@@ -313,8 +363,12 @@ int lockd_up(void)
313destroy_and_out: 363destroy_and_out:
314 svc_destroy(serv); 364 svc_destroy(serv);
315out: 365out:
316 if (!error) 366 if (!error) {
367 struct lockd_net *ln = net_generic(net, lockd_net_id);
368
369 ln->nlmsvc_users++;
317 nlmsvc_users++; 370 nlmsvc_users++;
371 }
318 mutex_unlock(&nlmsvc_mutex); 372 mutex_unlock(&nlmsvc_mutex);
319 return error; 373 return error;
320} 374}
@@ -328,8 +382,10 @@ lockd_down(void)
328{ 382{
329 mutex_lock(&nlmsvc_mutex); 383 mutex_lock(&nlmsvc_mutex);
330 if (nlmsvc_users) { 384 if (nlmsvc_users) {
331 if (--nlmsvc_users) 385 if (--nlmsvc_users) {
386 lockd_down_net(current->nsproxy->net_ns);
332 goto out; 387 goto out;
388 }
333 } else { 389 } else {
334 printk(KERN_ERR "lockd_down: no users! task=%p\n", 390 printk(KERN_ERR "lockd_down: no users! task=%p\n",
335 nlmsvc_task); 391 nlmsvc_task);
@@ -497,24 +553,55 @@ module_param_call(nlm_tcpport, param_set_port, param_get_int,
497module_param(nsm_use_hostnames, bool, 0644); 553module_param(nsm_use_hostnames, bool, 0644);
498module_param(nlm_max_connections, uint, 0644); 554module_param(nlm_max_connections, uint, 0644);
499 555
556static int lockd_init_net(struct net *net)
557{
558 return 0;
559}
560
561static void lockd_exit_net(struct net *net)
562{
563}
564
565static struct pernet_operations lockd_net_ops = {
566 .init = lockd_init_net,
567 .exit = lockd_exit_net,
568 .id = &lockd_net_id,
569 .size = sizeof(struct lockd_net),
570};
571
572
500/* 573/*
501 * Initialising and terminating the module. 574 * Initialising and terminating the module.
502 */ 575 */
503 576
504static int __init init_nlm(void) 577static int __init init_nlm(void)
505{ 578{
579 int err;
580
506#ifdef CONFIG_SYSCTL 581#ifdef CONFIG_SYSCTL
582 err = -ENOMEM;
507 nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root); 583 nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root);
508 return nlm_sysctl_table ? 0 : -ENOMEM; 584 if (nlm_sysctl_table == NULL)
509#else 585 goto err_sysctl;
586#endif
587 err = register_pernet_subsys(&lockd_net_ops);
588 if (err)
589 goto err_pernet;
510 return 0; 590 return 0;
591
592err_pernet:
593#ifdef CONFIG_SYSCTL
594 unregister_sysctl_table(nlm_sysctl_table);
511#endif 595#endif
596err_sysctl:
597 return err;
512} 598}
513 599
514static void __exit exit_nlm(void) 600static void __exit exit_nlm(void)
515{ 601{
516 /* FIXME: delete all NLM clients */ 602 /* FIXME: delete all NLM clients */
517 nlm_shutdown_hosts(); 603 nlm_shutdown_hosts();
604 unregister_pernet_subsys(&lockd_net_ops);
518#ifdef CONFIG_SYSCTL 605#ifdef CONFIG_SYSCTL
519 unregister_sysctl_table(nlm_sysctl_table); 606 unregister_sysctl_table(nlm_sysctl_table);
520#endif 607#endif
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index f0179c3745d2..e46353f41a42 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -46,7 +46,6 @@ static void nlmsvc_remove_block(struct nlm_block *block);
46static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock); 46static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock);
47static void nlmsvc_freegrantargs(struct nlm_rqst *call); 47static void nlmsvc_freegrantargs(struct nlm_rqst *call);
48static const struct rpc_call_ops nlmsvc_grant_ops; 48static const struct rpc_call_ops nlmsvc_grant_ops;
49static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie);
50 49
51/* 50/*
52 * The list of blocked locks to retry 51 * The list of blocked locks to retry
@@ -54,6 +53,35 @@ static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie);
54static LIST_HEAD(nlm_blocked); 53static LIST_HEAD(nlm_blocked);
55static DEFINE_SPINLOCK(nlm_blocked_lock); 54static DEFINE_SPINLOCK(nlm_blocked_lock);
56 55
56#ifdef LOCKD_DEBUG
57static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
58{
59 /*
60 * We can get away with a static buffer because we're only
61 * called with BKL held.
62 */
63 static char buf[2*NLM_MAXCOOKIELEN+1];
64 unsigned int i, len = sizeof(buf);
65 char *p = buf;
66
67 len--; /* allow for trailing \0 */
68 if (len < 3)
69 return "???";
70 for (i = 0 ; i < cookie->len ; i++) {
71 if (len < 2) {
72 strcpy(p-3, "...");
73 break;
74 }
75 sprintf(p, "%02x", cookie->data[i]);
76 p += 2;
77 len -= 2;
78 }
79 *p = '\0';
80
81 return buf;
82}
83#endif
84
57/* 85/*
58 * Insert a blocked lock into the global list 86 * Insert a blocked lock into the global list
59 */ 87 */
@@ -935,32 +963,3 @@ nlmsvc_retry_blocked(void)
935 963
936 return timeout; 964 return timeout;
937} 965}
938
939#ifdef RPC_DEBUG
940static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
941{
942 /*
943 * We can get away with a static buffer because we're only
944 * called with BKL held.
945 */
946 static char buf[2*NLM_MAXCOOKIELEN+1];
947 unsigned int i, len = sizeof(buf);
948 char *p = buf;
949
950 len--; /* allow for trailing \0 */
951 if (len < 3)
952 return "???";
953 for (i = 0 ; i < cookie->len ; i++) {
954 if (len < 2) {
955 strcpy(p-3, "...");
956 break;
957 }
958 sprintf(p, "%02x", cookie->data[i]);
959 p += 2;
960 len -= 2;
961 }
962 *p = '\0';
963
964 return buf;
965}
966#endif
diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c
index e97404d611e0..9c501449450d 100644
--- a/fs/logfs/dev_mtd.c
+++ b/fs/logfs/dev_mtd.c
@@ -152,9 +152,6 @@ static struct page *logfs_mtd_find_first_sb(struct super_block *sb, u64 *ofs)
152 filler_t *filler = logfs_mtd_readpage; 152 filler_t *filler = logfs_mtd_readpage;
153 struct mtd_info *mtd = super->s_mtd; 153 struct mtd_info *mtd = super->s_mtd;
154 154
155 if (!mtd_can_have_bb(mtd))
156 return NULL;
157
158 *ofs = 0; 155 *ofs = 0;
159 while (mtd_block_isbad(mtd, *ofs)) { 156 while (mtd_block_isbad(mtd, *ofs)) {
160 *ofs += mtd->erasesize; 157 *ofs += mtd->erasesize;
@@ -172,9 +169,6 @@ static struct page *logfs_mtd_find_last_sb(struct super_block *sb, u64 *ofs)
172 filler_t *filler = logfs_mtd_readpage; 169 filler_t *filler = logfs_mtd_readpage;
173 struct mtd_info *mtd = super->s_mtd; 170 struct mtd_info *mtd = super->s_mtd;
174 171
175 if (!mtd_can_have_bb(mtd))
176 return NULL;
177
178 *ofs = mtd->size - mtd->erasesize; 172 *ofs = mtd->size - mtd->erasesize;
179 while (mtd_block_isbad(mtd, *ofs)) { 173 while (mtd_block_isbad(mtd, *ofs)) {
180 *ofs -= mtd->erasesize; 174 *ofs -= mtd->erasesize;
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
index dbcd82126aed..2a0e6c599147 100644
--- a/fs/nfs/Kconfig
+++ b/fs/nfs/Kconfig
@@ -64,6 +64,7 @@ config NFS_V4
64 bool "NFS client support for NFS version 4" 64 bool "NFS client support for NFS version 4"
65 depends on NFS_FS 65 depends on NFS_FS
66 select SUNRPC_GSS 66 select SUNRPC_GSS
67 select KEYS
67 help 68 help
68 This option enables support for version 4 of the NFS protocol 69 This option enables support for version 4 of the NFS protocol
69 (RFC 3530) in the kernel's NFS client. 70 (RFC 3530) in the kernel's NFS client.
@@ -98,6 +99,18 @@ config PNFS_OBJLAYOUT
98 depends on NFS_FS && NFS_V4_1 && SCSI_OSD_ULD 99 depends on NFS_FS && NFS_V4_1 && SCSI_OSD_ULD
99 default m 100 default m
100 101
102config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
103 string "NFSv4.1 Implementation ID Domain"
104 depends on NFS_V4_1
105 default "kernel.org"
106 help
107 This option defines the domain portion of the implementation ID that
108 may be sent in the NFS exchange_id operation. The value must be in
109 the format of a DNS domain name and should be set to the DNS domain
110 name of the distribution.
111 If the NFS client is unchanged from the upstream kernel, this
112 option should be set to the default "kernel.org".
113
101config ROOT_NFS 114config ROOT_NFS
102 bool "Root file system on NFS" 115 bool "Root file system on NFS"
103 depends on NFS_FS=y && IP_PNP 116 depends on NFS_FS=y && IP_PNP
@@ -130,16 +143,10 @@ config NFS_USE_KERNEL_DNS
130 bool 143 bool
131 depends on NFS_V4 && !NFS_USE_LEGACY_DNS 144 depends on NFS_V4 && !NFS_USE_LEGACY_DNS
132 select DNS_RESOLVER 145 select DNS_RESOLVER
133 select KEYS
134 default y 146 default y
135 147
136config NFS_USE_NEW_IDMAPPER 148config NFS_DEBUG
137 bool "Use the new idmapper upcall routine" 149 bool
138 depends on NFS_V4 && KEYS 150 depends on NFS_FS && SUNRPC_DEBUG
139 help 151 select CRC32
140 Say Y here if you want NFS to use the new idmapper upcall functions. 152 default y
141 You will need /sbin/request-key (usually provided by the keyutils
142 package). For details, read
143 <file:Documentation/filesystems/nfs/idmapper.txt>.
144
145 If you are unsure, say N.
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 48cfac31f64c..9c94297bb70e 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -46,9 +46,6 @@ MODULE_LICENSE("GPL");
46MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>"); 46MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>");
47MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver"); 47MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver");
48 48
49struct dentry *bl_device_pipe;
50wait_queue_head_t bl_wq;
51
52static void print_page(struct page *page) 49static void print_page(struct page *page)
53{ 50{
54 dprintk("PRINTPAGE page %p\n", page); 51 dprintk("PRINTPAGE page %p\n", page);
@@ -236,12 +233,11 @@ bl_read_pagelist(struct nfs_read_data *rdata)
236 sector_t isect, extent_length = 0; 233 sector_t isect, extent_length = 0;
237 struct parallel_io *par; 234 struct parallel_io *par;
238 loff_t f_offset = rdata->args.offset; 235 loff_t f_offset = rdata->args.offset;
239 size_t count = rdata->args.count;
240 struct page **pages = rdata->args.pages; 236 struct page **pages = rdata->args.pages;
241 int pg_index = rdata->args.pgbase >> PAGE_CACHE_SHIFT; 237 int pg_index = rdata->args.pgbase >> PAGE_CACHE_SHIFT;
242 238
243 dprintk("%s enter nr_pages %u offset %lld count %Zd\n", __func__, 239 dprintk("%s enter nr_pages %u offset %lld count %u\n", __func__,
244 rdata->npages, f_offset, count); 240 rdata->npages, f_offset, (unsigned int)rdata->args.count);
245 241
246 par = alloc_parallel(rdata); 242 par = alloc_parallel(rdata);
247 if (!par) 243 if (!par)
@@ -1025,10 +1021,128 @@ static const struct rpc_pipe_ops bl_upcall_ops = {
1025 .destroy_msg = bl_pipe_destroy_msg, 1021 .destroy_msg = bl_pipe_destroy_msg,
1026}; 1022};
1027 1023
1024static struct dentry *nfs4blocklayout_register_sb(struct super_block *sb,
1025 struct rpc_pipe *pipe)
1026{
1027 struct dentry *dir, *dentry;
1028
1029 dir = rpc_d_lookup_sb(sb, NFS_PIPE_DIRNAME);
1030 if (dir == NULL)
1031 return ERR_PTR(-ENOENT);
1032 dentry = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe);
1033 dput(dir);
1034 return dentry;
1035}
1036
1037static void nfs4blocklayout_unregister_sb(struct super_block *sb,
1038 struct rpc_pipe *pipe)
1039{
1040 if (pipe->dentry)
1041 rpc_unlink(pipe->dentry);
1042}
1043
1044static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
1045 void *ptr)
1046{
1047 struct super_block *sb = ptr;
1048 struct net *net = sb->s_fs_info;
1049 struct nfs_net *nn = net_generic(net, nfs_net_id);
1050 struct dentry *dentry;
1051 int ret = 0;
1052
1053 if (!try_module_get(THIS_MODULE))
1054 return 0;
1055
1056 if (nn->bl_device_pipe == NULL) {
1057 module_put(THIS_MODULE);
1058 return 0;
1059 }
1060
1061 switch (event) {
1062 case RPC_PIPEFS_MOUNT:
1063 dentry = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe);
1064 if (IS_ERR(dentry)) {
1065 ret = PTR_ERR(dentry);
1066 break;
1067 }
1068 nn->bl_device_pipe->dentry = dentry;
1069 break;
1070 case RPC_PIPEFS_UMOUNT:
1071 if (nn->bl_device_pipe->dentry)
1072 nfs4blocklayout_unregister_sb(sb, nn->bl_device_pipe);
1073 break;
1074 default:
1075 ret = -ENOTSUPP;
1076 break;
1077 }
1078 module_put(THIS_MODULE);
1079 return ret;
1080}
1081
1082static struct notifier_block nfs4blocklayout_block = {
1083 .notifier_call = rpc_pipefs_event,
1084};
1085
1086static struct dentry *nfs4blocklayout_register_net(struct net *net,
1087 struct rpc_pipe *pipe)
1088{
1089 struct super_block *pipefs_sb;
1090 struct dentry *dentry;
1091
1092 pipefs_sb = rpc_get_sb_net(net);
1093 if (!pipefs_sb)
1094 return NULL;
1095 dentry = nfs4blocklayout_register_sb(pipefs_sb, pipe);
1096 rpc_put_sb_net(net);
1097 return dentry;
1098}
1099
1100static void nfs4blocklayout_unregister_net(struct net *net,
1101 struct rpc_pipe *pipe)
1102{
1103 struct super_block *pipefs_sb;
1104
1105 pipefs_sb = rpc_get_sb_net(net);
1106 if (pipefs_sb) {
1107 nfs4blocklayout_unregister_sb(pipefs_sb, pipe);
1108 rpc_put_sb_net(net);
1109 }
1110}
1111
1112static int nfs4blocklayout_net_init(struct net *net)
1113{
1114 struct nfs_net *nn = net_generic(net, nfs_net_id);
1115 struct dentry *dentry;
1116
1117 init_waitqueue_head(&nn->bl_wq);
1118 nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0);
1119 if (IS_ERR(nn->bl_device_pipe))
1120 return PTR_ERR(nn->bl_device_pipe);
1121 dentry = nfs4blocklayout_register_net(net, nn->bl_device_pipe);
1122 if (IS_ERR(dentry)) {
1123 rpc_destroy_pipe_data(nn->bl_device_pipe);
1124 return PTR_ERR(dentry);
1125 }
1126 nn->bl_device_pipe->dentry = dentry;
1127 return 0;
1128}
1129
1130static void nfs4blocklayout_net_exit(struct net *net)
1131{
1132 struct nfs_net *nn = net_generic(net, nfs_net_id);
1133
1134 nfs4blocklayout_unregister_net(net, nn->bl_device_pipe);
1135 rpc_destroy_pipe_data(nn->bl_device_pipe);
1136 nn->bl_device_pipe = NULL;
1137}
1138
1139static struct pernet_operations nfs4blocklayout_net_ops = {
1140 .init = nfs4blocklayout_net_init,
1141 .exit = nfs4blocklayout_net_exit,
1142};
1143
1028static int __init nfs4blocklayout_init(void) 1144static int __init nfs4blocklayout_init(void)
1029{ 1145{
1030 struct vfsmount *mnt;
1031 struct path path;
1032 int ret; 1146 int ret;
1033 1147
1034 dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__); 1148 dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__);
@@ -1037,32 +1151,17 @@ static int __init nfs4blocklayout_init(void)
1037 if (ret) 1151 if (ret)
1038 goto out; 1152 goto out;
1039 1153
1040 init_waitqueue_head(&bl_wq); 1154 ret = rpc_pipefs_notifier_register(&nfs4blocklayout_block);
1041 1155 if (ret)
1042 mnt = rpc_get_mount();
1043 if (IS_ERR(mnt)) {
1044 ret = PTR_ERR(mnt);
1045 goto out_remove; 1156 goto out_remove;
1046 } 1157 ret = register_pernet_subsys(&nfs4blocklayout_net_ops);
1047
1048 ret = vfs_path_lookup(mnt->mnt_root,
1049 mnt,
1050 NFS_PIPE_DIRNAME, 0, &path);
1051 if (ret) 1158 if (ret)
1052 goto out_putrpc; 1159 goto out_notifier;
1053
1054 bl_device_pipe = rpc_mkpipe(path.dentry, "blocklayout", NULL,
1055 &bl_upcall_ops, 0);
1056 path_put(&path);
1057 if (IS_ERR(bl_device_pipe)) {
1058 ret = PTR_ERR(bl_device_pipe);
1059 goto out_putrpc;
1060 }
1061out: 1160out:
1062 return ret; 1161 return ret;
1063 1162
1064out_putrpc: 1163out_notifier:
1065 rpc_put_mount(); 1164 rpc_pipefs_notifier_unregister(&nfs4blocklayout_block);
1066out_remove: 1165out_remove:
1067 pnfs_unregister_layoutdriver(&blocklayout_type); 1166 pnfs_unregister_layoutdriver(&blocklayout_type);
1068 return ret; 1167 return ret;
@@ -1073,9 +1172,9 @@ static void __exit nfs4blocklayout_exit(void)
1073 dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n", 1172 dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n",
1074 __func__); 1173 __func__);
1075 1174
1175 rpc_pipefs_notifier_unregister(&nfs4blocklayout_block);
1176 unregister_pernet_subsys(&nfs4blocklayout_net_ops);
1076 pnfs_unregister_layoutdriver(&blocklayout_type); 1177 pnfs_unregister_layoutdriver(&blocklayout_type);
1077 rpc_unlink(bl_device_pipe);
1078 rpc_put_mount();
1079} 1178}
1080 1179
1081MODULE_ALIAS("nfs-layouttype4-3"); 1180MODULE_ALIAS("nfs-layouttype4-3");
diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h
index e31a2df28e70..03350690118e 100644
--- a/fs/nfs/blocklayout/blocklayout.h
+++ b/fs/nfs/blocklayout/blocklayout.h
@@ -37,6 +37,7 @@
37#include <linux/sunrpc/rpc_pipe_fs.h> 37#include <linux/sunrpc/rpc_pipe_fs.h>
38 38
39#include "../pnfs.h" 39#include "../pnfs.h"
40#include "../netns.h"
40 41
41#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT) 42#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
42#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT) 43#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
@@ -50,6 +51,7 @@ struct pnfs_block_dev {
50 struct list_head bm_node; 51 struct list_head bm_node;
51 struct nfs4_deviceid bm_mdevid; /* associated devid */ 52 struct nfs4_deviceid bm_mdevid; /* associated devid */
52 struct block_device *bm_mdev; /* meta device itself */ 53 struct block_device *bm_mdev; /* meta device itself */
54 struct net *net;
53}; 55};
54 56
55enum exstate4 { 57enum exstate4 {
@@ -151,9 +153,9 @@ BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
151 return BLK_LO2EXT(lseg->pls_layout); 153 return BLK_LO2EXT(lseg->pls_layout);
152} 154}
153 155
154struct bl_dev_msg { 156struct bl_pipe_msg {
155 int32_t status; 157 struct rpc_pipe_msg msg;
156 uint32_t major, minor; 158 wait_queue_head_t *bl_wq;
157}; 159};
158 160
159struct bl_msg_hdr { 161struct bl_msg_hdr {
@@ -161,9 +163,6 @@ struct bl_msg_hdr {
161 u16 totallen; /* length of entire message, including hdr itself */ 163 u16 totallen; /* length of entire message, including hdr itself */
162}; 164};
163 165
164extern struct dentry *bl_device_pipe;
165extern wait_queue_head_t bl_wq;
166
167#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */ 166#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
168#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/ 167#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
169#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */ 168#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
diff --git a/fs/nfs/blocklayout/blocklayoutdev.c b/fs/nfs/blocklayout/blocklayoutdev.c
index d08ba9107fde..a5c88a554d92 100644
--- a/fs/nfs/blocklayout/blocklayoutdev.c
+++ b/fs/nfs/blocklayout/blocklayoutdev.c
@@ -46,7 +46,7 @@ static int decode_sector_number(__be32 **rp, sector_t *sp)
46 46
47 *rp = xdr_decode_hyper(*rp, &s); 47 *rp = xdr_decode_hyper(*rp, &s);
48 if (s & 0x1ff) { 48 if (s & 0x1ff) {
49 printk(KERN_WARNING "%s: sector not aligned\n", __func__); 49 printk(KERN_WARNING "NFS: %s: sector not aligned\n", __func__);
50 return -1; 50 return -1;
51 } 51 }
52 *sp = s >> SECTOR_SHIFT; 52 *sp = s >> SECTOR_SHIFT;
@@ -79,27 +79,30 @@ int nfs4_blkdev_put(struct block_device *bdev)
79 return blkdev_put(bdev, FMODE_READ); 79 return blkdev_put(bdev, FMODE_READ);
80} 80}
81 81
82static struct bl_dev_msg bl_mount_reply;
83
84ssize_t bl_pipe_downcall(struct file *filp, const char __user *src, 82ssize_t bl_pipe_downcall(struct file *filp, const char __user *src,
85 size_t mlen) 83 size_t mlen)
86{ 84{
85 struct nfs_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
86 nfs_net_id);
87
87 if (mlen != sizeof (struct bl_dev_msg)) 88 if (mlen != sizeof (struct bl_dev_msg))
88 return -EINVAL; 89 return -EINVAL;
89 90
90 if (copy_from_user(&bl_mount_reply, src, mlen) != 0) 91 if (copy_from_user(&nn->bl_mount_reply, src, mlen) != 0)
91 return -EFAULT; 92 return -EFAULT;
92 93
93 wake_up(&bl_wq); 94 wake_up(&nn->bl_wq);
94 95
95 return mlen; 96 return mlen;
96} 97}
97 98
98void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg) 99void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg)
99{ 100{
101 struct bl_pipe_msg *bl_pipe_msg = container_of(msg, struct bl_pipe_msg, msg);
102
100 if (msg->errno >= 0) 103 if (msg->errno >= 0)
101 return; 104 return;
102 wake_up(&bl_wq); 105 wake_up(bl_pipe_msg->bl_wq);
103} 106}
104 107
105/* 108/*
@@ -111,29 +114,33 @@ nfs4_blk_decode_device(struct nfs_server *server,
111{ 114{
112 struct pnfs_block_dev *rv; 115 struct pnfs_block_dev *rv;
113 struct block_device *bd = NULL; 116 struct block_device *bd = NULL;
114 struct rpc_pipe_msg msg; 117 struct bl_pipe_msg bl_pipe_msg;
118 struct rpc_pipe_msg *msg = &bl_pipe_msg.msg;
115 struct bl_msg_hdr bl_msg = { 119 struct bl_msg_hdr bl_msg = {
116 .type = BL_DEVICE_MOUNT, 120 .type = BL_DEVICE_MOUNT,
117 .totallen = dev->mincount, 121 .totallen = dev->mincount,
118 }; 122 };
119 uint8_t *dataptr; 123 uint8_t *dataptr;
120 DECLARE_WAITQUEUE(wq, current); 124 DECLARE_WAITQUEUE(wq, current);
121 struct bl_dev_msg *reply = &bl_mount_reply;
122 int offset, len, i, rc; 125 int offset, len, i, rc;
126 struct net *net = server->nfs_client->net;
127 struct nfs_net *nn = net_generic(net, nfs_net_id);
128 struct bl_dev_msg *reply = &nn->bl_mount_reply;
123 129
124 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__); 130 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
125 dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data, 131 dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data,
126 dev->mincount); 132 dev->mincount);
127 133
128 memset(&msg, 0, sizeof(msg)); 134 bl_pipe_msg.bl_wq = &nn->bl_wq;
129 msg.data = kzalloc(sizeof(bl_msg) + dev->mincount, GFP_NOFS); 135 memset(msg, 0, sizeof(*msg));
130 if (!msg.data) { 136 msg->data = kzalloc(sizeof(bl_msg) + dev->mincount, GFP_NOFS);
137 if (!msg->data) {
131 rv = ERR_PTR(-ENOMEM); 138 rv = ERR_PTR(-ENOMEM);
132 goto out; 139 goto out;
133 } 140 }
134 141
135 memcpy(msg.data, &bl_msg, sizeof(bl_msg)); 142 memcpy(msg->data, &bl_msg, sizeof(bl_msg));
136 dataptr = (uint8_t *) msg.data; 143 dataptr = (uint8_t *) msg->data;
137 len = dev->mincount; 144 len = dev->mincount;
138 offset = sizeof(bl_msg); 145 offset = sizeof(bl_msg);
139 for (i = 0; len > 0; i++) { 146 for (i = 0; len > 0; i++) {
@@ -142,13 +149,13 @@ nfs4_blk_decode_device(struct nfs_server *server,
142 len -= PAGE_CACHE_SIZE; 149 len -= PAGE_CACHE_SIZE;
143 offset += PAGE_CACHE_SIZE; 150 offset += PAGE_CACHE_SIZE;
144 } 151 }
145 msg.len = sizeof(bl_msg) + dev->mincount; 152 msg->len = sizeof(bl_msg) + dev->mincount;
146 153
147 dprintk("%s CALLING USERSPACE DAEMON\n", __func__); 154 dprintk("%s CALLING USERSPACE DAEMON\n", __func__);
148 add_wait_queue(&bl_wq, &wq); 155 add_wait_queue(&nn->bl_wq, &wq);
149 rc = rpc_queue_upcall(bl_device_pipe->d_inode, &msg); 156 rc = rpc_queue_upcall(nn->bl_device_pipe, msg);
150 if (rc < 0) { 157 if (rc < 0) {
151 remove_wait_queue(&bl_wq, &wq); 158 remove_wait_queue(&nn->bl_wq, &wq);
152 rv = ERR_PTR(rc); 159 rv = ERR_PTR(rc);
153 goto out; 160 goto out;
154 } 161 }
@@ -156,7 +163,7 @@ nfs4_blk_decode_device(struct nfs_server *server,
156 set_current_state(TASK_UNINTERRUPTIBLE); 163 set_current_state(TASK_UNINTERRUPTIBLE);
157 schedule(); 164 schedule();
158 __set_current_state(TASK_RUNNING); 165 __set_current_state(TASK_RUNNING);
159 remove_wait_queue(&bl_wq, &wq); 166 remove_wait_queue(&nn->bl_wq, &wq);
160 167
161 if (reply->status != BL_DEVICE_REQUEST_PROC) { 168 if (reply->status != BL_DEVICE_REQUEST_PROC) {
162 dprintk("%s failed to open device: %d\n", 169 dprintk("%s failed to open device: %d\n",
@@ -181,13 +188,14 @@ nfs4_blk_decode_device(struct nfs_server *server,
181 188
182 rv->bm_mdev = bd; 189 rv->bm_mdev = bd;
183 memcpy(&rv->bm_mdevid, &dev->dev_id, sizeof(struct nfs4_deviceid)); 190 memcpy(&rv->bm_mdevid, &dev->dev_id, sizeof(struct nfs4_deviceid));
191 rv->net = net;
184 dprintk("%s Created device %s with bd_block_size %u\n", 192 dprintk("%s Created device %s with bd_block_size %u\n",
185 __func__, 193 __func__,
186 bd->bd_disk->disk_name, 194 bd->bd_disk->disk_name,
187 bd->bd_block_size); 195 bd->bd_block_size);
188 196
189out: 197out:
190 kfree(msg.data); 198 kfree(msg->data);
191 return rv; 199 return rv;
192} 200}
193 201
diff --git a/fs/nfs/blocklayout/blocklayoutdm.c b/fs/nfs/blocklayout/blocklayoutdm.c
index d055c7558073..737d839bc17b 100644
--- a/fs/nfs/blocklayout/blocklayoutdm.c
+++ b/fs/nfs/blocklayout/blocklayoutdm.c
@@ -38,9 +38,10 @@
38 38
39#define NFSDBG_FACILITY NFSDBG_PNFS_LD 39#define NFSDBG_FACILITY NFSDBG_PNFS_LD
40 40
41static void dev_remove(dev_t dev) 41static void dev_remove(struct net *net, dev_t dev)
42{ 42{
43 struct rpc_pipe_msg msg; 43 struct bl_pipe_msg bl_pipe_msg;
44 struct rpc_pipe_msg *msg = &bl_pipe_msg.msg;
44 struct bl_dev_msg bl_umount_request; 45 struct bl_dev_msg bl_umount_request;
45 struct bl_msg_hdr bl_msg = { 46 struct bl_msg_hdr bl_msg = {
46 .type = BL_DEVICE_UMOUNT, 47 .type = BL_DEVICE_UMOUNT,
@@ -48,36 +49,38 @@ static void dev_remove(dev_t dev)
48 }; 49 };
49 uint8_t *dataptr; 50 uint8_t *dataptr;
50 DECLARE_WAITQUEUE(wq, current); 51 DECLARE_WAITQUEUE(wq, current);
52 struct nfs_net *nn = net_generic(net, nfs_net_id);
51 53
52 dprintk("Entering %s\n", __func__); 54 dprintk("Entering %s\n", __func__);
53 55
54 memset(&msg, 0, sizeof(msg)); 56 bl_pipe_msg.bl_wq = &nn->bl_wq;
55 msg.data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS); 57 memset(msg, 0, sizeof(*msg));
56 if (!msg.data) 58 msg->data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS);
59 if (!msg->data)
57 goto out; 60 goto out;
58 61
59 memset(&bl_umount_request, 0, sizeof(bl_umount_request)); 62 memset(&bl_umount_request, 0, sizeof(bl_umount_request));
60 bl_umount_request.major = MAJOR(dev); 63 bl_umount_request.major = MAJOR(dev);
61 bl_umount_request.minor = MINOR(dev); 64 bl_umount_request.minor = MINOR(dev);
62 65
63 memcpy(msg.data, &bl_msg, sizeof(bl_msg)); 66 memcpy(msg->data, &bl_msg, sizeof(bl_msg));
64 dataptr = (uint8_t *) msg.data; 67 dataptr = (uint8_t *) msg->data;
65 memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request)); 68 memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request));
66 msg.len = sizeof(bl_msg) + bl_msg.totallen; 69 msg->len = sizeof(bl_msg) + bl_msg.totallen;
67 70
68 add_wait_queue(&bl_wq, &wq); 71 add_wait_queue(&nn->bl_wq, &wq);
69 if (rpc_queue_upcall(bl_device_pipe->d_inode, &msg) < 0) { 72 if (rpc_queue_upcall(nn->bl_device_pipe, msg) < 0) {
70 remove_wait_queue(&bl_wq, &wq); 73 remove_wait_queue(&nn->bl_wq, &wq);
71 goto out; 74 goto out;
72 } 75 }
73 76
74 set_current_state(TASK_UNINTERRUPTIBLE); 77 set_current_state(TASK_UNINTERRUPTIBLE);
75 schedule(); 78 schedule();
76 __set_current_state(TASK_RUNNING); 79 __set_current_state(TASK_RUNNING);
77 remove_wait_queue(&bl_wq, &wq); 80 remove_wait_queue(&nn->bl_wq, &wq);
78 81
79out: 82out:
80 kfree(msg.data); 83 kfree(msg->data);
81} 84}
82 85
83/* 86/*
@@ -90,10 +93,10 @@ static void nfs4_blk_metadev_release(struct pnfs_block_dev *bdev)
90 dprintk("%s Releasing\n", __func__); 93 dprintk("%s Releasing\n", __func__);
91 rv = nfs4_blkdev_put(bdev->bm_mdev); 94 rv = nfs4_blkdev_put(bdev->bm_mdev);
92 if (rv) 95 if (rv)
93 printk(KERN_ERR "%s nfs4_blkdev_put returns %d\n", 96 printk(KERN_ERR "NFS: %s nfs4_blkdev_put returns %d\n",
94 __func__, rv); 97 __func__, rv);
95 98
96 dev_remove(bdev->bm_mdev->bd_dev); 99 dev_remove(bdev->net, bdev->bm_mdev->bd_dev);
97} 100}
98 101
99void bl_free_block_dev(struct pnfs_block_dev *bdev) 102void bl_free_block_dev(struct pnfs_block_dev *bdev)
diff --git a/fs/nfs/blocklayout/extents.c b/fs/nfs/blocklayout/extents.c
index 1abac09f7cd5..1f9a6032796b 100644
--- a/fs/nfs/blocklayout/extents.c
+++ b/fs/nfs/blocklayout/extents.c
@@ -147,7 +147,7 @@ static int _preload_range(struct pnfs_inval_markings *marks,
147 count = (int)(end - start) / (int)tree->mtt_step_size; 147 count = (int)(end - start) / (int)tree->mtt_step_size;
148 148
149 /* Pre-malloc what memory we might need */ 149 /* Pre-malloc what memory we might need */
150 storage = kmalloc(sizeof(*storage) * count, GFP_NOFS); 150 storage = kcalloc(count, sizeof(*storage), GFP_NOFS);
151 if (!storage) 151 if (!storage)
152 return -ENOMEM; 152 return -ENOMEM;
153 for (i = 0; i < count; i++) { 153 for (i = 0; i < count; i++) {
diff --git a/fs/nfs/cache_lib.c b/fs/nfs/cache_lib.c
index c98b439332fc..dded26368111 100644
--- a/fs/nfs/cache_lib.c
+++ b/fs/nfs/cache_lib.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/sunrpc/cache.h> 14#include <linux/sunrpc/cache.h>
15#include <linux/sunrpc/rpc_pipe_fs.h> 15#include <linux/sunrpc/rpc_pipe_fs.h>
16#include <net/net_namespace.h>
16 17
17#include "cache_lib.h" 18#include "cache_lib.h"
18 19
@@ -111,30 +112,54 @@ int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq)
111 return 0; 112 return 0;
112} 113}
113 114
114int nfs_cache_register(struct cache_detail *cd) 115int nfs_cache_register_sb(struct super_block *sb, struct cache_detail *cd)
115{ 116{
116 struct vfsmount *mnt;
117 struct path path;
118 int ret; 117 int ret;
118 struct dentry *dir;
119 119
120 mnt = rpc_get_mount(); 120 dir = rpc_d_lookup_sb(sb, "cache");
121 if (IS_ERR(mnt)) 121 BUG_ON(dir == NULL);
122 return PTR_ERR(mnt); 122 ret = sunrpc_cache_register_pipefs(dir, cd->name, 0600, cd);
123 ret = vfs_path_lookup(mnt->mnt_root, mnt, "/cache", 0, &path); 123 dput(dir);
124 if (ret)
125 goto err;
126 ret = sunrpc_cache_register_pipefs(path.dentry, cd->name, 0600, cd);
127 path_put(&path);
128 if (!ret)
129 return ret;
130err:
131 rpc_put_mount();
132 return ret; 124 return ret;
133} 125}
134 126
135void nfs_cache_unregister(struct cache_detail *cd) 127int nfs_cache_register_net(struct net *net, struct cache_detail *cd)
136{ 128{
137 sunrpc_cache_unregister_pipefs(cd); 129 struct super_block *pipefs_sb;
138 rpc_put_mount(); 130 int ret = 0;
131
132 pipefs_sb = rpc_get_sb_net(net);
133 if (pipefs_sb) {
134 ret = nfs_cache_register_sb(pipefs_sb, cd);
135 rpc_put_sb_net(net);
136 }
137 return ret;
138}
139
140void nfs_cache_unregister_sb(struct super_block *sb, struct cache_detail *cd)
141{
142 if (cd->u.pipefs.dir)
143 sunrpc_cache_unregister_pipefs(cd);
144}
145
146void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd)
147{
148 struct super_block *pipefs_sb;
149
150 pipefs_sb = rpc_get_sb_net(net);
151 if (pipefs_sb) {
152 nfs_cache_unregister_sb(pipefs_sb, cd);
153 rpc_put_sb_net(net);
154 }
155}
156
157void nfs_cache_init(struct cache_detail *cd)
158{
159 sunrpc_init_cache_detail(cd);
139} 160}
140 161
162void nfs_cache_destroy(struct cache_detail *cd)
163{
164 sunrpc_destroy_cache_detail(cd);
165}
diff --git a/fs/nfs/cache_lib.h b/fs/nfs/cache_lib.h
index 7cf6cafcc007..317db95e37f8 100644
--- a/fs/nfs/cache_lib.h
+++ b/fs/nfs/cache_lib.h
@@ -23,5 +23,11 @@ extern struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void);
23extern void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq); 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); 24extern int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq);
25 25
26extern int nfs_cache_register(struct cache_detail *cd); 26extern void nfs_cache_init(struct cache_detail *cd);
27extern void nfs_cache_unregister(struct cache_detail *cd); 27extern void nfs_cache_destroy(struct cache_detail *cd);
28extern int nfs_cache_register_net(struct net *net, struct cache_detail *cd);
29extern void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd);
30extern int nfs_cache_register_sb(struct super_block *sb,
31 struct cache_detail *cd);
32extern void nfs_cache_unregister_sb(struct super_block *sb,
33 struct cache_detail *cd);
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 516f3375e067..eb95f5091c1a 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -85,7 +85,7 @@ nfs4_callback_svc(void *vrqstp)
85 } 85 }
86 if (err < 0) { 86 if (err < 0) {
87 if (err != preverr) { 87 if (err != preverr) {
88 printk(KERN_WARNING "%s: unexpected error " 88 printk(KERN_WARNING "NFS: %s: unexpected error "
89 "from svc_recv (%d)\n", __func__, err); 89 "from svc_recv (%d)\n", __func__, err);
90 preverr = err; 90 preverr = err;
91 } 91 }
@@ -101,12 +101,12 @@ nfs4_callback_svc(void *vrqstp)
101/* 101/*
102 * Prepare to bring up the NFSv4 callback service 102 * Prepare to bring up the NFSv4 callback service
103 */ 103 */
104struct svc_rqst * 104static struct svc_rqst *
105nfs4_callback_up(struct svc_serv *serv) 105nfs4_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
106{ 106{
107 int ret; 107 int ret;
108 108
109 ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET, 109 ret = svc_create_xprt(serv, "tcp", xprt->xprt_net, PF_INET,
110 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); 110 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
111 if (ret <= 0) 111 if (ret <= 0)
112 goto out_err; 112 goto out_err;
@@ -114,7 +114,7 @@ nfs4_callback_up(struct svc_serv *serv)
114 dprintk("NFS: Callback listener port = %u (af %u)\n", 114 dprintk("NFS: Callback listener port = %u (af %u)\n",
115 nfs_callback_tcpport, PF_INET); 115 nfs_callback_tcpport, PF_INET);
116 116
117 ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET6, 117 ret = svc_create_xprt(serv, "tcp", xprt->xprt_net, PF_INET6,
118 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); 118 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
119 if (ret > 0) { 119 if (ret > 0) {
120 nfs_callback_tcpport6 = ret; 120 nfs_callback_tcpport6 = ret;
@@ -172,7 +172,7 @@ nfs41_callback_svc(void *vrqstp)
172/* 172/*
173 * Bring up the NFSv4.1 callback service 173 * Bring up the NFSv4.1 callback service
174 */ 174 */
175struct svc_rqst * 175static struct svc_rqst *
176nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) 176nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
177{ 177{
178 struct svc_rqst *rqstp; 178 struct svc_rqst *rqstp;
@@ -183,7 +183,7 @@ nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
183 * fore channel connection. 183 * fore channel connection.
184 * Returns the input port (0) and sets the svc_serv bc_xprt on success 184 * Returns the input port (0) and sets the svc_serv bc_xprt on success
185 */ 185 */
186 ret = svc_create_xprt(serv, "tcp-bc", &init_net, PF_INET, 0, 186 ret = svc_create_xprt(serv, "tcp-bc", xprt->xprt_net, PF_INET, 0,
187 SVC_SOCK_ANONYMOUS); 187 SVC_SOCK_ANONYMOUS);
188 if (ret < 0) { 188 if (ret < 0) {
189 rqstp = ERR_PTR(ret); 189 rqstp = ERR_PTR(ret);
@@ -269,7 +269,7 @@ int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt)
269 serv, xprt, &rqstp, &callback_svc); 269 serv, xprt, &rqstp, &callback_svc);
270 if (!minorversion_setup) { 270 if (!minorversion_setup) {
271 /* v4.0 callback setup */ 271 /* v4.0 callback setup */
272 rqstp = nfs4_callback_up(serv); 272 rqstp = nfs4_callback_up(serv, xprt);
273 callback_svc = nfs4_callback_svc; 273 callback_svc = nfs4_callback_svc;
274 } 274 }
275 275
@@ -332,7 +332,6 @@ void nfs_callback_down(int minorversion)
332int 332int
333check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp) 333check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
334{ 334{
335 struct rpc_clnt *r = clp->cl_rpcclient;
336 char *p = svc_gss_principal(rqstp); 335 char *p = svc_gss_principal(rqstp);
337 336
338 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS) 337 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
@@ -353,7 +352,7 @@ check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
353 if (memcmp(p, "nfs@", 4) != 0) 352 if (memcmp(p, "nfs@", 4) != 0)
354 return 0; 353 return 0;
355 p += 4; 354 p += 4;
356 if (strcmp(p, r->cl_server) != 0) 355 if (strcmp(p, clp->cl_hostname) != 0)
357 return 0; 356 return 0;
358 return 1; 357 return 1;
359} 358}
diff --git a/fs/nfs/callback.h b/fs/nfs/callback.h
index c89d3b9e483c..a5527c90a5aa 100644
--- a/fs/nfs/callback.h
+++ b/fs/nfs/callback.h
@@ -38,7 +38,8 @@ enum nfs4_callback_opnum {
38struct cb_process_state { 38struct cb_process_state {
39 __be32 drc_status; 39 __be32 drc_status;
40 struct nfs_client *clp; 40 struct nfs_client *clp;
41 int slotid; 41 u32 slotid;
42 struct net *net;
42}; 43};
43 44
44struct cb_compound_hdr_arg { 45struct cb_compound_hdr_arg {
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index 54cea8ad5a76..1b5d809a105e 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -8,6 +8,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 <linux/slab.h>
11#include <linux/rcupdate.h>
11#include "nfs4_fs.h" 12#include "nfs4_fs.h"
12#include "callback.h" 13#include "callback.h"
13#include "delegation.h" 14#include "delegation.h"
@@ -33,7 +34,7 @@ __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
33 res->bitmap[0] = res->bitmap[1] = 0; 34 res->bitmap[0] = res->bitmap[1] = 0;
34 res->status = htonl(NFS4ERR_BADHANDLE); 35 res->status = htonl(NFS4ERR_BADHANDLE);
35 36
36 dprintk("NFS: GETATTR callback request from %s\n", 37 dprintk_rcu("NFS: GETATTR callback request from %s\n",
37 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 38 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
38 39
39 inode = nfs_delegation_find_inode(cps->clp, &args->fh); 40 inode = nfs_delegation_find_inode(cps->clp, &args->fh);
@@ -73,7 +74,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
73 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */ 74 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
74 goto out; 75 goto out;
75 76
76 dprintk("NFS: RECALL callback request from %s\n", 77 dprintk_rcu("NFS: RECALL callback request from %s\n",
77 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 78 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
78 79
79 res = htonl(NFS4ERR_BADHANDLE); 80 res = htonl(NFS4ERR_BADHANDLE);
@@ -86,8 +87,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
86 res = 0; 87 res = 0;
87 break; 88 break;
88 case -ENOENT: 89 case -ENOENT:
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);
@@ -98,52 +98,64 @@ out:
98 return res; 98 return res;
99} 99}
100 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
109#if defined(CONFIG_NFS_V4_1) 101#if defined(CONFIG_NFS_V4_1)
110 102
111static u32 initiate_file_draining(struct nfs_client *clp, 103/*
112 struct cb_layoutrecallargs *args) 104 * Lookup a layout by filehandle.
105 *
106 * Note: gets a refcount on the layout hdr and on its respective inode.
107 * Caller must put the layout hdr and the inode.
108 *
109 * TODO: keep track of all layouts (and delegations) in a hash table
110 * hashed by filehandle.
111 */
112static struct pnfs_layout_hdr * get_layout_by_fh_locked(struct nfs_client *clp, struct nfs_fh *fh)
113{ 113{
114 struct nfs_server *server; 114 struct nfs_server *server;
115 struct pnfs_layout_hdr *lo;
116 struct inode *ino; 115 struct inode *ino;
117 bool found = false; 116 struct pnfs_layout_hdr *lo;
118 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
119 LIST_HEAD(free_me_list);
120 117
121 spin_lock(&clp->cl_lock);
122 rcu_read_lock();
123 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { 118 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
124 list_for_each_entry(lo, &server->layouts, plh_layouts) { 119 list_for_each_entry(lo, &server->layouts, plh_layouts) {
125 if (nfs_compare_fh(&args->cbl_fh, 120 if (nfs_compare_fh(fh, &NFS_I(lo->plh_inode)->fh))
126 &NFS_I(lo->plh_inode)->fh))
127 continue; 121 continue;
128 ino = igrab(lo->plh_inode); 122 ino = igrab(lo->plh_inode);
129 if (!ino) 123 if (!ino)
130 continue; 124 continue;
131 found = true;
132 /* Without this, layout can be freed as soon
133 * as we release cl_lock.
134 */
135 get_layout_hdr(lo); 125 get_layout_hdr(lo);
136 break; 126 return lo;
137 } 127 }
138 if (found)
139 break;
140 } 128 }
129
130 return NULL;
131}
132
133static struct pnfs_layout_hdr * get_layout_by_fh(struct nfs_client *clp, struct nfs_fh *fh)
134{
135 struct pnfs_layout_hdr *lo;
136
137 spin_lock(&clp->cl_lock);
138 rcu_read_lock();
139 lo = get_layout_by_fh_locked(clp, fh);
141 rcu_read_unlock(); 140 rcu_read_unlock();
142 spin_unlock(&clp->cl_lock); 141 spin_unlock(&clp->cl_lock);
143 142
144 if (!found) 143 return lo;
144}
145
146static u32 initiate_file_draining(struct nfs_client *clp,
147 struct cb_layoutrecallargs *args)
148{
149 struct inode *ino;
150 struct pnfs_layout_hdr *lo;
151 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
152 LIST_HEAD(free_me_list);
153
154 lo = get_layout_by_fh(clp, &args->cbl_fh);
155 if (!lo)
145 return NFS4ERR_NOMATCHING_LAYOUT; 156 return NFS4ERR_NOMATCHING_LAYOUT;
146 157
158 ino = lo->plh_inode;
147 spin_lock(&ino->i_lock); 159 spin_lock(&ino->i_lock);
148 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || 160 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
149 mark_matching_lsegs_invalid(lo, &free_me_list, 161 mark_matching_lsegs_invalid(lo, &free_me_list,
@@ -213,17 +225,13 @@ static u32 initiate_bulk_draining(struct nfs_client *clp,
213static u32 do_callback_layoutrecall(struct nfs_client *clp, 225static u32 do_callback_layoutrecall(struct nfs_client *clp,
214 struct cb_layoutrecallargs *args) 226 struct cb_layoutrecallargs *args)
215{ 227{
216 u32 res = NFS4ERR_DELAY; 228 u32 res;
217 229
218 dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type); 230 dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type);
219 if (test_and_set_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state))
220 goto out;
221 if (args->cbl_recall_type == RETURN_FILE) 231 if (args->cbl_recall_type == RETURN_FILE)
222 res = initiate_file_draining(clp, args); 232 res = initiate_file_draining(clp, args);
223 else 233 else
224 res = initiate_bulk_draining(clp, args); 234 res = initiate_bulk_draining(clp, args);
225 clear_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state);
226out:
227 dprintk("%s returning %i\n", __func__, res); 235 dprintk("%s returning %i\n", __func__, res);
228 return res; 236 return res;
229 237
@@ -303,21 +311,6 @@ out:
303 return res; 311 return res;
304} 312}
305 313
306int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
307{
308 if (delegation == NULL)
309 return 0;
310
311 if (stateid->stateid.seqid != 0)
312 return 0;
313 if (memcmp(&delegation->stateid.stateid.other,
314 &stateid->stateid.other,
315 NFS4_STATEID_OTHER_SIZE))
316 return 0;
317
318 return 1;
319}
320
321/* 314/*
322 * Validate the sequenceID sent by the server. 315 * Validate the sequenceID sent by the server.
323 * Return success if the sequenceID is one more than what we last saw on 316 * Return success if the sequenceID is one more than what we last saw on
@@ -441,7 +434,7 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
441 int i; 434 int i;
442 __be32 status = htonl(NFS4ERR_BADSESSION); 435 __be32 status = htonl(NFS4ERR_BADSESSION);
443 436
444 clp = nfs4_find_client_sessionid(args->csa_addr, &args->csa_sessionid); 437 clp = nfs4_find_client_sessionid(cps->net, args->csa_addr, &args->csa_sessionid);
445 if (clp == NULL) 438 if (clp == NULL)
446 goto out; 439 goto out;
447 440
@@ -517,7 +510,7 @@ __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy,
517 if (!cps->clp) /* set in cb_sequence */ 510 if (!cps->clp) /* set in cb_sequence */
518 goto out; 511 goto out;
519 512
520 dprintk("NFS: RECALL_ANY callback request from %s\n", 513 dprintk_rcu("NFS: RECALL_ANY callback request from %s\n",
521 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 514 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
522 515
523 status = cpu_to_be32(NFS4ERR_INVAL); 516 status = cpu_to_be32(NFS4ERR_INVAL);
@@ -552,7 +545,7 @@ __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy,
552 if (!cps->clp) /* set in cb_sequence */ 545 if (!cps->clp) /* set in cb_sequence */
553 goto out; 546 goto out;
554 547
555 dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n", 548 dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
556 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR), 549 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
557 args->crsa_target_max_slots); 550 args->crsa_target_max_slots);
558 551
diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
index d50b2742f23b..95bfc243992c 100644
--- a/fs/nfs/callback_xdr.c
+++ b/fs/nfs/callback_xdr.c
@@ -9,6 +9,8 @@
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/ratelimit.h>
13#include <linux/printk.h>
12#include <linux/slab.h> 14#include <linux/slab.h>
13#include <linux/sunrpc/bc_xprt.h> 15#include <linux/sunrpc/bc_xprt.h>
14#include "nfs4_fs.h" 16#include "nfs4_fs.h"
@@ -73,7 +75,7 @@ static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
73 75
74 p = xdr_inline_decode(xdr, nbytes); 76 p = xdr_inline_decode(xdr, nbytes);
75 if (unlikely(p == NULL)) 77 if (unlikely(p == NULL))
76 printk(KERN_WARNING "NFSv4 callback reply buffer overflowed!\n"); 78 printk(KERN_WARNING "NFS: NFSv4 callback reply buffer overflowed!\n");
77 return p; 79 return p;
78} 80}
79 81
@@ -138,10 +140,10 @@ static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
138{ 140{
139 __be32 *p; 141 __be32 *p;
140 142
141 p = read_buf(xdr, 16); 143 p = read_buf(xdr, NFS4_STATEID_SIZE);
142 if (unlikely(p == NULL)) 144 if (unlikely(p == NULL))
143 return htonl(NFS4ERR_RESOURCE); 145 return htonl(NFS4ERR_RESOURCE);
144 memcpy(stateid->data, p, 16); 146 memcpy(stateid, p, NFS4_STATEID_SIZE);
145 return 0; 147 return 0;
146} 148}
147 149
@@ -155,7 +157,7 @@ static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound
155 return status; 157 return status;
156 /* We do not like overly long tags! */ 158 /* We do not like overly long tags! */
157 if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) { 159 if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
158 printk("NFSv4 CALLBACK %s: client sent tag of length %u\n", 160 printk("NFS: NFSv4 CALLBACK %s: client sent tag of length %u\n",
159 __func__, hdr->taglen); 161 __func__, hdr->taglen);
160 return htonl(NFS4ERR_RESOURCE); 162 return htonl(NFS4ERR_RESOURCE);
161 } 163 }
@@ -167,7 +169,7 @@ static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound
167 if (hdr->minorversion <= 1) { 169 if (hdr->minorversion <= 1) {
168 hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */ 170 hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */
169 } else { 171 } else {
170 printk(KERN_WARNING "%s: NFSv4 server callback with " 172 pr_warn_ratelimited("NFS: %s: NFSv4 server callback with "
171 "illegal minor version %u!\n", 173 "illegal minor version %u!\n",
172 __func__, hdr->minorversion); 174 __func__, hdr->minorversion);
173 return htonl(NFS4ERR_MINOR_VERS_MISMATCH); 175 return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
@@ -759,14 +761,14 @@ static void nfs4_callback_free_slot(struct nfs4_session *session)
759 * Let the state manager know callback processing done. 761 * Let the state manager know callback processing done.
760 * A single slot, so highest used slotid is either 0 or -1 762 * A single slot, so highest used slotid is either 0 or -1
761 */ 763 */
762 tbl->highest_used_slotid = -1; 764 tbl->highest_used_slotid = NFS4_NO_SLOT;
763 nfs4_check_drain_bc_complete(session); 765 nfs4_check_drain_bc_complete(session);
764 spin_unlock(&tbl->slot_tbl_lock); 766 spin_unlock(&tbl->slot_tbl_lock);
765} 767}
766 768
767static void nfs4_cb_free_slot(struct cb_process_state *cps) 769static void nfs4_cb_free_slot(struct cb_process_state *cps)
768{ 770{
769 if (cps->slotid != -1) 771 if (cps->slotid != NFS4_NO_SLOT)
770 nfs4_callback_free_slot(cps->clp->cl_session); 772 nfs4_callback_free_slot(cps->clp->cl_session);
771} 773}
772 774
@@ -860,7 +862,8 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
860 struct cb_process_state cps = { 862 struct cb_process_state cps = {
861 .drc_status = 0, 863 .drc_status = 0,
862 .clp = NULL, 864 .clp = NULL,
863 .slotid = -1, 865 .slotid = NFS4_NO_SLOT,
866 .net = rqstp->rq_xprt->xpt_net,
864 }; 867 };
865 unsigned int nops = 0; 868 unsigned int nops = 0;
866 869
@@ -876,7 +879,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
876 return rpc_garbage_args; 879 return rpc_garbage_args;
877 880
878 if (hdr_arg.minorversion == 0) { 881 if (hdr_arg.minorversion == 0) {
879 cps.clp = nfs4_find_client_ident(hdr_arg.cb_ident); 882 cps.clp = nfs4_find_client_ident(rqstp->rq_xprt->xpt_net, hdr_arg.cb_ident);
880 if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp)) 883 if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp))
881 return rpc_drop_reply; 884 return rpc_drop_reply;
882 } 885 }
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 31778f74357d..2f378487ccde 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -39,6 +39,8 @@
39#include <net/ipv6.h> 39#include <net/ipv6.h>
40#include <linux/nfs_xdr.h> 40#include <linux/nfs_xdr.h>
41#include <linux/sunrpc/bc_xprt.h> 41#include <linux/sunrpc/bc_xprt.h>
42#include <linux/nsproxy.h>
43#include <linux/pid_namespace.h>
42 44
43#include <asm/system.h> 45#include <asm/system.h>
44 46
@@ -49,15 +51,12 @@
49#include "internal.h" 51#include "internal.h"
50#include "fscache.h" 52#include "fscache.h"
51#include "pnfs.h" 53#include "pnfs.h"
54#include "netns.h"
52 55
53#define NFSDBG_FACILITY NFSDBG_CLIENT 56#define NFSDBG_FACILITY NFSDBG_CLIENT
54 57
55static DEFINE_SPINLOCK(nfs_client_lock);
56static LIST_HEAD(nfs_client_list);
57static LIST_HEAD(nfs_volume_list);
58static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); 58static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
59#ifdef CONFIG_NFS_V4 59#ifdef CONFIG_NFS_V4
60static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
61 60
62/* 61/*
63 * Get a unique NFSv4.0 callback identifier which will be used 62 * Get a unique NFSv4.0 callback identifier which will be used
@@ -66,15 +65,16 @@ static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
66static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) 65static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
67{ 66{
68 int ret = 0; 67 int ret = 0;
68 struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
69 69
70 if (clp->rpc_ops->version != 4 || minorversion != 0) 70 if (clp->rpc_ops->version != 4 || minorversion != 0)
71 return ret; 71 return ret;
72retry: 72retry:
73 if (!idr_pre_get(&cb_ident_idr, GFP_KERNEL)) 73 if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL))
74 return -ENOMEM; 74 return -ENOMEM;
75 spin_lock(&nfs_client_lock); 75 spin_lock(&nn->nfs_client_lock);
76 ret = idr_get_new(&cb_ident_idr, clp, &clp->cl_cb_ident); 76 ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident);
77 spin_unlock(&nfs_client_lock); 77 spin_unlock(&nn->nfs_client_lock);
78 if (ret == -EAGAIN) 78 if (ret == -EAGAIN)
79 goto retry; 79 goto retry;
80 return ret; 80 return ret;
@@ -89,7 +89,7 @@ static bool nfs4_disable_idmapping = true;
89/* 89/*
90 * RPC cruft for NFS 90 * RPC cruft for NFS
91 */ 91 */
92static struct rpc_version *nfs_version[5] = { 92static const struct rpc_version *nfs_version[5] = {
93 [2] = &nfs_version2, 93 [2] = &nfs_version2,
94#ifdef CONFIG_NFS_V3 94#ifdef CONFIG_NFS_V3
95 [3] = &nfs_version3, 95 [3] = &nfs_version3,
@@ -99,7 +99,7 @@ static struct rpc_version *nfs_version[5] = {
99#endif 99#endif
100}; 100};
101 101
102struct rpc_program nfs_program = { 102const struct rpc_program nfs_program = {
103 .name = "nfs", 103 .name = "nfs",
104 .number = NFS_PROGRAM, 104 .number = NFS_PROGRAM,
105 .nrvers = ARRAY_SIZE(nfs_version), 105 .nrvers = ARRAY_SIZE(nfs_version),
@@ -115,11 +115,11 @@ struct rpc_stat nfs_rpcstat = {
115 115
116#ifdef CONFIG_NFS_V3_ACL 116#ifdef CONFIG_NFS_V3_ACL
117static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; 117static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
118static struct rpc_version * nfsacl_version[] = { 118static const struct rpc_version *nfsacl_version[] = {
119 [3] = &nfsacl_version3, 119 [3] = &nfsacl_version3,
120}; 120};
121 121
122struct rpc_program nfsacl_program = { 122const struct rpc_program nfsacl_program = {
123 .name = "nfsacl", 123 .name = "nfsacl",
124 .number = NFS_ACL_PROGRAM, 124 .number = NFS_ACL_PROGRAM,
125 .nrvers = ARRAY_SIZE(nfsacl_version), 125 .nrvers = ARRAY_SIZE(nfsacl_version),
@@ -135,6 +135,7 @@ struct nfs_client_initdata {
135 const struct nfs_rpc_ops *rpc_ops; 135 const struct nfs_rpc_ops *rpc_ops;
136 int proto; 136 int proto;
137 u32 minorversion; 137 u32 minorversion;
138 struct net *net;
138}; 139};
139 140
140/* 141/*
@@ -171,6 +172,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
171 clp->cl_rpcclient = ERR_PTR(-EINVAL); 172 clp->cl_rpcclient = ERR_PTR(-EINVAL);
172 173
173 clp->cl_proto = cl_init->proto; 174 clp->cl_proto = cl_init->proto;
175 clp->net = get_net(cl_init->net);
174 176
175#ifdef CONFIG_NFS_V4 177#ifdef CONFIG_NFS_V4
176 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); 178 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
@@ -202,8 +204,11 @@ error_0:
202#ifdef CONFIG_NFS_V4_1 204#ifdef CONFIG_NFS_V4_1
203static void nfs4_shutdown_session(struct nfs_client *clp) 205static void nfs4_shutdown_session(struct nfs_client *clp)
204{ 206{
205 if (nfs4_has_session(clp)) 207 if (nfs4_has_session(clp)) {
208 nfs4_deviceid_purge_client(clp);
206 nfs4_destroy_session(clp->cl_session); 209 nfs4_destroy_session(clp->cl_session);
210 }
211
207} 212}
208#else /* CONFIG_NFS_V4_1 */ 213#else /* CONFIG_NFS_V4_1 */
209static void nfs4_shutdown_session(struct nfs_client *clp) 214static void nfs4_shutdown_session(struct nfs_client *clp)
@@ -233,16 +238,20 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
233} 238}
234 239
235/* idr_remove_all is not needed as all id's are removed by nfs_put_client */ 240/* idr_remove_all is not needed as all id's are removed by nfs_put_client */
236void nfs_cleanup_cb_ident_idr(void) 241void nfs_cleanup_cb_ident_idr(struct net *net)
237{ 242{
238 idr_destroy(&cb_ident_idr); 243 struct nfs_net *nn = net_generic(net, nfs_net_id);
244
245 idr_destroy(&nn->cb_ident_idr);
239} 246}
240 247
241/* nfs_client_lock held */ 248/* nfs_client_lock held */
242static void nfs_cb_idr_remove_locked(struct nfs_client *clp) 249static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
243{ 250{
251 struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
252
244 if (clp->cl_cb_ident) 253 if (clp->cl_cb_ident)
245 idr_remove(&cb_ident_idr, clp->cl_cb_ident); 254 idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident);
246} 255}
247 256
248static void pnfs_init_server(struct nfs_server *server) 257static void pnfs_init_server(struct nfs_server *server)
@@ -260,7 +269,7 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
260{ 269{
261} 270}
262 271
263void nfs_cleanup_cb_ident_idr(void) 272void nfs_cleanup_cb_ident_idr(struct net *net)
264{ 273{
265} 274}
266 275
@@ -292,10 +301,10 @@ static void nfs_free_client(struct nfs_client *clp)
292 if (clp->cl_machine_cred != NULL) 301 if (clp->cl_machine_cred != NULL)
293 put_rpccred(clp->cl_machine_cred); 302 put_rpccred(clp->cl_machine_cred);
294 303
295 nfs4_deviceid_purge_client(clp); 304 put_net(clp->net);
296
297 kfree(clp->cl_hostname); 305 kfree(clp->cl_hostname);
298 kfree(clp->server_scope); 306 kfree(clp->server_scope);
307 kfree(clp->impl_id);
299 kfree(clp); 308 kfree(clp);
300 309
301 dprintk("<-- nfs_free_client()\n"); 310 dprintk("<-- nfs_free_client()\n");
@@ -306,15 +315,18 @@ static void nfs_free_client(struct nfs_client *clp)
306 */ 315 */
307void nfs_put_client(struct nfs_client *clp) 316void nfs_put_client(struct nfs_client *clp)
308{ 317{
318 struct nfs_net *nn;
319
309 if (!clp) 320 if (!clp)
310 return; 321 return;
311 322
312 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); 323 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
324 nn = net_generic(clp->net, nfs_net_id);
313 325
314 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { 326 if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) {
315 list_del(&clp->cl_share_link); 327 list_del(&clp->cl_share_link);
316 nfs_cb_idr_remove_locked(clp); 328 nfs_cb_idr_remove_locked(clp);
317 spin_unlock(&nfs_client_lock); 329 spin_unlock(&nn->nfs_client_lock);
318 330
319 BUG_ON(!list_empty(&clp->cl_superblocks)); 331 BUG_ON(!list_empty(&clp->cl_superblocks));
320 332
@@ -392,6 +404,7 @@ static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1,
392 (sin1->sin_port == sin2->sin_port); 404 (sin1->sin_port == sin2->sin_port);
393} 405}
394 406
407#if defined(CONFIG_NFS_V4_1)
395/* 408/*
396 * Test if two socket addresses represent the same actual socket, 409 * Test if two socket addresses represent the same actual socket,
397 * by comparing (only) relevant fields, excluding the port number. 410 * by comparing (only) relevant fields, excluding the port number.
@@ -410,6 +423,7 @@ static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
410 } 423 }
411 return 0; 424 return 0;
412} 425}
426#endif /* CONFIG_NFS_V4_1 */
413 427
414/* 428/*
415 * Test if two socket addresses represent the same actual socket, 429 * Test if two socket addresses represent the same actual socket,
@@ -430,10 +444,10 @@ static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
430 return 0; 444 return 0;
431} 445}
432 446
447#if defined(CONFIG_NFS_V4_1)
433/* Common match routine for v4.0 and v4.1 callback services */ 448/* Common match routine for v4.0 and v4.1 callback services */
434bool 449static bool nfs4_cb_match_client(const struct sockaddr *addr,
435nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp, 450 struct nfs_client *clp, u32 minorversion)
436 u32 minorversion)
437{ 451{
438 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; 452 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
439 453
@@ -453,6 +467,7 @@ nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp,
453 467
454 return true; 468 return true;
455} 469}
470#endif /* CONFIG_NFS_V4_1 */
456 471
457/* 472/*
458 * Find an nfs_client on the list that matches the initialisation data 473 * Find an nfs_client on the list that matches the initialisation data
@@ -462,8 +477,9 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
462{ 477{
463 struct nfs_client *clp; 478 struct nfs_client *clp;
464 const struct sockaddr *sap = data->addr; 479 const struct sockaddr *sap = data->addr;
480 struct nfs_net *nn = net_generic(data->net, nfs_net_id);
465 481
466 list_for_each_entry(clp, &nfs_client_list, cl_share_link) { 482 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
467 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; 483 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
468 /* Don't match clients that failed to initialise properly */ 484 /* Don't match clients that failed to initialise properly */
469 if (clp->cl_cons_state < 0) 485 if (clp->cl_cons_state < 0)
@@ -501,13 +517,14 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
501{ 517{
502 struct nfs_client *clp, *new = NULL; 518 struct nfs_client *clp, *new = NULL;
503 int error; 519 int error;
520 struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id);
504 521
505 dprintk("--> nfs_get_client(%s,v%u)\n", 522 dprintk("--> nfs_get_client(%s,v%u)\n",
506 cl_init->hostname ?: "", cl_init->rpc_ops->version); 523 cl_init->hostname ?: "", cl_init->rpc_ops->version);
507 524
508 /* see if the client already exists */ 525 /* see if the client already exists */
509 do { 526 do {
510 spin_lock(&nfs_client_lock); 527 spin_lock(&nn->nfs_client_lock);
511 528
512 clp = nfs_match_client(cl_init); 529 clp = nfs_match_client(cl_init);
513 if (clp) 530 if (clp)
@@ -515,7 +532,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
515 if (new) 532 if (new)
516 goto install_client; 533 goto install_client;
517 534
518 spin_unlock(&nfs_client_lock); 535 spin_unlock(&nn->nfs_client_lock);
519 536
520 new = nfs_alloc_client(cl_init); 537 new = nfs_alloc_client(cl_init);
521 } while (!IS_ERR(new)); 538 } while (!IS_ERR(new));
@@ -526,8 +543,8 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
526 /* install a new client and return with it unready */ 543 /* install a new client and return with it unready */
527install_client: 544install_client:
528 clp = new; 545 clp = new;
529 list_add(&clp->cl_share_link, &nfs_client_list); 546 list_add(&clp->cl_share_link, &nn->nfs_client_list);
530 spin_unlock(&nfs_client_lock); 547 spin_unlock(&nn->nfs_client_lock);
531 548
532 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr, 549 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr,
533 authflavour, noresvport); 550 authflavour, noresvport);
@@ -542,7 +559,7 @@ install_client:
542 * - make sure it's ready before returning 559 * - make sure it's ready before returning
543 */ 560 */
544found_client: 561found_client:
545 spin_unlock(&nfs_client_lock); 562 spin_unlock(&nn->nfs_client_lock);
546 563
547 if (new) 564 if (new)
548 nfs_free_client(new); 565 nfs_free_client(new);
@@ -642,7 +659,7 @@ static int nfs_create_rpc_client(struct nfs_client *clp,
642{ 659{
643 struct rpc_clnt *clnt = NULL; 660 struct rpc_clnt *clnt = NULL;
644 struct rpc_create_args args = { 661 struct rpc_create_args args = {
645 .net = &init_net, 662 .net = clp->net,
646 .protocol = clp->cl_proto, 663 .protocol = clp->cl_proto,
647 .address = (struct sockaddr *)&clp->cl_addr, 664 .address = (struct sockaddr *)&clp->cl_addr,
648 .addrsize = clp->cl_addrlen, 665 .addrsize = clp->cl_addrlen,
@@ -696,6 +713,7 @@ static int nfs_start_lockd(struct nfs_server *server)
696 .nfs_version = clp->rpc_ops->version, 713 .nfs_version = clp->rpc_ops->version,
697 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? 714 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
698 1 : 0, 715 1 : 0,
716 .net = clp->net,
699 }; 717 };
700 718
701 if (nlm_init.nfs_version > 3) 719 if (nlm_init.nfs_version > 3)
@@ -831,6 +849,7 @@ static int nfs_init_server(struct nfs_server *server,
831 .addrlen = data->nfs_server.addrlen, 849 .addrlen = data->nfs_server.addrlen,
832 .rpc_ops = &nfs_v2_clientops, 850 .rpc_ops = &nfs_v2_clientops,
833 .proto = data->nfs_server.protocol, 851 .proto = data->nfs_server.protocol,
852 .net = data->net,
834 }; 853 };
835 struct rpc_timeout timeparms; 854 struct rpc_timeout timeparms;
836 struct nfs_client *clp; 855 struct nfs_client *clp;
@@ -1029,25 +1048,30 @@ static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_serve
1029static void nfs_server_insert_lists(struct nfs_server *server) 1048static void nfs_server_insert_lists(struct nfs_server *server)
1030{ 1049{
1031 struct nfs_client *clp = server->nfs_client; 1050 struct nfs_client *clp = server->nfs_client;
1051 struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
1032 1052
1033 spin_lock(&nfs_client_lock); 1053 spin_lock(&nn->nfs_client_lock);
1034 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); 1054 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
1035 list_add_tail(&server->master_link, &nfs_volume_list); 1055 list_add_tail(&server->master_link, &nn->nfs_volume_list);
1036 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); 1056 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
1037 spin_unlock(&nfs_client_lock); 1057 spin_unlock(&nn->nfs_client_lock);
1038 1058
1039} 1059}
1040 1060
1041static void nfs_server_remove_lists(struct nfs_server *server) 1061static void nfs_server_remove_lists(struct nfs_server *server)
1042{ 1062{
1043 struct nfs_client *clp = server->nfs_client; 1063 struct nfs_client *clp = server->nfs_client;
1064 struct nfs_net *nn;
1044 1065
1045 spin_lock(&nfs_client_lock); 1066 if (clp == NULL)
1067 return;
1068 nn = net_generic(clp->net, nfs_net_id);
1069 spin_lock(&nn->nfs_client_lock);
1046 list_del_rcu(&server->client_link); 1070 list_del_rcu(&server->client_link);
1047 if (clp && list_empty(&clp->cl_superblocks)) 1071 if (list_empty(&clp->cl_superblocks))
1048 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); 1072 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
1049 list_del(&server->master_link); 1073 list_del(&server->master_link);
1050 spin_unlock(&nfs_client_lock); 1074 spin_unlock(&nn->nfs_client_lock);
1051 1075
1052 synchronize_rcu(); 1076 synchronize_rcu();
1053} 1077}
@@ -1086,6 +1110,8 @@ static struct nfs_server *nfs_alloc_server(void)
1086 return NULL; 1110 return NULL;
1087 } 1111 }
1088 1112
1113 ida_init(&server->openowner_id);
1114 ida_init(&server->lockowner_id);
1089 pnfs_init_server(server); 1115 pnfs_init_server(server);
1090 1116
1091 return server; 1117 return server;
@@ -1111,6 +1137,8 @@ void nfs_free_server(struct nfs_server *server)
1111 1137
1112 nfs_put_client(server->nfs_client); 1138 nfs_put_client(server->nfs_client);
1113 1139
1140 ida_destroy(&server->lockowner_id);
1141 ida_destroy(&server->openowner_id);
1114 nfs_free_iostats(server->io_stats); 1142 nfs_free_iostats(server->io_stats);
1115 bdi_destroy(&server->backing_dev_info); 1143 bdi_destroy(&server->backing_dev_info);
1116 kfree(server); 1144 kfree(server);
@@ -1189,45 +1217,19 @@ error:
1189/* 1217/*
1190 * NFSv4.0 callback thread helper 1218 * NFSv4.0 callback thread helper
1191 * 1219 *
1192 * Find a client by IP address, protocol version, and minorversion
1193 *
1194 * Called from the pg_authenticate method. The callback identifier
1195 * is not used as it has not been decoded.
1196 *
1197 * Returns NULL if no such client
1198 */
1199struct nfs_client *
1200nfs4_find_client_no_ident(const struct sockaddr *addr)
1201{
1202 struct nfs_client *clp;
1203
1204 spin_lock(&nfs_client_lock);
1205 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1206 if (nfs4_cb_match_client(addr, clp, 0) == false)
1207 continue;
1208 atomic_inc(&clp->cl_count);
1209 spin_unlock(&nfs_client_lock);
1210 return clp;
1211 }
1212 spin_unlock(&nfs_client_lock);
1213 return NULL;
1214}
1215
1216/*
1217 * NFSv4.0 callback thread helper
1218 *
1219 * Find a client by callback identifier 1220 * Find a client by callback identifier
1220 */ 1221 */
1221struct nfs_client * 1222struct nfs_client *
1222nfs4_find_client_ident(int cb_ident) 1223nfs4_find_client_ident(struct net *net, int cb_ident)
1223{ 1224{
1224 struct nfs_client *clp; 1225 struct nfs_client *clp;
1226 struct nfs_net *nn = net_generic(net, nfs_net_id);
1225 1227
1226 spin_lock(&nfs_client_lock); 1228 spin_lock(&nn->nfs_client_lock);
1227 clp = idr_find(&cb_ident_idr, cb_ident); 1229 clp = idr_find(&nn->cb_ident_idr, cb_ident);
1228 if (clp) 1230 if (clp)
1229 atomic_inc(&clp->cl_count); 1231 atomic_inc(&clp->cl_count);
1230 spin_unlock(&nfs_client_lock); 1232 spin_unlock(&nn->nfs_client_lock);
1231 return clp; 1233 return clp;
1232} 1234}
1233 1235
@@ -1240,13 +1242,14 @@ nfs4_find_client_ident(int cb_ident)
1240 * Returns NULL if no such client 1242 * Returns NULL if no such client
1241 */ 1243 */
1242struct nfs_client * 1244struct nfs_client *
1243nfs4_find_client_sessionid(const struct sockaddr *addr, 1245nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
1244 struct nfs4_sessionid *sid) 1246 struct nfs4_sessionid *sid)
1245{ 1247{
1246 struct nfs_client *clp; 1248 struct nfs_client *clp;
1249 struct nfs_net *nn = net_generic(net, nfs_net_id);
1247 1250
1248 spin_lock(&nfs_client_lock); 1251 spin_lock(&nn->nfs_client_lock);
1249 list_for_each_entry(clp, &nfs_client_list, cl_share_link) { 1252 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
1250 if (nfs4_cb_match_client(addr, clp, 1) == false) 1253 if (nfs4_cb_match_client(addr, clp, 1) == false)
1251 continue; 1254 continue;
1252 1255
@@ -1259,17 +1262,17 @@ nfs4_find_client_sessionid(const struct sockaddr *addr,
1259 continue; 1262 continue;
1260 1263
1261 atomic_inc(&clp->cl_count); 1264 atomic_inc(&clp->cl_count);
1262 spin_unlock(&nfs_client_lock); 1265 spin_unlock(&nn->nfs_client_lock);
1263 return clp; 1266 return clp;
1264 } 1267 }
1265 spin_unlock(&nfs_client_lock); 1268 spin_unlock(&nn->nfs_client_lock);
1266 return NULL; 1269 return NULL;
1267} 1270}
1268 1271
1269#else /* CONFIG_NFS_V4_1 */ 1272#else /* CONFIG_NFS_V4_1 */
1270 1273
1271struct nfs_client * 1274struct nfs_client *
1272nfs4_find_client_sessionid(const struct sockaddr *addr, 1275nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
1273 struct nfs4_sessionid *sid) 1276 struct nfs4_sessionid *sid)
1274{ 1277{
1275 return NULL; 1278 return NULL;
@@ -1284,16 +1287,18 @@ static int nfs4_init_callback(struct nfs_client *clp)
1284 int error; 1287 int error;
1285 1288
1286 if (clp->rpc_ops->version == 4) { 1289 if (clp->rpc_ops->version == 4) {
1290 struct rpc_xprt *xprt;
1291
1292 xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
1293
1287 if (nfs4_has_session(clp)) { 1294 if (nfs4_has_session(clp)) {
1288 error = xprt_setup_backchannel( 1295 error = xprt_setup_backchannel(xprt,
1289 clp->cl_rpcclient->cl_xprt,
1290 NFS41_BC_MIN_CALLBACKS); 1296 NFS41_BC_MIN_CALLBACKS);
1291 if (error < 0) 1297 if (error < 0)
1292 return error; 1298 return error;
1293 } 1299 }
1294 1300
1295 error = nfs_callback_up(clp->cl_mvops->minor_version, 1301 error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
1296 clp->cl_rpcclient->cl_xprt);
1297 if (error < 0) { 1302 if (error < 0) {
1298 dprintk("%s: failed to start callback. Error = %d\n", 1303 dprintk("%s: failed to start callback. Error = %d\n",
1299 __func__, error); 1304 __func__, error);
@@ -1344,6 +1349,7 @@ int nfs4_init_client(struct nfs_client *clp,
1344 rpc_authflavor_t authflavour, 1349 rpc_authflavor_t authflavour,
1345 int noresvport) 1350 int noresvport)
1346{ 1351{
1352 char buf[INET6_ADDRSTRLEN + 1];
1347 int error; 1353 int error;
1348 1354
1349 if (clp->cl_cons_state == NFS_CS_READY) { 1355 if (clp->cl_cons_state == NFS_CS_READY) {
@@ -1359,6 +1365,20 @@ int nfs4_init_client(struct nfs_client *clp,
1359 1, noresvport); 1365 1, noresvport);
1360 if (error < 0) 1366 if (error < 0)
1361 goto error; 1367 goto error;
1368
1369 /* If no clientaddr= option was specified, find a usable cb address */
1370 if (ip_addr == NULL) {
1371 struct sockaddr_storage cb_addr;
1372 struct sockaddr *sap = (struct sockaddr *)&cb_addr;
1373
1374 error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr));
1375 if (error < 0)
1376 goto error;
1377 error = rpc_ntop(sap, buf, sizeof(buf));
1378 if (error < 0)
1379 goto error;
1380 ip_addr = (const char *)buf;
1381 }
1362 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); 1382 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
1363 1383
1364 error = nfs_idmap_new(clp); 1384 error = nfs_idmap_new(clp);
@@ -1393,7 +1413,7 @@ static int nfs4_set_client(struct nfs_server *server,
1393 const char *ip_addr, 1413 const char *ip_addr,
1394 rpc_authflavor_t authflavour, 1414 rpc_authflavor_t authflavour,
1395 int proto, const struct rpc_timeout *timeparms, 1415 int proto, const struct rpc_timeout *timeparms,
1396 u32 minorversion) 1416 u32 minorversion, struct net *net)
1397{ 1417{
1398 struct nfs_client_initdata cl_init = { 1418 struct nfs_client_initdata cl_init = {
1399 .hostname = hostname, 1419 .hostname = hostname,
@@ -1402,6 +1422,7 @@ static int nfs4_set_client(struct nfs_server *server,
1402 .rpc_ops = &nfs_v4_clientops, 1422 .rpc_ops = &nfs_v4_clientops,
1403 .proto = proto, 1423 .proto = proto,
1404 .minorversion = minorversion, 1424 .minorversion = minorversion,
1425 .net = net,
1405 }; 1426 };
1406 struct nfs_client *clp; 1427 struct nfs_client *clp;
1407 int error; 1428 int error;
@@ -1453,6 +1474,7 @@ struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
1453 .rpc_ops = &nfs_v4_clientops, 1474 .rpc_ops = &nfs_v4_clientops,
1454 .proto = ds_proto, 1475 .proto = ds_proto,
1455 .minorversion = mds_clp->cl_minorversion, 1476 .minorversion = mds_clp->cl_minorversion,
1477 .net = mds_clp->net,
1456 }; 1478 };
1457 struct rpc_timeout ds_timeout = { 1479 struct rpc_timeout ds_timeout = {
1458 .to_initval = 15 * HZ, 1480 .to_initval = 15 * HZ,
@@ -1580,7 +1602,8 @@ static int nfs4_init_server(struct nfs_server *server,
1580 data->auth_flavors[0], 1602 data->auth_flavors[0],
1581 data->nfs_server.protocol, 1603 data->nfs_server.protocol,
1582 &timeparms, 1604 &timeparms,
1583 data->minorversion); 1605 data->minorversion,
1606 data->net);
1584 if (error < 0) 1607 if (error < 0)
1585 goto error; 1608 goto error;
1586 1609
@@ -1675,9 +1698,10 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1675 data->addrlen, 1698 data->addrlen,
1676 parent_client->cl_ipaddr, 1699 parent_client->cl_ipaddr,
1677 data->authflavor, 1700 data->authflavor,
1678 parent_server->client->cl_xprt->prot, 1701 rpc_protocol(parent_server->client),
1679 parent_server->client->cl_timeout, 1702 parent_server->client->cl_timeout,
1680 parent_client->cl_mvops->minor_version); 1703 parent_client->cl_mvops->minor_version,
1704 parent_client->net);
1681 if (error < 0) 1705 if (error < 0)
1682 goto error; 1706 goto error;
1683 1707
@@ -1770,6 +1794,18 @@ out_free_server:
1770 return ERR_PTR(error); 1794 return ERR_PTR(error);
1771} 1795}
1772 1796
1797void nfs_clients_init(struct net *net)
1798{
1799 struct nfs_net *nn = net_generic(net, nfs_net_id);
1800
1801 INIT_LIST_HEAD(&nn->nfs_client_list);
1802 INIT_LIST_HEAD(&nn->nfs_volume_list);
1803#ifdef CONFIG_NFS_V4
1804 idr_init(&nn->cb_ident_idr);
1805#endif
1806 spin_lock_init(&nn->nfs_client_lock);
1807}
1808
1773#ifdef CONFIG_PROC_FS 1809#ifdef CONFIG_PROC_FS
1774static struct proc_dir_entry *proc_fs_nfs; 1810static struct proc_dir_entry *proc_fs_nfs;
1775 1811
@@ -1823,13 +1859,15 @@ static int nfs_server_list_open(struct inode *inode, struct file *file)
1823{ 1859{
1824 struct seq_file *m; 1860 struct seq_file *m;
1825 int ret; 1861 int ret;
1862 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1863 struct net *net = pid_ns->child_reaper->nsproxy->net_ns;
1826 1864
1827 ret = seq_open(file, &nfs_server_list_ops); 1865 ret = seq_open(file, &nfs_server_list_ops);
1828 if (ret < 0) 1866 if (ret < 0)
1829 return ret; 1867 return ret;
1830 1868
1831 m = file->private_data; 1869 m = file->private_data;
1832 m->private = PDE(inode)->data; 1870 m->private = net;
1833 1871
1834 return 0; 1872 return 0;
1835} 1873}
@@ -1839,9 +1877,11 @@ static int nfs_server_list_open(struct inode *inode, struct file *file)
1839 */ 1877 */
1840static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) 1878static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1841{ 1879{
1880 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1881
1842 /* lock the list against modification */ 1882 /* lock the list against modification */
1843 spin_lock(&nfs_client_lock); 1883 spin_lock(&nn->nfs_client_lock);
1844 return seq_list_start_head(&nfs_client_list, *_pos); 1884 return seq_list_start_head(&nn->nfs_client_list, *_pos);
1845} 1885}
1846 1886
1847/* 1887/*
@@ -1849,7 +1889,9 @@ static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1849 */ 1889 */
1850static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) 1890static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1851{ 1891{
1852 return seq_list_next(v, &nfs_client_list, pos); 1892 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1893
1894 return seq_list_next(v, &nn->nfs_client_list, pos);
1853} 1895}
1854 1896
1855/* 1897/*
@@ -1857,7 +1899,9 @@ static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1857 */ 1899 */
1858static void nfs_server_list_stop(struct seq_file *p, void *v) 1900static void nfs_server_list_stop(struct seq_file *p, void *v)
1859{ 1901{
1860 spin_unlock(&nfs_client_lock); 1902 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1903
1904 spin_unlock(&nn->nfs_client_lock);
1861} 1905}
1862 1906
1863/* 1907/*
@@ -1866,9 +1910,10 @@ static void nfs_server_list_stop(struct seq_file *p, void *v)
1866static int nfs_server_list_show(struct seq_file *m, void *v) 1910static int nfs_server_list_show(struct seq_file *m, void *v)
1867{ 1911{
1868 struct nfs_client *clp; 1912 struct nfs_client *clp;
1913 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1869 1914
1870 /* display header on line 1 */ 1915 /* display header on line 1 */
1871 if (v == &nfs_client_list) { 1916 if (v == &nn->nfs_client_list) {
1872 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); 1917 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1873 return 0; 1918 return 0;
1874 } 1919 }
@@ -1880,12 +1925,14 @@ static int nfs_server_list_show(struct seq_file *m, void *v)
1880 if (clp->cl_cons_state != NFS_CS_READY) 1925 if (clp->cl_cons_state != NFS_CS_READY)
1881 return 0; 1926 return 0;
1882 1927
1928 rcu_read_lock();
1883 seq_printf(m, "v%u %s %s %3d %s\n", 1929 seq_printf(m, "v%u %s %s %3d %s\n",
1884 clp->rpc_ops->version, 1930 clp->rpc_ops->version,
1885 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 1931 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1886 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), 1932 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
1887 atomic_read(&clp->cl_count), 1933 atomic_read(&clp->cl_count),
1888 clp->cl_hostname); 1934 clp->cl_hostname);
1935 rcu_read_unlock();
1889 1936
1890 return 0; 1937 return 0;
1891} 1938}
@@ -1897,13 +1944,15 @@ static int nfs_volume_list_open(struct inode *inode, struct file *file)
1897{ 1944{
1898 struct seq_file *m; 1945 struct seq_file *m;
1899 int ret; 1946 int ret;
1947 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1948 struct net *net = pid_ns->child_reaper->nsproxy->net_ns;
1900 1949
1901 ret = seq_open(file, &nfs_volume_list_ops); 1950 ret = seq_open(file, &nfs_volume_list_ops);
1902 if (ret < 0) 1951 if (ret < 0)
1903 return ret; 1952 return ret;
1904 1953
1905 m = file->private_data; 1954 m = file->private_data;
1906 m->private = PDE(inode)->data; 1955 m->private = net;
1907 1956
1908 return 0; 1957 return 0;
1909} 1958}
@@ -1913,9 +1962,11 @@ static int nfs_volume_list_open(struct inode *inode, struct file *file)
1913 */ 1962 */
1914static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) 1963static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1915{ 1964{
1965 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1966
1916 /* lock the list against modification */ 1967 /* lock the list against modification */
1917 spin_lock(&nfs_client_lock); 1968 spin_lock(&nn->nfs_client_lock);
1918 return seq_list_start_head(&nfs_volume_list, *_pos); 1969 return seq_list_start_head(&nn->nfs_volume_list, *_pos);
1919} 1970}
1920 1971
1921/* 1972/*
@@ -1923,7 +1974,9 @@ static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1923 */ 1974 */
1924static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) 1975static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1925{ 1976{
1926 return seq_list_next(v, &nfs_volume_list, pos); 1977 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1978
1979 return seq_list_next(v, &nn->nfs_volume_list, pos);
1927} 1980}
1928 1981
1929/* 1982/*
@@ -1931,7 +1984,9 @@ static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1931 */ 1984 */
1932static void nfs_volume_list_stop(struct seq_file *p, void *v) 1985static void nfs_volume_list_stop(struct seq_file *p, void *v)
1933{ 1986{
1934 spin_unlock(&nfs_client_lock); 1987 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1988
1989 spin_unlock(&nn->nfs_client_lock);
1935} 1990}
1936 1991
1937/* 1992/*
@@ -1942,9 +1997,10 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
1942 struct nfs_server *server; 1997 struct nfs_server *server;
1943 struct nfs_client *clp; 1998 struct nfs_client *clp;
1944 char dev[8], fsid[17]; 1999 char dev[8], fsid[17];
2000 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1945 2001
1946 /* display header on line 1 */ 2002 /* display header on line 1 */
1947 if (v == &nfs_volume_list) { 2003 if (v == &nn->nfs_volume_list) {
1948 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); 2004 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n");
1949 return 0; 2005 return 0;
1950 } 2006 }
@@ -1959,6 +2015,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
1959 (unsigned long long) server->fsid.major, 2015 (unsigned long long) server->fsid.major,
1960 (unsigned long long) server->fsid.minor); 2016 (unsigned long long) server->fsid.minor);
1961 2017
2018 rcu_read_lock();
1962 seq_printf(m, "v%u %s %s %-7s %-17s %s\n", 2019 seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
1963 clp->rpc_ops->version, 2020 clp->rpc_ops->version,
1964 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 2021 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
@@ -1966,6 +2023,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
1966 dev, 2023 dev,
1967 fsid, 2024 fsid,
1968 nfs_server_fscache_state(server)); 2025 nfs_server_fscache_state(server));
2026 rcu_read_unlock();
1969 2027
1970 return 0; 2028 return 0;
1971} 2029}
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 7f2654069806..89af1d269274 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -105,7 +105,7 @@ again:
105 continue; 105 continue;
106 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) 106 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
107 continue; 107 continue;
108 if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0) 108 if (!nfs4_stateid_match(&state->stateid, stateid))
109 continue; 109 continue;
110 get_nfs_open_context(ctx); 110 get_nfs_open_context(ctx);
111 spin_unlock(&inode->i_lock); 111 spin_unlock(&inode->i_lock);
@@ -139,8 +139,7 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
139 if (delegation != NULL) { 139 if (delegation != NULL) {
140 spin_lock(&delegation->lock); 140 spin_lock(&delegation->lock);
141 if (delegation->inode != NULL) { 141 if (delegation->inode != NULL) {
142 memcpy(delegation->stateid.data, res->delegation.data, 142 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
143 sizeof(delegation->stateid.data));
144 delegation->type = res->delegation_type; 143 delegation->type = res->delegation_type;
145 delegation->maxsize = res->maxsize; 144 delegation->maxsize = res->maxsize;
146 oldcred = delegation->cred; 145 oldcred = delegation->cred;
@@ -236,8 +235,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
236 delegation = kmalloc(sizeof(*delegation), GFP_NOFS); 235 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
237 if (delegation == NULL) 236 if (delegation == NULL)
238 return -ENOMEM; 237 return -ENOMEM;
239 memcpy(delegation->stateid.data, res->delegation.data, 238 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
240 sizeof(delegation->stateid.data));
241 delegation->type = res->delegation_type; 239 delegation->type = res->delegation_type;
242 delegation->maxsize = res->maxsize; 240 delegation->maxsize = res->maxsize;
243 delegation->change_attr = inode->i_version; 241 delegation->change_attr = inode->i_version;
@@ -250,19 +248,22 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
250 old_delegation = rcu_dereference_protected(nfsi->delegation, 248 old_delegation = rcu_dereference_protected(nfsi->delegation,
251 lockdep_is_held(&clp->cl_lock)); 249 lockdep_is_held(&clp->cl_lock));
252 if (old_delegation != NULL) { 250 if (old_delegation != NULL) {
253 if (memcmp(&delegation->stateid, &old_delegation->stateid, 251 if (nfs4_stateid_match(&delegation->stateid,
254 sizeof(old_delegation->stateid)) == 0 && 252 &old_delegation->stateid) &&
255 delegation->type == old_delegation->type) { 253 delegation->type == old_delegation->type) {
256 goto out; 254 goto out;
257 } 255 }
258 /* 256 /*
259 * Deal with broken servers that hand out two 257 * Deal with broken servers that hand out two
260 * delegations for the same file. 258 * delegations for the same file.
259 * Allow for upgrades to a WRITE delegation, but
260 * nothing else.
261 */ 261 */
262 dfprintk(FILE, "%s: server %s handed out " 262 dfprintk(FILE, "%s: server %s handed out "
263 "a duplicate delegation!\n", 263 "a duplicate delegation!\n",
264 __func__, clp->cl_hostname); 264 __func__, clp->cl_hostname);
265 if (delegation->type <= old_delegation->type) { 265 if (delegation->type == old_delegation->type ||
266 !(delegation->type & FMODE_WRITE)) {
266 freeme = delegation; 267 freeme = delegation;
267 delegation = NULL; 268 delegation = NULL;
268 goto out; 269 goto out;
@@ -455,17 +456,24 @@ static void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp,
455 rcu_read_unlock(); 456 rcu_read_unlock();
456} 457}
457 458
458static void nfs_client_mark_return_all_delegations(struct nfs_client *clp)
459{
460 nfs_client_mark_return_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
461}
462
463static void nfs_delegation_run_state_manager(struct nfs_client *clp) 459static void nfs_delegation_run_state_manager(struct nfs_client *clp)
464{ 460{
465 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) 461 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state))
466 nfs4_schedule_state_manager(clp); 462 nfs4_schedule_state_manager(clp);
467} 463}
468 464
465void nfs_remove_bad_delegation(struct inode *inode)
466{
467 struct nfs_delegation *delegation;
468
469 delegation = nfs_detach_delegation(NFS_I(inode), NFS_SERVER(inode));
470 if (delegation) {
471 nfs_inode_find_state_and_recover(inode, &delegation->stateid);
472 nfs_free_delegation(delegation);
473 }
474}
475EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation);
476
469/** 477/**
470 * nfs_expire_all_delegation_types 478 * nfs_expire_all_delegation_types
471 * @clp: client to process 479 * @clp: client to process
@@ -488,18 +496,6 @@ void nfs_expire_all_delegations(struct nfs_client *clp)
488 nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE); 496 nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
489} 497}
490 498
491/**
492 * nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
493 * @clp: client to process
494 *
495 */
496void nfs_handle_cb_pathdown(struct nfs_client *clp)
497{
498 if (clp == NULL)
499 return;
500 nfs_client_mark_return_all_delegations(clp);
501}
502
503static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server) 499static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
504{ 500{
505 struct nfs_delegation *delegation; 501 struct nfs_delegation *delegation;
@@ -531,7 +527,7 @@ void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
531/** 527/**
532 * nfs_async_inode_return_delegation - asynchronously return a delegation 528 * nfs_async_inode_return_delegation - asynchronously return a delegation
533 * @inode: inode to process 529 * @inode: inode to process
534 * @stateid: state ID information from CB_RECALL arguments 530 * @stateid: state ID information
535 * 531 *
536 * Returns zero on success, or a negative errno value. 532 * Returns zero on success, or a negative errno value.
537 */ 533 */
@@ -545,7 +541,7 @@ int nfs_async_inode_return_delegation(struct inode *inode,
545 rcu_read_lock(); 541 rcu_read_lock();
546 delegation = rcu_dereference(NFS_I(inode)->delegation); 542 delegation = rcu_dereference(NFS_I(inode)->delegation);
547 543
548 if (!clp->cl_mvops->validate_stateid(delegation, stateid)) { 544 if (!clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) {
549 rcu_read_unlock(); 545 rcu_read_unlock();
550 return -ENOENT; 546 return -ENOENT;
551 } 547 }
@@ -684,21 +680,25 @@ int nfs_delegations_present(struct nfs_client *clp)
684 * nfs4_copy_delegation_stateid - Copy inode's state ID information 680 * nfs4_copy_delegation_stateid - Copy inode's state ID information
685 * @dst: stateid data structure to fill in 681 * @dst: stateid data structure to fill in
686 * @inode: inode to check 682 * @inode: inode to check
683 * @flags: delegation type requirement
687 * 684 *
688 * Returns one and fills in "dst->data" * if inode had a delegation, 685 * Returns "true" and fills in "dst->data" * if inode had a delegation,
689 * otherwise zero is returned. 686 * otherwise "false" is returned.
690 */ 687 */
691int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode) 688bool nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode,
689 fmode_t flags)
692{ 690{
693 struct nfs_inode *nfsi = NFS_I(inode); 691 struct nfs_inode *nfsi = NFS_I(inode);
694 struct nfs_delegation *delegation; 692 struct nfs_delegation *delegation;
695 int ret = 0; 693 bool ret;
696 694
695 flags &= FMODE_READ|FMODE_WRITE;
697 rcu_read_lock(); 696 rcu_read_lock();
698 delegation = rcu_dereference(nfsi->delegation); 697 delegation = rcu_dereference(nfsi->delegation);
699 if (delegation != NULL) { 698 ret = (delegation != NULL && (delegation->type & flags) == flags);
700 memcpy(dst->data, delegation->stateid.data, sizeof(dst->data)); 699 if (ret) {
701 ret = 1; 700 nfs4_stateid_copy(dst, &delegation->stateid);
701 nfs_mark_delegation_referenced(delegation);
702 } 702 }
703 rcu_read_unlock(); 703 rcu_read_unlock();
704 return ret; 704 return ret;
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index d9322e490c56..cd6a7a8dadae 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -42,9 +42,9 @@ void 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_all_delegation_types(struct nfs_client *clp, fmode_t flags);
44void nfs_expire_unreferenced_delegations(struct nfs_client *clp); 44void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
45void nfs_handle_cb_pathdown(struct nfs_client *clp);
46int nfs_client_return_marked_delegations(struct nfs_client *clp); 45int nfs_client_return_marked_delegations(struct nfs_client *clp);
47int nfs_delegations_present(struct nfs_client *clp); 46int nfs_delegations_present(struct nfs_client *clp);
47void nfs_remove_bad_delegation(struct inode *inode);
48 48
49void nfs_delegation_mark_reclaim(struct nfs_client *clp); 49void nfs_delegation_mark_reclaim(struct nfs_client *clp);
50void nfs_delegation_reap_unclaimed(struct nfs_client *clp); 50void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
@@ -53,7 +53,7 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
53int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync); 53int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
54int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid); 54int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid);
55int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl); 55int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl);
56int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode); 56bool nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode, fmode_t flags);
57 57
58void nfs_mark_delegation_referenced(struct nfs_delegation *delegation); 58void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
59int nfs_have_delegation(struct inode *inode, fmode_t flags); 59int nfs_have_delegation(struct inode *inode, fmode_t flags);
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index fd9a872fada0..9952170271b2 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -207,7 +207,7 @@ struct nfs_cache_array_entry {
207}; 207};
208 208
209struct nfs_cache_array { 209struct nfs_cache_array {
210 unsigned int size; 210 int size;
211 int eof_index; 211 int eof_index;
212 u64 last_cookie; 212 u64 last_cookie;
213 struct nfs_cache_array_entry array[0]; 213 struct nfs_cache_array_entry array[0];
@@ -1429,6 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1429 } 1429 }
1430 1430
1431 open_flags = nd->intent.open.flags; 1431 open_flags = nd->intent.open.flags;
1432 attr.ia_valid = 0;
1432 1433
1433 ctx = create_nfs_open_context(dentry, open_flags); 1434 ctx = create_nfs_open_context(dentry, open_flags);
1434 res = ERR_CAST(ctx); 1435 res = ERR_CAST(ctx);
@@ -1437,11 +1438,14 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1437 1438
1438 if (nd->flags & LOOKUP_CREATE) { 1439 if (nd->flags & LOOKUP_CREATE) {
1439 attr.ia_mode = nd->intent.open.create_mode; 1440 attr.ia_mode = nd->intent.open.create_mode;
1440 attr.ia_valid = ATTR_MODE; 1441 attr.ia_valid |= ATTR_MODE;
1441 attr.ia_mode &= ~current_umask(); 1442 attr.ia_mode &= ~current_umask();
1442 } else { 1443 } else
1443 open_flags &= ~(O_EXCL | O_CREAT); 1444 open_flags &= ~(O_EXCL | O_CREAT);
1444 attr.ia_valid = 0; 1445
1446 if (open_flags & O_TRUNC) {
1447 attr.ia_valid |= ATTR_SIZE;
1448 attr.ia_size = 0;
1445 } 1449 }
1446 1450
1447 /* Open the file on the server */ 1451 /* Open the file on the server */
@@ -1495,6 +1499,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1495 struct inode *inode; 1499 struct inode *inode;
1496 struct inode *dir; 1500 struct inode *dir;
1497 struct nfs_open_context *ctx; 1501 struct nfs_open_context *ctx;
1502 struct iattr attr;
1498 int openflags, ret = 0; 1503 int openflags, ret = 0;
1499 1504
1500 if (nd->flags & LOOKUP_RCU) 1505 if (nd->flags & LOOKUP_RCU)
@@ -1523,19 +1528,27 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1523 /* We cannot do exclusive creation on a positive dentry */ 1528 /* We cannot do exclusive creation on a positive dentry */
1524 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) 1529 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
1525 goto no_open_dput; 1530 goto no_open_dput;
1526 /* We can't create new files, or truncate existing ones here */ 1531 /* We can't create new files here */
1527 openflags &= ~(O_CREAT|O_EXCL|O_TRUNC); 1532 openflags &= ~(O_CREAT|O_EXCL);
1528 1533
1529 ctx = create_nfs_open_context(dentry, openflags); 1534 ctx = create_nfs_open_context(dentry, openflags);
1530 ret = PTR_ERR(ctx); 1535 ret = PTR_ERR(ctx);
1531 if (IS_ERR(ctx)) 1536 if (IS_ERR(ctx))
1532 goto out; 1537 goto out;
1538
1539 attr.ia_valid = 0;
1540 if (openflags & O_TRUNC) {
1541 attr.ia_valid |= ATTR_SIZE;
1542 attr.ia_size = 0;
1543 nfs_wb_all(inode);
1544 }
1545
1533 /* 1546 /*
1534 * Note: we're not holding inode->i_mutex and so may be racing with 1547 * Note: we're not holding inode->i_mutex and so may be racing with
1535 * operations that change the directory. We therefore save the 1548 * operations that change the directory. We therefore save the
1536 * change attribute *before* we do the RPC call. 1549 * change attribute *before* we do the RPC call.
1537 */ 1550 */
1538 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, NULL); 1551 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr);
1539 if (IS_ERR(inode)) { 1552 if (IS_ERR(inode)) {
1540 ret = PTR_ERR(inode); 1553 ret = PTR_ERR(inode);
1541 switch (ret) { 1554 switch (ret) {
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 1940f1a56a5f..9c7f66ac6cc2 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -265,9 +265,7 @@ static void nfs_direct_read_release(void *calldata)
265} 265}
266 266
267static const struct rpc_call_ops nfs_read_direct_ops = { 267static const struct rpc_call_ops nfs_read_direct_ops = {
268#if defined(CONFIG_NFS_V4_1)
269 .rpc_call_prepare = nfs_read_prepare, 268 .rpc_call_prepare = nfs_read_prepare,
270#endif /* CONFIG_NFS_V4_1 */
271 .rpc_call_done = nfs_direct_read_result, 269 .rpc_call_done = nfs_direct_read_result,
272 .rpc_release = nfs_direct_read_release, 270 .rpc_release = nfs_direct_read_release,
273}; 271};
@@ -554,9 +552,7 @@ static void nfs_direct_commit_release(void *calldata)
554} 552}
555 553
556static const struct rpc_call_ops nfs_commit_direct_ops = { 554static const struct rpc_call_ops nfs_commit_direct_ops = {
557#if defined(CONFIG_NFS_V4_1)
558 .rpc_call_prepare = nfs_write_prepare, 555 .rpc_call_prepare = nfs_write_prepare,
559#endif /* CONFIG_NFS_V4_1 */
560 .rpc_call_done = nfs_direct_commit_result, 556 .rpc_call_done = nfs_direct_commit_result,
561 .rpc_release = nfs_direct_commit_release, 557 .rpc_release = nfs_direct_commit_release,
562}; 558};
@@ -696,9 +692,7 @@ out_unlock:
696} 692}
697 693
698static const struct rpc_call_ops nfs_write_direct_ops = { 694static const struct rpc_call_ops nfs_write_direct_ops = {
699#if defined(CONFIG_NFS_V4_1)
700 .rpc_call_prepare = nfs_write_prepare, 695 .rpc_call_prepare = nfs_write_prepare,
701#endif /* CONFIG_NFS_V4_1 */
702 .rpc_call_done = nfs_direct_write_result, 696 .rpc_call_done = nfs_direct_write_result,
703 .rpc_release = nfs_direct_write_release, 697 .rpc_release = nfs_direct_write_release,
704}; 698};
diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index a6e711ad130f..b3924b8a6000 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -10,8 +10,9 @@
10 10
11#include <linux/sunrpc/clnt.h> 11#include <linux/sunrpc/clnt.h>
12#include <linux/dns_resolver.h> 12#include <linux/dns_resolver.h>
13#include "dns_resolve.h"
13 14
14ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 15ssize_t nfs_dns_resolve_name(struct net *net, char *name, size_t namelen,
15 struct sockaddr *sa, size_t salen) 16 struct sockaddr *sa, size_t salen)
16{ 17{
17 ssize_t ret; 18 ssize_t ret;
@@ -20,7 +21,7 @@ ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
20 21
21 ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL); 22 ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
22 if (ip_len > 0) 23 if (ip_len > 0)
23 ret = rpc_pton(ip_addr, ip_len, sa, salen); 24 ret = rpc_pton(net, ip_addr, ip_len, sa, salen);
24 else 25 else
25 ret = -ESRCH; 26 ret = -ESRCH;
26 kfree(ip_addr); 27 kfree(ip_addr);
@@ -40,15 +41,15 @@ ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
40#include <linux/sunrpc/clnt.h> 41#include <linux/sunrpc/clnt.h>
41#include <linux/sunrpc/cache.h> 42#include <linux/sunrpc/cache.h>
42#include <linux/sunrpc/svcauth.h> 43#include <linux/sunrpc/svcauth.h>
44#include <linux/sunrpc/rpc_pipe_fs.h>
43 45
44#include "dns_resolve.h" 46#include "dns_resolve.h"
45#include "cache_lib.h" 47#include "cache_lib.h"
48#include "netns.h"
46 49
47#define NFS_DNS_HASHBITS 4 50#define NFS_DNS_HASHBITS 4
48#define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS) 51#define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS)
49 52
50static struct cache_head *nfs_dns_table[NFS_DNS_HASHTBL_SIZE];
51
52struct nfs_dns_ent { 53struct nfs_dns_ent {
53 struct cache_head h; 54 struct cache_head h;
54 55
@@ -224,7 +225,7 @@ static int nfs_dns_parse(struct cache_detail *cd, char *buf, int buflen)
224 len = qword_get(&buf, buf1, sizeof(buf1)); 225 len = qword_get(&buf, buf1, sizeof(buf1));
225 if (len <= 0) 226 if (len <= 0)
226 goto out; 227 goto out;
227 key.addrlen = rpc_pton(buf1, len, 228 key.addrlen = rpc_pton(cd->net, buf1, len,
228 (struct sockaddr *)&key.addr, 229 (struct sockaddr *)&key.addr,
229 sizeof(key.addr)); 230 sizeof(key.addr));
230 231
@@ -259,21 +260,6 @@ out:
259 return ret; 260 return ret;
260} 261}
261 262
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, 263static int do_cache_lookup(struct cache_detail *cd,
278 struct nfs_dns_ent *key, 264 struct nfs_dns_ent *key,
279 struct nfs_dns_ent **item, 265 struct nfs_dns_ent **item,
@@ -336,8 +322,8 @@ out:
336 return ret; 322 return ret;
337} 323}
338 324
339ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 325ssize_t nfs_dns_resolve_name(struct net *net, char *name,
340 struct sockaddr *sa, size_t salen) 326 size_t namelen, struct sockaddr *sa, size_t salen)
341{ 327{
342 struct nfs_dns_ent key = { 328 struct nfs_dns_ent key = {
343 .hostname = name, 329 .hostname = name,
@@ -345,28 +331,118 @@ ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
345 }; 331 };
346 struct nfs_dns_ent *item = NULL; 332 struct nfs_dns_ent *item = NULL;
347 ssize_t ret; 333 ssize_t ret;
334 struct nfs_net *nn = net_generic(net, nfs_net_id);
348 335
349 ret = do_cache_lookup_wait(&nfs_dns_resolve, &key, &item); 336 ret = do_cache_lookup_wait(nn->nfs_dns_resolve, &key, &item);
350 if (ret == 0) { 337 if (ret == 0) {
351 if (salen >= item->addrlen) { 338 if (salen >= item->addrlen) {
352 memcpy(sa, &item->addr, item->addrlen); 339 memcpy(sa, &item->addr, item->addrlen);
353 ret = item->addrlen; 340 ret = item->addrlen;
354 } else 341 } else
355 ret = -EOVERFLOW; 342 ret = -EOVERFLOW;
356 cache_put(&item->h, &nfs_dns_resolve); 343 cache_put(&item->h, nn->nfs_dns_resolve);
357 } else if (ret == -ENOENT) 344 } else if (ret == -ENOENT)
358 ret = -ESRCH; 345 ret = -ESRCH;
359 return ret; 346 return ret;
360} 347}
361 348
349int nfs_dns_resolver_cache_init(struct net *net)
350{
351 int err = -ENOMEM;
352 struct nfs_net *nn = net_generic(net, nfs_net_id);
353 struct cache_detail *cd;
354 struct cache_head **tbl;
355
356 cd = kzalloc(sizeof(struct cache_detail), GFP_KERNEL);
357 if (cd == NULL)
358 goto err_cd;
359
360 tbl = kzalloc(NFS_DNS_HASHTBL_SIZE * sizeof(struct cache_head *),
361 GFP_KERNEL);
362 if (tbl == NULL)
363 goto err_tbl;
364
365 cd->owner = THIS_MODULE,
366 cd->hash_size = NFS_DNS_HASHTBL_SIZE,
367 cd->hash_table = tbl,
368 cd->name = "dns_resolve",
369 cd->cache_put = nfs_dns_ent_put,
370 cd->cache_upcall = nfs_dns_upcall,
371 cd->cache_parse = nfs_dns_parse,
372 cd->cache_show = nfs_dns_show,
373 cd->match = nfs_dns_match,
374 cd->init = nfs_dns_ent_init,
375 cd->update = nfs_dns_ent_update,
376 cd->alloc = nfs_dns_ent_alloc,
377
378 nfs_cache_init(cd);
379 err = nfs_cache_register_net(net, cd);
380 if (err)
381 goto err_reg;
382 nn->nfs_dns_resolve = cd;
383 return 0;
384
385err_reg:
386 nfs_cache_destroy(cd);
387 kfree(cd->hash_table);
388err_tbl:
389 kfree(cd);
390err_cd:
391 return err;
392}
393
394void nfs_dns_resolver_cache_destroy(struct net *net)
395{
396 struct nfs_net *nn = net_generic(net, nfs_net_id);
397 struct cache_detail *cd = nn->nfs_dns_resolve;
398
399 nfs_cache_unregister_net(net, cd);
400 nfs_cache_destroy(cd);
401 kfree(cd->hash_table);
402 kfree(cd);
403}
404
405static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
406 void *ptr)
407{
408 struct super_block *sb = ptr;
409 struct net *net = sb->s_fs_info;
410 struct nfs_net *nn = net_generic(net, nfs_net_id);
411 struct cache_detail *cd = nn->nfs_dns_resolve;
412 int ret = 0;
413
414 if (cd == NULL)
415 return 0;
416
417 if (!try_module_get(THIS_MODULE))
418 return 0;
419
420 switch (event) {
421 case RPC_PIPEFS_MOUNT:
422 ret = nfs_cache_register_sb(sb, cd);
423 break;
424 case RPC_PIPEFS_UMOUNT:
425 nfs_cache_unregister_sb(sb, cd);
426 break;
427 default:
428 ret = -ENOTSUPP;
429 break;
430 }
431 module_put(THIS_MODULE);
432 return ret;
433}
434
435static struct notifier_block nfs_dns_resolver_block = {
436 .notifier_call = rpc_pipefs_event,
437};
438
362int nfs_dns_resolver_init(void) 439int nfs_dns_resolver_init(void)
363{ 440{
364 return nfs_cache_register(&nfs_dns_resolve); 441 return rpc_pipefs_notifier_register(&nfs_dns_resolver_block);
365} 442}
366 443
367void nfs_dns_resolver_destroy(void) 444void nfs_dns_resolver_destroy(void)
368{ 445{
369 nfs_cache_unregister(&nfs_dns_resolve); 446 rpc_pipefs_notifier_unregister(&nfs_dns_resolver_block);
370} 447}
371
372#endif 448#endif
diff --git a/fs/nfs/dns_resolve.h b/fs/nfs/dns_resolve.h
index 199bb5543a91..2e4f596d2923 100644
--- a/fs/nfs/dns_resolve.h
+++ b/fs/nfs/dns_resolve.h
@@ -15,12 +15,22 @@ static inline int nfs_dns_resolver_init(void)
15 15
16static inline void nfs_dns_resolver_destroy(void) 16static inline void nfs_dns_resolver_destroy(void)
17{} 17{}
18
19static inline int nfs_dns_resolver_cache_init(struct net *net)
20{
21 return 0;
22}
23
24static inline void nfs_dns_resolver_cache_destroy(struct net *net)
25{}
18#else 26#else
19extern int nfs_dns_resolver_init(void); 27extern int nfs_dns_resolver_init(void);
20extern void nfs_dns_resolver_destroy(void); 28extern void nfs_dns_resolver_destroy(void);
29extern int nfs_dns_resolver_cache_init(struct net *net);
30extern void nfs_dns_resolver_cache_destroy(struct net *net);
21#endif 31#endif
22 32
23extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 33extern ssize_t nfs_dns_resolve_name(struct net *net, char *name,
24 struct sockaddr *sa, size_t salen); 34 size_t namelen, struct sockaddr *sa, size_t salen);
25 35
26#endif 36#endif
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index c43a452f7da2..4fdaaa63cf1c 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -530,6 +530,8 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
530 if (mapping != dentry->d_inode->i_mapping) 530 if (mapping != dentry->d_inode->i_mapping)
531 goto out_unlock; 531 goto out_unlock;
532 532
533 wait_on_page_writeback(page);
534
533 pagelen = nfs_page_length(page); 535 pagelen = nfs_page_length(page);
534 if (pagelen == 0) 536 if (pagelen == 0)
535 goto out_unlock; 537 goto out_unlock;
diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index 419119c371bf..ae65c16b3670 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -327,7 +327,7 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
327{ 327{
328 struct nfs_inode *nfsi = NFS_I(inode); 328 struct nfs_inode *nfsi = NFS_I(inode);
329 struct nfs_server *nfss = NFS_SERVER(inode); 329 struct nfs_server *nfss = NFS_SERVER(inode);
330 struct fscache_cookie *old = nfsi->fscache; 330 NFS_IFDEBUG(struct fscache_cookie *old = nfsi->fscache);
331 331
332 nfs_fscache_inode_lock(inode); 332 nfs_fscache_inode_lock(inode);
333 if (nfsi->fscache) { 333 if (nfsi->fscache) {
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 2c05f1991e1e..a701a83047d3 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -34,11 +34,29 @@
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#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/string.h> 37#include <linux/parser.h>
38#include <linux/kernel.h> 38#include <linux/fs.h>
39#include <linux/slab.h>
40#include <linux/nfs_idmap.h> 39#include <linux/nfs_idmap.h>
40#include <net/net_namespace.h>
41#include <linux/sunrpc/rpc_pipe_fs.h>
41#include <linux/nfs_fs.h> 42#include <linux/nfs_fs.h>
43#include <linux/nfs_fs_sb.h>
44#include <linux/key.h>
45#include <linux/keyctl.h>
46#include <linux/key-type.h>
47#include <keys/user-type.h>
48#include <linux/module.h>
49
50#include "internal.h"
51#include "netns.h"
52
53#define NFS_UINT_MAXLEN 11
54
55/* Default cache timeout is 10 minutes */
56unsigned int nfs_idmap_cache_timeout = 600;
57static const struct cred *id_resolver_cache;
58static struct key_type key_type_id_resolver_legacy;
59
42 60
43/** 61/**
44 * nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields 62 * nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields
@@ -142,24 +160,7 @@ static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen)
142 return snprintf(buf, buflen, "%u", id); 160 return snprintf(buf, buflen, "%u", id);
143} 161}
144 162
145#ifdef CONFIG_NFS_USE_NEW_IDMAPPER 163static struct key_type key_type_id_resolver = {
146
147#include <linux/cred.h>
148#include <linux/sunrpc/sched.h>
149#include <linux/nfs4.h>
150#include <linux/nfs_fs_sb.h>
151#include <linux/keyctl.h>
152#include <linux/key-type.h>
153#include <linux/rcupdate.h>
154#include <linux/err.h>
155
156#include <keys/user-type.h>
157
158#define NFS_UINT_MAXLEN 11
159
160const struct cred *id_resolver_cache;
161
162struct key_type key_type_id_resolver = {
163 .name = "id_resolver", 164 .name = "id_resolver",
164 .instantiate = user_instantiate, 165 .instantiate = user_instantiate,
165 .match = user_match, 166 .match = user_match,
@@ -169,13 +170,14 @@ struct key_type key_type_id_resolver = {
169 .read = user_read, 170 .read = user_read,
170}; 171};
171 172
172int nfs_idmap_init(void) 173static int nfs_idmap_init_keyring(void)
173{ 174{
174 struct cred *cred; 175 struct cred *cred;
175 struct key *keyring; 176 struct key *keyring;
176 int ret = 0; 177 int ret = 0;
177 178
178 printk(KERN_NOTICE "Registering the %s key type\n", key_type_id_resolver.name); 179 printk(KERN_NOTICE "NFS: Registering the %s key type\n",
180 key_type_id_resolver.name);
179 181
180 cred = prepare_kernel_cred(NULL); 182 cred = prepare_kernel_cred(NULL);
181 if (!cred) 183 if (!cred)
@@ -210,7 +212,7 @@ failed_put_cred:
210 return ret; 212 return ret;
211} 213}
212 214
213void nfs_idmap_quit(void) 215static void nfs_idmap_quit_keyring(void)
214{ 216{
215 key_revoke(id_resolver_cache->thread_keyring); 217 key_revoke(id_resolver_cache->thread_keyring);
216 unregister_key_type(&key_type_id_resolver); 218 unregister_key_type(&key_type_id_resolver);
@@ -245,8 +247,10 @@ static ssize_t nfs_idmap_get_desc(const char *name, size_t namelen,
245 return desclen; 247 return desclen;
246} 248}
247 249
248static ssize_t nfs_idmap_request_key(const char *name, size_t namelen, 250static ssize_t nfs_idmap_request_key(struct key_type *key_type,
249 const char *type, void *data, size_t data_size) 251 const char *name, size_t namelen,
252 const char *type, void *data,
253 size_t data_size, struct idmap *idmap)
250{ 254{
251 const struct cred *saved_cred; 255 const struct cred *saved_cred;
252 struct key *rkey; 256 struct key *rkey;
@@ -259,8 +263,12 @@ static ssize_t nfs_idmap_request_key(const char *name, size_t namelen,
259 goto out; 263 goto out;
260 264
261 saved_cred = override_creds(id_resolver_cache); 265 saved_cred = override_creds(id_resolver_cache);
262 rkey = request_key(&key_type_id_resolver, desc, ""); 266 if (idmap)
267 rkey = request_key_with_auxdata(key_type, desc, "", 0, idmap);
268 else
269 rkey = request_key(&key_type_id_resolver, desc, "");
263 revert_creds(saved_cred); 270 revert_creds(saved_cred);
271
264 kfree(desc); 272 kfree(desc);
265 if (IS_ERR(rkey)) { 273 if (IS_ERR(rkey)) {
266 ret = PTR_ERR(rkey); 274 ret = PTR_ERR(rkey);
@@ -293,31 +301,46 @@ out:
293 return ret; 301 return ret;
294} 302}
295 303
304static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,
305 const char *type, void *data,
306 size_t data_size, struct idmap *idmap)
307{
308 ssize_t ret = nfs_idmap_request_key(&key_type_id_resolver,
309 name, namelen, type, data,
310 data_size, NULL);
311 if (ret < 0) {
312 ret = nfs_idmap_request_key(&key_type_id_resolver_legacy,
313 name, namelen, type, data,
314 data_size, idmap);
315 }
316 return ret;
317}
296 318
297/* ID -> Name */ 319/* ID -> Name */
298static ssize_t nfs_idmap_lookup_name(__u32 id, const char *type, char *buf, size_t buflen) 320static ssize_t nfs_idmap_lookup_name(__u32 id, const char *type, char *buf,
321 size_t buflen, struct idmap *idmap)
299{ 322{
300 char id_str[NFS_UINT_MAXLEN]; 323 char id_str[NFS_UINT_MAXLEN];
301 int id_len; 324 int id_len;
302 ssize_t ret; 325 ssize_t ret;
303 326
304 id_len = snprintf(id_str, sizeof(id_str), "%u", id); 327 id_len = snprintf(id_str, sizeof(id_str), "%u", id);
305 ret = nfs_idmap_request_key(id_str, id_len, type, buf, buflen); 328 ret = nfs_idmap_get_key(id_str, id_len, type, buf, buflen, idmap);
306 if (ret < 0) 329 if (ret < 0)
307 return -EINVAL; 330 return -EINVAL;
308 return ret; 331 return ret;
309} 332}
310 333
311/* Name -> ID */ 334/* Name -> ID */
312static int nfs_idmap_lookup_id(const char *name, size_t namelen, 335static int nfs_idmap_lookup_id(const char *name, size_t namelen, const char *type,
313 const char *type, __u32 *id) 336 __u32 *id, struct idmap *idmap)
314{ 337{
315 char id_str[NFS_UINT_MAXLEN]; 338 char id_str[NFS_UINT_MAXLEN];
316 long id_long; 339 long id_long;
317 ssize_t data_size; 340 ssize_t data_size;
318 int ret = 0; 341 int ret = 0;
319 342
320 data_size = nfs_idmap_request_key(name, namelen, type, id_str, NFS_UINT_MAXLEN); 343 data_size = nfs_idmap_get_key(name, namelen, type, id_str, NFS_UINT_MAXLEN, idmap);
321 if (data_size <= 0) { 344 if (data_size <= 0) {
322 ret = -EINVAL; 345 ret = -EINVAL;
323 } else { 346 } else {
@@ -327,114 +350,103 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
327 return ret; 350 return ret;
328} 351}
329 352
330int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 353/* idmap classic begins here */
331{ 354module_param(nfs_idmap_cache_timeout, int, 0644);
332 if (nfs_map_string_to_numeric(name, namelen, uid))
333 return 0;
334 return nfs_idmap_lookup_id(name, namelen, "uid", uid);
335}
336
337int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
338{
339 if (nfs_map_string_to_numeric(name, namelen, gid))
340 return 0;
341 return nfs_idmap_lookup_id(name, namelen, "gid", gid);
342}
343
344int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
345{
346 int ret = -EINVAL;
347
348 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
349 ret = nfs_idmap_lookup_name(uid, "user", buf, buflen);
350 if (ret < 0)
351 ret = nfs_map_numeric_to_string(uid, buf, buflen);
352 return ret;
353}
354int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
355{
356 int ret = -EINVAL;
357 355
358 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 356struct idmap {
359 ret = nfs_idmap_lookup_name(gid, "group", buf, buflen); 357 struct rpc_pipe *idmap_pipe;
360 if (ret < 0) 358 struct key_construction *idmap_key_cons;
361 ret = nfs_map_numeric_to_string(gid, buf, buflen);
362 return ret;
363}
364
365#else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
366
367#include <linux/module.h>
368#include <linux/mutex.h>
369#include <linux/init.h>
370#include <linux/socket.h>
371#include <linux/in.h>
372#include <linux/sched.h>
373#include <linux/sunrpc/clnt.h>
374#include <linux/workqueue.h>
375#include <linux/sunrpc/rpc_pipe_fs.h>
376
377#include <linux/nfs_fs.h>
378
379#include "nfs4_fs.h"
380
381#define IDMAP_HASH_SZ 128
382
383/* Default cache timeout is 10 minutes */
384unsigned int nfs_idmap_cache_timeout = 600 * HZ;
385
386static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
387{
388 char *endp;
389 int num = simple_strtol(val, &endp, 0);
390 int jif = num * HZ;
391 if (endp == val || *endp || num < 0 || jif < num)
392 return -EINVAL;
393 *((int *)kp->arg) = jif;
394 return 0;
395}
396
397module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
398 &nfs_idmap_cache_timeout, 0644);
399
400struct idmap_hashent {
401 unsigned long ih_expires;
402 __u32 ih_id;
403 size_t ih_namelen;
404 char ih_name[IDMAP_NAMESZ];
405}; 359};
406 360
407struct idmap_hashtable { 361enum {
408 __u8 h_type; 362 Opt_find_uid, Opt_find_gid, Opt_find_user, Opt_find_group, Opt_find_err
409 struct idmap_hashent h_entries[IDMAP_HASH_SZ];
410}; 363};
411 364
412struct idmap { 365static const match_table_t nfs_idmap_tokens = {
413 struct dentry *idmap_dentry; 366 { Opt_find_uid, "uid:%s" },
414 wait_queue_head_t idmap_wq; 367 { Opt_find_gid, "gid:%s" },
415 struct idmap_msg idmap_im; 368 { Opt_find_user, "user:%s" },
416 struct mutex idmap_lock; /* Serializes upcalls */ 369 { Opt_find_group, "group:%s" },
417 struct mutex idmap_im_lock; /* Protects the hashtable */ 370 { Opt_find_err, NULL }
418 struct idmap_hashtable idmap_user_hash;
419 struct idmap_hashtable idmap_group_hash;
420}; 371};
421 372
373static int nfs_idmap_legacy_upcall(struct key_construction *, const char *, void *);
422static ssize_t idmap_pipe_downcall(struct file *, const char __user *, 374static ssize_t idmap_pipe_downcall(struct file *, const char __user *,
423 size_t); 375 size_t);
424static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *); 376static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *);
425 377
426static unsigned int fnvhash32(const void *, size_t);
427
428static const struct rpc_pipe_ops idmap_upcall_ops = { 378static const struct rpc_pipe_ops idmap_upcall_ops = {
429 .upcall = rpc_pipe_generic_upcall, 379 .upcall = rpc_pipe_generic_upcall,
430 .downcall = idmap_pipe_downcall, 380 .downcall = idmap_pipe_downcall,
431 .destroy_msg = idmap_pipe_destroy_msg, 381 .destroy_msg = idmap_pipe_destroy_msg,
432}; 382};
433 383
384static struct key_type key_type_id_resolver_legacy = {
385 .name = "id_resolver",
386 .instantiate = user_instantiate,
387 .match = user_match,
388 .revoke = user_revoke,
389 .destroy = user_destroy,
390 .describe = user_describe,
391 .read = user_read,
392 .request_key = nfs_idmap_legacy_upcall,
393};
394
395static void __nfs_idmap_unregister(struct rpc_pipe *pipe)
396{
397 if (pipe->dentry)
398 rpc_unlink(pipe->dentry);
399}
400
401static int __nfs_idmap_register(struct dentry *dir,
402 struct idmap *idmap,
403 struct rpc_pipe *pipe)
404{
405 struct dentry *dentry;
406
407 dentry = rpc_mkpipe_dentry(dir, "idmap", idmap, pipe);
408 if (IS_ERR(dentry))
409 return PTR_ERR(dentry);
410 pipe->dentry = dentry;
411 return 0;
412}
413
414static void nfs_idmap_unregister(struct nfs_client *clp,
415 struct rpc_pipe *pipe)
416{
417 struct net *net = clp->net;
418 struct super_block *pipefs_sb;
419
420 pipefs_sb = rpc_get_sb_net(net);
421 if (pipefs_sb) {
422 __nfs_idmap_unregister(pipe);
423 rpc_put_sb_net(net);
424 }
425}
426
427static int nfs_idmap_register(struct nfs_client *clp,
428 struct idmap *idmap,
429 struct rpc_pipe *pipe)
430{
431 struct net *net = clp->net;
432 struct super_block *pipefs_sb;
433 int err = 0;
434
435 pipefs_sb = rpc_get_sb_net(net);
436 if (pipefs_sb) {
437 if (clp->cl_rpcclient->cl_dentry)
438 err = __nfs_idmap_register(clp->cl_rpcclient->cl_dentry,
439 idmap, pipe);
440 rpc_put_sb_net(net);
441 }
442 return err;
443}
444
434int 445int
435nfs_idmap_new(struct nfs_client *clp) 446nfs_idmap_new(struct nfs_client *clp)
436{ 447{
437 struct idmap *idmap; 448 struct idmap *idmap;
449 struct rpc_pipe *pipe;
438 int error; 450 int error;
439 451
440 BUG_ON(clp->cl_idmap != NULL); 452 BUG_ON(clp->cl_idmap != NULL);
@@ -443,19 +455,19 @@ nfs_idmap_new(struct nfs_client *clp)
443 if (idmap == NULL) 455 if (idmap == NULL)
444 return -ENOMEM; 456 return -ENOMEM;
445 457
446 idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_path.dentry, 458 pipe = rpc_mkpipe_data(&idmap_upcall_ops, 0);
447 "idmap", idmap, &idmap_upcall_ops, 0); 459 if (IS_ERR(pipe)) {
448 if (IS_ERR(idmap->idmap_dentry)) { 460 error = PTR_ERR(pipe);
449 error = PTR_ERR(idmap->idmap_dentry);
450 kfree(idmap); 461 kfree(idmap);
451 return error; 462 return error;
452 } 463 }
453 464 error = nfs_idmap_register(clp, idmap, pipe);
454 mutex_init(&idmap->idmap_lock); 465 if (error) {
455 mutex_init(&idmap->idmap_im_lock); 466 rpc_destroy_pipe_data(pipe);
456 init_waitqueue_head(&idmap->idmap_wq); 467 kfree(idmap);
457 idmap->idmap_user_hash.h_type = IDMAP_TYPE_USER; 468 return error;
458 idmap->idmap_group_hash.h_type = IDMAP_TYPE_GROUP; 469 }
470 idmap->idmap_pipe = pipe;
459 471
460 clp->cl_idmap = idmap; 472 clp->cl_idmap = idmap;
461 return 0; 473 return 0;
@@ -468,211 +480,220 @@ nfs_idmap_delete(struct nfs_client *clp)
468 480
469 if (!idmap) 481 if (!idmap)
470 return; 482 return;
471 rpc_unlink(idmap->idmap_dentry); 483 nfs_idmap_unregister(clp, idmap->idmap_pipe);
484 rpc_destroy_pipe_data(idmap->idmap_pipe);
472 clp->cl_idmap = NULL; 485 clp->cl_idmap = NULL;
473 kfree(idmap); 486 kfree(idmap);
474} 487}
475 488
476/* 489static int __rpc_pipefs_event(struct nfs_client *clp, unsigned long event,
477 * Helper routines for manipulating the hashtable 490 struct super_block *sb)
478 */
479static inline struct idmap_hashent *
480idmap_name_hash(struct idmap_hashtable* h, const char *name, size_t len)
481{
482 return &h->h_entries[fnvhash32(name, len) % IDMAP_HASH_SZ];
483}
484
485static struct idmap_hashent *
486idmap_lookup_name(struct idmap_hashtable *h, const char *name, size_t len)
487{ 491{
488 struct idmap_hashent *he = idmap_name_hash(h, name, len); 492 int err = 0;
489 493
490 if (he->ih_namelen != len || memcmp(he->ih_name, name, len) != 0) 494 switch (event) {
491 return NULL; 495 case RPC_PIPEFS_MOUNT:
492 if (time_after(jiffies, he->ih_expires)) 496 BUG_ON(clp->cl_rpcclient->cl_dentry == NULL);
493 return NULL; 497 err = __nfs_idmap_register(clp->cl_rpcclient->cl_dentry,
494 return he; 498 clp->cl_idmap,
499 clp->cl_idmap->idmap_pipe);
500 break;
501 case RPC_PIPEFS_UMOUNT:
502 if (clp->cl_idmap->idmap_pipe) {
503 struct dentry *parent;
504
505 parent = clp->cl_idmap->idmap_pipe->dentry->d_parent;
506 __nfs_idmap_unregister(clp->cl_idmap->idmap_pipe);
507 /*
508 * Note: This is a dirty hack. SUNRPC hook has been
509 * called already but simple_rmdir() call for the
510 * directory returned with error because of idmap pipe
511 * inside. Thus now we have to remove this directory
512 * here.
513 */
514 if (rpc_rmdir(parent))
515 printk(KERN_ERR "NFS: %s: failed to remove "
516 "clnt dir!\n", __func__);
517 }
518 break;
519 default:
520 printk(KERN_ERR "NFS: %s: unknown event: %ld\n", __func__,
521 event);
522 return -ENOTSUPP;
523 }
524 return err;
525}
526
527static struct nfs_client *nfs_get_client_for_event(struct net *net, int event)
528{
529 struct nfs_net *nn = net_generic(net, nfs_net_id);
530 struct dentry *cl_dentry;
531 struct nfs_client *clp;
532
533 spin_lock(&nn->nfs_client_lock);
534 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
535 if (clp->rpc_ops != &nfs_v4_clientops)
536 continue;
537 cl_dentry = clp->cl_idmap->idmap_pipe->dentry;
538 if (((event == RPC_PIPEFS_MOUNT) && cl_dentry) ||
539 ((event == RPC_PIPEFS_UMOUNT) && !cl_dentry))
540 continue;
541 atomic_inc(&clp->cl_count);
542 spin_unlock(&nn->nfs_client_lock);
543 return clp;
544 }
545 spin_unlock(&nn->nfs_client_lock);
546 return NULL;
495} 547}
496 548
497static inline struct idmap_hashent * 549static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
498idmap_id_hash(struct idmap_hashtable* h, __u32 id) 550 void *ptr)
499{ 551{
500 return &h->h_entries[fnvhash32(&id, sizeof(id)) % IDMAP_HASH_SZ]; 552 struct super_block *sb = ptr;
501} 553 struct nfs_client *clp;
554 int error = 0;
502 555
503static struct idmap_hashent * 556 while ((clp = nfs_get_client_for_event(sb->s_fs_info, event))) {
504idmap_lookup_id(struct idmap_hashtable *h, __u32 id) 557 error = __rpc_pipefs_event(clp, event, sb);
505{ 558 nfs_put_client(clp);
506 struct idmap_hashent *he = idmap_id_hash(h, id); 559 if (error)
507 if (he->ih_id != id || he->ih_namelen == 0) 560 break;
508 return NULL; 561 }
509 if (time_after(jiffies, he->ih_expires)) 562 return error;
510 return NULL;
511 return he;
512} 563}
513 564
514/* 565#define PIPEFS_NFS_PRIO 1
515 * Routines for allocating new entries in the hashtable. 566
516 * For now, we just have 1 entry per bucket, so it's all 567static struct notifier_block nfs_idmap_block = {
517 * pretty trivial. 568 .notifier_call = rpc_pipefs_event,
518 */ 569 .priority = SUNRPC_PIPEFS_NFS_PRIO,
519static inline struct idmap_hashent * 570};
520idmap_alloc_name(struct idmap_hashtable *h, char *name, size_t len)
521{
522 return idmap_name_hash(h, name, len);
523}
524 571
525static inline struct idmap_hashent * 572int nfs_idmap_init(void)
526idmap_alloc_id(struct idmap_hashtable *h, __u32 id)
527{ 573{
528 return idmap_id_hash(h, id); 574 int ret;
575 ret = nfs_idmap_init_keyring();
576 if (ret != 0)
577 goto out;
578 ret = rpc_pipefs_notifier_register(&nfs_idmap_block);
579 if (ret != 0)
580 nfs_idmap_quit_keyring();
581out:
582 return ret;
529} 583}
530 584
531static void 585void nfs_idmap_quit(void)
532idmap_update_entry(struct idmap_hashent *he, const char *name,
533 size_t namelen, __u32 id)
534{ 586{
535 he->ih_id = id; 587 rpc_pipefs_notifier_unregister(&nfs_idmap_block);
536 memcpy(he->ih_name, name, namelen); 588 nfs_idmap_quit_keyring();
537 he->ih_name[namelen] = '\0';
538 he->ih_namelen = namelen;
539 he->ih_expires = jiffies + nfs_idmap_cache_timeout;
540} 589}
541 590
542/* 591static int nfs_idmap_prepare_message(char *desc, struct idmap_msg *im,
543 * Name -> ID 592 struct rpc_pipe_msg *msg)
544 */
545static int
546nfs_idmap_id(struct idmap *idmap, struct idmap_hashtable *h,
547 const char *name, size_t namelen, __u32 *id)
548{ 593{
549 struct rpc_pipe_msg msg; 594 substring_t substr;
550 struct idmap_msg *im; 595 int token, ret;
551 struct idmap_hashent *he;
552 DECLARE_WAITQUEUE(wq, current);
553 int ret = -EIO;
554
555 im = &idmap->idmap_im;
556
557 /*
558 * String sanity checks
559 * Note that the userland daemon expects NUL terminated strings
560 */
561 for (;;) {
562 if (namelen == 0)
563 return -EINVAL;
564 if (name[namelen-1] != '\0')
565 break;
566 namelen--;
567 }
568 if (namelen >= IDMAP_NAMESZ)
569 return -EINVAL;
570 596
571 mutex_lock(&idmap->idmap_lock); 597 memset(im, 0, sizeof(*im));
572 mutex_lock(&idmap->idmap_im_lock); 598 memset(msg, 0, sizeof(*msg));
573
574 he = idmap_lookup_name(h, name, namelen);
575 if (he != NULL) {
576 *id = he->ih_id;
577 ret = 0;
578 goto out;
579 }
580 599
581 memset(im, 0, sizeof(*im)); 600 im->im_type = IDMAP_TYPE_GROUP;
582 memcpy(im->im_name, name, namelen); 601 token = match_token(desc, nfs_idmap_tokens, &substr);
583 602
584 im->im_type = h->h_type; 603 switch (token) {
585 im->im_conv = IDMAP_CONV_NAMETOID; 604 case Opt_find_uid:
605 im->im_type = IDMAP_TYPE_USER;
606 case Opt_find_gid:
607 im->im_conv = IDMAP_CONV_NAMETOID;
608 ret = match_strlcpy(im->im_name, &substr, IDMAP_NAMESZ);
609 break;
586 610
587 memset(&msg, 0, sizeof(msg)); 611 case Opt_find_user:
588 msg.data = im; 612 im->im_type = IDMAP_TYPE_USER;
589 msg.len = sizeof(*im); 613 case Opt_find_group:
614 im->im_conv = IDMAP_CONV_IDTONAME;
615 ret = match_int(&substr, &im->im_id);
616 break;
590 617
591 add_wait_queue(&idmap->idmap_wq, &wq); 618 default:
592 if (rpc_queue_upcall(idmap->idmap_dentry->d_inode, &msg) < 0) { 619 ret = -EINVAL;
593 remove_wait_queue(&idmap->idmap_wq, &wq);
594 goto out; 620 goto out;
595 } 621 }
596 622
597 set_current_state(TASK_UNINTERRUPTIBLE); 623 msg->data = im;
598 mutex_unlock(&idmap->idmap_im_lock); 624 msg->len = sizeof(struct idmap_msg);
599 schedule();
600 __set_current_state(TASK_RUNNING);
601 remove_wait_queue(&idmap->idmap_wq, &wq);
602 mutex_lock(&idmap->idmap_im_lock);
603 625
604 if (im->im_status & IDMAP_STATUS_SUCCESS) { 626out:
605 *id = im->im_id;
606 ret = 0;
607 }
608
609 out:
610 memset(im, 0, sizeof(*im));
611 mutex_unlock(&idmap->idmap_im_lock);
612 mutex_unlock(&idmap->idmap_lock);
613 return ret; 627 return ret;
614} 628}
615 629
616/* 630static int nfs_idmap_legacy_upcall(struct key_construction *cons,
617 * ID -> Name 631 const char *op,
618 */ 632 void *aux)
619static int
620nfs_idmap_name(struct idmap *idmap, struct idmap_hashtable *h,
621 __u32 id, char *name)
622{ 633{
623 struct rpc_pipe_msg msg; 634 struct rpc_pipe_msg *msg;
624 struct idmap_msg *im; 635 struct idmap_msg *im;
625 struct idmap_hashent *he; 636 struct idmap *idmap = (struct idmap *)aux;
626 DECLARE_WAITQUEUE(wq, current); 637 struct key *key = cons->key;
627 int ret = -EIO; 638 int ret;
628 unsigned int len;
629
630 im = &idmap->idmap_im;
631 639
632 mutex_lock(&idmap->idmap_lock); 640 /* msg and im are freed in idmap_pipe_destroy_msg */
633 mutex_lock(&idmap->idmap_im_lock); 641 msg = kmalloc(sizeof(*msg), GFP_KERNEL);
642 if (IS_ERR(msg)) {
643 ret = PTR_ERR(msg);
644 goto out0;
645 }
634 646
635 he = idmap_lookup_id(h, id); 647 im = kmalloc(sizeof(*im), GFP_KERNEL);
636 if (he) { 648 if (IS_ERR(im)) {
637 memcpy(name, he->ih_name, he->ih_namelen); 649 ret = PTR_ERR(im);
638 ret = he->ih_namelen; 650 goto out1;
639 goto out;
640 } 651 }
641 652
642 memset(im, 0, sizeof(*im)); 653 ret = nfs_idmap_prepare_message(key->description, im, msg);
643 im->im_type = h->h_type; 654 if (ret < 0)
644 im->im_conv = IDMAP_CONV_IDTONAME; 655 goto out2;
645 im->im_id = id;
646 656
647 memset(&msg, 0, sizeof(msg)); 657 idmap->idmap_key_cons = cons;
648 msg.data = im;
649 msg.len = sizeof(*im);
650 658
651 add_wait_queue(&idmap->idmap_wq, &wq); 659 ret = rpc_queue_upcall(idmap->idmap_pipe, msg);
660 if (ret < 0)
661 goto out2;
652 662
653 if (rpc_queue_upcall(idmap->idmap_dentry->d_inode, &msg) < 0) { 663 return ret;
654 remove_wait_queue(&idmap->idmap_wq, &wq); 664
655 goto out; 665out2:
656 } 666 kfree(im);
667out1:
668 kfree(msg);
669out0:
670 key_revoke(cons->key);
671 key_revoke(cons->authkey);
672 return ret;
673}
674
675static int nfs_idmap_instantiate(struct key *key, struct key *authkey, char *data)
676{
677 return key_instantiate_and_link(key, data, strlen(data) + 1,
678 id_resolver_cache->thread_keyring,
679 authkey);
680}
657 681
658 set_current_state(TASK_UNINTERRUPTIBLE); 682static int nfs_idmap_read_message(struct idmap_msg *im, struct key *key, struct key *authkey)
659 mutex_unlock(&idmap->idmap_im_lock); 683{
660 schedule(); 684 char id_str[NFS_UINT_MAXLEN];
661 __set_current_state(TASK_RUNNING); 685 int ret = -EINVAL;
662 remove_wait_queue(&idmap->idmap_wq, &wq); 686
663 mutex_lock(&idmap->idmap_im_lock); 687 switch (im->im_conv) {
664 688 case IDMAP_CONV_NAMETOID:
665 if (im->im_status & IDMAP_STATUS_SUCCESS) { 689 sprintf(id_str, "%d", im->im_id);
666 if ((len = strnlen(im->im_name, IDMAP_NAMESZ)) == 0) 690 ret = nfs_idmap_instantiate(key, authkey, id_str);
667 goto out; 691 break;
668 memcpy(name, im->im_name, len); 692 case IDMAP_CONV_IDTONAME:
669 ret = len; 693 ret = nfs_idmap_instantiate(key, authkey, im->im_name);
694 break;
670 } 695 }
671 696
672 out:
673 memset(im, 0, sizeof(*im));
674 mutex_unlock(&idmap->idmap_im_lock);
675 mutex_unlock(&idmap->idmap_lock);
676 return ret; 697 return ret;
677} 698}
678 699
@@ -681,115 +702,51 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
681{ 702{
682 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode); 703 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode);
683 struct idmap *idmap = (struct idmap *)rpci->private; 704 struct idmap *idmap = (struct idmap *)rpci->private;
684 struct idmap_msg im_in, *im = &idmap->idmap_im; 705 struct key_construction *cons = idmap->idmap_key_cons;
685 struct idmap_hashtable *h; 706 struct idmap_msg im;
686 struct idmap_hashent *he = NULL;
687 size_t namelen_in; 707 size_t namelen_in;
688 int ret; 708 int ret;
689 709
690 if (mlen != sizeof(im_in)) 710 if (mlen != sizeof(im)) {
691 return -ENOSPC; 711 ret = -ENOSPC;
692
693 if (copy_from_user(&im_in, src, mlen) != 0)
694 return -EFAULT;
695
696 mutex_lock(&idmap->idmap_im_lock);
697
698 ret = mlen;
699 im->im_status = im_in.im_status;
700 /* If we got an error, terminate now, and wake up pending upcalls */
701 if (!(im_in.im_status & IDMAP_STATUS_SUCCESS)) {
702 wake_up(&idmap->idmap_wq);
703 goto out; 712 goto out;
704 } 713 }
705 714
706 /* Sanity checking of strings */ 715 if (copy_from_user(&im, src, mlen) != 0) {
707 ret = -EINVAL; 716 ret = -EFAULT;
708 namelen_in = strnlen(im_in.im_name, IDMAP_NAMESZ);
709 if (namelen_in == 0 || namelen_in == IDMAP_NAMESZ)
710 goto out; 717 goto out;
718 }
711 719
712 switch (im_in.im_type) { 720 if (!(im.im_status & IDMAP_STATUS_SUCCESS)) {
713 case IDMAP_TYPE_USER: 721 ret = mlen;
714 h = &idmap->idmap_user_hash; 722 complete_request_key(idmap->idmap_key_cons, -ENOKEY);
715 break; 723 goto out_incomplete;
716 case IDMAP_TYPE_GROUP:
717 h = &idmap->idmap_group_hash;
718 break;
719 default:
720 goto out;
721 } 724 }
722 725
723 switch (im_in.im_conv) { 726 namelen_in = strnlen(im.im_name, IDMAP_NAMESZ);
724 case IDMAP_CONV_IDTONAME: 727 if (namelen_in == 0 || namelen_in == IDMAP_NAMESZ) {
725 /* Did we match the current upcall? */ 728 ret = -EINVAL;
726 if (im->im_conv == IDMAP_CONV_IDTONAME
727 && im->im_type == im_in.im_type
728 && im->im_id == im_in.im_id) {
729 /* Yes: copy string, including the terminating '\0' */
730 memcpy(im->im_name, im_in.im_name, namelen_in);
731 im->im_name[namelen_in] = '\0';
732 wake_up(&idmap->idmap_wq);
733 }
734 he = idmap_alloc_id(h, im_in.im_id);
735 break;
736 case IDMAP_CONV_NAMETOID:
737 /* Did we match the current upcall? */
738 if (im->im_conv == IDMAP_CONV_NAMETOID
739 && im->im_type == im_in.im_type
740 && strnlen(im->im_name, IDMAP_NAMESZ) == namelen_in
741 && memcmp(im->im_name, im_in.im_name, namelen_in) == 0) {
742 im->im_id = im_in.im_id;
743 wake_up(&idmap->idmap_wq);
744 }
745 he = idmap_alloc_name(h, im_in.im_name, namelen_in);
746 break;
747 default:
748 goto out; 729 goto out;
749 } 730 }
750 731
751 /* If the entry is valid, also copy it to the cache */ 732 ret = nfs_idmap_read_message(&im, cons->key, cons->authkey);
752 if (he != NULL) 733 if (ret >= 0) {
753 idmap_update_entry(he, im_in.im_name, namelen_in, im_in.im_id); 734 key_set_timeout(cons->key, nfs_idmap_cache_timeout);
754 ret = mlen; 735 ret = mlen;
736 }
737
755out: 738out:
756 mutex_unlock(&idmap->idmap_im_lock); 739 complete_request_key(idmap->idmap_key_cons, ret);
740out_incomplete:
757 return ret; 741 return ret;
758} 742}
759 743
760static void 744static void
761idmap_pipe_destroy_msg(struct rpc_pipe_msg *msg) 745idmap_pipe_destroy_msg(struct rpc_pipe_msg *msg)
762{ 746{
763 struct idmap_msg *im = msg->data; 747 /* Free memory allocated in nfs_idmap_legacy_upcall() */
764 struct idmap *idmap = container_of(im, struct idmap, idmap_im); 748 kfree(msg->data);
765 749 kfree(msg);
766 if (msg->errno >= 0)
767 return;
768 mutex_lock(&idmap->idmap_im_lock);
769 im->im_status = IDMAP_STATUS_LOOKUPFAIL;
770 wake_up(&idmap->idmap_wq);
771 mutex_unlock(&idmap->idmap_im_lock);
772}
773
774/*
775 * Fowler/Noll/Vo hash
776 * http://www.isthe.com/chongo/tech/comp/fnv/
777 */
778
779#define FNV_P_32 ((unsigned int)0x01000193) /* 16777619 */
780#define FNV_1_32 ((unsigned int)0x811c9dc5) /* 2166136261 */
781
782static unsigned int fnvhash32(const void *buf, size_t buflen)
783{
784 const unsigned char *p, *end = (const unsigned char *)buf + buflen;
785 unsigned int hash = FNV_1_32;
786
787 for (p = buf; p < end; p++) {
788 hash *= FNV_P_32;
789 hash ^= (unsigned int)*p;
790 }
791
792 return hash;
793} 750}
794 751
795int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 752int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid)
@@ -798,16 +755,16 @@ int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_
798 755
799 if (nfs_map_string_to_numeric(name, namelen, uid)) 756 if (nfs_map_string_to_numeric(name, namelen, uid))
800 return 0; 757 return 0;
801 return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid); 758 return nfs_idmap_lookup_id(name, namelen, "uid", uid, idmap);
802} 759}
803 760
804int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 761int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
805{ 762{
806 struct idmap *idmap = server->nfs_client->cl_idmap; 763 struct idmap *idmap = server->nfs_client->cl_idmap;
807 764
808 if (nfs_map_string_to_numeric(name, namelen, uid)) 765 if (nfs_map_string_to_numeric(name, namelen, gid))
809 return 0; 766 return 0;
810 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid); 767 return nfs_idmap_lookup_id(name, namelen, "gid", gid, idmap);
811} 768}
812 769
813int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) 770int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
@@ -816,21 +773,19 @@ int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, s
816 int ret = -EINVAL; 773 int ret = -EINVAL;
817 774
818 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 775 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
819 ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); 776 ret = nfs_idmap_lookup_name(uid, "user", buf, buflen, idmap);
820 if (ret < 0) 777 if (ret < 0)
821 ret = nfs_map_numeric_to_string(uid, buf, buflen); 778 ret = nfs_map_numeric_to_string(uid, buf, buflen);
822 return ret; 779 return ret;
823} 780}
824int nfs_map_gid_to_group(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) 781int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
825{ 782{
826 struct idmap *idmap = server->nfs_client->cl_idmap; 783 struct idmap *idmap = server->nfs_client->cl_idmap;
827 int ret = -EINVAL; 784 int ret = -EINVAL;
828 785
829 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 786 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
830 ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); 787 ret = nfs_idmap_lookup_name(gid, "group", buf, buflen, idmap);
831 if (ret < 0) 788 if (ret < 0)
832 ret = nfs_map_numeric_to_string(uid, buf, buflen); 789 ret = nfs_map_numeric_to_string(gid, buf, buflen);
833 return ret; 790 return ret;
834} 791}
835
836#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index f649fba8c384..7bb4d13c1cd5 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -39,6 +39,7 @@
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/compat.h> 40#include <linux/compat.h>
41#include <linux/freezer.h> 41#include <linux/freezer.h>
42#include <linux/crc32.h>
42 43
43#include <asm/system.h> 44#include <asm/system.h>
44#include <asm/uaccess.h> 45#include <asm/uaccess.h>
@@ -51,6 +52,7 @@
51#include "fscache.h" 52#include "fscache.h"
52#include "dns_resolve.h" 53#include "dns_resolve.h"
53#include "pnfs.h" 54#include "pnfs.h"
55#include "netns.h"
54 56
55#define NFSDBG_FACILITY NFSDBG_VFS 57#define NFSDBG_FACILITY NFSDBG_VFS
56 58
@@ -388,9 +390,10 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
388 unlock_new_inode(inode); 390 unlock_new_inode(inode);
389 } else 391 } else
390 nfs_refresh_inode(inode, fattr); 392 nfs_refresh_inode(inode, fattr);
391 dprintk("NFS: nfs_fhget(%s/%Ld ct=%d)\n", 393 dprintk("NFS: nfs_fhget(%s/%Ld fh_crc=0x%08x ct=%d)\n",
392 inode->i_sb->s_id, 394 inode->i_sb->s_id,
393 (long long)NFS_FILEID(inode), 395 (long long)NFS_FILEID(inode),
396 nfs_display_fhandle_hash(fh),
394 atomic_read(&inode->i_count)); 397 atomic_read(&inode->i_count));
395 398
396out: 399out:
@@ -401,7 +404,7 @@ out_no_inode:
401 goto out; 404 goto out;
402} 405}
403 406
404#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE) 407#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE|ATTR_OPEN)
405 408
406int 409int
407nfs_setattr(struct dentry *dentry, struct iattr *attr) 410nfs_setattr(struct dentry *dentry, struct iattr *attr)
@@ -423,7 +426,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
423 426
424 /* Optimization: if the end result is no change, don't RPC */ 427 /* Optimization: if the end result is no change, don't RPC */
425 attr->ia_valid &= NFS_VALID_ATTRS; 428 attr->ia_valid &= NFS_VALID_ATTRS;
426 if ((attr->ia_valid & ~ATTR_FILE) == 0) 429 if ((attr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0)
427 return 0; 430 return 0;
428 431
429 /* Write all dirty data */ 432 /* Write all dirty data */
@@ -1044,6 +1047,67 @@ struct nfs_fh *nfs_alloc_fhandle(void)
1044 return fh; 1047 return fh;
1045} 1048}
1046 1049
1050#ifdef NFS_DEBUG
1051/*
1052 * _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
1053 * in the same way that wireshark does
1054 *
1055 * @fh: file handle
1056 *
1057 * For debugging only.
1058 */
1059u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
1060{
1061 /* wireshark uses 32-bit AUTODIN crc and does a bitwise
1062 * not on the result */
1063 return ~crc32(0xFFFFFFFF, &fh->data[0], fh->size);
1064}
1065
1066/*
1067 * _nfs_display_fhandle - display an NFS file handle on the console
1068 *
1069 * @fh: file handle to display
1070 * @caption: display caption
1071 *
1072 * For debugging only.
1073 */
1074void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
1075{
1076 unsigned short i;
1077
1078 if (fh == NULL || fh->size == 0) {
1079 printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh);
1080 return;
1081 }
1082
1083 printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
1084 caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
1085 for (i = 0; i < fh->size; i += 16) {
1086 __be32 *pos = (__be32 *)&fh->data[i];
1087
1088 switch ((fh->size - i - 1) >> 2) {
1089 case 0:
1090 printk(KERN_DEFAULT " %08x\n",
1091 be32_to_cpup(pos));
1092 break;
1093 case 1:
1094 printk(KERN_DEFAULT " %08x %08x\n",
1095 be32_to_cpup(pos), be32_to_cpup(pos + 1));
1096 break;
1097 case 2:
1098 printk(KERN_DEFAULT " %08x %08x %08x\n",
1099 be32_to_cpup(pos), be32_to_cpup(pos + 1),
1100 be32_to_cpup(pos + 2));
1101 break;
1102 default:
1103 printk(KERN_DEFAULT " %08x %08x %08x %08x\n",
1104 be32_to_cpup(pos), be32_to_cpup(pos + 1),
1105 be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
1106 }
1107 }
1108}
1109#endif
1110
1047/** 1111/**
1048 * nfs_inode_attrs_need_update - check if the inode attributes need updating 1112 * nfs_inode_attrs_need_update - check if the inode attributes need updating
1049 * @inode - pointer to inode 1113 * @inode - pointer to inode
@@ -1211,8 +1275,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1211 unsigned long now = jiffies; 1275 unsigned long now = jiffies;
1212 unsigned long save_cache_validity; 1276 unsigned long save_cache_validity;
1213 1277
1214 dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", 1278 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
1215 __func__, inode->i_sb->s_id, inode->i_ino, 1279 __func__, inode->i_sb->s_id, inode->i_ino,
1280 nfs_display_fhandle_hash(NFS_FH(inode)),
1216 atomic_read(&inode->i_count), fattr->valid); 1281 atomic_read(&inode->i_count), fattr->valid);
1217 1282
1218 if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid) 1283 if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid)
@@ -1406,7 +1471,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1406 /* 1471 /*
1407 * Big trouble! The inode has become a different object. 1472 * Big trouble! The inode has become a different object.
1408 */ 1473 */
1409 printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n", 1474 printk(KERN_DEBUG "NFS: %s: inode %ld mode changed, %07o to %07o\n",
1410 __func__, inode->i_ino, inode->i_mode, fattr->mode); 1475 __func__, inode->i_ino, inode->i_mode, fattr->mode);
1411 out_err: 1476 out_err:
1412 /* 1477 /*
@@ -1495,7 +1560,7 @@ static void init_once(void *foo)
1495 INIT_LIST_HEAD(&nfsi->open_files); 1560 INIT_LIST_HEAD(&nfsi->open_files);
1496 INIT_LIST_HEAD(&nfsi->access_cache_entry_lru); 1561 INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
1497 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru); 1562 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
1498 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC); 1563 INIT_LIST_HEAD(&nfsi->commit_list);
1499 nfsi->npages = 0; 1564 nfsi->npages = 0;
1500 nfsi->ncommit = 0; 1565 nfsi->ncommit = 0;
1501 atomic_set(&nfsi->silly_count, 1); 1566 atomic_set(&nfsi->silly_count, 1);
@@ -1552,6 +1617,28 @@ static void nfsiod_stop(void)
1552 destroy_workqueue(wq); 1617 destroy_workqueue(wq);
1553} 1618}
1554 1619
1620int nfs_net_id;
1621EXPORT_SYMBOL_GPL(nfs_net_id);
1622
1623static int nfs_net_init(struct net *net)
1624{
1625 nfs_clients_init(net);
1626 return nfs_dns_resolver_cache_init(net);
1627}
1628
1629static void nfs_net_exit(struct net *net)
1630{
1631 nfs_dns_resolver_cache_destroy(net);
1632 nfs_cleanup_cb_ident_idr(net);
1633}
1634
1635static struct pernet_operations nfs_net_ops = {
1636 .init = nfs_net_init,
1637 .exit = nfs_net_exit,
1638 .id = &nfs_net_id,
1639 .size = sizeof(struct nfs_net),
1640};
1641
1555/* 1642/*
1556 * Initialize NFS 1643 * Initialize NFS
1557 */ 1644 */
@@ -1561,10 +1648,14 @@ static int __init init_nfs_fs(void)
1561 1648
1562 err = nfs_idmap_init(); 1649 err = nfs_idmap_init();
1563 if (err < 0) 1650 if (err < 0)
1564 goto out9; 1651 goto out10;
1565 1652
1566 err = nfs_dns_resolver_init(); 1653 err = nfs_dns_resolver_init();
1567 if (err < 0) 1654 if (err < 0)
1655 goto out9;
1656
1657 err = register_pernet_subsys(&nfs_net_ops);
1658 if (err < 0)
1568 goto out8; 1659 goto out8;
1569 1660
1570 err = nfs_fscache_register(); 1661 err = nfs_fscache_register();
@@ -1600,14 +1691,14 @@ static int __init init_nfs_fs(void)
1600 goto out0; 1691 goto out0;
1601 1692
1602#ifdef CONFIG_PROC_FS 1693#ifdef CONFIG_PROC_FS
1603 rpc_proc_register(&nfs_rpcstat); 1694 rpc_proc_register(&init_net, &nfs_rpcstat);
1604#endif 1695#endif
1605 if ((err = register_nfs_fs()) != 0) 1696 if ((err = register_nfs_fs()) != 0)
1606 goto out; 1697 goto out;
1607 return 0; 1698 return 0;
1608out: 1699out:
1609#ifdef CONFIG_PROC_FS 1700#ifdef CONFIG_PROC_FS
1610 rpc_proc_unregister("nfs"); 1701 rpc_proc_unregister(&init_net, "nfs");
1611#endif 1702#endif
1612 nfs_destroy_directcache(); 1703 nfs_destroy_directcache();
1613out0: 1704out0:
@@ -1625,10 +1716,12 @@ out5:
1625out6: 1716out6:
1626 nfs_fscache_unregister(); 1717 nfs_fscache_unregister();
1627out7: 1718out7:
1628 nfs_dns_resolver_destroy(); 1719 unregister_pernet_subsys(&nfs_net_ops);
1629out8: 1720out8:
1630 nfs_idmap_quit(); 1721 nfs_dns_resolver_destroy();
1631out9: 1722out9:
1723 nfs_idmap_quit();
1724out10:
1632 return err; 1725 return err;
1633} 1726}
1634 1727
@@ -1640,12 +1733,12 @@ static void __exit exit_nfs_fs(void)
1640 nfs_destroy_inodecache(); 1733 nfs_destroy_inodecache();
1641 nfs_destroy_nfspagecache(); 1734 nfs_destroy_nfspagecache();
1642 nfs_fscache_unregister(); 1735 nfs_fscache_unregister();
1736 unregister_pernet_subsys(&nfs_net_ops);
1643 nfs_dns_resolver_destroy(); 1737 nfs_dns_resolver_destroy();
1644 nfs_idmap_quit(); 1738 nfs_idmap_quit();
1645#ifdef CONFIG_PROC_FS 1739#ifdef CONFIG_PROC_FS
1646 rpc_proc_unregister("nfs"); 1740 rpc_proc_unregister(&init_net, "nfs");
1647#endif 1741#endif
1648 nfs_cleanup_cb_ident_idr();
1649 unregister_nfs_fs(); 1742 unregister_nfs_fs();
1650 nfs_fs_proc_exit(); 1743 nfs_fs_proc_exit();
1651 nfsiod_stop(); 1744 nfsiod_stop();
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 8102db9b926c..2476dc69365f 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -123,6 +123,7 @@ struct nfs_parsed_mount_data {
123 } nfs_server; 123 } nfs_server;
124 124
125 struct security_mnt_opts lsm_opts; 125 struct security_mnt_opts lsm_opts;
126 struct net *net;
126}; 127};
127 128
128/* mount_clnt.c */ 129/* mount_clnt.c */
@@ -137,20 +138,22 @@ struct nfs_mount_request {
137 int noresvport; 138 int noresvport;
138 unsigned int *auth_flav_len; 139 unsigned int *auth_flav_len;
139 rpc_authflavor_t *auth_flavs; 140 rpc_authflavor_t *auth_flavs;
141 struct net *net;
140}; 142};
141 143
142extern int nfs_mount(struct nfs_mount_request *info); 144extern int nfs_mount(struct nfs_mount_request *info);
143extern void nfs_umount(const struct nfs_mount_request *info); 145extern void nfs_umount(const struct nfs_mount_request *info);
144 146
145/* client.c */ 147/* client.c */
146extern struct rpc_program nfs_program; 148extern const struct rpc_program nfs_program;
149extern void nfs_clients_init(struct net *net);
147 150
148extern void nfs_cleanup_cb_ident_idr(void); 151extern void nfs_cleanup_cb_ident_idr(struct net *);
149extern void nfs_put_client(struct nfs_client *); 152extern void nfs_put_client(struct nfs_client *);
150extern struct nfs_client *nfs4_find_client_no_ident(const struct sockaddr *); 153extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
151extern struct nfs_client *nfs4_find_client_ident(int);
152extern struct nfs_client * 154extern struct nfs_client *
153nfs4_find_client_sessionid(const struct sockaddr *, struct nfs4_sessionid *); 155nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
156 struct nfs4_sessionid *);
154extern struct nfs_server *nfs_create_server( 157extern struct nfs_server *nfs_create_server(
155 const struct nfs_parsed_mount_data *, 158 const struct nfs_parsed_mount_data *,
156 struct nfs_fh *); 159 struct nfs_fh *);
@@ -329,6 +332,8 @@ void nfs_retry_commit(struct list_head *page_list,
329void nfs_commit_clear_lock(struct nfs_inode *nfsi); 332void nfs_commit_clear_lock(struct nfs_inode *nfsi);
330void nfs_commitdata_release(void *data); 333void nfs_commitdata_release(void *data);
331void nfs_commit_release_pages(struct nfs_write_data *data); 334void nfs_commit_release_pages(struct nfs_write_data *data);
335void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *head);
336void nfs_request_remove_commit_list(struct nfs_page *req);
332 337
333#ifdef CONFIG_MIGRATION 338#ifdef CONFIG_MIGRATION
334extern int nfs_migrate_page(struct address_space *, 339extern int nfs_migrate_page(struct address_space *,
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c
index d4c2d6b7507e..8e65c7f1f87c 100644
--- a/fs/nfs/mount_clnt.c
+++ b/fs/nfs/mount_clnt.c
@@ -16,7 +16,7 @@
16#include <linux/nfs_fs.h> 16#include <linux/nfs_fs.h>
17#include "internal.h" 17#include "internal.h"
18 18
19#ifdef RPC_DEBUG 19#ifdef NFS_DEBUG
20# define NFSDBG_FACILITY NFSDBG_MOUNT 20# define NFSDBG_FACILITY NFSDBG_MOUNT
21#endif 21#endif
22 22
@@ -67,7 +67,7 @@ enum {
67 MOUNTPROC3_EXPORT = 5, 67 MOUNTPROC3_EXPORT = 5,
68}; 68};
69 69
70static struct rpc_program mnt_program; 70static const struct rpc_program mnt_program;
71 71
72/* 72/*
73 * Defined by OpenGroup XNFS Version 3W, chapter 8 73 * Defined by OpenGroup XNFS Version 3W, chapter 8
@@ -153,7 +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 .net = info->net,
157 .protocol = info->protocol, 157 .protocol = info->protocol,
158 .address = info->sap, 158 .address = info->sap,
159 .addrsize = info->salen, 159 .addrsize = info->salen,
@@ -225,7 +225,7 @@ void nfs_umount(const struct nfs_mount_request *info)
225 .to_retries = 2, 225 .to_retries = 2,
226 }; 226 };
227 struct rpc_create_args args = { 227 struct rpc_create_args args = {
228 .net = &init_net, 228 .net = info->net,
229 .protocol = IPPROTO_UDP, 229 .protocol = IPPROTO_UDP,
230 .address = info->sap, 230 .address = info->sap,
231 .addrsize = info->salen, 231 .addrsize = info->salen,
@@ -488,19 +488,19 @@ static struct rpc_procinfo mnt3_procedures[] = {
488}; 488};
489 489
490 490
491static struct rpc_version mnt_version1 = { 491static const struct rpc_version mnt_version1 = {
492 .number = 1, 492 .number = 1,
493 .nrprocs = ARRAY_SIZE(mnt_procedures), 493 .nrprocs = ARRAY_SIZE(mnt_procedures),
494 .procs = mnt_procedures, 494 .procs = mnt_procedures,
495}; 495};
496 496
497static struct rpc_version mnt_version3 = { 497static const struct rpc_version mnt_version3 = {
498 .number = 3, 498 .number = 3,
499 .nrprocs = ARRAY_SIZE(mnt3_procedures), 499 .nrprocs = ARRAY_SIZE(mnt3_procedures),
500 .procs = mnt3_procedures, 500 .procs = mnt3_procedures,
501}; 501};
502 502
503static struct rpc_version *mnt_version[] = { 503static const struct rpc_version *mnt_version[] = {
504 NULL, 504 NULL,
505 &mnt_version1, 505 &mnt_version1,
506 NULL, 506 NULL,
@@ -509,7 +509,7 @@ static struct rpc_version *mnt_version[] = {
509 509
510static struct rpc_stat mnt_stats; 510static struct rpc_stat mnt_stats;
511 511
512static struct rpc_program mnt_program = { 512static const struct rpc_program mnt_program = {
513 .name = "mount", 513 .name = "mount",
514 .number = NFS_MNT_PROGRAM, 514 .number = NFS_MNT_PROGRAM,
515 .nrvers = ARRAY_SIZE(mnt_version), 515 .nrvers = ARRAY_SIZE(mnt_version),
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 8102391bb374..1807866bb3ab 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -276,7 +276,10 @@ out:
276 nfs_free_fattr(fattr); 276 nfs_free_fattr(fattr);
277 nfs_free_fhandle(fh); 277 nfs_free_fhandle(fh);
278out_nofree: 278out_nofree:
279 dprintk("<-- nfs_follow_mountpoint() = %p\n", mnt); 279 if (IS_ERR(mnt))
280 dprintk("<-- %s(): error %ld\n", __func__, PTR_ERR(mnt));
281 else
282 dprintk("<-- %s() = %p\n", __func__, mnt);
280 return mnt; 283 return mnt;
281} 284}
282 285
diff --git a/fs/nfs/netns.h b/fs/nfs/netns.h
new file mode 100644
index 000000000000..aa14ec303e94
--- /dev/null
+++ b/fs/nfs/netns.h
@@ -0,0 +1,27 @@
1#ifndef __NFS_NETNS_H__
2#define __NFS_NETNS_H__
3
4#include <net/net_namespace.h>
5#include <net/netns/generic.h>
6
7struct bl_dev_msg {
8 int32_t status;
9 uint32_t major, minor;
10};
11
12struct nfs_net {
13 struct cache_detail *nfs_dns_resolve;
14 struct rpc_pipe *bl_device_pipe;
15 struct bl_dev_msg bl_mount_reply;
16 wait_queue_head_t bl_wq;
17 struct list_head nfs_client_list;
18 struct list_head nfs_volume_list;
19#ifdef CONFIG_NFS_V4
20 struct idr cb_ident_idr; /* Protected by nfs_client_lock */
21#endif
22 spinlock_t nfs_client_lock;
23};
24
25extern int nfs_net_id;
26
27#endif
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index 792cb13a4304..1f56000fabbd 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -1150,7 +1150,7 @@ struct rpc_procinfo nfs_procedures[] = {
1150 PROC(STATFS, fhandle, statfsres, 0), 1150 PROC(STATFS, fhandle, statfsres, 0),
1151}; 1151};
1152 1152
1153struct rpc_version nfs_version2 = { 1153const struct rpc_version nfs_version2 = {
1154 .number = 2, 1154 .number = 2,
1155 .nrprocs = ARRAY_SIZE(nfs_procedures), 1155 .nrprocs = ARRAY_SIZE(nfs_procedures),
1156 .procs = nfs_procedures 1156 .procs = nfs_procedures
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 7ef23979896d..e4498dc351a8 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -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 0 195 NULL,
196 }; 196 };
197 struct rpc_message msg = { 197 struct rpc_message msg = {
198 .rpc_argp = &args, 198 .rpc_argp = &args,
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index 91943953a370..5242eae6711a 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -428,6 +428,11 @@ nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
428 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; 428 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
429} 429}
430 430
431static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
432{
433 rpc_call_start(task);
434}
435
431static int 436static int
432nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir) 437nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
433{ 438{
@@ -445,6 +450,11 @@ nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
445 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME]; 450 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
446} 451}
447 452
453static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
454{
455 rpc_call_start(task);
456}
457
448static int 458static int
449nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 459nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
450 struct inode *new_dir) 460 struct inode *new_dir)
@@ -814,6 +824,11 @@ static void nfs3_proc_read_setup(struct nfs_read_data *data, struct rpc_message
814 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ]; 824 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
815} 825}
816 826
827static void nfs3_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
828{
829 rpc_call_start(task);
830}
831
817static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data) 832static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
818{ 833{
819 if (nfs3_async_handle_jukebox(task, data->inode)) 834 if (nfs3_async_handle_jukebox(task, data->inode))
@@ -828,6 +843,11 @@ static void nfs3_proc_write_setup(struct nfs_write_data *data, struct rpc_messag
828 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE]; 843 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
829} 844}
830 845
846static void nfs3_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
847{
848 rpc_call_start(task);
849}
850
831static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data) 851static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
832{ 852{
833 if (nfs3_async_handle_jukebox(task, data->inode)) 853 if (nfs3_async_handle_jukebox(task, data->inode))
@@ -864,9 +884,11 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
864 .create = nfs3_proc_create, 884 .create = nfs3_proc_create,
865 .remove = nfs3_proc_remove, 885 .remove = nfs3_proc_remove,
866 .unlink_setup = nfs3_proc_unlink_setup, 886 .unlink_setup = nfs3_proc_unlink_setup,
887 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
867 .unlink_done = nfs3_proc_unlink_done, 888 .unlink_done = nfs3_proc_unlink_done,
868 .rename = nfs3_proc_rename, 889 .rename = nfs3_proc_rename,
869 .rename_setup = nfs3_proc_rename_setup, 890 .rename_setup = nfs3_proc_rename_setup,
891 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
870 .rename_done = nfs3_proc_rename_done, 892 .rename_done = nfs3_proc_rename_done,
871 .link = nfs3_proc_link, 893 .link = nfs3_proc_link,
872 .symlink = nfs3_proc_symlink, 894 .symlink = nfs3_proc_symlink,
@@ -879,8 +901,10 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
879 .pathconf = nfs3_proc_pathconf, 901 .pathconf = nfs3_proc_pathconf,
880 .decode_dirent = nfs3_decode_dirent, 902 .decode_dirent = nfs3_decode_dirent,
881 .read_setup = nfs3_proc_read_setup, 903 .read_setup = nfs3_proc_read_setup,
904 .read_rpc_prepare = nfs3_proc_read_rpc_prepare,
882 .read_done = nfs3_read_done, 905 .read_done = nfs3_read_done,
883 .write_setup = nfs3_proc_write_setup, 906 .write_setup = nfs3_proc_write_setup,
907 .write_rpc_prepare = nfs3_proc_write_rpc_prepare,
884 .write_done = nfs3_write_done, 908 .write_done = nfs3_write_done,
885 .commit_setup = nfs3_proc_commit_setup, 909 .commit_setup = nfs3_proc_commit_setup,
886 .commit_done = nfs3_commit_done, 910 .commit_done = nfs3_commit_done,
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index 183c6b123d0f..a77cc9a3ce55 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -2461,7 +2461,7 @@ struct rpc_procinfo nfs3_procedures[] = {
2461 PROC(COMMIT, commit, commit, 5), 2461 PROC(COMMIT, commit, commit, 5),
2462}; 2462};
2463 2463
2464struct rpc_version nfs_version3 = { 2464const struct rpc_version nfs_version3 = {
2465 .number = 3, 2465 .number = 3,
2466 .nrprocs = ARRAY_SIZE(nfs3_procedures), 2466 .nrprocs = ARRAY_SIZE(nfs3_procedures),
2467 .procs = nfs3_procedures 2467 .procs = nfs3_procedures
@@ -2489,7 +2489,7 @@ static struct rpc_procinfo nfs3_acl_procedures[] = {
2489 }, 2489 },
2490}; 2490};
2491 2491
2492struct rpc_version nfsacl_version3 = { 2492const struct rpc_version nfsacl_version3 = {
2493 .number = 3, 2493 .number = 3,
2494 .nrprocs = sizeof(nfs3_acl_procedures)/ 2494 .nrprocs = sizeof(nfs3_acl_procedures)/
2495 sizeof(nfs3_acl_procedures[0]), 2495 sizeof(nfs3_acl_procedures[0]),
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 4d7d0aedc101..97ecc863dd76 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -20,7 +20,6 @@ enum nfs4_client_state {
20 NFS4CLNT_RECLAIM_REBOOT, 20 NFS4CLNT_RECLAIM_REBOOT,
21 NFS4CLNT_RECLAIM_NOGRACE, 21 NFS4CLNT_RECLAIM_NOGRACE,
22 NFS4CLNT_DELEGRETURN, 22 NFS4CLNT_DELEGRETURN,
23 NFS4CLNT_LAYOUTRECALL,
24 NFS4CLNT_SESSION_RESET, 23 NFS4CLNT_SESSION_RESET,
25 NFS4CLNT_RECALL_SLOT, 24 NFS4CLNT_RECALL_SLOT,
26 NFS4CLNT_LEASE_CONFIRM, 25 NFS4CLNT_LEASE_CONFIRM,
@@ -44,7 +43,7 @@ struct nfs4_minor_version_ops {
44 struct nfs4_sequence_args *args, 43 struct nfs4_sequence_args *args,
45 struct nfs4_sequence_res *res, 44 struct nfs4_sequence_res *res,
46 int cache_reply); 45 int cache_reply);
47 int (*validate_stateid)(struct nfs_delegation *, 46 bool (*match_stateid)(const nfs4_stateid *,
48 const nfs4_stateid *); 47 const nfs4_stateid *);
49 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *, 48 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
50 struct nfs_fsinfo *); 49 struct nfs_fsinfo *);
@@ -53,26 +52,25 @@ struct nfs4_minor_version_ops {
53 const struct nfs4_state_maintenance_ops *state_renewal_ops; 52 const struct nfs4_state_maintenance_ops *state_renewal_ops;
54}; 53};
55 54
56/* 55struct nfs_unique_id {
57 * struct rpc_sequence ensures that RPC calls are sent in the exact 56 struct rb_node rb_node;
58 * order that they appear on the list. 57 __u64 id;
59 */
60struct rpc_sequence {
61 struct rpc_wait_queue wait; /* RPC call delay queue */
62 spinlock_t lock; /* Protects the list */
63 struct list_head list; /* Defines sequence of RPC calls */
64}; 58};
65 59
66#define NFS_SEQID_CONFIRMED 1 60#define NFS_SEQID_CONFIRMED 1
67struct nfs_seqid_counter { 61struct nfs_seqid_counter {
68 struct rpc_sequence *sequence; 62 int owner_id;
69 int flags; 63 int flags;
70 u32 counter; 64 u32 counter;
65 spinlock_t lock; /* Protects the list */
66 struct list_head list; /* Defines sequence of RPC calls */
67 struct rpc_wait_queue wait; /* RPC call delay queue */
71}; 68};
72 69
73struct nfs_seqid { 70struct nfs_seqid {
74 struct nfs_seqid_counter *sequence; 71 struct nfs_seqid_counter *sequence;
75 struct list_head list; 72 struct list_head list;
73 struct rpc_task *task;
76}; 74};
77 75
78static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status) 76static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
@@ -81,18 +79,12 @@ static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status
81 seqid->flags |= NFS_SEQID_CONFIRMED; 79 seqid->flags |= NFS_SEQID_CONFIRMED;
82} 80}
83 81
84struct nfs_unique_id {
85 struct rb_node rb_node;
86 __u64 id;
87};
88
89/* 82/*
90 * NFS4 state_owners and lock_owners are simply labels for ordered 83 * NFS4 state_owners and lock_owners are simply labels for ordered
91 * sequences of RPC calls. Their sole purpose is to provide once-only 84 * sequences of RPC calls. Their sole purpose is to provide once-only
92 * semantics by allowing the server to identify replayed requests. 85 * semantics by allowing the server to identify replayed requests.
93 */ 86 */
94struct nfs4_state_owner { 87struct nfs4_state_owner {
95 struct nfs_unique_id so_owner_id;
96 struct nfs_server *so_server; 88 struct nfs_server *so_server;
97 struct list_head so_lru; 89 struct list_head so_lru;
98 unsigned long so_expires; 90 unsigned long so_expires;
@@ -105,7 +97,6 @@ struct nfs4_state_owner {
105 unsigned long so_flags; 97 unsigned long so_flags;
106 struct list_head so_states; 98 struct list_head so_states;
107 struct nfs_seqid_counter so_seqid; 99 struct nfs_seqid_counter so_seqid;
108 struct rpc_sequence so_sequence;
109}; 100};
110 101
111enum { 102enum {
@@ -146,8 +137,6 @@ struct nfs4_lock_state {
146#define NFS_LOCK_INITIALIZED 1 137#define NFS_LOCK_INITIALIZED 1
147 int ls_flags; 138 int ls_flags;
148 struct nfs_seqid_counter ls_seqid; 139 struct nfs_seqid_counter ls_seqid;
149 struct rpc_sequence ls_sequence;
150 struct nfs_unique_id ls_id;
151 nfs4_stateid ls_stateid; 140 nfs4_stateid ls_stateid;
152 atomic_t ls_count; 141 atomic_t ls_count;
153 struct nfs4_lock_owner ls_owner; 142 struct nfs4_lock_owner ls_owner;
@@ -193,6 +182,7 @@ struct nfs4_exception {
193 long timeout; 182 long timeout;
194 int retry; 183 int retry;
195 struct nfs4_state *state; 184 struct nfs4_state *state;
185 struct inode *inode;
196}; 186};
197 187
198struct nfs4_state_recovery_ops { 188struct nfs4_state_recovery_ops {
@@ -224,7 +214,7 @@ extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, boo
224extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 214extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
225extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 215extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
226 struct nfs4_fs_locations *fs_locations, struct page *page); 216 struct nfs4_fs_locations *fs_locations, struct page *page);
227extern void nfs4_release_lockowner(const struct nfs4_lock_state *); 217extern int nfs4_release_lockowner(struct nfs4_lock_state *);
228extern const struct xattr_handler *nfs4_xattr_handlers[]; 218extern const struct xattr_handler *nfs4_xattr_handlers[];
229 219
230#if defined(CONFIG_NFS_V4_1) 220#if defined(CONFIG_NFS_V4_1)
@@ -233,12 +223,13 @@ static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *ser
233 return server->nfs_client->cl_session; 223 return server->nfs_client->cl_session;
234} 224}
235 225
226extern bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy);
236extern int nfs4_setup_sequence(const struct nfs_server *server, 227extern int nfs4_setup_sequence(const struct nfs_server *server,
237 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 228 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
238 int cache_reply, struct rpc_task *task); 229 struct rpc_task *task);
239extern int nfs41_setup_sequence(struct nfs4_session *session, 230extern int nfs41_setup_sequence(struct nfs4_session *session,
240 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 231 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
241 int cache_reply, struct rpc_task *task); 232 struct rpc_task *task);
242extern void nfs4_destroy_session(struct nfs4_session *session); 233extern void nfs4_destroy_session(struct nfs4_session *session);
243extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp); 234extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
244extern int nfs4_proc_create_session(struct nfs_client *); 235extern int nfs4_proc_create_session(struct nfs_client *);
@@ -269,7 +260,7 @@ static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *ser
269 260
270static inline int nfs4_setup_sequence(const struct nfs_server *server, 261static inline int nfs4_setup_sequence(const struct nfs_server *server,
271 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 262 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
272 int cache_reply, struct rpc_task *task) 263 struct rpc_task *task)
273{ 264{
274 return 0; 265 return 0;
275} 266}
@@ -319,7 +310,7 @@ static inline void nfs4_schedule_session_recovery(struct nfs4_session *session)
319} 310}
320#endif /* CONFIG_NFS_V4_1 */ 311#endif /* CONFIG_NFS_V4_1 */
321 312
322extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *); 313extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t);
323extern void nfs4_put_state_owner(struct nfs4_state_owner *); 314extern void nfs4_put_state_owner(struct nfs4_state_owner *);
324extern void nfs4_purge_state_owners(struct nfs_server *); 315extern void nfs4_purge_state_owners(struct nfs_server *);
325extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 316extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
@@ -327,6 +318,8 @@ extern void nfs4_put_open_state(struct nfs4_state *);
327extern void nfs4_close_state(struct nfs4_state *, fmode_t); 318extern void nfs4_close_state(struct nfs4_state *, fmode_t);
328extern void nfs4_close_sync(struct nfs4_state *, fmode_t); 319extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
329extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t); 320extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
321extern void nfs_inode_find_state_and_recover(struct inode *inode,
322 const nfs4_stateid *stateid);
330extern void nfs4_schedule_lease_recovery(struct nfs_client *); 323extern void nfs4_schedule_lease_recovery(struct nfs_client *);
331extern void nfs4_schedule_state_manager(struct nfs_client *); 324extern void nfs4_schedule_state_manager(struct nfs_client *);
332extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp); 325extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
@@ -337,7 +330,8 @@ extern void nfs41_handle_server_scope(struct nfs_client *,
337 struct server_scope **); 330 struct server_scope **);
338extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 331extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
339extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 332extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
340extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t, pid_t); 333extern void nfs4_select_rw_stateid(nfs4_stateid *, struct nfs4_state *,
334 fmode_t, fl_owner_t, pid_t);
341 335
342extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask); 336extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
343extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 337extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
@@ -346,6 +340,8 @@ extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
346extern void nfs_release_seqid(struct nfs_seqid *seqid); 340extern void nfs_release_seqid(struct nfs_seqid *seqid);
347extern void nfs_free_seqid(struct nfs_seqid *seqid); 341extern void nfs_free_seqid(struct nfs_seqid *seqid);
348 342
343extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
344
349extern const nfs4_stateid zero_stateid; 345extern const nfs4_stateid zero_stateid;
350 346
351/* nfs4xdr.c */ 347/* nfs4xdr.c */
@@ -357,6 +353,16 @@ struct nfs4_mount_data;
357extern struct svc_version nfs4_callback_version1; 353extern struct svc_version nfs4_callback_version1;
358extern struct svc_version nfs4_callback_version4; 354extern struct svc_version nfs4_callback_version4;
359 355
356static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
357{
358 memcpy(dst, src, sizeof(*dst));
359}
360
361static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
362{
363 return memcmp(dst, src, sizeof(*dst)) == 0;
364}
365
360#else 366#else
361 367
362#define nfs4_close_state(a, b) do { } while (0) 368#define nfs4_close_state(a, b) do { } while (0)
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
index 71ec08617e23..634c0bcb4fd6 100644
--- a/fs/nfs/nfs4filelayout.c
+++ b/fs/nfs/nfs4filelayout.c
@@ -33,7 +33,10 @@
33#include <linux/nfs_page.h> 33#include <linux/nfs_page.h>
34#include <linux/module.h> 34#include <linux/module.h>
35 35
36#include <linux/sunrpc/metrics.h>
37
36#include "internal.h" 38#include "internal.h"
39#include "delegation.h"
37#include "nfs4filelayout.h" 40#include "nfs4filelayout.h"
38 41
39#define NFSDBG_FACILITY NFSDBG_PNFS_LD 42#define NFSDBG_FACILITY NFSDBG_PNFS_LD
@@ -84,12 +87,27 @@ static int filelayout_async_handle_error(struct rpc_task *task,
84 struct nfs_client *clp, 87 struct nfs_client *clp,
85 int *reset) 88 int *reset)
86{ 89{
90 struct nfs_server *mds_server = NFS_SERVER(state->inode);
91 struct nfs_client *mds_client = mds_server->nfs_client;
92
87 if (task->tk_status >= 0) 93 if (task->tk_status >= 0)
88 return 0; 94 return 0;
89
90 *reset = 0; 95 *reset = 0;
91 96
92 switch (task->tk_status) { 97 switch (task->tk_status) {
98 /* MDS state errors */
99 case -NFS4ERR_DELEG_REVOKED:
100 case -NFS4ERR_ADMIN_REVOKED:
101 case -NFS4ERR_BAD_STATEID:
102 nfs_remove_bad_delegation(state->inode);
103 case -NFS4ERR_OPENMODE:
104 nfs4_schedule_stateid_recovery(mds_server, state);
105 goto wait_on_recovery;
106 case -NFS4ERR_EXPIRED:
107 nfs4_schedule_stateid_recovery(mds_server, state);
108 nfs4_schedule_lease_recovery(mds_client);
109 goto wait_on_recovery;
110 /* DS session errors */
93 case -NFS4ERR_BADSESSION: 111 case -NFS4ERR_BADSESSION:
94 case -NFS4ERR_BADSLOT: 112 case -NFS4ERR_BADSLOT:
95 case -NFS4ERR_BAD_HIGH_SLOT: 113 case -NFS4ERR_BAD_HIGH_SLOT:
@@ -115,8 +133,14 @@ static int filelayout_async_handle_error(struct rpc_task *task,
115 *reset = 1; 133 *reset = 1;
116 break; 134 break;
117 } 135 }
136out:
118 task->tk_status = 0; 137 task->tk_status = 0;
119 return -EAGAIN; 138 return -EAGAIN;
139wait_on_recovery:
140 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
141 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
142 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
143 goto out;
120} 144}
121 145
122/* NFS_PROTO call done callback routines */ 146/* NFS_PROTO call done callback routines */
@@ -173,7 +197,7 @@ static void filelayout_read_prepare(struct rpc_task *task, void *data)
173 197
174 if (nfs41_setup_sequence(rdata->ds_clp->cl_session, 198 if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
175 &rdata->args.seq_args, &rdata->res.seq_res, 199 &rdata->args.seq_args, &rdata->res.seq_res,
176 0, task)) 200 task))
177 return; 201 return;
178 202
179 rpc_call_start(task); 203 rpc_call_start(task);
@@ -189,10 +213,18 @@ static void filelayout_read_call_done(struct rpc_task *task, void *data)
189 rdata->mds_ops->rpc_call_done(task, data); 213 rdata->mds_ops->rpc_call_done(task, data);
190} 214}
191 215
216static void filelayout_read_count_stats(struct rpc_task *task, void *data)
217{
218 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
219
220 rpc_count_iostats(task, NFS_SERVER(rdata->inode)->client->cl_metrics);
221}
222
192static void filelayout_read_release(void *data) 223static void filelayout_read_release(void *data)
193{ 224{
194 struct nfs_read_data *rdata = (struct nfs_read_data *)data; 225 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
195 226
227 put_lseg(rdata->lseg);
196 rdata->mds_ops->rpc_release(data); 228 rdata->mds_ops->rpc_release(data);
197} 229}
198 230
@@ -254,7 +286,7 @@ static void filelayout_write_prepare(struct rpc_task *task, void *data)
254 286
255 if (nfs41_setup_sequence(wdata->ds_clp->cl_session, 287 if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
256 &wdata->args.seq_args, &wdata->res.seq_res, 288 &wdata->args.seq_args, &wdata->res.seq_res,
257 0, task)) 289 task))
258 return; 290 return;
259 291
260 rpc_call_start(task); 292 rpc_call_start(task);
@@ -268,10 +300,18 @@ static void filelayout_write_call_done(struct rpc_task *task, void *data)
268 wdata->mds_ops->rpc_call_done(task, data); 300 wdata->mds_ops->rpc_call_done(task, data);
269} 301}
270 302
303static void filelayout_write_count_stats(struct rpc_task *task, void *data)
304{
305 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
306
307 rpc_count_iostats(task, NFS_SERVER(wdata->inode)->client->cl_metrics);
308}
309
271static void filelayout_write_release(void *data) 310static void filelayout_write_release(void *data)
272{ 311{
273 struct nfs_write_data *wdata = (struct nfs_write_data *)data; 312 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
274 313
314 put_lseg(wdata->lseg);
275 wdata->mds_ops->rpc_release(data); 315 wdata->mds_ops->rpc_release(data);
276} 316}
277 317
@@ -282,24 +322,28 @@ static void filelayout_commit_release(void *data)
282 nfs_commit_release_pages(wdata); 322 nfs_commit_release_pages(wdata);
283 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding)) 323 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding))
284 nfs_commit_clear_lock(NFS_I(wdata->inode)); 324 nfs_commit_clear_lock(NFS_I(wdata->inode));
325 put_lseg(wdata->lseg);
285 nfs_commitdata_release(wdata); 326 nfs_commitdata_release(wdata);
286} 327}
287 328
288struct rpc_call_ops filelayout_read_call_ops = { 329static const struct rpc_call_ops filelayout_read_call_ops = {
289 .rpc_call_prepare = filelayout_read_prepare, 330 .rpc_call_prepare = filelayout_read_prepare,
290 .rpc_call_done = filelayout_read_call_done, 331 .rpc_call_done = filelayout_read_call_done,
332 .rpc_count_stats = filelayout_read_count_stats,
291 .rpc_release = filelayout_read_release, 333 .rpc_release = filelayout_read_release,
292}; 334};
293 335
294struct rpc_call_ops filelayout_write_call_ops = { 336static const struct rpc_call_ops filelayout_write_call_ops = {
295 .rpc_call_prepare = filelayout_write_prepare, 337 .rpc_call_prepare = filelayout_write_prepare,
296 .rpc_call_done = filelayout_write_call_done, 338 .rpc_call_done = filelayout_write_call_done,
339 .rpc_count_stats = filelayout_write_count_stats,
297 .rpc_release = filelayout_write_release, 340 .rpc_release = filelayout_write_release,
298}; 341};
299 342
300struct rpc_call_ops filelayout_commit_call_ops = { 343static const struct rpc_call_ops filelayout_commit_call_ops = {
301 .rpc_call_prepare = filelayout_write_prepare, 344 .rpc_call_prepare = filelayout_write_prepare,
302 .rpc_call_done = filelayout_write_call_done, 345 .rpc_call_done = filelayout_write_call_done,
346 .rpc_count_stats = filelayout_write_count_stats,
303 .rpc_release = filelayout_commit_release, 347 .rpc_release = filelayout_commit_release,
304}; 348};
305 349
@@ -367,7 +411,8 @@ filelayout_write_pagelist(struct nfs_write_data *data, int sync)
367 idx = nfs4_fl_calc_ds_index(lseg, j); 411 idx = nfs4_fl_calc_ds_index(lseg, j);
368 ds = nfs4_fl_prepare_ds(lseg, idx); 412 ds = nfs4_fl_prepare_ds(lseg, idx);
369 if (!ds) { 413 if (!ds) {
370 printk(KERN_ERR "%s: prepare_ds failed, use MDS\n", __func__); 414 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
415 __func__);
371 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); 416 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
372 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); 417 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
373 return PNFS_NOT_ATTEMPTED; 418 return PNFS_NOT_ATTEMPTED;
@@ -575,7 +620,7 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo,
575 goto out_err_free; 620 goto out_err_free;
576 fl->fh_array[i]->size = be32_to_cpup(p++); 621 fl->fh_array[i]->size = be32_to_cpup(p++);
577 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) { 622 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
578 printk(KERN_ERR "Too big fh %d received %d\n", 623 printk(KERN_ERR "NFS: Too big fh %d received %d\n",
579 i, fl->fh_array[i]->size); 624 i, fl->fh_array[i]->size);
580 goto out_err_free; 625 goto out_err_free;
581 } 626 }
@@ -640,14 +685,16 @@ filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
640 int size = (fl->stripe_type == STRIPE_SPARSE) ? 685 int size = (fl->stripe_type == STRIPE_SPARSE) ?
641 fl->dsaddr->ds_num : fl->dsaddr->stripe_count; 686 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
642 687
643 fl->commit_buckets = kcalloc(size, sizeof(struct list_head), gfp_flags); 688 fl->commit_buckets = kcalloc(size, sizeof(struct nfs4_fl_commit_bucket), gfp_flags);
644 if (!fl->commit_buckets) { 689 if (!fl->commit_buckets) {
645 filelayout_free_lseg(&fl->generic_hdr); 690 filelayout_free_lseg(&fl->generic_hdr);
646 return NULL; 691 return NULL;
647 } 692 }
648 fl->number_of_buckets = size; 693 fl->number_of_buckets = size;
649 for (i = 0; i < size; i++) 694 for (i = 0; i < size; i++) {
650 INIT_LIST_HEAD(&fl->commit_buckets[i]); 695 INIT_LIST_HEAD(&fl->commit_buckets[i].written);
696 INIT_LIST_HEAD(&fl->commit_buckets[i].committing);
697 }
651 } 698 }
652 return &fl->generic_hdr; 699 return &fl->generic_hdr;
653} 700}
@@ -679,7 +726,7 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
679 return (p_stripe == r_stripe); 726 return (p_stripe == r_stripe);
680} 727}
681 728
682void 729static void
683filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio, 730filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
684 struct nfs_page *req) 731 struct nfs_page *req)
685{ 732{
@@ -696,7 +743,7 @@ filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
696 nfs_pageio_reset_read_mds(pgio); 743 nfs_pageio_reset_read_mds(pgio);
697} 744}
698 745
699void 746static void
700filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio, 747filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
701 struct nfs_page *req) 748 struct nfs_page *req)
702{ 749{
@@ -725,11 +772,6 @@ static const struct nfs_pageio_ops filelayout_pg_write_ops = {
725 .pg_doio = pnfs_generic_pg_writepages, 772 .pg_doio = pnfs_generic_pg_writepages,
726}; 773};
727 774
728static bool filelayout_mark_pnfs_commit(struct pnfs_layout_segment *lseg)
729{
730 return !FILELAYOUT_LSEG(lseg)->commit_through_mds;
731}
732
733static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j) 775static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
734{ 776{
735 if (fl->stripe_type == STRIPE_SPARSE) 777 if (fl->stripe_type == STRIPE_SPARSE)
@@ -738,13 +780,49 @@ static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
738 return j; 780 return j;
739} 781}
740 782
741struct list_head *filelayout_choose_commit_list(struct nfs_page *req) 783/* The generic layer is about to remove the req from the commit list.
784 * If this will make the bucket empty, it will need to put the lseg reference.
785 */
786static void
787filelayout_clear_request_commit(struct nfs_page *req)
788{
789 struct pnfs_layout_segment *freeme = NULL;
790 struct inode *inode = req->wb_context->dentry->d_inode;
791
792 spin_lock(&inode->i_lock);
793 if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags))
794 goto out;
795 if (list_is_singular(&req->wb_list)) {
796 struct inode *inode = req->wb_context->dentry->d_inode;
797 struct pnfs_layout_segment *lseg;
798
799 /* From here we can find the bucket, but for the moment,
800 * since there is only one relevant lseg...
801 */
802 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) {
803 if (lseg->pls_range.iomode == IOMODE_RW) {
804 freeme = lseg;
805 break;
806 }
807 }
808 }
809out:
810 nfs_request_remove_commit_list(req);
811 spin_unlock(&inode->i_lock);
812 put_lseg(freeme);
813}
814
815static struct list_head *
816filelayout_choose_commit_list(struct nfs_page *req,
817 struct pnfs_layout_segment *lseg)
742{ 818{
743 struct pnfs_layout_segment *lseg = req->wb_commit_lseg;
744 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); 819 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
745 u32 i, j; 820 u32 i, j;
746 struct list_head *list; 821 struct list_head *list;
747 822
823 if (fl->commit_through_mds)
824 return &NFS_I(req->wb_context->dentry->d_inode)->commit_list;
825
748 /* Note that we are calling nfs4_fl_calc_j_index on each page 826 /* Note that we are calling nfs4_fl_calc_j_index on each page
749 * that ends up being committed to a data server. An attractive 827 * that ends up being committed to a data server. An attractive
750 * alternative is to add a field to nfs_write_data and nfs_page 828 * alternative is to add a field to nfs_write_data and nfs_page
@@ -754,14 +832,30 @@ struct list_head *filelayout_choose_commit_list(struct nfs_page *req)
754 j = nfs4_fl_calc_j_index(lseg, 832 j = nfs4_fl_calc_j_index(lseg,
755 (loff_t)req->wb_index << PAGE_CACHE_SHIFT); 833 (loff_t)req->wb_index << PAGE_CACHE_SHIFT);
756 i = select_bucket_index(fl, j); 834 i = select_bucket_index(fl, j);
757 list = &fl->commit_buckets[i]; 835 list = &fl->commit_buckets[i].written;
758 if (list_empty(list)) { 836 if (list_empty(list)) {
759 /* Non-empty buckets hold a reference on the lseg */ 837 /* Non-empty buckets hold a reference on the lseg. That ref
838 * is normally transferred to the COMMIT call and released
839 * there. It could also be released if the last req is pulled
840 * off due to a rewrite, in which case it will be done in
841 * filelayout_remove_commit_req
842 */
760 get_lseg(lseg); 843 get_lseg(lseg);
761 } 844 }
845 set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
762 return list; 846 return list;
763} 847}
764 848
849static void
850filelayout_mark_request_commit(struct nfs_page *req,
851 struct pnfs_layout_segment *lseg)
852{
853 struct list_head *list;
854
855 list = filelayout_choose_commit_list(req, lseg);
856 nfs_request_add_commit_list(req, list);
857}
858
765static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i) 859static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
766{ 860{
767 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); 861 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
@@ -797,11 +891,12 @@ static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
797 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index); 891 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
798 ds = nfs4_fl_prepare_ds(lseg, idx); 892 ds = nfs4_fl_prepare_ds(lseg, idx);
799 if (!ds) { 893 if (!ds) {
800 printk(KERN_ERR "%s: prepare_ds failed, use MDS\n", __func__); 894 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
895 __func__);
801 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); 896 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
802 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); 897 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
803 prepare_to_resend_writes(data); 898 prepare_to_resend_writes(data);
804 data->mds_ops->rpc_release(data); 899 filelayout_commit_release(data);
805 return -EAGAIN; 900 return -EAGAIN;
806 } 901 }
807 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how); 902 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
@@ -817,24 +912,87 @@ static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
817/* 912/*
818 * This is only useful while we are using whole file layouts. 913 * This is only useful while we are using whole file layouts.
819 */ 914 */
820static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode) 915static struct pnfs_layout_segment *
916find_only_write_lseg_locked(struct inode *inode)
821{ 917{
822 struct pnfs_layout_segment *lseg, *rv = NULL; 918 struct pnfs_layout_segment *lseg;
823 919
824 spin_lock(&inode->i_lock);
825 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) 920 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list)
826 if (lseg->pls_range.iomode == IOMODE_RW) 921 if (lseg->pls_range.iomode == IOMODE_RW)
827 rv = get_lseg(lseg); 922 return lseg;
923 return NULL;
924}
925
926static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode)
927{
928 struct pnfs_layout_segment *rv;
929
930 spin_lock(&inode->i_lock);
931 rv = find_only_write_lseg_locked(inode);
932 if (rv)
933 get_lseg(rv);
828 spin_unlock(&inode->i_lock); 934 spin_unlock(&inode->i_lock);
829 return rv; 935 return rv;
830} 936}
831 937
832static int alloc_ds_commits(struct inode *inode, struct list_head *list) 938static int
939filelayout_scan_ds_commit_list(struct nfs4_fl_commit_bucket *bucket, int max,
940 spinlock_t *lock)
941{
942 struct list_head *src = &bucket->written;
943 struct list_head *dst = &bucket->committing;
944 struct nfs_page *req, *tmp;
945 int ret = 0;
946
947 list_for_each_entry_safe(req, tmp, src, wb_list) {
948 if (!nfs_lock_request(req))
949 continue;
950 if (cond_resched_lock(lock))
951 list_safe_reset_next(req, tmp, wb_list);
952 nfs_request_remove_commit_list(req);
953 clear_bit(PG_COMMIT_TO_DS, &req->wb_flags);
954 nfs_list_add_request(req, dst);
955 ret++;
956 if (ret == max)
957 break;
958 }
959 return ret;
960}
961
962/* Move reqs from written to committing lists, returning count of number moved.
963 * Note called with i_lock held.
964 */
965static int filelayout_scan_commit_lists(struct inode *inode, int max,
966 spinlock_t *lock)
967{
968 struct pnfs_layout_segment *lseg;
969 struct nfs4_filelayout_segment *fl;
970 int i, rv = 0, cnt;
971
972 lseg = find_only_write_lseg_locked(inode);
973 if (!lseg)
974 goto out_done;
975 fl = FILELAYOUT_LSEG(lseg);
976 if (fl->commit_through_mds)
977 goto out_done;
978 for (i = 0; i < fl->number_of_buckets && max != 0; i++) {
979 cnt = filelayout_scan_ds_commit_list(&fl->commit_buckets[i],
980 max, lock);
981 max -= cnt;
982 rv += cnt;
983 }
984out_done:
985 return rv;
986}
987
988static unsigned int
989alloc_ds_commits(struct inode *inode, struct list_head *list)
833{ 990{
834 struct pnfs_layout_segment *lseg; 991 struct pnfs_layout_segment *lseg;
835 struct nfs4_filelayout_segment *fl; 992 struct nfs4_filelayout_segment *fl;
836 struct nfs_write_data *data; 993 struct nfs_write_data *data;
837 int i, j; 994 int i, j;
995 unsigned int nreq = 0;
838 996
839 /* Won't need this when non-whole file layout segments are supported 997 /* Won't need this when non-whole file layout segments are supported
840 * instead we will use a pnfs_layout_hdr structure */ 998 * instead we will use a pnfs_layout_hdr structure */
@@ -843,28 +1001,27 @@ static int alloc_ds_commits(struct inode *inode, struct list_head *list)
843 return 0; 1001 return 0;
844 fl = FILELAYOUT_LSEG(lseg); 1002 fl = FILELAYOUT_LSEG(lseg);
845 for (i = 0; i < fl->number_of_buckets; i++) { 1003 for (i = 0; i < fl->number_of_buckets; i++) {
846 if (list_empty(&fl->commit_buckets[i])) 1004 if (list_empty(&fl->commit_buckets[i].committing))
847 continue; 1005 continue;
848 data = nfs_commitdata_alloc(); 1006 data = nfs_commitdata_alloc();
849 if (!data) 1007 if (!data)
850 goto out_bad; 1008 break;
851 data->ds_commit_index = i; 1009 data->ds_commit_index = i;
852 data->lseg = lseg; 1010 data->lseg = lseg;
853 list_add(&data->pages, list); 1011 list_add(&data->pages, list);
1012 nreq++;
854 } 1013 }
855 put_lseg(lseg);
856 return 0;
857 1014
858out_bad: 1015 /* Clean up on error */
859 for (j = i; j < fl->number_of_buckets; j++) { 1016 for (j = i; j < fl->number_of_buckets; j++) {
860 if (list_empty(&fl->commit_buckets[i])) 1017 if (list_empty(&fl->commit_buckets[i].committing))
861 continue; 1018 continue;
862 nfs_retry_commit(&fl->commit_buckets[i], lseg); 1019 nfs_retry_commit(&fl->commit_buckets[i].committing, lseg);
863 put_lseg(lseg); /* associated with emptying bucket */ 1020 put_lseg(lseg); /* associated with emptying bucket */
864 } 1021 }
865 put_lseg(lseg); 1022 put_lseg(lseg);
866 /* Caller will clean up entries put on list */ 1023 /* Caller will clean up entries put on list */
867 return -ENOMEM; 1024 return nreq;
868} 1025}
869 1026
870/* This follows nfs_commit_list pretty closely */ 1027/* This follows nfs_commit_list pretty closely */
@@ -874,40 +1031,40 @@ filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
874{ 1031{
875 struct nfs_write_data *data, *tmp; 1032 struct nfs_write_data *data, *tmp;
876 LIST_HEAD(list); 1033 LIST_HEAD(list);
1034 unsigned int nreq = 0;
877 1035
878 if (!list_empty(mds_pages)) { 1036 if (!list_empty(mds_pages)) {
879 data = nfs_commitdata_alloc(); 1037 data = nfs_commitdata_alloc();
880 if (!data) 1038 if (data != NULL) {
881 goto out_bad; 1039 data->lseg = NULL;
882 data->lseg = NULL; 1040 list_add(&data->pages, &list);
883 list_add(&data->pages, &list); 1041 nreq++;
1042 } else
1043 nfs_retry_commit(mds_pages, NULL);
884 } 1044 }
885 1045
886 if (alloc_ds_commits(inode, &list)) 1046 nreq += alloc_ds_commits(inode, &list);
887 goto out_bad; 1047
1048 if (nreq == 0) {
1049 nfs_commit_clear_lock(NFS_I(inode));
1050 goto out;
1051 }
1052
1053 atomic_add(nreq, &NFS_I(inode)->commits_outstanding);
888 1054
889 list_for_each_entry_safe(data, tmp, &list, pages) { 1055 list_for_each_entry_safe(data, tmp, &list, pages) {
890 list_del_init(&data->pages); 1056 list_del_init(&data->pages);
891 atomic_inc(&NFS_I(inode)->commits_outstanding);
892 if (!data->lseg) { 1057 if (!data->lseg) {
893 nfs_init_commit(data, mds_pages, NULL); 1058 nfs_init_commit(data, mds_pages, NULL);
894 nfs_initiate_commit(data, NFS_CLIENT(inode), 1059 nfs_initiate_commit(data, NFS_CLIENT(inode),
895 data->mds_ops, how); 1060 data->mds_ops, how);
896 } else { 1061 } else {
897 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index], data->lseg); 1062 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index].committing, data->lseg);
898 filelayout_initiate_commit(data, how); 1063 filelayout_initiate_commit(data, how);
899 } 1064 }
900 } 1065 }
901 return 0; 1066out:
902 out_bad: 1067 return PNFS_ATTEMPTED;
903 list_for_each_entry_safe(data, tmp, &list, pages) {
904 nfs_retry_commit(&data->pages, data->lseg);
905 list_del_init(&data->pages);
906 nfs_commit_free(data);
907 }
908 nfs_retry_commit(mds_pages, NULL);
909 nfs_commit_clear_lock(NFS_I(inode));
910 return -ENOMEM;
911} 1068}
912 1069
913static void 1070static void
@@ -924,8 +1081,9 @@ static struct pnfs_layoutdriver_type filelayout_type = {
924 .free_lseg = filelayout_free_lseg, 1081 .free_lseg = filelayout_free_lseg,
925 .pg_read_ops = &filelayout_pg_read_ops, 1082 .pg_read_ops = &filelayout_pg_read_ops,
926 .pg_write_ops = &filelayout_pg_write_ops, 1083 .pg_write_ops = &filelayout_pg_write_ops,
927 .mark_pnfs_commit = filelayout_mark_pnfs_commit, 1084 .mark_request_commit = filelayout_mark_request_commit,
928 .choose_commit_list = filelayout_choose_commit_list, 1085 .clear_request_commit = filelayout_clear_request_commit,
1086 .scan_commit_lists = filelayout_scan_commit_lists,
929 .commit_pagelist = filelayout_commit_pagelist, 1087 .commit_pagelist = filelayout_commit_pagelist,
930 .read_pagelist = filelayout_read_pagelist, 1088 .read_pagelist = filelayout_read_pagelist,
931 .write_pagelist = filelayout_write_pagelist, 1089 .write_pagelist = filelayout_write_pagelist,
diff --git a/fs/nfs/nfs4filelayout.h b/fs/nfs/nfs4filelayout.h
index 2e42284253fa..21190bb1f5e3 100644
--- a/fs/nfs/nfs4filelayout.h
+++ b/fs/nfs/nfs4filelayout.h
@@ -74,6 +74,11 @@ struct nfs4_file_layout_dsaddr {
74 struct nfs4_pnfs_ds *ds_list[1]; 74 struct nfs4_pnfs_ds *ds_list[1];
75}; 75};
76 76
77struct nfs4_fl_commit_bucket {
78 struct list_head written;
79 struct list_head committing;
80};
81
77struct nfs4_filelayout_segment { 82struct nfs4_filelayout_segment {
78 struct pnfs_layout_segment generic_hdr; 83 struct pnfs_layout_segment generic_hdr;
79 u32 stripe_type; 84 u32 stripe_type;
@@ -84,7 +89,7 @@ struct nfs4_filelayout_segment {
84 struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */ 89 struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */
85 unsigned int num_fh; 90 unsigned int num_fh;
86 struct nfs_fh **fh_array; 91 struct nfs_fh **fh_array;
87 struct list_head *commit_buckets; /* Sort commits to ds */ 92 struct nfs4_fl_commit_bucket *commit_buckets; /* Sort commits to ds */
88 int number_of_buckets; 93 int number_of_buckets;
89}; 94};
90 95
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index 8ae91908f5aa..a866bbd2890a 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -45,7 +45,7 @@
45 * - incremented when a device id maps a data server already in the cache. 45 * - incremented when a device id maps a data server already in the cache.
46 * - decremented when deviceid is removed from the cache. 46 * - decremented when deviceid is removed from the cache.
47 */ 47 */
48DEFINE_SPINLOCK(nfs4_ds_cache_lock); 48static DEFINE_SPINLOCK(nfs4_ds_cache_lock);
49static LIST_HEAD(nfs4_data_server_cache); 49static LIST_HEAD(nfs4_data_server_cache);
50 50
51/* Debug routines */ 51/* Debug routines */
@@ -108,58 +108,40 @@ same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2)
108 return false; 108 return false;
109} 109}
110 110
111/* 111static bool
112 * Lookup DS by addresses. The first matching address returns true. 112_same_data_server_addrs_locked(const struct list_head *dsaddrs1,
113 * nfs4_ds_cache_lock is held 113 const struct list_head *dsaddrs2)
114 */
115static struct nfs4_pnfs_ds *
116_data_server_lookup_locked(struct list_head *dsaddrs)
117{ 114{
118 struct nfs4_pnfs_ds *ds;
119 struct nfs4_pnfs_ds_addr *da1, *da2; 115 struct nfs4_pnfs_ds_addr *da1, *da2;
120 116
121 list_for_each_entry(da1, dsaddrs, da_node) { 117 /* step through both lists, comparing as we go */
122 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) { 118 for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node),
123 list_for_each_entry(da2, &ds->ds_addrs, da_node) { 119 da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node);
124 if (same_sockaddr( 120 da1 != NULL && da2 != NULL;
125 (struct sockaddr *)&da1->da_addr, 121 da1 = list_entry(da1->da_node.next, typeof(*da1), da_node),
126 (struct sockaddr *)&da2->da_addr)) 122 da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) {
127 return ds; 123 if (!same_sockaddr((struct sockaddr *)&da1->da_addr,
128 } 124 (struct sockaddr *)&da2->da_addr))
129 } 125 return false;
130 } 126 }
131 return NULL; 127 if (da1 == NULL && da2 == NULL)
128 return true;
129
130 return false;
132} 131}
133 132
134/* 133/*
135 * Compare two lists of addresses. 134 * Lookup DS by addresses. nfs4_ds_cache_lock is held
136 */ 135 */
137static bool 136static struct nfs4_pnfs_ds *
138_data_server_match_all_addrs_locked(struct list_head *dsaddrs1, 137_data_server_lookup_locked(const struct list_head *dsaddrs)
139 struct list_head *dsaddrs2)
140{ 138{
141 struct nfs4_pnfs_ds_addr *da1, *da2; 139 struct nfs4_pnfs_ds *ds;
142 size_t count1 = 0,
143 count2 = 0;
144
145 list_for_each_entry(da1, dsaddrs1, da_node)
146 count1++;
147
148 list_for_each_entry(da2, dsaddrs2, da_node) {
149 bool found = false;
150 count2++;
151 list_for_each_entry(da1, dsaddrs1, da_node) {
152 if (same_sockaddr((struct sockaddr *)&da1->da_addr,
153 (struct sockaddr *)&da2->da_addr)) {
154 found = true;
155 break;
156 }
157 }
158 if (!found)
159 return false;
160 }
161 140
162 return (count1 == count2); 141 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node)
142 if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs))
143 return ds;
144 return NULL;
163} 145}
164 146
165/* 147/*
@@ -356,11 +338,6 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
356 dprintk("%s add new data server %s\n", __func__, 338 dprintk("%s add new data server %s\n", __func__,
357 ds->ds_remotestr); 339 ds->ds_remotestr);
358 } else { 340 } else {
359 if (!_data_server_match_all_addrs_locked(&tmp_ds->ds_addrs,
360 dsaddrs)) {
361 dprintk("%s: multipath address mismatch: %s != %s",
362 __func__, tmp_ds->ds_remotestr, remotestr);
363 }
364 kfree(remotestr); 341 kfree(remotestr);
365 kfree(ds); 342 kfree(ds);
366 atomic_inc(&tmp_ds->ds_count); 343 atomic_inc(&tmp_ds->ds_count);
@@ -378,7 +355,7 @@ out:
378 * Currently only supports ipv4, ipv6 and one multi-path address. 355 * Currently only supports ipv4, ipv6 and one multi-path address.
379 */ 356 */
380static struct nfs4_pnfs_ds_addr * 357static struct nfs4_pnfs_ds_addr *
381decode_ds_addr(struct xdr_stream *streamp, gfp_t gfp_flags) 358decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags)
382{ 359{
383 struct nfs4_pnfs_ds_addr *da = NULL; 360 struct nfs4_pnfs_ds_addr *da = NULL;
384 char *buf, *portstr; 361 char *buf, *portstr;
@@ -457,7 +434,7 @@ decode_ds_addr(struct xdr_stream *streamp, gfp_t gfp_flags)
457 434
458 INIT_LIST_HEAD(&da->da_node); 435 INIT_LIST_HEAD(&da->da_node);
459 436
460 if (!rpc_pton(buf, portstr-buf, (struct sockaddr *)&da->da_addr, 437 if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr,
461 sizeof(da->da_addr))) { 438 sizeof(da->da_addr))) {
462 dprintk("%s: error parsing address %s\n", __func__, buf); 439 dprintk("%s: error parsing address %s\n", __func__, buf);
463 goto out_free_da; 440 goto out_free_da;
@@ -554,7 +531,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
554 cnt = be32_to_cpup(p); 531 cnt = be32_to_cpup(p);
555 dprintk("%s stripe count %d\n", __func__, cnt); 532 dprintk("%s stripe count %d\n", __func__, cnt);
556 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) { 533 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
557 printk(KERN_WARNING "%s: stripe count %d greater than " 534 printk(KERN_WARNING "NFS: %s: stripe count %d greater than "
558 "supported maximum %d\n", __func__, 535 "supported maximum %d\n", __func__,
559 cnt, NFS4_PNFS_MAX_STRIPE_CNT); 536 cnt, NFS4_PNFS_MAX_STRIPE_CNT);
560 goto out_err_free_scratch; 537 goto out_err_free_scratch;
@@ -585,7 +562,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
585 num = be32_to_cpup(p); 562 num = be32_to_cpup(p);
586 dprintk("%s ds_num %u\n", __func__, num); 563 dprintk("%s ds_num %u\n", __func__, num);
587 if (num > NFS4_PNFS_MAX_MULTI_CNT) { 564 if (num > NFS4_PNFS_MAX_MULTI_CNT) {
588 printk(KERN_WARNING "%s: multipath count %d greater than " 565 printk(KERN_WARNING "NFS: %s: multipath count %d greater than "
589 "supported maximum %d\n", __func__, 566 "supported maximum %d\n", __func__,
590 num, NFS4_PNFS_MAX_MULTI_CNT); 567 num, NFS4_PNFS_MAX_MULTI_CNT);
591 goto out_err_free_stripe_indices; 568 goto out_err_free_stripe_indices;
@@ -593,7 +570,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
593 570
594 /* validate stripe indices are all < num */ 571 /* validate stripe indices are all < num */
595 if (max_stripe_index >= num) { 572 if (max_stripe_index >= num) {
596 printk(KERN_WARNING "%s: stripe index %u >= num ds %u\n", 573 printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n",
597 __func__, max_stripe_index, num); 574 __func__, max_stripe_index, num);
598 goto out_err_free_stripe_indices; 575 goto out_err_free_stripe_indices;
599 } 576 }
@@ -625,7 +602,8 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
625 602
626 mp_count = be32_to_cpup(p); /* multipath count */ 603 mp_count = be32_to_cpup(p); /* multipath count */
627 for (j = 0; j < mp_count; j++) { 604 for (j = 0; j < mp_count; j++) {
628 da = decode_ds_addr(&stream, gfp_flags); 605 da = decode_ds_addr(NFS_SERVER(ino)->nfs_client->net,
606 &stream, gfp_flags);
629 if (da) 607 if (da)
630 list_add_tail(&da->da_node, &dsaddrs); 608 list_add_tail(&da->da_node, &dsaddrs);
631 } 609 }
@@ -686,7 +664,7 @@ decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_fl
686 664
687 new = decode_device(inode, dev, gfp_flags); 665 new = decode_device(inode, dev, gfp_flags);
688 if (!new) { 666 if (!new) {
689 printk(KERN_WARNING "%s: Could not decode or add device\n", 667 printk(KERN_WARNING "NFS: %s: Could not decode or add device\n",
690 __func__); 668 __func__);
691 return NULL; 669 return NULL;
692 } 670 }
@@ -835,7 +813,7 @@ nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx)
835 struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; 813 struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx];
836 814
837 if (ds == NULL) { 815 if (ds == NULL) {
838 printk(KERN_ERR "%s: No data server for offset index %d\n", 816 printk(KERN_ERR "NFS: %s: No data server for offset index %d\n",
839 __func__, ds_idx); 817 __func__, ds_idx);
840 return NULL; 818 return NULL;
841 } 819 }
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index bb80c49b6533..9c8eca315f43 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -94,13 +94,14 @@ static int nfs4_validate_fspath(struct dentry *dentry,
94} 94}
95 95
96static size_t nfs_parse_server_name(char *string, size_t len, 96static size_t nfs_parse_server_name(char *string, size_t len,
97 struct sockaddr *sa, size_t salen) 97 struct sockaddr *sa, size_t salen, struct nfs_server *server)
98{ 98{
99 struct net *net = rpc_net_ns(server->client);
99 ssize_t ret; 100 ssize_t ret;
100 101
101 ret = rpc_pton(string, len, sa, salen); 102 ret = rpc_pton(net, string, len, sa, salen);
102 if (ret == 0) { 103 if (ret == 0) {
103 ret = nfs_dns_resolve_name(string, len, sa, salen); 104 ret = nfs_dns_resolve_name(net, string, len, sa, salen);
104 if (ret < 0) 105 if (ret < 0)
105 ret = 0; 106 ret = 0;
106 } 107 }
@@ -137,7 +138,8 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
137 continue; 138 continue;
138 139
139 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len, 140 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len,
140 mountdata->addr, addr_bufsize); 141 mountdata->addr, addr_bufsize,
142 NFS_SB(mountdata->sb));
141 if (mountdata->addrlen == 0) 143 if (mountdata->addrlen == 0)
142 continue; 144 continue;
143 145
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index f0c849c98fe4..b76dd0efae75 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -72,18 +72,21 @@
72 72
73#define NFS4_MAX_LOOP_ON_RECOVER (10) 73#define NFS4_MAX_LOOP_ON_RECOVER (10)
74 74
75static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
76
75struct nfs4_opendata; 77struct nfs4_opendata;
76static int _nfs4_proc_open(struct nfs4_opendata *data); 78static int _nfs4_proc_open(struct nfs4_opendata *data);
77static int _nfs4_recover_proc_open(struct nfs4_opendata *data); 79static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
78static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); 80static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
79static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); 81static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
82static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
80static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); 83static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
81static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, 84static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
82 struct nfs_fattr *fattr, struct iattr *sattr, 85 struct nfs_fattr *fattr, struct iattr *sattr,
83 struct nfs4_state *state); 86 struct nfs4_state *state);
84#ifdef CONFIG_NFS_V4_1 87#ifdef CONFIG_NFS_V4_1
85static int nfs41_test_stateid(struct nfs_server *, struct nfs4_state *); 88static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *);
86static int nfs41_free_stateid(struct nfs_server *, struct nfs4_state *); 89static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *);
87#endif 90#endif
88/* Prevent leaks of NFSv4 errors into userland */ 91/* Prevent leaks of NFSv4 errors into userland */
89static int nfs4_map_errors(int err) 92static int nfs4_map_errors(int err)
@@ -259,15 +262,28 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
259{ 262{
260 struct nfs_client *clp = server->nfs_client; 263 struct nfs_client *clp = server->nfs_client;
261 struct nfs4_state *state = exception->state; 264 struct nfs4_state *state = exception->state;
265 struct inode *inode = exception->inode;
262 int ret = errorcode; 266 int ret = errorcode;
263 267
264 exception->retry = 0; 268 exception->retry = 0;
265 switch(errorcode) { 269 switch(errorcode) {
266 case 0: 270 case 0:
267 return 0; 271 return 0;
272 case -NFS4ERR_OPENMODE:
273 if (nfs_have_delegation(inode, FMODE_READ)) {
274 nfs_inode_return_delegation(inode);
275 exception->retry = 1;
276 return 0;
277 }
278 if (state == NULL)
279 break;
280 nfs4_schedule_stateid_recovery(server, state);
281 goto wait_on_recovery;
282 case -NFS4ERR_DELEG_REVOKED:
268 case -NFS4ERR_ADMIN_REVOKED: 283 case -NFS4ERR_ADMIN_REVOKED:
269 case -NFS4ERR_BAD_STATEID: 284 case -NFS4ERR_BAD_STATEID:
270 case -NFS4ERR_OPENMODE: 285 if (state != NULL)
286 nfs_remove_bad_delegation(state->inode);
271 if (state == NULL) 287 if (state == NULL)
272 break; 288 break;
273 nfs4_schedule_stateid_recovery(server, state); 289 nfs4_schedule_stateid_recovery(server, state);
@@ -360,16 +376,14 @@ static void renew_lease(const struct nfs_server *server, unsigned long timestamp
360 * When updating highest_used_slotid there may be "holes" in the bitmap 376 * When updating highest_used_slotid there may be "holes" in the bitmap
361 * so we need to scan down from highest_used_slotid to 0 looking for the now 377 * so we need to scan down from highest_used_slotid to 0 looking for the now
362 * highest slotid in use. 378 * highest slotid in use.
363 * If none found, highest_used_slotid is set to -1. 379 * If none found, highest_used_slotid is set to NFS4_NO_SLOT.
364 * 380 *
365 * Must be called while holding tbl->slot_tbl_lock 381 * Must be called while holding tbl->slot_tbl_lock
366 */ 382 */
367static void 383static void
368nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) 384nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid)
369{ 385{
370 int slotid = free_slotid; 386 BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE);
371
372 BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE);
373 /* clear used bit in bitmap */ 387 /* clear used bit in bitmap */
374 __clear_bit(slotid, tbl->used_slots); 388 __clear_bit(slotid, tbl->used_slots);
375 389
@@ -379,10 +393,16 @@ nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
379 if (slotid < tbl->max_slots) 393 if (slotid < tbl->max_slots)
380 tbl->highest_used_slotid = slotid; 394 tbl->highest_used_slotid = slotid;
381 else 395 else
382 tbl->highest_used_slotid = -1; 396 tbl->highest_used_slotid = NFS4_NO_SLOT;
383 } 397 }
384 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, 398 dprintk("%s: slotid %u highest_used_slotid %d\n", __func__,
385 free_slotid, tbl->highest_used_slotid); 399 slotid, tbl->highest_used_slotid);
400}
401
402bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy)
403{
404 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
405 return true;
386} 406}
387 407
388/* 408/*
@@ -390,16 +410,13 @@ nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
390 */ 410 */
391static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) 411static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
392{ 412{
393 struct rpc_task *task;
394
395 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { 413 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
396 task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); 414 rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq,
397 if (task) 415 nfs4_set_task_privileged, NULL);
398 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
399 return; 416 return;
400 } 417 }
401 418
402 if (ses->fc_slot_table.highest_used_slotid != -1) 419 if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT)
403 return; 420 return;
404 421
405 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); 422 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__);
@@ -412,7 +429,7 @@ static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
412void nfs4_check_drain_bc_complete(struct nfs4_session *ses) 429void nfs4_check_drain_bc_complete(struct nfs4_session *ses)
413{ 430{
414 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || 431 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) ||
415 ses->bc_slot_table.highest_used_slotid != -1) 432 ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT)
416 return; 433 return;
417 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); 434 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__);
418 complete(&ses->bc_slot_table.complete); 435 complete(&ses->bc_slot_table.complete);
@@ -507,25 +524,25 @@ static int nfs4_sequence_done(struct rpc_task *task,
507 * nfs4_find_slot looks for an unset bit in the used_slots bitmap. 524 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
508 * If found, we mark the slot as used, update the highest_used_slotid, 525 * If found, we mark the slot as used, update the highest_used_slotid,
509 * and respectively set up the sequence operation args. 526 * and respectively set up the sequence operation args.
510 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. 527 * The slot number is returned if found, or NFS4_NO_SLOT otherwise.
511 * 528 *
512 * Note: must be called with under the slot_tbl_lock. 529 * Note: must be called with under the slot_tbl_lock.
513 */ 530 */
514static u8 531static u32
515nfs4_find_slot(struct nfs4_slot_table *tbl) 532nfs4_find_slot(struct nfs4_slot_table *tbl)
516{ 533{
517 int slotid; 534 u32 slotid;
518 u8 ret_id = NFS4_MAX_SLOT_TABLE; 535 u32 ret_id = NFS4_NO_SLOT;
519 BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
520 536
521 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", 537 dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
522 __func__, tbl->used_slots[0], tbl->highest_used_slotid, 538 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
523 tbl->max_slots); 539 tbl->max_slots);
524 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); 540 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
525 if (slotid >= tbl->max_slots) 541 if (slotid >= tbl->max_slots)
526 goto out; 542 goto out;
527 __set_bit(slotid, tbl->used_slots); 543 __set_bit(slotid, tbl->used_slots);
528 if (slotid > tbl->highest_used_slotid) 544 if (slotid > tbl->highest_used_slotid ||
545 tbl->highest_used_slotid == NFS4_NO_SLOT)
529 tbl->highest_used_slotid = slotid; 546 tbl->highest_used_slotid = slotid;
530 ret_id = slotid; 547 ret_id = slotid;
531out: 548out:
@@ -534,15 +551,25 @@ out:
534 return ret_id; 551 return ret_id;
535} 552}
536 553
554static void nfs41_init_sequence(struct nfs4_sequence_args *args,
555 struct nfs4_sequence_res *res, int cache_reply)
556{
557 args->sa_session = NULL;
558 args->sa_cache_this = 0;
559 if (cache_reply)
560 args->sa_cache_this = 1;
561 res->sr_session = NULL;
562 res->sr_slot = NULL;
563}
564
537int nfs41_setup_sequence(struct nfs4_session *session, 565int nfs41_setup_sequence(struct nfs4_session *session,
538 struct nfs4_sequence_args *args, 566 struct nfs4_sequence_args *args,
539 struct nfs4_sequence_res *res, 567 struct nfs4_sequence_res *res,
540 int cache_reply,
541 struct rpc_task *task) 568 struct rpc_task *task)
542{ 569{
543 struct nfs4_slot *slot; 570 struct nfs4_slot *slot;
544 struct nfs4_slot_table *tbl; 571 struct nfs4_slot_table *tbl;
545 u8 slotid; 572 u32 slotid;
546 573
547 dprintk("--> %s\n", __func__); 574 dprintk("--> %s\n", __func__);
548 /* slot already allocated? */ 575 /* slot already allocated? */
@@ -570,7 +597,7 @@ int nfs41_setup_sequence(struct nfs4_session *session,
570 } 597 }
571 598
572 slotid = nfs4_find_slot(tbl); 599 slotid = nfs4_find_slot(tbl);
573 if (slotid == NFS4_MAX_SLOT_TABLE) { 600 if (slotid == NFS4_NO_SLOT) {
574 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 601 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
575 spin_unlock(&tbl->slot_tbl_lock); 602 spin_unlock(&tbl->slot_tbl_lock);
576 dprintk("<-- %s: no free slots\n", __func__); 603 dprintk("<-- %s: no free slots\n", __func__);
@@ -582,7 +609,6 @@ int nfs41_setup_sequence(struct nfs4_session *session,
582 slot = tbl->slots + slotid; 609 slot = tbl->slots + slotid;
583 args->sa_session = session; 610 args->sa_session = session;
584 args->sa_slotid = slotid; 611 args->sa_slotid = slotid;
585 args->sa_cache_this = cache_reply;
586 612
587 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); 613 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
588 614
@@ -602,24 +628,19 @@ EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
602int nfs4_setup_sequence(const struct nfs_server *server, 628int nfs4_setup_sequence(const struct nfs_server *server,
603 struct nfs4_sequence_args *args, 629 struct nfs4_sequence_args *args,
604 struct nfs4_sequence_res *res, 630 struct nfs4_sequence_res *res,
605 int cache_reply,
606 struct rpc_task *task) 631 struct rpc_task *task)
607{ 632{
608 struct nfs4_session *session = nfs4_get_session(server); 633 struct nfs4_session *session = nfs4_get_session(server);
609 int ret = 0; 634 int ret = 0;
610 635
611 if (session == NULL) { 636 if (session == NULL)
612 args->sa_session = NULL;
613 res->sr_session = NULL;
614 goto out; 637 goto out;
615 }
616 638
617 dprintk("--> %s clp %p session %p sr_slot %td\n", 639 dprintk("--> %s clp %p session %p sr_slot %td\n",
618 __func__, session->clp, session, res->sr_slot ? 640 __func__, session->clp, session, res->sr_slot ?
619 res->sr_slot - session->fc_slot_table.slots : -1); 641 res->sr_slot - session->fc_slot_table.slots : -1);
620 642
621 ret = nfs41_setup_sequence(session, args, res, cache_reply, 643 ret = nfs41_setup_sequence(session, args, res, task);
622 task);
623out: 644out:
624 dprintk("<-- %s status=%d\n", __func__, ret); 645 dprintk("<-- %s status=%d\n", __func__, ret);
625 return ret; 646 return ret;
@@ -629,7 +650,6 @@ struct nfs41_call_sync_data {
629 const struct nfs_server *seq_server; 650 const struct nfs_server *seq_server;
630 struct nfs4_sequence_args *seq_args; 651 struct nfs4_sequence_args *seq_args;
631 struct nfs4_sequence_res *seq_res; 652 struct nfs4_sequence_res *seq_res;
632 int cache_reply;
633}; 653};
634 654
635static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) 655static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
@@ -639,7 +659,7 @@ static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
639 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); 659 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
640 660
641 if (nfs4_setup_sequence(data->seq_server, data->seq_args, 661 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
642 data->seq_res, data->cache_reply, task)) 662 data->seq_res, task))
643 return; 663 return;
644 rpc_call_start(task); 664 rpc_call_start(task);
645} 665}
@@ -657,12 +677,12 @@ static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
657 nfs41_sequence_done(task, data->seq_res); 677 nfs41_sequence_done(task, data->seq_res);
658} 678}
659 679
660struct rpc_call_ops nfs41_call_sync_ops = { 680static const struct rpc_call_ops nfs41_call_sync_ops = {
661 .rpc_call_prepare = nfs41_call_sync_prepare, 681 .rpc_call_prepare = nfs41_call_sync_prepare,
662 .rpc_call_done = nfs41_call_sync_done, 682 .rpc_call_done = nfs41_call_sync_done,
663}; 683};
664 684
665struct rpc_call_ops nfs41_call_priv_sync_ops = { 685static const struct rpc_call_ops nfs41_call_priv_sync_ops = {
666 .rpc_call_prepare = nfs41_call_priv_sync_prepare, 686 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
667 .rpc_call_done = nfs41_call_sync_done, 687 .rpc_call_done = nfs41_call_sync_done,
668}; 688};
@@ -672,7 +692,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
672 struct rpc_message *msg, 692 struct rpc_message *msg,
673 struct nfs4_sequence_args *args, 693 struct nfs4_sequence_args *args,
674 struct nfs4_sequence_res *res, 694 struct nfs4_sequence_res *res,
675 int cache_reply,
676 int privileged) 695 int privileged)
677{ 696{
678 int ret; 697 int ret;
@@ -681,7 +700,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
681 .seq_server = server, 700 .seq_server = server,
682 .seq_args = args, 701 .seq_args = args,
683 .seq_res = res, 702 .seq_res = res,
684 .cache_reply = cache_reply,
685 }; 703 };
686 struct rpc_task_setup task_setup = { 704 struct rpc_task_setup task_setup = {
687 .rpc_client = clnt, 705 .rpc_client = clnt,
@@ -690,7 +708,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
690 .callback_data = &data 708 .callback_data = &data
691 }; 709 };
692 710
693 res->sr_slot = NULL;
694 if (privileged) 711 if (privileged)
695 task_setup.callback_ops = &nfs41_call_priv_sync_ops; 712 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
696 task = rpc_run_task(&task_setup); 713 task = rpc_run_task(&task_setup);
@@ -710,10 +727,17 @@ int _nfs4_call_sync_session(struct rpc_clnt *clnt,
710 struct nfs4_sequence_res *res, 727 struct nfs4_sequence_res *res,
711 int cache_reply) 728 int cache_reply)
712{ 729{
713 return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0); 730 nfs41_init_sequence(args, res, cache_reply);
731 return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0);
714} 732}
715 733
716#else 734#else
735static inline
736void nfs41_init_sequence(struct nfs4_sequence_args *args,
737 struct nfs4_sequence_res *res, int cache_reply)
738{
739}
740
717static int nfs4_sequence_done(struct rpc_task *task, 741static int nfs4_sequence_done(struct rpc_task *task,
718 struct nfs4_sequence_res *res) 742 struct nfs4_sequence_res *res)
719{ 743{
@@ -728,7 +752,7 @@ int _nfs4_call_sync(struct rpc_clnt *clnt,
728 struct nfs4_sequence_res *res, 752 struct nfs4_sequence_res *res,
729 int cache_reply) 753 int cache_reply)
730{ 754{
731 args->sa_session = res->sr_session = NULL; 755 nfs41_init_sequence(args, res, cache_reply);
732 return rpc_call_sync(clnt, msg, 0); 756 return rpc_call_sync(clnt, msg, 0);
733} 757}
734 758
@@ -815,20 +839,22 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
815 p->o_arg.open_flags = flags; 839 p->o_arg.open_flags = flags;
816 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); 840 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
817 p->o_arg.clientid = server->nfs_client->cl_clientid; 841 p->o_arg.clientid = server->nfs_client->cl_clientid;
818 p->o_arg.id = sp->so_owner_id.id; 842 p->o_arg.id = sp->so_seqid.owner_id;
819 p->o_arg.name = &dentry->d_name; 843 p->o_arg.name = &dentry->d_name;
820 p->o_arg.server = server; 844 p->o_arg.server = server;
821 p->o_arg.bitmask = server->attr_bitmask; 845 p->o_arg.bitmask = server->attr_bitmask;
822 p->o_arg.dir_bitmask = server->cache_consistency_bitmask; 846 p->o_arg.dir_bitmask = server->cache_consistency_bitmask;
823 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; 847 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
824 if (flags & O_CREAT) { 848 if (attrs != NULL && attrs->ia_valid != 0) {
825 u32 *s; 849 __be32 verf[2];
826 850
827 p->o_arg.u.attrs = &p->attrs; 851 p->o_arg.u.attrs = &p->attrs;
828 memcpy(&p->attrs, attrs, sizeof(p->attrs)); 852 memcpy(&p->attrs, attrs, sizeof(p->attrs));
829 s = (u32 *) p->o_arg.u.verifier.data; 853
830 s[0] = jiffies; 854 verf[0] = jiffies;
831 s[1] = current->pid; 855 verf[1] = current->pid;
856 memcpy(p->o_arg.u.verifier.data, verf,
857 sizeof(p->o_arg.u.verifier.data));
832 } 858 }
833 p->c_arg.fh = &p->o_res.fh; 859 p->c_arg.fh = &p->o_res.fh;
834 p->c_arg.stateid = &p->o_res.stateid; 860 p->c_arg.stateid = &p->o_res.stateid;
@@ -878,7 +904,7 @@ static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode
878{ 904{
879 int ret = 0; 905 int ret = 0;
880 906
881 if (open_mode & O_EXCL) 907 if (open_mode & (O_EXCL|O_TRUNC))
882 goto out; 908 goto out;
883 switch (mode & (FMODE_READ|FMODE_WRITE)) { 909 switch (mode & (FMODE_READ|FMODE_WRITE)) {
884 case FMODE_READ: 910 case FMODE_READ:
@@ -927,8 +953,8 @@ static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
927static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) 953static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
928{ 954{
929 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) 955 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
930 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); 956 nfs4_stateid_copy(&state->stateid, stateid);
931 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); 957 nfs4_stateid_copy(&state->open_stateid, stateid);
932 switch (fmode) { 958 switch (fmode) {
933 case FMODE_READ: 959 case FMODE_READ:
934 set_bit(NFS_O_RDONLY_STATE, &state->flags); 960 set_bit(NFS_O_RDONLY_STATE, &state->flags);
@@ -956,7 +982,7 @@ static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_s
956 */ 982 */
957 write_seqlock(&state->seqlock); 983 write_seqlock(&state->seqlock);
958 if (deleg_stateid != NULL) { 984 if (deleg_stateid != NULL) {
959 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); 985 nfs4_stateid_copy(&state->stateid, deleg_stateid);
960 set_bit(NFS_DELEGATED_STATE, &state->flags); 986 set_bit(NFS_DELEGATED_STATE, &state->flags);
961 } 987 }
962 if (open_stateid != NULL) 988 if (open_stateid != NULL)
@@ -987,7 +1013,7 @@ static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stat
987 1013
988 if (delegation == NULL) 1014 if (delegation == NULL)
989 delegation = &deleg_cur->stateid; 1015 delegation = &deleg_cur->stateid;
990 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) 1016 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
991 goto no_delegation_unlock; 1017 goto no_delegation_unlock;
992 1018
993 nfs_mark_delegation_referenced(deleg_cur); 1019 nfs_mark_delegation_referenced(deleg_cur);
@@ -1026,7 +1052,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1026 struct nfs4_state *state = opendata->state; 1052 struct nfs4_state *state = opendata->state;
1027 struct nfs_inode *nfsi = NFS_I(state->inode); 1053 struct nfs_inode *nfsi = NFS_I(state->inode);
1028 struct nfs_delegation *delegation; 1054 struct nfs_delegation *delegation;
1029 int open_mode = opendata->o_arg.open_flags & O_EXCL; 1055 int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC);
1030 fmode_t fmode = opendata->o_arg.fmode; 1056 fmode_t fmode = opendata->o_arg.fmode;
1031 nfs4_stateid stateid; 1057 nfs4_stateid stateid;
1032 int ret = -EAGAIN; 1058 int ret = -EAGAIN;
@@ -1048,7 +1074,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1048 break; 1074 break;
1049 } 1075 }
1050 /* Save the delegation */ 1076 /* Save the delegation */
1051 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); 1077 nfs4_stateid_copy(&stateid, &delegation->stateid);
1052 rcu_read_unlock(); 1078 rcu_read_unlock();
1053 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); 1079 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1054 if (ret != 0) 1080 if (ret != 0)
@@ -1090,6 +1116,7 @@ static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data
1090 if (state == NULL) 1116 if (state == NULL)
1091 goto err_put_inode; 1117 goto err_put_inode;
1092 if (data->o_res.delegation_type != 0) { 1118 if (data->o_res.delegation_type != 0) {
1119 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
1093 int delegation_flags = 0; 1120 int delegation_flags = 0;
1094 1121
1095 rcu_read_lock(); 1122 rcu_read_lock();
@@ -1101,7 +1128,7 @@ static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data
1101 pr_err_ratelimited("NFS: Broken NFSv4 server %s is " 1128 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1102 "returning a delegation for " 1129 "returning a delegation for "
1103 "OPEN(CLAIM_DELEGATE_CUR)\n", 1130 "OPEN(CLAIM_DELEGATE_CUR)\n",
1104 NFS_CLIENT(inode)->cl_server); 1131 clp->cl_hostname);
1105 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) 1132 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1106 nfs_inode_set_delegation(state->inode, 1133 nfs_inode_set_delegation(state->inode,
1107 data->owner->so_cred, 1134 data->owner->so_cred,
@@ -1210,10 +1237,10 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
1210 * Check if we need to update the current stateid. 1237 * Check if we need to update the current stateid.
1211 */ 1238 */
1212 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && 1239 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1213 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { 1240 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1214 write_seqlock(&state->seqlock); 1241 write_seqlock(&state->seqlock);
1215 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) 1242 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1216 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); 1243 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1217 write_sequnlock(&state->seqlock); 1244 write_sequnlock(&state->seqlock);
1218 } 1245 }
1219 return 0; 1246 return 0;
@@ -1282,8 +1309,7 @@ static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs
1282 if (IS_ERR(opendata)) 1309 if (IS_ERR(opendata))
1283 return PTR_ERR(opendata); 1310 return PTR_ERR(opendata);
1284 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; 1311 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1285 memcpy(opendata->o_arg.u.delegation.data, stateid->data, 1312 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1286 sizeof(opendata->o_arg.u.delegation.data));
1287 ret = nfs4_open_recover(opendata, state); 1313 ret = nfs4_open_recover(opendata, state);
1288 nfs4_opendata_put(opendata); 1314 nfs4_opendata_put(opendata);
1289 return ret; 1315 return ret;
@@ -1319,8 +1345,11 @@ int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state
1319 * The show must go on: exit, but mark the 1345 * The show must go on: exit, but mark the
1320 * stateid as needing recovery. 1346 * stateid as needing recovery.
1321 */ 1347 */
1348 case -NFS4ERR_DELEG_REVOKED:
1322 case -NFS4ERR_ADMIN_REVOKED: 1349 case -NFS4ERR_ADMIN_REVOKED:
1323 case -NFS4ERR_BAD_STATEID: 1350 case -NFS4ERR_BAD_STATEID:
1351 nfs_inode_find_state_and_recover(state->inode,
1352 stateid);
1324 nfs4_schedule_stateid_recovery(server, state); 1353 nfs4_schedule_stateid_recovery(server, state);
1325 case -EKEYEXPIRED: 1354 case -EKEYEXPIRED:
1326 /* 1355 /*
@@ -1345,8 +1374,7 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1345 1374
1346 data->rpc_status = task->tk_status; 1375 data->rpc_status = task->tk_status;
1347 if (data->rpc_status == 0) { 1376 if (data->rpc_status == 0) {
1348 memcpy(data->o_res.stateid.data, data->c_res.stateid.data, 1377 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1349 sizeof(data->o_res.stateid.data));
1350 nfs_confirm_seqid(&data->owner->so_seqid, 0); 1378 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1351 renew_lease(data->o_res.server, data->timestamp); 1379 renew_lease(data->o_res.server, data->timestamp);
1352 data->rpc_done = 1; 1380 data->rpc_done = 1;
@@ -1440,7 +1468,7 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1440 rcu_read_unlock(); 1468 rcu_read_unlock();
1441 } 1469 }
1442 /* Update sequence id. */ 1470 /* Update sequence id. */
1443 data->o_arg.id = sp->so_owner_id.id; 1471 data->o_arg.id = sp->so_seqid.owner_id;
1444 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; 1472 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1445 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { 1473 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1446 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; 1474 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
@@ -1449,7 +1477,7 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1449 data->timestamp = jiffies; 1477 data->timestamp = jiffies;
1450 if (nfs4_setup_sequence(data->o_arg.server, 1478 if (nfs4_setup_sequence(data->o_arg.server,
1451 &data->o_arg.seq_args, 1479 &data->o_arg.seq_args,
1452 &data->o_res.seq_res, 1, task)) 1480 &data->o_res.seq_res, task))
1453 return; 1481 return;
1454 rpc_call_start(task); 1482 rpc_call_start(task);
1455 return; 1483 return;
@@ -1551,6 +1579,7 @@ static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1551 }; 1579 };
1552 int status; 1580 int status;
1553 1581
1582 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1554 kref_get(&data->kref); 1583 kref_get(&data->kref);
1555 data->rpc_done = 0; 1584 data->rpc_done = 0;
1556 data->rpc_status = 0; 1585 data->rpc_status = 0;
@@ -1712,15 +1741,32 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta
1712} 1741}
1713 1742
1714#if defined(CONFIG_NFS_V4_1) 1743#if defined(CONFIG_NFS_V4_1)
1715static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) 1744static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *stateid, unsigned int flags)
1716{ 1745{
1717 int status; 1746 int status = NFS_OK;
1718 struct nfs_server *server = NFS_SERVER(state->inode); 1747 struct nfs_server *server = NFS_SERVER(state->inode);
1719 1748
1720 status = nfs41_test_stateid(server, state); 1749 if (state->flags & flags) {
1721 if (status == NFS_OK) 1750 status = nfs41_test_stateid(server, stateid);
1722 return 0; 1751 if (status != NFS_OK) {
1723 nfs41_free_stateid(server, state); 1752 nfs41_free_stateid(server, stateid);
1753 state->flags &= ~flags;
1754 }
1755 }
1756 return status;
1757}
1758
1759static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1760{
1761 int deleg_status, open_status;
1762 int deleg_flags = 1 << NFS_DELEGATED_STATE;
1763 int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE);
1764
1765 deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags);
1766 open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags);
1767
1768 if ((deleg_status == NFS_OK) && (open_status == NFS_OK))
1769 return NFS_OK;
1724 return nfs4_open_expired(sp, state); 1770 return nfs4_open_expired(sp, state);
1725} 1771}
1726#endif 1772#endif
@@ -1754,7 +1800,8 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode
1754 1800
1755 /* Protect against reboot recovery conflicts */ 1801 /* Protect against reboot recovery conflicts */
1756 status = -ENOMEM; 1802 status = -ENOMEM;
1757 if (!(sp = nfs4_get_state_owner(server, cred))) { 1803 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
1804 if (sp == NULL) {
1758 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); 1805 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1759 goto out_err; 1806 goto out_err;
1760 } 1807 }
@@ -1829,7 +1876,7 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry,
1829 * the user though... 1876 * the user though...
1830 */ 1877 */
1831 if (status == -NFS4ERR_BAD_SEQID) { 1878 if (status == -NFS4ERR_BAD_SEQID) {
1832 printk(KERN_WARNING "NFS: v4 server %s " 1879 pr_warn_ratelimited("NFS: v4 server %s "
1833 " returned a bad sequence-id error!\n", 1880 " returned a bad sequence-id error!\n",
1834 NFS_SERVER(dir)->nfs_client->cl_hostname); 1881 NFS_SERVER(dir)->nfs_client->cl_hostname);
1835 exception.retry = 1; 1882 exception.retry = 1;
@@ -1882,12 +1929,14 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1882 1929
1883 nfs_fattr_init(fattr); 1930 nfs_fattr_init(fattr);
1884 1931
1885 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { 1932 if (state != NULL) {
1933 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
1934 current->files, current->tgid);
1935 } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
1936 FMODE_WRITE)) {
1886 /* Use that stateid */ 1937 /* Use that stateid */
1887 } else if (state != NULL) {
1888 nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid);
1889 } else 1938 } else
1890 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); 1939 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
1891 1940
1892 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); 1941 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
1893 if (status == 0 && state != NULL) 1942 if (status == 0 && state != NULL)
@@ -1900,7 +1949,10 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1900 struct nfs4_state *state) 1949 struct nfs4_state *state)
1901{ 1950{
1902 struct nfs_server *server = NFS_SERVER(inode); 1951 struct nfs_server *server = NFS_SERVER(inode);
1903 struct nfs4_exception exception = { }; 1952 struct nfs4_exception exception = {
1953 .state = state,
1954 .inode = inode,
1955 };
1904 int err; 1956 int err;
1905 do { 1957 do {
1906 err = nfs4_handle_exception(server, 1958 err = nfs4_handle_exception(server,
@@ -1954,6 +2006,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
1954 struct nfs4_state *state = calldata->state; 2006 struct nfs4_state *state = calldata->state;
1955 struct nfs_server *server = NFS_SERVER(calldata->inode); 2007 struct nfs_server *server = NFS_SERVER(calldata->inode);
1956 2008
2009 dprintk("%s: begin!\n", __func__);
1957 if (!nfs4_sequence_done(task, &calldata->res.seq_res)) 2010 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
1958 return; 2011 return;
1959 /* hmm. we are done with the inode, and in the process of freeing 2012 /* hmm. we are done with the inode, and in the process of freeing
@@ -1981,6 +2034,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
1981 } 2034 }
1982 nfs_release_seqid(calldata->arg.seqid); 2035 nfs_release_seqid(calldata->arg.seqid);
1983 nfs_refresh_inode(calldata->inode, calldata->res.fattr); 2036 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2037 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
1984} 2038}
1985 2039
1986static void nfs4_close_prepare(struct rpc_task *task, void *data) 2040static void nfs4_close_prepare(struct rpc_task *task, void *data)
@@ -1989,6 +2043,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
1989 struct nfs4_state *state = calldata->state; 2043 struct nfs4_state *state = calldata->state;
1990 int call_close = 0; 2044 int call_close = 0;
1991 2045
2046 dprintk("%s: begin!\n", __func__);
1992 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) 2047 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1993 return; 2048 return;
1994 2049
@@ -2013,7 +2068,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
2013 if (!call_close) { 2068 if (!call_close) {
2014 /* Note: exit _without_ calling nfs4_close_done */ 2069 /* Note: exit _without_ calling nfs4_close_done */
2015 task->tk_action = NULL; 2070 task->tk_action = NULL;
2016 return; 2071 goto out;
2017 } 2072 }
2018 2073
2019 if (calldata->arg.fmode == 0) { 2074 if (calldata->arg.fmode == 0) {
@@ -2022,17 +2077,20 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
2022 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { 2077 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) {
2023 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, 2078 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq,
2024 task, NULL); 2079 task, NULL);
2025 return; 2080 goto out;
2026 } 2081 }
2027 } 2082 }
2028 2083
2029 nfs_fattr_init(calldata->res.fattr); 2084 nfs_fattr_init(calldata->res.fattr);
2030 calldata->timestamp = jiffies; 2085 calldata->timestamp = jiffies;
2031 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), 2086 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode),
2032 &calldata->arg.seq_args, &calldata->res.seq_res, 2087 &calldata->arg.seq_args,
2033 1, task)) 2088 &calldata->res.seq_res,
2034 return; 2089 task))
2090 goto out;
2035 rpc_call_start(task); 2091 rpc_call_start(task);
2092out:
2093 dprintk("%s: done!\n", __func__);
2036} 2094}
2037 2095
2038static const struct rpc_call_ops nfs4_close_ops = { 2096static const struct rpc_call_ops nfs4_close_ops = {
@@ -2074,6 +2132,7 @@ int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc)
2074 calldata = kzalloc(sizeof(*calldata), gfp_mask); 2132 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2075 if (calldata == NULL) 2133 if (calldata == NULL)
2076 goto out; 2134 goto out;
2135 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2077 calldata->inode = state->inode; 2136 calldata->inode = state->inode;
2078 calldata->state = state; 2137 calldata->state = state;
2079 calldata->arg.fh = NFS_FH(state->inode); 2138 calldata->arg.fh = NFS_FH(state->inode);
@@ -2182,6 +2241,7 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
2182 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; 2241 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2183 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 2242 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2184 server->acl_bitmask = res.acl_bitmask; 2243 server->acl_bitmask = res.acl_bitmask;
2244 server->fh_expire_type = res.fh_expire_type;
2185 } 2245 }
2186 2246
2187 return status; 2247 return status;
@@ -2303,7 +2363,6 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2303 return nfs4_map_errors(status); 2363 return nfs4_map_errors(status);
2304} 2364}
2305 2365
2306static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
2307/* 2366/*
2308 * Get locations and (maybe) other attributes of a referral. 2367 * Get locations and (maybe) other attributes of a referral.
2309 * Note that we'll actually follow the referral later when 2368 * Note that we'll actually follow the referral later when
@@ -2420,6 +2479,10 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2420 } 2479 }
2421 } 2480 }
2422 2481
2482 /* Deal with open(O_TRUNC) */
2483 if (sattr->ia_valid & ATTR_OPEN)
2484 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
2485
2423 status = nfs4_do_setattr(inode, cred, fattr, sattr, state); 2486 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2424 if (status == 0) 2487 if (status == 0)
2425 nfs_setattr_update_inode(inode, sattr); 2488 nfs_setattr_update_inode(inode, sattr);
@@ -2494,7 +2557,7 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
2494 struct nfs_server *server = NFS_SERVER(inode); 2557 struct nfs_server *server = NFS_SERVER(inode);
2495 struct nfs4_accessargs args = { 2558 struct nfs4_accessargs args = {
2496 .fh = NFS_FH(inode), 2559 .fh = NFS_FH(inode),
2497 .bitmask = server->attr_bitmask, 2560 .bitmask = server->cache_consistency_bitmask,
2498 }; 2561 };
2499 struct nfs4_accessres res = { 2562 struct nfs4_accessres res = {
2500 .server = server, 2563 .server = server,
@@ -2712,8 +2775,18 @@ static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2712 2775
2713 args->bitmask = server->cache_consistency_bitmask; 2776 args->bitmask = server->cache_consistency_bitmask;
2714 res->server = server; 2777 res->server = server;
2715 res->seq_res.sr_slot = NULL;
2716 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; 2778 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2779 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
2780}
2781
2782static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
2783{
2784 if (nfs4_setup_sequence(NFS_SERVER(data->dir),
2785 &data->args.seq_args,
2786 &data->res.seq_res,
2787 task))
2788 return;
2789 rpc_call_start(task);
2717} 2790}
2718 2791
2719static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir) 2792static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
@@ -2738,6 +2811,17 @@ static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
2738 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; 2811 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
2739 arg->bitmask = server->attr_bitmask; 2812 arg->bitmask = server->attr_bitmask;
2740 res->server = server; 2813 res->server = server;
2814 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
2815}
2816
2817static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
2818{
2819 if (nfs4_setup_sequence(NFS_SERVER(data->old_dir),
2820 &data->args.seq_args,
2821 &data->res.seq_res,
2822 task))
2823 return;
2824 rpc_call_start(task);
2741} 2825}
2742 2826
2743static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 2827static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
@@ -3232,6 +3316,17 @@ static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message
3232 data->timestamp = jiffies; 3316 data->timestamp = jiffies;
3233 data->read_done_cb = nfs4_read_done_cb; 3317 data->read_done_cb = nfs4_read_done_cb;
3234 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; 3318 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3319 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3320}
3321
3322static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3323{
3324 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
3325 &data->args.seq_args,
3326 &data->res.seq_res,
3327 task))
3328 return;
3329 rpc_call_start(task);
3235} 3330}
3236 3331
3237/* Reset the the nfs_read_data to send the read to the MDS. */ 3332/* Reset the the nfs_read_data to send the read to the MDS. */
@@ -3305,6 +3400,17 @@ static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_messag
3305 data->timestamp = jiffies; 3400 data->timestamp = jiffies;
3306 3401
3307 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; 3402 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3403 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3404}
3405
3406static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
3407{
3408 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
3409 &data->args.seq_args,
3410 &data->res.seq_res,
3411 task))
3412 return;
3413 rpc_call_start(task);
3308} 3414}
3309 3415
3310static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) 3416static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data)
@@ -3339,6 +3445,7 @@ static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_messa
3339 data->write_done_cb = nfs4_commit_done_cb; 3445 data->write_done_cb = nfs4_commit_done_cb;
3340 data->res.server = server; 3446 data->res.server = server;
3341 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; 3447 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3448 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3342} 3449}
3343 3450
3344struct nfs4_renewdata { 3451struct nfs4_renewdata {
@@ -3575,8 +3682,8 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3575 } 3682 }
3576 if (npages > 1) { 3683 if (npages > 1) {
3577 /* for decoding across pages */ 3684 /* for decoding across pages */
3578 args.acl_scratch = alloc_page(GFP_KERNEL); 3685 res.acl_scratch = alloc_page(GFP_KERNEL);
3579 if (!args.acl_scratch) 3686 if (!res.acl_scratch)
3580 goto out_free; 3687 goto out_free;
3581 } 3688 }
3582 args.acl_len = npages * PAGE_SIZE; 3689 args.acl_len = npages * PAGE_SIZE;
@@ -3612,8 +3719,8 @@ out_free:
3612 for (i = 0; i < npages; i++) 3719 for (i = 0; i < npages; i++)
3613 if (pages[i]) 3720 if (pages[i])
3614 __free_page(pages[i]); 3721 __free_page(pages[i]);
3615 if (args.acl_scratch) 3722 if (res.acl_scratch)
3616 __free_page(args.acl_scratch); 3723 __free_page(res.acl_scratch);
3617 return ret; 3724 return ret;
3618} 3725}
3619 3726
@@ -3714,8 +3821,11 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
3714 if (task->tk_status >= 0) 3821 if (task->tk_status >= 0)
3715 return 0; 3822 return 0;
3716 switch(task->tk_status) { 3823 switch(task->tk_status) {
3824 case -NFS4ERR_DELEG_REVOKED:
3717 case -NFS4ERR_ADMIN_REVOKED: 3825 case -NFS4ERR_ADMIN_REVOKED:
3718 case -NFS4ERR_BAD_STATEID: 3826 case -NFS4ERR_BAD_STATEID:
3827 if (state != NULL)
3828 nfs_remove_bad_delegation(state->inode);
3719 case -NFS4ERR_OPENMODE: 3829 case -NFS4ERR_OPENMODE:
3720 if (state == NULL) 3830 if (state == NULL)
3721 break; 3831 break;
@@ -3764,6 +3874,16 @@ wait_on_recovery:
3764 return -EAGAIN; 3874 return -EAGAIN;
3765} 3875}
3766 3876
3877static void nfs4_construct_boot_verifier(struct nfs_client *clp,
3878 nfs4_verifier *bootverf)
3879{
3880 __be32 verf[2];
3881
3882 verf[0] = htonl((u32)clp->cl_boot_time.tv_sec);
3883 verf[1] = htonl((u32)clp->cl_boot_time.tv_nsec);
3884 memcpy(bootverf->data, verf, sizeof(bootverf->data));
3885}
3886
3767int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, 3887int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3768 unsigned short port, struct rpc_cred *cred, 3888 unsigned short port, struct rpc_cred *cred,
3769 struct nfs4_setclientid_res *res) 3889 struct nfs4_setclientid_res *res)
@@ -3780,15 +3900,13 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3780 .rpc_resp = res, 3900 .rpc_resp = res,
3781 .rpc_cred = cred, 3901 .rpc_cred = cred,
3782 }; 3902 };
3783 __be32 *p;
3784 int loop = 0; 3903 int loop = 0;
3785 int status; 3904 int status;
3786 3905
3787 p = (__be32*)sc_verifier.data; 3906 nfs4_construct_boot_verifier(clp, &sc_verifier);
3788 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3789 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3790 3907
3791 for(;;) { 3908 for(;;) {
3909 rcu_read_lock();
3792 setclientid.sc_name_len = scnprintf(setclientid.sc_name, 3910 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3793 sizeof(setclientid.sc_name), "%s/%s %s %s %u", 3911 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3794 clp->cl_ipaddr, 3912 clp->cl_ipaddr,
@@ -3805,6 +3923,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3805 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, 3923 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3806 sizeof(setclientid.sc_uaddr), "%s.%u.%u", 3924 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3807 clp->cl_ipaddr, port >> 8, port & 255); 3925 clp->cl_ipaddr, port >> 8, port & 255);
3926 rcu_read_unlock();
3808 3927
3809 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 3928 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
3810 if (status != -NFS4ERR_CLID_INUSE) 3929 if (status != -NFS4ERR_CLID_INUSE)
@@ -3891,7 +4010,7 @@ static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3891 4010
3892 if (nfs4_setup_sequence(d_data->res.server, 4011 if (nfs4_setup_sequence(d_data->res.server,
3893 &d_data->args.seq_args, 4012 &d_data->args.seq_args,
3894 &d_data->res.seq_res, 1, task)) 4013 &d_data->res.seq_res, task))
3895 return; 4014 return;
3896 rpc_call_start(task); 4015 rpc_call_start(task);
3897} 4016}
@@ -3925,11 +4044,12 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
3925 data = kzalloc(sizeof(*data), GFP_NOFS); 4044 data = kzalloc(sizeof(*data), GFP_NOFS);
3926 if (data == NULL) 4045 if (data == NULL)
3927 return -ENOMEM; 4046 return -ENOMEM;
4047 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3928 data->args.fhandle = &data->fh; 4048 data->args.fhandle = &data->fh;
3929 data->args.stateid = &data->stateid; 4049 data->args.stateid = &data->stateid;
3930 data->args.bitmask = server->attr_bitmask; 4050 data->args.bitmask = server->attr_bitmask;
3931 nfs_copy_fh(&data->fh, NFS_FH(inode)); 4051 nfs_copy_fh(&data->fh, NFS_FH(inode));
3932 memcpy(&data->stateid, stateid, sizeof(data->stateid)); 4052 nfs4_stateid_copy(&data->stateid, stateid);
3933 data->res.fattr = &data->fattr; 4053 data->res.fattr = &data->fattr;
3934 data->res.server = server; 4054 data->res.server = server;
3935 nfs_fattr_init(data->res.fattr); 4055 nfs_fattr_init(data->res.fattr);
@@ -4016,7 +4136,7 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
4016 if (status != 0) 4136 if (status != 0)
4017 goto out; 4137 goto out;
4018 lsp = request->fl_u.nfs4_fl.owner; 4138 lsp = request->fl_u.nfs4_fl.owner;
4019 arg.lock_owner.id = lsp->ls_id.id; 4139 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4020 arg.lock_owner.s_dev = server->s_dev; 4140 arg.lock_owner.s_dev = server->s_dev;
4021 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); 4141 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4022 switch (status) { 4142 switch (status) {
@@ -4112,9 +4232,8 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
4112 return; 4232 return;
4113 switch (task->tk_status) { 4233 switch (task->tk_status) {
4114 case 0: 4234 case 0:
4115 memcpy(calldata->lsp->ls_stateid.data, 4235 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4116 calldata->res.stateid.data, 4236 &calldata->res.stateid);
4117 sizeof(calldata->lsp->ls_stateid.data));
4118 renew_lease(calldata->server, calldata->timestamp); 4237 renew_lease(calldata->server, calldata->timestamp);
4119 break; 4238 break;
4120 case -NFS4ERR_BAD_STATEID: 4239 case -NFS4ERR_BAD_STATEID:
@@ -4142,7 +4261,7 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4142 calldata->timestamp = jiffies; 4261 calldata->timestamp = jiffies;
4143 if (nfs4_setup_sequence(calldata->server, 4262 if (nfs4_setup_sequence(calldata->server,
4144 &calldata->arg.seq_args, 4263 &calldata->arg.seq_args,
4145 &calldata->res.seq_res, 1, task)) 4264 &calldata->res.seq_res, task))
4146 return; 4265 return;
4147 rpc_call_start(task); 4266 rpc_call_start(task);
4148} 4267}
@@ -4182,6 +4301,7 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4182 return ERR_PTR(-ENOMEM); 4301 return ERR_PTR(-ENOMEM);
4183 } 4302 }
4184 4303
4304 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4185 msg.rpc_argp = &data->arg; 4305 msg.rpc_argp = &data->arg;
4186 msg.rpc_resp = &data->res; 4306 msg.rpc_resp = &data->res;
4187 task_setup_data.callback_data = data; 4307 task_setup_data.callback_data = data;
@@ -4261,7 +4381,7 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4261 goto out_free_seqid; 4381 goto out_free_seqid;
4262 p->arg.lock_stateid = &lsp->ls_stateid; 4382 p->arg.lock_stateid = &lsp->ls_stateid;
4263 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; 4383 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4264 p->arg.lock_owner.id = lsp->ls_id.id; 4384 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
4265 p->arg.lock_owner.s_dev = server->s_dev; 4385 p->arg.lock_owner.s_dev = server->s_dev;
4266 p->res.lock_seqid = p->arg.lock_seqid; 4386 p->res.lock_seqid = p->arg.lock_seqid;
4267 p->lsp = lsp; 4387 p->lsp = lsp;
@@ -4297,7 +4417,7 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4297 data->timestamp = jiffies; 4417 data->timestamp = jiffies;
4298 if (nfs4_setup_sequence(data->server, 4418 if (nfs4_setup_sequence(data->server,
4299 &data->arg.seq_args, 4419 &data->arg.seq_args,
4300 &data->res.seq_res, 1, task)) 4420 &data->res.seq_res, task))
4301 return; 4421 return;
4302 rpc_call_start(task); 4422 rpc_call_start(task);
4303 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); 4423 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
@@ -4326,8 +4446,7 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4326 goto out; 4446 goto out;
4327 } 4447 }
4328 if (data->rpc_status == 0) { 4448 if (data->rpc_status == 0) {
4329 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, 4449 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4330 sizeof(data->lsp->ls_stateid.data));
4331 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; 4450 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4332 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); 4451 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4333 } 4452 }
@@ -4415,6 +4534,7 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
4415 data->arg.reclaim = NFS_LOCK_RECLAIM; 4534 data->arg.reclaim = NFS_LOCK_RECLAIM;
4416 task_setup_data.callback_ops = &nfs4_recover_lock_ops; 4535 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4417 } 4536 }
4537 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4418 msg.rpc_argp = &data->arg; 4538 msg.rpc_argp = &data->arg;
4419 msg.rpc_resp = &data->res; 4539 msg.rpc_resp = &data->res;
4420 task_setup_data.callback_data = data; 4540 task_setup_data.callback_data = data;
@@ -4479,15 +4599,34 @@ out:
4479} 4599}
4480 4600
4481#if defined(CONFIG_NFS_V4_1) 4601#if defined(CONFIG_NFS_V4_1)
4482static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) 4602static int nfs41_check_expired_locks(struct nfs4_state *state)
4483{ 4603{
4484 int status; 4604 int status, ret = NFS_OK;
4605 struct nfs4_lock_state *lsp;
4485 struct nfs_server *server = NFS_SERVER(state->inode); 4606 struct nfs_server *server = NFS_SERVER(state->inode);
4486 4607
4487 status = nfs41_test_stateid(server, state); 4608 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
4609 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) {
4610 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4611 if (status != NFS_OK) {
4612 nfs41_free_stateid(server, &lsp->ls_stateid);
4613 lsp->ls_flags &= ~NFS_LOCK_INITIALIZED;
4614 ret = status;
4615 }
4616 }
4617 };
4618
4619 return ret;
4620}
4621
4622static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
4623{
4624 int status = NFS_OK;
4625
4626 if (test_bit(LK_STATE_IN_USE, &state->flags))
4627 status = nfs41_check_expired_locks(state);
4488 if (status == NFS_OK) 4628 if (status == NFS_OK)
4489 return 0; 4629 return status;
4490 nfs41_free_stateid(server, state);
4491 return nfs4_lock_expired(state, request); 4630 return nfs4_lock_expired(state, request);
4492} 4631}
4493#endif 4632#endif
@@ -4523,7 +4662,8 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
4523 /* Note: we always want to sleep here! */ 4662 /* Note: we always want to sleep here! */
4524 request->fl_flags = fl_flags | FL_SLEEP; 4663 request->fl_flags = fl_flags | FL_SLEEP;
4525 if (do_vfs_lock(request->fl_file, request) < 0) 4664 if (do_vfs_lock(request->fl_file, request) < 0)
4526 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); 4665 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
4666 "manager!\n", __func__);
4527out_unlock: 4667out_unlock:
4528 up_read(&nfsi->rwsem); 4668 up_read(&nfsi->rwsem);
4529out: 4669out:
@@ -4533,7 +4673,9 @@ out:
4533 4673
4534static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) 4674static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4535{ 4675{
4536 struct nfs4_exception exception = { }; 4676 struct nfs4_exception exception = {
4677 .state = state,
4678 };
4537 int err; 4679 int err;
4538 4680
4539 do { 4681 do {
@@ -4603,8 +4745,8 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4603 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); 4745 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4604 switch (err) { 4746 switch (err) {
4605 default: 4747 default:
4606 printk(KERN_ERR "%s: unhandled error %d.\n", 4748 printk(KERN_ERR "NFS: %s: unhandled error "
4607 __func__, err); 4749 "%d.\n", __func__, err);
4608 case 0: 4750 case 0:
4609 case -ESTALE: 4751 case -ESTALE:
4610 goto out; 4752 goto out;
@@ -4626,6 +4768,7 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4626 * The show must go on: exit, but mark the 4768 * The show must go on: exit, but mark the
4627 * stateid as needing recovery. 4769 * stateid as needing recovery.
4628 */ 4770 */
4771 case -NFS4ERR_DELEG_REVOKED:
4629 case -NFS4ERR_ADMIN_REVOKED: 4772 case -NFS4ERR_ADMIN_REVOKED:
4630 case -NFS4ERR_BAD_STATEID: 4773 case -NFS4ERR_BAD_STATEID:
4631 case -NFS4ERR_OPENMODE: 4774 case -NFS4ERR_OPENMODE:
@@ -4655,33 +4798,44 @@ out:
4655 return err; 4798 return err;
4656} 4799}
4657 4800
4801struct nfs_release_lockowner_data {
4802 struct nfs4_lock_state *lsp;
4803 struct nfs_server *server;
4804 struct nfs_release_lockowner_args args;
4805};
4806
4658static void nfs4_release_lockowner_release(void *calldata) 4807static void nfs4_release_lockowner_release(void *calldata)
4659{ 4808{
4809 struct nfs_release_lockowner_data *data = calldata;
4810 nfs4_free_lock_state(data->server, data->lsp);
4660 kfree(calldata); 4811 kfree(calldata);
4661} 4812}
4662 4813
4663const struct rpc_call_ops nfs4_release_lockowner_ops = { 4814static const struct rpc_call_ops nfs4_release_lockowner_ops = {
4664 .rpc_release = nfs4_release_lockowner_release, 4815 .rpc_release = nfs4_release_lockowner_release,
4665}; 4816};
4666 4817
4667void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) 4818int nfs4_release_lockowner(struct nfs4_lock_state *lsp)
4668{ 4819{
4669 struct nfs_server *server = lsp->ls_state->owner->so_server; 4820 struct nfs_server *server = lsp->ls_state->owner->so_server;
4670 struct nfs_release_lockowner_args *args; 4821 struct nfs_release_lockowner_data *data;
4671 struct rpc_message msg = { 4822 struct rpc_message msg = {
4672 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], 4823 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
4673 }; 4824 };
4674 4825
4675 if (server->nfs_client->cl_mvops->minor_version != 0) 4826 if (server->nfs_client->cl_mvops->minor_version != 0)
4676 return; 4827 return -EINVAL;
4677 args = kmalloc(sizeof(*args), GFP_NOFS); 4828 data = kmalloc(sizeof(*data), GFP_NOFS);
4678 if (!args) 4829 if (!data)
4679 return; 4830 return -ENOMEM;
4680 args->lock_owner.clientid = server->nfs_client->cl_clientid; 4831 data->lsp = lsp;
4681 args->lock_owner.id = lsp->ls_id.id; 4832 data->server = server;
4682 args->lock_owner.s_dev = server->s_dev; 4833 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
4683 msg.rpc_argp = args; 4834 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
4684 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); 4835 data->args.lock_owner.s_dev = server->s_dev;
4836 msg.rpc_argp = &data->args;
4837 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
4838 return 0;
4685} 4839}
4686 4840
4687#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" 4841#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
@@ -4727,11 +4881,11 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4727 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || 4881 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
4728 (fattr->valid & NFS_ATTR_FATTR_FILEID)) && 4882 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
4729 (fattr->valid & NFS_ATTR_FATTR_FSID) && 4883 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4730 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) 4884 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
4731 return; 4885 return;
4732 4886
4733 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | 4887 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4734 NFS_ATTR_FATTR_NLINK; 4888 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
4735 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; 4889 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4736 fattr->nlink = 2; 4890 fattr->nlink = 2;
4737} 4891}
@@ -4798,7 +4952,8 @@ static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct
4798 return status; 4952 return status;
4799} 4953}
4800 4954
4801int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) 4955static int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
4956 struct nfs4_secinfo_flavors *flavors)
4802{ 4957{
4803 struct nfs4_exception exception = { }; 4958 struct nfs4_exception exception = { };
4804 int err; 4959 int err;
@@ -4852,6 +5007,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4852{ 5007{
4853 nfs4_verifier verifier; 5008 nfs4_verifier verifier;
4854 struct nfs41_exchange_id_args args = { 5009 struct nfs41_exchange_id_args args = {
5010 .verifier = &verifier,
4855 .client = clp, 5011 .client = clp,
4856 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, 5012 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
4857 }; 5013 };
@@ -4865,15 +5021,11 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4865 .rpc_resp = &res, 5021 .rpc_resp = &res,
4866 .rpc_cred = cred, 5022 .rpc_cred = cred,
4867 }; 5023 };
4868 __be32 *p;
4869 5024
4870 dprintk("--> %s\n", __func__); 5025 dprintk("--> %s\n", __func__);
4871 BUG_ON(clp == NULL); 5026 BUG_ON(clp == NULL);
4872 5027
4873 p = (u32 *)verifier.data; 5028 nfs4_construct_boot_verifier(clp, &verifier);
4874 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4875 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4876 args.verifier = &verifier;
4877 5029
4878 args.id_len = scnprintf(args.id, sizeof(args.id), 5030 args.id_len = scnprintf(args.id, sizeof(args.id),
4879 "%s/%s.%s/%u", 5031 "%s/%s.%s/%u",
@@ -4883,14 +5035,29 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4883 clp->cl_rpcclient->cl_auth->au_flavor); 5035 clp->cl_rpcclient->cl_auth->au_flavor);
4884 5036
4885 res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); 5037 res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL);
4886 if (unlikely(!res.server_scope)) 5038 if (unlikely(!res.server_scope)) {
4887 return -ENOMEM; 5039 status = -ENOMEM;
5040 goto out;
5041 }
5042
5043 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_KERNEL);
5044 if (unlikely(!res.impl_id)) {
5045 status = -ENOMEM;
5046 goto out_server_scope;
5047 }
4888 5048
4889 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 5049 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4890 if (!status) 5050 if (!status)
4891 status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); 5051 status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
4892 5052
4893 if (!status) { 5053 if (!status) {
5054 /* use the most recent implementation id */
5055 kfree(clp->impl_id);
5056 clp->impl_id = res.impl_id;
5057 } else
5058 kfree(res.impl_id);
5059
5060 if (!status) {
4894 if (clp->server_scope && 5061 if (clp->server_scope &&
4895 !nfs41_same_server_scope(clp->server_scope, 5062 !nfs41_same_server_scope(clp->server_scope,
4896 res.server_scope)) { 5063 res.server_scope)) {
@@ -4901,12 +5068,21 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4901 clp->server_scope = NULL; 5068 clp->server_scope = NULL;
4902 } 5069 }
4903 5070
4904 if (!clp->server_scope) 5071 if (!clp->server_scope) {
4905 clp->server_scope = res.server_scope; 5072 clp->server_scope = res.server_scope;
4906 else 5073 goto out;
4907 kfree(res.server_scope); 5074 }
4908 } 5075 }
4909 5076
5077out_server_scope:
5078 kfree(res.server_scope);
5079out:
5080 if (clp->impl_id)
5081 dprintk("%s: Server Implementation ID: "
5082 "domain: %s, name: %s, date: %llu,%u\n",
5083 __func__, clp->impl_id->domain, clp->impl_id->name,
5084 clp->impl_id->date.seconds,
5085 clp->impl_id->date.nseconds);
4910 dprintk("<-- %s status= %d\n", __func__, status); 5086 dprintk("<-- %s status= %d\n", __func__, status);
4911 return status; 5087 return status;
4912} 5088}
@@ -4930,7 +5106,7 @@ static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4930 since we're invoked within one */ 5106 since we're invoked within one */
4931 ret = nfs41_setup_sequence(data->clp->cl_session, 5107 ret = nfs41_setup_sequence(data->clp->cl_session,
4932 &data->args->la_seq_args, 5108 &data->args->la_seq_args,
4933 &data->res->lr_seq_res, 0, task); 5109 &data->res->lr_seq_res, task);
4934 5110
4935 BUG_ON(ret == -EAGAIN); 5111 BUG_ON(ret == -EAGAIN);
4936 rpc_call_start(task); 5112 rpc_call_start(task);
@@ -4963,7 +5139,7 @@ static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4963 dprintk("<-- %s\n", __func__); 5139 dprintk("<-- %s\n", __func__);
4964} 5140}
4965 5141
4966struct rpc_call_ops nfs4_get_lease_time_ops = { 5142static const struct rpc_call_ops nfs4_get_lease_time_ops = {
4967 .rpc_call_prepare = nfs4_get_lease_time_prepare, 5143 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4968 .rpc_call_done = nfs4_get_lease_time_done, 5144 .rpc_call_done = nfs4_get_lease_time_done,
4969}; 5145};
@@ -4994,6 +5170,7 @@ int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4994 }; 5170 };
4995 int status; 5171 int status;
4996 5172
5173 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
4997 dprintk("--> %s\n", __func__); 5174 dprintk("--> %s\n", __func__);
4998 task = rpc_run_task(&task_setup); 5175 task = rpc_run_task(&task_setup);
4999 5176
@@ -5008,37 +5185,53 @@ int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
5008 return status; 5185 return status;
5009} 5186}
5010 5187
5188static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags)
5189{
5190 return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags);
5191}
5192
5193static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl,
5194 struct nfs4_slot *new,
5195 u32 max_slots,
5196 u32 ivalue)
5197{
5198 struct nfs4_slot *old = NULL;
5199 u32 i;
5200
5201 spin_lock(&tbl->slot_tbl_lock);
5202 if (new) {
5203 old = tbl->slots;
5204 tbl->slots = new;
5205 tbl->max_slots = max_slots;
5206 }
5207 tbl->highest_used_slotid = -1; /* no slot is currently used */
5208 for (i = 0; i < tbl->max_slots; i++)
5209 tbl->slots[i].seq_nr = ivalue;
5210 spin_unlock(&tbl->slot_tbl_lock);
5211 kfree(old);
5212}
5213
5011/* 5214/*
5012 * Reset a slot table 5215 * (re)Initialise a slot table
5013 */ 5216 */
5014static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, 5217static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
5015 int ivalue) 5218 u32 ivalue)
5016{ 5219{
5017 struct nfs4_slot *new = NULL; 5220 struct nfs4_slot *new = NULL;
5018 int i; 5221 int ret = -ENOMEM;
5019 int ret = 0;
5020 5222
5021 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, 5223 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
5022 max_reqs, tbl->max_slots); 5224 max_reqs, tbl->max_slots);
5023 5225
5024 /* Does the newly negotiated max_reqs match the existing slot table? */ 5226 /* Does the newly negotiated max_reqs match the existing slot table? */
5025 if (max_reqs != tbl->max_slots) { 5227 if (max_reqs != tbl->max_slots) {
5026 ret = -ENOMEM; 5228 new = nfs4_alloc_slots(max_reqs, GFP_NOFS);
5027 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
5028 GFP_NOFS);
5029 if (!new) 5229 if (!new)
5030 goto out; 5230 goto out;
5031 ret = 0;
5032 kfree(tbl->slots);
5033 }
5034 spin_lock(&tbl->slot_tbl_lock);
5035 if (new) {
5036 tbl->slots = new;
5037 tbl->max_slots = max_reqs;
5038 } 5231 }
5039 for (i = 0; i < tbl->max_slots; ++i) 5232 ret = 0;
5040 tbl->slots[i].seq_nr = ivalue; 5233
5041 spin_unlock(&tbl->slot_tbl_lock); 5234 nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue);
5042 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, 5235 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
5043 tbl, tbl->slots, tbl->max_slots); 5236 tbl, tbl->slots, tbl->max_slots);
5044out: 5237out:
@@ -5061,36 +5254,6 @@ static void nfs4_destroy_slot_tables(struct nfs4_session *session)
5061} 5254}
5062 5255
5063/* 5256/*
5064 * Initialize slot table
5065 */
5066static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
5067 int max_slots, int ivalue)
5068{
5069 struct nfs4_slot *slot;
5070 int ret = -ENOMEM;
5071
5072 BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
5073
5074 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
5075
5076 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS);
5077 if (!slot)
5078 goto out;
5079 ret = 0;
5080
5081 spin_lock(&tbl->slot_tbl_lock);
5082 tbl->max_slots = max_slots;
5083 tbl->slots = slot;
5084 tbl->highest_used_slotid = -1; /* no slot is currently used */
5085 spin_unlock(&tbl->slot_tbl_lock);
5086 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
5087 tbl, tbl->slots, tbl->max_slots);
5088out:
5089 dprintk("<-- %s: return %d\n", __func__, ret);
5090 return ret;
5091}
5092
5093/*
5094 * Initialize or reset the forechannel and backchannel tables 5257 * Initialize or reset the forechannel and backchannel tables
5095 */ 5258 */
5096static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) 5259static int nfs4_setup_session_slot_tables(struct nfs4_session *ses)
@@ -5101,25 +5264,16 @@ static int nfs4_setup_session_slot_tables(struct nfs4_session *ses)
5101 dprintk("--> %s\n", __func__); 5264 dprintk("--> %s\n", __func__);
5102 /* Fore channel */ 5265 /* Fore channel */
5103 tbl = &ses->fc_slot_table; 5266 tbl = &ses->fc_slot_table;
5104 if (tbl->slots == NULL) { 5267 status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1);
5105 status = nfs4_init_slot_table(tbl, ses->fc_attrs.max_reqs, 1); 5268 if (status) /* -ENOMEM */
5106 if (status) /* -ENOMEM */ 5269 return status;
5107 return status;
5108 } else {
5109 status = nfs4_reset_slot_table(tbl, ses->fc_attrs.max_reqs, 1);
5110 if (status)
5111 return status;
5112 }
5113 /* Back channel */ 5270 /* Back channel */
5114 tbl = &ses->bc_slot_table; 5271 tbl = &ses->bc_slot_table;
5115 if (tbl->slots == NULL) { 5272 status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0);
5116 status = nfs4_init_slot_table(tbl, ses->bc_attrs.max_reqs, 0); 5273 if (status && tbl->slots == NULL)
5117 if (status) 5274 /* Fore and back channel share a connection so get
5118 /* Fore and back channel share a connection so get 5275 * both slot tables or neither */
5119 * both slot tables or neither */ 5276 nfs4_destroy_slot_tables(ses);
5120 nfs4_destroy_slot_tables(ses);
5121 } else
5122 status = nfs4_reset_slot_table(tbl, ses->bc_attrs.max_reqs, 0);
5123 return status; 5277 return status;
5124} 5278}
5125 5279
@@ -5133,13 +5287,13 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
5133 return NULL; 5287 return NULL;
5134 5288
5135 tbl = &session->fc_slot_table; 5289 tbl = &session->fc_slot_table;
5136 tbl->highest_used_slotid = -1; 5290 tbl->highest_used_slotid = NFS4_NO_SLOT;
5137 spin_lock_init(&tbl->slot_tbl_lock); 5291 spin_lock_init(&tbl->slot_tbl_lock);
5138 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); 5292 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
5139 init_completion(&tbl->complete); 5293 init_completion(&tbl->complete);
5140 5294
5141 tbl = &session->bc_slot_table; 5295 tbl = &session->bc_slot_table;
5142 tbl->highest_used_slotid = -1; 5296 tbl->highest_used_slotid = NFS4_NO_SLOT;
5143 spin_lock_init(&tbl->slot_tbl_lock); 5297 spin_lock_init(&tbl->slot_tbl_lock);
5144 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); 5298 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
5145 init_completion(&tbl->complete); 5299 init_completion(&tbl->complete);
@@ -5152,11 +5306,16 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
5152 5306
5153void nfs4_destroy_session(struct nfs4_session *session) 5307void nfs4_destroy_session(struct nfs4_session *session)
5154{ 5308{
5309 struct rpc_xprt *xprt;
5310
5155 nfs4_proc_destroy_session(session); 5311 nfs4_proc_destroy_session(session);
5312
5313 rcu_read_lock();
5314 xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt);
5315 rcu_read_unlock();
5156 dprintk("%s Destroy backchannel for xprt %p\n", 5316 dprintk("%s Destroy backchannel for xprt %p\n",
5157 __func__, session->clp->cl_rpcclient->cl_xprt); 5317 __func__, xprt);
5158 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, 5318 xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS);
5159 NFS41_BC_MIN_CALLBACKS);
5160 nfs4_destroy_slot_tables(session); 5319 nfs4_destroy_slot_tables(session);
5161 kfree(session); 5320 kfree(session);
5162} 5321}
@@ -5184,7 +5343,7 @@ static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5184 args->fc_attrs.max_rqst_sz = mxrqst_sz; 5343 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5185 args->fc_attrs.max_resp_sz = mxresp_sz; 5344 args->fc_attrs.max_resp_sz = mxresp_sz;
5186 args->fc_attrs.max_ops = NFS4_MAX_OPS; 5345 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5187 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; 5346 args->fc_attrs.max_reqs = max_session_slots;
5188 5347
5189 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " 5348 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5190 "max_ops=%u max_reqs=%u\n", 5349 "max_ops=%u max_reqs=%u\n",
@@ -5224,6 +5383,8 @@ static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args
5224 return -EINVAL; 5383 return -EINVAL;
5225 if (rcvd->max_reqs == 0) 5384 if (rcvd->max_reqs == 0)
5226 return -EINVAL; 5385 return -EINVAL;
5386 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
5387 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
5227 return 0; 5388 return 0;
5228} 5389}
5229 5390
@@ -5239,9 +5400,9 @@ static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args
5239 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) 5400 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5240 return -EINVAL; 5401 return -EINVAL;
5241 /* These would render the backchannel useless: */ 5402 /* These would render the backchannel useless: */
5242 if (rcvd->max_ops == 0) 5403 if (rcvd->max_ops != sent->max_ops)
5243 return -EINVAL; 5404 return -EINVAL;
5244 if (rcvd->max_reqs == 0) 5405 if (rcvd->max_reqs != sent->max_reqs)
5245 return -EINVAL; 5406 return -EINVAL;
5246 return 0; 5407 return 0;
5247} 5408}
@@ -5344,7 +5505,7 @@ int nfs4_proc_destroy_session(struct nfs4_session *session)
5344 5505
5345 if (status) 5506 if (status)
5346 printk(KERN_WARNING 5507 printk(KERN_WARNING
5347 "Got error %d from the server on DESTROY_SESSION. " 5508 "NFS: Got error %d from the server on DESTROY_SESSION. "
5348 "Session has been destroyed regardless...\n", status); 5509 "Session has been destroyed regardless...\n", status);
5349 5510
5350 dprintk("<-- nfs4_proc_destroy_session\n"); 5511 dprintk("<-- nfs4_proc_destroy_session\n");
@@ -5467,7 +5628,7 @@ static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5467 args = task->tk_msg.rpc_argp; 5628 args = task->tk_msg.rpc_argp;
5468 res = task->tk_msg.rpc_resp; 5629 res = task->tk_msg.rpc_resp;
5469 5630
5470 if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) 5631 if (nfs41_setup_sequence(clp->cl_session, args, res, task))
5471 return; 5632 return;
5472 rpc_call_start(task); 5633 rpc_call_start(task);
5473} 5634}
@@ -5499,6 +5660,7 @@ static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_
5499 nfs_put_client(clp); 5660 nfs_put_client(clp);
5500 return ERR_PTR(-ENOMEM); 5661 return ERR_PTR(-ENOMEM);
5501 } 5662 }
5663 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
5502 msg.rpc_argp = &calldata->args; 5664 msg.rpc_argp = &calldata->args;
5503 msg.rpc_resp = &calldata->res; 5665 msg.rpc_resp = &calldata->res;
5504 calldata->clp = clp; 5666 calldata->clp = clp;
@@ -5560,7 +5722,7 @@ static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5560 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 5722 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5561 if (nfs41_setup_sequence(calldata->clp->cl_session, 5723 if (nfs41_setup_sequence(calldata->clp->cl_session,
5562 &calldata->arg.seq_args, 5724 &calldata->arg.seq_args,
5563 &calldata->res.seq_res, 0, task)) 5725 &calldata->res.seq_res, task))
5564 return; 5726 return;
5565 5727
5566 rpc_call_start(task); 5728 rpc_call_start(task);
@@ -5639,6 +5801,7 @@ static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5639 calldata->clp = clp; 5801 calldata->clp = clp;
5640 calldata->arg.one_fs = 0; 5802 calldata->arg.one_fs = 0;
5641 5803
5804 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
5642 msg.rpc_argp = &calldata->arg; 5805 msg.rpc_argp = &calldata->arg;
5643 msg.rpc_resp = &calldata->res; 5806 msg.rpc_resp = &calldata->res;
5644 task_setup_data.callback_data = calldata; 5807 task_setup_data.callback_data = calldata;
@@ -5670,7 +5833,7 @@ nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
5670 * to be no way to prevent it completely. 5833 * to be no way to prevent it completely.
5671 */ 5834 */
5672 if (nfs4_setup_sequence(server, &lgp->args.seq_args, 5835 if (nfs4_setup_sequence(server, &lgp->args.seq_args,
5673 &lgp->res.seq_res, 0, task)) 5836 &lgp->res.seq_res, task))
5674 return; 5837 return;
5675 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, 5838 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
5676 NFS_I(lgp->args.inode)->layout, 5839 NFS_I(lgp->args.inode)->layout,
@@ -5745,6 +5908,7 @@ int nfs4_proc_layoutget(struct nfs4_layoutget *lgp)
5745 5908
5746 lgp->res.layoutp = &lgp->args.layout; 5909 lgp->res.layoutp = &lgp->args.layout;
5747 lgp->res.seq_res.sr_slot = NULL; 5910 lgp->res.seq_res.sr_slot = NULL;
5911 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
5748 task = rpc_run_task(&task_setup_data); 5912 task = rpc_run_task(&task_setup_data);
5749 if (IS_ERR(task)) 5913 if (IS_ERR(task))
5750 return PTR_ERR(task); 5914 return PTR_ERR(task);
@@ -5765,7 +5929,7 @@ nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
5765 5929
5766 dprintk("--> %s\n", __func__); 5930 dprintk("--> %s\n", __func__);
5767 if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, 5931 if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args,
5768 &lrp->res.seq_res, 0, task)) 5932 &lrp->res.seq_res, task))
5769 return; 5933 return;
5770 rpc_call_start(task); 5934 rpc_call_start(task);
5771} 5935}
@@ -5831,6 +5995,7 @@ int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
5831 int status; 5995 int status;
5832 5996
5833 dprintk("--> %s\n", __func__); 5997 dprintk("--> %s\n", __func__);
5998 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
5834 task = rpc_run_task(&task_setup_data); 5999 task = rpc_run_task(&task_setup_data);
5835 if (IS_ERR(task)) 6000 if (IS_ERR(task))
5836 return PTR_ERR(task); 6001 return PTR_ERR(task);
@@ -5931,7 +6096,7 @@ static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
5931 struct nfs_server *server = NFS_SERVER(data->args.inode); 6096 struct nfs_server *server = NFS_SERVER(data->args.inode);
5932 6097
5933 if (nfs4_setup_sequence(server, &data->args.seq_args, 6098 if (nfs4_setup_sequence(server, &data->args.seq_args,
5934 &data->res.seq_res, 1, task)) 6099 &data->res.seq_res, task))
5935 return; 6100 return;
5936 rpc_call_start(task); 6101 rpc_call_start(task);
5937} 6102}
@@ -6018,6 +6183,7 @@ nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
6018 data->args.lastbytewritten, 6183 data->args.lastbytewritten,
6019 data->args.inode->i_ino); 6184 data->args.inode->i_ino);
6020 6185
6186 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
6021 task = rpc_run_task(&task_setup_data); 6187 task = rpc_run_task(&task_setup_data);
6022 if (IS_ERR(task)) 6188 if (IS_ERR(task))
6023 return PTR_ERR(task); 6189 return PTR_ERR(task);
@@ -6111,11 +6277,12 @@ out_freepage:
6111out: 6277out:
6112 return err; 6278 return err;
6113} 6279}
6114static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) 6280
6281static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6115{ 6282{
6116 int status; 6283 int status;
6117 struct nfs41_test_stateid_args args = { 6284 struct nfs41_test_stateid_args args = {
6118 .stateid = &state->stateid, 6285 .stateid = stateid,
6119 }; 6286 };
6120 struct nfs41_test_stateid_res res; 6287 struct nfs41_test_stateid_res res;
6121 struct rpc_message msg = { 6288 struct rpc_message msg = {
@@ -6123,28 +6290,31 @@ static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *sta
6123 .rpc_argp = &args, 6290 .rpc_argp = &args,
6124 .rpc_resp = &res, 6291 .rpc_resp = &res,
6125 }; 6292 };
6126 args.seq_args.sa_session = res.seq_res.sr_session = NULL; 6293
6127 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); 6294 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6295 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
6296
6297 if (status == NFS_OK)
6298 return res.status;
6128 return status; 6299 return status;
6129} 6300}
6130 6301
6131static int nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) 6302static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6132{ 6303{
6133 struct nfs4_exception exception = { }; 6304 struct nfs4_exception exception = { };
6134 int err; 6305 int err;
6135 do { 6306 do {
6136 err = nfs4_handle_exception(server, 6307 err = nfs4_handle_exception(server,
6137 _nfs41_test_stateid(server, state), 6308 _nfs41_test_stateid(server, stateid),
6138 &exception); 6309 &exception);
6139 } while (exception.retry); 6310 } while (exception.retry);
6140 return err; 6311 return err;
6141} 6312}
6142 6313
6143static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *state) 6314static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6144{ 6315{
6145 int status;
6146 struct nfs41_free_stateid_args args = { 6316 struct nfs41_free_stateid_args args = {
6147 .stateid = &state->stateid, 6317 .stateid = stateid,
6148 }; 6318 };
6149 struct nfs41_free_stateid_res res; 6319 struct nfs41_free_stateid_res res;
6150 struct rpc_message msg = { 6320 struct rpc_message msg = {
@@ -6153,25 +6323,46 @@ static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *stat
6153 .rpc_resp = &res, 6323 .rpc_resp = &res,
6154 }; 6324 };
6155 6325
6156 args.seq_args.sa_session = res.seq_res.sr_session = NULL; 6326 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6157 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); 6327 return nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
6158 return status;
6159} 6328}
6160 6329
6161static int nfs41_free_stateid(struct nfs_server *server, struct nfs4_state *state) 6330static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6162{ 6331{
6163 struct nfs4_exception exception = { }; 6332 struct nfs4_exception exception = { };
6164 int err; 6333 int err;
6165 do { 6334 do {
6166 err = nfs4_handle_exception(server, 6335 err = nfs4_handle_exception(server,
6167 _nfs4_free_stateid(server, state), 6336 _nfs4_free_stateid(server, stateid),
6168 &exception); 6337 &exception);
6169 } while (exception.retry); 6338 } while (exception.retry);
6170 return err; 6339 return err;
6171} 6340}
6341
6342static bool nfs41_match_stateid(const nfs4_stateid *s1,
6343 const nfs4_stateid *s2)
6344{
6345 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
6346 return false;
6347
6348 if (s1->seqid == s2->seqid)
6349 return true;
6350 if (s1->seqid == 0 || s2->seqid == 0)
6351 return true;
6352
6353 return false;
6354}
6355
6172#endif /* CONFIG_NFS_V4_1 */ 6356#endif /* CONFIG_NFS_V4_1 */
6173 6357
6174struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { 6358static bool nfs4_match_stateid(const nfs4_stateid *s1,
6359 const nfs4_stateid *s2)
6360{
6361 return nfs4_stateid_match(s1, s2);
6362}
6363
6364
6365static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6175 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 6366 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6176 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 6367 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6177 .recover_open = nfs4_open_reclaim, 6368 .recover_open = nfs4_open_reclaim,
@@ -6181,7 +6372,7 @@ struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6181}; 6372};
6182 6373
6183#if defined(CONFIG_NFS_V4_1) 6374#if defined(CONFIG_NFS_V4_1)
6184struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { 6375static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6185 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 6376 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6186 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 6377 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6187 .recover_open = nfs4_open_reclaim, 6378 .recover_open = nfs4_open_reclaim,
@@ -6192,7 +6383,7 @@ struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6192}; 6383};
6193#endif /* CONFIG_NFS_V4_1 */ 6384#endif /* CONFIG_NFS_V4_1 */
6194 6385
6195struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { 6386static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6196 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 6387 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6197 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 6388 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6198 .recover_open = nfs4_open_expired, 6389 .recover_open = nfs4_open_expired,
@@ -6202,7 +6393,7 @@ struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6202}; 6393};
6203 6394
6204#if defined(CONFIG_NFS_V4_1) 6395#if defined(CONFIG_NFS_V4_1)
6205struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { 6396static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6206 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 6397 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6207 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 6398 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6208 .recover_open = nfs41_open_expired, 6399 .recover_open = nfs41_open_expired,
@@ -6212,14 +6403,14 @@ struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6212}; 6403};
6213#endif /* CONFIG_NFS_V4_1 */ 6404#endif /* CONFIG_NFS_V4_1 */
6214 6405
6215struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { 6406static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
6216 .sched_state_renewal = nfs4_proc_async_renew, 6407 .sched_state_renewal = nfs4_proc_async_renew,
6217 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, 6408 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
6218 .renew_lease = nfs4_proc_renew, 6409 .renew_lease = nfs4_proc_renew,
6219}; 6410};
6220 6411
6221#if defined(CONFIG_NFS_V4_1) 6412#if defined(CONFIG_NFS_V4_1)
6222struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { 6413static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6223 .sched_state_renewal = nfs41_proc_async_sequence, 6414 .sched_state_renewal = nfs41_proc_async_sequence,
6224 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, 6415 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
6225 .renew_lease = nfs4_proc_sequence, 6416 .renew_lease = nfs4_proc_sequence,
@@ -6229,7 +6420,7 @@ struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6229static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { 6420static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6230 .minor_version = 0, 6421 .minor_version = 0,
6231 .call_sync = _nfs4_call_sync, 6422 .call_sync = _nfs4_call_sync,
6232 .validate_stateid = nfs4_validate_delegation_stateid, 6423 .match_stateid = nfs4_match_stateid,
6233 .find_root_sec = nfs4_find_root_sec, 6424 .find_root_sec = nfs4_find_root_sec,
6234 .reboot_recovery_ops = &nfs40_reboot_recovery_ops, 6425 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
6235 .nograce_recovery_ops = &nfs40_nograce_recovery_ops, 6426 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
@@ -6240,7 +6431,7 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6240static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { 6431static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
6241 .minor_version = 1, 6432 .minor_version = 1,
6242 .call_sync = _nfs4_call_sync_session, 6433 .call_sync = _nfs4_call_sync_session,
6243 .validate_stateid = nfs41_validate_delegation_stateid, 6434 .match_stateid = nfs41_match_stateid,
6244 .find_root_sec = nfs41_find_root_sec, 6435 .find_root_sec = nfs41_find_root_sec,
6245 .reboot_recovery_ops = &nfs41_reboot_recovery_ops, 6436 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
6246 .nograce_recovery_ops = &nfs41_nograce_recovery_ops, 6437 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
@@ -6280,9 +6471,11 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
6280 .create = nfs4_proc_create, 6471 .create = nfs4_proc_create,
6281 .remove = nfs4_proc_remove, 6472 .remove = nfs4_proc_remove,
6282 .unlink_setup = nfs4_proc_unlink_setup, 6473 .unlink_setup = nfs4_proc_unlink_setup,
6474 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
6283 .unlink_done = nfs4_proc_unlink_done, 6475 .unlink_done = nfs4_proc_unlink_done,
6284 .rename = nfs4_proc_rename, 6476 .rename = nfs4_proc_rename,
6285 .rename_setup = nfs4_proc_rename_setup, 6477 .rename_setup = nfs4_proc_rename_setup,
6478 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
6286 .rename_done = nfs4_proc_rename_done, 6479 .rename_done = nfs4_proc_rename_done,
6287 .link = nfs4_proc_link, 6480 .link = nfs4_proc_link,
6288 .symlink = nfs4_proc_symlink, 6481 .symlink = nfs4_proc_symlink,
@@ -6296,8 +6489,10 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
6296 .set_capabilities = nfs4_server_capabilities, 6489 .set_capabilities = nfs4_server_capabilities,
6297 .decode_dirent = nfs4_decode_dirent, 6490 .decode_dirent = nfs4_decode_dirent,
6298 .read_setup = nfs4_proc_read_setup, 6491 .read_setup = nfs4_proc_read_setup,
6492 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
6299 .read_done = nfs4_read_done, 6493 .read_done = nfs4_read_done,
6300 .write_setup = nfs4_proc_write_setup, 6494 .write_setup = nfs4_proc_write_setup,
6495 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
6301 .write_done = nfs4_write_done, 6496 .write_done = nfs4_write_done,
6302 .commit_setup = nfs4_proc_commit_setup, 6497 .commit_setup = nfs4_proc_commit_setup,
6303 .commit_done = nfs4_commit_done, 6498 .commit_done = nfs4_commit_done,
@@ -6321,6 +6516,10 @@ const struct xattr_handler *nfs4_xattr_handlers[] = {
6321 NULL 6516 NULL
6322}; 6517};
6323 6518
6519module_param(max_session_slots, ushort, 0644);
6520MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
6521 "requests the client will negotiate");
6522
6324/* 6523/*
6325 * Local variables: 6524 * Local variables:
6326 * c-basic-offset: 8 6525 * c-basic-offset: 8
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index a53f33b4ac3a..0f43414eb25a 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -146,6 +146,11 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
146 struct rpc_cred *cred = NULL; 146 struct rpc_cred *cred = NULL;
147 struct nfs_server *server; 147 struct nfs_server *server;
148 148
149 /* Use machine credentials if available */
150 cred = nfs4_get_machine_cred_locked(clp);
151 if (cred != NULL)
152 goto out;
153
149 rcu_read_lock(); 154 rcu_read_lock();
150 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { 155 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
151 cred = nfs4_get_renew_cred_server_locked(server); 156 cred = nfs4_get_renew_cred_server_locked(server);
@@ -153,6 +158,8 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
153 break; 158 break;
154 } 159 }
155 rcu_read_unlock(); 160 rcu_read_unlock();
161
162out:
156 return cred; 163 return cred;
157} 164}
158 165
@@ -190,30 +197,29 @@ static int nfs41_setup_state_renewal(struct nfs_client *clp)
190static void nfs4_end_drain_session(struct nfs_client *clp) 197static void nfs4_end_drain_session(struct nfs_client *clp)
191{ 198{
192 struct nfs4_session *ses = clp->cl_session; 199 struct nfs4_session *ses = clp->cl_session;
200 struct nfs4_slot_table *tbl;
193 int max_slots; 201 int max_slots;
194 202
195 if (ses == NULL) 203 if (ses == NULL)
196 return; 204 return;
205 tbl = &ses->fc_slot_table;
197 if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { 206 if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
198 spin_lock(&ses->fc_slot_table.slot_tbl_lock); 207 spin_lock(&tbl->slot_tbl_lock);
199 max_slots = ses->fc_slot_table.max_slots; 208 max_slots = tbl->max_slots;
200 while (max_slots--) { 209 while (max_slots--) {
201 struct rpc_task *task; 210 if (rpc_wake_up_first(&tbl->slot_tbl_waitq,
202 211 nfs4_set_task_privileged,
203 task = rpc_wake_up_next(&ses->fc_slot_table. 212 NULL) == NULL)
204 slot_tbl_waitq);
205 if (!task)
206 break; 213 break;
207 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
208 } 214 }
209 spin_unlock(&ses->fc_slot_table.slot_tbl_lock); 215 spin_unlock(&tbl->slot_tbl_lock);
210 } 216 }
211} 217}
212 218
213static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl) 219static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl)
214{ 220{
215 spin_lock(&tbl->slot_tbl_lock); 221 spin_lock(&tbl->slot_tbl_lock);
216 if (tbl->highest_used_slotid != -1) { 222 if (tbl->highest_used_slotid != NFS4_NO_SLOT) {
217 INIT_COMPLETION(tbl->complete); 223 INIT_COMPLETION(tbl->complete);
218 spin_unlock(&tbl->slot_tbl_lock); 224 spin_unlock(&tbl->slot_tbl_lock);
219 return wait_for_completion_interruptible(&tbl->complete); 225 return wait_for_completion_interruptible(&tbl->complete);
@@ -317,62 +323,6 @@ out:
317 return cred; 323 return cred;
318} 324}
319 325
320static void nfs_alloc_unique_id_locked(struct rb_root *root,
321 struct nfs_unique_id *new,
322 __u64 minval, int maxbits)
323{
324 struct rb_node **p, *parent;
325 struct nfs_unique_id *pos;
326 __u64 mask = ~0ULL;
327
328 if (maxbits < 64)
329 mask = (1ULL << maxbits) - 1ULL;
330
331 /* Ensure distribution is more or less flat */
332 get_random_bytes(&new->id, sizeof(new->id));
333 new->id &= mask;
334 if (new->id < minval)
335 new->id += minval;
336retry:
337 p = &root->rb_node;
338 parent = NULL;
339
340 while (*p != NULL) {
341 parent = *p;
342 pos = rb_entry(parent, struct nfs_unique_id, rb_node);
343
344 if (new->id < pos->id)
345 p = &(*p)->rb_left;
346 else if (new->id > pos->id)
347 p = &(*p)->rb_right;
348 else
349 goto id_exists;
350 }
351 rb_link_node(&new->rb_node, parent, p);
352 rb_insert_color(&new->rb_node, root);
353 return;
354id_exists:
355 for (;;) {
356 new->id++;
357 if (new->id < minval || (new->id & mask) != new->id) {
358 new->id = minval;
359 break;
360 }
361 parent = rb_next(parent);
362 if (parent == NULL)
363 break;
364 pos = rb_entry(parent, struct nfs_unique_id, rb_node);
365 if (new->id < pos->id)
366 break;
367 }
368 goto retry;
369}
370
371static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id)
372{
373 rb_erase(&id->rb_node, root);
374}
375
376static struct nfs4_state_owner * 326static struct nfs4_state_owner *
377nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred) 327nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred)
378{ 328{
@@ -405,6 +355,7 @@ nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
405 struct rb_node **p = &server->state_owners.rb_node, 355 struct rb_node **p = &server->state_owners.rb_node,
406 *parent = NULL; 356 *parent = NULL;
407 struct nfs4_state_owner *sp; 357 struct nfs4_state_owner *sp;
358 int err;
408 359
409 while (*p != NULL) { 360 while (*p != NULL) {
410 parent = *p; 361 parent = *p;
@@ -421,8 +372,9 @@ nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
421 return sp; 372 return sp;
422 } 373 }
423 } 374 }
424 nfs_alloc_unique_id_locked(&server->openowner_id, 375 err = ida_get_new(&server->openowner_id, &new->so_seqid.owner_id);
425 &new->so_owner_id, 1, 64); 376 if (err)
377 return ERR_PTR(err);
426 rb_link_node(&new->so_server_node, parent, p); 378 rb_link_node(&new->so_server_node, parent, p);
427 rb_insert_color(&new->so_server_node, &server->state_owners); 379 rb_insert_color(&new->so_server_node, &server->state_owners);
428 return new; 380 return new;
@@ -435,7 +387,23 @@ nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
435 387
436 if (!RB_EMPTY_NODE(&sp->so_server_node)) 388 if (!RB_EMPTY_NODE(&sp->so_server_node))
437 rb_erase(&sp->so_server_node, &server->state_owners); 389 rb_erase(&sp->so_server_node, &server->state_owners);
438 nfs_free_unique_id(&server->openowner_id, &sp->so_owner_id); 390 ida_remove(&server->openowner_id, sp->so_seqid.owner_id);
391}
392
393static void
394nfs4_init_seqid_counter(struct nfs_seqid_counter *sc)
395{
396 sc->flags = 0;
397 sc->counter = 0;
398 spin_lock_init(&sc->lock);
399 INIT_LIST_HEAD(&sc->list);
400 rpc_init_wait_queue(&sc->wait, "Seqid_waitqueue");
401}
402
403static void
404nfs4_destroy_seqid_counter(struct nfs_seqid_counter *sc)
405{
406 rpc_destroy_wait_queue(&sc->wait);
439} 407}
440 408
441/* 409/*
@@ -444,19 +412,20 @@ nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
444 * 412 *
445 */ 413 */
446static struct nfs4_state_owner * 414static struct nfs4_state_owner *
447nfs4_alloc_state_owner(void) 415nfs4_alloc_state_owner(struct nfs_server *server,
416 struct rpc_cred *cred,
417 gfp_t gfp_flags)
448{ 418{
449 struct nfs4_state_owner *sp; 419 struct nfs4_state_owner *sp;
450 420
451 sp = kzalloc(sizeof(*sp),GFP_NOFS); 421 sp = kzalloc(sizeof(*sp), gfp_flags);
452 if (!sp) 422 if (!sp)
453 return NULL; 423 return NULL;
424 sp->so_server = server;
425 sp->so_cred = get_rpccred(cred);
454 spin_lock_init(&sp->so_lock); 426 spin_lock_init(&sp->so_lock);
455 INIT_LIST_HEAD(&sp->so_states); 427 INIT_LIST_HEAD(&sp->so_states);
456 rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); 428 nfs4_init_seqid_counter(&sp->so_seqid);
457 sp->so_seqid.sequence = &sp->so_sequence;
458 spin_lock_init(&sp->so_sequence.lock);
459 INIT_LIST_HEAD(&sp->so_sequence.list);
460 atomic_set(&sp->so_count, 1); 429 atomic_set(&sp->so_count, 1);
461 INIT_LIST_HEAD(&sp->so_lru); 430 INIT_LIST_HEAD(&sp->so_lru);
462 return sp; 431 return sp;
@@ -478,7 +447,7 @@ nfs4_drop_state_owner(struct nfs4_state_owner *sp)
478 447
479static void nfs4_free_state_owner(struct nfs4_state_owner *sp) 448static void nfs4_free_state_owner(struct nfs4_state_owner *sp)
480{ 449{
481 rpc_destroy_wait_queue(&sp->so_sequence.wait); 450 nfs4_destroy_seqid_counter(&sp->so_seqid);
482 put_rpccred(sp->so_cred); 451 put_rpccred(sp->so_cred);
483 kfree(sp); 452 kfree(sp);
484} 453}
@@ -516,7 +485,8 @@ static void nfs4_gc_state_owners(struct nfs_server *server)
516 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. 485 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL.
517 */ 486 */
518struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, 487struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
519 struct rpc_cred *cred) 488 struct rpc_cred *cred,
489 gfp_t gfp_flags)
520{ 490{
521 struct nfs_client *clp = server->nfs_client; 491 struct nfs_client *clp = server->nfs_client;
522 struct nfs4_state_owner *sp, *new; 492 struct nfs4_state_owner *sp, *new;
@@ -526,20 +496,18 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
526 spin_unlock(&clp->cl_lock); 496 spin_unlock(&clp->cl_lock);
527 if (sp != NULL) 497 if (sp != NULL)
528 goto out; 498 goto out;
529 new = nfs4_alloc_state_owner(); 499 new = nfs4_alloc_state_owner(server, cred, gfp_flags);
530 if (new == NULL) 500 if (new == NULL)
531 goto out; 501 goto out;
532 new->so_server = server; 502 do {
533 new->so_cred = cred; 503 if (ida_pre_get(&server->openowner_id, gfp_flags) == 0)
534 spin_lock(&clp->cl_lock); 504 break;
535 sp = nfs4_insert_state_owner_locked(new); 505 spin_lock(&clp->cl_lock);
536 spin_unlock(&clp->cl_lock); 506 sp = nfs4_insert_state_owner_locked(new);
537 if (sp == new) 507 spin_unlock(&clp->cl_lock);
538 get_rpccred(cred); 508 } while (sp == ERR_PTR(-EAGAIN));
539 else { 509 if (sp != new)
540 rpc_destroy_wait_queue(&new->so_sequence.wait); 510 nfs4_free_state_owner(new);
541 kfree(new);
542 }
543out: 511out:
544 nfs4_gc_state_owners(server); 512 nfs4_gc_state_owners(server);
545 return sp; 513 return sp;
@@ -795,15 +763,11 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
795{ 763{
796 struct nfs4_lock_state *lsp; 764 struct nfs4_lock_state *lsp;
797 struct nfs_server *server = state->owner->so_server; 765 struct nfs_server *server = state->owner->so_server;
798 struct nfs_client *clp = server->nfs_client;
799 766
800 lsp = kzalloc(sizeof(*lsp), GFP_NOFS); 767 lsp = kzalloc(sizeof(*lsp), GFP_NOFS);
801 if (lsp == NULL) 768 if (lsp == NULL)
802 return NULL; 769 return NULL;
803 rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue"); 770 nfs4_init_seqid_counter(&lsp->ls_seqid);
804 spin_lock_init(&lsp->ls_sequence.lock);
805 INIT_LIST_HEAD(&lsp->ls_sequence.list);
806 lsp->ls_seqid.sequence = &lsp->ls_sequence;
807 atomic_set(&lsp->ls_count, 1); 771 atomic_set(&lsp->ls_count, 1);
808 lsp->ls_state = state; 772 lsp->ls_state = state;
809 lsp->ls_owner.lo_type = type; 773 lsp->ls_owner.lo_type = type;
@@ -815,25 +779,22 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
815 lsp->ls_owner.lo_u.posix_owner = fl_owner; 779 lsp->ls_owner.lo_u.posix_owner = fl_owner;
816 break; 780 break;
817 default: 781 default:
818 kfree(lsp); 782 goto out_free;
819 return NULL;
820 } 783 }
821 spin_lock(&clp->cl_lock); 784 lsp->ls_seqid.owner_id = ida_simple_get(&server->lockowner_id, 0, 0, GFP_NOFS);
822 nfs_alloc_unique_id_locked(&server->lockowner_id, &lsp->ls_id, 1, 64); 785 if (lsp->ls_seqid.owner_id < 0)
823 spin_unlock(&clp->cl_lock); 786 goto out_free;
824 INIT_LIST_HEAD(&lsp->ls_locks); 787 INIT_LIST_HEAD(&lsp->ls_locks);
825 return lsp; 788 return lsp;
789out_free:
790 kfree(lsp);
791 return NULL;
826} 792}
827 793
828static void nfs4_free_lock_state(struct nfs4_lock_state *lsp) 794void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp)
829{ 795{
830 struct nfs_server *server = lsp->ls_state->owner->so_server; 796 ida_simple_remove(&server->lockowner_id, lsp->ls_seqid.owner_id);
831 struct nfs_client *clp = server->nfs_client; 797 nfs4_destroy_seqid_counter(&lsp->ls_seqid);
832
833 spin_lock(&clp->cl_lock);
834 nfs_free_unique_id(&server->lockowner_id, &lsp->ls_id);
835 spin_unlock(&clp->cl_lock);
836 rpc_destroy_wait_queue(&lsp->ls_sequence.wait);
837 kfree(lsp); 798 kfree(lsp);
838} 799}
839 800
@@ -865,7 +826,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_
865 } 826 }
866 spin_unlock(&state->state_lock); 827 spin_unlock(&state->state_lock);
867 if (new != NULL) 828 if (new != NULL)
868 nfs4_free_lock_state(new); 829 nfs4_free_lock_state(state->owner->so_server, new);
869 return lsp; 830 return lsp;
870} 831}
871 832
@@ -886,9 +847,11 @@ void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
886 if (list_empty(&state->lock_states)) 847 if (list_empty(&state->lock_states))
887 clear_bit(LK_STATE_IN_USE, &state->flags); 848 clear_bit(LK_STATE_IN_USE, &state->flags);
888 spin_unlock(&state->state_lock); 849 spin_unlock(&state->state_lock);
889 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) 850 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) {
890 nfs4_release_lockowner(lsp); 851 if (nfs4_release_lockowner(lsp) == 0)
891 nfs4_free_lock_state(lsp); 852 return;
853 }
854 nfs4_free_lock_state(lsp->ls_state->owner->so_server, lsp);
892} 855}
893 856
894static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) 857static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
@@ -918,7 +881,8 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
918 if (fl->fl_flags & FL_POSIX) 881 if (fl->fl_flags & FL_POSIX)
919 lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE); 882 lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE);
920 else if (fl->fl_flags & FL_FLOCK) 883 else if (fl->fl_flags & FL_FLOCK)
921 lsp = nfs4_get_lock_state(state, 0, fl->fl_pid, NFS4_FLOCK_LOCK_TYPE); 884 lsp = nfs4_get_lock_state(state, NULL, fl->fl_pid,
885 NFS4_FLOCK_LOCK_TYPE);
922 else 886 else
923 return -EINVAL; 887 return -EINVAL;
924 if (lsp == NULL) 888 if (lsp == NULL)
@@ -928,28 +892,49 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
928 return 0; 892 return 0;
929} 893}
930 894
931/* 895static bool nfs4_copy_lock_stateid(nfs4_stateid *dst, struct nfs4_state *state,
932 * Byte-range lock aware utility to initialize the stateid of read/write 896 fl_owner_t fl_owner, pid_t fl_pid)
933 * requests.
934 */
935void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
936{ 897{
937 struct nfs4_lock_state *lsp; 898 struct nfs4_lock_state *lsp;
938 int seq; 899 bool ret = false;
939 900
940 do {
941 seq = read_seqbegin(&state->seqlock);
942 memcpy(dst, &state->stateid, sizeof(*dst));
943 } while (read_seqretry(&state->seqlock, seq));
944 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) 901 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
945 return; 902 goto out;
946 903
947 spin_lock(&state->state_lock); 904 spin_lock(&state->state_lock);
948 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE); 905 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
949 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) 906 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) {
950 memcpy(dst, &lsp->ls_stateid, sizeof(*dst)); 907 nfs4_stateid_copy(dst, &lsp->ls_stateid);
908 ret = true;
909 }
951 spin_unlock(&state->state_lock); 910 spin_unlock(&state->state_lock);
952 nfs4_put_lock_state(lsp); 911 nfs4_put_lock_state(lsp);
912out:
913 return ret;
914}
915
916static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
917{
918 int seq;
919
920 do {
921 seq = read_seqbegin(&state->seqlock);
922 nfs4_stateid_copy(dst, &state->stateid);
923 } while (read_seqretry(&state->seqlock, seq));
924}
925
926/*
927 * Byte-range lock aware utility to initialize the stateid of read/write
928 * requests.
929 */
930void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state,
931 fmode_t fmode, fl_owner_t fl_owner, pid_t fl_pid)
932{
933 if (nfs4_copy_delegation_stateid(dst, state->inode, fmode))
934 return;
935 if (nfs4_copy_lock_stateid(dst, state, fl_owner, fl_pid))
936 return;
937 nfs4_copy_open_stateid(dst, state);
953} 938}
954 939
955struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask) 940struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask)
@@ -960,20 +945,28 @@ struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_m
960 if (new != NULL) { 945 if (new != NULL) {
961 new->sequence = counter; 946 new->sequence = counter;
962 INIT_LIST_HEAD(&new->list); 947 INIT_LIST_HEAD(&new->list);
948 new->task = NULL;
963 } 949 }
964 return new; 950 return new;
965} 951}
966 952
967void nfs_release_seqid(struct nfs_seqid *seqid) 953void nfs_release_seqid(struct nfs_seqid *seqid)
968{ 954{
969 if (!list_empty(&seqid->list)) { 955 struct nfs_seqid_counter *sequence;
970 struct rpc_sequence *sequence = seqid->sequence->sequence;
971 956
972 spin_lock(&sequence->lock); 957 if (list_empty(&seqid->list))
973 list_del_init(&seqid->list); 958 return;
974 spin_unlock(&sequence->lock); 959 sequence = seqid->sequence;
975 rpc_wake_up(&sequence->wait); 960 spin_lock(&sequence->lock);
961 list_del_init(&seqid->list);
962 if (!list_empty(&sequence->list)) {
963 struct nfs_seqid *next;
964
965 next = list_first_entry(&sequence->list,
966 struct nfs_seqid, list);
967 rpc_wake_up_queued_task(&sequence->wait, next->task);
976 } 968 }
969 spin_unlock(&sequence->lock);
977} 970}
978 971
979void nfs_free_seqid(struct nfs_seqid *seqid) 972void nfs_free_seqid(struct nfs_seqid *seqid)
@@ -989,14 +982,14 @@ void nfs_free_seqid(struct nfs_seqid *seqid)
989 */ 982 */
990static void nfs_increment_seqid(int status, struct nfs_seqid *seqid) 983static void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
991{ 984{
992 BUG_ON(list_first_entry(&seqid->sequence->sequence->list, struct nfs_seqid, list) != seqid); 985 BUG_ON(list_first_entry(&seqid->sequence->list, struct nfs_seqid, list) != seqid);
993 switch (status) { 986 switch (status) {
994 case 0: 987 case 0:
995 break; 988 break;
996 case -NFS4ERR_BAD_SEQID: 989 case -NFS4ERR_BAD_SEQID:
997 if (seqid->sequence->flags & NFS_SEQID_CONFIRMED) 990 if (seqid->sequence->flags & NFS_SEQID_CONFIRMED)
998 return; 991 return;
999 printk(KERN_WARNING "NFS: v4 server returned a bad" 992 pr_warn_ratelimited("NFS: v4 server returned a bad"
1000 " sequence-id error on an" 993 " sequence-id error on an"
1001 " unconfirmed sequence %p!\n", 994 " unconfirmed sequence %p!\n",
1002 seqid->sequence); 995 seqid->sequence);
@@ -1040,10 +1033,11 @@ void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid)
1040 1033
1041int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) 1034int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task)
1042{ 1035{
1043 struct rpc_sequence *sequence = seqid->sequence->sequence; 1036 struct nfs_seqid_counter *sequence = seqid->sequence;
1044 int status = 0; 1037 int status = 0;
1045 1038
1046 spin_lock(&sequence->lock); 1039 spin_lock(&sequence->lock);
1040 seqid->task = task;
1047 if (list_empty(&seqid->list)) 1041 if (list_empty(&seqid->list))
1048 list_add_tail(&seqid->list, &sequence->list); 1042 list_add_tail(&seqid->list, &sequence->list);
1049 if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid) 1043 if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid)
@@ -1072,19 +1066,28 @@ static void nfs4_clear_state_manager_bit(struct nfs_client *clp)
1072void nfs4_schedule_state_manager(struct nfs_client *clp) 1066void nfs4_schedule_state_manager(struct nfs_client *clp)
1073{ 1067{
1074 struct task_struct *task; 1068 struct task_struct *task;
1069 char buf[INET6_ADDRSTRLEN + sizeof("-manager") + 1];
1075 1070
1076 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) 1071 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
1077 return; 1072 return;
1078 __module_get(THIS_MODULE); 1073 __module_get(THIS_MODULE);
1079 atomic_inc(&clp->cl_count); 1074 atomic_inc(&clp->cl_count);
1080 task = kthread_run(nfs4_run_state_manager, clp, "%s-manager", 1075
1081 rpc_peeraddr2str(clp->cl_rpcclient, 1076 /* The rcu_read_lock() is not strictly necessary, as the state
1082 RPC_DISPLAY_ADDR)); 1077 * manager is the only thread that ever changes the rpc_xprt
1083 if (!IS_ERR(task)) 1078 * after it's initialized. At this point, we're single threaded. */
1084 return; 1079 rcu_read_lock();
1085 nfs4_clear_state_manager_bit(clp); 1080 snprintf(buf, sizeof(buf), "%s-manager",
1086 nfs_put_client(clp); 1081 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
1087 module_put(THIS_MODULE); 1082 rcu_read_unlock();
1083 task = kthread_run(nfs4_run_state_manager, clp, buf);
1084 if (IS_ERR(task)) {
1085 printk(KERN_ERR "%s: kthread_run: %ld\n",
1086 __func__, PTR_ERR(task));
1087 nfs4_clear_state_manager_bit(clp);
1088 nfs_put_client(clp);
1089 module_put(THIS_MODULE);
1090 }
1088} 1091}
1089 1092
1090/* 1093/*
@@ -1098,10 +1101,25 @@ void nfs4_schedule_lease_recovery(struct nfs_client *clp)
1098 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); 1101 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1099 nfs4_schedule_state_manager(clp); 1102 nfs4_schedule_state_manager(clp);
1100} 1103}
1104EXPORT_SYMBOL_GPL(nfs4_schedule_lease_recovery);
1105
1106/*
1107 * nfs40_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
1108 * @clp: client to process
1109 *
1110 * Set the NFS4CLNT_LEASE_EXPIRED state in order to force a
1111 * resend of the SETCLIENTID and hence re-establish the
1112 * callback channel. Then return all existing delegations.
1113 */
1114static void nfs40_handle_cb_pathdown(struct nfs_client *clp)
1115{
1116 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1117 nfs_expire_all_delegations(clp);
1118}
1101 1119
1102void nfs4_schedule_path_down_recovery(struct nfs_client *clp) 1120void nfs4_schedule_path_down_recovery(struct nfs_client *clp)
1103{ 1121{
1104 nfs_handle_cb_pathdown(clp); 1122 nfs40_handle_cb_pathdown(clp);
1105 nfs4_schedule_state_manager(clp); 1123 nfs4_schedule_state_manager(clp);
1106} 1124}
1107 1125
@@ -1135,6 +1153,34 @@ void nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4
1135 nfs4_state_mark_reclaim_nograce(clp, state); 1153 nfs4_state_mark_reclaim_nograce(clp, state);
1136 nfs4_schedule_state_manager(clp); 1154 nfs4_schedule_state_manager(clp);
1137} 1155}
1156EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery);
1157
1158void nfs_inode_find_state_and_recover(struct inode *inode,
1159 const nfs4_stateid *stateid)
1160{
1161 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
1162 struct nfs_inode *nfsi = NFS_I(inode);
1163 struct nfs_open_context *ctx;
1164 struct nfs4_state *state;
1165 bool found = false;
1166
1167 spin_lock(&inode->i_lock);
1168 list_for_each_entry(ctx, &nfsi->open_files, list) {
1169 state = ctx->state;
1170 if (state == NULL)
1171 continue;
1172 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
1173 continue;
1174 if (!nfs4_stateid_match(&state->stateid, stateid))
1175 continue;
1176 nfs4_state_mark_reclaim_nograce(clp, state);
1177 found = true;
1178 }
1179 spin_unlock(&inode->i_lock);
1180 if (found)
1181 nfs4_schedule_state_manager(clp);
1182}
1183
1138 1184
1139static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) 1185static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
1140{ 1186{
@@ -1173,8 +1219,8 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
1173 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: 1219 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1174 goto out; 1220 goto out;
1175 default: 1221 default:
1176 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", 1222 printk(KERN_ERR "NFS: %s: unhandled error %d. "
1177 __func__, status); 1223 "Zeroing state\n", __func__, status);
1178 case -ENOMEM: 1224 case -ENOMEM:
1179 case -NFS4ERR_DENIED: 1225 case -NFS4ERR_DENIED:
1180 case -NFS4ERR_RECLAIM_BAD: 1226 case -NFS4ERR_RECLAIM_BAD:
@@ -1220,8 +1266,9 @@ restart:
1220 spin_lock(&state->state_lock); 1266 spin_lock(&state->state_lock);
1221 list_for_each_entry(lock, &state->lock_states, ls_locks) { 1267 list_for_each_entry(lock, &state->lock_states, ls_locks) {
1222 if (!(lock->ls_flags & NFS_LOCK_INITIALIZED)) 1268 if (!(lock->ls_flags & NFS_LOCK_INITIALIZED))
1223 printk("%s: Lock reclaim failed!\n", 1269 pr_warn_ratelimited("NFS: "
1224 __func__); 1270 "%s: Lock reclaim "
1271 "failed!\n", __func__);
1225 } 1272 }
1226 spin_unlock(&state->state_lock); 1273 spin_unlock(&state->state_lock);
1227 nfs4_put_open_state(state); 1274 nfs4_put_open_state(state);
@@ -1230,8 +1277,8 @@ restart:
1230 } 1277 }
1231 switch (status) { 1278 switch (status) {
1232 default: 1279 default:
1233 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", 1280 printk(KERN_ERR "NFS: %s: unhandled error %d. "
1234 __func__, status); 1281 "Zeroing state\n", __func__, status);
1235 case -ENOENT: 1282 case -ENOENT:
1236 case -ENOMEM: 1283 case -ENOMEM:
1237 case -ESTALE: 1284 case -ESTALE:
@@ -1239,8 +1286,8 @@ restart:
1239 * Open state on this file cannot be recovered 1286 * Open state on this file cannot be recovered
1240 * All we can do is revert to using the zero stateid. 1287 * All we can do is revert to using the zero stateid.
1241 */ 1288 */
1242 memset(state->stateid.data, 0, 1289 memset(&state->stateid, 0,
1243 sizeof(state->stateid.data)); 1290 sizeof(state->stateid));
1244 /* Mark the file as being 'closed' */ 1291 /* Mark the file as being 'closed' */
1245 state->state = 0; 1292 state->state = 0;
1246 break; 1293 break;
@@ -1418,7 +1465,7 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1418 case 0: 1465 case 0:
1419 break; 1466 break;
1420 case -NFS4ERR_CB_PATH_DOWN: 1467 case -NFS4ERR_CB_PATH_DOWN:
1421 nfs_handle_cb_pathdown(clp); 1468 nfs40_handle_cb_pathdown(clp);
1422 break; 1469 break;
1423 case -NFS4ERR_NO_GRACE: 1470 case -NFS4ERR_NO_GRACE:
1424 nfs4_state_end_reclaim_reboot(clp); 1471 nfs4_state_end_reclaim_reboot(clp);
@@ -1799,7 +1846,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
1799 } while (atomic_read(&clp->cl_count) > 1); 1846 } while (atomic_read(&clp->cl_count) > 1);
1800 return; 1847 return;
1801out_error: 1848out_error:
1802 printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s" 1849 pr_warn_ratelimited("NFS: state manager failed on NFSv4 server %s"
1803 " with error %d\n", clp->cl_hostname, -status); 1850 " with error %d\n", clp->cl_hostname, -status);
1804 nfs4_end_drain_session(clp); 1851 nfs4_end_drain_session(clp);
1805 nfs4_clear_state_manager_bit(clp); 1852 nfs4_clear_state_manager_bit(clp);
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 95e92e438407..c74fdb114b48 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -44,6 +44,8 @@
44#include <linux/pagemap.h> 44#include <linux/pagemap.h>
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h> 46#include <linux/kdev_t.h>
47#include <linux/module.h>
48#include <linux/utsname.h>
47#include <linux/sunrpc/clnt.h> 49#include <linux/sunrpc/clnt.h>
48#include <linux/sunrpc/msg_prot.h> 50#include <linux/sunrpc/msg_prot.h>
49#include <linux/sunrpc/gss_api.h> 51#include <linux/sunrpc/gss_api.h>
@@ -271,7 +273,12 @@ static int nfs4_stat_to_errno(int);
271 1 /* flags */ + \ 273 1 /* flags */ + \
272 1 /* spa_how */ + \ 274 1 /* spa_how */ + \
273 0 /* SP4_NONE (for now) */ + \ 275 0 /* SP4_NONE (for now) */ + \
274 1 /* zero implemetation id array */) 276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
275#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
276 2 /* eir_clientid */ + \ 283 2 /* eir_clientid */ + \
277 1 /* eir_sequenceid */ + \ 284 1 /* eir_sequenceid */ + \
@@ -284,7 +291,11 @@ static int nfs4_stat_to_errno(int);
284 /* eir_server_scope<> */ \ 291 /* eir_server_scope<> */ \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
286 1 /* eir_server_impl_id array length */ + \ 293 1 /* eir_server_impl_id array length */ + \
287 0 /* ignored eir_server_impl_id contents */) 294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
288#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
289#define decode_channel_attrs_maxsz (6 + \ 300#define decode_channel_attrs_maxsz (6 + \
290 1 /* ca_rdma_ird.len */ + \ 301 1 /* ca_rdma_ird.len */ + \
@@ -838,6 +849,12 @@ const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
838 XDR_UNIT); 849 XDR_UNIT);
839#endif /* CONFIG_NFS_V4_1 */ 850#endif /* CONFIG_NFS_V4_1 */
840 851
852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
841static const umode_t nfs_type2fmt[] = { 858static const umode_t nfs_type2fmt[] = {
842 [NF4BAD] = 0, 859 [NF4BAD] = 0,
843 [NF4REG] = S_IFREG, 860 [NF4REG] = S_IFREG,
@@ -868,15 +885,44 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
868 return p; 885 return p;
869} 886}
870 887
888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
871static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
872{ 897{
873 __be32 *p; 898 __be32 *p;
874 899
875 p = xdr_reserve_space(xdr, 4 + len); 900 p = reserve_space(xdr, 4 + len);
876 BUG_ON(p == NULL);
877 xdr_encode_opaque(p, str, len); 901 xdr_encode_opaque(p, str, len);
878} 902}
879 903
904static void encode_uint32(struct xdr_stream *xdr, u32 n)
905{
906 __be32 *p;
907
908 p = reserve_space(xdr, 4);
909 *p = cpu_to_be32(n);
910}
911
912static void encode_uint64(struct xdr_stream *xdr, u64 n)
913{
914 __be32 *p;
915
916 p = reserve_space(xdr, 8);
917 xdr_encode_hyper(p, n);
918}
919
920static void encode_nfs4_seqid(struct xdr_stream *xdr,
921 const struct nfs_seqid *seqid)
922{
923 encode_uint32(xdr, seqid->sequence->counter);
924}
925
880static void encode_compound_hdr(struct xdr_stream *xdr, 926static void encode_compound_hdr(struct xdr_stream *xdr,
881 struct rpc_rqst *req, 927 struct rpc_rqst *req,
882 struct compound_hdr *hdr) 928 struct compound_hdr *hdr)
@@ -889,28 +935,37 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
889 * but this is not required as a MUST for the server to do so. */ 935 * but this is not required as a MUST for the server to do so. */
890 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 936 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
891 937
892 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
893 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 938 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
894 p = reserve_space(xdr, 4 + hdr->taglen + 8); 939 encode_string(xdr, hdr->taglen, hdr->tag);
895 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen); 940 p = reserve_space(xdr, 8);
896 *p++ = cpu_to_be32(hdr->minorversion); 941 *p++ = cpu_to_be32(hdr->minorversion);
897 hdr->nops_p = p; 942 hdr->nops_p = p;
898 *p = cpu_to_be32(hdr->nops); 943 *p = cpu_to_be32(hdr->nops);
899} 944}
900 945
946static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
947 uint32_t replen,
948 struct compound_hdr *hdr)
949{
950 encode_uint32(xdr, op);
951 hdr->nops++;
952 hdr->replen += replen;
953}
954
901static void encode_nops(struct compound_hdr *hdr) 955static void encode_nops(struct compound_hdr *hdr)
902{ 956{
903 BUG_ON(hdr->nops > NFS4_MAX_OPS); 957 BUG_ON(hdr->nops > NFS4_MAX_OPS);
904 *hdr->nops_p = htonl(hdr->nops); 958 *hdr->nops_p = htonl(hdr->nops);
905} 959}
906 960
907static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 961static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
908{ 962{
909 __be32 *p; 963 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
964}
910 965
911 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); 966static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
912 BUG_ON(p == NULL); 967{
913 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); 968 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
914} 969}
915 970
916static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 971static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
@@ -1023,7 +1078,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
1023 * Now we backfill the bitmap and the attribute buffer length. 1078 * Now we backfill the bitmap and the attribute buffer length.
1024 */ 1079 */
1025 if (len != ((char *)p - (char *)q) + 4) { 1080 if (len != ((char *)p - (char *)q) + 4) {
1026 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n", 1081 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
1027 len, ((char *)p - (char *)q) + 4); 1082 len, ((char *)p - (char *)q) + 4);
1028 BUG(); 1083 BUG();
1029 } 1084 }
@@ -1037,46 +1092,33 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
1037 1092
1038static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 1093static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1039{ 1094{
1040 __be32 *p; 1095 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1041 1096 encode_uint32(xdr, access);
1042 p = reserve_space(xdr, 8);
1043 *p++ = cpu_to_be32(OP_ACCESS);
1044 *p = cpu_to_be32(access);
1045 hdr->nops++;
1046 hdr->replen += decode_access_maxsz;
1047} 1097}
1048 1098
1049static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 1099static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1050{ 1100{
1051 __be32 *p; 1101 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1052 1102 encode_nfs4_seqid(xdr, arg->seqid);
1053 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE); 1103 encode_nfs4_stateid(xdr, arg->stateid);
1054 *p++ = cpu_to_be32(OP_CLOSE);
1055 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1056 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1057 hdr->nops++;
1058 hdr->replen += decode_close_maxsz;
1059} 1104}
1060 1105
1061static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 1106static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1062{ 1107{
1063 __be32 *p; 1108 __be32 *p;
1064 1109
1065 p = reserve_space(xdr, 16); 1110 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1066 *p++ = cpu_to_be32(OP_COMMIT); 1111 p = reserve_space(xdr, 12);
1067 p = xdr_encode_hyper(p, args->offset); 1112 p = xdr_encode_hyper(p, args->offset);
1068 *p = cpu_to_be32(args->count); 1113 *p = cpu_to_be32(args->count);
1069 hdr->nops++;
1070 hdr->replen += decode_commit_maxsz;
1071} 1114}
1072 1115
1073static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 1116static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1074{ 1117{
1075 __be32 *p; 1118 __be32 *p;
1076 1119
1077 p = reserve_space(xdr, 8); 1120 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1078 *p++ = cpu_to_be32(OP_CREATE); 1121 encode_uint32(xdr, create->ftype);
1079 *p = cpu_to_be32(create->ftype);
1080 1122
1081 switch (create->ftype) { 1123 switch (create->ftype) {
1082 case NF4LNK: 1124 case NF4LNK:
@@ -1096,9 +1138,6 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
1096 } 1138 }
1097 1139
1098 encode_string(xdr, create->name->len, create->name->name); 1140 encode_string(xdr, create->name->len, create->name->name);
1099 hdr->nops++;
1100 hdr->replen += decode_create_maxsz;
1101
1102 encode_attrs(xdr, create->attrs, create->server); 1141 encode_attrs(xdr, create->attrs, create->server);
1103} 1142}
1104 1143
@@ -1106,25 +1145,21 @@ static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct c
1106{ 1145{
1107 __be32 *p; 1146 __be32 *p;
1108 1147
1109 p = reserve_space(xdr, 12); 1148 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1110 *p++ = cpu_to_be32(OP_GETATTR); 1149 p = reserve_space(xdr, 8);
1111 *p++ = cpu_to_be32(1); 1150 *p++ = cpu_to_be32(1);
1112 *p = cpu_to_be32(bitmap); 1151 *p = cpu_to_be32(bitmap);
1113 hdr->nops++;
1114 hdr->replen += decode_getattr_maxsz;
1115} 1152}
1116 1153
1117static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 1154static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1118{ 1155{
1119 __be32 *p; 1156 __be32 *p;
1120 1157
1121 p = reserve_space(xdr, 16); 1158 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1122 *p++ = cpu_to_be32(OP_GETATTR); 1159 p = reserve_space(xdr, 12);
1123 *p++ = cpu_to_be32(2); 1160 *p++ = cpu_to_be32(2);
1124 *p++ = cpu_to_be32(bm0); 1161 *p++ = cpu_to_be32(bm0);
1125 *p = cpu_to_be32(bm1); 1162 *p = cpu_to_be32(bm1);
1126 hdr->nops++;
1127 hdr->replen += decode_getattr_maxsz;
1128} 1163}
1129 1164
1130static void 1165static void
@@ -1134,8 +1169,7 @@ encode_getattr_three(struct xdr_stream *xdr,
1134{ 1169{
1135 __be32 *p; 1170 __be32 *p;
1136 1171
1137 p = reserve_space(xdr, 4); 1172 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1138 *p = cpu_to_be32(OP_GETATTR);
1139 if (bm2) { 1173 if (bm2) {
1140 p = reserve_space(xdr, 16); 1174 p = reserve_space(xdr, 16);
1141 *p++ = cpu_to_be32(3); 1175 *p++ = cpu_to_be32(3);
@@ -1152,8 +1186,6 @@ encode_getattr_three(struct xdr_stream *xdr,
1152 *p++ = cpu_to_be32(1); 1186 *p++ = cpu_to_be32(1);
1153 *p = cpu_to_be32(bm0); 1187 *p = cpu_to_be32(bm0);
1154 } 1188 }
1155 hdr->nops++;
1156 hdr->replen += decode_getattr_maxsz;
1157} 1189}
1158 1190
1159static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1191static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
@@ -1179,23 +1211,13 @@ static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, stru
1179 1211
1180static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1212static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1181{ 1213{
1182 __be32 *p; 1214 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1183
1184 p = reserve_space(xdr, 4);
1185 *p = cpu_to_be32(OP_GETFH);
1186 hdr->nops++;
1187 hdr->replen += decode_getfh_maxsz;
1188} 1215}
1189 1216
1190static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1217static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1191{ 1218{
1192 __be32 *p; 1219 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1193 1220 encode_string(xdr, name->len, name->name);
1194 p = reserve_space(xdr, 8 + name->len);
1195 *p++ = cpu_to_be32(OP_LINK);
1196 xdr_encode_opaque(p, name->name, name->len);
1197 hdr->nops++;
1198 hdr->replen += decode_link_maxsz;
1199} 1221}
1200 1222
1201static inline int nfs4_lock_type(struct file_lock *fl, int block) 1223static inline int nfs4_lock_type(struct file_lock *fl, int block)
@@ -1232,79 +1254,60 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
1232{ 1254{
1233 __be32 *p; 1255 __be32 *p;
1234 1256
1235 p = reserve_space(xdr, 32); 1257 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1236 *p++ = cpu_to_be32(OP_LOCK); 1258 p = reserve_space(xdr, 28);
1237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1259 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim); 1260 *p++ = cpu_to_be32(args->reclaim);
1239 p = xdr_encode_hyper(p, args->fl->fl_start); 1261 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1241 *p = cpu_to_be32(args->new_lock_owner); 1263 *p = cpu_to_be32(args->new_lock_owner);
1242 if (args->new_lock_owner){ 1264 if (args->new_lock_owner){
1243 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1265 encode_nfs4_seqid(xdr, args->open_seqid);
1244 *p++ = cpu_to_be32(args->open_seqid->sequence->counter); 1266 encode_nfs4_stateid(xdr, args->open_stateid);
1245 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE); 1267 encode_nfs4_seqid(xdr, args->lock_seqid);
1246 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1247 encode_lockowner(xdr, &args->lock_owner); 1268 encode_lockowner(xdr, &args->lock_owner);
1248 } 1269 }
1249 else { 1270 else {
1250 p = reserve_space(xdr, NFS4_STATEID_SIZE+4); 1271 encode_nfs4_stateid(xdr, args->lock_stateid);
1251 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE); 1272 encode_nfs4_seqid(xdr, args->lock_seqid);
1252 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1253 } 1273 }
1254 hdr->nops++;
1255 hdr->replen += decode_lock_maxsz;
1256} 1274}
1257 1275
1258static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 1276static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1259{ 1277{
1260 __be32 *p; 1278 __be32 *p;
1261 1279
1262 p = reserve_space(xdr, 24); 1280 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1263 *p++ = cpu_to_be32(OP_LOCKT); 1281 p = reserve_space(xdr, 20);
1264 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1282 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1265 p = xdr_encode_hyper(p, args->fl->fl_start); 1283 p = xdr_encode_hyper(p, args->fl->fl_start);
1266 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1284 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1267 encode_lockowner(xdr, &args->lock_owner); 1285 encode_lockowner(xdr, &args->lock_owner);
1268 hdr->nops++;
1269 hdr->replen += decode_lockt_maxsz;
1270} 1286}
1271 1287
1272static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 1288static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1273{ 1289{
1274 __be32 *p; 1290 __be32 *p;
1275 1291
1276 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16); 1292 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1277 *p++ = cpu_to_be32(OP_LOCKU); 1293 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1278 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1294 encode_nfs4_seqid(xdr, args->seqid);
1279 *p++ = cpu_to_be32(args->seqid->sequence->counter); 1295 encode_nfs4_stateid(xdr, args->stateid);
1280 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE); 1296 p = reserve_space(xdr, 16);
1281 p = xdr_encode_hyper(p, args->fl->fl_start); 1297 p = xdr_encode_hyper(p, args->fl->fl_start);
1282 xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1298 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1283 hdr->nops++;
1284 hdr->replen += decode_locku_maxsz;
1285} 1299}
1286 1300
1287static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1301static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1288{ 1302{
1289 __be32 *p; 1303 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1290
1291 p = reserve_space(xdr, 4);
1292 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1293 encode_lockowner(xdr, lowner); 1304 encode_lockowner(xdr, lowner);
1294 hdr->nops++;
1295 hdr->replen += decode_release_lockowner_maxsz;
1296} 1305}
1297 1306
1298static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1307static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1299{ 1308{
1300 int len = name->len; 1309 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1301 __be32 *p; 1310 encode_string(xdr, name->len, name->name);
1302
1303 p = reserve_space(xdr, 8 + len);
1304 *p++ = cpu_to_be32(OP_LOOKUP);
1305 xdr_encode_opaque(p, name->name, len);
1306 hdr->nops++;
1307 hdr->replen += decode_lookup_maxsz;
1308} 1311}
1309 1312
1310static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 1313static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
@@ -1335,9 +1338,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
1335 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 1338 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1336 * owner 4 = 32 1339 * owner 4 = 32
1337 */ 1340 */
1338 p = reserve_space(xdr, 8); 1341 encode_nfs4_seqid(xdr, arg->seqid);
1339 *p++ = cpu_to_be32(OP_OPEN);
1340 *p = cpu_to_be32(arg->seqid->sequence->counter);
1341 encode_share_access(xdr, arg->fmode); 1342 encode_share_access(xdr, arg->fmode);
1342 p = reserve_space(xdr, 32); 1343 p = reserve_space(xdr, 32);
1343 p = xdr_encode_hyper(p, arg->clientid); 1344 p = xdr_encode_hyper(p, arg->clientid);
@@ -1437,14 +1438,15 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
1437{ 1438{
1438 __be32 *p; 1439 __be32 *p;
1439 1440
1440 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1441 p = reserve_space(xdr, 4);
1441 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1442 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1442 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); 1443 encode_nfs4_stateid(xdr, stateid);
1443 encode_string(xdr, name->len, name->name); 1444 encode_string(xdr, name->len, name->name);
1444} 1445}
1445 1446
1446static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 1447static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1447{ 1448{
1449 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1448 encode_openhdr(xdr, arg); 1450 encode_openhdr(xdr, arg);
1449 encode_opentype(xdr, arg); 1451 encode_opentype(xdr, arg);
1450 switch (arg->claim) { 1452 switch (arg->claim) {
@@ -1460,88 +1462,64 @@ static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg,
1460 default: 1462 default:
1461 BUG(); 1463 BUG();
1462 } 1464 }
1463 hdr->nops++;
1464 hdr->replen += decode_open_maxsz;
1465} 1465}
1466 1466
1467static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 1467static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1468{ 1468{
1469 __be32 *p; 1469 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1470 1470 encode_nfs4_stateid(xdr, arg->stateid);
1471 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1471 encode_nfs4_seqid(xdr, arg->seqid);
1472 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1473 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1474 *p = cpu_to_be32(arg->seqid->sequence->counter);
1475 hdr->nops++;
1476 hdr->replen += decode_open_confirm_maxsz;
1477} 1472}
1478 1473
1479static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 1474static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1480{ 1475{
1481 __be32 *p; 1476 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1482 1477 encode_nfs4_stateid(xdr, arg->stateid);
1483 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1478 encode_nfs4_seqid(xdr, arg->seqid);
1484 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1485 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1486 *p = cpu_to_be32(arg->seqid->sequence->counter);
1487 encode_share_access(xdr, arg->fmode); 1479 encode_share_access(xdr, arg->fmode);
1488 hdr->nops++;
1489 hdr->replen += decode_open_downgrade_maxsz;
1490} 1480}
1491 1481
1492static void 1482static void
1493encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 1483encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1494{ 1484{
1495 int len = fh->size; 1485 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1496 __be32 *p; 1486 encode_string(xdr, fh->size, fh->data);
1497
1498 p = reserve_space(xdr, 8 + len);
1499 *p++ = cpu_to_be32(OP_PUTFH);
1500 xdr_encode_opaque(p, fh->data, len);
1501 hdr->nops++;
1502 hdr->replen += decode_putfh_maxsz;
1503} 1487}
1504 1488
1505static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1489static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1506{ 1490{
1507 __be32 *p; 1491 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1508
1509 p = reserve_space(xdr, 4);
1510 *p = cpu_to_be32(OP_PUTROOTFH);
1511 hdr->nops++;
1512 hdr->replen += decode_putrootfh_maxsz;
1513} 1492}
1514 1493
1515static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid) 1494static void encode_open_stateid(struct xdr_stream *xdr,
1495 const struct nfs_open_context *ctx,
1496 const struct nfs_lock_context *l_ctx,
1497 fmode_t fmode,
1498 int zero_seqid)
1516{ 1499{
1517 nfs4_stateid stateid; 1500 nfs4_stateid stateid;
1518 __be32 *p;
1519 1501
1520 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1521 if (ctx->state != NULL) { 1502 if (ctx->state != NULL) {
1522 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid); 1503 nfs4_select_rw_stateid(&stateid, ctx->state,
1504 fmode, l_ctx->lockowner, l_ctx->pid);
1523 if (zero_seqid) 1505 if (zero_seqid)
1524 stateid.stateid.seqid = 0; 1506 stateid.seqid = 0;
1525 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE); 1507 encode_nfs4_stateid(xdr, &stateid);
1526 } else 1508 } else
1527 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); 1509 encode_nfs4_stateid(xdr, &zero_stateid);
1528} 1510}
1529 1511
1530static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 1512static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1531{ 1513{
1532 __be32 *p; 1514 __be32 *p;
1533 1515
1534 p = reserve_space(xdr, 4); 1516 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1535 *p = cpu_to_be32(OP_READ); 1517 encode_open_stateid(xdr, args->context, args->lock_context,
1536 1518 FMODE_READ, hdr->minorversion);
1537 encode_stateid(xdr, args->context, args->lock_context,
1538 hdr->minorversion);
1539 1519
1540 p = reserve_space(xdr, 12); 1520 p = reserve_space(xdr, 12);
1541 p = xdr_encode_hyper(p, args->offset); 1521 p = xdr_encode_hyper(p, args->offset);
1542 *p = cpu_to_be32(args->count); 1522 *p = cpu_to_be32(args->count);
1543 hdr->nops++;
1544 hdr->replen += decode_read_maxsz;
1545} 1523}
1546 1524
1547static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 1525static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
@@ -1551,7 +1529,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
1551 FATTR4_WORD1_MOUNTED_ON_FILEID, 1529 FATTR4_WORD1_MOUNTED_ON_FILEID,
1552 }; 1530 };
1553 uint32_t dircount = readdir->count >> 1; 1531 uint32_t dircount = readdir->count >> 1;
1554 __be32 *p; 1532 __be32 *p, verf[2];
1555 1533
1556 if (readdir->plus) { 1534 if (readdir->plus) {
1557 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 1535 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
@@ -1566,80 +1544,54 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
1566 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 1544 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1567 attrs[0] |= FATTR4_WORD0_FILEID; 1545 attrs[0] |= FATTR4_WORD0_FILEID;
1568 1546
1569 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20); 1547 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1570 *p++ = cpu_to_be32(OP_READDIR); 1548 encode_uint64(xdr, readdir->cookie);
1571 p = xdr_encode_hyper(p, readdir->cookie); 1549 encode_nfs4_verifier(xdr, &readdir->verifier);
1572 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE); 1550 p = reserve_space(xdr, 20);
1573 *p++ = cpu_to_be32(dircount); 1551 *p++ = cpu_to_be32(dircount);
1574 *p++ = cpu_to_be32(readdir->count); 1552 *p++ = cpu_to_be32(readdir->count);
1575 *p++ = cpu_to_be32(2); 1553 *p++ = cpu_to_be32(2);
1576 1554
1577 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 1555 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1578 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1556 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1579 hdr->nops++; 1557 memcpy(verf, readdir->verifier.data, sizeof(verf));
1580 hdr->replen += decode_readdir_maxsz;
1581 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 1558 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1582 __func__, 1559 __func__,
1583 (unsigned long long)readdir->cookie, 1560 (unsigned long long)readdir->cookie,
1584 ((u32 *)readdir->verifier.data)[0], 1561 verf[0], verf[1],
1585 ((u32 *)readdir->verifier.data)[1],
1586 attrs[0] & readdir->bitmask[0], 1562 attrs[0] & readdir->bitmask[0],
1587 attrs[1] & readdir->bitmask[1]); 1563 attrs[1] & readdir->bitmask[1]);
1588} 1564}
1589 1565
1590static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 1566static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1591{ 1567{
1592 __be32 *p; 1568 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1593
1594 p = reserve_space(xdr, 4);
1595 *p = cpu_to_be32(OP_READLINK);
1596 hdr->nops++;
1597 hdr->replen += decode_readlink_maxsz;
1598} 1569}
1599 1570
1600static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1571static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1601{ 1572{
1602 __be32 *p; 1573 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1603 1574 encode_string(xdr, name->len, name->name);
1604 p = reserve_space(xdr, 8 + name->len);
1605 *p++ = cpu_to_be32(OP_REMOVE);
1606 xdr_encode_opaque(p, name->name, name->len);
1607 hdr->nops++;
1608 hdr->replen += decode_remove_maxsz;
1609} 1575}
1610 1576
1611static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 1577static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1612{ 1578{
1613 __be32 *p; 1579 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1614
1615 p = reserve_space(xdr, 4);
1616 *p = cpu_to_be32(OP_RENAME);
1617 encode_string(xdr, oldname->len, oldname->name); 1580 encode_string(xdr, oldname->len, oldname->name);
1618 encode_string(xdr, newname->len, newname->name); 1581 encode_string(xdr, newname->len, newname->name);
1619 hdr->nops++;
1620 hdr->replen += decode_rename_maxsz;
1621} 1582}
1622 1583
1623static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr) 1584static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1585 struct compound_hdr *hdr)
1624{ 1586{
1625 __be32 *p; 1587 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1626 1588 encode_uint64(xdr, clid);
1627 p = reserve_space(xdr, 12);
1628 *p++ = cpu_to_be32(OP_RENEW);
1629 xdr_encode_hyper(p, client_stateid->cl_clientid);
1630 hdr->nops++;
1631 hdr->replen += decode_renew_maxsz;
1632} 1589}
1633 1590
1634static void 1591static void
1635encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1592encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1636{ 1593{
1637 __be32 *p; 1594 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1638
1639 p = reserve_space(xdr, 4);
1640 *p = cpu_to_be32(OP_RESTOREFH);
1641 hdr->nops++;
1642 hdr->replen += decode_restorefh_maxsz;
1643} 1595}
1644 1596
1645static void 1597static void
@@ -1647,9 +1599,8 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
1647{ 1599{
1648 __be32 *p; 1600 __be32 *p;
1649 1601
1650 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1602 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1651 *p++ = cpu_to_be32(OP_SETATTR); 1603 encode_nfs4_stateid(xdr, &zero_stateid);
1652 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1653 p = reserve_space(xdr, 2*4); 1604 p = reserve_space(xdr, 2*4);
1654 *p++ = cpu_to_be32(1); 1605 *p++ = cpu_to_be32(1);
1655 *p = cpu_to_be32(FATTR4_WORD0_ACL); 1606 *p = cpu_to_be32(FATTR4_WORD0_ACL);
@@ -1657,30 +1608,18 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
1657 p = reserve_space(xdr, 4); 1608 p = reserve_space(xdr, 4);
1658 *p = cpu_to_be32(arg->acl_len); 1609 *p = cpu_to_be32(arg->acl_len);
1659 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 1610 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1660 hdr->nops++;
1661 hdr->replen += decode_setacl_maxsz;
1662} 1611}
1663 1612
1664static void 1613static void
1665encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1614encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1666{ 1615{
1667 __be32 *p; 1616 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1668
1669 p = reserve_space(xdr, 4);
1670 *p = cpu_to_be32(OP_SAVEFH);
1671 hdr->nops++;
1672 hdr->replen += decode_savefh_maxsz;
1673} 1617}
1674 1618
1675static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 1619static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1676{ 1620{
1677 __be32 *p; 1621 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1678 1622 encode_nfs4_stateid(xdr, &arg->stateid);
1679 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1680 *p++ = cpu_to_be32(OP_SETATTR);
1681 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1682 hdr->nops++;
1683 hdr->replen += decode_setattr_maxsz;
1684 encode_attrs(xdr, arg->iap, server); 1623 encode_attrs(xdr, arg->iap, server);
1685} 1624}
1686 1625
@@ -1688,9 +1627,8 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
1688{ 1627{
1689 __be32 *p; 1628 __be32 *p;
1690 1629
1691 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE); 1630 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1692 *p++ = cpu_to_be32(OP_SETCLIENTID); 1631 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1693 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1694 1632
1695 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 1633 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1696 p = reserve_space(xdr, 4); 1634 p = reserve_space(xdr, 4);
@@ -1699,31 +1637,23 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
1699 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 1637 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1700 p = reserve_space(xdr, 4); 1638 p = reserve_space(xdr, 4);
1701 *p = cpu_to_be32(setclientid->sc_cb_ident); 1639 *p = cpu_to_be32(setclientid->sc_cb_ident);
1702 hdr->nops++;
1703 hdr->replen += decode_setclientid_maxsz;
1704} 1640}
1705 1641
1706static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 1642static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1707{ 1643{
1708 __be32 *p; 1644 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1709 1645 decode_setclientid_confirm_maxsz, hdr);
1710 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE); 1646 encode_uint64(xdr, arg->clientid);
1711 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM); 1647 encode_nfs4_verifier(xdr, &arg->confirm);
1712 p = xdr_encode_hyper(p, arg->clientid);
1713 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1714 hdr->nops++;
1715 hdr->replen += decode_setclientid_confirm_maxsz;
1716} 1648}
1717 1649
1718static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 1650static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1719{ 1651{
1720 __be32 *p; 1652 __be32 *p;
1721 1653
1722 p = reserve_space(xdr, 4); 1654 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1723 *p = cpu_to_be32(OP_WRITE); 1655 encode_open_stateid(xdr, args->context, args->lock_context,
1724 1656 FMODE_WRITE, hdr->minorversion);
1725 encode_stateid(xdr, args->context, args->lock_context,
1726 hdr->minorversion);
1727 1657
1728 p = reserve_space(xdr, 16); 1658 p = reserve_space(xdr, 16);
1729 p = xdr_encode_hyper(p, args->offset); 1659 p = xdr_encode_hyper(p, args->offset);
@@ -1731,32 +1661,18 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
1731 *p = cpu_to_be32(args->count); 1661 *p = cpu_to_be32(args->count);
1732 1662
1733 xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 1663 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1734 hdr->nops++;
1735 hdr->replen += decode_write_maxsz;
1736} 1664}
1737 1665
1738static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 1666static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1739{ 1667{
1740 __be32 *p; 1668 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1741 1669 encode_nfs4_stateid(xdr, stateid);
1742 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1743
1744 *p++ = cpu_to_be32(OP_DELEGRETURN);
1745 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1746 hdr->nops++;
1747 hdr->replen += decode_delegreturn_maxsz;
1748} 1670}
1749 1671
1750static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1672static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1751{ 1673{
1752 int len = name->len; 1674 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1753 __be32 *p; 1675 encode_string(xdr, name->len, name->name);
1754
1755 p = reserve_space(xdr, 8 + len);
1756 *p++ = cpu_to_be32(OP_SECINFO);
1757 xdr_encode_opaque(p, name->name, len);
1758 hdr->nops++;
1759 hdr->replen += decode_secinfo_maxsz;
1760} 1676}
1761 1677
1762#if defined(CONFIG_NFS_V4_1) 1678#if defined(CONFIG_NFS_V4_1)
@@ -1766,19 +1682,39 @@ static void encode_exchange_id(struct xdr_stream *xdr,
1766 struct compound_hdr *hdr) 1682 struct compound_hdr *hdr)
1767{ 1683{
1768 __be32 *p; 1684 __be32 *p;
1685 char impl_name[NFS4_OPAQUE_LIMIT];
1686 int len = 0;
1769 1687
1770 p = reserve_space(xdr, 4 + sizeof(args->verifier->data)); 1688 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1771 *p++ = cpu_to_be32(OP_EXCHANGE_ID); 1689 encode_nfs4_verifier(xdr, args->verifier);
1772 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1773 1690
1774 encode_string(xdr, args->id_len, args->id); 1691 encode_string(xdr, args->id_len, args->id);
1775 1692
1776 p = reserve_space(xdr, 12); 1693 p = reserve_space(xdr, 12);
1777 *p++ = cpu_to_be32(args->flags); 1694 *p++ = cpu_to_be32(args->flags);
1778 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1695 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1779 *p = cpu_to_be32(0); /* zero length implementation id array */ 1696
1780 hdr->nops++; 1697 if (send_implementation_id &&
1781 hdr->replen += decode_exchange_id_maxsz; 1698 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1699 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1700 <= NFS4_OPAQUE_LIMIT + 1)
1701 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1702 utsname()->sysname, utsname()->release,
1703 utsname()->version, utsname()->machine);
1704
1705 if (len > 0) {
1706 *p = cpu_to_be32(1); /* implementation id array length=1 */
1707
1708 encode_string(xdr,
1709 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1710 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1711 encode_string(xdr, len, impl_name);
1712 /* just send zeros for nii_date - the date is in nii_name */
1713 p = reserve_space(xdr, 12);
1714 p = xdr_encode_hyper(p, 0);
1715 *p = cpu_to_be32(0);
1716 } else
1717 *p = cpu_to_be32(0); /* implementation id array length=0 */
1782} 1718}
1783 1719
1784static void encode_create_session(struct xdr_stream *xdr, 1720static void encode_create_session(struct xdr_stream *xdr,
@@ -1801,8 +1737,8 @@ static void encode_create_session(struct xdr_stream *xdr,
1801 len = scnprintf(machine_name, sizeof(machine_name), "%s", 1737 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1802 clp->cl_ipaddr); 1738 clp->cl_ipaddr);
1803 1739
1804 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12); 1740 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1805 *p++ = cpu_to_be32(OP_CREATE_SESSION); 1741 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1806 p = xdr_encode_hyper(p, clp->cl_clientid); 1742 p = xdr_encode_hyper(p, clp->cl_clientid);
1807 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1743 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1808 *p++ = cpu_to_be32(args->flags); /*flags */ 1744 *p++ = cpu_to_be32(args->flags); /*flags */
@@ -1835,33 +1771,22 @@ static void encode_create_session(struct xdr_stream *xdr,
1835 *p++ = cpu_to_be32(0); /* UID */ 1771 *p++ = cpu_to_be32(0); /* UID */
1836 *p++ = cpu_to_be32(0); /* GID */ 1772 *p++ = cpu_to_be32(0); /* GID */
1837 *p = cpu_to_be32(0); /* No more gids */ 1773 *p = cpu_to_be32(0); /* No more gids */
1838 hdr->nops++;
1839 hdr->replen += decode_create_session_maxsz;
1840} 1774}
1841 1775
1842static void encode_destroy_session(struct xdr_stream *xdr, 1776static void encode_destroy_session(struct xdr_stream *xdr,
1843 struct nfs4_session *session, 1777 struct nfs4_session *session,
1844 struct compound_hdr *hdr) 1778 struct compound_hdr *hdr)
1845{ 1779{
1846 __be32 *p; 1780 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1847 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN); 1781 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1848 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1849 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1850 hdr->nops++;
1851 hdr->replen += decode_destroy_session_maxsz;
1852} 1782}
1853 1783
1854static void encode_reclaim_complete(struct xdr_stream *xdr, 1784static void encode_reclaim_complete(struct xdr_stream *xdr,
1855 struct nfs41_reclaim_complete_args *args, 1785 struct nfs41_reclaim_complete_args *args,
1856 struct compound_hdr *hdr) 1786 struct compound_hdr *hdr)
1857{ 1787{
1858 __be32 *p; 1788 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1859 1789 encode_uint32(xdr, args->one_fs);
1860 p = reserve_space(xdr, 8);
1861 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1862 *p++ = cpu_to_be32(args->one_fs);
1863 hdr->nops++;
1864 hdr->replen += decode_reclaim_complete_maxsz;
1865} 1790}
1866#endif /* CONFIG_NFS_V4_1 */ 1791#endif /* CONFIG_NFS_V4_1 */
1867 1792
@@ -1883,8 +1808,7 @@ static void encode_sequence(struct xdr_stream *xdr,
1883 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1808 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1884 slot = tp->slots + args->sa_slotid; 1809 slot = tp->slots + args->sa_slotid;
1885 1810
1886 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16); 1811 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1887 *p++ = cpu_to_be32(OP_SEQUENCE);
1888 1812
1889 /* 1813 /*
1890 * Sessionid + seqid + slotid + max slotid + cache_this 1814 * Sessionid + seqid + slotid + max slotid + cache_this
@@ -1898,13 +1822,12 @@ static void encode_sequence(struct xdr_stream *xdr,
1898 ((u32 *)session->sess_id.data)[3], 1822 ((u32 *)session->sess_id.data)[3],
1899 slot->seq_nr, args->sa_slotid, 1823 slot->seq_nr, args->sa_slotid,
1900 tp->highest_used_slotid, args->sa_cache_this); 1824 tp->highest_used_slotid, args->sa_cache_this);
1825 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1901 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1826 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1902 *p++ = cpu_to_be32(slot->seq_nr); 1827 *p++ = cpu_to_be32(slot->seq_nr);
1903 *p++ = cpu_to_be32(args->sa_slotid); 1828 *p++ = cpu_to_be32(args->sa_slotid);
1904 *p++ = cpu_to_be32(tp->highest_used_slotid); 1829 *p++ = cpu_to_be32(tp->highest_used_slotid);
1905 *p = cpu_to_be32(args->sa_cache_this); 1830 *p = cpu_to_be32(args->sa_cache_this);
1906 hdr->nops++;
1907 hdr->replen += decode_sequence_maxsz;
1908#endif /* CONFIG_NFS_V4_1 */ 1831#endif /* CONFIG_NFS_V4_1 */
1909} 1832}
1910 1833
@@ -1919,14 +1842,12 @@ encode_getdevicelist(struct xdr_stream *xdr,
1919 .data = "dummmmmy", 1842 .data = "dummmmmy",
1920 }; 1843 };
1921 1844
1922 p = reserve_space(xdr, 20); 1845 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1923 *p++ = cpu_to_be32(OP_GETDEVICELIST); 1846 p = reserve_space(xdr, 16);
1924 *p++ = cpu_to_be32(args->layoutclass); 1847 *p++ = cpu_to_be32(args->layoutclass);
1925 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 1848 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1926 xdr_encode_hyper(p, 0ULL); /* cookie */ 1849 xdr_encode_hyper(p, 0ULL); /* cookie */
1927 encode_nfs4_verifier(xdr, &dummy); 1850 encode_nfs4_verifier(xdr, &dummy);
1928 hdr->nops++;
1929 hdr->replen += decode_getdevicelist_maxsz;
1930} 1851}
1931 1852
1932static void 1853static void
@@ -1936,15 +1857,13 @@ encode_getdeviceinfo(struct xdr_stream *xdr,
1936{ 1857{
1937 __be32 *p; 1858 __be32 *p;
1938 1859
1939 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE); 1860 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1940 *p++ = cpu_to_be32(OP_GETDEVICEINFO); 1861 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1941 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1862 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1942 NFS4_DEVICEID4_SIZE); 1863 NFS4_DEVICEID4_SIZE);
1943 *p++ = cpu_to_be32(args->pdev->layout_type); 1864 *p++ = cpu_to_be32(args->pdev->layout_type);
1944 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1865 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1945 *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1866 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1946 hdr->nops++;
1947 hdr->replen += decode_getdeviceinfo_maxsz;
1948} 1867}
1949 1868
1950static void 1869static void
@@ -1954,16 +1873,16 @@ encode_layoutget(struct xdr_stream *xdr,
1954{ 1873{
1955 __be32 *p; 1874 __be32 *p;
1956 1875
1957 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); 1876 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1958 *p++ = cpu_to_be32(OP_LAYOUTGET); 1877 p = reserve_space(xdr, 36);
1959 *p++ = cpu_to_be32(0); /* Signal layout available */ 1878 *p++ = cpu_to_be32(0); /* Signal layout available */
1960 *p++ = cpu_to_be32(args->type); 1879 *p++ = cpu_to_be32(args->type);
1961 *p++ = cpu_to_be32(args->range.iomode); 1880 *p++ = cpu_to_be32(args->range.iomode);
1962 p = xdr_encode_hyper(p, args->range.offset); 1881 p = xdr_encode_hyper(p, args->range.offset);
1963 p = xdr_encode_hyper(p, args->range.length); 1882 p = xdr_encode_hyper(p, args->range.length);
1964 p = xdr_encode_hyper(p, args->minlength); 1883 p = xdr_encode_hyper(p, args->minlength);
1965 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); 1884 encode_nfs4_stateid(xdr, &args->stateid);
1966 *p = cpu_to_be32(args->maxcount); 1885 encode_uint32(xdr, args->maxcount);
1967 1886
1968 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1887 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1969 __func__, 1888 __func__,
@@ -1972,8 +1891,6 @@ encode_layoutget(struct xdr_stream *xdr,
1972 (unsigned long)args->range.offset, 1891 (unsigned long)args->range.offset,
1973 (unsigned long)args->range.length, 1892 (unsigned long)args->range.length,
1974 args->maxcount); 1893 args->maxcount);
1975 hdr->nops++;
1976 hdr->replen += decode_layoutget_maxsz;
1977} 1894}
1978 1895
1979static int 1896static int
@@ -1987,13 +1904,14 @@ encode_layoutcommit(struct xdr_stream *xdr,
1987 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1904 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988 NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1905 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1989 1906
1990 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); 1907 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1991 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT); 1908 p = reserve_space(xdr, 20);
1992 /* Only whole file layouts */ 1909 /* Only whole file layouts */
1993 p = xdr_encode_hyper(p, 0); /* offset */ 1910 p = xdr_encode_hyper(p, 0); /* offset */
1994 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1911 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1995 *p++ = cpu_to_be32(0); /* reclaim */ 1912 *p = cpu_to_be32(0); /* reclaim */
1996 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE); 1913 encode_nfs4_stateid(xdr, &args->stateid);
1914 p = reserve_space(xdr, 20);
1997 *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1915 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1998 p = xdr_encode_hyper(p, args->lastbytewritten); 1916 p = xdr_encode_hyper(p, args->lastbytewritten);
1999 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1917 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
@@ -2002,13 +1920,9 @@ encode_layoutcommit(struct xdr_stream *xdr,
2002 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1920 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2003 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1921 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2004 NFS_I(inode)->layout, xdr, args); 1922 NFS_I(inode)->layout, xdr, args);
2005 else { 1923 else
2006 p = reserve_space(xdr, 4); 1924 encode_uint32(xdr, 0); /* no layout-type payload */
2007 *p = cpu_to_be32(0); /* no layout-type payload */
2008 }
2009 1925
2010 hdr->nops++;
2011 hdr->replen += decode_layoutcommit_maxsz;
2012 return 0; 1926 return 0;
2013} 1927}
2014 1928
@@ -2019,27 +1933,23 @@ encode_layoutreturn(struct xdr_stream *xdr,
2019{ 1933{
2020 __be32 *p; 1934 __be32 *p;
2021 1935
2022 p = reserve_space(xdr, 20); 1936 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2023 *p++ = cpu_to_be32(OP_LAYOUTRETURN); 1937 p = reserve_space(xdr, 16);
2024 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1938 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2025 *p++ = cpu_to_be32(args->layout_type); 1939 *p++ = cpu_to_be32(args->layout_type);
2026 *p++ = cpu_to_be32(IOMODE_ANY); 1940 *p++ = cpu_to_be32(IOMODE_ANY);
2027 *p = cpu_to_be32(RETURN_FILE); 1941 *p = cpu_to_be32(RETURN_FILE);
2028 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE); 1942 p = reserve_space(xdr, 16);
2029 p = xdr_encode_hyper(p, 0); 1943 p = xdr_encode_hyper(p, 0);
2030 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1944 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2031 spin_lock(&args->inode->i_lock); 1945 spin_lock(&args->inode->i_lock);
2032 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); 1946 encode_nfs4_stateid(xdr, &args->stateid);
2033 spin_unlock(&args->inode->i_lock); 1947 spin_unlock(&args->inode->i_lock);
2034 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 1948 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2035 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 1949 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2036 NFS_I(args->inode)->layout, xdr, args); 1950 NFS_I(args->inode)->layout, xdr, args);
2037 } else { 1951 } else
2038 p = reserve_space(xdr, 4); 1952 encode_uint32(xdr, 0);
2039 *p = cpu_to_be32(0);
2040 }
2041 hdr->nops++;
2042 hdr->replen += decode_layoutreturn_maxsz;
2043} 1953}
2044 1954
2045static int 1955static int
@@ -2047,12 +1957,8 @@ encode_secinfo_no_name(struct xdr_stream *xdr,
2047 const struct nfs41_secinfo_no_name_args *args, 1957 const struct nfs41_secinfo_no_name_args *args,
2048 struct compound_hdr *hdr) 1958 struct compound_hdr *hdr)
2049{ 1959{
2050 __be32 *p; 1960 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2051 p = reserve_space(xdr, 8); 1961 encode_uint32(xdr, args->style);
2052 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2053 *p++ = cpu_to_be32(args->style);
2054 hdr->nops++;
2055 hdr->replen += decode_secinfo_no_name_maxsz;
2056 return 0; 1962 return 0;
2057} 1963}
2058 1964
@@ -2060,26 +1966,17 @@ static void encode_test_stateid(struct xdr_stream *xdr,
2060 struct nfs41_test_stateid_args *args, 1966 struct nfs41_test_stateid_args *args,
2061 struct compound_hdr *hdr) 1967 struct compound_hdr *hdr)
2062{ 1968{
2063 __be32 *p; 1969 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2064 1970 encode_uint32(xdr, 1);
2065 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE); 1971 encode_nfs4_stateid(xdr, args->stateid);
2066 *p++ = cpu_to_be32(OP_TEST_STATEID);
2067 *p++ = cpu_to_be32(1);
2068 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2069 hdr->nops++;
2070 hdr->replen += decode_test_stateid_maxsz;
2071} 1972}
2072 1973
2073static void encode_free_stateid(struct xdr_stream *xdr, 1974static void encode_free_stateid(struct xdr_stream *xdr,
2074 struct nfs41_free_stateid_args *args, 1975 struct nfs41_free_stateid_args *args,
2075 struct compound_hdr *hdr) 1976 struct compound_hdr *hdr)
2076{ 1977{
2077 __be32 *p; 1978 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2078 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE); 1979 encode_nfs4_stateid(xdr, args->stateid);
2079 *p++ = cpu_to_be32(OP_FREE_STATEID);
2080 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2081 hdr->nops++;
2082 hdr->replen += decode_free_stateid_maxsz;
2083} 1980}
2084#endif /* CONFIG_NFS_V4_1 */ 1981#endif /* CONFIG_NFS_V4_1 */
2085 1982
@@ -2522,7 +2419,6 @@ static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2522 2419
2523 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2420 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2524 args->acl_pages, args->acl_pgbase, args->acl_len); 2421 args->acl_pages, args->acl_pgbase, args->acl_len);
2525 xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2526 2422
2527 encode_nops(&hdr); 2423 encode_nops(&hdr);
2528} 2424}
@@ -2634,6 +2530,7 @@ static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2634 encode_sequence(xdr, &args->seq_args, &hdr); 2530 encode_sequence(xdr, &args->seq_args, &hdr);
2635 encode_putfh(xdr, args->fhandle, &hdr); 2531 encode_putfh(xdr, args->fhandle, &hdr);
2636 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2532 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2533 FATTR4_WORD0_FH_EXPIRE_TYPE|
2637 FATTR4_WORD0_LINK_SUPPORT| 2534 FATTR4_WORD0_LINK_SUPPORT|
2638 FATTR4_WORD0_SYMLINK_SUPPORT| 2535 FATTR4_WORD0_SYMLINK_SUPPORT|
2639 FATTR4_WORD0_ACLSUPPORT, &hdr); 2536 FATTR4_WORD0_ACLSUPPORT, &hdr);
@@ -2651,7 +2548,7 @@ static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2651 }; 2548 };
2652 2549
2653 encode_compound_hdr(xdr, req, &hdr); 2550 encode_compound_hdr(xdr, req, &hdr);
2654 encode_renew(xdr, clp, &hdr); 2551 encode_renew(xdr, clp->cl_clientid, &hdr);
2655 encode_nops(&hdr); 2552 encode_nops(&hdr);
2656} 2553}
2657 2554
@@ -3181,6 +3078,28 @@ out_overflow:
3181 return -EIO; 3078 return -EIO;
3182} 3079}
3183 3080
3081static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3082 uint32_t *bitmap, uint32_t *type)
3083{
3084 __be32 *p;
3085
3086 *type = 0;
3087 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3088 return -EIO;
3089 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3090 p = xdr_inline_decode(xdr, 4);
3091 if (unlikely(!p))
3092 goto out_overflow;
3093 *type = be32_to_cpup(p);
3094 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3095 }
3096 dprintk("%s: expire type=0x%x\n", __func__, *type);
3097 return 0;
3098out_overflow:
3099 print_overflow_msg(__func__, xdr);
3100 return -EIO;
3101}
3102
3184static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 3103static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3185{ 3104{
3186 __be32 *p; 3105 __be32 *p;
@@ -3514,16 +3433,17 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3514 n = be32_to_cpup(p); 3433 n = be32_to_cpup(p);
3515 if (n == 0) 3434 if (n == 0)
3516 goto root_path; 3435 goto root_path;
3517 dprintk("path "); 3436 dprintk("pathname4: ");
3518 path->ncomponents = 0; 3437 path->ncomponents = 0;
3519 while (path->ncomponents < n) { 3438 while (path->ncomponents < n) {
3520 struct nfs4_string *component = &path->components[path->ncomponents]; 3439 struct nfs4_string *component = &path->components[path->ncomponents];
3521 status = decode_opaque_inline(xdr, &component->len, &component->data); 3440 status = decode_opaque_inline(xdr, &component->len, &component->data);
3522 if (unlikely(status != 0)) 3441 if (unlikely(status != 0))
3523 goto out_eio; 3442 goto out_eio;
3524 if (path->ncomponents != n) 3443 ifdebug (XDR)
3525 dprintk("/"); 3444 pr_cont("%s%.*s ",
3526 dprintk("%s", component->data); 3445 (path->ncomponents != n ? "/ " : ""),
3446 component->len, component->data);
3527 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 3447 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3528 path->ncomponents++; 3448 path->ncomponents++;
3529 else { 3449 else {
@@ -3532,14 +3452,13 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3532 } 3452 }
3533 } 3453 }
3534out: 3454out:
3535 dprintk("\n");
3536 return status; 3455 return status;
3537root_path: 3456root_path:
3538/* a root pathname is sent as a zero component4 */ 3457/* a root pathname is sent as a zero component4 */
3539 path->ncomponents = 1; 3458 path->ncomponents = 1;
3540 path->components[0].len=0; 3459 path->components[0].len=0;
3541 path->components[0].data=NULL; 3460 path->components[0].data=NULL;
3542 dprintk("path /\n"); 3461 dprintk("pathname4: /\n");
3543 goto out; 3462 goto out;
3544out_eio: 3463out_eio:
3545 dprintk(" status %d", status); 3464 dprintk(" status %d", status);
@@ -3561,7 +3480,11 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
3561 status = 0; 3480 status = 0;
3562 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3481 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3563 goto out; 3482 goto out;
3564 dprintk("%s: fsroot ", __func__); 3483 status = -EIO;
3484 /* Ignore borken servers that return unrequested attrs */
3485 if (unlikely(res == NULL))
3486 goto out;
3487 dprintk("%s: fsroot:\n", __func__);
3565 status = decode_pathname(xdr, &res->fs_path); 3488 status = decode_pathname(xdr, &res->fs_path);
3566 if (unlikely(status != 0)) 3489 if (unlikely(status != 0))
3567 goto out; 3490 goto out;
@@ -3582,7 +3505,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
3582 m = be32_to_cpup(p); 3505 m = be32_to_cpup(p);
3583 3506
3584 loc->nservers = 0; 3507 loc->nservers = 0;
3585 dprintk("%s: servers ", __func__); 3508 dprintk("%s: servers:\n", __func__);
3586 while (loc->nservers < m) { 3509 while (loc->nservers < m) {
3587 struct nfs4_string *server = &loc->servers[loc->nservers]; 3510 struct nfs4_string *server = &loc->servers[loc->nservers];
3588 status = decode_opaque_inline(xdr, &server->len, &server->data); 3511 status = decode_opaque_inline(xdr, &server->len, &server->data);
@@ -3614,7 +3537,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
3614 res->nlocations++; 3537 res->nlocations++;
3615 } 3538 }
3616 if (res->nlocations != 0) 3539 if (res->nlocations != 0)
3617 status = NFS_ATTR_FATTR_V4_REFERRAL; 3540 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3618out: 3541out:
3619 dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3542 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3620 return status; 3543 return status;
@@ -4158,7 +4081,7 @@ static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4158 4081
4159static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 4082static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4160{ 4083{
4161 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE); 4084 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4162} 4085}
4163 4086
4164static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 4087static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
@@ -4175,7 +4098,7 @@ static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4175 4098
4176static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4099static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4177{ 4100{
4178 return decode_opaque_fixed(xdr, verifier, 8); 4101 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4179} 4102}
4180 4103
4181static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 4104static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
@@ -4225,6 +4148,9 @@ static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_re
4225 goto xdr_error; 4148 goto xdr_error;
4226 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 4149 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4227 goto xdr_error; 4150 goto xdr_error;
4151 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4152 &res->fh_expire_type)) != 0)
4153 goto xdr_error;
4228 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 4154 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4229 goto xdr_error; 4155 goto xdr_error;
4230 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 4156 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
@@ -4295,6 +4221,7 @@ xdr_error:
4295 4221
4296static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4222static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4297 struct nfs_fattr *fattr, struct nfs_fh *fh, 4223 struct nfs_fattr *fattr, struct nfs_fh *fh,
4224 struct nfs4_fs_locations *fs_loc,
4298 const struct nfs_server *server) 4225 const struct nfs_server *server)
4299{ 4226{
4300 int status; 4227 int status;
@@ -4342,9 +4269,7 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4342 goto xdr_error; 4269 goto xdr_error;
4343 fattr->valid |= status; 4270 fattr->valid |= status;
4344 4271
4345 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, 4272 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4346 struct nfs4_fs_locations,
4347 fattr));
4348 if (status < 0) 4273 if (status < 0)
4349 goto xdr_error; 4274 goto xdr_error;
4350 fattr->valid |= status; 4275 fattr->valid |= status;
@@ -4408,7 +4333,8 @@ xdr_error:
4408} 4333}
4409 4334
4410static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4335static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4411 struct nfs_fh *fh, const struct nfs_server *server) 4336 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4337 const struct nfs_server *server)
4412{ 4338{
4413 __be32 *savep; 4339 __be32 *savep;
4414 uint32_t attrlen, 4340 uint32_t attrlen,
@@ -4427,7 +4353,7 @@ static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fat
4427 if (status < 0) 4353 if (status < 0)
4428 goto xdr_error; 4354 goto xdr_error;
4429 4355
4430 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server); 4356 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4431 if (status < 0) 4357 if (status < 0)
4432 goto xdr_error; 4358 goto xdr_error;
4433 4359
@@ -4440,7 +4366,7 @@ xdr_error:
4440static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4366static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4441 const struct nfs_server *server) 4367 const struct nfs_server *server)
4442{ 4368{
4443 return decode_getfattr_generic(xdr, fattr, NULL, server); 4369 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4444} 4370}
4445 4371
4446/* 4372/*
@@ -4464,8 +4390,8 @@ static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4464 return 0; 4390 return 0;
4465 } 4391 }
4466 if (num > 1) 4392 if (num > 1)
4467 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers " 4393 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4468 "per filesystem not supported\n", __func__); 4394 "drivers per filesystem not supported\n", __func__);
4469 4395
4470 /* Decode and set first layout type, move xdr->p past unused types */ 4396 /* Decode and set first layout type, move xdr->p past unused types */
4471 p = xdr_inline_decode(xdr, num * 4); 4397 p = xdr_inline_decode(xdr, num * 4);
@@ -4864,17 +4790,16 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
4864 size_t hdrlen; 4790 size_t hdrlen;
4865 u32 recvd, pglen = rcvbuf->page_len; 4791 u32 recvd, pglen = rcvbuf->page_len;
4866 int status; 4792 int status;
4793 __be32 verf[2];
4867 4794
4868 status = decode_op_hdr(xdr, OP_READDIR); 4795 status = decode_op_hdr(xdr, OP_READDIR);
4869 if (!status) 4796 if (!status)
4870 status = decode_verifier(xdr, readdir->verifier.data); 4797 status = decode_verifier(xdr, readdir->verifier.data);
4871 if (unlikely(status)) 4798 if (unlikely(status))
4872 return status; 4799 return status;
4800 memcpy(verf, readdir->verifier.data, sizeof(verf));
4873 dprintk("%s: verifier = %08x:%08x\n", 4801 dprintk("%s: verifier = %08x:%08x\n",
4874 __func__, 4802 __func__, verf[0], verf[1]);
4875 ((u32 *)readdir->verifier.data)[0],
4876 ((u32 *)readdir->verifier.data)[1]);
4877
4878 4803
4879 hdrlen = (char *) xdr->p - (char *) iov->iov_base; 4804 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4880 recvd = rcvbuf->len - hdrlen; 4805 recvd = rcvbuf->len - hdrlen;
@@ -5121,7 +5046,7 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5121 goto out_overflow; 5046 goto out_overflow;
5122 res->count = be32_to_cpup(p++); 5047 res->count = be32_to_cpup(p++);
5123 res->verf->committed = be32_to_cpup(p++); 5048 res->verf->committed = be32_to_cpup(p++);
5124 memcpy(res->verf->verifier, p, 8); 5049 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
5125 return 0; 5050 return 0;
5126out_overflow: 5051out_overflow:
5127 print_overflow_msg(__func__, xdr); 5052 print_overflow_msg(__func__, xdr);
@@ -5215,6 +5140,7 @@ static int decode_exchange_id(struct xdr_stream *xdr,
5215 char *dummy_str; 5140 char *dummy_str;
5216 int status; 5141 int status;
5217 struct nfs_client *clp = res->client; 5142 struct nfs_client *clp = res->client;
5143 uint32_t impl_id_count;
5218 5144
5219 status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 5145 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5220 if (status) 5146 if (status)
@@ -5256,11 +5182,38 @@ static int decode_exchange_id(struct xdr_stream *xdr,
5256 memcpy(res->server_scope->server_scope, dummy_str, dummy); 5182 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5257 res->server_scope->server_scope_sz = dummy; 5183 res->server_scope->server_scope_sz = dummy;
5258 5184
5259 /* Throw away Implementation id array */ 5185 /* Implementation Id */
5260 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5186 p = xdr_inline_decode(xdr, 4);
5261 if (unlikely(status)) 5187 if (unlikely(!p))
5262 return status; 5188 goto out_overflow;
5189 impl_id_count = be32_to_cpup(p++);
5190
5191 if (impl_id_count) {
5192 /* nii_domain */
5193 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5194 if (unlikely(status))
5195 return status;
5196 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5197 return -EIO;
5198 memcpy(res->impl_id->domain, dummy_str, dummy);
5199
5200 /* nii_name */
5201 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5202 if (unlikely(status))
5203 return status;
5204 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5205 return -EIO;
5206 memcpy(res->impl_id->name, dummy_str, dummy);
5263 5207
5208 /* nii_date */
5209 p = xdr_inline_decode(xdr, 12);
5210 if (unlikely(!p))
5211 goto out_overflow;
5212 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5213 res->impl_id->date.nseconds = be32_to_cpup(p);
5214
5215 /* if there's more than one entry, ignore the rest */
5216 }
5264 return 0; 5217 return 0;
5265out_overflow: 5218out_overflow:
5266 print_overflow_msg(__func__, xdr); 5219 print_overflow_msg(__func__, xdr);
@@ -5286,8 +5239,8 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
5286 attrs->max_reqs = be32_to_cpup(p++); 5239 attrs->max_reqs = be32_to_cpup(p++);
5287 nr_attrs = be32_to_cpup(p); 5240 nr_attrs = be32_to_cpup(p);
5288 if (unlikely(nr_attrs > 1)) { 5241 if (unlikely(nr_attrs > 1)) {
5289 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", 5242 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5290 __func__, nr_attrs); 5243 "count %u\n", __func__, nr_attrs);
5291 return -EINVAL; 5244 return -EINVAL;
5292 } 5245 }
5293 if (nr_attrs == 1) { 5246 if (nr_attrs == 1) {
@@ -5437,14 +5390,14 @@ static int decode_getdevicelist(struct xdr_stream *xdr,
5437 p += 2; 5390 p += 2;
5438 5391
5439 /* Read verifier */ 5392 /* Read verifier */
5440 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8); 5393 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
5441 5394
5442 res->num_devs = be32_to_cpup(p); 5395 res->num_devs = be32_to_cpup(p);
5443 5396
5444 dprintk("%s: num_dev %d\n", __func__, res->num_devs); 5397 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5445 5398
5446 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5399 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5447 printk(KERN_ERR "%s too many result dev_num %u\n", 5400 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
5448 __func__, res->num_devs); 5401 __func__, res->num_devs);
5449 return -EIO; 5402 return -EIO;
5450 } 5403 }
@@ -5538,11 +5491,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5538 status = decode_op_hdr(xdr, OP_LAYOUTGET); 5491 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5539 if (status) 5492 if (status)
5540 return status; 5493 return status;
5541 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE); 5494 p = xdr_inline_decode(xdr, 4);
5495 if (unlikely(!p))
5496 goto out_overflow;
5497 res->return_on_close = be32_to_cpup(p);
5498 decode_stateid(xdr, &res->stateid);
5499 p = xdr_inline_decode(xdr, 4);
5542 if (unlikely(!p)) 5500 if (unlikely(!p))
5543 goto out_overflow; 5501 goto out_overflow;
5544 res->return_on_close = be32_to_cpup(p++);
5545 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5546 layout_count = be32_to_cpup(p); 5502 layout_count = be32_to_cpup(p);
5547 if (!layout_count) { 5503 if (!layout_count) {
5548 dprintk("%s: server responded with empty layout array\n", 5504 dprintk("%s: server responded with empty layout array\n",
@@ -5667,7 +5623,8 @@ static int decode_test_stateid(struct xdr_stream *xdr,
5667 if (unlikely(!p)) 5623 if (unlikely(!p))
5668 goto out_overflow; 5624 goto out_overflow;
5669 res->status = be32_to_cpup(p++); 5625 res->status = be32_to_cpup(p++);
5670 return res->status; 5626
5627 return status;
5671out_overflow: 5628out_overflow:
5672 print_overflow_msg(__func__, xdr); 5629 print_overflow_msg(__func__, xdr);
5673out: 5630out:
@@ -6032,6 +5989,10 @@ nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6032 struct compound_hdr hdr; 5989 struct compound_hdr hdr;
6033 int status; 5990 int status;
6034 5991
5992 if (res->acl_scratch != NULL) {
5993 void *p = page_address(res->acl_scratch);
5994 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5995 }
6035 status = decode_compound_hdr(xdr, &hdr); 5996 status = decode_compound_hdr(xdr, &hdr);
6036 if (status) 5997 if (status)
6037 goto out; 5998 goto out;
@@ -6580,8 +6541,9 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6580 if (status) 6541 if (status)
6581 goto out; 6542 goto out;
6582 xdr_enter_page(xdr, PAGE_SIZE); 6543 xdr_enter_page(xdr, PAGE_SIZE);
6583 status = decode_getfattr(xdr, &res->fs_locations->fattr, 6544 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6584 res->fs_locations->server); 6545 NULL, res->fs_locations,
6546 res->fs_locations->server);
6585out: 6547out:
6586 return status; 6548 return status;
6587} 6549}
@@ -6961,7 +6923,7 @@ int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6961 goto out_overflow; 6923 goto out_overflow;
6962 6924
6963 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 6925 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6964 entry->server) < 0) 6926 NULL, entry->server) < 0)
6965 goto out_overflow; 6927 goto out_overflow;
6966 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 6928 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6967 entry->ino = entry->fattr->mounted_on_fileid; 6929 entry->ino = entry->fattr->mounted_on_fileid;
@@ -7109,7 +7071,7 @@ struct rpc_procinfo nfs4_procedures[] = {
7109#endif /* CONFIG_NFS_V4_1 */ 7071#endif /* CONFIG_NFS_V4_1 */
7110}; 7072};
7111 7073
7112struct rpc_version nfs_version4 = { 7074const struct rpc_version nfs_version4 = {
7113 .number = 4, 7075 .number = 4,
7114 .nrprocs = ARRAY_SIZE(nfs4_procedures), 7076 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7115 .procs = nfs4_procedures 7077 .procs = nfs4_procedures
diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
index c4744e1d513c..cd3c910d2d12 100644
--- a/fs/nfs/nfsroot.c
+++ b/fs/nfs/nfsroot.c
@@ -104,7 +104,7 @@ static char nfs_export_path[NFS_MAXPATHLEN + 1] __initdata = "";
104/* server:export path string passed to super.c */ 104/* server:export path string passed to super.c */
105static char nfs_root_device[NFS_MAXPATHLEN + 1] __initdata = ""; 105static char nfs_root_device[NFS_MAXPATHLEN + 1] __initdata = "";
106 106
107#ifdef RPC_DEBUG 107#ifdef NFS_DEBUG
108/* 108/*
109 * When the "nfsrootdebug" kernel command line option is specified, 109 * When the "nfsrootdebug" kernel command line option is specified,
110 * enable debugging messages for NFSROOT. 110 * enable debugging messages for NFSROOT.
diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c
index 55d01280a609..4bff4a3dab46 100644
--- a/fs/nfs/objlayout/objio_osd.c
+++ b/fs/nfs/objlayout/objio_osd.c
@@ -137,6 +137,7 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
137 struct objio_dev_ent *ode; 137 struct objio_dev_ent *ode;
138 struct osd_dev *od; 138 struct osd_dev *od;
139 struct osd_dev_info odi; 139 struct osd_dev_info odi;
140 bool retry_flag = true;
140 int err; 141 int err;
141 142
142 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id); 143 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
@@ -171,10 +172,18 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
171 goto out; 172 goto out;
172 } 173 }
173 174
175retry_lookup:
174 od = osduld_info_lookup(&odi); 176 od = osduld_info_lookup(&odi);
175 if (unlikely(IS_ERR(od))) { 177 if (unlikely(IS_ERR(od))) {
176 err = PTR_ERR(od); 178 err = PTR_ERR(od);
177 dprintk("%s: osduld_info_lookup => %d\n", __func__, err); 179 dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
180 if (err == -ENODEV && retry_flag) {
181 err = objlayout_autologin(deviceaddr);
182 if (likely(!err)) {
183 retry_flag = false;
184 goto retry_lookup;
185 }
186 }
178 goto out; 187 goto out;
179 } 188 }
180 189
@@ -205,25 +214,36 @@ static void copy_single_comp(struct ore_components *oc, unsigned c,
205int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags, 214int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags,
206 struct objio_segment **pseg) 215 struct objio_segment **pseg)
207{ 216{
208 struct __alloc_objio_segment { 217/* This is the in memory structure of the objio_segment
209 struct objio_segment olseg; 218 *
210 struct ore_dev *ods[numdevs]; 219 * struct __alloc_objio_segment {
211 struct ore_comp comps[numdevs]; 220 * struct objio_segment olseg;
212 } *aolseg; 221 * struct ore_dev *ods[numdevs];
213 222 * struct ore_comp comps[numdevs];
214 aolseg = kzalloc(sizeof(*aolseg), gfp_flags); 223 * } *aolseg;
215 if (unlikely(!aolseg)) { 224 * NOTE: The code as above compiles and runs perfectly. It is elegant,
225 * type safe and compact. At some Past time Linus has decided he does not
226 * like variable length arrays, For the sake of this principal we uglify
227 * the code as below.
228 */
229 struct objio_segment *lseg;
230 size_t lseg_size = sizeof(*lseg) +
231 numdevs * sizeof(lseg->oc.ods[0]) +
232 numdevs * sizeof(*lseg->oc.comps);
233
234 lseg = kzalloc(lseg_size, gfp_flags);
235 if (unlikely(!lseg)) {
216 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__, 236 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__,
217 numdevs, sizeof(*aolseg)); 237 numdevs, lseg_size);
218 return -ENOMEM; 238 return -ENOMEM;
219 } 239 }
220 240
221 aolseg->olseg.oc.numdevs = numdevs; 241 lseg->oc.numdevs = numdevs;
222 aolseg->olseg.oc.single_comp = EC_MULTPLE_COMPS; 242 lseg->oc.single_comp = EC_MULTPLE_COMPS;
223 aolseg->olseg.oc.comps = aolseg->comps; 243 lseg->oc.ods = (void *)(lseg + 1);
224 aolseg->olseg.oc.ods = aolseg->ods; 244 lseg->oc.comps = (void *)(lseg->oc.ods + numdevs);
225 245
226 *pseg = &aolseg->olseg; 246 *pseg = lseg;
227 return 0; 247 return 0;
228} 248}
229 249
@@ -582,10 +602,10 @@ objlayout_init(void)
582 602
583 if (ret) 603 if (ret)
584 printk(KERN_INFO 604 printk(KERN_INFO
585 "%s: Registering OSD pNFS Layout Driver failed: error=%d\n", 605 "NFS: %s: Registering OSD pNFS Layout Driver failed: error=%d\n",
586 __func__, ret); 606 __func__, ret);
587 else 607 else
588 printk(KERN_INFO "%s: Registered OSD pNFS Layout Driver\n", 608 printk(KERN_INFO "NFS: %s: Registered OSD pNFS Layout Driver\n",
589 __func__); 609 __func__);
590 return ret; 610 return ret;
591} 611}
@@ -594,7 +614,7 @@ static void __exit
594objlayout_exit(void) 614objlayout_exit(void)
595{ 615{
596 pnfs_unregister_layoutdriver(&objlayout_type); 616 pnfs_unregister_layoutdriver(&objlayout_type);
597 printk(KERN_INFO "%s: Unregistered OSD pNFS Layout Driver\n", 617 printk(KERN_INFO "NFS: %s: Unregistered OSD pNFS Layout Driver\n",
598 __func__); 618 __func__);
599} 619}
600 620
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index b3c29039f5b8..8d45f1c318ce 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -37,6 +37,9 @@
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */ 38 */
39 39
40#include <linux/kmod.h>
41#include <linux/moduleparam.h>
42#include <linux/ratelimit.h>
40#include <scsi/osd_initiator.h> 43#include <scsi/osd_initiator.h>
41#include "objlayout.h" 44#include "objlayout.h"
42 45
@@ -156,7 +159,7 @@ last_byte_offset(u64 start, u64 len)
156 return end > start ? end - 1 : NFS4_MAX_UINT64; 159 return end > start ? end - 1 : NFS4_MAX_UINT64;
157} 160}
158 161
159void _fix_verify_io_params(struct pnfs_layout_segment *lseg, 162static void _fix_verify_io_params(struct pnfs_layout_segment *lseg,
160 struct page ***p_pages, unsigned *p_pgbase, 163 struct page ***p_pages, unsigned *p_pgbase,
161 u64 offset, unsigned long count) 164 u64 offset, unsigned long count)
162{ 165{
@@ -490,9 +493,9 @@ encode_accumulated_error(struct objlayout *objlay, __be32 *p)
490 if (!ioerr->oer_errno) 493 if (!ioerr->oer_errno)
491 continue; 494 continue;
492 495
493 printk(KERN_ERR "%s: err[%d]: errno=%d is_write=%d " 496 printk(KERN_ERR "NFS: %s: err[%d]: errno=%d "
494 "dev(%llx:%llx) par=0x%llx obj=0x%llx " 497 "is_write=%d dev(%llx:%llx) par=0x%llx "
495 "offset=0x%llx length=0x%llx\n", 498 "obj=0x%llx offset=0x%llx length=0x%llx\n",
496 __func__, i, ioerr->oer_errno, 499 __func__, i, ioerr->oer_errno,
497 ioerr->oer_iswrite, 500 ioerr->oer_iswrite,
498 _DEVID_LO(&ioerr->oer_component.oid_device_id), 501 _DEVID_LO(&ioerr->oer_component.oid_device_id),
@@ -651,3 +654,134 @@ void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
651 __free_page(odi->page); 654 __free_page(odi->page);
652 kfree(odi); 655 kfree(odi);
653} 656}
657
658enum {
659 OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
660 OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
661 OSD_LOGIN_UPCALL_PATHLEN = 256
662};
663
664static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login";
665
666module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog),
667 0600);
668MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program");
669
670struct __auto_login {
671 char uri[OBJLAYOUT_MAX_URI_LEN];
672 char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
673 char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN];
674};
675
676static int __objlayout_upcall(struct __auto_login *login)
677{
678 static char *envp[] = { "HOME=/",
679 "TERM=linux",
680 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
681 NULL
682 };
683 char *argv[8];
684 int ret;
685
686 if (unlikely(!osd_login_prog[0])) {
687 dprintk("%s: osd_login_prog is disabled\n", __func__);
688 return -EACCES;
689 }
690
691 dprintk("%s uri: %s\n", __func__, login->uri);
692 dprintk("%s osdname %s\n", __func__, login->osdname);
693 dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
694
695 argv[0] = (char *)osd_login_prog;
696 argv[1] = "-u";
697 argv[2] = login->uri;
698 argv[3] = "-o";
699 argv[4] = login->osdname;
700 argv[5] = "-s";
701 argv[6] = login->systemid_hex;
702 argv[7] = NULL;
703
704 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
705 /*
706 * Disable the upcall mechanism if we're getting an ENOENT or
707 * EACCES error. The admin can re-enable it on the fly by using
708 * sysfs to set the objlayoutdriver.osd_login_prog module parameter once
709 * the problem has been fixed.
710 */
711 if (ret == -ENOENT || ret == -EACCES) {
712 printk(KERN_ERR "PNFS-OBJ: %s was not found please set "
713 "objlayoutdriver.osd_login_prog kernel parameter!\n",
714 osd_login_prog);
715 osd_login_prog[0] = '\0';
716 }
717 dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
718
719 return ret;
720}
721
722/* Assume dest is all zeros */
723static void __copy_nfsS_and_zero_terminate(struct nfs4_string s,
724 char *dest, int max_len,
725 const char *var_name)
726{
727 if (!s.len)
728 return;
729
730 if (s.len >= max_len) {
731 pr_warn_ratelimited(
732 "objlayout_autologin: %s: s.len(%d) >= max_len(%d)",
733 var_name, s.len, max_len);
734 s.len = max_len - 1; /* space for null terminator */
735 }
736
737 memcpy(dest, s.data, s.len);
738}
739
740/* Assume sysid is all zeros */
741static void _sysid_2_hex(struct nfs4_string s,
742 char sysid[OBJLAYOUT_MAX_SYSID_HEX_LEN])
743{
744 int i;
745 char *cur;
746
747 if (!s.len)
748 return;
749
750 if (s.len != OSD_SYSTEMID_LEN) {
751 pr_warn_ratelimited(
752 "objlayout_autologin: systemid_len(%d) != OSD_SYSTEMID_LEN",
753 s.len);
754 if (s.len > OSD_SYSTEMID_LEN)
755 s.len = OSD_SYSTEMID_LEN;
756 }
757
758 cur = sysid;
759 for (i = 0; i < s.len; i++)
760 cur = hex_byte_pack(cur, s.data[i]);
761}
762
763int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr)
764{
765 int rc;
766 struct __auto_login login;
767
768 if (!deviceaddr->oda_targetaddr.ota_netaddr.r_addr.len)
769 return -ENODEV;
770
771 memset(&login, 0, sizeof(login));
772 __copy_nfsS_and_zero_terminate(
773 deviceaddr->oda_targetaddr.ota_netaddr.r_addr,
774 login.uri, sizeof(login.uri), "URI");
775
776 __copy_nfsS_and_zero_terminate(
777 deviceaddr->oda_osdname,
778 login.osdname, sizeof(login.osdname), "OSDNAME");
779
780 _sysid_2_hex(deviceaddr->oda_systemid, login.systemid_hex);
781
782 rc = __objlayout_upcall(&login);
783 if (rc > 0) /* script returns positive values */
784 rc = -ENODEV;
785
786 return rc;
787}
diff --git a/fs/nfs/objlayout/objlayout.h b/fs/nfs/objlayout/objlayout.h
index 8ec34727ed21..880ba086be94 100644
--- a/fs/nfs/objlayout/objlayout.h
+++ b/fs/nfs/objlayout/objlayout.h
@@ -184,4 +184,6 @@ extern void objlayout_encode_layoutreturn(
184 struct xdr_stream *, 184 struct xdr_stream *,
185 const struct nfs4_layoutreturn_args *); 185 const struct nfs4_layoutreturn_args *);
186 186
187extern int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr);
188
187#endif /* _OBJLAYOUT_H */ 189#endif /* _OBJLAYOUT_H */
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 5668f7c54c41..d21fceaa9f62 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -13,6 +13,7 @@
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/sunrpc/clnt.h> 15#include <linux/sunrpc/clnt.h>
16#include <linux/nfs.h>
16#include <linux/nfs3.h> 17#include <linux/nfs3.h>
17#include <linux/nfs4.h> 18#include <linux/nfs4.h>
18#include <linux/nfs_page.h> 19#include <linux/nfs_page.h>
@@ -106,36 +107,6 @@ void nfs_unlock_request(struct nfs_page *req)
106 nfs_release_request(req); 107 nfs_release_request(req);
107} 108}
108 109
109/**
110 * nfs_set_page_tag_locked - Tag a request as locked
111 * @req:
112 */
113int nfs_set_page_tag_locked(struct nfs_page *req)
114{
115 if (!nfs_lock_request_dontget(req))
116 return 0;
117 if (test_bit(PG_MAPPED, &req->wb_flags))
118 radix_tree_tag_set(&NFS_I(req->wb_context->dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
119 return 1;
120}
121
122/**
123 * nfs_clear_page_tag_locked - Clear request tag and wake up sleepers
124 */
125void nfs_clear_page_tag_locked(struct nfs_page *req)
126{
127 if (test_bit(PG_MAPPED, &req->wb_flags)) {
128 struct inode *inode = req->wb_context->dentry->d_inode;
129 struct nfs_inode *nfsi = NFS_I(inode);
130
131 spin_lock(&inode->i_lock);
132 radix_tree_tag_clear(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
133 nfs_unlock_request(req);
134 spin_unlock(&inode->i_lock);
135 } else
136 nfs_unlock_request(req);
137}
138
139/* 110/*
140 * nfs_clear_request - Free up all resources allocated to the request 111 * nfs_clear_request - Free up all resources allocated to the request
141 * @req: 112 * @req:
@@ -425,67 +396,6 @@ void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index)
425 } 396 }
426} 397}
427 398
428#define NFS_SCAN_MAXENTRIES 16
429/**
430 * nfs_scan_list - Scan a list for matching requests
431 * @nfsi: NFS inode
432 * @dst: Destination list
433 * @idx_start: lower bound of page->index to scan
434 * @npages: idx_start + npages sets the upper bound to scan.
435 * @tag: tag to scan for
436 *
437 * Moves elements from one of the inode request lists.
438 * If the number of requests is set to 0, the entire address_space
439 * starting at index idx_start, is scanned.
440 * The requests are *not* checked to ensure that they form a contiguous set.
441 * You must be holding the inode's i_lock when calling this function
442 */
443int nfs_scan_list(struct nfs_inode *nfsi,
444 struct list_head *dst, pgoff_t idx_start,
445 unsigned int npages, int tag)
446{
447 struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES];
448 struct nfs_page *req;
449 pgoff_t idx_end;
450 int found, i;
451 int res;
452 struct list_head *list;
453
454 res = 0;
455 if (npages == 0)
456 idx_end = ~0;
457 else
458 idx_end = idx_start + npages - 1;
459
460 for (;;) {
461 found = radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree,
462 (void **)&pgvec[0], idx_start,
463 NFS_SCAN_MAXENTRIES, tag);
464 if (found <= 0)
465 break;
466 for (i = 0; i < found; i++) {
467 req = pgvec[i];
468 if (req->wb_index > idx_end)
469 goto out;
470 idx_start = req->wb_index + 1;
471 if (nfs_set_page_tag_locked(req)) {
472 kref_get(&req->wb_kref);
473 radix_tree_tag_clear(&nfsi->nfs_page_tree,
474 req->wb_index, tag);
475 list = pnfs_choose_commit_list(req, dst);
476 nfs_list_add_request(req, list);
477 res++;
478 if (res == INT_MAX)
479 goto out;
480 }
481 }
482 /* for latency reduction */
483 cond_resched_lock(&nfsi->vfs_inode.i_lock);
484 }
485out:
486 return res;
487}
488
489int __init nfs_init_nfspagecache(void) 399int __init nfs_init_nfspagecache(void)
490{ 400{
491 nfs_page_cachep = kmem_cache_create("nfs_page", 401 nfs_page_cachep = kmem_cache_create("nfs_page",
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 17149a490065..b5d451586943 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -101,8 +101,8 @@ set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh,
101 goto out_no_driver; 101 goto out_no_driver;
102 if (!(server->nfs_client->cl_exchange_flags & 102 if (!(server->nfs_client->cl_exchange_flags &
103 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) { 103 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
104 printk(KERN_ERR "%s: id %u cl_exchange_flags 0x%x\n", __func__, 104 printk(KERN_ERR "NFS: %s: id %u cl_exchange_flags 0x%x\n",
105 id, server->nfs_client->cl_exchange_flags); 105 __func__, id, server->nfs_client->cl_exchange_flags);
106 goto out_no_driver; 106 goto out_no_driver;
107 } 107 }
108 ld_type = find_pnfs_driver(id); 108 ld_type = find_pnfs_driver(id);
@@ -122,8 +122,8 @@ set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh,
122 server->pnfs_curr_ld = ld_type; 122 server->pnfs_curr_ld = ld_type;
123 if (ld_type->set_layoutdriver 123 if (ld_type->set_layoutdriver
124 && ld_type->set_layoutdriver(server, mntfh)) { 124 && ld_type->set_layoutdriver(server, mntfh)) {
125 printk(KERN_ERR "%s: Error initializing pNFS layout driver %u.\n", 125 printk(KERN_ERR "NFS: %s: Error initializing pNFS layout "
126 __func__, id); 126 "driver %u.\n", __func__, id);
127 module_put(ld_type->owner); 127 module_put(ld_type->owner);
128 goto out_no_driver; 128 goto out_no_driver;
129 } 129 }
@@ -143,11 +143,11 @@ pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
143 struct pnfs_layoutdriver_type *tmp; 143 struct pnfs_layoutdriver_type *tmp;
144 144
145 if (ld_type->id == 0) { 145 if (ld_type->id == 0) {
146 printk(KERN_ERR "%s id 0 is reserved\n", __func__); 146 printk(KERN_ERR "NFS: %s id 0 is reserved\n", __func__);
147 return status; 147 return status;
148 } 148 }
149 if (!ld_type->alloc_lseg || !ld_type->free_lseg) { 149 if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
150 printk(KERN_ERR "%s Layout driver must provide " 150 printk(KERN_ERR "NFS: %s Layout driver must provide "
151 "alloc_lseg and free_lseg.\n", __func__); 151 "alloc_lseg and free_lseg.\n", __func__);
152 return status; 152 return status;
153 } 153 }
@@ -160,7 +160,7 @@ pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
160 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id, 160 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
161 ld_type->name); 161 ld_type->name);
162 } else { 162 } else {
163 printk(KERN_ERR "%s Module with id %d already loaded!\n", 163 printk(KERN_ERR "NFS: %s Module with id %d already loaded!\n",
164 __func__, ld_type->id); 164 __func__, ld_type->id);
165 } 165 }
166 spin_unlock(&pnfs_spinlock); 166 spin_unlock(&pnfs_spinlock);
@@ -496,12 +496,12 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
496{ 496{
497 u32 oldseq, newseq; 497 u32 oldseq, newseq;
498 498
499 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid); 499 oldseq = be32_to_cpu(lo->plh_stateid.seqid);
500 newseq = be32_to_cpu(new->stateid.seqid); 500 newseq = be32_to_cpu(new->seqid);
501 if ((int)(newseq - oldseq) > 0) { 501 if ((int)(newseq - oldseq) > 0) {
502 memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid)); 502 nfs4_stateid_copy(&lo->plh_stateid, new);
503 if (update_barrier) { 503 if (update_barrier) {
504 u32 new_barrier = be32_to_cpu(new->stateid.seqid); 504 u32 new_barrier = be32_to_cpu(new->seqid);
505 505
506 if ((int)(new_barrier - lo->plh_barrier)) 506 if ((int)(new_barrier - lo->plh_barrier))
507 lo->plh_barrier = new_barrier; 507 lo->plh_barrier = new_barrier;
@@ -525,7 +525,7 @@ pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
525 int lget) 525 int lget)
526{ 526{
527 if ((stateid) && 527 if ((stateid) &&
528 (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0) 528 (int)(lo->plh_barrier - be32_to_cpu(stateid->seqid)) >= 0)
529 return true; 529 return true;
530 return lo->plh_block_lgets || 530 return lo->plh_block_lgets ||
531 test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) || 531 test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
@@ -549,11 +549,10 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
549 549
550 do { 550 do {
551 seq = read_seqbegin(&open_state->seqlock); 551 seq = read_seqbegin(&open_state->seqlock);
552 memcpy(dst->data, open_state->stateid.data, 552 nfs4_stateid_copy(dst, &open_state->stateid);
553 sizeof(open_state->stateid.data));
554 } while (read_seqretry(&open_state->seqlock, seq)); 553 } while (read_seqretry(&open_state->seqlock, seq));
555 } else 554 } else
556 memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data)); 555 nfs4_stateid_copy(dst, &lo->plh_stateid);
557 spin_unlock(&lo->plh_inode->i_lock); 556 spin_unlock(&lo->plh_inode->i_lock);
558 dprintk("<-- %s\n", __func__); 557 dprintk("<-- %s\n", __func__);
559 return status; 558 return status;
@@ -590,7 +589,7 @@ send_layoutget(struct pnfs_layout_hdr *lo,
590 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; 589 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
591 max_pages = max_resp_sz >> PAGE_SHIFT; 590 max_pages = max_resp_sz >> PAGE_SHIFT;
592 591
593 pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags); 592 pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags);
594 if (!pages) 593 if (!pages)
595 goto out_err_free; 594 goto out_err_free;
596 595
@@ -760,7 +759,7 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
760 } 759 }
761 if (!found) { 760 if (!found) {
762 struct pnfs_layout_hdr *lo = nfsi->layout; 761 struct pnfs_layout_hdr *lo = nfsi->layout;
763 u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid); 762 u32 current_seqid = be32_to_cpu(lo->plh_stateid.seqid);
764 763
765 /* Since close does not return a layout stateid for use as 764 /* Since close does not return a layout stateid for use as
766 * a barrier, we choose the worst-case barrier. 765 * a barrier, we choose the worst-case barrier.
@@ -966,8 +965,7 @@ pnfs_update_layout(struct inode *ino,
966 } 965 }
967 966
968 /* Do we even need to bother with this? */ 967 /* Do we even need to bother with this? */
969 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || 968 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
970 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
971 dprintk("%s matches recall, use MDS\n", __func__); 969 dprintk("%s matches recall, use MDS\n", __func__);
972 goto out_unlock; 970 goto out_unlock;
973 } 971 }
@@ -1032,7 +1030,6 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)
1032 struct nfs4_layoutget_res *res = &lgp->res; 1030 struct nfs4_layoutget_res *res = &lgp->res;
1033 struct pnfs_layout_segment *lseg; 1031 struct pnfs_layout_segment *lseg;
1034 struct inode *ino = lo->plh_inode; 1032 struct inode *ino = lo->plh_inode;
1035 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
1036 int status = 0; 1033 int status = 0;
1037 1034
1038 /* Inject layout blob into I/O device driver */ 1035 /* Inject layout blob into I/O device driver */
@@ -1048,8 +1045,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)
1048 } 1045 }
1049 1046
1050 spin_lock(&ino->i_lock); 1047 spin_lock(&ino->i_lock);
1051 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || 1048 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1052 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1053 dprintk("%s forget reply due to recall\n", __func__); 1049 dprintk("%s forget reply due to recall\n", __func__);
1054 goto out_forget_reply; 1050 goto out_forget_reply;
1055 } 1051 }
@@ -1214,6 +1210,7 @@ void pnfs_ld_write_done(struct nfs_write_data *data)
1214 } 1210 }
1215 data->task.tk_status = pnfs_write_done_resend_to_mds(data->inode, &data->pages); 1211 data->task.tk_status = pnfs_write_done_resend_to_mds(data->inode, &data->pages);
1216 } 1212 }
1213 put_lseg(data->lseg);
1217 data->mds_ops->rpc_release(data); 1214 data->mds_ops->rpc_release(data);
1218} 1215}
1219EXPORT_SYMBOL_GPL(pnfs_ld_write_done); 1216EXPORT_SYMBOL_GPL(pnfs_ld_write_done);
@@ -1227,6 +1224,7 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc,
1227 nfs_list_add_request(data->req, &desc->pg_list); 1224 nfs_list_add_request(data->req, &desc->pg_list);
1228 nfs_pageio_reset_write_mds(desc); 1225 nfs_pageio_reset_write_mds(desc);
1229 desc->pg_recoalesce = 1; 1226 desc->pg_recoalesce = 1;
1227 put_lseg(data->lseg);
1230 nfs_writedata_release(data); 1228 nfs_writedata_release(data);
1231} 1229}
1232 1230
@@ -1327,6 +1325,7 @@ void pnfs_ld_read_done(struct nfs_read_data *data)
1327 data->mds_ops->rpc_call_done(&data->task, data); 1325 data->mds_ops->rpc_call_done(&data->task, data);
1328 } else 1326 } else
1329 pnfs_ld_handle_read_error(data); 1327 pnfs_ld_handle_read_error(data);
1328 put_lseg(data->lseg);
1330 data->mds_ops->rpc_release(data); 1329 data->mds_ops->rpc_release(data);
1331} 1330}
1332EXPORT_SYMBOL_GPL(pnfs_ld_read_done); 1331EXPORT_SYMBOL_GPL(pnfs_ld_read_done);
@@ -1530,8 +1529,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
1530 end_pos = nfsi->layout->plh_lwb; 1529 end_pos = nfsi->layout->plh_lwb;
1531 nfsi->layout->plh_lwb = 0; 1530 nfsi->layout->plh_lwb = 0;
1532 1531
1533 memcpy(&data->args.stateid.data, nfsi->layout->plh_stateid.data, 1532 nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
1534 sizeof(nfsi->layout->plh_stateid.data));
1535 spin_unlock(&inode->i_lock); 1533 spin_unlock(&inode->i_lock);
1536 1534
1537 data->args.inode = inode; 1535 data->args.inode = inode;
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index 53d593a0a4f2..442ebf68eeec 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -94,11 +94,10 @@ struct pnfs_layoutdriver_type {
94 const struct nfs_pageio_ops *pg_read_ops; 94 const struct nfs_pageio_ops *pg_read_ops;
95 const struct nfs_pageio_ops *pg_write_ops; 95 const struct nfs_pageio_ops *pg_write_ops;
96 96
97 /* Returns true if layoutdriver wants to divert this request to 97 void (*mark_request_commit) (struct nfs_page *req,
98 * driver's commit routine. 98 struct pnfs_layout_segment *lseg);
99 */ 99 void (*clear_request_commit) (struct nfs_page *req);
100 bool (*mark_pnfs_commit)(struct pnfs_layout_segment *lseg); 100 int (*scan_commit_lists) (struct inode *inode, int max, spinlock_t *lock);
101 struct list_head * (*choose_commit_list) (struct nfs_page *req);
102 int (*commit_pagelist)(struct inode *inode, struct list_head *mds_pages, int how); 101 int (*commit_pagelist)(struct inode *inode, struct list_head *mds_pages, int how);
103 102
104 /* 103 /*
@@ -229,7 +228,6 @@ struct nfs4_deviceid_node {
229 atomic_t ref; 228 atomic_t ref;
230}; 229};
231 230
232void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
233struct nfs4_deviceid_node *nfs4_find_get_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *); 231struct nfs4_deviceid_node *nfs4_find_get_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
234void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *); 232void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
235void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, 233void nfs4_init_deviceid_node(struct nfs4_deviceid_node *,
@@ -262,20 +260,6 @@ static inline int pnfs_enabled_sb(struct nfs_server *nfss)
262 return nfss->pnfs_curr_ld != NULL; 260 return nfss->pnfs_curr_ld != NULL;
263} 261}
264 262
265static inline void
266pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
267{
268 if (lseg) {
269 struct pnfs_layoutdriver_type *ld;
270
271 ld = NFS_SERVER(req->wb_page->mapping->host)->pnfs_curr_ld;
272 if (ld->mark_pnfs_commit && ld->mark_pnfs_commit(lseg)) {
273 set_bit(PG_PNFS_COMMIT, &req->wb_flags);
274 req->wb_commit_lseg = get_lseg(lseg);
275 }
276 }
277}
278
279static inline int 263static inline int
280pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how) 264pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how)
281{ 265{
@@ -284,27 +268,42 @@ pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how)
284 return NFS_SERVER(inode)->pnfs_curr_ld->commit_pagelist(inode, mds_pages, how); 268 return NFS_SERVER(inode)->pnfs_curr_ld->commit_pagelist(inode, mds_pages, how);
285} 269}
286 270
287static inline struct list_head * 271static inline bool
288pnfs_choose_commit_list(struct nfs_page *req, struct list_head *mds) 272pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
289{ 273{
290 struct list_head *rv; 274 struct inode *inode = req->wb_context->dentry->d_inode;
275 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
291 276
292 if (test_and_clear_bit(PG_PNFS_COMMIT, &req->wb_flags)) { 277 if (lseg == NULL || ld->mark_request_commit == NULL)
293 struct inode *inode = req->wb_commit_lseg->pls_layout->plh_inode; 278 return false;
279 ld->mark_request_commit(req, lseg);
280 return true;
281}
294 282
295 set_bit(NFS_INO_PNFS_COMMIT, &NFS_I(inode)->flags); 283static inline bool
296 rv = NFS_SERVER(inode)->pnfs_curr_ld->choose_commit_list(req); 284pnfs_clear_request_commit(struct nfs_page *req)
297 /* matched by ref taken when PG_PNFS_COMMIT is set */ 285{
298 put_lseg(req->wb_commit_lseg); 286 struct inode *inode = req->wb_context->dentry->d_inode;
299 } else 287 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
300 rv = mds; 288
301 return rv; 289 if (ld == NULL || ld->clear_request_commit == NULL)
290 return false;
291 ld->clear_request_commit(req);
292 return true;
302} 293}
303 294
304static inline void pnfs_clear_request_commit(struct nfs_page *req) 295static inline int
296pnfs_scan_commit_lists(struct inode *inode, int max, spinlock_t *lock)
305{ 297{
306 if (test_and_clear_bit(PG_PNFS_COMMIT, &req->wb_flags)) 298 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
307 put_lseg(req->wb_commit_lseg); 299 int ret;
300
301 if (ld == NULL || ld->scan_commit_lists == NULL)
302 return 0;
303 ret = ld->scan_commit_lists(inode, max, lock);
304 if (ret != 0)
305 set_bit(NFS_INO_PNFS_COMMIT, &NFS_I(inode)->flags);
306 return ret;
308} 307}
309 308
310/* Should the pNFS client commit and return the layout upon a setattr */ 309/* Should the pNFS client commit and return the layout upon a setattr */
@@ -328,6 +327,13 @@ static inline int pnfs_return_layout(struct inode *ino)
328 return 0; 327 return 0;
329} 328}
330 329
330#ifdef NFS_DEBUG
331void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
332#else
333static inline void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id)
334{
335}
336#endif /* NFS_DEBUG */
331#else /* CONFIG_NFS_V4_1 */ 337#else /* CONFIG_NFS_V4_1 */
332 338
333static inline void pnfs_destroy_all_layouts(struct nfs_client *clp) 339static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
@@ -400,35 +406,35 @@ static inline bool pnfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, st
400 return false; 406 return false;
401} 407}
402 408
403static inline void
404pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
405{
406}
407
408static inline int 409static inline int
409pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how) 410pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how)
410{ 411{
411 return PNFS_NOT_ATTEMPTED; 412 return PNFS_NOT_ATTEMPTED;
412} 413}
413 414
414static inline struct list_head * 415static inline bool
415pnfs_choose_commit_list(struct nfs_page *req, struct list_head *mds) 416pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
416{ 417{
417 return mds; 418 return false;
418} 419}
419 420
420static inline void pnfs_clear_request_commit(struct nfs_page *req) 421static inline bool
422pnfs_clear_request_commit(struct nfs_page *req)
421{ 423{
424 return false;
422} 425}
423 426
424static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync) 427static inline int
428pnfs_scan_commit_lists(struct inode *inode, int max, spinlock_t *lock)
425{ 429{
426 return 0; 430 return 0;
427} 431}
428 432
429static inline void nfs4_deviceid_purge_client(struct nfs_client *ncl) 433static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync)
430{ 434{
435 return 0;
431} 436}
437
432#endif /* CONFIG_NFS_V4_1 */ 438#endif /* CONFIG_NFS_V4_1 */
433 439
434#endif /* FS_NFS_PNFS_H */ 440#endif /* FS_NFS_PNFS_H */
diff --git a/fs/nfs/pnfs_dev.c b/fs/nfs/pnfs_dev.c
index 4f359d2a26eb..73f701f1f4d3 100644
--- a/fs/nfs/pnfs_dev.c
+++ b/fs/nfs/pnfs_dev.c
@@ -43,6 +43,7 @@
43static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE]; 43static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE];
44static DEFINE_SPINLOCK(nfs4_deviceid_lock); 44static DEFINE_SPINLOCK(nfs4_deviceid_lock);
45 45
46#ifdef NFS_DEBUG
46void 47void
47nfs4_print_deviceid(const struct nfs4_deviceid *id) 48nfs4_print_deviceid(const struct nfs4_deviceid *id)
48{ 49{
@@ -52,6 +53,7 @@ nfs4_print_deviceid(const struct nfs4_deviceid *id)
52 p[0], p[1], p[2], p[3]); 53 p[0], p[1], p[2], p[3]);
53} 54}
54EXPORT_SYMBOL_GPL(nfs4_print_deviceid); 55EXPORT_SYMBOL_GPL(nfs4_print_deviceid);
56#endif
55 57
56static inline u32 58static inline u32
57nfs4_deviceid_hash(const struct nfs4_deviceid *id) 59nfs4_deviceid_hash(const struct nfs4_deviceid *id)
@@ -92,7 +94,7 @@ _lookup_deviceid(const struct pnfs_layoutdriver_type *ld,
92 * @clp nfs_client associated with deviceid 94 * @clp nfs_client associated with deviceid
93 * @id deviceid to look up 95 * @id deviceid to look up
94 */ 96 */
95struct nfs4_deviceid_node * 97static struct nfs4_deviceid_node *
96_find_get_deviceid(const struct pnfs_layoutdriver_type *ld, 98_find_get_deviceid(const struct pnfs_layoutdriver_type *ld,
97 const struct nfs_client *clp, const struct nfs4_deviceid *id, 99 const struct nfs_client *clp, const struct nfs4_deviceid *id,
98 long hash) 100 long hash)
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 0c672588fe5a..b63b6f4d14fb 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -358,6 +358,11 @@ nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
358 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE]; 358 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
359} 359}
360 360
361static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
362{
363 rpc_call_start(task);
364}
365
361static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) 366static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
362{ 367{
363 if (nfs_async_handle_expired_key(task)) 368 if (nfs_async_handle_expired_key(task))
@@ -372,6 +377,11 @@ nfs_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
372 msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME]; 377 msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
373} 378}
374 379
380static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
381{
382 rpc_call_start(task);
383}
384
375static int 385static int
376nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 386nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
377 struct inode *new_dir) 387 struct inode *new_dir)
@@ -651,6 +661,11 @@ static void nfs_proc_read_setup(struct nfs_read_data *data, struct rpc_message *
651 msg->rpc_proc = &nfs_procedures[NFSPROC_READ]; 661 msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
652} 662}
653 663
664static void nfs_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
665{
666 rpc_call_start(task);
667}
668
654static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data) 669static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
655{ 670{
656 if (nfs_async_handle_expired_key(task)) 671 if (nfs_async_handle_expired_key(task))
@@ -668,6 +683,11 @@ static void nfs_proc_write_setup(struct nfs_write_data *data, struct rpc_message
668 msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE]; 683 msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
669} 684}
670 685
686static void nfs_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
687{
688 rpc_call_start(task);
689}
690
671static void 691static void
672nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg) 692nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
673{ 693{
@@ -721,9 +741,11 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
721 .create = nfs_proc_create, 741 .create = nfs_proc_create,
722 .remove = nfs_proc_remove, 742 .remove = nfs_proc_remove,
723 .unlink_setup = nfs_proc_unlink_setup, 743 .unlink_setup = nfs_proc_unlink_setup,
744 .unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
724 .unlink_done = nfs_proc_unlink_done, 745 .unlink_done = nfs_proc_unlink_done,
725 .rename = nfs_proc_rename, 746 .rename = nfs_proc_rename,
726 .rename_setup = nfs_proc_rename_setup, 747 .rename_setup = nfs_proc_rename_setup,
748 .rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
727 .rename_done = nfs_proc_rename_done, 749 .rename_done = nfs_proc_rename_done,
728 .link = nfs_proc_link, 750 .link = nfs_proc_link,
729 .symlink = nfs_proc_symlink, 751 .symlink = nfs_proc_symlink,
@@ -736,8 +758,10 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
736 .pathconf = nfs_proc_pathconf, 758 .pathconf = nfs_proc_pathconf,
737 .decode_dirent = nfs2_decode_dirent, 759 .decode_dirent = nfs2_decode_dirent,
738 .read_setup = nfs_proc_read_setup, 760 .read_setup = nfs_proc_read_setup,
761 .read_rpc_prepare = nfs_proc_read_rpc_prepare,
739 .read_done = nfs_read_done, 762 .read_done = nfs_read_done,
740 .write_setup = nfs_proc_write_setup, 763 .write_setup = nfs_proc_write_setup,
764 .write_rpc_prepare = nfs_proc_write_rpc_prepare,
741 .write_done = nfs_write_done, 765 .write_done = nfs_write_done,
742 .commit_setup = nfs_proc_commit_setup, 766 .commit_setup = nfs_proc_commit_setup,
743 .lock = nfs_proc_lock, 767 .lock = nfs_proc_lock,
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index cfa175c223dc..cc1f758a7ee1 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -66,7 +66,6 @@ void nfs_readdata_free(struct nfs_read_data *p)
66 66
67void nfs_readdata_release(struct nfs_read_data *rdata) 67void nfs_readdata_release(struct nfs_read_data *rdata)
68{ 68{
69 put_lseg(rdata->lseg);
70 put_nfs_open_context(rdata->args.context); 69 put_nfs_open_context(rdata->args.context);
71 nfs_readdata_free(rdata); 70 nfs_readdata_free(rdata);
72} 71}
@@ -465,23 +464,14 @@ static void nfs_readpage_release_partial(void *calldata)
465 nfs_readdata_release(calldata); 464 nfs_readdata_release(calldata);
466} 465}
467 466
468#if defined(CONFIG_NFS_V4_1)
469void nfs_read_prepare(struct rpc_task *task, void *calldata) 467void nfs_read_prepare(struct rpc_task *task, void *calldata)
470{ 468{
471 struct nfs_read_data *data = calldata; 469 struct nfs_read_data *data = calldata;
472 470 NFS_PROTO(data->inode)->read_rpc_prepare(task, data);
473 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
474 &data->args.seq_args, &data->res.seq_res,
475 0, task))
476 return;
477 rpc_call_start(task);
478} 471}
479#endif /* CONFIG_NFS_V4_1 */
480 472
481static const struct rpc_call_ops nfs_read_partial_ops = { 473static const struct rpc_call_ops nfs_read_partial_ops = {
482#if defined(CONFIG_NFS_V4_1)
483 .rpc_call_prepare = nfs_read_prepare, 474 .rpc_call_prepare = nfs_read_prepare,
484#endif /* CONFIG_NFS_V4_1 */
485 .rpc_call_done = nfs_readpage_result_partial, 475 .rpc_call_done = nfs_readpage_result_partial,
486 .rpc_release = nfs_readpage_release_partial, 476 .rpc_release = nfs_readpage_release_partial,
487}; 477};
@@ -545,9 +535,7 @@ static void nfs_readpage_release_full(void *calldata)
545} 535}
546 536
547static const struct rpc_call_ops nfs_read_full_ops = { 537static const struct rpc_call_ops nfs_read_full_ops = {
548#if defined(CONFIG_NFS_V4_1)
549 .rpc_call_prepare = nfs_read_prepare, 538 .rpc_call_prepare = nfs_read_prepare,
550#endif /* CONFIG_NFS_V4_1 */
551 .rpc_call_done = nfs_readpage_result_full, 539 .rpc_call_done = nfs_readpage_result_full,
552 .rpc_release = nfs_readpage_release_full, 540 .rpc_release = nfs_readpage_release_full,
553}; 541};
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 3dfa4f112c0a..ccc4cdb1efe9 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -52,6 +52,8 @@
52#include <linux/nfs_xdr.h> 52#include <linux/nfs_xdr.h>
53#include <linux/magic.h> 53#include <linux/magic.h>
54#include <linux/parser.h> 54#include <linux/parser.h>
55#include <linux/nsproxy.h>
56#include <linux/rcupdate.h>
55 57
56#include <asm/system.h> 58#include <asm/system.h>
57#include <asm/uaccess.h> 59#include <asm/uaccess.h>
@@ -79,7 +81,6 @@ enum {
79 Opt_cto, Opt_nocto, 81 Opt_cto, Opt_nocto,
80 Opt_ac, Opt_noac, 82 Opt_ac, Opt_noac,
81 Opt_lock, Opt_nolock, 83 Opt_lock, Opt_nolock,
82 Opt_v2, Opt_v3, Opt_v4,
83 Opt_udp, Opt_tcp, Opt_rdma, 84 Opt_udp, Opt_tcp, Opt_rdma,
84 Opt_acl, Opt_noacl, 85 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus, 86 Opt_rdirplus, Opt_nordirplus,
@@ -97,10 +98,10 @@ enum {
97 Opt_namelen, 98 Opt_namelen,
98 Opt_mountport, 99 Opt_mountport,
99 Opt_mountvers, 100 Opt_mountvers,
100 Opt_nfsvers,
101 Opt_minorversion, 101 Opt_minorversion,
102 102
103 /* Mount options that take string arguments */ 103 /* Mount options that take string arguments */
104 Opt_nfsvers,
104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, 105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
105 Opt_addr, Opt_mountaddr, Opt_clientaddr, 106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
106 Opt_lookupcache, 107 Opt_lookupcache,
@@ -132,9 +133,6 @@ static const match_table_t nfs_mount_option_tokens = {
132 { Opt_noac, "noac" }, 133 { Opt_noac, "noac" },
133 { Opt_lock, "lock" }, 134 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" }, 135 { Opt_nolock, "nolock" },
135 { Opt_v2, "v2" },
136 { Opt_v3, "v3" },
137 { Opt_v4, "v4" },
138 { Opt_udp, "udp" }, 136 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" }, 137 { Opt_tcp, "tcp" },
140 { Opt_rdma, "rdma" }, 138 { Opt_rdma, "rdma" },
@@ -163,9 +161,10 @@ static const match_table_t nfs_mount_option_tokens = {
163 { Opt_namelen, "namlen=%s" }, 161 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" }, 162 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" }, 163 { Opt_mountvers, "mountvers=%s" },
164 { Opt_minorversion, "minorversion=%s" },
165
166 { Opt_nfsvers, "nfsvers=%s" }, 166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" }, 167 { Opt_nfsvers, "vers=%s" },
168 { Opt_minorversion, "minorversion=%s" },
169 168
170 { Opt_sec, "sec=%s" }, 169 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" }, 170 { Opt_proto, "proto=%s" },
@@ -179,6 +178,9 @@ static const match_table_t nfs_mount_option_tokens = {
179 { Opt_fscache_uniq, "fsc=%s" }, 178 { Opt_fscache_uniq, "fsc=%s" },
180 { Opt_local_lock, "local_lock=%s" }, 179 { Opt_local_lock, "local_lock=%s" },
181 180
181 /* The following needs to be listed after all other options */
182 { Opt_nfsvers, "v%s" },
183
182 { Opt_err, NULL } 184 { Opt_err, NULL }
183}; 185};
184 186
@@ -259,6 +261,22 @@ static match_table_t nfs_local_lock_tokens = {
259 { Opt_local_lock_err, NULL } 261 { Opt_local_lock_err, NULL }
260}; 262};
261 263
264enum {
265 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
266 Opt_vers_4_1,
267
268 Opt_vers_err
269};
270
271static match_table_t nfs_vers_tokens = {
272 { Opt_vers_2, "2" },
273 { Opt_vers_3, "3" },
274 { Opt_vers_4, "4" },
275 { Opt_vers_4_0, "4.0" },
276 { Opt_vers_4_1, "4.1" },
277
278 { Opt_vers_err, NULL }
279};
262 280
263static void nfs_umount_begin(struct super_block *); 281static void nfs_umount_begin(struct super_block *);
264static int nfs_statfs(struct dentry *, struct kstatfs *); 282static int nfs_statfs(struct dentry *, struct kstatfs *);
@@ -620,7 +638,6 @@ static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
620 struct nfs_client *clp = nfss->nfs_client; 638 struct nfs_client *clp = nfss->nfs_client;
621 639
622 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr); 640 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
623 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
624} 641}
625#else 642#else
626static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss, 643static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
@@ -629,6 +646,15 @@ static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
629} 646}
630#endif 647#endif
631 648
649static void nfs_show_nfs_version(struct seq_file *m,
650 unsigned int version,
651 unsigned int minorversion)
652{
653 seq_printf(m, ",vers=%u", version);
654 if (version == 4)
655 seq_printf(m, ".%u", minorversion);
656}
657
632/* 658/*
633 * Describe the mount options in force on this server representation 659 * Describe the mount options in force on this server representation
634 */ 660 */
@@ -656,7 +682,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
656 u32 version = clp->rpc_ops->version; 682 u32 version = clp->rpc_ops->version;
657 int local_flock, local_fcntl; 683 int local_flock, local_fcntl;
658 684
659 seq_printf(m, ",vers=%u", version); 685 nfs_show_nfs_version(m, version, clp->cl_minorversion);
660 seq_printf(m, ",rsize=%u", nfss->rsize); 686 seq_printf(m, ",rsize=%u", nfss->rsize);
661 seq_printf(m, ",wsize=%u", nfss->wsize); 687 seq_printf(m, ",wsize=%u", nfss->wsize);
662 if (nfss->bsize != 0) 688 if (nfss->bsize != 0)
@@ -676,8 +702,10 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
676 else 702 else
677 seq_puts(m, nfs_infop->nostr); 703 seq_puts(m, nfs_infop->nostr);
678 } 704 }
705 rcu_read_lock();
679 seq_printf(m, ",proto=%s", 706 seq_printf(m, ",proto=%s",
680 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID)); 707 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
708 rcu_read_unlock();
681 if (version == 4) { 709 if (version == 4) {
682 if (nfss->port != NFS_PORT) 710 if (nfss->port != NFS_PORT)
683 seq_printf(m, ",port=%u", nfss->port); 711 seq_printf(m, ",port=%u", nfss->port);
@@ -726,9 +754,11 @@ static int nfs_show_options(struct seq_file *m, struct dentry *root)
726 754
727 nfs_show_mount_options(m, nfss, 0); 755 nfs_show_mount_options(m, nfss, 0);
728 756
757 rcu_read_lock();
729 seq_printf(m, ",addr=%s", 758 seq_printf(m, ",addr=%s",
730 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient, 759 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
731 RPC_DISPLAY_ADDR)); 760 RPC_DISPLAY_ADDR));
761 rcu_read_unlock();
732 762
733 return 0; 763 return 0;
734} 764}
@@ -745,7 +775,6 @@ static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
745#endif 775#endif
746#endif 776#endif
747 777
748#ifdef CONFIG_NFS_V4
749#ifdef CONFIG_NFS_V4_1 778#ifdef CONFIG_NFS_V4_1
750static void show_pnfs(struct seq_file *m, struct nfs_server *server) 779static void show_pnfs(struct seq_file *m, struct nfs_server *server)
751{ 780{
@@ -755,9 +784,26 @@ static void show_pnfs(struct seq_file *m, struct nfs_server *server)
755 else 784 else
756 seq_printf(m, "not configured"); 785 seq_printf(m, "not configured");
757} 786}
787
788static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
789{
790 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
791 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
792 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
793 "date='%llu,%u'",
794 impl_id->name, impl_id->domain,
795 impl_id->date.seconds, impl_id->date.nseconds);
796 }
797}
758#else 798#else
759static void show_pnfs(struct seq_file *m, struct nfs_server *server) {} 799#ifdef CONFIG_NFS_V4
800static void show_pnfs(struct seq_file *m, struct nfs_server *server)
801{
802}
760#endif 803#endif
804static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
805{
806}
761#endif 807#endif
762 808
763static int nfs_show_devname(struct seq_file *m, struct dentry *root) 809static int nfs_show_devname(struct seq_file *m, struct dentry *root)
@@ -806,6 +852,8 @@ static int nfs_show_stats(struct seq_file *m, struct dentry *root)
806 852
807 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); 853 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
808 854
855 show_implementation_id(m, nfss);
856
809 seq_printf(m, "\n\tcaps:\t"); 857 seq_printf(m, "\n\tcaps:\t");
810 seq_printf(m, "caps=0x%x", nfss->caps); 858 seq_printf(m, "caps=0x%x", nfss->caps);
811 seq_printf(m, ",wtmult=%u", nfss->wtmult); 859 seq_printf(m, ",wtmult=%u", nfss->wtmult);
@@ -908,6 +956,7 @@ static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int ve
908 data->auth_flavor_len = 1; 956 data->auth_flavor_len = 1;
909 data->version = version; 957 data->version = version;
910 data->minorversion = 0; 958 data->minorversion = 0;
959 data->net = current->nsproxy->net_ns;
911 security_init_mnt_opts(&data->lsm_opts); 960 security_init_mnt_opts(&data->lsm_opts);
912 } 961 }
913 return data; 962 return data;
@@ -1052,6 +1101,40 @@ static int nfs_parse_security_flavors(char *value,
1052 return 1; 1101 return 1;
1053} 1102}
1054 1103
1104static int nfs_parse_version_string(char *string,
1105 struct nfs_parsed_mount_data *mnt,
1106 substring_t *args)
1107{
1108 mnt->flags &= ~NFS_MOUNT_VER3;
1109 switch (match_token(string, nfs_vers_tokens, args)) {
1110 case Opt_vers_2:
1111 mnt->version = 2;
1112 break;
1113 case Opt_vers_3:
1114 mnt->flags |= NFS_MOUNT_VER3;
1115 mnt->version = 3;
1116 break;
1117 case Opt_vers_4:
1118 /* Backward compatibility option. In future,
1119 * the mount program should always supply
1120 * a NFSv4 minor version number.
1121 */
1122 mnt->version = 4;
1123 break;
1124 case Opt_vers_4_0:
1125 mnt->version = 4;
1126 mnt->minorversion = 0;
1127 break;
1128 case Opt_vers_4_1:
1129 mnt->version = 4;
1130 mnt->minorversion = 1;
1131 break;
1132 default:
1133 return 0;
1134 }
1135 return 1;
1136}
1137
1055static int nfs_get_option_str(substring_t args[], char **option) 1138static int nfs_get_option_str(substring_t args[], char **option)
1056{ 1139{
1057 kfree(*option); 1140 kfree(*option);
@@ -1157,18 +1240,6 @@ static int nfs_parse_mount_options(char *raw,
1157 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | 1240 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1158 NFS_MOUNT_LOCAL_FCNTL); 1241 NFS_MOUNT_LOCAL_FCNTL);
1159 break; 1242 break;
1160 case Opt_v2:
1161 mnt->flags &= ~NFS_MOUNT_VER3;
1162 mnt->version = 2;
1163 break;
1164 case Opt_v3:
1165 mnt->flags |= NFS_MOUNT_VER3;
1166 mnt->version = 3;
1167 break;
1168 case Opt_v4:
1169 mnt->flags &= ~NFS_MOUNT_VER3;
1170 mnt->version = 4;
1171 break;
1172 case Opt_udp: 1243 case Opt_udp:
1173 mnt->flags &= ~NFS_MOUNT_TCP; 1244 mnt->flags &= ~NFS_MOUNT_TCP;
1174 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; 1245 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
@@ -1295,26 +1366,6 @@ static int nfs_parse_mount_options(char *raw,
1295 goto out_invalid_value; 1366 goto out_invalid_value;
1296 mnt->mount_server.version = option; 1367 mnt->mount_server.version = option;
1297 break; 1368 break;
1298 case Opt_nfsvers:
1299 if (nfs_get_option_ul(args, &option))
1300 goto out_invalid_value;
1301 switch (option) {
1302 case NFS2_VERSION:
1303 mnt->flags &= ~NFS_MOUNT_VER3;
1304 mnt->version = 2;
1305 break;
1306 case NFS3_VERSION:
1307 mnt->flags |= NFS_MOUNT_VER3;
1308 mnt->version = 3;
1309 break;
1310 case NFS4_VERSION:
1311 mnt->flags &= ~NFS_MOUNT_VER3;
1312 mnt->version = 4;
1313 break;
1314 default:
1315 goto out_invalid_value;
1316 }
1317 break;
1318 case Opt_minorversion: 1369 case Opt_minorversion:
1319 if (nfs_get_option_ul(args, &option)) 1370 if (nfs_get_option_ul(args, &option))
1320 goto out_invalid_value; 1371 goto out_invalid_value;
@@ -1326,6 +1377,15 @@ static int nfs_parse_mount_options(char *raw,
1326 /* 1377 /*
1327 * options that take text values 1378 * options that take text values
1328 */ 1379 */
1380 case Opt_nfsvers:
1381 string = match_strdup(args);
1382 if (string == NULL)
1383 goto out_nomem;
1384 rc = nfs_parse_version_string(string, mnt, args);
1385 kfree(string);
1386 if (!rc)
1387 goto out_invalid_value;
1388 break;
1329 case Opt_sec: 1389 case Opt_sec:
1330 string = match_strdup(args); 1390 string = match_strdup(args);
1331 if (string == NULL) 1391 if (string == NULL)
@@ -1405,7 +1465,7 @@ static int nfs_parse_mount_options(char *raw,
1405 if (string == NULL) 1465 if (string == NULL)
1406 goto out_nomem; 1466 goto out_nomem;
1407 mnt->nfs_server.addrlen = 1467 mnt->nfs_server.addrlen =
1408 rpc_pton(string, strlen(string), 1468 rpc_pton(mnt->net, string, strlen(string),
1409 (struct sockaddr *) 1469 (struct sockaddr *)
1410 &mnt->nfs_server.address, 1470 &mnt->nfs_server.address,
1411 sizeof(mnt->nfs_server.address)); 1471 sizeof(mnt->nfs_server.address));
@@ -1427,7 +1487,7 @@ static int nfs_parse_mount_options(char *raw,
1427 if (string == NULL) 1487 if (string == NULL)
1428 goto out_nomem; 1488 goto out_nomem;
1429 mnt->mount_server.addrlen = 1489 mnt->mount_server.addrlen =
1430 rpc_pton(string, strlen(string), 1490 rpc_pton(mnt->net, string, strlen(string),
1431 (struct sockaddr *) 1491 (struct sockaddr *)
1432 &mnt->mount_server.address, 1492 &mnt->mount_server.address,
1433 sizeof(mnt->mount_server.address)); 1493 sizeof(mnt->mount_server.address));
@@ -1516,6 +1576,9 @@ static int nfs_parse_mount_options(char *raw,
1516 if (!sloppy && invalid_option) 1576 if (!sloppy && invalid_option)
1517 return 0; 1577 return 0;
1518 1578
1579 if (mnt->minorversion && mnt->version != 4)
1580 goto out_minorversion_mismatch;
1581
1519 /* 1582 /*
1520 * verify that any proto=/mountproto= options match the address 1583 * verify that any proto=/mountproto= options match the address
1521 * familiies in the addr=/mountaddr= options. 1584 * familiies in the addr=/mountaddr= options.
@@ -1549,6 +1612,10 @@ out_invalid_address:
1549out_invalid_value: 1612out_invalid_value:
1550 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p); 1613 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1551 return 0; 1614 return 0;
1615out_minorversion_mismatch:
1616 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1617 "minorversion=%u\n", mnt->version, mnt->minorversion);
1618 return 0;
1552out_nomem: 1619out_nomem:
1553 printk(KERN_INFO "NFS: not enough memory to parse option\n"); 1620 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1554 return 0; 1621 return 0;
@@ -1622,6 +1689,7 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1622 .noresvport = args->flags & NFS_MOUNT_NORESVPORT, 1689 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1623 .auth_flav_len = &server_authlist_len, 1690 .auth_flav_len = &server_authlist_len,
1624 .auth_flavs = server_authlist, 1691 .auth_flavs = server_authlist,
1692 .net = args->net,
1625 }; 1693 };
1626 int status; 1694 int status;
1627 1695
@@ -2047,7 +2115,7 @@ static inline void nfs_initialise_sb(struct super_block *sb)
2047 2115
2048 /* We probably want something more informative here */ 2116 /* We probably want something more informative here */
2049 snprintf(sb->s_id, sizeof(sb->s_id), 2117 snprintf(sb->s_id, sizeof(sb->s_id),
2050 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); 2118 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2051 2119
2052 if (sb->s_blocksize == 0) 2120 if (sb->s_blocksize == 0)
2053 sb->s_blocksize = nfs_block_bits(server->wsize, 2121 sb->s_blocksize = nfs_block_bits(server->wsize,
@@ -2499,12 +2567,6 @@ static int nfs4_validate_text_mount_data(void *options,
2499 return -EINVAL; 2567 return -EINVAL;
2500 } 2568 }
2501 2569
2502 if (args->client_address == NULL) {
2503 dfprintk(MOUNT,
2504 "NFS4: mount program didn't pass callback address\n");
2505 return -EINVAL;
2506 }
2507
2508 return nfs_parse_devname(dev_name, 2570 return nfs_parse_devname(dev_name,
2509 &args->nfs_server.hostname, 2571 &args->nfs_server.hostname,
2510 NFS4_MAXNAMLEN, 2572 NFS4_MAXNAMLEN,
@@ -2663,8 +2725,7 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2663 if (!s->s_root) { 2725 if (!s->s_root) {
2664 /* initial superblock/root creation */ 2726 /* initial superblock/root creation */
2665 nfs4_fill_super(s); 2727 nfs4_fill_super(s);
2666 nfs_fscache_get_super_cookie( 2728 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
2667 s, data ? data->fscache_uniq : NULL, NULL);
2668 } 2729 }
2669 2730
2670 mntroot = nfs4_get_root(s, mntfh, dev_name); 2731 mntroot = nfs4_get_root(s, mntfh, dev_name);
diff --git a/fs/nfs/sysctl.c b/fs/nfs/sysctl.c
index 978aaeb8a093..ad4d2e787b20 100644
--- a/fs/nfs/sysctl.c
+++ b/fs/nfs/sysctl.c
@@ -32,7 +32,6 @@ static ctl_table nfs_cb_sysctls[] = {
32 .extra1 = (int *)&nfs_set_port_min, 32 .extra1 = (int *)&nfs_set_port_min,
33 .extra2 = (int *)&nfs_set_port_max, 33 .extra2 = (int *)&nfs_set_port_max,
34 }, 34 },
35#ifndef CONFIG_NFS_USE_NEW_IDMAPPER
36 { 35 {
37 .procname = "idmap_cache_timeout", 36 .procname = "idmap_cache_timeout",
38 .data = &nfs_idmap_cache_timeout, 37 .data = &nfs_idmap_cache_timeout,
@@ -40,7 +39,6 @@ static ctl_table nfs_cb_sysctls[] = {
40 .mode = 0644, 39 .mode = 0644,
41 .proc_handler = proc_dointvec_jiffies, 40 .proc_handler = proc_dointvec_jiffies,
42 }, 41 },
43#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
44#endif 42#endif
45 { 43 {
46 .procname = "nfs_mountpoint_timeout", 44 .procname = "nfs_mountpoint_timeout",
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index 4f9319a2e567..3210a03342f9 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -20,15 +20,6 @@
20#include "iostat.h" 20#include "iostat.h"
21#include "delegation.h" 21#include "delegation.h"
22 22
23struct nfs_unlinkdata {
24 struct hlist_node list;
25 struct nfs_removeargs args;
26 struct nfs_removeres res;
27 struct inode *dir;
28 struct rpc_cred *cred;
29 struct nfs_fattr dir_attr;
30};
31
32/** 23/**
33 * nfs_free_unlinkdata - release data from a sillydelete operation. 24 * nfs_free_unlinkdata - release data from a sillydelete operation.
34 * @data: pointer to unlink structure. 25 * @data: pointer to unlink structure.
@@ -107,25 +98,16 @@ static void nfs_async_unlink_release(void *calldata)
107 nfs_sb_deactive(sb); 98 nfs_sb_deactive(sb);
108} 99}
109 100
110#if defined(CONFIG_NFS_V4_1) 101static void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
111void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
112{ 102{
113 struct nfs_unlinkdata *data = calldata; 103 struct nfs_unlinkdata *data = calldata;
114 struct nfs_server *server = NFS_SERVER(data->dir); 104 NFS_PROTO(data->dir)->unlink_rpc_prepare(task, data);
115
116 if (nfs4_setup_sequence(server, &data->args.seq_args,
117 &data->res.seq_res, 1, task))
118 return;
119 rpc_call_start(task);
120} 105}
121#endif /* CONFIG_NFS_V4_1 */
122 106
123static const struct rpc_call_ops nfs_unlink_ops = { 107static const struct rpc_call_ops nfs_unlink_ops = {
124 .rpc_call_done = nfs_async_unlink_done, 108 .rpc_call_done = nfs_async_unlink_done,
125 .rpc_release = nfs_async_unlink_release, 109 .rpc_release = nfs_async_unlink_release,
126#if defined(CONFIG_NFS_V4_1)
127 .rpc_call_prepare = nfs_unlink_prepare, 110 .rpc_call_prepare = nfs_unlink_prepare,
128#endif /* CONFIG_NFS_V4_1 */
129}; 111};
130 112
131static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct nfs_unlinkdata *data) 113static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct nfs_unlinkdata *data)
@@ -341,18 +323,6 @@ nfs_cancel_async_unlink(struct dentry *dentry)
341 spin_unlock(&dentry->d_lock); 323 spin_unlock(&dentry->d_lock);
342} 324}
343 325
344struct nfs_renamedata {
345 struct nfs_renameargs args;
346 struct nfs_renameres res;
347 struct rpc_cred *cred;
348 struct inode *old_dir;
349 struct dentry *old_dentry;
350 struct nfs_fattr old_fattr;
351 struct inode *new_dir;
352 struct dentry *new_dentry;
353 struct nfs_fattr new_fattr;
354};
355
356/** 326/**
357 * nfs_async_rename_done - Sillyrename post-processing 327 * nfs_async_rename_done - Sillyrename post-processing
358 * @task: rpc_task of the sillyrename 328 * @task: rpc_task of the sillyrename
@@ -403,25 +373,16 @@ static void nfs_async_rename_release(void *calldata)
403 kfree(data); 373 kfree(data);
404} 374}
405 375
406#if defined(CONFIG_NFS_V4_1)
407static void nfs_rename_prepare(struct rpc_task *task, void *calldata) 376static void nfs_rename_prepare(struct rpc_task *task, void *calldata)
408{ 377{
409 struct nfs_renamedata *data = calldata; 378 struct nfs_renamedata *data = calldata;
410 struct nfs_server *server = NFS_SERVER(data->old_dir); 379 NFS_PROTO(data->old_dir)->rename_rpc_prepare(task, data);
411
412 if (nfs4_setup_sequence(server, &data->args.seq_args,
413 &data->res.seq_res, 1, task))
414 return;
415 rpc_call_start(task);
416} 380}
417#endif /* CONFIG_NFS_V4_1 */
418 381
419static const struct rpc_call_ops nfs_rename_ops = { 382static const struct rpc_call_ops nfs_rename_ops = {
420 .rpc_call_done = nfs_async_rename_done, 383 .rpc_call_done = nfs_async_rename_done,
421 .rpc_release = nfs_async_rename_release, 384 .rpc_release = nfs_async_rename_release,
422#if defined(CONFIG_NFS_V4_1)
423 .rpc_call_prepare = nfs_rename_prepare, 385 .rpc_call_prepare = nfs_rename_prepare,
424#endif /* CONFIG_NFS_V4_1 */
425}; 386};
426 387
427/** 388/**
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 834f0fe96f89..2c68818f68ac 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -100,7 +100,6 @@ void nfs_writedata_free(struct nfs_write_data *p)
100 100
101void nfs_writedata_release(struct nfs_write_data *wdata) 101void nfs_writedata_release(struct nfs_write_data *wdata)
102{ 102{
103 put_lseg(wdata->lseg);
104 put_nfs_open_context(wdata->args.context); 103 put_nfs_open_context(wdata->args.context);
105 nfs_writedata_free(wdata); 104 nfs_writedata_free(wdata);
106} 105}
@@ -236,10 +235,10 @@ static struct nfs_page *nfs_find_and_lock_request(struct page *page, bool nonblo
236 req = nfs_page_find_request_locked(page); 235 req = nfs_page_find_request_locked(page);
237 if (req == NULL) 236 if (req == NULL)
238 break; 237 break;
239 if (nfs_set_page_tag_locked(req)) 238 if (nfs_lock_request_dontget(req))
240 break; 239 break;
241 /* Note: If we hold the page lock, as is the case in nfs_writepage, 240 /* Note: If we hold the page lock, as is the case in nfs_writepage,
242 * then the call to nfs_set_page_tag_locked() will always 241 * then the call to nfs_lock_request_dontget() will always
243 * succeed provided that someone hasn't already marked the 242 * succeed provided that someone hasn't already marked the
244 * request as dirty (in which case we don't care). 243 * request as dirty (in which case we don't care).
245 */ 244 */
@@ -375,21 +374,14 @@ out_err:
375/* 374/*
376 * Insert a write request into an inode 375 * Insert a write request into an inode
377 */ 376 */
378static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req) 377static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
379{ 378{
380 struct nfs_inode *nfsi = NFS_I(inode); 379 struct nfs_inode *nfsi = NFS_I(inode);
381 int error;
382
383 error = radix_tree_preload(GFP_NOFS);
384 if (error != 0)
385 goto out;
386 380
387 /* Lock the request! */ 381 /* Lock the request! */
388 nfs_lock_request_dontget(req); 382 nfs_lock_request_dontget(req);
389 383
390 spin_lock(&inode->i_lock); 384 spin_lock(&inode->i_lock);
391 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
392 BUG_ON(error);
393 if (!nfsi->npages && nfs_have_delegation(inode, FMODE_WRITE)) 385 if (!nfsi->npages && nfs_have_delegation(inode, FMODE_WRITE))
394 inode->i_version++; 386 inode->i_version++;
395 set_bit(PG_MAPPED, &req->wb_flags); 387 set_bit(PG_MAPPED, &req->wb_flags);
@@ -397,12 +389,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
397 set_page_private(req->wb_page, (unsigned long)req); 389 set_page_private(req->wb_page, (unsigned long)req);
398 nfsi->npages++; 390 nfsi->npages++;
399 kref_get(&req->wb_kref); 391 kref_get(&req->wb_kref);
400 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
401 NFS_PAGE_TAG_LOCKED);
402 spin_unlock(&inode->i_lock); 392 spin_unlock(&inode->i_lock);
403 radix_tree_preload_end();
404out:
405 return error;
406} 393}
407 394
408/* 395/*
@@ -419,7 +406,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
419 set_page_private(req->wb_page, 0); 406 set_page_private(req->wb_page, 0);
420 ClearPagePrivate(req->wb_page); 407 ClearPagePrivate(req->wb_page);
421 clear_bit(PG_MAPPED, &req->wb_flags); 408 clear_bit(PG_MAPPED, &req->wb_flags);
422 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
423 nfsi->npages--; 409 nfsi->npages--;
424 spin_unlock(&inode->i_lock); 410 spin_unlock(&inode->i_lock);
425 nfs_release_request(req); 411 nfs_release_request(req);
@@ -432,39 +418,90 @@ nfs_mark_request_dirty(struct nfs_page *req)
432} 418}
433 419
434#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 420#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
435/* 421/**
436 * Add a request to the inode's commit list. 422 * nfs_request_add_commit_list - add request to a commit list
423 * @req: pointer to a struct nfs_page
424 * @head: commit list head
425 *
426 * This sets the PG_CLEAN bit, updates the inode global count of
427 * number of outstanding requests requiring a commit as well as
428 * the MM page stats.
429 *
430 * The caller must _not_ hold the inode->i_lock, but must be
431 * holding the nfs_page lock.
437 */ 432 */
438static void 433void
439nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) 434nfs_request_add_commit_list(struct nfs_page *req, struct list_head *head)
440{ 435{
441 struct inode *inode = req->wb_context->dentry->d_inode; 436 struct inode *inode = req->wb_context->dentry->d_inode;
442 struct nfs_inode *nfsi = NFS_I(inode);
443 437
444 spin_lock(&inode->i_lock);
445 set_bit(PG_CLEAN, &(req)->wb_flags); 438 set_bit(PG_CLEAN, &(req)->wb_flags);
446 radix_tree_tag_set(&nfsi->nfs_page_tree, 439 spin_lock(&inode->i_lock);
447 req->wb_index, 440 nfs_list_add_request(req, head);
448 NFS_PAGE_TAG_COMMIT); 441 NFS_I(inode)->ncommit++;
449 nfsi->ncommit++;
450 spin_unlock(&inode->i_lock); 442 spin_unlock(&inode->i_lock);
451 pnfs_mark_request_commit(req, lseg);
452 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 443 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
453 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE); 444 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
454 __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 445 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
455} 446}
447EXPORT_SYMBOL_GPL(nfs_request_add_commit_list);
456 448
457static int 449/**
450 * nfs_request_remove_commit_list - Remove request from a commit list
451 * @req: pointer to a nfs_page
452 *
453 * This clears the PG_CLEAN bit, and updates the inode global count of
454 * number of outstanding requests requiring a commit
455 * It does not update the MM page stats.
456 *
457 * The caller _must_ hold the inode->i_lock and the nfs_page lock.
458 */
459void
460nfs_request_remove_commit_list(struct nfs_page *req)
461{
462 struct inode *inode = req->wb_context->dentry->d_inode;
463
464 if (!test_and_clear_bit(PG_CLEAN, &(req)->wb_flags))
465 return;
466 nfs_list_remove_request(req);
467 NFS_I(inode)->ncommit--;
468}
469EXPORT_SYMBOL_GPL(nfs_request_remove_commit_list);
470
471
472/*
473 * Add a request to the inode's commit list.
474 */
475static void
476nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
477{
478 struct inode *inode = req->wb_context->dentry->d_inode;
479
480 if (pnfs_mark_request_commit(req, lseg))
481 return;
482 nfs_request_add_commit_list(req, &NFS_I(inode)->commit_list);
483}
484
485static void
486nfs_clear_page_commit(struct page *page)
487{
488 dec_zone_page_state(page, NR_UNSTABLE_NFS);
489 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE);
490}
491
492static void
458nfs_clear_request_commit(struct nfs_page *req) 493nfs_clear_request_commit(struct nfs_page *req)
459{ 494{
460 struct page *page = req->wb_page; 495 if (test_bit(PG_CLEAN, &req->wb_flags)) {
496 struct inode *inode = req->wb_context->dentry->d_inode;
461 497
462 if (test_and_clear_bit(PG_CLEAN, &(req)->wb_flags)) { 498 if (!pnfs_clear_request_commit(req)) {
463 dec_zone_page_state(page, NR_UNSTABLE_NFS); 499 spin_lock(&inode->i_lock);
464 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE); 500 nfs_request_remove_commit_list(req);
465 return 1; 501 spin_unlock(&inode->i_lock);
502 }
503 nfs_clear_page_commit(req->wb_page);
466 } 504 }
467 return 0;
468} 505}
469 506
470static inline 507static inline
@@ -491,15 +528,14 @@ int nfs_reschedule_unstable_write(struct nfs_page *req,
491 return 0; 528 return 0;
492} 529}
493#else 530#else
494static inline void 531static void
495nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) 532nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
496{ 533{
497} 534}
498 535
499static inline int 536static void
500nfs_clear_request_commit(struct nfs_page *req) 537nfs_clear_request_commit(struct nfs_page *req)
501{ 538{
502 return 0;
503} 539}
504 540
505static inline 541static inline
@@ -520,46 +556,65 @@ int nfs_reschedule_unstable_write(struct nfs_page *req,
520static int 556static int
521nfs_need_commit(struct nfs_inode *nfsi) 557nfs_need_commit(struct nfs_inode *nfsi)
522{ 558{
523 return radix_tree_tagged(&nfsi->nfs_page_tree, NFS_PAGE_TAG_COMMIT); 559 return nfsi->ncommit > 0;
560}
561
562/* i_lock held by caller */
563static int
564nfs_scan_commit_list(struct list_head *src, struct list_head *dst, int max,
565 spinlock_t *lock)
566{
567 struct nfs_page *req, *tmp;
568 int ret = 0;
569
570 list_for_each_entry_safe(req, tmp, src, wb_list) {
571 if (!nfs_lock_request(req))
572 continue;
573 if (cond_resched_lock(lock))
574 list_safe_reset_next(req, tmp, wb_list);
575 nfs_request_remove_commit_list(req);
576 nfs_list_add_request(req, dst);
577 ret++;
578 if (ret == max)
579 break;
580 }
581 return ret;
524} 582}
525 583
526/* 584/*
527 * nfs_scan_commit - Scan an inode for commit requests 585 * nfs_scan_commit - Scan an inode for commit requests
528 * @inode: NFS inode to scan 586 * @inode: NFS inode to scan
529 * @dst: destination list 587 * @dst: destination list
530 * @idx_start: lower bound of page->index to scan.
531 * @npages: idx_start + npages sets the upper bound to scan.
532 * 588 *
533 * Moves requests from the inode's 'commit' request list. 589 * Moves requests from the inode's 'commit' request list.
534 * The requests are *not* checked to ensure that they form a contiguous set. 590 * The requests are *not* checked to ensure that they form a contiguous set.
535 */ 591 */
536static int 592static int
537nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 593nfs_scan_commit(struct inode *inode, struct list_head *dst)
538{ 594{
539 struct nfs_inode *nfsi = NFS_I(inode); 595 struct nfs_inode *nfsi = NFS_I(inode);
540 int ret; 596 int ret = 0;
541
542 if (!nfs_need_commit(nfsi))
543 return 0;
544 597
545 spin_lock(&inode->i_lock); 598 spin_lock(&inode->i_lock);
546 ret = nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT); 599 if (nfsi->ncommit > 0) {
547 if (ret > 0) 600 const int max = INT_MAX;
548 nfsi->ncommit -= ret;
549 spin_unlock(&inode->i_lock);
550
551 if (nfs_need_commit(NFS_I(inode)))
552 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
553 601
602 ret = nfs_scan_commit_list(&nfsi->commit_list, dst, max,
603 &inode->i_lock);
604 ret += pnfs_scan_commit_lists(inode, max - ret,
605 &inode->i_lock);
606 }
607 spin_unlock(&inode->i_lock);
554 return ret; 608 return ret;
555} 609}
610
556#else 611#else
557static inline int nfs_need_commit(struct nfs_inode *nfsi) 612static inline int nfs_need_commit(struct nfs_inode *nfsi)
558{ 613{
559 return 0; 614 return 0;
560} 615}
561 616
562static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 617static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst)
563{ 618{
564 return 0; 619 return 0;
565} 620}
@@ -604,7 +659,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
604 || end < req->wb_offset) 659 || end < req->wb_offset)
605 goto out_flushme; 660 goto out_flushme;
606 661
607 if (nfs_set_page_tag_locked(req)) 662 if (nfs_lock_request_dontget(req))
608 break; 663 break;
609 664
610 /* The request is locked, so wait and then retry */ 665 /* The request is locked, so wait and then retry */
@@ -616,13 +671,6 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
616 spin_lock(&inode->i_lock); 671 spin_lock(&inode->i_lock);
617 } 672 }
618 673
619 if (nfs_clear_request_commit(req) &&
620 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree,
621 req->wb_index, NFS_PAGE_TAG_COMMIT) != NULL) {
622 NFS_I(inode)->ncommit--;
623 pnfs_clear_request_commit(req);
624 }
625
626 /* Okay, the request matches. Update the region */ 674 /* Okay, the request matches. Update the region */
627 if (offset < req->wb_offset) { 675 if (offset < req->wb_offset) {
628 req->wb_offset = offset; 676 req->wb_offset = offset;
@@ -634,6 +682,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
634 req->wb_bytes = rqend - req->wb_offset; 682 req->wb_bytes = rqend - req->wb_offset;
635out_unlock: 683out_unlock:
636 spin_unlock(&inode->i_lock); 684 spin_unlock(&inode->i_lock);
685 nfs_clear_request_commit(req);
637 return req; 686 return req;
638out_flushme: 687out_flushme:
639 spin_unlock(&inode->i_lock); 688 spin_unlock(&inode->i_lock);
@@ -655,7 +704,6 @@ static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
655{ 704{
656 struct inode *inode = page->mapping->host; 705 struct inode *inode = page->mapping->host;
657 struct nfs_page *req; 706 struct nfs_page *req;
658 int error;
659 707
660 req = nfs_try_to_update_request(inode, page, offset, bytes); 708 req = nfs_try_to_update_request(inode, page, offset, bytes);
661 if (req != NULL) 709 if (req != NULL)
@@ -663,11 +711,7 @@ static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
663 req = nfs_create_request(ctx, inode, page, offset, bytes); 711 req = nfs_create_request(ctx, inode, page, offset, bytes);
664 if (IS_ERR(req)) 712 if (IS_ERR(req))
665 goto out; 713 goto out;
666 error = nfs_inode_add_request(inode, req); 714 nfs_inode_add_request(inode, req);
667 if (error != 0) {
668 nfs_release_request(req);
669 req = ERR_PTR(error);
670 }
671out: 715out:
672 return req; 716 return req;
673} 717}
@@ -684,7 +728,7 @@ static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
684 nfs_grow_file(page, offset, count); 728 nfs_grow_file(page, offset, count);
685 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes); 729 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
686 nfs_mark_request_dirty(req); 730 nfs_mark_request_dirty(req);
687 nfs_clear_page_tag_locked(req); 731 nfs_unlock_request(req);
688 return 0; 732 return 0;
689} 733}
690 734
@@ -777,7 +821,7 @@ static void nfs_writepage_release(struct nfs_page *req,
777 821
778 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req, data)) 822 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req, data))
779 nfs_inode_remove_request(req); 823 nfs_inode_remove_request(req);
780 nfs_clear_page_tag_locked(req); 824 nfs_unlock_request(req);
781 nfs_end_page_writeback(page); 825 nfs_end_page_writeback(page);
782} 826}
783 827
@@ -925,7 +969,7 @@ static void nfs_redirty_request(struct nfs_page *req)
925 struct page *page = req->wb_page; 969 struct page *page = req->wb_page;
926 970
927 nfs_mark_request_dirty(req); 971 nfs_mark_request_dirty(req);
928 nfs_clear_page_tag_locked(req); 972 nfs_unlock_request(req);
929 nfs_end_page_writeback(page); 973 nfs_end_page_writeback(page);
930} 974}
931 975
@@ -1128,23 +1172,14 @@ out:
1128 nfs_writedata_release(calldata); 1172 nfs_writedata_release(calldata);
1129} 1173}
1130 1174
1131#if defined(CONFIG_NFS_V4_1)
1132void nfs_write_prepare(struct rpc_task *task, void *calldata) 1175void nfs_write_prepare(struct rpc_task *task, void *calldata)
1133{ 1176{
1134 struct nfs_write_data *data = calldata; 1177 struct nfs_write_data *data = calldata;
1135 1178 NFS_PROTO(data->inode)->write_rpc_prepare(task, data);
1136 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
1137 &data->args.seq_args,
1138 &data->res.seq_res, 1, task))
1139 return;
1140 rpc_call_start(task);
1141} 1179}
1142#endif /* CONFIG_NFS_V4_1 */
1143 1180
1144static const struct rpc_call_ops nfs_write_partial_ops = { 1181static const struct rpc_call_ops nfs_write_partial_ops = {
1145#if defined(CONFIG_NFS_V4_1)
1146 .rpc_call_prepare = nfs_write_prepare, 1182 .rpc_call_prepare = nfs_write_prepare,
1147#endif /* CONFIG_NFS_V4_1 */
1148 .rpc_call_done = nfs_writeback_done_partial, 1183 .rpc_call_done = nfs_writeback_done_partial,
1149 .rpc_release = nfs_writeback_release_partial, 1184 .rpc_release = nfs_writeback_release_partial,
1150}; 1185};
@@ -1199,16 +1234,14 @@ static void nfs_writeback_release_full(void *calldata)
1199remove_request: 1234remove_request:
1200 nfs_inode_remove_request(req); 1235 nfs_inode_remove_request(req);
1201 next: 1236 next:
1202 nfs_clear_page_tag_locked(req); 1237 nfs_unlock_request(req);
1203 nfs_end_page_writeback(page); 1238 nfs_end_page_writeback(page);
1204 } 1239 }
1205 nfs_writedata_release(calldata); 1240 nfs_writedata_release(calldata);
1206} 1241}
1207 1242
1208static const struct rpc_call_ops nfs_write_full_ops = { 1243static const struct rpc_call_ops nfs_write_full_ops = {
1209#if defined(CONFIG_NFS_V4_1)
1210 .rpc_call_prepare = nfs_write_prepare, 1244 .rpc_call_prepare = nfs_write_prepare,
1211#endif /* CONFIG_NFS_V4_1 */
1212 .rpc_call_done = nfs_writeback_done_full, 1245 .rpc_call_done = nfs_writeback_done_full,
1213 .rpc_release = nfs_writeback_release_full, 1246 .rpc_release = nfs_writeback_release_full,
1214}; 1247};
@@ -1325,7 +1358,6 @@ void nfs_commitdata_release(void *data)
1325{ 1358{
1326 struct nfs_write_data *wdata = data; 1359 struct nfs_write_data *wdata = data;
1327 1360
1328 put_lseg(wdata->lseg);
1329 put_nfs_open_context(wdata->args.context); 1361 put_nfs_open_context(wdata->args.context);
1330 nfs_commit_free(wdata); 1362 nfs_commit_free(wdata);
1331} 1363}
@@ -1411,7 +1443,7 @@ void nfs_retry_commit(struct list_head *page_list,
1411 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 1443 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
1412 dec_bdi_stat(req->wb_page->mapping->backing_dev_info, 1444 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1413 BDI_RECLAIMABLE); 1445 BDI_RECLAIMABLE);
1414 nfs_clear_page_tag_locked(req); 1446 nfs_unlock_request(req);
1415 } 1447 }
1416} 1448}
1417EXPORT_SYMBOL_GPL(nfs_retry_commit); 1449EXPORT_SYMBOL_GPL(nfs_retry_commit);
@@ -1460,7 +1492,7 @@ void nfs_commit_release_pages(struct nfs_write_data *data)
1460 while (!list_empty(&data->pages)) { 1492 while (!list_empty(&data->pages)) {
1461 req = nfs_list_entry(data->pages.next); 1493 req = nfs_list_entry(data->pages.next);
1462 nfs_list_remove_request(req); 1494 nfs_list_remove_request(req);
1463 nfs_clear_request_commit(req); 1495 nfs_clear_page_commit(req->wb_page);
1464 1496
1465 dprintk("NFS: commit (%s/%lld %d@%lld)", 1497 dprintk("NFS: commit (%s/%lld %d@%lld)",
1466 req->wb_context->dentry->d_sb->s_id, 1498 req->wb_context->dentry->d_sb->s_id,
@@ -1486,7 +1518,7 @@ void nfs_commit_release_pages(struct nfs_write_data *data)
1486 dprintk(" mismatch\n"); 1518 dprintk(" mismatch\n");
1487 nfs_mark_request_dirty(req); 1519 nfs_mark_request_dirty(req);
1488 next: 1520 next:
1489 nfs_clear_page_tag_locked(req); 1521 nfs_unlock_request(req);
1490 } 1522 }
1491} 1523}
1492EXPORT_SYMBOL_GPL(nfs_commit_release_pages); 1524EXPORT_SYMBOL_GPL(nfs_commit_release_pages);
@@ -1501,9 +1533,7 @@ static void nfs_commit_release(void *calldata)
1501} 1533}
1502 1534
1503static const struct rpc_call_ops nfs_commit_ops = { 1535static const struct rpc_call_ops nfs_commit_ops = {
1504#if defined(CONFIG_NFS_V4_1)
1505 .rpc_call_prepare = nfs_write_prepare, 1536 .rpc_call_prepare = nfs_write_prepare,
1506#endif /* CONFIG_NFS_V4_1 */
1507 .rpc_call_done = nfs_commit_done, 1537 .rpc_call_done = nfs_commit_done,
1508 .rpc_release = nfs_commit_release, 1538 .rpc_release = nfs_commit_release,
1509}; 1539};
@@ -1517,7 +1547,7 @@ int nfs_commit_inode(struct inode *inode, int how)
1517 res = nfs_commit_set_lock(NFS_I(inode), may_wait); 1547 res = nfs_commit_set_lock(NFS_I(inode), may_wait);
1518 if (res <= 0) 1548 if (res <= 0)
1519 goto out_mark_dirty; 1549 goto out_mark_dirty;
1520 res = nfs_scan_commit(inode, &head, 0, 0); 1550 res = nfs_scan_commit(inode, &head);
1521 if (res) { 1551 if (res) {
1522 int error; 1552 int error;
1523 1553
@@ -1635,6 +1665,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1635 if (req == NULL) 1665 if (req == NULL)
1636 break; 1666 break;
1637 if (nfs_lock_request_dontget(req)) { 1667 if (nfs_lock_request_dontget(req)) {
1668 nfs_clear_request_commit(req);
1638 nfs_inode_remove_request(req); 1669 nfs_inode_remove_request(req);
1639 /* 1670 /*
1640 * In case nfs_inode_remove_request has marked the 1671 * In case nfs_inode_remove_request has marked the
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 24b6bcf1e945..cf6e4190e41c 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -605,24 +605,24 @@ static struct rpc_version nfs_cb_version4 = {
605 .procs = nfs4_cb_procedures 605 .procs = nfs4_cb_procedures
606}; 606};
607 607
608static struct rpc_version *nfs_cb_version[] = { 608static const struct rpc_version *nfs_cb_version[] = {
609 &nfs_cb_version4, 609 &nfs_cb_version4,
610}; 610};
611 611
612static struct rpc_program cb_program; 612static const struct rpc_program cb_program;
613 613
614static struct rpc_stat cb_stats = { 614static struct rpc_stat cb_stats = {
615 .program = &cb_program 615 .program = &cb_program
616}; 616};
617 617
618#define NFS4_CALLBACK 0x40000000 618#define NFS4_CALLBACK 0x40000000
619static struct rpc_program cb_program = { 619static const struct rpc_program cb_program = {
620 .name = "nfs4_cb", 620 .name = "nfs4_cb",
621 .number = NFS4_CALLBACK, 621 .number = NFS4_CALLBACK,
622 .nrvers = ARRAY_SIZE(nfs_cb_version), 622 .nrvers = ARRAY_SIZE(nfs_cb_version),
623 .version = nfs_cb_version, 623 .version = nfs_cb_version,
624 .stats = &cb_stats, 624 .stats = &cb_stats,
625 .pipe_dir_name = "/nfsd4_cb", 625 .pipe_dir_name = "nfsd4_cb",
626}; 626};
627 627
628static int max_cb_time(void) 628static int max_cb_time(void)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index e318964d8aca..a0a2b535b0e0 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1346,7 +1346,7 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se, struct svc_r
1346 else 1346 else
1347 goto out_err; 1347 goto out_err;
1348 1348
1349 conn->cb_addrlen = rpc_uaddr2sockaddr(se->se_callback_addr_val, 1349 conn->cb_addrlen = rpc_uaddr2sockaddr(&init_net, se->se_callback_addr_val,
1350 se->se_callback_addr_len, 1350 se->se_callback_addr_len,
1351 (struct sockaddr *)&conn->cb_addr, 1351 (struct sockaddr *)&conn->cb_addr,
1352 sizeof(conn->cb_addr)); 1352 sizeof(conn->cb_addr));
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 748eda93ce59..64c24af8d7ea 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -223,7 +223,7 @@ static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
223 if (qword_get(&buf, fo_path, size) < 0) 223 if (qword_get(&buf, fo_path, size) < 0)
224 return -EINVAL; 224 return -EINVAL;
225 225
226 if (rpc_pton(fo_path, size, sap, salen) == 0) 226 if (rpc_pton(&init_net, fo_path, size, sap, salen) == 0)
227 return -EINVAL; 227 return -EINVAL;
228 228
229 return nlmsvc_unlock_all_by_ip(sap); 229 return nlmsvc_unlock_all_by_ip(sap);
@@ -722,7 +722,7 @@ static ssize_t __write_ports_addxprt(char *buf)
722 nfsd_serv->sv_nrthreads--; 722 nfsd_serv->sv_nrthreads--;
723 return 0; 723 return 0;
724out_close: 724out_close:
725 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port); 725 xprt = svc_find_xprt(nfsd_serv, transport, &init_net, PF_INET, port);
726 if (xprt != NULL) { 726 if (xprt != NULL) {
727 svc_close_xprt(xprt); 727 svc_close_xprt(xprt);
728 svc_xprt_put(xprt); 728 svc_xprt_put(xprt);
@@ -748,7 +748,7 @@ static ssize_t __write_ports_delxprt(char *buf)
748 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL) 748 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
749 return -EINVAL; 749 return -EINVAL;
750 750
751 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port); 751 xprt = svc_find_xprt(nfsd_serv, transport, &init_net, AF_UNSPEC, port);
752 if (xprt == NULL) 752 if (xprt == NULL)
753 return -ENOTCONN; 753 return -ENOTCONN;
754 754
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index aacf1f4b9fb5..28dfad39f0c5 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -251,13 +251,13 @@ static void nfsd_shutdown(void)
251 nfsd_up = false; 251 nfsd_up = false;
252} 252}
253 253
254static void nfsd_last_thread(struct svc_serv *serv) 254static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
255{ 255{
256 /* When last nfsd thread exits we need to do some clean-up */ 256 /* When last nfsd thread exits we need to do some clean-up */
257 nfsd_serv = NULL; 257 nfsd_serv = NULL;
258 nfsd_shutdown(); 258 nfsd_shutdown();
259 259
260 svc_rpcb_cleanup(serv); 260 svc_rpcb_cleanup(serv, net);
261 261
262 printk(KERN_WARNING "nfsd: last server has exited, flushing export " 262 printk(KERN_WARNING "nfsd: last server has exited, flushing export "
263 "cache\n"); 263 "cache\n");
diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c
index a2e2402b2afb..6d4521feb6e3 100644
--- a/fs/nfsd/stats.c
+++ b/fs/nfsd/stats.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/sunrpc/stats.h> 26#include <linux/sunrpc/stats.h>
27#include <linux/nfsd/stats.h> 27#include <linux/nfsd/stats.h>
28#include <net/net_namespace.h>
28 29
29#include "nfsd.h" 30#include "nfsd.h"
30 31
@@ -94,11 +95,11 @@ static const struct file_operations nfsd_proc_fops = {
94void 95void
95nfsd_stat_init(void) 96nfsd_stat_init(void)
96{ 97{
97 svc_proc_register(&nfsd_svcstats, &nfsd_proc_fops); 98 svc_proc_register(&init_net, &nfsd_svcstats, &nfsd_proc_fops);
98} 99}
99 100
100void 101void
101nfsd_stat_shutdown(void) 102nfsd_stat_shutdown(void)
102{ 103{
103 svc_proc_unregister("nfsd"); 104 svc_proc_unregister(&init_net, "nfsd");
104} 105}
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9cde9edf9c4d..d4548dd49b02 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -198,26 +198,6 @@ static int proc_root_link(struct dentry *dentry, struct path *path)
198 return result; 198 return result;
199} 199}
200 200
201static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
202{
203 struct mm_struct *mm;
204 int err;
205
206 err = mutex_lock_killable(&task->signal->cred_guard_mutex);
207 if (err)
208 return ERR_PTR(err);
209
210 mm = get_task_mm(task);
211 if (mm && mm != current->mm &&
212 !ptrace_may_access(task, mode)) {
213 mmput(mm);
214 mm = ERR_PTR(-EACCES);
215 }
216 mutex_unlock(&task->signal->cred_guard_mutex);
217
218 return mm;
219}
220
221struct mm_struct *mm_for_maps(struct task_struct *task) 201struct mm_struct *mm_for_maps(struct task_struct *task)
222{ 202{
223 return mm_access(task, PTRACE_MODE_READ); 203 return mm_access(task, PTRACE_MODE_READ);
@@ -711,6 +691,13 @@ static int mem_open(struct inode* inode, struct file* file)
711 if (IS_ERR(mm)) 691 if (IS_ERR(mm))
712 return PTR_ERR(mm); 692 return PTR_ERR(mm);
713 693
694 if (mm) {
695 /* ensure this mm_struct can't be freed */
696 atomic_inc(&mm->mm_count);
697 /* but do not pin its memory */
698 mmput(mm);
699 }
700
714 /* OK to pass negative loff_t, we can catch out-of-range */ 701 /* OK to pass negative loff_t, we can catch out-of-range */
715 file->f_mode |= FMODE_UNSIGNED_OFFSET; 702 file->f_mode |= FMODE_UNSIGNED_OFFSET;
716 file->private_data = mm; 703 file->private_data = mm;
@@ -718,57 +705,13 @@ static int mem_open(struct inode* inode, struct file* file)
718 return 0; 705 return 0;
719} 706}
720 707
721static ssize_t mem_read(struct file * file, char __user * buf, 708static ssize_t mem_rw(struct file *file, char __user *buf,
722 size_t count, loff_t *ppos) 709 size_t count, loff_t *ppos, int write)
723{ 710{
724 int ret;
725 char *page;
726 unsigned long src = *ppos;
727 struct mm_struct *mm = file->private_data; 711 struct mm_struct *mm = file->private_data;
728 712 unsigned long addr = *ppos;
729 if (!mm) 713 ssize_t copied;
730 return 0;
731
732 page = (char *)__get_free_page(GFP_TEMPORARY);
733 if (!page)
734 return -ENOMEM;
735
736 ret = 0;
737
738 while (count > 0) {
739 int this_len, retval;
740
741 this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
742 retval = access_remote_vm(mm, src, page, this_len, 0);
743 if (!retval) {
744 if (!ret)
745 ret = -EIO;
746 break;
747 }
748
749 if (copy_to_user(buf, page, retval)) {
750 ret = -EFAULT;
751 break;
752 }
753
754 ret += retval;
755 src += retval;
756 buf += retval;
757 count -= retval;
758 }
759 *ppos = src;
760
761 free_page((unsigned long) page);
762 return ret;
763}
764
765static ssize_t mem_write(struct file * file, const char __user *buf,
766 size_t count, loff_t *ppos)
767{
768 int copied;
769 char *page; 714 char *page;
770 unsigned long dst = *ppos;
771 struct mm_struct *mm = file->private_data;
772 715
773 if (!mm) 716 if (!mm)
774 return 0; 717 return 0;
@@ -778,31 +721,54 @@ static ssize_t mem_write(struct file * file, const char __user *buf,
778 return -ENOMEM; 721 return -ENOMEM;
779 722
780 copied = 0; 723 copied = 0;
724 if (!atomic_inc_not_zero(&mm->mm_users))
725 goto free;
726
781 while (count > 0) { 727 while (count > 0) {
782 int this_len, retval; 728 int this_len = min_t(int, count, PAGE_SIZE);
783 729
784 this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; 730 if (write && copy_from_user(page, buf, this_len)) {
785 if (copy_from_user(page, buf, this_len)) {
786 copied = -EFAULT; 731 copied = -EFAULT;
787 break; 732 break;
788 } 733 }
789 retval = access_remote_vm(mm, dst, page, this_len, 1); 734
790 if (!retval) { 735 this_len = access_remote_vm(mm, addr, page, this_len, write);
736 if (!this_len) {
791 if (!copied) 737 if (!copied)
792 copied = -EIO; 738 copied = -EIO;
793 break; 739 break;
794 } 740 }
795 copied += retval; 741
796 buf += retval; 742 if (!write && copy_to_user(buf, page, this_len)) {
797 dst += retval; 743 copied = -EFAULT;
798 count -= retval; 744 break;
745 }
746
747 buf += this_len;
748 addr += this_len;
749 copied += this_len;
750 count -= this_len;
799 } 751 }
800 *ppos = dst; 752 *ppos = addr;
801 753
754 mmput(mm);
755free:
802 free_page((unsigned long) page); 756 free_page((unsigned long) page);
803 return copied; 757 return copied;
804} 758}
805 759
760static ssize_t mem_read(struct file *file, char __user *buf,
761 size_t count, loff_t *ppos)
762{
763 return mem_rw(file, buf, count, ppos, 0);
764}
765
766static ssize_t mem_write(struct file *file, const char __user *buf,
767 size_t count, loff_t *ppos)
768{
769 return mem_rw(file, (char __user*)buf, count, ppos, 1);
770}
771
806loff_t mem_lseek(struct file *file, loff_t offset, int orig) 772loff_t mem_lseek(struct file *file, loff_t offset, int orig)
807{ 773{
808 switch (orig) { 774 switch (orig) {
@@ -822,8 +788,8 @@ loff_t mem_lseek(struct file *file, loff_t offset, int orig)
822static int mem_release(struct inode *inode, struct file *file) 788static int mem_release(struct inode *inode, struct file *file)
823{ 789{
824 struct mm_struct *mm = file->private_data; 790 struct mm_struct *mm = file->private_data;
825 791 if (mm)
826 mmput(mm); 792 mmdrop(mm);
827 return 0; 793 return 0;
828} 794}
829 795