xref: /openbmc/linux/fs/nfs/super.c (revision 24f68eb5bf14a74027946970a18bc902e19d986a)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f7b422b1SDavid Howells /*
3f7b422b1SDavid Howells  *  linux/fs/nfs/super.c
4f7b422b1SDavid Howells  *
5f7b422b1SDavid Howells  *  Copyright (C) 1992  Rick Sladkey
6f7b422b1SDavid Howells  *
7f7b422b1SDavid Howells  *  nfs superblock handling functions
8f7b422b1SDavid Howells  *
9526719baSAlan Cox  *  Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
10f7b422b1SDavid Howells  *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
11f7b422b1SDavid Howells  *
12f7b422b1SDavid Howells  *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
13f7b422b1SDavid Howells  *  J.S.Peatfield@damtp.cam.ac.uk
14f7b422b1SDavid Howells  *
15f7b422b1SDavid Howells  *  Split from inode.c by David Howells <dhowells@redhat.com>
16f7b422b1SDavid Howells  *
1754ceac45SDavid Howells  * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
1854ceac45SDavid Howells  *   particular server are held in the same superblock
1954ceac45SDavid Howells  * - NFS superblocks can have several effective roots to the dentry tree
2054ceac45SDavid Howells  * - directory type roots are spliced into the tree when a path from one root reaches the root
2154ceac45SDavid Howells  *   of another (see nfs_lookup())
22f7b422b1SDavid Howells  */
23f7b422b1SDavid Howells 
24f7b422b1SDavid Howells #include <linux/module.h>
25f7b422b1SDavid Howells #include <linux/init.h>
26f7b422b1SDavid Howells 
27f7b422b1SDavid Howells #include <linux/time.h>
28f7b422b1SDavid Howells #include <linux/kernel.h>
29f7b422b1SDavid Howells #include <linux/mm.h>
30f7b422b1SDavid Howells #include <linux/string.h>
31f7b422b1SDavid Howells #include <linux/stat.h>
32f7b422b1SDavid Howells #include <linux/errno.h>
33f7b422b1SDavid Howells #include <linux/unistd.h>
34f7b422b1SDavid Howells #include <linux/sunrpc/clnt.h>
355976687aSJeff Layton #include <linux/sunrpc/addr.h>
36f7b422b1SDavid Howells #include <linux/sunrpc/stats.h>
37f7b422b1SDavid Howells #include <linux/sunrpc/metrics.h>
380896a725S\"Talpey, Thomas\ #include <linux/sunrpc/xprtsock.h>
392cf7ff7aS\"Talpey, Thomas\ #include <linux/sunrpc/xprtrdma.h>
40f7b422b1SDavid Howells #include <linux/nfs_fs.h>
41f7b422b1SDavid Howells #include <linux/nfs_mount.h>
42f7b422b1SDavid Howells #include <linux/nfs4_mount.h>
43f7b422b1SDavid Howells #include <linux/lockd/bind.h>
44f7b422b1SDavid Howells #include <linux/seq_file.h>
45f7b422b1SDavid Howells #include <linux/mount.h>
46c02d7adfSTrond Myklebust #include <linux/namei.h>
47f7b422b1SDavid Howells #include <linux/vfs.h>
48f7b422b1SDavid Howells #include <linux/inet.h>
49fd00a8ffSChuck Lever #include <linux/in6.h>
506c4a878eSTrond Myklebust #include <linux/sched.h>
515a0e3ad6STejun Heo #include <linux/slab.h>
52fd00a8ffSChuck Lever #include <net/ipv6.h>
53d8e7748aSChuck Lever #include <linux/netdevice.h>
54f7b422b1SDavid Howells #include <linux/nfs_xdr.h>
55b5d5dfbdSAdrian Bunk #include <linux/magic.h>
56bf0fd768SChuck Lever #include <linux/parser.h>
57e50a7a1aSStanislav Kinsbursky #include <linux/nsproxy.h>
582446ab60STrond Myklebust #include <linux/rcupdate.h>
59f7b422b1SDavid Howells 
607c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
610cfcd405SDai Ngo #include <linux/nfs_ssc.h>
62f7b422b1SDavid Howells 
63c8407f2eSChuck Lever #include <uapi/linux/tls.h>
64c8407f2eSChuck Lever 
65f7b422b1SDavid Howells #include "nfs4_fs.h"
66f7b422b1SDavid Howells #include "callback.h"
67f7b422b1SDavid Howells #include "delegation.h"
68f7b422b1SDavid Howells #include "iostat.h"
69f7b422b1SDavid Howells #include "internal.h"
7008734048SDavid Howells #include "fscache.h"
7176e697baSTrond Myklebust #include "nfs4session.h"
72ae50c0b5SJ. Bruce Fields #include "pnfs.h"
73ab7017a3SBryan Schumaker #include "nfs.h"
741c725118SBenjamin Coddington #include "netns.h"
751c725118SBenjamin Coddington #include "sysfs.h"
76f7b422b1SDavid Howells 
77f7b422b1SDavid Howells #define NFSDBG_FACILITY		NFSDBG_VFS
78bf0fd768SChuck Lever 
796a74490dSBryan Schumaker const struct super_operations nfs_sops = {
80f7b422b1SDavid Howells 	.alloc_inode	= nfs_alloc_inode,
81ca1a199eSAl Viro 	.free_inode	= nfs_free_inode,
82f7b422b1SDavid Howells 	.write_inode	= nfs_write_inode,
83eed99357STrond Myklebust 	.drop_inode	= nfs_drop_inode,
84f7b422b1SDavid Howells 	.statfs		= nfs_statfs,
85b57922d9SAl Viro 	.evict_inode	= nfs_evict_inode,
86f7b422b1SDavid Howells 	.umount_begin	= nfs_umount_begin,
87f7b422b1SDavid Howells 	.show_options	= nfs_show_options,
88c7f404b4SAl Viro 	.show_devname	= nfs_show_devname,
89c7f404b4SAl Viro 	.show_path	= nfs_show_path,
90f7b422b1SDavid Howells 	.show_stats	= nfs_show_stats,
91f7b422b1SDavid Howells };
92ddda8e0aSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_sops);
93f7b422b1SDavid Howells 
9402591f9fSDai Ngo #ifdef CONFIG_NFS_V4_2
950cfcd405SDai Ngo static const struct nfs_ssc_client_ops nfs_ssc_clnt_ops_tbl = {
960cfcd405SDai Ngo 	.sco_sb_deactive = nfs_sb_deactive,
970cfcd405SDai Ngo };
9802591f9fSDai Ngo #endif
990cfcd405SDai Ngo 
10089d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
register_nfs4_fs(void)1011ae811eeSbjschuma@gmail.com static int __init register_nfs4_fs(void)
1021ae811eeSbjschuma@gmail.com {
1031ae811eeSbjschuma@gmail.com 	return register_filesystem(&nfs4_fs_type);
1041ae811eeSbjschuma@gmail.com }
1051ae811eeSbjschuma@gmail.com 
unregister_nfs4_fs(void)1061ae811eeSbjschuma@gmail.com static void unregister_nfs4_fs(void)
1071ae811eeSbjschuma@gmail.com {
1081ae811eeSbjschuma@gmail.com 	unregister_filesystem(&nfs4_fs_type);
1091ae811eeSbjschuma@gmail.com }
1101ae811eeSbjschuma@gmail.com #else
register_nfs4_fs(void)1111ae811eeSbjschuma@gmail.com static int __init register_nfs4_fs(void)
1121ae811eeSbjschuma@gmail.com {
1131ae811eeSbjschuma@gmail.com 	return 0;
1141ae811eeSbjschuma@gmail.com }
1151ae811eeSbjschuma@gmail.com 
unregister_nfs4_fs(void)1161ae811eeSbjschuma@gmail.com static void unregister_nfs4_fs(void)
1171ae811eeSbjschuma@gmail.com {
1181ae811eeSbjschuma@gmail.com }
119f7b422b1SDavid Howells #endif
120f7b422b1SDavid Howells 
12102591f9fSDai Ngo #ifdef CONFIG_NFS_V4_2
nfs_ssc_register_ops(void)1220cfcd405SDai Ngo static void nfs_ssc_register_ops(void)
1230cfcd405SDai Ngo {
1240cfcd405SDai Ngo 	nfs_ssc_register(&nfs_ssc_clnt_ops_tbl);
1250cfcd405SDai Ngo }
1260cfcd405SDai Ngo 
nfs_ssc_unregister_ops(void)1270cfcd405SDai Ngo static void nfs_ssc_unregister_ops(void)
1280cfcd405SDai Ngo {
1290cfcd405SDai Ngo 	nfs_ssc_unregister(&nfs_ssc_clnt_ops_tbl);
1300cfcd405SDai Ngo }
13102591f9fSDai Ngo #endif /* CONFIG_NFS_V4_2 */
1320cfcd405SDai Ngo 
1338e1f936bSRusty Russell static struct shrinker acl_shrinker = {
1341ab6c499SDave Chinner 	.count_objects	= nfs_access_cache_count,
1351ab6c499SDave Chinner 	.scan_objects	= nfs_access_cache_scan,
1368e1f936bSRusty Russell 	.seeks		= DEFAULT_SEEKS,
1378e1f936bSRusty Russell };
138979df72eSTrond Myklebust 
139f7b422b1SDavid Howells /*
140f7b422b1SDavid Howells  * Register the NFS filesystems
141f7b422b1SDavid Howells  */
register_nfs_fs(void)142f7b422b1SDavid Howells int __init register_nfs_fs(void)
143f7b422b1SDavid Howells {
144f7b422b1SDavid Howells 	int ret;
145f7b422b1SDavid Howells 
146f7b422b1SDavid Howells         ret = register_filesystem(&nfs_fs_type);
147f7b422b1SDavid Howells 	if (ret < 0)
148f7b422b1SDavid Howells 		goto error_0;
149f7b422b1SDavid Howells 
1501ae811eeSbjschuma@gmail.com 	ret = register_nfs4_fs();
151f7b422b1SDavid Howells 	if (ret < 0)
152f7b422b1SDavid Howells 		goto error_1;
1531ae811eeSbjschuma@gmail.com 
1541ae811eeSbjschuma@gmail.com 	ret = nfs_register_sysctl();
1551ae811eeSbjschuma@gmail.com 	if (ret < 0)
1561ae811eeSbjschuma@gmail.com 		goto error_2;
157e33c267aSRoman Gushchin 	ret = register_shrinker(&acl_shrinker, "nfs-acl");
1585ef8d792SKinglong Mee 	if (ret < 0)
1595ef8d792SKinglong Mee 		goto error_3;
16002591f9fSDai Ngo #ifdef CONFIG_NFS_V4_2
1610cfcd405SDai Ngo 	nfs_ssc_register_ops();
16202591f9fSDai Ngo #endif
163f7b422b1SDavid Howells 	return 0;
1645ef8d792SKinglong Mee error_3:
1655ef8d792SKinglong Mee 	nfs_unregister_sysctl();
1661ae811eeSbjschuma@gmail.com error_2:
1671ae811eeSbjschuma@gmail.com 	unregister_nfs4_fs();
168f7b422b1SDavid Howells error_1:
169f7b422b1SDavid Howells 	unregister_filesystem(&nfs_fs_type);
170f7b422b1SDavid Howells error_0:
171f7b422b1SDavid Howells 	return ret;
172f7b422b1SDavid Howells }
173f7b422b1SDavid Howells 
174f7b422b1SDavid Howells /*
175f7b422b1SDavid Howells  * Unregister the NFS filesystems
176f7b422b1SDavid Howells  */
unregister_nfs_fs(void)177f7b422b1SDavid Howells void __exit unregister_nfs_fs(void)
178f7b422b1SDavid Howells {
1798e1f936bSRusty Russell 	unregister_shrinker(&acl_shrinker);
18049af7ee1SAlexey Dobriyan 	nfs_unregister_sysctl();
1811ae811eeSbjschuma@gmail.com 	unregister_nfs4_fs();
18202591f9fSDai Ngo #ifdef CONFIG_NFS_V4_2
1830cfcd405SDai Ngo 	nfs_ssc_unregister_ops();
18402591f9fSDai Ngo #endif
185f7b422b1SDavid Howells 	unregister_filesystem(&nfs_fs_type);
186f7b422b1SDavid Howells }
187f7b422b1SDavid Howells 
nfs_sb_active(struct super_block * sb)188ea7c38feSTrond Myklebust bool nfs_sb_active(struct super_block *sb)
189ef818a28SSteve Dickson {
190ef818a28SSteve Dickson 	struct nfs_server *server = NFS_SB(sb);
1911daef0a8STrond Myklebust 
192ea7c38feSTrond Myklebust 	if (!atomic_inc_not_zero(&sb->s_active))
193ea7c38feSTrond Myklebust 		return false;
194ea7c38feSTrond Myklebust 	if (atomic_inc_return(&server->active) != 1)
195ea7c38feSTrond Myklebust 		atomic_dec(&sb->s_active);
196ea7c38feSTrond Myklebust 	return true;
1971daef0a8STrond Myklebust }
19889d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_sb_active);
1991daef0a8STrond Myklebust 
nfs_sb_deactive(struct super_block * sb)2001daef0a8STrond Myklebust void nfs_sb_deactive(struct super_block *sb)
2011daef0a8STrond Myklebust {
2021daef0a8STrond Myklebust 	struct nfs_server *server = NFS_SB(sb);
2031daef0a8STrond Myklebust 
2041daef0a8STrond Myklebust 	if (atomic_dec_and_test(&server->active))
2051daef0a8STrond Myklebust 		deactivate_super(sb);
206ef818a28SSteve Dickson }
20789d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_sb_deactive);
208ef818a28SSteve Dickson 
__nfs_list_for_each_server(struct list_head * head,int (* fn)(struct nfs_server *,void *),void * data)2093c9e502bSTrond Myklebust static int __nfs_list_for_each_server(struct list_head *head,
2103c9e502bSTrond Myklebust 		int (*fn)(struct nfs_server *, void *),
2113c9e502bSTrond Myklebust 		void *data)
2123c9e502bSTrond Myklebust {
2133c9e502bSTrond Myklebust 	struct nfs_server *server, *last = NULL;
2143c9e502bSTrond Myklebust 	int ret = 0;
2153c9e502bSTrond Myklebust 
2163c9e502bSTrond Myklebust 	rcu_read_lock();
2173c9e502bSTrond Myklebust 	list_for_each_entry_rcu(server, head, client_link) {
2189c07b75bSTrond Myklebust 		if (!(server->super && nfs_sb_active(server->super)))
2193c9e502bSTrond Myklebust 			continue;
2203c9e502bSTrond Myklebust 		rcu_read_unlock();
2213c9e502bSTrond Myklebust 		if (last)
2223c9e502bSTrond Myklebust 			nfs_sb_deactive(last->super);
2233c9e502bSTrond Myklebust 		last = server;
2243c9e502bSTrond Myklebust 		ret = fn(server, data);
2253c9e502bSTrond Myklebust 		if (ret)
2263c9e502bSTrond Myklebust 			goto out;
2276c4a878eSTrond Myklebust 		cond_resched();
2283c9e502bSTrond Myklebust 		rcu_read_lock();
2293c9e502bSTrond Myklebust 	}
2303c9e502bSTrond Myklebust 	rcu_read_unlock();
2313c9e502bSTrond Myklebust out:
2323c9e502bSTrond Myklebust 	if (last)
2333c9e502bSTrond Myklebust 		nfs_sb_deactive(last->super);
2343c9e502bSTrond Myklebust 	return ret;
2353c9e502bSTrond Myklebust }
2363c9e502bSTrond Myklebust 
nfs_client_for_each_server(struct nfs_client * clp,int (* fn)(struct nfs_server *,void *),void * data)2373c9e502bSTrond Myklebust int nfs_client_for_each_server(struct nfs_client *clp,
2383c9e502bSTrond Myklebust 		int (*fn)(struct nfs_server *, void *),
2393c9e502bSTrond Myklebust 		void *data)
2403c9e502bSTrond Myklebust {
2413c9e502bSTrond Myklebust 	return __nfs_list_for_each_server(&clp->cl_superblocks, fn, data);
2423c9e502bSTrond Myklebust }
2433c9e502bSTrond Myklebust EXPORT_SYMBOL_GPL(nfs_client_for_each_server);
2443c9e502bSTrond Myklebust 
245f7b422b1SDavid Howells /*
246f7b422b1SDavid Howells  * Deliver file system statistics to userspace
247f7b422b1SDavid Howells  */
nfs_statfs(struct dentry * dentry,struct kstatfs * buf)248fbdefd64SBryan Schumaker int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
249f7b422b1SDavid Howells {
2500c7d90cfSDavid Howells 	struct nfs_server *server = NFS_SB(dentry->d_sb);
251f7b422b1SDavid Howells 	unsigned char blockbits;
252f7b422b1SDavid Howells 	unsigned long blockres;
2532b0143b5SDavid Howells 	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
254ca7e9a0dSTrond Myklebust 	struct nfs_fsstat res;
255ca7e9a0dSTrond Myklebust 	int error = -ENOMEM;
256ca7e9a0dSTrond Myklebust 
257ca7e9a0dSTrond Myklebust 	res.fattr = nfs_alloc_fattr();
258ca7e9a0dSTrond Myklebust 	if (res.fattr == NULL)
259ca7e9a0dSTrond Myklebust 		goto out_err;
260f7b422b1SDavid Howells 
2618fa5c000SDavid Howells 	error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
262fbf3fdd2SMenyhart Zoltan 	if (unlikely(error == -ESTALE)) {
263fbf3fdd2SMenyhart Zoltan 		struct dentry *pd_dentry;
264ca7e9a0dSTrond Myklebust 
265fbf3fdd2SMenyhart Zoltan 		pd_dentry = dget_parent(dentry);
2662b0143b5SDavid Howells 		nfs_zap_caches(d_inode(pd_dentry));
267fbf3fdd2SMenyhart Zoltan 		dput(pd_dentry);
268fbf3fdd2SMenyhart Zoltan 	}
269ca7e9a0dSTrond Myklebust 	nfs_free_fattr(res.fattr);
270f7b422b1SDavid Howells 	if (error < 0)
271f7b422b1SDavid Howells 		goto out_err;
272ca7e9a0dSTrond Myklebust 
2731a0ba9aeSAmnon Aaronsohn 	buf->f_type = NFS_SUPER_MAGIC;
274f7b422b1SDavid Howells 
275f7b422b1SDavid Howells 	/*
276f7b422b1SDavid Howells 	 * Current versions of glibc do not correctly handle the
277f7b422b1SDavid Howells 	 * case where f_frsize != f_bsize.  Eventually we want to
278f7b422b1SDavid Howells 	 * report the value of wtmult in this field.
279f7b422b1SDavid Howells 	 */
2800c7d90cfSDavid Howells 	buf->f_frsize = dentry->d_sb->s_blocksize;
281f7b422b1SDavid Howells 
282f7b422b1SDavid Howells 	/*
283f7b422b1SDavid Howells 	 * On most *nix systems, f_blocks, f_bfree, and f_bavail
284f7b422b1SDavid Howells 	 * are reported in units of f_frsize.  Linux hasn't had
285f7b422b1SDavid Howells 	 * an f_frsize field in its statfs struct until recently,
286f7b422b1SDavid Howells 	 * thus historically Linux's sys_statfs reports these
287f7b422b1SDavid Howells 	 * fields in units of f_bsize.
288f7b422b1SDavid Howells 	 */
2890c7d90cfSDavid Howells 	buf->f_bsize = dentry->d_sb->s_blocksize;
2900c7d90cfSDavid Howells 	blockbits = dentry->d_sb->s_blocksize_bits;
291f7b422b1SDavid Howells 	blockres = (1 << blockbits) - 1;
292f7b422b1SDavid Howells 	buf->f_blocks = (res.tbytes + blockres) >> blockbits;
293f7b422b1SDavid Howells 	buf->f_bfree = (res.fbytes + blockres) >> blockbits;
294f7b422b1SDavid Howells 	buf->f_bavail = (res.abytes + blockres) >> blockbits;
295f7b422b1SDavid Howells 
296f7b422b1SDavid Howells 	buf->f_files = res.tfiles;
297f7b422b1SDavid Howells 	buf->f_ffree = res.afiles;
298f7b422b1SDavid Howells 
299f7b422b1SDavid Howells 	buf->f_namelen = server->namelen;
3001a0ba9aeSAmnon Aaronsohn 
301f7b422b1SDavid Howells 	return 0;
302f7b422b1SDavid Howells 
303f7b422b1SDavid Howells  out_err:
3043110ff80SHarvey Harrison 	dprintk("%s: statfs error = %d\n", __func__, -error);
3051a0ba9aeSAmnon Aaronsohn 	return error;
306f7b422b1SDavid Howells }
30789d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_statfs);
308f7b422b1SDavid Howells 
3097d4e2747SDavid Howells /*
3107d4e2747SDavid Howells  * Map the security flavour number to a name
3117d4e2747SDavid Howells  */
nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)31281039f1fSTrond Myklebust static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
31381039f1fSTrond Myklebust {
3147d4e2747SDavid Howells 	static const struct {
31581039f1fSTrond Myklebust 		rpc_authflavor_t flavour;
31681039f1fSTrond Myklebust 		const char *str;
3174d4b69ddSWeston Andros Adamson 	} sec_flavours[NFS_AUTH_INFO_MAX_FLAVORS] = {
3184d4b69ddSWeston Andros Adamson 		/* update NFS_AUTH_INFO_MAX_FLAVORS when this list changes! */
31981039f1fSTrond Myklebust 		{ RPC_AUTH_NULL, "null" },
32081039f1fSTrond Myklebust 		{ RPC_AUTH_UNIX, "sys" },
32181039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_KRB5, "krb5" },
32281039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_KRB5I, "krb5i" },
32381039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_KRB5P, "krb5p" },
32481039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_LKEY, "lkey" },
32581039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_LKEYI, "lkeyi" },
32681039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_LKEYP, "lkeyp" },
32781039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_SPKM, "spkm" },
32881039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_SPKMI, "spkmi" },
32981039f1fSTrond Myklebust 		{ RPC_AUTH_GSS_SPKMP, "spkmp" },
3304d81cd16SChuck Lever 		{ UINT_MAX, "unknown" }
33181039f1fSTrond Myklebust 	};
33281039f1fSTrond Myklebust 	int i;
33381039f1fSTrond Myklebust 
3344d81cd16SChuck Lever 	for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
33581039f1fSTrond Myklebust 		if (sec_flavours[i].flavour == flavour)
33681039f1fSTrond Myklebust 			break;
33781039f1fSTrond Myklebust 	}
33881039f1fSTrond Myklebust 	return sec_flavours[i].str;
33981039f1fSTrond Myklebust }
34081039f1fSTrond Myklebust 
nfs_show_mountd_netid(struct seq_file * m,struct nfs_server * nfss,int showdefaults)341ee671b01SJeff Layton static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
342ee671b01SJeff Layton 				  int showdefaults)
343ee671b01SJeff Layton {
344ee671b01SJeff Layton 	struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
3456f6e3c09SNeilBrown 	char *proto = NULL;
346ee671b01SJeff Layton 
347ee671b01SJeff Layton 	switch (sap->sa_family) {
348ee671b01SJeff Layton 	case AF_INET:
349ee671b01SJeff Layton 		switch (nfss->mountd_protocol) {
350ee671b01SJeff Layton 		case IPPROTO_UDP:
3516f6e3c09SNeilBrown 			proto = RPCBIND_NETID_UDP;
352ee671b01SJeff Layton 			break;
353ee671b01SJeff Layton 		case IPPROTO_TCP:
3546f6e3c09SNeilBrown 			proto = RPCBIND_NETID_TCP;
355ee671b01SJeff Layton 			break;
356ee671b01SJeff Layton 		}
357ee671b01SJeff Layton 		break;
358ee671b01SJeff Layton 	case AF_INET6:
359ee671b01SJeff Layton 		switch (nfss->mountd_protocol) {
360ee671b01SJeff Layton 		case IPPROTO_UDP:
3616f6e3c09SNeilBrown 			proto = RPCBIND_NETID_UDP6;
362ee671b01SJeff Layton 			break;
363ee671b01SJeff Layton 		case IPPROTO_TCP:
3646f6e3c09SNeilBrown 			proto = RPCBIND_NETID_TCP6;
365ee671b01SJeff Layton 			break;
366ee671b01SJeff Layton 		}
367ee671b01SJeff Layton 		break;
368ee671b01SJeff Layton 	}
3696f6e3c09SNeilBrown 	if (proto || showdefaults)
3706f6e3c09SNeilBrown 		seq_printf(m, ",mountproto=%s", proto ?: "auto");
371ee671b01SJeff Layton }
372ee671b01SJeff Layton 
nfs_show_mountd_options(struct seq_file * m,struct nfs_server * nfss,int showdefaults)37382d101d5SChuck Lever static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
37482d101d5SChuck Lever 				    int showdefaults)
37582d101d5SChuck Lever {
37682d101d5SChuck Lever 	struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
37782d101d5SChuck Lever 
378d5eff1a3SBryan Schumaker 	if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
379d5eff1a3SBryan Schumaker 		return;
380d5eff1a3SBryan Schumaker 
38182d101d5SChuck Lever 	switch (sap->sa_family) {
38282d101d5SChuck Lever 	case AF_INET: {
38382d101d5SChuck Lever 		struct sockaddr_in *sin = (struct sockaddr_in *)sap;
384be859405SHarvey Harrison 		seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
38582d101d5SChuck Lever 		break;
38682d101d5SChuck Lever 	}
38782d101d5SChuck Lever 	case AF_INET6: {
38882d101d5SChuck Lever 		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
389d250e190SChuck Lever 		seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
39082d101d5SChuck Lever 		break;
39182d101d5SChuck Lever 	}
39282d101d5SChuck Lever 	default:
39382d101d5SChuck Lever 		if (showdefaults)
3941c316e39SMarkus Elfring 			seq_puts(m, ",mountaddr=unspecified");
39582d101d5SChuck Lever 	}
39682d101d5SChuck Lever 
39782d101d5SChuck Lever 	if (nfss->mountd_version || showdefaults)
39882d101d5SChuck Lever 		seq_printf(m, ",mountvers=%u", nfss->mountd_version);
399aa699473SStanislav Kinsbursky 	if ((nfss->mountd_port &&
400aa699473SStanislav Kinsbursky 		nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
401aa699473SStanislav Kinsbursky 		showdefaults)
40282d101d5SChuck Lever 		seq_printf(m, ",mountport=%u", nfss->mountd_port);
40382d101d5SChuck Lever 
404ee671b01SJeff Layton 	nfs_show_mountd_netid(m, nfss, showdefaults);
40582d101d5SChuck Lever }
40682d101d5SChuck Lever 
40789d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
nfs_show_nfsv4_options(struct seq_file * m,struct nfs_server * nfss,int showdefaults)4080be8189fSTrond Myklebust static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
4090be8189fSTrond Myklebust 				    int showdefaults)
4100be8189fSTrond Myklebust {
4110be8189fSTrond Myklebust 	struct nfs_client *clp = nfss->nfs_client;
4120be8189fSTrond Myklebust 
4130be8189fSTrond Myklebust 	seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
4140be8189fSTrond Myklebust }
4150be8189fSTrond Myklebust #else
nfs_show_nfsv4_options(struct seq_file * m,struct nfs_server * nfss,int showdefaults)4160be8189fSTrond Myklebust static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
4170be8189fSTrond Myklebust 				    int showdefaults)
4180be8189fSTrond Myklebust {
4190be8189fSTrond Myklebust }
4200be8189fSTrond Myklebust #endif
4210be8189fSTrond Myklebust 
nfs_show_nfs_version(struct seq_file * m,unsigned int version,unsigned int minorversion)4227bbceb6fSTrond Myklebust static void nfs_show_nfs_version(struct seq_file *m,
4237bbceb6fSTrond Myklebust 		unsigned int version,
4247bbceb6fSTrond Myklebust 		unsigned int minorversion)
4257bbceb6fSTrond Myklebust {
4267bbceb6fSTrond Myklebust 	seq_printf(m, ",vers=%u", version);
4277bbceb6fSTrond Myklebust 	if (version == 4)
4287bbceb6fSTrond Myklebust 		seq_printf(m, ".%u", minorversion);
4297bbceb6fSTrond Myklebust }
4307bbceb6fSTrond Myklebust 
431f7b422b1SDavid Howells /*
432f7b422b1SDavid Howells  * Describe the mount options in force on this server representation
433f7b422b1SDavid Howells  */
nfs_show_mount_options(struct seq_file * m,struct nfs_server * nfss,int showdefaults)43482d101d5SChuck Lever static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
43582d101d5SChuck Lever 				   int showdefaults)
436f7b422b1SDavid Howells {
437509de811SDavid Howells 	static const struct proc_nfs_info {
438f7b422b1SDavid Howells 		int flag;
439509de811SDavid Howells 		const char *str;
440509de811SDavid Howells 		const char *nostr;
441f7b422b1SDavid Howells 	} nfs_info[] = {
44291a575e1STrond Myklebust 		{ NFS_MOUNT_SOFT, ",soft", "" },
44391a575e1STrond Myklebust 		{ NFS_MOUNT_SOFTERR, ",softerr", "" },
444c74dfe97STrond Myklebust 		{ NFS_MOUNT_SOFTREVAL, ",softreval", "" },
44582d101d5SChuck Lever 		{ NFS_MOUNT_POSIX, ",posix", "" },
446f7b422b1SDavid Howells 		{ NFS_MOUNT_NOCTO, ",nocto", "" },
447f7b422b1SDavid Howells 		{ NFS_MOUNT_NOAC, ",noac", "" },
448f7b422b1SDavid Howells 		{ NFS_MOUNT_NONLM, ",nolock", "" },
449f7b422b1SDavid Howells 		{ NFS_MOUNT_NOACL, ",noacl", "" },
45074dd34e6SSteve Dickson 		{ NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
45175180df2STrond Myklebust 		{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
452d740351bSChuck Lever 		{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
453f7b422b1SDavid Howells 		{ 0, NULL, NULL }
454f7b422b1SDavid Howells 	};
455509de811SDavid Howells 	const struct proc_nfs_info *nfs_infop;
4568fa5c000SDavid Howells 	struct nfs_client *clp = nfss->nfs_client;
45782d101d5SChuck Lever 	u32 version = clp->rpc_ops->version;
4587c563cc9SSuresh Jayaraman 	int local_flock, local_fcntl;
459f7b422b1SDavid Howells 
4607bbceb6fSTrond Myklebust 	nfs_show_nfs_version(m, version, clp->cl_minorversion);
4612d767432SChuck Lever 	seq_printf(m, ",rsize=%u", nfss->rsize);
4622d767432SChuck Lever 	seq_printf(m, ",wsize=%u", nfss->wsize);
46382d101d5SChuck Lever 	if (nfss->bsize != 0)
46482d101d5SChuck Lever 		seq_printf(m, ",bsize=%u", nfss->bsize);
46582d101d5SChuck Lever 	seq_printf(m, ",namlen=%u", nfss->namelen);
4660e0cab74SChuck Lever 	if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
4672d767432SChuck Lever 		seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
4680e0cab74SChuck Lever 	if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
4692d767432SChuck Lever 		seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
4700e0cab74SChuck Lever 	if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
4712d767432SChuck Lever 		seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
4720e0cab74SChuck Lever 	if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
4732d767432SChuck Lever 		seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
47491a575e1STrond Myklebust 	if (!(nfss->flags & (NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR)))
47591a575e1STrond Myklebust 			seq_puts(m, ",hard");
476f7b422b1SDavid Howells 	for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
477f7b422b1SDavid Howells 		if (nfss->flags & nfs_infop->flag)
478f7b422b1SDavid Howells 			seq_puts(m, nfs_infop->str);
479f7b422b1SDavid Howells 		else
480f7b422b1SDavid Howells 			seq_puts(m, nfs_infop->nostr);
481f7b422b1SDavid Howells 	}
4822446ab60STrond Myklebust 	rcu_read_lock();
48356928eddS\"Talpey, Thomas\ 	seq_printf(m, ",proto=%s",
484ee671b01SJeff Layton 		   rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
4852446ab60STrond Myklebust 	rcu_read_unlock();
486fd87c8b7STrond Myklebust 	if (clp->cl_nconnect > 0)
487fd87c8b7STrond Myklebust 		seq_printf(m, ",nconnect=%u", clp->cl_nconnect);
48882d101d5SChuck Lever 	if (version == 4) {
4897e134205SOlga Kornievskaia 		if (clp->cl_max_connect > 1)
4907e134205SOlga Kornievskaia 			seq_printf(m, ",max_connect=%u", clp->cl_max_connect);
49182d101d5SChuck Lever 		if (nfss->port != NFS_PORT)
49282d101d5SChuck Lever 			seq_printf(m, ",port=%u", nfss->port);
49382d101d5SChuck Lever 	} else
49482d101d5SChuck Lever 		if (nfss->port)
49582d101d5SChuck Lever 			seq_printf(m, ",port=%u", nfss->port);
49682d101d5SChuck Lever 
49733170233STrond Myklebust 	seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
49833170233STrond Myklebust 	seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
49981039f1fSTrond Myklebust 	seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
500c8407f2eSChuck Lever 	switch (clp->cl_xprtsec.policy) {
501c8407f2eSChuck Lever 	case RPC_XPRTSEC_TLS_ANON:
502c8407f2eSChuck Lever 		seq_puts(m, ",xprtsec=tls");
503c8407f2eSChuck Lever 		break;
504c8407f2eSChuck Lever 	case RPC_XPRTSEC_TLS_X509:
505c8407f2eSChuck Lever 		seq_puts(m, ",xprtsec=mtls");
506c8407f2eSChuck Lever 		break;
507c8407f2eSChuck Lever 	default:
508c8407f2eSChuck Lever 		break;
509c8407f2eSChuck Lever 	}
51082d101d5SChuck Lever 
51182d101d5SChuck Lever 	if (version != 4)
51282d101d5SChuck Lever 		nfs_show_mountd_options(m, nfss, showdefaults);
5130be8189fSTrond Myklebust 	else
5140be8189fSTrond Myklebust 		nfs_show_nfsv4_options(m, nfss, showdefaults);
51582d101d5SChuck Lever 
516b797cac7SDavid Howells 	if (nfss->options & NFS_OPTION_FSCACHE)
5171c316e39SMarkus Elfring 		seq_puts(m, ",fsc");
5189b00c643SPatrick J. LoPresti 
51989652617SChuck Lever 	if (nfss->options & NFS_OPTION_MIGRATION)
5201c316e39SMarkus Elfring 		seq_puts(m, ",migration");
52189652617SChuck Lever 
5229b00c643SPatrick J. LoPresti 	if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
5239b00c643SPatrick J. LoPresti 		if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
5241c316e39SMarkus Elfring 			seq_puts(m, ",lookupcache=none");
5259b00c643SPatrick J. LoPresti 		else
5261c316e39SMarkus Elfring 			seq_puts(m, ",lookupcache=pos");
5279b00c643SPatrick J. LoPresti 	}
5287c563cc9SSuresh Jayaraman 
5297c563cc9SSuresh Jayaraman 	local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
5307c563cc9SSuresh Jayaraman 	local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
5317c563cc9SSuresh Jayaraman 
5327c563cc9SSuresh Jayaraman 	if (!local_flock && !local_fcntl)
5331c316e39SMarkus Elfring 		seq_puts(m, ",local_lock=none");
5347c563cc9SSuresh Jayaraman 	else if (local_flock && local_fcntl)
5351c316e39SMarkus Elfring 		seq_puts(m, ",local_lock=all");
5367c563cc9SSuresh Jayaraman 	else if (local_flock)
5371c316e39SMarkus Elfring 		seq_puts(m, ",local_lock=flock");
5387c563cc9SSuresh Jayaraman 	else
5391c316e39SMarkus Elfring 		seq_puts(m, ",local_lock=posix");
5407ae017c7STrond Myklebust 
5417ae017c7STrond Myklebust 	if (nfss->flags & NFS_MOUNT_WRITE_EAGER) {
5427ae017c7STrond Myklebust 		if (nfss->flags & NFS_MOUNT_WRITE_WAIT)
5437ae017c7STrond Myklebust 			seq_puts(m, ",write=wait");
5447ae017c7STrond Myklebust 		else
5457ae017c7STrond Myklebust 			seq_puts(m, ",write=eager");
5467ae017c7STrond Myklebust 	}
547f7b422b1SDavid Howells }
548f7b422b1SDavid Howells 
549f7b422b1SDavid Howells /*
550f7b422b1SDavid Howells  * Describe the mount options on this VFS mountpoint
551f7b422b1SDavid Howells  */
nfs_show_options(struct seq_file * m,struct dentry * root)552fbdefd64SBryan Schumaker int nfs_show_options(struct seq_file *m, struct dentry *root)
553f7b422b1SDavid Howells {
55434c80b1dSAl Viro 	struct nfs_server *nfss = NFS_SB(root->d_sb);
555f7b422b1SDavid Howells 
556f7b422b1SDavid Howells 	nfs_show_mount_options(m, nfss, 0);
557f7b422b1SDavid Howells 
5582446ab60STrond Myklebust 	rcu_read_lock();
5595d8515caSChuck Lever 	seq_printf(m, ",addr=%s",
5605d8515caSChuck Lever 			rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
5615d8515caSChuck Lever 							RPC_DISPLAY_ADDR));
5622446ab60STrond Myklebust 	rcu_read_unlock();
563f7b422b1SDavid Howells 
564f7b422b1SDavid Howells 	return 0;
565f7b422b1SDavid Howells }
56689d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_show_options);
56745402c38SH Hartley Sweeten 
56889d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
show_lease(struct seq_file * m,struct nfs_server * server)5691a7441b2SDave Wysochanski static void show_lease(struct seq_file *m, struct nfs_server *server)
5701a7441b2SDave Wysochanski {
5711a7441b2SDave Wysochanski 	struct nfs_client *clp = server->nfs_client;
5721a7441b2SDave Wysochanski 	unsigned long expire;
5731a7441b2SDave Wysochanski 
5741a7441b2SDave Wysochanski 	seq_printf(m, ",lease_time=%ld", clp->cl_lease_time / HZ);
5751a7441b2SDave Wysochanski 	expire = clp->cl_last_renewal + clp->cl_lease_time;
5761a7441b2SDave Wysochanski 	seq_printf(m, ",lease_expired=%ld",
5771a7441b2SDave Wysochanski 		   time_after(expire, jiffies) ?  0 : (jiffies - expire) / HZ);
5781a7441b2SDave Wysochanski }
579ae50c0b5SJ. Bruce Fields #ifdef CONFIG_NFS_V4_1
show_sessions(struct seq_file * m,struct nfs_server * server)58045402c38SH Hartley Sweeten static void show_sessions(struct seq_file *m, struct nfs_server *server)
581ae50c0b5SJ. Bruce Fields {
582ae50c0b5SJ. Bruce Fields 	if (nfs4_has_session(server->nfs_client))
5831c316e39SMarkus Elfring 		seq_puts(m, ",sessions");
584ae50c0b5SJ. Bruce Fields }
585ae50c0b5SJ. Bruce Fields #else
show_sessions(struct seq_file * m,struct nfs_server * server)58645402c38SH Hartley Sweeten static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
58745402c38SH Hartley Sweeten #endif
588ae50c0b5SJ. Bruce Fields #endif
589ae50c0b5SJ. Bruce Fields 
590ae50c0b5SJ. Bruce Fields #ifdef CONFIG_NFS_V4_1
show_pnfs(struct seq_file * m,struct nfs_server * server)59145402c38SH Hartley Sweeten static void show_pnfs(struct seq_file *m, struct nfs_server *server)
592ae50c0b5SJ. Bruce Fields {
593ae50c0b5SJ. Bruce Fields 	seq_printf(m, ",pnfs=");
594ae50c0b5SJ. Bruce Fields 	if (server->pnfs_curr_ld)
595ae50c0b5SJ. Bruce Fields 		seq_printf(m, "%s", server->pnfs_curr_ld->name);
596ae50c0b5SJ. Bruce Fields 	else
597ae50c0b5SJ. Bruce Fields 		seq_printf(m, "not configured");
598ae50c0b5SJ. Bruce Fields }
5997e03b7ccSTrond Myklebust 
show_implementation_id(struct seq_file * m,struct nfs_server * nfss)6007e03b7ccSTrond Myklebust static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
6017e03b7ccSTrond Myklebust {
60259155546SChuck Lever 	if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
60359155546SChuck Lever 		struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
6047e03b7ccSTrond Myklebust 		seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
6057e03b7ccSTrond Myklebust 			   "date='%llu,%u'",
6067e03b7ccSTrond Myklebust 			   impl_id->name, impl_id->domain,
6077e03b7ccSTrond Myklebust 			   impl_id->date.seconds, impl_id->date.nseconds);
6087e03b7ccSTrond Myklebust 	}
6097e03b7ccSTrond Myklebust }
61045402c38SH Hartley Sweeten #else
61189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
show_pnfs(struct seq_file * m,struct nfs_server * server)6127e03b7ccSTrond Myklebust static void show_pnfs(struct seq_file *m, struct nfs_server *server)
6137e03b7ccSTrond Myklebust {
6147e03b7ccSTrond Myklebust }
61545402c38SH Hartley Sweeten #endif
show_implementation_id(struct seq_file * m,struct nfs_server * nfss)6167e03b7ccSTrond Myklebust static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
6177e03b7ccSTrond Myklebust {
6187e03b7ccSTrond Myklebust }
61945402c38SH Hartley Sweeten #endif
620f7b422b1SDavid Howells 
nfs_show_devname(struct seq_file * m,struct dentry * root)621fbdefd64SBryan Schumaker int nfs_show_devname(struct seq_file *m, struct dentry *root)
622c7f404b4SAl Viro {
623c7f404b4SAl Viro 	char *page = (char *) __get_free_page(GFP_KERNEL);
624c7f404b4SAl Viro 	char *devname, *dummy;
625c7f404b4SAl Viro 	int err = 0;
626c7f404b4SAl Viro 	if (!page)
627c7f404b4SAl Viro 		return -ENOMEM;
62897a54868SBen Hutchings 	devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
629c7f404b4SAl Viro 	if (IS_ERR(devname))
630c7f404b4SAl Viro 		err = PTR_ERR(devname);
631c7f404b4SAl Viro 	else
632c7f404b4SAl Viro 		seq_escape(m, devname, " \t\n\\");
633c7f404b4SAl Viro 	free_page((unsigned long)page);
634c7f404b4SAl Viro 	return err;
635c7f404b4SAl Viro }
63689d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_show_devname);
637c7f404b4SAl Viro 
nfs_show_path(struct seq_file * m,struct dentry * dentry)638fbdefd64SBryan Schumaker int nfs_show_path(struct seq_file *m, struct dentry *dentry)
639c7f404b4SAl Viro {
640c7f404b4SAl Viro 	seq_puts(m, "/");
641c7f404b4SAl Viro 	return 0;
642c7f404b4SAl Viro }
64389d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_show_path);
644c7f404b4SAl Viro 
645f7b422b1SDavid Howells /*
646f7b422b1SDavid Howells  * Present statistical information for this VFS mountpoint
647f7b422b1SDavid Howells  */
nfs_show_stats(struct seq_file * m,struct dentry * root)648fbdefd64SBryan Schumaker int nfs_show_stats(struct seq_file *m, struct dentry *root)
649f7b422b1SDavid Howells {
650f7b422b1SDavid Howells 	int i, cpu;
65164132379SAl Viro 	struct nfs_server *nfss = NFS_SB(root->d_sb);
652f7b422b1SDavid Howells 	struct rpc_auth *auth = nfss->client->cl_auth;
653f7b422b1SDavid Howells 	struct nfs_iostats totals = { };
654f7b422b1SDavid Howells 
655f7b422b1SDavid Howells 	seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
656f7b422b1SDavid Howells 
657f7b422b1SDavid Howells 	/*
658f7b422b1SDavid Howells 	 * Display all mount option settings
659f7b422b1SDavid Howells 	 */
6601c316e39SMarkus Elfring 	seq_puts(m, "\n\topts:\t");
661bc98a42cSDavid Howells 	seq_puts(m, sb_rdonly(root->d_sb) ? "ro" : "rw");
6621751e8a6SLinus Torvalds 	seq_puts(m, root->d_sb->s_flags & SB_SYNCHRONOUS ? ",sync" : "");
6631751e8a6SLinus Torvalds 	seq_puts(m, root->d_sb->s_flags & SB_NOATIME ? ",noatime" : "");
6641751e8a6SLinus Torvalds 	seq_puts(m, root->d_sb->s_flags & SB_NODIRATIME ? ",nodiratime" : "");
665f7b422b1SDavid Howells 	nfs_show_mount_options(m, nfss, 1);
666f7b422b1SDavid Howells 
667f7b422b1SDavid Howells 	seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
668f7b422b1SDavid Howells 
6697e03b7ccSTrond Myklebust 	show_implementation_id(m, nfss);
6707d2ed9acSWeston Andros Adamson 
6711c316e39SMarkus Elfring 	seq_puts(m, "\n\tcaps:\t");
672f7b422b1SDavid Howells 	seq_printf(m, "caps=0x%x", nfss->caps);
6732d767432SChuck Lever 	seq_printf(m, ",wtmult=%u", nfss->wtmult);
6742d767432SChuck Lever 	seq_printf(m, ",dtsize=%u", nfss->dtsize);
6752d767432SChuck Lever 	seq_printf(m, ",bsize=%u", nfss->bsize);
6762d767432SChuck Lever 	seq_printf(m, ",namlen=%u", nfss->namelen);
677f7b422b1SDavid Howells 
67889d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
67940c55319STrond Myklebust 	if (nfss->nfs_client->rpc_ops->version == 4) {
6801c316e39SMarkus Elfring 		seq_puts(m, "\n\tnfsv4:\t");
681f7b422b1SDavid Howells 		seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
682f7b422b1SDavid Howells 		seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
683a09df2caSDavid Quigley 		seq_printf(m, ",bm2=0x%x", nfss->attr_bitmask[2]);
684f7b422b1SDavid Howells 		seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
685ae50c0b5SJ. Bruce Fields 		show_sessions(m, nfss);
686ae50c0b5SJ. Bruce Fields 		show_pnfs(m, nfss);
6871a7441b2SDave Wysochanski 		show_lease(m, nfss);
688f7b422b1SDavid Howells 	}
689f7b422b1SDavid Howells #endif
690f7b422b1SDavid Howells 
691f7b422b1SDavid Howells 	/*
692f7b422b1SDavid Howells 	 * Display security flavor in effect for this mount
693f7b422b1SDavid Howells 	 */
6942d767432SChuck Lever 	seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
695f7b422b1SDavid Howells 	if (auth->au_flavor)
6962d767432SChuck Lever 		seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
697f7b422b1SDavid Howells 
698f7b422b1SDavid Howells 	/*
699f7b422b1SDavid Howells 	 * Display superblock I/O counters
700f7b422b1SDavid Howells 	 */
701f7b422b1SDavid Howells 	for_each_possible_cpu(cpu) {
702f7b422b1SDavid Howells 		struct nfs_iostats *stats;
703f7b422b1SDavid Howells 
704f7b422b1SDavid Howells 		preempt_disable();
705f7b422b1SDavid Howells 		stats = per_cpu_ptr(nfss->io_stats, cpu);
706f7b422b1SDavid Howells 
707f7b422b1SDavid Howells 		for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
708f7b422b1SDavid Howells 			totals.events[i] += stats->events[i];
709f7b422b1SDavid Howells 		for (i = 0; i < __NFSIOS_BYTESMAX; i++)
710f7b422b1SDavid Howells 			totals.bytes[i] += stats->bytes[i];
711f7b422b1SDavid Howells 
712f7b422b1SDavid Howells 		preempt_enable();
713f7b422b1SDavid Howells 	}
714f7b422b1SDavid Howells 
7151c316e39SMarkus Elfring 	seq_puts(m, "\n\tevents:\t");
716f7b422b1SDavid Howells 	for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
717f7b422b1SDavid Howells 		seq_printf(m, "%lu ", totals.events[i]);
7181c316e39SMarkus Elfring 	seq_puts(m, "\n\tbytes:\t");
719f7b422b1SDavid Howells 	for (i = 0; i < __NFSIOS_BYTESMAX; i++)
720f7b422b1SDavid Howells 		seq_printf(m, "%Lu ", totals.bytes[i]);
7219bcaa35cSMarkus Elfring 	seq_putc(m, '\n');
722f7b422b1SDavid Howells 
723016583d7SDave Wysochanski 	rpc_clnt_show_stats(m, nfss->client);
724f7b422b1SDavid Howells 
725f7b422b1SDavid Howells 	return 0;
726f7b422b1SDavid Howells }
72789d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_show_stats);
728f7b422b1SDavid Howells 
729f7b422b1SDavid Howells /*
730f7b422b1SDavid Howells  * Begin unmount by attempting to remove all automounted mountpoints we added
73154ceac45SDavid Howells  * in response to xdev traversals and referrals
732f7b422b1SDavid Howells  */
nfs_umount_begin(struct super_block * sb)733fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *sb)
734f7b422b1SDavid Howells {
73567e55205SAlessio Igor Bogani 	struct nfs_server *server;
736fc6ae3cfSTrond Myklebust 	struct rpc_clnt *rpc;
737fc6ae3cfSTrond Myklebust 
73867e55205SAlessio Igor Bogani 	server = NFS_SB(sb);
739fc6ae3cfSTrond Myklebust 	/* -EIO all pending I/O */
740fc6ae3cfSTrond Myklebust 	rpc = server->client_acl;
741fc6ae3cfSTrond Myklebust 	if (!IS_ERR(rpc))
742fc6ae3cfSTrond Myklebust 		rpc_killall_tasks(rpc);
743fc6ae3cfSTrond Myklebust 	rpc = server->client;
744fc6ae3cfSTrond Myklebust 	if (!IS_ERR(rpc))
745fc6ae3cfSTrond Myklebust 		rpc_killall_tasks(rpc);
746f7b422b1SDavid Howells }
74789d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_umount_begin);
748f7b422b1SDavid Howells 
7494d4b69ddSWeston Andros Adamson /*
7504d4b69ddSWeston Andros Adamson  * Return true if 'match' is in auth_info or auth_info is empty.
7514d4b69ddSWeston Andros Adamson  * Return false otherwise.
7524d4b69ddSWeston Andros Adamson  */
nfs_auth_info_match(const struct nfs_auth_info * auth_info,rpc_authflavor_t match)7534d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *auth_info,
7544d4b69ddSWeston Andros Adamson 			 rpc_authflavor_t match)
7554d4b69ddSWeston Andros Adamson {
7564d4b69ddSWeston Andros Adamson 	int i;
7574d4b69ddSWeston Andros Adamson 
7584d4b69ddSWeston Andros Adamson 	if (!auth_info->flavor_len)
7594d4b69ddSWeston Andros Adamson 		return true;
7604d4b69ddSWeston Andros Adamson 
7614d4b69ddSWeston Andros Adamson 	for (i = 0; i < auth_info->flavor_len; i++) {
7624d4b69ddSWeston Andros Adamson 		if (auth_info->flavors[i] == match)
7634d4b69ddSWeston Andros Adamson 			return true;
7644d4b69ddSWeston Andros Adamson 	}
7654d4b69ddSWeston Andros Adamson 	return false;
7664d4b69ddSWeston Andros Adamson }
7674d4b69ddSWeston Andros Adamson EXPORT_SYMBOL_GPL(nfs_auth_info_match);
7684d4b69ddSWeston Andros Adamson 
7694d4b69ddSWeston Andros Adamson /*
77038465f5dSScott Mayhew  * Ensure that a specified authtype in ctx->auth_info is supported by
77138465f5dSScott Mayhew  * the server. Returns 0 and sets ctx->selected_flavor if it's ok, and
7724d4b69ddSWeston Andros Adamson  * -EACCES if not.
773ec88f28dSChuck Lever  */
nfs_verify_authflavors(struct nfs_fs_context * ctx,rpc_authflavor_t * server_authlist,unsigned int count)77438465f5dSScott Mayhew static int nfs_verify_authflavors(struct nfs_fs_context *ctx,
7755eb005caSDavid Howells 				  rpc_authflavor_t *server_authlist,
7765eb005caSDavid Howells 				  unsigned int count)
777ec88f28dSChuck Lever {
7784d4b69ddSWeston Andros Adamson 	rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR;
77953a75f22SChuck Lever 	bool found_auth_null = false;
7809111c95bSJeff Layton 	unsigned int i;
7814580a92dSChuck Lever 
7824580a92dSChuck Lever 	/*
783d497ab97SWeston Andros Adamson 	 * If the sec= mount option is used, the specified flavor or AUTH_NULL
784d497ab97SWeston Andros Adamson 	 * must be in the list returned by the server.
785d497ab97SWeston Andros Adamson 	 *
786d497ab97SWeston Andros Adamson 	 * AUTH_NULL has a special meaning when it's in the server list - it
787d497ab97SWeston Andros Adamson 	 * means that the server will ignore the rpc creds, so any flavor
788e68fd7c8SSteve Dickson 	 * can be used but still use the sec= that was specified.
78953a75f22SChuck Lever 	 *
79053a75f22SChuck Lever 	 * Note also that the MNT procedure in MNTv1 does not return a list
79153a75f22SChuck Lever 	 * of supported security flavors. In this case, nfs_mount() fabricates
79253a75f22SChuck Lever 	 * a security flavor list containing just AUTH_NULL.
793d497ab97SWeston Andros Adamson 	 */
794d497ab97SWeston Andros Adamson 	for (i = 0; i < count; i++) {
7954d4b69ddSWeston Andros Adamson 		flavor = server_authlist[i];
7964d4b69ddSWeston Andros Adamson 
79738465f5dSScott Mayhew 		if (nfs_auth_info_match(&ctx->auth_info, flavor))
798e68fd7c8SSteve Dickson 			goto out;
799e68fd7c8SSteve Dickson 
800e68fd7c8SSteve Dickson 		if (flavor == RPC_AUTH_NULL)
80153a75f22SChuck Lever 			found_auth_null = true;
802e68fd7c8SSteve Dickson 	}
803e68fd7c8SSteve Dickson 
80453a75f22SChuck Lever 	if (found_auth_null) {
80538465f5dSScott Mayhew 		flavor = ctx->auth_info.flavors[0];
806d497ab97SWeston Andros Adamson 		goto out;
807d497ab97SWeston Andros Adamson 	}
8089111c95bSJeff Layton 
8094d4b69ddSWeston Andros Adamson 	dfprintk(MOUNT,
8104d4b69ddSWeston Andros Adamson 		 "NFS: specified auth flavors not supported by server\n");
811d497ab97SWeston Andros Adamson 	return -EACCES;
8129111c95bSJeff Layton 
8139111c95bSJeff Layton out:
81438465f5dSScott Mayhew 	ctx->selected_flavor = flavor;
81538465f5dSScott Mayhew 	dfprintk(MOUNT, "NFS: using auth flavor %u\n", ctx->selected_flavor);
8169111c95bSJeff Layton 	return 0;
817ec88f28dSChuck Lever }
818ec88f28dSChuck Lever 
819ec88f28dSChuck Lever /*
8200076d7b7SChuck Lever  * Use the remote server's MOUNT service to request the NFS file handle
8210076d7b7SChuck Lever  * corresponding to the provided path.
8220076d7b7SChuck Lever  */
nfs_request_mount(struct fs_context * fc,struct nfs_fh * root_fh,rpc_authflavor_t * server_authlist,unsigned int * server_authlist_len)82362a55d08SScott Mayhew static int nfs_request_mount(struct fs_context *fc,
824294ae81dSJeff Layton 			     struct nfs_fh *root_fh,
825294ae81dSJeff Layton 			     rpc_authflavor_t *server_authlist,
826294ae81dSJeff Layton 			     unsigned int *server_authlist_len)
8270076d7b7SChuck Lever {
82862a55d08SScott Mayhew 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
829c5d120f8SChuck Lever 	struct nfs_mount_request request = {
830cf0d7e7fSKees Cook 		.sap		= &ctx->mount_server._address,
83138465f5dSScott Mayhew 		.dirpath	= ctx->nfs_server.export_path,
83238465f5dSScott Mayhew 		.protocol	= ctx->mount_server.protocol,
833c5d120f8SChuck Lever 		.fh		= root_fh,
83438465f5dSScott Mayhew 		.noresvport	= ctx->flags & NFS_MOUNT_NORESVPORT,
835294ae81dSJeff Layton 		.auth_flav_len	= server_authlist_len,
836ec88f28dSChuck Lever 		.auth_flavs	= server_authlist,
83762a55d08SScott Mayhew 		.net		= fc->net_ns,
838c5d120f8SChuck Lever 	};
8394c568017SChuck Lever 	int status;
8400076d7b7SChuck Lever 
84138465f5dSScott Mayhew 	if (ctx->mount_server.version == 0) {
84238465f5dSScott Mayhew 		switch (ctx->version) {
8438a6e5debSTrond Myklebust 			default:
84438465f5dSScott Mayhew 				ctx->mount_server.version = NFS_MNT3_VERSION;
8458a6e5debSTrond Myklebust 				break;
8468a6e5debSTrond Myklebust 			case 2:
84738465f5dSScott Mayhew 				ctx->mount_server.version = NFS_MNT_VERSION;
8480076d7b7SChuck Lever 		}
8498a6e5debSTrond Myklebust 	}
85038465f5dSScott Mayhew 	request.version = ctx->mount_server.version;
8510076d7b7SChuck Lever 
85238465f5dSScott Mayhew 	if (ctx->mount_server.hostname)
85338465f5dSScott Mayhew 		request.hostname = ctx->mount_server.hostname;
85433832034SChuck Lever 	else
85538465f5dSScott Mayhew 		request.hostname = ctx->nfs_server.hostname;
85633832034SChuck Lever 
8570076d7b7SChuck Lever 	/*
8580076d7b7SChuck Lever 	 * Construct the mount server's address.
8590076d7b7SChuck Lever 	 */
86038465f5dSScott Mayhew 	if (ctx->mount_server.address.sa_family == AF_UNSPEC) {
861cf0d7e7fSKees Cook 		memcpy(request.sap, &ctx->nfs_server._address,
86238465f5dSScott Mayhew 		       ctx->nfs_server.addrlen);
86338465f5dSScott Mayhew 		ctx->mount_server.addrlen = ctx->nfs_server.addrlen;
8644c568017SChuck Lever 	}
86538465f5dSScott Mayhew 	request.salen = ctx->mount_server.addrlen;
86638465f5dSScott Mayhew 	nfs_set_port(request.sap, &ctx->mount_server.port, 0);
8670076d7b7SChuck Lever 
8680076d7b7SChuck Lever 	/*
8690076d7b7SChuck Lever 	 * Now ask the mount server to map our export path
8700076d7b7SChuck Lever 	 * to a file handle.
8710076d7b7SChuck Lever 	 */
872*351f0339SNeilBrown 	if ((request.protocol == XPRT_TRANSPORT_UDP) ==
873*351f0339SNeilBrown 	    !(ctx->flags & NFS_MOUNT_TCP))
874*351f0339SNeilBrown 		/*
875*351f0339SNeilBrown 		 * NFS protocol and mount protocol are both UDP or neither UDP
876*351f0339SNeilBrown 		 * so timeouts are compatible.  Use NFS timeouts for MOUNT
877*351f0339SNeilBrown 		 */
878c9301cb3SEryu Guan 		status = nfs_mount(&request, ctx->timeo, ctx->retrans);
879*351f0339SNeilBrown 	else
880*351f0339SNeilBrown 		status = nfs_mount(&request, NFS_UNSPEC_TIMEO, NFS_UNSPEC_RETRANS);
881ec88f28dSChuck Lever 	if (status != 0) {
882396cee97SChuck Lever 		dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
883c5d120f8SChuck Lever 				request.hostname, status);
8840076d7b7SChuck Lever 		return status;
8850076d7b7SChuck Lever 	}
8860076d7b7SChuck Lever 
8879111c95bSJeff Layton 	return 0;
888ec88f28dSChuck Lever }
889ec88f28dSChuck Lever 
nfs_try_mount_request(struct fs_context * fc)89062a55d08SScott Mayhew static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
891d17540c6SJeff Layton {
89262a55d08SScott Mayhew 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
893d17540c6SJeff Layton 	int status;
8949111c95bSJeff Layton 	unsigned int i;
8959111c95bSJeff Layton 	bool tried_auth_unix = false;
8969111c95bSJeff Layton 	bool auth_null_in_list = false;
8979111c95bSJeff Layton 	struct nfs_server *server = ERR_PTR(-EACCES);
898294ae81dSJeff Layton 	rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS];
899294ae81dSJeff Layton 	unsigned int authlist_len = ARRAY_SIZE(authlist);
900d17540c6SJeff Layton 
90162a55d08SScott Mayhew 	status = nfs_request_mount(fc, ctx->mntfh, authlist, &authlist_len);
902d17540c6SJeff Layton 	if (status)
903d17540c6SJeff Layton 		return ERR_PTR(status);
904d17540c6SJeff Layton 
9059111c95bSJeff Layton 	/*
9069111c95bSJeff Layton 	 * Was a sec= authflavor specified in the options? First, verify
9079111c95bSJeff Layton 	 * whether the server supports it, and then just try to use it if so.
9089111c95bSJeff Layton 	 */
9095eb005caSDavid Howells 	if (ctx->auth_info.flavor_len > 0) {
9105eb005caSDavid Howells 		status = nfs_verify_authflavors(ctx, authlist, authlist_len);
911a3f73c27SWeston Andros Adamson 		dfprintk(MOUNT, "NFS: using auth flavor %u\n",
9125eb005caSDavid Howells 			 ctx->selected_flavor);
9139111c95bSJeff Layton 		if (status)
9149111c95bSJeff Layton 			return ERR_PTR(status);
91562a55d08SScott Mayhew 		return ctx->nfs_mod->rpc_ops->create_server(fc);
9169111c95bSJeff Layton 	}
9179111c95bSJeff Layton 
9189111c95bSJeff Layton 	/*
9199111c95bSJeff Layton 	 * No sec= option was provided. RFC 2623, section 2.7 suggests we
9209111c95bSJeff Layton 	 * SHOULD prefer the flavor listed first. However, some servers list
9219111c95bSJeff Layton 	 * AUTH_NULL first. Avoid ever choosing AUTH_NULL.
9229111c95bSJeff Layton 	 */
9239111c95bSJeff Layton 	for (i = 0; i < authlist_len; ++i) {
9249111c95bSJeff Layton 		rpc_authflavor_t flavor;
9259111c95bSJeff Layton 		struct rpcsec_gss_info info;
9269111c95bSJeff Layton 
9279111c95bSJeff Layton 		flavor = authlist[i];
9289111c95bSJeff Layton 		switch (flavor) {
9299111c95bSJeff Layton 		case RPC_AUTH_UNIX:
9309111c95bSJeff Layton 			tried_auth_unix = true;
9319111c95bSJeff Layton 			break;
9329111c95bSJeff Layton 		case RPC_AUTH_NULL:
9339111c95bSJeff Layton 			auth_null_in_list = true;
9349111c95bSJeff Layton 			continue;
9359111c95bSJeff Layton 		default:
9369111c95bSJeff Layton 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
9379111c95bSJeff Layton 				continue;
938fb08334bSNick Desaulniers 			break;
9399111c95bSJeff Layton 		}
9409111c95bSJeff Layton 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
9415eb005caSDavid Howells 		ctx->selected_flavor = flavor;
94262a55d08SScott Mayhew 		server = ctx->nfs_mod->rpc_ops->create_server(fc);
9439111c95bSJeff Layton 		if (!IS_ERR(server))
9449111c95bSJeff Layton 			return server;
9459111c95bSJeff Layton 	}
9469111c95bSJeff Layton 
9479111c95bSJeff Layton 	/*
9489111c95bSJeff Layton 	 * Nothing we tried so far worked. At this point, give up if we've
9499111c95bSJeff Layton 	 * already tried AUTH_UNIX or if the server's list doesn't contain
9509111c95bSJeff Layton 	 * AUTH_NULL
9519111c95bSJeff Layton 	 */
9529111c95bSJeff Layton 	if (tried_auth_unix || !auth_null_in_list)
9539111c95bSJeff Layton 		return server;
9549111c95bSJeff Layton 
9559111c95bSJeff Layton 	/* Last chance! Try AUTH_UNIX */
9569111c95bSJeff Layton 	dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", RPC_AUTH_UNIX);
9575eb005caSDavid Howells 	ctx->selected_flavor = RPC_AUTH_UNIX;
95862a55d08SScott Mayhew 	return ctx->nfs_mod->rpc_ops->create_server(fc);
959d17540c6SJeff Layton }
960d17540c6SJeff Layton 
nfs_try_get_tree(struct fs_context * fc)961f2aedb71SDavid Howells int nfs_try_get_tree(struct fs_context *fc)
962486aa699SBryan Schumaker {
963f2aedb71SDavid Howells 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
964d17540c6SJeff Layton 
965f2aedb71SDavid Howells 	if (ctx->need_mount)
96662a55d08SScott Mayhew 		ctx->server = nfs_try_mount_request(fc);
967f2aedb71SDavid Howells 	else
96862a55d08SScott Mayhew 		ctx->server = ctx->nfs_mod->rpc_ops->create_server(fc);
969f2aedb71SDavid Howells 
970f2aedb71SDavid Howells 	return nfs_get_tree_common(fc);
971486aa699SBryan Schumaker }
972f2aedb71SDavid Howells EXPORT_SYMBOL_GPL(nfs_try_get_tree);
973f2aedb71SDavid Howells 
974486aa699SBryan Schumaker 
97571a6ec8aSScott Mayhew #define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \
976c8e47028SScott Mayhew 		| NFS_MOUNT_SECURE \
977c8e47028SScott Mayhew 		| NFS_MOUNT_TCP \
978c8e47028SScott Mayhew 		| NFS_MOUNT_VER3 \
979c8e47028SScott Mayhew 		| NFS_MOUNT_KERBEROS \
980c8e47028SScott Mayhew 		| NFS_MOUNT_NONLM \
981c8e47028SScott Mayhew 		| NFS_MOUNT_BROKEN_SUID \
982c8e47028SScott Mayhew 		| NFS_MOUNT_STRICTLOCK \
983c8e47028SScott Mayhew 		| NFS_MOUNT_LEGACY_INTERFACE)
984c8e47028SScott Mayhew 
98571a6ec8aSScott Mayhew #define NFS_MOUNT_CMP_FLAGMASK (NFS_REMOUNT_CMP_FLAGMASK & \
98671a6ec8aSScott Mayhew 		~(NFS_MOUNT_UNSHARED | NFS_MOUNT_NORESVPORT))
98771a6ec8aSScott Mayhew 
98848b605f8SJeff Layton static int
nfs_compare_remount_data(struct nfs_server * nfss,struct nfs_fs_context * ctx)98948b605f8SJeff Layton nfs_compare_remount_data(struct nfs_server *nfss,
9905eb005caSDavid Howells 			 struct nfs_fs_context *ctx)
99148b605f8SJeff Layton {
9925eb005caSDavid Howells 	if ((ctx->flags ^ nfss->flags) & NFS_REMOUNT_CMP_FLAGMASK ||
9935eb005caSDavid Howells 	    ctx->rsize != nfss->rsize ||
9945eb005caSDavid Howells 	    ctx->wsize != nfss->wsize ||
9955eb005caSDavid Howells 	    ctx->version != nfss->nfs_client->rpc_ops->version ||
9965eb005caSDavid Howells 	    ctx->minorversion != nfss->nfs_client->cl_minorversion ||
9975eb005caSDavid Howells 	    ctx->retrans != nfss->client->cl_timeout->to_retries ||
9985eb005caSDavid Howells 	    !nfs_auth_info_match(&ctx->auth_info, nfss->client->cl_auth->au_flavor) ||
9995eb005caSDavid Howells 	    ctx->acregmin != nfss->acregmin / HZ ||
10005eb005caSDavid Howells 	    ctx->acregmax != nfss->acregmax / HZ ||
10015eb005caSDavid Howells 	    ctx->acdirmin != nfss->acdirmin / HZ ||
10025eb005caSDavid Howells 	    ctx->acdirmax != nfss->acdirmax / HZ ||
10035eb005caSDavid Howells 	    ctx->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
10045eb005caSDavid Howells 	    (ctx->options & NFS_OPTION_FSCACHE) != (nfss->options & NFS_OPTION_FSCACHE) ||
10055eb005caSDavid Howells 	    ctx->nfs_server.port != nfss->port ||
10065eb005caSDavid Howells 	    ctx->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
10075eb005caSDavid Howells 	    !rpc_cmp_addr((struct sockaddr *)&ctx->nfs_server.address,
1008a1be9eeeSStefan Richter 			  (struct sockaddr *)&nfss->nfs_client->cl_addr))
100948b605f8SJeff Layton 		return -EINVAL;
101048b605f8SJeff Layton 
101148b605f8SJeff Layton 	return 0;
101248b605f8SJeff Layton }
101348b605f8SJeff Layton 
nfs_reconfigure(struct fs_context * fc)1014f2aedb71SDavid Howells int nfs_reconfigure(struct fs_context *fc)
101548b605f8SJeff Layton {
1016f2aedb71SDavid Howells 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
1017f2aedb71SDavid Howells 	struct super_block *sb = fc->root->d_sb;
101848b605f8SJeff Layton 	struct nfs_server *nfss = sb->s_fs_info;
10191301ba60SAnna Schumaker 	int ret;
102048b605f8SJeff Layton 
102102b9984dSTheodore Ts'o 	sync_filesystem(sb);
102202b9984dSTheodore Ts'o 
102348b605f8SJeff Layton 	/*
102448b605f8SJeff Layton 	 * Userspace mount programs that send binary options generally send
102548b605f8SJeff Layton 	 * them populated with default values. We have no way to know which
102648b605f8SJeff Layton 	 * ones were explicitly specified. Fall back to legacy behavior and
102748b605f8SJeff Layton 	 * just return success.
102848b605f8SJeff Layton 	 */
1029f2aedb71SDavid Howells 	if (ctx->skip_reconfig_option_check)
103048b605f8SJeff Layton 		return 0;
103148b605f8SJeff Layton 
103226c4c170SJeff Layton 	/*
103326c4c170SJeff Layton 	 * noac is a special case. It implies -o sync, but that's not
1034f2aedb71SDavid Howells 	 * necessarily reflected in the mtab options. reconfigure_super
10351751e8a6SLinus Torvalds 	 * will clear SB_SYNCHRONOUS if -o sync wasn't specified in the
103626c4c170SJeff Layton 	 * remount options, so we have to explicitly reset it.
103726c4c170SJeff Layton 	 */
1038f2aedb71SDavid Howells 	if (ctx->flags & NFS_MOUNT_NOAC) {
1039f2aedb71SDavid Howells 		fc->sb_flags |= SB_SYNCHRONOUS;
1040f2aedb71SDavid Howells 		fc->sb_flags_mask |= SB_SYNCHRONOUS;
1041f2aedb71SDavid Howells 	}
104226c4c170SJeff Layton 
104348b605f8SJeff Layton 	/* compare new mount options with old ones */
10441301ba60SAnna Schumaker 	ret = nfs_compare_remount_data(nfss, ctx);
10451301ba60SAnna Schumaker 	if (ret)
10461301ba60SAnna Schumaker 		return ret;
10471301ba60SAnna Schumaker 
10481301ba60SAnna Schumaker 	return nfs_probe_server(nfss, NFS_FH(d_inode(fc->root)));
104948b605f8SJeff Layton }
1050f2aedb71SDavid Howells EXPORT_SYMBOL_GPL(nfs_reconfigure);
105148b605f8SJeff Layton 
105254ceac45SDavid Howells /*
1053ab88dca3SAl Viro  * Finish setting up an NFS superblock
105454ceac45SDavid Howells  */
nfs_fill_super(struct super_block * sb,struct nfs_fs_context * ctx)105562a55d08SScott Mayhew static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
105654ceac45SDavid Howells {
105754ceac45SDavid Howells 	struct nfs_server *server = NFS_SB(sb);
105854ceac45SDavid Howells 
105954ceac45SDavid Howells 	sb->s_blocksize_bits = 0;
106054ceac45SDavid Howells 	sb->s_blocksize = 0;
10616a74490dSBryan Schumaker 	sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
10626a74490dSBryan Schumaker 	sb->s_op = server->nfs_client->cl_nfs_mod->sops;
10638c6d76a3SOlga Kornievskaia 	if (ctx->bsize)
10645eb005caSDavid Howells 		sb->s_blocksize = nfs_block_size(ctx->bsize, &sb->s_blocksize_bits);
106554ceac45SDavid Howells 
10662a9d683bSTrond Myklebust 	switch (server->nfs_client->rpc_ops->version) {
10672a9d683bSTrond Myklebust 	case 2:
10682a9d683bSTrond Myklebust 		sb->s_time_gran = 1000;
10692a9d683bSTrond Myklebust 		sb->s_time_min = 0;
10702a9d683bSTrond Myklebust 		sb->s_time_max = U32_MAX;
10712a9d683bSTrond Myklebust 		break;
10722a9d683bSTrond Myklebust 	case 3:
10732a9d683bSTrond Myklebust 		/*
10742a9d683bSTrond Myklebust 		 * The VFS shouldn't apply the umask to mode bits.
10752a9d683bSTrond Myklebust 		 * We will do so ourselves when necessary.
107654ceac45SDavid Howells 		 */
10771751e8a6SLinus Torvalds 		sb->s_flags |= SB_POSIXACL;
107854ceac45SDavid Howells 		sb->s_time_gran = 1;
10791fcb79c1SDeepa Dinamani 		sb->s_time_min = 0;
10801fcb79c1SDeepa Dinamani 		sb->s_time_max = U32_MAX;
10812a9d683bSTrond Myklebust 		sb->s_export_op = &nfs_export_ops;
10822a9d683bSTrond Myklebust 		break;
10832a9d683bSTrond Myklebust 	case 4:
10842a9d683bSTrond Myklebust 		sb->s_flags |= SB_POSIXACL;
10852a9d683bSTrond Myklebust 		sb->s_time_gran = 1;
10861fcb79c1SDeepa Dinamani 		sb->s_time_min = S64_MIN;
10871fcb79c1SDeepa Dinamani 		sb->s_time_max = S64_MAX;
10882a9d683bSTrond Myklebust 		if (server->caps & NFS_CAP_ATOMIC_OPEN_V1)
10892a9d683bSTrond Myklebust 			sb->s_export_op = &nfs_export_ops;
10902a9d683bSTrond Myklebust 		break;
109154ceac45SDavid Howells 	}
109254ceac45SDavid Howells 
1093ab88dca3SAl Viro 	sb->s_magic = NFS_SUPER_MAGIC;
109454ceac45SDavid Howells 
1095ab88dca3SAl Viro 	/* We probably want something more informative here */
1096ab88dca3SAl Viro 	snprintf(sb->s_id, sizeof(sb->s_id),
1097ab88dca3SAl Viro 		 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
109854ceac45SDavid Howells 
1099ab88dca3SAl Viro 	if (sb->s_blocksize == 0)
1100ab88dca3SAl Viro 		sb->s_blocksize = nfs_block_bits(server->wsize,
1101ab88dca3SAl Viro 						 &sb->s_blocksize_bits);
110254ceac45SDavid Howells 
1103ab88dca3SAl Viro 	nfs_super_set_maxbytes(sb, server->maxfilesize);
11041c725118SBenjamin Coddington 	nfs_sysfs_move_server_to_sb(sb);
1105ec1ade6aSOlga Kornievskaia 	server->has_sec_mnt_opts = ctx->has_sec_mnt_opts;
110654ceac45SDavid Howells }
110754ceac45SDavid Howells 
nfs_compare_mount_options(const struct super_block * s,const struct nfs_server * b,const struct fs_context * fc)110862a55d08SScott Mayhew static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b,
110962a55d08SScott Mayhew 				     const struct fs_context *fc)
1110275a5d24STrond Myklebust {
1111275a5d24STrond Myklebust 	const struct nfs_server *a = s->s_fs_info;
1112275a5d24STrond Myklebust 	const struct rpc_clnt *clnt_a = a->client;
1113275a5d24STrond Myklebust 	const struct rpc_clnt *clnt_b = b->client;
1114275a5d24STrond Myklebust 
111562a55d08SScott Mayhew 	if ((s->s_flags & NFS_SB_MASK) != (fc->sb_flags & NFS_SB_MASK))
1116275a5d24STrond Myklebust 		goto Ebusy;
1117275a5d24STrond Myklebust 	if (a->nfs_client != b->nfs_client)
1118275a5d24STrond Myklebust 		goto Ebusy;
11190aea92bfSTrond Myklebust 	if ((a->flags ^ b->flags) & NFS_MOUNT_CMP_FLAGMASK)
1120275a5d24STrond Myklebust 		goto Ebusy;
1121275a5d24STrond Myklebust 	if (a->wsize != b->wsize)
1122275a5d24STrond Myklebust 		goto Ebusy;
1123275a5d24STrond Myklebust 	if (a->rsize != b->rsize)
1124275a5d24STrond Myklebust 		goto Ebusy;
1125275a5d24STrond Myklebust 	if (a->acregmin != b->acregmin)
1126275a5d24STrond Myklebust 		goto Ebusy;
1127275a5d24STrond Myklebust 	if (a->acregmax != b->acregmax)
1128275a5d24STrond Myklebust 		goto Ebusy;
1129275a5d24STrond Myklebust 	if (a->acdirmin != b->acdirmin)
1130275a5d24STrond Myklebust 		goto Ebusy;
1131275a5d24STrond Myklebust 	if (a->acdirmax != b->acdirmax)
1132275a5d24STrond Myklebust 		goto Ebusy;
1133594d1644SChris Perl 	if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1134275a5d24STrond Myklebust 		goto Ebusy;
1135e89a5a43STrond Myklebust 	return 1;
1136275a5d24STrond Myklebust Ebusy:
1137e89a5a43STrond Myklebust 	return 0;
1138e89a5a43STrond Myklebust }
1139e89a5a43STrond Myklebust 
nfs_set_super(struct super_block * s,struct fs_context * fc)1140f2aedb71SDavid Howells static int nfs_set_super(struct super_block *s, struct fs_context *fc)
1141e89a5a43STrond Myklebust {
1142f2aedb71SDavid Howells 	struct nfs_server *server = fc->s_fs_info;
1143e89a5a43STrond Myklebust 	int ret;
1144e89a5a43STrond Myklebust 
11458b244ff2SAl Viro 	s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
1146e89a5a43STrond Myklebust 	ret = set_anon_super(s, server);
1147e89a5a43STrond Myklebust 	if (ret == 0)
1148e89a5a43STrond Myklebust 		server->s_dev = s->s_dev;
1149e89a5a43STrond Myklebust 	return ret;
1150e89a5a43STrond Myklebust }
1151e89a5a43STrond Myklebust 
nfs_compare_super_address(struct nfs_server * server1,struct nfs_server * server2)1152fd00a8ffSChuck Lever static int nfs_compare_super_address(struct nfs_server *server1,
1153fd00a8ffSChuck Lever 				     struct nfs_server *server2)
1154fd00a8ffSChuck Lever {
1155fd00a8ffSChuck Lever 	struct sockaddr *sap1, *sap2;
11567e3fcf61SJ. Bruce Fields 	struct rpc_xprt *xprt1 = server1->client->cl_xprt;
11577e3fcf61SJ. Bruce Fields 	struct rpc_xprt *xprt2 = server2->client->cl_xprt;
11587e3fcf61SJ. Bruce Fields 
11597e3fcf61SJ. Bruce Fields 	if (!net_eq(xprt1->xprt_net, xprt2->xprt_net))
11607e3fcf61SJ. Bruce Fields 		return 0;
1161fd00a8ffSChuck Lever 
1162fd00a8ffSChuck Lever 	sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1163fd00a8ffSChuck Lever 	sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1164fd00a8ffSChuck Lever 
1165fd00a8ffSChuck Lever 	if (sap1->sa_family != sap2->sa_family)
1166fd00a8ffSChuck Lever 		return 0;
1167fd00a8ffSChuck Lever 
1168fd00a8ffSChuck Lever 	switch (sap1->sa_family) {
1169fd00a8ffSChuck Lever 	case AF_INET: {
1170fd00a8ffSChuck Lever 		struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1171fd00a8ffSChuck Lever 		struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1172fd00a8ffSChuck Lever 		if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1173fd00a8ffSChuck Lever 			return 0;
1174fd00a8ffSChuck Lever 		if (sin1->sin_port != sin2->sin_port)
1175fd00a8ffSChuck Lever 			return 0;
1176fd00a8ffSChuck Lever 		break;
1177fd00a8ffSChuck Lever 	}
1178fd00a8ffSChuck Lever 	case AF_INET6: {
1179fd00a8ffSChuck Lever 		struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1180fd00a8ffSChuck Lever 		struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1181fd00a8ffSChuck Lever 		if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1182fd00a8ffSChuck Lever 			return 0;
1183fd00a8ffSChuck Lever 		if (sin1->sin6_port != sin2->sin6_port)
1184fd00a8ffSChuck Lever 			return 0;
1185fd00a8ffSChuck Lever 		break;
1186fd00a8ffSChuck Lever 	}
1187fd00a8ffSChuck Lever 	default:
1188fd00a8ffSChuck Lever 		return 0;
1189fd00a8ffSChuck Lever 	}
1190fd00a8ffSChuck Lever 
1191fd00a8ffSChuck Lever 	return 1;
1192fd00a8ffSChuck Lever }
1193fd00a8ffSChuck Lever 
nfs_compare_userns(const struct nfs_server * old,const struct nfs_server * new)11943b7eb5e3STrond Myklebust static int nfs_compare_userns(const struct nfs_server *old,
11953b7eb5e3STrond Myklebust 		const struct nfs_server *new)
11963b7eb5e3STrond Myklebust {
11973b7eb5e3STrond Myklebust 	const struct user_namespace *oldns = &init_user_ns;
11983b7eb5e3STrond Myklebust 	const struct user_namespace *newns = &init_user_ns;
11993b7eb5e3STrond Myklebust 
12003b7eb5e3STrond Myklebust 	if (old->client && old->client->cl_cred)
12013b7eb5e3STrond Myklebust 		oldns = old->client->cl_cred->user_ns;
12023b7eb5e3STrond Myklebust 	if (new->client && new->client->cl_cred)
12033b7eb5e3STrond Myklebust 		newns = new->client->cl_cred->user_ns;
12043b7eb5e3STrond Myklebust 	if (oldns != newns)
12053b7eb5e3STrond Myklebust 		return 0;
12063b7eb5e3STrond Myklebust 	return 1;
12073b7eb5e3STrond Myklebust }
12083b7eb5e3STrond Myklebust 
nfs_compare_super(struct super_block * sb,struct fs_context * fc)1209f2aedb71SDavid Howells static int nfs_compare_super(struct super_block *sb, struct fs_context *fc)
1210e89a5a43STrond Myklebust {
1211f2aedb71SDavid Howells 	struct nfs_server *server = fc->s_fs_info, *old = NFS_SB(sb);
1212e89a5a43STrond Myklebust 
1213fd00a8ffSChuck Lever 	if (!nfs_compare_super_address(old, server))
1214e89a5a43STrond Myklebust 		return 0;
1215e89a5a43STrond Myklebust 	/* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1216e89a5a43STrond Myklebust 	if (old->flags & NFS_MOUNT_UNSHARED)
1217e89a5a43STrond Myklebust 		return 0;
1218e89a5a43STrond Myklebust 	if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1219e89a5a43STrond Myklebust 		return 0;
12203b7eb5e3STrond Myklebust 	if (!nfs_compare_userns(old, server))
12213b7eb5e3STrond Myklebust 		return 0;
1222ec1ade6aSOlga Kornievskaia 	if ((old->has_sec_mnt_opts || fc->security) &&
1223ec1ade6aSOlga Kornievskaia 			security_sb_mnt_opts_compat(sb, fc->security))
1224ec1ade6aSOlga Kornievskaia 		return 0;
122562a55d08SScott Mayhew 	return nfs_compare_mount_options(sb, server, fc);
1226275a5d24STrond Myklebust }
1227275a5d24STrond Myklebust 
122839ffb921STrond Myklebust #ifdef CONFIG_NFS_FSCACHE
nfs_get_cache_cookie(struct super_block * sb,struct nfs_fs_context * ctx)1229a6b5a28eSDave Wysochanski static int nfs_get_cache_cookie(struct super_block *sb,
1230f2aedb71SDavid Howells 				struct nfs_fs_context *ctx)
12312311b943SBryan Schumaker {
1232c4271c6eSTrond Myklebust 	struct nfs_server *nfss = NFS_SB(sb);
12332311b943SBryan Schumaker 	char *uniq = NULL;
12342311b943SBryan Schumaker 	int ulen = 0;
12352311b943SBryan Schumaker 
1236c4271c6eSTrond Myklebust 	nfss->fscache = NULL;
1237c4271c6eSTrond Myklebust 
1238f2aedb71SDavid Howells 	if (!ctx)
1239a6b5a28eSDave Wysochanski 		return 0;
1240f2aedb71SDavid Howells 
1241f2aedb71SDavid Howells 	if (ctx->clone_data.sb) {
1242f2aedb71SDavid Howells 		struct nfs_server *mnt_s = NFS_SB(ctx->clone_data.sb);
1243c4271c6eSTrond Myklebust 		if (!(mnt_s->options & NFS_OPTION_FSCACHE))
1244a6b5a28eSDave Wysochanski 			return 0;
1245a6b5a28eSDave Wysochanski 		if (mnt_s->fscache_uniq) {
1246a6b5a28eSDave Wysochanski 			uniq = mnt_s->fscache_uniq;
1247a6b5a28eSDave Wysochanski 			ulen = strlen(uniq);
12489c91fa36SYueHaibing 		}
1249f2aedb71SDavid Howells 	} else {
1250f2aedb71SDavid Howells 		if (!(ctx->options & NFS_OPTION_FSCACHE))
1251a6b5a28eSDave Wysochanski 			return 0;
1252f2aedb71SDavid Howells 		if (ctx->fscache_uniq) {
1253f2aedb71SDavid Howells 			uniq = ctx->fscache_uniq;
1254f2aedb71SDavid Howells 			ulen = strlen(ctx->fscache_uniq);
1255f2aedb71SDavid Howells 		}
1256f2aedb71SDavid Howells 	}
12572311b943SBryan Schumaker 
1258a6b5a28eSDave Wysochanski 	return nfs_fscache_get_super_cookie(sb, uniq, ulen);
12592311b943SBryan Schumaker }
126039ffb921STrond Myklebust #else
nfs_get_cache_cookie(struct super_block * sb,struct nfs_fs_context * ctx)1261a6b5a28eSDave Wysochanski static int nfs_get_cache_cookie(struct super_block *sb,
1262f2aedb71SDavid Howells 				struct nfs_fs_context *ctx)
126339ffb921STrond Myklebust {
1264a6b5a28eSDave Wysochanski 	return 0;
126539ffb921STrond Myklebust }
126639ffb921STrond Myklebust #endif
12672311b943SBryan Schumaker 
nfs_get_tree_common(struct fs_context * fc)1268f2aedb71SDavid Howells int nfs_get_tree_common(struct fs_context *fc)
126954ceac45SDavid Howells {
1270f2aedb71SDavid Howells 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
127154ceac45SDavid Howells 	struct super_block *s;
1272f2aedb71SDavid Howells 	int (*compare_super)(struct super_block *, struct fs_context *) = nfs_compare_super;
127362a55d08SScott Mayhew 	struct nfs_server *server = ctx->server;
127401194981SAl Viro 	int error;
127554ceac45SDavid Howells 
127662a55d08SScott Mayhew 	ctx->server = NULL;
1277444a5296SAl Viro 	if (IS_ERR(server))
1278f2aedb71SDavid Howells 		return PTR_ERR(server);
1279444a5296SAl Viro 
128075180df2STrond Myklebust 	if (server->flags & NFS_MOUNT_UNSHARED)
128175180df2STrond Myklebust 		compare_super = NULL;
128275180df2STrond Myklebust 
1283fb2088ccSSachin Prabhu 	/* -o noac implies -o sync */
1284fb2088ccSSachin Prabhu 	if (server->flags & NFS_MOUNT_NOAC)
1285f2aedb71SDavid Howells 		fc->sb_flags |= SB_SYNCHRONOUS;
1286fb2088ccSSachin Prabhu 
1287f2aedb71SDavid Howells 	if (ctx->clone_data.sb)
1288f2aedb71SDavid Howells 		if (ctx->clone_data.sb->s_flags & SB_SYNCHRONOUS)
1289f2aedb71SDavid Howells 			fc->sb_flags |= SB_SYNCHRONOUS;
1290f2aedb71SDavid Howells 
129154ceac45SDavid Howells 	/* Get a superblock - note that we may end up sharing one that already exists */
1292f2aedb71SDavid Howells 	fc->s_fs_info = server;
1293f2aedb71SDavid Howells 	s = sget_fc(fc, compare_super, nfs_set_super);
1294f2aedb71SDavid Howells 	fc->s_fs_info = NULL;
1295816724e6STrond Myklebust 	if (IS_ERR(s)) {
1296f2aedb71SDavid Howells 		error = PTR_ERR(s);
1297ce8866f0SScott Mayhew 		nfs_errorf(fc, "NFS: Couldn't get superblock");
129854ceac45SDavid Howells 		goto out_err_nosb;
1299816724e6STrond Myklebust 	}
1300816724e6STrond Myklebust 
130154ceac45SDavid Howells 	if (s->s_fs_info != server) {
130254ceac45SDavid Howells 		nfs_free_server(server);
130354ceac45SDavid Howells 		server = NULL;
1304fa799759SMiklos Szeredi 	} else {
13059052c7cfSJan Kara 		error = super_setup_bdi_name(s, "%u:%u", MAJOR(server->s_dev),
13069052c7cfSJan Kara 					     MINOR(server->s_dev));
1307f2aedb71SDavid Howells 		if (error)
13089052c7cfSJan Kara 			goto error_splat_super;
130955b2598eSChristoph Hellwig 		s->s_bdi->io_pages = server->rpages;
1310ce6cda18SChuck Lever 		server->super = s;
131101194981SAl Viro 	}
1312f7b422b1SDavid Howells 
131354ceac45SDavid Howells 	if (!s->s_root) {
131462a55d08SScott Mayhew 		unsigned bsize = ctx->clone_data.inherited_bsize;
131554ceac45SDavid Howells 		/* initial superblock/root creation */
131662a55d08SScott Mayhew 		nfs_fill_super(s, ctx);
1317ab88dca3SAl Viro 		if (bsize) {
1318ab88dca3SAl Viro 			s->s_blocksize_bits = bsize;
1319ab88dca3SAl Viro 			s->s_blocksize = 1U << bsize;
1320ab88dca3SAl Viro 		}
1321a6b5a28eSDave Wysochanski 		error = nfs_get_cache_cookie(s, ctx);
1322a6b5a28eSDave Wysochanski 		if (error < 0)
1323a6b5a28eSDave Wysochanski 			goto error_splat_super;
132454ceac45SDavid Howells 	}
1325f7b422b1SDavid Howells 
132662a55d08SScott Mayhew 	error = nfs_get_root(s, fc);
132762a55d08SScott Mayhew 	if (error < 0) {
1328ce8866f0SScott Mayhew 		nfs_errorf(fc, "NFS: Couldn't get root dentry");
132954ceac45SDavid Howells 		goto error_splat_super;
1330f2aedb71SDavid Howells 	}
1331adf2314fSAl Viro 
13321751e8a6SLinus Torvalds 	s->s_flags |= SB_ACTIVE;
1333f2aedb71SDavid Howells 	error = 0;
13340655960fSChuck Lever 
13350655960fSChuck Lever out:
1336f2aedb71SDavid Howells 	return error;
133754ceac45SDavid Howells 
133854ceac45SDavid Howells out_err_nosb:
133954ceac45SDavid Howells 	nfs_free_server(server);
13400655960fSChuck Lever 	goto out;
134154ceac45SDavid Howells error_splat_super:
13426f5bbff9SAl Viro 	deactivate_locked_super(s);
13430655960fSChuck Lever 	goto out;
1344f7b422b1SDavid Howells }
1345816724e6STrond Myklebust 
134654ceac45SDavid Howells /*
13471c725118SBenjamin Coddington  * Destroy an NFS superblock
134854ceac45SDavid Howells  */
nfs_kill_super(struct super_block * s)1349fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *s)
1350f7b422b1SDavid Howells {
1351f7b422b1SDavid Howells 	struct nfs_server *server = NFS_SB(s);
1352f7b422b1SDavid Howells 
13531c725118SBenjamin Coddington 	nfs_sysfs_move_sb_to_server(server);
13545069ba84SChristoph Hellwig 	kill_anon_super(s);
13557b14a213SChristoph Hellwig 
135608734048SDavid Howells 	nfs_fscache_release_super_cookie(s);
13577b14a213SChristoph Hellwig 
135854ceac45SDavid Howells 	nfs_free_server(server);
1359f7b422b1SDavid Howells }
136089d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_kill_super);
1361f7b422b1SDavid Howells 
136289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
136354ceac45SDavid Howells 
1364fac1e8e4SBryan Schumaker /*
1365fac1e8e4SBryan Schumaker  * NFS v4 module parameters need to stay in the
1366fac1e8e4SBryan Schumaker  * NFS client for backwards compatibility
1367fac1e8e4SBryan Schumaker  */
1368fac1e8e4SBryan Schumaker unsigned int nfs_callback_set_tcpport;
13695405fc44STrond Myklebust unsigned short nfs_callback_nr_threads;
1370fac1e8e4SBryan Schumaker /* Default cache timeout is 10 minutes */
1371fac1e8e4SBryan Schumaker unsigned int nfs_idmap_cache_timeout = 600;
1372fac1e8e4SBryan Schumaker /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
1373fac1e8e4SBryan Schumaker bool nfs4_disable_idmapping = true;
1374fac1e8e4SBryan Schumaker unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
13755405fc44STrond Myklebust unsigned short max_session_cb_slots = NFS4_DEF_CB_SLOT_TABLE_SIZE;
1376fac1e8e4SBryan Schumaker unsigned short send_implementation_id = 1;
13776f2ea7f2SChuck Lever char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
1378f6de7a39STrond Myklebust bool recover_lost_locks = false;
1379fac1e8e4SBryan Schumaker 
13805405fc44STrond Myklebust EXPORT_SYMBOL_GPL(nfs_callback_nr_threads);
138189d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
138289d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
138389d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
138489d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(max_session_slots);
13855405fc44STrond Myklebust EXPORT_SYMBOL_GPL(max_session_cb_slots);
138689d77c8fSBryan Schumaker EXPORT_SYMBOL_GPL(send_implementation_id);
13876f2ea7f2SChuck Lever EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
1388f6de7a39STrond Myklebust EXPORT_SYMBOL_GPL(recover_lost_locks);
138989d77c8fSBryan Schumaker 
1390fac1e8e4SBryan Schumaker #define NFS_CALLBACK_MAXPORTNR (65535U)
1391fac1e8e4SBryan Schumaker 
param_set_portnr(const char * val,const struct kernel_param * kp)1392fac1e8e4SBryan Schumaker static int param_set_portnr(const char *val, const struct kernel_param *kp)
1393fac1e8e4SBryan Schumaker {
1394fac1e8e4SBryan Schumaker 	unsigned long num;
1395fac1e8e4SBryan Schumaker 	int ret;
1396fac1e8e4SBryan Schumaker 
1397fac1e8e4SBryan Schumaker 	if (!val)
1398fac1e8e4SBryan Schumaker 		return -EINVAL;
13997297cb68SDaniel Walter 	ret = kstrtoul(val, 0, &num);
1400379ebf07SDan Carpenter 	if (ret || num > NFS_CALLBACK_MAXPORTNR)
1401fac1e8e4SBryan Schumaker 		return -EINVAL;
1402fac1e8e4SBryan Schumaker 	*((unsigned int *)kp->arg) = num;
1403fac1e8e4SBryan Schumaker 	return 0;
1404fac1e8e4SBryan Schumaker }
14059c27847dSLuis R. Rodriguez static const struct kernel_param_ops param_ops_portnr = {
1406fac1e8e4SBryan Schumaker 	.set = param_set_portnr,
1407fac1e8e4SBryan Schumaker 	.get = param_get_uint,
1408fac1e8e4SBryan Schumaker };
1409a799b68aSHuilong Deng #define param_check_portnr(name, p) __param_check(name, p, unsigned int)
1410fac1e8e4SBryan Schumaker 
1411fac1e8e4SBryan Schumaker module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
14125405fc44STrond Myklebust module_param_named(callback_nr_threads, nfs_callback_nr_threads, ushort, 0644);
14135405fc44STrond Myklebust MODULE_PARM_DESC(callback_nr_threads, "Number of threads that will be "
14145405fc44STrond Myklebust 		"assigned to the NFSv4 callback channels.");
1415fac1e8e4SBryan Schumaker module_param(nfs_idmap_cache_timeout, int, 0644);
1416fac1e8e4SBryan Schumaker module_param(nfs4_disable_idmapping, bool, 0644);
14176f2ea7f2SChuck Lever module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
14186f2ea7f2SChuck Lever 			NFS4_CLIENT_ID_UNIQ_LEN, 0600);
1419fac1e8e4SBryan Schumaker MODULE_PARM_DESC(nfs4_disable_idmapping,
1420fac1e8e4SBryan Schumaker 		"Turn off NFSv4 idmapping when using 'sec=sys'");
1421fac1e8e4SBryan Schumaker module_param(max_session_slots, ushort, 0644);
1422fac1e8e4SBryan Schumaker MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
1423fac1e8e4SBryan Schumaker 		"requests the client will negotiate");
14245405fc44STrond Myklebust module_param(max_session_cb_slots, ushort, 0644);
1425f36ab161SWei Yongjun MODULE_PARM_DESC(max_session_cb_slots, "Maximum number of parallel NFSv4.1 "
14265405fc44STrond Myklebust 		"callbacks the client will process for a given server");
1427fac1e8e4SBryan Schumaker module_param(send_implementation_id, ushort, 0644);
1428fac1e8e4SBryan Schumaker MODULE_PARM_DESC(send_implementation_id,
1429fac1e8e4SBryan Schumaker 		"Send implementation ID with NFSv4.1 exchange_id");
14306f2ea7f2SChuck Lever MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
1431425e776dSbjschuma@gmail.com 
1432f6de7a39STrond Myklebust module_param(recover_lost_locks, bool, 0644);
1433f6de7a39STrond Myklebust MODULE_PARM_DESC(recover_lost_locks,
1434f6de7a39STrond Myklebust 		 "If the server reports that a lock might be lost, "
1435f6de7a39STrond Myklebust 		 "try to recover it risking data corruption.");
1436f6de7a39STrond Myklebust 
1437f6de7a39STrond Myklebust 
143854ceac45SDavid Howells #endif /* CONFIG_NFS_V4 */
1439