ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / nfsd / nfs3proc.c
1 /*
2  * linux/fs/nfsd/nfs3proc.c
3  *
4  * Process version 3 NFS requests.
5  *
6  * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #include <linux/linkage.h>
10 #include <linux/time.h>
11 #include <linux/errno.h>
12 #include <linux/fs.h>
13 #include <linux/ext2_fs.h>
14 #include <linux/stat.h>
15 #include <linux/fcntl.h>
16 #include <linux/net.h>
17 #include <linux/in.h>
18 #include <linux/unistd.h>
19 #include <linux/slab.h>
20 #include <linux/major.h>
21
22 #include <linux/sunrpc/svc.h>
23 #include <linux/nfsd/nfsd.h>
24 #include <linux/nfsd/cache.h>
25 #include <linux/nfsd/xdr3.h>
26 #include <linux/nfs3.h>
27
28 #define NFSDDBG_FACILITY                NFSDDBG_PROC
29
30 #define RETURN_STATUS(st)       { resp->status = (st); return (st); }
31
32 static int      nfs3_ftypes[] = {
33         0,                      /* NF3NON */
34         S_IFREG,                /* NF3REG */
35         S_IFDIR,                /* NF3DIR */
36         S_IFBLK,                /* NF3BLK */
37         S_IFCHR,                /* NF3CHR */
38         S_IFLNK,                /* NF3LNK */
39         S_IFSOCK,               /* NF3SOCK */
40         S_IFIFO,                /* NF3FIFO */
41 };
42
43 /*
44  * NULL call.
45  */
46 static int
47 nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
48 {
49         return nfs_ok;
50 }
51
52 /*
53  * Get a file's attributes
54  */
55 static int
56 nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle  *argp,
57                                            struct nfsd3_attrstat *resp)
58 {
59         int     nfserr;
60
61         dprintk("nfsd: GETATTR(3)  %s\n",
62                                 SVCFH_fmt(&argp->fh));
63
64         fh_copy(&resp->fh, &argp->fh);
65         nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_NOP);
66         RETURN_STATUS(nfserr);
67 }
68
69 /*
70  * Set a file's attributes
71  */
72 static int
73 nfsd3_proc_setattr(struct svc_rqst *rqstp, struct nfsd3_sattrargs *argp,
74                                            struct nfsd3_attrstat  *resp)
75 {
76         int     nfserr;
77
78         dprintk("nfsd: SETATTR(3)  %s\n",
79                                 SVCFH_fmt(&argp->fh));
80
81         fh_copy(&resp->fh, &argp->fh);
82         nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
83                               argp->check_guard, argp->guardtime);
84         RETURN_STATUS(nfserr);
85 }
86
87 /*
88  * Look up a path name component
89  */
90 static int
91 nfsd3_proc_lookup(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
92                                           struct nfsd3_diropres  *resp)
93 {
94         int     nfserr;
95
96         dprintk("nfsd: LOOKUP(3)   %s %.*s\n",
97                                 SVCFH_fmt(&argp->fh),
98                                 argp->len,
99                                 argp->name);
100
101         fh_copy(&resp->dirfh, &argp->fh);
102         fh_init(&resp->fh, NFS3_FHSIZE);
103
104         nfserr = nfsd_lookup(rqstp, &resp->dirfh,
105                                     argp->name,
106                                     argp->len,
107                                     &resp->fh);
108         RETURN_STATUS(nfserr);
109 }
110
111 /*
112  * Check file access
113  */
114 static int
115 nfsd3_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
116                                           struct nfsd3_accessres *resp)
117 {
118         int     nfserr;
119
120         dprintk("nfsd: ACCESS(3)   %s 0x%x\n",
121                                 SVCFH_fmt(&argp->fh),
122                                 argp->access);
123
124         fh_copy(&resp->fh, &argp->fh);
125         resp->access = argp->access;
126         nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
127         RETURN_STATUS(nfserr);
128 }
129
130 /*
131  * Read a symlink.
132  */
133 static int
134 nfsd3_proc_readlink(struct svc_rqst *rqstp, struct nfsd3_readlinkargs *argp,
135                                            struct nfsd3_readlinkres *resp)
136 {
137         int nfserr;
138
139         dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));
140
141         /* Read the symlink. */
142         fh_copy(&resp->fh, &argp->fh);
143         resp->len = NFS3_MAXPATHLEN;
144         nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
145         RETURN_STATUS(nfserr);
146 }
147
148 /*
149  * Read a portion of a file.
150  */
151 static int
152 nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
153                                         struct nfsd3_readres  *resp)
154 {
155         int     nfserr;
156
157         dprintk("nfsd: READ(3) %s %lu bytes at %lu\n",
158                                 SVCFH_fmt(&argp->fh),
159                                 (unsigned long) argp->count,
160                                 (unsigned long) argp->offset);
161
162         /* Obtain buffer pointer for payload.
163          * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
164          * + 1 (xdr opaque byte count) = 26
165          */
166
167         resp->count = argp->count;
168         if (NFSSVC_MAXBLKSIZE < resp->count)
169                 resp->count = NFSSVC_MAXBLKSIZE;
170
171         svc_reserve(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
172
173         fh_copy(&resp->fh, &argp->fh);
174         nfserr = nfsd_read(rqstp, &resp->fh,
175                                   argp->offset,
176                                   argp->vec, argp->vlen,
177                                   &resp->count);
178         if (nfserr == 0) {
179                 struct inode    *inode = resp->fh.fh_dentry->d_inode;
180
181                 resp->eof = (argp->offset + resp->count) >= inode->i_size;
182         }
183
184         RETURN_STATUS(nfserr);
185 }
186
187 /*
188  * Write data to a file
189  */
190 static int
191 nfsd3_proc_write(struct svc_rqst *rqstp, struct nfsd3_writeargs *argp,
192                                          struct nfsd3_writeres  *resp)
193 {
194         int     nfserr;
195
196         dprintk("nfsd: WRITE(3)    %s %d bytes at %ld%s\n",
197                                 SVCFH_fmt(&argp->fh),
198                                 argp->len,
199                                 (unsigned long) argp->offset,
200                                 argp->stable? " stable" : "");
201
202         fh_copy(&resp->fh, &argp->fh);
203         resp->committed = argp->stable;
204         nfserr = nfsd_write(rqstp, &resp->fh,
205                                    argp->offset,
206                                    argp->vec, argp->vlen,
207                                    argp->len,
208                                    &resp->committed);
209         resp->count = argp->count;
210         RETURN_STATUS(nfserr);
211 }
212
213 /*
214  * With NFSv3, CREATE processing is a lot easier than with NFSv2.
215  * At least in theory; we'll see how it fares in practice when the
216  * first reports about SunOS compatibility problems start to pour in...
217  */
218 static int
219 nfsd3_proc_create(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
220                                           struct nfsd3_diropres   *resp)
221 {
222         svc_fh          *dirfhp, *newfhp = NULL;
223         struct iattr    *attr;
224         u32             nfserr;
225
226         dprintk("nfsd: CREATE(3)   %s %.*s\n",
227                                 SVCFH_fmt(&argp->fh),
228                                 argp->len,
229                                 argp->name);
230
231         dirfhp = fh_copy(&resp->dirfh, &argp->fh);
232         newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
233         attr   = &argp->attrs;
234
235         /* Get the directory inode */
236         nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, MAY_CREATE);
237         if (nfserr)
238                 RETURN_STATUS(nfserr);
239
240         /* Unfudge the mode bits */
241         attr->ia_mode &= ~S_IFMT;
242         if (!(attr->ia_valid & ATTR_MODE)) { 
243                 attr->ia_valid |= ATTR_MODE;
244                 attr->ia_mode = S_IFREG;
245         } else {
246                 attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
247         }
248
249         /* Now create the file and set attributes */
250         nfserr = nfsd_create_v3(rqstp, dirfhp, argp->name, argp->len,
251                                 attr, newfhp,
252                                 argp->createmode, argp->verf, NULL);
253
254         RETURN_STATUS(nfserr);
255 }
256
257 /*
258  * Make directory. This operation is not idempotent.
259  */
260 static int
261 nfsd3_proc_mkdir(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
262                                          struct nfsd3_diropres   *resp)
263 {
264         int     nfserr;
265
266         dprintk("nfsd: MKDIR(3)    %s %.*s\n",
267                                 SVCFH_fmt(&argp->fh),
268                                 argp->len,
269                                 argp->name);
270
271         argp->attrs.ia_valid &= ~ATTR_SIZE;
272         fh_copy(&resp->dirfh, &argp->fh);
273         fh_init(&resp->fh, NFS3_FHSIZE);
274         nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
275                                     &argp->attrs, S_IFDIR, 0, &resp->fh);
276
277         RETURN_STATUS(nfserr);
278 }
279
280 static int
281 nfsd3_proc_symlink(struct svc_rqst *rqstp, struct nfsd3_symlinkargs *argp,
282                                            struct nfsd3_diropres    *resp)
283 {
284         int     nfserr;
285
286         dprintk("nfsd: SYMLINK(3)  %s %.*s -> %.*s\n",
287                                 SVCFH_fmt(&argp->ffh),
288                                 argp->flen, argp->fname,
289                                 argp->tlen, argp->tname);
290
291         fh_copy(&resp->dirfh, &argp->ffh);
292         fh_init(&resp->fh, NFS3_FHSIZE);
293         nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen,
294                                                    argp->tname, argp->tlen,
295                                                    &resp->fh, &argp->attrs);
296         RETURN_STATUS(nfserr);
297 }
298
299 /*
300  * Make socket/fifo/device.
301  */
302 static int
303 nfsd3_proc_mknod(struct svc_rqst *rqstp, struct nfsd3_mknodargs *argp,
304                                          struct nfsd3_diropres  *resp)
305 {
306         int     nfserr, type;
307         dev_t   rdev = 0;
308
309         dprintk("nfsd: MKNOD(3)    %s %.*s\n",
310                                 SVCFH_fmt(&argp->fh),
311                                 argp->len,
312                                 argp->name);
313
314         fh_copy(&resp->dirfh, &argp->fh);
315         fh_init(&resp->fh, NFS3_FHSIZE);
316
317         if (argp->ftype == 0 || argp->ftype >= NF3BAD)
318                 RETURN_STATUS(nfserr_inval);
319         if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
320                 rdev = MKDEV(argp->major, argp->minor);
321                 if (MAJOR(rdev) != argp->major ||
322                     MINOR(rdev) != argp->minor)
323                         RETURN_STATUS(nfserr_inval);
324         } else
325                 if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO)
326                         RETURN_STATUS(nfserr_inval);
327
328         type = nfs3_ftypes[argp->ftype];
329         nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
330                                     &argp->attrs, type, rdev, &resp->fh);
331
332         RETURN_STATUS(nfserr);
333 }
334
335 /*
336  * Remove file/fifo/socket etc.
337  */
338 static int
339 nfsd3_proc_remove(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
340                                           struct nfsd3_attrstat  *resp)
341 {
342         int     nfserr;
343
344         dprintk("nfsd: REMOVE(3)   %s %.*s\n",
345                                 SVCFH_fmt(&argp->fh),
346                                 argp->len,
347                                 argp->name);
348
349         /* Unlink. -S_IFDIR means file must not be a directory */
350         fh_copy(&resp->fh, &argp->fh);
351         nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
352         RETURN_STATUS(nfserr);
353 }
354
355 /*
356  * Remove a directory
357  */
358 static int
359 nfsd3_proc_rmdir(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
360                                          struct nfsd3_attrstat  *resp)
361 {
362         int     nfserr;
363
364         dprintk("nfsd: RMDIR(3)    %s %.*s\n",
365                                 SVCFH_fmt(&argp->fh),
366                                 argp->len,
367                                 argp->name);
368
369         fh_copy(&resp->fh, &argp->fh);
370         nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
371         RETURN_STATUS(nfserr);
372 }
373
374 static int
375 nfsd3_proc_rename(struct svc_rqst *rqstp, struct nfsd3_renameargs *argp,
376                                           struct nfsd3_renameres  *resp)
377 {
378         int     nfserr;
379
380         dprintk("nfsd: RENAME(3)   %s %.*s ->\n",
381                                 SVCFH_fmt(&argp->ffh),
382                                 argp->flen,
383                                 argp->fname);
384         dprintk("nfsd: -> %s %.*s\n",
385                                 SVCFH_fmt(&argp->tfh),
386                                 argp->tlen,
387                                 argp->tname);
388
389         fh_copy(&resp->ffh, &argp->ffh);
390         fh_copy(&resp->tfh, &argp->tfh);
391         nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
392                                     &resp->tfh, argp->tname, argp->tlen);
393         RETURN_STATUS(nfserr);
394 }
395
396 static int
397 nfsd3_proc_link(struct svc_rqst *rqstp, struct nfsd3_linkargs *argp,
398                                         struct nfsd3_linkres  *resp)
399 {
400         int     nfserr;
401
402         dprintk("nfsd: LINK(3)     %s ->\n",
403                                 SVCFH_fmt(&argp->ffh));
404         dprintk("nfsd:   -> %s %.*s\n",
405                                 SVCFH_fmt(&argp->tfh),
406                                 argp->tlen,
407                                 argp->tname);
408
409         fh_copy(&resp->fh,  &argp->ffh);
410         fh_copy(&resp->tfh, &argp->tfh);
411         nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
412                                   &resp->fh);
413         RETURN_STATUS(nfserr);
414 }
415
416 /*
417  * Read a portion of a directory.
418  */
419 static int
420 nfsd3_proc_readdir(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp,
421                                            struct nfsd3_readdirres  *resp)
422 {
423         int             nfserr, count;
424
425         dprintk("nfsd: READDIR(3)  %s %d bytes at %d\n",
426                                 SVCFH_fmt(&argp->fh),
427                                 argp->count, (u32) argp->cookie);
428
429         /* Make sure we've room for the NULL ptr & eof flag, and shrink to
430          * client read size */
431         count = (argp->count >> 2) - 2;
432
433         /* Read directory and encode entries on the fly */
434         fh_copy(&resp->fh, &argp->fh);
435
436         resp->buflen = count;
437         resp->common.err = nfs_ok;
438         resp->buffer = argp->buffer;
439         resp->offset = NULL;
440         resp->rqstp = rqstp;
441         nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie, 
442                                         &resp->common, nfs3svc_encode_entry);
443         memcpy(resp->verf, argp->verf, 8);
444         resp->count = resp->buffer - argp->buffer;
445         if (resp->offset)
446                 xdr_encode_hyper(resp->offset, argp->cookie);
447
448         RETURN_STATUS(nfserr);
449 }
450
451 /*
452  * Read a portion of a directory, including file handles and attrs.
453  * For now, we choose to ignore the dircount parameter.
454  */
455 static int
456 nfsd3_proc_readdirplus(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp,
457                                                struct nfsd3_readdirres  *resp)
458 {
459         int     nfserr, count = 0;
460         loff_t  offset;
461         int     i;
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         nfserr = nfsd_readdir(rqstp, &resp->fh,
481                                      &offset,
482                                      &resp->common,
483                                      nfs3svc_encode_entry_plus);
484         memcpy(resp->verf, argp->verf, 8);
485         for (i=1; i<rqstp->rq_resused ; i++) {
486                 page_addr = page_address(rqstp->rq_respages[i]);
487
488                 if (((caddr_t)resp->buffer >= page_addr) &&
489                     ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
490                         count += (caddr_t)resp->buffer - page_addr;
491                         break;
492                 }
493                 count += PAGE_SIZE;
494         }
495         resp->count = count >> 2;
496         if (resp->offset)
497                 xdr_encode_hyper(resp->offset, offset);
498
499         RETURN_STATUS(nfserr);
500 }
501
502 /*
503  * Get file system stats
504  */
505 static int
506 nfsd3_proc_fsstat(struct svc_rqst * rqstp, struct nfsd_fhandle    *argp,
507                                            struct nfsd3_fsstatres *resp)
508 {
509         int     nfserr;
510
511         dprintk("nfsd: FSSTAT(3)   %s\n",
512                                 SVCFH_fmt(&argp->fh));
513
514         nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats);
515         fh_put(&argp->fh);
516         RETURN_STATUS(nfserr);
517 }
518
519 /*
520  * Get file system info
521  */
522 static int
523 nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle    *argp,
524                                            struct nfsd3_fsinfores *resp)
525 {
526         int     nfserr;
527
528         dprintk("nfsd: FSINFO(3)   %s\n",
529                                 SVCFH_fmt(&argp->fh));
530
531         resp->f_rtmax  = NFSSVC_MAXBLKSIZE;
532         resp->f_rtpref = NFSSVC_MAXBLKSIZE;
533         resp->f_rtmult = PAGE_SIZE;
534         resp->f_wtmax  = NFSSVC_MAXBLKSIZE;
535         resp->f_wtpref = NFSSVC_MAXBLKSIZE;
536         resp->f_wtmult = PAGE_SIZE;
537         resp->f_dtpref = PAGE_SIZE;
538         resp->f_maxfilesize = ~(u32) 0;
539         resp->f_properties = NFS3_FSF_DEFAULT;
540
541         nfserr = fh_verify(rqstp, &argp->fh, 0, MAY_NOP);
542
543         /* Check special features of the file system. May request
544          * different read/write sizes for file systems known to have
545          * problems with large blocks */
546         if (nfserr == 0) {
547                 struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb;
548
549                 /* Note that we don't care for remote fs's here */
550                 if (sb->s_magic == 0x4d44 /* MSDOS_SUPER_MAGIC */) {
551                         resp->f_properties = NFS3_FSF_BILLYBOY;
552                 }
553                 resp->f_maxfilesize = sb->s_maxbytes;
554         }
555
556         fh_put(&argp->fh);
557         RETURN_STATUS(nfserr);
558 }
559
560 /*
561  * Get pathconf info for the specified file
562  */
563 static int
564 nfsd3_proc_pathconf(struct svc_rqst * rqstp, struct nfsd_fhandle      *argp,
565                                              struct nfsd3_pathconfres *resp)
566 {
567         int     nfserr;
568
569         dprintk("nfsd: PATHCONF(3) %s\n",
570                                 SVCFH_fmt(&argp->fh));
571
572         /* Set default pathconf */
573         resp->p_link_max = 255;         /* at least */
574         resp->p_name_max = 255;         /* at least */
575         resp->p_no_trunc = 0;
576         resp->p_chown_restricted = 1;
577         resp->p_case_insensitive = 0;
578         resp->p_case_preserving = 1;
579
580         nfserr = fh_verify(rqstp, &argp->fh, 0, MAY_NOP);
581
582         if (nfserr == 0) {
583                 struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb;
584
585                 /* Note that we don't care for remote fs's here */
586                 switch (sb->s_magic) {
587                 case EXT2_SUPER_MAGIC:
588                         resp->p_link_max = EXT2_LINK_MAX;
589                         resp->p_name_max = EXT2_NAME_LEN;
590                         break;
591                 case 0x4d44:    /* MSDOS_SUPER_MAGIC */
592                         resp->p_case_insensitive = 1;
593                         resp->p_case_preserving  = 0;
594                         break;
595                 }
596         }
597
598         fh_put(&argp->fh);
599         RETURN_STATUS(nfserr);
600 }
601
602
603 /*
604  * Commit a file (range) to stable storage.
605  */
606 static int
607 nfsd3_proc_commit(struct svc_rqst * rqstp, struct nfsd3_commitargs *argp,
608                                            struct nfsd3_commitres  *resp)
609 {
610         int     nfserr;
611
612         dprintk("nfsd: COMMIT(3)   %s %u@%Lu\n",
613                                 SVCFH_fmt(&argp->fh),
614                                 argp->count,
615                                 (unsigned long long) argp->offset);
616
617         if (argp->offset > NFS_OFFSET_MAX)
618                 RETURN_STATUS(nfserr_inval);
619
620         fh_copy(&resp->fh, &argp->fh);
621         nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count);
622
623         RETURN_STATUS(nfserr);
624 }
625
626
627 /*
628  * NFSv3 Server procedures.
629  * Only the results of non-idempotent operations are cached.
630  */
631 #define nfs3svc_decode_voidargs         NULL
632 #define nfs3svc_release_void            NULL
633 #define nfs3svc_decode_fhandleargs      nfs3svc_decode_fhandle
634 #define nfs3svc_encode_attrstatres      nfs3svc_encode_attrstat
635 #define nfs3svc_encode_wccstatres       nfs3svc_encode_wccstat
636 #define nfsd3_mkdirargs                 nfsd3_createargs
637 #define nfsd3_readdirplusargs           nfsd3_readdirargs
638 #define nfsd3_fhandleargs               nfsd_fhandle
639 #define nfsd3_fhandleres                nfsd3_attrstat
640 #define nfsd3_attrstatres               nfsd3_attrstat
641 #define nfsd3_wccstatres                nfsd3_attrstat
642 #define nfsd3_createres                 nfsd3_diropres
643 #define nfsd3_voidres                   nfsd3_voidargs
644 struct nfsd3_voidargs { int dummy; };
645
646 #define PROC(name, argt, rest, relt, cache, respsize)   \
647  { (svc_procfunc) nfsd3_proc_##name,            \
648    (kxdrproc_t) nfs3svc_decode_##argt##args,    \
649    (kxdrproc_t) nfs3svc_encode_##rest##res,     \
650    (kxdrproc_t) nfs3svc_release_##relt,         \
651    sizeof(struct nfsd3_##argt##args),           \
652    sizeof(struct nfsd3_##rest##res),            \
653    0,                                           \
654    cache,                                       \
655    respsize,                                    \
656  }
657
658 #define ST 1            /* status*/
659 #define FH 17           /* filehandle with length */
660 #define AT 21           /* attributes */
661 #define pAT (1+AT)      /* post attributes - conditional */
662 #define WC (7+pAT)      /* WCC attributes */
663
664 static struct svc_procedure             nfsd_procedures3[22] = {
665   PROC(null,     void,          void,           void,     RC_NOCACHE, ST),
666   PROC(getattr,  fhandle,       attrstat,       fhandle,  RC_NOCACHE, ST+AT),
667   PROC(setattr,  sattr,         wccstat,        fhandle,  RC_REPLBUFF, ST+WC),
668   PROC(lookup,   dirop,         dirop,          fhandle2, RC_NOCACHE, ST+FH+pAT+pAT),
669   PROC(access,   access,        access,         fhandle,  RC_NOCACHE, ST+pAT+1),
670   PROC(readlink, readlink,      readlink,       fhandle,  RC_NOCACHE, ST+pAT+1+NFS3_MAXPATHLEN/4),
671   PROC(read,     read,          read,           fhandle,  RC_NOCACHE, ST+pAT+4+NFSSVC_MAXBLKSIZE),
672   PROC(write,    write,         write,          fhandle,  RC_REPLBUFF, ST+WC+4),
673   PROC(create,   create,        create,         fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
674   PROC(mkdir,    mkdir,         create,         fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
675   PROC(symlink,  symlink,       create,         fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
676   PROC(mknod,    mknod,         create,         fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
677   PROC(remove,   dirop,         wccstat,        fhandle,  RC_REPLBUFF, ST+WC),
678   PROC(rmdir,    dirop,         wccstat,        fhandle,  RC_REPLBUFF, ST+WC),
679   PROC(rename,   rename,        rename,         fhandle2, RC_REPLBUFF, ST+WC+WC),
680   PROC(link,     link,          link,           fhandle2, RC_REPLBUFF, ST+pAT+WC),
681   PROC(readdir,  readdir,       readdir,        fhandle,  RC_NOCACHE, 0),
682   PROC(readdirplus,readdirplus, readdir,        fhandle,  RC_NOCACHE, 0),
683   PROC(fsstat,   fhandle,       fsstat,         void,     RC_NOCACHE, ST+pAT+2*6+1),
684   PROC(fsinfo,   fhandle,       fsinfo,         void,     RC_NOCACHE, ST+pAT+12),
685   PROC(pathconf, fhandle,       pathconf,       void,     RC_NOCACHE, ST+pAT+6),
686   PROC(commit,   commit,        commit,         fhandle,  RC_NOCACHE, ST+WC+2),
687 };
688
689 struct svc_version      nfsd_version3 = {
690                 .vs_vers        = 3,
691                 .vs_nproc       = 22,
692                 .vs_proc        = nfsd_procedures3,
693                 .vs_dispatch    = nfsd_dispatch,
694                 .vs_xdrsize     = NFS3_SVC_XDRSIZE,
695 };