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 .clear_inode
= nfs_clear_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 .clear_inode
= nfs4_clear_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 switch (sap
->sa_family
) {
551 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
552 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
556 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
557 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
562 seq_printf(m
, ",mountaddr=unspecified");
565 if (nfss
->mountd_version
|| showdefaults
)
566 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
567 if (nfss
->mountd_port
|| showdefaults
)
568 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
570 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
574 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
577 struct nfs_client
*clp
= nfss
->nfs_client
;
579 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
580 seq_printf(m
, ",minorversion=%u", clp
->cl_minorversion
);
583 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
590 * Describe the mount options in force on this server representation
592 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
595 static const struct proc_nfs_info
{
600 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
601 { NFS_MOUNT_POSIX
, ",posix", "" },
602 { NFS_MOUNT_NOCTO
, ",nocto", "" },
603 { NFS_MOUNT_NOAC
, ",noac", "" },
604 { NFS_MOUNT_NONLM
, ",nolock", "" },
605 { NFS_MOUNT_NOACL
, ",noacl", "" },
606 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
607 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
608 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
611 const struct proc_nfs_info
*nfs_infop
;
612 struct nfs_client
*clp
= nfss
->nfs_client
;
613 u32 version
= clp
->rpc_ops
->version
;
615 seq_printf(m
, ",vers=%u", version
);
616 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
617 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
618 if (nfss
->bsize
!= 0)
619 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
620 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
621 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
622 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
623 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
624 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
625 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
626 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
627 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
628 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
629 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
630 if (nfss
->flags
& nfs_infop
->flag
)
631 seq_puts(m
, nfs_infop
->str
);
633 seq_puts(m
, nfs_infop
->nostr
);
635 seq_printf(m
, ",proto=%s",
636 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
638 if (nfss
->port
!= NFS_PORT
)
639 seq_printf(m
, ",port=%u", nfss
->port
);
642 seq_printf(m
, ",port=%u", nfss
->port
);
644 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
645 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
646 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
649 nfs_show_mountd_options(m
, nfss
, showdefaults
);
651 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
653 if (nfss
->options
& NFS_OPTION_FSCACHE
)
654 seq_printf(m
, ",fsc");
658 * Describe the mount options on this VFS mountpoint
660 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
662 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
664 nfs_show_mount_options(m
, nfss
, 0);
666 seq_printf(m
, ",addr=%s",
667 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
674 * Present statistical information for this VFS mountpoint
676 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
679 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
680 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
681 struct nfs_iostats totals
= { };
683 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
686 * Display all mount option settings
688 seq_printf(m
, "\n\topts:\t");
689 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
690 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
691 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
692 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
693 nfs_show_mount_options(m
, nfss
, 1);
695 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
697 seq_printf(m
, "\n\tcaps:\t");
698 seq_printf(m
, "caps=0x%x", nfss
->caps
);
699 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
700 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
701 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
702 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
705 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
706 seq_printf(m
, "\n\tnfsv4:\t");
707 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
708 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
709 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
714 * Display security flavor in effect for this mount
716 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
718 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
721 * Display superblock I/O counters
723 for_each_possible_cpu(cpu
) {
724 struct nfs_iostats
*stats
;
727 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
729 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
730 totals
.events
[i
] += stats
->events
[i
];
731 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
732 totals
.bytes
[i
] += stats
->bytes
[i
];
733 #ifdef CONFIG_NFS_FSCACHE
734 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
735 totals
.fscache
[i
] += stats
->fscache
[i
];
741 seq_printf(m
, "\n\tevents:\t");
742 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
743 seq_printf(m
, "%lu ", totals
.events
[i
]);
744 seq_printf(m
, "\n\tbytes:\t");
745 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
746 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
747 #ifdef CONFIG_NFS_FSCACHE
748 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
749 seq_printf(m
, "\n\tfsc:\t");
750 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
751 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
756 rpc_print_iostats(m
, nfss
->client
);
762 * Begin unmount by attempting to remove all automounted mountpoints we added
763 * in response to xdev traversals and referrals
765 static void nfs_umount_begin(struct super_block
*sb
)
767 struct nfs_server
*server
;
768 struct rpc_clnt
*rpc
;
771 /* -EIO all pending I/O */
772 rpc
= server
->client_acl
;
774 rpc_killall_tasks(rpc
);
775 rpc
= server
->client
;
777 rpc_killall_tasks(rpc
);
780 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
782 struct nfs_parsed_mount_data
*data
;
784 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
786 data
->acregmin
= NFS_DEF_ACREGMIN
;
787 data
->acregmax
= NFS_DEF_ACREGMAX
;
788 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
789 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
790 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
791 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
792 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
793 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
794 data
->auth_flavor_len
= 1;
795 data
->version
= version
;
796 data
->minorversion
= 0;
802 * Sanity-check a server address provided by the mount command.
804 * Address family must be initialized, and address must not be
805 * the ANY address for that family.
807 static int nfs_verify_server_address(struct sockaddr
*addr
)
809 switch (addr
->sa_family
) {
811 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
812 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
815 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
816 return !ipv6_addr_any(sa
);
820 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
825 * Select between a default port value and a user-specified port value.
826 * If a zero value is set, then autobind will be used.
828 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
829 const unsigned short default_port
)
831 if (*port
== NFS_UNSPEC_PORT
)
832 *port
= default_port
;
834 rpc_set_port(sap
, *port
);
838 * Sanity check the NFS transport protocol.
841 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
843 switch (mnt
->nfs_server
.protocol
) {
844 case XPRT_TRANSPORT_UDP
:
845 case XPRT_TRANSPORT_TCP
:
846 case XPRT_TRANSPORT_RDMA
:
849 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
854 * For text based NFSv2/v3 mounts, the mount protocol transport default
855 * settings should depend upon the specified NFS transport.
857 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
859 nfs_validate_transport_protocol(mnt
);
861 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
862 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
864 switch (mnt
->nfs_server
.protocol
) {
865 case XPRT_TRANSPORT_UDP
:
866 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
868 case XPRT_TRANSPORT_TCP
:
869 case XPRT_TRANSPORT_RDMA
:
870 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
875 * Parse the value of the 'sec=' option.
877 static int nfs_parse_security_flavors(char *value
,
878 struct nfs_parsed_mount_data
*mnt
)
880 substring_t args
[MAX_OPT_ARGS
];
882 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
884 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
886 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
889 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
892 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
895 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
898 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
901 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
904 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
907 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
910 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
913 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
916 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
922 mnt
->auth_flavor_len
= 1;
927 * Error-check and convert a string of mount options from user space into
928 * a data structure. The whole mount string is processed; bad options are
929 * skipped as they are encountered. If there were no errors, return 1;
930 * otherwise return 0 (zero).
932 static int nfs_parse_mount_options(char *raw
,
933 struct nfs_parsed_mount_data
*mnt
)
935 char *p
, *string
, *secdata
;
936 int rc
, sloppy
= 0, invalid_option
= 0;
937 unsigned short protofamily
= AF_UNSPEC
;
938 unsigned short mountfamily
= AF_UNSPEC
;
941 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
944 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
946 secdata
= alloc_secdata();
950 rc
= security_sb_copy_data(raw
, secdata
);
952 goto out_security_failure
;
954 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
956 goto out_security_failure
;
958 free_secdata(secdata
);
960 while ((p
= strsep(&raw
, ",")) != NULL
) {
961 substring_t args
[MAX_OPT_ARGS
];
962 unsigned long option
;
968 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
970 token
= match_token(p
, nfs_mount_option_tokens
, args
);
974 * boolean options: foo/nofoo
977 mnt
->flags
|= NFS_MOUNT_SOFT
;
980 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
983 mnt
->flags
|= NFS_MOUNT_POSIX
;
986 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
989 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
992 mnt
->flags
|= NFS_MOUNT_NOCTO
;
995 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
998 mnt
->flags
|= NFS_MOUNT_NOAC
;
1001 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1004 mnt
->flags
|= NFS_MOUNT_NONLM
;
1007 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1011 mnt
->flags
|= NFS_MOUNT_VER3
;
1014 #ifdef CONFIG_NFS_V4
1016 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1021 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1022 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1025 mnt
->flags
|= NFS_MOUNT_TCP
;
1026 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1029 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1030 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1031 xprt_load_transport(p
);
1034 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1037 mnt
->flags
|= NFS_MOUNT_NOACL
;
1040 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1042 case Opt_nordirplus
:
1043 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1045 case Opt_sharecache
:
1046 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1048 case Opt_nosharecache
:
1049 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1052 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1054 case Opt_noresvport
:
1055 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1058 mnt
->options
|= NFS_OPTION_FSCACHE
;
1059 kfree(mnt
->fscache_uniq
);
1060 mnt
->fscache_uniq
= NULL
;
1063 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1064 kfree(mnt
->fscache_uniq
);
1065 mnt
->fscache_uniq
= NULL
;
1069 * options that take numeric values
1072 string
= match_strdup(args
);
1075 rc
= strict_strtoul(string
, 10, &option
);
1077 if (rc
!= 0 || option
> USHRT_MAX
)
1078 goto out_invalid_value
;
1079 mnt
->nfs_server
.port
= option
;
1082 string
= match_strdup(args
);
1085 rc
= strict_strtoul(string
, 10, &option
);
1088 goto out_invalid_value
;
1089 mnt
->rsize
= option
;
1092 string
= match_strdup(args
);
1095 rc
= strict_strtoul(string
, 10, &option
);
1098 goto out_invalid_value
;
1099 mnt
->wsize
= option
;
1102 string
= match_strdup(args
);
1105 rc
= strict_strtoul(string
, 10, &option
);
1108 goto out_invalid_value
;
1109 mnt
->bsize
= option
;
1112 string
= match_strdup(args
);
1115 rc
= strict_strtoul(string
, 10, &option
);
1117 if (rc
!= 0 || option
== 0)
1118 goto out_invalid_value
;
1119 mnt
->timeo
= 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
->retrans
= option
;
1132 string
= match_strdup(args
);
1135 rc
= strict_strtoul(string
, 10, &option
);
1138 goto out_invalid_value
;
1139 mnt
->acregmin
= option
;
1142 string
= match_strdup(args
);
1145 rc
= strict_strtoul(string
, 10, &option
);
1148 goto out_invalid_value
;
1149 mnt
->acregmax
= option
;
1152 string
= match_strdup(args
);
1155 rc
= strict_strtoul(string
, 10, &option
);
1158 goto out_invalid_value
;
1159 mnt
->acdirmin
= option
;
1162 string
= match_strdup(args
);
1165 rc
= strict_strtoul(string
, 10, &option
);
1168 goto out_invalid_value
;
1169 mnt
->acdirmax
= option
;
1172 string
= match_strdup(args
);
1175 rc
= strict_strtoul(string
, 10, &option
);
1178 goto out_invalid_value
;
1179 mnt
->acregmin
= mnt
->acregmax
=
1180 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1183 string
= match_strdup(args
);
1186 rc
= strict_strtoul(string
, 10, &option
);
1189 goto out_invalid_value
;
1190 mnt
->namlen
= option
;
1193 string
= match_strdup(args
);
1196 rc
= strict_strtoul(string
, 10, &option
);
1198 if (rc
!= 0 || option
> USHRT_MAX
)
1199 goto out_invalid_value
;
1200 mnt
->mount_server
.port
= option
;
1203 string
= match_strdup(args
);
1206 rc
= strict_strtoul(string
, 10, &option
);
1209 option
< NFS_MNT_VERSION
||
1210 option
> NFS_MNT3_VERSION
)
1211 goto out_invalid_value
;
1212 mnt
->mount_server
.version
= option
;
1215 string
= match_strdup(args
);
1218 rc
= strict_strtoul(string
, 10, &option
);
1221 goto out_invalid_value
;
1224 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1228 mnt
->flags
|= NFS_MOUNT_VER3
;
1231 #ifdef CONFIG_NFS_V4
1233 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1238 goto out_invalid_value
;
1241 case Opt_minorversion
:
1242 string
= match_strdup(args
);
1245 rc
= strict_strtoul(string
, 10, &option
);
1248 goto out_invalid_value
;
1249 if (option
> NFS4_MAX_MINOR_VERSION
)
1250 goto out_invalid_value
;
1251 mnt
->minorversion
= option
;
1255 * options that take text values
1258 string
= match_strdup(args
);
1261 rc
= nfs_parse_security_flavors(string
, mnt
);
1264 dfprintk(MOUNT
, "NFS: unrecognized "
1265 "security flavor\n");
1270 string
= match_strdup(args
);
1273 token
= match_token(string
,
1274 nfs_xprt_protocol_tokens
, args
);
1276 protofamily
= AF_INET
;
1279 protofamily
= AF_INET6
;
1281 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1282 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1286 protofamily
= AF_INET6
;
1288 mnt
->flags
|= NFS_MOUNT_TCP
;
1289 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1293 /* vector side protocols to TCP */
1294 mnt
->flags
|= NFS_MOUNT_TCP
;
1295 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1296 xprt_load_transport(string
);
1300 dfprintk(MOUNT
, "NFS: unrecognized "
1301 "transport protocol\n");
1306 case Opt_mountproto
:
1307 string
= match_strdup(args
);
1310 token
= match_token(string
,
1311 nfs_xprt_protocol_tokens
, args
);
1314 mountfamily
= AF_INET
;
1317 mountfamily
= AF_INET6
;
1319 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1322 mountfamily
= AF_INET6
;
1324 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1326 case Opt_xprt_rdma
: /* not used for side protocols */
1328 dfprintk(MOUNT
, "NFS: unrecognized "
1329 "transport protocol\n");
1334 string
= match_strdup(args
);
1337 mnt
->nfs_server
.addrlen
=
1338 rpc_pton(string
, strlen(string
),
1340 &mnt
->nfs_server
.address
,
1341 sizeof(mnt
->nfs_server
.address
));
1343 if (mnt
->nfs_server
.addrlen
== 0)
1344 goto out_invalid_address
;
1346 case Opt_clientaddr
:
1347 string
= match_strdup(args
);
1350 kfree(mnt
->client_address
);
1351 mnt
->client_address
= string
;
1354 string
= match_strdup(args
);
1357 kfree(mnt
->mount_server
.hostname
);
1358 mnt
->mount_server
.hostname
= string
;
1361 string
= match_strdup(args
);
1364 mnt
->mount_server
.addrlen
=
1365 rpc_pton(string
, strlen(string
),
1367 &mnt
->mount_server
.address
,
1368 sizeof(mnt
->mount_server
.address
));
1370 if (mnt
->mount_server
.addrlen
== 0)
1371 goto out_invalid_address
;
1373 case Opt_lookupcache
:
1374 string
= match_strdup(args
);
1377 token
= match_token(string
,
1378 nfs_lookupcache_tokens
, args
);
1381 case Opt_lookupcache_all
:
1382 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1384 case Opt_lookupcache_positive
:
1385 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1386 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1388 case Opt_lookupcache_none
:
1389 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1392 dfprintk(MOUNT
, "NFS: invalid "
1393 "lookupcache argument\n");
1397 case Opt_fscache_uniq
:
1398 string
= match_strdup(args
);
1401 kfree(mnt
->fscache_uniq
);
1402 mnt
->fscache_uniq
= string
;
1403 mnt
->options
|= NFS_OPTION_FSCACHE
;
1411 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1414 case Opt_deprecated
:
1415 dfprintk(MOUNT
, "NFS: ignoring mount option "
1421 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1426 if (!sloppy
&& invalid_option
)
1430 * verify that any proto=/mountproto= options match the address
1431 * familiies in the addr=/mountaddr= options.
1433 if (protofamily
!= AF_UNSPEC
&&
1434 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1435 goto out_proto_mismatch
;
1437 if (mountfamily
!= AF_UNSPEC
) {
1438 if (mnt
->mount_server
.addrlen
) {
1439 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1440 goto out_mountproto_mismatch
;
1442 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1443 goto out_mountproto_mismatch
;
1449 out_mountproto_mismatch
:
1450 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1454 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1456 out_invalid_address
:
1457 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1460 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1463 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1465 out_security_failure
:
1466 free_secdata(secdata
);
1467 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1472 * Match the requested auth flavors with the list returned by
1473 * the server. Returns zero and sets the mount's authentication
1474 * flavor on success; returns -EACCES if server does not support
1475 * the requested flavor.
1477 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1478 struct nfs_mount_request
*request
)
1480 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1483 * Certain releases of Linux's mountd return an empty
1484 * flavor list. To prevent behavioral regression with
1485 * these servers (ie. rejecting mounts that used to
1486 * succeed), revert to pre-2.6.32 behavior (no checking)
1487 * if the returned flavor list is empty.
1489 if (server_authlist_len
== 0)
1493 * We avoid sophisticated negotiating here, as there are
1494 * plenty of cases where we can get it wrong, providing
1495 * either too little or too much security.
1497 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1498 * flavor listed first. However, some servers list
1499 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1500 * preferred default, in args->auth_flavors[0] if user
1501 * didn't specify sec= mount option.
1503 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1504 for (j
= 0; j
< server_authlist_len
; j
++)
1505 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1506 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1507 request
->auth_flavs
[j
]);
1508 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1512 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1513 nfs_umount(request
);
1518 * Use the remote server's MOUNT service to request the NFS file handle
1519 * corresponding to the provided path.
1521 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1522 struct nfs_fh
*root_fh
)
1524 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1525 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1526 struct nfs_mount_request request
= {
1527 .sap
= (struct sockaddr
*)
1528 &args
->mount_server
.address
,
1529 .dirpath
= args
->nfs_server
.export_path
,
1530 .protocol
= args
->mount_server
.protocol
,
1532 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1533 .auth_flav_len
= &server_authlist_len
,
1534 .auth_flavs
= server_authlist
,
1538 if (args
->mount_server
.version
== 0) {
1539 switch (args
->version
) {
1541 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1544 args
->mount_server
.version
= NFS_MNT_VERSION
;
1547 request
.version
= args
->mount_server
.version
;
1549 if (args
->mount_server
.hostname
)
1550 request
.hostname
= args
->mount_server
.hostname
;
1552 request
.hostname
= args
->nfs_server
.hostname
;
1555 * Construct the mount server's address.
1557 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1558 memcpy(request
.sap
, &args
->nfs_server
.address
,
1559 args
->nfs_server
.addrlen
);
1560 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1562 request
.salen
= args
->mount_server
.addrlen
;
1563 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1566 * Now ask the mount server to map our export path
1569 status
= nfs_mount(&request
);
1571 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1572 request
.hostname
, status
);
1577 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1579 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1581 return nfs_walk_authlist(args
, &request
);
1584 static int nfs_parse_simple_hostname(const char *dev_name
,
1585 char **hostname
, size_t maxnamlen
,
1586 char **export_path
, size_t maxpathlen
)
1589 char *colon
, *comma
;
1591 colon
= strchr(dev_name
, ':');
1593 goto out_bad_devname
;
1595 len
= colon
- dev_name
;
1596 if (len
> maxnamlen
)
1599 /* N.B. caller will free nfs_server.hostname in all cases */
1600 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1604 /* kill possible hostname list: not supported */
1605 comma
= strchr(*hostname
, ',');
1606 if (comma
!= NULL
) {
1607 if (comma
== *hostname
)
1608 goto out_bad_devname
;
1613 len
= strlen(colon
);
1614 if (len
> maxpathlen
)
1616 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1620 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1624 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1628 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1632 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1633 return -ENAMETOOLONG
;
1636 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1637 return -ENAMETOOLONG
;
1641 * Hostname has square brackets around it because it contains one or
1642 * more colons. We look for the first closing square bracket, and a
1643 * colon must follow it.
1645 static int nfs_parse_protected_hostname(const char *dev_name
,
1646 char **hostname
, size_t maxnamlen
,
1647 char **export_path
, size_t maxpathlen
)
1652 start
= (char *)(dev_name
+ 1);
1654 end
= strchr(start
, ']');
1656 goto out_bad_devname
;
1657 if (*(end
+ 1) != ':')
1658 goto out_bad_devname
;
1661 if (len
> maxnamlen
)
1664 /* N.B. caller will free nfs_server.hostname in all cases */
1665 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1666 if (*hostname
== NULL
)
1671 if (len
> maxpathlen
)
1673 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1680 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1684 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1688 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1689 return -ENAMETOOLONG
;
1692 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1693 return -ENAMETOOLONG
;
1697 * Split "dev_name" into "hostname:export_path".
1699 * The leftmost colon demarks the split between the server's hostname
1700 * and the export path. If the hostname starts with a left square
1701 * bracket, then it may contain colons.
1703 * Note: caller frees hostname and export path, even on error.
1705 static int nfs_parse_devname(const char *dev_name
,
1706 char **hostname
, size_t maxnamlen
,
1707 char **export_path
, size_t maxpathlen
)
1709 if (*dev_name
== '[')
1710 return nfs_parse_protected_hostname(dev_name
,
1711 hostname
, maxnamlen
,
1712 export_path
, maxpathlen
);
1714 return nfs_parse_simple_hostname(dev_name
,
1715 hostname
, maxnamlen
,
1716 export_path
, maxpathlen
);
1720 * Validate the NFS2/NFS3 mount data
1721 * - fills in the mount root filehandle
1723 * For option strings, user space handles the following behaviors:
1725 * + DNS: mapping server host name to IP address ("addr=" option)
1727 * + failure mode: how to behave if a mount request can't be handled
1728 * immediately ("fg/bg" option)
1730 * + retry: how often to retry a mount request ("retry=" option)
1732 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1733 * mountproto=tcp after mountproto=udp, and so on
1735 static int nfs_validate_mount_data(void *options
,
1736 struct nfs_parsed_mount_data
*args
,
1737 struct nfs_fh
*mntfh
,
1738 const char *dev_name
)
1740 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1741 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1746 switch (data
->version
) {
1752 if (data
->flags
& NFS_MOUNT_VER3
)
1754 data
->root
.size
= NFS2_FHSIZE
;
1755 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1757 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1760 memset(data
->context
, 0, sizeof(data
->context
));
1762 if (data
->flags
& NFS_MOUNT_VER3
) {
1763 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1764 goto out_invalid_fh
;
1765 mntfh
->size
= data
->root
.size
;
1768 mntfh
->size
= NFS2_FHSIZE
;
1773 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1774 if (mntfh
->size
< sizeof(mntfh
->data
))
1775 memset(mntfh
->data
+ mntfh
->size
, 0,
1776 sizeof(mntfh
->data
) - mntfh
->size
);
1779 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1782 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1783 args
->rsize
= data
->rsize
;
1784 args
->wsize
= data
->wsize
;
1785 args
->timeo
= data
->timeo
;
1786 args
->retrans
= data
->retrans
;
1787 args
->acregmin
= data
->acregmin
;
1788 args
->acregmax
= data
->acregmax
;
1789 args
->acdirmin
= data
->acdirmin
;
1790 args
->acdirmax
= data
->acdirmax
;
1792 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1793 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1794 if (!nfs_verify_server_address(sap
))
1795 goto out_no_address
;
1797 if (!(data
->flags
& NFS_MOUNT_TCP
))
1798 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1799 /* N.B. caller will free nfs_server.hostname in all cases */
1800 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1801 args
->namlen
= data
->namlen
;
1802 args
->bsize
= data
->bsize
;
1804 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1805 args
->auth_flavors
[0] = data
->pseudoflavor
;
1806 if (!args
->nfs_server
.hostname
)
1810 * The legacy version 6 binary mount data from userspace has a
1811 * field used only to transport selinux information into the
1812 * the kernel. To continue to support that functionality we
1813 * have a touch of selinux knowledge here in the NFS code. The
1814 * userspace code converted context=blah to just blah so we are
1815 * converting back to the full string selinux understands.
1817 if (data
->context
[0]){
1818 #ifdef CONFIG_SECURITY_SELINUX
1820 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1823 strcpy(opts_str
, "context=");
1824 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1825 strcat(opts_str
, &data
->context
[0]);
1826 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1839 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1842 if (!nfs_verify_server_address(sap
))
1843 goto out_no_address
;
1845 if (args
->version
== 4)
1846 #ifdef CONFIG_NFS_V4
1847 return nfs4_validate_text_mount_data(options
,
1850 goto out_v4_not_compiled
;
1853 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1855 nfs_set_mount_transport_protocol(args
);
1857 status
= nfs_parse_devname(dev_name
,
1858 &args
->nfs_server
.hostname
,
1860 &args
->nfs_server
.export_path
,
1863 status
= nfs_try_mount(args
, mntfh
);
1865 kfree(args
->nfs_server
.export_path
);
1866 args
->nfs_server
.export_path
= NULL
;
1875 #ifndef CONFIG_NFS_V3
1876 if (args
->version
== 3)
1877 goto out_v3_not_compiled
;
1878 #endif /* !CONFIG_NFS_V3 */
1883 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1887 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1892 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1895 #ifndef CONFIG_NFS_V3
1896 out_v3_not_compiled
:
1897 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1898 return -EPROTONOSUPPORT
;
1899 #endif /* !CONFIG_NFS_V3 */
1901 #ifndef CONFIG_NFS_V4
1902 out_v4_not_compiled
:
1903 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1904 return -EPROTONOSUPPORT
;
1905 #endif /* !CONFIG_NFS_V4 */
1908 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1912 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1916 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1921 nfs_compare_remount_data(struct nfs_server
*nfss
,
1922 struct nfs_parsed_mount_data
*data
)
1924 if (data
->flags
!= nfss
->flags
||
1925 data
->rsize
!= nfss
->rsize
||
1926 data
->wsize
!= nfss
->wsize
||
1927 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1928 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1929 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1930 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1931 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1932 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1933 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1934 data
->nfs_server
.port
!= nfss
->port
||
1935 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1936 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
1937 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
1944 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1947 struct nfs_server
*nfss
= sb
->s_fs_info
;
1948 struct nfs_parsed_mount_data
*data
;
1949 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1950 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1951 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1954 * Userspace mount programs that send binary options generally send
1955 * them populated with default values. We have no way to know which
1956 * ones were explicitly specified. Fall back to legacy behavior and
1957 * just return success.
1959 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1960 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1961 options
->version
<= 6))))
1964 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1968 /* fill out struct with values from existing mount */
1969 data
->flags
= nfss
->flags
;
1970 data
->rsize
= nfss
->rsize
;
1971 data
->wsize
= nfss
->wsize
;
1972 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1973 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1974 data
->acregmin
= nfss
->acregmin
/ HZ
;
1975 data
->acregmax
= nfss
->acregmax
/ HZ
;
1976 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1977 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1978 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1979 data
->nfs_server
.port
= nfss
->port
;
1980 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1981 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1982 data
->nfs_server
.addrlen
);
1984 /* overwrite those values with any that were specified */
1985 error
= nfs_parse_mount_options((char *)options
, data
);
1989 /* compare new mount options with old ones */
1990 error
= nfs_compare_remount_data(nfss
, data
);
1997 * Initialise the common bits of the superblock
1999 static inline void nfs_initialise_sb(struct super_block
*sb
)
2001 struct nfs_server
*server
= NFS_SB(sb
);
2003 sb
->s_magic
= NFS_SUPER_MAGIC
;
2005 /* We probably want something more informative here */
2006 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
2007 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
2009 if (sb
->s_blocksize
== 0)
2010 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
2011 &sb
->s_blocksize_bits
);
2013 if (server
->flags
& NFS_MOUNT_NOAC
)
2014 sb
->s_flags
|= MS_SYNCHRONOUS
;
2016 sb
->s_bdi
= &server
->backing_dev_info
;
2018 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2022 * Finish setting up an NFS2/3 superblock
2024 static void nfs_fill_super(struct super_block
*sb
,
2025 struct nfs_parsed_mount_data
*data
)
2027 struct nfs_server
*server
= NFS_SB(sb
);
2029 sb
->s_blocksize_bits
= 0;
2030 sb
->s_blocksize
= 0;
2032 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2034 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2035 /* The VFS shouldn't apply the umask to mode bits. We will do
2036 * so ourselves when necessary.
2038 sb
->s_flags
|= MS_POSIXACL
;
2039 sb
->s_time_gran
= 1;
2042 sb
->s_op
= &nfs_sops
;
2043 nfs_initialise_sb(sb
);
2047 * Finish setting up a cloned NFS2/3 superblock
2049 static void nfs_clone_super(struct super_block
*sb
,
2050 const struct super_block
*old_sb
)
2052 struct nfs_server
*server
= NFS_SB(sb
);
2054 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2055 sb
->s_blocksize
= old_sb
->s_blocksize
;
2056 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2058 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2059 /* The VFS shouldn't apply the umask to mode bits. We will do
2060 * so ourselves when necessary.
2062 sb
->s_flags
|= MS_POSIXACL
;
2063 sb
->s_time_gran
= 1;
2066 sb
->s_op
= old_sb
->s_op
;
2067 nfs_initialise_sb(sb
);
2070 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2072 const struct nfs_server
*a
= s
->s_fs_info
;
2073 const struct rpc_clnt
*clnt_a
= a
->client
;
2074 const struct rpc_clnt
*clnt_b
= b
->client
;
2076 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2078 if (a
->nfs_client
!= b
->nfs_client
)
2080 if (a
->flags
!= b
->flags
)
2082 if (a
->wsize
!= b
->wsize
)
2084 if (a
->rsize
!= b
->rsize
)
2086 if (a
->acregmin
!= b
->acregmin
)
2088 if (a
->acregmax
!= b
->acregmax
)
2090 if (a
->acdirmin
!= b
->acdirmin
)
2092 if (a
->acdirmax
!= b
->acdirmax
)
2094 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2101 struct nfs_sb_mountdata
{
2102 struct nfs_server
*server
;
2106 static int nfs_set_super(struct super_block
*s
, void *data
)
2108 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2109 struct nfs_server
*server
= sb_mntdata
->server
;
2112 s
->s_flags
= sb_mntdata
->mntflags
;
2113 s
->s_fs_info
= server
;
2114 ret
= set_anon_super(s
, server
);
2116 server
->s_dev
= s
->s_dev
;
2120 static int nfs_compare_super_address(struct nfs_server
*server1
,
2121 struct nfs_server
*server2
)
2123 struct sockaddr
*sap1
, *sap2
;
2125 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2126 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2128 if (sap1
->sa_family
!= sap2
->sa_family
)
2131 switch (sap1
->sa_family
) {
2133 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2134 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2135 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2137 if (sin1
->sin_port
!= sin2
->sin_port
)
2142 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2143 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2144 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2146 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2157 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2159 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2160 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2161 int mntflags
= sb_mntdata
->mntflags
;
2163 if (!nfs_compare_super_address(old
, server
))
2165 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2166 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2168 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2170 return nfs_compare_mount_options(sb
, server
, mntflags
);
2173 static int nfs_bdi_register(struct nfs_server
*server
)
2175 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2178 static int nfs_get_sb(struct file_system_type
*fs_type
,
2179 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2181 struct nfs_server
*server
= NULL
;
2182 struct super_block
*s
;
2183 struct nfs_parsed_mount_data
*data
;
2184 struct nfs_fh
*mntfh
;
2185 struct dentry
*mntroot
;
2186 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2187 struct nfs_sb_mountdata sb_mntdata
= {
2190 int error
= -ENOMEM
;
2192 data
= nfs_alloc_parsed_mount_data(3);
2193 mntfh
= nfs_alloc_fhandle();
2194 if (data
== NULL
|| mntfh
== NULL
)
2197 security_init_mnt_opts(&data
->lsm_opts
);
2199 /* Validate the mount data */
2200 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2204 #ifdef CONFIG_NFS_V4
2205 if (data
->version
== 4) {
2206 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2207 kfree(data
->client_address
);
2208 kfree(data
->nfs_server
.export_path
);
2211 #endif /* CONFIG_NFS_V4 */
2213 /* Get a volume representation */
2214 server
= nfs_create_server(data
, mntfh
);
2215 if (IS_ERR(server
)) {
2216 error
= PTR_ERR(server
);
2219 sb_mntdata
.server
= server
;
2221 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2222 compare_super
= NULL
;
2224 /* Get a superblock - note that we may end up sharing one that already exists */
2225 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2231 if (s
->s_fs_info
!= server
) {
2232 nfs_free_server(server
);
2235 error
= nfs_bdi_register(server
);
2237 goto error_splat_bdi
;
2241 /* initial superblock/root creation */
2242 nfs_fill_super(s
, data
);
2243 nfs_fscache_get_super_cookie(
2244 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2247 mntroot
= nfs_get_root(s
, mntfh
);
2248 if (IS_ERR(mntroot
)) {
2249 error
= PTR_ERR(mntroot
);
2250 goto error_splat_super
;
2253 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2255 goto error_splat_root
;
2257 s
->s_flags
|= MS_ACTIVE
;
2259 mnt
->mnt_root
= mntroot
;
2263 kfree(data
->nfs_server
.hostname
);
2264 kfree(data
->mount_server
.hostname
);
2265 kfree(data
->fscache_uniq
);
2266 security_free_mnt_opts(&data
->lsm_opts
);
2268 nfs_free_fhandle(mntfh
);
2273 nfs_free_server(server
);
2279 if (server
&& !s
->s_root
)
2280 bdi_unregister(&server
->backing_dev_info
);
2282 deactivate_locked_super(s
);
2287 * Ensure that we unregister the bdi before kill_anon_super
2288 * releases the device name
2290 static void nfs_put_super(struct super_block
*s
)
2292 struct nfs_server
*server
= NFS_SB(s
);
2294 bdi_unregister(&server
->backing_dev_info
);
2298 * Destroy an NFS2/3 superblock
2300 static void nfs_kill_super(struct super_block
*s
)
2302 struct nfs_server
*server
= NFS_SB(s
);
2305 nfs_fscache_release_super_cookie(s
);
2306 nfs_free_server(server
);
2310 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2312 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2313 const char *dev_name
, void *raw_data
,
2314 struct vfsmount
*mnt
)
2316 struct nfs_clone_mount
*data
= raw_data
;
2317 struct super_block
*s
;
2318 struct nfs_server
*server
;
2319 struct dentry
*mntroot
;
2320 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2321 struct nfs_sb_mountdata sb_mntdata
= {
2326 dprintk("--> nfs_xdev_get_sb()\n");
2328 /* create a new volume representation */
2329 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2330 if (IS_ERR(server
)) {
2331 error
= PTR_ERR(server
);
2332 goto out_err_noserver
;
2334 sb_mntdata
.server
= server
;
2336 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2337 compare_super
= NULL
;
2339 /* Get a superblock - note that we may end up sharing one that already exists */
2340 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2346 if (s
->s_fs_info
!= server
) {
2347 nfs_free_server(server
);
2350 error
= nfs_bdi_register(server
);
2352 goto error_splat_bdi
;
2356 /* initial superblock/root creation */
2357 nfs_clone_super(s
, data
->sb
);
2358 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2361 mntroot
= nfs_get_root(s
, data
->fh
);
2362 if (IS_ERR(mntroot
)) {
2363 error
= PTR_ERR(mntroot
);
2364 goto error_splat_super
;
2366 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2369 goto error_splat_super
;
2372 s
->s_flags
|= MS_ACTIVE
;
2374 mnt
->mnt_root
= mntroot
;
2376 /* clone any lsm security options from the parent to the new sb */
2377 security_sb_clone_mnt_opts(data
->sb
, s
);
2379 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2383 nfs_free_server(server
);
2385 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2389 if (server
&& !s
->s_root
)
2390 bdi_unregister(&server
->backing_dev_info
);
2392 deactivate_locked_super(s
);
2393 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2397 #ifdef CONFIG_NFS_V4
2400 * Finish setting up a cloned NFS4 superblock
2402 static void nfs4_clone_super(struct super_block
*sb
,
2403 const struct super_block
*old_sb
)
2405 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2406 sb
->s_blocksize
= old_sb
->s_blocksize
;
2407 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2408 sb
->s_time_gran
= 1;
2409 sb
->s_op
= old_sb
->s_op
;
2410 nfs_initialise_sb(sb
);
2414 * Set up an NFS4 superblock
2416 static void nfs4_fill_super(struct super_block
*sb
)
2418 sb
->s_time_gran
= 1;
2419 sb
->s_op
= &nfs4_sops
;
2420 nfs_initialise_sb(sb
);
2423 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2425 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2428 static int nfs4_validate_text_mount_data(void *options
,
2429 struct nfs_parsed_mount_data
*args
,
2430 const char *dev_name
)
2432 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2434 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2436 nfs_validate_transport_protocol(args
);
2438 nfs4_validate_mount_flags(args
);
2440 if (args
->version
!= 4) {
2442 "NFS4: Illegal mount version\n");
2446 if (args
->auth_flavor_len
> 1) {
2448 "NFS4: Too many RPC auth flavours specified\n");
2452 if (args
->client_address
== NULL
) {
2454 "NFS4: mount program didn't pass callback address\n");
2458 return nfs_parse_devname(dev_name
,
2459 &args
->nfs_server
.hostname
,
2461 &args
->nfs_server
.export_path
,
2466 * Validate NFSv4 mount options
2468 static int nfs4_validate_mount_data(void *options
,
2469 struct nfs_parsed_mount_data
*args
,
2470 const char *dev_name
)
2472 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2473 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2479 switch (data
->version
) {
2481 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2482 goto out_no_address
;
2483 if (data
->host_addrlen
== 0)
2484 goto out_no_address
;
2485 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2486 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2488 if (!nfs_verify_server_address(sap
))
2489 goto out_no_address
;
2491 if (data
->auth_flavourlen
) {
2492 if (data
->auth_flavourlen
> 1)
2493 goto out_inval_auth
;
2494 if (copy_from_user(&args
->auth_flavors
[0],
2495 data
->auth_flavours
,
2496 sizeof(args
->auth_flavors
[0])))
2500 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2503 args
->nfs_server
.hostname
= c
;
2505 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2508 args
->nfs_server
.export_path
= c
;
2509 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2511 c
= strndup_user(data
->client_addr
.data
, 16);
2514 args
->client_address
= c
;
2517 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2521 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2522 args
->rsize
= data
->rsize
;
2523 args
->wsize
= data
->wsize
;
2524 args
->timeo
= data
->timeo
;
2525 args
->retrans
= data
->retrans
;
2526 args
->acregmin
= data
->acregmin
;
2527 args
->acregmax
= data
->acregmax
;
2528 args
->acdirmin
= data
->acdirmin
;
2529 args
->acdirmax
= data
->acdirmax
;
2530 args
->nfs_server
.protocol
= data
->proto
;
2531 nfs_validate_transport_protocol(args
);
2535 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2538 if (!nfs_verify_server_address(sap
))
2541 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2547 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2551 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2552 data
->auth_flavourlen
);
2556 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2561 * Get the superblock for the NFS4 root partition
2563 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2564 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2566 struct nfs_parsed_mount_data
*data
= raw_data
;
2567 struct super_block
*s
;
2568 struct nfs_server
*server
;
2569 struct nfs_fh
*mntfh
;
2570 struct dentry
*mntroot
;
2571 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2572 struct nfs_sb_mountdata sb_mntdata
= {
2575 int error
= -ENOMEM
;
2577 mntfh
= nfs_alloc_fhandle();
2578 if (data
== NULL
|| mntfh
== NULL
)
2581 security_init_mnt_opts(&data
->lsm_opts
);
2583 /* Get a volume representation */
2584 server
= nfs4_create_server(data
, mntfh
);
2585 if (IS_ERR(server
)) {
2586 error
= PTR_ERR(server
);
2589 sb_mntdata
.server
= server
;
2591 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2592 compare_super
= NULL
;
2594 /* Get a superblock - note that we may end up sharing one that already exists */
2595 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2601 if (s
->s_fs_info
!= server
) {
2602 nfs_free_server(server
);
2605 error
= nfs_bdi_register(server
);
2607 goto error_splat_bdi
;
2611 /* initial superblock/root creation */
2613 nfs_fscache_get_super_cookie(
2614 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2617 mntroot
= nfs4_get_root(s
, mntfh
);
2618 if (IS_ERR(mntroot
)) {
2619 error
= PTR_ERR(mntroot
);
2620 goto error_splat_super
;
2623 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2625 goto error_splat_root
;
2627 s
->s_flags
|= MS_ACTIVE
;
2629 mnt
->mnt_root
= mntroot
;
2633 security_free_mnt_opts(&data
->lsm_opts
);
2635 nfs_free_fhandle(mntfh
);
2639 nfs_free_server(server
);
2645 if (server
&& !s
->s_root
)
2646 bdi_unregister(&server
->backing_dev_info
);
2648 deactivate_locked_super(s
);
2652 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2653 int flags
, void *data
, const char *hostname
)
2655 struct vfsmount
*root_mnt
;
2659 len
= strlen(hostname
) + 3;
2660 root_devname
= kmalloc(len
, GFP_KERNEL
);
2661 if (root_devname
== NULL
)
2662 return ERR_PTR(-ENOMEM
);
2663 snprintf(root_devname
, len
, "%s:/", hostname
);
2664 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2665 kfree(root_devname
);
2669 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2671 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2672 char *devname
, *tmp
;
2676 devname
= nfs_path(path
->mnt
->mnt_devname
,
2677 path
->mnt
->mnt_root
, path
->dentry
,
2679 if (IS_ERR(devname
))
2681 tmp
= kstrdup(devname
, GFP_KERNEL
);
2684 kfree(mnt
->mnt_devname
);
2685 mnt
->mnt_devname
= tmp
;
2687 free_page((unsigned long)page
);
2690 struct nfs_referral_count
{
2691 struct list_head list
;
2692 const struct task_struct
*task
;
2693 unsigned int referral_count
;
2696 static LIST_HEAD(nfs_referral_count_list
);
2697 static DEFINE_SPINLOCK(nfs_referral_count_list_lock
);
2699 static struct nfs_referral_count
*nfs_find_referral_count(void)
2701 struct nfs_referral_count
*p
;
2703 list_for_each_entry(p
, &nfs_referral_count_list
, list
) {
2704 if (p
->task
== current
)
2710 #define NFS_MAX_NESTED_REFERRALS 2
2712 static int nfs_referral_loop_protect(void)
2714 struct nfs_referral_count
*p
, *new;
2717 new = kmalloc(sizeof(*new), GFP_KERNEL
);
2720 new->task
= current
;
2721 new->referral_count
= 1;
2724 spin_lock(&nfs_referral_count_list_lock
);
2725 p
= nfs_find_referral_count();
2727 if (p
->referral_count
>= NFS_MAX_NESTED_REFERRALS
)
2730 p
->referral_count
++;
2732 list_add(&new->list
, &nfs_referral_count_list
);
2735 spin_unlock(&nfs_referral_count_list_lock
);
2741 static void nfs_referral_loop_unprotect(void)
2743 struct nfs_referral_count
*p
;
2745 spin_lock(&nfs_referral_count_list_lock
);
2746 p
= nfs_find_referral_count();
2747 p
->referral_count
--;
2748 if (p
->referral_count
== 0)
2752 spin_unlock(&nfs_referral_count_list_lock
);
2756 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2757 const char *export_path
, struct vfsmount
*mnt_target
)
2759 struct nameidata
*nd
= NULL
;
2760 struct mnt_namespace
*ns_private
;
2761 struct super_block
*s
;
2764 nd
= kmalloc(sizeof(*nd
), GFP_KERNEL
);
2768 ns_private
= create_mnt_ns(root_mnt
);
2769 ret
= PTR_ERR(ns_private
);
2770 if (IS_ERR(ns_private
))
2773 ret
= nfs_referral_loop_protect();
2775 goto out_put_mnt_ns
;
2777 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2778 export_path
, LOOKUP_FOLLOW
, nd
);
2780 nfs_referral_loop_unprotect();
2781 put_mnt_ns(ns_private
);
2786 s
= nd
->path
.mnt
->mnt_sb
;
2787 atomic_inc(&s
->s_active
);
2788 mnt_target
->mnt_sb
= s
;
2789 mnt_target
->mnt_root
= dget(nd
->path
.dentry
);
2791 /* Correct the device pathname */
2792 nfs_fix_devname(&nd
->path
, mnt_target
);
2794 path_put(&nd
->path
);
2796 down_write(&s
->s_umount
);
2799 put_mnt_ns(ns_private
);
2807 static int nfs4_try_mount(int flags
, const char *dev_name
,
2808 struct nfs_parsed_mount_data
*data
,
2809 struct vfsmount
*mnt
)
2812 struct vfsmount
*root_mnt
;
2815 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2817 export_path
= data
->nfs_server
.export_path
;
2818 data
->nfs_server
.export_path
= "/";
2819 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2820 data
->nfs_server
.hostname
);
2821 data
->nfs_server
.export_path
= export_path
;
2823 error
= PTR_ERR(root_mnt
);
2824 if (IS_ERR(root_mnt
))
2827 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2830 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2831 error
!= 0 ? " [error]" : "");
2836 * Get the superblock for an NFS4 mountpoint
2838 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2839 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2841 struct nfs_parsed_mount_data
*data
;
2842 int error
= -ENOMEM
;
2844 data
= nfs_alloc_parsed_mount_data(4);
2848 /* Validate the mount data */
2849 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2853 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2856 kfree(data
->client_address
);
2857 kfree(data
->nfs_server
.export_path
);
2858 kfree(data
->nfs_server
.hostname
);
2859 kfree(data
->fscache_uniq
);
2862 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2863 error
!= 0 ? " [error]" : "");
2867 static void nfs4_kill_super(struct super_block
*sb
)
2869 struct nfs_server
*server
= NFS_SB(sb
);
2871 dprintk("--> %s\n", __func__
);
2872 nfs_super_return_all_delegations(sb
);
2873 kill_anon_super(sb
);
2874 nfs_fscache_release_super_cookie(sb
);
2875 nfs_free_server(server
);
2876 dprintk("<-- %s\n", __func__
);
2880 * Clone an NFS4 server record on xdev traversal (FSID-change)
2882 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2883 const char *dev_name
, void *raw_data
,
2884 struct vfsmount
*mnt
)
2886 struct nfs_clone_mount
*data
= raw_data
;
2887 struct super_block
*s
;
2888 struct nfs_server
*server
;
2889 struct dentry
*mntroot
;
2890 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2891 struct nfs_sb_mountdata sb_mntdata
= {
2896 dprintk("--> nfs4_xdev_get_sb()\n");
2898 /* create a new volume representation */
2899 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2900 if (IS_ERR(server
)) {
2901 error
= PTR_ERR(server
);
2902 goto out_err_noserver
;
2904 sb_mntdata
.server
= server
;
2906 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2907 compare_super
= NULL
;
2909 /* Get a superblock - note that we may end up sharing one that already exists */
2910 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2916 if (s
->s_fs_info
!= server
) {
2917 nfs_free_server(server
);
2920 error
= nfs_bdi_register(server
);
2922 goto error_splat_bdi
;
2926 /* initial superblock/root creation */
2927 nfs4_clone_super(s
, data
->sb
);
2928 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2931 mntroot
= nfs4_get_root(s
, data
->fh
);
2932 if (IS_ERR(mntroot
)) {
2933 error
= PTR_ERR(mntroot
);
2934 goto error_splat_super
;
2936 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2939 goto error_splat_super
;
2942 s
->s_flags
|= MS_ACTIVE
;
2944 mnt
->mnt_root
= mntroot
;
2946 security_sb_clone_mnt_opts(data
->sb
, s
);
2948 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2952 nfs_free_server(server
);
2954 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2958 if (server
&& !s
->s_root
)
2959 bdi_unregister(&server
->backing_dev_info
);
2961 deactivate_locked_super(s
);
2962 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2966 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2967 int flags
, const char *dev_name
, void *raw_data
,
2968 struct vfsmount
*mnt
)
2970 struct nfs_clone_mount
*data
= raw_data
;
2971 struct super_block
*s
;
2972 struct nfs_server
*server
;
2973 struct dentry
*mntroot
;
2974 struct nfs_fh
*mntfh
;
2975 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2976 struct nfs_sb_mountdata sb_mntdata
= {
2979 int error
= -ENOMEM
;
2981 dprintk("--> nfs4_referral_get_sb()\n");
2983 mntfh
= nfs_alloc_fhandle();
2987 /* create a new volume representation */
2988 server
= nfs4_create_referral_server(data
, mntfh
);
2989 if (IS_ERR(server
)) {
2990 error
= PTR_ERR(server
);
2991 goto out_err_noserver
;
2993 sb_mntdata
.server
= server
;
2995 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2996 compare_super
= NULL
;
2998 /* Get a superblock - note that we may end up sharing one that already exists */
2999 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
3005 if (s
->s_fs_info
!= server
) {
3006 nfs_free_server(server
);
3009 error
= nfs_bdi_register(server
);
3011 goto error_splat_bdi
;
3015 /* initial superblock/root creation */
3017 nfs_fscache_get_super_cookie(s
, NULL
, data
);
3020 mntroot
= nfs4_get_root(s
, mntfh
);
3021 if (IS_ERR(mntroot
)) {
3022 error
= PTR_ERR(mntroot
);
3023 goto error_splat_super
;
3025 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
3028 goto error_splat_super
;
3031 s
->s_flags
|= MS_ACTIVE
;
3033 mnt
->mnt_root
= mntroot
;
3035 security_sb_clone_mnt_opts(data
->sb
, s
);
3037 nfs_free_fhandle(mntfh
);
3038 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3042 nfs_free_server(server
);
3044 nfs_free_fhandle(mntfh
);
3046 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
3050 if (server
&& !s
->s_root
)
3051 bdi_unregister(&server
->backing_dev_info
);
3053 deactivate_locked_super(s
);
3054 nfs_free_fhandle(mntfh
);
3055 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
3060 * Create an NFS4 server record on referral traversal
3062 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
3063 int flags
, const char *dev_name
, void *raw_data
,
3064 struct vfsmount
*mnt
)
3066 struct nfs_clone_mount
*data
= raw_data
;
3068 struct vfsmount
*root_mnt
;
3071 dprintk("--> nfs4_referral_get_sb()\n");
3073 export_path
= data
->mnt_path
;
3074 data
->mnt_path
= "/";
3076 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
3077 flags
, data
, data
->hostname
);
3078 data
->mnt_path
= export_path
;
3080 error
= PTR_ERR(root_mnt
);
3081 if (IS_ERR(root_mnt
))
3084 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
3086 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
3087 error
!= 0 ? " [error]" : "");
3091 #endif /* CONFIG_NFS_V4 */