xref: /linux/fs/nfsd/nfsctl.c (revision 93483ac5fec62cc1de166051b219d953bb5e4ef4)
109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * Syscall interface to knfsd.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
85a0e3ad6STejun Heo #include <linux/slab.h>
93f8206d4SAl Viro #include <linux/namei.h>
10b41b66d6SNeilBrown #include <linux/ctype.h>
1196a374a3SDavid Howells #include <linux/fs_context.h>
121da177e4SLinus Torvalds 
1380212d59SNeilBrown #include <linux/sunrpc/svcsock.h>
144373ea84SWendy Cheng #include <linux/lockd/lockd.h>
155976687aSJeff Layton #include <linux/sunrpc/addr.h>
16b0b0c0a2SKevin Coffman #include <linux/sunrpc/gss_api.h>
17813fd320SJeff Layton #include <linux/sunrpc/rpc_pipe_fs.h>
18143cb494SPaul Gortmaker #include <linux/module.h>
19e8a79fb1SJ. Bruce Fields #include <linux/fsnotify.h>
201da177e4SLinus Torvalds 
212ca72e17SJ. Bruce Fields #include "idmap.h"
229a74af21SBoaz Harrosh #include "nfsd.h"
239a74af21SBoaz Harrosh #include "cache.h"
24f3c7521fSBryan Schumaker #include "state.h"
257ea34ac1SJeff Layton #include "netns.h"
269cf514ccSChristoph Hellwig #include "pnfs.h"
272e6c6e4cSChuck Lever #include "filecache.h"
2839d432fcSChuck Lever #include "trace.h"
2913727f85SLorenzo Bianconi #include "netlink.h"
309a74af21SBoaz Harrosh 
311da177e4SLinus Torvalds /*
32b0b0c0a2SKevin Coffman  *	We have a single directory with several nodes in it.
331da177e4SLinus Torvalds  */
341da177e4SLinus Torvalds enum {
351da177e4SLinus Torvalds 	NFSD_Root = 1,
361da177e4SLinus Torvalds 	NFSD_List,
3720ad856eSAmir Goldstein 	NFSD_Export_Stats,
38e8e8753fSJ. Bruce Fields 	NFSD_Export_features,
391da177e4SLinus Torvalds 	NFSD_Fh,
404373ea84SWendy Cheng 	NFSD_FO_UnlockIP,
4117efa372SWendy Cheng 	NFSD_FO_UnlockFS,
421da177e4SLinus Torvalds 	NFSD_Threads,
43eed2965aSGreg Banks 	NFSD_Pool_Threads,
4403cf6c9fSGreg Banks 	NFSD_Pool_Stats,
45a2f999a3SJeff Layton 	NFSD_Reply_Cache_Stats,
4670c3b76cSNeilBrown 	NFSD_Versions,
4780212d59SNeilBrown 	NFSD_Ports,
48596bbe53SNeilBrown 	NFSD_MaxBlkSize,
495b8db00bSJeff Layton 	NFSD_MaxConnections,
502e6c6e4cSChuck Lever 	NFSD_Filecache,
5170c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4
521da177e4SLinus Torvalds 	NFSD_Leasetime,
53efc4bb4fSJ. Bruce Fields 	NFSD_Gracetime,
540964a3d3SNeilBrown 	NFSD_RecoveryDir,
557f5ef2e9SJeff Layton 	NFSD_V4EndGrace,
5670c3b76cSNeilBrown #endif
57e8a79fb1SJ. Bruce Fields 	NFSD_MaxReserved
581da177e4SLinus Torvalds };
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds /*
611da177e4SLinus Torvalds  * write() for these nodes.
621da177e4SLinus Torvalds  */
631da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
64b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
65b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
661da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size);
67eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
6870c3b76cSNeilBrown static ssize_t write_versions(struct file *file, char *buf, size_t size);
6980212d59SNeilBrown static ssize_t write_ports(struct file *file, char *buf, size_t size);
70596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
715b8db00bSJeff Layton static ssize_t write_maxconn(struct file *file, char *buf, size_t size);
7270c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4
731da177e4SLinus Torvalds static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
74efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
7574fd4873SJeff Layton #ifdef CONFIG_NFSD_LEGACY_CLIENT_TRACKING
760964a3d3SNeilBrown static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
7774fd4873SJeff Layton #endif
787f5ef2e9SJeff Layton static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size);
7970c3b76cSNeilBrown #endif
801da177e4SLinus Torvalds 
81c2cdc2abSEric Biggers static ssize_t (*const write_op[])(struct file *, char *, size_t) = {
821da177e4SLinus Torvalds 	[NFSD_Fh] = write_filehandle,
83b046ccdcSChuck Lever 	[NFSD_FO_UnlockIP] = write_unlock_ip,
84b046ccdcSChuck Lever 	[NFSD_FO_UnlockFS] = write_unlock_fs,
851da177e4SLinus Torvalds 	[NFSD_Threads] = write_threads,
86eed2965aSGreg Banks 	[NFSD_Pool_Threads] = write_pool_threads,
8770c3b76cSNeilBrown 	[NFSD_Versions] = write_versions,
8880212d59SNeilBrown 	[NFSD_Ports] = write_ports,
89596bbe53SNeilBrown 	[NFSD_MaxBlkSize] = write_maxblksize,
905b8db00bSJeff Layton 	[NFSD_MaxConnections] = write_maxconn,
9170c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4
921da177e4SLinus Torvalds 	[NFSD_Leasetime] = write_leasetime,
93efc4bb4fSJ. Bruce Fields 	[NFSD_Gracetime] = write_gracetime,
9474fd4873SJeff Layton #ifdef CONFIG_NFSD_LEGACY_CLIENT_TRACKING
950964a3d3SNeilBrown 	[NFSD_RecoveryDir] = write_recoverydir,
9674fd4873SJeff Layton #endif
977f5ef2e9SJeff Layton 	[NFSD_V4EndGrace] = write_v4_end_grace,
9870c3b76cSNeilBrown #endif
991da177e4SLinus Torvalds };
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
1021da177e4SLinus Torvalds {
103496ad9aaSAl Viro 	ino_t ino =  file_inode(file)->i_ino;
1041da177e4SLinus Torvalds 	char *data;
1051da177e4SLinus Torvalds 	ssize_t rv;
1061da177e4SLinus Torvalds 
107e8c96f8cSTobias Klauser 	if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
1081da177e4SLinus Torvalds 		return -EINVAL;
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 	data = simple_transaction_get(file, buf, size);
1111da177e4SLinus Torvalds 	if (IS_ERR(data))
1121da177e4SLinus Torvalds 		return PTR_ERR(data);
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds 	rv = write_op[ino](file, data, size);
1153434d7aaSChuck Lever 	if (rv < 0)
1161da177e4SLinus Torvalds 		return rv;
1173434d7aaSChuck Lever 
1183434d7aaSChuck Lever 	simple_transaction_set(file, rv);
1193434d7aaSChuck Lever 	return size;
1201da177e4SLinus Torvalds }
1211da177e4SLinus Torvalds 
1227390022dSNeilBrown static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
1237390022dSNeilBrown {
1247390022dSNeilBrown 	if (! file->private_data) {
1257390022dSNeilBrown 		/* An attempt to read a transaction file without writing
1267390022dSNeilBrown 		 * causes a 0-byte write so that the file can return
1277390022dSNeilBrown 		 * state information
1287390022dSNeilBrown 		 */
1297390022dSNeilBrown 		ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
1307390022dSNeilBrown 		if (rv < 0)
1317390022dSNeilBrown 			return rv;
1327390022dSNeilBrown 	}
1337390022dSNeilBrown 	return simple_transaction_read(file, buf, size, pos);
1347390022dSNeilBrown }
1357390022dSNeilBrown 
1364b6f5d20SArjan van de Ven static const struct file_operations transaction_ops = {
1371da177e4SLinus Torvalds 	.write		= nfsctl_transaction_write,
1387390022dSNeilBrown 	.read		= nfsctl_transaction_read,
1391da177e4SLinus Torvalds 	.release	= simple_transaction_release,
1406038f373SArnd Bergmann 	.llseek		= default_llseek,
1411da177e4SLinus Torvalds };
1421da177e4SLinus Torvalds 
14396d851c4SStanislav Kinsbursky static int exports_net_open(struct net *net, struct file *file)
1441da177e4SLinus Torvalds {
145f2c7ea10SStanislav Kinsbursky 	int err;
146f2c7ea10SStanislav Kinsbursky 	struct seq_file *seq;
14796d851c4SStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
148f2c7ea10SStanislav Kinsbursky 
149f2c7ea10SStanislav Kinsbursky 	err = seq_open(file, &nfs_exports_op);
150f2c7ea10SStanislav Kinsbursky 	if (err)
151f2c7ea10SStanislav Kinsbursky 		return err;
152f2c7ea10SStanislav Kinsbursky 
153f2c7ea10SStanislav Kinsbursky 	seq = file->private_data;
154e5f06f72SStanislav Kinsbursky 	seq->private = nn->svc_export_cache;
155f2c7ea10SStanislav Kinsbursky 	return 0;
1561da177e4SLinus Torvalds }
1571da177e4SLinus Torvalds 
15896d851c4SStanislav Kinsbursky static int exports_nfsd_open(struct inode *inode, struct file *file)
15996d851c4SStanislav Kinsbursky {
16096d851c4SStanislav Kinsbursky 	return exports_net_open(inode->i_sb->s_fs_info, file);
16196d851c4SStanislav Kinsbursky }
16296d851c4SStanislav Kinsbursky 
16396d851c4SStanislav Kinsbursky static const struct file_operations exports_nfsd_operations = {
16496d851c4SStanislav Kinsbursky 	.open		= exports_nfsd_open,
1651da177e4SLinus Torvalds 	.read		= seq_read,
1661da177e4SLinus Torvalds 	.llseek		= seq_lseek,
1671da177e4SLinus Torvalds 	.release	= seq_release,
1681da177e4SLinus Torvalds };
1691da177e4SLinus Torvalds 
170e8e8753fSJ. Bruce Fields static int export_features_show(struct seq_file *m, void *v)
171e8e8753fSJ. Bruce Fields {
172e8e8753fSJ. Bruce Fields 	seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
173e8e8753fSJ. Bruce Fields 	return 0;
174e8e8753fSJ. Bruce Fields }
175e8e8753fSJ. Bruce Fields 
1769beeaab8SChenXiaoSong DEFINE_SHOW_ATTRIBUTE(export_features);
177e8e8753fSJ. Bruce Fields 
178828c0950SAlexey Dobriyan static const struct file_operations pool_stats_operations = {
17903cf6c9fSGreg Banks 	.open		= nfsd_pool_stats_open,
18003cf6c9fSGreg Banks 	.read		= seq_read,
18103cf6c9fSGreg Banks 	.llseek		= seq_lseek,
1827b207ccdSNeilBrown 	.release	= seq_release,
18303cf6c9fSGreg Banks };
18403cf6c9fSGreg Banks 
18564776611SChenXiaoSong DEFINE_SHOW_ATTRIBUTE(nfsd_reply_cache_stats);
186a2f999a3SJeff Layton 
1871342f9ddSChenXiaoSong DEFINE_SHOW_ATTRIBUTE(nfsd_file_cache_stats);
1882e6c6e4cSChuck Lever 
1891da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/
1901da177e4SLinus Torvalds /*
1911da177e4SLinus Torvalds  * payload - write methods
1921da177e4SLinus Torvalds  */
1931da177e4SLinus Torvalds 
194244c7d44SAl Viro static inline struct net *netns(struct file *file)
195244c7d44SAl Viro {
196244c7d44SAl Viro 	return file_inode(file)->i_sb->s_fs_info;
197244c7d44SAl Viro }
1981da177e4SLinus Torvalds 
199f2453978SChuck Lever /*
200262a0982SChuck Lever  * write_unlock_ip - Release all locks used by a client
201262a0982SChuck Lever  *
202262a0982SChuck Lever  * Experimental.
203262a0982SChuck Lever  *
204262a0982SChuck Lever  * Input:
205262a0982SChuck Lever  *			buf:	'\n'-terminated C string containing a
2064116092bSChuck Lever  *				presentation format IP address
207262a0982SChuck Lever  *			size:	length of C string in @buf
208262a0982SChuck Lever  * Output:
209262a0982SChuck Lever  *	On success:	returns zero if all specified locks were released;
210262a0982SChuck Lever  *			returns one if one or more locks were not released
211262a0982SChuck Lever  *	On error:	return code is negative errno value
212262a0982SChuck Lever  */
213b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
2144373ea84SWendy Cheng {
2154116092bSChuck Lever 	struct sockaddr_storage address;
2164116092bSChuck Lever 	struct sockaddr *sap = (struct sockaddr *)&address;
2174116092bSChuck Lever 	size_t salen = sizeof(address);
218367c8c7bSChuck Lever 	char *fo_path;
219244c7d44SAl Viro 	struct net *net = netns(file);
2204373ea84SWendy Cheng 
2214373ea84SWendy Cheng 	/* sanity check */
2224373ea84SWendy Cheng 	if (size == 0)
2234373ea84SWendy Cheng 		return -EINVAL;
2244373ea84SWendy Cheng 
2254373ea84SWendy Cheng 	if (buf[size-1] != '\n')
2264373ea84SWendy Cheng 		return -EINVAL;
2274373ea84SWendy Cheng 
2284373ea84SWendy Cheng 	fo_path = buf;
2294373ea84SWendy Cheng 	if (qword_get(&buf, fo_path, size) < 0)
2304373ea84SWendy Cheng 		return -EINVAL;
2314373ea84SWendy Cheng 
23211f77942SStanislav Kinsbursky 	if (rpc_pton(net, fo_path, size, sap, salen) == 0)
2334373ea84SWendy Cheng 		return -EINVAL;
2344373ea84SWendy Cheng 
23539d432fcSChuck Lever 	trace_nfsd_ctl_unlock_ip(net, buf);
2364116092bSChuck Lever 	return nlmsvc_unlock_all_by_ip(sap);
2374373ea84SWendy Cheng }
2384373ea84SWendy Cheng 
239f2453978SChuck Lever /*
240262a0982SChuck Lever  * write_unlock_fs - Release all locks on a local file system
241262a0982SChuck Lever  *
242262a0982SChuck Lever  * Experimental.
243262a0982SChuck Lever  *
244262a0982SChuck Lever  * Input:
245262a0982SChuck Lever  *			buf:	'\n'-terminated C string containing the
246262a0982SChuck Lever  *				absolute pathname of a local file system
247262a0982SChuck Lever  *			size:	length of C string in @buf
248262a0982SChuck Lever  * Output:
249262a0982SChuck Lever  *	On success:	returns zero if all specified locks were released;
250262a0982SChuck Lever  *			returns one if one or more locks were not released
251262a0982SChuck Lever  *	On error:	return code is negative errno value
252262a0982SChuck Lever  */
253b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
25417efa372SWendy Cheng {
255a63bb996SAl Viro 	struct path path;
25617efa372SWendy Cheng 	char *fo_path;
25717efa372SWendy Cheng 	int error;
25817efa372SWendy Cheng 
25917efa372SWendy Cheng 	/* sanity check */
26017efa372SWendy Cheng 	if (size == 0)
26117efa372SWendy Cheng 		return -EINVAL;
26217efa372SWendy Cheng 
26317efa372SWendy Cheng 	if (buf[size-1] != '\n')
26417efa372SWendy Cheng 		return -EINVAL;
26517efa372SWendy Cheng 
26617efa372SWendy Cheng 	fo_path = buf;
26717efa372SWendy Cheng 	if (qword_get(&buf, fo_path, size) < 0)
26817efa372SWendy Cheng 		return -EINVAL;
26939d432fcSChuck Lever 	trace_nfsd_ctl_unlock_fs(netns(file), fo_path);
270a63bb996SAl Viro 	error = kern_path(fo_path, 0, &path);
27117efa372SWendy Cheng 	if (error)
27217efa372SWendy Cheng 		return error;
27317efa372SWendy Cheng 
274262a0982SChuck Lever 	/*
275262a0982SChuck Lever 	 * XXX: Needs better sanity checking.  Otherwise we could end up
276262a0982SChuck Lever 	 * releasing locks on the wrong file system.
277262a0982SChuck Lever 	 *
278262a0982SChuck Lever 	 * For example:
279262a0982SChuck Lever 	 * 1.  Does the path refer to a directory?
280262a0982SChuck Lever 	 * 2.  Is that directory a mount point, or
281262a0982SChuck Lever 	 * 3.  Is that directory the root of an exported file system?
282262a0982SChuck Lever 	 */
283d8c9584eSAl Viro 	error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb);
28417efa372SWendy Cheng 
285a63bb996SAl Viro 	path_put(&path);
28617efa372SWendy Cheng 	return error;
28717efa372SWendy Cheng }
28817efa372SWendy Cheng 
289f2453978SChuck Lever /*
290262a0982SChuck Lever  * write_filehandle - Get a variable-length NFS file handle by path
291262a0982SChuck Lever  *
292262a0982SChuck Lever  * On input, the buffer contains a '\n'-terminated C string comprised of
293262a0982SChuck Lever  * three alphanumeric words separated by whitespace.  The string may
294262a0982SChuck Lever  * contain escape sequences.
295262a0982SChuck Lever  *
296262a0982SChuck Lever  * Input:
297262a0982SChuck Lever  *			buf:
298262a0982SChuck Lever  *				domain:		client domain name
299262a0982SChuck Lever  *				path:		export pathname
300262a0982SChuck Lever  *				maxsize:	numeric maximum size of
301262a0982SChuck Lever  *						@buf
302262a0982SChuck Lever  *			size:	length of C string in @buf
303262a0982SChuck Lever  * Output:
304262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C
305262a0982SChuck Lever  *			string containing a ASCII hex text version
306262a0982SChuck Lever  *			of the NFS file handle;
307262a0982SChuck Lever  *			return code is the size in bytes of the string
308262a0982SChuck Lever  *	On error:	return code is negative errno value
309262a0982SChuck Lever  */
3101da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
3111da177e4SLinus Torvalds {
3121da177e4SLinus Torvalds 	char *dname, *path;
3133f649ab7SKees Cook 	int maxsize;
3141da177e4SLinus Torvalds 	char *mesg = buf;
3151da177e4SLinus Torvalds 	int len;
3161da177e4SLinus Torvalds 	struct auth_domain *dom;
3171da177e4SLinus Torvalds 	struct knfsd_fh fh;
3181da177e4SLinus Torvalds 
31987d26ea7SJ. Bruce Fields 	if (size == 0)
32087d26ea7SJ. Bruce Fields 		return -EINVAL;
32187d26ea7SJ. Bruce Fields 
3221da177e4SLinus Torvalds 	if (buf[size-1] != '\n')
3231da177e4SLinus Torvalds 		return -EINVAL;
3241da177e4SLinus Torvalds 	buf[size-1] = 0;
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 	dname = mesg;
3271da177e4SLinus Torvalds 	len = qword_get(&mesg, dname, size);
32854224f04SChuck Lever 	if (len <= 0)
32954224f04SChuck Lever 		return -EINVAL;
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds 	path = dname+len+1;
3321da177e4SLinus Torvalds 	len = qword_get(&mesg, path, size);
33354224f04SChuck Lever 	if (len <= 0)
33454224f04SChuck Lever 		return -EINVAL;
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds 	len = get_int(&mesg, &maxsize);
3371da177e4SLinus Torvalds 	if (len)
3381da177e4SLinus Torvalds 		return len;
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds 	if (maxsize < NFS_FHSIZE)
3411da177e4SLinus Torvalds 		return -EINVAL;
3423c7aa15dSKinglong Mee 	maxsize = min(maxsize, NFS3_FHSIZE);
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	if (qword_get(&mesg, mesg, size) > 0)
3451da177e4SLinus Torvalds 		return -EINVAL;
3461da177e4SLinus Torvalds 
34739d432fcSChuck Lever 	trace_nfsd_ctl_filehandle(netns(file), dname, path, maxsize);
34839d432fcSChuck Lever 
3491da177e4SLinus Torvalds 	/* we have all the words, they are in buf.. */
3501da177e4SLinus Torvalds 	dom = unix_domain_find(dname);
3511da177e4SLinus Torvalds 	if (!dom)
3521da177e4SLinus Torvalds 		return -ENOMEM;
3531da177e4SLinus Torvalds 
354244c7d44SAl Viro 	len = exp_rootfh(netns(file), dom, path, &fh, maxsize);
3551da177e4SLinus Torvalds 	auth_domain_put(dom);
3561da177e4SLinus Torvalds 	if (len)
3571da177e4SLinus Torvalds 		return len;
3581da177e4SLinus Torvalds 
35954224f04SChuck Lever 	mesg = buf;
36054224f04SChuck Lever 	len = SIMPLE_TRANSACTION_LIMIT;
361d8b26071SNeilBrown 	qword_addhex(&mesg, &len, fh.fh_raw, fh.fh_size);
3621da177e4SLinus Torvalds 	mesg[-1] = '\n';
3631da177e4SLinus Torvalds 	return mesg - buf;
3641da177e4SLinus Torvalds }
3651da177e4SLinus Torvalds 
366f2453978SChuck Lever /*
367262a0982SChuck Lever  * write_threads - Start NFSD, or report the current number of running threads
368262a0982SChuck Lever  *
369262a0982SChuck Lever  * Input:
370262a0982SChuck Lever  *			buf:		ignored
371262a0982SChuck Lever  *			size:		zero
372262a0982SChuck Lever  * Output:
373262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C
374262a0982SChuck Lever  *			string numeric value representing the number of
375262a0982SChuck Lever  *			running NFSD threads;
376262a0982SChuck Lever  *			return code is the size in bytes of the string
377262a0982SChuck Lever  *	On error:	return code is zero
378262a0982SChuck Lever  *
379262a0982SChuck Lever  * OR
380262a0982SChuck Lever  *
381262a0982SChuck Lever  * Input:
382262a0982SChuck Lever  *			buf:		C string containing an unsigned
383262a0982SChuck Lever  *					integer value representing the
384262a0982SChuck Lever  *					number of NFSD threads to start
385262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
386262a0982SChuck Lever  * Output:
387262a0982SChuck Lever  *	On success:	NFS service is started;
388262a0982SChuck Lever  *			passed-in buffer filled with '\n'-terminated C
389262a0982SChuck Lever  *			string numeric value representing the number of
390262a0982SChuck Lever  *			running NFSD threads;
391262a0982SChuck Lever  *			return code is the size in bytes of the string
392262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
393262a0982SChuck Lever  */
3941da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size)
3951da177e4SLinus Torvalds {
3961da177e4SLinus Torvalds 	char *mesg = buf;
3971da177e4SLinus Torvalds 	int rv;
398244c7d44SAl Viro 	struct net *net = netns(file);
399d41a9417SStanislav Kinsbursky 
4001da177e4SLinus Torvalds 	if (size > 0) {
4011da177e4SLinus Torvalds 		int newthreads;
4021da177e4SLinus Torvalds 		rv = get_int(&mesg, &newthreads);
4031da177e4SLinus Torvalds 		if (rv)
4041da177e4SLinus Torvalds 			return rv;
4051da177e4SLinus Torvalds 		if (newthreads < 0)
4061da177e4SLinus Torvalds 			return -EINVAL;
40739d432fcSChuck Lever 		trace_nfsd_ctl_threads(net, newthreads);
4084df493a2STrond Myklebust 		rv = nfsd_svc(newthreads, net, file->f_cred);
40982e12fe9SNeilBrown 		if (rv < 0)
4101da177e4SLinus Torvalds 			return rv;
41182e12fe9SNeilBrown 	} else
4129dd9845fSStanislav Kinsbursky 		rv = nfsd_nrthreads(net);
413e06b6405SChuck Lever 
41482e12fe9SNeilBrown 	return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
4151da177e4SLinus Torvalds }
4161da177e4SLinus Torvalds 
417f2453978SChuck Lever /*
418262a0982SChuck Lever  * write_pool_threads - Set or report the current number of threads per pool
419262a0982SChuck Lever  *
420262a0982SChuck Lever  * Input:
421262a0982SChuck Lever  *			buf:		ignored
422262a0982SChuck Lever  *			size:		zero
423262a0982SChuck Lever  *
424262a0982SChuck Lever  * OR
425262a0982SChuck Lever  *
426262a0982SChuck Lever  * Input:
427262a0982SChuck Lever  *			buf:		C string containing whitespace-
428262a0982SChuck Lever  *					separated unsigned integer values
429262a0982SChuck Lever  *					representing the number of NFSD
430262a0982SChuck Lever  *					threads to start in each pool
431262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
432262a0982SChuck Lever  * Output:
433262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C
434262a0982SChuck Lever  *			string containing integer values representing the
435262a0982SChuck Lever  *			number of NFSD threads in each pool;
436262a0982SChuck Lever  *			return code is the size in bytes of the string
437262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
438262a0982SChuck Lever  */
439eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
440eed2965aSGreg Banks {
441eed2965aSGreg Banks 	/* if size > 0, look for an array of number of threads per node
442eed2965aSGreg Banks 	 * and apply them  then write out number of threads per node as reply
443eed2965aSGreg Banks 	 */
444eed2965aSGreg Banks 	char *mesg = buf;
445eed2965aSGreg Banks 	int i;
446eed2965aSGreg Banks 	int rv;
447eed2965aSGreg Banks 	int len;
448bedbdd8bSNeil Brown 	int npools;
449eed2965aSGreg Banks 	int *nthreads;
450244c7d44SAl Viro 	struct net *net = netns(file);
451eed2965aSGreg Banks 
452bedbdd8bSNeil Brown 	mutex_lock(&nfsd_mutex);
4539dd9845fSStanislav Kinsbursky 	npools = nfsd_nrpools(net);
454eed2965aSGreg Banks 	if (npools == 0) {
455eed2965aSGreg Banks 		/*
456eed2965aSGreg Banks 		 * NFS is shut down.  The admin can start it by
457eed2965aSGreg Banks 		 * writing to the threads file but NOT the pool_threads
458eed2965aSGreg Banks 		 * file, sorry.  Report zero threads.
459eed2965aSGreg Banks 		 */
460bedbdd8bSNeil Brown 		mutex_unlock(&nfsd_mutex);
461eed2965aSGreg Banks 		strcpy(buf, "0\n");
462eed2965aSGreg Banks 		return strlen(buf);
463eed2965aSGreg Banks 	}
464eed2965aSGreg Banks 
465eed2965aSGreg Banks 	nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
466bedbdd8bSNeil Brown 	rv = -ENOMEM;
467eed2965aSGreg Banks 	if (nthreads == NULL)
468bedbdd8bSNeil Brown 		goto out_free;
469eed2965aSGreg Banks 
470eed2965aSGreg Banks 	if (size > 0) {
471eed2965aSGreg Banks 		for (i = 0; i < npools; i++) {
472eed2965aSGreg Banks 			rv = get_int(&mesg, &nthreads[i]);
473eed2965aSGreg Banks 			if (rv == -ENOENT)
474eed2965aSGreg Banks 				break;		/* fewer numbers than pools */
475eed2965aSGreg Banks 			if (rv)
476eed2965aSGreg Banks 				goto out_free;	/* syntax error */
477eed2965aSGreg Banks 			rv = -EINVAL;
478eed2965aSGreg Banks 			if (nthreads[i] < 0)
479eed2965aSGreg Banks 				goto out_free;
48039d432fcSChuck Lever 			trace_nfsd_ctl_pool_threads(net, i, nthreads[i]);
481eed2965aSGreg Banks 		}
4823938a0d5SStanislav Kinsbursky 		rv = nfsd_set_nrthreads(i, nthreads, net);
483eed2965aSGreg Banks 		if (rv)
484eed2965aSGreg Banks 			goto out_free;
485eed2965aSGreg Banks 	}
486eed2965aSGreg Banks 
4879dd9845fSStanislav Kinsbursky 	rv = nfsd_get_nrthreads(npools, nthreads, net);
488eed2965aSGreg Banks 	if (rv)
489eed2965aSGreg Banks 		goto out_free;
490eed2965aSGreg Banks 
491eed2965aSGreg Banks 	mesg = buf;
492eed2965aSGreg Banks 	size = SIMPLE_TRANSACTION_LIMIT;
493eed2965aSGreg Banks 	for (i = 0; i < npools && size > 0; i++) {
494eed2965aSGreg Banks 		snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
495eed2965aSGreg Banks 		len = strlen(mesg);
496eed2965aSGreg Banks 		size -= len;
497eed2965aSGreg Banks 		mesg += len;
498eed2965aSGreg Banks 	}
499413d63d7SJ. Bruce Fields 	rv = mesg - buf;
500eed2965aSGreg Banks out_free:
501eed2965aSGreg Banks 	kfree(nthreads);
502bedbdd8bSNeil Brown 	mutex_unlock(&nfsd_mutex);
503eed2965aSGreg Banks 	return rv;
504eed2965aSGreg Banks }
505eed2965aSGreg Banks 
506ff7d1179STrond Myklebust static ssize_t
507e333f3bbSTrond Myklebust nfsd_print_version_support(struct nfsd_net *nn, char *buf, int remaining,
508e333f3bbSTrond Myklebust 		const char *sep, unsigned vers, int minor)
509ff7d1179STrond Myklebust {
510abcb4dacSNeilBrown 	const char *format = minor < 0 ? "%s%c%u" : "%s%c%u.%u";
511e333f3bbSTrond Myklebust 	bool supported = !!nfsd_vers(nn, vers, NFSD_TEST);
512ff7d1179STrond Myklebust 
513abcb4dacSNeilBrown 	if (vers == 4 && minor >= 0 &&
514e333f3bbSTrond Myklebust 	    !nfsd_minorversion(nn, minor, NFSD_TEST))
515ff7d1179STrond Myklebust 		supported = false;
516abcb4dacSNeilBrown 	if (minor == 0 && supported)
517abcb4dacSNeilBrown 		/*
518abcb4dacSNeilBrown 		 * special case for backward compatability.
519abcb4dacSNeilBrown 		 * +4.0 is never reported, it is implied by
520abcb4dacSNeilBrown 		 * +4, unless -4.0 is present.
521abcb4dacSNeilBrown 		 */
522abcb4dacSNeilBrown 		return 0;
523ff7d1179STrond Myklebust 	return snprintf(buf, remaining, format, sep,
524ff7d1179STrond Myklebust 			supported ? '+' : '-', vers, minor);
525ff7d1179STrond Myklebust }
526ff7d1179STrond Myklebust 
5273dd98a3bSJeff Layton static ssize_t __write_versions(struct file *file, char *buf, size_t size)
52870c3b76cSNeilBrown {
52970c3b76cSNeilBrown 	char *mesg = buf;
5308daf220aSBenny Halevy 	char *vers, *minorp, sign;
531261758b5SChuck Lever 	int len, num, remaining;
53270c3b76cSNeilBrown 	ssize_t tlen = 0;
53370c3b76cSNeilBrown 	char *sep;
534244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
53570c3b76cSNeilBrown 
53670c3b76cSNeilBrown 	if (size > 0) {
5379dd9845fSStanislav Kinsbursky 		if (nn->nfsd_serv)
5386658d3a7SNeilBrown 			/* Cannot change versions without updating
5399dd9845fSStanislav Kinsbursky 			 * nn->nfsd_serv->sv_xdrsize, and reallocing
5406658d3a7SNeilBrown 			 * rq_argp and rq_resp
5416658d3a7SNeilBrown 			 */
54270c3b76cSNeilBrown 			return -EBUSY;
54370c3b76cSNeilBrown 		if (buf[size-1] != '\n')
54470c3b76cSNeilBrown 			return -EINVAL;
54570c3b76cSNeilBrown 		buf[size-1] = 0;
54639d432fcSChuck Lever 		trace_nfsd_ctl_version(netns(file), buf);
54770c3b76cSNeilBrown 
54870c3b76cSNeilBrown 		vers = mesg;
54970c3b76cSNeilBrown 		len = qword_get(&mesg, vers, size);
55070c3b76cSNeilBrown 		if (len <= 0) return -EINVAL;
55170c3b76cSNeilBrown 		do {
552d3635ff0STrond Myklebust 			enum vers_op cmd;
553abcb4dacSNeilBrown 			unsigned minor;
55470c3b76cSNeilBrown 			sign = *vers;
55570c3b76cSNeilBrown 			if (sign == '+' || sign == '-')
5568daf220aSBenny Halevy 				num = simple_strtol((vers+1), &minorp, 0);
55770c3b76cSNeilBrown 			else
5588daf220aSBenny Halevy 				num = simple_strtol(vers, &minorp, 0);
5598daf220aSBenny Halevy 			if (*minorp == '.') {
560ff89be87SJ. Bruce Fields 				if (num != 4)
5618daf220aSBenny Halevy 					return -EINVAL;
562e35659f1SNeilBrown 				if (kstrtouint(minorp+1, 0, &minor) < 0)
5638daf220aSBenny Halevy 					return -EINVAL;
564abcb4dacSNeilBrown 			}
565abcb4dacSNeilBrown 
566d3635ff0STrond Myklebust 			cmd = sign == '-' ? NFSD_CLEAR : NFSD_SET;
56770c3b76cSNeilBrown 			switch(num) {
5682f3a4b2aSJeff Layton #ifdef CONFIG_NFSD_V2
56970c3b76cSNeilBrown 			case 2:
5702f3a4b2aSJeff Layton #endif
57170c3b76cSNeilBrown 			case 3:
572e333f3bbSTrond Myklebust 				nfsd_vers(nn, num, cmd);
573d3635ff0STrond Myklebust 				break;
57470c3b76cSNeilBrown 			case 4:
575abcb4dacSNeilBrown 				if (*minorp == '.') {
576e333f3bbSTrond Myklebust 					if (nfsd_minorversion(nn, minor, cmd) < 0)
577abcb4dacSNeilBrown 						return -EINVAL;
578e333f3bbSTrond Myklebust 				} else if ((cmd == NFSD_SET) != nfsd_vers(nn, num, NFSD_TEST)) {
579abcb4dacSNeilBrown 					/*
580abcb4dacSNeilBrown 					 * Either we have +4 and no minors are enabled,
581abcb4dacSNeilBrown 					 * or we have -4 and at least one minor is enabled.
582abcb4dacSNeilBrown 					 * In either case, propagate 'cmd' to all minors.
583abcb4dacSNeilBrown 					 */
584abcb4dacSNeilBrown 					minor = 0;
585e333f3bbSTrond Myklebust 					while (nfsd_minorversion(nn, minor, cmd) >= 0)
586abcb4dacSNeilBrown 						minor++;
587abcb4dacSNeilBrown 				}
58870c3b76cSNeilBrown 				break;
58970c3b76cSNeilBrown 			default:
5908e823bafSJeff Layton 				/* Ignore requests to disable non-existent versions */
5918e823bafSJeff Layton 				if (cmd == NFSD_SET)
59270c3b76cSNeilBrown 					return -EINVAL;
59370c3b76cSNeilBrown 			}
59470c3b76cSNeilBrown 			vers += len + 1;
59570c3b76cSNeilBrown 		} while ((len = qword_get(&mesg, vers, size)) > 0);
59670c3b76cSNeilBrown 		/* If all get turned off, turn them back on, as
59770c3b76cSNeilBrown 		 * having no versions is BAD
59870c3b76cSNeilBrown 		 */
599e333f3bbSTrond Myklebust 		nfsd_reset_versions(nn);
60070c3b76cSNeilBrown 	}
601261758b5SChuck Lever 
60270c3b76cSNeilBrown 	/* Now write current state into reply buffer */
60370c3b76cSNeilBrown 	sep = "";
604261758b5SChuck Lever 	remaining = SIMPLE_TRANSACTION_LIMIT;
605ff7d1179STrond Myklebust 	for (num=2 ; num <= 4 ; num++) {
606abcb4dacSNeilBrown 		int minor;
607e333f3bbSTrond Myklebust 		if (!nfsd_vers(nn, num, NFSD_AVAIL))
608e35659f1SNeilBrown 			continue;
609abcb4dacSNeilBrown 
610abcb4dacSNeilBrown 		minor = -1;
611ff7d1179STrond Myklebust 		do {
612e333f3bbSTrond Myklebust 			len = nfsd_print_version_support(nn, buf, remaining,
613ff7d1179STrond Myklebust 					sep, num, minor);
614818f2f57SDan Carpenter 			if (len >= remaining)
615ff7d1179STrond Myklebust 				goto out;
616261758b5SChuck Lever 			remaining -= len;
617261758b5SChuck Lever 			buf += len;
618261758b5SChuck Lever 			tlen += len;
619ff7d1179STrond Myklebust 			minor++;
620abcb4dacSNeilBrown 			if (len)
621ff7d1179STrond Myklebust 				sep = " ";
622ff7d1179STrond Myklebust 		} while (num == 4 && minor <= NFSD_SUPPORTED_MINOR_VERSION);
623261758b5SChuck Lever 	}
624ff7d1179STrond Myklebust out:
625261758b5SChuck Lever 	len = snprintf(buf, remaining, "\n");
626818f2f57SDan Carpenter 	if (len >= remaining)
627261758b5SChuck Lever 		return -EINVAL;
628261758b5SChuck Lever 	return tlen + len;
62970c3b76cSNeilBrown }
63070c3b76cSNeilBrown 
631f2453978SChuck Lever /*
632262a0982SChuck Lever  * write_versions - Set or report the available NFS protocol versions
633262a0982SChuck Lever  *
634262a0982SChuck Lever  * Input:
635262a0982SChuck Lever  *			buf:		ignored
636262a0982SChuck Lever  *			size:		zero
637262a0982SChuck Lever  * Output:
638262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C
639262a0982SChuck Lever  *			string containing positive or negative integer
640262a0982SChuck Lever  *			values representing the current status of each
641262a0982SChuck Lever  *			protocol version;
642262a0982SChuck Lever  *			return code is the size in bytes of the string
643262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
644262a0982SChuck Lever  *
645262a0982SChuck Lever  * OR
646262a0982SChuck Lever  *
647262a0982SChuck Lever  * Input:
648262a0982SChuck Lever  *			buf:		C string containing whitespace-
649262a0982SChuck Lever  *					separated positive or negative
650262a0982SChuck Lever  *					integer values representing NFS
651262a0982SChuck Lever  *					protocol versions to enable ("+n")
652262a0982SChuck Lever  *					or disable ("-n")
653262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
654262a0982SChuck Lever  * Output:
655262a0982SChuck Lever  *	On success:	status of zero or more protocol versions has
656262a0982SChuck Lever  *			been updated; passed-in buffer filled with
657262a0982SChuck Lever  *			'\n'-terminated C string containing positive
658262a0982SChuck Lever  *			or negative integer values representing the
659262a0982SChuck Lever  *			current status of each protocol version;
660262a0982SChuck Lever  *			return code is the size in bytes of the string
661262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
662262a0982SChuck Lever  */
6633dd98a3bSJeff Layton static ssize_t write_versions(struct file *file, char *buf, size_t size)
6643dd98a3bSJeff Layton {
6653dd98a3bSJeff Layton 	ssize_t rv;
6663dd98a3bSJeff Layton 
6673dd98a3bSJeff Layton 	mutex_lock(&nfsd_mutex);
6683dd98a3bSJeff Layton 	rv = __write_versions(file, buf, size);
6693dd98a3bSJeff Layton 	mutex_unlock(&nfsd_mutex);
6703dd98a3bSJeff Layton 	return rv;
6713dd98a3bSJeff Layton }
6723dd98a3bSJeff Layton 
6734cd5dc75SChuck Lever /*
6740a5372d8SChuck Lever  * Zero-length write.  Return a list of NFSD's current listener
6750a5372d8SChuck Lever  * transports.
6760a5372d8SChuck Lever  */
6779dd9845fSStanislav Kinsbursky static ssize_t __write_ports_names(char *buf, struct net *net)
6780a5372d8SChuck Lever {
6799dd9845fSStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
6809dd9845fSStanislav Kinsbursky 
6819dd9845fSStanislav Kinsbursky 	if (nn->nfsd_serv == NULL)
6820a5372d8SChuck Lever 		return 0;
6839dd9845fSStanislav Kinsbursky 	return svc_xprt_names(nn->nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
6840a5372d8SChuck Lever }
6850a5372d8SChuck Lever 
6860a5372d8SChuck Lever /*
6870b7c2f6fSChuck Lever  * A single 'fd' number was written, in which case it must be for
6880b7c2f6fSChuck Lever  * a socket of a supported family/protocol, and we use it as an
6890b7c2f6fSChuck Lever  * nfsd listener.
6900b7c2f6fSChuck Lever  */
6914df493a2STrond Myklebust static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred *cred)
6920b7c2f6fSChuck Lever {
6930b7c2f6fSChuck Lever 	char *mesg = buf;
6940b7c2f6fSChuck Lever 	int fd, err;
6959dd9845fSStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
69664e63041SJeff Layton 	struct svc_serv *serv;
6970b7c2f6fSChuck Lever 
6980b7c2f6fSChuck Lever 	err = get_int(&mesg, &fd);
6990b7c2f6fSChuck Lever 	if (err != 0 || fd < 0)
7000b7c2f6fSChuck Lever 		return -EINVAL;
70139d432fcSChuck Lever 	trace_nfsd_ctl_ports_addfd(net, fd);
7020b7c2f6fSChuck Lever 
7036777436bSStanislav Kinsbursky 	err = nfsd_create_serv(net);
7040b7c2f6fSChuck Lever 	if (err != 0)
7050b7c2f6fSChuck Lever 		return err;
7060b7c2f6fSChuck Lever 
70764e63041SJeff Layton 	serv = nn->nfsd_serv;
70864e63041SJeff Layton 	err = svc_addsock(serv, net, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred);
709ea068badSChuck Lever 
7101e3577a4SNeilBrown 	if (!serv->sv_nrthreads && list_empty(&nn->nfsd_serv->sv_permsocks))
71117419aefSNeilBrown 		nfsd_destroy_serv(net);
71217419aefSNeilBrown 
713ea068badSChuck Lever 	return err;
7140b7c2f6fSChuck Lever }
7150b7c2f6fSChuck Lever 
7160b7c2f6fSChuck Lever /*
717442a6290SChuck Lever  * A transport listener is added by writing its transport name and
7184eb68c26SChuck Lever  * a port number.
7194eb68c26SChuck Lever  */
7204df493a2STrond Myklebust static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct cred *cred)
7214eb68c26SChuck Lever {
7224eb68c26SChuck Lever 	char transport[16];
72337498292SChuck Lever 	struct svc_xprt *xprt;
7244eb68c26SChuck Lever 	int port, err;
7259dd9845fSStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
72664e63041SJeff Layton 	struct svc_serv *serv;
7274eb68c26SChuck Lever 
728a10fded1SJ. Bruce Fields 	if (sscanf(buf, "%15s %5u", transport, &port) != 2)
7294eb68c26SChuck Lever 		return -EINVAL;
7304eb68c26SChuck Lever 
7314be929beSAlexey Dobriyan 	if (port < 1 || port > USHRT_MAX)
7324eb68c26SChuck Lever 		return -EINVAL;
73339d432fcSChuck Lever 	trace_nfsd_ctl_ports_addxprt(net, transport, port);
7344eb68c26SChuck Lever 
7356777436bSStanislav Kinsbursky 	err = nfsd_create_serv(net);
7364eb68c26SChuck Lever 	if (err != 0)
7374eb68c26SChuck Lever 		return err;
7384eb68c26SChuck Lever 
73964e63041SJeff Layton 	serv = nn->nfsd_serv;
74064e63041SJeff Layton 	err = svc_xprt_create(serv, transport, net,
7414df493a2STrond Myklebust 			      PF_INET, port, SVC_SOCK_ANONYMOUS, cred);
74268717908SChuck Lever 	if (err < 0)
74337498292SChuck Lever 		goto out_err;
74437498292SChuck Lever 
74564e63041SJeff Layton 	err = svc_xprt_create(serv, transport, net,
7464df493a2STrond Myklebust 			      PF_INET6, port, SVC_SOCK_ANONYMOUS, cred);
74737498292SChuck Lever 	if (err < 0 && err != -EAFNOSUPPORT)
74837498292SChuck Lever 		goto out_close;
7490cd14a06SJeff Layton 
7504eb68c26SChuck Lever 	return 0;
75137498292SChuck Lever out_close:
75264e63041SJeff Layton 	xprt = svc_find_xprt(serv, transport, net, PF_INET, port);
75337498292SChuck Lever 	if (xprt != NULL) {
7544355d767SChuck Lever 		svc_xprt_close(xprt);
75537498292SChuck Lever 		svc_xprt_put(xprt);
75637498292SChuck Lever 	}
75737498292SChuck Lever out_err:
7581e3577a4SNeilBrown 	if (!serv->sv_nrthreads && list_empty(&nn->nfsd_serv->sv_permsocks))
75917419aefSNeilBrown 		nfsd_destroy_serv(net);
7602a501f55SNeilBrown 
76137498292SChuck Lever 	return err;
7624eb68c26SChuck Lever }
7634eb68c26SChuck Lever 
76408160352SStanislav Kinsbursky static ssize_t __write_ports(struct file *file, char *buf, size_t size,
76508160352SStanislav Kinsbursky 			     struct net *net)
76680212d59SNeilBrown {
7670a5372d8SChuck Lever 	if (size == 0)
7689dd9845fSStanislav Kinsbursky 		return __write_ports_names(buf, net);
7690b7c2f6fSChuck Lever 
7700b7c2f6fSChuck Lever 	if (isdigit(buf[0]))
7714df493a2STrond Myklebust 		return __write_ports_addfd(buf, net, file->f_cred);
77282d56591SChuck Lever 
7734eb68c26SChuck Lever 	if (isalpha(buf[0]))
7744df493a2STrond Myklebust 		return __write_ports_addxprt(buf, net, file->f_cred);
7754cd5dc75SChuck Lever 
776b41b66d6SNeilBrown 	return -EINVAL;
777b41b66d6SNeilBrown }
77880212d59SNeilBrown 
779f2453978SChuck Lever /*
780262a0982SChuck Lever  * write_ports - Pass a socket file descriptor or transport name to listen on
781262a0982SChuck Lever  *
782262a0982SChuck Lever  * Input:
783262a0982SChuck Lever  *			buf:		ignored
784262a0982SChuck Lever  *			size:		zero
785262a0982SChuck Lever  * Output:
786262a0982SChuck Lever  *	On success:	passed-in buffer filled with a '\n'-terminated C
787262a0982SChuck Lever  *			string containing a whitespace-separated list of
788262a0982SChuck Lever  *			named NFSD listeners;
789262a0982SChuck Lever  *			return code is the size in bytes of the string
790262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
791262a0982SChuck Lever  *
792262a0982SChuck Lever  * OR
793262a0982SChuck Lever  *
794262a0982SChuck Lever  * Input:
795262a0982SChuck Lever  *			buf:		C string containing an unsigned
796262a0982SChuck Lever  *					integer value representing a bound
797262a0982SChuck Lever  *					but unconnected socket that is to be
798c71206a7SChuck Lever  *					used as an NFSD listener; listen(3)
799c71206a7SChuck Lever  *					must be called for a SOCK_STREAM
800c71206a7SChuck Lever  *					socket, otherwise it is ignored
801262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
802262a0982SChuck Lever  * Output:
803262a0982SChuck Lever  *	On success:	NFS service is started;
804262a0982SChuck Lever  *			passed-in buffer filled with a '\n'-terminated C
805262a0982SChuck Lever  *			string containing a unique alphanumeric name of
806262a0982SChuck Lever  *			the listener;
807262a0982SChuck Lever  *			return code is the size in bytes of the string
808262a0982SChuck Lever  *	On error:	return code is a negative errno value
809262a0982SChuck Lever  *
810262a0982SChuck Lever  * OR
811262a0982SChuck Lever  *
812262a0982SChuck Lever  * Input:
813262a0982SChuck Lever  *			buf:		C string containing a transport
814262a0982SChuck Lever  *					name and an unsigned integer value
815262a0982SChuck Lever  *					representing the port to listen on,
816262a0982SChuck Lever  *					separated by whitespace
817262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
818262a0982SChuck Lever  * Output:
819262a0982SChuck Lever  *	On success:	returns zero; NFS service is started
820262a0982SChuck Lever  *	On error:	return code is a negative errno value
821262a0982SChuck Lever  */
822bedbdd8bSNeil Brown static ssize_t write_ports(struct file *file, char *buf, size_t size)
823bedbdd8bSNeil Brown {
824bedbdd8bSNeil Brown 	ssize_t rv;
8253dd98a3bSJeff Layton 
826bedbdd8bSNeil Brown 	mutex_lock(&nfsd_mutex);
827244c7d44SAl Viro 	rv = __write_ports(file, buf, size, netns(file));
828bedbdd8bSNeil Brown 	mutex_unlock(&nfsd_mutex);
829bedbdd8bSNeil Brown 	return rv;
830bedbdd8bSNeil Brown }
831bedbdd8bSNeil Brown 
832bedbdd8bSNeil Brown 
833596bbe53SNeilBrown int nfsd_max_blksize;
834596bbe53SNeilBrown 
835f2453978SChuck Lever /*
836262a0982SChuck Lever  * write_maxblksize - Set or report the current NFS blksize
837262a0982SChuck Lever  *
838262a0982SChuck Lever  * Input:
839262a0982SChuck Lever  *			buf:		ignored
840262a0982SChuck Lever  *			size:		zero
841262a0982SChuck Lever  *
842262a0982SChuck Lever  * OR
843262a0982SChuck Lever  *
844262a0982SChuck Lever  * Input:
845262a0982SChuck Lever  *			buf:		C string containing an unsigned
846262a0982SChuck Lever  *					integer value representing the new
847262a0982SChuck Lever  *					NFS blksize
848262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
849262a0982SChuck Lever  * Output:
850262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C string
851262a0982SChuck Lever  *			containing numeric value of the current NFS blksize
852262a0982SChuck Lever  *			setting;
853262a0982SChuck Lever  *			return code is the size in bytes of the string
854262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
855262a0982SChuck Lever  */
856596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
857596bbe53SNeilBrown {
858596bbe53SNeilBrown 	char *mesg = buf;
859244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
8609dd9845fSStanislav Kinsbursky 
861596bbe53SNeilBrown 	if (size > 0) {
862596bbe53SNeilBrown 		int bsize;
863596bbe53SNeilBrown 		int rv = get_int(&mesg, &bsize);
864596bbe53SNeilBrown 		if (rv)
865596bbe53SNeilBrown 			return rv;
86639d432fcSChuck Lever 		trace_nfsd_ctl_maxblksize(netns(file), bsize);
86739d432fcSChuck Lever 
868596bbe53SNeilBrown 		/* force bsize into allowed range and
869596bbe53SNeilBrown 		 * required alignment.
870596bbe53SNeilBrown 		 */
8713c7aa15dSKinglong Mee 		bsize = max_t(int, bsize, 1024);
8723c7aa15dSKinglong Mee 		bsize = min_t(int, bsize, NFSSVC_MAXBLKSIZE);
873596bbe53SNeilBrown 		bsize &= ~(1024-1);
874bedbdd8bSNeil Brown 		mutex_lock(&nfsd_mutex);
8759dd9845fSStanislav Kinsbursky 		if (nn->nfsd_serv) {
876bedbdd8bSNeil Brown 			mutex_unlock(&nfsd_mutex);
877596bbe53SNeilBrown 			return -EBUSY;
878596bbe53SNeilBrown 		}
879596bbe53SNeilBrown 		nfsd_max_blksize = bsize;
880bedbdd8bSNeil Brown 		mutex_unlock(&nfsd_mutex);
881596bbe53SNeilBrown 	}
882e06b6405SChuck Lever 
883e06b6405SChuck Lever 	return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
884e06b6405SChuck Lever 							nfsd_max_blksize);
885596bbe53SNeilBrown }
886596bbe53SNeilBrown 
887f2453978SChuck Lever /*
8885b8db00bSJeff Layton  * write_maxconn - Set or report the current max number of connections
8895b8db00bSJeff Layton  *
8905b8db00bSJeff Layton  * Input:
8915b8db00bSJeff Layton  *			buf:		ignored
8925b8db00bSJeff Layton  *			size:		zero
8935b8db00bSJeff Layton  * OR
8945b8db00bSJeff Layton  *
8955b8db00bSJeff Layton  * Input:
8965b8db00bSJeff Layton  *			buf:		C string containing an unsigned
8975b8db00bSJeff Layton  *					integer value representing the new
8985b8db00bSJeff Layton  *					number of max connections
8995b8db00bSJeff Layton  *			size:		non-zero length of C string in @buf
9005b8db00bSJeff Layton  * Output:
9015b8db00bSJeff Layton  *	On success:	passed-in buffer filled with '\n'-terminated C string
9025b8db00bSJeff Layton  *			containing numeric value of max_connections setting
9035b8db00bSJeff Layton  *			for this net namespace;
9045b8db00bSJeff Layton  *			return code is the size in bytes of the string
9055b8db00bSJeff Layton  *	On error:	return code is zero or a negative errno value
9065b8db00bSJeff Layton  */
9075b8db00bSJeff Layton static ssize_t write_maxconn(struct file *file, char *buf, size_t size)
9085b8db00bSJeff Layton {
9095b8db00bSJeff Layton 	char *mesg = buf;
910244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
9115b8db00bSJeff Layton 	unsigned int maxconn = nn->max_connections;
9125b8db00bSJeff Layton 
9135b8db00bSJeff Layton 	if (size > 0) {
9145b8db00bSJeff Layton 		int rv = get_uint(&mesg, &maxconn);
9155b8db00bSJeff Layton 
9165b8db00bSJeff Layton 		if (rv)
9175b8db00bSJeff Layton 			return rv;
91839d432fcSChuck Lever 		trace_nfsd_ctl_maxconn(netns(file), maxconn);
9195b8db00bSJeff Layton 		nn->max_connections = maxconn;
9205b8db00bSJeff Layton 	}
9215b8db00bSJeff Layton 
9225b8db00bSJeff Layton 	return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%u\n", maxconn);
9235b8db00bSJeff Layton }
9245b8db00bSJeff Layton 
92570c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4
9269dd9845fSStanislav Kinsbursky static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size,
92720b7d86fSArnd Bergmann 				  time64_t *time, struct nfsd_net *nn)
9281da177e4SLinus Torvalds {
92939d432fcSChuck Lever 	struct dentry *dentry = file_dentry(file);
9301da177e4SLinus Torvalds 	char *mesg = buf;
931f0135740SJ. Bruce Fields 	int rv, i;
9321da177e4SLinus Torvalds 
9331da177e4SLinus Torvalds 	if (size > 0) {
9349dd9845fSStanislav Kinsbursky 		if (nn->nfsd_serv)
9353dd98a3bSJeff Layton 			return -EBUSY;
936f0135740SJ. Bruce Fields 		rv = get_int(&mesg, &i);
9371da177e4SLinus Torvalds 		if (rv)
9381da177e4SLinus Torvalds 			return rv;
93939d432fcSChuck Lever 		trace_nfsd_ctl_time(netns(file), dentry->d_name.name,
94039d432fcSChuck Lever 				    dentry->d_name.len, i);
94139d432fcSChuck Lever 
942e7b184f1SJ. Bruce Fields 		/*
943e7b184f1SJ. Bruce Fields 		 * Some sanity checking.  We don't have a reason for
944e7b184f1SJ. Bruce Fields 		 * these particular numbers, but problems with the
945e7b184f1SJ. Bruce Fields 		 * extremes are:
946e7b184f1SJ. Bruce Fields 		 *	- Too short: the briefest network outage may
947e7b184f1SJ. Bruce Fields 		 *	  cause clients to lose all their locks.  Also,
948e7b184f1SJ. Bruce Fields 		 *	  the frequent polling may be wasteful.
949e7b184f1SJ. Bruce Fields 		 *	- Too long: do you really want reboot recovery
950e7b184f1SJ. Bruce Fields 		 *	  to take more than an hour?  Or to make other
951e7b184f1SJ. Bruce Fields 		 *	  clients wait an hour before being able to
952e7b184f1SJ. Bruce Fields 		 *	  revoke a dead client's locks?
953e7b184f1SJ. Bruce Fields 		 */
954f0135740SJ. Bruce Fields 		if (i < 10 || i > 3600)
9551da177e4SLinus Torvalds 			return -EINVAL;
956f0135740SJ. Bruce Fields 		*time = i;
9571da177e4SLinus Torvalds 	}
958e06b6405SChuck Lever 
95920b7d86fSArnd Bergmann 	return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%lld\n", *time);
960f0135740SJ. Bruce Fields }
961f0135740SJ. Bruce Fields 
9629dd9845fSStanislav Kinsbursky static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size,
96320b7d86fSArnd Bergmann 				time64_t *time, struct nfsd_net *nn)
964f0135740SJ. Bruce Fields {
965f0135740SJ. Bruce Fields 	ssize_t rv;
966f0135740SJ. Bruce Fields 
967f0135740SJ. Bruce Fields 	mutex_lock(&nfsd_mutex);
9689dd9845fSStanislav Kinsbursky 	rv = __nfsd4_write_time(file, buf, size, time, nn);
969f0135740SJ. Bruce Fields 	mutex_unlock(&nfsd_mutex);
970f0135740SJ. Bruce Fields 	return rv;
9711da177e4SLinus Torvalds }
9721da177e4SLinus Torvalds 
973f2453978SChuck Lever /*
974262a0982SChuck Lever  * write_leasetime - Set or report the current NFSv4 lease time
975262a0982SChuck Lever  *
976262a0982SChuck Lever  * Input:
977262a0982SChuck Lever  *			buf:		ignored
978262a0982SChuck Lever  *			size:		zero
979262a0982SChuck Lever  *
980262a0982SChuck Lever  * OR
981262a0982SChuck Lever  *
982262a0982SChuck Lever  * Input:
983262a0982SChuck Lever  *			buf:		C string containing an unsigned
984262a0982SChuck Lever  *					integer value representing the new
985262a0982SChuck Lever  *					NFSv4 lease expiry time
986262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
987262a0982SChuck Lever  * Output:
988262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C
989262a0982SChuck Lever  *			string containing unsigned integer value of the
990262a0982SChuck Lever  *			current lease expiry time;
991262a0982SChuck Lever  *			return code is the size in bytes of the string
992262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
993262a0982SChuck Lever  */
9943dd98a3bSJeff Layton static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
9953dd98a3bSJeff Layton {
996244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
9979dd9845fSStanislav Kinsbursky 	return nfsd4_write_time(file, buf, size, &nn->nfsd4_lease, nn);
9983dd98a3bSJeff Layton }
9993dd98a3bSJeff Layton 
1000f2453978SChuck Lever /*
1001efc4bb4fSJ. Bruce Fields  * write_gracetime - Set or report current NFSv4 grace period time
1002efc4bb4fSJ. Bruce Fields  *
1003efc4bb4fSJ. Bruce Fields  * As above, but sets the time of the NFSv4 grace period.
1004efc4bb4fSJ. Bruce Fields  *
1005efc4bb4fSJ. Bruce Fields  * Note this should never be set to less than the *previous*
1006efc4bb4fSJ. Bruce Fields  * lease-period time, but we don't try to enforce this.  (In the common
1007efc4bb4fSJ. Bruce Fields  * case (a new boot), we don't know what the previous lease time was
1008efc4bb4fSJ. Bruce Fields  * anyway.)
1009efc4bb4fSJ. Bruce Fields  */
1010efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1011efc4bb4fSJ. Bruce Fields {
1012244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
10139dd9845fSStanislav Kinsbursky 	return nfsd4_write_time(file, buf, size, &nn->nfsd4_grace, nn);
1014efc4bb4fSJ. Bruce Fields }
1015efc4bb4fSJ. Bruce Fields 
101674fd4873SJeff Layton #ifdef CONFIG_NFSD_LEGACY_CLIENT_TRACKING
10179dd9845fSStanislav Kinsbursky static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size,
10189dd9845fSStanislav Kinsbursky 				   struct nfsd_net *nn)
10190964a3d3SNeilBrown {
10200964a3d3SNeilBrown 	char *mesg = buf;
10210964a3d3SNeilBrown 	char *recdir;
10220964a3d3SNeilBrown 	int len, status;
10230964a3d3SNeilBrown 
10243dd98a3bSJeff Layton 	if (size > 0) {
10259dd9845fSStanislav Kinsbursky 		if (nn->nfsd_serv)
10263dd98a3bSJeff Layton 			return -EBUSY;
10273dd98a3bSJeff Layton 		if (size > PATH_MAX || buf[size-1] != '\n')
10280964a3d3SNeilBrown 			return -EINVAL;
10290964a3d3SNeilBrown 		buf[size-1] = 0;
10300964a3d3SNeilBrown 
10310964a3d3SNeilBrown 		recdir = mesg;
10320964a3d3SNeilBrown 		len = qword_get(&mesg, recdir, size);
10330964a3d3SNeilBrown 		if (len <= 0)
10340964a3d3SNeilBrown 			return -EINVAL;
103539d432fcSChuck Lever 		trace_nfsd_ctl_recoverydir(netns(file), recdir);
10360964a3d3SNeilBrown 
10370964a3d3SNeilBrown 		status = nfs4_reset_recoverydir(recdir);
103869049961SAndi Kleen 		if (status)
103969049961SAndi Kleen 			return status;
10403dd98a3bSJeff Layton 	}
10413d72ab8fSChuck Lever 
10423d72ab8fSChuck Lever 	return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
10433d72ab8fSChuck Lever 							nfs4_recoverydir());
10440964a3d3SNeilBrown }
10453dd98a3bSJeff Layton 
1046f2453978SChuck Lever /*
1047262a0982SChuck Lever  * write_recoverydir - Set or report the pathname of the recovery directory
1048262a0982SChuck Lever  *
1049262a0982SChuck Lever  * Input:
1050262a0982SChuck Lever  *			buf:		ignored
1051262a0982SChuck Lever  *			size:		zero
1052262a0982SChuck Lever  *
1053262a0982SChuck Lever  * OR
1054262a0982SChuck Lever  *
1055262a0982SChuck Lever  * Input:
1056262a0982SChuck Lever  *			buf:		C string containing the pathname
1057262a0982SChuck Lever  *					of the directory on a local file
1058262a0982SChuck Lever  *					system containing permanent NFSv4
1059262a0982SChuck Lever  *					recovery data
1060262a0982SChuck Lever  *			size:		non-zero length of C string in @buf
1061262a0982SChuck Lever  * Output:
1062262a0982SChuck Lever  *	On success:	passed-in buffer filled with '\n'-terminated C string
1063262a0982SChuck Lever  *			containing the current recovery pathname setting;
1064262a0982SChuck Lever  *			return code is the size in bytes of the string
1065262a0982SChuck Lever  *	On error:	return code is zero or a negative errno value
1066262a0982SChuck Lever  */
10673dd98a3bSJeff Layton static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
10683dd98a3bSJeff Layton {
10693dd98a3bSJeff Layton 	ssize_t rv;
1070244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
10713dd98a3bSJeff Layton 
10723dd98a3bSJeff Layton 	mutex_lock(&nfsd_mutex);
10739dd9845fSStanislav Kinsbursky 	rv = __write_recoverydir(file, buf, size, nn);
10743dd98a3bSJeff Layton 	mutex_unlock(&nfsd_mutex);
10753dd98a3bSJeff Layton 	return rv;
10763dd98a3bSJeff Layton }
107774fd4873SJeff Layton #endif
10783dd98a3bSJeff Layton 
1079f2453978SChuck Lever /*
10807f5ef2e9SJeff Layton  * write_v4_end_grace - release grace period for nfsd's v4.x lock manager
10817f5ef2e9SJeff Layton  *
10827f5ef2e9SJeff Layton  * Input:
10837f5ef2e9SJeff Layton  *			buf:		ignored
10847f5ef2e9SJeff Layton  *			size:		zero
10857f5ef2e9SJeff Layton  * OR
10867f5ef2e9SJeff Layton  *
10877f5ef2e9SJeff Layton  * Input:
10887f5ef2e9SJeff Layton  *			buf:		any value
10897f5ef2e9SJeff Layton  *			size:		non-zero length of C string in @buf
10907f5ef2e9SJeff Layton  * Output:
10917f5ef2e9SJeff Layton  *			passed-in buffer filled with "Y" or "N" with a newline
10927f5ef2e9SJeff Layton  *			and NULL-terminated C string. This indicates whether
10937f5ef2e9SJeff Layton  *			the grace period has ended in the current net
10947f5ef2e9SJeff Layton  *			namespace. Return code is the size in bytes of the
10957f5ef2e9SJeff Layton  *			string. Writing a string that starts with 'Y', 'y', or
10967f5ef2e9SJeff Layton  *			'1' to the file will end the grace period for nfsd's v4
10977f5ef2e9SJeff Layton  *			lock manager.
10987f5ef2e9SJeff Layton  */
10997f5ef2e9SJeff Layton static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size)
11007f5ef2e9SJeff Layton {
1101244c7d44SAl Viro 	struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
11027f5ef2e9SJeff Layton 
11037f5ef2e9SJeff Layton 	if (size > 0) {
11047f5ef2e9SJeff Layton 		switch(buf[0]) {
11057f5ef2e9SJeff Layton 		case 'Y':
11067f5ef2e9SJeff Layton 		case 'y':
11077f5ef2e9SJeff Layton 		case '1':
1108dd838821SYihao Wu 			if (!nn->nfsd_serv)
110962a063b8SJ. Bruce Fields 				return -EBUSY;
111039d432fcSChuck Lever 			trace_nfsd_end_grace(netns(file));
11118073a98eSChuck Lever 			nfsd4_end_grace(nn);
11127f5ef2e9SJeff Layton 			break;
11137f5ef2e9SJeff Layton 		default:
11147f5ef2e9SJeff Layton 			return -EINVAL;
11157f5ef2e9SJeff Layton 		}
11167f5ef2e9SJeff Layton 	}
11177f5ef2e9SJeff Layton 
11187f5ef2e9SJeff Layton 	return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%c\n",
11197f5ef2e9SJeff Layton 			 nn->grace_ended ? 'Y' : 'N');
11207f5ef2e9SJeff Layton }
11217f5ef2e9SJeff Layton 
112270c3b76cSNeilBrown #endif
11230964a3d3SNeilBrown 
11241da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/
11251da177e4SLinus Torvalds /*
11261da177e4SLinus Torvalds  *	populating the filesystem.
11271da177e4SLinus Torvalds  */
11281da177e4SLinus Torvalds 
1129e8a79fb1SJ. Bruce Fields /* Basically copying rpc_get_inode. */
1130e8a79fb1SJ. Bruce Fields static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode)
1131e8a79fb1SJ. Bruce Fields {
1132e8a79fb1SJ. Bruce Fields 	struct inode *inode = new_inode(sb);
1133e8a79fb1SJ. Bruce Fields 	if (!inode)
1134e8a79fb1SJ. Bruce Fields 		return NULL;
1135e8a79fb1SJ. Bruce Fields 	/* Following advice from simple_fill_super documentation: */
1136e8a79fb1SJ. Bruce Fields 	inode->i_ino = iunique(sb, NFSD_MaxReserved);
1137e8a79fb1SJ. Bruce Fields 	inode->i_mode = mode;
113811fec9b9SJeff Layton 	simple_inode_init_ts(inode);
1139e8a79fb1SJ. Bruce Fields 	switch (mode & S_IFMT) {
1140e8a79fb1SJ. Bruce Fields 	case S_IFDIR:
1141e8a79fb1SJ. Bruce Fields 		inode->i_fop = &simple_dir_operations;
1142e8a79fb1SJ. Bruce Fields 		inode->i_op = &simple_dir_inode_operations;
1143e8a79fb1SJ. Bruce Fields 		inc_nlink(inode);
114476c50eb7SGustavo A. R. Silva 		break;
11454df750c9SChuck Lever 	case S_IFLNK:
11464df750c9SChuck Lever 		inode->i_op = &simple_symlink_inode_operations;
11474df750c9SChuck Lever 		break;
1148e8a79fb1SJ. Bruce Fields 	default:
1149e8a79fb1SJ. Bruce Fields 		break;
1150e8a79fb1SJ. Bruce Fields 	}
1151e8a79fb1SJ. Bruce Fields 	return inode;
1152e8a79fb1SJ. Bruce Fields }
1153e8a79fb1SJ. Bruce Fields 
1154bebd6997SJ. Bruce Fields static int __nfsd_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode, struct nfsdfs_client *ncl)
1155e8a79fb1SJ. Bruce Fields {
1156e8a79fb1SJ. Bruce Fields 	struct inode *inode;
1157e8a79fb1SJ. Bruce Fields 
1158e8a79fb1SJ. Bruce Fields 	inode = nfsd_get_inode(dir->i_sb, mode);
1159e8a79fb1SJ. Bruce Fields 	if (!inode)
1160e8a79fb1SJ. Bruce Fields 		return -ENOMEM;
1161bebd6997SJ. Bruce Fields 	if (ncl) {
1162bebd6997SJ. Bruce Fields 		inode->i_private = ncl;
1163bebd6997SJ. Bruce Fields 		kref_get(&ncl->cl_ref);
1164bebd6997SJ. Bruce Fields 	}
1165e8a79fb1SJ. Bruce Fields 	d_add(dentry, inode);
1166e8a79fb1SJ. Bruce Fields 	inc_nlink(dir);
1167e8a79fb1SJ. Bruce Fields 	fsnotify_mkdir(dir, dentry);
1168e8a79fb1SJ. Bruce Fields 	return 0;
1169e8a79fb1SJ. Bruce Fields }
1170e8a79fb1SJ. Bruce Fields 
1171e8a79fb1SJ. Bruce Fields static struct dentry *nfsd_mkdir(struct dentry *parent, struct nfsdfs_client *ncl, char *name)
1172e8a79fb1SJ. Bruce Fields {
1173e8a79fb1SJ. Bruce Fields 	struct inode *dir = parent->d_inode;
1174e8a79fb1SJ. Bruce Fields 	struct dentry *dentry;
1175e8a79fb1SJ. Bruce Fields 	int ret = -ENOMEM;
1176e8a79fb1SJ. Bruce Fields 
1177e8a79fb1SJ. Bruce Fields 	inode_lock(dir);
1178e8a79fb1SJ. Bruce Fields 	dentry = d_alloc_name(parent, name);
1179e8a79fb1SJ. Bruce Fields 	if (!dentry)
1180e8a79fb1SJ. Bruce Fields 		goto out_err;
1181bebd6997SJ. Bruce Fields 	ret = __nfsd_mkdir(d_inode(parent), dentry, S_IFDIR | 0600, ncl);
1182e8a79fb1SJ. Bruce Fields 	if (ret)
1183e8a79fb1SJ. Bruce Fields 		goto out_err;
1184e8a79fb1SJ. Bruce Fields out:
1185e8a79fb1SJ. Bruce Fields 	inode_unlock(dir);
1186e8a79fb1SJ. Bruce Fields 	return dentry;
1187e8a79fb1SJ. Bruce Fields out_err:
1188d6846bfbSTetsuo Handa 	dput(dentry);
1189e8a79fb1SJ. Bruce Fields 	dentry = ERR_PTR(ret);
1190e8a79fb1SJ. Bruce Fields 	goto out;
1191e8a79fb1SJ. Bruce Fields }
1192e8a79fb1SJ. Bruce Fields 
11934df750c9SChuck Lever #if IS_ENABLED(CONFIG_SUNRPC_GSS)
11944df750c9SChuck Lever static int __nfsd_symlink(struct inode *dir, struct dentry *dentry,
11954df750c9SChuck Lever 			  umode_t mode, const char *content)
11964df750c9SChuck Lever {
11974df750c9SChuck Lever 	struct inode *inode;
11984df750c9SChuck Lever 
11994df750c9SChuck Lever 	inode = nfsd_get_inode(dir->i_sb, mode);
12004df750c9SChuck Lever 	if (!inode)
12014df750c9SChuck Lever 		return -ENOMEM;
12024df750c9SChuck Lever 
12034df750c9SChuck Lever 	inode->i_link = (char *)content;
12044df750c9SChuck Lever 	inode->i_size = strlen(content);
12054df750c9SChuck Lever 
12064df750c9SChuck Lever 	d_add(dentry, inode);
12074df750c9SChuck Lever 	inc_nlink(dir);
12084df750c9SChuck Lever 	fsnotify_create(dir, dentry);
12094df750c9SChuck Lever 	return 0;
12104df750c9SChuck Lever }
12114df750c9SChuck Lever 
12124df750c9SChuck Lever /*
12134df750c9SChuck Lever  * @content is assumed to be a NUL-terminated string that lives
12144df750c9SChuck Lever  * longer than the symlink itself.
12154df750c9SChuck Lever  */
121639d432fcSChuck Lever static void _nfsd_symlink(struct dentry *parent, const char *name,
12174df750c9SChuck Lever 			  const char *content)
12184df750c9SChuck Lever {
12194df750c9SChuck Lever 	struct inode *dir = parent->d_inode;
12204df750c9SChuck Lever 	struct dentry *dentry;
12214b471a8bSChuck Lever 	int ret;
12224df750c9SChuck Lever 
12234df750c9SChuck Lever 	inode_lock(dir);
12244df750c9SChuck Lever 	dentry = d_alloc_name(parent, name);
12254df750c9SChuck Lever 	if (!dentry)
12264b471a8bSChuck Lever 		goto out;
12274df750c9SChuck Lever 	ret = __nfsd_symlink(d_inode(parent), dentry, S_IFLNK | 0777, content);
12284df750c9SChuck Lever 	if (ret)
12294b471a8bSChuck Lever 		dput(dentry);
12304df750c9SChuck Lever out:
12314df750c9SChuck Lever 	inode_unlock(dir);
12324df750c9SChuck Lever }
12334df750c9SChuck Lever #else
123439d432fcSChuck Lever static inline void _nfsd_symlink(struct dentry *parent, const char *name,
12354df750c9SChuck Lever 				 const char *content)
12364df750c9SChuck Lever {
12374df750c9SChuck Lever }
12384df750c9SChuck Lever 
12394df750c9SChuck Lever #endif
12404df750c9SChuck Lever 
1241b7a14708SAl Viro static void clear_ncl(struct dentry *dentry)
1242e8a79fb1SJ. Bruce Fields {
1243b7a14708SAl Viro 	struct inode *inode = d_inode(dentry);
124497ad4031SJ. Bruce Fields 	struct nfsdfs_client *ncl = inode->i_private;
124597ad4031SJ. Bruce Fields 
1246b7a14708SAl Viro 	spin_lock(&inode->i_lock);
124797ad4031SJ. Bruce Fields 	inode->i_private = NULL;
1248b7a14708SAl Viro 	spin_unlock(&inode->i_lock);
124997ad4031SJ. Bruce Fields 	kref_put(&ncl->cl_ref, ncl->cl_release);
125097ad4031SJ. Bruce Fields }
125197ad4031SJ. Bruce Fields 
125297ad4031SJ. Bruce Fields struct nfsdfs_client *get_nfsdfs_client(struct inode *inode)
125397ad4031SJ. Bruce Fields {
125497ad4031SJ. Bruce Fields 	struct nfsdfs_client *nc;
125597ad4031SJ. Bruce Fields 
1256b7a14708SAl Viro 	spin_lock(&inode->i_lock);
1257b7a14708SAl Viro 	nc = inode->i_private;
1258b7a14708SAl Viro 	if (nc)
1259b7a14708SAl Viro 		kref_get(&nc->cl_ref);
1260b7a14708SAl Viro 	spin_unlock(&inode->i_lock);
126197ad4031SJ. Bruce Fields 	return nc;
126297ad4031SJ. Bruce Fields }
126397ad4031SJ. Bruce Fields 
126497ad4031SJ. Bruce Fields /* XXX: cut'n'paste from simple_fill_super; figure out if we could share
126597ad4031SJ. Bruce Fields  * code instead. */
126697ad4031SJ. Bruce Fields static  int nfsdfs_create_files(struct dentry *root,
1267472d155aSNeilBrown 				const struct tree_descr *files,
1268b7a14708SAl Viro 				struct nfsdfs_client *ncl,
1269472d155aSNeilBrown 				struct dentry **fdentries)
127097ad4031SJ. Bruce Fields {
127197ad4031SJ. Bruce Fields 	struct inode *dir = d_inode(root);
127297ad4031SJ. Bruce Fields 	struct inode *inode;
127397ad4031SJ. Bruce Fields 	struct dentry *dentry;
127497ad4031SJ. Bruce Fields 	int i;
127597ad4031SJ. Bruce Fields 
127697ad4031SJ. Bruce Fields 	inode_lock(dir);
127797ad4031SJ. Bruce Fields 	for (i = 0; files->name && files->name[0]; i++, files++) {
127897ad4031SJ. Bruce Fields 		dentry = d_alloc_name(root, files->name);
127997ad4031SJ. Bruce Fields 		if (!dentry)
128097ad4031SJ. Bruce Fields 			goto out;
128197ad4031SJ. Bruce Fields 		inode = nfsd_get_inode(d_inode(root)->i_sb,
128297ad4031SJ. Bruce Fields 					S_IFREG | files->mode);
128397ad4031SJ. Bruce Fields 		if (!inode) {
128497ad4031SJ. Bruce Fields 			dput(dentry);
128597ad4031SJ. Bruce Fields 			goto out;
128697ad4031SJ. Bruce Fields 		}
1287b7a14708SAl Viro 		kref_get(&ncl->cl_ref);
128897ad4031SJ. Bruce Fields 		inode->i_fop = files->ops;
1289b7a14708SAl Viro 		inode->i_private = ncl;
129097ad4031SJ. Bruce Fields 		d_add(dentry, inode);
129197ad4031SJ. Bruce Fields 		fsnotify_create(dir, dentry);
1292472d155aSNeilBrown 		if (fdentries)
1293472d155aSNeilBrown 			fdentries[i] = dentry;
129497ad4031SJ. Bruce Fields 	}
129597ad4031SJ. Bruce Fields 	inode_unlock(dir);
129697ad4031SJ. Bruce Fields 	return 0;
129797ad4031SJ. Bruce Fields out:
129897ad4031SJ. Bruce Fields 	inode_unlock(dir);
129997ad4031SJ. Bruce Fields 	return -ENOMEM;
130097ad4031SJ. Bruce Fields }
130197ad4031SJ. Bruce Fields 
130297ad4031SJ. Bruce Fields /* on success, returns positive number unique to that client. */
130397ad4031SJ. Bruce Fields struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
130497ad4031SJ. Bruce Fields 				 struct nfsdfs_client *ncl, u32 id,
1305472d155aSNeilBrown 				 const struct tree_descr *files,
1306472d155aSNeilBrown 				 struct dentry **fdentries)
130797ad4031SJ. Bruce Fields {
130897ad4031SJ. Bruce Fields 	struct dentry *dentry;
1309e8a79fb1SJ. Bruce Fields 	char name[11];
131097ad4031SJ. Bruce Fields 	int ret;
1311e8a79fb1SJ. Bruce Fields 
1312bf5ed3e3SJ. Bruce Fields 	sprintf(name, "%u", id);
1313e8a79fb1SJ. Bruce Fields 
131497ad4031SJ. Bruce Fields 	dentry = nfsd_mkdir(nn->nfsd_client_dir, ncl, name);
131597ad4031SJ. Bruce Fields 	if (IS_ERR(dentry)) /* XXX: tossing errors? */
131697ad4031SJ. Bruce Fields 		return NULL;
1317b7a14708SAl Viro 	ret = nfsdfs_create_files(dentry, files, ncl, fdentries);
131897ad4031SJ. Bruce Fields 	if (ret) {
131997ad4031SJ. Bruce Fields 		nfsd_client_rmdir(dentry);
132097ad4031SJ. Bruce Fields 		return NULL;
132197ad4031SJ. Bruce Fields 	}
132297ad4031SJ. Bruce Fields 	return dentry;
1323e8a79fb1SJ. Bruce Fields }
1324e8a79fb1SJ. Bruce Fields 
1325e8a79fb1SJ. Bruce Fields /* Taken from __rpc_rmdir: */
1326e8a79fb1SJ. Bruce Fields void nfsd_client_rmdir(struct dentry *dentry)
1327e8a79fb1SJ. Bruce Fields {
1328b7a14708SAl Viro 	simple_recursive_removal(dentry, clear_ncl);
1329e8a79fb1SJ. Bruce Fields }
1330e8a79fb1SJ. Bruce Fields 
133196a374a3SDavid Howells static int nfsd_fill_super(struct super_block *sb, struct fs_context *fc)
13321da177e4SLinus Torvalds {
1333e8a79fb1SJ. Bruce Fields 	struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
1334e8a79fb1SJ. Bruce Fields 							nfsd_net_id);
1335e8a79fb1SJ. Bruce Fields 	struct dentry *dentry;
1336e8a79fb1SJ. Bruce Fields 	int ret;
1337e8a79fb1SJ. Bruce Fields 
1338cda37124SEric Biggers 	static const struct tree_descr nfsd_files[] = {
133996d851c4SStanislav Kinsbursky 		[NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO},
134020ad856eSAmir Goldstein 		/* Per-export io stats use same ops as exports file */
134120ad856eSAmir Goldstein 		[NFSD_Export_Stats] = {"export_stats", &exports_nfsd_operations, S_IRUGO},
1342e8e8753fSJ. Bruce Fields 		[NFSD_Export_features] = {"export_features",
13439beeaab8SChenXiaoSong 					&export_features_fops, S_IRUGO},
13444373ea84SWendy Cheng 		[NFSD_FO_UnlockIP] = {"unlock_ip",
13454373ea84SWendy Cheng 					&transaction_ops, S_IWUSR|S_IRUSR},
134617efa372SWendy Cheng 		[NFSD_FO_UnlockFS] = {"unlock_filesystem",
134717efa372SWendy Cheng 					&transaction_ops, S_IWUSR|S_IRUSR},
13481da177e4SLinus Torvalds 		[NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
13491da177e4SLinus Torvalds 		[NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1350eed2965aSGreg Banks 		[NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
135103cf6c9fSGreg Banks 		[NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
135264776611SChenXiaoSong 		[NFSD_Reply_Cache_Stats] = {"reply_cache_stats",
135364776611SChenXiaoSong 					&nfsd_reply_cache_stats_fops, S_IRUGO},
135470c3b76cSNeilBrown 		[NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
135580212d59SNeilBrown 		[NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1356596bbe53SNeilBrown 		[NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
13575b8db00bSJeff Layton 		[NFSD_MaxConnections] = {"max_connections", &transaction_ops, S_IWUSR|S_IRUGO},
13581342f9ddSChenXiaoSong 		[NFSD_Filecache] = {"filecache", &nfsd_file_cache_stats_fops, S_IRUGO},
13591da177e4SLinus Torvalds #ifdef CONFIG_NFSD_V4
13601da177e4SLinus Torvalds 		[NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1361efc4bb4fSJ. Bruce Fields 		[NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
13620964a3d3SNeilBrown 		[NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
13637f5ef2e9SJeff Layton 		[NFSD_V4EndGrace] = {"v4_end_grace", &transaction_ops, S_IWUSR|S_IRUGO},
13641da177e4SLinus Torvalds #endif
13651da177e4SLinus Torvalds 		/* last one */ {""}
13661da177e4SLinus Torvalds 	};
136796a374a3SDavid Howells 
1368e8a79fb1SJ. Bruce Fields 	ret = simple_fill_super(sb, 0x6e667364, nfsd_files);
1369e8a79fb1SJ. Bruce Fields 	if (ret)
1370e8a79fb1SJ. Bruce Fields 		return ret;
137139d432fcSChuck Lever 	_nfsd_symlink(sb->s_root, "supported_krb5_enctypes",
13724df750c9SChuck Lever 		      "/proc/net/rpc/gss_krb5_enctypes");
1373e8a79fb1SJ. Bruce Fields 	dentry = nfsd_mkdir(sb->s_root, NULL, "clients");
1374e8a79fb1SJ. Bruce Fields 	if (IS_ERR(dentry))
1375e8a79fb1SJ. Bruce Fields 		return PTR_ERR(dentry);
1376e8a79fb1SJ. Bruce Fields 	nn->nfsd_client_dir = dentry;
1377e8a79fb1SJ. Bruce Fields 	return 0;
13781da177e4SLinus Torvalds }
13791da177e4SLinus Torvalds 
138096a374a3SDavid Howells static int nfsd_fs_get_tree(struct fs_context *fc)
13811da177e4SLinus Torvalds {
1382533770ccSAl Viro 	return get_tree_keyed(fc, nfsd_fill_super, get_net(fc->net_ns));
138396a374a3SDavid Howells }
138496a374a3SDavid Howells 
138596a374a3SDavid Howells static void nfsd_fs_free_fc(struct fs_context *fc)
138696a374a3SDavid Howells {
138796a374a3SDavid Howells 	if (fc->s_fs_info)
138896a374a3SDavid Howells 		put_net(fc->s_fs_info);
138996a374a3SDavid Howells }
139096a374a3SDavid Howells 
139196a374a3SDavid Howells static const struct fs_context_operations nfsd_fs_context_ops = {
139296a374a3SDavid Howells 	.free		= nfsd_fs_free_fc,
139396a374a3SDavid Howells 	.get_tree	= nfsd_fs_get_tree,
139496a374a3SDavid Howells };
139596a374a3SDavid Howells 
139696a374a3SDavid Howells static int nfsd_init_fs_context(struct fs_context *fc)
139796a374a3SDavid Howells {
139896a374a3SDavid Howells 	put_user_ns(fc->user_ns);
139996a374a3SDavid Howells 	fc->user_ns = get_user_ns(fc->net_ns->user_ns);
140096a374a3SDavid Howells 	fc->ops = &nfsd_fs_context_ops;
140196a374a3SDavid Howells 	return 0;
140211f77942SStanislav Kinsbursky }
140311f77942SStanislav Kinsbursky 
140411f77942SStanislav Kinsbursky static void nfsd_umount(struct super_block *sb)
140511f77942SStanislav Kinsbursky {
140611f77942SStanislav Kinsbursky 	struct net *net = sb->s_fs_info;
140711f77942SStanislav Kinsbursky 
1408c6c7f2a8STrond Myklebust 	nfsd_shutdown_threads(net);
1409c6c7f2a8STrond Myklebust 
141011f77942SStanislav Kinsbursky 	kill_litter_super(sb);
141111f77942SStanislav Kinsbursky 	put_net(net);
14121da177e4SLinus Torvalds }
14131da177e4SLinus Torvalds 
14141da177e4SLinus Torvalds static struct file_system_type nfsd_fs_type = {
14151da177e4SLinus Torvalds 	.owner		= THIS_MODULE,
14161da177e4SLinus Torvalds 	.name		= "nfsd",
141796a374a3SDavid Howells 	.init_fs_context = nfsd_init_fs_context,
141811f77942SStanislav Kinsbursky 	.kill_sb	= nfsd_umount,
14191da177e4SLinus Torvalds };
14207f78e035SEric W. Biederman MODULE_ALIAS_FS("nfsd");
14211da177e4SLinus Torvalds 
1422e331f606SJ. Bruce Fields #ifdef CONFIG_PROC_FS
1423340086daSTom Rix 
1424340086daSTom Rix static int exports_proc_open(struct inode *inode, struct file *file)
1425340086daSTom Rix {
1426340086daSTom Rix 	return exports_net_open(current->nsproxy->net_ns, file);
1427340086daSTom Rix }
1428340086daSTom Rix 
1429340086daSTom Rix static const struct proc_ops exports_proc_ops = {
1430340086daSTom Rix 	.proc_open	= exports_proc_open,
1431340086daSTom Rix 	.proc_read	= seq_read,
1432340086daSTom Rix 	.proc_lseek	= seq_lseek,
1433340086daSTom Rix 	.proc_release	= seq_release,
1434340086daSTom Rix };
1435340086daSTom Rix 
1436e331f606SJ. Bruce Fields static int create_proc_exports_entry(void)
1437e331f606SJ. Bruce Fields {
1438e331f606SJ. Bruce Fields 	struct proc_dir_entry *entry;
1439e331f606SJ. Bruce Fields 
1440e331f606SJ. Bruce Fields 	entry = proc_mkdir("fs/nfs", NULL);
1441e331f606SJ. Bruce Fields 	if (!entry)
1442e331f606SJ. Bruce Fields 		return -ENOMEM;
144397a32539SAlexey Dobriyan 	entry = proc_create("exports", 0, entry, &exports_proc_ops);
1444ff7c4b36Sfanchaoting 	if (!entry) {
1445ff7c4b36Sfanchaoting 		remove_proc_entry("fs/nfs", NULL);
1446e331f606SJ. Bruce Fields 		return -ENOMEM;
1447ff7c4b36Sfanchaoting 	}
1448e331f606SJ. Bruce Fields 	return 0;
1449e331f606SJ. Bruce Fields }
1450e331f606SJ. Bruce Fields #else /* CONFIG_PROC_FS */
1451e331f606SJ. Bruce Fields static int create_proc_exports_entry(void)
1452e331f606SJ. Bruce Fields {
1453e331f606SJ. Bruce Fields 	return 0;
1454e331f606SJ. Bruce Fields }
1455e331f606SJ. Bruce Fields #endif
1456e331f606SJ. Bruce Fields 
1457c7d03a00SAlexey Dobriyan unsigned int nfsd_net_id;
14585717e012SStanislav Kinsbursky 
14595e092be7SChuck Lever /**
1460bd9d6a3eSLorenzo Bianconi  * nfsd_nl_rpc_status_get_start - Prepare rpc_status_get dumpit
1461bd9d6a3eSLorenzo Bianconi  * @cb: netlink metadata and command arguments
1462bd9d6a3eSLorenzo Bianconi  *
1463bd9d6a3eSLorenzo Bianconi  * Return values:
1464bd9d6a3eSLorenzo Bianconi  *   %0: The rpc_status_get command may proceed
1465bd9d6a3eSLorenzo Bianconi  *   %-ENODEV: There is no NFSD running in this namespace
1466bd9d6a3eSLorenzo Bianconi  */
146713727f85SLorenzo Bianconi int nfsd_nl_rpc_status_get_start(struct netlink_callback *cb)
146813727f85SLorenzo Bianconi {
1469bd9d6a3eSLorenzo Bianconi 	struct nfsd_net *nn = net_generic(sock_net(cb->skb->sk), nfsd_net_id);
1470bd9d6a3eSLorenzo Bianconi 	int ret = -ENODEV;
1471bd9d6a3eSLorenzo Bianconi 
1472bd9d6a3eSLorenzo Bianconi 	mutex_lock(&nfsd_mutex);
14731bd773b4SNeilBrown 	if (nn->nfsd_serv)
1474bd9d6a3eSLorenzo Bianconi 		ret = 0;
14751bd773b4SNeilBrown 	else
1476bd9d6a3eSLorenzo Bianconi 		mutex_unlock(&nfsd_mutex);
1477bd9d6a3eSLorenzo Bianconi 
1478bd9d6a3eSLorenzo Bianconi 	return ret;
1479bd9d6a3eSLorenzo Bianconi }
1480bd9d6a3eSLorenzo Bianconi 
1481bd9d6a3eSLorenzo Bianconi static int nfsd_genl_rpc_status_compose_msg(struct sk_buff *skb,
1482bd9d6a3eSLorenzo Bianconi 					    struct netlink_callback *cb,
1483bd9d6a3eSLorenzo Bianconi 					    struct nfsd_genl_rqstp *rqstp)
1484bd9d6a3eSLorenzo Bianconi {
1485bd9d6a3eSLorenzo Bianconi 	void *hdr;
1486bd9d6a3eSLorenzo Bianconi 	u32 i;
1487bd9d6a3eSLorenzo Bianconi 
1488bd9d6a3eSLorenzo Bianconi 	hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
1489bd9d6a3eSLorenzo Bianconi 			  &nfsd_nl_family, 0, NFSD_CMD_RPC_STATUS_GET);
1490bd9d6a3eSLorenzo Bianconi 	if (!hdr)
1491bd9d6a3eSLorenzo Bianconi 		return -ENOBUFS;
1492bd9d6a3eSLorenzo Bianconi 
1493bd9d6a3eSLorenzo Bianconi 	if (nla_put_be32(skb, NFSD_A_RPC_STATUS_XID, rqstp->rq_xid) ||
1494bd9d6a3eSLorenzo Bianconi 	    nla_put_u32(skb, NFSD_A_RPC_STATUS_FLAGS, rqstp->rq_flags) ||
1495bd9d6a3eSLorenzo Bianconi 	    nla_put_u32(skb, NFSD_A_RPC_STATUS_PROG, rqstp->rq_prog) ||
1496bd9d6a3eSLorenzo Bianconi 	    nla_put_u32(skb, NFSD_A_RPC_STATUS_PROC, rqstp->rq_proc) ||
1497bd9d6a3eSLorenzo Bianconi 	    nla_put_u8(skb, NFSD_A_RPC_STATUS_VERSION, rqstp->rq_vers) ||
1498bd9d6a3eSLorenzo Bianconi 	    nla_put_s64(skb, NFSD_A_RPC_STATUS_SERVICE_TIME,
1499bd9d6a3eSLorenzo Bianconi 			ktime_to_us(rqstp->rq_stime),
1500bd9d6a3eSLorenzo Bianconi 			NFSD_A_RPC_STATUS_PAD))
1501bd9d6a3eSLorenzo Bianconi 		return -ENOBUFS;
1502bd9d6a3eSLorenzo Bianconi 
1503bd9d6a3eSLorenzo Bianconi 	switch (rqstp->rq_saddr.sa_family) {
1504bd9d6a3eSLorenzo Bianconi 	case AF_INET: {
1505bd9d6a3eSLorenzo Bianconi 		const struct sockaddr_in *s_in, *d_in;
1506bd9d6a3eSLorenzo Bianconi 
1507bd9d6a3eSLorenzo Bianconi 		s_in = (const struct sockaddr_in *)&rqstp->rq_saddr;
1508bd9d6a3eSLorenzo Bianconi 		d_in = (const struct sockaddr_in *)&rqstp->rq_daddr;
1509bd9d6a3eSLorenzo Bianconi 		if (nla_put_in_addr(skb, NFSD_A_RPC_STATUS_SADDR4,
1510bd9d6a3eSLorenzo Bianconi 				    s_in->sin_addr.s_addr) ||
1511bd9d6a3eSLorenzo Bianconi 		    nla_put_in_addr(skb, NFSD_A_RPC_STATUS_DADDR4,
1512bd9d6a3eSLorenzo Bianconi 				    d_in->sin_addr.s_addr) ||
1513bd9d6a3eSLorenzo Bianconi 		    nla_put_be16(skb, NFSD_A_RPC_STATUS_SPORT,
1514bd9d6a3eSLorenzo Bianconi 				 s_in->sin_port) ||
1515bd9d6a3eSLorenzo Bianconi 		    nla_put_be16(skb, NFSD_A_RPC_STATUS_DPORT,
1516bd9d6a3eSLorenzo Bianconi 				 d_in->sin_port))
1517bd9d6a3eSLorenzo Bianconi 			return -ENOBUFS;
1518bd9d6a3eSLorenzo Bianconi 		break;
1519bd9d6a3eSLorenzo Bianconi 	}
1520bd9d6a3eSLorenzo Bianconi 	case AF_INET6: {
1521bd9d6a3eSLorenzo Bianconi 		const struct sockaddr_in6 *s_in, *d_in;
1522bd9d6a3eSLorenzo Bianconi 
1523bd9d6a3eSLorenzo Bianconi 		s_in = (const struct sockaddr_in6 *)&rqstp->rq_saddr;
1524bd9d6a3eSLorenzo Bianconi 		d_in = (const struct sockaddr_in6 *)&rqstp->rq_daddr;
1525bd9d6a3eSLorenzo Bianconi 		if (nla_put_in6_addr(skb, NFSD_A_RPC_STATUS_SADDR6,
1526bd9d6a3eSLorenzo Bianconi 				     &s_in->sin6_addr) ||
1527bd9d6a3eSLorenzo Bianconi 		    nla_put_in6_addr(skb, NFSD_A_RPC_STATUS_DADDR6,
1528bd9d6a3eSLorenzo Bianconi 				     &d_in->sin6_addr) ||
1529bd9d6a3eSLorenzo Bianconi 		    nla_put_be16(skb, NFSD_A_RPC_STATUS_SPORT,
1530bd9d6a3eSLorenzo Bianconi 				 s_in->sin6_port) ||
1531bd9d6a3eSLorenzo Bianconi 		    nla_put_be16(skb, NFSD_A_RPC_STATUS_DPORT,
1532bd9d6a3eSLorenzo Bianconi 				 d_in->sin6_port))
1533bd9d6a3eSLorenzo Bianconi 			return -ENOBUFS;
1534bd9d6a3eSLorenzo Bianconi 		break;
1535bd9d6a3eSLorenzo Bianconi 	}
1536bd9d6a3eSLorenzo Bianconi 	}
1537bd9d6a3eSLorenzo Bianconi 
1538bd9d6a3eSLorenzo Bianconi 	for (i = 0; i < rqstp->rq_opcnt; i++)
1539bd9d6a3eSLorenzo Bianconi 		if (nla_put_u32(skb, NFSD_A_RPC_STATUS_COMPOUND_OPS,
1540bd9d6a3eSLorenzo Bianconi 				rqstp->rq_opnum[i]))
1541bd9d6a3eSLorenzo Bianconi 			return -ENOBUFS;
1542bd9d6a3eSLorenzo Bianconi 
1543bd9d6a3eSLorenzo Bianconi 	genlmsg_end(skb, hdr);
154413727f85SLorenzo Bianconi 	return 0;
154513727f85SLorenzo Bianconi }
154613727f85SLorenzo Bianconi 
1547bd9d6a3eSLorenzo Bianconi /**
1548bd9d6a3eSLorenzo Bianconi  * nfsd_nl_rpc_status_get_dumpit - Handle rpc_status_get dumpit
1549bd9d6a3eSLorenzo Bianconi  * @skb: reply buffer
1550bd9d6a3eSLorenzo Bianconi  * @cb: netlink metadata and command arguments
1551bd9d6a3eSLorenzo Bianconi  *
1552bd9d6a3eSLorenzo Bianconi  * Returns the size of the reply or a negative errno.
1553bd9d6a3eSLorenzo Bianconi  */
155413727f85SLorenzo Bianconi int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb,
155513727f85SLorenzo Bianconi 				  struct netlink_callback *cb)
155613727f85SLorenzo Bianconi {
1557bd9d6a3eSLorenzo Bianconi 	struct nfsd_net *nn = net_generic(sock_net(skb->sk), nfsd_net_id);
1558bd9d6a3eSLorenzo Bianconi 	int i, ret, rqstp_index = 0;
1559bd9d6a3eSLorenzo Bianconi 
1560bd9d6a3eSLorenzo Bianconi 	rcu_read_lock();
1561bd9d6a3eSLorenzo Bianconi 
1562bd9d6a3eSLorenzo Bianconi 	for (i = 0; i < nn->nfsd_serv->sv_nrpools; i++) {
1563bd9d6a3eSLorenzo Bianconi 		struct svc_rqst *rqstp;
1564bd9d6a3eSLorenzo Bianconi 
1565bd9d6a3eSLorenzo Bianconi 		if (i < cb->args[0]) /* already consumed */
1566bd9d6a3eSLorenzo Bianconi 			continue;
1567bd9d6a3eSLorenzo Bianconi 
1568bd9d6a3eSLorenzo Bianconi 		rqstp_index = 0;
1569bd9d6a3eSLorenzo Bianconi 		list_for_each_entry_rcu(rqstp,
1570bd9d6a3eSLorenzo Bianconi 				&nn->nfsd_serv->sv_pools[i].sp_all_threads,
1571bd9d6a3eSLorenzo Bianconi 				rq_all) {
1572bd9d6a3eSLorenzo Bianconi 			struct nfsd_genl_rqstp genl_rqstp;
1573bd9d6a3eSLorenzo Bianconi 			unsigned int status_counter;
1574bd9d6a3eSLorenzo Bianconi 
1575bd9d6a3eSLorenzo Bianconi 			if (rqstp_index++ < cb->args[1]) /* already consumed */
1576bd9d6a3eSLorenzo Bianconi 				continue;
1577bd9d6a3eSLorenzo Bianconi 			/*
1578bd9d6a3eSLorenzo Bianconi 			 * Acquire rq_status_counter before parsing the rqst
1579bd9d6a3eSLorenzo Bianconi 			 * fields. rq_status_counter is set to an odd value in
1580bd9d6a3eSLorenzo Bianconi 			 * order to notify the consumers the rqstp fields are
1581bd9d6a3eSLorenzo Bianconi 			 * meaningful.
1582bd9d6a3eSLorenzo Bianconi 			 */
1583bd9d6a3eSLorenzo Bianconi 			status_counter =
1584bd9d6a3eSLorenzo Bianconi 				smp_load_acquire(&rqstp->rq_status_counter);
1585bd9d6a3eSLorenzo Bianconi 			if (!(status_counter & 1))
1586bd9d6a3eSLorenzo Bianconi 				continue;
1587bd9d6a3eSLorenzo Bianconi 
1588bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_xid = rqstp->rq_xid;
1589bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_flags = rqstp->rq_flags;
1590bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_vers = rqstp->rq_vers;
1591bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_prog = rqstp->rq_prog;
1592bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_proc = rqstp->rq_proc;
1593bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_stime = rqstp->rq_stime;
1594bd9d6a3eSLorenzo Bianconi 			genl_rqstp.rq_opcnt = 0;
1595bd9d6a3eSLorenzo Bianconi 			memcpy(&genl_rqstp.rq_daddr, svc_daddr(rqstp),
1596bd9d6a3eSLorenzo Bianconi 			       sizeof(struct sockaddr));
1597bd9d6a3eSLorenzo Bianconi 			memcpy(&genl_rqstp.rq_saddr, svc_addr(rqstp),
1598bd9d6a3eSLorenzo Bianconi 			       sizeof(struct sockaddr));
1599bd9d6a3eSLorenzo Bianconi 
1600bd9d6a3eSLorenzo Bianconi #ifdef CONFIG_NFSD_V4
1601bd9d6a3eSLorenzo Bianconi 			if (rqstp->rq_vers == NFS4_VERSION &&
1602bd9d6a3eSLorenzo Bianconi 			    rqstp->rq_proc == NFSPROC4_COMPOUND) {
1603bd9d6a3eSLorenzo Bianconi 				/* NFSv4 compound */
1604bd9d6a3eSLorenzo Bianconi 				struct nfsd4_compoundargs *args;
1605bd9d6a3eSLorenzo Bianconi 				int j;
1606bd9d6a3eSLorenzo Bianconi 
1607bd9d6a3eSLorenzo Bianconi 				args = rqstp->rq_argp;
1608bd9d6a3eSLorenzo Bianconi 				genl_rqstp.rq_opcnt = args->opcnt;
1609bd9d6a3eSLorenzo Bianconi 				for (j = 0; j < genl_rqstp.rq_opcnt; j++)
1610bd9d6a3eSLorenzo Bianconi 					genl_rqstp.rq_opnum[j] =
1611bd9d6a3eSLorenzo Bianconi 						args->ops[j].opnum;
1612bd9d6a3eSLorenzo Bianconi 			}
1613bd9d6a3eSLorenzo Bianconi #endif /* CONFIG_NFSD_V4 */
1614bd9d6a3eSLorenzo Bianconi 
1615bd9d6a3eSLorenzo Bianconi 			/*
1616bd9d6a3eSLorenzo Bianconi 			 * Acquire rq_status_counter before reporting the rqst
1617bd9d6a3eSLorenzo Bianconi 			 * fields to the user.
1618bd9d6a3eSLorenzo Bianconi 			 */
1619bd9d6a3eSLorenzo Bianconi 			if (smp_load_acquire(&rqstp->rq_status_counter) !=
1620bd9d6a3eSLorenzo Bianconi 			    status_counter)
1621bd9d6a3eSLorenzo Bianconi 				continue;
1622bd9d6a3eSLorenzo Bianconi 
1623bd9d6a3eSLorenzo Bianconi 			ret = nfsd_genl_rpc_status_compose_msg(skb, cb,
1624bd9d6a3eSLorenzo Bianconi 							       &genl_rqstp);
1625bd9d6a3eSLorenzo Bianconi 			if (ret)
1626bd9d6a3eSLorenzo Bianconi 				goto out;
1627bd9d6a3eSLorenzo Bianconi 		}
162813727f85SLorenzo Bianconi 	}
162913727f85SLorenzo Bianconi 
1630bd9d6a3eSLorenzo Bianconi 	cb->args[0] = i;
1631bd9d6a3eSLorenzo Bianconi 	cb->args[1] = rqstp_index;
1632bd9d6a3eSLorenzo Bianconi 	ret = skb->len;
1633bd9d6a3eSLorenzo Bianconi out:
1634bd9d6a3eSLorenzo Bianconi 	rcu_read_unlock();
1635bd9d6a3eSLorenzo Bianconi 
1636bd9d6a3eSLorenzo Bianconi 	return ret;
1637bd9d6a3eSLorenzo Bianconi }
1638bd9d6a3eSLorenzo Bianconi 
1639bd9d6a3eSLorenzo Bianconi /**
1640bd9d6a3eSLorenzo Bianconi  * nfsd_nl_rpc_status_get_done - rpc_status_get dumpit post-processing
1641bd9d6a3eSLorenzo Bianconi  * @cb: netlink metadata and command arguments
1642bd9d6a3eSLorenzo Bianconi  *
1643bd9d6a3eSLorenzo Bianconi  * Return values:
1644bd9d6a3eSLorenzo Bianconi  *   %0: Success
1645bd9d6a3eSLorenzo Bianconi  */
164613727f85SLorenzo Bianconi int nfsd_nl_rpc_status_get_done(struct netlink_callback *cb)
164713727f85SLorenzo Bianconi {
1648bd9d6a3eSLorenzo Bianconi 	mutex_unlock(&nfsd_mutex);
1649bd9d6a3eSLorenzo Bianconi 
165013727f85SLorenzo Bianconi 	return 0;
165113727f85SLorenzo Bianconi }
165213727f85SLorenzo Bianconi 
16535e092be7SChuck Lever /**
16545e092be7SChuck Lever  * nfsd_net_init - Prepare the nfsd_net portion of a new net namespace
16555e092be7SChuck Lever  * @net: a freshly-created network namespace
16565e092be7SChuck Lever  *
16575e092be7SChuck Lever  * This information stays around as long as the network namespace is
16585e092be7SChuck Lever  * alive whether or not there is an NFSD instance running in the
16595e092be7SChuck Lever  * namespace.
16605e092be7SChuck Lever  *
16615e092be7SChuck Lever  * Returns zero on success, or a negative errno otherwise.
16625e092be7SChuck Lever  */
16635e092be7SChuck Lever static __net_init int nfsd_net_init(struct net *net)
16645717e012SStanislav Kinsbursky {
16655717e012SStanislav Kinsbursky 	int retval;
16663d733711SStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
16675717e012SStanislav Kinsbursky 
16685717e012SStanislav Kinsbursky 	retval = nfsd_export_init(net);
16695717e012SStanislav Kinsbursky 	if (retval)
16705717e012SStanislav Kinsbursky 		goto out_export_error;
1671f69adb2fSStanislav Kinsbursky 	retval = nfsd_idmap_init(net);
1672f69adb2fSStanislav Kinsbursky 	if (retval)
1673f69adb2fSStanislav Kinsbursky 		goto out_idmap_error;
1674ed9ab734SJeff Layton 	retval = nfsd_net_reply_cache_init(nn);
1675ed9ab734SJeff Layton 	if (retval)
1676ed9ab734SJeff Layton 		goto out_repcache_error;
1677e333f3bbSTrond Myklebust 	nn->nfsd_versions = NULL;
1678e333f3bbSTrond Myklebust 	nn->nfsd4_minorversions = NULL;
1679f385f7d2SDai Ngo 	nfsd4_init_leases_net(nn);
168091d2e9b5SChuck Lever 	get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
168191d2e9b5SChuck Lever 	seqlock_init(&nn->writeverf_lock);
1682*93483ac5SJosef Bacik 	nfsd_proc_stat_init(net);
16832c830dd7SJ. Bruce Fields 
16845717e012SStanislav Kinsbursky 	return 0;
16855717e012SStanislav Kinsbursky 
1686ed9ab734SJeff Layton out_repcache_error:
1687ed9ab734SJeff Layton 	nfsd_idmap_shutdown(net);
1688f69adb2fSStanislav Kinsbursky out_idmap_error:
1689f69adb2fSStanislav Kinsbursky 	nfsd_export_shutdown(net);
16905717e012SStanislav Kinsbursky out_export_error:
16915717e012SStanislav Kinsbursky 	return retval;
16925717e012SStanislav Kinsbursky }
16935717e012SStanislav Kinsbursky 
16945e092be7SChuck Lever /**
16955e092be7SChuck Lever  * nfsd_net_exit - Release the nfsd_net portion of a net namespace
16965e092be7SChuck Lever  * @net: a network namespace that is about to be destroyed
16975e092be7SChuck Lever  *
16985e092be7SChuck Lever  */
16995e092be7SChuck Lever static __net_exit void nfsd_net_exit(struct net *net)
17005717e012SStanislav Kinsbursky {
1701ed9ab734SJeff Layton 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1702ed9ab734SJeff Layton 
1703*93483ac5SJosef Bacik 	nfsd_proc_stat_shutdown(net);
1704ed9ab734SJeff Layton 	nfsd_net_reply_cache_destroy(nn);
1705f69adb2fSStanislav Kinsbursky 	nfsd_idmap_shutdown(net);
17065717e012SStanislav Kinsbursky 	nfsd_export_shutdown(net);
1707ed9ab734SJeff Layton 	nfsd_netns_free_versions(nn);
17085717e012SStanislav Kinsbursky }
17095717e012SStanislav Kinsbursky 
17107ea34ac1SJeff Layton static struct pernet_operations nfsd_net_ops = {
17115e092be7SChuck Lever 	.init = nfsd_net_init,
17125e092be7SChuck Lever 	.exit = nfsd_net_exit,
17137ea34ac1SJeff Layton 	.id   = &nfsd_net_id,
17147ea34ac1SJeff Layton 	.size = sizeof(struct nfsd_net),
17157ea34ac1SJeff Layton };
17167ea34ac1SJeff Layton 
17171da177e4SLinus Torvalds static int __init init_nfsd(void)
17181da177e4SLinus Torvalds {
17191da177e4SLinus Torvalds 	int retval;
17201da177e4SLinus Torvalds 
1721bb7ffbf2SGiuseppe Cantavenera 	retval = nfsd4_init_slabs();
1722bb7ffbf2SGiuseppe Cantavenera 	if (retval)
1723b10252c7SAlexander Sverdlin 		return retval;
17249cf514ccSChristoph Hellwig 	retval = nfsd4_init_pnfs();
172565178db4SBryan Schumaker 	if (retval)
172665178db4SBryan Schumaker 		goto out_free_slabs;
1727*93483ac5SJosef Bacik 	retval = nfsd_stat_counters_init();	/* Statistics */
1728e567b98cSAmir Goldstein 	if (retval)
1729e567b98cSAmir Goldstein 		goto out_free_pnfs;
1730027690c7SJ. Bruce Fields 	retval = nfsd_drc_slab_create();
1731027690c7SJ. Bruce Fields 	if (retval)
1732027690c7SJ. Bruce Fields 		goto out_free_stat;
17331da177e4SLinus Torvalds 	nfsd_lockd_init();	/* lockd->nfsd callbacks */
1734e331f606SJ. Bruce Fields 	retval = create_proc_exports_entry();
1735e331f606SJ. Bruce Fields 	if (retval)
1736f69adb2fSStanislav Kinsbursky 		goto out_free_lockd;
1737bd5ae928SJ. Bruce Fields 	retval = register_pernet_subsys(&nfsd_net_ops);
1738bd5ae928SJ. Bruce Fields 	if (retval < 0)
17396f6f84aaSZhang Xiaoxu 		goto out_free_exports;
1740b10252c7SAlexander Sverdlin 	retval = register_cld_notifier();
1741b10252c7SAlexander Sverdlin 	if (retval)
174262fdb65eSZhang Xiaoxu 		goto out_free_subsys;
1743d76cc46bSDai Ngo 	retval = nfsd4_create_laundry_wq();
1744d76cc46bSDai Ngo 	if (retval)
17456f6f84aaSZhang Xiaoxu 		goto out_free_cld;
17466f6f84aaSZhang Xiaoxu 	retval = register_filesystem(&nfsd_fs_type);
17476f6f84aaSZhang Xiaoxu 	if (retval)
1748d76cc46bSDai Ngo 		goto out_free_all;
1749bd9d6a3eSLorenzo Bianconi 	retval = genl_register_family(&nfsd_nl_family);
1750bd9d6a3eSLorenzo Bianconi 	if (retval)
1751bd9d6a3eSLorenzo Bianconi 		goto out_free_all;
1752bd9d6a3eSLorenzo Bianconi 
175326808d3fSJ. Bruce Fields 	return 0;
175426808d3fSJ. Bruce Fields out_free_all:
17556f6f84aaSZhang Xiaoxu 	nfsd4_destroy_laundry_wq();
17566f6f84aaSZhang Xiaoxu out_free_cld:
175762fdb65eSZhang Xiaoxu 	unregister_cld_notifier();
175862fdb65eSZhang Xiaoxu out_free_subsys:
1759b10252c7SAlexander Sverdlin 	unregister_pernet_subsys(&nfsd_net_ops);
1760bd5ae928SJ. Bruce Fields out_free_exports:
17611da177e4SLinus Torvalds 	remove_proc_entry("fs/nfs/exports", NULL);
17621da177e4SLinus Torvalds 	remove_proc_entry("fs/nfs", NULL);
1763dbf847ecSJ. Bruce Fields out_free_lockd:
17641da177e4SLinus Torvalds 	nfsd_lockd_shutdown();
1765027690c7SJ. Bruce Fields 	nfsd_drc_slab_free();
1766027690c7SJ. Bruce Fields out_free_stat:
1767*93483ac5SJosef Bacik 	nfsd_stat_counters_destroy();
1768e567b98cSAmir Goldstein out_free_pnfs:
17699cf514ccSChristoph Hellwig 	nfsd4_exit_pnfs();
177065178db4SBryan Schumaker out_free_slabs:
177146b25895SJ. Bruce Fields 	nfsd4_free_slabs();
17721da177e4SLinus Torvalds 	return retval;
17731da177e4SLinus Torvalds }
17741da177e4SLinus Torvalds 
17751da177e4SLinus Torvalds static void __exit exit_nfsd(void)
17761da177e4SLinus Torvalds {
1777bd9d6a3eSLorenzo Bianconi 	genl_unregister_family(&nfsd_nl_family);
17786f6f84aaSZhang Xiaoxu 	unregister_filesystem(&nfsd_fs_type);
1779d76cc46bSDai Ngo 	nfsd4_destroy_laundry_wq();
1780b10252c7SAlexander Sverdlin 	unregister_cld_notifier();
1781bd5ae928SJ. Bruce Fields 	unregister_pernet_subsys(&nfsd_net_ops);
1782027690c7SJ. Bruce Fields 	nfsd_drc_slab_free();
17831da177e4SLinus Torvalds 	remove_proc_entry("fs/nfs/exports", NULL);
17841da177e4SLinus Torvalds 	remove_proc_entry("fs/nfs", NULL);
1785*93483ac5SJosef Bacik 	nfsd_stat_counters_destroy();
17861da177e4SLinus Torvalds 	nfsd_lockd_shutdown();
1787e8ff2a84SJ. Bruce Fields 	nfsd4_free_slabs();
17889cf514ccSChristoph Hellwig 	nfsd4_exit_pnfs();
17891da177e4SLinus Torvalds }
17901da177e4SLinus Torvalds 
17911da177e4SLinus Torvalds MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
17925865bafaSJeff Layton MODULE_DESCRIPTION("In-kernel NFS server");
17931da177e4SLinus Torvalds MODULE_LICENSE("GPL");
17941da177e4SLinus Torvalds module_init(init_nfsd)
17951da177e4SLinus Torvalds module_exit(exit_nfsd)
1796