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