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