2 * Syscall interface to knfsd.
4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 #include <linux/namei.h>
8 #include <linux/ctype.h>
10 #include <linux/nfsd_idmap.h>
11 #include <linux/sunrpc/svcsock.h>
12 #include <linux/nfsd/syscall.h>
13 #include <linux/lockd/lockd.h>
14 #include <linux/sunrpc/clnt.h>
20 * We have a single directory with 9 nodes in it.
43 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
44 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
53 * write() for these nodes.
55 static ssize_t write_svc(struct file *file, char *buf, size_t size);
56 static ssize_t write_add(struct file *file, char *buf, size_t size);
57 static ssize_t write_del(struct file *file, char *buf, size_t size);
58 static ssize_t write_export(struct file *file, char *buf, size_t size);
59 static ssize_t write_unexport(struct file *file, char *buf, size_t size);
60 static ssize_t write_getfd(struct file *file, char *buf, size_t size);
61 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
62 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
63 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
64 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
65 static ssize_t write_threads(struct file *file, char *buf, size_t size);
66 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
67 static ssize_t write_versions(struct file *file, char *buf, size_t size);
68 static ssize_t write_ports(struct file *file, char *buf, size_t size);
69 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
71 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
72 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
75 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
76 [NFSD_Svc] = write_svc,
77 [NFSD_Add] = write_add,
78 [NFSD_Del] = write_del,
79 [NFSD_Export] = write_export,
80 [NFSD_Unexport] = write_unexport,
81 [NFSD_Getfd] = write_getfd,
82 [NFSD_Getfs] = write_getfs,
83 [NFSD_Fh] = write_filehandle,
84 [NFSD_FO_UnlockIP] = write_unlock_ip,
85 [NFSD_FO_UnlockFS] = write_unlock_fs,
86 [NFSD_Threads] = write_threads,
87 [NFSD_Pool_Threads] = write_pool_threads,
88 [NFSD_Versions] = write_versions,
89 [NFSD_Ports] = write_ports,
90 [NFSD_MaxBlkSize] = write_maxblksize,
92 [NFSD_Leasetime] = write_leasetime,
93 [NFSD_RecoveryDir] = write_recoverydir,
97 static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
99 ino_t ino = file->f_path.dentry->d_inode->i_ino;
103 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
106 data = simple_transaction_get(file, buf, size);
108 return PTR_ERR(data);
110 rv = write_op[ino](file, data, size);
112 simple_transaction_set(file, rv);
118 static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
120 if (! file->private_data) {
121 /* An attempt to read a transaction file without writing
122 * causes a 0-byte write so that the file can return
125 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
129 return simple_transaction_read(file, buf, size, pos);
132 static const struct file_operations transaction_ops = {
133 .write = nfsctl_transaction_write,
134 .read = nfsctl_transaction_read,
135 .release = simple_transaction_release,
138 static int exports_open(struct inode *inode, struct file *file)
140 return seq_open(file, &nfs_exports_op);
143 static const struct file_operations exports_operations = {
144 .open = exports_open,
147 .release = seq_release,
148 .owner = THIS_MODULE,
151 static int export_features_show(struct seq_file *m, void *v)
153 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
157 static int export_features_open(struct inode *inode, struct file *file)
159 return single_open(file, export_features_show, NULL);
162 static struct file_operations export_features_operations = {
163 .open = export_features_open,
166 .release = single_release,
169 extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
170 extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
172 static const struct file_operations pool_stats_operations = {
173 .open = nfsd_pool_stats_open,
176 .release = nfsd_pool_stats_release,
177 .owner = THIS_MODULE,
180 /*----------------------------------------------------------------------------*/
182 * payload - write methods
186 * write_svc - Start kernel's NFSD server
188 * Deprecated. /proc/fs/nfsd/threads is preferred.
189 * Function remains to support old versions of nfs-utils.
192 * buf: struct nfsctl_svc
193 * svc_port: port number of this
195 * svc_nthreads: number of threads to start
196 * size: size in bytes of passed in nfsctl_svc
198 * On success: returns zero
199 * On error: return code is negative errno value
201 static ssize_t write_svc(struct file *file, char *buf, size_t size)
203 struct nfsctl_svc *data;
205 if (size < sizeof(*data))
207 data = (struct nfsctl_svc*) buf;
208 err = nfsd_svc(data->svc_port, data->svc_nthreads);
215 * write_add - Add or modify client entry in auth unix cache
217 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
218 * Function remains to support old versions of nfs-utils.
221 * buf: struct nfsctl_client
222 * cl_ident: '\0'-terminated C string
223 * containing domain name
225 * cl_naddr: no. of items in cl_addrlist
226 * cl_addrlist: array of client addresses
227 * cl_fhkeytype: ignored
228 * cl_fhkeylen: ignored
230 * size: size in bytes of passed in nfsctl_client
232 * On success: returns zero
233 * On error: return code is negative errno value
235 * Note: Only AF_INET client addresses are passed in, since
236 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
238 static ssize_t write_add(struct file *file, char *buf, size_t size)
240 struct nfsctl_client *data;
241 if (size < sizeof(*data))
243 data = (struct nfsctl_client *)buf;
244 return exp_addclient(data);
248 * write_del - Remove client from auth unix cache
250 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
251 * Function remains to support old versions of nfs-utils.
254 * buf: struct nfsctl_client
255 * cl_ident: '\0'-terminated C string
256 * containing domain name
259 * cl_addrlist: ignored
260 * cl_fhkeytype: ignored
261 * cl_fhkeylen: ignored
263 * size: size in bytes of passed in nfsctl_client
265 * On success: returns zero
266 * On error: return code is negative errno value
268 * Note: Only AF_INET client addresses are passed in, since
269 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
271 static ssize_t write_del(struct file *file, char *buf, size_t size)
273 struct nfsctl_client *data;
274 if (size < sizeof(*data))
276 data = (struct nfsctl_client *)buf;
277 return exp_delclient(data);
281 * write_export - Export part or all of a local file system
283 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
284 * Function remains to support old versions of nfs-utils.
287 * buf: struct nfsctl_export
288 * ex_client: '\0'-terminated C string
289 * containing domain name
290 * of client allowed to access
292 * ex_path: '\0'-terminated C string
293 * containing pathname of
294 * directory in local file system
295 * ex_dev: fsid to use for this export
297 * ex_flags: export flags for this export
298 * ex_anon_uid: UID to use for anonymous
300 * ex_anon_gid: GID to use for anonymous
302 * size: size in bytes of passed in nfsctl_export
304 * On success: returns zero
305 * On error: return code is negative errno value
307 static ssize_t write_export(struct file *file, char *buf, size_t size)
309 struct nfsctl_export *data;
310 if (size < sizeof(*data))
312 data = (struct nfsctl_export*)buf;
313 return exp_export(data);
317 * write_unexport - Unexport a previously exported file system
319 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
320 * Function remains to support old versions of nfs-utils.
323 * buf: struct nfsctl_export
324 * ex_client: '\0'-terminated C string
325 * containing domain name
326 * of client no longer allowed
327 * to access this export
328 * ex_path: '\0'-terminated C string
329 * containing pathname of
330 * directory in local file system
334 * ex_anon_uid: ignored
335 * ex_anon_gid: ignored
336 * size: size in bytes of passed in nfsctl_export
338 * On success: returns zero
339 * On error: return code is negative errno value
341 static ssize_t write_unexport(struct file *file, char *buf, size_t size)
343 struct nfsctl_export *data;
345 if (size < sizeof(*data))
347 data = (struct nfsctl_export*)buf;
348 return exp_unexport(data);
352 * write_getfs - Get a variable-length NFS file handle by path
354 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
355 * Function remains to support old versions of nfs-utils.
358 * buf: struct nfsctl_fsparm
359 * gd_addr: socket address of client
360 * gd_path: '\0'-terminated C string
361 * containing pathname of
362 * directory in local file system
363 * gd_maxlen: maximum size of returned file
365 * size: size in bytes of passed in nfsctl_fsparm
367 * On success: passed-in buffer filled with a knfsd_fh structure
368 * (a variable-length raw NFS file handle);
369 * return code is the size in bytes of the file handle
370 * On error: return code is negative errno value
372 * Note: Only AF_INET client addresses are passed in, since gd_addr
373 * is the same size as a struct sockaddr_in.
375 static ssize_t write_getfs(struct file *file, char *buf, size_t size)
377 struct nfsctl_fsparm *data;
378 struct sockaddr_in *sin;
379 struct auth_domain *clp;
381 struct knfsd_fh *res;
384 if (size < sizeof(*data))
386 data = (struct nfsctl_fsparm*)buf;
387 err = -EPROTONOSUPPORT;
388 if (data->gd_addr.sa_family != AF_INET)
390 sin = (struct sockaddr_in *)&data->gd_addr;
391 if (data->gd_maxlen > NFS3_FHSIZE)
392 data->gd_maxlen = NFS3_FHSIZE;
394 res = (struct knfsd_fh*)buf;
398 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
400 clp = auth_unix_lookup(&in6);
404 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
405 auth_domain_put(clp);
409 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
415 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
417 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
418 * Function remains to support old versions of nfs-utils.
421 * buf: struct nfsctl_fdparm
422 * gd_addr: socket address of client
423 * gd_path: '\0'-terminated C string
424 * containing pathname of
425 * directory in local file system
426 * gd_version: fdparm structure version
427 * size: size in bytes of passed in nfsctl_fdparm
429 * On success: passed-in buffer filled with nfsctl_res
430 * (a fixed-length raw NFS file handle);
431 * return code is the size in bytes of the file handle
432 * On error: return code is negative errno value
434 * Note: Only AF_INET client addresses are passed in, since gd_addr
435 * is the same size as a struct sockaddr_in.
437 static ssize_t write_getfd(struct file *file, char *buf, size_t size)
439 struct nfsctl_fdparm *data;
440 struct sockaddr_in *sin;
441 struct auth_domain *clp;
447 if (size < sizeof(*data))
449 data = (struct nfsctl_fdparm*)buf;
450 err = -EPROTONOSUPPORT;
451 if (data->gd_addr.sa_family != AF_INET)
454 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
458 sin = (struct sockaddr_in *)&data->gd_addr;
461 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
463 clp = auth_unix_lookup(&in6);
467 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
468 auth_domain_put(clp);
473 memset(res,0, NFS_FHSIZE);
474 memcpy(res, &fh.fh_base, fh.fh_size);
482 * write_unlock_ip - Release all locks used by a client
487 * buf: '\n'-terminated C string containing a
488 * presentation format IP address
489 * size: length of C string in @buf
491 * On success: returns zero if all specified locks were released;
492 * returns one if one or more locks were not released
493 * On error: return code is negative errno value
495 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
497 struct sockaddr_storage address;
498 struct sockaddr *sap = (struct sockaddr *)&address;
499 size_t salen = sizeof(address);
506 if (buf[size-1] != '\n')
510 if (qword_get(&buf, fo_path, size) < 0)
513 if (rpc_pton(fo_path, size, sap, salen) == 0)
516 return nlmsvc_unlock_all_by_ip(sap);
520 * write_unlock_fs - Release all locks on a local file system
525 * buf: '\n'-terminated C string containing the
526 * absolute pathname of a local file system
527 * size: length of C string in @buf
529 * On success: returns zero if all specified locks were released;
530 * returns one if one or more locks were not released
531 * On error: return code is negative errno value
533 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
543 if (buf[size-1] != '\n')
547 if (qword_get(&buf, fo_path, size) < 0)
550 error = kern_path(fo_path, 0, &path);
555 * XXX: Needs better sanity checking. Otherwise we could end up
556 * releasing locks on the wrong file system.
559 * 1. Does the path refer to a directory?
560 * 2. Is that directory a mount point, or
561 * 3. Is that directory the root of an exported file system?
563 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
570 * write_filehandle - Get a variable-length NFS file handle by path
572 * On input, the buffer contains a '\n'-terminated C string comprised of
573 * three alphanumeric words separated by whitespace. The string may
574 * contain escape sequences.
578 * domain: client domain name
579 * path: export pathname
580 * maxsize: numeric maximum size of
582 * size: length of C string in @buf
584 * On success: passed-in buffer filled with '\n'-terminated C
585 * string containing a ASCII hex text version
586 * of the NFS file handle;
587 * return code is the size in bytes of the string
588 * On error: return code is negative errno value
590 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
593 int uninitialized_var(maxsize);
596 struct auth_domain *dom;
602 if (buf[size-1] != '\n')
607 len = qword_get(&mesg, dname, size);
612 len = qword_get(&mesg, path, size);
616 len = get_int(&mesg, &maxsize);
620 if (maxsize < NFS_FHSIZE)
622 if (maxsize > NFS3_FHSIZE)
623 maxsize = NFS3_FHSIZE;
625 if (qword_get(&mesg, mesg, size)>0)
628 /* we have all the words, they are in buf.. */
629 dom = unix_domain_find(dname);
633 len = exp_rootfh(dom, path, &fh, maxsize);
634 auth_domain_put(dom);
639 len = SIMPLE_TRANSACTION_LIMIT;
640 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
646 * write_threads - Start NFSD, or report the current number of running threads
652 * On success: passed-in buffer filled with '\n'-terminated C
653 * string numeric value representing the number of
654 * running NFSD threads;
655 * return code is the size in bytes of the string
656 * On error: return code is zero
661 * buf: C string containing an unsigned
662 * integer value representing the
663 * number of NFSD threads to start
664 * size: non-zero length of C string in @buf
666 * On success: NFS service is started;
667 * passed-in buffer filled with '\n'-terminated C
668 * string numeric value representing the number of
669 * running NFSD threads;
670 * return code is the size in bytes of the string
671 * On error: return code is zero or a negative errno value
673 static ssize_t write_threads(struct file *file, char *buf, size_t size)
679 rv = get_int(&mesg, &newthreads);
684 rv = nfsd_svc(NFS_PORT, newthreads);
688 rv = nfsd_nrthreads();
690 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
694 * write_pool_threads - Set or report the current number of threads per pool
703 * buf: C string containing whitespace-
704 * separated unsigned integer values
705 * representing the number of NFSD
706 * threads to start in each pool
707 * size: non-zero length of C string in @buf
709 * On success: passed-in buffer filled with '\n'-terminated C
710 * string containing integer values representing the
711 * number of NFSD threads in each pool;
712 * return code is the size in bytes of the string
713 * On error: return code is zero or a negative errno value
715 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
717 /* if size > 0, look for an array of number of threads per node
718 * and apply them then write out number of threads per node as reply
727 mutex_lock(&nfsd_mutex);
728 npools = nfsd_nrpools();
731 * NFS is shut down. The admin can start it by
732 * writing to the threads file but NOT the pool_threads
733 * file, sorry. Report zero threads.
735 mutex_unlock(&nfsd_mutex);
740 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
742 if (nthreads == NULL)
746 for (i = 0; i < npools; i++) {
747 rv = get_int(&mesg, &nthreads[i]);
749 break; /* fewer numbers than pools */
751 goto out_free; /* syntax error */
756 rv = nfsd_set_nrthreads(i, nthreads);
761 rv = nfsd_get_nrthreads(npools, nthreads);
766 size = SIMPLE_TRANSACTION_LIMIT;
767 for (i = 0; i < npools && size > 0; i++) {
768 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
776 mutex_unlock(&nfsd_mutex);
780 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
783 char *vers, *minorp, sign;
784 int len, num, remaining;
791 /* Cannot change versions without updating
792 * nfsd_serv->sv_xdrsize, and reallocing
793 * rq_argp and rq_resp
796 if (buf[size-1] != '\n')
801 len = qword_get(&mesg, vers, size);
802 if (len <= 0) return -EINVAL;
805 if (sign == '+' || sign == '-')
806 num = simple_strtol((vers+1), &minorp, 0);
808 num = simple_strtol(vers, &minorp, 0);
809 if (*minorp == '.') {
812 minor = simple_strtoul(minorp+1, NULL, 0);
815 if (nfsd_minorversion(minor, sign == '-' ?
816 NFSD_CLEAR : NFSD_SET) < 0)
824 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
831 } while ((len = qword_get(&mesg, vers, size)) > 0);
832 /* If all get turned off, turn them back on, as
833 * having no versions is BAD
835 nfsd_reset_versions();
838 /* Now write current state into reply buffer */
841 remaining = SIMPLE_TRANSACTION_LIMIT;
842 for (num=2 ; num <= 4 ; num++)
843 if (nfsd_vers(num, NFSD_AVAIL)) {
844 len = snprintf(buf, remaining, "%s%c%d", sep,
845 nfsd_vers(num, NFSD_TEST)?'+':'-',
855 if (nfsd_vers(4, NFSD_AVAIL))
856 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
858 len = snprintf(buf, remaining, " %c4.%u",
859 (nfsd_vers(4, NFSD_TEST) &&
860 nfsd_minorversion(minor, NFSD_TEST)) ?
871 len = snprintf(buf, remaining, "\n");
878 * write_versions - Set or report the available NFS protocol versions
884 * On success: passed-in buffer filled with '\n'-terminated C
885 * string containing positive or negative integer
886 * values representing the current status of each
888 * return code is the size in bytes of the string
889 * On error: return code is zero or a negative errno value
894 * buf: C string containing whitespace-
895 * separated positive or negative
896 * integer values representing NFS
897 * protocol versions to enable ("+n")
899 * size: non-zero length of C string in @buf
901 * On success: status of zero or more protocol versions has
902 * been updated; passed-in buffer filled with
903 * '\n'-terminated C string containing positive
904 * or negative integer values representing the
905 * current status of each protocol version;
906 * return code is the size in bytes of the string
907 * On error: return code is zero or a negative errno value
909 static ssize_t write_versions(struct file *file, char *buf, size_t size)
913 mutex_lock(&nfsd_mutex);
914 rv = __write_versions(file, buf, size);
915 mutex_unlock(&nfsd_mutex);
920 * Zero-length write. Return a list of NFSD's current listener
923 static ssize_t __write_ports_names(char *buf)
925 if (nfsd_serv == NULL)
927 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
931 * A single 'fd' number was written, in which case it must be for
932 * a socket of a supported family/protocol, and we use it as an
935 static ssize_t __write_ports_addfd(char *buf)
940 err = get_int(&mesg, &fd);
941 if (err != 0 || fd < 0)
944 err = nfsd_create_serv();
952 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
957 /* Decrease the count, but don't shut down the service */
958 nfsd_serv->sv_nrthreads--;
963 * A '-' followed by the 'name' of a socket means we close the socket.
965 static ssize_t __write_ports_delfd(char *buf)
970 toclose = kstrdup(buf + 1, GFP_KERNEL);
974 if (nfsd_serv != NULL)
975 len = svc_sock_names(nfsd_serv, buf,
976 SIMPLE_TRANSACTION_LIMIT, toclose);
985 * A transport listener is added by writing it's transport name and
988 static ssize_t __write_ports_addxprt(char *buf)
993 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
996 if (port < 1 || port > USHORT_MAX)
999 err = nfsd_create_serv();
1003 err = svc_create_xprt(nfsd_serv, transport,
1004 PF_INET, port, SVC_SOCK_ANONYMOUS);
1006 /* Give a reasonable perror msg for bad transport string */
1008 err = -EPROTONOSUPPORT;
1015 * A transport listener is removed by writing a "-", it's transport
1016 * name, and it's port number.
1018 static ssize_t __write_ports_delxprt(char *buf)
1020 struct svc_xprt *xprt;
1024 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1027 if (port < 1 || port > USHORT_MAX || nfsd_serv == NULL)
1030 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1034 svc_close_xprt(xprt);
1039 static ssize_t __write_ports(struct file *file, char *buf, size_t size)
1042 return __write_ports_names(buf);
1044 if (isdigit(buf[0]))
1045 return __write_ports_addfd(buf);
1047 if (buf[0] == '-' && isdigit(buf[1]))
1048 return __write_ports_delfd(buf);
1050 if (isalpha(buf[0]))
1051 return __write_ports_addxprt(buf);
1053 if (buf[0] == '-' && isalpha(buf[1]))
1054 return __write_ports_delxprt(buf);
1060 * write_ports - Pass a socket file descriptor or transport name to listen on
1066 * On success: passed-in buffer filled with a '\n'-terminated C
1067 * string containing a whitespace-separated list of
1068 * named NFSD listeners;
1069 * return code is the size in bytes of the string
1070 * On error: return code is zero or a negative errno value
1075 * buf: C string containing an unsigned
1076 * integer value representing a bound
1077 * but unconnected socket that is to be
1078 * used as an NFSD listener; listen(3)
1079 * must be called for a SOCK_STREAM
1080 * socket, otherwise it is ignored
1081 * size: non-zero length of C string in @buf
1083 * On success: NFS service is started;
1084 * passed-in buffer filled with a '\n'-terminated C
1085 * string containing a unique alphanumeric name of
1087 * return code is the size in bytes of the string
1088 * On error: return code is a negative errno value
1093 * buf: C string containing a "-" followed
1094 * by an integer value representing a
1095 * previously passed in socket file
1097 * size: non-zero length of C string in @buf
1099 * On success: NFS service no longer listens on that socket;
1100 * passed-in buffer filled with a '\n'-terminated C
1101 * string containing a unique name of the listener;
1102 * return code is the size in bytes of the string
1103 * On error: return code is a negative errno value
1108 * buf: C string containing a transport
1109 * name and an unsigned integer value
1110 * representing the port to listen on,
1111 * separated by whitespace
1112 * size: non-zero length of C string in @buf
1114 * On success: returns zero; NFS service is started
1115 * On error: return code is a negative errno value
1120 * buf: C string containing a "-" followed
1121 * by a transport name and an unsigned
1122 * integer value representing the port
1123 * to listen on, separated by whitespace
1124 * size: non-zero length of C string in @buf
1126 * On success: returns zero; NFS service no longer listens
1128 * On error: return code is a negative errno value
1130 static ssize_t write_ports(struct file *file, char *buf, size_t size)
1134 mutex_lock(&nfsd_mutex);
1135 rv = __write_ports(file, buf, size);
1136 mutex_unlock(&nfsd_mutex);
1141 int nfsd_max_blksize;
1144 * write_maxblksize - Set or report the current NFS blksize
1153 * buf: C string containing an unsigned
1154 * integer value representing the new
1156 * size: non-zero length of C string in @buf
1158 * On success: passed-in buffer filled with '\n'-terminated C string
1159 * containing numeric value of the current NFS blksize
1161 * return code is the size in bytes of the string
1162 * On error: return code is zero or a negative errno value
1164 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1169 int rv = get_int(&mesg, &bsize);
1172 /* force bsize into allowed range and
1173 * required alignment.
1177 if (bsize > NFSSVC_MAXBLKSIZE)
1178 bsize = NFSSVC_MAXBLKSIZE;
1180 mutex_lock(&nfsd_mutex);
1181 if (nfsd_serv && nfsd_serv->sv_nrthreads) {
1182 mutex_unlock(&nfsd_mutex);
1185 nfsd_max_blksize = bsize;
1186 mutex_unlock(&nfsd_mutex);
1189 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1193 #ifdef CONFIG_NFSD_V4
1194 extern time_t nfs4_leasetime(void);
1196 static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
1198 /* if size > 10 seconds, call
1199 * nfs4_reset_lease() then write out the new lease (seconds) as reply
1207 rv = get_int(&mesg, &lease);
1210 if (lease < 10 || lease > 3600)
1212 nfs4_reset_lease(lease);
1215 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n",
1220 * write_leasetime - Set or report the current NFSv4 lease time
1229 * buf: C string containing an unsigned
1230 * integer value representing the new
1231 * NFSv4 lease expiry time
1232 * size: non-zero length of C string in @buf
1234 * On success: passed-in buffer filled with '\n'-terminated C
1235 * string containing unsigned integer value of the
1236 * current lease expiry time;
1237 * return code is the size in bytes of the string
1238 * On error: return code is zero or a negative errno value
1240 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1244 mutex_lock(&nfsd_mutex);
1245 rv = __write_leasetime(file, buf, size);
1246 mutex_unlock(&nfsd_mutex);
1250 extern char *nfs4_recoverydir(void);
1252 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
1261 if (size > PATH_MAX || buf[size-1] != '\n')
1266 len = qword_get(&mesg, recdir, size);
1270 status = nfs4_reset_recoverydir(recdir);
1273 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1274 nfs4_recoverydir());
1278 * write_recoverydir - Set or report the pathname of the recovery directory
1287 * buf: C string containing the pathname
1288 * of the directory on a local file
1289 * system containing permanent NFSv4
1291 * size: non-zero length of C string in @buf
1293 * On success: passed-in buffer filled with '\n'-terminated C string
1294 * containing the current recovery pathname setting;
1295 * return code is the size in bytes of the string
1296 * On error: return code is zero or a negative errno value
1298 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1302 mutex_lock(&nfsd_mutex);
1303 rv = __write_recoverydir(file, buf, size);
1304 mutex_unlock(&nfsd_mutex);
1310 /*----------------------------------------------------------------------------*/
1312 * populating the filesystem.
1315 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1317 static struct tree_descr nfsd_files[] = {
1318 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1319 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1320 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1321 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1322 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1323 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1324 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
1325 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
1326 [NFSD_Export_features] = {"export_features",
1327 &export_features_operations, S_IRUGO},
1328 [NFSD_FO_UnlockIP] = {"unlock_ip",
1329 &transaction_ops, S_IWUSR|S_IRUSR},
1330 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1331 &transaction_ops, S_IWUSR|S_IRUSR},
1332 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1333 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1334 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1335 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1336 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1337 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1338 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1339 #ifdef CONFIG_NFSD_V4
1340 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1341 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1345 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1348 static int nfsd_get_sb(struct file_system_type *fs_type,
1349 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1351 return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
1354 static struct file_system_type nfsd_fs_type = {
1355 .owner = THIS_MODULE,
1357 .get_sb = nfsd_get_sb,
1358 .kill_sb = kill_litter_super,
1361 #ifdef CONFIG_PROC_FS
1362 static int create_proc_exports_entry(void)
1364 struct proc_dir_entry *entry;
1366 entry = proc_mkdir("fs/nfs", NULL);
1369 entry = proc_create("exports", 0, entry, &exports_operations);
1374 #else /* CONFIG_PROC_FS */
1375 static int create_proc_exports_entry(void)
1381 static int __init init_nfsd(void)
1384 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1386 retval = nfs4_state_init(); /* nfs4 locking state */
1389 nfsd_stat_init(); /* Statistics */
1390 retval = nfsd_reply_cache_init();
1393 retval = nfsd_export_init();
1395 goto out_free_cache;
1396 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1397 retval = nfsd_idmap_init();
1399 goto out_free_lockd;
1400 retval = create_proc_exports_entry();
1402 goto out_free_idmap;
1403 retval = register_filesystem(&nfsd_fs_type);
1408 remove_proc_entry("fs/nfs/exports", NULL);
1409 remove_proc_entry("fs/nfs", NULL);
1411 nfsd_idmap_shutdown();
1413 nfsd_lockd_shutdown();
1414 nfsd_export_shutdown();
1416 nfsd_reply_cache_shutdown();
1418 nfsd_stat_shutdown();
1423 static void __exit exit_nfsd(void)
1425 nfsd_export_shutdown();
1426 nfsd_reply_cache_shutdown();
1427 remove_proc_entry("fs/nfs/exports", NULL);
1428 remove_proc_entry("fs/nfs", NULL);
1429 nfsd_stat_shutdown();
1430 nfsd_lockd_shutdown();
1431 nfsd_idmap_shutdown();
1433 unregister_filesystem(&nfsd_fs_type);
1436 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1437 MODULE_LICENSE("GPL");
1438 module_init(init_nfsd)
1439 module_exit(exit_nfsd)