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