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/sunrpc/svcsock.h>
12 #include <linux/nfsd/syscall.h>
13 #include <linux/lockd/lockd.h>
14 #include <linux/sunrpc/clnt.h>
15 #include <linux/sunrpc/gss_api.h>
16 #include <linux/sunrpc/gss_krb5_enctypes.h>
23 * We have a single directory with several nodes in it.
27 #ifdef CONFIG_NFSD_DEPRECATED
47 NFSD_SupportedEnctypes,
49 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
50 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
60 * write() for these nodes.
62 #ifdef CONFIG_NFSD_DEPRECATED
63 static ssize_t write_svc(struct file *file, char *buf, size_t size);
64 static ssize_t write_add(struct file *file, char *buf, size_t size);
65 static ssize_t write_del(struct file *file, char *buf, size_t size);
66 static ssize_t write_export(struct file *file, char *buf, size_t size);
67 static ssize_t write_unexport(struct file *file, char *buf, size_t size);
68 static ssize_t write_getfd(struct file *file, char *buf, size_t size);
69 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
71 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
72 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
73 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
74 static ssize_t write_threads(struct file *file, char *buf, size_t size);
75 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
76 static ssize_t write_versions(struct file *file, char *buf, size_t size);
77 static ssize_t write_ports(struct file *file, char *buf, size_t size);
78 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
80 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
81 static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
82 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
85 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
86 #ifdef CONFIG_NFSD_DEPRECATED
87 [NFSD_Svc] = write_svc,
88 [NFSD_Add] = write_add,
89 [NFSD_Del] = write_del,
90 [NFSD_Export] = write_export,
91 [NFSD_Unexport] = write_unexport,
92 [NFSD_Getfd] = write_getfd,
93 [NFSD_Getfs] = write_getfs,
95 [NFSD_Fh] = write_filehandle,
96 [NFSD_FO_UnlockIP] = write_unlock_ip,
97 [NFSD_FO_UnlockFS] = write_unlock_fs,
98 [NFSD_Threads] = write_threads,
99 [NFSD_Pool_Threads] = write_pool_threads,
100 [NFSD_Versions] = write_versions,
101 [NFSD_Ports] = write_ports,
102 [NFSD_MaxBlkSize] = write_maxblksize,
103 #ifdef CONFIG_NFSD_V4
104 [NFSD_Leasetime] = write_leasetime,
105 [NFSD_Gracetime] = write_gracetime,
106 [NFSD_RecoveryDir] = write_recoverydir,
110 static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
112 ino_t ino = file->f_path.dentry->d_inode->i_ino;
116 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
119 data = simple_transaction_get(file, buf, size);
121 return PTR_ERR(data);
123 rv = write_op[ino](file, data, size);
125 simple_transaction_set(file, rv);
131 static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
133 #ifdef CONFIG_NFSD_DEPRECATED
135 if (file->f_dentry->d_name.name[0] == '.' && !warned) {
137 "Warning: \"%s\" uses deprecated NFSD interface: %s."
138 " This will be removed in 2.6.40\n",
139 current->comm, file->f_dentry->d_name.name);
143 if (! file->private_data) {
144 /* An attempt to read a transaction file without writing
145 * causes a 0-byte write so that the file can return
148 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
152 return simple_transaction_read(file, buf, size, pos);
155 static const struct file_operations transaction_ops = {
156 .write = nfsctl_transaction_write,
157 .read = nfsctl_transaction_read,
158 .release = simple_transaction_release,
159 .llseek = default_llseek,
162 static int exports_open(struct inode *inode, struct file *file)
164 return seq_open(file, &nfs_exports_op);
167 static const struct file_operations exports_operations = {
168 .open = exports_open,
171 .release = seq_release,
172 .owner = THIS_MODULE,
175 static int export_features_show(struct seq_file *m, void *v)
177 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
181 static int export_features_open(struct inode *inode, struct file *file)
183 return single_open(file, export_features_show, NULL);
186 static struct file_operations export_features_operations = {
187 .open = export_features_open,
190 .release = single_release,
193 #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
194 static int supported_enctypes_show(struct seq_file *m, void *v)
196 seq_printf(m, KRB5_SUPPORTED_ENCTYPES);
200 static int supported_enctypes_open(struct inode *inode, struct file *file)
202 return single_open(file, supported_enctypes_show, NULL);
205 static struct file_operations supported_enctypes_ops = {
206 .open = supported_enctypes_open,
209 .release = single_release,
211 #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
213 extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
214 extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
216 static const struct file_operations pool_stats_operations = {
217 .open = nfsd_pool_stats_open,
220 .release = nfsd_pool_stats_release,
221 .owner = THIS_MODULE,
224 /*----------------------------------------------------------------------------*/
226 * payload - write methods
229 #ifdef CONFIG_NFSD_DEPRECATED
231 * write_svc - Start kernel's NFSD server
233 * Deprecated. /proc/fs/nfsd/threads is preferred.
234 * Function remains to support old versions of nfs-utils.
237 * buf: struct nfsctl_svc
238 * svc_port: port number of this
240 * svc_nthreads: number of threads to start
241 * size: size in bytes of passed in nfsctl_svc
243 * On success: returns zero
244 * On error: return code is negative errno value
246 static ssize_t write_svc(struct file *file, char *buf, size_t size)
248 struct nfsctl_svc *data;
250 if (size < sizeof(*data))
252 data = (struct nfsctl_svc*) buf;
253 err = nfsd_svc(data->svc_port, data->svc_nthreads);
260 * write_add - Add or modify client entry in auth unix cache
262 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
263 * Function remains to support old versions of nfs-utils.
266 * buf: struct nfsctl_client
267 * cl_ident: '\0'-terminated C string
268 * containing domain name
270 * cl_naddr: no. of items in cl_addrlist
271 * cl_addrlist: array of client addresses
272 * cl_fhkeytype: ignored
273 * cl_fhkeylen: ignored
275 * size: size in bytes of passed in nfsctl_client
277 * On success: returns zero
278 * On error: return code is negative errno value
280 * Note: Only AF_INET client addresses are passed in, since
281 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
283 static ssize_t write_add(struct file *file, char *buf, size_t size)
285 struct nfsctl_client *data;
286 if (size < sizeof(*data))
288 data = (struct nfsctl_client *)buf;
289 return exp_addclient(data);
293 * write_del - Remove client from auth unix cache
295 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
296 * Function remains to support old versions of nfs-utils.
299 * buf: struct nfsctl_client
300 * cl_ident: '\0'-terminated C string
301 * containing domain name
304 * cl_addrlist: ignored
305 * cl_fhkeytype: ignored
306 * cl_fhkeylen: ignored
308 * size: size in bytes of passed in nfsctl_client
310 * On success: returns zero
311 * On error: return code is negative errno value
313 * Note: Only AF_INET client addresses are passed in, since
314 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
316 static ssize_t write_del(struct file *file, char *buf, size_t size)
318 struct nfsctl_client *data;
319 if (size < sizeof(*data))
321 data = (struct nfsctl_client *)buf;
322 return exp_delclient(data);
326 * write_export - Export part or all of a local file system
328 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
329 * Function remains to support old versions of nfs-utils.
332 * buf: struct nfsctl_export
333 * ex_client: '\0'-terminated C string
334 * containing domain name
335 * of client allowed to access
337 * ex_path: '\0'-terminated C string
338 * containing pathname of
339 * directory in local file system
340 * ex_dev: fsid to use for this export
342 * ex_flags: export flags for this export
343 * ex_anon_uid: UID to use for anonymous
345 * ex_anon_gid: GID to use for anonymous
347 * size: size in bytes of passed in nfsctl_export
349 * On success: returns zero
350 * On error: return code is negative errno value
352 static ssize_t write_export(struct file *file, char *buf, size_t size)
354 struct nfsctl_export *data;
355 if (size < sizeof(*data))
357 data = (struct nfsctl_export*)buf;
358 return exp_export(data);
362 * write_unexport - Unexport a previously exported file system
364 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
365 * Function remains to support old versions of nfs-utils.
368 * buf: struct nfsctl_export
369 * ex_client: '\0'-terminated C string
370 * containing domain name
371 * of client no longer allowed
372 * to access this export
373 * ex_path: '\0'-terminated C string
374 * containing pathname of
375 * directory in local file system
379 * ex_anon_uid: ignored
380 * ex_anon_gid: ignored
381 * size: size in bytes of passed in nfsctl_export
383 * On success: returns zero
384 * On error: return code is negative errno value
386 static ssize_t write_unexport(struct file *file, char *buf, size_t size)
388 struct nfsctl_export *data;
390 if (size < sizeof(*data))
392 data = (struct nfsctl_export*)buf;
393 return exp_unexport(data);
397 * write_getfs - Get a variable-length NFS file handle by path
399 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
400 * Function remains to support old versions of nfs-utils.
403 * buf: struct nfsctl_fsparm
404 * gd_addr: socket address of client
405 * gd_path: '\0'-terminated C string
406 * containing pathname of
407 * directory in local file system
408 * gd_maxlen: maximum size of returned file
410 * size: size in bytes of passed in nfsctl_fsparm
412 * On success: passed-in buffer filled with a knfsd_fh structure
413 * (a variable-length raw NFS file handle);
414 * return code is the size in bytes of the file handle
415 * On error: return code is negative errno value
417 * Note: Only AF_INET client addresses are passed in, since gd_addr
418 * is the same size as a struct sockaddr_in.
420 static ssize_t write_getfs(struct file *file, char *buf, size_t size)
422 struct nfsctl_fsparm *data;
423 struct sockaddr_in *sin;
424 struct auth_domain *clp;
426 struct knfsd_fh *res;
429 if (size < sizeof(*data))
431 data = (struct nfsctl_fsparm*)buf;
432 err = -EPROTONOSUPPORT;
433 if (data->gd_addr.sa_family != AF_INET)
435 sin = (struct sockaddr_in *)&data->gd_addr;
436 if (data->gd_maxlen > NFS3_FHSIZE)
437 data->gd_maxlen = NFS3_FHSIZE;
439 res = (struct knfsd_fh*)buf;
443 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
445 clp = auth_unix_lookup(&init_net, &in6);
449 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
450 auth_domain_put(clp);
454 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
460 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
462 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
463 * Function remains to support old versions of nfs-utils.
466 * buf: struct nfsctl_fdparm
467 * gd_addr: socket address of client
468 * gd_path: '\0'-terminated C string
469 * containing pathname of
470 * directory in local file system
471 * gd_version: fdparm structure version
472 * size: size in bytes of passed in nfsctl_fdparm
474 * On success: passed-in buffer filled with nfsctl_res
475 * (a fixed-length raw NFS file handle);
476 * return code is the size in bytes of the file handle
477 * On error: return code is negative errno value
479 * Note: Only AF_INET client addresses are passed in, since gd_addr
480 * is the same size as a struct sockaddr_in.
482 static ssize_t write_getfd(struct file *file, char *buf, size_t size)
484 struct nfsctl_fdparm *data;
485 struct sockaddr_in *sin;
486 struct auth_domain *clp;
492 if (size < sizeof(*data))
494 data = (struct nfsctl_fdparm*)buf;
495 err = -EPROTONOSUPPORT;
496 if (data->gd_addr.sa_family != AF_INET)
499 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
503 sin = (struct sockaddr_in *)&data->gd_addr;
506 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
508 clp = auth_unix_lookup(&init_net, &in6);
512 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
513 auth_domain_put(clp);
518 memset(res,0, NFS_FHSIZE);
519 memcpy(res, &fh.fh_base, fh.fh_size);
525 #endif /* CONFIG_NFSD_DEPRECATED */
528 * write_unlock_ip - Release all locks used by a client
533 * buf: '\n'-terminated C string containing a
534 * presentation format IP address
535 * size: length of C string in @buf
537 * On success: returns zero if all specified locks were released;
538 * returns one if one or more locks were not released
539 * On error: return code is negative errno value
541 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
543 struct sockaddr_storage address;
544 struct sockaddr *sap = (struct sockaddr *)&address;
545 size_t salen = sizeof(address);
552 if (buf[size-1] != '\n')
556 if (qword_get(&buf, fo_path, size) < 0)
559 if (rpc_pton(fo_path, size, sap, salen) == 0)
562 return nlmsvc_unlock_all_by_ip(sap);
566 * write_unlock_fs - Release all locks on a local file system
571 * buf: '\n'-terminated C string containing the
572 * absolute pathname of a local file system
573 * size: length of C string in @buf
575 * On success: returns zero if all specified locks were released;
576 * returns one if one or more locks were not released
577 * On error: return code is negative errno value
579 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
589 if (buf[size-1] != '\n')
593 if (qword_get(&buf, fo_path, size) < 0)
596 error = kern_path(fo_path, 0, &path);
601 * XXX: Needs better sanity checking. Otherwise we could end up
602 * releasing locks on the wrong file system.
605 * 1. Does the path refer to a directory?
606 * 2. Is that directory a mount point, or
607 * 3. Is that directory the root of an exported file system?
609 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
616 * write_filehandle - Get a variable-length NFS file handle by path
618 * On input, the buffer contains a '\n'-terminated C string comprised of
619 * three alphanumeric words separated by whitespace. The string may
620 * contain escape sequences.
624 * domain: client domain name
625 * path: export pathname
626 * maxsize: numeric maximum size of
628 * size: length of C string in @buf
630 * On success: passed-in buffer filled with '\n'-terminated C
631 * string containing a ASCII hex text version
632 * of the NFS file handle;
633 * return code is the size in bytes of the string
634 * On error: return code is negative errno value
636 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
639 int uninitialized_var(maxsize);
642 struct auth_domain *dom;
648 if (buf[size-1] != '\n')
653 len = qword_get(&mesg, dname, size);
658 len = qword_get(&mesg, path, size);
662 len = get_int(&mesg, &maxsize);
666 if (maxsize < NFS_FHSIZE)
668 if (maxsize > NFS3_FHSIZE)
669 maxsize = NFS3_FHSIZE;
671 if (qword_get(&mesg, mesg, size)>0)
674 /* we have all the words, they are in buf.. */
675 dom = unix_domain_find(dname);
679 len = exp_rootfh(dom, path, &fh, maxsize);
680 auth_domain_put(dom);
685 len = SIMPLE_TRANSACTION_LIMIT;
686 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
692 * write_threads - Start NFSD, or report the current number of running threads
698 * On success: passed-in buffer filled with '\n'-terminated C
699 * string numeric value representing the number of
700 * running NFSD threads;
701 * return code is the size in bytes of the string
702 * On error: return code is zero
707 * buf: C string containing an unsigned
708 * integer value representing the
709 * number of NFSD threads to start
710 * size: non-zero length of C string in @buf
712 * On success: NFS service is started;
713 * passed-in buffer filled with '\n'-terminated C
714 * string numeric value representing the number of
715 * running NFSD threads;
716 * return code is the size in bytes of the string
717 * On error: return code is zero or a negative errno value
719 static ssize_t write_threads(struct file *file, char *buf, size_t size)
725 rv = get_int(&mesg, &newthreads);
730 rv = nfsd_svc(NFS_PORT, newthreads);
734 rv = nfsd_nrthreads();
736 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
740 * write_pool_threads - Set or report the current number of threads per pool
749 * buf: C string containing whitespace-
750 * separated unsigned integer values
751 * representing the number of NFSD
752 * threads to start in each pool
753 * size: non-zero length of C string in @buf
755 * On success: passed-in buffer filled with '\n'-terminated C
756 * string containing integer values representing the
757 * number of NFSD threads in each pool;
758 * return code is the size in bytes of the string
759 * On error: return code is zero or a negative errno value
761 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
763 /* if size > 0, look for an array of number of threads per node
764 * and apply them then write out number of threads per node as reply
773 mutex_lock(&nfsd_mutex);
774 npools = nfsd_nrpools();
777 * NFS is shut down. The admin can start it by
778 * writing to the threads file but NOT the pool_threads
779 * file, sorry. Report zero threads.
781 mutex_unlock(&nfsd_mutex);
786 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
788 if (nthreads == NULL)
792 for (i = 0; i < npools; i++) {
793 rv = get_int(&mesg, &nthreads[i]);
795 break; /* fewer numbers than pools */
797 goto out_free; /* syntax error */
802 rv = nfsd_set_nrthreads(i, nthreads);
807 rv = nfsd_get_nrthreads(npools, nthreads);
812 size = SIMPLE_TRANSACTION_LIMIT;
813 for (i = 0; i < npools && size > 0; i++) {
814 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
822 mutex_unlock(&nfsd_mutex);
826 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
829 char *vers, *minorp, sign;
830 int len, num, remaining;
837 /* Cannot change versions without updating
838 * nfsd_serv->sv_xdrsize, and reallocing
839 * rq_argp and rq_resp
842 if (buf[size-1] != '\n')
847 len = qword_get(&mesg, vers, size);
848 if (len <= 0) return -EINVAL;
851 if (sign == '+' || sign == '-')
852 num = simple_strtol((vers+1), &minorp, 0);
854 num = simple_strtol(vers, &minorp, 0);
855 if (*minorp == '.') {
858 minor = simple_strtoul(minorp+1, NULL, 0);
861 if (nfsd_minorversion(minor, sign == '-' ?
862 NFSD_CLEAR : NFSD_SET) < 0)
870 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
877 } while ((len = qword_get(&mesg, vers, size)) > 0);
878 /* If all get turned off, turn them back on, as
879 * having no versions is BAD
881 nfsd_reset_versions();
884 /* Now write current state into reply buffer */
887 remaining = SIMPLE_TRANSACTION_LIMIT;
888 for (num=2 ; num <= 4 ; num++)
889 if (nfsd_vers(num, NFSD_AVAIL)) {
890 len = snprintf(buf, remaining, "%s%c%d", sep,
891 nfsd_vers(num, NFSD_TEST)?'+':'-',
901 if (nfsd_vers(4, NFSD_AVAIL))
902 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
904 len = snprintf(buf, remaining, " %c4.%u",
905 (nfsd_vers(4, NFSD_TEST) &&
906 nfsd_minorversion(minor, NFSD_TEST)) ?
917 len = snprintf(buf, remaining, "\n");
924 * write_versions - Set or report the available NFS protocol versions
930 * On success: passed-in buffer filled with '\n'-terminated C
931 * string containing positive or negative integer
932 * values representing the current status of each
934 * return code is the size in bytes of the string
935 * On error: return code is zero or a negative errno value
940 * buf: C string containing whitespace-
941 * separated positive or negative
942 * integer values representing NFS
943 * protocol versions to enable ("+n")
945 * size: non-zero length of C string in @buf
947 * On success: status of zero or more protocol versions has
948 * been updated; passed-in buffer filled with
949 * '\n'-terminated C string containing positive
950 * or negative integer values representing the
951 * current status of each protocol version;
952 * return code is the size in bytes of the string
953 * On error: return code is zero or a negative errno value
955 static ssize_t write_versions(struct file *file, char *buf, size_t size)
959 mutex_lock(&nfsd_mutex);
960 rv = __write_versions(file, buf, size);
961 mutex_unlock(&nfsd_mutex);
966 * Zero-length write. Return a list of NFSD's current listener
969 static ssize_t __write_ports_names(char *buf)
971 if (nfsd_serv == NULL)
973 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
977 * A single 'fd' number was written, in which case it must be for
978 * a socket of a supported family/protocol, and we use it as an
981 static ssize_t __write_ports_addfd(char *buf)
986 err = get_int(&mesg, &fd);
987 if (err != 0 || fd < 0)
990 err = nfsd_create_serv();
994 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
996 svc_destroy(nfsd_serv);
1000 /* Decrease the count, but don't shut down the service */
1001 nfsd_serv->sv_nrthreads--;
1006 * A '-' followed by the 'name' of a socket means we close the socket.
1008 static ssize_t __write_ports_delfd(char *buf)
1013 toclose = kstrdup(buf + 1, GFP_KERNEL);
1014 if (toclose == NULL)
1017 if (nfsd_serv != NULL)
1018 len = svc_sock_names(nfsd_serv, buf,
1019 SIMPLE_TRANSACTION_LIMIT, toclose);
1025 * A transport listener is added by writing it's transport name and
1028 static ssize_t __write_ports_addxprt(char *buf)
1031 struct svc_xprt *xprt;
1034 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
1037 if (port < 1 || port > USHRT_MAX)
1040 err = nfsd_create_serv();
1044 err = svc_create_xprt(nfsd_serv, transport, &init_net,
1045 PF_INET, port, SVC_SOCK_ANONYMOUS);
1049 err = svc_create_xprt(nfsd_serv, transport, &init_net,
1050 PF_INET6, port, SVC_SOCK_ANONYMOUS);
1051 if (err < 0 && err != -EAFNOSUPPORT)
1054 /* Decrease the count, but don't shut down the service */
1055 nfsd_serv->sv_nrthreads--;
1058 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
1060 svc_close_xprt(xprt);
1064 svc_destroy(nfsd_serv);
1069 * A transport listener is removed by writing a "-", it's transport
1070 * name, and it's port number.
1072 static ssize_t __write_ports_delxprt(char *buf)
1074 struct svc_xprt *xprt;
1078 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1081 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
1084 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1088 svc_close_xprt(xprt);
1093 static ssize_t __write_ports(struct file *file, char *buf, size_t size)
1096 return __write_ports_names(buf);
1098 if (isdigit(buf[0]))
1099 return __write_ports_addfd(buf);
1101 if (buf[0] == '-' && isdigit(buf[1]))
1102 return __write_ports_delfd(buf);
1104 if (isalpha(buf[0]))
1105 return __write_ports_addxprt(buf);
1107 if (buf[0] == '-' && isalpha(buf[1]))
1108 return __write_ports_delxprt(buf);
1114 * write_ports - Pass a socket file descriptor or transport name to listen on
1120 * On success: passed-in buffer filled with a '\n'-terminated C
1121 * string containing a whitespace-separated list of
1122 * named NFSD listeners;
1123 * return code is the size in bytes of the string
1124 * On error: return code is zero or a negative errno value
1129 * buf: C string containing an unsigned
1130 * integer value representing a bound
1131 * but unconnected socket that is to be
1132 * used as an NFSD listener; listen(3)
1133 * must be called for a SOCK_STREAM
1134 * socket, otherwise it is ignored
1135 * size: non-zero length of C string in @buf
1137 * On success: NFS service is started;
1138 * passed-in buffer filled with a '\n'-terminated C
1139 * string containing a unique alphanumeric name of
1141 * return code is the size in bytes of the string
1142 * On error: return code is a negative errno value
1147 * buf: C string containing a "-" followed
1148 * by an integer value representing a
1149 * previously passed in socket file
1151 * size: non-zero length of C string in @buf
1153 * On success: NFS service no longer listens on that socket;
1154 * passed-in buffer filled with a '\n'-terminated C
1155 * string containing a unique name of the listener;
1156 * return code is the size in bytes of the string
1157 * On error: return code is a negative errno value
1162 * buf: C string containing a transport
1163 * name and an unsigned integer value
1164 * representing the port to listen on,
1165 * separated by whitespace
1166 * size: non-zero length of C string in @buf
1168 * On success: returns zero; NFS service is started
1169 * On error: return code is a negative errno value
1174 * buf: C string containing a "-" followed
1175 * by a transport name and an unsigned
1176 * integer value representing the port
1177 * to listen on, separated by whitespace
1178 * size: non-zero length of C string in @buf
1180 * On success: returns zero; NFS service no longer listens
1182 * On error: return code is a negative errno value
1184 static ssize_t write_ports(struct file *file, char *buf, size_t size)
1188 mutex_lock(&nfsd_mutex);
1189 rv = __write_ports(file, buf, size);
1190 mutex_unlock(&nfsd_mutex);
1195 int nfsd_max_blksize;
1198 * write_maxblksize - Set or report the current NFS blksize
1207 * buf: C string containing an unsigned
1208 * integer value representing the new
1210 * size: non-zero length of C string in @buf
1212 * On success: passed-in buffer filled with '\n'-terminated C string
1213 * containing numeric value of the current NFS blksize
1215 * return code is the size in bytes of the string
1216 * On error: return code is zero or a negative errno value
1218 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1223 int rv = get_int(&mesg, &bsize);
1226 /* force bsize into allowed range and
1227 * required alignment.
1231 if (bsize > NFSSVC_MAXBLKSIZE)
1232 bsize = NFSSVC_MAXBLKSIZE;
1234 mutex_lock(&nfsd_mutex);
1236 mutex_unlock(&nfsd_mutex);
1239 nfsd_max_blksize = bsize;
1240 mutex_unlock(&nfsd_mutex);
1243 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1247 #ifdef CONFIG_NFSD_V4
1248 static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1256 rv = get_int(&mesg, &i);
1260 * Some sanity checking. We don't have a reason for
1261 * these particular numbers, but problems with the
1263 * - Too short: the briefest network outage may
1264 * cause clients to lose all their locks. Also,
1265 * the frequent polling may be wasteful.
1266 * - Too long: do you really want reboot recovery
1267 * to take more than an hour? Or to make other
1268 * clients wait an hour before being able to
1269 * revoke a dead client's locks?
1271 if (i < 10 || i > 3600)
1276 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
1279 static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1283 mutex_lock(&nfsd_mutex);
1284 rv = __nfsd4_write_time(file, buf, size, time);
1285 mutex_unlock(&nfsd_mutex);
1290 * write_leasetime - Set or report the current NFSv4 lease time
1299 * buf: C string containing an unsigned
1300 * integer value representing the new
1301 * NFSv4 lease expiry time
1302 * size: non-zero length of C string in @buf
1304 * On success: passed-in buffer filled with '\n'-terminated C
1305 * string containing unsigned integer value of the
1306 * current lease expiry time;
1307 * return code is the size in bytes of the string
1308 * On error: return code is zero or a negative errno value
1310 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1312 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
1316 * write_gracetime - Set or report current NFSv4 grace period time
1318 * As above, but sets the time of the NFSv4 grace period.
1320 * Note this should never be set to less than the *previous*
1321 * lease-period time, but we don't try to enforce this. (In the common
1322 * case (a new boot), we don't know what the previous lease time was
1325 static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1327 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
1330 extern char *nfs4_recoverydir(void);
1332 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
1341 if (size > PATH_MAX || buf[size-1] != '\n')
1346 len = qword_get(&mesg, recdir, size);
1350 status = nfs4_reset_recoverydir(recdir);
1355 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1356 nfs4_recoverydir());
1360 * write_recoverydir - Set or report the pathname of the recovery directory
1369 * buf: C string containing the pathname
1370 * of the directory on a local file
1371 * system containing permanent NFSv4
1373 * size: non-zero length of C string in @buf
1375 * On success: passed-in buffer filled with '\n'-terminated C string
1376 * containing the current recovery pathname setting;
1377 * return code is the size in bytes of the string
1378 * On error: return code is zero or a negative errno value
1380 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1384 mutex_lock(&nfsd_mutex);
1385 rv = __write_recoverydir(file, buf, size);
1386 mutex_unlock(&nfsd_mutex);
1392 /*----------------------------------------------------------------------------*/
1394 * populating the filesystem.
1397 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1399 static struct tree_descr nfsd_files[] = {
1400 #ifdef CONFIG_NFSD_DEPRECATED
1401 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1402 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1403 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1404 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1405 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1406 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1407 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
1409 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
1410 [NFSD_Export_features] = {"export_features",
1411 &export_features_operations, S_IRUGO},
1412 [NFSD_FO_UnlockIP] = {"unlock_ip",
1413 &transaction_ops, S_IWUSR|S_IRUSR},
1414 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1415 &transaction_ops, S_IWUSR|S_IRUSR},
1416 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1417 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1418 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1419 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1420 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1421 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1422 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1423 #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
1424 [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO},
1425 #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
1426 #ifdef CONFIG_NFSD_V4
1427 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1428 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
1429 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1433 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1436 static struct dentry *nfsd_mount(struct file_system_type *fs_type,
1437 int flags, const char *dev_name, void *data)
1439 return mount_single(fs_type, flags, data, nfsd_fill_super);
1442 static struct file_system_type nfsd_fs_type = {
1443 .owner = THIS_MODULE,
1445 .mount = nfsd_mount,
1446 .kill_sb = kill_litter_super,
1449 #ifdef CONFIG_PROC_FS
1450 static int create_proc_exports_entry(void)
1452 struct proc_dir_entry *entry;
1454 entry = proc_mkdir("fs/nfs", NULL);
1457 entry = proc_create("exports", 0, entry, &exports_operations);
1462 #else /* CONFIG_PROC_FS */
1463 static int create_proc_exports_entry(void)
1469 static int __init init_nfsd(void)
1472 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1474 retval = nfs4_state_init(); /* nfs4 locking state */
1477 nfsd_stat_init(); /* Statistics */
1478 retval = nfsd_reply_cache_init();
1481 retval = nfsd_export_init();
1483 goto out_free_cache;
1484 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1485 retval = nfsd_idmap_init();
1487 goto out_free_lockd;
1488 retval = create_proc_exports_entry();
1490 goto out_free_idmap;
1491 retval = register_filesystem(&nfsd_fs_type);
1496 remove_proc_entry("fs/nfs/exports", NULL);
1497 remove_proc_entry("fs/nfs", NULL);
1499 nfsd_idmap_shutdown();
1501 nfsd_lockd_shutdown();
1502 nfsd_export_shutdown();
1504 nfsd_reply_cache_shutdown();
1506 nfsd_stat_shutdown();
1511 static void __exit exit_nfsd(void)
1513 nfsd_export_shutdown();
1514 nfsd_reply_cache_shutdown();
1515 remove_proc_entry("fs/nfs/exports", NULL);
1516 remove_proc_entry("fs/nfs", NULL);
1517 nfsd_stat_shutdown();
1518 nfsd_lockd_shutdown();
1519 nfsd_idmap_shutdown();
1521 unregister_filesystem(&nfsd_fs_type);
1524 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1525 MODULE_LICENSE("GPL");
1526 module_init(init_nfsd)
1527 module_exit(exit_nfsd)