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