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/lockd/lockd.h>
13 #include <linux/sunrpc/addr.h>
14 #include <linux/sunrpc/gss_api.h>
15 #include <linux/sunrpc/gss_krb5_enctypes.h>
16 #include <linux/sunrpc/rpc_pipe_fs.h>
17 #include <linux/module.h>
26 * We have a single directory with several nodes in it.
38 NFSD_Reply_Cache_Stats
,
43 NFSD_SupportedEnctypes
,
45 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
46 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
57 * write() for these nodes.
59 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
);
60 static ssize_t
write_unlock_ip(struct file
*file
, char *buf
, size_t size
);
61 static ssize_t
write_unlock_fs(struct file
*file
, char *buf
, size_t size
);
62 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
);
63 static ssize_t
write_pool_threads(struct file
*file
, char *buf
, size_t size
);
64 static ssize_t
write_versions(struct file
*file
, char *buf
, size_t size
);
65 static ssize_t
write_ports(struct file
*file
, char *buf
, size_t size
);
66 static ssize_t
write_maxblksize(struct file
*file
, char *buf
, size_t size
);
67 static ssize_t
write_maxconn(struct file
*file
, char *buf
, size_t size
);
69 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
);
70 static ssize_t
write_gracetime(struct file
*file
, char *buf
, size_t size
);
71 static ssize_t
write_recoverydir(struct file
*file
, char *buf
, size_t size
);
72 static ssize_t
write_v4_end_grace(struct file
*file
, char *buf
, size_t size
);
75 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
76 [NFSD_Fh
] = write_filehandle
,
77 [NFSD_FO_UnlockIP
] = write_unlock_ip
,
78 [NFSD_FO_UnlockFS
] = write_unlock_fs
,
79 [NFSD_Threads
] = write_threads
,
80 [NFSD_Pool_Threads
] = write_pool_threads
,
81 [NFSD_Versions
] = write_versions
,
82 [NFSD_Ports
] = write_ports
,
83 [NFSD_MaxBlkSize
] = write_maxblksize
,
84 [NFSD_MaxConnections
] = write_maxconn
,
86 [NFSD_Leasetime
] = write_leasetime
,
87 [NFSD_Gracetime
] = write_gracetime
,
88 [NFSD_RecoveryDir
] = write_recoverydir
,
89 [NFSD_V4EndGrace
] = write_v4_end_grace
,
93 static ssize_t
nfsctl_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
95 ino_t ino
= file_inode(file
)->i_ino
;
99 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
102 data
= simple_transaction_get(file
, buf
, size
);
104 return PTR_ERR(data
);
106 rv
= write_op
[ino
](file
, data
, size
);
108 simple_transaction_set(file
, rv
);
114 static ssize_t
nfsctl_transaction_read(struct file
*file
, char __user
*buf
, size_t size
, loff_t
*pos
)
116 if (! file
->private_data
) {
117 /* An attempt to read a transaction file without writing
118 * causes a 0-byte write so that the file can return
121 ssize_t rv
= nfsctl_transaction_write(file
, buf
, 0, pos
);
125 return simple_transaction_read(file
, buf
, size
, pos
);
128 static const struct file_operations transaction_ops
= {
129 .write
= nfsctl_transaction_write
,
130 .read
= nfsctl_transaction_read
,
131 .release
= simple_transaction_release
,
132 .llseek
= default_llseek
,
135 static int exports_net_open(struct net
*net
, struct file
*file
)
138 struct seq_file
*seq
;
139 struct nfsd_net
*nn
= net_generic(net
, nfsd_net_id
);
141 err
= seq_open(file
, &nfs_exports_op
);
145 seq
= file
->private_data
;
146 seq
->private = nn
->svc_export_cache
;
150 static int exports_proc_open(struct inode
*inode
, struct file
*file
)
152 return exports_net_open(current
->nsproxy
->net_ns
, file
);
155 static const struct file_operations exports_proc_operations
= {
156 .open
= exports_proc_open
,
159 .release
= seq_release
,
160 .owner
= THIS_MODULE
,
163 static int exports_nfsd_open(struct inode
*inode
, struct file
*file
)
165 return exports_net_open(inode
->i_sb
->s_fs_info
, file
);
168 static const struct file_operations exports_nfsd_operations
= {
169 .open
= exports_nfsd_open
,
172 .release
= seq_release
,
173 .owner
= THIS_MODULE
,
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
,
219 .owner
= THIS_MODULE
,
222 static struct file_operations reply_cache_stats_operations
= {
223 .open
= nfsd_reply_cache_stats_open
,
226 .release
= single_release
,
229 /*----------------------------------------------------------------------------*/
231 * payload - write methods
234 static inline struct net
*netns(struct file
*file
)
236 return file_inode(file
)->i_sb
->s_fs_info
;
240 * write_unlock_ip - Release all locks used by a client
245 * buf: '\n'-terminated C string containing a
246 * presentation format IP address
247 * size: length of C string in @buf
249 * On success: returns zero if all specified locks were released;
250 * returns one if one or more locks were not released
251 * On error: return code is negative errno value
253 static ssize_t
write_unlock_ip(struct file
*file
, char *buf
, size_t size
)
255 struct sockaddr_storage address
;
256 struct sockaddr
*sap
= (struct sockaddr
*)&address
;
257 size_t salen
= sizeof(address
);
259 struct net
*net
= netns(file
);
265 if (buf
[size
-1] != '\n')
269 if (qword_get(&buf
, fo_path
, size
) < 0)
272 if (rpc_pton(net
, fo_path
, size
, sap
, salen
) == 0)
275 return nlmsvc_unlock_all_by_ip(sap
);
279 * write_unlock_fs - Release all locks on a local file system
284 * buf: '\n'-terminated C string containing the
285 * absolute pathname of a local file system
286 * size: length of C string in @buf
288 * On success: returns zero if all specified locks were released;
289 * returns one if one or more locks were not released
290 * On error: return code is negative errno value
292 static ssize_t
write_unlock_fs(struct file
*file
, char *buf
, size_t size
)
302 if (buf
[size
-1] != '\n')
306 if (qword_get(&buf
, fo_path
, size
) < 0)
309 error
= kern_path(fo_path
, 0, &path
);
314 * XXX: Needs better sanity checking. Otherwise we could end up
315 * releasing locks on the wrong file system.
318 * 1. Does the path refer to a directory?
319 * 2. Is that directory a mount point, or
320 * 3. Is that directory the root of an exported file system?
322 error
= nlmsvc_unlock_all_by_sb(path
.dentry
->d_sb
);
329 * write_filehandle - Get a variable-length NFS file handle by path
331 * On input, the buffer contains a '\n'-terminated C string comprised of
332 * three alphanumeric words separated by whitespace. The string may
333 * contain escape sequences.
337 * domain: client domain name
338 * path: export pathname
339 * maxsize: numeric maximum size of
341 * size: length of C string in @buf
343 * On success: passed-in buffer filled with '\n'-terminated C
344 * string containing a ASCII hex text version
345 * of the NFS file handle;
346 * return code is the size in bytes of the string
347 * On error: return code is negative errno value
349 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
)
352 int uninitialized_var(maxsize
);
355 struct auth_domain
*dom
;
361 if (buf
[size
-1] != '\n')
366 len
= qword_get(&mesg
, dname
, size
);
371 len
= qword_get(&mesg
, path
, size
);
375 len
= get_int(&mesg
, &maxsize
);
379 if (maxsize
< NFS_FHSIZE
)
381 maxsize
= min(maxsize
, NFS3_FHSIZE
);
383 if (qword_get(&mesg
, mesg
, size
)>0)
386 /* we have all the words, they are in buf.. */
387 dom
= unix_domain_find(dname
);
391 len
= exp_rootfh(netns(file
), dom
, path
, &fh
, maxsize
);
392 auth_domain_put(dom
);
397 len
= SIMPLE_TRANSACTION_LIMIT
;
398 qword_addhex(&mesg
, &len
, (char*)&fh
.fh_base
, fh
.fh_size
);
404 * write_threads - Start NFSD, or report the current number of running threads
410 * On success: passed-in buffer filled with '\n'-terminated C
411 * string numeric value representing the number of
412 * running NFSD threads;
413 * return code is the size in bytes of the string
414 * On error: return code is zero
419 * buf: C string containing an unsigned
420 * integer value representing the
421 * number of NFSD threads to start
422 * size: non-zero length of C string in @buf
424 * On success: NFS service is started;
425 * passed-in buffer filled with '\n'-terminated C
426 * string numeric value representing the number of
427 * running NFSD threads;
428 * return code is the size in bytes of the string
429 * On error: return code is zero or a negative errno value
431 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
)
435 struct net
*net
= netns(file
);
439 rv
= get_int(&mesg
, &newthreads
);
444 rv
= nfsd_svc(newthreads
, net
);
448 rv
= nfsd_nrthreads(net
);
450 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%d\n", rv
);
454 * write_pool_threads - Set or report the current number of threads per pool
463 * buf: C string containing whitespace-
464 * separated unsigned integer values
465 * representing the number of NFSD
466 * threads to start in each pool
467 * size: non-zero length of C string in @buf
469 * On success: passed-in buffer filled with '\n'-terminated C
470 * string containing integer values representing the
471 * number of NFSD threads in each pool;
472 * return code is the size in bytes of the string
473 * On error: return code is zero or a negative errno value
475 static ssize_t
write_pool_threads(struct file
*file
, char *buf
, size_t size
)
477 /* if size > 0, look for an array of number of threads per node
478 * and apply them then write out number of threads per node as reply
486 struct net
*net
= netns(file
);
488 mutex_lock(&nfsd_mutex
);
489 npools
= nfsd_nrpools(net
);
492 * NFS is shut down. The admin can start it by
493 * writing to the threads file but NOT the pool_threads
494 * file, sorry. Report zero threads.
496 mutex_unlock(&nfsd_mutex
);
501 nthreads
= kcalloc(npools
, sizeof(int), GFP_KERNEL
);
503 if (nthreads
== NULL
)
507 for (i
= 0; i
< npools
; i
++) {
508 rv
= get_int(&mesg
, &nthreads
[i
]);
510 break; /* fewer numbers than pools */
512 goto out_free
; /* syntax error */
517 rv
= nfsd_set_nrthreads(i
, nthreads
, net
);
522 rv
= nfsd_get_nrthreads(npools
, nthreads
, net
);
527 size
= SIMPLE_TRANSACTION_LIMIT
;
528 for (i
= 0; i
< npools
&& size
> 0; i
++) {
529 snprintf(mesg
, size
, "%d%c", nthreads
[i
], (i
== npools
-1 ? '\n' : ' '));
537 mutex_unlock(&nfsd_mutex
);
541 static ssize_t
__write_versions(struct file
*file
, char *buf
, size_t size
)
544 char *vers
, *minorp
, sign
;
545 int len
, num
, remaining
;
549 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
553 /* Cannot change versions without updating
554 * nn->nfsd_serv->sv_xdrsize, and reallocing
555 * rq_argp and rq_resp
558 if (buf
[size
-1] != '\n')
563 len
= qword_get(&mesg
, vers
, size
);
564 if (len
<= 0) return -EINVAL
;
567 if (sign
== '+' || sign
== '-')
568 num
= simple_strtol((vers
+1), &minorp
, 0);
570 num
= simple_strtol(vers
, &minorp
, 0);
571 if (*minorp
== '.') {
574 minor
= simple_strtoul(minorp
+1, NULL
, 0);
577 if (nfsd_minorversion(minor
, sign
== '-' ?
578 NFSD_CLEAR
: NFSD_SET
) < 0)
586 nfsd_vers(num
, sign
== '-' ? NFSD_CLEAR
: NFSD_SET
);
593 } while ((len
= qword_get(&mesg
, vers
, size
)) > 0);
594 /* If all get turned off, turn them back on, as
595 * having no versions is BAD
597 nfsd_reset_versions();
600 /* Now write current state into reply buffer */
603 remaining
= SIMPLE_TRANSACTION_LIMIT
;
604 for (num
=2 ; num
<= 4 ; num
++)
605 if (nfsd_vers(num
, NFSD_AVAIL
)) {
606 len
= snprintf(buf
, remaining
, "%s%c%d", sep
,
607 nfsd_vers(num
, NFSD_TEST
)?'+':'-',
611 if (len
>= remaining
)
617 if (nfsd_vers(4, NFSD_AVAIL
))
618 for (minor
= 1; minor
<= NFSD_SUPPORTED_MINOR_VERSION
;
620 len
= snprintf(buf
, remaining
, " %c4.%u",
621 (nfsd_vers(4, NFSD_TEST
) &&
622 nfsd_minorversion(minor
, NFSD_TEST
)) ?
626 if (len
>= remaining
)
633 len
= snprintf(buf
, remaining
, "\n");
634 if (len
>= remaining
)
640 * write_versions - Set or report the available NFS protocol versions
646 * On success: passed-in buffer filled with '\n'-terminated C
647 * string containing positive or negative integer
648 * values representing the current status of each
650 * return code is the size in bytes of the string
651 * On error: return code is zero or a negative errno value
656 * buf: C string containing whitespace-
657 * separated positive or negative
658 * integer values representing NFS
659 * protocol versions to enable ("+n")
661 * size: non-zero length of C string in @buf
663 * On success: status of zero or more protocol versions has
664 * been updated; passed-in buffer filled with
665 * '\n'-terminated C string containing positive
666 * or negative integer values representing the
667 * current status of each protocol version;
668 * return code is the size in bytes of the string
669 * On error: return code is zero or a negative errno value
671 static ssize_t
write_versions(struct file
*file
, char *buf
, size_t size
)
675 mutex_lock(&nfsd_mutex
);
676 rv
= __write_versions(file
, buf
, size
);
677 mutex_unlock(&nfsd_mutex
);
682 * Zero-length write. Return a list of NFSD's current listener
685 static ssize_t
__write_ports_names(char *buf
, struct net
*net
)
687 struct nfsd_net
*nn
= net_generic(net
, nfsd_net_id
);
689 if (nn
->nfsd_serv
== NULL
)
691 return svc_xprt_names(nn
->nfsd_serv
, buf
, SIMPLE_TRANSACTION_LIMIT
);
695 * A single 'fd' number was written, in which case it must be for
696 * a socket of a supported family/protocol, and we use it as an
699 static ssize_t
__write_ports_addfd(char *buf
, struct net
*net
)
703 struct nfsd_net
*nn
= net_generic(net
, nfsd_net_id
);
705 err
= get_int(&mesg
, &fd
);
706 if (err
!= 0 || fd
< 0)
709 if (svc_alien_sock(net
, fd
)) {
710 printk(KERN_ERR
"%s: socket net is different to NFSd's one\n", __func__
);
714 err
= nfsd_create_serv(net
);
718 err
= svc_addsock(nn
->nfsd_serv
, fd
, buf
, SIMPLE_TRANSACTION_LIMIT
);
724 /* Decrease the count, but don't shut down the service */
725 nn
->nfsd_serv
->sv_nrthreads
--;
730 * A transport listener is added by writing it's transport name and
733 static ssize_t
__write_ports_addxprt(char *buf
, struct net
*net
)
736 struct svc_xprt
*xprt
;
738 struct nfsd_net
*nn
= net_generic(net
, nfsd_net_id
);
740 if (sscanf(buf
, "%15s %5u", transport
, &port
) != 2)
743 if (port
< 1 || port
> USHRT_MAX
)
746 err
= nfsd_create_serv(net
);
750 err
= svc_create_xprt(nn
->nfsd_serv
, transport
, net
,
751 PF_INET
, port
, SVC_SOCK_ANONYMOUS
);
755 err
= svc_create_xprt(nn
->nfsd_serv
, transport
, net
,
756 PF_INET6
, port
, SVC_SOCK_ANONYMOUS
);
757 if (err
< 0 && err
!= -EAFNOSUPPORT
)
760 /* Decrease the count, but don't shut down the service */
761 nn
->nfsd_serv
->sv_nrthreads
--;
764 xprt
= svc_find_xprt(nn
->nfsd_serv
, transport
, net
, PF_INET
, port
);
766 svc_close_xprt(xprt
);
774 static ssize_t
__write_ports(struct file
*file
, char *buf
, size_t size
,
778 return __write_ports_names(buf
, net
);
781 return __write_ports_addfd(buf
, net
);
784 return __write_ports_addxprt(buf
, net
);
790 * write_ports - Pass a socket file descriptor or transport name to listen on
796 * On success: passed-in buffer filled with a '\n'-terminated C
797 * string containing a whitespace-separated list of
798 * named NFSD listeners;
799 * return code is the size in bytes of the string
800 * On error: return code is zero or a negative errno value
805 * buf: C string containing an unsigned
806 * integer value representing a bound
807 * but unconnected socket that is to be
808 * used as an NFSD listener; listen(3)
809 * must be called for a SOCK_STREAM
810 * socket, otherwise it is ignored
811 * size: non-zero length of C string in @buf
813 * On success: NFS service is started;
814 * passed-in buffer filled with a '\n'-terminated C
815 * string containing a unique alphanumeric name of
817 * return code is the size in bytes of the string
818 * On error: return code is a negative errno value
823 * buf: C string containing a transport
824 * name and an unsigned integer value
825 * representing the port to listen on,
826 * separated by whitespace
827 * size: non-zero length of C string in @buf
829 * On success: returns zero; NFS service is started
830 * On error: return code is a negative errno value
832 static ssize_t
write_ports(struct file
*file
, char *buf
, size_t size
)
836 mutex_lock(&nfsd_mutex
);
837 rv
= __write_ports(file
, buf
, size
, netns(file
));
838 mutex_unlock(&nfsd_mutex
);
843 int nfsd_max_blksize
;
846 * write_maxblksize - Set or report the current NFS blksize
855 * buf: C string containing an unsigned
856 * integer value representing the new
858 * size: non-zero length of C string in @buf
860 * On success: passed-in buffer filled with '\n'-terminated C string
861 * containing numeric value of the current NFS blksize
863 * return code is the size in bytes of the string
864 * On error: return code is zero or a negative errno value
866 static ssize_t
write_maxblksize(struct file
*file
, char *buf
, size_t size
)
869 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
873 int rv
= get_int(&mesg
, &bsize
);
876 /* force bsize into allowed range and
877 * required alignment.
879 bsize
= max_t(int, bsize
, 1024);
880 bsize
= min_t(int, bsize
, NFSSVC_MAXBLKSIZE
);
882 mutex_lock(&nfsd_mutex
);
884 mutex_unlock(&nfsd_mutex
);
887 nfsd_max_blksize
= bsize
;
888 mutex_unlock(&nfsd_mutex
);
891 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%d\n",
896 * write_maxconn - Set or report the current max number of connections
904 * buf: C string containing an unsigned
905 * integer value representing the new
906 * number of max connections
907 * size: non-zero length of C string in @buf
909 * On success: passed-in buffer filled with '\n'-terminated C string
910 * containing numeric value of max_connections setting
911 * for this net namespace;
912 * return code is the size in bytes of the string
913 * On error: return code is zero or a negative errno value
915 static ssize_t
write_maxconn(struct file
*file
, char *buf
, size_t size
)
918 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
919 unsigned int maxconn
= nn
->max_connections
;
922 int rv
= get_uint(&mesg
, &maxconn
);
926 nn
->max_connections
= maxconn
;
929 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%u\n", maxconn
);
932 #ifdef CONFIG_NFSD_V4
933 static ssize_t
__nfsd4_write_time(struct file
*file
, char *buf
, size_t size
,
934 time_t *time
, struct nfsd_net
*nn
)
942 rv
= get_int(&mesg
, &i
);
946 * Some sanity checking. We don't have a reason for
947 * these particular numbers, but problems with the
949 * - Too short: the briefest network outage may
950 * cause clients to lose all their locks. Also,
951 * the frequent polling may be wasteful.
952 * - Too long: do you really want reboot recovery
953 * to take more than an hour? Or to make other
954 * clients wait an hour before being able to
955 * revoke a dead client's locks?
957 if (i
< 10 || i
> 3600)
962 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%ld\n", *time
);
965 static ssize_t
nfsd4_write_time(struct file
*file
, char *buf
, size_t size
,
966 time_t *time
, struct nfsd_net
*nn
)
970 mutex_lock(&nfsd_mutex
);
971 rv
= __nfsd4_write_time(file
, buf
, size
, time
, nn
);
972 mutex_unlock(&nfsd_mutex
);
977 * write_leasetime - Set or report the current NFSv4 lease time
986 * buf: C string containing an unsigned
987 * integer value representing the new
988 * NFSv4 lease expiry time
989 * size: non-zero length of C string in @buf
991 * On success: passed-in buffer filled with '\n'-terminated C
992 * string containing unsigned integer value of the
993 * current lease expiry time;
994 * return code is the size in bytes of the string
995 * On error: return code is zero or a negative errno value
997 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
)
999 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
1000 return nfsd4_write_time(file
, buf
, size
, &nn
->nfsd4_lease
, nn
);
1004 * write_gracetime - Set or report current NFSv4 grace period time
1006 * As above, but sets the time of the NFSv4 grace period.
1008 * Note this should never be set to less than the *previous*
1009 * lease-period time, but we don't try to enforce this. (In the common
1010 * case (a new boot), we don't know what the previous lease time was
1013 static ssize_t
write_gracetime(struct file
*file
, char *buf
, size_t size
)
1015 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
1016 return nfsd4_write_time(file
, buf
, size
, &nn
->nfsd4_grace
, nn
);
1019 static ssize_t
__write_recoverydir(struct file
*file
, char *buf
, size_t size
,
1020 struct nfsd_net
*nn
)
1029 if (size
> PATH_MAX
|| buf
[size
-1] != '\n')
1034 len
= qword_get(&mesg
, recdir
, size
);
1038 status
= nfs4_reset_recoverydir(recdir
);
1043 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%s\n",
1044 nfs4_recoverydir());
1048 * write_recoverydir - Set or report the pathname of the recovery directory
1057 * buf: C string containing the pathname
1058 * of the directory on a local file
1059 * system containing permanent NFSv4
1061 * size: non-zero length of C string in @buf
1063 * On success: passed-in buffer filled with '\n'-terminated C string
1064 * containing the current recovery pathname setting;
1065 * return code is the size in bytes of the string
1066 * On error: return code is zero or a negative errno value
1068 static ssize_t
write_recoverydir(struct file
*file
, char *buf
, size_t size
)
1071 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
1073 mutex_lock(&nfsd_mutex
);
1074 rv
= __write_recoverydir(file
, buf
, size
, nn
);
1075 mutex_unlock(&nfsd_mutex
);
1080 * write_v4_end_grace - release grace period for nfsd's v4.x lock manager
1089 * size: non-zero length of C string in @buf
1091 * passed-in buffer filled with "Y" or "N" with a newline
1092 * and NULL-terminated C string. This indicates whether
1093 * the grace period has ended in the current net
1094 * namespace. Return code is the size in bytes of the
1095 * string. Writing a string that starts with 'Y', 'y', or
1096 * '1' to the file will end the grace period for nfsd's v4
1099 static ssize_t
write_v4_end_grace(struct file
*file
, char *buf
, size_t size
)
1101 struct nfsd_net
*nn
= net_generic(netns(file
), nfsd_net_id
);
1108 nfsd4_end_grace(nn
);
1115 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%c\n",
1116 nn
->grace_ended
? 'Y' : 'N');
1121 /*----------------------------------------------------------------------------*/
1123 * populating the filesystem.
1126 static int nfsd_fill_super(struct super_block
* sb
, void * data
, int silent
)
1128 static struct tree_descr nfsd_files
[] = {
1129 [NFSD_List
] = {"exports", &exports_nfsd_operations
, S_IRUGO
},
1130 [NFSD_Export_features
] = {"export_features",
1131 &export_features_operations
, S_IRUGO
},
1132 [NFSD_FO_UnlockIP
] = {"unlock_ip",
1133 &transaction_ops
, S_IWUSR
|S_IRUSR
},
1134 [NFSD_FO_UnlockFS
] = {"unlock_filesystem",
1135 &transaction_ops
, S_IWUSR
|S_IRUSR
},
1136 [NFSD_Fh
] = {"filehandle", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1137 [NFSD_Threads
] = {"threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1138 [NFSD_Pool_Threads
] = {"pool_threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1139 [NFSD_Pool_Stats
] = {"pool_stats", &pool_stats_operations
, S_IRUGO
},
1140 [NFSD_Reply_Cache_Stats
] = {"reply_cache_stats", &reply_cache_stats_operations
, S_IRUGO
},
1141 [NFSD_Versions
] = {"versions", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1142 [NFSD_Ports
] = {"portlist", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1143 [NFSD_MaxBlkSize
] = {"max_block_size", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1144 [NFSD_MaxConnections
] = {"max_connections", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1145 #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
1146 [NFSD_SupportedEnctypes
] = {"supported_krb5_enctypes", &supported_enctypes_ops
, S_IRUGO
},
1147 #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
1148 #ifdef CONFIG_NFSD_V4
1149 [NFSD_Leasetime
] = {"nfsv4leasetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1150 [NFSD_Gracetime
] = {"nfsv4gracetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1151 [NFSD_RecoveryDir
] = {"nfsv4recoverydir", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1152 [NFSD_V4EndGrace
] = {"v4_end_grace", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1156 struct net
*net
= data
;
1159 ret
= simple_fill_super(sb
, 0x6e667364, nfsd_files
);
1162 sb
->s_fs_info
= get_net(net
);
1166 static struct dentry
*nfsd_mount(struct file_system_type
*fs_type
,
1167 int flags
, const char *dev_name
, void *data
)
1169 return mount_ns(fs_type
, flags
, current
->nsproxy
->net_ns
, nfsd_fill_super
);
1172 static void nfsd_umount(struct super_block
*sb
)
1174 struct net
*net
= sb
->s_fs_info
;
1176 kill_litter_super(sb
);
1180 static struct file_system_type nfsd_fs_type
= {
1181 .owner
= THIS_MODULE
,
1183 .mount
= nfsd_mount
,
1184 .kill_sb
= nfsd_umount
,
1186 MODULE_ALIAS_FS("nfsd");
1188 #ifdef CONFIG_PROC_FS
1189 static int create_proc_exports_entry(void)
1191 struct proc_dir_entry
*entry
;
1193 entry
= proc_mkdir("fs/nfs", NULL
);
1196 entry
= proc_create("exports", 0, entry
,
1197 &exports_proc_operations
);
1199 remove_proc_entry("fs/nfs", NULL
);
1204 #else /* CONFIG_PROC_FS */
1205 static int create_proc_exports_entry(void)
1213 static __net_init
int nfsd_init_net(struct net
*net
)
1216 struct nfsd_net
*nn
= net_generic(net
, nfsd_net_id
);
1218 retval
= nfsd_export_init(net
);
1220 goto out_export_error
;
1221 retval
= nfsd_idmap_init(net
);
1223 goto out_idmap_error
;
1224 nn
->nfsd4_lease
= 90; /* default lease time */
1225 nn
->nfsd4_grace
= 90;
1229 nfsd_export_shutdown(net
);
1234 static __net_exit
void nfsd_exit_net(struct net
*net
)
1236 nfsd_idmap_shutdown(net
);
1237 nfsd_export_shutdown(net
);
1240 static struct pernet_operations nfsd_net_ops
= {
1241 .init
= nfsd_init_net
,
1242 .exit
= nfsd_exit_net
,
1244 .size
= sizeof(struct nfsd_net
),
1247 static int __init
init_nfsd(void)
1250 printk(KERN_INFO
"Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1252 retval
= register_cld_notifier();
1255 retval
= register_pernet_subsys(&nfsd_net_ops
);
1257 goto out_unregister_notifier
;
1258 retval
= nfsd4_init_slabs();
1260 goto out_unregister_pernet
;
1261 retval
= nfsd_fault_inject_init(); /* nfsd fault injection controls */
1263 goto out_free_slabs
;
1264 nfsd_stat_init(); /* Statistics */
1265 retval
= nfsd_reply_cache_init();
1268 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1269 retval
= create_proc_exports_entry();
1271 goto out_free_lockd
;
1272 retval
= register_filesystem(&nfsd_fs_type
);
1277 remove_proc_entry("fs/nfs/exports", NULL
);
1278 remove_proc_entry("fs/nfs", NULL
);
1280 nfsd_lockd_shutdown();
1281 nfsd_reply_cache_shutdown();
1283 nfsd_stat_shutdown();
1284 nfsd_fault_inject_cleanup();
1287 out_unregister_pernet
:
1288 unregister_pernet_subsys(&nfsd_net_ops
);
1289 out_unregister_notifier
:
1290 unregister_cld_notifier();
1294 static void __exit
exit_nfsd(void)
1296 nfsd_reply_cache_shutdown();
1297 remove_proc_entry("fs/nfs/exports", NULL
);
1298 remove_proc_entry("fs/nfs", NULL
);
1299 nfsd_stat_shutdown();
1300 nfsd_lockd_shutdown();
1302 nfsd_fault_inject_cleanup();
1303 unregister_filesystem(&nfsd_fs_type
);
1304 unregister_pernet_subsys(&nfsd_net_ops
);
1305 unregister_cld_notifier();
1308 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1309 MODULE_LICENSE("GPL");
1310 module_init(init_nfsd
)
1311 module_exit(exit_nfsd
)