blob: 17715a6c7a4090f2bb7ac3f4dd66659137ee5e8a [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 Lever3fd95572018-07-27 11:19:05 -0400204 nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
205 &argp->first, cnt);
Chuck Lever14168d62020-10-01 18:59:54 -0400206 if (!nvecs) {
207 resp->status = nfserr_io;
208 goto out;
209 }
210 resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
211 rqstp->rq_vec, nvecs, &cnt,
212 resp->committed, resp->verf);
David Shaw31dec252009-03-05 20:16:14 -0500213 resp->count = cnt;
Chuck Lever14168d62020-10-01 18:59:54 -0400214out:
Chuck Levercc028a12020-10-02 15:52:44 -0400215 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218/*
219 * With NFSv3, CREATE processing is a lot easier than with NFSv2.
220 * At least in theory; we'll see how it fares in practice when the
221 * first reports about SunOS compatibility problems start to pour in...
222 */
Al Viro7111c662006-10-19 23:28:45 -0700223static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200224nfsd3_proc_create(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200226 struct nfsd3_createargs *argp = rqstp->rq_argp;
227 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 svc_fh *dirfhp, *newfhp = NULL;
229 struct iattr *attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 dprintk("nfsd: CREATE(3) %s %.*s\n",
232 SVCFH_fmt(&argp->fh),
233 argp->len,
234 argp->name);
235
236 dirfhp = fh_copy(&resp->dirfh, &argp->fh);
237 newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
238 attr = &argp->attrs;
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 /* Unfudge the mode bits */
241 attr->ia_mode &= ~S_IFMT;
242 if (!(attr->ia_valid & ATTR_MODE)) {
243 attr->ia_valid |= ATTR_MODE;
244 attr->ia_mode = S_IFREG;
245 } else {
246 attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
247 }
248
249 /* Now create the file and set attributes */
Chuck Lever14168d62020-10-01 18:59:54 -0400250 resp->status = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
251 attr, newfhp, argp->createmode,
252 (u32 *)argp->verf, NULL, NULL);
Chuck Levercc028a12020-10-02 15:52:44 -0400253 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
256/*
257 * Make directory. This operation is not idempotent.
258 */
Al Viro7111c662006-10-19 23:28:45 -0700259static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200260nfsd3_proc_mkdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200262 struct nfsd3_createargs *argp = rqstp->rq_argp;
263 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 dprintk("nfsd: MKDIR(3) %s %.*s\n",
266 SVCFH_fmt(&argp->fh),
267 argp->len,
268 argp->name);
269
270 argp->attrs.ia_valid &= ~ATTR_SIZE;
271 fh_copy(&resp->dirfh, &argp->fh);
272 fh_init(&resp->fh, NFS3_FHSIZE);
Chuck Lever14168d62020-10-01 18:59:54 -0400273 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
274 &argp->attrs, S_IFDIR, 0, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400275 fh_unlock(&resp->dirfh);
Chuck Levercc028a12020-10-02 15:52:44 -0400276 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Al Viro7111c662006-10-19 23:28:45 -0700279static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200280nfsd3_proc_symlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200282 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
283 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Chuck Lever14168d62020-10-01 18:59:54 -0400285 if (argp->tlen == 0) {
286 resp->status = nfserr_inval;
287 goto out;
288 }
289 if (argp->tlen > NFS3_MAXPATHLEN) {
290 resp->status = nfserr_nametoolong;
291 goto out;
292 }
Chuck Lever38a70312018-03-27 10:54:21 -0400293
294 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
Chuck Lever11b4d662018-07-27 11:19:10 -0400295 page_address(rqstp->rq_arg.pages[0]),
Chuck Lever38a70312018-03-27 10:54:21 -0400296 argp->tlen);
Chuck Lever14168d62020-10-01 18:59:54 -0400297 if (IS_ERR(argp->tname)) {
298 resp->status = nfserrno(PTR_ERR(argp->tname));
299 goto out;
300 }
Chuck Lever38a70312018-03-27 10:54:21 -0400301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
303 SVCFH_fmt(&argp->ffh),
304 argp->flen, argp->fname,
305 argp->tlen, argp->tname);
306
307 fh_copy(&resp->dirfh, &argp->ffh);
308 fh_init(&resp->fh, NFS3_FHSIZE);
Chuck Lever14168d62020-10-01 18:59:54 -0400309 resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
310 argp->flen, argp->tname, &resp->fh);
Chuck Lever11b4d662018-07-27 11:19:10 -0400311 kfree(argp->tname);
Chuck Lever14168d62020-10-01 18:59:54 -0400312out:
Chuck Levercc028a12020-10-02 15:52:44 -0400313 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316/*
317 * Make socket/fifo/device.
318 */
Al Viro7111c662006-10-19 23:28:45 -0700319static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200320nfsd3_proc_mknod(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200322 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
323 struct nfsd3_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700324 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 dev_t rdev = 0;
326
327 dprintk("nfsd: MKNOD(3) %s %.*s\n",
328 SVCFH_fmt(&argp->fh),
329 argp->len,
330 argp->name);
331
332 fh_copy(&resp->dirfh, &argp->fh);
333 fh_init(&resp->fh, NFS3_FHSIZE);
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
336 rdev = MKDEV(argp->major, argp->minor);
337 if (MAJOR(rdev) != argp->major ||
Chuck Lever14168d62020-10-01 18:59:54 -0400338 MINOR(rdev) != argp->minor) {
339 resp->status = nfserr_inval;
340 goto out;
341 }
342 } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
Chuck Lever66d60e32020-10-23 10:41:12 -0400343 resp->status = nfserr_badtype;
Chuck Lever14168d62020-10-01 18:59:54 -0400344 goto out;
345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 type = nfs3_ftypes[argp->ftype];
Chuck Lever14168d62020-10-01 18:59:54 -0400348 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
349 &argp->attrs, type, rdev, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400350 fh_unlock(&resp->dirfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400351out:
Chuck Levercc028a12020-10-02 15:52:44 -0400352 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355/*
356 * Remove file/fifo/socket etc.
357 */
Al Viro7111c662006-10-19 23:28:45 -0700358static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200359nfsd3_proc_remove(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200361 struct nfsd3_diropargs *argp = rqstp->rq_argp;
362 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 dprintk("nfsd: REMOVE(3) %s %.*s\n",
365 SVCFH_fmt(&argp->fh),
366 argp->len,
367 argp->name);
368
369 /* Unlink. -S_IFDIR means file must not be a directory */
370 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400371 resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
372 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400373 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400374 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375}
376
377/*
378 * Remove a directory
379 */
Al Viro7111c662006-10-19 23:28:45 -0700380static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200381nfsd3_proc_rmdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200383 struct nfsd3_diropargs *argp = rqstp->rq_argp;
384 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 dprintk("nfsd: RMDIR(3) %s %.*s\n",
387 SVCFH_fmt(&argp->fh),
388 argp->len,
389 argp->name);
390
391 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400392 resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
393 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400394 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400395 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Al Viro7111c662006-10-19 23:28:45 -0700398static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200399nfsd3_proc_rename(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200401 struct nfsd3_renameargs *argp = rqstp->rq_argp;
402 struct nfsd3_renameres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 dprintk("nfsd: RENAME(3) %s %.*s ->\n",
405 SVCFH_fmt(&argp->ffh),
406 argp->flen,
407 argp->fname);
408 dprintk("nfsd: -> %s %.*s\n",
409 SVCFH_fmt(&argp->tfh),
410 argp->tlen,
411 argp->tname);
412
413 fh_copy(&resp->ffh, &argp->ffh);
414 fh_copy(&resp->tfh, &argp->tfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400415 resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
416 &resp->tfh, argp->tname, argp->tlen);
Chuck Levercc028a12020-10-02 15:52:44 -0400417 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Al Viro7111c662006-10-19 23:28:45 -0700420static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200421nfsd3_proc_link(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200423 struct nfsd3_linkargs *argp = rqstp->rq_argp;
424 struct nfsd3_linkres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 dprintk("nfsd: LINK(3) %s ->\n",
427 SVCFH_fmt(&argp->ffh));
428 dprintk("nfsd: -> %s %.*s\n",
429 SVCFH_fmt(&argp->tfh),
430 argp->tlen,
431 argp->tname);
432
433 fh_copy(&resp->fh, &argp->ffh);
434 fh_copy(&resp->tfh, &argp->tfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400435 resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
436 &resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400437 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
Chuck Lever40116eb2020-11-17 09:50:23 -0500440static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
441 struct nfsd3_readdirres *resp,
442 int count)
443{
Chuck Lever7f87fc22020-10-22 19:46:58 -0400444 struct xdr_buf *buf = &resp->dirlist;
445 struct xdr_stream *xdr = &resp->xdr;
446
Chuck Lever40116eb2020-11-17 09:50:23 -0500447 count = min_t(u32, count, svc_max_payload(rqstp));
448
Chuck Lever7f87fc22020-10-22 19:46:58 -0400449 memset(buf, 0, sizeof(*buf));
Chuck Lever40116eb2020-11-17 09:50:23 -0500450
Chuck Lever7f87fc22020-10-22 19:46:58 -0400451 /* Reserve room for the NULL ptr & eof flag (-2 words) */
452 buf->buflen = count - XDR_UNIT * 2;
453 buf->pages = rqstp->rq_next_page;
Chuck Lever40116eb2020-11-17 09:50:23 -0500454 while (count > 0) {
455 rqstp->rq_next_page++;
456 count -= PAGE_SIZE;
457 }
Chuck Lever7f87fc22020-10-22 19:46:58 -0400458
459 /* This is xdr_init_encode(), but it assumes that
460 * the head kvec has already been consumed. */
461 xdr_set_scratch_buffer(xdr, NULL, 0);
462 xdr->buf = buf;
463 xdr->page_ptr = buf->pages;
464 xdr->iov = NULL;
465 xdr->p = page_address(*buf->pages);
466 xdr->end = xdr->p + (PAGE_SIZE >> 2);
467 xdr->rqst = NULL;
Chuck Lever40116eb2020-11-17 09:50:23 -0500468}
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470/*
471 * Read a portion of a directory.
472 */
Al Viro7111c662006-10-19 23:28:45 -0700473static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200474nfsd3_proc_readdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200476 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
477 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500478 loff_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
481 SVCFH_fmt(&argp->fh),
482 argp->count, (u32) argp->cookie);
483
Chuck Lever40116eb2020-11-17 09:50:23 -0500484 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 fh_copy(&resp->fh, &argp->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 resp->common.err = nfs_ok;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400488 resp->cookie_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 resp->rqstp = rqstp;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500490 offset = argp->cookie;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500491 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
Chuck Lever7f87fc22020-10-22 19:46:58 -0400492 &resp->common, nfs3svc_encode_entry3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 memcpy(resp->verf, argp->verf, 8);
Chuck Levera161e6c2020-11-10 09:57:14 -0500494 nfs3svc_encode_cookie3(resp, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Chuck Lever76ed0dd2021-01-15 09:28:44 -0500496 /* Recycle only pages that were part of the reply */
497 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
498
Chuck Levercc028a12020-10-02 15:52:44 -0400499 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500}
501
502/*
503 * Read a portion of a directory, including file handles and attrs.
504 * For now, we choose to ignore the dircount parameter.
505 */
Al Viro7111c662006-10-19 23:28:45 -0700506static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200507nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200509 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
510 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 loff_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
514 SVCFH_fmt(&argp->fh),
515 argp->count, (u32) argp->cookie);
516
Chuck Lever40116eb2020-11-17 09:50:23 -0500517 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 fh_copy(&resp->fh, &argp->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 resp->common.err = nfs_ok;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400521 resp->cookie_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 resp->rqstp = rqstp;
523 offset = argp->cookie;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400524
Chuck Lever14168d62020-10-01 18:59:54 -0400525 resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
526 if (resp->status != nfs_ok)
527 goto out;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400528
Chuck Lever14168d62020-10-01 18:59:54 -0400529 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
530 resp->status = nfserr_notsupp;
531 goto out;
532 }
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400533
Chuck Lever14168d62020-10-01 18:59:54 -0400534 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
Chuck Lever7f87fc22020-10-22 19:46:58 -0400535 &resp->common, nfs3svc_encode_entryplus3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 memcpy(resp->verf, argp->verf, 8);
Chuck Levera161e6c2020-11-10 09:57:14 -0500537 nfs3svc_encode_cookie3(resp, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Chuck Lever76ed0dd2021-01-15 09:28:44 -0500539 /* Recycle only pages that were part of the reply */
540 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
541
Chuck Lever14168d62020-10-01 18:59:54 -0400542out:
Chuck Levercc028a12020-10-02 15:52:44 -0400543 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
546/*
547 * Get file system stats
548 */
Al Viro7111c662006-10-19 23:28:45 -0700549static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200550nfsd3_proc_fsstat(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200552 struct nfsd_fhandle *argp = rqstp->rq_argp;
553 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 dprintk("nfsd: FSSTAT(3) %s\n",
556 SVCFH_fmt(&argp->fh));
557
Chuck Lever14168d62020-10-01 18:59:54 -0400558 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400560 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563/*
564 * Get file system info
565 */
Al Viro7111c662006-10-19 23:28:45 -0700566static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200567nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200569 struct nfsd_fhandle *argp = rqstp->rq_argp;
570 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
Greg Banks7adae482006-10-04 02:15:47 -0700571 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 dprintk("nfsd: FSINFO(3) %s\n",
574 SVCFH_fmt(&argp->fh));
575
Greg Banks7adae482006-10-04 02:15:47 -0700576 resp->f_rtmax = max_blocksize;
577 resp->f_rtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 resp->f_rtmult = PAGE_SIZE;
Greg Banks7adae482006-10-04 02:15:47 -0700579 resp->f_wtmax = max_blocksize;
580 resp->f_wtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 resp->f_wtmult = PAGE_SIZE;
NeilBrownf875a792019-03-07 09:49:46 +1100582 resp->f_dtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 resp->f_maxfilesize = ~(u32) 0;
584 resp->f_properties = NFS3_FSF_DEFAULT;
585
Chuck Lever14168d62020-10-01 18:59:54 -0400586 resp->status = fh_verify(rqstp, &argp->fh, 0,
587 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 /* Check special features of the file system. May request
590 * different read/write sizes for file systems known to have
591 * problems with large blocks */
Chuck Lever14168d62020-10-01 18:59:54 -0400592 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400593 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 /* Note that we don't care for remote fs's here */
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800596 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 resp->f_properties = NFS3_FSF_BILLYBOY;
598 }
599 resp->f_maxfilesize = sb->s_maxbytes;
600 }
601
602 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400603 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606/*
607 * Get pathconf info for the specified file
608 */
Al Viro7111c662006-10-19 23:28:45 -0700609static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200610nfsd3_proc_pathconf(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200612 struct nfsd_fhandle *argp = rqstp->rq_argp;
613 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 dprintk("nfsd: PATHCONF(3) %s\n",
616 SVCFH_fmt(&argp->fh));
617
618 /* Set default pathconf */
619 resp->p_link_max = 255; /* at least */
620 resp->p_name_max = 255; /* at least */
621 resp->p_no_trunc = 0;
622 resp->p_chown_restricted = 1;
623 resp->p_case_insensitive = 0;
624 resp->p_case_preserving = 1;
625
Chuck Lever14168d62020-10-01 18:59:54 -0400626 resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Chuck Lever14168d62020-10-01 18:59:54 -0400628 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400629 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 /* Note that we don't care for remote fs's here */
632 switch (sb->s_magic) {
633 case EXT2_SUPER_MAGIC:
634 resp->p_link_max = EXT2_LINK_MAX;
635 resp->p_name_max = EXT2_NAME_LEN;
636 break;
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800637 case MSDOS_SUPER_MAGIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 resp->p_case_insensitive = 1;
639 resp->p_case_preserving = 0;
640 break;
641 }
642 }
643
644 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400645 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648/*
649 * Commit a file (range) to stable storage.
650 */
Al Viro7111c662006-10-19 23:28:45 -0700651static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200652nfsd3_proc_commit(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200654 struct nfsd3_commitargs *argp = rqstp->rq_argp;
655 struct nfsd3_commitres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
658 SVCFH_fmt(&argp->fh),
659 argp->count,
660 (unsigned long long) argp->offset);
661
Chuck Lever14168d62020-10-01 18:59:54 -0400662 if (argp->offset > NFS_OFFSET_MAX) {
663 resp->status = nfserr_inval;
664 goto out;
665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
667 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400668 resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
669 argp->count, resp->verf);
670out:
Chuck Levercc028a12020-10-02 15:52:44 -0400671 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
674
675/*
676 * NFSv3 Server procedures.
677 * Only the results of non-idempotent operations are cached.
678 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
680#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
681#define nfsd3_mkdirargs nfsd3_createargs
682#define nfsd3_readdirplusargs nfsd3_readdirargs
683#define nfsd3_fhandleargs nfsd_fhandle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684#define nfsd3_attrstatres nfsd3_attrstat
685#define nfsd3_wccstatres nfsd3_attrstat
686#define nfsd3_createres nfsd3_diropres
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688#define ST 1 /* status*/
689#define FH 17 /* filehandle with length */
690#define AT 21 /* attributes */
691#define pAT (1+AT) /* post attributes - conditional */
692#define WC (7+pAT) /* WCC attributes */
693
Christoph Hellwig860bda22017-05-12 16:11:49 +0200694static const struct svc_procedure nfsd_procedures3[22] = {
Yu Zhiguob9081d92009-06-09 17:33:34 +0800695 [NFS3PROC_NULL] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200696 .pc_func = nfsd3_proc_null,
Chuck Lever788f7182020-11-05 14:48:29 -0500697 .pc_decode = nfssvc_decode_voidarg,
698 .pc_encode = nfssvc_encode_voidres,
699 .pc_argsize = sizeof(struct nfsd_voidargs),
700 .pc_ressize = sizeof(struct nfsd_voidres),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800701 .pc_cachetype = RC_NOCACHE,
702 .pc_xdrressize = ST,
Chuck Lever2289e872020-09-17 17:22:49 -0400703 .pc_name = "NULL",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800704 },
705 [NFS3PROC_GETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200706 .pc_func = nfsd3_proc_getattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200707 .pc_decode = nfs3svc_decode_fhandleargs,
Chuck Lever2c42f802020-10-21 11:58:41 -0400708 .pc_encode = nfs3svc_encode_getattrres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200709 .pc_release = nfs3svc_release_fhandle,
Chuck Lever95753632020-10-20 14:30:02 -0400710 .pc_argsize = sizeof(struct nfsd_fhandle),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800711 .pc_ressize = sizeof(struct nfsd3_attrstatres),
712 .pc_cachetype = RC_NOCACHE,
713 .pc_xdrressize = ST+AT,
Chuck Lever2289e872020-09-17 17:22:49 -0400714 .pc_name = "GETATTR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800715 },
716 [NFS3PROC_SETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200717 .pc_func = nfsd3_proc_setattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200718 .pc_decode = nfs3svc_decode_sattrargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200719 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200720 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800721 .pc_argsize = sizeof(struct nfsd3_sattrargs),
722 .pc_ressize = sizeof(struct nfsd3_wccstatres),
723 .pc_cachetype = RC_REPLBUFF,
724 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400725 .pc_name = "SETATTR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800726 },
727 [NFS3PROC_LOOKUP] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200728 .pc_func = nfsd3_proc_lookup,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200729 .pc_decode = nfs3svc_decode_diropargs,
Chuck Lever5cf35332020-10-22 14:46:58 -0400730 .pc_encode = nfs3svc_encode_lookupres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200731 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800732 .pc_argsize = sizeof(struct nfsd3_diropargs),
733 .pc_ressize = sizeof(struct nfsd3_diropres),
734 .pc_cachetype = RC_NOCACHE,
735 .pc_xdrressize = ST+FH+pAT+pAT,
Chuck Lever2289e872020-09-17 17:22:49 -0400736 .pc_name = "LOOKUP",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800737 },
738 [NFS3PROC_ACCESS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200739 .pc_func = nfsd3_proc_access,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200740 .pc_decode = nfs3svc_decode_accessargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200741 .pc_encode = nfs3svc_encode_accessres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200742 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800743 .pc_argsize = sizeof(struct nfsd3_accessargs),
744 .pc_ressize = sizeof(struct nfsd3_accessres),
745 .pc_cachetype = RC_NOCACHE,
746 .pc_xdrressize = ST+pAT+1,
Chuck Lever2289e872020-09-17 17:22:49 -0400747 .pc_name = "ACCESS",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800748 },
749 [NFS3PROC_READLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200750 .pc_func = nfsd3_proc_readlink,
Chuck Lever224c1c82020-10-24 12:51:18 -0400751 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200752 .pc_encode = nfs3svc_encode_readlinkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200753 .pc_release = nfs3svc_release_fhandle,
Chuck Lever224c1c82020-10-24 12:51:18 -0400754 .pc_argsize = sizeof(struct nfsd_fhandle),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800755 .pc_ressize = sizeof(struct nfsd3_readlinkres),
756 .pc_cachetype = RC_NOCACHE,
757 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
Chuck Lever2289e872020-09-17 17:22:49 -0400758 .pc_name = "READLINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800759 },
760 [NFS3PROC_READ] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200761 .pc_func = nfsd3_proc_read,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200762 .pc_decode = nfs3svc_decode_readargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200763 .pc_encode = nfs3svc_encode_readres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200764 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800765 .pc_argsize = sizeof(struct nfsd3_readargs),
766 .pc_ressize = sizeof(struct nfsd3_readres),
767 .pc_cachetype = RC_NOCACHE,
768 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
Chuck Lever2289e872020-09-17 17:22:49 -0400769 .pc_name = "READ",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800770 },
771 [NFS3PROC_WRITE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200772 .pc_func = nfsd3_proc_write,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200773 .pc_decode = nfs3svc_decode_writeargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200774 .pc_encode = nfs3svc_encode_writeres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200775 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800776 .pc_argsize = sizeof(struct nfsd3_writeargs),
777 .pc_ressize = sizeof(struct nfsd3_writeres),
778 .pc_cachetype = RC_REPLBUFF,
779 .pc_xdrressize = ST+WC+4,
Chuck Lever2289e872020-09-17 17:22:49 -0400780 .pc_name = "WRITE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800781 },
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,
Chuck Lever2289e872020-09-17 17:22:49 -0400791 .pc_name = "CREATE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800792 },
793 [NFS3PROC_MKDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200794 .pc_func = nfsd3_proc_mkdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200795 .pc_decode = nfs3svc_decode_mkdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200796 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200797 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800798 .pc_argsize = sizeof(struct nfsd3_mkdirargs),
799 .pc_ressize = sizeof(struct nfsd3_createres),
800 .pc_cachetype = RC_REPLBUFF,
801 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400802 .pc_name = "MKDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800803 },
804 [NFS3PROC_SYMLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200805 .pc_func = nfsd3_proc_symlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200806 .pc_decode = nfs3svc_decode_symlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200807 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200808 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800809 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
810 .pc_ressize = sizeof(struct nfsd3_createres),
811 .pc_cachetype = RC_REPLBUFF,
812 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400813 .pc_name = "SYMLINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800814 },
815 [NFS3PROC_MKNOD] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200816 .pc_func = nfsd3_proc_mknod,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200817 .pc_decode = nfs3svc_decode_mknodargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200818 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200819 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800820 .pc_argsize = sizeof(struct nfsd3_mknodargs),
821 .pc_ressize = sizeof(struct nfsd3_createres),
822 .pc_cachetype = RC_REPLBUFF,
823 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400824 .pc_name = "MKNOD",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800825 },
826 [NFS3PROC_REMOVE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200827 .pc_func = nfsd3_proc_remove,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200828 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200829 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200830 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800831 .pc_argsize = sizeof(struct nfsd3_diropargs),
832 .pc_ressize = sizeof(struct nfsd3_wccstatres),
833 .pc_cachetype = RC_REPLBUFF,
834 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400835 .pc_name = "REMOVE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800836 },
837 [NFS3PROC_RMDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200838 .pc_func = nfsd3_proc_rmdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200839 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200840 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200841 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800842 .pc_argsize = sizeof(struct nfsd3_diropargs),
843 .pc_ressize = sizeof(struct nfsd3_wccstatres),
844 .pc_cachetype = RC_REPLBUFF,
845 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400846 .pc_name = "RMDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800847 },
848 [NFS3PROC_RENAME] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200849 .pc_func = nfsd3_proc_rename,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200850 .pc_decode = nfs3svc_decode_renameargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200851 .pc_encode = nfs3svc_encode_renameres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200852 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800853 .pc_argsize = sizeof(struct nfsd3_renameargs),
854 .pc_ressize = sizeof(struct nfsd3_renameres),
855 .pc_cachetype = RC_REPLBUFF,
856 .pc_xdrressize = ST+WC+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400857 .pc_name = "RENAME",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800858 },
859 [NFS3PROC_LINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200860 .pc_func = nfsd3_proc_link,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200861 .pc_decode = nfs3svc_decode_linkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200862 .pc_encode = nfs3svc_encode_linkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200863 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800864 .pc_argsize = sizeof(struct nfsd3_linkargs),
865 .pc_ressize = sizeof(struct nfsd3_linkres),
866 .pc_cachetype = RC_REPLBUFF,
867 .pc_xdrressize = ST+pAT+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400868 .pc_name = "LINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800869 },
870 [NFS3PROC_READDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200871 .pc_func = nfsd3_proc_readdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200872 .pc_decode = nfs3svc_decode_readdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200873 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200874 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800875 .pc_argsize = sizeof(struct nfsd3_readdirargs),
876 .pc_ressize = sizeof(struct nfsd3_readdirres),
877 .pc_cachetype = RC_NOCACHE,
Chuck Lever2289e872020-09-17 17:22:49 -0400878 .pc_name = "READDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800879 },
880 [NFS3PROC_READDIRPLUS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200881 .pc_func = nfsd3_proc_readdirplus,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200882 .pc_decode = nfs3svc_decode_readdirplusargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200883 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200884 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800885 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
886 .pc_ressize = sizeof(struct nfsd3_readdirres),
887 .pc_cachetype = RC_NOCACHE,
Chuck Lever2289e872020-09-17 17:22:49 -0400888 .pc_name = "READDIRPLUS",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800889 },
890 [NFS3PROC_FSSTAT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200891 .pc_func = nfsd3_proc_fsstat,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200892 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200893 .pc_encode = nfs3svc_encode_fsstatres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800894 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
895 .pc_ressize = sizeof(struct nfsd3_fsstatres),
896 .pc_cachetype = RC_NOCACHE,
897 .pc_xdrressize = ST+pAT+2*6+1,
Chuck Lever2289e872020-09-17 17:22:49 -0400898 .pc_name = "FSSTAT",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800899 },
900 [NFS3PROC_FSINFO] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200901 .pc_func = nfsd3_proc_fsinfo,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200902 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200903 .pc_encode = nfs3svc_encode_fsinfores,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800904 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
905 .pc_ressize = sizeof(struct nfsd3_fsinfores),
906 .pc_cachetype = RC_NOCACHE,
907 .pc_xdrressize = ST+pAT+12,
Chuck Lever2289e872020-09-17 17:22:49 -0400908 .pc_name = "FSINFO",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800909 },
910 [NFS3PROC_PATHCONF] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200911 .pc_func = nfsd3_proc_pathconf,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200912 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200913 .pc_encode = nfs3svc_encode_pathconfres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800914 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
915 .pc_ressize = sizeof(struct nfsd3_pathconfres),
916 .pc_cachetype = RC_NOCACHE,
917 .pc_xdrressize = ST+pAT+6,
Chuck Lever2289e872020-09-17 17:22:49 -0400918 .pc_name = "PATHCONF",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800919 },
920 [NFS3PROC_COMMIT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200921 .pc_func = nfsd3_proc_commit,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200922 .pc_decode = nfs3svc_decode_commitargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200923 .pc_encode = nfs3svc_encode_commitres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200924 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800925 .pc_argsize = sizeof(struct nfsd3_commitargs),
926 .pc_ressize = sizeof(struct nfsd3_commitres),
927 .pc_cachetype = RC_NOCACHE,
928 .pc_xdrressize = ST+WC+2,
Chuck Lever2289e872020-09-17 17:22:49 -0400929 .pc_name = "COMMIT",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800930 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931};
932
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200933static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
Christoph Hellwige9679182017-05-12 16:21:37 +0200934const struct svc_version nfsd_version3 = {
935 .vs_vers = 3,
936 .vs_nproc = 22,
937 .vs_proc = nfsd_procedures3,
938 .vs_dispatch = nfsd_dispatch,
939 .vs_count = nfsd_count3,
940 .vs_xdrsize = NFS3_SVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941};