Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / fs / nfsd / nfsproc.c
blob9473d048efec8fd4363b8f46b63a1443ec9b73ca
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Process version 2 NFS requests.
5 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
6 */
8 #include <linux/namei.h>
10 #include "cache.h"
11 #include "xdr.h"
12 #include "vfs.h"
14 #define NFSDDBG_FACILITY NFSDDBG_PROC
16 static __be32
17 nfsd_proc_null(struct svc_rqst *rqstp)
19 return rpc_success;
23 * Get a file's attributes
24 * N.B. After this call resp->fh needs an fh_put
26 static __be32
27 nfsd_proc_getattr(struct svc_rqst *rqstp)
29 struct nfsd_fhandle *argp = rqstp->rq_argp;
30 struct nfsd_attrstat *resp = rqstp->rq_resp;
32 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
34 fh_copy(&resp->fh, &argp->fh);
35 resp->status = fh_verify(rqstp, &resp->fh, 0,
36 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
37 if (resp->status != nfs_ok)
38 goto out;
39 resp->status = fh_getattr(&resp->fh, &resp->stat);
40 out:
41 return rpc_success;
45 * Set a file's attributes
46 * N.B. After this call resp->fh needs an fh_put
48 static __be32
49 nfsd_proc_setattr(struct svc_rqst *rqstp)
51 struct nfsd_sattrargs *argp = rqstp->rq_argp;
52 struct nfsd_attrstat *resp = rqstp->rq_resp;
53 struct iattr *iap = &argp->attrs;
54 struct svc_fh *fhp;
56 dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
57 SVCFH_fmt(&argp->fh),
58 argp->attrs.ia_valid, (long) argp->attrs.ia_size);
60 fhp = fh_copy(&resp->fh, &argp->fh);
63 * NFSv2 does not differentiate between "set-[ac]time-to-now"
64 * which only requires access, and "set-[ac]time-to-X" which
65 * requires ownership.
66 * So if it looks like it might be "set both to the same time which
67 * is close to now", and if setattr_prepare fails, then we
68 * convert to "set to now" instead of "set to explicit time"
70 * We only call setattr_prepare as the last test as technically
71 * it is not an interface that we should be using.
73 #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
74 #define MAX_TOUCH_TIME_ERROR (30*60)
75 if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
76 iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
78 * Looks probable.
80 * Now just make sure time is in the right ballpark.
81 * Solaris, at least, doesn't seem to care what the time
82 * request is. We require it be within 30 minutes of now.
84 time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds();
86 resp->status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
87 if (resp->status != nfs_ok)
88 goto out;
90 if (delta < 0)
91 delta = -delta;
92 if (delta < MAX_TOUCH_TIME_ERROR &&
93 setattr_prepare(fhp->fh_dentry, iap) != 0) {
95 * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
96 * This will cause notify_change to set these times
97 * to "now"
99 iap->ia_valid &= ~BOTH_TIME_SET;
103 resp->status = nfsd_setattr(rqstp, fhp, iap, 0, (time64_t)0);
104 if (resp->status != nfs_ok)
105 goto out;
107 resp->status = fh_getattr(&resp->fh, &resp->stat);
108 out:
109 return rpc_success;
112 /* Obsolete, replaced by MNTPROC_MNT. */
113 static __be32
114 nfsd_proc_root(struct svc_rqst *rqstp)
116 return rpc_success;
120 * Look up a path name component
121 * Note: the dentry in the resp->fh may be negative if the file
122 * doesn't exist yet.
123 * N.B. After this call resp->fh needs an fh_put
125 static __be32
126 nfsd_proc_lookup(struct svc_rqst *rqstp)
128 struct nfsd_diropargs *argp = rqstp->rq_argp;
129 struct nfsd_diropres *resp = rqstp->rq_resp;
131 dprintk("nfsd: LOOKUP %s %.*s\n",
132 SVCFH_fmt(&argp->fh), argp->len, argp->name);
134 fh_init(&resp->fh, NFS_FHSIZE);
135 resp->status = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
136 &resp->fh);
137 fh_put(&argp->fh);
138 if (resp->status != nfs_ok)
139 goto out;
141 resp->status = fh_getattr(&resp->fh, &resp->stat);
142 out:
143 return rpc_success;
147 * Read a symlink.
149 static __be32
150 nfsd_proc_readlink(struct svc_rqst *rqstp)
152 struct nfsd_readlinkargs *argp = rqstp->rq_argp;
153 struct nfsd_readlinkres *resp = rqstp->rq_resp;
155 dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
157 /* Read the symlink. */
158 resp->len = NFS_MAXPATHLEN;
159 resp->status = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
161 fh_put(&argp->fh);
162 return rpc_success;
166 * Read a portion of a file.
167 * N.B. After this call resp->fh needs an fh_put
169 static __be32
170 nfsd_proc_read(struct svc_rqst *rqstp)
172 struct nfsd_readargs *argp = rqstp->rq_argp;
173 struct nfsd_readres *resp = rqstp->rq_resp;
174 u32 eof;
176 dprintk("nfsd: READ %s %d bytes at %d\n",
177 SVCFH_fmt(&argp->fh),
178 argp->count, argp->offset);
180 /* Obtain buffer pointer for payload. 19 is 1 word for
181 * status, 17 words for fattr, and 1 word for the byte count.
184 if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
185 char buf[RPC_MAX_ADDRBUFLEN];
186 printk(KERN_NOTICE
187 "oversized read request from %s (%d bytes)\n",
188 svc_print_addr(rqstp, buf, sizeof(buf)),
189 argp->count);
190 argp->count = NFSSVC_MAXBLKSIZE_V2;
192 svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
194 resp->count = argp->count;
195 resp->status = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
196 argp->offset,
197 rqstp->rq_vec, argp->vlen,
198 &resp->count,
199 &eof);
200 if (resp->status == nfs_ok)
201 resp->status = fh_getattr(&resp->fh, &resp->stat);
202 else if (resp->status == nfserr_jukebox)
203 return rpc_drop_reply;
204 return rpc_success;
207 /* Reserved */
208 static __be32
209 nfsd_proc_writecache(struct svc_rqst *rqstp)
211 return rpc_success;
215 * Write data to a file
216 * N.B. After this call resp->fh needs an fh_put
218 static __be32
219 nfsd_proc_write(struct svc_rqst *rqstp)
221 struct nfsd_writeargs *argp = rqstp->rq_argp;
222 struct nfsd_attrstat *resp = rqstp->rq_resp;
223 unsigned long cnt = argp->len;
224 unsigned int nvecs;
226 dprintk("nfsd: WRITE %s %d bytes at %d\n",
227 SVCFH_fmt(&argp->fh),
228 argp->len, argp->offset);
230 nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
231 &argp->first, cnt);
232 if (!nvecs) {
233 resp->status = nfserr_io;
234 goto out;
237 resp->status = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh),
238 argp->offset, rqstp->rq_vec, nvecs,
239 &cnt, NFS_DATA_SYNC, NULL);
240 if (resp->status == nfs_ok)
241 resp->status = fh_getattr(&resp->fh, &resp->stat);
242 else if (resp->status == nfserr_jukebox)
243 return rpc_drop_reply;
244 out:
245 return rpc_success;
249 * CREATE processing is complicated. The keyword here is `overloaded.'
250 * The parent directory is kept locked between the check for existence
251 * and the actual create() call in compliance with VFS protocols.
252 * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
254 static __be32
255 nfsd_proc_create(struct svc_rqst *rqstp)
257 struct nfsd_createargs *argp = rqstp->rq_argp;
258 struct nfsd_diropres *resp = rqstp->rq_resp;
259 svc_fh *dirfhp = &argp->fh;
260 svc_fh *newfhp = &resp->fh;
261 struct iattr *attr = &argp->attrs;
262 struct inode *inode;
263 struct dentry *dchild;
264 int type, mode;
265 int hosterr;
266 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
268 dprintk("nfsd: CREATE %s %.*s\n",
269 SVCFH_fmt(dirfhp), argp->len, argp->name);
271 /* First verify the parent file handle */
272 resp->status = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
273 if (resp->status != nfs_ok)
274 goto done; /* must fh_put dirfhp even on error */
276 /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
278 resp->status = nfserr_exist;
279 if (isdotent(argp->name, argp->len))
280 goto done;
281 hosterr = fh_want_write(dirfhp);
282 if (hosterr) {
283 resp->status = nfserrno(hosterr);
284 goto done;
287 fh_lock_nested(dirfhp, I_MUTEX_PARENT);
288 dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
289 if (IS_ERR(dchild)) {
290 resp->status = nfserrno(PTR_ERR(dchild));
291 goto out_unlock;
293 fh_init(newfhp, NFS_FHSIZE);
294 resp->status = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
295 if (!resp->status && d_really_is_negative(dchild))
296 resp->status = nfserr_noent;
297 dput(dchild);
298 if (resp->status) {
299 if (resp->status != nfserr_noent)
300 goto out_unlock;
302 * If the new file handle wasn't verified, we can't tell
303 * whether the file exists or not. Time to bail ...
305 resp->status = nfserr_acces;
306 if (!newfhp->fh_dentry) {
307 printk(KERN_WARNING
308 "nfsd_proc_create: file handle not verified\n");
309 goto out_unlock;
313 inode = d_inode(newfhp->fh_dentry);
315 /* Unfudge the mode bits */
316 if (attr->ia_valid & ATTR_MODE) {
317 type = attr->ia_mode & S_IFMT;
318 mode = attr->ia_mode & ~S_IFMT;
319 if (!type) {
320 /* no type, so if target exists, assume same as that,
321 * else assume a file */
322 if (inode) {
323 type = inode->i_mode & S_IFMT;
324 switch(type) {
325 case S_IFCHR:
326 case S_IFBLK:
327 /* reserve rdev for later checking */
328 rdev = inode->i_rdev;
329 attr->ia_valid |= ATTR_SIZE;
331 fallthrough;
332 case S_IFIFO:
333 /* this is probably a permission check..
334 * at least IRIX implements perm checking on
335 * echo thing > device-special-file-or-pipe
336 * by doing a CREATE with type==0
338 resp->status = nfsd_permission(rqstp,
339 newfhp->fh_export,
340 newfhp->fh_dentry,
341 NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
342 if (resp->status && resp->status != nfserr_rofs)
343 goto out_unlock;
345 } else
346 type = S_IFREG;
348 } else if (inode) {
349 type = inode->i_mode & S_IFMT;
350 mode = inode->i_mode & ~S_IFMT;
351 } else {
352 type = S_IFREG;
353 mode = 0; /* ??? */
356 attr->ia_valid |= ATTR_MODE;
357 attr->ia_mode = mode;
359 /* Special treatment for non-regular files according to the
360 * gospel of sun micro
362 if (type != S_IFREG) {
363 if (type != S_IFBLK && type != S_IFCHR) {
364 rdev = 0;
365 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
366 /* If you think you've seen the worst, grok this. */
367 type = S_IFIFO;
368 } else {
369 /* Okay, char or block special */
370 if (!rdev)
371 rdev = wanted;
374 /* we've used the SIZE information, so discard it */
375 attr->ia_valid &= ~ATTR_SIZE;
377 /* Make sure the type and device matches */
378 resp->status = nfserr_exist;
379 if (inode && type != (inode->i_mode & S_IFMT))
380 goto out_unlock;
383 resp->status = nfs_ok;
384 if (!inode) {
385 /* File doesn't exist. Create it and set attrs */
386 resp->status = nfsd_create_locked(rqstp, dirfhp, argp->name,
387 argp->len, attr, type, rdev,
388 newfhp);
389 } else if (type == S_IFREG) {
390 dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
391 argp->name, attr->ia_valid, (long) attr->ia_size);
392 /* File already exists. We ignore all attributes except
393 * size, so that creat() behaves exactly like
394 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
396 attr->ia_valid &= ATTR_SIZE;
397 if (attr->ia_valid)
398 resp->status = nfsd_setattr(rqstp, newfhp, attr, 0,
399 (time64_t)0);
402 out_unlock:
403 /* We don't really need to unlock, as fh_put does it. */
404 fh_unlock(dirfhp);
405 fh_drop_write(dirfhp);
406 done:
407 fh_put(dirfhp);
408 if (resp->status != nfs_ok)
409 goto out;
410 resp->status = fh_getattr(&resp->fh, &resp->stat);
411 out:
412 return rpc_success;
415 static __be32
416 nfsd_proc_remove(struct svc_rqst *rqstp)
418 struct nfsd_diropargs *argp = rqstp->rq_argp;
419 struct nfsd_stat *resp = rqstp->rq_resp;
421 dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
422 argp->len, argp->name);
424 /* Unlink. -SIFDIR means file must not be a directory */
425 resp->status = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR,
426 argp->name, argp->len);
427 fh_put(&argp->fh);
428 return rpc_success;
431 static __be32
432 nfsd_proc_rename(struct svc_rqst *rqstp)
434 struct nfsd_renameargs *argp = rqstp->rq_argp;
435 struct nfsd_stat *resp = rqstp->rq_resp;
437 dprintk("nfsd: RENAME %s %.*s -> \n",
438 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
439 dprintk("nfsd: -> %s %.*s\n",
440 SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
442 resp->status = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
443 &argp->tfh, argp->tname, argp->tlen);
444 fh_put(&argp->ffh);
445 fh_put(&argp->tfh);
446 return rpc_success;
449 static __be32
450 nfsd_proc_link(struct svc_rqst *rqstp)
452 struct nfsd_linkargs *argp = rqstp->rq_argp;
453 struct nfsd_stat *resp = rqstp->rq_resp;
455 dprintk("nfsd: LINK %s ->\n",
456 SVCFH_fmt(&argp->ffh));
457 dprintk("nfsd: %s %.*s\n",
458 SVCFH_fmt(&argp->tfh),
459 argp->tlen,
460 argp->tname);
462 resp->status = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
463 &argp->ffh);
464 fh_put(&argp->ffh);
465 fh_put(&argp->tfh);
466 return rpc_success;
469 static __be32
470 nfsd_proc_symlink(struct svc_rqst *rqstp)
472 struct nfsd_symlinkargs *argp = rqstp->rq_argp;
473 struct nfsd_stat *resp = rqstp->rq_resp;
474 struct svc_fh newfh;
476 if (argp->tlen > NFS_MAXPATHLEN) {
477 resp->status = nfserr_nametoolong;
478 goto out;
481 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
482 page_address(rqstp->rq_arg.pages[0]),
483 argp->tlen);
484 if (IS_ERR(argp->tname)) {
485 resp->status = nfserrno(PTR_ERR(argp->tname));
486 goto out;
489 dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
490 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
491 argp->tlen, argp->tname);
493 fh_init(&newfh, NFS_FHSIZE);
494 resp->status = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
495 argp->tname, &newfh);
497 kfree(argp->tname);
498 fh_put(&argp->ffh);
499 fh_put(&newfh);
500 out:
501 return rpc_success;
505 * Make directory. This operation is not idempotent.
506 * N.B. After this call resp->fh needs an fh_put
508 static __be32
509 nfsd_proc_mkdir(struct svc_rqst *rqstp)
511 struct nfsd_createargs *argp = rqstp->rq_argp;
512 struct nfsd_diropres *resp = rqstp->rq_resp;
514 dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
516 if (resp->fh.fh_dentry) {
517 printk(KERN_WARNING
518 "nfsd_proc_mkdir: response already verified??\n");
521 argp->attrs.ia_valid &= ~ATTR_SIZE;
522 fh_init(&resp->fh, NFS_FHSIZE);
523 resp->status = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
524 &argp->attrs, S_IFDIR, 0, &resp->fh);
525 fh_put(&argp->fh);
526 if (resp->status != nfs_ok)
527 goto out;
529 resp->status = fh_getattr(&resp->fh, &resp->stat);
530 out:
531 return rpc_success;
535 * Remove a directory
537 static __be32
538 nfsd_proc_rmdir(struct svc_rqst *rqstp)
540 struct nfsd_diropargs *argp = rqstp->rq_argp;
541 struct nfsd_stat *resp = rqstp->rq_resp;
543 dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
545 resp->status = nfsd_unlink(rqstp, &argp->fh, S_IFDIR,
546 argp->name, argp->len);
547 fh_put(&argp->fh);
548 return rpc_success;
552 * Read a portion of a directory.
554 static __be32
555 nfsd_proc_readdir(struct svc_rqst *rqstp)
557 struct nfsd_readdirargs *argp = rqstp->rq_argp;
558 struct nfsd_readdirres *resp = rqstp->rq_resp;
559 int count;
560 loff_t offset;
562 dprintk("nfsd: READDIR %s %d bytes at %d\n",
563 SVCFH_fmt(&argp->fh),
564 argp->count, argp->cookie);
566 /* Shrink to the client read size */
567 count = (argp->count >> 2) - 2;
569 /* Make sure we've room for the NULL ptr & eof flag */
570 count -= 2;
571 if (count < 0)
572 count = 0;
574 resp->buffer = argp->buffer;
575 resp->offset = NULL;
576 resp->buflen = count;
577 resp->common.err = nfs_ok;
578 /* Read directory and encode entries on the fly */
579 offset = argp->cookie;
580 resp->status = nfsd_readdir(rqstp, &argp->fh, &offset,
581 &resp->common, nfssvc_encode_entry);
583 resp->count = resp->buffer - argp->buffer;
584 if (resp->offset)
585 *resp->offset = htonl(offset);
587 fh_put(&argp->fh);
588 return rpc_success;
592 * Get file system info
594 static __be32
595 nfsd_proc_statfs(struct svc_rqst *rqstp)
597 struct nfsd_fhandle *argp = rqstp->rq_argp;
598 struct nfsd_statfsres *resp = rqstp->rq_resp;
600 dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
602 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
603 NFSD_MAY_BYPASS_GSS_ON_ROOT);
604 fh_put(&argp->fh);
605 return rpc_success;
609 * NFSv2 Server procedures.
610 * Only the results of non-idempotent operations are cached.
613 #define ST 1 /* status */
614 #define FH 8 /* filehandle */
615 #define AT 18 /* attributes */
617 static const struct svc_procedure nfsd_procedures2[18] = {
618 [NFSPROC_NULL] = {
619 .pc_func = nfsd_proc_null,
620 .pc_decode = nfssvc_decode_voidarg,
621 .pc_encode = nfssvc_encode_voidres,
622 .pc_argsize = sizeof(struct nfsd_voidargs),
623 .pc_ressize = sizeof(struct nfsd_voidres),
624 .pc_cachetype = RC_NOCACHE,
625 .pc_xdrressize = 0,
627 [NFSPROC_GETATTR] = {
628 .pc_func = nfsd_proc_getattr,
629 .pc_decode = nfssvc_decode_fhandle,
630 .pc_encode = nfssvc_encode_attrstat,
631 .pc_release = nfssvc_release_attrstat,
632 .pc_argsize = sizeof(struct nfsd_fhandle),
633 .pc_ressize = sizeof(struct nfsd_attrstat),
634 .pc_cachetype = RC_NOCACHE,
635 .pc_xdrressize = ST+AT,
637 [NFSPROC_SETATTR] = {
638 .pc_func = nfsd_proc_setattr,
639 .pc_decode = nfssvc_decode_sattrargs,
640 .pc_encode = nfssvc_encode_attrstat,
641 .pc_release = nfssvc_release_attrstat,
642 .pc_argsize = sizeof(struct nfsd_sattrargs),
643 .pc_ressize = sizeof(struct nfsd_attrstat),
644 .pc_cachetype = RC_REPLBUFF,
645 .pc_xdrressize = ST+AT,
647 [NFSPROC_ROOT] = {
648 .pc_func = nfsd_proc_root,
649 .pc_decode = nfssvc_decode_voidarg,
650 .pc_encode = nfssvc_encode_voidres,
651 .pc_argsize = sizeof(struct nfsd_voidargs),
652 .pc_ressize = sizeof(struct nfsd_voidres),
653 .pc_cachetype = RC_NOCACHE,
654 .pc_xdrressize = 0,
656 [NFSPROC_LOOKUP] = {
657 .pc_func = nfsd_proc_lookup,
658 .pc_decode = nfssvc_decode_diropargs,
659 .pc_encode = nfssvc_encode_diropres,
660 .pc_release = nfssvc_release_diropres,
661 .pc_argsize = sizeof(struct nfsd_diropargs),
662 .pc_ressize = sizeof(struct nfsd_diropres),
663 .pc_cachetype = RC_NOCACHE,
664 .pc_xdrressize = ST+FH+AT,
666 [NFSPROC_READLINK] = {
667 .pc_func = nfsd_proc_readlink,
668 .pc_decode = nfssvc_decode_readlinkargs,
669 .pc_encode = nfssvc_encode_readlinkres,
670 .pc_argsize = sizeof(struct nfsd_readlinkargs),
671 .pc_ressize = sizeof(struct nfsd_readlinkres),
672 .pc_cachetype = RC_NOCACHE,
673 .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
675 [NFSPROC_READ] = {
676 .pc_func = nfsd_proc_read,
677 .pc_decode = nfssvc_decode_readargs,
678 .pc_encode = nfssvc_encode_readres,
679 .pc_release = nfssvc_release_readres,
680 .pc_argsize = sizeof(struct nfsd_readargs),
681 .pc_ressize = sizeof(struct nfsd_readres),
682 .pc_cachetype = RC_NOCACHE,
683 .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
685 [NFSPROC_WRITECACHE] = {
686 .pc_func = nfsd_proc_writecache,
687 .pc_decode = nfssvc_decode_voidarg,
688 .pc_encode = nfssvc_encode_voidres,
689 .pc_argsize = sizeof(struct nfsd_voidargs),
690 .pc_ressize = sizeof(struct nfsd_voidres),
691 .pc_cachetype = RC_NOCACHE,
692 .pc_xdrressize = 0,
694 [NFSPROC_WRITE] = {
695 .pc_func = nfsd_proc_write,
696 .pc_decode = nfssvc_decode_writeargs,
697 .pc_encode = nfssvc_encode_attrstat,
698 .pc_release = nfssvc_release_attrstat,
699 .pc_argsize = sizeof(struct nfsd_writeargs),
700 .pc_ressize = sizeof(struct nfsd_attrstat),
701 .pc_cachetype = RC_REPLBUFF,
702 .pc_xdrressize = ST+AT,
704 [NFSPROC_CREATE] = {
705 .pc_func = nfsd_proc_create,
706 .pc_decode = nfssvc_decode_createargs,
707 .pc_encode = nfssvc_encode_diropres,
708 .pc_release = nfssvc_release_diropres,
709 .pc_argsize = sizeof(struct nfsd_createargs),
710 .pc_ressize = sizeof(struct nfsd_diropres),
711 .pc_cachetype = RC_REPLBUFF,
712 .pc_xdrressize = ST+FH+AT,
714 [NFSPROC_REMOVE] = {
715 .pc_func = nfsd_proc_remove,
716 .pc_decode = nfssvc_decode_diropargs,
717 .pc_encode = nfssvc_encode_stat,
718 .pc_argsize = sizeof(struct nfsd_diropargs),
719 .pc_ressize = sizeof(struct nfsd_stat),
720 .pc_cachetype = RC_REPLSTAT,
721 .pc_xdrressize = ST,
723 [NFSPROC_RENAME] = {
724 .pc_func = nfsd_proc_rename,
725 .pc_decode = nfssvc_decode_renameargs,
726 .pc_encode = nfssvc_encode_stat,
727 .pc_argsize = sizeof(struct nfsd_renameargs),
728 .pc_ressize = sizeof(struct nfsd_stat),
729 .pc_cachetype = RC_REPLSTAT,
730 .pc_xdrressize = ST,
732 [NFSPROC_LINK] = {
733 .pc_func = nfsd_proc_link,
734 .pc_decode = nfssvc_decode_linkargs,
735 .pc_encode = nfssvc_encode_stat,
736 .pc_argsize = sizeof(struct nfsd_linkargs),
737 .pc_ressize = sizeof(struct nfsd_stat),
738 .pc_cachetype = RC_REPLSTAT,
739 .pc_xdrressize = ST,
741 [NFSPROC_SYMLINK] = {
742 .pc_func = nfsd_proc_symlink,
743 .pc_decode = nfssvc_decode_symlinkargs,
744 .pc_encode = nfssvc_encode_stat,
745 .pc_argsize = sizeof(struct nfsd_symlinkargs),
746 .pc_ressize = sizeof(struct nfsd_stat),
747 .pc_cachetype = RC_REPLSTAT,
748 .pc_xdrressize = ST,
750 [NFSPROC_MKDIR] = {
751 .pc_func = nfsd_proc_mkdir,
752 .pc_decode = nfssvc_decode_createargs,
753 .pc_encode = nfssvc_encode_diropres,
754 .pc_release = nfssvc_release_diropres,
755 .pc_argsize = sizeof(struct nfsd_createargs),
756 .pc_ressize = sizeof(struct nfsd_diropres),
757 .pc_cachetype = RC_REPLBUFF,
758 .pc_xdrressize = ST+FH+AT,
760 [NFSPROC_RMDIR] = {
761 .pc_func = nfsd_proc_rmdir,
762 .pc_decode = nfssvc_decode_diropargs,
763 .pc_encode = nfssvc_encode_stat,
764 .pc_argsize = sizeof(struct nfsd_diropargs),
765 .pc_ressize = sizeof(struct nfsd_stat),
766 .pc_cachetype = RC_REPLSTAT,
767 .pc_xdrressize = ST,
769 [NFSPROC_READDIR] = {
770 .pc_func = nfsd_proc_readdir,
771 .pc_decode = nfssvc_decode_readdirargs,
772 .pc_encode = nfssvc_encode_readdirres,
773 .pc_argsize = sizeof(struct nfsd_readdirargs),
774 .pc_ressize = sizeof(struct nfsd_readdirres),
775 .pc_cachetype = RC_NOCACHE,
777 [NFSPROC_STATFS] = {
778 .pc_func = nfsd_proc_statfs,
779 .pc_decode = nfssvc_decode_fhandle,
780 .pc_encode = nfssvc_encode_statfsres,
781 .pc_argsize = sizeof(struct nfsd_fhandle),
782 .pc_ressize = sizeof(struct nfsd_statfsres),
783 .pc_cachetype = RC_NOCACHE,
784 .pc_xdrressize = ST+5,
789 static unsigned int nfsd_count2[ARRAY_SIZE(nfsd_procedures2)];
790 const struct svc_version nfsd_version2 = {
791 .vs_vers = 2,
792 .vs_nproc = 18,
793 .vs_proc = nfsd_procedures2,
794 .vs_count = nfsd_count2,
795 .vs_dispatch = nfsd_dispatch,
796 .vs_xdrsize = NFS2_SVC_XDRSIZE,
800 * Map errnos to NFS errnos.
802 __be32
803 nfserrno (int errno)
805 static struct {
806 __be32 nfserr;
807 int syserr;
808 } nfs_errtbl[] = {
809 { nfs_ok, 0 },
810 { nfserr_perm, -EPERM },
811 { nfserr_noent, -ENOENT },
812 { nfserr_io, -EIO },
813 { nfserr_nxio, -ENXIO },
814 { nfserr_fbig, -E2BIG },
815 { nfserr_acces, -EACCES },
816 { nfserr_exist, -EEXIST },
817 { nfserr_xdev, -EXDEV },
818 { nfserr_mlink, -EMLINK },
819 { nfserr_nodev, -ENODEV },
820 { nfserr_notdir, -ENOTDIR },
821 { nfserr_isdir, -EISDIR },
822 { nfserr_inval, -EINVAL },
823 { nfserr_fbig, -EFBIG },
824 { nfserr_nospc, -ENOSPC },
825 { nfserr_rofs, -EROFS },
826 { nfserr_mlink, -EMLINK },
827 { nfserr_nametoolong, -ENAMETOOLONG },
828 { nfserr_notempty, -ENOTEMPTY },
829 #ifdef EDQUOT
830 { nfserr_dquot, -EDQUOT },
831 #endif
832 { nfserr_stale, -ESTALE },
833 { nfserr_jukebox, -ETIMEDOUT },
834 { nfserr_jukebox, -ERESTARTSYS },
835 { nfserr_jukebox, -EAGAIN },
836 { nfserr_jukebox, -EWOULDBLOCK },
837 { nfserr_jukebox, -ENOMEM },
838 { nfserr_io, -ETXTBSY },
839 { nfserr_notsupp, -EOPNOTSUPP },
840 { nfserr_toosmall, -ETOOSMALL },
841 { nfserr_serverfault, -ESERVERFAULT },
842 { nfserr_serverfault, -ENFILE },
843 { nfserr_io, -EUCLEAN },
844 { nfserr_perm, -ENOKEY },
846 int i;
848 for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
849 if (nfs_errtbl[i].syserr == errno)
850 return nfs_errtbl[i].nfserr;
852 WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
853 return nfserr_io;