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
);
435 nfs_free_fattr(res
.fattr
);
439 buf
->f_type
= NFS_SUPER_MAGIC
;
442 * Current versions of glibc do not correctly handle the
443 * case where f_frsize != f_bsize. Eventually we want to
444 * report the value of wtmult in this field.
446 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
449 * On most *nix systems, f_blocks, f_bfree, and f_bavail
450 * are reported in units of f_frsize. Linux hasn't had
451 * an f_frsize field in its statfs struct until recently,
452 * thus historically Linux's sys_statfs reports these
453 * fields in units of f_bsize.
455 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
456 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
457 blockres
= (1 << blockbits
) - 1;
458 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
459 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
460 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
462 buf
->f_files
= res
.tfiles
;
463 buf
->f_ffree
= res
.afiles
;
465 buf
->f_namelen
= server
->namelen
;
470 dprintk("%s: statfs error = %d\n", __func__
, -error
);
475 * Map the security flavour number to a name
477 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
479 static const struct {
480 rpc_authflavor_t flavour
;
483 { RPC_AUTH_NULL
, "null" },
484 { RPC_AUTH_UNIX
, "sys" },
485 { RPC_AUTH_GSS_KRB5
, "krb5" },
486 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
487 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
488 { RPC_AUTH_GSS_LKEY
, "lkey" },
489 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
490 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
491 { RPC_AUTH_GSS_SPKM
, "spkm" },
492 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
493 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
494 { UINT_MAX
, "unknown" }
498 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
499 if (sec_flavours
[i
].flavour
== flavour
)
502 return sec_flavours
[i
].str
;
505 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
508 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
510 seq_printf(m
, ",mountproto=");
511 switch (sap
->sa_family
) {
513 switch (nfss
->mountd_protocol
) {
515 seq_printf(m
, RPCBIND_NETID_UDP
);
518 seq_printf(m
, RPCBIND_NETID_TCP
);
522 seq_printf(m
, "auto");
526 switch (nfss
->mountd_protocol
) {
528 seq_printf(m
, RPCBIND_NETID_UDP6
);
531 seq_printf(m
, RPCBIND_NETID_TCP6
);
535 seq_printf(m
, "auto");
540 seq_printf(m
, "auto");
544 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
547 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
549 if (nfss
->flags
& NFS_MOUNT_LEGACY_INTERFACE
)
552 switch (sap
->sa_family
) {
554 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
555 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
559 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
560 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
565 seq_printf(m
, ",mountaddr=unspecified");
568 if (nfss
->mountd_version
|| showdefaults
)
569 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
570 if (nfss
->mountd_port
|| showdefaults
)
571 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
573 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
577 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
580 struct nfs_client
*clp
= nfss
->nfs_client
;
582 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
583 seq_printf(m
, ",minorversion=%u", clp
->cl_minorversion
);
586 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
593 * Describe the mount options in force on this server representation
595 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
598 static const struct proc_nfs_info
{
603 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
604 { NFS_MOUNT_POSIX
, ",posix", "" },
605 { NFS_MOUNT_NOCTO
, ",nocto", "" },
606 { NFS_MOUNT_NOAC
, ",noac", "" },
607 { NFS_MOUNT_NONLM
, ",nolock", "" },
608 { NFS_MOUNT_NOACL
, ",noacl", "" },
609 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
610 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
611 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
614 const struct proc_nfs_info
*nfs_infop
;
615 struct nfs_client
*clp
= nfss
->nfs_client
;
616 u32 version
= clp
->rpc_ops
->version
;
618 seq_printf(m
, ",vers=%u", version
);
619 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
620 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
621 if (nfss
->bsize
!= 0)
622 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
623 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
624 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
625 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
626 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
627 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
628 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
629 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
630 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
631 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
632 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
633 if (nfss
->flags
& nfs_infop
->flag
)
634 seq_puts(m
, nfs_infop
->str
);
636 seq_puts(m
, nfs_infop
->nostr
);
638 seq_printf(m
, ",proto=%s",
639 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
641 if (nfss
->port
!= NFS_PORT
)
642 seq_printf(m
, ",port=%u", nfss
->port
);
645 seq_printf(m
, ",port=%u", nfss
->port
);
647 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
648 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
649 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
652 nfs_show_mountd_options(m
, nfss
, showdefaults
);
654 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
656 if (nfss
->options
& NFS_OPTION_FSCACHE
)
657 seq_printf(m
, ",fsc");
659 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONEG
) {
660 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONE
)
661 seq_printf(m
, ",lookupcache=none");
663 seq_printf(m
, ",lookupcache=pos");
668 * Describe the mount options on this VFS mountpoint
670 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
672 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
674 nfs_show_mount_options(m
, nfss
, 0);
676 seq_printf(m
, ",addr=%s",
677 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
684 * Present statistical information for this VFS mountpoint
686 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
689 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
690 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
691 struct nfs_iostats totals
= { };
693 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
696 * Display all mount option settings
698 seq_printf(m
, "\n\topts:\t");
699 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
700 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
701 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
702 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
703 nfs_show_mount_options(m
, nfss
, 1);
705 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
707 seq_printf(m
, "\n\tcaps:\t");
708 seq_printf(m
, "caps=0x%x", nfss
->caps
);
709 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
710 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
711 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
712 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
715 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
716 seq_printf(m
, "\n\tnfsv4:\t");
717 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
718 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
719 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
724 * Display security flavor in effect for this mount
726 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
728 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
731 * Display superblock I/O counters
733 for_each_possible_cpu(cpu
) {
734 struct nfs_iostats
*stats
;
737 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
739 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
740 totals
.events
[i
] += stats
->events
[i
];
741 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
742 totals
.bytes
[i
] += stats
->bytes
[i
];
743 #ifdef CONFIG_NFS_FSCACHE
744 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
745 totals
.fscache
[i
] += stats
->fscache
[i
];
751 seq_printf(m
, "\n\tevents:\t");
752 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
753 seq_printf(m
, "%lu ", totals
.events
[i
]);
754 seq_printf(m
, "\n\tbytes:\t");
755 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
756 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
757 #ifdef CONFIG_NFS_FSCACHE
758 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
759 seq_printf(m
, "\n\tfsc:\t");
760 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
761 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
766 rpc_print_iostats(m
, nfss
->client
);
772 * Begin unmount by attempting to remove all automounted mountpoints we added
773 * in response to xdev traversals and referrals
775 static void nfs_umount_begin(struct super_block
*sb
)
777 struct nfs_server
*server
;
778 struct rpc_clnt
*rpc
;
781 /* -EIO all pending I/O */
782 rpc
= server
->client_acl
;
784 rpc_killall_tasks(rpc
);
785 rpc
= server
->client
;
787 rpc_killall_tasks(rpc
);
790 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
792 struct nfs_parsed_mount_data
*data
;
794 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
796 data
->acregmin
= NFS_DEF_ACREGMIN
;
797 data
->acregmax
= NFS_DEF_ACREGMAX
;
798 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
799 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
800 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
801 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
802 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
803 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
804 data
->auth_flavor_len
= 1;
805 data
->version
= version
;
806 data
->minorversion
= 0;
812 * Sanity-check a server address provided by the mount command.
814 * Address family must be initialized, and address must not be
815 * the ANY address for that family.
817 static int nfs_verify_server_address(struct sockaddr
*addr
)
819 switch (addr
->sa_family
) {
821 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
822 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
825 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
826 return !ipv6_addr_any(sa
);
830 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
835 * Select between a default port value and a user-specified port value.
836 * If a zero value is set, then autobind will be used.
838 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
839 const unsigned short default_port
)
841 if (*port
== NFS_UNSPEC_PORT
)
842 *port
= default_port
;
844 rpc_set_port(sap
, *port
);
848 * Sanity check the NFS transport protocol.
851 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
853 switch (mnt
->nfs_server
.protocol
) {
854 case XPRT_TRANSPORT_UDP
:
855 case XPRT_TRANSPORT_TCP
:
856 case XPRT_TRANSPORT_RDMA
:
859 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
864 * For text based NFSv2/v3 mounts, the mount protocol transport default
865 * settings should depend upon the specified NFS transport.
867 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
869 nfs_validate_transport_protocol(mnt
);
871 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
872 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
874 switch (mnt
->nfs_server
.protocol
) {
875 case XPRT_TRANSPORT_UDP
:
876 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
878 case XPRT_TRANSPORT_TCP
:
879 case XPRT_TRANSPORT_RDMA
:
880 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
885 * Parse the value of the 'sec=' option.
887 static int nfs_parse_security_flavors(char *value
,
888 struct nfs_parsed_mount_data
*mnt
)
890 substring_t args
[MAX_OPT_ARGS
];
892 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
894 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
896 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
899 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
902 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
905 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
908 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
911 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
914 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
917 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
920 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
923 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
926 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
932 mnt
->auth_flavor_len
= 1;
937 * Error-check and convert a string of mount options from user space into
938 * a data structure. The whole mount string is processed; bad options are
939 * skipped as they are encountered. If there were no errors, return 1;
940 * otherwise return 0 (zero).
942 static int nfs_parse_mount_options(char *raw
,
943 struct nfs_parsed_mount_data
*mnt
)
945 char *p
, *string
, *secdata
;
946 int rc
, sloppy
= 0, invalid_option
= 0;
947 unsigned short protofamily
= AF_UNSPEC
;
948 unsigned short mountfamily
= AF_UNSPEC
;
951 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
954 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
956 secdata
= alloc_secdata();
960 rc
= security_sb_copy_data(raw
, secdata
);
962 goto out_security_failure
;
964 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
966 goto out_security_failure
;
968 free_secdata(secdata
);
970 while ((p
= strsep(&raw
, ",")) != NULL
) {
971 substring_t args
[MAX_OPT_ARGS
];
972 unsigned long option
;
978 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
980 token
= match_token(p
, nfs_mount_option_tokens
, args
);
984 * boolean options: foo/nofoo
987 mnt
->flags
|= NFS_MOUNT_SOFT
;
990 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
993 mnt
->flags
|= NFS_MOUNT_POSIX
;
996 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
999 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1002 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1005 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1008 mnt
->flags
|= NFS_MOUNT_NOAC
;
1011 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1014 mnt
->flags
|= NFS_MOUNT_NONLM
;
1017 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1021 mnt
->flags
|= NFS_MOUNT_VER3
;
1024 #ifdef CONFIG_NFS_V4
1026 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1031 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1032 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1035 mnt
->flags
|= NFS_MOUNT_TCP
;
1036 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1039 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1040 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1041 xprt_load_transport(p
);
1044 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1047 mnt
->flags
|= NFS_MOUNT_NOACL
;
1050 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1052 case Opt_nordirplus
:
1053 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1055 case Opt_sharecache
:
1056 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1058 case Opt_nosharecache
:
1059 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1062 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1064 case Opt_noresvport
:
1065 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1068 mnt
->options
|= NFS_OPTION_FSCACHE
;
1069 kfree(mnt
->fscache_uniq
);
1070 mnt
->fscache_uniq
= NULL
;
1073 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1074 kfree(mnt
->fscache_uniq
);
1075 mnt
->fscache_uniq
= NULL
;
1079 * options that take numeric values
1082 string
= match_strdup(args
);
1085 rc
= strict_strtoul(string
, 10, &option
);
1087 if (rc
!= 0 || option
> USHRT_MAX
)
1088 goto out_invalid_value
;
1089 mnt
->nfs_server
.port
= option
;
1092 string
= match_strdup(args
);
1095 rc
= strict_strtoul(string
, 10, &option
);
1098 goto out_invalid_value
;
1099 mnt
->rsize
= option
;
1102 string
= match_strdup(args
);
1105 rc
= strict_strtoul(string
, 10, &option
);
1108 goto out_invalid_value
;
1109 mnt
->wsize
= option
;
1112 string
= match_strdup(args
);
1115 rc
= strict_strtoul(string
, 10, &option
);
1118 goto out_invalid_value
;
1119 mnt
->bsize
= option
;
1122 string
= match_strdup(args
);
1125 rc
= strict_strtoul(string
, 10, &option
);
1127 if (rc
!= 0 || option
== 0)
1128 goto out_invalid_value
;
1129 mnt
->timeo
= option
;
1132 string
= match_strdup(args
);
1135 rc
= strict_strtoul(string
, 10, &option
);
1137 if (rc
!= 0 || option
== 0)
1138 goto out_invalid_value
;
1139 mnt
->retrans
= option
;
1142 string
= match_strdup(args
);
1145 rc
= strict_strtoul(string
, 10, &option
);
1148 goto out_invalid_value
;
1149 mnt
->acregmin
= option
;
1152 string
= match_strdup(args
);
1155 rc
= strict_strtoul(string
, 10, &option
);
1158 goto out_invalid_value
;
1159 mnt
->acregmax
= option
;
1162 string
= match_strdup(args
);
1165 rc
= strict_strtoul(string
, 10, &option
);
1168 goto out_invalid_value
;
1169 mnt
->acdirmin
= option
;
1172 string
= match_strdup(args
);
1175 rc
= strict_strtoul(string
, 10, &option
);
1178 goto out_invalid_value
;
1179 mnt
->acdirmax
= option
;
1182 string
= match_strdup(args
);
1185 rc
= strict_strtoul(string
, 10, &option
);
1188 goto out_invalid_value
;
1189 mnt
->acregmin
= mnt
->acregmax
=
1190 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1193 string
= match_strdup(args
);
1196 rc
= strict_strtoul(string
, 10, &option
);
1199 goto out_invalid_value
;
1200 mnt
->namlen
= option
;
1203 string
= match_strdup(args
);
1206 rc
= strict_strtoul(string
, 10, &option
);
1208 if (rc
!= 0 || option
> USHRT_MAX
)
1209 goto out_invalid_value
;
1210 mnt
->mount_server
.port
= option
;
1213 string
= match_strdup(args
);
1216 rc
= strict_strtoul(string
, 10, &option
);
1219 option
< NFS_MNT_VERSION
||
1220 option
> NFS_MNT3_VERSION
)
1221 goto out_invalid_value
;
1222 mnt
->mount_server
.version
= option
;
1225 string
= match_strdup(args
);
1228 rc
= strict_strtoul(string
, 10, &option
);
1231 goto out_invalid_value
;
1234 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1238 mnt
->flags
|= NFS_MOUNT_VER3
;
1241 #ifdef CONFIG_NFS_V4
1243 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1248 goto out_invalid_value
;
1251 case Opt_minorversion
:
1252 string
= match_strdup(args
);
1255 rc
= strict_strtoul(string
, 10, &option
);
1258 goto out_invalid_value
;
1259 if (option
> NFS4_MAX_MINOR_VERSION
)
1260 goto out_invalid_value
;
1261 mnt
->minorversion
= option
;
1265 * options that take text values
1268 string
= match_strdup(args
);
1271 rc
= nfs_parse_security_flavors(string
, mnt
);
1274 dfprintk(MOUNT
, "NFS: unrecognized "
1275 "security flavor\n");
1280 string
= match_strdup(args
);
1283 token
= match_token(string
,
1284 nfs_xprt_protocol_tokens
, args
);
1286 protofamily
= AF_INET
;
1289 protofamily
= AF_INET6
;
1291 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1292 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1296 protofamily
= AF_INET6
;
1298 mnt
->flags
|= NFS_MOUNT_TCP
;
1299 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1303 /* vector side protocols to TCP */
1304 mnt
->flags
|= NFS_MOUNT_TCP
;
1305 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1306 xprt_load_transport(string
);
1310 dfprintk(MOUNT
, "NFS: unrecognized "
1311 "transport protocol\n");
1316 case Opt_mountproto
:
1317 string
= match_strdup(args
);
1320 token
= match_token(string
,
1321 nfs_xprt_protocol_tokens
, args
);
1324 mountfamily
= AF_INET
;
1327 mountfamily
= AF_INET6
;
1329 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1332 mountfamily
= AF_INET6
;
1334 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1336 case Opt_xprt_rdma
: /* not used for side protocols */
1338 dfprintk(MOUNT
, "NFS: unrecognized "
1339 "transport protocol\n");
1344 string
= match_strdup(args
);
1347 mnt
->nfs_server
.addrlen
=
1348 rpc_pton(string
, strlen(string
),
1350 &mnt
->nfs_server
.address
,
1351 sizeof(mnt
->nfs_server
.address
));
1353 if (mnt
->nfs_server
.addrlen
== 0)
1354 goto out_invalid_address
;
1356 case Opt_clientaddr
:
1357 string
= match_strdup(args
);
1360 kfree(mnt
->client_address
);
1361 mnt
->client_address
= string
;
1364 string
= match_strdup(args
);
1367 kfree(mnt
->mount_server
.hostname
);
1368 mnt
->mount_server
.hostname
= string
;
1371 string
= match_strdup(args
);
1374 mnt
->mount_server
.addrlen
=
1375 rpc_pton(string
, strlen(string
),
1377 &mnt
->mount_server
.address
,
1378 sizeof(mnt
->mount_server
.address
));
1380 if (mnt
->mount_server
.addrlen
== 0)
1381 goto out_invalid_address
;
1383 case Opt_lookupcache
:
1384 string
= match_strdup(args
);
1387 token
= match_token(string
,
1388 nfs_lookupcache_tokens
, args
);
1391 case Opt_lookupcache_all
:
1392 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1394 case Opt_lookupcache_positive
:
1395 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1396 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1398 case Opt_lookupcache_none
:
1399 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1402 dfprintk(MOUNT
, "NFS: invalid "
1403 "lookupcache argument\n");
1407 case Opt_fscache_uniq
:
1408 string
= match_strdup(args
);
1411 kfree(mnt
->fscache_uniq
);
1412 mnt
->fscache_uniq
= string
;
1413 mnt
->options
|= NFS_OPTION_FSCACHE
;
1421 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1424 case Opt_deprecated
:
1425 dfprintk(MOUNT
, "NFS: ignoring mount option "
1431 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1436 if (!sloppy
&& invalid_option
)
1440 * verify that any proto=/mountproto= options match the address
1441 * familiies in the addr=/mountaddr= options.
1443 if (protofamily
!= AF_UNSPEC
&&
1444 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1445 goto out_proto_mismatch
;
1447 if (mountfamily
!= AF_UNSPEC
) {
1448 if (mnt
->mount_server
.addrlen
) {
1449 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1450 goto out_mountproto_mismatch
;
1452 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1453 goto out_mountproto_mismatch
;
1459 out_mountproto_mismatch
:
1460 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1464 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1466 out_invalid_address
:
1467 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1470 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1473 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1475 out_security_failure
:
1476 free_secdata(secdata
);
1477 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1482 * Match the requested auth flavors with the list returned by
1483 * the server. Returns zero and sets the mount's authentication
1484 * flavor on success; returns -EACCES if server does not support
1485 * the requested flavor.
1487 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1488 struct nfs_mount_request
*request
)
1490 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1493 * Certain releases of Linux's mountd return an empty
1494 * flavor list. To prevent behavioral regression with
1495 * these servers (ie. rejecting mounts that used to
1496 * succeed), revert to pre-2.6.32 behavior (no checking)
1497 * if the returned flavor list is empty.
1499 if (server_authlist_len
== 0)
1503 * We avoid sophisticated negotiating here, as there are
1504 * plenty of cases where we can get it wrong, providing
1505 * either too little or too much security.
1507 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1508 * flavor listed first. However, some servers list
1509 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1510 * preferred default, in args->auth_flavors[0] if user
1511 * didn't specify sec= mount option.
1513 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1514 for (j
= 0; j
< server_authlist_len
; j
++)
1515 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1516 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1517 request
->auth_flavs
[j
]);
1518 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1522 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1523 nfs_umount(request
);
1528 * Use the remote server's MOUNT service to request the NFS file handle
1529 * corresponding to the provided path.
1531 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1532 struct nfs_fh
*root_fh
)
1534 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1535 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1536 struct nfs_mount_request request
= {
1537 .sap
= (struct sockaddr
*)
1538 &args
->mount_server
.address
,
1539 .dirpath
= args
->nfs_server
.export_path
,
1540 .protocol
= args
->mount_server
.protocol
,
1542 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1543 .auth_flav_len
= &server_authlist_len
,
1544 .auth_flavs
= server_authlist
,
1548 if (args
->mount_server
.version
== 0) {
1549 switch (args
->version
) {
1551 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1554 args
->mount_server
.version
= NFS_MNT_VERSION
;
1557 request
.version
= args
->mount_server
.version
;
1559 if (args
->mount_server
.hostname
)
1560 request
.hostname
= args
->mount_server
.hostname
;
1562 request
.hostname
= args
->nfs_server
.hostname
;
1565 * Construct the mount server's address.
1567 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1568 memcpy(request
.sap
, &args
->nfs_server
.address
,
1569 args
->nfs_server
.addrlen
);
1570 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1572 request
.salen
= args
->mount_server
.addrlen
;
1573 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1576 * Now ask the mount server to map our export path
1579 status
= nfs_mount(&request
);
1581 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1582 request
.hostname
, status
);
1587 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1589 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1591 return nfs_walk_authlist(args
, &request
);
1594 static int nfs_parse_simple_hostname(const char *dev_name
,
1595 char **hostname
, size_t maxnamlen
,
1596 char **export_path
, size_t maxpathlen
)
1599 char *colon
, *comma
;
1601 colon
= strchr(dev_name
, ':');
1603 goto out_bad_devname
;
1605 len
= colon
- dev_name
;
1606 if (len
> maxnamlen
)
1609 /* N.B. caller will free nfs_server.hostname in all cases */
1610 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1614 /* kill possible hostname list: not supported */
1615 comma
= strchr(*hostname
, ',');
1616 if (comma
!= NULL
) {
1617 if (comma
== *hostname
)
1618 goto out_bad_devname
;
1623 len
= strlen(colon
);
1624 if (len
> maxpathlen
)
1626 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1630 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1634 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1638 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1642 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1643 return -ENAMETOOLONG
;
1646 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1647 return -ENAMETOOLONG
;
1651 * Hostname has square brackets around it because it contains one or
1652 * more colons. We look for the first closing square bracket, and a
1653 * colon must follow it.
1655 static int nfs_parse_protected_hostname(const char *dev_name
,
1656 char **hostname
, size_t maxnamlen
,
1657 char **export_path
, size_t maxpathlen
)
1662 start
= (char *)(dev_name
+ 1);
1664 end
= strchr(start
, ']');
1666 goto out_bad_devname
;
1667 if (*(end
+ 1) != ':')
1668 goto out_bad_devname
;
1671 if (len
> maxnamlen
)
1674 /* N.B. caller will free nfs_server.hostname in all cases */
1675 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1676 if (*hostname
== NULL
)
1681 if (len
> maxpathlen
)
1683 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1690 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1694 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1698 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1699 return -ENAMETOOLONG
;
1702 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1703 return -ENAMETOOLONG
;
1707 * Split "dev_name" into "hostname:export_path".
1709 * The leftmost colon demarks the split between the server's hostname
1710 * and the export path. If the hostname starts with a left square
1711 * bracket, then it may contain colons.
1713 * Note: caller frees hostname and export path, even on error.
1715 static int nfs_parse_devname(const char *dev_name
,
1716 char **hostname
, size_t maxnamlen
,
1717 char **export_path
, size_t maxpathlen
)
1719 if (*dev_name
== '[')
1720 return nfs_parse_protected_hostname(dev_name
,
1721 hostname
, maxnamlen
,
1722 export_path
, maxpathlen
);
1724 return nfs_parse_simple_hostname(dev_name
,
1725 hostname
, maxnamlen
,
1726 export_path
, maxpathlen
);
1730 * Validate the NFS2/NFS3 mount data
1731 * - fills in the mount root filehandle
1733 * For option strings, user space handles the following behaviors:
1735 * + DNS: mapping server host name to IP address ("addr=" option)
1737 * + failure mode: how to behave if a mount request can't be handled
1738 * immediately ("fg/bg" option)
1740 * + retry: how often to retry a mount request ("retry=" option)
1742 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1743 * mountproto=tcp after mountproto=udp, and so on
1745 static int nfs_validate_mount_data(void *options
,
1746 struct nfs_parsed_mount_data
*args
,
1747 struct nfs_fh
*mntfh
,
1748 const char *dev_name
)
1750 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1751 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1756 switch (data
->version
) {
1762 if (data
->flags
& NFS_MOUNT_VER3
)
1764 data
->root
.size
= NFS2_FHSIZE
;
1765 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1767 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1770 memset(data
->context
, 0, sizeof(data
->context
));
1772 if (data
->flags
& NFS_MOUNT_VER3
) {
1773 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1774 goto out_invalid_fh
;
1775 mntfh
->size
= data
->root
.size
;
1778 mntfh
->size
= NFS2_FHSIZE
;
1783 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1784 if (mntfh
->size
< sizeof(mntfh
->data
))
1785 memset(mntfh
->data
+ mntfh
->size
, 0,
1786 sizeof(mntfh
->data
) - mntfh
->size
);
1789 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1792 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1793 args
->flags
|= NFS_MOUNT_LEGACY_INTERFACE
;
1794 args
->rsize
= data
->rsize
;
1795 args
->wsize
= data
->wsize
;
1796 args
->timeo
= data
->timeo
;
1797 args
->retrans
= data
->retrans
;
1798 args
->acregmin
= data
->acregmin
;
1799 args
->acregmax
= data
->acregmax
;
1800 args
->acdirmin
= data
->acdirmin
;
1801 args
->acdirmax
= data
->acdirmax
;
1803 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1804 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1805 if (!nfs_verify_server_address(sap
))
1806 goto out_no_address
;
1808 if (!(data
->flags
& NFS_MOUNT_TCP
))
1809 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1810 /* N.B. caller will free nfs_server.hostname in all cases */
1811 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1812 args
->namlen
= data
->namlen
;
1813 args
->bsize
= data
->bsize
;
1815 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1816 args
->auth_flavors
[0] = data
->pseudoflavor
;
1817 if (!args
->nfs_server
.hostname
)
1821 * The legacy version 6 binary mount data from userspace has a
1822 * field used only to transport selinux information into the
1823 * the kernel. To continue to support that functionality we
1824 * have a touch of selinux knowledge here in the NFS code. The
1825 * userspace code converted context=blah to just blah so we are
1826 * converting back to the full string selinux understands.
1828 if (data
->context
[0]){
1829 #ifdef CONFIG_SECURITY_SELINUX
1831 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1834 strcpy(opts_str
, "context=");
1835 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1836 strcat(opts_str
, &data
->context
[0]);
1837 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1850 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1853 if (!nfs_verify_server_address(sap
))
1854 goto out_no_address
;
1856 if (args
->version
== 4)
1857 #ifdef CONFIG_NFS_V4
1858 return nfs4_validate_text_mount_data(options
,
1861 goto out_v4_not_compiled
;
1864 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1866 nfs_set_mount_transport_protocol(args
);
1868 status
= nfs_parse_devname(dev_name
,
1869 &args
->nfs_server
.hostname
,
1871 &args
->nfs_server
.export_path
,
1874 status
= nfs_try_mount(args
, mntfh
);
1876 kfree(args
->nfs_server
.export_path
);
1877 args
->nfs_server
.export_path
= NULL
;
1886 #ifndef CONFIG_NFS_V3
1887 if (args
->version
== 3)
1888 goto out_v3_not_compiled
;
1889 #endif /* !CONFIG_NFS_V3 */
1894 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1898 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1903 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1906 #ifndef CONFIG_NFS_V3
1907 out_v3_not_compiled
:
1908 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1909 return -EPROTONOSUPPORT
;
1910 #endif /* !CONFIG_NFS_V3 */
1912 #ifndef CONFIG_NFS_V4
1913 out_v4_not_compiled
:
1914 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1915 return -EPROTONOSUPPORT
;
1916 #endif /* !CONFIG_NFS_V4 */
1919 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1923 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1927 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1932 nfs_compare_remount_data(struct nfs_server
*nfss
,
1933 struct nfs_parsed_mount_data
*data
)
1935 if (data
->flags
!= nfss
->flags
||
1936 data
->rsize
!= nfss
->rsize
||
1937 data
->wsize
!= nfss
->wsize
||
1938 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1939 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1940 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1941 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1942 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1943 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1944 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1945 data
->nfs_server
.port
!= nfss
->port
||
1946 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1947 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
1948 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
1955 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1958 struct nfs_server
*nfss
= sb
->s_fs_info
;
1959 struct nfs_parsed_mount_data
*data
;
1960 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1961 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1962 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1965 * Userspace mount programs that send binary options generally send
1966 * them populated with default values. We have no way to know which
1967 * ones were explicitly specified. Fall back to legacy behavior and
1968 * just return success.
1970 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1971 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1972 options
->version
<= 6))))
1975 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1979 /* fill out struct with values from existing mount */
1980 data
->flags
= nfss
->flags
;
1981 data
->rsize
= nfss
->rsize
;
1982 data
->wsize
= nfss
->wsize
;
1983 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1984 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1985 data
->acregmin
= nfss
->acregmin
/ HZ
;
1986 data
->acregmax
= nfss
->acregmax
/ HZ
;
1987 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1988 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1989 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1990 data
->nfs_server
.port
= nfss
->port
;
1991 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1992 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1993 data
->nfs_server
.addrlen
);
1995 /* overwrite those values with any that were specified */
1996 error
= nfs_parse_mount_options((char *)options
, data
);
2000 /* compare new mount options with old ones */
2001 error
= nfs_compare_remount_data(nfss
, data
);
2008 * Initialise the common bits of the superblock
2010 static inline void nfs_initialise_sb(struct super_block
*sb
)
2012 struct nfs_server
*server
= NFS_SB(sb
);
2014 sb
->s_magic
= NFS_SUPER_MAGIC
;
2016 /* We probably want something more informative here */
2017 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
2018 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
2020 if (sb
->s_blocksize
== 0)
2021 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
2022 &sb
->s_blocksize_bits
);
2024 if (server
->flags
& NFS_MOUNT_NOAC
)
2025 sb
->s_flags
|= MS_SYNCHRONOUS
;
2027 sb
->s_bdi
= &server
->backing_dev_info
;
2029 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2033 * Finish setting up an NFS2/3 superblock
2035 static void nfs_fill_super(struct super_block
*sb
,
2036 struct nfs_parsed_mount_data
*data
)
2038 struct nfs_server
*server
= NFS_SB(sb
);
2040 sb
->s_blocksize_bits
= 0;
2041 sb
->s_blocksize
= 0;
2043 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2045 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2046 /* The VFS shouldn't apply the umask to mode bits. We will do
2047 * so ourselves when necessary.
2049 sb
->s_flags
|= MS_POSIXACL
;
2050 sb
->s_time_gran
= 1;
2053 sb
->s_op
= &nfs_sops
;
2054 nfs_initialise_sb(sb
);
2058 * Finish setting up a cloned NFS2/3 superblock
2060 static void nfs_clone_super(struct super_block
*sb
,
2061 const struct super_block
*old_sb
)
2063 struct nfs_server
*server
= NFS_SB(sb
);
2065 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2066 sb
->s_blocksize
= old_sb
->s_blocksize
;
2067 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2069 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2070 /* The VFS shouldn't apply the umask to mode bits. We will do
2071 * so ourselves when necessary.
2073 sb
->s_flags
|= MS_POSIXACL
;
2074 sb
->s_time_gran
= 1;
2077 sb
->s_op
= old_sb
->s_op
;
2078 nfs_initialise_sb(sb
);
2081 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2083 const struct nfs_server
*a
= s
->s_fs_info
;
2084 const struct rpc_clnt
*clnt_a
= a
->client
;
2085 const struct rpc_clnt
*clnt_b
= b
->client
;
2087 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2089 if (a
->nfs_client
!= b
->nfs_client
)
2091 if (a
->flags
!= b
->flags
)
2093 if (a
->wsize
!= b
->wsize
)
2095 if (a
->rsize
!= b
->rsize
)
2097 if (a
->acregmin
!= b
->acregmin
)
2099 if (a
->acregmax
!= b
->acregmax
)
2101 if (a
->acdirmin
!= b
->acdirmin
)
2103 if (a
->acdirmax
!= b
->acdirmax
)
2105 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2112 struct nfs_sb_mountdata
{
2113 struct nfs_server
*server
;
2117 static int nfs_set_super(struct super_block
*s
, void *data
)
2119 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2120 struct nfs_server
*server
= sb_mntdata
->server
;
2123 s
->s_flags
= sb_mntdata
->mntflags
;
2124 s
->s_fs_info
= server
;
2125 ret
= set_anon_super(s
, server
);
2127 server
->s_dev
= s
->s_dev
;
2131 static int nfs_compare_super_address(struct nfs_server
*server1
,
2132 struct nfs_server
*server2
)
2134 struct sockaddr
*sap1
, *sap2
;
2136 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2137 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2139 if (sap1
->sa_family
!= sap2
->sa_family
)
2142 switch (sap1
->sa_family
) {
2144 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2145 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2146 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2148 if (sin1
->sin_port
!= sin2
->sin_port
)
2153 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2154 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2155 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2157 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2168 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2170 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2171 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2172 int mntflags
= sb_mntdata
->mntflags
;
2174 if (!nfs_compare_super_address(old
, server
))
2176 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2177 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2179 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2181 return nfs_compare_mount_options(sb
, server
, mntflags
);
2184 static int nfs_bdi_register(struct nfs_server
*server
)
2186 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2189 static int nfs_get_sb(struct file_system_type
*fs_type
,
2190 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2192 struct nfs_server
*server
= NULL
;
2193 struct super_block
*s
;
2194 struct nfs_parsed_mount_data
*data
;
2195 struct nfs_fh
*mntfh
;
2196 struct dentry
*mntroot
;
2197 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2198 struct nfs_sb_mountdata sb_mntdata
= {
2201 int error
= -ENOMEM
;
2203 data
= nfs_alloc_parsed_mount_data(3);
2204 mntfh
= nfs_alloc_fhandle();
2205 if (data
== NULL
|| mntfh
== NULL
)
2208 security_init_mnt_opts(&data
->lsm_opts
);
2210 /* Validate the mount data */
2211 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2215 #ifdef CONFIG_NFS_V4
2216 if (data
->version
== 4) {
2217 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2218 kfree(data
->client_address
);
2219 kfree(data
->nfs_server
.export_path
);
2222 #endif /* CONFIG_NFS_V4 */
2224 /* Get a volume representation */
2225 server
= nfs_create_server(data
, mntfh
);
2226 if (IS_ERR(server
)) {
2227 error
= PTR_ERR(server
);
2230 sb_mntdata
.server
= server
;
2232 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2233 compare_super
= NULL
;
2235 /* Get a superblock - note that we may end up sharing one that already exists */
2236 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2242 if (s
->s_fs_info
!= server
) {
2243 nfs_free_server(server
);
2246 error
= nfs_bdi_register(server
);
2248 goto error_splat_bdi
;
2252 /* initial superblock/root creation */
2253 nfs_fill_super(s
, data
);
2254 nfs_fscache_get_super_cookie(
2255 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2258 mntroot
= nfs_get_root(s
, mntfh
);
2259 if (IS_ERR(mntroot
)) {
2260 error
= PTR_ERR(mntroot
);
2261 goto error_splat_super
;
2264 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2266 goto error_splat_root
;
2268 s
->s_flags
|= MS_ACTIVE
;
2270 mnt
->mnt_root
= mntroot
;
2274 kfree(data
->nfs_server
.hostname
);
2275 kfree(data
->mount_server
.hostname
);
2276 kfree(data
->fscache_uniq
);
2277 security_free_mnt_opts(&data
->lsm_opts
);
2279 nfs_free_fhandle(mntfh
);
2284 nfs_free_server(server
);
2290 if (server
&& !s
->s_root
)
2291 bdi_unregister(&server
->backing_dev_info
);
2293 deactivate_locked_super(s
);
2298 * Ensure that we unregister the bdi before kill_anon_super
2299 * releases the device name
2301 static void nfs_put_super(struct super_block
*s
)
2303 struct nfs_server
*server
= NFS_SB(s
);
2305 bdi_unregister(&server
->backing_dev_info
);
2309 * Destroy an NFS2/3 superblock
2311 static void nfs_kill_super(struct super_block
*s
)
2313 struct nfs_server
*server
= NFS_SB(s
);
2316 nfs_fscache_release_super_cookie(s
);
2317 nfs_free_server(server
);
2321 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2323 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2324 const char *dev_name
, void *raw_data
,
2325 struct vfsmount
*mnt
)
2327 struct nfs_clone_mount
*data
= raw_data
;
2328 struct super_block
*s
;
2329 struct nfs_server
*server
;
2330 struct dentry
*mntroot
;
2331 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2332 struct nfs_sb_mountdata sb_mntdata
= {
2337 dprintk("--> nfs_xdev_get_sb()\n");
2339 /* create a new volume representation */
2340 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2341 if (IS_ERR(server
)) {
2342 error
= PTR_ERR(server
);
2343 goto out_err_noserver
;
2345 sb_mntdata
.server
= server
;
2347 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2348 compare_super
= NULL
;
2350 /* Get a superblock - note that we may end up sharing one that already exists */
2351 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2357 if (s
->s_fs_info
!= server
) {
2358 nfs_free_server(server
);
2361 error
= nfs_bdi_register(server
);
2363 goto error_splat_bdi
;
2367 /* initial superblock/root creation */
2368 nfs_clone_super(s
, data
->sb
);
2369 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2372 mntroot
= nfs_get_root(s
, data
->fh
);
2373 if (IS_ERR(mntroot
)) {
2374 error
= PTR_ERR(mntroot
);
2375 goto error_splat_super
;
2377 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2380 goto error_splat_super
;
2383 s
->s_flags
|= MS_ACTIVE
;
2385 mnt
->mnt_root
= mntroot
;
2387 /* clone any lsm security options from the parent to the new sb */
2388 security_sb_clone_mnt_opts(data
->sb
, s
);
2390 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2394 nfs_free_server(server
);
2396 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2400 if (server
&& !s
->s_root
)
2401 bdi_unregister(&server
->backing_dev_info
);
2403 deactivate_locked_super(s
);
2404 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2408 #ifdef CONFIG_NFS_V4
2411 * Finish setting up a cloned NFS4 superblock
2413 static void nfs4_clone_super(struct super_block
*sb
,
2414 const struct super_block
*old_sb
)
2416 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2417 sb
->s_blocksize
= old_sb
->s_blocksize
;
2418 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2419 sb
->s_time_gran
= 1;
2420 sb
->s_op
= old_sb
->s_op
;
2421 nfs_initialise_sb(sb
);
2425 * Set up an NFS4 superblock
2427 static void nfs4_fill_super(struct super_block
*sb
)
2429 sb
->s_time_gran
= 1;
2430 sb
->s_op
= &nfs4_sops
;
2431 nfs_initialise_sb(sb
);
2434 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2436 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2439 static int nfs4_validate_text_mount_data(void *options
,
2440 struct nfs_parsed_mount_data
*args
,
2441 const char *dev_name
)
2443 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2445 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2447 nfs_validate_transport_protocol(args
);
2449 nfs4_validate_mount_flags(args
);
2451 if (args
->version
!= 4) {
2453 "NFS4: Illegal mount version\n");
2457 if (args
->auth_flavor_len
> 1) {
2459 "NFS4: Too many RPC auth flavours specified\n");
2463 if (args
->client_address
== NULL
) {
2465 "NFS4: mount program didn't pass callback address\n");
2469 return nfs_parse_devname(dev_name
,
2470 &args
->nfs_server
.hostname
,
2472 &args
->nfs_server
.export_path
,
2477 * Validate NFSv4 mount options
2479 static int nfs4_validate_mount_data(void *options
,
2480 struct nfs_parsed_mount_data
*args
,
2481 const char *dev_name
)
2483 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2484 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2490 switch (data
->version
) {
2492 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2493 goto out_no_address
;
2494 if (data
->host_addrlen
== 0)
2495 goto out_no_address
;
2496 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2497 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2499 if (!nfs_verify_server_address(sap
))
2500 goto out_no_address
;
2502 if (data
->auth_flavourlen
) {
2503 if (data
->auth_flavourlen
> 1)
2504 goto out_inval_auth
;
2505 if (copy_from_user(&args
->auth_flavors
[0],
2506 data
->auth_flavours
,
2507 sizeof(args
->auth_flavors
[0])))
2511 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2514 args
->nfs_server
.hostname
= c
;
2516 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2519 args
->nfs_server
.export_path
= c
;
2520 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2522 c
= strndup_user(data
->client_addr
.data
, 16);
2525 args
->client_address
= c
;
2528 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2532 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2533 args
->rsize
= data
->rsize
;
2534 args
->wsize
= data
->wsize
;
2535 args
->timeo
= data
->timeo
;
2536 args
->retrans
= data
->retrans
;
2537 args
->acregmin
= data
->acregmin
;
2538 args
->acregmax
= data
->acregmax
;
2539 args
->acdirmin
= data
->acdirmin
;
2540 args
->acdirmax
= data
->acdirmax
;
2541 args
->nfs_server
.protocol
= data
->proto
;
2542 nfs_validate_transport_protocol(args
);
2546 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2549 if (!nfs_verify_server_address(sap
))
2552 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2558 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2562 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2563 data
->auth_flavourlen
);
2567 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2572 * Get the superblock for the NFS4 root partition
2574 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2575 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2577 struct nfs_parsed_mount_data
*data
= raw_data
;
2578 struct super_block
*s
;
2579 struct nfs_server
*server
;
2580 struct nfs_fh
*mntfh
;
2581 struct dentry
*mntroot
;
2582 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2583 struct nfs_sb_mountdata sb_mntdata
= {
2586 int error
= -ENOMEM
;
2588 mntfh
= nfs_alloc_fhandle();
2589 if (data
== NULL
|| mntfh
== NULL
)
2592 security_init_mnt_opts(&data
->lsm_opts
);
2594 /* Get a volume representation */
2595 server
= nfs4_create_server(data
, mntfh
);
2596 if (IS_ERR(server
)) {
2597 error
= PTR_ERR(server
);
2600 sb_mntdata
.server
= server
;
2602 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2603 compare_super
= NULL
;
2605 /* Get a superblock - note that we may end up sharing one that already exists */
2606 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2612 if (s
->s_fs_info
!= server
) {
2613 nfs_free_server(server
);
2616 error
= nfs_bdi_register(server
);
2618 goto error_splat_bdi
;
2622 /* initial superblock/root creation */
2624 nfs_fscache_get_super_cookie(
2625 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2628 mntroot
= nfs4_get_root(s
, mntfh
);
2629 if (IS_ERR(mntroot
)) {
2630 error
= PTR_ERR(mntroot
);
2631 goto error_splat_super
;
2634 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2636 goto error_splat_root
;
2638 s
->s_flags
|= MS_ACTIVE
;
2640 mnt
->mnt_root
= mntroot
;
2644 security_free_mnt_opts(&data
->lsm_opts
);
2646 nfs_free_fhandle(mntfh
);
2650 nfs_free_server(server
);
2656 if (server
&& !s
->s_root
)
2657 bdi_unregister(&server
->backing_dev_info
);
2659 deactivate_locked_super(s
);
2663 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2664 int flags
, void *data
, const char *hostname
)
2666 struct vfsmount
*root_mnt
;
2670 len
= strlen(hostname
) + 3;
2671 root_devname
= kmalloc(len
, GFP_KERNEL
);
2672 if (root_devname
== NULL
)
2673 return ERR_PTR(-ENOMEM
);
2674 snprintf(root_devname
, len
, "%s:/", hostname
);
2675 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2676 kfree(root_devname
);
2680 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2682 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2683 char *devname
, *tmp
;
2687 devname
= nfs_path(path
->mnt
->mnt_devname
,
2688 path
->mnt
->mnt_root
, path
->dentry
,
2690 if (IS_ERR(devname
))
2692 tmp
= kstrdup(devname
, GFP_KERNEL
);
2695 kfree(mnt
->mnt_devname
);
2696 mnt
->mnt_devname
= tmp
;
2698 free_page((unsigned long)page
);
2701 struct nfs_referral_count
{
2702 struct list_head list
;
2703 const struct task_struct
*task
;
2704 unsigned int referral_count
;
2707 static LIST_HEAD(nfs_referral_count_list
);
2708 static DEFINE_SPINLOCK(nfs_referral_count_list_lock
);
2710 static struct nfs_referral_count
*nfs_find_referral_count(void)
2712 struct nfs_referral_count
*p
;
2714 list_for_each_entry(p
, &nfs_referral_count_list
, list
) {
2715 if (p
->task
== current
)
2721 #define NFS_MAX_NESTED_REFERRALS 2
2723 static int nfs_referral_loop_protect(void)
2725 struct nfs_referral_count
*p
, *new;
2728 new = kmalloc(sizeof(*new), GFP_KERNEL
);
2731 new->task
= current
;
2732 new->referral_count
= 1;
2735 spin_lock(&nfs_referral_count_list_lock
);
2736 p
= nfs_find_referral_count();
2738 if (p
->referral_count
>= NFS_MAX_NESTED_REFERRALS
)
2741 p
->referral_count
++;
2743 list_add(&new->list
, &nfs_referral_count_list
);
2746 spin_unlock(&nfs_referral_count_list_lock
);
2752 static void nfs_referral_loop_unprotect(void)
2754 struct nfs_referral_count
*p
;
2756 spin_lock(&nfs_referral_count_list_lock
);
2757 p
= nfs_find_referral_count();
2758 p
->referral_count
--;
2759 if (p
->referral_count
== 0)
2763 spin_unlock(&nfs_referral_count_list_lock
);
2767 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2768 const char *export_path
, struct vfsmount
*mnt_target
)
2770 struct nameidata
*nd
= NULL
;
2771 struct mnt_namespace
*ns_private
;
2772 struct super_block
*s
;
2775 nd
= kmalloc(sizeof(*nd
), GFP_KERNEL
);
2779 ns_private
= create_mnt_ns(root_mnt
);
2780 ret
= PTR_ERR(ns_private
);
2781 if (IS_ERR(ns_private
))
2784 ret
= nfs_referral_loop_protect();
2786 goto out_put_mnt_ns
;
2788 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2789 export_path
, LOOKUP_FOLLOW
, nd
);
2791 nfs_referral_loop_unprotect();
2792 put_mnt_ns(ns_private
);
2797 s
= nd
->path
.mnt
->mnt_sb
;
2798 atomic_inc(&s
->s_active
);
2799 mnt_target
->mnt_sb
= s
;
2800 mnt_target
->mnt_root
= dget(nd
->path
.dentry
);
2802 /* Correct the device pathname */
2803 nfs_fix_devname(&nd
->path
, mnt_target
);
2805 path_put(&nd
->path
);
2807 down_write(&s
->s_umount
);
2810 put_mnt_ns(ns_private
);
2818 static int nfs4_try_mount(int flags
, const char *dev_name
,
2819 struct nfs_parsed_mount_data
*data
,
2820 struct vfsmount
*mnt
)
2823 struct vfsmount
*root_mnt
;
2826 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2828 export_path
= data
->nfs_server
.export_path
;
2829 data
->nfs_server
.export_path
= "/";
2830 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2831 data
->nfs_server
.hostname
);
2832 data
->nfs_server
.export_path
= export_path
;
2834 error
= PTR_ERR(root_mnt
);
2835 if (IS_ERR(root_mnt
))
2838 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2841 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2842 error
!= 0 ? " [error]" : "");
2847 * Get the superblock for an NFS4 mountpoint
2849 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2850 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2852 struct nfs_parsed_mount_data
*data
;
2853 int error
= -ENOMEM
;
2855 data
= nfs_alloc_parsed_mount_data(4);
2859 /* Validate the mount data */
2860 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2864 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2867 kfree(data
->client_address
);
2868 kfree(data
->nfs_server
.export_path
);
2869 kfree(data
->nfs_server
.hostname
);
2870 kfree(data
->fscache_uniq
);
2873 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2874 error
!= 0 ? " [error]" : "");
2878 static void nfs4_kill_super(struct super_block
*sb
)
2880 struct nfs_server
*server
= NFS_SB(sb
);
2882 dprintk("--> %s\n", __func__
);
2883 nfs_super_return_all_delegations(sb
);
2884 kill_anon_super(sb
);
2885 nfs_fscache_release_super_cookie(sb
);
2886 nfs_free_server(server
);
2887 dprintk("<-- %s\n", __func__
);
2891 * Clone an NFS4 server record on xdev traversal (FSID-change)
2893 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2894 const char *dev_name
, void *raw_data
,
2895 struct vfsmount
*mnt
)
2897 struct nfs_clone_mount
*data
= raw_data
;
2898 struct super_block
*s
;
2899 struct nfs_server
*server
;
2900 struct dentry
*mntroot
;
2901 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2902 struct nfs_sb_mountdata sb_mntdata
= {
2907 dprintk("--> nfs4_xdev_get_sb()\n");
2909 /* create a new volume representation */
2910 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2911 if (IS_ERR(server
)) {
2912 error
= PTR_ERR(server
);
2913 goto out_err_noserver
;
2915 sb_mntdata
.server
= server
;
2917 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2918 compare_super
= NULL
;
2920 /* Get a superblock - note that we may end up sharing one that already exists */
2921 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2927 if (s
->s_fs_info
!= server
) {
2928 nfs_free_server(server
);
2931 error
= nfs_bdi_register(server
);
2933 goto error_splat_bdi
;
2937 /* initial superblock/root creation */
2938 nfs4_clone_super(s
, data
->sb
);
2939 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2942 mntroot
= nfs4_get_root(s
, data
->fh
);
2943 if (IS_ERR(mntroot
)) {
2944 error
= PTR_ERR(mntroot
);
2945 goto error_splat_super
;
2947 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2950 goto error_splat_super
;
2953 s
->s_flags
|= MS_ACTIVE
;
2955 mnt
->mnt_root
= mntroot
;
2957 security_sb_clone_mnt_opts(data
->sb
, s
);
2959 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2963 nfs_free_server(server
);
2965 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2969 if (server
&& !s
->s_root
)
2970 bdi_unregister(&server
->backing_dev_info
);
2972 deactivate_locked_super(s
);
2973 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2977 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2978 int flags
, const char *dev_name
, void *raw_data
,
2979 struct vfsmount
*mnt
)
2981 struct nfs_clone_mount
*data
= raw_data
;
2982 struct super_block
*s
;
2983 struct nfs_server
*server
;
2984 struct dentry
*mntroot
;
2985 struct nfs_fh
*mntfh
;
2986 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2987 struct nfs_sb_mountdata sb_mntdata
= {
2990 int error
= -ENOMEM
;
2992 dprintk("--> nfs4_referral_get_sb()\n");
2994 mntfh
= nfs_alloc_fhandle();
2998 /* create a new volume representation */
2999 server
= nfs4_create_referral_server(data
, mntfh
);
3000 if (IS_ERR(server
)) {
3001 error
= PTR_ERR(server
);
3002 goto out_err_noserver
;
3004 sb_mntdata
.server
= server
;
3006 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
3007 compare_super
= NULL
;
3009 /* Get a superblock - note that we may end up sharing one that already exists */
3010 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
3016 if (s
->s_fs_info
!= server
) {
3017 nfs_free_server(server
);
3020 error
= nfs_bdi_register(server
);
3022 goto error_splat_bdi
;
3026 /* initial superblock/root creation */
3028 nfs_fscache_get_super_cookie(s
, NULL
, data
);
3031 mntroot
= nfs4_get_root(s
, mntfh
);
3032 if (IS_ERR(mntroot
)) {
3033 error
= PTR_ERR(mntroot
);
3034 goto error_splat_super
;
3036 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
3039 goto error_splat_super
;
3042 s
->s_flags
|= MS_ACTIVE
;
3044 mnt
->mnt_root
= mntroot
;
3046 security_sb_clone_mnt_opts(data
->sb
, s
);
3048 nfs_free_fhandle(mntfh
);
3049 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3053 nfs_free_server(server
);
3055 nfs_free_fhandle(mntfh
);
3057 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
3061 if (server
&& !s
->s_root
)
3062 bdi_unregister(&server
->backing_dev_info
);
3064 deactivate_locked_super(s
);
3065 nfs_free_fhandle(mntfh
);
3066 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
3071 * Create an NFS4 server record on referral traversal
3073 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
3074 int flags
, const char *dev_name
, void *raw_data
,
3075 struct vfsmount
*mnt
)
3077 struct nfs_clone_mount
*data
= raw_data
;
3079 struct vfsmount
*root_mnt
;
3082 dprintk("--> nfs4_referral_get_sb()\n");
3084 export_path
= data
->mnt_path
;
3085 data
->mnt_path
= "/";
3087 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
3088 flags
, data
, data
->hostname
);
3089 data
->mnt_path
= export_path
;
3091 error
= PTR_ERR(root_mnt
);
3092 if (IS_ERR(root_mnt
))
3095 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
3097 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
3098 error
!= 0 ? " [error]" : "");
3102 #endif /* CONFIG_NFS_V4 */