]> git.ipfire.org Git - people/ms/linux.git/blame - fs/nfsd/nfs3proc.c
SUNRPC: Fix general protection fault in trace_rpc_xdr_overflow()
[people/ms/linux.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
1da177e4
LT
18static 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 */
7111c66e 32static __be32
a6beb732 33nfsd3_proc_null(struct svc_rqst *rqstp)
1da177e4 34{
cc028a10 35 return rpc_success;
1da177e4
LT
36}
37
38/*
39 * Get a file's attributes
40 */
7111c66e 41static __be32
a6beb732 42nfsd3_proc_getattr(struct svc_rqst *rqstp)
1da177e4 43{
a6beb732
CH
44 struct nfsd_fhandle *argp = rqstp->rq_argp;
45 struct nfsd3_attrstat *resp = rqstp->rq_resp;
1da177e4
LT
46
47 dprintk("nfsd: GETATTR(3) %s\n",
a334de28 48 SVCFH_fmt(&argp->fh));
1da177e4
LT
49
50 fh_copy(&resp->fh, &argp->fh);
14168d67
CL
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);
57out:
cc028a10 58 return rpc_success;
1da177e4
LT
59}
60
61/*
62 * Set a file's attributes
63 */
7111c66e 64static __be32
a6beb732 65nfsd3_proc_setattr(struct svc_rqst *rqstp)
1da177e4 66{
a6beb732
CH
67 struct nfsd3_sattrargs *argp = rqstp->rq_argp;
68 struct nfsd3_attrstat *resp = rqstp->rq_resp;
1da177e4
LT
69
70 dprintk("nfsd: SETATTR(3) %s\n",
71 SVCFH_fmt(&argp->fh));
72
73 fh_copy(&resp->fh, &argp->fh);
14168d67
CL
74 resp->status = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
75 argp->check_guard, argp->guardtime);
cc028a10 76 return rpc_success;
1da177e4
LT
77}
78
79/*
80 * Look up a path name component
81 */
7111c66e 82static __be32
a6beb732 83nfsd3_proc_lookup(struct svc_rqst *rqstp)
1da177e4 84{
a6beb732
CH
85 struct nfsd3_diropargs *argp = rqstp->rq_argp;
86 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4
LT
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
14168d67
CL
96 resp->status = nfsd_lookup(rqstp, &resp->dirfh,
97 argp->name, argp->len,
98 &resp->fh);
cc028a10 99 return rpc_success;
1da177e4
LT
100}
101
102/*
103 * Check file access
104 */
7111c66e 105static __be32
a6beb732 106nfsd3_proc_access(struct svc_rqst *rqstp)
1da177e4 107{
a6beb732
CH
108 struct nfsd3_accessargs *argp = rqstp->rq_argp;
109 struct nfsd3_accessres *resp = rqstp->rq_resp;
1da177e4
LT
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;
14168d67 117 resp->status = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
cc028a10 118 return rpc_success;
1da177e4
LT
119}
120
121/*
122 * Read a symlink.
123 */
7111c66e 124static __be32
a6beb732 125nfsd3_proc_readlink(struct svc_rqst *rqstp)
1da177e4 126{
a6beb732
CH
127 struct nfsd3_readlinkargs *argp = rqstp->rq_argp;
128 struct nfsd3_readlinkres *resp = rqstp->rq_resp;
1da177e4
LT
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;
14168d67 135 resp->status = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
cc028a10 136 return rpc_success;
1da177e4
LT
137}
138
139/*
140 * Read a portion of a file.
141 */
7111c66e 142static __be32
a6beb732 143nfsd3_proc_read(struct svc_rqst *rqstp)
1da177e4 144{
a6beb732
CH
145 struct nfsd3_readargs *argp = rqstp->rq_argp;
146 struct nfsd3_readres *resp = rqstp->rq_resp;
7adae489 147 u32 max_blocksize = svc_max_payload(rqstp);
ac503e4a 148 unsigned long cnt = min(argp->count, max_blocksize);
1da177e4 149
18b631f8 150 dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
1da177e4
LT
151 SVCFH_fmt(&argp->fh),
152 (unsigned long) argp->count,
18b631f8 153 (unsigned long long) argp->offset);
1da177e4
LT
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 */
ac503e4a 159 resp->count = cnt;
cd123012 160 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
1da177e4
LT
161
162 fh_copy(&resp->fh, &argp->fh);
14168d67
CL
163 resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
164 rqstp->rq_vec, argp->vlen, &resp->count,
165 &resp->eof);
cc028a10 166 return rpc_success;
1da177e4
LT
167}
168
169/*
170 * Write data to a file
171 */
7111c66e 172static __be32
a6beb732 173nfsd3_proc_write(struct svc_rqst *rqstp)
1da177e4 174{
a6beb732
CH
175 struct nfsd3_writeargs *argp = rqstp->rq_argp;
176 struct nfsd3_writeres *resp = rqstp->rq_resp;
31dec253 177 unsigned long cnt = argp->len;
8154ef27 178 unsigned int nvecs;
1da177e4 179
18b631f8 180 dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
1da177e4
LT
181 SVCFH_fmt(&argp->fh),
182 argp->len,
18b631f8 183 (unsigned long long) argp->offset,
1da177e4
LT
184 argp->stable? " stable" : "");
185
186 fh_copy(&resp->fh, &argp->fh);
187 resp->committed = argp->stable;
3fd9557a
CL
188 nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
189 &argp->first, cnt);
14168d67
CL
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);
31dec253 197 resp->count = cnt;
14168d67 198out:
cc028a10 199 return rpc_success;
1da177e4
LT
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 */
7111c66e 207static __be32
a6beb732 208nfsd3_proc_create(struct svc_rqst *rqstp)
1da177e4 209{
a6beb732
CH
210 struct nfsd3_createargs *argp = rqstp->rq_argp;
211 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4
LT
212 svc_fh *dirfhp, *newfhp = NULL;
213 struct iattr *attr;
1da177e4
LT
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
1da177e4
LT
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 */
14168d67
CL
234 resp->status = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
235 attr, newfhp, argp->createmode,
236 (u32 *)argp->verf, NULL, NULL);
cc028a10 237 return rpc_success;
1da177e4
LT
238}
239
240/*
241 * Make directory. This operation is not idempotent.
242 */
7111c66e 243static __be32
a6beb732 244nfsd3_proc_mkdir(struct svc_rqst *rqstp)
1da177e4 245{
a6beb732
CH
246 struct nfsd3_createargs *argp = rqstp->rq_argp;
247 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
257 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
258 &argp->attrs, S_IFDIR, 0, &resp->fh);
43a9aa64 259 fh_unlock(&resp->dirfh);
cc028a10 260 return rpc_success;
1da177e4
LT
261}
262
7111c66e 263static __be32
a6beb732 264nfsd3_proc_symlink(struct svc_rqst *rqstp)
1da177e4 265{
a6beb732
CH
266 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
267 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4 268
14168d67
CL
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 }
38a70315
CL
277
278 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
11b4d66e 279 page_address(rqstp->rq_arg.pages[0]),
38a70315 280 argp->tlen);
14168d67
CL
281 if (IS_ERR(argp->tname)) {
282 resp->status = nfserrno(PTR_ERR(argp->tname));
283 goto out;
284 }
38a70315 285
1da177e4
LT
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);
14168d67
CL
293 resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
294 argp->flen, argp->tname, &resp->fh);
11b4d66e 295 kfree(argp->tname);
14168d67 296out:
cc028a10 297 return rpc_success;
1da177e4
LT
298}
299
300/*
301 * Make socket/fifo/device.
302 */
7111c66e 303static __be32
a6beb732 304nfsd3_proc_mknod(struct svc_rqst *rqstp)
1da177e4 305{
a6beb732
CH
306 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
307 struct nfsd3_diropres *resp = rqstp->rq_resp;
c4d987ba 308 int type;
1da177e4
LT
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
14168d67
CL
319 if (argp->ftype == 0 || argp->ftype >= NF3BAD) {
320 resp->status = nfserr_inval;
321 goto out;
322 }
1da177e4
LT
323 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
324 rdev = MKDEV(argp->major, argp->minor);
325 if (MAJOR(rdev) != argp->major ||
14168d67
CL
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 }
1da177e4
LT
334
335 type = nfs3_ftypes[argp->ftype];
14168d67
CL
336 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
337 &argp->attrs, type, rdev, &resp->fh);
43a9aa64 338 fh_unlock(&resp->dirfh);
14168d67 339out:
cc028a10 340 return rpc_success;
1da177e4
LT
341}
342
343/*
344 * Remove file/fifo/socket etc.
345 */
7111c66e 346static __be32
a6beb732 347nfsd3_proc_remove(struct svc_rqst *rqstp)
1da177e4 348{
a6beb732
CH
349 struct nfsd3_diropargs *argp = rqstp->rq_argp;
350 struct nfsd3_attrstat *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
359 resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
360 argp->name, argp->len);
43a9aa64 361 fh_unlock(&resp->fh);
cc028a10 362 return rpc_success;
1da177e4
LT
363}
364
365/*
366 * Remove a directory
367 */
7111c66e 368static __be32
a6beb732 369nfsd3_proc_rmdir(struct svc_rqst *rqstp)
1da177e4 370{
a6beb732
CH
371 struct nfsd3_diropargs *argp = rqstp->rq_argp;
372 struct nfsd3_attrstat *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
380 resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
381 argp->name, argp->len);
43a9aa64 382 fh_unlock(&resp->fh);
cc028a10 383 return rpc_success;
1da177e4
LT
384}
385
7111c66e 386static __be32
a6beb732 387nfsd3_proc_rename(struct svc_rqst *rqstp)
1da177e4 388{
a6beb732
CH
389 struct nfsd3_renameargs *argp = rqstp->rq_argp;
390 struct nfsd3_renameres *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
403 resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
404 &resp->tfh, argp->tname, argp->tlen);
cc028a10 405 return rpc_success;
1da177e4
LT
406}
407
7111c66e 408static __be32
a6beb732 409nfsd3_proc_link(struct svc_rqst *rqstp)
1da177e4 410{
a6beb732
CH
411 struct nfsd3_linkargs *argp = rqstp->rq_argp;
412 struct nfsd3_linkres *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
423 resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
424 &resp->fh);
cc028a10 425 return rpc_success;
1da177e4
LT
426}
427
428/*
429 * Read a portion of a directory.
430 */
7111c66e 431static __be32
a6beb732 432nfsd3_proc_readdir(struct svc_rqst *rqstp)
1da177e4 433{
a6beb732
CH
434 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
435 struct nfsd3_readdirres *resp = rqstp->rq_resp;
3c86794a
MZ
436 int count = 0;
437 struct page **p;
438 caddr_t page_addr = NULL;
1da177e4
LT
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;
14168d67
CL
455 resp->status = nfsd_readdir(rqstp, &resp->fh, (loff_t *)&argp->cookie,
456 &resp->common, nfs3svc_encode_entry);
1da177e4 457 memcpy(resp->verf, argp->verf, 8);
3c86794a
MZ
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;
b602345d
N
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 }
1da177e4 483
cc028a10 484 return rpc_success;
1da177e4
LT
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 */
7111c66e 491static __be32
a6beb732 492nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
1da177e4 493{
a6beb732
CH
494 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
495 struct nfsd3_readdirres *resp = rqstp->rq_resp;
c4d987ba 496 int count = 0;
1da177e4 497 loff_t offset;
afc59400 498 struct page **p;
1da177e4
LT
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;
18c01ab3 517
14168d67
CL
518 resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
519 if (resp->status != nfs_ok)
520 goto out;
18c01ab3 521
14168d67
CL
522 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
523 resp->status = nfserr_notsupp;
524 goto out;
525 }
18c01ab3 526
14168d67
CL
527 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
528 &resp->common, nfs3svc_encode_entry_plus);
1da177e4 529 memcpy(resp->verf, argp->verf, 8);
afc59400
BF
530 for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
531 page_addr = page_address(*p);
1da177e4
LT
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 }
b602345d 550 resp->offset = NULL;
1da177e4
LT
551 }
552
14168d67 553out:
cc028a10 554 return rpc_success;
1da177e4
LT
555}
556
557/*
558 * Get file system stats
559 */
7111c66e 560static __be32
a6beb732 561nfsd3_proc_fsstat(struct svc_rqst *rqstp)
1da177e4 562{
a6beb732
CH
563 struct nfsd_fhandle *argp = rqstp->rq_argp;
564 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
1da177e4
LT
565
566 dprintk("nfsd: FSSTAT(3) %s\n",
567 SVCFH_fmt(&argp->fh));
568
14168d67 569 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
1da177e4 570 fh_put(&argp->fh);
cc028a10 571 return rpc_success;
1da177e4
LT
572}
573
574/*
575 * Get file system info
576 */
7111c66e 577static __be32
a6beb732 578nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
1da177e4 579{
a6beb732
CH
580 struct nfsd_fhandle *argp = rqstp->rq_argp;
581 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
7adae489 582 u32 max_blocksize = svc_max_payload(rqstp);
1da177e4
LT
583
584 dprintk("nfsd: FSINFO(3) %s\n",
585 SVCFH_fmt(&argp->fh));
586
7adae489
GB
587 resp->f_rtmax = max_blocksize;
588 resp->f_rtpref = max_blocksize;
1da177e4 589 resp->f_rtmult = PAGE_SIZE;
7adae489
GB
590 resp->f_wtmax = max_blocksize;
591 resp->f_wtpref = max_blocksize;
1da177e4 592 resp->f_wtmult = PAGE_SIZE;
f875a792 593 resp->f_dtpref = max_blocksize;
1da177e4
LT
594 resp->f_maxfilesize = ~(u32) 0;
595 resp->f_properties = NFS3_FSF_DEFAULT;
596
14168d67
CL
597 resp->status = fh_verify(rqstp, &argp->fh, 0,
598 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
1da177e4
LT
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 */
14168d67 603 if (resp->status == nfs_ok) {
fc64005c 604 struct super_block *sb = argp->fh.fh_dentry->d_sb;
1da177e4
LT
605
606 /* Note that we don't care for remote fs's here */
12214cb7 607 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
1da177e4
LT
608 resp->f_properties = NFS3_FSF_BILLYBOY;
609 }
610 resp->f_maxfilesize = sb->s_maxbytes;
611 }
612
613 fh_put(&argp->fh);
cc028a10 614 return rpc_success;
1da177e4
LT
615}
616
617/*
618 * Get pathconf info for the specified file
619 */
7111c66e 620static __be32
a6beb732 621nfsd3_proc_pathconf(struct svc_rqst *rqstp)
1da177e4 622{
a6beb732
CH
623 struct nfsd_fhandle *argp = rqstp->rq_argp;
624 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
1da177e4
LT
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
14168d67 637 resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
1da177e4 638
14168d67 639 if (resp->status == nfs_ok) {
fc64005c 640 struct super_block *sb = argp->fh.fh_dentry->d_sb;
1da177e4
LT
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;
12214cb7 648 case MSDOS_SUPER_MAGIC:
1da177e4
LT
649 resp->p_case_insensitive = 1;
650 resp->p_case_preserving = 0;
651 break;
652 }
653 }
654
655 fh_put(&argp->fh);
cc028a10 656 return rpc_success;
1da177e4
LT
657}
658
1da177e4
LT
659/*
660 * Commit a file (range) to stable storage.
661 */
7111c66e 662static __be32
a6beb732 663nfsd3_proc_commit(struct svc_rqst *rqstp)
1da177e4 664{
a6beb732
CH
665 struct nfsd3_commitargs *argp = rqstp->rq_argp;
666 struct nfsd3_commitres *resp = rqstp->rq_resp;
1da177e4
LT
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
14168d67
CL
673 if (argp->offset > NFS_OFFSET_MAX) {
674 resp->status = nfserr_inval;
675 goto out;
676 }
1da177e4
LT
677
678 fh_copy(&resp->fh, &argp->fh);
14168d67
CL
679 resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
680 argp->count, resp->verf);
681out:
cc028a10 682 return rpc_success;
1da177e4
LT
683}
684
685
686/*
687 * NFSv3 Server procedures.
688 * Only the results of non-idempotent operations are cached.
689 */
1da177e4
LT
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
701struct nfsd3_voidargs { int dummy; };
702
1da177e4
LT
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
860bda29 709static const struct svc_procedure nfsd_procedures3[22] = {
b9081d90 710 [NFS3PROC_NULL] = {
a6beb732 711 .pc_func = nfsd3_proc_null,
dcc46991 712 .pc_decode = nfs3svc_decode_voidarg,
63f8de37 713 .pc_encode = nfs3svc_encode_voidres,
b9081d90
YZ
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] = {
a6beb732 720 .pc_func = nfsd3_proc_getattr,
026fec7e 721 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 722 .pc_encode = nfs3svc_encode_attrstatres,
8537488b 723 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 730 .pc_func = nfsd3_proc_setattr,
026fec7e 731 .pc_decode = nfs3svc_decode_sattrargs,
63f8de37 732 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 733 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 740 .pc_func = nfsd3_proc_lookup,
026fec7e 741 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 742 .pc_encode = nfs3svc_encode_diropres,
8537488b 743 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 750 .pc_func = nfsd3_proc_access,
026fec7e 751 .pc_decode = nfs3svc_decode_accessargs,
63f8de37 752 .pc_encode = nfs3svc_encode_accessres,
8537488b 753 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 760 .pc_func = nfsd3_proc_readlink,
026fec7e 761 .pc_decode = nfs3svc_decode_readlinkargs,
63f8de37 762 .pc_encode = nfs3svc_encode_readlinkres,
8537488b 763 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 770 .pc_func = nfsd3_proc_read,
026fec7e 771 .pc_decode = nfs3svc_decode_readargs,
63f8de37 772 .pc_encode = nfs3svc_encode_readres,
8537488b 773 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 780 .pc_func = nfsd3_proc_write,
026fec7e 781 .pc_decode = nfs3svc_decode_writeargs,
63f8de37 782 .pc_encode = nfs3svc_encode_writeres,
8537488b 783 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 790 .pc_func = nfsd3_proc_create,
026fec7e 791 .pc_decode = nfs3svc_decode_createargs,
63f8de37 792 .pc_encode = nfs3svc_encode_createres,
8537488b 793 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 800 .pc_func = nfsd3_proc_mkdir,
026fec7e 801 .pc_decode = nfs3svc_decode_mkdirargs,
63f8de37 802 .pc_encode = nfs3svc_encode_createres,
8537488b 803 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 810 .pc_func = nfsd3_proc_symlink,
026fec7e 811 .pc_decode = nfs3svc_decode_symlinkargs,
63f8de37 812 .pc_encode = nfs3svc_encode_createres,
8537488b 813 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 820 .pc_func = nfsd3_proc_mknod,
026fec7e 821 .pc_decode = nfs3svc_decode_mknodargs,
63f8de37 822 .pc_encode = nfs3svc_encode_createres,
8537488b 823 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 830 .pc_func = nfsd3_proc_remove,
026fec7e 831 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 832 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 833 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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] = {
a6beb732 840 .pc_func = nfsd3_proc_rmdir,
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_RENAME] = {
a6beb732 850 .pc_func = nfsd3_proc_rename,
026fec7e 851 .pc_decode = nfs3svc_decode_renameargs,
63f8de37 852 .pc_encode = nfs3svc_encode_renameres,
8537488b 853 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 860 .pc_func = nfsd3_proc_link,
026fec7e 861 .pc_decode = nfs3svc_decode_linkargs,
63f8de37 862 .pc_encode = nfs3svc_encode_linkres,
8537488b 863 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
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] = {
a6beb732 870 .pc_func = nfsd3_proc_readdir,
026fec7e 871 .pc_decode = nfs3svc_decode_readdirargs,
63f8de37 872 .pc_encode = nfs3svc_encode_readdirres,
8537488b 873 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
874 .pc_argsize = sizeof(struct nfsd3_readdirargs),
875 .pc_ressize = sizeof(struct nfsd3_readdirres),
876 .pc_cachetype = RC_NOCACHE,
877 },
878 [NFS3PROC_READDIRPLUS] = {
a6beb732 879 .pc_func = nfsd3_proc_readdirplus,
026fec7e 880 .pc_decode = nfs3svc_decode_readdirplusargs,
63f8de37 881 .pc_encode = nfs3svc_encode_readdirres,
8537488b 882 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
883 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
884 .pc_ressize = sizeof(struct nfsd3_readdirres),
885 .pc_cachetype = RC_NOCACHE,
886 },
887 [NFS3PROC_FSSTAT] = {
a6beb732 888 .pc_func = nfsd3_proc_fsstat,
026fec7e 889 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 890 .pc_encode = nfs3svc_encode_fsstatres,
b9081d90
YZ
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] = {
a6beb732 897 .pc_func = nfsd3_proc_fsinfo,
026fec7e 898 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 899 .pc_encode = nfs3svc_encode_fsinfores,
b9081d90
YZ
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] = {
a6beb732 906 .pc_func = nfsd3_proc_pathconf,
026fec7e 907 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 908 .pc_encode = nfs3svc_encode_pathconfres,
b9081d90
YZ
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] = {
a6beb732 915 .pc_func = nfsd3_proc_commit,
026fec7e 916 .pc_decode = nfs3svc_decode_commitargs,
63f8de37 917 .pc_encode = nfs3svc_encode_commitres,
8537488b 918 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
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 },
1da177e4
LT
924};
925
7fd38af9 926static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
e9679189
CH
927const 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,
1da177e4 934};