blob: edcb380fbf126d53db8283a8aa543151432f8baa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Server-side procedures for NFSv4.
3 *
4 * Copyright (c) 2002 The Regents of the University of Michigan.
5 * All rights reserved.
6 *
7 * Kendrick Smith <kmsmith@umich.edu>
8 * Andy Adamson <andros@umich.edu>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
J. Bruce Fields880a3a52018-03-21 17:19:02 -040035#include <linux/fs_struct.h>
NeilBrown7e06b7f2005-06-23 22:03:13 -070036#include <linux/file.h>
Anna Schumakerb0cb9082014-11-07 14:44:27 -050037#include <linux/falloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -040039#include <linux/kthread.h>
Olga Kornievskaia624322f2019-10-04 16:34:26 -040040#include <linux/sunrpc/addr.h>
Dai Ngo0cfcd402020-10-18 23:42:49 -040041#include <linux/nfs_ssc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Mi Jinlong58e7b332011-08-28 18:18:56 +080043#include "idmap.h"
Boaz Harrosh9a74af22009-12-03 20:30:56 +020044#include "cache.h"
45#include "xdr4.h"
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050046#include "vfs.h"
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +010047#include "current_stateid.h"
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +030048#include "netns.h"
Christoph Hellwig4ac72492013-12-20 05:16:55 -080049#include "acl.h"
Christoph Hellwig9cf514c2014-05-05 13:11:59 +020050#include "pnfs.h"
Christoph Hellwig31ef83d2014-08-16 19:02:22 -050051#include "trace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Chuck Leverd6c9e432020-12-18 12:28:23 -050053static bool inter_copy_offload_enable;
54module_param(inter_copy_offload_enable, bool, 0644);
55MODULE_PARM_DESC(inter_copy_offload_enable,
56 "Enable inter server to server copy offload. Default: false");
57
David Quigley18032ca2013-05-02 13:19:10 -040058#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
59#include <linux/security.h>
60
61static inline void
62nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
63{
David Howells2b0143b2015-03-17 22:25:59 +000064 struct inode *inode = d_inode(resfh->fh_dentry);
David Quigley18032ca2013-05-02 13:19:10 -040065 int status;
66
Al Viro59551022016-01-22 15:40:57 -050067 inode_lock(inode);
David Quigley18032ca2013-05-02 13:19:10 -040068 status = security_inode_setsecctx(resfh->fh_dentry,
69 label->data, label->len);
Al Viro59551022016-01-22 15:40:57 -050070 inode_unlock(inode);
David Quigley18032ca2013-05-02 13:19:10 -040071
72 if (status)
73 /*
74 * XXX: We should really fail the whole open, but we may
75 * already have created a new file, so it may be too
76 * late. For now this seems the least of evils:
77 */
78 bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
79
80 return;
81}
82#else
83static inline void
84nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
85{ }
86#endif
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define NFSDDBG_FACILITY NFSDDBG_PROC
89
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080090static u32 nfsd_attrmask[] = {
91 NFSD_WRITEABLE_ATTRS_WORD0,
92 NFSD_WRITEABLE_ATTRS_WORD1,
93 NFSD_WRITEABLE_ATTRS_WORD2
94};
95
96static u32 nfsd41_ex_attrmask[] = {
97 NFSD_SUPPATTR_EXCLCREAT_WORD0,
98 NFSD_SUPPATTR_EXCLCREAT_WORD1,
99 NFSD_SUPPATTR_EXCLCREAT_WORD2
100};
101
102static __be32
103check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
104 u32 *bmval, u32 *writable)
105{
106 struct dentry *dentry = cstate->current_fh.fh_dentry;
J. Bruce Fields32ddd942017-01-03 12:30:11 -0500107 struct svc_export *exp = cstate->current_fh.fh_export;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800108
J. Bruce Fields916d2d82016-10-18 14:18:40 -0400109 if (!nfsd_attrs_supported(cstate->minorversion, bmval))
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800110 return nfserr_attrnotsupp;
J. Bruce Fields916d2d82016-10-18 14:18:40 -0400111 if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
112 return nfserr_attrnotsupp;
J. Bruce Fields32ddd942017-01-03 12:30:11 -0500113 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
114 !(exp->ex_flags & NFSEXP_SECURITY_LABEL))
115 return nfserr_attrnotsupp;
J. Bruce Fields916d2d82016-10-18 14:18:40 -0400116 if (writable && !bmval_is_subset(bmval, writable))
117 return nfserr_inval;
Andreas Gruenbacher47057ab2016-01-12 20:24:14 +0100118 if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
119 (bmval[1] & FATTR4_WORD1_MODE))
120 return nfserr_inval;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800121 return nfs_ok;
122}
123
124static __be32
125nfsd4_check_open_attributes(struct svc_rqst *rqstp,
126 struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
127{
128 __be32 status = nfs_ok;
129
130 if (open->op_create == NFS4_OPEN_CREATE) {
131 if (open->op_createmode == NFS4_CREATE_UNCHECKED
132 || open->op_createmode == NFS4_CREATE_GUARDED)
133 status = check_attr_support(rqstp, cstate,
134 open->op_bmval, nfsd_attrmask);
135 else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
136 status = check_attr_support(rqstp, cstate,
137 open->op_bmval, nfsd41_ex_attrmask);
138 }
139
140 return status;
141}
142
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800143static int
144is_create_with_attrs(struct nfsd4_open *open)
145{
146 return open->op_create == NFS4_OPEN_CREATE
147 && (open->op_createmode == NFS4_CREATE_UNCHECKED
148 || open->op_createmode == NFS4_CREATE_GUARDED
149 || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
150}
151
152/*
153 * if error occurs when setting the acl, just clear the acl bit
154 * in the returned attr bitmap.
155 */
156static void
157do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
158 struct nfs4_acl *acl, u32 *bmval)
159{
160 __be32 status;
161
162 status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
163 if (status)
164 /*
165 * We should probably fail the whole open at this point,
166 * but we've already created the file, so it's too late;
167 * So this seems the least of evils:
168 */
169 bmval[0] &= ~FATTR4_WORD0_ACL;
170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172static inline void
173fh_dup2(struct svc_fh *dst, struct svc_fh *src)
174{
175 fh_put(dst);
176 dget(src->fh_dentry);
177 if (src->fh_export)
Kinglong Meebf18f162014-06-10 22:06:44 +0800178 exp_get(src->fh_export);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 *dst = *src;
180}
181
Al Virob37ad282006-10-19 23:28:59 -0700182static __be32
J. Bruce Fieldsdc730e12006-10-17 00:10:13 -0700183do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Al Virob37ad282006-10-19 23:28:59 -0700185 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 if (open->op_truncate &&
188 !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
189 return nfserr_inval;
190
J. Bruce Fieldsa0432262011-08-25 10:48:39 -0400191 accmode |= NFSD_MAY_READ_IF_EXEC;
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200194 accmode |= NFSD_MAY_READ;
J. Bruce Fields9801d8a2006-10-17 00:10:14 -0700195 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200196 accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
J. Bruce Fields57ecb342009-12-01 19:42:57 -0500197 if (open->op_share_deny & NFS4_SHARE_DENY_READ)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200198 accmode |= NFSD_MAY_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
201
202 return status;
203}
204
J. Bruce Fieldsaadab6c2011-08-15 16:55:02 -0400205static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
206{
David Howells2b0143b2015-03-17 22:25:59 +0000207 umode_t mode = d_inode(fh->fh_dentry)->i_mode;
J. Bruce Fieldsaadab6c2011-08-15 16:55:02 -0400208
209 if (S_ISREG(mode))
210 return nfs_ok;
211 if (S_ISDIR(mode))
212 return nfserr_isdir;
213 /*
214 * Using err_symlink as our catch-all case may look odd; but
215 * there's no other obvious error for this case in 4.0, and we
216 * happen to know that it will cause the linux v4 client to do
217 * the right thing on attempts to open something other than a
218 * regular file.
219 */
220 return nfserr_symlink;
221}
222
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400223static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400225 if (nfsd4_has_session(cstate))
226 return;
227 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
228 &resfh->fh_handle);
229}
230
231static __be32
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500232do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400233{
234 struct svc_fh *current_fh = &cstate->current_fh;
Neil Brown7007c902012-12-07 15:40:55 -0500235 int accmode;
Al Virob37ad282006-10-19 23:28:59 -0700236 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500238 *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
239 if (!*resfh)
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500240 return nfserr_jukebox;
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500241 fh_init(*resfh, NFS4_FHSIZE);
zhengbin500c24812019-12-25 11:19:35 +0800242 open->op_truncate = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 if (open->op_create) {
Benny Halevy79fb54a2009-04-03 08:29:17 +0300245 /* FIXME: check session persistence and pnfs flags.
246 * The nfsv4.1 spec requires the following semantics:
247 *
248 * Persistent | pNFS | Server REQUIRED | Client Allowed
249 * Reply Cache | server | |
250 * -------------+--------+-----------------+--------------------
251 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
252 * | | | (SHOULD)
253 * | | and EXCLUSIVE4 | or EXCLUSIVE4
254 * | | | (SHOULD NOT)
255 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
256 * yes | no | GUARDED4 | GUARDED4
257 * yes | yes | GUARDED4 | GUARDED4
258 */
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 /*
261 * Note: create modes (UNCHECKED,GUARDED...) are the same
Mi Jinlongac6721a2011-04-20 17:06:25 +0800262 * in NFSv4 as in v3 except EXCLUSIVE4_1.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 */
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400264 current->fs->umask = open->op_umask;
Chuck Lever1708e502020-11-16 17:45:04 -0500265 status = do_nfsd_create(rqstp, current_fh, open->op_fname,
266 open->op_fnamelen, &open->op_iattr,
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500267 *resfh, open->op_createmode,
Jeff Layton749997e2007-07-31 00:37:51 -0700268 (u32 *)open->op_verf.data,
J. Bruce Fields856121b2011-10-13 11:37:11 -0400269 &open->op_truncate, &open->op_created);
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400270 current->fs->umask = 0;
Jeff Layton749997e2007-07-31 00:37:51 -0700271
David Quigley18032ca2013-05-02 13:19:10 -0400272 if (!status && open->op_label.len)
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500273 nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
David Quigley18032ca2013-05-02 13:19:10 -0400274
J. Bruce Fields99f88722009-02-02 15:12:27 -0500275 /*
Kinglong Meeead8fb82015-07-30 21:55:02 +0800276 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
277 * use the returned bitmask to indicate which attributes
278 * we used to store the verifier:
Jeff Layton749997e2007-07-31 00:37:51 -0700279 */
Kinglong Meeead8fb82015-07-30 21:55:02 +0800280 if (nfsd_create_is_exclusive(open->op_createmode) && status == 0)
281 open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
282 FATTR4_WORD1_TIME_MODIFY);
J. Bruce Fields43357232014-01-24 18:04:40 -0500283 } else
284 /*
285 * Note this may exit with the parent still locked.
286 * We will hold the lock until nfsd4_open's final
287 * lookup, to prevent renames or unlinks until we've had
288 * a chance to an acquire a delegation if appropriate.
289 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 status = nfsd_lookup(rqstp, current_fh,
Chuck Lever1708e502020-11-16 17:45:04 -0500291 open->op_fname, open->op_fnamelen, *resfh);
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800292 if (status)
293 goto out;
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500294 status = nfsd_check_obj_isreg(*resfh);
J. Bruce Fields9dc4e6c2012-04-09 18:06:49 -0400295 if (status)
296 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800298 if (is_create_with_attrs(open) && open->op_acl != NULL)
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500299 do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800300
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500301 nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
Neil Brown7007c902012-12-07 15:40:55 -0500302 accmode = NFSD_MAY_NOP;
J. Bruce Fields89f6c332013-06-19 15:47:37 -0400303 if (open->op_created ||
304 open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
Neil Brown7007c902012-12-07 15:40:55 -0500305 accmode |= NFSD_MAY_OWNER_OVERRIDE;
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500306 status = do_open_permission(rqstp, *resfh, open, accmode);
J. Bruce Fields41fd1e42012-01-27 16:26:02 -0500307 set_change_info(&open->op_cinfo, current_fh);
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800308out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return status;
310}
311
Al Virob37ad282006-10-19 23:28:59 -0700312static __be32
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400313do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400315 struct svc_fh *current_fh = &cstate->current_fh;
Al Virob37ad282006-10-19 23:28:59 -0700316 __be32 status;
J. Bruce Fields9f415eb2013-05-03 16:09:09 -0400317 int accmode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 /* We don't know the target directory, and therefore can not
320 * set the change info
321 */
322
323 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
324
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400325 nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
328 (open->op_iattr.ia_size == 0);
J. Bruce Fields9f415eb2013-05-03 16:09:09 -0400329 /*
330 * In the delegation case, the client is telling us about an
331 * open that it *already* performed locally, some time ago. We
332 * should let it succeed now if possible.
333 *
334 * In the case of a CLAIM_FH open, on the other hand, the client
335 * may be counting on us to enforce permissions (the Linux 4.1
336 * client uses this for normal opens, for example).
337 */
338 if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
339 accmode = NFSD_MAY_OWNER_OVERRIDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
J. Bruce Fields9f415eb2013-05-03 16:09:09 -0400341 status = do_open_permission(rqstp, current_fh, open, accmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 return status;
344}
345
Andy Adamson60adfc52009-04-03 08:28:50 +0300346static void
347copy_clientid(clientid_t *clid, struct nfsd4_session *session)
348{
349 struct nfsd4_sessionid *sid =
350 (struct nfsd4_sessionid *)session->se_sessionid.data;
351
352 clid->cl_boot = sid->clientid.cl_boot;
353 clid->cl_id = sid->clientid.cl_id;
354}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
J.Bruce Fields71911552006-12-13 00:35:29 -0800356static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800357nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200358 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200360 struct nfsd4_open *open = &u->open;
Al Virob37ad282006-10-19 23:28:59 -0700361 __be32 status;
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500362 struct svc_fh *resfh = NULL;
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +0300363 struct net *net = SVC_NET(rqstp);
364 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
J. Bruce Fields03f318c2018-06-08 12:28:47 -0400365 bool reclaim = false;
Andy Adamson66689582009-04-03 08:28:45 +0300366
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400367 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
Chuck Lever1708e502020-11-16 17:45:04 -0500368 (int)open->op_fnamelen, open->op_fname,
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400369 open->op_openowner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* This check required by spec. */
372 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
373 return nfserr_inval;
374
zhengbin500c24812019-12-25 11:19:35 +0800375 open->op_created = false;
Mi Jinlongab1350b2011-07-14 15:06:26 +0800376 /*
377 * RFC5661 18.51.3
378 * Before RECLAIM_COMPLETE done, server should deny new lock
379 */
380 if (nfsd4_has_session(cstate) &&
J. Bruce Fieldsec596592021-01-21 17:57:45 -0500381 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) &&
Mi Jinlongab1350b2011-07-14 15:06:26 +0800382 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
383 return nfserr_grace;
384
Andy Adamson60adfc52009-04-03 08:28:50 +0300385 if (nfsd4_has_session(cstate))
386 copy_clientid(&open->op_clientid, cstate->session);
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 /* check seqid for replay. set nfs4_owner */
Kinglong Mee6cd22662015-07-13 17:32:05 +0800389 status = nfsd4_process_open1(cstate, open, nn);
Al Viroa90b0612006-10-19 23:29:03 -0700390 if (status == nfserr_replay_me) {
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400391 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800392 fh_put(&cstate->current_fh);
J. Bruce Fieldsa4773c02009-02-02 17:23:10 -0500393 fh_copy_shallow(&cstate->current_fh.fh_handle,
394 &rp->rp_openfh);
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200395 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (status)
397 dprintk("nfsd4_open: replay failed"
398 " restoring previous filehandle\n");
399 else
Al Viroa90b0612006-10-19 23:29:03 -0700400 status = nfserr_replay_me;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402 if (status)
403 goto out;
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800404 if (open->op_xdr_error) {
405 status = open->op_xdr_error;
406 goto out;
407 }
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800408
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800409 status = nfsd4_check_open_attributes(rqstp, cstate, open);
410 if (status)
411 goto out;
412
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800413 /* Openowner is now set, so sequence id will get bumped. Now we need
414 * these checks before we do any creates: */
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800415 status = nfserr_grace;
J. Bruce Fieldsc87fb4a2015-08-06 12:47:02 -0400416 if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800417 goto out;
418 status = nfserr_no_grace;
J. Bruce Fieldsc87fb4a2015-08-06 12:47:02 -0400419 if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800420 goto out;
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 switch (open->op_claim_type) {
NeilBrown0dd3c192005-06-23 22:02:56 -0700423 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 case NFS4_OPEN_CLAIM_NULL:
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500425 status = do_open_lookup(rqstp, cstate, open, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (status)
427 goto out;
428 break;
429 case NFS4_OPEN_CLAIM_PREVIOUS:
J. Bruce Fields1722b042021-01-21 17:57:44 -0500430 status = nfs4_check_open_reclaim(cstate->clp);
Mi Jinlong0cf99b92011-11-23 10:48:40 +0800431 if (status)
432 goto out;
Jeff Laytonba5378b2014-05-30 09:09:28 -0400433 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
J. Bruce Fields03f318c2018-06-08 12:28:47 -0400434 reclaim = true;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500435 fallthrough;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400436 case NFS4_OPEN_CLAIM_FH:
437 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400438 status = do_open_fhandle(rqstp, cstate, open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (status)
440 goto out;
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500441 resfh = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 break;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400443 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
J. Bruce Fields2fdada02007-07-27 16:10:37 -0400445 dprintk("NFSD: unsupported OPEN claim type %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 open->op_claim_type);
447 status = nfserr_notsupp;
448 goto out;
449 default:
J. Bruce Fields2fdada02007-07-27 16:10:37 -0400450 dprintk("NFSD: Invalid OPEN claim type %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 open->op_claim_type);
452 status = nfserr_inval;
453 goto out;
454 }
455 /*
456 * nfsd4_process_open2() does the actual opening of the file. If
457 * successful, it (1) truncates the file if open->op_truncate was
458 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
459 */
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500460 status = nfsd4_process_open2(rqstp, resfh, open);
Jeff Laytonb3fbfe02014-07-29 21:37:44 -0400461 WARN(status && open->op_created,
462 "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
463 be32_to_cpu(status));
J. Bruce Fields03f318c2018-06-08 12:28:47 -0400464 if (reclaim && !status)
465 nn->somebody_reclaimed = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466out:
J. Bruce Fieldsc0e6bee2012-01-27 17:26:06 -0500467 if (resfh && resfh != &cstate->current_fh) {
468 fh_dup2(&cstate->current_fh, resfh);
469 fh_put(resfh);
470 kfree(resfh);
471 }
Jeff Layton42297892015-03-23 10:53:44 -0400472 nfsd4_cleanup_open_state(cstate, open);
J. Bruce Fields9411b1d2013-04-01 16:37:12 -0400473 nfsd4_bump_seqid(cstate, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return status;
475}
476
477/*
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800478 * OPEN is the only seqid-mutating operation whose decoding can fail
479 * with a seqid-mutating error (specifically, decoding of user names in
480 * the attributes). Therefore we have to do some processing to look up
481 * the stateowner so that we can bump the seqid.
482 */
483static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
484{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200485 struct nfsd4_open *open = &op->u.open;
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800486
487 if (!seqid_mutating_err(ntohl(op->status)))
488 return op->status;
489 if (nfsd4_has_session(cstate))
490 return op->status;
491 open->op_xdr_error = op->status;
Christoph Hellwigeb698532017-05-08 20:58:35 +0200492 return nfsd4_open(rqstp, cstate, &op->u);
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800493}
494
495/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 * filehandle-manipulating ops.
497 */
J.Bruce Fields71911552006-12-13 00:35:29 -0800498static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800499nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200500 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200502 u->getfh = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 return nfs_ok;
504}
505
J.Bruce Fields71911552006-12-13 00:35:29 -0800506static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800507nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200508 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200510 struct nfsd4_putfh *putfh = &u->putfh;
Olga Kornievskaiab9e86382019-10-07 10:56:48 -0400511 __be32 ret;
Christoph Hellwigeb698532017-05-08 20:58:35 +0200512
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800513 fh_put(&cstate->current_fh);
514 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
515 memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
516 putfh->pf_fhlen);
Olga Kornievskaiab9e86382019-10-07 10:56:48 -0400517 ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
518#ifdef CONFIG_NFSD_V4_2_INTER_SSC
519 if (ret == nfserr_stale && putfh->no_verify) {
520 SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN);
521 ret = 0;
522 }
523#endif
524 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525}
526
J.Bruce Fields71911552006-12-13 00:35:29 -0800527static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800528nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200529 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Al Virob37ad282006-10-19 23:28:59 -0700531 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800533 fh_put(&cstate->current_fh);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700534 status = exp_pseudoroot(rqstp, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 return status;
536}
537
J.Bruce Fields71911552006-12-13 00:35:29 -0800538static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800539nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200540 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800542 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return nfserr_restorefh;
544
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800545 fh_dup2(&cstate->current_fh, &cstate->save_fh);
Olga Kornievskaia51100d22018-09-13 13:58:24 -0400546 if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) {
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100547 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
Olga Kornievskaia51100d22018-09-13 13:58:24 -0400548 SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 return nfs_ok;
551}
552
J.Bruce Fields71911552006-12-13 00:35:29 -0800553static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800554nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200555 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800557 fh_dup2(&cstate->save_fh, &cstate->current_fh);
Olga Kornievskaia51100d22018-09-13 13:58:24 -0400558 if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100559 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
Olga Kornievskaia51100d22018-09-13 13:58:24 -0400560 SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG);
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 return nfs_ok;
563}
564
565/*
566 * misc nfsv4 ops
567 */
J.Bruce Fields71911552006-12-13 00:35:29 -0800568static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800569nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200570 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200572 struct nfsd4_access *access = &u->access;
Frank van der Lindenc11d7fd2020-06-23 22:39:24 +0000573 u32 access_full;
Christoph Hellwigeb698532017-05-08 20:58:35 +0200574
Frank van der Lindenc11d7fd2020-06-23 22:39:24 +0000575 access_full = NFS3_ACCESS_FULL;
576 if (cstate->minorversion >= 2)
577 access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
578 NFS4_ACCESS_XAWRITE;
579
580 if (access->ac_req_access & ~access_full)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return nfserr_inval;
582
583 access->ac_resp_access = access->ac_req_access;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800584 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
585 &access->ac_supported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +0300588static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
Chuck Leverab4684d2012-03-02 17:13:50 -0500589{
Trond Myklebust27c438f2019-09-02 13:02:56 -0400590 __be32 *verf = (__be32 *)verifier->data;
Chuck Leverab4684d2012-03-02 17:13:50 -0500591
Trond Myklebust27c438f2019-09-02 13:02:56 -0400592 BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data));
593
594 nfsd_copy_boot_verifier(verf, net_generic(net, nfsd_net_id));
Chuck Leverab4684d2012-03-02 17:13:50 -0500595}
596
J.Bruce Fields71911552006-12-13 00:35:29 -0800597static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800598nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200599 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200601 struct nfsd4_commit *commit = &u->commit;
602
J. Bruce Fields75c096f2011-08-15 18:39:32 -0400603 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
Trond Myklebust524ff1a2020-01-06 13:40:36 -0500604 commit->co_count,
605 (__be32 *)commit->co_verf.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
Al Virob37ad282006-10-19 23:28:59 -0700608static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800609nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200610 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200612 struct nfsd4_create *create = &u->create;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 struct svc_fh resfh;
Al Virob37ad282006-10-19 23:28:59 -0700614 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 dev_t rdev;
616
617 fh_init(&resfh, NFS4_FHSIZE);
618
J. Bruce Fieldsfa081392016-07-21 16:00:12 -0400619 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 if (status)
621 return status;
622
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800623 status = check_attr_support(rqstp, cstate, create->cr_bmval,
624 nfsd_attrmask);
625 if (status)
626 return status;
627
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400628 current->fs->umask = create->cr_umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 switch (create->cr_type) {
630 case NF4LNK:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800631 status = nfsd_symlink(rqstp, &cstate->current_fh,
632 create->cr_name, create->cr_namelen,
Kinglong Mee1e444f52014-07-01 17:48:02 +0800633 create->cr_data, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 break;
635
636 case NF4BLK:
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400637 status = nfserr_inval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
639 if (MAJOR(rdev) != create->cr_specdata1 ||
640 MINOR(rdev) != create->cr_specdata2)
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400641 goto out_umask;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800642 status = nfsd_create(rqstp, &cstate->current_fh,
643 create->cr_name, create->cr_namelen,
644 &create->cr_iattr, S_IFBLK, rdev, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 break;
646
647 case NF4CHR:
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400648 status = nfserr_inval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
650 if (MAJOR(rdev) != create->cr_specdata1 ||
651 MINOR(rdev) != create->cr_specdata2)
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400652 goto out_umask;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800653 status = nfsd_create(rqstp, &cstate->current_fh,
654 create->cr_name, create->cr_namelen,
655 &create->cr_iattr,S_IFCHR, rdev, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 break;
657
658 case NF4SOCK:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800659 status = nfsd_create(rqstp, &cstate->current_fh,
660 create->cr_name, create->cr_namelen,
661 &create->cr_iattr, S_IFSOCK, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 break;
663
664 case NF4FIFO:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800665 status = nfsd_create(rqstp, &cstate->current_fh,
666 create->cr_name, create->cr_namelen,
667 &create->cr_iattr, S_IFIFO, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 break;
669
670 case NF4DIR:
671 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800672 status = nfsd_create(rqstp, &cstate->current_fh,
673 create->cr_name, create->cr_namelen,
674 &create->cr_iattr, S_IFDIR, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 break;
676
677 default:
678 status = nfserr_badtype;
679 }
680
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800681 if (status)
682 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
David Quigley18032ca2013-05-02 13:19:10 -0400684 if (create->cr_label.len)
685 nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
686
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800687 if (create->cr_acl != NULL)
688 do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
689 create->cr_bmval);
690
691 fh_unlock(&cstate->current_fh);
692 set_change_info(&create->cr_cinfo, &cstate->current_fh);
693 fh_dup2(&cstate->current_fh, &resfh);
694out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 fh_put(&resfh);
J. Bruce Fields880a3a52018-03-21 17:19:02 -0400696out_umask:
697 current->fs->umask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 return status;
699}
700
J.Bruce Fields71911552006-12-13 00:35:29 -0800701static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800702nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200703 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200705 struct nfsd4_getattr *getattr = &u->getattr;
Al Virob37ad282006-10-19 23:28:59 -0700706 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200708 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 if (status)
710 return status;
711
712 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
713 return nfserr_inval;
714
J. Bruce Fields916d2d82016-10-18 14:18:40 -0400715 getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
716 getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
717 getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800719 getattr->ga_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 return nfs_ok;
721}
722
J.Bruce Fields71911552006-12-13 00:35:29 -0800723static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800724nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200725 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200727 struct nfsd4_link *link = &u->link;
J. Bruce Fields95424462017-09-15 16:02:52 -0400728 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800730 status = nfsd_link(rqstp, &cstate->current_fh,
731 link->li_name, link->li_namelen, &cstate->save_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 if (!status)
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800733 set_change_info(&link->li_cinfo, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return status;
735}
736
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500737static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
739 struct svc_fh tmp_fh;
Al Virob37ad282006-10-19 23:28:59 -0700740 __be32 ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 fh_init(&tmp_fh, NFS4_FHSIZE);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700743 ret = exp_pseudoroot(rqstp, &tmp_fh);
744 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 return ret;
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500746 if (tmp_fh.fh_dentry == fh->fh_dentry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 fh_put(&tmp_fh);
748 return nfserr_noent;
749 }
750 fh_put(&tmp_fh);
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500751 return nfsd_lookup(rqstp, fh, "..", 2, fh);
752}
753
754static __be32
755nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200756 union nfsd4_op_u *u)
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500757{
758 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
760
J.Bruce Fields71911552006-12-13 00:35:29 -0800761static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800762nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200763 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800765 return nfsd_lookup(rqstp, &cstate->current_fh,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200766 u->lookup.lo_name, u->lookup.lo_len,
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800767 &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
769
J.Bruce Fields71911552006-12-13 00:35:29 -0800770static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800771nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200772 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200774 struct nfsd4_read *read = &u->read;
Al Virob37ad282006-10-19 23:28:59 -0700775 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Jeff Layton5c4583b2019-08-18 14:18:54 -0400777 read->rd_nf = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 if (read->rd_offset >= OFFSET_MAX)
779 return nfserr_inval;
780
Chuck Lever87c59422018-03-28 13:29:11 -0400781 trace_nfsd_read_start(rqstp, &cstate->current_fh,
782 read->rd_offset, read->rd_length);
783
J. Bruce Fields9b3234b2012-12-04 18:03:46 -0500784 /*
785 * If we do a zero copy read, then a client will see read data
786 * that reflects the state of the file *after* performing the
787 * following compound.
788 *
789 * To ensure proper ordering, we therefore turn off zero copy if
790 * the client wants us to do more in this compound:
791 */
792 if (!nfsd4_last_compound_op(rqstp))
Jeff Layton779fb0f2014-11-19 07:51:18 -0500793 clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
J. Bruce Fields9b3234b2012-12-04 18:03:46 -0500794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 /* check stateid */
Anna Schumakeraa0d6ae2015-12-03 12:59:51 +0100796 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
797 &read->rd_stateid, RD_STATE,
Olga Kornievskaia624322f2019-10-04 16:34:26 -0400798 &read->rd_nf, NULL);
Christoph Hellwigaf90f702015-06-18 16:45:00 +0200799 if (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
801 goto out;
802 }
803 status = nfs_ok;
804out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 read->rd_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800806 read->rd_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 return status;
808}
809
J. Bruce Fields34b1744c2017-05-05 17:09:37 -0400810
811static void
812nfsd4_read_release(union nfsd4_op_u *u)
813{
Jeff Layton5c4583b2019-08-18 14:18:54 -0400814 if (u->read.rd_nf)
815 nfsd_file_put(u->read.rd_nf);
Chuck Lever87c59422018-03-28 13:29:11 -0400816 trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
817 u->read.rd_offset, u->read.rd_length);
J. Bruce Fields34b1744c2017-05-05 17:09:37 -0400818}
819
J.Bruce Fields71911552006-12-13 00:35:29 -0800820static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800821nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200822 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200824 struct nfsd4_readdir *readdir = &u->readdir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 u64 cookie = readdir->rd_cookie;
826 static const nfs4_verifier zeroverf;
827
828 /* no need to check permission - this will be done in nfsd_readdir() */
829
830 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
831 return nfserr_inval;
832
J. Bruce Fields916d2d82016-10-18 14:18:40 -0400833 readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
834 readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
835 readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Bernd Schubert832023b2011-08-08 17:38:08 +0200837 if ((cookie == 1) || (cookie == 2) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
839 return nfserr_bad_cookie;
840
841 readdir->rd_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800842 readdir->rd_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 return nfs_ok;
844}
845
J.Bruce Fields71911552006-12-13 00:35:29 -0800846static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800847nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200848 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200850 u->readlink.rl_rqstp = rqstp;
851 u->readlink.rl_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 return nfs_ok;
853}
854
J.Bruce Fields71911552006-12-13 00:35:29 -0800855static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800856nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200857 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200859 struct nfsd4_remove *remove = &u->remove;
Al Virob37ad282006-10-19 23:28:59 -0700860 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
J. Bruce Fieldsc87fb4a2015-08-06 12:47:02 -0400862 if (opens_in_grace(SVC_NET(rqstp)))
NeilBrownc815afc2005-06-23 22:03:00 -0700863 return nfserr_grace;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800864 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
865 remove->rm_name, remove->rm_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 if (!status) {
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800867 fh_unlock(&cstate->current_fh);
868 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870 return status;
871}
872
J.Bruce Fields71911552006-12-13 00:35:29 -0800873static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800874nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200875 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200877 struct nfsd4_rename *rename = &u->rename;
J. Bruce Fields95424462017-09-15 16:02:52 -0400878 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
J. Bruce Fieldsf8f71d02018-11-06 11:47:20 -0500880 if (opens_in_grace(SVC_NET(rqstp)))
NeilBrownc815afc2005-06-23 22:03:00 -0700881 return nfserr_grace;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800882 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
883 rename->rn_snamelen, &cstate->current_fh,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 rename->rn_tname, rename->rn_tnamelen);
J. Bruce Fields2a6cf942013-04-30 15:28:51 -0400885 if (status)
886 return status;
887 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
888 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
889 return nfs_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
J.Bruce Fields71911552006-12-13 00:35:29 -0800892static __be32
Andy Adamsondcb488a32007-07-17 04:04:51 -0700893nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200894 union nfsd4_op_u *u)
Andy Adamsondcb488a32007-07-17 04:04:51 -0700895{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200896 struct nfsd4_secinfo *secinfo = &u->secinfo;
Andy Adamsondcb488a32007-07-17 04:04:51 -0700897 struct svc_export *exp;
898 struct dentry *dentry;
899 __be32 err;
900
J. Bruce Fields29a78a32011-04-09 11:28:53 -0400901 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
902 if (err)
903 return err;
Andy Adamsondcb488a32007-07-17 04:04:51 -0700904 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
905 secinfo->si_name, secinfo->si_namelen,
906 &exp, &dentry);
907 if (err)
908 return err;
J. Bruce Fields2f6fc052016-03-02 16:36:21 -0800909 fh_unlock(&cstate->current_fh);
David Howells2b0143b2015-03-17 22:25:59 +0000910 if (d_really_is_negative(dentry)) {
Andy Adamsondcb488a32007-07-17 04:04:51 -0700911 exp_put(exp);
912 err = nfserr_noent;
913 } else
914 secinfo->si_exp = exp;
915 dput(dentry);
J. Bruce Fields56560b92010-12-16 09:57:15 -0500916 if (cstate->minorversion)
917 /* See rfc 5661 section 2.6.3.1.1.8 */
918 fh_put(&cstate->current_fh);
Andy Adamsondcb488a32007-07-17 04:04:51 -0700919 return err;
920}
921
922static __be32
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500923nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200924 union nfsd4_op_u *u)
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500925{
926 __be32 err;
927
Christoph Hellwigeb698532017-05-08 20:58:35 +0200928 switch (u->secinfo_no_name.sin_style) {
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500929 case NFS4_SECINFO_STYLE4_CURRENT_FH:
930 break;
931 case NFS4_SECINFO_STYLE4_PARENT:
932 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
933 if (err)
934 return err;
935 break;
936 default:
937 return nfserr_inval;
938 }
Kinglong Meebf18f162014-06-10 22:06:44 +0800939
Christoph Hellwigeb698532017-05-08 20:58:35 +0200940 u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500941 fh_put(&cstate->current_fh);
942 return nfs_ok;
943}
944
J. Bruce Fields34b1744c2017-05-05 17:09:37 -0400945static void
946nfsd4_secinfo_release(union nfsd4_op_u *u)
947{
948 if (u->secinfo.si_exp)
949 exp_put(u->secinfo.si_exp);
950}
951
Eryu Guanec572b92017-09-29 15:01:10 +0800952static void
953nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
954{
955 if (u->secinfo_no_name.sin_exp)
956 exp_put(u->secinfo_no_name.sin_exp);
957}
958
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500959static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800960nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +0200961 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
Christoph Hellwigeb698532017-05-08 20:58:35 +0200963 struct nfsd4_setattr *setattr = &u->setattr;
Al Virob37ad282006-10-19 23:28:59 -0700964 __be32 status = nfs_ok;
Al Viro96f6f982012-04-12 23:47:00 -0400965 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
Christoph Hellwigaf90f702015-06-18 16:45:00 +0200968 status = nfs4_preprocess_stateid_op(rqstp, cstate,
Anna Schumakeraa0d6ae2015-12-03 12:59:51 +0100969 &cstate->current_fh, &setattr->sa_stateid,
Olga Kornievskaia624322f2019-10-04 16:34:26 -0400970 WR_STATE, NULL, NULL);
J. Bruce Fields375c5542006-01-18 17:43:33 -0800971 if (status) {
Greg Banks3e3b4802006-10-02 02:17:41 -0700972 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
J. Bruce Fields375c5542006-01-18 17:43:33 -0800973 return status;
974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
Al Viro96f6f982012-04-12 23:47:00 -0400976 err = fh_want_write(&cstate->current_fh);
977 if (err)
978 return nfserrno(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 status = nfs_ok;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800980
981 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
982 nfsd_attrmask);
983 if (status)
984 goto out;
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 if (setattr->sa_acl != NULL)
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800987 status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
988 setattr->sa_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (status)
Dave Hansen18f335a2008-02-15 14:37:38 -0800990 goto out;
David Quigley18032ca2013-05-02 13:19:10 -0400991 if (setattr->sa_label.len)
992 status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
993 &setattr->sa_label);
994 if (status)
995 goto out;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800996 status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
Arnd Bergmann2a1aa482019-11-03 17:50:18 +0100997 0, (time64_t)0);
Dave Hansen18f335a2008-02-15 14:37:38 -0800998out:
Al Virobad0dcf2011-11-23 12:03:18 -0500999 fh_drop_write(&cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 return status;
1001}
1002
J.Bruce Fields71911552006-12-13 00:35:29 -08001003static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001004nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001005 union nfsd4_op_u *u)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001007 struct nfsd4_write *write = &u->write;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 stateid_t *stateid = &write->wr_stateid;
Jeff Layton5c4583b2019-08-18 14:18:54 -04001009 struct nfsd_file *nf = NULL;
Al Virob37ad282006-10-19 23:28:59 -07001010 __be32 status = nfs_ok;
David Shaw31dec252009-03-05 20:16:14 -05001011 unsigned long cnt;
J. Bruce Fieldsffe11372012-11-15 14:52:19 -05001012 int nvecs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if (write->wr_offset >= OFFSET_MAX)
1015 return nfserr_inval;
1016
Chuck Leverd890be12018-03-27 10:53:27 -04001017 cnt = write->wr_buflen;
1018 trace_nfsd_write_start(rqstp, &cstate->current_fh,
1019 write->wr_offset, cnt);
Anna Schumakeraa0d6ae2015-12-03 12:59:51 +01001020 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001021 stateid, WR_STATE, &nf, NULL);
J. Bruce Fields375c5542006-01-18 17:43:33 -08001022 if (status) {
1023 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1024 return status;
1025 }
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 write->wr_how_written = write->wr_stable_how;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Chuck Leverc1346a122020-11-03 11:54:23 -05001029 nvecs = svc_fill_write_vector(rqstp, write->wr_payload.pages,
1030 write->wr_payload.head, write->wr_buflen);
J. Bruce Fieldsffe11372012-11-15 14:52:19 -05001031 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1032
Trond Myklebust16f8f892020-01-06 13:40:29 -05001033 status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
Christoph Hellwigaf90f702015-06-18 16:45:00 +02001034 write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
Trond Myklebust19e06632020-01-06 13:40:37 -05001035 write->wr_how_written,
1036 (__be32 *)write->wr_verifier.data);
Jeff Layton5c4583b2019-08-18 14:18:54 -04001037 nfsd_file_put(nf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
David Shaw31dec252009-03-05 20:16:14 -05001039 write->wr_bytes_written = cnt;
Chuck Leverd890be12018-03-27 10:53:27 -04001040 trace_nfsd_write_done(rqstp, &cstate->current_fh,
1041 write->wr_offset, cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Anna Schumaker24bab492014-09-26 13:58:27 -04001045static __be32
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001046nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Jeff Layton5c4583b2019-08-18 14:18:54 -04001047 stateid_t *src_stateid, struct nfsd_file **src,
1048 stateid_t *dst_stateid, struct nfsd_file **dst)
Christoph Hellwigffa01602015-12-03 12:59:52 +01001049{
Christoph Hellwigffa01602015-12-03 12:59:52 +01001050 __be32 status;
1051
Scott Mayhew01310bb2018-11-08 11:11:36 -05001052 if (!cstate->save_fh.fh_dentry)
1053 return nfserr_nofilehandle;
1054
Christoph Hellwigffa01602015-12-03 12:59:52 +01001055 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001056 src_stateid, RD_STATE, src, NULL);
Christoph Hellwigffa01602015-12-03 12:59:52 +01001057 if (status) {
1058 dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1059 goto out;
1060 }
1061
1062 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001063 dst_stateid, WR_STATE, dst, NULL);
Christoph Hellwigffa01602015-12-03 12:59:52 +01001064 if (status) {
1065 dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1066 goto out_put_src;
1067 }
1068
1069 /* fix up for NFS-specific error code */
Jeff Layton5c4583b2019-08-18 14:18:54 -04001070 if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
1071 !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
Christoph Hellwigffa01602015-12-03 12:59:52 +01001072 status = nfserr_wrong_type;
1073 goto out_put_dst;
1074 }
1075
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001076out:
1077 return status;
1078out_put_dst:
Jeff Layton5c4583b2019-08-18 14:18:54 -04001079 nfsd_file_put(*dst);
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001080out_put_src:
Jeff Layton5c4583b2019-08-18 14:18:54 -04001081 nfsd_file_put(*src);
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001082 goto out;
1083}
1084
1085static __be32
1086nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001087 union nfsd4_op_u *u)
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001088{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001089 struct nfsd4_clone *clone = &u->clone;
Jeff Layton5c4583b2019-08-18 14:18:54 -04001090 struct nfsd_file *src, *dst;
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001091 __be32 status;
1092
1093 status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
1094 &clone->cl_dst_stateid, &dst);
1095 if (status)
1096 goto out;
1097
Trond Myklebustb66ae6d2020-01-06 13:40:32 -05001098 status = nfsd4_clone_file_range(src, clone->cl_src_pos,
1099 dst, clone->cl_dst_pos, clone->cl_count,
Trond Myklebusta25e37262019-11-27 17:05:51 -05001100 EX_ISSYNC(cstate->current_fh.fh_export));
Christoph Hellwigffa01602015-12-03 12:59:52 +01001101
Jeff Layton5c4583b2019-08-18 14:18:54 -04001102 nfsd_file_put(dst);
1103 nfsd_file_put(src);
Christoph Hellwigffa01602015-12-03 12:59:52 +01001104out:
1105 return status;
1106}
1107
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001108void nfs4_put_copy(struct nfsd4_copy *copy)
1109{
1110 if (!refcount_dec_and_test(&copy->refcount))
1111 return;
1112 kfree(copy);
1113}
1114
1115static bool
1116check_and_set_stop_copy(struct nfsd4_copy *copy)
1117{
1118 bool value;
1119
1120 spin_lock(&copy->cp_clp->async_lock);
1121 value = copy->stopped;
1122 if (!copy->stopped)
1123 copy->stopped = true;
1124 spin_unlock(&copy->cp_clp->async_lock);
1125 return value;
1126}
1127
1128static void nfsd4_stop_copy(struct nfsd4_copy *copy)
1129{
1130 /* only 1 thread should stop the copy */
1131 if (!check_and_set_stop_copy(copy))
1132 kthread_stop(copy->copy_task);
1133 nfs4_put_copy(copy);
1134}
1135
1136static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp)
1137{
1138 struct nfsd4_copy *copy = NULL;
1139
1140 spin_lock(&clp->async_lock);
1141 if (!list_empty(&clp->async_copies)) {
1142 copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
1143 copies);
1144 refcount_inc(&copy->refcount);
1145 }
1146 spin_unlock(&clp->async_lock);
1147 return copy;
1148}
1149
1150void nfsd4_shutdown_copy(struct nfs4_client *clp)
1151{
1152 struct nfsd4_copy *copy;
1153
1154 while ((copy = nfsd4_get_copy(clp)) != NULL)
1155 nfsd4_stop_copy(copy);
1156}
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001157#ifdef CONFIG_NFSD_V4_2_INTER_SSC
1158
1159extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1160 struct nfs_fh *src_fh,
1161 nfs4_stateid *stateid);
1162extern void nfs42_ssc_close(struct file *filep);
1163
1164extern void nfs_sb_deactive(struct super_block *sb);
1165
1166#define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
1167
Chuck Leverf2453972020-04-06 16:01:42 -04001168/*
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001169 * Support one copy source server for now.
1170 */
1171static __be32
1172nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
1173 struct vfsmount **mount)
1174{
1175 struct file_system_type *type;
1176 struct vfsmount *ss_mnt;
1177 struct nfs42_netaddr *naddr;
1178 struct sockaddr_storage tmp_addr;
1179 size_t tmp_addrlen, match_netid_len = 3;
1180 char *startsep = "", *endsep = "", *match_netid = "tcp";
1181 char *ipaddr, *dev_name, *raw_data;
Olga Kornievskaiab8290ca2019-12-04 15:13:53 -05001182 int len, raw_len;
1183 __be32 status = nfserr_inval;
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001184
1185 naddr = &nss->u.nl4_addr;
1186 tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
1187 naddr->addr_len,
1188 (struct sockaddr *)&tmp_addr,
1189 sizeof(tmp_addr));
1190 if (tmp_addrlen == 0)
1191 goto out_err;
1192
1193 if (tmp_addr.ss_family == AF_INET6) {
1194 startsep = "[";
1195 endsep = "]";
1196 match_netid = "tcp6";
1197 match_netid_len = 4;
1198 }
1199
1200 if (naddr->netid_len != match_netid_len ||
1201 strncmp(naddr->netid, match_netid, naddr->netid_len))
1202 goto out_err;
1203
1204 /* Construct the raw data for the vfs_kern_mount call */
1205 len = RPC_MAX_ADDRBUFLEN + 1;
1206 ipaddr = kzalloc(len, GFP_KERNEL);
1207 if (!ipaddr)
1208 goto out_err;
1209
1210 rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len);
1211
1212 /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
1213
1214 raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr);
1215 raw_data = kzalloc(raw_len, GFP_KERNEL);
1216 if (!raw_data)
1217 goto out_free_ipaddr;
1218
1219 snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr);
1220
Olga Kornievskaiab8290ca2019-12-04 15:13:53 -05001221 status = nfserr_nodev;
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001222 type = get_fs_type("nfs");
1223 if (!type)
1224 goto out_free_rawdata;
1225
1226 /* Set the server:<export> for the vfs_kern_mount call */
1227 dev_name = kzalloc(len + 5, GFP_KERNEL);
1228 if (!dev_name)
1229 goto out_free_rawdata;
1230 snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
1231
1232 /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
1233 ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
1234 module_put(type->owner);
1235 if (IS_ERR(ss_mnt))
1236 goto out_free_devname;
1237
1238 status = 0;
1239 *mount = ss_mnt;
1240
1241out_free_devname:
1242 kfree(dev_name);
1243out_free_rawdata:
1244 kfree(raw_data);
1245out_free_ipaddr:
1246 kfree(ipaddr);
1247out_err:
1248 return status;
1249}
1250
1251static void
1252nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1253{
Dai Ngo0cfcd402020-10-18 23:42:49 -04001254 nfs_do_sb_deactive(ss_mnt->mnt_sb);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001255 mntput(ss_mnt);
1256}
1257
Chuck Leverf2453972020-04-06 16:01:42 -04001258/*
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001259 * Verify COPY destination stateid.
Chuck Leverf2453972020-04-06 16:01:42 -04001260 *
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001261 * Connect to the source server with NFSv4.1.
1262 * Create the source struct file for nfsd_copy_range.
1263 * Called with COPY cstate:
1264 * SAVED_FH: source filehandle
1265 * CURRENT_FH: destination filehandle
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001266 */
1267static __be32
1268nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1269 struct nfsd4_compound_state *cstate,
1270 struct nfsd4_copy *copy, struct vfsmount **mount)
1271{
1272 struct svc_fh *s_fh = NULL;
1273 stateid_t *s_stid = &copy->cp_src_stateid;
Olga Kornievskaiab8290ca2019-12-04 15:13:53 -05001274 __be32 status = nfserr_inval;
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001275
1276 /* Verify the destination stateid and set dst struct file*/
1277 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1278 &copy->cp_dst_stateid,
1279 WR_STATE, &copy->nf_dst, NULL);
1280 if (status)
1281 goto out;
1282
1283 status = nfsd4_interssc_connect(&copy->cp_src, rqstp, mount);
1284 if (status)
1285 goto out;
1286
1287 s_fh = &cstate->save_fh;
1288
1289 copy->c_fh.size = s_fh->fh_handle.fh_size;
1290 memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_base, copy->c_fh.size);
Olga Kornievskaia3f9544c2019-12-04 15:13:53 -05001291 copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001292 memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
1293 sizeof(stateid_opaque_t));
1294
1295 status = 0;
1296out:
1297 return status;
1298}
1299
1300static void
1301nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1302 struct nfsd_file *dst)
1303{
1304 nfs42_ssc_close(src->nf_file);
Olga Kornievskaia614c9752021-03-09 09:41:14 -05001305 fput(src->nf_file);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001306 nfsd_file_put(dst);
1307 mntput(ss_mnt);
1308}
1309
1310#else /* CONFIG_NFSD_V4_2_INTER_SSC */
1311
1312static __be32
1313nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1314 struct nfsd4_compound_state *cstate,
1315 struct nfsd4_copy *copy,
1316 struct vfsmount **mount)
1317{
1318 *mount = NULL;
Olga Kornievskaiab8290ca2019-12-04 15:13:53 -05001319 return nfserr_inval;
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001320}
1321
1322static void
1323nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1324 struct nfsd_file *dst)
1325{
1326}
1327
1328static void
1329nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1330{
1331}
1332
1333static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1334 struct nfs_fh *src_fh,
1335 nfs4_stateid *stateid)
1336{
1337 return NULL;
1338}
1339#endif /* CONFIG_NFSD_V4_2_INTER_SSC */
1340
1341static __be32
1342nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
1343 struct nfsd4_compound_state *cstate,
1344 struct nfsd4_copy *copy)
1345{
1346 return nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid,
1347 &copy->nf_src, &copy->cp_dst_stateid,
1348 &copy->nf_dst);
1349}
1350
1351static void
1352nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst)
1353{
1354 nfsd_file_put(src);
1355 nfsd_file_put(dst);
1356}
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001357
1358static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
1359{
1360 struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
1361
1362 nfs4_put_copy(copy);
1363}
1364
1365static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
1366 struct rpc_task *task)
1367{
1368 return 1;
1369}
1370
1371static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
1372 .release = nfsd4_cb_offload_release,
1373 .done = nfsd4_cb_offload_done
1374};
1375
1376static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
1377{
1378 copy->cp_res.wr_stable_how = NFS_UNSTABLE;
1379 copy->cp_synchronous = sync;
1380 gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net);
1381}
1382
1383static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
1384{
1385 ssize_t bytes_copied = 0;
J. Bruce Fieldse7a833e2021-03-18 20:03:22 -04001386 u64 bytes_total = copy->cp_count;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001387 u64 src_pos = copy->cp_src_pos;
1388 u64 dst_pos = copy->cp_dst_pos;
1389
J. Bruce Fields792a5112021-03-18 20:03:23 -04001390 /* See RFC 7862 p.67: */
1391 if (bytes_total == 0)
1392 bytes_total = ULLONG_MAX;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001393 do {
1394 if (kthread_should_stop())
1395 break;
Jeff Layton5c4583b2019-08-18 14:18:54 -04001396 bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file,
1397 src_pos, copy->nf_dst->nf_file, dst_pos,
1398 bytes_total);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001399 if (bytes_copied <= 0)
1400 break;
1401 bytes_total -= bytes_copied;
1402 copy->cp_res.wr_bytes_written += bytes_copied;
1403 src_pos += bytes_copied;
1404 dst_pos += bytes_copied;
1405 } while (bytes_total > 0 && !copy->cp_synchronous);
1406 return bytes_copied;
1407}
1408
1409static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
1410{
1411 __be32 status;
1412 ssize_t bytes;
1413
1414 bytes = _nfsd_copy_file_range(copy);
1415 /* for async copy, we ignore the error, client can always retry
1416 * to get the error
1417 */
1418 if (bytes < 0 && !copy->cp_res.wr_bytes_written)
1419 status = nfserrno(bytes);
1420 else {
1421 nfsd4_init_copy_res(copy, sync);
1422 status = nfs_ok;
1423 }
1424
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001425 if (!copy->cp_intra) /* Inter server SSC */
1426 nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src,
1427 copy->nf_dst);
1428 else
1429 nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
1430
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001431 return status;
1432}
1433
Chuck Levereb162e12020-11-30 16:17:40 -05001434static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001435{
1436 dst->cp_src_pos = src->cp_src_pos;
1437 dst->cp_dst_pos = src->cp_dst_pos;
1438 dst->cp_count = src->cp_count;
1439 dst->cp_synchronous = src->cp_synchronous;
1440 memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
1441 memcpy(&dst->fh, &src->fh, sizeof(src->fh));
1442 dst->cp_clp = src->cp_clp;
Jeff Layton5c4583b2019-08-18 14:18:54 -04001443 dst->nf_dst = nfsd_file_get(src->nf_dst);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001444 dst->cp_intra = src->cp_intra;
1445 if (src->cp_intra) /* for inter, file_src doesn't exist yet */
1446 dst->nf_src = nfsd_file_get(src->nf_src);
1447
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001448 memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001449 memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server));
1450 memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid));
1451 memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh));
1452 dst->ss_mnt = src->ss_mnt;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001453}
1454
1455static void cleanup_async_copy(struct nfsd4_copy *copy)
1456{
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001457 nfs4_free_copy_state(copy);
Jeff Layton5c4583b2019-08-18 14:18:54 -04001458 nfsd_file_put(copy->nf_dst);
Olga Kornievskaia2e577f02019-12-04 15:13:54 -05001459 if (copy->cp_intra)
1460 nfsd_file_put(copy->nf_src);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001461 spin_lock(&copy->cp_clp->async_lock);
1462 list_del(&copy->copies);
1463 spin_unlock(&copy->cp_clp->async_lock);
1464 nfs4_put_copy(copy);
1465}
1466
1467static int nfsd4_do_async_copy(void *data)
1468{
1469 struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1470 struct nfsd4_copy *cb_copy;
1471
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001472 if (!copy->cp_intra) { /* Inter server SSC */
1473 copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL);
1474 if (!copy->nf_src) {
1475 copy->nfserr = nfserr_serverfault;
1476 nfsd4_interssc_disconnect(copy->ss_mnt);
1477 goto do_callback;
1478 }
1479 copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, &copy->c_fh,
1480 &copy->stateid);
1481 if (IS_ERR(copy->nf_src->nf_file)) {
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001482 copy->nfserr = nfserr_offload_denied;
1483 nfsd4_interssc_disconnect(copy->ss_mnt);
1484 goto do_callback;
1485 }
1486 }
1487
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001488 copy->nfserr = nfsd4_do_copy(copy, 0);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001489do_callback:
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001490 cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1491 if (!cb_copy)
1492 goto out;
Dai Ngo49a36132020-10-29 15:07:16 -04001493 refcount_set(&cb_copy->refcount, 1);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001494 memcpy(&cb_copy->cp_res, &copy->cp_res, sizeof(copy->cp_res));
1495 cb_copy->cp_clp = copy->cp_clp;
1496 cb_copy->nfserr = copy->nfserr;
1497 memcpy(&cb_copy->fh, &copy->fh, sizeof(copy->fh));
1498 nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp,
1499 &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD);
1500 nfsd4_run_cb(&cb_copy->cp_cb);
1501out:
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001502 if (!copy->cp_intra)
1503 kfree(copy->nf_src);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001504 cleanup_async_copy(copy);
1505 return 0;
1506}
1507
Christoph Hellwigffa01602015-12-03 12:59:52 +01001508static __be32
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001509nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001510 union nfsd4_op_u *u)
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001511{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001512 struct nfsd4_copy *copy = &u->copy;
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001513 __be32 status;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001514 struct nfsd4_copy *async_copy = NULL;
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001515
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001516 if (!copy->cp_intra) { /* Inter server SSC */
1517 if (!inter_copy_offload_enable || copy->cp_synchronous) {
1518 status = nfserr_notsupp;
1519 goto out;
1520 }
1521 status = nfsd4_setup_inter_ssc(rqstp, cstate, copy,
1522 &copy->ss_mnt);
1523 if (status)
1524 return nfserr_offload_denied;
1525 } else {
1526 status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
1527 if (status)
1528 return status;
1529 }
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001530
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001531 copy->cp_clp = cstate->clp;
1532 memcpy(&copy->fh, &cstate->current_fh.fh_handle,
1533 sizeof(struct knfsd_fh));
1534 if (!copy->cp_synchronous) {
1535 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001536
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001537 status = nfserrno(-ENOMEM);
1538 async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1539 if (!async_copy)
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001540 goto out_err;
1541 if (!nfs4_init_copy_state(nn, copy))
1542 goto out_err;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001543 refcount_set(&async_copy->refcount, 1);
1544 memcpy(&copy->cp_res.cb_stateid, &copy->cp_stateid,
1545 sizeof(copy->cp_stateid));
Chuck Levereb162e12020-11-30 16:17:40 -05001546 dup_copy_fields(copy, async_copy);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001547 async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
1548 async_copy, "%s", "copy thread");
1549 if (IS_ERR(async_copy->copy_task))
1550 goto out_err;
1551 spin_lock(&async_copy->cp_clp->async_lock);
1552 list_add(&async_copy->copies,
1553 &async_copy->cp_clp->async_copies);
1554 spin_unlock(&async_copy->cp_clp->async_lock);
1555 wake_up_process(async_copy->copy_task);
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001556 status = nfs_ok;
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001557 } else {
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001558 status = nfsd4_do_copy(copy, 1);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001559 }
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001560out:
1561 return status;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001562out_err:
Olga Kornievskaia18f428d2019-12-04 15:13:54 -05001563 if (async_copy)
1564 cleanup_async_copy(async_copy);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001565 status = nfserrno(-ENOMEM);
1566 if (!copy->cp_intra)
1567 nfsd4_interssc_disconnect(copy->ss_mnt);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001568 goto out;
1569}
1570
1571struct nfsd4_copy *
1572find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
1573{
1574 struct nfsd4_copy *copy;
1575
1576 spin_lock(&clp->async_lock);
1577 list_for_each_entry(copy, &clp->async_copies, copies) {
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001578 if (memcmp(&copy->cp_stateid.stid, stateid, NFS4_STATEID_SIZE))
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001579 continue;
1580 refcount_inc(&copy->refcount);
1581 spin_unlock(&clp->async_lock);
1582 return copy;
1583 }
1584 spin_unlock(&clp->async_lock);
1585 return NULL;
Anna Schumaker29ae7f92016-09-07 15:57:30 -04001586}
1587
1588static __be32
Olga Kornievskaia885e2bf2018-07-20 18:19:19 -04001589nfsd4_offload_cancel(struct svc_rqst *rqstp,
1590 struct nfsd4_compound_state *cstate,
1591 union nfsd4_op_u *u)
1592{
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001593 struct nfsd4_offload_status *os = &u->offload_status;
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001594 struct nfsd4_copy *copy;
1595 struct nfs4_client *clp = cstate->clp;
1596
1597 copy = find_async_copy(clp, &os->stateid);
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001598 if (!copy) {
1599 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001600
Olga Kornievskaiace0887a2019-10-09 11:50:48 -04001601 return manage_cpntf_state(nn, &os->stateid, clp, NULL);
1602 } else
1603 nfsd4_stop_copy(copy);
1604
1605 return nfs_ok;
Olga Kornievskaia885e2bf2018-07-20 18:19:19 -04001606}
1607
1608static __be32
Olga Kornievskaia51911862019-08-08 11:14:59 -04001609nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1610 union nfsd4_op_u *u)
1611{
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001612 struct nfsd4_copy_notify *cn = &u->copy_notify;
1613 __be32 status;
1614 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1615 struct nfs4_stid *stid;
1616 struct nfs4_cpntf_state *cps;
1617 struct nfs4_client *clp = cstate->clp;
1618
1619 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1620 &cn->cpn_src_stateid, RD_STATE, NULL,
1621 &stid);
1622 if (status)
1623 return status;
1624
1625 cn->cpn_sec = nn->nfsd4_lease;
1626 cn->cpn_nsec = 0;
1627
1628 status = nfserrno(-ENOMEM);
1629 cps = nfs4_alloc_init_cpntf_state(nn, stid);
1630 if (!cps)
1631 goto out;
1632 memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t));
1633 memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t));
1634 memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t));
1635
1636 /* For now, only return one server address in cpn_src, the
1637 * address used by the client to connect to this server.
1638 */
1639 cn->cpn_src.nl4_type = NL4_NETADDR;
1640 status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr,
1641 &cn->cpn_src.u.nl4_addr);
1642 WARN_ON_ONCE(status);
1643 if (status) {
1644 nfs4_put_cpntf_state(nn, cps);
1645 goto out;
1646 }
1647out:
1648 nfs4_put_stid(stid);
1649 return status;
Olga Kornievskaia51911862019-08-08 11:14:59 -04001650}
1651
1652static __be32
Anna Schumaker95d871f2014-11-07 14:44:26 -05001653nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1654 struct nfsd4_fallocate *fallocate, int flags)
1655{
J. Bruce Fields0d4d6722018-11-06 17:44:03 -05001656 __be32 status;
Jeff Layton5c4583b2019-08-18 14:18:54 -04001657 struct nfsd_file *nf;
Anna Schumaker95d871f2014-11-07 14:44:26 -05001658
Anna Schumakeraa0d6ae2015-12-03 12:59:51 +01001659 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
Anna Schumaker95d871f2014-11-07 14:44:26 -05001660 &fallocate->falloc_stateid,
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001661 WR_STATE, &nf, NULL);
Anna Schumaker95d871f2014-11-07 14:44:26 -05001662 if (status != nfs_ok) {
1663 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
1664 return status;
1665 }
1666
Jeff Layton5c4583b2019-08-18 14:18:54 -04001667 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
Anna Schumaker95d871f2014-11-07 14:44:26 -05001668 fallocate->falloc_offset,
1669 fallocate->falloc_length,
1670 flags);
Jeff Layton5c4583b2019-08-18 14:18:54 -04001671 nfsd_file_put(nf);
Anna Schumaker95d871f2014-11-07 14:44:26 -05001672 return status;
1673}
Olga Kornievskaia6308bc92018-07-20 18:19:18 -04001674static __be32
1675nfsd4_offload_status(struct svc_rqst *rqstp,
1676 struct nfsd4_compound_state *cstate,
1677 union nfsd4_op_u *u)
1678{
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -04001679 struct nfsd4_offload_status *os = &u->offload_status;
1680 __be32 status = 0;
1681 struct nfsd4_copy *copy;
1682 struct nfs4_client *clp = cstate->clp;
1683
1684 copy = find_async_copy(clp, &os->stateid);
1685 if (copy) {
1686 os->count = copy->cp_res.wr_bytes_written;
1687 nfs4_put_copy(copy);
1688 } else
1689 status = nfserr_bad_stateid;
1690
1691 return status;
Olga Kornievskaia6308bc92018-07-20 18:19:18 -04001692}
Anna Schumaker95d871f2014-11-07 14:44:26 -05001693
1694static __be32
1695nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001696 union nfsd4_op_u *u)
Anna Schumaker95d871f2014-11-07 14:44:26 -05001697{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001698 return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
Anna Schumaker95d871f2014-11-07 14:44:26 -05001699}
1700
1701static __be32
Anna Schumakerb0cb9082014-11-07 14:44:27 -05001702nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001703 union nfsd4_op_u *u)
Anna Schumakerb0cb9082014-11-07 14:44:27 -05001704{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001705 return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
Anna Schumakerb0cb9082014-11-07 14:44:27 -05001706 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
1707}
1708
1709static __be32
Anna Schumaker24bab492014-09-26 13:58:27 -04001710nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001711 union nfsd4_op_u *u)
Anna Schumaker24bab492014-09-26 13:58:27 -04001712{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001713 struct nfsd4_seek *seek = &u->seek;
Anna Schumaker24bab492014-09-26 13:58:27 -04001714 int whence;
1715 __be32 status;
Jeff Layton5c4583b2019-08-18 14:18:54 -04001716 struct nfsd_file *nf;
Anna Schumaker24bab492014-09-26 13:58:27 -04001717
Anna Schumakeraa0d6ae2015-12-03 12:59:51 +01001718 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
Anna Schumaker24bab492014-09-26 13:58:27 -04001719 &seek->seek_stateid,
Olga Kornievskaia624322f2019-10-04 16:34:26 -04001720 RD_STATE, &nf, NULL);
Anna Schumaker24bab492014-09-26 13:58:27 -04001721 if (status) {
1722 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
1723 return status;
1724 }
1725
1726 switch (seek->seek_whence) {
1727 case NFS4_CONTENT_DATA:
1728 whence = SEEK_DATA;
1729 break;
1730 case NFS4_CONTENT_HOLE:
1731 whence = SEEK_HOLE;
1732 break;
1733 default:
1734 status = nfserr_union_notsupp;
1735 goto out;
1736 }
1737
1738 /*
1739 * Note: This call does change file->f_pos, but nothing in NFSD
1740 * should ever file->f_pos.
1741 */
Jeff Layton5c4583b2019-08-18 14:18:54 -04001742 seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
Anna Schumaker24bab492014-09-26 13:58:27 -04001743 if (seek->seek_pos < 0)
1744 status = nfserrno(seek->seek_pos);
Jeff Layton5c4583b2019-08-18 14:18:54 -04001745 else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
Anna Schumaker24bab492014-09-26 13:58:27 -04001746 seek->seek_eof = true;
1747
1748out:
Jeff Layton5c4583b2019-08-18 14:18:54 -04001749 nfsd_file_put(nf);
Anna Schumaker24bab492014-09-26 13:58:27 -04001750 return status;
1751}
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753/* This routine never returns NFS_OK! If there are no other errors, it
1754 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
1755 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
1756 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
1757 */
Al Virob37ad282006-10-19 23:28:59 -07001758static __be32
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001759_nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001760 struct nfsd4_verify *verify)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
Al Viro2ebbc012006-10-19 23:28:58 -07001762 __be32 *buf, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 int count;
Al Virob37ad282006-10-19 23:28:59 -07001764 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Miklos Szeredi8837abc2008-06-16 13:20:29 +02001766 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 if (status)
1768 return status;
1769
Yu Zhiguo3c8e0312009-05-16 16:22:31 +08001770 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
1771 if (status)
1772 return status;
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
1775 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
1776 return nfserr_inval;
1777 if (verify->ve_attrlen & 3)
1778 return nfserr_inval;
1779
1780 /* count in words:
1781 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
1782 */
1783 count = 4 + (verify->ve_attrlen >> 2);
1784 buf = kmalloc(count << 2, GFP_KERNEL);
1785 if (!buf)
J. Bruce Fields3e772462011-08-10 19:07:33 -04001786 return nfserr_jukebox;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
J. Bruce Fields84822d02012-12-14 17:57:50 -05001788 p = buf;
J. Bruce Fieldsd5184652013-08-26 16:04:46 -04001789 status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001790 cstate->current_fh.fh_export,
J. Bruce Fieldsd5184652013-08-26 16:04:46 -04001791 cstate->current_fh.fh_dentry,
1792 verify->ve_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08001793 rqstp, 0);
J. Bruce Fields41ae6e712013-08-21 15:32:50 -04001794 /*
1795 * If nfsd4_encode_fattr() ran out of space, assume that's because
1796 * the attributes are longer (hence different) than those given:
1797 */
J. Bruce Fields84822d02012-12-14 17:57:50 -05001798 if (status == nfserr_resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 status = nfserr_not_same;
1800 if (status)
1801 goto out_kfree;
1802
Benny Halevy95ec28c2009-04-03 08:29:08 +03001803 /* skip bitmap */
1804 p = buf + 1 + ntohl(buf[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 status = nfserr_not_same;
1806 if (ntohl(*p++) != verify->ve_attrlen)
1807 goto out_kfree;
1808 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
1809 status = nfserr_same;
1810
1811out_kfree:
1812 kfree(buf);
1813 return status;
1814}
1815
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001816static __be32
1817nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001818 union nfsd4_op_u *u)
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001819{
1820 __be32 status;
1821
Christoph Hellwigeb698532017-05-08 20:58:35 +02001822 status = _nfsd4_verify(rqstp, cstate, &u->verify);
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001823 return status == nfserr_not_same ? nfs_ok : status;
1824}
1825
1826static __be32
1827nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001828 union nfsd4_op_u *u)
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001829{
1830 __be32 status;
1831
Christoph Hellwigeb698532017-05-08 20:58:35 +02001832 status = _nfsd4_verify(rqstp, cstate, &u->nverify);
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001833 return status == nfserr_same ? nfs_ok : status;
1834}
1835
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001836#ifdef CONFIG_NFSD_PNFS
1837static const struct nfsd4_layout_ops *
1838nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
1839{
Jeff Layton8a4c3922016-07-10 15:55:58 -04001840 if (!exp->ex_layout_types) {
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001841 dprintk("%s: export does not support pNFS\n", __func__);
1842 return NULL;
1843 }
1844
Ari Kauppib550a322017-05-05 16:07:55 -04001845 if (layout_type >= LAYOUT_TYPE_MAX ||
1846 !(exp->ex_layout_types & (1 << layout_type))) {
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001847 dprintk("%s: layout type %d not supported\n",
1848 __func__, layout_type);
1849 return NULL;
1850 }
1851
1852 return nfsd4_layout_ops[layout_type];
1853}
1854
1855static __be32
1856nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001857 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001858{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001859 struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001860 const struct nfsd4_layout_ops *ops;
1861 struct nfsd4_deviceid_map *map;
1862 struct svc_export *exp;
1863 __be32 nfserr;
1864
1865 dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
1866 __func__,
1867 gdp->gd_layout_type,
1868 gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
1869 gdp->gd_maxcount);
1870
1871 map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
1872 if (!map) {
1873 dprintk("%s: couldn't find device ID to export mapping!\n",
1874 __func__);
1875 return nfserr_noent;
1876 }
1877
1878 exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
1879 if (IS_ERR(exp)) {
1880 dprintk("%s: could not find device id\n", __func__);
1881 return nfserr_noent;
1882 }
1883
1884 nfserr = nfserr_layoutunavailable;
1885 ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
1886 if (!ops)
1887 goto out;
1888
1889 nfserr = nfs_ok;
Christoph Hellwigf99d4fb2016-03-04 20:46:17 +01001890 if (gdp->gd_maxcount != 0) {
1891 nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
J. Bruce Fieldsec596592021-01-21 17:57:45 -05001892 rqstp, cstate->clp, gdp);
Christoph Hellwigf99d4fb2016-03-04 20:46:17 +01001893 }
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001894
1895 gdp->gd_notify_types &= ops->notify_types;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001896out:
Kinglong Meea1420382015-03-15 23:12:15 +08001897 exp_put(exp);
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001898 return nfserr;
1899}
1900
J. Bruce Fields34b1744c2017-05-05 17:09:37 -04001901static void
1902nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
1903{
1904 kfree(u->getdeviceinfo.gd_device);
1905}
1906
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001907static __be32
1908nfsd4_layoutget(struct svc_rqst *rqstp,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001909 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001910{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001911 struct nfsd4_layoutget *lgp = &u->layoutget;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001912 struct svc_fh *current_fh = &cstate->current_fh;
1913 const struct nfsd4_layout_ops *ops;
1914 struct nfs4_layout_stateid *ls;
1915 __be32 nfserr;
Benjamin Coddington66282ec2017-12-19 09:35:25 -05001916 int accmode = NFSD_MAY_READ_IF_EXEC;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001917
1918 switch (lgp->lg_seg.iomode) {
1919 case IOMODE_READ:
Benjamin Coddington66282ec2017-12-19 09:35:25 -05001920 accmode |= NFSD_MAY_READ;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001921 break;
1922 case IOMODE_RW:
Benjamin Coddington66282ec2017-12-19 09:35:25 -05001923 accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001924 break;
1925 default:
1926 dprintk("%s: invalid iomode %d\n",
1927 __func__, lgp->lg_seg.iomode);
1928 nfserr = nfserr_badiomode;
1929 goto out;
1930 }
1931
1932 nfserr = fh_verify(rqstp, current_fh, 0, accmode);
1933 if (nfserr)
1934 goto out;
1935
1936 nfserr = nfserr_layoutunavailable;
1937 ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
1938 if (!ops)
1939 goto out;
1940
1941 /*
1942 * Verify minlength and range as per RFC5661:
1943 * o If loga_length is less than loga_minlength,
1944 * the metadata server MUST return NFS4ERR_INVAL.
1945 * o If the sum of loga_offset and loga_minlength exceeds
1946 * NFS4_UINT64_MAX, and loga_minlength is not
1947 * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
1948 * o If the sum of loga_offset and loga_length exceeds
1949 * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
1950 * the error NFS4ERR_INVAL MUST result.
1951 */
1952 nfserr = nfserr_inval;
1953 if (lgp->lg_seg.length < lgp->lg_minlength ||
1954 (lgp->lg_minlength != NFS4_MAX_UINT64 &&
1955 lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
1956 (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
1957 lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
1958 goto out;
1959 if (lgp->lg_seg.length == 0)
1960 goto out;
1961
1962 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
1963 true, lgp->lg_layout_type, &ls);
Christoph Hellwig31ef83d2014-08-16 19:02:22 -05001964 if (nfserr) {
Chuck Leverf394b622018-03-27 10:53:11 -04001965 trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001966 goto out;
Christoph Hellwig31ef83d2014-08-16 19:02:22 -05001967 }
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001968
Christoph Hellwigc5c707f2014-09-23 12:38:48 +02001969 nfserr = nfserr_recallconflict;
1970 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
1971 goto out_put_stid;
1972
David Howells2b0143b2015-03-17 22:25:59 +00001973 nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001974 current_fh, lgp);
1975 if (nfserr)
1976 goto out_put_stid;
1977
1978 nfserr = nfsd4_insert_layout(lgp, ls);
1979
1980out_put_stid:
Jeff Laytoncc8a5532015-09-17 07:58:24 -04001981 mutex_unlock(&ls->ls_mutex);
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001982 nfs4_put_stid(&ls->ls_stid);
1983out:
1984 return nfserr;
1985}
1986
J. Bruce Fields34b1744c2017-05-05 17:09:37 -04001987static void
1988nfsd4_layoutget_release(union nfsd4_op_u *u)
1989{
1990 kfree(u->layoutget.lg_content);
1991}
1992
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001993static __be32
1994nfsd4_layoutcommit(struct svc_rqst *rqstp,
Christoph Hellwigeb698532017-05-08 20:58:35 +02001995 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001996{
Christoph Hellwigeb698532017-05-08 20:58:35 +02001997 struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02001998 const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
1999 struct svc_fh *current_fh = &cstate->current_fh;
2000 const struct nfsd4_layout_ops *ops;
2001 loff_t new_size = lcp->lc_last_wr + 1;
2002 struct inode *inode;
2003 struct nfs4_layout_stateid *ls;
2004 __be32 nfserr;
2005
2006 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
2007 if (nfserr)
2008 goto out;
2009
2010 nfserr = nfserr_layoutunavailable;
2011 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
2012 if (!ops)
2013 goto out;
David Howells2b0143b2015-03-17 22:25:59 +00002014 inode = d_inode(current_fh->fh_dentry);
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002015
2016 nfserr = nfserr_inval;
2017 if (new_size <= seg->offset) {
2018 dprintk("pnfsd: last write before layout segment\n");
2019 goto out;
2020 }
2021 if (new_size > seg->offset + seg->length) {
2022 dprintk("pnfsd: last write beyond layout segment\n");
2023 goto out;
2024 }
2025 if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
2026 dprintk("pnfsd: layoutcommit beyond EOF\n");
2027 goto out;
2028 }
2029
2030 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
2031 false, lcp->lc_layout_type,
2032 &ls);
2033 if (nfserr) {
Chuck Leverf394b622018-03-27 10:53:11 -04002034 trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002035 /* fixup error code as per RFC5661 */
2036 if (nfserr == nfserr_bad_stateid)
2037 nfserr = nfserr_badlayout;
2038 goto out;
2039 }
2040
Jeff Laytoncc8a5532015-09-17 07:58:24 -04002041 /* LAYOUTCOMMIT does not require any serialization */
2042 mutex_unlock(&ls->ls_mutex);
2043
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002044 if (new_size > i_size_read(inode)) {
2045 lcp->lc_size_chg = 1;
2046 lcp->lc_newsize = new_size;
2047 } else {
2048 lcp->lc_size_chg = 0;
2049 }
2050
Kinglong Meed8398fc2015-07-07 10:12:03 +08002051 nfserr = ops->proc_layoutcommit(inode, lcp);
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002052 nfs4_put_stid(&ls->ls_stid);
2053out:
2054 return nfserr;
2055}
2056
2057static __be32
2058nfsd4_layoutreturn(struct svc_rqst *rqstp,
Christoph Hellwigeb698532017-05-08 20:58:35 +02002059 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002060{
Christoph Hellwigeb698532017-05-08 20:58:35 +02002061 struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002062 struct svc_fh *current_fh = &cstate->current_fh;
2063 __be32 nfserr;
2064
2065 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
2066 if (nfserr)
2067 goto out;
2068
2069 nfserr = nfserr_layoutunavailable;
2070 if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
2071 goto out;
2072
2073 switch (lrp->lr_seg.iomode) {
2074 case IOMODE_READ:
2075 case IOMODE_RW:
2076 case IOMODE_ANY:
2077 break;
2078 default:
2079 dprintk("%s: invalid iomode %d\n", __func__,
2080 lrp->lr_seg.iomode);
2081 nfserr = nfserr_inval;
2082 goto out;
2083 }
2084
2085 switch (lrp->lr_return_type) {
2086 case RETURN_FILE:
2087 nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
2088 break;
2089 case RETURN_FSID:
2090 case RETURN_ALL:
2091 nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
2092 break;
2093 default:
2094 dprintk("%s: invalid return_type %d\n", __func__,
2095 lrp->lr_return_type);
2096 nfserr = nfserr_inval;
2097 break;
2098 }
2099out:
2100 return nfserr;
2101}
2102#endif /* CONFIG_NFSD_PNFS */
2103
Frank van der Linden23e50fe2020-06-23 22:39:26 +00002104static __be32
2105nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2106 union nfsd4_op_u *u)
2107{
2108 struct nfsd4_getxattr *getxattr = &u->getxattr;
2109
2110 return nfsd_getxattr(rqstp, &cstate->current_fh,
2111 getxattr->getxa_name, &getxattr->getxa_buf,
2112 &getxattr->getxa_len);
2113}
2114
2115static __be32
2116nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2117 union nfsd4_op_u *u)
2118{
2119 struct nfsd4_setxattr *setxattr = &u->setxattr;
2120 __be32 ret;
2121
2122 if (opens_in_grace(SVC_NET(rqstp)))
2123 return nfserr_grace;
2124
2125 ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
2126 setxattr->setxa_buf, setxattr->setxa_len,
2127 setxattr->setxa_flags);
2128
2129 if (!ret)
2130 set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
2131
2132 return ret;
2133}
2134
2135static __be32
2136nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2137 union nfsd4_op_u *u)
2138{
2139 /*
2140 * Get the entire list, then copy out only the user attributes
2141 * in the encode function.
2142 */
2143 return nfsd_listxattr(rqstp, &cstate->current_fh,
2144 &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
2145}
2146
2147static __be32
2148nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2149 union nfsd4_op_u *u)
2150{
2151 struct nfsd4_removexattr *removexattr = &u->removexattr;
2152 __be32 ret;
2153
2154 if (opens_in_grace(SVC_NET(rqstp)))
2155 return nfserr_grace;
2156
2157 ret = nfsd_removexattr(rqstp, &cstate->current_fh,
2158 removexattr->rmxa_name);
2159
2160 if (!ret)
2161 set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
2162
2163 return ret;
2164}
2165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166/*
2167 * NULL call.
2168 */
Al Viro7111c662006-10-19 23:28:45 -07002169static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +02002170nfsd4_proc_null(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171{
Chuck Levercc028a12020-10-02 15:52:44 -04002172 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
Shankar Anande2b20952006-07-10 04:45:44 -07002175static inline void nfsd4_increment_op_stats(u32 opnum)
2176{
2177 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
Amir Goldsteine567b982021-01-06 09:52:35 +02002178 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]);
Shankar Anande2b20952006-07-10 04:45:44 -07002179}
2180
Christoph Hellwigbb2a8b02017-05-08 23:46:47 +02002181static const struct nfsd4_operation nfsd4_ops[];
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002182
Adrian Bunkf1c7f792008-08-08 19:26:42 +03002183static const char *nfsd4_op_name(unsigned opnum);
Benny Halevyb001a1b2008-07-02 11:15:03 +03002184
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185/*
J. Bruce Fields57716352010-04-21 12:27:19 -04002186 * Enforce NFSv4.1 COMPOUND ordering rules:
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002187 *
J. Bruce Fields57716352010-04-21 12:27:19 -04002188 * Also note, enforced elsewhere:
2189 * - SEQUENCE other than as first op results in
2190 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04002191 * - BIND_CONN_TO_SESSION must be the only op in its compound.
2192 * (Enforced in nfsd4_bind_conn_to_session().)
J. Bruce Fields57716352010-04-21 12:27:19 -04002193 * - DESTROY_SESSION must be the final operation in a compound, if
2194 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
2195 * (Enforced in nfsd4_destroy_session().)
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002196 */
J. Bruce Fields57716352010-04-21 12:27:19 -04002197static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002198{
J. Bruce Fields7a04cfd2018-06-13 15:04:59 -04002199 struct nfsd4_op *first_op = &args->ops[0];
J. Bruce Fields57716352010-04-21 12:27:19 -04002200
2201 /* These ordering requirements don't apply to NFSv4.0: */
2202 if (args->minorversion == 0)
2203 return nfs_ok;
2204 /* This is weird, but OK, not our problem: */
2205 if (args->opcnt == 0)
2206 return nfs_ok;
J. Bruce Fields7a04cfd2018-06-13 15:04:59 -04002207 if (first_op->status == nfserr_op_illegal)
J. Bruce Fields57716352010-04-21 12:27:19 -04002208 return nfs_ok;
J. Bruce Fields7a04cfd2018-06-13 15:04:59 -04002209 if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
J. Bruce Fields57716352010-04-21 12:27:19 -04002210 return nfserr_op_not_in_session;
J. Bruce Fields7a04cfd2018-06-13 15:04:59 -04002211 if (first_op->opnum == OP_SEQUENCE)
J. Bruce Fields57716352010-04-21 12:27:19 -04002212 return nfs_ok;
J. Bruce Fields7a04cfd2018-06-13 15:04:59 -04002213 /*
2214 * So first_op is something allowed outside a session, like
2215 * EXCHANGE_ID; but then it has to be the only op in the
2216 * compound:
2217 */
J. Bruce Fields57716352010-04-21 12:27:19 -04002218 if (args->opcnt != 1)
2219 return nfserr_not_only_op;
2220 return nfs_ok;
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002221}
2222
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002223const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
J. Bruce Fields22b03212011-04-09 11:23:24 -04002224{
2225 return &nfsd4_ops[op->opnum];
2226}
2227
J. Bruce Fields10910062011-01-24 12:11:02 -05002228bool nfsd4_cache_this_op(struct nfsd4_op *op)
2229{
J. Bruce Fieldse372ba62014-05-19 12:27:11 -04002230 if (op->opnum == OP_ILLEGAL)
2231 return false;
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04002232 return OPDESC(op)->op_flags & OP_CACHEME;
J. Bruce Fields10910062011-01-24 12:11:02 -05002233}
2234
J. Bruce Fields68d93182011-04-08 17:00:50 -04002235static bool need_wrongsec_check(struct svc_rqst *rqstp)
2236{
2237 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2238 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2239 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2240 struct nfsd4_op *next = &argp->ops[resp->opcnt];
Christoph Hellwigbb2a8b02017-05-08 23:46:47 +02002241 const struct nfsd4_operation *thisd = OPDESC(this);
2242 const struct nfsd4_operation *nextd;
J. Bruce Fields68d93182011-04-08 17:00:50 -04002243
J. Bruce Fields68d93182011-04-08 17:00:50 -04002244 /*
2245 * Most ops check wronsec on our own; only the putfh-like ops
2246 * have special rules.
2247 */
2248 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
2249 return false;
2250 /*
2251 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
2252 * put-filehandle operation if we're not going to use the
2253 * result:
2254 */
2255 if (argp->opcnt == resp->opcnt)
2256 return false;
J. Bruce Fields51904b02014-10-22 14:46:29 -04002257 if (next->opnum == OP_ILLEGAL)
2258 return false;
J. Bruce Fields68d93182011-04-08 17:00:50 -04002259 nextd = OPDESC(next);
2260 /*
2261 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
2262 * errors themselves as necessary; others should check for them
2263 * now:
2264 */
2265 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
2266}
2267
Olga Kornievskaiab9e86382019-10-07 10:56:48 -04002268#ifdef CONFIG_NFSD_V4_2_INTER_SSC
2269static void
2270check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2271{
2272 struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL;
2273 struct nfsd4_copy *copy;
2274 struct nfsd4_putfh *putfh;
2275 int i;
2276
2277 /* traverse all operation and if it's a COPY compound, mark the
2278 * source filehandle to skip verification
2279 */
2280 for (i = 0; i < args->opcnt; i++) {
2281 op = &args->ops[i];
2282 if (op->opnum == OP_PUTFH)
2283 current_op = op;
2284 else if (op->opnum == OP_SAVEFH)
2285 saved_op = current_op;
2286 else if (op->opnum == OP_RESTOREFH)
2287 current_op = saved_op;
2288 else if (op->opnum == OP_COPY) {
2289 copy = (struct nfsd4_copy *)&op->u;
2290 if (!saved_op) {
2291 op->status = nfserr_nofilehandle;
2292 return;
2293 }
2294 putfh = (struct nfsd4_putfh *)&saved_op->u;
2295 if (!copy->cp_intra)
2296 putfh->no_verify = true;
2297 }
2298 }
2299}
2300#else
2301static void
2302check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2303{
2304}
2305#endif
2306
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002307/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 * COMPOUND call.
2309 */
Al Viro7111c662006-10-19 23:28:45 -07002310static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +02002311nfsd4_proc_compound(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312{
Christoph Hellwiga6beb732017-05-08 17:35:49 +02002313 struct nfsd4_compoundargs *args = rqstp->rq_argp;
2314 struct nfsd4_compoundres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 struct nfsd4_op *op;
Andy Adamsone354d572009-03-28 11:30:52 +03002316 struct nfsd4_compound_state *cstate = &resp->cstate;
Kinglong Mee4daeed22014-03-26 17:10:37 +08002317 struct svc_fh *current_fh = &cstate->current_fh;
2318 struct svc_fh *save_fh = &cstate->save_fh;
Trond Myklebuste333f3b2019-04-09 11:46:19 -04002319 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
Al Virob37ad282006-10-19 23:28:59 -07002320 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Chuck Leverbddfdbc2020-10-27 15:53:42 -04002322 resp->xdr = &rqstp->rq_res_stream;
2323
2324 /* reserve space for: NFS status code */
2325 xdr_reserve_space(resp->xdr, XDR_UNIT);
2326
2327 resp->tagp = resp->xdr->p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 /* reserve space for: taglen, tag, and opcnt */
Chuck Leverbddfdbc2020-10-27 15:53:42 -04002329 xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 resp->taglen = args->taglen;
2331 resp->tag = args->tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 resp->rqstp = rqstp;
Kinglong Mee4daeed22014-03-26 17:10:37 +08002333 cstate->minorversion = args->minorversion;
Kinglong Mee4daeed22014-03-26 17:10:37 +08002334 fh_init(current_fh, NFS4_FHSIZE);
2335 fh_init(save_fh, NFS4_FHSIZE);
NeilBrown8ff30fa2010-08-12 17:04:07 +10002336 /*
2337 * Don't use the deferral mechanism for NFSv4; compounds make it
2338 * too hard to avoid non-idempotency problems.
2339 */
Jeff Layton30660e04b2014-11-19 07:51:16 -05002340 clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
2342 /*
2343 * According to RFC3010, this takes precedence over all other errors.
2344 */
2345 status = nfserr_minor_vers_mismatch;
Trond Myklebuste333f3b2019-04-09 11:46:19 -04002346 if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 goto out;
J. Bruce Fields00781172017-11-15 12:30:27 -05002348 status = nfserr_resource;
2349 if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
2350 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
J. Bruce Fields57716352010-04-21 12:27:19 -04002352 status = nfs41_check_op_ordering(args);
2353 if (status) {
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002354 op = &args->ops[0];
J. Bruce Fields57716352010-04-21 12:27:19 -04002355 op->status = status;
J. Bruce Fields5b7b15ae2018-06-13 15:21:35 -04002356 resp->opcnt = 1;
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002357 goto encode_op;
2358 }
Olga Kornievskaiab9e86382019-10-07 10:56:48 -04002359 check_if_stalefh_allowed(args);
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03002360
J. Bruce Fields28df3d12017-07-28 16:35:15 -04002361 rqstp->rq_lease_breaker = (void **)&cstate->clp;
2362
Chuck Leverfff40802018-03-27 10:53:54 -04002363 trace_nfsd_compound(rqstp, args->opcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 while (!status && resp->opcnt < args->opcnt) {
2365 op = &args->ops[resp->opcnt++];
2366
2367 /*
2368 * The XDR decode routines may have pre-set op->status;
2369 * for example, if there is a miscellaneous XDR error
2370 * it will be set to nfserr_bad_xdr.
2371 */
J. Bruce Fields9d313b12013-02-28 12:51:49 -08002372 if (op->status) {
2373 if (op->opnum == OP_OPEN)
2374 op->status = nfsd4_open_omfg(rqstp, cstate, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 goto encode_op;
J. Bruce Fields9d313b12013-02-28 12:51:49 -08002376 }
Olga Kornievskaiab9e86382019-10-07 10:56:48 -04002377 if (!current_fh->fh_dentry &&
2378 !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) {
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002379 if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002380 op->status = nfserr_nofilehandle;
2381 goto encode_op;
2382 }
Olga Kornievskaiab9e86382019-10-07 10:56:48 -04002383 } else if (current_fh->fh_export &&
2384 current_fh->fh_export->ex_fslocs.migrated &&
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002385 !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002386 op->status = nfserr_moved;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 goto encode_op;
2388 }
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002389
Kinglong Mee23367452014-03-29 10:23:47 +08002390 fh_clear_wcc(current_fh);
2391
Mi Jinlong58e7b332011-08-28 18:18:56 +08002392 /* If op is non-idempotent */
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002393 if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
J. Bruce Fields4c69d582014-01-28 16:01:04 -05002394 /*
J. Bruce Fieldsa8095f72014-03-11 17:54:34 -04002395 * Don't execute this op if we couldn't encode a
2396 * succesful reply:
2397 */
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002398 u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
J. Bruce Fieldsa8095f72014-03-11 17:54:34 -04002399 /*
2400 * Plus if there's another operation, make sure
J. Bruce Fields4c69d582014-01-28 16:01:04 -05002401 * we'll have space to at least encode an error:
2402 */
2403 if (resp->opcnt < args->opcnt)
2404 plen += COMPOUND_ERR_SLACK_SPACE;
Mi Jinlong58e7b332011-08-28 18:18:56 +08002405 op->status = nfsd4_check_resp_size(resp, plen);
2406 }
2407
2408 if (op->status)
2409 goto encode_op;
2410
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002411 if (op->opdesc->op_get_currentstateid)
2412 op->opdesc->op_get_currentstateid(cstate, &op->u);
2413 op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
J. Bruce Fields9a307402017-05-23 12:24:40 -04002415 /* Only from SEQUENCE */
2416 if (cstate->status == nfserr_replay_cache) {
2417 dprintk("%s NFS4.1 replay from cache\n", __func__);
2418 status = op->status;
2419 goto out;
2420 }
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01002421 if (!op->status) {
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002422 if (op->opdesc->op_set_currentstateid)
2423 op->opdesc->op_set_currentstateid(cstate, &op->u);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01002424
J. Bruce Fieldsf4f9ef42017-07-06 17:51:29 -04002425 if (op->opdesc->op_flags & OP_CLEAR_STATEID)
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +01002426 clear_current_stateid(cstate);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01002427
J. Bruce Fieldsd781e3d2019-12-06 16:07:32 -05002428 if (current_fh->fh_export &&
2429 need_wrongsec_check(rqstp))
Kinglong Mee4daeed22014-03-26 17:10:37 +08002430 op->status = check_nfsd_access(current_fh->fh_export, rqstp);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01002431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432encode_op:
Al Viroa90b0612006-10-19 23:29:03 -07002433 if (op->status == nfserr_replay_me) {
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08002434 op->replay = &cstate->replay_owner->so_replay;
Chuck Leverbddfdbc2020-10-27 15:53:42 -04002435 nfsd4_encode_replay(resp->xdr, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 status = op->status = op->replay->rp_status;
2437 } else {
2438 nfsd4_encode_operation(resp, op);
2439 status = op->status;
2440 }
Benny Halevy04077172008-12-15 19:40:49 +02002441
Chuck Leverfff40802018-03-27 10:53:54 -04002442 trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
2443 nfsd4_op_name(op->opnum));
Benny Halevy04077172008-12-15 19:40:49 +02002444
Jeff Layton58fb12e2014-07-29 21:34:27 -04002445 nfsd4_cstate_clear_replay(cstate);
Shankar Anande2b20952006-07-10 04:45:44 -07002446 nfsd4_increment_op_stats(op->opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 }
2448
Kinglong Mee4daeed22014-03-26 17:10:37 +08002449 fh_put(current_fh);
2450 fh_put(save_fh);
2451 BUG_ON(cstate->replay_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452out:
Chuck Levercc028a12020-10-02 15:52:44 -04002453 cstate->status = status;
Andy Adamson2f425872009-04-03 08:27:32 +03002454 /* Reset deferral mechanism for RPC deferrals */
Jeff Layton30660e04b2014-11-19 07:51:16 -05002455 set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
Chuck Levercc028a12020-10-02 15:52:44 -04002456 return rpc_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457}
2458
Mi Jinlong58e7b332011-08-28 18:18:56 +08002459#define op_encode_hdr_size (2)
2460#define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
2461#define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
2462#define op_encode_change_info_maxsz (5)
2463#define nfs4_fattr_bitmap_maxsz (4)
2464
J. Bruce Fields8c7424c2014-03-10 12:19:10 -04002465/* We'll fall back on returning no lockowner if run out of space: */
2466#define op_encode_lockowner_maxsz (0)
Mi Jinlong58e7b332011-08-28 18:18:56 +08002467#define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
2468
2469#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
2470
2471#define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
2472#define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
2473 op_encode_ace_maxsz)
2474
2475#define op_encode_channel_attrs_maxsz (6 + 1 + 1)
2476
2477static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2478{
2479 return (op_encode_hdr_size) * sizeof(__be32);
2480}
2481
2482static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2483{
2484 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
2485}
2486
Kinglong Mee2282cd22017-02-03 22:36:00 +08002487static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2488{
2489 /* ac_supported, ac_resp_access */
2490 return (op_encode_hdr_size + 2)* sizeof(__be32);
2491}
2492
Mi Jinlong58e7b332011-08-28 18:18:56 +08002493static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2494{
2495 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
2496}
2497
2498static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2499{
2500 return (op_encode_hdr_size + op_encode_change_info_maxsz
2501 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2502}
2503
J. Bruce Fieldsb86cef62014-03-23 12:01:48 -04002504/*
2505 * Note since this is an idempotent operation we won't insist on failing
2506 * the op prematurely if the estimate is too large. We may turn off splice
2507 * reads unnecessarily.
2508 */
2509static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
2510 struct nfsd4_op *op)
2511{
2512 u32 *bmap = op->u.getattr.ga_bmval;
2513 u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
2514 u32 ret = 0;
2515
2516 if (bmap0 & FATTR4_WORD0_ACL)
2517 return svc_max_payload(rqstp);
2518 if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
2519 return svc_max_payload(rqstp);
2520
2521 if (bmap1 & FATTR4_WORD1_OWNER) {
2522 ret += IDMAP_NAMESZ + 4;
2523 bmap1 &= ~FATTR4_WORD1_OWNER;
2524 }
2525 if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
2526 ret += IDMAP_NAMESZ + 4;
2527 bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
2528 }
2529 if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
2530 ret += NFS4_FHSIZE + 4;
2531 bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
2532 }
2533 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
Kinglong Mee1ec8c0c2015-03-28 23:46:09 +08002534 ret += NFS4_MAXLABELLEN + 12;
J. Bruce Fieldsb86cef62014-03-23 12:01:48 -04002535 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2536 }
2537 /*
2538 * Largest of remaining attributes are 16 bytes (e.g.,
2539 * supported_attributes)
2540 */
2541 ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
2542 /* bitmask, length */
2543 ret += 20;
2544 return ret;
2545}
2546
Kinglong Mee2282cd22017-02-03 22:36:00 +08002547static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2548{
2549 return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
2550}
2551
Mi Jinlong58e7b332011-08-28 18:18:56 +08002552static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2553{
2554 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2555 * sizeof(__be32);
2556}
2557
2558static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2559{
2560 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
2561 * sizeof(__be32);
2562}
2563
2564static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2565{
2566 return (op_encode_hdr_size + op_encode_stateid_maxsz
2567 + op_encode_change_info_maxsz + 1
2568 + nfs4_fattr_bitmap_maxsz
2569 + op_encode_delegation_maxsz) * sizeof(__be32);
2570}
2571
2572static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2573{
2574 u32 maxcount = 0, rlen = 0;
2575
2576 maxcount = svc_max_payload(rqstp);
Kinglong Mee3c7aa152014-06-10 18:08:19 +08002577 rlen = min(op->u.read.rd_length, maxcount);
Mi Jinlong58e7b332011-08-28 18:18:56 +08002578
J. Bruce Fields622f5602014-05-16 14:38:20 -04002579 return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
Mi Jinlong58e7b332011-08-28 18:18:56 +08002580}
2581
Anna Schumaker528b8492020-09-28 13:08:58 -04002582static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2583{
2584 u32 maxcount = svc_max_payload(rqstp);
2585 u32 rlen = min(op->u.read.rd_length, maxcount);
2586 /*
2587 * If we detect that the file changed during hole encoding, then we
2588 * recover by encoding the remaining reply as data. This means we need
2589 * to set aside enough room to encode two data segments.
2590 */
2591 u32 seg_len = 2 * (1 + 2 + 1);
2592
2593 return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32);
2594}
2595
Mi Jinlong58e7b332011-08-28 18:18:56 +08002596static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2597{
Kinglong Mee3c7aa152014-06-10 18:08:19 +08002598 u32 maxcount = 0, rlen = 0;
Mi Jinlong58e7b332011-08-28 18:18:56 +08002599
Kinglong Mee3c7aa152014-06-10 18:08:19 +08002600 maxcount = svc_max_payload(rqstp);
2601 rlen = min(op->u.readdir.rd_maxcount, maxcount);
Mi Jinlong58e7b332011-08-28 18:18:56 +08002602
J. Bruce Fields561f0ed2014-01-20 16:37:11 -05002603 return (op_encode_hdr_size + op_encode_verifier_maxsz +
2604 XDR_QUADLEN(rlen)) * sizeof(__be32);
Mi Jinlong58e7b332011-08-28 18:18:56 +08002605}
2606
Kinglong Mee2282cd22017-02-03 22:36:00 +08002607static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2608{
2609 return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
2610}
2611
Mi Jinlong58e7b332011-08-28 18:18:56 +08002612static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2613{
2614 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2615 * sizeof(__be32);
2616}
2617
2618static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2619{
2620 return (op_encode_hdr_size + op_encode_change_info_maxsz
2621 + op_encode_change_info_maxsz) * sizeof(__be32);
2622}
2623
J. Bruce Fieldsccae70a2014-03-23 09:34:22 -07002624static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
2625 struct nfsd4_op *op)
2626{
J. Bruce Fieldsd1d84c92014-08-21 15:04:31 -04002627 return (op_encode_hdr_size
2628 + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
J. Bruce Fieldsccae70a2014-03-23 09:34:22 -07002629}
2630
Kinglong Mee2282cd22017-02-03 22:36:00 +08002631static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2632{
2633 return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
2634 * sizeof(__be32);
2635}
2636
Mi Jinlong58e7b332011-08-28 18:18:56 +08002637static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2638{
2639 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2640}
2641
Kinglong Mee2282cd22017-02-03 22:36:00 +08002642static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2643{
2644 return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
2645 (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
2646}
2647
Mi Jinlong58e7b332011-08-28 18:18:56 +08002648static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2649{
J. Bruce Fields480efae2014-03-10 14:17:55 -04002650 return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2651 sizeof(__be32);
Mi Jinlong58e7b332011-08-28 18:18:56 +08002652}
2653
2654static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2655{
J. Bruce Fieldsf34e4322014-05-16 21:24:56 -04002656 return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
Mi Jinlong58e7b332011-08-28 18:18:56 +08002657}
2658
2659static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2660{
2661 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
Kinglong Meea8bb84b2013-12-10 15:24:36 +08002662 1 + 1 + /* eir_flags, spr_how */\
2663 4 + /* spo_must_enforce & _allow with bitmap */\
Mi Jinlong58e7b332011-08-28 18:18:56 +08002664 2 + /*eir_server_owner.so_minor_id */\
2665 /* eir_server_owner.so_major_id<> */\
2666 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2667 /* eir_server_scope<> */\
2668 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2669 1 + /* eir_server_impl_id array length */\
2670 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
2671}
2672
2673static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2674{
2675 return (op_encode_hdr_size + \
2676 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
2677 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
2678}
2679
2680static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2681{
2682 return (op_encode_hdr_size + \
2683 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
2684 2 + /* csr_sequence, csr_flags */\
2685 op_encode_channel_attrs_maxsz + \
2686 op_encode_channel_attrs_maxsz) * sizeof(__be32);
2687}
2688
Anna Schumaker29ae7f92016-09-07 15:57:30 -04002689static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2690{
2691 return (op_encode_hdr_size +
2692 1 /* wr_callback */ +
2693 op_encode_stateid_maxsz /* wr_callback */ +
2694 2 /* wr_count */ +
2695 1 /* wr_committed */ +
2696 op_encode_verifier_maxsz +
2697 1 /* cr_consecutive */ +
2698 1 /* cr_synchronous */) * sizeof(__be32);
2699}
2700
Olga Kornievskaia6308bc92018-07-20 18:19:18 -04002701static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
2702 struct nfsd4_op *op)
2703{
2704 return (op_encode_hdr_size +
2705 2 /* osr_count */ +
2706 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
2707}
2708
Olga Kornievskaia51911862019-08-08 11:14:59 -04002709static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp,
2710 struct nfsd4_op *op)
2711{
2712 return (op_encode_hdr_size +
2713 3 /* cnr_lease_time */ +
2714 1 /* We support one cnr_source_server */ +
2715 1 /* cnr_stateid seq */ +
2716 op_encode_stateid_maxsz /* cnr_stateid */ +
2717 1 /* num cnr_source_server*/ +
2718 1 /* nl4_type */ +
2719 1 /* nl4 size */ +
2720 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */)
2721 * sizeof(__be32);
2722}
2723
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002724#ifdef CONFIG_NFSD_PNFS
Kinglong Mee2282cd22017-02-03 22:36:00 +08002725static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2726{
2727 u32 maxcount = 0, rlen = 0;
2728
2729 maxcount = svc_max_payload(rqstp);
2730 rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
2731
2732 return (op_encode_hdr_size +
2733 1 /* gd_layout_type*/ +
2734 XDR_QUADLEN(rlen) +
2735 2 /* gd_notify_types */) * sizeof(__be32);
2736}
2737
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02002738/*
2739 * At this stage we don't really know what layout driver will handle the request,
2740 * so we need to define an arbitrary upper bound here.
2741 */
2742#define MAX_LAYOUT_SIZE 128
2743static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2744{
2745 return (op_encode_hdr_size +
2746 1 /* logr_return_on_close */ +
2747 op_encode_stateid_maxsz +
2748 1 /* nr of layouts */ +
2749 MAX_LAYOUT_SIZE) * sizeof(__be32);
2750}
2751
2752static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2753{
2754 return (op_encode_hdr_size +
2755 1 /* locr_newsize */ +
2756 2 /* ns_size */) * sizeof(__be32);
2757}
2758
2759static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2760{
2761 return (op_encode_hdr_size +
2762 1 /* lrs_stateid */ +
2763 op_encode_stateid_maxsz) * sizeof(__be32);
2764}
2765#endif /* CONFIG_NFSD_PNFS */
2766
Kinglong Mee2282cd22017-02-03 22:36:00 +08002767
2768static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2769{
2770 return (op_encode_hdr_size + 3) * sizeof(__be32);
2771}
2772
Frank van der Linden23e50fe2020-06-23 22:39:26 +00002773static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp,
2774 struct nfsd4_op *op)
2775{
2776 u32 maxcount, rlen;
2777
2778 maxcount = svc_max_payload(rqstp);
2779 rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
2780
2781 return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2782}
2783
2784static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp,
2785 struct nfsd4_op *op)
2786{
2787 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2788 * sizeof(__be32);
2789}
2790static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp,
2791 struct nfsd4_op *op)
2792{
2793 u32 maxcount, rlen;
2794
2795 maxcount = svc_max_payload(rqstp);
2796 rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
2797
2798 return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2799}
2800
2801static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp,
2802 struct nfsd4_op *op)
2803{
2804 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2805 * sizeof(__be32);
2806}
2807
2808
Christoph Hellwigbb2a8b02017-05-08 23:46:47 +02002809static const struct nfsd4_operation nfsd4_ops[] = {
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002810 [OP_ACCESS] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002811 .op_func = nfsd4_access,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002812 .op_name = "OP_ACCESS",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002813 .op_rsize_bop = nfsd4_access_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002814 },
2815 [OP_CLOSE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002816 .op_func = nfsd4_close,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002817 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002818 .op_name = "OP_CLOSE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002819 .op_rsize_bop = nfsd4_status_stateid_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02002820 .op_get_currentstateid = nfsd4_get_closestateid,
Christoph Hellwigb60e9852017-05-08 20:03:15 +02002821 .op_set_currentstateid = nfsd4_set_closestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002822 },
2823 [OP_COMMIT] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002824 .op_func = nfsd4_commit,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002825 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002826 .op_name = "OP_COMMIT",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002827 .op_rsize_bop = nfsd4_commit_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002828 },
2829 [OP_CREATE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002830 .op_func = nfsd4_create,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01002831 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002832 .op_name = "OP_CREATE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002833 .op_rsize_bop = nfsd4_create_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002834 },
2835 [OP_DELEGRETURN] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002836 .op_func = nfsd4_delegreturn,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002837 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002838 .op_name = "OP_DELEGRETURN",
Mi Jinlong58e7b332011-08-28 18:18:56 +08002839 .op_rsize_bop = nfsd4_only_status_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02002840 .op_get_currentstateid = nfsd4_get_delegreturnstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002841 },
2842 [OP_GETATTR] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002843 .op_func = nfsd4_getattr,
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08002844 .op_flags = ALLOWED_ON_ABSENT_FS,
J. Bruce Fieldsb86cef62014-03-23 12:01:48 -04002845 .op_rsize_bop = nfsd4_getattr_rsize,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002846 .op_name = "OP_GETATTR",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002847 },
2848 [OP_GETFH] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002849 .op_func = nfsd4_getfh,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002850 .op_name = "OP_GETFH",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002851 .op_rsize_bop = nfsd4_getfh_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002852 },
2853 [OP_LINK] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002854 .op_func = nfsd4_link,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04002855 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
2856 | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002857 .op_name = "OP_LINK",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002858 .op_rsize_bop = nfsd4_link_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002859 },
2860 [OP_LOCK] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002861 .op_func = nfsd4_lock,
J. Bruce Fieldsb7571e42017-05-06 10:49:21 -04002862 .op_flags = OP_MODIFIES_SOMETHING |
2863 OP_NONTRIVIAL_ERROR_ENCODE,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002864 .op_name = "OP_LOCK",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002865 .op_rsize_bop = nfsd4_lock_rsize,
Christoph Hellwigb60e9852017-05-08 20:03:15 +02002866 .op_set_currentstateid = nfsd4_set_lockstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002867 },
2868 [OP_LOCKT] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002869 .op_func = nfsd4_lockt,
J. Bruce Fieldsb7571e42017-05-06 10:49:21 -04002870 .op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002871 .op_name = "OP_LOCKT",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002872 .op_rsize_bop = nfsd4_lock_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002873 },
2874 [OP_LOCKU] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002875 .op_func = nfsd4_locku,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002876 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002877 .op_name = "OP_LOCKU",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002878 .op_rsize_bop = nfsd4_status_stateid_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02002879 .op_get_currentstateid = nfsd4_get_lockustateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002880 },
2881 [OP_LOOKUP] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002882 .op_func = nfsd4_lookup,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01002883 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002884 .op_name = "OP_LOOKUP",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002885 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002886 },
2887 [OP_LOOKUPP] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002888 .op_func = nfsd4_lookupp,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01002889 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002890 .op_name = "OP_LOOKUPP",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002891 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002892 },
2893 [OP_NVERIFY] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002894 .op_func = nfsd4_nverify,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002895 .op_name = "OP_NVERIFY",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002896 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002897 },
2898 [OP_OPEN] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002899 .op_func = nfsd4_open,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002900 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002901 .op_name = "OP_OPEN",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002902 .op_rsize_bop = nfsd4_open_rsize,
Christoph Hellwigb60e9852017-05-08 20:03:15 +02002903 .op_set_currentstateid = nfsd4_set_openstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002904 },
2905 [OP_OPEN_CONFIRM] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002906 .op_func = nfsd4_open_confirm,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002907 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002908 .op_name = "OP_OPEN_CONFIRM",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002909 .op_rsize_bop = nfsd4_status_stateid_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002910 },
2911 [OP_OPEN_DOWNGRADE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002912 .op_func = nfsd4_open_downgrade,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002913 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002914 .op_name = "OP_OPEN_DOWNGRADE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002915 .op_rsize_bop = nfsd4_status_stateid_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02002916 .op_get_currentstateid = nfsd4_get_opendowngradestateid,
Christoph Hellwigb60e9852017-05-08 20:03:15 +02002917 .op_set_currentstateid = nfsd4_set_opendowngradestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002918 },
2919 [OP_PUTFH] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002920 .op_func = nfsd4_putfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04002921 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fields5b648692014-03-07 11:43:58 -05002922 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002923 .op_name = "OP_PUTFH",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002924 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002925 },
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08002926 [OP_PUTPUBFH] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002927 .op_func = nfsd4_putrootfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04002928 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fields5b648692014-03-07 11:43:58 -05002929 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002930 .op_name = "OP_PUTPUBFH",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002931 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08002932 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002933 [OP_PUTROOTFH] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002934 .op_func = nfsd4_putrootfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04002935 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fields5b648692014-03-07 11:43:58 -05002936 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002937 .op_name = "OP_PUTROOTFH",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002938 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002939 },
2940 [OP_READ] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002941 .op_func = nfsd4_read,
J. Bruce Fields34b1744c2017-05-05 17:09:37 -04002942 .op_release = nfsd4_read_release,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002943 .op_name = "OP_READ",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002944 .op_rsize_bop = nfsd4_read_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02002945 .op_get_currentstateid = nfsd4_get_readstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002946 },
2947 [OP_READDIR] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002948 .op_func = nfsd4_readdir,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002949 .op_name = "OP_READDIR",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002950 .op_rsize_bop = nfsd4_readdir_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002951 },
2952 [OP_READLINK] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002953 .op_func = nfsd4_readlink,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002954 .op_name = "OP_READLINK",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002955 .op_rsize_bop = nfsd4_readlink_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002956 },
2957 [OP_REMOVE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002958 .op_func = nfsd4_remove,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04002959 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002960 .op_name = "OP_REMOVE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002961 .op_rsize_bop = nfsd4_remove_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002962 },
2963 [OP_RENAME] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002964 .op_func = nfsd4_rename,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04002965 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002966 .op_name = "OP_RENAME",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002967 .op_rsize_bop = nfsd4_rename_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002968 },
2969 [OP_RENEW] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002970 .op_func = nfsd4_renew,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002971 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
2972 | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002973 .op_name = "OP_RENEW",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002974 .op_rsize_bop = nfsd4_only_status_rsize,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002975
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002976 },
2977 [OP_RESTOREFH] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002978 .op_func = nfsd4_restorefh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04002979 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Mi Jinlong58e7b332011-08-28 18:18:56 +08002980 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002981 .op_name = "OP_RESTOREFH",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002982 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002983 },
2984 [OP_SAVEFH] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002985 .op_func = nfsd4_savefh,
Mi Jinlong58e7b332011-08-28 18:18:56 +08002986 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002987 .op_name = "OP_SAVEFH",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002988 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002989 },
Andy Adamsondcb488a32007-07-17 04:04:51 -07002990 [OP_SECINFO] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002991 .op_func = nfsd4_secinfo,
J. Bruce Fields34b1744c2017-05-05 17:09:37 -04002992 .op_release = nfsd4_secinfo_release,
J. Bruce Fields68d93182011-04-08 17:00:50 -04002993 .op_flags = OP_HANDLES_WRONGSEC,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002994 .op_name = "OP_SECINFO",
Christoph Hellwig1c122632017-05-08 20:42:10 +02002995 .op_rsize_bop = nfsd4_secinfo_rsize,
Andy Adamsondcb488a32007-07-17 04:04:51 -07002996 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08002997 [OP_SETATTR] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02002998 .op_func = nfsd4_setattr,
Benny Halevyb001a1b2008-07-02 11:15:03 +03002999 .op_name = "OP_SETATTR",
J. Bruce Fieldsb7571e42017-05-06 10:49:21 -04003000 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
3001 | OP_NONTRIVIAL_ERROR_ENCODE,
Christoph Hellwig1c122632017-05-08 20:42:10 +02003002 .op_rsize_bop = nfsd4_setattr_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02003003 .op_get_currentstateid = nfsd4_get_setattrstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003004 },
3005 [OP_SETCLIENTID] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003006 .op_func = nfsd4_setclientid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003007 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fieldsb7571e42017-05-06 10:49:21 -04003008 | OP_MODIFIES_SOMETHING | OP_CACHEME
3009 | OP_NONTRIVIAL_ERROR_ENCODE,
Benny Halevyb001a1b2008-07-02 11:15:03 +03003010 .op_name = "OP_SETCLIENTID",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003011 .op_rsize_bop = nfsd4_setclientid_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003012 },
3013 [OP_SETCLIENTID_CONFIRM] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003014 .op_func = nfsd4_setclientid_confirm,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003015 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04003016 | OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03003017 .op_name = "OP_SETCLIENTID_CONFIRM",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003018 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003019 },
3020 [OP_VERIFY] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003021 .op_func = nfsd4_verify,
Benny Halevyb001a1b2008-07-02 11:15:03 +03003022 .op_name = "OP_VERIFY",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003023 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003024 },
3025 [OP_WRITE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003026 .op_func = nfsd4_write,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04003027 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03003028 .op_name = "OP_WRITE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003029 .op_rsize_bop = nfsd4_write_rsize,
Christoph Hellwig57832e72017-05-08 20:37:33 +02003030 .op_get_currentstateid = nfsd4_get_writestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003031 },
3032 [OP_RELEASE_LOCKOWNER] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003033 .op_func = nfsd4_release_lockowner,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003034 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3035 | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03003036 .op_name = "OP_RELEASE_LOCKOWNER",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003037 .op_rsize_bop = nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003038 },
Andy Adamson069b6ad2009-04-03 08:27:58 +03003039
3040 /* NFSv4.1 operations */
3041 [OP_EXCHANGE_ID] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003042 .op_func = nfsd4_exchange_id,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003043 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3044 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003045 .op_name = "OP_EXCHANGE_ID",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003046 .op_rsize_bop = nfsd4_exchange_id_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003047 },
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -04003048 [OP_BACKCHANNEL_CTL] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003049 .op_func = nfsd4_backchannel_ctl,
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -04003050 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3051 .op_name = "OP_BACKCHANNEL_CTL",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003052 .op_rsize_bop = nfsd4_only_status_rsize,
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -04003053 },
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04003054 [OP_BIND_CONN_TO_SESSION] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003055 .op_func = nfsd4_bind_conn_to_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003056 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3057 | OP_MODIFIES_SOMETHING,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04003058 .op_name = "OP_BIND_CONN_TO_SESSION",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003059 .op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04003060 },
Andy Adamson069b6ad2009-04-03 08:27:58 +03003061 [OP_CREATE_SESSION] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003062 .op_func = nfsd4_create_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003063 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3064 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003065 .op_name = "OP_CREATE_SESSION",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003066 .op_rsize_bop = nfsd4_create_session_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003067 },
3068 [OP_DESTROY_SESSION] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003069 .op_func = nfsd4_destroy_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003070 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3071 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003072 .op_name = "OP_DESTROY_SESSION",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003073 .op_rsize_bop = nfsd4_only_status_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003074 },
3075 [OP_SEQUENCE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003076 .op_func = nfsd4_sequence,
Andy Adamsonf9bb94c42009-04-03 08:28:12 +03003077 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003078 .op_name = "OP_SEQUENCE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003079 .op_rsize_bop = nfsd4_sequence_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03003080 },
Benny Halevy094b5d72011-06-16 11:39:10 -04003081 [OP_DESTROY_CLIENTID] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003082 .op_func = nfsd4_destroy_clientid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003083 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3084 | OP_MODIFIES_SOMETHING,
Benny Halevy094b5d72011-06-16 11:39:10 -04003085 .op_name = "OP_DESTROY_CLIENTID",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003086 .op_rsize_bop = nfsd4_only_status_rsize,
Benny Halevy094b5d72011-06-16 11:39:10 -04003087 },
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04003088 [OP_RECLAIM_COMPLETE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003089 .op_func = nfsd4_reclaim_complete,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003090 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04003091 .op_name = "OP_RECLAIM_COMPLETE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003092 .op_rsize_bop = nfsd4_only_status_rsize,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04003093 },
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05003094 [OP_SECINFO_NO_NAME] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003095 .op_func = nfsd4_secinfo_no_name,
Eryu Guanec572b92017-09-29 15:01:10 +08003096 .op_release = nfsd4_secinfo_no_name_release,
J. Bruce Fields68d93182011-04-08 17:00:50 -04003097 .op_flags = OP_HANDLES_WRONGSEC,
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05003098 .op_name = "OP_SECINFO_NO_NAME",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003099 .op_rsize_bop = nfsd4_secinfo_rsize,
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05003100 },
Bryan Schumaker17456802011-07-13 10:50:48 -04003101 [OP_TEST_STATEID] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003102 .op_func = nfsd4_test_stateid,
Bryan Schumaker17456802011-07-13 10:50:48 -04003103 .op_flags = ALLOWED_WITHOUT_FH,
3104 .op_name = "OP_TEST_STATEID",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003105 .op_rsize_bop = nfsd4_test_stateid_rsize,
Bryan Schumaker17456802011-07-13 10:50:48 -04003106 },
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003107 [OP_FREE_STATEID] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003108 .op_func = nfsd4_free_stateid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08003109 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003110 .op_name = "OP_FREE_STATEID",
Christoph Hellwig57832e72017-05-08 20:37:33 +02003111 .op_get_currentstateid = nfsd4_get_freestateid,
Christoph Hellwig1c122632017-05-08 20:42:10 +02003112 .op_rsize_bop = nfsd4_only_status_rsize,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003113 },
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003114#ifdef CONFIG_NFSD_PNFS
3115 [OP_GETDEVICEINFO] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003116 .op_func = nfsd4_getdeviceinfo,
J. Bruce Fields34b1744c2017-05-05 17:09:37 -04003117 .op_release = nfsd4_getdeviceinfo_release,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003118 .op_flags = ALLOWED_WITHOUT_FH,
3119 .op_name = "OP_GETDEVICEINFO",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003120 .op_rsize_bop = nfsd4_getdeviceinfo_rsize,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003121 },
3122 [OP_LAYOUTGET] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003123 .op_func = nfsd4_layoutget,
J. Bruce Fields34b1744c2017-05-05 17:09:37 -04003124 .op_release = nfsd4_layoutget_release,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003125 .op_flags = OP_MODIFIES_SOMETHING,
3126 .op_name = "OP_LAYOUTGET",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003127 .op_rsize_bop = nfsd4_layoutget_rsize,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003128 },
3129 [OP_LAYOUTCOMMIT] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003130 .op_func = nfsd4_layoutcommit,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003131 .op_flags = OP_MODIFIES_SOMETHING,
3132 .op_name = "OP_LAYOUTCOMMIT",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003133 .op_rsize_bop = nfsd4_layoutcommit_rsize,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003134 },
3135 [OP_LAYOUTRETURN] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003136 .op_func = nfsd4_layoutreturn,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003137 .op_flags = OP_MODIFIES_SOMETHING,
3138 .op_name = "OP_LAYOUTRETURN",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003139 .op_rsize_bop = nfsd4_layoutreturn_rsize,
Christoph Hellwig9cf514c2014-05-05 13:11:59 +02003140 },
3141#endif /* CONFIG_NFSD_PNFS */
Anna Schumaker24bab492014-09-26 13:58:27 -04003142
3143 /* NFSv4.2 operations */
Anna Schumaker95d871f2014-11-07 14:44:26 -05003144 [OP_ALLOCATE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003145 .op_func = nfsd4_allocate,
Olga Kornievskaia03b31f42018-12-04 14:09:21 -05003146 .op_flags = OP_MODIFIES_SOMETHING,
Anna Schumaker95d871f2014-11-07 14:44:26 -05003147 .op_name = "OP_ALLOCATE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003148 .op_rsize_bop = nfsd4_only_status_rsize,
Anna Schumaker95d871f2014-11-07 14:44:26 -05003149 },
Anna Schumakerb0cb9082014-11-07 14:44:27 -05003150 [OP_DEALLOCATE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003151 .op_func = nfsd4_deallocate,
Olga Kornievskaia03b31f42018-12-04 14:09:21 -05003152 .op_flags = OP_MODIFIES_SOMETHING,
Anna Schumakerb0cb9082014-11-07 14:44:27 -05003153 .op_name = "OP_DEALLOCATE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003154 .op_rsize_bop = nfsd4_only_status_rsize,
Anna Schumakerb0cb9082014-11-07 14:44:27 -05003155 },
Christoph Hellwigffa01602015-12-03 12:59:52 +01003156 [OP_CLONE] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003157 .op_func = nfsd4_clone,
Olga Kornievskaia03b31f42018-12-04 14:09:21 -05003158 .op_flags = OP_MODIFIES_SOMETHING,
Christoph Hellwigffa01602015-12-03 12:59:52 +01003159 .op_name = "OP_CLONE",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003160 .op_rsize_bop = nfsd4_only_status_rsize,
Christoph Hellwigffa01602015-12-03 12:59:52 +01003161 },
Anna Schumaker29ae7f92016-09-07 15:57:30 -04003162 [OP_COPY] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003163 .op_func = nfsd4_copy,
Olga Kornievskaia03b31f42018-12-04 14:09:21 -05003164 .op_flags = OP_MODIFIES_SOMETHING,
Anna Schumaker29ae7f92016-09-07 15:57:30 -04003165 .op_name = "OP_COPY",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003166 .op_rsize_bop = nfsd4_copy_rsize,
Anna Schumaker29ae7f92016-09-07 15:57:30 -04003167 },
Anna Schumaker528b8492020-09-28 13:08:58 -04003168 [OP_READ_PLUS] = {
3169 .op_func = nfsd4_read,
3170 .op_release = nfsd4_read_release,
3171 .op_name = "OP_READ_PLUS",
3172 .op_rsize_bop = nfsd4_read_plus_rsize,
3173 .op_get_currentstateid = nfsd4_get_readstateid,
3174 },
Anna Schumaker24bab492014-09-26 13:58:27 -04003175 [OP_SEEK] = {
Christoph Hellwigeb698532017-05-08 20:58:35 +02003176 .op_func = nfsd4_seek,
Anna Schumaker24bab492014-09-26 13:58:27 -04003177 .op_name = "OP_SEEK",
Christoph Hellwig1c122632017-05-08 20:42:10 +02003178 .op_rsize_bop = nfsd4_seek_rsize,
Anna Schumaker24bab492014-09-26 13:58:27 -04003179 },
Olga Kornievskaia6308bc92018-07-20 18:19:18 -04003180 [OP_OFFLOAD_STATUS] = {
3181 .op_func = nfsd4_offload_status,
3182 .op_name = "OP_OFFLOAD_STATUS",
3183 .op_rsize_bop = nfsd4_offload_status_rsize,
3184 },
Olga Kornievskaia885e2bf2018-07-20 18:19:19 -04003185 [OP_OFFLOAD_CANCEL] = {
3186 .op_func = nfsd4_offload_cancel,
3187 .op_flags = OP_MODIFIES_SOMETHING,
3188 .op_name = "OP_OFFLOAD_CANCEL",
3189 .op_rsize_bop = nfsd4_only_status_rsize,
3190 },
Olga Kornievskaia51911862019-08-08 11:14:59 -04003191 [OP_COPY_NOTIFY] = {
3192 .op_func = nfsd4_copy_notify,
3193 .op_flags = OP_MODIFIES_SOMETHING,
3194 .op_name = "OP_COPY_NOTIFY",
3195 .op_rsize_bop = nfsd4_copy_notify_rsize,
3196 },
Frank van der Linden23e50fe2020-06-23 22:39:26 +00003197 [OP_GETXATTR] = {
3198 .op_func = nfsd4_getxattr,
3199 .op_name = "OP_GETXATTR",
3200 .op_rsize_bop = nfsd4_getxattr_rsize,
3201 },
3202 [OP_SETXATTR] = {
3203 .op_func = nfsd4_setxattr,
3204 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3205 .op_name = "OP_SETXATTR",
3206 .op_rsize_bop = nfsd4_setxattr_rsize,
3207 },
3208 [OP_LISTXATTRS] = {
3209 .op_func = nfsd4_listxattrs,
3210 .op_name = "OP_LISTXATTRS",
3211 .op_rsize_bop = nfsd4_listxattrs_rsize,
3212 },
3213 [OP_REMOVEXATTR] = {
3214 .op_func = nfsd4_removexattr,
3215 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3216 .op_name = "OP_REMOVEXATTR",
3217 .op_rsize_bop = nfsd4_removexattr_rsize,
3218 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08003219};
3220
Andrew Elbleed941642016-06-15 12:52:09 -04003221/**
3222 * nfsd4_spo_must_allow - Determine if the compound op contains an
3223 * operation that is allowed to be sent with machine credentials
3224 *
3225 * @rqstp: a pointer to the struct svc_rqst
3226 *
3227 * Checks to see if the compound contains a spo_must_allow op
3228 * and confirms that it was sent with the proper machine creds.
3229 */
3230
3231bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
3232{
3233 struct nfsd4_compoundres *resp = rqstp->rq_resp;
3234 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
3235 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
3236 struct nfsd4_compound_state *cstate = &resp->cstate;
3237 struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
3238 u32 opiter;
3239
3240 if (!cstate->minorversion)
3241 return false;
3242
Zheng Bin44b49aa2020-09-11 12:10:14 +08003243 if (cstate->spo_must_allowed)
Andrew Elbleed941642016-06-15 12:52:09 -04003244 return true;
3245
3246 opiter = resp->opcnt;
3247 while (opiter < argp->opcnt) {
3248 this = &argp->ops[opiter++];
3249 if (test_bit(this->opnum, allow->u.longs) &&
3250 cstate->clp->cl_mach_cred &&
3251 nfsd4_mach_creds_match(cstate->clp, rqstp)) {
3252 cstate->spo_must_allowed = true;
3253 return true;
3254 }
3255 }
3256 cstate->spo_must_allowed = false;
3257 return false;
3258}
3259
J. Bruce Fields4f0cefb2014-03-11 15:39:13 -04003260int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
3261{
Olga Kornievskaia05b72782017-03-23 14:36:20 -04003262 if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
J. Bruce Fields4f0cefb2014-03-11 15:39:13 -04003263 return op_encode_hdr_size * sizeof(__be32);
Kinglong Mee2282cd22017-02-03 22:36:00 +08003264
3265 BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
3266 return OPDESC(op)->op_rsize_bop(rqstp, op);
J. Bruce Fields4f0cefb2014-03-11 15:39:13 -04003267}
3268
J. Bruce Fields07d1f802014-03-06 20:39:29 -05003269void warn_on_nonidempotent_op(struct nfsd4_op *op)
3270{
3271 if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
Chuck Lever3a237b42020-11-22 12:49:52 -05003272 pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
J. Bruce Fields07d1f802014-03-06 20:39:29 -05003273 op->opnum, nfsd4_op_name(op->opnum));
3274 WARN_ON_ONCE(1);
3275 }
3276}
3277
Adrian Bunkf1c7f792008-08-08 19:26:42 +03003278static const char *nfsd4_op_name(unsigned opnum)
Benny Halevyb001a1b2008-07-02 11:15:03 +03003279{
3280 if (opnum < ARRAY_SIZE(nfsd4_ops))
3281 return nfsd4_ops[opnum].op_name;
3282 return "unknown_operation";
3283}
3284
Christoph Hellwig860bda22017-05-12 16:11:49 +02003285static const struct svc_procedure nfsd_procedures4[2] = {
Yu Zhiguo0a93a472009-05-19 14:09:54 +08003286 [NFSPROC4_NULL] = {
Christoph Hellwigf7235b62017-05-08 17:59:13 +02003287 .pc_func = nfsd4_proc_null,
Chuck Lever788f7182020-11-05 14:48:29 -05003288 .pc_decode = nfssvc_decode_voidarg,
3289 .pc_encode = nfssvc_encode_voidres,
3290 .pc_argsize = sizeof(struct nfsd_voidargs),
3291 .pc_ressize = sizeof(struct nfsd_voidres),
Yu Zhiguo0a93a472009-05-19 14:09:54 +08003292 .pc_cachetype = RC_NOCACHE,
3293 .pc_xdrressize = 1,
Chuck Lever2289e872020-09-17 17:22:49 -04003294 .pc_name = "NULL",
Yu Zhiguo0a93a472009-05-19 14:09:54 +08003295 },
3296 [NFSPROC4_COMPOUND] = {
Christoph Hellwigf7235b62017-05-08 17:59:13 +02003297 .pc_func = nfsd4_proc_compound,
Christoph Hellwig026fec72017-05-08 19:01:48 +02003298 .pc_decode = nfs4svc_decode_compoundargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +02003299 .pc_encode = nfs4svc_encode_compoundres,
Yu Zhiguo0a93a472009-05-19 14:09:54 +08003300 .pc_argsize = sizeof(struct nfsd4_compoundargs),
3301 .pc_ressize = sizeof(struct nfsd4_compoundres),
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003302 .pc_release = nfsd4_release_compoundargs,
Yu Zhiguo0a93a472009-05-19 14:09:54 +08003303 .pc_cachetype = RC_NOCACHE,
3304 .pc_xdrressize = NFSD_BUFSIZE/4,
Chuck Lever2289e872020-09-17 17:22:49 -04003305 .pc_name = "COMPOUND",
Yu Zhiguo0a93a472009-05-19 14:09:54 +08003306 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307};
3308
Christoph Hellwig7fd38af2017-05-08 23:40:27 +02003309static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
Christoph Hellwige9679182017-05-12 16:21:37 +02003310const struct svc_version nfsd_version4 = {
Jeff Layton5283b032017-02-24 13:25:24 -05003311 .vs_vers = 4,
3312 .vs_nproc = 2,
3313 .vs_proc = nfsd_procedures4,
Christoph Hellwig7fd38af2017-05-08 23:40:27 +02003314 .vs_count = nfsd_count3,
Jeff Layton5283b032017-02-24 13:25:24 -05003315 .vs_dispatch = nfsd_dispatch,
3316 .vs_xdrsize = NFS4_SVC_XDRSIZE,
3317 .vs_rpcb_optnl = true,
3318 .vs_need_cong_ctrl = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319};
3320
3321/*
3322 * Local variables:
3323 * c-basic-offset: 8
3324 * End:
3325 */