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