]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Syscall interface to knfsd. |
3 | * | |
4 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> | |
5 | */ | |
6 | ||
5a0e3ad6 | 7 | #include <linux/slab.h> |
3f8206d4 | 8 | #include <linux/namei.h> |
b41b66d6 | 9 | #include <linux/ctype.h> |
1da177e4 | 10 | |
1da177e4 | 11 | #include <linux/nfsd_idmap.h> |
80212d59 | 12 | #include <linux/sunrpc/svcsock.h> |
1da177e4 | 13 | #include <linux/nfsd/syscall.h> |
4373ea84 | 14 | #include <linux/lockd/lockd.h> |
4116092b | 15 | #include <linux/sunrpc/clnt.h> |
1da177e4 | 16 | |
9a74af21 BH |
17 | #include "nfsd.h" |
18 | #include "cache.h" | |
19 | ||
1da177e4 LT |
20 | /* |
21 | * We have a single directory with 9 nodes in it. | |
22 | */ | |
23 | enum { | |
24 | NFSD_Root = 1, | |
25 | NFSD_Svc, | |
26 | NFSD_Add, | |
27 | NFSD_Del, | |
28 | NFSD_Export, | |
29 | NFSD_Unexport, | |
30 | NFSD_Getfd, | |
31 | NFSD_Getfs, | |
32 | NFSD_List, | |
e8e8753f | 33 | NFSD_Export_features, |
1da177e4 | 34 | NFSD_Fh, |
4373ea84 | 35 | NFSD_FO_UnlockIP, |
17efa372 | 36 | NFSD_FO_UnlockFS, |
1da177e4 | 37 | NFSD_Threads, |
eed2965a | 38 | NFSD_Pool_Threads, |
03cf6c9f | 39 | NFSD_Pool_Stats, |
70c3b76c | 40 | NFSD_Versions, |
80212d59 | 41 | NFSD_Ports, |
596bbe53 | 42 | NFSD_MaxBlkSize, |
70c3b76c N |
43 | /* |
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 | |
46 | */ | |
47 | #ifdef CONFIG_NFSD_V4 | |
1da177e4 | 48 | NFSD_Leasetime, |
efc4bb4f | 49 | NFSD_Gracetime, |
0964a3d3 | 50 | NFSD_RecoveryDir, |
70c3b76c | 51 | #endif |
1da177e4 LT |
52 | }; |
53 | ||
54 | /* | |
55 | * write() for these nodes. | |
56 | */ | |
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); | |
b046ccdc CL |
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); | |
1da177e4 | 67 | static ssize_t write_threads(struct file *file, char *buf, size_t size); |
eed2965a | 68 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); |
70c3b76c | 69 | static ssize_t write_versions(struct file *file, char *buf, size_t size); |
80212d59 | 70 | static ssize_t write_ports(struct file *file, char *buf, size_t size); |
596bbe53 | 71 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); |
70c3b76c | 72 | #ifdef CONFIG_NFSD_V4 |
1da177e4 | 73 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size); |
efc4bb4f | 74 | static ssize_t write_gracetime(struct file *file, char *buf, size_t size); |
0964a3d3 | 75 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); |
70c3b76c | 76 | #endif |
1da177e4 LT |
77 | |
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, | |
b046ccdc CL |
87 | [NFSD_FO_UnlockIP] = write_unlock_ip, |
88 | [NFSD_FO_UnlockFS] = write_unlock_fs, | |
1da177e4 | 89 | [NFSD_Threads] = write_threads, |
eed2965a | 90 | [NFSD_Pool_Threads] = write_pool_threads, |
70c3b76c | 91 | [NFSD_Versions] = write_versions, |
80212d59 | 92 | [NFSD_Ports] = write_ports, |
596bbe53 | 93 | [NFSD_MaxBlkSize] = write_maxblksize, |
70c3b76c | 94 | #ifdef CONFIG_NFSD_V4 |
1da177e4 | 95 | [NFSD_Leasetime] = write_leasetime, |
efc4bb4f | 96 | [NFSD_Gracetime] = write_gracetime, |
0964a3d3 | 97 | [NFSD_RecoveryDir] = write_recoverydir, |
70c3b76c | 98 | #endif |
1da177e4 LT |
99 | }; |
100 | ||
101 | static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) | |
102 | { | |
7eaa36e2 | 103 | ino_t ino = file->f_path.dentry->d_inode->i_ino; |
1da177e4 LT |
104 | char *data; |
105 | ssize_t rv; | |
106 | ||
e8c96f8c | 107 | if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) |
1da177e4 LT |
108 | return -EINVAL; |
109 | ||
110 | data = simple_transaction_get(file, buf, size); | |
111 | if (IS_ERR(data)) | |
112 | return PTR_ERR(data); | |
113 | ||
114 | rv = write_op[ino](file, data, size); | |
8971a101 | 115 | if (rv >= 0) { |
1da177e4 LT |
116 | simple_transaction_set(file, rv); |
117 | rv = size; | |
118 | } | |
119 | return rv; | |
120 | } | |
121 | ||
7390022d N |
122 | static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) |
123 | { | |
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 | |
127 | * state information | |
128 | */ | |
129 | ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); | |
130 | if (rv < 0) | |
131 | return rv; | |
132 | } | |
133 | return simple_transaction_read(file, buf, size, pos); | |
134 | } | |
135 | ||
4b6f5d20 | 136 | static const struct file_operations transaction_ops = { |
1da177e4 | 137 | .write = nfsctl_transaction_write, |
7390022d | 138 | .read = nfsctl_transaction_read, |
1da177e4 LT |
139 | .release = simple_transaction_release, |
140 | }; | |
141 | ||
1da177e4 LT |
142 | static int exports_open(struct inode *inode, struct file *file) |
143 | { | |
144 | return seq_open(file, &nfs_exports_op); | |
145 | } | |
146 | ||
4b6f5d20 | 147 | static const struct file_operations exports_operations = { |
1da177e4 LT |
148 | .open = exports_open, |
149 | .read = seq_read, | |
150 | .llseek = seq_lseek, | |
151 | .release = seq_release, | |
9ef2db26 | 152 | .owner = THIS_MODULE, |
1da177e4 LT |
153 | }; |
154 | ||
e8e8753f BF |
155 | static int export_features_show(struct seq_file *m, void *v) |
156 | { | |
157 | seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS); | |
158 | return 0; | |
159 | } | |
160 | ||
161 | static int export_features_open(struct inode *inode, struct file *file) | |
162 | { | |
163 | return single_open(file, export_features_show, NULL); | |
164 | } | |
165 | ||
166 | static struct file_operations export_features_operations = { | |
167 | .open = export_features_open, | |
168 | .read = seq_read, | |
169 | .llseek = seq_lseek, | |
170 | .release = single_release, | |
171 | }; | |
172 | ||
03cf6c9f | 173 | extern int nfsd_pool_stats_open(struct inode *inode, struct file *file); |
ed2d8aed | 174 | extern int nfsd_pool_stats_release(struct inode *inode, struct file *file); |
03cf6c9f | 175 | |
828c0950 | 176 | static const struct file_operations pool_stats_operations = { |
03cf6c9f GB |
177 | .open = nfsd_pool_stats_open, |
178 | .read = seq_read, | |
179 | .llseek = seq_lseek, | |
ed2d8aed | 180 | .release = nfsd_pool_stats_release, |
03cf6c9f GB |
181 | .owner = THIS_MODULE, |
182 | }; | |
183 | ||
1da177e4 LT |
184 | /*----------------------------------------------------------------------------*/ |
185 | /* | |
186 | * payload - write methods | |
1da177e4 LT |
187 | */ |
188 | ||
262a0982 CL |
189 | /** |
190 | * write_svc - Start kernel's NFSD server | |
191 | * | |
192 | * Deprecated. /proc/fs/nfsd/threads is preferred. | |
193 | * Function remains to support old versions of nfs-utils. | |
194 | * | |
195 | * Input: | |
196 | * buf: struct nfsctl_svc | |
197 | * svc_port: port number of this | |
198 | * server's listener | |
199 | * svc_nthreads: number of threads to start | |
200 | * size: size in bytes of passed in nfsctl_svc | |
201 | * Output: | |
202 | * On success: returns zero | |
203 | * On error: return code is negative errno value | |
204 | */ | |
1da177e4 LT |
205 | static ssize_t write_svc(struct file *file, char *buf, size_t size) |
206 | { | |
207 | struct nfsctl_svc *data; | |
82e12fe9 | 208 | int err; |
1da177e4 LT |
209 | if (size < sizeof(*data)) |
210 | return -EINVAL; | |
211 | data = (struct nfsctl_svc*) buf; | |
82e12fe9 N |
212 | err = nfsd_svc(data->svc_port, data->svc_nthreads); |
213 | if (err < 0) | |
214 | return err; | |
215 | return 0; | |
1da177e4 LT |
216 | } |
217 | ||
262a0982 CL |
218 | /** |
219 | * write_add - Add or modify client entry in auth unix cache | |
220 | * | |
221 | * Deprecated. /proc/net/rpc/auth.unix.ip is preferred. | |
222 | * Function remains to support old versions of nfs-utils. | |
223 | * | |
224 | * Input: | |
225 | * buf: struct nfsctl_client | |
226 | * cl_ident: '\0'-terminated C string | |
227 | * containing domain name | |
228 | * of client | |
229 | * cl_naddr: no. of items in cl_addrlist | |
230 | * cl_addrlist: array of client addresses | |
231 | * cl_fhkeytype: ignored | |
232 | * cl_fhkeylen: ignored | |
233 | * cl_fhkey: ignored | |
234 | * size: size in bytes of passed in nfsctl_client | |
235 | * Output: | |
236 | * On success: returns zero | |
237 | * On error: return code is negative errno value | |
238 | * | |
239 | * Note: Only AF_INET client addresses are passed in, since | |
240 | * nfsctl_client.cl_addrlist contains only in_addr fields for addresses. | |
241 | */ | |
1da177e4 LT |
242 | static ssize_t write_add(struct file *file, char *buf, size_t size) |
243 | { | |
244 | struct nfsctl_client *data; | |
245 | if (size < sizeof(*data)) | |
246 | return -EINVAL; | |
247 | data = (struct nfsctl_client *)buf; | |
248 | return exp_addclient(data); | |
249 | } | |
250 | ||
262a0982 CL |
251 | /** |
252 | * write_del - Remove client from auth unix cache | |
253 | * | |
254 | * Deprecated. /proc/net/rpc/auth.unix.ip is preferred. | |
255 | * Function remains to support old versions of nfs-utils. | |
256 | * | |
257 | * Input: | |
258 | * buf: struct nfsctl_client | |
259 | * cl_ident: '\0'-terminated C string | |
260 | * containing domain name | |
261 | * of client | |
262 | * cl_naddr: ignored | |
263 | * cl_addrlist: ignored | |
264 | * cl_fhkeytype: ignored | |
265 | * cl_fhkeylen: ignored | |
266 | * cl_fhkey: ignored | |
267 | * size: size in bytes of passed in nfsctl_client | |
268 | * Output: | |
269 | * On success: returns zero | |
270 | * On error: return code is negative errno value | |
271 | * | |
272 | * Note: Only AF_INET client addresses are passed in, since | |
273 | * nfsctl_client.cl_addrlist contains only in_addr fields for addresses. | |
274 | */ | |
1da177e4 LT |
275 | static ssize_t write_del(struct file *file, char *buf, size_t size) |
276 | { | |
277 | struct nfsctl_client *data; | |
278 | if (size < sizeof(*data)) | |
279 | return -EINVAL; | |
280 | data = (struct nfsctl_client *)buf; | |
281 | return exp_delclient(data); | |
282 | } | |
283 | ||
262a0982 CL |
284 | /** |
285 | * write_export - Export part or all of a local file system | |
286 | * | |
287 | * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred. | |
288 | * Function remains to support old versions of nfs-utils. | |
289 | * | |
290 | * Input: | |
291 | * buf: struct nfsctl_export | |
292 | * ex_client: '\0'-terminated C string | |
293 | * containing domain name | |
294 | * of client allowed to access | |
295 | * this export | |
296 | * ex_path: '\0'-terminated C string | |
297 | * containing pathname of | |
298 | * directory in local file system | |
299 | * ex_dev: fsid to use for this export | |
300 | * ex_ino: ignored | |
301 | * ex_flags: export flags for this export | |
302 | * ex_anon_uid: UID to use for anonymous | |
303 | * requests | |
304 | * ex_anon_gid: GID to use for anonymous | |
305 | * requests | |
306 | * size: size in bytes of passed in nfsctl_export | |
307 | * Output: | |
308 | * On success: returns zero | |
309 | * On error: return code is negative errno value | |
310 | */ | |
1da177e4 LT |
311 | static ssize_t write_export(struct file *file, char *buf, size_t size) |
312 | { | |
313 | struct nfsctl_export *data; | |
314 | if (size < sizeof(*data)) | |
315 | return -EINVAL; | |
316 | data = (struct nfsctl_export*)buf; | |
317 | return exp_export(data); | |
318 | } | |
319 | ||
262a0982 CL |
320 | /** |
321 | * write_unexport - Unexport a previously exported file system | |
322 | * | |
323 | * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred. | |
324 | * Function remains to support old versions of nfs-utils. | |
325 | * | |
326 | * Input: | |
327 | * buf: struct nfsctl_export | |
328 | * ex_client: '\0'-terminated C string | |
329 | * containing domain name | |
330 | * of client no longer allowed | |
331 | * to access this export | |
332 | * ex_path: '\0'-terminated C string | |
333 | * containing pathname of | |
334 | * directory in local file system | |
335 | * ex_dev: ignored | |
336 | * ex_ino: ignored | |
337 | * ex_flags: ignored | |
338 | * ex_anon_uid: ignored | |
339 | * ex_anon_gid: ignored | |
340 | * size: size in bytes of passed in nfsctl_export | |
341 | * Output: | |
342 | * On success: returns zero | |
343 | * On error: return code is negative errno value | |
344 | */ | |
1da177e4 LT |
345 | static ssize_t write_unexport(struct file *file, char *buf, size_t size) |
346 | { | |
347 | struct nfsctl_export *data; | |
348 | ||
349 | if (size < sizeof(*data)) | |
350 | return -EINVAL; | |
351 | data = (struct nfsctl_export*)buf; | |
352 | return exp_unexport(data); | |
353 | } | |
354 | ||
262a0982 CL |
355 | /** |
356 | * write_getfs - Get a variable-length NFS file handle by path | |
357 | * | |
358 | * Deprecated. /proc/fs/nfsd/filehandle is preferred. | |
359 | * Function remains to support old versions of nfs-utils. | |
360 | * | |
361 | * Input: | |
362 | * buf: struct nfsctl_fsparm | |
363 | * gd_addr: socket address of client | |
364 | * gd_path: '\0'-terminated C string | |
365 | * containing pathname of | |
366 | * directory in local file system | |
367 | * gd_maxlen: maximum size of returned file | |
368 | * handle | |
369 | * size: size in bytes of passed in nfsctl_fsparm | |
370 | * Output: | |
371 | * On success: passed-in buffer filled with a knfsd_fh structure | |
372 | * (a variable-length raw NFS file handle); | |
373 | * return code is the size in bytes of the file handle | |
374 | * On error: return code is negative errno value | |
375 | * | |
376 | * Note: Only AF_INET client addresses are passed in, since gd_addr | |
377 | * is the same size as a struct sockaddr_in. | |
378 | */ | |
1da177e4 LT |
379 | static ssize_t write_getfs(struct file *file, char *buf, size_t size) |
380 | { | |
381 | struct nfsctl_fsparm *data; | |
382 | struct sockaddr_in *sin; | |
383 | struct auth_domain *clp; | |
384 | int err = 0; | |
385 | struct knfsd_fh *res; | |
f15364bd | 386 | struct in6_addr in6; |
1da177e4 LT |
387 | |
388 | if (size < sizeof(*data)) | |
389 | return -EINVAL; | |
390 | data = (struct nfsctl_fsparm*)buf; | |
391 | err = -EPROTONOSUPPORT; | |
392 | if (data->gd_addr.sa_family != AF_INET) | |
393 | goto out; | |
394 | sin = (struct sockaddr_in *)&data->gd_addr; | |
395 | if (data->gd_maxlen > NFS3_FHSIZE) | |
396 | data->gd_maxlen = NFS3_FHSIZE; | |
397 | ||
398 | res = (struct knfsd_fh*)buf; | |
399 | ||
400 | exp_readlock(); | |
f15364bd AC |
401 | |
402 | ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6); | |
403 | ||
404 | clp = auth_unix_lookup(&in6); | |
405 | if (!clp) | |
1da177e4 LT |
406 | err = -EPERM; |
407 | else { | |
408 | err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen); | |
409 | auth_domain_put(clp); | |
410 | } | |
411 | exp_readunlock(); | |
412 | if (err == 0) | |
12127498 | 413 | err = res->fh_size + offsetof(struct knfsd_fh, fh_base); |
1da177e4 LT |
414 | out: |
415 | return err; | |
416 | } | |
417 | ||
262a0982 CL |
418 | /** |
419 | * write_getfd - Get a fixed-length NFS file handle by path (used by mountd) | |
420 | * | |
421 | * Deprecated. /proc/fs/nfsd/filehandle is preferred. | |
422 | * Function remains to support old versions of nfs-utils. | |
423 | * | |
424 | * Input: | |
425 | * buf: struct nfsctl_fdparm | |
426 | * gd_addr: socket address of client | |
427 | * gd_path: '\0'-terminated C string | |
428 | * containing pathname of | |
429 | * directory in local file system | |
430 | * gd_version: fdparm structure version | |
431 | * size: size in bytes of passed in nfsctl_fdparm | |
432 | * Output: | |
433 | * On success: passed-in buffer filled with nfsctl_res | |
434 | * (a fixed-length raw NFS file handle); | |
435 | * return code is the size in bytes of the file handle | |
436 | * On error: return code is negative errno value | |
437 | * | |
438 | * Note: Only AF_INET client addresses are passed in, since gd_addr | |
439 | * is the same size as a struct sockaddr_in. | |
440 | */ | |
1da177e4 LT |
441 | static ssize_t write_getfd(struct file *file, char *buf, size_t size) |
442 | { | |
443 | struct nfsctl_fdparm *data; | |
444 | struct sockaddr_in *sin; | |
445 | struct auth_domain *clp; | |
446 | int err = 0; | |
447 | struct knfsd_fh fh; | |
448 | char *res; | |
f15364bd | 449 | struct in6_addr in6; |
1da177e4 LT |
450 | |
451 | if (size < sizeof(*data)) | |
452 | return -EINVAL; | |
453 | data = (struct nfsctl_fdparm*)buf; | |
454 | err = -EPROTONOSUPPORT; | |
455 | if (data->gd_addr.sa_family != AF_INET) | |
456 | goto out; | |
457 | err = -EINVAL; | |
458 | if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS) | |
459 | goto out; | |
460 | ||
461 | res = buf; | |
462 | sin = (struct sockaddr_in *)&data->gd_addr; | |
463 | exp_readlock(); | |
f15364bd AC |
464 | |
465 | ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6); | |
466 | ||
467 | clp = auth_unix_lookup(&in6); | |
468 | if (!clp) | |
1da177e4 LT |
469 | err = -EPERM; |
470 | else { | |
471 | err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE); | |
472 | auth_domain_put(clp); | |
473 | } | |
474 | exp_readunlock(); | |
475 | ||
476 | if (err == 0) { | |
477 | memset(res,0, NFS_FHSIZE); | |
478 | memcpy(res, &fh.fh_base, fh.fh_size); | |
479 | err = NFS_FHSIZE; | |
480 | } | |
481 | out: | |
482 | return err; | |
483 | } | |
484 | ||
262a0982 CL |
485 | /** |
486 | * write_unlock_ip - Release all locks used by a client | |
487 | * | |
488 | * Experimental. | |
489 | * | |
490 | * Input: | |
491 | * buf: '\n'-terminated C string containing a | |
4116092b | 492 | * presentation format IP address |
262a0982 CL |
493 | * size: length of C string in @buf |
494 | * Output: | |
495 | * On success: returns zero if all specified locks were released; | |
496 | * returns one if one or more locks were not released | |
497 | * On error: return code is negative errno value | |
262a0982 | 498 | */ |
b046ccdc | 499 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) |
4373ea84 | 500 | { |
4116092b CL |
501 | struct sockaddr_storage address; |
502 | struct sockaddr *sap = (struct sockaddr *)&address; | |
503 | size_t salen = sizeof(address); | |
367c8c7b | 504 | char *fo_path; |
4373ea84 WC |
505 | |
506 | /* sanity check */ | |
507 | if (size == 0) | |
508 | return -EINVAL; | |
509 | ||
510 | if (buf[size-1] != '\n') | |
511 | return -EINVAL; | |
512 | ||
513 | fo_path = buf; | |
514 | if (qword_get(&buf, fo_path, size) < 0) | |
515 | return -EINVAL; | |
516 | ||
4116092b | 517 | if (rpc_pton(fo_path, size, sap, salen) == 0) |
4373ea84 | 518 | return -EINVAL; |
4373ea84 | 519 | |
4116092b | 520 | return nlmsvc_unlock_all_by_ip(sap); |
4373ea84 WC |
521 | } |
522 | ||
262a0982 CL |
523 | /** |
524 | * write_unlock_fs - Release all locks on a local file system | |
525 | * | |
526 | * Experimental. | |
527 | * | |
528 | * Input: | |
529 | * buf: '\n'-terminated C string containing the | |
530 | * absolute pathname of a local file system | |
531 | * size: length of C string in @buf | |
532 | * Output: | |
533 | * On success: returns zero if all specified locks were released; | |
534 | * returns one if one or more locks were not released | |
535 | * On error: return code is negative errno value | |
536 | */ | |
b046ccdc | 537 | static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) |
17efa372 | 538 | { |
a63bb996 | 539 | struct path path; |
17efa372 WC |
540 | char *fo_path; |
541 | int error; | |
542 | ||
543 | /* sanity check */ | |
544 | if (size == 0) | |
545 | return -EINVAL; | |
546 | ||
547 | if (buf[size-1] != '\n') | |
548 | return -EINVAL; | |
549 | ||
550 | fo_path = buf; | |
551 | if (qword_get(&buf, fo_path, size) < 0) | |
552 | return -EINVAL; | |
553 | ||
a63bb996 | 554 | error = kern_path(fo_path, 0, &path); |
17efa372 WC |
555 | if (error) |
556 | return error; | |
557 | ||
262a0982 CL |
558 | /* |
559 | * XXX: Needs better sanity checking. Otherwise we could end up | |
560 | * releasing locks on the wrong file system. | |
561 | * | |
562 | * For example: | |
563 | * 1. Does the path refer to a directory? | |
564 | * 2. Is that directory a mount point, or | |
565 | * 3. Is that directory the root of an exported file system? | |
566 | */ | |
a63bb996 | 567 | error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb); |
17efa372 | 568 | |
a63bb996 | 569 | path_put(&path); |
17efa372 WC |
570 | return error; |
571 | } | |
572 | ||
262a0982 CL |
573 | /** |
574 | * write_filehandle - Get a variable-length NFS file handle by path | |
575 | * | |
576 | * On input, the buffer contains a '\n'-terminated C string comprised of | |
577 | * three alphanumeric words separated by whitespace. The string may | |
578 | * contain escape sequences. | |
579 | * | |
580 | * Input: | |
581 | * buf: | |
582 | * domain: client domain name | |
583 | * path: export pathname | |
584 | * maxsize: numeric maximum size of | |
585 | * @buf | |
586 | * size: length of C string in @buf | |
587 | * Output: | |
588 | * On success: passed-in buffer filled with '\n'-terminated C | |
589 | * string containing a ASCII hex text version | |
590 | * of the NFS file handle; | |
591 | * return code is the size in bytes of the string | |
592 | * On error: return code is negative errno value | |
593 | */ | |
1da177e4 LT |
594 | static ssize_t write_filehandle(struct file *file, char *buf, size_t size) |
595 | { | |
1da177e4 | 596 | char *dname, *path; |
246d95ba | 597 | int uninitialized_var(maxsize); |
1da177e4 LT |
598 | char *mesg = buf; |
599 | int len; | |
600 | struct auth_domain *dom; | |
601 | struct knfsd_fh fh; | |
602 | ||
87d26ea7 BF |
603 | if (size == 0) |
604 | return -EINVAL; | |
605 | ||
1da177e4 LT |
606 | if (buf[size-1] != '\n') |
607 | return -EINVAL; | |
608 | buf[size-1] = 0; | |
609 | ||
610 | dname = mesg; | |
611 | len = qword_get(&mesg, dname, size); | |
54224f04 CL |
612 | if (len <= 0) |
613 | return -EINVAL; | |
1da177e4 LT |
614 | |
615 | path = dname+len+1; | |
616 | len = qword_get(&mesg, path, size); | |
54224f04 CL |
617 | if (len <= 0) |
618 | return -EINVAL; | |
1da177e4 LT |
619 | |
620 | len = get_int(&mesg, &maxsize); | |
621 | if (len) | |
622 | return len; | |
623 | ||
624 | if (maxsize < NFS_FHSIZE) | |
625 | return -EINVAL; | |
626 | if (maxsize > NFS3_FHSIZE) | |
627 | maxsize = NFS3_FHSIZE; | |
628 | ||
629 | if (qword_get(&mesg, mesg, size)>0) | |
630 | return -EINVAL; | |
631 | ||
632 | /* we have all the words, they are in buf.. */ | |
633 | dom = unix_domain_find(dname); | |
634 | if (!dom) | |
635 | return -ENOMEM; | |
636 | ||
637 | len = exp_rootfh(dom, path, &fh, maxsize); | |
638 | auth_domain_put(dom); | |
639 | if (len) | |
640 | return len; | |
641 | ||
54224f04 CL |
642 | mesg = buf; |
643 | len = SIMPLE_TRANSACTION_LIMIT; | |
1da177e4 LT |
644 | qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); |
645 | mesg[-1] = '\n'; | |
646 | return mesg - buf; | |
647 | } | |
648 | ||
262a0982 CL |
649 | /** |
650 | * write_threads - Start NFSD, or report the current number of running threads | |
651 | * | |
652 | * Input: | |
653 | * buf: ignored | |
654 | * size: zero | |
655 | * Output: | |
656 | * On success: passed-in buffer filled with '\n'-terminated C | |
657 | * string numeric value representing the number of | |
658 | * running NFSD threads; | |
659 | * return code is the size in bytes of the string | |
660 | * On error: return code is zero | |
661 | * | |
662 | * OR | |
663 | * | |
664 | * Input: | |
665 | * buf: C string containing an unsigned | |
666 | * integer value representing the | |
667 | * number of NFSD threads to start | |
668 | * size: non-zero length of C string in @buf | |
669 | * Output: | |
670 | * On success: NFS service is started; | |
671 | * passed-in buffer filled with '\n'-terminated C | |
672 | * string numeric value representing the number of | |
673 | * running NFSD threads; | |
674 | * return code is the size in bytes of the string | |
675 | * On error: return code is zero or a negative errno value | |
676 | */ | |
1da177e4 LT |
677 | static ssize_t write_threads(struct file *file, char *buf, size_t size) |
678 | { | |
1da177e4 LT |
679 | char *mesg = buf; |
680 | int rv; | |
681 | if (size > 0) { | |
682 | int newthreads; | |
683 | rv = get_int(&mesg, &newthreads); | |
684 | if (rv) | |
685 | return rv; | |
9e074856 | 686 | if (newthreads < 0) |
1da177e4 | 687 | return -EINVAL; |
9e074856 | 688 | rv = nfsd_svc(NFS_PORT, newthreads); |
82e12fe9 | 689 | if (rv < 0) |
1da177e4 | 690 | return rv; |
82e12fe9 N |
691 | } else |
692 | rv = nfsd_nrthreads(); | |
e06b6405 | 693 | |
82e12fe9 | 694 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); |
1da177e4 LT |
695 | } |
696 | ||
262a0982 CL |
697 | /** |
698 | * write_pool_threads - Set or report the current number of threads per pool | |
699 | * | |
700 | * Input: | |
701 | * buf: ignored | |
702 | * size: zero | |
703 | * | |
704 | * OR | |
705 | * | |
706 | * Input: | |
707 | * buf: C string containing whitespace- | |
708 | * separated unsigned integer values | |
709 | * representing the number of NFSD | |
710 | * threads to start in each pool | |
711 | * size: non-zero length of C string in @buf | |
712 | * Output: | |
713 | * On success: passed-in buffer filled with '\n'-terminated C | |
714 | * string containing integer values representing the | |
715 | * number of NFSD threads in each pool; | |
716 | * return code is the size in bytes of the string | |
717 | * On error: return code is zero or a negative errno value | |
718 | */ | |
eed2965a GB |
719 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) |
720 | { | |
721 | /* if size > 0, look for an array of number of threads per node | |
722 | * and apply them then write out number of threads per node as reply | |
723 | */ | |
724 | char *mesg = buf; | |
725 | int i; | |
726 | int rv; | |
727 | int len; | |
bedbdd8b | 728 | int npools; |
eed2965a GB |
729 | int *nthreads; |
730 | ||
bedbdd8b NB |
731 | mutex_lock(&nfsd_mutex); |
732 | npools = nfsd_nrpools(); | |
eed2965a GB |
733 | if (npools == 0) { |
734 | /* | |
735 | * NFS is shut down. The admin can start it by | |
736 | * writing to the threads file but NOT the pool_threads | |
737 | * file, sorry. Report zero threads. | |
738 | */ | |
bedbdd8b | 739 | mutex_unlock(&nfsd_mutex); |
eed2965a GB |
740 | strcpy(buf, "0\n"); |
741 | return strlen(buf); | |
742 | } | |
743 | ||
744 | nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); | |
bedbdd8b | 745 | rv = -ENOMEM; |
eed2965a | 746 | if (nthreads == NULL) |
bedbdd8b | 747 | goto out_free; |
eed2965a GB |
748 | |
749 | if (size > 0) { | |
750 | for (i = 0; i < npools; i++) { | |
751 | rv = get_int(&mesg, &nthreads[i]); | |
752 | if (rv == -ENOENT) | |
753 | break; /* fewer numbers than pools */ | |
754 | if (rv) | |
755 | goto out_free; /* syntax error */ | |
756 | rv = -EINVAL; | |
757 | if (nthreads[i] < 0) | |
758 | goto out_free; | |
759 | } | |
760 | rv = nfsd_set_nrthreads(i, nthreads); | |
761 | if (rv) | |
762 | goto out_free; | |
763 | } | |
764 | ||
765 | rv = nfsd_get_nrthreads(npools, nthreads); | |
766 | if (rv) | |
767 | goto out_free; | |
768 | ||
769 | mesg = buf; | |
770 | size = SIMPLE_TRANSACTION_LIMIT; | |
771 | for (i = 0; i < npools && size > 0; i++) { | |
772 | snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); | |
773 | len = strlen(mesg); | |
774 | size -= len; | |
775 | mesg += len; | |
776 | } | |
413d63d7 | 777 | rv = mesg - buf; |
eed2965a GB |
778 | out_free: |
779 | kfree(nthreads); | |
bedbdd8b | 780 | mutex_unlock(&nfsd_mutex); |
eed2965a GB |
781 | return rv; |
782 | } | |
783 | ||
3dd98a3b | 784 | static ssize_t __write_versions(struct file *file, char *buf, size_t size) |
70c3b76c | 785 | { |
70c3b76c | 786 | char *mesg = buf; |
8daf220a | 787 | char *vers, *minorp, sign; |
261758b5 | 788 | int len, num, remaining; |
8daf220a | 789 | unsigned minor; |
70c3b76c N |
790 | ssize_t tlen = 0; |
791 | char *sep; | |
792 | ||
793 | if (size>0) { | |
794 | if (nfsd_serv) | |
6658d3a7 N |
795 | /* Cannot change versions without updating |
796 | * nfsd_serv->sv_xdrsize, and reallocing | |
797 | * rq_argp and rq_resp | |
798 | */ | |
70c3b76c N |
799 | return -EBUSY; |
800 | if (buf[size-1] != '\n') | |
801 | return -EINVAL; | |
802 | buf[size-1] = 0; | |
803 | ||
804 | vers = mesg; | |
805 | len = qword_get(&mesg, vers, size); | |
806 | if (len <= 0) return -EINVAL; | |
807 | do { | |
808 | sign = *vers; | |
809 | if (sign == '+' || sign == '-') | |
8daf220a | 810 | num = simple_strtol((vers+1), &minorp, 0); |
70c3b76c | 811 | else |
8daf220a BH |
812 | num = simple_strtol(vers, &minorp, 0); |
813 | if (*minorp == '.') { | |
814 | if (num < 4) | |
815 | return -EINVAL; | |
816 | minor = simple_strtoul(minorp+1, NULL, 0); | |
817 | if (minor == 0) | |
818 | return -EINVAL; | |
819 | if (nfsd_minorversion(minor, sign == '-' ? | |
820 | NFSD_CLEAR : NFSD_SET) < 0) | |
821 | return -EINVAL; | |
822 | goto next; | |
823 | } | |
70c3b76c N |
824 | switch(num) { |
825 | case 2: | |
826 | case 3: | |
827 | case 4: | |
6658d3a7 | 828 | nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET); |
70c3b76c N |
829 | break; |
830 | default: | |
831 | return -EINVAL; | |
832 | } | |
8daf220a | 833 | next: |
70c3b76c | 834 | vers += len + 1; |
70c3b76c N |
835 | } while ((len = qword_get(&mesg, vers, size)) > 0); |
836 | /* If all get turned off, turn them back on, as | |
837 | * having no versions is BAD | |
838 | */ | |
6658d3a7 | 839 | nfsd_reset_versions(); |
70c3b76c | 840 | } |
261758b5 | 841 | |
70c3b76c N |
842 | /* Now write current state into reply buffer */ |
843 | len = 0; | |
844 | sep = ""; | |
261758b5 | 845 | remaining = SIMPLE_TRANSACTION_LIMIT; |
70c3b76c | 846 | for (num=2 ; num <= 4 ; num++) |
6658d3a7 | 847 | if (nfsd_vers(num, NFSD_AVAIL)) { |
261758b5 | 848 | len = snprintf(buf, remaining, "%s%c%d", sep, |
6658d3a7 | 849 | nfsd_vers(num, NFSD_TEST)?'+':'-', |
70c3b76c N |
850 | num); |
851 | sep = " "; | |
261758b5 CL |
852 | |
853 | if (len > remaining) | |
854 | break; | |
855 | remaining -= len; | |
856 | buf += len; | |
857 | tlen += len; | |
70c3b76c | 858 | } |
8daf220a | 859 | if (nfsd_vers(4, NFSD_AVAIL)) |
261758b5 CL |
860 | for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION; |
861 | minor++) { | |
862 | len = snprintf(buf, remaining, " %c4.%u", | |
8daf220a BH |
863 | (nfsd_vers(4, NFSD_TEST) && |
864 | nfsd_minorversion(minor, NFSD_TEST)) ? | |
865 | '+' : '-', | |
866 | minor); | |
261758b5 CL |
867 | |
868 | if (len > remaining) | |
869 | break; | |
870 | remaining -= len; | |
871 | buf += len; | |
872 | tlen += len; | |
873 | } | |
874 | ||
875 | len = snprintf(buf, remaining, "\n"); | |
876 | if (len > remaining) | |
877 | return -EINVAL; | |
878 | return tlen + len; | |
70c3b76c N |
879 | } |
880 | ||
262a0982 CL |
881 | /** |
882 | * write_versions - Set or report the available NFS protocol versions | |
883 | * | |
884 | * Input: | |
885 | * buf: ignored | |
886 | * size: zero | |
887 | * Output: | |
888 | * On success: passed-in buffer filled with '\n'-terminated C | |
889 | * string containing positive or negative integer | |
890 | * values representing the current status of each | |
891 | * protocol version; | |
892 | * return code is the size in bytes of the string | |
893 | * On error: return code is zero or a negative errno value | |
894 | * | |
895 | * OR | |
896 | * | |
897 | * Input: | |
898 | * buf: C string containing whitespace- | |
899 | * separated positive or negative | |
900 | * integer values representing NFS | |
901 | * protocol versions to enable ("+n") | |
902 | * or disable ("-n") | |
903 | * size: non-zero length of C string in @buf | |
904 | * Output: | |
905 | * On success: status of zero or more protocol versions has | |
906 | * been updated; passed-in buffer filled with | |
907 | * '\n'-terminated C string containing positive | |
908 | * or negative integer values representing the | |
909 | * current status of each protocol version; | |
910 | * return code is the size in bytes of the string | |
911 | * On error: return code is zero or a negative errno value | |
912 | */ | |
3dd98a3b JL |
913 | static ssize_t write_versions(struct file *file, char *buf, size_t size) |
914 | { | |
915 | ssize_t rv; | |
916 | ||
917 | mutex_lock(&nfsd_mutex); | |
918 | rv = __write_versions(file, buf, size); | |
919 | mutex_unlock(&nfsd_mutex); | |
920 | return rv; | |
921 | } | |
922 | ||
0a5372d8 CL |
923 | /* |
924 | * Zero-length write. Return a list of NFSD's current listener | |
925 | * transports. | |
926 | */ | |
927 | static ssize_t __write_ports_names(char *buf) | |
928 | { | |
929 | if (nfsd_serv == NULL) | |
930 | return 0; | |
335c54bd | 931 | return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); |
0a5372d8 CL |
932 | } |
933 | ||
0b7c2f6f CL |
934 | /* |
935 | * A single 'fd' number was written, in which case it must be for | |
936 | * a socket of a supported family/protocol, and we use it as an | |
937 | * nfsd listener. | |
938 | */ | |
939 | static ssize_t __write_ports_addfd(char *buf) | |
940 | { | |
941 | char *mesg = buf; | |
942 | int fd, err; | |
943 | ||
944 | err = get_int(&mesg, &fd); | |
945 | if (err != 0 || fd < 0) | |
946 | return -EINVAL; | |
947 | ||
948 | err = nfsd_create_serv(); | |
949 | if (err != 0) | |
950 | return err; | |
951 | ||
ea068bad | 952 | err = lockd_up(); |
78a8d7c8 JL |
953 | if (err != 0) { |
954 | svc_destroy(nfsd_serv); | |
955 | return err; | |
956 | } | |
0b7c2f6f | 957 | |
bfba9ab4 | 958 | err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); |
78a8d7c8 | 959 | if (err < 0) { |
ea068bad | 960 | lockd_down(); |
78a8d7c8 JL |
961 | svc_destroy(nfsd_serv); |
962 | return err; | |
963 | } | |
0b7c2f6f | 964 | |
ea068bad CL |
965 | /* Decrease the count, but don't shut down the service */ |
966 | nfsd_serv->sv_nrthreads--; | |
967 | return err; | |
0b7c2f6f CL |
968 | } |
969 | ||
82d56591 CL |
970 | /* |
971 | * A '-' followed by the 'name' of a socket means we close the socket. | |
972 | */ | |
973 | static ssize_t __write_ports_delfd(char *buf) | |
974 | { | |
975 | char *toclose; | |
976 | int len = 0; | |
977 | ||
978 | toclose = kstrdup(buf + 1, GFP_KERNEL); | |
979 | if (toclose == NULL) | |
980 | return -ENOMEM; | |
981 | ||
982 | if (nfsd_serv != NULL) | |
8435d34d CL |
983 | len = svc_sock_names(nfsd_serv, buf, |
984 | SIMPLE_TRANSACTION_LIMIT, toclose); | |
82d56591 CL |
985 | if (len >= 0) |
986 | lockd_down(); | |
987 | ||
988 | kfree(toclose); | |
989 | return len; | |
990 | } | |
991 | ||
4eb68c26 CL |
992 | /* |
993 | * A transport listener is added by writing it's transport name and | |
994 | * a port number. | |
995 | */ | |
996 | static ssize_t __write_ports_addxprt(char *buf) | |
997 | { | |
998 | char transport[16]; | |
37498292 | 999 | struct svc_xprt *xprt; |
4eb68c26 CL |
1000 | int port, err; |
1001 | ||
1002 | if (sscanf(buf, "%15s %4u", transport, &port) != 2) | |
1003 | return -EINVAL; | |
1004 | ||
4be929be | 1005 | if (port < 1 || port > USHRT_MAX) |
4eb68c26 CL |
1006 | return -EINVAL; |
1007 | ||
1008 | err = nfsd_create_serv(); | |
1009 | if (err != 0) | |
1010 | return err; | |
1011 | ||
1012 | err = svc_create_xprt(nfsd_serv, transport, | |
1013 | PF_INET, port, SVC_SOCK_ANONYMOUS); | |
68717908 | 1014 | if (err < 0) |
37498292 CL |
1015 | goto out_err; |
1016 | ||
1017 | err = svc_create_xprt(nfsd_serv, transport, | |
1018 | PF_INET6, port, SVC_SOCK_ANONYMOUS); | |
1019 | if (err < 0 && err != -EAFNOSUPPORT) | |
1020 | goto out_close; | |
4eb68c26 | 1021 | return 0; |
37498292 CL |
1022 | out_close: |
1023 | xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port); | |
1024 | if (xprt != NULL) { | |
1025 | svc_close_xprt(xprt); | |
1026 | svc_xprt_put(xprt); | |
1027 | } | |
1028 | out_err: | |
1029 | /* Decrease the count, but don't shut down the service */ | |
1030 | nfsd_serv->sv_nrthreads--; | |
1031 | return err; | |
4eb68c26 CL |
1032 | } |
1033 | ||
4cd5dc75 CL |
1034 | /* |
1035 | * A transport listener is removed by writing a "-", it's transport | |
1036 | * name, and it's port number. | |
1037 | */ | |
1038 | static ssize_t __write_ports_delxprt(char *buf) | |
1039 | { | |
1040 | struct svc_xprt *xprt; | |
1041 | char transport[16]; | |
1042 | int port; | |
1043 | ||
1044 | if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2) | |
1045 | return -EINVAL; | |
1046 | ||
4be929be | 1047 | if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL) |
4cd5dc75 CL |
1048 | return -EINVAL; |
1049 | ||
1050 | xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port); | |
1051 | if (xprt == NULL) | |
1052 | return -ENOTCONN; | |
1053 | ||
1054 | svc_close_xprt(xprt); | |
1055 | svc_xprt_put(xprt); | |
1056 | return 0; | |
1057 | } | |
1058 | ||
bedbdd8b | 1059 | static ssize_t __write_ports(struct file *file, char *buf, size_t size) |
80212d59 | 1060 | { |
0a5372d8 CL |
1061 | if (size == 0) |
1062 | return __write_ports_names(buf); | |
0b7c2f6f CL |
1063 | |
1064 | if (isdigit(buf[0])) | |
1065 | return __write_ports_addfd(buf); | |
82d56591 CL |
1066 | |
1067 | if (buf[0] == '-' && isdigit(buf[1])) | |
1068 | return __write_ports_delfd(buf); | |
4eb68c26 CL |
1069 | |
1070 | if (isalpha(buf[0])) | |
1071 | return __write_ports_addxprt(buf); | |
4cd5dc75 CL |
1072 | |
1073 | if (buf[0] == '-' && isalpha(buf[1])) | |
1074 | return __write_ports_delxprt(buf); | |
1075 | ||
b41b66d6 | 1076 | return -EINVAL; |
80212d59 N |
1077 | } |
1078 | ||
262a0982 CL |
1079 | /** |
1080 | * write_ports - Pass a socket file descriptor or transport name to listen on | |
1081 | * | |
1082 | * Input: | |
1083 | * buf: ignored | |
1084 | * size: zero | |
1085 | * Output: | |
1086 | * On success: passed-in buffer filled with a '\n'-terminated C | |
1087 | * string containing a whitespace-separated list of | |
1088 | * named NFSD listeners; | |
1089 | * return code is the size in bytes of the string | |
1090 | * On error: return code is zero or a negative errno value | |
1091 | * | |
1092 | * OR | |
1093 | * | |
1094 | * Input: | |
1095 | * buf: C string containing an unsigned | |
1096 | * integer value representing a bound | |
1097 | * but unconnected socket that is to be | |
c71206a7 CL |
1098 | * used as an NFSD listener; listen(3) |
1099 | * must be called for a SOCK_STREAM | |
1100 | * socket, otherwise it is ignored | |
262a0982 CL |
1101 | * size: non-zero length of C string in @buf |
1102 | * Output: | |
1103 | * On success: NFS service is started; | |
1104 | * passed-in buffer filled with a '\n'-terminated C | |
1105 | * string containing a unique alphanumeric name of | |
1106 | * the listener; | |
1107 | * return code is the size in bytes of the string | |
1108 | * On error: return code is a negative errno value | |
1109 | * | |
1110 | * OR | |
1111 | * | |
1112 | * Input: | |
1113 | * buf: C string containing a "-" followed | |
1114 | * by an integer value representing a | |
1115 | * previously passed in socket file | |
1116 | * descriptor | |
1117 | * size: non-zero length of C string in @buf | |
1118 | * Output: | |
1119 | * On success: NFS service no longer listens on that socket; | |
1120 | * passed-in buffer filled with a '\n'-terminated C | |
1121 | * string containing a unique name of the listener; | |
1122 | * return code is the size in bytes of the string | |
1123 | * On error: return code is a negative errno value | |
1124 | * | |
1125 | * OR | |
1126 | * | |
1127 | * Input: | |
1128 | * buf: C string containing a transport | |
1129 | * name and an unsigned integer value | |
1130 | * representing the port to listen on, | |
1131 | * separated by whitespace | |
1132 | * size: non-zero length of C string in @buf | |
1133 | * Output: | |
1134 | * On success: returns zero; NFS service is started | |
1135 | * On error: return code is a negative errno value | |
1136 | * | |
1137 | * OR | |
1138 | * | |
1139 | * Input: | |
1140 | * buf: C string containing a "-" followed | |
1141 | * by a transport name and an unsigned | |
1142 | * integer value representing the port | |
1143 | * to listen on, separated by whitespace | |
1144 | * size: non-zero length of C string in @buf | |
1145 | * Output: | |
1146 | * On success: returns zero; NFS service no longer listens | |
1147 | * on that transport | |
1148 | * On error: return code is a negative errno value | |
1149 | */ | |
bedbdd8b NB |
1150 | static ssize_t write_ports(struct file *file, char *buf, size_t size) |
1151 | { | |
1152 | ssize_t rv; | |
3dd98a3b | 1153 | |
bedbdd8b NB |
1154 | mutex_lock(&nfsd_mutex); |
1155 | rv = __write_ports(file, buf, size); | |
1156 | mutex_unlock(&nfsd_mutex); | |
1157 | return rv; | |
1158 | } | |
1159 | ||
1160 | ||
596bbe53 N |
1161 | int nfsd_max_blksize; |
1162 | ||
262a0982 CL |
1163 | /** |
1164 | * write_maxblksize - Set or report the current NFS blksize | |
1165 | * | |
1166 | * Input: | |
1167 | * buf: ignored | |
1168 | * size: zero | |
1169 | * | |
1170 | * OR | |
1171 | * | |
1172 | * Input: | |
1173 | * buf: C string containing an unsigned | |
1174 | * integer value representing the new | |
1175 | * NFS blksize | |
1176 | * size: non-zero length of C string in @buf | |
1177 | * Output: | |
1178 | * On success: passed-in buffer filled with '\n'-terminated C string | |
1179 | * containing numeric value of the current NFS blksize | |
1180 | * setting; | |
1181 | * return code is the size in bytes of the string | |
1182 | * On error: return code is zero or a negative errno value | |
1183 | */ | |
596bbe53 N |
1184 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) |
1185 | { | |
1186 | char *mesg = buf; | |
1187 | if (size > 0) { | |
1188 | int bsize; | |
1189 | int rv = get_int(&mesg, &bsize); | |
1190 | if (rv) | |
1191 | return rv; | |
1192 | /* force bsize into allowed range and | |
1193 | * required alignment. | |
1194 | */ | |
1195 | if (bsize < 1024) | |
1196 | bsize = 1024; | |
1197 | if (bsize > NFSSVC_MAXBLKSIZE) | |
1198 | bsize = NFSSVC_MAXBLKSIZE; | |
1199 | bsize &= ~(1024-1); | |
bedbdd8b | 1200 | mutex_lock(&nfsd_mutex); |
596bbe53 | 1201 | if (nfsd_serv && nfsd_serv->sv_nrthreads) { |
bedbdd8b | 1202 | mutex_unlock(&nfsd_mutex); |
596bbe53 N |
1203 | return -EBUSY; |
1204 | } | |
1205 | nfsd_max_blksize = bsize; | |
bedbdd8b | 1206 | mutex_unlock(&nfsd_mutex); |
596bbe53 | 1207 | } |
e06b6405 CL |
1208 | |
1209 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", | |
1210 | nfsd_max_blksize); | |
596bbe53 N |
1211 | } |
1212 | ||
70c3b76c | 1213 | #ifdef CONFIG_NFSD_V4 |
f0135740 | 1214 | static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) |
1da177e4 | 1215 | { |
1da177e4 | 1216 | char *mesg = buf; |
f0135740 | 1217 | int rv, i; |
1da177e4 LT |
1218 | |
1219 | if (size > 0) { | |
3dd98a3b JL |
1220 | if (nfsd_serv) |
1221 | return -EBUSY; | |
f0135740 | 1222 | rv = get_int(&mesg, &i); |
1da177e4 LT |
1223 | if (rv) |
1224 | return rv; | |
e7b184f1 BF |
1225 | /* |
1226 | * Some sanity checking. We don't have a reason for | |
1227 | * these particular numbers, but problems with the | |
1228 | * extremes are: | |
1229 | * - Too short: the briefest network outage may | |
1230 | * cause clients to lose all their locks. Also, | |
1231 | * the frequent polling may be wasteful. | |
1232 | * - Too long: do you really want reboot recovery | |
1233 | * to take more than an hour? Or to make other | |
1234 | * clients wait an hour before being able to | |
1235 | * revoke a dead client's locks? | |
1236 | */ | |
f0135740 | 1237 | if (i < 10 || i > 3600) |
1da177e4 | 1238 | return -EINVAL; |
f0135740 | 1239 | *time = i; |
1da177e4 | 1240 | } |
e06b6405 | 1241 | |
f0135740 BF |
1242 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time); |
1243 | } | |
1244 | ||
1245 | static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) | |
1246 | { | |
1247 | ssize_t rv; | |
1248 | ||
1249 | mutex_lock(&nfsd_mutex); | |
1250 | rv = __nfsd4_write_time(file, buf, size, time); | |
1251 | mutex_unlock(&nfsd_mutex); | |
1252 | return rv; | |
1da177e4 LT |
1253 | } |
1254 | ||
262a0982 CL |
1255 | /** |
1256 | * write_leasetime - Set or report the current NFSv4 lease time | |
1257 | * | |
1258 | * Input: | |
1259 | * buf: ignored | |
1260 | * size: zero | |
1261 | * | |
1262 | * OR | |
1263 | * | |
1264 | * Input: | |
1265 | * buf: C string containing an unsigned | |
1266 | * integer value representing the new | |
1267 | * NFSv4 lease expiry time | |
1268 | * size: non-zero length of C string in @buf | |
1269 | * Output: | |
1270 | * On success: passed-in buffer filled with '\n'-terminated C | |
1271 | * string containing unsigned integer value of the | |
1272 | * current lease expiry time; | |
1273 | * return code is the size in bytes of the string | |
1274 | * On error: return code is zero or a negative errno value | |
1275 | */ | |
3dd98a3b JL |
1276 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size) |
1277 | { | |
f0135740 | 1278 | return nfsd4_write_time(file, buf, size, &nfsd4_lease); |
3dd98a3b JL |
1279 | } |
1280 | ||
efc4bb4f BF |
1281 | /** |
1282 | * write_gracetime - Set or report current NFSv4 grace period time | |
1283 | * | |
1284 | * As above, but sets the time of the NFSv4 grace period. | |
1285 | * | |
1286 | * Note this should never be set to less than the *previous* | |
1287 | * lease-period time, but we don't try to enforce this. (In the common | |
1288 | * case (a new boot), we don't know what the previous lease time was | |
1289 | * anyway.) | |
1290 | */ | |
1291 | static ssize_t write_gracetime(struct file *file, char *buf, size_t size) | |
1292 | { | |
1293 | return nfsd4_write_time(file, buf, size, &nfsd4_grace); | |
1294 | } | |
1295 | ||
3dd98a3b JL |
1296 | extern char *nfs4_recoverydir(void); |
1297 | ||
1298 | static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size) | |
0964a3d3 N |
1299 | { |
1300 | char *mesg = buf; | |
1301 | char *recdir; | |
1302 | int len, status; | |
1303 | ||
3dd98a3b JL |
1304 | if (size > 0) { |
1305 | if (nfsd_serv) | |
1306 | return -EBUSY; | |
1307 | if (size > PATH_MAX || buf[size-1] != '\n') | |
1308 | return -EINVAL; | |
1309 | buf[size-1] = 0; | |
0964a3d3 | 1310 | |
3dd98a3b JL |
1311 | recdir = mesg; |
1312 | len = qword_get(&mesg, recdir, size); | |
1313 | if (len <= 0) | |
1314 | return -EINVAL; | |
0964a3d3 | 1315 | |
3dd98a3b JL |
1316 | status = nfs4_reset_recoverydir(recdir); |
1317 | } | |
3d72ab8f CL |
1318 | |
1319 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", | |
1320 | nfs4_recoverydir()); | |
0964a3d3 | 1321 | } |
3dd98a3b | 1322 | |
262a0982 CL |
1323 | /** |
1324 | * write_recoverydir - Set or report the pathname of the recovery directory | |
1325 | * | |
1326 | * Input: | |
1327 | * buf: ignored | |
1328 | * size: zero | |
1329 | * | |
1330 | * OR | |
1331 | * | |
1332 | * Input: | |
1333 | * buf: C string containing the pathname | |
1334 | * of the directory on a local file | |
1335 | * system containing permanent NFSv4 | |
1336 | * recovery data | |
1337 | * size: non-zero length of C string in @buf | |
1338 | * Output: | |
1339 | * On success: passed-in buffer filled with '\n'-terminated C string | |
1340 | * containing the current recovery pathname setting; | |
1341 | * return code is the size in bytes of the string | |
1342 | * On error: return code is zero or a negative errno value | |
1343 | */ | |
3dd98a3b JL |
1344 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) |
1345 | { | |
1346 | ssize_t rv; | |
1347 | ||
1348 | mutex_lock(&nfsd_mutex); | |
1349 | rv = __write_recoverydir(file, buf, size); | |
1350 | mutex_unlock(&nfsd_mutex); | |
1351 | return rv; | |
1352 | } | |
1353 | ||
70c3b76c | 1354 | #endif |
0964a3d3 | 1355 | |
1da177e4 LT |
1356 | /*----------------------------------------------------------------------------*/ |
1357 | /* | |
1358 | * populating the filesystem. | |
1359 | */ | |
1360 | ||
1361 | static int nfsd_fill_super(struct super_block * sb, void * data, int silent) | |
1362 | { | |
1363 | static struct tree_descr nfsd_files[] = { | |
1364 | [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR}, | |
1365 | [NFSD_Add] = {".add", &transaction_ops, S_IWUSR}, | |
1366 | [NFSD_Del] = {".del", &transaction_ops, S_IWUSR}, | |
1367 | [NFSD_Export] = {".export", &transaction_ops, S_IWUSR}, | |
1368 | [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR}, | |
1369 | [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR}, | |
1370 | [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR}, | |
1371 | [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, | |
e8e8753f BF |
1372 | [NFSD_Export_features] = {"export_features", |
1373 | &export_features_operations, S_IRUGO}, | |
4373ea84 WC |
1374 | [NFSD_FO_UnlockIP] = {"unlock_ip", |
1375 | &transaction_ops, S_IWUSR|S_IRUSR}, | |
17efa372 WC |
1376 | [NFSD_FO_UnlockFS] = {"unlock_filesystem", |
1377 | &transaction_ops, S_IWUSR|S_IRUSR}, | |
1da177e4 LT |
1378 | [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, |
1379 | [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, | |
eed2965a | 1380 | [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, |
03cf6c9f | 1381 | [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, |
70c3b76c | 1382 | [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, |
80212d59 | 1383 | [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, |
596bbe53 | 1384 | [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, |
1da177e4 LT |
1385 | #ifdef CONFIG_NFSD_V4 |
1386 | [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, | |
efc4bb4f | 1387 | [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR}, |
0964a3d3 | 1388 | [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, |
1da177e4 LT |
1389 | #endif |
1390 | /* last one */ {""} | |
1391 | }; | |
1392 | return simple_fill_super(sb, 0x6e667364, nfsd_files); | |
1393 | } | |
1394 | ||
454e2398 DH |
1395 | static int nfsd_get_sb(struct file_system_type *fs_type, |
1396 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) | |
1da177e4 | 1397 | { |
454e2398 | 1398 | return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt); |
1da177e4 LT |
1399 | } |
1400 | ||
1401 | static struct file_system_type nfsd_fs_type = { | |
1402 | .owner = THIS_MODULE, | |
1403 | .name = "nfsd", | |
1404 | .get_sb = nfsd_get_sb, | |
1405 | .kill_sb = kill_litter_super, | |
1406 | }; | |
1407 | ||
e331f606 BF |
1408 | #ifdef CONFIG_PROC_FS |
1409 | static int create_proc_exports_entry(void) | |
1410 | { | |
1411 | struct proc_dir_entry *entry; | |
1412 | ||
1413 | entry = proc_mkdir("fs/nfs", NULL); | |
1414 | if (!entry) | |
1415 | return -ENOMEM; | |
9ef2db26 | 1416 | entry = proc_create("exports", 0, entry, &exports_operations); |
e331f606 BF |
1417 | if (!entry) |
1418 | return -ENOMEM; | |
e331f606 BF |
1419 | return 0; |
1420 | } | |
1421 | #else /* CONFIG_PROC_FS */ | |
1422 | static int create_proc_exports_entry(void) | |
1423 | { | |
1424 | return 0; | |
1425 | } | |
1426 | #endif | |
1427 | ||
1da177e4 LT |
1428 | static int __init init_nfsd(void) |
1429 | { | |
1430 | int retval; | |
1431 | printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); | |
1432 | ||
e8ff2a84 BF |
1433 | retval = nfs4_state_init(); /* nfs4 locking state */ |
1434 | if (retval) | |
1435 | return retval; | |
1da177e4 | 1436 | nfsd_stat_init(); /* Statistics */ |
d5c3428b BF |
1437 | retval = nfsd_reply_cache_init(); |
1438 | if (retval) | |
1439 | goto out_free_stat; | |
dbf847ec BF |
1440 | retval = nfsd_export_init(); |
1441 | if (retval) | |
1442 | goto out_free_cache; | |
1da177e4 | 1443 | nfsd_lockd_init(); /* lockd->nfsd callbacks */ |
dbf847ec BF |
1444 | retval = nfsd_idmap_init(); |
1445 | if (retval) | |
1446 | goto out_free_lockd; | |
e331f606 BF |
1447 | retval = create_proc_exports_entry(); |
1448 | if (retval) | |
1449 | goto out_free_idmap; | |
1da177e4 | 1450 | retval = register_filesystem(&nfsd_fs_type); |
26808d3f BF |
1451 | if (retval) |
1452 | goto out_free_all; | |
1453 | return 0; | |
1454 | out_free_all: | |
26808d3f BF |
1455 | remove_proc_entry("fs/nfs/exports", NULL); |
1456 | remove_proc_entry("fs/nfs", NULL); | |
e331f606 | 1457 | out_free_idmap: |
dbf847ec BF |
1458 | nfsd_idmap_shutdown(); |
1459 | out_free_lockd: | |
26808d3f | 1460 | nfsd_lockd_shutdown(); |
e331f606 | 1461 | nfsd_export_shutdown(); |
dbf847ec | 1462 | out_free_cache: |
e331f606 | 1463 | nfsd_reply_cache_shutdown(); |
d5c3428b BF |
1464 | out_free_stat: |
1465 | nfsd_stat_shutdown(); | |
26808d3f | 1466 | nfsd4_free_slabs(); |
1da177e4 LT |
1467 | return retval; |
1468 | } | |
1469 | ||
1470 | static void __exit exit_nfsd(void) | |
1471 | { | |
1472 | nfsd_export_shutdown(); | |
d5c3428b | 1473 | nfsd_reply_cache_shutdown(); |
1da177e4 LT |
1474 | remove_proc_entry("fs/nfs/exports", NULL); |
1475 | remove_proc_entry("fs/nfs", NULL); | |
1476 | nfsd_stat_shutdown(); | |
1477 | nfsd_lockd_shutdown(); | |
1da177e4 | 1478 | nfsd_idmap_shutdown(); |
e8ff2a84 | 1479 | nfsd4_free_slabs(); |
1da177e4 LT |
1480 | unregister_filesystem(&nfsd_fs_type); |
1481 | } | |
1482 | ||
1483 | MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); | |
1484 | MODULE_LICENSE("GPL"); | |
1485 | module_init(init_nfsd) | |
1486 | module_exit(exit_nfsd) |