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) {
133 "Warning: \"%s\" uses deprecated NFSD interface: %s."
134 " This will be removed in 2.6.40\n",
135 current->comm, file->f_dentry->d_name.name);
138 if (! file->private_data) {
139 /* An attempt to read a transaction file without writing
140 * causes a 0-byte write so that the file can return
143 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
147 return simple_transaction_read(file, buf, size, pos);
150 static const struct file_operations transaction_ops = {
151 .write = nfsctl_transaction_write,
152 .read = nfsctl_transaction_read,
153 .release = simple_transaction_release,
156 static int exports_open(struct inode *inode, struct file *file)
158 return seq_open(file, &nfs_exports_op);
161 static const struct file_operations exports_operations = {
162 .open = exports_open,
165 .release = seq_release,
166 .owner = THIS_MODULE,
169 static int export_features_show(struct seq_file *m, void *v)
171 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
175 static int export_features_open(struct inode *inode, struct file *file)
177 return single_open(file, export_features_show, NULL);
180 static struct file_operations export_features_operations = {
181 .open = export_features_open,
184 .release = single_release,
187 extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
188 extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
190 static const struct file_operations pool_stats_operations = {
191 .open = nfsd_pool_stats_open,
194 .release = nfsd_pool_stats_release,
195 .owner = THIS_MODULE,
198 /*----------------------------------------------------------------------------*/
200 * payload - write methods
203 #ifdef CONFIG_NFSD_DEPRECATED
205 * write_svc - Start kernel's NFSD server
207 * Deprecated. /proc/fs/nfsd/threads is preferred.
208 * Function remains to support old versions of nfs-utils.
211 * buf: struct nfsctl_svc
212 * svc_port: port number of this
214 * svc_nthreads: number of threads to start
215 * size: size in bytes of passed in nfsctl_svc
217 * On success: returns zero
218 * On error: return code is negative errno value
220 static ssize_t write_svc(struct file *file, char *buf, size_t size)
222 struct nfsctl_svc *data;
224 if (size < sizeof(*data))
226 data = (struct nfsctl_svc*) buf;
227 err = nfsd_svc(data->svc_port, data->svc_nthreads);
234 * write_add - Add or modify client entry in auth unix cache
236 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
237 * Function remains to support old versions of nfs-utils.
240 * buf: struct nfsctl_client
241 * cl_ident: '\0'-terminated C string
242 * containing domain name
244 * cl_naddr: no. of items in cl_addrlist
245 * cl_addrlist: array of client addresses
246 * cl_fhkeytype: ignored
247 * cl_fhkeylen: ignored
249 * size: size in bytes of passed in nfsctl_client
251 * On success: returns zero
252 * On error: return code is negative errno value
254 * Note: Only AF_INET client addresses are passed in, since
255 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
257 static ssize_t write_add(struct file *file, char *buf, size_t size)
259 struct nfsctl_client *data;
260 if (size < sizeof(*data))
262 data = (struct nfsctl_client *)buf;
263 return exp_addclient(data);
267 * write_del - Remove client from auth unix cache
269 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
270 * Function remains to support old versions of nfs-utils.
273 * buf: struct nfsctl_client
274 * cl_ident: '\0'-terminated C string
275 * containing domain name
278 * cl_addrlist: ignored
279 * cl_fhkeytype: ignored
280 * cl_fhkeylen: ignored
282 * size: size in bytes of passed in nfsctl_client
284 * On success: returns zero
285 * On error: return code is negative errno value
287 * Note: Only AF_INET client addresses are passed in, since
288 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
290 static ssize_t write_del(struct file *file, char *buf, size_t size)
292 struct nfsctl_client *data;
293 if (size < sizeof(*data))
295 data = (struct nfsctl_client *)buf;
296 return exp_delclient(data);
300 * write_export - Export part or all of a local 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 allowed to access
311 * ex_path: '\0'-terminated C string
312 * containing pathname of
313 * directory in local file system
314 * ex_dev: fsid to use for this export
316 * ex_flags: export flags for this export
317 * ex_anon_uid: UID to use for anonymous
319 * ex_anon_gid: GID to use for anonymous
321 * size: size in bytes of passed in nfsctl_export
323 * On success: returns zero
324 * On error: return code is negative errno value
326 static ssize_t write_export(struct file *file, char *buf, size_t size)
328 struct nfsctl_export *data;
329 if (size < sizeof(*data))
331 data = (struct nfsctl_export*)buf;
332 return exp_export(data);
336 * write_unexport - Unexport a previously exported file system
338 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
339 * Function remains to support old versions of nfs-utils.
342 * buf: struct nfsctl_export
343 * ex_client: '\0'-terminated C string
344 * containing domain name
345 * of client no longer allowed
346 * to access this export
347 * ex_path: '\0'-terminated C string
348 * containing pathname of
349 * directory in local file system
353 * ex_anon_uid: ignored
354 * ex_anon_gid: ignored
355 * size: size in bytes of passed in nfsctl_export
357 * On success: returns zero
358 * On error: return code is negative errno value
360 static ssize_t write_unexport(struct file *file, char *buf, size_t size)
362 struct nfsctl_export *data;
364 if (size < sizeof(*data))
366 data = (struct nfsctl_export*)buf;
367 return exp_unexport(data);
371 * write_getfs - Get a variable-length NFS file handle by path
373 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
374 * Function remains to support old versions of nfs-utils.
377 * buf: struct nfsctl_fsparm
378 * gd_addr: socket address of client
379 * gd_path: '\0'-terminated C string
380 * containing pathname of
381 * directory in local file system
382 * gd_maxlen: maximum size of returned file
384 * size: size in bytes of passed in nfsctl_fsparm
386 * On success: passed-in buffer filled with a knfsd_fh structure
387 * (a variable-length raw NFS file handle);
388 * return code is the size in bytes of the file handle
389 * On error: return code is negative errno value
391 * Note: Only AF_INET client addresses are passed in, since gd_addr
392 * is the same size as a struct sockaddr_in.
394 static ssize_t write_getfs(struct file *file, char *buf, size_t size)
396 struct nfsctl_fsparm *data;
397 struct sockaddr_in *sin;
398 struct auth_domain *clp;
400 struct knfsd_fh *res;
403 if (size < sizeof(*data))
405 data = (struct nfsctl_fsparm*)buf;
406 err = -EPROTONOSUPPORT;
407 if (data->gd_addr.sa_family != AF_INET)
409 sin = (struct sockaddr_in *)&data->gd_addr;
410 if (data->gd_maxlen > NFS3_FHSIZE)
411 data->gd_maxlen = NFS3_FHSIZE;
413 res = (struct knfsd_fh*)buf;
417 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
419 clp = auth_unix_lookup(&init_net, &in6);
423 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
424 auth_domain_put(clp);
428 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
434 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
436 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
437 * Function remains to support old versions of nfs-utils.
440 * buf: struct nfsctl_fdparm
441 * gd_addr: socket address of client
442 * gd_path: '\0'-terminated C string
443 * containing pathname of
444 * directory in local file system
445 * gd_version: fdparm structure version
446 * size: size in bytes of passed in nfsctl_fdparm
448 * On success: passed-in buffer filled with nfsctl_res
449 * (a fixed-length raw NFS file handle);
450 * return code is the size in bytes of the file handle
451 * On error: return code is negative errno value
453 * Note: Only AF_INET client addresses are passed in, since gd_addr
454 * is the same size as a struct sockaddr_in.
456 static ssize_t write_getfd(struct file *file, char *buf, size_t size)
458 struct nfsctl_fdparm *data;
459 struct sockaddr_in *sin;
460 struct auth_domain *clp;
466 if (size < sizeof(*data))
468 data = (struct nfsctl_fdparm*)buf;
469 err = -EPROTONOSUPPORT;
470 if (data->gd_addr.sa_family != AF_INET)
473 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
477 sin = (struct sockaddr_in *)&data->gd_addr;
480 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
482 clp = auth_unix_lookup(&init_net, &in6);
486 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
487 auth_domain_put(clp);
492 memset(res,0, NFS_FHSIZE);
493 memcpy(res, &fh.fh_base, fh.fh_size);
499 #endif /* CONFIG_NFSD_DEPRECATED */
502 * write_unlock_ip - Release all locks used by a client
507 * buf: '\n'-terminated C string containing a
508 * presentation format IP address
509 * size: length of C string in @buf
511 * On success: returns zero if all specified locks were released;
512 * returns one if one or more locks were not released
513 * On error: return code is negative errno value
515 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
517 struct sockaddr_storage address;
518 struct sockaddr *sap = (struct sockaddr *)&address;
519 size_t salen = sizeof(address);
526 if (buf[size-1] != '\n')
530 if (qword_get(&buf, fo_path, size) < 0)
533 if (rpc_pton(fo_path, size, sap, salen) == 0)
536 return nlmsvc_unlock_all_by_ip(sap);
540 * write_unlock_fs - Release all locks on a local file system
545 * buf: '\n'-terminated C string containing the
546 * absolute pathname of a local file system
547 * size: length of C string in @buf
549 * On success: returns zero if all specified locks were released;
550 * returns one if one or more locks were not released
551 * On error: return code is negative errno value
553 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
563 if (buf[size-1] != '\n')
567 if (qword_get(&buf, fo_path, size) < 0)
570 error = kern_path(fo_path, 0, &path);
575 * XXX: Needs better sanity checking. Otherwise we could end up
576 * releasing locks on the wrong file system.
579 * 1. Does the path refer to a directory?
580 * 2. Is that directory a mount point, or
581 * 3. Is that directory the root of an exported file system?
583 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
590 * write_filehandle - Get a variable-length NFS file handle by path
592 * On input, the buffer contains a '\n'-terminated C string comprised of
593 * three alphanumeric words separated by whitespace. The string may
594 * contain escape sequences.
598 * domain: client domain name
599 * path: export pathname
600 * maxsize: numeric maximum size of
602 * size: length of C string in @buf
604 * On success: passed-in buffer filled with '\n'-terminated C
605 * string containing a ASCII hex text version
606 * of the NFS file handle;
607 * return code is the size in bytes of the string
608 * On error: return code is negative errno value
610 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
613 int uninitialized_var(maxsize);
616 struct auth_domain *dom;
622 if (buf[size-1] != '\n')
627 len = qword_get(&mesg, dname, size);
632 len = qword_get(&mesg, path, size);
636 len = get_int(&mesg, &maxsize);
640 if (maxsize < NFS_FHSIZE)
642 if (maxsize > NFS3_FHSIZE)
643 maxsize = NFS3_FHSIZE;
645 if (qword_get(&mesg, mesg, size)>0)
648 /* we have all the words, they are in buf.. */
649 dom = unix_domain_find(dname);
653 len = exp_rootfh(dom, path, &fh, maxsize);
654 auth_domain_put(dom);
659 len = SIMPLE_TRANSACTION_LIMIT;
660 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
666 * write_threads - Start NFSD, or report the current number of running threads
672 * On success: passed-in buffer filled with '\n'-terminated C
673 * string numeric value representing the number of
674 * running NFSD threads;
675 * return code is the size in bytes of the string
676 * On error: return code is zero
681 * buf: C string containing an unsigned
682 * integer value representing the
683 * number of NFSD threads to start
684 * size: non-zero length of C string in @buf
686 * On success: NFS service is started;
687 * passed-in buffer filled with '\n'-terminated C
688 * string numeric value representing the number of
689 * running NFSD threads;
690 * return code is the size in bytes of the string
691 * On error: return code is zero or a negative errno value
693 static ssize_t write_threads(struct file *file, char *buf, size_t size)
699 rv = get_int(&mesg, &newthreads);
704 rv = nfsd_svc(NFS_PORT, newthreads);
708 rv = nfsd_nrthreads();
710 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
714 * write_pool_threads - Set or report the current number of threads per pool
723 * buf: C string containing whitespace-
724 * separated unsigned integer values
725 * representing the number of NFSD
726 * threads to start in each pool
727 * size: non-zero length of C string in @buf
729 * On success: passed-in buffer filled with '\n'-terminated C
730 * string containing integer values representing the
731 * number of NFSD threads in each pool;
732 * return code is the size in bytes of the string
733 * On error: return code is zero or a negative errno value
735 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
737 /* if size > 0, look for an array of number of threads per node
738 * and apply them then write out number of threads per node as reply
747 mutex_lock(&nfsd_mutex);
748 npools = nfsd_nrpools();
751 * NFS is shut down. The admin can start it by
752 * writing to the threads file but NOT the pool_threads
753 * file, sorry. Report zero threads.
755 mutex_unlock(&nfsd_mutex);
760 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
762 if (nthreads == NULL)
766 for (i = 0; i < npools; i++) {
767 rv = get_int(&mesg, &nthreads[i]);
769 break; /* fewer numbers than pools */
771 goto out_free; /* syntax error */
776 rv = nfsd_set_nrthreads(i, nthreads);
781 rv = nfsd_get_nrthreads(npools, nthreads);
786 size = SIMPLE_TRANSACTION_LIMIT;
787 for (i = 0; i < npools && size > 0; i++) {
788 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
796 mutex_unlock(&nfsd_mutex);
800 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
803 char *vers, *minorp, sign;
804 int len, num, remaining;
811 /* Cannot change versions without updating
812 * nfsd_serv->sv_xdrsize, and reallocing
813 * rq_argp and rq_resp
816 if (buf[size-1] != '\n')
821 len = qword_get(&mesg, vers, size);
822 if (len <= 0) return -EINVAL;
825 if (sign == '+' || sign == '-')
826 num = simple_strtol((vers+1), &minorp, 0);
828 num = simple_strtol(vers, &minorp, 0);
829 if (*minorp == '.') {
832 minor = simple_strtoul(minorp+1, NULL, 0);
835 if (nfsd_minorversion(minor, sign == '-' ?
836 NFSD_CLEAR : NFSD_SET) < 0)
844 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
851 } while ((len = qword_get(&mesg, vers, size)) > 0);
852 /* If all get turned off, turn them back on, as
853 * having no versions is BAD
855 nfsd_reset_versions();
858 /* Now write current state into reply buffer */
861 remaining = SIMPLE_TRANSACTION_LIMIT;
862 for (num=2 ; num <= 4 ; num++)
863 if (nfsd_vers(num, NFSD_AVAIL)) {
864 len = snprintf(buf, remaining, "%s%c%d", sep,
865 nfsd_vers(num, NFSD_TEST)?'+':'-',
875 if (nfsd_vers(4, NFSD_AVAIL))
876 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
878 len = snprintf(buf, remaining, " %c4.%u",
879 (nfsd_vers(4, NFSD_TEST) &&
880 nfsd_minorversion(minor, NFSD_TEST)) ?
891 len = snprintf(buf, remaining, "\n");
898 * write_versions - Set or report the available NFS protocol versions
904 * On success: passed-in buffer filled with '\n'-terminated C
905 * string containing positive or negative integer
906 * values representing the current status of each
908 * return code is the size in bytes of the string
909 * On error: return code is zero or a negative errno value
914 * buf: C string containing whitespace-
915 * separated positive or negative
916 * integer values representing NFS
917 * protocol versions to enable ("+n")
919 * size: non-zero length of C string in @buf
921 * On success: status of zero or more protocol versions has
922 * been updated; passed-in buffer filled with
923 * '\n'-terminated C string containing positive
924 * or negative integer values representing the
925 * current status of each protocol version;
926 * return code is the size in bytes of the string
927 * On error: return code is zero or a negative errno value
929 static ssize_t write_versions(struct file *file, char *buf, size_t size)
933 mutex_lock(&nfsd_mutex);
934 rv = __write_versions(file, buf, size);
935 mutex_unlock(&nfsd_mutex);
940 * Zero-length write. Return a list of NFSD's current listener
943 static ssize_t __write_ports_names(char *buf)
945 if (nfsd_serv == NULL)
947 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
951 * A single 'fd' number was written, in which case it must be for
952 * a socket of a supported family/protocol, and we use it as an
955 static ssize_t __write_ports_addfd(char *buf)
960 err = get_int(&mesg, &fd);
961 if (err != 0 || fd < 0)
964 err = nfsd_create_serv();
968 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
970 svc_destroy(nfsd_serv);
974 /* Decrease the count, but don't shut down the service */
975 nfsd_serv->sv_nrthreads--;
980 * A '-' followed by the 'name' of a socket means we close the socket.
982 static ssize_t __write_ports_delfd(char *buf)
987 toclose = kstrdup(buf + 1, GFP_KERNEL);
991 if (nfsd_serv != NULL)
992 len = svc_sock_names(nfsd_serv, buf,
993 SIMPLE_TRANSACTION_LIMIT, toclose);
999 * A transport listener is added by writing it's transport name and
1002 static ssize_t __write_ports_addxprt(char *buf)
1005 struct svc_xprt *xprt;
1008 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
1011 if (port < 1 || port > USHRT_MAX)
1014 err = nfsd_create_serv();
1018 err = svc_create_xprt(nfsd_serv, transport, &init_net,
1019 PF_INET, port, SVC_SOCK_ANONYMOUS);
1023 err = svc_create_xprt(nfsd_serv, transport, &init_net,
1024 PF_INET6, port, SVC_SOCK_ANONYMOUS);
1025 if (err < 0 && err != -EAFNOSUPPORT)
1028 /* Decrease the count, but don't shut down the service */
1029 nfsd_serv->sv_nrthreads--;
1032 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
1034 svc_close_xprt(xprt);
1038 svc_destroy(nfsd_serv);
1043 * A transport listener is removed by writing a "-", it's transport
1044 * name, and it's port number.
1046 static ssize_t __write_ports_delxprt(char *buf)
1048 struct svc_xprt *xprt;
1052 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1055 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
1058 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1062 svc_close_xprt(xprt);
1067 static ssize_t __write_ports(struct file *file, char *buf, size_t size)
1070 return __write_ports_names(buf);
1072 if (isdigit(buf[0]))
1073 return __write_ports_addfd(buf);
1075 if (buf[0] == '-' && isdigit(buf[1]))
1076 return __write_ports_delfd(buf);
1078 if (isalpha(buf[0]))
1079 return __write_ports_addxprt(buf);
1081 if (buf[0] == '-' && isalpha(buf[1]))
1082 return __write_ports_delxprt(buf);
1088 * write_ports - Pass a socket file descriptor or transport name to listen on
1094 * On success: passed-in buffer filled with a '\n'-terminated C
1095 * string containing a whitespace-separated list of
1096 * named NFSD listeners;
1097 * return code is the size in bytes of the string
1098 * On error: return code is zero or a negative errno value
1103 * buf: C string containing an unsigned
1104 * integer value representing a bound
1105 * but unconnected socket that is to be
1106 * used as an NFSD listener; listen(3)
1107 * must be called for a SOCK_STREAM
1108 * socket, otherwise it is ignored
1109 * size: non-zero length of C string in @buf
1111 * On success: NFS service is started;
1112 * passed-in buffer filled with a '\n'-terminated C
1113 * string containing a unique alphanumeric name of
1115 * return code is the size in bytes of the string
1116 * On error: return code is a negative errno value
1121 * buf: C string containing a "-" followed
1122 * by an integer value representing a
1123 * previously passed in socket file
1125 * size: non-zero length of C string in @buf
1127 * On success: NFS service no longer listens on that socket;
1128 * passed-in buffer filled with a '\n'-terminated C
1129 * string containing a unique name of the listener;
1130 * return code is the size in bytes of the string
1131 * On error: return code is a negative errno value
1136 * buf: C string containing a transport
1137 * name and an unsigned integer value
1138 * representing the port to listen on,
1139 * separated by whitespace
1140 * size: non-zero length of C string in @buf
1142 * On success: returns zero; NFS service is started
1143 * On error: return code is a negative errno value
1148 * buf: C string containing a "-" followed
1149 * by a transport name and an unsigned
1150 * integer value representing the port
1151 * to listen on, separated by whitespace
1152 * size: non-zero length of C string in @buf
1154 * On success: returns zero; NFS service no longer listens
1156 * On error: return code is a negative errno value
1158 static ssize_t write_ports(struct file *file, char *buf, size_t size)
1162 mutex_lock(&nfsd_mutex);
1163 rv = __write_ports(file, buf, size);
1164 mutex_unlock(&nfsd_mutex);
1169 int nfsd_max_blksize;
1172 * write_maxblksize - Set or report the current NFS blksize
1181 * buf: C string containing an unsigned
1182 * integer value representing the new
1184 * size: non-zero length of C string in @buf
1186 * On success: passed-in buffer filled with '\n'-terminated C string
1187 * containing numeric value of the current NFS blksize
1189 * return code is the size in bytes of the string
1190 * On error: return code is zero or a negative errno value
1192 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1197 int rv = get_int(&mesg, &bsize);
1200 /* force bsize into allowed range and
1201 * required alignment.
1205 if (bsize > NFSSVC_MAXBLKSIZE)
1206 bsize = NFSSVC_MAXBLKSIZE;
1208 mutex_lock(&nfsd_mutex);
1210 mutex_unlock(&nfsd_mutex);
1213 nfsd_max_blksize = bsize;
1214 mutex_unlock(&nfsd_mutex);
1217 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1221 #ifdef CONFIG_NFSD_V4
1222 static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1230 rv = get_int(&mesg, &i);
1234 * Some sanity checking. We don't have a reason for
1235 * these particular numbers, but problems with the
1237 * - Too short: the briefest network outage may
1238 * cause clients to lose all their locks. Also,
1239 * the frequent polling may be wasteful.
1240 * - Too long: do you really want reboot recovery
1241 * to take more than an hour? Or to make other
1242 * clients wait an hour before being able to
1243 * revoke a dead client's locks?
1245 if (i < 10 || i > 3600)
1250 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
1253 static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1257 mutex_lock(&nfsd_mutex);
1258 rv = __nfsd4_write_time(file, buf, size, time);
1259 mutex_unlock(&nfsd_mutex);
1264 * write_leasetime - Set or report the current NFSv4 lease time
1273 * buf: C string containing an unsigned
1274 * integer value representing the new
1275 * NFSv4 lease expiry time
1276 * size: non-zero length of C string in @buf
1278 * On success: passed-in buffer filled with '\n'-terminated C
1279 * string containing unsigned integer value of the
1280 * current lease expiry time;
1281 * return code is the size in bytes of the string
1282 * On error: return code is zero or a negative errno value
1284 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1286 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
1290 * write_gracetime - Set or report current NFSv4 grace period time
1292 * As above, but sets the time of the NFSv4 grace period.
1294 * Note this should never be set to less than the *previous*
1295 * lease-period time, but we don't try to enforce this. (In the common
1296 * case (a new boot), we don't know what the previous lease time was
1299 static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1301 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
1304 extern char *nfs4_recoverydir(void);
1306 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
1315 if (size > PATH_MAX || buf[size-1] != '\n')
1320 len = qword_get(&mesg, recdir, size);
1324 status = nfs4_reset_recoverydir(recdir);
1329 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1330 nfs4_recoverydir());
1334 * write_recoverydir - Set or report the pathname of the recovery directory
1343 * buf: C string containing the pathname
1344 * of the directory on a local file
1345 * system containing permanent NFSv4
1347 * size: non-zero length of C string in @buf
1349 * On success: passed-in buffer filled with '\n'-terminated C string
1350 * containing the current recovery pathname setting;
1351 * return code is the size in bytes of the string
1352 * On error: return code is zero or a negative errno value
1354 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1358 mutex_lock(&nfsd_mutex);
1359 rv = __write_recoverydir(file, buf, size);
1360 mutex_unlock(&nfsd_mutex);
1366 /*----------------------------------------------------------------------------*/
1368 * populating the filesystem.
1371 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1373 static struct tree_descr nfsd_files[] = {
1374 #ifdef CONFIG_NFSD_DEPRECATED
1375 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1376 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1377 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1378 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1379 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1380 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1381 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
1383 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
1384 [NFSD_Export_features] = {"export_features",
1385 &export_features_operations, S_IRUGO},
1386 [NFSD_FO_UnlockIP] = {"unlock_ip",
1387 &transaction_ops, S_IWUSR|S_IRUSR},
1388 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1389 &transaction_ops, S_IWUSR|S_IRUSR},
1390 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1391 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1392 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1393 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1394 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1395 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1396 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1397 #ifdef CONFIG_NFSD_V4
1398 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1399 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
1400 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1404 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1407 static int nfsd_get_sb(struct file_system_type *fs_type,
1408 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1410 return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
1413 static struct file_system_type nfsd_fs_type = {
1414 .owner = THIS_MODULE,
1416 .get_sb = nfsd_get_sb,
1417 .kill_sb = kill_litter_super,
1420 #ifdef CONFIG_PROC_FS
1421 static int create_proc_exports_entry(void)
1423 struct proc_dir_entry *entry;
1425 entry = proc_mkdir("fs/nfs", NULL);
1428 entry = proc_create("exports", 0, entry, &exports_operations);
1433 #else /* CONFIG_PROC_FS */
1434 static int create_proc_exports_entry(void)
1440 static int __init init_nfsd(void)
1443 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1445 retval = nfs4_state_init(); /* nfs4 locking state */
1448 nfsd_stat_init(); /* Statistics */
1449 retval = nfsd_reply_cache_init();
1452 retval = nfsd_export_init();
1454 goto out_free_cache;
1455 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1456 retval = nfsd_idmap_init();
1458 goto out_free_lockd;
1459 retval = create_proc_exports_entry();
1461 goto out_free_idmap;
1462 retval = register_filesystem(&nfsd_fs_type);
1467 remove_proc_entry("fs/nfs/exports", NULL);
1468 remove_proc_entry("fs/nfs", NULL);
1470 nfsd_idmap_shutdown();
1472 nfsd_lockd_shutdown();
1473 nfsd_export_shutdown();
1475 nfsd_reply_cache_shutdown();
1477 nfsd_stat_shutdown();
1482 static void __exit exit_nfsd(void)
1484 nfsd_export_shutdown();
1485 nfsd_reply_cache_shutdown();
1486 remove_proc_entry("fs/nfs/exports", NULL);
1487 remove_proc_entry("fs/nfs", NULL);
1488 nfsd_stat_shutdown();
1489 nfsd_lockd_shutdown();
1490 nfsd_idmap_shutdown();
1492 unregister_filesystem(&nfsd_fs_type);
1495 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1496 MODULE_LICENSE("GPL");
1497 module_init(init_nfsd)
1498 module_exit(exit_nfsd)