2 * Syscall interface to knfsd.
7 #include <linux/slab.h>
8 #include <linux/namei.h>
9 #include <linux/ctype.h>
11 #include <linux/sunrpc/svcsock.h>
12 #include <linux/nfsd/syscall.h>
13 #include <linux/lockd/lockd.h>
14 #include <linux/sunrpc/clnt.h>
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)
130 #ifdef CONFIG_NFSD_DEPRECATED
132 if (file->f_dentry->d_name.name[0] == '.' && !warned) {
134 "Warning: \"%s\" uses deprecated NFSD interface: %s."
135 " This will be removed in 2.6.40\n",
136 current->comm, 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,
156 .llseek = default_llseek,
159 static int exports_open(struct inode *inode, struct file *file)
161 return seq_open(file, &nfs_exports_op);
164 static const struct file_operations exports_operations = {
165 .open = exports_open,
168 .release = seq_release,
169 .owner = THIS_MODULE,
172 static int export_features_show(struct seq_file *m, void *v)
174 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
178 static int export_features_open(struct inode *inode, struct file *file)
180 return single_open(file, export_features_show, NULL);
183 static struct file_operations export_features_operations = {
184 .open = export_features_open,
187 .release = single_release,
190 extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
191 extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
193 static const struct file_operations pool_stats_operations = {
194 .open = nfsd_pool_stats_open,
197 .release = nfsd_pool_stats_release,
198 .owner = THIS_MODULE,
201 /*----------------------------------------------------------------------------*/
203 * payload - write methods
206 #ifdef CONFIG_NFSD_DEPRECATED
208 * write_svc - Start kernel's NFSD server
210 * Deprecated. /proc/fs/nfsd/threads is preferred.
211 * Function remains to support old versions of nfs-utils.
214 * buf: struct nfsctl_svc
215 * svc_port: port number of this
217 * svc_nthreads: number of threads to start
218 * size: size in bytes of passed in nfsctl_svc
220 * On success: returns zero
221 * On error: return code is negative errno value
223 static ssize_t write_svc(struct file *file, char *buf, size_t size)
225 struct nfsctl_svc *data;
227 if (size < sizeof(*data))
229 data = (struct nfsctl_svc*) buf;
230 err = nfsd_svc(data->svc_port, data->svc_nthreads);
237 * write_add - Add or modify client entry in auth unix cache
239 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
240 * Function remains to support old versions of nfs-utils.
243 * buf: struct nfsctl_client
244 * cl_ident: '\0'-terminated C string
245 * containing domain name
247 * cl_naddr: no. of items in cl_addrlist
248 * cl_addrlist: array of client addresses
249 * cl_fhkeytype: ignored
250 * cl_fhkeylen: ignored
252 * size: size in bytes of passed in nfsctl_client
254 * On success: returns zero
255 * On error: return code is negative errno value
257 * Note: Only AF_INET client addresses are passed in, since
258 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
260 static ssize_t write_add(struct file *file, char *buf, size_t size)
262 struct nfsctl_client *data;
263 if (size < sizeof(*data))
265 data = (struct nfsctl_client *)buf;
266 return exp_addclient(data);
270 * write_del - Remove client from auth unix cache
272 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
273 * Function remains to support old versions of nfs-utils.
276 * buf: struct nfsctl_client
277 * cl_ident: '\0'-terminated C string
278 * containing domain name
281 * cl_addrlist: ignored
282 * cl_fhkeytype: ignored
283 * cl_fhkeylen: ignored
285 * size: size in bytes of passed in nfsctl_client
287 * On success: returns zero
288 * On error: return code is negative errno value
290 * Note: Only AF_INET client addresses are passed in, since
291 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
293 static ssize_t write_del(struct file *file, char *buf, size_t size)
295 struct nfsctl_client *data;
296 if (size < sizeof(*data))
298 data = (struct nfsctl_client *)buf;
299 return exp_delclient(data);
303 * write_export - Export part or all of a local file system
305 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
306 * Function remains to support old versions of nfs-utils.
309 * buf: struct nfsctl_export
310 * ex_client: '\0'-terminated C string
311 * containing domain name
312 * of client allowed to access
314 * ex_path: '\0'-terminated C string
315 * containing pathname of
316 * directory in local file system
317 * ex_dev: fsid to use for this export
319 * ex_flags: export flags for this export
320 * ex_anon_uid: UID to use for anonymous
322 * ex_anon_gid: GID to use for anonymous
324 * size: size in bytes of passed in nfsctl_export
326 * On success: returns zero
327 * On error: return code is negative errno value
329 static ssize_t write_export(struct file *file, char *buf, size_t size)
331 struct nfsctl_export *data;
332 if (size < sizeof(*data))
334 data = (struct nfsctl_export*)buf;
335 return exp_export(data);
339 * write_unexport - Unexport a previously exported file system
341 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
342 * Function remains to support old versions of nfs-utils.
345 * buf: struct nfsctl_export
346 * ex_client: '\0'-terminated C string
347 * containing domain name
348 * of client no longer allowed
349 * to access this export
350 * ex_path: '\0'-terminated C string
351 * containing pathname of
352 * directory in local file system
356 * ex_anon_uid: ignored
357 * ex_anon_gid: ignored
358 * size: size in bytes of passed in nfsctl_export
360 * On success: returns zero
361 * On error: return code is negative errno value
363 static ssize_t write_unexport(struct file *file, char *buf, size_t size)
365 struct nfsctl_export *data;
367 if (size < sizeof(*data))
369 data = (struct nfsctl_export*)buf;
370 return exp_unexport(data);
374 * write_getfs - Get a variable-length NFS file handle by path
376 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
377 * Function remains to support old versions of nfs-utils.
380 * buf: struct nfsctl_fsparm
381 * gd_addr: socket address of client
382 * gd_path: '\0'-terminated C string
383 * containing pathname of
384 * directory in local file system
385 * gd_maxlen: maximum size of returned file
387 * size: size in bytes of passed in nfsctl_fsparm
389 * On success: passed-in buffer filled with a knfsd_fh structure
390 * (a variable-length raw NFS file handle);
391 * return code is the size in bytes of the file handle
392 * On error: return code is negative errno value
394 * Note: Only AF_INET client addresses are passed in, since gd_addr
395 * is the same size as a struct sockaddr_in.
397 static ssize_t write_getfs(struct file *file, char *buf, size_t size)
399 struct nfsctl_fsparm *data;
400 struct sockaddr_in *sin;
401 struct auth_domain *clp;
403 struct knfsd_fh *res;
406 if (size < sizeof(*data))
408 data = (struct nfsctl_fsparm*)buf;
409 err = -EPROTONOSUPPORT;
410 if (data->gd_addr.sa_family != AF_INET)
412 sin = (struct sockaddr_in *)&data->gd_addr;
413 if (data->gd_maxlen > NFS3_FHSIZE)
414 data->gd_maxlen = NFS3_FHSIZE;
416 res = (struct knfsd_fh*)buf;
420 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
422 clp = auth_unix_lookup(&init_net, &in6);
426 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
427 auth_domain_put(clp);
431 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
437 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
439 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
440 * Function remains to support old versions of nfs-utils.
443 * buf: struct nfsctl_fdparm
444 * gd_addr: socket address of client
445 * gd_path: '\0'-terminated C string
446 * containing pathname of
447 * directory in local file system
448 * gd_version: fdparm structure version
449 * size: size in bytes of passed in nfsctl_fdparm
451 * On success: passed-in buffer filled with nfsctl_res
452 * (a fixed-length raw NFS file handle);
453 * return code is the size in bytes of the file handle
454 * On error: return code is negative errno value
456 * Note: Only AF_INET client addresses are passed in, since gd_addr
457 * is the same size as a struct sockaddr_in.
459 static ssize_t write_getfd(struct file *file, char *buf, size_t size)
461 struct nfsctl_fdparm *data;
462 struct sockaddr_in *sin;
463 struct auth_domain *clp;
469 if (size < sizeof(*data))
471 data = (struct nfsctl_fdparm*)buf;
472 err = -EPROTONOSUPPORT;
473 if (data->gd_addr.sa_family != AF_INET)
476 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
480 sin = (struct sockaddr_in *)&data->gd_addr;
483 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
485 clp = auth_unix_lookup(&init_net, &in6);
489 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
490 auth_domain_put(clp);
495 memset(res,0, NFS_FHSIZE);
496 memcpy(res, &fh.fh_base, fh.fh_size);
502 #endif /* CONFIG_NFSD_DEPRECATED */
505 * write_unlock_ip - Release all locks used by a client
510 * buf: '\n'-terminated C string containing a
511 * presentation format IP address
512 * size: length of C string in @buf
514 * On success: returns zero if all specified locks were released;
515 * returns one if one or more locks were not released
516 * On error: return code is negative errno value
518 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
520 struct sockaddr_storage address;
521 struct sockaddr *sap = (struct sockaddr *)&address;
522 size_t salen = sizeof(address);
529 if (buf[size-1] != '\n')
533 if (qword_get(&buf, fo_path, size) < 0)
536 if (rpc_pton(fo_path, size, sap, salen) == 0)
539 return nlmsvc_unlock_all_by_ip(sap);
543 * write_unlock_fs - Release all locks on a local file system
548 * buf: '\n'-terminated C string containing the
549 * absolute pathname of a local file system
550 * size: length of C string in @buf
552 * On success: returns zero if all specified locks were released;
553 * returns one if one or more locks were not released
554 * On error: return code is negative errno value
556 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
566 if (buf[size-1] != '\n')
570 if (qword_get(&buf, fo_path, size) < 0)
573 error = kern_path(fo_path, 0, &path);
578 * XXX: Needs better sanity checking. Otherwise we could end up
579 * releasing locks on the wrong file system.
582 * 1. Does the path refer to a directory?
583 * 2. Is that directory a mount point, or
584 * 3. Is that directory the root of an exported file system?
586 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
593 * write_filehandle - Get a variable-length NFS file handle by path
595 * On input, the buffer contains a '\n'-terminated C string comprised of
596 * three alphanumeric words separated by whitespace. The string may
597 * contain escape sequences.
601 * domain: client domain name
602 * path: export pathname
603 * maxsize: numeric maximum size of
605 * size: length of C string in @buf
607 * On success: passed-in buffer filled with '\n'-terminated C
608 * string containing a ASCII hex text version
609 * of the NFS file handle;
610 * return code is the size in bytes of the string
611 * On error: return code is negative errno value
613 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
616 int uninitialized_var(maxsize);
619 struct auth_domain *dom;
625 if (buf[size-1] != '\n')
630 len = qword_get(&mesg, dname, size);
635 len = qword_get(&mesg, path, size);
639 len = get_int(&mesg, &maxsize);
643 if (maxsize < NFS_FHSIZE)
645 if (maxsize > NFS3_FHSIZE)
646 maxsize = NFS3_FHSIZE;
648 if (qword_get(&mesg, mesg, size)>0)
651 /* we have all the words, they are in buf.. */
652 dom = unix_domain_find(dname);
656 len = exp_rootfh(dom, path, &fh, maxsize);
657 auth_domain_put(dom);
662 len = SIMPLE_TRANSACTION_LIMIT;
663 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
669 * write_threads - Start NFSD, or report the current number of running threads
675 * On success: passed-in buffer filled with '\n'-terminated C
676 * string numeric value representing the number of
677 * running NFSD threads;
678 * return code is the size in bytes of the string
679 * On error: return code is zero
684 * buf: C string containing an unsigned
685 * integer value representing the
686 * number of NFSD threads to start
687 * size: non-zero length of C string in @buf
689 * On success: NFS service is started;
690 * passed-in buffer filled with '\n'-terminated C
691 * string numeric value representing the number of
692 * running NFSD threads;
693 * return code is the size in bytes of the string
694 * On error: return code is zero or a negative errno value
696 static ssize_t write_threads(struct file *file, char *buf, size_t size)
702 rv = get_int(&mesg, &newthreads);
707 rv = nfsd_svc(NFS_PORT, newthreads);
711 rv = nfsd_nrthreads();
713 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
717 * write_pool_threads - Set or report the current number of threads per pool
726 * buf: C string containing whitespace-
727 * separated unsigned integer values
728 * representing the number of NFSD
729 * threads to start in each pool
730 * size: non-zero length of C string in @buf
732 * On success: passed-in buffer filled with '\n'-terminated C
733 * string containing integer values representing the
734 * number of NFSD threads in each pool;
735 * return code is the size in bytes of the string
736 * On error: return code is zero or a negative errno value
738 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
740 /* if size > 0, look for an array of number of threads per node
741 * and apply them then write out number of threads per node as reply
750 mutex_lock(&nfsd_mutex);
751 npools = nfsd_nrpools();
754 * NFS is shut down. The admin can start it by
755 * writing to the threads file but NOT the pool_threads
756 * file, sorry. Report zero threads.
758 mutex_unlock(&nfsd_mutex);
763 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
765 if (nthreads == NULL)
769 for (i = 0; i < npools; i++) {
770 rv = get_int(&mesg, &nthreads[i]);
772 break; /* fewer numbers than pools */
774 goto out_free; /* syntax error */
779 rv = nfsd_set_nrthreads(i, nthreads);
784 rv = nfsd_get_nrthreads(npools, nthreads);
789 size = SIMPLE_TRANSACTION_LIMIT;
790 for (i = 0; i < npools && size > 0; i++) {
791 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
799 mutex_unlock(&nfsd_mutex);
803 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
806 char *vers, *minorp, sign;
807 int len, num, remaining;
814 /* Cannot change versions without updating
815 * nfsd_serv->sv_xdrsize, and reallocing
816 * rq_argp and rq_resp
819 if (buf[size-1] != '\n')
824 len = qword_get(&mesg, vers, size);
825 if (len <= 0) return -EINVAL;
828 if (sign == '+' || sign == '-')
829 num = simple_strtol((vers+1), &minorp, 0);
831 num = simple_strtol(vers, &minorp, 0);
832 if (*minorp == '.') {
835 minor = simple_strtoul(minorp+1, NULL, 0);
838 if (nfsd_minorversion(minor, sign == '-' ?
839 NFSD_CLEAR : NFSD_SET) < 0)
847 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
854 } while ((len = qword_get(&mesg, vers, size)) > 0);
855 /* If all get turned off, turn them back on, as
856 * having no versions is BAD
858 nfsd_reset_versions();
861 /* Now write current state into reply buffer */
864 remaining = SIMPLE_TRANSACTION_LIMIT;
865 for (num=2 ; num <= 4 ; num++)
866 if (nfsd_vers(num, NFSD_AVAIL)) {
867 len = snprintf(buf, remaining, "%s%c%d", sep,
868 nfsd_vers(num, NFSD_TEST)?'+':'-',
878 if (nfsd_vers(4, NFSD_AVAIL))
879 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
881 len = snprintf(buf, remaining, " %c4.%u",
882 (nfsd_vers(4, NFSD_TEST) &&
883 nfsd_minorversion(minor, NFSD_TEST)) ?
894 len = snprintf(buf, remaining, "\n");
901 * write_versions - Set or report the available NFS protocol versions
907 * On success: passed-in buffer filled with '\n'-terminated C
908 * string containing positive or negative integer
909 * values representing the current status of each
911 * return code is the size in bytes of the string
912 * On error: return code is zero or a negative errno value
917 * buf: C string containing whitespace-
918 * separated positive or negative
919 * integer values representing NFS
920 * protocol versions to enable ("+n")
922 * size: non-zero length of C string in @buf
924 * On success: status of zero or more protocol versions has
925 * been updated; passed-in buffer filled with
926 * '\n'-terminated C string containing positive
927 * or negative integer values representing the
928 * current status of each protocol version;
929 * return code is the size in bytes of the string
930 * On error: return code is zero or a negative errno value
932 static ssize_t write_versions(struct file *file, char *buf, size_t size)
936 mutex_lock(&nfsd_mutex);
937 rv = __write_versions(file, buf, size);
938 mutex_unlock(&nfsd_mutex);
943 * Zero-length write. Return a list of NFSD's current listener
946 static ssize_t __write_ports_names(char *buf)
948 if (nfsd_serv == NULL)
950 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
954 * A single 'fd' number was written, in which case it must be for
955 * a socket of a supported family/protocol, and we use it as an
958 static ssize_t __write_ports_addfd(char *buf)
963 err = get_int(&mesg, &fd);
964 if (err != 0 || fd < 0)
967 err = nfsd_create_serv();
971 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
973 svc_destroy(nfsd_serv);
977 /* Decrease the count, but don't shut down the service */
978 nfsd_serv->sv_nrthreads--;
983 * A '-' followed by the 'name' of a socket means we close the socket.
985 static ssize_t __write_ports_delfd(char *buf)
990 toclose = kstrdup(buf + 1, GFP_KERNEL);
994 if (nfsd_serv != NULL)
995 len = svc_sock_names(nfsd_serv, buf,
996 SIMPLE_TRANSACTION_LIMIT, toclose);
1002 * A transport listener is added by writing it's transport name and
1005 static ssize_t __write_ports_addxprt(char *buf)
1008 struct svc_xprt *xprt;
1011 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
1014 if (port < 1 || port > USHRT_MAX)
1017 err = nfsd_create_serv();
1021 err = svc_create_xprt(nfsd_serv, transport, &init_net,
1022 PF_INET, port, SVC_SOCK_ANONYMOUS);
1026 err = svc_create_xprt(nfsd_serv, transport, &init_net,
1027 PF_INET6, port, SVC_SOCK_ANONYMOUS);
1028 if (err < 0 && err != -EAFNOSUPPORT)
1031 /* Decrease the count, but don't shut down the service */
1032 nfsd_serv->sv_nrthreads--;
1035 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
1037 svc_close_xprt(xprt);
1041 svc_destroy(nfsd_serv);
1046 * A transport listener is removed by writing a "-", it's transport
1047 * name, and it's port number.
1049 static ssize_t __write_ports_delxprt(char *buf)
1051 struct svc_xprt *xprt;
1055 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1058 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
1061 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1065 svc_close_xprt(xprt);
1070 static ssize_t __write_ports(struct file *file, char *buf, size_t size)
1073 return __write_ports_names(buf);
1075 if (isdigit(buf[0]))
1076 return __write_ports_addfd(buf);
1078 if (buf[0] == '-' && isdigit(buf[1]))
1079 return __write_ports_delfd(buf);
1081 if (isalpha(buf[0]))
1082 return __write_ports_addxprt(buf);
1084 if (buf[0] == '-' && isalpha(buf[1]))
1085 return __write_ports_delxprt(buf);
1091 * write_ports - Pass a socket file descriptor or transport name to listen on
1097 * On success: passed-in buffer filled with a '\n'-terminated C
1098 * string containing a whitespace-separated list of
1099 * named NFSD listeners;
1100 * return code is the size in bytes of the string
1101 * On error: return code is zero or a negative errno value
1106 * buf: C string containing an unsigned
1107 * integer value representing a bound
1108 * but unconnected socket that is to be
1109 * used as an NFSD listener; listen(3)
1110 * must be called for a SOCK_STREAM
1111 * socket, otherwise it is ignored
1112 * size: non-zero length of C string in @buf
1114 * On success: NFS service is started;
1115 * passed-in buffer filled with a '\n'-terminated C
1116 * string containing a unique alphanumeric name of
1118 * return code is the size in bytes of the string
1119 * On error: return code is a negative errno value
1124 * buf: C string containing a "-" followed
1125 * by an integer value representing a
1126 * previously passed in socket file
1128 * size: non-zero length of C string in @buf
1130 * On success: NFS service no longer listens on that socket;
1131 * passed-in buffer filled with a '\n'-terminated C
1132 * string containing a unique name of the listener;
1133 * return code is the size in bytes of the string
1134 * On error: return code is a negative errno value
1139 * buf: C string containing a transport
1140 * name and an unsigned integer value
1141 * representing the port to listen on,
1142 * separated by whitespace
1143 * size: non-zero length of C string in @buf
1145 * On success: returns zero; NFS service is started
1146 * On error: return code is a negative errno value
1151 * buf: C string containing a "-" followed
1152 * by a transport name and an unsigned
1153 * integer value representing the port
1154 * to listen on, separated by whitespace
1155 * size: non-zero length of C string in @buf
1157 * On success: returns zero; NFS service no longer listens
1159 * On error: return code is a negative errno value
1161 static ssize_t write_ports(struct file *file, char *buf, size_t size)
1165 mutex_lock(&nfsd_mutex);
1166 rv = __write_ports(file, buf, size);
1167 mutex_unlock(&nfsd_mutex);
1172 int nfsd_max_blksize;
1175 * write_maxblksize - Set or report the current NFS blksize
1184 * buf: C string containing an unsigned
1185 * integer value representing the new
1187 * size: non-zero length of C string in @buf
1189 * On success: passed-in buffer filled with '\n'-terminated C string
1190 * containing numeric value of the current NFS blksize
1192 * return code is the size in bytes of the string
1193 * On error: return code is zero or a negative errno value
1195 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1200 int rv = get_int(&mesg, &bsize);
1203 /* force bsize into allowed range and
1204 * required alignment.
1208 if (bsize > NFSSVC_MAXBLKSIZE)
1209 bsize = NFSSVC_MAXBLKSIZE;
1211 mutex_lock(&nfsd_mutex);
1213 mutex_unlock(&nfsd_mutex);
1216 nfsd_max_blksize = bsize;
1217 mutex_unlock(&nfsd_mutex);
1220 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1224 #ifdef CONFIG_NFSD_V4
1225 static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1233 rv = get_int(&mesg, &i);
1237 * Some sanity checking. We don't have a reason for
1238 * these particular numbers, but problems with the
1240 * - Too short: the briefest network outage may
1241 * cause clients to lose all their locks. Also,
1242 * the frequent polling may be wasteful.
1243 * - Too long: do you really want reboot recovery
1244 * to take more than an hour? Or to make other
1245 * clients wait an hour before being able to
1246 * revoke a dead client's locks?
1248 if (i < 10 || i > 3600)
1253 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
1256 static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1260 mutex_lock(&nfsd_mutex);
1261 rv = __nfsd4_write_time(file, buf, size, time);
1262 mutex_unlock(&nfsd_mutex);
1267 * write_leasetime - Set or report the current NFSv4 lease time
1276 * buf: C string containing an unsigned
1277 * integer value representing the new
1278 * NFSv4 lease expiry time
1279 * size: non-zero length of C string in @buf
1281 * On success: passed-in buffer filled with '\n'-terminated C
1282 * string containing unsigned integer value of the
1283 * current lease expiry time;
1284 * return code is the size in bytes of the string
1285 * On error: return code is zero or a negative errno value
1287 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1289 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
1293 * write_gracetime - Set or report current NFSv4 grace period time
1295 * As above, but sets the time of the NFSv4 grace period.
1297 * Note this should never be set to less than the *previous*
1298 * lease-period time, but we don't try to enforce this. (In the common
1299 * case (a new boot), we don't know what the previous lease time was
1302 static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1304 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
1307 extern char *nfs4_recoverydir(void);
1309 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
1318 if (size > PATH_MAX || buf[size-1] != '\n')
1323 len = qword_get(&mesg, recdir, size);
1327 status = nfs4_reset_recoverydir(recdir);
1332 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1333 nfs4_recoverydir());
1337 * write_recoverydir - Set or report the pathname of the recovery directory
1346 * buf: C string containing the pathname
1347 * of the directory on a local file
1348 * system containing permanent NFSv4
1350 * size: non-zero length of C string in @buf
1352 * On success: passed-in buffer filled with '\n'-terminated C string
1353 * containing the current recovery pathname setting;
1354 * return code is the size in bytes of the string
1355 * On error: return code is zero or a negative errno value
1357 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1361 mutex_lock(&nfsd_mutex);
1362 rv = __write_recoverydir(file, buf, size);
1363 mutex_unlock(&nfsd_mutex);
1369 /*----------------------------------------------------------------------------*/
1371 * populating the filesystem.
1374 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1376 static struct tree_descr nfsd_files[] = {
1377 #ifdef CONFIG_NFSD_DEPRECATED
1378 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1379 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1380 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1381 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1382 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1383 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1384 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
1386 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
1387 [NFSD_Export_features] = {"export_features",
1388 &export_features_operations, S_IRUGO},
1389 [NFSD_FO_UnlockIP] = {"unlock_ip",
1390 &transaction_ops, S_IWUSR|S_IRUSR},
1391 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1392 &transaction_ops, S_IWUSR|S_IRUSR},
1393 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1394 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1395 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1396 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1397 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1398 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1399 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1400 #ifdef CONFIG_NFSD_V4
1401 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1402 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
1403 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1407 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1410 static struct dentry *nfsd_mount(struct file_system_type *fs_type,
1411 int flags, const char *dev_name, void *data)
1413 return mount_single(fs_type, flags, data, nfsd_fill_super);
1416 static struct file_system_type nfsd_fs_type = {
1417 .owner = THIS_MODULE,
1419 .mount = nfsd_mount,
1420 .kill_sb = kill_litter_super,
1423 #ifdef CONFIG_PROC_FS
1424 static int create_proc_exports_entry(void)
1426 struct proc_dir_entry *entry;
1428 entry = proc_mkdir("fs/nfs", NULL);
1431 entry = proc_create("exports", 0, entry, &exports_operations);
1436 #else /* CONFIG_PROC_FS */
1437 static int create_proc_exports_entry(void)
1443 static int __init init_nfsd(void)
1448 retval = nfs4_state_init(); /* nfs4 locking state */
1451 nfsd_stat_init(); /* Statistics */
1452 retval = nfsd_reply_cache_init();
1455 retval = nfsd_export_init();
1457 goto out_free_cache;
1458 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1459 retval = nfsd_idmap_init();
1461 goto out_free_lockd;
1462 retval = create_proc_exports_entry();
1464 goto out_free_idmap;
1465 retval = register_filesystem(&nfsd_fs_type);
1470 remove_proc_entry("fs/nfs/exports", NULL);
1471 remove_proc_entry("fs/nfs", NULL);
1473 nfsd_idmap_shutdown();
1475 nfsd_lockd_shutdown();
1476 nfsd_export_shutdown();
1478 nfsd_reply_cache_shutdown();
1480 nfsd_stat_shutdown();
1485 static void __exit exit_nfsd(void)
1487 nfsd_export_shutdown();
1488 nfsd_reply_cache_shutdown();
1489 remove_proc_entry("fs/nfs/exports", NULL);
1490 remove_proc_entry("fs/nfs", NULL);
1491 nfsd_stat_shutdown();
1492 nfsd_lockd_shutdown();
1493 nfsd_idmap_shutdown();
1495 unregister_filesystem(&nfsd_fs_type);
1499 MODULE_LICENSE("GPL");
1500 module_init(init_nfsd)
1501 module_exit(exit_nfsd)