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/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/namei.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
49 #include <linux/slab.h>
51 #include <linux/netdevice.h>
52 #include <linux/nfs_xdr.h>
53 #include <linux/magic.h>
54 #include <linux/parser.h>
55 #include <linux/nsproxy.h>
56 #include <linux/rcupdate.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
69 #define NFSDBG_FACILITY NFSDBG_VFS
70 #define NFS_TEXT_DATA 1
72 #if IS_ENABLED(CONFIG_NFS_V3)
73 #define NFS_DEFAULT_VERSION 3
75 #define NFS_DEFAULT_VERSION 2
79 /* Mount options that take no arguments */
81 Opt_posix
, Opt_noposix
,
85 Opt_udp
, Opt_tcp
, Opt_rdma
,
87 Opt_rdirplus
, Opt_nordirplus
,
88 Opt_sharecache
, Opt_nosharecache
,
89 Opt_resvport
, Opt_noresvport
,
90 Opt_fscache
, Opt_nofscache
,
92 /* Mount options that take integer arguments */
94 Opt_rsize
, Opt_wsize
, Opt_bsize
,
95 Opt_timeo
, Opt_retrans
,
96 Opt_acregmin
, Opt_acregmax
,
97 Opt_acdirmin
, Opt_acdirmax
,
104 /* Mount options that take string arguments */
106 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
107 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
112 /* Special mount options */
113 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
118 static const match_table_t nfs_mount_option_tokens
= {
119 { Opt_userspace
, "bg" },
120 { Opt_userspace
, "fg" },
121 { Opt_userspace
, "retry=%s" },
123 { Opt_sloppy
, "sloppy" },
125 { Opt_soft
, "soft" },
126 { Opt_hard
, "hard" },
127 { Opt_deprecated
, "intr" },
128 { Opt_deprecated
, "nointr" },
129 { Opt_posix
, "posix" },
130 { Opt_noposix
, "noposix" },
132 { Opt_nocto
, "nocto" },
134 { Opt_noac
, "noac" },
135 { Opt_lock
, "lock" },
136 { Opt_nolock
, "nolock" },
139 { Opt_rdma
, "rdma" },
141 { Opt_noacl
, "noacl" },
142 { Opt_rdirplus
, "rdirplus" },
143 { Opt_nordirplus
, "nordirplus" },
144 { Opt_sharecache
, "sharecache" },
145 { Opt_nosharecache
, "nosharecache" },
146 { Opt_resvport
, "resvport" },
147 { Opt_noresvport
, "noresvport" },
148 { Opt_fscache
, "fsc" },
149 { Opt_nofscache
, "nofsc" },
151 { Opt_port
, "port=%s" },
152 { Opt_rsize
, "rsize=%s" },
153 { Opt_wsize
, "wsize=%s" },
154 { Opt_bsize
, "bsize=%s" },
155 { Opt_timeo
, "timeo=%s" },
156 { Opt_retrans
, "retrans=%s" },
157 { Opt_acregmin
, "acregmin=%s" },
158 { Opt_acregmax
, "acregmax=%s" },
159 { Opt_acdirmin
, "acdirmin=%s" },
160 { Opt_acdirmax
, "acdirmax=%s" },
161 { Opt_actimeo
, "actimeo=%s" },
162 { Opt_namelen
, "namlen=%s" },
163 { Opt_mountport
, "mountport=%s" },
164 { Opt_mountvers
, "mountvers=%s" },
165 { Opt_minorversion
, "minorversion=%s" },
167 { Opt_nfsvers
, "nfsvers=%s" },
168 { Opt_nfsvers
, "vers=%s" },
170 { Opt_sec
, "sec=%s" },
171 { Opt_proto
, "proto=%s" },
172 { Opt_mountproto
, "mountproto=%s" },
173 { Opt_addr
, "addr=%s" },
174 { Opt_clientaddr
, "clientaddr=%s" },
175 { Opt_mounthost
, "mounthost=%s" },
176 { Opt_mountaddr
, "mountaddr=%s" },
178 { Opt_lookupcache
, "lookupcache=%s" },
179 { Opt_fscache_uniq
, "fsc=%s" },
180 { Opt_local_lock
, "local_lock=%s" },
182 /* The following needs to be listed after all other options */
183 { Opt_nfsvers
, "v%s" },
189 Opt_xprt_udp
, Opt_xprt_udp6
, Opt_xprt_tcp
, Opt_xprt_tcp6
, Opt_xprt_rdma
,
194 static const match_table_t nfs_xprt_protocol_tokens
= {
195 { Opt_xprt_udp
, "udp" },
196 { Opt_xprt_udp6
, "udp6" },
197 { Opt_xprt_tcp
, "tcp" },
198 { Opt_xprt_tcp6
, "tcp6" },
199 { Opt_xprt_rdma
, "rdma" },
201 { Opt_xprt_err
, NULL
}
205 Opt_sec_none
, Opt_sec_sys
,
206 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
207 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
208 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
213 static const match_table_t nfs_secflavor_tokens
= {
214 { Opt_sec_none
, "none" },
215 { Opt_sec_none
, "null" },
216 { Opt_sec_sys
, "sys" },
218 { Opt_sec_krb5
, "krb5" },
219 { Opt_sec_krb5i
, "krb5i" },
220 { Opt_sec_krb5p
, "krb5p" },
222 { Opt_sec_lkey
, "lkey" },
223 { Opt_sec_lkeyi
, "lkeyi" },
224 { Opt_sec_lkeyp
, "lkeyp" },
226 { Opt_sec_spkm
, "spkm3" },
227 { Opt_sec_spkmi
, "spkm3i" },
228 { Opt_sec_spkmp
, "spkm3p" },
230 { Opt_sec_err
, NULL
}
234 Opt_lookupcache_all
, Opt_lookupcache_positive
,
235 Opt_lookupcache_none
,
240 static match_table_t nfs_lookupcache_tokens
= {
241 { Opt_lookupcache_all
, "all" },
242 { Opt_lookupcache_positive
, "pos" },
243 { Opt_lookupcache_positive
, "positive" },
244 { Opt_lookupcache_none
, "none" },
246 { Opt_lookupcache_err
, NULL
}
250 Opt_local_lock_all
, Opt_local_lock_flock
, Opt_local_lock_posix
,
256 static match_table_t nfs_local_lock_tokens
= {
257 { Opt_local_lock_all
, "all" },
258 { Opt_local_lock_flock
, "flock" },
259 { Opt_local_lock_posix
, "posix" },
260 { Opt_local_lock_none
, "none" },
262 { Opt_local_lock_err
, NULL
}
266 Opt_vers_2
, Opt_vers_3
, Opt_vers_4
, Opt_vers_4_0
,
272 static match_table_t nfs_vers_tokens
= {
276 { Opt_vers_4_0
, "4.0" },
277 { Opt_vers_4_1
, "4.1" },
279 { Opt_vers_err
, NULL
}
282 static struct dentry
*nfs_xdev_mount(struct file_system_type
*fs_type
,
283 int flags
, const char *dev_name
, void *raw_data
);
285 struct file_system_type nfs_fs_type
= {
286 .owner
= THIS_MODULE
,
288 .mount
= nfs_fs_mount
,
289 .kill_sb
= nfs_kill_super
,
290 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
292 EXPORT_SYMBOL_GPL(nfs_fs_type
);
294 struct file_system_type nfs_xdev_fs_type
= {
295 .owner
= THIS_MODULE
,
297 .mount
= nfs_xdev_mount
,
298 .kill_sb
= nfs_kill_super
,
299 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
302 const struct super_operations nfs_sops
= {
303 .alloc_inode
= nfs_alloc_inode
,
304 .destroy_inode
= nfs_destroy_inode
,
305 .write_inode
= nfs_write_inode
,
306 .put_super
= nfs_put_super
,
307 .statfs
= nfs_statfs
,
308 .evict_inode
= nfs_evict_inode
,
309 .umount_begin
= nfs_umount_begin
,
310 .show_options
= nfs_show_options
,
311 .show_devname
= nfs_show_devname
,
312 .show_path
= nfs_show_path
,
313 .show_stats
= nfs_show_stats
,
314 .remount_fs
= nfs_remount
,
316 EXPORT_SYMBOL_GPL(nfs_sops
);
318 #if IS_ENABLED(CONFIG_NFS_V4)
319 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*);
320 static int nfs4_validate_mount_data(void *options
,
321 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
324 static struct shrinker acl_shrinker
= {
325 .shrink
= nfs_access_cache_shrinker
,
326 .seeks
= DEFAULT_SEEKS
,
330 * Register the NFS filesystems
332 int __init
register_nfs_fs(void)
336 ret
= register_filesystem(&nfs_fs_type
);
340 ret
= nfs_register_sysctl();
343 register_shrinker(&acl_shrinker
);
347 unregister_filesystem(&nfs_fs_type
);
353 * Unregister the NFS filesystems
355 void __exit
unregister_nfs_fs(void)
357 unregister_shrinker(&acl_shrinker
);
358 nfs_unregister_sysctl();
359 unregister_filesystem(&nfs_fs_type
);
362 void nfs_sb_active(struct super_block
*sb
)
364 struct nfs_server
*server
= NFS_SB(sb
);
366 if (atomic_inc_return(&server
->active
) == 1)
367 atomic_inc(&sb
->s_active
);
369 EXPORT_SYMBOL_GPL(nfs_sb_active
);
371 void nfs_sb_deactive(struct super_block
*sb
)
373 struct nfs_server
*server
= NFS_SB(sb
);
375 if (atomic_dec_and_test(&server
->active
))
376 deactivate_super(sb
);
378 EXPORT_SYMBOL_GPL(nfs_sb_deactive
);
381 * Deliver file system statistics to userspace
383 int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
385 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
386 unsigned char blockbits
;
387 unsigned long blockres
;
388 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
389 struct nfs_fsstat res
;
392 res
.fattr
= nfs_alloc_fattr();
393 if (res
.fattr
== NULL
)
396 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
397 if (unlikely(error
== -ESTALE
)) {
398 struct dentry
*pd_dentry
;
400 pd_dentry
= dget_parent(dentry
);
401 if (pd_dentry
!= NULL
) {
402 nfs_zap_caches(pd_dentry
->d_inode
);
406 nfs_free_fattr(res
.fattr
);
410 buf
->f_type
= NFS_SUPER_MAGIC
;
413 * Current versions of glibc do not correctly handle the
414 * case where f_frsize != f_bsize. Eventually we want to
415 * report the value of wtmult in this field.
417 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
420 * On most *nix systems, f_blocks, f_bfree, and f_bavail
421 * are reported in units of f_frsize. Linux hasn't had
422 * an f_frsize field in its statfs struct until recently,
423 * thus historically Linux's sys_statfs reports these
424 * fields in units of f_bsize.
426 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
427 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
428 blockres
= (1 << blockbits
) - 1;
429 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
430 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
431 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
433 buf
->f_files
= res
.tfiles
;
434 buf
->f_ffree
= res
.afiles
;
436 buf
->f_namelen
= server
->namelen
;
441 dprintk("%s: statfs error = %d\n", __func__
, -error
);
444 EXPORT_SYMBOL_GPL(nfs_statfs
);
447 * Map the security flavour number to a name
449 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
451 static const struct {
452 rpc_authflavor_t flavour
;
455 { RPC_AUTH_NULL
, "null" },
456 { RPC_AUTH_UNIX
, "sys" },
457 { RPC_AUTH_GSS_KRB5
, "krb5" },
458 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
459 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
460 { RPC_AUTH_GSS_LKEY
, "lkey" },
461 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
462 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
463 { RPC_AUTH_GSS_SPKM
, "spkm" },
464 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
465 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
466 { UINT_MAX
, "unknown" }
470 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
471 if (sec_flavours
[i
].flavour
== flavour
)
474 return sec_flavours
[i
].str
;
477 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
480 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
482 seq_printf(m
, ",mountproto=");
483 switch (sap
->sa_family
) {
485 switch (nfss
->mountd_protocol
) {
487 seq_printf(m
, RPCBIND_NETID_UDP
);
490 seq_printf(m
, RPCBIND_NETID_TCP
);
494 seq_printf(m
, "auto");
498 switch (nfss
->mountd_protocol
) {
500 seq_printf(m
, RPCBIND_NETID_UDP6
);
503 seq_printf(m
, RPCBIND_NETID_TCP6
);
507 seq_printf(m
, "auto");
512 seq_printf(m
, "auto");
516 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
519 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
521 if (nfss
->flags
& NFS_MOUNT_LEGACY_INTERFACE
)
524 switch (sap
->sa_family
) {
526 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
527 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
531 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
532 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
537 seq_printf(m
, ",mountaddr=unspecified");
540 if (nfss
->mountd_version
|| showdefaults
)
541 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
542 if ((nfss
->mountd_port
&&
543 nfss
->mountd_port
!= (unsigned short)NFS_UNSPEC_PORT
) ||
545 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
547 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
550 #if IS_ENABLED(CONFIG_NFS_V4)
551 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
554 struct nfs_client
*clp
= nfss
->nfs_client
;
556 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
559 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
565 static void nfs_show_nfs_version(struct seq_file
*m
,
566 unsigned int version
,
567 unsigned int minorversion
)
569 seq_printf(m
, ",vers=%u", version
);
571 seq_printf(m
, ".%u", minorversion
);
575 * Describe the mount options in force on this server representation
577 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
580 static const struct proc_nfs_info
{
585 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
586 { NFS_MOUNT_POSIX
, ",posix", "" },
587 { NFS_MOUNT_NOCTO
, ",nocto", "" },
588 { NFS_MOUNT_NOAC
, ",noac", "" },
589 { NFS_MOUNT_NONLM
, ",nolock", "" },
590 { NFS_MOUNT_NOACL
, ",noacl", "" },
591 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
592 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
593 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
596 const struct proc_nfs_info
*nfs_infop
;
597 struct nfs_client
*clp
= nfss
->nfs_client
;
598 u32 version
= clp
->rpc_ops
->version
;
599 int local_flock
, local_fcntl
;
601 nfs_show_nfs_version(m
, version
, clp
->cl_minorversion
);
602 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
603 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
604 if (nfss
->bsize
!= 0)
605 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
606 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
607 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
608 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
609 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
610 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
611 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
612 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
613 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
614 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
615 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
616 if (nfss
->flags
& nfs_infop
->flag
)
617 seq_puts(m
, nfs_infop
->str
);
619 seq_puts(m
, nfs_infop
->nostr
);
622 seq_printf(m
, ",proto=%s",
623 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
626 if (nfss
->port
!= NFS_PORT
)
627 seq_printf(m
, ",port=%u", nfss
->port
);
630 seq_printf(m
, ",port=%u", nfss
->port
);
632 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
633 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
634 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
637 nfs_show_mountd_options(m
, nfss
, showdefaults
);
639 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
641 if (nfss
->options
& NFS_OPTION_FSCACHE
)
642 seq_printf(m
, ",fsc");
644 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONEG
) {
645 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONE
)
646 seq_printf(m
, ",lookupcache=none");
648 seq_printf(m
, ",lookupcache=pos");
651 local_flock
= nfss
->flags
& NFS_MOUNT_LOCAL_FLOCK
;
652 local_fcntl
= nfss
->flags
& NFS_MOUNT_LOCAL_FCNTL
;
654 if (!local_flock
&& !local_fcntl
)
655 seq_printf(m
, ",local_lock=none");
656 else if (local_flock
&& local_fcntl
)
657 seq_printf(m
, ",local_lock=all");
658 else if (local_flock
)
659 seq_printf(m
, ",local_lock=flock");
661 seq_printf(m
, ",local_lock=posix");
665 * Describe the mount options on this VFS mountpoint
667 int nfs_show_options(struct seq_file
*m
, struct dentry
*root
)
669 struct nfs_server
*nfss
= NFS_SB(root
->d_sb
);
671 nfs_show_mount_options(m
, nfss
, 0);
674 seq_printf(m
, ",addr=%s",
675 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
681 EXPORT_SYMBOL_GPL(nfs_show_options
);
683 #if IS_ENABLED(CONFIG_NFS_V4)
684 #ifdef CONFIG_NFS_V4_1
685 static void show_sessions(struct seq_file
*m
, struct nfs_server
*server
)
687 if (nfs4_has_session(server
->nfs_client
))
688 seq_printf(m
, ",sessions");
691 static void show_sessions(struct seq_file
*m
, struct nfs_server
*server
) {}
695 #ifdef CONFIG_NFS_V4_1
696 static void show_pnfs(struct seq_file
*m
, struct nfs_server
*server
)
698 seq_printf(m
, ",pnfs=");
699 if (server
->pnfs_curr_ld
)
700 seq_printf(m
, "%s", server
->pnfs_curr_ld
->name
);
702 seq_printf(m
, "not configured");
705 static void show_implementation_id(struct seq_file
*m
, struct nfs_server
*nfss
)
707 if (nfss
->nfs_client
&& nfss
->nfs_client
->cl_implid
) {
708 struct nfs41_impl_id
*impl_id
= nfss
->nfs_client
->cl_implid
;
709 seq_printf(m
, "\n\timpl_id:\tname='%s',domain='%s',"
711 impl_id
->name
, impl_id
->domain
,
712 impl_id
->date
.seconds
, impl_id
->date
.nseconds
);
716 #if IS_ENABLED(CONFIG_NFS_V4)
717 static void show_pnfs(struct seq_file
*m
, struct nfs_server
*server
)
721 static void show_implementation_id(struct seq_file
*m
, struct nfs_server
*nfss
)
726 int nfs_show_devname(struct seq_file
*m
, struct dentry
*root
)
728 char *page
= (char *) __get_free_page(GFP_KERNEL
);
729 char *devname
, *dummy
;
733 devname
= nfs_path(&dummy
, root
, page
, PAGE_SIZE
);
735 err
= PTR_ERR(devname
);
737 seq_escape(m
, devname
, " \t\n\\");
738 free_page((unsigned long)page
);
741 EXPORT_SYMBOL_GPL(nfs_show_devname
);
743 int nfs_show_path(struct seq_file
*m
, struct dentry
*dentry
)
748 EXPORT_SYMBOL_GPL(nfs_show_path
);
751 * Present statistical information for this VFS mountpoint
753 int nfs_show_stats(struct seq_file
*m
, struct dentry
*root
)
756 struct nfs_server
*nfss
= NFS_SB(root
->d_sb
);
757 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
758 struct nfs_iostats totals
= { };
760 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
763 * Display all mount option settings
765 seq_printf(m
, "\n\topts:\t");
766 seq_puts(m
, root
->d_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
767 seq_puts(m
, root
->d_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
768 seq_puts(m
, root
->d_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
769 seq_puts(m
, root
->d_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
770 nfs_show_mount_options(m
, nfss
, 1);
772 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
774 show_implementation_id(m
, nfss
);
776 seq_printf(m
, "\n\tcaps:\t");
777 seq_printf(m
, "caps=0x%x", nfss
->caps
);
778 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
779 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
780 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
781 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
783 #if IS_ENABLED(CONFIG_NFS_V4)
784 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
785 seq_printf(m
, "\n\tnfsv4:\t");
786 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
787 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
788 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
789 show_sessions(m
, nfss
);
795 * Display security flavor in effect for this mount
797 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
799 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
802 * Display superblock I/O counters
804 for_each_possible_cpu(cpu
) {
805 struct nfs_iostats
*stats
;
808 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
810 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
811 totals
.events
[i
] += stats
->events
[i
];
812 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
813 totals
.bytes
[i
] += stats
->bytes
[i
];
814 #ifdef CONFIG_NFS_FSCACHE
815 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
816 totals
.fscache
[i
] += stats
->fscache
[i
];
822 seq_printf(m
, "\n\tevents:\t");
823 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
824 seq_printf(m
, "%lu ", totals
.events
[i
]);
825 seq_printf(m
, "\n\tbytes:\t");
826 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
827 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
828 #ifdef CONFIG_NFS_FSCACHE
829 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
830 seq_printf(m
, "\n\tfsc:\t");
831 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
832 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
837 rpc_print_iostats(m
, nfss
->client
);
841 EXPORT_SYMBOL_GPL(nfs_show_stats
);
844 * Begin unmount by attempting to remove all automounted mountpoints we added
845 * in response to xdev traversals and referrals
847 void nfs_umount_begin(struct super_block
*sb
)
849 struct nfs_server
*server
;
850 struct rpc_clnt
*rpc
;
853 /* -EIO all pending I/O */
854 rpc
= server
->client_acl
;
856 rpc_killall_tasks(rpc
);
857 rpc
= server
->client
;
859 rpc_killall_tasks(rpc
);
861 EXPORT_SYMBOL_GPL(nfs_umount_begin
);
863 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(void)
865 struct nfs_parsed_mount_data
*data
;
867 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
869 data
->acregmin
= NFS_DEF_ACREGMIN
;
870 data
->acregmax
= NFS_DEF_ACREGMAX
;
871 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
872 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
873 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
874 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
875 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
876 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
877 data
->auth_flavor_len
= 1;
878 data
->minorversion
= 0;
879 data
->need_mount
= true;
880 data
->net
= current
->nsproxy
->net_ns
;
881 security_init_mnt_opts(&data
->lsm_opts
);
886 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data
*data
)
889 kfree(data
->client_address
);
890 kfree(data
->mount_server
.hostname
);
891 kfree(data
->nfs_server
.export_path
);
892 kfree(data
->nfs_server
.hostname
);
893 kfree(data
->fscache_uniq
);
894 security_free_mnt_opts(&data
->lsm_opts
);
900 * Sanity-check a server address provided by the mount command.
902 * Address family must be initialized, and address must not be
903 * the ANY address for that family.
905 static int nfs_verify_server_address(struct sockaddr
*addr
)
907 switch (addr
->sa_family
) {
909 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
910 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
913 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
914 return !ipv6_addr_any(sa
);
918 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
923 * Select between a default port value and a user-specified port value.
924 * If a zero value is set, then autobind will be used.
926 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
927 const unsigned short default_port
)
929 if (*port
== NFS_UNSPEC_PORT
)
930 *port
= default_port
;
932 rpc_set_port(sap
, *port
);
936 * Sanity check the NFS transport protocol.
939 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
941 switch (mnt
->nfs_server
.protocol
) {
942 case XPRT_TRANSPORT_UDP
:
943 case XPRT_TRANSPORT_TCP
:
944 case XPRT_TRANSPORT_RDMA
:
947 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
952 * For text based NFSv2/v3 mounts, the mount protocol transport default
953 * settings should depend upon the specified NFS transport.
955 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
957 nfs_validate_transport_protocol(mnt
);
959 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
960 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
962 switch (mnt
->nfs_server
.protocol
) {
963 case XPRT_TRANSPORT_UDP
:
964 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
966 case XPRT_TRANSPORT_TCP
:
967 case XPRT_TRANSPORT_RDMA
:
968 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
973 * Parse the value of the 'sec=' option.
975 static int nfs_parse_security_flavors(char *value
,
976 struct nfs_parsed_mount_data
*mnt
)
978 substring_t args
[MAX_OPT_ARGS
];
980 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
982 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
984 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
987 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
990 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
993 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
996 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
999 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
1002 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
1005 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
1008 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
1011 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
1014 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
1020 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
1021 mnt
->auth_flavor_len
= 1;
1025 static int nfs_parse_version_string(char *string
,
1026 struct nfs_parsed_mount_data
*mnt
,
1029 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1030 switch (match_token(string
, nfs_vers_tokens
, args
)) {
1035 mnt
->flags
|= NFS_MOUNT_VER3
;
1039 /* Backward compatibility option. In future,
1040 * the mount program should always supply
1041 * a NFSv4 minor version number.
1047 mnt
->minorversion
= 0;
1051 mnt
->minorversion
= 1;
1059 static int nfs_get_option_str(substring_t args
[], char **option
)
1062 *option
= match_strdup(args
);
1066 static int nfs_get_option_ul(substring_t args
[], unsigned long *option
)
1071 string
= match_strdup(args
);
1074 rc
= strict_strtoul(string
, 10, option
);
1081 * Error-check and convert a string of mount options from user space into
1082 * a data structure. The whole mount string is processed; bad options are
1083 * skipped as they are encountered. If there were no errors, return 1;
1084 * otherwise return 0 (zero).
1086 static int nfs_parse_mount_options(char *raw
,
1087 struct nfs_parsed_mount_data
*mnt
)
1089 char *p
, *string
, *secdata
;
1090 int rc
, sloppy
= 0, invalid_option
= 0;
1091 unsigned short protofamily
= AF_UNSPEC
;
1092 unsigned short mountfamily
= AF_UNSPEC
;
1095 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
1098 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
1100 secdata
= alloc_secdata();
1104 rc
= security_sb_copy_data(raw
, secdata
);
1106 goto out_security_failure
;
1108 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
1110 goto out_security_failure
;
1112 free_secdata(secdata
);
1114 while ((p
= strsep(&raw
, ",")) != NULL
) {
1115 substring_t args
[MAX_OPT_ARGS
];
1116 unsigned long option
;
1122 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
1124 token
= match_token(p
, nfs_mount_option_tokens
, args
);
1128 * boolean options: foo/nofoo
1131 mnt
->flags
|= NFS_MOUNT_SOFT
;
1134 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
1137 mnt
->flags
|= NFS_MOUNT_POSIX
;
1140 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
1143 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1146 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1149 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1152 mnt
->flags
|= NFS_MOUNT_NOAC
;
1155 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1156 mnt
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1157 NFS_MOUNT_LOCAL_FCNTL
);
1160 mnt
->flags
|= NFS_MOUNT_NONLM
;
1161 mnt
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1162 NFS_MOUNT_LOCAL_FCNTL
);
1165 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1166 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1169 mnt
->flags
|= NFS_MOUNT_TCP
;
1170 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1173 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1174 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1175 xprt_load_transport(p
);
1178 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1181 mnt
->flags
|= NFS_MOUNT_NOACL
;
1184 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1186 case Opt_nordirplus
:
1187 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1189 case Opt_sharecache
:
1190 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1192 case Opt_nosharecache
:
1193 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1196 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1198 case Opt_noresvport
:
1199 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1202 mnt
->options
|= NFS_OPTION_FSCACHE
;
1203 kfree(mnt
->fscache_uniq
);
1204 mnt
->fscache_uniq
= NULL
;
1207 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1208 kfree(mnt
->fscache_uniq
);
1209 mnt
->fscache_uniq
= NULL
;
1213 * options that take numeric values
1216 if (nfs_get_option_ul(args
, &option
) ||
1218 goto out_invalid_value
;
1219 mnt
->nfs_server
.port
= option
;
1222 if (nfs_get_option_ul(args
, &option
))
1223 goto out_invalid_value
;
1224 mnt
->rsize
= option
;
1227 if (nfs_get_option_ul(args
, &option
))
1228 goto out_invalid_value
;
1229 mnt
->wsize
= option
;
1232 if (nfs_get_option_ul(args
, &option
))
1233 goto out_invalid_value
;
1234 mnt
->bsize
= option
;
1237 if (nfs_get_option_ul(args
, &option
) || option
== 0)
1238 goto out_invalid_value
;
1239 mnt
->timeo
= option
;
1242 if (nfs_get_option_ul(args
, &option
) || option
== 0)
1243 goto out_invalid_value
;
1244 mnt
->retrans
= option
;
1247 if (nfs_get_option_ul(args
, &option
))
1248 goto out_invalid_value
;
1249 mnt
->acregmin
= option
;
1252 if (nfs_get_option_ul(args
, &option
))
1253 goto out_invalid_value
;
1254 mnt
->acregmax
= option
;
1257 if (nfs_get_option_ul(args
, &option
))
1258 goto out_invalid_value
;
1259 mnt
->acdirmin
= option
;
1262 if (nfs_get_option_ul(args
, &option
))
1263 goto out_invalid_value
;
1264 mnt
->acdirmax
= option
;
1267 if (nfs_get_option_ul(args
, &option
))
1268 goto out_invalid_value
;
1269 mnt
->acregmin
= mnt
->acregmax
=
1270 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1273 if (nfs_get_option_ul(args
, &option
))
1274 goto out_invalid_value
;
1275 mnt
->namlen
= option
;
1278 if (nfs_get_option_ul(args
, &option
) ||
1280 goto out_invalid_value
;
1281 mnt
->mount_server
.port
= option
;
1284 if (nfs_get_option_ul(args
, &option
) ||
1285 option
< NFS_MNT_VERSION
||
1286 option
> NFS_MNT3_VERSION
)
1287 goto out_invalid_value
;
1288 mnt
->mount_server
.version
= option
;
1290 case Opt_minorversion
:
1291 if (nfs_get_option_ul(args
, &option
))
1292 goto out_invalid_value
;
1293 if (option
> NFS4_MAX_MINOR_VERSION
)
1294 goto out_invalid_value
;
1295 mnt
->minorversion
= option
;
1299 * options that take text values
1302 string
= match_strdup(args
);
1305 rc
= nfs_parse_version_string(string
, mnt
, args
);
1308 goto out_invalid_value
;
1311 string
= match_strdup(args
);
1314 rc
= nfs_parse_security_flavors(string
, mnt
);
1317 dfprintk(MOUNT
, "NFS: unrecognized "
1318 "security flavor\n");
1323 string
= match_strdup(args
);
1326 token
= match_token(string
,
1327 nfs_xprt_protocol_tokens
, args
);
1329 protofamily
= AF_INET
;
1332 protofamily
= AF_INET6
;
1334 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1335 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1338 protofamily
= AF_INET6
;
1340 mnt
->flags
|= NFS_MOUNT_TCP
;
1341 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1344 /* vector side protocols to TCP */
1345 mnt
->flags
|= NFS_MOUNT_TCP
;
1346 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1347 xprt_load_transport(string
);
1350 dfprintk(MOUNT
, "NFS: unrecognized "
1351 "transport protocol\n");
1357 case Opt_mountproto
:
1358 string
= match_strdup(args
);
1361 token
= match_token(string
,
1362 nfs_xprt_protocol_tokens
, args
);
1365 mountfamily
= AF_INET
;
1368 mountfamily
= AF_INET6
;
1370 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1373 mountfamily
= AF_INET6
;
1375 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1377 case Opt_xprt_rdma
: /* not used for side protocols */
1379 dfprintk(MOUNT
, "NFS: unrecognized "
1380 "transport protocol\n");
1385 string
= match_strdup(args
);
1388 mnt
->nfs_server
.addrlen
=
1389 rpc_pton(mnt
->net
, string
, strlen(string
),
1391 &mnt
->nfs_server
.address
,
1392 sizeof(mnt
->nfs_server
.address
));
1394 if (mnt
->nfs_server
.addrlen
== 0)
1395 goto out_invalid_address
;
1397 case Opt_clientaddr
:
1398 if (nfs_get_option_str(args
, &mnt
->client_address
))
1402 if (nfs_get_option_str(args
,
1403 &mnt
->mount_server
.hostname
))
1407 string
= match_strdup(args
);
1410 mnt
->mount_server
.addrlen
=
1411 rpc_pton(mnt
->net
, string
, strlen(string
),
1413 &mnt
->mount_server
.address
,
1414 sizeof(mnt
->mount_server
.address
));
1416 if (mnt
->mount_server
.addrlen
== 0)
1417 goto out_invalid_address
;
1419 case Opt_lookupcache
:
1420 string
= match_strdup(args
);
1423 token
= match_token(string
,
1424 nfs_lookupcache_tokens
, args
);
1427 case Opt_lookupcache_all
:
1428 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1430 case Opt_lookupcache_positive
:
1431 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1432 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1434 case Opt_lookupcache_none
:
1435 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1438 dfprintk(MOUNT
, "NFS: invalid "
1439 "lookupcache argument\n");
1443 case Opt_fscache_uniq
:
1444 if (nfs_get_option_str(args
, &mnt
->fscache_uniq
))
1446 mnt
->options
|= NFS_OPTION_FSCACHE
;
1448 case Opt_local_lock
:
1449 string
= match_strdup(args
);
1452 token
= match_token(string
, nfs_local_lock_tokens
,
1456 case Opt_local_lock_all
:
1457 mnt
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1458 NFS_MOUNT_LOCAL_FCNTL
);
1460 case Opt_local_lock_flock
:
1461 mnt
->flags
|= NFS_MOUNT_LOCAL_FLOCK
;
1463 case Opt_local_lock_posix
:
1464 mnt
->flags
|= NFS_MOUNT_LOCAL_FCNTL
;
1466 case Opt_local_lock_none
:
1467 mnt
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1468 NFS_MOUNT_LOCAL_FCNTL
);
1471 dfprintk(MOUNT
, "NFS: invalid "
1472 "local_lock argument\n");
1482 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1485 case Opt_deprecated
:
1486 dfprintk(MOUNT
, "NFS: ignoring mount option "
1492 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1497 if (!sloppy
&& invalid_option
)
1500 if (mnt
->minorversion
&& mnt
->version
!= 4)
1501 goto out_minorversion_mismatch
;
1504 * verify that any proto=/mountproto= options match the address
1505 * familiies in the addr=/mountaddr= options.
1507 if (protofamily
!= AF_UNSPEC
&&
1508 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1509 goto out_proto_mismatch
;
1511 if (mountfamily
!= AF_UNSPEC
) {
1512 if (mnt
->mount_server
.addrlen
) {
1513 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1514 goto out_mountproto_mismatch
;
1516 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1517 goto out_mountproto_mismatch
;
1523 out_mountproto_mismatch
:
1524 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1528 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1530 out_invalid_address
:
1531 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1534 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1536 out_minorversion_mismatch
:
1537 printk(KERN_INFO
"NFS: mount option vers=%u does not support "
1538 "minorversion=%u\n", mnt
->version
, mnt
->minorversion
);
1541 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1543 out_security_failure
:
1544 free_secdata(secdata
);
1545 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1550 * Match the requested auth flavors with the list returned by
1551 * the server. Returns zero and sets the mount's authentication
1552 * flavor on success; returns -EACCES if server does not support
1553 * the requested flavor.
1555 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1556 struct nfs_mount_request
*request
)
1558 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1561 * Certain releases of Linux's mountd return an empty
1562 * flavor list. To prevent behavioral regression with
1563 * these servers (ie. rejecting mounts that used to
1564 * succeed), revert to pre-2.6.32 behavior (no checking)
1565 * if the returned flavor list is empty.
1567 if (server_authlist_len
== 0)
1571 * We avoid sophisticated negotiating here, as there are
1572 * plenty of cases where we can get it wrong, providing
1573 * either too little or too much security.
1575 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1576 * flavor listed first. However, some servers list
1577 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1578 * preferred default, in args->auth_flavors[0] if user
1579 * didn't specify sec= mount option.
1581 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1582 for (j
= 0; j
< server_authlist_len
; j
++)
1583 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1584 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1585 request
->auth_flavs
[j
]);
1586 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1590 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1591 nfs_umount(request
);
1596 * Use the remote server's MOUNT service to request the NFS file handle
1597 * corresponding to the provided path.
1599 static int nfs_request_mount(struct nfs_parsed_mount_data
*args
,
1600 struct nfs_fh
*root_fh
)
1602 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1603 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1604 struct nfs_mount_request request
= {
1605 .sap
= (struct sockaddr
*)
1606 &args
->mount_server
.address
,
1607 .dirpath
= args
->nfs_server
.export_path
,
1608 .protocol
= args
->mount_server
.protocol
,
1610 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1611 .auth_flav_len
= &server_authlist_len
,
1612 .auth_flavs
= server_authlist
,
1617 if (args
->mount_server
.version
== 0) {
1618 switch (args
->version
) {
1620 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1623 args
->mount_server
.version
= NFS_MNT_VERSION
;
1626 request
.version
= args
->mount_server
.version
;
1628 if (args
->mount_server
.hostname
)
1629 request
.hostname
= args
->mount_server
.hostname
;
1631 request
.hostname
= args
->nfs_server
.hostname
;
1634 * Construct the mount server's address.
1636 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1637 memcpy(request
.sap
, &args
->nfs_server
.address
,
1638 args
->nfs_server
.addrlen
);
1639 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1641 request
.salen
= args
->mount_server
.addrlen
;
1642 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1645 * Now ask the mount server to map our export path
1648 status
= nfs_mount(&request
);
1650 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1651 request
.hostname
, status
);
1656 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1658 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1660 return nfs_walk_authlist(args
, &request
);
1663 struct dentry
*nfs_try_mount(int flags
, const char *dev_name
,
1664 struct nfs_mount_info
*mount_info
,
1665 struct nfs_subversion
*nfs_mod
)
1668 struct nfs_server
*server
;
1670 if (mount_info
->parsed
->need_mount
) {
1671 status
= nfs_request_mount(mount_info
->parsed
, mount_info
->mntfh
);
1673 return ERR_PTR(status
);
1676 /* Get a volume representation */
1677 server
= nfs_mod
->rpc_ops
->create_server(mount_info
, nfs_mod
);
1679 return ERR_CAST(server
);
1681 return nfs_fs_mount_common(server
, flags
, dev_name
, mount_info
, nfs_mod
);
1683 EXPORT_SYMBOL_GPL(nfs_try_mount
);
1686 * Split "dev_name" into "hostname:export_path".
1688 * The leftmost colon demarks the split between the server's hostname
1689 * and the export path. If the hostname starts with a left square
1690 * bracket, then it may contain colons.
1692 * Note: caller frees hostname and export path, even on error.
1694 static int nfs_parse_devname(const char *dev_name
,
1695 char **hostname
, size_t maxnamlen
,
1696 char **export_path
, size_t maxpathlen
)
1701 /* Is the host name protected with square brakcets? */
1702 if (*dev_name
== '[') {
1703 end
= strchr(++dev_name
, ']');
1704 if (end
== NULL
|| end
[1] != ':')
1705 goto out_bad_devname
;
1707 len
= end
- dev_name
;
1712 end
= strchr(dev_name
, ':');
1714 goto out_bad_devname
;
1715 len
= end
- dev_name
;
1717 /* kill possible hostname list: not supported */
1718 comma
= strchr(dev_name
, ',');
1719 if (comma
!= NULL
&& comma
< end
)
1723 if (len
> maxnamlen
)
1726 /* N.B. caller will free nfs_server.hostname in all cases */
1727 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1728 if (*hostname
== NULL
)
1730 len
= strlen(++end
);
1731 if (len
> maxpathlen
)
1733 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1737 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1741 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1745 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1749 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1750 return -ENAMETOOLONG
;
1753 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1754 return -ENAMETOOLONG
;
1758 * Validate the NFS2/NFS3 mount data
1759 * - fills in the mount root filehandle
1761 * For option strings, user space handles the following behaviors:
1763 * + DNS: mapping server host name to IP address ("addr=" option)
1765 * + failure mode: how to behave if a mount request can't be handled
1766 * immediately ("fg/bg" option)
1768 * + retry: how often to retry a mount request ("retry=" option)
1770 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1771 * mountproto=tcp after mountproto=udp, and so on
1773 static int nfs23_validate_mount_data(void *options
,
1774 struct nfs_parsed_mount_data
*args
,
1775 struct nfs_fh
*mntfh
,
1776 const char *dev_name
)
1778 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1779 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1784 args
->version
= NFS_DEFAULT_VERSION
;
1785 switch (data
->version
) {
1791 if (data
->flags
& NFS_MOUNT_VER3
)
1793 data
->root
.size
= NFS2_FHSIZE
;
1794 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1796 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1799 memset(data
->context
, 0, sizeof(data
->context
));
1801 if (data
->flags
& NFS_MOUNT_VER3
) {
1802 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1803 goto out_invalid_fh
;
1804 mntfh
->size
= data
->root
.size
;
1807 mntfh
->size
= NFS2_FHSIZE
;
1812 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1813 if (mntfh
->size
< sizeof(mntfh
->data
))
1814 memset(mntfh
->data
+ mntfh
->size
, 0,
1815 sizeof(mntfh
->data
) - mntfh
->size
);
1818 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1821 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1822 args
->flags
|= NFS_MOUNT_LEGACY_INTERFACE
;
1823 args
->rsize
= data
->rsize
;
1824 args
->wsize
= data
->wsize
;
1825 args
->timeo
= data
->timeo
;
1826 args
->retrans
= data
->retrans
;
1827 args
->acregmin
= data
->acregmin
;
1828 args
->acregmax
= data
->acregmax
;
1829 args
->acdirmin
= data
->acdirmin
;
1830 args
->acdirmax
= data
->acdirmax
;
1831 args
->need_mount
= false;
1833 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1834 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1835 if (!nfs_verify_server_address(sap
))
1836 goto out_no_address
;
1838 if (!(data
->flags
& NFS_MOUNT_TCP
))
1839 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1840 /* N.B. caller will free nfs_server.hostname in all cases */
1841 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1842 args
->namlen
= data
->namlen
;
1843 args
->bsize
= data
->bsize
;
1845 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1846 args
->auth_flavors
[0] = data
->pseudoflavor
;
1847 if (!args
->nfs_server
.hostname
)
1850 if (!(data
->flags
& NFS_MOUNT_NONLM
))
1851 args
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1852 NFS_MOUNT_LOCAL_FCNTL
);
1854 args
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1855 NFS_MOUNT_LOCAL_FCNTL
);
1857 * The legacy version 6 binary mount data from userspace has a
1858 * field used only to transport selinux information into the
1859 * the kernel. To continue to support that functionality we
1860 * have a touch of selinux knowledge here in the NFS code. The
1861 * userspace code converted context=blah to just blah so we are
1862 * converting back to the full string selinux understands.
1864 if (data
->context
[0]){
1865 #ifdef CONFIG_SECURITY_SELINUX
1867 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1870 strcpy(opts_str
, "context=");
1871 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1872 strcat(opts_str
, &data
->context
[0]);
1873 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1884 return NFS_TEXT_DATA
;
1887 #if !IS_ENABLED(CONFIG_NFS_V3)
1888 if (args
->version
== 3)
1889 goto out_v3_not_compiled
;
1890 #endif /* !CONFIG_NFS_V3 */
1895 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1899 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1904 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1907 #if !IS_ENABLED(CONFIG_NFS_V3)
1908 out_v3_not_compiled
:
1909 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1910 return -EPROTONOSUPPORT
;
1911 #endif /* !CONFIG_NFS_V3 */
1914 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1918 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1922 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1926 #if IS_ENABLED(CONFIG_NFS_V4)
1927 static int nfs_validate_mount_data(struct file_system_type
*fs_type
,
1929 struct nfs_parsed_mount_data
*args
,
1930 struct nfs_fh
*mntfh
,
1931 const char *dev_name
)
1933 if (fs_type
== &nfs_fs_type
)
1934 return nfs23_validate_mount_data(options
, args
, mntfh
, dev_name
);
1935 return nfs4_validate_mount_data(options
, args
, dev_name
);
1938 static int nfs_validate_mount_data(struct file_system_type
*fs_type
,
1940 struct nfs_parsed_mount_data
*args
,
1941 struct nfs_fh
*mntfh
,
1942 const char *dev_name
)
1944 return nfs23_validate_mount_data(options
, args
, mntfh
, dev_name
);
1948 static int nfs_validate_text_mount_data(void *options
,
1949 struct nfs_parsed_mount_data
*args
,
1950 const char *dev_name
)
1953 int max_namelen
= PAGE_SIZE
;
1954 int max_pathlen
= NFS_MAXPATHLEN
;
1955 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1957 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1960 if (!nfs_verify_server_address(sap
))
1961 goto out_no_address
;
1963 if (args
->version
== 4) {
1964 #if IS_ENABLED(CONFIG_NFS_V4)
1966 max_namelen
= NFS4_MAXNAMLEN
;
1967 max_pathlen
= NFS4_MAXPATHLEN
;
1968 nfs_validate_transport_protocol(args
);
1969 nfs4_validate_mount_flags(args
);
1971 goto out_v4_not_compiled
;
1972 #endif /* CONFIG_NFS_V4 */
1974 nfs_set_mount_transport_protocol(args
);
1976 nfs_set_port(sap
, &args
->nfs_server
.port
, port
);
1978 if (args
->auth_flavor_len
> 1)
1981 return nfs_parse_devname(dev_name
,
1982 &args
->nfs_server
.hostname
,
1984 &args
->nfs_server
.export_path
,
1987 #if !IS_ENABLED(CONFIG_NFS_V4)
1988 out_v4_not_compiled
:
1989 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1990 return -EPROTONOSUPPORT
;
1991 #endif /* !CONFIG_NFS_V4 */
1994 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1998 dfprintk(MOUNT
, "NFS: Too many RPC auth flavours specified\n");
2003 nfs_compare_remount_data(struct nfs_server
*nfss
,
2004 struct nfs_parsed_mount_data
*data
)
2006 if (data
->flags
!= nfss
->flags
||
2007 data
->rsize
!= nfss
->rsize
||
2008 data
->wsize
!= nfss
->wsize
||
2009 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
2010 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
2011 data
->acregmin
!= nfss
->acregmin
/ HZ
||
2012 data
->acregmax
!= nfss
->acregmax
/ HZ
||
2013 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
2014 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
2015 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
2016 data
->nfs_server
.port
!= nfss
->port
||
2017 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
2018 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
2019 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
2026 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
2029 struct nfs_server
*nfss
= sb
->s_fs_info
;
2030 struct nfs_parsed_mount_data
*data
;
2031 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
2032 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
2033 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
2036 * Userspace mount programs that send binary options generally send
2037 * them populated with default values. We have no way to know which
2038 * ones were explicitly specified. Fall back to legacy behavior and
2039 * just return success.
2041 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
2042 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
2043 options
->version
<= 6))))
2046 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2050 /* fill out struct with values from existing mount */
2051 data
->flags
= nfss
->flags
;
2052 data
->rsize
= nfss
->rsize
;
2053 data
->wsize
= nfss
->wsize
;
2054 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
2055 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
2056 data
->acregmin
= nfss
->acregmin
/ HZ
;
2057 data
->acregmax
= nfss
->acregmax
/ HZ
;
2058 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
2059 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
2060 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
2061 data
->nfs_server
.port
= nfss
->port
;
2062 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
2063 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
2064 data
->nfs_server
.addrlen
);
2066 /* overwrite those values with any that were specified */
2067 error
= nfs_parse_mount_options((char *)options
, data
);
2072 * noac is a special case. It implies -o sync, but that's not
2073 * necessarily reflected in the mtab options. do_remount_sb
2074 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2075 * remount options, so we have to explicitly reset it.
2077 if (data
->flags
& NFS_MOUNT_NOAC
)
2078 *flags
|= MS_SYNCHRONOUS
;
2080 /* compare new mount options with old ones */
2081 error
= nfs_compare_remount_data(nfss
, data
);
2086 EXPORT_SYMBOL_GPL(nfs_remount
);
2089 * Initialise the common bits of the superblock
2091 inline void nfs_initialise_sb(struct super_block
*sb
)
2093 struct nfs_server
*server
= NFS_SB(sb
);
2095 sb
->s_magic
= NFS_SUPER_MAGIC
;
2097 /* We probably want something more informative here */
2098 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
2099 "%u:%u", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
2101 if (sb
->s_blocksize
== 0)
2102 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
2103 &sb
->s_blocksize_bits
);
2105 sb
->s_bdi
= &server
->backing_dev_info
;
2107 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2111 * Finish setting up an NFS2/3 superblock
2113 void nfs_fill_super(struct super_block
*sb
, struct nfs_mount_info
*mount_info
)
2115 struct nfs_parsed_mount_data
*data
= mount_info
->parsed
;
2116 struct nfs_server
*server
= NFS_SB(sb
);
2118 sb
->s_blocksize_bits
= 0;
2119 sb
->s_blocksize
= 0;
2120 sb
->s_xattr
= server
->nfs_client
->cl_nfs_mod
->xattr
;
2121 sb
->s_op
= server
->nfs_client
->cl_nfs_mod
->sops
;
2122 if (data
&& data
->bsize
)
2123 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2125 if (server
->nfs_client
->rpc_ops
->version
!= 2) {
2126 /* The VFS shouldn't apply the umask to mode bits. We will do
2127 * so ourselves when necessary.
2129 sb
->s_flags
|= MS_POSIXACL
;
2130 sb
->s_time_gran
= 1;
2133 nfs_initialise_sb(sb
);
2135 EXPORT_SYMBOL_GPL(nfs_fill_super
);
2138 * Finish setting up a cloned NFS2/3/4 superblock
2140 void nfs_clone_super(struct super_block
*sb
, struct nfs_mount_info
*mount_info
)
2142 const struct super_block
*old_sb
= mount_info
->cloned
->sb
;
2143 struct nfs_server
*server
= NFS_SB(sb
);
2145 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2146 sb
->s_blocksize
= old_sb
->s_blocksize
;
2147 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2148 sb
->s_xattr
= old_sb
->s_xattr
;
2149 sb
->s_op
= old_sb
->s_op
;
2150 sb
->s_time_gran
= 1;
2152 if (server
->nfs_client
->rpc_ops
->version
!= 2) {
2153 /* The VFS shouldn't apply the umask to mode bits. We will do
2154 * so ourselves when necessary.
2156 sb
->s_flags
|= MS_POSIXACL
;
2159 nfs_initialise_sb(sb
);
2162 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2164 const struct nfs_server
*a
= s
->s_fs_info
;
2165 const struct rpc_clnt
*clnt_a
= a
->client
;
2166 const struct rpc_clnt
*clnt_b
= b
->client
;
2168 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2170 if (a
->nfs_client
!= b
->nfs_client
)
2172 if (a
->flags
!= b
->flags
)
2174 if (a
->wsize
!= b
->wsize
)
2176 if (a
->rsize
!= b
->rsize
)
2178 if (a
->acregmin
!= b
->acregmin
)
2180 if (a
->acregmax
!= b
->acregmax
)
2182 if (a
->acdirmin
!= b
->acdirmin
)
2184 if (a
->acdirmax
!= b
->acdirmax
)
2186 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2193 struct nfs_sb_mountdata
{
2194 struct nfs_server
*server
;
2198 static int nfs_set_super(struct super_block
*s
, void *data
)
2200 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2201 struct nfs_server
*server
= sb_mntdata
->server
;
2204 s
->s_flags
= sb_mntdata
->mntflags
;
2205 s
->s_fs_info
= server
;
2206 s
->s_d_op
= server
->nfs_client
->rpc_ops
->dentry_ops
;
2207 ret
= set_anon_super(s
, server
);
2209 server
->s_dev
= s
->s_dev
;
2213 static int nfs_compare_super_address(struct nfs_server
*server1
,
2214 struct nfs_server
*server2
)
2216 struct sockaddr
*sap1
, *sap2
;
2218 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2219 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2221 if (sap1
->sa_family
!= sap2
->sa_family
)
2224 switch (sap1
->sa_family
) {
2226 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2227 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2228 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2230 if (sin1
->sin_port
!= sin2
->sin_port
)
2235 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2236 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2237 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2239 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2250 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2252 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2253 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2254 int mntflags
= sb_mntdata
->mntflags
;
2256 if (!nfs_compare_super_address(old
, server
))
2258 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2259 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2261 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2263 return nfs_compare_mount_options(sb
, server
, mntflags
);
2266 #ifdef CONFIG_NFS_FSCACHE
2267 static void nfs_get_cache_cookie(struct super_block
*sb
,
2268 struct nfs_parsed_mount_data
*parsed
,
2269 struct nfs_clone_mount
*cloned
)
2274 if (parsed
&& parsed
->fscache_uniq
) {
2275 uniq
= parsed
->fscache_uniq
;
2276 ulen
= strlen(parsed
->fscache_uniq
);
2277 } else if (cloned
) {
2278 struct nfs_server
*mnt_s
= NFS_SB(cloned
->sb
);
2279 if (mnt_s
->fscache_key
) {
2280 uniq
= mnt_s
->fscache_key
->key
.uniquifier
;
2281 ulen
= mnt_s
->fscache_key
->key
.uniq_len
;
2285 nfs_fscache_get_super_cookie(sb
, uniq
, ulen
);
2288 static void nfs_get_cache_cookie(struct super_block
*sb
,
2289 struct nfs_parsed_mount_data
*parsed
,
2290 struct nfs_clone_mount
*cloned
)
2295 static int nfs_bdi_register(struct nfs_server
*server
)
2297 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2300 int nfs_set_sb_security(struct super_block
*s
, struct dentry
*mntroot
,
2301 struct nfs_mount_info
*mount_info
)
2303 return security_sb_set_mnt_opts(s
, &mount_info
->parsed
->lsm_opts
);
2305 EXPORT_SYMBOL_GPL(nfs_set_sb_security
);
2307 int nfs_clone_sb_security(struct super_block
*s
, struct dentry
*mntroot
,
2308 struct nfs_mount_info
*mount_info
)
2310 /* clone any lsm security options from the parent to the new sb */
2311 security_sb_clone_mnt_opts(mount_info
->cloned
->sb
, s
);
2312 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
)
2316 EXPORT_SYMBOL_GPL(nfs_clone_sb_security
);
2318 struct dentry
*nfs_fs_mount_common(struct nfs_server
*server
,
2319 int flags
, const char *dev_name
,
2320 struct nfs_mount_info
*mount_info
,
2321 struct nfs_subversion
*nfs_mod
)
2323 struct super_block
*s
;
2324 struct dentry
*mntroot
= ERR_PTR(-ENOMEM
);
2325 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2326 struct nfs_sb_mountdata sb_mntdata
= {
2332 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2333 compare_super
= NULL
;
2335 /* -o noac implies -o sync */
2336 if (server
->flags
& NFS_MOUNT_NOAC
)
2337 sb_mntdata
.mntflags
|= MS_SYNCHRONOUS
;
2339 /* Get a superblock - note that we may end up sharing one that already exists */
2340 s
= sget(nfs_mod
->nfs_fs
, compare_super
, nfs_set_super
, flags
, &sb_mntdata
);
2342 mntroot
= ERR_CAST(s
);
2346 if (s
->s_fs_info
!= server
) {
2347 nfs_free_server(server
);
2350 error
= nfs_bdi_register(server
);
2352 mntroot
= ERR_PTR(error
);
2353 goto error_splat_bdi
;
2358 /* initial superblock/root creation */
2359 mount_info
->fill_super(s
, mount_info
);
2360 nfs_get_cache_cookie(s
, mount_info
->parsed
, mount_info
->cloned
);
2363 mntroot
= nfs_get_root(s
, mount_info
->mntfh
, dev_name
);
2364 if (IS_ERR(mntroot
))
2365 goto error_splat_super
;
2367 error
= mount_info
->set_security(s
, mntroot
, mount_info
);
2369 goto error_splat_root
;
2371 s
->s_flags
|= MS_ACTIVE
;
2377 nfs_free_server(server
);
2382 mntroot
= ERR_PTR(error
);
2384 if (server
&& !s
->s_root
)
2385 bdi_unregister(&server
->backing_dev_info
);
2387 deactivate_locked_super(s
);
2390 EXPORT_SYMBOL_GPL(nfs_fs_mount_common
);
2392 struct dentry
*nfs_fs_mount(struct file_system_type
*fs_type
,
2393 int flags
, const char *dev_name
, void *raw_data
)
2395 struct nfs_mount_info mount_info
= {
2396 .fill_super
= nfs_fill_super
,
2397 .set_security
= nfs_set_sb_security
,
2399 struct dentry
*mntroot
= ERR_PTR(-ENOMEM
);
2400 struct nfs_subversion
*nfs_mod
;
2403 mount_info
.parsed
= nfs_alloc_parsed_mount_data();
2404 mount_info
.mntfh
= nfs_alloc_fhandle();
2405 if (mount_info
.parsed
== NULL
|| mount_info
.mntfh
== NULL
)
2408 /* Validate the mount data */
2409 error
= nfs_validate_mount_data(fs_type
, raw_data
, mount_info
.parsed
, mount_info
.mntfh
, dev_name
);
2410 if (error
== NFS_TEXT_DATA
)
2411 error
= nfs_validate_text_mount_data(raw_data
, mount_info
.parsed
, dev_name
);
2413 mntroot
= ERR_PTR(error
);
2417 nfs_mod
= get_nfs_version(mount_info
.parsed
->version
);
2418 if (IS_ERR(nfs_mod
)) {
2419 mntroot
= ERR_CAST(nfs_mod
);
2423 mntroot
= nfs_mod
->rpc_ops
->try_mount(flags
, dev_name
, &mount_info
, nfs_mod
);
2425 put_nfs_version(nfs_mod
);
2427 nfs_free_parsed_mount_data(mount_info
.parsed
);
2428 nfs_free_fhandle(mount_info
.mntfh
);
2431 EXPORT_SYMBOL_GPL(nfs_fs_mount
);
2434 * Ensure that we unregister the bdi before kill_anon_super
2435 * releases the device name
2437 void nfs_put_super(struct super_block
*s
)
2439 struct nfs_server
*server
= NFS_SB(s
);
2441 bdi_unregister(&server
->backing_dev_info
);
2443 EXPORT_SYMBOL_GPL(nfs_put_super
);
2446 * Destroy an NFS2/3 superblock
2448 void nfs_kill_super(struct super_block
*s
)
2450 struct nfs_server
*server
= NFS_SB(s
);
2453 nfs_fscache_release_super_cookie(s
);
2454 nfs_free_server(server
);
2456 EXPORT_SYMBOL_GPL(nfs_kill_super
);
2459 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2462 nfs_xdev_mount(struct file_system_type
*fs_type
, int flags
,
2463 const char *dev_name
, void *raw_data
)
2465 struct nfs_clone_mount
*data
= raw_data
;
2466 struct nfs_mount_info mount_info
= {
2467 .fill_super
= nfs_clone_super
,
2468 .set_security
= nfs_clone_sb_security
,
2471 struct nfs_server
*server
;
2472 struct dentry
*mntroot
= ERR_PTR(-ENOMEM
);
2473 struct nfs_subversion
*nfs_mod
= NFS_SB(data
->sb
)->nfs_client
->cl_nfs_mod
;
2476 dprintk("--> nfs_xdev_mount_common()\n");
2478 mount_info
.mntfh
= mount_info
.cloned
->fh
;
2480 /* create a new volume representation */
2481 server
= nfs_mod
->rpc_ops
->clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
, data
->authflavor
);
2482 if (IS_ERR(server
)) {
2483 error
= PTR_ERR(server
);
2487 mntroot
= nfs_fs_mount_common(server
, flags
, dev_name
, &mount_info
, nfs_mod
);
2488 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2493 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error
);
2497 #if IS_ENABLED(CONFIG_NFS_V4)
2499 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2501 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
|
2502 NFS_MOUNT_LOCAL_FLOCK
|NFS_MOUNT_LOCAL_FCNTL
);
2506 * Validate NFSv4 mount options
2508 static int nfs4_validate_mount_data(void *options
,
2509 struct nfs_parsed_mount_data
*args
,
2510 const char *dev_name
)
2512 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2513 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2521 switch (data
->version
) {
2523 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2524 goto out_no_address
;
2525 if (data
->host_addrlen
== 0)
2526 goto out_no_address
;
2527 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2528 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2530 if (!nfs_verify_server_address(sap
))
2531 goto out_no_address
;
2533 if (data
->auth_flavourlen
) {
2534 if (data
->auth_flavourlen
> 1)
2535 goto out_inval_auth
;
2536 if (copy_from_user(&args
->auth_flavors
[0],
2537 data
->auth_flavours
,
2538 sizeof(args
->auth_flavors
[0])))
2542 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2545 args
->nfs_server
.hostname
= c
;
2547 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2550 args
->nfs_server
.export_path
= c
;
2551 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2553 c
= strndup_user(data
->client_addr
.data
, 16);
2556 args
->client_address
= c
;
2559 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2563 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2564 args
->rsize
= data
->rsize
;
2565 args
->wsize
= data
->wsize
;
2566 args
->timeo
= data
->timeo
;
2567 args
->retrans
= data
->retrans
;
2568 args
->acregmin
= data
->acregmin
;
2569 args
->acregmax
= data
->acregmax
;
2570 args
->acdirmin
= data
->acdirmin
;
2571 args
->acdirmax
= data
->acdirmax
;
2572 args
->nfs_server
.protocol
= data
->proto
;
2573 nfs_validate_transport_protocol(args
);
2577 return NFS_TEXT_DATA
;
2583 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2587 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2588 data
->auth_flavourlen
);
2592 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2597 * NFS v4 module parameters need to stay in the
2598 * NFS client for backwards compatibility
2600 unsigned int nfs_callback_set_tcpport
;
2601 unsigned short nfs_callback_tcpport
;
2602 /* Default cache timeout is 10 minutes */
2603 unsigned int nfs_idmap_cache_timeout
= 600;
2604 /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2605 bool nfs4_disable_idmapping
= true;
2606 unsigned short max_session_slots
= NFS4_DEF_SLOT_TABLE_SIZE
;
2607 unsigned short send_implementation_id
= 1;
2609 EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport
);
2610 EXPORT_SYMBOL_GPL(nfs_callback_tcpport
);
2611 EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout
);
2612 EXPORT_SYMBOL_GPL(nfs4_disable_idmapping
);
2613 EXPORT_SYMBOL_GPL(max_session_slots
);
2614 EXPORT_SYMBOL_GPL(send_implementation_id
);
2616 #define NFS_CALLBACK_MAXPORTNR (65535U)
2618 static int param_set_portnr(const char *val
, const struct kernel_param
*kp
)
2625 ret
= strict_strtoul(val
, 0, &num
);
2626 if (ret
== -EINVAL
|| num
> NFS_CALLBACK_MAXPORTNR
)
2628 *((unsigned int *)kp
->arg
) = num
;
2631 static struct kernel_param_ops param_ops_portnr
= {
2632 .set
= param_set_portnr
,
2633 .get
= param_get_uint
,
2635 #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2637 module_param_named(callback_tcpport
, nfs_callback_set_tcpport
, portnr
, 0644);
2638 module_param(nfs_idmap_cache_timeout
, int, 0644);
2639 module_param(nfs4_disable_idmapping
, bool, 0644);
2640 MODULE_PARM_DESC(nfs4_disable_idmapping
,
2641 "Turn off NFSv4 idmapping when using 'sec=sys'");
2642 module_param(max_session_slots
, ushort
, 0644);
2643 MODULE_PARM_DESC(max_session_slots
, "Maximum number of outstanding NFSv4.1 "
2644 "requests the client will negotiate");
2645 module_param(send_implementation_id
, ushort
, 0644);
2646 MODULE_PARM_DESC(send_implementation_id
,
2647 "Send implementation ID with NFSv4.1 exchange_id");
2648 #endif /* CONFIG_NFS_V4 */