blob: 76931f4f57c3ef4977ad714071c9d64a86aaa614 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Process version 3 NFS requests.
4 *
5 * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
6 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/fs.h>
9#include <linux/ext2_fs.h>
Qinghuang Feng12214cb2009-01-12 03:13:53 +080010#include <linux/magic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Boaz Harrosh9a74af22009-12-03 20:30:56 +020012#include "cache.h"
13#include "xdr3.h"
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050014#include "vfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define NFSDDBG_FACILITY NFSDDBG_PROC
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018static 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 */
Al Viro7111c662006-10-19 23:28:45 -070032static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020033nfsd3_proc_null(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Chuck Levercc028a12020-10-02 15:52:44 -040035 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
38/*
39 * Get a file's attributes
40 */
Al Viro7111c662006-10-19 23:28:45 -070041static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020042nfsd3_proc_getattr(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020044 struct nfsd_fhandle *argp = rqstp->rq_argp;
45 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 dprintk("nfsd: GETATTR(3) %s\n",
David Shawa334de22006-01-06 00:19:58 -080048 SVCFH_fmt(&argp->fh));
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -040051 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;
David Shawa334de22006-01-06 00:19:58 -080055
Chuck Lever14168d62020-10-01 18:59:54 -040056 resp->status = fh_getattr(&resp->fh, &resp->stat);
57out:
Chuck Levercc028a12020-10-02 15:52:44 -040058 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61/*
62 * Set a file's attributes
63 */
Al Viro7111c662006-10-19 23:28:45 -070064static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020065nfsd3_proc_setattr(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020067 struct nfsd3_sattrargs *argp = rqstp->rq_argp;
68 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 dprintk("nfsd: SETATTR(3) %s\n",
71 SVCFH_fmt(&argp->fh));
72
73 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -040074 resp->status = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
75 argp->check_guard, argp->guardtime);
Chuck Levercc028a12020-10-02 15:52:44 -040076 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
79/*
80 * Look up a path name component
81 */
Al Viro7111c662006-10-19 23:28:45 -070082static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020083nfsd3_proc_lookup(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020085 struct nfsd3_diropargs *argp = rqstp->rq_argp;
86 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
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
Chuck Lever14168d62020-10-01 18:59:54 -040096 resp->status = nfsd_lookup(rqstp, &resp->dirfh,
97 argp->name, argp->len,
98 &resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -040099 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102/*
103 * Check file access
104 */
Al Viro7111c662006-10-19 23:28:45 -0700105static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200106nfsd3_proc_access(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200108 struct nfsd3_accessargs *argp = rqstp->rq_argp;
109 struct nfsd3_accessres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
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;
Chuck Lever14168d62020-10-01 18:59:54 -0400117 resp->status = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
Chuck Levercc028a12020-10-02 15:52:44 -0400118 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
121/*
122 * Read a symlink.
123 */
Al Viro7111c662006-10-19 23:28:45 -0700124static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200125nfsd3_proc_readlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200127 struct nfsd3_readlinkargs *argp = rqstp->rq_argp;
128 struct nfsd3_readlinkres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
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;
Chuck Lever14168d62020-10-01 18:59:54 -0400135 resp->status = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
Chuck Levercc028a12020-10-02 15:52:44 -0400136 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139/*
140 * Read a portion of a file.
141 */
Al Viro7111c662006-10-19 23:28:45 -0700142static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200143nfsd3_proc_read(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200145 struct nfsd3_readargs *argp = rqstp->rq_argp;
146 struct nfsd3_readres *resp = rqstp->rq_resp;
Greg Banks7adae482006-10-04 02:15:47 -0700147 u32 max_blocksize = svc_max_payload(rqstp);
Benjamin Coddingtonac503e42016-03-22 10:28:36 -0400148 unsigned long cnt = min(argp->count, max_blocksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500150 dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 SVCFH_fmt(&argp->fh),
152 (unsigned long) argp->count,
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500153 (unsigned long long) argp->offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
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 */
Benjamin Coddingtonac503e42016-03-22 10:28:36 -0400159 resp->count = cnt;
Jeff Laytoncd1230122007-05-09 02:34:50 -0700160 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400163 resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
164 rqstp->rq_vec, argp->vlen, &resp->count,
165 &resp->eof);
Chuck Levercc028a12020-10-02 15:52:44 -0400166 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
169/*
170 * Write data to a file
171 */
Al Viro7111c662006-10-19 23:28:45 -0700172static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200173nfsd3_proc_write(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200175 struct nfsd3_writeargs *argp = rqstp->rq_argp;
176 struct nfsd3_writeres *resp = rqstp->rq_resp;
David Shaw31dec252009-03-05 20:16:14 -0500177 unsigned long cnt = argp->len;
Chuck Lever8154ef22018-03-27 10:54:07 -0400178 unsigned int nvecs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500180 dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 SVCFH_fmt(&argp->fh),
182 argp->len,
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500183 (unsigned long long) argp->offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 argp->stable? " stable" : "");
185
186 fh_copy(&resp->fh, &argp->fh);
187 resp->committed = argp->stable;
Chuck Lever3fd95572018-07-27 11:19:05 -0400188 nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
189 &argp->first, cnt);
Chuck Lever14168d62020-10-01 18:59:54 -0400190 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);
David Shaw31dec252009-03-05 20:16:14 -0500197 resp->count = cnt;
Chuck Lever14168d62020-10-01 18:59:54 -0400198out:
Chuck Levercc028a12020-10-02 15:52:44 -0400199 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
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 */
Al Viro7111c662006-10-19 23:28:45 -0700207static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200208nfsd3_proc_create(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200210 struct nfsd3_createargs *argp = rqstp->rq_argp;
211 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 svc_fh *dirfhp, *newfhp = NULL;
213 struct iattr *attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 /* 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 */
Chuck Lever14168d62020-10-01 18:59:54 -0400234 resp->status = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
235 attr, newfhp, argp->createmode,
236 (u32 *)argp->verf, NULL, NULL);
Chuck Levercc028a12020-10-02 15:52:44 -0400237 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
240/*
241 * Make directory. This operation is not idempotent.
242 */
Al Viro7111c662006-10-19 23:28:45 -0700243static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200244nfsd3_proc_mkdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200246 struct nfsd3_createargs *argp = rqstp->rq_argp;
247 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
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);
Chuck Lever14168d62020-10-01 18:59:54 -0400257 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
258 &argp->attrs, S_IFDIR, 0, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400259 fh_unlock(&resp->dirfh);
Chuck Levercc028a12020-10-02 15:52:44 -0400260 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
Al Viro7111c662006-10-19 23:28:45 -0700263static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200264nfsd3_proc_symlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200266 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
267 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Chuck Lever14168d62020-10-01 18:59:54 -0400269 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 }
Chuck Lever38a70312018-03-27 10:54:21 -0400277
278 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
Chuck Lever11b4d662018-07-27 11:19:10 -0400279 page_address(rqstp->rq_arg.pages[0]),
Chuck Lever38a70312018-03-27 10:54:21 -0400280 argp->tlen);
Chuck Lever14168d62020-10-01 18:59:54 -0400281 if (IS_ERR(argp->tname)) {
282 resp->status = nfserrno(PTR_ERR(argp->tname));
283 goto out;
284 }
Chuck Lever38a70312018-03-27 10:54:21 -0400285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 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);
Chuck Lever14168d62020-10-01 18:59:54 -0400293 resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
294 argp->flen, argp->tname, &resp->fh);
Chuck Lever11b4d662018-07-27 11:19:10 -0400295 kfree(argp->tname);
Chuck Lever14168d62020-10-01 18:59:54 -0400296out:
Chuck Levercc028a12020-10-02 15:52:44 -0400297 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
300/*
301 * Make socket/fifo/device.
302 */
Al Viro7111c662006-10-19 23:28:45 -0700303static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200304nfsd3_proc_mknod(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200306 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
307 struct nfsd3_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700308 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
320 rdev = MKDEV(argp->major, argp->minor);
321 if (MAJOR(rdev) != argp->major ||
Chuck Lever14168d62020-10-01 18:59:54 -0400322 MINOR(rdev) != argp->minor) {
323 resp->status = nfserr_inval;
324 goto out;
325 }
326 } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
Chuck Lever66d60e32020-10-23 10:41:12 -0400327 resp->status = nfserr_badtype;
Chuck Lever14168d62020-10-01 18:59:54 -0400328 goto out;
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 type = nfs3_ftypes[argp->ftype];
Chuck Lever14168d62020-10-01 18:59:54 -0400332 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
333 &argp->attrs, type, rdev, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400334 fh_unlock(&resp->dirfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400335out:
Chuck Levercc028a12020-10-02 15:52:44 -0400336 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339/*
340 * Remove file/fifo/socket etc.
341 */
Al Viro7111c662006-10-19 23:28:45 -0700342static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200343nfsd3_proc_remove(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200345 struct nfsd3_diropargs *argp = rqstp->rq_argp;
346 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 dprintk("nfsd: REMOVE(3) %s %.*s\n",
349 SVCFH_fmt(&argp->fh),
350 argp->len,
351 argp->name);
352
353 /* Unlink. -S_IFDIR means file must not be a directory */
354 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400355 resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
356 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400357 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400358 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
361/*
362 * Remove a directory
363 */
Al Viro7111c662006-10-19 23:28:45 -0700364static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200365nfsd3_proc_rmdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200367 struct nfsd3_diropargs *argp = rqstp->rq_argp;
368 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 dprintk("nfsd: RMDIR(3) %s %.*s\n",
371 SVCFH_fmt(&argp->fh),
372 argp->len,
373 argp->name);
374
375 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400376 resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
377 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400378 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400379 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
Al Viro7111c662006-10-19 23:28:45 -0700382static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200383nfsd3_proc_rename(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200385 struct nfsd3_renameargs *argp = rqstp->rq_argp;
386 struct nfsd3_renameres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 dprintk("nfsd: RENAME(3) %s %.*s ->\n",
389 SVCFH_fmt(&argp->ffh),
390 argp->flen,
391 argp->fname);
392 dprintk("nfsd: -> %s %.*s\n",
393 SVCFH_fmt(&argp->tfh),
394 argp->tlen,
395 argp->tname);
396
397 fh_copy(&resp->ffh, &argp->ffh);
398 fh_copy(&resp->tfh, &argp->tfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400399 resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
400 &resp->tfh, argp->tname, argp->tlen);
Chuck Levercc028a12020-10-02 15:52:44 -0400401 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
Al Viro7111c662006-10-19 23:28:45 -0700404static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200405nfsd3_proc_link(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200407 struct nfsd3_linkargs *argp = rqstp->rq_argp;
408 struct nfsd3_linkres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 dprintk("nfsd: LINK(3) %s ->\n",
411 SVCFH_fmt(&argp->ffh));
412 dprintk("nfsd: -> %s %.*s\n",
413 SVCFH_fmt(&argp->tfh),
414 argp->tlen,
415 argp->tname);
416
417 fh_copy(&resp->fh, &argp->ffh);
418 fh_copy(&resp->tfh, &argp->tfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400419 resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
420 &resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400421 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424/*
425 * Read a portion of a directory.
426 */
Al Viro7111c662006-10-19 23:28:45 -0700427static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200428nfsd3_proc_readdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200430 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
431 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Murphy Zhou3c867942019-04-04 14:57:11 +0800432 int count = 0;
433 struct page **p;
434 caddr_t page_addr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
437 SVCFH_fmt(&argp->fh),
438 argp->count, (u32) argp->cookie);
439
440 /* Make sure we've room for the NULL ptr & eof flag, and shrink to
441 * client read size */
442 count = (argp->count >> 2) - 2;
443
444 /* Read directory and encode entries on the fly */
445 fh_copy(&resp->fh, &argp->fh);
446
447 resp->buflen = count;
448 resp->common.err = nfs_ok;
449 resp->buffer = argp->buffer;
450 resp->rqstp = rqstp;
Chuck Lever14168d62020-10-01 18:59:54 -0400451 resp->status = nfsd_readdir(rqstp, &resp->fh, (loff_t *)&argp->cookie,
452 &resp->common, nfs3svc_encode_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 memcpy(resp->verf, argp->verf, 8);
Murphy Zhou3c867942019-04-04 14:57:11 +0800454 count = 0;
455 for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
456 page_addr = page_address(*p);
457
458 if (((caddr_t)resp->buffer >= page_addr) &&
459 ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
460 count += (caddr_t)resp->buffer - page_addr;
461 break;
462 }
463 count += PAGE_SIZE;
464 }
465 resp->count = count >> 2;
NeilBrownb6023452019-03-04 14:08:22 +1100466 if (resp->offset) {
467 loff_t offset = argp->cookie;
468
469 if (unlikely(resp->offset1)) {
470 /* we ended up with offset on a page boundary */
471 *resp->offset = htonl(offset >> 32);
472 *resp->offset1 = htonl(offset & 0xffffffff);
473 resp->offset1 = NULL;
474 } else {
475 xdr_encode_hyper(resp->offset, offset);
476 }
477 resp->offset = NULL;
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Chuck Levercc028a12020-10-02 15:52:44 -0400480 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
483/*
484 * Read a portion of a directory, including file handles and attrs.
485 * For now, we choose to ignore the dircount parameter.
486 */
Al Viro7111c662006-10-19 23:28:45 -0700487static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200488nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200490 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
491 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700492 int count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 loff_t offset;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -0500494 struct page **p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 caddr_t page_addr = NULL;
496
497 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
498 SVCFH_fmt(&argp->fh),
499 argp->count, (u32) argp->cookie);
500
501 /* Convert byte count to number of words (i.e. >> 2),
502 * and reserve room for the NULL ptr & eof flag (-2 words) */
503 resp->count = (argp->count >> 2) - 2;
504
505 /* Read directory and encode entries on the fly */
506 fh_copy(&resp->fh, &argp->fh);
507
508 resp->common.err = nfs_ok;
509 resp->buffer = argp->buffer;
510 resp->buflen = resp->count;
511 resp->rqstp = rqstp;
512 offset = argp->cookie;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400513
Chuck Lever14168d62020-10-01 18:59:54 -0400514 resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
515 if (resp->status != nfs_ok)
516 goto out;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400517
Chuck Lever14168d62020-10-01 18:59:54 -0400518 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
519 resp->status = nfserr_notsupp;
520 goto out;
521 }
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400522
Chuck Lever14168d62020-10-01 18:59:54 -0400523 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
524 &resp->common, nfs3svc_encode_entry_plus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 memcpy(resp->verf, argp->verf, 8);
J. Bruce Fieldsafc59402012-12-10 18:01:37 -0500526 for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
527 page_addr = page_address(*p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 if (((caddr_t)resp->buffer >= page_addr) &&
530 ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
531 count += (caddr_t)resp->buffer - page_addr;
532 break;
533 }
534 count += PAGE_SIZE;
535 }
536 resp->count = count >> 2;
537 if (resp->offset) {
538 if (unlikely(resp->offset1)) {
539 /* we ended up with offset on a page boundary */
540 *resp->offset = htonl(offset >> 32);
541 *resp->offset1 = htonl(offset & 0xffffffff);
542 resp->offset1 = NULL;
543 } else {
544 xdr_encode_hyper(resp->offset, offset);
545 }
NeilBrownb6023452019-03-04 14:08:22 +1100546 resp->offset = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
548
Chuck Lever14168d62020-10-01 18:59:54 -0400549out:
Chuck Levercc028a12020-10-02 15:52:44 -0400550 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553/*
554 * Get file system stats
555 */
Al Viro7111c662006-10-19 23:28:45 -0700556static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200557nfsd3_proc_fsstat(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200559 struct nfsd_fhandle *argp = rqstp->rq_argp;
560 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 dprintk("nfsd: FSSTAT(3) %s\n",
563 SVCFH_fmt(&argp->fh));
564
Chuck Lever14168d62020-10-01 18:59:54 -0400565 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400567 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
569
570/*
571 * Get file system info
572 */
Al Viro7111c662006-10-19 23:28:45 -0700573static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200574nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200576 struct nfsd_fhandle *argp = rqstp->rq_argp;
577 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
Greg Banks7adae482006-10-04 02:15:47 -0700578 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 dprintk("nfsd: FSINFO(3) %s\n",
581 SVCFH_fmt(&argp->fh));
582
Greg Banks7adae482006-10-04 02:15:47 -0700583 resp->f_rtmax = max_blocksize;
584 resp->f_rtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 resp->f_rtmult = PAGE_SIZE;
Greg Banks7adae482006-10-04 02:15:47 -0700586 resp->f_wtmax = max_blocksize;
587 resp->f_wtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 resp->f_wtmult = PAGE_SIZE;
NeilBrownf875a792019-03-07 09:49:46 +1100589 resp->f_dtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 resp->f_maxfilesize = ~(u32) 0;
591 resp->f_properties = NFS3_FSF_DEFAULT;
592
Chuck Lever14168d62020-10-01 18:59:54 -0400593 resp->status = fh_verify(rqstp, &argp->fh, 0,
594 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 /* Check special features of the file system. May request
597 * different read/write sizes for file systems known to have
598 * problems with large blocks */
Chuck Lever14168d62020-10-01 18:59:54 -0400599 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400600 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 /* Note that we don't care for remote fs's here */
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800603 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 resp->f_properties = NFS3_FSF_BILLYBOY;
605 }
606 resp->f_maxfilesize = sb->s_maxbytes;
607 }
608
609 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400610 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
612
613/*
614 * Get pathconf info for the specified file
615 */
Al Viro7111c662006-10-19 23:28:45 -0700616static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200617nfsd3_proc_pathconf(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200619 struct nfsd_fhandle *argp = rqstp->rq_argp;
620 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 dprintk("nfsd: PATHCONF(3) %s\n",
623 SVCFH_fmt(&argp->fh));
624
625 /* Set default pathconf */
626 resp->p_link_max = 255; /* at least */
627 resp->p_name_max = 255; /* at least */
628 resp->p_no_trunc = 0;
629 resp->p_chown_restricted = 1;
630 resp->p_case_insensitive = 0;
631 resp->p_case_preserving = 1;
632
Chuck Lever14168d62020-10-01 18:59:54 -0400633 resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Chuck Lever14168d62020-10-01 18:59:54 -0400635 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400636 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 /* Note that we don't care for remote fs's here */
639 switch (sb->s_magic) {
640 case EXT2_SUPER_MAGIC:
641 resp->p_link_max = EXT2_LINK_MAX;
642 resp->p_name_max = EXT2_NAME_LEN;
643 break;
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800644 case MSDOS_SUPER_MAGIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 resp->p_case_insensitive = 1;
646 resp->p_case_preserving = 0;
647 break;
648 }
649 }
650
651 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400652 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655/*
656 * Commit a file (range) to stable storage.
657 */
Al Viro7111c662006-10-19 23:28:45 -0700658static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200659nfsd3_proc_commit(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200661 struct nfsd3_commitargs *argp = rqstp->rq_argp;
662 struct nfsd3_commitres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
665 SVCFH_fmt(&argp->fh),
666 argp->count,
667 (unsigned long long) argp->offset);
668
Chuck Lever14168d62020-10-01 18:59:54 -0400669 if (argp->offset > NFS_OFFSET_MAX) {
670 resp->status = nfserr_inval;
671 goto out;
672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400675 resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
676 argp->count, resp->verf);
677out:
Chuck Levercc028a12020-10-02 15:52:44 -0400678 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
681
682/*
683 * NFSv3 Server procedures.
684 * Only the results of non-idempotent operations are cached.
685 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#define nfs3svc_decode_fhandleargs nfs3svc_decode_fhandle
687#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
688#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
689#define nfsd3_mkdirargs nfsd3_createargs
690#define nfsd3_readdirplusargs nfsd3_readdirargs
691#define nfsd3_fhandleargs nfsd_fhandle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692#define nfsd3_attrstatres nfsd3_attrstat
693#define nfsd3_wccstatres nfsd3_attrstat
694#define nfsd3_createres nfsd3_diropres
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#define ST 1 /* status*/
697#define FH 17 /* filehandle with length */
698#define AT 21 /* attributes */
699#define pAT (1+AT) /* post attributes - conditional */
700#define WC (7+pAT) /* WCC attributes */
701
Christoph Hellwig860bda22017-05-12 16:11:49 +0200702static const struct svc_procedure nfsd_procedures3[22] = {
Yu Zhiguob9081d92009-06-09 17:33:34 +0800703 [NFS3PROC_NULL] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200704 .pc_func = nfsd3_proc_null,
Chuck Lever788f7182020-11-05 14:48:29 -0500705 .pc_decode = nfssvc_decode_voidarg,
706 .pc_encode = nfssvc_encode_voidres,
707 .pc_argsize = sizeof(struct nfsd_voidargs),
708 .pc_ressize = sizeof(struct nfsd_voidres),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800709 .pc_cachetype = RC_NOCACHE,
710 .pc_xdrressize = ST,
711 },
712 [NFS3PROC_GETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200713 .pc_func = nfsd3_proc_getattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200714 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200715 .pc_encode = nfs3svc_encode_attrstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200716 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800717 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
718 .pc_ressize = sizeof(struct nfsd3_attrstatres),
719 .pc_cachetype = RC_NOCACHE,
720 .pc_xdrressize = ST+AT,
721 },
722 [NFS3PROC_SETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200723 .pc_func = nfsd3_proc_setattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200724 .pc_decode = nfs3svc_decode_sattrargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200725 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200726 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800727 .pc_argsize = sizeof(struct nfsd3_sattrargs),
728 .pc_ressize = sizeof(struct nfsd3_wccstatres),
729 .pc_cachetype = RC_REPLBUFF,
730 .pc_xdrressize = ST+WC,
731 },
732 [NFS3PROC_LOOKUP] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200733 .pc_func = nfsd3_proc_lookup,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200734 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200735 .pc_encode = nfs3svc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200736 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800737 .pc_argsize = sizeof(struct nfsd3_diropargs),
738 .pc_ressize = sizeof(struct nfsd3_diropres),
739 .pc_cachetype = RC_NOCACHE,
740 .pc_xdrressize = ST+FH+pAT+pAT,
741 },
742 [NFS3PROC_ACCESS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200743 .pc_func = nfsd3_proc_access,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200744 .pc_decode = nfs3svc_decode_accessargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200745 .pc_encode = nfs3svc_encode_accessres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200746 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800747 .pc_argsize = sizeof(struct nfsd3_accessargs),
748 .pc_ressize = sizeof(struct nfsd3_accessres),
749 .pc_cachetype = RC_NOCACHE,
750 .pc_xdrressize = ST+pAT+1,
751 },
752 [NFS3PROC_READLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200753 .pc_func = nfsd3_proc_readlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200754 .pc_decode = nfs3svc_decode_readlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200755 .pc_encode = nfs3svc_encode_readlinkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200756 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800757 .pc_argsize = sizeof(struct nfsd3_readlinkargs),
758 .pc_ressize = sizeof(struct nfsd3_readlinkres),
759 .pc_cachetype = RC_NOCACHE,
760 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
761 },
762 [NFS3PROC_READ] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200763 .pc_func = nfsd3_proc_read,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200764 .pc_decode = nfs3svc_decode_readargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200765 .pc_encode = nfs3svc_encode_readres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200766 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800767 .pc_argsize = sizeof(struct nfsd3_readargs),
768 .pc_ressize = sizeof(struct nfsd3_readres),
769 .pc_cachetype = RC_NOCACHE,
770 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
771 },
772 [NFS3PROC_WRITE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200773 .pc_func = nfsd3_proc_write,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200774 .pc_decode = nfs3svc_decode_writeargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200775 .pc_encode = nfs3svc_encode_writeres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200776 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800777 .pc_argsize = sizeof(struct nfsd3_writeargs),
778 .pc_ressize = sizeof(struct nfsd3_writeres),
779 .pc_cachetype = RC_REPLBUFF,
780 .pc_xdrressize = ST+WC+4,
781 },
782 [NFS3PROC_CREATE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200783 .pc_func = nfsd3_proc_create,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200784 .pc_decode = nfs3svc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200785 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200786 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800787 .pc_argsize = sizeof(struct nfsd3_createargs),
788 .pc_ressize = sizeof(struct nfsd3_createres),
789 .pc_cachetype = RC_REPLBUFF,
790 .pc_xdrressize = ST+(1+FH+pAT)+WC,
791 },
792 [NFS3PROC_MKDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200793 .pc_func = nfsd3_proc_mkdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200794 .pc_decode = nfs3svc_decode_mkdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200795 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200796 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800797 .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,
801 },
802 [NFS3PROC_SYMLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200803 .pc_func = nfsd3_proc_symlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200804 .pc_decode = nfs3svc_decode_symlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200805 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200806 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800807 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
808 .pc_ressize = sizeof(struct nfsd3_createres),
809 .pc_cachetype = RC_REPLBUFF,
810 .pc_xdrressize = ST+(1+FH+pAT)+WC,
811 },
812 [NFS3PROC_MKNOD] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200813 .pc_func = nfsd3_proc_mknod,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200814 .pc_decode = nfs3svc_decode_mknodargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200815 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200816 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800817 .pc_argsize = sizeof(struct nfsd3_mknodargs),
818 .pc_ressize = sizeof(struct nfsd3_createres),
819 .pc_cachetype = RC_REPLBUFF,
820 .pc_xdrressize = ST+(1+FH+pAT)+WC,
821 },
822 [NFS3PROC_REMOVE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200823 .pc_func = nfsd3_proc_remove,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200824 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200825 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200826 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800827 .pc_argsize = sizeof(struct nfsd3_diropargs),
828 .pc_ressize = sizeof(struct nfsd3_wccstatres),
829 .pc_cachetype = RC_REPLBUFF,
830 .pc_xdrressize = ST+WC,
831 },
832 [NFS3PROC_RMDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200833 .pc_func = nfsd3_proc_rmdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200834 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200835 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200836 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800837 .pc_argsize = sizeof(struct nfsd3_diropargs),
838 .pc_ressize = sizeof(struct nfsd3_wccstatres),
839 .pc_cachetype = RC_REPLBUFF,
840 .pc_xdrressize = ST+WC,
841 },
842 [NFS3PROC_RENAME] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200843 .pc_func = nfsd3_proc_rename,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200844 .pc_decode = nfs3svc_decode_renameargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200845 .pc_encode = nfs3svc_encode_renameres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200846 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800847 .pc_argsize = sizeof(struct nfsd3_renameargs),
848 .pc_ressize = sizeof(struct nfsd3_renameres),
849 .pc_cachetype = RC_REPLBUFF,
850 .pc_xdrressize = ST+WC+WC,
851 },
852 [NFS3PROC_LINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200853 .pc_func = nfsd3_proc_link,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200854 .pc_decode = nfs3svc_decode_linkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200855 .pc_encode = nfs3svc_encode_linkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200856 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800857 .pc_argsize = sizeof(struct nfsd3_linkargs),
858 .pc_ressize = sizeof(struct nfsd3_linkres),
859 .pc_cachetype = RC_REPLBUFF,
860 .pc_xdrressize = ST+pAT+WC,
861 },
862 [NFS3PROC_READDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200863 .pc_func = nfsd3_proc_readdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200864 .pc_decode = nfs3svc_decode_readdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200865 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200866 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800867 .pc_argsize = sizeof(struct nfsd3_readdirargs),
868 .pc_ressize = sizeof(struct nfsd3_readdirres),
869 .pc_cachetype = RC_NOCACHE,
870 },
871 [NFS3PROC_READDIRPLUS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200872 .pc_func = nfsd3_proc_readdirplus,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200873 .pc_decode = nfs3svc_decode_readdirplusargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200874 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200875 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800876 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
877 .pc_ressize = sizeof(struct nfsd3_readdirres),
878 .pc_cachetype = RC_NOCACHE,
879 },
880 [NFS3PROC_FSSTAT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200881 .pc_func = nfsd3_proc_fsstat,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200882 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200883 .pc_encode = nfs3svc_encode_fsstatres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800884 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
885 .pc_ressize = sizeof(struct nfsd3_fsstatres),
886 .pc_cachetype = RC_NOCACHE,
887 .pc_xdrressize = ST+pAT+2*6+1,
888 },
889 [NFS3PROC_FSINFO] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200890 .pc_func = nfsd3_proc_fsinfo,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200891 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200892 .pc_encode = nfs3svc_encode_fsinfores,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800893 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
894 .pc_ressize = sizeof(struct nfsd3_fsinfores),
895 .pc_cachetype = RC_NOCACHE,
896 .pc_xdrressize = ST+pAT+12,
897 },
898 [NFS3PROC_PATHCONF] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200899 .pc_func = nfsd3_proc_pathconf,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200900 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200901 .pc_encode = nfs3svc_encode_pathconfres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800902 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
903 .pc_ressize = sizeof(struct nfsd3_pathconfres),
904 .pc_cachetype = RC_NOCACHE,
905 .pc_xdrressize = ST+pAT+6,
906 },
907 [NFS3PROC_COMMIT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200908 .pc_func = nfsd3_proc_commit,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200909 .pc_decode = nfs3svc_decode_commitargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200910 .pc_encode = nfs3svc_encode_commitres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200911 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800912 .pc_argsize = sizeof(struct nfsd3_commitargs),
913 .pc_ressize = sizeof(struct nfsd3_commitres),
914 .pc_cachetype = RC_NOCACHE,
915 .pc_xdrressize = ST+WC+2,
916 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917};
918
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200919static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
Christoph Hellwige9679182017-05-12 16:21:37 +0200920const struct svc_version nfsd_version3 = {
921 .vs_vers = 3,
922 .vs_nproc = 22,
923 .vs_proc = nfsd_procedures3,
924 .vs_dispatch = nfsd_dispatch,
925 .vs_count = nfsd_count3,
926 .vs_xdrsize = NFS3_SVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927};