diff options
Diffstat (limited to 'fs/nfs/super.c')
-rw-r--r-- | fs/nfs/super.c | 1411 |
1 files changed, 474 insertions, 937 deletions
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index e8a9bee74d9d..b99113b0f65f 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -13,6 +13,11 @@ | |||
13 | * | 13 | * |
14 | * Split from inode.c by David Howells <dhowells@redhat.com> | 14 | * Split from inode.c by David Howells <dhowells@redhat.com> |
15 | * | 15 | * |
16 | * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a | ||
17 | * particular server are held in the same superblock | ||
18 | * - NFS superblocks can have several effective roots to the dentry tree | ||
19 | * - directory type roots are spliced into the tree when a path from one root reaches the root | ||
20 | * of another (see nfs_lookup()) | ||
16 | */ | 21 | */ |
17 | 22 | ||
18 | #include <linux/config.h> | 23 | #include <linux/config.h> |
@@ -52,66 +57,12 @@ | |||
52 | 57 | ||
53 | #define NFSDBG_FACILITY NFSDBG_VFS | 58 | #define NFSDBG_FACILITY NFSDBG_VFS |
54 | 59 | ||
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 | */ | ||
66 | static 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 | |||
80 | static 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 | |||
89 | struct rpc_stat nfs_rpcstat = { | ||
90 | .program = &nfs_program | ||
91 | }; | ||
92 | |||
93 | |||
94 | #ifdef CONFIG_NFS_V3_ACL | ||
95 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; | ||
96 | static struct rpc_version * nfsacl_version[] = { | ||
97 | [3] = &nfsacl_version3, | ||
98 | }; | ||
99 | |||
100 | struct 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 | |||
109 | static void nfs_umount_begin(struct vfsmount *, int); | 60 | static void nfs_umount_begin(struct vfsmount *, int); |
110 | static int nfs_statfs(struct dentry *, struct kstatfs *); | 61 | static int nfs_statfs(struct dentry *, struct kstatfs *); |
111 | static int nfs_show_options(struct seq_file *, struct vfsmount *); | 62 | static int nfs_show_options(struct seq_file *, struct vfsmount *); |
112 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); | 63 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); |
113 | static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *); | 64 | static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *); |
114 | static int nfs_clone_nfs_sb(struct file_system_type *fs_type, | 65 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, |
115 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); | 66 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
116 | static void nfs_kill_super(struct super_block *); | 67 | static void nfs_kill_super(struct super_block *); |
117 | 68 | ||
@@ -123,10 +74,10 @@ static struct file_system_type nfs_fs_type = { | |||
123 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | 74 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
124 | }; | 75 | }; |
125 | 76 | ||
126 | struct file_system_type clone_nfs_fs_type = { | 77 | struct file_system_type nfs_xdev_fs_type = { |
127 | .owner = THIS_MODULE, | 78 | .owner = THIS_MODULE, |
128 | .name = "nfs", | 79 | .name = "nfs", |
129 | .get_sb = nfs_clone_nfs_sb, | 80 | .get_sb = nfs_xdev_get_sb, |
130 | .kill_sb = nfs_kill_super, | 81 | .kill_sb = nfs_kill_super, |
131 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | 82 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
132 | }; | 83 | }; |
@@ -145,10 +96,10 @@ static struct super_operations nfs_sops = { | |||
145 | #ifdef CONFIG_NFS_V4 | 96 | #ifdef CONFIG_NFS_V4 |
146 | static int nfs4_get_sb(struct file_system_type *fs_type, | 97 | static int nfs4_get_sb(struct file_system_type *fs_type, |
147 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); | 98 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
148 | static int nfs_clone_nfs4_sb(struct file_system_type *fs_type, | 99 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, |
149 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); | 100 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
150 | static int nfs_referral_nfs4_sb(struct file_system_type *fs_type, | 101 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, |
151 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); | 102 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
152 | static void nfs4_kill_super(struct super_block *sb); | 103 | static void nfs4_kill_super(struct super_block *sb); |
153 | 104 | ||
154 | static struct file_system_type nfs4_fs_type = { | 105 | static struct file_system_type nfs4_fs_type = { |
@@ -159,18 +110,18 @@ static struct file_system_type nfs4_fs_type = { | |||
159 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | 110 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
160 | }; | 111 | }; |
161 | 112 | ||
162 | struct file_system_type clone_nfs4_fs_type = { | 113 | struct file_system_type nfs4_xdev_fs_type = { |
163 | .owner = THIS_MODULE, | 114 | .owner = THIS_MODULE, |
164 | .name = "nfs4", | 115 | .name = "nfs4", |
165 | .get_sb = nfs_clone_nfs4_sb, | 116 | .get_sb = nfs4_xdev_get_sb, |
166 | .kill_sb = nfs4_kill_super, | 117 | .kill_sb = nfs4_kill_super, |
167 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | 118 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
168 | }; | 119 | }; |
169 | 120 | ||
170 | struct file_system_type nfs_referral_nfs4_fs_type = { | 121 | struct file_system_type nfs4_referral_fs_type = { |
171 | .owner = THIS_MODULE, | 122 | .owner = THIS_MODULE, |
172 | .name = "nfs4", | 123 | .name = "nfs4", |
173 | .get_sb = nfs_referral_nfs4_sb, | 124 | .get_sb = nfs4_referral_get_sb, |
174 | .kill_sb = nfs4_kill_super, | 125 | .kill_sb = nfs4_kill_super, |
175 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | 126 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
176 | }; | 127 | }; |
@@ -187,39 +138,7 @@ static struct super_operations nfs4_sops = { | |||
187 | }; | 138 | }; |
188 | #endif | 139 | #endif |
189 | 140 | ||
190 | #ifdef CONFIG_NFS_V4 | 141 | static struct shrinker *acl_shrinker; |
191 | static const int nfs_set_port_min = 0; | ||
192 | static const int nfs_set_port_max = 65535; | ||
193 | |||
194 | static int param_set_port(const char *val, struct kernel_param *kp) | ||
195 | { | ||
196 | char *endp; | ||
197 | int num = simple_strtol(val, &endp, 0); | ||
198 | if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max) | ||
199 | return -EINVAL; | ||
200 | *((int *)kp->arg) = num; | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | module_param_call(callback_tcpport, param_set_port, param_get_int, | ||
205 | &nfs_callback_set_tcpport, 0644); | ||
206 | #endif | ||
207 | |||
208 | #ifdef CONFIG_NFS_V4 | ||
209 | static int param_set_idmap_timeout(const char *val, struct kernel_param *kp) | ||
210 | { | ||
211 | char *endp; | ||
212 | int num = simple_strtol(val, &endp, 0); | ||
213 | int jif = num * HZ; | ||
214 | if (endp == val || *endp || num < 0 || jif < num) | ||
215 | return -EINVAL; | ||
216 | *((int *)kp->arg) = jif; | ||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int, | ||
221 | &nfs_idmap_cache_timeout, 0644); | ||
222 | #endif | ||
223 | 142 | ||
224 | /* | 143 | /* |
225 | * Register the NFS filesystems | 144 | * Register the NFS filesystems |
@@ -240,6 +159,7 @@ int __init register_nfs_fs(void) | |||
240 | if (ret < 0) | 159 | if (ret < 0) |
241 | goto error_2; | 160 | goto error_2; |
242 | #endif | 161 | #endif |
162 | acl_shrinker = set_shrinker(DEFAULT_SEEKS, nfs_access_cache_shrinker); | ||
243 | return 0; | 163 | return 0; |
244 | 164 | ||
245 | #ifdef CONFIG_NFS_V4 | 165 | #ifdef CONFIG_NFS_V4 |
@@ -257,6 +177,8 @@ error_0: | |||
257 | */ | 177 | */ |
258 | void __exit unregister_nfs_fs(void) | 178 | void __exit unregister_nfs_fs(void) |
259 | { | 179 | { |
180 | if (acl_shrinker != NULL) | ||
181 | remove_shrinker(acl_shrinker); | ||
260 | #ifdef CONFIG_NFS_V4 | 182 | #ifdef CONFIG_NFS_V4 |
261 | unregister_filesystem(&nfs4_fs_type); | 183 | unregister_filesystem(&nfs4_fs_type); |
262 | nfs_unregister_sysctl(); | 184 | nfs_unregister_sysctl(); |
@@ -269,11 +191,10 @@ void __exit unregister_nfs_fs(void) | |||
269 | */ | 191 | */ |
270 | static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) | 192 | static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
271 | { | 193 | { |
272 | struct super_block *sb = dentry->d_sb; | 194 | struct nfs_server *server = NFS_SB(dentry->d_sb); |
273 | struct nfs_server *server = NFS_SB(sb); | ||
274 | unsigned char blockbits; | 195 | unsigned char blockbits; |
275 | unsigned long blockres; | 196 | unsigned long blockres; |
276 | struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode); | 197 | struct nfs_fh *fh = NFS_FH(dentry->d_inode); |
277 | struct nfs_fattr fattr; | 198 | struct nfs_fattr fattr; |
278 | struct nfs_fsstat res = { | 199 | struct nfs_fsstat res = { |
279 | .fattr = &fattr, | 200 | .fattr = &fattr, |
@@ -282,7 +203,7 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
282 | 203 | ||
283 | lock_kernel(); | 204 | lock_kernel(); |
284 | 205 | ||
285 | error = server->rpc_ops->statfs(server, rootfh, &res); | 206 | error = server->nfs_client->rpc_ops->statfs(server, fh, &res); |
286 | buf->f_type = NFS_SUPER_MAGIC; | 207 | buf->f_type = NFS_SUPER_MAGIC; |
287 | if (error < 0) | 208 | if (error < 0) |
288 | goto out_err; | 209 | goto out_err; |
@@ -292,7 +213,7 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
292 | * case where f_frsize != f_bsize. Eventually we want to | 213 | * case where f_frsize != f_bsize. Eventually we want to |
293 | * report the value of wtmult in this field. | 214 | * report the value of wtmult in this field. |
294 | */ | 215 | */ |
295 | buf->f_frsize = sb->s_blocksize; | 216 | buf->f_frsize = dentry->d_sb->s_blocksize; |
296 | 217 | ||
297 | /* | 218 | /* |
298 | * On most *nix systems, f_blocks, f_bfree, and f_bavail | 219 | * On most *nix systems, f_blocks, f_bfree, and f_bavail |
@@ -301,8 +222,8 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
301 | * thus historically Linux's sys_statfs reports these | 222 | * thus historically Linux's sys_statfs reports these |
302 | * fields in units of f_bsize. | 223 | * fields in units of f_bsize. |
303 | */ | 224 | */ |
304 | buf->f_bsize = sb->s_blocksize; | 225 | buf->f_bsize = dentry->d_sb->s_blocksize; |
305 | blockbits = sb->s_blocksize_bits; | 226 | blockbits = dentry->d_sb->s_blocksize_bits; |
306 | blockres = (1 << blockbits) - 1; | 227 | blockres = (1 << blockbits) - 1; |
307 | buf->f_blocks = (res.tbytes + blockres) >> blockbits; | 228 | buf->f_blocks = (res.tbytes + blockres) >> blockbits; |
308 | buf->f_bfree = (res.fbytes + blockres) >> blockbits; | 229 | buf->f_bfree = (res.fbytes + blockres) >> blockbits; |
@@ -323,9 +244,12 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
323 | 244 | ||
324 | } | 245 | } |
325 | 246 | ||
247 | /* | ||
248 | * Map the security flavour number to a name | ||
249 | */ | ||
326 | static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) | 250 | static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) |
327 | { | 251 | { |
328 | static struct { | 252 | static const struct { |
329 | rpc_authflavor_t flavour; | 253 | rpc_authflavor_t flavour; |
330 | const char *str; | 254 | const char *str; |
331 | } sec_flavours[] = { | 255 | } sec_flavours[] = { |
@@ -356,10 +280,10 @@ static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) | |||
356 | */ | 280 | */ |
357 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) | 281 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) |
358 | { | 282 | { |
359 | static struct proc_nfs_info { | 283 | static const struct proc_nfs_info { |
360 | int flag; | 284 | int flag; |
361 | char *str; | 285 | const char *str; |
362 | char *nostr; | 286 | const char *nostr; |
363 | } nfs_info[] = { | 287 | } nfs_info[] = { |
364 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, | 288 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, |
365 | { NFS_MOUNT_INTR, ",intr", "" }, | 289 | { NFS_MOUNT_INTR, ",intr", "" }, |
@@ -369,11 +293,12 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, | |||
369 | { NFS_MOUNT_NOACL, ",noacl", "" }, | 293 | { NFS_MOUNT_NOACL, ",noacl", "" }, |
370 | { 0, NULL, NULL } | 294 | { 0, NULL, NULL } |
371 | }; | 295 | }; |
372 | struct proc_nfs_info *nfs_infop; | 296 | const struct proc_nfs_info *nfs_infop; |
297 | struct nfs_client *clp = nfss->nfs_client; | ||
373 | char buf[12]; | 298 | char buf[12]; |
374 | char *proto; | 299 | const char *proto; |
375 | 300 | ||
376 | seq_printf(m, ",vers=%d", nfss->rpc_ops->version); | 301 | seq_printf(m, ",vers=%d", clp->rpc_ops->version); |
377 | seq_printf(m, ",rsize=%d", nfss->rsize); | 302 | seq_printf(m, ",rsize=%d", nfss->rsize); |
378 | seq_printf(m, ",wsize=%d", nfss->wsize); | 303 | seq_printf(m, ",wsize=%d", nfss->wsize); |
379 | if (nfss->acregmin != 3*HZ || showdefaults) | 304 | if (nfss->acregmin != 3*HZ || showdefaults) |
@@ -402,8 +327,8 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, | |||
402 | proto = buf; | 327 | proto = buf; |
403 | } | 328 | } |
404 | seq_printf(m, ",proto=%s", proto); | 329 | seq_printf(m, ",proto=%s", proto); |
405 | seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ); | 330 | seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ); |
406 | seq_printf(m, ",retrans=%u", nfss->retrans_count); | 331 | seq_printf(m, ",retrans=%u", clp->retrans_count); |
407 | seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor)); | 332 | seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor)); |
408 | } | 333 | } |
409 | 334 | ||
@@ -417,7 +342,7 @@ static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) | |||
417 | nfs_show_mount_options(m, nfss, 0); | 342 | nfs_show_mount_options(m, nfss, 0); |
418 | 343 | ||
419 | seq_puts(m, ",addr="); | 344 | seq_puts(m, ",addr="); |
420 | seq_escape(m, nfss->hostname, " \t\n\\"); | 345 | seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\"); |
421 | 346 | ||
422 | return 0; | 347 | return 0; |
423 | } | 348 | } |
@@ -454,7 +379,7 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) | |||
454 | seq_printf(m, ",namelen=%d", nfss->namelen); | 379 | seq_printf(m, ",namelen=%d", nfss->namelen); |
455 | 380 | ||
456 | #ifdef CONFIG_NFS_V4 | 381 | #ifdef CONFIG_NFS_V4 |
457 | if (nfss->rpc_ops->version == 4) { | 382 | if (nfss->nfs_client->cl_nfsversion == 4) { |
458 | seq_printf(m, "\n\tnfsv4:\t"); | 383 | seq_printf(m, "\n\tnfsv4:\t"); |
459 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); | 384 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
460 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); | 385 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
@@ -501,782 +426,353 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) | |||
501 | 426 | ||
502 | /* | 427 | /* |
503 | * Begin unmount by attempting to remove all automounted mountpoints we added | 428 | * Begin unmount by attempting to remove all automounted mountpoints we added |
504 | * in response to traversals | 429 | * in response to xdev traversals and referrals |
505 | */ | 430 | */ |
506 | static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) | 431 | static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) |
507 | { | 432 | { |
508 | struct nfs_server *server; | ||
509 | struct rpc_clnt *rpc; | ||
510 | |||
511 | shrink_submounts(vfsmnt, &nfs_automount_list); | 433 | shrink_submounts(vfsmnt, &nfs_automount_list); |
512 | if (!(flags & MNT_FORCE)) | ||
513 | return; | ||
514 | /* -EIO all pending I/O */ | ||
515 | server = NFS_SB(vfsmnt->mnt_sb); | ||
516 | rpc = server->client; | ||
517 | if (!IS_ERR(rpc)) | ||
518 | rpc_killall_tasks(rpc); | ||
519 | rpc = server->client_acl; | ||
520 | if (!IS_ERR(rpc)) | ||
521 | rpc_killall_tasks(rpc); | ||
522 | } | 434 | } |
523 | 435 | ||
524 | /* | 436 | /* |
525 | * Obtain the root inode of the file system. | 437 | * Validate the NFS2/NFS3 mount data |
438 | * - fills in the mount root filehandle | ||
526 | */ | 439 | */ |
527 | static struct inode * | 440 | static int nfs_validate_mount_data(struct nfs_mount_data *data, |
528 | nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo) | 441 | struct nfs_fh *mntfh) |
529 | { | 442 | { |
530 | struct nfs_server *server = NFS_SB(sb); | 443 | if (data == NULL) { |
531 | int error; | 444 | dprintk("%s: missing data argument\n", __FUNCTION__); |
532 | 445 | return -EINVAL; | |
533 | error = server->rpc_ops->getroot(server, rootfh, fsinfo); | ||
534 | if (error < 0) { | ||
535 | dprintk("nfs_get_root: getattr error = %d\n", -error); | ||
536 | return ERR_PTR(error); | ||
537 | } | 446 | } |
538 | 447 | ||
539 | server->fsid = fsinfo->fattr->fsid; | 448 | if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) { |
540 | return nfs_fhget(sb, rootfh, fsinfo->fattr); | 449 | dprintk("%s: bad mount version\n", __FUNCTION__); |
541 | } | 450 | return -EINVAL; |
542 | 451 | } | |
543 | /* | ||
544 | * Do NFS version-independent mount processing, and sanity checking | ||
545 | */ | ||
546 | static int | ||
547 | nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor) | ||
548 | { | ||
549 | struct nfs_server *server; | ||
550 | struct inode *root_inode; | ||
551 | struct nfs_fattr fattr; | ||
552 | struct nfs_fsinfo fsinfo = { | ||
553 | .fattr = &fattr, | ||
554 | }; | ||
555 | struct nfs_pathconf pathinfo = { | ||
556 | .fattr = &fattr, | ||
557 | }; | ||
558 | int no_root_error = 0; | ||
559 | unsigned long max_rpc_payload; | ||
560 | |||
561 | /* We probably want something more informative here */ | ||
562 | snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); | ||
563 | |||
564 | server = NFS_SB(sb); | ||
565 | 452 | ||
566 | sb->s_magic = NFS_SUPER_MAGIC; | 453 | switch (data->version) { |
454 | case 1: | ||
455 | data->namlen = 0; | ||
456 | case 2: | ||
457 | data->bsize = 0; | ||
458 | case 3: | ||
459 | if (data->flags & NFS_MOUNT_VER3) { | ||
460 | dprintk("%s: mount structure version %d does not support NFSv3\n", | ||
461 | __FUNCTION__, | ||
462 | data->version); | ||
463 | return -EINVAL; | ||
464 | } | ||
465 | data->root.size = NFS2_FHSIZE; | ||
466 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); | ||
467 | case 4: | ||
468 | if (data->flags & NFS_MOUNT_SECFLAVOUR) { | ||
469 | dprintk("%s: mount structure version %d does not support strong security\n", | ||
470 | __FUNCTION__, | ||
471 | data->version); | ||
472 | return -EINVAL; | ||
473 | } | ||
474 | case 5: | ||
475 | memset(data->context, 0, sizeof(data->context)); | ||
476 | } | ||
567 | 477 | ||
568 | server->io_stats = nfs_alloc_iostats(); | 478 | /* Set the pseudoflavor */ |
569 | if (server->io_stats == NULL) | 479 | if (!(data->flags & NFS_MOUNT_SECFLAVOUR)) |
570 | return -ENOMEM; | 480 | data->pseudoflavor = RPC_AUTH_UNIX; |
571 | 481 | ||
572 | root_inode = nfs_get_root(sb, &server->fh, &fsinfo); | 482 | #ifndef CONFIG_NFS_V3 |
573 | /* Did getting the root inode fail? */ | 483 | /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */ |
574 | if (IS_ERR(root_inode)) { | 484 | if (data->flags & NFS_MOUNT_VER3) { |
575 | no_root_error = PTR_ERR(root_inode); | 485 | dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__); |
576 | goto out_no_root; | 486 | return -EPROTONOSUPPORT; |
577 | } | ||
578 | sb->s_root = d_alloc_root(root_inode); | ||
579 | if (!sb->s_root) { | ||
580 | no_root_error = -ENOMEM; | ||
581 | goto out_no_root; | ||
582 | } | 487 | } |
583 | sb->s_root->d_op = server->rpc_ops->dentry_ops; | 488 | #endif /* CONFIG_NFS_V3 */ |
584 | |||
585 | /* mount time stamp, in seconds */ | ||
586 | server->mount_time = jiffies; | ||
587 | |||
588 | /* Get some general file system info */ | ||
589 | if (server->namelen == 0 && | ||
590 | server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0) | ||
591 | server->namelen = pathinfo.max_namelen; | ||
592 | /* Work out a lot of parameters */ | ||
593 | if (server->rsize == 0) | ||
594 | server->rsize = nfs_block_size(fsinfo.rtpref, NULL); | ||
595 | if (server->wsize == 0) | ||
596 | server->wsize = nfs_block_size(fsinfo.wtpref, NULL); | ||
597 | |||
598 | if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax) | ||
599 | server->rsize = nfs_block_size(fsinfo.rtmax, NULL); | ||
600 | if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax) | ||
601 | server->wsize = nfs_block_size(fsinfo.wtmax, NULL); | ||
602 | |||
603 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); | ||
604 | if (server->rsize > max_rpc_payload) | ||
605 | server->rsize = max_rpc_payload; | ||
606 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) | ||
607 | server->rsize = NFS_MAX_FILE_IO_SIZE; | ||
608 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | ||
609 | |||
610 | if (server->wsize > max_rpc_payload) | ||
611 | server->wsize = max_rpc_payload; | ||
612 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) | ||
613 | server->wsize = NFS_MAX_FILE_IO_SIZE; | ||
614 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | ||
615 | 489 | ||
616 | if (sb->s_blocksize == 0) | 490 | /* We now require that the mount process passes the remote address */ |
617 | sb->s_blocksize = nfs_block_bits(server->wsize, | 491 | if (data->addr.sin_addr.s_addr == INADDR_ANY) { |
618 | &sb->s_blocksize_bits); | 492 | dprintk("%s: mount program didn't pass remote address!\n", |
619 | server->wtmult = nfs_block_bits(fsinfo.wtmult, NULL); | 493 | __FUNCTION__); |
620 | 494 | return -EINVAL; | |
621 | server->dtsize = nfs_block_size(fsinfo.dtpref, NULL); | ||
622 | if (server->dtsize > PAGE_CACHE_SIZE) | ||
623 | server->dtsize = PAGE_CACHE_SIZE; | ||
624 | if (server->dtsize > server->rsize) | ||
625 | server->dtsize = server->rsize; | ||
626 | |||
627 | if (server->flags & NFS_MOUNT_NOAC) { | ||
628 | server->acregmin = server->acregmax = 0; | ||
629 | server->acdirmin = server->acdirmax = 0; | ||
630 | sb->s_flags |= MS_SYNCHRONOUS; | ||
631 | } | 495 | } |
632 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; | ||
633 | 496 | ||
634 | nfs_super_set_maxbytes(sb, fsinfo.maxfilesize); | 497 | /* Prepare the root filehandle */ |
498 | if (data->flags & NFS_MOUNT_VER3) | ||
499 | mntfh->size = data->root.size; | ||
500 | else | ||
501 | mntfh->size = NFS2_FHSIZE; | ||
502 | |||
503 | if (mntfh->size > sizeof(mntfh->data)) { | ||
504 | dprintk("%s: invalid root filehandle\n", __FUNCTION__); | ||
505 | return -EINVAL; | ||
506 | } | ||
635 | 507 | ||
636 | server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0; | 508 | memcpy(mntfh->data, data->root.data, mntfh->size); |
637 | server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0; | 509 | if (mntfh->size < sizeof(mntfh->data)) |
510 | memset(mntfh->data + mntfh->size, 0, | ||
511 | sizeof(mntfh->data) - mntfh->size); | ||
638 | 512 | ||
639 | /* We're airborne Set socket buffersize */ | ||
640 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); | ||
641 | return 0; | 513 | return 0; |
642 | /* Yargs. It didn't work out. */ | ||
643 | out_no_root: | ||
644 | dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error); | ||
645 | if (!IS_ERR(root_inode)) | ||
646 | iput(root_inode); | ||
647 | return no_root_error; | ||
648 | } | 514 | } |
649 | 515 | ||
650 | /* | 516 | /* |
651 | * Initialise the timeout values for a connection | 517 | * Initialise the common bits of the superblock |
652 | */ | 518 | */ |
653 | static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, unsigned int timeo, unsigned int retrans) | 519 | static inline void nfs_initialise_sb(struct super_block *sb) |
654 | { | 520 | { |
655 | to->to_initval = timeo * HZ / 10; | 521 | struct nfs_server *server = NFS_SB(sb); |
656 | to->to_retries = retrans; | ||
657 | if (!to->to_retries) | ||
658 | to->to_retries = 2; | ||
659 | |||
660 | switch (proto) { | ||
661 | case IPPROTO_TCP: | ||
662 | if (!to->to_initval) | ||
663 | to->to_initval = 60 * HZ; | ||
664 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) | ||
665 | to->to_initval = NFS_MAX_TCP_TIMEOUT; | ||
666 | to->to_increment = to->to_initval; | ||
667 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); | ||
668 | to->to_exponential = 0; | ||
669 | break; | ||
670 | case IPPROTO_UDP: | ||
671 | default: | ||
672 | if (!to->to_initval) | ||
673 | to->to_initval = 11 * HZ / 10; | ||
674 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) | ||
675 | to->to_initval = NFS_MAX_UDP_TIMEOUT; | ||
676 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; | ||
677 | to->to_exponential = 1; | ||
678 | break; | ||
679 | } | ||
680 | } | ||
681 | 522 | ||
682 | /* | 523 | sb->s_magic = NFS_SUPER_MAGIC; |
683 | * Create an RPC client handle. | ||
684 | */ | ||
685 | static struct rpc_clnt * | ||
686 | nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data) | ||
687 | { | ||
688 | struct rpc_timeout timeparms; | ||
689 | struct rpc_xprt *xprt = NULL; | ||
690 | struct rpc_clnt *clnt = NULL; | ||
691 | int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP; | ||
692 | |||
693 | nfs_init_timeout_values(&timeparms, proto, data->timeo, data->retrans); | ||
694 | |||
695 | server->retrans_timeo = timeparms.to_initval; | ||
696 | server->retrans_count = timeparms.to_retries; | ||
697 | |||
698 | /* create transport and client */ | ||
699 | xprt = xprt_create_proto(proto, &server->addr, &timeparms); | ||
700 | if (IS_ERR(xprt)) { | ||
701 | dprintk("%s: cannot create RPC transport. Error = %ld\n", | ||
702 | __FUNCTION__, PTR_ERR(xprt)); | ||
703 | return (struct rpc_clnt *)xprt; | ||
704 | } | ||
705 | clnt = rpc_create_client(xprt, server->hostname, &nfs_program, | ||
706 | server->rpc_ops->version, data->pseudoflavor); | ||
707 | if (IS_ERR(clnt)) { | ||
708 | dprintk("%s: cannot create RPC client. Error = %ld\n", | ||
709 | __FUNCTION__, PTR_ERR(xprt)); | ||
710 | goto out_fail; | ||
711 | } | ||
712 | 524 | ||
713 | clnt->cl_intr = 1; | 525 | /* We probably want something more informative here */ |
714 | clnt->cl_softrtry = 1; | 526 | snprintf(sb->s_id, sizeof(sb->s_id), |
527 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); | ||
528 | |||
529 | if (sb->s_blocksize == 0) | ||
530 | sb->s_blocksize = nfs_block_bits(server->wsize, | ||
531 | &sb->s_blocksize_bits); | ||
715 | 532 | ||
716 | return clnt; | 533 | if (server->flags & NFS_MOUNT_NOAC) |
534 | sb->s_flags |= MS_SYNCHRONOUS; | ||
717 | 535 | ||
718 | out_fail: | 536 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
719 | return clnt; | ||
720 | } | 537 | } |
721 | 538 | ||
722 | /* | 539 | /* |
723 | * Clone a server record | 540 | * Finish setting up an NFS2/3 superblock |
724 | */ | 541 | */ |
725 | static struct nfs_server *nfs_clone_server(struct super_block *sb, struct nfs_clone_mount *data) | 542 | static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data) |
726 | { | 543 | { |
727 | struct nfs_server *server = NFS_SB(sb); | 544 | struct nfs_server *server = NFS_SB(sb); |
728 | struct nfs_server *parent = NFS_SB(data->sb); | ||
729 | struct inode *root_inode; | ||
730 | struct nfs_fsinfo fsinfo; | ||
731 | void *err = ERR_PTR(-ENOMEM); | ||
732 | |||
733 | sb->s_op = data->sb->s_op; | ||
734 | sb->s_blocksize = data->sb->s_blocksize; | ||
735 | sb->s_blocksize_bits = data->sb->s_blocksize_bits; | ||
736 | sb->s_maxbytes = data->sb->s_maxbytes; | ||
737 | |||
738 | server->client_sys = server->client_acl = ERR_PTR(-EINVAL); | ||
739 | server->io_stats = nfs_alloc_iostats(); | ||
740 | if (server->io_stats == NULL) | ||
741 | goto out; | ||
742 | |||
743 | server->client = rpc_clone_client(parent->client); | ||
744 | if (IS_ERR((err = server->client))) | ||
745 | goto out; | ||
746 | |||
747 | if (!IS_ERR(parent->client_sys)) { | ||
748 | server->client_sys = rpc_clone_client(parent->client_sys); | ||
749 | if (IS_ERR((err = server->client_sys))) | ||
750 | goto out; | ||
751 | } | ||
752 | if (!IS_ERR(parent->client_acl)) { | ||
753 | server->client_acl = rpc_clone_client(parent->client_acl); | ||
754 | if (IS_ERR((err = server->client_acl))) | ||
755 | goto out; | ||
756 | } | ||
757 | root_inode = nfs_fhget(sb, data->fh, data->fattr); | ||
758 | if (!root_inode) | ||
759 | goto out; | ||
760 | sb->s_root = d_alloc_root(root_inode); | ||
761 | if (!sb->s_root) | ||
762 | goto out_put_root; | ||
763 | fsinfo.fattr = data->fattr; | ||
764 | if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0) | ||
765 | nfs_super_set_maxbytes(sb, fsinfo.maxfilesize); | ||
766 | sb->s_root->d_op = server->rpc_ops->dentry_ops; | ||
767 | sb->s_flags |= MS_ACTIVE; | ||
768 | return server; | ||
769 | out_put_root: | ||
770 | iput(root_inode); | ||
771 | out: | ||
772 | return err; | ||
773 | } | ||
774 | 545 | ||
775 | /* | 546 | sb->s_blocksize_bits = 0; |
776 | * Copy an existing superblock and attach revised data | 547 | sb->s_blocksize = 0; |
777 | */ | 548 | if (data->bsize) |
778 | static int nfs_clone_generic_sb(struct nfs_clone_mount *data, | 549 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
779 | struct super_block *(*fill_sb)(struct nfs_server *, struct nfs_clone_mount *), | ||
780 | struct nfs_server *(*fill_server)(struct super_block *, struct nfs_clone_mount *), | ||
781 | struct vfsmount *mnt) | ||
782 | { | ||
783 | struct nfs_server *server; | ||
784 | struct nfs_server *parent = NFS_SB(data->sb); | ||
785 | struct super_block *sb = ERR_PTR(-EINVAL); | ||
786 | char *hostname; | ||
787 | int error = -ENOMEM; | ||
788 | int len; | ||
789 | |||
790 | server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL); | ||
791 | if (server == NULL) | ||
792 | goto out_err; | ||
793 | memcpy(server, parent, sizeof(*server)); | ||
794 | hostname = (data->hostname != NULL) ? data->hostname : parent->hostname; | ||
795 | len = strlen(hostname) + 1; | ||
796 | server->hostname = kmalloc(len, GFP_KERNEL); | ||
797 | if (server->hostname == NULL) | ||
798 | goto free_server; | ||
799 | memcpy(server->hostname, hostname, len); | ||
800 | error = rpciod_up(); | ||
801 | if (error != 0) | ||
802 | goto free_hostname; | ||
803 | |||
804 | sb = fill_sb(server, data); | ||
805 | if (IS_ERR(sb)) { | ||
806 | error = PTR_ERR(sb); | ||
807 | goto kill_rpciod; | ||
808 | } | ||
809 | |||
810 | if (sb->s_root) | ||
811 | goto out_rpciod_down; | ||
812 | 550 | ||
813 | server = fill_server(sb, data); | 551 | if (server->flags & NFS_MOUNT_VER3) { |
814 | if (IS_ERR(server)) { | 552 | /* The VFS shouldn't apply the umask to mode bits. We will do |
815 | error = PTR_ERR(server); | 553 | * so ourselves when necessary. |
816 | goto out_deactivate; | 554 | */ |
555 | sb->s_flags |= MS_POSIXACL; | ||
556 | sb->s_time_gran = 1; | ||
817 | } | 557 | } |
818 | return simple_set_mnt(mnt, sb); | 558 | |
819 | out_deactivate: | 559 | sb->s_op = &nfs_sops; |
820 | up_write(&sb->s_umount); | 560 | nfs_initialise_sb(sb); |
821 | deactivate_super(sb); | ||
822 | return error; | ||
823 | out_rpciod_down: | ||
824 | rpciod_down(); | ||
825 | kfree(server->hostname); | ||
826 | kfree(server); | ||
827 | return simple_set_mnt(mnt, sb); | ||
828 | kill_rpciod: | ||
829 | rpciod_down(); | ||
830 | free_hostname: | ||
831 | kfree(server->hostname); | ||
832 | free_server: | ||
833 | kfree(server); | ||
834 | out_err: | ||
835 | return error; | ||
836 | } | 561 | } |
837 | 562 | ||
838 | /* | 563 | /* |
839 | * Set up an NFS2/3 superblock | 564 | * Finish setting up a cloned NFS2/3 superblock |
840 | * | ||
841 | * The way this works is that the mount process passes a structure | ||
842 | * in the data argument which contains the server's IP address | ||
843 | * and the root file handle obtained from the server's mount | ||
844 | * daemon. We stash these away in the private superblock fields. | ||
845 | */ | 565 | */ |
846 | static int | 566 | static void nfs_clone_super(struct super_block *sb, |
847 | nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent) | 567 | const struct super_block *old_sb) |
848 | { | 568 | { |
849 | struct nfs_server *server; | 569 | struct nfs_server *server = NFS_SB(sb); |
850 | rpc_authflavor_t authflavor; | ||
851 | 570 | ||
852 | server = NFS_SB(sb); | 571 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
853 | sb->s_blocksize_bits = 0; | 572 | sb->s_blocksize = old_sb->s_blocksize; |
854 | sb->s_blocksize = 0; | 573 | sb->s_maxbytes = old_sb->s_maxbytes; |
855 | if (data->bsize) | ||
856 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); | ||
857 | if (data->rsize) | ||
858 | server->rsize = nfs_block_size(data->rsize, NULL); | ||
859 | if (data->wsize) | ||
860 | server->wsize = nfs_block_size(data->wsize, NULL); | ||
861 | server->flags = data->flags & NFS_MOUNT_FLAGMASK; | ||
862 | |||
863 | server->acregmin = data->acregmin*HZ; | ||
864 | server->acregmax = data->acregmax*HZ; | ||
865 | server->acdirmin = data->acdirmin*HZ; | ||
866 | server->acdirmax = data->acdirmax*HZ; | ||
867 | |||
868 | /* Start lockd here, before we might error out */ | ||
869 | if (!(server->flags & NFS_MOUNT_NONLM)) | ||
870 | lockd_up(); | ||
871 | |||
872 | server->namelen = data->namlen; | ||
873 | server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL); | ||
874 | if (!server->hostname) | ||
875 | return -ENOMEM; | ||
876 | strcpy(server->hostname, data->hostname); | ||
877 | |||
878 | /* Check NFS protocol revision and initialize RPC op vector | ||
879 | * and file handle pool. */ | ||
880 | #ifdef CONFIG_NFS_V3 | ||
881 | if (server->flags & NFS_MOUNT_VER3) { | ||
882 | server->rpc_ops = &nfs_v3_clientops; | ||
883 | server->caps |= NFS_CAP_READDIRPLUS; | ||
884 | } else { | ||
885 | server->rpc_ops = &nfs_v2_clientops; | ||
886 | } | ||
887 | #else | ||
888 | server->rpc_ops = &nfs_v2_clientops; | ||
889 | #endif | ||
890 | 574 | ||
891 | /* Fill in pseudoflavor for mount version < 5 */ | ||
892 | if (!(data->flags & NFS_MOUNT_SECFLAVOUR)) | ||
893 | data->pseudoflavor = RPC_AUTH_UNIX; | ||
894 | authflavor = data->pseudoflavor; /* save for sb_init() */ | ||
895 | /* XXX maybe we want to add a server->pseudoflavor field */ | ||
896 | |||
897 | /* Create RPC client handles */ | ||
898 | server->client = nfs_create_client(server, data); | ||
899 | if (IS_ERR(server->client)) | ||
900 | return PTR_ERR(server->client); | ||
901 | /* RFC 2623, sec 2.3.2 */ | ||
902 | if (authflavor != RPC_AUTH_UNIX) { | ||
903 | struct rpc_auth *auth; | ||
904 | |||
905 | server->client_sys = rpc_clone_client(server->client); | ||
906 | if (IS_ERR(server->client_sys)) | ||
907 | return PTR_ERR(server->client_sys); | ||
908 | auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys); | ||
909 | if (IS_ERR(auth)) | ||
910 | return PTR_ERR(auth); | ||
911 | } else { | ||
912 | atomic_inc(&server->client->cl_count); | ||
913 | server->client_sys = server->client; | ||
914 | } | ||
915 | if (server->flags & NFS_MOUNT_VER3) { | 575 | if (server->flags & NFS_MOUNT_VER3) { |
916 | #ifdef CONFIG_NFS_V3_ACL | 576 | /* The VFS shouldn't apply the umask to mode bits. We will do |
917 | if (!(server->flags & NFS_MOUNT_NOACL)) { | 577 | * so ourselves when necessary. |
918 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); | ||
919 | /* No errors! Assume that Sun nfsacls are supported */ | ||
920 | if (!IS_ERR(server->client_acl)) | ||
921 | server->caps |= NFS_CAP_ACLS; | ||
922 | } | ||
923 | #else | ||
924 | server->flags &= ~NFS_MOUNT_NOACL; | ||
925 | #endif /* CONFIG_NFS_V3_ACL */ | ||
926 | /* | ||
927 | * The VFS shouldn't apply the umask to mode bits. We will | ||
928 | * do so ourselves when necessary. | ||
929 | */ | 578 | */ |
930 | sb->s_flags |= MS_POSIXACL; | 579 | sb->s_flags |= MS_POSIXACL; |
931 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) | ||
932 | server->namelen = NFS3_MAXNAMLEN; | ||
933 | sb->s_time_gran = 1; | 580 | sb->s_time_gran = 1; |
934 | } else { | ||
935 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) | ||
936 | server->namelen = NFS2_MAXNAMLEN; | ||
937 | } | 581 | } |
938 | 582 | ||
939 | sb->s_op = &nfs_sops; | 583 | sb->s_op = old_sb->s_op; |
940 | return nfs_sb_init(sb, authflavor); | 584 | nfs_initialise_sb(sb); |
941 | } | 585 | } |
942 | 586 | ||
943 | static int nfs_set_super(struct super_block *s, void *data) | 587 | static int nfs_set_super(struct super_block *s, void *_server) |
944 | { | 588 | { |
945 | s->s_fs_info = data; | 589 | struct nfs_server *server = _server; |
946 | return set_anon_super(s, data); | 590 | int ret; |
591 | |||
592 | s->s_fs_info = server; | ||
593 | ret = set_anon_super(s, server); | ||
594 | if (ret == 0) | ||
595 | server->s_dev = s->s_dev; | ||
596 | return ret; | ||
947 | } | 597 | } |
948 | 598 | ||
949 | static int nfs_compare_super(struct super_block *sb, void *data) | 599 | static int nfs_compare_super(struct super_block *sb, void *data) |
950 | { | 600 | { |
951 | struct nfs_server *server = data; | 601 | struct nfs_server *server = data, *old = NFS_SB(sb); |
952 | struct nfs_server *old = NFS_SB(sb); | ||
953 | 602 | ||
954 | if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr) | 603 | if (old->nfs_client != server->nfs_client) |
955 | return 0; | 604 | return 0; |
956 | if (old->addr.sin_port != server->addr.sin_port) | 605 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
957 | return 0; | 606 | return 0; |
958 | return !nfs_compare_fh(&old->fh, &server->fh); | 607 | return 1; |
959 | } | 608 | } |
960 | 609 | ||
961 | static int nfs_get_sb(struct file_system_type *fs_type, | 610 | static int nfs_get_sb(struct file_system_type *fs_type, |
962 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) | 611 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
963 | { | 612 | { |
964 | int error; | ||
965 | struct nfs_server *server = NULL; | 613 | struct nfs_server *server = NULL; |
966 | struct super_block *s; | 614 | struct super_block *s; |
967 | struct nfs_fh *root; | 615 | struct nfs_fh mntfh; |
968 | struct nfs_mount_data *data = raw_data; | 616 | struct nfs_mount_data *data = raw_data; |
617 | struct dentry *mntroot; | ||
618 | int error; | ||
969 | 619 | ||
970 | error = -EINVAL; | 620 | /* Validate the mount data */ |
971 | if (data == NULL) { | 621 | error = nfs_validate_mount_data(data, &mntfh); |
972 | dprintk("%s: missing data argument\n", __FUNCTION__); | 622 | if (error < 0) |
973 | goto out_err_noserver; | 623 | return error; |
974 | } | ||
975 | if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) { | ||
976 | dprintk("%s: bad mount version\n", __FUNCTION__); | ||
977 | goto out_err_noserver; | ||
978 | } | ||
979 | switch (data->version) { | ||
980 | case 1: | ||
981 | data->namlen = 0; | ||
982 | case 2: | ||
983 | data->bsize = 0; | ||
984 | case 3: | ||
985 | if (data->flags & NFS_MOUNT_VER3) { | ||
986 | dprintk("%s: mount structure version %d does not support NFSv3\n", | ||
987 | __FUNCTION__, | ||
988 | data->version); | ||
989 | goto out_err_noserver; | ||
990 | } | ||
991 | data->root.size = NFS2_FHSIZE; | ||
992 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); | ||
993 | case 4: | ||
994 | if (data->flags & NFS_MOUNT_SECFLAVOUR) { | ||
995 | dprintk("%s: mount structure version %d does not support strong security\n", | ||
996 | __FUNCTION__, | ||
997 | data->version); | ||
998 | goto out_err_noserver; | ||
999 | } | ||
1000 | case 5: | ||
1001 | memset(data->context, 0, sizeof(data->context)); | ||
1002 | } | ||
1003 | #ifndef CONFIG_NFS_V3 | ||
1004 | /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */ | ||
1005 | error = -EPROTONOSUPPORT; | ||
1006 | if (data->flags & NFS_MOUNT_VER3) { | ||
1007 | dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__); | ||
1008 | goto out_err_noserver; | ||
1009 | } | ||
1010 | #endif /* CONFIG_NFS_V3 */ | ||
1011 | 624 | ||
1012 | error = -ENOMEM; | 625 | /* Get a volume representation */ |
1013 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); | 626 | server = nfs_create_server(data, &mntfh); |
1014 | if (!server) | 627 | if (IS_ERR(server)) { |
628 | error = PTR_ERR(server); | ||
1015 | goto out_err_noserver; | 629 | goto out_err_noserver; |
1016 | /* Zero out the NFS state stuff */ | ||
1017 | init_nfsv4_state(server); | ||
1018 | server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL); | ||
1019 | |||
1020 | root = &server->fh; | ||
1021 | if (data->flags & NFS_MOUNT_VER3) | ||
1022 | root->size = data->root.size; | ||
1023 | else | ||
1024 | root->size = NFS2_FHSIZE; | ||
1025 | error = -EINVAL; | ||
1026 | if (root->size > sizeof(root->data)) { | ||
1027 | dprintk("%s: invalid root filehandle\n", __FUNCTION__); | ||
1028 | goto out_err; | ||
1029 | } | ||
1030 | memcpy(root->data, data->root.data, root->size); | ||
1031 | |||
1032 | /* We now require that the mount process passes the remote address */ | ||
1033 | memcpy(&server->addr, &data->addr, sizeof(server->addr)); | ||
1034 | if (server->addr.sin_addr.s_addr == INADDR_ANY) { | ||
1035 | dprintk("%s: mount program didn't pass remote address!\n", | ||
1036 | __FUNCTION__); | ||
1037 | goto out_err; | ||
1038 | } | ||
1039 | |||
1040 | /* Fire up rpciod if not yet running */ | ||
1041 | error = rpciod_up(); | ||
1042 | if (error < 0) { | ||
1043 | dprintk("%s: couldn't start rpciod! Error = %d\n", | ||
1044 | __FUNCTION__, error); | ||
1045 | goto out_err; | ||
1046 | } | 630 | } |
1047 | 631 | ||
632 | /* Get a superblock - note that we may end up sharing one that already exists */ | ||
1048 | s = sget(fs_type, nfs_compare_super, nfs_set_super, server); | 633 | s = sget(fs_type, nfs_compare_super, nfs_set_super, server); |
1049 | if (IS_ERR(s)) { | 634 | if (IS_ERR(s)) { |
1050 | error = PTR_ERR(s); | 635 | error = PTR_ERR(s); |
1051 | goto out_err_rpciod; | 636 | goto out_err_nosb; |
1052 | } | 637 | } |
1053 | 638 | ||
1054 | if (s->s_root) | 639 | if (s->s_fs_info != server) { |
1055 | goto out_rpciod_down; | 640 | nfs_free_server(server); |
641 | server = NULL; | ||
642 | } | ||
1056 | 643 | ||
1057 | s->s_flags = flags; | 644 | if (!s->s_root) { |
645 | /* initial superblock/root creation */ | ||
646 | s->s_flags = flags; | ||
647 | nfs_fill_super(s, data); | ||
648 | } | ||
1058 | 649 | ||
1059 | error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0); | 650 | mntroot = nfs_get_root(s, &mntfh); |
1060 | if (error) { | 651 | if (IS_ERR(mntroot)) { |
1061 | up_write(&s->s_umount); | 652 | error = PTR_ERR(mntroot); |
1062 | deactivate_super(s); | 653 | goto error_splat_super; |
1063 | return error; | ||
1064 | } | 654 | } |
1065 | s->s_flags |= MS_ACTIVE; | ||
1066 | return simple_set_mnt(mnt, s); | ||
1067 | 655 | ||
1068 | out_rpciod_down: | 656 | s->s_flags |= MS_ACTIVE; |
1069 | rpciod_down(); | 657 | mnt->mnt_sb = s; |
1070 | kfree(server); | 658 | mnt->mnt_root = mntroot; |
1071 | return simple_set_mnt(mnt, s); | 659 | return 0; |
1072 | 660 | ||
1073 | out_err_rpciod: | 661 | out_err_nosb: |
1074 | rpciod_down(); | 662 | nfs_free_server(server); |
1075 | out_err: | ||
1076 | kfree(server); | ||
1077 | out_err_noserver: | 663 | out_err_noserver: |
1078 | return error; | 664 | return error; |
665 | |||
666 | error_splat_super: | ||
667 | up_write(&s->s_umount); | ||
668 | deactivate_super(s); | ||
669 | return error; | ||
1079 | } | 670 | } |
1080 | 671 | ||
672 | /* | ||
673 | * Destroy an NFS2/3 superblock | ||
674 | */ | ||
1081 | static void nfs_kill_super(struct super_block *s) | 675 | static void nfs_kill_super(struct super_block *s) |
1082 | { | 676 | { |
1083 | struct nfs_server *server = NFS_SB(s); | 677 | struct nfs_server *server = NFS_SB(s); |
1084 | 678 | ||
1085 | kill_anon_super(s); | 679 | kill_anon_super(s); |
1086 | 680 | nfs_free_server(server); | |
1087 | if (!IS_ERR(server->client)) | ||
1088 | rpc_shutdown_client(server->client); | ||
1089 | if (!IS_ERR(server->client_sys)) | ||
1090 | rpc_shutdown_client(server->client_sys); | ||
1091 | if (!IS_ERR(server->client_acl)) | ||
1092 | rpc_shutdown_client(server->client_acl); | ||
1093 | |||
1094 | if (!(server->flags & NFS_MOUNT_NONLM)) | ||
1095 | lockd_down(); /* release rpc.lockd */ | ||
1096 | |||
1097 | rpciod_down(); /* release rpciod */ | ||
1098 | |||
1099 | nfs_free_iostats(server->io_stats); | ||
1100 | kfree(server->hostname); | ||
1101 | kfree(server); | ||
1102 | nfs_release_automount_timer(); | ||
1103 | } | ||
1104 | |||
1105 | static struct super_block *nfs_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data) | ||
1106 | { | ||
1107 | struct super_block *sb; | ||
1108 | |||
1109 | server->fsid = data->fattr->fsid; | ||
1110 | nfs_copy_fh(&server->fh, data->fh); | ||
1111 | sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); | ||
1112 | if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM)) | ||
1113 | lockd_up(); | ||
1114 | return sb; | ||
1115 | } | 681 | } |
1116 | 682 | ||
1117 | static int nfs_clone_nfs_sb(struct file_system_type *fs_type, | 683 | /* |
1118 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) | 684 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
685 | */ | ||
686 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, | ||
687 | const char *dev_name, void *raw_data, | ||
688 | struct vfsmount *mnt) | ||
1119 | { | 689 | { |
1120 | struct nfs_clone_mount *data = raw_data; | 690 | struct nfs_clone_mount *data = raw_data; |
1121 | return nfs_clone_generic_sb(data, nfs_clone_sb, nfs_clone_server, mnt); | 691 | struct super_block *s; |
1122 | } | 692 | struct nfs_server *server; |
693 | struct dentry *mntroot; | ||
694 | int error; | ||
1123 | 695 | ||
1124 | #ifdef CONFIG_NFS_V4 | 696 | dprintk("--> nfs_xdev_get_sb()\n"); |
1125 | static struct rpc_clnt *nfs4_create_client(struct nfs_server *server, | ||
1126 | struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor) | ||
1127 | { | ||
1128 | struct nfs4_client *clp; | ||
1129 | struct rpc_xprt *xprt = NULL; | ||
1130 | struct rpc_clnt *clnt = NULL; | ||
1131 | int err = -EIO; | ||
1132 | |||
1133 | clp = nfs4_get_client(&server->addr.sin_addr); | ||
1134 | if (!clp) { | ||
1135 | dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__); | ||
1136 | return ERR_PTR(err); | ||
1137 | } | ||
1138 | 697 | ||
1139 | /* Now create transport and client */ | 698 | /* create a new volume representation */ |
1140 | down_write(&clp->cl_sem); | 699 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
1141 | if (IS_ERR(clp->cl_rpcclient)) { | 700 | if (IS_ERR(server)) { |
1142 | xprt = xprt_create_proto(proto, &server->addr, timeparms); | 701 | error = PTR_ERR(server); |
1143 | if (IS_ERR(xprt)) { | 702 | goto out_err_noserver; |
1144 | up_write(&clp->cl_sem); | ||
1145 | err = PTR_ERR(xprt); | ||
1146 | dprintk("%s: cannot create RPC transport. Error = %d\n", | ||
1147 | __FUNCTION__, err); | ||
1148 | goto out_fail; | ||
1149 | } | ||
1150 | /* Bind to a reserved port! */ | ||
1151 | xprt->resvport = 1; | ||
1152 | clnt = rpc_create_client(xprt, server->hostname, &nfs_program, | ||
1153 | server->rpc_ops->version, flavor); | ||
1154 | if (IS_ERR(clnt)) { | ||
1155 | up_write(&clp->cl_sem); | ||
1156 | err = PTR_ERR(clnt); | ||
1157 | dprintk("%s: cannot create RPC client. Error = %d\n", | ||
1158 | __FUNCTION__, err); | ||
1159 | goto out_fail; | ||
1160 | } | ||
1161 | clnt->cl_intr = 1; | ||
1162 | clnt->cl_softrtry = 1; | ||
1163 | clp->cl_rpcclient = clnt; | ||
1164 | memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr)); | ||
1165 | nfs_idmap_new(clp); | ||
1166 | } | ||
1167 | list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); | ||
1168 | clnt = rpc_clone_client(clp->cl_rpcclient); | ||
1169 | if (!IS_ERR(clnt)) | ||
1170 | server->nfs4_state = clp; | ||
1171 | up_write(&clp->cl_sem); | ||
1172 | clp = NULL; | ||
1173 | |||
1174 | if (IS_ERR(clnt)) { | ||
1175 | dprintk("%s: cannot create RPC client. Error = %d\n", | ||
1176 | __FUNCTION__, err); | ||
1177 | return clnt; | ||
1178 | } | 703 | } |
1179 | 704 | ||
1180 | if (server->nfs4_state->cl_idmap == NULL) { | 705 | /* Get a superblock - note that we may end up sharing one that already exists */ |
1181 | dprintk("%s: failed to create idmapper.\n", __FUNCTION__); | 706 | s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); |
1182 | return ERR_PTR(-ENOMEM); | 707 | if (IS_ERR(s)) { |
708 | error = PTR_ERR(s); | ||
709 | goto out_err_nosb; | ||
1183 | } | 710 | } |
1184 | 711 | ||
1185 | if (clnt->cl_auth->au_flavor != flavor) { | 712 | if (s->s_fs_info != server) { |
1186 | struct rpc_auth *auth; | 713 | nfs_free_server(server); |
1187 | 714 | server = NULL; | |
1188 | auth = rpcauth_create(flavor, clnt); | ||
1189 | if (IS_ERR(auth)) { | ||
1190 | dprintk("%s: couldn't create credcache!\n", __FUNCTION__); | ||
1191 | return (struct rpc_clnt *)auth; | ||
1192 | } | ||
1193 | } | 715 | } |
1194 | return clnt; | ||
1195 | |||
1196 | out_fail: | ||
1197 | if (clp) | ||
1198 | nfs4_put_client(clp); | ||
1199 | return ERR_PTR(err); | ||
1200 | } | ||
1201 | |||
1202 | /* | ||
1203 | * Set up an NFS4 superblock | ||
1204 | */ | ||
1205 | static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent) | ||
1206 | { | ||
1207 | struct nfs_server *server; | ||
1208 | struct rpc_timeout timeparms; | ||
1209 | rpc_authflavor_t authflavour; | ||
1210 | int err = -EIO; | ||
1211 | 716 | ||
1212 | sb->s_blocksize_bits = 0; | 717 | if (!s->s_root) { |
1213 | sb->s_blocksize = 0; | 718 | /* initial superblock/root creation */ |
1214 | server = NFS_SB(sb); | 719 | s->s_flags = flags; |
1215 | if (data->rsize != 0) | 720 | nfs_clone_super(s, data->sb); |
1216 | server->rsize = nfs_block_size(data->rsize, NULL); | 721 | } |
1217 | if (data->wsize != 0) | ||
1218 | server->wsize = nfs_block_size(data->wsize, NULL); | ||
1219 | server->flags = data->flags & NFS_MOUNT_FLAGMASK; | ||
1220 | server->caps = NFS_CAP_ATOMIC_OPEN; | ||
1221 | 722 | ||
1222 | server->acregmin = data->acregmin*HZ; | 723 | mntroot = nfs_get_root(s, data->fh); |
1223 | server->acregmax = data->acregmax*HZ; | 724 | if (IS_ERR(mntroot)) { |
1224 | server->acdirmin = data->acdirmin*HZ; | 725 | error = PTR_ERR(mntroot); |
1225 | server->acdirmax = data->acdirmax*HZ; | 726 | goto error_splat_super; |
727 | } | ||
1226 | 728 | ||
1227 | server->rpc_ops = &nfs_v4_clientops; | 729 | s->s_flags |= MS_ACTIVE; |
730 | mnt->mnt_sb = s; | ||
731 | mnt->mnt_root = mntroot; | ||
1228 | 732 | ||
1229 | nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans); | 733 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
734 | return 0; | ||
1230 | 735 | ||
1231 | server->retrans_timeo = timeparms.to_initval; | 736 | out_err_nosb: |
1232 | server->retrans_count = timeparms.to_retries; | 737 | nfs_free_server(server); |
738 | out_err_noserver: | ||
739 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); | ||
740 | return error; | ||
1233 | 741 | ||
1234 | /* Now create transport and client */ | 742 | error_splat_super: |
1235 | authflavour = RPC_AUTH_UNIX; | 743 | up_write(&s->s_umount); |
1236 | if (data->auth_flavourlen != 0) { | 744 | deactivate_super(s); |
1237 | if (data->auth_flavourlen != 1) { | 745 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
1238 | dprintk("%s: Invalid number of RPC auth flavours %d.\n", | 746 | return error; |
1239 | __FUNCTION__, data->auth_flavourlen); | 747 | } |
1240 | err = -EINVAL; | ||
1241 | goto out_fail; | ||
1242 | } | ||
1243 | if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) { | ||
1244 | err = -EFAULT; | ||
1245 | goto out_fail; | ||
1246 | } | ||
1247 | } | ||
1248 | 748 | ||
1249 | server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour); | 749 | #ifdef CONFIG_NFS_V4 |
1250 | if (IS_ERR(server->client)) { | ||
1251 | err = PTR_ERR(server->client); | ||
1252 | dprintk("%s: cannot create RPC client. Error = %d\n", | ||
1253 | __FUNCTION__, err); | ||
1254 | goto out_fail; | ||
1255 | } | ||
1256 | 750 | ||
751 | /* | ||
752 | * Finish setting up a cloned NFS4 superblock | ||
753 | */ | ||
754 | static void nfs4_clone_super(struct super_block *sb, | ||
755 | const struct super_block *old_sb) | ||
756 | { | ||
757 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; | ||
758 | sb->s_blocksize = old_sb->s_blocksize; | ||
759 | sb->s_maxbytes = old_sb->s_maxbytes; | ||
1257 | sb->s_time_gran = 1; | 760 | sb->s_time_gran = 1; |
1258 | 761 | sb->s_op = old_sb->s_op; | |
1259 | sb->s_op = &nfs4_sops; | 762 | nfs_initialise_sb(sb); |
1260 | err = nfs_sb_init(sb, authflavour); | ||
1261 | |||
1262 | out_fail: | ||
1263 | return err; | ||
1264 | } | 763 | } |
1265 | 764 | ||
1266 | static int nfs4_compare_super(struct super_block *sb, void *data) | 765 | /* |
766 | * Set up an NFS4 superblock | ||
767 | */ | ||
768 | static void nfs4_fill_super(struct super_block *sb) | ||
1267 | { | 769 | { |
1268 | struct nfs_server *server = data; | 770 | sb->s_time_gran = 1; |
1269 | struct nfs_server *old = NFS_SB(sb); | 771 | sb->s_op = &nfs4_sops; |
1270 | 772 | nfs_initialise_sb(sb); | |
1271 | if (strcmp(server->hostname, old->hostname) != 0) | ||
1272 | return 0; | ||
1273 | if (strcmp(server->mnt_path, old->mnt_path) != 0) | ||
1274 | return 0; | ||
1275 | return 1; | ||
1276 | } | 773 | } |
1277 | 774 | ||
1278 | static void * | 775 | static void *nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen) |
1279 | nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen) | ||
1280 | { | 776 | { |
1281 | void *p = NULL; | 777 | void *p = NULL; |
1282 | 778 | ||
@@ -1297,14 +793,22 @@ nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen) | |||
1297 | return dst; | 793 | return dst; |
1298 | } | 794 | } |
1299 | 795 | ||
796 | /* | ||
797 | * Get the superblock for an NFS4 mountpoint | ||
798 | */ | ||
1300 | static int nfs4_get_sb(struct file_system_type *fs_type, | 799 | static int nfs4_get_sb(struct file_system_type *fs_type, |
1301 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) | 800 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
1302 | { | 801 | { |
1303 | int error; | ||
1304 | struct nfs_server *server; | ||
1305 | struct super_block *s; | ||
1306 | struct nfs4_mount_data *data = raw_data; | 802 | struct nfs4_mount_data *data = raw_data; |
803 | struct super_block *s; | ||
804 | struct nfs_server *server; | ||
805 | struct sockaddr_in addr; | ||
806 | rpc_authflavor_t authflavour; | ||
807 | struct nfs_fh mntfh; | ||
808 | struct dentry *mntroot; | ||
809 | char *mntpath = NULL, *hostname = NULL, ip_addr[16]; | ||
1307 | void *p; | 810 | void *p; |
811 | int error; | ||
1308 | 812 | ||
1309 | if (data == NULL) { | 813 | if (data == NULL) { |
1310 | dprintk("%s: missing data argument\n", __FUNCTION__); | 814 | dprintk("%s: missing data argument\n", __FUNCTION__); |
@@ -1315,84 +819,112 @@ static int nfs4_get_sb(struct file_system_type *fs_type, | |||
1315 | return -EINVAL; | 819 | return -EINVAL; |
1316 | } | 820 | } |
1317 | 821 | ||
1318 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); | 822 | /* We now require that the mount process passes the remote address */ |
1319 | if (!server) | 823 | if (data->host_addrlen != sizeof(addr)) |
1320 | return -ENOMEM; | 824 | return -EINVAL; |
1321 | /* Zero out the NFS state stuff */ | 825 | |
1322 | init_nfsv4_state(server); | 826 | if (copy_from_user(&addr, data->host_addr, sizeof(addr))) |
1323 | server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL); | 827 | return -EFAULT; |
828 | |||
829 | if (addr.sin_family != AF_INET || | ||
830 | addr.sin_addr.s_addr == INADDR_ANY | ||
831 | ) { | ||
832 | dprintk("%s: mount program didn't pass remote IP address!\n", | ||
833 | __FUNCTION__); | ||
834 | return -EINVAL; | ||
835 | } | ||
836 | /* RFC3530: The default port for NFS is 2049 */ | ||
837 | if (addr.sin_port == 0) | ||
838 | addr.sin_port = NFS_PORT; | ||
839 | |||
840 | /* Grab the authentication type */ | ||
841 | authflavour = RPC_AUTH_UNIX; | ||
842 | if (data->auth_flavourlen != 0) { | ||
843 | if (data->auth_flavourlen != 1) { | ||
844 | dprintk("%s: Invalid number of RPC auth flavours %d.\n", | ||
845 | __FUNCTION__, data->auth_flavourlen); | ||
846 | error = -EINVAL; | ||
847 | goto out_err_noserver; | ||
848 | } | ||
849 | |||
850 | if (copy_from_user(&authflavour, data->auth_flavours, | ||
851 | sizeof(authflavour))) { | ||
852 | error = -EFAULT; | ||
853 | goto out_err_noserver; | ||
854 | } | ||
855 | } | ||
1324 | 856 | ||
1325 | p = nfs_copy_user_string(NULL, &data->hostname, 256); | 857 | p = nfs_copy_user_string(NULL, &data->hostname, 256); |
1326 | if (IS_ERR(p)) | 858 | if (IS_ERR(p)) |
1327 | goto out_err; | 859 | goto out_err; |
1328 | server->hostname = p; | 860 | hostname = p; |
1329 | 861 | ||
1330 | p = nfs_copy_user_string(NULL, &data->mnt_path, 1024); | 862 | p = nfs_copy_user_string(NULL, &data->mnt_path, 1024); |
1331 | if (IS_ERR(p)) | 863 | if (IS_ERR(p)) |
1332 | goto out_err; | 864 | goto out_err; |
1333 | server->mnt_path = p; | 865 | mntpath = p; |
866 | |||
867 | dprintk("MNTPATH: %s\n", mntpath); | ||
1334 | 868 | ||
1335 | p = nfs_copy_user_string(server->ip_addr, &data->client_addr, | 869 | p = nfs_copy_user_string(ip_addr, &data->client_addr, |
1336 | sizeof(server->ip_addr) - 1); | 870 | sizeof(ip_addr) - 1); |
1337 | if (IS_ERR(p)) | 871 | if (IS_ERR(p)) |
1338 | goto out_err; | 872 | goto out_err; |
1339 | 873 | ||
1340 | /* We now require that the mount process passes the remote address */ | 874 | /* Get a volume representation */ |
1341 | if (data->host_addrlen != sizeof(server->addr)) { | 875 | server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr, |
1342 | error = -EINVAL; | 876 | authflavour, &mntfh); |
1343 | goto out_free; | 877 | if (IS_ERR(server)) { |
1344 | } | 878 | error = PTR_ERR(server); |
1345 | if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) { | 879 | goto out_err_noserver; |
1346 | error = -EFAULT; | ||
1347 | goto out_free; | ||
1348 | } | ||
1349 | if (server->addr.sin_family != AF_INET || | ||
1350 | server->addr.sin_addr.s_addr == INADDR_ANY) { | ||
1351 | dprintk("%s: mount program didn't pass remote IP address!\n", | ||
1352 | __FUNCTION__); | ||
1353 | error = -EINVAL; | ||
1354 | goto out_free; | ||
1355 | } | ||
1356 | |||
1357 | /* Fire up rpciod if not yet running */ | ||
1358 | error = rpciod_up(); | ||
1359 | if (error < 0) { | ||
1360 | dprintk("%s: couldn't start rpciod! Error = %d\n", | ||
1361 | __FUNCTION__, error); | ||
1362 | goto out_free; | ||
1363 | } | 880 | } |
1364 | 881 | ||
1365 | s = sget(fs_type, nfs4_compare_super, nfs_set_super, server); | 882 | /* Get a superblock - note that we may end up sharing one that already exists */ |
1366 | 883 | s = sget(fs_type, nfs_compare_super, nfs_set_super, server); | |
1367 | if (IS_ERR(s)) { | 884 | if (IS_ERR(s)) { |
1368 | error = PTR_ERR(s); | 885 | error = PTR_ERR(s); |
1369 | goto out_free; | 886 | goto out_free; |
1370 | } | 887 | } |
1371 | 888 | ||
1372 | if (s->s_root) { | 889 | if (s->s_fs_info != server) { |
1373 | kfree(server->mnt_path); | 890 | nfs_free_server(server); |
1374 | kfree(server->hostname); | 891 | server = NULL; |
1375 | kfree(server); | ||
1376 | return simple_set_mnt(mnt, s); | ||
1377 | } | 892 | } |
1378 | 893 | ||
1379 | s->s_flags = flags; | 894 | if (!s->s_root) { |
895 | /* initial superblock/root creation */ | ||
896 | s->s_flags = flags; | ||
897 | nfs4_fill_super(s); | ||
898 | } | ||
1380 | 899 | ||
1381 | error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0); | 900 | mntroot = nfs4_get_root(s, &mntfh); |
1382 | if (error) { | 901 | if (IS_ERR(mntroot)) { |
1383 | up_write(&s->s_umount); | 902 | error = PTR_ERR(mntroot); |
1384 | deactivate_super(s); | 903 | goto error_splat_super; |
1385 | return error; | ||
1386 | } | 904 | } |
905 | |||
1387 | s->s_flags |= MS_ACTIVE; | 906 | s->s_flags |= MS_ACTIVE; |
1388 | return simple_set_mnt(mnt, s); | 907 | mnt->mnt_sb = s; |
908 | mnt->mnt_root = mntroot; | ||
909 | kfree(mntpath); | ||
910 | kfree(hostname); | ||
911 | return 0; | ||
912 | |||
1389 | out_err: | 913 | out_err: |
1390 | error = PTR_ERR(p); | 914 | error = PTR_ERR(p); |
915 | goto out_err_noserver; | ||
916 | |||
1391 | out_free: | 917 | out_free: |
1392 | kfree(server->mnt_path); | 918 | nfs_free_server(server); |
1393 | kfree(server->hostname); | 919 | out_err_noserver: |
1394 | kfree(server); | 920 | kfree(mntpath); |
921 | kfree(hostname); | ||
1395 | return error; | 922 | return error; |
923 | |||
924 | error_splat_super: | ||
925 | up_write(&s->s_umount); | ||
926 | deactivate_super(s); | ||
927 | goto out_err_noserver; | ||
1396 | } | 928 | } |
1397 | 929 | ||
1398 | static void nfs4_kill_super(struct super_block *sb) | 930 | static void nfs4_kill_super(struct super_block *sb) |
@@ -1403,135 +935,140 @@ static void nfs4_kill_super(struct super_block *sb) | |||
1403 | kill_anon_super(sb); | 935 | kill_anon_super(sb); |
1404 | 936 | ||
1405 | nfs4_renewd_prepare_shutdown(server); | 937 | nfs4_renewd_prepare_shutdown(server); |
938 | nfs_free_server(server); | ||
939 | } | ||
940 | |||
941 | /* | ||
942 | * Clone an NFS4 server record on xdev traversal (FSID-change) | ||
943 | */ | ||
944 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, | ||
945 | const char *dev_name, void *raw_data, | ||
946 | struct vfsmount *mnt) | ||
947 | { | ||
948 | struct nfs_clone_mount *data = raw_data; | ||
949 | struct super_block *s; | ||
950 | struct nfs_server *server; | ||
951 | struct dentry *mntroot; | ||
952 | int error; | ||
953 | |||
954 | dprintk("--> nfs4_xdev_get_sb()\n"); | ||
955 | |||
956 | /* create a new volume representation */ | ||
957 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); | ||
958 | if (IS_ERR(server)) { | ||
959 | error = PTR_ERR(server); | ||
960 | goto out_err_noserver; | ||
961 | } | ||
962 | |||
963 | /* Get a superblock - note that we may end up sharing one that already exists */ | ||
964 | s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); | ||
965 | if (IS_ERR(s)) { | ||
966 | error = PTR_ERR(s); | ||
967 | goto out_err_nosb; | ||
968 | } | ||
1406 | 969 | ||
1407 | if (server->client != NULL && !IS_ERR(server->client)) | 970 | if (s->s_fs_info != server) { |
1408 | rpc_shutdown_client(server->client); | 971 | nfs_free_server(server); |
972 | server = NULL; | ||
973 | } | ||
1409 | 974 | ||
1410 | destroy_nfsv4_state(server); | 975 | if (!s->s_root) { |
976 | /* initial superblock/root creation */ | ||
977 | s->s_flags = flags; | ||
978 | nfs4_clone_super(s, data->sb); | ||
979 | } | ||
980 | |||
981 | mntroot = nfs4_get_root(s, data->fh); | ||
982 | if (IS_ERR(mntroot)) { | ||
983 | error = PTR_ERR(mntroot); | ||
984 | goto error_splat_super; | ||
985 | } | ||
1411 | 986 | ||
1412 | rpciod_down(); | 987 | s->s_flags |= MS_ACTIVE; |
988 | mnt->mnt_sb = s; | ||
989 | mnt->mnt_root = mntroot; | ||
990 | |||
991 | dprintk("<-- nfs4_xdev_get_sb() = 0\n"); | ||
992 | return 0; | ||
993 | |||
994 | out_err_nosb: | ||
995 | nfs_free_server(server); | ||
996 | out_err_noserver: | ||
997 | dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); | ||
998 | return error; | ||
1413 | 999 | ||
1414 | nfs_free_iostats(server->io_stats); | 1000 | error_splat_super: |
1415 | kfree(server->hostname); | 1001 | up_write(&s->s_umount); |
1416 | kfree(server); | 1002 | deactivate_super(s); |
1417 | nfs_release_automount_timer(); | 1003 | dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); |
1004 | return error; | ||
1418 | } | 1005 | } |
1419 | 1006 | ||
1420 | /* | 1007 | /* |
1421 | * Constructs the SERVER-side path | 1008 | * Create an NFS4 server record on referral traversal |
1422 | */ | 1009 | */ |
1423 | static inline char *nfs4_dup_path(const struct dentry *dentry) | 1010 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags, |
1011 | const char *dev_name, void *raw_data, | ||
1012 | struct vfsmount *mnt) | ||
1424 | { | 1013 | { |
1425 | char *page = (char *) __get_free_page(GFP_USER); | 1014 | struct nfs_clone_mount *data = raw_data; |
1426 | char *path; | 1015 | struct super_block *s; |
1016 | struct nfs_server *server; | ||
1017 | struct dentry *mntroot; | ||
1018 | struct nfs_fh mntfh; | ||
1019 | int error; | ||
1427 | 1020 | ||
1428 | path = nfs4_path(dentry, page, PAGE_SIZE); | 1021 | dprintk("--> nfs4_referral_get_sb()\n"); |
1429 | if (!IS_ERR(path)) { | ||
1430 | int len = PAGE_SIZE + page - path; | ||
1431 | char *tmp = path; | ||
1432 | 1022 | ||
1433 | path = kmalloc(len, GFP_KERNEL); | 1023 | /* create a new volume representation */ |
1434 | if (path) | 1024 | server = nfs4_create_referral_server(data, &mntfh); |
1435 | memcpy(path, tmp, len); | 1025 | if (IS_ERR(server)) { |
1436 | else | 1026 | error = PTR_ERR(server); |
1437 | path = ERR_PTR(-ENOMEM); | 1027 | goto out_err_noserver; |
1438 | } | 1028 | } |
1439 | free_page((unsigned long)page); | ||
1440 | return path; | ||
1441 | } | ||
1442 | 1029 | ||
1443 | static struct super_block *nfs4_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data) | 1030 | /* Get a superblock - note that we may end up sharing one that already exists */ |
1444 | { | 1031 | s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); |
1445 | const struct dentry *dentry = data->dentry; | 1032 | if (IS_ERR(s)) { |
1446 | struct nfs4_client *clp = server->nfs4_state; | 1033 | error = PTR_ERR(s); |
1447 | struct super_block *sb; | 1034 | goto out_err_nosb; |
1448 | |||
1449 | server->fsid = data->fattr->fsid; | ||
1450 | nfs_copy_fh(&server->fh, data->fh); | ||
1451 | server->mnt_path = nfs4_dup_path(dentry); | ||
1452 | if (IS_ERR(server->mnt_path)) { | ||
1453 | sb = (struct super_block *)server->mnt_path; | ||
1454 | goto err; | ||
1455 | } | 1035 | } |
1456 | sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server); | ||
1457 | if (IS_ERR(sb) || sb->s_root) | ||
1458 | goto free_path; | ||
1459 | nfs4_server_capabilities(server, &server->fh); | ||
1460 | |||
1461 | down_write(&clp->cl_sem); | ||
1462 | atomic_inc(&clp->cl_count); | ||
1463 | list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); | ||
1464 | up_write(&clp->cl_sem); | ||
1465 | return sb; | ||
1466 | free_path: | ||
1467 | kfree(server->mnt_path); | ||
1468 | err: | ||
1469 | server->mnt_path = NULL; | ||
1470 | return sb; | ||
1471 | } | ||
1472 | 1036 | ||
1473 | static int nfs_clone_nfs4_sb(struct file_system_type *fs_type, | 1037 | if (s->s_fs_info != server) { |
1474 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) | 1038 | nfs_free_server(server); |
1475 | { | 1039 | server = NULL; |
1476 | struct nfs_clone_mount *data = raw_data; | 1040 | } |
1477 | return nfs_clone_generic_sb(data, nfs4_clone_sb, nfs_clone_server, mnt); | ||
1478 | } | ||
1479 | 1041 | ||
1480 | static struct super_block *nfs4_referral_sb(struct nfs_server *server, struct nfs_clone_mount *data) | 1042 | if (!s->s_root) { |
1481 | { | 1043 | /* initial superblock/root creation */ |
1482 | struct super_block *sb = ERR_PTR(-ENOMEM); | 1044 | s->s_flags = flags; |
1483 | int len; | 1045 | nfs4_fill_super(s); |
1484 | 1046 | } | |
1485 | len = strlen(data->mnt_path) + 1; | ||
1486 | server->mnt_path = kmalloc(len, GFP_KERNEL); | ||
1487 | if (server->mnt_path == NULL) | ||
1488 | goto err; | ||
1489 | memcpy(server->mnt_path, data->mnt_path, len); | ||
1490 | memcpy(&server->addr, data->addr, sizeof(struct sockaddr_in)); | ||
1491 | |||
1492 | sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server); | ||
1493 | if (IS_ERR(sb) || sb->s_root) | ||
1494 | goto free_path; | ||
1495 | return sb; | ||
1496 | free_path: | ||
1497 | kfree(server->mnt_path); | ||
1498 | err: | ||
1499 | server->mnt_path = NULL; | ||
1500 | return sb; | ||
1501 | } | ||
1502 | 1047 | ||
1503 | static struct nfs_server *nfs4_referral_server(struct super_block *sb, struct nfs_clone_mount *data) | 1048 | mntroot = nfs4_get_root(s, data->fh); |
1504 | { | 1049 | if (IS_ERR(mntroot)) { |
1505 | struct nfs_server *server = NFS_SB(sb); | 1050 | error = PTR_ERR(mntroot); |
1506 | struct rpc_timeout timeparms; | 1051 | goto error_splat_super; |
1507 | int proto, timeo, retrans; | 1052 | } |
1508 | void *err; | ||
1509 | |||
1510 | proto = IPPROTO_TCP; | ||
1511 | /* Since we are following a referral and there may be alternatives, | ||
1512 | set the timeouts and retries to low values */ | ||
1513 | timeo = 2; | ||
1514 | retrans = 1; | ||
1515 | nfs_init_timeout_values(&timeparms, proto, timeo, retrans); | ||
1516 | |||
1517 | server->client = nfs4_create_client(server, &timeparms, proto, data->authflavor); | ||
1518 | if (IS_ERR((err = server->client))) | ||
1519 | goto out_err; | ||
1520 | 1053 | ||
1521 | sb->s_time_gran = 1; | 1054 | s->s_flags |= MS_ACTIVE; |
1522 | sb->s_op = &nfs4_sops; | 1055 | mnt->mnt_sb = s; |
1523 | err = ERR_PTR(nfs_sb_init(sb, data->authflavor)); | 1056 | mnt->mnt_root = mntroot; |
1524 | if (!IS_ERR(err)) | ||
1525 | return server; | ||
1526 | out_err: | ||
1527 | return (struct nfs_server *)err; | ||
1528 | } | ||
1529 | 1057 | ||
1530 | static int nfs_referral_nfs4_sb(struct file_system_type *fs_type, | 1058 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
1531 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) | 1059 | return 0; |
1532 | { | 1060 | |
1533 | struct nfs_clone_mount *data = raw_data; | 1061 | out_err_nosb: |
1534 | return nfs_clone_generic_sb(data, nfs4_referral_sb, nfs4_referral_server, mnt); | 1062 | nfs_free_server(server); |
1063 | out_err_noserver: | ||
1064 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); | ||
1065 | return error; | ||
1066 | |||
1067 | error_splat_super: | ||
1068 | up_write(&s->s_umount); | ||
1069 | deactivate_super(s); | ||
1070 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); | ||
1071 | return error; | ||
1535 | } | 1072 | } |
1536 | 1073 | ||
1537 | #endif | 1074 | #endif /* CONFIG_NFS_V4 */ |