blob: 15dac36ca852e1eb268c8089ecdf43f9dd25d4d6 [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{
Chuck Lever224c1c82020-10-24 12:51:18 -0400127 struct nfsd_fhandle *argp = rqstp->rq_argp;
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200128 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 Lever9a9c8922020-10-22 15:18:40 -0400135 resp->pages = rqstp->rq_next_page++;
136 resp->status = nfsd_readlink(rqstp, &resp->fh,
137 page_address(*resp->pages), &resp->len);
Chuck Levercc028a12020-10-02 15:52:44 -0400138 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
141/*
142 * Read a portion of a file.
143 */
Al Viro7111c662006-10-19 23:28:45 -0700144static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200145nfsd3_proc_read(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200147 struct nfsd3_readargs *argp = rqstp->rq_argp;
148 struct nfsd3_readres *resp = rqstp->rq_resp;
Chuck Leverbe63bd22020-10-20 14:34:40 -0400149 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500155 dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 SVCFH_fmt(&argp->fh),
157 (unsigned long) argp->count,
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500158 (unsigned long long) argp->offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Chuck Leverbe63bd22020-10-20 14:34:40 -0400160 v = 0;
161 len = argp->count;
Chuck Levercc9bcda2020-10-22 15:23:50 -0400162 resp->pages = rqstp->rq_next_page;
Chuck Leverbe63bd22020-10-20 14:34:40 -0400163 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* Obtain buffer pointer for payload.
173 * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
174 * + 1 (xdr opaque byte count) = 26
175 */
Chuck Leverbe63bd22020-10-20 14:34:40 -0400176 resp->count = argp->count;
Jeff Laytoncd1230122007-05-09 02:34:50 -0700177 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400180 resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
Chuck Leverbe63bd22020-10-20 14:34:40 -0400181 rqstp->rq_vec, v, &resp->count, &resp->eof);
Chuck Levercc028a12020-10-02 15:52:44 -0400182 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
185/*
186 * Write data to a file
187 */
Al Viro7111c662006-10-19 23:28:45 -0700188static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200189nfsd3_proc_write(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200191 struct nfsd3_writeargs *argp = rqstp->rq_argp;
192 struct nfsd3_writeres *resp = rqstp->rq_resp;
David Shaw31dec252009-03-05 20:16:14 -0500193 unsigned long cnt = argp->len;
Chuck Lever8154ef22018-03-27 10:54:07 -0400194 unsigned int nvecs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500196 dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 SVCFH_fmt(&argp->fh),
198 argp->len,
J. Bruce Fields18b631f2010-11-29 15:28:10 -0500199 (unsigned long long) argp->offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 argp->stable? " stable" : "");
201
202 fh_copy(&resp->fh, &argp->fh);
203 resp->committed = argp->stable;
Chuck Leverdae9a6c2021-09-30 17:06:21 -0400204 nvecs = svc_fill_write_vector(rqstp, &argp->payload);
Chuck Lever14168d62020-10-01 18:59:54 -0400205 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);
David Shaw31dec252009-03-05 20:16:14 -0500212 resp->count = cnt;
Chuck Lever14168d62020-10-01 18:59:54 -0400213out:
Chuck Levercc028a12020-10-02 15:52:44 -0400214 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
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 */
Al Viro7111c662006-10-19 23:28:45 -0700222static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200223nfsd3_proc_create(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200225 struct nfsd3_createargs *argp = rqstp->rq_argp;
226 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 svc_fh *dirfhp, *newfhp = NULL;
228 struct iattr *attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 /* 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 */
Chuck Lever14168d62020-10-01 18:59:54 -0400249 resp->status = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
250 attr, newfhp, argp->createmode,
251 (u32 *)argp->verf, NULL, NULL);
Chuck Levercc028a12020-10-02 15:52:44 -0400252 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255/*
256 * Make directory. This operation is not idempotent.
257 */
Al Viro7111c662006-10-19 23:28:45 -0700258static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200259nfsd3_proc_mkdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200261 struct nfsd3_createargs *argp = rqstp->rq_argp;
262 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
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);
Chuck Lever14168d62020-10-01 18:59:54 -0400272 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
273 &argp->attrs, S_IFDIR, 0, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400274 fh_unlock(&resp->dirfh);
Chuck Levercc028a12020-10-02 15:52:44 -0400275 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Al Viro7111c662006-10-19 23:28:45 -0700278static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200279nfsd3_proc_symlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200281 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
282 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Chuck Lever14168d62020-10-01 18:59:54 -0400284 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 }
Chuck Lever38a70312018-03-27 10:54:21 -0400292
293 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
Chuck Lever11b4d662018-07-27 11:19:10 -0400294 page_address(rqstp->rq_arg.pages[0]),
Chuck Lever38a70312018-03-27 10:54:21 -0400295 argp->tlen);
Chuck Lever14168d62020-10-01 18:59:54 -0400296 if (IS_ERR(argp->tname)) {
297 resp->status = nfserrno(PTR_ERR(argp->tname));
298 goto out;
299 }
Chuck Lever38a70312018-03-27 10:54:21 -0400300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 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);
Chuck Lever14168d62020-10-01 18:59:54 -0400308 resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
309 argp->flen, argp->tname, &resp->fh);
Chuck Lever11b4d662018-07-27 11:19:10 -0400310 kfree(argp->tname);
Chuck Lever14168d62020-10-01 18:59:54 -0400311out:
Chuck Levercc028a12020-10-02 15:52:44 -0400312 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
315/*
316 * Make socket/fifo/device.
317 */
Al Viro7111c662006-10-19 23:28:45 -0700318static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200319nfsd3_proc_mknod(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200321 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
322 struct nfsd3_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700323 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
335 rdev = MKDEV(argp->major, argp->minor);
336 if (MAJOR(rdev) != argp->major ||
Chuck Lever14168d62020-10-01 18:59:54 -0400337 MINOR(rdev) != argp->minor) {
338 resp->status = nfserr_inval;
339 goto out;
340 }
341 } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
Chuck Lever66d60e32020-10-23 10:41:12 -0400342 resp->status = nfserr_badtype;
Chuck Lever14168d62020-10-01 18:59:54 -0400343 goto out;
344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 type = nfs3_ftypes[argp->ftype];
Chuck Lever14168d62020-10-01 18:59:54 -0400347 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
348 &argp->attrs, type, rdev, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400349 fh_unlock(&resp->dirfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400350out:
Chuck Levercc028a12020-10-02 15:52:44 -0400351 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
354/*
355 * Remove file/fifo/socket etc.
356 */
Al Viro7111c662006-10-19 23:28:45 -0700357static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200358nfsd3_proc_remove(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200360 struct nfsd3_diropargs *argp = rqstp->rq_argp;
361 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
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);
Chuck Lever14168d62020-10-01 18:59:54 -0400370 resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
371 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400372 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400373 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
376/*
377 * Remove a directory
378 */
Al Viro7111c662006-10-19 23:28:45 -0700379static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200380nfsd3_proc_rmdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200382 struct nfsd3_diropargs *argp = rqstp->rq_argp;
383 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
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);
Chuck Lever14168d62020-10-01 18:59:54 -0400391 resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
392 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400393 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400394 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
Al Viro7111c662006-10-19 23:28:45 -0700397static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200398nfsd3_proc_rename(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200400 struct nfsd3_renameargs *argp = rqstp->rq_argp;
401 struct nfsd3_renameres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
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);
Chuck Lever14168d62020-10-01 18:59:54 -0400414 resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
415 &resp->tfh, argp->tname, argp->tlen);
Chuck Levercc028a12020-10-02 15:52:44 -0400416 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
Al Viro7111c662006-10-19 23:28:45 -0700419static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200420nfsd3_proc_link(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200422 struct nfsd3_linkargs *argp = rqstp->rq_argp;
423 struct nfsd3_linkres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
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);
Chuck Lever14168d62020-10-01 18:59:54 -0400434 resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
435 &resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400436 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Chuck Lever40116eb2020-11-17 09:50:23 -0500439static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
440 struct nfsd3_readdirres *resp,
Chuck Lever53b11192021-12-16 11:12:11 -0500441 u32 count)
Chuck Lever40116eb2020-11-17 09:50:23 -0500442{
Chuck Lever7f87fc22020-10-22 19:46:58 -0400443 struct xdr_buf *buf = &resp->dirlist;
444 struct xdr_stream *xdr = &resp->xdr;
445
Chuck Lever53b11192021-12-16 11:12:11 -0500446 count = clamp(count, (u32)(XDR_UNIT * 2), svc_max_payload(rqstp));
Chuck Lever40116eb2020-11-17 09:50:23 -0500447
Chuck Lever7f87fc22020-10-22 19:46:58 -0400448 memset(buf, 0, sizeof(*buf));
Chuck Lever40116eb2020-11-17 09:50:23 -0500449
Chuck Lever7f87fc22020-10-22 19:46:58 -0400450 /* Reserve room for the NULL ptr & eof flag (-2 words) */
451 buf->buflen = count - XDR_UNIT * 2;
452 buf->pages = rqstp->rq_next_page;
Chuck Lever53b11192021-12-16 11:12:11 -0500453 rqstp->rq_next_page += (buf->buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400454
455 /* This is xdr_init_encode(), but it assumes that
456 * the head kvec has already been consumed. */
457 xdr_set_scratch_buffer(xdr, NULL, 0);
458 xdr->buf = buf;
459 xdr->page_ptr = buf->pages;
460 xdr->iov = NULL;
461 xdr->p = page_address(*buf->pages);
Chuck Lever53b11192021-12-16 11:12:11 -0500462 xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
Chuck Lever7f87fc22020-10-22 19:46:58 -0400463 xdr->rqst = NULL;
Chuck Lever40116eb2020-11-17 09:50:23 -0500464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/*
467 * Read a portion of a directory.
468 */
Al Viro7111c662006-10-19 23:28:45 -0700469static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200470nfsd3_proc_readdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200472 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
473 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500474 loff_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
477 SVCFH_fmt(&argp->fh),
478 argp->count, (u32) argp->cookie);
479
Chuck Lever40116eb2020-11-17 09:50:23 -0500480 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 fh_copy(&resp->fh, &argp->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 resp->common.err = nfs_ok;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400484 resp->cookie_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 resp->rqstp = rqstp;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500486 offset = argp->cookie;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500487 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
Chuck Lever7f87fc22020-10-22 19:46:58 -0400488 &resp->common, nfs3svc_encode_entry3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 memcpy(resp->verf, argp->verf, 8);
Chuck Levera161e6c2020-11-10 09:57:14 -0500490 nfs3svc_encode_cookie3(resp, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Chuck Lever76ed0dd2021-01-15 09:28:44 -0500492 /* Recycle only pages that were part of the reply */
493 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
494
Chuck Levercc028a12020-10-02 15:52:44 -0400495 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
498/*
499 * Read a portion of a directory, including file handles and attrs.
500 * For now, we choose to ignore the dircount parameter.
501 */
Al Viro7111c662006-10-19 23:28:45 -0700502static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200503nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200505 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
506 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 loff_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
510 SVCFH_fmt(&argp->fh),
511 argp->count, (u32) argp->cookie);
512
Chuck Lever40116eb2020-11-17 09:50:23 -0500513 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 fh_copy(&resp->fh, &argp->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 resp->common.err = nfs_ok;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400517 resp->cookie_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 resp->rqstp = rqstp;
519 offset = argp->cookie;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400520
Chuck Lever14168d62020-10-01 18:59:54 -0400521 resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
522 if (resp->status != nfs_ok)
523 goto out;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400524
Chuck Lever14168d62020-10-01 18:59:54 -0400525 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
526 resp->status = nfserr_notsupp;
527 goto out;
528 }
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400529
Chuck Lever14168d62020-10-01 18:59:54 -0400530 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
Chuck Lever7f87fc22020-10-22 19:46:58 -0400531 &resp->common, nfs3svc_encode_entryplus3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 memcpy(resp->verf, argp->verf, 8);
Chuck Levera161e6c2020-11-10 09:57:14 -0500533 nfs3svc_encode_cookie3(resp, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Chuck Lever76ed0dd2021-01-15 09:28:44 -0500535 /* Recycle only pages that were part of the reply */
536 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
537
Chuck Lever14168d62020-10-01 18:59:54 -0400538out:
Chuck Levercc028a12020-10-02 15:52:44 -0400539 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
542/*
543 * Get file system stats
544 */
Al Viro7111c662006-10-19 23:28:45 -0700545static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200546nfsd3_proc_fsstat(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200548 struct nfsd_fhandle *argp = rqstp->rq_argp;
549 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 dprintk("nfsd: FSSTAT(3) %s\n",
552 SVCFH_fmt(&argp->fh));
553
Chuck Lever14168d62020-10-01 18:59:54 -0400554 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400556 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559/*
560 * Get file system info
561 */
Al Viro7111c662006-10-19 23:28:45 -0700562static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200563nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200565 struct nfsd_fhandle *argp = rqstp->rq_argp;
566 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
Greg Banks7adae482006-10-04 02:15:47 -0700567 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 dprintk("nfsd: FSINFO(3) %s\n",
570 SVCFH_fmt(&argp->fh));
571
Greg Banks7adae482006-10-04 02:15:47 -0700572 resp->f_rtmax = max_blocksize;
573 resp->f_rtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 resp->f_rtmult = PAGE_SIZE;
Greg Banks7adae482006-10-04 02:15:47 -0700575 resp->f_wtmax = max_blocksize;
576 resp->f_wtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 resp->f_wtmult = PAGE_SIZE;
NeilBrownf875a792019-03-07 09:49:46 +1100578 resp->f_dtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 resp->f_maxfilesize = ~(u32) 0;
580 resp->f_properties = NFS3_FSF_DEFAULT;
581
Chuck Lever14168d62020-10-01 18:59:54 -0400582 resp->status = fh_verify(rqstp, &argp->fh, 0,
583 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 /* Check special features of the file system. May request
586 * different read/write sizes for file systems known to have
587 * problems with large blocks */
Chuck Lever14168d62020-10-01 18:59:54 -0400588 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400589 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 /* Note that we don't care for remote fs's here */
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800592 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 resp->f_properties = NFS3_FSF_BILLYBOY;
594 }
595 resp->f_maxfilesize = sb->s_maxbytes;
596 }
597
598 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400599 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
602/*
603 * Get pathconf info for the specified file
604 */
Al Viro7111c662006-10-19 23:28:45 -0700605static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200606nfsd3_proc_pathconf(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200608 struct nfsd_fhandle *argp = rqstp->rq_argp;
609 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 dprintk("nfsd: PATHCONF(3) %s\n",
612 SVCFH_fmt(&argp->fh));
613
614 /* Set default pathconf */
615 resp->p_link_max = 255; /* at least */
616 resp->p_name_max = 255; /* at least */
617 resp->p_no_trunc = 0;
618 resp->p_chown_restricted = 1;
619 resp->p_case_insensitive = 0;
620 resp->p_case_preserving = 1;
621
Chuck Lever14168d62020-10-01 18:59:54 -0400622 resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Chuck Lever14168d62020-10-01 18:59:54 -0400624 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400625 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 /* Note that we don't care for remote fs's here */
628 switch (sb->s_magic) {
629 case EXT2_SUPER_MAGIC:
630 resp->p_link_max = EXT2_LINK_MAX;
631 resp->p_name_max = EXT2_NAME_LEN;
632 break;
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800633 case MSDOS_SUPER_MAGIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 resp->p_case_insensitive = 1;
635 resp->p_case_preserving = 0;
636 break;
637 }
638 }
639
640 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400641 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644/*
645 * Commit a file (range) to stable storage.
646 */
Al Viro7111c662006-10-19 23:28:45 -0700647static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200648nfsd3_proc_commit(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200650 struct nfsd3_commitargs *argp = rqstp->rq_argp;
651 struct nfsd3_commitres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
654 SVCFH_fmt(&argp->fh),
655 argp->count,
656 (unsigned long long) argp->offset);
657
Chuck Lever14168d62020-10-01 18:59:54 -0400658 if (argp->offset > NFS_OFFSET_MAX) {
659 resp->status = nfserr_inval;
660 goto out;
661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400664 resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
665 argp->count, resp->verf);
666out:
Chuck Levercc028a12020-10-02 15:52:44 -0400667 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670
671/*
672 * NFSv3 Server procedures.
673 * Only the results of non-idempotent operations are cached.
674 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
676#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
677#define nfsd3_mkdirargs nfsd3_createargs
678#define nfsd3_readdirplusargs nfsd3_readdirargs
679#define nfsd3_fhandleargs nfsd_fhandle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#define nfsd3_attrstatres nfsd3_attrstat
681#define nfsd3_wccstatres nfsd3_attrstat
682#define nfsd3_createres nfsd3_diropres
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684#define ST 1 /* status*/
685#define FH 17 /* filehandle with length */
686#define AT 21 /* attributes */
687#define pAT (1+AT) /* post attributes - conditional */
688#define WC (7+pAT) /* WCC attributes */
689
Christoph Hellwig860bda22017-05-12 16:11:49 +0200690static const struct svc_procedure nfsd_procedures3[22] = {
Yu Zhiguob9081d92009-06-09 17:33:34 +0800691 [NFS3PROC_NULL] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200692 .pc_func = nfsd3_proc_null,
Chuck Lever788f7182020-11-05 14:48:29 -0500693 .pc_decode = nfssvc_decode_voidarg,
694 .pc_encode = nfssvc_encode_voidres,
695 .pc_argsize = sizeof(struct nfsd_voidargs),
696 .pc_ressize = sizeof(struct nfsd_voidres),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800697 .pc_cachetype = RC_NOCACHE,
698 .pc_xdrressize = ST,
Chuck Lever2289e872020-09-17 17:22:49 -0400699 .pc_name = "NULL",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800700 },
701 [NFS3PROC_GETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200702 .pc_func = nfsd3_proc_getattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200703 .pc_decode = nfs3svc_decode_fhandleargs,
Chuck Lever2c42f802020-10-21 11:58:41 -0400704 .pc_encode = nfs3svc_encode_getattrres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200705 .pc_release = nfs3svc_release_fhandle,
Chuck Lever95753632020-10-20 14:30:02 -0400706 .pc_argsize = sizeof(struct nfsd_fhandle),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800707 .pc_ressize = sizeof(struct nfsd3_attrstatres),
708 .pc_cachetype = RC_NOCACHE,
709 .pc_xdrressize = ST+AT,
Chuck Lever2289e872020-09-17 17:22:49 -0400710 .pc_name = "GETATTR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800711 },
712 [NFS3PROC_SETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200713 .pc_func = nfsd3_proc_setattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200714 .pc_decode = nfs3svc_decode_sattrargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200715 .pc_encode = nfs3svc_encode_wccstatres,
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_sattrargs),
718 .pc_ressize = sizeof(struct nfsd3_wccstatres),
719 .pc_cachetype = RC_REPLBUFF,
720 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400721 .pc_name = "SETATTR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800722 },
723 [NFS3PROC_LOOKUP] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200724 .pc_func = nfsd3_proc_lookup,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200725 .pc_decode = nfs3svc_decode_diropargs,
Chuck Lever5cf35332020-10-22 14:46:58 -0400726 .pc_encode = nfs3svc_encode_lookupres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200727 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800728 .pc_argsize = sizeof(struct nfsd3_diropargs),
729 .pc_ressize = sizeof(struct nfsd3_diropres),
730 .pc_cachetype = RC_NOCACHE,
731 .pc_xdrressize = ST+FH+pAT+pAT,
Chuck Lever2289e872020-09-17 17:22:49 -0400732 .pc_name = "LOOKUP",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800733 },
734 [NFS3PROC_ACCESS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200735 .pc_func = nfsd3_proc_access,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200736 .pc_decode = nfs3svc_decode_accessargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200737 .pc_encode = nfs3svc_encode_accessres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200738 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800739 .pc_argsize = sizeof(struct nfsd3_accessargs),
740 .pc_ressize = sizeof(struct nfsd3_accessres),
741 .pc_cachetype = RC_NOCACHE,
742 .pc_xdrressize = ST+pAT+1,
Chuck Lever2289e872020-09-17 17:22:49 -0400743 .pc_name = "ACCESS",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800744 },
745 [NFS3PROC_READLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200746 .pc_func = nfsd3_proc_readlink,
Chuck Lever224c1c82020-10-24 12:51:18 -0400747 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200748 .pc_encode = nfs3svc_encode_readlinkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200749 .pc_release = nfs3svc_release_fhandle,
Chuck Lever224c1c82020-10-24 12:51:18 -0400750 .pc_argsize = sizeof(struct nfsd_fhandle),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800751 .pc_ressize = sizeof(struct nfsd3_readlinkres),
752 .pc_cachetype = RC_NOCACHE,
753 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
Chuck Lever2289e872020-09-17 17:22:49 -0400754 .pc_name = "READLINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800755 },
756 [NFS3PROC_READ] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200757 .pc_func = nfsd3_proc_read,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200758 .pc_decode = nfs3svc_decode_readargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200759 .pc_encode = nfs3svc_encode_readres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200760 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800761 .pc_argsize = sizeof(struct nfsd3_readargs),
762 .pc_ressize = sizeof(struct nfsd3_readres),
763 .pc_cachetype = RC_NOCACHE,
764 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
Chuck Lever2289e872020-09-17 17:22:49 -0400765 .pc_name = "READ",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800766 },
767 [NFS3PROC_WRITE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200768 .pc_func = nfsd3_proc_write,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200769 .pc_decode = nfs3svc_decode_writeargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200770 .pc_encode = nfs3svc_encode_writeres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200771 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800772 .pc_argsize = sizeof(struct nfsd3_writeargs),
773 .pc_ressize = sizeof(struct nfsd3_writeres),
774 .pc_cachetype = RC_REPLBUFF,
775 .pc_xdrressize = ST+WC+4,
Chuck Lever2289e872020-09-17 17:22:49 -0400776 .pc_name = "WRITE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800777 },
778 [NFS3PROC_CREATE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200779 .pc_func = nfsd3_proc_create,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200780 .pc_decode = nfs3svc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200781 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200782 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800783 .pc_argsize = sizeof(struct nfsd3_createargs),
784 .pc_ressize = sizeof(struct nfsd3_createres),
785 .pc_cachetype = RC_REPLBUFF,
786 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400787 .pc_name = "CREATE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800788 },
789 [NFS3PROC_MKDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200790 .pc_func = nfsd3_proc_mkdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200791 .pc_decode = nfs3svc_decode_mkdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200792 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200793 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800794 .pc_argsize = sizeof(struct nfsd3_mkdirargs),
795 .pc_ressize = sizeof(struct nfsd3_createres),
796 .pc_cachetype = RC_REPLBUFF,
797 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400798 .pc_name = "MKDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800799 },
800 [NFS3PROC_SYMLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200801 .pc_func = nfsd3_proc_symlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200802 .pc_decode = nfs3svc_decode_symlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200803 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200804 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800805 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
806 .pc_ressize = sizeof(struct nfsd3_createres),
807 .pc_cachetype = RC_REPLBUFF,
808 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400809 .pc_name = "SYMLINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800810 },
811 [NFS3PROC_MKNOD] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200812 .pc_func = nfsd3_proc_mknod,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200813 .pc_decode = nfs3svc_decode_mknodargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200814 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200815 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800816 .pc_argsize = sizeof(struct nfsd3_mknodargs),
817 .pc_ressize = sizeof(struct nfsd3_createres),
818 .pc_cachetype = RC_REPLBUFF,
819 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400820 .pc_name = "MKNOD",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800821 },
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,
Chuck Lever2289e872020-09-17 17:22:49 -0400831 .pc_name = "REMOVE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800832 },
833 [NFS3PROC_RMDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200834 .pc_func = nfsd3_proc_rmdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200835 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200836 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200837 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800838 .pc_argsize = sizeof(struct nfsd3_diropargs),
839 .pc_ressize = sizeof(struct nfsd3_wccstatres),
840 .pc_cachetype = RC_REPLBUFF,
841 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400842 .pc_name = "RMDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800843 },
844 [NFS3PROC_RENAME] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200845 .pc_func = nfsd3_proc_rename,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200846 .pc_decode = nfs3svc_decode_renameargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200847 .pc_encode = nfs3svc_encode_renameres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200848 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800849 .pc_argsize = sizeof(struct nfsd3_renameargs),
850 .pc_ressize = sizeof(struct nfsd3_renameres),
851 .pc_cachetype = RC_REPLBUFF,
852 .pc_xdrressize = ST+WC+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400853 .pc_name = "RENAME",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800854 },
855 [NFS3PROC_LINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200856 .pc_func = nfsd3_proc_link,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200857 .pc_decode = nfs3svc_decode_linkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200858 .pc_encode = nfs3svc_encode_linkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200859 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800860 .pc_argsize = sizeof(struct nfsd3_linkargs),
861 .pc_ressize = sizeof(struct nfsd3_linkres),
862 .pc_cachetype = RC_REPLBUFF,
863 .pc_xdrressize = ST+pAT+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400864 .pc_name = "LINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800865 },
866 [NFS3PROC_READDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200867 .pc_func = nfsd3_proc_readdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200868 .pc_decode = nfs3svc_decode_readdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200869 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200870 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800871 .pc_argsize = sizeof(struct nfsd3_readdirargs),
872 .pc_ressize = sizeof(struct nfsd3_readdirres),
873 .pc_cachetype = RC_NOCACHE,
Chuck Lever2289e872020-09-17 17:22:49 -0400874 .pc_name = "READDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800875 },
876 [NFS3PROC_READDIRPLUS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200877 .pc_func = nfsd3_proc_readdirplus,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200878 .pc_decode = nfs3svc_decode_readdirplusargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200879 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200880 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800881 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
882 .pc_ressize = sizeof(struct nfsd3_readdirres),
883 .pc_cachetype = RC_NOCACHE,
Chuck Lever2289e872020-09-17 17:22:49 -0400884 .pc_name = "READDIRPLUS",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800885 },
886 [NFS3PROC_FSSTAT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200887 .pc_func = nfsd3_proc_fsstat,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200888 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200889 .pc_encode = nfs3svc_encode_fsstatres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800890 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
891 .pc_ressize = sizeof(struct nfsd3_fsstatres),
892 .pc_cachetype = RC_NOCACHE,
893 .pc_xdrressize = ST+pAT+2*6+1,
Chuck Lever2289e872020-09-17 17:22:49 -0400894 .pc_name = "FSSTAT",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800895 },
896 [NFS3PROC_FSINFO] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200897 .pc_func = nfsd3_proc_fsinfo,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200898 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200899 .pc_encode = nfs3svc_encode_fsinfores,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800900 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
901 .pc_ressize = sizeof(struct nfsd3_fsinfores),
902 .pc_cachetype = RC_NOCACHE,
903 .pc_xdrressize = ST+pAT+12,
Chuck Lever2289e872020-09-17 17:22:49 -0400904 .pc_name = "FSINFO",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800905 },
906 [NFS3PROC_PATHCONF] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200907 .pc_func = nfsd3_proc_pathconf,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200908 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200909 .pc_encode = nfs3svc_encode_pathconfres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800910 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
911 .pc_ressize = sizeof(struct nfsd3_pathconfres),
912 .pc_cachetype = RC_NOCACHE,
913 .pc_xdrressize = ST+pAT+6,
Chuck Lever2289e872020-09-17 17:22:49 -0400914 .pc_name = "PATHCONF",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800915 },
916 [NFS3PROC_COMMIT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200917 .pc_func = nfsd3_proc_commit,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200918 .pc_decode = nfs3svc_decode_commitargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200919 .pc_encode = nfs3svc_encode_commitres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200920 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800921 .pc_argsize = sizeof(struct nfsd3_commitargs),
922 .pc_ressize = sizeof(struct nfsd3_commitres),
923 .pc_cachetype = RC_NOCACHE,
924 .pc_xdrressize = ST+WC+2,
Chuck Lever2289e872020-09-17 17:22:49 -0400925 .pc_name = "COMMIT",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800926 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927};
928
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200929static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
Christoph Hellwige9679182017-05-12 16:21:37 +0200930const struct svc_version nfsd_version3 = {
931 .vs_vers = 3,
932 .vs_nproc = 22,
933 .vs_proc = nfsd_procedures3,
934 .vs_dispatch = nfsd_dispatch,
935 .vs_count = nfsd_count3,
936 .vs_xdrsize = NFS3_SVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937};