]> git.ipfire.org Git - people/ms/linux.git/blame - fs/nfsd/nfs3proc.c
Linux 5.16-rc5
[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{
224c1c89 127 struct nfsd_fhandle *argp = rqstp->rq_argp;
a6beb732 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;
9a9c8923
CL
135 resp->pages = rqstp->rq_next_page++;
136 resp->status = nfsd_readlink(rqstp, &resp->fh,
137 page_address(*resp->pages), &resp->len);
cc028a10 138 return rpc_success;
1da177e4
LT
139}
140
141/*
142 * Read a portion of a file.
143 */
7111c66e 144static __be32
a6beb732 145nfsd3_proc_read(struct svc_rqst *rqstp)
1da177e4 146{
a6beb732
CH
147 struct nfsd3_readargs *argp = rqstp->rq_argp;
148 struct nfsd3_readres *resp = rqstp->rq_resp;
be63bd2a
CL
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);
1da177e4 154
18b631f8 155 dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
1da177e4
LT
156 SVCFH_fmt(&argp->fh),
157 (unsigned long) argp->count,
18b631f8 158 (unsigned long long) argp->offset);
1da177e4 159
be63bd2a
CL
160 v = 0;
161 len = argp->count;
cc9bcdad 162 resp->pages = rqstp->rq_next_page;
be63bd2a
CL
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
1da177e4
LT
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 */
be63bd2a 176 resp->count = argp->count;
cd123012 177 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
1da177e4
LT
178
179 fh_copy(&resp->fh, &argp->fh);
14168d67 180 resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
be63bd2a 181 rqstp->rq_vec, v, &resp->count, &resp->eof);
cc028a10 182 return rpc_success;
1da177e4
LT
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;
31dec253 193 unsigned long cnt = argp->len;
8154ef27 194 unsigned int nvecs;
1da177e4 195
18b631f8 196 dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
1da177e4
LT
197 SVCFH_fmt(&argp->fh),
198 argp->len,
18b631f8 199 (unsigned long long) argp->offset,
1da177e4
LT
200 argp->stable? " stable" : "");
201
202 fh_copy(&resp->fh, &argp->fh);
203 resp->committed = argp->stable;
dae9a6ca 204 nvecs = svc_fill_write_vector(rqstp, &argp->payload);
14168d67
CL
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);
31dec253 212 resp->count = cnt;
14168d67 213out:
cc028a10 214 return rpc_success;
1da177e4
LT
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 */
7111c66e 222static __be32
a6beb732 223nfsd3_proc_create(struct svc_rqst *rqstp)
1da177e4 224{
a6beb732
CH
225 struct nfsd3_createargs *argp = rqstp->rq_argp;
226 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4
LT
227 svc_fh *dirfhp, *newfhp = NULL;
228 struct iattr *attr;
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 */
14168d67
CL
249 resp->status = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
250 attr, newfhp, argp->createmode,
251 (u32 *)argp->verf, NULL, NULL);
cc028a10 252 return rpc_success;
1da177e4
LT
253}
254
255/*
256 * Make directory. This operation is not idempotent.
257 */
7111c66e 258static __be32
a6beb732 259nfsd3_proc_mkdir(struct svc_rqst *rqstp)
1da177e4 260{
a6beb732
CH
261 struct nfsd3_createargs *argp = rqstp->rq_argp;
262 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
272 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
273 &argp->attrs, S_IFDIR, 0, &resp->fh);
43a9aa64 274 fh_unlock(&resp->dirfh);
cc028a10 275 return rpc_success;
1da177e4
LT
276}
277
7111c66e 278static __be32
a6beb732 279nfsd3_proc_symlink(struct svc_rqst *rqstp)
1da177e4 280{
a6beb732
CH
281 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
282 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4 283
14168d67
CL
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 }
38a70315
CL
292
293 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
11b4d66e 294 page_address(rqstp->rq_arg.pages[0]),
38a70315 295 argp->tlen);
14168d67
CL
296 if (IS_ERR(argp->tname)) {
297 resp->status = nfserrno(PTR_ERR(argp->tname));
298 goto out;
299 }
38a70315 300
1da177e4
LT
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);
14168d67
CL
308 resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
309 argp->flen, argp->tname, &resp->fh);
11b4d66e 310 kfree(argp->tname);
14168d67 311out:
cc028a10 312 return rpc_success;
1da177e4
LT
313}
314
315/*
316 * Make socket/fifo/device.
317 */
7111c66e 318static __be32
a6beb732 319nfsd3_proc_mknod(struct svc_rqst *rqstp)
1da177e4 320{
a6beb732
CH
321 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
322 struct nfsd3_diropres *resp = rqstp->rq_resp;
c4d987ba 323 int type;
1da177e4
LT
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
1da177e4
LT
334 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
335 rdev = MKDEV(argp->major, argp->minor);
336 if (MAJOR(rdev) != argp->major ||
14168d67
CL
337 MINOR(rdev) != argp->minor) {
338 resp->status = nfserr_inval;
339 goto out;
340 }
341 } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
66d60e3a 342 resp->status = nfserr_badtype;
14168d67
CL
343 goto out;
344 }
1da177e4
LT
345
346 type = nfs3_ftypes[argp->ftype];
14168d67
CL
347 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
348 &argp->attrs, type, rdev, &resp->fh);
43a9aa64 349 fh_unlock(&resp->dirfh);
14168d67 350out:
cc028a10 351 return rpc_success;
1da177e4
LT
352}
353
354/*
355 * Remove file/fifo/socket etc.
356 */
7111c66e 357static __be32
a6beb732 358nfsd3_proc_remove(struct svc_rqst *rqstp)
1da177e4 359{
a6beb732
CH
360 struct nfsd3_diropargs *argp = rqstp->rq_argp;
361 struct nfsd3_attrstat *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
370 resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
371 argp->name, argp->len);
43a9aa64 372 fh_unlock(&resp->fh);
cc028a10 373 return rpc_success;
1da177e4
LT
374}
375
376/*
377 * Remove a directory
378 */
7111c66e 379static __be32
a6beb732 380nfsd3_proc_rmdir(struct svc_rqst *rqstp)
1da177e4 381{
a6beb732
CH
382 struct nfsd3_diropargs *argp = rqstp->rq_argp;
383 struct nfsd3_attrstat *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
391 resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
392 argp->name, argp->len);
43a9aa64 393 fh_unlock(&resp->fh);
cc028a10 394 return rpc_success;
1da177e4
LT
395}
396
7111c66e 397static __be32
a6beb732 398nfsd3_proc_rename(struct svc_rqst *rqstp)
1da177e4 399{
a6beb732
CH
400 struct nfsd3_renameargs *argp = rqstp->rq_argp;
401 struct nfsd3_renameres *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
414 resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
415 &resp->tfh, argp->tname, argp->tlen);
cc028a10 416 return rpc_success;
1da177e4
LT
417}
418
7111c66e 419static __be32
a6beb732 420nfsd3_proc_link(struct svc_rqst *rqstp)
1da177e4 421{
a6beb732
CH
422 struct nfsd3_linkargs *argp = rqstp->rq_argp;
423 struct nfsd3_linkres *resp = rqstp->rq_resp;
1da177e4
LT
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);
14168d67
CL
434 resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
435 &resp->fh);
cc028a10 436 return rpc_success;
1da177e4
LT
437}
438
40116ebd
CL
439static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
440 struct nfsd3_readdirres *resp,
441 int count)
442{
7f87fc2d
CL
443 struct xdr_buf *buf = &resp->dirlist;
444 struct xdr_stream *xdr = &resp->xdr;
445
40116ebd
CL
446 count = min_t(u32, count, svc_max_payload(rqstp));
447
7f87fc2d 448 memset(buf, 0, sizeof(*buf));
40116ebd 449
7f87fc2d
CL
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;
40116ebd
CL
453 while (count > 0) {
454 rqstp->rq_next_page++;
455 count -= PAGE_SIZE;
456 }
7f87fc2d
CL
457
458 /* This is xdr_init_encode(), but it assumes that
459 * the head kvec has already been consumed. */
460 xdr_set_scratch_buffer(xdr, NULL, 0);
461 xdr->buf = buf;
462 xdr->page_ptr = buf->pages;
463 xdr->iov = NULL;
464 xdr->p = page_address(*buf->pages);
465 xdr->end = xdr->p + (PAGE_SIZE >> 2);
466 xdr->rqst = NULL;
40116ebd
CL
467}
468
1da177e4
LT
469/*
470 * Read a portion of a directory.
471 */
7111c66e 472static __be32
a6beb732 473nfsd3_proc_readdir(struct svc_rqst *rqstp)
1da177e4 474{
a6beb732
CH
475 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
476 struct nfsd3_readdirres *resp = rqstp->rq_resp;
0a8f37fb 477 loff_t offset;
1da177e4
LT
478
479 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
480 SVCFH_fmt(&argp->fh),
481 argp->count, (u32) argp->cookie);
482
40116ebd 483 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
1da177e4 484
1da177e4 485 fh_copy(&resp->fh, &argp->fh);
1da177e4 486 resp->common.err = nfs_ok;
7f87fc2d 487 resp->cookie_offset = 0;
1da177e4 488 resp->rqstp = rqstp;
0a8f37fb 489 offset = argp->cookie;
0a8f37fb 490 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
7f87fc2d 491 &resp->common, nfs3svc_encode_entry3);
1da177e4 492 memcpy(resp->verf, argp->verf, 8);
a161e6c7 493 nfs3svc_encode_cookie3(resp, offset);
1da177e4 494
76ed0dd9
CL
495 /* Recycle only pages that were part of the reply */
496 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
497
cc028a10 498 return rpc_success;
1da177e4
LT
499}
500
501/*
502 * Read a portion of a directory, including file handles and attrs.
503 * For now, we choose to ignore the dircount parameter.
504 */
7111c66e 505static __be32
a6beb732 506nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
1da177e4 507{
a6beb732
CH
508 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
509 struct nfsd3_readdirres *resp = rqstp->rq_resp;
1da177e4 510 loff_t offset;
1da177e4
LT
511
512 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
513 SVCFH_fmt(&argp->fh),
514 argp->count, (u32) argp->cookie);
515
40116ebd 516 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
1da177e4 517
1da177e4 518 fh_copy(&resp->fh, &argp->fh);
1da177e4 519 resp->common.err = nfs_ok;
7f87fc2d 520 resp->cookie_offset = 0;
1da177e4
LT
521 resp->rqstp = rqstp;
522 offset = argp->cookie;
18c01ab3 523
14168d67
CL
524 resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
525 if (resp->status != nfs_ok)
526 goto out;
18c01ab3 527
14168d67
CL
528 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
529 resp->status = nfserr_notsupp;
530 goto out;
531 }
18c01ab3 532
14168d67 533 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
7f87fc2d 534 &resp->common, nfs3svc_encode_entryplus3);
1da177e4 535 memcpy(resp->verf, argp->verf, 8);
a161e6c7 536 nfs3svc_encode_cookie3(resp, offset);
1da177e4 537
76ed0dd9
CL
538 /* Recycle only pages that were part of the reply */
539 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
540
14168d67 541out:
cc028a10 542 return rpc_success;
1da177e4
LT
543}
544
545/*
546 * Get file system stats
547 */
7111c66e 548static __be32
a6beb732 549nfsd3_proc_fsstat(struct svc_rqst *rqstp)
1da177e4 550{
a6beb732
CH
551 struct nfsd_fhandle *argp = rqstp->rq_argp;
552 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
1da177e4
LT
553
554 dprintk("nfsd: FSSTAT(3) %s\n",
555 SVCFH_fmt(&argp->fh));
556
14168d67 557 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
1da177e4 558 fh_put(&argp->fh);
cc028a10 559 return rpc_success;
1da177e4
LT
560}
561
562/*
563 * Get file system info
564 */
7111c66e 565static __be32
a6beb732 566nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
1da177e4 567{
a6beb732
CH
568 struct nfsd_fhandle *argp = rqstp->rq_argp;
569 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
7adae489 570 u32 max_blocksize = svc_max_payload(rqstp);
1da177e4
LT
571
572 dprintk("nfsd: FSINFO(3) %s\n",
573 SVCFH_fmt(&argp->fh));
574
7adae489
GB
575 resp->f_rtmax = max_blocksize;
576 resp->f_rtpref = max_blocksize;
1da177e4 577 resp->f_rtmult = PAGE_SIZE;
7adae489
GB
578 resp->f_wtmax = max_blocksize;
579 resp->f_wtpref = max_blocksize;
1da177e4 580 resp->f_wtmult = PAGE_SIZE;
f875a792 581 resp->f_dtpref = max_blocksize;
1da177e4
LT
582 resp->f_maxfilesize = ~(u32) 0;
583 resp->f_properties = NFS3_FSF_DEFAULT;
584
14168d67
CL
585 resp->status = fh_verify(rqstp, &argp->fh, 0,
586 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
1da177e4
LT
587
588 /* Check special features of the file system. May request
589 * different read/write sizes for file systems known to have
590 * problems with large blocks */
14168d67 591 if (resp->status == nfs_ok) {
fc64005c 592 struct super_block *sb = argp->fh.fh_dentry->d_sb;
1da177e4
LT
593
594 /* Note that we don't care for remote fs's here */
12214cb7 595 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
1da177e4
LT
596 resp->f_properties = NFS3_FSF_BILLYBOY;
597 }
598 resp->f_maxfilesize = sb->s_maxbytes;
599 }
600
601 fh_put(&argp->fh);
cc028a10 602 return rpc_success;
1da177e4
LT
603}
604
605/*
606 * Get pathconf info for the specified file
607 */
7111c66e 608static __be32
a6beb732 609nfsd3_proc_pathconf(struct svc_rqst *rqstp)
1da177e4 610{
a6beb732
CH
611 struct nfsd_fhandle *argp = rqstp->rq_argp;
612 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
1da177e4
LT
613
614 dprintk("nfsd: PATHCONF(3) %s\n",
615 SVCFH_fmt(&argp->fh));
616
617 /* Set default pathconf */
618 resp->p_link_max = 255; /* at least */
619 resp->p_name_max = 255; /* at least */
620 resp->p_no_trunc = 0;
621 resp->p_chown_restricted = 1;
622 resp->p_case_insensitive = 0;
623 resp->p_case_preserving = 1;
624
14168d67 625 resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
1da177e4 626
14168d67 627 if (resp->status == nfs_ok) {
fc64005c 628 struct super_block *sb = argp->fh.fh_dentry->d_sb;
1da177e4
LT
629
630 /* Note that we don't care for remote fs's here */
631 switch (sb->s_magic) {
632 case EXT2_SUPER_MAGIC:
633 resp->p_link_max = EXT2_LINK_MAX;
634 resp->p_name_max = EXT2_NAME_LEN;
635 break;
12214cb7 636 case MSDOS_SUPER_MAGIC:
1da177e4
LT
637 resp->p_case_insensitive = 1;
638 resp->p_case_preserving = 0;
639 break;
640 }
641 }
642
643 fh_put(&argp->fh);
cc028a10 644 return rpc_success;
1da177e4
LT
645}
646
1da177e4
LT
647/*
648 * Commit a file (range) to stable storage.
649 */
7111c66e 650static __be32
a6beb732 651nfsd3_proc_commit(struct svc_rqst *rqstp)
1da177e4 652{
a6beb732
CH
653 struct nfsd3_commitargs *argp = rqstp->rq_argp;
654 struct nfsd3_commitres *resp = rqstp->rq_resp;
1da177e4
LT
655
656 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
657 SVCFH_fmt(&argp->fh),
658 argp->count,
659 (unsigned long long) argp->offset);
660
14168d67
CL
661 if (argp->offset > NFS_OFFSET_MAX) {
662 resp->status = nfserr_inval;
663 goto out;
664 }
1da177e4
LT
665
666 fh_copy(&resp->fh, &argp->fh);
14168d67
CL
667 resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
668 argp->count, resp->verf);
669out:
cc028a10 670 return rpc_success;
1da177e4
LT
671}
672
673
674/*
675 * NFSv3 Server procedures.
676 * Only the results of non-idempotent operations are cached.
677 */
1da177e4
LT
678#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
679#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
680#define nfsd3_mkdirargs nfsd3_createargs
681#define nfsd3_readdirplusargs nfsd3_readdirargs
682#define nfsd3_fhandleargs nfsd_fhandle
1da177e4
LT
683#define nfsd3_attrstatres nfsd3_attrstat
684#define nfsd3_wccstatres nfsd3_attrstat
685#define nfsd3_createres nfsd3_diropres
1da177e4 686
1da177e4
LT
687#define ST 1 /* status*/
688#define FH 17 /* filehandle with length */
689#define AT 21 /* attributes */
690#define pAT (1+AT) /* post attributes - conditional */
691#define WC (7+pAT) /* WCC attributes */
692
860bda29 693static const struct svc_procedure nfsd_procedures3[22] = {
b9081d90 694 [NFS3PROC_NULL] = {
a6beb732 695 .pc_func = nfsd3_proc_null,
788f7183
CL
696 .pc_decode = nfssvc_decode_voidarg,
697 .pc_encode = nfssvc_encode_voidres,
698 .pc_argsize = sizeof(struct nfsd_voidargs),
699 .pc_ressize = sizeof(struct nfsd_voidres),
b9081d90
YZ
700 .pc_cachetype = RC_NOCACHE,
701 .pc_xdrressize = ST,
2289e87b 702 .pc_name = "NULL",
b9081d90
YZ
703 },
704 [NFS3PROC_GETATTR] = {
a6beb732 705 .pc_func = nfsd3_proc_getattr,
026fec7e 706 .pc_decode = nfs3svc_decode_fhandleargs,
2c42f804 707 .pc_encode = nfs3svc_encode_getattrres,
8537488b 708 .pc_release = nfs3svc_release_fhandle,
9575363a 709 .pc_argsize = sizeof(struct nfsd_fhandle),
b9081d90
YZ
710 .pc_ressize = sizeof(struct nfsd3_attrstatres),
711 .pc_cachetype = RC_NOCACHE,
712 .pc_xdrressize = ST+AT,
2289e87b 713 .pc_name = "GETATTR",
b9081d90
YZ
714 },
715 [NFS3PROC_SETATTR] = {
a6beb732 716 .pc_func = nfsd3_proc_setattr,
026fec7e 717 .pc_decode = nfs3svc_decode_sattrargs,
63f8de37 718 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 719 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
720 .pc_argsize = sizeof(struct nfsd3_sattrargs),
721 .pc_ressize = sizeof(struct nfsd3_wccstatres),
722 .pc_cachetype = RC_REPLBUFF,
723 .pc_xdrressize = ST+WC,
2289e87b 724 .pc_name = "SETATTR",
b9081d90
YZ
725 },
726 [NFS3PROC_LOOKUP] = {
a6beb732 727 .pc_func = nfsd3_proc_lookup,
026fec7e 728 .pc_decode = nfs3svc_decode_diropargs,
5cf35335 729 .pc_encode = nfs3svc_encode_lookupres,
8537488b 730 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
731 .pc_argsize = sizeof(struct nfsd3_diropargs),
732 .pc_ressize = sizeof(struct nfsd3_diropres),
733 .pc_cachetype = RC_NOCACHE,
734 .pc_xdrressize = ST+FH+pAT+pAT,
2289e87b 735 .pc_name = "LOOKUP",
b9081d90
YZ
736 },
737 [NFS3PROC_ACCESS] = {
a6beb732 738 .pc_func = nfsd3_proc_access,
026fec7e 739 .pc_decode = nfs3svc_decode_accessargs,
63f8de37 740 .pc_encode = nfs3svc_encode_accessres,
8537488b 741 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
742 .pc_argsize = sizeof(struct nfsd3_accessargs),
743 .pc_ressize = sizeof(struct nfsd3_accessres),
744 .pc_cachetype = RC_NOCACHE,
745 .pc_xdrressize = ST+pAT+1,
2289e87b 746 .pc_name = "ACCESS",
b9081d90
YZ
747 },
748 [NFS3PROC_READLINK] = {
a6beb732 749 .pc_func = nfsd3_proc_readlink,
224c1c89 750 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 751 .pc_encode = nfs3svc_encode_readlinkres,
8537488b 752 .pc_release = nfs3svc_release_fhandle,
224c1c89 753 .pc_argsize = sizeof(struct nfsd_fhandle),
b9081d90
YZ
754 .pc_ressize = sizeof(struct nfsd3_readlinkres),
755 .pc_cachetype = RC_NOCACHE,
756 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
2289e87b 757 .pc_name = "READLINK",
b9081d90
YZ
758 },
759 [NFS3PROC_READ] = {
a6beb732 760 .pc_func = nfsd3_proc_read,
026fec7e 761 .pc_decode = nfs3svc_decode_readargs,
63f8de37 762 .pc_encode = nfs3svc_encode_readres,
8537488b 763 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
764 .pc_argsize = sizeof(struct nfsd3_readargs),
765 .pc_ressize = sizeof(struct nfsd3_readres),
766 .pc_cachetype = RC_NOCACHE,
767 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
2289e87b 768 .pc_name = "READ",
b9081d90
YZ
769 },
770 [NFS3PROC_WRITE] = {
a6beb732 771 .pc_func = nfsd3_proc_write,
026fec7e 772 .pc_decode = nfs3svc_decode_writeargs,
63f8de37 773 .pc_encode = nfs3svc_encode_writeres,
8537488b 774 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
775 .pc_argsize = sizeof(struct nfsd3_writeargs),
776 .pc_ressize = sizeof(struct nfsd3_writeres),
777 .pc_cachetype = RC_REPLBUFF,
778 .pc_xdrressize = ST+WC+4,
2289e87b 779 .pc_name = "WRITE",
b9081d90
YZ
780 },
781 [NFS3PROC_CREATE] = {
a6beb732 782 .pc_func = nfsd3_proc_create,
026fec7e 783 .pc_decode = nfs3svc_decode_createargs,
63f8de37 784 .pc_encode = nfs3svc_encode_createres,
8537488b 785 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
786 .pc_argsize = sizeof(struct nfsd3_createargs),
787 .pc_ressize = sizeof(struct nfsd3_createres),
788 .pc_cachetype = RC_REPLBUFF,
789 .pc_xdrressize = ST+(1+FH+pAT)+WC,
2289e87b 790 .pc_name = "CREATE",
b9081d90
YZ
791 },
792 [NFS3PROC_MKDIR] = {
a6beb732 793 .pc_func = nfsd3_proc_mkdir,
026fec7e 794 .pc_decode = nfs3svc_decode_mkdirargs,
63f8de37 795 .pc_encode = nfs3svc_encode_createres,
8537488b 796 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
797 .pc_argsize = sizeof(struct nfsd3_mkdirargs),
798 .pc_ressize = sizeof(struct nfsd3_createres),
799 .pc_cachetype = RC_REPLBUFF,
800 .pc_xdrressize = ST+(1+FH+pAT)+WC,
2289e87b 801 .pc_name = "MKDIR",
b9081d90
YZ
802 },
803 [NFS3PROC_SYMLINK] = {
a6beb732 804 .pc_func = nfsd3_proc_symlink,
026fec7e 805 .pc_decode = nfs3svc_decode_symlinkargs,
63f8de37 806 .pc_encode = nfs3svc_encode_createres,
8537488b 807 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
808 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
809 .pc_ressize = sizeof(struct nfsd3_createres),
810 .pc_cachetype = RC_REPLBUFF,
811 .pc_xdrressize = ST+(1+FH+pAT)+WC,
2289e87b 812 .pc_name = "SYMLINK",
b9081d90
YZ
813 },
814 [NFS3PROC_MKNOD] = {
a6beb732 815 .pc_func = nfsd3_proc_mknod,
026fec7e 816 .pc_decode = nfs3svc_decode_mknodargs,
63f8de37 817 .pc_encode = nfs3svc_encode_createres,
8537488b 818 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
819 .pc_argsize = sizeof(struct nfsd3_mknodargs),
820 .pc_ressize = sizeof(struct nfsd3_createres),
821 .pc_cachetype = RC_REPLBUFF,
822 .pc_xdrressize = ST+(1+FH+pAT)+WC,
2289e87b 823 .pc_name = "MKNOD",
b9081d90
YZ
824 },
825 [NFS3PROC_REMOVE] = {
a6beb732 826 .pc_func = nfsd3_proc_remove,
026fec7e 827 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 828 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 829 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
830 .pc_argsize = sizeof(struct nfsd3_diropargs),
831 .pc_ressize = sizeof(struct nfsd3_wccstatres),
832 .pc_cachetype = RC_REPLBUFF,
833 .pc_xdrressize = ST+WC,
2289e87b 834 .pc_name = "REMOVE",
b9081d90
YZ
835 },
836 [NFS3PROC_RMDIR] = {
a6beb732 837 .pc_func = nfsd3_proc_rmdir,
026fec7e 838 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 839 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 840 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
841 .pc_argsize = sizeof(struct nfsd3_diropargs),
842 .pc_ressize = sizeof(struct nfsd3_wccstatres),
843 .pc_cachetype = RC_REPLBUFF,
844 .pc_xdrressize = ST+WC,
2289e87b 845 .pc_name = "RMDIR",
b9081d90
YZ
846 },
847 [NFS3PROC_RENAME] = {
a6beb732 848 .pc_func = nfsd3_proc_rename,
026fec7e 849 .pc_decode = nfs3svc_decode_renameargs,
63f8de37 850 .pc_encode = nfs3svc_encode_renameres,
8537488b 851 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
852 .pc_argsize = sizeof(struct nfsd3_renameargs),
853 .pc_ressize = sizeof(struct nfsd3_renameres),
854 .pc_cachetype = RC_REPLBUFF,
855 .pc_xdrressize = ST+WC+WC,
2289e87b 856 .pc_name = "RENAME",
b9081d90
YZ
857 },
858 [NFS3PROC_LINK] = {
a6beb732 859 .pc_func = nfsd3_proc_link,
026fec7e 860 .pc_decode = nfs3svc_decode_linkargs,
63f8de37 861 .pc_encode = nfs3svc_encode_linkres,
8537488b 862 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
863 .pc_argsize = sizeof(struct nfsd3_linkargs),
864 .pc_ressize = sizeof(struct nfsd3_linkres),
865 .pc_cachetype = RC_REPLBUFF,
866 .pc_xdrressize = ST+pAT+WC,
2289e87b 867 .pc_name = "LINK",
b9081d90
YZ
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,
2289e87b 877 .pc_name = "READDIR",
b9081d90
YZ
878 },
879 [NFS3PROC_READDIRPLUS] = {
a6beb732 880 .pc_func = nfsd3_proc_readdirplus,
026fec7e 881 .pc_decode = nfs3svc_decode_readdirplusargs,
63f8de37 882 .pc_encode = nfs3svc_encode_readdirres,
8537488b 883 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
884 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
885 .pc_ressize = sizeof(struct nfsd3_readdirres),
886 .pc_cachetype = RC_NOCACHE,
2289e87b 887 .pc_name = "READDIRPLUS",
b9081d90
YZ
888 },
889 [NFS3PROC_FSSTAT] = {
a6beb732 890 .pc_func = nfsd3_proc_fsstat,
026fec7e 891 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 892 .pc_encode = nfs3svc_encode_fsstatres,
b9081d90
YZ
893 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
894 .pc_ressize = sizeof(struct nfsd3_fsstatres),
895 .pc_cachetype = RC_NOCACHE,
896 .pc_xdrressize = ST+pAT+2*6+1,
2289e87b 897 .pc_name = "FSSTAT",
b9081d90
YZ
898 },
899 [NFS3PROC_FSINFO] = {
a6beb732 900 .pc_func = nfsd3_proc_fsinfo,
026fec7e 901 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 902 .pc_encode = nfs3svc_encode_fsinfores,
b9081d90
YZ
903 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
904 .pc_ressize = sizeof(struct nfsd3_fsinfores),
905 .pc_cachetype = RC_NOCACHE,
906 .pc_xdrressize = ST+pAT+12,
2289e87b 907 .pc_name = "FSINFO",
b9081d90
YZ
908 },
909 [NFS3PROC_PATHCONF] = {
a6beb732 910 .pc_func = nfsd3_proc_pathconf,
026fec7e 911 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 912 .pc_encode = nfs3svc_encode_pathconfres,
b9081d90
YZ
913 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
914 .pc_ressize = sizeof(struct nfsd3_pathconfres),
915 .pc_cachetype = RC_NOCACHE,
916 .pc_xdrressize = ST+pAT+6,
2289e87b 917 .pc_name = "PATHCONF",
b9081d90
YZ
918 },
919 [NFS3PROC_COMMIT] = {
a6beb732 920 .pc_func = nfsd3_proc_commit,
026fec7e 921 .pc_decode = nfs3svc_decode_commitargs,
63f8de37 922 .pc_encode = nfs3svc_encode_commitres,
8537488b 923 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
924 .pc_argsize = sizeof(struct nfsd3_commitargs),
925 .pc_ressize = sizeof(struct nfsd3_commitres),
926 .pc_cachetype = RC_NOCACHE,
927 .pc_xdrressize = ST+WC+2,
2289e87b 928 .pc_name = "COMMIT",
b9081d90 929 },
1da177e4
LT
930};
931
7fd38af9 932static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
e9679189
CH
933const struct svc_version nfsd_version3 = {
934 .vs_vers = 3,
935 .vs_nproc = 22,
936 .vs_proc = nfsd_procedures3,
937 .vs_dispatch = nfsd_dispatch,
938 .vs_count = nfsd_count3,
939 .vs_xdrsize = NFS3_SVC_XDRSIZE,
1da177e4 940};