blob: 33b3e2b06779da530630fbb43800b3587c2728d9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Syscall interface to knfsd.
3 *
4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
5 */
6
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Al Viro3f8206d2008-07-26 03:46:43 -04008#include <linux/namei.h>
NeilBrownb41b66d2006-10-02 02:17:48 -07009#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
NeilBrown80212d52006-10-02 02:17:47 -070011#include <linux/sunrpc/svcsock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/nfsd/syscall.h>
Wendy Cheng4373ea82008-01-17 11:10:12 -050013#include <linux/lockd/lockd.h>
Chuck Lever41160922009-08-09 15:09:40 -040014#include <linux/sunrpc/clnt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
J. Bruce Fields2ca72e12011-01-04 17:37:15 -050016#include "idmap.h"
Boaz Harrosh9a74af22009-12-03 20:30:56 +020017#include "nfsd.h"
18#include "cache.h"
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21 * We have a single directory with 9 nodes in it.
22 */
23enum {
24 NFSD_Root = 1,
NeilBrown1e140562010-09-22 12:55:07 +100025#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 NFSD_Svc,
27 NFSD_Add,
28 NFSD_Del,
29 NFSD_Export,
30 NFSD_Unexport,
31 NFSD_Getfd,
32 NFSD_Getfs,
NeilBrown1e140562010-09-22 12:55:07 +100033#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 NFSD_List,
J. Bruce Fieldse8e87532009-12-14 12:53:32 -050035 NFSD_Export_features,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 NFSD_Fh,
Wendy Cheng4373ea82008-01-17 11:10:12 -050037 NFSD_FO_UnlockIP,
Wendy Cheng17efa372008-01-17 11:10:12 -050038 NFSD_FO_UnlockFS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 NFSD_Threads,
Greg Bankseed29652006-10-02 02:18:02 -070040 NFSD_Pool_Threads,
Greg Banks03cf6c92009-01-13 21:26:36 +110041 NFSD_Pool_Stats,
NeilBrown70c3b762005-11-07 01:00:25 -080042 NFSD_Versions,
NeilBrown80212d52006-10-02 02:17:47 -070043 NFSD_Ports,
NeilBrown596bbe52006-10-04 02:15:48 -070044 NFSD_MaxBlkSize,
NeilBrown70c3b762005-11-07 01:00:25 -080045 /*
46 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
47 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
48 */
49#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 NFSD_Leasetime,
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -050051 NFSD_Gracetime,
NeilBrown0964a3d2005-06-23 22:04:32 -070052 NFSD_RecoveryDir,
NeilBrown70c3b762005-11-07 01:00:25 -080053#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
56/*
57 * write() for these nodes.
58 */
NeilBrown1e140562010-09-22 12:55:07 +100059#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static ssize_t write_svc(struct file *file, char *buf, size_t size);
61static ssize_t write_add(struct file *file, char *buf, size_t size);
62static ssize_t write_del(struct file *file, char *buf, size_t size);
63static ssize_t write_export(struct file *file, char *buf, size_t size);
64static ssize_t write_unexport(struct file *file, char *buf, size_t size);
65static ssize_t write_getfd(struct file *file, char *buf, size_t size);
66static ssize_t write_getfs(struct file *file, char *buf, size_t size);
NeilBrown1e140562010-09-22 12:55:07 +100067#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
Chuck Leverb046ccd2008-12-12 16:57:13 -050069static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
70static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static ssize_t write_threads(struct file *file, char *buf, size_t size);
Greg Bankseed29652006-10-02 02:18:02 -070072static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080073static ssize_t write_versions(struct file *file, char *buf, size_t size);
NeilBrown80212d52006-10-02 02:17:47 -070074static ssize_t write_ports(struct file *file, char *buf, size_t size);
NeilBrown596bbe52006-10-04 02:15:48 -070075static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080076#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -050078static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
NeilBrown0964a3d2005-06-23 22:04:32 -070079static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080080#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82static ssize_t (*write_op[])(struct file *, char *, size_t) = {
NeilBrown1e140562010-09-22 12:55:07 +100083#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 [NFSD_Svc] = write_svc,
85 [NFSD_Add] = write_add,
86 [NFSD_Del] = write_del,
87 [NFSD_Export] = write_export,
88 [NFSD_Unexport] = write_unexport,
89 [NFSD_Getfd] = write_getfd,
90 [NFSD_Getfs] = write_getfs,
NeilBrown1e140562010-09-22 12:55:07 +100091#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 [NFSD_Fh] = write_filehandle,
Chuck Leverb046ccd2008-12-12 16:57:13 -050093 [NFSD_FO_UnlockIP] = write_unlock_ip,
94 [NFSD_FO_UnlockFS] = write_unlock_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 [NFSD_Threads] = write_threads,
Greg Bankseed29652006-10-02 02:18:02 -070096 [NFSD_Pool_Threads] = write_pool_threads,
NeilBrown70c3b762005-11-07 01:00:25 -080097 [NFSD_Versions] = write_versions,
NeilBrown80212d52006-10-02 02:17:47 -070098 [NFSD_Ports] = write_ports,
NeilBrown596bbe52006-10-04 02:15:48 -070099 [NFSD_MaxBlkSize] = write_maxblksize,
NeilBrown70c3b762005-11-07 01:00:25 -0800100#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 [NFSD_Leasetime] = write_leasetime,
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -0500102 [NFSD_Gracetime] = write_gracetime,
NeilBrown0964a3d2005-06-23 22:04:32 -0700103 [NFSD_RecoveryDir] = write_recoverydir,
NeilBrown70c3b762005-11-07 01:00:25 -0800104#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
107static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
108{
Josef "Jeff" Sipek7eaa36e2006-12-08 02:36:41 -0800109 ino_t ino = file->f_path.dentry->d_inode->i_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 char *data;
111 ssize_t rv;
112
Tobias Klausere8c96f82006-03-24 03:15:34 -0800113 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return -EINVAL;
115
116 data = simple_transaction_get(file, buf, size);
117 if (IS_ERR(data))
118 return PTR_ERR(data);
119
120 rv = write_op[ino](file, data, size);
NeilBrown8971a102007-02-14 00:33:11 -0800121 if (rv >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 simple_transaction_set(file, rv);
123 rv = size;
124 }
125 return rv;
126}
127
NeilBrown73900222005-11-07 01:00:24 -0800128static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
129{
bookjovi@gmail.com5b6a5992010-12-11 00:21:17 -0500130#ifdef CONFIG_NFSD_DEPRECATED
NeilBrownc67874f2010-09-22 12:55:07 +1000131 static int warned;
132 if (file->f_dentry->d_name.name[0] == '.' && !warned) {
NeilBrownc67874f2010-09-22 12:55:07 +1000133 printk(KERN_INFO
134 "Warning: \"%s\" uses deprecated NFSD interface: %s."
135 " This will be removed in 2.6.40\n",
Pavel Emelyanov049ef272010-09-23 18:26:58 +0400136 current->comm, file->f_dentry->d_name.name);
NeilBrownc67874f2010-09-22 12:55:07 +1000137 warned = 1;
138 }
bookjovi@gmail.com5b6a5992010-12-11 00:21:17 -0500139#endif
NeilBrown73900222005-11-07 01:00:24 -0800140 if (! file->private_data) {
141 /* An attempt to read a transaction file without writing
142 * causes a 0-byte write so that the file can return
143 * state information
144 */
145 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
146 if (rv < 0)
147 return rv;
148 }
149 return simple_transaction_read(file, buf, size, pos);
150}
151
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800152static const struct file_operations transaction_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 .write = nfsctl_transaction_write,
NeilBrown73900222005-11-07 01:00:24 -0800154 .read = nfsctl_transaction_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 .release = simple_transaction_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200156 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157};
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static int exports_open(struct inode *inode, struct file *file)
160{
161 return seq_open(file, &nfs_exports_op);
162}
163
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800164static const struct file_operations exports_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 .open = exports_open,
166 .read = seq_read,
167 .llseek = seq_lseek,
168 .release = seq_release,
Denis V. Lunev9ef2db22008-04-29 01:02:04 -0700169 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170};
171
J. Bruce Fieldse8e87532009-12-14 12:53:32 -0500172static int export_features_show(struct seq_file *m, void *v)
173{
174 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
175 return 0;
176}
177
178static int export_features_open(struct inode *inode, struct file *file)
179{
180 return single_open(file, export_features_show, NULL);
181}
182
183static struct file_operations export_features_operations = {
184 .open = export_features_open,
185 .read = seq_read,
186 .llseek = seq_lseek,
187 .release = single_release,
188};
189
Greg Banks03cf6c92009-01-13 21:26:36 +1100190extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
Ryusei Yamaguchied2d8ae2009-08-16 00:54:41 +0900191extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
Greg Banks03cf6c92009-01-13 21:26:36 +1100192
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700193static const struct file_operations pool_stats_operations = {
Greg Banks03cf6c92009-01-13 21:26:36 +1100194 .open = nfsd_pool_stats_open,
195 .read = seq_read,
196 .llseek = seq_lseek,
Ryusei Yamaguchied2d8ae2009-08-16 00:54:41 +0900197 .release = nfsd_pool_stats_release,
Greg Banks03cf6c92009-01-13 21:26:36 +1100198 .owner = THIS_MODULE,
199};
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*----------------------------------------------------------------------------*/
202/*
203 * payload - write methods
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 */
205
NeilBrown1e140562010-09-22 12:55:07 +1000206#ifdef CONFIG_NFSD_DEPRECATED
Chuck Lever262a0982008-12-12 16:57:35 -0500207/**
208 * write_svc - Start kernel's NFSD server
209 *
210 * Deprecated. /proc/fs/nfsd/threads is preferred.
211 * Function remains to support old versions of nfs-utils.
212 *
213 * Input:
214 * buf: struct nfsctl_svc
215 * svc_port: port number of this
216 * server's listener
217 * svc_nthreads: number of threads to start
218 * size: size in bytes of passed in nfsctl_svc
219 * Output:
220 * On success: returns zero
221 * On error: return code is negative errno value
222 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static ssize_t write_svc(struct file *file, char *buf, size_t size)
224{
225 struct nfsctl_svc *data;
NeilBrown82e12fe2009-06-16 11:03:07 +1000226 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (size < sizeof(*data))
228 return -EINVAL;
229 data = (struct nfsctl_svc*) buf;
NeilBrown82e12fe2009-06-16 11:03:07 +1000230 err = nfsd_svc(data->svc_port, data->svc_nthreads);
231 if (err < 0)
232 return err;
233 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
Chuck Lever262a0982008-12-12 16:57:35 -0500236/**
237 * write_add - Add or modify client entry in auth unix cache
238 *
239 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
240 * Function remains to support old versions of nfs-utils.
241 *
242 * Input:
243 * buf: struct nfsctl_client
244 * cl_ident: '\0'-terminated C string
245 * containing domain name
246 * of client
247 * cl_naddr: no. of items in cl_addrlist
248 * cl_addrlist: array of client addresses
249 * cl_fhkeytype: ignored
250 * cl_fhkeylen: ignored
251 * cl_fhkey: ignored
252 * size: size in bytes of passed in nfsctl_client
253 * Output:
254 * On success: returns zero
255 * On error: return code is negative errno value
256 *
257 * Note: Only AF_INET client addresses are passed in, since
258 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
259 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static ssize_t write_add(struct file *file, char *buf, size_t size)
261{
262 struct nfsctl_client *data;
263 if (size < sizeof(*data))
264 return -EINVAL;
265 data = (struct nfsctl_client *)buf;
266 return exp_addclient(data);
267}
268
Chuck Lever262a0982008-12-12 16:57:35 -0500269/**
270 * write_del - Remove client from auth unix cache
271 *
272 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
273 * Function remains to support old versions of nfs-utils.
274 *
275 * Input:
276 * buf: struct nfsctl_client
277 * cl_ident: '\0'-terminated C string
278 * containing domain name
279 * of client
280 * cl_naddr: ignored
281 * cl_addrlist: ignored
282 * cl_fhkeytype: ignored
283 * cl_fhkeylen: ignored
284 * cl_fhkey: ignored
285 * size: size in bytes of passed in nfsctl_client
286 * Output:
287 * On success: returns zero
288 * On error: return code is negative errno value
289 *
290 * Note: Only AF_INET client addresses are passed in, since
291 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
292 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293static ssize_t write_del(struct file *file, char *buf, size_t size)
294{
295 struct nfsctl_client *data;
296 if (size < sizeof(*data))
297 return -EINVAL;
298 data = (struct nfsctl_client *)buf;
299 return exp_delclient(data);
300}
301
Chuck Lever262a0982008-12-12 16:57:35 -0500302/**
303 * write_export - Export part or all of a local file system
304 *
305 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
306 * Function remains to support old versions of nfs-utils.
307 *
308 * Input:
309 * buf: struct nfsctl_export
310 * ex_client: '\0'-terminated C string
311 * containing domain name
312 * of client allowed to access
313 * this export
314 * ex_path: '\0'-terminated C string
315 * containing pathname of
316 * directory in local file system
317 * ex_dev: fsid to use for this export
318 * ex_ino: ignored
319 * ex_flags: export flags for this export
320 * ex_anon_uid: UID to use for anonymous
321 * requests
322 * ex_anon_gid: GID to use for anonymous
323 * requests
324 * size: size in bytes of passed in nfsctl_export
325 * Output:
326 * On success: returns zero
327 * On error: return code is negative errno value
328 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329static ssize_t write_export(struct file *file, char *buf, size_t size)
330{
331 struct nfsctl_export *data;
332 if (size < sizeof(*data))
333 return -EINVAL;
334 data = (struct nfsctl_export*)buf;
335 return exp_export(data);
336}
337
Chuck Lever262a0982008-12-12 16:57:35 -0500338/**
339 * write_unexport - Unexport a previously exported file system
340 *
341 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
342 * Function remains to support old versions of nfs-utils.
343 *
344 * Input:
345 * buf: struct nfsctl_export
346 * ex_client: '\0'-terminated C string
347 * containing domain name
348 * of client no longer allowed
349 * to access this export
350 * ex_path: '\0'-terminated C string
351 * containing pathname of
352 * directory in local file system
353 * ex_dev: ignored
354 * ex_ino: ignored
355 * ex_flags: ignored
356 * ex_anon_uid: ignored
357 * ex_anon_gid: ignored
358 * size: size in bytes of passed in nfsctl_export
359 * Output:
360 * On success: returns zero
361 * On error: return code is negative errno value
362 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363static ssize_t write_unexport(struct file *file, char *buf, size_t size)
364{
365 struct nfsctl_export *data;
366
367 if (size < sizeof(*data))
368 return -EINVAL;
369 data = (struct nfsctl_export*)buf;
370 return exp_unexport(data);
371}
372
Chuck Lever262a0982008-12-12 16:57:35 -0500373/**
374 * write_getfs - Get a variable-length NFS file handle by path
375 *
376 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
377 * Function remains to support old versions of nfs-utils.
378 *
379 * Input:
380 * buf: struct nfsctl_fsparm
381 * gd_addr: socket address of client
382 * gd_path: '\0'-terminated C string
383 * containing pathname of
384 * directory in local file system
385 * gd_maxlen: maximum size of returned file
386 * handle
387 * size: size in bytes of passed in nfsctl_fsparm
388 * Output:
389 * On success: passed-in buffer filled with a knfsd_fh structure
390 * (a variable-length raw NFS file handle);
391 * return code is the size in bytes of the file handle
392 * On error: return code is negative errno value
393 *
394 * Note: Only AF_INET client addresses are passed in, since gd_addr
395 * is the same size as a struct sockaddr_in.
396 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397static ssize_t write_getfs(struct file *file, char *buf, size_t size)
398{
399 struct nfsctl_fsparm *data;
400 struct sockaddr_in *sin;
401 struct auth_domain *clp;
402 int err = 0;
403 struct knfsd_fh *res;
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100404 struct in6_addr in6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 if (size < sizeof(*data))
407 return -EINVAL;
408 data = (struct nfsctl_fsparm*)buf;
409 err = -EPROTONOSUPPORT;
410 if (data->gd_addr.sa_family != AF_INET)
411 goto out;
412 sin = (struct sockaddr_in *)&data->gd_addr;
413 if (data->gd_maxlen > NFS3_FHSIZE)
414 data->gd_maxlen = NFS3_FHSIZE;
415
416 res = (struct knfsd_fh*)buf;
417
418 exp_readlock();
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100419
420 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
421
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400422 clp = auth_unix_lookup(&init_net, &in6);
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100423 if (!clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 err = -EPERM;
425 else {
426 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
427 auth_domain_put(clp);
428 }
429 exp_readunlock();
430 if (err == 0)
Andrew Morton12127492007-07-17 04:04:34 -0700431 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 out:
433 return err;
434}
435
Chuck Lever262a0982008-12-12 16:57:35 -0500436/**
437 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
438 *
439 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
440 * Function remains to support old versions of nfs-utils.
441 *
442 * Input:
443 * buf: struct nfsctl_fdparm
444 * gd_addr: socket address of client
445 * gd_path: '\0'-terminated C string
446 * containing pathname of
447 * directory in local file system
448 * gd_version: fdparm structure version
449 * size: size in bytes of passed in nfsctl_fdparm
450 * Output:
451 * On success: passed-in buffer filled with nfsctl_res
452 * (a fixed-length raw NFS file handle);
453 * return code is the size in bytes of the file handle
454 * On error: return code is negative errno value
455 *
456 * Note: Only AF_INET client addresses are passed in, since gd_addr
457 * is the same size as a struct sockaddr_in.
458 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459static ssize_t write_getfd(struct file *file, char *buf, size_t size)
460{
461 struct nfsctl_fdparm *data;
462 struct sockaddr_in *sin;
463 struct auth_domain *clp;
464 int err = 0;
465 struct knfsd_fh fh;
466 char *res;
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100467 struct in6_addr in6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 if (size < sizeof(*data))
470 return -EINVAL;
471 data = (struct nfsctl_fdparm*)buf;
472 err = -EPROTONOSUPPORT;
473 if (data->gd_addr.sa_family != AF_INET)
474 goto out;
475 err = -EINVAL;
476 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
477 goto out;
478
479 res = buf;
480 sin = (struct sockaddr_in *)&data->gd_addr;
481 exp_readlock();
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100482
483 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
484
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400485 clp = auth_unix_lookup(&init_net, &in6);
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100486 if (!clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 err = -EPERM;
488 else {
489 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
490 auth_domain_put(clp);
491 }
492 exp_readunlock();
493
494 if (err == 0) {
495 memset(res,0, NFS_FHSIZE);
496 memcpy(res, &fh.fh_base, fh.fh_size);
497 err = NFS_FHSIZE;
498 }
499 out:
500 return err;
501}
NeilBrown1e140562010-09-22 12:55:07 +1000502#endif /* CONFIG_NFSD_DEPRECATED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Chuck Lever262a0982008-12-12 16:57:35 -0500504/**
505 * write_unlock_ip - Release all locks used by a client
506 *
507 * Experimental.
508 *
509 * Input:
510 * buf: '\n'-terminated C string containing a
Chuck Lever41160922009-08-09 15:09:40 -0400511 * presentation format IP address
Chuck Lever262a0982008-12-12 16:57:35 -0500512 * size: length of C string in @buf
513 * Output:
514 * On success: returns zero if all specified locks were released;
515 * returns one if one or more locks were not released
516 * On error: return code is negative errno value
Chuck Lever262a0982008-12-12 16:57:35 -0500517 */
Chuck Leverb046ccd2008-12-12 16:57:13 -0500518static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
Wendy Cheng4373ea82008-01-17 11:10:12 -0500519{
Chuck Lever41160922009-08-09 15:09:40 -0400520 struct sockaddr_storage address;
521 struct sockaddr *sap = (struct sockaddr *)&address;
522 size_t salen = sizeof(address);
Chuck Lever367c8c72008-06-30 18:58:14 -0400523 char *fo_path;
Wendy Cheng4373ea82008-01-17 11:10:12 -0500524
525 /* sanity check */
526 if (size == 0)
527 return -EINVAL;
528
529 if (buf[size-1] != '\n')
530 return -EINVAL;
531
532 fo_path = buf;
533 if (qword_get(&buf, fo_path, size) < 0)
534 return -EINVAL;
535
Chuck Lever41160922009-08-09 15:09:40 -0400536 if (rpc_pton(fo_path, size, sap, salen) == 0)
Wendy Cheng4373ea82008-01-17 11:10:12 -0500537 return -EINVAL;
Wendy Cheng4373ea82008-01-17 11:10:12 -0500538
Chuck Lever41160922009-08-09 15:09:40 -0400539 return nlmsvc_unlock_all_by_ip(sap);
Wendy Cheng4373ea82008-01-17 11:10:12 -0500540}
541
Chuck Lever262a0982008-12-12 16:57:35 -0500542/**
543 * write_unlock_fs - Release all locks on a local file system
544 *
545 * Experimental.
546 *
547 * Input:
548 * buf: '\n'-terminated C string containing the
549 * absolute pathname of a local file system
550 * size: length of C string in @buf
551 * Output:
552 * On success: returns zero if all specified locks were released;
553 * returns one if one or more locks were not released
554 * On error: return code is negative errno value
555 */
Chuck Leverb046ccd2008-12-12 16:57:13 -0500556static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
Wendy Cheng17efa372008-01-17 11:10:12 -0500557{
Al Viroa63bb992008-08-02 01:03:36 -0400558 struct path path;
Wendy Cheng17efa372008-01-17 11:10:12 -0500559 char *fo_path;
560 int error;
561
562 /* sanity check */
563 if (size == 0)
564 return -EINVAL;
565
566 if (buf[size-1] != '\n')
567 return -EINVAL;
568
569 fo_path = buf;
570 if (qword_get(&buf, fo_path, size) < 0)
571 return -EINVAL;
572
Al Viroa63bb992008-08-02 01:03:36 -0400573 error = kern_path(fo_path, 0, &path);
Wendy Cheng17efa372008-01-17 11:10:12 -0500574 if (error)
575 return error;
576
Chuck Lever262a0982008-12-12 16:57:35 -0500577 /*
578 * XXX: Needs better sanity checking. Otherwise we could end up
579 * releasing locks on the wrong file system.
580 *
581 * For example:
582 * 1. Does the path refer to a directory?
583 * 2. Is that directory a mount point, or
584 * 3. Is that directory the root of an exported file system?
585 */
Al Viroa63bb992008-08-02 01:03:36 -0400586 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
Wendy Cheng17efa372008-01-17 11:10:12 -0500587
Al Viroa63bb992008-08-02 01:03:36 -0400588 path_put(&path);
Wendy Cheng17efa372008-01-17 11:10:12 -0500589 return error;
590}
591
Chuck Lever262a0982008-12-12 16:57:35 -0500592/**
593 * write_filehandle - Get a variable-length NFS file handle by path
594 *
595 * On input, the buffer contains a '\n'-terminated C string comprised of
596 * three alphanumeric words separated by whitespace. The string may
597 * contain escape sequences.
598 *
599 * Input:
600 * buf:
601 * domain: client domain name
602 * path: export pathname
603 * maxsize: numeric maximum size of
604 * @buf
605 * size: length of C string in @buf
606 * Output:
607 * On success: passed-in buffer filled with '\n'-terminated C
608 * string containing a ASCII hex text version
609 * of the NFS file handle;
610 * return code is the size in bytes of the string
611 * On error: return code is negative errno value
612 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
614{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 char *dname, *path;
Andrew Morton246d95b2007-08-09 00:53:50 -0700616 int uninitialized_var(maxsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 char *mesg = buf;
618 int len;
619 struct auth_domain *dom;
620 struct knfsd_fh fh;
621
J. Bruce Fields87d26ea2008-01-22 17:40:42 -0500622 if (size == 0)
623 return -EINVAL;
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (buf[size-1] != '\n')
626 return -EINVAL;
627 buf[size-1] = 0;
628
629 dname = mesg;
630 len = qword_get(&mesg, dname, size);
Chuck Lever54224f02008-12-12 16:57:20 -0500631 if (len <= 0)
632 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 path = dname+len+1;
635 len = qword_get(&mesg, path, size);
Chuck Lever54224f02008-12-12 16:57:20 -0500636 if (len <= 0)
637 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 len = get_int(&mesg, &maxsize);
640 if (len)
641 return len;
642
643 if (maxsize < NFS_FHSIZE)
644 return -EINVAL;
645 if (maxsize > NFS3_FHSIZE)
646 maxsize = NFS3_FHSIZE;
647
648 if (qword_get(&mesg, mesg, size)>0)
649 return -EINVAL;
650
651 /* we have all the words, they are in buf.. */
652 dom = unix_domain_find(dname);
653 if (!dom)
654 return -ENOMEM;
655
656 len = exp_rootfh(dom, path, &fh, maxsize);
657 auth_domain_put(dom);
658 if (len)
659 return len;
660
Chuck Lever54224f02008-12-12 16:57:20 -0500661 mesg = buf;
662 len = SIMPLE_TRANSACTION_LIMIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
664 mesg[-1] = '\n';
665 return mesg - buf;
666}
667
Chuck Lever262a0982008-12-12 16:57:35 -0500668/**
669 * write_threads - Start NFSD, or report the current number of running threads
670 *
671 * Input:
672 * buf: ignored
673 * size: zero
674 * Output:
675 * On success: passed-in buffer filled with '\n'-terminated C
676 * string numeric value representing the number of
677 * running NFSD threads;
678 * return code is the size in bytes of the string
679 * On error: return code is zero
680 *
681 * OR
682 *
683 * Input:
684 * buf: C string containing an unsigned
685 * integer value representing the
686 * number of NFSD threads to start
687 * size: non-zero length of C string in @buf
688 * Output:
689 * On success: NFS service is started;
690 * passed-in buffer filled with '\n'-terminated C
691 * string numeric value representing the number of
692 * running NFSD threads;
693 * return code is the size in bytes of the string
694 * On error: return code is zero or a negative errno value
695 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696static ssize_t write_threads(struct file *file, char *buf, size_t size)
697{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 char *mesg = buf;
699 int rv;
700 if (size > 0) {
701 int newthreads;
702 rv = get_int(&mesg, &newthreads);
703 if (rv)
704 return rv;
Chuck Lever9e074852008-12-12 16:57:27 -0500705 if (newthreads < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return -EINVAL;
Chuck Lever9e074852008-12-12 16:57:27 -0500707 rv = nfsd_svc(NFS_PORT, newthreads);
NeilBrown82e12fe2009-06-16 11:03:07 +1000708 if (rv < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 return rv;
NeilBrown82e12fe2009-06-16 11:03:07 +1000710 } else
711 rv = nfsd_nrthreads();
Chuck Levere06b6402009-04-23 19:33:25 -0400712
NeilBrown82e12fe2009-06-16 11:03:07 +1000713 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714}
715
Chuck Lever262a0982008-12-12 16:57:35 -0500716/**
717 * write_pool_threads - Set or report the current number of threads per pool
718 *
719 * Input:
720 * buf: ignored
721 * size: zero
722 *
723 * OR
724 *
725 * Input:
726 * buf: C string containing whitespace-
727 * separated unsigned integer values
728 * representing the number of NFSD
729 * threads to start in each pool
730 * size: non-zero length of C string in @buf
731 * Output:
732 * On success: passed-in buffer filled with '\n'-terminated C
733 * string containing integer values representing the
734 * number of NFSD threads in each pool;
735 * return code is the size in bytes of the string
736 * On error: return code is zero or a negative errno value
737 */
Greg Bankseed29652006-10-02 02:18:02 -0700738static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
739{
740 /* if size > 0, look for an array of number of threads per node
741 * and apply them then write out number of threads per node as reply
742 */
743 char *mesg = buf;
744 int i;
745 int rv;
746 int len;
Neil Brownbedbdd82008-06-10 08:40:35 -0400747 int npools;
Greg Bankseed29652006-10-02 02:18:02 -0700748 int *nthreads;
749
Neil Brownbedbdd82008-06-10 08:40:35 -0400750 mutex_lock(&nfsd_mutex);
751 npools = nfsd_nrpools();
Greg Bankseed29652006-10-02 02:18:02 -0700752 if (npools == 0) {
753 /*
754 * NFS is shut down. The admin can start it by
755 * writing to the threads file but NOT the pool_threads
756 * file, sorry. Report zero threads.
757 */
Neil Brownbedbdd82008-06-10 08:40:35 -0400758 mutex_unlock(&nfsd_mutex);
Greg Bankseed29652006-10-02 02:18:02 -0700759 strcpy(buf, "0\n");
760 return strlen(buf);
761 }
762
763 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
Neil Brownbedbdd82008-06-10 08:40:35 -0400764 rv = -ENOMEM;
Greg Bankseed29652006-10-02 02:18:02 -0700765 if (nthreads == NULL)
Neil Brownbedbdd82008-06-10 08:40:35 -0400766 goto out_free;
Greg Bankseed29652006-10-02 02:18:02 -0700767
768 if (size > 0) {
769 for (i = 0; i < npools; i++) {
770 rv = get_int(&mesg, &nthreads[i]);
771 if (rv == -ENOENT)
772 break; /* fewer numbers than pools */
773 if (rv)
774 goto out_free; /* syntax error */
775 rv = -EINVAL;
776 if (nthreads[i] < 0)
777 goto out_free;
778 }
779 rv = nfsd_set_nrthreads(i, nthreads);
780 if (rv)
781 goto out_free;
782 }
783
784 rv = nfsd_get_nrthreads(npools, nthreads);
785 if (rv)
786 goto out_free;
787
788 mesg = buf;
789 size = SIMPLE_TRANSACTION_LIMIT;
790 for (i = 0; i < npools && size > 0; i++) {
791 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
792 len = strlen(mesg);
793 size -= len;
794 mesg += len;
795 }
J. Bruce Fields413d63d7102009-07-28 11:37:25 -0400796 rv = mesg - buf;
Greg Bankseed29652006-10-02 02:18:02 -0700797out_free:
798 kfree(nthreads);
Neil Brownbedbdd82008-06-10 08:40:35 -0400799 mutex_unlock(&nfsd_mutex);
Greg Bankseed29652006-10-02 02:18:02 -0700800 return rv;
801}
802
Jeff Layton3dd98a32008-06-10 08:40:36 -0400803static ssize_t __write_versions(struct file *file, char *buf, size_t size)
NeilBrown70c3b762005-11-07 01:00:25 -0800804{
NeilBrown70c3b762005-11-07 01:00:25 -0800805 char *mesg = buf;
Benny Halevy8daf2202009-04-03 08:28:59 +0300806 char *vers, *minorp, sign;
Chuck Lever261758b2009-04-23 19:33:18 -0400807 int len, num, remaining;
Benny Halevy8daf2202009-04-03 08:28:59 +0300808 unsigned minor;
NeilBrown70c3b762005-11-07 01:00:25 -0800809 ssize_t tlen = 0;
810 char *sep;
811
812 if (size>0) {
813 if (nfsd_serv)
NeilBrown6658d3a2006-10-02 02:17:46 -0700814 /* Cannot change versions without updating
815 * nfsd_serv->sv_xdrsize, and reallocing
816 * rq_argp and rq_resp
817 */
NeilBrown70c3b762005-11-07 01:00:25 -0800818 return -EBUSY;
819 if (buf[size-1] != '\n')
820 return -EINVAL;
821 buf[size-1] = 0;
822
823 vers = mesg;
824 len = qword_get(&mesg, vers, size);
825 if (len <= 0) return -EINVAL;
826 do {
827 sign = *vers;
828 if (sign == '+' || sign == '-')
Benny Halevy8daf2202009-04-03 08:28:59 +0300829 num = simple_strtol((vers+1), &minorp, 0);
NeilBrown70c3b762005-11-07 01:00:25 -0800830 else
Benny Halevy8daf2202009-04-03 08:28:59 +0300831 num = simple_strtol(vers, &minorp, 0);
832 if (*minorp == '.') {
833 if (num < 4)
834 return -EINVAL;
835 minor = simple_strtoul(minorp+1, NULL, 0);
836 if (minor == 0)
837 return -EINVAL;
838 if (nfsd_minorversion(minor, sign == '-' ?
839 NFSD_CLEAR : NFSD_SET) < 0)
840 return -EINVAL;
841 goto next;
842 }
NeilBrown70c3b762005-11-07 01:00:25 -0800843 switch(num) {
844 case 2:
845 case 3:
846 case 4:
NeilBrown6658d3a2006-10-02 02:17:46 -0700847 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
NeilBrown70c3b762005-11-07 01:00:25 -0800848 break;
849 default:
850 return -EINVAL;
851 }
Benny Halevy8daf2202009-04-03 08:28:59 +0300852 next:
NeilBrown70c3b762005-11-07 01:00:25 -0800853 vers += len + 1;
NeilBrown70c3b762005-11-07 01:00:25 -0800854 } while ((len = qword_get(&mesg, vers, size)) > 0);
855 /* If all get turned off, turn them back on, as
856 * having no versions is BAD
857 */
NeilBrown6658d3a2006-10-02 02:17:46 -0700858 nfsd_reset_versions();
NeilBrown70c3b762005-11-07 01:00:25 -0800859 }
Chuck Lever261758b2009-04-23 19:33:18 -0400860
NeilBrown70c3b762005-11-07 01:00:25 -0800861 /* Now write current state into reply buffer */
862 len = 0;
863 sep = "";
Chuck Lever261758b2009-04-23 19:33:18 -0400864 remaining = SIMPLE_TRANSACTION_LIMIT;
NeilBrown70c3b762005-11-07 01:00:25 -0800865 for (num=2 ; num <= 4 ; num++)
NeilBrown6658d3a2006-10-02 02:17:46 -0700866 if (nfsd_vers(num, NFSD_AVAIL)) {
Chuck Lever261758b2009-04-23 19:33:18 -0400867 len = snprintf(buf, remaining, "%s%c%d", sep,
NeilBrown6658d3a2006-10-02 02:17:46 -0700868 nfsd_vers(num, NFSD_TEST)?'+':'-',
NeilBrown70c3b762005-11-07 01:00:25 -0800869 num);
870 sep = " ";
Chuck Lever261758b2009-04-23 19:33:18 -0400871
872 if (len > remaining)
873 break;
874 remaining -= len;
875 buf += len;
876 tlen += len;
NeilBrown70c3b762005-11-07 01:00:25 -0800877 }
Benny Halevy8daf2202009-04-03 08:28:59 +0300878 if (nfsd_vers(4, NFSD_AVAIL))
Chuck Lever261758b2009-04-23 19:33:18 -0400879 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
880 minor++) {
881 len = snprintf(buf, remaining, " %c4.%u",
Benny Halevy8daf2202009-04-03 08:28:59 +0300882 (nfsd_vers(4, NFSD_TEST) &&
883 nfsd_minorversion(minor, NFSD_TEST)) ?
884 '+' : '-',
885 minor);
Chuck Lever261758b2009-04-23 19:33:18 -0400886
887 if (len > remaining)
888 break;
889 remaining -= len;
890 buf += len;
891 tlen += len;
892 }
893
894 len = snprintf(buf, remaining, "\n");
895 if (len > remaining)
896 return -EINVAL;
897 return tlen + len;
NeilBrown70c3b762005-11-07 01:00:25 -0800898}
899
Chuck Lever262a0982008-12-12 16:57:35 -0500900/**
901 * write_versions - Set or report the available NFS protocol versions
902 *
903 * Input:
904 * buf: ignored
905 * size: zero
906 * Output:
907 * On success: passed-in buffer filled with '\n'-terminated C
908 * string containing positive or negative integer
909 * values representing the current status of each
910 * protocol version;
911 * return code is the size in bytes of the string
912 * On error: return code is zero or a negative errno value
913 *
914 * OR
915 *
916 * Input:
917 * buf: C string containing whitespace-
918 * separated positive or negative
919 * integer values representing NFS
920 * protocol versions to enable ("+n")
921 * or disable ("-n")
922 * size: non-zero length of C string in @buf
923 * Output:
924 * On success: status of zero or more protocol versions has
925 * been updated; passed-in buffer filled with
926 * '\n'-terminated C string containing positive
927 * or negative integer values representing the
928 * current status of each protocol version;
929 * return code is the size in bytes of the string
930 * On error: return code is zero or a negative errno value
931 */
Jeff Layton3dd98a32008-06-10 08:40:36 -0400932static ssize_t write_versions(struct file *file, char *buf, size_t size)
933{
934 ssize_t rv;
935
936 mutex_lock(&nfsd_mutex);
937 rv = __write_versions(file, buf, size);
938 mutex_unlock(&nfsd_mutex);
939 return rv;
940}
941
Chuck Lever4cd5dc72009-04-23 19:31:32 -0400942/*
Chuck Lever0a5372d2009-04-23 19:32:10 -0400943 * Zero-length write. Return a list of NFSD's current listener
944 * transports.
945 */
946static ssize_t __write_ports_names(char *buf)
947{
948 if (nfsd_serv == NULL)
949 return 0;
Chuck Lever335c54b2009-04-23 19:32:25 -0400950 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
Chuck Lever0a5372d2009-04-23 19:32:10 -0400951}
952
953/*
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400954 * A single 'fd' number was written, in which case it must be for
955 * a socket of a supported family/protocol, and we use it as an
956 * nfsd listener.
957 */
958static ssize_t __write_ports_addfd(char *buf)
959{
960 char *mesg = buf;
961 int fd, err;
962
963 err = get_int(&mesg, &fd);
964 if (err != 0 || fd < 0)
965 return -EINVAL;
966
967 err = nfsd_create_serv();
968 if (err != 0)
969 return err;
970
Chuck Leverbfba9ab2009-04-23 19:32:33 -0400971 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
Jeff Layton78a8d7c2010-07-19 16:50:05 -0400972 if (err < 0) {
Jeff Layton78a8d7c2010-07-19 16:50:05 -0400973 svc_destroy(nfsd_serv);
974 return err;
975 }
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400976
Chuck Leverea068ba2009-04-23 19:32:18 -0400977 /* Decrease the count, but don't shut down the service */
978 nfsd_serv->sv_nrthreads--;
979 return err;
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400980}
981
982/*
Chuck Lever82d56592009-04-23 19:31:48 -0400983 * A '-' followed by the 'name' of a socket means we close the socket.
984 */
985static ssize_t __write_ports_delfd(char *buf)
986{
987 char *toclose;
988 int len = 0;
989
990 toclose = kstrdup(buf + 1, GFP_KERNEL);
991 if (toclose == NULL)
992 return -ENOMEM;
993
994 if (nfsd_serv != NULL)
Chuck Lever8435d342009-04-23 19:32:40 -0400995 len = svc_sock_names(nfsd_serv, buf,
996 SIMPLE_TRANSACTION_LIMIT, toclose);
Chuck Lever82d56592009-04-23 19:31:48 -0400997 kfree(toclose);
998 return len;
999}
1000
1001/*
Chuck Lever4eb68c22009-04-23 19:31:40 -04001002 * A transport listener is added by writing it's transport name and
1003 * a port number.
1004 */
1005static ssize_t __write_ports_addxprt(char *buf)
1006{
1007 char transport[16];
Chuck Lever37498292010-01-26 14:04:22 -05001008 struct svc_xprt *xprt;
Chuck Lever4eb68c22009-04-23 19:31:40 -04001009 int port, err;
1010
1011 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
1012 return -EINVAL;
1013
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001014 if (port < 1 || port > USHRT_MAX)
Chuck Lever4eb68c22009-04-23 19:31:40 -04001015 return -EINVAL;
1016
1017 err = nfsd_create_serv();
1018 if (err != 0)
1019 return err;
1020
Pavel Emelyanovfc5d00b2010-09-29 16:03:50 +04001021 err = svc_create_xprt(nfsd_serv, transport, &init_net,
Chuck Lever4eb68c22009-04-23 19:31:40 -04001022 PF_INET, port, SVC_SOCK_ANONYMOUS);
Chuck Lever68717902010-01-26 14:04:13 -05001023 if (err < 0)
Chuck Lever37498292010-01-26 14:04:22 -05001024 goto out_err;
1025
Pavel Emelyanovfc5d00b2010-09-29 16:03:50 +04001026 err = svc_create_xprt(nfsd_serv, transport, &init_net,
Chuck Lever37498292010-01-26 14:04:22 -05001027 PF_INET6, port, SVC_SOCK_ANONYMOUS);
1028 if (err < 0 && err != -EAFNOSUPPORT)
1029 goto out_close;
Jeff Layton0cd14a02010-07-19 16:50:06 -04001030
1031 /* Decrease the count, but don't shut down the service */
1032 nfsd_serv->sv_nrthreads--;
Chuck Lever4eb68c22009-04-23 19:31:40 -04001033 return 0;
Chuck Lever37498292010-01-26 14:04:22 -05001034out_close:
1035 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
1036 if (xprt != NULL) {
1037 svc_close_xprt(xprt);
1038 svc_xprt_put(xprt);
1039 }
1040out_err:
Jeff Layton0cd14a02010-07-19 16:50:06 -04001041 svc_destroy(nfsd_serv);
Chuck Lever37498292010-01-26 14:04:22 -05001042 return err;
Chuck Lever4eb68c22009-04-23 19:31:40 -04001043}
1044
1045/*
Chuck Lever4cd5dc72009-04-23 19:31:32 -04001046 * A transport listener is removed by writing a "-", it's transport
1047 * name, and it's port number.
1048 */
1049static ssize_t __write_ports_delxprt(char *buf)
1050{
1051 struct svc_xprt *xprt;
1052 char transport[16];
1053 int port;
1054
1055 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1056 return -EINVAL;
1057
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001058 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
Chuck Lever4cd5dc72009-04-23 19:31:32 -04001059 return -EINVAL;
1060
1061 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1062 if (xprt == NULL)
1063 return -ENOTCONN;
1064
1065 svc_close_xprt(xprt);
1066 svc_xprt_put(xprt);
1067 return 0;
1068}
1069
Neil Brownbedbdd82008-06-10 08:40:35 -04001070static ssize_t __write_ports(struct file *file, char *buf, size_t size)
NeilBrown80212d52006-10-02 02:17:47 -07001071{
Chuck Lever0a5372d2009-04-23 19:32:10 -04001072 if (size == 0)
1073 return __write_ports_names(buf);
Chuck Lever0b7c2f62009-04-23 19:31:55 -04001074
1075 if (isdigit(buf[0]))
1076 return __write_ports_addfd(buf);
Chuck Lever82d56592009-04-23 19:31:48 -04001077
1078 if (buf[0] == '-' && isdigit(buf[1]))
1079 return __write_ports_delfd(buf);
Chuck Lever4eb68c22009-04-23 19:31:40 -04001080
1081 if (isalpha(buf[0]))
1082 return __write_ports_addxprt(buf);
Chuck Lever4cd5dc72009-04-23 19:31:32 -04001083
1084 if (buf[0] == '-' && isalpha(buf[1]))
1085 return __write_ports_delxprt(buf);
1086
NeilBrownb41b66d2006-10-02 02:17:48 -07001087 return -EINVAL;
NeilBrown80212d52006-10-02 02:17:47 -07001088}
1089
Chuck Lever262a0982008-12-12 16:57:35 -05001090/**
1091 * write_ports - Pass a socket file descriptor or transport name to listen on
1092 *
1093 * Input:
1094 * buf: ignored
1095 * size: zero
1096 * Output:
1097 * On success: passed-in buffer filled with a '\n'-terminated C
1098 * string containing a whitespace-separated list of
1099 * named NFSD listeners;
1100 * return code is the size in bytes of the string
1101 * On error: return code is zero or a negative errno value
1102 *
1103 * OR
1104 *
1105 * Input:
1106 * buf: C string containing an unsigned
1107 * integer value representing a bound
1108 * but unconnected socket that is to be
Chuck Leverc71206a2009-04-23 19:32:03 -04001109 * used as an NFSD listener; listen(3)
1110 * must be called for a SOCK_STREAM
1111 * socket, otherwise it is ignored
Chuck Lever262a0982008-12-12 16:57:35 -05001112 * size: non-zero length of C string in @buf
1113 * Output:
1114 * On success: NFS service is started;
1115 * passed-in buffer filled with a '\n'-terminated C
1116 * string containing a unique alphanumeric name of
1117 * the listener;
1118 * return code is the size in bytes of the string
1119 * On error: return code is a negative errno value
1120 *
1121 * OR
1122 *
1123 * Input:
1124 * buf: C string containing a "-" followed
1125 * by an integer value representing a
1126 * previously passed in socket file
1127 * descriptor
1128 * size: non-zero length of C string in @buf
1129 * Output:
1130 * On success: NFS service no longer listens on that socket;
1131 * passed-in buffer filled with a '\n'-terminated C
1132 * string containing a unique name of the listener;
1133 * return code is the size in bytes of the string
1134 * On error: return code is a negative errno value
1135 *
1136 * OR
1137 *
1138 * Input:
1139 * buf: C string containing a transport
1140 * name and an unsigned integer value
1141 * representing the port to listen on,
1142 * separated by whitespace
1143 * size: non-zero length of C string in @buf
1144 * Output:
1145 * On success: returns zero; NFS service is started
1146 * On error: return code is a negative errno value
1147 *
1148 * OR
1149 *
1150 * Input:
1151 * buf: C string containing a "-" followed
1152 * by a transport name and an unsigned
1153 * integer value representing the port
1154 * to listen on, separated by whitespace
1155 * size: non-zero length of C string in @buf
1156 * Output:
1157 * On success: returns zero; NFS service no longer listens
1158 * on that transport
1159 * On error: return code is a negative errno value
1160 */
Neil Brownbedbdd82008-06-10 08:40:35 -04001161static ssize_t write_ports(struct file *file, char *buf, size_t size)
1162{
1163 ssize_t rv;
Jeff Layton3dd98a32008-06-10 08:40:36 -04001164
Neil Brownbedbdd82008-06-10 08:40:35 -04001165 mutex_lock(&nfsd_mutex);
1166 rv = __write_ports(file, buf, size);
1167 mutex_unlock(&nfsd_mutex);
1168 return rv;
1169}
1170
1171
NeilBrown596bbe52006-10-04 02:15:48 -07001172int nfsd_max_blksize;
1173
Chuck Lever262a0982008-12-12 16:57:35 -05001174/**
1175 * write_maxblksize - Set or report the current NFS blksize
1176 *
1177 * Input:
1178 * buf: ignored
1179 * size: zero
1180 *
1181 * OR
1182 *
1183 * Input:
1184 * buf: C string containing an unsigned
1185 * integer value representing the new
1186 * NFS blksize
1187 * size: non-zero length of C string in @buf
1188 * Output:
1189 * On success: passed-in buffer filled with '\n'-terminated C string
1190 * containing numeric value of the current NFS blksize
1191 * setting;
1192 * return code is the size in bytes of the string
1193 * On error: return code is zero or a negative errno value
1194 */
NeilBrown596bbe52006-10-04 02:15:48 -07001195static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1196{
1197 char *mesg = buf;
1198 if (size > 0) {
1199 int bsize;
1200 int rv = get_int(&mesg, &bsize);
1201 if (rv)
1202 return rv;
1203 /* force bsize into allowed range and
1204 * required alignment.
1205 */
1206 if (bsize < 1024)
1207 bsize = 1024;
1208 if (bsize > NFSSVC_MAXBLKSIZE)
1209 bsize = NFSSVC_MAXBLKSIZE;
1210 bsize &= ~(1024-1);
Neil Brownbedbdd82008-06-10 08:40:35 -04001211 mutex_lock(&nfsd_mutex);
J. Bruce Fields7fa53cc2010-08-06 18:00:33 -04001212 if (nfsd_serv) {
Neil Brownbedbdd82008-06-10 08:40:35 -04001213 mutex_unlock(&nfsd_mutex);
NeilBrown596bbe52006-10-04 02:15:48 -07001214 return -EBUSY;
1215 }
1216 nfsd_max_blksize = bsize;
Neil Brownbedbdd82008-06-10 08:40:35 -04001217 mutex_unlock(&nfsd_mutex);
NeilBrown596bbe52006-10-04 02:15:48 -07001218 }
Chuck Levere06b6402009-04-23 19:33:25 -04001219
1220 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1221 nfsd_max_blksize);
NeilBrown596bbe52006-10-04 02:15:48 -07001222}
1223
NeilBrown70c3b762005-11-07 01:00:25 -08001224#ifdef CONFIG_NFSD_V4
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001225static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 char *mesg = buf;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001228 int rv, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 if (size > 0) {
Jeff Layton3dd98a32008-06-10 08:40:36 -04001231 if (nfsd_serv)
1232 return -EBUSY;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001233 rv = get_int(&mesg, &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 if (rv)
1235 return rv;
J. Bruce Fieldse7b184f2010-03-02 11:18:40 -05001236 /*
1237 * Some sanity checking. We don't have a reason for
1238 * these particular numbers, but problems with the
1239 * extremes are:
1240 * - Too short: the briefest network outage may
1241 * cause clients to lose all their locks. Also,
1242 * the frequent polling may be wasteful.
1243 * - Too long: do you really want reboot recovery
1244 * to take more than an hour? Or to make other
1245 * clients wait an hour before being able to
1246 * revoke a dead client's locks?
1247 */
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001248 if (i < 10 || i > 3600)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 return -EINVAL;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001250 *time = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
Chuck Levere06b6402009-04-23 19:33:25 -04001252
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001253 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
1254}
1255
1256static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1257{
1258 ssize_t rv;
1259
1260 mutex_lock(&nfsd_mutex);
1261 rv = __nfsd4_write_time(file, buf, size, time);
1262 mutex_unlock(&nfsd_mutex);
1263 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Chuck Lever262a0982008-12-12 16:57:35 -05001266/**
1267 * write_leasetime - Set or report the current NFSv4 lease time
1268 *
1269 * Input:
1270 * buf: ignored
1271 * size: zero
1272 *
1273 * OR
1274 *
1275 * Input:
1276 * buf: C string containing an unsigned
1277 * integer value representing the new
1278 * NFSv4 lease expiry time
1279 * size: non-zero length of C string in @buf
1280 * Output:
1281 * On success: passed-in buffer filled with '\n'-terminated C
1282 * string containing unsigned integer value of the
1283 * current lease expiry time;
1284 * return code is the size in bytes of the string
1285 * On error: return code is zero or a negative errno value
1286 */
Jeff Layton3dd98a32008-06-10 08:40:36 -04001287static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1288{
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001289 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
Jeff Layton3dd98a32008-06-10 08:40:36 -04001290}
1291
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -05001292/**
1293 * write_gracetime - Set or report current NFSv4 grace period time
1294 *
1295 * As above, but sets the time of the NFSv4 grace period.
1296 *
1297 * Note this should never be set to less than the *previous*
1298 * lease-period time, but we don't try to enforce this. (In the common
1299 * case (a new boot), we don't know what the previous lease time was
1300 * anyway.)
1301 */
1302static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1303{
1304 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
1305}
1306
Jeff Layton3dd98a32008-06-10 08:40:36 -04001307extern char *nfs4_recoverydir(void);
1308
1309static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
NeilBrown0964a3d2005-06-23 22:04:32 -07001310{
1311 char *mesg = buf;
1312 char *recdir;
1313 int len, status;
1314
Jeff Layton3dd98a32008-06-10 08:40:36 -04001315 if (size > 0) {
1316 if (nfsd_serv)
1317 return -EBUSY;
1318 if (size > PATH_MAX || buf[size-1] != '\n')
1319 return -EINVAL;
1320 buf[size-1] = 0;
NeilBrown0964a3d2005-06-23 22:04:32 -07001321
Jeff Layton3dd98a32008-06-10 08:40:36 -04001322 recdir = mesg;
1323 len = qword_get(&mesg, recdir, size);
1324 if (len <= 0)
1325 return -EINVAL;
NeilBrown0964a3d2005-06-23 22:04:32 -07001326
Jeff Layton3dd98a32008-06-10 08:40:36 -04001327 status = nfs4_reset_recoverydir(recdir);
Andi Kleen69049962010-07-20 15:24:27 -07001328 if (status)
1329 return status;
Jeff Layton3dd98a32008-06-10 08:40:36 -04001330 }
Chuck Lever3d72ab82009-04-23 19:33:10 -04001331
1332 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1333 nfs4_recoverydir());
NeilBrown0964a3d2005-06-23 22:04:32 -07001334}
Jeff Layton3dd98a32008-06-10 08:40:36 -04001335
Chuck Lever262a0982008-12-12 16:57:35 -05001336/**
1337 * write_recoverydir - Set or report the pathname of the recovery directory
1338 *
1339 * Input:
1340 * buf: ignored
1341 * size: zero
1342 *
1343 * OR
1344 *
1345 * Input:
1346 * buf: C string containing the pathname
1347 * of the directory on a local file
1348 * system containing permanent NFSv4
1349 * recovery data
1350 * size: non-zero length of C string in @buf
1351 * Output:
1352 * On success: passed-in buffer filled with '\n'-terminated C string
1353 * containing the current recovery pathname setting;
1354 * return code is the size in bytes of the string
1355 * On error: return code is zero or a negative errno value
1356 */
Jeff Layton3dd98a32008-06-10 08:40:36 -04001357static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1358{
1359 ssize_t rv;
1360
1361 mutex_lock(&nfsd_mutex);
1362 rv = __write_recoverydir(file, buf, size);
1363 mutex_unlock(&nfsd_mutex);
1364 return rv;
1365}
1366
NeilBrown70c3b762005-11-07 01:00:25 -08001367#endif
NeilBrown0964a3d2005-06-23 22:04:32 -07001368
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369/*----------------------------------------------------------------------------*/
1370/*
1371 * populating the filesystem.
1372 */
1373
1374static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1375{
1376 static struct tree_descr nfsd_files[] = {
NeilBrown1e140562010-09-22 12:55:07 +10001377#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1379 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1380 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1381 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1382 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1383 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1384 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown1e140562010-09-22 12:55:07 +10001385#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
J. Bruce Fieldse8e87532009-12-14 12:53:32 -05001387 [NFSD_Export_features] = {"export_features",
1388 &export_features_operations, S_IRUGO},
Wendy Cheng4373ea82008-01-17 11:10:12 -05001389 [NFSD_FO_UnlockIP] = {"unlock_ip",
1390 &transaction_ops, S_IWUSR|S_IRUSR},
Wendy Cheng17efa372008-01-17 11:10:12 -05001391 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1392 &transaction_ops, S_IWUSR|S_IRUSR},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1394 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
Greg Bankseed29652006-10-02 02:18:02 -07001395 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
Greg Banks03cf6c92009-01-13 21:26:36 +11001396 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
NeilBrown70c3b762005-11-07 01:00:25 -08001397 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown80212d52006-10-02 02:17:47 -07001398 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
NeilBrown596bbe52006-10-04 02:15:48 -07001399 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400#ifdef CONFIG_NFSD_V4
1401 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -05001402 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown0964a3d2005-06-23 22:04:32 -07001403 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404#endif
1405 /* last one */ {""}
1406 };
1407 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1408}
1409
Al Virofc14f2f2010-07-25 01:48:30 +04001410static struct dentry *nfsd_mount(struct file_system_type *fs_type,
1411 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Al Virofc14f2f2010-07-25 01:48:30 +04001413 return mount_single(fs_type, flags, data, nfsd_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414}
1415
1416static struct file_system_type nfsd_fs_type = {
1417 .owner = THIS_MODULE,
1418 .name = "nfsd",
Al Virofc14f2f2010-07-25 01:48:30 +04001419 .mount = nfsd_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 .kill_sb = kill_litter_super,
1421};
1422
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001423#ifdef CONFIG_PROC_FS
1424static int create_proc_exports_entry(void)
1425{
1426 struct proc_dir_entry *entry;
1427
1428 entry = proc_mkdir("fs/nfs", NULL);
1429 if (!entry)
1430 return -ENOMEM;
Denis V. Lunev9ef2db22008-04-29 01:02:04 -07001431 entry = proc_create("exports", 0, entry, &exports_operations);
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001432 if (!entry)
1433 return -ENOMEM;
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001434 return 0;
1435}
1436#else /* CONFIG_PROC_FS */
1437static int create_proc_exports_entry(void)
1438{
1439 return 0;
1440}
1441#endif
1442
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443static int __init init_nfsd(void)
1444{
1445 int retval;
1446 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1447
J. Bruce Fieldse8ff2a82007-08-01 15:30:59 -04001448 retval = nfs4_state_init(); /* nfs4 locking state */
1449 if (retval)
1450 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 nfsd_stat_init(); /* Statistics */
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001452 retval = nfsd_reply_cache_init();
1453 if (retval)
1454 goto out_free_stat;
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001455 retval = nfsd_export_init();
1456 if (retval)
1457 goto out_free_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 nfsd_lockd_init(); /* lockd->nfsd callbacks */
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001459 retval = nfsd_idmap_init();
1460 if (retval)
1461 goto out_free_lockd;
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001462 retval = create_proc_exports_entry();
1463 if (retval)
1464 goto out_free_idmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 retval = register_filesystem(&nfsd_fs_type);
J. Bruce Fields26808d32007-11-09 13:44:06 -05001466 if (retval)
1467 goto out_free_all;
1468 return 0;
1469out_free_all:
J. Bruce Fields26808d32007-11-09 13:44:06 -05001470 remove_proc_entry("fs/nfs/exports", NULL);
1471 remove_proc_entry("fs/nfs", NULL);
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001472out_free_idmap:
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001473 nfsd_idmap_shutdown();
1474out_free_lockd:
J. Bruce Fields26808d32007-11-09 13:44:06 -05001475 nfsd_lockd_shutdown();
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001476 nfsd_export_shutdown();
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001477out_free_cache:
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001478 nfsd_reply_cache_shutdown();
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001479out_free_stat:
1480 nfsd_stat_shutdown();
J. Bruce Fields26808d32007-11-09 13:44:06 -05001481 nfsd4_free_slabs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 return retval;
1483}
1484
1485static void __exit exit_nfsd(void)
1486{
1487 nfsd_export_shutdown();
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001488 nfsd_reply_cache_shutdown();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 remove_proc_entry("fs/nfs/exports", NULL);
1490 remove_proc_entry("fs/nfs", NULL);
1491 nfsd_stat_shutdown();
1492 nfsd_lockd_shutdown();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 nfsd_idmap_shutdown();
J. Bruce Fieldse8ff2a82007-08-01 15:30:59 -04001494 nfsd4_free_slabs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 unregister_filesystem(&nfsd_fs_type);
1496}
1497
1498MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1499MODULE_LICENSE("GPL");
1500module_init(init_nfsd)
1501module_exit(exit_nfsd)