1 // SPDX-License-Identifier: GPL-2.0-only
3 * Syscall interface to knfsd.
8 #include <linux/slab.h>
9 #include <linux/namei.h>
10 #include <linux/ctype.h>
12 #include <linux/sunrpc/svcsock.h>
13 #include <linux/lockd/lockd.h>
14 #include <linux/sunrpc/addr.h>
15 #include <linux/sunrpc/gss_api.h>
16 #include <linux/sunrpc/gss_krb5_enctypes.h>
17 #include <linux/sunrpc/rpc_pipe_fs.h>
18 #include <linux/module.h>
28 * We have a single directory with several nodes in it.
40 NFSD_Reply_Cache_Stats,
45 NFSD_SupportedEnctypes,
47 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
48 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
59 * write() for these nodes.
61 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
62 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
63 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
64 static ssize_t write_threads(struct file *file, char *buf, size_t size);
65 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
66 static ssize_t write_versions(struct file *file, char *buf, size_t size);
67 static ssize_t write_ports(struct file *file, char *buf, size_t size);
68 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
69 static ssize_t write_maxconn(struct file *file, char *buf, size_t size);
71 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
72 static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
73 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
74 static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size);
77 static ssize_t (*const write_op[])(struct file *, char *, size_t) = {
78 [NFSD_Fh] = write_filehandle,
79 [NFSD_FO_UnlockIP] = write_unlock_ip,
80 [NFSD_FO_UnlockFS] = write_unlock_fs,
81 [NFSD_Threads] = write_threads,
82 [NFSD_Pool_Threads] = write_pool_threads,
83 [NFSD_Versions] = write_versions,
84 [NFSD_Ports] = write_ports,
85 [NFSD_MaxBlkSize] = write_maxblksize,
86 [NFSD_MaxConnections] = write_maxconn,
88 [NFSD_Leasetime] = write_leasetime,
89 [NFSD_Gracetime] = write_gracetime,
90 [NFSD_RecoveryDir] = write_recoverydir,
91 [NFSD_V4EndGrace] = write_v4_end_grace,
95 static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
97 ino_t ino = file_inode(file)->i_ino;
101 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
104 data = simple_transaction_get(file, buf, size);
106 return PTR_ERR(data);
108 rv = write_op[ino](file, data, size);
110 simple_transaction_set(file, rv);
116 static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
118 if (! file->private_data) {
119 /* An attempt to read a transaction file without writing
120 * causes a 0-byte write so that the file can return
123 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
127 return simple_transaction_read(file, buf, size, pos);
130 static const struct file_operations transaction_ops = {
131 .write = nfsctl_transaction_write,
132 .read = nfsctl_transaction_read,
133 .release = simple_transaction_release,
134 .llseek = default_llseek,
137 static int exports_net_open(struct net *net, struct file *file)
140 struct seq_file *seq;
141 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
143 err = seq_open(file, &nfs_exports_op);
147 seq = file->private_data;
148 seq->private = nn->svc_export_cache;
152 static int exports_proc_open(struct inode *inode, struct file *file)
154 return exports_net_open(current->nsproxy->net_ns, file);
157 static const struct file_operations exports_proc_operations = {
158 .open = exports_proc_open,
161 .release = seq_release,
164 static int exports_nfsd_open(struct inode *inode, struct file *file)
166 return exports_net_open(inode->i_sb->s_fs_info, file);
169 static const struct file_operations exports_nfsd_operations = {
170 .open = exports_nfsd_open,
173 .release = seq_release,
176 static int export_features_show(struct seq_file *m, void *v)
178 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
182 static int export_features_open(struct inode *inode, struct file *file)
184 return single_open(file, export_features_show, NULL);
187 static const struct file_operations export_features_operations = {
188 .open = export_features_open,
191 .release = single_release,
194 #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
195 static int supported_enctypes_show(struct seq_file *m, void *v)
197 seq_printf(m, KRB5_SUPPORTED_ENCTYPES);
201 static int supported_enctypes_open(struct inode *inode, struct file *file)
203 return single_open(file, supported_enctypes_show, NULL);
206 static const struct file_operations supported_enctypes_ops = {
207 .open = supported_enctypes_open,
210 .release = single_release,
212 #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
214 static const struct file_operations pool_stats_operations = {
215 .open = nfsd_pool_stats_open,
218 .release = nfsd_pool_stats_release,
221 static const struct file_operations reply_cache_stats_operations = {
222 .open = nfsd_reply_cache_stats_open,
225 .release = single_release,
228 /*----------------------------------------------------------------------------*/
230 * payload - write methods
233 static inline struct net *netns(struct file *file)
235 return file_inode(file)->i_sb->s_fs_info;
239 * write_unlock_ip - Release all locks used by a client
244 * buf: '\n'-terminated C string containing a
245 * presentation format IP address
246 * size: length of C string in @buf
248 * On success: returns zero if all specified locks were released;
249 * returns one if one or more locks were not released
250 * On error: return code is negative errno value
252 static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
254 struct sockaddr_storage address;
255 struct sockaddr *sap = (struct sockaddr *)&address;
256 size_t salen = sizeof(address);
258 struct net *net = netns(file);
264 if (buf[size-1] != '\n')
268 if (qword_get(&buf, fo_path, size) < 0)
271 if (rpc_pton(net, fo_path, size, sap, salen) == 0)
274 return nlmsvc_unlock_all_by_ip(sap);
278 * write_unlock_fs - Release all locks on a local file system
283 * buf: '\n'-terminated C string containing the
284 * absolute pathname of a local file system
285 * size: length of C string in @buf
287 * On success: returns zero if all specified locks were released;
288 * returns one if one or more locks were not released
289 * On error: return code is negative errno value
291 static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
301 if (buf[size-1] != '\n')
305 if (qword_get(&buf, fo_path, size) < 0)
308 error = kern_path(fo_path, 0, &path);
313 * XXX: Needs better sanity checking. Otherwise we could end up
314 * releasing locks on the wrong file system.
317 * 1. Does the path refer to a directory?
318 * 2. Is that directory a mount point, or
319 * 3. Is that directory the root of an exported file system?
321 error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb);
328 * write_filehandle - Get a variable-length NFS file handle by path
330 * On input, the buffer contains a '\n'-terminated C string comprised of
331 * three alphanumeric words separated by whitespace. The string may
332 * contain escape sequences.
336 * domain: client domain name
337 * path: export pathname
338 * maxsize: numeric maximum size of
340 * size: length of C string in @buf
342 * On success: passed-in buffer filled with '\n'-terminated C
343 * string containing a ASCII hex text version
344 * of the NFS file handle;
345 * return code is the size in bytes of the string
346 * On error: return code is negative errno value
348 static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
351 int uninitialized_var(maxsize);
354 struct auth_domain *dom;
360 if (buf[size-1] != '\n')
365 len = qword_get(&mesg, dname, size);
370 len = qword_get(&mesg, path, size);
374 len = get_int(&mesg, &maxsize);
378 if (maxsize < NFS_FHSIZE)
380 maxsize = min(maxsize, NFS3_FHSIZE);
382 if (qword_get(&mesg, mesg, size)>0)
385 /* we have all the words, they are in buf.. */
386 dom = unix_domain_find(dname);
390 len = exp_rootfh(netns(file), dom, path, &fh, maxsize);
391 auth_domain_put(dom);
396 len = SIMPLE_TRANSACTION_LIMIT;
397 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
403 * write_threads - Start NFSD, or report the current number of running threads
409 * On success: passed-in buffer filled with '\n'-terminated C
410 * string numeric value representing the number of
411 * running NFSD threads;
412 * return code is the size in bytes of the string
413 * On error: return code is zero
418 * buf: C string containing an unsigned
419 * integer value representing the
420 * number of NFSD threads to start
421 * size: non-zero length of C string in @buf
423 * On success: NFS service is started;
424 * passed-in buffer filled with '\n'-terminated C
425 * string numeric value representing the number of
426 * running NFSD threads;
427 * return code is the size in bytes of the string
428 * On error: return code is zero or a negative errno value
430 static ssize_t write_threads(struct file *file, char *buf, size_t size)
434 struct net *net = netns(file);
438 rv = get_int(&mesg, &newthreads);
443 rv = nfsd_svc(newthreads, net, file->f_cred);
447 rv = nfsd_nrthreads(net);
449 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
453 * write_pool_threads - Set or report the current number of threads per pool
462 * buf: C string containing whitespace-
463 * separated unsigned integer values
464 * representing the number of NFSD
465 * threads to start in each pool
466 * size: non-zero length of C string in @buf
468 * On success: passed-in buffer filled with '\n'-terminated C
469 * string containing integer values representing the
470 * number of NFSD threads in each pool;
471 * return code is the size in bytes of the string
472 * On error: return code is zero or a negative errno value
474 static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
476 /* if size > 0, look for an array of number of threads per node
477 * and apply them then write out number of threads per node as reply
485 struct net *net = netns(file);
487 mutex_lock(&nfsd_mutex);
488 npools = nfsd_nrpools(net);
491 * NFS is shut down. The admin can start it by
492 * writing to the threads file but NOT the pool_threads
493 * file, sorry. Report zero threads.
495 mutex_unlock(&nfsd_mutex);
500 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
502 if (nthreads == NULL)
506 for (i = 0; i < npools; i++) {
507 rv = get_int(&mesg, &nthreads[i]);
509 break; /* fewer numbers than pools */
511 goto out_free; /* syntax error */
516 rv = nfsd_set_nrthreads(i, nthreads, net);
521 rv = nfsd_get_nrthreads(npools, nthreads, net);
526 size = SIMPLE_TRANSACTION_LIMIT;
527 for (i = 0; i < npools && size > 0; i++) {
528 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
536 mutex_unlock(&nfsd_mutex);
541 nfsd_print_version_support(struct nfsd_net *nn, char *buf, int remaining,
542 const char *sep, unsigned vers, int minor)
544 const char *format = minor < 0 ? "%s%c%u" : "%s%c%u.%u";
545 bool supported = !!nfsd_vers(nn, vers, NFSD_TEST);
547 if (vers == 4 && minor >= 0 &&
548 !nfsd_minorversion(nn, minor, NFSD_TEST))
550 if (minor == 0 && supported)
552 * special case for backward compatability.
553 * +4.0 is never reported, it is implied by
554 * +4, unless -4.0 is present.
557 return snprintf(buf, remaining, format, sep,
558 supported ? '+' : '-', vers, minor);
561 static ssize_t __write_versions(struct file *file, char *buf, size_t size)
564 char *vers, *minorp, sign;
565 int len, num, remaining;
568 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
572 /* Cannot change versions without updating
573 * nn->nfsd_serv->sv_xdrsize, and reallocing
574 * rq_argp and rq_resp
577 if (buf[size-1] != '\n')
582 len = qword_get(&mesg, vers, size);
583 if (len <= 0) return -EINVAL;
588 if (sign == '+' || sign == '-')
589 num = simple_strtol((vers+1), &minorp, 0);
591 num = simple_strtol(vers, &minorp, 0);
592 if (*minorp == '.') {
595 if (kstrtouint(minorp+1, 0, &minor) < 0)
599 cmd = sign == '-' ? NFSD_CLEAR : NFSD_SET;
603 nfsd_vers(nn, num, cmd);
606 if (*minorp == '.') {
607 if (nfsd_minorversion(nn, minor, cmd) < 0)
609 } else if ((cmd == NFSD_SET) != nfsd_vers(nn, num, NFSD_TEST)) {
611 * Either we have +4 and no minors are enabled,
612 * or we have -4 and at least one minor is enabled.
613 * In either case, propagate 'cmd' to all minors.
616 while (nfsd_minorversion(nn, minor, cmd) >= 0)
624 } while ((len = qword_get(&mesg, vers, size)) > 0);
625 /* If all get turned off, turn them back on, as
626 * having no versions is BAD
628 nfsd_reset_versions(nn);
631 /* Now write current state into reply buffer */
634 remaining = SIMPLE_TRANSACTION_LIMIT;
635 for (num=2 ; num <= 4 ; num++) {
637 if (!nfsd_vers(nn, num, NFSD_AVAIL))
642 len = nfsd_print_version_support(nn, buf, remaining,
644 if (len >= remaining)
652 } while (num == 4 && minor <= NFSD_SUPPORTED_MINOR_VERSION);
655 len = snprintf(buf, remaining, "\n");
656 if (len >= remaining)
662 * write_versions - Set or report the available NFS protocol versions
668 * On success: passed-in buffer filled with '\n'-terminated C
669 * string containing positive or negative integer
670 * values representing the current status of each
672 * return code is the size in bytes of the string
673 * On error: return code is zero or a negative errno value
678 * buf: C string containing whitespace-
679 * separated positive or negative
680 * integer values representing NFS
681 * protocol versions to enable ("+n")
683 * size: non-zero length of C string in @buf
685 * On success: status of zero or more protocol versions has
686 * been updated; passed-in buffer filled with
687 * '\n'-terminated C string containing positive
688 * or negative integer values representing the
689 * current status of each protocol version;
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_versions(struct file *file, char *buf, size_t size)
697 mutex_lock(&nfsd_mutex);
698 rv = __write_versions(file, buf, size);
699 mutex_unlock(&nfsd_mutex);
704 * Zero-length write. Return a list of NFSD's current listener
707 static ssize_t __write_ports_names(char *buf, struct net *net)
709 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
711 if (nn->nfsd_serv == NULL)
713 return svc_xprt_names(nn->nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
717 * A single 'fd' number was written, in which case it must be for
718 * a socket of a supported family/protocol, and we use it as an
721 static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred *cred)
725 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
727 err = get_int(&mesg, &fd);
728 if (err != 0 || fd < 0)
731 if (svc_alien_sock(net, fd)) {
732 printk(KERN_ERR "%s: socket net is different to NFSd's one\n", __func__);
736 err = nfsd_create_serv(net);
740 err = svc_addsock(nn->nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred);
746 /* Decrease the count, but don't shut down the service */
747 nn->nfsd_serv->sv_nrthreads--;
752 * A transport listener is added by writing it's transport name and
755 static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct cred *cred)
758 struct svc_xprt *xprt;
760 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
762 if (sscanf(buf, "%15s %5u", transport, &port) != 2)
765 if (port < 1 || port > USHRT_MAX)
768 err = nfsd_create_serv(net);
772 err = svc_create_xprt(nn->nfsd_serv, transport, net,
773 PF_INET, port, SVC_SOCK_ANONYMOUS, cred);
777 err = svc_create_xprt(nn->nfsd_serv, transport, net,
778 PF_INET6, port, SVC_SOCK_ANONYMOUS, cred);
779 if (err < 0 && err != -EAFNOSUPPORT)
782 /* Decrease the count, but don't shut down the service */
783 nn->nfsd_serv->sv_nrthreads--;
786 xprt = svc_find_xprt(nn->nfsd_serv, transport, net, PF_INET, port);
788 svc_close_xprt(xprt);
796 static ssize_t __write_ports(struct file *file, char *buf, size_t size,
800 return __write_ports_names(buf, net);
803 return __write_ports_addfd(buf, net, file->f_cred);
806 return __write_ports_addxprt(buf, net, file->f_cred);
812 * write_ports - Pass a socket file descriptor or transport name to listen on
818 * On success: passed-in buffer filled with a '\n'-terminated C
819 * string containing a whitespace-separated list of
820 * named NFSD listeners;
821 * return code is the size in bytes of the string
822 * On error: return code is zero or a negative errno value
827 * buf: C string containing an unsigned
828 * integer value representing a bound
829 * but unconnected socket that is to be
830 * used as an NFSD listener; listen(3)
831 * must be called for a SOCK_STREAM
832 * socket, otherwise it is ignored
833 * size: non-zero length of C string in @buf
835 * On success: NFS service is started;
836 * passed-in buffer filled with a '\n'-terminated C
837 * string containing a unique alphanumeric name of
839 * return code is the size in bytes of the string
840 * On error: return code is a negative errno value
845 * buf: C string containing a transport
846 * name and an unsigned integer value
847 * representing the port to listen on,
848 * separated by whitespace
849 * size: non-zero length of C string in @buf
851 * On success: returns zero; NFS service is started
852 * On error: return code is a negative errno value
854 static ssize_t write_ports(struct file *file, char *buf, size_t size)
858 mutex_lock(&nfsd_mutex);
859 rv = __write_ports(file, buf, size, netns(file));
860 mutex_unlock(&nfsd_mutex);
865 int nfsd_max_blksize;
868 * write_maxblksize - Set or report the current NFS blksize
877 * buf: C string containing an unsigned
878 * integer value representing the new
880 * size: non-zero length of C string in @buf
882 * On success: passed-in buffer filled with '\n'-terminated C string
883 * containing numeric value of the current NFS blksize
885 * return code is the size in bytes of the string
886 * On error: return code is zero or a negative errno value
888 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
891 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
895 int rv = get_int(&mesg, &bsize);
898 /* force bsize into allowed range and
899 * required alignment.
901 bsize = max_t(int, bsize, 1024);
902 bsize = min_t(int, bsize, NFSSVC_MAXBLKSIZE);
904 mutex_lock(&nfsd_mutex);
906 mutex_unlock(&nfsd_mutex);
909 nfsd_max_blksize = bsize;
910 mutex_unlock(&nfsd_mutex);
913 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
918 * write_maxconn - Set or report the current max number of connections
926 * buf: C string containing an unsigned
927 * integer value representing the new
928 * number of max connections
929 * size: non-zero length of C string in @buf
931 * On success: passed-in buffer filled with '\n'-terminated C string
932 * containing numeric value of max_connections setting
933 * for this net namespace;
934 * return code is the size in bytes of the string
935 * On error: return code is zero or a negative errno value
937 static ssize_t write_maxconn(struct file *file, char *buf, size_t size)
940 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
941 unsigned int maxconn = nn->max_connections;
944 int rv = get_uint(&mesg, &maxconn);
948 nn->max_connections = maxconn;
951 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%u\n", maxconn);
954 #ifdef CONFIG_NFSD_V4
955 static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size,
956 time_t *time, struct nfsd_net *nn)
964 rv = get_int(&mesg, &i);
968 * Some sanity checking. We don't have a reason for
969 * these particular numbers, but problems with the
971 * - Too short: the briefest network outage may
972 * cause clients to lose all their locks. Also,
973 * the frequent polling may be wasteful.
974 * - Too long: do you really want reboot recovery
975 * to take more than an hour? Or to make other
976 * clients wait an hour before being able to
977 * revoke a dead client's locks?
979 if (i < 10 || i > 3600)
984 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
987 static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size,
988 time_t *time, struct nfsd_net *nn)
992 mutex_lock(&nfsd_mutex);
993 rv = __nfsd4_write_time(file, buf, size, time, nn);
994 mutex_unlock(&nfsd_mutex);
999 * write_leasetime - Set or report the current NFSv4 lease time
1008 * buf: C string containing an unsigned
1009 * integer value representing the new
1010 * NFSv4 lease expiry time
1011 * size: non-zero length of C string in @buf
1013 * On success: passed-in buffer filled with '\n'-terminated C
1014 * string containing unsigned integer value of the
1015 * current lease expiry time;
1016 * return code is the size in bytes of the string
1017 * On error: return code is zero or a negative errno value
1019 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1021 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
1022 return nfsd4_write_time(file, buf, size, &nn->nfsd4_lease, nn);
1026 * write_gracetime - Set or report current NFSv4 grace period time
1028 * As above, but sets the time of the NFSv4 grace period.
1030 * Note this should never be set to less than the *previous*
1031 * lease-period time, but we don't try to enforce this. (In the common
1032 * case (a new boot), we don't know what the previous lease time was
1035 static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1037 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
1038 return nfsd4_write_time(file, buf, size, &nn->nfsd4_grace, nn);
1041 static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size,
1042 struct nfsd_net *nn)
1051 if (size > PATH_MAX || buf[size-1] != '\n')
1056 len = qword_get(&mesg, recdir, size);
1060 status = nfs4_reset_recoverydir(recdir);
1065 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1066 nfs4_recoverydir());
1070 * write_recoverydir - Set or report the pathname of the recovery directory
1079 * buf: C string containing the pathname
1080 * of the directory on a local file
1081 * system containing permanent NFSv4
1083 * size: non-zero length of C string in @buf
1085 * On success: passed-in buffer filled with '\n'-terminated C string
1086 * containing the current recovery pathname setting;
1087 * return code is the size in bytes of the string
1088 * On error: return code is zero or a negative errno value
1090 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1093 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
1095 mutex_lock(&nfsd_mutex);
1096 rv = __write_recoverydir(file, buf, size, nn);
1097 mutex_unlock(&nfsd_mutex);
1102 * write_v4_end_grace - release grace period for nfsd's v4.x lock manager
1111 * size: non-zero length of C string in @buf
1113 * passed-in buffer filled with "Y" or "N" with a newline
1114 * and NULL-terminated C string. This indicates whether
1115 * the grace period has ended in the current net
1116 * namespace. Return code is the size in bytes of the
1117 * string. Writing a string that starts with 'Y', 'y', or
1118 * '1' to the file will end the grace period for nfsd's v4
1121 static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size)
1123 struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id);
1132 nfsd4_end_grace(nn);
1139 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%c\n",
1140 nn->grace_ended ? 'Y' : 'N');
1145 /*----------------------------------------------------------------------------*/
1147 * populating the filesystem.
1150 static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1152 static const struct tree_descr nfsd_files[] = {
1153 [NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO},
1154 [NFSD_Export_features] = {"export_features",
1155 &export_features_operations, S_IRUGO},
1156 [NFSD_FO_UnlockIP] = {"unlock_ip",
1157 &transaction_ops, S_IWUSR|S_IRUSR},
1158 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1159 &transaction_ops, S_IWUSR|S_IRUSR},
1160 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1161 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
1162 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
1163 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
1164 [NFSD_Reply_Cache_Stats] = {"reply_cache_stats", &reply_cache_stats_operations, S_IRUGO},
1165 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
1166 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
1167 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
1168 [NFSD_MaxConnections] = {"max_connections", &transaction_ops, S_IWUSR|S_IRUGO},
1169 #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
1170 [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO},
1171 #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
1172 #ifdef CONFIG_NFSD_V4
1173 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
1174 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
1175 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
1176 [NFSD_V4EndGrace] = {"v4_end_grace", &transaction_ops, S_IWUSR|S_IRUGO},
1180 get_net(sb->s_fs_info);
1181 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1184 static struct dentry *nfsd_mount(struct file_system_type *fs_type,
1185 int flags, const char *dev_name, void *data)
1187 struct net *net = current->nsproxy->net_ns;
1188 return mount_ns(fs_type, flags, data, net, net->user_ns, nfsd_fill_super);
1191 static void nfsd_umount(struct super_block *sb)
1193 struct net *net = sb->s_fs_info;
1195 kill_litter_super(sb);
1199 static struct file_system_type nfsd_fs_type = {
1200 .owner = THIS_MODULE,
1202 .mount = nfsd_mount,
1203 .kill_sb = nfsd_umount,
1205 MODULE_ALIAS_FS("nfsd");
1207 #ifdef CONFIG_PROC_FS
1208 static int create_proc_exports_entry(void)
1210 struct proc_dir_entry *entry;
1212 entry = proc_mkdir("fs/nfs", NULL);
1215 entry = proc_create("exports", 0, entry,
1216 &exports_proc_operations);
1218 remove_proc_entry("fs/nfs", NULL);
1223 #else /* CONFIG_PROC_FS */
1224 static int create_proc_exports_entry(void)
1230 unsigned int nfsd_net_id;
1232 static __net_init int nfsd_init_net(struct net *net)
1235 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1237 retval = nfsd_export_init(net);
1239 goto out_export_error;
1240 retval = nfsd_idmap_init(net);
1242 goto out_idmap_error;
1243 nn->nfsd_versions = NULL;
1244 nn->nfsd4_minorversions = NULL;
1245 nn->nfsd4_lease = 90; /* default lease time */
1246 nn->nfsd4_grace = 90;
1247 nn->somebody_reclaimed = false;
1248 nn->track_reclaim_completes = false;
1249 nn->clverifier_counter = prandom_u32();
1250 nn->clientid_counter = prandom_u32();
1251 nn->s2s_cp_cl_id = nn->clientid_counter++;
1253 atomic_set(&nn->ntf_refcnt, 0);
1254 init_waitqueue_head(&nn->ntf_wq);
1258 nfsd_export_shutdown(net);
1263 static __net_exit void nfsd_exit_net(struct net *net)
1265 nfsd_idmap_shutdown(net);
1266 nfsd_export_shutdown(net);
1267 nfsd_netns_free_versions(net_generic(net, nfsd_net_id));
1270 static struct pernet_operations nfsd_net_ops = {
1271 .init = nfsd_init_net,
1272 .exit = nfsd_exit_net,
1274 .size = sizeof(struct nfsd_net),
1277 static int __init init_nfsd(void)
1282 retval = register_pernet_subsys(&nfsd_net_ops);
1285 retval = register_cld_notifier();
1287 goto out_unregister_pernet;
1288 retval = nfsd4_init_slabs();
1290 goto out_unregister_notifier;
1291 retval = nfsd4_init_pnfs();
1293 goto out_free_slabs;
1294 nfsd_fault_inject_init(); /* nfsd fault injection controls */
1295 nfsd_stat_init(); /* Statistics */
1296 retval = nfsd_reply_cache_init();
1299 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1300 retval = create_proc_exports_entry();
1302 goto out_free_lockd;
1303 retval = register_filesystem(&nfsd_fs_type);
1308 remove_proc_entry("fs/nfs/exports", NULL);
1309 remove_proc_entry("fs/nfs", NULL);
1311 nfsd_lockd_shutdown();
1312 nfsd_reply_cache_shutdown();
1314 nfsd_stat_shutdown();
1315 nfsd_fault_inject_cleanup();
1319 out_unregister_notifier:
1320 unregister_cld_notifier();
1321 out_unregister_pernet:
1322 unregister_pernet_subsys(&nfsd_net_ops);
1326 static void __exit exit_nfsd(void)
1328 nfsd_reply_cache_shutdown();
1329 remove_proc_entry("fs/nfs/exports", NULL);
1330 remove_proc_entry("fs/nfs", NULL);
1331 nfsd_stat_shutdown();
1332 nfsd_lockd_shutdown();
1335 nfsd_fault_inject_cleanup();
1336 unregister_filesystem(&nfsd_fs_type);
1337 unregister_cld_notifier();
1338 unregister_pernet_subsys(&nfsd_net_ops);
1342 MODULE_LICENSE("GPL");
1343 module_init(init_nfsd)
1344 module_exit(exit_nfsd)