]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - fs/nfsd/nfsproc.c
sunrpc: properly type pc_decode callbacks
[mirror_ubuntu-focal-kernel.git] / fs / nfsd / nfsproc.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Process version 2 NFS requests.
3 *
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
5 */
6
1da177e4 7#include <linux/namei.h>
1da177e4 8
9a74af21
BH
9#include "cache.h"
10#include "xdr.h"
0a3adade 11#include "vfs.h"
1da177e4
LT
12
13typedef struct svc_rqst svc_rqst;
14typedef struct svc_buf svc_buf;
15
16#define NFSDDBG_FACILITY NFSDDBG_PROC
17
18
7111c66e 19static __be32
a6beb732 20nfsd_proc_null(struct svc_rqst *rqstp)
1da177e4
LT
21{
22 return nfs_ok;
23}
24
c4d987ba
AV
25static __be32
26nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp)
846f2fcd
DS
27{
28 if (err) return err;
3dadecce 29 return fh_getattr(&resp->fh, &resp->stat);
846f2fcd 30}
c4d987ba
AV
31static __be32
32nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
846f2fcd
DS
33{
34 if (err) return err;
3dadecce 35 return fh_getattr(&resp->fh, &resp->stat);
846f2fcd 36}
1da177e4
LT
37/*
38 * Get a file's attributes
39 * N.B. After this call resp->fh needs an fh_put
40 */
7111c66e 41static __be32
a6beb732 42nfsd_proc_getattr(struct svc_rqst *rqstp)
1da177e4 43{
a6beb732
CH
44 struct nfsd_fhandle *argp = rqstp->rq_argp;
45 struct nfsd_attrstat *resp = rqstp->rq_resp;
c4d987ba 46 __be32 nfserr;
1da177e4
LT
47 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
48
49 fh_copy(&resp->fh, &argp->fh);
04716e66
BF
50 nfserr = fh_verify(rqstp, &resp->fh, 0,
51 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
846f2fcd 52 return nfsd_return_attrs(nfserr, resp);
1da177e4
LT
53}
54
55/*
56 * Set a file's attributes
57 * N.B. After this call resp->fh needs an fh_put
58 */
7111c66e 59static __be32
a6beb732 60nfsd_proc_setattr(struct svc_rqst *rqstp)
1da177e4 61{
a6beb732
CH
62 struct nfsd_sattrargs *argp = rqstp->rq_argp;
63 struct nfsd_attrstat *resp = rqstp->rq_resp;
cc265089
AG
64 struct iattr *iap = &argp->attrs;
65 struct svc_fh *fhp;
c4d987ba 66 __be32 nfserr;
cc265089 67
1da177e4
LT
68 dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
69 SVCFH_fmt(&argp->fh),
70 argp->attrs.ia_valid, (long) argp->attrs.ia_size);
71
cc265089
AG
72 fhp = fh_copy(&resp->fh, &argp->fh);
73
74 /*
75 * NFSv2 does not differentiate between "set-[ac]time-to-now"
76 * which only requires access, and "set-[ac]time-to-X" which
77 * requires ownership.
78 * So if it looks like it might be "set both to the same time which
31051c85 79 * is close to now", and if setattr_prepare fails, then we
cc265089
AG
80 * convert to "set to now" instead of "set to explicit time"
81 *
31051c85 82 * We only call setattr_prepare as the last test as technically
cc265089
AG
83 * it is not an interface that we should be using.
84 */
85#define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
86#define MAX_TOUCH_TIME_ERROR (30*60)
87 if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
88 iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
89 /*
90 * Looks probable.
91 *
92 * Now just make sure time is in the right ballpark.
93 * Solaris, at least, doesn't seem to care what the time
94 * request is. We require it be within 30 minutes of now.
95 */
96 time_t delta = iap->ia_atime.tv_sec - get_seconds();
cc265089
AG
97
98 nfserr = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
99 if (nfserr)
100 goto done;
cc265089
AG
101
102 if (delta < 0)
103 delta = -delta;
104 if (delta < MAX_TOUCH_TIME_ERROR &&
31051c85 105 setattr_prepare(fhp->fh_dentry, iap) != 0) {
cc265089
AG
106 /*
107 * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
108 * This will cause notify_change to set these times
109 * to "now"
110 */
111 iap->ia_valid &= ~BOTH_TIME_SET;
112 }
113 }
114
115 nfserr = nfsd_setattr(rqstp, fhp, iap, 0, (time_t)0);
116done:
846f2fcd 117 return nfsd_return_attrs(nfserr, resp);
1da177e4
LT
118}
119
120/*
121 * Look up a path name component
122 * Note: the dentry in the resp->fh may be negative if the file
123 * doesn't exist yet.
124 * N.B. After this call resp->fh needs an fh_put
125 */
7111c66e 126static __be32
a6beb732 127nfsd_proc_lookup(struct svc_rqst *rqstp)
1da177e4 128{
a6beb732
CH
129 struct nfsd_diropargs *argp = rqstp->rq_argp;
130 struct nfsd_diropres *resp = rqstp->rq_resp;
c4d987ba 131 __be32 nfserr;
1da177e4
LT
132
133 dprintk("nfsd: LOOKUP %s %.*s\n",
134 SVCFH_fmt(&argp->fh), argp->len, argp->name);
135
136 fh_init(&resp->fh, NFS_FHSIZE);
137 nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
138 &resp->fh);
139
140 fh_put(&argp->fh);
846f2fcd 141 return nfsd_return_dirop(nfserr, resp);
1da177e4
LT
142}
143
144/*
145 * Read a symlink.
146 */
7111c66e 147static __be32
a6beb732 148nfsd_proc_readlink(struct svc_rqst *rqstp)
1da177e4 149{
a6beb732
CH
150 struct nfsd_readlinkargs *argp = rqstp->rq_argp;
151 struct nfsd_readlinkres *resp = rqstp->rq_resp;
c4d987ba 152 __be32 nfserr;
1da177e4
LT
153
154 dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
155
156 /* Read the symlink. */
157 resp->len = NFS_MAXPATHLEN;
158 nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
159
160 fh_put(&argp->fh);
161 return nfserr;
162}
163
164/*
165 * Read a portion of a file.
166 * N.B. After this call resp->fh needs an fh_put
167 */
7111c66e 168static __be32
a6beb732 169nfsd_proc_read(struct svc_rqst *rqstp)
1da177e4 170{
a6beb732
CH
171 struct nfsd_readargs *argp = rqstp->rq_argp;
172 struct nfsd_readres *resp = rqstp->rq_resp;
c4d987ba 173 __be32 nfserr;
1da177e4
LT
174
175 dprintk("nfsd: READ %s %d bytes at %d\n",
176 SVCFH_fmt(&argp->fh),
177 argp->count, argp->offset);
178
179 /* Obtain buffer pointer for payload. 19 is 1 word for
180 * status, 17 words for fattr, and 1 word for the byte count.
181 */
182
7adae489 183 if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
ad06e4bd 184 char buf[RPC_MAX_ADDRBUFLEN];
1da177e4 185 printk(KERN_NOTICE
ad06e4bd
CL
186 "oversized read request from %s (%d bytes)\n",
187 svc_print_addr(rqstp, buf, sizeof(buf)),
1da177e4 188 argp->count);
7adae489 189 argp->count = NFSSVC_MAXBLKSIZE_V2;
1da177e4 190 }
cd123012 191 svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
1da177e4
LT
192
193 resp->count = argp->count;
039a87ca 194 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
1da177e4 195 argp->offset,
3cc03b16 196 rqstp->rq_vec, argp->vlen,
1da177e4
LT
197 &resp->count);
198
846f2fcd 199 if (nfserr) return nfserr;
3dadecce 200 return fh_getattr(&resp->fh, &resp->stat);
1da177e4
LT
201}
202
203/*
204 * Write data to a file
205 * N.B. After this call resp->fh needs an fh_put
206 */
7111c66e 207static __be32
a6beb732 208nfsd_proc_write(struct svc_rqst *rqstp)
1da177e4 209{
a6beb732
CH
210 struct nfsd_writeargs *argp = rqstp->rq_argp;
211 struct nfsd_attrstat *resp = rqstp->rq_resp;
c4d987ba 212 __be32 nfserr;
31dec253 213 unsigned long cnt = argp->len;
1da177e4
LT
214
215 dprintk("nfsd: WRITE %s %d bytes at %d\n",
216 SVCFH_fmt(&argp->fh),
217 argp->len, argp->offset);
218
52e380e0
KM
219 nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), argp->offset,
220 rqstp->rq_vec, argp->vlen, &cnt, NFS_DATA_SYNC);
846f2fcd 221 return nfsd_return_attrs(nfserr, resp);
1da177e4
LT
222}
223
224/*
225 * CREATE processing is complicated. The keyword here is `overloaded.'
226 * The parent directory is kept locked between the check for existence
227 * and the actual create() call in compliance with VFS protocols.
228 * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
229 */
7111c66e 230static __be32
a6beb732 231nfsd_proc_create(struct svc_rqst *rqstp)
1da177e4 232{
a6beb732
CH
233 struct nfsd_createargs *argp = rqstp->rq_argp;
234 struct nfsd_diropres *resp = rqstp->rq_resp;
1da177e4
LT
235 svc_fh *dirfhp = &argp->fh;
236 svc_fh *newfhp = &resp->fh;
237 struct iattr *attr = &argp->attrs;
238 struct inode *inode;
239 struct dentry *dchild;
c4d987ba
AV
240 int type, mode;
241 __be32 nfserr;
4a55c101 242 int hosterr;
1da177e4
LT
243 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
244
245 dprintk("nfsd: CREATE %s %.*s\n",
246 SVCFH_fmt(dirfhp), argp->len, argp->name);
247
248 /* First verify the parent file handle */
8837abca 249 nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
1da177e4
LT
250 if (nfserr)
251 goto done; /* must fh_put dirfhp even on error */
252
8837abca 253 /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
1da177e4 254
1da177e4
LT
255 nfserr = nfserr_exist;
256 if (isdotent(argp->name, argp->len))
257 goto done;
4a55c101
JK
258 hosterr = fh_want_write(dirfhp);
259 if (hosterr) {
260 nfserr = nfserrno(hosterr);
261 goto done;
262 }
263
7ed94296 264 fh_lock_nested(dirfhp, I_MUTEX_PARENT);
1da177e4
LT
265 dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
266 if (IS_ERR(dchild)) {
267 nfserr = nfserrno(PTR_ERR(dchild));
268 goto out_unlock;
269 }
270 fh_init(newfhp, NFS_FHSIZE);
271 nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
2b0143b5 272 if (!nfserr && d_really_is_negative(dchild))
1da177e4
LT
273 nfserr = nfserr_noent;
274 dput(dchild);
275 if (nfserr) {
276 if (nfserr != nfserr_noent)
277 goto out_unlock;
278 /*
279 * If the new file handle wasn't verified, we can't tell
280 * whether the file exists or not. Time to bail ...
281 */
282 nfserr = nfserr_acces;
283 if (!newfhp->fh_dentry) {
284 printk(KERN_WARNING
285 "nfsd_proc_create: file handle not verified\n");
286 goto out_unlock;
287 }
288 }
289
2b0143b5 290 inode = d_inode(newfhp->fh_dentry);
1da177e4
LT
291
292 /* Unfudge the mode bits */
293 if (attr->ia_valid & ATTR_MODE) {
294 type = attr->ia_mode & S_IFMT;
295 mode = attr->ia_mode & ~S_IFMT;
296 if (!type) {
297 /* no type, so if target exists, assume same as that,
298 * else assume a file */
299 if (inode) {
300 type = inode->i_mode & S_IFMT;
301 switch(type) {
302 case S_IFCHR:
303 case S_IFBLK:
304 /* reserve rdev for later checking */
305 rdev = inode->i_rdev;
306 attr->ia_valid |= ATTR_SIZE;
307
308 /* FALLTHROUGH */
309 case S_IFIFO:
310 /* this is probably a permission check..
311 * at least IRIX implements perm checking on
312 * echo thing > device-special-file-or-pipe
313 * by doing a CREATE with type==0
314 */
0ec757df
BF
315 nfserr = nfsd_permission(rqstp,
316 newfhp->fh_export,
1da177e4 317 newfhp->fh_dentry,
8837abca 318 NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
1da177e4
LT
319 if (nfserr && nfserr != nfserr_rofs)
320 goto out_unlock;
321 }
322 } else
323 type = S_IFREG;
324 }
325 } else if (inode) {
326 type = inode->i_mode & S_IFMT;
327 mode = inode->i_mode & ~S_IFMT;
328 } else {
329 type = S_IFREG;
330 mode = 0; /* ??? */
331 }
332
333 attr->ia_valid |= ATTR_MODE;
334 attr->ia_mode = mode;
335
336 /* Special treatment for non-regular files according to the
337 * gospel of sun micro
338 */
339 if (type != S_IFREG) {
1da177e4
LT
340 if (type != S_IFBLK && type != S_IFCHR) {
341 rdev = 0;
342 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
343 /* If you think you've seen the worst, grok this. */
344 type = S_IFIFO;
345 } else {
346 /* Okay, char or block special */
1da177e4
LT
347 if (!rdev)
348 rdev = wanted;
349 }
350
351 /* we've used the SIZE information, so discard it */
352 attr->ia_valid &= ~ATTR_SIZE;
353
354 /* Make sure the type and device matches */
355 nfserr = nfserr_exist;
356 if (inode && type != (inode->i_mode & S_IFMT))
357 goto out_unlock;
358 }
359
360 nfserr = 0;
361 if (!inode) {
362 /* File doesn't exist. Create it and set attrs */
b44061d0
BF
363 nfserr = nfsd_create_locked(rqstp, dirfhp, argp->name,
364 argp->len, attr, type, rdev, newfhp);
1da177e4
LT
365 } else if (type == S_IFREG) {
366 dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
367 argp->name, attr->ia_valid, (long) attr->ia_size);
368 /* File already exists. We ignore all attributes except
369 * size, so that creat() behaves exactly like
370 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
371 */
372 attr->ia_valid &= ATTR_SIZE;
373 if (attr->ia_valid)
374 nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
375 }
376
377out_unlock:
378 /* We don't really need to unlock, as fh_put does it. */
379 fh_unlock(dirfhp);
4a55c101 380 fh_drop_write(dirfhp);
1da177e4
LT
381done:
382 fh_put(dirfhp);
846f2fcd 383 return nfsd_return_dirop(nfserr, resp);
1da177e4
LT
384}
385
7111c66e 386static __be32
a6beb732 387nfsd_proc_remove(struct svc_rqst *rqstp)
1da177e4 388{
a6beb732 389 struct nfsd_diropargs *argp = rqstp->rq_argp;
c4d987ba 390 __be32 nfserr;
1da177e4
LT
391
392 dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
393 argp->len, argp->name);
394
395 /* Unlink. -SIFDIR means file must not be a directory */
396 nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
397 fh_put(&argp->fh);
398 return nfserr;
399}
400
7111c66e 401static __be32
a6beb732 402nfsd_proc_rename(struct svc_rqst *rqstp)
1da177e4 403{
a6beb732 404 struct nfsd_renameargs *argp = rqstp->rq_argp;
c4d987ba 405 __be32 nfserr;
1da177e4
LT
406
407 dprintk("nfsd: RENAME %s %.*s -> \n",
408 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
409 dprintk("nfsd: -> %s %.*s\n",
410 SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
411
412 nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
413 &argp->tfh, argp->tname, argp->tlen);
414 fh_put(&argp->ffh);
415 fh_put(&argp->tfh);
416 return nfserr;
417}
418
7111c66e 419static __be32
a6beb732 420nfsd_proc_link(struct svc_rqst *rqstp)
1da177e4 421{
a6beb732 422 struct nfsd_linkargs *argp = rqstp->rq_argp;
c4d987ba 423 __be32 nfserr;
1da177e4
LT
424
425 dprintk("nfsd: LINK %s ->\n",
426 SVCFH_fmt(&argp->ffh));
427 dprintk("nfsd: %s %.*s\n",
428 SVCFH_fmt(&argp->tfh),
429 argp->tlen,
430 argp->tname);
431
432 nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
433 &argp->ffh);
434 fh_put(&argp->ffh);
435 fh_put(&argp->tfh);
436 return nfserr;
437}
438
7111c66e 439static __be32
a6beb732 440nfsd_proc_symlink(struct svc_rqst *rqstp)
1da177e4 441{
a6beb732 442 struct nfsd_symlinkargs *argp = rqstp->rq_argp;
1da177e4 443 struct svc_fh newfh;
c4d987ba 444 __be32 nfserr;
1da177e4
LT
445
446 dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
447 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
448 argp->tlen, argp->tname);
449
450 fh_init(&newfh, NFS_FHSIZE);
451 /*
0aeae33f
BF
452 * Crazy hack: the request fits in a page, and already-decoded
453 * attributes follow argp->tname, so it's safe to just write a
454 * null to ensure it's null-terminated:
1da177e4 455 */
0aeae33f 456 argp->tname[argp->tlen] = '\0';
1da177e4 457 nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
1e444f5b 458 argp->tname, &newfh);
1da177e4
LT
459
460 fh_put(&argp->ffh);
461 fh_put(&newfh);
462 return nfserr;
463}
464
465/*
466 * Make directory. This operation is not idempotent.
467 * N.B. After this call resp->fh needs an fh_put
468 */
7111c66e 469static __be32
a6beb732 470nfsd_proc_mkdir(struct svc_rqst *rqstp)
1da177e4 471{
a6beb732
CH
472 struct nfsd_createargs *argp = rqstp->rq_argp;
473 struct nfsd_diropres *resp = rqstp->rq_resp;
c4d987ba 474 __be32 nfserr;
1da177e4
LT
475
476 dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
477
478 if (resp->fh.fh_dentry) {
479 printk(KERN_WARNING
480 "nfsd_proc_mkdir: response already verified??\n");
481 }
482
483 argp->attrs.ia_valid &= ~ATTR_SIZE;
484 fh_init(&resp->fh, NFS_FHSIZE);
485 nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
486 &argp->attrs, S_IFDIR, 0, &resp->fh);
487 fh_put(&argp->fh);
846f2fcd 488 return nfsd_return_dirop(nfserr, resp);
1da177e4
LT
489}
490
491/*
492 * Remove a directory
493 */
7111c66e 494static __be32
a6beb732 495nfsd_proc_rmdir(struct svc_rqst *rqstp)
1da177e4 496{
a6beb732 497 struct nfsd_diropargs *argp = rqstp->rq_argp;
c4d987ba 498 __be32 nfserr;
1da177e4
LT
499
500 dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
501
502 nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
503 fh_put(&argp->fh);
504 return nfserr;
505}
506
507/*
508 * Read a portion of a directory.
509 */
7111c66e 510static __be32
a6beb732 511nfsd_proc_readdir(struct svc_rqst *rqstp)
1da177e4 512{
a6beb732
CH
513 struct nfsd_readdirargs *argp = rqstp->rq_argp;
514 struct nfsd_readdirres *resp = rqstp->rq_resp;
c4d987ba
AV
515 int count;
516 __be32 nfserr;
1da177e4
LT
517 loff_t offset;
518
519 dprintk("nfsd: READDIR %s %d bytes at %d\n",
520 SVCFH_fmt(&argp->fh),
521 argp->count, argp->cookie);
522
523 /* Shrink to the client read size */
524 count = (argp->count >> 2) - 2;
525
526 /* Make sure we've room for the NULL ptr & eof flag */
527 count -= 2;
528 if (count < 0)
529 count = 0;
530
531 resp->buffer = argp->buffer;
532 resp->offset = NULL;
533 resp->buflen = count;
534 resp->common.err = nfs_ok;
535 /* Read directory and encode entries on the fly */
536 offset = argp->cookie;
537 nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
538 &resp->common, nfssvc_encode_entry);
539
540 resp->count = resp->buffer - argp->buffer;
541 if (resp->offset)
542 *resp->offset = htonl(offset);
543
544 fh_put(&argp->fh);
545 return nfserr;
546}
547
548/*
549 * Get file system info
550 */
7111c66e 551static __be32
a6beb732 552nfsd_proc_statfs(struct svc_rqst *rqstp)
1da177e4 553{
a6beb732
CH
554 struct nfsd_fhandle *argp = rqstp->rq_argp;
555 struct nfsd_statfsres *resp = rqstp->rq_resp;
c4d987ba 556 __be32 nfserr;
1da177e4
LT
557
558 dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
559
04716e66
BF
560 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
561 NFSD_MAY_BYPASS_GSS_ON_ROOT);
1da177e4
LT
562 fh_put(&argp->fh);
563 return nfserr;
564}
565
566/*
567 * NFSv2 Server procedures.
568 * Only the results of non-idempotent operations are cached.
569 */
1da177e4
LT
570struct nfsd_void { int dummy; };
571
1da177e4
LT
572#define ST 1 /* status */
573#define FH 8 /* filehandle */
574#define AT 18 /* attributes */
575
576static struct svc_procedure nfsd_procedures2[18] = {
b9081d90 577 [NFSPROC_NULL] = {
a6beb732 578 .pc_func = nfsd_proc_null,
026fec7e 579 .pc_decode = nfssvc_decode_void,
b9081d90
YZ
580 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
581 .pc_argsize = sizeof(struct nfsd_void),
582 .pc_ressize = sizeof(struct nfsd_void),
583 .pc_cachetype = RC_NOCACHE,
584 .pc_xdrressize = ST,
585 },
586 [NFSPROC_GETATTR] = {
a6beb732 587 .pc_func = nfsd_proc_getattr,
026fec7e 588 .pc_decode = nfssvc_decode_fhandle,
b9081d90 589 .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
8537488b 590 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
591 .pc_argsize = sizeof(struct nfsd_fhandle),
592 .pc_ressize = sizeof(struct nfsd_attrstat),
593 .pc_cachetype = RC_NOCACHE,
594 .pc_xdrressize = ST+AT,
595 },
596 [NFSPROC_SETATTR] = {
a6beb732 597 .pc_func = nfsd_proc_setattr,
026fec7e 598 .pc_decode = nfssvc_decode_sattrargs,
b9081d90 599 .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
8537488b 600 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
601 .pc_argsize = sizeof(struct nfsd_sattrargs),
602 .pc_ressize = sizeof(struct nfsd_attrstat),
603 .pc_cachetype = RC_REPLBUFF,
604 .pc_xdrressize = ST+AT,
605 },
606 [NFSPROC_ROOT] = {
026fec7e 607 .pc_decode = nfssvc_decode_void,
b9081d90
YZ
608 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
609 .pc_argsize = sizeof(struct nfsd_void),
610 .pc_ressize = sizeof(struct nfsd_void),
611 .pc_cachetype = RC_NOCACHE,
612 .pc_xdrressize = ST,
613 },
614 [NFSPROC_LOOKUP] = {
a6beb732 615 .pc_func = nfsd_proc_lookup,
026fec7e 616 .pc_decode = nfssvc_decode_diropargs,
b9081d90 617 .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
8537488b 618 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
619 .pc_argsize = sizeof(struct nfsd_diropargs),
620 .pc_ressize = sizeof(struct nfsd_diropres),
621 .pc_cachetype = RC_NOCACHE,
622 .pc_xdrressize = ST+FH+AT,
623 },
624 [NFSPROC_READLINK] = {
a6beb732 625 .pc_func = nfsd_proc_readlink,
026fec7e 626 .pc_decode = nfssvc_decode_readlinkargs,
b9081d90
YZ
627 .pc_encode = (kxdrproc_t) nfssvc_encode_readlinkres,
628 .pc_argsize = sizeof(struct nfsd_readlinkargs),
629 .pc_ressize = sizeof(struct nfsd_readlinkres),
630 .pc_cachetype = RC_NOCACHE,
631 .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
632 },
633 [NFSPROC_READ] = {
a6beb732 634 .pc_func = nfsd_proc_read,
026fec7e 635 .pc_decode = nfssvc_decode_readargs,
b9081d90 636 .pc_encode = (kxdrproc_t) nfssvc_encode_readres,
8537488b 637 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
638 .pc_argsize = sizeof(struct nfsd_readargs),
639 .pc_ressize = sizeof(struct nfsd_readres),
640 .pc_cachetype = RC_NOCACHE,
641 .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
642 },
643 [NFSPROC_WRITECACHE] = {
026fec7e 644 .pc_decode = nfssvc_decode_void,
b9081d90
YZ
645 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
646 .pc_argsize = sizeof(struct nfsd_void),
647 .pc_ressize = sizeof(struct nfsd_void),
648 .pc_cachetype = RC_NOCACHE,
649 .pc_xdrressize = ST,
650 },
651 [NFSPROC_WRITE] = {
a6beb732 652 .pc_func = nfsd_proc_write,
026fec7e 653 .pc_decode = nfssvc_decode_writeargs,
b9081d90 654 .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
8537488b 655 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
656 .pc_argsize = sizeof(struct nfsd_writeargs),
657 .pc_ressize = sizeof(struct nfsd_attrstat),
658 .pc_cachetype = RC_REPLBUFF,
659 .pc_xdrressize = ST+AT,
660 },
661 [NFSPROC_CREATE] = {
a6beb732 662 .pc_func = nfsd_proc_create,
026fec7e 663 .pc_decode = nfssvc_decode_createargs,
b9081d90 664 .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
8537488b 665 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
666 .pc_argsize = sizeof(struct nfsd_createargs),
667 .pc_ressize = sizeof(struct nfsd_diropres),
668 .pc_cachetype = RC_REPLBUFF,
669 .pc_xdrressize = ST+FH+AT,
670 },
671 [NFSPROC_REMOVE] = {
a6beb732 672 .pc_func = nfsd_proc_remove,
026fec7e 673 .pc_decode = nfssvc_decode_diropargs,
b9081d90
YZ
674 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
675 .pc_argsize = sizeof(struct nfsd_diropargs),
676 .pc_ressize = sizeof(struct nfsd_void),
677 .pc_cachetype = RC_REPLSTAT,
678 .pc_xdrressize = ST,
679 },
680 [NFSPROC_RENAME] = {
a6beb732 681 .pc_func = nfsd_proc_rename,
026fec7e 682 .pc_decode = nfssvc_decode_renameargs,
b9081d90
YZ
683 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
684 .pc_argsize = sizeof(struct nfsd_renameargs),
685 .pc_ressize = sizeof(struct nfsd_void),
686 .pc_cachetype = RC_REPLSTAT,
687 .pc_xdrressize = ST,
688 },
689 [NFSPROC_LINK] = {
a6beb732 690 .pc_func = nfsd_proc_link,
026fec7e 691 .pc_decode = nfssvc_decode_linkargs,
b9081d90
YZ
692 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
693 .pc_argsize = sizeof(struct nfsd_linkargs),
694 .pc_ressize = sizeof(struct nfsd_void),
695 .pc_cachetype = RC_REPLSTAT,
696 .pc_xdrressize = ST,
697 },
698 [NFSPROC_SYMLINK] = {
a6beb732 699 .pc_func = nfsd_proc_symlink,
026fec7e 700 .pc_decode = nfssvc_decode_symlinkargs,
b9081d90
YZ
701 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
702 .pc_argsize = sizeof(struct nfsd_symlinkargs),
703 .pc_ressize = sizeof(struct nfsd_void),
704 .pc_cachetype = RC_REPLSTAT,
705 .pc_xdrressize = ST,
706 },
707 [NFSPROC_MKDIR] = {
a6beb732 708 .pc_func = nfsd_proc_mkdir,
026fec7e 709 .pc_decode = nfssvc_decode_createargs,
b9081d90 710 .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
8537488b 711 .pc_release = nfssvc_release_fhandle,
b9081d90
YZ
712 .pc_argsize = sizeof(struct nfsd_createargs),
713 .pc_ressize = sizeof(struct nfsd_diropres),
714 .pc_cachetype = RC_REPLBUFF,
715 .pc_xdrressize = ST+FH+AT,
716 },
717 [NFSPROC_RMDIR] = {
a6beb732 718 .pc_func = nfsd_proc_rmdir,
026fec7e 719 .pc_decode = nfssvc_decode_diropargs,
b9081d90
YZ
720 .pc_encode = (kxdrproc_t) nfssvc_encode_void,
721 .pc_argsize = sizeof(struct nfsd_diropargs),
722 .pc_ressize = sizeof(struct nfsd_void),
723 .pc_cachetype = RC_REPLSTAT,
724 .pc_xdrressize = ST,
725 },
726 [NFSPROC_READDIR] = {
a6beb732 727 .pc_func = nfsd_proc_readdir,
026fec7e 728 .pc_decode = nfssvc_decode_readdirargs,
b9081d90
YZ
729 .pc_encode = (kxdrproc_t) nfssvc_encode_readdirres,
730 .pc_argsize = sizeof(struct nfsd_readdirargs),
731 .pc_ressize = sizeof(struct nfsd_readdirres),
732 .pc_cachetype = RC_NOCACHE,
733 },
734 [NFSPROC_STATFS] = {
a6beb732 735 .pc_func = nfsd_proc_statfs,
026fec7e 736 .pc_decode = nfssvc_decode_fhandle,
b9081d90
YZ
737 .pc_encode = (kxdrproc_t) nfssvc_encode_statfsres,
738 .pc_argsize = sizeof(struct nfsd_fhandle),
739 .pc_ressize = sizeof(struct nfsd_statfsres),
740 .pc_cachetype = RC_NOCACHE,
741 .pc_xdrressize = ST+5,
742 },
1da177e4
LT
743};
744
745
746struct svc_version nfsd_version2 = {
747 .vs_vers = 2,
748 .vs_nproc = 18,
749 .vs_proc = nfsd_procedures2,
750 .vs_dispatch = nfsd_dispatch,
751 .vs_xdrsize = NFS2_SVC_XDRSIZE,
752};
753
754/*
755 * Map errnos to NFS errnos.
756 */
63f10311 757__be32
1da177e4
LT
758nfserrno (int errno)
759{
760 static struct {
63f10311 761 __be32 nfserr;
1da177e4
LT
762 int syserr;
763 } nfs_errtbl[] = {
764 { nfs_ok, 0 },
765 { nfserr_perm, -EPERM },
766 { nfserr_noent, -ENOENT },
767 { nfserr_io, -EIO },
768 { nfserr_nxio, -ENXIO },
62814d6a 769 { nfserr_fbig, -E2BIG },
1da177e4
LT
770 { nfserr_acces, -EACCES },
771 { nfserr_exist, -EEXIST },
772 { nfserr_xdev, -EXDEV },
773 { nfserr_mlink, -EMLINK },
774 { nfserr_nodev, -ENODEV },
775 { nfserr_notdir, -ENOTDIR },
776 { nfserr_isdir, -EISDIR },
777 { nfserr_inval, -EINVAL },
778 { nfserr_fbig, -EFBIG },
779 { nfserr_nospc, -ENOSPC },
780 { nfserr_rofs, -EROFS },
781 { nfserr_mlink, -EMLINK },
782 { nfserr_nametoolong, -ENAMETOOLONG },
783 { nfserr_notempty, -ENOTEMPTY },
784#ifdef EDQUOT
785 { nfserr_dquot, -EDQUOT },
786#endif
787 { nfserr_stale, -ESTALE },
788 { nfserr_jukebox, -ETIMEDOUT },
599eb304 789 { nfserr_jukebox, -ERESTARTSYS },
062304a8
BF
790 { nfserr_jukebox, -EAGAIN },
791 { nfserr_jukebox, -EWOULDBLOCK },
3beb6cd1 792 { nfserr_jukebox, -ENOMEM },
1da177e4 793 { nfserr_io, -ETXTBSY },
a838cc49 794 { nfserr_notsupp, -EOPNOTSUPP },
b7aeda40 795 { nfserr_toosmall, -ETOOSMALL },
f39bde24 796 { nfserr_serverfault, -ESERVERFAULT },
b3fbfe0e 797 { nfserr_serverfault, -ENFILE },
42e61616 798 { nfserr_io, -EUCLEAN },
c952cd4e 799 { nfserr_perm, -ENOKEY },
1da177e4
LT
800 };
801 int i;
802
63f10311 803 for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
1da177e4
LT
804 if (nfs_errtbl[i].syserr == errno)
805 return nfs_errtbl[i].nfserr;
806 }
ff30f08c 807 WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
1da177e4
LT
808 return nfserr_io;
809}
810