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_fscache_uniq
, "fsc=%s" },
145 { Opt_nofscache
, "nofsc" },
147 { Opt_port
, "port=%s" },
148 { Opt_rsize
, "rsize=%s" },
149 { Opt_wsize
, "wsize=%s" },
150 { Opt_bsize
, "bsize=%s" },
151 { Opt_timeo
, "timeo=%s" },
152 { Opt_retrans
, "retrans=%s" },
153 { Opt_acregmin
, "acregmin=%s" },
154 { Opt_acregmax
, "acregmax=%s" },
155 { Opt_acdirmin
, "acdirmin=%s" },
156 { Opt_acdirmax
, "acdirmax=%s" },
157 { Opt_actimeo
, "actimeo=%s" },
158 { Opt_namelen
, "namlen=%s" },
159 { Opt_mountport
, "mountport=%s" },
160 { Opt_mountvers
, "mountvers=%s" },
161 { Opt_nfsvers
, "nfsvers=%s" },
162 { Opt_nfsvers
, "vers=%s" },
163 { Opt_minorversion
, "minorversion=%s" },
165 { Opt_sec
, "sec=%s" },
166 { Opt_proto
, "proto=%s" },
167 { Opt_mountproto
, "mountproto=%s" },
168 { Opt_addr
, "addr=%s" },
169 { Opt_clientaddr
, "clientaddr=%s" },
170 { Opt_mounthost
, "mounthost=%s" },
171 { Opt_mountaddr
, "mountaddr=%s" },
173 { Opt_lookupcache
, "lookupcache=%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_fattr fattr
;
427 struct nfs_fsstat res
= {
432 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
435 buf
->f_type
= NFS_SUPER_MAGIC
;
438 * Current versions of glibc do not correctly handle the
439 * case where f_frsize != f_bsize. Eventually we want to
440 * report the value of wtmult in this field.
442 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
445 * On most *nix systems, f_blocks, f_bfree, and f_bavail
446 * are reported in units of f_frsize. Linux hasn't had
447 * an f_frsize field in its statfs struct until recently,
448 * thus historically Linux's sys_statfs reports these
449 * fields in units of f_bsize.
451 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
452 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
453 blockres
= (1 << blockbits
) - 1;
454 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
455 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
456 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
458 buf
->f_files
= res
.tfiles
;
459 buf
->f_ffree
= res
.afiles
;
461 buf
->f_namelen
= server
->namelen
;
466 dprintk("%s: statfs error = %d\n", __func__
, -error
);
471 * Map the security flavour number to a name
473 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
475 static const struct {
476 rpc_authflavor_t flavour
;
479 { RPC_AUTH_NULL
, "null" },
480 { RPC_AUTH_UNIX
, "sys" },
481 { RPC_AUTH_GSS_KRB5
, "krb5" },
482 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
483 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
484 { RPC_AUTH_GSS_LKEY
, "lkey" },
485 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
486 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
487 { RPC_AUTH_GSS_SPKM
, "spkm" },
488 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
489 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
490 { UINT_MAX
, "unknown" }
494 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
495 if (sec_flavours
[i
].flavour
== flavour
)
498 return sec_flavours
[i
].str
;
501 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
504 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
506 seq_printf(m
, ",mountproto=");
507 switch (sap
->sa_family
) {
509 switch (nfss
->mountd_protocol
) {
511 seq_printf(m
, RPCBIND_NETID_UDP
);
514 seq_printf(m
, RPCBIND_NETID_TCP
);
518 seq_printf(m
, "auto");
522 switch (nfss
->mountd_protocol
) {
524 seq_printf(m
, RPCBIND_NETID_UDP6
);
527 seq_printf(m
, RPCBIND_NETID_TCP6
);
531 seq_printf(m
, "auto");
536 seq_printf(m
, "auto");
540 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
543 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
545 switch (sap
->sa_family
) {
547 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
548 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
552 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
553 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
558 seq_printf(m
, ",mountaddr=unspecified");
561 if (nfss
->mountd_version
|| showdefaults
)
562 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
563 if (nfss
->mountd_port
|| showdefaults
)
564 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
566 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
570 * Describe the mount options in force on this server representation
572 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
575 static const struct proc_nfs_info
{
580 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
581 { NFS_MOUNT_POSIX
, ",posix", "" },
582 { NFS_MOUNT_NOCTO
, ",nocto", "" },
583 { NFS_MOUNT_NOAC
, ",noac", "" },
584 { NFS_MOUNT_NONLM
, ",nolock", "" },
585 { NFS_MOUNT_NOACL
, ",noacl", "" },
586 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
587 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
588 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
591 const struct proc_nfs_info
*nfs_infop
;
592 struct nfs_client
*clp
= nfss
->nfs_client
;
593 u32 version
= clp
->rpc_ops
->version
;
595 seq_printf(m
, ",vers=%u", version
);
596 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
597 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
598 if (nfss
->bsize
!= 0)
599 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
600 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
601 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
602 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
603 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
604 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
605 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
606 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
607 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
608 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
609 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
610 if (nfss
->flags
& nfs_infop
->flag
)
611 seq_puts(m
, nfs_infop
->str
);
613 seq_puts(m
, nfs_infop
->nostr
);
615 seq_printf(m
, ",proto=%s",
616 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
618 if (nfss
->port
!= NFS_PORT
)
619 seq_printf(m
, ",port=%u", nfss
->port
);
622 seq_printf(m
, ",port=%u", nfss
->port
);
624 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
625 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
626 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
629 nfs_show_mountd_options(m
, nfss
, showdefaults
);
632 if (clp
->rpc_ops
->version
== 4)
633 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
635 if (nfss
->options
& NFS_OPTION_FSCACHE
)
636 seq_printf(m
, ",fsc");
640 * Describe the mount options on this VFS mountpoint
642 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
644 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
646 nfs_show_mount_options(m
, nfss
, 0);
648 seq_printf(m
, ",addr=%s",
649 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
656 * Present statistical information for this VFS mountpoint
658 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
661 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
662 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
663 struct nfs_iostats totals
= { };
665 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
668 * Display all mount option settings
670 seq_printf(m
, "\n\topts:\t");
671 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
672 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
673 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
674 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
675 nfs_show_mount_options(m
, nfss
, 1);
677 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
679 seq_printf(m
, "\n\tcaps:\t");
680 seq_printf(m
, "caps=0x%x", nfss
->caps
);
681 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
682 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
683 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
684 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
687 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
688 seq_printf(m
, "\n\tnfsv4:\t");
689 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
690 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
691 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
696 * Display security flavor in effect for this mount
698 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
700 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
703 * Display superblock I/O counters
705 for_each_possible_cpu(cpu
) {
706 struct nfs_iostats
*stats
;
709 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
711 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
712 totals
.events
[i
] += stats
->events
[i
];
713 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
714 totals
.bytes
[i
] += stats
->bytes
[i
];
715 #ifdef CONFIG_NFS_FSCACHE
716 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
717 totals
.fscache
[i
] += stats
->fscache
[i
];
723 seq_printf(m
, "\n\tevents:\t");
724 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
725 seq_printf(m
, "%lu ", totals
.events
[i
]);
726 seq_printf(m
, "\n\tbytes:\t");
727 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
728 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
729 #ifdef CONFIG_NFS_FSCACHE
730 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
731 seq_printf(m
, "\n\tfsc:\t");
732 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
733 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
738 rpc_print_iostats(m
, nfss
->client
);
744 * Begin unmount by attempting to remove all automounted mountpoints we added
745 * in response to xdev traversals and referrals
747 static void nfs_umount_begin(struct super_block
*sb
)
749 struct nfs_server
*server
;
750 struct rpc_clnt
*rpc
;
753 /* -EIO all pending I/O */
754 rpc
= server
->client_acl
;
756 rpc_killall_tasks(rpc
);
757 rpc
= server
->client
;
759 rpc_killall_tasks(rpc
);
762 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
764 struct nfs_parsed_mount_data
*data
;
766 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
768 data
->acregmin
= NFS_DEF_ACREGMIN
;
769 data
->acregmax
= NFS_DEF_ACREGMAX
;
770 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
771 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
772 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
773 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
774 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
775 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
776 data
->auth_flavor_len
= 1;
777 data
->version
= version
;
778 data
->minorversion
= 0;
784 * Sanity-check a server address provided by the mount command.
786 * Address family must be initialized, and address must not be
787 * the ANY address for that family.
789 static int nfs_verify_server_address(struct sockaddr
*addr
)
791 switch (addr
->sa_family
) {
793 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
794 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
797 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
798 return !ipv6_addr_any(sa
);
802 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
807 * Select between a default port value and a user-specified port value.
808 * If a zero value is set, then autobind will be used.
810 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
811 const unsigned short default_port
)
813 if (*port
== NFS_UNSPEC_PORT
)
814 *port
= default_port
;
816 rpc_set_port(sap
, *port
);
820 * Sanity check the NFS transport protocol.
823 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
825 switch (mnt
->nfs_server
.protocol
) {
826 case XPRT_TRANSPORT_UDP
:
827 case XPRT_TRANSPORT_TCP
:
828 case XPRT_TRANSPORT_RDMA
:
831 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
836 * For text based NFSv2/v3 mounts, the mount protocol transport default
837 * settings should depend upon the specified NFS transport.
839 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
841 nfs_validate_transport_protocol(mnt
);
843 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
844 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
846 switch (mnt
->nfs_server
.protocol
) {
847 case XPRT_TRANSPORT_UDP
:
848 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
850 case XPRT_TRANSPORT_TCP
:
851 case XPRT_TRANSPORT_RDMA
:
852 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
857 * Parse the value of the 'sec=' option.
859 static int nfs_parse_security_flavors(char *value
,
860 struct nfs_parsed_mount_data
*mnt
)
862 substring_t args
[MAX_OPT_ARGS
];
864 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
866 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
868 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
871 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
874 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
877 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
880 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
883 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
886 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
889 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
892 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
895 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
898 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
904 mnt
->auth_flavor_len
= 1;
909 * Error-check and convert a string of mount options from user space into
910 * a data structure. The whole mount string is processed; bad options are
911 * skipped as they are encountered. If there were no errors, return 1;
912 * otherwise return 0 (zero).
914 static int nfs_parse_mount_options(char *raw
,
915 struct nfs_parsed_mount_data
*mnt
)
917 char *p
, *string
, *secdata
;
918 int rc
, sloppy
= 0, invalid_option
= 0;
919 unsigned short protofamily
= AF_UNSPEC
;
920 unsigned short mountfamily
= AF_UNSPEC
;
923 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
926 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
928 secdata
= alloc_secdata();
932 rc
= security_sb_copy_data(raw
, secdata
);
934 goto out_security_failure
;
936 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
938 goto out_security_failure
;
940 free_secdata(secdata
);
942 while ((p
= strsep(&raw
, ",")) != NULL
) {
943 substring_t args
[MAX_OPT_ARGS
];
944 unsigned long option
;
950 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
952 token
= match_token(p
, nfs_mount_option_tokens
, args
);
956 * boolean options: foo/nofoo
959 mnt
->flags
|= NFS_MOUNT_SOFT
;
962 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
965 mnt
->flags
|= NFS_MOUNT_POSIX
;
968 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
971 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
974 mnt
->flags
|= NFS_MOUNT_NOCTO
;
977 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
980 mnt
->flags
|= NFS_MOUNT_NOAC
;
983 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
986 mnt
->flags
|= NFS_MOUNT_NONLM
;
989 mnt
->flags
&= ~NFS_MOUNT_VER3
;
993 mnt
->flags
|= NFS_MOUNT_VER3
;
998 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1003 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1004 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1007 mnt
->flags
|= NFS_MOUNT_TCP
;
1008 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1011 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1012 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1013 xprt_load_transport(p
);
1016 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1019 mnt
->flags
|= NFS_MOUNT_NOACL
;
1022 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1024 case Opt_nordirplus
:
1025 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1027 case Opt_sharecache
:
1028 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1030 case Opt_nosharecache
:
1031 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1034 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1036 case Opt_noresvport
:
1037 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1040 mnt
->options
|= NFS_OPTION_FSCACHE
;
1041 kfree(mnt
->fscache_uniq
);
1042 mnt
->fscache_uniq
= NULL
;
1045 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1046 kfree(mnt
->fscache_uniq
);
1047 mnt
->fscache_uniq
= NULL
;
1049 case Opt_fscache_uniq
:
1050 string
= match_strdup(args
);
1053 kfree(mnt
->fscache_uniq
);
1054 mnt
->fscache_uniq
= string
;
1055 mnt
->options
|= NFS_OPTION_FSCACHE
;
1059 * options that take numeric values
1062 string
= match_strdup(args
);
1065 rc
= strict_strtoul(string
, 10, &option
);
1067 if (rc
!= 0 || option
> USHORT_MAX
)
1068 goto out_invalid_value
;
1069 mnt
->nfs_server
.port
= option
;
1072 string
= match_strdup(args
);
1075 rc
= strict_strtoul(string
, 10, &option
);
1078 goto out_invalid_value
;
1079 mnt
->rsize
= option
;
1082 string
= match_strdup(args
);
1085 rc
= strict_strtoul(string
, 10, &option
);
1088 goto out_invalid_value
;
1089 mnt
->wsize
= option
;
1092 string
= match_strdup(args
);
1095 rc
= strict_strtoul(string
, 10, &option
);
1098 goto out_invalid_value
;
1099 mnt
->bsize
= option
;
1102 string
= match_strdup(args
);
1105 rc
= strict_strtoul(string
, 10, &option
);
1107 if (rc
!= 0 || option
== 0)
1108 goto out_invalid_value
;
1109 mnt
->timeo
= 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
->retrans
= option
;
1122 string
= match_strdup(args
);
1125 rc
= strict_strtoul(string
, 10, &option
);
1128 goto out_invalid_value
;
1129 mnt
->acregmin
= option
;
1132 string
= match_strdup(args
);
1135 rc
= strict_strtoul(string
, 10, &option
);
1138 goto out_invalid_value
;
1139 mnt
->acregmax
= option
;
1142 string
= match_strdup(args
);
1145 rc
= strict_strtoul(string
, 10, &option
);
1148 goto out_invalid_value
;
1149 mnt
->acdirmin
= option
;
1152 string
= match_strdup(args
);
1155 rc
= strict_strtoul(string
, 10, &option
);
1158 goto out_invalid_value
;
1159 mnt
->acdirmax
= option
;
1162 string
= match_strdup(args
);
1165 rc
= strict_strtoul(string
, 10, &option
);
1168 goto out_invalid_value
;
1169 mnt
->acregmin
= mnt
->acregmax
=
1170 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1173 string
= match_strdup(args
);
1176 rc
= strict_strtoul(string
, 10, &option
);
1179 goto out_invalid_value
;
1180 mnt
->namlen
= option
;
1183 string
= match_strdup(args
);
1186 rc
= strict_strtoul(string
, 10, &option
);
1188 if (rc
!= 0 || option
> USHORT_MAX
)
1189 goto out_invalid_value
;
1190 mnt
->mount_server
.port
= option
;
1193 string
= match_strdup(args
);
1196 rc
= strict_strtoul(string
, 10, &option
);
1199 option
< NFS_MNT_VERSION
||
1200 option
> NFS_MNT3_VERSION
)
1201 goto out_invalid_value
;
1202 mnt
->mount_server
.version
= option
;
1205 string
= match_strdup(args
);
1208 rc
= strict_strtoul(string
, 10, &option
);
1211 goto out_invalid_value
;
1214 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1218 mnt
->flags
|= NFS_MOUNT_VER3
;
1221 #ifdef CONFIG_NFS_V4
1223 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1228 goto out_invalid_value
;
1231 case Opt_minorversion
:
1232 string
= match_strdup(args
);
1235 rc
= strict_strtoul(string
, 10, &option
);
1238 goto out_invalid_value
;
1239 if (option
> NFS4_MAX_MINOR_VERSION
)
1240 goto out_invalid_value
;
1241 mnt
->minorversion
= option
;
1245 * options that take text values
1248 string
= match_strdup(args
);
1251 rc
= nfs_parse_security_flavors(string
, mnt
);
1254 dfprintk(MOUNT
, "NFS: unrecognized "
1255 "security flavor\n");
1260 string
= match_strdup(args
);
1263 token
= match_token(string
,
1264 nfs_xprt_protocol_tokens
, args
);
1266 protofamily
= AF_INET
;
1269 protofamily
= AF_INET6
;
1271 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1272 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1276 protofamily
= AF_INET6
;
1278 mnt
->flags
|= NFS_MOUNT_TCP
;
1279 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1283 /* vector side protocols to TCP */
1284 mnt
->flags
|= NFS_MOUNT_TCP
;
1285 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1286 xprt_load_transport(string
);
1290 dfprintk(MOUNT
, "NFS: unrecognized "
1291 "transport protocol\n");
1296 case Opt_mountproto
:
1297 string
= match_strdup(args
);
1300 token
= match_token(string
,
1301 nfs_xprt_protocol_tokens
, args
);
1304 mountfamily
= AF_INET
;
1307 mountfamily
= AF_INET6
;
1309 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1312 mountfamily
= AF_INET6
;
1314 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1316 case Opt_xprt_rdma
: /* not used for side protocols */
1318 dfprintk(MOUNT
, "NFS: unrecognized "
1319 "transport protocol\n");
1324 string
= match_strdup(args
);
1327 mnt
->nfs_server
.addrlen
=
1328 rpc_pton(string
, strlen(string
),
1330 &mnt
->nfs_server
.address
,
1331 sizeof(mnt
->nfs_server
.address
));
1333 if (mnt
->nfs_server
.addrlen
== 0)
1334 goto out_invalid_address
;
1336 case Opt_clientaddr
:
1337 string
= match_strdup(args
);
1340 kfree(mnt
->client_address
);
1341 mnt
->client_address
= string
;
1344 string
= match_strdup(args
);
1347 kfree(mnt
->mount_server
.hostname
);
1348 mnt
->mount_server
.hostname
= string
;
1351 string
= match_strdup(args
);
1354 mnt
->mount_server
.addrlen
=
1355 rpc_pton(string
, strlen(string
),
1357 &mnt
->mount_server
.address
,
1358 sizeof(mnt
->mount_server
.address
));
1360 if (mnt
->mount_server
.addrlen
== 0)
1361 goto out_invalid_address
;
1363 case Opt_lookupcache
:
1364 string
= match_strdup(args
);
1367 token
= match_token(string
,
1368 nfs_lookupcache_tokens
, args
);
1371 case Opt_lookupcache_all
:
1372 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1374 case Opt_lookupcache_positive
:
1375 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1376 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1378 case Opt_lookupcache_none
:
1379 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1382 dfprintk(MOUNT
, "NFS: invalid "
1383 "lookupcache argument\n");
1393 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1396 case Opt_deprecated
:
1397 dfprintk(MOUNT
, "NFS: ignoring mount option "
1403 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1408 if (!sloppy
&& invalid_option
)
1412 * verify that any proto=/mountproto= options match the address
1413 * familiies in the addr=/mountaddr= options.
1415 if (protofamily
!= AF_UNSPEC
&&
1416 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1417 goto out_proto_mismatch
;
1419 if (mountfamily
!= AF_UNSPEC
) {
1420 if (mnt
->mount_server
.addrlen
) {
1421 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1422 goto out_mountproto_mismatch
;
1424 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1425 goto out_mountproto_mismatch
;
1431 out_mountproto_mismatch
:
1432 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1436 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1438 out_invalid_address
:
1439 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1442 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1445 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1447 out_security_failure
:
1448 free_secdata(secdata
);
1449 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1454 * Match the requested auth flavors with the list returned by
1455 * the server. Returns zero and sets the mount's authentication
1456 * flavor on success; returns -EACCES if server does not support
1457 * the requested flavor.
1459 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1460 struct nfs_mount_request
*request
)
1462 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1465 * Certain releases of Linux's mountd return an empty
1466 * flavor list. To prevent behavioral regression with
1467 * these servers (ie. rejecting mounts that used to
1468 * succeed), revert to pre-2.6.32 behavior (no checking)
1469 * if the returned flavor list is empty.
1471 if (server_authlist_len
== 0)
1475 * We avoid sophisticated negotiating here, as there are
1476 * plenty of cases where we can get it wrong, providing
1477 * either too little or too much security.
1479 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1480 * flavor listed first. However, some servers list
1481 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1482 * preferred default, in args->auth_flavors[0] if user
1483 * didn't specify sec= mount option.
1485 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1486 for (j
= 0; j
< server_authlist_len
; j
++)
1487 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1488 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1489 request
->auth_flavs
[j
]);
1490 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1494 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1495 nfs_umount(request
);
1500 * Use the remote server's MOUNT service to request the NFS file handle
1501 * corresponding to the provided path.
1503 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1504 struct nfs_fh
*root_fh
)
1506 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1507 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1508 struct nfs_mount_request request
= {
1509 .sap
= (struct sockaddr
*)
1510 &args
->mount_server
.address
,
1511 .dirpath
= args
->nfs_server
.export_path
,
1512 .protocol
= args
->mount_server
.protocol
,
1514 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1515 .auth_flav_len
= &server_authlist_len
,
1516 .auth_flavs
= server_authlist
,
1520 if (args
->mount_server
.version
== 0) {
1521 switch (args
->version
) {
1523 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1526 args
->mount_server
.version
= NFS_MNT_VERSION
;
1529 request
.version
= args
->mount_server
.version
;
1531 if (args
->mount_server
.hostname
)
1532 request
.hostname
= args
->mount_server
.hostname
;
1534 request
.hostname
= args
->nfs_server
.hostname
;
1537 * Construct the mount server's address.
1539 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1540 memcpy(request
.sap
, &args
->nfs_server
.address
,
1541 args
->nfs_server
.addrlen
);
1542 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1544 request
.salen
= args
->mount_server
.addrlen
;
1545 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1548 * Now ask the mount server to map our export path
1551 status
= nfs_mount(&request
);
1553 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1554 request
.hostname
, status
);
1559 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1561 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1563 return nfs_walk_authlist(args
, &request
);
1566 static int nfs_parse_simple_hostname(const char *dev_name
,
1567 char **hostname
, size_t maxnamlen
,
1568 char **export_path
, size_t maxpathlen
)
1571 char *colon
, *comma
;
1573 colon
= strchr(dev_name
, ':');
1575 goto out_bad_devname
;
1577 len
= colon
- dev_name
;
1578 if (len
> maxnamlen
)
1581 /* N.B. caller will free nfs_server.hostname in all cases */
1582 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1586 /* kill possible hostname list: not supported */
1587 comma
= strchr(*hostname
, ',');
1588 if (comma
!= NULL
) {
1589 if (comma
== *hostname
)
1590 goto out_bad_devname
;
1595 len
= strlen(colon
);
1596 if (len
> maxpathlen
)
1598 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1602 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1606 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1610 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1614 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1615 return -ENAMETOOLONG
;
1618 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1619 return -ENAMETOOLONG
;
1623 * Hostname has square brackets around it because it contains one or
1624 * more colons. We look for the first closing square bracket, and a
1625 * colon must follow it.
1627 static int nfs_parse_protected_hostname(const char *dev_name
,
1628 char **hostname
, size_t maxnamlen
,
1629 char **export_path
, size_t maxpathlen
)
1634 start
= (char *)(dev_name
+ 1);
1636 end
= strchr(start
, ']');
1638 goto out_bad_devname
;
1639 if (*(end
+ 1) != ':')
1640 goto out_bad_devname
;
1643 if (len
> maxnamlen
)
1646 /* N.B. caller will free nfs_server.hostname in all cases */
1647 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1648 if (*hostname
== NULL
)
1653 if (len
> maxpathlen
)
1655 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1662 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1666 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1670 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1671 return -ENAMETOOLONG
;
1674 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1675 return -ENAMETOOLONG
;
1679 * Split "dev_name" into "hostname:export_path".
1681 * The leftmost colon demarks the split between the server's hostname
1682 * and the export path. If the hostname starts with a left square
1683 * bracket, then it may contain colons.
1685 * Note: caller frees hostname and export path, even on error.
1687 static int nfs_parse_devname(const char *dev_name
,
1688 char **hostname
, size_t maxnamlen
,
1689 char **export_path
, size_t maxpathlen
)
1691 if (*dev_name
== '[')
1692 return nfs_parse_protected_hostname(dev_name
,
1693 hostname
, maxnamlen
,
1694 export_path
, maxpathlen
);
1696 return nfs_parse_simple_hostname(dev_name
,
1697 hostname
, maxnamlen
,
1698 export_path
, maxpathlen
);
1702 * Validate the NFS2/NFS3 mount data
1703 * - fills in the mount root filehandle
1705 * For option strings, user space handles the following behaviors:
1707 * + DNS: mapping server host name to IP address ("addr=" option)
1709 * + failure mode: how to behave if a mount request can't be handled
1710 * immediately ("fg/bg" option)
1712 * + retry: how often to retry a mount request ("retry=" option)
1714 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1715 * mountproto=tcp after mountproto=udp, and so on
1717 static int nfs_validate_mount_data(void *options
,
1718 struct nfs_parsed_mount_data
*args
,
1719 struct nfs_fh
*mntfh
,
1720 const char *dev_name
)
1722 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1723 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1728 switch (data
->version
) {
1734 if (data
->flags
& NFS_MOUNT_VER3
)
1736 data
->root
.size
= NFS2_FHSIZE
;
1737 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1739 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1742 memset(data
->context
, 0, sizeof(data
->context
));
1744 if (data
->flags
& NFS_MOUNT_VER3
) {
1745 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1746 goto out_invalid_fh
;
1747 mntfh
->size
= data
->root
.size
;
1750 mntfh
->size
= NFS2_FHSIZE
;
1755 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1756 if (mntfh
->size
< sizeof(mntfh
->data
))
1757 memset(mntfh
->data
+ mntfh
->size
, 0,
1758 sizeof(mntfh
->data
) - mntfh
->size
);
1761 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1764 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1765 args
->rsize
= data
->rsize
;
1766 args
->wsize
= data
->wsize
;
1767 args
->timeo
= data
->timeo
;
1768 args
->retrans
= data
->retrans
;
1769 args
->acregmin
= data
->acregmin
;
1770 args
->acregmax
= data
->acregmax
;
1771 args
->acdirmin
= data
->acdirmin
;
1772 args
->acdirmax
= data
->acdirmax
;
1774 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1775 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1776 if (!nfs_verify_server_address(sap
))
1777 goto out_no_address
;
1779 if (!(data
->flags
& NFS_MOUNT_TCP
))
1780 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1781 /* N.B. caller will free nfs_server.hostname in all cases */
1782 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1783 args
->namlen
= data
->namlen
;
1784 args
->bsize
= data
->bsize
;
1786 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1787 args
->auth_flavors
[0] = data
->pseudoflavor
;
1788 if (!args
->nfs_server
.hostname
)
1792 * The legacy version 6 binary mount data from userspace has a
1793 * field used only to transport selinux information into the
1794 * the kernel. To continue to support that functionality we
1795 * have a touch of selinux knowledge here in the NFS code. The
1796 * userspace code converted context=blah to just blah so we are
1797 * converting back to the full string selinux understands.
1799 if (data
->context
[0]){
1800 #ifdef CONFIG_SECURITY_SELINUX
1802 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1805 strcpy(opts_str
, "context=");
1806 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1807 strcat(opts_str
, &data
->context
[0]);
1808 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1821 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1824 if (!nfs_verify_server_address(sap
))
1825 goto out_no_address
;
1827 if (args
->version
== 4)
1828 #ifdef CONFIG_NFS_V4
1829 return nfs4_validate_text_mount_data(options
,
1832 goto out_v4_not_compiled
;
1835 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1837 nfs_set_mount_transport_protocol(args
);
1839 status
= nfs_parse_devname(dev_name
,
1840 &args
->nfs_server
.hostname
,
1842 &args
->nfs_server
.export_path
,
1845 status
= nfs_try_mount(args
, mntfh
);
1847 kfree(args
->nfs_server
.export_path
);
1848 args
->nfs_server
.export_path
= NULL
;
1857 #ifndef CONFIG_NFS_V3
1858 if (args
->version
== 3)
1859 goto out_v3_not_compiled
;
1860 #endif /* !CONFIG_NFS_V3 */
1865 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1869 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1874 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1877 #ifndef CONFIG_NFS_V3
1878 out_v3_not_compiled
:
1879 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1880 return -EPROTONOSUPPORT
;
1881 #endif /* !CONFIG_NFS_V3 */
1883 #ifndef CONFIG_NFS_V4
1884 out_v4_not_compiled
:
1885 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1886 return -EPROTONOSUPPORT
;
1887 #endif /* !CONFIG_NFS_V4 */
1890 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1894 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1898 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1903 nfs_compare_remount_data(struct nfs_server
*nfss
,
1904 struct nfs_parsed_mount_data
*data
)
1906 if (data
->flags
!= nfss
->flags
||
1907 data
->rsize
!= nfss
->rsize
||
1908 data
->wsize
!= nfss
->wsize
||
1909 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1910 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1911 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1912 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1913 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1914 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1915 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1916 data
->nfs_server
.port
!= nfss
->port
||
1917 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1918 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
1919 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
1926 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1929 struct nfs_server
*nfss
= sb
->s_fs_info
;
1930 struct nfs_parsed_mount_data
*data
;
1931 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1932 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1933 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1936 * Userspace mount programs that send binary options generally send
1937 * them populated with default values. We have no way to know which
1938 * ones were explicitly specified. Fall back to legacy behavior and
1939 * just return success.
1941 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1942 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1943 options
->version
<= 6))))
1946 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1950 /* fill out struct with values from existing mount */
1951 data
->flags
= nfss
->flags
;
1952 data
->rsize
= nfss
->rsize
;
1953 data
->wsize
= nfss
->wsize
;
1954 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1955 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1956 data
->acregmin
= nfss
->acregmin
/ HZ
;
1957 data
->acregmax
= nfss
->acregmax
/ HZ
;
1958 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1959 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1960 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1961 data
->nfs_server
.port
= nfss
->port
;
1962 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1963 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1964 data
->nfs_server
.addrlen
);
1966 /* overwrite those values with any that were specified */
1967 error
= nfs_parse_mount_options((char *)options
, data
);
1971 /* compare new mount options with old ones */
1972 error
= nfs_compare_remount_data(nfss
, data
);
1979 * Initialise the common bits of the superblock
1981 static inline void nfs_initialise_sb(struct super_block
*sb
)
1983 struct nfs_server
*server
= NFS_SB(sb
);
1985 sb
->s_magic
= NFS_SUPER_MAGIC
;
1987 /* We probably want something more informative here */
1988 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1989 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1991 if (sb
->s_blocksize
== 0)
1992 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1993 &sb
->s_blocksize_bits
);
1995 if (server
->flags
& NFS_MOUNT_NOAC
)
1996 sb
->s_flags
|= MS_SYNCHRONOUS
;
1998 sb
->s_bdi
= &server
->backing_dev_info
;
2000 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2004 * Finish setting up an NFS2/3 superblock
2006 static void nfs_fill_super(struct super_block
*sb
,
2007 struct nfs_parsed_mount_data
*data
)
2009 struct nfs_server
*server
= NFS_SB(sb
);
2011 sb
->s_blocksize_bits
= 0;
2012 sb
->s_blocksize
= 0;
2014 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2016 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2017 /* The VFS shouldn't apply the umask to mode bits. We will do
2018 * so ourselves when necessary.
2020 sb
->s_flags
|= MS_POSIXACL
;
2021 sb
->s_time_gran
= 1;
2024 sb
->s_op
= &nfs_sops
;
2025 nfs_initialise_sb(sb
);
2029 * Finish setting up a cloned NFS2/3 superblock
2031 static void nfs_clone_super(struct super_block
*sb
,
2032 const struct super_block
*old_sb
)
2034 struct nfs_server
*server
= NFS_SB(sb
);
2036 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2037 sb
->s_blocksize
= old_sb
->s_blocksize
;
2038 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2040 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2041 /* The VFS shouldn't apply the umask to mode bits. We will do
2042 * so ourselves when necessary.
2044 sb
->s_flags
|= MS_POSIXACL
;
2045 sb
->s_time_gran
= 1;
2048 sb
->s_op
= old_sb
->s_op
;
2049 nfs_initialise_sb(sb
);
2052 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2054 const struct nfs_server
*a
= s
->s_fs_info
;
2055 const struct rpc_clnt
*clnt_a
= a
->client
;
2056 const struct rpc_clnt
*clnt_b
= b
->client
;
2058 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2060 if (a
->nfs_client
!= b
->nfs_client
)
2062 if (a
->flags
!= b
->flags
)
2064 if (a
->wsize
!= b
->wsize
)
2066 if (a
->rsize
!= b
->rsize
)
2068 if (a
->acregmin
!= b
->acregmin
)
2070 if (a
->acregmax
!= b
->acregmax
)
2072 if (a
->acdirmin
!= b
->acdirmin
)
2074 if (a
->acdirmax
!= b
->acdirmax
)
2076 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2083 struct nfs_sb_mountdata
{
2084 struct nfs_server
*server
;
2088 static int nfs_set_super(struct super_block
*s
, void *data
)
2090 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2091 struct nfs_server
*server
= sb_mntdata
->server
;
2094 s
->s_flags
= sb_mntdata
->mntflags
;
2095 s
->s_fs_info
= server
;
2096 ret
= set_anon_super(s
, server
);
2098 server
->s_dev
= s
->s_dev
;
2102 static int nfs_compare_super_address(struct nfs_server
*server1
,
2103 struct nfs_server
*server2
)
2105 struct sockaddr
*sap1
, *sap2
;
2107 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2108 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2110 if (sap1
->sa_family
!= sap2
->sa_family
)
2113 switch (sap1
->sa_family
) {
2115 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2116 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2117 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2119 if (sin1
->sin_port
!= sin2
->sin_port
)
2124 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2125 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2126 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2128 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2139 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2141 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2142 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2143 int mntflags
= sb_mntdata
->mntflags
;
2145 if (!nfs_compare_super_address(old
, server
))
2147 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2148 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2150 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2152 return nfs_compare_mount_options(sb
, server
, mntflags
);
2155 static int nfs_bdi_register(struct nfs_server
*server
)
2157 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2160 static int nfs_get_sb(struct file_system_type
*fs_type
,
2161 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2163 struct nfs_server
*server
= NULL
;
2164 struct super_block
*s
;
2165 struct nfs_parsed_mount_data
*data
;
2166 struct nfs_fh
*mntfh
;
2167 struct dentry
*mntroot
;
2168 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2169 struct nfs_sb_mountdata sb_mntdata
= {
2172 int error
= -ENOMEM
;
2174 data
= nfs_alloc_parsed_mount_data(3);
2175 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2176 if (data
== NULL
|| mntfh
== NULL
)
2179 security_init_mnt_opts(&data
->lsm_opts
);
2181 /* Validate the mount data */
2182 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2186 #ifdef CONFIG_NFS_V4
2187 if (data
->version
== 4) {
2188 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2189 kfree(data
->client_address
);
2192 #endif /* CONFIG_NFS_V4 */
2194 /* Get a volume representation */
2195 server
= nfs_create_server(data
, mntfh
);
2196 if (IS_ERR(server
)) {
2197 error
= PTR_ERR(server
);
2200 sb_mntdata
.server
= server
;
2202 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2203 compare_super
= NULL
;
2205 /* Get a superblock - note that we may end up sharing one that already exists */
2206 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2212 if (s
->s_fs_info
!= server
) {
2213 nfs_free_server(server
);
2216 error
= nfs_bdi_register(server
);
2218 goto error_splat_bdi
;
2222 /* initial superblock/root creation */
2223 nfs_fill_super(s
, data
);
2224 nfs_fscache_get_super_cookie(
2225 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2228 mntroot
= nfs_get_root(s
, mntfh
);
2229 if (IS_ERR(mntroot
)) {
2230 error
= PTR_ERR(mntroot
);
2231 goto error_splat_super
;
2234 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2236 goto error_splat_root
;
2238 s
->s_flags
|= MS_ACTIVE
;
2240 mnt
->mnt_root
= mntroot
;
2244 kfree(data
->nfs_server
.hostname
);
2245 kfree(data
->mount_server
.hostname
);
2246 kfree(data
->fscache_uniq
);
2247 security_free_mnt_opts(&data
->lsm_opts
);
2254 nfs_free_server(server
);
2260 if (server
&& !s
->s_root
)
2261 bdi_unregister(&server
->backing_dev_info
);
2263 deactivate_locked_super(s
);
2268 * Ensure that we unregister the bdi before kill_anon_super
2269 * releases the device name
2271 static void nfs_put_super(struct super_block
*s
)
2273 struct nfs_server
*server
= NFS_SB(s
);
2275 bdi_unregister(&server
->backing_dev_info
);
2279 * Destroy an NFS2/3 superblock
2281 static void nfs_kill_super(struct super_block
*s
)
2283 struct nfs_server
*server
= NFS_SB(s
);
2286 nfs_fscache_release_super_cookie(s
);
2287 nfs_free_server(server
);
2291 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2293 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2294 const char *dev_name
, void *raw_data
,
2295 struct vfsmount
*mnt
)
2297 struct nfs_clone_mount
*data
= raw_data
;
2298 struct super_block
*s
;
2299 struct nfs_server
*server
;
2300 struct dentry
*mntroot
;
2301 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2302 struct nfs_sb_mountdata sb_mntdata
= {
2307 dprintk("--> nfs_xdev_get_sb()\n");
2309 /* create a new volume representation */
2310 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2311 if (IS_ERR(server
)) {
2312 error
= PTR_ERR(server
);
2313 goto out_err_noserver
;
2315 sb_mntdata
.server
= server
;
2317 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2318 compare_super
= NULL
;
2320 /* Get a superblock - note that we may end up sharing one that already exists */
2321 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2327 if (s
->s_fs_info
!= server
) {
2328 nfs_free_server(server
);
2331 error
= nfs_bdi_register(server
);
2333 goto error_splat_bdi
;
2337 /* initial superblock/root creation */
2338 nfs_clone_super(s
, data
->sb
);
2339 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2342 mntroot
= nfs_get_root(s
, data
->fh
);
2343 if (IS_ERR(mntroot
)) {
2344 error
= PTR_ERR(mntroot
);
2345 goto error_splat_super
;
2347 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2350 goto error_splat_super
;
2353 s
->s_flags
|= MS_ACTIVE
;
2355 mnt
->mnt_root
= mntroot
;
2357 /* clone any lsm security options from the parent to the new sb */
2358 security_sb_clone_mnt_opts(data
->sb
, s
);
2360 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2364 nfs_free_server(server
);
2366 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2370 if (server
&& !s
->s_root
)
2371 bdi_unregister(&server
->backing_dev_info
);
2373 deactivate_locked_super(s
);
2374 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2378 #ifdef CONFIG_NFS_V4
2381 * Finish setting up a cloned NFS4 superblock
2383 static void nfs4_clone_super(struct super_block
*sb
,
2384 const struct super_block
*old_sb
)
2386 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2387 sb
->s_blocksize
= old_sb
->s_blocksize
;
2388 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2389 sb
->s_time_gran
= 1;
2390 sb
->s_op
= old_sb
->s_op
;
2391 nfs_initialise_sb(sb
);
2395 * Set up an NFS4 superblock
2397 static void nfs4_fill_super(struct super_block
*sb
)
2399 sb
->s_time_gran
= 1;
2400 sb
->s_op
= &nfs4_sops
;
2401 nfs_initialise_sb(sb
);
2404 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2406 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2409 static int nfs4_validate_text_mount_data(void *options
,
2410 struct nfs_parsed_mount_data
*args
,
2411 const char *dev_name
)
2413 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2415 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2417 nfs_validate_transport_protocol(args
);
2419 nfs4_validate_mount_flags(args
);
2421 if (args
->version
!= 4) {
2423 "NFS4: Illegal mount version\n");
2427 if (args
->auth_flavor_len
> 1) {
2429 "NFS4: Too many RPC auth flavours specified\n");
2433 if (args
->client_address
== NULL
) {
2435 "NFS4: mount program didn't pass callback address\n");
2439 return nfs_parse_devname(dev_name
,
2440 &args
->nfs_server
.hostname
,
2442 &args
->nfs_server
.export_path
,
2447 * Validate NFSv4 mount options
2449 static int nfs4_validate_mount_data(void *options
,
2450 struct nfs_parsed_mount_data
*args
,
2451 const char *dev_name
)
2453 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2454 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2460 switch (data
->version
) {
2462 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2463 goto out_no_address
;
2464 if (data
->host_addrlen
== 0)
2465 goto out_no_address
;
2466 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2467 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2469 if (!nfs_verify_server_address(sap
))
2470 goto out_no_address
;
2472 if (data
->auth_flavourlen
) {
2473 if (data
->auth_flavourlen
> 1)
2474 goto out_inval_auth
;
2475 if (copy_from_user(&args
->auth_flavors
[0],
2476 data
->auth_flavours
,
2477 sizeof(args
->auth_flavors
[0])))
2481 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2484 args
->nfs_server
.hostname
= c
;
2486 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2489 args
->nfs_server
.export_path
= c
;
2490 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2492 c
= strndup_user(data
->client_addr
.data
, 16);
2495 args
->client_address
= c
;
2498 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2502 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2503 args
->rsize
= data
->rsize
;
2504 args
->wsize
= data
->wsize
;
2505 args
->timeo
= data
->timeo
;
2506 args
->retrans
= data
->retrans
;
2507 args
->acregmin
= data
->acregmin
;
2508 args
->acregmax
= data
->acregmax
;
2509 args
->acdirmin
= data
->acdirmin
;
2510 args
->acdirmax
= data
->acdirmax
;
2511 args
->nfs_server
.protocol
= data
->proto
;
2512 nfs_validate_transport_protocol(args
);
2516 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2519 if (!nfs_verify_server_address(sap
))
2522 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2528 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2532 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2533 data
->auth_flavourlen
);
2537 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2542 * Get the superblock for the NFS4 root partition
2544 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2545 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2547 struct nfs_parsed_mount_data
*data
= raw_data
;
2548 struct super_block
*s
;
2549 struct nfs_server
*server
;
2550 struct nfs_fh
*mntfh
;
2551 struct dentry
*mntroot
;
2552 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2553 struct nfs_sb_mountdata sb_mntdata
= {
2556 int error
= -ENOMEM
;
2558 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2559 if (data
== NULL
|| mntfh
== NULL
)
2562 security_init_mnt_opts(&data
->lsm_opts
);
2564 /* Get a volume representation */
2565 server
= nfs4_create_server(data
, mntfh
);
2566 if (IS_ERR(server
)) {
2567 error
= PTR_ERR(server
);
2570 sb_mntdata
.server
= server
;
2572 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2573 compare_super
= NULL
;
2575 /* Get a superblock - note that we may end up sharing one that already exists */
2576 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2582 if (s
->s_fs_info
!= server
) {
2583 nfs_free_server(server
);
2586 error
= nfs_bdi_register(server
);
2588 goto error_splat_bdi
;
2592 /* initial superblock/root creation */
2594 nfs_fscache_get_super_cookie(
2595 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2598 mntroot
= nfs4_get_root(s
, mntfh
);
2599 if (IS_ERR(mntroot
)) {
2600 error
= PTR_ERR(mntroot
);
2601 goto error_splat_super
;
2604 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2606 goto error_splat_root
;
2608 s
->s_flags
|= MS_ACTIVE
;
2610 mnt
->mnt_root
= mntroot
;
2614 security_free_mnt_opts(&data
->lsm_opts
);
2620 nfs_free_server(server
);
2626 if (server
&& !s
->s_root
)
2627 bdi_unregister(&server
->backing_dev_info
);
2629 deactivate_locked_super(s
);
2633 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2634 int flags
, void *data
, const char *hostname
)
2636 struct vfsmount
*root_mnt
;
2640 len
= strlen(hostname
) + 3;
2641 root_devname
= kmalloc(len
, GFP_KERNEL
);
2642 if (root_devname
== NULL
)
2643 return ERR_PTR(-ENOMEM
);
2644 snprintf(root_devname
, len
, "%s:/", hostname
);
2645 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2646 kfree(root_devname
);
2650 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2652 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2653 char *devname
, *tmp
;
2657 devname
= nfs_path(path
->mnt
->mnt_devname
,
2658 path
->mnt
->mnt_root
, path
->dentry
,
2660 if (devname
== NULL
)
2662 tmp
= kstrdup(devname
, GFP_KERNEL
);
2665 kfree(mnt
->mnt_devname
);
2666 mnt
->mnt_devname
= tmp
;
2668 free_page((unsigned long)page
);
2671 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2672 const char *export_path
, struct vfsmount
*mnt_target
)
2674 struct mnt_namespace
*ns_private
;
2675 struct nameidata nd
;
2676 struct super_block
*s
;
2679 ns_private
= create_mnt_ns(root_mnt
);
2680 ret
= PTR_ERR(ns_private
);
2681 if (IS_ERR(ns_private
))
2684 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2685 export_path
, LOOKUP_FOLLOW
, &nd
);
2687 put_mnt_ns(ns_private
);
2692 s
= nd
.path
.mnt
->mnt_sb
;
2693 atomic_inc(&s
->s_active
);
2694 mnt_target
->mnt_sb
= s
;
2695 mnt_target
->mnt_root
= dget(nd
.path
.dentry
);
2697 /* Correct the device pathname */
2698 nfs_fix_devname(&nd
.path
, mnt_target
);
2701 down_write(&s
->s_umount
);
2709 static int nfs4_try_mount(int flags
, const char *dev_name
,
2710 struct nfs_parsed_mount_data
*data
,
2711 struct vfsmount
*mnt
)
2714 struct vfsmount
*root_mnt
;
2717 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2719 export_path
= data
->nfs_server
.export_path
;
2720 data
->nfs_server
.export_path
= "/";
2721 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2722 data
->nfs_server
.hostname
);
2723 data
->nfs_server
.export_path
= export_path
;
2725 error
= PTR_ERR(root_mnt
);
2726 if (IS_ERR(root_mnt
))
2729 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2732 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2733 error
!= 0 ? " [error]" : "");
2738 * Get the superblock for an NFS4 mountpoint
2740 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2741 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2743 struct nfs_parsed_mount_data
*data
;
2744 int error
= -ENOMEM
;
2746 data
= nfs_alloc_parsed_mount_data(4);
2750 /* Validate the mount data */
2751 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2755 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2758 kfree(data
->client_address
);
2759 kfree(data
->nfs_server
.export_path
);
2760 kfree(data
->nfs_server
.hostname
);
2761 kfree(data
->fscache_uniq
);
2764 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2765 error
!= 0 ? " [error]" : "");
2769 static void nfs4_kill_super(struct super_block
*sb
)
2771 struct nfs_server
*server
= NFS_SB(sb
);
2773 dprintk("--> %s\n", __func__
);
2774 nfs_super_return_all_delegations(sb
);
2775 kill_anon_super(sb
);
2776 nfs_fscache_release_super_cookie(sb
);
2777 nfs_free_server(server
);
2778 dprintk("<-- %s\n", __func__
);
2782 * Clone an NFS4 server record on xdev traversal (FSID-change)
2784 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2785 const char *dev_name
, void *raw_data
,
2786 struct vfsmount
*mnt
)
2788 struct nfs_clone_mount
*data
= raw_data
;
2789 struct super_block
*s
;
2790 struct nfs_server
*server
;
2791 struct dentry
*mntroot
;
2792 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2793 struct nfs_sb_mountdata sb_mntdata
= {
2798 dprintk("--> nfs4_xdev_get_sb()\n");
2800 /* create a new volume representation */
2801 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2802 if (IS_ERR(server
)) {
2803 error
= PTR_ERR(server
);
2804 goto out_err_noserver
;
2806 sb_mntdata
.server
= server
;
2808 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2809 compare_super
= NULL
;
2811 /* Get a superblock - note that we may end up sharing one that already exists */
2812 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2818 if (s
->s_fs_info
!= server
) {
2819 nfs_free_server(server
);
2822 error
= nfs_bdi_register(server
);
2824 goto error_splat_bdi
;
2828 /* initial superblock/root creation */
2829 nfs4_clone_super(s
, data
->sb
);
2830 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2833 mntroot
= nfs4_get_root(s
, data
->fh
);
2834 if (IS_ERR(mntroot
)) {
2835 error
= PTR_ERR(mntroot
);
2836 goto error_splat_super
;
2838 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2841 goto error_splat_super
;
2844 s
->s_flags
|= MS_ACTIVE
;
2846 mnt
->mnt_root
= mntroot
;
2848 security_sb_clone_mnt_opts(data
->sb
, s
);
2850 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2854 nfs_free_server(server
);
2856 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2860 if (server
&& !s
->s_root
)
2861 bdi_unregister(&server
->backing_dev_info
);
2863 deactivate_locked_super(s
);
2864 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2868 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2869 int flags
, const char *dev_name
, void *raw_data
,
2870 struct vfsmount
*mnt
)
2872 struct nfs_clone_mount
*data
= raw_data
;
2873 struct super_block
*s
;
2874 struct nfs_server
*server
;
2875 struct dentry
*mntroot
;
2876 struct nfs_fh mntfh
;
2877 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2878 struct nfs_sb_mountdata sb_mntdata
= {
2883 dprintk("--> nfs4_referral_get_sb()\n");
2885 /* create a new volume representation */
2886 server
= nfs4_create_referral_server(data
, &mntfh
);
2887 if (IS_ERR(server
)) {
2888 error
= PTR_ERR(server
);
2889 goto out_err_noserver
;
2891 sb_mntdata
.server
= server
;
2893 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2894 compare_super
= NULL
;
2896 /* Get a superblock - note that we may end up sharing one that already exists */
2897 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2903 if (s
->s_fs_info
!= server
) {
2904 nfs_free_server(server
);
2907 error
= nfs_bdi_register(server
);
2909 goto error_splat_bdi
;
2913 /* initial superblock/root creation */
2915 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2918 mntroot
= nfs4_get_root(s
, &mntfh
);
2919 if (IS_ERR(mntroot
)) {
2920 error
= PTR_ERR(mntroot
);
2921 goto error_splat_super
;
2923 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2926 goto error_splat_super
;
2929 s
->s_flags
|= MS_ACTIVE
;
2931 mnt
->mnt_root
= mntroot
;
2933 security_sb_clone_mnt_opts(data
->sb
, s
);
2935 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2939 nfs_free_server(server
);
2941 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2945 if (server
&& !s
->s_root
)
2946 bdi_unregister(&server
->backing_dev_info
);
2948 deactivate_locked_super(s
);
2949 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2954 * Create an NFS4 server record on referral traversal
2956 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
2957 int flags
, const char *dev_name
, void *raw_data
,
2958 struct vfsmount
*mnt
)
2960 struct nfs_clone_mount
*data
= raw_data
;
2962 struct vfsmount
*root_mnt
;
2965 dprintk("--> nfs4_referral_get_sb()\n");
2967 export_path
= data
->mnt_path
;
2968 data
->mnt_path
= "/";
2970 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
2971 flags
, data
, data
->hostname
);
2972 data
->mnt_path
= export_path
;
2974 error
= PTR_ERR(root_mnt
);
2975 if (IS_ERR(root_mnt
))
2978 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2980 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
2981 error
!= 0 ? " [error]" : "");
2985 #endif /* CONFIG_NFS_V4 */