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/addr.h>
35 #include <linux/sunrpc/stats.h>
36 #include <linux/sunrpc/metrics.h>
37 #include <linux/sunrpc/xprtsock.h>
38 #include <linux/sunrpc/xprtrdma.h>
39 #include <linux/nfs_fs.h>
40 #include <linux/nfs_mount.h>
41 #include <linux/nfs4_mount.h>
42 #include <linux/lockd/bind.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/namei.h>
46 #include <linux/nfs_idmap.h>
47 #include <linux/vfs.h>
48 #include <linux/inet.h>
49 #include <linux/in6.h>
50 #include <linux/slab.h>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
56 #include <linux/nsproxy.h>
57 #include <linux/rcupdate.h>
58 #include <linux/kthread.h>
60 #include <asm/uaccess.h>
64 #include "delegation.h"
68 #include "nfs4session.h"
72 #define NFSDBG_FACILITY NFSDBG_VFS
73 #define NFS_TEXT_DATA 1
75 #if IS_ENABLED(CONFIG_NFS_V3)
76 #define NFS_DEFAULT_VERSION 3
78 #define NFS_DEFAULT_VERSION 2
82 /* Mount options that take no arguments */
84 Opt_posix
, Opt_noposix
,
88 Opt_udp
, Opt_tcp
, Opt_rdma
,
90 Opt_rdirplus
, Opt_nordirplus
,
91 Opt_sharecache
, Opt_nosharecache
,
92 Opt_resvport
, Opt_noresvport
,
93 Opt_fscache
, Opt_nofscache
,
94 Opt_migration
, Opt_nomigration
,
96 /* Mount options that take integer arguments */
98 Opt_rsize
, Opt_wsize
, Opt_bsize
,
99 Opt_timeo
, Opt_retrans
,
100 Opt_acregmin
, Opt_acregmax
,
101 Opt_acdirmin
, Opt_acdirmax
,
108 /* Mount options that take string arguments */
110 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
111 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
116 /* Special mount options */
117 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
122 static const match_table_t nfs_mount_option_tokens
= {
123 { Opt_userspace
, "bg" },
124 { Opt_userspace
, "fg" },
125 { Opt_userspace
, "retry=%s" },
127 { Opt_sloppy
, "sloppy" },
129 { Opt_soft
, "soft" },
130 { Opt_hard
, "hard" },
131 { Opt_deprecated
, "intr" },
132 { Opt_deprecated
, "nointr" },
133 { Opt_posix
, "posix" },
134 { Opt_noposix
, "noposix" },
136 { Opt_nocto
, "nocto" },
138 { Opt_noac
, "noac" },
139 { Opt_lock
, "lock" },
140 { Opt_nolock
, "nolock" },
143 { Opt_rdma
, "rdma" },
145 { Opt_noacl
, "noacl" },
146 { Opt_rdirplus
, "rdirplus" },
147 { Opt_nordirplus
, "nordirplus" },
148 { Opt_sharecache
, "sharecache" },
149 { Opt_nosharecache
, "nosharecache" },
150 { Opt_resvport
, "resvport" },
151 { Opt_noresvport
, "noresvport" },
152 { Opt_fscache
, "fsc" },
153 { Opt_nofscache
, "nofsc" },
154 { Opt_migration
, "migration" },
155 { Opt_nomigration
, "nomigration" },
157 { Opt_port
, "port=%s" },
158 { Opt_rsize
, "rsize=%s" },
159 { Opt_wsize
, "wsize=%s" },
160 { Opt_bsize
, "bsize=%s" },
161 { Opt_timeo
, "timeo=%s" },
162 { Opt_retrans
, "retrans=%s" },
163 { Opt_acregmin
, "acregmin=%s" },
164 { Opt_acregmax
, "acregmax=%s" },
165 { Opt_acdirmin
, "acdirmin=%s" },
166 { Opt_acdirmax
, "acdirmax=%s" },
167 { Opt_actimeo
, "actimeo=%s" },
168 { Opt_namelen
, "namlen=%s" },
169 { Opt_mountport
, "mountport=%s" },
170 { Opt_mountvers
, "mountvers=%s" },
171 { Opt_minorversion
, "minorversion=%s" },
173 { Opt_nfsvers
, "nfsvers=%s" },
174 { Opt_nfsvers
, "vers=%s" },
176 { Opt_sec
, "sec=%s" },
177 { Opt_proto
, "proto=%s" },
178 { Opt_mountproto
, "mountproto=%s" },
179 { Opt_addr
, "addr=%s" },
180 { Opt_clientaddr
, "clientaddr=%s" },
181 { Opt_mounthost
, "mounthost=%s" },
182 { Opt_mountaddr
, "mountaddr=%s" },
184 { Opt_lookupcache
, "lookupcache=%s" },
185 { Opt_fscache_uniq
, "fsc=%s" },
186 { Opt_local_lock
, "local_lock=%s" },
188 /* The following needs to be listed after all other options */
189 { Opt_nfsvers
, "v%s" },
195 Opt_xprt_udp
, Opt_xprt_udp6
, Opt_xprt_tcp
, Opt_xprt_tcp6
, Opt_xprt_rdma
,
200 static const match_table_t nfs_xprt_protocol_tokens
= {
201 { Opt_xprt_udp
, "udp" },
202 { Opt_xprt_udp6
, "udp6" },
203 { Opt_xprt_tcp
, "tcp" },
204 { Opt_xprt_tcp6
, "tcp6" },
205 { Opt_xprt_rdma
, "rdma" },
207 { Opt_xprt_err
, NULL
}
211 Opt_sec_none
, Opt_sec_sys
,
212 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
213 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
214 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
219 static const match_table_t nfs_secflavor_tokens
= {
220 { Opt_sec_none
, "none" },
221 { Opt_sec_none
, "null" },
222 { Opt_sec_sys
, "sys" },
224 { Opt_sec_krb5
, "krb5" },
225 { Opt_sec_krb5i
, "krb5i" },
226 { Opt_sec_krb5p
, "krb5p" },
228 { Opt_sec_lkey
, "lkey" },
229 { Opt_sec_lkeyi
, "lkeyi" },
230 { Opt_sec_lkeyp
, "lkeyp" },
232 { Opt_sec_spkm
, "spkm3" },
233 { Opt_sec_spkmi
, "spkm3i" },
234 { Opt_sec_spkmp
, "spkm3p" },
236 { Opt_sec_err
, NULL
}
240 Opt_lookupcache_all
, Opt_lookupcache_positive
,
241 Opt_lookupcache_none
,
246 static match_table_t nfs_lookupcache_tokens
= {
247 { Opt_lookupcache_all
, "all" },
248 { Opt_lookupcache_positive
, "pos" },
249 { Opt_lookupcache_positive
, "positive" },
250 { Opt_lookupcache_none
, "none" },
252 { Opt_lookupcache_err
, NULL
}
256 Opt_local_lock_all
, Opt_local_lock_flock
, Opt_local_lock_posix
,
262 static match_table_t nfs_local_lock_tokens
= {
263 { Opt_local_lock_all
, "all" },
264 { Opt_local_lock_flock
, "flock" },
265 { Opt_local_lock_posix
, "posix" },
266 { Opt_local_lock_none
, "none" },
268 { Opt_local_lock_err
, NULL
}
272 Opt_vers_2
, Opt_vers_3
, Opt_vers_4
, Opt_vers_4_0
,
278 static match_table_t nfs_vers_tokens
= {
282 { Opt_vers_4_0
, "4.0" },
283 { Opt_vers_4_1
, "4.1" },
285 { Opt_vers_err
, NULL
}
288 static struct dentry
*nfs_xdev_mount(struct file_system_type
*fs_type
,
289 int flags
, const char *dev_name
, void *raw_data
);
291 struct file_system_type nfs_fs_type
= {
292 .owner
= THIS_MODULE
,
294 .mount
= nfs_fs_mount
,
295 .kill_sb
= nfs_kill_super
,
296 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
298 EXPORT_SYMBOL_GPL(nfs_fs_type
);
300 struct file_system_type nfs_xdev_fs_type
= {
301 .owner
= THIS_MODULE
,
303 .mount
= nfs_xdev_mount
,
304 .kill_sb
= nfs_kill_super
,
305 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
308 const struct super_operations nfs_sops
= {
309 .alloc_inode
= nfs_alloc_inode
,
310 .destroy_inode
= nfs_destroy_inode
,
311 .write_inode
= nfs_write_inode
,
312 .drop_inode
= nfs_drop_inode
,
313 .put_super
= nfs_put_super
,
314 .statfs
= nfs_statfs
,
315 .evict_inode
= nfs_evict_inode
,
316 .umount_begin
= nfs_umount_begin
,
317 .show_options
= nfs_show_options
,
318 .show_devname
= nfs_show_devname
,
319 .show_path
= nfs_show_path
,
320 .show_stats
= nfs_show_stats
,
321 .remount_fs
= nfs_remount
,
323 EXPORT_SYMBOL_GPL(nfs_sops
);
325 #if IS_ENABLED(CONFIG_NFS_V4)
326 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*);
327 static int nfs4_validate_mount_data(void *options
,
328 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
330 struct file_system_type nfs4_fs_type
= {
331 .owner
= THIS_MODULE
,
333 .mount
= nfs_fs_mount
,
334 .kill_sb
= nfs_kill_super
,
335 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
337 EXPORT_SYMBOL_GPL(nfs4_fs_type
);
339 static int __init
register_nfs4_fs(void)
341 return register_filesystem(&nfs4_fs_type
);
344 static void unregister_nfs4_fs(void)
346 unregister_filesystem(&nfs4_fs_type
);
349 static int __init
register_nfs4_fs(void)
354 static void unregister_nfs4_fs(void)
359 static struct shrinker acl_shrinker
= {
360 .shrink
= nfs_access_cache_shrinker
,
361 .seeks
= DEFAULT_SEEKS
,
365 * Register the NFS filesystems
367 int __init
register_nfs_fs(void)
371 ret
= register_filesystem(&nfs_fs_type
);
375 ret
= register_nfs4_fs();
379 ret
= nfs_register_sysctl();
382 register_shrinker(&acl_shrinker
);
386 unregister_nfs4_fs();
388 unregister_filesystem(&nfs_fs_type
);
394 * Unregister the NFS filesystems
396 void __exit
unregister_nfs_fs(void)
398 unregister_shrinker(&acl_shrinker
);
399 nfs_unregister_sysctl();
400 unregister_nfs4_fs();
401 unregister_filesystem(&nfs_fs_type
);
404 void nfs_sb_active(struct super_block
*sb
)
406 struct nfs_server
*server
= NFS_SB(sb
);
408 if (atomic_inc_return(&server
->active
) == 1)
409 atomic_inc(&sb
->s_active
);
411 EXPORT_SYMBOL_GPL(nfs_sb_active
);
413 void nfs_sb_deactive(struct super_block
*sb
)
415 struct nfs_server
*server
= NFS_SB(sb
);
417 if (atomic_dec_and_test(&server
->active
))
418 deactivate_super(sb
);
420 EXPORT_SYMBOL_GPL(nfs_sb_deactive
);
422 static int nfs_deactivate_super_async_work(void *ptr
)
424 struct super_block
*sb
= ptr
;
426 deactivate_super(sb
);
427 module_put_and_exit(0);
432 * same effect as deactivate_super, but will do final unmount in kthread
435 static void nfs_deactivate_super_async(struct super_block
*sb
)
437 struct task_struct
*task
;
438 char buf
[INET6_ADDRSTRLEN
+ 1];
439 struct nfs_server
*server
= NFS_SB(sb
);
440 struct nfs_client
*clp
= server
->nfs_client
;
442 if (!atomic_add_unless(&sb
->s_active
, -1, 1)) {
444 snprintf(buf
, sizeof(buf
),
445 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_ADDR
));
448 __module_get(THIS_MODULE
);
449 task
= kthread_run(nfs_deactivate_super_async_work
, sb
,
450 "%s-deactivate-super", buf
);
452 pr_err("%s: kthread_run: %ld\n",
453 __func__
, PTR_ERR(task
));
454 /* make synchronous call and hope for the best */
455 deactivate_super(sb
);
456 module_put(THIS_MODULE
);
461 void nfs_sb_deactive_async(struct super_block
*sb
)
463 struct nfs_server
*server
= NFS_SB(sb
);
465 if (atomic_dec_and_test(&server
->active
))
466 nfs_deactivate_super_async(sb
);
468 EXPORT_SYMBOL_GPL(nfs_sb_deactive_async
);
471 * Deliver file system statistics to userspace
473 int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
475 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
476 unsigned char blockbits
;
477 unsigned long blockres
;
478 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
479 struct nfs_fsstat res
;
482 res
.fattr
= nfs_alloc_fattr();
483 if (res
.fattr
== NULL
)
486 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
487 if (unlikely(error
== -ESTALE
)) {
488 struct dentry
*pd_dentry
;
490 pd_dentry
= dget_parent(dentry
);
491 if (pd_dentry
!= NULL
) {
492 nfs_zap_caches(pd_dentry
->d_inode
);
496 nfs_free_fattr(res
.fattr
);
500 buf
->f_type
= NFS_SUPER_MAGIC
;
503 * Current versions of glibc do not correctly handle the
504 * case where f_frsize != f_bsize. Eventually we want to
505 * report the value of wtmult in this field.
507 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
510 * On most *nix systems, f_blocks, f_bfree, and f_bavail
511 * are reported in units of f_frsize. Linux hasn't had
512 * an f_frsize field in its statfs struct until recently,
513 * thus historically Linux's sys_statfs reports these
514 * fields in units of f_bsize.
516 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
517 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
518 blockres
= (1 << blockbits
) - 1;
519 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
520 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
521 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
523 buf
->f_files
= res
.tfiles
;
524 buf
->f_ffree
= res
.afiles
;
526 buf
->f_namelen
= server
->namelen
;
531 dprintk("%s: statfs error = %d\n", __func__
, -error
);
534 EXPORT_SYMBOL_GPL(nfs_statfs
);
537 * Map the security flavour number to a name
539 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
541 static const struct {
542 rpc_authflavor_t flavour
;
545 { RPC_AUTH_NULL
, "null" },
546 { RPC_AUTH_UNIX
, "sys" },
547 { RPC_AUTH_GSS_KRB5
, "krb5" },
548 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
549 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
550 { RPC_AUTH_GSS_LKEY
, "lkey" },
551 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
552 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
553 { RPC_AUTH_GSS_SPKM
, "spkm" },
554 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
555 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
556 { UINT_MAX
, "unknown" }
560 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
561 if (sec_flavours
[i
].flavour
== flavour
)
564 return sec_flavours
[i
].str
;
567 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
570 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
572 seq_printf(m
, ",mountproto=");
573 switch (sap
->sa_family
) {
575 switch (nfss
->mountd_protocol
) {
577 seq_printf(m
, RPCBIND_NETID_UDP
);
580 seq_printf(m
, RPCBIND_NETID_TCP
);
584 seq_printf(m
, "auto");
588 switch (nfss
->mountd_protocol
) {
590 seq_printf(m
, RPCBIND_NETID_UDP6
);
593 seq_printf(m
, RPCBIND_NETID_TCP6
);
597 seq_printf(m
, "auto");
602 seq_printf(m
, "auto");
606 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
609 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
611 if (nfss
->flags
& NFS_MOUNT_LEGACY_INTERFACE
)
614 switch (sap
->sa_family
) {
616 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
617 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
621 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
622 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
627 seq_printf(m
, ",mountaddr=unspecified");
630 if (nfss
->mountd_version
|| showdefaults
)
631 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
632 if ((nfss
->mountd_port
&&
633 nfss
->mountd_port
!= (unsigned short)NFS_UNSPEC_PORT
) ||
635 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
637 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
640 #if IS_ENABLED(CONFIG_NFS_V4)
641 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
644 struct nfs_client
*clp
= nfss
->nfs_client
;
646 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
649 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
655 static void nfs_show_nfs_version(struct seq_file
*m
,
656 unsigned int version
,
657 unsigned int minorversion
)
659 seq_printf(m
, ",vers=%u", version
);
661 seq_printf(m
, ".%u", minorversion
);
665 * Describe the mount options in force on this server representation
667 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
670 static const struct proc_nfs_info
{
675 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
676 { NFS_MOUNT_POSIX
, ",posix", "" },
677 { NFS_MOUNT_NOCTO
, ",nocto", "" },
678 { NFS_MOUNT_NOAC
, ",noac", "" },
679 { NFS_MOUNT_NONLM
, ",nolock", "" },
680 { NFS_MOUNT_NOACL
, ",noacl", "" },
681 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
682 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
683 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
686 const struct proc_nfs_info
*nfs_infop
;
687 struct nfs_client
*clp
= nfss
->nfs_client
;
688 u32 version
= clp
->rpc_ops
->version
;
689 int local_flock
, local_fcntl
;
691 nfs_show_nfs_version(m
, version
, clp
->cl_minorversion
);
692 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
693 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
694 if (nfss
->bsize
!= 0)
695 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
696 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
697 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
698 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
699 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
700 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
701 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
702 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
703 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
704 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
705 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
706 if (nfss
->flags
& nfs_infop
->flag
)
707 seq_puts(m
, nfs_infop
->str
);
709 seq_puts(m
, nfs_infop
->nostr
);
712 seq_printf(m
, ",proto=%s",
713 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
716 if (nfss
->port
!= NFS_PORT
)
717 seq_printf(m
, ",port=%u", nfss
->port
);
720 seq_printf(m
, ",port=%u", nfss
->port
);
722 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
723 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
724 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
727 nfs_show_mountd_options(m
, nfss
, showdefaults
);
729 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
731 if (nfss
->options
& NFS_OPTION_FSCACHE
)
732 seq_printf(m
, ",fsc");
734 if (nfss
->options
& NFS_OPTION_MIGRATION
)
735 seq_printf(m
, ",migration");
737 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONEG
) {
738 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONE
)
739 seq_printf(m
, ",lookupcache=none");
741 seq_printf(m
, ",lookupcache=pos");
744 local_flock
= nfss
->flags
& NFS_MOUNT_LOCAL_FLOCK
;
745 local_fcntl
= nfss
->flags
& NFS_MOUNT_LOCAL_FCNTL
;
747 if (!local_flock
&& !local_fcntl
)
748 seq_printf(m
, ",local_lock=none");
749 else if (local_flock
&& local_fcntl
)
750 seq_printf(m
, ",local_lock=all");
751 else if (local_flock
)
752 seq_printf(m
, ",local_lock=flock");
754 seq_printf(m
, ",local_lock=posix");
758 * Describe the mount options on this VFS mountpoint
760 int nfs_show_options(struct seq_file
*m
, struct dentry
*root
)
762 struct nfs_server
*nfss
= NFS_SB(root
->d_sb
);
764 nfs_show_mount_options(m
, nfss
, 0);
767 seq_printf(m
, ",addr=%s",
768 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
774 EXPORT_SYMBOL_GPL(nfs_show_options
);
776 #if IS_ENABLED(CONFIG_NFS_V4)
777 #ifdef CONFIG_NFS_V4_1
778 static void show_sessions(struct seq_file
*m
, struct nfs_server
*server
)
780 if (nfs4_has_session(server
->nfs_client
))
781 seq_printf(m
, ",sessions");
784 static void show_sessions(struct seq_file
*m
, struct nfs_server
*server
) {}
788 #ifdef CONFIG_NFS_V4_1
789 static void show_pnfs(struct seq_file
*m
, struct nfs_server
*server
)
791 seq_printf(m
, ",pnfs=");
792 if (server
->pnfs_curr_ld
)
793 seq_printf(m
, "%s", server
->pnfs_curr_ld
->name
);
795 seq_printf(m
, "not configured");
798 static void show_implementation_id(struct seq_file
*m
, struct nfs_server
*nfss
)
800 if (nfss
->nfs_client
&& nfss
->nfs_client
->cl_implid
) {
801 struct nfs41_impl_id
*impl_id
= nfss
->nfs_client
->cl_implid
;
802 seq_printf(m
, "\n\timpl_id:\tname='%s',domain='%s',"
804 impl_id
->name
, impl_id
->domain
,
805 impl_id
->date
.seconds
, impl_id
->date
.nseconds
);
809 #if IS_ENABLED(CONFIG_NFS_V4)
810 static void show_pnfs(struct seq_file
*m
, struct nfs_server
*server
)
814 static void show_implementation_id(struct seq_file
*m
, struct nfs_server
*nfss
)
819 int nfs_show_devname(struct seq_file
*m
, struct dentry
*root
)
821 char *page
= (char *) __get_free_page(GFP_KERNEL
);
822 char *devname
, *dummy
;
826 devname
= nfs_path(&dummy
, root
, page
, PAGE_SIZE
, 0);
828 err
= PTR_ERR(devname
);
830 seq_escape(m
, devname
, " \t\n\\");
831 free_page((unsigned long)page
);
834 EXPORT_SYMBOL_GPL(nfs_show_devname
);
836 int nfs_show_path(struct seq_file
*m
, struct dentry
*dentry
)
841 EXPORT_SYMBOL_GPL(nfs_show_path
);
844 * Present statistical information for this VFS mountpoint
846 int nfs_show_stats(struct seq_file
*m
, struct dentry
*root
)
849 struct nfs_server
*nfss
= NFS_SB(root
->d_sb
);
850 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
851 struct nfs_iostats totals
= { };
853 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
856 * Display all mount option settings
858 seq_printf(m
, "\n\topts:\t");
859 seq_puts(m
, root
->d_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
860 seq_puts(m
, root
->d_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
861 seq_puts(m
, root
->d_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
862 seq_puts(m
, root
->d_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
863 nfs_show_mount_options(m
, nfss
, 1);
865 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
867 show_implementation_id(m
, nfss
);
869 seq_printf(m
, "\n\tcaps:\t");
870 seq_printf(m
, "caps=0x%x", nfss
->caps
);
871 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
872 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
873 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
874 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
876 #if IS_ENABLED(CONFIG_NFS_V4)
877 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
878 seq_printf(m
, "\n\tnfsv4:\t");
879 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
880 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
881 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
882 show_sessions(m
, nfss
);
888 * Display security flavor in effect for this mount
890 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
892 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
895 * Display superblock I/O counters
897 for_each_possible_cpu(cpu
) {
898 struct nfs_iostats
*stats
;
901 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
903 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
904 totals
.events
[i
] += stats
->events
[i
];
905 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
906 totals
.bytes
[i
] += stats
->bytes
[i
];
907 #ifdef CONFIG_NFS_FSCACHE
908 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
909 totals
.fscache
[i
] += stats
->fscache
[i
];
915 seq_printf(m
, "\n\tevents:\t");
916 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
917 seq_printf(m
, "%lu ", totals
.events
[i
]);
918 seq_printf(m
, "\n\tbytes:\t");
919 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
920 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
921 #ifdef CONFIG_NFS_FSCACHE
922 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
923 seq_printf(m
, "\n\tfsc:\t");
924 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
925 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
930 rpc_print_iostats(m
, nfss
->client
);
934 EXPORT_SYMBOL_GPL(nfs_show_stats
);
937 * Begin unmount by attempting to remove all automounted mountpoints we added
938 * in response to xdev traversals and referrals
940 void nfs_umount_begin(struct super_block
*sb
)
942 struct nfs_server
*server
;
943 struct rpc_clnt
*rpc
;
946 /* -EIO all pending I/O */
947 rpc
= server
->client_acl
;
949 rpc_killall_tasks(rpc
);
950 rpc
= server
->client
;
952 rpc_killall_tasks(rpc
);
954 EXPORT_SYMBOL_GPL(nfs_umount_begin
);
956 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(void)
958 struct nfs_parsed_mount_data
*data
;
960 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
962 data
->acregmin
= NFS_DEF_ACREGMIN
;
963 data
->acregmax
= NFS_DEF_ACREGMAX
;
964 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
965 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
966 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
967 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
968 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
969 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
970 data
->auth_flavor_len
= 1;
971 data
->minorversion
= 0;
972 data
->need_mount
= true;
973 data
->net
= current
->nsproxy
->net_ns
;
974 security_init_mnt_opts(&data
->lsm_opts
);
979 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data
*data
)
982 kfree(data
->client_address
);
983 kfree(data
->mount_server
.hostname
);
984 kfree(data
->nfs_server
.export_path
);
985 kfree(data
->nfs_server
.hostname
);
986 kfree(data
->fscache_uniq
);
987 security_free_mnt_opts(&data
->lsm_opts
);
993 * Sanity-check a server address provided by the mount command.
995 * Address family must be initialized, and address must not be
996 * the ANY address for that family.
998 static int nfs_verify_server_address(struct sockaddr
*addr
)
1000 switch (addr
->sa_family
) {
1002 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
1003 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
1006 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
1007 return !ipv6_addr_any(sa
);
1011 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
1016 * Select between a default port value and a user-specified port value.
1017 * If a zero value is set, then autobind will be used.
1019 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
1020 const unsigned short default_port
)
1022 if (*port
== NFS_UNSPEC_PORT
)
1023 *port
= default_port
;
1025 rpc_set_port(sap
, *port
);
1029 * Sanity check the NFS transport protocol.
1032 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
1034 switch (mnt
->nfs_server
.protocol
) {
1035 case XPRT_TRANSPORT_UDP
:
1036 case XPRT_TRANSPORT_TCP
:
1037 case XPRT_TRANSPORT_RDMA
:
1040 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1045 * For text based NFSv2/v3 mounts, the mount protocol transport default
1046 * settings should depend upon the specified NFS transport.
1048 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
1050 nfs_validate_transport_protocol(mnt
);
1052 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
1053 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
1055 switch (mnt
->nfs_server
.protocol
) {
1056 case XPRT_TRANSPORT_UDP
:
1057 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1059 case XPRT_TRANSPORT_TCP
:
1060 case XPRT_TRANSPORT_RDMA
:
1061 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1066 * Parse the value of the 'sec=' option.
1068 static int nfs_parse_security_flavors(char *value
,
1069 struct nfs_parsed_mount_data
*mnt
)
1071 substring_t args
[MAX_OPT_ARGS
];
1073 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
1075 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
1077 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
1080 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1083 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
1086 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
1089 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
1092 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
1095 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
1098 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
1101 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
1104 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
1107 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
1113 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
1114 mnt
->auth_flavor_len
= 1;
1118 static int nfs_parse_version_string(char *string
,
1119 struct nfs_parsed_mount_data
*mnt
,
1122 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1123 switch (match_token(string
, nfs_vers_tokens
, args
)) {
1128 mnt
->flags
|= NFS_MOUNT_VER3
;
1132 /* Backward compatibility option. In future,
1133 * the mount program should always supply
1134 * a NFSv4 minor version number.
1140 mnt
->minorversion
= 0;
1144 mnt
->minorversion
= 1;
1152 static int nfs_get_option_str(substring_t args
[], char **option
)
1155 *option
= match_strdup(args
);
1159 static int nfs_get_option_ul(substring_t args
[], unsigned long *option
)
1164 string
= match_strdup(args
);
1167 rc
= kstrtoul(string
, 10, option
);
1174 * Error-check and convert a string of mount options from user space into
1175 * a data structure. The whole mount string is processed; bad options are
1176 * skipped as they are encountered. If there were no errors, return 1;
1177 * otherwise return 0 (zero).
1179 static int nfs_parse_mount_options(char *raw
,
1180 struct nfs_parsed_mount_data
*mnt
)
1182 char *p
, *string
, *secdata
;
1183 int rc
, sloppy
= 0, invalid_option
= 0;
1184 unsigned short protofamily
= AF_UNSPEC
;
1185 unsigned short mountfamily
= AF_UNSPEC
;
1188 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
1191 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
1193 secdata
= alloc_secdata();
1197 rc
= security_sb_copy_data(raw
, secdata
);
1199 goto out_security_failure
;
1201 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
1203 goto out_security_failure
;
1205 free_secdata(secdata
);
1207 while ((p
= strsep(&raw
, ",")) != NULL
) {
1208 substring_t args
[MAX_OPT_ARGS
];
1209 unsigned long option
;
1215 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
1217 token
= match_token(p
, nfs_mount_option_tokens
, args
);
1221 * boolean options: foo/nofoo
1224 mnt
->flags
|= NFS_MOUNT_SOFT
;
1227 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
1230 mnt
->flags
|= NFS_MOUNT_POSIX
;
1233 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
1236 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1239 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1242 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1245 mnt
->flags
|= NFS_MOUNT_NOAC
;
1248 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1249 mnt
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1250 NFS_MOUNT_LOCAL_FCNTL
);
1253 mnt
->flags
|= NFS_MOUNT_NONLM
;
1254 mnt
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1255 NFS_MOUNT_LOCAL_FCNTL
);
1258 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1259 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1262 mnt
->flags
|= NFS_MOUNT_TCP
;
1263 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1266 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1267 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1268 xprt_load_transport(p
);
1271 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1274 mnt
->flags
|= NFS_MOUNT_NOACL
;
1277 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1279 case Opt_nordirplus
:
1280 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1282 case Opt_sharecache
:
1283 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1285 case Opt_nosharecache
:
1286 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1289 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1291 case Opt_noresvport
:
1292 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1295 mnt
->options
|= NFS_OPTION_FSCACHE
;
1296 kfree(mnt
->fscache_uniq
);
1297 mnt
->fscache_uniq
= NULL
;
1300 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1301 kfree(mnt
->fscache_uniq
);
1302 mnt
->fscache_uniq
= NULL
;
1305 mnt
->options
|= NFS_OPTION_MIGRATION
;
1307 case Opt_nomigration
:
1308 mnt
->options
&= NFS_OPTION_MIGRATION
;
1312 * options that take numeric values
1315 if (nfs_get_option_ul(args
, &option
) ||
1317 goto out_invalid_value
;
1318 mnt
->nfs_server
.port
= option
;
1321 if (nfs_get_option_ul(args
, &option
))
1322 goto out_invalid_value
;
1323 mnt
->rsize
= option
;
1326 if (nfs_get_option_ul(args
, &option
))
1327 goto out_invalid_value
;
1328 mnt
->wsize
= option
;
1331 if (nfs_get_option_ul(args
, &option
))
1332 goto out_invalid_value
;
1333 mnt
->bsize
= option
;
1336 if (nfs_get_option_ul(args
, &option
) || option
== 0)
1337 goto out_invalid_value
;
1338 mnt
->timeo
= option
;
1341 if (nfs_get_option_ul(args
, &option
) || option
== 0)
1342 goto out_invalid_value
;
1343 mnt
->retrans
= option
;
1346 if (nfs_get_option_ul(args
, &option
))
1347 goto out_invalid_value
;
1348 mnt
->acregmin
= option
;
1351 if (nfs_get_option_ul(args
, &option
))
1352 goto out_invalid_value
;
1353 mnt
->acregmax
= option
;
1356 if (nfs_get_option_ul(args
, &option
))
1357 goto out_invalid_value
;
1358 mnt
->acdirmin
= option
;
1361 if (nfs_get_option_ul(args
, &option
))
1362 goto out_invalid_value
;
1363 mnt
->acdirmax
= option
;
1366 if (nfs_get_option_ul(args
, &option
))
1367 goto out_invalid_value
;
1368 mnt
->acregmin
= mnt
->acregmax
=
1369 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1372 if (nfs_get_option_ul(args
, &option
))
1373 goto out_invalid_value
;
1374 mnt
->namlen
= option
;
1377 if (nfs_get_option_ul(args
, &option
) ||
1379 goto out_invalid_value
;
1380 mnt
->mount_server
.port
= option
;
1383 if (nfs_get_option_ul(args
, &option
) ||
1384 option
< NFS_MNT_VERSION
||
1385 option
> NFS_MNT3_VERSION
)
1386 goto out_invalid_value
;
1387 mnt
->mount_server
.version
= option
;
1389 case Opt_minorversion
:
1390 if (nfs_get_option_ul(args
, &option
))
1391 goto out_invalid_value
;
1392 if (option
> NFS4_MAX_MINOR_VERSION
)
1393 goto out_invalid_value
;
1394 mnt
->minorversion
= option
;
1398 * options that take text values
1401 string
= match_strdup(args
);
1404 rc
= nfs_parse_version_string(string
, mnt
, args
);
1407 goto out_invalid_value
;
1410 string
= match_strdup(args
);
1413 rc
= nfs_parse_security_flavors(string
, mnt
);
1416 dfprintk(MOUNT
, "NFS: unrecognized "
1417 "security flavor\n");
1422 string
= match_strdup(args
);
1425 token
= match_token(string
,
1426 nfs_xprt_protocol_tokens
, args
);
1428 protofamily
= AF_INET
;
1431 protofamily
= AF_INET6
;
1433 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1434 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1437 protofamily
= AF_INET6
;
1439 mnt
->flags
|= NFS_MOUNT_TCP
;
1440 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1443 /* vector side protocols to TCP */
1444 mnt
->flags
|= NFS_MOUNT_TCP
;
1445 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1446 xprt_load_transport(string
);
1449 dfprintk(MOUNT
, "NFS: unrecognized "
1450 "transport protocol\n");
1456 case Opt_mountproto
:
1457 string
= match_strdup(args
);
1460 token
= match_token(string
,
1461 nfs_xprt_protocol_tokens
, args
);
1464 mountfamily
= AF_INET
;
1467 mountfamily
= AF_INET6
;
1469 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1472 mountfamily
= AF_INET6
;
1474 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1476 case Opt_xprt_rdma
: /* not used for side protocols */
1478 dfprintk(MOUNT
, "NFS: unrecognized "
1479 "transport protocol\n");
1484 string
= match_strdup(args
);
1487 mnt
->nfs_server
.addrlen
=
1488 rpc_pton(mnt
->net
, string
, strlen(string
),
1490 &mnt
->nfs_server
.address
,
1491 sizeof(mnt
->nfs_server
.address
));
1493 if (mnt
->nfs_server
.addrlen
== 0)
1494 goto out_invalid_address
;
1496 case Opt_clientaddr
:
1497 if (nfs_get_option_str(args
, &mnt
->client_address
))
1501 if (nfs_get_option_str(args
,
1502 &mnt
->mount_server
.hostname
))
1506 string
= match_strdup(args
);
1509 mnt
->mount_server
.addrlen
=
1510 rpc_pton(mnt
->net
, string
, strlen(string
),
1512 &mnt
->mount_server
.address
,
1513 sizeof(mnt
->mount_server
.address
));
1515 if (mnt
->mount_server
.addrlen
== 0)
1516 goto out_invalid_address
;
1518 case Opt_lookupcache
:
1519 string
= match_strdup(args
);
1522 token
= match_token(string
,
1523 nfs_lookupcache_tokens
, args
);
1526 case Opt_lookupcache_all
:
1527 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1529 case Opt_lookupcache_positive
:
1530 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1531 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1533 case Opt_lookupcache_none
:
1534 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1537 dfprintk(MOUNT
, "NFS: invalid "
1538 "lookupcache argument\n");
1542 case Opt_fscache_uniq
:
1543 if (nfs_get_option_str(args
, &mnt
->fscache_uniq
))
1545 mnt
->options
|= NFS_OPTION_FSCACHE
;
1547 case Opt_local_lock
:
1548 string
= match_strdup(args
);
1551 token
= match_token(string
, nfs_local_lock_tokens
,
1555 case Opt_local_lock_all
:
1556 mnt
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1557 NFS_MOUNT_LOCAL_FCNTL
);
1559 case Opt_local_lock_flock
:
1560 mnt
->flags
|= NFS_MOUNT_LOCAL_FLOCK
;
1562 case Opt_local_lock_posix
:
1563 mnt
->flags
|= NFS_MOUNT_LOCAL_FCNTL
;
1565 case Opt_local_lock_none
:
1566 mnt
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1567 NFS_MOUNT_LOCAL_FCNTL
);
1570 dfprintk(MOUNT
, "NFS: invalid "
1571 "local_lock argument\n");
1581 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1584 case Opt_deprecated
:
1585 dfprintk(MOUNT
, "NFS: ignoring mount option "
1591 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1596 if (!sloppy
&& invalid_option
)
1599 if (mnt
->minorversion
&& mnt
->version
!= 4)
1600 goto out_minorversion_mismatch
;
1602 if (mnt
->options
& NFS_OPTION_MIGRATION
&&
1603 mnt
->version
!= 4 && mnt
->minorversion
!= 0)
1604 goto out_migration_misuse
;
1607 * verify that any proto=/mountproto= options match the address
1608 * families in the addr=/mountaddr= options.
1610 if (protofamily
!= AF_UNSPEC
&&
1611 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1612 goto out_proto_mismatch
;
1614 if (mountfamily
!= AF_UNSPEC
) {
1615 if (mnt
->mount_server
.addrlen
) {
1616 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1617 goto out_mountproto_mismatch
;
1619 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1620 goto out_mountproto_mismatch
;
1626 out_mountproto_mismatch
:
1627 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1631 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1633 out_invalid_address
:
1634 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1637 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1639 out_minorversion_mismatch
:
1640 printk(KERN_INFO
"NFS: mount option vers=%u does not support "
1641 "minorversion=%u\n", mnt
->version
, mnt
->minorversion
);
1643 out_migration_misuse
:
1645 "NFS: 'migration' not supported for this NFS version\n");
1648 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1650 out_security_failure
:
1651 free_secdata(secdata
);
1652 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1657 * Match the requested auth flavors with the list returned by
1658 * the server. Returns zero and sets the mount's authentication
1659 * flavor on success; returns -EACCES if server does not support
1660 * the requested flavor.
1662 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1663 struct nfs_mount_request
*request
)
1665 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1668 * Certain releases of Linux's mountd return an empty
1669 * flavor list. To prevent behavioral regression with
1670 * these servers (ie. rejecting mounts that used to
1671 * succeed), revert to pre-2.6.32 behavior (no checking)
1672 * if the returned flavor list is empty.
1674 if (server_authlist_len
== 0)
1678 * We avoid sophisticated negotiating here, as there are
1679 * plenty of cases where we can get it wrong, providing
1680 * either too little or too much security.
1682 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1683 * flavor listed first. However, some servers list
1684 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1685 * preferred default, in args->auth_flavors[0] if user
1686 * didn't specify sec= mount option.
1688 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1689 for (j
= 0; j
< server_authlist_len
; j
++)
1690 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1691 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1692 request
->auth_flavs
[j
]);
1693 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1697 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1698 nfs_umount(request
);
1703 * Use the remote server's MOUNT service to request the NFS file handle
1704 * corresponding to the provided path.
1706 static int nfs_request_mount(struct nfs_parsed_mount_data
*args
,
1707 struct nfs_fh
*root_fh
)
1709 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1710 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1711 struct nfs_mount_request request
= {
1712 .sap
= (struct sockaddr
*)
1713 &args
->mount_server
.address
,
1714 .dirpath
= args
->nfs_server
.export_path
,
1715 .protocol
= args
->mount_server
.protocol
,
1717 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1718 .auth_flav_len
= &server_authlist_len
,
1719 .auth_flavs
= server_authlist
,
1724 if (args
->mount_server
.version
== 0) {
1725 switch (args
->version
) {
1727 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1730 args
->mount_server
.version
= NFS_MNT_VERSION
;
1733 request
.version
= args
->mount_server
.version
;
1735 if (args
->mount_server
.hostname
)
1736 request
.hostname
= args
->mount_server
.hostname
;
1738 request
.hostname
= args
->nfs_server
.hostname
;
1741 * Construct the mount server's address.
1743 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1744 memcpy(request
.sap
, &args
->nfs_server
.address
,
1745 args
->nfs_server
.addrlen
);
1746 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1748 request
.salen
= args
->mount_server
.addrlen
;
1749 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1752 * Now ask the mount server to map our export path
1755 status
= nfs_mount(&request
);
1757 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1758 request
.hostname
, status
);
1763 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1765 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1767 return nfs_walk_authlist(args
, &request
);
1770 struct dentry
*nfs_try_mount(int flags
, const char *dev_name
,
1771 struct nfs_mount_info
*mount_info
,
1772 struct nfs_subversion
*nfs_mod
)
1775 struct nfs_server
*server
;
1777 if (mount_info
->parsed
->need_mount
) {
1778 status
= nfs_request_mount(mount_info
->parsed
, mount_info
->mntfh
);
1780 return ERR_PTR(status
);
1783 /* Get a volume representation */
1784 server
= nfs_mod
->rpc_ops
->create_server(mount_info
, nfs_mod
);
1786 return ERR_CAST(server
);
1788 return nfs_fs_mount_common(server
, flags
, dev_name
, mount_info
, nfs_mod
);
1790 EXPORT_SYMBOL_GPL(nfs_try_mount
);
1793 * Split "dev_name" into "hostname:export_path".
1795 * The leftmost colon demarks the split between the server's hostname
1796 * and the export path. If the hostname starts with a left square
1797 * bracket, then it may contain colons.
1799 * Note: caller frees hostname and export path, even on error.
1801 static int nfs_parse_devname(const char *dev_name
,
1802 char **hostname
, size_t maxnamlen
,
1803 char **export_path
, size_t maxpathlen
)
1808 /* Is the host name protected with square brakcets? */
1809 if (*dev_name
== '[') {
1810 end
= strchr(++dev_name
, ']');
1811 if (end
== NULL
|| end
[1] != ':')
1812 goto out_bad_devname
;
1814 len
= end
- dev_name
;
1819 end
= strchr(dev_name
, ':');
1821 goto out_bad_devname
;
1822 len
= end
- dev_name
;
1824 /* kill possible hostname list: not supported */
1825 comma
= strchr(dev_name
, ',');
1826 if (comma
!= NULL
&& comma
< end
)
1830 if (len
> maxnamlen
)
1833 /* N.B. caller will free nfs_server.hostname in all cases */
1834 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1835 if (*hostname
== NULL
)
1837 len
= strlen(++end
);
1838 if (len
> maxpathlen
)
1840 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1844 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1848 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1852 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1856 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1857 return -ENAMETOOLONG
;
1860 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1861 return -ENAMETOOLONG
;
1865 * Validate the NFS2/NFS3 mount data
1866 * - fills in the mount root filehandle
1868 * For option strings, user space handles the following behaviors:
1870 * + DNS: mapping server host name to IP address ("addr=" option)
1872 * + failure mode: how to behave if a mount request can't be handled
1873 * immediately ("fg/bg" option)
1875 * + retry: how often to retry a mount request ("retry=" option)
1877 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1878 * mountproto=tcp after mountproto=udp, and so on
1880 static int nfs23_validate_mount_data(void *options
,
1881 struct nfs_parsed_mount_data
*args
,
1882 struct nfs_fh
*mntfh
,
1883 const char *dev_name
)
1885 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1886 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1891 args
->version
= NFS_DEFAULT_VERSION
;
1892 switch (data
->version
) {
1898 if (data
->flags
& NFS_MOUNT_VER3
)
1900 data
->root
.size
= NFS2_FHSIZE
;
1901 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1903 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1906 memset(data
->context
, 0, sizeof(data
->context
));
1908 if (data
->flags
& NFS_MOUNT_VER3
) {
1909 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1910 goto out_invalid_fh
;
1911 mntfh
->size
= data
->root
.size
;
1914 mntfh
->size
= NFS2_FHSIZE
;
1919 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1920 if (mntfh
->size
< sizeof(mntfh
->data
))
1921 memset(mntfh
->data
+ mntfh
->size
, 0,
1922 sizeof(mntfh
->data
) - mntfh
->size
);
1925 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1928 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1929 args
->flags
|= NFS_MOUNT_LEGACY_INTERFACE
;
1930 args
->rsize
= data
->rsize
;
1931 args
->wsize
= data
->wsize
;
1932 args
->timeo
= data
->timeo
;
1933 args
->retrans
= data
->retrans
;
1934 args
->acregmin
= data
->acregmin
;
1935 args
->acregmax
= data
->acregmax
;
1936 args
->acdirmin
= data
->acdirmin
;
1937 args
->acdirmax
= data
->acdirmax
;
1938 args
->need_mount
= false;
1940 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1941 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1942 args
->nfs_server
.port
= ntohs(data
->addr
.sin_port
);
1943 if (!nfs_verify_server_address(sap
))
1944 goto out_no_address
;
1946 if (!(data
->flags
& NFS_MOUNT_TCP
))
1947 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1948 /* N.B. caller will free nfs_server.hostname in all cases */
1949 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1950 args
->namlen
= data
->namlen
;
1951 args
->bsize
= data
->bsize
;
1953 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1954 args
->auth_flavors
[0] = data
->pseudoflavor
;
1955 if (!args
->nfs_server
.hostname
)
1958 if (!(data
->flags
& NFS_MOUNT_NONLM
))
1959 args
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1960 NFS_MOUNT_LOCAL_FCNTL
);
1962 args
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1963 NFS_MOUNT_LOCAL_FCNTL
);
1965 * The legacy version 6 binary mount data from userspace has a
1966 * field used only to transport selinux information into the
1967 * the kernel. To continue to support that functionality we
1968 * have a touch of selinux knowledge here in the NFS code. The
1969 * userspace code converted context=blah to just blah so we are
1970 * converting back to the full string selinux understands.
1972 if (data
->context
[0]){
1973 #ifdef CONFIG_SECURITY_SELINUX
1975 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1978 strcpy(opts_str
, "context=");
1979 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1980 strcat(opts_str
, &data
->context
[0]);
1981 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1992 return NFS_TEXT_DATA
;
1995 #if !IS_ENABLED(CONFIG_NFS_V3)
1996 if (args
->version
== 3)
1997 goto out_v3_not_compiled
;
1998 #endif /* !CONFIG_NFS_V3 */
2003 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
2007 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
2012 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2015 #if !IS_ENABLED(CONFIG_NFS_V3)
2016 out_v3_not_compiled
:
2017 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
2018 return -EPROTONOSUPPORT
;
2019 #endif /* !CONFIG_NFS_V3 */
2022 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
2026 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
2030 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
2034 #if IS_ENABLED(CONFIG_NFS_V4)
2035 static int nfs_validate_mount_data(struct file_system_type
*fs_type
,
2037 struct nfs_parsed_mount_data
*args
,
2038 struct nfs_fh
*mntfh
,
2039 const char *dev_name
)
2041 if (fs_type
== &nfs_fs_type
)
2042 return nfs23_validate_mount_data(options
, args
, mntfh
, dev_name
);
2043 return nfs4_validate_mount_data(options
, args
, dev_name
);
2046 static int nfs_validate_mount_data(struct file_system_type
*fs_type
,
2048 struct nfs_parsed_mount_data
*args
,
2049 struct nfs_fh
*mntfh
,
2050 const char *dev_name
)
2052 return nfs23_validate_mount_data(options
, args
, mntfh
, dev_name
);
2056 static int nfs_validate_text_mount_data(void *options
,
2057 struct nfs_parsed_mount_data
*args
,
2058 const char *dev_name
)
2061 int max_namelen
= PAGE_SIZE
;
2062 int max_pathlen
= NFS_MAXPATHLEN
;
2063 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2065 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2068 if (!nfs_verify_server_address(sap
))
2069 goto out_no_address
;
2071 if (args
->version
== 4) {
2072 #if IS_ENABLED(CONFIG_NFS_V4)
2074 max_namelen
= NFS4_MAXNAMLEN
;
2075 max_pathlen
= NFS4_MAXPATHLEN
;
2076 nfs_validate_transport_protocol(args
);
2077 nfs4_validate_mount_flags(args
);
2079 goto out_v4_not_compiled
;
2080 #endif /* CONFIG_NFS_V4 */
2082 nfs_set_mount_transport_protocol(args
);
2084 nfs_set_port(sap
, &args
->nfs_server
.port
, port
);
2086 if (args
->auth_flavor_len
> 1)
2089 return nfs_parse_devname(dev_name
,
2090 &args
->nfs_server
.hostname
,
2092 &args
->nfs_server
.export_path
,
2095 #if !IS_ENABLED(CONFIG_NFS_V4)
2096 out_v4_not_compiled
:
2097 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
2098 return -EPROTONOSUPPORT
;
2099 #endif /* !CONFIG_NFS_V4 */
2102 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
2106 dfprintk(MOUNT
, "NFS: Too many RPC auth flavours specified\n");
2111 nfs_compare_remount_data(struct nfs_server
*nfss
,
2112 struct nfs_parsed_mount_data
*data
)
2114 if (data
->flags
!= nfss
->flags
||
2115 data
->rsize
!= nfss
->rsize
||
2116 data
->wsize
!= nfss
->wsize
||
2117 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
2118 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
2119 data
->acregmin
!= nfss
->acregmin
/ HZ
||
2120 data
->acregmax
!= nfss
->acregmax
/ HZ
||
2121 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
2122 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
2123 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
2124 data
->nfs_server
.port
!= nfss
->port
||
2125 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
2126 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
2127 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
2134 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
2137 struct nfs_server
*nfss
= sb
->s_fs_info
;
2138 struct nfs_parsed_mount_data
*data
;
2139 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
2140 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
2141 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
2144 * Userspace mount programs that send binary options generally send
2145 * them populated with default values. We have no way to know which
2146 * ones were explicitly specified. Fall back to legacy behavior and
2147 * just return success.
2149 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
2150 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
2151 options
->version
<= 6))))
2154 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2158 /* fill out struct with values from existing mount */
2159 data
->flags
= nfss
->flags
;
2160 data
->rsize
= nfss
->rsize
;
2161 data
->wsize
= nfss
->wsize
;
2162 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
2163 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
2164 data
->acregmin
= nfss
->acregmin
/ HZ
;
2165 data
->acregmax
= nfss
->acregmax
/ HZ
;
2166 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
2167 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
2168 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
2169 data
->nfs_server
.port
= nfss
->port
;
2170 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
2171 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
2172 data
->nfs_server
.addrlen
);
2174 /* overwrite those values with any that were specified */
2175 error
= nfs_parse_mount_options((char *)options
, data
);
2180 * noac is a special case. It implies -o sync, but that's not
2181 * necessarily reflected in the mtab options. do_remount_sb
2182 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2183 * remount options, so we have to explicitly reset it.
2185 if (data
->flags
& NFS_MOUNT_NOAC
)
2186 *flags
|= MS_SYNCHRONOUS
;
2188 /* compare new mount options with old ones */
2189 error
= nfs_compare_remount_data(nfss
, data
);
2194 EXPORT_SYMBOL_GPL(nfs_remount
);
2197 * Initialise the common bits of the superblock
2199 inline void nfs_initialise_sb(struct super_block
*sb
)
2201 struct nfs_server
*server
= NFS_SB(sb
);
2203 sb
->s_magic
= NFS_SUPER_MAGIC
;
2205 /* We probably want something more informative here */
2206 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
2207 "%u:%u", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
2209 if (sb
->s_blocksize
== 0)
2210 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
2211 &sb
->s_blocksize_bits
);
2213 sb
->s_bdi
= &server
->backing_dev_info
;
2215 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2219 * Finish setting up an NFS2/3 superblock
2221 void nfs_fill_super(struct super_block
*sb
, struct nfs_mount_info
*mount_info
)
2223 struct nfs_parsed_mount_data
*data
= mount_info
->parsed
;
2224 struct nfs_server
*server
= NFS_SB(sb
);
2226 sb
->s_blocksize_bits
= 0;
2227 sb
->s_blocksize
= 0;
2228 sb
->s_xattr
= server
->nfs_client
->cl_nfs_mod
->xattr
;
2229 sb
->s_op
= server
->nfs_client
->cl_nfs_mod
->sops
;
2230 if (data
&& data
->bsize
)
2231 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2233 if (server
->nfs_client
->rpc_ops
->version
!= 2) {
2234 /* The VFS shouldn't apply the umask to mode bits. We will do
2235 * so ourselves when necessary.
2237 sb
->s_flags
|= MS_POSIXACL
;
2238 sb
->s_time_gran
= 1;
2241 nfs_initialise_sb(sb
);
2243 EXPORT_SYMBOL_GPL(nfs_fill_super
);
2246 * Finish setting up a cloned NFS2/3/4 superblock
2248 void nfs_clone_super(struct super_block
*sb
, struct nfs_mount_info
*mount_info
)
2250 const struct super_block
*old_sb
= mount_info
->cloned
->sb
;
2251 struct nfs_server
*server
= NFS_SB(sb
);
2253 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2254 sb
->s_blocksize
= old_sb
->s_blocksize
;
2255 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2256 sb
->s_xattr
= old_sb
->s_xattr
;
2257 sb
->s_op
= old_sb
->s_op
;
2258 sb
->s_time_gran
= 1;
2260 if (server
->nfs_client
->rpc_ops
->version
!= 2) {
2261 /* The VFS shouldn't apply the umask to mode bits. We will do
2262 * so ourselves when necessary.
2264 sb
->s_flags
|= MS_POSIXACL
;
2267 nfs_initialise_sb(sb
);
2270 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2272 const struct nfs_server
*a
= s
->s_fs_info
;
2273 const struct rpc_clnt
*clnt_a
= a
->client
;
2274 const struct rpc_clnt
*clnt_b
= b
->client
;
2276 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2278 if (a
->nfs_client
!= b
->nfs_client
)
2280 if (a
->flags
!= b
->flags
)
2282 if (a
->wsize
!= b
->wsize
)
2284 if (a
->rsize
!= b
->rsize
)
2286 if (a
->acregmin
!= b
->acregmin
)
2288 if (a
->acregmax
!= b
->acregmax
)
2290 if (a
->acdirmin
!= b
->acdirmin
)
2292 if (a
->acdirmax
!= b
->acdirmax
)
2294 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2301 struct nfs_sb_mountdata
{
2302 struct nfs_server
*server
;
2306 static int nfs_set_super(struct super_block
*s
, void *data
)
2308 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2309 struct nfs_server
*server
= sb_mntdata
->server
;
2312 s
->s_flags
= sb_mntdata
->mntflags
;
2313 s
->s_fs_info
= server
;
2314 s
->s_d_op
= server
->nfs_client
->rpc_ops
->dentry_ops
;
2315 ret
= set_anon_super(s
, server
);
2317 server
->s_dev
= s
->s_dev
;
2321 static int nfs_compare_super_address(struct nfs_server
*server1
,
2322 struct nfs_server
*server2
)
2324 struct sockaddr
*sap1
, *sap2
;
2326 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2327 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2329 if (sap1
->sa_family
!= sap2
->sa_family
)
2332 switch (sap1
->sa_family
) {
2334 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2335 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2336 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2338 if (sin1
->sin_port
!= sin2
->sin_port
)
2343 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2344 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2345 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2347 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2358 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2360 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2361 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2362 int mntflags
= sb_mntdata
->mntflags
;
2364 if (!nfs_compare_super_address(old
, server
))
2366 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2367 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2369 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2371 return nfs_compare_mount_options(sb
, server
, mntflags
);
2374 #ifdef CONFIG_NFS_FSCACHE
2375 static void nfs_get_cache_cookie(struct super_block
*sb
,
2376 struct nfs_parsed_mount_data
*parsed
,
2377 struct nfs_clone_mount
*cloned
)
2379 struct nfs_server
*nfss
= NFS_SB(sb
);
2383 nfss
->fscache_key
= NULL
;
2384 nfss
->fscache
= NULL
;
2387 if (!(parsed
->options
& NFS_OPTION_FSCACHE
))
2389 if (parsed
->fscache_uniq
) {
2390 uniq
= parsed
->fscache_uniq
;
2391 ulen
= strlen(parsed
->fscache_uniq
);
2393 } else if (cloned
) {
2394 struct nfs_server
*mnt_s
= NFS_SB(cloned
->sb
);
2395 if (!(mnt_s
->options
& NFS_OPTION_FSCACHE
))
2397 if (mnt_s
->fscache_key
) {
2398 uniq
= mnt_s
->fscache_key
->key
.uniquifier
;
2399 ulen
= mnt_s
->fscache_key
->key
.uniq_len
;
2404 nfs_fscache_get_super_cookie(sb
, uniq
, ulen
);
2407 static void nfs_get_cache_cookie(struct super_block
*sb
,
2408 struct nfs_parsed_mount_data
*parsed
,
2409 struct nfs_clone_mount
*cloned
)
2414 static int nfs_bdi_register(struct nfs_server
*server
)
2416 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2419 int nfs_set_sb_security(struct super_block
*s
, struct dentry
*mntroot
,
2420 struct nfs_mount_info
*mount_info
)
2422 return security_sb_set_mnt_opts(s
, &mount_info
->parsed
->lsm_opts
);
2424 EXPORT_SYMBOL_GPL(nfs_set_sb_security
);
2426 int nfs_clone_sb_security(struct super_block
*s
, struct dentry
*mntroot
,
2427 struct nfs_mount_info
*mount_info
)
2429 /* clone any lsm security options from the parent to the new sb */
2430 security_sb_clone_mnt_opts(mount_info
->cloned
->sb
, s
);
2431 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
)
2435 EXPORT_SYMBOL_GPL(nfs_clone_sb_security
);
2437 struct dentry
*nfs_fs_mount_common(struct nfs_server
*server
,
2438 int flags
, const char *dev_name
,
2439 struct nfs_mount_info
*mount_info
,
2440 struct nfs_subversion
*nfs_mod
)
2442 struct super_block
*s
;
2443 struct dentry
*mntroot
= ERR_PTR(-ENOMEM
);
2444 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2445 struct nfs_sb_mountdata sb_mntdata
= {
2451 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2452 compare_super
= NULL
;
2454 /* -o noac implies -o sync */
2455 if (server
->flags
& NFS_MOUNT_NOAC
)
2456 sb_mntdata
.mntflags
|= MS_SYNCHRONOUS
;
2458 /* Get a superblock - note that we may end up sharing one that already exists */
2459 s
= sget(nfs_mod
->nfs_fs
, compare_super
, nfs_set_super
, flags
, &sb_mntdata
);
2461 mntroot
= ERR_CAST(s
);
2465 if (s
->s_fs_info
!= server
) {
2466 nfs_free_server(server
);
2469 error
= nfs_bdi_register(server
);
2471 mntroot
= ERR_PTR(error
);
2472 goto error_splat_bdi
;
2477 /* initial superblock/root creation */
2478 mount_info
->fill_super(s
, mount_info
);
2479 nfs_get_cache_cookie(s
, mount_info
->parsed
, mount_info
->cloned
);
2482 mntroot
= nfs_get_root(s
, mount_info
->mntfh
, dev_name
);
2483 if (IS_ERR(mntroot
))
2484 goto error_splat_super
;
2486 error
= mount_info
->set_security(s
, mntroot
, mount_info
);
2488 goto error_splat_root
;
2490 s
->s_flags
|= MS_ACTIVE
;
2496 nfs_free_server(server
);
2501 mntroot
= ERR_PTR(error
);
2503 if (server
&& !s
->s_root
)
2504 bdi_unregister(&server
->backing_dev_info
);
2506 deactivate_locked_super(s
);
2509 EXPORT_SYMBOL_GPL(nfs_fs_mount_common
);
2511 struct dentry
*nfs_fs_mount(struct file_system_type
*fs_type
,
2512 int flags
, const char *dev_name
, void *raw_data
)
2514 struct nfs_mount_info mount_info
= {
2515 .fill_super
= nfs_fill_super
,
2516 .set_security
= nfs_set_sb_security
,
2518 struct dentry
*mntroot
= ERR_PTR(-ENOMEM
);
2519 struct nfs_subversion
*nfs_mod
;
2522 mount_info
.parsed
= nfs_alloc_parsed_mount_data();
2523 mount_info
.mntfh
= nfs_alloc_fhandle();
2524 if (mount_info
.parsed
== NULL
|| mount_info
.mntfh
== NULL
)
2527 /* Validate the mount data */
2528 error
= nfs_validate_mount_data(fs_type
, raw_data
, mount_info
.parsed
, mount_info
.mntfh
, dev_name
);
2529 if (error
== NFS_TEXT_DATA
)
2530 error
= nfs_validate_text_mount_data(raw_data
, mount_info
.parsed
, dev_name
);
2532 mntroot
= ERR_PTR(error
);
2536 nfs_mod
= get_nfs_version(mount_info
.parsed
->version
);
2537 if (IS_ERR(nfs_mod
)) {
2538 mntroot
= ERR_CAST(nfs_mod
);
2542 mntroot
= nfs_mod
->rpc_ops
->try_mount(flags
, dev_name
, &mount_info
, nfs_mod
);
2544 put_nfs_version(nfs_mod
);
2546 nfs_free_parsed_mount_data(mount_info
.parsed
);
2547 nfs_free_fhandle(mount_info
.mntfh
);
2550 EXPORT_SYMBOL_GPL(nfs_fs_mount
);
2553 * Ensure that we unregister the bdi before kill_anon_super
2554 * releases the device name
2556 void nfs_put_super(struct super_block
*s
)
2558 struct nfs_server
*server
= NFS_SB(s
);
2560 bdi_unregister(&server
->backing_dev_info
);
2562 EXPORT_SYMBOL_GPL(nfs_put_super
);
2565 * Destroy an NFS2/3 superblock
2567 void nfs_kill_super(struct super_block
*s
)
2569 struct nfs_server
*server
= NFS_SB(s
);
2572 nfs_fscache_release_super_cookie(s
);
2573 nfs_free_server(server
);
2575 EXPORT_SYMBOL_GPL(nfs_kill_super
);
2578 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2580 static struct dentry
*
2581 nfs_xdev_mount(struct file_system_type
*fs_type
, int flags
,
2582 const char *dev_name
, void *raw_data
)
2584 struct nfs_clone_mount
*data
= raw_data
;
2585 struct nfs_mount_info mount_info
= {
2586 .fill_super
= nfs_clone_super
,
2587 .set_security
= nfs_clone_sb_security
,
2590 struct nfs_server
*server
;
2591 struct dentry
*mntroot
= ERR_PTR(-ENOMEM
);
2592 struct nfs_subversion
*nfs_mod
= NFS_SB(data
->sb
)->nfs_client
->cl_nfs_mod
;
2595 dprintk("--> nfs_xdev_mount_common()\n");
2597 mount_info
.mntfh
= mount_info
.cloned
->fh
;
2599 /* create a new volume representation */
2600 server
= nfs_mod
->rpc_ops
->clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
, data
->authflavor
);
2601 if (IS_ERR(server
)) {
2602 error
= PTR_ERR(server
);
2606 mntroot
= nfs_fs_mount_common(server
, flags
, dev_name
, &mount_info
, nfs_mod
);
2607 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2612 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error
);
2616 #if IS_ENABLED(CONFIG_NFS_V4)
2618 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2620 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
|
2621 NFS_MOUNT_LOCAL_FLOCK
|NFS_MOUNT_LOCAL_FCNTL
);
2625 * Validate NFSv4 mount options
2627 static int nfs4_validate_mount_data(void *options
,
2628 struct nfs_parsed_mount_data
*args
,
2629 const char *dev_name
)
2631 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2632 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2640 switch (data
->version
) {
2642 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2643 goto out_no_address
;
2644 if (data
->host_addrlen
== 0)
2645 goto out_no_address
;
2646 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2647 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2649 if (!nfs_verify_server_address(sap
))
2650 goto out_no_address
;
2651 args
->nfs_server
.port
= ntohs(((struct sockaddr_in
*)sap
)->sin_port
);
2653 if (data
->auth_flavourlen
) {
2654 if (data
->auth_flavourlen
> 1)
2655 goto out_inval_auth
;
2656 if (copy_from_user(&args
->auth_flavors
[0],
2657 data
->auth_flavours
,
2658 sizeof(args
->auth_flavors
[0])))
2662 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2665 args
->nfs_server
.hostname
= c
;
2667 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2670 args
->nfs_server
.export_path
= c
;
2671 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2673 c
= strndup_user(data
->client_addr
.data
, 16);
2676 args
->client_address
= c
;
2679 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2683 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2684 args
->rsize
= data
->rsize
;
2685 args
->wsize
= data
->wsize
;
2686 args
->timeo
= data
->timeo
;
2687 args
->retrans
= data
->retrans
;
2688 args
->acregmin
= data
->acregmin
;
2689 args
->acregmax
= data
->acregmax
;
2690 args
->acdirmin
= data
->acdirmin
;
2691 args
->acdirmax
= data
->acdirmax
;
2692 args
->nfs_server
.protocol
= data
->proto
;
2693 nfs_validate_transport_protocol(args
);
2697 return NFS_TEXT_DATA
;
2703 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2707 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2708 data
->auth_flavourlen
);
2712 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2717 * NFS v4 module parameters need to stay in the
2718 * NFS client for backwards compatibility
2720 unsigned int nfs_callback_set_tcpport
;
2721 unsigned short nfs_callback_tcpport
;
2722 /* Default cache timeout is 10 minutes */
2723 unsigned int nfs_idmap_cache_timeout
= 600;
2724 /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2725 bool nfs4_disable_idmapping
= true;
2726 unsigned short max_session_slots
= NFS4_DEF_SLOT_TABLE_SIZE
;
2727 unsigned short send_implementation_id
= 1;
2728 char nfs4_client_id_uniquifier
[NFS4_CLIENT_ID_UNIQ_LEN
] = "";
2730 EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport
);
2731 EXPORT_SYMBOL_GPL(nfs_callback_tcpport
);
2732 EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout
);
2733 EXPORT_SYMBOL_GPL(nfs4_disable_idmapping
);
2734 EXPORT_SYMBOL_GPL(max_session_slots
);
2735 EXPORT_SYMBOL_GPL(send_implementation_id
);
2736 EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier
);
2738 #define NFS_CALLBACK_MAXPORTNR (65535U)
2740 static int param_set_portnr(const char *val
, const struct kernel_param
*kp
)
2747 ret
= kstrtoul(val
, 0, &num
);
2748 if (ret
== -EINVAL
|| num
> NFS_CALLBACK_MAXPORTNR
)
2750 *((unsigned int *)kp
->arg
) = num
;
2753 static struct kernel_param_ops param_ops_portnr
= {
2754 .set
= param_set_portnr
,
2755 .get
= param_get_uint
,
2757 #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2759 module_param_named(callback_tcpport
, nfs_callback_set_tcpport
, portnr
, 0644);
2760 module_param(nfs_idmap_cache_timeout
, int, 0644);
2761 module_param(nfs4_disable_idmapping
, bool, 0644);
2762 module_param_string(nfs4_unique_id
, nfs4_client_id_uniquifier
,
2763 NFS4_CLIENT_ID_UNIQ_LEN
, 0600);
2764 MODULE_PARM_DESC(nfs4_disable_idmapping
,
2765 "Turn off NFSv4 idmapping when using 'sec=sys'");
2766 module_param(max_session_slots
, ushort
, 0644);
2767 MODULE_PARM_DESC(max_session_slots
, "Maximum number of outstanding NFSv4.1 "
2768 "requests the client will negotiate");
2769 module_param(send_implementation_id
, ushort
, 0644);
2770 MODULE_PARM_DESC(send_implementation_id
,
2771 "Send implementation ID with NFSv4.1 exchange_id");
2772 MODULE_PARM_DESC(nfs4_unique_id
, "nfs_client_id4 uniquifier string");
2773 MODULE_ALIAS("nfs4");
2775 #endif /* CONFIG_NFS_V4 */