blob: 8ef53f6726ec8b26b9f027c73785141e86fdb1fe [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 Lever6a2f7742021-12-21 11:52:06 -0500205
Chuck Lever14168d62020-10-01 18:59:54 -0400206 resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
207 rqstp->rq_vec, nvecs, &cnt,
208 resp->committed, resp->verf);
David Shaw31dec252009-03-05 20:16:14 -0500209 resp->count = cnt;
Chuck Levercc028a12020-10-02 15:52:44 -0400210 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
213/*
214 * With NFSv3, CREATE processing is a lot easier than with NFSv2.
215 * At least in theory; we'll see how it fares in practice when the
216 * first reports about SunOS compatibility problems start to pour in...
217 */
Al Viro7111c662006-10-19 23:28:45 -0700218static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200219nfsd3_proc_create(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200221 struct nfsd3_createargs *argp = rqstp->rq_argp;
222 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 svc_fh *dirfhp, *newfhp = NULL;
224 struct iattr *attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 dprintk("nfsd: CREATE(3) %s %.*s\n",
227 SVCFH_fmt(&argp->fh),
228 argp->len,
229 argp->name);
230
231 dirfhp = fh_copy(&resp->dirfh, &argp->fh);
232 newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
233 attr = &argp->attrs;
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 /* Unfudge the mode bits */
236 attr->ia_mode &= ~S_IFMT;
237 if (!(attr->ia_valid & ATTR_MODE)) {
238 attr->ia_valid |= ATTR_MODE;
239 attr->ia_mode = S_IFREG;
240 } else {
241 attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
242 }
243
244 /* Now create the file and set attributes */
Chuck Lever14168d62020-10-01 18:59:54 -0400245 resp->status = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
246 attr, newfhp, argp->createmode,
247 (u32 *)argp->verf, NULL, NULL);
Chuck Levercc028a12020-10-02 15:52:44 -0400248 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
251/*
252 * Make directory. This operation is not idempotent.
253 */
Al Viro7111c662006-10-19 23:28:45 -0700254static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200255nfsd3_proc_mkdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200257 struct nfsd3_createargs *argp = rqstp->rq_argp;
258 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 dprintk("nfsd: MKDIR(3) %s %.*s\n",
261 SVCFH_fmt(&argp->fh),
262 argp->len,
263 argp->name);
264
265 argp->attrs.ia_valid &= ~ATTR_SIZE;
266 fh_copy(&resp->dirfh, &argp->fh);
267 fh_init(&resp->fh, NFS3_FHSIZE);
Chuck Lever14168d62020-10-01 18:59:54 -0400268 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
269 &argp->attrs, S_IFDIR, 0, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400270 fh_unlock(&resp->dirfh);
Chuck Levercc028a12020-10-02 15:52:44 -0400271 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
Al Viro7111c662006-10-19 23:28:45 -0700274static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200275nfsd3_proc_symlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200277 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
278 struct nfsd3_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Chuck Lever14168d62020-10-01 18:59:54 -0400280 if (argp->tlen == 0) {
281 resp->status = nfserr_inval;
282 goto out;
283 }
284 if (argp->tlen > NFS3_MAXPATHLEN) {
285 resp->status = nfserr_nametoolong;
286 goto out;
287 }
Chuck Lever38a70312018-03-27 10:54:21 -0400288
289 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
Chuck Lever11b4d662018-07-27 11:19:10 -0400290 page_address(rqstp->rq_arg.pages[0]),
Chuck Lever38a70312018-03-27 10:54:21 -0400291 argp->tlen);
Chuck Lever14168d62020-10-01 18:59:54 -0400292 if (IS_ERR(argp->tname)) {
293 resp->status = nfserrno(PTR_ERR(argp->tname));
294 goto out;
295 }
Chuck Lever38a70312018-03-27 10:54:21 -0400296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
298 SVCFH_fmt(&argp->ffh),
299 argp->flen, argp->fname,
300 argp->tlen, argp->tname);
301
302 fh_copy(&resp->dirfh, &argp->ffh);
303 fh_init(&resp->fh, NFS3_FHSIZE);
Chuck Lever14168d62020-10-01 18:59:54 -0400304 resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
305 argp->flen, argp->tname, &resp->fh);
Chuck Lever11b4d662018-07-27 11:19:10 -0400306 kfree(argp->tname);
Chuck Lever14168d62020-10-01 18:59:54 -0400307out:
Chuck Levercc028a12020-10-02 15:52:44 -0400308 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
311/*
312 * Make socket/fifo/device.
313 */
Al Viro7111c662006-10-19 23:28:45 -0700314static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200315nfsd3_proc_mknod(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200317 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
318 struct nfsd3_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700319 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 dev_t rdev = 0;
321
322 dprintk("nfsd: MKNOD(3) %s %.*s\n",
323 SVCFH_fmt(&argp->fh),
324 argp->len,
325 argp->name);
326
327 fh_copy(&resp->dirfh, &argp->fh);
328 fh_init(&resp->fh, NFS3_FHSIZE);
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
331 rdev = MKDEV(argp->major, argp->minor);
332 if (MAJOR(rdev) != argp->major ||
Chuck Lever14168d62020-10-01 18:59:54 -0400333 MINOR(rdev) != argp->minor) {
334 resp->status = nfserr_inval;
335 goto out;
336 }
337 } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
Chuck Lever66d60e32020-10-23 10:41:12 -0400338 resp->status = nfserr_badtype;
Chuck Lever14168d62020-10-01 18:59:54 -0400339 goto out;
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 type = nfs3_ftypes[argp->ftype];
Chuck Lever14168d62020-10-01 18:59:54 -0400343 resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
344 &argp->attrs, type, rdev, &resp->fh);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400345 fh_unlock(&resp->dirfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400346out:
Chuck Levercc028a12020-10-02 15:52:44 -0400347 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350/*
351 * Remove file/fifo/socket etc.
352 */
Al Viro7111c662006-10-19 23:28:45 -0700353static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200354nfsd3_proc_remove(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200356 struct nfsd3_diropargs *argp = rqstp->rq_argp;
357 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 dprintk("nfsd: REMOVE(3) %s %.*s\n",
360 SVCFH_fmt(&argp->fh),
361 argp->len,
362 argp->name);
363
364 /* Unlink. -S_IFDIR means file must not be a directory */
365 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400366 resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
367 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400368 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400369 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
372/*
373 * Remove a directory
374 */
Al Viro7111c662006-10-19 23:28:45 -0700375static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200376nfsd3_proc_rmdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200378 struct nfsd3_diropargs *argp = rqstp->rq_argp;
379 struct nfsd3_attrstat *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 dprintk("nfsd: RMDIR(3) %s %.*s\n",
382 SVCFH_fmt(&argp->fh),
383 argp->len,
384 argp->name);
385
386 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400387 resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
388 argp->name, argp->len);
Chuck Lever43a9aa62010-07-06 16:53:34 -0400389 fh_unlock(&resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400390 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
Al Viro7111c662006-10-19 23:28:45 -0700393static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200394nfsd3_proc_rename(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200396 struct nfsd3_renameargs *argp = rqstp->rq_argp;
397 struct nfsd3_renameres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 dprintk("nfsd: RENAME(3) %s %.*s ->\n",
400 SVCFH_fmt(&argp->ffh),
401 argp->flen,
402 argp->fname);
403 dprintk("nfsd: -> %s %.*s\n",
404 SVCFH_fmt(&argp->tfh),
405 argp->tlen,
406 argp->tname);
407
408 fh_copy(&resp->ffh, &argp->ffh);
409 fh_copy(&resp->tfh, &argp->tfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400410 resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
411 &resp->tfh, argp->tname, argp->tlen);
Chuck Levercc028a12020-10-02 15:52:44 -0400412 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Al Viro7111c662006-10-19 23:28:45 -0700415static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200416nfsd3_proc_link(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200418 struct nfsd3_linkargs *argp = rqstp->rq_argp;
419 struct nfsd3_linkres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 dprintk("nfsd: LINK(3) %s ->\n",
422 SVCFH_fmt(&argp->ffh));
423 dprintk("nfsd: -> %s %.*s\n",
424 SVCFH_fmt(&argp->tfh),
425 argp->tlen,
426 argp->tname);
427
428 fh_copy(&resp->fh, &argp->ffh);
429 fh_copy(&resp->tfh, &argp->tfh);
Chuck Lever14168d62020-10-01 18:59:54 -0400430 resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
431 &resp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400432 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
Chuck Lever40116eb2020-11-17 09:50:23 -0500435static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
436 struct nfsd3_readdirres *resp,
Chuck Lever53b11192021-12-16 11:12:11 -0500437 u32 count)
Chuck Lever40116eb2020-11-17 09:50:23 -0500438{
Chuck Lever7f87fc22020-10-22 19:46:58 -0400439 struct xdr_buf *buf = &resp->dirlist;
440 struct xdr_stream *xdr = &resp->xdr;
441
Chuck Lever53b11192021-12-16 11:12:11 -0500442 count = clamp(count, (u32)(XDR_UNIT * 2), svc_max_payload(rqstp));
Chuck Lever40116eb2020-11-17 09:50:23 -0500443
Chuck Lever7f87fc22020-10-22 19:46:58 -0400444 memset(buf, 0, sizeof(*buf));
Chuck Lever40116eb2020-11-17 09:50:23 -0500445
Chuck Lever7f87fc22020-10-22 19:46:58 -0400446 /* Reserve room for the NULL ptr & eof flag (-2 words) */
447 buf->buflen = count - XDR_UNIT * 2;
448 buf->pages = rqstp->rq_next_page;
Chuck Lever53b11192021-12-16 11:12:11 -0500449 rqstp->rq_next_page += (buf->buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400450
451 /* This is xdr_init_encode(), but it assumes that
452 * the head kvec has already been consumed. */
453 xdr_set_scratch_buffer(xdr, NULL, 0);
454 xdr->buf = buf;
455 xdr->page_ptr = buf->pages;
456 xdr->iov = NULL;
457 xdr->p = page_address(*buf->pages);
Chuck Lever53b11192021-12-16 11:12:11 -0500458 xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
Chuck Lever7f87fc22020-10-22 19:46:58 -0400459 xdr->rqst = NULL;
Chuck Lever40116eb2020-11-17 09:50:23 -0500460}
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462/*
463 * Read a portion of a directory.
464 */
Al Viro7111c662006-10-19 23:28:45 -0700465static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200466nfsd3_proc_readdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200468 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
469 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500470 loff_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
473 SVCFH_fmt(&argp->fh),
474 argp->count, (u32) argp->cookie);
475
Chuck Lever40116eb2020-11-17 09:50:23 -0500476 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 fh_copy(&resp->fh, &argp->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 resp->common.err = nfs_ok;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400480 resp->cookie_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 resp->rqstp = rqstp;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500482 offset = argp->cookie;
Chuck Lever0a8f37f2020-11-10 10:24:39 -0500483 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
Chuck Lever7f87fc22020-10-22 19:46:58 -0400484 &resp->common, nfs3svc_encode_entry3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 memcpy(resp->verf, argp->verf, 8);
Chuck Levera161e6c2020-11-10 09:57:14 -0500486 nfs3svc_encode_cookie3(resp, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Chuck Lever76ed0dd2021-01-15 09:28:44 -0500488 /* Recycle only pages that were part of the reply */
489 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
490
Chuck Levercc028a12020-10-02 15:52:44 -0400491 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494/*
495 * Read a portion of a directory, including file handles and attrs.
496 * For now, we choose to ignore the dircount parameter.
497 */
Al Viro7111c662006-10-19 23:28:45 -0700498static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200499nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200501 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
502 struct nfsd3_readdirres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 loff_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
506 SVCFH_fmt(&argp->fh),
507 argp->count, (u32) argp->cookie);
508
Chuck Lever40116eb2020-11-17 09:50:23 -0500509 nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 fh_copy(&resp->fh, &argp->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 resp->common.err = nfs_ok;
Chuck Lever7f87fc22020-10-22 19:46:58 -0400513 resp->cookie_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 resp->rqstp = rqstp;
515 offset = argp->cookie;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400516
Chuck Lever14168d62020-10-01 18:59:54 -0400517 resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
518 if (resp->status != nfs_ok)
519 goto out;
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400520
Chuck Lever14168d62020-10-01 18:59:54 -0400521 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
522 resp->status = nfserr_notsupp;
523 goto out;
524 }
Rajesh Ghanekar18c01ab2014-08-01 22:17:30 -0400525
Chuck Lever14168d62020-10-01 18:59:54 -0400526 resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
Chuck Lever7f87fc22020-10-22 19:46:58 -0400527 &resp->common, nfs3svc_encode_entryplus3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 memcpy(resp->verf, argp->verf, 8);
Chuck Levera161e6c2020-11-10 09:57:14 -0500529 nfs3svc_encode_cookie3(resp, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Chuck Lever76ed0dd2021-01-15 09:28:44 -0500531 /* Recycle only pages that were part of the reply */
532 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
533
Chuck Lever14168d62020-10-01 18:59:54 -0400534out:
Chuck Levercc028a12020-10-02 15:52:44 -0400535 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
538/*
539 * Get file system stats
540 */
Al Viro7111c662006-10-19 23:28:45 -0700541static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200542nfsd3_proc_fsstat(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200544 struct nfsd_fhandle *argp = rqstp->rq_argp;
545 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 dprintk("nfsd: FSSTAT(3) %s\n",
548 SVCFH_fmt(&argp->fh));
549
Chuck Lever14168d62020-10-01 18:59:54 -0400550 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400552 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553}
554
555/*
556 * Get file system info
557 */
Al Viro7111c662006-10-19 23:28:45 -0700558static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200559nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200561 struct nfsd_fhandle *argp = rqstp->rq_argp;
562 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
Greg Banks7adae482006-10-04 02:15:47 -0700563 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 dprintk("nfsd: FSINFO(3) %s\n",
566 SVCFH_fmt(&argp->fh));
567
Greg Banks7adae482006-10-04 02:15:47 -0700568 resp->f_rtmax = max_blocksize;
569 resp->f_rtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 resp->f_rtmult = PAGE_SIZE;
Greg Banks7adae482006-10-04 02:15:47 -0700571 resp->f_wtmax = max_blocksize;
572 resp->f_wtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 resp->f_wtmult = PAGE_SIZE;
NeilBrownf875a792019-03-07 09:49:46 +1100574 resp->f_dtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 resp->f_maxfilesize = ~(u32) 0;
576 resp->f_properties = NFS3_FSF_DEFAULT;
577
Chuck Lever14168d62020-10-01 18:59:54 -0400578 resp->status = fh_verify(rqstp, &argp->fh, 0,
579 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 /* Check special features of the file system. May request
582 * different read/write sizes for file systems known to have
583 * problems with large blocks */
Chuck Lever14168d62020-10-01 18:59:54 -0400584 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400585 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 /* Note that we don't care for remote fs's here */
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800588 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 resp->f_properties = NFS3_FSF_BILLYBOY;
590 }
591 resp->f_maxfilesize = sb->s_maxbytes;
592 }
593
594 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400595 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
598/*
599 * Get pathconf info for the specified file
600 */
Al Viro7111c662006-10-19 23:28:45 -0700601static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200602nfsd3_proc_pathconf(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200604 struct nfsd_fhandle *argp = rqstp->rq_argp;
605 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 dprintk("nfsd: PATHCONF(3) %s\n",
608 SVCFH_fmt(&argp->fh));
609
610 /* Set default pathconf */
611 resp->p_link_max = 255; /* at least */
612 resp->p_name_max = 255; /* at least */
613 resp->p_no_trunc = 0;
614 resp->p_chown_restricted = 1;
615 resp->p_case_insensitive = 0;
616 resp->p_case_preserving = 1;
617
Chuck Lever14168d62020-10-01 18:59:54 -0400618 resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Chuck Lever14168d62020-10-01 18:59:54 -0400620 if (resp->status == nfs_ok) {
Al Virofc640052016-04-10 01:33:30 -0400621 struct super_block *sb = argp->fh.fh_dentry->d_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /* Note that we don't care for remote fs's here */
624 switch (sb->s_magic) {
625 case EXT2_SUPER_MAGIC:
626 resp->p_link_max = EXT2_LINK_MAX;
627 resp->p_name_max = EXT2_NAME_LEN;
628 break;
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800629 case MSDOS_SUPER_MAGIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 resp->p_case_insensitive = 1;
631 resp->p_case_preserving = 0;
632 break;
633 }
634 }
635
636 fh_put(&argp->fh);
Chuck Levercc028a12020-10-02 15:52:44 -0400637 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640/*
641 * Commit a file (range) to stable storage.
642 */
Al Viro7111c662006-10-19 23:28:45 -0700643static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200644nfsd3_proc_commit(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200646 struct nfsd3_commitargs *argp = rqstp->rq_argp;
647 struct nfsd3_commitres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
650 SVCFH_fmt(&argp->fh),
651 argp->count,
652 (unsigned long long) argp->offset);
653
Chuck Lever14168d62020-10-01 18:59:54 -0400654 if (argp->offset > NFS_OFFSET_MAX) {
655 resp->status = nfserr_inval;
656 goto out;
657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 fh_copy(&resp->fh, &argp->fh);
Chuck Lever14168d62020-10-01 18:59:54 -0400660 resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
661 argp->count, resp->verf);
662out:
Chuck Levercc028a12020-10-02 15:52:44 -0400663 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
665
666
667/*
668 * NFSv3 Server procedures.
669 * Only the results of non-idempotent operations are cached.
670 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
672#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
673#define nfsd3_mkdirargs nfsd3_createargs
674#define nfsd3_readdirplusargs nfsd3_readdirargs
675#define nfsd3_fhandleargs nfsd_fhandle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#define nfsd3_attrstatres nfsd3_attrstat
677#define nfsd3_wccstatres nfsd3_attrstat
678#define nfsd3_createres nfsd3_diropres
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#define ST 1 /* status*/
681#define FH 17 /* filehandle with length */
682#define AT 21 /* attributes */
683#define pAT (1+AT) /* post attributes - conditional */
684#define WC (7+pAT) /* WCC attributes */
685
Christoph Hellwig860bda22017-05-12 16:11:49 +0200686static const struct svc_procedure nfsd_procedures3[22] = {
Yu Zhiguob9081d92009-06-09 17:33:34 +0800687 [NFS3PROC_NULL] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200688 .pc_func = nfsd3_proc_null,
Chuck Lever788f7182020-11-05 14:48:29 -0500689 .pc_decode = nfssvc_decode_voidarg,
690 .pc_encode = nfssvc_encode_voidres,
691 .pc_argsize = sizeof(struct nfsd_voidargs),
692 .pc_ressize = sizeof(struct nfsd_voidres),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800693 .pc_cachetype = RC_NOCACHE,
694 .pc_xdrressize = ST,
Chuck Lever2289e872020-09-17 17:22:49 -0400695 .pc_name = "NULL",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800696 },
697 [NFS3PROC_GETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200698 .pc_func = nfsd3_proc_getattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200699 .pc_decode = nfs3svc_decode_fhandleargs,
Chuck Lever2c42f802020-10-21 11:58:41 -0400700 .pc_encode = nfs3svc_encode_getattrres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200701 .pc_release = nfs3svc_release_fhandle,
Chuck Lever95753632020-10-20 14:30:02 -0400702 .pc_argsize = sizeof(struct nfsd_fhandle),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800703 .pc_ressize = sizeof(struct nfsd3_attrstatres),
704 .pc_cachetype = RC_NOCACHE,
705 .pc_xdrressize = ST+AT,
Chuck Lever2289e872020-09-17 17:22:49 -0400706 .pc_name = "GETATTR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800707 },
708 [NFS3PROC_SETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200709 .pc_func = nfsd3_proc_setattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200710 .pc_decode = nfs3svc_decode_sattrargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200711 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200712 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800713 .pc_argsize = sizeof(struct nfsd3_sattrargs),
714 .pc_ressize = sizeof(struct nfsd3_wccstatres),
715 .pc_cachetype = RC_REPLBUFF,
716 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400717 .pc_name = "SETATTR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800718 },
719 [NFS3PROC_LOOKUP] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200720 .pc_func = nfsd3_proc_lookup,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200721 .pc_decode = nfs3svc_decode_diropargs,
Chuck Lever5cf35332020-10-22 14:46:58 -0400722 .pc_encode = nfs3svc_encode_lookupres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200723 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800724 .pc_argsize = sizeof(struct nfsd3_diropargs),
725 .pc_ressize = sizeof(struct nfsd3_diropres),
726 .pc_cachetype = RC_NOCACHE,
727 .pc_xdrressize = ST+FH+pAT+pAT,
Chuck Lever2289e872020-09-17 17:22:49 -0400728 .pc_name = "LOOKUP",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800729 },
730 [NFS3PROC_ACCESS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200731 .pc_func = nfsd3_proc_access,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200732 .pc_decode = nfs3svc_decode_accessargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200733 .pc_encode = nfs3svc_encode_accessres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200734 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800735 .pc_argsize = sizeof(struct nfsd3_accessargs),
736 .pc_ressize = sizeof(struct nfsd3_accessres),
737 .pc_cachetype = RC_NOCACHE,
738 .pc_xdrressize = ST+pAT+1,
Chuck Lever2289e872020-09-17 17:22:49 -0400739 .pc_name = "ACCESS",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800740 },
741 [NFS3PROC_READLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200742 .pc_func = nfsd3_proc_readlink,
Chuck Lever224c1c82020-10-24 12:51:18 -0400743 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200744 .pc_encode = nfs3svc_encode_readlinkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200745 .pc_release = nfs3svc_release_fhandle,
Chuck Lever224c1c82020-10-24 12:51:18 -0400746 .pc_argsize = sizeof(struct nfsd_fhandle),
Yu Zhiguob9081d92009-06-09 17:33:34 +0800747 .pc_ressize = sizeof(struct nfsd3_readlinkres),
748 .pc_cachetype = RC_NOCACHE,
749 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
Chuck Lever2289e872020-09-17 17:22:49 -0400750 .pc_name = "READLINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800751 },
752 [NFS3PROC_READ] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200753 .pc_func = nfsd3_proc_read,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200754 .pc_decode = nfs3svc_decode_readargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200755 .pc_encode = nfs3svc_encode_readres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200756 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800757 .pc_argsize = sizeof(struct nfsd3_readargs),
758 .pc_ressize = sizeof(struct nfsd3_readres),
759 .pc_cachetype = RC_NOCACHE,
760 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
Chuck Lever2289e872020-09-17 17:22:49 -0400761 .pc_name = "READ",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800762 },
763 [NFS3PROC_WRITE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200764 .pc_func = nfsd3_proc_write,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200765 .pc_decode = nfs3svc_decode_writeargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200766 .pc_encode = nfs3svc_encode_writeres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200767 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800768 .pc_argsize = sizeof(struct nfsd3_writeargs),
769 .pc_ressize = sizeof(struct nfsd3_writeres),
770 .pc_cachetype = RC_REPLBUFF,
771 .pc_xdrressize = ST+WC+4,
Chuck Lever2289e872020-09-17 17:22:49 -0400772 .pc_name = "WRITE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800773 },
774 [NFS3PROC_CREATE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200775 .pc_func = nfsd3_proc_create,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200776 .pc_decode = nfs3svc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200777 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200778 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800779 .pc_argsize = sizeof(struct nfsd3_createargs),
780 .pc_ressize = sizeof(struct nfsd3_createres),
781 .pc_cachetype = RC_REPLBUFF,
782 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400783 .pc_name = "CREATE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800784 },
785 [NFS3PROC_MKDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200786 .pc_func = nfsd3_proc_mkdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200787 .pc_decode = nfs3svc_decode_mkdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200788 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200789 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800790 .pc_argsize = sizeof(struct nfsd3_mkdirargs),
791 .pc_ressize = sizeof(struct nfsd3_createres),
792 .pc_cachetype = RC_REPLBUFF,
793 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400794 .pc_name = "MKDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800795 },
796 [NFS3PROC_SYMLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200797 .pc_func = nfsd3_proc_symlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200798 .pc_decode = nfs3svc_decode_symlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200799 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200800 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800801 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
802 .pc_ressize = sizeof(struct nfsd3_createres),
803 .pc_cachetype = RC_REPLBUFF,
804 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400805 .pc_name = "SYMLINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800806 },
807 [NFS3PROC_MKNOD] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200808 .pc_func = nfsd3_proc_mknod,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200809 .pc_decode = nfs3svc_decode_mknodargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200810 .pc_encode = nfs3svc_encode_createres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200811 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800812 .pc_argsize = sizeof(struct nfsd3_mknodargs),
813 .pc_ressize = sizeof(struct nfsd3_createres),
814 .pc_cachetype = RC_REPLBUFF,
815 .pc_xdrressize = ST+(1+FH+pAT)+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400816 .pc_name = "MKNOD",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800817 },
818 [NFS3PROC_REMOVE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200819 .pc_func = nfsd3_proc_remove,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200820 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200821 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200822 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800823 .pc_argsize = sizeof(struct nfsd3_diropargs),
824 .pc_ressize = sizeof(struct nfsd3_wccstatres),
825 .pc_cachetype = RC_REPLBUFF,
826 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400827 .pc_name = "REMOVE",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800828 },
829 [NFS3PROC_RMDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200830 .pc_func = nfsd3_proc_rmdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200831 .pc_decode = nfs3svc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200832 .pc_encode = nfs3svc_encode_wccstatres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200833 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800834 .pc_argsize = sizeof(struct nfsd3_diropargs),
835 .pc_ressize = sizeof(struct nfsd3_wccstatres),
836 .pc_cachetype = RC_REPLBUFF,
837 .pc_xdrressize = ST+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400838 .pc_name = "RMDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800839 },
840 [NFS3PROC_RENAME] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200841 .pc_func = nfsd3_proc_rename,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200842 .pc_decode = nfs3svc_decode_renameargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200843 .pc_encode = nfs3svc_encode_renameres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200844 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800845 .pc_argsize = sizeof(struct nfsd3_renameargs),
846 .pc_ressize = sizeof(struct nfsd3_renameres),
847 .pc_cachetype = RC_REPLBUFF,
848 .pc_xdrressize = ST+WC+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400849 .pc_name = "RENAME",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800850 },
851 [NFS3PROC_LINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200852 .pc_func = nfsd3_proc_link,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200853 .pc_decode = nfs3svc_decode_linkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200854 .pc_encode = nfs3svc_encode_linkres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200855 .pc_release = nfs3svc_release_fhandle2,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800856 .pc_argsize = sizeof(struct nfsd3_linkargs),
857 .pc_ressize = sizeof(struct nfsd3_linkres),
858 .pc_cachetype = RC_REPLBUFF,
859 .pc_xdrressize = ST+pAT+WC,
Chuck Lever2289e872020-09-17 17:22:49 -0400860 .pc_name = "LINK",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800861 },
862 [NFS3PROC_READDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200863 .pc_func = nfsd3_proc_readdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200864 .pc_decode = nfs3svc_decode_readdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200865 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200866 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800867 .pc_argsize = sizeof(struct nfsd3_readdirargs),
868 .pc_ressize = sizeof(struct nfsd3_readdirres),
869 .pc_cachetype = RC_NOCACHE,
Chuck Lever2289e872020-09-17 17:22:49 -0400870 .pc_name = "READDIR",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800871 },
872 [NFS3PROC_READDIRPLUS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200873 .pc_func = nfsd3_proc_readdirplus,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200874 .pc_decode = nfs3svc_decode_readdirplusargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200875 .pc_encode = nfs3svc_encode_readdirres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200876 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800877 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
878 .pc_ressize = sizeof(struct nfsd3_readdirres),
879 .pc_cachetype = RC_NOCACHE,
Chuck Lever2289e872020-09-17 17:22:49 -0400880 .pc_name = "READDIRPLUS",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800881 },
882 [NFS3PROC_FSSTAT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200883 .pc_func = nfsd3_proc_fsstat,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200884 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200885 .pc_encode = nfs3svc_encode_fsstatres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800886 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
887 .pc_ressize = sizeof(struct nfsd3_fsstatres),
888 .pc_cachetype = RC_NOCACHE,
889 .pc_xdrressize = ST+pAT+2*6+1,
Chuck Lever2289e872020-09-17 17:22:49 -0400890 .pc_name = "FSSTAT",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800891 },
892 [NFS3PROC_FSINFO] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200893 .pc_func = nfsd3_proc_fsinfo,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200894 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200895 .pc_encode = nfs3svc_encode_fsinfores,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800896 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
897 .pc_ressize = sizeof(struct nfsd3_fsinfores),
898 .pc_cachetype = RC_NOCACHE,
899 .pc_xdrressize = ST+pAT+12,
Chuck Lever2289e872020-09-17 17:22:49 -0400900 .pc_name = "FSINFO",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800901 },
902 [NFS3PROC_PATHCONF] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200903 .pc_func = nfsd3_proc_pathconf,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200904 .pc_decode = nfs3svc_decode_fhandleargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200905 .pc_encode = nfs3svc_encode_pathconfres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800906 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
907 .pc_ressize = sizeof(struct nfsd3_pathconfres),
908 .pc_cachetype = RC_NOCACHE,
909 .pc_xdrressize = ST+pAT+6,
Chuck Lever2289e872020-09-17 17:22:49 -0400910 .pc_name = "PATHCONF",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800911 },
912 [NFS3PROC_COMMIT] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200913 .pc_func = nfsd3_proc_commit,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200914 .pc_decode = nfs3svc_decode_commitargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200915 .pc_encode = nfs3svc_encode_commitres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200916 .pc_release = nfs3svc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800917 .pc_argsize = sizeof(struct nfsd3_commitargs),
918 .pc_ressize = sizeof(struct nfsd3_commitres),
919 .pc_cachetype = RC_NOCACHE,
920 .pc_xdrressize = ST+WC+2,
Chuck Lever2289e872020-09-17 17:22:49 -0400921 .pc_name = "COMMIT",
Yu Zhiguob9081d92009-06-09 17:33:34 +0800922 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923};
924
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200925static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
Christoph Hellwige9679182017-05-12 16:21:37 +0200926const struct svc_version nfsd_version3 = {
927 .vs_vers = 3,
928 .vs_nproc = 22,
929 .vs_proc = nfsd_procedures3,
930 .vs_dispatch = nfsd_dispatch,
931 .vs_count = nfsd_count3,
932 .vs_xdrsize = NFS3_SVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933};