4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, 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>
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())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/mnt_namespace.h>
46 #include <linux/namei.h>
47 #include <linux/nfs_idmap.h>
48 #include <linux/vfs.h>
49 #include <linux/inet.h>
50 #include <linux/in6.h>
51 #include <linux/slab.h>
53 #include <linux/netdevice.h>
54 #include <linux/nfs_xdr.h>
55 #include <linux/magic.h>
56 #include <linux/parser.h>
58 #include <asm/system.h>
59 #include <asm/uaccess.h>
63 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_VFS
71 /* Mount options that take no arguments */
73 Opt_posix
, Opt_noposix
,
77 Opt_v2
, Opt_v3
, Opt_v4
,
78 Opt_udp
, Opt_tcp
, Opt_rdma
,
80 Opt_rdirplus
, Opt_nordirplus
,
81 Opt_sharecache
, Opt_nosharecache
,
82 Opt_resvport
, Opt_noresvport
,
83 Opt_fscache
, Opt_nofscache
,
85 /* Mount options that take integer arguments */
87 Opt_rsize
, Opt_wsize
, Opt_bsize
,
88 Opt_timeo
, Opt_retrans
,
89 Opt_acregmin
, Opt_acregmax
,
90 Opt_acdirmin
, Opt_acdirmax
,
98 /* Mount options that take string arguments */
99 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
100 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
104 /* Special mount options */
105 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
110 static const match_table_t nfs_mount_option_tokens
= {
111 { Opt_userspace
, "bg" },
112 { Opt_userspace
, "fg" },
113 { Opt_userspace
, "retry=%s" },
115 { Opt_sloppy
, "sloppy" },
117 { Opt_soft
, "soft" },
118 { Opt_hard
, "hard" },
119 { Opt_deprecated
, "intr" },
120 { Opt_deprecated
, "nointr" },
121 { Opt_posix
, "posix" },
122 { Opt_noposix
, "noposix" },
124 { Opt_nocto
, "nocto" },
126 { Opt_noac
, "noac" },
127 { Opt_lock
, "lock" },
128 { Opt_nolock
, "nolock" },
134 { Opt_rdma
, "rdma" },
136 { Opt_noacl
, "noacl" },
137 { Opt_rdirplus
, "rdirplus" },
138 { Opt_nordirplus
, "nordirplus" },
139 { Opt_sharecache
, "sharecache" },
140 { Opt_nosharecache
, "nosharecache" },
141 { Opt_resvport
, "resvport" },
142 { Opt_noresvport
, "noresvport" },
143 { Opt_fscache
, "fsc" },
144 { Opt_nofscache
, "nofsc" },
146 { Opt_port
, "port=%s" },
147 { Opt_rsize
, "rsize=%s" },
148 { Opt_wsize
, "wsize=%s" },
149 { Opt_bsize
, "bsize=%s" },
150 { Opt_timeo
, "timeo=%s" },
151 { Opt_retrans
, "retrans=%s" },
152 { Opt_acregmin
, "acregmin=%s" },
153 { Opt_acregmax
, "acregmax=%s" },
154 { Opt_acdirmin
, "acdirmin=%s" },
155 { Opt_acdirmax
, "acdirmax=%s" },
156 { Opt_actimeo
, "actimeo=%s" },
157 { Opt_namelen
, "namlen=%s" },
158 { Opt_mountport
, "mountport=%s" },
159 { Opt_mountvers
, "mountvers=%s" },
160 { Opt_nfsvers
, "nfsvers=%s" },
161 { Opt_nfsvers
, "vers=%s" },
162 { Opt_minorversion
, "minorversion=%s" },
164 { Opt_sec
, "sec=%s" },
165 { Opt_proto
, "proto=%s" },
166 { Opt_mountproto
, "mountproto=%s" },
167 { Opt_addr
, "addr=%s" },
168 { Opt_clientaddr
, "clientaddr=%s" },
169 { Opt_mounthost
, "mounthost=%s" },
170 { Opt_mountaddr
, "mountaddr=%s" },
172 { Opt_lookupcache
, "lookupcache=%s" },
173 { Opt_fscache_uniq
, "fsc=%s" },
179 Opt_xprt_udp
, Opt_xprt_udp6
, Opt_xprt_tcp
, Opt_xprt_tcp6
, Opt_xprt_rdma
,
184 static const match_table_t nfs_xprt_protocol_tokens
= {
185 { Opt_xprt_udp
, "udp" },
186 { Opt_xprt_udp6
, "udp6" },
187 { Opt_xprt_tcp
, "tcp" },
188 { Opt_xprt_tcp6
, "tcp6" },
189 { Opt_xprt_rdma
, "rdma" },
191 { Opt_xprt_err
, NULL
}
195 Opt_sec_none
, Opt_sec_sys
,
196 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
197 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
198 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
203 static const match_table_t nfs_secflavor_tokens
= {
204 { Opt_sec_none
, "none" },
205 { Opt_sec_none
, "null" },
206 { Opt_sec_sys
, "sys" },
208 { Opt_sec_krb5
, "krb5" },
209 { Opt_sec_krb5i
, "krb5i" },
210 { Opt_sec_krb5p
, "krb5p" },
212 { Opt_sec_lkey
, "lkey" },
213 { Opt_sec_lkeyi
, "lkeyi" },
214 { Opt_sec_lkeyp
, "lkeyp" },
216 { Opt_sec_spkm
, "spkm3" },
217 { Opt_sec_spkmi
, "spkm3i" },
218 { Opt_sec_spkmp
, "spkm3p" },
220 { Opt_sec_err
, NULL
}
224 Opt_lookupcache_all
, Opt_lookupcache_positive
,
225 Opt_lookupcache_none
,
230 static match_table_t nfs_lookupcache_tokens
= {
231 { Opt_lookupcache_all
, "all" },
232 { Opt_lookupcache_positive
, "pos" },
233 { Opt_lookupcache_positive
, "positive" },
234 { Opt_lookupcache_none
, "none" },
236 { Opt_lookupcache_err
, NULL
}
240 static void nfs_umount_begin(struct super_block
*);
241 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
242 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
243 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
244 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
245 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
246 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
247 static void nfs_put_super(struct super_block
*);
248 static void nfs_kill_super(struct super_block
*);
249 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
251 static struct file_system_type nfs_fs_type
= {
252 .owner
= THIS_MODULE
,
254 .get_sb
= nfs_get_sb
,
255 .kill_sb
= nfs_kill_super
,
256 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
259 struct file_system_type nfs_xdev_fs_type
= {
260 .owner
= THIS_MODULE
,
262 .get_sb
= nfs_xdev_get_sb
,
263 .kill_sb
= nfs_kill_super
,
264 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
267 static const struct super_operations nfs_sops
= {
268 .alloc_inode
= nfs_alloc_inode
,
269 .destroy_inode
= nfs_destroy_inode
,
270 .write_inode
= nfs_write_inode
,
271 .put_super
= nfs_put_super
,
272 .statfs
= nfs_statfs
,
273 .evict_inode
= nfs_evict_inode
,
274 .umount_begin
= nfs_umount_begin
,
275 .show_options
= nfs_show_options
,
276 .show_stats
= nfs_show_stats
,
277 .remount_fs
= nfs_remount
,
281 static int nfs4_validate_text_mount_data(void *options
,
282 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
283 static int nfs4_try_mount(int flags
, const char *dev_name
,
284 struct nfs_parsed_mount_data
*data
, struct vfsmount
*mnt
);
285 static int nfs4_get_sb(struct file_system_type
*fs_type
,
286 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
287 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
288 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
289 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
290 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
291 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
292 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
293 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
294 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
295 static void nfs4_kill_super(struct super_block
*sb
);
297 static struct file_system_type nfs4_fs_type
= {
298 .owner
= THIS_MODULE
,
300 .get_sb
= nfs4_get_sb
,
301 .kill_sb
= nfs4_kill_super
,
302 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
305 static struct file_system_type nfs4_remote_fs_type
= {
306 .owner
= THIS_MODULE
,
308 .get_sb
= nfs4_remote_get_sb
,
309 .kill_sb
= nfs4_kill_super
,
310 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
313 struct file_system_type nfs4_xdev_fs_type
= {
314 .owner
= THIS_MODULE
,
316 .get_sb
= nfs4_xdev_get_sb
,
317 .kill_sb
= nfs4_kill_super
,
318 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
321 static struct file_system_type nfs4_remote_referral_fs_type
= {
322 .owner
= THIS_MODULE
,
324 .get_sb
= nfs4_remote_referral_get_sb
,
325 .kill_sb
= nfs4_kill_super
,
326 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
329 struct file_system_type nfs4_referral_fs_type
= {
330 .owner
= THIS_MODULE
,
332 .get_sb
= nfs4_referral_get_sb
,
333 .kill_sb
= nfs4_kill_super
,
334 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
337 static const struct super_operations nfs4_sops
= {
338 .alloc_inode
= nfs_alloc_inode
,
339 .destroy_inode
= nfs_destroy_inode
,
340 .write_inode
= nfs_write_inode
,
341 .put_super
= nfs_put_super
,
342 .statfs
= nfs_statfs
,
343 .evict_inode
= nfs4_evict_inode
,
344 .umount_begin
= nfs_umount_begin
,
345 .show_options
= nfs_show_options
,
346 .show_stats
= nfs_show_stats
,
347 .remount_fs
= nfs_remount
,
351 static struct shrinker acl_shrinker
= {
352 .shrink
= nfs_access_cache_shrinker
,
353 .seeks
= DEFAULT_SEEKS
,
357 * Register the NFS filesystems
359 int __init
register_nfs_fs(void)
363 ret
= register_filesystem(&nfs_fs_type
);
367 ret
= nfs_register_sysctl();
371 ret
= register_filesystem(&nfs4_fs_type
);
375 register_shrinker(&acl_shrinker
);
380 nfs_unregister_sysctl();
383 unregister_filesystem(&nfs_fs_type
);
389 * Unregister the NFS filesystems
391 void __exit
unregister_nfs_fs(void)
393 unregister_shrinker(&acl_shrinker
);
395 unregister_filesystem(&nfs4_fs_type
);
397 nfs_unregister_sysctl();
398 unregister_filesystem(&nfs_fs_type
);
401 void nfs_sb_active(struct super_block
*sb
)
403 struct nfs_server
*server
= NFS_SB(sb
);
405 if (atomic_inc_return(&server
->active
) == 1)
406 atomic_inc(&sb
->s_active
);
409 void nfs_sb_deactive(struct super_block
*sb
)
411 struct nfs_server
*server
= NFS_SB(sb
);
413 if (atomic_dec_and_test(&server
->active
))
414 deactivate_super(sb
);
418 * Deliver file system statistics to userspace
420 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
422 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
423 unsigned char blockbits
;
424 unsigned long blockres
;
425 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
426 struct nfs_fsstat res
;
429 res
.fattr
= nfs_alloc_fattr();
430 if (res
.fattr
== NULL
)
433 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
434 if (unlikely(error
== -ESTALE
)) {
435 struct dentry
*pd_dentry
;
437 pd_dentry
= dget_parent(dentry
);
438 if (pd_dentry
!= NULL
) {
439 nfs_zap_caches(pd_dentry
->d_inode
);
443 nfs_free_fattr(res
.fattr
);
447 buf
->f_type
= NFS_SUPER_MAGIC
;
450 * Current versions of glibc do not correctly handle the
451 * case where f_frsize != f_bsize. Eventually we want to
452 * report the value of wtmult in this field.
454 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
457 * On most *nix systems, f_blocks, f_bfree, and f_bavail
458 * are reported in units of f_frsize. Linux hasn't had
459 * an f_frsize field in its statfs struct until recently,
460 * thus historically Linux's sys_statfs reports these
461 * fields in units of f_bsize.
463 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
464 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
465 blockres
= (1 << blockbits
) - 1;
466 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
467 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
468 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
470 buf
->f_files
= res
.tfiles
;
471 buf
->f_ffree
= res
.afiles
;
473 buf
->f_namelen
= server
->namelen
;
478 dprintk("%s: statfs error = %d\n", __func__
, -error
);
483 * Map the security flavour number to a name
485 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
487 static const struct {
488 rpc_authflavor_t flavour
;
491 { RPC_AUTH_NULL
, "null" },
492 { RPC_AUTH_UNIX
, "sys" },
493 { RPC_AUTH_GSS_KRB5
, "krb5" },
494 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
495 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
496 { RPC_AUTH_GSS_LKEY
, "lkey" },
497 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
498 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
499 { RPC_AUTH_GSS_SPKM
, "spkm" },
500 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
501 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
502 { UINT_MAX
, "unknown" }
506 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
507 if (sec_flavours
[i
].flavour
== flavour
)
510 return sec_flavours
[i
].str
;
513 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
516 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
518 seq_printf(m
, ",mountproto=");
519 switch (sap
->sa_family
) {
521 switch (nfss
->mountd_protocol
) {
523 seq_printf(m
, RPCBIND_NETID_UDP
);
526 seq_printf(m
, RPCBIND_NETID_TCP
);
530 seq_printf(m
, "auto");
534 switch (nfss
->mountd_protocol
) {
536 seq_printf(m
, RPCBIND_NETID_UDP6
);
539 seq_printf(m
, RPCBIND_NETID_TCP6
);
543 seq_printf(m
, "auto");
548 seq_printf(m
, "auto");
552 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
555 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
557 if (nfss
->flags
& NFS_MOUNT_LEGACY_INTERFACE
)
560 switch (sap
->sa_family
) {
562 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
563 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
567 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
568 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
573 seq_printf(m
, ",mountaddr=unspecified");
576 if (nfss
->mountd_version
|| showdefaults
)
577 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
578 if (nfss
->mountd_port
|| showdefaults
)
579 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
581 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
585 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
588 struct nfs_client
*clp
= nfss
->nfs_client
;
590 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
591 seq_printf(m
, ",minorversion=%u", clp
->cl_minorversion
);
594 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
601 * Describe the mount options in force on this server representation
603 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
606 static const struct proc_nfs_info
{
611 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
612 { NFS_MOUNT_POSIX
, ",posix", "" },
613 { NFS_MOUNT_NOCTO
, ",nocto", "" },
614 { NFS_MOUNT_NOAC
, ",noac", "" },
615 { NFS_MOUNT_NONLM
, ",nolock", "" },
616 { NFS_MOUNT_NOACL
, ",noacl", "" },
617 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
618 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
619 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
622 const struct proc_nfs_info
*nfs_infop
;
623 struct nfs_client
*clp
= nfss
->nfs_client
;
624 u32 version
= clp
->rpc_ops
->version
;
626 seq_printf(m
, ",vers=%u", version
);
627 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
628 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
629 if (nfss
->bsize
!= 0)
630 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
631 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
632 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
633 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
634 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
635 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
636 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
637 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
638 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
639 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
640 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
641 if (nfss
->flags
& nfs_infop
->flag
)
642 seq_puts(m
, nfs_infop
->str
);
644 seq_puts(m
, nfs_infop
->nostr
);
646 seq_printf(m
, ",proto=%s",
647 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
649 if (nfss
->port
!= NFS_PORT
)
650 seq_printf(m
, ",port=%u", nfss
->port
);
653 seq_printf(m
, ",port=%u", nfss
->port
);
655 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
656 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
657 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
660 nfs_show_mountd_options(m
, nfss
, showdefaults
);
662 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
664 if (nfss
->options
& NFS_OPTION_FSCACHE
)
665 seq_printf(m
, ",fsc");
667 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONEG
) {
668 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONE
)
669 seq_printf(m
, ",lookupcache=none");
671 seq_printf(m
, ",lookupcache=pos");
676 * Describe the mount options on this VFS mountpoint
678 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
680 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
682 nfs_show_mount_options(m
, nfss
, 0);
684 seq_printf(m
, ",addr=%s",
685 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
692 * Present statistical information for this VFS mountpoint
694 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
697 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
698 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
699 struct nfs_iostats totals
= { };
701 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
704 * Display all mount option settings
706 seq_printf(m
, "\n\topts:\t");
707 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
708 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
709 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
710 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
711 nfs_show_mount_options(m
, nfss
, 1);
713 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
715 seq_printf(m
, "\n\tcaps:\t");
716 seq_printf(m
, "caps=0x%x", nfss
->caps
);
717 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
718 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
719 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
720 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
723 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
724 seq_printf(m
, "\n\tnfsv4:\t");
725 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
726 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
727 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
732 * Display security flavor in effect for this mount
734 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
736 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
739 * Display superblock I/O counters
741 for_each_possible_cpu(cpu
) {
742 struct nfs_iostats
*stats
;
745 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
747 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
748 totals
.events
[i
] += stats
->events
[i
];
749 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
750 totals
.bytes
[i
] += stats
->bytes
[i
];
751 #ifdef CONFIG_NFS_FSCACHE
752 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
753 totals
.fscache
[i
] += stats
->fscache
[i
];
759 seq_printf(m
, "\n\tevents:\t");
760 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
761 seq_printf(m
, "%lu ", totals
.events
[i
]);
762 seq_printf(m
, "\n\tbytes:\t");
763 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
764 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
765 #ifdef CONFIG_NFS_FSCACHE
766 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
767 seq_printf(m
, "\n\tfsc:\t");
768 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
769 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
774 rpc_print_iostats(m
, nfss
->client
);
780 * Begin unmount by attempting to remove all automounted mountpoints we added
781 * in response to xdev traversals and referrals
783 static void nfs_umount_begin(struct super_block
*sb
)
785 struct nfs_server
*server
;
786 struct rpc_clnt
*rpc
;
789 /* -EIO all pending I/O */
790 rpc
= server
->client_acl
;
792 rpc_killall_tasks(rpc
);
793 rpc
= server
->client
;
795 rpc_killall_tasks(rpc
);
798 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
800 struct nfs_parsed_mount_data
*data
;
802 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
804 data
->acregmin
= NFS_DEF_ACREGMIN
;
805 data
->acregmax
= NFS_DEF_ACREGMAX
;
806 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
807 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
808 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
809 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
810 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
811 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
812 data
->auth_flavor_len
= 1;
813 data
->version
= version
;
814 data
->minorversion
= 0;
820 * Sanity-check a server address provided by the mount command.
822 * Address family must be initialized, and address must not be
823 * the ANY address for that family.
825 static int nfs_verify_server_address(struct sockaddr
*addr
)
827 switch (addr
->sa_family
) {
829 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
830 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
833 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
834 return !ipv6_addr_any(sa
);
838 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
843 * Select between a default port value and a user-specified port value.
844 * If a zero value is set, then autobind will be used.
846 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
847 const unsigned short default_port
)
849 if (*port
== NFS_UNSPEC_PORT
)
850 *port
= default_port
;
852 rpc_set_port(sap
, *port
);
856 * Sanity check the NFS transport protocol.
859 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
861 switch (mnt
->nfs_server
.protocol
) {
862 case XPRT_TRANSPORT_UDP
:
863 case XPRT_TRANSPORT_TCP
:
864 case XPRT_TRANSPORT_RDMA
:
867 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
872 * For text based NFSv2/v3 mounts, the mount protocol transport default
873 * settings should depend upon the specified NFS transport.
875 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
877 nfs_validate_transport_protocol(mnt
);
879 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
880 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
882 switch (mnt
->nfs_server
.protocol
) {
883 case XPRT_TRANSPORT_UDP
:
884 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
886 case XPRT_TRANSPORT_TCP
:
887 case XPRT_TRANSPORT_RDMA
:
888 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
893 * Parse the value of the 'sec=' option.
895 static int nfs_parse_security_flavors(char *value
,
896 struct nfs_parsed_mount_data
*mnt
)
898 substring_t args
[MAX_OPT_ARGS
];
900 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
902 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
904 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
907 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
910 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
913 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
916 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
919 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
922 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
925 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
928 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
931 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
934 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
940 mnt
->auth_flavor_len
= 1;
945 * Error-check and convert a string of mount options from user space into
946 * a data structure. The whole mount string is processed; bad options are
947 * skipped as they are encountered. If there were no errors, return 1;
948 * otherwise return 0 (zero).
950 static int nfs_parse_mount_options(char *raw
,
951 struct nfs_parsed_mount_data
*mnt
)
953 char *p
, *string
, *secdata
;
954 int rc
, sloppy
= 0, invalid_option
= 0;
955 unsigned short protofamily
= AF_UNSPEC
;
956 unsigned short mountfamily
= AF_UNSPEC
;
959 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
962 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
964 secdata
= alloc_secdata();
968 rc
= security_sb_copy_data(raw
, secdata
);
970 goto out_security_failure
;
972 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
974 goto out_security_failure
;
976 free_secdata(secdata
);
978 while ((p
= strsep(&raw
, ",")) != NULL
) {
979 substring_t args
[MAX_OPT_ARGS
];
980 unsigned long option
;
986 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
988 token
= match_token(p
, nfs_mount_option_tokens
, args
);
992 * boolean options: foo/nofoo
995 mnt
->flags
|= NFS_MOUNT_SOFT
;
998 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
1001 mnt
->flags
|= NFS_MOUNT_POSIX
;
1004 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
1007 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1010 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1013 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1016 mnt
->flags
|= NFS_MOUNT_NOAC
;
1019 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1022 mnt
->flags
|= NFS_MOUNT_NONLM
;
1025 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1029 mnt
->flags
|= NFS_MOUNT_VER3
;
1032 #ifdef CONFIG_NFS_V4
1034 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1039 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1040 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1043 mnt
->flags
|= NFS_MOUNT_TCP
;
1044 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1047 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1048 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1049 xprt_load_transport(p
);
1052 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1055 mnt
->flags
|= NFS_MOUNT_NOACL
;
1058 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1060 case Opt_nordirplus
:
1061 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1063 case Opt_sharecache
:
1064 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1066 case Opt_nosharecache
:
1067 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1070 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1072 case Opt_noresvport
:
1073 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1076 mnt
->options
|= NFS_OPTION_FSCACHE
;
1077 kfree(mnt
->fscache_uniq
);
1078 mnt
->fscache_uniq
= NULL
;
1081 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1082 kfree(mnt
->fscache_uniq
);
1083 mnt
->fscache_uniq
= NULL
;
1087 * options that take numeric values
1090 string
= match_strdup(args
);
1093 rc
= strict_strtoul(string
, 10, &option
);
1095 if (rc
!= 0 || option
> USHRT_MAX
)
1096 goto out_invalid_value
;
1097 mnt
->nfs_server
.port
= option
;
1100 string
= match_strdup(args
);
1103 rc
= strict_strtoul(string
, 10, &option
);
1106 goto out_invalid_value
;
1107 mnt
->rsize
= option
;
1110 string
= match_strdup(args
);
1113 rc
= strict_strtoul(string
, 10, &option
);
1116 goto out_invalid_value
;
1117 mnt
->wsize
= option
;
1120 string
= match_strdup(args
);
1123 rc
= strict_strtoul(string
, 10, &option
);
1126 goto out_invalid_value
;
1127 mnt
->bsize
= option
;
1130 string
= match_strdup(args
);
1133 rc
= strict_strtoul(string
, 10, &option
);
1135 if (rc
!= 0 || option
== 0)
1136 goto out_invalid_value
;
1137 mnt
->timeo
= option
;
1140 string
= match_strdup(args
);
1143 rc
= strict_strtoul(string
, 10, &option
);
1145 if (rc
!= 0 || option
== 0)
1146 goto out_invalid_value
;
1147 mnt
->retrans
= option
;
1150 string
= match_strdup(args
);
1153 rc
= strict_strtoul(string
, 10, &option
);
1156 goto out_invalid_value
;
1157 mnt
->acregmin
= option
;
1160 string
= match_strdup(args
);
1163 rc
= strict_strtoul(string
, 10, &option
);
1166 goto out_invalid_value
;
1167 mnt
->acregmax
= option
;
1170 string
= match_strdup(args
);
1173 rc
= strict_strtoul(string
, 10, &option
);
1176 goto out_invalid_value
;
1177 mnt
->acdirmin
= option
;
1180 string
= match_strdup(args
);
1183 rc
= strict_strtoul(string
, 10, &option
);
1186 goto out_invalid_value
;
1187 mnt
->acdirmax
= option
;
1190 string
= match_strdup(args
);
1193 rc
= strict_strtoul(string
, 10, &option
);
1196 goto out_invalid_value
;
1197 mnt
->acregmin
= mnt
->acregmax
=
1198 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1201 string
= match_strdup(args
);
1204 rc
= strict_strtoul(string
, 10, &option
);
1207 goto out_invalid_value
;
1208 mnt
->namlen
= option
;
1211 string
= match_strdup(args
);
1214 rc
= strict_strtoul(string
, 10, &option
);
1216 if (rc
!= 0 || option
> USHRT_MAX
)
1217 goto out_invalid_value
;
1218 mnt
->mount_server
.port
= option
;
1221 string
= match_strdup(args
);
1224 rc
= strict_strtoul(string
, 10, &option
);
1227 option
< NFS_MNT_VERSION
||
1228 option
> NFS_MNT3_VERSION
)
1229 goto out_invalid_value
;
1230 mnt
->mount_server
.version
= option
;
1233 string
= match_strdup(args
);
1236 rc
= strict_strtoul(string
, 10, &option
);
1239 goto out_invalid_value
;
1242 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1246 mnt
->flags
|= NFS_MOUNT_VER3
;
1249 #ifdef CONFIG_NFS_V4
1251 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1256 goto out_invalid_value
;
1259 case Opt_minorversion
:
1260 string
= match_strdup(args
);
1263 rc
= strict_strtoul(string
, 10, &option
);
1266 goto out_invalid_value
;
1267 if (option
> NFS4_MAX_MINOR_VERSION
)
1268 goto out_invalid_value
;
1269 mnt
->minorversion
= option
;
1273 * options that take text values
1276 string
= match_strdup(args
);
1279 rc
= nfs_parse_security_flavors(string
, mnt
);
1282 dfprintk(MOUNT
, "NFS: unrecognized "
1283 "security flavor\n");
1288 string
= match_strdup(args
);
1291 token
= match_token(string
,
1292 nfs_xprt_protocol_tokens
, args
);
1294 protofamily
= AF_INET
;
1297 protofamily
= AF_INET6
;
1299 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1300 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1304 protofamily
= AF_INET6
;
1306 mnt
->flags
|= NFS_MOUNT_TCP
;
1307 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1311 /* vector side protocols to TCP */
1312 mnt
->flags
|= NFS_MOUNT_TCP
;
1313 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1314 xprt_load_transport(string
);
1318 dfprintk(MOUNT
, "NFS: unrecognized "
1319 "transport protocol\n");
1324 case Opt_mountproto
:
1325 string
= match_strdup(args
);
1328 token
= match_token(string
,
1329 nfs_xprt_protocol_tokens
, args
);
1332 mountfamily
= AF_INET
;
1335 mountfamily
= AF_INET6
;
1337 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1340 mountfamily
= AF_INET6
;
1342 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1344 case Opt_xprt_rdma
: /* not used for side protocols */
1346 dfprintk(MOUNT
, "NFS: unrecognized "
1347 "transport protocol\n");
1352 string
= match_strdup(args
);
1355 mnt
->nfs_server
.addrlen
=
1356 rpc_pton(string
, strlen(string
),
1358 &mnt
->nfs_server
.address
,
1359 sizeof(mnt
->nfs_server
.address
));
1361 if (mnt
->nfs_server
.addrlen
== 0)
1362 goto out_invalid_address
;
1364 case Opt_clientaddr
:
1365 string
= match_strdup(args
);
1368 kfree(mnt
->client_address
);
1369 mnt
->client_address
= string
;
1372 string
= match_strdup(args
);
1375 kfree(mnt
->mount_server
.hostname
);
1376 mnt
->mount_server
.hostname
= string
;
1379 string
= match_strdup(args
);
1382 mnt
->mount_server
.addrlen
=
1383 rpc_pton(string
, strlen(string
),
1385 &mnt
->mount_server
.address
,
1386 sizeof(mnt
->mount_server
.address
));
1388 if (mnt
->mount_server
.addrlen
== 0)
1389 goto out_invalid_address
;
1391 case Opt_lookupcache
:
1392 string
= match_strdup(args
);
1395 token
= match_token(string
,
1396 nfs_lookupcache_tokens
, args
);
1399 case Opt_lookupcache_all
:
1400 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1402 case Opt_lookupcache_positive
:
1403 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1404 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1406 case Opt_lookupcache_none
:
1407 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1410 dfprintk(MOUNT
, "NFS: invalid "
1411 "lookupcache argument\n");
1415 case Opt_fscache_uniq
:
1416 string
= match_strdup(args
);
1419 kfree(mnt
->fscache_uniq
);
1420 mnt
->fscache_uniq
= string
;
1421 mnt
->options
|= NFS_OPTION_FSCACHE
;
1429 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1432 case Opt_deprecated
:
1433 dfprintk(MOUNT
, "NFS: ignoring mount option "
1439 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1444 if (!sloppy
&& invalid_option
)
1448 * verify that any proto=/mountproto= options match the address
1449 * familiies in the addr=/mountaddr= options.
1451 if (protofamily
!= AF_UNSPEC
&&
1452 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1453 goto out_proto_mismatch
;
1455 if (mountfamily
!= AF_UNSPEC
) {
1456 if (mnt
->mount_server
.addrlen
) {
1457 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1458 goto out_mountproto_mismatch
;
1460 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1461 goto out_mountproto_mismatch
;
1467 out_mountproto_mismatch
:
1468 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1472 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1474 out_invalid_address
:
1475 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1478 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1481 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1483 out_security_failure
:
1484 free_secdata(secdata
);
1485 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1490 * Match the requested auth flavors with the list returned by
1491 * the server. Returns zero and sets the mount's authentication
1492 * flavor on success; returns -EACCES if server does not support
1493 * the requested flavor.
1495 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1496 struct nfs_mount_request
*request
)
1498 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1501 * Certain releases of Linux's mountd return an empty
1502 * flavor list. To prevent behavioral regression with
1503 * these servers (ie. rejecting mounts that used to
1504 * succeed), revert to pre-2.6.32 behavior (no checking)
1505 * if the returned flavor list is empty.
1507 if (server_authlist_len
== 0)
1511 * We avoid sophisticated negotiating here, as there are
1512 * plenty of cases where we can get it wrong, providing
1513 * either too little or too much security.
1515 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1516 * flavor listed first. However, some servers list
1517 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1518 * preferred default, in args->auth_flavors[0] if user
1519 * didn't specify sec= mount option.
1521 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1522 for (j
= 0; j
< server_authlist_len
; j
++)
1523 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1524 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1525 request
->auth_flavs
[j
]);
1526 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1530 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1531 nfs_umount(request
);
1536 * Use the remote server's MOUNT service to request the NFS file handle
1537 * corresponding to the provided path.
1539 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1540 struct nfs_fh
*root_fh
)
1542 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1543 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1544 struct nfs_mount_request request
= {
1545 .sap
= (struct sockaddr
*)
1546 &args
->mount_server
.address
,
1547 .dirpath
= args
->nfs_server
.export_path
,
1548 .protocol
= args
->mount_server
.protocol
,
1550 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1551 .auth_flav_len
= &server_authlist_len
,
1552 .auth_flavs
= server_authlist
,
1556 if (args
->mount_server
.version
== 0) {
1557 switch (args
->version
) {
1559 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1562 args
->mount_server
.version
= NFS_MNT_VERSION
;
1565 request
.version
= args
->mount_server
.version
;
1567 if (args
->mount_server
.hostname
)
1568 request
.hostname
= args
->mount_server
.hostname
;
1570 request
.hostname
= args
->nfs_server
.hostname
;
1573 * Construct the mount server's address.
1575 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1576 memcpy(request
.sap
, &args
->nfs_server
.address
,
1577 args
->nfs_server
.addrlen
);
1578 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1580 request
.salen
= args
->mount_server
.addrlen
;
1581 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1584 * Now ask the mount server to map our export path
1587 status
= nfs_mount(&request
);
1589 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1590 request
.hostname
, status
);
1595 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1597 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1599 return nfs_walk_authlist(args
, &request
);
1602 static int nfs_parse_simple_hostname(const char *dev_name
,
1603 char **hostname
, size_t maxnamlen
,
1604 char **export_path
, size_t maxpathlen
)
1607 char *colon
, *comma
;
1609 colon
= strchr(dev_name
, ':');
1611 goto out_bad_devname
;
1613 len
= colon
- dev_name
;
1614 if (len
> maxnamlen
)
1617 /* N.B. caller will free nfs_server.hostname in all cases */
1618 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1622 /* kill possible hostname list: not supported */
1623 comma
= strchr(*hostname
, ',');
1624 if (comma
!= NULL
) {
1625 if (comma
== *hostname
)
1626 goto out_bad_devname
;
1631 len
= strlen(colon
);
1632 if (len
> maxpathlen
)
1634 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1638 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1642 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1646 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1650 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1651 return -ENAMETOOLONG
;
1654 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1655 return -ENAMETOOLONG
;
1659 * Hostname has square brackets around it because it contains one or
1660 * more colons. We look for the first closing square bracket, and a
1661 * colon must follow it.
1663 static int nfs_parse_protected_hostname(const char *dev_name
,
1664 char **hostname
, size_t maxnamlen
,
1665 char **export_path
, size_t maxpathlen
)
1670 start
= (char *)(dev_name
+ 1);
1672 end
= strchr(start
, ']');
1674 goto out_bad_devname
;
1675 if (*(end
+ 1) != ':')
1676 goto out_bad_devname
;
1679 if (len
> maxnamlen
)
1682 /* N.B. caller will free nfs_server.hostname in all cases */
1683 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1684 if (*hostname
== NULL
)
1689 if (len
> maxpathlen
)
1691 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1698 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1702 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1706 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1707 return -ENAMETOOLONG
;
1710 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1711 return -ENAMETOOLONG
;
1715 * Split "dev_name" into "hostname:export_path".
1717 * The leftmost colon demarks the split between the server's hostname
1718 * and the export path. If the hostname starts with a left square
1719 * bracket, then it may contain colons.
1721 * Note: caller frees hostname and export path, even on error.
1723 static int nfs_parse_devname(const char *dev_name
,
1724 char **hostname
, size_t maxnamlen
,
1725 char **export_path
, size_t maxpathlen
)
1727 if (*dev_name
== '[')
1728 return nfs_parse_protected_hostname(dev_name
,
1729 hostname
, maxnamlen
,
1730 export_path
, maxpathlen
);
1732 return nfs_parse_simple_hostname(dev_name
,
1733 hostname
, maxnamlen
,
1734 export_path
, maxpathlen
);
1738 * Validate the NFS2/NFS3 mount data
1739 * - fills in the mount root filehandle
1741 * For option strings, user space handles the following behaviors:
1743 * + DNS: mapping server host name to IP address ("addr=" option)
1745 * + failure mode: how to behave if a mount request can't be handled
1746 * immediately ("fg/bg" option)
1748 * + retry: how often to retry a mount request ("retry=" option)
1750 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1751 * mountproto=tcp after mountproto=udp, and so on
1753 static int nfs_validate_mount_data(void *options
,
1754 struct nfs_parsed_mount_data
*args
,
1755 struct nfs_fh
*mntfh
,
1756 const char *dev_name
)
1758 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1759 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1764 switch (data
->version
) {
1770 if (data
->flags
& NFS_MOUNT_VER3
)
1772 data
->root
.size
= NFS2_FHSIZE
;
1773 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1775 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1778 memset(data
->context
, 0, sizeof(data
->context
));
1780 if (data
->flags
& NFS_MOUNT_VER3
) {
1781 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1782 goto out_invalid_fh
;
1783 mntfh
->size
= data
->root
.size
;
1786 mntfh
->size
= NFS2_FHSIZE
;
1791 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1792 if (mntfh
->size
< sizeof(mntfh
->data
))
1793 memset(mntfh
->data
+ mntfh
->size
, 0,
1794 sizeof(mntfh
->data
) - mntfh
->size
);
1797 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1800 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1801 args
->flags
|= NFS_MOUNT_LEGACY_INTERFACE
;
1802 args
->rsize
= data
->rsize
;
1803 args
->wsize
= data
->wsize
;
1804 args
->timeo
= data
->timeo
;
1805 args
->retrans
= data
->retrans
;
1806 args
->acregmin
= data
->acregmin
;
1807 args
->acregmax
= data
->acregmax
;
1808 args
->acdirmin
= data
->acdirmin
;
1809 args
->acdirmax
= data
->acdirmax
;
1811 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1812 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1813 if (!nfs_verify_server_address(sap
))
1814 goto out_no_address
;
1816 if (!(data
->flags
& NFS_MOUNT_TCP
))
1817 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1818 /* N.B. caller will free nfs_server.hostname in all cases */
1819 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1820 args
->namlen
= data
->namlen
;
1821 args
->bsize
= data
->bsize
;
1823 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1824 args
->auth_flavors
[0] = data
->pseudoflavor
;
1825 if (!args
->nfs_server
.hostname
)
1829 * The legacy version 6 binary mount data from userspace has a
1830 * field used only to transport selinux information into the
1831 * the kernel. To continue to support that functionality we
1832 * have a touch of selinux knowledge here in the NFS code. The
1833 * userspace code converted context=blah to just blah so we are
1834 * converting back to the full string selinux understands.
1836 if (data
->context
[0]){
1837 #ifdef CONFIG_SECURITY_SELINUX
1839 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1842 strcpy(opts_str
, "context=");
1843 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1844 strcat(opts_str
, &data
->context
[0]);
1845 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1858 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1861 if (!nfs_verify_server_address(sap
))
1862 goto out_no_address
;
1864 if (args
->version
== 4)
1865 #ifdef CONFIG_NFS_V4
1866 return nfs4_validate_text_mount_data(options
,
1869 goto out_v4_not_compiled
;
1872 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1874 nfs_set_mount_transport_protocol(args
);
1876 status
= nfs_parse_devname(dev_name
,
1877 &args
->nfs_server
.hostname
,
1879 &args
->nfs_server
.export_path
,
1882 status
= nfs_try_mount(args
, mntfh
);
1884 kfree(args
->nfs_server
.export_path
);
1885 args
->nfs_server
.export_path
= NULL
;
1894 #ifndef CONFIG_NFS_V3
1895 if (args
->version
== 3)
1896 goto out_v3_not_compiled
;
1897 #endif /* !CONFIG_NFS_V3 */
1902 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1906 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1911 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1914 #ifndef CONFIG_NFS_V3
1915 out_v3_not_compiled
:
1916 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1917 return -EPROTONOSUPPORT
;
1918 #endif /* !CONFIG_NFS_V3 */
1920 #ifndef CONFIG_NFS_V4
1921 out_v4_not_compiled
:
1922 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1923 return -EPROTONOSUPPORT
;
1924 #endif /* !CONFIG_NFS_V4 */
1927 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1931 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1935 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1940 nfs_compare_remount_data(struct nfs_server
*nfss
,
1941 struct nfs_parsed_mount_data
*data
)
1943 if (data
->flags
!= nfss
->flags
||
1944 data
->rsize
!= nfss
->rsize
||
1945 data
->wsize
!= nfss
->wsize
||
1946 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1947 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1948 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1949 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1950 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1951 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1952 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1953 data
->nfs_server
.port
!= nfss
->port
||
1954 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1955 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
1956 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
1963 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1966 struct nfs_server
*nfss
= sb
->s_fs_info
;
1967 struct nfs_parsed_mount_data
*data
;
1968 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1969 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1970 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1973 * Userspace mount programs that send binary options generally send
1974 * them populated with default values. We have no way to know which
1975 * ones were explicitly specified. Fall back to legacy behavior and
1976 * just return success.
1978 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1979 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1980 options
->version
<= 6))))
1983 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1987 /* fill out struct with values from existing mount */
1988 data
->flags
= nfss
->flags
;
1989 data
->rsize
= nfss
->rsize
;
1990 data
->wsize
= nfss
->wsize
;
1991 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1992 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1993 data
->acregmin
= nfss
->acregmin
/ HZ
;
1994 data
->acregmax
= nfss
->acregmax
/ HZ
;
1995 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1996 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1997 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1998 data
->nfs_server
.port
= nfss
->port
;
1999 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
2000 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
2001 data
->nfs_server
.addrlen
);
2003 /* overwrite those values with any that were specified */
2004 error
= nfs_parse_mount_options((char *)options
, data
);
2008 /* compare new mount options with old ones */
2009 error
= nfs_compare_remount_data(nfss
, data
);
2016 * Initialise the common bits of the superblock
2018 static inline void nfs_initialise_sb(struct super_block
*sb
)
2020 struct nfs_server
*server
= NFS_SB(sb
);
2022 sb
->s_magic
= NFS_SUPER_MAGIC
;
2024 /* We probably want something more informative here */
2025 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
2026 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
2028 if (sb
->s_blocksize
== 0)
2029 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
2030 &sb
->s_blocksize_bits
);
2032 if (server
->flags
& NFS_MOUNT_NOAC
)
2033 sb
->s_flags
|= MS_SYNCHRONOUS
;
2035 sb
->s_bdi
= &server
->backing_dev_info
;
2037 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2041 * Finish setting up an NFS2/3 superblock
2043 static void nfs_fill_super(struct super_block
*sb
,
2044 struct nfs_parsed_mount_data
*data
)
2046 struct nfs_server
*server
= NFS_SB(sb
);
2048 sb
->s_blocksize_bits
= 0;
2049 sb
->s_blocksize
= 0;
2051 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2053 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2054 /* The VFS shouldn't apply the umask to mode bits. We will do
2055 * so ourselves when necessary.
2057 sb
->s_flags
|= MS_POSIXACL
;
2058 sb
->s_time_gran
= 1;
2061 sb
->s_op
= &nfs_sops
;
2062 nfs_initialise_sb(sb
);
2066 * Finish setting up a cloned NFS2/3 superblock
2068 static void nfs_clone_super(struct super_block
*sb
,
2069 const struct super_block
*old_sb
)
2071 struct nfs_server
*server
= NFS_SB(sb
);
2073 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2074 sb
->s_blocksize
= old_sb
->s_blocksize
;
2075 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2077 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2078 /* The VFS shouldn't apply the umask to mode bits. We will do
2079 * so ourselves when necessary.
2081 sb
->s_flags
|= MS_POSIXACL
;
2082 sb
->s_time_gran
= 1;
2085 sb
->s_op
= old_sb
->s_op
;
2086 nfs_initialise_sb(sb
);
2089 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2091 const struct nfs_server
*a
= s
->s_fs_info
;
2092 const struct rpc_clnt
*clnt_a
= a
->client
;
2093 const struct rpc_clnt
*clnt_b
= b
->client
;
2095 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2097 if (a
->nfs_client
!= b
->nfs_client
)
2099 if (a
->flags
!= b
->flags
)
2101 if (a
->wsize
!= b
->wsize
)
2103 if (a
->rsize
!= b
->rsize
)
2105 if (a
->acregmin
!= b
->acregmin
)
2107 if (a
->acregmax
!= b
->acregmax
)
2109 if (a
->acdirmin
!= b
->acdirmin
)
2111 if (a
->acdirmax
!= b
->acdirmax
)
2113 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2120 struct nfs_sb_mountdata
{
2121 struct nfs_server
*server
;
2125 static int nfs_set_super(struct super_block
*s
, void *data
)
2127 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2128 struct nfs_server
*server
= sb_mntdata
->server
;
2131 s
->s_flags
= sb_mntdata
->mntflags
;
2132 s
->s_fs_info
= server
;
2133 ret
= set_anon_super(s
, server
);
2135 server
->s_dev
= s
->s_dev
;
2139 static int nfs_compare_super_address(struct nfs_server
*server1
,
2140 struct nfs_server
*server2
)
2142 struct sockaddr
*sap1
, *sap2
;
2144 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2145 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2147 if (sap1
->sa_family
!= sap2
->sa_family
)
2150 switch (sap1
->sa_family
) {
2152 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2153 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2154 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2156 if (sin1
->sin_port
!= sin2
->sin_port
)
2161 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2162 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2163 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2165 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2176 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2178 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2179 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2180 int mntflags
= sb_mntdata
->mntflags
;
2182 if (!nfs_compare_super_address(old
, server
))
2184 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2185 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2187 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2189 return nfs_compare_mount_options(sb
, server
, mntflags
);
2192 static int nfs_bdi_register(struct nfs_server
*server
)
2194 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2197 static int nfs_get_sb(struct file_system_type
*fs_type
,
2198 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2200 struct nfs_server
*server
= NULL
;
2201 struct super_block
*s
;
2202 struct nfs_parsed_mount_data
*data
;
2203 struct nfs_fh
*mntfh
;
2204 struct dentry
*mntroot
;
2205 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2206 struct nfs_sb_mountdata sb_mntdata
= {
2209 int error
= -ENOMEM
;
2211 data
= nfs_alloc_parsed_mount_data(3);
2212 mntfh
= nfs_alloc_fhandle();
2213 if (data
== NULL
|| mntfh
== NULL
)
2216 security_init_mnt_opts(&data
->lsm_opts
);
2218 /* Validate the mount data */
2219 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2223 #ifdef CONFIG_NFS_V4
2224 if (data
->version
== 4) {
2225 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2226 kfree(data
->client_address
);
2227 kfree(data
->nfs_server
.export_path
);
2230 #endif /* CONFIG_NFS_V4 */
2232 /* Get a volume representation */
2233 server
= nfs_create_server(data
, mntfh
);
2234 if (IS_ERR(server
)) {
2235 error
= PTR_ERR(server
);
2238 sb_mntdata
.server
= server
;
2240 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2241 compare_super
= NULL
;
2243 /* Get a superblock - note that we may end up sharing one that already exists */
2244 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2250 if (s
->s_fs_info
!= server
) {
2251 nfs_free_server(server
);
2254 error
= nfs_bdi_register(server
);
2256 goto error_splat_bdi
;
2260 /* initial superblock/root creation */
2261 nfs_fill_super(s
, data
);
2262 nfs_fscache_get_super_cookie(
2263 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2266 mntroot
= nfs_get_root(s
, mntfh
);
2267 if (IS_ERR(mntroot
)) {
2268 error
= PTR_ERR(mntroot
);
2269 goto error_splat_super
;
2272 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2274 goto error_splat_root
;
2276 s
->s_flags
|= MS_ACTIVE
;
2278 mnt
->mnt_root
= mntroot
;
2282 kfree(data
->nfs_server
.hostname
);
2283 kfree(data
->mount_server
.hostname
);
2284 kfree(data
->fscache_uniq
);
2285 security_free_mnt_opts(&data
->lsm_opts
);
2287 nfs_free_fhandle(mntfh
);
2292 nfs_free_server(server
);
2298 if (server
&& !s
->s_root
)
2299 bdi_unregister(&server
->backing_dev_info
);
2301 deactivate_locked_super(s
);
2306 * Ensure that we unregister the bdi before kill_anon_super
2307 * releases the device name
2309 static void nfs_put_super(struct super_block
*s
)
2311 struct nfs_server
*server
= NFS_SB(s
);
2313 bdi_unregister(&server
->backing_dev_info
);
2317 * Destroy an NFS2/3 superblock
2319 static void nfs_kill_super(struct super_block
*s
)
2321 struct nfs_server
*server
= NFS_SB(s
);
2324 nfs_fscache_release_super_cookie(s
);
2325 nfs_free_server(server
);
2329 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2331 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2332 const char *dev_name
, void *raw_data
,
2333 struct vfsmount
*mnt
)
2335 struct nfs_clone_mount
*data
= raw_data
;
2336 struct super_block
*s
;
2337 struct nfs_server
*server
;
2338 struct dentry
*mntroot
;
2339 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2340 struct nfs_sb_mountdata sb_mntdata
= {
2345 dprintk("--> nfs_xdev_get_sb()\n");
2347 /* create a new volume representation */
2348 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2349 if (IS_ERR(server
)) {
2350 error
= PTR_ERR(server
);
2351 goto out_err_noserver
;
2353 sb_mntdata
.server
= server
;
2355 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2356 compare_super
= NULL
;
2358 /* Get a superblock - note that we may end up sharing one that already exists */
2359 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2365 if (s
->s_fs_info
!= server
) {
2366 nfs_free_server(server
);
2369 error
= nfs_bdi_register(server
);
2371 goto error_splat_bdi
;
2375 /* initial superblock/root creation */
2376 nfs_clone_super(s
, data
->sb
);
2377 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2380 mntroot
= nfs_get_root(s
, data
->fh
);
2381 if (IS_ERR(mntroot
)) {
2382 error
= PTR_ERR(mntroot
);
2383 goto error_splat_super
;
2385 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2388 goto error_splat_super
;
2391 s
->s_flags
|= MS_ACTIVE
;
2393 mnt
->mnt_root
= mntroot
;
2395 /* clone any lsm security options from the parent to the new sb */
2396 security_sb_clone_mnt_opts(data
->sb
, s
);
2398 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2402 nfs_free_server(server
);
2404 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2408 if (server
&& !s
->s_root
)
2409 bdi_unregister(&server
->backing_dev_info
);
2411 deactivate_locked_super(s
);
2412 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2416 #ifdef CONFIG_NFS_V4
2419 * Finish setting up a cloned NFS4 superblock
2421 static void nfs4_clone_super(struct super_block
*sb
,
2422 const struct super_block
*old_sb
)
2424 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2425 sb
->s_blocksize
= old_sb
->s_blocksize
;
2426 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2427 sb
->s_time_gran
= 1;
2428 sb
->s_op
= old_sb
->s_op
;
2429 nfs_initialise_sb(sb
);
2433 * Set up an NFS4 superblock
2435 static void nfs4_fill_super(struct super_block
*sb
)
2437 sb
->s_time_gran
= 1;
2438 sb
->s_op
= &nfs4_sops
;
2439 nfs_initialise_sb(sb
);
2442 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2444 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2447 static int nfs4_validate_text_mount_data(void *options
,
2448 struct nfs_parsed_mount_data
*args
,
2449 const char *dev_name
)
2451 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2453 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2455 nfs_validate_transport_protocol(args
);
2457 nfs4_validate_mount_flags(args
);
2459 if (args
->version
!= 4) {
2461 "NFS4: Illegal mount version\n");
2465 if (args
->auth_flavor_len
> 1) {
2467 "NFS4: Too many RPC auth flavours specified\n");
2471 if (args
->client_address
== NULL
) {
2473 "NFS4: mount program didn't pass callback address\n");
2477 return nfs_parse_devname(dev_name
,
2478 &args
->nfs_server
.hostname
,
2480 &args
->nfs_server
.export_path
,
2485 * Validate NFSv4 mount options
2487 static int nfs4_validate_mount_data(void *options
,
2488 struct nfs_parsed_mount_data
*args
,
2489 const char *dev_name
)
2491 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2492 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2498 switch (data
->version
) {
2500 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2501 goto out_no_address
;
2502 if (data
->host_addrlen
== 0)
2503 goto out_no_address
;
2504 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2505 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2507 if (!nfs_verify_server_address(sap
))
2508 goto out_no_address
;
2510 if (data
->auth_flavourlen
) {
2511 if (data
->auth_flavourlen
> 1)
2512 goto out_inval_auth
;
2513 if (copy_from_user(&args
->auth_flavors
[0],
2514 data
->auth_flavours
,
2515 sizeof(args
->auth_flavors
[0])))
2519 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2522 args
->nfs_server
.hostname
= c
;
2524 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2527 args
->nfs_server
.export_path
= c
;
2528 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2530 c
= strndup_user(data
->client_addr
.data
, 16);
2533 args
->client_address
= c
;
2536 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2540 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2541 args
->rsize
= data
->rsize
;
2542 args
->wsize
= data
->wsize
;
2543 args
->timeo
= data
->timeo
;
2544 args
->retrans
= data
->retrans
;
2545 args
->acregmin
= data
->acregmin
;
2546 args
->acregmax
= data
->acregmax
;
2547 args
->acdirmin
= data
->acdirmin
;
2548 args
->acdirmax
= data
->acdirmax
;
2549 args
->nfs_server
.protocol
= data
->proto
;
2550 nfs_validate_transport_protocol(args
);
2554 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2557 if (!nfs_verify_server_address(sap
))
2560 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2566 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2570 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2571 data
->auth_flavourlen
);
2575 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2580 * Get the superblock for the NFS4 root partition
2582 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2583 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2585 struct nfs_parsed_mount_data
*data
= raw_data
;
2586 struct super_block
*s
;
2587 struct nfs_server
*server
;
2588 struct nfs_fh
*mntfh
;
2589 struct dentry
*mntroot
;
2590 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2591 struct nfs_sb_mountdata sb_mntdata
= {
2594 int error
= -ENOMEM
;
2596 mntfh
= nfs_alloc_fhandle();
2597 if (data
== NULL
|| mntfh
== NULL
)
2600 security_init_mnt_opts(&data
->lsm_opts
);
2602 /* Get a volume representation */
2603 server
= nfs4_create_server(data
, mntfh
);
2604 if (IS_ERR(server
)) {
2605 error
= PTR_ERR(server
);
2608 sb_mntdata
.server
= server
;
2610 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2611 compare_super
= NULL
;
2613 /* Get a superblock - note that we may end up sharing one that already exists */
2614 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2620 if (s
->s_fs_info
!= server
) {
2621 nfs_free_server(server
);
2624 error
= nfs_bdi_register(server
);
2626 goto error_splat_bdi
;
2630 /* initial superblock/root creation */
2632 nfs_fscache_get_super_cookie(
2633 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2636 mntroot
= nfs4_get_root(s
, mntfh
);
2637 if (IS_ERR(mntroot
)) {
2638 error
= PTR_ERR(mntroot
);
2639 goto error_splat_super
;
2642 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2644 goto error_splat_root
;
2646 s
->s_flags
|= MS_ACTIVE
;
2648 mnt
->mnt_root
= mntroot
;
2652 security_free_mnt_opts(&data
->lsm_opts
);
2654 nfs_free_fhandle(mntfh
);
2658 nfs_free_server(server
);
2664 if (server
&& !s
->s_root
)
2665 bdi_unregister(&server
->backing_dev_info
);
2667 deactivate_locked_super(s
);
2671 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2672 int flags
, void *data
, const char *hostname
)
2674 struct vfsmount
*root_mnt
;
2678 len
= strlen(hostname
) + 3;
2679 root_devname
= kmalloc(len
, GFP_KERNEL
);
2680 if (root_devname
== NULL
)
2681 return ERR_PTR(-ENOMEM
);
2682 snprintf(root_devname
, len
, "%s:/", hostname
);
2683 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2684 kfree(root_devname
);
2688 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2690 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2691 char *devname
, *tmp
;
2695 devname
= nfs_path(path
->mnt
->mnt_devname
,
2696 path
->mnt
->mnt_root
, path
->dentry
,
2698 if (IS_ERR(devname
))
2700 tmp
= kstrdup(devname
, GFP_KERNEL
);
2703 kfree(mnt
->mnt_devname
);
2704 mnt
->mnt_devname
= tmp
;
2706 free_page((unsigned long)page
);
2709 struct nfs_referral_count
{
2710 struct list_head list
;
2711 const struct task_struct
*task
;
2712 unsigned int referral_count
;
2715 static LIST_HEAD(nfs_referral_count_list
);
2716 static DEFINE_SPINLOCK(nfs_referral_count_list_lock
);
2718 static struct nfs_referral_count
*nfs_find_referral_count(void)
2720 struct nfs_referral_count
*p
;
2722 list_for_each_entry(p
, &nfs_referral_count_list
, list
) {
2723 if (p
->task
== current
)
2729 #define NFS_MAX_NESTED_REFERRALS 2
2731 static int nfs_referral_loop_protect(void)
2733 struct nfs_referral_count
*p
, *new;
2736 new = kmalloc(sizeof(*new), GFP_KERNEL
);
2739 new->task
= current
;
2740 new->referral_count
= 1;
2743 spin_lock(&nfs_referral_count_list_lock
);
2744 p
= nfs_find_referral_count();
2746 if (p
->referral_count
>= NFS_MAX_NESTED_REFERRALS
)
2749 p
->referral_count
++;
2751 list_add(&new->list
, &nfs_referral_count_list
);
2754 spin_unlock(&nfs_referral_count_list_lock
);
2760 static void nfs_referral_loop_unprotect(void)
2762 struct nfs_referral_count
*p
;
2764 spin_lock(&nfs_referral_count_list_lock
);
2765 p
= nfs_find_referral_count();
2766 p
->referral_count
--;
2767 if (p
->referral_count
== 0)
2771 spin_unlock(&nfs_referral_count_list_lock
);
2775 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2776 const char *export_path
, struct vfsmount
*mnt_target
)
2778 struct nameidata
*nd
= NULL
;
2779 struct mnt_namespace
*ns_private
;
2780 struct super_block
*s
;
2783 nd
= kmalloc(sizeof(*nd
), GFP_KERNEL
);
2787 ns_private
= create_mnt_ns(root_mnt
);
2788 ret
= PTR_ERR(ns_private
);
2789 if (IS_ERR(ns_private
))
2792 ret
= nfs_referral_loop_protect();
2794 goto out_put_mnt_ns
;
2796 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2797 export_path
, LOOKUP_FOLLOW
, nd
);
2799 nfs_referral_loop_unprotect();
2800 put_mnt_ns(ns_private
);
2805 s
= nd
->path
.mnt
->mnt_sb
;
2806 atomic_inc(&s
->s_active
);
2807 mnt_target
->mnt_sb
= s
;
2808 mnt_target
->mnt_root
= dget(nd
->path
.dentry
);
2810 /* Correct the device pathname */
2811 nfs_fix_devname(&nd
->path
, mnt_target
);
2813 path_put(&nd
->path
);
2815 down_write(&s
->s_umount
);
2818 put_mnt_ns(ns_private
);
2826 static int nfs4_try_mount(int flags
, const char *dev_name
,
2827 struct nfs_parsed_mount_data
*data
,
2828 struct vfsmount
*mnt
)
2831 struct vfsmount
*root_mnt
;
2834 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2836 export_path
= data
->nfs_server
.export_path
;
2837 data
->nfs_server
.export_path
= "/";
2838 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2839 data
->nfs_server
.hostname
);
2840 data
->nfs_server
.export_path
= export_path
;
2842 error
= PTR_ERR(root_mnt
);
2843 if (IS_ERR(root_mnt
))
2846 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2849 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2850 error
!= 0 ? " [error]" : "");
2855 * Get the superblock for an NFS4 mountpoint
2857 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2858 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2860 struct nfs_parsed_mount_data
*data
;
2861 int error
= -ENOMEM
;
2863 data
= nfs_alloc_parsed_mount_data(4);
2867 /* Validate the mount data */
2868 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2872 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2875 kfree(data
->client_address
);
2876 kfree(data
->nfs_server
.export_path
);
2877 kfree(data
->nfs_server
.hostname
);
2878 kfree(data
->fscache_uniq
);
2881 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2882 error
!= 0 ? " [error]" : "");
2886 static void nfs4_kill_super(struct super_block
*sb
)
2888 struct nfs_server
*server
= NFS_SB(sb
);
2890 dprintk("--> %s\n", __func__
);
2891 nfs_super_return_all_delegations(sb
);
2892 kill_anon_super(sb
);
2893 nfs_fscache_release_super_cookie(sb
);
2894 nfs_free_server(server
);
2895 dprintk("<-- %s\n", __func__
);
2899 * Clone an NFS4 server record on xdev traversal (FSID-change)
2901 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2902 const char *dev_name
, void *raw_data
,
2903 struct vfsmount
*mnt
)
2905 struct nfs_clone_mount
*data
= raw_data
;
2906 struct super_block
*s
;
2907 struct nfs_server
*server
;
2908 struct dentry
*mntroot
;
2909 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2910 struct nfs_sb_mountdata sb_mntdata
= {
2915 dprintk("--> nfs4_xdev_get_sb()\n");
2917 /* create a new volume representation */
2918 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2919 if (IS_ERR(server
)) {
2920 error
= PTR_ERR(server
);
2921 goto out_err_noserver
;
2923 sb_mntdata
.server
= server
;
2925 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2926 compare_super
= NULL
;
2928 /* Get a superblock - note that we may end up sharing one that already exists */
2929 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2935 if (s
->s_fs_info
!= server
) {
2936 nfs_free_server(server
);
2939 error
= nfs_bdi_register(server
);
2941 goto error_splat_bdi
;
2945 /* initial superblock/root creation */
2946 nfs4_clone_super(s
, data
->sb
);
2947 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2950 mntroot
= nfs4_get_root(s
, data
->fh
);
2951 if (IS_ERR(mntroot
)) {
2952 error
= PTR_ERR(mntroot
);
2953 goto error_splat_super
;
2955 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2958 goto error_splat_super
;
2961 s
->s_flags
|= MS_ACTIVE
;
2963 mnt
->mnt_root
= mntroot
;
2965 security_sb_clone_mnt_opts(data
->sb
, s
);
2967 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2971 nfs_free_server(server
);
2973 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2977 if (server
&& !s
->s_root
)
2978 bdi_unregister(&server
->backing_dev_info
);
2980 deactivate_locked_super(s
);
2981 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2985 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2986 int flags
, const char *dev_name
, void *raw_data
,
2987 struct vfsmount
*mnt
)
2989 struct nfs_clone_mount
*data
= raw_data
;
2990 struct super_block
*s
;
2991 struct nfs_server
*server
;
2992 struct dentry
*mntroot
;
2993 struct nfs_fh
*mntfh
;
2994 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2995 struct nfs_sb_mountdata sb_mntdata
= {
2998 int error
= -ENOMEM
;
3000 dprintk("--> nfs4_referral_get_sb()\n");
3002 mntfh
= nfs_alloc_fhandle();
3006 /* create a new volume representation */
3007 server
= nfs4_create_referral_server(data
, mntfh
);
3008 if (IS_ERR(server
)) {
3009 error
= PTR_ERR(server
);
3010 goto out_err_noserver
;
3012 sb_mntdata
.server
= server
;
3014 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
3015 compare_super
= NULL
;
3017 /* Get a superblock - note that we may end up sharing one that already exists */
3018 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
3024 if (s
->s_fs_info
!= server
) {
3025 nfs_free_server(server
);
3028 error
= nfs_bdi_register(server
);
3030 goto error_splat_bdi
;
3034 /* initial superblock/root creation */
3036 nfs_fscache_get_super_cookie(s
, NULL
, data
);
3039 mntroot
= nfs4_get_root(s
, mntfh
);
3040 if (IS_ERR(mntroot
)) {
3041 error
= PTR_ERR(mntroot
);
3042 goto error_splat_super
;
3044 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
3047 goto error_splat_super
;
3050 s
->s_flags
|= MS_ACTIVE
;
3052 mnt
->mnt_root
= mntroot
;
3054 security_sb_clone_mnt_opts(data
->sb
, s
);
3056 nfs_free_fhandle(mntfh
);
3057 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3061 nfs_free_server(server
);
3063 nfs_free_fhandle(mntfh
);
3065 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
3069 if (server
&& !s
->s_root
)
3070 bdi_unregister(&server
->backing_dev_info
);
3072 deactivate_locked_super(s
);
3073 nfs_free_fhandle(mntfh
);
3074 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
3079 * Create an NFS4 server record on referral traversal
3081 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
3082 int flags
, const char *dev_name
, void *raw_data
,
3083 struct vfsmount
*mnt
)
3085 struct nfs_clone_mount
*data
= raw_data
;
3087 struct vfsmount
*root_mnt
;
3090 dprintk("--> nfs4_referral_get_sb()\n");
3092 export_path
= data
->mnt_path
;
3093 data
->mnt_path
= "/";
3095 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
3096 flags
, data
, data
->hostname
);
3097 data
->mnt_path
= export_path
;
3099 error
= PTR_ERR(root_mnt
);
3100 if (IS_ERR(root_mnt
))
3103 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
3105 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
3106 error
!= 0 ? " [error]" : "");
3110 #endif /* CONFIG_NFS_V4 */