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