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>
57 #include <linux/kthread.h>
59 #include <asm/uaccess.h>
63 #include "delegation.h"
70 #define NFSDBG_FACILITY NFSDBG_VFS
71 #define NFS_TEXT_DATA 1
73 #if IS_ENABLED(CONFIG_NFS_V3)
74 #define NFS_DEFAULT_VERSION 3
76 #define NFS_DEFAULT_VERSION 2
80 /* Mount options that take no arguments */
82 Opt_posix, Opt_noposix,
86 Opt_udp, Opt_tcp, Opt_rdma,
88 Opt_rdirplus, Opt_nordirplus,
89 Opt_sharecache, Opt_nosharecache,
90 Opt_resvport, Opt_noresvport,
91 Opt_fscache, Opt_nofscache,
92 Opt_migration, Opt_nomigration,
94 /* Mount options that take integer arguments */
96 Opt_rsize, Opt_wsize, Opt_bsize,
97 Opt_timeo, Opt_retrans,
98 Opt_acregmin, Opt_acregmax,
99 Opt_acdirmin, Opt_acdirmax,
106 /* Mount options that take string arguments */
108 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
109 Opt_addr, Opt_mountaddr, Opt_clientaddr,
114 /* Special mount options */
115 Opt_userspace, Opt_deprecated, Opt_sloppy,
120 static const match_table_t nfs_mount_option_tokens = {
121 { Opt_userspace, "bg" },
122 { Opt_userspace, "fg" },
123 { Opt_userspace, "retry=%s" },
125 { Opt_sloppy, "sloppy" },
127 { Opt_soft, "soft" },
128 { Opt_hard, "hard" },
129 { Opt_deprecated, "intr" },
130 { Opt_deprecated, "nointr" },
131 { Opt_posix, "posix" },
132 { Opt_noposix, "noposix" },
134 { Opt_nocto, "nocto" },
136 { Opt_noac, "noac" },
137 { Opt_lock, "lock" },
138 { Opt_nolock, "nolock" },
141 { Opt_rdma, "rdma" },
143 { Opt_noacl, "noacl" },
144 { Opt_rdirplus, "rdirplus" },
145 { Opt_nordirplus, "nordirplus" },
146 { Opt_sharecache, "sharecache" },
147 { Opt_nosharecache, "nosharecache" },
148 { Opt_resvport, "resvport" },
149 { Opt_noresvport, "noresvport" },
150 { Opt_fscache, "fsc" },
151 { Opt_nofscache, "nofsc" },
152 { Opt_migration, "migration" },
153 { Opt_nomigration, "nomigration" },
155 { Opt_port, "port=%s" },
156 { Opt_rsize, "rsize=%s" },
157 { Opt_wsize, "wsize=%s" },
158 { Opt_bsize, "bsize=%s" },
159 { Opt_timeo, "timeo=%s" },
160 { Opt_retrans, "retrans=%s" },
161 { Opt_acregmin, "acregmin=%s" },
162 { Opt_acregmax, "acregmax=%s" },
163 { Opt_acdirmin, "acdirmin=%s" },
164 { Opt_acdirmax, "acdirmax=%s" },
165 { Opt_actimeo, "actimeo=%s" },
166 { Opt_namelen, "namlen=%s" },
167 { Opt_mountport, "mountport=%s" },
168 { Opt_mountvers, "mountvers=%s" },
169 { Opt_minorversion, "minorversion=%s" },
171 { Opt_nfsvers, "nfsvers=%s" },
172 { Opt_nfsvers, "vers=%s" },
174 { Opt_sec, "sec=%s" },
175 { Opt_proto, "proto=%s" },
176 { Opt_mountproto, "mountproto=%s" },
177 { Opt_addr, "addr=%s" },
178 { Opt_clientaddr, "clientaddr=%s" },
179 { Opt_mounthost, "mounthost=%s" },
180 { Opt_mountaddr, "mountaddr=%s" },
182 { Opt_lookupcache, "lookupcache=%s" },
183 { Opt_fscache_uniq, "fsc=%s" },
184 { Opt_local_lock, "local_lock=%s" },
186 /* The following needs to be listed after all other options */
187 { Opt_nfsvers, "v%s" },
193 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
198 static const match_table_t nfs_xprt_protocol_tokens = {
199 { Opt_xprt_udp, "udp" },
200 { Opt_xprt_udp6, "udp6" },
201 { Opt_xprt_tcp, "tcp" },
202 { Opt_xprt_tcp6, "tcp6" },
203 { Opt_xprt_rdma, "rdma" },
205 { Opt_xprt_err, NULL }
209 Opt_sec_none, Opt_sec_sys,
210 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
211 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
212 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
217 static const match_table_t nfs_secflavor_tokens = {
218 { Opt_sec_none, "none" },
219 { Opt_sec_none, "null" },
220 { Opt_sec_sys, "sys" },
222 { Opt_sec_krb5, "krb5" },
223 { Opt_sec_krb5i, "krb5i" },
224 { Opt_sec_krb5p, "krb5p" },
226 { Opt_sec_lkey, "lkey" },
227 { Opt_sec_lkeyi, "lkeyi" },
228 { Opt_sec_lkeyp, "lkeyp" },
230 { Opt_sec_spkm, "spkm3" },
231 { Opt_sec_spkmi, "spkm3i" },
232 { Opt_sec_spkmp, "spkm3p" },
234 { Opt_sec_err, NULL }
238 Opt_lookupcache_all, Opt_lookupcache_positive,
239 Opt_lookupcache_none,
244 static match_table_t nfs_lookupcache_tokens = {
245 { Opt_lookupcache_all, "all" },
246 { Opt_lookupcache_positive, "pos" },
247 { Opt_lookupcache_positive, "positive" },
248 { Opt_lookupcache_none, "none" },
250 { Opt_lookupcache_err, NULL }
254 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
260 static match_table_t nfs_local_lock_tokens = {
261 { Opt_local_lock_all, "all" },
262 { Opt_local_lock_flock, "flock" },
263 { Opt_local_lock_posix, "posix" },
264 { Opt_local_lock_none, "none" },
266 { Opt_local_lock_err, NULL }
270 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
276 static match_table_t nfs_vers_tokens = {
280 { Opt_vers_4_0, "4.0" },
281 { Opt_vers_4_1, "4.1" },
283 { Opt_vers_err, NULL }
286 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
287 int flags, const char *dev_name, void *raw_data);
289 struct file_system_type nfs_fs_type = {
290 .owner = THIS_MODULE,
292 .mount = nfs_fs_mount,
293 .kill_sb = nfs_kill_super,
294 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
296 EXPORT_SYMBOL_GPL(nfs_fs_type);
298 struct file_system_type nfs_xdev_fs_type = {
299 .owner = THIS_MODULE,
301 .mount = nfs_xdev_mount,
302 .kill_sb = nfs_kill_super,
303 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
306 const struct super_operations nfs_sops = {
307 .alloc_inode = nfs_alloc_inode,
308 .destroy_inode = nfs_destroy_inode,
309 .write_inode = nfs_write_inode,
310 .put_super = nfs_put_super,
311 .statfs = nfs_statfs,
312 .evict_inode = nfs_evict_inode,
313 .umount_begin = nfs_umount_begin,
314 .show_options = nfs_show_options,
315 .show_devname = nfs_show_devname,
316 .show_path = nfs_show_path,
317 .show_stats = nfs_show_stats,
318 .remount_fs = nfs_remount,
320 EXPORT_SYMBOL_GPL(nfs_sops);
322 #if IS_ENABLED(CONFIG_NFS_V4)
323 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
324 static int nfs4_validate_mount_data(void *options,
325 struct nfs_parsed_mount_data *args, const char *dev_name);
327 struct file_system_type nfs4_fs_type = {
328 .owner = THIS_MODULE,
330 .mount = nfs_fs_mount,
331 .kill_sb = nfs_kill_super,
332 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
334 EXPORT_SYMBOL_GPL(nfs4_fs_type);
336 static int __init register_nfs4_fs(void)
338 return register_filesystem(&nfs4_fs_type);
341 static void unregister_nfs4_fs(void)
343 unregister_filesystem(&nfs4_fs_type);
346 static int __init register_nfs4_fs(void)
351 static void unregister_nfs4_fs(void)
356 static struct shrinker acl_shrinker = {
357 .shrink = nfs_access_cache_shrinker,
358 .seeks = DEFAULT_SEEKS,
362 * Register the NFS filesystems
364 int __init register_nfs_fs(void)
368 ret = register_filesystem(&nfs_fs_type);
372 ret = register_nfs4_fs();
376 ret = nfs_register_sysctl();
379 register_shrinker(&acl_shrinker);
383 unregister_nfs4_fs();
385 unregister_filesystem(&nfs_fs_type);
391 * Unregister the NFS filesystems
393 void __exit unregister_nfs_fs(void)
395 unregister_shrinker(&acl_shrinker);
396 nfs_unregister_sysctl();
397 unregister_nfs4_fs();
398 unregister_filesystem(&nfs_fs_type);
401 void nfs_sb_active(struct super_block *sb)
403 struct nfs_server *server = NFS_SB(sb);
405 if (atomic_inc_return(&server->active) == 1)
406 atomic_inc(&sb->s_active);
408 EXPORT_SYMBOL_GPL(nfs_sb_active);
410 void nfs_sb_deactive(struct super_block *sb)
412 struct nfs_server *server = NFS_SB(sb);
414 if (atomic_dec_and_test(&server->active))
415 deactivate_super(sb);
417 EXPORT_SYMBOL_GPL(nfs_sb_deactive);
419 static int nfs_deactivate_super_async_work(void *ptr)
421 struct super_block *sb = ptr;
423 deactivate_super(sb);
424 module_put_and_exit(0);
429 * same effect as deactivate_super, but will do final unmount in kthread
432 static void nfs_deactivate_super_async(struct super_block *sb)
434 struct task_struct *task;
435 char buf[INET6_ADDRSTRLEN + 1];
436 struct nfs_server *server = NFS_SB(sb);
437 struct nfs_client *clp = server->nfs_client;
439 if (!atomic_add_unless(&sb->s_active, -1, 1)) {
441 snprintf(buf, sizeof(buf),
442 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
445 __module_get(THIS_MODULE);
446 task = kthread_run(nfs_deactivate_super_async_work, sb,
447 "%s-deactivate-super", buf);
449 pr_err("%s: kthread_run: %ld\n",
450 __func__, PTR_ERR(task));
451 /* make synchronous call and hope for the best */
452 deactivate_super(sb);
453 module_put(THIS_MODULE);
458 void nfs_sb_deactive_async(struct super_block *sb)
460 struct nfs_server *server = NFS_SB(sb);
462 if (atomic_dec_and_test(&server->active))
463 nfs_deactivate_super_async(sb);
465 EXPORT_SYMBOL_GPL(nfs_sb_deactive_async);
468 * Deliver file system statistics to userspace
470 int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
472 struct nfs_server *server = NFS_SB(dentry->d_sb);
473 unsigned char blockbits;
474 unsigned long blockres;
475 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
476 struct nfs_fsstat res;
479 res.fattr = nfs_alloc_fattr();
480 if (res.fattr == NULL)
483 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
484 if (unlikely(error == -ESTALE)) {
485 struct dentry *pd_dentry;
487 pd_dentry = dget_parent(dentry);
488 if (pd_dentry != NULL) {
489 nfs_zap_caches(pd_dentry->d_inode);
493 nfs_free_fattr(res.fattr);
497 buf->f_type = NFS_SUPER_MAGIC;
500 * Current versions of glibc do not correctly handle the
501 * case where f_frsize != f_bsize. Eventually we want to
502 * report the value of wtmult in this field.
504 buf->f_frsize = dentry->d_sb->s_blocksize;
507 * On most *nix systems, f_blocks, f_bfree, and f_bavail
508 * are reported in units of f_frsize. Linux hasn't had
509 * an f_frsize field in its statfs struct until recently,
510 * thus historically Linux's sys_statfs reports these
511 * fields in units of f_bsize.
513 buf->f_bsize = dentry->d_sb->s_blocksize;
514 blockbits = dentry->d_sb->s_blocksize_bits;
515 blockres = (1 << blockbits) - 1;
516 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
517 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
518 buf->f_bavail = (res.abytes + blockres) >> blockbits;
520 buf->f_files = res.tfiles;
521 buf->f_ffree = res.afiles;
523 buf->f_namelen = server->namelen;
528 dprintk("%s: statfs error = %d\n", __func__, -error);
531 EXPORT_SYMBOL_GPL(nfs_statfs);
534 * Map the security flavour number to a name
536 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
538 static const struct {
539 rpc_authflavor_t flavour;
542 { RPC_AUTH_NULL, "null" },
543 { RPC_AUTH_UNIX, "sys" },
544 { RPC_AUTH_GSS_KRB5, "krb5" },
545 { RPC_AUTH_GSS_KRB5I, "krb5i" },
546 { RPC_AUTH_GSS_KRB5P, "krb5p" },
547 { RPC_AUTH_GSS_LKEY, "lkey" },
548 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
549 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
550 { RPC_AUTH_GSS_SPKM, "spkm" },
551 { RPC_AUTH_GSS_SPKMI, "spkmi" },
552 { RPC_AUTH_GSS_SPKMP, "spkmp" },
553 { UINT_MAX, "unknown" }
557 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
558 if (sec_flavours[i].flavour == flavour)
561 return sec_flavours[i].str;
564 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
567 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
569 seq_printf(m, ",mountproto=");
570 switch (sap->sa_family) {
572 switch (nfss->mountd_protocol) {
574 seq_printf(m, RPCBIND_NETID_UDP);
577 seq_printf(m, RPCBIND_NETID_TCP);
581 seq_printf(m, "auto");
585 switch (nfss->mountd_protocol) {
587 seq_printf(m, RPCBIND_NETID_UDP6);
590 seq_printf(m, RPCBIND_NETID_TCP6);
594 seq_printf(m, "auto");
599 seq_printf(m, "auto");
603 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
606 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
608 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
611 switch (sap->sa_family) {
613 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
614 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
618 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
619 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
624 seq_printf(m, ",mountaddr=unspecified");
627 if (nfss->mountd_version || showdefaults)
628 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
629 if ((nfss->mountd_port &&
630 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
632 seq_printf(m, ",mountport=%u", nfss->mountd_port);
634 nfs_show_mountd_netid(m, nfss, showdefaults);
637 #if IS_ENABLED(CONFIG_NFS_V4)
638 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
641 struct nfs_client *clp = nfss->nfs_client;
643 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
646 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
652 static void nfs_show_nfs_version(struct seq_file *m,
653 unsigned int version,
654 unsigned int minorversion)
656 seq_printf(m, ",vers=%u", version);
658 seq_printf(m, ".%u", minorversion);
662 * Describe the mount options in force on this server representation
664 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
667 static const struct proc_nfs_info {
672 { NFS_MOUNT_SOFT, ",soft", ",hard" },
673 { NFS_MOUNT_POSIX, ",posix", "" },
674 { NFS_MOUNT_NOCTO, ",nocto", "" },
675 { NFS_MOUNT_NOAC, ",noac", "" },
676 { NFS_MOUNT_NONLM, ",nolock", "" },
677 { NFS_MOUNT_NOACL, ",noacl", "" },
678 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
679 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
680 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
683 const struct proc_nfs_info *nfs_infop;
684 struct nfs_client *clp = nfss->nfs_client;
685 u32 version = clp->rpc_ops->version;
686 int local_flock, local_fcntl;
688 nfs_show_nfs_version(m, version, clp->cl_minorversion);
689 seq_printf(m, ",rsize=%u", nfss->rsize);
690 seq_printf(m, ",wsize=%u", nfss->wsize);
691 if (nfss->bsize != 0)
692 seq_printf(m, ",bsize=%u", nfss->bsize);
693 seq_printf(m, ",namlen=%u", nfss->namelen);
694 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
695 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
696 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
697 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
698 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
699 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
700 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
701 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
702 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
703 if (nfss->flags & nfs_infop->flag)
704 seq_puts(m, nfs_infop->str);
706 seq_puts(m, nfs_infop->nostr);
709 seq_printf(m, ",proto=%s",
710 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
713 if (nfss->port != NFS_PORT)
714 seq_printf(m, ",port=%u", nfss->port);
717 seq_printf(m, ",port=%u", nfss->port);
719 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
720 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
721 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
724 nfs_show_mountd_options(m, nfss, showdefaults);
726 nfs_show_nfsv4_options(m, nfss, showdefaults);
728 if (nfss->options & NFS_OPTION_FSCACHE)
729 seq_printf(m, ",fsc");
731 if (nfss->options & NFS_OPTION_MIGRATION)
732 seq_printf(m, ",migration");
734 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
735 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
736 seq_printf(m, ",lookupcache=none");
738 seq_printf(m, ",lookupcache=pos");
741 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
742 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
744 if (!local_flock && !local_fcntl)
745 seq_printf(m, ",local_lock=none");
746 else if (local_flock && local_fcntl)
747 seq_printf(m, ",local_lock=all");
748 else if (local_flock)
749 seq_printf(m, ",local_lock=flock");
751 seq_printf(m, ",local_lock=posix");
755 * Describe the mount options on this VFS mountpoint
757 int nfs_show_options(struct seq_file *m, struct dentry *root)
759 struct nfs_server *nfss = NFS_SB(root->d_sb);
761 nfs_show_mount_options(m, nfss, 0);
764 seq_printf(m, ",addr=%s",
765 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
771 EXPORT_SYMBOL_GPL(nfs_show_options);
773 #if IS_ENABLED(CONFIG_NFS_V4)
774 #ifdef CONFIG_NFS_V4_1
775 static void show_sessions(struct seq_file *m, struct nfs_server *server)
777 if (nfs4_has_session(server->nfs_client))
778 seq_printf(m, ",sessions");
781 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
785 #ifdef CONFIG_NFS_V4_1
786 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
788 seq_printf(m, ",pnfs=");
789 if (server->pnfs_curr_ld)
790 seq_printf(m, "%s", server->pnfs_curr_ld->name);
792 seq_printf(m, "not configured");
795 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
797 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
798 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
799 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
801 impl_id->name, impl_id->domain,
802 impl_id->date.seconds, impl_id->date.nseconds);
806 #if IS_ENABLED(CONFIG_NFS_V4)
807 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
811 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
816 int nfs_show_devname(struct seq_file *m, struct dentry *root)
818 char *page = (char *) __get_free_page(GFP_KERNEL);
819 char *devname, *dummy;
823 devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
825 err = PTR_ERR(devname);
827 seq_escape(m, devname, " \t\n\\");
828 free_page((unsigned long)page);
831 EXPORT_SYMBOL_GPL(nfs_show_devname);
833 int nfs_show_path(struct seq_file *m, struct dentry *dentry)
838 EXPORT_SYMBOL_GPL(nfs_show_path);
841 * Present statistical information for this VFS mountpoint
843 int nfs_show_stats(struct seq_file *m, struct dentry *root)
846 struct nfs_server *nfss = NFS_SB(root->d_sb);
847 struct rpc_auth *auth = nfss->client->cl_auth;
848 struct nfs_iostats totals = { };
850 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
853 * Display all mount option settings
855 seq_printf(m, "\n\topts:\t");
856 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
857 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
858 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
859 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
860 nfs_show_mount_options(m, nfss, 1);
862 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
864 show_implementation_id(m, nfss);
866 seq_printf(m, "\n\tcaps:\t");
867 seq_printf(m, "caps=0x%x", nfss->caps);
868 seq_printf(m, ",wtmult=%u", nfss->wtmult);
869 seq_printf(m, ",dtsize=%u", nfss->dtsize);
870 seq_printf(m, ",bsize=%u", nfss->bsize);
871 seq_printf(m, ",namlen=%u", nfss->namelen);
873 #if IS_ENABLED(CONFIG_NFS_V4)
874 if (nfss->nfs_client->rpc_ops->version == 4) {
875 seq_printf(m, "\n\tnfsv4:\t");
876 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
877 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
878 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
879 show_sessions(m, nfss);
885 * Display security flavor in effect for this mount
887 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
889 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
892 * Display superblock I/O counters
894 for_each_possible_cpu(cpu) {
895 struct nfs_iostats *stats;
898 stats = per_cpu_ptr(nfss->io_stats, cpu);
900 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
901 totals.events[i] += stats->events[i];
902 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
903 totals.bytes[i] += stats->bytes[i];
904 #ifdef CONFIG_NFS_FSCACHE
905 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
906 totals.fscache[i] += stats->fscache[i];
912 seq_printf(m, "\n\tevents:\t");
913 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
914 seq_printf(m, "%lu ", totals.events[i]);
915 seq_printf(m, "\n\tbytes:\t");
916 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
917 seq_printf(m, "%Lu ", totals.bytes[i]);
918 #ifdef CONFIG_NFS_FSCACHE
919 if (nfss->options & NFS_OPTION_FSCACHE) {
920 seq_printf(m, "\n\tfsc:\t");
921 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
922 seq_printf(m, "%Lu ", totals.bytes[i]);
927 rpc_print_iostats(m, nfss->client);
931 EXPORT_SYMBOL_GPL(nfs_show_stats);
934 * Begin unmount by attempting to remove all automounted mountpoints we added
935 * in response to xdev traversals and referrals
937 void nfs_umount_begin(struct super_block *sb)
939 struct nfs_server *server;
940 struct rpc_clnt *rpc;
943 /* -EIO all pending I/O */
944 rpc = server->client_acl;
946 rpc_killall_tasks(rpc);
947 rpc = server->client;
949 rpc_killall_tasks(rpc);
951 EXPORT_SYMBOL_GPL(nfs_umount_begin);
953 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
955 struct nfs_parsed_mount_data *data;
957 data = kzalloc(sizeof(*data), GFP_KERNEL);
959 data->acregmin = NFS_DEF_ACREGMIN;
960 data->acregmax = NFS_DEF_ACREGMAX;
961 data->acdirmin = NFS_DEF_ACDIRMIN;
962 data->acdirmax = NFS_DEF_ACDIRMAX;
963 data->mount_server.port = NFS_UNSPEC_PORT;
964 data->nfs_server.port = NFS_UNSPEC_PORT;
965 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
966 data->auth_flavors[0] = RPC_AUTH_UNIX;
967 data->auth_flavor_len = 1;
968 data->minorversion = 0;
969 data->need_mount = true;
970 data->net = current->nsproxy->net_ns;
971 security_init_mnt_opts(&data->lsm_opts);
976 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
979 kfree(data->client_address);
980 kfree(data->mount_server.hostname);
981 kfree(data->nfs_server.export_path);
982 kfree(data->nfs_server.hostname);
983 kfree(data->fscache_uniq);
984 security_free_mnt_opts(&data->lsm_opts);
990 * Sanity-check a server address provided by the mount command.
992 * Address family must be initialized, and address must not be
993 * the ANY address for that family.
995 static int nfs_verify_server_address(struct sockaddr *addr)
997 switch (addr->sa_family) {
999 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
1000 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
1003 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1004 return !ipv6_addr_any(sa);
1008 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
1013 * Select between a default port value and a user-specified port value.
1014 * If a zero value is set, then autobind will be used.
1016 static void nfs_set_port(struct sockaddr *sap, int *port,
1017 const unsigned short default_port)
1019 if (*port == NFS_UNSPEC_PORT)
1020 *port = default_port;
1022 rpc_set_port(sap, *port);
1026 * Sanity check the NFS transport protocol.
1029 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1031 switch (mnt->nfs_server.protocol) {
1032 case XPRT_TRANSPORT_UDP:
1033 case XPRT_TRANSPORT_TCP:
1034 case XPRT_TRANSPORT_RDMA:
1037 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1042 * For text based NFSv2/v3 mounts, the mount protocol transport default
1043 * settings should depend upon the specified NFS transport.
1045 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1047 nfs_validate_transport_protocol(mnt);
1049 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1050 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1052 switch (mnt->nfs_server.protocol) {
1053 case XPRT_TRANSPORT_UDP:
1054 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1056 case XPRT_TRANSPORT_TCP:
1057 case XPRT_TRANSPORT_RDMA:
1058 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1063 * Parse the value of the 'sec=' option.
1065 static int nfs_parse_security_flavors(char *value,
1066 struct nfs_parsed_mount_data *mnt)
1068 substring_t args[MAX_OPT_ARGS];
1070 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1072 switch (match_token(value, nfs_secflavor_tokens, args)) {
1074 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1077 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1080 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1083 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1086 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1089 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1092 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1095 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1098 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1101 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1104 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1110 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1111 mnt->auth_flavor_len = 1;
1115 static int nfs_parse_version_string(char *string,
1116 struct nfs_parsed_mount_data *mnt,
1119 mnt->flags &= ~NFS_MOUNT_VER3;
1120 switch (match_token(string, nfs_vers_tokens, args)) {
1125 mnt->flags |= NFS_MOUNT_VER3;
1129 /* Backward compatibility option. In future,
1130 * the mount program should always supply
1131 * a NFSv4 minor version number.
1137 mnt->minorversion = 0;
1141 mnt->minorversion = 1;
1149 static int nfs_get_option_str(substring_t args[], char **option)
1152 *option = match_strdup(args);
1156 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1161 string = match_strdup(args);
1164 rc = kstrtoul(string, 10, option);
1171 * Error-check and convert a string of mount options from user space into
1172 * a data structure. The whole mount string is processed; bad options are
1173 * skipped as they are encountered. If there were no errors, return 1;
1174 * otherwise return 0 (zero).
1176 static int nfs_parse_mount_options(char *raw,
1177 struct nfs_parsed_mount_data *mnt)
1179 char *p, *string, *secdata;
1180 int rc, sloppy = 0, invalid_option = 0;
1181 unsigned short protofamily = AF_UNSPEC;
1182 unsigned short mountfamily = AF_UNSPEC;
1185 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1188 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1190 secdata = alloc_secdata();
1194 rc = security_sb_copy_data(raw, secdata);
1196 goto out_security_failure;
1198 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1200 goto out_security_failure;
1202 free_secdata(secdata);
1204 while ((p = strsep(&raw, ",")) != NULL) {
1205 substring_t args[MAX_OPT_ARGS];
1206 unsigned long option;
1212 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1214 token = match_token(p, nfs_mount_option_tokens, args);
1218 * boolean options: foo/nofoo
1221 mnt->flags |= NFS_MOUNT_SOFT;
1224 mnt->flags &= ~NFS_MOUNT_SOFT;
1227 mnt->flags |= NFS_MOUNT_POSIX;
1230 mnt->flags &= ~NFS_MOUNT_POSIX;
1233 mnt->flags &= ~NFS_MOUNT_NOCTO;
1236 mnt->flags |= NFS_MOUNT_NOCTO;
1239 mnt->flags &= ~NFS_MOUNT_NOAC;
1242 mnt->flags |= NFS_MOUNT_NOAC;
1245 mnt->flags &= ~NFS_MOUNT_NONLM;
1246 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1247 NFS_MOUNT_LOCAL_FCNTL);
1250 mnt->flags |= NFS_MOUNT_NONLM;
1251 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1252 NFS_MOUNT_LOCAL_FCNTL);
1255 mnt->flags &= ~NFS_MOUNT_TCP;
1256 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1259 mnt->flags |= NFS_MOUNT_TCP;
1260 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1263 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1264 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1265 xprt_load_transport(p);
1268 mnt->flags &= ~NFS_MOUNT_NOACL;
1271 mnt->flags |= NFS_MOUNT_NOACL;
1274 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1276 case Opt_nordirplus:
1277 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1279 case Opt_sharecache:
1280 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1282 case Opt_nosharecache:
1283 mnt->flags |= NFS_MOUNT_UNSHARED;
1286 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1288 case Opt_noresvport:
1289 mnt->flags |= NFS_MOUNT_NORESVPORT;
1292 mnt->options |= NFS_OPTION_FSCACHE;
1293 kfree(mnt->fscache_uniq);
1294 mnt->fscache_uniq = NULL;
1297 mnt->options &= ~NFS_OPTION_FSCACHE;
1298 kfree(mnt->fscache_uniq);
1299 mnt->fscache_uniq = NULL;
1302 mnt->options |= NFS_OPTION_MIGRATION;
1304 case Opt_nomigration:
1305 mnt->options &= NFS_OPTION_MIGRATION;
1309 * options that take numeric values
1312 if (nfs_get_option_ul(args, &option) ||
1314 goto out_invalid_value;
1315 mnt->nfs_server.port = option;
1318 if (nfs_get_option_ul(args, &option))
1319 goto out_invalid_value;
1320 mnt->rsize = option;
1323 if (nfs_get_option_ul(args, &option))
1324 goto out_invalid_value;
1325 mnt->wsize = option;
1328 if (nfs_get_option_ul(args, &option))
1329 goto out_invalid_value;
1330 mnt->bsize = option;
1333 if (nfs_get_option_ul(args, &option) || option == 0)
1334 goto out_invalid_value;
1335 mnt->timeo = option;
1338 if (nfs_get_option_ul(args, &option) || option == 0)
1339 goto out_invalid_value;
1340 mnt->retrans = option;
1343 if (nfs_get_option_ul(args, &option))
1344 goto out_invalid_value;
1345 mnt->acregmin = option;
1348 if (nfs_get_option_ul(args, &option))
1349 goto out_invalid_value;
1350 mnt->acregmax = option;
1353 if (nfs_get_option_ul(args, &option))
1354 goto out_invalid_value;
1355 mnt->acdirmin = option;
1358 if (nfs_get_option_ul(args, &option))
1359 goto out_invalid_value;
1360 mnt->acdirmax = option;
1363 if (nfs_get_option_ul(args, &option))
1364 goto out_invalid_value;
1365 mnt->acregmin = mnt->acregmax =
1366 mnt->acdirmin = mnt->acdirmax = option;
1369 if (nfs_get_option_ul(args, &option))
1370 goto out_invalid_value;
1371 mnt->namlen = option;
1374 if (nfs_get_option_ul(args, &option) ||
1376 goto out_invalid_value;
1377 mnt->mount_server.port = option;
1380 if (nfs_get_option_ul(args, &option) ||
1381 option < NFS_MNT_VERSION ||
1382 option > NFS_MNT3_VERSION)
1383 goto out_invalid_value;
1384 mnt->mount_server.version = option;
1386 case Opt_minorversion:
1387 if (nfs_get_option_ul(args, &option))
1388 goto out_invalid_value;
1389 if (option > NFS4_MAX_MINOR_VERSION)
1390 goto out_invalid_value;
1391 mnt->minorversion = option;
1395 * options that take text values
1398 string = match_strdup(args);
1401 rc = nfs_parse_version_string(string, mnt, args);
1404 goto out_invalid_value;
1407 string = match_strdup(args);
1410 rc = nfs_parse_security_flavors(string, mnt);
1413 dfprintk(MOUNT, "NFS: unrecognized "
1414 "security flavor\n");
1419 string = match_strdup(args);
1422 token = match_token(string,
1423 nfs_xprt_protocol_tokens, args);
1425 protofamily = AF_INET;
1428 protofamily = AF_INET6;
1430 mnt->flags &= ~NFS_MOUNT_TCP;
1431 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1434 protofamily = AF_INET6;
1436 mnt->flags |= NFS_MOUNT_TCP;
1437 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1440 /* vector side protocols to TCP */
1441 mnt->flags |= NFS_MOUNT_TCP;
1442 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1443 xprt_load_transport(string);
1446 dfprintk(MOUNT, "NFS: unrecognized "
1447 "transport protocol\n");
1453 case Opt_mountproto:
1454 string = match_strdup(args);
1457 token = match_token(string,
1458 nfs_xprt_protocol_tokens, args);
1461 mountfamily = AF_INET;
1464 mountfamily = AF_INET6;
1466 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1469 mountfamily = AF_INET6;
1471 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1473 case Opt_xprt_rdma: /* not used for side protocols */
1475 dfprintk(MOUNT, "NFS: unrecognized "
1476 "transport protocol\n");
1481 string = match_strdup(args);
1484 mnt->nfs_server.addrlen =
1485 rpc_pton(mnt->net, string, strlen(string),
1487 &mnt->nfs_server.address,
1488 sizeof(mnt->nfs_server.address));
1490 if (mnt->nfs_server.addrlen == 0)
1491 goto out_invalid_address;
1493 case Opt_clientaddr:
1494 if (nfs_get_option_str(args, &mnt->client_address))
1498 if (nfs_get_option_str(args,
1499 &mnt->mount_server.hostname))
1503 string = match_strdup(args);
1506 mnt->mount_server.addrlen =
1507 rpc_pton(mnt->net, string, strlen(string),
1509 &mnt->mount_server.address,
1510 sizeof(mnt->mount_server.address));
1512 if (mnt->mount_server.addrlen == 0)
1513 goto out_invalid_address;
1515 case Opt_lookupcache:
1516 string = match_strdup(args);
1519 token = match_token(string,
1520 nfs_lookupcache_tokens, args);
1523 case Opt_lookupcache_all:
1524 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1526 case Opt_lookupcache_positive:
1527 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1528 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1530 case Opt_lookupcache_none:
1531 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1534 dfprintk(MOUNT, "NFS: invalid "
1535 "lookupcache argument\n");
1539 case Opt_fscache_uniq:
1540 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1542 mnt->options |= NFS_OPTION_FSCACHE;
1544 case Opt_local_lock:
1545 string = match_strdup(args);
1548 token = match_token(string, nfs_local_lock_tokens,
1552 case Opt_local_lock_all:
1553 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1554 NFS_MOUNT_LOCAL_FCNTL);
1556 case Opt_local_lock_flock:
1557 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1559 case Opt_local_lock_posix:
1560 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1562 case Opt_local_lock_none:
1563 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1564 NFS_MOUNT_LOCAL_FCNTL);
1567 dfprintk(MOUNT, "NFS: invalid "
1568 "local_lock argument\n");
1578 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1581 case Opt_deprecated:
1582 dfprintk(MOUNT, "NFS: ignoring mount option "
1588 dfprintk(MOUNT, "NFS: unrecognized mount option "
1593 if (!sloppy && invalid_option)
1596 if (mnt->minorversion && mnt->version != 4)
1597 goto out_minorversion_mismatch;
1599 if (mnt->options & NFS_OPTION_MIGRATION &&
1600 mnt->version != 4 && mnt->minorversion != 0)
1601 goto out_migration_misuse;
1604 * verify that any proto=/mountproto= options match the address
1605 * families in the addr=/mountaddr= options.
1607 if (protofamily != AF_UNSPEC &&
1608 protofamily != mnt->nfs_server.address.ss_family)
1609 goto out_proto_mismatch;
1611 if (mountfamily != AF_UNSPEC) {
1612 if (mnt->mount_server.addrlen) {
1613 if (mountfamily != mnt->mount_server.address.ss_family)
1614 goto out_mountproto_mismatch;
1616 if (mountfamily != mnt->nfs_server.address.ss_family)
1617 goto out_mountproto_mismatch;
1623 out_mountproto_mismatch:
1624 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1628 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1630 out_invalid_address:
1631 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1634 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1636 out_minorversion_mismatch:
1637 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1638 "minorversion=%u\n", mnt->version, mnt->minorversion);
1640 out_migration_misuse:
1642 "NFS: 'migration' not supported for this NFS version\n");
1645 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1647 out_security_failure:
1648 free_secdata(secdata);
1649 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1654 * Match the requested auth flavors with the list returned by
1655 * the server. Returns zero and sets the mount's authentication
1656 * flavor on success; returns -EACCES if server does not support
1657 * the requested flavor.
1659 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1660 struct nfs_mount_request *request)
1662 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1665 * Certain releases of Linux's mountd return an empty
1666 * flavor list. To prevent behavioral regression with
1667 * these servers (ie. rejecting mounts that used to
1668 * succeed), revert to pre-2.6.32 behavior (no checking)
1669 * if the returned flavor list is empty.
1671 if (server_authlist_len == 0)
1675 * We avoid sophisticated negotiating here, as there are
1676 * plenty of cases where we can get it wrong, providing
1677 * either too little or too much security.
1679 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1680 * flavor listed first. However, some servers list
1681 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1682 * preferred default, in args->auth_flavors[0] if user
1683 * didn't specify sec= mount option.
1685 for (i = 0; i < args->auth_flavor_len; i++)
1686 for (j = 0; j < server_authlist_len; j++)
1687 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1688 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1689 request->auth_flavs[j]);
1690 args->auth_flavors[0] = request->auth_flavs[j];
1694 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1695 nfs_umount(request);
1700 * Use the remote server's MOUNT service to request the NFS file handle
1701 * corresponding to the provided path.
1703 static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1704 struct nfs_fh *root_fh)
1706 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1707 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1708 struct nfs_mount_request request = {
1709 .sap = (struct sockaddr *)
1710 &args->mount_server.address,
1711 .dirpath = args->nfs_server.export_path,
1712 .protocol = args->mount_server.protocol,
1714 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1715 .auth_flav_len = &server_authlist_len,
1716 .auth_flavs = server_authlist,
1721 if (args->mount_server.version == 0) {
1722 switch (args->version) {
1724 args->mount_server.version = NFS_MNT3_VERSION;
1727 args->mount_server.version = NFS_MNT_VERSION;
1730 request.version = args->mount_server.version;
1732 if (args->mount_server.hostname)
1733 request.hostname = args->mount_server.hostname;
1735 request.hostname = args->nfs_server.hostname;
1738 * Construct the mount server's address.
1740 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1741 memcpy(request.sap, &args->nfs_server.address,
1742 args->nfs_server.addrlen);
1743 args->mount_server.addrlen = args->nfs_server.addrlen;
1745 request.salen = args->mount_server.addrlen;
1746 nfs_set_port(request.sap, &args->mount_server.port, 0);
1749 * Now ask the mount server to map our export path
1752 status = nfs_mount(&request);
1754 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1755 request.hostname, status);
1760 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1762 if (args->mount_server.version != NFS_MNT3_VERSION)
1764 return nfs_walk_authlist(args, &request);
1767 struct dentry *nfs_try_mount(int flags, const char *dev_name,
1768 struct nfs_mount_info *mount_info,
1769 struct nfs_subversion *nfs_mod)
1772 struct nfs_server *server;
1774 if (mount_info->parsed->need_mount) {
1775 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
1777 return ERR_PTR(status);
1780 /* Get a volume representation */
1781 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
1783 return ERR_CAST(server);
1785 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
1787 EXPORT_SYMBOL_GPL(nfs_try_mount);
1790 * Split "dev_name" into "hostname:export_path".
1792 * The leftmost colon demarks the split between the server's hostname
1793 * and the export path. If the hostname starts with a left square
1794 * bracket, then it may contain colons.
1796 * Note: caller frees hostname and export path, even on error.
1798 static int nfs_parse_devname(const char *dev_name,
1799 char **hostname, size_t maxnamlen,
1800 char **export_path, size_t maxpathlen)
1805 /* Is the host name protected with square brakcets? */
1806 if (*dev_name == '[') {
1807 end = strchr(++dev_name, ']');
1808 if (end == NULL || end[1] != ':')
1809 goto out_bad_devname;
1811 len = end - dev_name;
1816 end = strchr(dev_name, ':');
1818 goto out_bad_devname;
1819 len = end - dev_name;
1821 /* kill possible hostname list: not supported */
1822 comma = strchr(dev_name, ',');
1823 if (comma != NULL && comma < end)
1827 if (len > maxnamlen)
1830 /* N.B. caller will free nfs_server.hostname in all cases */
1831 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1832 if (*hostname == NULL)
1834 len = strlen(++end);
1835 if (len > maxpathlen)
1837 *export_path = kstrndup(end, len, GFP_KERNEL);
1841 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1845 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1849 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1853 dfprintk(MOUNT, "NFS: server hostname too long\n");
1854 return -ENAMETOOLONG;
1857 dfprintk(MOUNT, "NFS: export pathname too long\n");
1858 return -ENAMETOOLONG;
1862 * Validate the NFS2/NFS3 mount data
1863 * - fills in the mount root filehandle
1865 * For option strings, user space handles the following behaviors:
1867 * + DNS: mapping server host name to IP address ("addr=" option)
1869 * + failure mode: how to behave if a mount request can't be handled
1870 * immediately ("fg/bg" option)
1872 * + retry: how often to retry a mount request ("retry=" option)
1874 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1875 * mountproto=tcp after mountproto=udp, and so on
1877 static int nfs23_validate_mount_data(void *options,
1878 struct nfs_parsed_mount_data *args,
1879 struct nfs_fh *mntfh,
1880 const char *dev_name)
1882 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1883 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1888 args->version = NFS_DEFAULT_VERSION;
1889 switch (data->version) {
1895 if (data->flags & NFS_MOUNT_VER3)
1897 data->root.size = NFS2_FHSIZE;
1898 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1900 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1903 memset(data->context, 0, sizeof(data->context));
1905 if (data->flags & NFS_MOUNT_VER3) {
1906 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1907 goto out_invalid_fh;
1908 mntfh->size = data->root.size;
1911 mntfh->size = NFS2_FHSIZE;
1916 memcpy(mntfh->data, data->root.data, mntfh->size);
1917 if (mntfh->size < sizeof(mntfh->data))
1918 memset(mntfh->data + mntfh->size, 0,
1919 sizeof(mntfh->data) - mntfh->size);
1922 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1925 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1926 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1927 args->rsize = data->rsize;
1928 args->wsize = data->wsize;
1929 args->timeo = data->timeo;
1930 args->retrans = data->retrans;
1931 args->acregmin = data->acregmin;
1932 args->acregmax = data->acregmax;
1933 args->acdirmin = data->acdirmin;
1934 args->acdirmax = data->acdirmax;
1935 args->need_mount = false;
1937 memcpy(sap, &data->addr, sizeof(data->addr));
1938 args->nfs_server.addrlen = sizeof(data->addr);
1939 args->nfs_server.port = ntohs(data->addr.sin_port);
1940 if (!nfs_verify_server_address(sap))
1941 goto out_no_address;
1943 if (!(data->flags & NFS_MOUNT_TCP))
1944 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1945 /* N.B. caller will free nfs_server.hostname in all cases */
1946 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1947 args->namlen = data->namlen;
1948 args->bsize = data->bsize;
1950 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1951 args->auth_flavors[0] = data->pseudoflavor;
1952 if (!args->nfs_server.hostname)
1955 if (!(data->flags & NFS_MOUNT_NONLM))
1956 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1957 NFS_MOUNT_LOCAL_FCNTL);
1959 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1960 NFS_MOUNT_LOCAL_FCNTL);
1962 * The legacy version 6 binary mount data from userspace has a
1963 * field used only to transport selinux information into the
1964 * the kernel. To continue to support that functionality we
1965 * have a touch of selinux knowledge here in the NFS code. The
1966 * userspace code converted context=blah to just blah so we are
1967 * converting back to the full string selinux understands.
1969 if (data->context[0]){
1970 #ifdef CONFIG_SECURITY_SELINUX
1972 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1975 strcpy(opts_str, "context=");
1976 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1977 strcat(opts_str, &data->context[0]);
1978 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1989 return NFS_TEXT_DATA;
1992 #if !IS_ENABLED(CONFIG_NFS_V3)
1993 if (args->version == 3)
1994 goto out_v3_not_compiled;
1995 #endif /* !CONFIG_NFS_V3 */
2000 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
2004 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2009 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2012 #if !IS_ENABLED(CONFIG_NFS_V3)
2013 out_v3_not_compiled:
2014 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2015 return -EPROTONOSUPPORT;
2016 #endif /* !CONFIG_NFS_V3 */
2019 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2023 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2027 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2031 #if IS_ENABLED(CONFIG_NFS_V4)
2032 static int nfs_validate_mount_data(struct file_system_type *fs_type,
2034 struct nfs_parsed_mount_data *args,
2035 struct nfs_fh *mntfh,
2036 const char *dev_name)
2038 if (fs_type == &nfs_fs_type)
2039 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2040 return nfs4_validate_mount_data(options, args, dev_name);
2043 static int nfs_validate_mount_data(struct file_system_type *fs_type,
2045 struct nfs_parsed_mount_data *args,
2046 struct nfs_fh *mntfh,
2047 const char *dev_name)
2049 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2053 static int nfs_validate_text_mount_data(void *options,
2054 struct nfs_parsed_mount_data *args,
2055 const char *dev_name)
2058 int max_namelen = PAGE_SIZE;
2059 int max_pathlen = NFS_MAXPATHLEN;
2060 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2062 if (nfs_parse_mount_options((char *)options, args) == 0)
2065 if (!nfs_verify_server_address(sap))
2066 goto out_no_address;
2068 if (args->version == 4) {
2069 #if IS_ENABLED(CONFIG_NFS_V4)
2071 max_namelen = NFS4_MAXNAMLEN;
2072 max_pathlen = NFS4_MAXPATHLEN;
2073 nfs_validate_transport_protocol(args);
2074 nfs4_validate_mount_flags(args);
2076 goto out_v4_not_compiled;
2077 #endif /* CONFIG_NFS_V4 */
2079 nfs_set_mount_transport_protocol(args);
2081 nfs_set_port(sap, &args->nfs_server.port, port);
2083 if (args->auth_flavor_len > 1)
2086 return nfs_parse_devname(dev_name,
2087 &args->nfs_server.hostname,
2089 &args->nfs_server.export_path,
2092 #if !IS_ENABLED(CONFIG_NFS_V4)
2093 out_v4_not_compiled:
2094 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2095 return -EPROTONOSUPPORT;
2096 #endif /* !CONFIG_NFS_V4 */
2099 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2103 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2108 nfs_compare_remount_data(struct nfs_server *nfss,
2109 struct nfs_parsed_mount_data *data)
2111 if (data->flags != nfss->flags ||
2112 data->rsize != nfss->rsize ||
2113 data->wsize != nfss->wsize ||
2114 data->retrans != nfss->client->cl_timeout->to_retries ||
2115 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2116 data->acregmin != nfss->acregmin / HZ ||
2117 data->acregmax != nfss->acregmax / HZ ||
2118 data->acdirmin != nfss->acdirmin / HZ ||
2119 data->acdirmax != nfss->acdirmax / HZ ||
2120 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2121 data->nfs_server.port != nfss->port ||
2122 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2123 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2124 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2131 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2134 struct nfs_server *nfss = sb->s_fs_info;
2135 struct nfs_parsed_mount_data *data;
2136 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2137 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2138 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2141 * Userspace mount programs that send binary options generally send
2142 * them populated with default values. We have no way to know which
2143 * ones were explicitly specified. Fall back to legacy behavior and
2144 * just return success.
2146 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2147 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2148 options->version <= 6))))
2151 data = kzalloc(sizeof(*data), GFP_KERNEL);
2155 /* fill out struct with values from existing mount */
2156 data->flags = nfss->flags;
2157 data->rsize = nfss->rsize;
2158 data->wsize = nfss->wsize;
2159 data->retrans = nfss->client->cl_timeout->to_retries;
2160 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2161 data->acregmin = nfss->acregmin / HZ;
2162 data->acregmax = nfss->acregmax / HZ;
2163 data->acdirmin = nfss->acdirmin / HZ;
2164 data->acdirmax = nfss->acdirmax / HZ;
2165 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2166 data->nfs_server.port = nfss->port;
2167 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2168 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2169 data->nfs_server.addrlen);
2171 /* overwrite those values with any that were specified */
2172 error = nfs_parse_mount_options((char *)options, data);
2177 * noac is a special case. It implies -o sync, but that's not
2178 * necessarily reflected in the mtab options. do_remount_sb
2179 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2180 * remount options, so we have to explicitly reset it.
2182 if (data->flags & NFS_MOUNT_NOAC)
2183 *flags |= MS_SYNCHRONOUS;
2185 /* compare new mount options with old ones */
2186 error = nfs_compare_remount_data(nfss, data);
2191 EXPORT_SYMBOL_GPL(nfs_remount);
2194 * Initialise the common bits of the superblock
2196 inline void nfs_initialise_sb(struct super_block *sb)
2198 struct nfs_server *server = NFS_SB(sb);
2200 sb->s_magic = NFS_SUPER_MAGIC;
2202 /* We probably want something more informative here */
2203 snprintf(sb->s_id, sizeof(sb->s_id),
2204 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2206 if (sb->s_blocksize == 0)
2207 sb->s_blocksize = nfs_block_bits(server->wsize,
2208 &sb->s_blocksize_bits);
2210 sb->s_bdi = &server->backing_dev_info;
2212 nfs_super_set_maxbytes(sb, server->maxfilesize);
2216 * Finish setting up an NFS2/3 superblock
2218 void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2220 struct nfs_parsed_mount_data *data = mount_info->parsed;
2221 struct nfs_server *server = NFS_SB(sb);
2223 sb->s_blocksize_bits = 0;
2224 sb->s_blocksize = 0;
2225 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2226 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2227 if (data && data->bsize)
2228 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2230 if (server->nfs_client->rpc_ops->version != 2) {
2231 /* The VFS shouldn't apply the umask to mode bits. We will do
2232 * so ourselves when necessary.
2234 sb->s_flags |= MS_POSIXACL;
2235 sb->s_time_gran = 1;
2238 nfs_initialise_sb(sb);
2240 EXPORT_SYMBOL_GPL(nfs_fill_super);
2243 * Finish setting up a cloned NFS2/3/4 superblock
2245 void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2247 const struct super_block *old_sb = mount_info->cloned->sb;
2248 struct nfs_server *server = NFS_SB(sb);
2250 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2251 sb->s_blocksize = old_sb->s_blocksize;
2252 sb->s_maxbytes = old_sb->s_maxbytes;
2253 sb->s_xattr = old_sb->s_xattr;
2254 sb->s_op = old_sb->s_op;
2255 sb->s_time_gran = 1;
2257 if (server->nfs_client->rpc_ops->version != 2) {
2258 /* The VFS shouldn't apply the umask to mode bits. We will do
2259 * so ourselves when necessary.
2261 sb->s_flags |= MS_POSIXACL;
2264 nfs_initialise_sb(sb);
2267 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2269 const struct nfs_server *a = s->s_fs_info;
2270 const struct rpc_clnt *clnt_a = a->client;
2271 const struct rpc_clnt *clnt_b = b->client;
2273 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2275 if (a->nfs_client != b->nfs_client)
2277 if (a->flags != b->flags)
2279 if (a->wsize != b->wsize)
2281 if (a->rsize != b->rsize)
2283 if (a->acregmin != b->acregmin)
2285 if (a->acregmax != b->acregmax)
2287 if (a->acdirmin != b->acdirmin)
2289 if (a->acdirmax != b->acdirmax)
2291 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2298 struct nfs_sb_mountdata {
2299 struct nfs_server *server;
2303 static int nfs_set_super(struct super_block *s, void *data)
2305 struct nfs_sb_mountdata *sb_mntdata = data;
2306 struct nfs_server *server = sb_mntdata->server;
2309 s->s_flags = sb_mntdata->mntflags;
2310 s->s_fs_info = server;
2311 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2312 ret = set_anon_super(s, server);
2314 server->s_dev = s->s_dev;
2318 static int nfs_compare_super_address(struct nfs_server *server1,
2319 struct nfs_server *server2)
2321 struct sockaddr *sap1, *sap2;
2323 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2324 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2326 if (sap1->sa_family != sap2->sa_family)
2329 switch (sap1->sa_family) {
2331 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2332 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2333 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2335 if (sin1->sin_port != sin2->sin_port)
2340 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2341 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2342 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2344 if (sin1->sin6_port != sin2->sin6_port)
2355 static int nfs_compare_super(struct super_block *sb, void *data)
2357 struct nfs_sb_mountdata *sb_mntdata = data;
2358 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2359 int mntflags = sb_mntdata->mntflags;
2361 if (!nfs_compare_super_address(old, server))
2363 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2364 if (old->flags & NFS_MOUNT_UNSHARED)
2366 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2368 return nfs_compare_mount_options(sb, server, mntflags);
2371 #ifdef CONFIG_NFS_FSCACHE
2372 static void nfs_get_cache_cookie(struct super_block *sb,
2373 struct nfs_parsed_mount_data *parsed,
2374 struct nfs_clone_mount *cloned)
2379 if (parsed && parsed->fscache_uniq) {
2380 uniq = parsed->fscache_uniq;
2381 ulen = strlen(parsed->fscache_uniq);
2382 } else if (cloned) {
2383 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2384 if (mnt_s->fscache_key) {
2385 uniq = mnt_s->fscache_key->key.uniquifier;
2386 ulen = mnt_s->fscache_key->key.uniq_len;
2390 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2393 static void nfs_get_cache_cookie(struct super_block *sb,
2394 struct nfs_parsed_mount_data *parsed,
2395 struct nfs_clone_mount *cloned)
2400 static int nfs_bdi_register(struct nfs_server *server)
2402 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2405 int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2406 struct nfs_mount_info *mount_info)
2408 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2410 EXPORT_SYMBOL_GPL(nfs_set_sb_security);
2412 int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2413 struct nfs_mount_info *mount_info)
2415 /* clone any lsm security options from the parent to the new sb */
2416 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2417 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2421 EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
2423 struct dentry *nfs_fs_mount_common(struct nfs_server *server,
2424 int flags, const char *dev_name,
2425 struct nfs_mount_info *mount_info,
2426 struct nfs_subversion *nfs_mod)
2428 struct super_block *s;
2429 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2430 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2431 struct nfs_sb_mountdata sb_mntdata = {
2437 if (server->flags & NFS_MOUNT_UNSHARED)
2438 compare_super = NULL;
2440 /* -o noac implies -o sync */
2441 if (server->flags & NFS_MOUNT_NOAC)
2442 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2444 /* Get a superblock - note that we may end up sharing one that already exists */
2445 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
2447 mntroot = ERR_CAST(s);
2451 if (s->s_fs_info != server) {
2452 nfs_free_server(server);
2455 error = nfs_bdi_register(server);
2457 mntroot = ERR_PTR(error);
2458 goto error_splat_bdi;
2463 /* initial superblock/root creation */
2464 mount_info->fill_super(s, mount_info);
2465 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2468 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
2469 if (IS_ERR(mntroot))
2470 goto error_splat_super;
2472 error = mount_info->set_security(s, mntroot, mount_info);
2474 goto error_splat_root;
2476 s->s_flags |= MS_ACTIVE;
2482 nfs_free_server(server);
2487 mntroot = ERR_PTR(error);
2489 if (server && !s->s_root)
2490 bdi_unregister(&server->backing_dev_info);
2492 deactivate_locked_super(s);
2495 EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
2497 struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2498 int flags, const char *dev_name, void *raw_data)
2500 struct nfs_mount_info mount_info = {
2501 .fill_super = nfs_fill_super,
2502 .set_security = nfs_set_sb_security,
2504 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2505 struct nfs_subversion *nfs_mod;
2508 mount_info.parsed = nfs_alloc_parsed_mount_data();
2509 mount_info.mntfh = nfs_alloc_fhandle();
2510 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
2513 /* Validate the mount data */
2514 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
2515 if (error == NFS_TEXT_DATA)
2516 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
2518 mntroot = ERR_PTR(error);
2522 nfs_mod = get_nfs_version(mount_info.parsed->version);
2523 if (IS_ERR(nfs_mod)) {
2524 mntroot = ERR_CAST(nfs_mod);
2528 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
2530 put_nfs_version(nfs_mod);
2532 nfs_free_parsed_mount_data(mount_info.parsed);
2533 nfs_free_fhandle(mount_info.mntfh);
2536 EXPORT_SYMBOL_GPL(nfs_fs_mount);
2539 * Ensure that we unregister the bdi before kill_anon_super
2540 * releases the device name
2542 void nfs_put_super(struct super_block *s)
2544 struct nfs_server *server = NFS_SB(s);
2546 bdi_unregister(&server->backing_dev_info);
2548 EXPORT_SYMBOL_GPL(nfs_put_super);
2551 * Destroy an NFS2/3 superblock
2553 void nfs_kill_super(struct super_block *s)
2555 struct nfs_server *server = NFS_SB(s);
2558 nfs_fscache_release_super_cookie(s);
2559 nfs_free_server(server);
2561 EXPORT_SYMBOL_GPL(nfs_kill_super);
2564 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2566 static struct dentry *
2567 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2568 const char *dev_name, void *raw_data)
2570 struct nfs_clone_mount *data = raw_data;
2571 struct nfs_mount_info mount_info = {
2572 .fill_super = nfs_clone_super,
2573 .set_security = nfs_clone_sb_security,
2576 struct nfs_server *server;
2577 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2578 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
2581 dprintk("--> nfs_xdev_mount_common()\n");
2583 mount_info.mntfh = mount_info.cloned->fh;
2585 /* create a new volume representation */
2586 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2587 if (IS_ERR(server)) {
2588 error = PTR_ERR(server);
2592 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
2593 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2598 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2602 #if IS_ENABLED(CONFIG_NFS_V4)
2604 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2606 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2607 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2611 * Validate NFSv4 mount options
2613 static int nfs4_validate_mount_data(void *options,
2614 struct nfs_parsed_mount_data *args,
2615 const char *dev_name)
2617 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2618 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2626 switch (data->version) {
2628 if (data->host_addrlen > sizeof(args->nfs_server.address))
2629 goto out_no_address;
2630 if (data->host_addrlen == 0)
2631 goto out_no_address;
2632 args->nfs_server.addrlen = data->host_addrlen;
2633 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2635 if (!nfs_verify_server_address(sap))
2636 goto out_no_address;
2637 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
2639 if (data->auth_flavourlen) {
2640 if (data->auth_flavourlen > 1)
2641 goto out_inval_auth;
2642 if (copy_from_user(&args->auth_flavors[0],
2643 data->auth_flavours,
2644 sizeof(args->auth_flavors[0])))
2648 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2651 args->nfs_server.hostname = c;
2653 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2656 args->nfs_server.export_path = c;
2657 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2659 c = strndup_user(data->client_addr.data, 16);
2662 args->client_address = c;
2665 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2669 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2670 args->rsize = data->rsize;
2671 args->wsize = data->wsize;
2672 args->timeo = data->timeo;
2673 args->retrans = data->retrans;
2674 args->acregmin = data->acregmin;
2675 args->acregmax = data->acregmax;
2676 args->acdirmin = data->acdirmin;
2677 args->acdirmax = data->acdirmax;
2678 args->nfs_server.protocol = data->proto;
2679 nfs_validate_transport_protocol(args);
2683 return NFS_TEXT_DATA;
2689 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2693 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2694 data->auth_flavourlen);
2698 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2703 * NFS v4 module parameters need to stay in the
2704 * NFS client for backwards compatibility
2706 unsigned int nfs_callback_set_tcpport;
2707 unsigned short nfs_callback_tcpport;
2708 /* Default cache timeout is 10 minutes */
2709 unsigned int nfs_idmap_cache_timeout = 600;
2710 /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2711 bool nfs4_disable_idmapping = true;
2712 unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2713 unsigned short send_implementation_id = 1;
2714 char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
2716 EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2717 EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2718 EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2719 EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2720 EXPORT_SYMBOL_GPL(max_session_slots);
2721 EXPORT_SYMBOL_GPL(send_implementation_id);
2722 EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
2724 #define NFS_CALLBACK_MAXPORTNR (65535U)
2726 static int param_set_portnr(const char *val, const struct kernel_param *kp)
2733 ret = kstrtoul(val, 0, &num);
2734 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2736 *((unsigned int *)kp->arg) = num;
2739 static struct kernel_param_ops param_ops_portnr = {
2740 .set = param_set_portnr,
2741 .get = param_get_uint,
2743 #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2745 module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2746 module_param(nfs_idmap_cache_timeout, int, 0644);
2747 module_param(nfs4_disable_idmapping, bool, 0644);
2748 module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
2749 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
2750 MODULE_PARM_DESC(nfs4_disable_idmapping,
2751 "Turn off NFSv4 idmapping when using 'sec=sys'");
2752 module_param(max_session_slots, ushort, 0644);
2753 MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2754 "requests the client will negotiate");
2755 module_param(send_implementation_id, ushort, 0644);
2756 MODULE_PARM_DESC(send_implementation_id,
2757 "Send implementation ID with NFSv4.1 exchange_id");
2758 MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
2759 MODULE_ALIAS("nfs4");
2761 #endif /* CONFIG_NFS_V4 */