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"
67 #include "nfs4session.h"
71 #define NFSDBG_FACILITY NFSDBG_VFS
72 #define NFS_TEXT_DATA 1
74 #if IS_ENABLED(CONFIG_NFS_V3)
75 #define NFS_DEFAULT_VERSION 3
77 #define NFS_DEFAULT_VERSION 2
81 /* Mount options that take no arguments */
83 Opt_posix, Opt_noposix,
87 Opt_udp, Opt_tcp, Opt_rdma,
89 Opt_rdirplus, Opt_nordirplus,
90 Opt_sharecache, Opt_nosharecache,
91 Opt_resvport, Opt_noresvport,
92 Opt_fscache, Opt_nofscache,
93 Opt_migration, Opt_nomigration,
95 /* Mount options that take integer arguments */
97 Opt_rsize, Opt_wsize, Opt_bsize,
98 Opt_timeo, Opt_retrans,
99 Opt_acregmin, Opt_acregmax,
100 Opt_acdirmin, Opt_acdirmax,
107 /* Mount options that take string arguments */
109 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
110 Opt_addr, Opt_mountaddr, Opt_clientaddr,
115 /* Special mount options */
116 Opt_userspace, Opt_deprecated, Opt_sloppy,
121 static const match_table_t nfs_mount_option_tokens = {
122 { Opt_userspace, "bg" },
123 { Opt_userspace, "fg" },
124 { Opt_userspace, "retry=%s" },
126 { Opt_sloppy, "sloppy" },
128 { Opt_soft, "soft" },
129 { Opt_hard, "hard" },
130 { Opt_deprecated, "intr" },
131 { Opt_deprecated, "nointr" },
132 { Opt_posix, "posix" },
133 { Opt_noposix, "noposix" },
135 { Opt_nocto, "nocto" },
137 { Opt_noac, "noac" },
138 { Opt_lock, "lock" },
139 { Opt_nolock, "nolock" },
142 { Opt_rdma, "rdma" },
144 { Opt_noacl, "noacl" },
145 { Opt_rdirplus, "rdirplus" },
146 { Opt_nordirplus, "nordirplus" },
147 { Opt_sharecache, "sharecache" },
148 { Opt_nosharecache, "nosharecache" },
149 { Opt_resvport, "resvport" },
150 { Opt_noresvport, "noresvport" },
151 { Opt_fscache, "fsc" },
152 { Opt_nofscache, "nofsc" },
153 { Opt_migration, "migration" },
154 { Opt_nomigration, "nomigration" },
156 { Opt_port, "port=%s" },
157 { Opt_rsize, "rsize=%s" },
158 { Opt_wsize, "wsize=%s" },
159 { Opt_bsize, "bsize=%s" },
160 { Opt_timeo, "timeo=%s" },
161 { Opt_retrans, "retrans=%s" },
162 { Opt_acregmin, "acregmin=%s" },
163 { Opt_acregmax, "acregmax=%s" },
164 { Opt_acdirmin, "acdirmin=%s" },
165 { Opt_acdirmax, "acdirmax=%s" },
166 { Opt_actimeo, "actimeo=%s" },
167 { Opt_namelen, "namlen=%s" },
168 { Opt_mountport, "mountport=%s" },
169 { Opt_mountvers, "mountvers=%s" },
170 { Opt_minorversion, "minorversion=%s" },
172 { Opt_nfsvers, "nfsvers=%s" },
173 { Opt_nfsvers, "vers=%s" },
175 { Opt_sec, "sec=%s" },
176 { Opt_proto, "proto=%s" },
177 { Opt_mountproto, "mountproto=%s" },
178 { Opt_addr, "addr=%s" },
179 { Opt_clientaddr, "clientaddr=%s" },
180 { Opt_mounthost, "mounthost=%s" },
181 { Opt_mountaddr, "mountaddr=%s" },
183 { Opt_lookupcache, "lookupcache=%s" },
184 { Opt_fscache_uniq, "fsc=%s" },
185 { Opt_local_lock, "local_lock=%s" },
187 /* The following needs to be listed after all other options */
188 { Opt_nfsvers, "v%s" },
194 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
199 static const match_table_t nfs_xprt_protocol_tokens = {
200 { Opt_xprt_udp, "udp" },
201 { Opt_xprt_udp6, "udp6" },
202 { Opt_xprt_tcp, "tcp" },
203 { Opt_xprt_tcp6, "tcp6" },
204 { Opt_xprt_rdma, "rdma" },
206 { Opt_xprt_err, NULL }
210 Opt_sec_none, Opt_sec_sys,
211 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
212 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
213 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
218 static const match_table_t nfs_secflavor_tokens = {
219 { Opt_sec_none, "none" },
220 { Opt_sec_none, "null" },
221 { Opt_sec_sys, "sys" },
223 { Opt_sec_krb5, "krb5" },
224 { Opt_sec_krb5i, "krb5i" },
225 { Opt_sec_krb5p, "krb5p" },
227 { Opt_sec_lkey, "lkey" },
228 { Opt_sec_lkeyi, "lkeyi" },
229 { Opt_sec_lkeyp, "lkeyp" },
231 { Opt_sec_spkm, "spkm3" },
232 { Opt_sec_spkmi, "spkm3i" },
233 { Opt_sec_spkmp, "spkm3p" },
235 { Opt_sec_err, NULL }
239 Opt_lookupcache_all, Opt_lookupcache_positive,
240 Opt_lookupcache_none,
245 static match_table_t nfs_lookupcache_tokens = {
246 { Opt_lookupcache_all, "all" },
247 { Opt_lookupcache_positive, "pos" },
248 { Opt_lookupcache_positive, "positive" },
249 { Opt_lookupcache_none, "none" },
251 { Opt_lookupcache_err, NULL }
255 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
261 static match_table_t nfs_local_lock_tokens = {
262 { Opt_local_lock_all, "all" },
263 { Opt_local_lock_flock, "flock" },
264 { Opt_local_lock_posix, "posix" },
265 { Opt_local_lock_none, "none" },
267 { Opt_local_lock_err, NULL }
271 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
277 static match_table_t nfs_vers_tokens = {
281 { Opt_vers_4_0, "4.0" },
282 { Opt_vers_4_1, "4.1" },
284 { Opt_vers_err, NULL }
287 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
288 int flags, const char *dev_name, void *raw_data);
290 struct file_system_type nfs_fs_type = {
291 .owner = THIS_MODULE,
293 .mount = nfs_fs_mount,
294 .kill_sb = nfs_kill_super,
295 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
297 EXPORT_SYMBOL_GPL(nfs_fs_type);
299 struct file_system_type nfs_xdev_fs_type = {
300 .owner = THIS_MODULE,
302 .mount = nfs_xdev_mount,
303 .kill_sb = nfs_kill_super,
304 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
307 const struct super_operations nfs_sops = {
308 .alloc_inode = nfs_alloc_inode,
309 .destroy_inode = nfs_destroy_inode,
310 .write_inode = nfs_write_inode,
311 .put_super = nfs_put_super,
312 .statfs = nfs_statfs,
313 .evict_inode = nfs_evict_inode,
314 .umount_begin = nfs_umount_begin,
315 .show_options = nfs_show_options,
316 .show_devname = nfs_show_devname,
317 .show_path = nfs_show_path,
318 .show_stats = nfs_show_stats,
319 .remount_fs = nfs_remount,
321 EXPORT_SYMBOL_GPL(nfs_sops);
323 #if IS_ENABLED(CONFIG_NFS_V4)
324 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
325 static int nfs4_validate_mount_data(void *options,
326 struct nfs_parsed_mount_data *args, const char *dev_name);
328 struct file_system_type nfs4_fs_type = {
329 .owner = THIS_MODULE,
331 .mount = nfs_fs_mount,
332 .kill_sb = nfs_kill_super,
333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
335 EXPORT_SYMBOL_GPL(nfs4_fs_type);
337 static int __init register_nfs4_fs(void)
339 return register_filesystem(&nfs4_fs_type);
342 static void unregister_nfs4_fs(void)
344 unregister_filesystem(&nfs4_fs_type);
347 static int __init register_nfs4_fs(void)
352 static void unregister_nfs4_fs(void)
357 static struct shrinker acl_shrinker = {
358 .shrink = nfs_access_cache_shrinker,
359 .seeks = DEFAULT_SEEKS,
363 * Register the NFS filesystems
365 int __init register_nfs_fs(void)
369 ret = register_filesystem(&nfs_fs_type);
373 ret = register_nfs4_fs();
377 ret = nfs_register_sysctl();
380 register_shrinker(&acl_shrinker);
384 unregister_nfs4_fs();
386 unregister_filesystem(&nfs_fs_type);
392 * Unregister the NFS filesystems
394 void __exit unregister_nfs_fs(void)
396 unregister_shrinker(&acl_shrinker);
397 nfs_unregister_sysctl();
398 unregister_nfs4_fs();
399 unregister_filesystem(&nfs_fs_type);
402 void nfs_sb_active(struct super_block *sb)
404 struct nfs_server *server = NFS_SB(sb);
406 if (atomic_inc_return(&server->active) == 1)
407 atomic_inc(&sb->s_active);
409 EXPORT_SYMBOL_GPL(nfs_sb_active);
411 void nfs_sb_deactive(struct super_block *sb)
413 struct nfs_server *server = NFS_SB(sb);
415 if (atomic_dec_and_test(&server->active))
416 deactivate_super(sb);
418 EXPORT_SYMBOL_GPL(nfs_sb_deactive);
420 static int nfs_deactivate_super_async_work(void *ptr)
422 struct super_block *sb = ptr;
424 deactivate_super(sb);
425 module_put_and_exit(0);
430 * same effect as deactivate_super, but will do final unmount in kthread
433 static void nfs_deactivate_super_async(struct super_block *sb)
435 struct task_struct *task;
436 char buf[INET6_ADDRSTRLEN + 1];
437 struct nfs_server *server = NFS_SB(sb);
438 struct nfs_client *clp = server->nfs_client;
440 if (!atomic_add_unless(&sb->s_active, -1, 1)) {
442 snprintf(buf, sizeof(buf),
443 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
446 __module_get(THIS_MODULE);
447 task = kthread_run(nfs_deactivate_super_async_work, sb,
448 "%s-deactivate-super", buf);
450 pr_err("%s: kthread_run: %ld\n",
451 __func__, PTR_ERR(task));
452 /* make synchronous call and hope for the best */
453 deactivate_super(sb);
454 module_put(THIS_MODULE);
459 void nfs_sb_deactive_async(struct super_block *sb)
461 struct nfs_server *server = NFS_SB(sb);
463 if (atomic_dec_and_test(&server->active))
464 nfs_deactivate_super_async(sb);
466 EXPORT_SYMBOL_GPL(nfs_sb_deactive_async);
469 * Deliver file system statistics to userspace
471 int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
473 struct nfs_server *server = NFS_SB(dentry->d_sb);
474 unsigned char blockbits;
475 unsigned long blockres;
476 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
477 struct nfs_fsstat res;
480 res.fattr = nfs_alloc_fattr();
481 if (res.fattr == NULL)
484 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
485 if (unlikely(error == -ESTALE)) {
486 struct dentry *pd_dentry;
488 pd_dentry = dget_parent(dentry);
489 if (pd_dentry != NULL) {
490 nfs_zap_caches(pd_dentry->d_inode);
494 nfs_free_fattr(res.fattr);
498 buf->f_type = NFS_SUPER_MAGIC;
501 * Current versions of glibc do not correctly handle the
502 * case where f_frsize != f_bsize. Eventually we want to
503 * report the value of wtmult in this field.
505 buf->f_frsize = dentry->d_sb->s_blocksize;
508 * On most *nix systems, f_blocks, f_bfree, and f_bavail
509 * are reported in units of f_frsize. Linux hasn't had
510 * an f_frsize field in its statfs struct until recently,
511 * thus historically Linux's sys_statfs reports these
512 * fields in units of f_bsize.
514 buf->f_bsize = dentry->d_sb->s_blocksize;
515 blockbits = dentry->d_sb->s_blocksize_bits;
516 blockres = (1 << blockbits) - 1;
517 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
518 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
519 buf->f_bavail = (res.abytes + blockres) >> blockbits;
521 buf->f_files = res.tfiles;
522 buf->f_ffree = res.afiles;
524 buf->f_namelen = server->namelen;
529 dprintk("%s: statfs error = %d\n", __func__, -error);
532 EXPORT_SYMBOL_GPL(nfs_statfs);
535 * Map the security flavour number to a name
537 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
539 static const struct {
540 rpc_authflavor_t flavour;
543 { RPC_AUTH_NULL, "null" },
544 { RPC_AUTH_UNIX, "sys" },
545 { RPC_AUTH_GSS_KRB5, "krb5" },
546 { RPC_AUTH_GSS_KRB5I, "krb5i" },
547 { RPC_AUTH_GSS_KRB5P, "krb5p" },
548 { RPC_AUTH_GSS_LKEY, "lkey" },
549 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
550 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
551 { RPC_AUTH_GSS_SPKM, "spkm" },
552 { RPC_AUTH_GSS_SPKMI, "spkmi" },
553 { RPC_AUTH_GSS_SPKMP, "spkmp" },
554 { UINT_MAX, "unknown" }
558 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
559 if (sec_flavours[i].flavour == flavour)
562 return sec_flavours[i].str;
565 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
568 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
570 seq_printf(m, ",mountproto=");
571 switch (sap->sa_family) {
573 switch (nfss->mountd_protocol) {
575 seq_printf(m, RPCBIND_NETID_UDP);
578 seq_printf(m, RPCBIND_NETID_TCP);
582 seq_printf(m, "auto");
586 switch (nfss->mountd_protocol) {
588 seq_printf(m, RPCBIND_NETID_UDP6);
591 seq_printf(m, RPCBIND_NETID_TCP6);
595 seq_printf(m, "auto");
600 seq_printf(m, "auto");
604 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
607 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
609 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
612 switch (sap->sa_family) {
614 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
615 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
619 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
620 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
625 seq_printf(m, ",mountaddr=unspecified");
628 if (nfss->mountd_version || showdefaults)
629 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
630 if ((nfss->mountd_port &&
631 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
633 seq_printf(m, ",mountport=%u", nfss->mountd_port);
635 nfs_show_mountd_netid(m, nfss, showdefaults);
638 #if IS_ENABLED(CONFIG_NFS_V4)
639 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
642 struct nfs_client *clp = nfss->nfs_client;
644 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
647 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
653 static void nfs_show_nfs_version(struct seq_file *m,
654 unsigned int version,
655 unsigned int minorversion)
657 seq_printf(m, ",vers=%u", version);
659 seq_printf(m, ".%u", minorversion);
663 * Describe the mount options in force on this server representation
665 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
668 static const struct proc_nfs_info {
673 { NFS_MOUNT_SOFT, ",soft", ",hard" },
674 { NFS_MOUNT_POSIX, ",posix", "" },
675 { NFS_MOUNT_NOCTO, ",nocto", "" },
676 { NFS_MOUNT_NOAC, ",noac", "" },
677 { NFS_MOUNT_NONLM, ",nolock", "" },
678 { NFS_MOUNT_NOACL, ",noacl", "" },
679 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
680 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
681 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
684 const struct proc_nfs_info *nfs_infop;
685 struct nfs_client *clp = nfss->nfs_client;
686 u32 version = clp->rpc_ops->version;
687 int local_flock, local_fcntl;
689 nfs_show_nfs_version(m, version, clp->cl_minorversion);
690 seq_printf(m, ",rsize=%u", nfss->rsize);
691 seq_printf(m, ",wsize=%u", nfss->wsize);
692 if (nfss->bsize != 0)
693 seq_printf(m, ",bsize=%u", nfss->bsize);
694 seq_printf(m, ",namlen=%u", nfss->namelen);
695 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
696 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
697 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
698 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
699 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
700 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
701 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
702 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
703 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
704 if (nfss->flags & nfs_infop->flag)
705 seq_puts(m, nfs_infop->str);
707 seq_puts(m, nfs_infop->nostr);
710 seq_printf(m, ",proto=%s",
711 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
714 if (nfss->port != NFS_PORT)
715 seq_printf(m, ",port=%u", nfss->port);
718 seq_printf(m, ",port=%u", nfss->port);
720 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
721 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
722 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
725 nfs_show_mountd_options(m, nfss, showdefaults);
727 nfs_show_nfsv4_options(m, nfss, showdefaults);
729 if (nfss->options & NFS_OPTION_FSCACHE)
730 seq_printf(m, ",fsc");
732 if (nfss->options & NFS_OPTION_MIGRATION)
733 seq_printf(m, ",migration");
735 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
736 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
737 seq_printf(m, ",lookupcache=none");
739 seq_printf(m, ",lookupcache=pos");
742 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
743 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
745 if (!local_flock && !local_fcntl)
746 seq_printf(m, ",local_lock=none");
747 else if (local_flock && local_fcntl)
748 seq_printf(m, ",local_lock=all");
749 else if (local_flock)
750 seq_printf(m, ",local_lock=flock");
752 seq_printf(m, ",local_lock=posix");
756 * Describe the mount options on this VFS mountpoint
758 int nfs_show_options(struct seq_file *m, struct dentry *root)
760 struct nfs_server *nfss = NFS_SB(root->d_sb);
762 nfs_show_mount_options(m, nfss, 0);
765 seq_printf(m, ",addr=%s",
766 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
772 EXPORT_SYMBOL_GPL(nfs_show_options);
774 #if IS_ENABLED(CONFIG_NFS_V4)
775 #ifdef CONFIG_NFS_V4_1
776 static void show_sessions(struct seq_file *m, struct nfs_server *server)
778 if (nfs4_has_session(server->nfs_client))
779 seq_printf(m, ",sessions");
782 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
786 #ifdef CONFIG_NFS_V4_1
787 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
789 seq_printf(m, ",pnfs=");
790 if (server->pnfs_curr_ld)
791 seq_printf(m, "%s", server->pnfs_curr_ld->name);
793 seq_printf(m, "not configured");
796 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
798 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
799 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
800 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
802 impl_id->name, impl_id->domain,
803 impl_id->date.seconds, impl_id->date.nseconds);
807 #if IS_ENABLED(CONFIG_NFS_V4)
808 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
812 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
817 int nfs_show_devname(struct seq_file *m, struct dentry *root)
819 char *page = (char *) __get_free_page(GFP_KERNEL);
820 char *devname, *dummy;
824 devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
826 err = PTR_ERR(devname);
828 seq_escape(m, devname, " \t\n\\");
829 free_page((unsigned long)page);
832 EXPORT_SYMBOL_GPL(nfs_show_devname);
834 int nfs_show_path(struct seq_file *m, struct dentry *dentry)
839 EXPORT_SYMBOL_GPL(nfs_show_path);
842 * Present statistical information for this VFS mountpoint
844 int nfs_show_stats(struct seq_file *m, struct dentry *root)
847 struct nfs_server *nfss = NFS_SB(root->d_sb);
848 struct rpc_auth *auth = nfss->client->cl_auth;
849 struct nfs_iostats totals = { };
851 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
854 * Display all mount option settings
856 seq_printf(m, "\n\topts:\t");
857 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
858 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
859 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
860 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
861 nfs_show_mount_options(m, nfss, 1);
863 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
865 show_implementation_id(m, nfss);
867 seq_printf(m, "\n\tcaps:\t");
868 seq_printf(m, "caps=0x%x", nfss->caps);
869 seq_printf(m, ",wtmult=%u", nfss->wtmult);
870 seq_printf(m, ",dtsize=%u", nfss->dtsize);
871 seq_printf(m, ",bsize=%u", nfss->bsize);
872 seq_printf(m, ",namlen=%u", nfss->namelen);
874 #if IS_ENABLED(CONFIG_NFS_V4)
875 if (nfss->nfs_client->rpc_ops->version == 4) {
876 seq_printf(m, "\n\tnfsv4:\t");
877 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
878 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
879 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
880 show_sessions(m, nfss);
886 * Display security flavor in effect for this mount
888 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
890 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
893 * Display superblock I/O counters
895 for_each_possible_cpu(cpu) {
896 struct nfs_iostats *stats;
899 stats = per_cpu_ptr(nfss->io_stats, cpu);
901 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
902 totals.events[i] += stats->events[i];
903 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
904 totals.bytes[i] += stats->bytes[i];
905 #ifdef CONFIG_NFS_FSCACHE
906 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
907 totals.fscache[i] += stats->fscache[i];
913 seq_printf(m, "\n\tevents:\t");
914 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
915 seq_printf(m, "%lu ", totals.events[i]);
916 seq_printf(m, "\n\tbytes:\t");
917 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
918 seq_printf(m, "%Lu ", totals.bytes[i]);
919 #ifdef CONFIG_NFS_FSCACHE
920 if (nfss->options & NFS_OPTION_FSCACHE) {
921 seq_printf(m, "\n\tfsc:\t");
922 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
923 seq_printf(m, "%Lu ", totals.bytes[i]);
928 rpc_print_iostats(m, nfss->client);
932 EXPORT_SYMBOL_GPL(nfs_show_stats);
935 * Begin unmount by attempting to remove all automounted mountpoints we added
936 * in response to xdev traversals and referrals
938 void nfs_umount_begin(struct super_block *sb)
940 struct nfs_server *server;
941 struct rpc_clnt *rpc;
944 /* -EIO all pending I/O */
945 rpc = server->client_acl;
947 rpc_killall_tasks(rpc);
948 rpc = server->client;
950 rpc_killall_tasks(rpc);
952 EXPORT_SYMBOL_GPL(nfs_umount_begin);
954 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
956 struct nfs_parsed_mount_data *data;
958 data = kzalloc(sizeof(*data), GFP_KERNEL);
960 data->acregmin = NFS_DEF_ACREGMIN;
961 data->acregmax = NFS_DEF_ACREGMAX;
962 data->acdirmin = NFS_DEF_ACDIRMIN;
963 data->acdirmax = NFS_DEF_ACDIRMAX;
964 data->mount_server.port = NFS_UNSPEC_PORT;
965 data->nfs_server.port = NFS_UNSPEC_PORT;
966 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
967 data->auth_flavors[0] = RPC_AUTH_UNIX;
968 data->auth_flavor_len = 1;
969 data->minorversion = 0;
970 data->need_mount = true;
971 data->net = current->nsproxy->net_ns;
972 security_init_mnt_opts(&data->lsm_opts);
977 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
980 kfree(data->client_address);
981 kfree(data->mount_server.hostname);
982 kfree(data->nfs_server.export_path);
983 kfree(data->nfs_server.hostname);
984 kfree(data->fscache_uniq);
985 security_free_mnt_opts(&data->lsm_opts);
991 * Sanity-check a server address provided by the mount command.
993 * Address family must be initialized, and address must not be
994 * the ANY address for that family.
996 static int nfs_verify_server_address(struct sockaddr *addr)
998 switch (addr->sa_family) {
1000 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
1001 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
1004 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1005 return !ipv6_addr_any(sa);
1009 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
1014 * Select between a default port value and a user-specified port value.
1015 * If a zero value is set, then autobind will be used.
1017 static void nfs_set_port(struct sockaddr *sap, int *port,
1018 const unsigned short default_port)
1020 if (*port == NFS_UNSPEC_PORT)
1021 *port = default_port;
1023 rpc_set_port(sap, *port);
1027 * Sanity check the NFS transport protocol.
1030 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1032 switch (mnt->nfs_server.protocol) {
1033 case XPRT_TRANSPORT_UDP:
1034 case XPRT_TRANSPORT_TCP:
1035 case XPRT_TRANSPORT_RDMA:
1038 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1043 * For text based NFSv2/v3 mounts, the mount protocol transport default
1044 * settings should depend upon the specified NFS transport.
1046 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1048 nfs_validate_transport_protocol(mnt);
1050 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1051 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1053 switch (mnt->nfs_server.protocol) {
1054 case XPRT_TRANSPORT_UDP:
1055 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1057 case XPRT_TRANSPORT_TCP:
1058 case XPRT_TRANSPORT_RDMA:
1059 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1064 * Parse the value of the 'sec=' option.
1066 static int nfs_parse_security_flavors(char *value,
1067 struct nfs_parsed_mount_data *mnt)
1069 substring_t args[MAX_OPT_ARGS];
1071 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1073 switch (match_token(value, nfs_secflavor_tokens, args)) {
1075 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1078 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1081 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1084 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1087 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1090 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1093 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1096 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1099 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1102 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1105 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1111 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1112 mnt->auth_flavor_len = 1;
1116 static int nfs_parse_version_string(char *string,
1117 struct nfs_parsed_mount_data *mnt,
1120 mnt->flags &= ~NFS_MOUNT_VER3;
1121 switch (match_token(string, nfs_vers_tokens, args)) {
1126 mnt->flags |= NFS_MOUNT_VER3;
1130 /* Backward compatibility option. In future,
1131 * the mount program should always supply
1132 * a NFSv4 minor version number.
1138 mnt->minorversion = 0;
1142 mnt->minorversion = 1;
1150 static int nfs_get_option_str(substring_t args[], char **option)
1153 *option = match_strdup(args);
1157 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1162 string = match_strdup(args);
1165 rc = kstrtoul(string, 10, option);
1172 * Error-check and convert a string of mount options from user space into
1173 * a data structure. The whole mount string is processed; bad options are
1174 * skipped as they are encountered. If there were no errors, return 1;
1175 * otherwise return 0 (zero).
1177 static int nfs_parse_mount_options(char *raw,
1178 struct nfs_parsed_mount_data *mnt)
1180 char *p, *string, *secdata;
1181 int rc, sloppy = 0, invalid_option = 0;
1182 unsigned short protofamily = AF_UNSPEC;
1183 unsigned short mountfamily = AF_UNSPEC;
1186 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1189 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1191 secdata = alloc_secdata();
1195 rc = security_sb_copy_data(raw, secdata);
1197 goto out_security_failure;
1199 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1201 goto out_security_failure;
1203 free_secdata(secdata);
1205 while ((p = strsep(&raw, ",")) != NULL) {
1206 substring_t args[MAX_OPT_ARGS];
1207 unsigned long option;
1213 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1215 token = match_token(p, nfs_mount_option_tokens, args);
1219 * boolean options: foo/nofoo
1222 mnt->flags |= NFS_MOUNT_SOFT;
1225 mnt->flags &= ~NFS_MOUNT_SOFT;
1228 mnt->flags |= NFS_MOUNT_POSIX;
1231 mnt->flags &= ~NFS_MOUNT_POSIX;
1234 mnt->flags &= ~NFS_MOUNT_NOCTO;
1237 mnt->flags |= NFS_MOUNT_NOCTO;
1240 mnt->flags &= ~NFS_MOUNT_NOAC;
1243 mnt->flags |= NFS_MOUNT_NOAC;
1246 mnt->flags &= ~NFS_MOUNT_NONLM;
1247 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1248 NFS_MOUNT_LOCAL_FCNTL);
1251 mnt->flags |= NFS_MOUNT_NONLM;
1252 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1253 NFS_MOUNT_LOCAL_FCNTL);
1256 mnt->flags &= ~NFS_MOUNT_TCP;
1257 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1260 mnt->flags |= NFS_MOUNT_TCP;
1261 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1264 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1265 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1266 xprt_load_transport(p);
1269 mnt->flags &= ~NFS_MOUNT_NOACL;
1272 mnt->flags |= NFS_MOUNT_NOACL;
1275 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1277 case Opt_nordirplus:
1278 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1280 case Opt_sharecache:
1281 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1283 case Opt_nosharecache:
1284 mnt->flags |= NFS_MOUNT_UNSHARED;
1287 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1289 case Opt_noresvport:
1290 mnt->flags |= NFS_MOUNT_NORESVPORT;
1293 mnt->options |= NFS_OPTION_FSCACHE;
1294 kfree(mnt->fscache_uniq);
1295 mnt->fscache_uniq = NULL;
1298 mnt->options &= ~NFS_OPTION_FSCACHE;
1299 kfree(mnt->fscache_uniq);
1300 mnt->fscache_uniq = NULL;
1303 mnt->options |= NFS_OPTION_MIGRATION;
1305 case Opt_nomigration:
1306 mnt->options &= NFS_OPTION_MIGRATION;
1310 * options that take numeric values
1313 if (nfs_get_option_ul(args, &option) ||
1315 goto out_invalid_value;
1316 mnt->nfs_server.port = option;
1319 if (nfs_get_option_ul(args, &option))
1320 goto out_invalid_value;
1321 mnt->rsize = option;
1324 if (nfs_get_option_ul(args, &option))
1325 goto out_invalid_value;
1326 mnt->wsize = option;
1329 if (nfs_get_option_ul(args, &option))
1330 goto out_invalid_value;
1331 mnt->bsize = option;
1334 if (nfs_get_option_ul(args, &option) || option == 0)
1335 goto out_invalid_value;
1336 mnt->timeo = option;
1339 if (nfs_get_option_ul(args, &option) || option == 0)
1340 goto out_invalid_value;
1341 mnt->retrans = option;
1344 if (nfs_get_option_ul(args, &option))
1345 goto out_invalid_value;
1346 mnt->acregmin = option;
1349 if (nfs_get_option_ul(args, &option))
1350 goto out_invalid_value;
1351 mnt->acregmax = option;
1354 if (nfs_get_option_ul(args, &option))
1355 goto out_invalid_value;
1356 mnt->acdirmin = option;
1359 if (nfs_get_option_ul(args, &option))
1360 goto out_invalid_value;
1361 mnt->acdirmax = option;
1364 if (nfs_get_option_ul(args, &option))
1365 goto out_invalid_value;
1366 mnt->acregmin = mnt->acregmax =
1367 mnt->acdirmin = mnt->acdirmax = option;
1370 if (nfs_get_option_ul(args, &option))
1371 goto out_invalid_value;
1372 mnt->namlen = option;
1375 if (nfs_get_option_ul(args, &option) ||
1377 goto out_invalid_value;
1378 mnt->mount_server.port = option;
1381 if (nfs_get_option_ul(args, &option) ||
1382 option < NFS_MNT_VERSION ||
1383 option > NFS_MNT3_VERSION)
1384 goto out_invalid_value;
1385 mnt->mount_server.version = option;
1387 case Opt_minorversion:
1388 if (nfs_get_option_ul(args, &option))
1389 goto out_invalid_value;
1390 if (option > NFS4_MAX_MINOR_VERSION)
1391 goto out_invalid_value;
1392 mnt->minorversion = option;
1396 * options that take text values
1399 string = match_strdup(args);
1402 rc = nfs_parse_version_string(string, mnt, args);
1405 goto out_invalid_value;
1408 string = match_strdup(args);
1411 rc = nfs_parse_security_flavors(string, mnt);
1414 dfprintk(MOUNT, "NFS: unrecognized "
1415 "security flavor\n");
1420 string = match_strdup(args);
1423 token = match_token(string,
1424 nfs_xprt_protocol_tokens, args);
1426 protofamily = AF_INET;
1429 protofamily = AF_INET6;
1431 mnt->flags &= ~NFS_MOUNT_TCP;
1432 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1435 protofamily = AF_INET6;
1437 mnt->flags |= NFS_MOUNT_TCP;
1438 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1441 /* vector side protocols to TCP */
1442 mnt->flags |= NFS_MOUNT_TCP;
1443 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1444 xprt_load_transport(string);
1447 dfprintk(MOUNT, "NFS: unrecognized "
1448 "transport protocol\n");
1454 case Opt_mountproto:
1455 string = match_strdup(args);
1458 token = match_token(string,
1459 nfs_xprt_protocol_tokens, args);
1462 mountfamily = AF_INET;
1465 mountfamily = AF_INET6;
1467 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1470 mountfamily = AF_INET6;
1472 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1474 case Opt_xprt_rdma: /* not used for side protocols */
1476 dfprintk(MOUNT, "NFS: unrecognized "
1477 "transport protocol\n");
1482 string = match_strdup(args);
1485 mnt->nfs_server.addrlen =
1486 rpc_pton(mnt->net, string, strlen(string),
1488 &mnt->nfs_server.address,
1489 sizeof(mnt->nfs_server.address));
1491 if (mnt->nfs_server.addrlen == 0)
1492 goto out_invalid_address;
1494 case Opt_clientaddr:
1495 if (nfs_get_option_str(args, &mnt->client_address))
1499 if (nfs_get_option_str(args,
1500 &mnt->mount_server.hostname))
1504 string = match_strdup(args);
1507 mnt->mount_server.addrlen =
1508 rpc_pton(mnt->net, string, strlen(string),
1510 &mnt->mount_server.address,
1511 sizeof(mnt->mount_server.address));
1513 if (mnt->mount_server.addrlen == 0)
1514 goto out_invalid_address;
1516 case Opt_lookupcache:
1517 string = match_strdup(args);
1520 token = match_token(string,
1521 nfs_lookupcache_tokens, args);
1524 case Opt_lookupcache_all:
1525 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1527 case Opt_lookupcache_positive:
1528 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1529 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1531 case Opt_lookupcache_none:
1532 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1535 dfprintk(MOUNT, "NFS: invalid "
1536 "lookupcache argument\n");
1540 case Opt_fscache_uniq:
1541 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1543 mnt->options |= NFS_OPTION_FSCACHE;
1545 case Opt_local_lock:
1546 string = match_strdup(args);
1549 token = match_token(string, nfs_local_lock_tokens,
1553 case Opt_local_lock_all:
1554 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1555 NFS_MOUNT_LOCAL_FCNTL);
1557 case Opt_local_lock_flock:
1558 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1560 case Opt_local_lock_posix:
1561 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1563 case Opt_local_lock_none:
1564 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1565 NFS_MOUNT_LOCAL_FCNTL);
1568 dfprintk(MOUNT, "NFS: invalid "
1569 "local_lock argument\n");
1579 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1582 case Opt_deprecated:
1583 dfprintk(MOUNT, "NFS: ignoring mount option "
1589 dfprintk(MOUNT, "NFS: unrecognized mount option "
1594 if (!sloppy && invalid_option)
1597 if (mnt->minorversion && mnt->version != 4)
1598 goto out_minorversion_mismatch;
1600 if (mnt->options & NFS_OPTION_MIGRATION &&
1601 mnt->version != 4 && mnt->minorversion != 0)
1602 goto out_migration_misuse;
1605 * verify that any proto=/mountproto= options match the address
1606 * families in the addr=/mountaddr= options.
1608 if (protofamily != AF_UNSPEC &&
1609 protofamily != mnt->nfs_server.address.ss_family)
1610 goto out_proto_mismatch;
1612 if (mountfamily != AF_UNSPEC) {
1613 if (mnt->mount_server.addrlen) {
1614 if (mountfamily != mnt->mount_server.address.ss_family)
1615 goto out_mountproto_mismatch;
1617 if (mountfamily != mnt->nfs_server.address.ss_family)
1618 goto out_mountproto_mismatch;
1624 out_mountproto_mismatch:
1625 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1629 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1631 out_invalid_address:
1632 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1635 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1637 out_minorversion_mismatch:
1638 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1639 "minorversion=%u\n", mnt->version, mnt->minorversion);
1641 out_migration_misuse:
1643 "NFS: 'migration' not supported for this NFS version\n");
1646 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1648 out_security_failure:
1649 free_secdata(secdata);
1650 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1655 * Match the requested auth flavors with the list returned by
1656 * the server. Returns zero and sets the mount's authentication
1657 * flavor on success; returns -EACCES if server does not support
1658 * the requested flavor.
1660 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1661 struct nfs_mount_request *request)
1663 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1666 * Certain releases of Linux's mountd return an empty
1667 * flavor list. To prevent behavioral regression with
1668 * these servers (ie. rejecting mounts that used to
1669 * succeed), revert to pre-2.6.32 behavior (no checking)
1670 * if the returned flavor list is empty.
1672 if (server_authlist_len == 0)
1676 * We avoid sophisticated negotiating here, as there are
1677 * plenty of cases where we can get it wrong, providing
1678 * either too little or too much security.
1680 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1681 * flavor listed first. However, some servers list
1682 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1683 * preferred default, in args->auth_flavors[0] if user
1684 * didn't specify sec= mount option.
1686 for (i = 0; i < args->auth_flavor_len; i++)
1687 for (j = 0; j < server_authlist_len; j++)
1688 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1689 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1690 request->auth_flavs[j]);
1691 args->auth_flavors[0] = request->auth_flavs[j];
1695 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1696 nfs_umount(request);
1701 * Use the remote server's MOUNT service to request the NFS file handle
1702 * corresponding to the provided path.
1704 static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1705 struct nfs_fh *root_fh)
1707 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1708 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1709 struct nfs_mount_request request = {
1710 .sap = (struct sockaddr *)
1711 &args->mount_server.address,
1712 .dirpath = args->nfs_server.export_path,
1713 .protocol = args->mount_server.protocol,
1715 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1716 .auth_flav_len = &server_authlist_len,
1717 .auth_flavs = server_authlist,
1722 if (args->mount_server.version == 0) {
1723 switch (args->version) {
1725 args->mount_server.version = NFS_MNT3_VERSION;
1728 args->mount_server.version = NFS_MNT_VERSION;
1731 request.version = args->mount_server.version;
1733 if (args->mount_server.hostname)
1734 request.hostname = args->mount_server.hostname;
1736 request.hostname = args->nfs_server.hostname;
1739 * Construct the mount server's address.
1741 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1742 memcpy(request.sap, &args->nfs_server.address,
1743 args->nfs_server.addrlen);
1744 args->mount_server.addrlen = args->nfs_server.addrlen;
1746 request.salen = args->mount_server.addrlen;
1747 nfs_set_port(request.sap, &args->mount_server.port, 0);
1750 * Now ask the mount server to map our export path
1753 status = nfs_mount(&request);
1755 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1756 request.hostname, status);
1761 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1763 if (args->mount_server.version != NFS_MNT3_VERSION)
1765 return nfs_walk_authlist(args, &request);
1768 struct dentry *nfs_try_mount(int flags, const char *dev_name,
1769 struct nfs_mount_info *mount_info,
1770 struct nfs_subversion *nfs_mod)
1773 struct nfs_server *server;
1775 if (mount_info->parsed->need_mount) {
1776 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
1778 return ERR_PTR(status);
1781 /* Get a volume representation */
1782 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
1784 return ERR_CAST(server);
1786 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
1788 EXPORT_SYMBOL_GPL(nfs_try_mount);
1791 * Split "dev_name" into "hostname:export_path".
1793 * The leftmost colon demarks the split between the server's hostname
1794 * and the export path. If the hostname starts with a left square
1795 * bracket, then it may contain colons.
1797 * Note: caller frees hostname and export path, even on error.
1799 static int nfs_parse_devname(const char *dev_name,
1800 char **hostname, size_t maxnamlen,
1801 char **export_path, size_t maxpathlen)
1806 /* Is the host name protected with square brakcets? */
1807 if (*dev_name == '[') {
1808 end = strchr(++dev_name, ']');
1809 if (end == NULL || end[1] != ':')
1810 goto out_bad_devname;
1812 len = end - dev_name;
1817 end = strchr(dev_name, ':');
1819 goto out_bad_devname;
1820 len = end - dev_name;
1822 /* kill possible hostname list: not supported */
1823 comma = strchr(dev_name, ',');
1824 if (comma != NULL && comma < end)
1828 if (len > maxnamlen)
1831 /* N.B. caller will free nfs_server.hostname in all cases */
1832 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1833 if (*hostname == NULL)
1835 len = strlen(++end);
1836 if (len > maxpathlen)
1838 *export_path = kstrndup(end, len, GFP_KERNEL);
1842 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1846 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1850 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1854 dfprintk(MOUNT, "NFS: server hostname too long\n");
1855 return -ENAMETOOLONG;
1858 dfprintk(MOUNT, "NFS: export pathname too long\n");
1859 return -ENAMETOOLONG;
1863 * Validate the NFS2/NFS3 mount data
1864 * - fills in the mount root filehandle
1866 * For option strings, user space handles the following behaviors:
1868 * + DNS: mapping server host name to IP address ("addr=" option)
1870 * + failure mode: how to behave if a mount request can't be handled
1871 * immediately ("fg/bg" option)
1873 * + retry: how often to retry a mount request ("retry=" option)
1875 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1876 * mountproto=tcp after mountproto=udp, and so on
1878 static int nfs23_validate_mount_data(void *options,
1879 struct nfs_parsed_mount_data *args,
1880 struct nfs_fh *mntfh,
1881 const char *dev_name)
1883 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1884 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1889 args->version = NFS_DEFAULT_VERSION;
1890 switch (data->version) {
1896 if (data->flags & NFS_MOUNT_VER3)
1898 data->root.size = NFS2_FHSIZE;
1899 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1901 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1904 memset(data->context, 0, sizeof(data->context));
1906 if (data->flags & NFS_MOUNT_VER3) {
1907 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1908 goto out_invalid_fh;
1909 mntfh->size = data->root.size;
1912 mntfh->size = NFS2_FHSIZE;
1917 memcpy(mntfh->data, data->root.data, mntfh->size);
1918 if (mntfh->size < sizeof(mntfh->data))
1919 memset(mntfh->data + mntfh->size, 0,
1920 sizeof(mntfh->data) - mntfh->size);
1923 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1926 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1927 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1928 args->rsize = data->rsize;
1929 args->wsize = data->wsize;
1930 args->timeo = data->timeo;
1931 args->retrans = data->retrans;
1932 args->acregmin = data->acregmin;
1933 args->acregmax = data->acregmax;
1934 args->acdirmin = data->acdirmin;
1935 args->acdirmax = data->acdirmax;
1936 args->need_mount = false;
1938 memcpy(sap, &data->addr, sizeof(data->addr));
1939 args->nfs_server.addrlen = sizeof(data->addr);
1940 args->nfs_server.port = ntohs(data->addr.sin_port);
1941 if (!nfs_verify_server_address(sap))
1942 goto out_no_address;
1944 if (!(data->flags & NFS_MOUNT_TCP))
1945 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1946 /* N.B. caller will free nfs_server.hostname in all cases */
1947 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1948 args->namlen = data->namlen;
1949 args->bsize = data->bsize;
1951 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1952 args->auth_flavors[0] = data->pseudoflavor;
1953 if (!args->nfs_server.hostname)
1956 if (!(data->flags & NFS_MOUNT_NONLM))
1957 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1958 NFS_MOUNT_LOCAL_FCNTL);
1960 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1961 NFS_MOUNT_LOCAL_FCNTL);
1963 * The legacy version 6 binary mount data from userspace has a
1964 * field used only to transport selinux information into the
1965 * the kernel. To continue to support that functionality we
1966 * have a touch of selinux knowledge here in the NFS code. The
1967 * userspace code converted context=blah to just blah so we are
1968 * converting back to the full string selinux understands.
1970 if (data->context[0]){
1971 #ifdef CONFIG_SECURITY_SELINUX
1973 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1976 strcpy(opts_str, "context=");
1977 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1978 strcat(opts_str, &data->context[0]);
1979 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1990 return NFS_TEXT_DATA;
1993 #if !IS_ENABLED(CONFIG_NFS_V3)
1994 if (args->version == 3)
1995 goto out_v3_not_compiled;
1996 #endif /* !CONFIG_NFS_V3 */
2001 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
2005 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2010 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2013 #if !IS_ENABLED(CONFIG_NFS_V3)
2014 out_v3_not_compiled:
2015 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2016 return -EPROTONOSUPPORT;
2017 #endif /* !CONFIG_NFS_V3 */
2020 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2024 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2028 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2032 #if IS_ENABLED(CONFIG_NFS_V4)
2033 static int nfs_validate_mount_data(struct file_system_type *fs_type,
2035 struct nfs_parsed_mount_data *args,
2036 struct nfs_fh *mntfh,
2037 const char *dev_name)
2039 if (fs_type == &nfs_fs_type)
2040 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2041 return nfs4_validate_mount_data(options, args, dev_name);
2044 static int nfs_validate_mount_data(struct file_system_type *fs_type,
2046 struct nfs_parsed_mount_data *args,
2047 struct nfs_fh *mntfh,
2048 const char *dev_name)
2050 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2054 static int nfs_validate_text_mount_data(void *options,
2055 struct nfs_parsed_mount_data *args,
2056 const char *dev_name)
2059 int max_namelen = PAGE_SIZE;
2060 int max_pathlen = NFS_MAXPATHLEN;
2061 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2063 if (nfs_parse_mount_options((char *)options, args) == 0)
2066 if (!nfs_verify_server_address(sap))
2067 goto out_no_address;
2069 if (args->version == 4) {
2070 #if IS_ENABLED(CONFIG_NFS_V4)
2072 max_namelen = NFS4_MAXNAMLEN;
2073 max_pathlen = NFS4_MAXPATHLEN;
2074 nfs_validate_transport_protocol(args);
2075 nfs4_validate_mount_flags(args);
2077 goto out_v4_not_compiled;
2078 #endif /* CONFIG_NFS_V4 */
2080 nfs_set_mount_transport_protocol(args);
2082 nfs_set_port(sap, &args->nfs_server.port, port);
2084 if (args->auth_flavor_len > 1)
2087 return nfs_parse_devname(dev_name,
2088 &args->nfs_server.hostname,
2090 &args->nfs_server.export_path,
2093 #if !IS_ENABLED(CONFIG_NFS_V4)
2094 out_v4_not_compiled:
2095 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2096 return -EPROTONOSUPPORT;
2097 #endif /* !CONFIG_NFS_V4 */
2100 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2104 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2109 nfs_compare_remount_data(struct nfs_server *nfss,
2110 struct nfs_parsed_mount_data *data)
2112 if (data->flags != nfss->flags ||
2113 data->rsize != nfss->rsize ||
2114 data->wsize != nfss->wsize ||
2115 data->retrans != nfss->client->cl_timeout->to_retries ||
2116 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2117 data->acregmin != nfss->acregmin / HZ ||
2118 data->acregmax != nfss->acregmax / HZ ||
2119 data->acdirmin != nfss->acdirmin / HZ ||
2120 data->acdirmax != nfss->acdirmax / HZ ||
2121 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2122 data->nfs_server.port != nfss->port ||
2123 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2124 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2125 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2132 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2135 struct nfs_server *nfss = sb->s_fs_info;
2136 struct nfs_parsed_mount_data *data;
2137 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2138 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2139 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2142 * Userspace mount programs that send binary options generally send
2143 * them populated with default values. We have no way to know which
2144 * ones were explicitly specified. Fall back to legacy behavior and
2145 * just return success.
2147 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2148 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2149 options->version <= 6))))
2152 data = kzalloc(sizeof(*data), GFP_KERNEL);
2156 /* fill out struct with values from existing mount */
2157 data->flags = nfss->flags;
2158 data->rsize = nfss->rsize;
2159 data->wsize = nfss->wsize;
2160 data->retrans = nfss->client->cl_timeout->to_retries;
2161 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2162 data->acregmin = nfss->acregmin / HZ;
2163 data->acregmax = nfss->acregmax / HZ;
2164 data->acdirmin = nfss->acdirmin / HZ;
2165 data->acdirmax = nfss->acdirmax / HZ;
2166 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2167 data->nfs_server.port = nfss->port;
2168 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2169 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2170 data->nfs_server.addrlen);
2172 /* overwrite those values with any that were specified */
2173 error = nfs_parse_mount_options((char *)options, data);
2178 * noac is a special case. It implies -o sync, but that's not
2179 * necessarily reflected in the mtab options. do_remount_sb
2180 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2181 * remount options, so we have to explicitly reset it.
2183 if (data->flags & NFS_MOUNT_NOAC)
2184 *flags |= MS_SYNCHRONOUS;
2186 /* compare new mount options with old ones */
2187 error = nfs_compare_remount_data(nfss, data);
2192 EXPORT_SYMBOL_GPL(nfs_remount);
2195 * Initialise the common bits of the superblock
2197 inline void nfs_initialise_sb(struct super_block *sb)
2199 struct nfs_server *server = NFS_SB(sb);
2201 sb->s_magic = NFS_SUPER_MAGIC;
2203 /* We probably want something more informative here */
2204 snprintf(sb->s_id, sizeof(sb->s_id),
2205 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2207 if (sb->s_blocksize == 0)
2208 sb->s_blocksize = nfs_block_bits(server->wsize,
2209 &sb->s_blocksize_bits);
2211 sb->s_bdi = &server->backing_dev_info;
2213 nfs_super_set_maxbytes(sb, server->maxfilesize);
2217 * Finish setting up an NFS2/3 superblock
2219 void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2221 struct nfs_parsed_mount_data *data = mount_info->parsed;
2222 struct nfs_server *server = NFS_SB(sb);
2224 sb->s_blocksize_bits = 0;
2225 sb->s_blocksize = 0;
2226 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2227 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2228 if (data && data->bsize)
2229 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2231 if (server->nfs_client->rpc_ops->version != 2) {
2232 /* The VFS shouldn't apply the umask to mode bits. We will do
2233 * so ourselves when necessary.
2235 sb->s_flags |= MS_POSIXACL;
2236 sb->s_time_gran = 1;
2239 nfs_initialise_sb(sb);
2241 EXPORT_SYMBOL_GPL(nfs_fill_super);
2244 * Finish setting up a cloned NFS2/3/4 superblock
2246 void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2248 const struct super_block *old_sb = mount_info->cloned->sb;
2249 struct nfs_server *server = NFS_SB(sb);
2251 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2252 sb->s_blocksize = old_sb->s_blocksize;
2253 sb->s_maxbytes = old_sb->s_maxbytes;
2254 sb->s_xattr = old_sb->s_xattr;
2255 sb->s_op = old_sb->s_op;
2256 sb->s_time_gran = 1;
2258 if (server->nfs_client->rpc_ops->version != 2) {
2259 /* The VFS shouldn't apply the umask to mode bits. We will do
2260 * so ourselves when necessary.
2262 sb->s_flags |= MS_POSIXACL;
2265 nfs_initialise_sb(sb);
2268 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2270 const struct nfs_server *a = s->s_fs_info;
2271 const struct rpc_clnt *clnt_a = a->client;
2272 const struct rpc_clnt *clnt_b = b->client;
2274 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2276 if (a->nfs_client != b->nfs_client)
2278 if (a->flags != b->flags)
2280 if (a->wsize != b->wsize)
2282 if (a->rsize != b->rsize)
2284 if (a->acregmin != b->acregmin)
2286 if (a->acregmax != b->acregmax)
2288 if (a->acdirmin != b->acdirmin)
2290 if (a->acdirmax != b->acdirmax)
2292 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2299 struct nfs_sb_mountdata {
2300 struct nfs_server *server;
2304 static int nfs_set_super(struct super_block *s, void *data)
2306 struct nfs_sb_mountdata *sb_mntdata = data;
2307 struct nfs_server *server = sb_mntdata->server;
2310 s->s_flags = sb_mntdata->mntflags;
2311 s->s_fs_info = server;
2312 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2313 ret = set_anon_super(s, server);
2315 server->s_dev = s->s_dev;
2319 static int nfs_compare_super_address(struct nfs_server *server1,
2320 struct nfs_server *server2)
2322 struct sockaddr *sap1, *sap2;
2324 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2325 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2327 if (sap1->sa_family != sap2->sa_family)
2330 switch (sap1->sa_family) {
2332 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2333 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2334 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2336 if (sin1->sin_port != sin2->sin_port)
2341 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2342 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2343 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2345 if (sin1->sin6_port != sin2->sin6_port)
2356 static int nfs_compare_super(struct super_block *sb, void *data)
2358 struct nfs_sb_mountdata *sb_mntdata = data;
2359 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2360 int mntflags = sb_mntdata->mntflags;
2362 if (!nfs_compare_super_address(old, server))
2364 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2365 if (old->flags & NFS_MOUNT_UNSHARED)
2367 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2369 return nfs_compare_mount_options(sb, server, mntflags);
2372 #ifdef CONFIG_NFS_FSCACHE
2373 static void nfs_get_cache_cookie(struct super_block *sb,
2374 struct nfs_parsed_mount_data *parsed,
2375 struct nfs_clone_mount *cloned)
2380 if (parsed && parsed->fscache_uniq) {
2381 uniq = parsed->fscache_uniq;
2382 ulen = strlen(parsed->fscache_uniq);
2383 } else if (cloned) {
2384 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2385 if (mnt_s->fscache_key) {
2386 uniq = mnt_s->fscache_key->key.uniquifier;
2387 ulen = mnt_s->fscache_key->key.uniq_len;
2391 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2394 static void nfs_get_cache_cookie(struct super_block *sb,
2395 struct nfs_parsed_mount_data *parsed,
2396 struct nfs_clone_mount *cloned)
2401 static int nfs_bdi_register(struct nfs_server *server)
2403 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2406 int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2407 struct nfs_mount_info *mount_info)
2409 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2411 EXPORT_SYMBOL_GPL(nfs_set_sb_security);
2413 int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2414 struct nfs_mount_info *mount_info)
2416 /* clone any lsm security options from the parent to the new sb */
2417 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2418 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2422 EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
2424 struct dentry *nfs_fs_mount_common(struct nfs_server *server,
2425 int flags, const char *dev_name,
2426 struct nfs_mount_info *mount_info,
2427 struct nfs_subversion *nfs_mod)
2429 struct super_block *s;
2430 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2431 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2432 struct nfs_sb_mountdata sb_mntdata = {
2438 if (server->flags & NFS_MOUNT_UNSHARED)
2439 compare_super = NULL;
2441 /* -o noac implies -o sync */
2442 if (server->flags & NFS_MOUNT_NOAC)
2443 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2445 /* Get a superblock - note that we may end up sharing one that already exists */
2446 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
2448 mntroot = ERR_CAST(s);
2452 if (s->s_fs_info != server) {
2453 nfs_free_server(server);
2456 error = nfs_bdi_register(server);
2458 mntroot = ERR_PTR(error);
2459 goto error_splat_bdi;
2464 /* initial superblock/root creation */
2465 mount_info->fill_super(s, mount_info);
2466 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2469 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
2470 if (IS_ERR(mntroot))
2471 goto error_splat_super;
2473 error = mount_info->set_security(s, mntroot, mount_info);
2475 goto error_splat_root;
2477 s->s_flags |= MS_ACTIVE;
2483 nfs_free_server(server);
2488 mntroot = ERR_PTR(error);
2490 if (server && !s->s_root)
2491 bdi_unregister(&server->backing_dev_info);
2493 deactivate_locked_super(s);
2496 EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
2498 struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2499 int flags, const char *dev_name, void *raw_data)
2501 struct nfs_mount_info mount_info = {
2502 .fill_super = nfs_fill_super,
2503 .set_security = nfs_set_sb_security,
2505 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2506 struct nfs_subversion *nfs_mod;
2509 mount_info.parsed = nfs_alloc_parsed_mount_data();
2510 mount_info.mntfh = nfs_alloc_fhandle();
2511 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
2514 /* Validate the mount data */
2515 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
2516 if (error == NFS_TEXT_DATA)
2517 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
2519 mntroot = ERR_PTR(error);
2523 nfs_mod = get_nfs_version(mount_info.parsed->version);
2524 if (IS_ERR(nfs_mod)) {
2525 mntroot = ERR_CAST(nfs_mod);
2529 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
2531 put_nfs_version(nfs_mod);
2533 nfs_free_parsed_mount_data(mount_info.parsed);
2534 nfs_free_fhandle(mount_info.mntfh);
2537 EXPORT_SYMBOL_GPL(nfs_fs_mount);
2540 * Ensure that we unregister the bdi before kill_anon_super
2541 * releases the device name
2543 void nfs_put_super(struct super_block *s)
2545 struct nfs_server *server = NFS_SB(s);
2547 bdi_unregister(&server->backing_dev_info);
2549 EXPORT_SYMBOL_GPL(nfs_put_super);
2552 * Destroy an NFS2/3 superblock
2554 void nfs_kill_super(struct super_block *s)
2556 struct nfs_server *server = NFS_SB(s);
2559 nfs_fscache_release_super_cookie(s);
2560 nfs_free_server(server);
2562 EXPORT_SYMBOL_GPL(nfs_kill_super);
2565 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2567 static struct dentry *
2568 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2569 const char *dev_name, void *raw_data)
2571 struct nfs_clone_mount *data = raw_data;
2572 struct nfs_mount_info mount_info = {
2573 .fill_super = nfs_clone_super,
2574 .set_security = nfs_clone_sb_security,
2577 struct nfs_server *server;
2578 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2579 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
2582 dprintk("--> nfs_xdev_mount_common()\n");
2584 mount_info.mntfh = mount_info.cloned->fh;
2586 /* create a new volume representation */
2587 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2588 if (IS_ERR(server)) {
2589 error = PTR_ERR(server);
2593 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
2594 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2599 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2603 #if IS_ENABLED(CONFIG_NFS_V4)
2605 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2607 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2608 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2612 * Validate NFSv4 mount options
2614 static int nfs4_validate_mount_data(void *options,
2615 struct nfs_parsed_mount_data *args,
2616 const char *dev_name)
2618 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2619 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2627 switch (data->version) {
2629 if (data->host_addrlen > sizeof(args->nfs_server.address))
2630 goto out_no_address;
2631 if (data->host_addrlen == 0)
2632 goto out_no_address;
2633 args->nfs_server.addrlen = data->host_addrlen;
2634 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2636 if (!nfs_verify_server_address(sap))
2637 goto out_no_address;
2638 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
2640 if (data->auth_flavourlen) {
2641 if (data->auth_flavourlen > 1)
2642 goto out_inval_auth;
2643 if (copy_from_user(&args->auth_flavors[0],
2644 data->auth_flavours,
2645 sizeof(args->auth_flavors[0])))
2649 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2652 args->nfs_server.hostname = c;
2654 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2657 args->nfs_server.export_path = c;
2658 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2660 c = strndup_user(data->client_addr.data, 16);
2663 args->client_address = c;
2666 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2670 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2671 args->rsize = data->rsize;
2672 args->wsize = data->wsize;
2673 args->timeo = data->timeo;
2674 args->retrans = data->retrans;
2675 args->acregmin = data->acregmin;
2676 args->acregmax = data->acregmax;
2677 args->acdirmin = data->acdirmin;
2678 args->acdirmax = data->acdirmax;
2679 args->nfs_server.protocol = data->proto;
2680 nfs_validate_transport_protocol(args);
2684 return NFS_TEXT_DATA;
2690 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2694 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2695 data->auth_flavourlen);
2699 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2704 * NFS v4 module parameters need to stay in the
2705 * NFS client for backwards compatibility
2707 unsigned int nfs_callback_set_tcpport;
2708 unsigned short nfs_callback_tcpport;
2709 /* Default cache timeout is 10 minutes */
2710 unsigned int nfs_idmap_cache_timeout = 600;
2711 /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2712 bool nfs4_disable_idmapping = true;
2713 unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2714 unsigned short send_implementation_id = 1;
2715 char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
2717 EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2718 EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2719 EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2720 EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2721 EXPORT_SYMBOL_GPL(max_session_slots);
2722 EXPORT_SYMBOL_GPL(send_implementation_id);
2723 EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
2725 #define NFS_CALLBACK_MAXPORTNR (65535U)
2727 static int param_set_portnr(const char *val, const struct kernel_param *kp)
2734 ret = kstrtoul(val, 0, &num);
2735 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2737 *((unsigned int *)kp->arg) = num;
2740 static struct kernel_param_ops param_ops_portnr = {
2741 .set = param_set_portnr,
2742 .get = param_get_uint,
2744 #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2746 module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2747 module_param(nfs_idmap_cache_timeout, int, 0644);
2748 module_param(nfs4_disable_idmapping, bool, 0644);
2749 module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
2750 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
2751 MODULE_PARM_DESC(nfs4_disable_idmapping,
2752 "Turn off NFSv4 idmapping when using 'sec=sys'");
2753 module_param(max_session_slots, ushort, 0644);
2754 MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2755 "requests the client will negotiate");
2756 module_param(send_implementation_id, ushort, 0644);
2757 MODULE_PARM_DESC(send_implementation_id,
2758 "Send implementation ID with NFSv4.1 exchange_id");
2759 MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
2760 MODULE_ALIAS("nfs4");
2762 #endif /* CONFIG_NFS_V4 */