aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs')
-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.c1313
-rw-r--r--fs/nfs/internal.h179
-rw-r--r--fs/nfs/namespace.c229
-rw-r--r--fs/nfs/nfs2xdr.c6
-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.c1533
-rw-r--r--fs/nfs/symlink.c2
-rw-r--r--fs/nfs/sysctl.c10
-rw-r--r--fs/nfs/write.c49
25 files changed, 2730 insertions, 1392 deletions
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 fa05c027ea11..add289138836 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 937fbfc381bb..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 dentry *, 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,555 +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 dentry *dentry, struct kstatfs *buf)
538{
539 struct super_block *sb = dentry->d_sb;
540 struct nfs_server *server = NFS_SB(sb);
541 unsigned char blockbits;
542 unsigned long blockres;
543 struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode);
544 struct nfs_fattr fattr;
545 struct nfs_fsstat res = {
546 .fattr = &fattr,
547 };
548 int error;
549
550 lock_kernel();
551
552 error = server->rpc_ops->statfs(server, rootfh, &res);
553 buf->f_type = NFS_SUPER_MAGIC;
554 if (error < 0)
555 goto out_err;
556
557 /*
558 * Current versions of glibc do not correctly handle the
559 * case where f_frsize != f_bsize. Eventually we want to
560 * report the value of wtmult in this field.
561 */
562 buf->f_frsize = sb->s_blocksize;
563
564 /*
565 * On most *nix systems, f_blocks, f_bfree, and f_bavail
566 * are reported in units of f_frsize. Linux hasn't had
567 * an f_frsize field in its statfs struct until recently,
568 * thus historically Linux's sys_statfs reports these
569 * fields in units of f_bsize.
570 */
571 buf->f_bsize = sb->s_blocksize;
572 blockbits = sb->s_blocksize_bits;
573 blockres = (1 << blockbits) - 1;
574 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
575 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
576 buf->f_bavail = (res.abytes + blockres) >> blockbits;
577
578 buf->f_files = res.tfiles;
579 buf->f_ffree = res.afiles;
580
581 buf->f_namelen = server->namelen;
582 out:
583 unlock_kernel();
584 return 0;
585
586 out_err:
587 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
588 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
589 goto out;
590
591}
592
593static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
594{
595 static struct proc_nfs_info {
596 int flag;
597 char *str;
598 char *nostr;
599 } nfs_info[] = {
600 { NFS_MOUNT_SOFT, ",soft", ",hard" },
601 { NFS_MOUNT_INTR, ",intr", "" },
602 { NFS_MOUNT_NOCTO, ",nocto", "" },
603 { NFS_MOUNT_NOAC, ",noac", "" },
604 { NFS_MOUNT_NONLM, ",nolock", "" },
605 { NFS_MOUNT_NOACL, ",noacl", "" },
606 { 0, NULL, NULL }
607 };
608 struct proc_nfs_info *nfs_infop;
609 char buf[12];
610 char *proto;
611
612 seq_printf(m, ",vers=%d", nfss->rpc_ops->version);
613 seq_printf(m, ",rsize=%d", nfss->rsize);
614 seq_printf(m, ",wsize=%d", nfss->wsize);
615 if (nfss->acregmin != 3*HZ || showdefaults)
616 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
617 if (nfss->acregmax != 60*HZ || showdefaults)
618 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
619 if (nfss->acdirmin != 30*HZ || showdefaults)
620 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
621 if (nfss->acdirmax != 60*HZ || showdefaults)
622 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
623 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
624 if (nfss->flags & nfs_infop->flag)
625 seq_puts(m, nfs_infop->str);
626 else
627 seq_puts(m, nfs_infop->nostr);
628 }
629 switch (nfss->client->cl_xprt->prot) {
630 case IPPROTO_TCP:
631 proto = "tcp";
632 break;
633 case IPPROTO_UDP:
634 proto = "udp";
635 break;
636 default:
637 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
638 proto = buf;
639 }
640 seq_printf(m, ",proto=%s", proto);
641 seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ);
642 seq_printf(m, ",retrans=%u", nfss->retrans_count);
643}
644
645static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
646{
647 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
648
649 nfs_show_mount_options(m, nfss, 0);
650
651 seq_puts(m, ",addr=");
652 seq_escape(m, nfss->hostname, " \t\n\\");
653
654 return 0;
655}
656
657static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
658{
659 int i, cpu;
660 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
661 struct rpc_auth *auth = nfss->client->cl_auth;
662 struct nfs_iostats totals = { };
663
664 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
665
666 /*
667 * Display all mount option settings
668 */
669 seq_printf(m, "\n\topts:\t");
670 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
671 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
672 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
673 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
674 nfs_show_mount_options(m, nfss, 1);
675
676 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
677
678 seq_printf(m, "\n\tcaps:\t");
679 seq_printf(m, "caps=0x%x", nfss->caps);
680 seq_printf(m, ",wtmult=%d", nfss->wtmult);
681 seq_printf(m, ",dtsize=%d", nfss->dtsize);
682 seq_printf(m, ",bsize=%d", nfss->bsize);
683 seq_printf(m, ",namelen=%d", nfss->namelen);
684
685#ifdef CONFIG_NFS_V4
686 if (nfss->rpc_ops->version == 4) {
687 seq_printf(m, "\n\tnfsv4:\t");
688 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
689 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
690 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
691 }
692#endif
693
694 /*
695 * Display security flavor in effect for this mount
696 */
697 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
698 if (auth->au_flavor)
699 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
700
701 /*
702 * Display superblock I/O counters
703 */
704 for_each_possible_cpu(cpu) {
705 struct nfs_iostats *stats;
706
707 preempt_disable();
708 stats = per_cpu_ptr(nfss->io_stats, cpu);
709
710 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
711 totals.events[i] += stats->events[i];
712 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
713 totals.bytes[i] += stats->bytes[i];
714
715 preempt_enable();
716 }
717
718 seq_printf(m, "\n\tevents:\t");
719 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
720 seq_printf(m, "%lu ", totals.events[i]);
721 seq_printf(m, "\n\tbytes:\t");
722 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
723 seq_printf(m, "%Lu ", totals.bytes[i]);
724 seq_printf(m, "\n");
725
726 rpc_print_iostats(m, nfss->client);
727
728 return 0;
729}
730
731/** 95/**
732 * 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
733 */ 97 */
@@ -890,6 +254,14 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
890 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS) 254 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
891 && fattr->size <= NFS_LIMIT_READDIRPLUS) 255 && fattr->size <= NFS_LIMIT_READDIRPLUS)
892 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 }
893 } else if (S_ISLNK(inode->i_mode)) 265 } else if (S_ISLNK(inode->i_mode))
894 inode->i_op = &nfs_symlink_inode_operations; 266 inode->i_op = &nfs_symlink_inode_operations;
895 else 267 else
@@ -1208,6 +580,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1208 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n", 580 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
1209 inode->i_sb->s_id, (long long)NFS_FILEID(inode)); 581 inode->i_sb->s_id, (long long)NFS_FILEID(inode));
1210 582
583 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
1211 lock_kernel(); 584 lock_kernel();
1212 if (!inode || is_bad_inode(inode)) 585 if (!inode || is_bad_inode(inode))
1213 goto out_nowait; 586 goto out_nowait;
@@ -1221,7 +594,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1221 status = -ESTALE; 594 status = -ESTALE;
1222 /* Do we trust the cached ESTALE? */ 595 /* Do we trust the cached ESTALE? */
1223 if (NFS_ATTRTIMEO(inode) != 0) { 596 if (NFS_ATTRTIMEO(inode) != 0) {
1224 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)) {
1225 /* no */ 598 /* no */
1226 } else 599 } else
1227 goto out; 600 goto out;
@@ -1252,8 +625,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1252 } 625 }
1253 spin_unlock(&inode->i_lock); 626 spin_unlock(&inode->i_lock);
1254 627
1255 nfs_revalidate_mapping(inode, inode->i_mapping);
1256
1257 if (nfsi->cache_validity & NFS_INO_INVALID_ACL) 628 if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
1258 nfs_zap_acl_cache(inode); 629 nfs_zap_acl_cache(inode);
1259 630
@@ -1287,8 +658,7 @@ int nfs_attribute_timeout(struct inode *inode)
1287 */ 658 */
1288int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) 659int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1289{ 660{
1290 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE); 661 if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
1291 if (!(NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
1292 && !nfs_attribute_timeout(inode)) 662 && !nfs_attribute_timeout(inode))
1293 return NFS_STALE(inode) ? -ESTALE : 0; 663 return NFS_STALE(inode) ? -ESTALE : 0;
1294 return __nfs_revalidate_inode(server, inode); 664 return __nfs_revalidate_inode(server, inode);
@@ -1299,9 +669,16 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1299 * @inode - pointer to host inode 669 * @inode - pointer to host inode
1300 * @mapping - pointer to mapping 670 * @mapping - pointer to mapping
1301 */ 671 */
1302void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) 672int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
1303{ 673{
1304 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);
1305 682
1306 if (nfsi->cache_validity & NFS_INO_INVALID_DATA) { 683 if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
1307 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE); 684 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
@@ -1322,6 +699,7 @@ void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
1322 inode->i_sb->s_id, 699 inode->i_sb->s_id,
1323 (long long)NFS_FILEID(inode)); 700 (long long)NFS_FILEID(inode));
1324 } 701 }
702 return ret;
1325} 703}
1326 704
1327/** 705/**
@@ -1361,12 +739,6 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1361{ 739{
1362 struct nfs_inode *nfsi = NFS_I(inode); 740 struct nfs_inode *nfsi = NFS_I(inode);
1363 741
1364 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
1365 && nfsi->change_attr == fattr->pre_change_attr) {
1366 nfsi->change_attr = fattr->change_attr;
1367 nfsi->cache_change_attribute = jiffies;
1368 }
1369
1370 /* If we have atomic WCC data, we may update some attributes */ 742 /* If we have atomic WCC data, we may update some attributes */
1371 if ((fattr->valid & NFS_ATTR_WCC) != 0) { 743 if ((fattr->valid & NFS_ATTR_WCC) != 0) {
1372 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) { 744 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
@@ -1400,9 +772,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1400 int data_unstable; 772 int data_unstable;
1401 773
1402 774
1403 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1404 return 0;
1405
1406 /* Has the inode gone and changed behind our back? */ 775 /* Has the inode gone and changed behind our back? */
1407 if (nfsi->fileid != fattr->fileid 776 if (nfsi->fileid != fattr->fileid
1408 || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) { 777 || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
@@ -1415,20 +784,13 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1415 /* Do atomic weak cache consistency updates */ 784 /* Do atomic weak cache consistency updates */
1416 nfs_wcc_update_inode(inode, fattr); 785 nfs_wcc_update_inode(inode, fattr);
1417 786
1418 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0) { 787 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1419 if (nfsi->change_attr == fattr->change_attr) 788 nfsi->change_attr != fattr->change_attr)
1420 goto out; 789 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
1421 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1422 if (!data_unstable)
1423 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1424 }
1425 790
1426 /* Verify a few of the more important attributes */ 791 /* Verify a few of the more important attributes */
1427 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) { 792 if (!timespec_equal(&inode->i_mtime, &fattr->mtime))
1428 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 793 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
1429 if (!data_unstable)
1430 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1431 }
1432 794
1433 cur_size = i_size_read(inode); 795 cur_size = i_size_read(inode);
1434 new_isize = nfs_size_to_loff_t(fattr->size); 796 new_isize = nfs_size_to_loff_t(fattr->size);
@@ -1445,7 +807,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1445 if (inode->i_nlink != fattr->nlink) 807 if (inode->i_nlink != fattr->nlink)
1446 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 808 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1447 809
1448out:
1449 if (!timespec_equal(&inode->i_atime, &fattr->atime)) 810 if (!timespec_equal(&inode->i_atime, &fattr->atime))
1450 nfsi->cache_validity |= NFS_INO_INVALID_ATIME; 811 nfsi->cache_validity |= NFS_INO_INVALID_ATIME;
1451 812
@@ -1471,7 +832,6 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
1471 if ((fattr->valid & NFS_ATTR_FATTR) == 0) 832 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1472 return 0; 833 return 0;
1473 spin_lock(&inode->i_lock); 834 spin_lock(&inode->i_lock);
1474 nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE;
1475 if (time_after(fattr->time_start, nfsi->last_updated)) 835 if (time_after(fattr->time_start, nfsi->last_updated))
1476 status = nfs_update_inode(inode, fattr); 836 status = nfs_update_inode(inode, fattr);
1477 else 837 else
@@ -1496,7 +856,7 @@ int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1496 856
1497 spin_lock(&inode->i_lock); 857 spin_lock(&inode->i_lock);
1498 if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) { 858 if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
1499 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;
1500 goto out; 860 goto out;
1501 } 861 }
1502 status = nfs_update_inode(inode, fattr); 862 status = nfs_update_inode(inode, fattr);
@@ -1519,6 +879,7 @@ out:
1519 */ 879 */
1520static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) 880static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1521{ 881{
882 struct nfs_server *server;
1522 struct nfs_inode *nfsi = NFS_I(inode); 883 struct nfs_inode *nfsi = NFS_I(inode);
1523 loff_t cur_isize, new_isize; 884 loff_t cur_isize, new_isize;
1524 unsigned int invalid = 0; 885 unsigned int invalid = 0;
@@ -1528,9 +889,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1528 __FUNCTION__, inode->i_sb->s_id, inode->i_ino, 889 __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
1529 atomic_read(&inode->i_count), fattr->valid); 890 atomic_read(&inode->i_count), fattr->valid);
1530 891
1531 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1532 return 0;
1533
1534 if (nfsi->fileid != fattr->fileid) 892 if (nfsi->fileid != fattr->fileid)
1535 goto out_fileid; 893 goto out_fileid;
1536 894
@@ -1540,6 +898,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1540 if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) 898 if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
1541 goto out_changed; 899 goto out_changed;
1542 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
1543 /* 907 /*
1544 * Update the read time so we don't revalidate too often. 908 * Update the read time so we don't revalidate too often.
1545 */ 909 */
@@ -1549,7 +913,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1549 /* 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? */
1550 data_stable = nfs_verify_change_attribute(inode, fattr->time_start); 914 data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
1551 if (data_stable) 915 if (data_stable)
1552 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);
1553 917
1554 /* Do atomic weak cache consistency updates */ 918 /* Do atomic weak cache consistency updates */
1555 nfs_wcc_update_inode(inode, fattr); 919 nfs_wcc_update_inode(inode, fattr);
@@ -1613,15 +977,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1613 inode->i_blksize = fattr->du.nfs2.blocksize; 977 inode->i_blksize = fattr->du.nfs2.blocksize;
1614 } 978 }
1615 979
1616 if ((fattr->valid & NFS_ATTR_FATTR_V4)) { 980 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1617 if (nfsi->change_attr != fattr->change_attr) { 981 nfsi->change_attr != fattr->change_attr) {
1618 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",
1619 inode->i_sb->s_id, inode->i_ino); 983 inode->i_sb->s_id, inode->i_ino);
1620 nfsi->change_attr = fattr->change_attr; 984 nfsi->change_attr = fattr->change_attr;
1621 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;
1622 nfsi->cache_change_attribute = jiffies; 986 nfsi->cache_change_attribute = jiffies;
1623 } else
1624 invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA);
1625 } 987 }
1626 988
1627 /* Update attrtimeo value if we're out of the unstable period */ 989 /* Update attrtimeo value if we're out of the unstable period */
@@ -1669,202 +1031,15 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1669 goto out_err; 1031 goto out_err;
1670} 1032}
1671 1033
1672/*
1673 * File system information
1674 */
1675
1676static int nfs_set_super(struct super_block *s, void *data)
1677{
1678 s->s_fs_info = data;
1679 return set_anon_super(s, data);
1680}
1681
1682static int nfs_compare_super(struct super_block *sb, void *data)
1683{
1684 struct nfs_server *server = data;
1685 struct nfs_server *old = NFS_SB(sb);
1686
1687 if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr)
1688 return 0;
1689 if (old->addr.sin_port != server->addr.sin_port)
1690 return 0;
1691 return !nfs_compare_fh(&old->fh, &server->fh);
1692}
1693
1694static int nfs_get_sb(struct file_system_type *fs_type,
1695 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1696{
1697 int error;
1698 struct nfs_server *server = NULL;
1699 struct super_block *s;
1700 struct nfs_fh *root;
1701 struct nfs_mount_data *data = raw_data;
1702
1703 error = -EINVAL;
1704 if (data == NULL) {
1705 dprintk("%s: missing data argument\n", __FUNCTION__);
1706 goto out_err_noserver;
1707 }
1708 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
1709 dprintk("%s: bad mount version\n", __FUNCTION__);
1710 goto out_err_noserver;
1711 }
1712 switch (data->version) {
1713 case 1:
1714 data->namlen = 0;
1715 case 2:
1716 data->bsize = 0;
1717 case 3:
1718 if (data->flags & NFS_MOUNT_VER3) {
1719 dprintk("%s: mount structure version %d does not support NFSv3\n",
1720 __FUNCTION__,
1721 data->version);
1722 goto out_err_noserver;
1723 }
1724 data->root.size = NFS2_FHSIZE;
1725 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1726 case 4:
1727 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
1728 dprintk("%s: mount structure version %d does not support strong security\n",
1729 __FUNCTION__,
1730 data->version);
1731 goto out_err_noserver;
1732 }
1733 case 5:
1734 memset(data->context, 0, sizeof(data->context));
1735 }
1736#ifndef CONFIG_NFS_V3
1737 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
1738 error = -EPROTONOSUPPORT;
1739 if (data->flags & NFS_MOUNT_VER3) {
1740 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
1741 goto out_err_noserver;
1742 }
1743#endif /* CONFIG_NFS_V3 */
1744
1745 error = -ENOMEM;
1746 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1747 if (!server)
1748 goto out_err_noserver;
1749 /* Zero out the NFS state stuff */
1750 init_nfsv4_state(server);
1751 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
1752
1753 root = &server->fh;
1754 if (data->flags & NFS_MOUNT_VER3)
1755 root->size = data->root.size;
1756 else
1757 root->size = NFS2_FHSIZE;
1758 error = -EINVAL;
1759 if (root->size > sizeof(root->data)) {
1760 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
1761 goto out_err;
1762 }
1763 memcpy(root->data, data->root.data, root->size);
1764
1765 /* We now require that the mount process passes the remote address */
1766 memcpy(&server->addr, &data->addr, sizeof(server->addr));
1767 if (server->addr.sin_addr.s_addr == INADDR_ANY) {
1768 dprintk("%s: mount program didn't pass remote address!\n",
1769 __FUNCTION__);
1770 goto out_err;
1771 }
1772
1773 /* Fire up rpciod if not yet running */
1774 error = rpciod_up();
1775 if (error < 0) {
1776 dprintk("%s: couldn't start rpciod! Error = %d\n",
1777 __FUNCTION__, error);
1778 goto out_err;
1779 }
1780
1781 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1782 if (IS_ERR(s)) {
1783 error = PTR_ERR(s);
1784 goto out_err_rpciod;
1785 }
1786
1787 if (s->s_root)
1788 goto out_rpciod_down;
1789
1790 s->s_flags = flags;
1791
1792 error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1793 if (error) {
1794 up_write(&s->s_umount);
1795 deactivate_super(s);
1796 return error;
1797 }
1798 s->s_flags |= MS_ACTIVE;
1799 return simple_set_mnt(mnt, s);
1800
1801out_rpciod_down:
1802 rpciod_down();
1803 kfree(server);
1804 return simple_set_mnt(mnt, s);
1805
1806out_err_rpciod:
1807 rpciod_down();
1808out_err:
1809 kfree(server);
1810out_err_noserver:
1811 return error;
1812}
1813
1814static void nfs_kill_super(struct super_block *s)
1815{
1816 struct nfs_server *server = NFS_SB(s);
1817
1818 kill_anon_super(s);
1819
1820 if (!IS_ERR(server->client))
1821 rpc_shutdown_client(server->client);
1822 if (!IS_ERR(server->client_sys))
1823 rpc_shutdown_client(server->client_sys);
1824 if (!IS_ERR(server->client_acl))
1825 rpc_shutdown_client(server->client_acl);
1826
1827 if (!(server->flags & NFS_MOUNT_NONLM))
1828 lockd_down(); /* release rpc.lockd */
1829
1830 rpciod_down(); /* release rpciod */
1831
1832 nfs_free_iostats(server->io_stats);
1833 kfree(server->hostname);
1834 kfree(server);
1835}
1836
1837static struct file_system_type nfs_fs_type = {
1838 .owner = THIS_MODULE,
1839 .name = "nfs",
1840 .get_sb = nfs_get_sb,
1841 .kill_sb = nfs_kill_super,
1842 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
1843};
1844 1034
1845#ifdef CONFIG_NFS_V4 1035#ifdef CONFIG_NFS_V4
1846 1036
1847static void nfs4_clear_inode(struct inode *);
1848
1849
1850static struct super_operations nfs4_sops = {
1851 .alloc_inode = nfs_alloc_inode,
1852 .destroy_inode = nfs_destroy_inode,
1853 .write_inode = nfs_write_inode,
1854 .delete_inode = nfs_delete_inode,
1855 .statfs = nfs_statfs,
1856 .clear_inode = nfs4_clear_inode,
1857 .umount_begin = nfs_umount_begin,
1858 .show_options = nfs_show_options,
1859 .show_stats = nfs_show_stats,
1860};
1861
1862/* 1037/*
1863 * 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
1864 * 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
1865 * nfs_open(). 1040 * nfs_open().
1866 */ 1041 */
1867static void nfs4_clear_inode(struct inode *inode) 1042void nfs4_clear_inode(struct inode *inode)
1868{ 1043{
1869 struct nfs_inode *nfsi = NFS_I(inode); 1044 struct nfs_inode *nfsi = NFS_I(inode);
1870 1045
@@ -1888,365 +1063,9 @@ static void nfs4_clear_inode(struct inode *inode)
1888 nfs4_close_state(state, state->state); 1063 nfs4_close_state(state, state->state);
1889 } 1064 }
1890} 1065}
1891
1892
1893static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
1894{
1895 struct nfs_server *server;
1896 struct nfs4_client *clp = NULL;
1897 struct rpc_xprt *xprt = NULL;
1898 struct rpc_clnt *clnt = NULL;
1899 struct rpc_timeout timeparms;
1900 rpc_authflavor_t authflavour;
1901 int err = -EIO;
1902
1903 sb->s_blocksize_bits = 0;
1904 sb->s_blocksize = 0;
1905 server = NFS_SB(sb);
1906 if (data->rsize != 0)
1907 server->rsize = nfs_block_size(data->rsize, NULL);
1908 if (data->wsize != 0)
1909 server->wsize = nfs_block_size(data->wsize, NULL);
1910 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
1911 server->caps = NFS_CAP_ATOMIC_OPEN;
1912
1913 server->acregmin = data->acregmin*HZ;
1914 server->acregmax = data->acregmax*HZ;
1915 server->acdirmin = data->acdirmin*HZ;
1916 server->acdirmax = data->acdirmax*HZ;
1917
1918 server->rpc_ops = &nfs_v4_clientops;
1919
1920 nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
1921
1922 server->retrans_timeo = timeparms.to_initval;
1923 server->retrans_count = timeparms.to_retries;
1924
1925 clp = nfs4_get_client(&server->addr.sin_addr);
1926 if (!clp) {
1927 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
1928 return -EIO;
1929 }
1930
1931 /* Now create transport and client */
1932 authflavour = RPC_AUTH_UNIX;
1933 if (data->auth_flavourlen != 0) {
1934 if (data->auth_flavourlen != 1) {
1935 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
1936 __FUNCTION__, data->auth_flavourlen);
1937 err = -EINVAL;
1938 goto out_fail;
1939 }
1940 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
1941 err = -EFAULT;
1942 goto out_fail;
1943 }
1944 }
1945
1946 down_write(&clp->cl_sem);
1947 if (IS_ERR(clp->cl_rpcclient)) {
1948 xprt = xprt_create_proto(data->proto, &server->addr, &timeparms);
1949 if (IS_ERR(xprt)) {
1950 up_write(&clp->cl_sem);
1951 err = PTR_ERR(xprt);
1952 dprintk("%s: cannot create RPC transport. Error = %d\n",
1953 __FUNCTION__, err);
1954 goto out_fail;
1955 }
1956 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
1957 server->rpc_ops->version, authflavour);
1958 if (IS_ERR(clnt)) {
1959 up_write(&clp->cl_sem);
1960 err = PTR_ERR(clnt);
1961 dprintk("%s: cannot create RPC client. Error = %d\n",
1962 __FUNCTION__, err);
1963 goto out_fail;
1964 }
1965 clnt->cl_intr = 1;
1966 clnt->cl_softrtry = 1;
1967 clp->cl_rpcclient = clnt;
1968 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1969 nfs_idmap_new(clp);
1970 }
1971 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1972 clnt = rpc_clone_client(clp->cl_rpcclient);
1973 if (!IS_ERR(clnt))
1974 server->nfs4_state = clp;
1975 up_write(&clp->cl_sem);
1976 clp = NULL;
1977
1978 if (IS_ERR(clnt)) {
1979 err = PTR_ERR(clnt);
1980 dprintk("%s: cannot create RPC client. Error = %d\n",
1981 __FUNCTION__, err);
1982 return err;
1983 }
1984
1985 server->client = clnt;
1986
1987 if (server->nfs4_state->cl_idmap == NULL) {
1988 dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
1989 return -ENOMEM;
1990 }
1991
1992 if (clnt->cl_auth->au_flavor != authflavour) {
1993 struct rpc_auth *auth;
1994
1995 auth = rpcauth_create(authflavour, clnt);
1996 if (IS_ERR(auth)) {
1997 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
1998 return PTR_ERR(auth);
1999 }
2000 }
2001
2002 sb->s_time_gran = 1;
2003
2004 sb->s_op = &nfs4_sops;
2005 err = nfs_sb_init(sb, authflavour);
2006 if (err == 0)
2007 return 0;
2008out_fail:
2009 if (clp)
2010 nfs4_put_client(clp);
2011 return err;
2012}
2013
2014static int nfs4_compare_super(struct super_block *sb, void *data)
2015{
2016 struct nfs_server *server = data;
2017 struct nfs_server *old = NFS_SB(sb);
2018
2019 if (strcmp(server->hostname, old->hostname) != 0)
2020 return 0;
2021 if (strcmp(server->mnt_path, old->mnt_path) != 0)
2022 return 0;
2023 return 1;
2024}
2025
2026static void *
2027nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
2028{
2029 void *p = NULL;
2030
2031 if (!src->len)
2032 return ERR_PTR(-EINVAL);
2033 if (src->len < maxlen)
2034 maxlen = src->len;
2035 if (dst == NULL) {
2036 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
2037 if (p == NULL)
2038 return ERR_PTR(-ENOMEM);
2039 }
2040 if (copy_from_user(dst, src->data, maxlen)) {
2041 kfree(p);
2042 return ERR_PTR(-EFAULT);
2043 }
2044 dst[maxlen] = '\0';
2045 return dst;
2046}
2047
2048static int nfs4_get_sb(struct file_system_type *fs_type,
2049 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2050{
2051 int error;
2052 struct nfs_server *server;
2053 struct super_block *s;
2054 struct nfs4_mount_data *data = raw_data;
2055 void *p;
2056
2057 if (data == NULL) {
2058 dprintk("%s: missing data argument\n", __FUNCTION__);
2059 return -EINVAL;
2060 }
2061 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
2062 dprintk("%s: bad mount version\n", __FUNCTION__);
2063 return -EINVAL;
2064 }
2065
2066 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
2067 if (!server)
2068 return -ENOMEM;
2069 /* Zero out the NFS state stuff */
2070 init_nfsv4_state(server);
2071 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
2072
2073 p = nfs_copy_user_string(NULL, &data->hostname, 256);
2074 if (IS_ERR(p))
2075 goto out_err;
2076 server->hostname = p;
2077
2078 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
2079 if (IS_ERR(p))
2080 goto out_err;
2081 server->mnt_path = p;
2082
2083 p = nfs_copy_user_string(server->ip_addr, &data->client_addr,
2084 sizeof(server->ip_addr) - 1);
2085 if (IS_ERR(p))
2086 goto out_err;
2087
2088 /* We now require that the mount process passes the remote address */
2089 if (data->host_addrlen != sizeof(server->addr)) {
2090 error = -EINVAL;
2091 goto out_free;
2092 }
2093 if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) {
2094 error = -EFAULT;
2095 goto out_free;
2096 }
2097 if (server->addr.sin_family != AF_INET ||
2098 server->addr.sin_addr.s_addr == INADDR_ANY) {
2099 dprintk("%s: mount program didn't pass remote IP address!\n",
2100 __FUNCTION__);
2101 error = -EINVAL;
2102 goto out_free;
2103 }
2104
2105 /* Fire up rpciod if not yet running */
2106 error = rpciod_up();
2107 if (error < 0) {
2108 dprintk("%s: couldn't start rpciod! Error = %d\n",
2109 __FUNCTION__, error);
2110 goto out_free;
2111 }
2112
2113 s = sget(fs_type, nfs4_compare_super, nfs_set_super, server);
2114 if (IS_ERR(s)) {
2115 error = PTR_ERR(s);
2116 goto out_free;
2117 }
2118
2119 if (s->s_root) {
2120 kfree(server->mnt_path);
2121 kfree(server->hostname);
2122 kfree(server);
2123 return simple_set_mnt(mnt, s);
2124 }
2125
2126 s->s_flags = flags;
2127
2128 error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
2129 if (error) {
2130 up_write(&s->s_umount);
2131 deactivate_super(s);
2132 return error;
2133 }
2134 s->s_flags |= MS_ACTIVE;
2135 return simple_set_mnt(mnt, s);
2136out_err:
2137 error = PTR_ERR(p);
2138out_free:
2139 kfree(server->mnt_path);
2140 kfree(server->hostname);
2141 kfree(server);
2142 return error;
2143}
2144
2145static void nfs4_kill_super(struct super_block *sb)
2146{
2147 struct nfs_server *server = NFS_SB(sb);
2148
2149 nfs_return_all_delegations(sb);
2150 kill_anon_super(sb);
2151
2152 nfs4_renewd_prepare_shutdown(server);
2153
2154 if (server->client != NULL && !IS_ERR(server->client))
2155 rpc_shutdown_client(server->client);
2156
2157 destroy_nfsv4_state(server);
2158
2159 rpciod_down();
2160
2161 nfs_free_iostats(server->io_stats);
2162 kfree(server->hostname);
2163 kfree(server);
2164}
2165
2166static struct file_system_type nfs4_fs_type = {
2167 .owner = THIS_MODULE,
2168 .name = "nfs4",
2169 .get_sb = nfs4_get_sb,
2170 .kill_sb = nfs4_kill_super,
2171 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
2172};
2173
2174static const int nfs_set_port_min = 0;
2175static const int nfs_set_port_max = 65535;
2176static int param_set_port(const char *val, struct kernel_param *kp)
2177{
2178 char *endp;
2179 int num = simple_strtol(val, &endp, 0);
2180 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
2181 return -EINVAL;
2182 *((int *)kp->arg) = num;
2183 return 0;
2184}
2185
2186module_param_call(callback_tcpport, param_set_port, param_get_int,
2187 &nfs_callback_set_tcpport, 0644);
2188
2189static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
2190{
2191 char *endp;
2192 int num = simple_strtol(val, &endp, 0);
2193 int jif = num * HZ;
2194 if (endp == val || *endp || num < 0 || jif < num)
2195 return -EINVAL;
2196 *((int *)kp->arg) = jif;
2197 return 0;
2198}
2199
2200module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
2201 &nfs_idmap_cache_timeout, 0644);
2202
2203#define nfs4_init_once(nfsi) \
2204 do { \
2205 INIT_LIST_HEAD(&(nfsi)->open_states); \
2206 nfsi->delegation = NULL; \
2207 nfsi->delegation_state = 0; \
2208 init_rwsem(&nfsi->rwsem); \
2209 } while(0)
2210
2211static inline int register_nfs4fs(void)
2212{
2213 int ret;
2214
2215 ret = nfs_register_sysctl();
2216 if (ret != 0)
2217 return ret;
2218 ret = register_filesystem(&nfs4_fs_type);
2219 if (ret != 0)
2220 nfs_unregister_sysctl();
2221 return ret;
2222}
2223
2224static inline void unregister_nfs4fs(void)
2225{
2226 unregister_filesystem(&nfs4_fs_type);
2227 nfs_unregister_sysctl();
2228}
2229#else
2230#define nfs4_init_once(nfsi) \
2231 do { } while (0)
2232#define register_nfs4fs() (0)
2233#define unregister_nfs4fs()
2234#endif 1066#endif
2235 1067
2236extern int nfs_init_nfspagecache(void); 1068struct inode *nfs_alloc_inode(struct super_block *sb)
2237extern void nfs_destroy_nfspagecache(void);
2238extern int nfs_init_readpagecache(void);
2239extern void nfs_destroy_readpagecache(void);
2240extern int nfs_init_writepagecache(void);
2241extern void nfs_destroy_writepagecache(void);
2242#ifdef CONFIG_NFS_DIRECTIO
2243extern int nfs_init_directcache(void);
2244extern void nfs_destroy_directcache(void);
2245#endif
2246
2247static kmem_cache_t * nfs_inode_cachep;
2248
2249static struct inode *nfs_alloc_inode(struct super_block *sb)
2250{ 1069{
2251 struct nfs_inode *nfsi; 1070 struct nfs_inode *nfsi;
2252 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);
@@ -2265,11 +1084,19 @@ static struct inode *nfs_alloc_inode(struct super_block *sb)
2265 return &nfsi->vfs_inode; 1084 return &nfsi->vfs_inode;
2266} 1085}
2267 1086
2268static void nfs_destroy_inode(struct inode *inode) 1087void nfs_destroy_inode(struct inode *inode)
2269{ 1088{
2270 kmem_cache_free(nfs_inode_cachep, NFS_I(inode)); 1089 kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
2271} 1090}
2272 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
2273static 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)
2274{ 1101{
2275 struct nfs_inode *nfsi = (struct nfs_inode *) foo; 1102 struct nfs_inode *nfsi = (struct nfs_inode *) foo;
@@ -2290,7 +1117,7 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2290 } 1117 }
2291} 1118}
2292 1119
2293static int nfs_init_inodecache(void) 1120static int __init nfs_init_inodecache(void)
2294{ 1121{
2295 nfs_inode_cachep = kmem_cache_create("nfs_inode_cache", 1122 nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
2296 sizeof(struct nfs_inode), 1123 sizeof(struct nfs_inode),
@@ -2303,7 +1130,7 @@ static int nfs_init_inodecache(void)
2303 return 0; 1130 return 0;
2304} 1131}
2305 1132
2306static void nfs_destroy_inodecache(void) 1133static void __exit nfs_destroy_inodecache(void)
2307{ 1134{
2308 if (kmem_cache_destroy(nfs_inode_cachep)) 1135 if (kmem_cache_destroy(nfs_inode_cachep))
2309 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");
@@ -2332,29 +1159,22 @@ static int __init init_nfs_fs(void)
2332 if (err) 1159 if (err)
2333 goto out1; 1160 goto out1;
2334 1161
2335#ifdef CONFIG_NFS_DIRECTIO
2336 err = nfs_init_directcache(); 1162 err = nfs_init_directcache();
2337 if (err) 1163 if (err)
2338 goto out0; 1164 goto out0;
2339#endif
2340 1165
2341#ifdef CONFIG_PROC_FS 1166#ifdef CONFIG_PROC_FS
2342 rpc_proc_register(&nfs_rpcstat); 1167 rpc_proc_register(&nfs_rpcstat);
2343#endif 1168#endif
2344 err = register_filesystem(&nfs_fs_type); 1169 if ((err = register_nfs_fs()) != 0)
2345 if (err)
2346 goto out;
2347 if ((err = register_nfs4fs()) != 0)
2348 goto out; 1170 goto out;
2349 return 0; 1171 return 0;
2350out: 1172out:
2351#ifdef CONFIG_PROC_FS 1173#ifdef CONFIG_PROC_FS
2352 rpc_proc_unregister("nfs"); 1174 rpc_proc_unregister("nfs");
2353#endif 1175#endif
2354#ifdef CONFIG_NFS_DIRECTIO
2355 nfs_destroy_directcache(); 1176 nfs_destroy_directcache();
2356out0: 1177out0:
2357#endif
2358 nfs_destroy_writepagecache(); 1178 nfs_destroy_writepagecache();
2359out1: 1179out1:
2360 nfs_destroy_readpagecache(); 1180 nfs_destroy_readpagecache();
@@ -2368,9 +1188,7 @@ out4:
2368 1188
2369static void __exit exit_nfs_fs(void) 1189static void __exit exit_nfs_fs(void)
2370{ 1190{
2371#ifdef CONFIG_NFS_DIRECTIO
2372 nfs_destroy_directcache(); 1191 nfs_destroy_directcache();
2373#endif
2374 nfs_destroy_writepagecache(); 1192 nfs_destroy_writepagecache();
2375 nfs_destroy_readpagecache(); 1193 nfs_destroy_readpagecache();
2376 nfs_destroy_inodecache(); 1194 nfs_destroy_inodecache();
@@ -2378,8 +1196,7 @@ static void __exit exit_nfs_fs(void)
2378#ifdef CONFIG_PROC_FS 1196#ifdef CONFIG_PROC_FS
2379 rpc_proc_unregister("nfs"); 1197 rpc_proc_unregister("nfs");
2380#endif 1198#endif
2381 unregister_filesystem(&nfs_fs_type); 1199 unregister_nfs_fs();
2382 unregister_nfs4fs();
2383} 1200}
2384 1201
2385/* 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..67391eef6b93 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -23,12 +23,11 @@
23#include <linux/nfs.h> 23#include <linux/nfs.h>
24#include <linux/nfs2.h> 24#include <linux/nfs2.h>
25#include <linux/nfs_fs.h> 25#include <linux/nfs_fs.h>
26#include "internal.h"
26 27
27#define NFSDBG_FACILITY NFSDBG_XDR 28#define NFSDBG_FACILITY NFSDBG_XDR
28/* #define NFS_PARANOIA 1 */ 29/* #define NFS_PARANOIA 1 */
29 30
30extern int nfs_stat_to_errno(int stat);
31
32/* Mapping from NFS error code to "errno" error code. */ 31/* Mapping from NFS error code to "errno" error code. */
33#define errno_NFSERR_IO EIO 32#define errno_NFSERR_IO EIO
34 33
@@ -131,7 +130,8 @@ xdr_decode_fattr(u32 *p, struct nfs_fattr *fattr)
131 fattr->du.nfs2.blocksize = ntohl(*p++); 130 fattr->du.nfs2.blocksize = ntohl(*p++);
132 rdev = ntohl(*p++); 131 rdev = ntohl(*p++);
133 fattr->du.nfs2.blocks = ntohl(*p++); 132 fattr->du.nfs2.blocks = ntohl(*p++);
134 fattr->fsid_u.nfs3 = ntohl(*p++); 133 fattr->fsid.major = ntohl(*p++);
134 fattr->fsid.minor = 0;
135 fattr->fileid = ntohl(*p++); 135 fattr->fileid = ntohl(*p++);
136 p = xdr_decode_time(p, &fattr->atime); 136 p = xdr_decode_time(p, &fattr->atime);
137 p = xdr_decode_time(p, &fattr->mtime); 137 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..b977748553d3
--- /dev/null
+++ b/fs/nfs/super.c
@@ -0,0 +1,1533 @@
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 dentry *, struct kstatfs *);
111static int nfs_show_options(struct seq_file *, struct vfsmount *);
112static int nfs_show_stats(struct seq_file *, struct vfsmount *);
113static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
114static int nfs_clone_nfs_sb(struct file_system_type *fs_type,
115 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
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 int nfs4_get_sb(struct file_system_type *fs_type,
147 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
148static int nfs_clone_nfs4_sb(struct file_system_type *fs_type,
149 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
150static int nfs_referral_nfs4_sb(struct file_system_type *fs_type,
151 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
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 dentry *dentry, struct kstatfs *buf)
267{
268 struct super_block *sb = dentry->d_sb;
269 struct nfs_server *server = NFS_SB(sb);
270 unsigned char blockbits;
271 unsigned long blockres;
272 struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode);
273 struct nfs_fattr fattr;
274 struct nfs_fsstat res = {
275 .fattr = &fattr,
276 };
277 int error;
278
279 lock_kernel();
280
281 error = server->rpc_ops->statfs(server, rootfh, &res);
282 buf->f_type = NFS_SUPER_MAGIC;
283 if (error < 0)
284 goto out_err;
285
286 /*
287 * Current versions of glibc do not correctly handle the
288 * case where f_frsize != f_bsize. Eventually we want to
289 * report the value of wtmult in this field.
290 */
291 buf->f_frsize = sb->s_blocksize;
292
293 /*
294 * On most *nix systems, f_blocks, f_bfree, and f_bavail
295 * are reported in units of f_frsize. Linux hasn't had
296 * an f_frsize field in its statfs struct until recently,
297 * thus historically Linux's sys_statfs reports these
298 * fields in units of f_bsize.
299 */
300 buf->f_bsize = sb->s_blocksize;
301 blockbits = sb->s_blocksize_bits;
302 blockres = (1 << blockbits) - 1;
303 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
304 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
305 buf->f_bavail = (res.abytes + blockres) >> blockbits;
306
307 buf->f_files = res.tfiles;
308 buf->f_ffree = res.afiles;
309
310 buf->f_namelen = server->namelen;
311 out:
312 unlock_kernel();
313 return 0;
314
315 out_err:
316 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
317 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
318 goto out;
319
320}
321
322static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
323{
324 static struct {
325 rpc_authflavor_t flavour;
326 const char *str;
327 } sec_flavours[] = {
328 { RPC_AUTH_NULL, "null" },
329 { RPC_AUTH_UNIX, "sys" },
330 { RPC_AUTH_GSS_KRB5, "krb5" },
331 { RPC_AUTH_GSS_KRB5I, "krb5i" },
332 { RPC_AUTH_GSS_KRB5P, "krb5p" },
333 { RPC_AUTH_GSS_LKEY, "lkey" },
334 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
335 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
336 { RPC_AUTH_GSS_SPKM, "spkm" },
337 { RPC_AUTH_GSS_SPKMI, "spkmi" },
338 { RPC_AUTH_GSS_SPKMP, "spkmp" },
339 { -1, "unknown" }
340 };
341 int i;
342
343 for (i=0; sec_flavours[i].flavour != -1; i++) {
344 if (sec_flavours[i].flavour == flavour)
345 break;
346 }
347 return sec_flavours[i].str;
348}
349
350/*
351 * Describe the mount options in force on this server representation
352 */
353static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
354{
355 static struct proc_nfs_info {
356 int flag;
357 char *str;
358 char *nostr;
359 } nfs_info[] = {
360 { NFS_MOUNT_SOFT, ",soft", ",hard" },
361 { NFS_MOUNT_INTR, ",intr", "" },
362 { NFS_MOUNT_NOCTO, ",nocto", "" },
363 { NFS_MOUNT_NOAC, ",noac", "" },
364 { NFS_MOUNT_NONLM, ",nolock", "" },
365 { NFS_MOUNT_NOACL, ",noacl", "" },
366 { 0, NULL, NULL }
367 };
368 struct proc_nfs_info *nfs_infop;
369 char buf[12];
370 char *proto;
371
372 seq_printf(m, ",vers=%d", nfss->rpc_ops->version);
373 seq_printf(m, ",rsize=%d", nfss->rsize);
374 seq_printf(m, ",wsize=%d", nfss->wsize);
375 if (nfss->acregmin != 3*HZ || showdefaults)
376 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
377 if (nfss->acregmax != 60*HZ || showdefaults)
378 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
379 if (nfss->acdirmin != 30*HZ || showdefaults)
380 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
381 if (nfss->acdirmax != 60*HZ || showdefaults)
382 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
383 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
384 if (nfss->flags & nfs_infop->flag)
385 seq_puts(m, nfs_infop->str);
386 else
387 seq_puts(m, nfs_infop->nostr);
388 }
389 switch (nfss->client->cl_xprt->prot) {
390 case IPPROTO_TCP:
391 proto = "tcp";
392 break;
393 case IPPROTO_UDP:
394 proto = "udp";
395 break;
396 default:
397 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
398 proto = buf;
399 }
400 seq_printf(m, ",proto=%s", proto);
401 seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ);
402 seq_printf(m, ",retrans=%u", nfss->retrans_count);
403 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
404}
405
406/*
407 * Describe the mount options on this VFS mountpoint
408 */
409static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
410{
411 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
412
413 nfs_show_mount_options(m, nfss, 0);
414
415 seq_puts(m, ",addr=");
416 seq_escape(m, nfss->hostname, " \t\n\\");
417
418 return 0;
419}
420
421/*
422 * Present statistical information for this VFS mountpoint
423 */
424static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
425{
426 int i, cpu;
427 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
428 struct rpc_auth *auth = nfss->client->cl_auth;
429 struct nfs_iostats totals = { };
430
431 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
432
433 /*
434 * Display all mount option settings
435 */
436 seq_printf(m, "\n\topts:\t");
437 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
438 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
439 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
440 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
441 nfs_show_mount_options(m, nfss, 1);
442
443 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
444
445 seq_printf(m, "\n\tcaps:\t");
446 seq_printf(m, "caps=0x%x", nfss->caps);
447 seq_printf(m, ",wtmult=%d", nfss->wtmult);
448 seq_printf(m, ",dtsize=%d", nfss->dtsize);
449 seq_printf(m, ",bsize=%d", nfss->bsize);
450 seq_printf(m, ",namelen=%d", nfss->namelen);
451
452#ifdef CONFIG_NFS_V4
453 if (nfss->rpc_ops->version == 4) {
454 seq_printf(m, "\n\tnfsv4:\t");
455 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
456 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
457 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
458 }
459#endif
460
461 /*
462 * Display security flavor in effect for this mount
463 */
464 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
465 if (auth->au_flavor)
466 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
467
468 /*
469 * Display superblock I/O counters
470 */
471 for_each_possible_cpu(cpu) {
472 struct nfs_iostats *stats;
473
474 preempt_disable();
475 stats = per_cpu_ptr(nfss->io_stats, cpu);
476
477 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
478 totals.events[i] += stats->events[i];
479 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
480 totals.bytes[i] += stats->bytes[i];
481
482 preempt_enable();
483 }
484
485 seq_printf(m, "\n\tevents:\t");
486 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
487 seq_printf(m, "%lu ", totals.events[i]);
488 seq_printf(m, "\n\tbytes:\t");
489 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
490 seq_printf(m, "%Lu ", totals.bytes[i]);
491 seq_printf(m, "\n");
492
493 rpc_print_iostats(m, nfss->client);
494
495 return 0;
496}
497
498/*
499 * Begin unmount by attempting to remove all automounted mountpoints we added
500 * in response to traversals
501 */
502static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
503{
504 struct nfs_server *server;
505 struct rpc_clnt *rpc;
506
507 shrink_submounts(vfsmnt, &nfs_automount_list);
508 if (!(flags & MNT_FORCE))
509 return;
510 /* -EIO all pending I/O */
511 server = NFS_SB(vfsmnt->mnt_sb);
512 rpc = server->client;
513 if (!IS_ERR(rpc))
514 rpc_killall_tasks(rpc);
515 rpc = server->client_acl;
516 if (!IS_ERR(rpc))
517 rpc_killall_tasks(rpc);
518}
519
520/*
521 * Obtain the root inode of the file system.
522 */
523static struct inode *
524nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo)
525{
526 struct nfs_server *server = NFS_SB(sb);
527 int error;
528
529 error = server->rpc_ops->getroot(server, rootfh, fsinfo);
530 if (error < 0) {
531 dprintk("nfs_get_root: getattr error = %d\n", -error);
532 return ERR_PTR(error);
533 }
534
535 server->fsid = fsinfo->fattr->fsid;
536 return nfs_fhget(sb, rootfh, fsinfo->fattr);
537}
538
539/*
540 * Do NFS version-independent mount processing, and sanity checking
541 */
542static int
543nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
544{
545 struct nfs_server *server;
546 struct inode *root_inode;
547 struct nfs_fattr fattr;
548 struct nfs_fsinfo fsinfo = {
549 .fattr = &fattr,
550 };
551 struct nfs_pathconf pathinfo = {
552 .fattr = &fattr,
553 };
554 int no_root_error = 0;
555 unsigned long max_rpc_payload;
556
557 /* We probably want something more informative here */
558 snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
559
560 server = NFS_SB(sb);
561
562 sb->s_magic = NFS_SUPER_MAGIC;
563
564 server->io_stats = nfs_alloc_iostats();
565 if (server->io_stats == NULL)
566 return -ENOMEM;
567
568 root_inode = nfs_get_root(sb, &server->fh, &fsinfo);
569 /* Did getting the root inode fail? */
570 if (IS_ERR(root_inode)) {
571 no_root_error = PTR_ERR(root_inode);
572 goto out_no_root;
573 }
574 sb->s_root = d_alloc_root(root_inode);
575 if (!sb->s_root) {
576 no_root_error = -ENOMEM;
577 goto out_no_root;
578 }
579 sb->s_root->d_op = server->rpc_ops->dentry_ops;
580
581 /* mount time stamp, in seconds */
582 server->mount_time = jiffies;
583
584 /* Get some general file system info */
585 if (server->namelen == 0 &&
586 server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0)
587 server->namelen = pathinfo.max_namelen;
588 /* Work out a lot of parameters */
589 if (server->rsize == 0)
590 server->rsize = nfs_block_size(fsinfo.rtpref, NULL);
591 if (server->wsize == 0)
592 server->wsize = nfs_block_size(fsinfo.wtpref, NULL);
593
594 if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax)
595 server->rsize = nfs_block_size(fsinfo.rtmax, NULL);
596 if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax)
597 server->wsize = nfs_block_size(fsinfo.wtmax, NULL);
598
599 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
600 if (server->rsize > max_rpc_payload)
601 server->rsize = max_rpc_payload;
602 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
603 server->rsize = NFS_MAX_FILE_IO_SIZE;
604 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
605
606 if (server->wsize > max_rpc_payload)
607 server->wsize = max_rpc_payload;
608 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
609 server->wsize = NFS_MAX_FILE_IO_SIZE;
610 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
611
612 if (sb->s_blocksize == 0)
613 sb->s_blocksize = nfs_block_bits(server->wsize,
614 &sb->s_blocksize_bits);
615 server->wtmult = nfs_block_bits(fsinfo.wtmult, NULL);
616
617 server->dtsize = nfs_block_size(fsinfo.dtpref, NULL);
618 if (server->dtsize > PAGE_CACHE_SIZE)
619 server->dtsize = PAGE_CACHE_SIZE;
620 if (server->dtsize > server->rsize)
621 server->dtsize = server->rsize;
622
623 if (server->flags & NFS_MOUNT_NOAC) {
624 server->acregmin = server->acregmax = 0;
625 server->acdirmin = server->acdirmax = 0;
626 sb->s_flags |= MS_SYNCHRONOUS;
627 }
628 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
629
630 nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
631
632 server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
633 server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
634
635 /* We're airborne Set socket buffersize */
636 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
637 return 0;
638 /* Yargs. It didn't work out. */
639out_no_root:
640 dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error);
641 if (!IS_ERR(root_inode))
642 iput(root_inode);
643 return no_root_error;
644}
645
646/*
647 * Initialise the timeout values for a connection
648 */
649static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, unsigned int timeo, unsigned int retrans)
650{
651 to->to_initval = timeo * HZ / 10;
652 to->to_retries = retrans;
653 if (!to->to_retries)
654 to->to_retries = 2;
655
656 switch (proto) {
657 case IPPROTO_TCP:
658 if (!to->to_initval)
659 to->to_initval = 60 * HZ;
660 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
661 to->to_initval = NFS_MAX_TCP_TIMEOUT;
662 to->to_increment = to->to_initval;
663 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
664 to->to_exponential = 0;
665 break;
666 case IPPROTO_UDP:
667 default:
668 if (!to->to_initval)
669 to->to_initval = 11 * HZ / 10;
670 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
671 to->to_initval = NFS_MAX_UDP_TIMEOUT;
672 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
673 to->to_exponential = 1;
674 break;
675 }
676}
677
678/*
679 * Create an RPC client handle.
680 */
681static struct rpc_clnt *
682nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
683{
684 struct rpc_timeout timeparms;
685 struct rpc_xprt *xprt = NULL;
686 struct rpc_clnt *clnt = NULL;
687 int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;
688
689 nfs_init_timeout_values(&timeparms, proto, data->timeo, data->retrans);
690
691 server->retrans_timeo = timeparms.to_initval;
692 server->retrans_count = timeparms.to_retries;
693
694 /* create transport and client */
695 xprt = xprt_create_proto(proto, &server->addr, &timeparms);
696 if (IS_ERR(xprt)) {
697 dprintk("%s: cannot create RPC transport. Error = %ld\n",
698 __FUNCTION__, PTR_ERR(xprt));
699 return (struct rpc_clnt *)xprt;
700 }
701 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
702 server->rpc_ops->version, data->pseudoflavor);
703 if (IS_ERR(clnt)) {
704 dprintk("%s: cannot create RPC client. Error = %ld\n",
705 __FUNCTION__, PTR_ERR(xprt));
706 goto out_fail;
707 }
708
709 clnt->cl_intr = 1;
710 clnt->cl_softrtry = 1;
711
712 return clnt;
713
714out_fail:
715 return clnt;
716}
717
718/*
719 * Clone a server record
720 */
721static struct nfs_server *nfs_clone_server(struct super_block *sb, struct nfs_clone_mount *data)
722{
723 struct nfs_server *server = NFS_SB(sb);
724 struct nfs_server *parent = NFS_SB(data->sb);
725 struct inode *root_inode;
726 struct nfs_fsinfo fsinfo;
727 void *err = ERR_PTR(-ENOMEM);
728
729 sb->s_op = data->sb->s_op;
730 sb->s_blocksize = data->sb->s_blocksize;
731 sb->s_blocksize_bits = data->sb->s_blocksize_bits;
732 sb->s_maxbytes = data->sb->s_maxbytes;
733
734 server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
735 server->io_stats = nfs_alloc_iostats();
736 if (server->io_stats == NULL)
737 goto out;
738
739 server->client = rpc_clone_client(parent->client);
740 if (IS_ERR((err = server->client)))
741 goto out;
742
743 if (!IS_ERR(parent->client_sys)) {
744 server->client_sys = rpc_clone_client(parent->client_sys);
745 if (IS_ERR((err = server->client_sys)))
746 goto out;
747 }
748 if (!IS_ERR(parent->client_acl)) {
749 server->client_acl = rpc_clone_client(parent->client_acl);
750 if (IS_ERR((err = server->client_acl)))
751 goto out;
752 }
753 root_inode = nfs_fhget(sb, data->fh, data->fattr);
754 if (!root_inode)
755 goto out;
756 sb->s_root = d_alloc_root(root_inode);
757 if (!sb->s_root)
758 goto out_put_root;
759 fsinfo.fattr = data->fattr;
760 if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0)
761 nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
762 sb->s_root->d_op = server->rpc_ops->dentry_ops;
763 sb->s_flags |= MS_ACTIVE;
764 return server;
765out_put_root:
766 iput(root_inode);
767out:
768 return err;
769}
770
771/*
772 * Copy an existing superblock and attach revised data
773 */
774static int nfs_clone_generic_sb(struct nfs_clone_mount *data,
775 struct super_block *(*fill_sb)(struct nfs_server *, struct nfs_clone_mount *),
776 struct nfs_server *(*fill_server)(struct super_block *, struct nfs_clone_mount *),
777 struct vfsmount *mnt)
778{
779 struct nfs_server *server;
780 struct nfs_server *parent = NFS_SB(data->sb);
781 struct super_block *sb = ERR_PTR(-EINVAL);
782 char *hostname;
783 int error = -ENOMEM;
784 int len;
785
786 server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
787 if (server == NULL)
788 goto out_err;
789 memcpy(server, parent, sizeof(*server));
790 hostname = (data->hostname != NULL) ? data->hostname : parent->hostname;
791 len = strlen(hostname) + 1;
792 server->hostname = kmalloc(len, GFP_KERNEL);
793 if (server->hostname == NULL)
794 goto free_server;
795 memcpy(server->hostname, hostname, len);
796 error = rpciod_up();
797 if (error != 0)
798 goto free_hostname;
799
800 sb = fill_sb(server, data);
801 if (IS_ERR(sb)) {
802 error = PTR_ERR(sb);
803 goto kill_rpciod;
804 }
805
806 if (sb->s_root)
807 goto out_rpciod_down;
808
809 server = fill_server(sb, data);
810 if (IS_ERR(server)) {
811 error = PTR_ERR(server);
812 goto out_deactivate;
813 }
814 return simple_set_mnt(mnt, sb);
815out_deactivate:
816 up_write(&sb->s_umount);
817 deactivate_super(sb);
818 return error;
819out_rpciod_down:
820 rpciod_down();
821 kfree(server->hostname);
822 kfree(server);
823 return simple_set_mnt(mnt, sb);
824kill_rpciod:
825 rpciod_down();
826free_hostname:
827 kfree(server->hostname);
828free_server:
829 kfree(server);
830out_err:
831 return error;
832}
833
834/*
835 * Set up an NFS2/3 superblock
836 *
837 * The way this works is that the mount process passes a structure
838 * in the data argument which contains the server's IP address
839 * and the root file handle obtained from the server's mount
840 * daemon. We stash these away in the private superblock fields.
841 */
842static int
843nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
844{
845 struct nfs_server *server;
846 rpc_authflavor_t authflavor;
847
848 server = NFS_SB(sb);
849 sb->s_blocksize_bits = 0;
850 sb->s_blocksize = 0;
851 if (data->bsize)
852 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
853 if (data->rsize)
854 server->rsize = nfs_block_size(data->rsize, NULL);
855 if (data->wsize)
856 server->wsize = nfs_block_size(data->wsize, NULL);
857 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
858
859 server->acregmin = data->acregmin*HZ;
860 server->acregmax = data->acregmax*HZ;
861 server->acdirmin = data->acdirmin*HZ;
862 server->acdirmax = data->acdirmax*HZ;
863
864 /* Start lockd here, before we might error out */
865 if (!(server->flags & NFS_MOUNT_NONLM))
866 lockd_up();
867
868 server->namelen = data->namlen;
869 server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL);
870 if (!server->hostname)
871 return -ENOMEM;
872 strcpy(server->hostname, data->hostname);
873
874 /* Check NFS protocol revision and initialize RPC op vector
875 * and file handle pool. */
876#ifdef CONFIG_NFS_V3
877 if (server->flags & NFS_MOUNT_VER3) {
878 server->rpc_ops = &nfs_v3_clientops;
879 server->caps |= NFS_CAP_READDIRPLUS;
880 } else {
881 server->rpc_ops = &nfs_v2_clientops;
882 }
883#else
884 server->rpc_ops = &nfs_v2_clientops;
885#endif
886
887 /* Fill in pseudoflavor for mount version < 5 */
888 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
889 data->pseudoflavor = RPC_AUTH_UNIX;
890 authflavor = data->pseudoflavor; /* save for sb_init() */
891 /* XXX maybe we want to add a server->pseudoflavor field */
892
893 /* Create RPC client handles */
894 server->client = nfs_create_client(server, data);
895 if (IS_ERR(server->client))
896 return PTR_ERR(server->client);
897 /* RFC 2623, sec 2.3.2 */
898 if (authflavor != RPC_AUTH_UNIX) {
899 struct rpc_auth *auth;
900
901 server->client_sys = rpc_clone_client(server->client);
902 if (IS_ERR(server->client_sys))
903 return PTR_ERR(server->client_sys);
904 auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys);
905 if (IS_ERR(auth))
906 return PTR_ERR(auth);
907 } else {
908 atomic_inc(&server->client->cl_count);
909 server->client_sys = server->client;
910 }
911 if (server->flags & NFS_MOUNT_VER3) {
912#ifdef CONFIG_NFS_V3_ACL
913 if (!(server->flags & NFS_MOUNT_NOACL)) {
914 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
915 /* No errors! Assume that Sun nfsacls are supported */
916 if (!IS_ERR(server->client_acl))
917 server->caps |= NFS_CAP_ACLS;
918 }
919#else
920 server->flags &= ~NFS_MOUNT_NOACL;
921#endif /* CONFIG_NFS_V3_ACL */
922 /*
923 * The VFS shouldn't apply the umask to mode bits. We will
924 * do so ourselves when necessary.
925 */
926 sb->s_flags |= MS_POSIXACL;
927 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
928 server->namelen = NFS3_MAXNAMLEN;
929 sb->s_time_gran = 1;
930 } else {
931 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
932 server->namelen = NFS2_MAXNAMLEN;
933 }
934
935 sb->s_op = &nfs_sops;
936 return nfs_sb_init(sb, authflavor);
937}
938
939static int nfs_set_super(struct super_block *s, void *data)
940{
941 s->s_fs_info = data;
942 return set_anon_super(s, data);
943}
944
945static int nfs_compare_super(struct super_block *sb, void *data)
946{
947 struct nfs_server *server = data;
948 struct nfs_server *old = NFS_SB(sb);
949
950 if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr)
951 return 0;
952 if (old->addr.sin_port != server->addr.sin_port)
953 return 0;
954 return !nfs_compare_fh(&old->fh, &server->fh);
955}
956
957static int nfs_get_sb(struct file_system_type *fs_type,
958 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
959{
960 int error;
961 struct nfs_server *server = NULL;
962 struct super_block *s;
963 struct nfs_fh *root;
964 struct nfs_mount_data *data = raw_data;
965
966 error = -EINVAL;
967 if (data == NULL) {
968 dprintk("%s: missing data argument\n", __FUNCTION__);
969 goto out_err_noserver;
970 }
971 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
972 dprintk("%s: bad mount version\n", __FUNCTION__);
973 goto out_err_noserver;
974 }
975 switch (data->version) {
976 case 1:
977 data->namlen = 0;
978 case 2:
979 data->bsize = 0;
980 case 3:
981 if (data->flags & NFS_MOUNT_VER3) {
982 dprintk("%s: mount structure version %d does not support NFSv3\n",
983 __FUNCTION__,
984 data->version);
985 goto out_err_noserver;
986 }
987 data->root.size = NFS2_FHSIZE;
988 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
989 case 4:
990 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
991 dprintk("%s: mount structure version %d does not support strong security\n",
992 __FUNCTION__,
993 data->version);
994 goto out_err_noserver;
995 }
996 case 5:
997 memset(data->context, 0, sizeof(data->context));
998 }
999#ifndef CONFIG_NFS_V3
1000 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
1001 error = -EPROTONOSUPPORT;
1002 if (data->flags & NFS_MOUNT_VER3) {
1003 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
1004 goto out_err_noserver;
1005 }
1006#endif /* CONFIG_NFS_V3 */
1007
1008 error = -ENOMEM;
1009 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1010 if (!server)
1011 goto out_err_noserver;
1012 /* Zero out the NFS state stuff */
1013 init_nfsv4_state(server);
1014 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
1015
1016 root = &server->fh;
1017 if (data->flags & NFS_MOUNT_VER3)
1018 root->size = data->root.size;
1019 else
1020 root->size = NFS2_FHSIZE;
1021 error = -EINVAL;
1022 if (root->size > sizeof(root->data)) {
1023 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
1024 goto out_err;
1025 }
1026 memcpy(root->data, data->root.data, root->size);
1027
1028 /* We now require that the mount process passes the remote address */
1029 memcpy(&server->addr, &data->addr, sizeof(server->addr));
1030 if (server->addr.sin_addr.s_addr == INADDR_ANY) {
1031 dprintk("%s: mount program didn't pass remote address!\n",
1032 __FUNCTION__);
1033 goto out_err;
1034 }
1035
1036 /* Fire up rpciod if not yet running */
1037 error = rpciod_up();
1038 if (error < 0) {
1039 dprintk("%s: couldn't start rpciod! Error = %d\n",
1040 __FUNCTION__, error);
1041 goto out_err;
1042 }
1043
1044 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1045 if (IS_ERR(s)) {
1046 error = PTR_ERR(s);
1047 goto out_err_rpciod;
1048 }
1049
1050 if (s->s_root)
1051 goto out_rpciod_down;
1052
1053 s->s_flags = flags;
1054
1055 error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1056 if (error) {
1057 up_write(&s->s_umount);
1058 deactivate_super(s);
1059 return error;
1060 }
1061 s->s_flags |= MS_ACTIVE;
1062 return simple_set_mnt(mnt, s);
1063
1064out_rpciod_down:
1065 rpciod_down();
1066 kfree(server);
1067 return simple_set_mnt(mnt, s);
1068
1069out_err_rpciod:
1070 rpciod_down();
1071out_err:
1072 kfree(server);
1073out_err_noserver:
1074 return error;
1075}
1076
1077static void nfs_kill_super(struct super_block *s)
1078{
1079 struct nfs_server *server = NFS_SB(s);
1080
1081 kill_anon_super(s);
1082
1083 if (!IS_ERR(server->client))
1084 rpc_shutdown_client(server->client);
1085 if (!IS_ERR(server->client_sys))
1086 rpc_shutdown_client(server->client_sys);
1087 if (!IS_ERR(server->client_acl))
1088 rpc_shutdown_client(server->client_acl);
1089
1090 if (!(server->flags & NFS_MOUNT_NONLM))
1091 lockd_down(); /* release rpc.lockd */
1092
1093 rpciod_down(); /* release rpciod */
1094
1095 nfs_free_iostats(server->io_stats);
1096 kfree(server->hostname);
1097 kfree(server);
1098 nfs_release_automount_timer();
1099}
1100
1101static struct super_block *nfs_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data)
1102{
1103 struct super_block *sb;
1104
1105 server->fsid = data->fattr->fsid;
1106 nfs_copy_fh(&server->fh, data->fh);
1107 sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1108 if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM))
1109 lockd_up();
1110 return sb;
1111}
1112
1113static int nfs_clone_nfs_sb(struct file_system_type *fs_type,
1114 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1115{
1116 struct nfs_clone_mount *data = raw_data;
1117 return nfs_clone_generic_sb(data, nfs_clone_sb, nfs_clone_server, mnt);
1118}
1119
1120#ifdef CONFIG_NFS_V4
1121static struct rpc_clnt *nfs4_create_client(struct nfs_server *server,
1122 struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor)
1123{
1124 struct nfs4_client *clp;
1125 struct rpc_xprt *xprt = NULL;
1126 struct rpc_clnt *clnt = NULL;
1127 int err = -EIO;
1128
1129 clp = nfs4_get_client(&server->addr.sin_addr);
1130 if (!clp) {
1131 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
1132 return ERR_PTR(err);
1133 }
1134
1135 /* Now create transport and client */
1136 down_write(&clp->cl_sem);
1137 if (IS_ERR(clp->cl_rpcclient)) {
1138 xprt = xprt_create_proto(proto, &server->addr, timeparms);
1139 if (IS_ERR(xprt)) {
1140 up_write(&clp->cl_sem);
1141 err = PTR_ERR(xprt);
1142 dprintk("%s: cannot create RPC transport. Error = %d\n",
1143 __FUNCTION__, err);
1144 goto out_fail;
1145 }
1146 /* Bind to a reserved port! */
1147 xprt->resvport = 1;
1148 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
1149 server->rpc_ops->version, flavor);
1150 if (IS_ERR(clnt)) {
1151 up_write(&clp->cl_sem);
1152 err = PTR_ERR(clnt);
1153 dprintk("%s: cannot create RPC client. Error = %d\n",
1154 __FUNCTION__, err);
1155 goto out_fail;
1156 }
1157 clnt->cl_intr = 1;
1158 clnt->cl_softrtry = 1;
1159 clp->cl_rpcclient = clnt;
1160 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1161 nfs_idmap_new(clp);
1162 }
1163 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1164 clnt = rpc_clone_client(clp->cl_rpcclient);
1165 if (!IS_ERR(clnt))
1166 server->nfs4_state = clp;
1167 up_write(&clp->cl_sem);
1168 clp = NULL;
1169
1170 if (IS_ERR(clnt)) {
1171 dprintk("%s: cannot create RPC client. Error = %d\n",
1172 __FUNCTION__, err);
1173 return clnt;
1174 }
1175
1176 if (server->nfs4_state->cl_idmap == NULL) {
1177 dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
1178 return ERR_PTR(-ENOMEM);
1179 }
1180
1181 if (clnt->cl_auth->au_flavor != flavor) {
1182 struct rpc_auth *auth;
1183
1184 auth = rpcauth_create(flavor, clnt);
1185 if (IS_ERR(auth)) {
1186 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
1187 return (struct rpc_clnt *)auth;
1188 }
1189 }
1190 return clnt;
1191
1192 out_fail:
1193 if (clp)
1194 nfs4_put_client(clp);
1195 return ERR_PTR(err);
1196}
1197
1198/*
1199 * Set up an NFS4 superblock
1200 */
1201static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
1202{
1203 struct nfs_server *server;
1204 struct rpc_timeout timeparms;
1205 rpc_authflavor_t authflavour;
1206 int err = -EIO;
1207
1208 sb->s_blocksize_bits = 0;
1209 sb->s_blocksize = 0;
1210 server = NFS_SB(sb);
1211 if (data->rsize != 0)
1212 server->rsize = nfs_block_size(data->rsize, NULL);
1213 if (data->wsize != 0)
1214 server->wsize = nfs_block_size(data->wsize, NULL);
1215 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
1216 server->caps = NFS_CAP_ATOMIC_OPEN;
1217
1218 server->acregmin = data->acregmin*HZ;
1219 server->acregmax = data->acregmax*HZ;
1220 server->acdirmin = data->acdirmin*HZ;
1221 server->acdirmax = data->acdirmax*HZ;
1222
1223 server->rpc_ops = &nfs_v4_clientops;
1224
1225 nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
1226
1227 server->retrans_timeo = timeparms.to_initval;
1228 server->retrans_count = timeparms.to_retries;
1229
1230 /* Now create transport and client */
1231 authflavour = RPC_AUTH_UNIX;
1232 if (data->auth_flavourlen != 0) {
1233 if (data->auth_flavourlen != 1) {
1234 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
1235 __FUNCTION__, data->auth_flavourlen);
1236 err = -EINVAL;
1237 goto out_fail;
1238 }
1239 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
1240 err = -EFAULT;
1241 goto out_fail;
1242 }
1243 }
1244
1245 server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour);
1246 if (IS_ERR(server->client)) {
1247 err = PTR_ERR(server->client);
1248 dprintk("%s: cannot create RPC client. Error = %d\n",
1249 __FUNCTION__, err);
1250 goto out_fail;
1251 }
1252
1253 sb->s_time_gran = 1;
1254
1255 sb->s_op = &nfs4_sops;
1256 err = nfs_sb_init(sb, authflavour);
1257
1258 out_fail:
1259 return err;
1260}
1261
1262static int nfs4_compare_super(struct super_block *sb, void *data)
1263{
1264 struct nfs_server *server = data;
1265 struct nfs_server *old = NFS_SB(sb);
1266
1267 if (strcmp(server->hostname, old->hostname) != 0)
1268 return 0;
1269 if (strcmp(server->mnt_path, old->mnt_path) != 0)
1270 return 0;
1271 return 1;
1272}
1273
1274static void *
1275nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
1276{
1277 void *p = NULL;
1278
1279 if (!src->len)
1280 return ERR_PTR(-EINVAL);
1281 if (src->len < maxlen)
1282 maxlen = src->len;
1283 if (dst == NULL) {
1284 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
1285 if (p == NULL)
1286 return ERR_PTR(-ENOMEM);
1287 }
1288 if (copy_from_user(dst, src->data, maxlen)) {
1289 kfree(p);
1290 return ERR_PTR(-EFAULT);
1291 }
1292 dst[maxlen] = '\0';
1293 return dst;
1294}
1295
1296static int nfs4_get_sb(struct file_system_type *fs_type,
1297 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1298{
1299 int error;
1300 struct nfs_server *server;
1301 struct super_block *s;
1302 struct nfs4_mount_data *data = raw_data;
1303 void *p;
1304
1305 if (data == NULL) {
1306 dprintk("%s: missing data argument\n", __FUNCTION__);
1307 return -EINVAL;
1308 }
1309 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
1310 dprintk("%s: bad mount version\n", __FUNCTION__);
1311 return -EINVAL;
1312 }
1313
1314 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1315 if (!server)
1316 return -ENOMEM;
1317 /* Zero out the NFS state stuff */
1318 init_nfsv4_state(server);
1319 server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
1320
1321 p = nfs_copy_user_string(NULL, &data->hostname, 256);
1322 if (IS_ERR(p))
1323 goto out_err;
1324 server->hostname = p;
1325
1326 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
1327 if (IS_ERR(p))
1328 goto out_err;
1329 server->mnt_path = p;
1330
1331 p = nfs_copy_user_string(server->ip_addr, &data->client_addr,
1332 sizeof(server->ip_addr) - 1);
1333 if (IS_ERR(p))
1334 goto out_err;
1335
1336 /* We now require that the mount process passes the remote address */
1337 if (data->host_addrlen != sizeof(server->addr)) {
1338 error = -EINVAL;
1339 goto out_free;
1340 }
1341 if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) {
1342 error = -EFAULT;
1343 goto out_free;
1344 }
1345 if (server->addr.sin_family != AF_INET ||
1346 server->addr.sin_addr.s_addr == INADDR_ANY) {
1347 dprintk("%s: mount program didn't pass remote IP address!\n",
1348 __FUNCTION__);
1349 error = -EINVAL;
1350 goto out_free;
1351 }
1352
1353 /* Fire up rpciod if not yet running */
1354 error = rpciod_up();
1355 if (error < 0) {
1356 dprintk("%s: couldn't start rpciod! Error = %d\n",
1357 __FUNCTION__, error);
1358 goto out_free;
1359 }
1360
1361 s = sget(fs_type, nfs4_compare_super, nfs_set_super, server);
1362
1363 if (IS_ERR(s)) {
1364 error = PTR_ERR(s);
1365 goto out_free;
1366 }
1367
1368 if (s->s_root) {
1369 kfree(server->mnt_path);
1370 kfree(server->hostname);
1371 kfree(server);
1372 return simple_set_mnt(mnt, s);
1373 }
1374
1375 s->s_flags = flags;
1376
1377 error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1378 if (error) {
1379 up_write(&s->s_umount);
1380 deactivate_super(s);
1381 return error;
1382 }
1383 s->s_flags |= MS_ACTIVE;
1384 return simple_set_mnt(mnt, s);
1385out_err:
1386 error = PTR_ERR(p);
1387out_free:
1388 kfree(server->mnt_path);
1389 kfree(server->hostname);
1390 kfree(server);
1391 return error;
1392}
1393
1394static void nfs4_kill_super(struct super_block *sb)
1395{
1396 struct nfs_server *server = NFS_SB(sb);
1397
1398 nfs_return_all_delegations(sb);
1399 kill_anon_super(sb);
1400
1401 nfs4_renewd_prepare_shutdown(server);
1402
1403 if (server->client != NULL && !IS_ERR(server->client))
1404 rpc_shutdown_client(server->client);
1405
1406 destroy_nfsv4_state(server);
1407
1408 rpciod_down();
1409
1410 nfs_free_iostats(server->io_stats);
1411 kfree(server->hostname);
1412 kfree(server);
1413 nfs_release_automount_timer();
1414}
1415
1416/*
1417 * Constructs the SERVER-side path
1418 */
1419static inline char *nfs4_dup_path(const struct dentry *dentry)
1420{
1421 char *page = (char *) __get_free_page(GFP_USER);
1422 char *path;
1423
1424 path = nfs4_path(dentry, page, PAGE_SIZE);
1425 if (!IS_ERR(path)) {
1426 int len = PAGE_SIZE + page - path;
1427 char *tmp = path;
1428
1429 path = kmalloc(len, GFP_KERNEL);
1430 if (path)
1431 memcpy(path, tmp, len);
1432 else
1433 path = ERR_PTR(-ENOMEM);
1434 }
1435 free_page((unsigned long)page);
1436 return path;
1437}
1438
1439static struct super_block *nfs4_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data)
1440{
1441 const struct dentry *dentry = data->dentry;
1442 struct nfs4_client *clp = server->nfs4_state;
1443 struct super_block *sb;
1444
1445 server->fsid = data->fattr->fsid;
1446 nfs_copy_fh(&server->fh, data->fh);
1447 server->mnt_path = nfs4_dup_path(dentry);
1448 if (IS_ERR(server->mnt_path)) {
1449 sb = (struct super_block *)server->mnt_path;
1450 goto err;
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 nfs4_server_capabilities(server, &server->fh);
1456
1457 down_write(&clp->cl_sem);
1458 atomic_inc(&clp->cl_count);
1459 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1460 up_write(&clp->cl_sem);
1461 return sb;
1462free_path:
1463 kfree(server->mnt_path);
1464err:
1465 server->mnt_path = NULL;
1466 return sb;
1467}
1468
1469static int nfs_clone_nfs4_sb(struct file_system_type *fs_type,
1470 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1471{
1472 struct nfs_clone_mount *data = raw_data;
1473 return nfs_clone_generic_sb(data, nfs4_clone_sb, nfs_clone_server, mnt);
1474}
1475
1476static struct super_block *nfs4_referral_sb(struct nfs_server *server, struct nfs_clone_mount *data)
1477{
1478 struct super_block *sb = ERR_PTR(-ENOMEM);
1479 int len;
1480
1481 len = strlen(data->mnt_path) + 1;
1482 server->mnt_path = kmalloc(len, GFP_KERNEL);
1483 if (server->mnt_path == NULL)
1484 goto err;
1485 memcpy(server->mnt_path, data->mnt_path, len);
1486 memcpy(&server->addr, data->addr, sizeof(struct sockaddr_in));
1487
1488 sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server);
1489 if (IS_ERR(sb) || sb->s_root)
1490 goto free_path;
1491 return sb;
1492free_path:
1493 kfree(server->mnt_path);
1494err:
1495 server->mnt_path = NULL;
1496 return sb;
1497}
1498
1499static struct nfs_server *nfs4_referral_server(struct super_block *sb, struct nfs_clone_mount *data)
1500{
1501 struct nfs_server *server = NFS_SB(sb);
1502 struct rpc_timeout timeparms;
1503 int proto, timeo, retrans;
1504 void *err;
1505
1506 proto = IPPROTO_TCP;
1507 /* Since we are following a referral and there may be alternatives,
1508 set the timeouts and retries to low values */
1509 timeo = 2;
1510 retrans = 1;
1511 nfs_init_timeout_values(&timeparms, proto, timeo, retrans);
1512
1513 server->client = nfs4_create_client(server, &timeparms, proto, data->authflavor);
1514 if (IS_ERR((err = server->client)))
1515 goto out_err;
1516
1517 sb->s_time_gran = 1;
1518 sb->s_op = &nfs4_sops;
1519 err = ERR_PTR(nfs_sb_init(sb, data->authflavor));
1520 if (!IS_ERR(err))
1521 return server;
1522out_err:
1523 return (struct nfs_server *)err;
1524}
1525
1526static int nfs_referral_nfs4_sb(struct file_system_type *fs_type,
1527 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1528{
1529 struct nfs_clone_mount *data = raw_data;
1530 return nfs_clone_generic_sb(data, nfs4_referral_sb, nfs4_referral_server, mnt);
1531}
1532
1533#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);