2 * Syscall interface to knfsd.
4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 #include <linux/slab.h>
8 #include <linux/namei.h>
9 #include <linux/ctype.h>
11 #include <linux/nfsd_idmap.h>
12 #include <linux/sunrpc/svcsock.h>
13 #include <linux/nfsd/syscall.h>
14 #include <linux/lockd/lockd.h>
15 #include <linux/sunrpc/clnt.h>
21 * We have a single directory with 9 nodes in it.
44 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
45 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
55 * write() for these nodes.
57 static ssize_t
write_svc(struct file
*file
, char *buf
, size_t size
);
58 static ssize_t
write_add(struct file
*file
, char *buf
, size_t size
);
59 static ssize_t
write_del(struct file
*file
, char *buf
, size_t size
);
60 static ssize_t
write_export(struct file
*file
, char *buf
, size_t size
);
61 static ssize_t
write_unexport(struct file
*file
, char *buf
, size_t size
);
62 static ssize_t
write_getfd(struct file
*file
, char *buf
, size_t size
);
63 static ssize_t
write_getfs(struct file
*file
, char *buf
, size_t size
);
64 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
);
65 static ssize_t
write_unlock_ip(struct file
*file
, char *buf
, size_t size
);
66 static ssize_t
write_unlock_fs(struct file
*file
, char *buf
, size_t size
);
67 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
);
68 static ssize_t
write_pool_threads(struct file
*file
, char *buf
, size_t size
);
69 static ssize_t
write_versions(struct file
*file
, char *buf
, size_t size
);
70 static ssize_t
write_ports(struct file
*file
, char *buf
, size_t size
);
71 static ssize_t
write_maxblksize(struct file
*file
, char *buf
, size_t size
);
73 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
);
74 static ssize_t
write_gracetime(struct file
*file
, char *buf
, size_t size
);
75 static ssize_t
write_recoverydir(struct file
*file
, char *buf
, size_t size
);
78 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
79 [NFSD_Svc
] = write_svc
,
80 [NFSD_Add
] = write_add
,
81 [NFSD_Del
] = write_del
,
82 [NFSD_Export
] = write_export
,
83 [NFSD_Unexport
] = write_unexport
,
84 [NFSD_Getfd
] = write_getfd
,
85 [NFSD_Getfs
] = write_getfs
,
86 [NFSD_Fh
] = write_filehandle
,
87 [NFSD_FO_UnlockIP
] = write_unlock_ip
,
88 [NFSD_FO_UnlockFS
] = write_unlock_fs
,
89 [NFSD_Threads
] = write_threads
,
90 [NFSD_Pool_Threads
] = write_pool_threads
,
91 [NFSD_Versions
] = write_versions
,
92 [NFSD_Ports
] = write_ports
,
93 [NFSD_MaxBlkSize
] = write_maxblksize
,
95 [NFSD_Leasetime
] = write_leasetime
,
96 [NFSD_Gracetime
] = write_gracetime
,
97 [NFSD_RecoveryDir
] = write_recoverydir
,
101 static ssize_t
nfsctl_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
103 ino_t ino
= file
->f_path
.dentry
->d_inode
->i_ino
;
107 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
110 data
= simple_transaction_get(file
, buf
, size
);
112 return PTR_ERR(data
);
114 rv
= write_op
[ino
](file
, data
, size
);
116 simple_transaction_set(file
, rv
);
122 static ssize_t
nfsctl_transaction_read(struct file
*file
, char __user
*buf
, size_t size
, loff_t
*pos
)
124 if (! file
->private_data
) {
125 /* An attempt to read a transaction file without writing
126 * causes a 0-byte write so that the file can return
129 ssize_t rv
= nfsctl_transaction_write(file
, buf
, 0, pos
);
133 return simple_transaction_read(file
, buf
, size
, pos
);
136 static const struct file_operations transaction_ops
= {
137 .write
= nfsctl_transaction_write
,
138 .read
= nfsctl_transaction_read
,
139 .release
= simple_transaction_release
,
140 .llseek
= default_llseek
,
143 static int exports_open(struct inode
*inode
, struct file
*file
)
145 return seq_open(file
, &nfs_exports_op
);
148 static const struct file_operations exports_operations
= {
149 .open
= exports_open
,
152 .release
= seq_release
,
153 .owner
= THIS_MODULE
,
156 static int export_features_show(struct seq_file
*m
, void *v
)
158 seq_printf(m
, "0x%x 0x%x\n", NFSEXP_ALLFLAGS
, NFSEXP_SECINFO_FLAGS
);
162 static int export_features_open(struct inode
*inode
, struct file
*file
)
164 return single_open(file
, export_features_show
, NULL
);
167 static struct file_operations export_features_operations
= {
168 .open
= export_features_open
,
171 .release
= single_release
,
174 extern int nfsd_pool_stats_open(struct inode
*inode
, struct file
*file
);
175 extern int nfsd_pool_stats_release(struct inode
*inode
, struct file
*file
);
177 static const struct file_operations pool_stats_operations
= {
178 .open
= nfsd_pool_stats_open
,
181 .release
= nfsd_pool_stats_release
,
182 .owner
= THIS_MODULE
,
185 /*----------------------------------------------------------------------------*/
187 * payload - write methods
191 * write_svc - Start kernel's NFSD server
193 * Deprecated. /proc/fs/nfsd/threads is preferred.
194 * Function remains to support old versions of nfs-utils.
197 * buf: struct nfsctl_svc
198 * svc_port: port number of this
200 * svc_nthreads: number of threads to start
201 * size: size in bytes of passed in nfsctl_svc
203 * On success: returns zero
204 * On error: return code is negative errno value
206 static ssize_t
write_svc(struct file
*file
, char *buf
, size_t size
)
208 struct nfsctl_svc
*data
;
210 if (size
< sizeof(*data
))
212 data
= (struct nfsctl_svc
*) buf
;
213 err
= nfsd_svc(data
->svc_port
, data
->svc_nthreads
);
220 * write_add - Add or modify client entry in auth unix cache
222 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
223 * Function remains to support old versions of nfs-utils.
226 * buf: struct nfsctl_client
227 * cl_ident: '\0'-terminated C string
228 * containing domain name
230 * cl_naddr: no. of items in cl_addrlist
231 * cl_addrlist: array of client addresses
232 * cl_fhkeytype: ignored
233 * cl_fhkeylen: ignored
235 * size: size in bytes of passed in nfsctl_client
237 * On success: returns zero
238 * On error: return code is negative errno value
240 * Note: Only AF_INET client addresses are passed in, since
241 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
243 static ssize_t
write_add(struct file
*file
, char *buf
, size_t size
)
245 struct nfsctl_client
*data
;
246 if (size
< sizeof(*data
))
248 data
= (struct nfsctl_client
*)buf
;
249 return exp_addclient(data
);
253 * write_del - Remove client from auth unix cache
255 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
256 * Function remains to support old versions of nfs-utils.
259 * buf: struct nfsctl_client
260 * cl_ident: '\0'-terminated C string
261 * containing domain name
264 * cl_addrlist: ignored
265 * cl_fhkeytype: ignored
266 * cl_fhkeylen: ignored
268 * size: size in bytes of passed in nfsctl_client
270 * On success: returns zero
271 * On error: return code is negative errno value
273 * Note: Only AF_INET client addresses are passed in, since
274 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
276 static ssize_t
write_del(struct file
*file
, char *buf
, size_t size
)
278 struct nfsctl_client
*data
;
279 if (size
< sizeof(*data
))
281 data
= (struct nfsctl_client
*)buf
;
282 return exp_delclient(data
);
286 * write_export - Export part or all of a local file system
288 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
289 * Function remains to support old versions of nfs-utils.
292 * buf: struct nfsctl_export
293 * ex_client: '\0'-terminated C string
294 * containing domain name
295 * of client allowed to access
297 * ex_path: '\0'-terminated C string
298 * containing pathname of
299 * directory in local file system
300 * ex_dev: fsid to use for this export
302 * ex_flags: export flags for this export
303 * ex_anon_uid: UID to use for anonymous
305 * ex_anon_gid: GID to use for anonymous
307 * size: size in bytes of passed in nfsctl_export
309 * On success: returns zero
310 * On error: return code is negative errno value
312 static ssize_t
write_export(struct file
*file
, char *buf
, size_t size
)
314 struct nfsctl_export
*data
;
315 if (size
< sizeof(*data
))
317 data
= (struct nfsctl_export
*)buf
;
318 return exp_export(data
);
322 * write_unexport - Unexport a previously exported file system
324 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
325 * Function remains to support old versions of nfs-utils.
328 * buf: struct nfsctl_export
329 * ex_client: '\0'-terminated C string
330 * containing domain name
331 * of client no longer allowed
332 * to access this export
333 * ex_path: '\0'-terminated C string
334 * containing pathname of
335 * directory in local file system
339 * ex_anon_uid: ignored
340 * ex_anon_gid: ignored
341 * size: size in bytes of passed in nfsctl_export
343 * On success: returns zero
344 * On error: return code is negative errno value
346 static ssize_t
write_unexport(struct file
*file
, char *buf
, size_t size
)
348 struct nfsctl_export
*data
;
350 if (size
< sizeof(*data
))
352 data
= (struct nfsctl_export
*)buf
;
353 return exp_unexport(data
);
357 * write_getfs - Get a variable-length NFS file handle by path
359 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
360 * Function remains to support old versions of nfs-utils.
363 * buf: struct nfsctl_fsparm
364 * gd_addr: socket address of client
365 * gd_path: '\0'-terminated C string
366 * containing pathname of
367 * directory in local file system
368 * gd_maxlen: maximum size of returned file
370 * size: size in bytes of passed in nfsctl_fsparm
372 * On success: passed-in buffer filled with a knfsd_fh structure
373 * (a variable-length raw NFS file handle);
374 * return code is the size in bytes of the file handle
375 * On error: return code is negative errno value
377 * Note: Only AF_INET client addresses are passed in, since gd_addr
378 * is the same size as a struct sockaddr_in.
380 static ssize_t
write_getfs(struct file
*file
, char *buf
, size_t size
)
382 struct nfsctl_fsparm
*data
;
383 struct sockaddr_in
*sin
;
384 struct auth_domain
*clp
;
386 struct knfsd_fh
*res
;
389 if (size
< sizeof(*data
))
391 data
= (struct nfsctl_fsparm
*)buf
;
392 err
= -EPROTONOSUPPORT
;
393 if (data
->gd_addr
.sa_family
!= AF_INET
)
395 sin
= (struct sockaddr_in
*)&data
->gd_addr
;
396 if (data
->gd_maxlen
> NFS3_FHSIZE
)
397 data
->gd_maxlen
= NFS3_FHSIZE
;
399 res
= (struct knfsd_fh
*)buf
;
403 ipv6_addr_set_v4mapped(sin
->sin_addr
.s_addr
, &in6
);
405 clp
= auth_unix_lookup(&in6
);
409 err
= exp_rootfh(clp
, data
->gd_path
, res
, data
->gd_maxlen
);
410 auth_domain_put(clp
);
414 err
= res
->fh_size
+ offsetof(struct knfsd_fh
, fh_base
);
420 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
422 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
423 * Function remains to support old versions of nfs-utils.
426 * buf: struct nfsctl_fdparm
427 * gd_addr: socket address of client
428 * gd_path: '\0'-terminated C string
429 * containing pathname of
430 * directory in local file system
431 * gd_version: fdparm structure version
432 * size: size in bytes of passed in nfsctl_fdparm
434 * On success: passed-in buffer filled with nfsctl_res
435 * (a fixed-length raw NFS file handle);
436 * return code is the size in bytes of the file handle
437 * On error: return code is negative errno value
439 * Note: Only AF_INET client addresses are passed in, since gd_addr
440 * is the same size as a struct sockaddr_in.
442 static ssize_t
write_getfd(struct file
*file
, char *buf
, size_t size
)
444 struct nfsctl_fdparm
*data
;
445 struct sockaddr_in
*sin
;
446 struct auth_domain
*clp
;
452 if (size
< sizeof(*data
))
454 data
= (struct nfsctl_fdparm
*)buf
;
455 err
= -EPROTONOSUPPORT
;
456 if (data
->gd_addr
.sa_family
!= AF_INET
)
459 if (data
->gd_version
< 2 || data
->gd_version
> NFSSVC_MAXVERS
)
463 sin
= (struct sockaddr_in
*)&data
->gd_addr
;
466 ipv6_addr_set_v4mapped(sin
->sin_addr
.s_addr
, &in6
);
468 clp
= auth_unix_lookup(&in6
);
472 err
= exp_rootfh(clp
, data
->gd_path
, &fh
, NFS_FHSIZE
);
473 auth_domain_put(clp
);
478 memset(res
,0, NFS_FHSIZE
);
479 memcpy(res
, &fh
.fh_base
, fh
.fh_size
);
487 * write_unlock_ip - Release all locks used by a client
492 * buf: '\n'-terminated C string containing a
493 * presentation format IP address
494 * size: length of C string in @buf
496 * On success: returns zero if all specified locks were released;
497 * returns one if one or more locks were not released
498 * On error: return code is negative errno value
500 static ssize_t
write_unlock_ip(struct file
*file
, char *buf
, size_t size
)
502 struct sockaddr_storage address
;
503 struct sockaddr
*sap
= (struct sockaddr
*)&address
;
504 size_t salen
= sizeof(address
);
511 if (buf
[size
-1] != '\n')
515 if (qword_get(&buf
, fo_path
, size
) < 0)
518 if (rpc_pton(fo_path
, size
, sap
, salen
) == 0)
521 return nlmsvc_unlock_all_by_ip(sap
);
525 * write_unlock_fs - Release all locks on a local file system
530 * buf: '\n'-terminated C string containing the
531 * absolute pathname of a local file system
532 * size: length of C string in @buf
534 * On success: returns zero if all specified locks were released;
535 * returns one if one or more locks were not released
536 * On error: return code is negative errno value
538 static ssize_t
write_unlock_fs(struct file
*file
, char *buf
, size_t size
)
548 if (buf
[size
-1] != '\n')
552 if (qword_get(&buf
, fo_path
, size
) < 0)
555 error
= kern_path(fo_path
, 0, &path
);
560 * XXX: Needs better sanity checking. Otherwise we could end up
561 * releasing locks on the wrong file system.
564 * 1. Does the path refer to a directory?
565 * 2. Is that directory a mount point, or
566 * 3. Is that directory the root of an exported file system?
568 error
= nlmsvc_unlock_all_by_sb(path
.mnt
->mnt_sb
);
575 * write_filehandle - Get a variable-length NFS file handle by path
577 * On input, the buffer contains a '\n'-terminated C string comprised of
578 * three alphanumeric words separated by whitespace. The string may
579 * contain escape sequences.
583 * domain: client domain name
584 * path: export pathname
585 * maxsize: numeric maximum size of
587 * size: length of C string in @buf
589 * On success: passed-in buffer filled with '\n'-terminated C
590 * string containing a ASCII hex text version
591 * of the NFS file handle;
592 * return code is the size in bytes of the string
593 * On error: return code is negative errno value
595 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
)
598 int uninitialized_var(maxsize
);
601 struct auth_domain
*dom
;
607 if (buf
[size
-1] != '\n')
612 len
= qword_get(&mesg
, dname
, size
);
617 len
= qword_get(&mesg
, path
, size
);
621 len
= get_int(&mesg
, &maxsize
);
625 if (maxsize
< NFS_FHSIZE
)
627 if (maxsize
> NFS3_FHSIZE
)
628 maxsize
= NFS3_FHSIZE
;
630 if (qword_get(&mesg
, mesg
, size
)>0)
633 /* we have all the words, they are in buf.. */
634 dom
= unix_domain_find(dname
);
638 len
= exp_rootfh(dom
, path
, &fh
, maxsize
);
639 auth_domain_put(dom
);
644 len
= SIMPLE_TRANSACTION_LIMIT
;
645 qword_addhex(&mesg
, &len
, (char*)&fh
.fh_base
, fh
.fh_size
);
651 * write_threads - Start NFSD, or report the current number of running threads
657 * On success: passed-in buffer filled with '\n'-terminated C
658 * string numeric value representing the number of
659 * running NFSD threads;
660 * return code is the size in bytes of the string
661 * On error: return code is zero
666 * buf: C string containing an unsigned
667 * integer value representing the
668 * number of NFSD threads to start
669 * size: non-zero length of C string in @buf
671 * On success: NFS service is started;
672 * passed-in buffer filled with '\n'-terminated C
673 * string numeric value representing the number of
674 * running NFSD threads;
675 * return code is the size in bytes of the string
676 * On error: return code is zero or a negative errno value
678 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
)
684 rv
= get_int(&mesg
, &newthreads
);
689 rv
= nfsd_svc(NFS_PORT
, newthreads
);
693 rv
= nfsd_nrthreads();
695 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%d\n", rv
);
699 * write_pool_threads - Set or report the current number of threads per pool
708 * buf: C string containing whitespace-
709 * separated unsigned integer values
710 * representing the number of NFSD
711 * threads to start in each pool
712 * size: non-zero length of C string in @buf
714 * On success: passed-in buffer filled with '\n'-terminated C
715 * string containing integer values representing the
716 * number of NFSD threads in each pool;
717 * return code is the size in bytes of the string
718 * On error: return code is zero or a negative errno value
720 static ssize_t
write_pool_threads(struct file
*file
, char *buf
, size_t size
)
722 /* if size > 0, look for an array of number of threads per node
723 * and apply them then write out number of threads per node as reply
732 mutex_lock(&nfsd_mutex
);
733 npools
= nfsd_nrpools();
736 * NFS is shut down. The admin can start it by
737 * writing to the threads file but NOT the pool_threads
738 * file, sorry. Report zero threads.
740 mutex_unlock(&nfsd_mutex
);
745 nthreads
= kcalloc(npools
, sizeof(int), GFP_KERNEL
);
747 if (nthreads
== NULL
)
751 for (i
= 0; i
< npools
; i
++) {
752 rv
= get_int(&mesg
, &nthreads
[i
]);
754 break; /* fewer numbers than pools */
756 goto out_free
; /* syntax error */
761 rv
= nfsd_set_nrthreads(i
, nthreads
);
766 rv
= nfsd_get_nrthreads(npools
, nthreads
);
771 size
= SIMPLE_TRANSACTION_LIMIT
;
772 for (i
= 0; i
< npools
&& size
> 0; i
++) {
773 snprintf(mesg
, size
, "%d%c", nthreads
[i
], (i
== npools
-1 ? '\n' : ' '));
781 mutex_unlock(&nfsd_mutex
);
785 static ssize_t
__write_versions(struct file
*file
, char *buf
, size_t size
)
788 char *vers
, *minorp
, sign
;
789 int len
, num
, remaining
;
796 /* Cannot change versions without updating
797 * nfsd_serv->sv_xdrsize, and reallocing
798 * rq_argp and rq_resp
801 if (buf
[size
-1] != '\n')
806 len
= qword_get(&mesg
, vers
, size
);
807 if (len
<= 0) return -EINVAL
;
810 if (sign
== '+' || sign
== '-')
811 num
= simple_strtol((vers
+1), &minorp
, 0);
813 num
= simple_strtol(vers
, &minorp
, 0);
814 if (*minorp
== '.') {
817 minor
= simple_strtoul(minorp
+1, NULL
, 0);
820 if (nfsd_minorversion(minor
, sign
== '-' ?
821 NFSD_CLEAR
: NFSD_SET
) < 0)
829 nfsd_vers(num
, sign
== '-' ? NFSD_CLEAR
: NFSD_SET
);
836 } while ((len
= qword_get(&mesg
, vers
, size
)) > 0);
837 /* If all get turned off, turn them back on, as
838 * having no versions is BAD
840 nfsd_reset_versions();
843 /* Now write current state into reply buffer */
846 remaining
= SIMPLE_TRANSACTION_LIMIT
;
847 for (num
=2 ; num
<= 4 ; num
++)
848 if (nfsd_vers(num
, NFSD_AVAIL
)) {
849 len
= snprintf(buf
, remaining
, "%s%c%d", sep
,
850 nfsd_vers(num
, NFSD_TEST
)?'+':'-',
860 if (nfsd_vers(4, NFSD_AVAIL
))
861 for (minor
= 1; minor
<= NFSD_SUPPORTED_MINOR_VERSION
;
863 len
= snprintf(buf
, remaining
, " %c4.%u",
864 (nfsd_vers(4, NFSD_TEST
) &&
865 nfsd_minorversion(minor
, NFSD_TEST
)) ?
876 len
= snprintf(buf
, remaining
, "\n");
883 * write_versions - Set or report the available NFS protocol versions
889 * On success: passed-in buffer filled with '\n'-terminated C
890 * string containing positive or negative integer
891 * values representing the current status of each
893 * return code is the size in bytes of the string
894 * On error: return code is zero or a negative errno value
899 * buf: C string containing whitespace-
900 * separated positive or negative
901 * integer values representing NFS
902 * protocol versions to enable ("+n")
904 * size: non-zero length of C string in @buf
906 * On success: status of zero or more protocol versions has
907 * been updated; passed-in buffer filled with
908 * '\n'-terminated C string containing positive
909 * or negative integer values representing the
910 * current status of each protocol version;
911 * return code is the size in bytes of the string
912 * On error: return code is zero or a negative errno value
914 static ssize_t
write_versions(struct file
*file
, char *buf
, size_t size
)
918 mutex_lock(&nfsd_mutex
);
919 rv
= __write_versions(file
, buf
, size
);
920 mutex_unlock(&nfsd_mutex
);
925 * Zero-length write. Return a list of NFSD's current listener
928 static ssize_t
__write_ports_names(char *buf
)
930 if (nfsd_serv
== NULL
)
932 return svc_xprt_names(nfsd_serv
, buf
, SIMPLE_TRANSACTION_LIMIT
);
936 * A single 'fd' number was written, in which case it must be for
937 * a socket of a supported family/protocol, and we use it as an
940 static ssize_t
__write_ports_addfd(char *buf
)
945 err
= get_int(&mesg
, &fd
);
946 if (err
!= 0 || fd
< 0)
949 err
= nfsd_create_serv();
953 err
= svc_addsock(nfsd_serv
, fd
, buf
, SIMPLE_TRANSACTION_LIMIT
);
955 svc_destroy(nfsd_serv
);
959 /* Decrease the count, but don't shut down the service */
960 nfsd_serv
->sv_nrthreads
--;
965 * A '-' followed by the 'name' of a socket means we close the socket.
967 static ssize_t
__write_ports_delfd(char *buf
)
972 toclose
= kstrdup(buf
+ 1, GFP_KERNEL
);
976 if (nfsd_serv
!= NULL
)
977 len
= svc_sock_names(nfsd_serv
, buf
,
978 SIMPLE_TRANSACTION_LIMIT
, toclose
);
984 * A transport listener is added by writing it's transport name and
987 static ssize_t
__write_ports_addxprt(char *buf
)
990 struct svc_xprt
*xprt
;
993 if (sscanf(buf
, "%15s %4u", transport
, &port
) != 2)
996 if (port
< 1 || port
> USHRT_MAX
)
999 err
= nfsd_create_serv();
1003 err
= svc_create_xprt(nfsd_serv
, transport
,
1004 PF_INET
, port
, SVC_SOCK_ANONYMOUS
);
1008 err
= svc_create_xprt(nfsd_serv
, transport
,
1009 PF_INET6
, port
, SVC_SOCK_ANONYMOUS
);
1010 if (err
< 0 && err
!= -EAFNOSUPPORT
)
1013 /* Decrease the count, but don't shut down the service */
1014 nfsd_serv
->sv_nrthreads
--;
1017 xprt
= svc_find_xprt(nfsd_serv
, transport
, PF_INET
, port
);
1019 svc_close_xprt(xprt
);
1023 svc_destroy(nfsd_serv
);
1028 * A transport listener is removed by writing a "-", it's transport
1029 * name, and it's port number.
1031 static ssize_t
__write_ports_delxprt(char *buf
)
1033 struct svc_xprt
*xprt
;
1037 if (sscanf(&buf
[1], "%15s %4u", transport
, &port
) != 2)
1040 if (port
< 1 || port
> USHRT_MAX
|| nfsd_serv
== NULL
)
1043 xprt
= svc_find_xprt(nfsd_serv
, transport
, AF_UNSPEC
, port
);
1047 svc_close_xprt(xprt
);
1052 static ssize_t
__write_ports(struct file
*file
, char *buf
, size_t size
)
1055 return __write_ports_names(buf
);
1057 if (isdigit(buf
[0]))
1058 return __write_ports_addfd(buf
);
1060 if (buf
[0] == '-' && isdigit(buf
[1]))
1061 return __write_ports_delfd(buf
);
1063 if (isalpha(buf
[0]))
1064 return __write_ports_addxprt(buf
);
1066 if (buf
[0] == '-' && isalpha(buf
[1]))
1067 return __write_ports_delxprt(buf
);
1073 * write_ports - Pass a socket file descriptor or transport name to listen on
1079 * On success: passed-in buffer filled with a '\n'-terminated C
1080 * string containing a whitespace-separated list of
1081 * named NFSD listeners;
1082 * return code is the size in bytes of the string
1083 * On error: return code is zero or a negative errno value
1088 * buf: C string containing an unsigned
1089 * integer value representing a bound
1090 * but unconnected socket that is to be
1091 * used as an NFSD listener; listen(3)
1092 * must be called for a SOCK_STREAM
1093 * socket, otherwise it is ignored
1094 * size: non-zero length of C string in @buf
1096 * On success: NFS service is started;
1097 * passed-in buffer filled with a '\n'-terminated C
1098 * string containing a unique alphanumeric name of
1100 * return code is the size in bytes of the string
1101 * On error: return code is a negative errno value
1106 * buf: C string containing a "-" followed
1107 * by an integer value representing a
1108 * previously passed in socket file
1110 * size: non-zero length of C string in @buf
1112 * On success: NFS service no longer listens on that socket;
1113 * passed-in buffer filled with a '\n'-terminated C
1114 * string containing a unique name of the listener;
1115 * return code is the size in bytes of the string
1116 * On error: return code is a negative errno value
1121 * buf: C string containing a transport
1122 * name and an unsigned integer value
1123 * representing the port to listen on,
1124 * separated by whitespace
1125 * size: non-zero length of C string in @buf
1127 * On success: returns zero; NFS service is started
1128 * On error: return code is a negative errno value
1133 * buf: C string containing a "-" followed
1134 * by a transport name and an unsigned
1135 * integer value representing the port
1136 * to listen on, separated by whitespace
1137 * size: non-zero length of C string in @buf
1139 * On success: returns zero; NFS service no longer listens
1141 * On error: return code is a negative errno value
1143 static ssize_t
write_ports(struct file
*file
, char *buf
, size_t size
)
1147 mutex_lock(&nfsd_mutex
);
1148 rv
= __write_ports(file
, buf
, size
);
1149 mutex_unlock(&nfsd_mutex
);
1154 int nfsd_max_blksize
;
1157 * write_maxblksize - Set or report the current NFS blksize
1166 * buf: C string containing an unsigned
1167 * integer value representing the new
1169 * size: non-zero length of C string in @buf
1171 * On success: passed-in buffer filled with '\n'-terminated C string
1172 * containing numeric value of the current NFS blksize
1174 * return code is the size in bytes of the string
1175 * On error: return code is zero or a negative errno value
1177 static ssize_t
write_maxblksize(struct file
*file
, char *buf
, size_t size
)
1182 int rv
= get_int(&mesg
, &bsize
);
1185 /* force bsize into allowed range and
1186 * required alignment.
1190 if (bsize
> NFSSVC_MAXBLKSIZE
)
1191 bsize
= NFSSVC_MAXBLKSIZE
;
1193 mutex_lock(&nfsd_mutex
);
1195 mutex_unlock(&nfsd_mutex
);
1198 nfsd_max_blksize
= bsize
;
1199 mutex_unlock(&nfsd_mutex
);
1202 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%d\n",
1206 #ifdef CONFIG_NFSD_V4
1207 static ssize_t
__nfsd4_write_time(struct file
*file
, char *buf
, size_t size
, time_t *time
)
1215 rv
= get_int(&mesg
, &i
);
1219 * Some sanity checking. We don't have a reason for
1220 * these particular numbers, but problems with the
1222 * - Too short: the briefest network outage may
1223 * cause clients to lose all their locks. Also,
1224 * the frequent polling may be wasteful.
1225 * - Too long: do you really want reboot recovery
1226 * to take more than an hour? Or to make other
1227 * clients wait an hour before being able to
1228 * revoke a dead client's locks?
1230 if (i
< 10 || i
> 3600)
1235 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%ld\n", *time
);
1238 static ssize_t
nfsd4_write_time(struct file
*file
, char *buf
, size_t size
, time_t *time
)
1242 mutex_lock(&nfsd_mutex
);
1243 rv
= __nfsd4_write_time(file
, buf
, size
, time
);
1244 mutex_unlock(&nfsd_mutex
);
1249 * write_leasetime - Set or report the current NFSv4 lease time
1258 * buf: C string containing an unsigned
1259 * integer value representing the new
1260 * NFSv4 lease expiry time
1261 * size: non-zero length of C string in @buf
1263 * On success: passed-in buffer filled with '\n'-terminated C
1264 * string containing unsigned integer value of the
1265 * current lease expiry time;
1266 * return code is the size in bytes of the string
1267 * On error: return code is zero or a negative errno value
1269 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
)
1271 return nfsd4_write_time(file
, buf
, size
, &nfsd4_lease
);
1275 * write_gracetime - Set or report current NFSv4 grace period time
1277 * As above, but sets the time of the NFSv4 grace period.
1279 * Note this should never be set to less than the *previous*
1280 * lease-period time, but we don't try to enforce this. (In the common
1281 * case (a new boot), we don't know what the previous lease time was
1284 static ssize_t
write_gracetime(struct file
*file
, char *buf
, size_t size
)
1286 return nfsd4_write_time(file
, buf
, size
, &nfsd4_grace
);
1289 extern char *nfs4_recoverydir(void);
1291 static ssize_t
__write_recoverydir(struct file
*file
, char *buf
, size_t size
)
1300 if (size
> PATH_MAX
|| buf
[size
-1] != '\n')
1305 len
= qword_get(&mesg
, recdir
, size
);
1309 status
= nfs4_reset_recoverydir(recdir
);
1314 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%s\n",
1315 nfs4_recoverydir());
1319 * write_recoverydir - Set or report the pathname of the recovery directory
1328 * buf: C string containing the pathname
1329 * of the directory on a local file
1330 * system containing permanent NFSv4
1332 * size: non-zero length of C string in @buf
1334 * On success: passed-in buffer filled with '\n'-terminated C string
1335 * containing the current recovery pathname setting;
1336 * return code is the size in bytes of the string
1337 * On error: return code is zero or a negative errno value
1339 static ssize_t
write_recoverydir(struct file
*file
, char *buf
, size_t size
)
1343 mutex_lock(&nfsd_mutex
);
1344 rv
= __write_recoverydir(file
, buf
, size
);
1345 mutex_unlock(&nfsd_mutex
);
1351 /*----------------------------------------------------------------------------*/
1353 * populating the filesystem.
1356 static int nfsd_fill_super(struct super_block
* sb
, void * data
, int silent
)
1358 static struct tree_descr nfsd_files
[] = {
1359 [NFSD_Svc
] = {".svc", &transaction_ops
, S_IWUSR
},
1360 [NFSD_Add
] = {".add", &transaction_ops
, S_IWUSR
},
1361 [NFSD_Del
] = {".del", &transaction_ops
, S_IWUSR
},
1362 [NFSD_Export
] = {".export", &transaction_ops
, S_IWUSR
},
1363 [NFSD_Unexport
] = {".unexport", &transaction_ops
, S_IWUSR
},
1364 [NFSD_Getfd
] = {".getfd", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1365 [NFSD_Getfs
] = {".getfs", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1366 [NFSD_List
] = {"exports", &exports_operations
, S_IRUGO
},
1367 [NFSD_Export_features
] = {"export_features",
1368 &export_features_operations
, S_IRUGO
},
1369 [NFSD_FO_UnlockIP
] = {"unlock_ip",
1370 &transaction_ops
, S_IWUSR
|S_IRUSR
},
1371 [NFSD_FO_UnlockFS
] = {"unlock_filesystem",
1372 &transaction_ops
, S_IWUSR
|S_IRUSR
},
1373 [NFSD_Fh
] = {"filehandle", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1374 [NFSD_Threads
] = {"threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1375 [NFSD_Pool_Threads
] = {"pool_threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1376 [NFSD_Pool_Stats
] = {"pool_stats", &pool_stats_operations
, S_IRUGO
},
1377 [NFSD_Versions
] = {"versions", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1378 [NFSD_Ports
] = {"portlist", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1379 [NFSD_MaxBlkSize
] = {"max_block_size", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1380 #ifdef CONFIG_NFSD_V4
1381 [NFSD_Leasetime
] = {"nfsv4leasetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1382 [NFSD_Gracetime
] = {"nfsv4gracetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1383 [NFSD_RecoveryDir
] = {"nfsv4recoverydir", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1387 return simple_fill_super(sb
, 0x6e667364, nfsd_files
);
1390 static int nfsd_get_sb(struct file_system_type
*fs_type
,
1391 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
1393 return get_sb_single(fs_type
, flags
, data
, nfsd_fill_super
, mnt
);
1396 static struct file_system_type nfsd_fs_type
= {
1397 .owner
= THIS_MODULE
,
1399 .get_sb
= nfsd_get_sb
,
1400 .kill_sb
= kill_litter_super
,
1403 #ifdef CONFIG_PROC_FS
1404 static int create_proc_exports_entry(void)
1406 struct proc_dir_entry
*entry
;
1408 entry
= proc_mkdir("fs/nfs", NULL
);
1411 entry
= proc_create("exports", 0, entry
, &exports_operations
);
1416 #else /* CONFIG_PROC_FS */
1417 static int create_proc_exports_entry(void)
1423 static int __init
init_nfsd(void)
1426 printk(KERN_INFO
"Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1428 retval
= nfs4_state_init(); /* nfs4 locking state */
1431 nfsd_stat_init(); /* Statistics */
1432 retval
= nfsd_reply_cache_init();
1435 retval
= nfsd_export_init();
1437 goto out_free_cache
;
1438 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1439 retval
= nfsd_idmap_init();
1441 goto out_free_lockd
;
1442 retval
= create_proc_exports_entry();
1444 goto out_free_idmap
;
1445 retval
= register_filesystem(&nfsd_fs_type
);
1450 remove_proc_entry("fs/nfs/exports", NULL
);
1451 remove_proc_entry("fs/nfs", NULL
);
1453 nfsd_idmap_shutdown();
1455 nfsd_lockd_shutdown();
1456 nfsd_export_shutdown();
1458 nfsd_reply_cache_shutdown();
1460 nfsd_stat_shutdown();
1465 static void __exit
exit_nfsd(void)
1467 nfsd_export_shutdown();
1468 nfsd_reply_cache_shutdown();
1469 remove_proc_entry("fs/nfs/exports", NULL
);
1470 remove_proc_entry("fs/nfs", NULL
);
1471 nfsd_stat_shutdown();
1472 nfsd_lockd_shutdown();
1473 nfsd_idmap_shutdown();
1475 unregister_filesystem(&nfsd_fs_type
);
1478 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1479 MODULE_LICENSE("GPL");
1480 module_init(init_nfsd
)
1481 module_exit(exit_nfsd
)