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.
25 #ifdef CONFIG_NFSD_DEPRECATED
46 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
47 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
57 * write() for these nodes.
59 #ifdef CONFIG_NFSD_DEPRECATED
60 static ssize_t
write_svc(struct file
*file
, char *buf
, size_t size
);
61 static ssize_t
write_add(struct file
*file
, char *buf
, size_t size
);
62 static ssize_t
write_del(struct file
*file
, char *buf
, size_t size
);
63 static ssize_t
write_export(struct file
*file
, char *buf
, size_t size
);
64 static ssize_t
write_unexport(struct file
*file
, char *buf
, size_t size
);
65 static ssize_t
write_getfd(struct file
*file
, char *buf
, size_t size
);
66 static ssize_t
write_getfs(struct file
*file
, char *buf
, size_t size
);
68 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
);
69 static ssize_t
write_unlock_ip(struct file
*file
, char *buf
, size_t size
);
70 static ssize_t
write_unlock_fs(struct file
*file
, char *buf
, size_t size
);
71 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
);
72 static ssize_t
write_pool_threads(struct file
*file
, char *buf
, size_t size
);
73 static ssize_t
write_versions(struct file
*file
, char *buf
, size_t size
);
74 static ssize_t
write_ports(struct file
*file
, char *buf
, size_t size
);
75 static ssize_t
write_maxblksize(struct file
*file
, char *buf
, size_t size
);
77 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
);
78 static ssize_t
write_gracetime(struct file
*file
, char *buf
, size_t size
);
79 static ssize_t
write_recoverydir(struct file
*file
, char *buf
, size_t size
);
82 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
83 #ifdef CONFIG_NFSD_DEPRECATED
84 [NFSD_Svc
] = write_svc
,
85 [NFSD_Add
] = write_add
,
86 [NFSD_Del
] = write_del
,
87 [NFSD_Export
] = write_export
,
88 [NFSD_Unexport
] = write_unexport
,
89 [NFSD_Getfd
] = write_getfd
,
90 [NFSD_Getfs
] = write_getfs
,
92 [NFSD_Fh
] = write_filehandle
,
93 [NFSD_FO_UnlockIP
] = write_unlock_ip
,
94 [NFSD_FO_UnlockFS
] = write_unlock_fs
,
95 [NFSD_Threads
] = write_threads
,
96 [NFSD_Pool_Threads
] = write_pool_threads
,
97 [NFSD_Versions
] = write_versions
,
98 [NFSD_Ports
] = write_ports
,
99 [NFSD_MaxBlkSize
] = write_maxblksize
,
100 #ifdef CONFIG_NFSD_V4
101 [NFSD_Leasetime
] = write_leasetime
,
102 [NFSD_Gracetime
] = write_gracetime
,
103 [NFSD_RecoveryDir
] = write_recoverydir
,
107 static ssize_t
nfsctl_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
109 ino_t ino
= file
->f_path
.dentry
->d_inode
->i_ino
;
113 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
116 data
= simple_transaction_get(file
, buf
, size
);
118 return PTR_ERR(data
);
120 rv
= write_op
[ino
](file
, data
, size
);
122 simple_transaction_set(file
, rv
);
128 static ssize_t
nfsctl_transaction_read(struct file
*file
, char __user
*buf
, size_t size
, loff_t
*pos
)
131 if (file
->f_dentry
->d_name
.name
[0] == '.' && !warned
) {
133 "Warning: \"%s\" uses deprecated NFSD interface: %s."
134 " This will be removed in 2.6.40\n",
135 current
->comm
, file
->f_dentry
->d_name
.name
);
138 if (! file
->private_data
) {
139 /* An attempt to read a transaction file without writing
140 * causes a 0-byte write so that the file can return
143 ssize_t rv
= nfsctl_transaction_write(file
, buf
, 0, pos
);
147 return simple_transaction_read(file
, buf
, size
, pos
);
150 static const struct file_operations transaction_ops
= {
151 .write
= nfsctl_transaction_write
,
152 .read
= nfsctl_transaction_read
,
153 .release
= simple_transaction_release
,
154 .llseek
= default_llseek
,
157 static int exports_open(struct inode
*inode
, struct file
*file
)
159 return seq_open(file
, &nfs_exports_op
);
162 static const struct file_operations exports_operations
= {
163 .open
= exports_open
,
166 .release
= seq_release
,
167 .owner
= THIS_MODULE
,
170 static int export_features_show(struct seq_file
*m
, void *v
)
172 seq_printf(m
, "0x%x 0x%x\n", NFSEXP_ALLFLAGS
, NFSEXP_SECINFO_FLAGS
);
176 static int export_features_open(struct inode
*inode
, struct file
*file
)
178 return single_open(file
, export_features_show
, NULL
);
181 static struct file_operations export_features_operations
= {
182 .open
= export_features_open
,
185 .release
= single_release
,
188 extern int nfsd_pool_stats_open(struct inode
*inode
, struct file
*file
);
189 extern int nfsd_pool_stats_release(struct inode
*inode
, struct file
*file
);
191 static const struct file_operations pool_stats_operations
= {
192 .open
= nfsd_pool_stats_open
,
195 .release
= nfsd_pool_stats_release
,
196 .owner
= THIS_MODULE
,
199 /*----------------------------------------------------------------------------*/
201 * payload - write methods
204 #ifdef CONFIG_NFSD_DEPRECATED
206 * write_svc - Start kernel's NFSD server
208 * Deprecated. /proc/fs/nfsd/threads is preferred.
209 * Function remains to support old versions of nfs-utils.
212 * buf: struct nfsctl_svc
213 * svc_port: port number of this
215 * svc_nthreads: number of threads to start
216 * size: size in bytes of passed in nfsctl_svc
218 * On success: returns zero
219 * On error: return code is negative errno value
221 static ssize_t
write_svc(struct file
*file
, char *buf
, size_t size
)
223 struct nfsctl_svc
*data
;
225 if (size
< sizeof(*data
))
227 data
= (struct nfsctl_svc
*) buf
;
228 err
= nfsd_svc(data
->svc_port
, data
->svc_nthreads
);
235 * write_add - Add or modify client entry in auth unix cache
237 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
238 * Function remains to support old versions of nfs-utils.
241 * buf: struct nfsctl_client
242 * cl_ident: '\0'-terminated C string
243 * containing domain name
245 * cl_naddr: no. of items in cl_addrlist
246 * cl_addrlist: array of client addresses
247 * cl_fhkeytype: ignored
248 * cl_fhkeylen: ignored
250 * size: size in bytes of passed in nfsctl_client
252 * On success: returns zero
253 * On error: return code is negative errno value
255 * Note: Only AF_INET client addresses are passed in, since
256 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
258 static ssize_t
write_add(struct file
*file
, char *buf
, size_t size
)
260 struct nfsctl_client
*data
;
261 if (size
< sizeof(*data
))
263 data
= (struct nfsctl_client
*)buf
;
264 return exp_addclient(data
);
268 * write_del - Remove client from auth unix cache
270 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
271 * Function remains to support old versions of nfs-utils.
274 * buf: struct nfsctl_client
275 * cl_ident: '\0'-terminated C string
276 * containing domain name
279 * cl_addrlist: ignored
280 * cl_fhkeytype: ignored
281 * cl_fhkeylen: ignored
283 * size: size in bytes of passed in nfsctl_client
285 * On success: returns zero
286 * On error: return code is negative errno value
288 * Note: Only AF_INET client addresses are passed in, since
289 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
291 static ssize_t
write_del(struct file
*file
, char *buf
, size_t size
)
293 struct nfsctl_client
*data
;
294 if (size
< sizeof(*data
))
296 data
= (struct nfsctl_client
*)buf
;
297 return exp_delclient(data
);
301 * write_export - Export part or all of a local file system
303 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
304 * Function remains to support old versions of nfs-utils.
307 * buf: struct nfsctl_export
308 * ex_client: '\0'-terminated C string
309 * containing domain name
310 * of client allowed to access
312 * ex_path: '\0'-terminated C string
313 * containing pathname of
314 * directory in local file system
315 * ex_dev: fsid to use for this export
317 * ex_flags: export flags for this export
318 * ex_anon_uid: UID to use for anonymous
320 * ex_anon_gid: GID to use for anonymous
322 * size: size in bytes of passed in nfsctl_export
324 * On success: returns zero
325 * On error: return code is negative errno value
327 static ssize_t
write_export(struct file
*file
, char *buf
, size_t size
)
329 struct nfsctl_export
*data
;
330 if (size
< sizeof(*data
))
332 data
= (struct nfsctl_export
*)buf
;
333 return exp_export(data
);
337 * write_unexport - Unexport a previously exported file system
339 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
340 * Function remains to support old versions of nfs-utils.
343 * buf: struct nfsctl_export
344 * ex_client: '\0'-terminated C string
345 * containing domain name
346 * of client no longer allowed
347 * to access this export
348 * ex_path: '\0'-terminated C string
349 * containing pathname of
350 * directory in local file system
354 * ex_anon_uid: ignored
355 * ex_anon_gid: ignored
356 * size: size in bytes of passed in nfsctl_export
358 * On success: returns zero
359 * On error: return code is negative errno value
361 static ssize_t
write_unexport(struct file
*file
, char *buf
, size_t size
)
363 struct nfsctl_export
*data
;
365 if (size
< sizeof(*data
))
367 data
= (struct nfsctl_export
*)buf
;
368 return exp_unexport(data
);
372 * write_getfs - Get a variable-length NFS file handle by path
374 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
375 * Function remains to support old versions of nfs-utils.
378 * buf: struct nfsctl_fsparm
379 * gd_addr: socket address of client
380 * gd_path: '\0'-terminated C string
381 * containing pathname of
382 * directory in local file system
383 * gd_maxlen: maximum size of returned file
385 * size: size in bytes of passed in nfsctl_fsparm
387 * On success: passed-in buffer filled with a knfsd_fh structure
388 * (a variable-length raw NFS file handle);
389 * return code is the size in bytes of the file handle
390 * On error: return code is negative errno value
392 * Note: Only AF_INET client addresses are passed in, since gd_addr
393 * is the same size as a struct sockaddr_in.
395 static ssize_t
write_getfs(struct file
*file
, char *buf
, size_t size
)
397 struct nfsctl_fsparm
*data
;
398 struct sockaddr_in
*sin
;
399 struct auth_domain
*clp
;
401 struct knfsd_fh
*res
;
404 if (size
< sizeof(*data
))
406 data
= (struct nfsctl_fsparm
*)buf
;
407 err
= -EPROTONOSUPPORT
;
408 if (data
->gd_addr
.sa_family
!= AF_INET
)
410 sin
= (struct sockaddr_in
*)&data
->gd_addr
;
411 if (data
->gd_maxlen
> NFS3_FHSIZE
)
412 data
->gd_maxlen
= NFS3_FHSIZE
;
414 res
= (struct knfsd_fh
*)buf
;
418 ipv6_addr_set_v4mapped(sin
->sin_addr
.s_addr
, &in6
);
420 clp
= auth_unix_lookup(&init_net
, &in6
);
424 err
= exp_rootfh(clp
, data
->gd_path
, res
, data
->gd_maxlen
);
425 auth_domain_put(clp
);
429 err
= res
->fh_size
+ offsetof(struct knfsd_fh
, fh_base
);
435 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
437 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
438 * Function remains to support old versions of nfs-utils.
441 * buf: struct nfsctl_fdparm
442 * gd_addr: socket address of client
443 * gd_path: '\0'-terminated C string
444 * containing pathname of
445 * directory in local file system
446 * gd_version: fdparm structure version
447 * size: size in bytes of passed in nfsctl_fdparm
449 * On success: passed-in buffer filled with nfsctl_res
450 * (a fixed-length raw NFS file handle);
451 * return code is the size in bytes of the file handle
452 * On error: return code is negative errno value
454 * Note: Only AF_INET client addresses are passed in, since gd_addr
455 * is the same size as a struct sockaddr_in.
457 static ssize_t
write_getfd(struct file
*file
, char *buf
, size_t size
)
459 struct nfsctl_fdparm
*data
;
460 struct sockaddr_in
*sin
;
461 struct auth_domain
*clp
;
467 if (size
< sizeof(*data
))
469 data
= (struct nfsctl_fdparm
*)buf
;
470 err
= -EPROTONOSUPPORT
;
471 if (data
->gd_addr
.sa_family
!= AF_INET
)
474 if (data
->gd_version
< 2 || data
->gd_version
> NFSSVC_MAXVERS
)
478 sin
= (struct sockaddr_in
*)&data
->gd_addr
;
481 ipv6_addr_set_v4mapped(sin
->sin_addr
.s_addr
, &in6
);
483 clp
= auth_unix_lookup(&init_net
, &in6
);
487 err
= exp_rootfh(clp
, data
->gd_path
, &fh
, NFS_FHSIZE
);
488 auth_domain_put(clp
);
493 memset(res
,0, NFS_FHSIZE
);
494 memcpy(res
, &fh
.fh_base
, fh
.fh_size
);
500 #endif /* CONFIG_NFSD_DEPRECATED */
503 * write_unlock_ip - Release all locks used by a client
508 * buf: '\n'-terminated C string containing a
509 * presentation format IP address
510 * size: length of C string in @buf
512 * On success: returns zero if all specified locks were released;
513 * returns one if one or more locks were not released
514 * On error: return code is negative errno value
516 static ssize_t
write_unlock_ip(struct file
*file
, char *buf
, size_t size
)
518 struct sockaddr_storage address
;
519 struct sockaddr
*sap
= (struct sockaddr
*)&address
;
520 size_t salen
= sizeof(address
);
527 if (buf
[size
-1] != '\n')
531 if (qword_get(&buf
, fo_path
, size
) < 0)
534 if (rpc_pton(fo_path
, size
, sap
, salen
) == 0)
537 return nlmsvc_unlock_all_by_ip(sap
);
541 * write_unlock_fs - Release all locks on a local file system
546 * buf: '\n'-terminated C string containing the
547 * absolute pathname of a local file system
548 * size: length of C string in @buf
550 * On success: returns zero if all specified locks were released;
551 * returns one if one or more locks were not released
552 * On error: return code is negative errno value
554 static ssize_t
write_unlock_fs(struct file
*file
, char *buf
, size_t size
)
564 if (buf
[size
-1] != '\n')
568 if (qword_get(&buf
, fo_path
, size
) < 0)
571 error
= kern_path(fo_path
, 0, &path
);
576 * XXX: Needs better sanity checking. Otherwise we could end up
577 * releasing locks on the wrong file system.
580 * 1. Does the path refer to a directory?
581 * 2. Is that directory a mount point, or
582 * 3. Is that directory the root of an exported file system?
584 error
= nlmsvc_unlock_all_by_sb(path
.mnt
->mnt_sb
);
591 * write_filehandle - Get a variable-length NFS file handle by path
593 * On input, the buffer contains a '\n'-terminated C string comprised of
594 * three alphanumeric words separated by whitespace. The string may
595 * contain escape sequences.
599 * domain: client domain name
600 * path: export pathname
601 * maxsize: numeric maximum size of
603 * size: length of C string in @buf
605 * On success: passed-in buffer filled with '\n'-terminated C
606 * string containing a ASCII hex text version
607 * of the NFS file handle;
608 * return code is the size in bytes of the string
609 * On error: return code is negative errno value
611 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
)
614 int uninitialized_var(maxsize
);
617 struct auth_domain
*dom
;
623 if (buf
[size
-1] != '\n')
628 len
= qword_get(&mesg
, dname
, size
);
633 len
= qword_get(&mesg
, path
, size
);
637 len
= get_int(&mesg
, &maxsize
);
641 if (maxsize
< NFS_FHSIZE
)
643 if (maxsize
> NFS3_FHSIZE
)
644 maxsize
= NFS3_FHSIZE
;
646 if (qword_get(&mesg
, mesg
, size
)>0)
649 /* we have all the words, they are in buf.. */
650 dom
= unix_domain_find(dname
);
654 len
= exp_rootfh(dom
, path
, &fh
, maxsize
);
655 auth_domain_put(dom
);
660 len
= SIMPLE_TRANSACTION_LIMIT
;
661 qword_addhex(&mesg
, &len
, (char*)&fh
.fh_base
, fh
.fh_size
);
667 * write_threads - Start NFSD, or report the current number of running threads
673 * On success: passed-in buffer filled with '\n'-terminated C
674 * string numeric value representing the number of
675 * running NFSD threads;
676 * return code is the size in bytes of the string
677 * On error: return code is zero
682 * buf: C string containing an unsigned
683 * integer value representing the
684 * number of NFSD threads to start
685 * size: non-zero length of C string in @buf
687 * On success: NFS service is started;
688 * passed-in buffer filled with '\n'-terminated C
689 * string numeric value representing the number of
690 * running NFSD threads;
691 * return code is the size in bytes of the string
692 * On error: return code is zero or a negative errno value
694 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
)
700 rv
= get_int(&mesg
, &newthreads
);
705 rv
= nfsd_svc(NFS_PORT
, newthreads
);
709 rv
= nfsd_nrthreads();
711 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%d\n", rv
);
715 * write_pool_threads - Set or report the current number of threads per pool
724 * buf: C string containing whitespace-
725 * separated unsigned integer values
726 * representing the number of NFSD
727 * threads to start in each pool
728 * size: non-zero length of C string in @buf
730 * On success: passed-in buffer filled with '\n'-terminated C
731 * string containing integer values representing the
732 * number of NFSD threads in each pool;
733 * return code is the size in bytes of the string
734 * On error: return code is zero or a negative errno value
736 static ssize_t
write_pool_threads(struct file
*file
, char *buf
, size_t size
)
738 /* if size > 0, look for an array of number of threads per node
739 * and apply them then write out number of threads per node as reply
748 mutex_lock(&nfsd_mutex
);
749 npools
= nfsd_nrpools();
752 * NFS is shut down. The admin can start it by
753 * writing to the threads file but NOT the pool_threads
754 * file, sorry. Report zero threads.
756 mutex_unlock(&nfsd_mutex
);
761 nthreads
= kcalloc(npools
, sizeof(int), GFP_KERNEL
);
763 if (nthreads
== NULL
)
767 for (i
= 0; i
< npools
; i
++) {
768 rv
= get_int(&mesg
, &nthreads
[i
]);
770 break; /* fewer numbers than pools */
772 goto out_free
; /* syntax error */
777 rv
= nfsd_set_nrthreads(i
, nthreads
);
782 rv
= nfsd_get_nrthreads(npools
, nthreads
);
787 size
= SIMPLE_TRANSACTION_LIMIT
;
788 for (i
= 0; i
< npools
&& size
> 0; i
++) {
789 snprintf(mesg
, size
, "%d%c", nthreads
[i
], (i
== npools
-1 ? '\n' : ' '));
797 mutex_unlock(&nfsd_mutex
);
801 static ssize_t
__write_versions(struct file
*file
, char *buf
, size_t size
)
804 char *vers
, *minorp
, sign
;
805 int len
, num
, remaining
;
812 /* Cannot change versions without updating
813 * nfsd_serv->sv_xdrsize, and reallocing
814 * rq_argp and rq_resp
817 if (buf
[size
-1] != '\n')
822 len
= qword_get(&mesg
, vers
, size
);
823 if (len
<= 0) return -EINVAL
;
826 if (sign
== '+' || sign
== '-')
827 num
= simple_strtol((vers
+1), &minorp
, 0);
829 num
= simple_strtol(vers
, &minorp
, 0);
830 if (*minorp
== '.') {
833 minor
= simple_strtoul(minorp
+1, NULL
, 0);
836 if (nfsd_minorversion(minor
, sign
== '-' ?
837 NFSD_CLEAR
: NFSD_SET
) < 0)
845 nfsd_vers(num
, sign
== '-' ? NFSD_CLEAR
: NFSD_SET
);
852 } while ((len
= qword_get(&mesg
, vers
, size
)) > 0);
853 /* If all get turned off, turn them back on, as
854 * having no versions is BAD
856 nfsd_reset_versions();
859 /* Now write current state into reply buffer */
862 remaining
= SIMPLE_TRANSACTION_LIMIT
;
863 for (num
=2 ; num
<= 4 ; num
++)
864 if (nfsd_vers(num
, NFSD_AVAIL
)) {
865 len
= snprintf(buf
, remaining
, "%s%c%d", sep
,
866 nfsd_vers(num
, NFSD_TEST
)?'+':'-',
876 if (nfsd_vers(4, NFSD_AVAIL
))
877 for (minor
= 1; minor
<= NFSD_SUPPORTED_MINOR_VERSION
;
879 len
= snprintf(buf
, remaining
, " %c4.%u",
880 (nfsd_vers(4, NFSD_TEST
) &&
881 nfsd_minorversion(minor
, NFSD_TEST
)) ?
892 len
= snprintf(buf
, remaining
, "\n");
899 * write_versions - Set or report the available NFS protocol versions
905 * On success: passed-in buffer filled with '\n'-terminated C
906 * string containing positive or negative integer
907 * values representing the current status of each
909 * return code is the size in bytes of the string
910 * On error: return code is zero or a negative errno value
915 * buf: C string containing whitespace-
916 * separated positive or negative
917 * integer values representing NFS
918 * protocol versions to enable ("+n")
920 * size: non-zero length of C string in @buf
922 * On success: status of zero or more protocol versions has
923 * been updated; passed-in buffer filled with
924 * '\n'-terminated C string containing positive
925 * or negative integer values representing the
926 * current status of each protocol version;
927 * return code is the size in bytes of the string
928 * On error: return code is zero or a negative errno value
930 static ssize_t
write_versions(struct file
*file
, char *buf
, size_t size
)
934 mutex_lock(&nfsd_mutex
);
935 rv
= __write_versions(file
, buf
, size
);
936 mutex_unlock(&nfsd_mutex
);
941 * Zero-length write. Return a list of NFSD's current listener
944 static ssize_t
__write_ports_names(char *buf
)
946 if (nfsd_serv
== NULL
)
948 return svc_xprt_names(nfsd_serv
, buf
, SIMPLE_TRANSACTION_LIMIT
);
952 * A single 'fd' number was written, in which case it must be for
953 * a socket of a supported family/protocol, and we use it as an
956 static ssize_t
__write_ports_addfd(char *buf
)
961 err
= get_int(&mesg
, &fd
);
962 if (err
!= 0 || fd
< 0)
965 err
= nfsd_create_serv();
969 err
= svc_addsock(nfsd_serv
, fd
, buf
, SIMPLE_TRANSACTION_LIMIT
);
971 svc_destroy(nfsd_serv
);
975 /* Decrease the count, but don't shut down the service */
976 nfsd_serv
->sv_nrthreads
--;
981 * A '-' followed by the 'name' of a socket means we close the socket.
983 static ssize_t
__write_ports_delfd(char *buf
)
988 toclose
= kstrdup(buf
+ 1, GFP_KERNEL
);
992 if (nfsd_serv
!= NULL
)
993 len
= svc_sock_names(nfsd_serv
, buf
,
994 SIMPLE_TRANSACTION_LIMIT
, toclose
);
1000 * A transport listener is added by writing it's transport name and
1003 static ssize_t
__write_ports_addxprt(char *buf
)
1006 struct svc_xprt
*xprt
;
1009 if (sscanf(buf
, "%15s %4u", transport
, &port
) != 2)
1012 if (port
< 1 || port
> USHRT_MAX
)
1015 err
= nfsd_create_serv();
1019 err
= svc_create_xprt(nfsd_serv
, transport
, &init_net
,
1020 PF_INET
, port
, SVC_SOCK_ANONYMOUS
);
1024 err
= svc_create_xprt(nfsd_serv
, transport
, &init_net
,
1025 PF_INET6
, port
, SVC_SOCK_ANONYMOUS
);
1026 if (err
< 0 && err
!= -EAFNOSUPPORT
)
1029 /* Decrease the count, but don't shut down the service */
1030 nfsd_serv
->sv_nrthreads
--;
1033 xprt
= svc_find_xprt(nfsd_serv
, transport
, PF_INET
, port
);
1035 svc_close_xprt(xprt
);
1039 svc_destroy(nfsd_serv
);
1044 * A transport listener is removed by writing a "-", it's transport
1045 * name, and it's port number.
1047 static ssize_t
__write_ports_delxprt(char *buf
)
1049 struct svc_xprt
*xprt
;
1053 if (sscanf(&buf
[1], "%15s %4u", transport
, &port
) != 2)
1056 if (port
< 1 || port
> USHRT_MAX
|| nfsd_serv
== NULL
)
1059 xprt
= svc_find_xprt(nfsd_serv
, transport
, AF_UNSPEC
, port
);
1063 svc_close_xprt(xprt
);
1068 static ssize_t
__write_ports(struct file
*file
, char *buf
, size_t size
)
1071 return __write_ports_names(buf
);
1073 if (isdigit(buf
[0]))
1074 return __write_ports_addfd(buf
);
1076 if (buf
[0] == '-' && isdigit(buf
[1]))
1077 return __write_ports_delfd(buf
);
1079 if (isalpha(buf
[0]))
1080 return __write_ports_addxprt(buf
);
1082 if (buf
[0] == '-' && isalpha(buf
[1]))
1083 return __write_ports_delxprt(buf
);
1089 * write_ports - Pass a socket file descriptor or transport name to listen on
1095 * On success: passed-in buffer filled with a '\n'-terminated C
1096 * string containing a whitespace-separated list of
1097 * named NFSD listeners;
1098 * return code is the size in bytes of the string
1099 * On error: return code is zero or a negative errno value
1104 * buf: C string containing an unsigned
1105 * integer value representing a bound
1106 * but unconnected socket that is to be
1107 * used as an NFSD listener; listen(3)
1108 * must be called for a SOCK_STREAM
1109 * socket, otherwise it is ignored
1110 * size: non-zero length of C string in @buf
1112 * On success: NFS service is started;
1113 * passed-in buffer filled with a '\n'-terminated C
1114 * string containing a unique alphanumeric name of
1116 * return code is the size in bytes of the string
1117 * On error: return code is a negative errno value
1122 * buf: C string containing a "-" followed
1123 * by an integer value representing a
1124 * previously passed in socket file
1126 * size: non-zero length of C string in @buf
1128 * On success: NFS service no longer listens on that socket;
1129 * passed-in buffer filled with a '\n'-terminated C
1130 * string containing a unique name of the listener;
1131 * return code is the size in bytes of the string
1132 * On error: return code is a negative errno value
1137 * buf: C string containing a transport
1138 * name and an unsigned integer value
1139 * representing the port to listen on,
1140 * separated by whitespace
1141 * size: non-zero length of C string in @buf
1143 * On success: returns zero; NFS service is started
1144 * On error: return code is a negative errno value
1149 * buf: C string containing a "-" followed
1150 * by a transport name and an unsigned
1151 * integer value representing the port
1152 * to listen on, separated by whitespace
1153 * size: non-zero length of C string in @buf
1155 * On success: returns zero; NFS service no longer listens
1157 * On error: return code is a negative errno value
1159 static ssize_t
write_ports(struct file
*file
, char *buf
, size_t size
)
1163 mutex_lock(&nfsd_mutex
);
1164 rv
= __write_ports(file
, buf
, size
);
1165 mutex_unlock(&nfsd_mutex
);
1170 int nfsd_max_blksize
;
1173 * write_maxblksize - Set or report the current NFS blksize
1182 * buf: C string containing an unsigned
1183 * integer value representing the new
1185 * size: non-zero length of C string in @buf
1187 * On success: passed-in buffer filled with '\n'-terminated C string
1188 * containing numeric value of the current NFS blksize
1190 * return code is the size in bytes of the string
1191 * On error: return code is zero or a negative errno value
1193 static ssize_t
write_maxblksize(struct file
*file
, char *buf
, size_t size
)
1198 int rv
= get_int(&mesg
, &bsize
);
1201 /* force bsize into allowed range and
1202 * required alignment.
1206 if (bsize
> NFSSVC_MAXBLKSIZE
)
1207 bsize
= NFSSVC_MAXBLKSIZE
;
1209 mutex_lock(&nfsd_mutex
);
1211 mutex_unlock(&nfsd_mutex
);
1214 nfsd_max_blksize
= bsize
;
1215 mutex_unlock(&nfsd_mutex
);
1218 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%d\n",
1222 #ifdef CONFIG_NFSD_V4
1223 static ssize_t
__nfsd4_write_time(struct file
*file
, char *buf
, size_t size
, time_t *time
)
1231 rv
= get_int(&mesg
, &i
);
1235 * Some sanity checking. We don't have a reason for
1236 * these particular numbers, but problems with the
1238 * - Too short: the briefest network outage may
1239 * cause clients to lose all their locks. Also,
1240 * the frequent polling may be wasteful.
1241 * - Too long: do you really want reboot recovery
1242 * to take more than an hour? Or to make other
1243 * clients wait an hour before being able to
1244 * revoke a dead client's locks?
1246 if (i
< 10 || i
> 3600)
1251 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%ld\n", *time
);
1254 static ssize_t
nfsd4_write_time(struct file
*file
, char *buf
, size_t size
, time_t *time
)
1258 mutex_lock(&nfsd_mutex
);
1259 rv
= __nfsd4_write_time(file
, buf
, size
, time
);
1260 mutex_unlock(&nfsd_mutex
);
1265 * write_leasetime - Set or report the current NFSv4 lease time
1274 * buf: C string containing an unsigned
1275 * integer value representing the new
1276 * NFSv4 lease expiry time
1277 * size: non-zero length of C string in @buf
1279 * On success: passed-in buffer filled with '\n'-terminated C
1280 * string containing unsigned integer value of the
1281 * current lease expiry time;
1282 * return code is the size in bytes of the string
1283 * On error: return code is zero or a negative errno value
1285 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
)
1287 return nfsd4_write_time(file
, buf
, size
, &nfsd4_lease
);
1291 * write_gracetime - Set or report current NFSv4 grace period time
1293 * As above, but sets the time of the NFSv4 grace period.
1295 * Note this should never be set to less than the *previous*
1296 * lease-period time, but we don't try to enforce this. (In the common
1297 * case (a new boot), we don't know what the previous lease time was
1300 static ssize_t
write_gracetime(struct file
*file
, char *buf
, size_t size
)
1302 return nfsd4_write_time(file
, buf
, size
, &nfsd4_grace
);
1305 extern char *nfs4_recoverydir(void);
1307 static ssize_t
__write_recoverydir(struct file
*file
, char *buf
, size_t size
)
1316 if (size
> PATH_MAX
|| buf
[size
-1] != '\n')
1321 len
= qword_get(&mesg
, recdir
, size
);
1325 status
= nfs4_reset_recoverydir(recdir
);
1330 return scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
, "%s\n",
1331 nfs4_recoverydir());
1335 * write_recoverydir - Set or report the pathname of the recovery directory
1344 * buf: C string containing the pathname
1345 * of the directory on a local file
1346 * system containing permanent NFSv4
1348 * size: non-zero length of C string in @buf
1350 * On success: passed-in buffer filled with '\n'-terminated C string
1351 * containing the current recovery pathname setting;
1352 * return code is the size in bytes of the string
1353 * On error: return code is zero or a negative errno value
1355 static ssize_t
write_recoverydir(struct file
*file
, char *buf
, size_t size
)
1359 mutex_lock(&nfsd_mutex
);
1360 rv
= __write_recoverydir(file
, buf
, size
);
1361 mutex_unlock(&nfsd_mutex
);
1367 /*----------------------------------------------------------------------------*/
1369 * populating the filesystem.
1372 static int nfsd_fill_super(struct super_block
* sb
, void * data
, int silent
)
1374 static struct tree_descr nfsd_files
[] = {
1375 #ifdef CONFIG_NFSD_DEPRECATED
1376 [NFSD_Svc
] = {".svc", &transaction_ops
, S_IWUSR
},
1377 [NFSD_Add
] = {".add", &transaction_ops
, S_IWUSR
},
1378 [NFSD_Del
] = {".del", &transaction_ops
, S_IWUSR
},
1379 [NFSD_Export
] = {".export", &transaction_ops
, S_IWUSR
},
1380 [NFSD_Unexport
] = {".unexport", &transaction_ops
, S_IWUSR
},
1381 [NFSD_Getfd
] = {".getfd", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1382 [NFSD_Getfs
] = {".getfs", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1384 [NFSD_List
] = {"exports", &exports_operations
, S_IRUGO
},
1385 [NFSD_Export_features
] = {"export_features",
1386 &export_features_operations
, S_IRUGO
},
1387 [NFSD_FO_UnlockIP
] = {"unlock_ip",
1388 &transaction_ops
, S_IWUSR
|S_IRUSR
},
1389 [NFSD_FO_UnlockFS
] = {"unlock_filesystem",
1390 &transaction_ops
, S_IWUSR
|S_IRUSR
},
1391 [NFSD_Fh
] = {"filehandle", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1392 [NFSD_Threads
] = {"threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1393 [NFSD_Pool_Threads
] = {"pool_threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1394 [NFSD_Pool_Stats
] = {"pool_stats", &pool_stats_operations
, S_IRUGO
},
1395 [NFSD_Versions
] = {"versions", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1396 [NFSD_Ports
] = {"portlist", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1397 [NFSD_MaxBlkSize
] = {"max_block_size", &transaction_ops
, S_IWUSR
|S_IRUGO
},
1398 #ifdef CONFIG_NFSD_V4
1399 [NFSD_Leasetime
] = {"nfsv4leasetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1400 [NFSD_Gracetime
] = {"nfsv4gracetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1401 [NFSD_RecoveryDir
] = {"nfsv4recoverydir", &transaction_ops
, S_IWUSR
|S_IRUSR
},
1405 return simple_fill_super(sb
, 0x6e667364, nfsd_files
);
1408 static struct dentry
*nfsd_mount(struct file_system_type
*fs_type
,
1409 int flags
, const char *dev_name
, void *data
)
1411 return mount_single(fs_type
, flags
, data
, nfsd_fill_super
);
1414 static struct file_system_type nfsd_fs_type
= {
1415 .owner
= THIS_MODULE
,
1417 .mount
= nfsd_mount
,
1418 .kill_sb
= kill_litter_super
,
1421 #ifdef CONFIG_PROC_FS
1422 static int create_proc_exports_entry(void)
1424 struct proc_dir_entry
*entry
;
1426 entry
= proc_mkdir("fs/nfs", NULL
);
1429 entry
= proc_create("exports", 0, entry
, &exports_operations
);
1434 #else /* CONFIG_PROC_FS */
1435 static int create_proc_exports_entry(void)
1441 static int __init
init_nfsd(void)
1444 printk(KERN_INFO
"Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1446 retval
= nfs4_state_init(); /* nfs4 locking state */
1449 nfsd_stat_init(); /* Statistics */
1450 retval
= nfsd_reply_cache_init();
1453 retval
= nfsd_export_init();
1455 goto out_free_cache
;
1456 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1457 retval
= nfsd_idmap_init();
1459 goto out_free_lockd
;
1460 retval
= create_proc_exports_entry();
1462 goto out_free_idmap
;
1463 retval
= register_filesystem(&nfsd_fs_type
);
1468 remove_proc_entry("fs/nfs/exports", NULL
);
1469 remove_proc_entry("fs/nfs", NULL
);
1471 nfsd_idmap_shutdown();
1473 nfsd_lockd_shutdown();
1474 nfsd_export_shutdown();
1476 nfsd_reply_cache_shutdown();
1478 nfsd_stat_shutdown();
1483 static void __exit
exit_nfsd(void)
1485 nfsd_export_shutdown();
1486 nfsd_reply_cache_shutdown();
1487 remove_proc_entry("fs/nfs/exports", NULL
);
1488 remove_proc_entry("fs/nfs", NULL
);
1489 nfsd_stat_shutdown();
1490 nfsd_lockd_shutdown();
1491 nfsd_idmap_shutdown();
1493 unregister_filesystem(&nfsd_fs_type
);
1496 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1497 MODULE_LICENSE("GPL");
1498 module_init(init_nfsd
)
1499 module_exit(exit_nfsd
)