4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/namei.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
49 #include <linux/slab.h>
51 #include <linux/netdevice.h>
52 #include <linux/nfs_xdr.h>
53 #include <linux/magic.h>
54 #include <linux/parser.h>
55 #include <linux/nsproxy.h>
56 #include <linux/rcupdate.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
69 #define NFSDBG_FACILITY NFSDBG_VFS
70 #define NFS_TEXT_DATA 1
72 #if IS_ENABLED(CONFIG_NFS_V3)
73 #define NFS_DEFAULT_VERSION 3
75 #define NFS_DEFAULT_VERSION 2
79 /* Mount options that take no arguments */
81 Opt_posix, Opt_noposix,
85 Opt_udp, Opt_tcp, Opt_rdma,
87 Opt_rdirplus, Opt_nordirplus,
88 Opt_sharecache, Opt_nosharecache,
89 Opt_resvport, Opt_noresvport,
90 Opt_fscache, Opt_nofscache,
91 Opt_migration, Opt_nomigration,
93 /* Mount options that take integer arguments */
95 Opt_rsize, Opt_wsize, Opt_bsize,
96 Opt_timeo, Opt_retrans,
97 Opt_acregmin, Opt_acregmax,
98 Opt_acdirmin, Opt_acdirmax,
105 /* Mount options that take string arguments */
107 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
108 Opt_addr, Opt_mountaddr, Opt_clientaddr,
113 /* Special mount options */
114 Opt_userspace, Opt_deprecated, Opt_sloppy,
119 static const match_table_t nfs_mount_option_tokens = {
120 { Opt_userspace, "bg" },
121 { Opt_userspace, "fg" },
122 { Opt_userspace, "retry=%s" },
124 { Opt_sloppy, "sloppy" },
126 { Opt_soft, "soft" },
127 { Opt_hard, "hard" },
128 { Opt_deprecated, "intr" },
129 { Opt_deprecated, "nointr" },
130 { Opt_posix, "posix" },
131 { Opt_noposix, "noposix" },
133 { Opt_nocto, "nocto" },
135 { Opt_noac, "noac" },
136 { Opt_lock, "lock" },
137 { Opt_nolock, "nolock" },
140 { Opt_rdma, "rdma" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
149 { Opt_fscache, "fsc" },
150 { Opt_nofscache, "nofsc" },
151 { Opt_migration, "migration" },
152 { Opt_nomigration, "nomigration" },
154 { Opt_port, "port=%s" },
155 { Opt_rsize, "rsize=%s" },
156 { Opt_wsize, "wsize=%s" },
157 { Opt_bsize, "bsize=%s" },
158 { Opt_timeo, "timeo=%s" },
159 { Opt_retrans, "retrans=%s" },
160 { Opt_acregmin, "acregmin=%s" },
161 { Opt_acregmax, "acregmax=%s" },
162 { Opt_acdirmin, "acdirmin=%s" },
163 { Opt_acdirmax, "acdirmax=%s" },
164 { Opt_actimeo, "actimeo=%s" },
165 { Opt_namelen, "namlen=%s" },
166 { Opt_mountport, "mountport=%s" },
167 { Opt_mountvers, "mountvers=%s" },
168 { Opt_minorversion, "minorversion=%s" },
170 { Opt_nfsvers, "nfsvers=%s" },
171 { Opt_nfsvers, "vers=%s" },
173 { Opt_sec, "sec=%s" },
174 { Opt_proto, "proto=%s" },
175 { Opt_mountproto, "mountproto=%s" },
176 { Opt_addr, "addr=%s" },
177 { Opt_clientaddr, "clientaddr=%s" },
178 { Opt_mounthost, "mounthost=%s" },
179 { Opt_mountaddr, "mountaddr=%s" },
181 { Opt_lookupcache, "lookupcache=%s" },
182 { Opt_fscache_uniq, "fsc=%s" },
183 { Opt_local_lock, "local_lock=%s" },
185 /* The following needs to be listed after all other options */
186 { Opt_nfsvers, "v%s" },
192 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
197 static const match_table_t nfs_xprt_protocol_tokens = {
198 { Opt_xprt_udp, "udp" },
199 { Opt_xprt_udp6, "udp6" },
200 { Opt_xprt_tcp, "tcp" },
201 { Opt_xprt_tcp6, "tcp6" },
202 { Opt_xprt_rdma, "rdma" },
204 { Opt_xprt_err, NULL }
208 Opt_sec_none, Opt_sec_sys,
209 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
210 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
211 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
216 static const match_table_t nfs_secflavor_tokens = {
217 { Opt_sec_none, "none" },
218 { Opt_sec_none, "null" },
219 { Opt_sec_sys, "sys" },
221 { Opt_sec_krb5, "krb5" },
222 { Opt_sec_krb5i, "krb5i" },
223 { Opt_sec_krb5p, "krb5p" },
225 { Opt_sec_lkey, "lkey" },
226 { Opt_sec_lkeyi, "lkeyi" },
227 { Opt_sec_lkeyp, "lkeyp" },
229 { Opt_sec_spkm, "spkm3" },
230 { Opt_sec_spkmi, "spkm3i" },
231 { Opt_sec_spkmp, "spkm3p" },
233 { Opt_sec_err, NULL }
237 Opt_lookupcache_all, Opt_lookupcache_positive,
238 Opt_lookupcache_none,
243 static match_table_t nfs_lookupcache_tokens = {
244 { Opt_lookupcache_all, "all" },
245 { Opt_lookupcache_positive, "pos" },
246 { Opt_lookupcache_positive, "positive" },
247 { Opt_lookupcache_none, "none" },
249 { Opt_lookupcache_err, NULL }
253 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
259 static match_table_t nfs_local_lock_tokens = {
260 { Opt_local_lock_all, "all" },
261 { Opt_local_lock_flock, "flock" },
262 { Opt_local_lock_posix, "posix" },
263 { Opt_local_lock_none, "none" },
265 { Opt_local_lock_err, NULL }
269 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
275 static match_table_t nfs_vers_tokens = {
279 { Opt_vers_4_0, "4.0" },
280 { Opt_vers_4_1, "4.1" },
282 { Opt_vers_err, NULL }
285 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data);
288 struct file_system_type nfs_fs_type = {
289 .owner = THIS_MODULE,
291 .mount = nfs_fs_mount,
292 .kill_sb = nfs_kill_super,
293 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
295 EXPORT_SYMBOL_GPL(nfs_fs_type);
297 struct file_system_type nfs_xdev_fs_type = {
298 .owner = THIS_MODULE,
300 .mount = nfs_xdev_mount,
301 .kill_sb = nfs_kill_super,
302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
305 const struct super_operations nfs_sops = {
306 .alloc_inode = nfs_alloc_inode,
307 .destroy_inode = nfs_destroy_inode,
308 .write_inode = nfs_write_inode,
309 .put_super = nfs_put_super,
310 .statfs = nfs_statfs,
311 .evict_inode = nfs_evict_inode,
312 .umount_begin = nfs_umount_begin,
313 .show_options = nfs_show_options,
314 .show_devname = nfs_show_devname,
315 .show_path = nfs_show_path,
316 .show_stats = nfs_show_stats,
317 .remount_fs = nfs_remount,
319 EXPORT_SYMBOL_GPL(nfs_sops);
321 #if IS_ENABLED(CONFIG_NFS_V4)
322 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
323 static int nfs4_validate_mount_data(void *options,
324 struct nfs_parsed_mount_data *args, const char *dev_name);
326 struct file_system_type nfs4_fs_type = {
327 .owner = THIS_MODULE,
329 .mount = nfs_fs_mount,
330 .kill_sb = nfs_kill_super,
331 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
333 EXPORT_SYMBOL_GPL(nfs4_fs_type);
335 static int __init register_nfs4_fs(void)
337 return register_filesystem(&nfs4_fs_type);
340 static void unregister_nfs4_fs(void)
342 unregister_filesystem(&nfs4_fs_type);
345 static int __init register_nfs4_fs(void)
350 static void unregister_nfs4_fs(void)
355 static struct shrinker acl_shrinker = {
356 .shrink = nfs_access_cache_shrinker,
357 .seeks = DEFAULT_SEEKS,
361 * Register the NFS filesystems
363 int __init register_nfs_fs(void)
367 ret = register_filesystem(&nfs_fs_type);
371 ret = register_nfs4_fs();
375 ret = nfs_register_sysctl();
378 register_shrinker(&acl_shrinker);
382 unregister_nfs4_fs();
384 unregister_filesystem(&nfs_fs_type);
390 * Unregister the NFS filesystems
392 void __exit unregister_nfs_fs(void)
394 unregister_shrinker(&acl_shrinker);
395 nfs_unregister_sysctl();
396 unregister_nfs4_fs();
397 unregister_filesystem(&nfs_fs_type);
400 void nfs_sb_active(struct super_block *sb)
402 struct nfs_server *server = NFS_SB(sb);
404 if (atomic_inc_return(&server->active) == 1)
405 atomic_inc(&sb->s_active);
407 EXPORT_SYMBOL_GPL(nfs_sb_active);
409 void nfs_sb_deactive(struct super_block *sb)
411 struct nfs_server *server = NFS_SB(sb);
413 if (atomic_dec_and_test(&server->active))
414 deactivate_super(sb);
416 EXPORT_SYMBOL_GPL(nfs_sb_deactive);
419 * Deliver file system statistics to userspace
421 int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
423 struct nfs_server *server = NFS_SB(dentry->d_sb);
424 unsigned char blockbits;
425 unsigned long blockres;
426 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
427 struct nfs_fsstat res;
430 res.fattr = nfs_alloc_fattr();
431 if (res.fattr == NULL)
434 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
435 if (unlikely(error == -ESTALE)) {
436 struct dentry *pd_dentry;
438 pd_dentry = dget_parent(dentry);
439 if (pd_dentry != NULL) {
440 nfs_zap_caches(pd_dentry->d_inode);
444 nfs_free_fattr(res.fattr);
448 buf->f_type = NFS_SUPER_MAGIC;
451 * Current versions of glibc do not correctly handle the
452 * case where f_frsize != f_bsize. Eventually we want to
453 * report the value of wtmult in this field.
455 buf->f_frsize = dentry->d_sb->s_blocksize;
458 * On most *nix systems, f_blocks, f_bfree, and f_bavail
459 * are reported in units of f_frsize. Linux hasn't had
460 * an f_frsize field in its statfs struct until recently,
461 * thus historically Linux's sys_statfs reports these
462 * fields in units of f_bsize.
464 buf->f_bsize = dentry->d_sb->s_blocksize;
465 blockbits = dentry->d_sb->s_blocksize_bits;
466 blockres = (1 << blockbits) - 1;
467 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
468 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
469 buf->f_bavail = (res.abytes + blockres) >> blockbits;
471 buf->f_files = res.tfiles;
472 buf->f_ffree = res.afiles;
474 buf->f_namelen = server->namelen;
479 dprintk("%s: statfs error = %d\n", __func__, -error);
482 EXPORT_SYMBOL_GPL(nfs_statfs);
485 * Map the security flavour number to a name
487 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
489 static const struct {
490 rpc_authflavor_t flavour;
493 { RPC_AUTH_NULL, "null" },
494 { RPC_AUTH_UNIX, "sys" },
495 { RPC_AUTH_GSS_KRB5, "krb5" },
496 { RPC_AUTH_GSS_KRB5I, "krb5i" },
497 { RPC_AUTH_GSS_KRB5P, "krb5p" },
498 { RPC_AUTH_GSS_LKEY, "lkey" },
499 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
500 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
501 { RPC_AUTH_GSS_SPKM, "spkm" },
502 { RPC_AUTH_GSS_SPKMI, "spkmi" },
503 { RPC_AUTH_GSS_SPKMP, "spkmp" },
504 { UINT_MAX, "unknown" }
508 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
509 if (sec_flavours[i].flavour == flavour)
512 return sec_flavours[i].str;
515 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
518 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
520 seq_printf(m, ",mountproto=");
521 switch (sap->sa_family) {
523 switch (nfss->mountd_protocol) {
525 seq_printf(m, RPCBIND_NETID_UDP);
528 seq_printf(m, RPCBIND_NETID_TCP);
532 seq_printf(m, "auto");
536 switch (nfss->mountd_protocol) {
538 seq_printf(m, RPCBIND_NETID_UDP6);
541 seq_printf(m, RPCBIND_NETID_TCP6);
545 seq_printf(m, "auto");
550 seq_printf(m, "auto");
554 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
557 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
559 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
562 switch (sap->sa_family) {
564 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
565 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
569 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
570 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
575 seq_printf(m, ",mountaddr=unspecified");
578 if (nfss->mountd_version || showdefaults)
579 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
580 if ((nfss->mountd_port &&
581 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
583 seq_printf(m, ",mountport=%u", nfss->mountd_port);
585 nfs_show_mountd_netid(m, nfss, showdefaults);
588 #if IS_ENABLED(CONFIG_NFS_V4)
589 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
592 struct nfs_client *clp = nfss->nfs_client;
594 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
597 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
603 static void nfs_show_nfs_version(struct seq_file *m,
604 unsigned int version,
605 unsigned int minorversion)
607 seq_printf(m, ",vers=%u", version);
609 seq_printf(m, ".%u", minorversion);
613 * Describe the mount options in force on this server representation
615 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
618 static const struct proc_nfs_info {
623 { NFS_MOUNT_SOFT, ",soft", ",hard" },
624 { NFS_MOUNT_POSIX, ",posix", "" },
625 { NFS_MOUNT_NOCTO, ",nocto", "" },
626 { NFS_MOUNT_NOAC, ",noac", "" },
627 { NFS_MOUNT_NONLM, ",nolock", "" },
628 { NFS_MOUNT_NOACL, ",noacl", "" },
629 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
630 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
631 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
634 const struct proc_nfs_info *nfs_infop;
635 struct nfs_client *clp = nfss->nfs_client;
636 u32 version = clp->rpc_ops->version;
637 int local_flock, local_fcntl;
639 nfs_show_nfs_version(m, version, clp->cl_minorversion);
640 seq_printf(m, ",rsize=%u", nfss->rsize);
641 seq_printf(m, ",wsize=%u", nfss->wsize);
642 if (nfss->bsize != 0)
643 seq_printf(m, ",bsize=%u", nfss->bsize);
644 seq_printf(m, ",namlen=%u", nfss->namelen);
645 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
646 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
647 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
648 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
649 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
650 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
651 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
652 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
653 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
654 if (nfss->flags & nfs_infop->flag)
655 seq_puts(m, nfs_infop->str);
657 seq_puts(m, nfs_infop->nostr);
660 seq_printf(m, ",proto=%s",
661 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
664 if (nfss->port != NFS_PORT)
665 seq_printf(m, ",port=%u", nfss->port);
668 seq_printf(m, ",port=%u", nfss->port);
670 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
671 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
672 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
675 nfs_show_mountd_options(m, nfss, showdefaults);
677 nfs_show_nfsv4_options(m, nfss, showdefaults);
679 if (nfss->options & NFS_OPTION_FSCACHE)
680 seq_printf(m, ",fsc");
682 if (nfss->options & NFS_OPTION_MIGRATION)
683 seq_printf(m, ",migration");
685 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
686 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
687 seq_printf(m, ",lookupcache=none");
689 seq_printf(m, ",lookupcache=pos");
692 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
693 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
695 if (!local_flock && !local_fcntl)
696 seq_printf(m, ",local_lock=none");
697 else if (local_flock && local_fcntl)
698 seq_printf(m, ",local_lock=all");
699 else if (local_flock)
700 seq_printf(m, ",local_lock=flock");
702 seq_printf(m, ",local_lock=posix");
706 * Describe the mount options on this VFS mountpoint
708 int nfs_show_options(struct seq_file *m, struct dentry *root)
710 struct nfs_server *nfss = NFS_SB(root->d_sb);
712 nfs_show_mount_options(m, nfss, 0);
715 seq_printf(m, ",addr=%s",
716 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
722 EXPORT_SYMBOL_GPL(nfs_show_options);
724 #if IS_ENABLED(CONFIG_NFS_V4)
725 #ifdef CONFIG_NFS_V4_1
726 static void show_sessions(struct seq_file *m, struct nfs_server *server)
728 if (nfs4_has_session(server->nfs_client))
729 seq_printf(m, ",sessions");
732 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
736 #ifdef CONFIG_NFS_V4_1
737 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
739 seq_printf(m, ",pnfs=");
740 if (server->pnfs_curr_ld)
741 seq_printf(m, "%s", server->pnfs_curr_ld->name);
743 seq_printf(m, "not configured");
746 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
748 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
749 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
750 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
752 impl_id->name, impl_id->domain,
753 impl_id->date.seconds, impl_id->date.nseconds);
757 #if IS_ENABLED(CONFIG_NFS_V4)
758 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
762 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
767 int nfs_show_devname(struct seq_file *m, struct dentry *root)
769 char *page = (char *) __get_free_page(GFP_KERNEL);
770 char *devname, *dummy;
774 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
776 err = PTR_ERR(devname);
778 seq_escape(m, devname, " \t\n\\");
779 free_page((unsigned long)page);
782 EXPORT_SYMBOL_GPL(nfs_show_devname);
784 int nfs_show_path(struct seq_file *m, struct dentry *dentry)
789 EXPORT_SYMBOL_GPL(nfs_show_path);
792 * Present statistical information for this VFS mountpoint
794 int nfs_show_stats(struct seq_file *m, struct dentry *root)
797 struct nfs_server *nfss = NFS_SB(root->d_sb);
798 struct rpc_auth *auth = nfss->client->cl_auth;
799 struct nfs_iostats totals = { };
801 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
804 * Display all mount option settings
806 seq_printf(m, "\n\topts:\t");
807 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
808 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
809 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
810 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
811 nfs_show_mount_options(m, nfss, 1);
813 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
815 show_implementation_id(m, nfss);
817 seq_printf(m, "\n\tcaps:\t");
818 seq_printf(m, "caps=0x%x", nfss->caps);
819 seq_printf(m, ",wtmult=%u", nfss->wtmult);
820 seq_printf(m, ",dtsize=%u", nfss->dtsize);
821 seq_printf(m, ",bsize=%u", nfss->bsize);
822 seq_printf(m, ",namlen=%u", nfss->namelen);
824 #if IS_ENABLED(CONFIG_NFS_V4)
825 if (nfss->nfs_client->rpc_ops->version == 4) {
826 seq_printf(m, "\n\tnfsv4:\t");
827 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
828 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
829 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
830 show_sessions(m, nfss);
836 * Display security flavor in effect for this mount
838 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
840 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
843 * Display superblock I/O counters
845 for_each_possible_cpu(cpu) {
846 struct nfs_iostats *stats;
849 stats = per_cpu_ptr(nfss->io_stats, cpu);
851 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
852 totals.events[i] += stats->events[i];
853 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
854 totals.bytes[i] += stats->bytes[i];
855 #ifdef CONFIG_NFS_FSCACHE
856 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
857 totals.fscache[i] += stats->fscache[i];
863 seq_printf(m, "\n\tevents:\t");
864 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
865 seq_printf(m, "%lu ", totals.events[i]);
866 seq_printf(m, "\n\tbytes:\t");
867 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
868 seq_printf(m, "%Lu ", totals.bytes[i]);
869 #ifdef CONFIG_NFS_FSCACHE
870 if (nfss->options & NFS_OPTION_FSCACHE) {
871 seq_printf(m, "\n\tfsc:\t");
872 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
873 seq_printf(m, "%Lu ", totals.bytes[i]);
878 rpc_print_iostats(m, nfss->client);
882 EXPORT_SYMBOL_GPL(nfs_show_stats);
885 * Begin unmount by attempting to remove all automounted mountpoints we added
886 * in response to xdev traversals and referrals
888 void nfs_umount_begin(struct super_block *sb)
890 struct nfs_server *server;
891 struct rpc_clnt *rpc;
894 /* -EIO all pending I/O */
895 rpc = server->client_acl;
897 rpc_killall_tasks(rpc);
898 rpc = server->client;
900 rpc_killall_tasks(rpc);
902 EXPORT_SYMBOL_GPL(nfs_umount_begin);
904 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
906 struct nfs_parsed_mount_data *data;
908 data = kzalloc(sizeof(*data), GFP_KERNEL);
910 data->acregmin = NFS_DEF_ACREGMIN;
911 data->acregmax = NFS_DEF_ACREGMAX;
912 data->acdirmin = NFS_DEF_ACDIRMIN;
913 data->acdirmax = NFS_DEF_ACDIRMAX;
914 data->mount_server.port = NFS_UNSPEC_PORT;
915 data->nfs_server.port = NFS_UNSPEC_PORT;
916 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
917 data->auth_flavors[0] = RPC_AUTH_UNIX;
918 data->auth_flavor_len = 1;
919 data->minorversion = 0;
920 data->need_mount = true;
921 data->net = current->nsproxy->net_ns;
922 security_init_mnt_opts(&data->lsm_opts);
927 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
930 kfree(data->client_address);
931 kfree(data->mount_server.hostname);
932 kfree(data->nfs_server.export_path);
933 kfree(data->nfs_server.hostname);
934 kfree(data->fscache_uniq);
935 security_free_mnt_opts(&data->lsm_opts);
941 * Sanity-check a server address provided by the mount command.
943 * Address family must be initialized, and address must not be
944 * the ANY address for that family.
946 static int nfs_verify_server_address(struct sockaddr *addr)
948 switch (addr->sa_family) {
950 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
951 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
954 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
955 return !ipv6_addr_any(sa);
959 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
964 * Select between a default port value and a user-specified port value.
965 * If a zero value is set, then autobind will be used.
967 static void nfs_set_port(struct sockaddr *sap, int *port,
968 const unsigned short default_port)
970 if (*port == NFS_UNSPEC_PORT)
971 *port = default_port;
973 rpc_set_port(sap, *port);
977 * Sanity check the NFS transport protocol.
980 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
982 switch (mnt->nfs_server.protocol) {
983 case XPRT_TRANSPORT_UDP:
984 case XPRT_TRANSPORT_TCP:
985 case XPRT_TRANSPORT_RDMA:
988 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
993 * For text based NFSv2/v3 mounts, the mount protocol transport default
994 * settings should depend upon the specified NFS transport.
996 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
998 nfs_validate_transport_protocol(mnt);
1000 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1001 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1003 switch (mnt->nfs_server.protocol) {
1004 case XPRT_TRANSPORT_UDP:
1005 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1007 case XPRT_TRANSPORT_TCP:
1008 case XPRT_TRANSPORT_RDMA:
1009 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1014 * Parse the value of the 'sec=' option.
1016 static int nfs_parse_security_flavors(char *value,
1017 struct nfs_parsed_mount_data *mnt)
1019 substring_t args[MAX_OPT_ARGS];
1021 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1023 switch (match_token(value, nfs_secflavor_tokens, args)) {
1025 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1028 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1031 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1034 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1037 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1040 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1043 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1046 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1049 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1052 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1055 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1061 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1062 mnt->auth_flavor_len = 1;
1066 static int nfs_parse_version_string(char *string,
1067 struct nfs_parsed_mount_data *mnt,
1070 mnt->flags &= ~NFS_MOUNT_VER3;
1071 switch (match_token(string, nfs_vers_tokens, args)) {
1076 mnt->flags |= NFS_MOUNT_VER3;
1080 /* Backward compatibility option. In future,
1081 * the mount program should always supply
1082 * a NFSv4 minor version number.
1088 mnt->minorversion = 0;
1092 mnt->minorversion = 1;
1100 static int nfs_get_option_str(substring_t args[], char **option)
1103 *option = match_strdup(args);
1107 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1112 string = match_strdup(args);
1115 rc = kstrtoul(string, 10, option);
1122 * Error-check and convert a string of mount options from user space into
1123 * a data structure. The whole mount string is processed; bad options are
1124 * skipped as they are encountered. If there were no errors, return 1;
1125 * otherwise return 0 (zero).
1127 static int nfs_parse_mount_options(char *raw,
1128 struct nfs_parsed_mount_data *mnt)
1130 char *p, *string, *secdata;
1131 int rc, sloppy = 0, invalid_option = 0;
1132 unsigned short protofamily = AF_UNSPEC;
1133 unsigned short mountfamily = AF_UNSPEC;
1136 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1139 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1141 secdata = alloc_secdata();
1145 rc = security_sb_copy_data(raw, secdata);
1147 goto out_security_failure;
1149 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1151 goto out_security_failure;
1153 free_secdata(secdata);
1155 while ((p = strsep(&raw, ",")) != NULL) {
1156 substring_t args[MAX_OPT_ARGS];
1157 unsigned long option;
1163 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1165 token = match_token(p, nfs_mount_option_tokens, args);
1169 * boolean options: foo/nofoo
1172 mnt->flags |= NFS_MOUNT_SOFT;
1175 mnt->flags &= ~NFS_MOUNT_SOFT;
1178 mnt->flags |= NFS_MOUNT_POSIX;
1181 mnt->flags &= ~NFS_MOUNT_POSIX;
1184 mnt->flags &= ~NFS_MOUNT_NOCTO;
1187 mnt->flags |= NFS_MOUNT_NOCTO;
1190 mnt->flags &= ~NFS_MOUNT_NOAC;
1193 mnt->flags |= NFS_MOUNT_NOAC;
1196 mnt->flags &= ~NFS_MOUNT_NONLM;
1197 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1198 NFS_MOUNT_LOCAL_FCNTL);
1201 mnt->flags |= NFS_MOUNT_NONLM;
1202 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1203 NFS_MOUNT_LOCAL_FCNTL);
1206 mnt->flags &= ~NFS_MOUNT_TCP;
1207 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1210 mnt->flags |= NFS_MOUNT_TCP;
1211 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1214 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1215 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1216 xprt_load_transport(p);
1219 mnt->flags &= ~NFS_MOUNT_NOACL;
1222 mnt->flags |= NFS_MOUNT_NOACL;
1225 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1227 case Opt_nordirplus:
1228 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1230 case Opt_sharecache:
1231 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1233 case Opt_nosharecache:
1234 mnt->flags |= NFS_MOUNT_UNSHARED;
1237 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1239 case Opt_noresvport:
1240 mnt->flags |= NFS_MOUNT_NORESVPORT;
1243 mnt->options |= NFS_OPTION_FSCACHE;
1244 kfree(mnt->fscache_uniq);
1245 mnt->fscache_uniq = NULL;
1248 mnt->options &= ~NFS_OPTION_FSCACHE;
1249 kfree(mnt->fscache_uniq);
1250 mnt->fscache_uniq = NULL;
1253 mnt->options |= NFS_OPTION_MIGRATION;
1255 case Opt_nomigration:
1256 mnt->options &= NFS_OPTION_MIGRATION;
1260 * options that take numeric values
1263 if (nfs_get_option_ul(args, &option) ||
1265 goto out_invalid_value;
1266 mnt->nfs_server.port = option;
1269 if (nfs_get_option_ul(args, &option))
1270 goto out_invalid_value;
1271 mnt->rsize = option;
1274 if (nfs_get_option_ul(args, &option))
1275 goto out_invalid_value;
1276 mnt->wsize = option;
1279 if (nfs_get_option_ul(args, &option))
1280 goto out_invalid_value;
1281 mnt->bsize = option;
1284 if (nfs_get_option_ul(args, &option) || option == 0)
1285 goto out_invalid_value;
1286 mnt->timeo = option;
1289 if (nfs_get_option_ul(args, &option) || option == 0)
1290 goto out_invalid_value;
1291 mnt->retrans = option;
1294 if (nfs_get_option_ul(args, &option))
1295 goto out_invalid_value;
1296 mnt->acregmin = option;
1299 if (nfs_get_option_ul(args, &option))
1300 goto out_invalid_value;
1301 mnt->acregmax = option;
1304 if (nfs_get_option_ul(args, &option))
1305 goto out_invalid_value;
1306 mnt->acdirmin = option;
1309 if (nfs_get_option_ul(args, &option))
1310 goto out_invalid_value;
1311 mnt->acdirmax = option;
1314 if (nfs_get_option_ul(args, &option))
1315 goto out_invalid_value;
1316 mnt->acregmin = mnt->acregmax =
1317 mnt->acdirmin = mnt->acdirmax = option;
1320 if (nfs_get_option_ul(args, &option))
1321 goto out_invalid_value;
1322 mnt->namlen = option;
1325 if (nfs_get_option_ul(args, &option) ||
1327 goto out_invalid_value;
1328 mnt->mount_server.port = option;
1331 if (nfs_get_option_ul(args, &option) ||
1332 option < NFS_MNT_VERSION ||
1333 option > NFS_MNT3_VERSION)
1334 goto out_invalid_value;
1335 mnt->mount_server.version = option;
1337 case Opt_minorversion:
1338 if (nfs_get_option_ul(args, &option))
1339 goto out_invalid_value;
1340 if (option > NFS4_MAX_MINOR_VERSION)
1341 goto out_invalid_value;
1342 mnt->minorversion = option;
1346 * options that take text values
1349 string = match_strdup(args);
1352 rc = nfs_parse_version_string(string, mnt, args);
1355 goto out_invalid_value;
1358 string = match_strdup(args);
1361 rc = nfs_parse_security_flavors(string, mnt);
1364 dfprintk(MOUNT, "NFS: unrecognized "
1365 "security flavor\n");
1370 string = match_strdup(args);
1373 token = match_token(string,
1374 nfs_xprt_protocol_tokens, args);
1376 protofamily = AF_INET;
1379 protofamily = AF_INET6;
1381 mnt->flags &= ~NFS_MOUNT_TCP;
1382 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1385 protofamily = AF_INET6;
1387 mnt->flags |= NFS_MOUNT_TCP;
1388 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1391 /* vector side protocols to TCP */
1392 mnt->flags |= NFS_MOUNT_TCP;
1393 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1394 xprt_load_transport(string);
1397 dfprintk(MOUNT, "NFS: unrecognized "
1398 "transport protocol\n");
1404 case Opt_mountproto:
1405 string = match_strdup(args);
1408 token = match_token(string,
1409 nfs_xprt_protocol_tokens, args);
1412 mountfamily = AF_INET;
1415 mountfamily = AF_INET6;
1417 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1420 mountfamily = AF_INET6;
1422 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1424 case Opt_xprt_rdma: /* not used for side protocols */
1426 dfprintk(MOUNT, "NFS: unrecognized "
1427 "transport protocol\n");
1432 string = match_strdup(args);
1435 mnt->nfs_server.addrlen =
1436 rpc_pton(mnt->net, string, strlen(string),
1438 &mnt->nfs_server.address,
1439 sizeof(mnt->nfs_server.address));
1441 if (mnt->nfs_server.addrlen == 0)
1442 goto out_invalid_address;
1444 case Opt_clientaddr:
1445 if (nfs_get_option_str(args, &mnt->client_address))
1449 if (nfs_get_option_str(args,
1450 &mnt->mount_server.hostname))
1454 string = match_strdup(args);
1457 mnt->mount_server.addrlen =
1458 rpc_pton(mnt->net, string, strlen(string),
1460 &mnt->mount_server.address,
1461 sizeof(mnt->mount_server.address));
1463 if (mnt->mount_server.addrlen == 0)
1464 goto out_invalid_address;
1466 case Opt_lookupcache:
1467 string = match_strdup(args);
1470 token = match_token(string,
1471 nfs_lookupcache_tokens, args);
1474 case Opt_lookupcache_all:
1475 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1477 case Opt_lookupcache_positive:
1478 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1479 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1481 case Opt_lookupcache_none:
1482 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1485 dfprintk(MOUNT, "NFS: invalid "
1486 "lookupcache argument\n");
1490 case Opt_fscache_uniq:
1491 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1493 mnt->options |= NFS_OPTION_FSCACHE;
1495 case Opt_local_lock:
1496 string = match_strdup(args);
1499 token = match_token(string, nfs_local_lock_tokens,
1503 case Opt_local_lock_all:
1504 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1505 NFS_MOUNT_LOCAL_FCNTL);
1507 case Opt_local_lock_flock:
1508 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1510 case Opt_local_lock_posix:
1511 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1513 case Opt_local_lock_none:
1514 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1515 NFS_MOUNT_LOCAL_FCNTL);
1518 dfprintk(MOUNT, "NFS: invalid "
1519 "local_lock argument\n");
1529 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1532 case Opt_deprecated:
1533 dfprintk(MOUNT, "NFS: ignoring mount option "
1539 dfprintk(MOUNT, "NFS: unrecognized mount option "
1544 if (!sloppy && invalid_option)
1547 if (mnt->minorversion && mnt->version != 4)
1548 goto out_minorversion_mismatch;
1550 if (mnt->options & NFS_OPTION_MIGRATION &&
1551 mnt->version != 4 && mnt->minorversion != 0)
1552 goto out_migration_misuse;
1555 * verify that any proto=/mountproto= options match the address
1556 * families in the addr=/mountaddr= options.
1558 if (protofamily != AF_UNSPEC &&
1559 protofamily != mnt->nfs_server.address.ss_family)
1560 goto out_proto_mismatch;
1562 if (mountfamily != AF_UNSPEC) {
1563 if (mnt->mount_server.addrlen) {
1564 if (mountfamily != mnt->mount_server.address.ss_family)
1565 goto out_mountproto_mismatch;
1567 if (mountfamily != mnt->nfs_server.address.ss_family)
1568 goto out_mountproto_mismatch;
1574 out_mountproto_mismatch:
1575 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1579 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1581 out_invalid_address:
1582 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1585 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1587 out_minorversion_mismatch:
1588 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1589 "minorversion=%u\n", mnt->version, mnt->minorversion);
1591 out_migration_misuse:
1593 "NFS: 'migration' not supported for this NFS version\n");
1596 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1598 out_security_failure:
1599 free_secdata(secdata);
1600 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1605 * Match the requested auth flavors with the list returned by
1606 * the server. Returns zero and sets the mount's authentication
1607 * flavor on success; returns -EACCES if server does not support
1608 * the requested flavor.
1610 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1611 struct nfs_mount_request *request)
1613 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1616 * Certain releases of Linux's mountd return an empty
1617 * flavor list. To prevent behavioral regression with
1618 * these servers (ie. rejecting mounts that used to
1619 * succeed), revert to pre-2.6.32 behavior (no checking)
1620 * if the returned flavor list is empty.
1622 if (server_authlist_len == 0)
1626 * We avoid sophisticated negotiating here, as there are
1627 * plenty of cases where we can get it wrong, providing
1628 * either too little or too much security.
1630 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1631 * flavor listed first. However, some servers list
1632 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1633 * preferred default, in args->auth_flavors[0] if user
1634 * didn't specify sec= mount option.
1636 for (i = 0; i < args->auth_flavor_len; i++)
1637 for (j = 0; j < server_authlist_len; j++)
1638 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1639 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1640 request->auth_flavs[j]);
1641 args->auth_flavors[0] = request->auth_flavs[j];
1645 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1646 nfs_umount(request);
1651 * Use the remote server's MOUNT service to request the NFS file handle
1652 * corresponding to the provided path.
1654 static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1655 struct nfs_fh *root_fh)
1657 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1658 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1659 struct nfs_mount_request request = {
1660 .sap = (struct sockaddr *)
1661 &args->mount_server.address,
1662 .dirpath = args->nfs_server.export_path,
1663 .protocol = args->mount_server.protocol,
1665 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1666 .auth_flav_len = &server_authlist_len,
1667 .auth_flavs = server_authlist,
1672 if (args->mount_server.version == 0) {
1673 switch (args->version) {
1675 args->mount_server.version = NFS_MNT3_VERSION;
1678 args->mount_server.version = NFS_MNT_VERSION;
1681 request.version = args->mount_server.version;
1683 if (args->mount_server.hostname)
1684 request.hostname = args->mount_server.hostname;
1686 request.hostname = args->nfs_server.hostname;
1689 * Construct the mount server's address.
1691 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1692 memcpy(request.sap, &args->nfs_server.address,
1693 args->nfs_server.addrlen);
1694 args->mount_server.addrlen = args->nfs_server.addrlen;
1696 request.salen = args->mount_server.addrlen;
1697 nfs_set_port(request.sap, &args->mount_server.port, 0);
1700 * Now ask the mount server to map our export path
1703 status = nfs_mount(&request);
1705 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1706 request.hostname, status);
1711 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1713 if (args->mount_server.version != NFS_MNT3_VERSION)
1715 return nfs_walk_authlist(args, &request);
1718 struct dentry *nfs_try_mount(int flags, const char *dev_name,
1719 struct nfs_mount_info *mount_info,
1720 struct nfs_subversion *nfs_mod)
1723 struct nfs_server *server;
1725 if (mount_info->parsed->need_mount) {
1726 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
1728 return ERR_PTR(status);
1731 /* Get a volume representation */
1732 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
1734 return ERR_CAST(server);
1736 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
1738 EXPORT_SYMBOL_GPL(nfs_try_mount);
1741 * Split "dev_name" into "hostname:export_path".
1743 * The leftmost colon demarks the split between the server's hostname
1744 * and the export path. If the hostname starts with a left square
1745 * bracket, then it may contain colons.
1747 * Note: caller frees hostname and export path, even on error.
1749 static int nfs_parse_devname(const char *dev_name,
1750 char **hostname, size_t maxnamlen,
1751 char **export_path, size_t maxpathlen)
1756 /* Is the host name protected with square brakcets? */
1757 if (*dev_name == '[') {
1758 end = strchr(++dev_name, ']');
1759 if (end == NULL || end[1] != ':')
1760 goto out_bad_devname;
1762 len = end - dev_name;
1767 end = strchr(dev_name, ':');
1769 goto out_bad_devname;
1770 len = end - dev_name;
1772 /* kill possible hostname list: not supported */
1773 comma = strchr(dev_name, ',');
1774 if (comma != NULL && comma < end)
1778 if (len > maxnamlen)
1781 /* N.B. caller will free nfs_server.hostname in all cases */
1782 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1783 if (*hostname == NULL)
1785 len = strlen(++end);
1786 if (len > maxpathlen)
1788 *export_path = kstrndup(end, len, GFP_KERNEL);
1792 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1796 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1800 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1804 dfprintk(MOUNT, "NFS: server hostname too long\n");
1805 return -ENAMETOOLONG;
1808 dfprintk(MOUNT, "NFS: export pathname too long\n");
1809 return -ENAMETOOLONG;
1813 * Validate the NFS2/NFS3 mount data
1814 * - fills in the mount root filehandle
1816 * For option strings, user space handles the following behaviors:
1818 * + DNS: mapping server host name to IP address ("addr=" option)
1820 * + failure mode: how to behave if a mount request can't be handled
1821 * immediately ("fg/bg" option)
1823 * + retry: how often to retry a mount request ("retry=" option)
1825 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1826 * mountproto=tcp after mountproto=udp, and so on
1828 static int nfs23_validate_mount_data(void *options,
1829 struct nfs_parsed_mount_data *args,
1830 struct nfs_fh *mntfh,
1831 const char *dev_name)
1833 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1834 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1839 args->version = NFS_DEFAULT_VERSION;
1840 switch (data->version) {
1846 if (data->flags & NFS_MOUNT_VER3)
1848 data->root.size = NFS2_FHSIZE;
1849 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1851 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1854 memset(data->context, 0, sizeof(data->context));
1856 if (data->flags & NFS_MOUNT_VER3) {
1857 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1858 goto out_invalid_fh;
1859 mntfh->size = data->root.size;
1862 mntfh->size = NFS2_FHSIZE;
1867 memcpy(mntfh->data, data->root.data, mntfh->size);
1868 if (mntfh->size < sizeof(mntfh->data))
1869 memset(mntfh->data + mntfh->size, 0,
1870 sizeof(mntfh->data) - mntfh->size);
1873 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1876 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1877 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1878 args->rsize = data->rsize;
1879 args->wsize = data->wsize;
1880 args->timeo = data->timeo;
1881 args->retrans = data->retrans;
1882 args->acregmin = data->acregmin;
1883 args->acregmax = data->acregmax;
1884 args->acdirmin = data->acdirmin;
1885 args->acdirmax = data->acdirmax;
1886 args->need_mount = false;
1888 memcpy(sap, &data->addr, sizeof(data->addr));
1889 args->nfs_server.addrlen = sizeof(data->addr);
1890 args->nfs_server.port = ntohs(data->addr.sin_port);
1891 if (!nfs_verify_server_address(sap))
1892 goto out_no_address;
1894 if (!(data->flags & NFS_MOUNT_TCP))
1895 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1896 /* N.B. caller will free nfs_server.hostname in all cases */
1897 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1898 args->namlen = data->namlen;
1899 args->bsize = data->bsize;
1901 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1902 args->auth_flavors[0] = data->pseudoflavor;
1903 if (!args->nfs_server.hostname)
1906 if (!(data->flags & NFS_MOUNT_NONLM))
1907 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1908 NFS_MOUNT_LOCAL_FCNTL);
1910 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1911 NFS_MOUNT_LOCAL_FCNTL);
1913 * The legacy version 6 binary mount data from userspace has a
1914 * field used only to transport selinux information into the
1915 * the kernel. To continue to support that functionality we
1916 * have a touch of selinux knowledge here in the NFS code. The
1917 * userspace code converted context=blah to just blah so we are
1918 * converting back to the full string selinux understands.
1920 if (data->context[0]){
1921 #ifdef CONFIG_SECURITY_SELINUX
1923 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1926 strcpy(opts_str, "context=");
1927 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1928 strcat(opts_str, &data->context[0]);
1929 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1940 return NFS_TEXT_DATA;
1943 #if !IS_ENABLED(CONFIG_NFS_V3)
1944 if (args->version == 3)
1945 goto out_v3_not_compiled;
1946 #endif /* !CONFIG_NFS_V3 */
1951 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1955 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1960 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1963 #if !IS_ENABLED(CONFIG_NFS_V3)
1964 out_v3_not_compiled:
1965 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1966 return -EPROTONOSUPPORT;
1967 #endif /* !CONFIG_NFS_V3 */
1970 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1974 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1978 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1982 #if IS_ENABLED(CONFIG_NFS_V4)
1983 static int nfs_validate_mount_data(struct file_system_type *fs_type,
1985 struct nfs_parsed_mount_data *args,
1986 struct nfs_fh *mntfh,
1987 const char *dev_name)
1989 if (fs_type == &nfs_fs_type)
1990 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1991 return nfs4_validate_mount_data(options, args, dev_name);
1994 static int nfs_validate_mount_data(struct file_system_type *fs_type,
1996 struct nfs_parsed_mount_data *args,
1997 struct nfs_fh *mntfh,
1998 const char *dev_name)
2000 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2004 static int nfs_validate_text_mount_data(void *options,
2005 struct nfs_parsed_mount_data *args,
2006 const char *dev_name)
2009 int max_namelen = PAGE_SIZE;
2010 int max_pathlen = NFS_MAXPATHLEN;
2011 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2013 if (nfs_parse_mount_options((char *)options, args) == 0)
2016 if (!nfs_verify_server_address(sap))
2017 goto out_no_address;
2019 if (args->version == 4) {
2020 #if IS_ENABLED(CONFIG_NFS_V4)
2022 max_namelen = NFS4_MAXNAMLEN;
2023 max_pathlen = NFS4_MAXPATHLEN;
2024 nfs_validate_transport_protocol(args);
2025 nfs4_validate_mount_flags(args);
2027 goto out_v4_not_compiled;
2028 #endif /* CONFIG_NFS_V4 */
2030 nfs_set_mount_transport_protocol(args);
2032 nfs_set_port(sap, &args->nfs_server.port, port);
2034 if (args->auth_flavor_len > 1)
2037 return nfs_parse_devname(dev_name,
2038 &args->nfs_server.hostname,
2040 &args->nfs_server.export_path,
2043 #if !IS_ENABLED(CONFIG_NFS_V4)
2044 out_v4_not_compiled:
2045 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2046 return -EPROTONOSUPPORT;
2047 #endif /* !CONFIG_NFS_V4 */
2050 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2054 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2059 nfs_compare_remount_data(struct nfs_server *nfss,
2060 struct nfs_parsed_mount_data *data)
2062 if (data->flags != nfss->flags ||
2063 data->rsize != nfss->rsize ||
2064 data->wsize != nfss->wsize ||
2065 data->retrans != nfss->client->cl_timeout->to_retries ||
2066 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2067 data->acregmin != nfss->acregmin / HZ ||
2068 data->acregmax != nfss->acregmax / HZ ||
2069 data->acdirmin != nfss->acdirmin / HZ ||
2070 data->acdirmax != nfss->acdirmax / HZ ||
2071 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2072 data->nfs_server.port != nfss->port ||
2073 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2074 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2075 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2082 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2085 struct nfs_server *nfss = sb->s_fs_info;
2086 struct nfs_parsed_mount_data *data;
2087 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2088 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2089 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2092 * Userspace mount programs that send binary options generally send
2093 * them populated with default values. We have no way to know which
2094 * ones were explicitly specified. Fall back to legacy behavior and
2095 * just return success.
2097 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2098 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2099 options->version <= 6))))
2102 data = kzalloc(sizeof(*data), GFP_KERNEL);
2106 /* fill out struct with values from existing mount */
2107 data->flags = nfss->flags;
2108 data->rsize = nfss->rsize;
2109 data->wsize = nfss->wsize;
2110 data->retrans = nfss->client->cl_timeout->to_retries;
2111 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2112 data->acregmin = nfss->acregmin / HZ;
2113 data->acregmax = nfss->acregmax / HZ;
2114 data->acdirmin = nfss->acdirmin / HZ;
2115 data->acdirmax = nfss->acdirmax / HZ;
2116 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2117 data->nfs_server.port = nfss->port;
2118 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2119 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2120 data->nfs_server.addrlen);
2122 /* overwrite those values with any that were specified */
2123 error = nfs_parse_mount_options((char *)options, data);
2128 * noac is a special case. It implies -o sync, but that's not
2129 * necessarily reflected in the mtab options. do_remount_sb
2130 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2131 * remount options, so we have to explicitly reset it.
2133 if (data->flags & NFS_MOUNT_NOAC)
2134 *flags |= MS_SYNCHRONOUS;
2136 /* compare new mount options with old ones */
2137 error = nfs_compare_remount_data(nfss, data);
2142 EXPORT_SYMBOL_GPL(nfs_remount);
2145 * Initialise the common bits of the superblock
2147 inline void nfs_initialise_sb(struct super_block *sb)
2149 struct nfs_server *server = NFS_SB(sb);
2151 sb->s_magic = NFS_SUPER_MAGIC;
2153 /* We probably want something more informative here */
2154 snprintf(sb->s_id, sizeof(sb->s_id),
2155 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2157 if (sb->s_blocksize == 0)
2158 sb->s_blocksize = nfs_block_bits(server->wsize,
2159 &sb->s_blocksize_bits);
2161 sb->s_bdi = &server->backing_dev_info;
2163 nfs_super_set_maxbytes(sb, server->maxfilesize);
2167 * Finish setting up an NFS2/3 superblock
2169 void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2171 struct nfs_parsed_mount_data *data = mount_info->parsed;
2172 struct nfs_server *server = NFS_SB(sb);
2174 sb->s_blocksize_bits = 0;
2175 sb->s_blocksize = 0;
2176 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2177 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2178 if (data && data->bsize)
2179 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2181 if (server->nfs_client->rpc_ops->version != 2) {
2182 /* The VFS shouldn't apply the umask to mode bits. We will do
2183 * so ourselves when necessary.
2185 sb->s_flags |= MS_POSIXACL;
2186 sb->s_time_gran = 1;
2189 nfs_initialise_sb(sb);
2191 EXPORT_SYMBOL_GPL(nfs_fill_super);
2194 * Finish setting up a cloned NFS2/3/4 superblock
2196 void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2198 const struct super_block *old_sb = mount_info->cloned->sb;
2199 struct nfs_server *server = NFS_SB(sb);
2201 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2202 sb->s_blocksize = old_sb->s_blocksize;
2203 sb->s_maxbytes = old_sb->s_maxbytes;
2204 sb->s_xattr = old_sb->s_xattr;
2205 sb->s_op = old_sb->s_op;
2206 sb->s_time_gran = 1;
2208 if (server->nfs_client->rpc_ops->version != 2) {
2209 /* The VFS shouldn't apply the umask to mode bits. We will do
2210 * so ourselves when necessary.
2212 sb->s_flags |= MS_POSIXACL;
2215 nfs_initialise_sb(sb);
2218 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2220 const struct nfs_server *a = s->s_fs_info;
2221 const struct rpc_clnt *clnt_a = a->client;
2222 const struct rpc_clnt *clnt_b = b->client;
2224 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2226 if (a->nfs_client != b->nfs_client)
2228 if (a->flags != b->flags)
2230 if (a->wsize != b->wsize)
2232 if (a->rsize != b->rsize)
2234 if (a->acregmin != b->acregmin)
2236 if (a->acregmax != b->acregmax)
2238 if (a->acdirmin != b->acdirmin)
2240 if (a->acdirmax != b->acdirmax)
2242 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2249 struct nfs_sb_mountdata {
2250 struct nfs_server *server;
2254 static int nfs_set_super(struct super_block *s, void *data)
2256 struct nfs_sb_mountdata *sb_mntdata = data;
2257 struct nfs_server *server = sb_mntdata->server;
2260 s->s_flags = sb_mntdata->mntflags;
2261 s->s_fs_info = server;
2262 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2263 ret = set_anon_super(s, server);
2265 server->s_dev = s->s_dev;
2269 static int nfs_compare_super_address(struct nfs_server *server1,
2270 struct nfs_server *server2)
2272 struct sockaddr *sap1, *sap2;
2274 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2275 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2277 if (sap1->sa_family != sap2->sa_family)
2280 switch (sap1->sa_family) {
2282 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2283 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2284 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2286 if (sin1->sin_port != sin2->sin_port)
2291 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2292 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2293 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2295 if (sin1->sin6_port != sin2->sin6_port)
2306 static int nfs_compare_super(struct super_block *sb, void *data)
2308 struct nfs_sb_mountdata *sb_mntdata = data;
2309 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2310 int mntflags = sb_mntdata->mntflags;
2312 if (!nfs_compare_super_address(old, server))
2314 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2315 if (old->flags & NFS_MOUNT_UNSHARED)
2317 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2319 return nfs_compare_mount_options(sb, server, mntflags);
2322 #ifdef CONFIG_NFS_FSCACHE
2323 static void nfs_get_cache_cookie(struct super_block *sb,
2324 struct nfs_parsed_mount_data *parsed,
2325 struct nfs_clone_mount *cloned)
2330 if (parsed && parsed->fscache_uniq) {
2331 uniq = parsed->fscache_uniq;
2332 ulen = strlen(parsed->fscache_uniq);
2333 } else if (cloned) {
2334 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2335 if (mnt_s->fscache_key) {
2336 uniq = mnt_s->fscache_key->key.uniquifier;
2337 ulen = mnt_s->fscache_key->key.uniq_len;
2341 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2344 static void nfs_get_cache_cookie(struct super_block *sb,
2345 struct nfs_parsed_mount_data *parsed,
2346 struct nfs_clone_mount *cloned)
2351 static int nfs_bdi_register(struct nfs_server *server)
2353 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2356 int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2357 struct nfs_mount_info *mount_info)
2359 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2361 EXPORT_SYMBOL_GPL(nfs_set_sb_security);
2363 int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2364 struct nfs_mount_info *mount_info)
2366 /* clone any lsm security options from the parent to the new sb */
2367 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2368 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2372 EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
2374 struct dentry *nfs_fs_mount_common(struct nfs_server *server,
2375 int flags, const char *dev_name,
2376 struct nfs_mount_info *mount_info,
2377 struct nfs_subversion *nfs_mod)
2379 struct super_block *s;
2380 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2381 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2382 struct nfs_sb_mountdata sb_mntdata = {
2388 if (server->flags & NFS_MOUNT_UNSHARED)
2389 compare_super = NULL;
2391 /* -o noac implies -o sync */
2392 if (server->flags & NFS_MOUNT_NOAC)
2393 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2395 /* Get a superblock - note that we may end up sharing one that already exists */
2396 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
2398 mntroot = ERR_CAST(s);
2402 if (s->s_fs_info != server) {
2403 nfs_free_server(server);
2406 error = nfs_bdi_register(server);
2408 mntroot = ERR_PTR(error);
2409 goto error_splat_bdi;
2414 /* initial superblock/root creation */
2415 mount_info->fill_super(s, mount_info);
2416 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2419 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
2420 if (IS_ERR(mntroot))
2421 goto error_splat_super;
2423 error = mount_info->set_security(s, mntroot, mount_info);
2425 goto error_splat_root;
2427 s->s_flags |= MS_ACTIVE;
2433 nfs_free_server(server);
2438 mntroot = ERR_PTR(error);
2440 if (server && !s->s_root)
2441 bdi_unregister(&server->backing_dev_info);
2443 deactivate_locked_super(s);
2446 EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
2448 struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2449 int flags, const char *dev_name, void *raw_data)
2451 struct nfs_mount_info mount_info = {
2452 .fill_super = nfs_fill_super,
2453 .set_security = nfs_set_sb_security,
2455 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2456 struct nfs_subversion *nfs_mod;
2459 mount_info.parsed = nfs_alloc_parsed_mount_data();
2460 mount_info.mntfh = nfs_alloc_fhandle();
2461 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
2464 /* Validate the mount data */
2465 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
2466 if (error == NFS_TEXT_DATA)
2467 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
2469 mntroot = ERR_PTR(error);
2473 nfs_mod = get_nfs_version(mount_info.parsed->version);
2474 if (IS_ERR(nfs_mod)) {
2475 mntroot = ERR_CAST(nfs_mod);
2479 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
2481 put_nfs_version(nfs_mod);
2483 nfs_free_parsed_mount_data(mount_info.parsed);
2484 nfs_free_fhandle(mount_info.mntfh);
2487 EXPORT_SYMBOL_GPL(nfs_fs_mount);
2490 * Ensure that we unregister the bdi before kill_anon_super
2491 * releases the device name
2493 void nfs_put_super(struct super_block *s)
2495 struct nfs_server *server = NFS_SB(s);
2497 bdi_unregister(&server->backing_dev_info);
2499 EXPORT_SYMBOL_GPL(nfs_put_super);
2502 * Destroy an NFS2/3 superblock
2504 void nfs_kill_super(struct super_block *s)
2506 struct nfs_server *server = NFS_SB(s);
2509 nfs_fscache_release_super_cookie(s);
2510 nfs_free_server(server);
2512 EXPORT_SYMBOL_GPL(nfs_kill_super);
2515 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2517 static struct dentry *
2518 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2519 const char *dev_name, void *raw_data)
2521 struct nfs_clone_mount *data = raw_data;
2522 struct nfs_mount_info mount_info = {
2523 .fill_super = nfs_clone_super,
2524 .set_security = nfs_clone_sb_security,
2527 struct nfs_server *server;
2528 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2529 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
2532 dprintk("--> nfs_xdev_mount_common()\n");
2534 mount_info.mntfh = mount_info.cloned->fh;
2536 /* create a new volume representation */
2537 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2538 if (IS_ERR(server)) {
2539 error = PTR_ERR(server);
2543 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
2544 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2549 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2553 #if IS_ENABLED(CONFIG_NFS_V4)
2555 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2557 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2558 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2562 * Validate NFSv4 mount options
2564 static int nfs4_validate_mount_data(void *options,
2565 struct nfs_parsed_mount_data *args,
2566 const char *dev_name)
2568 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2569 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2577 switch (data->version) {
2579 if (data->host_addrlen > sizeof(args->nfs_server.address))
2580 goto out_no_address;
2581 if (data->host_addrlen == 0)
2582 goto out_no_address;
2583 args->nfs_server.addrlen = data->host_addrlen;
2584 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2586 if (!nfs_verify_server_address(sap))
2587 goto out_no_address;
2588 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
2590 if (data->auth_flavourlen) {
2591 if (data->auth_flavourlen > 1)
2592 goto out_inval_auth;
2593 if (copy_from_user(&args->auth_flavors[0],
2594 data->auth_flavours,
2595 sizeof(args->auth_flavors[0])))
2599 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2602 args->nfs_server.hostname = c;
2604 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2607 args->nfs_server.export_path = c;
2608 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2610 c = strndup_user(data->client_addr.data, 16);
2613 args->client_address = c;
2616 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2620 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2621 args->rsize = data->rsize;
2622 args->wsize = data->wsize;
2623 args->timeo = data->timeo;
2624 args->retrans = data->retrans;
2625 args->acregmin = data->acregmin;
2626 args->acregmax = data->acregmax;
2627 args->acdirmin = data->acdirmin;
2628 args->acdirmax = data->acdirmax;
2629 args->nfs_server.protocol = data->proto;
2630 nfs_validate_transport_protocol(args);
2634 return NFS_TEXT_DATA;
2640 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2644 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2645 data->auth_flavourlen);
2649 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2654 * NFS v4 module parameters need to stay in the
2655 * NFS client for backwards compatibility
2657 unsigned int nfs_callback_set_tcpport;
2658 unsigned short nfs_callback_tcpport;
2659 /* Default cache timeout is 10 minutes */
2660 unsigned int nfs_idmap_cache_timeout = 600;
2661 /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2662 bool nfs4_disable_idmapping = true;
2663 unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2664 unsigned short send_implementation_id = 1;
2665 char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
2667 EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2668 EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2669 EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2670 EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2671 EXPORT_SYMBOL_GPL(max_session_slots);
2672 EXPORT_SYMBOL_GPL(send_implementation_id);
2673 EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
2675 #define NFS_CALLBACK_MAXPORTNR (65535U)
2677 static int param_set_portnr(const char *val, const struct kernel_param *kp)
2684 ret = kstrtoul(val, 0, &num);
2685 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2687 *((unsigned int *)kp->arg) = num;
2690 static struct kernel_param_ops param_ops_portnr = {
2691 .set = param_set_portnr,
2692 .get = param_get_uint,
2694 #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2696 module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2697 module_param(nfs_idmap_cache_timeout, int, 0644);
2698 module_param(nfs4_disable_idmapping, bool, 0644);
2699 module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
2700 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
2701 MODULE_PARM_DESC(nfs4_disable_idmapping,
2702 "Turn off NFSv4 idmapping when using 'sec=sys'");
2703 module_param(max_session_slots, ushort, 0644);
2704 MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2705 "requests the client will negotiate");
2706 module_param(send_implementation_id, ushort, 0644);
2707 MODULE_PARM_DESC(send_implementation_id,
2708 "Send implementation ID with NFSv4.1 exchange_id");
2709 MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
2710 MODULE_ALIAS("nfs4");
2712 #endif /* CONFIG_NFS_V4 */