]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Syscall interface to knfsd. |
3 | * | |
4 | * Copyright (C) 1995, 1996 Olaf Kirch <[email protected]> | |
5 | */ | |
6 | ||
5a0e3ad6 | 7 | #include <linux/slab.h> |
3f8206d4 | 8 | #include <linux/namei.h> |
b41b66d6 | 9 | #include <linux/ctype.h> |
1da177e4 | 10 | |
80212d59 | 11 | #include <linux/sunrpc/svcsock.h> |
4373ea84 | 12 | #include <linux/lockd/lockd.h> |
4116092b | 13 | #include <linux/sunrpc/clnt.h> |
b0b0c0a2 | 14 | #include <linux/sunrpc/gss_api.h> |
b084f598 | 15 | #include <linux/sunrpc/gss_krb5_enctypes.h> |
1da177e4 | 16 | |
2ca72e17 | 17 | #include "idmap.h" |
9a74af21 BH |
18 | #include "nfsd.h" |
19 | #include "cache.h" | |
20 | ||
1da177e4 | 21 | /* |
b0b0c0a2 | 22 | * We have a single directory with several nodes in it. |
1da177e4 LT |
23 | */ |
24 | enum { | |
25 | NFSD_Root = 1, | |
1da177e4 | 26 | NFSD_List, |
e8e8753f | 27 | NFSD_Export_features, |
1da177e4 | 28 | NFSD_Fh, |
4373ea84 | 29 | NFSD_FO_UnlockIP, |
17efa372 | 30 | NFSD_FO_UnlockFS, |
1da177e4 | 31 | NFSD_Threads, |
eed2965a | 32 | NFSD_Pool_Threads, |
03cf6c9f | 33 | NFSD_Pool_Stats, |
70c3b76c | 34 | NFSD_Versions, |
80212d59 | 35 | NFSD_Ports, |
596bbe53 | 36 | NFSD_MaxBlkSize, |
b0b0c0a2 | 37 | NFSD_SupportedEnctypes, |
70c3b76c N |
38 | /* |
39 | * The below MUST come last. Otherwise we leave a hole in nfsd_files[] | |
40 | * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops | |
41 | */ | |
42 | #ifdef CONFIG_NFSD_V4 | |
1da177e4 | 43 | NFSD_Leasetime, |
efc4bb4f | 44 | NFSD_Gracetime, |
0964a3d3 | 45 | NFSD_RecoveryDir, |
70c3b76c | 46 | #endif |
1da177e4 LT |
47 | }; |
48 | ||
49 | /* | |
50 | * write() for these nodes. | |
51 | */ | |
1da177e4 | 52 | static ssize_t write_filehandle(struct file *file, char *buf, size_t size); |
b046ccdc CL |
53 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); |
54 | static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size); | |
1da177e4 | 55 | static ssize_t write_threads(struct file *file, char *buf, size_t size); |
eed2965a | 56 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); |
70c3b76c | 57 | static ssize_t write_versions(struct file *file, char *buf, size_t size); |
80212d59 | 58 | static ssize_t write_ports(struct file *file, char *buf, size_t size); |
596bbe53 | 59 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); |
70c3b76c | 60 | #ifdef CONFIG_NFSD_V4 |
1da177e4 | 61 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size); |
efc4bb4f | 62 | static ssize_t write_gracetime(struct file *file, char *buf, size_t size); |
0964a3d3 | 63 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); |
70c3b76c | 64 | #endif |
1da177e4 LT |
65 | |
66 | static ssize_t (*write_op[])(struct file *, char *, size_t) = { | |
1da177e4 | 67 | [NFSD_Fh] = write_filehandle, |
b046ccdc CL |
68 | [NFSD_FO_UnlockIP] = write_unlock_ip, |
69 | [NFSD_FO_UnlockFS] = write_unlock_fs, | |
1da177e4 | 70 | [NFSD_Threads] = write_threads, |
eed2965a | 71 | [NFSD_Pool_Threads] = write_pool_threads, |
70c3b76c | 72 | [NFSD_Versions] = write_versions, |
80212d59 | 73 | [NFSD_Ports] = write_ports, |
596bbe53 | 74 | [NFSD_MaxBlkSize] = write_maxblksize, |
70c3b76c | 75 | #ifdef CONFIG_NFSD_V4 |
1da177e4 | 76 | [NFSD_Leasetime] = write_leasetime, |
efc4bb4f | 77 | [NFSD_Gracetime] = write_gracetime, |
0964a3d3 | 78 | [NFSD_RecoveryDir] = write_recoverydir, |
70c3b76c | 79 | #endif |
1da177e4 LT |
80 | }; |
81 | ||
82 | static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) | |
83 | { | |
7eaa36e2 | 84 | ino_t ino = file->f_path.dentry->d_inode->i_ino; |
1da177e4 LT |
85 | char *data; |
86 | ssize_t rv; | |
87 | ||
e8c96f8c | 88 | if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) |
1da177e4 LT |
89 | return -EINVAL; |
90 | ||
91 | data = simple_transaction_get(file, buf, size); | |
92 | if (IS_ERR(data)) | |
93 | return PTR_ERR(data); | |
94 | ||
95 | rv = write_op[ino](file, data, size); | |
8971a101 | 96 | if (rv >= 0) { |
1da177e4 LT |
97 | simple_transaction_set(file, rv); |
98 | rv = size; | |
99 | } | |
100 | return rv; | |
101 | } | |
102 | ||
7390022d N |
103 | static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) |
104 | { | |
105 | if (! file->private_data) { | |
106 | /* An attempt to read a transaction file without writing | |
107 | * causes a 0-byte write so that the file can return | |
108 | * state information | |
109 | */ | |
110 | ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); | |
111 | if (rv < 0) | |
112 | return rv; | |
113 | } | |
114 | return simple_transaction_read(file, buf, size, pos); | |
115 | } | |
116 | ||
4b6f5d20 | 117 | static const struct file_operations transaction_ops = { |
1da177e4 | 118 | .write = nfsctl_transaction_write, |
7390022d | 119 | .read = nfsctl_transaction_read, |
1da177e4 | 120 | .release = simple_transaction_release, |
6038f373 | 121 | .llseek = default_llseek, |
1da177e4 LT |
122 | }; |
123 | ||
1da177e4 LT |
124 | static int exports_open(struct inode *inode, struct file *file) |
125 | { | |
126 | return seq_open(file, &nfs_exports_op); | |
127 | } | |
128 | ||
4b6f5d20 | 129 | static const struct file_operations exports_operations = { |
1da177e4 LT |
130 | .open = exports_open, |
131 | .read = seq_read, | |
132 | .llseek = seq_lseek, | |
133 | .release = seq_release, | |
9ef2db26 | 134 | .owner = THIS_MODULE, |
1da177e4 LT |
135 | }; |
136 | ||
e8e8753f BF |
137 | static int export_features_show(struct seq_file *m, void *v) |
138 | { | |
139 | seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS); | |
140 | return 0; | |
141 | } | |
142 | ||
143 | static int export_features_open(struct inode *inode, struct file *file) | |
144 | { | |
145 | return single_open(file, export_features_show, NULL); | |
146 | } | |
147 | ||
148 | static struct file_operations export_features_operations = { | |
149 | .open = export_features_open, | |
150 | .read = seq_read, | |
151 | .llseek = seq_lseek, | |
152 | .release = single_release, | |
153 | }; | |
154 | ||
b084f598 | 155 | #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) |
b0b0c0a2 KC |
156 | static int supported_enctypes_show(struct seq_file *m, void *v) |
157 | { | |
b084f598 | 158 | seq_printf(m, KRB5_SUPPORTED_ENCTYPES); |
b0b0c0a2 KC |
159 | return 0; |
160 | } | |
161 | ||
162 | static int supported_enctypes_open(struct inode *inode, struct file *file) | |
163 | { | |
164 | return single_open(file, supported_enctypes_show, NULL); | |
165 | } | |
166 | ||
167 | static struct file_operations supported_enctypes_ops = { | |
168 | .open = supported_enctypes_open, | |
169 | .read = seq_read, | |
170 | .llseek = seq_lseek, | |
171 | .release = single_release, | |
172 | }; | |
b084f598 | 173 | #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ |
b0b0c0a2 | 174 | |
03cf6c9f | 175 | extern int nfsd_pool_stats_open(struct inode *inode, struct file *file); |
ed2d8aed | 176 | extern int nfsd_pool_stats_release(struct inode *inode, struct file *file); |
03cf6c9f | 177 | |
828c0950 | 178 | static const struct file_operations pool_stats_operations = { |
03cf6c9f GB |
179 | .open = nfsd_pool_stats_open, |
180 | .read = seq_read, | |
181 | .llseek = seq_lseek, | |
ed2d8aed | 182 | .release = nfsd_pool_stats_release, |
03cf6c9f GB |
183 | .owner = THIS_MODULE, |
184 | }; | |
185 | ||
1da177e4 LT |
186 | /*----------------------------------------------------------------------------*/ |
187 | /* | |
188 | * payload - write methods | |
1da177e4 LT |
189 | */ |
190 | ||
1da177e4 | 191 | |
262a0982 CL |
192 | /** |
193 | * write_unlock_ip - Release all locks used by a client | |
194 | * | |
195 | * Experimental. | |
196 | * | |
197 | * Input: | |
198 | * buf: '\n'-terminated C string containing a | |
4116092b | 199 | * presentation format IP address |
262a0982 CL |
200 | * size: length of C string in @buf |
201 | * Output: | |
202 | * On success: returns zero if all specified locks were released; | |
203 | * returns one if one or more locks were not released | |
204 | * On error: return code is negative errno value | |
262a0982 | 205 | */ |
b046ccdc | 206 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) |
4373ea84 | 207 | { |
4116092b CL |
208 | struct sockaddr_storage address; |
209 | struct sockaddr *sap = (struct sockaddr *)&address; | |
210 | size_t salen = sizeof(address); | |
367c8c7b | 211 | char *fo_path; |
4373ea84 WC |
212 | |
213 | /* sanity check */ | |
214 | if (size == 0) | |
215 | return -EINVAL; | |
216 | ||
217 | if (buf[size-1] != '\n') | |
218 | return -EINVAL; | |
219 | ||
220 | fo_path = buf; | |
221 | if (qword_get(&buf, fo_path, size) < 0) | |
222 | return -EINVAL; | |
223 | ||
4116092b | 224 | if (rpc_pton(fo_path, size, sap, salen) == 0) |
4373ea84 | 225 | return -EINVAL; |
4373ea84 | 226 | |
4116092b | 227 | return nlmsvc_unlock_all_by_ip(sap); |
4373ea84 WC |
228 | } |
229 | ||
262a0982 CL |
230 | /** |
231 | * write_unlock_fs - Release all locks on a local file system | |
232 | * | |
233 | * Experimental. | |
234 | * | |
235 | * Input: | |
236 | * buf: '\n'-terminated C string containing the | |
237 | * absolute pathname of a local file system | |
238 | * size: length of C string in @buf | |
239 | * Output: | |
240 | * On success: returns zero if all specified locks were released; | |
241 | * returns one if one or more locks were not released | |
242 | * On error: return code is negative errno value | |
243 | */ | |
b046ccdc | 244 | static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) |
17efa372 | 245 | { |
a63bb996 | 246 | struct path path; |
17efa372 WC |
247 | char *fo_path; |
248 | int error; | |
249 | ||
250 | /* sanity check */ | |
251 | if (size == 0) | |
252 | return -EINVAL; | |
253 | ||
254 | if (buf[size-1] != '\n') | |
255 | return -EINVAL; | |
256 | ||
257 | fo_path = buf; | |
258 | if (qword_get(&buf, fo_path, size) < 0) | |
259 | return -EINVAL; | |
260 | ||
a63bb996 | 261 | error = kern_path(fo_path, 0, &path); |
17efa372 WC |
262 | if (error) |
263 | return error; | |
264 | ||
262a0982 CL |
265 | /* |
266 | * XXX: Needs better sanity checking. Otherwise we could end up | |
267 | * releasing locks on the wrong file system. | |
268 | * | |
269 | * For example: | |
270 | * 1. Does the path refer to a directory? | |
271 | * 2. Is that directory a mount point, or | |
272 | * 3. Is that directory the root of an exported file system? | |
273 | */ | |
a63bb996 | 274 | error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb); |
17efa372 | 275 | |
a63bb996 | 276 | path_put(&path); |
17efa372 WC |
277 | return error; |
278 | } | |
279 | ||
262a0982 CL |
280 | /** |
281 | * write_filehandle - Get a variable-length NFS file handle by path | |
282 | * | |
283 | * On input, the buffer contains a '\n'-terminated C string comprised of | |
284 | * three alphanumeric words separated by whitespace. The string may | |
285 | * contain escape sequences. | |
286 | * | |
287 | * Input: | |
288 | * buf: | |
289 | * domain: client domain name | |
290 | * path: export pathname | |
291 | * maxsize: numeric maximum size of | |
292 | * @buf | |
293 | * size: length of C string in @buf | |
294 | * Output: | |
295 | * On success: passed-in buffer filled with '\n'-terminated C | |
296 | * string containing a ASCII hex text version | |
297 | * of the NFS file handle; | |
298 | * return code is the size in bytes of the string | |
299 | * On error: return code is negative errno value | |
300 | */ | |
1da177e4 LT |
301 | static ssize_t write_filehandle(struct file *file, char *buf, size_t size) |
302 | { | |
1da177e4 | 303 | char *dname, *path; |
246d95ba | 304 | int uninitialized_var(maxsize); |
1da177e4 LT |
305 | char *mesg = buf; |
306 | int len; | |
307 | struct auth_domain *dom; | |
308 | struct knfsd_fh fh; | |
309 | ||
87d26ea7 BF |
310 | if (size == 0) |
311 | return -EINVAL; | |
312 | ||
1da177e4 LT |
313 | if (buf[size-1] != '\n') |
314 | return -EINVAL; | |
315 | buf[size-1] = 0; | |
316 | ||
317 | dname = mesg; | |
318 | len = qword_get(&mesg, dname, size); | |
54224f04 CL |
319 | if (len <= 0) |
320 | return -EINVAL; | |
1da177e4 LT |
321 | |
322 | path = dname+len+1; | |
323 | len = qword_get(&mesg, path, size); | |
54224f04 CL |
324 | if (len <= 0) |
325 | return -EINVAL; | |
1da177e4 LT |
326 | |
327 | len = get_int(&mesg, &maxsize); | |
328 | if (len) | |
329 | return len; | |
330 | ||
331 | if (maxsize < NFS_FHSIZE) | |
332 | return -EINVAL; | |
333 | if (maxsize > NFS3_FHSIZE) | |
334 | maxsize = NFS3_FHSIZE; | |
335 | ||
336 | if (qword_get(&mesg, mesg, size)>0) | |
337 | return -EINVAL; | |
338 | ||
339 | /* we have all the words, they are in buf.. */ | |
340 | dom = unix_domain_find(dname); | |
341 | if (!dom) | |
342 | return -ENOMEM; | |
343 | ||
344 | len = exp_rootfh(dom, path, &fh, maxsize); | |
345 | auth_domain_put(dom); | |
346 | if (len) | |
347 | return len; | |
348 | ||
54224f04 CL |
349 | mesg = buf; |
350 | len = SIMPLE_TRANSACTION_LIMIT; | |
1da177e4 LT |
351 | qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); |
352 | mesg[-1] = '\n'; | |
353 | return mesg - buf; | |
354 | } | |
355 | ||
262a0982 CL |
356 | /** |
357 | * write_threads - Start NFSD, or report the current number of running threads | |
358 | * | |
359 | * Input: | |
360 | * buf: ignored | |
361 | * size: zero | |
362 | * Output: | |
363 | * On success: passed-in buffer filled with '\n'-terminated C | |
364 | * string numeric value representing the number of | |
365 | * running NFSD threads; | |
366 | * return code is the size in bytes of the string | |
367 | * On error: return code is zero | |
368 | * | |
369 | * OR | |
370 | * | |
371 | * Input: | |
372 | * buf: C string containing an unsigned | |
373 | * integer value representing the | |
374 | * number of NFSD threads to start | |
375 | * size: non-zero length of C string in @buf | |
376 | * Output: | |
377 | * On success: NFS service is started; | |
378 | * passed-in buffer filled with '\n'-terminated C | |
379 | * string numeric value representing the number of | |
380 | * running NFSD threads; | |
381 | * return code is the size in bytes of the string | |
382 | * On error: return code is zero or a negative errno value | |
383 | */ | |
1da177e4 LT |
384 | static ssize_t write_threads(struct file *file, char *buf, size_t size) |
385 | { | |
1da177e4 LT |
386 | char *mesg = buf; |
387 | int rv; | |
388 | if (size > 0) { | |
389 | int newthreads; | |
390 | rv = get_int(&mesg, &newthreads); | |
391 | if (rv) | |
392 | return rv; | |
9e074856 | 393 | if (newthreads < 0) |
1da177e4 | 394 | return -EINVAL; |
9e074856 | 395 | rv = nfsd_svc(NFS_PORT, newthreads); |
82e12fe9 | 396 | if (rv < 0) |
1da177e4 | 397 | return rv; |
82e12fe9 N |
398 | } else |
399 | rv = nfsd_nrthreads(); | |
e06b6405 | 400 | |
82e12fe9 | 401 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); |
1da177e4 LT |
402 | } |
403 | ||
262a0982 CL |
404 | /** |
405 | * write_pool_threads - Set or report the current number of threads per pool | |
406 | * | |
407 | * Input: | |
408 | * buf: ignored | |
409 | * size: zero | |
410 | * | |
411 | * OR | |
412 | * | |
413 | * Input: | |
414 | * buf: C string containing whitespace- | |
415 | * separated unsigned integer values | |
416 | * representing the number of NFSD | |
417 | * threads to start in each pool | |
418 | * size: non-zero length of C string in @buf | |
419 | * Output: | |
420 | * On success: passed-in buffer filled with '\n'-terminated C | |
421 | * string containing integer values representing the | |
422 | * number of NFSD threads in each pool; | |
423 | * return code is the size in bytes of the string | |
424 | * On error: return code is zero or a negative errno value | |
425 | */ | |
eed2965a GB |
426 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) |
427 | { | |
428 | /* if size > 0, look for an array of number of threads per node | |
429 | * and apply them then write out number of threads per node as reply | |
430 | */ | |
431 | char *mesg = buf; | |
432 | int i; | |
433 | int rv; | |
434 | int len; | |
bedbdd8b | 435 | int npools; |
eed2965a GB |
436 | int *nthreads; |
437 | ||
bedbdd8b NB |
438 | mutex_lock(&nfsd_mutex); |
439 | npools = nfsd_nrpools(); | |
eed2965a GB |
440 | if (npools == 0) { |
441 | /* | |
442 | * NFS is shut down. The admin can start it by | |
443 | * writing to the threads file but NOT the pool_threads | |
444 | * file, sorry. Report zero threads. | |
445 | */ | |
bedbdd8b | 446 | mutex_unlock(&nfsd_mutex); |
eed2965a GB |
447 | strcpy(buf, "0\n"); |
448 | return strlen(buf); | |
449 | } | |
450 | ||
451 | nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); | |
bedbdd8b | 452 | rv = -ENOMEM; |
eed2965a | 453 | if (nthreads == NULL) |
bedbdd8b | 454 | goto out_free; |
eed2965a GB |
455 | |
456 | if (size > 0) { | |
457 | for (i = 0; i < npools; i++) { | |
458 | rv = get_int(&mesg, &nthreads[i]); | |
459 | if (rv == -ENOENT) | |
460 | break; /* fewer numbers than pools */ | |
461 | if (rv) | |
462 | goto out_free; /* syntax error */ | |
463 | rv = -EINVAL; | |
464 | if (nthreads[i] < 0) | |
465 | goto out_free; | |
466 | } | |
467 | rv = nfsd_set_nrthreads(i, nthreads); | |
468 | if (rv) | |
469 | goto out_free; | |
470 | } | |
471 | ||
472 | rv = nfsd_get_nrthreads(npools, nthreads); | |
473 | if (rv) | |
474 | goto out_free; | |
475 | ||
476 | mesg = buf; | |
477 | size = SIMPLE_TRANSACTION_LIMIT; | |
478 | for (i = 0; i < npools && size > 0; i++) { | |
479 | snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); | |
480 | len = strlen(mesg); | |
481 | size -= len; | |
482 | mesg += len; | |
483 | } | |
413d63d7 | 484 | rv = mesg - buf; |
eed2965a GB |
485 | out_free: |
486 | kfree(nthreads); | |
bedbdd8b | 487 | mutex_unlock(&nfsd_mutex); |
eed2965a GB |
488 | return rv; |
489 | } | |
490 | ||
3dd98a3b | 491 | static ssize_t __write_versions(struct file *file, char *buf, size_t size) |
70c3b76c | 492 | { |
70c3b76c | 493 | char *mesg = buf; |
8daf220a | 494 | char *vers, *minorp, sign; |
261758b5 | 495 | int len, num, remaining; |
8daf220a | 496 | unsigned minor; |
70c3b76c N |
497 | ssize_t tlen = 0; |
498 | char *sep; | |
499 | ||
500 | if (size>0) { | |
501 | if (nfsd_serv) | |
6658d3a7 N |
502 | /* Cannot change versions without updating |
503 | * nfsd_serv->sv_xdrsize, and reallocing | |
504 | * rq_argp and rq_resp | |
505 | */ | |
70c3b76c N |
506 | return -EBUSY; |
507 | if (buf[size-1] != '\n') | |
508 | return -EINVAL; | |
509 | buf[size-1] = 0; | |
510 | ||
511 | vers = mesg; | |
512 | len = qword_get(&mesg, vers, size); | |
513 | if (len <= 0) return -EINVAL; | |
514 | do { | |
515 | sign = *vers; | |
516 | if (sign == '+' || sign == '-') | |
8daf220a | 517 | num = simple_strtol((vers+1), &minorp, 0); |
70c3b76c | 518 | else |
8daf220a BH |
519 | num = simple_strtol(vers, &minorp, 0); |
520 | if (*minorp == '.') { | |
521 | if (num < 4) | |
522 | return -EINVAL; | |
523 | minor = simple_strtoul(minorp+1, NULL, 0); | |
524 | if (minor == 0) | |
525 | return -EINVAL; | |
526 | if (nfsd_minorversion(minor, sign == '-' ? | |
527 | NFSD_CLEAR : NFSD_SET) < 0) | |
528 | return -EINVAL; | |
529 | goto next; | |
530 | } | |
70c3b76c N |
531 | switch(num) { |
532 | case 2: | |
533 | case 3: | |
534 | case 4: | |
6658d3a7 | 535 | nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET); |
70c3b76c N |
536 | break; |
537 | default: | |
538 | return -EINVAL; | |
539 | } | |
8daf220a | 540 | next: |
70c3b76c | 541 | vers += len + 1; |
70c3b76c N |
542 | } while ((len = qword_get(&mesg, vers, size)) > 0); |
543 | /* If all get turned off, turn them back on, as | |
544 | * having no versions is BAD | |
545 | */ | |
6658d3a7 | 546 | nfsd_reset_versions(); |
70c3b76c | 547 | } |
261758b5 | 548 | |
70c3b76c N |
549 | /* Now write current state into reply buffer */ |
550 | len = 0; | |
551 | sep = ""; | |
261758b5 | 552 | remaining = SIMPLE_TRANSACTION_LIMIT; |
70c3b76c | 553 | for (num=2 ; num <= 4 ; num++) |
6658d3a7 | 554 | if (nfsd_vers(num, NFSD_AVAIL)) { |
261758b5 | 555 | len = snprintf(buf, remaining, "%s%c%d", sep, |
6658d3a7 | 556 | nfsd_vers(num, NFSD_TEST)?'+':'-', |
70c3b76c N |
557 | num); |
558 | sep = " "; | |
261758b5 CL |
559 | |
560 | if (len > remaining) | |
561 | break; | |
562 | remaining -= len; | |
563 | buf += len; | |
564 | tlen += len; | |
70c3b76c | 565 | } |
8daf220a | 566 | if (nfsd_vers(4, NFSD_AVAIL)) |
261758b5 CL |
567 | for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION; |
568 | minor++) { | |
569 | len = snprintf(buf, remaining, " %c4.%u", | |
8daf220a BH |
570 | (nfsd_vers(4, NFSD_TEST) && |
571 | nfsd_minorversion(minor, NFSD_TEST)) ? | |
572 | '+' : '-', | |
573 | minor); | |
261758b5 CL |
574 | |
575 | if (len > remaining) | |
576 | break; | |
577 | remaining -= len; | |
578 | buf += len; | |
579 | tlen += len; | |
580 | } | |
581 | ||
582 | len = snprintf(buf, remaining, "\n"); | |
583 | if (len > remaining) | |
584 | return -EINVAL; | |
585 | return tlen + len; | |
70c3b76c N |
586 | } |
587 | ||
262a0982 CL |
588 | /** |
589 | * write_versions - Set or report the available NFS protocol versions | |
590 | * | |
591 | * Input: | |
592 | * buf: ignored | |
593 | * size: zero | |
594 | * Output: | |
595 | * On success: passed-in buffer filled with '\n'-terminated C | |
596 | * string containing positive or negative integer | |
597 | * values representing the current status of each | |
598 | * protocol version; | |
599 | * return code is the size in bytes of the string | |
600 | * On error: return code is zero or a negative errno value | |
601 | * | |
602 | * OR | |
603 | * | |
604 | * Input: | |
605 | * buf: C string containing whitespace- | |
606 | * separated positive or negative | |
607 | * integer values representing NFS | |
608 | * protocol versions to enable ("+n") | |
609 | * or disable ("-n") | |
610 | * size: non-zero length of C string in @buf | |
611 | * Output: | |
612 | * On success: status of zero or more protocol versions has | |
613 | * been updated; passed-in buffer filled with | |
614 | * '\n'-terminated C string containing positive | |
615 | * or negative integer values representing the | |
616 | * current status of each protocol version; | |
617 | * return code is the size in bytes of the string | |
618 | * On error: return code is zero or a negative errno value | |
619 | */ | |
3dd98a3b JL |
620 | static ssize_t write_versions(struct file *file, char *buf, size_t size) |
621 | { | |
622 | ssize_t rv; | |
623 | ||
624 | mutex_lock(&nfsd_mutex); | |
625 | rv = __write_versions(file, buf, size); | |
626 | mutex_unlock(&nfsd_mutex); | |
627 | return rv; | |
628 | } | |
629 | ||
0a5372d8 CL |
630 | /* |
631 | * Zero-length write. Return a list of NFSD's current listener | |
632 | * transports. | |
633 | */ | |
634 | static ssize_t __write_ports_names(char *buf) | |
635 | { | |
636 | if (nfsd_serv == NULL) | |
637 | return 0; | |
335c54bd | 638 | return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); |
0a5372d8 CL |
639 | } |
640 | ||
0b7c2f6f CL |
641 | /* |
642 | * A single 'fd' number was written, in which case it must be for | |
643 | * a socket of a supported family/protocol, and we use it as an | |
644 | * nfsd listener. | |
645 | */ | |
646 | static ssize_t __write_ports_addfd(char *buf) | |
647 | { | |
648 | char *mesg = buf; | |
649 | int fd, err; | |
650 | ||
651 | err = get_int(&mesg, &fd); | |
652 | if (err != 0 || fd < 0) | |
653 | return -EINVAL; | |
654 | ||
655 | err = nfsd_create_serv(); | |
656 | if (err != 0) | |
657 | return err; | |
658 | ||
bfba9ab4 | 659 | err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); |
78a8d7c8 | 660 | if (err < 0) { |
78a8d7c8 JL |
661 | svc_destroy(nfsd_serv); |
662 | return err; | |
663 | } | |
0b7c2f6f | 664 | |
ea068bad CL |
665 | /* Decrease the count, but don't shut down the service */ |
666 | nfsd_serv->sv_nrthreads--; | |
667 | return err; | |
0b7c2f6f CL |
668 | } |
669 | ||
82d56591 CL |
670 | /* |
671 | * A '-' followed by the 'name' of a socket means we close the socket. | |
672 | */ | |
673 | static ssize_t __write_ports_delfd(char *buf) | |
674 | { | |
675 | char *toclose; | |
676 | int len = 0; | |
677 | ||
678 | toclose = kstrdup(buf + 1, GFP_KERNEL); | |
679 | if (toclose == NULL) | |
680 | return -ENOMEM; | |
681 | ||
682 | if (nfsd_serv != NULL) | |
8435d34d CL |
683 | len = svc_sock_names(nfsd_serv, buf, |
684 | SIMPLE_TRANSACTION_LIMIT, toclose); | |
82d56591 CL |
685 | kfree(toclose); |
686 | return len; | |
687 | } | |
688 | ||
4eb68c26 CL |
689 | /* |
690 | * A transport listener is added by writing it's transport name and | |
691 | * a port number. | |
692 | */ | |
693 | static ssize_t __write_ports_addxprt(char *buf) | |
694 | { | |
695 | char transport[16]; | |
37498292 | 696 | struct svc_xprt *xprt; |
4eb68c26 CL |
697 | int port, err; |
698 | ||
699 | if (sscanf(buf, "%15s %4u", transport, &port) != 2) | |
700 | return -EINVAL; | |
701 | ||
4be929be | 702 | if (port < 1 || port > USHRT_MAX) |
4eb68c26 CL |
703 | return -EINVAL; |
704 | ||
705 | err = nfsd_create_serv(); | |
706 | if (err != 0) | |
707 | return err; | |
708 | ||
fc5d00b0 | 709 | err = svc_create_xprt(nfsd_serv, transport, &init_net, |
4eb68c26 | 710 | PF_INET, port, SVC_SOCK_ANONYMOUS); |
68717908 | 711 | if (err < 0) |
37498292 CL |
712 | goto out_err; |
713 | ||
fc5d00b0 | 714 | err = svc_create_xprt(nfsd_serv, transport, &init_net, |
37498292 CL |
715 | PF_INET6, port, SVC_SOCK_ANONYMOUS); |
716 | if (err < 0 && err != -EAFNOSUPPORT) | |
717 | goto out_close; | |
0cd14a06 JL |
718 | |
719 | /* Decrease the count, but don't shut down the service */ | |
720 | nfsd_serv->sv_nrthreads--; | |
4eb68c26 | 721 | return 0; |
37498292 CL |
722 | out_close: |
723 | xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port); | |
724 | if (xprt != NULL) { | |
725 | svc_close_xprt(xprt); | |
726 | svc_xprt_put(xprt); | |
727 | } | |
728 | out_err: | |
0cd14a06 | 729 | svc_destroy(nfsd_serv); |
37498292 | 730 | return err; |
4eb68c26 CL |
731 | } |
732 | ||
4cd5dc75 CL |
733 | /* |
734 | * A transport listener is removed by writing a "-", it's transport | |
735 | * name, and it's port number. | |
736 | */ | |
737 | static ssize_t __write_ports_delxprt(char *buf) | |
738 | { | |
739 | struct svc_xprt *xprt; | |
740 | char transport[16]; | |
741 | int port; | |
742 | ||
743 | if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2) | |
744 | return -EINVAL; | |
745 | ||
4be929be | 746 | if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL) |
4cd5dc75 CL |
747 | return -EINVAL; |
748 | ||
749 | xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port); | |
750 | if (xprt == NULL) | |
751 | return -ENOTCONN; | |
752 | ||
753 | svc_close_xprt(xprt); | |
754 | svc_xprt_put(xprt); | |
755 | return 0; | |
756 | } | |
757 | ||
bedbdd8b | 758 | static ssize_t __write_ports(struct file *file, char *buf, size_t size) |
80212d59 | 759 | { |
0a5372d8 CL |
760 | if (size == 0) |
761 | return __write_ports_names(buf); | |
0b7c2f6f CL |
762 | |
763 | if (isdigit(buf[0])) | |
764 | return __write_ports_addfd(buf); | |
82d56591 CL |
765 | |
766 | if (buf[0] == '-' && isdigit(buf[1])) | |
767 | return __write_ports_delfd(buf); | |
4eb68c26 CL |
768 | |
769 | if (isalpha(buf[0])) | |
770 | return __write_ports_addxprt(buf); | |
4cd5dc75 CL |
771 | |
772 | if (buf[0] == '-' && isalpha(buf[1])) | |
773 | return __write_ports_delxprt(buf); | |
774 | ||
b41b66d6 | 775 | return -EINVAL; |
80212d59 N |
776 | } |
777 | ||
262a0982 CL |
778 | /** |
779 | * write_ports - Pass a socket file descriptor or transport name to listen on | |
780 | * | |
781 | * Input: | |
782 | * buf: ignored | |
783 | * size: zero | |
784 | * Output: | |
785 | * On success: passed-in buffer filled with a '\n'-terminated C | |
786 | * string containing a whitespace-separated list of | |
787 | * named NFSD listeners; | |
788 | * return code is the size in bytes of the string | |
789 | * On error: return code is zero or a negative errno value | |
790 | * | |
791 | * OR | |
792 | * | |
793 | * Input: | |
794 | * buf: C string containing an unsigned | |
795 | * integer value representing a bound | |
796 | * but unconnected socket that is to be | |
c71206a7 CL |
797 | * used as an NFSD listener; listen(3) |
798 | * must be called for a SOCK_STREAM | |
799 | * socket, otherwise it is ignored | |
262a0982 CL |
800 | * size: non-zero length of C string in @buf |
801 | * Output: | |
802 | * On success: NFS service is started; | |
803 | * passed-in buffer filled with a '\n'-terminated C | |
804 | * string containing a unique alphanumeric name of | |
805 | * the listener; | |
806 | * return code is the size in bytes of the string | |
807 | * On error: return code is a negative errno value | |
808 | * | |
809 | * OR | |
810 | * | |
811 | * Input: | |
812 | * buf: C string containing a "-" followed | |
813 | * by an integer value representing a | |
814 | * previously passed in socket file | |
815 | * descriptor | |
816 | * size: non-zero length of C string in @buf | |
817 | * Output: | |
818 | * On success: NFS service no longer listens on that socket; | |
819 | * passed-in buffer filled with a '\n'-terminated C | |
820 | * string containing a unique name of the listener; | |
821 | * return code is the size in bytes of the string | |
822 | * On error: return code is a negative errno value | |
823 | * | |
824 | * OR | |
825 | * | |
826 | * Input: | |
827 | * buf: C string containing a transport | |
828 | * name and an unsigned integer value | |
829 | * representing the port to listen on, | |
830 | * separated by whitespace | |
831 | * size: non-zero length of C string in @buf | |
832 | * Output: | |
833 | * On success: returns zero; NFS service is started | |
834 | * On error: return code is a negative errno value | |
835 | * | |
836 | * OR | |
837 | * | |
838 | * Input: | |
839 | * buf: C string containing a "-" followed | |
840 | * by a transport name and an unsigned | |
841 | * integer value representing the port | |
842 | * to listen on, separated by whitespace | |
843 | * size: non-zero length of C string in @buf | |
844 | * Output: | |
845 | * On success: returns zero; NFS service no longer listens | |
846 | * on that transport | |
847 | * On error: return code is a negative errno value | |
848 | */ | |
bedbdd8b NB |
849 | static ssize_t write_ports(struct file *file, char *buf, size_t size) |
850 | { | |
851 | ssize_t rv; | |
3dd98a3b | 852 | |
bedbdd8b NB |
853 | mutex_lock(&nfsd_mutex); |
854 | rv = __write_ports(file, buf, size); | |
855 | mutex_unlock(&nfsd_mutex); | |
856 | return rv; | |
857 | } | |
858 | ||
859 | ||
596bbe53 N |
860 | int nfsd_max_blksize; |
861 | ||
262a0982 CL |
862 | /** |
863 | * write_maxblksize - Set or report the current NFS blksize | |
864 | * | |
865 | * Input: | |
866 | * buf: ignored | |
867 | * size: zero | |
868 | * | |
869 | * OR | |
870 | * | |
871 | * Input: | |
872 | * buf: C string containing an unsigned | |
873 | * integer value representing the new | |
874 | * NFS blksize | |
875 | * size: non-zero length of C string in @buf | |
876 | * Output: | |
877 | * On success: passed-in buffer filled with '\n'-terminated C string | |
878 | * containing numeric value of the current NFS blksize | |
879 | * setting; | |
880 | * return code is the size in bytes of the string | |
881 | * On error: return code is zero or a negative errno value | |
882 | */ | |
596bbe53 N |
883 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) |
884 | { | |
885 | char *mesg = buf; | |
886 | if (size > 0) { | |
887 | int bsize; | |
888 | int rv = get_int(&mesg, &bsize); | |
889 | if (rv) | |
890 | return rv; | |
891 | /* force bsize into allowed range and | |
892 | * required alignment. | |
893 | */ | |
894 | if (bsize < 1024) | |
895 | bsize = 1024; | |
896 | if (bsize > NFSSVC_MAXBLKSIZE) | |
897 | bsize = NFSSVC_MAXBLKSIZE; | |
898 | bsize &= ~(1024-1); | |
bedbdd8b | 899 | mutex_lock(&nfsd_mutex); |
7fa53cc8 | 900 | if (nfsd_serv) { |
bedbdd8b | 901 | mutex_unlock(&nfsd_mutex); |
596bbe53 N |
902 | return -EBUSY; |
903 | } | |
904 | nfsd_max_blksize = bsize; | |
bedbdd8b | 905 | mutex_unlock(&nfsd_mutex); |
596bbe53 | 906 | } |
e06b6405 CL |
907 | |
908 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", | |
909 | nfsd_max_blksize); | |
596bbe53 N |
910 | } |
911 | ||
70c3b76c | 912 | #ifdef CONFIG_NFSD_V4 |
f0135740 | 913 | static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) |
1da177e4 | 914 | { |
1da177e4 | 915 | char *mesg = buf; |
f0135740 | 916 | int rv, i; |
1da177e4 LT |
917 | |
918 | if (size > 0) { | |
3dd98a3b JL |
919 | if (nfsd_serv) |
920 | return -EBUSY; | |
f0135740 | 921 | rv = get_int(&mesg, &i); |
1da177e4 LT |
922 | if (rv) |
923 | return rv; | |
e7b184f1 BF |
924 | /* |
925 | * Some sanity checking. We don't have a reason for | |
926 | * these particular numbers, but problems with the | |
927 | * extremes are: | |
928 | * - Too short: the briefest network outage may | |
929 | * cause clients to lose all their locks. Also, | |
930 | * the frequent polling may be wasteful. | |
931 | * - Too long: do you really want reboot recovery | |
932 | * to take more than an hour? Or to make other | |
933 | * clients wait an hour before being able to | |
934 | * revoke a dead client's locks? | |
935 | */ | |
f0135740 | 936 | if (i < 10 || i > 3600) |
1da177e4 | 937 | return -EINVAL; |
f0135740 | 938 | *time = i; |
1da177e4 | 939 | } |
e06b6405 | 940 | |
f0135740 BF |
941 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time); |
942 | } | |
943 | ||
944 | static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) | |
945 | { | |
946 | ssize_t rv; | |
947 | ||
948 | mutex_lock(&nfsd_mutex); | |
949 | rv = __nfsd4_write_time(file, buf, size, time); | |
950 | mutex_unlock(&nfsd_mutex); | |
951 | return rv; | |
1da177e4 LT |
952 | } |
953 | ||
262a0982 CL |
954 | /** |
955 | * write_leasetime - Set or report the current NFSv4 lease time | |
956 | * | |
957 | * Input: | |
958 | * buf: ignored | |
959 | * size: zero | |
960 | * | |
961 | * OR | |
962 | * | |
963 | * Input: | |
964 | * buf: C string containing an unsigned | |
965 | * integer value representing the new | |
966 | * NFSv4 lease expiry time | |
967 | * size: non-zero length of C string in @buf | |
968 | * Output: | |
969 | * On success: passed-in buffer filled with '\n'-terminated C | |
970 | * string containing unsigned integer value of the | |
971 | * current lease expiry time; | |
972 | * return code is the size in bytes of the string | |
973 | * On error: return code is zero or a negative errno value | |
974 | */ | |
3dd98a3b JL |
975 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size) |
976 | { | |
f0135740 | 977 | return nfsd4_write_time(file, buf, size, &nfsd4_lease); |
3dd98a3b JL |
978 | } |
979 | ||
efc4bb4f BF |
980 | /** |
981 | * write_gracetime - Set or report current NFSv4 grace period time | |
982 | * | |
983 | * As above, but sets the time of the NFSv4 grace period. | |
984 | * | |
985 | * Note this should never be set to less than the *previous* | |
986 | * lease-period time, but we don't try to enforce this. (In the common | |
987 | * case (a new boot), we don't know what the previous lease time was | |
988 | * anyway.) | |
989 | */ | |
990 | static ssize_t write_gracetime(struct file *file, char *buf, size_t size) | |
991 | { | |
992 | return nfsd4_write_time(file, buf, size, &nfsd4_grace); | |
993 | } | |
994 | ||
3dd98a3b JL |
995 | extern char *nfs4_recoverydir(void); |
996 | ||
997 | static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size) | |
0964a3d3 N |
998 | { |
999 | char *mesg = buf; | |
1000 | char *recdir; | |
1001 | int len, status; | |
1002 | ||
3dd98a3b JL |
1003 | if (size > 0) { |
1004 | if (nfsd_serv) | |
1005 | return -EBUSY; | |
1006 | if (size > PATH_MAX || buf[size-1] != '\n') | |
1007 | return -EINVAL; | |
1008 | buf[size-1] = 0; | |
0964a3d3 | 1009 | |
3dd98a3b JL |
1010 | recdir = mesg; |
1011 | len = qword_get(&mesg, recdir, size); | |
1012 | if (len <= 0) | |
1013 | return -EINVAL; | |
0964a3d3 | 1014 | |
3dd98a3b | 1015 | status = nfs4_reset_recoverydir(recdir); |
69049961 AK |
1016 | if (status) |
1017 | return status; | |
3dd98a3b | 1018 | } |
3d72ab8f CL |
1019 | |
1020 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", | |
1021 | nfs4_recoverydir()); | |
0964a3d3 | 1022 | } |
3dd98a3b | 1023 | |
262a0982 CL |
1024 | /** |
1025 | * write_recoverydir - Set or report the pathname of the recovery directory | |
1026 | * | |
1027 | * Input: | |
1028 | * buf: ignored | |
1029 | * size: zero | |
1030 | * | |
1031 | * OR | |
1032 | * | |
1033 | * Input: | |
1034 | * buf: C string containing the pathname | |
1035 | * of the directory on a local file | |
1036 | * system containing permanent NFSv4 | |
1037 | * recovery data | |
1038 | * size: non-zero length of C string in @buf | |
1039 | * Output: | |
1040 | * On success: passed-in buffer filled with '\n'-terminated C string | |
1041 | * containing the current recovery pathname setting; | |
1042 | * return code is the size in bytes of the string | |
1043 | * On error: return code is zero or a negative errno value | |
1044 | */ | |
3dd98a3b JL |
1045 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) |
1046 | { | |
1047 | ssize_t rv; | |
1048 | ||
1049 | mutex_lock(&nfsd_mutex); | |
1050 | rv = __write_recoverydir(file, buf, size); | |
1051 | mutex_unlock(&nfsd_mutex); | |
1052 | return rv; | |
1053 | } | |
1054 | ||
70c3b76c | 1055 | #endif |
0964a3d3 | 1056 | |
1da177e4 LT |
1057 | /*----------------------------------------------------------------------------*/ |
1058 | /* | |
1059 | * populating the filesystem. | |
1060 | */ | |
1061 | ||
1062 | static int nfsd_fill_super(struct super_block * sb, void * data, int silent) | |
1063 | { | |
1064 | static struct tree_descr nfsd_files[] = { | |
1da177e4 | 1065 | [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, |
e8e8753f BF |
1066 | [NFSD_Export_features] = {"export_features", |
1067 | &export_features_operations, S_IRUGO}, | |
4373ea84 WC |
1068 | [NFSD_FO_UnlockIP] = {"unlock_ip", |
1069 | &transaction_ops, S_IWUSR|S_IRUSR}, | |
17efa372 WC |
1070 | [NFSD_FO_UnlockFS] = {"unlock_filesystem", |
1071 | &transaction_ops, S_IWUSR|S_IRUSR}, | |
1da177e4 LT |
1072 | [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, |
1073 | [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, | |
eed2965a | 1074 | [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, |
03cf6c9f | 1075 | [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, |
70c3b76c | 1076 | [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, |
80212d59 | 1077 | [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, |
596bbe53 | 1078 | [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, |
b084f598 | 1079 | #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) |
b0b0c0a2 | 1080 | [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO}, |
b084f598 | 1081 | #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ |
1da177e4 LT |
1082 | #ifdef CONFIG_NFSD_V4 |
1083 | [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, | |
efc4bb4f | 1084 | [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR}, |
0964a3d3 | 1085 | [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, |
1da177e4 LT |
1086 | #endif |
1087 | /* last one */ {""} | |
1088 | }; | |
1089 | return simple_fill_super(sb, 0x6e667364, nfsd_files); | |
1090 | } | |
1091 | ||
fc14f2fe AV |
1092 | static struct dentry *nfsd_mount(struct file_system_type *fs_type, |
1093 | int flags, const char *dev_name, void *data) | |
1da177e4 | 1094 | { |
fc14f2fe | 1095 | return mount_single(fs_type, flags, data, nfsd_fill_super); |
1da177e4 LT |
1096 | } |
1097 | ||
1098 | static struct file_system_type nfsd_fs_type = { | |
1099 | .owner = THIS_MODULE, | |
1100 | .name = "nfsd", | |
fc14f2fe | 1101 | .mount = nfsd_mount, |
1da177e4 LT |
1102 | .kill_sb = kill_litter_super, |
1103 | }; | |
1104 | ||
e331f606 BF |
1105 | #ifdef CONFIG_PROC_FS |
1106 | static int create_proc_exports_entry(void) | |
1107 | { | |
1108 | struct proc_dir_entry *entry; | |
1109 | ||
1110 | entry = proc_mkdir("fs/nfs", NULL); | |
1111 | if (!entry) | |
1112 | return -ENOMEM; | |
9ef2db26 | 1113 | entry = proc_create("exports", 0, entry, &exports_operations); |
e331f606 BF |
1114 | if (!entry) |
1115 | return -ENOMEM; | |
e331f606 BF |
1116 | return 0; |
1117 | } | |
1118 | #else /* CONFIG_PROC_FS */ | |
1119 | static int create_proc_exports_entry(void) | |
1120 | { | |
1121 | return 0; | |
1122 | } | |
1123 | #endif | |
1124 | ||
1da177e4 LT |
1125 | static int __init init_nfsd(void) |
1126 | { | |
1127 | int retval; | |
1128 | printk(KERN_INFO "Installing knfsd (copyright (C) 1996 [email protected]).\n"); | |
1129 | ||
e8ff2a84 BF |
1130 | retval = nfs4_state_init(); /* nfs4 locking state */ |
1131 | if (retval) | |
1132 | return retval; | |
1da177e4 | 1133 | nfsd_stat_init(); /* Statistics */ |
d5c3428b BF |
1134 | retval = nfsd_reply_cache_init(); |
1135 | if (retval) | |
1136 | goto out_free_stat; | |
dbf847ec BF |
1137 | retval = nfsd_export_init(); |
1138 | if (retval) | |
1139 | goto out_free_cache; | |
1da177e4 | 1140 | nfsd_lockd_init(); /* lockd->nfsd callbacks */ |
dbf847ec BF |
1141 | retval = nfsd_idmap_init(); |
1142 | if (retval) | |
1143 | goto out_free_lockd; | |
e331f606 BF |
1144 | retval = create_proc_exports_entry(); |
1145 | if (retval) | |
1146 | goto out_free_idmap; | |
1da177e4 | 1147 | retval = register_filesystem(&nfsd_fs_type); |
26808d3f BF |
1148 | if (retval) |
1149 | goto out_free_all; | |
1150 | return 0; | |
1151 | out_free_all: | |
26808d3f BF |
1152 | remove_proc_entry("fs/nfs/exports", NULL); |
1153 | remove_proc_entry("fs/nfs", NULL); | |
e331f606 | 1154 | out_free_idmap: |
dbf847ec BF |
1155 | nfsd_idmap_shutdown(); |
1156 | out_free_lockd: | |
26808d3f | 1157 | nfsd_lockd_shutdown(); |
e331f606 | 1158 | nfsd_export_shutdown(); |
dbf847ec | 1159 | out_free_cache: |
e331f606 | 1160 | nfsd_reply_cache_shutdown(); |
d5c3428b BF |
1161 | out_free_stat: |
1162 | nfsd_stat_shutdown(); | |
26808d3f | 1163 | nfsd4_free_slabs(); |
1da177e4 LT |
1164 | return retval; |
1165 | } | |
1166 | ||
1167 | static void __exit exit_nfsd(void) | |
1168 | { | |
1169 | nfsd_export_shutdown(); | |
d5c3428b | 1170 | nfsd_reply_cache_shutdown(); |
1da177e4 LT |
1171 | remove_proc_entry("fs/nfs/exports", NULL); |
1172 | remove_proc_entry("fs/nfs", NULL); | |
1173 | nfsd_stat_shutdown(); | |
1174 | nfsd_lockd_shutdown(); | |
1da177e4 | 1175 | nfsd_idmap_shutdown(); |
e8ff2a84 | 1176 | nfsd4_free_slabs(); |
1da177e4 LT |
1177 | unregister_filesystem(&nfsd_fs_type); |
1178 | } | |
1179 | ||
1180 | MODULE_AUTHOR("Olaf Kirch <[email protected]>"); | |
1181 | MODULE_LICENSE("GPL"); | |
1182 | module_init(init_nfsd) | |
1183 | module_exit(exit_nfsd) |