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>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
67 #define NFSDBG_FACILITY NFSDBG_VFS
70 /* Mount options that take no arguments */
72 Opt_posix
, Opt_noposix
,
76 Opt_v2
, Opt_v3
, Opt_v4
,
77 Opt_udp
, Opt_tcp
, Opt_rdma
,
79 Opt_rdirplus
, Opt_nordirplus
,
80 Opt_sharecache
, Opt_nosharecache
,
81 Opt_resvport
, Opt_noresvport
,
82 Opt_fscache
, Opt_nofscache
,
84 /* Mount options that take integer arguments */
86 Opt_rsize
, Opt_wsize
, Opt_bsize
,
87 Opt_timeo
, Opt_retrans
,
88 Opt_acregmin
, Opt_acregmax
,
89 Opt_acdirmin
, Opt_acdirmax
,
97 /* Mount options that take string arguments */
98 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
99 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
103 /* Special mount options */
104 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
109 static const match_table_t nfs_mount_option_tokens
= {
110 { Opt_userspace
, "bg" },
111 { Opt_userspace
, "fg" },
112 { Opt_userspace
, "retry=%s" },
114 { Opt_sloppy
, "sloppy" },
116 { Opt_soft
, "soft" },
117 { Opt_hard
, "hard" },
118 { Opt_deprecated
, "intr" },
119 { Opt_deprecated
, "nointr" },
120 { Opt_posix
, "posix" },
121 { Opt_noposix
, "noposix" },
123 { Opt_nocto
, "nocto" },
125 { Opt_noac
, "noac" },
126 { Opt_lock
, "lock" },
127 { Opt_nolock
, "nolock" },
133 { Opt_rdma
, "rdma" },
135 { Opt_noacl
, "noacl" },
136 { Opt_rdirplus
, "rdirplus" },
137 { Opt_nordirplus
, "nordirplus" },
138 { Opt_sharecache
, "sharecache" },
139 { Opt_nosharecache
, "nosharecache" },
140 { Opt_resvport
, "resvport" },
141 { Opt_noresvport
, "noresvport" },
142 { Opt_fscache
, "fsc" },
143 { Opt_fscache_uniq
, "fsc=%s" },
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" },
178 Opt_xprt_udp
, Opt_xprt_udp6
, Opt_xprt_tcp
, Opt_xprt_tcp6
, Opt_xprt_rdma
,
183 static const match_table_t nfs_xprt_protocol_tokens
= {
184 { Opt_xprt_udp
, "udp" },
185 { Opt_xprt_udp6
, "udp6" },
186 { Opt_xprt_tcp
, "tcp" },
187 { Opt_xprt_tcp6
, "tcp6" },
188 { Opt_xprt_rdma
, "rdma" },
190 { Opt_xprt_err
, NULL
}
194 Opt_sec_none
, Opt_sec_sys
,
195 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
196 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
197 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
202 static const match_table_t nfs_secflavor_tokens
= {
203 { Opt_sec_none
, "none" },
204 { Opt_sec_none
, "null" },
205 { Opt_sec_sys
, "sys" },
207 { Opt_sec_krb5
, "krb5" },
208 { Opt_sec_krb5i
, "krb5i" },
209 { Opt_sec_krb5p
, "krb5p" },
211 { Opt_sec_lkey
, "lkey" },
212 { Opt_sec_lkeyi
, "lkeyi" },
213 { Opt_sec_lkeyp
, "lkeyp" },
215 { Opt_sec_spkm
, "spkm3" },
216 { Opt_sec_spkmi
, "spkm3i" },
217 { Opt_sec_spkmp
, "spkm3p" },
219 { Opt_sec_err
, NULL
}
223 Opt_lookupcache_all
, Opt_lookupcache_positive
,
224 Opt_lookupcache_none
,
229 static match_table_t nfs_lookupcache_tokens
= {
230 { Opt_lookupcache_all
, "all" },
231 { Opt_lookupcache_positive
, "pos" },
232 { Opt_lookupcache_positive
, "positive" },
233 { Opt_lookupcache_none
, "none" },
235 { Opt_lookupcache_err
, NULL
}
239 static void nfs_umount_begin(struct super_block
*);
240 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
241 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
242 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
243 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
244 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
245 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
246 static void nfs_put_super(struct super_block
*);
247 static void nfs_kill_super(struct super_block
*);
248 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
250 static struct file_system_type nfs_fs_type
= {
251 .owner
= THIS_MODULE
,
253 .get_sb
= nfs_get_sb
,
254 .kill_sb
= nfs_kill_super
,
255 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
258 struct file_system_type nfs_xdev_fs_type
= {
259 .owner
= THIS_MODULE
,
261 .get_sb
= nfs_xdev_get_sb
,
262 .kill_sb
= nfs_kill_super
,
263 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
266 static const struct super_operations nfs_sops
= {
267 .alloc_inode
= nfs_alloc_inode
,
268 .destroy_inode
= nfs_destroy_inode
,
269 .write_inode
= nfs_write_inode
,
270 .put_super
= nfs_put_super
,
271 .statfs
= nfs_statfs
,
272 .clear_inode
= nfs_clear_inode
,
273 .umount_begin
= nfs_umount_begin
,
274 .show_options
= nfs_show_options
,
275 .show_stats
= nfs_show_stats
,
276 .remount_fs
= nfs_remount
,
280 static int nfs4_validate_text_mount_data(void *options
,
281 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
282 static int nfs4_try_mount(int flags
, const char *dev_name
,
283 struct nfs_parsed_mount_data
*data
, struct vfsmount
*mnt
);
284 static int nfs4_get_sb(struct file_system_type
*fs_type
,
285 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
286 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
287 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
288 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
289 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
290 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
291 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
292 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
293 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
294 static void nfs4_kill_super(struct super_block
*sb
);
296 static struct file_system_type nfs4_fs_type
= {
297 .owner
= THIS_MODULE
,
299 .get_sb
= nfs4_get_sb
,
300 .kill_sb
= nfs4_kill_super
,
301 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
304 static struct file_system_type nfs4_remote_fs_type
= {
305 .owner
= THIS_MODULE
,
307 .get_sb
= nfs4_remote_get_sb
,
308 .kill_sb
= nfs4_kill_super
,
309 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
312 struct file_system_type nfs4_xdev_fs_type
= {
313 .owner
= THIS_MODULE
,
315 .get_sb
= nfs4_xdev_get_sb
,
316 .kill_sb
= nfs4_kill_super
,
317 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
320 static struct file_system_type nfs4_remote_referral_fs_type
= {
321 .owner
= THIS_MODULE
,
323 .get_sb
= nfs4_remote_referral_get_sb
,
324 .kill_sb
= nfs4_kill_super
,
325 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
328 struct file_system_type nfs4_referral_fs_type
= {
329 .owner
= THIS_MODULE
,
331 .get_sb
= nfs4_referral_get_sb
,
332 .kill_sb
= nfs4_kill_super
,
333 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
336 static const struct super_operations nfs4_sops
= {
337 .alloc_inode
= nfs_alloc_inode
,
338 .destroy_inode
= nfs_destroy_inode
,
339 .write_inode
= nfs_write_inode
,
340 .put_super
= nfs_put_super
,
341 .statfs
= nfs_statfs
,
342 .clear_inode
= nfs4_clear_inode
,
343 .umount_begin
= nfs_umount_begin
,
344 .show_options
= nfs_show_options
,
345 .show_stats
= nfs_show_stats
,
346 .remount_fs
= nfs_remount
,
350 static struct shrinker acl_shrinker
= {
351 .shrink
= nfs_access_cache_shrinker
,
352 .seeks
= DEFAULT_SEEKS
,
356 * Register the NFS filesystems
358 int __init
register_nfs_fs(void)
362 ret
= register_filesystem(&nfs_fs_type
);
366 ret
= nfs_register_sysctl();
370 ret
= register_filesystem(&nfs4_fs_type
);
374 register_shrinker(&acl_shrinker
);
379 nfs_unregister_sysctl();
382 unregister_filesystem(&nfs_fs_type
);
388 * Unregister the NFS filesystems
390 void __exit
unregister_nfs_fs(void)
392 unregister_shrinker(&acl_shrinker
);
394 unregister_filesystem(&nfs4_fs_type
);
396 nfs_unregister_sysctl();
397 unregister_filesystem(&nfs_fs_type
);
400 void nfs_sb_active(struct super_block
*sb
)
402 struct nfs_server
*server
= NFS_SB(sb
);
404 if (atomic_inc_return(&server
->active
) == 1)
405 atomic_inc(&sb
->s_active
);
408 void nfs_sb_deactive(struct super_block
*sb
)
410 struct nfs_server
*server
= NFS_SB(sb
);
412 if (atomic_dec_and_test(&server
->active
))
413 deactivate_super(sb
);
417 * Deliver file system statistics to userspace
419 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
421 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
422 unsigned char blockbits
;
423 unsigned long blockres
;
424 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
425 struct nfs_fattr fattr
;
426 struct nfs_fsstat res
= {
431 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
434 buf
->f_type
= NFS_SUPER_MAGIC
;
437 * Current versions of glibc do not correctly handle the
438 * case where f_frsize != f_bsize. Eventually we want to
439 * report the value of wtmult in this field.
441 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
444 * On most *nix systems, f_blocks, f_bfree, and f_bavail
445 * are reported in units of f_frsize. Linux hasn't had
446 * an f_frsize field in its statfs struct until recently,
447 * thus historically Linux's sys_statfs reports these
448 * fields in units of f_bsize.
450 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
451 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
452 blockres
= (1 << blockbits
) - 1;
453 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
454 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
455 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
457 buf
->f_files
= res
.tfiles
;
458 buf
->f_ffree
= res
.afiles
;
460 buf
->f_namelen
= server
->namelen
;
465 dprintk("%s: statfs error = %d\n", __func__
, -error
);
470 * Map the security flavour number to a name
472 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
474 static const struct {
475 rpc_authflavor_t flavour
;
478 { RPC_AUTH_NULL
, "null" },
479 { RPC_AUTH_UNIX
, "sys" },
480 { RPC_AUTH_GSS_KRB5
, "krb5" },
481 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
482 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
483 { RPC_AUTH_GSS_LKEY
, "lkey" },
484 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
485 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
486 { RPC_AUTH_GSS_SPKM
, "spkm" },
487 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
488 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
489 { UINT_MAX
, "unknown" }
493 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
494 if (sec_flavours
[i
].flavour
== flavour
)
497 return sec_flavours
[i
].str
;
500 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
503 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
505 seq_printf(m
, ",mountproto=");
506 switch (sap
->sa_family
) {
508 switch (nfss
->mountd_protocol
) {
510 seq_printf(m
, RPCBIND_NETID_UDP
);
513 seq_printf(m
, RPCBIND_NETID_TCP
);
517 seq_printf(m
, "auto");
521 switch (nfss
->mountd_protocol
) {
523 seq_printf(m
, RPCBIND_NETID_UDP6
);
526 seq_printf(m
, RPCBIND_NETID_TCP6
);
530 seq_printf(m
, "auto");
535 seq_printf(m
, "auto");
539 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
542 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
544 switch (sap
->sa_family
) {
546 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
547 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
551 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
552 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
557 seq_printf(m
, ",mountaddr=unspecified");
560 if (nfss
->mountd_version
|| showdefaults
)
561 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
562 if (nfss
->mountd_port
|| showdefaults
)
563 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
565 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
569 * Describe the mount options in force on this server representation
571 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
574 static const struct proc_nfs_info
{
579 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
580 { NFS_MOUNT_POSIX
, ",posix", "" },
581 { NFS_MOUNT_NOCTO
, ",nocto", "" },
582 { NFS_MOUNT_NOAC
, ",noac", "" },
583 { NFS_MOUNT_NONLM
, ",nolock", "" },
584 { NFS_MOUNT_NOACL
, ",noacl", "" },
585 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
586 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
587 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
590 const struct proc_nfs_info
*nfs_infop
;
591 struct nfs_client
*clp
= nfss
->nfs_client
;
592 u32 version
= clp
->rpc_ops
->version
;
594 seq_printf(m
, ",vers=%u", version
);
595 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
596 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
597 if (nfss
->bsize
!= 0)
598 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
599 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
600 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
601 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
602 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
603 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
604 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
605 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
606 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
607 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
608 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
609 if (nfss
->flags
& nfs_infop
->flag
)
610 seq_puts(m
, nfs_infop
->str
);
612 seq_puts(m
, nfs_infop
->nostr
);
614 seq_printf(m
, ",proto=%s",
615 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
617 if (nfss
->port
!= NFS_PORT
)
618 seq_printf(m
, ",port=%u", nfss
->port
);
621 seq_printf(m
, ",port=%u", nfss
->port
);
623 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
624 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
625 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
628 nfs_show_mountd_options(m
, nfss
, showdefaults
);
631 if (clp
->rpc_ops
->version
== 4)
632 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
634 if (nfss
->options
& NFS_OPTION_FSCACHE
)
635 seq_printf(m
, ",fsc");
639 * Describe the mount options on this VFS mountpoint
641 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
643 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
645 nfs_show_mount_options(m
, nfss
, 0);
647 seq_printf(m
, ",addr=%s",
648 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
655 * Present statistical information for this VFS mountpoint
657 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
660 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
661 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
662 struct nfs_iostats totals
= { };
664 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
667 * Display all mount option settings
669 seq_printf(m
, "\n\topts:\t");
670 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
671 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
672 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
673 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
674 nfs_show_mount_options(m
, nfss
, 1);
676 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
678 seq_printf(m
, "\n\tcaps:\t");
679 seq_printf(m
, "caps=0x%x", nfss
->caps
);
680 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
681 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
682 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
683 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
686 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
687 seq_printf(m
, "\n\tnfsv4:\t");
688 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
689 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
690 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
695 * Display security flavor in effect for this mount
697 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
699 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
702 * Display superblock I/O counters
704 for_each_possible_cpu(cpu
) {
705 struct nfs_iostats
*stats
;
708 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
710 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
711 totals
.events
[i
] += stats
->events
[i
];
712 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
713 totals
.bytes
[i
] += stats
->bytes
[i
];
714 #ifdef CONFIG_NFS_FSCACHE
715 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
716 totals
.fscache
[i
] += stats
->fscache
[i
];
722 seq_printf(m
, "\n\tevents:\t");
723 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
724 seq_printf(m
, "%lu ", totals
.events
[i
]);
725 seq_printf(m
, "\n\tbytes:\t");
726 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
727 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
728 #ifdef CONFIG_NFS_FSCACHE
729 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
730 seq_printf(m
, "\n\tfsc:\t");
731 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
732 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
737 rpc_print_iostats(m
, nfss
->client
);
743 * Begin unmount by attempting to remove all automounted mountpoints we added
744 * in response to xdev traversals and referrals
746 static void nfs_umount_begin(struct super_block
*sb
)
748 struct nfs_server
*server
;
749 struct rpc_clnt
*rpc
;
752 /* -EIO all pending I/O */
753 rpc
= server
->client_acl
;
755 rpc_killall_tasks(rpc
);
756 rpc
= server
->client
;
758 rpc_killall_tasks(rpc
);
761 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
763 struct nfs_parsed_mount_data
*data
;
765 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
767 data
->acregmin
= NFS_DEF_ACREGMIN
;
768 data
->acregmax
= NFS_DEF_ACREGMAX
;
769 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
770 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
771 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
772 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
773 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
774 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
775 data
->auth_flavor_len
= 1;
776 data
->version
= version
;
777 data
->minorversion
= 0;
783 * Sanity-check a server address provided by the mount command.
785 * Address family must be initialized, and address must not be
786 * the ANY address for that family.
788 static int nfs_verify_server_address(struct sockaddr
*addr
)
790 switch (addr
->sa_family
) {
792 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
793 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
796 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
797 return !ipv6_addr_any(sa
);
801 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
806 * Select between a default port value and a user-specified port value.
807 * If a zero value is set, then autobind will be used.
809 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
810 const unsigned short default_port
)
812 if (*port
== NFS_UNSPEC_PORT
)
813 *port
= default_port
;
815 rpc_set_port(sap
, *port
);
819 * Sanity check the NFS transport protocol.
822 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
824 switch (mnt
->nfs_server
.protocol
) {
825 case XPRT_TRANSPORT_UDP
:
826 case XPRT_TRANSPORT_TCP
:
827 case XPRT_TRANSPORT_RDMA
:
830 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
835 * For text based NFSv2/v3 mounts, the mount protocol transport default
836 * settings should depend upon the specified NFS transport.
838 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
840 nfs_validate_transport_protocol(mnt
);
842 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
843 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
845 switch (mnt
->nfs_server
.protocol
) {
846 case XPRT_TRANSPORT_UDP
:
847 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
849 case XPRT_TRANSPORT_TCP
:
850 case XPRT_TRANSPORT_RDMA
:
851 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
856 * Parse the value of the 'sec=' option.
858 static int nfs_parse_security_flavors(char *value
,
859 struct nfs_parsed_mount_data
*mnt
)
861 substring_t args
[MAX_OPT_ARGS
];
863 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
865 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
867 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
870 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
873 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
876 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
879 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
882 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
885 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
888 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
891 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
894 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
897 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
903 mnt
->auth_flavor_len
= 1;
908 * Error-check and convert a string of mount options from user space into
909 * a data structure. The whole mount string is processed; bad options are
910 * skipped as they are encountered. If there were no errors, return 1;
911 * otherwise return 0 (zero).
913 static int nfs_parse_mount_options(char *raw
,
914 struct nfs_parsed_mount_data
*mnt
)
916 char *p
, *string
, *secdata
;
917 int rc
, sloppy
= 0, invalid_option
= 0;
918 unsigned short protofamily
= AF_UNSPEC
;
919 unsigned short mountfamily
= AF_UNSPEC
;
922 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
925 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
927 secdata
= alloc_secdata();
931 rc
= security_sb_copy_data(raw
, secdata
);
933 goto out_security_failure
;
935 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
937 goto out_security_failure
;
939 free_secdata(secdata
);
941 while ((p
= strsep(&raw
, ",")) != NULL
) {
942 substring_t args
[MAX_OPT_ARGS
];
943 unsigned long option
;
949 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
951 token
= match_token(p
, nfs_mount_option_tokens
, args
);
955 * boolean options: foo/nofoo
958 mnt
->flags
|= NFS_MOUNT_SOFT
;
961 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
964 mnt
->flags
|= NFS_MOUNT_POSIX
;
967 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
970 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
973 mnt
->flags
|= NFS_MOUNT_NOCTO
;
976 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
979 mnt
->flags
|= NFS_MOUNT_NOAC
;
982 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
985 mnt
->flags
|= NFS_MOUNT_NONLM
;
988 mnt
->flags
&= ~NFS_MOUNT_VER3
;
992 mnt
->flags
|= NFS_MOUNT_VER3
;
997 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1002 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1003 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1006 mnt
->flags
|= NFS_MOUNT_TCP
;
1007 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1010 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1011 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1012 xprt_load_transport(p
);
1015 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1018 mnt
->flags
|= NFS_MOUNT_NOACL
;
1021 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1023 case Opt_nordirplus
:
1024 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1026 case Opt_sharecache
:
1027 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1029 case Opt_nosharecache
:
1030 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1033 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1035 case Opt_noresvport
:
1036 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1039 mnt
->options
|= NFS_OPTION_FSCACHE
;
1040 kfree(mnt
->fscache_uniq
);
1041 mnt
->fscache_uniq
= NULL
;
1044 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1045 kfree(mnt
->fscache_uniq
);
1046 mnt
->fscache_uniq
= NULL
;
1048 case Opt_fscache_uniq
:
1049 string
= match_strdup(args
);
1052 kfree(mnt
->fscache_uniq
);
1053 mnt
->fscache_uniq
= string
;
1054 mnt
->options
|= NFS_OPTION_FSCACHE
;
1058 * options that take numeric values
1061 string
= match_strdup(args
);
1064 rc
= strict_strtoul(string
, 10, &option
);
1066 if (rc
!= 0 || option
> USHORT_MAX
)
1067 goto out_invalid_value
;
1068 mnt
->nfs_server
.port
= option
;
1071 string
= match_strdup(args
);
1074 rc
= strict_strtoul(string
, 10, &option
);
1077 goto out_invalid_value
;
1078 mnt
->rsize
= option
;
1081 string
= match_strdup(args
);
1084 rc
= strict_strtoul(string
, 10, &option
);
1087 goto out_invalid_value
;
1088 mnt
->wsize
= option
;
1091 string
= match_strdup(args
);
1094 rc
= strict_strtoul(string
, 10, &option
);
1097 goto out_invalid_value
;
1098 mnt
->bsize
= option
;
1101 string
= match_strdup(args
);
1104 rc
= strict_strtoul(string
, 10, &option
);
1106 if (rc
!= 0 || option
== 0)
1107 goto out_invalid_value
;
1108 mnt
->timeo
= option
;
1111 string
= match_strdup(args
);
1114 rc
= strict_strtoul(string
, 10, &option
);
1116 if (rc
!= 0 || option
== 0)
1117 goto out_invalid_value
;
1118 mnt
->retrans
= option
;
1121 string
= match_strdup(args
);
1124 rc
= strict_strtoul(string
, 10, &option
);
1127 goto out_invalid_value
;
1128 mnt
->acregmin
= option
;
1131 string
= match_strdup(args
);
1134 rc
= strict_strtoul(string
, 10, &option
);
1137 goto out_invalid_value
;
1138 mnt
->acregmax
= option
;
1141 string
= match_strdup(args
);
1144 rc
= strict_strtoul(string
, 10, &option
);
1147 goto out_invalid_value
;
1148 mnt
->acdirmin
= option
;
1151 string
= match_strdup(args
);
1154 rc
= strict_strtoul(string
, 10, &option
);
1157 goto out_invalid_value
;
1158 mnt
->acdirmax
= option
;
1161 string
= match_strdup(args
);
1164 rc
= strict_strtoul(string
, 10, &option
);
1167 goto out_invalid_value
;
1168 mnt
->acregmin
= mnt
->acregmax
=
1169 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1172 string
= match_strdup(args
);
1175 rc
= strict_strtoul(string
, 10, &option
);
1178 goto out_invalid_value
;
1179 mnt
->namlen
= option
;
1182 string
= match_strdup(args
);
1185 rc
= strict_strtoul(string
, 10, &option
);
1187 if (rc
!= 0 || option
> USHORT_MAX
)
1188 goto out_invalid_value
;
1189 mnt
->mount_server
.port
= option
;
1192 string
= match_strdup(args
);
1195 rc
= strict_strtoul(string
, 10, &option
);
1198 option
< NFS_MNT_VERSION
||
1199 option
> NFS_MNT3_VERSION
)
1200 goto out_invalid_value
;
1201 mnt
->mount_server
.version
= option
;
1204 string
= match_strdup(args
);
1207 rc
= strict_strtoul(string
, 10, &option
);
1210 goto out_invalid_value
;
1213 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1217 mnt
->flags
|= NFS_MOUNT_VER3
;
1220 #ifdef CONFIG_NFS_V4
1222 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1227 goto out_invalid_value
;
1230 case Opt_minorversion
:
1231 string
= match_strdup(args
);
1234 rc
= strict_strtoul(string
, 10, &option
);
1237 goto out_invalid_value
;
1238 if (option
> NFS4_MAX_MINOR_VERSION
)
1239 goto out_invalid_value
;
1240 mnt
->minorversion
= option
;
1244 * options that take text values
1247 string
= match_strdup(args
);
1250 rc
= nfs_parse_security_flavors(string
, mnt
);
1253 dfprintk(MOUNT
, "NFS: unrecognized "
1254 "security flavor\n");
1259 string
= match_strdup(args
);
1262 token
= match_token(string
,
1263 nfs_xprt_protocol_tokens
, args
);
1265 protofamily
= AF_INET
;
1268 protofamily
= AF_INET6
;
1270 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1271 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1275 protofamily
= AF_INET6
;
1277 mnt
->flags
|= NFS_MOUNT_TCP
;
1278 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1282 /* vector side protocols to TCP */
1283 mnt
->flags
|= NFS_MOUNT_TCP
;
1284 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1285 xprt_load_transport(string
);
1289 dfprintk(MOUNT
, "NFS: unrecognized "
1290 "transport protocol\n");
1295 case Opt_mountproto
:
1296 string
= match_strdup(args
);
1299 token
= match_token(string
,
1300 nfs_xprt_protocol_tokens
, args
);
1303 mountfamily
= AF_INET
;
1306 mountfamily
= AF_INET6
;
1308 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1311 mountfamily
= AF_INET6
;
1313 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1315 case Opt_xprt_rdma
: /* not used for side protocols */
1317 dfprintk(MOUNT
, "NFS: unrecognized "
1318 "transport protocol\n");
1323 string
= match_strdup(args
);
1326 mnt
->nfs_server
.addrlen
=
1327 rpc_pton(string
, strlen(string
),
1329 &mnt
->nfs_server
.address
,
1330 sizeof(mnt
->nfs_server
.address
));
1332 if (mnt
->nfs_server
.addrlen
== 0)
1333 goto out_invalid_address
;
1335 case Opt_clientaddr
:
1336 string
= match_strdup(args
);
1339 kfree(mnt
->client_address
);
1340 mnt
->client_address
= string
;
1343 string
= match_strdup(args
);
1346 kfree(mnt
->mount_server
.hostname
);
1347 mnt
->mount_server
.hostname
= string
;
1350 string
= match_strdup(args
);
1353 mnt
->mount_server
.addrlen
=
1354 rpc_pton(string
, strlen(string
),
1356 &mnt
->mount_server
.address
,
1357 sizeof(mnt
->mount_server
.address
));
1359 if (mnt
->mount_server
.addrlen
== 0)
1360 goto out_invalid_address
;
1362 case Opt_lookupcache
:
1363 string
= match_strdup(args
);
1366 token
= match_token(string
,
1367 nfs_lookupcache_tokens
, args
);
1370 case Opt_lookupcache_all
:
1371 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1373 case Opt_lookupcache_positive
:
1374 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1375 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1377 case Opt_lookupcache_none
:
1378 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1381 dfprintk(MOUNT
, "NFS: invalid "
1382 "lookupcache argument\n");
1392 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1395 case Opt_deprecated
:
1396 dfprintk(MOUNT
, "NFS: ignoring mount option "
1402 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1407 if (!sloppy
&& invalid_option
)
1411 * verify that any proto=/mountproto= options match the address
1412 * familiies in the addr=/mountaddr= options.
1414 if (protofamily
!= AF_UNSPEC
&&
1415 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1416 goto out_proto_mismatch
;
1418 if (mountfamily
!= AF_UNSPEC
) {
1419 if (mnt
->mount_server
.addrlen
) {
1420 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1421 goto out_mountproto_mismatch
;
1423 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1424 goto out_mountproto_mismatch
;
1430 out_mountproto_mismatch
:
1431 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1435 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1437 out_invalid_address
:
1438 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1441 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1444 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1446 out_security_failure
:
1447 free_secdata(secdata
);
1448 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1453 * Match the requested auth flavors with the list returned by
1454 * the server. Returns zero and sets the mount's authentication
1455 * flavor on success; returns -EACCES if server does not support
1456 * the requested flavor.
1458 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1459 struct nfs_mount_request
*request
)
1461 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1464 * Certain releases of Linux's mountd return an empty
1465 * flavor list. To prevent behavioral regression with
1466 * these servers (ie. rejecting mounts that used to
1467 * succeed), revert to pre-2.6.32 behavior (no checking)
1468 * if the returned flavor list is empty.
1470 if (server_authlist_len
== 0)
1474 * We avoid sophisticated negotiating here, as there are
1475 * plenty of cases where we can get it wrong, providing
1476 * either too little or too much security.
1478 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1479 * flavor listed first. However, some servers list
1480 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1481 * preferred default, in args->auth_flavors[0] if user
1482 * didn't specify sec= mount option.
1484 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1485 for (j
= 0; j
< server_authlist_len
; j
++)
1486 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1487 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1488 request
->auth_flavs
[j
]);
1489 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1493 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1494 nfs_umount(request
);
1499 * Use the remote server's MOUNT service to request the NFS file handle
1500 * corresponding to the provided path.
1502 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1503 struct nfs_fh
*root_fh
)
1505 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1506 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1507 struct nfs_mount_request request
= {
1508 .sap
= (struct sockaddr
*)
1509 &args
->mount_server
.address
,
1510 .dirpath
= args
->nfs_server
.export_path
,
1511 .protocol
= args
->mount_server
.protocol
,
1513 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1514 .auth_flav_len
= &server_authlist_len
,
1515 .auth_flavs
= server_authlist
,
1519 if (args
->mount_server
.version
== 0) {
1520 switch (args
->version
) {
1522 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1525 args
->mount_server
.version
= NFS_MNT_VERSION
;
1528 request
.version
= args
->mount_server
.version
;
1530 if (args
->mount_server
.hostname
)
1531 request
.hostname
= args
->mount_server
.hostname
;
1533 request
.hostname
= args
->nfs_server
.hostname
;
1536 * Construct the mount server's address.
1538 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1539 memcpy(request
.sap
, &args
->nfs_server
.address
,
1540 args
->nfs_server
.addrlen
);
1541 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1543 request
.salen
= args
->mount_server
.addrlen
;
1544 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1547 * Now ask the mount server to map our export path
1550 status
= nfs_mount(&request
);
1552 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1553 request
.hostname
, status
);
1558 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1560 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1562 return nfs_walk_authlist(args
, &request
);
1565 static int nfs_parse_simple_hostname(const char *dev_name
,
1566 char **hostname
, size_t maxnamlen
,
1567 char **export_path
, size_t maxpathlen
)
1570 char *colon
, *comma
;
1572 colon
= strchr(dev_name
, ':');
1574 goto out_bad_devname
;
1576 len
= colon
- dev_name
;
1577 if (len
> maxnamlen
)
1580 /* N.B. caller will free nfs_server.hostname in all cases */
1581 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1585 /* kill possible hostname list: not supported */
1586 comma
= strchr(*hostname
, ',');
1587 if (comma
!= NULL
) {
1588 if (comma
== *hostname
)
1589 goto out_bad_devname
;
1594 len
= strlen(colon
);
1595 if (len
> maxpathlen
)
1597 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1601 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1605 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1609 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1613 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1614 return -ENAMETOOLONG
;
1617 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1618 return -ENAMETOOLONG
;
1622 * Hostname has square brackets around it because it contains one or
1623 * more colons. We look for the first closing square bracket, and a
1624 * colon must follow it.
1626 static int nfs_parse_protected_hostname(const char *dev_name
,
1627 char **hostname
, size_t maxnamlen
,
1628 char **export_path
, size_t maxpathlen
)
1633 start
= (char *)(dev_name
+ 1);
1635 end
= strchr(start
, ']');
1637 goto out_bad_devname
;
1638 if (*(end
+ 1) != ':')
1639 goto out_bad_devname
;
1642 if (len
> maxnamlen
)
1645 /* N.B. caller will free nfs_server.hostname in all cases */
1646 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1647 if (*hostname
== NULL
)
1652 if (len
> maxpathlen
)
1654 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1661 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1665 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1669 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1670 return -ENAMETOOLONG
;
1673 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1674 return -ENAMETOOLONG
;
1678 * Split "dev_name" into "hostname:export_path".
1680 * The leftmost colon demarks the split between the server's hostname
1681 * and the export path. If the hostname starts with a left square
1682 * bracket, then it may contain colons.
1684 * Note: caller frees hostname and export path, even on error.
1686 static int nfs_parse_devname(const char *dev_name
,
1687 char **hostname
, size_t maxnamlen
,
1688 char **export_path
, size_t maxpathlen
)
1690 if (*dev_name
== '[')
1691 return nfs_parse_protected_hostname(dev_name
,
1692 hostname
, maxnamlen
,
1693 export_path
, maxpathlen
);
1695 return nfs_parse_simple_hostname(dev_name
,
1696 hostname
, maxnamlen
,
1697 export_path
, maxpathlen
);
1701 * Validate the NFS2/NFS3 mount data
1702 * - fills in the mount root filehandle
1704 * For option strings, user space handles the following behaviors:
1706 * + DNS: mapping server host name to IP address ("addr=" option)
1708 * + failure mode: how to behave if a mount request can't be handled
1709 * immediately ("fg/bg" option)
1711 * + retry: how often to retry a mount request ("retry=" option)
1713 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1714 * mountproto=tcp after mountproto=udp, and so on
1716 static int nfs_validate_mount_data(void *options
,
1717 struct nfs_parsed_mount_data
*args
,
1718 struct nfs_fh
*mntfh
,
1719 const char *dev_name
)
1721 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1722 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1727 switch (data
->version
) {
1733 if (data
->flags
& NFS_MOUNT_VER3
)
1735 data
->root
.size
= NFS2_FHSIZE
;
1736 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1738 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1741 memset(data
->context
, 0, sizeof(data
->context
));
1743 if (data
->flags
& NFS_MOUNT_VER3
) {
1744 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1745 goto out_invalid_fh
;
1746 mntfh
->size
= data
->root
.size
;
1749 mntfh
->size
= NFS2_FHSIZE
;
1754 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1755 if (mntfh
->size
< sizeof(mntfh
->data
))
1756 memset(mntfh
->data
+ mntfh
->size
, 0,
1757 sizeof(mntfh
->data
) - mntfh
->size
);
1760 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1763 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1764 args
->rsize
= data
->rsize
;
1765 args
->wsize
= data
->wsize
;
1766 args
->timeo
= data
->timeo
;
1767 args
->retrans
= data
->retrans
;
1768 args
->acregmin
= data
->acregmin
;
1769 args
->acregmax
= data
->acregmax
;
1770 args
->acdirmin
= data
->acdirmin
;
1771 args
->acdirmax
= data
->acdirmax
;
1773 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1774 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1775 if (!nfs_verify_server_address(sap
))
1776 goto out_no_address
;
1778 if (!(data
->flags
& NFS_MOUNT_TCP
))
1779 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1780 /* N.B. caller will free nfs_server.hostname in all cases */
1781 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1782 args
->namlen
= data
->namlen
;
1783 args
->bsize
= data
->bsize
;
1785 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1786 args
->auth_flavors
[0] = data
->pseudoflavor
;
1787 if (!args
->nfs_server
.hostname
)
1791 * The legacy version 6 binary mount data from userspace has a
1792 * field used only to transport selinux information into the
1793 * the kernel. To continue to support that functionality we
1794 * have a touch of selinux knowledge here in the NFS code. The
1795 * userspace code converted context=blah to just blah so we are
1796 * converting back to the full string selinux understands.
1798 if (data
->context
[0]){
1799 #ifdef CONFIG_SECURITY_SELINUX
1801 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1804 strcpy(opts_str
, "context=");
1805 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1806 strcat(opts_str
, &data
->context
[0]);
1807 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1820 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1823 if (!nfs_verify_server_address(sap
))
1824 goto out_no_address
;
1826 if (args
->version
== 4)
1827 #ifdef CONFIG_NFS_V4
1828 return nfs4_validate_text_mount_data(options
,
1831 goto out_v4_not_compiled
;
1834 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1836 nfs_set_mount_transport_protocol(args
);
1838 status
= nfs_parse_devname(dev_name
,
1839 &args
->nfs_server
.hostname
,
1841 &args
->nfs_server
.export_path
,
1844 status
= nfs_try_mount(args
, mntfh
);
1846 kfree(args
->nfs_server
.export_path
);
1847 args
->nfs_server
.export_path
= NULL
;
1856 #ifndef CONFIG_NFS_V3
1857 if (args
->version
== 3)
1858 goto out_v3_not_compiled
;
1859 #endif /* !CONFIG_NFS_V3 */
1864 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1868 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1873 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1876 #ifndef CONFIG_NFS_V3
1877 out_v3_not_compiled
:
1878 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1879 return -EPROTONOSUPPORT
;
1880 #endif /* !CONFIG_NFS_V3 */
1882 #ifndef CONFIG_NFS_V4
1883 out_v4_not_compiled
:
1884 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1885 return -EPROTONOSUPPORT
;
1886 #endif /* !CONFIG_NFS_V4 */
1889 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1893 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1897 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1902 nfs_compare_remount_data(struct nfs_server
*nfss
,
1903 struct nfs_parsed_mount_data
*data
)
1905 if (data
->flags
!= nfss
->flags
||
1906 data
->rsize
!= nfss
->rsize
||
1907 data
->wsize
!= nfss
->wsize
||
1908 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1909 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1910 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1911 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1912 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1913 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1914 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1915 data
->nfs_server
.port
!= nfss
->port
||
1916 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1917 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
1918 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
1925 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1928 struct nfs_server
*nfss
= sb
->s_fs_info
;
1929 struct nfs_parsed_mount_data
*data
;
1930 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1931 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1932 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1935 * Userspace mount programs that send binary options generally send
1936 * them populated with default values. We have no way to know which
1937 * ones were explicitly specified. Fall back to legacy behavior and
1938 * just return success.
1940 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1941 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1942 options
->version
<= 6))))
1945 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1949 /* fill out struct with values from existing mount */
1950 data
->flags
= nfss
->flags
;
1951 data
->rsize
= nfss
->rsize
;
1952 data
->wsize
= nfss
->wsize
;
1953 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1954 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1955 data
->acregmin
= nfss
->acregmin
/ HZ
;
1956 data
->acregmax
= nfss
->acregmax
/ HZ
;
1957 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1958 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1959 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1960 data
->nfs_server
.port
= nfss
->port
;
1961 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1962 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1963 data
->nfs_server
.addrlen
);
1965 /* overwrite those values with any that were specified */
1966 error
= nfs_parse_mount_options((char *)options
, data
);
1970 /* compare new mount options with old ones */
1971 error
= nfs_compare_remount_data(nfss
, data
);
1978 * Initialise the common bits of the superblock
1980 static inline void nfs_initialise_sb(struct super_block
*sb
)
1982 struct nfs_server
*server
= NFS_SB(sb
);
1984 sb
->s_magic
= NFS_SUPER_MAGIC
;
1986 /* We probably want something more informative here */
1987 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1988 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1990 if (sb
->s_blocksize
== 0)
1991 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1992 &sb
->s_blocksize_bits
);
1994 if (server
->flags
& NFS_MOUNT_NOAC
)
1995 sb
->s_flags
|= MS_SYNCHRONOUS
;
1997 sb
->s_bdi
= &server
->backing_dev_info
;
1999 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2003 * Finish setting up an NFS2/3 superblock
2005 static void nfs_fill_super(struct super_block
*sb
,
2006 struct nfs_parsed_mount_data
*data
)
2008 struct nfs_server
*server
= NFS_SB(sb
);
2010 sb
->s_blocksize_bits
= 0;
2011 sb
->s_blocksize
= 0;
2013 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2015 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2016 /* The VFS shouldn't apply the umask to mode bits. We will do
2017 * so ourselves when necessary.
2019 sb
->s_flags
|= MS_POSIXACL
;
2020 sb
->s_time_gran
= 1;
2023 sb
->s_op
= &nfs_sops
;
2024 nfs_initialise_sb(sb
);
2028 * Finish setting up a cloned NFS2/3 superblock
2030 static void nfs_clone_super(struct super_block
*sb
,
2031 const struct super_block
*old_sb
)
2033 struct nfs_server
*server
= NFS_SB(sb
);
2035 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2036 sb
->s_blocksize
= old_sb
->s_blocksize
;
2037 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2039 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2040 /* The VFS shouldn't apply the umask to mode bits. We will do
2041 * so ourselves when necessary.
2043 sb
->s_flags
|= MS_POSIXACL
;
2044 sb
->s_time_gran
= 1;
2047 sb
->s_op
= old_sb
->s_op
;
2048 nfs_initialise_sb(sb
);
2051 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2053 const struct nfs_server
*a
= s
->s_fs_info
;
2054 const struct rpc_clnt
*clnt_a
= a
->client
;
2055 const struct rpc_clnt
*clnt_b
= b
->client
;
2057 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2059 if (a
->nfs_client
!= b
->nfs_client
)
2061 if (a
->flags
!= b
->flags
)
2063 if (a
->wsize
!= b
->wsize
)
2065 if (a
->rsize
!= b
->rsize
)
2067 if (a
->acregmin
!= b
->acregmin
)
2069 if (a
->acregmax
!= b
->acregmax
)
2071 if (a
->acdirmin
!= b
->acdirmin
)
2073 if (a
->acdirmax
!= b
->acdirmax
)
2075 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2082 struct nfs_sb_mountdata
{
2083 struct nfs_server
*server
;
2087 static int nfs_set_super(struct super_block
*s
, void *data
)
2089 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2090 struct nfs_server
*server
= sb_mntdata
->server
;
2093 s
->s_flags
= sb_mntdata
->mntflags
;
2094 s
->s_fs_info
= server
;
2095 ret
= set_anon_super(s
, server
);
2097 server
->s_dev
= s
->s_dev
;
2101 static int nfs_compare_super_address(struct nfs_server
*server1
,
2102 struct nfs_server
*server2
)
2104 struct sockaddr
*sap1
, *sap2
;
2106 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2107 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2109 if (sap1
->sa_family
!= sap2
->sa_family
)
2112 switch (sap1
->sa_family
) {
2114 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2115 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2116 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2118 if (sin1
->sin_port
!= sin2
->sin_port
)
2123 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2124 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2125 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2127 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2138 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2140 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2141 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2142 int mntflags
= sb_mntdata
->mntflags
;
2144 if (!nfs_compare_super_address(old
, server
))
2146 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2147 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2149 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2151 return nfs_compare_mount_options(sb
, server
, mntflags
);
2154 static int nfs_bdi_register(struct nfs_server
*server
)
2156 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2159 static int nfs_get_sb(struct file_system_type
*fs_type
,
2160 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2162 struct nfs_server
*server
= NULL
;
2163 struct super_block
*s
;
2164 struct nfs_parsed_mount_data
*data
;
2165 struct nfs_fh
*mntfh
;
2166 struct dentry
*mntroot
;
2167 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2168 struct nfs_sb_mountdata sb_mntdata
= {
2171 int error
= -ENOMEM
;
2173 data
= nfs_alloc_parsed_mount_data(3);
2174 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2175 if (data
== NULL
|| mntfh
== NULL
)
2178 security_init_mnt_opts(&data
->lsm_opts
);
2180 /* Validate the mount data */
2181 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2185 #ifdef CONFIG_NFS_V4
2186 if (data
->version
== 4) {
2187 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2188 kfree(data
->client_address
);
2191 #endif /* CONFIG_NFS_V4 */
2193 /* Get a volume representation */
2194 server
= nfs_create_server(data
, mntfh
);
2195 if (IS_ERR(server
)) {
2196 error
= PTR_ERR(server
);
2199 sb_mntdata
.server
= server
;
2201 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2202 compare_super
= NULL
;
2204 /* Get a superblock - note that we may end up sharing one that already exists */
2205 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2211 if (s
->s_fs_info
!= server
) {
2212 nfs_free_server(server
);
2215 error
= nfs_bdi_register(server
);
2217 goto error_splat_super
;
2221 /* initial superblock/root creation */
2222 nfs_fill_super(s
, data
);
2223 nfs_fscache_get_super_cookie(
2224 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2227 mntroot
= nfs_get_root(s
, mntfh
);
2228 if (IS_ERR(mntroot
)) {
2229 error
= PTR_ERR(mntroot
);
2230 goto error_splat_super
;
2233 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2235 goto error_splat_root
;
2237 s
->s_flags
|= MS_ACTIVE
;
2239 mnt
->mnt_root
= mntroot
;
2243 kfree(data
->nfs_server
.hostname
);
2244 kfree(data
->mount_server
.hostname
);
2245 kfree(data
->fscache_uniq
);
2246 security_free_mnt_opts(&data
->lsm_opts
);
2253 nfs_free_server(server
);
2259 deactivate_locked_super(s
);
2264 * Ensure that we unregister the bdi before kill_anon_super
2265 * releases the device name
2267 static void nfs_put_super(struct super_block
*s
)
2269 struct nfs_server
*server
= NFS_SB(s
);
2271 bdi_unregister(&server
->backing_dev_info
);
2275 * Destroy an NFS2/3 superblock
2277 static void nfs_kill_super(struct super_block
*s
)
2279 struct nfs_server
*server
= NFS_SB(s
);
2282 nfs_fscache_release_super_cookie(s
);
2283 nfs_free_server(server
);
2287 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2289 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2290 const char *dev_name
, void *raw_data
,
2291 struct vfsmount
*mnt
)
2293 struct nfs_clone_mount
*data
= raw_data
;
2294 struct super_block
*s
;
2295 struct nfs_server
*server
;
2296 struct dentry
*mntroot
;
2297 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2298 struct nfs_sb_mountdata sb_mntdata
= {
2303 dprintk("--> nfs_xdev_get_sb()\n");
2305 /* create a new volume representation */
2306 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2307 if (IS_ERR(server
)) {
2308 error
= PTR_ERR(server
);
2309 goto out_err_noserver
;
2311 sb_mntdata
.server
= server
;
2313 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2314 compare_super
= NULL
;
2316 /* Get a superblock - note that we may end up sharing one that already exists */
2317 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2323 if (s
->s_fs_info
!= server
) {
2324 nfs_free_server(server
);
2327 error
= nfs_bdi_register(server
);
2329 goto error_splat_super
;
2333 /* initial superblock/root creation */
2334 nfs_clone_super(s
, data
->sb
);
2335 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2338 mntroot
= nfs_get_root(s
, data
->fh
);
2339 if (IS_ERR(mntroot
)) {
2340 error
= PTR_ERR(mntroot
);
2341 goto error_splat_super
;
2343 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2346 goto error_splat_super
;
2349 s
->s_flags
|= MS_ACTIVE
;
2351 mnt
->mnt_root
= mntroot
;
2353 /* clone any lsm security options from the parent to the new sb */
2354 security_sb_clone_mnt_opts(data
->sb
, s
);
2356 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2360 nfs_free_server(server
);
2362 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2366 deactivate_locked_super(s
);
2367 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2371 #ifdef CONFIG_NFS_V4
2374 * Finish setting up a cloned NFS4 superblock
2376 static void nfs4_clone_super(struct super_block
*sb
,
2377 const struct super_block
*old_sb
)
2379 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2380 sb
->s_blocksize
= old_sb
->s_blocksize
;
2381 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2382 sb
->s_time_gran
= 1;
2383 sb
->s_op
= old_sb
->s_op
;
2384 nfs_initialise_sb(sb
);
2388 * Set up an NFS4 superblock
2390 static void nfs4_fill_super(struct super_block
*sb
)
2392 sb
->s_time_gran
= 1;
2393 sb
->s_op
= &nfs4_sops
;
2394 nfs_initialise_sb(sb
);
2397 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2399 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2402 static int nfs4_validate_text_mount_data(void *options
,
2403 struct nfs_parsed_mount_data
*args
,
2404 const char *dev_name
)
2406 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2408 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2410 nfs_validate_transport_protocol(args
);
2412 nfs4_validate_mount_flags(args
);
2414 if (args
->version
!= 4) {
2416 "NFS4: Illegal mount version\n");
2420 if (args
->auth_flavor_len
> 1) {
2422 "NFS4: Too many RPC auth flavours specified\n");
2426 if (args
->client_address
== NULL
) {
2428 "NFS4: mount program didn't pass callback address\n");
2432 return nfs_parse_devname(dev_name
,
2433 &args
->nfs_server
.hostname
,
2435 &args
->nfs_server
.export_path
,
2440 * Validate NFSv4 mount options
2442 static int nfs4_validate_mount_data(void *options
,
2443 struct nfs_parsed_mount_data
*args
,
2444 const char *dev_name
)
2446 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2447 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2453 switch (data
->version
) {
2455 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2456 goto out_no_address
;
2457 if (data
->host_addrlen
== 0)
2458 goto out_no_address
;
2459 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2460 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2462 if (!nfs_verify_server_address(sap
))
2463 goto out_no_address
;
2465 if (data
->auth_flavourlen
) {
2466 if (data
->auth_flavourlen
> 1)
2467 goto out_inval_auth
;
2468 if (copy_from_user(&args
->auth_flavors
[0],
2469 data
->auth_flavours
,
2470 sizeof(args
->auth_flavors
[0])))
2474 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2477 args
->nfs_server
.hostname
= c
;
2479 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2482 args
->nfs_server
.export_path
= c
;
2483 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2485 c
= strndup_user(data
->client_addr
.data
, 16);
2488 args
->client_address
= c
;
2491 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2495 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2496 args
->rsize
= data
->rsize
;
2497 args
->wsize
= data
->wsize
;
2498 args
->timeo
= data
->timeo
;
2499 args
->retrans
= data
->retrans
;
2500 args
->acregmin
= data
->acregmin
;
2501 args
->acregmax
= data
->acregmax
;
2502 args
->acdirmin
= data
->acdirmin
;
2503 args
->acdirmax
= data
->acdirmax
;
2504 args
->nfs_server
.protocol
= data
->proto
;
2505 nfs_validate_transport_protocol(args
);
2509 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2512 if (!nfs_verify_server_address(sap
))
2515 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2521 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2525 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2526 data
->auth_flavourlen
);
2530 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2535 * Get the superblock for the NFS4 root partition
2537 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2538 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2540 struct nfs_parsed_mount_data
*data
= raw_data
;
2541 struct super_block
*s
;
2542 struct nfs_server
*server
;
2543 struct nfs_fh
*mntfh
;
2544 struct dentry
*mntroot
;
2545 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2546 struct nfs_sb_mountdata sb_mntdata
= {
2549 int error
= -ENOMEM
;
2551 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2552 if (data
== NULL
|| mntfh
== NULL
)
2555 security_init_mnt_opts(&data
->lsm_opts
);
2557 /* Get a volume representation */
2558 server
= nfs4_create_server(data
, mntfh
);
2559 if (IS_ERR(server
)) {
2560 error
= PTR_ERR(server
);
2563 sb_mntdata
.server
= server
;
2565 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2566 compare_super
= NULL
;
2568 /* Get a superblock - note that we may end up sharing one that already exists */
2569 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2575 if (s
->s_fs_info
!= server
) {
2576 nfs_free_server(server
);
2579 error
= nfs_bdi_register(server
);
2581 goto error_splat_super
;
2585 /* initial superblock/root creation */
2587 nfs_fscache_get_super_cookie(
2588 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2591 mntroot
= nfs4_get_root(s
, mntfh
);
2592 if (IS_ERR(mntroot
)) {
2593 error
= PTR_ERR(mntroot
);
2594 goto error_splat_super
;
2597 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2599 goto error_splat_root
;
2601 s
->s_flags
|= MS_ACTIVE
;
2603 mnt
->mnt_root
= mntroot
;
2607 security_free_mnt_opts(&data
->lsm_opts
);
2613 nfs_free_server(server
);
2619 deactivate_locked_super(s
);
2623 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2624 int flags
, void *data
, const char *hostname
)
2626 struct vfsmount
*root_mnt
;
2630 len
= strlen(hostname
) + 3;
2631 root_devname
= kmalloc(len
, GFP_KERNEL
);
2632 if (root_devname
== NULL
)
2633 return ERR_PTR(-ENOMEM
);
2634 snprintf(root_devname
, len
, "%s:/", hostname
);
2635 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2636 kfree(root_devname
);
2640 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2642 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2643 char *devname
, *tmp
;
2647 devname
= nfs_path(path
->mnt
->mnt_devname
,
2648 path
->mnt
->mnt_root
, path
->dentry
,
2650 if (devname
== NULL
)
2652 tmp
= kstrdup(devname
, GFP_KERNEL
);
2655 kfree(mnt
->mnt_devname
);
2656 mnt
->mnt_devname
= tmp
;
2658 free_page((unsigned long)page
);
2661 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2662 const char *export_path
, struct vfsmount
*mnt_target
)
2664 struct mnt_namespace
*ns_private
;
2665 struct nameidata nd
;
2666 struct super_block
*s
;
2669 ns_private
= create_mnt_ns(root_mnt
);
2670 ret
= PTR_ERR(ns_private
);
2671 if (IS_ERR(ns_private
))
2674 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2675 export_path
, LOOKUP_FOLLOW
, &nd
);
2677 put_mnt_ns(ns_private
);
2682 s
= nd
.path
.mnt
->mnt_sb
;
2683 atomic_inc(&s
->s_active
);
2684 mnt_target
->mnt_sb
= s
;
2685 mnt_target
->mnt_root
= dget(nd
.path
.dentry
);
2687 /* Correct the device pathname */
2688 nfs_fix_devname(&nd
.path
, mnt_target
);
2691 down_write(&s
->s_umount
);
2699 static int nfs4_try_mount(int flags
, const char *dev_name
,
2700 struct nfs_parsed_mount_data
*data
,
2701 struct vfsmount
*mnt
)
2704 struct vfsmount
*root_mnt
;
2707 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2709 export_path
= data
->nfs_server
.export_path
;
2710 data
->nfs_server
.export_path
= "/";
2711 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2712 data
->nfs_server
.hostname
);
2713 data
->nfs_server
.export_path
= export_path
;
2715 error
= PTR_ERR(root_mnt
);
2716 if (IS_ERR(root_mnt
))
2719 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2722 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2723 error
!= 0 ? " [error]" : "");
2728 * Get the superblock for an NFS4 mountpoint
2730 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2731 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2733 struct nfs_parsed_mount_data
*data
;
2734 int error
= -ENOMEM
;
2736 data
= nfs_alloc_parsed_mount_data(4);
2740 /* Validate the mount data */
2741 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2745 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2748 kfree(data
->client_address
);
2749 kfree(data
->nfs_server
.export_path
);
2750 kfree(data
->nfs_server
.hostname
);
2751 kfree(data
->fscache_uniq
);
2754 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2755 error
!= 0 ? " [error]" : "");
2759 static void nfs4_kill_super(struct super_block
*sb
)
2761 struct nfs_server
*server
= NFS_SB(sb
);
2763 dprintk("--> %s\n", __func__
);
2764 nfs_super_return_all_delegations(sb
);
2765 kill_anon_super(sb
);
2766 nfs_fscache_release_super_cookie(sb
);
2767 nfs_free_server(server
);
2768 dprintk("<-- %s\n", __func__
);
2772 * Clone an NFS4 server record on xdev traversal (FSID-change)
2774 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2775 const char *dev_name
, void *raw_data
,
2776 struct vfsmount
*mnt
)
2778 struct nfs_clone_mount
*data
= raw_data
;
2779 struct super_block
*s
;
2780 struct nfs_server
*server
;
2781 struct dentry
*mntroot
;
2782 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2783 struct nfs_sb_mountdata sb_mntdata
= {
2788 dprintk("--> nfs4_xdev_get_sb()\n");
2790 /* create a new volume representation */
2791 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2792 if (IS_ERR(server
)) {
2793 error
= PTR_ERR(server
);
2794 goto out_err_noserver
;
2796 sb_mntdata
.server
= server
;
2798 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2799 compare_super
= NULL
;
2801 /* Get a superblock - note that we may end up sharing one that already exists */
2802 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2808 if (s
->s_fs_info
!= server
) {
2809 nfs_free_server(server
);
2812 error
= nfs_bdi_register(server
);
2814 goto error_splat_super
;
2818 /* initial superblock/root creation */
2819 nfs4_clone_super(s
, data
->sb
);
2820 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2823 mntroot
= nfs4_get_root(s
, data
->fh
);
2824 if (IS_ERR(mntroot
)) {
2825 error
= PTR_ERR(mntroot
);
2826 goto error_splat_super
;
2828 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2831 goto error_splat_super
;
2834 s
->s_flags
|= MS_ACTIVE
;
2836 mnt
->mnt_root
= mntroot
;
2838 security_sb_clone_mnt_opts(data
->sb
, s
);
2840 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2844 nfs_free_server(server
);
2846 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2850 deactivate_locked_super(s
);
2851 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2855 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2856 int flags
, const char *dev_name
, void *raw_data
,
2857 struct vfsmount
*mnt
)
2859 struct nfs_clone_mount
*data
= raw_data
;
2860 struct super_block
*s
;
2861 struct nfs_server
*server
;
2862 struct dentry
*mntroot
;
2863 struct nfs_fh mntfh
;
2864 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2865 struct nfs_sb_mountdata sb_mntdata
= {
2870 dprintk("--> nfs4_referral_get_sb()\n");
2872 /* create a new volume representation */
2873 server
= nfs4_create_referral_server(data
, &mntfh
);
2874 if (IS_ERR(server
)) {
2875 error
= PTR_ERR(server
);
2876 goto out_err_noserver
;
2878 sb_mntdata
.server
= server
;
2880 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2881 compare_super
= NULL
;
2883 /* Get a superblock - note that we may end up sharing one that already exists */
2884 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2890 if (s
->s_fs_info
!= server
) {
2891 nfs_free_server(server
);
2894 error
= nfs_bdi_register(server
);
2896 goto error_splat_super
;
2900 /* initial superblock/root creation */
2902 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2905 mntroot
= nfs4_get_root(s
, &mntfh
);
2906 if (IS_ERR(mntroot
)) {
2907 error
= PTR_ERR(mntroot
);
2908 goto error_splat_super
;
2910 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2913 goto error_splat_super
;
2916 s
->s_flags
|= MS_ACTIVE
;
2918 mnt
->mnt_root
= mntroot
;
2920 security_sb_clone_mnt_opts(data
->sb
, s
);
2922 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2926 nfs_free_server(server
);
2928 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2932 deactivate_locked_super(s
);
2933 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2938 * Create an NFS4 server record on referral traversal
2940 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
2941 int flags
, const char *dev_name
, void *raw_data
,
2942 struct vfsmount
*mnt
)
2944 struct nfs_clone_mount
*data
= raw_data
;
2946 struct vfsmount
*root_mnt
;
2949 dprintk("--> nfs4_referral_get_sb()\n");
2951 export_path
= data
->mnt_path
;
2952 data
->mnt_path
= "/";
2954 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
2955 flags
, data
, data
->hostname
);
2956 data
->mnt_path
= export_path
;
2958 error
= PTR_ERR(root_mnt
);
2959 if (IS_ERR(root_mnt
))
2962 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2964 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
2965 error
!= 0 ? " [error]" : "");
2969 #endif /* CONFIG_NFS_V4 */