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