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