2 * Syscall interface to knfsd.
4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 #include <linux/slab.h>
8 #include <linux/namei.h>
9 #include <linux/ctype.h>
11 #include <linux/nfsd_idmap.h>
12 #include <linux/sunrpc/svcsock.h>
13 #include <linux/nfsd/syscall.h>
14 #include <linux/lockd/lockd.h>
15 #include <linux/sunrpc/clnt.h>
21 * We have a single directory with 9 nodes in it.
25 #ifdef CONFIG_NFSD_DEPRECATED
46 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
47 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
57 * write() for these nodes.
59 #ifdef CONFIG_NFSD_DEPRECATED
60 static ssize_t write_svc(struct file *file, char *buf, size_t size);
61 static ssize_t write_add(struct file *file, char *buf, size_t size);
62 static ssize_t write_del(struct file *file, char *buf, size_t size);
63 static ssize_t write_export(struct file *file, char *buf, size_t size);
64 static ssize_t write_unexport(struct file *file, char *buf, size_t size);
65 static ssize_t write_getfd(struct file *file, char *buf, size_t size);
66 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
68 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
69 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
70 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
71 static ssize_t write_threads(struct file *file, char *buf, size_t size);
72 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
73 static ssize_t write_versions(struct file *file, char *buf, size_t size);
74 static ssize_t write_ports(struct file *file, char *buf, size_t size);
75 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
77 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
78 static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
79 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
82 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
83 #ifdef CONFIG_NFSD_DEPRECATED
84 [NFSD_Svc] = write_svc,
85 [NFSD_Add] = write_add,
86 [NFSD_Del] = write_del,
87 [NFSD_Export] = write_export,
88 [NFSD_Unexport] = write_unexport,
89 [NFSD_Getfd] = write_getfd,
90 [NFSD_Getfs] = write_getfs,
92 [NFSD_Fh] = write_filehandle,
93 [NFSD_FO_UnlockIP] = write_unlock_ip,
94 [NFSD_FO_UnlockFS] = write_unlock_fs,
95 [NFSD_Threads] = write_threads,
96 [NFSD_Pool_Threads] = write_pool_threads,
97 [NFSD_Versions] = write_versions,
98 [NFSD_Ports] = write_ports,
99 [NFSD_MaxBlkSize] = write_maxblksize,
100 #ifdef CONFIG_NFSD_V4
101 [NFSD_Leasetime] = write_leasetime,
102 [NFSD_Gracetime] = write_gracetime,
103 [NFSD_RecoveryDir] = write_recoverydir,
107 static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
109 ino_t ino = file->f_path.dentry->d_inode->i_ino;
113 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
116 data = simple_transaction_get(file, buf, size);
118 return PTR_ERR(data);
120 rv = write_op[ino](file, data, size);
122 simple_transaction_set(file, rv);
128 static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
131 if (file->f_dentry->d_name.name[0] == '.' && !warned) {
132 char name[sizeof(current->comm)];
134 "Warning: \"%s\" uses deprecated NFSD interface: %s."
135 " This will be removed in 2.6.40\n",
136 get_task_comm(name, current),
137 file->f_dentry->d_name.name);
140 if (! file->private_data) {
141 /* An attempt to read a transaction file without writing
142 * causes a 0-byte write so that the file can return
145 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
149 return simple_transaction_read(file, buf, size, pos);
152 static const struct file_operations transaction_ops = {
153 .write = nfsctl_transaction_write,
154 .read = nfsctl_transaction_read,
155 .release = simple_transaction_release,
158 static int exports_open(struct inode *inode, struct file *file)
160 return seq_open(file, &nfs_exports_op);
163 static const struct file_operations exports_operations = {
164 .open = exports_open,
167 .release = seq_release,
168 .owner = THIS_MODULE,
171 static int export_features_show(struct seq_file *m, void *v)
173 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
177 static int export_features_open(struct inode *inode, struct file *file)
179 return single_open(file, export_features_show, NULL);
182 static struct file_operations export_features_operations = {
183 .open = export_features_open,
186 .release = single_release,
189 extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
190 extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
192 static const struct file_operations pool_stats_operations = {
193 .open = nfsd_pool_stats_open,
196 .release = nfsd_pool_stats_release,
197 .owner = THIS_MODULE,
200 /*----------------------------------------------------------------------------*/
202 * payload - write methods
205 #ifdef CONFIG_NFSD_DEPRECATED
207 * write_svc - Start kernel's NFSD server
209 * Deprecated. /proc/fs/nfsd/threads is preferred.
210 * Function remains to support old versions of nfs-utils.
213 * buf: struct nfsctl_svc
214 * svc_port: port number of this
216 * svc_nthreads: number of threads to start
217 * size: size in bytes of passed in nfsctl_svc
219 * On success: returns zero
220 * On error: return code is negative errno value
222 static ssize_t write_svc(struct file *file, char *buf, size_t size)
224 struct nfsctl_svc *data;
226 if (size < sizeof(*data))
228 data = (struct nfsctl_svc*) buf;
229 err = nfsd_svc(data->svc_port, data->svc_nthreads);
236 * write_add - Add or modify client entry in auth unix cache
238 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
239 * Function remains to support old versions of nfs-utils.
242 * buf: struct nfsctl_client
243 * cl_ident: '\0'-terminated C string
244 * containing domain name
246 * cl_naddr: no. of items in cl_addrlist
247 * cl_addrlist: array of client addresses
248 * cl_fhkeytype: ignored
249 * cl_fhkeylen: ignored
251 * size: size in bytes of passed in nfsctl_client
253 * On success: returns zero
254 * On error: return code is negative errno value
256 * Note: Only AF_INET client addresses are passed in, since
257 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
259 static ssize_t write_add(struct file *file, char *buf, size_t size)
261 struct nfsctl_client *data;
262 if (size < sizeof(*data))
264 data = (struct nfsctl_client *)buf;
265 return exp_addclient(data);
269 * write_del - Remove client from auth unix cache
271 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
272 * Function remains to support old versions of nfs-utils.
275 * buf: struct nfsctl_client
276 * cl_ident: '\0'-terminated C string
277 * containing domain name
280 * cl_addrlist: ignored
281 * cl_fhkeytype: ignored
282 * cl_fhkeylen: ignored
284 * size: size in bytes of passed in nfsctl_client
286 * On success: returns zero
287 * On error: return code is negative errno value
289 * Note: Only AF_INET client addresses are passed in, since
290 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
292 static ssize_t write_del(struct file *file, char *buf, size_t size)
294 struct nfsctl_client *data;
295 if (size < sizeof(*data))
297 data = (struct nfsctl_client *)buf;
298 return exp_delclient(data);
302 * write_export - Export part or all of a local file system
304 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
305 * Function remains to support old versions of nfs-utils.
308 * buf: struct nfsctl_export
309 * ex_client: '\0'-terminated C string
310 * containing domain name
311 * of client allowed to access
313 * ex_path: '\0'-terminated C string
314 * containing pathname of
315 * directory in local file system
316 * ex_dev: fsid to use for this export
318 * ex_flags: export flags for this export
319 * ex_anon_uid: UID to use for anonymous
321 * ex_anon_gid: GID to use for anonymous
323 * size: size in bytes of passed in nfsctl_export
325 * On success: returns zero
326 * On error: return code is negative errno value
328 static ssize_t write_export(struct file *file, char *buf, size_t size)
330 struct nfsctl_export *data;
331 if (size < sizeof(*data))
333 data = (struct nfsctl_export*)buf;
334 return exp_export(data);
338 * write_unexport - Unexport a previously exported file system
340 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
341 * Function remains to support old versions of nfs-utils.
344 * buf: struct nfsctl_export
345 * ex_client: '\0'-terminated C string
346 * containing domain name
347 * of client no longer allowed
348 * to access this export
349 * ex_path: '\0'-terminated C string
350 * containing pathname of
351 * directory in local file system
355 * ex_anon_uid: ignored
356 * ex_anon_gid: ignored
357 * size: size in bytes of passed in nfsctl_export
359 * On success: returns zero
360 * On error: return code is negative errno value
362 static ssize_t write_unexport(struct file *file, char *buf, size_t size)
364 struct nfsctl_export *data;
366 if (size < sizeof(*data))
368 data = (struct nfsctl_export*)buf;
369 return exp_unexport(data);
373 * write_getfs - Get a variable-length NFS file handle by path
375 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
376 * Function remains to support old versions of nfs-utils.
379 * buf: struct nfsctl_fsparm
380 * gd_addr: socket address of client
381 * gd_path: '\0'-terminated C string
382 * containing pathname of
383 * directory in local file system
384 * gd_maxlen: maximum size of returned file
386 * size: size in bytes of passed in nfsctl_fsparm
388 * On success: passed-in buffer filled with a knfsd_fh structure
389 * (a variable-length raw NFS file handle);
390 * return code is the size in bytes of the file handle
391 * On error: return code is negative errno value
393 * Note: Only AF_INET client addresses are passed in, since gd_addr
394 * is the same size as a struct sockaddr_in.
396 static ssize_t write_getfs(struct file *file, char *buf, size_t size)
398 struct nfsctl_fsparm *data;
399 struct sockaddr_in *sin;
400 struct auth_domain *clp;
402 struct knfsd_fh *res;
405 if (size < sizeof(*data))
407 data = (struct nfsctl_fsparm*)buf;
408 err = -EPROTONOSUPPORT;
409 if (data->gd_addr.sa_family != AF_INET)
411 sin = (struct sockaddr_in *)&data->gd_addr;
412 if (data->gd_maxlen > NFS3_FHSIZE)
413 data->gd_maxlen = NFS3_FHSIZE;
415 res = (struct knfsd_fh*)buf;
419 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
421 clp = auth_unix_lookup(&in6);
425 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
426 auth_domain_put(clp);
430 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
436 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
438 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
439 * Function remains to support old versions of nfs-utils.
442 * buf: struct nfsctl_fdparm
443 * gd_addr: socket address of client
444 * gd_path: '\0'-terminated C string
445 * containing pathname of
446 * directory in local file system
447 * gd_version: fdparm structure version
448 * size: size in bytes of passed in nfsctl_fdparm
450 * On success: passed-in buffer filled with nfsctl_res
451 * (a fixed-length raw NFS file handle);
452 * return code is the size in bytes of the file handle
453 * On error: return code is negative errno value
455 * Note: Only AF_INET client addresses are passed in, since gd_addr
456 * is the same size as a struct sockaddr_in.
458 static ssize_t write_getfd(struct file *file, char *buf, size_t size)
460 struct nfsctl_fdparm *data;
461 struct sockaddr_in *sin;
462 struct auth_domain *clp;
468 if (size < sizeof(*data))
470 data = (struct nfsctl_fdparm*)buf;
471 err = -EPROTONOSUPPORT;
472 if (data->gd_addr.sa_family != AF_INET)
475 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
479 sin = (struct sockaddr_in *)&data->gd_addr;
482 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
484 clp = auth_unix_lookup(&in6);
488 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
489 auth_domain_put(clp);
494 memset(res,0, NFS_FHSIZE);
495 memcpy(res, &fh.fh_base, fh.fh_size);
501 #endif /* CONFIG_NFSD_DEPRECATED */
504 * write_unlock_ip - Release all locks used by a client
509 * buf: '\n'-terminated C string containing a
510 * presentation format IP address
511 * size: length of C string in @buf
513 * On success: returns zero if all specified locks were released;
514 * returns one if one or more locks were not released
515 * On error: return code is negative errno value
517 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
519 struct sockaddr_storage address;
520 struct sockaddr *sap = (struct sockaddr *)&address;
521 size_t salen = sizeof(address);
528 if (buf[size-1] != '\n')
532 if (qword_get(&buf, fo_path, size) < 0)
535 if (rpc_pton(fo_path, size, sap, salen) == 0)
538 return nlmsvc_unlock_all_by_ip(sap);
542 * write_unlock_fs - Release all locks on a local file system
547 * buf: '\n'-terminated C string containing the
548 * absolute pathname of a local file system
549 * size: length of C string in @buf
551 * On success: returns zero if all specified locks were released;
552 * returns one if one or more locks were not released
553 * On error: return code is negative errno value
555 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
565 if (buf[size-1] != '\n')
569 if (qword_get(&buf, fo_path, size) < 0)
572 error = kern_path(fo_path, 0, &path);
577 * XXX: Needs better sanity checking. Otherwise we could end up
578 * releasing locks on the wrong file system.
581 * 1. Does the path refer to a directory?
582 * 2. Is that directory a mount point, or
583 * 3. Is that directory the root of an exported file system?
585 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
592 * write_filehandle - Get a variable-length NFS file handle by path
594 * On input, the buffer contains a '\n'-terminated C string comprised of
595 * three alphanumeric words separated by whitespace. The string may
596 * contain escape sequences.
600 * domain: client domain name
601 * path: export pathname
602 * maxsize: numeric maximum size of
604 * size: length of C string in @buf
606 * On success: passed-in buffer filled with '\n'-terminated C
607 * string containing a ASCII hex text version
608 * of the NFS file handle;
609 * return code is the size in bytes of the string
610 * On error: return code is negative errno value
612 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
615 int uninitialized_var(maxsize);
618 struct auth_domain *dom;
624 if (buf[size-1] != '\n')
629 len = qword_get(&mesg, dname, size);
634 len = qword_get(&mesg, path, size);
638 len = get_int(&mesg, &maxsize);
642 if (maxsize < NFS_FHSIZE)
644 if (maxsize > NFS3_FHSIZE)
645 maxsize = NFS3_FHSIZE;
647 if (qword_get(&mesg, mesg, size)>0)
650 /* we have all the words, they are in buf.. */
651 dom = unix_domain_find(dname);
655 len = exp_rootfh(dom, path, &fh, maxsize);
656 auth_domain_put(dom);
661 len = SIMPLE_TRANSACTION_LIMIT;
662 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
668 * write_threads - Start NFSD, or report the current number of running threads
674 * On success: passed-in buffer filled with '\n'-terminated C
675 * string numeric value representing the number of
676 * running NFSD threads;
677 * return code is the size in bytes of the string
678 * On error: return code is zero
683 * buf: C string containing an unsigned
684 * integer value representing the
685 * number of NFSD threads to start
686 * size: non-zero length of C string in @buf
688 * On success: NFS service is started;
689 * passed-in buffer filled with '\n'-terminated C
690 * string numeric value representing the number of
691 * running NFSD threads;
692 * return code is the size in bytes of the string
693 * On error: return code is zero or a negative errno value
695 static ssize_t write_threads(struct file *file, char *buf, size_t size)
701 rv = get_int(&mesg, &newthreads);
706 rv = nfsd_svc(NFS_PORT, newthreads);
710 rv = nfsd_nrthreads();
712 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
716 * write_pool_threads - Set or report the current number of threads per pool
725 * buf: C string containing whitespace-
726 * separated unsigned integer values
727 * representing the number of NFSD
728 * threads to start in each pool
729 * size: non-zero length of C string in @buf
731 * On success: passed-in buffer filled with '\n'-terminated C
732 * string containing integer values representing the
733 * number of NFSD threads in each pool;
734 * return code is the size in bytes of the string
735 * On error: return code is zero or a negative errno value
737 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
739 /* if size > 0, look for an array of number of threads per node
740 * and apply them then write out number of threads per node as reply
749 mutex_lock(&nfsd_mutex);
750 npools = nfsd_nrpools();
753 * NFS is shut down. The admin can start it by
754 * writing to the threads file but NOT the pool_threads
755 * file, sorry. Report zero threads.
757 mutex_unlock(&nfsd_mutex);
762 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
764 if (nthreads == NULL)
768 for (i = 0; i < npools; i++) {
769 rv = get_int(&mesg, &nthreads[i]);
771 break; /* fewer numbers than pools */
773 goto out_free; /* syntax error */
778 rv = nfsd_set_nrthreads(i, nthreads);
783 rv = nfsd_get_nrthreads(npools, nthreads);
788 size = SIMPLE_TRANSACTION_LIMIT;
789 for (i = 0; i < npools && size > 0; i++) {
790 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
798 mutex_unlock(&nfsd_mutex);
802 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
805 char *vers, *minorp, sign;
806 int len, num, remaining;
813 /* Cannot change versions without updating
814 * nfsd_serv->sv_xdrsize, and reallocing
815 * rq_argp and rq_resp
818 if (buf[size-1] != '\n')
823 len = qword_get(&mesg, vers, size);
824 if (len <= 0) return -EINVAL;
827 if (sign == '+' || sign == '-')
828 num = simple_strtol((vers+1), &minorp, 0);
830 num = simple_strtol(vers, &minorp, 0);
831 if (*minorp == '.') {
834 minor = simple_strtoul(minorp+1, NULL, 0);
837 if (nfsd_minorversion(minor, sign == '-' ?
838 NFSD_CLEAR : NFSD_SET) < 0)
846 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
853 } while ((len = qword_get(&mesg, vers, size)) > 0);
854 /* If all get turned off, turn them back on, as
855 * having no versions is BAD
857 nfsd_reset_versions();
860 /* Now write current state into reply buffer */
863 remaining = SIMPLE_TRANSACTION_LIMIT;
864 for (num=2 ; num <= 4 ; num++)
865 if (nfsd_vers(num, NFSD_AVAIL)) {
866 len = snprintf(buf, remaining, "%s%c%d", sep,
867 nfsd_vers(num, NFSD_TEST)?'+':'-',
877 if (nfsd_vers(4, NFSD_AVAIL))
878 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
880 len = snprintf(buf, remaining, " %c4.%u",
881 (nfsd_vers(4, NFSD_TEST) &&
882 nfsd_minorversion(minor, NFSD_TEST)) ?
893 len = snprintf(buf, remaining, "\n");
900 * write_versions - Set or report the available NFS protocol versions
906 * On success: passed-in buffer filled with '\n'-terminated C
907 * string containing positive or negative integer
908 * values representing the current status of each
910 * return code is the size in bytes of the string
911 * On error: return code is zero or a negative errno value
916 * buf: C string containing whitespace-
917 * separated positive or negative
918 * integer values representing NFS
919 * protocol versions to enable ("+n")
921 * size: non-zero length of C string in @buf
923 * On success: status of zero or more protocol versions has
924 * been updated; passed-in buffer filled with
925 * '\n'-terminated C string containing positive
926 * or negative integer values representing the
927 * current status of each protocol version;
928 * return code is the size in bytes of the string
929 * On error: return code is zero or a negative errno value
931 static ssize_t write_versions(struct file *file, char *buf, size_t size)
935 mutex_lock(&nfsd_mutex);
936 rv = __write_versions(file, buf, size);
937 mutex_unlock(&nfsd_mutex);
942 * Zero-length write. Return a list of NFSD's current listener
945 static ssize_t __write_ports_names(char *buf)
947 if (nfsd_serv == NULL)
949 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
953 * A single 'fd' number was written, in which case it must be for
954 * a socket of a supported family/protocol, and we use it as an
957 static ssize_t __write_ports_addfd(char *buf)
962 err = get_int(&mesg, &fd);
963 if (err != 0 || fd < 0)
966 err = nfsd_create_serv();
970 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
972 svc_destroy(nfsd_serv);
976 /* Decrease the count, but don't shut down the service */
977 nfsd_serv->sv_nrthreads--;
982 * A '-' followed by the 'name' of a socket means we close the socket.
984 static ssize_t __write_ports_delfd(char *buf)
989 toclose = kstrdup(buf + 1, GFP_KERNEL);
993 if (nfsd_serv != NULL)
994 len = svc_sock_names(nfsd_serv, buf,
995 SIMPLE_TRANSACTION_LIMIT, toclose);
1001 * A transport listener is added by writing it's transport name and
1004 static ssize_t __write_ports_addxprt(char *buf)
1007 struct svc_xprt *xprt;
1010 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
1013 if (port < 1 || port > USHRT_MAX)
1016 err = nfsd_create_serv();
1020 err = svc_create_xprt(nfsd_serv, transport,
1021 PF_INET, port, SVC_SOCK_ANONYMOUS);
1025 err = svc_create_xprt(nfsd_serv, transport,
1026 PF_INET6, port, SVC_SOCK_ANONYMOUS);
1027 if (err < 0 && err != -EAFNOSUPPORT)
1030 /* Decrease the count, but don't shut down the service */
1031 nfsd_serv->sv_nrthreads--;
1034 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
1036 svc_close_xprt(xprt);
1040 svc_destroy(nfsd_serv);
1045 * A transport listener is removed by writing a "-", it's transport
1046 * name, and it's port number.
1048 static ssize_t __write_ports_delxprt(char *buf)
1050 struct svc_xprt *xprt;
1054 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1057 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
1060 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1064 svc_close_xprt(xprt);
1069 static ssize_t __write_ports(struct file *file, char *buf, size_t size)
1072 return __write_ports_names(buf);
1074 if (isdigit(buf[0]))
1075 return __write_ports_addfd(buf);
1077 if (buf[0] == '-' && isdigit(buf[1]))
1078 return __write_ports_delfd(buf);
1080 if (isalpha(buf[0]))
1081 return __write_ports_addxprt(buf);
1083 if (buf[0] == '-' && isalpha(buf[1]))
1084 return __write_ports_delxprt(buf);
1090 * write_ports - Pass a socket file descriptor or transport name to listen on
1096 * On success: passed-in buffer filled with a '\n'-terminated C
1097 * string containing a whitespace-separated list of
1098 * named NFSD listeners;
1099 * return code is the size in bytes of the string
1100 * On error: return code is zero or a negative errno value
1105 * buf: C string containing an unsigned
1106 * integer value representing a bound
1107 * but unconnected socket that is to be
1108 * used as an NFSD listener; listen(3)
1109 * must be called for a SOCK_STREAM
1110 * socket, otherwise it is ignored
1111 * size: non-zero length of C string in @buf
1113 * On success: NFS service is started;
1114 * passed-in buffer filled with a '\n'-terminated C
1115 * string containing a unique alphanumeric name of
1117 * return code is the size in bytes of the string
1118 * On error: return code is a negative errno value
1123 * buf: C string containing a "-" followed
1124 * by an integer value representing a
1125 * previously passed in socket file
1127 * size: non-zero length of C string in @buf
1129 * On success: NFS service no longer listens on that socket;
1130 * passed-in buffer filled with a '\n'-terminated C
1131 * string containing a unique name of the listener;
1132 * return code is the size in bytes of the string
1133 * On error: return code is a negative errno value
1138 * buf: C string containing a transport
1139 * name and an unsigned integer value
1140 * representing the port to listen on,
1141 * separated by whitespace
1142 * size: non-zero length of C string in @buf
1144 * On success: returns zero; NFS service is started
1145 * On error: return code is a negative errno value
1150 * buf: C string containing a "-" followed
1151 * by a transport name and an unsigned
1152 * integer value representing the port
1153 * to listen on, separated by whitespace
1154 * size: non-zero length of C string in @buf
1156 * On success: returns zero; NFS service no longer listens
1158 * On error: return code is a negative errno value
1160 static ssize_t write_ports(struct file *file, char *buf, size_t size)
1164 mutex_lock(&nfsd_mutex);
1165 rv = __write_ports(file, buf, size);
1166 mutex_unlock(&nfsd_mutex);
1171 int nfsd_max_blksize;
1174 * write_maxblksize - Set or report the current NFS blksize
1183 * buf: C string containing an unsigned
1184 * integer value representing the new
1186 * size: non-zero length of C string in @buf
1188 * On success: passed-in buffer filled with '\n'-terminated C string
1189 * containing numeric value of the current NFS blksize
1191 * return code is the size in bytes of the string
1192 * On error: return code is zero or a negative errno value
1194 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1199 int rv = get_int(&mesg, &bsize);
1202 /* force bsize into allowed range and
1203 * required alignment.
1207 if (bsize > NFSSVC_MAXBLKSIZE)
1208 bsize = NFSSVC_MAXBLKSIZE;
1210 mutex_lock(&nfsd_mutex);
1212 mutex_unlock(&nfsd_mutex);
1215 nfsd_max_blksize = bsize;
1216 mutex_unlock(&nfsd_mutex);
1219 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1223 #ifdef CONFIG_NFSD_V4
1224 static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1232 rv = get_int(&mesg, &i);
1236 * Some sanity checking. We don't have a reason for
1237 * these particular numbers, but problems with the
1239 * - Too short: the briefest network outage may
1240 * cause clients to lose all their locks. Also,
1241 * the frequent polling may be wasteful.
1242 * - Too long: do you really want reboot recovery
1243 * to take more than an hour? Or to make other
1244 * clients wait an hour before being able to
1245 * revoke a dead client's locks?
1247 if (i < 10 || i > 3600)
1252 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
1255 static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1259 mutex_lock(&nfsd_mutex);
1260 rv = __nfsd4_write_time(file, buf, size, time);
1261 mutex_unlock(&nfsd_mutex);
1266 * write_leasetime - Set or report the current NFSv4 lease time
1275 * buf: C string containing an unsigned
1276 * integer value representing the new
1277 * NFSv4 lease expiry time
1278 * size: non-zero length of C string in @buf
1280 * On success: passed-in buffer filled with '\n'-terminated C
1281 * string containing unsigned integer value of the
1282 * current lease expiry time;
1283 * return code is the size in bytes of the string
1284 * On error: return code is zero or a negative errno value
1286 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1288 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
1292 * write_gracetime - Set or report current NFSv4 grace period time
1294 * As above, but sets the time of the NFSv4 grace period.
1296 * Note this should never be set to less than the *previous*
1297 * lease-period time, but we don't try to enforce this. (In the common
1298 * case (a new boot), we don't know what the previous lease time was
1301 static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1303 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
1306 extern char *nfs4_recoverydir(void);
1308 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
1317 if (size > PATH_MAX || buf[size-1] != '\n')
1322 len = qword_get(&mesg, recdir, size);
1326 status = nfs4_reset_recoverydir(recdir);
1331 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1332 nfs4_recoverydir());
1336 * write_recoverydir - Set or report the pathname of the recovery directory
1345 * buf: C string containing the pathname
1346 * of the directory on a local file
1347 * system containing permanent NFSv4
1349 * size: non-zero length of C string in @buf
1351 * On success: passed-in buffer filled with '\n'-terminated C string
1352 * containing the current recovery pathname setting;
1353 * return code is the size in bytes of the string
1354 * On error: return code is zero or a negative errno value
1356 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1360 mutex_lock(&nfsd_mutex);
1361 rv = __write_recoverydir(file, buf, size);
1362 mutex_unlock(&nfsd_mutex);
1368 /*----------------------------------------------------------------------------*/
1370 * populating the filesystem.
1373 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1375 static struct tree_descr nfsd_files[] = {
1376 #ifdef CONFIG_NFSD_DEPRECATED
1377 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1378 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1379 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1380 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1381 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1382 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1383 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
1385 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
1386 [NFSD_Export_features] = {"export_features",
1387 &export_features_operations, S_IRUGO},
1388 [NFSD_FO_UnlockIP] = {"unlock_ip",
1389 &transaction_ops, S_IWUSR|S_IRUSR},
1390 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1391 &transaction_ops, S_IWUSR|S_IRUSR},
1392 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1393 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1394 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1395 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1396 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1397 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1398 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1399 #ifdef CONFIG_NFSD_V4
1400 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1401 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
1402 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1406 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1409 static int nfsd_get_sb(struct file_system_type *fs_type,
1410 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1412 return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
1415 static struct file_system_type nfsd_fs_type = {
1416 .owner = THIS_MODULE,
1418 .get_sb = nfsd_get_sb,
1419 .kill_sb = kill_litter_super,
1422 #ifdef CONFIG_PROC_FS
1423 static int create_proc_exports_entry(void)
1425 struct proc_dir_entry *entry;
1427 entry = proc_mkdir("fs/nfs", NULL);
1430 entry = proc_create("exports", 0, entry, &exports_operations);
1435 #else /* CONFIG_PROC_FS */
1436 static int create_proc_exports_entry(void)
1442 static int __init init_nfsd(void)
1445 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1447 retval = nfs4_state_init(); /* nfs4 locking state */
1450 nfsd_stat_init(); /* Statistics */
1451 retval = nfsd_reply_cache_init();
1454 retval = nfsd_export_init();
1456 goto out_free_cache;
1457 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1458 retval = nfsd_idmap_init();
1460 goto out_free_lockd;
1461 retval = create_proc_exports_entry();
1463 goto out_free_idmap;
1464 retval = register_filesystem(&nfsd_fs_type);
1469 remove_proc_entry("fs/nfs/exports", NULL);
1470 remove_proc_entry("fs/nfs", NULL);
1472 nfsd_idmap_shutdown();
1474 nfsd_lockd_shutdown();
1475 nfsd_export_shutdown();
1477 nfsd_reply_cache_shutdown();
1479 nfsd_stat_shutdown();
1484 static void __exit exit_nfsd(void)
1486 nfsd_export_shutdown();
1487 nfsd_reply_cache_shutdown();
1488 remove_proc_entry("fs/nfs/exports", NULL);
1489 remove_proc_entry("fs/nfs", NULL);
1490 nfsd_stat_shutdown();
1491 nfsd_lockd_shutdown();
1492 nfsd_idmap_shutdown();
1494 unregister_filesystem(&nfsd_fs_type);
1497 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1498 MODULE_LICENSE("GPL");
1499 module_init(init_nfsd)
1500 module_exit(exit_nfsd)