]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/nfsd/nfsctl.c
nfsd: Move private headers to source directory
[net-next-2.6.git] / fs / nfsd / nfsctl.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/nfsd/nfsctl.c
3 *
4 * Syscall interface to knfsd.
5 *
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 */
8
3f8206d4 9#include <linux/namei.h>
b41b66d6 10#include <linux/ctype.h>
1da177e4 11
1da177e4 12#include <linux/nfsd_idmap.h>
80212d59 13#include <linux/sunrpc/svcsock.h>
1da177e4 14#include <linux/nfsd/syscall.h>
4373ea84 15#include <linux/lockd/lockd.h>
4116092b 16#include <linux/sunrpc/clnt.h>
1da177e4 17
9a74af21
BH
18#include "nfsd.h"
19#include "cache.h"
20
1da177e4
LT
21/*
22 * We have a single directory with 9 nodes in it.
23 */
24enum {
25 NFSD_Root = 1,
26 NFSD_Svc,
27 NFSD_Add,
28 NFSD_Del,
29 NFSD_Export,
30 NFSD_Unexport,
31 NFSD_Getfd,
32 NFSD_Getfs,
33 NFSD_List,
34 NFSD_Fh,
4373ea84 35 NFSD_FO_UnlockIP,
17efa372 36 NFSD_FO_UnlockFS,
1da177e4 37 NFSD_Threads,
eed2965a 38 NFSD_Pool_Threads,
03cf6c9f 39 NFSD_Pool_Stats,
70c3b76c 40 NFSD_Versions,
80212d59 41 NFSD_Ports,
596bbe53 42 NFSD_MaxBlkSize,
70c3b76c
N
43 /*
44 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
45 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
46 */
47#ifdef CONFIG_NFSD_V4
1da177e4 48 NFSD_Leasetime,
0964a3d3 49 NFSD_RecoveryDir,
70c3b76c 50#endif
1da177e4
LT
51};
52
53/*
54 * write() for these nodes.
55 */
56static ssize_t write_svc(struct file *file, char *buf, size_t size);
57static ssize_t write_add(struct file *file, char *buf, size_t size);
58static ssize_t write_del(struct file *file, char *buf, size_t size);
59static ssize_t write_export(struct file *file, char *buf, size_t size);
60static ssize_t write_unexport(struct file *file, char *buf, size_t size);
61static ssize_t write_getfd(struct file *file, char *buf, size_t size);
62static ssize_t write_getfs(struct file *file, char *buf, size_t size);
63static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
b046ccdc
CL
64static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
65static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
1da177e4 66static ssize_t write_threads(struct file *file, char *buf, size_t size);
eed2965a 67static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
70c3b76c 68static ssize_t write_versions(struct file *file, char *buf, size_t size);
80212d59 69static ssize_t write_ports(struct file *file, char *buf, size_t size);
596bbe53 70static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
70c3b76c 71#ifdef CONFIG_NFSD_V4
1da177e4 72static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
0964a3d3 73static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
70c3b76c 74#endif
1da177e4
LT
75
76static ssize_t (*write_op[])(struct file *, char *, size_t) = {
77 [NFSD_Svc] = write_svc,
78 [NFSD_Add] = write_add,
79 [NFSD_Del] = write_del,
80 [NFSD_Export] = write_export,
81 [NFSD_Unexport] = write_unexport,
82 [NFSD_Getfd] = write_getfd,
83 [NFSD_Getfs] = write_getfs,
84 [NFSD_Fh] = write_filehandle,
b046ccdc
CL
85 [NFSD_FO_UnlockIP] = write_unlock_ip,
86 [NFSD_FO_UnlockFS] = write_unlock_fs,
1da177e4 87 [NFSD_Threads] = write_threads,
eed2965a 88 [NFSD_Pool_Threads] = write_pool_threads,
70c3b76c 89 [NFSD_Versions] = write_versions,
80212d59 90 [NFSD_Ports] = write_ports,
596bbe53 91 [NFSD_MaxBlkSize] = write_maxblksize,
70c3b76c 92#ifdef CONFIG_NFSD_V4
1da177e4 93 [NFSD_Leasetime] = write_leasetime,
0964a3d3 94 [NFSD_RecoveryDir] = write_recoverydir,
70c3b76c 95#endif
1da177e4
LT
96};
97
98static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
99{
7eaa36e2 100 ino_t ino = file->f_path.dentry->d_inode->i_ino;
1da177e4
LT
101 char *data;
102 ssize_t rv;
103
e8c96f8c 104 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
1da177e4
LT
105 return -EINVAL;
106
107 data = simple_transaction_get(file, buf, size);
108 if (IS_ERR(data))
109 return PTR_ERR(data);
110
111 rv = write_op[ino](file, data, size);
8971a101 112 if (rv >= 0) {
1da177e4
LT
113 simple_transaction_set(file, rv);
114 rv = size;
115 }
116 return rv;
117}
118
7390022d
N
119static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
120{
121 if (! file->private_data) {
122 /* An attempt to read a transaction file without writing
123 * causes a 0-byte write so that the file can return
124 * state information
125 */
126 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
127 if (rv < 0)
128 return rv;
129 }
130 return simple_transaction_read(file, buf, size, pos);
131}
132
4b6f5d20 133static const struct file_operations transaction_ops = {
1da177e4 134 .write = nfsctl_transaction_write,
7390022d 135 .read = nfsctl_transaction_read,
1da177e4
LT
136 .release = simple_transaction_release,
137};
138
1da177e4
LT
139static int exports_open(struct inode *inode, struct file *file)
140{
141 return seq_open(file, &nfs_exports_op);
142}
143
4b6f5d20 144static const struct file_operations exports_operations = {
1da177e4
LT
145 .open = exports_open,
146 .read = seq_read,
147 .llseek = seq_lseek,
148 .release = seq_release,
9ef2db26 149 .owner = THIS_MODULE,
1da177e4
LT
150};
151
03cf6c9f 152extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
ed2d8aed 153extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
03cf6c9f 154
828c0950 155static const struct file_operations pool_stats_operations = {
03cf6c9f
GB
156 .open = nfsd_pool_stats_open,
157 .read = seq_read,
158 .llseek = seq_lseek,
ed2d8aed 159 .release = nfsd_pool_stats_release,
03cf6c9f
GB
160 .owner = THIS_MODULE,
161};
162
1da177e4
LT
163/*----------------------------------------------------------------------------*/
164/*
165 * payload - write methods
1da177e4
LT
166 */
167
262a0982
CL
168/**
169 * write_svc - Start kernel's NFSD server
170 *
171 * Deprecated. /proc/fs/nfsd/threads is preferred.
172 * Function remains to support old versions of nfs-utils.
173 *
174 * Input:
175 * buf: struct nfsctl_svc
176 * svc_port: port number of this
177 * server's listener
178 * svc_nthreads: number of threads to start
179 * size: size in bytes of passed in nfsctl_svc
180 * Output:
181 * On success: returns zero
182 * On error: return code is negative errno value
183 */
1da177e4
LT
184static ssize_t write_svc(struct file *file, char *buf, size_t size)
185{
186 struct nfsctl_svc *data;
82e12fe9 187 int err;
1da177e4
LT
188 if (size < sizeof(*data))
189 return -EINVAL;
190 data = (struct nfsctl_svc*) buf;
82e12fe9
N
191 err = nfsd_svc(data->svc_port, data->svc_nthreads);
192 if (err < 0)
193 return err;
194 return 0;
1da177e4
LT
195}
196
262a0982
CL
197/**
198 * write_add - Add or modify client entry in auth unix cache
199 *
200 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
201 * Function remains to support old versions of nfs-utils.
202 *
203 * Input:
204 * buf: struct nfsctl_client
205 * cl_ident: '\0'-terminated C string
206 * containing domain name
207 * of client
208 * cl_naddr: no. of items in cl_addrlist
209 * cl_addrlist: array of client addresses
210 * cl_fhkeytype: ignored
211 * cl_fhkeylen: ignored
212 * cl_fhkey: ignored
213 * size: size in bytes of passed in nfsctl_client
214 * Output:
215 * On success: returns zero
216 * On error: return code is negative errno value
217 *
218 * Note: Only AF_INET client addresses are passed in, since
219 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
220 */
1da177e4
LT
221static ssize_t write_add(struct file *file, char *buf, size_t size)
222{
223 struct nfsctl_client *data;
224 if (size < sizeof(*data))
225 return -EINVAL;
226 data = (struct nfsctl_client *)buf;
227 return exp_addclient(data);
228}
229
262a0982
CL
230/**
231 * write_del - Remove client from auth unix cache
232 *
233 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
234 * Function remains to support old versions of nfs-utils.
235 *
236 * Input:
237 * buf: struct nfsctl_client
238 * cl_ident: '\0'-terminated C string
239 * containing domain name
240 * of client
241 * cl_naddr: ignored
242 * cl_addrlist: ignored
243 * cl_fhkeytype: ignored
244 * cl_fhkeylen: ignored
245 * cl_fhkey: ignored
246 * size: size in bytes of passed in nfsctl_client
247 * Output:
248 * On success: returns zero
249 * On error: return code is negative errno value
250 *
251 * Note: Only AF_INET client addresses are passed in, since
252 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
253 */
1da177e4
LT
254static ssize_t write_del(struct file *file, char *buf, size_t size)
255{
256 struct nfsctl_client *data;
257 if (size < sizeof(*data))
258 return -EINVAL;
259 data = (struct nfsctl_client *)buf;
260 return exp_delclient(data);
261}
262
262a0982
CL
263/**
264 * write_export - Export part or all of a local file system
265 *
266 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
267 * Function remains to support old versions of nfs-utils.
268 *
269 * Input:
270 * buf: struct nfsctl_export
271 * ex_client: '\0'-terminated C string
272 * containing domain name
273 * of client allowed to access
274 * this export
275 * ex_path: '\0'-terminated C string
276 * containing pathname of
277 * directory in local file system
278 * ex_dev: fsid to use for this export
279 * ex_ino: ignored
280 * ex_flags: export flags for this export
281 * ex_anon_uid: UID to use for anonymous
282 * requests
283 * ex_anon_gid: GID to use for anonymous
284 * requests
285 * size: size in bytes of passed in nfsctl_export
286 * Output:
287 * On success: returns zero
288 * On error: return code is negative errno value
289 */
1da177e4
LT
290static ssize_t write_export(struct file *file, char *buf, size_t size)
291{
292 struct nfsctl_export *data;
293 if (size < sizeof(*data))
294 return -EINVAL;
295 data = (struct nfsctl_export*)buf;
296 return exp_export(data);
297}
298
262a0982
CL
299/**
300 * write_unexport - Unexport a previously exported file system
301 *
302 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
303 * Function remains to support old versions of nfs-utils.
304 *
305 * Input:
306 * buf: struct nfsctl_export
307 * ex_client: '\0'-terminated C string
308 * containing domain name
309 * of client no longer allowed
310 * to access this export
311 * ex_path: '\0'-terminated C string
312 * containing pathname of
313 * directory in local file system
314 * ex_dev: ignored
315 * ex_ino: ignored
316 * ex_flags: ignored
317 * ex_anon_uid: ignored
318 * ex_anon_gid: ignored
319 * size: size in bytes of passed in nfsctl_export
320 * Output:
321 * On success: returns zero
322 * On error: return code is negative errno value
323 */
1da177e4
LT
324static ssize_t write_unexport(struct file *file, char *buf, size_t size)
325{
326 struct nfsctl_export *data;
327
328 if (size < sizeof(*data))
329 return -EINVAL;
330 data = (struct nfsctl_export*)buf;
331 return exp_unexport(data);
332}
333
262a0982
CL
334/**
335 * write_getfs - Get a variable-length NFS file handle by path
336 *
337 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
338 * Function remains to support old versions of nfs-utils.
339 *
340 * Input:
341 * buf: struct nfsctl_fsparm
342 * gd_addr: socket address of client
343 * gd_path: '\0'-terminated C string
344 * containing pathname of
345 * directory in local file system
346 * gd_maxlen: maximum size of returned file
347 * handle
348 * size: size in bytes of passed in nfsctl_fsparm
349 * Output:
350 * On success: passed-in buffer filled with a knfsd_fh structure
351 * (a variable-length raw NFS file handle);
352 * return code is the size in bytes of the file handle
353 * On error: return code is negative errno value
354 *
355 * Note: Only AF_INET client addresses are passed in, since gd_addr
356 * is the same size as a struct sockaddr_in.
357 */
1da177e4
LT
358static ssize_t write_getfs(struct file *file, char *buf, size_t size)
359{
360 struct nfsctl_fsparm *data;
361 struct sockaddr_in *sin;
362 struct auth_domain *clp;
363 int err = 0;
364 struct knfsd_fh *res;
f15364bd 365 struct in6_addr in6;
1da177e4
LT
366
367 if (size < sizeof(*data))
368 return -EINVAL;
369 data = (struct nfsctl_fsparm*)buf;
370 err = -EPROTONOSUPPORT;
371 if (data->gd_addr.sa_family != AF_INET)
372 goto out;
373 sin = (struct sockaddr_in *)&data->gd_addr;
374 if (data->gd_maxlen > NFS3_FHSIZE)
375 data->gd_maxlen = NFS3_FHSIZE;
376
377 res = (struct knfsd_fh*)buf;
378
379 exp_readlock();
f15364bd
AC
380
381 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
382
383 clp = auth_unix_lookup(&in6);
384 if (!clp)
1da177e4
LT
385 err = -EPERM;
386 else {
387 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
388 auth_domain_put(clp);
389 }
390 exp_readunlock();
391 if (err == 0)
12127498 392 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
1da177e4
LT
393 out:
394 return err;
395}
396
262a0982
CL
397/**
398 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
399 *
400 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
401 * Function remains to support old versions of nfs-utils.
402 *
403 * Input:
404 * buf: struct nfsctl_fdparm
405 * gd_addr: socket address of client
406 * gd_path: '\0'-terminated C string
407 * containing pathname of
408 * directory in local file system
409 * gd_version: fdparm structure version
410 * size: size in bytes of passed in nfsctl_fdparm
411 * Output:
412 * On success: passed-in buffer filled with nfsctl_res
413 * (a fixed-length raw NFS file handle);
414 * return code is the size in bytes of the file handle
415 * On error: return code is negative errno value
416 *
417 * Note: Only AF_INET client addresses are passed in, since gd_addr
418 * is the same size as a struct sockaddr_in.
419 */
1da177e4
LT
420static ssize_t write_getfd(struct file *file, char *buf, size_t size)
421{
422 struct nfsctl_fdparm *data;
423 struct sockaddr_in *sin;
424 struct auth_domain *clp;
425 int err = 0;
426 struct knfsd_fh fh;
427 char *res;
f15364bd 428 struct in6_addr in6;
1da177e4
LT
429
430 if (size < sizeof(*data))
431 return -EINVAL;
432 data = (struct nfsctl_fdparm*)buf;
433 err = -EPROTONOSUPPORT;
434 if (data->gd_addr.sa_family != AF_INET)
435 goto out;
436 err = -EINVAL;
437 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
438 goto out;
439
440 res = buf;
441 sin = (struct sockaddr_in *)&data->gd_addr;
442 exp_readlock();
f15364bd
AC
443
444 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
445
446 clp = auth_unix_lookup(&in6);
447 if (!clp)
1da177e4
LT
448 err = -EPERM;
449 else {
450 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
451 auth_domain_put(clp);
452 }
453 exp_readunlock();
454
455 if (err == 0) {
456 memset(res,0, NFS_FHSIZE);
457 memcpy(res, &fh.fh_base, fh.fh_size);
458 err = NFS_FHSIZE;
459 }
460 out:
461 return err;
462}
463
262a0982
CL
464/**
465 * write_unlock_ip - Release all locks used by a client
466 *
467 * Experimental.
468 *
469 * Input:
470 * buf: '\n'-terminated C string containing a
4116092b 471 * presentation format IP address
262a0982
CL
472 * size: length of C string in @buf
473 * Output:
474 * On success: returns zero if all specified locks were released;
475 * returns one if one or more locks were not released
476 * On error: return code is negative errno value
262a0982 477 */
b046ccdc 478static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
4373ea84 479{
4116092b
CL
480 struct sockaddr_storage address;
481 struct sockaddr *sap = (struct sockaddr *)&address;
482 size_t salen = sizeof(address);
367c8c7b 483 char *fo_path;
4373ea84
WC
484
485 /* sanity check */
486 if (size == 0)
487 return -EINVAL;
488
489 if (buf[size-1] != '\n')
490 return -EINVAL;
491
492 fo_path = buf;
493 if (qword_get(&buf, fo_path, size) < 0)
494 return -EINVAL;
495
4116092b 496 if (rpc_pton(fo_path, size, sap, salen) == 0)
4373ea84 497 return -EINVAL;
4373ea84 498
4116092b 499 return nlmsvc_unlock_all_by_ip(sap);
4373ea84
WC
500}
501
262a0982
CL
502/**
503 * write_unlock_fs - Release all locks on a local file system
504 *
505 * Experimental.
506 *
507 * Input:
508 * buf: '\n'-terminated C string containing the
509 * absolute pathname of a local file system
510 * size: length of C string in @buf
511 * Output:
512 * On success: returns zero if all specified locks were released;
513 * returns one if one or more locks were not released
514 * On error: return code is negative errno value
515 */
b046ccdc 516static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
17efa372 517{
a63bb996 518 struct path path;
17efa372
WC
519 char *fo_path;
520 int error;
521
522 /* sanity check */
523 if (size == 0)
524 return -EINVAL;
525
526 if (buf[size-1] != '\n')
527 return -EINVAL;
528
529 fo_path = buf;
530 if (qword_get(&buf, fo_path, size) < 0)
531 return -EINVAL;
532
a63bb996 533 error = kern_path(fo_path, 0, &path);
17efa372
WC
534 if (error)
535 return error;
536
262a0982
CL
537 /*
538 * XXX: Needs better sanity checking. Otherwise we could end up
539 * releasing locks on the wrong file system.
540 *
541 * For example:
542 * 1. Does the path refer to a directory?
543 * 2. Is that directory a mount point, or
544 * 3. Is that directory the root of an exported file system?
545 */
a63bb996 546 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
17efa372 547
a63bb996 548 path_put(&path);
17efa372
WC
549 return error;
550}
551
262a0982
CL
552/**
553 * write_filehandle - Get a variable-length NFS file handle by path
554 *
555 * On input, the buffer contains a '\n'-terminated C string comprised of
556 * three alphanumeric words separated by whitespace. The string may
557 * contain escape sequences.
558 *
559 * Input:
560 * buf:
561 * domain: client domain name
562 * path: export pathname
563 * maxsize: numeric maximum size of
564 * @buf
565 * size: length of C string in @buf
566 * Output:
567 * On success: passed-in buffer filled with '\n'-terminated C
568 * string containing a ASCII hex text version
569 * of the NFS file handle;
570 * return code is the size in bytes of the string
571 * On error: return code is negative errno value
572 */
1da177e4
LT
573static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
574{
1da177e4 575 char *dname, *path;
246d95ba 576 int uninitialized_var(maxsize);
1da177e4
LT
577 char *mesg = buf;
578 int len;
579 struct auth_domain *dom;
580 struct knfsd_fh fh;
581
87d26ea7
BF
582 if (size == 0)
583 return -EINVAL;
584
1da177e4
LT
585 if (buf[size-1] != '\n')
586 return -EINVAL;
587 buf[size-1] = 0;
588
589 dname = mesg;
590 len = qword_get(&mesg, dname, size);
54224f04
CL
591 if (len <= 0)
592 return -EINVAL;
1da177e4
LT
593
594 path = dname+len+1;
595 len = qword_get(&mesg, path, size);
54224f04
CL
596 if (len <= 0)
597 return -EINVAL;
1da177e4
LT
598
599 len = get_int(&mesg, &maxsize);
600 if (len)
601 return len;
602
603 if (maxsize < NFS_FHSIZE)
604 return -EINVAL;
605 if (maxsize > NFS3_FHSIZE)
606 maxsize = NFS3_FHSIZE;
607
608 if (qword_get(&mesg, mesg, size)>0)
609 return -EINVAL;
610
611 /* we have all the words, they are in buf.. */
612 dom = unix_domain_find(dname);
613 if (!dom)
614 return -ENOMEM;
615
616 len = exp_rootfh(dom, path, &fh, maxsize);
617 auth_domain_put(dom);
618 if (len)
619 return len;
620
54224f04
CL
621 mesg = buf;
622 len = SIMPLE_TRANSACTION_LIMIT;
1da177e4
LT
623 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
624 mesg[-1] = '\n';
625 return mesg - buf;
626}
627
262a0982
CL
628/**
629 * write_threads - Start NFSD, or report the current number of running threads
630 *
631 * Input:
632 * buf: ignored
633 * size: zero
634 * Output:
635 * On success: passed-in buffer filled with '\n'-terminated C
636 * string numeric value representing the number of
637 * running NFSD threads;
638 * return code is the size in bytes of the string
639 * On error: return code is zero
640 *
641 * OR
642 *
643 * Input:
644 * buf: C string containing an unsigned
645 * integer value representing the
646 * number of NFSD threads to start
647 * size: non-zero length of C string in @buf
648 * Output:
649 * On success: NFS service is started;
650 * passed-in buffer filled with '\n'-terminated C
651 * string numeric value representing the number of
652 * running NFSD threads;
653 * return code is the size in bytes of the string
654 * On error: return code is zero or a negative errno value
655 */
1da177e4
LT
656static ssize_t write_threads(struct file *file, char *buf, size_t size)
657{
1da177e4
LT
658 char *mesg = buf;
659 int rv;
660 if (size > 0) {
661 int newthreads;
662 rv = get_int(&mesg, &newthreads);
663 if (rv)
664 return rv;
9e074856 665 if (newthreads < 0)
1da177e4 666 return -EINVAL;
9e074856 667 rv = nfsd_svc(NFS_PORT, newthreads);
82e12fe9 668 if (rv < 0)
1da177e4 669 return rv;
82e12fe9
N
670 } else
671 rv = nfsd_nrthreads();
e06b6405 672
82e12fe9 673 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
1da177e4
LT
674}
675
262a0982
CL
676/**
677 * write_pool_threads - Set or report the current number of threads per pool
678 *
679 * Input:
680 * buf: ignored
681 * size: zero
682 *
683 * OR
684 *
685 * Input:
686 * buf: C string containing whitespace-
687 * separated unsigned integer values
688 * representing the number of NFSD
689 * threads to start in each pool
690 * size: non-zero length of C string in @buf
691 * Output:
692 * On success: passed-in buffer filled with '\n'-terminated C
693 * string containing integer values representing the
694 * number of NFSD threads in each pool;
695 * return code is the size in bytes of the string
696 * On error: return code is zero or a negative errno value
697 */
eed2965a
GB
698static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
699{
700 /* if size > 0, look for an array of number of threads per node
701 * and apply them then write out number of threads per node as reply
702 */
703 char *mesg = buf;
704 int i;
705 int rv;
706 int len;
bedbdd8b 707 int npools;
eed2965a
GB
708 int *nthreads;
709
bedbdd8b
NB
710 mutex_lock(&nfsd_mutex);
711 npools = nfsd_nrpools();
eed2965a
GB
712 if (npools == 0) {
713 /*
714 * NFS is shut down. The admin can start it by
715 * writing to the threads file but NOT the pool_threads
716 * file, sorry. Report zero threads.
717 */
bedbdd8b 718 mutex_unlock(&nfsd_mutex);
eed2965a
GB
719 strcpy(buf, "0\n");
720 return strlen(buf);
721 }
722
723 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
bedbdd8b 724 rv = -ENOMEM;
eed2965a 725 if (nthreads == NULL)
bedbdd8b 726 goto out_free;
eed2965a
GB
727
728 if (size > 0) {
729 for (i = 0; i < npools; i++) {
730 rv = get_int(&mesg, &nthreads[i]);
731 if (rv == -ENOENT)
732 break; /* fewer numbers than pools */
733 if (rv)
734 goto out_free; /* syntax error */
735 rv = -EINVAL;
736 if (nthreads[i] < 0)
737 goto out_free;
738 }
739 rv = nfsd_set_nrthreads(i, nthreads);
740 if (rv)
741 goto out_free;
742 }
743
744 rv = nfsd_get_nrthreads(npools, nthreads);
745 if (rv)
746 goto out_free;
747
748 mesg = buf;
749 size = SIMPLE_TRANSACTION_LIMIT;
750 for (i = 0; i < npools && size > 0; i++) {
751 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
752 len = strlen(mesg);
753 size -= len;
754 mesg += len;
755 }
413d63d7 756 rv = mesg - buf;
eed2965a
GB
757out_free:
758 kfree(nthreads);
bedbdd8b 759 mutex_unlock(&nfsd_mutex);
eed2965a
GB
760 return rv;
761}
762
3dd98a3b 763static ssize_t __write_versions(struct file *file, char *buf, size_t size)
70c3b76c 764{
70c3b76c 765 char *mesg = buf;
8daf220a 766 char *vers, *minorp, sign;
261758b5 767 int len, num, remaining;
8daf220a 768 unsigned minor;
70c3b76c
N
769 ssize_t tlen = 0;
770 char *sep;
771
772 if (size>0) {
773 if (nfsd_serv)
6658d3a7
N
774 /* Cannot change versions without updating
775 * nfsd_serv->sv_xdrsize, and reallocing
776 * rq_argp and rq_resp
777 */
70c3b76c
N
778 return -EBUSY;
779 if (buf[size-1] != '\n')
780 return -EINVAL;
781 buf[size-1] = 0;
782
783 vers = mesg;
784 len = qword_get(&mesg, vers, size);
785 if (len <= 0) return -EINVAL;
786 do {
787 sign = *vers;
788 if (sign == '+' || sign == '-')
8daf220a 789 num = simple_strtol((vers+1), &minorp, 0);
70c3b76c 790 else
8daf220a
BH
791 num = simple_strtol(vers, &minorp, 0);
792 if (*minorp == '.') {
793 if (num < 4)
794 return -EINVAL;
795 minor = simple_strtoul(minorp+1, NULL, 0);
796 if (minor == 0)
797 return -EINVAL;
798 if (nfsd_minorversion(minor, sign == '-' ?
799 NFSD_CLEAR : NFSD_SET) < 0)
800 return -EINVAL;
801 goto next;
802 }
70c3b76c
N
803 switch(num) {
804 case 2:
805 case 3:
806 case 4:
6658d3a7 807 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
70c3b76c
N
808 break;
809 default:
810 return -EINVAL;
811 }
8daf220a 812 next:
70c3b76c 813 vers += len + 1;
70c3b76c
N
814 } while ((len = qword_get(&mesg, vers, size)) > 0);
815 /* If all get turned off, turn them back on, as
816 * having no versions is BAD
817 */
6658d3a7 818 nfsd_reset_versions();
70c3b76c 819 }
261758b5 820
70c3b76c
N
821 /* Now write current state into reply buffer */
822 len = 0;
823 sep = "";
261758b5 824 remaining = SIMPLE_TRANSACTION_LIMIT;
70c3b76c 825 for (num=2 ; num <= 4 ; num++)
6658d3a7 826 if (nfsd_vers(num, NFSD_AVAIL)) {
261758b5 827 len = snprintf(buf, remaining, "%s%c%d", sep,
6658d3a7 828 nfsd_vers(num, NFSD_TEST)?'+':'-',
70c3b76c
N
829 num);
830 sep = " ";
261758b5
CL
831
832 if (len > remaining)
833 break;
834 remaining -= len;
835 buf += len;
836 tlen += len;
70c3b76c 837 }
8daf220a 838 if (nfsd_vers(4, NFSD_AVAIL))
261758b5
CL
839 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
840 minor++) {
841 len = snprintf(buf, remaining, " %c4.%u",
8daf220a
BH
842 (nfsd_vers(4, NFSD_TEST) &&
843 nfsd_minorversion(minor, NFSD_TEST)) ?
844 '+' : '-',
845 minor);
261758b5
CL
846
847 if (len > remaining)
848 break;
849 remaining -= len;
850 buf += len;
851 tlen += len;
852 }
853
854 len = snprintf(buf, remaining, "\n");
855 if (len > remaining)
856 return -EINVAL;
857 return tlen + len;
70c3b76c
N
858}
859
262a0982
CL
860/**
861 * write_versions - Set or report the available NFS protocol versions
862 *
863 * Input:
864 * buf: ignored
865 * size: zero
866 * Output:
867 * On success: passed-in buffer filled with '\n'-terminated C
868 * string containing positive or negative integer
869 * values representing the current status of each
870 * protocol version;
871 * return code is the size in bytes of the string
872 * On error: return code is zero or a negative errno value
873 *
874 * OR
875 *
876 * Input:
877 * buf: C string containing whitespace-
878 * separated positive or negative
879 * integer values representing NFS
880 * protocol versions to enable ("+n")
881 * or disable ("-n")
882 * size: non-zero length of C string in @buf
883 * Output:
884 * On success: status of zero or more protocol versions has
885 * been updated; passed-in buffer filled with
886 * '\n'-terminated C string containing positive
887 * or negative integer values representing the
888 * current status of each protocol version;
889 * return code is the size in bytes of the string
890 * On error: return code is zero or a negative errno value
891 */
3dd98a3b
JL
892static ssize_t write_versions(struct file *file, char *buf, size_t size)
893{
894 ssize_t rv;
895
896 mutex_lock(&nfsd_mutex);
897 rv = __write_versions(file, buf, size);
898 mutex_unlock(&nfsd_mutex);
899 return rv;
900}
901
0a5372d8
CL
902/*
903 * Zero-length write. Return a list of NFSD's current listener
904 * transports.
905 */
906static ssize_t __write_ports_names(char *buf)
907{
908 if (nfsd_serv == NULL)
909 return 0;
335c54bd 910 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
0a5372d8
CL
911}
912
0b7c2f6f
CL
913/*
914 * A single 'fd' number was written, in which case it must be for
915 * a socket of a supported family/protocol, and we use it as an
916 * nfsd listener.
917 */
918static ssize_t __write_ports_addfd(char *buf)
919{
920 char *mesg = buf;
921 int fd, err;
922
923 err = get_int(&mesg, &fd);
924 if (err != 0 || fd < 0)
925 return -EINVAL;
926
927 err = nfsd_create_serv();
928 if (err != 0)
929 return err;
930
ea068bad
CL
931 err = lockd_up();
932 if (err != 0)
933 goto out;
0b7c2f6f 934
bfba9ab4 935 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
ea068bad
CL
936 if (err < 0)
937 lockd_down();
0b7c2f6f 938
ea068bad
CL
939out:
940 /* Decrease the count, but don't shut down the service */
941 nfsd_serv->sv_nrthreads--;
942 return err;
0b7c2f6f
CL
943}
944
82d56591
CL
945/*
946 * A '-' followed by the 'name' of a socket means we close the socket.
947 */
948static ssize_t __write_ports_delfd(char *buf)
949{
950 char *toclose;
951 int len = 0;
952
953 toclose = kstrdup(buf + 1, GFP_KERNEL);
954 if (toclose == NULL)
955 return -ENOMEM;
956
957 if (nfsd_serv != NULL)
8435d34d
CL
958 len = svc_sock_names(nfsd_serv, buf,
959 SIMPLE_TRANSACTION_LIMIT, toclose);
82d56591
CL
960 if (len >= 0)
961 lockd_down();
962
963 kfree(toclose);
964 return len;
965}
966
4eb68c26
CL
967/*
968 * A transport listener is added by writing it's transport name and
969 * a port number.
970 */
971static ssize_t __write_ports_addxprt(char *buf)
972{
973 char transport[16];
974 int port, err;
975
976 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
977 return -EINVAL;
978
979 if (port < 1 || port > USHORT_MAX)
980 return -EINVAL;
981
982 err = nfsd_create_serv();
983 if (err != 0)
984 return err;
985
986 err = svc_create_xprt(nfsd_serv, transport,
987 PF_INET, port, SVC_SOCK_ANONYMOUS);
988 if (err < 0) {
989 /* Give a reasonable perror msg for bad transport string */
990 if (err == -ENOENT)
991 err = -EPROTONOSUPPORT;
992 return err;
993 }
994 return 0;
995}
996
4cd5dc75
CL
997/*
998 * A transport listener is removed by writing a "-", it's transport
999 * name, and it's port number.
1000 */
1001static ssize_t __write_ports_delxprt(char *buf)
1002{
1003 struct svc_xprt *xprt;
1004 char transport[16];
1005 int port;
1006
1007 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1008 return -EINVAL;
1009
1010 if (port < 1 || port > USHORT_MAX || nfsd_serv == NULL)
1011 return -EINVAL;
1012
1013 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1014 if (xprt == NULL)
1015 return -ENOTCONN;
1016
1017 svc_close_xprt(xprt);
1018 svc_xprt_put(xprt);
1019 return 0;
1020}
1021
bedbdd8b 1022static ssize_t __write_ports(struct file *file, char *buf, size_t size)
80212d59 1023{
0a5372d8
CL
1024 if (size == 0)
1025 return __write_ports_names(buf);
0b7c2f6f
CL
1026
1027 if (isdigit(buf[0]))
1028 return __write_ports_addfd(buf);
82d56591
CL
1029
1030 if (buf[0] == '-' && isdigit(buf[1]))
1031 return __write_ports_delfd(buf);
4eb68c26
CL
1032
1033 if (isalpha(buf[0]))
1034 return __write_ports_addxprt(buf);
4cd5dc75
CL
1035
1036 if (buf[0] == '-' && isalpha(buf[1]))
1037 return __write_ports_delxprt(buf);
1038
b41b66d6 1039 return -EINVAL;
80212d59
N
1040}
1041
262a0982
CL
1042/**
1043 * write_ports - Pass a socket file descriptor or transport name to listen on
1044 *
1045 * Input:
1046 * buf: ignored
1047 * size: zero
1048 * Output:
1049 * On success: passed-in buffer filled with a '\n'-terminated C
1050 * string containing a whitespace-separated list of
1051 * named NFSD listeners;
1052 * return code is the size in bytes of the string
1053 * On error: return code is zero or a negative errno value
1054 *
1055 * OR
1056 *
1057 * Input:
1058 * buf: C string containing an unsigned
1059 * integer value representing a bound
1060 * but unconnected socket that is to be
c71206a7
CL
1061 * used as an NFSD listener; listen(3)
1062 * must be called for a SOCK_STREAM
1063 * socket, otherwise it is ignored
262a0982
CL
1064 * size: non-zero length of C string in @buf
1065 * Output:
1066 * On success: NFS service is started;
1067 * passed-in buffer filled with a '\n'-terminated C
1068 * string containing a unique alphanumeric name of
1069 * the listener;
1070 * return code is the size in bytes of the string
1071 * On error: return code is a negative errno value
1072 *
1073 * OR
1074 *
1075 * Input:
1076 * buf: C string containing a "-" followed
1077 * by an integer value representing a
1078 * previously passed in socket file
1079 * descriptor
1080 * size: non-zero length of C string in @buf
1081 * Output:
1082 * On success: NFS service no longer listens on that socket;
1083 * passed-in buffer filled with a '\n'-terminated C
1084 * string containing a unique name of the listener;
1085 * return code is the size in bytes of the string
1086 * On error: return code is a negative errno value
1087 *
1088 * OR
1089 *
1090 * Input:
1091 * buf: C string containing a transport
1092 * name and an unsigned integer value
1093 * representing the port to listen on,
1094 * separated by whitespace
1095 * size: non-zero length of C string in @buf
1096 * Output:
1097 * On success: returns zero; NFS service is started
1098 * On error: return code is a negative errno value
1099 *
1100 * OR
1101 *
1102 * Input:
1103 * buf: C string containing a "-" followed
1104 * by a transport name and an unsigned
1105 * integer value representing the port
1106 * to listen on, separated by whitespace
1107 * size: non-zero length of C string in @buf
1108 * Output:
1109 * On success: returns zero; NFS service no longer listens
1110 * on that transport
1111 * On error: return code is a negative errno value
1112 */
bedbdd8b
NB
1113static ssize_t write_ports(struct file *file, char *buf, size_t size)
1114{
1115 ssize_t rv;
3dd98a3b 1116
bedbdd8b
NB
1117 mutex_lock(&nfsd_mutex);
1118 rv = __write_ports(file, buf, size);
1119 mutex_unlock(&nfsd_mutex);
1120 return rv;
1121}
1122
1123
596bbe53
N
1124int nfsd_max_blksize;
1125
262a0982
CL
1126/**
1127 * write_maxblksize - Set or report the current NFS blksize
1128 *
1129 * Input:
1130 * buf: ignored
1131 * size: zero
1132 *
1133 * OR
1134 *
1135 * Input:
1136 * buf: C string containing an unsigned
1137 * integer value representing the new
1138 * NFS blksize
1139 * size: non-zero length of C string in @buf
1140 * Output:
1141 * On success: passed-in buffer filled with '\n'-terminated C string
1142 * containing numeric value of the current NFS blksize
1143 * setting;
1144 * return code is the size in bytes of the string
1145 * On error: return code is zero or a negative errno value
1146 */
596bbe53
N
1147static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1148{
1149 char *mesg = buf;
1150 if (size > 0) {
1151 int bsize;
1152 int rv = get_int(&mesg, &bsize);
1153 if (rv)
1154 return rv;
1155 /* force bsize into allowed range and
1156 * required alignment.
1157 */
1158 if (bsize < 1024)
1159 bsize = 1024;
1160 if (bsize > NFSSVC_MAXBLKSIZE)
1161 bsize = NFSSVC_MAXBLKSIZE;
1162 bsize &= ~(1024-1);
bedbdd8b 1163 mutex_lock(&nfsd_mutex);
596bbe53 1164 if (nfsd_serv && nfsd_serv->sv_nrthreads) {
bedbdd8b 1165 mutex_unlock(&nfsd_mutex);
596bbe53
N
1166 return -EBUSY;
1167 }
1168 nfsd_max_blksize = bsize;
bedbdd8b 1169 mutex_unlock(&nfsd_mutex);
596bbe53 1170 }
e06b6405
CL
1171
1172 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1173 nfsd_max_blksize);
596bbe53
N
1174}
1175
70c3b76c 1176#ifdef CONFIG_NFSD_V4
1da177e4
LT
1177extern time_t nfs4_leasetime(void);
1178
3dd98a3b 1179static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
1da177e4
LT
1180{
1181 /* if size > 10 seconds, call
1182 * nfs4_reset_lease() then write out the new lease (seconds) as reply
1183 */
1184 char *mesg = buf;
3dd98a3b 1185 int rv, lease;
1da177e4
LT
1186
1187 if (size > 0) {
3dd98a3b
JL
1188 if (nfsd_serv)
1189 return -EBUSY;
1da177e4
LT
1190 rv = get_int(&mesg, &lease);
1191 if (rv)
1192 return rv;
1193 if (lease < 10 || lease > 3600)
1194 return -EINVAL;
1195 nfs4_reset_lease(lease);
1196 }
e06b6405
CL
1197
1198 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n",
1199 nfs4_lease_time());
1da177e4
LT
1200}
1201
262a0982
CL
1202/**
1203 * write_leasetime - Set or report the current NFSv4 lease time
1204 *
1205 * Input:
1206 * buf: ignored
1207 * size: zero
1208 *
1209 * OR
1210 *
1211 * Input:
1212 * buf: C string containing an unsigned
1213 * integer value representing the new
1214 * NFSv4 lease expiry time
1215 * size: non-zero length of C string in @buf
1216 * Output:
1217 * On success: passed-in buffer filled with '\n'-terminated C
1218 * string containing unsigned integer value of the
1219 * current lease expiry time;
1220 * return code is the size in bytes of the string
1221 * On error: return code is zero or a negative errno value
1222 */
3dd98a3b
JL
1223static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1224{
1225 ssize_t rv;
1226
1227 mutex_lock(&nfsd_mutex);
1228 rv = __write_leasetime(file, buf, size);
1229 mutex_unlock(&nfsd_mutex);
1230 return rv;
1231}
1232
1233extern char *nfs4_recoverydir(void);
1234
1235static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
0964a3d3
N
1236{
1237 char *mesg = buf;
1238 char *recdir;
1239 int len, status;
1240
3dd98a3b
JL
1241 if (size > 0) {
1242 if (nfsd_serv)
1243 return -EBUSY;
1244 if (size > PATH_MAX || buf[size-1] != '\n')
1245 return -EINVAL;
1246 buf[size-1] = 0;
0964a3d3 1247
3dd98a3b
JL
1248 recdir = mesg;
1249 len = qword_get(&mesg, recdir, size);
1250 if (len <= 0)
1251 return -EINVAL;
0964a3d3 1252
3dd98a3b
JL
1253 status = nfs4_reset_recoverydir(recdir);
1254 }
3d72ab8f
CL
1255
1256 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1257 nfs4_recoverydir());
0964a3d3 1258}
3dd98a3b 1259
262a0982
CL
1260/**
1261 * write_recoverydir - Set or report the pathname of the recovery directory
1262 *
1263 * Input:
1264 * buf: ignored
1265 * size: zero
1266 *
1267 * OR
1268 *
1269 * Input:
1270 * buf: C string containing the pathname
1271 * of the directory on a local file
1272 * system containing permanent NFSv4
1273 * recovery data
1274 * size: non-zero length of C string in @buf
1275 * Output:
1276 * On success: passed-in buffer filled with '\n'-terminated C string
1277 * containing the current recovery pathname setting;
1278 * return code is the size in bytes of the string
1279 * On error: return code is zero or a negative errno value
1280 */
3dd98a3b
JL
1281static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1282{
1283 ssize_t rv;
1284
1285 mutex_lock(&nfsd_mutex);
1286 rv = __write_recoverydir(file, buf, size);
1287 mutex_unlock(&nfsd_mutex);
1288 return rv;
1289}
1290
70c3b76c 1291#endif
0964a3d3 1292
1da177e4
LT
1293/*----------------------------------------------------------------------------*/
1294/*
1295 * populating the filesystem.
1296 */
1297
1298static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1299{
1300 static struct tree_descr nfsd_files[] = {
1301 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1302 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1303 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1304 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1305 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1306 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1307 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
1308 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
4373ea84
WC
1309 [NFSD_FO_UnlockIP] = {"unlock_ip",
1310 &transaction_ops, S_IWUSR|S_IRUSR},
17efa372
WC
1311 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1312 &transaction_ops, S_IWUSR|S_IRUSR},
1da177e4
LT
1313 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1314 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
eed2965a 1315 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
03cf6c9f 1316 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
70c3b76c 1317 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
80212d59 1318 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
596bbe53 1319 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1da177e4
LT
1320#ifdef CONFIG_NFSD_V4
1321 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
0964a3d3 1322 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1da177e4
LT
1323#endif
1324 /* last one */ {""}
1325 };
1326 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1327}
1328
454e2398
DH
1329static int nfsd_get_sb(struct file_system_type *fs_type,
1330 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1da177e4 1331{
454e2398 1332 return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
1da177e4
LT
1333}
1334
1335static struct file_system_type nfsd_fs_type = {
1336 .owner = THIS_MODULE,
1337 .name = "nfsd",
1338 .get_sb = nfsd_get_sb,
1339 .kill_sb = kill_litter_super,
1340};
1341
e331f606
BF
1342#ifdef CONFIG_PROC_FS
1343static int create_proc_exports_entry(void)
1344{
1345 struct proc_dir_entry *entry;
1346
1347 entry = proc_mkdir("fs/nfs", NULL);
1348 if (!entry)
1349 return -ENOMEM;
9ef2db26 1350 entry = proc_create("exports", 0, entry, &exports_operations);
e331f606
BF
1351 if (!entry)
1352 return -ENOMEM;
e331f606
BF
1353 return 0;
1354}
1355#else /* CONFIG_PROC_FS */
1356static int create_proc_exports_entry(void)
1357{
1358 return 0;
1359}
1360#endif
1361
1da177e4
LT
1362static int __init init_nfsd(void)
1363{
1364 int retval;
1365 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1366
e8ff2a84
BF
1367 retval = nfs4_state_init(); /* nfs4 locking state */
1368 if (retval)
1369 return retval;
1da177e4 1370 nfsd_stat_init(); /* Statistics */
d5c3428b
BF
1371 retval = nfsd_reply_cache_init();
1372 if (retval)
1373 goto out_free_stat;
dbf847ec
BF
1374 retval = nfsd_export_init();
1375 if (retval)
1376 goto out_free_cache;
1da177e4 1377 nfsd_lockd_init(); /* lockd->nfsd callbacks */
dbf847ec
BF
1378 retval = nfsd_idmap_init();
1379 if (retval)
1380 goto out_free_lockd;
e331f606
BF
1381 retval = create_proc_exports_entry();
1382 if (retval)
1383 goto out_free_idmap;
1da177e4 1384 retval = register_filesystem(&nfsd_fs_type);
26808d3f
BF
1385 if (retval)
1386 goto out_free_all;
1387 return 0;
1388out_free_all:
26808d3f
BF
1389 remove_proc_entry("fs/nfs/exports", NULL);
1390 remove_proc_entry("fs/nfs", NULL);
e331f606 1391out_free_idmap:
dbf847ec
BF
1392 nfsd_idmap_shutdown();
1393out_free_lockd:
26808d3f 1394 nfsd_lockd_shutdown();
e331f606 1395 nfsd_export_shutdown();
dbf847ec 1396out_free_cache:
e331f606 1397 nfsd_reply_cache_shutdown();
d5c3428b
BF
1398out_free_stat:
1399 nfsd_stat_shutdown();
26808d3f 1400 nfsd4_free_slabs();
1da177e4
LT
1401 return retval;
1402}
1403
1404static void __exit exit_nfsd(void)
1405{
1406 nfsd_export_shutdown();
d5c3428b 1407 nfsd_reply_cache_shutdown();
1da177e4
LT
1408 remove_proc_entry("fs/nfs/exports", NULL);
1409 remove_proc_entry("fs/nfs", NULL);
1410 nfsd_stat_shutdown();
1411 nfsd_lockd_shutdown();
1da177e4 1412 nfsd_idmap_shutdown();
e8ff2a84 1413 nfsd4_free_slabs();
1da177e4
LT
1414 unregister_filesystem(&nfsd_fs_type);
1415}
1416
1417MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1418MODULE_LICENSE("GPL");
1419module_init(init_nfsd)
1420module_exit(exit_nfsd)