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