]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/nfsd/nfs3proc.c
x86/cpu: Make alternative_msr_write work for 32-bit code
[mirror_ubuntu-artful-kernel.git] / fs / nfsd / nfs3proc.c
1 /*
2 * Process version 3 NFS requests.
3 *
4 * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
5 */
6
7 #include <linux/fs.h>
8 #include <linux/ext2_fs.h>
9 #include <linux/magic.h>
10
11 #include "cache.h"
12 #include "xdr3.h"
13 #include "vfs.h"
14
15 #define NFSDDBG_FACILITY NFSDDBG_PROC
16
17 #define RETURN_STATUS(st) { resp->status = (st); return (st); }
18
19 static int nfs3_ftypes[] = {
20 0, /* NF3NON */
21 S_IFREG, /* NF3REG */
22 S_IFDIR, /* NF3DIR */
23 S_IFBLK, /* NF3BLK */
24 S_IFCHR, /* NF3CHR */
25 S_IFLNK, /* NF3LNK */
26 S_IFSOCK, /* NF3SOCK */
27 S_IFIFO, /* NF3FIFO */
28 };
29
30 /*
31 * NULL call.
32 */
33 static __be32
34 nfsd3_proc_null(struct svc_rqst *rqstp)
35 {
36 return nfs_ok;
37 }
38
39 /*
40 * Get a file's attributes
41 */
42 static __be32
43 nfsd3_proc_getattr(struct svc_rqst *rqstp)
44 {
45 struct nfsd_fhandle *argp = rqstp->rq_argp;
46 struct nfsd3_attrstat *resp = rqstp->rq_resp;
47 __be32 nfserr;
48
49 dprintk("nfsd: GETATTR(3) %s\n",
50 SVCFH_fmt(&argp->fh));
51
52 fh_copy(&resp->fh, &argp->fh);
53 nfserr = fh_verify(rqstp, &resp->fh, 0,
54 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
55 if (nfserr)
56 RETURN_STATUS(nfserr);
57
58 nfserr = fh_getattr(&resp->fh, &resp->stat);
59
60 RETURN_STATUS(nfserr);
61 }
62
63 /*
64 * Set a file's attributes
65 */
66 static __be32
67 nfsd3_proc_setattr(struct svc_rqst *rqstp)
68 {
69 struct nfsd3_sattrargs *argp = rqstp->rq_argp;
70 struct nfsd3_attrstat *resp = rqstp->rq_resp;
71 __be32 nfserr;
72
73 dprintk("nfsd: SETATTR(3) %s\n",
74 SVCFH_fmt(&argp->fh));
75
76 fh_copy(&resp->fh, &argp->fh);
77 nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
78 argp->check_guard, argp->guardtime);
79 RETURN_STATUS(nfserr);
80 }
81
82 /*
83 * Look up a path name component
84 */
85 static __be32
86 nfsd3_proc_lookup(struct svc_rqst *rqstp)
87 {
88 struct nfsd3_diropargs *argp = rqstp->rq_argp;
89 struct nfsd3_diropres *resp = rqstp->rq_resp;
90 __be32 nfserr;
91
92 dprintk("nfsd: LOOKUP(3) %s %.*s\n",
93 SVCFH_fmt(&argp->fh),
94 argp->len,
95 argp->name);
96
97 fh_copy(&resp->dirfh, &argp->fh);
98 fh_init(&resp->fh, NFS3_FHSIZE);
99
100 nfserr = nfsd_lookup(rqstp, &resp->dirfh,
101 argp->name,
102 argp->len,
103 &resp->fh);
104 RETURN_STATUS(nfserr);
105 }
106
107 /*
108 * Check file access
109 */
110 static __be32
111 nfsd3_proc_access(struct svc_rqst *rqstp)
112 {
113 struct nfsd3_accessargs *argp = rqstp->rq_argp;
114 struct nfsd3_accessres *resp = rqstp->rq_resp;
115 __be32 nfserr;
116
117 dprintk("nfsd: ACCESS(3) %s 0x%x\n",
118 SVCFH_fmt(&argp->fh),
119 argp->access);
120
121 fh_copy(&resp->fh, &argp->fh);
122 resp->access = argp->access;
123 nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
124 RETURN_STATUS(nfserr);
125 }
126
127 /*
128 * Read a symlink.
129 */
130 static __be32
131 nfsd3_proc_readlink(struct svc_rqst *rqstp)
132 {
133 struct nfsd3_readlinkargs *argp = rqstp->rq_argp;
134 struct nfsd3_readlinkres *resp = rqstp->rq_resp;
135 __be32 nfserr;
136
137 dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));
138
139 /* Read the symlink. */
140 fh_copy(&resp->fh, &argp->fh);
141 resp->len = NFS3_MAXPATHLEN;
142 nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
143 RETURN_STATUS(nfserr);
144 }
145
146 /*
147 * Read a portion of a file.
148 */
149 static __be32
150 nfsd3_proc_read(struct svc_rqst *rqstp)
151 {
152 struct nfsd3_readargs *argp = rqstp->rq_argp;
153 struct nfsd3_readres *resp = rqstp->rq_resp;
154 __be32 nfserr;
155 u32 max_blocksize = svc_max_payload(rqstp);
156 unsigned long cnt = min(argp->count, max_blocksize);
157
158 dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
159 SVCFH_fmt(&argp->fh),
160 (unsigned long) argp->count,
161 (unsigned long long) argp->offset);
162
163 /* Obtain buffer pointer for payload.
164 * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
165 * + 1 (xdr opaque byte count) = 26
166 */
167 resp->count = cnt;
168 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
169
170 fh_copy(&resp->fh, &argp->fh);
171 nfserr = nfsd_read(rqstp, &resp->fh,
172 argp->offset,
173 rqstp->rq_vec, argp->vlen,
174 &resp->count);
175 if (nfserr == 0) {
176 struct inode *inode = d_inode(resp->fh.fh_dentry);
177 resp->eof = nfsd_eof_on_read(cnt, resp->count, argp->offset,
178 inode->i_size);
179 }
180
181 RETURN_STATUS(nfserr);
182 }
183
184 /*
185 * Write data to a file
186 */
187 static __be32
188 nfsd3_proc_write(struct svc_rqst *rqstp)
189 {
190 struct nfsd3_writeargs *argp = rqstp->rq_argp;
191 struct nfsd3_writeres *resp = rqstp->rq_resp;
192 __be32 nfserr;
193 unsigned long cnt = argp->len;
194
195 dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
196 SVCFH_fmt(&argp->fh),
197 argp->len,
198 (unsigned long long) argp->offset,
199 argp->stable? " stable" : "");
200
201 fh_copy(&resp->fh, &argp->fh);
202 resp->committed = argp->stable;
203 nfserr = nfsd_write(rqstp, &resp->fh, argp->offset,
204 rqstp->rq_vec, argp->vlen,
205 &cnt, resp->committed);
206 resp->count = cnt;
207 RETURN_STATUS(nfserr);
208 }
209
210 /*
211 * With NFSv3, CREATE processing is a lot easier than with NFSv2.
212 * At least in theory; we'll see how it fares in practice when the
213 * first reports about SunOS compatibility problems start to pour in...
214 */
215 static __be32
216 nfsd3_proc_create(struct svc_rqst *rqstp)
217 {
218 struct nfsd3_createargs *argp = rqstp->rq_argp;
219 struct nfsd3_diropres *resp = rqstp->rq_resp;
220 svc_fh *dirfhp, *newfhp = NULL;
221 struct iattr *attr;
222 __be32 nfserr;
223
224 dprintk("nfsd: CREATE(3) %s %.*s\n",
225 SVCFH_fmt(&argp->fh),
226 argp->len,
227 argp->name);
228
229 dirfhp = fh_copy(&resp->dirfh, &argp->fh);
230 newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
231 attr = &argp->attrs;
232
233 /* Unfudge the mode bits */
234 attr->ia_mode &= ~S_IFMT;
235 if (!(attr->ia_valid & ATTR_MODE)) {
236 attr->ia_valid |= ATTR_MODE;
237 attr->ia_mode = S_IFREG;
238 } else {
239 attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
240 }
241
242 /* Now create the file and set attributes */
243 nfserr = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
244 attr, newfhp,
245 argp->createmode, (u32 *)argp->verf, NULL, NULL);
246
247 RETURN_STATUS(nfserr);
248 }
249
250 /*
251 * Make directory. This operation is not idempotent.
252 */
253 static __be32
254 nfsd3_proc_mkdir(struct svc_rqst *rqstp)
255 {
256 struct nfsd3_createargs *argp = rqstp->rq_argp;
257 struct nfsd3_diropres *resp = rqstp->rq_resp;
258 __be32 nfserr;
259
260 dprintk("nfsd: MKDIR(3) %s %.*s\n",
261 SVCFH_fmt(&argp->fh),
262 argp->len,
263 argp->name);
264
265 argp->attrs.ia_valid &= ~ATTR_SIZE;
266 fh_copy(&resp->dirfh, &argp->fh);
267 fh_init(&resp->fh, NFS3_FHSIZE);
268 nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
269 &argp->attrs, S_IFDIR, 0, &resp->fh);
270 fh_unlock(&resp->dirfh);
271 RETURN_STATUS(nfserr);
272 }
273
274 static __be32
275 nfsd3_proc_symlink(struct svc_rqst *rqstp)
276 {
277 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
278 struct nfsd3_diropres *resp = rqstp->rq_resp;
279 __be32 nfserr;
280
281 dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
282 SVCFH_fmt(&argp->ffh),
283 argp->flen, argp->fname,
284 argp->tlen, argp->tname);
285
286 fh_copy(&resp->dirfh, &argp->ffh);
287 fh_init(&resp->fh, NFS3_FHSIZE);
288 nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen,
289 argp->tname, &resp->fh);
290 RETURN_STATUS(nfserr);
291 }
292
293 /*
294 * Make socket/fifo/device.
295 */
296 static __be32
297 nfsd3_proc_mknod(struct svc_rqst *rqstp)
298 {
299 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
300 struct nfsd3_diropres *resp = rqstp->rq_resp;
301 __be32 nfserr;
302 int type;
303 dev_t rdev = 0;
304
305 dprintk("nfsd: MKNOD(3) %s %.*s\n",
306 SVCFH_fmt(&argp->fh),
307 argp->len,
308 argp->name);
309
310 fh_copy(&resp->dirfh, &argp->fh);
311 fh_init(&resp->fh, NFS3_FHSIZE);
312
313 if (argp->ftype == 0 || argp->ftype >= NF3BAD)
314 RETURN_STATUS(nfserr_inval);
315 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
316 rdev = MKDEV(argp->major, argp->minor);
317 if (MAJOR(rdev) != argp->major ||
318 MINOR(rdev) != argp->minor)
319 RETURN_STATUS(nfserr_inval);
320 } else
321 if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO)
322 RETURN_STATUS(nfserr_inval);
323
324 type = nfs3_ftypes[argp->ftype];
325 nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
326 &argp->attrs, type, rdev, &resp->fh);
327 fh_unlock(&resp->dirfh);
328 RETURN_STATUS(nfserr);
329 }
330
331 /*
332 * Remove file/fifo/socket etc.
333 */
334 static __be32
335 nfsd3_proc_remove(struct svc_rqst *rqstp)
336 {
337 struct nfsd3_diropargs *argp = rqstp->rq_argp;
338 struct nfsd3_attrstat *resp = rqstp->rq_resp;
339 __be32 nfserr;
340
341 dprintk("nfsd: REMOVE(3) %s %.*s\n",
342 SVCFH_fmt(&argp->fh),
343 argp->len,
344 argp->name);
345
346 /* Unlink. -S_IFDIR means file must not be a directory */
347 fh_copy(&resp->fh, &argp->fh);
348 nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
349 fh_unlock(&resp->fh);
350 RETURN_STATUS(nfserr);
351 }
352
353 /*
354 * Remove a directory
355 */
356 static __be32
357 nfsd3_proc_rmdir(struct svc_rqst *rqstp)
358 {
359 struct nfsd3_diropargs *argp = rqstp->rq_argp;
360 struct nfsd3_attrstat *resp = rqstp->rq_resp;
361 __be32 nfserr;
362
363 dprintk("nfsd: RMDIR(3) %s %.*s\n",
364 SVCFH_fmt(&argp->fh),
365 argp->len,
366 argp->name);
367
368 fh_copy(&resp->fh, &argp->fh);
369 nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
370 fh_unlock(&resp->fh);
371 RETURN_STATUS(nfserr);
372 }
373
374 static __be32
375 nfsd3_proc_rename(struct svc_rqst *rqstp)
376 {
377 struct nfsd3_renameargs *argp = rqstp->rq_argp;
378 struct nfsd3_renameres *resp = rqstp->rq_resp;
379 __be32 nfserr;
380
381 dprintk("nfsd: RENAME(3) %s %.*s ->\n",
382 SVCFH_fmt(&argp->ffh),
383 argp->flen,
384 argp->fname);
385 dprintk("nfsd: -> %s %.*s\n",
386 SVCFH_fmt(&argp->tfh),
387 argp->tlen,
388 argp->tname);
389
390 fh_copy(&resp->ffh, &argp->ffh);
391 fh_copy(&resp->tfh, &argp->tfh);
392 nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
393 &resp->tfh, argp->tname, argp->tlen);
394 RETURN_STATUS(nfserr);
395 }
396
397 static __be32
398 nfsd3_proc_link(struct svc_rqst *rqstp)
399 {
400 struct nfsd3_linkargs *argp = rqstp->rq_argp;
401 struct nfsd3_linkres *resp = rqstp->rq_resp;
402 __be32 nfserr;
403
404 dprintk("nfsd: LINK(3) %s ->\n",
405 SVCFH_fmt(&argp->ffh));
406 dprintk("nfsd: -> %s %.*s\n",
407 SVCFH_fmt(&argp->tfh),
408 argp->tlen,
409 argp->tname);
410
411 fh_copy(&resp->fh, &argp->ffh);
412 fh_copy(&resp->tfh, &argp->tfh);
413 nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
414 &resp->fh);
415 RETURN_STATUS(nfserr);
416 }
417
418 /*
419 * Read a portion of a directory.
420 */
421 static __be32
422 nfsd3_proc_readdir(struct svc_rqst *rqstp)
423 {
424 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
425 struct nfsd3_readdirres *resp = rqstp->rq_resp;
426 __be32 nfserr;
427 int count;
428
429 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
430 SVCFH_fmt(&argp->fh),
431 argp->count, (u32) argp->cookie);
432
433 /* Make sure we've room for the NULL ptr & eof flag, and shrink to
434 * client read size */
435 count = (argp->count >> 2) - 2;
436
437 /* Read directory and encode entries on the fly */
438 fh_copy(&resp->fh, &argp->fh);
439
440 resp->buflen = count;
441 resp->common.err = nfs_ok;
442 resp->buffer = argp->buffer;
443 resp->rqstp = rqstp;
444 nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie,
445 &resp->common, nfs3svc_encode_entry);
446 memcpy(resp->verf, argp->verf, 8);
447 resp->count = resp->buffer - argp->buffer;
448 if (resp->offset)
449 xdr_encode_hyper(resp->offset, argp->cookie);
450
451 RETURN_STATUS(nfserr);
452 }
453
454 /*
455 * Read a portion of a directory, including file handles and attrs.
456 * For now, we choose to ignore the dircount parameter.
457 */
458 static __be32
459 nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
460 {
461 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
462 struct nfsd3_readdirres *resp = rqstp->rq_resp;
463 __be32 nfserr;
464 int count = 0;
465 loff_t offset;
466 struct page **p;
467 caddr_t page_addr = NULL;
468
469 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
470 SVCFH_fmt(&argp->fh),
471 argp->count, (u32) argp->cookie);
472
473 /* Convert byte count to number of words (i.e. >> 2),
474 * and reserve room for the NULL ptr & eof flag (-2 words) */
475 resp->count = (argp->count >> 2) - 2;
476
477 /* Read directory and encode entries on the fly */
478 fh_copy(&resp->fh, &argp->fh);
479
480 resp->common.err = nfs_ok;
481 resp->buffer = argp->buffer;
482 resp->buflen = resp->count;
483 resp->rqstp = rqstp;
484 offset = argp->cookie;
485
486 nfserr = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
487 if (nfserr)
488 RETURN_STATUS(nfserr);
489
490 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS)
491 RETURN_STATUS(nfserr_notsupp);
492
493 nfserr = nfsd_readdir(rqstp, &resp->fh,
494 &offset,
495 &resp->common,
496 nfs3svc_encode_entry_plus);
497 memcpy(resp->verf, argp->verf, 8);
498 for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
499 page_addr = page_address(*p);
500
501 if (((caddr_t)resp->buffer >= page_addr) &&
502 ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
503 count += (caddr_t)resp->buffer - page_addr;
504 break;
505 }
506 count += PAGE_SIZE;
507 }
508 resp->count = count >> 2;
509 if (resp->offset) {
510 if (unlikely(resp->offset1)) {
511 /* we ended up with offset on a page boundary */
512 *resp->offset = htonl(offset >> 32);
513 *resp->offset1 = htonl(offset & 0xffffffff);
514 resp->offset1 = NULL;
515 } else {
516 xdr_encode_hyper(resp->offset, offset);
517 }
518 }
519
520 RETURN_STATUS(nfserr);
521 }
522
523 /*
524 * Get file system stats
525 */
526 static __be32
527 nfsd3_proc_fsstat(struct svc_rqst *rqstp)
528 {
529 struct nfsd_fhandle *argp = rqstp->rq_argp;
530 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
531 __be32 nfserr;
532
533 dprintk("nfsd: FSSTAT(3) %s\n",
534 SVCFH_fmt(&argp->fh));
535
536 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
537 fh_put(&argp->fh);
538 RETURN_STATUS(nfserr);
539 }
540
541 /*
542 * Get file system info
543 */
544 static __be32
545 nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
546 {
547 struct nfsd_fhandle *argp = rqstp->rq_argp;
548 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
549 __be32 nfserr;
550 u32 max_blocksize = svc_max_payload(rqstp);
551
552 dprintk("nfsd: FSINFO(3) %s\n",
553 SVCFH_fmt(&argp->fh));
554
555 resp->f_rtmax = max_blocksize;
556 resp->f_rtpref = max_blocksize;
557 resp->f_rtmult = PAGE_SIZE;
558 resp->f_wtmax = max_blocksize;
559 resp->f_wtpref = max_blocksize;
560 resp->f_wtmult = PAGE_SIZE;
561 resp->f_dtpref = PAGE_SIZE;
562 resp->f_maxfilesize = ~(u32) 0;
563 resp->f_properties = NFS3_FSF_DEFAULT;
564
565 nfserr = fh_verify(rqstp, &argp->fh, 0,
566 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
567
568 /* Check special features of the file system. May request
569 * different read/write sizes for file systems known to have
570 * problems with large blocks */
571 if (nfserr == 0) {
572 struct super_block *sb = argp->fh.fh_dentry->d_sb;
573
574 /* Note that we don't care for remote fs's here */
575 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
576 resp->f_properties = NFS3_FSF_BILLYBOY;
577 }
578 resp->f_maxfilesize = sb->s_maxbytes;
579 }
580
581 fh_put(&argp->fh);
582 RETURN_STATUS(nfserr);
583 }
584
585 /*
586 * Get pathconf info for the specified file
587 */
588 static __be32
589 nfsd3_proc_pathconf(struct svc_rqst *rqstp)
590 {
591 struct nfsd_fhandle *argp = rqstp->rq_argp;
592 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
593 __be32 nfserr;
594
595 dprintk("nfsd: PATHCONF(3) %s\n",
596 SVCFH_fmt(&argp->fh));
597
598 /* Set default pathconf */
599 resp->p_link_max = 255; /* at least */
600 resp->p_name_max = 255; /* at least */
601 resp->p_no_trunc = 0;
602 resp->p_chown_restricted = 1;
603 resp->p_case_insensitive = 0;
604 resp->p_case_preserving = 1;
605
606 nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
607
608 if (nfserr == 0) {
609 struct super_block *sb = argp->fh.fh_dentry->d_sb;
610
611 /* Note that we don't care for remote fs's here */
612 switch (sb->s_magic) {
613 case EXT2_SUPER_MAGIC:
614 resp->p_link_max = EXT2_LINK_MAX;
615 resp->p_name_max = EXT2_NAME_LEN;
616 break;
617 case MSDOS_SUPER_MAGIC:
618 resp->p_case_insensitive = 1;
619 resp->p_case_preserving = 0;
620 break;
621 }
622 }
623
624 fh_put(&argp->fh);
625 RETURN_STATUS(nfserr);
626 }
627
628
629 /*
630 * Commit a file (range) to stable storage.
631 */
632 static __be32
633 nfsd3_proc_commit(struct svc_rqst *rqstp)
634 {
635 struct nfsd3_commitargs *argp = rqstp->rq_argp;
636 struct nfsd3_commitres *resp = rqstp->rq_resp;
637 __be32 nfserr;
638
639 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
640 SVCFH_fmt(&argp->fh),
641 argp->count,
642 (unsigned long long) argp->offset);
643
644 if (argp->offset > NFS_OFFSET_MAX)
645 RETURN_STATUS(nfserr_inval);
646
647 fh_copy(&resp->fh, &argp->fh);
648 nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count);
649
650 RETURN_STATUS(nfserr);
651 }
652
653
654 /*
655 * NFSv3 Server procedures.
656 * Only the results of non-idempotent operations are cached.
657 */
658 #define nfs3svc_decode_fhandleargs nfs3svc_decode_fhandle
659 #define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
660 #define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
661 #define nfsd3_mkdirargs nfsd3_createargs
662 #define nfsd3_readdirplusargs nfsd3_readdirargs
663 #define nfsd3_fhandleargs nfsd_fhandle
664 #define nfsd3_fhandleres nfsd3_attrstat
665 #define nfsd3_attrstatres nfsd3_attrstat
666 #define nfsd3_wccstatres nfsd3_attrstat
667 #define nfsd3_createres nfsd3_diropres
668 #define nfsd3_voidres nfsd3_voidargs
669 struct nfsd3_voidargs { int dummy; };
670
671 #define ST 1 /* status*/
672 #define FH 17 /* filehandle with length */
673 #define AT 21 /* attributes */
674 #define pAT (1+AT) /* post attributes - conditional */
675 #define WC (7+pAT) /* WCC attributes */
676
677 static const struct svc_procedure nfsd_procedures3[22] = {
678 [NFS3PROC_NULL] = {
679 .pc_func = nfsd3_proc_null,
680 .pc_encode = nfs3svc_encode_voidres,
681 .pc_argsize = sizeof(struct nfsd3_voidargs),
682 .pc_ressize = sizeof(struct nfsd3_voidres),
683 .pc_cachetype = RC_NOCACHE,
684 .pc_xdrressize = ST,
685 },
686 [NFS3PROC_GETATTR] = {
687 .pc_func = nfsd3_proc_getattr,
688 .pc_decode = nfs3svc_decode_fhandleargs,
689 .pc_encode = nfs3svc_encode_attrstatres,
690 .pc_release = nfs3svc_release_fhandle,
691 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
692 .pc_ressize = sizeof(struct nfsd3_attrstatres),
693 .pc_cachetype = RC_NOCACHE,
694 .pc_xdrressize = ST+AT,
695 },
696 [NFS3PROC_SETATTR] = {
697 .pc_func = nfsd3_proc_setattr,
698 .pc_decode = nfs3svc_decode_sattrargs,
699 .pc_encode = nfs3svc_encode_wccstatres,
700 .pc_release = nfs3svc_release_fhandle,
701 .pc_argsize = sizeof(struct nfsd3_sattrargs),
702 .pc_ressize = sizeof(struct nfsd3_wccstatres),
703 .pc_cachetype = RC_REPLBUFF,
704 .pc_xdrressize = ST+WC,
705 },
706 [NFS3PROC_LOOKUP] = {
707 .pc_func = nfsd3_proc_lookup,
708 .pc_decode = nfs3svc_decode_diropargs,
709 .pc_encode = nfs3svc_encode_diropres,
710 .pc_release = nfs3svc_release_fhandle2,
711 .pc_argsize = sizeof(struct nfsd3_diropargs),
712 .pc_ressize = sizeof(struct nfsd3_diropres),
713 .pc_cachetype = RC_NOCACHE,
714 .pc_xdrressize = ST+FH+pAT+pAT,
715 },
716 [NFS3PROC_ACCESS] = {
717 .pc_func = nfsd3_proc_access,
718 .pc_decode = nfs3svc_decode_accessargs,
719 .pc_encode = nfs3svc_encode_accessres,
720 .pc_release = nfs3svc_release_fhandle,
721 .pc_argsize = sizeof(struct nfsd3_accessargs),
722 .pc_ressize = sizeof(struct nfsd3_accessres),
723 .pc_cachetype = RC_NOCACHE,
724 .pc_xdrressize = ST+pAT+1,
725 },
726 [NFS3PROC_READLINK] = {
727 .pc_func = nfsd3_proc_readlink,
728 .pc_decode = nfs3svc_decode_readlinkargs,
729 .pc_encode = nfs3svc_encode_readlinkres,
730 .pc_release = nfs3svc_release_fhandle,
731 .pc_argsize = sizeof(struct nfsd3_readlinkargs),
732 .pc_ressize = sizeof(struct nfsd3_readlinkres),
733 .pc_cachetype = RC_NOCACHE,
734 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
735 },
736 [NFS3PROC_READ] = {
737 .pc_func = nfsd3_proc_read,
738 .pc_decode = nfs3svc_decode_readargs,
739 .pc_encode = nfs3svc_encode_readres,
740 .pc_release = nfs3svc_release_fhandle,
741 .pc_argsize = sizeof(struct nfsd3_readargs),
742 .pc_ressize = sizeof(struct nfsd3_readres),
743 .pc_cachetype = RC_NOCACHE,
744 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
745 },
746 [NFS3PROC_WRITE] = {
747 .pc_func = nfsd3_proc_write,
748 .pc_decode = nfs3svc_decode_writeargs,
749 .pc_encode = nfs3svc_encode_writeres,
750 .pc_release = nfs3svc_release_fhandle,
751 .pc_argsize = sizeof(struct nfsd3_writeargs),
752 .pc_ressize = sizeof(struct nfsd3_writeres),
753 .pc_cachetype = RC_REPLBUFF,
754 .pc_xdrressize = ST+WC+4,
755 },
756 [NFS3PROC_CREATE] = {
757 .pc_func = nfsd3_proc_create,
758 .pc_decode = nfs3svc_decode_createargs,
759 .pc_encode = nfs3svc_encode_createres,
760 .pc_release = nfs3svc_release_fhandle2,
761 .pc_argsize = sizeof(struct nfsd3_createargs),
762 .pc_ressize = sizeof(struct nfsd3_createres),
763 .pc_cachetype = RC_REPLBUFF,
764 .pc_xdrressize = ST+(1+FH+pAT)+WC,
765 },
766 [NFS3PROC_MKDIR] = {
767 .pc_func = nfsd3_proc_mkdir,
768 .pc_decode = nfs3svc_decode_mkdirargs,
769 .pc_encode = nfs3svc_encode_createres,
770 .pc_release = nfs3svc_release_fhandle2,
771 .pc_argsize = sizeof(struct nfsd3_mkdirargs),
772 .pc_ressize = sizeof(struct nfsd3_createres),
773 .pc_cachetype = RC_REPLBUFF,
774 .pc_xdrressize = ST+(1+FH+pAT)+WC,
775 },
776 [NFS3PROC_SYMLINK] = {
777 .pc_func = nfsd3_proc_symlink,
778 .pc_decode = nfs3svc_decode_symlinkargs,
779 .pc_encode = nfs3svc_encode_createres,
780 .pc_release = nfs3svc_release_fhandle2,
781 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
782 .pc_ressize = sizeof(struct nfsd3_createres),
783 .pc_cachetype = RC_REPLBUFF,
784 .pc_xdrressize = ST+(1+FH+pAT)+WC,
785 },
786 [NFS3PROC_MKNOD] = {
787 .pc_func = nfsd3_proc_mknod,
788 .pc_decode = nfs3svc_decode_mknodargs,
789 .pc_encode = nfs3svc_encode_createres,
790 .pc_release = nfs3svc_release_fhandle2,
791 .pc_argsize = sizeof(struct nfsd3_mknodargs),
792 .pc_ressize = sizeof(struct nfsd3_createres),
793 .pc_cachetype = RC_REPLBUFF,
794 .pc_xdrressize = ST+(1+FH+pAT)+WC,
795 },
796 [NFS3PROC_REMOVE] = {
797 .pc_func = nfsd3_proc_remove,
798 .pc_decode = nfs3svc_decode_diropargs,
799 .pc_encode = nfs3svc_encode_wccstatres,
800 .pc_release = nfs3svc_release_fhandle,
801 .pc_argsize = sizeof(struct nfsd3_diropargs),
802 .pc_ressize = sizeof(struct nfsd3_wccstatres),
803 .pc_cachetype = RC_REPLBUFF,
804 .pc_xdrressize = ST+WC,
805 },
806 [NFS3PROC_RMDIR] = {
807 .pc_func = nfsd3_proc_rmdir,
808 .pc_decode = nfs3svc_decode_diropargs,
809 .pc_encode = nfs3svc_encode_wccstatres,
810 .pc_release = nfs3svc_release_fhandle,
811 .pc_argsize = sizeof(struct nfsd3_diropargs),
812 .pc_ressize = sizeof(struct nfsd3_wccstatres),
813 .pc_cachetype = RC_REPLBUFF,
814 .pc_xdrressize = ST+WC,
815 },
816 [NFS3PROC_RENAME] = {
817 .pc_func = nfsd3_proc_rename,
818 .pc_decode = nfs3svc_decode_renameargs,
819 .pc_encode = nfs3svc_encode_renameres,
820 .pc_release = nfs3svc_release_fhandle2,
821 .pc_argsize = sizeof(struct nfsd3_renameargs),
822 .pc_ressize = sizeof(struct nfsd3_renameres),
823 .pc_cachetype = RC_REPLBUFF,
824 .pc_xdrressize = ST+WC+WC,
825 },
826 [NFS3PROC_LINK] = {
827 .pc_func = nfsd3_proc_link,
828 .pc_decode = nfs3svc_decode_linkargs,
829 .pc_encode = nfs3svc_encode_linkres,
830 .pc_release = nfs3svc_release_fhandle2,
831 .pc_argsize = sizeof(struct nfsd3_linkargs),
832 .pc_ressize = sizeof(struct nfsd3_linkres),
833 .pc_cachetype = RC_REPLBUFF,
834 .pc_xdrressize = ST+pAT+WC,
835 },
836 [NFS3PROC_READDIR] = {
837 .pc_func = nfsd3_proc_readdir,
838 .pc_decode = nfs3svc_decode_readdirargs,
839 .pc_encode = nfs3svc_encode_readdirres,
840 .pc_release = nfs3svc_release_fhandle,
841 .pc_argsize = sizeof(struct nfsd3_readdirargs),
842 .pc_ressize = sizeof(struct nfsd3_readdirres),
843 .pc_cachetype = RC_NOCACHE,
844 },
845 [NFS3PROC_READDIRPLUS] = {
846 .pc_func = nfsd3_proc_readdirplus,
847 .pc_decode = nfs3svc_decode_readdirplusargs,
848 .pc_encode = nfs3svc_encode_readdirres,
849 .pc_release = nfs3svc_release_fhandle,
850 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
851 .pc_ressize = sizeof(struct nfsd3_readdirres),
852 .pc_cachetype = RC_NOCACHE,
853 },
854 [NFS3PROC_FSSTAT] = {
855 .pc_func = nfsd3_proc_fsstat,
856 .pc_decode = nfs3svc_decode_fhandleargs,
857 .pc_encode = nfs3svc_encode_fsstatres,
858 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
859 .pc_ressize = sizeof(struct nfsd3_fsstatres),
860 .pc_cachetype = RC_NOCACHE,
861 .pc_xdrressize = ST+pAT+2*6+1,
862 },
863 [NFS3PROC_FSINFO] = {
864 .pc_func = nfsd3_proc_fsinfo,
865 .pc_decode = nfs3svc_decode_fhandleargs,
866 .pc_encode = nfs3svc_encode_fsinfores,
867 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
868 .pc_ressize = sizeof(struct nfsd3_fsinfores),
869 .pc_cachetype = RC_NOCACHE,
870 .pc_xdrressize = ST+pAT+12,
871 },
872 [NFS3PROC_PATHCONF] = {
873 .pc_func = nfsd3_proc_pathconf,
874 .pc_decode = nfs3svc_decode_fhandleargs,
875 .pc_encode = nfs3svc_encode_pathconfres,
876 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
877 .pc_ressize = sizeof(struct nfsd3_pathconfres),
878 .pc_cachetype = RC_NOCACHE,
879 .pc_xdrressize = ST+pAT+6,
880 },
881 [NFS3PROC_COMMIT] = {
882 .pc_func = nfsd3_proc_commit,
883 .pc_decode = nfs3svc_decode_commitargs,
884 .pc_encode = nfs3svc_encode_commitres,
885 .pc_release = nfs3svc_release_fhandle,
886 .pc_argsize = sizeof(struct nfsd3_commitargs),
887 .pc_ressize = sizeof(struct nfsd3_commitres),
888 .pc_cachetype = RC_NOCACHE,
889 .pc_xdrressize = ST+WC+2,
890 },
891 };
892
893 static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
894 const struct svc_version nfsd_version3 = {
895 .vs_vers = 3,
896 .vs_nproc = 22,
897 .vs_proc = nfsd_procedures3,
898 .vs_dispatch = nfsd_dispatch,
899 .vs_count = nfsd_count3,
900 .vs_xdrsize = NFS3_SVC_XDRSIZE,
901 };