2 * linux/fs/nfsd/nfsctl.c
4 * Syscall interface to knfsd.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
9 #include <linux/namei.h>
10 #include <linux/ctype.h>
12 #include <linux/nfsd_idmap.h>
13 #include <linux/sunrpc/svcsock.h>
14 #include <linux/nfsd/syscall.h>
15 #include <linux/lockd/lockd.h>
16 #include <linux/sunrpc/clnt.h>
22 * We have a single directory with 9 nodes in it.
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
54 * write() for these nodes.
56 static ssize_t write_svc(struct file *file, char *buf, size_t size);
57 static ssize_t write_add(struct file *file, char *buf, size_t size);
58 static ssize_t write_del(struct file *file, char *buf, size_t size);
59 static ssize_t write_export(struct file *file, char *buf, size_t size);
60 static ssize_t write_unexport(struct file *file, char *buf, size_t size);
61 static ssize_t write_getfd(struct file *file, char *buf, size_t size);
62 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
63 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
64 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
65 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
66 static ssize_t write_threads(struct file *file, char *buf, size_t size);
67 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
68 static ssize_t write_versions(struct file *file, char *buf, size_t size);
69 static ssize_t write_ports(struct file *file, char *buf, size_t size);
70 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
72 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
73 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
76 static 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,
85 [NFSD_FO_UnlockIP] = write_unlock_ip,
86 [NFSD_FO_UnlockFS] = write_unlock_fs,
87 [NFSD_Threads] = write_threads,
88 [NFSD_Pool_Threads] = write_pool_threads,
89 [NFSD_Versions] = write_versions,
90 [NFSD_Ports] = write_ports,
91 [NFSD_MaxBlkSize] = write_maxblksize,
93 [NFSD_Leasetime] = write_leasetime,
94 [NFSD_RecoveryDir] = write_recoverydir,
98 static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
100 ino_t ino = file->f_path.dentry->d_inode->i_ino;
104 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
107 data = simple_transaction_get(file, buf, size);
109 return PTR_ERR(data);
111 rv = write_op[ino](file, data, size);
113 simple_transaction_set(file, rv);
119 static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
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
126 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
130 return simple_transaction_read(file, buf, size, pos);
133 static const struct file_operations transaction_ops = {
134 .write = nfsctl_transaction_write,
135 .read = nfsctl_transaction_read,
136 .release = simple_transaction_release,
139 static int exports_open(struct inode *inode, struct file *file)
141 return seq_open(file, &nfs_exports_op);
144 static const struct file_operations exports_operations = {
145 .open = exports_open,
148 .release = seq_release,
149 .owner = THIS_MODULE,
152 extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
153 extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
155 static const struct file_operations pool_stats_operations = {
156 .open = nfsd_pool_stats_open,
159 .release = nfsd_pool_stats_release,
160 .owner = THIS_MODULE,
163 /*----------------------------------------------------------------------------*/
165 * payload - write methods
169 * write_svc - Start kernel's NFSD server
171 * Deprecated. /proc/fs/nfsd/threads is preferred.
172 * Function remains to support old versions of nfs-utils.
175 * buf: struct nfsctl_svc
176 * svc_port: port number of this
178 * svc_nthreads: number of threads to start
179 * size: size in bytes of passed in nfsctl_svc
181 * On success: returns zero
182 * On error: return code is negative errno value
184 static ssize_t write_svc(struct file *file, char *buf, size_t size)
186 struct nfsctl_svc *data;
188 if (size < sizeof(*data))
190 data = (struct nfsctl_svc*) buf;
191 err = nfsd_svc(data->svc_port, data->svc_nthreads);
198 * write_add - Add or modify client entry in auth unix cache
200 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
201 * Function remains to support old versions of nfs-utils.
204 * buf: struct nfsctl_client
205 * cl_ident: '\0'-terminated C string
206 * containing domain name
208 * cl_naddr: no. of items in cl_addrlist
209 * cl_addrlist: array of client addresses
210 * cl_fhkeytype: ignored
211 * cl_fhkeylen: ignored
213 * size: size in bytes of passed in nfsctl_client
215 * On success: returns zero
216 * On error: return code is negative errno value
218 * Note: Only AF_INET client addresses are passed in, since
219 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
221 static ssize_t write_add(struct file *file, char *buf, size_t size)
223 struct nfsctl_client *data;
224 if (size < sizeof(*data))
226 data = (struct nfsctl_client *)buf;
227 return exp_addclient(data);
231 * write_del - Remove client from auth unix cache
233 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
234 * Function remains to support old versions of nfs-utils.
237 * buf: struct nfsctl_client
238 * cl_ident: '\0'-terminated C string
239 * containing domain name
242 * cl_addrlist: ignored
243 * cl_fhkeytype: ignored
244 * cl_fhkeylen: ignored
246 * size: size in bytes of passed in nfsctl_client
248 * On success: returns zero
249 * On error: return code is negative errno value
251 * Note: Only AF_INET client addresses are passed in, since
252 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
254 static ssize_t write_del(struct file *file, char *buf, size_t size)
256 struct nfsctl_client *data;
257 if (size < sizeof(*data))
259 data = (struct nfsctl_client *)buf;
260 return exp_delclient(data);
264 * write_export - Export part or all of a local file system
266 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
267 * Function remains to support old versions of nfs-utils.
270 * buf: struct nfsctl_export
271 * ex_client: '\0'-terminated C string
272 * containing domain name
273 * of client allowed to access
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
280 * ex_flags: export flags for this export
281 * ex_anon_uid: UID to use for anonymous
283 * ex_anon_gid: GID to use for anonymous
285 * size: size in bytes of passed in nfsctl_export
287 * On success: returns zero
288 * On error: return code is negative errno value
290 static ssize_t write_export(struct file *file, char *buf, size_t size)
292 struct nfsctl_export *data;
293 if (size < sizeof(*data))
295 data = (struct nfsctl_export*)buf;
296 return exp_export(data);
300 * write_unexport - Unexport a previously exported file system
302 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
303 * Function remains to support old versions of nfs-utils.
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
317 * ex_anon_uid: ignored
318 * ex_anon_gid: ignored
319 * size: size in bytes of passed in nfsctl_export
321 * On success: returns zero
322 * On error: return code is negative errno value
324 static ssize_t write_unexport(struct file *file, char *buf, size_t size)
326 struct nfsctl_export *data;
328 if (size < sizeof(*data))
330 data = (struct nfsctl_export*)buf;
331 return exp_unexport(data);
335 * write_getfs - Get a variable-length NFS file handle by path
337 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
338 * Function remains to support old versions of nfs-utils.
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
348 * size: size in bytes of passed in nfsctl_fsparm
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
355 * Note: Only AF_INET client addresses are passed in, since gd_addr
356 * is the same size as a struct sockaddr_in.
358 static ssize_t write_getfs(struct file *file, char *buf, size_t size)
360 struct nfsctl_fsparm *data;
361 struct sockaddr_in *sin;
362 struct auth_domain *clp;
364 struct knfsd_fh *res;
367 if (size < sizeof(*data))
369 data = (struct nfsctl_fsparm*)buf;
370 err = -EPROTONOSUPPORT;
371 if (data->gd_addr.sa_family != AF_INET)
373 sin = (struct sockaddr_in *)&data->gd_addr;
374 if (data->gd_maxlen > NFS3_FHSIZE)
375 data->gd_maxlen = NFS3_FHSIZE;
377 res = (struct knfsd_fh*)buf;
381 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
383 clp = auth_unix_lookup(&in6);
387 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
388 auth_domain_put(clp);
392 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
398 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
400 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
401 * Function remains to support old versions of nfs-utils.
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
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
417 * Note: Only AF_INET client addresses are passed in, since gd_addr
418 * is the same size as a struct sockaddr_in.
420 static ssize_t write_getfd(struct file *file, char *buf, size_t size)
422 struct nfsctl_fdparm *data;
423 struct sockaddr_in *sin;
424 struct auth_domain *clp;
430 if (size < sizeof(*data))
432 data = (struct nfsctl_fdparm*)buf;
433 err = -EPROTONOSUPPORT;
434 if (data->gd_addr.sa_family != AF_INET)
437 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
441 sin = (struct sockaddr_in *)&data->gd_addr;
444 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
446 clp = auth_unix_lookup(&in6);
450 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
451 auth_domain_put(clp);
456 memset(res,0, NFS_FHSIZE);
457 memcpy(res, &fh.fh_base, fh.fh_size);
465 * write_unlock_ip - Release all locks used by a client
470 * buf: '\n'-terminated C string containing a
471 * presentation format IP address
472 * size: length of C string in @buf
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
478 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
480 struct sockaddr_storage address;
481 struct sockaddr *sap = (struct sockaddr *)&address;
482 size_t salen = sizeof(address);
489 if (buf[size-1] != '\n')
493 if (qword_get(&buf, fo_path, size) < 0)
496 if (rpc_pton(fo_path, size, sap, salen) == 0)
499 return nlmsvc_unlock_all_by_ip(sap);
503 * write_unlock_fs - Release all locks on a local file system
508 * buf: '\n'-terminated C string containing the
509 * absolute pathname of a local file system
510 * size: length of C string in @buf
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
516 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
526 if (buf[size-1] != '\n')
530 if (qword_get(&buf, fo_path, size) < 0)
533 error = kern_path(fo_path, 0, &path);
538 * XXX: Needs better sanity checking. Otherwise we could end up
539 * releasing locks on the wrong file system.
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?
546 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
553 * write_filehandle - Get a variable-length NFS file handle by path
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.
561 * domain: client domain name
562 * path: export pathname
563 * maxsize: numeric maximum size of
565 * size: length of C string in @buf
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
573 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
576 int uninitialized_var(maxsize);
579 struct auth_domain *dom;
585 if (buf[size-1] != '\n')
590 len = qword_get(&mesg, dname, size);
595 len = qword_get(&mesg, path, size);
599 len = get_int(&mesg, &maxsize);
603 if (maxsize < NFS_FHSIZE)
605 if (maxsize > NFS3_FHSIZE)
606 maxsize = NFS3_FHSIZE;
608 if (qword_get(&mesg, mesg, size)>0)
611 /* we have all the words, they are in buf.. */
612 dom = unix_domain_find(dname);
616 len = exp_rootfh(dom, path, &fh, maxsize);
617 auth_domain_put(dom);
622 len = SIMPLE_TRANSACTION_LIMIT;
623 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
629 * write_threads - Start NFSD, or report the current number of running threads
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
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
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
656 static ssize_t write_threads(struct file *file, char *buf, size_t size)
662 rv = get_int(&mesg, &newthreads);
667 rv = nfsd_svc(NFS_PORT, newthreads);
671 rv = nfsd_nrthreads();
673 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
677 * write_pool_threads - Set or report the current number of threads per pool
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
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
698 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
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
710 mutex_lock(&nfsd_mutex);
711 npools = nfsd_nrpools();
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.
718 mutex_unlock(&nfsd_mutex);
723 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
725 if (nthreads == NULL)
729 for (i = 0; i < npools; i++) {
730 rv = get_int(&mesg, &nthreads[i]);
732 break; /* fewer numbers than pools */
734 goto out_free; /* syntax error */
739 rv = nfsd_set_nrthreads(i, nthreads);
744 rv = nfsd_get_nrthreads(npools, nthreads);
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' : ' '));
759 mutex_unlock(&nfsd_mutex);
763 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
766 char *vers, *minorp, sign;
767 int len, num, remaining;
774 /* Cannot change versions without updating
775 * nfsd_serv->sv_xdrsize, and reallocing
776 * rq_argp and rq_resp
779 if (buf[size-1] != '\n')
784 len = qword_get(&mesg, vers, size);
785 if (len <= 0) return -EINVAL;
788 if (sign == '+' || sign == '-')
789 num = simple_strtol((vers+1), &minorp, 0);
791 num = simple_strtol(vers, &minorp, 0);
792 if (*minorp == '.') {
795 minor = simple_strtoul(minorp+1, NULL, 0);
798 if (nfsd_minorversion(minor, sign == '-' ?
799 NFSD_CLEAR : NFSD_SET) < 0)
807 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
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
818 nfsd_reset_versions();
821 /* Now write current state into reply buffer */
824 remaining = SIMPLE_TRANSACTION_LIMIT;
825 for (num=2 ; num <= 4 ; num++)
826 if (nfsd_vers(num, NFSD_AVAIL)) {
827 len = snprintf(buf, remaining, "%s%c%d", sep,
828 nfsd_vers(num, NFSD_TEST)?'+':'-',
838 if (nfsd_vers(4, NFSD_AVAIL))
839 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
841 len = snprintf(buf, remaining, " %c4.%u",
842 (nfsd_vers(4, NFSD_TEST) &&
843 nfsd_minorversion(minor, NFSD_TEST)) ?
854 len = snprintf(buf, remaining, "\n");
861 * write_versions - Set or report the available NFS protocol versions
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
871 * return code is the size in bytes of the string
872 * On error: return code is zero or a negative errno value
877 * buf: C string containing whitespace-
878 * separated positive or negative
879 * integer values representing NFS
880 * protocol versions to enable ("+n")
882 * size: non-zero length of C string in @buf
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
892 static ssize_t write_versions(struct file *file, char *buf, size_t size)
896 mutex_lock(&nfsd_mutex);
897 rv = __write_versions(file, buf, size);
898 mutex_unlock(&nfsd_mutex);
903 * Zero-length write. Return a list of NFSD's current listener
906 static ssize_t __write_ports_names(char *buf)
908 if (nfsd_serv == NULL)
910 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
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
918 static ssize_t __write_ports_addfd(char *buf)
923 err = get_int(&mesg, &fd);
924 if (err != 0 || fd < 0)
927 err = nfsd_create_serv();
935 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
940 /* Decrease the count, but don't shut down the service */
941 nfsd_serv->sv_nrthreads--;
946 * A '-' followed by the 'name' of a socket means we close the socket.
948 static ssize_t __write_ports_delfd(char *buf)
953 toclose = kstrdup(buf + 1, GFP_KERNEL);
957 if (nfsd_serv != NULL)
958 len = svc_sock_names(nfsd_serv, buf,
959 SIMPLE_TRANSACTION_LIMIT, toclose);
968 * A transport listener is added by writing it's transport name and
971 static ssize_t __write_ports_addxprt(char *buf)
976 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
979 if (port < 1 || port > USHORT_MAX)
982 err = nfsd_create_serv();
986 err = svc_create_xprt(nfsd_serv, transport,
987 PF_INET, port, SVC_SOCK_ANONYMOUS);
989 /* Give a reasonable perror msg for bad transport string */
991 err = -EPROTONOSUPPORT;
998 * A transport listener is removed by writing a "-", it's transport
999 * name, and it's port number.
1001 static ssize_t __write_ports_delxprt(char *buf)
1003 struct svc_xprt *xprt;
1007 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1010 if (port < 1 || port > USHORT_MAX || nfsd_serv == NULL)
1013 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1017 svc_close_xprt(xprt);
1022 static ssize_t __write_ports(struct file *file, char *buf, size_t size)
1025 return __write_ports_names(buf);
1027 if (isdigit(buf[0]))
1028 return __write_ports_addfd(buf);
1030 if (buf[0] == '-' && isdigit(buf[1]))
1031 return __write_ports_delfd(buf);
1033 if (isalpha(buf[0]))
1034 return __write_ports_addxprt(buf);
1036 if (buf[0] == '-' && isalpha(buf[1]))
1037 return __write_ports_delxprt(buf);
1043 * write_ports - Pass a socket file descriptor or transport name to listen on
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
1058 * buf: C string containing an unsigned
1059 * integer value representing a bound
1060 * but unconnected socket that is to be
1061 * used as an NFSD listener; listen(3)
1062 * must be called for a SOCK_STREAM
1063 * socket, otherwise it is ignored
1064 * size: non-zero length of C string in @buf
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
1070 * return code is the size in bytes of the string
1071 * On error: return code is a negative errno value
1076 * buf: C string containing a "-" followed
1077 * by an integer value representing a
1078 * previously passed in socket file
1080 * size: non-zero length of C string in @buf
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
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
1097 * On success: returns zero; NFS service is started
1098 * On error: return code is a negative errno value
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
1109 * On success: returns zero; NFS service no longer listens
1111 * On error: return code is a negative errno value
1113 static ssize_t write_ports(struct file *file, char *buf, size_t size)
1117 mutex_lock(&nfsd_mutex);
1118 rv = __write_ports(file, buf, size);
1119 mutex_unlock(&nfsd_mutex);
1124 int nfsd_max_blksize;
1127 * write_maxblksize - Set or report the current NFS blksize
1136 * buf: C string containing an unsigned
1137 * integer value representing the new
1139 * size: non-zero length of C string in @buf
1141 * On success: passed-in buffer filled with '\n'-terminated C string
1142 * containing numeric value of the current NFS blksize
1144 * return code is the size in bytes of the string
1145 * On error: return code is zero or a negative errno value
1147 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1152 int rv = get_int(&mesg, &bsize);
1155 /* force bsize into allowed range and
1156 * required alignment.
1160 if (bsize > NFSSVC_MAXBLKSIZE)
1161 bsize = NFSSVC_MAXBLKSIZE;
1163 mutex_lock(&nfsd_mutex);
1164 if (nfsd_serv && nfsd_serv->sv_nrthreads) {
1165 mutex_unlock(&nfsd_mutex);
1168 nfsd_max_blksize = bsize;
1169 mutex_unlock(&nfsd_mutex);
1172 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1176 #ifdef CONFIG_NFSD_V4
1177 extern time_t nfs4_leasetime(void);
1179 static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
1181 /* if size > 10 seconds, call
1182 * nfs4_reset_lease() then write out the new lease (seconds) as reply
1190 rv = get_int(&mesg, &lease);
1193 if (lease < 10 || lease > 3600)
1195 nfs4_reset_lease(lease);
1198 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n",
1203 * write_leasetime - Set or report the current NFSv4 lease time
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
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
1223 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1227 mutex_lock(&nfsd_mutex);
1228 rv = __write_leasetime(file, buf, size);
1229 mutex_unlock(&nfsd_mutex);
1233 extern char *nfs4_recoverydir(void);
1235 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
1244 if (size > PATH_MAX || buf[size-1] != '\n')
1249 len = qword_get(&mesg, recdir, size);
1253 status = nfs4_reset_recoverydir(recdir);
1256 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1257 nfs4_recoverydir());
1261 * write_recoverydir - Set or report the pathname of the recovery directory
1270 * buf: C string containing the pathname
1271 * of the directory on a local file
1272 * system containing permanent NFSv4
1274 * size: non-zero length of C string in @buf
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
1281 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1285 mutex_lock(&nfsd_mutex);
1286 rv = __write_recoverydir(file, buf, size);
1287 mutex_unlock(&nfsd_mutex);
1293 /*----------------------------------------------------------------------------*/
1295 * populating the filesystem.
1298 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
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},
1309 [NFSD_FO_UnlockIP] = {"unlock_ip",
1310 &transaction_ops, S_IWUSR|S_IRUSR},
1311 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1312 &transaction_ops, S_IWUSR|S_IRUSR},
1313 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1314 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1315 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1316 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1317 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1318 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1319 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1320 #ifdef CONFIG_NFSD_V4
1321 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1322 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1326 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1329 static int nfsd_get_sb(struct file_system_type *fs_type,
1330 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1332 return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
1335 static struct file_system_type nfsd_fs_type = {
1336 .owner = THIS_MODULE,
1338 .get_sb = nfsd_get_sb,
1339 .kill_sb = kill_litter_super,
1342 #ifdef CONFIG_PROC_FS
1343 static int create_proc_exports_entry(void)
1345 struct proc_dir_entry *entry;
1347 entry = proc_mkdir("fs/nfs", NULL);
1350 entry = proc_create("exports", 0, entry, &exports_operations);
1355 #else /* CONFIG_PROC_FS */
1356 static int create_proc_exports_entry(void)
1362 static int __init init_nfsd(void)
1365 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1367 retval = nfs4_state_init(); /* nfs4 locking state */
1370 nfsd_stat_init(); /* Statistics */
1371 retval = nfsd_reply_cache_init();
1374 retval = nfsd_export_init();
1376 goto out_free_cache;
1377 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1378 retval = nfsd_idmap_init();
1380 goto out_free_lockd;
1381 retval = create_proc_exports_entry();
1383 goto out_free_idmap;
1384 retval = register_filesystem(&nfsd_fs_type);
1389 remove_proc_entry("fs/nfs/exports", NULL);
1390 remove_proc_entry("fs/nfs", NULL);
1392 nfsd_idmap_shutdown();
1394 nfsd_lockd_shutdown();
1395 nfsd_export_shutdown();
1397 nfsd_reply_cache_shutdown();
1399 nfsd_stat_shutdown();
1404 static void __exit exit_nfsd(void)
1406 nfsd_export_shutdown();
1407 nfsd_reply_cache_shutdown();
1408 remove_proc_entry("fs/nfs/exports", NULL);
1409 remove_proc_entry("fs/nfs", NULL);
1410 nfsd_stat_shutdown();
1411 nfsd_lockd_shutdown();
1412 nfsd_idmap_shutdown();
1414 unregister_filesystem(&nfsd_fs_type);
1417 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1418 MODULE_LICENSE("GPL");
1419 module_init(init_nfsd)
1420 module_exit(exit_nfsd)