aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/filesystems/automount-support.txt2
-rw-r--r--drivers/usb/core/inode.c2
-rw-r--r--fs/9p/vfs_super.c7
-rw-r--r--fs/afs/mntpt.c2
-rw-r--r--fs/afs/super.c2
-rw-r--r--fs/afs/super.h2
-rw-r--r--fs/binfmt_misc.c3
-rw-r--r--fs/cifs/cifsfs.c6
-rw-r--r--fs/configfs/mount.c2
-rw-r--r--fs/debugfs/inode.c2
-rw-r--r--fs/fuse/inode.c5
-rw-r--r--fs/libfs.c4
-rw-r--r--fs/lockd/clntlock.c39
-rw-r--r--fs/lockd/clntproc.c14
-rw-r--r--fs/lockd/host.c9
-rw-r--r--fs/namespace.c128
-rw-r--r--fs/nfs/Makefile8
-rw-r--r--fs/nfs/callback.c2
-rw-r--r--fs/nfs/callback_xdr.c2
-rw-r--r--fs/nfs/dir.c18
-rw-r--r--fs/nfs/direct.c6
-rw-r--r--fs/nfs/file.c30
-rw-r--r--fs/nfs/idmap.c1
-rw-r--r--fs/nfs/inode.c1292
-rw-r--r--fs/nfs/internal.h179
-rw-r--r--fs/nfs/namespace.c229
-rw-r--r--fs/nfs/nfs2xdr.c5
-rw-r--r--fs/nfs/nfs3acl.c11
-rw-r--r--fs/nfs/nfs3proc.c5
-rw-r--r--fs/nfs/nfs3xdr.c6
-rw-r--r--fs/nfs/nfs4_fs.h4
-rw-r--r--fs/nfs/nfs4namespace.c201
-rw-r--r--fs/nfs/nfs4proc.c111
-rw-r--r--fs/nfs/nfs4xdr.c218
-rw-r--r--fs/nfs/pagelist.c51
-rw-r--r--fs/nfs/proc.c5
-rw-r--r--fs/nfs/read.c122
-rw-r--r--fs/nfs/super.c1497
-rw-r--r--fs/nfs/symlink.c2
-rw-r--r--fs/nfs/sysctl.c10
-rw-r--r--fs/nfs/write.c49
-rw-r--r--fs/super.c24
-rw-r--r--include/linux/fs.h4
-rw-r--r--include/linux/lockd/lockd.h4
-rw-r--r--include/linux/mount.h8
-rw-r--r--include/linux/nfs4.h1
-rw-r--r--include/linux/nfs_fs.h64
-rw-r--r--include/linux/nfs_fs_sb.h1
-rw-r--r--include/linux/nfs_page.h5
-rw-r--r--include/linux/nfs_xdr.h61
-rw-r--r--include/linux/sunrpc/xdr.h1
-rw-r--r--mm/shmem.c2
-rw-r--r--net/sunrpc/auth_null.c2
-rw-r--r--net/sunrpc/auth_unix.c1
-rw-r--r--net/sunrpc/rpc_pipe.c2
-rw-r--r--net/sunrpc/xdr.c28
-rw-r--r--net/sunrpc/xprt.c4
-rw-r--r--net/sunrpc/xprtsock.c11
-rw-r--r--security/inode.c2
59 files changed, 3029 insertions, 1489 deletions
diff --git a/Documentation/filesystems/automount-support.txt b/Documentation/filesystems/automount-support.txt
index 58c65a1713e5..7cac200e2a85 100644
--- a/Documentation/filesystems/automount-support.txt
+++ b/Documentation/filesystems/automount-support.txt
@@ -19,7 +19,7 @@ following procedure:
19 19
20 (2) Have the follow_link() op do the following steps: 20 (2) Have the follow_link() op do the following steps:
21 21
22 (a) Call do_kern_mount() to call the appropriate filesystem to set up a 22 (a) Call vfs_kern_mount() to call the appropriate filesystem to set up a
23 superblock and gain a vfsmount structure representing it. 23 superblock and gain a vfsmount structure representing it.
24 24
25 (b) Copy the nameidata provided as an argument and substitute the dentry 25 (b) Copy the nameidata provided as an argument and substitute the dentry
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 3cf945cc5b9a..695b90a17a68 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -569,7 +569,7 @@ static int create_special_files (void)
569 ignore_mount = 1; 569 ignore_mount = 1;
570 570
571 /* create the devices special file */ 571 /* create the devices special file */
572 retval = simple_pin_fs("usbfs", &usbfs_mount, &usbfs_mount_count); 572 retval = simple_pin_fs(&usb_fs_type, &usbfs_mount, &usbfs_mount_count);
573 if (retval) { 573 if (retval) {
574 err ("Unable to get usbfs mount"); 574 err ("Unable to get usbfs mount");
575 goto exit; 575 goto exit;
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 61c599b4a1e3..00c1f6baf870 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -253,11 +253,12 @@ static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt)
253} 253}
254 254
255static void 255static void
256v9fs_umount_begin(struct super_block *sb) 256v9fs_umount_begin(struct vfsmount *vfsmnt, int flags)
257{ 257{
258 struct v9fs_session_info *v9ses = sb->s_fs_info; 258 struct v9fs_session_info *v9ses = vfsmnt->mnt_sb->s_fs_info;
259 259
260 v9fs_session_cancel(v9ses); 260 if (flags & MNT_FORCE)
261 v9fs_session_cancel(v9ses);
261} 262}
262 263
263static struct super_operations v9fs_super_ops = { 264static struct super_operations v9fs_super_ops = {
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index 4e6eeb59b83c..7b6dc03caf44 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -210,7 +210,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
210 210
211 /* try and do the mount */ 211 /* try and do the mount */
212 kdebug("--- attempting mount %s -o %s ---", devname, options); 212 kdebug("--- attempting mount %s -o %s ---", devname, options);
213 mnt = do_kern_mount("afs", 0, devname, options); 213 mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options);
214 kdebug("--- mount result %p ---", mnt); 214 kdebug("--- mount result %p ---", mnt);
215 215
216 free_page((unsigned long) devname); 216 free_page((unsigned long) devname);
diff --git a/fs/afs/super.c b/fs/afs/super.c
index 53c56e7231ab..93a7821db0d7 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -48,7 +48,7 @@ static void afs_put_super(struct super_block *sb);
48 48
49static void afs_destroy_inode(struct inode *inode); 49static void afs_destroy_inode(struct inode *inode);
50 50
51static struct file_system_type afs_fs_type = { 51struct file_system_type afs_fs_type = {
52 .owner = THIS_MODULE, 52 .owner = THIS_MODULE,
53 .name = "afs", 53 .name = "afs",
54 .get_sb = afs_get_sb, 54 .get_sb = afs_get_sb,
diff --git a/fs/afs/super.h b/fs/afs/super.h
index ac11362f4e95..32de8cc6fae8 100644
--- a/fs/afs/super.h
+++ b/fs/afs/super.h
@@ -38,6 +38,8 @@ static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
38 return sb->s_fs_info; 38 return sb->s_fs_info;
39} 39}
40 40
41extern struct file_system_type afs_fs_type;
42
41#endif /* __KERNEL__ */ 43#endif /* __KERNEL__ */
42 44
43#endif /* _LINUX_AFS_SUPER_H */ 45#endif /* _LINUX_AFS_SUPER_H */
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index d73d75591a39..c0a909e1d290 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -55,6 +55,7 @@ typedef struct {
55} Node; 55} Node;
56 56
57static DEFINE_RWLOCK(entries_lock); 57static DEFINE_RWLOCK(entries_lock);
58static struct file_system_type bm_fs_type;
58static struct vfsmount *bm_mnt; 59static struct vfsmount *bm_mnt;
59static int entry_count; 60static int entry_count;
60 61
@@ -638,7 +639,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
638 if (!inode) 639 if (!inode)
639 goto out2; 640 goto out2;
640 641
641 err = simple_pin_fs("binfmt_misc", &bm_mnt, &entry_count); 642 err = simple_pin_fs(&bm_fs_type, &bm_mnt, &entry_count);
642 if (err) { 643 if (err) {
643 iput(inode); 644 iput(inode);
644 inode = NULL; 645 inode = NULL;
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index c262d8874ce9..3fdc2258f447 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -402,12 +402,14 @@ static struct quotactl_ops cifs_quotactl_ops = {
402#endif 402#endif
403 403
404#ifdef CONFIG_CIFS_EXPERIMENTAL 404#ifdef CONFIG_CIFS_EXPERIMENTAL
405static void cifs_umount_begin(struct super_block * sblock) 405static void cifs_umount_begin(struct vfsmount * vfsmnt, int flags)
406{ 406{
407 struct cifs_sb_info *cifs_sb; 407 struct cifs_sb_info *cifs_sb;
408 struct cifsTconInfo * tcon; 408 struct cifsTconInfo * tcon;
409 409
410 cifs_sb = CIFS_SB(sblock); 410 if (!(flags & MNT_FORCE))
411 return;
412 cifs_sb = CIFS_SB(vfsmnt->mnt_sb);
411 if(cifs_sb == NULL) 413 if(cifs_sb == NULL)
412 return; 414 return;
413 415
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index f920d30478e5..be5d86ae56f0 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -118,7 +118,7 @@ static struct file_system_type configfs_fs_type = {
118 118
119int configfs_pin_fs(void) 119int configfs_pin_fs(void)
120{ 120{
121 return simple_pin_fs("configfs", &configfs_mount, 121 return simple_pin_fs(&configfs_fs_type, &configfs_mount,
122 &configfs_mnt_count); 122 &configfs_mnt_count);
123} 123}
124 124
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index b55b4ea9a676..90f9417181fd 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -199,7 +199,7 @@ struct dentry *debugfs_create_file(const char *name, mode_t mode,
199 199
200 pr_debug("debugfs: creating file '%s'\n",name); 200 pr_debug("debugfs: creating file '%s'\n",name);
201 201
202 error = simple_pin_fs("debugfs", &debugfs_mount, &debugfs_mount_count); 202 error = simple_pin_fs(&debug_fs_type, &debugfs_mount, &debugfs_mount_count);
203 if (error) 203 if (error)
204 goto exit; 204 goto exit;
205 205
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 7627022446b2..13ebe5780c93 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -195,9 +195,10 @@ struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
195 return inode; 195 return inode;
196} 196}
197 197
198static void fuse_umount_begin(struct super_block *sb) 198static void fuse_umount_begin(struct vfsmount *vfsmnt, int flags)
199{ 199{
200 fuse_abort_conn(get_fuse_conn_super(sb)); 200 if (flags & MNT_FORCE)
201 fuse_abort_conn(get_fuse_conn_super(vfsmnt->mnt_sb));
201} 202}
202 203
203static void fuse_put_super(struct super_block *sb) 204static void fuse_put_super(struct super_block *sb)
diff --git a/fs/libfs.c b/fs/libfs.c
index 7145ba7a48d0..4a3ec9ad8bed 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -424,13 +424,13 @@ out:
424 424
425static DEFINE_SPINLOCK(pin_fs_lock); 425static DEFINE_SPINLOCK(pin_fs_lock);
426 426
427int simple_pin_fs(char *name, struct vfsmount **mount, int *count) 427int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *count)
428{ 428{
429 struct vfsmount *mnt = NULL; 429 struct vfsmount *mnt = NULL;
430 spin_lock(&pin_fs_lock); 430 spin_lock(&pin_fs_lock);
431 if (unlikely(!*mount)) { 431 if (unlikely(!*mount)) {
432 spin_unlock(&pin_fs_lock); 432 spin_unlock(&pin_fs_lock);
433 mnt = do_kern_mount(name, 0, name, NULL); 433 mnt = vfs_kern_mount(type, 0, type->name, NULL);
434 if (IS_ERR(mnt)) 434 if (IS_ERR(mnt))
435 return PTR_ERR(mnt); 435 return PTR_ERR(mnt);
436 spin_lock(&pin_fs_lock); 436 spin_lock(&pin_fs_lock);
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
index bce744468708..52774feab93f 100644
--- a/fs/lockd/clntlock.c
+++ b/fs/lockd/clntlock.c
@@ -147,11 +147,10 @@ u32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock)
147 * Someone has sent us an SM_NOTIFY. Ensure we bind to the new port number, 147 * Someone has sent us an SM_NOTIFY. Ensure we bind to the new port number,
148 * that we mark locks for reclaiming, and that we bump the pseudo NSM state. 148 * that we mark locks for reclaiming, and that we bump the pseudo NSM state.
149 */ 149 */
150static inline 150static void nlmclnt_prepare_reclaim(struct nlm_host *host)
151void nlmclnt_prepare_reclaim(struct nlm_host *host, u32 newstate)
152{ 151{
152 down_write(&host->h_rwsem);
153 host->h_monitored = 0; 153 host->h_monitored = 0;
154 host->h_nsmstate = newstate;
155 host->h_state++; 154 host->h_state++;
156 host->h_nextrebind = 0; 155 host->h_nextrebind = 0;
157 nlm_rebind_host(host); 156 nlm_rebind_host(host);
@@ -164,6 +163,13 @@ void nlmclnt_prepare_reclaim(struct nlm_host *host, u32 newstate)
164 dprintk("NLM: reclaiming locks for host %s", host->h_name); 163 dprintk("NLM: reclaiming locks for host %s", host->h_name);
165} 164}
166 165
166static void nlmclnt_finish_reclaim(struct nlm_host *host)
167{
168 host->h_reclaiming = 0;
169 up_write(&host->h_rwsem);
170 dprintk("NLM: done reclaiming locks for host %s", host->h_name);
171}
172
167/* 173/*
168 * Reclaim all locks on server host. We do this by spawning a separate 174 * Reclaim all locks on server host. We do this by spawning a separate
169 * reclaimer thread. 175 * reclaimer thread.
@@ -171,12 +177,10 @@ void nlmclnt_prepare_reclaim(struct nlm_host *host, u32 newstate)
171void 177void
172nlmclnt_recovery(struct nlm_host *host, u32 newstate) 178nlmclnt_recovery(struct nlm_host *host, u32 newstate)
173{ 179{
174 if (host->h_reclaiming++) { 180 if (host->h_nsmstate == newstate)
175 if (host->h_nsmstate == newstate) 181 return;
176 return; 182 host->h_nsmstate = newstate;
177 nlmclnt_prepare_reclaim(host, newstate); 183 if (!host->h_reclaiming++) {
178 } else {
179 nlmclnt_prepare_reclaim(host, newstate);
180 nlm_get_host(host); 184 nlm_get_host(host);
181 __module_get(THIS_MODULE); 185 __module_get(THIS_MODULE);
182 if (kernel_thread(reclaimer, host, CLONE_KERNEL) < 0) 186 if (kernel_thread(reclaimer, host, CLONE_KERNEL) < 0)
@@ -190,6 +194,7 @@ reclaimer(void *ptr)
190 struct nlm_host *host = (struct nlm_host *) ptr; 194 struct nlm_host *host = (struct nlm_host *) ptr;
191 struct nlm_wait *block; 195 struct nlm_wait *block;
192 struct file_lock *fl, *next; 196 struct file_lock *fl, *next;
197 u32 nsmstate;
193 198
194 daemonize("%s-reclaim", host->h_name); 199 daemonize("%s-reclaim", host->h_name);
195 allow_signal(SIGKILL); 200 allow_signal(SIGKILL);
@@ -199,19 +204,25 @@ reclaimer(void *ptr)
199 lock_kernel(); 204 lock_kernel();
200 lockd_up(); 205 lockd_up();
201 206
207 nlmclnt_prepare_reclaim(host);
202 /* First, reclaim all locks that have been marked. */ 208 /* First, reclaim all locks that have been marked. */
203restart: 209restart:
210 nsmstate = host->h_nsmstate;
204 list_for_each_entry_safe(fl, next, &host->h_reclaim, fl_u.nfs_fl.list) { 211 list_for_each_entry_safe(fl, next, &host->h_reclaim, fl_u.nfs_fl.list) {
205 list_del_init(&fl->fl_u.nfs_fl.list); 212 list_del_init(&fl->fl_u.nfs_fl.list);
206 213
207 if (signalled()) 214 if (signalled())
208 continue; 215 continue;
209 if (nlmclnt_reclaim(host, fl) == 0) 216 if (nlmclnt_reclaim(host, fl) != 0)
210 list_add_tail(&fl->fl_u.nfs_fl.list, &host->h_granted); 217 continue;
211 goto restart; 218 list_add_tail(&fl->fl_u.nfs_fl.list, &host->h_granted);
219 if (host->h_nsmstate != nsmstate) {
220 /* Argh! The server rebooted again! */
221 list_splice_init(&host->h_granted, &host->h_reclaim);
222 goto restart;
223 }
212 } 224 }
213 225 nlmclnt_finish_reclaim(host);
214 host->h_reclaiming = 0;
215 226
216 /* Now, wake up all processes that sleep on a blocked lock */ 227 /* Now, wake up all processes that sleep on a blocked lock */
217 list_for_each_entry(block, &nlm_blocked, b_list) { 228 list_for_each_entry(block, &nlm_blocked, b_list) {
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index f96e38155b5c..4db62098d3f4 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -508,7 +508,10 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
508 } 508 }
509 509
510 block = nlmclnt_prepare_block(host, fl); 510 block = nlmclnt_prepare_block(host, fl);
511again:
511 for(;;) { 512 for(;;) {
513 /* Reboot protection */
514 fl->fl_u.nfs_fl.state = host->h_state;
512 status = nlmclnt_call(req, NLMPROC_LOCK); 515 status = nlmclnt_call(req, NLMPROC_LOCK);
513 if (status < 0) 516 if (status < 0)
514 goto out_unblock; 517 goto out_unblock;
@@ -531,10 +534,16 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
531 } 534 }
532 535
533 if (resp->status == NLM_LCK_GRANTED) { 536 if (resp->status == NLM_LCK_GRANTED) {
534 fl->fl_u.nfs_fl.state = host->h_state; 537 down_read(&host->h_rwsem);
538 /* Check whether or not the server has rebooted */
539 if (fl->fl_u.nfs_fl.state != host->h_state) {
540 up_read(&host->h_rwsem);
541 goto again;
542 }
535 fl->fl_flags |= FL_SLEEP; 543 fl->fl_flags |= FL_SLEEP;
536 /* Ensure the resulting lock will get added to granted list */ 544 /* Ensure the resulting lock will get added to granted list */
537 do_vfs_lock(fl); 545 do_vfs_lock(fl);
546 up_read(&host->h_rwsem);
538 } 547 }
539 status = nlm_stat_to_errno(resp->status); 548 status = nlm_stat_to_errno(resp->status);
540out_unblock: 549out_unblock:
@@ -596,6 +605,7 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
596static int 605static int
597nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl) 606nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
598{ 607{
608 struct nlm_host *host = req->a_host;
599 struct nlm_res *resp = &req->a_res; 609 struct nlm_res *resp = &req->a_res;
600 int status; 610 int status;
601 611
@@ -604,7 +614,9 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
604 * request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either 614 * request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either
605 * case, we want to unlock. 615 * case, we want to unlock.
606 */ 616 */
617 down_read(&host->h_rwsem);
607 do_vfs_lock(fl); 618 do_vfs_lock(fl);
619 up_read(&host->h_rwsem);
608 620
609 if (req->a_flags & RPC_TASK_ASYNC) 621 if (req->a_flags & RPC_TASK_ASYNC)
610 return nlm_async_call(req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops); 622 return nlm_async_call(req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 729ac427d359..38b0e8a1aec0 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -112,11 +112,12 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
112 host->h_version = version; 112 host->h_version = version;
113 host->h_proto = proto; 113 host->h_proto = proto;
114 host->h_rpcclnt = NULL; 114 host->h_rpcclnt = NULL;
115 init_MUTEX(&host->h_sema); 115 mutex_init(&host->h_mutex);
116 host->h_nextrebind = jiffies + NLM_HOST_REBIND; 116 host->h_nextrebind = jiffies + NLM_HOST_REBIND;
117 host->h_expires = jiffies + NLM_HOST_EXPIRE; 117 host->h_expires = jiffies + NLM_HOST_EXPIRE;
118 atomic_set(&host->h_count, 1); 118 atomic_set(&host->h_count, 1);
119 init_waitqueue_head(&host->h_gracewait); 119 init_waitqueue_head(&host->h_gracewait);
120 init_rwsem(&host->h_rwsem);
120 host->h_state = 0; /* pseudo NSM state */ 121 host->h_state = 0; /* pseudo NSM state */
121 host->h_nsmstate = 0; /* real NSM state */ 122 host->h_nsmstate = 0; /* real NSM state */
122 host->h_server = server; 123 host->h_server = server;
@@ -172,7 +173,7 @@ nlm_bind_host(struct nlm_host *host)
172 (unsigned)ntohl(host->h_addr.sin_addr.s_addr)); 173 (unsigned)ntohl(host->h_addr.sin_addr.s_addr));
173 174
174 /* Lock host handle */ 175 /* Lock host handle */
175 down(&host->h_sema); 176 mutex_lock(&host->h_mutex);
176 177
177 /* If we've already created an RPC client, check whether 178 /* If we've already created an RPC client, check whether
178 * RPC rebind is required 179 * RPC rebind is required
@@ -204,12 +205,12 @@ nlm_bind_host(struct nlm_host *host)
204 host->h_rpcclnt = clnt; 205 host->h_rpcclnt = clnt;
205 } 206 }
206 207
207 up(&host->h_sema); 208 mutex_unlock(&host->h_mutex);
208 return clnt; 209 return clnt;
209 210
210forgetit: 211forgetit:
211 printk("lockd: couldn't create RPC handle for %s\n", host->h_name); 212 printk("lockd: couldn't create RPC handle for %s\n", host->h_name);
212 up(&host->h_sema); 213 mutex_unlock(&host->h_mutex);
213 return NULL; 214 return NULL;
214} 215}
215 216
diff --git a/fs/namespace.c b/fs/namespace.c
index bf478addb852..6bb0b85293e7 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -576,8 +576,8 @@ static int do_umount(struct vfsmount *mnt, int flags)
576 */ 576 */
577 577
578 lock_kernel(); 578 lock_kernel();
579 if ((flags & MNT_FORCE) && sb->s_op->umount_begin) 579 if (sb->s_op->umount_begin)
580 sb->s_op->umount_begin(sb); 580 sb->s_op->umount_begin(mnt, flags);
581 unlock_kernel(); 581 unlock_kernel();
582 582
583 /* 583 /*
@@ -1163,13 +1163,46 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1163} 1163}
1164 1164
1165/* 1165/*
1166 * go through the vfsmounts we've just consigned to the graveyard to
1167 * - check that they're still dead
1168 * - delete the vfsmount from the appropriate namespace under lock
1169 * - dispose of the corpse
1170 */
1171static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
1172{
1173 struct namespace *namespace;
1174 struct vfsmount *mnt;
1175
1176 while (!list_empty(graveyard)) {
1177 LIST_HEAD(umounts);
1178 mnt = list_entry(graveyard->next, struct vfsmount, mnt_expire);
1179 list_del_init(&mnt->mnt_expire);
1180
1181 /* don't do anything if the namespace is dead - all the
1182 * vfsmounts from it are going away anyway */
1183 namespace = mnt->mnt_namespace;
1184 if (!namespace || !namespace->root)
1185 continue;
1186 get_namespace(namespace);
1187
1188 spin_unlock(&vfsmount_lock);
1189 down_write(&namespace_sem);
1190 expire_mount(mnt, mounts, &umounts);
1191 up_write(&namespace_sem);
1192 release_mounts(&umounts);
1193 mntput(mnt);
1194 put_namespace(namespace);
1195 spin_lock(&vfsmount_lock);
1196 }
1197}
1198
1199/*
1166 * process a list of expirable mountpoints with the intent of discarding any 1200 * process a list of expirable mountpoints with the intent of discarding any
1167 * mountpoints that aren't in use and haven't been touched since last we came 1201 * mountpoints that aren't in use and haven't been touched since last we came
1168 * here 1202 * here
1169 */ 1203 */
1170void mark_mounts_for_expiry(struct list_head *mounts) 1204void mark_mounts_for_expiry(struct list_head *mounts)
1171{ 1205{
1172 struct namespace *namespace;
1173 struct vfsmount *mnt, *next; 1206 struct vfsmount *mnt, *next;
1174 LIST_HEAD(graveyard); 1207 LIST_HEAD(graveyard);
1175 1208
@@ -1193,38 +1226,79 @@ void mark_mounts_for_expiry(struct list_head *mounts)
1193 list_move(&mnt->mnt_expire, &graveyard); 1226 list_move(&mnt->mnt_expire, &graveyard);
1194 } 1227 }
1195 1228
1196 /* 1229 expire_mount_list(&graveyard, mounts);
1197 * go through the vfsmounts we've just consigned to the graveyard to
1198 * - check that they're still dead
1199 * - delete the vfsmount from the appropriate namespace under lock
1200 * - dispose of the corpse
1201 */
1202 while (!list_empty(&graveyard)) {
1203 LIST_HEAD(umounts);
1204 mnt = list_entry(graveyard.next, struct vfsmount, mnt_expire);
1205 list_del_init(&mnt->mnt_expire);
1206 1230
1207 /* don't do anything if the namespace is dead - all the 1231 spin_unlock(&vfsmount_lock);
1208 * vfsmounts from it are going away anyway */ 1232}
1209 namespace = mnt->mnt_namespace; 1233
1210 if (!namespace || !namespace->root) 1234EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
1235
1236/*
1237 * Ripoff of 'select_parent()'
1238 *
1239 * search the list of submounts for a given mountpoint, and move any
1240 * shrinkable submounts to the 'graveyard' list.
1241 */
1242static int select_submounts(struct vfsmount *parent, struct list_head *graveyard)
1243{
1244 struct vfsmount *this_parent = parent;
1245 struct list_head *next;
1246 int found = 0;
1247
1248repeat:
1249 next = this_parent->mnt_mounts.next;
1250resume:
1251 while (next != &this_parent->mnt_mounts) {
1252 struct list_head *tmp = next;
1253 struct vfsmount *mnt = list_entry(tmp, struct vfsmount, mnt_child);
1254
1255 next = tmp->next;
1256 if (!(mnt->mnt_flags & MNT_SHRINKABLE))
1211 continue; 1257 continue;
1212 get_namespace(namespace); 1258 /*
1259 * Descend a level if the d_mounts list is non-empty.
1260 */
1261 if (!list_empty(&mnt->mnt_mounts)) {
1262 this_parent = mnt;
1263 goto repeat;
1264 }
1213 1265
1214 spin_unlock(&vfsmount_lock); 1266 if (!propagate_mount_busy(mnt, 1)) {
1215 down_write(&namespace_sem); 1267 mntget(mnt);
1216 expire_mount(mnt, mounts, &umounts); 1268 list_move_tail(&mnt->mnt_expire, graveyard);
1217 up_write(&namespace_sem); 1269 found++;
1218 release_mounts(&umounts); 1270 }
1219 mntput(mnt);
1220 put_namespace(namespace);
1221 spin_lock(&vfsmount_lock);
1222 } 1271 }
1272 /*
1273 * All done at this level ... ascend and resume the search
1274 */
1275 if (this_parent != parent) {
1276 next = this_parent->mnt_child.next;
1277 this_parent = this_parent->mnt_parent;
1278 goto resume;
1279 }
1280 return found;
1281}
1282
1283/*
1284 * process a list of expirable mountpoints with the intent of discarding any
1285 * submounts of a specific parent mountpoint
1286 */
1287void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts)
1288{
1289 LIST_HEAD(graveyard);
1290 int found;
1291
1292 spin_lock(&vfsmount_lock);
1293
1294 /* extract submounts of 'mountpoint' from the expiration list */
1295 while ((found = select_submounts(mountpoint, &graveyard)) != 0)
1296 expire_mount_list(&graveyard, mounts);
1223 1297
1224 spin_unlock(&vfsmount_lock); 1298 spin_unlock(&vfsmount_lock);
1225} 1299}
1226 1300
1227EXPORT_SYMBOL_GPL(mark_mounts_for_expiry); 1301EXPORT_SYMBOL_GPL(shrink_submounts);
1228 1302
1229/* 1303/*
1230 * Some copy_from_user() implementations do not return the exact number of 1304 * Some copy_from_user() implementations do not return the exact number of
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index ec61fd56a1a9..0b572a0c1967 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -4,14 +4,16 @@
4 4
5obj-$(CONFIG_NFS_FS) += nfs.o 5obj-$(CONFIG_NFS_FS) += nfs.o
6 6
7nfs-y := dir.o file.o inode.o nfs2xdr.o pagelist.o \ 7nfs-y := dir.o file.o inode.o super.o nfs2xdr.o pagelist.o \
8 proc.o read.o symlink.o unlink.o write.o 8 proc.o read.o symlink.o unlink.o write.o \
9 namespace.o
9nfs-$(CONFIG_ROOT_NFS) += nfsroot.o mount_clnt.o 10nfs-$(CONFIG_ROOT_NFS) += nfsroot.o mount_clnt.o
10nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o 11nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o
11nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o 12nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o
12nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ 13nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \
13 delegation.o idmap.o \ 14 delegation.o idmap.o \
14 callback.o callback_xdr.o callback_proc.o 15 callback.o callback_xdr.o callback_proc.o \
16 nfs4namespace.o
15nfs-$(CONFIG_NFS_DIRECTIO) += direct.o 17nfs-$(CONFIG_NFS_DIRECTIO) += direct.o
16nfs-$(CONFIG_SYSCTL) += sysctl.o 18nfs-$(CONFIG_SYSCTL) += sysctl.o
17nfs-objs := $(nfs-y) 19nfs-objs := $(nfs-y)
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 90c95adc8c1b..d53f8c6a9ecb 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -182,8 +182,6 @@ static int nfs_callback_authenticate(struct svc_rqst *rqstp)
182/* 182/*
183 * Define NFS4 callback program 183 * Define NFS4 callback program
184 */ 184 */
185extern struct svc_version nfs4_callback_version1;
186
187static struct svc_version *nfs4_callback_version[] = { 185static struct svc_version *nfs4_callback_version[] = {
188 [1] = &nfs4_callback_version1, 186 [1] = &nfs4_callback_version1,
189}; 187};
diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
index 05c38cf40b69..c92991328d9a 100644
--- a/fs/nfs/callback_xdr.c
+++ b/fs/nfs/callback_xdr.c
@@ -202,7 +202,7 @@ static unsigned decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xd
202 status = decode_fh(xdr, &args->fh); 202 status = decode_fh(xdr, &args->fh);
203out: 203out:
204 dprintk("%s: exit with status = %d\n", __FUNCTION__, status); 204 dprintk("%s: exit with status = %d\n", __FUNCTION__, status);
205 return 0; 205 return status;
206} 206}
207 207
208static unsigned encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 208static unsigned encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index cae74dd4c7f5..3ddda6f7ecc2 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -528,7 +528,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
528 528
529 lock_kernel(); 529 lock_kernel();
530 530
531 res = nfs_revalidate_inode(NFS_SERVER(inode), inode); 531 res = nfs_revalidate_mapping(inode, filp->f_mapping);
532 if (res < 0) { 532 if (res < 0) {
533 unlock_kernel(); 533 unlock_kernel();
534 return res; 534 return res;
@@ -868,6 +868,17 @@ int nfs_is_exclusive_create(struct inode *dir, struct nameidata *nd)
868 return (nd->intent.open.flags & O_EXCL) != 0; 868 return (nd->intent.open.flags & O_EXCL) != 0;
869} 869}
870 870
871static inline int nfs_reval_fsid(struct inode *dir,
872 struct nfs_fh *fh, struct nfs_fattr *fattr)
873{
874 struct nfs_server *server = NFS_SERVER(dir);
875
876 if (!nfs_fsid_equal(&server->fsid, &fattr->fsid))
877 /* Revalidate fsid on root dir */
878 return __nfs_revalidate_inode(server, dir->i_sb->s_root->d_inode);
879 return 0;
880}
881
871static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) 882static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
872{ 883{
873 struct dentry *res; 884 struct dentry *res;
@@ -900,6 +911,11 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
900 res = ERR_PTR(error); 911 res = ERR_PTR(error);
901 goto out_unlock; 912 goto out_unlock;
902 } 913 }
914 error = nfs_reval_fsid(dir, &fhandle, &fattr);
915 if (error < 0) {
916 res = ERR_PTR(error);
917 goto out_unlock;
918 }
903 inode = nfs_fhget(dentry->d_sb, &fhandle, &fattr); 919 inode = nfs_fhget(dentry->d_sb, &fhandle, &fattr);
904 res = (struct dentry *)inode; 920 res = (struct dentry *)inode;
905 if (IS_ERR(res)) 921 if (IS_ERR(res))
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 3c72b0c07283..402005c35ab3 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -892,7 +892,7 @@ out:
892 * nfs_init_directcache - create a slab cache for nfs_direct_req structures 892 * nfs_init_directcache - create a slab cache for nfs_direct_req structures
893 * 893 *
894 */ 894 */
895int nfs_init_directcache(void) 895int __init nfs_init_directcache(void)
896{ 896{
897 nfs_direct_cachep = kmem_cache_create("nfs_direct_cache", 897 nfs_direct_cachep = kmem_cache_create("nfs_direct_cache",
898 sizeof(struct nfs_direct_req), 898 sizeof(struct nfs_direct_req),
@@ -906,10 +906,10 @@ int nfs_init_directcache(void)
906} 906}
907 907
908/** 908/**
909 * nfs_init_directcache - destroy the slab cache for nfs_direct_req structures 909 * nfs_destroy_directcache - destroy the slab cache for nfs_direct_req structures
910 * 910 *
911 */ 911 */
912void nfs_destroy_directcache(void) 912void __exit nfs_destroy_directcache(void)
913{ 913{
914 if (kmem_cache_destroy(nfs_direct_cachep)) 914 if (kmem_cache_destroy(nfs_direct_cachep))
915 printk(KERN_INFO "nfs_direct_cache: not all structures were freed\n"); 915 printk(KERN_INFO "nfs_direct_cache: not all structures were freed\n");
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index fade02c15e6e..106ef0dec04d 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -127,23 +127,6 @@ nfs_file_release(struct inode *inode, struct file *filp)
127} 127}
128 128
129/** 129/**
130 * nfs_revalidate_file - Revalidate the page cache & related metadata
131 * @inode - pointer to inode struct
132 * @file - pointer to file
133 */
134static int nfs_revalidate_file(struct inode *inode, struct file *filp)
135{
136 struct nfs_inode *nfsi = NFS_I(inode);
137 int retval = 0;
138
139 if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR))
140 || nfs_attribute_timeout(inode))
141 retval = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
142 nfs_revalidate_mapping(inode, filp->f_mapping);
143 return 0;
144}
145
146/**
147 * nfs_revalidate_size - Revalidate the file size 130 * nfs_revalidate_size - Revalidate the file size
148 * @inode - pointer to inode struct 131 * @inode - pointer to inode struct
149 * @file - pointer to struct file 132 * @file - pointer to struct file
@@ -228,7 +211,7 @@ nfs_file_read(struct kiocb *iocb, char __user * buf, size_t count, loff_t pos)
228 dentry->d_parent->d_name.name, dentry->d_name.name, 211 dentry->d_parent->d_name.name, dentry->d_name.name,
229 (unsigned long) count, (unsigned long) pos); 212 (unsigned long) count, (unsigned long) pos);
230 213
231 result = nfs_revalidate_file(inode, iocb->ki_filp); 214 result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
232 nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count); 215 nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count);
233 if (!result) 216 if (!result)
234 result = generic_file_aio_read(iocb, buf, count, pos); 217 result = generic_file_aio_read(iocb, buf, count, pos);
@@ -247,7 +230,7 @@ nfs_file_sendfile(struct file *filp, loff_t *ppos, size_t count,
247 dentry->d_parent->d_name.name, dentry->d_name.name, 230 dentry->d_parent->d_name.name, dentry->d_name.name,
248 (unsigned long) count, (unsigned long long) *ppos); 231 (unsigned long) count, (unsigned long long) *ppos);
249 232
250 res = nfs_revalidate_file(inode, filp); 233 res = nfs_revalidate_mapping(inode, filp->f_mapping);
251 if (!res) 234 if (!res)
252 res = generic_file_sendfile(filp, ppos, count, actor, target); 235 res = generic_file_sendfile(filp, ppos, count, actor, target);
253 return res; 236 return res;
@@ -263,7 +246,7 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
263 dfprintk(VFS, "nfs: mmap(%s/%s)\n", 246 dfprintk(VFS, "nfs: mmap(%s/%s)\n",
264 dentry->d_parent->d_name.name, dentry->d_name.name); 247 dentry->d_parent->d_name.name, dentry->d_name.name);
265 248
266 status = nfs_revalidate_file(inode, file); 249 status = nfs_revalidate_mapping(inode, file->f_mapping);
267 if (!status) 250 if (!status)
268 status = generic_file_mmap(file, vma); 251 status = generic_file_mmap(file, vma);
269 return status; 252 return status;
@@ -320,7 +303,11 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offse
320 303
321static void nfs_invalidate_page(struct page *page, unsigned long offset) 304static void nfs_invalidate_page(struct page *page, unsigned long offset)
322{ 305{
323 /* FIXME: we really should cancel any unstarted writes on this page */ 306 struct inode *inode = page->mapping->host;
307
308 /* Cancel any unstarted writes on this page */
309 if (offset == 0)
310 nfs_sync_inode_wait(inode, page->index, 1, FLUSH_INVALIDATE);
324} 311}
325 312
326static int nfs_release_page(struct page *page, gfp_t gfp) 313static int nfs_release_page(struct page *page, gfp_t gfp)
@@ -373,7 +360,6 @@ nfs_file_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t
373 if (result) 360 if (result)
374 goto out; 361 goto out;
375 } 362 }
376 nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
377 363
378 result = count; 364 result = count;
379 if (!count) 365 if (!count)
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 3fab5b0cfc5a..b81e7ed3c902 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -47,7 +47,6 @@
47#include <linux/workqueue.h> 47#include <linux/workqueue.h>
48#include <linux/sunrpc/rpc_pipe_fs.h> 48#include <linux/sunrpc/rpc_pipe_fs.h>
49 49
50#include <linux/nfs_fs_sb.h>
51#include <linux/nfs_fs.h> 50#include <linux/nfs_fs.h>
52 51
53#include <linux/nfs_idmap.h> 52#include <linux/nfs_idmap.h>
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index d0b991a92327..24a7139d3449 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -36,6 +36,8 @@
36#include <linux/mount.h> 36#include <linux/mount.h>
37#include <linux/nfs_idmap.h> 37#include <linux/nfs_idmap.h>
38#include <linux/vfs.h> 38#include <linux/vfs.h>
39#include <linux/inet.h>
40#include <linux/nfs_xdr.h>
39 41
40#include <asm/system.h> 42#include <asm/system.h>
41#include <asm/uaccess.h> 43#include <asm/uaccess.h>
@@ -44,89 +46,17 @@
44#include "callback.h" 46#include "callback.h"
45#include "delegation.h" 47#include "delegation.h"
46#include "iostat.h" 48#include "iostat.h"
49#include "internal.h"
47 50
48#define NFSDBG_FACILITY NFSDBG_VFS 51#define NFSDBG_FACILITY NFSDBG_VFS
49#define NFS_PARANOIA 1 52#define NFS_PARANOIA 1
50 53
51/* Maximum number of readahead requests
52 * FIXME: this should really be a sysctl so that users may tune it to suit
53 * their needs. People that do NFS over a slow network, might for
54 * instance want to reduce it to something closer to 1 for improved
55 * interactive response.
56 */
57#define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
58
59static void nfs_invalidate_inode(struct inode *); 54static void nfs_invalidate_inode(struct inode *);
60static int nfs_update_inode(struct inode *, struct nfs_fattr *); 55static int nfs_update_inode(struct inode *, struct nfs_fattr *);
61 56
62static struct inode *nfs_alloc_inode(struct super_block *sb);
63static void nfs_destroy_inode(struct inode *);
64static int nfs_write_inode(struct inode *,int);
65static void nfs_delete_inode(struct inode *);
66static void nfs_clear_inode(struct inode *);
67static void nfs_umount_begin(struct super_block *);
68static int nfs_statfs(struct super_block *, struct kstatfs *);
69static int nfs_show_options(struct seq_file *, struct vfsmount *);
70static int nfs_show_stats(struct seq_file *, struct vfsmount *);
71static void nfs_zap_acl_cache(struct inode *); 57static void nfs_zap_acl_cache(struct inode *);
72 58
73static struct rpc_program nfs_program; 59static kmem_cache_t * nfs_inode_cachep;
74
75static struct super_operations nfs_sops = {
76 .alloc_inode = nfs_alloc_inode,
77 .destroy_inode = nfs_destroy_inode,
78 .write_inode = nfs_write_inode,
79 .delete_inode = nfs_delete_inode,
80 .statfs = nfs_statfs,
81 .clear_inode = nfs_clear_inode,
82 .umount_begin = nfs_umount_begin,
83 .show_options = nfs_show_options,
84 .show_stats = nfs_show_stats,
85};
86
87/*
88 * RPC cruft for NFS
89 */
90static struct rpc_stat nfs_rpcstat = {
91 .program = &nfs_program
92};
93static struct rpc_version * nfs_version[] = {
94 NULL,
95 NULL,
96 &nfs_version2,
97#if defined(CONFIG_NFS_V3)
98 &nfs_version3,
99#elif defined(CONFIG_NFS_V4)
100 NULL,
101#endif
102#if defined(CONFIG_NFS_V4)
103 &nfs_version4,
104#endif
105};
106
107static struct rpc_program nfs_program = {
108 .name = "nfs",
109 .number = NFS_PROGRAM,
110 .nrvers = ARRAY_SIZE(nfs_version),
111 .version = nfs_version,
112 .stats = &nfs_rpcstat,
113 .pipe_dir_name = "/nfs",
114};
115
116#ifdef CONFIG_NFS_V3_ACL
117static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
118static struct rpc_version * nfsacl_version[] = {
119 [3] = &nfsacl_version3,
120};
121
122struct rpc_program nfsacl_program = {
123 .name = "nfsacl",
124 .number = NFS_ACL_PROGRAM,
125 .nrvers = ARRAY_SIZE(nfsacl_version),
126 .version = nfsacl_version,
127 .stats = &nfsacl_rpcstat,
128};
129#endif /* CONFIG_NFS_V3_ACL */
130 60
131static inline unsigned long 61static inline unsigned long
132nfs_fattr_to_ino_t(struct nfs_fattr *fattr) 62nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
@@ -134,8 +64,7 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
134 return nfs_fileid_to_ino_t(fattr->fileid); 64 return nfs_fileid_to_ino_t(fattr->fileid);
135} 65}
136 66
137static int 67int nfs_write_inode(struct inode *inode, int sync)
138nfs_write_inode(struct inode *inode, int sync)
139{ 68{
140 int flags = sync ? FLUSH_SYNC : 0; 69 int flags = sync ? FLUSH_SYNC : 0;
141 int ret; 70 int ret;
@@ -146,31 +75,15 @@ nfs_write_inode(struct inode *inode, int sync)
146 return 0; 75 return 0;
147} 76}
148 77
149static void 78void nfs_clear_inode(struct inode *inode)
150nfs_delete_inode(struct inode * inode)
151{ 79{
152 dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 80 struct nfs_inode *nfsi = NFS_I(inode);
153 81 struct rpc_cred *cred;
154 truncate_inode_pages(&inode->i_data, 0);
155 82
156 nfs_wb_all(inode);
157 /* 83 /*
158 * The following should never happen... 84 * The following should never happen...
159 */ 85 */
160 if (nfs_have_writebacks(inode)) { 86 BUG_ON(nfs_have_writebacks(inode));
161 printk(KERN_ERR "nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino);
162 }
163
164 clear_inode(inode);
165}
166
167static void
168nfs_clear_inode(struct inode *inode)
169{
170 struct nfs_inode *nfsi = NFS_I(inode);
171 struct rpc_cred *cred;
172
173 nfs_wb_all(inode);
174 BUG_ON (!list_empty(&nfsi->open_files)); 87 BUG_ON (!list_empty(&nfsi->open_files));
175 nfs_zap_acl_cache(inode); 88 nfs_zap_acl_cache(inode);
176 cred = nfsi->cache_access.cred; 89 cred = nfsi->cache_access.cred;
@@ -179,554 +92,6 @@ nfs_clear_inode(struct inode *inode)
179 BUG_ON(atomic_read(&nfsi->data_updates) != 0); 92 BUG_ON(atomic_read(&nfsi->data_updates) != 0);
180} 93}
181 94
182void
183nfs_umount_begin(struct super_block *sb)
184{
185 struct rpc_clnt *rpc = NFS_SB(sb)->client;
186
187 /* -EIO all pending I/O */
188 if (!IS_ERR(rpc))
189 rpc_killall_tasks(rpc);
190 rpc = NFS_SB(sb)->client_acl;
191 if (!IS_ERR(rpc))
192 rpc_killall_tasks(rpc);
193}
194
195
196static inline unsigned long
197nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
198{
199 /* make sure blocksize is a power of two */
200 if ((bsize & (bsize - 1)) || nrbitsp) {
201 unsigned char nrbits;
202
203 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
204 ;
205 bsize = 1 << nrbits;
206 if (nrbitsp)
207 *nrbitsp = nrbits;
208 }
209
210 return bsize;
211}
212
213/*
214 * Calculate the number of 512byte blocks used.
215 */
216static inline unsigned long
217nfs_calc_block_size(u64 tsize)
218{
219 loff_t used = (tsize + 511) >> 9;
220 return (used > ULONG_MAX) ? ULONG_MAX : used;
221}
222
223/*
224 * Compute and set NFS server blocksize
225 */
226static inline unsigned long
227nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
228{
229 if (bsize < NFS_MIN_FILE_IO_SIZE)
230 bsize = NFS_DEF_FILE_IO_SIZE;
231 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
232 bsize = NFS_MAX_FILE_IO_SIZE;
233
234 return nfs_block_bits(bsize, nrbitsp);
235}
236
237/*
238 * Obtain the root inode of the file system.
239 */
240static struct inode *
241nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo)
242{
243 struct nfs_server *server = NFS_SB(sb);
244 int error;
245
246 error = server->rpc_ops->getroot(server, rootfh, fsinfo);
247 if (error < 0) {
248 dprintk("nfs_get_root: getattr error = %d\n", -error);
249 return ERR_PTR(error);
250 }
251
252 return nfs_fhget(sb, rootfh, fsinfo->fattr);
253}
254
255/*
256 * Do NFS version-independent mount processing, and sanity checking
257 */
258static int
259nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
260{
261 struct nfs_server *server;
262 struct inode *root_inode;
263 struct nfs_fattr fattr;
264 struct nfs_fsinfo fsinfo = {
265 .fattr = &fattr,
266 };
267 struct nfs_pathconf pathinfo = {
268 .fattr = &fattr,
269 };
270 int no_root_error = 0;
271 unsigned long max_rpc_payload;
272
273 /* We probably want something more informative here */
274 snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
275
276 server = NFS_SB(sb);
277
278 sb->s_magic = NFS_SUPER_MAGIC;
279
280 server->io_stats = nfs_alloc_iostats();
281 if (server->io_stats == NULL)
282 return -ENOMEM;
283
284 root_inode = nfs_get_root(sb, &server->fh, &fsinfo);
285 /* Did getting the root inode fail? */
286 if (IS_ERR(root_inode)) {
287 no_root_error = PTR_ERR(root_inode);
288 goto out_no_root;
289 }
290 sb->s_root = d_alloc_root(root_inode);
291 if (!sb->s_root) {
292 no_root_error = -ENOMEM;
293 goto out_no_root;
294 }
295 sb->s_root->d_op = server->rpc_ops->dentry_ops;
296
297 /* mount time stamp, in seconds */
298 server->mount_time = jiffies;
299
300 /* Get some general file system info */
301 if (server->namelen == 0 &&
302 server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0)
303 server->namelen = pathinfo.max_namelen;
304 /* Work out a lot of parameters */
305 if (server->rsize == 0)
306 server->rsize = nfs_block_size(fsinfo.rtpref, NULL);
307 if (server->wsize == 0)
308 server->wsize = nfs_block_size(fsinfo.wtpref, NULL);
309
310 if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax)
311 server->rsize = nfs_block_size(fsinfo.rtmax, NULL);
312 if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax)
313 server->wsize = nfs_block_size(fsinfo.wtmax, NULL);
314
315 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
316 if (server->rsize > max_rpc_payload)
317 server->rsize = max_rpc_payload;
318 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
319 server->rsize = NFS_MAX_FILE_IO_SIZE;
320 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
321
322 if (server->wsize > max_rpc_payload)
323 server->wsize = max_rpc_payload;
324 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
325 server->wsize = NFS_MAX_FILE_IO_SIZE;
326 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
327
328 if (sb->s_blocksize == 0)
329 sb->s_blocksize = nfs_block_bits(server->wsize,
330 &sb->s_blocksize_bits);
331 server->wtmult = nfs_block_bits(fsinfo.wtmult, NULL);
332
333 server->dtsize = nfs_block_size(fsinfo.dtpref, NULL);
334 if (server->dtsize > PAGE_CACHE_SIZE)
335 server->dtsize = PAGE_CACHE_SIZE;
336 if (server->dtsize > server->rsize)
337 server->dtsize = server->rsize;
338
339 if (server->flags & NFS_MOUNT_NOAC) {
340 server->acregmin = server->acregmax = 0;
341 server->acdirmin = server->acdirmax = 0;
342 sb->s_flags |= MS_SYNCHRONOUS;
343 }
344 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
345
346 sb->s_maxbytes = fsinfo.maxfilesize;
347 if (sb->s_maxbytes > MAX_LFS_FILESIZE)
348 sb->s_maxbytes = MAX_LFS_FILESIZE;
349
350 server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
351 server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
352
353 /* We're airborne Set socket buffersize */
354 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
355 return 0;
356 /* Yargs. It didn't work out. */
357out_no_root:
358 dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error);
359 if (!IS_ERR(root_inode))
360 iput(root_inode);
361 return no_root_error;
362}
363
364static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, unsigned int timeo, unsigned int retrans)
365{
366 to->to_initval = timeo * HZ / 10;
367 to->to_retries = retrans;
368 if (!to->to_retries)
369 to->to_retries = 2;
370
371 switch (proto) {
372 case IPPROTO_TCP:
373 if (!to->to_initval)
374 to->to_initval = 60 * HZ;
375 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
376 to->to_initval = NFS_MAX_TCP_TIMEOUT;
377 to->to_increment = to->to_initval;
378 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
379 to->to_exponential = 0;
380 break;
381 case IPPROTO_UDP:
382 default:
383 if (!to->to_initval)
384 to->to_initval = 11 * HZ / 10;
385 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
386 to->to_initval = NFS_MAX_UDP_TIMEOUT;
387 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
388 to->to_exponential = 1;
389 break;
390 }
391}
392
393/*
394 * Create an RPC client handle.
395 */
396static struct rpc_clnt *
397nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
398{
399 struct rpc_timeout timeparms;
400 struct rpc_xprt *xprt = NULL;
401 struct rpc_clnt *clnt = NULL;
402 int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;
403
404 nfs_init_timeout_values(&timeparms, proto, data->timeo, data->retrans);
405
406 server->retrans_timeo = timeparms.to_initval;
407 server->retrans_count = timeparms.to_retries;
408
409 /* create transport and client */
410 xprt = xprt_create_proto(proto, &server->addr, &timeparms);
411 if (IS_ERR(xprt)) {
412 dprintk("%s: cannot create RPC transport. Error = %ld\n",
413 __FUNCTION__, PTR_ERR(xprt));
414 return (struct rpc_clnt *)xprt;
415 }
416 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
417 server->rpc_ops->version, data->pseudoflavor);
418 if (IS_ERR(clnt)) {
419 dprintk("%s: cannot create RPC client. Error = %ld\n",
420 __FUNCTION__, PTR_ERR(xprt));
421 goto out_fail;
422 }
423
424 clnt->cl_intr = 1;
425 clnt->cl_softrtry = 1;
426
427 return clnt;
428
429out_fail:
430 return clnt;
431}
432
433/*
434 * The way this works is that the mount process passes a structure
435 * in the data argument which contains the server's IP address
436 * and the root file handle obtained from the server's mount
437 * daemon. We stash these away in the private superblock fields.
438 */
439static int
440nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
441{
442 struct nfs_server *server;
443 rpc_authflavor_t authflavor;
444
445 server = NFS_SB(sb);
446 sb->s_blocksize_bits = 0;
447 sb->s_blocksize = 0;
448 if (data->bsize)
449 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
450 if (data->rsize)
451 server->rsize = nfs_block_size(data->rsize, NULL);
452 if (data->wsize)
453 server->wsize = nfs_block_size(data->wsize, NULL);
454 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
455
456 server->acregmin = data->acregmin*HZ;
457 server->acregmax = data->acregmax*HZ;
458 server->acdirmin = data->acdirmin*HZ;
459 server->acdirmax = data->acdirmax*HZ;
460
461 /* Start lockd here, before we might error out */
462 if (!(server->flags & NFS_MOUNT_NONLM))
463 lockd_up();
464
465 server->namelen = data->namlen;
466 server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL);
467 if (!server->hostname)
468 return -ENOMEM;
469 strcpy(server->hostname, data->hostname);
470
471 /* Check NFS protocol revision and initialize RPC op vector
472 * and file handle pool. */
473#ifdef CONFIG_NFS_V3
474 if (server->flags & NFS_MOUNT_VER3) {
475 server->rpc_ops = &nfs_v3_clientops;
476 server->caps |= NFS_CAP_READDIRPLUS;
477 } else {
478 server->rpc_ops = &nfs_v2_clientops;
479 }
480#else
481 server->rpc_ops = &nfs_v2_clientops;
482#endif
483
484 /* Fill in pseudoflavor for mount version < 5 */
485 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
486 data->pseudoflavor = RPC_AUTH_UNIX;
487 authflavor = data->pseudoflavor; /* save for sb_init() */
488 /* XXX maybe we want to add a server->pseudoflavor field */
489
490 /* Create RPC client handles */
491 server->client = nfs_create_client(server, data);
492 if (IS_ERR(server->client))
493 return PTR_ERR(server->client);
494 /* RFC 2623, sec 2.3.2 */
495 if (authflavor != RPC_AUTH_UNIX) {
496 struct rpc_auth *auth;
497
498 server->client_sys = rpc_clone_client(server->client);
499 if (IS_ERR(server->client_sys))
500 return PTR_ERR(server->client_sys);
501 auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys);
502 if (IS_ERR(auth))
503 return PTR_ERR(auth);
504 } else {
505 atomic_inc(&server->client->cl_count);
506 server->client_sys = server->client;
507 }
508 if (server->flags & NFS_MOUNT_VER3) {
509#ifdef CONFIG_NFS_V3_ACL
510 if (!(server->flags & NFS_MOUNT_NOACL)) {
511 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
512 /* No errors! Assume that Sun nfsacls are supported */
513 if (!IS_ERR(server->client_acl))
514 server->caps |= NFS_CAP_ACLS;
515 }
516#else
517 server->flags &= ~NFS_MOUNT_NOACL;
518#endif /* CONFIG_NFS_V3_ACL */
519 /*
520 * The VFS shouldn't apply the umask to mode bits. We will
521 * do so ourselves when necessary.
522 */
523 sb->s_flags |= MS_POSIXACL;
524 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
525 server->namelen = NFS3_MAXNAMLEN;
526 sb->s_time_gran = 1;
527 } else {
528 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
529 server->namelen = NFS2_MAXNAMLEN;
530 }
531
532 sb->s_op = &nfs_sops;
533 return nfs_sb_init(sb, authflavor);
534}
535
536static int
537nfs_statfs(struct super_block *sb, struct kstatfs *buf)
538{
539 struct nfs_server *server = NFS_SB(sb);
540 unsigned char blockbits;
541 unsigned long blockres;
542 struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode);
543 struct nfs_fattr fattr;
544 struct nfs_fsstat res = {
545 .fattr = &fattr,
546 };
547 int error;
548
549 lock_kernel();
550
551 error = server->rpc_ops->statfs(server, rootfh, &res);
552 buf->f_type = NFS_SUPER_MAGIC;
553 if (error < 0)
554 goto out_err;
555
556 /*
557 * Current versions of glibc do not correctly handle the
558 * case where f_frsize != f_bsize. Eventually we want to
559 * report the value of wtmult in this field.
560 */
561 buf->f_frsize = sb->s_blocksize;
562
563 /*
564 * On most *nix systems, f_blocks, f_bfree, and f_bavail
565 * are reported in units of f_frsize. Linux hasn't had
566 * an f_frsize field in its statfs struct until recently,
567 * thus historically Linux's sys_statfs reports these
568 * fields in units of f_bsize.
569 */
570 buf->f_bsize = sb->s_blocksize;
571 blockbits = sb->s_blocksize_bits;
572 blockres = (1 << blockbits) - 1;
573 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
574 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
575 buf->f_bavail = (res.abytes + blockres) >> blockbits;
576
577 buf->f_files = res.tfiles;
578 buf->f_ffree = res.afiles;
579
580 buf->f_namelen = server->namelen;
581 out:
582 unlock_kernel();
583 return 0;
584
585 out_err:
586 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
587 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
588 goto out;
589
590}
591
592static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
593{
594 static struct proc_nfs_info {
595 int flag;
596 char *str;
597 char *nostr;
598 } nfs_info[] = {
599 { NFS_MOUNT_SOFT, ",soft", ",hard" },
600 { NFS_MOUNT_INTR, ",intr", "" },
601 { NFS_MOUNT_NOCTO, ",nocto", "" },
602 { NFS_MOUNT_NOAC, ",noac", "" },
603 { NFS_MOUNT_NONLM, ",nolock", "" },
604 { NFS_MOUNT_NOACL, ",noacl", "" },
605 { 0, NULL, NULL }
606 };
607 struct proc_nfs_info *nfs_infop;
608 char buf[12];
609 char *proto;
610
611 seq_printf(m, ",vers=%d", nfss->rpc_ops->version);
612 seq_printf(m, ",rsize=%d", nfss->rsize);
613 seq_printf(m, ",wsize=%d", nfss->wsize);
614 if (nfss->acregmin != 3*HZ || showdefaults)
615 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
616 if (nfss->acregmax != 60*HZ || showdefaults)
617 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
618 if (nfss->acdirmin != 30*HZ || showdefaults)
619 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
620 if (nfss->acdirmax != 60*HZ || showdefaults)
621 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
622 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
623 if (nfss->flags & nfs_infop->flag)
624 seq_puts(m, nfs_infop->str);
625 else
626 seq_puts(m, nfs_infop->nostr);
627 }
628 switch (nfss->client->cl_xprt->prot) {
629 case IPPROTO_TCP:
630 proto = "tcp";
631 break;
632 case IPPROTO_UDP:
633 proto = "udp";
634 break;
635 default:
636 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
637 proto = buf;
638 }
639 seq_printf(m, ",proto=%s", proto);
640 seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ);
641 seq_printf(m, ",retrans=%u", nfss->retrans_count);
642}
643
644static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
645{
646 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
647
648 nfs_show_mount_options(m, nfss, 0);
649
650 seq_puts(m, ",addr=");
651 seq_escape(m, nfss->hostname, " \t\n\\");
652
653 return 0;
654}
655
656static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
657{
658 int i, cpu;
659 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
660 struct rpc_auth *auth = nfss->client->cl_auth;
661 struct nfs_iostats totals = { };
662
663 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
664
665 /*
666 * Display all mount option settings
667 */
668 seq_printf(m, "\n\topts:\t");
669 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
670 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
671 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
672 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
673 nfs_show_mount_options(m, nfss, 1);
674
675 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
676
677 seq_printf(m, "\n\tcaps:\t");
678 seq_printf(m, "caps=0x%x", nfss->caps);
679 seq_printf(m, ",wtmult=%d", nfss->wtmult);
680 seq_printf(m, ",dtsize=%d", nfss->dtsize);
681 seq_printf(m, ",bsize=%d", nfss->bsize);
682 seq_printf(m, ",namelen=%d", nfss->namelen);
683
684#ifdef CONFIG_NFS_V4
685 if (nfss->rpc_ops->version == 4) {
686 seq_printf(m, "\n\tnfsv4:\t");
687 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
688 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
689 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
690 }
691#endif
692
693 /*
694 * Display security flavor in effect for this mount
695 */
696 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
697 if (auth->au_flavor)
698 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
699
700 /*
701 * Display superblock I/O counters
702 */
703 for_each_possible_cpu(cpu) {
704 struct nfs_iostats *stats;
705
706 preempt_disable();
707 stats = per_cpu_ptr(nfss->io_stats, cpu);
708
709 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
710 totals.events[i] += stats->events[i];
711 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
712 totals.bytes[i] += stats->bytes[i];
713
714 preempt_enable();
715 }
716
717 seq_printf(m, "\n\tevents:\t");
718 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
719 seq_printf(m, "%lu ", totals.events[i]);
720 seq_printf(m, "\n\tbytes:\t");
721 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
722 seq_printf(m, "%Lu ", totals.bytes[i]);
723 seq_printf(m, "\n");
724
725 rpc_print_iostats(m, nfss->client);
726
727 return 0;
728}
729
730/** 95/**
731 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk 96 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
732 */ 97 */
@@ -889,6 +254,14 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
889 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS) 254 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
890 && fattr->size <= NFS_LIMIT_READDIRPLUS) 255 && fattr->size <= NFS_LIMIT_READDIRPLUS)
891 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode)); 256 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode));
257 /* Deal with crossing mountpoints */
258 if (!nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) {
259 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
260 inode->i_op = &nfs_referral_inode_operations;
261 else
262 inode->i_op = &nfs_mountpoint_inode_operations;
263 inode->i_fop = NULL;
264 }
892 } else if (S_ISLNK(inode->i_mode)) 265 } else if (S_ISLNK(inode->i_mode))
893 inode->i_op = &nfs_symlink_inode_operations; 266 inode->i_op = &nfs_symlink_inode_operations;
894 else 267 else
@@ -1207,6 +580,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1207 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n", 580 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
1208 inode->i_sb->s_id, (long long)NFS_FILEID(inode)); 581 inode->i_sb->s_id, (long long)NFS_FILEID(inode));
1209 582
583 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
1210 lock_kernel(); 584 lock_kernel();
1211 if (!inode || is_bad_inode(inode)) 585 if (!inode || is_bad_inode(inode))
1212 goto out_nowait; 586 goto out_nowait;
@@ -1220,7 +594,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1220 status = -ESTALE; 594 status = -ESTALE;
1221 /* Do we trust the cached ESTALE? */ 595 /* Do we trust the cached ESTALE? */
1222 if (NFS_ATTRTIMEO(inode) != 0) { 596 if (NFS_ATTRTIMEO(inode) != 0) {
1223 if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ATIME)) { 597 if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME)) {
1224 /* no */ 598 /* no */
1225 } else 599 } else
1226 goto out; 600 goto out;
@@ -1251,8 +625,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1251 } 625 }
1252 spin_unlock(&inode->i_lock); 626 spin_unlock(&inode->i_lock);
1253 627
1254 nfs_revalidate_mapping(inode, inode->i_mapping);
1255
1256 if (nfsi->cache_validity & NFS_INO_INVALID_ACL) 628 if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
1257 nfs_zap_acl_cache(inode); 629 nfs_zap_acl_cache(inode);
1258 630
@@ -1286,8 +658,7 @@ int nfs_attribute_timeout(struct inode *inode)
1286 */ 658 */
1287int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) 659int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1288{ 660{
1289 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE); 661 if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
1290 if (!(NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
1291 && !nfs_attribute_timeout(inode)) 662 && !nfs_attribute_timeout(inode))
1292 return NFS_STALE(inode) ? -ESTALE : 0; 663 return NFS_STALE(inode) ? -ESTALE : 0;
1293 return __nfs_revalidate_inode(server, inode); 664 return __nfs_revalidate_inode(server, inode);
@@ -1298,9 +669,16 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1298 * @inode - pointer to host inode 669 * @inode - pointer to host inode
1299 * @mapping - pointer to mapping 670 * @mapping - pointer to mapping
1300 */ 671 */
1301void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) 672int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
1302{ 673{
1303 struct nfs_inode *nfsi = NFS_I(inode); 674 struct nfs_inode *nfsi = NFS_I(inode);
675 int ret = 0;
676
677 if (NFS_STALE(inode))
678 ret = -ESTALE;
679 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
680 || nfs_attribute_timeout(inode))
681 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
1304 682
1305 if (nfsi->cache_validity & NFS_INO_INVALID_DATA) { 683 if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
1306 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE); 684 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
@@ -1321,6 +699,7 @@ void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
1321 inode->i_sb->s_id, 699 inode->i_sb->s_id,
1322 (long long)NFS_FILEID(inode)); 700 (long long)NFS_FILEID(inode));
1323 } 701 }
702 return ret;
1324} 703}
1325 704
1326/** 705/**
@@ -1360,12 +739,6 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1360{ 739{
1361 struct nfs_inode *nfsi = NFS_I(inode); 740 struct nfs_inode *nfsi = NFS_I(inode);
1362 741
1363 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
1364 && nfsi->change_attr == fattr->pre_change_attr) {
1365 nfsi->change_attr = fattr->change_attr;
1366 nfsi->cache_change_attribute = jiffies;
1367 }
1368
1369 /* If we have atomic WCC data, we may update some attributes */ 742 /* If we have atomic WCC data, we may update some attributes */
1370 if ((fattr->valid & NFS_ATTR_WCC) != 0) { 743 if ((fattr->valid & NFS_ATTR_WCC) != 0) {
1371 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) { 744 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
@@ -1399,9 +772,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1399 int data_unstable; 772 int data_unstable;
1400 773
1401 774
1402 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1403 return 0;
1404
1405 /* Has the inode gone and changed behind our back? */ 775 /* Has the inode gone and changed behind our back? */
1406 if (nfsi->fileid != fattr->fileid 776 if (nfsi->fileid != fattr->fileid
1407 || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) { 777 || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
@@ -1414,20 +784,13 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1414 /* Do atomic weak cache consistency updates */ 784 /* Do atomic weak cache consistency updates */
1415 nfs_wcc_update_inode(inode, fattr); 785 nfs_wcc_update_inode(inode, fattr);
1416 786
1417 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0) { 787 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1418 if (nfsi->change_attr == fattr->change_attr) 788 nfsi->change_attr != fattr->change_attr)
1419 goto out; 789 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
1420 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1421 if (!data_unstable)
1422 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1423 }
1424 790
1425 /* Verify a few of the more important attributes */ 791 /* Verify a few of the more important attributes */
1426 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) { 792 if (!timespec_equal(&inode->i_mtime, &fattr->mtime))
1427 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 793 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
1428 if (!data_unstable)
1429 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1430 }
1431 794
1432 cur_size = i_size_read(inode); 795 cur_size = i_size_read(inode);
1433 new_isize = nfs_size_to_loff_t(fattr->size); 796 new_isize = nfs_size_to_loff_t(fattr->size);
@@ -1444,7 +807,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1444 if (inode->i_nlink != fattr->nlink) 807 if (inode->i_nlink != fattr->nlink)
1445 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 808 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1446 809
1447out:
1448 if (!timespec_equal(&inode->i_atime, &fattr->atime)) 810 if (!timespec_equal(&inode->i_atime, &fattr->atime))
1449 nfsi->cache_validity |= NFS_INO_INVALID_ATIME; 811 nfsi->cache_validity |= NFS_INO_INVALID_ATIME;
1450 812
@@ -1470,7 +832,6 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
1470 if ((fattr->valid & NFS_ATTR_FATTR) == 0) 832 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1471 return 0; 833 return 0;
1472 spin_lock(&inode->i_lock); 834 spin_lock(&inode->i_lock);
1473 nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE;
1474 if (time_after(fattr->time_start, nfsi->last_updated)) 835 if (time_after(fattr->time_start, nfsi->last_updated))
1475 status = nfs_update_inode(inode, fattr); 836 status = nfs_update_inode(inode, fattr);
1476 else 837 else
@@ -1495,7 +856,7 @@ int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1495 856
1496 spin_lock(&inode->i_lock); 857 spin_lock(&inode->i_lock);
1497 if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) { 858 if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
1498 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS; 859 nfsi->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
1499 goto out; 860 goto out;
1500 } 861 }
1501 status = nfs_update_inode(inode, fattr); 862 status = nfs_update_inode(inode, fattr);
@@ -1518,6 +879,7 @@ out:
1518 */ 879 */
1519static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) 880static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1520{ 881{
882 struct nfs_server *server;
1521 struct nfs_inode *nfsi = NFS_I(inode); 883 struct nfs_inode *nfsi = NFS_I(inode);
1522 loff_t cur_isize, new_isize; 884 loff_t cur_isize, new_isize;
1523 unsigned int invalid = 0; 885 unsigned int invalid = 0;
@@ -1527,9 +889,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1527 __FUNCTION__, inode->i_sb->s_id, inode->i_ino, 889 __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
1528 atomic_read(&inode->i_count), fattr->valid); 890 atomic_read(&inode->i_count), fattr->valid);
1529 891
1530 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1531 return 0;
1532
1533 if (nfsi->fileid != fattr->fileid) 892 if (nfsi->fileid != fattr->fileid)
1534 goto out_fileid; 893 goto out_fileid;
1535 894
@@ -1539,6 +898,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1539 if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) 898 if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
1540 goto out_changed; 899 goto out_changed;
1541 900
901 server = NFS_SERVER(inode);
902 /* Update the fsid if and only if this is the root directory */
903 if (inode == inode->i_sb->s_root->d_inode
904 && !nfs_fsid_equal(&server->fsid, &fattr->fsid))
905 server->fsid = fattr->fsid;
906
1542 /* 907 /*
1543 * Update the read time so we don't revalidate too often. 908 * Update the read time so we don't revalidate too often.
1544 */ 909 */
@@ -1548,7 +913,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1548 /* Are we racing with known updates of the metadata on the server? */ 913 /* Are we racing with known updates of the metadata on the server? */
1549 data_stable = nfs_verify_change_attribute(inode, fattr->time_start); 914 data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
1550 if (data_stable) 915 if (data_stable)
1551 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME); 916 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATIME);
1552 917
1553 /* Do atomic weak cache consistency updates */ 918 /* Do atomic weak cache consistency updates */
1554 nfs_wcc_update_inode(inode, fattr); 919 nfs_wcc_update_inode(inode, fattr);
@@ -1612,15 +977,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1612 inode->i_blksize = fattr->du.nfs2.blocksize; 977 inode->i_blksize = fattr->du.nfs2.blocksize;
1613 } 978 }
1614 979
1615 if ((fattr->valid & NFS_ATTR_FATTR_V4)) { 980 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1616 if (nfsi->change_attr != fattr->change_attr) { 981 nfsi->change_attr != fattr->change_attr) {
1617 dprintk("NFS: change_attr change on server for file %s/%ld\n", 982 dprintk("NFS: change_attr change on server for file %s/%ld\n",
1618 inode->i_sb->s_id, inode->i_ino); 983 inode->i_sb->s_id, inode->i_ino);
1619 nfsi->change_attr = fattr->change_attr; 984 nfsi->change_attr = fattr->change_attr;
1620 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 985 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1621 nfsi->cache_change_attribute = jiffies; 986 nfsi->cache_change_attribute = jiffies;
1622 } else
1623 invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA);
1624 } 987 }
1625 988
1626 /* Update attrtimeo value if we're out of the unstable period */ 989 /* Update attrtimeo value if we're out of the unstable period */
@@ -1668,190 +1031,15 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1668 goto out_err; 1031 goto out_err;
1669} 1032}
1670 1033
1671/*
1672 * File system information
1673 */
1674
1675static int nfs_set_super(struct super_block *s, void *data)
1676{
1677 s->s_fs_info = data;
1678 return set_anon_super(s, data);
1679}
1680
1681static int nfs_compare_super(struct super_block *sb, void *data)
1682{
1683 struct nfs_server *server = data;
1684 struct nfs_server *old = NFS_SB(sb);
1685
1686 if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr)
1687 return 0;
1688 if (old->addr.sin_port != server->addr.sin_port)
1689 return 0;
1690 return !nfs_compare_fh(&old->fh, &server->fh);
1691}
1692
1693static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
1694 int flags, const char *dev_name, void *raw_data)
1695{
1696 int error;
1697 struct nfs_server *server = NULL;
1698 struct super_block *s;
1699 struct nfs_fh *root;
1700 struct nfs_mount_data *data = raw_data;
1701
1702 s = ERR_PTR(-EINVAL);
1703 if (data == NULL) {
1704 dprintk("%s: missing data argument\n", __FUNCTION__);
1705 goto out_err;
1706 }
1707 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
1708 dprintk("%s: bad mount version\n", __FUNCTION__);
1709 goto out_err;
1710 }
1711 switch (data->version) {
1712 case 1:
1713 data->namlen = 0;
1714 case 2:
1715 data->bsize = 0;
1716 case 3:
1717 if (data->flags & NFS_MOUNT_VER3) {
1718 dprintk("%s: mount structure version %d does not support NFSv3\n",
1719 __FUNCTION__,
1720 data->version);
1721 goto out_err;
1722 }
1723 data->root.size = NFS2_FHSIZE;
1724 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1725 case 4:
1726 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
1727 dprintk("%s: mount structure version %d does not support strong security\n",
1728 __FUNCTION__,
1729 data->version);
1730 goto out_err;
1731 }
1732 case 5:
1733 memset(data->context, 0, sizeof(data->context));
1734 }
1735#ifndef CONFIG_NFS_V3
1736 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
1737 s = ERR_PTR(-EPROTONOSUPPORT);
1738 if (data->flags & NFS_MOUNT_VER3) {
1739 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
1740 goto out_err;
1741 }
1742#endif /* CONFIG_NFS_V3 */
1743
1744 s = ERR_PTR(-ENOMEM);
1745 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1746 if (!server)
1747 goto out_err;
1748 /* Zero out the NFS state stuff */
1749 init_nfsv4_state(server);
1750 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
1751
1752 root = &server->fh;
1753 if (data->flags & NFS_MOUNT_VER3)
1754 root->size = data->root.size;
1755 else
1756 root->size = NFS2_FHSIZE;
1757 s = ERR_PTR(-EINVAL);
1758 if (root->size > sizeof(root->data)) {
1759 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
1760 goto out_err;
1761 }
1762 memcpy(root->data, data->root.data, root->size);
1763
1764 /* We now require that the mount process passes the remote address */
1765 memcpy(&server->addr, &data->addr, sizeof(server->addr));
1766 if (server->addr.sin_addr.s_addr == INADDR_ANY) {
1767 dprintk("%s: mount program didn't pass remote address!\n",
1768 __FUNCTION__);
1769 goto out_err;
1770 }
1771
1772 /* Fire up rpciod if not yet running */
1773 s = ERR_PTR(rpciod_up());
1774 if (IS_ERR(s)) {
1775 dprintk("%s: couldn't start rpciod! Error = %ld\n",
1776 __FUNCTION__, PTR_ERR(s));
1777 goto out_err;
1778 }
1779
1780 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1781 if (IS_ERR(s) || s->s_root)
1782 goto out_rpciod_down;
1783
1784 s->s_flags = flags;
1785
1786 error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1787 if (error) {
1788 up_write(&s->s_umount);
1789 deactivate_super(s);
1790 return ERR_PTR(error);
1791 }
1792 s->s_flags |= MS_ACTIVE;
1793 return s;
1794out_rpciod_down:
1795 rpciod_down();
1796out_err:
1797 kfree(server);
1798 return s;
1799}
1800
1801static void nfs_kill_super(struct super_block *s)
1802{
1803 struct nfs_server *server = NFS_SB(s);
1804
1805 kill_anon_super(s);
1806
1807 if (!IS_ERR(server->client))
1808 rpc_shutdown_client(server->client);
1809 if (!IS_ERR(server->client_sys))
1810 rpc_shutdown_client(server->client_sys);
1811 if (!IS_ERR(server->client_acl))
1812 rpc_shutdown_client(server->client_acl);
1813
1814 if (!(server->flags & NFS_MOUNT_NONLM))
1815 lockd_down(); /* release rpc.lockd */
1816
1817 rpciod_down(); /* release rpciod */
1818
1819 nfs_free_iostats(server->io_stats);
1820 kfree(server->hostname);
1821 kfree(server);
1822}
1823
1824static struct file_system_type nfs_fs_type = {
1825 .owner = THIS_MODULE,
1826 .name = "nfs",
1827 .get_sb = nfs_get_sb,
1828 .kill_sb = nfs_kill_super,
1829 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
1830};
1831 1034
1832#ifdef CONFIG_NFS_V4 1035#ifdef CONFIG_NFS_V4
1833 1036
1834static void nfs4_clear_inode(struct inode *);
1835
1836
1837static struct super_operations nfs4_sops = {
1838 .alloc_inode = nfs_alloc_inode,
1839 .destroy_inode = nfs_destroy_inode,
1840 .write_inode = nfs_write_inode,
1841 .delete_inode = nfs_delete_inode,
1842 .statfs = nfs_statfs,
1843 .clear_inode = nfs4_clear_inode,
1844 .umount_begin = nfs_umount_begin,
1845 .show_options = nfs_show_options,
1846 .show_stats = nfs_show_stats,
1847};
1848
1849/* 1037/*
1850 * Clean out any remaining NFSv4 state that might be left over due 1038 * Clean out any remaining NFSv4 state that might be left over due
1851 * to open() calls that passed nfs_atomic_lookup, but failed to call 1039 * to open() calls that passed nfs_atomic_lookup, but failed to call
1852 * nfs_open(). 1040 * nfs_open().
1853 */ 1041 */
1854static void nfs4_clear_inode(struct inode *inode) 1042void nfs4_clear_inode(struct inode *inode)
1855{ 1043{
1856 struct nfs_inode *nfsi = NFS_I(inode); 1044 struct nfs_inode *nfsi = NFS_I(inode);
1857 1045
@@ -1875,357 +1063,9 @@ static void nfs4_clear_inode(struct inode *inode)
1875 nfs4_close_state(state, state->state); 1063 nfs4_close_state(state, state->state);
1876 } 1064 }
1877} 1065}
1878
1879
1880static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
1881{
1882 struct nfs_server *server;
1883 struct nfs4_client *clp = NULL;
1884 struct rpc_xprt *xprt = NULL;
1885 struct rpc_clnt *clnt = NULL;
1886 struct rpc_timeout timeparms;
1887 rpc_authflavor_t authflavour;
1888 int err = -EIO;
1889
1890 sb->s_blocksize_bits = 0;
1891 sb->s_blocksize = 0;
1892 server = NFS_SB(sb);
1893 if (data->rsize != 0)
1894 server->rsize = nfs_block_size(data->rsize, NULL);
1895 if (data->wsize != 0)
1896 server->wsize = nfs_block_size(data->wsize, NULL);
1897 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
1898 server->caps = NFS_CAP_ATOMIC_OPEN;
1899
1900 server->acregmin = data->acregmin*HZ;
1901 server->acregmax = data->acregmax*HZ;
1902 server->acdirmin = data->acdirmin*HZ;
1903 server->acdirmax = data->acdirmax*HZ;
1904
1905 server->rpc_ops = &nfs_v4_clientops;
1906
1907 nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
1908
1909 server->retrans_timeo = timeparms.to_initval;
1910 server->retrans_count = timeparms.to_retries;
1911
1912 clp = nfs4_get_client(&server->addr.sin_addr);
1913 if (!clp) {
1914 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
1915 return -EIO;
1916 }
1917
1918 /* Now create transport and client */
1919 authflavour = RPC_AUTH_UNIX;
1920 if (data->auth_flavourlen != 0) {
1921 if (data->auth_flavourlen != 1) {
1922 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
1923 __FUNCTION__, data->auth_flavourlen);
1924 err = -EINVAL;
1925 goto out_fail;
1926 }
1927 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
1928 err = -EFAULT;
1929 goto out_fail;
1930 }
1931 }
1932
1933 down_write(&clp->cl_sem);
1934 if (IS_ERR(clp->cl_rpcclient)) {
1935 xprt = xprt_create_proto(data->proto, &server->addr, &timeparms);
1936 if (IS_ERR(xprt)) {
1937 up_write(&clp->cl_sem);
1938 err = PTR_ERR(xprt);
1939 dprintk("%s: cannot create RPC transport. Error = %d\n",
1940 __FUNCTION__, err);
1941 goto out_fail;
1942 }
1943 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
1944 server->rpc_ops->version, authflavour);
1945 if (IS_ERR(clnt)) {
1946 up_write(&clp->cl_sem);
1947 err = PTR_ERR(clnt);
1948 dprintk("%s: cannot create RPC client. Error = %d\n",
1949 __FUNCTION__, err);
1950 goto out_fail;
1951 }
1952 clnt->cl_intr = 1;
1953 clnt->cl_softrtry = 1;
1954 clp->cl_rpcclient = clnt;
1955 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1956 nfs_idmap_new(clp);
1957 }
1958 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1959 clnt = rpc_clone_client(clp->cl_rpcclient);
1960 if (!IS_ERR(clnt))
1961 server->nfs4_state = clp;
1962 up_write(&clp->cl_sem);
1963 clp = NULL;
1964
1965 if (IS_ERR(clnt)) {
1966 err = PTR_ERR(clnt);
1967 dprintk("%s: cannot create RPC client. Error = %d\n",
1968 __FUNCTION__, err);
1969 return err;
1970 }
1971
1972 server->client = clnt;
1973
1974 if (server->nfs4_state->cl_idmap == NULL) {
1975 dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
1976 return -ENOMEM;
1977 }
1978
1979 if (clnt->cl_auth->au_flavor != authflavour) {
1980 struct rpc_auth *auth;
1981
1982 auth = rpcauth_create(authflavour, clnt);
1983 if (IS_ERR(auth)) {
1984 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
1985 return PTR_ERR(auth);
1986 }
1987 }
1988
1989 sb->s_time_gran = 1;
1990
1991 sb->s_op = &nfs4_sops;
1992 err = nfs_sb_init(sb, authflavour);
1993 if (err == 0)
1994 return 0;
1995out_fail:
1996 if (clp)
1997 nfs4_put_client(clp);
1998 return err;
1999}
2000
2001static int nfs4_compare_super(struct super_block *sb, void *data)
2002{
2003 struct nfs_server *server = data;
2004 struct nfs_server *old = NFS_SB(sb);
2005
2006 if (strcmp(server->hostname, old->hostname) != 0)
2007 return 0;
2008 if (strcmp(server->mnt_path, old->mnt_path) != 0)
2009 return 0;
2010 return 1;
2011}
2012
2013static void *
2014nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
2015{
2016 void *p = NULL;
2017
2018 if (!src->len)
2019 return ERR_PTR(-EINVAL);
2020 if (src->len < maxlen)
2021 maxlen = src->len;
2022 if (dst == NULL) {
2023 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
2024 if (p == NULL)
2025 return ERR_PTR(-ENOMEM);
2026 }
2027 if (copy_from_user(dst, src->data, maxlen)) {
2028 kfree(p);
2029 return ERR_PTR(-EFAULT);
2030 }
2031 dst[maxlen] = '\0';
2032 return dst;
2033}
2034
2035static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
2036 int flags, const char *dev_name, void *raw_data)
2037{
2038 int error;
2039 struct nfs_server *server;
2040 struct super_block *s;
2041 struct nfs4_mount_data *data = raw_data;
2042 void *p;
2043
2044 if (data == NULL) {
2045 dprintk("%s: missing data argument\n", __FUNCTION__);
2046 return ERR_PTR(-EINVAL);
2047 }
2048 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
2049 dprintk("%s: bad mount version\n", __FUNCTION__);
2050 return ERR_PTR(-EINVAL);
2051 }
2052
2053 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
2054 if (!server)
2055 return ERR_PTR(-ENOMEM);
2056 /* Zero out the NFS state stuff */
2057 init_nfsv4_state(server);
2058 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
2059
2060 p = nfs_copy_user_string(NULL, &data->hostname, 256);
2061 if (IS_ERR(p))
2062 goto out_err;
2063 server->hostname = p;
2064
2065 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
2066 if (IS_ERR(p))
2067 goto out_err;
2068 server->mnt_path = p;
2069
2070 p = nfs_copy_user_string(server->ip_addr, &data->client_addr,
2071 sizeof(server->ip_addr) - 1);
2072 if (IS_ERR(p))
2073 goto out_err;
2074
2075 /* We now require that the mount process passes the remote address */
2076 if (data->host_addrlen != sizeof(server->addr)) {
2077 s = ERR_PTR(-EINVAL);
2078 goto out_free;
2079 }
2080 if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) {
2081 s = ERR_PTR(-EFAULT);
2082 goto out_free;
2083 }
2084 if (server->addr.sin_family != AF_INET ||
2085 server->addr.sin_addr.s_addr == INADDR_ANY) {
2086 dprintk("%s: mount program didn't pass remote IP address!\n",
2087 __FUNCTION__);
2088 s = ERR_PTR(-EINVAL);
2089 goto out_free;
2090 }
2091
2092 /* Fire up rpciod if not yet running */
2093 s = ERR_PTR(rpciod_up());
2094 if (IS_ERR(s)) {
2095 dprintk("%s: couldn't start rpciod! Error = %ld\n",
2096 __FUNCTION__, PTR_ERR(s));
2097 goto out_free;
2098 }
2099
2100 s = sget(fs_type, nfs4_compare_super, nfs_set_super, server);
2101
2102 if (IS_ERR(s) || s->s_root)
2103 goto out_free;
2104
2105 s->s_flags = flags;
2106
2107 error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
2108 if (error) {
2109 up_write(&s->s_umount);
2110 deactivate_super(s);
2111 return ERR_PTR(error);
2112 }
2113 s->s_flags |= MS_ACTIVE;
2114 return s;
2115out_err:
2116 s = (struct super_block *)p;
2117out_free:
2118 kfree(server->mnt_path);
2119 kfree(server->hostname);
2120 kfree(server);
2121 return s;
2122}
2123
2124static void nfs4_kill_super(struct super_block *sb)
2125{
2126 struct nfs_server *server = NFS_SB(sb);
2127
2128 nfs_return_all_delegations(sb);
2129 kill_anon_super(sb);
2130
2131 nfs4_renewd_prepare_shutdown(server);
2132
2133 if (server->client != NULL && !IS_ERR(server->client))
2134 rpc_shutdown_client(server->client);
2135
2136 destroy_nfsv4_state(server);
2137
2138 rpciod_down();
2139
2140 nfs_free_iostats(server->io_stats);
2141 kfree(server->hostname);
2142 kfree(server);
2143}
2144
2145static struct file_system_type nfs4_fs_type = {
2146 .owner = THIS_MODULE,
2147 .name = "nfs4",
2148 .get_sb = nfs4_get_sb,
2149 .kill_sb = nfs4_kill_super,
2150 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
2151};
2152
2153static const int nfs_set_port_min = 0;
2154static const int nfs_set_port_max = 65535;
2155static int param_set_port(const char *val, struct kernel_param *kp)
2156{
2157 char *endp;
2158 int num = simple_strtol(val, &endp, 0);
2159 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
2160 return -EINVAL;
2161 *((int *)kp->arg) = num;
2162 return 0;
2163}
2164
2165module_param_call(callback_tcpport, param_set_port, param_get_int,
2166 &nfs_callback_set_tcpport, 0644);
2167
2168static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
2169{
2170 char *endp;
2171 int num = simple_strtol(val, &endp, 0);
2172 int jif = num * HZ;
2173 if (endp == val || *endp || num < 0 || jif < num)
2174 return -EINVAL;
2175 *((int *)kp->arg) = jif;
2176 return 0;
2177}
2178
2179module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
2180 &nfs_idmap_cache_timeout, 0644);
2181
2182#define nfs4_init_once(nfsi) \
2183 do { \
2184 INIT_LIST_HEAD(&(nfsi)->open_states); \
2185 nfsi->delegation = NULL; \
2186 nfsi->delegation_state = 0; \
2187 init_rwsem(&nfsi->rwsem); \
2188 } while(0)
2189
2190static inline int register_nfs4fs(void)
2191{
2192 int ret;
2193
2194 ret = nfs_register_sysctl();
2195 if (ret != 0)
2196 return ret;
2197 ret = register_filesystem(&nfs4_fs_type);
2198 if (ret != 0)
2199 nfs_unregister_sysctl();
2200 return ret;
2201}
2202
2203static inline void unregister_nfs4fs(void)
2204{
2205 unregister_filesystem(&nfs4_fs_type);
2206 nfs_unregister_sysctl();
2207}
2208#else
2209#define nfs4_init_once(nfsi) \
2210 do { } while (0)
2211#define register_nfs4fs() (0)
2212#define unregister_nfs4fs()
2213#endif 1066#endif
2214 1067
2215extern int nfs_init_nfspagecache(void); 1068struct inode *nfs_alloc_inode(struct super_block *sb)
2216extern void nfs_destroy_nfspagecache(void);
2217extern int nfs_init_readpagecache(void);
2218extern void nfs_destroy_readpagecache(void);
2219extern int nfs_init_writepagecache(void);
2220extern void nfs_destroy_writepagecache(void);
2221#ifdef CONFIG_NFS_DIRECTIO
2222extern int nfs_init_directcache(void);
2223extern void nfs_destroy_directcache(void);
2224#endif
2225
2226static kmem_cache_t * nfs_inode_cachep;
2227
2228static struct inode *nfs_alloc_inode(struct super_block *sb)
2229{ 1069{
2230 struct nfs_inode *nfsi; 1070 struct nfs_inode *nfsi;
2231 nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, SLAB_KERNEL); 1071 nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, SLAB_KERNEL);
@@ -2244,11 +1084,19 @@ static struct inode *nfs_alloc_inode(struct super_block *sb)
2244 return &nfsi->vfs_inode; 1084 return &nfsi->vfs_inode;
2245} 1085}
2246 1086
2247static void nfs_destroy_inode(struct inode *inode) 1087void nfs_destroy_inode(struct inode *inode)
2248{ 1088{
2249 kmem_cache_free(nfs_inode_cachep, NFS_I(inode)); 1089 kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
2250} 1090}
2251 1091
1092#define nfs4_init_once(nfsi) \
1093 do { \
1094 INIT_LIST_HEAD(&(nfsi)->open_states); \
1095 nfsi->delegation = NULL; \
1096 nfsi->delegation_state = 0; \
1097 init_rwsem(&nfsi->rwsem); \
1098 } while(0)
1099
2252static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) 1100static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2253{ 1101{
2254 struct nfs_inode *nfsi = (struct nfs_inode *) foo; 1102 struct nfs_inode *nfsi = (struct nfs_inode *) foo;
@@ -2269,7 +1117,7 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2269 } 1117 }
2270} 1118}
2271 1119
2272static int nfs_init_inodecache(void) 1120static int __init nfs_init_inodecache(void)
2273{ 1121{
2274 nfs_inode_cachep = kmem_cache_create("nfs_inode_cache", 1122 nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
2275 sizeof(struct nfs_inode), 1123 sizeof(struct nfs_inode),
@@ -2282,7 +1130,7 @@ static int nfs_init_inodecache(void)
2282 return 0; 1130 return 0;
2283} 1131}
2284 1132
2285static void nfs_destroy_inodecache(void) 1133static void __exit nfs_destroy_inodecache(void)
2286{ 1134{
2287 if (kmem_cache_destroy(nfs_inode_cachep)) 1135 if (kmem_cache_destroy(nfs_inode_cachep))
2288 printk(KERN_INFO "nfs_inode_cache: not all structures were freed\n"); 1136 printk(KERN_INFO "nfs_inode_cache: not all structures were freed\n");
@@ -2311,29 +1159,22 @@ static int __init init_nfs_fs(void)
2311 if (err) 1159 if (err)
2312 goto out1; 1160 goto out1;
2313 1161
2314#ifdef CONFIG_NFS_DIRECTIO
2315 err = nfs_init_directcache(); 1162 err = nfs_init_directcache();
2316 if (err) 1163 if (err)
2317 goto out0; 1164 goto out0;
2318#endif
2319 1165
2320#ifdef CONFIG_PROC_FS 1166#ifdef CONFIG_PROC_FS
2321 rpc_proc_register(&nfs_rpcstat); 1167 rpc_proc_register(&nfs_rpcstat);
2322#endif 1168#endif
2323 err = register_filesystem(&nfs_fs_type); 1169 if ((err = register_nfs_fs()) != 0)
2324 if (err)
2325 goto out;
2326 if ((err = register_nfs4fs()) != 0)
2327 goto out; 1170 goto out;
2328 return 0; 1171 return 0;
2329out: 1172out:
2330#ifdef CONFIG_PROC_FS 1173#ifdef CONFIG_PROC_FS
2331 rpc_proc_unregister("nfs"); 1174 rpc_proc_unregister("nfs");
2332#endif 1175#endif
2333#ifdef CONFIG_NFS_DIRECTIO
2334 nfs_destroy_directcache(); 1176 nfs_destroy_directcache();
2335out0: 1177out0:
2336#endif
2337 nfs_destroy_writepagecache(); 1178 nfs_destroy_writepagecache();
2338out1: 1179out1:
2339 nfs_destroy_readpagecache(); 1180 nfs_destroy_readpagecache();
@@ -2347,9 +1188,7 @@ out4:
2347 1188
2348static void __exit exit_nfs_fs(void) 1189static void __exit exit_nfs_fs(void)
2349{ 1190{
2350#ifdef CONFIG_NFS_DIRECTIO
2351 nfs_destroy_directcache(); 1191 nfs_destroy_directcache();
2352#endif
2353 nfs_destroy_writepagecache(); 1192 nfs_destroy_writepagecache();
2354 nfs_destroy_readpagecache(); 1193 nfs_destroy_readpagecache();
2355 nfs_destroy_inodecache(); 1194 nfs_destroy_inodecache();
@@ -2357,8 +1196,7 @@ static void __exit exit_nfs_fs(void)
2357#ifdef CONFIG_PROC_FS 1196#ifdef CONFIG_PROC_FS
2358 rpc_proc_unregister("nfs"); 1197 rpc_proc_unregister("nfs");
2359#endif 1198#endif
2360 unregister_filesystem(&nfs_fs_type); 1199 unregister_nfs_fs();
2361 unregister_nfs4fs();
2362} 1200}
2363 1201
2364/* Not quite true; I just maintain it */ 1202/* Not quite true; I just maintain it */
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
new file mode 100644
index 000000000000..5e51c4535b6f
--- /dev/null
+++ b/fs/nfs/internal.h
@@ -0,0 +1,179 @@
1/*
2 * NFS internal definitions
3 */
4
5#include <linux/mount.h>
6
7struct nfs_clone_mount {
8 const struct super_block *sb;
9 const struct dentry *dentry;
10 struct nfs_fh *fh;
11 struct nfs_fattr *fattr;
12 char *hostname;
13 char *mnt_path;
14 struct sockaddr_in *addr;
15 rpc_authflavor_t authflavor;
16};
17
18/* namespace-nfs4.c */
19#ifdef CONFIG_NFS_V4
20extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
21#else
22static inline
23struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
24{
25 return ERR_PTR(-ENOENT);
26}
27#endif
28
29/* callback_xdr.c */
30extern struct svc_version nfs4_callback_version1;
31
32/* pagelist.c */
33extern int __init nfs_init_nfspagecache(void);
34extern void __exit nfs_destroy_nfspagecache(void);
35extern int __init nfs_init_readpagecache(void);
36extern void __exit nfs_destroy_readpagecache(void);
37extern int __init nfs_init_writepagecache(void);
38extern void __exit nfs_destroy_writepagecache(void);
39
40#ifdef CONFIG_NFS_DIRECTIO
41extern int __init nfs_init_directcache(void);
42extern void __exit nfs_destroy_directcache(void);
43#else
44#define nfs_init_directcache() (0)
45#define nfs_destroy_directcache() do {} while(0)
46#endif
47
48/* nfs2xdr.c */
49extern struct rpc_procinfo nfs_procedures[];
50extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
51
52/* nfs3xdr.c */
53extern struct rpc_procinfo nfs3_procedures[];
54extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
55
56/* nfs4xdr.c */
57extern int nfs_stat_to_errno(int);
58extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
59
60/* nfs4proc.c */
61extern struct rpc_procinfo nfs4_procedures[];
62
63extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
64 struct nfs4_fs_locations *fs_locations,
65 struct page *page);
66
67/* inode.c */
68extern struct inode *nfs_alloc_inode(struct super_block *sb);
69extern void nfs_destroy_inode(struct inode *);
70extern int nfs_write_inode(struct inode *,int);
71extern void nfs_clear_inode(struct inode *);
72#ifdef CONFIG_NFS_V4
73extern void nfs4_clear_inode(struct inode *);
74#endif
75
76/* super.c */
77extern struct file_system_type nfs_referral_nfs4_fs_type;
78extern struct file_system_type clone_nfs_fs_type;
79#ifdef CONFIG_NFS_V4
80extern struct file_system_type clone_nfs4_fs_type;
81#endif
82#ifdef CONFIG_PROC_FS
83extern struct rpc_stat nfs_rpcstat;
84#endif
85extern int __init register_nfs_fs(void);
86extern void __exit unregister_nfs_fs(void);
87
88/* namespace.c */
89extern char *nfs_path(const char *base, const struct dentry *dentry,
90 char *buffer, ssize_t buflen);
91
92/*
93 * Determine the mount path as a string
94 */
95static inline char *nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
96{
97 return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
98}
99
100/*
101 * Determine the device name as a string
102 */
103static inline char *nfs_devname(const struct vfsmount *mnt_parent,
104 const struct dentry *dentry,
105 char *buffer, ssize_t buflen)
106{
107 return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
108}
109
110/*
111 * Determine the actual block size (and log2 thereof)
112 */
113static inline
114unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
115{
116 /* make sure blocksize is a power of two */
117 if ((bsize & (bsize - 1)) || nrbitsp) {
118 unsigned char nrbits;
119
120 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
121 ;
122 bsize = 1 << nrbits;
123 if (nrbitsp)
124 *nrbitsp = nrbits;
125 }
126
127 return bsize;
128}
129
130/*
131 * Calculate the number of 512byte blocks used.
132 */
133static inline unsigned long nfs_calc_block_size(u64 tsize)
134{
135 loff_t used = (tsize + 511) >> 9;
136 return (used > ULONG_MAX) ? ULONG_MAX : used;
137}
138
139/*
140 * Compute and set NFS server blocksize
141 */
142static inline
143unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
144{
145 if (bsize < NFS_MIN_FILE_IO_SIZE)
146 bsize = NFS_DEF_FILE_IO_SIZE;
147 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
148 bsize = NFS_MAX_FILE_IO_SIZE;
149
150 return nfs_block_bits(bsize, nrbitsp);
151}
152
153/*
154 * Determine the maximum file size for a superblock
155 */
156static inline
157void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
158{
159 sb->s_maxbytes = (loff_t)maxfilesize;
160 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
161 sb->s_maxbytes = MAX_LFS_FILESIZE;
162}
163
164/*
165 * Check if the string represents a "valid" IPv4 address
166 */
167static inline int valid_ipaddr4(const char *buf)
168{
169 int rc, count, in[4];
170
171 rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
172 if (rc != 4)
173 return -EINVAL;
174 for (count = 0; count < 4; count++) {
175 if (in[count] > 255)
176 return -EINVAL;
177 }
178 return 0;
179}
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
new file mode 100644
index 000000000000..19b98ca468eb
--- /dev/null
+++ b/fs/nfs/namespace.c
@@ -0,0 +1,229 @@
1/*
2 * linux/fs/nfs/namespace.c
3 *
4 * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com>
5 *
6 * NFS namespace
7 */
8
9#include <linux/config.h>
10
11#include <linux/dcache.h>
12#include <linux/mount.h>
13#include <linux/namei.h>
14#include <linux/nfs_fs.h>
15#include <linux/string.h>
16#include <linux/sunrpc/clnt.h>
17#include <linux/vfs.h>
18#include "internal.h"
19
20#define NFSDBG_FACILITY NFSDBG_VFS
21
22static void nfs_expire_automounts(void *list);
23
24LIST_HEAD(nfs_automount_list);
25static DECLARE_WORK(nfs_automount_task, nfs_expire_automounts, &nfs_automount_list);
26int nfs_mountpoint_expiry_timeout = 500 * HZ;
27
28/*
29 * nfs_path - reconstruct the path given an arbitrary dentry
30 * @base - arbitrary string to prepend to the path
31 * @dentry - pointer to dentry
32 * @buffer - result buffer
33 * @buflen - length of buffer
34 *
35 * Helper function for constructing the path from the
36 * root dentry to an arbitrary hashed dentry.
37 *
38 * This is mainly for use in figuring out the path on the
39 * server side when automounting on top of an existing partition.
40 */
41char *nfs_path(const char *base, const struct dentry *dentry,
42 char *buffer, ssize_t buflen)
43{
44 char *end = buffer+buflen;
45 int namelen;
46
47 *--end = '\0';
48 buflen--;
49 spin_lock(&dcache_lock);
50 while (!IS_ROOT(dentry)) {
51 namelen = dentry->d_name.len;
52 buflen -= namelen + 1;
53 if (buflen < 0)
54 goto Elong;
55 end -= namelen;
56 memcpy(end, dentry->d_name.name, namelen);
57 *--end = '/';
58 dentry = dentry->d_parent;
59 }
60 spin_unlock(&dcache_lock);
61 namelen = strlen(base);
62 /* Strip off excess slashes in base string */
63 while (namelen > 0 && base[namelen - 1] == '/')
64 namelen--;
65 buflen -= namelen;
66 if (buflen < 0)
67 goto Elong;
68 end -= namelen;
69 memcpy(end, base, namelen);
70 return end;
71Elong:
72 return ERR_PTR(-ENAMETOOLONG);
73}
74
75/*
76 * nfs_follow_mountpoint - handle crossing a mountpoint on the server
77 * @dentry - dentry of mountpoint
78 * @nd - nameidata info
79 *
80 * When we encounter a mountpoint on the server, we want to set up
81 * a mountpoint on the client too, to prevent inode numbers from
82 * colliding, and to allow "df" to work properly.
83 * On NFSv4, we also want to allow for the fact that different
84 * filesystems may be migrated to different servers in a failover
85 * situation, and that different filesystems may want to use
86 * different security flavours.
87 */
88static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
89{
90 struct vfsmount *mnt;
91 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
92 struct dentry *parent;
93 struct nfs_fh fh;
94 struct nfs_fattr fattr;
95 int err;
96
97 BUG_ON(IS_ROOT(dentry));
98 dprintk("%s: enter\n", __FUNCTION__);
99 dput(nd->dentry);
100 nd->dentry = dget(dentry);
101 if (d_mountpoint(nd->dentry))
102 goto out_follow;
103 /* Look it up again */
104 parent = dget_parent(nd->dentry);
105 err = server->rpc_ops->lookup(parent->d_inode, &nd->dentry->d_name, &fh, &fattr);
106 dput(parent);
107 if (err != 0)
108 goto out_err;
109
110 if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL)
111 mnt = nfs_do_refmount(nd->mnt, nd->dentry);
112 else
113 mnt = nfs_do_submount(nd->mnt, nd->dentry, &fh, &fattr);
114 err = PTR_ERR(mnt);
115 if (IS_ERR(mnt))
116 goto out_err;
117
118 mntget(mnt);
119 err = do_add_mount(mnt, nd, nd->mnt->mnt_flags|MNT_SHRINKABLE, &nfs_automount_list);
120 if (err < 0) {
121 mntput(mnt);
122 if (err == -EBUSY)
123 goto out_follow;
124 goto out_err;
125 }
126 mntput(nd->mnt);
127 dput(nd->dentry);
128 nd->mnt = mnt;
129 nd->dentry = dget(mnt->mnt_root);
130 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
131out:
132 dprintk("%s: done, returned %d\n", __FUNCTION__, err);
133 return ERR_PTR(err);
134out_err:
135 path_release(nd);
136 goto out;
137out_follow:
138 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
139 ;
140 err = 0;
141 goto out;
142}
143
144struct inode_operations nfs_mountpoint_inode_operations = {
145 .follow_link = nfs_follow_mountpoint,
146 .getattr = nfs_getattr,
147};
148
149struct inode_operations nfs_referral_inode_operations = {
150 .follow_link = nfs_follow_mountpoint,
151};
152
153static void nfs_expire_automounts(void *data)
154{
155 struct list_head *list = (struct list_head *)data;
156
157 mark_mounts_for_expiry(list);
158 if (!list_empty(list))
159 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
160}
161
162void nfs_release_automount_timer(void)
163{
164 if (list_empty(&nfs_automount_list)) {
165 cancel_delayed_work(&nfs_automount_task);
166 flush_scheduled_work();
167 }
168}
169
170/*
171 * Clone a mountpoint of the appropriate type
172 */
173static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, char *devname,
174 struct nfs_clone_mount *mountdata)
175{
176#ifdef CONFIG_NFS_V4
177 struct vfsmount *mnt = NULL;
178 switch (server->rpc_ops->version) {
179 case 2:
180 case 3:
181 mnt = vfs_kern_mount(&clone_nfs_fs_type, 0, devname, mountdata);
182 break;
183 case 4:
184 mnt = vfs_kern_mount(&clone_nfs4_fs_type, 0, devname, mountdata);
185 }
186 return mnt;
187#else
188 return vfs_kern_mount(&clone_nfs_fs_type, 0, devname, mountdata);
189#endif
190}
191
192/**
193 * nfs_do_submount - set up mountpoint when crossing a filesystem boundary
194 * @mnt_parent - mountpoint of parent directory
195 * @dentry - parent directory
196 * @fh - filehandle for new root dentry
197 * @fattr - attributes for new root inode
198 *
199 */
200struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent,
201 const struct dentry *dentry, struct nfs_fh *fh,
202 struct nfs_fattr *fattr)
203{
204 struct nfs_clone_mount mountdata = {
205 .sb = mnt_parent->mnt_sb,
206 .dentry = dentry,
207 .fh = fh,
208 .fattr = fattr,
209 };
210 struct vfsmount *mnt = ERR_PTR(-ENOMEM);
211 char *page = (char *) __get_free_page(GFP_USER);
212 char *devname;
213
214 dprintk("%s: submounting on %s/%s\n", __FUNCTION__,
215 dentry->d_parent->d_name.name,
216 dentry->d_name.name);
217 if (page == NULL)
218 goto out;
219 devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE);
220 mnt = (struct vfsmount *)devname;
221 if (IS_ERR(devname))
222 goto free_page;
223 mnt = nfs_do_clone_mount(NFS_SB(mnt_parent->mnt_sb), devname, &mountdata);
224free_page:
225 free_page((unsigned long)page);
226out:
227 dprintk("%s: done\n", __FUNCTION__);
228 return mnt;
229}
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index f0015fa876e1..4a006f81666b 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -27,8 +27,6 @@
27#define NFSDBG_FACILITY NFSDBG_XDR 27#define NFSDBG_FACILITY NFSDBG_XDR
28/* #define NFS_PARANOIA 1 */ 28/* #define NFS_PARANOIA 1 */
29 29
30extern int nfs_stat_to_errno(int stat);
31
32/* Mapping from NFS error code to "errno" error code. */ 30/* Mapping from NFS error code to "errno" error code. */
33#define errno_NFSERR_IO EIO 31#define errno_NFSERR_IO EIO
34 32
@@ -131,7 +129,8 @@ xdr_decode_fattr(u32 *p, struct nfs_fattr *fattr)
131 fattr->du.nfs2.blocksize = ntohl(*p++); 129 fattr->du.nfs2.blocksize = ntohl(*p++);
132 rdev = ntohl(*p++); 130 rdev = ntohl(*p++);
133 fattr->du.nfs2.blocks = ntohl(*p++); 131 fattr->du.nfs2.blocks = ntohl(*p++);
134 fattr->fsid_u.nfs3 = ntohl(*p++); 132 fattr->fsid.major = ntohl(*p++);
133 fattr->fsid.minor = 0;
135 fattr->fileid = ntohl(*p++); 134 fattr->fileid = ntohl(*p++);
136 p = xdr_decode_time(p, &fattr->atime); 135 p = xdr_decode_time(p, &fattr->atime);
137 p = xdr_decode_time(p, &fattr->mtime); 136 p = xdr_decode_time(p, &fattr->mtime);
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 33287879bd23..7322da4d2055 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -172,8 +172,10 @@ static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl,
172 inode->i_ino, acl, dfacl); 172 inode->i_ino, acl, dfacl);
173 spin_lock(&inode->i_lock); 173 spin_lock(&inode->i_lock);
174 __nfs3_forget_cached_acls(NFS_I(inode)); 174 __nfs3_forget_cached_acls(NFS_I(inode));
175 nfsi->acl_access = posix_acl_dup(acl); 175 if (!IS_ERR(acl))
176 nfsi->acl_default = posix_acl_dup(dfacl); 176 nfsi->acl_access = posix_acl_dup(acl);
177 if (!IS_ERR(dfacl))
178 nfsi->acl_default = posix_acl_dup(dfacl);
177 spin_unlock(&inode->i_lock); 179 spin_unlock(&inode->i_lock);
178} 180}
179 181
@@ -254,7 +256,9 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
254 res.acl_access = NULL; 256 res.acl_access = NULL;
255 } 257 }
256 } 258 }
257 nfs3_cache_acls(inode, res.acl_access, res.acl_default); 259 nfs3_cache_acls(inode,
260 (res.mask & NFS_ACL) ? res.acl_access : ERR_PTR(-EINVAL),
261 (res.mask & NFS_DFACL) ? res.acl_default : ERR_PTR(-EINVAL));
258 262
259 switch(type) { 263 switch(type) {
260 case ACL_TYPE_ACCESS: 264 case ACL_TYPE_ACCESS:
@@ -329,6 +333,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
329 switch (status) { 333 switch (status) {
330 case 0: 334 case 0:
331 status = nfs_refresh_inode(inode, &fattr); 335 status = nfs_refresh_inode(inode, &fattr);
336 nfs3_cache_acls(inode, acl, dfacl);
332 break; 337 break;
333 case -EPFNOSUPPORT: 338 case -EPFNOSUPPORT:
334 case -EPROTONOSUPPORT: 339 case -EPROTONOSUPPORT:
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index cf186f0d2b3b..7143b1f82cea 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -20,11 +20,10 @@
20#include <linux/nfs_mount.h> 20#include <linux/nfs_mount.h>
21 21
22#include "iostat.h" 22#include "iostat.h"
23#include "internal.h"
23 24
24#define NFSDBG_FACILITY NFSDBG_PROC 25#define NFSDBG_FACILITY NFSDBG_PROC
25 26
26extern struct rpc_procinfo nfs3_procedures[];
27
28/* A wrapper to handle the EJUKEBOX error message */ 27/* A wrapper to handle the EJUKEBOX error message */
29static int 28static int
30nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) 29nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
@@ -809,8 +808,6 @@ nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
809 return status; 808 return status;
810} 809}
811 810
812extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
813
814static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data) 811static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data)
815{ 812{
816 if (nfs3_async_handle_jukebox(task, data->inode)) 813 if (nfs3_async_handle_jukebox(task, data->inode))
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index ec233619687e..0250269e9753 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -22,14 +22,13 @@
22#include <linux/nfs3.h> 22#include <linux/nfs3.h>
23#include <linux/nfs_fs.h> 23#include <linux/nfs_fs.h>
24#include <linux/nfsacl.h> 24#include <linux/nfsacl.h>
25#include "internal.h"
25 26
26#define NFSDBG_FACILITY NFSDBG_XDR 27#define NFSDBG_FACILITY NFSDBG_XDR
27 28
28/* Mapping from NFS error code to "errno" error code. */ 29/* Mapping from NFS error code to "errno" error code. */
29#define errno_NFSERR_IO EIO 30#define errno_NFSERR_IO EIO
30 31
31extern int nfs_stat_to_errno(int);
32
33/* 32/*
34 * Declare the space requirements for NFS arguments and replies as 33 * Declare the space requirements for NFS arguments and replies as
35 * number of 32bit-words 34 * number of 32bit-words
@@ -166,7 +165,8 @@ xdr_decode_fattr(u32 *p, struct nfs_fattr *fattr)
166 if (MAJOR(fattr->rdev) != major || MINOR(fattr->rdev) != minor) 165 if (MAJOR(fattr->rdev) != major || MINOR(fattr->rdev) != minor)
167 fattr->rdev = 0; 166 fattr->rdev = 0;
168 167
169 p = xdr_decode_hyper(p, &fattr->fsid_u.nfs3); 168 p = xdr_decode_hyper(p, &fattr->fsid.major);
169 fattr->fsid.minor = 0;
170 p = xdr_decode_hyper(p, &fattr->fileid); 170 p = xdr_decode_hyper(p, &fattr->fileid);
171 p = xdr_decode_time3(p, &fattr->atime); 171 p = xdr_decode_time3(p, &fattr->atime);
172 p = xdr_decode_time3(p, &fattr->mtime); 172 p = xdr_decode_time3(p, &fattr->mtime);
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 0f5e4e7cddec..9a102860df37 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -217,6 +217,9 @@ extern int nfs4_proc_renew(struct nfs4_client *, struct rpc_cred *);
217extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state); 217extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state);
218extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); 218extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
219extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *); 219extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
220extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
221extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
222 struct nfs4_fs_locations *fs_locations, struct page *page);
220 223
221extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops; 224extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
222extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops; 225extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
@@ -225,6 +228,7 @@ extern const u32 nfs4_fattr_bitmap[2];
225extern const u32 nfs4_statfs_bitmap[2]; 228extern const u32 nfs4_statfs_bitmap[2];
226extern const u32 nfs4_pathconf_bitmap[2]; 229extern const u32 nfs4_pathconf_bitmap[2];
227extern const u32 nfs4_fsinfo_bitmap[2]; 230extern const u32 nfs4_fsinfo_bitmap[2];
231extern const u32 nfs4_fs_locations_bitmap[2];
228 232
229/* nfs4renewd.c */ 233/* nfs4renewd.c */
230extern void nfs4_schedule_state_renewal(struct nfs4_client *); 234extern void nfs4_schedule_state_renewal(struct nfs4_client *);
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
new file mode 100644
index 000000000000..ea38d27b74e6
--- /dev/null
+++ b/fs/nfs/nfs4namespace.c
@@ -0,0 +1,201 @@
1/*
2 * linux/fs/nfs/nfs4namespace.c
3 *
4 * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com>
5 *
6 * NFSv4 namespace
7 */
8
9#include <linux/config.h>
10
11#include <linux/dcache.h>
12#include <linux/mount.h>
13#include <linux/namei.h>
14#include <linux/nfs_fs.h>
15#include <linux/string.h>
16#include <linux/sunrpc/clnt.h>
17#include <linux/vfs.h>
18#include <linux/inet.h>
19#include "internal.h"
20
21#define NFSDBG_FACILITY NFSDBG_VFS
22
23/*
24 * Check if fs_root is valid
25 */
26static inline char *nfs4_pathname_string(struct nfs4_pathname *pathname,
27 char *buffer, ssize_t buflen)
28{
29 char *end = buffer + buflen;
30 int n;
31
32 *--end = '\0';
33 buflen--;
34
35 n = pathname->ncomponents;
36 while (--n >= 0) {
37 struct nfs4_string *component = &pathname->components[n];
38 buflen -= component->len + 1;
39 if (buflen < 0)
40 goto Elong;
41 end -= component->len;
42 memcpy(end, component->data, component->len);
43 *--end = '/';
44 }
45 return end;
46Elong:
47 return ERR_PTR(-ENAMETOOLONG);
48}
49
50
51/**
52 * nfs_follow_referral - set up mountpoint when hitting a referral on moved error
53 * @mnt_parent - mountpoint of parent directory
54 * @dentry - parent directory
55 * @fspath - fs path returned in fs_locations
56 * @mntpath - mount path to new server
57 * @hostname - hostname of new server
58 * @addr - host addr of new server
59 *
60 */
61static struct vfsmount *nfs_follow_referral(const struct vfsmount *mnt_parent,
62 const struct dentry *dentry,
63 struct nfs4_fs_locations *locations)
64{
65 struct vfsmount *mnt = ERR_PTR(-ENOENT);
66 struct nfs_clone_mount mountdata = {
67 .sb = mnt_parent->mnt_sb,
68 .dentry = dentry,
69 .authflavor = NFS_SB(mnt_parent->mnt_sb)->client->cl_auth->au_flavor,
70 };
71 char *page, *page2;
72 char *path, *fs_path;
73 char *devname;
74 int loc, s;
75
76 if (locations == NULL || locations->nlocations <= 0)
77 goto out;
78
79 dprintk("%s: referral at %s/%s\n", __FUNCTION__,
80 dentry->d_parent->d_name.name, dentry->d_name.name);
81
82 /* Ensure fs path is a prefix of current dentry path */
83 page = (char *) __get_free_page(GFP_USER);
84 if (page == NULL)
85 goto out;
86 page2 = (char *) __get_free_page(GFP_USER);
87 if (page2 == NULL)
88 goto out;
89
90 path = nfs4_path(dentry, page, PAGE_SIZE);
91 if (IS_ERR(path))
92 goto out_free;
93
94 fs_path = nfs4_pathname_string(&locations->fs_path, page2, PAGE_SIZE);
95 if (IS_ERR(fs_path))
96 goto out_free;
97
98 if (strncmp(path, fs_path, strlen(fs_path)) != 0) {
99 dprintk("%s: path %s does not begin with fsroot %s\n", __FUNCTION__, path, fs_path);
100 goto out_free;
101 }
102
103 devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE);
104 if (IS_ERR(devname)) {
105 mnt = (struct vfsmount *)devname;
106 goto out_free;
107 }
108
109 loc = 0;
110 while (loc < locations->nlocations && IS_ERR(mnt)) {
111 struct nfs4_fs_location *location = &locations->locations[loc];
112 char *mnt_path;
113
114 if (location == NULL || location->nservers <= 0 ||
115 location->rootpath.ncomponents == 0) {
116 loc++;
117 continue;
118 }
119
120 mnt_path = nfs4_pathname_string(&location->rootpath, page2, PAGE_SIZE);
121 if (IS_ERR(mnt_path)) {
122 loc++;
123 continue;
124 }
125 mountdata.mnt_path = mnt_path;
126
127 s = 0;
128 while (s < location->nservers) {
129 struct sockaddr_in addr = {};
130
131 if (location->servers[s].len <= 0 ||
132 valid_ipaddr4(location->servers[s].data) < 0) {
133 s++;
134 continue;
135 }
136
137 mountdata.hostname = location->servers[s].data;
138 addr.sin_addr.s_addr = in_aton(mountdata.hostname);
139 addr.sin_family = AF_INET;
140 addr.sin_port = htons(NFS_PORT);
141 mountdata.addr = &addr;
142
143 mnt = vfs_kern_mount(&nfs_referral_nfs4_fs_type, 0, devname, &mountdata);
144 if (!IS_ERR(mnt)) {
145 break;
146 }
147 s++;
148 }
149 loc++;
150 }
151
152out_free:
153 free_page((unsigned long)page);
154 free_page((unsigned long)page2);
155out:
156 dprintk("%s: done\n", __FUNCTION__);
157 return mnt;
158}
159
160/*
161 * nfs_do_refmount - handle crossing a referral on server
162 * @dentry - dentry of referral
163 * @nd - nameidata info
164 *
165 */
166struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
167{
168 struct vfsmount *mnt = ERR_PTR(-ENOENT);
169 struct dentry *parent;
170 struct nfs4_fs_locations *fs_locations = NULL;
171 struct page *page;
172 int err;
173
174 /* BUG_ON(IS_ROOT(dentry)); */
175 dprintk("%s: enter\n", __FUNCTION__);
176
177 page = alloc_page(GFP_KERNEL);
178 if (page == NULL)
179 goto out;
180
181 fs_locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
182 if (fs_locations == NULL)
183 goto out_free;
184
185 /* Get locations */
186 parent = dget_parent(dentry);
187 dprintk("%s: getting locations for %s/%s\n", __FUNCTION__, parent->d_name.name, dentry->d_name.name);
188 err = nfs4_proc_fs_locations(parent->d_inode, dentry, fs_locations, page);
189 dput(parent);
190 if (err != 0 || fs_locations->nlocations <= 0 ||
191 fs_locations->fs_path.ncomponents <= 0)
192 goto out_free;
193
194 mnt = nfs_follow_referral(mnt_parent, dentry, fs_locations);
195out_free:
196 __free_page(page);
197 kfree(fs_locations);
198out:
199 dprintk("%s: done\n", __FUNCTION__);
200 return mnt;
201}
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index d86c0db7b1e8..b4916b092194 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -65,8 +65,6 @@ static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *)
65static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); 65static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
66static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception); 66static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
67static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp); 67static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp);
68extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
69extern struct rpc_procinfo nfs4_procedures[];
70 68
71/* Prevent leaks of NFSv4 errors into userland */ 69/* Prevent leaks of NFSv4 errors into userland */
72int nfs4_map_errors(int err) 70int nfs4_map_errors(int err)
@@ -121,6 +119,25 @@ const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
121 0 119 0
122}; 120};
123 121
122const u32 nfs4_fs_locations_bitmap[2] = {
123 FATTR4_WORD0_TYPE
124 | FATTR4_WORD0_CHANGE
125 | FATTR4_WORD0_SIZE
126 | FATTR4_WORD0_FSID
127 | FATTR4_WORD0_FILEID
128 | FATTR4_WORD0_FS_LOCATIONS,
129 FATTR4_WORD1_MODE
130 | FATTR4_WORD1_NUMLINKS
131 | FATTR4_WORD1_OWNER
132 | FATTR4_WORD1_OWNER_GROUP
133 | FATTR4_WORD1_RAWDEV
134 | FATTR4_WORD1_SPACE_USED
135 | FATTR4_WORD1_TIME_ACCESS
136 | FATTR4_WORD1_TIME_METADATA
137 | FATTR4_WORD1_TIME_MODIFY
138 | FATTR4_WORD1_MOUNTED_ON_FILEID
139};
140
124static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry, 141static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry,
125 struct nfs4_readdir_arg *readdir) 142 struct nfs4_readdir_arg *readdir)
126{ 143{
@@ -185,15 +202,15 @@ static void renew_lease(const struct nfs_server *server, unsigned long timestamp
185 spin_unlock(&clp->cl_lock); 202 spin_unlock(&clp->cl_lock);
186} 203}
187 204
188static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo) 205static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
189{ 206{
190 struct nfs_inode *nfsi = NFS_I(inode); 207 struct nfs_inode *nfsi = NFS_I(dir);
191 208
192 spin_lock(&inode->i_lock); 209 spin_lock(&dir->i_lock);
193 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 210 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
194 if (cinfo->before == nfsi->change_attr && cinfo->atomic) 211 if (cinfo->before == nfsi->change_attr && cinfo->atomic)
195 nfsi->change_attr = cinfo->after; 212 nfsi->change_attr = cinfo->after;
196 spin_unlock(&inode->i_lock); 213 spin_unlock(&dir->i_lock);
197} 214}
198 215
199struct nfs4_opendata { 216struct nfs4_opendata {
@@ -1331,7 +1348,7 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
1331 return status; 1348 return status;
1332} 1349}
1333 1350
1334static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) 1351int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1335{ 1352{
1336 struct nfs4_exception exception = { }; 1353 struct nfs4_exception exception = { };
1337 int err; 1354 int err;
@@ -1443,6 +1460,50 @@ out:
1443 return nfs4_map_errors(status); 1460 return nfs4_map_errors(status);
1444} 1461}
1445 1462
1463/*
1464 * Get locations and (maybe) other attributes of a referral.
1465 * Note that we'll actually follow the referral later when
1466 * we detect fsid mismatch in inode revalidation
1467 */
1468static int nfs4_get_referral(struct inode *dir, struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
1469{
1470 int status = -ENOMEM;
1471 struct page *page = NULL;
1472 struct nfs4_fs_locations *locations = NULL;
1473 struct dentry dentry = {};
1474
1475 page = alloc_page(GFP_KERNEL);
1476 if (page == NULL)
1477 goto out;
1478 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
1479 if (locations == NULL)
1480 goto out;
1481
1482 dentry.d_name.name = name->name;
1483 dentry.d_name.len = name->len;
1484 status = nfs4_proc_fs_locations(dir, &dentry, locations, page);
1485 if (status != 0)
1486 goto out;
1487 /* Make sure server returned a different fsid for the referral */
1488 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
1489 dprintk("%s: server did not return a different fsid for a referral at %s\n", __FUNCTION__, name->name);
1490 status = -EIO;
1491 goto out;
1492 }
1493
1494 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
1495 fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
1496 if (!fattr->mode)
1497 fattr->mode = S_IFDIR;
1498 memset(fhandle, 0, sizeof(struct nfs_fh));
1499out:
1500 if (page)
1501 __free_page(page);
1502 if (locations)
1503 kfree(locations);
1504 return status;
1505}
1506
1446static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) 1507static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1447{ 1508{
1448 struct nfs4_getattr_arg args = { 1509 struct nfs4_getattr_arg args = {
@@ -1547,6 +1608,8 @@ static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,
1547 1608
1548 dprintk("NFS call lookup %s\n", name->name); 1609 dprintk("NFS call lookup %s\n", name->name);
1549 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 1610 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1611 if (status == -NFS4ERR_MOVED)
1612 status = nfs4_get_referral(dir, name, fattr, fhandle);
1550 dprintk("NFS reply lookup: %d\n", status); 1613 dprintk("NFS reply lookup: %d\n", status);
1551 return status; 1614 return status;
1552} 1615}
@@ -2008,7 +2071,7 @@ static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *
2008 if (!status) { 2071 if (!status) {
2009 update_changeattr(dir, &res.cinfo); 2072 update_changeattr(dir, &res.cinfo);
2010 nfs_post_op_update_inode(dir, res.dir_attr); 2073 nfs_post_op_update_inode(dir, res.dir_attr);
2011 nfs_refresh_inode(inode, res.fattr); 2074 nfs_post_op_update_inode(inode, res.fattr);
2012 } 2075 }
2013 2076
2014 return status; 2077 return status;
@@ -3570,6 +3633,36 @@ ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
3570 return len; 3633 return len;
3571} 3634}
3572 3635
3636int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
3637 struct nfs4_fs_locations *fs_locations, struct page *page)
3638{
3639 struct nfs_server *server = NFS_SERVER(dir);
3640 u32 bitmask[2] = {
3641 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
3642 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
3643 };
3644 struct nfs4_fs_locations_arg args = {
3645 .dir_fh = NFS_FH(dir),
3646 .name = &dentry->d_name,
3647 .page = page,
3648 .bitmask = bitmask,
3649 };
3650 struct rpc_message msg = {
3651 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
3652 .rpc_argp = &args,
3653 .rpc_resp = fs_locations,
3654 };
3655 int status;
3656
3657 dprintk("%s: start\n", __FUNCTION__);
3658 fs_locations->fattr.valid = 0;
3659 fs_locations->server = server;
3660 fs_locations->nlocations = 0;
3661 status = rpc_call_sync(server->client, &msg, 0);
3662 dprintk("%s: returned status = %d\n", __FUNCTION__, status);
3663 return status;
3664}
3665
3573struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = { 3666struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
3574 .recover_open = nfs4_open_reclaim, 3667 .recover_open = nfs4_open_reclaim,
3575 .recover_lock = nfs4_lock_reclaim, 3668 .recover_lock = nfs4_lock_reclaim,
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 7c5d70efe720..1750d996f49f 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -411,6 +411,15 @@ static int nfs_stat_to_errno(int);
411#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 411#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
412 decode_putfh_maxsz + \ 412 decode_putfh_maxsz + \
413 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 413 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
414#define NFS4_enc_fs_locations_sz \
415 (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_getattr_maxsz)
418#define NFS4_dec_fs_locations_sz \
419 (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
421 op_decode_hdr_maxsz + \
422 nfs4_fattr_bitmap_maxsz)
414 423
415static struct { 424static struct {
416 unsigned int mode; 425 unsigned int mode;
@@ -722,6 +731,13 @@ static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
722 bitmask[1] & nfs4_fsinfo_bitmap[1]); 731 bitmask[1] & nfs4_fsinfo_bitmap[1]);
723} 732}
724 733
734static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
735{
736 return encode_getattr_two(xdr,
737 bitmask[0] & nfs4_fs_locations_bitmap[0],
738 bitmask[1] & nfs4_fs_locations_bitmap[1]);
739}
740
725static int encode_getfh(struct xdr_stream *xdr) 741static int encode_getfh(struct xdr_stream *xdr)
726{ 742{
727 uint32_t *p; 743 uint32_t *p;
@@ -2003,6 +2019,38 @@ out:
2003} 2019}
2004 2020
2005/* 2021/*
2022 * Encode FS_LOCATIONS request
2023 */
2024static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations_arg *args)
2025{
2026 struct xdr_stream xdr;
2027 struct compound_hdr hdr = {
2028 .nops = 3,
2029 };
2030 struct rpc_auth *auth = req->rq_task->tk_auth;
2031 int replen;
2032 int status;
2033
2034 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2035 encode_compound_hdr(&xdr, &hdr);
2036 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2037 goto out;
2038 if ((status = encode_lookup(&xdr, args->name)) != 0)
2039 goto out;
2040 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2041 goto out;
2042 /* set up reply
2043 * toplevel_status + OP_PUTFH + status
2044 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2045 */
2046 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2047 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2048 0, PAGE_SIZE);
2049out:
2050 return status;
2051}
2052
2053/*
2006 * START OF "GENERIC" DECODE ROUTINES. 2054 * START OF "GENERIC" DECODE ROUTINES.
2007 * These may look a little ugly since they are imported from a "generic" 2055 * These may look a little ugly since they are imported from a "generic"
2008 * set of XDR encode/decode routines which are intended to be shared by 2056 * set of XDR encode/decode routines which are intended to be shared by
@@ -2036,7 +2084,7 @@ out:
2036 } \ 2084 } \
2037} while (0) 2085} while (0)
2038 2086
2039static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string) 2087static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2040{ 2088{
2041 uint32_t *p; 2089 uint32_t *p;
2042 2090
@@ -2087,7 +2135,7 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2087static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp) 2135static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
2088{ 2136{
2089 uint32_t *p; 2137 uint32_t *p;
2090 uint32_t strlen; 2138 unsigned int strlen;
2091 char *str; 2139 char *str;
2092 2140
2093 READ_BUF(12); 2141 READ_BUF(12);
@@ -2217,7 +2265,7 @@ static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap,
2217 return 0; 2265 return 0;
2218} 2266}
2219 2267
2220static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid) 2268static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2221{ 2269{
2222 uint32_t *p; 2270 uint32_t *p;
2223 2271
@@ -2285,6 +2333,22 @@ static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
2285 return 0; 2333 return 0;
2286} 2334}
2287 2335
2336static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2337{
2338 uint32_t *p;
2339
2340 *fileid = 0;
2341 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2342 return -EIO;
2343 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2344 READ_BUF(8);
2345 READ64(*fileid);
2346 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2347 }
2348 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2349 return 0;
2350}
2351
2288static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2352static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2289{ 2353{
2290 uint32_t *p; 2354 uint32_t *p;
@@ -2336,6 +2400,116 @@ static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
2336 return status; 2400 return status;
2337} 2401}
2338 2402
2403static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2404{
2405 int n;
2406 uint32_t *p;
2407 int status = 0;
2408
2409 READ_BUF(4);
2410 READ32(n);
2411 if (n < 0)
2412 goto out_eio;
2413 if (n == 0)
2414 goto root_path;
2415 dprintk("path ");
2416 path->ncomponents = 0;
2417 while (path->ncomponents < n) {
2418 struct nfs4_string *component = &path->components[path->ncomponents];
2419 status = decode_opaque_inline(xdr, &component->len, &component->data);
2420 if (unlikely(status != 0))
2421 goto out_eio;
2422 if (path->ncomponents != n)
2423 dprintk("/");
2424 dprintk("%s", component->data);
2425 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2426 path->ncomponents++;
2427 else {
2428 dprintk("cannot parse %d components in path\n", n);
2429 goto out_eio;
2430 }
2431 }
2432out:
2433 dprintk("\n");
2434 return status;
2435root_path:
2436/* a root pathname is sent as a zero component4 */
2437 path->ncomponents = 1;
2438 path->components[0].len=0;
2439 path->components[0].data=NULL;
2440 dprintk("path /\n");
2441 goto out;
2442out_eio:
2443 dprintk(" status %d", status);
2444 status = -EIO;
2445 goto out;
2446}
2447
2448static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2449{
2450 int n;
2451 uint32_t *p;
2452 int status = -EIO;
2453
2454 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2455 goto out;
2456 status = 0;
2457 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2458 goto out;
2459 dprintk("%s: fsroot ", __FUNCTION__);
2460 status = decode_pathname(xdr, &res->fs_path);
2461 if (unlikely(status != 0))
2462 goto out;
2463 READ_BUF(4);
2464 READ32(n);
2465 if (n <= 0)
2466 goto out_eio;
2467 res->nlocations = 0;
2468 while (res->nlocations < n) {
2469 int m;
2470 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2471
2472 READ_BUF(4);
2473 READ32(m);
2474 if (m <= 0)
2475 goto out_eio;
2476
2477 loc->nservers = 0;
2478 dprintk("%s: servers ", __FUNCTION__);
2479 while (loc->nservers < m) {
2480 struct nfs4_string *server = &loc->servers[loc->nservers];
2481 status = decode_opaque_inline(xdr, &server->len, &server->data);
2482 if (unlikely(status != 0))
2483 goto out_eio;
2484 dprintk("%s ", server->data);
2485 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2486 loc->nservers++;
2487 else {
2488 int i;
2489 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2490 for (i = loc->nservers; i < m; i++) {
2491 int len;
2492 char *data;
2493 status = decode_opaque_inline(xdr, &len, &data);
2494 if (unlikely(status != 0))
2495 goto out_eio;
2496 }
2497 }
2498 }
2499 status = decode_pathname(xdr, &loc->rootpath);
2500 if (unlikely(status != 0))
2501 goto out_eio;
2502 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2503 res->nlocations++;
2504 }
2505out:
2506 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2507 return status;
2508out_eio:
2509 status = -EIO;
2510 goto out;
2511}
2512
2339static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2513static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2340{ 2514{
2341 uint32_t *p; 2515 uint32_t *p;
@@ -2841,6 +3015,7 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
2841 bitmap[2] = {0}, 3015 bitmap[2] = {0},
2842 type; 3016 type;
2843 int status, fmode = 0; 3017 int status, fmode = 0;
3018 uint64_t fileid;
2844 3019
2845 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3020 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2846 goto xdr_error; 3021 goto xdr_error;
@@ -2863,10 +3038,14 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
2863 goto xdr_error; 3038 goto xdr_error;
2864 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0) 3039 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2865 goto xdr_error; 3040 goto xdr_error;
2866 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0) 3041 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
2867 goto xdr_error; 3042 goto xdr_error;
2868 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0) 3043 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2869 goto xdr_error; 3044 goto xdr_error;
3045 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3046 struct nfs4_fs_locations,
3047 fattr))) != 0)
3048 goto xdr_error;
2870 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0) 3049 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2871 goto xdr_error; 3050 goto xdr_error;
2872 fattr->mode |= fmode; 3051 fattr->mode |= fmode;
@@ -2886,6 +3065,10 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
2886 goto xdr_error; 3065 goto xdr_error;
2887 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0) 3066 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2888 goto xdr_error; 3067 goto xdr_error;
3068 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3069 goto xdr_error;
3070 if (fattr->fileid == 0 && fileid != 0)
3071 fattr->fileid = fileid;
2889 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) 3072 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
2890 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4; 3073 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2891xdr_error: 3074xdr_error:
@@ -3350,8 +3533,7 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3350 attrlen, recvd); 3533 attrlen, recvd);
3351 return -EINVAL; 3534 return -EINVAL;
3352 } 3535 }
3353 if (attrlen <= *acl_len) 3536 xdr_read_pages(xdr, attrlen);
3354 xdr_read_pages(xdr, attrlen);
3355 *acl_len = attrlen; 3537 *acl_len = attrlen;
3356 } else 3538 } else
3357 status = -EOPNOTSUPP; 3539 status = -EOPNOTSUPP;
@@ -4211,6 +4393,29 @@ out:
4211 return status; 4393 return status;
4212} 4394}
4213 4395
4396/*
4397 * FS_LOCATIONS request
4398 */
4399static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations *res)
4400{
4401 struct xdr_stream xdr;
4402 struct compound_hdr hdr;
4403 int status;
4404
4405 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4406 status = decode_compound_hdr(&xdr, &hdr);
4407 if (status != 0)
4408 goto out;
4409 if ((status = decode_putfh(&xdr)) != 0)
4410 goto out;
4411 if ((status = decode_lookup(&xdr)) != 0)
4412 goto out;
4413 xdr_enter_page(&xdr, PAGE_SIZE);
4414 status = decode_getfattr(&xdr, &res->fattr, res->server);
4415out:
4416 return status;
4417}
4418
4214uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus) 4419uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4215{ 4420{
4216 uint32_t bitmap[2] = {0}; 4421 uint32_t bitmap[2] = {0};
@@ -4382,6 +4587,7 @@ struct rpc_procinfo nfs4_procedures[] = {
4382 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 4587 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4383 PROC(GETACL, enc_getacl, dec_getacl), 4588 PROC(GETACL, enc_getacl, dec_getacl),
4384 PROC(SETACL, enc_setacl, dec_setacl), 4589 PROC(SETACL, enc_setacl, dec_setacl),
4590 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4385}; 4591};
4386 4592
4387struct rpc_version nfs_version4 = { 4593struct rpc_version nfs_version4 = {
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 106aca388ebc..ef9429643ebc 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -325,6 +325,7 @@ out:
325 325
326/** 326/**
327 * nfs_scan_list - Scan a list for matching requests 327 * nfs_scan_list - Scan a list for matching requests
328 * @nfsi: NFS inode
328 * @head: One of the NFS inode request lists 329 * @head: One of the NFS inode request lists
329 * @dst: Destination list 330 * @dst: Destination list
330 * @idx_start: lower bound of page->index to scan 331 * @idx_start: lower bound of page->index to scan
@@ -336,14 +337,15 @@ out:
336 * The requests are *not* checked to ensure that they form a contiguous set. 337 * The requests are *not* checked to ensure that they form a contiguous set.
337 * You must be holding the inode's req_lock when calling this function 338 * You must be holding the inode's req_lock when calling this function
338 */ 339 */
339int 340int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head,
340nfs_scan_list(struct list_head *head, struct list_head *dst, 341 struct list_head *dst, unsigned long idx_start,
341 unsigned long idx_start, unsigned int npages) 342 unsigned int npages)
342{ 343{
343 struct list_head *pos, *tmp; 344 struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES];
344 struct nfs_page *req; 345 struct nfs_page *req;
345 unsigned long idx_end; 346 unsigned long idx_end;
346 int res; 347 int found, i;
348 int res;
347 349
348 res = 0; 350 res = 0;
349 if (npages == 0) 351 if (npages == 0)
@@ -351,25 +353,32 @@ nfs_scan_list(struct list_head *head, struct list_head *dst,
351 else 353 else
352 idx_end = idx_start + npages - 1; 354 idx_end = idx_start + npages - 1;
353 355
354 list_for_each_safe(pos, tmp, head) { 356 for (;;) {
355 357 found = radix_tree_gang_lookup(&nfsi->nfs_page_tree,
356 req = nfs_list_entry(pos); 358 (void **)&pgvec[0], idx_start,
357 359 NFS_SCAN_MAXENTRIES);
358 if (req->wb_index < idx_start) 360 if (found <= 0)
359 continue;
360 if (req->wb_index > idx_end)
361 break; 361 break;
362 for (i = 0; i < found; i++) {
363 req = pgvec[i];
364 if (req->wb_index > idx_end)
365 goto out;
366 idx_start = req->wb_index + 1;
367 if (req->wb_list_head != head)
368 continue;
369 if (nfs_set_page_writeback_locked(req)) {
370 nfs_list_remove_request(req);
371 nfs_list_add_request(req, dst);
372 res++;
373 }
374 }
362 375
363 if (!nfs_set_page_writeback_locked(req))
364 continue;
365 nfs_list_remove_request(req);
366 nfs_list_add_request(req, dst);
367 res++;
368 } 376 }
377out:
369 return res; 378 return res;
370} 379}
371 380
372int nfs_init_nfspagecache(void) 381int __init nfs_init_nfspagecache(void)
373{ 382{
374 nfs_page_cachep = kmem_cache_create("nfs_page", 383 nfs_page_cachep = kmem_cache_create("nfs_page",
375 sizeof(struct nfs_page), 384 sizeof(struct nfs_page),
@@ -381,7 +390,7 @@ int nfs_init_nfspagecache(void)
381 return 0; 390 return 0;
382} 391}
383 392
384void nfs_destroy_nfspagecache(void) 393void __exit nfs_destroy_nfspagecache(void)
385{ 394{
386 if (kmem_cache_destroy(nfs_page_cachep)) 395 if (kmem_cache_destroy(nfs_page_cachep))
387 printk(KERN_INFO "nfs_page: not all structures were freed\n"); 396 printk(KERN_INFO "nfs_page: not all structures were freed\n");
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 9dd85cac2df0..b3899ea3229e 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -44,11 +44,10 @@
44#include <linux/nfs_page.h> 44#include <linux/nfs_page.h>
45#include <linux/lockd/bind.h> 45#include <linux/lockd/bind.h>
46#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
47#include "internal.h"
47 48
48#define NFSDBG_FACILITY NFSDBG_PROC 49#define NFSDBG_FACILITY NFSDBG_PROC
49 50
50extern struct rpc_procinfo nfs_procedures[];
51
52/* 51/*
53 * Bare-bones access to getattr: this is for nfs_read_super. 52 * Bare-bones access to getattr: this is for nfs_read_super.
54 */ 53 */
@@ -611,8 +610,6 @@ nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
611 return 0; 610 return 0;
612} 611}
613 612
614extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
615
616static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data) 613static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
617{ 614{
618 if (task->tk_status >= 0) { 615 if (task->tk_status >= 0) {
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 624ca7146b6b..41c2ffee24f5 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -51,14 +51,11 @@ struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
51 if (p) { 51 if (p) {
52 memset(p, 0, sizeof(*p)); 52 memset(p, 0, sizeof(*p));
53 INIT_LIST_HEAD(&p->pages); 53 INIT_LIST_HEAD(&p->pages);
54 if (pagecount < NFS_PAGEVEC_SIZE) 54 if (pagecount <= ARRAY_SIZE(p->page_array))
55 p->pagevec = &p->page_array[0]; 55 p->pagevec = p->page_array;
56 else { 56 else {
57 size_t size = ++pagecount * sizeof(struct page *); 57 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
58 p->pagevec = kmalloc(size, GFP_NOFS); 58 if (!p->pagevec) {
59 if (p->pagevec) {
60 memset(p->pagevec, 0, size);
61 } else {
62 mempool_free(p, nfs_rdata_mempool); 59 mempool_free(p, nfs_rdata_mempool);
63 p = NULL; 60 p = NULL;
64 } 61 }
@@ -104,6 +101,28 @@ int nfs_return_empty_page(struct page *page)
104 return 0; 101 return 0;
105} 102}
106 103
104static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data)
105{
106 unsigned int remainder = data->args.count - data->res.count;
107 unsigned int base = data->args.pgbase + data->res.count;
108 unsigned int pglen;
109 struct page **pages;
110
111 if (data->res.eof == 0 || remainder == 0)
112 return;
113 /*
114 * Note: "remainder" can never be negative, since we check for
115 * this in the XDR code.
116 */
117 pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
118 base &= ~PAGE_CACHE_MASK;
119 pglen = PAGE_CACHE_SIZE - base;
120 if (pglen < remainder)
121 memclear_highpage_flush(*pages, base, pglen);
122 else
123 memclear_highpage_flush(*pages, base, remainder);
124}
125
107/* 126/*
108 * Read a page synchronously. 127 * Read a page synchronously.
109 */ 128 */
@@ -177,11 +196,9 @@ static int nfs_readpage_sync(struct nfs_open_context *ctx, struct inode *inode,
177 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME; 196 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME;
178 spin_unlock(&inode->i_lock); 197 spin_unlock(&inode->i_lock);
179 198
180 if (count) 199 nfs_readpage_truncate_uninitialised_page(rdata);
181 memclear_highpage_flush(page, rdata->args.pgbase, count); 200 if (rdata->res.eof || rdata->res.count == rdata->args.count)
182 SetPageUptodate(page); 201 SetPageUptodate(page);
183 if (PageError(page))
184 ClearPageError(page);
185 result = 0; 202 result = 0;
186 203
187io_error: 204io_error:
@@ -436,20 +453,12 @@ static void nfs_readpage_result_partial(struct rpc_task *task, void *calldata)
436 struct nfs_page *req = data->req; 453 struct nfs_page *req = data->req;
437 struct page *page = req->wb_page; 454 struct page *page = req->wb_page;
438 455
456 if (likely(task->tk_status >= 0))
457 nfs_readpage_truncate_uninitialised_page(data);
458 else
459 SetPageError(page);
439 if (nfs_readpage_result(task, data) != 0) 460 if (nfs_readpage_result(task, data) != 0)
440 return; 461 return;
441 if (task->tk_status >= 0) {
442 unsigned int request = data->args.count;
443 unsigned int result = data->res.count;
444
445 if (result < request) {
446 memclear_highpage_flush(page,
447 data->args.pgbase + result,
448 request - result);
449 }
450 } else
451 SetPageError(page);
452
453 if (atomic_dec_and_test(&req->wb_complete)) { 462 if (atomic_dec_and_test(&req->wb_complete)) {
454 if (!PageError(page)) 463 if (!PageError(page))
455 SetPageUptodate(page); 464 SetPageUptodate(page);
@@ -462,6 +471,40 @@ static const struct rpc_call_ops nfs_read_partial_ops = {
462 .rpc_release = nfs_readdata_release, 471 .rpc_release = nfs_readdata_release,
463}; 472};
464 473
474static void nfs_readpage_set_pages_uptodate(struct nfs_read_data *data)
475{
476 unsigned int count = data->res.count;
477 unsigned int base = data->args.pgbase;
478 struct page **pages;
479
480 if (unlikely(count == 0))
481 return;
482 pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
483 base &= ~PAGE_CACHE_MASK;
484 count += base;
485 for (;count >= PAGE_CACHE_SIZE; count -= PAGE_CACHE_SIZE, pages++)
486 SetPageUptodate(*pages);
487 /*
488 * Was this an eof or a short read? If the latter, don't mark the page
489 * as uptodate yet.
490 */
491 if (count > 0 && (data->res.eof || data->args.count == data->res.count))
492 SetPageUptodate(*pages);
493}
494
495static void nfs_readpage_set_pages_error(struct nfs_read_data *data)
496{
497 unsigned int count = data->args.count;
498 unsigned int base = data->args.pgbase;
499 struct page **pages;
500
501 pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
502 base &= ~PAGE_CACHE_MASK;
503 count += base;
504 for (;count >= PAGE_CACHE_SIZE; count -= PAGE_CACHE_SIZE, pages++)
505 SetPageError(*pages);
506}
507
465/* 508/*
466 * This is the callback from RPC telling us whether a reply was 509 * This is the callback from RPC telling us whether a reply was
467 * received or some error occurred (timeout or socket shutdown). 510 * received or some error occurred (timeout or socket shutdown).
@@ -469,27 +512,24 @@ static const struct rpc_call_ops nfs_read_partial_ops = {
469static void nfs_readpage_result_full(struct rpc_task *task, void *calldata) 512static void nfs_readpage_result_full(struct rpc_task *task, void *calldata)
470{ 513{
471 struct nfs_read_data *data = calldata; 514 struct nfs_read_data *data = calldata;
472 unsigned int count = data->res.count;
473 515
516 /*
517 * Note: nfs_readpage_result may change the values of
518 * data->args. In the multi-page case, we therefore need
519 * to ensure that we call the next nfs_readpage_set_page_uptodate()
520 * first in the multi-page case.
521 */
522 if (likely(task->tk_status >= 0)) {
523 nfs_readpage_truncate_uninitialised_page(data);
524 nfs_readpage_set_pages_uptodate(data);
525 } else
526 nfs_readpage_set_pages_error(data);
474 if (nfs_readpage_result(task, data) != 0) 527 if (nfs_readpage_result(task, data) != 0)
475 return; 528 return;
476 while (!list_empty(&data->pages)) { 529 while (!list_empty(&data->pages)) {
477 struct nfs_page *req = nfs_list_entry(data->pages.next); 530 struct nfs_page *req = nfs_list_entry(data->pages.next);
478 struct page *page = req->wb_page;
479 nfs_list_remove_request(req);
480 531
481 if (task->tk_status >= 0) { 532 nfs_list_remove_request(req);
482 if (count < PAGE_CACHE_SIZE) {
483 if (count < req->wb_bytes)
484 memclear_highpage_flush(page,
485 req->wb_pgbase + count,
486 req->wb_bytes - count);
487 count = 0;
488 } else
489 count -= PAGE_CACHE_SIZE;
490 SetPageUptodate(page);
491 } else
492 SetPageError(page);
493 nfs_readpage_release(req); 533 nfs_readpage_release(req);
494 } 534 }
495} 535}
@@ -654,7 +694,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
654 return ret; 694 return ret;
655} 695}
656 696
657int nfs_init_readpagecache(void) 697int __init nfs_init_readpagecache(void)
658{ 698{
659 nfs_rdata_cachep = kmem_cache_create("nfs_read_data", 699 nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
660 sizeof(struct nfs_read_data), 700 sizeof(struct nfs_read_data),
@@ -671,7 +711,7 @@ int nfs_init_readpagecache(void)
671 return 0; 711 return 0;
672} 712}
673 713
674void nfs_destroy_readpagecache(void) 714void __exit nfs_destroy_readpagecache(void)
675{ 715{
676 mempool_destroy(nfs_rdata_mempool); 716 mempool_destroy(nfs_rdata_mempool);
677 if (kmem_cache_destroy(nfs_rdata_cachep)) 717 if (kmem_cache_destroy(nfs_rdata_cachep))
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
new file mode 100644
index 000000000000..30f939bcb724
--- /dev/null
+++ b/fs/nfs/super.c
@@ -0,0 +1,1497 @@
1/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
16 */
17
18#include <linux/config.h>
19#include <linux/module.h>
20#include <linux/init.h>
21
22#include <linux/time.h>
23#include <linux/kernel.h>
24#include <linux/mm.h>
25#include <linux/string.h>
26#include <linux/stat.h>
27#include <linux/errno.h>
28#include <linux/unistd.h>
29#include <linux/sunrpc/clnt.h>
30#include <linux/sunrpc/stats.h>
31#include <linux/sunrpc/metrics.h>
32#include <linux/nfs_fs.h>
33#include <linux/nfs_mount.h>
34#include <linux/nfs4_mount.h>
35#include <linux/lockd/bind.h>
36#include <linux/smp_lock.h>
37#include <linux/seq_file.h>
38#include <linux/mount.h>
39#include <linux/nfs_idmap.h>
40#include <linux/vfs.h>
41#include <linux/inet.h>
42#include <linux/nfs_xdr.h>
43
44#include <asm/system.h>
45#include <asm/uaccess.h>
46
47#include "nfs4_fs.h"
48#include "callback.h"
49#include "delegation.h"
50#include "iostat.h"
51#include "internal.h"
52
53#define NFSDBG_FACILITY NFSDBG_VFS
54
55/* Maximum number of readahead requests
56 * FIXME: this should really be a sysctl so that users may tune it to suit
57 * their needs. People that do NFS over a slow network, might for
58 * instance want to reduce it to something closer to 1 for improved
59 * interactive response.
60 */
61#define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
62
63/*
64 * RPC cruft for NFS
65 */
66static struct rpc_version * nfs_version[] = {
67 NULL,
68 NULL,
69 &nfs_version2,
70#if defined(CONFIG_NFS_V3)
71 &nfs_version3,
72#elif defined(CONFIG_NFS_V4)
73 NULL,
74#endif
75#if defined(CONFIG_NFS_V4)
76 &nfs_version4,
77#endif
78};
79
80static struct rpc_program nfs_program = {
81 .name = "nfs",
82 .number = NFS_PROGRAM,
83 .nrvers = ARRAY_SIZE(nfs_version),
84 .version = nfs_version,
85 .stats = &nfs_rpcstat,
86 .pipe_dir_name = "/nfs",
87};
88
89struct rpc_stat nfs_rpcstat = {
90 .program = &nfs_program
91};
92
93
94#ifdef CONFIG_NFS_V3_ACL
95static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
96static struct rpc_version * nfsacl_version[] = {
97 [3] = &nfsacl_version3,
98};
99
100struct rpc_program nfsacl_program = {
101 .name = "nfsacl",
102 .number = NFS_ACL_PROGRAM,
103 .nrvers = ARRAY_SIZE(nfsacl_version),
104 .version = nfsacl_version,
105 .stats = &nfsacl_rpcstat,
106};
107#endif /* CONFIG_NFS_V3_ACL */
108
109static void nfs_umount_begin(struct vfsmount *, int);
110static int nfs_statfs(struct super_block *, struct kstatfs *);
111static int nfs_show_options(struct seq_file *, struct vfsmount *);
112static int nfs_show_stats(struct seq_file *, struct vfsmount *);
113static struct super_block *nfs_get_sb(struct file_system_type *, int, const char *, void *);
114static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type,
115 int flags, const char *dev_name, void *raw_data);
116static void nfs_kill_super(struct super_block *);
117
118static struct file_system_type nfs_fs_type = {
119 .owner = THIS_MODULE,
120 .name = "nfs",
121 .get_sb = nfs_get_sb,
122 .kill_sb = nfs_kill_super,
123 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
124};
125
126struct file_system_type clone_nfs_fs_type = {
127 .owner = THIS_MODULE,
128 .name = "nfs",
129 .get_sb = nfs_clone_nfs_sb,
130 .kill_sb = nfs_kill_super,
131 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
132};
133
134static struct super_operations nfs_sops = {
135 .alloc_inode = nfs_alloc_inode,
136 .destroy_inode = nfs_destroy_inode,
137 .write_inode = nfs_write_inode,
138 .statfs = nfs_statfs,
139 .clear_inode = nfs_clear_inode,
140 .umount_begin = nfs_umount_begin,
141 .show_options = nfs_show_options,
142 .show_stats = nfs_show_stats,
143};
144
145#ifdef CONFIG_NFS_V4
146static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
147 int flags, const char *dev_name, void *raw_data);
148static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type,
149 int flags, const char *dev_name, void *raw_data);
150static struct super_block *nfs_referral_nfs4_sb(struct file_system_type *fs_type,
151 int flags, const char *dev_name, void *raw_data);
152static void nfs4_kill_super(struct super_block *sb);
153
154static struct file_system_type nfs4_fs_type = {
155 .owner = THIS_MODULE,
156 .name = "nfs4",
157 .get_sb = nfs4_get_sb,
158 .kill_sb = nfs4_kill_super,
159 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
160};
161
162struct file_system_type clone_nfs4_fs_type = {
163 .owner = THIS_MODULE,
164 .name = "nfs4",
165 .get_sb = nfs_clone_nfs4_sb,
166 .kill_sb = nfs4_kill_super,
167 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
168};
169
170struct file_system_type nfs_referral_nfs4_fs_type = {
171 .owner = THIS_MODULE,
172 .name = "nfs4",
173 .get_sb = nfs_referral_nfs4_sb,
174 .kill_sb = nfs4_kill_super,
175 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
176};
177
178static struct super_operations nfs4_sops = {
179 .alloc_inode = nfs_alloc_inode,
180 .destroy_inode = nfs_destroy_inode,
181 .write_inode = nfs_write_inode,
182 .statfs = nfs_statfs,
183 .clear_inode = nfs4_clear_inode,
184 .umount_begin = nfs_umount_begin,
185 .show_options = nfs_show_options,
186 .show_stats = nfs_show_stats,
187};
188#endif
189
190static const int nfs_set_port_min = 0;
191static const int nfs_set_port_max = 65535;
192
193static int param_set_port(const char *val, struct kernel_param *kp)
194{
195 char *endp;
196 int num = simple_strtol(val, &endp, 0);
197 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
198 return -EINVAL;
199 *((int *)kp->arg) = num;
200 return 0;
201}
202
203module_param_call(callback_tcpport, param_set_port, param_get_int,
204 &nfs_callback_set_tcpport, 0644);
205
206static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
207{
208 char *endp;
209 int num = simple_strtol(val, &endp, 0);
210 int jif = num * HZ;
211 if (endp == val || *endp || num < 0 || jif < num)
212 return -EINVAL;
213 *((int *)kp->arg) = jif;
214 return 0;
215}
216
217module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
218 &nfs_idmap_cache_timeout, 0644);
219
220/*
221 * Register the NFS filesystems
222 */
223int __init register_nfs_fs(void)
224{
225 int ret;
226
227 ret = register_filesystem(&nfs_fs_type);
228 if (ret < 0)
229 goto error_0;
230
231#ifdef CONFIG_NFS_V4
232 ret = nfs_register_sysctl();
233 if (ret < 0)
234 goto error_1;
235 ret = register_filesystem(&nfs4_fs_type);
236 if (ret < 0)
237 goto error_2;
238#endif
239 return 0;
240
241#ifdef CONFIG_NFS_V4
242error_2:
243 nfs_unregister_sysctl();
244error_1:
245 unregister_filesystem(&nfs_fs_type);
246#endif
247error_0:
248 return ret;
249}
250
251/*
252 * Unregister the NFS filesystems
253 */
254void __exit unregister_nfs_fs(void)
255{
256#ifdef CONFIG_NFS_V4
257 unregister_filesystem(&nfs4_fs_type);
258 nfs_unregister_sysctl();
259#endif
260 unregister_filesystem(&nfs_fs_type);
261}
262
263/*
264 * Deliver file system statistics to userspace
265 */
266static int nfs_statfs(struct super_block *sb, struct kstatfs *buf)
267{
268 struct nfs_server *server = NFS_SB(sb);
269 unsigned char blockbits;
270 unsigned long blockres;
271 struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode);
272 struct nfs_fattr fattr;
273 struct nfs_fsstat res = {
274 .fattr = &fattr,
275 };
276 int error;
277
278 lock_kernel();
279
280 error = server->rpc_ops->statfs(server, rootfh, &res);
281 buf->f_type = NFS_SUPER_MAGIC;
282 if (error < 0)
283 goto out_err;
284
285 /*
286 * Current versions of glibc do not correctly handle the
287 * case where f_frsize != f_bsize. Eventually we want to
288 * report the value of wtmult in this field.
289 */
290 buf->f_frsize = sb->s_blocksize;
291
292 /*
293 * On most *nix systems, f_blocks, f_bfree, and f_bavail
294 * are reported in units of f_frsize. Linux hasn't had
295 * an f_frsize field in its statfs struct until recently,
296 * thus historically Linux's sys_statfs reports these
297 * fields in units of f_bsize.
298 */
299 buf->f_bsize = sb->s_blocksize;
300 blockbits = sb->s_blocksize_bits;
301 blockres = (1 << blockbits) - 1;
302 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
303 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
304 buf->f_bavail = (res.abytes + blockres) >> blockbits;
305
306 buf->f_files = res.tfiles;
307 buf->f_ffree = res.afiles;
308
309 buf->f_namelen = server->namelen;
310 out:
311 unlock_kernel();
312 return 0;
313
314 out_err:
315 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
316 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
317 goto out;
318
319}
320
321static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
322{
323 static struct {
324 rpc_authflavor_t flavour;
325 const char *str;
326 } sec_flavours[] = {
327 { RPC_AUTH_NULL, "null" },
328 { RPC_AUTH_UNIX, "sys" },
329 { RPC_AUTH_GSS_KRB5, "krb5" },
330 { RPC_AUTH_GSS_KRB5I, "krb5i" },
331 { RPC_AUTH_GSS_KRB5P, "krb5p" },
332 { RPC_AUTH_GSS_LKEY, "lkey" },
333 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
334 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
335 { RPC_AUTH_GSS_SPKM, "spkm" },
336 { RPC_AUTH_GSS_SPKMI, "spkmi" },
337 { RPC_AUTH_GSS_SPKMP, "spkmp" },
338 { -1, "unknown" }
339 };
340 int i;
341
342 for (i=0; sec_flavours[i].flavour != -1; i++) {
343 if (sec_flavours[i].flavour == flavour)
344 break;
345 }
346 return sec_flavours[i].str;
347}
348
349/*
350 * Describe the mount options in force on this server representation
351 */
352static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
353{
354 static struct proc_nfs_info {
355 int flag;
356 char *str;
357 char *nostr;
358 } nfs_info[] = {
359 { NFS_MOUNT_SOFT, ",soft", ",hard" },
360 { NFS_MOUNT_INTR, ",intr", "" },
361 { NFS_MOUNT_NOCTO, ",nocto", "" },
362 { NFS_MOUNT_NOAC, ",noac", "" },
363 { NFS_MOUNT_NONLM, ",nolock", "" },
364 { NFS_MOUNT_NOACL, ",noacl", "" },
365 { 0, NULL, NULL }
366 };
367 struct proc_nfs_info *nfs_infop;
368 char buf[12];
369 char *proto;
370
371 seq_printf(m, ",vers=%d", nfss->rpc_ops->version);
372 seq_printf(m, ",rsize=%d", nfss->rsize);
373 seq_printf(m, ",wsize=%d", nfss->wsize);
374 if (nfss->acregmin != 3*HZ || showdefaults)
375 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
376 if (nfss->acregmax != 60*HZ || showdefaults)
377 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
378 if (nfss->acdirmin != 30*HZ || showdefaults)
379 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
380 if (nfss->acdirmax != 60*HZ || showdefaults)
381 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
382 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
383 if (nfss->flags & nfs_infop->flag)
384 seq_puts(m, nfs_infop->str);
385 else
386 seq_puts(m, nfs_infop->nostr);
387 }
388 switch (nfss->client->cl_xprt->prot) {
389 case IPPROTO_TCP:
390 proto = "tcp";
391 break;
392 case IPPROTO_UDP:
393 proto = "udp";
394 break;
395 default:
396 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
397 proto = buf;
398 }
399 seq_printf(m, ",proto=%s", proto);
400 seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ);
401 seq_printf(m, ",retrans=%u", nfss->retrans_count);
402 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
403}
404
405/*
406 * Describe the mount options on this VFS mountpoint
407 */
408static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
409{
410 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
411
412 nfs_show_mount_options(m, nfss, 0);
413
414 seq_puts(m, ",addr=");
415 seq_escape(m, nfss->hostname, " \t\n\\");
416
417 return 0;
418}
419
420/*
421 * Present statistical information for this VFS mountpoint
422 */
423static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
424{
425 int i, cpu;
426 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
427 struct rpc_auth *auth = nfss->client->cl_auth;
428 struct nfs_iostats totals = { };
429
430 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
431
432 /*
433 * Display all mount option settings
434 */
435 seq_printf(m, "\n\topts:\t");
436 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
437 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
438 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
439 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
440 nfs_show_mount_options(m, nfss, 1);
441
442 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
443
444 seq_printf(m, "\n\tcaps:\t");
445 seq_printf(m, "caps=0x%x", nfss->caps);
446 seq_printf(m, ",wtmult=%d", nfss->wtmult);
447 seq_printf(m, ",dtsize=%d", nfss->dtsize);
448 seq_printf(m, ",bsize=%d", nfss->bsize);
449 seq_printf(m, ",namelen=%d", nfss->namelen);
450
451#ifdef CONFIG_NFS_V4
452 if (nfss->rpc_ops->version == 4) {
453 seq_printf(m, "\n\tnfsv4:\t");
454 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
455 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
456 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
457 }
458#endif
459
460 /*
461 * Display security flavor in effect for this mount
462 */
463 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
464 if (auth->au_flavor)
465 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
466
467 /*
468 * Display superblock I/O counters
469 */
470 for_each_possible_cpu(cpu) {
471 struct nfs_iostats *stats;
472
473 preempt_disable();
474 stats = per_cpu_ptr(nfss->io_stats, cpu);
475
476 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
477 totals.events[i] += stats->events[i];
478 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
479 totals.bytes[i] += stats->bytes[i];
480
481 preempt_enable();
482 }
483
484 seq_printf(m, "\n\tevents:\t");
485 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
486 seq_printf(m, "%lu ", totals.events[i]);
487 seq_printf(m, "\n\tbytes:\t");
488 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
489 seq_printf(m, "%Lu ", totals.bytes[i]);
490 seq_printf(m, "\n");
491
492 rpc_print_iostats(m, nfss->client);
493
494 return 0;
495}
496
497/*
498 * Begin unmount by attempting to remove all automounted mountpoints we added
499 * in response to traversals
500 */
501static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
502{
503 struct nfs_server *server;
504 struct rpc_clnt *rpc;
505
506 shrink_submounts(vfsmnt, &nfs_automount_list);
507 if (!(flags & MNT_FORCE))
508 return;
509 /* -EIO all pending I/O */
510 server = NFS_SB(vfsmnt->mnt_sb);
511 rpc = server->client;
512 if (!IS_ERR(rpc))
513 rpc_killall_tasks(rpc);
514 rpc = server->client_acl;
515 if (!IS_ERR(rpc))
516 rpc_killall_tasks(rpc);
517}
518
519/*
520 * Obtain the root inode of the file system.
521 */
522static struct inode *
523nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo)
524{
525 struct nfs_server *server = NFS_SB(sb);
526 int error;
527
528 error = server->rpc_ops->getroot(server, rootfh, fsinfo);
529 if (error < 0) {
530 dprintk("nfs_get_root: getattr error = %d\n", -error);
531 return ERR_PTR(error);
532 }
533
534 server->fsid = fsinfo->fattr->fsid;
535 return nfs_fhget(sb, rootfh, fsinfo->fattr);
536}
537
538/*
539 * Do NFS version-independent mount processing, and sanity checking
540 */
541static int
542nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
543{
544 struct nfs_server *server;
545 struct inode *root_inode;
546 struct nfs_fattr fattr;
547 struct nfs_fsinfo fsinfo = {
548 .fattr = &fattr,
549 };
550 struct nfs_pathconf pathinfo = {
551 .fattr = &fattr,
552 };
553 int no_root_error = 0;
554 unsigned long max_rpc_payload;
555
556 /* We probably want something more informative here */
557 snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
558
559 server = NFS_SB(sb);
560
561 sb->s_magic = NFS_SUPER_MAGIC;
562
563 server->io_stats = nfs_alloc_iostats();
564 if (server->io_stats == NULL)
565 return -ENOMEM;
566
567 root_inode = nfs_get_root(sb, &server->fh, &fsinfo);
568 /* Did getting the root inode fail? */
569 if (IS_ERR(root_inode)) {
570 no_root_error = PTR_ERR(root_inode);
571 goto out_no_root;
572 }
573 sb->s_root = d_alloc_root(root_inode);
574 if (!sb->s_root) {
575 no_root_error = -ENOMEM;
576 goto out_no_root;
577 }
578 sb->s_root->d_op = server->rpc_ops->dentry_ops;
579
580 /* mount time stamp, in seconds */
581 server->mount_time = jiffies;
582
583 /* Get some general file system info */
584 if (server->namelen == 0 &&
585 server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0)
586 server->namelen = pathinfo.max_namelen;
587 /* Work out a lot of parameters */
588 if (server->rsize == 0)
589 server->rsize = nfs_block_size(fsinfo.rtpref, NULL);
590 if (server->wsize == 0)
591 server->wsize = nfs_block_size(fsinfo.wtpref, NULL);
592
593 if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax)
594 server->rsize = nfs_block_size(fsinfo.rtmax, NULL);
595 if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax)
596 server->wsize = nfs_block_size(fsinfo.wtmax, NULL);
597
598 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
599 if (server->rsize > max_rpc_payload)
600 server->rsize = max_rpc_payload;
601 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
602 server->rsize = NFS_MAX_FILE_IO_SIZE;
603 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
604
605 if (server->wsize > max_rpc_payload)
606 server->wsize = max_rpc_payload;
607 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
608 server->wsize = NFS_MAX_FILE_IO_SIZE;
609 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
610
611 if (sb->s_blocksize == 0)
612 sb->s_blocksize = nfs_block_bits(server->wsize,
613 &sb->s_blocksize_bits);
614 server->wtmult = nfs_block_bits(fsinfo.wtmult, NULL);
615
616 server->dtsize = nfs_block_size(fsinfo.dtpref, NULL);
617 if (server->dtsize > PAGE_CACHE_SIZE)
618 server->dtsize = PAGE_CACHE_SIZE;
619 if (server->dtsize > server->rsize)
620 server->dtsize = server->rsize;
621
622 if (server->flags & NFS_MOUNT_NOAC) {
623 server->acregmin = server->acregmax = 0;
624 server->acdirmin = server->acdirmax = 0;
625 sb->s_flags |= MS_SYNCHRONOUS;
626 }
627 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
628
629 nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
630
631 server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
632 server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
633
634 /* We're airborne Set socket buffersize */
635 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
636 return 0;
637 /* Yargs. It didn't work out. */
638out_no_root:
639 dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error);
640 if (!IS_ERR(root_inode))
641 iput(root_inode);
642 return no_root_error;
643}
644
645/*
646 * Initialise the timeout values for a connection
647 */
648static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, unsigned int timeo, unsigned int retrans)
649{
650 to->to_initval = timeo * HZ / 10;
651 to->to_retries = retrans;
652 if (!to->to_retries)
653 to->to_retries = 2;
654
655 switch (proto) {
656 case IPPROTO_TCP:
657 if (!to->to_initval)
658 to->to_initval = 60 * HZ;
659 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
660 to->to_initval = NFS_MAX_TCP_TIMEOUT;
661 to->to_increment = to->to_initval;
662 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
663 to->to_exponential = 0;
664 break;
665 case IPPROTO_UDP:
666 default:
667 if (!to->to_initval)
668 to->to_initval = 11 * HZ / 10;
669 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
670 to->to_initval = NFS_MAX_UDP_TIMEOUT;
671 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
672 to->to_exponential = 1;
673 break;
674 }
675}
676
677/*
678 * Create an RPC client handle.
679 */
680static struct rpc_clnt *
681nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
682{
683 struct rpc_timeout timeparms;
684 struct rpc_xprt *xprt = NULL;
685 struct rpc_clnt *clnt = NULL;
686 int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;
687
688 nfs_init_timeout_values(&timeparms, proto, data->timeo, data->retrans);
689
690 server->retrans_timeo = timeparms.to_initval;
691 server->retrans_count = timeparms.to_retries;
692
693 /* create transport and client */
694 xprt = xprt_create_proto(proto, &server->addr, &timeparms);
695 if (IS_ERR(xprt)) {
696 dprintk("%s: cannot create RPC transport. Error = %ld\n",
697 __FUNCTION__, PTR_ERR(xprt));
698 return (struct rpc_clnt *)xprt;
699 }
700 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
701 server->rpc_ops->version, data->pseudoflavor);
702 if (IS_ERR(clnt)) {
703 dprintk("%s: cannot create RPC client. Error = %ld\n",
704 __FUNCTION__, PTR_ERR(xprt));
705 goto out_fail;
706 }
707
708 clnt->cl_intr = 1;
709 clnt->cl_softrtry = 1;
710
711 return clnt;
712
713out_fail:
714 return clnt;
715}
716
717/*
718 * Clone a server record
719 */
720static struct nfs_server *nfs_clone_server(struct super_block *sb, struct nfs_clone_mount *data)
721{
722 struct nfs_server *server = NFS_SB(sb);
723 struct nfs_server *parent = NFS_SB(data->sb);
724 struct inode *root_inode;
725 struct nfs_fsinfo fsinfo;
726 void *err = ERR_PTR(-ENOMEM);
727
728 sb->s_op = data->sb->s_op;
729 sb->s_blocksize = data->sb->s_blocksize;
730 sb->s_blocksize_bits = data->sb->s_blocksize_bits;
731 sb->s_maxbytes = data->sb->s_maxbytes;
732
733 server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
734 server->io_stats = nfs_alloc_iostats();
735 if (server->io_stats == NULL)
736 goto out;
737
738 server->client = rpc_clone_client(parent->client);
739 if (IS_ERR((err = server->client)))
740 goto out;
741
742 if (!IS_ERR(parent->client_sys)) {
743 server->client_sys = rpc_clone_client(parent->client_sys);
744 if (IS_ERR((err = server->client_sys)))
745 goto out;
746 }
747 if (!IS_ERR(parent->client_acl)) {
748 server->client_acl = rpc_clone_client(parent->client_acl);
749 if (IS_ERR((err = server->client_acl)))
750 goto out;
751 }
752 root_inode = nfs_fhget(sb, data->fh, data->fattr);
753 if (!root_inode)
754 goto out;
755 sb->s_root = d_alloc_root(root_inode);
756 if (!sb->s_root)
757 goto out_put_root;
758 fsinfo.fattr = data->fattr;
759 if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0)
760 nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
761 sb->s_root->d_op = server->rpc_ops->dentry_ops;
762 sb->s_flags |= MS_ACTIVE;
763 return server;
764out_put_root:
765 iput(root_inode);
766out:
767 return err;
768}
769
770/*
771 * Copy an existing superblock and attach revised data
772 */
773static struct super_block *nfs_clone_generic_sb(struct nfs_clone_mount *data,
774 struct super_block *(*fill_sb)(struct nfs_server *, struct nfs_clone_mount *),
775 struct nfs_server *(*fill_server)(struct super_block *, struct nfs_clone_mount *))
776{
777 struct nfs_server *server;
778 struct nfs_server *parent = NFS_SB(data->sb);
779 struct super_block *sb = ERR_PTR(-EINVAL);
780 void *err = ERR_PTR(-ENOMEM);
781 char *hostname;
782 int len;
783
784 server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
785 if (server == NULL)
786 goto out_err;
787 memcpy(server, parent, sizeof(*server));
788 hostname = (data->hostname != NULL) ? data->hostname : parent->hostname;
789 len = strlen(hostname) + 1;
790 server->hostname = kmalloc(len, GFP_KERNEL);
791 if (server->hostname == NULL)
792 goto free_server;
793 memcpy(server->hostname, hostname, len);
794 if (rpciod_up() != 0)
795 goto free_hostname;
796
797 sb = fill_sb(server, data);
798 if (IS_ERR((err = sb)) || sb->s_root)
799 goto kill_rpciod;
800
801 server = fill_server(sb, data);
802 if (IS_ERR((err = server)))
803 goto out_deactivate;
804 return sb;
805out_deactivate:
806 up_write(&sb->s_umount);
807 deactivate_super(sb);
808 return (struct super_block *)err;
809kill_rpciod:
810 rpciod_down();
811free_hostname:
812 kfree(server->hostname);
813free_server:
814 kfree(server);
815out_err:
816 return (struct super_block *)err;
817}
818
819/*
820 * Set up an NFS2/3 superblock
821 *
822 * The way this works is that the mount process passes a structure
823 * in the data argument which contains the server's IP address
824 * and the root file handle obtained from the server's mount
825 * daemon. We stash these away in the private superblock fields.
826 */
827static int
828nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
829{
830 struct nfs_server *server;
831 rpc_authflavor_t authflavor;
832
833 server = NFS_SB(sb);
834 sb->s_blocksize_bits = 0;
835 sb->s_blocksize = 0;
836 if (data->bsize)
837 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
838 if (data->rsize)
839 server->rsize = nfs_block_size(data->rsize, NULL);
840 if (data->wsize)
841 server->wsize = nfs_block_size(data->wsize, NULL);
842 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
843
844 server->acregmin = data->acregmin*HZ;
845 server->acregmax = data->acregmax*HZ;
846 server->acdirmin = data->acdirmin*HZ;
847 server->acdirmax = data->acdirmax*HZ;
848
849 /* Start lockd here, before we might error out */
850 if (!(server->flags & NFS_MOUNT_NONLM))
851 lockd_up();
852
853 server->namelen = data->namlen;
854 server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL);
855 if (!server->hostname)
856 return -ENOMEM;
857 strcpy(server->hostname, data->hostname);
858
859 /* Check NFS protocol revision and initialize RPC op vector
860 * and file handle pool. */
861#ifdef CONFIG_NFS_V3
862 if (server->flags & NFS_MOUNT_VER3) {
863 server->rpc_ops = &nfs_v3_clientops;
864 server->caps |= NFS_CAP_READDIRPLUS;
865 } else {
866 server->rpc_ops = &nfs_v2_clientops;
867 }
868#else
869 server->rpc_ops = &nfs_v2_clientops;
870#endif
871
872 /* Fill in pseudoflavor for mount version < 5 */
873 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
874 data->pseudoflavor = RPC_AUTH_UNIX;
875 authflavor = data->pseudoflavor; /* save for sb_init() */
876 /* XXX maybe we want to add a server->pseudoflavor field */
877
878 /* Create RPC client handles */
879 server->client = nfs_create_client(server, data);
880 if (IS_ERR(server->client))
881 return PTR_ERR(server->client);
882 /* RFC 2623, sec 2.3.2 */
883 if (authflavor != RPC_AUTH_UNIX) {
884 struct rpc_auth *auth;
885
886 server->client_sys = rpc_clone_client(server->client);
887 if (IS_ERR(server->client_sys))
888 return PTR_ERR(server->client_sys);
889 auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys);
890 if (IS_ERR(auth))
891 return PTR_ERR(auth);
892 } else {
893 atomic_inc(&server->client->cl_count);
894 server->client_sys = server->client;
895 }
896 if (server->flags & NFS_MOUNT_VER3) {
897#ifdef CONFIG_NFS_V3_ACL
898 if (!(server->flags & NFS_MOUNT_NOACL)) {
899 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
900 /* No errors! Assume that Sun nfsacls are supported */
901 if (!IS_ERR(server->client_acl))
902 server->caps |= NFS_CAP_ACLS;
903 }
904#else
905 server->flags &= ~NFS_MOUNT_NOACL;
906#endif /* CONFIG_NFS_V3_ACL */
907 /*
908 * The VFS shouldn't apply the umask to mode bits. We will
909 * do so ourselves when necessary.
910 */
911 sb->s_flags |= MS_POSIXACL;
912 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
913 server->namelen = NFS3_MAXNAMLEN;
914 sb->s_time_gran = 1;
915 } else {
916 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
917 server->namelen = NFS2_MAXNAMLEN;
918 }
919
920 sb->s_op = &nfs_sops;
921 return nfs_sb_init(sb, authflavor);
922}
923
924static int nfs_set_super(struct super_block *s, void *data)
925{
926 s->s_fs_info = data;
927 return set_anon_super(s, data);
928}
929
930static int nfs_compare_super(struct super_block *sb, void *data)
931{
932 struct nfs_server *server = data;
933 struct nfs_server *old = NFS_SB(sb);
934
935 if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr)
936 return 0;
937 if (old->addr.sin_port != server->addr.sin_port)
938 return 0;
939 return !nfs_compare_fh(&old->fh, &server->fh);
940}
941
942static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
943 int flags, const char *dev_name, void *raw_data)
944{
945 int error;
946 struct nfs_server *server = NULL;
947 struct super_block *s;
948 struct nfs_fh *root;
949 struct nfs_mount_data *data = raw_data;
950
951 s = ERR_PTR(-EINVAL);
952 if (data == NULL) {
953 dprintk("%s: missing data argument\n", __FUNCTION__);
954 goto out_err;
955 }
956 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
957 dprintk("%s: bad mount version\n", __FUNCTION__);
958 goto out_err;
959 }
960 switch (data->version) {
961 case 1:
962 data->namlen = 0;
963 case 2:
964 data->bsize = 0;
965 case 3:
966 if (data->flags & NFS_MOUNT_VER3) {
967 dprintk("%s: mount structure version %d does not support NFSv3\n",
968 __FUNCTION__,
969 data->version);
970 goto out_err;
971 }
972 data->root.size = NFS2_FHSIZE;
973 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
974 case 4:
975 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
976 dprintk("%s: mount structure version %d does not support strong security\n",
977 __FUNCTION__,
978 data->version);
979 goto out_err;
980 }
981 case 5:
982 memset(data->context, 0, sizeof(data->context));
983 }
984#ifndef CONFIG_NFS_V3
985 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
986 s = ERR_PTR(-EPROTONOSUPPORT);
987 if (data->flags & NFS_MOUNT_VER3) {
988 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
989 goto out_err;
990 }
991#endif /* CONFIG_NFS_V3 */
992
993 s = ERR_PTR(-ENOMEM);
994 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
995 if (!server)
996 goto out_err;
997 /* Zero out the NFS state stuff */
998 init_nfsv4_state(server);
999 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
1000
1001 root = &server->fh;
1002 if (data->flags & NFS_MOUNT_VER3)
1003 root->size = data->root.size;
1004 else
1005 root->size = NFS2_FHSIZE;
1006 s = ERR_PTR(-EINVAL);
1007 if (root->size > sizeof(root->data)) {
1008 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
1009 goto out_err;
1010 }
1011 memcpy(root->data, data->root.data, root->size);
1012
1013 /* We now require that the mount process passes the remote address */
1014 memcpy(&server->addr, &data->addr, sizeof(server->addr));
1015 if (server->addr.sin_addr.s_addr == INADDR_ANY) {
1016 dprintk("%s: mount program didn't pass remote address!\n",
1017 __FUNCTION__);
1018 goto out_err;
1019 }
1020
1021 /* Fire up rpciod if not yet running */
1022 s = ERR_PTR(rpciod_up());
1023 if (IS_ERR(s)) {
1024 dprintk("%s: couldn't start rpciod! Error = %ld\n",
1025 __FUNCTION__, PTR_ERR(s));
1026 goto out_err;
1027 }
1028
1029 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1030 if (IS_ERR(s) || s->s_root)
1031 goto out_rpciod_down;
1032
1033 s->s_flags = flags;
1034
1035 error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1036 if (error) {
1037 up_write(&s->s_umount);
1038 deactivate_super(s);
1039 return ERR_PTR(error);
1040 }
1041 s->s_flags |= MS_ACTIVE;
1042 return s;
1043out_rpciod_down:
1044 rpciod_down();
1045out_err:
1046 kfree(server);
1047 return s;
1048}
1049
1050static void nfs_kill_super(struct super_block *s)
1051{
1052 struct nfs_server *server = NFS_SB(s);
1053
1054 kill_anon_super(s);
1055
1056 if (!IS_ERR(server->client))
1057 rpc_shutdown_client(server->client);
1058 if (!IS_ERR(server->client_sys))
1059 rpc_shutdown_client(server->client_sys);
1060 if (!IS_ERR(server->client_acl))
1061 rpc_shutdown_client(server->client_acl);
1062
1063 if (!(server->flags & NFS_MOUNT_NONLM))
1064 lockd_down(); /* release rpc.lockd */
1065
1066 rpciod_down(); /* release rpciod */
1067
1068 nfs_free_iostats(server->io_stats);
1069 kfree(server->hostname);
1070 kfree(server);
1071 nfs_release_automount_timer();
1072}
1073
1074static struct super_block *nfs_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data)
1075{
1076 struct super_block *sb;
1077
1078 server->fsid = data->fattr->fsid;
1079 nfs_copy_fh(&server->fh, data->fh);
1080 sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1081 if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM))
1082 lockd_up();
1083 return sb;
1084}
1085
1086static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type,
1087 int flags, const char *dev_name, void *raw_data)
1088{
1089 struct nfs_clone_mount *data = raw_data;
1090 return nfs_clone_generic_sb(data, nfs_clone_sb, nfs_clone_server);
1091}
1092
1093#ifdef CONFIG_NFS_V4
1094static struct rpc_clnt *nfs4_create_client(struct nfs_server *server,
1095 struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor)
1096{
1097 struct nfs4_client *clp;
1098 struct rpc_xprt *xprt = NULL;
1099 struct rpc_clnt *clnt = NULL;
1100 int err = -EIO;
1101
1102 clp = nfs4_get_client(&server->addr.sin_addr);
1103 if (!clp) {
1104 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
1105 return ERR_PTR(err);
1106 }
1107
1108 /* Now create transport and client */
1109 down_write(&clp->cl_sem);
1110 if (IS_ERR(clp->cl_rpcclient)) {
1111 xprt = xprt_create_proto(proto, &server->addr, timeparms);
1112 if (IS_ERR(xprt)) {
1113 up_write(&clp->cl_sem);
1114 err = PTR_ERR(xprt);
1115 dprintk("%s: cannot create RPC transport. Error = %d\n",
1116 __FUNCTION__, err);
1117 goto out_fail;
1118 }
1119 /* Bind to a reserved port! */
1120 xprt->resvport = 1;
1121 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
1122 server->rpc_ops->version, flavor);
1123 if (IS_ERR(clnt)) {
1124 up_write(&clp->cl_sem);
1125 err = PTR_ERR(clnt);
1126 dprintk("%s: cannot create RPC client. Error = %d\n",
1127 __FUNCTION__, err);
1128 goto out_fail;
1129 }
1130 clnt->cl_intr = 1;
1131 clnt->cl_softrtry = 1;
1132 clp->cl_rpcclient = clnt;
1133 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1134 nfs_idmap_new(clp);
1135 }
1136 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1137 clnt = rpc_clone_client(clp->cl_rpcclient);
1138 if (!IS_ERR(clnt))
1139 server->nfs4_state = clp;
1140 up_write(&clp->cl_sem);
1141 clp = NULL;
1142
1143 if (IS_ERR(clnt)) {
1144 dprintk("%s: cannot create RPC client. Error = %d\n",
1145 __FUNCTION__, err);
1146 return clnt;
1147 }
1148
1149 if (server->nfs4_state->cl_idmap == NULL) {
1150 dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
1151 return ERR_PTR(-ENOMEM);
1152 }
1153
1154 if (clnt->cl_auth->au_flavor != flavor) {
1155 struct rpc_auth *auth;
1156
1157 auth = rpcauth_create(flavor, clnt);
1158 if (IS_ERR(auth)) {
1159 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
1160 return (struct rpc_clnt *)auth;
1161 }
1162 }
1163 return clnt;
1164
1165 out_fail:
1166 if (clp)
1167 nfs4_put_client(clp);
1168 return ERR_PTR(err);
1169}
1170
1171/*
1172 * Set up an NFS4 superblock
1173 */
1174static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
1175{
1176 struct nfs_server *server;
1177 struct rpc_timeout timeparms;
1178 rpc_authflavor_t authflavour;
1179 int err = -EIO;
1180
1181 sb->s_blocksize_bits = 0;
1182 sb->s_blocksize = 0;
1183 server = NFS_SB(sb);
1184 if (data->rsize != 0)
1185 server->rsize = nfs_block_size(data->rsize, NULL);
1186 if (data->wsize != 0)
1187 server->wsize = nfs_block_size(data->wsize, NULL);
1188 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
1189 server->caps = NFS_CAP_ATOMIC_OPEN;
1190
1191 server->acregmin = data->acregmin*HZ;
1192 server->acregmax = data->acregmax*HZ;
1193 server->acdirmin = data->acdirmin*HZ;
1194 server->acdirmax = data->acdirmax*HZ;
1195
1196 server->rpc_ops = &nfs_v4_clientops;
1197
1198 nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
1199
1200 server->retrans_timeo = timeparms.to_initval;
1201 server->retrans_count = timeparms.to_retries;
1202
1203 /* Now create transport and client */
1204 authflavour = RPC_AUTH_UNIX;
1205 if (data->auth_flavourlen != 0) {
1206 if (data->auth_flavourlen != 1) {
1207 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
1208 __FUNCTION__, data->auth_flavourlen);
1209 err = -EINVAL;
1210 goto out_fail;
1211 }
1212 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
1213 err = -EFAULT;
1214 goto out_fail;
1215 }
1216 }
1217
1218 server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour);
1219 if (IS_ERR(server->client)) {
1220 err = PTR_ERR(server->client);
1221 dprintk("%s: cannot create RPC client. Error = %d\n",
1222 __FUNCTION__, err);
1223 goto out_fail;
1224 }
1225
1226 sb->s_time_gran = 1;
1227
1228 sb->s_op = &nfs4_sops;
1229 err = nfs_sb_init(sb, authflavour);
1230
1231 out_fail:
1232 return err;
1233}
1234
1235static int nfs4_compare_super(struct super_block *sb, void *data)
1236{
1237 struct nfs_server *server = data;
1238 struct nfs_server *old = NFS_SB(sb);
1239
1240 if (strcmp(server->hostname, old->hostname) != 0)
1241 return 0;
1242 if (strcmp(server->mnt_path, old->mnt_path) != 0)
1243 return 0;
1244 return 1;
1245}
1246
1247static void *
1248nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
1249{
1250 void *p = NULL;
1251
1252 if (!src->len)
1253 return ERR_PTR(-EINVAL);
1254 if (src->len < maxlen)
1255 maxlen = src->len;
1256 if (dst == NULL) {
1257 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
1258 if (p == NULL)
1259 return ERR_PTR(-ENOMEM);
1260 }
1261 if (copy_from_user(dst, src->data, maxlen)) {
1262 kfree(p);
1263 return ERR_PTR(-EFAULT);
1264 }
1265 dst[maxlen] = '\0';
1266 return dst;
1267}
1268
1269static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
1270 int flags, const char *dev_name, void *raw_data)
1271{
1272 int error;
1273 struct nfs_server *server;
1274 struct super_block *s;
1275 struct nfs4_mount_data *data = raw_data;
1276 void *p;
1277
1278 if (data == NULL) {
1279 dprintk("%s: missing data argument\n", __FUNCTION__);
1280 return ERR_PTR(-EINVAL);
1281 }
1282 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
1283 dprintk("%s: bad mount version\n", __FUNCTION__);
1284 return ERR_PTR(-EINVAL);
1285 }
1286
1287 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1288 if (!server)
1289 return ERR_PTR(-ENOMEM);
1290 /* Zero out the NFS state stuff */
1291 init_nfsv4_state(server);
1292 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
1293
1294 p = nfs_copy_user_string(NULL, &data->hostname, 256);
1295 if (IS_ERR(p))
1296 goto out_err;
1297 server->hostname = p;
1298
1299 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
1300 if (IS_ERR(p))
1301 goto out_err;
1302 server->mnt_path = p;
1303
1304 p = nfs_copy_user_string(server->ip_addr, &data->client_addr,
1305 sizeof(server->ip_addr) - 1);
1306 if (IS_ERR(p))
1307 goto out_err;
1308
1309 /* We now require that the mount process passes the remote address */
1310 if (data->host_addrlen != sizeof(server->addr)) {
1311 s = ERR_PTR(-EINVAL);
1312 goto out_free;
1313 }
1314 if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) {
1315 s = ERR_PTR(-EFAULT);
1316 goto out_free;
1317 }
1318 if (server->addr.sin_family != AF_INET ||
1319 server->addr.sin_addr.s_addr == INADDR_ANY) {
1320 dprintk("%s: mount program didn't pass remote IP address!\n",
1321 __FUNCTION__);
1322 s = ERR_PTR(-EINVAL);
1323 goto out_free;
1324 }
1325
1326 /* Fire up rpciod if not yet running */
1327 s = ERR_PTR(rpciod_up());
1328 if (IS_ERR(s)) {
1329 dprintk("%s: couldn't start rpciod! Error = %ld\n",
1330 __FUNCTION__, PTR_ERR(s));
1331 goto out_free;
1332 }
1333
1334 s = sget(fs_type, nfs4_compare_super, nfs_set_super, server);
1335
1336 if (IS_ERR(s) || s->s_root)
1337 goto out_free;
1338
1339 s->s_flags = flags;
1340
1341 error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1342 if (error) {
1343 up_write(&s->s_umount);
1344 deactivate_super(s);
1345 return ERR_PTR(error);
1346 }
1347 s->s_flags |= MS_ACTIVE;
1348 return s;
1349out_err:
1350 s = (struct super_block *)p;
1351out_free:
1352 kfree(server->mnt_path);
1353 kfree(server->hostname);
1354 kfree(server);
1355 return s;
1356}
1357
1358static void nfs4_kill_super(struct super_block *sb)
1359{
1360 struct nfs_server *server = NFS_SB(sb);
1361
1362 nfs_return_all_delegations(sb);
1363 kill_anon_super(sb);
1364
1365 nfs4_renewd_prepare_shutdown(server);
1366
1367 if (server->client != NULL && !IS_ERR(server->client))
1368 rpc_shutdown_client(server->client);
1369
1370 destroy_nfsv4_state(server);
1371
1372 rpciod_down();
1373
1374 nfs_free_iostats(server->io_stats);
1375 kfree(server->hostname);
1376 kfree(server);
1377 nfs_release_automount_timer();
1378}
1379
1380/*
1381 * Constructs the SERVER-side path
1382 */
1383static inline char *nfs4_dup_path(const struct dentry *dentry)
1384{
1385 char *page = (char *) __get_free_page(GFP_USER);
1386 char *path;
1387
1388 path = nfs4_path(dentry, page, PAGE_SIZE);
1389 if (!IS_ERR(path)) {
1390 int len = PAGE_SIZE + page - path;
1391 char *tmp = path;
1392
1393 path = kmalloc(len, GFP_KERNEL);
1394 if (path)
1395 memcpy(path, tmp, len);
1396 else
1397 path = ERR_PTR(-ENOMEM);
1398 }
1399 free_page((unsigned long)page);
1400 return path;
1401}
1402
1403static struct super_block *nfs4_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data)
1404{
1405 const struct dentry *dentry = data->dentry;
1406 struct nfs4_client *clp = server->nfs4_state;
1407 struct super_block *sb;
1408
1409 server->fsid = data->fattr->fsid;
1410 nfs_copy_fh(&server->fh, data->fh);
1411 server->mnt_path = nfs4_dup_path(dentry);
1412 if (IS_ERR(server->mnt_path)) {
1413 sb = (struct super_block *)server->mnt_path;
1414 goto err;
1415 }
1416 sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server);
1417 if (IS_ERR(sb) || sb->s_root)
1418 goto free_path;
1419 nfs4_server_capabilities(server, &server->fh);
1420
1421 down_write(&clp->cl_sem);
1422 atomic_inc(&clp->cl_count);
1423 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1424 up_write(&clp->cl_sem);
1425 return sb;
1426free_path:
1427 kfree(server->mnt_path);
1428err:
1429 server->mnt_path = NULL;
1430 return sb;
1431}
1432
1433static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type,
1434 int flags, const char *dev_name, void *raw_data)
1435{
1436 struct nfs_clone_mount *data = raw_data;
1437 return nfs_clone_generic_sb(data, nfs4_clone_sb, nfs_clone_server);
1438}
1439
1440static struct super_block *nfs4_referral_sb(struct nfs_server *server, struct nfs_clone_mount *data)
1441{
1442 struct super_block *sb = ERR_PTR(-ENOMEM);
1443 int len;
1444
1445 len = strlen(data->mnt_path) + 1;
1446 server->mnt_path = kmalloc(len, GFP_KERNEL);
1447 if (server->mnt_path == NULL)
1448 goto err;
1449 memcpy(server->mnt_path, data->mnt_path, len);
1450 memcpy(&server->addr, data->addr, sizeof(struct sockaddr_in));
1451
1452 sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server);
1453 if (IS_ERR(sb) || sb->s_root)
1454 goto free_path;
1455 return sb;
1456free_path:
1457 kfree(server->mnt_path);
1458err:
1459 server->mnt_path = NULL;
1460 return sb;
1461}
1462
1463static struct nfs_server *nfs4_referral_server(struct super_block *sb, struct nfs_clone_mount *data)
1464{
1465 struct nfs_server *server = NFS_SB(sb);
1466 struct rpc_timeout timeparms;
1467 int proto, timeo, retrans;
1468 void *err;
1469
1470 proto = IPPROTO_TCP;
1471 /* Since we are following a referral and there may be alternatives,
1472 set the timeouts and retries to low values */
1473 timeo = 2;
1474 retrans = 1;
1475 nfs_init_timeout_values(&timeparms, proto, timeo, retrans);
1476
1477 server->client = nfs4_create_client(server, &timeparms, proto, data->authflavor);
1478 if (IS_ERR((err = server->client)))
1479 goto out_err;
1480
1481 sb->s_time_gran = 1;
1482 sb->s_op = &nfs4_sops;
1483 err = ERR_PTR(nfs_sb_init(sb, data->authflavor));
1484 if (!IS_ERR(err))
1485 return server;
1486out_err:
1487 return (struct nfs_server *)err;
1488}
1489
1490static struct super_block *nfs_referral_nfs4_sb(struct file_system_type *fs_type,
1491 int flags, const char *dev_name, void *raw_data)
1492{
1493 struct nfs_clone_mount *data = raw_data;
1494 return nfs_clone_generic_sb(data, nfs4_referral_sb, nfs4_referral_server);
1495}
1496
1497#endif
diff --git a/fs/nfs/symlink.c b/fs/nfs/symlink.c
index 18dc95b0b646..636c479995bc 100644
--- a/fs/nfs/symlink.c
+++ b/fs/nfs/symlink.c
@@ -52,7 +52,7 @@ static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52{ 52{
53 struct inode *inode = dentry->d_inode; 53 struct inode *inode = dentry->d_inode;
54 struct page *page; 54 struct page *page;
55 void *err = ERR_PTR(nfs_revalidate_inode(NFS_SERVER(inode), inode)); 55 void *err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
56 if (err) 56 if (err)
57 goto read_failed; 57 goto read_failed;
58 page = read_cache_page(&inode->i_data, 0, 58 page = read_cache_page(&inode->i_data, 0,
diff --git a/fs/nfs/sysctl.c b/fs/nfs/sysctl.c
index 4c486eb867ca..db61e51bb154 100644
--- a/fs/nfs/sysctl.c
+++ b/fs/nfs/sysctl.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/nfs4.h> 13#include <linux/nfs4.h>
14#include <linux/nfs_idmap.h> 14#include <linux/nfs_idmap.h>
15#include <linux/nfs_fs.h>
15 16
16#include "callback.h" 17#include "callback.h"
17 18
@@ -46,6 +47,15 @@ static ctl_table nfs_cb_sysctls[] = {
46 .strategy = &sysctl_jiffies, 47 .strategy = &sysctl_jiffies,
47 }, 48 },
48#endif 49#endif
50 {
51 .ctl_name = CTL_UNNUMBERED,
52 .procname = "nfs_mountpoint_timeout",
53 .data = &nfs_mountpoint_expiry_timeout,
54 .maxlen = sizeof(nfs_mountpoint_expiry_timeout),
55 .mode = 0644,
56 .proc_handler = &proc_dointvec_jiffies,
57 .strategy = &sysctl_jiffies,
58 },
49 { .ctl_name = 0 } 59 { .ctl_name = 0 }
50}; 60};
51 61
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 4cfada2cc09f..b383fdd3a15c 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -98,11 +98,10 @@ struct nfs_write_data *nfs_commit_alloc(unsigned int pagecount)
98 if (p) { 98 if (p) {
99 memset(p, 0, sizeof(*p)); 99 memset(p, 0, sizeof(*p));
100 INIT_LIST_HEAD(&p->pages); 100 INIT_LIST_HEAD(&p->pages);
101 if (pagecount < NFS_PAGEVEC_SIZE) 101 if (pagecount <= ARRAY_SIZE(p->page_array))
102 p->pagevec = &p->page_array[0]; 102 p->pagevec = p->page_array;
103 else { 103 else {
104 size_t size = ++pagecount * sizeof(struct page *); 104 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
105 p->pagevec = kzalloc(size, GFP_NOFS);
106 if (!p->pagevec) { 105 if (!p->pagevec) {
107 mempool_free(p, nfs_commit_mempool); 106 mempool_free(p, nfs_commit_mempool);
108 p = NULL; 107 p = NULL;
@@ -126,14 +125,11 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
126 if (p) { 125 if (p) {
127 memset(p, 0, sizeof(*p)); 126 memset(p, 0, sizeof(*p));
128 INIT_LIST_HEAD(&p->pages); 127 INIT_LIST_HEAD(&p->pages);
129 if (pagecount < NFS_PAGEVEC_SIZE) 128 if (pagecount <= ARRAY_SIZE(p->page_array))
130 p->pagevec = &p->page_array[0]; 129 p->pagevec = p->page_array;
131 else { 130 else {
132 size_t size = ++pagecount * sizeof(struct page *); 131 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
133 p->pagevec = kmalloc(size, GFP_NOFS); 132 if (!p->pagevec) {
134 if (p->pagevec) {
135 memset(p->pagevec, 0, size);
136 } else {
137 mempool_free(p, nfs_wdata_mempool); 133 mempool_free(p, nfs_wdata_mempool);
138 p = NULL; 134 p = NULL;
139 } 135 }
@@ -583,6 +579,17 @@ static int nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, un
583 return ret; 579 return ret;
584} 580}
585 581
582static void nfs_cancel_requests(struct list_head *head)
583{
584 struct nfs_page *req;
585 while(!list_empty(head)) {
586 req = nfs_list_entry(head->next);
587 nfs_list_remove_request(req);
588 nfs_inode_remove_request(req);
589 nfs_clear_page_writeback(req);
590 }
591}
592
586/* 593/*
587 * nfs_scan_dirty - Scan an inode for dirty requests 594 * nfs_scan_dirty - Scan an inode for dirty requests
588 * @inode: NFS inode to scan 595 * @inode: NFS inode to scan
@@ -627,7 +634,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_st
627 int res = 0; 634 int res = 0;
628 635
629 if (nfsi->ncommit != 0) { 636 if (nfsi->ncommit != 0) {
630 res = nfs_scan_list(&nfsi->commit, dst, idx_start, npages); 637 res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages);
631 nfsi->ncommit -= res; 638 nfsi->ncommit -= res;
632 if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit)) 639 if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit))
633 printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n"); 640 printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n");
@@ -1495,15 +1502,25 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
1495 pages = nfs_scan_dirty(inode, &head, idx_start, npages); 1502 pages = nfs_scan_dirty(inode, &head, idx_start, npages);
1496 if (pages != 0) { 1503 if (pages != 0) {
1497 spin_unlock(&nfsi->req_lock); 1504 spin_unlock(&nfsi->req_lock);
1498 ret = nfs_flush_list(inode, &head, pages, how); 1505 if (how & FLUSH_INVALIDATE)
1506 nfs_cancel_requests(&head);
1507 else
1508 ret = nfs_flush_list(inode, &head, pages, how);
1499 spin_lock(&nfsi->req_lock); 1509 spin_lock(&nfsi->req_lock);
1500 continue; 1510 continue;
1501 } 1511 }
1502 if (nocommit) 1512 if (nocommit)
1503 break; 1513 break;
1504 pages = nfs_scan_commit(inode, &head, 0, 0); 1514 pages = nfs_scan_commit(inode, &head, idx_start, npages);
1505 if (pages == 0) 1515 if (pages == 0)
1506 break; 1516 break;
1517 if (how & FLUSH_INVALIDATE) {
1518 spin_unlock(&nfsi->req_lock);
1519 nfs_cancel_requests(&head);
1520 spin_lock(&nfsi->req_lock);
1521 continue;
1522 }
1523 pages += nfs_scan_commit(inode, &head, 0, 0);
1507 spin_unlock(&nfsi->req_lock); 1524 spin_unlock(&nfsi->req_lock);
1508 ret = nfs_commit_list(inode, &head, how); 1525 ret = nfs_commit_list(inode, &head, how);
1509 spin_lock(&nfsi->req_lock); 1526 spin_lock(&nfsi->req_lock);
@@ -1512,7 +1529,7 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
1512 return ret; 1529 return ret;
1513} 1530}
1514 1531
1515int nfs_init_writepagecache(void) 1532int __init nfs_init_writepagecache(void)
1516{ 1533{
1517 nfs_wdata_cachep = kmem_cache_create("nfs_write_data", 1534 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
1518 sizeof(struct nfs_write_data), 1535 sizeof(struct nfs_write_data),
@@ -1534,7 +1551,7 @@ int nfs_init_writepagecache(void)
1534 return 0; 1551 return 0;
1535} 1552}
1536 1553
1537void nfs_destroy_writepagecache(void) 1554void __exit nfs_destroy_writepagecache(void)
1538{ 1555{
1539 mempool_destroy(nfs_commit_mempool); 1556 mempool_destroy(nfs_commit_mempool);
1540 mempool_destroy(nfs_wdata_mempool); 1557 mempool_destroy(nfs_wdata_mempool);
diff --git a/fs/super.c b/fs/super.c
index a66f66bb8049..15f2afdbf82e 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -800,17 +800,13 @@ struct super_block *get_sb_single(struct file_system_type *fs_type,
800EXPORT_SYMBOL(get_sb_single); 800EXPORT_SYMBOL(get_sb_single);
801 801
802struct vfsmount * 802struct vfsmount *
803do_kern_mount(const char *fstype, int flags, const char *name, void *data) 803vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
804{ 804{
805 struct file_system_type *type = get_fs_type(fstype);
806 struct super_block *sb = ERR_PTR(-ENOMEM); 805 struct super_block *sb = ERR_PTR(-ENOMEM);
807 struct vfsmount *mnt; 806 struct vfsmount *mnt;
808 int error; 807 int error;
809 char *secdata = NULL; 808 char *secdata = NULL;
810 809
811 if (!type)
812 return ERR_PTR(-ENODEV);
813
814 mnt = alloc_vfsmnt(name); 810 mnt = alloc_vfsmnt(name);
815 if (!mnt) 811 if (!mnt)
816 goto out; 812 goto out;
@@ -841,7 +837,6 @@ do_kern_mount(const char *fstype, int flags, const char *name, void *data)
841 mnt->mnt_parent = mnt; 837 mnt->mnt_parent = mnt;
842 up_write(&sb->s_umount); 838 up_write(&sb->s_umount);
843 free_secdata(secdata); 839 free_secdata(secdata);
844 put_filesystem(type);
845 return mnt; 840 return mnt;
846out_sb: 841out_sb:
847 up_write(&sb->s_umount); 842 up_write(&sb->s_umount);
@@ -852,15 +847,26 @@ out_free_secdata:
852out_mnt: 847out_mnt:
853 free_vfsmnt(mnt); 848 free_vfsmnt(mnt);
854out: 849out:
855 put_filesystem(type);
856 return (struct vfsmount *)sb; 850 return (struct vfsmount *)sb;
857} 851}
858 852
859EXPORT_SYMBOL_GPL(do_kern_mount); 853EXPORT_SYMBOL_GPL(vfs_kern_mount);
854
855struct vfsmount *
856do_kern_mount(const char *fstype, int flags, const char *name, void *data)
857{
858 struct file_system_type *type = get_fs_type(fstype);
859 struct vfsmount *mnt;
860 if (!type)
861 return ERR_PTR(-ENODEV);
862 mnt = vfs_kern_mount(type, flags, name, data);
863 put_filesystem(type);
864 return mnt;
865}
860 866
861struct vfsmount *kern_mount(struct file_system_type *type) 867struct vfsmount *kern_mount(struct file_system_type *type)
862{ 868{
863 return do_kern_mount(type->name, 0, type->name, NULL); 869 return vfs_kern_mount(type, 0, type->name, NULL);
864} 870}
865 871
866EXPORT_SYMBOL(kern_mount); 872EXPORT_SYMBOL(kern_mount);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ecc8c2c3d8ca..2d5a112e8404 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1100,7 +1100,7 @@ struct super_operations {
1100 int (*statfs) (struct super_block *, struct kstatfs *); 1100 int (*statfs) (struct super_block *, struct kstatfs *);
1101 int (*remount_fs) (struct super_block *, int *, char *); 1101 int (*remount_fs) (struct super_block *, int *, char *);
1102 void (*clear_inode) (struct inode *); 1102 void (*clear_inode) (struct inode *);
1103 void (*umount_begin) (struct super_block *); 1103 void (*umount_begin) (struct vfsmount *, int);
1104 1104
1105 int (*show_options)(struct seq_file *, struct vfsmount *); 1105 int (*show_options)(struct seq_file *, struct vfsmount *);
1106 int (*show_stats)(struct seq_file *, struct vfsmount *); 1106 int (*show_stats)(struct seq_file *, struct vfsmount *);
@@ -1762,7 +1762,7 @@ extern struct inode_operations simple_dir_inode_operations;
1762struct tree_descr { char *name; const struct file_operations *ops; int mode; }; 1762struct tree_descr { char *name; const struct file_operations *ops; int mode; };
1763struct dentry *d_alloc_name(struct dentry *, const char *); 1763struct dentry *d_alloc_name(struct dentry *, const char *);
1764extern int simple_fill_super(struct super_block *, int, struct tree_descr *); 1764extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
1765extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count); 1765extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
1766extern void simple_release_fs(struct vfsmount **mount, int *count); 1766extern void simple_release_fs(struct vfsmount **mount, int *count);
1767 1767
1768extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t); 1768extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t);
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
index a8876bc6513b..aa4fe905bb4d 100644
--- a/include/linux/lockd/lockd.h
+++ b/include/linux/lockd/lockd.h
@@ -49,11 +49,12 @@ struct nlm_host {
49 h_killed : 1, 49 h_killed : 1,
50 h_monitored : 1; 50 h_monitored : 1;
51 wait_queue_head_t h_gracewait; /* wait while reclaiming */ 51 wait_queue_head_t h_gracewait; /* wait while reclaiming */
52 struct rw_semaphore h_rwsem; /* Reboot recovery lock */
52 u32 h_state; /* pseudo-state counter */ 53 u32 h_state; /* pseudo-state counter */
53 u32 h_nsmstate; /* true remote NSM state */ 54 u32 h_nsmstate; /* true remote NSM state */
54 u32 h_pidcount; /* Pseudopids */ 55 u32 h_pidcount; /* Pseudopids */
55 atomic_t h_count; /* reference count */ 56 atomic_t h_count; /* reference count */
56 struct semaphore h_sema; /* mutex for pmap binding */ 57 struct mutex h_mutex; /* mutex for pmap binding */
57 unsigned long h_nextrebind; /* next portmap call */ 58 unsigned long h_nextrebind; /* next portmap call */
58 unsigned long h_expires; /* eligible for GC */ 59 unsigned long h_expires; /* eligible for GC */
59 struct list_head h_lockowners; /* Lockowners for the client */ 60 struct list_head h_lockowners; /* Lockowners for the client */
@@ -219,6 +220,7 @@ static __inline__ int
219nlm_compare_locks(const struct file_lock *fl1, const struct file_lock *fl2) 220nlm_compare_locks(const struct file_lock *fl1, const struct file_lock *fl2)
220{ 221{
221 return fl1->fl_pid == fl2->fl_pid 222 return fl1->fl_pid == fl2->fl_pid
223 && fl1->fl_owner == fl2->fl_owner
222 && fl1->fl_start == fl2->fl_start 224 && fl1->fl_start == fl2->fl_start
223 && fl1->fl_end == fl2->fl_end 225 && fl1->fl_end == fl2->fl_end
224 &&(fl1->fl_type == fl2->fl_type || fl2->fl_type == F_UNLCK); 226 &&(fl1->fl_type == fl2->fl_type || fl2->fl_type == F_UNLCK);
diff --git a/include/linux/mount.h b/include/linux/mount.h
index b7472ae91fa4..9b4e0071b92e 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -23,6 +23,8 @@
23#define MNT_NOATIME 0x08 23#define MNT_NOATIME 0x08
24#define MNT_NODIRATIME 0x10 24#define MNT_NODIRATIME 0x10
25 25
26#define MNT_SHRINKABLE 0x100
27
26#define MNT_SHARED 0x1000 /* if the vfsmount is a shared mount */ 28#define MNT_SHARED 0x1000 /* if the vfsmount is a shared mount */
27#define MNT_UNBINDABLE 0x2000 /* if the vfsmount is a unbindable mount */ 29#define MNT_UNBINDABLE 0x2000 /* if the vfsmount is a unbindable mount */
28#define MNT_PNODE_MASK 0x3000 /* propogation flag mask */ 30#define MNT_PNODE_MASK 0x3000 /* propogation flag mask */
@@ -73,12 +75,18 @@ extern struct vfsmount *alloc_vfsmnt(const char *name);
73extern struct vfsmount *do_kern_mount(const char *fstype, int flags, 75extern struct vfsmount *do_kern_mount(const char *fstype, int flags,
74 const char *name, void *data); 76 const char *name, void *data);
75 77
78struct file_system_type;
79extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
80 int flags, const char *name,
81 void *data);
82
76struct nameidata; 83struct nameidata;
77 84
78extern int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd, 85extern int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
79 int mnt_flags, struct list_head *fslist); 86 int mnt_flags, struct list_head *fslist);
80 87
81extern void mark_mounts_for_expiry(struct list_head *mounts); 88extern void mark_mounts_for_expiry(struct list_head *mounts);
89extern void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts);
82 90
83extern spinlock_t vfsmount_lock; 91extern spinlock_t vfsmount_lock;
84extern dev_t name_to_dev_t(char *name); 92extern dev_t name_to_dev_t(char *name);
diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
index 1059e6d69d3b..5f681d534295 100644
--- a/include/linux/nfs4.h
+++ b/include/linux/nfs4.h
@@ -384,6 +384,7 @@ enum {
384 NFSPROC4_CLNT_DELEGRETURN, 384 NFSPROC4_CLNT_DELEGRETURN,
385 NFSPROC4_CLNT_GETACL, 385 NFSPROC4_CLNT_GETACL,
386 NFSPROC4_CLNT_SETACL, 386 NFSPROC4_CLNT_SETACL,
387 NFSPROC4_CLNT_FS_LOCATIONS,
387}; 388};
388 389
389#endif 390#endif
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 7e079f8ce18b..152798949113 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -9,6 +9,27 @@
9#ifndef _LINUX_NFS_FS_H 9#ifndef _LINUX_NFS_FS_H
10#define _LINUX_NFS_FS_H 10#define _LINUX_NFS_FS_H
11 11
12#include <linux/config.h>
13#include <linux/in.h>
14#include <linux/mm.h>
15#include <linux/pagemap.h>
16#include <linux/rwsem.h>
17#include <linux/wait.h>
18
19#include <linux/sunrpc/debug.h>
20#include <linux/sunrpc/auth.h>
21#include <linux/sunrpc/clnt.h>
22
23#include <linux/nfs.h>
24#include <linux/nfs2.h>
25#include <linux/nfs3.h>
26#include <linux/nfs4.h>
27#include <linux/nfs_xdr.h>
28
29#include <linux/nfs_fs_sb.h>
30
31#include <linux/rwsem.h>
32#include <linux/mempool.h>
12 33
13/* 34/*
14 * Enable debugging support for nfs client. 35 * Enable debugging support for nfs client.
@@ -41,27 +62,9 @@
41#define FLUSH_LOWPRI 8 /* low priority background flush */ 62#define FLUSH_LOWPRI 8 /* low priority background flush */
42#define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */ 63#define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */
43#define FLUSH_NOCOMMIT 32 /* Don't send the NFSv3/v4 COMMIT */ 64#define FLUSH_NOCOMMIT 32 /* Don't send the NFSv3/v4 COMMIT */
65#define FLUSH_INVALIDATE 64 /* Invalidate the page cache */
44 66
45#ifdef __KERNEL__ 67#ifdef __KERNEL__
46#include <linux/in.h>
47#include <linux/mm.h>
48#include <linux/pagemap.h>
49#include <linux/rwsem.h>
50#include <linux/wait.h>
51
52#include <linux/nfs_fs_sb.h>
53
54#include <linux/sunrpc/debug.h>
55#include <linux/sunrpc/auth.h>
56#include <linux/sunrpc/clnt.h>
57
58#include <linux/nfs.h>
59#include <linux/nfs2.h>
60#include <linux/nfs3.h>
61#include <linux/nfs4.h>
62#include <linux/nfs_xdr.h>
63#include <linux/rwsem.h>
64#include <linux/mempool.h>
65 68
66/* 69/*
67 * NFSv3/v4 Access mode cache entry 70 * NFSv3/v4 Access mode cache entry
@@ -233,8 +236,12 @@ static inline int nfs_caches_unstable(struct inode *inode)
233 236
234static inline void nfs_mark_for_revalidate(struct inode *inode) 237static inline void nfs_mark_for_revalidate(struct inode *inode)
235{ 238{
239 struct nfs_inode *nfsi = NFS_I(inode);
240
236 spin_lock(&inode->i_lock); 241 spin_lock(&inode->i_lock);
237 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS; 242 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS;
243 if (S_ISDIR(inode->i_mode))
244 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
238 spin_unlock(&inode->i_lock); 245 spin_unlock(&inode->i_lock);
239} 246}
240 247
@@ -296,7 +303,7 @@ extern int nfs_release(struct inode *, struct file *);
296extern int nfs_attribute_timeout(struct inode *inode); 303extern int nfs_attribute_timeout(struct inode *inode);
297extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode); 304extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode);
298extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *); 305extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
299extern void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping); 306extern int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping);
300extern int nfs_setattr(struct dentry *, struct iattr *); 307extern int nfs_setattr(struct dentry *, struct iattr *);
301extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr); 308extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr);
302extern void nfs_begin_attr_update(struct inode *); 309extern void nfs_begin_attr_update(struct inode *);
@@ -306,6 +313,12 @@ extern void nfs_end_data_update(struct inode *);
306extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); 313extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
307extern void put_nfs_open_context(struct nfs_open_context *ctx); 314extern void put_nfs_open_context(struct nfs_open_context *ctx);
308extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, int mode); 315extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, int mode);
316extern struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent,
317 const struct dentry *dentry,
318 struct nfs_fh *fh,
319 struct nfs_fattr *fattr);
320extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent,
321 struct dentry *dentry);
309 322
310/* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */ 323/* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
311extern u32 root_nfs_parse_addr(char *name); /*__init*/ 324extern u32 root_nfs_parse_addr(char *name); /*__init*/
@@ -392,6 +405,15 @@ extern void nfs_unregister_sysctl(void);
392#endif 405#endif
393 406
394/* 407/*
408 * linux/fs/nfs/namespace.c
409 */
410extern struct list_head nfs_automount_list;
411extern struct inode_operations nfs_mountpoint_inode_operations;
412extern struct inode_operations nfs_referral_inode_operations;
413extern int nfs_mountpoint_expiry_timeout;
414extern void nfs_release_automount_timer(void);
415
416/*
395 * linux/fs/nfs/unlink.c 417 * linux/fs/nfs/unlink.c
396 */ 418 */
397extern int nfs_async_unlink(struct dentry *); 419extern int nfs_async_unlink(struct dentry *);
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index 65dec21af774..6b4a13c79474 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -35,6 +35,7 @@ struct nfs_server {
35 char * hostname; /* remote hostname */ 35 char * hostname; /* remote hostname */
36 struct nfs_fh fh; 36 struct nfs_fh fh;
37 struct sockaddr_in addr; 37 struct sockaddr_in addr;
38 struct nfs_fsid fsid;
38 unsigned long mount_time; /* when this fs was mounted */ 39 unsigned long mount_time; /* when this fs was mounted */
39#ifdef CONFIG_NFS_V4 40#ifdef CONFIG_NFS_V4
40 /* Our own IP address, as a null-terminated string. 41 /* Our own IP address, as a null-terminated string.
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h
index 66e2ed658527..1f7bd287c230 100644
--- a/include/linux/nfs_page.h
+++ b/include/linux/nfs_page.h
@@ -13,7 +13,6 @@
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/pagemap.h> 14#include <linux/pagemap.h>
15#include <linux/wait.h> 15#include <linux/wait.h>
16#include <linux/nfs_fs_sb.h>
17#include <linux/sunrpc/auth.h> 16#include <linux/sunrpc/auth.h>
18#include <linux/nfs_xdr.h> 17#include <linux/nfs_xdr.h>
19 18
@@ -63,8 +62,8 @@ extern void nfs_release_request(struct nfs_page *req);
63 62
64extern int nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst, 63extern int nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
65 unsigned long idx_start, unsigned int npages); 64 unsigned long idx_start, unsigned int npages);
66extern int nfs_scan_list(struct list_head *, struct list_head *, 65extern int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head, struct list_head *dst,
67 unsigned long, unsigned int); 66 unsigned long idx_start, unsigned int npages);
68extern int nfs_coalesce_requests(struct list_head *, struct list_head *, 67extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
69 unsigned int); 68 unsigned int);
70extern int nfs_wait_on_request(struct nfs_page *); 69extern int nfs_wait_on_request(struct nfs_page *);
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 7fafc4c546b7..7c7320fa51aa 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -14,11 +14,19 @@
14#define NFS_DEF_FILE_IO_SIZE (4096U) 14#define NFS_DEF_FILE_IO_SIZE (4096U)
15#define NFS_MIN_FILE_IO_SIZE (1024U) 15#define NFS_MIN_FILE_IO_SIZE (1024U)
16 16
17struct nfs4_fsid { 17struct nfs_fsid {
18 __u64 major; 18 uint64_t major;
19 __u64 minor; 19 uint64_t minor;
20}; 20};
21 21
22/*
23 * Helper for checking equality between 2 fsids.
24 */
25static inline int nfs_fsid_equal(const struct nfs_fsid *a, const struct nfs_fsid *b)
26{
27 return a->major == b->major && a->minor == b->minor;
28}
29
22struct nfs_fattr { 30struct nfs_fattr {
23 unsigned short valid; /* which fields are valid */ 31 unsigned short valid; /* which fields are valid */
24 __u64 pre_size; /* pre_op_attr.size */ 32 __u64 pre_size; /* pre_op_attr.size */
@@ -40,10 +48,7 @@ struct nfs_fattr {
40 } nfs3; 48 } nfs3;
41 } du; 49 } du;
42 dev_t rdev; 50 dev_t rdev;
43 union { 51 struct nfs_fsid fsid;
44 __u64 nfs3; /* also nfs2 */
45 struct nfs4_fsid nfs4;
46 } fsid_u;
47 __u64 fileid; 52 __u64 fileid;
48 struct timespec atime; 53 struct timespec atime;
49 struct timespec mtime; 54 struct timespec mtime;
@@ -57,8 +62,8 @@ struct nfs_fattr {
57#define NFS_ATTR_WCC 0x0001 /* pre-op WCC data */ 62#define NFS_ATTR_WCC 0x0001 /* pre-op WCC data */
58#define NFS_ATTR_FATTR 0x0002 /* post-op attributes */ 63#define NFS_ATTR_FATTR 0x0002 /* post-op attributes */
59#define NFS_ATTR_FATTR_V3 0x0004 /* NFSv3 attributes */ 64#define NFS_ATTR_FATTR_V3 0x0004 /* NFSv3 attributes */
60#define NFS_ATTR_FATTR_V4 0x0008 65#define NFS_ATTR_FATTR_V4 0x0008 /* NFSv4 change attribute */
61#define NFS_ATTR_PRE_CHANGE 0x0010 66#define NFS_ATTR_FATTR_V4_REFERRAL 0x0010 /* NFSv4 referral */
62 67
63/* 68/*
64 * Info on the file system 69 * Info on the file system
@@ -675,6 +680,40 @@ struct nfs4_server_caps_res {
675 u32 has_symlinks; 680 u32 has_symlinks;
676}; 681};
677 682
683struct nfs4_string {
684 unsigned int len;
685 char *data;
686};
687
688#define NFS4_PATHNAME_MAXCOMPONENTS 512
689struct nfs4_pathname {
690 unsigned int ncomponents;
691 struct nfs4_string components[NFS4_PATHNAME_MAXCOMPONENTS];
692};
693
694#define NFS4_FS_LOCATION_MAXSERVERS 10
695struct nfs4_fs_location {
696 unsigned int nservers;
697 struct nfs4_string servers[NFS4_FS_LOCATION_MAXSERVERS];
698 struct nfs4_pathname rootpath;
699};
700
701#define NFS4_FS_LOCATIONS_MAXENTRIES 10
702struct nfs4_fs_locations {
703 struct nfs_fattr fattr;
704 const struct nfs_server *server;
705 struct nfs4_pathname fs_path;
706 int nlocations;
707 struct nfs4_fs_location locations[NFS4_FS_LOCATIONS_MAXENTRIES];
708};
709
710struct nfs4_fs_locations_arg {
711 const struct nfs_fh *dir_fh;
712 const struct qstr *name;
713 struct page *page;
714 const u32 *bitmask;
715};
716
678#endif /* CONFIG_NFS_V4 */ 717#endif /* CONFIG_NFS_V4 */
679 718
680struct nfs_page; 719struct nfs_page;
@@ -695,7 +734,7 @@ struct nfs_read_data {
695#ifdef CONFIG_NFS_V4 734#ifdef CONFIG_NFS_V4
696 unsigned long timestamp; /* For lease renewal */ 735 unsigned long timestamp; /* For lease renewal */
697#endif 736#endif
698 struct page *page_array[NFS_PAGEVEC_SIZE + 1]; 737 struct page *page_array[NFS_PAGEVEC_SIZE];
699}; 738};
700 739
701struct nfs_write_data { 740struct nfs_write_data {
@@ -713,7 +752,7 @@ struct nfs_write_data {
713#ifdef CONFIG_NFS_V4 752#ifdef CONFIG_NFS_V4
714 unsigned long timestamp; /* For lease renewal */ 753 unsigned long timestamp; /* For lease renewal */
715#endif 754#endif
716 struct page *page_array[NFS_PAGEVEC_SIZE + 1]; 755 struct page *page_array[NFS_PAGEVEC_SIZE];
717}; 756};
718 757
719struct nfs_access_entry; 758struct nfs_access_entry;
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index 84c35d42d250..e6d3d349506c 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -194,6 +194,7 @@ extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
194extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, uint32_t *p); 194extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, uint32_t *p);
195extern uint32_t *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes); 195extern uint32_t *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
196extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len); 196extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
197extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
197 198
198#endif /* __KERNEL__ */ 199#endif /* __KERNEL__ */
199 200
diff --git a/mm/shmem.c b/mm/shmem.c
index 1e43c8a865ba..797eef3805ce 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2263,7 +2263,7 @@ static int __init init_tmpfs(void)
2263#ifdef CONFIG_TMPFS 2263#ifdef CONFIG_TMPFS
2264 devfs_mk_dir("shm"); 2264 devfs_mk_dir("shm");
2265#endif 2265#endif
2266 shm_mnt = do_kern_mount(tmpfs_fs_type.name, MS_NOUSER, 2266 shm_mnt = vfs_kern_mount(&tmpfs_fs_type, MS_NOUSER,
2267 tmpfs_fs_type.name, NULL); 2267 tmpfs_fs_type.name, NULL);
2268 if (IS_ERR(shm_mnt)) { 2268 if (IS_ERR(shm_mnt)) {
2269 error = PTR_ERR(shm_mnt); 2269 error = PTR_ERR(shm_mnt);
diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c
index f56767aaa927..2eccffa96ba1 100644
--- a/net/sunrpc/auth_null.c
+++ b/net/sunrpc/auth_null.c
@@ -118,6 +118,8 @@ struct rpc_auth null_auth = {
118 .au_cslack = 4, 118 .au_cslack = 4,
119 .au_rslack = 2, 119 .au_rslack = 2,
120 .au_ops = &authnull_ops, 120 .au_ops = &authnull_ops,
121 .au_flavor = RPC_AUTH_NULL,
122 .au_count = ATOMIC_INIT(0),
121}; 123};
122 124
123static 125static
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index df14b6bfbf10..74c7406a1054 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -225,6 +225,7 @@ struct rpc_auth unix_auth = {
225 .au_cslack = UNX_WRITESLACK, 225 .au_cslack = UNX_WRITESLACK,
226 .au_rslack = 2, /* assume AUTH_NULL verf */ 226 .au_rslack = 2, /* assume AUTH_NULL verf */
227 .au_ops = &authunix_ops, 227 .au_ops = &authunix_ops,
228 .au_flavor = RPC_AUTH_UNIX,
228 .au_count = ATOMIC_INIT(0), 229 .au_count = ATOMIC_INIT(0),
229 .au_credcache = &unix_cred_cache, 230 .au_credcache = &unix_cred_cache,
230}; 231};
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index cc673dd8433f..a5226df8ac03 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -439,7 +439,7 @@ struct vfsmount *rpc_get_mount(void)
439{ 439{
440 int err; 440 int err;
441 441
442 err = simple_pin_fs("rpc_pipefs", &rpc_mount, &rpc_mount_count); 442 err = simple_pin_fs(&rpc_pipe_fs_type, &rpc_mount, &rpc_mount_count);
443 if (err != 0) 443 if (err != 0)
444 return ERR_PTR(err); 444 return ERR_PTR(err);
445 return rpc_mount; 445 return rpc_mount;
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index ca4bfa57e116..49174f0d0a3e 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -568,8 +568,7 @@ EXPORT_SYMBOL(xdr_inline_decode);
568 * 568 *
569 * Moves data beyond the current pointer position from the XDR head[] buffer 569 * Moves data beyond the current pointer position from the XDR head[] buffer
570 * into the page list. Any data that lies beyond current position + "len" 570 * into the page list. Any data that lies beyond current position + "len"
571 * bytes is moved into the XDR tail[]. The current pointer is then 571 * bytes is moved into the XDR tail[].
572 * repositioned at the beginning of the XDR tail.
573 */ 572 */
574void xdr_read_pages(struct xdr_stream *xdr, unsigned int len) 573void xdr_read_pages(struct xdr_stream *xdr, unsigned int len)
575{ 574{
@@ -606,6 +605,31 @@ void xdr_read_pages(struct xdr_stream *xdr, unsigned int len)
606} 605}
607EXPORT_SYMBOL(xdr_read_pages); 606EXPORT_SYMBOL(xdr_read_pages);
608 607
608/**
609 * xdr_enter_page - decode data from the XDR page
610 * @xdr: pointer to xdr_stream struct
611 * @len: number of bytes of page data
612 *
613 * Moves data beyond the current pointer position from the XDR head[] buffer
614 * into the page list. Any data that lies beyond current position + "len"
615 * bytes is moved into the XDR tail[]. The current pointer is then
616 * repositioned at the beginning of the first XDR page.
617 */
618void xdr_enter_page(struct xdr_stream *xdr, unsigned int len)
619{
620 char * kaddr = page_address(xdr->buf->pages[0]);
621 xdr_read_pages(xdr, len);
622 /*
623 * Position current pointer at beginning of tail, and
624 * set remaining message length.
625 */
626 if (len > PAGE_CACHE_SIZE - xdr->buf->page_base)
627 len = PAGE_CACHE_SIZE - xdr->buf->page_base;
628 xdr->p = (uint32_t *)(kaddr + xdr->buf->page_base);
629 xdr->end = (uint32_t *)((char *)xdr->p + len);
630}
631EXPORT_SYMBOL(xdr_enter_page);
632
609static struct kvec empty_iov = {.iov_base = NULL, .iov_len = 0}; 633static struct kvec empty_iov = {.iov_base = NULL, .iov_len = 0};
610 634
611void 635void
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 4dd5b3cfe754..02060d0e7be8 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -41,7 +41,7 @@
41#include <linux/types.h> 41#include <linux/types.h>
42#include <linux/interrupt.h> 42#include <linux/interrupt.h>
43#include <linux/workqueue.h> 43#include <linux/workqueue.h>
44#include <linux/random.h> 44#include <linux/net.h>
45 45
46#include <linux/sunrpc/clnt.h> 46#include <linux/sunrpc/clnt.h>
47#include <linux/sunrpc/metrics.h> 47#include <linux/sunrpc/metrics.h>
@@ -830,7 +830,7 @@ static inline u32 xprt_alloc_xid(struct rpc_xprt *xprt)
830 830
831static inline void xprt_init_xid(struct rpc_xprt *xprt) 831static inline void xprt_init_xid(struct rpc_xprt *xprt)
832{ 832{
833 get_random_bytes(&xprt->xid, sizeof(xprt->xid)); 833 xprt->xid = net_random();
834} 834}
835 835
836static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt) 836static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt)
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 4b4e7dfdff14..21006b109101 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -930,6 +930,13 @@ static void xs_udp_timer(struct rpc_task *task)
930 xprt_adjust_cwnd(task, -ETIMEDOUT); 930 xprt_adjust_cwnd(task, -ETIMEDOUT);
931} 931}
932 932
933static unsigned short xs_get_random_port(void)
934{
935 unsigned short range = xprt_max_resvport - xprt_min_resvport;
936 unsigned short rand = (unsigned short) net_random() % range;
937 return rand + xprt_min_resvport;
938}
939
933/** 940/**
934 * xs_set_port - reset the port number in the remote endpoint address 941 * xs_set_port - reset the port number in the remote endpoint address
935 * @xprt: generic transport 942 * @xprt: generic transport
@@ -1275,7 +1282,7 @@ int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to)
1275 memset(xprt->slot, 0, slot_table_size); 1282 memset(xprt->slot, 0, slot_table_size);
1276 1283
1277 xprt->prot = IPPROTO_UDP; 1284 xprt->prot = IPPROTO_UDP;
1278 xprt->port = xprt_max_resvport; 1285 xprt->port = xs_get_random_port();
1279 xprt->tsh_size = 0; 1286 xprt->tsh_size = 0;
1280 xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0; 1287 xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0;
1281 /* XXX: header size can vary due to auth type, IPv6, etc. */ 1288 /* XXX: header size can vary due to auth type, IPv6, etc. */
@@ -1317,7 +1324,7 @@ int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to)
1317 memset(xprt->slot, 0, slot_table_size); 1324 memset(xprt->slot, 0, slot_table_size);
1318 1325
1319 xprt->prot = IPPROTO_TCP; 1326 xprt->prot = IPPROTO_TCP;
1320 xprt->port = xprt_max_resvport; 1327 xprt->port = xs_get_random_port();
1321 xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32); 1328 xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32);
1322 xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0; 1329 xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0;
1323 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; 1330 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
diff --git a/security/inode.c b/security/inode.c
index 0f77b0223662..8bf40625c670 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -224,7 +224,7 @@ struct dentry *securityfs_create_file(const char *name, mode_t mode,
224 224
225 pr_debug("securityfs: creating file '%s'\n",name); 225 pr_debug("securityfs: creating file '%s'\n",name);
226 226
227 error = simple_pin_fs("securityfs", &mount, &mount_count); 227 error = simple_pin_fs(&fs_type, &mount, &mount_count);
228 if (error) { 228 if (error) {
229 dentry = ERR_PTR(error); 229 dentry = ERR_PTR(error);
230 goto exit; 230 goto exit;