4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
18 #include <linux/config.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
22 #include <linux/time.h>
23 #include <linux/kernel.h>
25 #include <linux/string.h>
26 #include <linux/stat.h>
27 #include <linux/errno.h>
28 #include <linux/unistd.h>
29 #include <linux/sunrpc/clnt.h>
30 #include <linux/sunrpc/stats.h>
31 #include <linux/sunrpc/metrics.h>
32 #include <linux/nfs_fs.h>
33 #include <linux/nfs_mount.h>
34 #include <linux/nfs4_mount.h>
35 #include <linux/lockd/bind.h>
36 #include <linux/smp_lock.h>
37 #include <linux/seq_file.h>
38 #include <linux/mount.h>
39 #include <linux/nfs_idmap.h>
40 #include <linux/vfs.h>
41 #include <linux/inet.h>
42 #include <linux/nfs_xdr.h>
44 #include <asm/system.h>
45 #include <asm/uaccess.h>
49 #include "delegation.h"
53 #define NFSDBG_FACILITY NFSDBG_VFS
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.
61 #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
66 static struct rpc_version
* nfs_version
[] = {
70 #if defined(CONFIG_NFS_V3)
72 #elif defined(CONFIG_NFS_V4)
75 #if defined(CONFIG_NFS_V4)
80 static struct rpc_program nfs_program
= {
82 .number
= NFS_PROGRAM
,
83 .nrvers
= ARRAY_SIZE(nfs_version
),
84 .version
= nfs_version
,
85 .stats
= &nfs_rpcstat
,
86 .pipe_dir_name
= "/nfs",
89 struct rpc_stat nfs_rpcstat
= {
90 .program
= &nfs_program
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
,
100 struct rpc_program nfsacl_program
= {
102 .number
= NFS_ACL_PROGRAM
,
103 .nrvers
= ARRAY_SIZE(nfsacl_version
),
104 .version
= nfsacl_version
,
105 .stats
= &nfsacl_rpcstat
,
107 #endif /* CONFIG_NFS_V3_ACL */
109 static void nfs_umount_begin(struct vfsmount
*, int);
110 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
111 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
112 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
*);
114 static int nfs_clone_nfs_sb(struct file_system_type
*fs_type
,
115 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
116 static void nfs_kill_super(struct super_block
*);
118 static struct file_system_type nfs_fs_type
= {
119 .owner
= THIS_MODULE
,
121 .get_sb
= nfs_get_sb
,
122 .kill_sb
= nfs_kill_super
,
123 .fs_flags
= FS_ODD_RENAME
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
126 struct file_system_type clone_nfs_fs_type
= {
127 .owner
= THIS_MODULE
,
129 .get_sb
= nfs_clone_nfs_sb
,
130 .kill_sb
= nfs_kill_super
,
131 .fs_flags
= FS_ODD_RENAME
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
134 static struct super_operations nfs_sops
= {
135 .alloc_inode
= nfs_alloc_inode
,
136 .destroy_inode
= nfs_destroy_inode
,
137 .write_inode
= nfs_write_inode
,
138 .statfs
= nfs_statfs
,
139 .clear_inode
= nfs_clear_inode
,
140 .umount_begin
= nfs_umount_begin
,
141 .show_options
= nfs_show_options
,
142 .show_stats
= nfs_show_stats
,
146 static int nfs4_get_sb(struct file_system_type
*fs_type
,
147 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
,
149 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
,
151 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
152 static void nfs4_kill_super(struct super_block
*sb
);
154 static struct file_system_type nfs4_fs_type
= {
155 .owner
= THIS_MODULE
,
157 .get_sb
= nfs4_get_sb
,
158 .kill_sb
= nfs4_kill_super
,
159 .fs_flags
= FS_ODD_RENAME
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
162 struct file_system_type clone_nfs4_fs_type
= {
163 .owner
= THIS_MODULE
,
165 .get_sb
= nfs_clone_nfs4_sb
,
166 .kill_sb
= nfs4_kill_super
,
167 .fs_flags
= FS_ODD_RENAME
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
170 struct file_system_type nfs_referral_nfs4_fs_type
= {
171 .owner
= THIS_MODULE
,
173 .get_sb
= nfs_referral_nfs4_sb
,
174 .kill_sb
= nfs4_kill_super
,
175 .fs_flags
= FS_ODD_RENAME
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
178 static struct super_operations nfs4_sops
= {
179 .alloc_inode
= nfs_alloc_inode
,
180 .destroy_inode
= nfs_destroy_inode
,
181 .write_inode
= nfs_write_inode
,
182 .statfs
= nfs_statfs
,
183 .clear_inode
= nfs4_clear_inode
,
184 .umount_begin
= nfs_umount_begin
,
185 .show_options
= nfs_show_options
,
186 .show_stats
= nfs_show_stats
,
191 static const int nfs_set_port_min
= 0;
192 static const int nfs_set_port_max
= 65535;
194 static int param_set_port(const char *val
, struct kernel_param
*kp
)
197 int num
= simple_strtol(val
, &endp
, 0);
198 if (endp
== val
|| *endp
|| num
< nfs_set_port_min
|| num
> nfs_set_port_max
)
200 *((int *)kp
->arg
) = num
;
204 module_param_call(callback_tcpport
, param_set_port
, param_get_int
,
205 &nfs_callback_set_tcpport
, 0644);
209 static int param_set_idmap_timeout(const char *val
, struct kernel_param
*kp
)
212 int num
= simple_strtol(val
, &endp
, 0);
214 if (endp
== val
|| *endp
|| num
< 0 || jif
< num
)
216 *((int *)kp
->arg
) = jif
;
220 module_param_call(idmap_cache_timeout
, param_set_idmap_timeout
, param_get_int
,
221 &nfs_idmap_cache_timeout
, 0644);
225 * Register the NFS filesystems
227 int __init
register_nfs_fs(void)
231 ret
= register_filesystem(&nfs_fs_type
);
236 ret
= nfs_register_sysctl();
239 ret
= register_filesystem(&nfs4_fs_type
);
247 nfs_unregister_sysctl();
249 unregister_filesystem(&nfs_fs_type
);
256 * Unregister the NFS filesystems
258 void __exit
unregister_nfs_fs(void)
261 unregister_filesystem(&nfs4_fs_type
);
262 nfs_unregister_sysctl();
264 unregister_filesystem(&nfs_fs_type
);
268 * Deliver file system statistics to userspace
270 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
272 struct super_block
*sb
= dentry
->d_sb
;
273 struct nfs_server
*server
= NFS_SB(sb
);
274 unsigned char blockbits
;
275 unsigned long blockres
;
276 struct nfs_fh
*rootfh
= NFS_FH(sb
->s_root
->d_inode
);
277 struct nfs_fattr fattr
;
278 struct nfs_fsstat res
= {
285 error
= server
->rpc_ops
->statfs(server
, rootfh
, &res
);
286 buf
->f_type
= NFS_SUPER_MAGIC
;
291 * Current versions of glibc do not correctly handle the
292 * case where f_frsize != f_bsize. Eventually we want to
293 * report the value of wtmult in this field.
295 buf
->f_frsize
= sb
->s_blocksize
;
298 * On most *nix systems, f_blocks, f_bfree, and f_bavail
299 * are reported in units of f_frsize. Linux hasn't had
300 * an f_frsize field in its statfs struct until recently,
301 * thus historically Linux's sys_statfs reports these
302 * fields in units of f_bsize.
304 buf
->f_bsize
= sb
->s_blocksize
;
305 blockbits
= sb
->s_blocksize_bits
;
306 blockres
= (1 << blockbits
) - 1;
307 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
308 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
309 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
311 buf
->f_files
= res
.tfiles
;
312 buf
->f_ffree
= res
.afiles
;
314 buf
->f_namelen
= server
->namelen
;
320 dprintk("%s: statfs error = %d\n", __FUNCTION__
, -error
);
321 buf
->f_bsize
= buf
->f_blocks
= buf
->f_bfree
= buf
->f_bavail
= -1;
326 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
329 rpc_authflavor_t flavour
;
332 { RPC_AUTH_NULL
, "null" },
333 { RPC_AUTH_UNIX
, "sys" },
334 { RPC_AUTH_GSS_KRB5
, "krb5" },
335 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
336 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
337 { RPC_AUTH_GSS_LKEY
, "lkey" },
338 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
339 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
340 { RPC_AUTH_GSS_SPKM
, "spkm" },
341 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
342 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
347 for (i
=0; sec_flavours
[i
].flavour
!= -1; i
++) {
348 if (sec_flavours
[i
].flavour
== flavour
)
351 return sec_flavours
[i
].str
;
355 * Describe the mount options in force on this server representation
357 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
, int showdefaults
)
359 static struct proc_nfs_info
{
364 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
365 { NFS_MOUNT_INTR
, ",intr", "" },
366 { NFS_MOUNT_NOCTO
, ",nocto", "" },
367 { NFS_MOUNT_NOAC
, ",noac", "" },
368 { NFS_MOUNT_NONLM
, ",nolock", "" },
369 { NFS_MOUNT_NOACL
, ",noacl", "" },
372 struct proc_nfs_info
*nfs_infop
;
376 seq_printf(m
, ",vers=%d", nfss
->rpc_ops
->version
);
377 seq_printf(m
, ",rsize=%d", nfss
->rsize
);
378 seq_printf(m
, ",wsize=%d", nfss
->wsize
);
379 if (nfss
->acregmin
!= 3*HZ
|| showdefaults
)
380 seq_printf(m
, ",acregmin=%d", nfss
->acregmin
/HZ
);
381 if (nfss
->acregmax
!= 60*HZ
|| showdefaults
)
382 seq_printf(m
, ",acregmax=%d", nfss
->acregmax
/HZ
);
383 if (nfss
->acdirmin
!= 30*HZ
|| showdefaults
)
384 seq_printf(m
, ",acdirmin=%d", nfss
->acdirmin
/HZ
);
385 if (nfss
->acdirmax
!= 60*HZ
|| showdefaults
)
386 seq_printf(m
, ",acdirmax=%d", nfss
->acdirmax
/HZ
);
387 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
388 if (nfss
->flags
& nfs_infop
->flag
)
389 seq_puts(m
, nfs_infop
->str
);
391 seq_puts(m
, nfs_infop
->nostr
);
393 switch (nfss
->client
->cl_xprt
->prot
) {
401 snprintf(buf
, sizeof(buf
), "%u", nfss
->client
->cl_xprt
->prot
);
404 seq_printf(m
, ",proto=%s", proto
);
405 seq_printf(m
, ",timeo=%lu", 10U * nfss
->retrans_timeo
/ HZ
);
406 seq_printf(m
, ",retrans=%u", nfss
->retrans_count
);
407 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
411 * Describe the mount options on this VFS mountpoint
413 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
415 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
417 nfs_show_mount_options(m
, nfss
, 0);
419 seq_puts(m
, ",addr=");
420 seq_escape(m
, nfss
->hostname
, " \t\n\\");
426 * Present statistical information for this VFS mountpoint
428 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
431 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
432 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
433 struct nfs_iostats totals
= { };
435 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
438 * Display all mount option settings
440 seq_printf(m
, "\n\topts:\t");
441 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
442 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
443 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
444 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
445 nfs_show_mount_options(m
, nfss
, 1);
447 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
449 seq_printf(m
, "\n\tcaps:\t");
450 seq_printf(m
, "caps=0x%x", nfss
->caps
);
451 seq_printf(m
, ",wtmult=%d", nfss
->wtmult
);
452 seq_printf(m
, ",dtsize=%d", nfss
->dtsize
);
453 seq_printf(m
, ",bsize=%d", nfss
->bsize
);
454 seq_printf(m
, ",namelen=%d", nfss
->namelen
);
457 if (nfss
->rpc_ops
->version
== 4) {
458 seq_printf(m
, "\n\tnfsv4:\t");
459 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
460 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
461 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
466 * Display security flavor in effect for this mount
468 seq_printf(m
, "\n\tsec:\tflavor=%d", auth
->au_ops
->au_flavor
);
470 seq_printf(m
, ",pseudoflavor=%d", auth
->au_flavor
);
473 * Display superblock I/O counters
475 for_each_possible_cpu(cpu
) {
476 struct nfs_iostats
*stats
;
479 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
481 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
482 totals
.events
[i
] += stats
->events
[i
];
483 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
484 totals
.bytes
[i
] += stats
->bytes
[i
];
489 seq_printf(m
, "\n\tevents:\t");
490 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
491 seq_printf(m
, "%lu ", totals
.events
[i
]);
492 seq_printf(m
, "\n\tbytes:\t");
493 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
494 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
497 rpc_print_iostats(m
, nfss
->client
);
503 * Begin unmount by attempting to remove all automounted mountpoints we added
504 * in response to traversals
506 static void nfs_umount_begin(struct vfsmount
*vfsmnt
, int flags
)
508 struct nfs_server
*server
;
509 struct rpc_clnt
*rpc
;
511 shrink_submounts(vfsmnt
, &nfs_automount_list
);
512 if (!(flags
& MNT_FORCE
))
514 /* -EIO all pending I/O */
515 server
= NFS_SB(vfsmnt
->mnt_sb
);
516 rpc
= server
->client
;
518 rpc_killall_tasks(rpc
);
519 rpc
= server
->client_acl
;
521 rpc_killall_tasks(rpc
);
525 * Obtain the root inode of the file system.
527 static struct inode
*
528 nfs_get_root(struct super_block
*sb
, struct nfs_fh
*rootfh
, struct nfs_fsinfo
*fsinfo
)
530 struct nfs_server
*server
= NFS_SB(sb
);
533 error
= server
->rpc_ops
->getroot(server
, rootfh
, fsinfo
);
535 dprintk("nfs_get_root: getattr error = %d\n", -error
);
536 return ERR_PTR(error
);
539 server
->fsid
= fsinfo
->fattr
->fsid
;
540 return nfs_fhget(sb
, rootfh
, fsinfo
->fattr
);
544 * Do NFS version-independent mount processing, and sanity checking
547 nfs_sb_init(struct super_block
*sb
, rpc_authflavor_t authflavor
)
549 struct nfs_server
*server
;
550 struct inode
*root_inode
;
551 struct nfs_fattr fattr
;
552 struct nfs_fsinfo fsinfo
= {
555 struct nfs_pathconf pathinfo
= {
558 int no_root_error
= 0;
559 unsigned long max_rpc_payload
;
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
));
566 sb
->s_magic
= NFS_SUPER_MAGIC
;
568 server
->io_stats
= nfs_alloc_iostats();
569 if (server
->io_stats
== NULL
)
572 root_inode
= nfs_get_root(sb
, &server
->fh
, &fsinfo
);
573 /* Did getting the root inode fail? */
574 if (IS_ERR(root_inode
)) {
575 no_root_error
= PTR_ERR(root_inode
);
578 sb
->s_root
= d_alloc_root(root_inode
);
580 no_root_error
= -ENOMEM
;
583 sb
->s_root
->d_op
= server
->rpc_ops
->dentry_ops
;
585 /* mount time stamp, in seconds */
586 server
->mount_time
= jiffies
;
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
);
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
);
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
;
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
;
616 if (sb
->s_blocksize
== 0)
617 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
618 &sb
->s_blocksize_bits
);
619 server
->wtmult
= nfs_block_bits(fsinfo
.wtmult
, NULL
);
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
;
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
;
632 server
->backing_dev_info
.ra_pages
= server
->rpages
* NFS_MAX_READAHEAD
;
634 nfs_super_set_maxbytes(sb
, fsinfo
.maxfilesize
);
636 server
->client
->cl_intr
= (server
->flags
& NFS_MOUNT_INTR
) ? 1 : 0;
637 server
->client
->cl_softrtry
= (server
->flags
& NFS_MOUNT_SOFT
) ? 1 : 0;
639 /* We're airborne Set socket buffersize */
640 rpc_setbufsize(server
->client
, server
->wsize
+ 100, server
->rsize
+ 100);
642 /* Yargs. It didn't work out. */
644 dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error
);
645 if (!IS_ERR(root_inode
))
647 return no_root_error
;
651 * Initialise the timeout values for a connection
653 static void nfs_init_timeout_values(struct rpc_timeout
*to
, int proto
, unsigned int timeo
, unsigned int retrans
)
655 to
->to_initval
= timeo
* HZ
/ 10;
656 to
->to_retries
= retrans
;
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;
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;
683 * Create an RPC client handle.
685 static struct rpc_clnt
*
686 nfs_create_client(struct nfs_server
*server
, const struct nfs_mount_data
*data
)
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
;
693 nfs_init_timeout_values(&timeparms
, proto
, data
->timeo
, data
->retrans
);
695 server
->retrans_timeo
= timeparms
.to_initval
;
696 server
->retrans_count
= timeparms
.to_retries
;
698 /* create transport and client */
699 xprt
= xprt_create_proto(proto
, &server
->addr
, &timeparms
);
701 dprintk("%s: cannot create RPC transport. Error = %ld\n",
702 __FUNCTION__
, PTR_ERR(xprt
));
703 return (struct rpc_clnt
*)xprt
;
705 clnt
= rpc_create_client(xprt
, server
->hostname
, &nfs_program
,
706 server
->rpc_ops
->version
, data
->pseudoflavor
);
708 dprintk("%s: cannot create RPC client. Error = %ld\n",
709 __FUNCTION__
, PTR_ERR(xprt
));
714 clnt
->cl_softrtry
= 1;
723 * Clone a server record
725 static struct nfs_server
*nfs_clone_server(struct super_block
*sb
, struct nfs_clone_mount
*data
)
727 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
);
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
;
738 server
->client_sys
= server
->client_acl
= ERR_PTR(-EINVAL
);
739 server
->io_stats
= nfs_alloc_iostats();
740 if (server
->io_stats
== NULL
)
743 server
->client
= rpc_clone_client(parent
->client
);
744 if (IS_ERR((err
= server
->client
)))
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
)))
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
)))
757 root_inode
= nfs_fhget(sb
, data
->fh
, data
->fattr
);
760 sb
->s_root
= d_alloc_root(root_inode
);
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
;
776 * Copy an existing superblock and attach revised data
778 static int nfs_clone_generic_sb(struct nfs_clone_mount
*data
,
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
)
783 struct nfs_server
*server
;
784 struct nfs_server
*parent
= NFS_SB(data
->sb
);
785 struct super_block
*sb
= ERR_PTR(-EINVAL
);
790 server
= kmalloc(sizeof(struct nfs_server
), GFP_KERNEL
);
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
)
799 memcpy(server
->hostname
, hostname
, len
);
804 sb
= fill_sb(server
, data
);
811 goto out_rpciod_down
;
813 server
= fill_server(sb
, data
);
814 if (IS_ERR(server
)) {
815 error
= PTR_ERR(server
);
818 return simple_set_mnt(mnt
, sb
);
820 up_write(&sb
->s_umount
);
821 deactivate_super(sb
);
825 kfree(server
->hostname
);
827 return simple_set_mnt(mnt
, sb
);
831 kfree(server
->hostname
);
839 * Set up an NFS2/3 superblock
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.
847 nfs_fill_super(struct super_block
*sb
, struct nfs_mount_data
*data
, int silent
)
849 struct nfs_server
*server
;
850 rpc_authflavor_t authflavor
;
853 sb
->s_blocksize_bits
= 0;
856 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
858 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
860 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
861 server
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
863 server
->acregmin
= data
->acregmin
*HZ
;
864 server
->acregmax
= data
->acregmax
*HZ
;
865 server
->acdirmin
= data
->acdirmin
*HZ
;
866 server
->acdirmax
= data
->acdirmax
*HZ
;
868 /* Start lockd here, before we might error out */
869 if (!(server
->flags
& NFS_MOUNT_NONLM
))
872 server
->namelen
= data
->namlen
;
873 server
->hostname
= kmalloc(strlen(data
->hostname
) + 1, GFP_KERNEL
);
874 if (!server
->hostname
)
876 strcpy(server
->hostname
, data
->hostname
);
878 /* Check NFS protocol revision and initialize RPC op vector
879 * and file handle pool. */
881 if (server
->flags
& NFS_MOUNT_VER3
) {
882 server
->rpc_ops
= &nfs_v3_clientops
;
883 server
->caps
|= NFS_CAP_READDIRPLUS
;
885 server
->rpc_ops
= &nfs_v2_clientops
;
888 server
->rpc_ops
= &nfs_v2_clientops
;
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 */
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
;
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
);
910 return PTR_ERR(auth
);
912 atomic_inc(&server
->client
->cl_count
);
913 server
->client_sys
= server
->client
;
915 if (server
->flags
& NFS_MOUNT_VER3
) {
916 #ifdef CONFIG_NFS_V3_ACL
917 if (!(server
->flags
& NFS_MOUNT_NOACL
)) {
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
;
924 server
->flags
&= ~NFS_MOUNT_NOACL
;
925 #endif /* CONFIG_NFS_V3_ACL */
927 * The VFS shouldn't apply the umask to mode bits. We will
928 * do so ourselves when necessary.
930 sb
->s_flags
|= MS_POSIXACL
;
931 if (server
->namelen
== 0 || server
->namelen
> NFS3_MAXNAMLEN
)
932 server
->namelen
= NFS3_MAXNAMLEN
;
935 if (server
->namelen
== 0 || server
->namelen
> NFS2_MAXNAMLEN
)
936 server
->namelen
= NFS2_MAXNAMLEN
;
939 sb
->s_op
= &nfs_sops
;
940 return nfs_sb_init(sb
, authflavor
);
943 static int nfs_set_super(struct super_block
*s
, void *data
)
946 return set_anon_super(s
, data
);
949 static int nfs_compare_super(struct super_block
*sb
, void *data
)
951 struct nfs_server
*server
= data
;
952 struct nfs_server
*old
= NFS_SB(sb
);
954 if (old
->addr
.sin_addr
.s_addr
!= server
->addr
.sin_addr
.s_addr
)
956 if (old
->addr
.sin_port
!= server
->addr
.sin_port
)
958 return !nfs_compare_fh(&old
->fh
, &server
->fh
);
961 static int nfs_get_sb(struct file_system_type
*fs_type
,
962 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
965 struct nfs_server
*server
= NULL
;
966 struct super_block
*s
;
968 struct nfs_mount_data
*data
= raw_data
;
972 dprintk("%s: missing data argument\n", __FUNCTION__
);
973 goto out_err_noserver
;
975 if (data
->version
<= 0 || data
->version
> NFS_MOUNT_VERSION
) {
976 dprintk("%s: bad mount version\n", __FUNCTION__
);
977 goto out_err_noserver
;
979 switch (data
->version
) {
985 if (data
->flags
& NFS_MOUNT_VER3
) {
986 dprintk("%s: mount structure version %d does not support NFSv3\n",
989 goto out_err_noserver
;
991 data
->root
.size
= NFS2_FHSIZE
;
992 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
994 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
) {
995 dprintk("%s: mount structure version %d does not support strong security\n",
998 goto out_err_noserver
;
1001 memset(data
->context
, 0, sizeof(data
->context
));
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
;
1010 #endif /* CONFIG_NFS_V3 */
1013 server
= kzalloc(sizeof(struct nfs_server
), GFP_KERNEL
);
1015 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
);
1021 if (data
->flags
& NFS_MOUNT_VER3
)
1022 root
->size
= data
->root
.size
;
1024 root
->size
= NFS2_FHSIZE
;
1026 if (root
->size
> sizeof(root
->data
)) {
1027 dprintk("%s: invalid root filehandle\n", __FUNCTION__
);
1030 memcpy(root
->data
, data
->root
.data
, root
->size
);
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",
1040 /* Fire up rpciod if not yet running */
1041 error
= rpciod_up();
1043 dprintk("%s: couldn't start rpciod! Error = %d\n",
1044 __FUNCTION__
, error
);
1048 s
= sget(fs_type
, nfs_compare_super
, nfs_set_super
, server
);
1051 goto out_err_rpciod
;
1055 goto out_rpciod_down
;
1059 error
= nfs_fill_super(s
, data
, flags
& MS_SILENT
? 1 : 0);
1061 up_write(&s
->s_umount
);
1062 deactivate_super(s
);
1065 s
->s_flags
|= MS_ACTIVE
;
1066 return simple_set_mnt(mnt
, s
);
1071 return simple_set_mnt(mnt
, s
);
1081 static void nfs_kill_super(struct super_block
*s
)
1083 struct nfs_server
*server
= NFS_SB(s
);
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
);
1094 if (!(server
->flags
& NFS_MOUNT_NONLM
))
1095 lockd_down(); /* release rpc.lockd */
1097 rpciod_down(); /* release rpciod */
1099 nfs_free_iostats(server
->io_stats
);
1100 kfree(server
->hostname
);
1102 nfs_release_automount_timer();
1105 static struct super_block
*nfs_clone_sb(struct nfs_server
*server
, struct nfs_clone_mount
*data
)
1107 struct super_block
*sb
;
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
))
1117 static int nfs_clone_nfs_sb(struct file_system_type
*fs_type
,
1118 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1120 struct nfs_clone_mount
*data
= raw_data
;
1121 return nfs_clone_generic_sb(data
, nfs_clone_sb
, nfs_clone_server
, mnt
);
1124 #ifdef CONFIG_NFS_V4
1125 static struct rpc_clnt
*nfs4_create_client(struct nfs_server
*server
,
1126 struct rpc_timeout
*timeparms
, int proto
, rpc_authflavor_t flavor
)
1128 struct nfs4_client
*clp
;
1129 struct rpc_xprt
*xprt
= NULL
;
1130 struct rpc_clnt
*clnt
= NULL
;
1133 clp
= nfs4_get_client(&server
->addr
.sin_addr
);
1135 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__
);
1136 return ERR_PTR(err
);
1139 /* Now create transport and client */
1140 down_write(&clp
->cl_sem
);
1141 if (IS_ERR(clp
->cl_rpcclient
)) {
1142 xprt
= xprt_create_proto(proto
, &server
->addr
, timeparms
);
1144 up_write(&clp
->cl_sem
);
1145 err
= PTR_ERR(xprt
);
1146 dprintk("%s: cannot create RPC transport. Error = %d\n",
1150 /* Bind to a reserved port! */
1152 clnt
= rpc_create_client(xprt
, server
->hostname
, &nfs_program
,
1153 server
->rpc_ops
->version
, flavor
);
1155 up_write(&clp
->cl_sem
);
1156 err
= PTR_ERR(clnt
);
1157 dprintk("%s: cannot create RPC client. Error = %d\n",
1162 clnt
->cl_softrtry
= 1;
1163 clp
->cl_rpcclient
= clnt
;
1164 memcpy(clp
->cl_ipaddr
, server
->ip_addr
, sizeof(clp
->cl_ipaddr
));
1167 list_add_tail(&server
->nfs4_siblings
, &clp
->cl_superblocks
);
1168 clnt
= rpc_clone_client(clp
->cl_rpcclient
);
1170 server
->nfs4_state
= clp
;
1171 up_write(&clp
->cl_sem
);
1175 dprintk("%s: cannot create RPC client. Error = %d\n",
1180 if (server
->nfs4_state
->cl_idmap
== NULL
) {
1181 dprintk("%s: failed to create idmapper.\n", __FUNCTION__
);
1182 return ERR_PTR(-ENOMEM
);
1185 if (clnt
->cl_auth
->au_flavor
!= flavor
) {
1186 struct rpc_auth
*auth
;
1188 auth
= rpcauth_create(flavor
, clnt
);
1190 dprintk("%s: couldn't create credcache!\n", __FUNCTION__
);
1191 return (struct rpc_clnt
*)auth
;
1198 nfs4_put_client(clp
);
1199 return ERR_PTR(err
);
1203 * Set up an NFS4 superblock
1205 static int nfs4_fill_super(struct super_block
*sb
, struct nfs4_mount_data
*data
, int silent
)
1207 struct nfs_server
*server
;
1208 struct rpc_timeout timeparms
;
1209 rpc_authflavor_t authflavour
;
1212 sb
->s_blocksize_bits
= 0;
1213 sb
->s_blocksize
= 0;
1214 server
= NFS_SB(sb
);
1215 if (data
->rsize
!= 0)
1216 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
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
;
1222 server
->acregmin
= data
->acregmin
*HZ
;
1223 server
->acregmax
= data
->acregmax
*HZ
;
1224 server
->acdirmin
= data
->acdirmin
*HZ
;
1225 server
->acdirmax
= data
->acdirmax
*HZ
;
1227 server
->rpc_ops
= &nfs_v4_clientops
;
1229 nfs_init_timeout_values(&timeparms
, data
->proto
, data
->timeo
, data
->retrans
);
1231 server
->retrans_timeo
= timeparms
.to_initval
;
1232 server
->retrans_count
= timeparms
.to_retries
;
1234 /* Now create transport and client */
1235 authflavour
= RPC_AUTH_UNIX
;
1236 if (data
->auth_flavourlen
!= 0) {
1237 if (data
->auth_flavourlen
!= 1) {
1238 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
1239 __FUNCTION__
, data
->auth_flavourlen
);
1243 if (copy_from_user(&authflavour
, data
->auth_flavours
, sizeof(authflavour
))) {
1249 server
->client
= nfs4_create_client(server
, &timeparms
, data
->proto
, authflavour
);
1250 if (IS_ERR(server
->client
)) {
1251 err
= PTR_ERR(server
->client
);
1252 dprintk("%s: cannot create RPC client. Error = %d\n",
1257 sb
->s_time_gran
= 1;
1259 sb
->s_op
= &nfs4_sops
;
1260 err
= nfs_sb_init(sb
, authflavour
);
1266 static int nfs4_compare_super(struct super_block
*sb
, void *data
)
1268 struct nfs_server
*server
= data
;
1269 struct nfs_server
*old
= NFS_SB(sb
);
1271 if (strcmp(server
->hostname
, old
->hostname
) != 0)
1273 if (strcmp(server
->mnt_path
, old
->mnt_path
) != 0)
1279 nfs_copy_user_string(char *dst
, struct nfs_string
*src
, int maxlen
)
1284 return ERR_PTR(-EINVAL
);
1285 if (src
->len
< maxlen
)
1288 p
= dst
= kmalloc(maxlen
+ 1, GFP_KERNEL
);
1290 return ERR_PTR(-ENOMEM
);
1292 if (copy_from_user(dst
, src
->data
, maxlen
)) {
1294 return ERR_PTR(-EFAULT
);
1300 static int nfs4_get_sb(struct file_system_type
*fs_type
,
1301 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1304 struct nfs_server
*server
;
1305 struct super_block
*s
;
1306 struct nfs4_mount_data
*data
= raw_data
;
1310 dprintk("%s: missing data argument\n", __FUNCTION__
);
1313 if (data
->version
<= 0 || data
->version
> NFS4_MOUNT_VERSION
) {
1314 dprintk("%s: bad mount version\n", __FUNCTION__
);
1318 server
= kzalloc(sizeof(struct nfs_server
), GFP_KERNEL
);
1321 /* Zero out the NFS state stuff */
1322 init_nfsv4_state(server
);
1323 server
->client
= server
->client_sys
= server
->client_acl
= ERR_PTR(-EINVAL
);
1325 p
= nfs_copy_user_string(NULL
, &data
->hostname
, 256);
1328 server
->hostname
= p
;
1330 p
= nfs_copy_user_string(NULL
, &data
->mnt_path
, 1024);
1333 server
->mnt_path
= p
;
1335 p
= nfs_copy_user_string(server
->ip_addr
, &data
->client_addr
,
1336 sizeof(server
->ip_addr
) - 1);
1340 /* We now require that the mount process passes the remote address */
1341 if (data
->host_addrlen
!= sizeof(server
->addr
)) {
1345 if (copy_from_user(&server
->addr
, data
->host_addr
, sizeof(server
->addr
))) {
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",
1357 /* Fire up rpciod if not yet running */
1358 error
= rpciod_up();
1360 dprintk("%s: couldn't start rpciod! Error = %d\n",
1361 __FUNCTION__
, error
);
1365 s
= sget(fs_type
, nfs4_compare_super
, nfs_set_super
, server
);
1373 kfree(server
->mnt_path
);
1374 kfree(server
->hostname
);
1376 return simple_set_mnt(mnt
, s
);
1381 error
= nfs4_fill_super(s
, data
, flags
& MS_SILENT
? 1 : 0);
1383 up_write(&s
->s_umount
);
1384 deactivate_super(s
);
1387 s
->s_flags
|= MS_ACTIVE
;
1388 return simple_set_mnt(mnt
, s
);
1392 kfree(server
->mnt_path
);
1393 kfree(server
->hostname
);
1398 static void nfs4_kill_super(struct super_block
*sb
)
1400 struct nfs_server
*server
= NFS_SB(sb
);
1402 nfs_return_all_delegations(sb
);
1403 kill_anon_super(sb
);
1405 nfs4_renewd_prepare_shutdown(server
);
1407 if (server
->client
!= NULL
&& !IS_ERR(server
->client
))
1408 rpc_shutdown_client(server
->client
);
1410 destroy_nfsv4_state(server
);
1414 nfs_free_iostats(server
->io_stats
);
1415 kfree(server
->hostname
);
1417 nfs_release_automount_timer();
1421 * Constructs the SERVER-side path
1423 static inline char *nfs4_dup_path(const struct dentry
*dentry
)
1425 char *page
= (char *) __get_free_page(GFP_USER
);
1428 path
= nfs4_path(dentry
, page
, PAGE_SIZE
);
1429 if (!IS_ERR(path
)) {
1430 int len
= PAGE_SIZE
+ page
- path
;
1433 path
= kmalloc(len
, GFP_KERNEL
);
1435 memcpy(path
, tmp
, len
);
1437 path
= ERR_PTR(-ENOMEM
);
1439 free_page((unsigned long)page
);
1443 static struct super_block
*nfs4_clone_sb(struct nfs_server
*server
, struct nfs_clone_mount
*data
)
1445 const struct dentry
*dentry
= data
->dentry
;
1446 struct nfs4_client
*clp
= server
->nfs4_state
;
1447 struct super_block
*sb
;
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
;
1456 sb
= sget(&nfs4_fs_type
, nfs4_compare_super
, nfs_set_super
, server
);
1457 if (IS_ERR(sb
) || sb
->s_root
)
1459 nfs4_server_capabilities(server
, &server
->fh
);
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
);
1467 kfree(server
->mnt_path
);
1469 server
->mnt_path
= NULL
;
1473 static int nfs_clone_nfs4_sb(struct file_system_type
*fs_type
,
1474 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1476 struct nfs_clone_mount
*data
= raw_data
;
1477 return nfs_clone_generic_sb(data
, nfs4_clone_sb
, nfs_clone_server
, mnt
);
1480 static struct super_block
*nfs4_referral_sb(struct nfs_server
*server
, struct nfs_clone_mount
*data
)
1482 struct super_block
*sb
= ERR_PTR(-ENOMEM
);
1485 len
= strlen(data
->mnt_path
) + 1;
1486 server
->mnt_path
= kmalloc(len
, GFP_KERNEL
);
1487 if (server
->mnt_path
== NULL
)
1489 memcpy(server
->mnt_path
, data
->mnt_path
, len
);
1490 memcpy(&server
->addr
, data
->addr
, sizeof(struct sockaddr_in
));
1492 sb
= sget(&nfs4_fs_type
, nfs4_compare_super
, nfs_set_super
, server
);
1493 if (IS_ERR(sb
) || sb
->s_root
)
1497 kfree(server
->mnt_path
);
1499 server
->mnt_path
= NULL
;
1503 static struct nfs_server
*nfs4_referral_server(struct super_block
*sb
, struct nfs_clone_mount
*data
)
1505 struct nfs_server
*server
= NFS_SB(sb
);
1506 struct rpc_timeout timeparms
;
1507 int proto
, timeo
, retrans
;
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 */
1515 nfs_init_timeout_values(&timeparms
, proto
, timeo
, retrans
);
1517 server
->client
= nfs4_create_client(server
, &timeparms
, proto
, data
->authflavor
);
1518 if (IS_ERR((err
= server
->client
)))
1521 sb
->s_time_gran
= 1;
1522 sb
->s_op
= &nfs4_sops
;
1523 err
= ERR_PTR(nfs_sb_init(sb
, data
->authflavor
));
1527 return (struct nfs_server
*)err
;
1530 static int nfs_referral_nfs4_sb(struct file_system_type
*fs_type
,
1531 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1533 struct nfs_clone_mount
*data
= raw_data
;
1534 return nfs_clone_generic_sb(data
, nfs4_referral_sb
, nfs4_referral_server
, mnt
);