]> git.ipfire.org Git - people/ms/linux.git/blame - fs/nfsd/nfs4proc.c
NFSD: nfserrno(-ENOMEM) is nfserr_jukebox
[people/ms/linux.git] / fs / nfsd / nfs4proc.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * 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.
1da177e4 34 */
880a3a53 35#include <linux/fs_struct.h>
7e06b7f9 36#include <linux/file.h>
b0cb9085 37#include <linux/falloc.h>
5a0e3ad6 38#include <linux/slab.h>
e0639dc5 39#include <linux/kthread.h>
254454a5
CL
40#include <linux/namei.h>
41
624322f1 42#include <linux/sunrpc/addr.h>
0cfcd405 43#include <linux/nfs_ssc.h>
1da177e4 44
58e7b33a 45#include "idmap.h"
9a74af21
BH
46#include "cache.h"
47#include "xdr4.h"
0a3adade 48#include "vfs.h"
8b70484c 49#include "current_stateid.h"
3320fef1 50#include "netns.h"
4ac7249e 51#include "acl.h"
9cf514cc 52#include "pnfs.h"
31ef83dc 53#include "trace.h"
1da177e4 54
d6c9e436
CL
55static bool inter_copy_offload_enable;
56module_param(inter_copy_offload_enable, bool, 0644);
57MODULE_PARM_DESC(inter_copy_offload_enable,
58 "Enable inter server to server copy offload. Default: false");
59
f4e44b39
DN
60#ifdef CONFIG_NFSD_V4_2_INTER_SSC
61static int nfsd4_ssc_umount_timeout = 900000; /* default to 15 mins */
62module_param(nfsd4_ssc_umount_timeout, int, 0644);
63MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
64 "idle msecs before unmount export from source server");
65#endif
66
18032ca0
DQ
67#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
68#include <linux/security.h>
69
70static inline void
71nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
72{
2b0143b5 73 struct inode *inode = d_inode(resfh->fh_dentry);
18032ca0
DQ
74 int status;
75
5955102c 76 inode_lock(inode);
18032ca0
DQ
77 status = security_inode_setsecctx(resfh->fh_dentry,
78 label->data, label->len);
5955102c 79 inode_unlock(inode);
18032ca0
DQ
80
81 if (status)
82 /*
83 * XXX: We should really fail the whole open, but we may
84 * already have created a new file, so it may be too
85 * late. For now this seems the least of evils:
86 */
87 bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
88
89 return;
90}
91#else
92static inline void
93nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
94{ }
95#endif
96
1da177e4
LT
97#define NFSDDBG_FACILITY NFSDDBG_PROC
98
3c8e0316
YZ
99static u32 nfsd_attrmask[] = {
100 NFSD_WRITEABLE_ATTRS_WORD0,
101 NFSD_WRITEABLE_ATTRS_WORD1,
102 NFSD_WRITEABLE_ATTRS_WORD2
103};
104
105static u32 nfsd41_ex_attrmask[] = {
106 NFSD_SUPPATTR_EXCLCREAT_WORD0,
107 NFSD_SUPPATTR_EXCLCREAT_WORD1,
108 NFSD_SUPPATTR_EXCLCREAT_WORD2
109};
110
111static __be32
112check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
113 u32 *bmval, u32 *writable)
114{
115 struct dentry *dentry = cstate->current_fh.fh_dentry;
32ddd944 116 struct svc_export *exp = cstate->current_fh.fh_export;
3c8e0316 117
916d2d84 118 if (!nfsd_attrs_supported(cstate->minorversion, bmval))
3c8e0316 119 return nfserr_attrnotsupp;
916d2d84
BF
120 if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
121 return nfserr_attrnotsupp;
32ddd944
BF
122 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
123 !(exp->ex_flags & NFSEXP_SECURITY_LABEL))
124 return nfserr_attrnotsupp;
916d2d84
BF
125 if (writable && !bmval_is_subset(bmval, writable))
126 return nfserr_inval;
47057abd
AG
127 if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
128 (bmval[1] & FATTR4_WORD1_MODE))
129 return nfserr_inval;
3c8e0316
YZ
130 return nfs_ok;
131}
132
133static __be32
134nfsd4_check_open_attributes(struct svc_rqst *rqstp,
135 struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
136{
137 __be32 status = nfs_ok;
138
139 if (open->op_create == NFS4_OPEN_CREATE) {
140 if (open->op_createmode == NFS4_CREATE_UNCHECKED
141 || open->op_createmode == NFS4_CREATE_GUARDED)
142 status = check_attr_support(rqstp, cstate,
143 open->op_bmval, nfsd_attrmask);
144 else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
145 status = check_attr_support(rqstp, cstate,
146 open->op_bmval, nfsd41_ex_attrmask);
147 }
148
149 return status;
150}
151
9208faf2
YZ
152static int
153is_create_with_attrs(struct nfsd4_open *open)
154{
155 return open->op_create == NFS4_OPEN_CREATE
156 && (open->op_createmode == NFS4_CREATE_UNCHECKED
157 || open->op_createmode == NFS4_CREATE_GUARDED
158 || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
159}
160
161/*
162 * if error occurs when setting the acl, just clear the acl bit
163 * in the returned attr bitmap.
164 */
165static void
166do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
167 struct nfs4_acl *acl, u32 *bmval)
168{
169 __be32 status;
170
171 status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
172 if (status)
173 /*
174 * We should probably fail the whole open at this point,
175 * but we've already created the file, so it's too late;
176 * So this seems the least of evils:
177 */
178 bmval[0] &= ~FATTR4_WORD0_ACL;
179}
180
1da177e4
LT
181static inline void
182fh_dup2(struct svc_fh *dst, struct svc_fh *src)
183{
184 fh_put(dst);
185 dget(src->fh_dentry);
186 if (src->fh_export)
bf18f163 187 exp_get(src->fh_export);
1da177e4
LT
188 *dst = *src;
189}
190
b37ad28b 191static __be32
dc730e17 192do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
1da177e4 193{
b37ad28b 194 __be32 status;
1da177e4
LT
195
196 if (open->op_truncate &&
197 !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
198 return nfserr_inval;
199
a043226b
BF
200 accmode |= NFSD_MAY_READ_IF_EXEC;
201
1da177e4 202 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
8837abca 203 accmode |= NFSD_MAY_READ;
9801d8a3 204 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
8837abca 205 accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
57ecb34f 206 if (open->op_share_deny & NFS4_SHARE_DENY_READ)
8837abca 207 accmode |= NFSD_MAY_WRITE;
1da177e4
LT
208
209 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
210
211 return status;
212}
213
aadab6c6
BF
214static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
215{
2b0143b5 216 umode_t mode = d_inode(fh->fh_dentry)->i_mode;
aadab6c6
BF
217
218 if (S_ISREG(mode))
219 return nfs_ok;
220 if (S_ISDIR(mode))
221 return nfserr_isdir;
222 /*
223 * Using err_symlink as our catch-all case may look odd; but
224 * there's no other obvious error for this case in 4.0, and we
225 * happen to know that it will cause the linux v4 client to do
226 * the right thing on attempts to open something other than a
227 * regular file.
228 */
229 return nfserr_symlink;
230}
231
bbc9c36c
BF
232static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
233{
234 if (nfsd4_has_session(cstate))
235 return;
236 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
237 &resfh->fh_handle);
238}
239
254454a5
CL
240static inline bool nfsd4_create_is_exclusive(int createmode)
241{
242 return createmode == NFS4_CREATE_EXCLUSIVE ||
243 createmode == NFS4_CREATE_EXCLUSIVE4_1;
244}
245
fb70bf12
CL
246static __be32
247nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
248 struct nfsd4_open *open)
249{
250 struct file *filp;
251 struct path path;
252 int oflags;
253
254 oflags = O_CREAT | O_LARGEFILE;
255 switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) {
256 case NFS4_SHARE_ACCESS_WRITE:
257 oflags |= O_WRONLY;
258 break;
259 case NFS4_SHARE_ACCESS_BOTH:
260 oflags |= O_RDWR;
261 break;
262 default:
263 oflags |= O_RDONLY;
264 }
265
266 path.mnt = fhp->fh_export->ex_path.mnt;
267 path.dentry = child;
268 filp = dentry_create(&path, oflags, open->op_iattr.ia_mode,
269 current_cred());
270 if (IS_ERR(filp))
271 return nfserrno(PTR_ERR(filp));
272
273 open->op_filp = filp;
274 return nfs_ok;
275}
276
254454a5
CL
277/*
278 * Implement NFSv4's unchecked, guarded, and exclusive create
279 * semantics for regular files. Open state for this new file is
280 * subsequently fabricated in nfsd4_process_open2().
281 *
282 * Upon return, caller must release @fhp and @resfhp.
283 */
284static __be32
285nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
286 struct svc_fh *resfhp, struct nfsd4_open *open)
287{
288 struct iattr *iap = &open->op_iattr;
289 struct dentry *parent, *child;
290 __u32 v_mtime, v_atime;
291 struct inode *inode;
292 __be32 status;
293 int host_err;
294
295 if (isdotent(open->op_fname, open->op_fnamelen))
296 return nfserr_exist;
297 if (!(iap->ia_valid & ATTR_MODE))
298 iap->ia_mode = 0;
299
300 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
301 if (status != nfs_ok)
302 return status;
303 parent = fhp->fh_dentry;
304 inode = d_inode(parent);
305
306 host_err = fh_want_write(fhp);
307 if (host_err)
308 return nfserrno(host_err);
309
310 fh_lock_nested(fhp, I_MUTEX_PARENT);
311
312 child = lookup_one_len(open->op_fname, parent, open->op_fnamelen);
313 if (IS_ERR(child)) {
314 status = nfserrno(PTR_ERR(child));
315 goto out;
316 }
317
318 if (d_really_is_negative(child)) {
319 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
320 if (status != nfs_ok)
321 goto out;
322 }
323
324 status = fh_compose(resfhp, fhp->fh_export, child, fhp);
325 if (status != nfs_ok)
326 goto out;
327
328 v_mtime = 0;
329 v_atime = 0;
330 if (nfsd4_create_is_exclusive(open->op_createmode)) {
331 u32 *verifier = (u32 *)open->op_verf.data;
332
333 /*
334 * Solaris 7 gets confused (bugid 4218508) if these have
335 * the high bit set, as do xfs filesystems without the
336 * "bigtime" feature. So just clear the high bits. If this
337 * is ever changed to use different attrs for storing the
338 * verifier, then do_open_lookup() will also need to be
339 * fixed accordingly.
340 */
341 v_mtime = verifier[0] & 0x7fffffff;
342 v_atime = verifier[1] & 0x7fffffff;
343 }
344
345 if (d_really_is_positive(child)) {
346 status = nfs_ok;
347
348 switch (open->op_createmode) {
349 case NFS4_CREATE_UNCHECKED:
350 if (!d_is_reg(child))
351 break;
352
353 /*
354 * In NFSv4, we don't want to truncate the file
355 * now. This would be wrong if the OPEN fails for
356 * some other reason. Furthermore, if the size is
357 * nonzero, we should ignore it according to spec!
358 */
359 open->op_truncate = (iap->ia_valid & ATTR_SIZE) &&
360 !iap->ia_size;
361 break;
362 case NFS4_CREATE_GUARDED:
363 status = nfserr_exist;
364 break;
365 case NFS4_CREATE_EXCLUSIVE:
366 if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
367 d_inode(child)->i_atime.tv_sec == v_atime &&
368 d_inode(child)->i_size == 0) {
369 open->op_created = true;
370 break; /* subtle */
371 }
372 status = nfserr_exist;
373 break;
374 case NFS4_CREATE_EXCLUSIVE4_1:
375 if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
376 d_inode(child)->i_atime.tv_sec == v_atime &&
377 d_inode(child)->i_size == 0) {
378 open->op_created = true;
379 goto set_attr; /* subtle */
380 }
381 status = nfserr_exist;
382 }
383 goto out;
384 }
385
386 if (!IS_POSIXACL(inode))
387 iap->ia_mode &= ~current_umask();
388
fb70bf12
CL
389 status = nfsd4_vfs_create(fhp, child, open);
390 if (status != nfs_ok)
254454a5 391 goto out;
254454a5
CL
392 open->op_created = true;
393
394 /* A newly created file already has a file size of zero. */
395 if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0))
396 iap->ia_valid &= ~ATTR_SIZE;
397 if (nfsd4_create_is_exclusive(open->op_createmode)) {
398 iap->ia_valid = ATTR_MTIME | ATTR_ATIME |
399 ATTR_MTIME_SET|ATTR_ATIME_SET;
400 iap->ia_mtime.tv_sec = v_mtime;
401 iap->ia_atime.tv_sec = v_atime;
402 iap->ia_mtime.tv_nsec = 0;
403 iap->ia_atime.tv_nsec = 0;
404 }
405
406set_attr:
407 status = nfsd_create_setattr(rqstp, fhp, resfhp, iap);
408
409out:
410 fh_unlock(fhp);
411 if (child && !IS_ERR(child))
412 dput(child);
413 fh_drop_write(fhp);
414 return status;
415}
416
b37ad28b 417static __be32
c0e6bee4 418do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
1da177e4 419{
bbc9c36c 420 struct svc_fh *current_fh = &cstate->current_fh;
7007c90f 421 int accmode;
b37ad28b 422 __be32 status;
1da177e4 423
c0e6bee4
BF
424 *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
425 if (!*resfh)
59deeb9e 426 return nfserr_jukebox;
c0e6bee4 427 fh_init(*resfh, NFS4_FHSIZE);
500c2481 428 open->op_truncate = false;
1da177e4
LT
429
430 if (open->op_create) {
79fb54ab
BH
431 /* FIXME: check session persistence and pnfs flags.
432 * The nfsv4.1 spec requires the following semantics:
433 *
434 * Persistent | pNFS | Server REQUIRED | Client Allowed
435 * Reply Cache | server | |
436 * -------------+--------+-----------------+--------------------
437 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
438 * | | | (SHOULD)
439 * | | and EXCLUSIVE4 | or EXCLUSIVE4
440 * | | | (SHOULD NOT)
441 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
442 * yes | no | GUARDED4 | GUARDED4
443 * yes | yes | GUARDED4 | GUARDED4
444 */
445
880a3a53 446 current->fs->umask = open->op_umask;
254454a5 447 status = nfsd4_create_file(rqstp, current_fh, *resfh, open);
880a3a53 448 current->fs->umask = 0;
749997e5 449
18032ca0 450 if (!status && open->op_label.len)
c0e6bee4 451 nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
18032ca0 452
99f88726 453 /*
ead8fb8c
KM
454 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
455 * use the returned bitmask to indicate which attributes
456 * we used to store the verifier:
749997e5 457 */
254454a5 458 if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0)
ead8fb8c
KM
459 open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
460 FATTR4_WORD1_TIME_MODIFY);
4335723e
BF
461 } else
462 /*
463 * Note this may exit with the parent still locked.
464 * We will hold the lock until nfsd4_open's final
465 * lookup, to prevent renames or unlinks until we've had
466 * a chance to an acquire a delegation if appropriate.
467 */
1da177e4 468 status = nfsd_lookup(rqstp, current_fh,
1708e50b 469 open->op_fname, open->op_fnamelen, *resfh);
9dc4e6c4
BF
470 if (status)
471 goto out;
c0e6bee4 472 status = nfsd_check_obj_isreg(*resfh);
af85852d
BF
473 if (status)
474 goto out;
1da177e4 475
9208faf2 476 if (is_create_with_attrs(open) && open->op_acl != NULL)
c0e6bee4 477 do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
9208faf2 478
c0e6bee4 479 nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
7007c90f 480 accmode = NFSD_MAY_NOP;
89f6c336
BF
481 if (open->op_created ||
482 open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
7007c90f 483 accmode |= NFSD_MAY_OWNER_OVERRIDE;
c0e6bee4 484 status = do_open_permission(rqstp, *resfh, open, accmode);
41fd1e42 485 set_change_info(&open->op_cinfo, current_fh);
af85852d 486out:
1da177e4
LT
487 return status;
488}
489
b37ad28b 490static __be32
bbc9c36c 491do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
1da177e4 492{
bbc9c36c 493 struct svc_fh *current_fh = &cstate->current_fh;
b37ad28b 494 __be32 status;
9f415eb2 495 int accmode = 0;
1da177e4 496
1da177e4
LT
497 /* We don't know the target directory, and therefore can not
498 * set the change info
499 */
500
501 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
502
bbc9c36c 503 nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
1da177e4
LT
504
505 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
506 (open->op_iattr.ia_size == 0);
9f415eb2
BF
507 /*
508 * In the delegation case, the client is telling us about an
509 * open that it *already* performed locally, some time ago. We
510 * should let it succeed now if possible.
511 *
512 * In the case of a CLAIM_FH open, on the other hand, the client
513 * may be counting on us to enforce permissions (the Linux 4.1
514 * client uses this for normal opens, for example).
515 */
516 if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
517 accmode = NFSD_MAY_OWNER_OVERRIDE;
1da177e4 518
9f415eb2 519 status = do_open_permission(rqstp, current_fh, open, accmode);
1da177e4
LT
520
521 return status;
522}
523
60adfc50
AA
524static void
525copy_clientid(clientid_t *clid, struct nfsd4_session *session)
526{
527 struct nfsd4_sessionid *sid =
528 (struct nfsd4_sessionid *)session->se_sessionid.data;
529
530 clid->cl_boot = sid->clientid.cl_boot;
531 clid->cl_id = sid->clientid.cl_id;
532}
1da177e4 533
7191155b 534static __be32
ca364317 535nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 536 union nfsd4_op_u *u)
1da177e4 537{
eb69853d 538 struct nfsd4_open *open = &u->open;
b37ad28b 539 __be32 status;
c0e6bee4 540 struct svc_fh *resfh = NULL;
3320fef1
SK
541 struct net *net = SVC_NET(rqstp);
542 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
03f318ca 543 bool reclaim = false;
6668958f 544
fe0750e5 545 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
1708e50b 546 (int)open->op_fnamelen, open->op_fname,
fe0750e5 547 open->op_openowner);
1da177e4 548
fb70bf12
CL
549 open->op_filp = NULL;
550
1da177e4
LT
551 /* This check required by spec. */
552 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
553 return nfserr_inval;
554
500c2481 555 open->op_created = false;
ab1350b2
MJ
556 /*
557 * RFC5661 18.51.3
558 * Before RECLAIM_COMPLETE done, server should deny new lock
559 */
560 if (nfsd4_has_session(cstate) &&
ec59659b 561 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) &&
ab1350b2
MJ
562 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
563 return nfserr_grace;
564
60adfc50
AA
565 if (nfsd4_has_session(cstate))
566 copy_clientid(&open->op_clientid, cstate->session);
567
1da177e4 568 /* check seqid for replay. set nfs4_owner */
6cd22668 569 status = nfsd4_process_open1(cstate, open, nn);
a90b061c 570 if (status == nfserr_replay_me) {
fe0750e5 571 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
ca364317 572 fh_put(&cstate->current_fh);
a4773c08
BF
573 fh_copy_shallow(&cstate->current_fh.fh_handle,
574 &rp->rp_openfh);
8837abca 575 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
1da177e4
LT
576 if (status)
577 dprintk("nfsd4_open: replay failed"
578 " restoring previous filehandle\n");
579 else
a90b061c 580 status = nfserr_replay_me;
1da177e4
LT
581 }
582 if (status)
583 goto out;
9d313b17
BF
584 if (open->op_xdr_error) {
585 status = open->op_xdr_error;
586 goto out;
587 }
fb553c0f 588
3c8e0316
YZ
589 status = nfsd4_check_open_attributes(rqstp, cstate, open);
590 if (status)
591 goto out;
592
fb553c0f
BF
593 /* Openowner is now set, so sequence id will get bumped. Now we need
594 * these checks before we do any creates: */
cbd0d51a 595 status = nfserr_grace;
c87fb4a3 596 if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
cbd0d51a
BF
597 goto out;
598 status = nfserr_no_grace;
c87fb4a3 599 if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
cbd0d51a 600 goto out;
fb553c0f 601
1da177e4 602 switch (open->op_claim_type) {
26320d7e
CL
603 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
604 case NFS4_OPEN_CLAIM_NULL:
605 status = do_open_lookup(rqstp, cstate, open, &resfh);
606 if (status)
1da177e4 607 goto out;
26320d7e
CL
608 break;
609 case NFS4_OPEN_CLAIM_PREVIOUS:
610 status = nfs4_check_open_reclaim(cstate->clp);
611 if (status)
1da177e4 612 goto out;
26320d7e
CL
613 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
614 reclaim = true;
615 fallthrough;
616 case NFS4_OPEN_CLAIM_FH:
617 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
618 status = do_open_fhandle(rqstp, cstate, open);
619 if (status)
620 goto out;
621 resfh = &cstate->current_fh;
622 break;
623 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
624 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
625 status = nfserr_notsupp;
626 goto out;
627 default:
628 status = nfserr_inval;
629 goto out;
1da177e4 630 }
7e2ce0cc 631
c0e6bee4 632 status = nfsd4_process_open2(rqstp, resfh, open);
ca3f9acb
CL
633 if (status && open->op_created)
634 pr_warn("nfsd4_process_open2 failed to open newly-created file: status=%u\n",
635 be32_to_cpu(status));
03f318ca
BF
636 if (reclaim && !status)
637 nn->somebody_reclaimed = true;
1da177e4 638out:
fb70bf12
CL
639 if (open->op_filp) {
640 fput(open->op_filp);
641 open->op_filp = NULL;
642 }
c0e6bee4
BF
643 if (resfh && resfh != &cstate->current_fh) {
644 fh_dup2(&cstate->current_fh, resfh);
645 fh_put(resfh);
646 kfree(resfh);
647 }
42297899 648 nfsd4_cleanup_open_state(cstate, open);
9411b1d4 649 nfsd4_bump_seqid(cstate, status);
1da177e4
LT
650 return status;
651}
652
9d313b17
BF
653/*
654 * OPEN is the only seqid-mutating operation whose decoding can fail
655 * with a seqid-mutating error (specifically, decoding of user names in
656 * the attributes). Therefore we have to do some processing to look up
657 * the stateowner so that we can bump the seqid.
658 */
659static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
660{
eb69853d 661 struct nfsd4_open *open = &op->u.open;
9d313b17
BF
662
663 if (!seqid_mutating_err(ntohl(op->status)))
664 return op->status;
665 if (nfsd4_has_session(cstate))
666 return op->status;
667 open->op_xdr_error = op->status;
eb69853d 668 return nfsd4_open(rqstp, cstate, &op->u);
9d313b17
BF
669}
670
1da177e4
LT
671/*
672 * filehandle-manipulating ops.
673 */
7191155b 674static __be32
b591480b 675nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 676 union nfsd4_op_u *u)
1da177e4 677{
eb69853d 678 u->getfh = &cstate->current_fh;
1da177e4
LT
679 return nfs_ok;
680}
681
7191155b 682static __be32
ca364317 683nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 684 union nfsd4_op_u *u)
1da177e4 685{
eb69853d 686 struct nfsd4_putfh *putfh = &u->putfh;
b9e8638e 687 __be32 ret;
eb69853d 688
ca364317
BF
689 fh_put(&cstate->current_fh);
690 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
d8b26071 691 memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval,
ca364317 692 putfh->pf_fhlen);
b9e8638e
OK
693 ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
694#ifdef CONFIG_NFSD_V4_2_INTER_SSC
695 if (ret == nfserr_stale && putfh->no_verify) {
696 SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN);
697 ret = 0;
698 }
699#endif
700 return ret;
1da177e4
LT
701}
702
7191155b 703static __be32
b591480b 704nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 705 union nfsd4_op_u *u)
1da177e4 706{
b37ad28b 707 __be32 status;
1da177e4 708
ca364317 709 fh_put(&cstate->current_fh);
df547efb 710 status = exp_pseudoroot(rqstp, &cstate->current_fh);
1da177e4
LT
711 return status;
712}
713
7191155b 714static __be32
b591480b 715nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 716 union nfsd4_op_u *u)
1da177e4 717{
ca364317 718 if (!cstate->save_fh.fh_dentry)
1da177e4
LT
719 return nfserr_restorefh;
720
ca364317 721 fh_dup2(&cstate->current_fh, &cstate->save_fh);
51100d2b 722 if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) {
37c593c5 723 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
51100d2b 724 SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
37c593c5 725 }
1da177e4
LT
726 return nfs_ok;
727}
728
7191155b 729static __be32
b591480b 730nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 731 union nfsd4_op_u *u)
1da177e4 732{
ca364317 733 fh_dup2(&cstate->save_fh, &cstate->current_fh);
51100d2b 734 if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
37c593c5 735 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
51100d2b 736 SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG);
37c593c5 737 }
1da177e4
LT
738 return nfs_ok;
739}
740
741/*
742 * misc nfsv4 ops
743 */
7191155b 744static __be32
ca364317 745nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 746 union nfsd4_op_u *u)
1da177e4 747{
eb69853d 748 struct nfsd4_access *access = &u->access;
c11d7fd1 749 u32 access_full;
eb69853d 750
c11d7fd1
FL
751 access_full = NFS3_ACCESS_FULL;
752 if (cstate->minorversion >= 2)
753 access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
754 NFS4_ACCESS_XAWRITE;
755
756 if (access->ac_req_access & ~access_full)
1da177e4
LT
757 return nfserr_inval;
758
759 access->ac_resp_access = access->ac_req_access;
ca364317
BF
760 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
761 &access->ac_supported);
1da177e4
LT
762}
763
b9c0ef85 764static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
ab4684d1 765{
27c438f5 766 __be32 *verf = (__be32 *)verifier->data;
ab4684d1 767
27c438f5
TM
768 BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data));
769
3988a578 770 nfsd_copy_write_verifier(verf, net_generic(net, nfsd_net_id));
ab4684d1
CL
771}
772
7191155b 773static __be32
ca364317 774nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 775 union nfsd4_op_u *u)
1da177e4 776{
eb69853d
CH
777 struct nfsd4_commit *commit = &u->commit;
778
75c096f7 779 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
524ff1af
TM
780 commit->co_count,
781 (__be32 *)commit->co_verf.data);
1da177e4
LT
782}
783
b37ad28b 784static __be32
ca364317 785nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 786 union nfsd4_op_u *u)
1da177e4 787{
eb69853d 788 struct nfsd4_create *create = &u->create;
1da177e4 789 struct svc_fh resfh;
b37ad28b 790 __be32 status;
1da177e4
LT
791 dev_t rdev;
792
793 fh_init(&resfh, NFS4_FHSIZE);
794
fa08139d 795 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
1da177e4
LT
796 if (status)
797 return status;
798
3c8e0316
YZ
799 status = check_attr_support(rqstp, cstate, create->cr_bmval,
800 nfsd_attrmask);
801 if (status)
802 return status;
803
880a3a53 804 current->fs->umask = create->cr_umask;
1da177e4
LT
805 switch (create->cr_type) {
806 case NF4LNK:
ca364317
BF
807 status = nfsd_symlink(rqstp, &cstate->current_fh,
808 create->cr_name, create->cr_namelen,
1e444f5b 809 create->cr_data, &resfh);
1da177e4
LT
810 break;
811
812 case NF4BLK:
880a3a53 813 status = nfserr_inval;
1da177e4
LT
814 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
815 if (MAJOR(rdev) != create->cr_specdata1 ||
816 MINOR(rdev) != create->cr_specdata2)
880a3a53 817 goto out_umask;
ca364317
BF
818 status = nfsd_create(rqstp, &cstate->current_fh,
819 create->cr_name, create->cr_namelen,
820 &create->cr_iattr, S_IFBLK, rdev, &resfh);
1da177e4
LT
821 break;
822
823 case NF4CHR:
880a3a53 824 status = nfserr_inval;
1da177e4
LT
825 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
826 if (MAJOR(rdev) != create->cr_specdata1 ||
827 MINOR(rdev) != create->cr_specdata2)
880a3a53 828 goto out_umask;
ca364317
BF
829 status = nfsd_create(rqstp, &cstate->current_fh,
830 create->cr_name, create->cr_namelen,
f532c9ff 831 &create->cr_iattr, S_IFCHR, rdev, &resfh);
1da177e4
LT
832 break;
833
834 case NF4SOCK:
ca364317
BF
835 status = nfsd_create(rqstp, &cstate->current_fh,
836 create->cr_name, create->cr_namelen,
837 &create->cr_iattr, S_IFSOCK, 0, &resfh);
1da177e4
LT
838 break;
839
840 case NF4FIFO:
ca364317
BF
841 status = nfsd_create(rqstp, &cstate->current_fh,
842 create->cr_name, create->cr_namelen,
843 &create->cr_iattr, S_IFIFO, 0, &resfh);
1da177e4
LT
844 break;
845
846 case NF4DIR:
847 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
ca364317
BF
848 status = nfsd_create(rqstp, &cstate->current_fh,
849 create->cr_name, create->cr_namelen,
850 &create->cr_iattr, S_IFDIR, 0, &resfh);
1da177e4
LT
851 break;
852
853 default:
854 status = nfserr_badtype;
855 }
856
9208faf2
YZ
857 if (status)
858 goto out;
1da177e4 859
18032ca0
DQ
860 if (create->cr_label.len)
861 nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
862
9208faf2
YZ
863 if (create->cr_acl != NULL)
864 do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
865 create->cr_bmval);
866
867 fh_unlock(&cstate->current_fh);
868 set_change_info(&create->cr_cinfo, &cstate->current_fh);
869 fh_dup2(&cstate->current_fh, &resfh);
870out:
1da177e4 871 fh_put(&resfh);
880a3a53
BF
872out_umask:
873 current->fs->umask = 0;
1da177e4
LT
874 return status;
875}
876
7191155b 877static __be32
ca364317 878nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 879 union nfsd4_op_u *u)
1da177e4 880{
eb69853d 881 struct nfsd4_getattr *getattr = &u->getattr;
b37ad28b 882 __be32 status;
1da177e4 883
8837abca 884 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
1da177e4
LT
885 if (status)
886 return status;
887
888 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
889 return nfserr_inval;
890
916d2d84
BF
891 getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
892 getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
893 getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
1da177e4 894
ca364317 895 getattr->ga_fhp = &cstate->current_fh;
1da177e4
LT
896 return nfs_ok;
897}
898
7191155b 899static __be32
ca364317 900nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 901 union nfsd4_op_u *u)
1da177e4 902{
eb69853d 903 struct nfsd4_link *link = &u->link;
95424460 904 __be32 status;
1da177e4 905
ca364317
BF
906 status = nfsd_link(rqstp, &cstate->current_fh,
907 link->li_name, link->li_namelen, &cstate->save_fh);
1da177e4 908 if (!status)
ca364317 909 set_change_info(&link->li_cinfo, &cstate->current_fh);
1da177e4
LT
910 return status;
911}
912
0ff7ab46 913static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
1da177e4
LT
914{
915 struct svc_fh tmp_fh;
b37ad28b 916 __be32 ret;
1da177e4
LT
917
918 fh_init(&tmp_fh, NFS4_FHSIZE);
df547efb
BF
919 ret = exp_pseudoroot(rqstp, &tmp_fh);
920 if (ret)
1da177e4 921 return ret;
0ff7ab46 922 if (tmp_fh.fh_dentry == fh->fh_dentry) {
1da177e4
LT
923 fh_put(&tmp_fh);
924 return nfserr_noent;
925 }
926 fh_put(&tmp_fh);
0ff7ab46
BF
927 return nfsd_lookup(rqstp, fh, "..", 2, fh);
928}
929
930static __be32
931nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 932 union nfsd4_op_u *u)
0ff7ab46
BF
933{
934 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
1da177e4
LT
935}
936
7191155b 937static __be32
ca364317 938nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 939 union nfsd4_op_u *u)
1da177e4 940{
ca364317 941 return nfsd_lookup(rqstp, &cstate->current_fh,
eb69853d 942 u->lookup.lo_name, u->lookup.lo_len,
ca364317 943 &cstate->current_fh);
1da177e4
LT
944}
945
7191155b 946static __be32
ca364317 947nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 948 union nfsd4_op_u *u)
1da177e4 949{
eb69853d 950 struct nfsd4_read *read = &u->read;
b37ad28b 951 __be32 status;
1da177e4 952
5c4583b2 953 read->rd_nf = NULL;
1da177e4 954
87c5942e
CL
955 trace_nfsd_read_start(rqstp, &cstate->current_fh,
956 read->rd_offset, read->rd_length);
957
0cb4d23a
CL
958 read->rd_length = min_t(u32, read->rd_length, svc_max_payload(rqstp));
959 if (read->rd_offset > (u64)OFFSET_MAX)
960 read->rd_offset = (u64)OFFSET_MAX;
961 if (read->rd_offset + read->rd_length > (u64)OFFSET_MAX)
962 read->rd_length = (u64)OFFSET_MAX - read->rd_offset;
963
9b3234b9
BF
964 /*
965 * If we do a zero copy read, then a client will see read data
966 * that reflects the state of the file *after* performing the
967 * following compound.
968 *
969 * To ensure proper ordering, we therefore turn off zero copy if
970 * the client wants us to do more in this compound:
971 */
972 if (!nfsd4_last_compound_op(rqstp))
28df0988 973 __clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
9b3234b9 974
1da177e4 975 /* check stateid */
aa0d6aed
AS
976 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
977 &read->rd_stateid, RD_STATE,
624322f1 978 &read->rd_nf, NULL);
af90f707 979 if (status) {
1da177e4
LT
980 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
981 goto out;
982 }
983 status = nfs_ok;
984out:
1da177e4 985 read->rd_rqstp = rqstp;
ca364317 986 read->rd_fhp = &cstate->current_fh;
1da177e4
LT
987 return status;
988}
989
34b1744c
BF
990
991static void
992nfsd4_read_release(union nfsd4_op_u *u)
993{
5c4583b2
JL
994 if (u->read.rd_nf)
995 nfsd_file_put(u->read.rd_nf);
87c5942e
CL
996 trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
997 u->read.rd_offset, u->read.rd_length);
34b1744c
BF
998}
999
7191155b 1000static __be32
ca364317 1001nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1002 union nfsd4_op_u *u)
1da177e4 1003{
eb69853d 1004 struct nfsd4_readdir *readdir = &u->readdir;
1da177e4
LT
1005 u64 cookie = readdir->rd_cookie;
1006 static const nfs4_verifier zeroverf;
1007
1008 /* no need to check permission - this will be done in nfsd_readdir() */
1009
1010 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
1011 return nfserr_inval;
1012
916d2d84
BF
1013 readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
1014 readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
1015 readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
1da177e4 1016
832023bf 1017 if ((cookie == 1) || (cookie == 2) ||
1da177e4
LT
1018 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
1019 return nfserr_bad_cookie;
1020
1021 readdir->rd_rqstp = rqstp;
ca364317 1022 readdir->rd_fhp = &cstate->current_fh;
1da177e4
LT
1023 return nfs_ok;
1024}
1025
7191155b 1026static __be32
ca364317 1027nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1028 union nfsd4_op_u *u)
1da177e4 1029{
eb69853d
CH
1030 u->readlink.rl_rqstp = rqstp;
1031 u->readlink.rl_fhp = &cstate->current_fh;
1da177e4
LT
1032 return nfs_ok;
1033}
1034
7191155b 1035static __be32
ca364317 1036nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1037 union nfsd4_op_u *u)
1da177e4 1038{
eb69853d 1039 struct nfsd4_remove *remove = &u->remove;
b37ad28b 1040 __be32 status;
1da177e4 1041
c87fb4a3 1042 if (opens_in_grace(SVC_NET(rqstp)))
c815afc7 1043 return nfserr_grace;
ca364317
BF
1044 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
1045 remove->rm_name, remove->rm_namelen);
1da177e4 1046 if (!status) {
ca364317
BF
1047 fh_unlock(&cstate->current_fh);
1048 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
1da177e4
LT
1049 }
1050 return status;
1051}
1052
7191155b 1053static __be32
ca364317 1054nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1055 union nfsd4_op_u *u)
1da177e4 1056{
eb69853d 1057 struct nfsd4_rename *rename = &u->rename;
95424460 1058 __be32 status;
1da177e4 1059
f8f71d00 1060 if (opens_in_grace(SVC_NET(rqstp)))
c815afc7 1061 return nfserr_grace;
ca364317
BF
1062 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
1063 rename->rn_snamelen, &cstate->current_fh,
1da177e4 1064 rename->rn_tname, rename->rn_tnamelen);
2a6cf944
BF
1065 if (status)
1066 return status;
1067 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
1068 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
1069 return nfs_ok;
1da177e4
LT
1070}
1071
dcb488a3
AA
1072static __be32
1073nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1074 union nfsd4_op_u *u)
dcb488a3 1075{
eb69853d 1076 struct nfsd4_secinfo *secinfo = &u->secinfo;
dcb488a3
AA
1077 struct svc_export *exp;
1078 struct dentry *dentry;
1079 __be32 err;
1080
29a78a3e
BF
1081 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
1082 if (err)
1083 return err;
dcb488a3
AA
1084 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
1085 secinfo->si_name, secinfo->si_namelen,
1086 &exp, &dentry);
1087 if (err)
1088 return err;
2f6fc056 1089 fh_unlock(&cstate->current_fh);
2b0143b5 1090 if (d_really_is_negative(dentry)) {
dcb488a3
AA
1091 exp_put(exp);
1092 err = nfserr_noent;
1093 } else
1094 secinfo->si_exp = exp;
1095 dput(dentry);
56560b9a
BF
1096 if (cstate->minorversion)
1097 /* See rfc 5661 section 2.6.3.1.1.8 */
1098 fh_put(&cstate->current_fh);
dcb488a3
AA
1099 return err;
1100}
1101
04f4ad16
BF
1102static __be32
1103nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1104 union nfsd4_op_u *u)
04f4ad16
BF
1105{
1106 __be32 err;
1107
eb69853d 1108 switch (u->secinfo_no_name.sin_style) {
04f4ad16
BF
1109 case NFS4_SECINFO_STYLE4_CURRENT_FH:
1110 break;
1111 case NFS4_SECINFO_STYLE4_PARENT:
1112 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
1113 if (err)
1114 return err;
1115 break;
1116 default:
1117 return nfserr_inval;
1118 }
bf18f163 1119
eb69853d 1120 u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
04f4ad16
BF
1121 fh_put(&cstate->current_fh);
1122 return nfs_ok;
1123}
1124
34b1744c
BF
1125static void
1126nfsd4_secinfo_release(union nfsd4_op_u *u)
1127{
1128 if (u->secinfo.si_exp)
1129 exp_put(u->secinfo.si_exp);
1130}
1131
ec572b9e
EG
1132static void
1133nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
1134{
1135 if (u->secinfo_no_name.sin_exp)
1136 exp_put(u->secinfo_no_name.sin_exp);
1137}
1138
7191155b 1139static __be32
ca364317 1140nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1141 union nfsd4_op_u *u)
1da177e4 1142{
eb69853d 1143 struct nfsd4_setattr *setattr = &u->setattr;
b37ad28b 1144 __be32 status = nfs_ok;
96f6f985 1145 int err;
1da177e4 1146
1da177e4 1147 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
af90f707 1148 status = nfs4_preprocess_stateid_op(rqstp, cstate,
aa0d6aed 1149 &cstate->current_fh, &setattr->sa_stateid,
624322f1 1150 WR_STATE, NULL, NULL);
375c5547 1151 if (status) {
3e3b4800 1152 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
375c5547
BF
1153 return status;
1154 }
1da177e4 1155 }
96f6f985
AV
1156 err = fh_want_write(&cstate->current_fh);
1157 if (err)
1158 return nfserrno(err);
1da177e4 1159 status = nfs_ok;
3c8e0316
YZ
1160
1161 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
1162 nfsd_attrmask);
1163 if (status)
1164 goto out;
1165
1da177e4 1166 if (setattr->sa_acl != NULL)
ca364317
BF
1167 status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
1168 setattr->sa_acl);
1da177e4 1169 if (status)
18f335af 1170 goto out;
18032ca0
DQ
1171 if (setattr->sa_label.len)
1172 status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
1173 &setattr->sa_label);
1174 if (status)
1175 goto out;
ca364317 1176 status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
2a1aa489 1177 0, (time64_t)0);
18f335af 1178out:
bad0dcff 1179 fh_drop_write(&cstate->current_fh);
1da177e4
LT
1180 return status;
1181}
1182
7191155b 1183static __be32
ca364317 1184nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1185 union nfsd4_op_u *u)
1da177e4 1186{
eb69853d 1187 struct nfsd4_write *write = &u->write;
1da177e4 1188 stateid_t *stateid = &write->wr_stateid;
5c4583b2 1189 struct nfsd_file *nf = NULL;
b37ad28b 1190 __be32 status = nfs_ok;
31dec253 1191 unsigned long cnt;
ffe1137b 1192 int nvecs;
1da177e4 1193
6260d9a5
CL
1194 if (write->wr_offset > (u64)OFFSET_MAX ||
1195 write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
1196 return nfserr_fbig;
1da177e4 1197
d890be15
CL
1198 cnt = write->wr_buflen;
1199 trace_nfsd_write_start(rqstp, &cstate->current_fh,
1200 write->wr_offset, cnt);
aa0d6aed 1201 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
624322f1 1202 stateid, WR_STATE, &nf, NULL);
375c5547
BF
1203 if (status) {
1204 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1205 return status;
1206 }
1207
1da177e4 1208 write->wr_how_written = write->wr_stable_how;
1da177e4 1209
dae9a6ca 1210 nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
ffe1137b
BF
1211 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1212
16f8f894 1213 status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
af90f707 1214 write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
19e0663f
TM
1215 write->wr_how_written,
1216 (__be32 *)write->wr_verifier.data);
5c4583b2 1217 nfsd_file_put(nf);
1da177e4 1218
31dec253 1219 write->wr_bytes_written = cnt;
d890be15
CL
1220 trace_nfsd_write_done(rqstp, &cstate->current_fh,
1221 write->wr_offset, cnt);
1da177e4 1222 return status;
1da177e4
LT
1223}
1224
ffa0160a 1225static __be32
29ae7f9d 1226nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
5c4583b2
JL
1227 stateid_t *src_stateid, struct nfsd_file **src,
1228 stateid_t *dst_stateid, struct nfsd_file **dst)
ffa0160a 1229{
ffa0160a
CH
1230 __be32 status;
1231
01310bb7
SM
1232 if (!cstate->save_fh.fh_dentry)
1233 return nfserr_nofilehandle;
1234
ffa0160a 1235 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
624322f1 1236 src_stateid, RD_STATE, src, NULL);
ffa0160a
CH
1237 if (status) {
1238 dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1239 goto out;
1240 }
1241
1242 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
624322f1 1243 dst_stateid, WR_STATE, dst, NULL);
ffa0160a
CH
1244 if (status) {
1245 dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1246 goto out_put_src;
1247 }
1248
1249 /* fix up for NFS-specific error code */
5c4583b2
JL
1250 if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
1251 !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
ffa0160a
CH
1252 status = nfserr_wrong_type;
1253 goto out_put_dst;
1254 }
1255
29ae7f9d
AS
1256out:
1257 return status;
1258out_put_dst:
5c4583b2 1259 nfsd_file_put(*dst);
29ae7f9d 1260out_put_src:
5c4583b2 1261 nfsd_file_put(*src);
29ae7f9d
AS
1262 goto out;
1263}
1264
1265static __be32
1266nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1267 union nfsd4_op_u *u)
29ae7f9d 1268{
eb69853d 1269 struct nfsd4_clone *clone = &u->clone;
5c4583b2 1270 struct nfsd_file *src, *dst;
29ae7f9d
AS
1271 __be32 status;
1272
1273 status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
1274 &clone->cl_dst_stateid, &dst);
1275 if (status)
1276 goto out;
1277
a2f4c3fa 1278 status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos,
b66ae6dd 1279 dst, clone->cl_dst_pos, clone->cl_count,
a25e3726 1280 EX_ISSYNC(cstate->current_fh.fh_export));
ffa0160a 1281
5c4583b2
JL
1282 nfsd_file_put(dst);
1283 nfsd_file_put(src);
ffa0160a
CH
1284out:
1285 return status;
1286}
1287
e0639dc5
OK
1288void nfs4_put_copy(struct nfsd4_copy *copy)
1289{
1290 if (!refcount_dec_and_test(&copy->refcount))
1291 return;
1292 kfree(copy);
1293}
1294
1295static bool
1296check_and_set_stop_copy(struct nfsd4_copy *copy)
1297{
1298 bool value;
1299
1300 spin_lock(&copy->cp_clp->async_lock);
1301 value = copy->stopped;
1302 if (!copy->stopped)
1303 copy->stopped = true;
1304 spin_unlock(&copy->cp_clp->async_lock);
1305 return value;
1306}
1307
1308static void nfsd4_stop_copy(struct nfsd4_copy *copy)
1309{
1310 /* only 1 thread should stop the copy */
1311 if (!check_and_set_stop_copy(copy))
1312 kthread_stop(copy->copy_task);
1313 nfs4_put_copy(copy);
1314}
1315
1316static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp)
1317{
1318 struct nfsd4_copy *copy = NULL;
1319
1320 spin_lock(&clp->async_lock);
1321 if (!list_empty(&clp->async_copies)) {
1322 copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
1323 copies);
1324 refcount_inc(&copy->refcount);
1325 }
1326 spin_unlock(&clp->async_lock);
1327 return copy;
1328}
1329
1330void nfsd4_shutdown_copy(struct nfs4_client *clp)
1331{
1332 struct nfsd4_copy *copy;
1333
1334 while ((copy = nfsd4_get_copy(clp)) != NULL)
1335 nfsd4_stop_copy(copy);
1336}
ce0887ac
OK
1337#ifdef CONFIG_NFSD_V4_2_INTER_SSC
1338
1339extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1340 struct nfs_fh *src_fh,
1341 nfs4_stateid *stateid);
1342extern void nfs42_ssc_close(struct file *filep);
1343
1344extern void nfs_sb_deactive(struct super_block *sb);
1345
1346#define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
1347
f4e44b39
DN
1348/*
1349 * setup a work entry in the ssc delayed unmount list.
1350 */
f47dc2d3 1351static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr,
f4e44b39
DN
1352 struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt)
1353{
8e70bf27 1354 struct nfsd4_ssc_umount_item *ni = NULL;
f4e44b39
DN
1355 struct nfsd4_ssc_umount_item *work = NULL;
1356 struct nfsd4_ssc_umount_item *tmp;
1357 DEFINE_WAIT(wait);
1358
1359 *ss_mnt = NULL;
1360 *retwork = NULL;
1361 work = kzalloc(sizeof(*work), GFP_KERNEL);
1362try_again:
1363 spin_lock(&nn->nfsd_ssc_lock);
1364 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1365 if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
1366 continue;
1367 /* found a match */
1368 if (ni->nsui_busy) {
1369 /* wait - and try again */
1370 prepare_to_wait(&nn->nfsd_ssc_waitq, &wait,
1371 TASK_INTERRUPTIBLE);
1372 spin_unlock(&nn->nfsd_ssc_lock);
1373
1374 /* allow 20secs for mount/unmount for now - revisit */
1375 if (signal_pending(current) ||
1376 (schedule_timeout(20*HZ) == 0)) {
1377 kfree(work);
1378 return nfserr_eagain;
1379 }
1380 finish_wait(&nn->nfsd_ssc_waitq, &wait);
1381 goto try_again;
1382 }
1383 *ss_mnt = ni->nsui_vfsmount;
1384 refcount_inc(&ni->nsui_refcnt);
1385 spin_unlock(&nn->nfsd_ssc_lock);
1386 kfree(work);
1387
1388 /* return vfsmount in ss_mnt */
1389 return 0;
1390 }
1391 if (work) {
53048779 1392 strlcpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr) - 1);
f4e44b39
DN
1393 refcount_set(&work->nsui_refcnt, 2);
1394 work->nsui_busy = true;
1395 list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list);
1396 *retwork = work;
1397 }
1398 spin_unlock(&nn->nfsd_ssc_lock);
1399 return 0;
1400}
1401
1402static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn,
1403 struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt)
1404{
1405 /* set nsui_vfsmount, clear busy flag and wakeup waiters */
1406 spin_lock(&nn->nfsd_ssc_lock);
1407 work->nsui_vfsmount = ss_mnt;
1408 work->nsui_busy = false;
1409 wake_up_all(&nn->nfsd_ssc_waitq);
1410 spin_unlock(&nn->nfsd_ssc_lock);
1411}
1412
1413static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn,
1414 struct nfsd4_ssc_umount_item *work)
1415{
1416 spin_lock(&nn->nfsd_ssc_lock);
1417 list_del(&work->nsui_list);
1418 wake_up_all(&nn->nfsd_ssc_waitq);
1419 spin_unlock(&nn->nfsd_ssc_lock);
1420 kfree(work);
1421}
1422
f2453978 1423/*
ce0887ac
OK
1424 * Support one copy source server for now.
1425 */
1426static __be32
1427nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
1428 struct vfsmount **mount)
1429{
1430 struct file_system_type *type;
1431 struct vfsmount *ss_mnt;
1432 struct nfs42_netaddr *naddr;
1433 struct sockaddr_storage tmp_addr;
1434 size_t tmp_addrlen, match_netid_len = 3;
1435 char *startsep = "", *endsep = "", *match_netid = "tcp";
1436 char *ipaddr, *dev_name, *raw_data;
b8290ca2
OK
1437 int len, raw_len;
1438 __be32 status = nfserr_inval;
f4e44b39
DN
1439 struct nfsd4_ssc_umount_item *work = NULL;
1440 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
ce0887ac
OK
1441
1442 naddr = &nss->u.nl4_addr;
1443 tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
1444 naddr->addr_len,
1445 (struct sockaddr *)&tmp_addr,
1446 sizeof(tmp_addr));
1447 if (tmp_addrlen == 0)
1448 goto out_err;
1449
1450 if (tmp_addr.ss_family == AF_INET6) {
1451 startsep = "[";
1452 endsep = "]";
1453 match_netid = "tcp6";
1454 match_netid_len = 4;
1455 }
1456
1457 if (naddr->netid_len != match_netid_len ||
1458 strncmp(naddr->netid, match_netid, naddr->netid_len))
1459 goto out_err;
1460
1461 /* Construct the raw data for the vfs_kern_mount call */
1462 len = RPC_MAX_ADDRBUFLEN + 1;
1463 ipaddr = kzalloc(len, GFP_KERNEL);
1464 if (!ipaddr)
1465 goto out_err;
1466
1467 rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len);
1468
1469 /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
1470
1471 raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr);
1472 raw_data = kzalloc(raw_len, GFP_KERNEL);
1473 if (!raw_data)
1474 goto out_free_ipaddr;
1475
1476 snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr);
1477
b8290ca2 1478 status = nfserr_nodev;
ce0887ac
OK
1479 type = get_fs_type("nfs");
1480 if (!type)
1481 goto out_free_rawdata;
1482
1483 /* Set the server:<export> for the vfs_kern_mount call */
1484 dev_name = kzalloc(len + 5, GFP_KERNEL);
1485 if (!dev_name)
1486 goto out_free_rawdata;
1487 snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
1488
f4e44b39
DN
1489 status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt);
1490 if (status)
1491 goto out_free_devname;
1492 if (ss_mnt)
1493 goto out_done;
1494
ce0887ac
OK
1495 /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
1496 ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
1497 module_put(type->owner);
f4e44b39 1498 if (IS_ERR(ss_mnt)) {
54185267 1499 status = nfserr_nodev;
f4e44b39
DN
1500 if (work)
1501 nfsd4_ssc_cancel_dul_work(nn, work);
ce0887ac 1502 goto out_free_devname;
f4e44b39
DN
1503 }
1504 if (work)
1505 nfsd4_ssc_update_dul_work(nn, work, ss_mnt);
1506out_done:
ce0887ac
OK
1507 status = 0;
1508 *mount = ss_mnt;
1509
1510out_free_devname:
1511 kfree(dev_name);
1512out_free_rawdata:
1513 kfree(raw_data);
1514out_free_ipaddr:
1515 kfree(ipaddr);
1516out_err:
1517 return status;
1518}
1519
1520static void
1521nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1522{
0cfcd405 1523 nfs_do_sb_deactive(ss_mnt->mnt_sb);
ce0887ac
OK
1524 mntput(ss_mnt);
1525}
1526
f2453978 1527/*
ce0887ac 1528 * Verify COPY destination stateid.
f2453978 1529 *
ce0887ac
OK
1530 * Connect to the source server with NFSv4.1.
1531 * Create the source struct file for nfsd_copy_range.
1532 * Called with COPY cstate:
1533 * SAVED_FH: source filehandle
1534 * CURRENT_FH: destination filehandle
ce0887ac
OK
1535 */
1536static __be32
1537nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1538 struct nfsd4_compound_state *cstate,
1539 struct nfsd4_copy *copy, struct vfsmount **mount)
1540{
1541 struct svc_fh *s_fh = NULL;
1542 stateid_t *s_stid = &copy->cp_src_stateid;
b8290ca2 1543 __be32 status = nfserr_inval;
ce0887ac
OK
1544
1545 /* Verify the destination stateid and set dst struct file*/
1546 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1547 &copy->cp_dst_stateid,
1548 WR_STATE, &copy->nf_dst, NULL);
1549 if (status)
1550 goto out;
1551
1552 status = nfsd4_interssc_connect(&copy->cp_src, rqstp, mount);
1553 if (status)
1554 goto out;
1555
1556 s_fh = &cstate->save_fh;
1557
1558 copy->c_fh.size = s_fh->fh_handle.fh_size;
d8b26071 1559 memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size);
3f9544ca 1560 copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
ce0887ac
OK
1561 memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
1562 sizeof(stateid_opaque_t));
1563
1564 status = 0;
1565out:
1566 return status;
1567}
1568
1569static void
1570nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1571 struct nfsd_file *dst)
1572{
f4e44b39
DN
1573 bool found = false;
1574 long timeout;
1575 struct nfsd4_ssc_umount_item *tmp;
f47dc2d3 1576 struct nfsd4_ssc_umount_item *ni = NULL;
f4e44b39
DN
1577 struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
1578
ce0887ac 1579 nfs42_ssc_close(src->nf_file);
ce0887ac 1580 nfsd_file_put(dst);
f4e44b39
DN
1581 fput(src->nf_file);
1582
1583 if (!nn) {
1584 mntput(ss_mnt);
1585 return;
1586 }
1587 spin_lock(&nn->nfsd_ssc_lock);
1588 timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
1589 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1590 if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
1591 list_del(&ni->nsui_list);
1592 /*
1593 * vfsmount can be shared by multiple exports,
1594 * decrement refcnt. If the count drops to 1 it
1595 * will be unmounted when nsui_expire expires.
1596 */
1597 refcount_dec(&ni->nsui_refcnt);
1598 ni->nsui_expire = jiffies + timeout;
1599 list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list);
1600 found = true;
1601 break;
1602 }
1603 }
1604 spin_unlock(&nn->nfsd_ssc_lock);
1605 if (!found) {
1606 mntput(ss_mnt);
1607 return;
1608 }
ce0887ac
OK
1609}
1610
1611#else /* CONFIG_NFSD_V4_2_INTER_SSC */
1612
1613static __be32
1614nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1615 struct nfsd4_compound_state *cstate,
1616 struct nfsd4_copy *copy,
1617 struct vfsmount **mount)
1618{
1619 *mount = NULL;
b8290ca2 1620 return nfserr_inval;
ce0887ac
OK
1621}
1622
1623static void
1624nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1625 struct nfsd_file *dst)
1626{
1627}
1628
1629static void
1630nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1631{
1632}
1633
1634static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1635 struct nfs_fh *src_fh,
1636 nfs4_stateid *stateid)
1637{
1638 return NULL;
1639}
1640#endif /* CONFIG_NFSD_V4_2_INTER_SSC */
1641
1642static __be32
1643nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
1644 struct nfsd4_compound_state *cstate,
1645 struct nfsd4_copy *copy)
1646{
1647 return nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid,
1648 &copy->nf_src, &copy->cp_dst_stateid,
1649 &copy->nf_dst);
1650}
1651
1652static void
1653nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst)
1654{
1655 nfsd_file_put(src);
1656 nfsd_file_put(dst);
1657}
e0639dc5
OK
1658
1659static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
1660{
1661 struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
1662
1663 nfs4_put_copy(copy);
1664}
1665
1666static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
1667 struct rpc_task *task)
1668{
1669 return 1;
1670}
1671
1672static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
1673 .release = nfsd4_cb_offload_release,
1674 .done = nfsd4_cb_offload_done
1675};
1676
1677static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
1678{
eac0b17a
OK
1679 copy->cp_res.wr_stable_how =
1680 copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE;
e0639dc5
OK
1681 copy->cp_synchronous = sync;
1682 gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net);
1683}
1684
1685static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
1686{
555dbf1a
TM
1687 struct file *dst = copy->nf_dst->nf_file;
1688 struct file *src = copy->nf_src->nf_file;
1689 errseq_t since;
e0639dc5 1690 ssize_t bytes_copied = 0;
e7a833e9 1691 u64 bytes_total = copy->cp_count;
e0639dc5
OK
1692 u64 src_pos = copy->cp_src_pos;
1693 u64 dst_pos = copy->cp_dst_pos;
c2f1c4bd 1694 int status;
e0639dc5 1695
792a5112
BF
1696 /* See RFC 7862 p.67: */
1697 if (bytes_total == 0)
1698 bytes_total = ULLONG_MAX;
e0639dc5
OK
1699 do {
1700 if (kthread_should_stop())
1701 break;
555dbf1a
TM
1702 bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos,
1703 bytes_total);
e0639dc5
OK
1704 if (bytes_copied <= 0)
1705 break;
1706 bytes_total -= bytes_copied;
1707 copy->cp_res.wr_bytes_written += bytes_copied;
1708 src_pos += bytes_copied;
1709 dst_pos += bytes_copied;
1710 } while (bytes_total > 0 && !copy->cp_synchronous);
eac0b17a
OK
1711 /* for a non-zero asynchronous copy do a commit of data */
1712 if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) {
555dbf1a
TM
1713 since = READ_ONCE(dst->f_wb_err);
1714 status = vfs_fsync_range(dst, copy->cp_dst_pos,
eac0b17a 1715 copy->cp_res.wr_bytes_written, 0);
555dbf1a
TM
1716 if (!status)
1717 status = filemap_check_wb_err(dst->f_mapping, since);
eac0b17a
OK
1718 if (!status)
1719 copy->committed = true;
1720 }
e0639dc5
OK
1721 return bytes_copied;
1722}
1723
1724static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
1725{
1726 __be32 status;
1727 ssize_t bytes;
1728
1729 bytes = _nfsd_copy_file_range(copy);
1730 /* for async copy, we ignore the error, client can always retry
1731 * to get the error
1732 */
1733 if (bytes < 0 && !copy->cp_res.wr_bytes_written)
1734 status = nfserrno(bytes);
1735 else {
1736 nfsd4_init_copy_res(copy, sync);
1737 status = nfs_ok;
1738 }
1739
ce0887ac
OK
1740 if (!copy->cp_intra) /* Inter server SSC */
1741 nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src,
1742 copy->nf_dst);
1743 else
1744 nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
1745
e0639dc5
OK
1746 return status;
1747}
1748
eb162e17 1749static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
e0639dc5
OK
1750{
1751 dst->cp_src_pos = src->cp_src_pos;
1752 dst->cp_dst_pos = src->cp_dst_pos;
1753 dst->cp_count = src->cp_count;
1754 dst->cp_synchronous = src->cp_synchronous;
1755 memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
1756 memcpy(&dst->fh, &src->fh, sizeof(src->fh));
1757 dst->cp_clp = src->cp_clp;
5c4583b2 1758 dst->nf_dst = nfsd_file_get(src->nf_dst);
ce0887ac
OK
1759 dst->cp_intra = src->cp_intra;
1760 if (src->cp_intra) /* for inter, file_src doesn't exist yet */
1761 dst->nf_src = nfsd_file_get(src->nf_src);
1762
e0639dc5 1763 memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
ce0887ac
OK
1764 memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server));
1765 memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid));
1766 memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh));
1767 dst->ss_mnt = src->ss_mnt;
e0639dc5
OK
1768}
1769
1770static void cleanup_async_copy(struct nfsd4_copy *copy)
1771{
624322f1 1772 nfs4_free_copy_state(copy);
5c4583b2 1773 nfsd_file_put(copy->nf_dst);
2e577f0f
OK
1774 if (copy->cp_intra)
1775 nfsd_file_put(copy->nf_src);
e0639dc5
OK
1776 spin_lock(&copy->cp_clp->async_lock);
1777 list_del(&copy->copies);
1778 spin_unlock(&copy->cp_clp->async_lock);
1779 nfs4_put_copy(copy);
1780}
1781
1782static int nfsd4_do_async_copy(void *data)
1783{
1784 struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1785 struct nfsd4_copy *cb_copy;
1786
ce0887ac
OK
1787 if (!copy->cp_intra) { /* Inter server SSC */
1788 copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL);
1789 if (!copy->nf_src) {
1790 copy->nfserr = nfserr_serverfault;
1791 nfsd4_interssc_disconnect(copy->ss_mnt);
1792 goto do_callback;
1793 }
1794 copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, &copy->c_fh,
1795 &copy->stateid);
1796 if (IS_ERR(copy->nf_src->nf_file)) {
ce0887ac
OK
1797 copy->nfserr = nfserr_offload_denied;
1798 nfsd4_interssc_disconnect(copy->ss_mnt);
1799 goto do_callback;
1800 }
1801 }
1802
e0639dc5 1803 copy->nfserr = nfsd4_do_copy(copy, 0);
ce0887ac 1804do_callback:
e0639dc5
OK
1805 cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1806 if (!cb_copy)
1807 goto out;
49a36132 1808 refcount_set(&cb_copy->refcount, 1);
e0639dc5
OK
1809 memcpy(&cb_copy->cp_res, &copy->cp_res, sizeof(copy->cp_res));
1810 cb_copy->cp_clp = copy->cp_clp;
1811 cb_copy->nfserr = copy->nfserr;
1812 memcpy(&cb_copy->fh, &copy->fh, sizeof(copy->fh));
1813 nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp,
1814 &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD);
87512386
CL
1815 trace_nfsd_cb_offload(copy->cp_clp, &copy->cp_res.cb_stateid,
1816 &copy->fh, copy->cp_count, copy->nfserr);
e0639dc5
OK
1817 nfsd4_run_cb(&cb_copy->cp_cb);
1818out:
ce0887ac
OK
1819 if (!copy->cp_intra)
1820 kfree(copy->nf_src);
e0639dc5
OK
1821 cleanup_async_copy(copy);
1822 return 0;
1823}
1824
29ae7f9d
AS
1825static __be32
1826nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 1827 union nfsd4_op_u *u)
29ae7f9d 1828{
eb69853d 1829 struct nfsd4_copy *copy = &u->copy;
29ae7f9d 1830 __be32 status;
e0639dc5 1831 struct nfsd4_copy *async_copy = NULL;
29ae7f9d 1832
ce0887ac
OK
1833 if (!copy->cp_intra) { /* Inter server SSC */
1834 if (!inter_copy_offload_enable || copy->cp_synchronous) {
1835 status = nfserr_notsupp;
1836 goto out;
1837 }
1838 status = nfsd4_setup_inter_ssc(rqstp, cstate, copy,
1839 &copy->ss_mnt);
1840 if (status)
1841 return nfserr_offload_denied;
1842 } else {
1843 status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
1844 if (status)
1845 return status;
1846 }
29ae7f9d 1847
e0639dc5
OK
1848 copy->cp_clp = cstate->clp;
1849 memcpy(&copy->fh, &cstate->current_fh.fh_handle,
1850 sizeof(struct knfsd_fh));
1851 if (!copy->cp_synchronous) {
1852 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
29ae7f9d 1853
e0639dc5
OK
1854 status = nfserrno(-ENOMEM);
1855 async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1856 if (!async_copy)
ce0887ac
OK
1857 goto out_err;
1858 if (!nfs4_init_copy_state(nn, copy))
1859 goto out_err;
e0639dc5 1860 refcount_set(&async_copy->refcount, 1);
e739b120
OK
1861 memcpy(&copy->cp_res.cb_stateid, &copy->cp_stateid.stid,
1862 sizeof(copy->cp_res.cb_stateid));
eb162e17 1863 dup_copy_fields(copy, async_copy);
e0639dc5
OK
1864 async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
1865 async_copy, "%s", "copy thread");
1866 if (IS_ERR(async_copy->copy_task))
1867 goto out_err;
1868 spin_lock(&async_copy->cp_clp->async_lock);
1869 list_add(&async_copy->copies,
1870 &async_copy->cp_clp->async_copies);
1871 spin_unlock(&async_copy->cp_clp->async_lock);
1872 wake_up_process(async_copy->copy_task);
29ae7f9d 1873 status = nfs_ok;
ce0887ac 1874 } else {
e0639dc5 1875 status = nfsd4_do_copy(copy, 1);
ce0887ac 1876 }
29ae7f9d
AS
1877out:
1878 return status;
e0639dc5 1879out_err:
18f428d4
OK
1880 if (async_copy)
1881 cleanup_async_copy(async_copy);
ce0887ac
OK
1882 status = nfserrno(-ENOMEM);
1883 if (!copy->cp_intra)
1884 nfsd4_interssc_disconnect(copy->ss_mnt);
e0639dc5
OK
1885 goto out;
1886}
1887
1888struct nfsd4_copy *
1889find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
1890{
1891 struct nfsd4_copy *copy;
1892
1893 spin_lock(&clp->async_lock);
1894 list_for_each_entry(copy, &clp->async_copies, copies) {
ce0887ac 1895 if (memcmp(&copy->cp_stateid.stid, stateid, NFS4_STATEID_SIZE))
e0639dc5
OK
1896 continue;
1897 refcount_inc(&copy->refcount);
1898 spin_unlock(&clp->async_lock);
1899 return copy;
1900 }
1901 spin_unlock(&clp->async_lock);
1902 return NULL;
29ae7f9d
AS
1903}
1904
885e2bf3
OK
1905static __be32
1906nfsd4_offload_cancel(struct svc_rqst *rqstp,
1907 struct nfsd4_compound_state *cstate,
1908 union nfsd4_op_u *u)
1909{
e0639dc5 1910 struct nfsd4_offload_status *os = &u->offload_status;
e0639dc5
OK
1911 struct nfsd4_copy *copy;
1912 struct nfs4_client *clp = cstate->clp;
1913
1914 copy = find_async_copy(clp, &os->stateid);
ce0887ac
OK
1915 if (!copy) {
1916 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1917
1918 return manage_cpntf_state(nn, &os->stateid, clp, NULL);
1919 } else
e0639dc5 1920 nfsd4_stop_copy(copy);
e0639dc5 1921
ce0887ac 1922 return nfs_ok;
885e2bf3
OK
1923}
1924
51911868
OK
1925static __be32
1926nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1927 union nfsd4_op_u *u)
1928{
624322f1
OK
1929 struct nfsd4_copy_notify *cn = &u->copy_notify;
1930 __be32 status;
1931 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1932 struct nfs4_stid *stid;
1933 struct nfs4_cpntf_state *cps;
1934 struct nfs4_client *clp = cstate->clp;
1935
1936 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1937 &cn->cpn_src_stateid, RD_STATE, NULL,
1938 &stid);
1939 if (status)
1940 return status;
1941
1942 cn->cpn_sec = nn->nfsd4_lease;
1943 cn->cpn_nsec = 0;
1944
1945 status = nfserrno(-ENOMEM);
1946 cps = nfs4_alloc_init_cpntf_state(nn, stid);
1947 if (!cps)
1948 goto out;
1949 memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t));
1950 memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t));
1951 memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t));
1952
1953 /* For now, only return one server address in cpn_src, the
1954 * address used by the client to connect to this server.
1955 */
1956 cn->cpn_src.nl4_type = NL4_NETADDR;
1957 status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr,
1958 &cn->cpn_src.u.nl4_addr);
1959 WARN_ON_ONCE(status);
1960 if (status) {
1961 nfs4_put_cpntf_state(nn, cps);
1962 goto out;
1963 }
1964out:
1965 nfs4_put_stid(stid);
1966 return status;
51911868
OK
1967}
1968
95d871f0
AS
1969static __be32
1970nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1971 struct nfsd4_fallocate *fallocate, int flags)
1972{
0d4d6720 1973 __be32 status;
5c4583b2 1974 struct nfsd_file *nf;
95d871f0 1975
aa0d6aed 1976 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
95d871f0 1977 &fallocate->falloc_stateid,
624322f1 1978 WR_STATE, &nf, NULL);
95d871f0
AS
1979 if (status != nfs_ok) {
1980 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
1981 return status;
1982 }
1983
5c4583b2 1984 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
95d871f0
AS
1985 fallocate->falloc_offset,
1986 fallocate->falloc_length,
1987 flags);
5c4583b2 1988 nfsd_file_put(nf);
95d871f0
AS
1989 return status;
1990}
6308bc98
OK
1991static __be32
1992nfsd4_offload_status(struct svc_rqst *rqstp,
1993 struct nfsd4_compound_state *cstate,
1994 union nfsd4_op_u *u)
1995{
e0639dc5
OK
1996 struct nfsd4_offload_status *os = &u->offload_status;
1997 __be32 status = 0;
1998 struct nfsd4_copy *copy;
1999 struct nfs4_client *clp = cstate->clp;
2000
2001 copy = find_async_copy(clp, &os->stateid);
2002 if (copy) {
2003 os->count = copy->cp_res.wr_bytes_written;
2004 nfs4_put_copy(copy);
2005 } else
2006 status = nfserr_bad_stateid;
2007
2008 return status;
6308bc98 2009}
95d871f0
AS
2010
2011static __be32
2012nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 2013 union nfsd4_op_u *u)
95d871f0 2014{
eb69853d 2015 return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
95d871f0
AS
2016}
2017
b0cb9085
AS
2018static __be32
2019nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 2020 union nfsd4_op_u *u)
b0cb9085 2021{
eb69853d 2022 return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
b0cb9085
AS
2023 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
2024}
2025
24bab491
AS
2026static __be32
2027nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 2028 union nfsd4_op_u *u)
24bab491 2029{
eb69853d 2030 struct nfsd4_seek *seek = &u->seek;
24bab491
AS
2031 int whence;
2032 __be32 status;
5c4583b2 2033 struct nfsd_file *nf;
24bab491 2034
aa0d6aed 2035 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
24bab491 2036 &seek->seek_stateid,
624322f1 2037 RD_STATE, &nf, NULL);
24bab491
AS
2038 if (status) {
2039 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
2040 return status;
2041 }
2042
2043 switch (seek->seek_whence) {
2044 case NFS4_CONTENT_DATA:
2045 whence = SEEK_DATA;
2046 break;
2047 case NFS4_CONTENT_HOLE:
2048 whence = SEEK_HOLE;
2049 break;
2050 default:
2051 status = nfserr_union_notsupp;
2052 goto out;
2053 }
2054
2055 /*
2056 * Note: This call does change file->f_pos, but nothing in NFSD
2057 * should ever file->f_pos.
2058 */
5c4583b2 2059 seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
24bab491
AS
2060 if (seek->seek_pos < 0)
2061 status = nfserrno(seek->seek_pos);
5c4583b2 2062 else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
24bab491
AS
2063 seek->seek_eof = true;
2064
2065out:
5c4583b2 2066 nfsd_file_put(nf);
24bab491
AS
2067 return status;
2068}
2069
1da177e4
LT
2070/* This routine never returns NFS_OK! If there are no other errors, it
2071 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
2072 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
2073 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
2074 */
b37ad28b 2075static __be32
c954e2a5 2076_nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
ca364317 2077 struct nfsd4_verify *verify)
1da177e4 2078{
2ebbc012 2079 __be32 *buf, *p;
1da177e4 2080 int count;
b37ad28b 2081 __be32 status;
1da177e4 2082
8837abca 2083 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
1da177e4
LT
2084 if (status)
2085 return status;
2086
3c8e0316
YZ
2087 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
2088 if (status)
2089 return status;
2090
1da177e4
LT
2091 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
2092 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
2093 return nfserr_inval;
2094 if (verify->ve_attrlen & 3)
2095 return nfserr_inval;
2096
2097 /* count in words:
2098 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
2099 */
2100 count = 4 + (verify->ve_attrlen >> 2);
2101 buf = kmalloc(count << 2, GFP_KERNEL);
2102 if (!buf)
3e772463 2103 return nfserr_jukebox;
1da177e4 2104
84822d0b 2105 p = buf;
d5184658 2106 status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
ca364317 2107 cstate->current_fh.fh_export,
d5184658
BF
2108 cstate->current_fh.fh_dentry,
2109 verify->ve_bmval,
406a7ea9 2110 rqstp, 0);
41ae6e71
BF
2111 /*
2112 * If nfsd4_encode_fattr() ran out of space, assume that's because
2113 * the attributes are longer (hence different) than those given:
2114 */
84822d0b 2115 if (status == nfserr_resource)
1da177e4
LT
2116 status = nfserr_not_same;
2117 if (status)
2118 goto out_kfree;
2119
95ec28cd
BH
2120 /* skip bitmap */
2121 p = buf + 1 + ntohl(buf[0]);
1da177e4
LT
2122 status = nfserr_not_same;
2123 if (ntohl(*p++) != verify->ve_attrlen)
2124 goto out_kfree;
2125 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
2126 status = nfserr_same;
2127
2128out_kfree:
2129 kfree(buf);
2130 return status;
2131}
2132
c954e2a5
BF
2133static __be32
2134nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 2135 union nfsd4_op_u *u)
c954e2a5
BF
2136{
2137 __be32 status;
2138
eb69853d 2139 status = _nfsd4_verify(rqstp, cstate, &u->verify);
c954e2a5
BF
2140 return status == nfserr_not_same ? nfs_ok : status;
2141}
2142
2143static __be32
2144nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
eb69853d 2145 union nfsd4_op_u *u)
c954e2a5
BF
2146{
2147 __be32 status;
2148
eb69853d 2149 status = _nfsd4_verify(rqstp, cstate, &u->nverify);
c954e2a5
BF
2150 return status == nfserr_same ? nfs_ok : status;
2151}
2152
9cf514cc
CH
2153#ifdef CONFIG_NFSD_PNFS
2154static const struct nfsd4_layout_ops *
2155nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
2156{
8a4c3926 2157 if (!exp->ex_layout_types) {
9cf514cc
CH
2158 dprintk("%s: export does not support pNFS\n", __func__);
2159 return NULL;
2160 }
2161
b550a32e
AK
2162 if (layout_type >= LAYOUT_TYPE_MAX ||
2163 !(exp->ex_layout_types & (1 << layout_type))) {
9cf514cc
CH
2164 dprintk("%s: layout type %d not supported\n",
2165 __func__, layout_type);
2166 return NULL;
2167 }
2168
2169 return nfsd4_layout_ops[layout_type];
2170}
2171
2172static __be32
2173nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
eb69853d 2174 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
9cf514cc 2175{
eb69853d 2176 struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
9cf514cc
CH
2177 const struct nfsd4_layout_ops *ops;
2178 struct nfsd4_deviceid_map *map;
2179 struct svc_export *exp;
2180 __be32 nfserr;
2181
2182 dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
2183 __func__,
2184 gdp->gd_layout_type,
2185 gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
2186 gdp->gd_maxcount);
2187
2188 map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
2189 if (!map) {
2190 dprintk("%s: couldn't find device ID to export mapping!\n",
2191 __func__);
2192 return nfserr_noent;
2193 }
2194
2195 exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
2196 if (IS_ERR(exp)) {
2197 dprintk("%s: could not find device id\n", __func__);
2198 return nfserr_noent;
2199 }
2200
2201 nfserr = nfserr_layoutunavailable;
2202 ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
2203 if (!ops)
2204 goto out;
2205
2206 nfserr = nfs_ok;
f99d4fbd
CH
2207 if (gdp->gd_maxcount != 0) {
2208 nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
ec59659b 2209 rqstp, cstate->clp, gdp);
f99d4fbd 2210 }
9cf514cc
CH
2211
2212 gdp->gd_notify_types &= ops->notify_types;
9cf514cc 2213out:
a1420384 2214 exp_put(exp);
9cf514cc
CH
2215 return nfserr;
2216}
2217
34b1744c
BF
2218static void
2219nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
2220{
2221 kfree(u->getdeviceinfo.gd_device);
2222}
2223
9cf514cc
CH
2224static __be32
2225nfsd4_layoutget(struct svc_rqst *rqstp,
eb69853d 2226 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
9cf514cc 2227{
eb69853d 2228 struct nfsd4_layoutget *lgp = &u->layoutget;
9cf514cc
CH
2229 struct svc_fh *current_fh = &cstate->current_fh;
2230 const struct nfsd4_layout_ops *ops;
2231 struct nfs4_layout_stateid *ls;
2232 __be32 nfserr;
66282ec1 2233 int accmode = NFSD_MAY_READ_IF_EXEC;
9cf514cc
CH
2234
2235 switch (lgp->lg_seg.iomode) {
2236 case IOMODE_READ:
66282ec1 2237 accmode |= NFSD_MAY_READ;
9cf514cc
CH
2238 break;
2239 case IOMODE_RW:
66282ec1 2240 accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
9cf514cc
CH
2241 break;
2242 default:
2243 dprintk("%s: invalid iomode %d\n",
2244 __func__, lgp->lg_seg.iomode);
2245 nfserr = nfserr_badiomode;
2246 goto out;
2247 }
2248
2249 nfserr = fh_verify(rqstp, current_fh, 0, accmode);
2250 if (nfserr)
2251 goto out;
2252
2253 nfserr = nfserr_layoutunavailable;
2254 ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
2255 if (!ops)
2256 goto out;
2257
2258 /*
2259 * Verify minlength and range as per RFC5661:
2260 * o If loga_length is less than loga_minlength,
2261 * the metadata server MUST return NFS4ERR_INVAL.
2262 * o If the sum of loga_offset and loga_minlength exceeds
2263 * NFS4_UINT64_MAX, and loga_minlength is not
2264 * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
2265 * o If the sum of loga_offset and loga_length exceeds
2266 * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
2267 * the error NFS4ERR_INVAL MUST result.
2268 */
2269 nfserr = nfserr_inval;
2270 if (lgp->lg_seg.length < lgp->lg_minlength ||
2271 (lgp->lg_minlength != NFS4_MAX_UINT64 &&
2272 lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
2273 (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
2274 lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
2275 goto out;
2276 if (lgp->lg_seg.length == 0)
2277 goto out;
2278
2279 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
2280 true, lgp->lg_layout_type, &ls);
31ef83dc 2281 if (nfserr) {
f394b62b 2282 trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
9cf514cc 2283 goto out;
31ef83dc 2284 }
9cf514cc 2285
c5c707f9
CH
2286 nfserr = nfserr_recallconflict;
2287 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
2288 goto out_put_stid;
2289
2b0143b5 2290 nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
9cf514cc
CH
2291 current_fh, lgp);
2292 if (nfserr)
2293 goto out_put_stid;
2294
2295 nfserr = nfsd4_insert_layout(lgp, ls);
2296
2297out_put_stid:
cc8a5532 2298 mutex_unlock(&ls->ls_mutex);
9cf514cc
CH
2299 nfs4_put_stid(&ls->ls_stid);
2300out:
2301 return nfserr;
2302}
2303
34b1744c
BF
2304static void
2305nfsd4_layoutget_release(union nfsd4_op_u *u)
2306{
2307 kfree(u->layoutget.lg_content);
2308}
2309
9cf514cc
CH
2310static __be32
2311nfsd4_layoutcommit(struct svc_rqst *rqstp,
eb69853d 2312 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
9cf514cc 2313{
eb69853d 2314 struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
9cf514cc
CH
2315 const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
2316 struct svc_fh *current_fh = &cstate->current_fh;
2317 const struct nfsd4_layout_ops *ops;
2318 loff_t new_size = lcp->lc_last_wr + 1;
2319 struct inode *inode;
2320 struct nfs4_layout_stateid *ls;
2321 __be32 nfserr;
2322
2323 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
2324 if (nfserr)
2325 goto out;
2326
2327 nfserr = nfserr_layoutunavailable;
2328 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
2329 if (!ops)
2330 goto out;
2b0143b5 2331 inode = d_inode(current_fh->fh_dentry);
9cf514cc
CH
2332
2333 nfserr = nfserr_inval;
2334 if (new_size <= seg->offset) {
2335 dprintk("pnfsd: last write before layout segment\n");
2336 goto out;
2337 }
2338 if (new_size > seg->offset + seg->length) {
2339 dprintk("pnfsd: last write beyond layout segment\n");
2340 goto out;
2341 }
2342 if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
2343 dprintk("pnfsd: layoutcommit beyond EOF\n");
2344 goto out;
2345 }
2346
2347 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
2348 false, lcp->lc_layout_type,
2349 &ls);
2350 if (nfserr) {
f394b62b 2351 trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
9cf514cc
CH
2352 /* fixup error code as per RFC5661 */
2353 if (nfserr == nfserr_bad_stateid)
2354 nfserr = nfserr_badlayout;
2355 goto out;
2356 }
2357
cc8a5532
JL
2358 /* LAYOUTCOMMIT does not require any serialization */
2359 mutex_unlock(&ls->ls_mutex);
2360
9cf514cc
CH
2361 if (new_size > i_size_read(inode)) {
2362 lcp->lc_size_chg = 1;
2363 lcp->lc_newsize = new_size;
2364 } else {
2365 lcp->lc_size_chg = 0;
2366 }
2367
d8398fc1 2368 nfserr = ops->proc_layoutcommit(inode, lcp);
9cf514cc
CH
2369 nfs4_put_stid(&ls->ls_stid);
2370out:
2371 return nfserr;
2372}
2373
2374static __be32
2375nfsd4_layoutreturn(struct svc_rqst *rqstp,
eb69853d 2376 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
9cf514cc 2377{
eb69853d 2378 struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
9cf514cc
CH
2379 struct svc_fh *current_fh = &cstate->current_fh;
2380 __be32 nfserr;
2381
2382 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
2383 if (nfserr)
2384 goto out;
2385
2386 nfserr = nfserr_layoutunavailable;
2387 if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
2388 goto out;
2389
2390 switch (lrp->lr_seg.iomode) {
2391 case IOMODE_READ:
2392 case IOMODE_RW:
2393 case IOMODE_ANY:
2394 break;
2395 default:
2396 dprintk("%s: invalid iomode %d\n", __func__,
2397 lrp->lr_seg.iomode);
2398 nfserr = nfserr_inval;
2399 goto out;
2400 }
2401
2402 switch (lrp->lr_return_type) {
2403 case RETURN_FILE:
2404 nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
2405 break;
2406 case RETURN_FSID:
2407 case RETURN_ALL:
2408 nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
2409 break;
2410 default:
2411 dprintk("%s: invalid return_type %d\n", __func__,
2412 lrp->lr_return_type);
2413 nfserr = nfserr_inval;
2414 break;
2415 }
2416out:
2417 return nfserr;
2418}
2419#endif /* CONFIG_NFSD_PNFS */
2420
23e50fe3
FL
2421static __be32
2422nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2423 union nfsd4_op_u *u)
2424{
2425 struct nfsd4_getxattr *getxattr = &u->getxattr;
2426
2427 return nfsd_getxattr(rqstp, &cstate->current_fh,
2428 getxattr->getxa_name, &getxattr->getxa_buf,
2429 &getxattr->getxa_len);
2430}
2431
2432static __be32
2433nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2434 union nfsd4_op_u *u)
2435{
2436 struct nfsd4_setxattr *setxattr = &u->setxattr;
2437 __be32 ret;
2438
2439 if (opens_in_grace(SVC_NET(rqstp)))
2440 return nfserr_grace;
2441
2442 ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
2443 setxattr->setxa_buf, setxattr->setxa_len,
2444 setxattr->setxa_flags);
2445
2446 if (!ret)
2447 set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
2448
2449 return ret;
2450}
2451
2452static __be32
2453nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2454 union nfsd4_op_u *u)
2455{
2456 /*
2457 * Get the entire list, then copy out only the user attributes
2458 * in the encode function.
2459 */
2460 return nfsd_listxattr(rqstp, &cstate->current_fh,
2461 &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
2462}
2463
2464static __be32
2465nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2466 union nfsd4_op_u *u)
2467{
2468 struct nfsd4_removexattr *removexattr = &u->removexattr;
2469 __be32 ret;
2470
2471 if (opens_in_grace(SVC_NET(rqstp)))
2472 return nfserr_grace;
2473
2474 ret = nfsd_removexattr(rqstp, &cstate->current_fh,
2475 removexattr->rmxa_name);
2476
2477 if (!ret)
2478 set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
2479
2480 return ret;
2481}
2482
1da177e4
LT
2483/*
2484 * NULL call.
2485 */
7111c66e 2486static __be32
a6beb732 2487nfsd4_proc_null(struct svc_rqst *rqstp)
1da177e4 2488{
cc028a10 2489 return rpc_success;
1da177e4
LT
2490}
2491
e2b20950
SA
2492static inline void nfsd4_increment_op_stats(u32 opnum)
2493{
2494 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
e567b98c 2495 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]);
e2b20950
SA
2496}
2497
bb2a8b0c 2498static const struct nfsd4_operation nfsd4_ops[];
b591480b 2499
f1c7f79b 2500static const char *nfsd4_op_name(unsigned opnum);
b001a1b6 2501
f9bb94c4 2502/*
57716355 2503 * Enforce NFSv4.1 COMPOUND ordering rules:
f9bb94c4 2504 *
57716355
BF
2505 * Also note, enforced elsewhere:
2506 * - SEQUENCE other than as first op results in
2507 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
1d1bc8f2
BF
2508 * - BIND_CONN_TO_SESSION must be the only op in its compound.
2509 * (Enforced in nfsd4_bind_conn_to_session().)
57716355
BF
2510 * - DESTROY_SESSION must be the final operation in a compound, if
2511 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
2512 * (Enforced in nfsd4_destroy_session().)
f9bb94c4 2513 */
57716355 2514static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
f9bb94c4 2515{
7a04cfda 2516 struct nfsd4_op *first_op = &args->ops[0];
57716355
BF
2517
2518 /* These ordering requirements don't apply to NFSv4.0: */
2519 if (args->minorversion == 0)
2520 return nfs_ok;
2521 /* This is weird, but OK, not our problem: */
2522 if (args->opcnt == 0)
2523 return nfs_ok;
7a04cfda 2524 if (first_op->status == nfserr_op_illegal)
57716355 2525 return nfs_ok;
7a04cfda 2526 if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
57716355 2527 return nfserr_op_not_in_session;
7a04cfda 2528 if (first_op->opnum == OP_SEQUENCE)
57716355 2529 return nfs_ok;
7a04cfda
BF
2530 /*
2531 * So first_op is something allowed outside a session, like
2532 * EXCHANGE_ID; but then it has to be the only op in the
2533 * compound:
2534 */
57716355
BF
2535 if (args->opcnt != 1)
2536 return nfserr_not_only_op;
2537 return nfs_ok;
f9bb94c4
AA
2538}
2539
f4f9ef4a 2540const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
22b03214
BF
2541{
2542 return &nfsd4_ops[op->opnum];
2543}
2544
1091006c
BF
2545bool nfsd4_cache_this_op(struct nfsd4_op *op)
2546{
e372ba60
BF
2547 if (op->opnum == OP_ILLEGAL)
2548 return false;
c856694e 2549 return OPDESC(op)->op_flags & OP_CACHEME;
1091006c
BF
2550}
2551
68d93184
BF
2552static bool need_wrongsec_check(struct svc_rqst *rqstp)
2553{
2554 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2555 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2556 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2557 struct nfsd4_op *next = &argp->ops[resp->opcnt];
bb2a8b0c
CH
2558 const struct nfsd4_operation *thisd = OPDESC(this);
2559 const struct nfsd4_operation *nextd;
68d93184 2560
68d93184
BF
2561 /*
2562 * Most ops check wronsec on our own; only the putfh-like ops
2563 * have special rules.
2564 */
2565 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
2566 return false;
2567 /*
2568 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
2569 * put-filehandle operation if we're not going to use the
2570 * result:
2571 */
2572 if (argp->opcnt == resp->opcnt)
2573 return false;
51904b08
BF
2574 if (next->opnum == OP_ILLEGAL)
2575 return false;
68d93184
BF
2576 nextd = OPDESC(next);
2577 /*
2578 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
2579 * errors themselves as necessary; others should check for them
2580 * now:
2581 */
2582 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
2583}
2584
b9e8638e
OK
2585#ifdef CONFIG_NFSD_V4_2_INTER_SSC
2586static void
2587check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2588{
2589 struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL;
2590 struct nfsd4_copy *copy;
2591 struct nfsd4_putfh *putfh;
2592 int i;
2593
2594 /* traverse all operation and if it's a COPY compound, mark the
2595 * source filehandle to skip verification
2596 */
2597 for (i = 0; i < args->opcnt; i++) {
2598 op = &args->ops[i];
2599 if (op->opnum == OP_PUTFH)
2600 current_op = op;
2601 else if (op->opnum == OP_SAVEFH)
2602 saved_op = current_op;
2603 else if (op->opnum == OP_RESTOREFH)
2604 current_op = saved_op;
2605 else if (op->opnum == OP_COPY) {
2606 copy = (struct nfsd4_copy *)&op->u;
2607 if (!saved_op) {
2608 op->status = nfserr_nofilehandle;
2609 return;
2610 }
2611 putfh = (struct nfsd4_putfh *)&saved_op->u;
2612 if (!copy->cp_intra)
2613 putfh->no_verify = true;
2614 }
2615 }
2616}
2617#else
2618static void
2619check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2620{
2621}
2622#endif
2623
1da177e4
LT
2624/*
2625 * COMPOUND call.
2626 */
7111c66e 2627static __be32
a6beb732 2628nfsd4_proc_compound(struct svc_rqst *rqstp)
1da177e4 2629{
a6beb732
CH
2630 struct nfsd4_compoundargs *args = rqstp->rq_argp;
2631 struct nfsd4_compoundres *resp = rqstp->rq_resp;
1da177e4 2632 struct nfsd4_op *op;
e354d571 2633 struct nfsd4_compound_state *cstate = &resp->cstate;
4daeed25
KM
2634 struct svc_fh *current_fh = &cstate->current_fh;
2635 struct svc_fh *save_fh = &cstate->save_fh;
e333f3bb 2636 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
b37ad28b 2637 __be32 status;
1da177e4 2638
bddfdbcd 2639 resp->xdr = &rqstp->rq_res_stream;
3b0ebb25 2640 resp->statusp = resp->xdr->p;
bddfdbcd
CL
2641
2642 /* reserve space for: NFS status code */
2643 xdr_reserve_space(resp->xdr, XDR_UNIT);
2644
1da177e4 2645 /* reserve space for: taglen, tag, and opcnt */
bddfdbcd 2646 xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
1da177e4
LT
2647 resp->taglen = args->taglen;
2648 resp->tag = args->tag;
1da177e4 2649 resp->rqstp = rqstp;
4daeed25 2650 cstate->minorversion = args->minorversion;
4daeed25
KM
2651 fh_init(current_fh, NFS4_FHSIZE);
2652 fh_init(save_fh, NFS4_FHSIZE);
28df0988 2653
8ff30fa4
N
2654 /*
2655 * Don't use the deferral mechanism for NFSv4; compounds make it
2656 * too hard to avoid non-idempotency problems.
2657 */
28df0988 2658 __clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
1da177e4
LT
2659
2660 /*
2661 * According to RFC3010, this takes precedence over all other errors.
2662 */
2663 status = nfserr_minor_vers_mismatch;
e333f3bb 2664 if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
1da177e4 2665 goto out;
0078117c
BF
2666 status = nfserr_resource;
2667 if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
2668 goto out;
1da177e4 2669
57716355
BF
2670 status = nfs41_check_op_ordering(args);
2671 if (status) {
f9bb94c4 2672 op = &args->ops[0];
57716355 2673 op->status = status;
5b7b15ae 2674 resp->opcnt = 1;
f9bb94c4
AA
2675 goto encode_op;
2676 }
b9e8638e 2677 check_if_stalefh_allowed(args);
f9bb94c4 2678
28df3d15
BF
2679 rqstp->rq_lease_breaker = (void **)&cstate->clp;
2680
fff4080b 2681 trace_nfsd_compound(rqstp, args->opcnt);
1da177e4
LT
2682 while (!status && resp->opcnt < args->opcnt) {
2683 op = &args->ops[resp->opcnt++];
2684
2685 /*
2686 * The XDR decode routines may have pre-set op->status;
2687 * for example, if there is a miscellaneous XDR error
2688 * it will be set to nfserr_bad_xdr.
2689 */
9d313b17
BF
2690 if (op->status) {
2691 if (op->opnum == OP_OPEN)
2692 op->status = nfsd4_open_omfg(rqstp, cstate, op);
1da177e4 2693 goto encode_op;
9d313b17 2694 }
b9e8638e
OK
2695 if (!current_fh->fh_dentry &&
2696 !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) {
f4f9ef4a 2697 if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
42ca0993
BF
2698 op->status = nfserr_nofilehandle;
2699 goto encode_op;
2700 }
b9e8638e
OK
2701 } else if (current_fh->fh_export &&
2702 current_fh->fh_export->ex_fslocs.migrated &&
f4f9ef4a 2703 !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
42ca0993 2704 op->status = nfserr_moved;
1da177e4
LT
2705 goto encode_op;
2706 }
b591480b 2707
fcb5e3fa 2708 fh_clear_pre_post_attrs(current_fh);
2336745e 2709
58e7b33a 2710 /* If op is non-idempotent */
f4f9ef4a 2711 if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
4c69d585 2712 /*
a8095f7e 2713 * Don't execute this op if we couldn't encode a
f532c9ff 2714 * successful reply:
a8095f7e 2715 */
f4f9ef4a 2716 u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
a8095f7e
BF
2717 /*
2718 * Plus if there's another operation, make sure
4c69d585
BF
2719 * we'll have space to at least encode an error:
2720 */
2721 if (resp->opcnt < args->opcnt)
2722 plen += COMPOUND_ERR_SLACK_SPACE;
58e7b33a
MJ
2723 op->status = nfsd4_check_resp_size(resp, plen);
2724 }
2725
2726 if (op->status)
2727 goto encode_op;
2728
f4f9ef4a
BF
2729 if (op->opdesc->op_get_currentstateid)
2730 op->opdesc->op_get_currentstateid(cstate, &op->u);
2731 op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
1da177e4 2732
9a307403
BF
2733 /* Only from SEQUENCE */
2734 if (cstate->status == nfserr_replay_cache) {
2735 dprintk("%s NFS4.1 replay from cache\n", __func__);
2736 status = op->status;
2737 goto out;
2738 }
8b70484c 2739 if (!op->status) {
f4f9ef4a
BF
2740 if (op->opdesc->op_set_currentstateid)
2741 op->opdesc->op_set_currentstateid(cstate, &op->u);
8b70484c 2742
f4f9ef4a 2743 if (op->opdesc->op_flags & OP_CLEAR_STATEID)
37c593c5 2744 clear_current_stateid(cstate);
8b70484c 2745
d781e3df
BF
2746 if (current_fh->fh_export &&
2747 need_wrongsec_check(rqstp))
4daeed25 2748 op->status = check_nfsd_access(current_fh->fh_export, rqstp);
8b70484c 2749 }
1da177e4 2750encode_op:
a90b061c 2751 if (op->status == nfserr_replay_me) {
a4f1706a 2752 op->replay = &cstate->replay_owner->so_replay;
bddfdbcd 2753 nfsd4_encode_replay(resp->xdr, op);
1da177e4
LT
2754 status = op->status = op->replay->rp_status;
2755 } else {
2756 nfsd4_encode_operation(resp, op);
2757 status = op->status;
2758 }
0407717d 2759
fff4080b
CL
2760 trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
2761 nfsd4_op_name(op->opnum));
0407717d 2762
58fb12e6 2763 nfsd4_cstate_clear_replay(cstate);
e2b20950 2764 nfsd4_increment_op_stats(op->opnum);
1da177e4
LT
2765 }
2766
4daeed25
KM
2767 fh_put(current_fh);
2768 fh_put(save_fh);
2769 BUG_ON(cstate->replay_owner);
1da177e4 2770out:
cc028a10 2771 cstate->status = status;
2f425878 2772 /* Reset deferral mechanism for RPC deferrals */
28df0988 2773 __set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
cc028a10 2774 return rpc_success;
1da177e4
LT
2775}
2776
58e7b33a
MJ
2777#define op_encode_hdr_size (2)
2778#define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
2779#define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
2780#define op_encode_change_info_maxsz (5)
2781#define nfs4_fattr_bitmap_maxsz (4)
2782
8c7424cf
BF
2783/* We'll fall back on returning no lockowner if run out of space: */
2784#define op_encode_lockowner_maxsz (0)
58e7b33a
MJ
2785#define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
2786
2787#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
2788
2789#define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
2790#define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
2791 op_encode_ace_maxsz)
2792
2793#define op_encode_channel_attrs_maxsz (6 + 1 + 1)
2794
2795static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2796{
2797 return (op_encode_hdr_size) * sizeof(__be32);
2798}
2799
2800static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2801{
2802 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
2803}
2804
2282cd2c
KM
2805static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2806{
2807 /* ac_supported, ac_resp_access */
2808 return (op_encode_hdr_size + 2)* sizeof(__be32);
2809}
2810
58e7b33a
MJ
2811static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2812{
2813 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
2814}
2815
2816static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2817{
2818 return (op_encode_hdr_size + op_encode_change_info_maxsz
2819 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2820}
2821
b86cef60
BF
2822/*
2823 * Note since this is an idempotent operation we won't insist on failing
2824 * the op prematurely if the estimate is too large. We may turn off splice
2825 * reads unnecessarily.
2826 */
2827static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
2828 struct nfsd4_op *op)
2829{
2830 u32 *bmap = op->u.getattr.ga_bmval;
2831 u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
2832 u32 ret = 0;
2833
2834 if (bmap0 & FATTR4_WORD0_ACL)
2835 return svc_max_payload(rqstp);
2836 if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
2837 return svc_max_payload(rqstp);
2838
2839 if (bmap1 & FATTR4_WORD1_OWNER) {
2840 ret += IDMAP_NAMESZ + 4;
2841 bmap1 &= ~FATTR4_WORD1_OWNER;
2842 }
2843 if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
2844 ret += IDMAP_NAMESZ + 4;
2845 bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
2846 }
2847 if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
2848 ret += NFS4_FHSIZE + 4;
2849 bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
2850 }
2851 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
1ec8c0c4 2852 ret += NFS4_MAXLABELLEN + 12;
b86cef60
BF
2853 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2854 }
2855 /*
2856 * Largest of remaining attributes are 16 bytes (e.g.,
2857 * supported_attributes)
2858 */
2859 ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
2860 /* bitmask, length */
2861 ret += 20;
2862 return ret;
2863}
2864
2282cd2c
KM
2865static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2866{
2867 return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
2868}
2869
58e7b33a
MJ
2870static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2871{
2872 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2873 * sizeof(__be32);
2874}
2875
2876static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2877{
2878 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
2879 * sizeof(__be32);
2880}
2881
2882static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2883{
2884 return (op_encode_hdr_size + op_encode_stateid_maxsz
2885 + op_encode_change_info_maxsz + 1
2886 + nfs4_fattr_bitmap_maxsz
2887 + op_encode_delegation_maxsz) * sizeof(__be32);
2888}
2889
2890static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2891{
2892 u32 maxcount = 0, rlen = 0;
2893
2894 maxcount = svc_max_payload(rqstp);
3c7aa15d 2895 rlen = min(op->u.read.rd_length, maxcount);
58e7b33a 2896
622f560e 2897 return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
58e7b33a
MJ
2898}
2899
528b8493
AS
2900static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2901{
2902 u32 maxcount = svc_max_payload(rqstp);
2903 u32 rlen = min(op->u.read.rd_length, maxcount);
2904 /*
2905 * If we detect that the file changed during hole encoding, then we
2906 * recover by encoding the remaining reply as data. This means we need
2907 * to set aside enough room to encode two data segments.
2908 */
2909 u32 seg_len = 2 * (1 + 2 + 1);
2910
2911 return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32);
2912}
2913
58e7b33a
MJ
2914static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2915{
3c7aa15d 2916 u32 maxcount = 0, rlen = 0;
58e7b33a 2917
3c7aa15d
KM
2918 maxcount = svc_max_payload(rqstp);
2919 rlen = min(op->u.readdir.rd_maxcount, maxcount);
58e7b33a 2920
561f0ed4
BF
2921 return (op_encode_hdr_size + op_encode_verifier_maxsz +
2922 XDR_QUADLEN(rlen)) * sizeof(__be32);
58e7b33a
MJ
2923}
2924
2282cd2c
KM
2925static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2926{
2927 return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
2928}
2929
58e7b33a
MJ
2930static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2931{
2932 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2933 * sizeof(__be32);
2934}
2935
2936static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2937{
2938 return (op_encode_hdr_size + op_encode_change_info_maxsz
2939 + op_encode_change_info_maxsz) * sizeof(__be32);
2940}
2941
ccae70a9
BF
2942static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
2943 struct nfsd4_op *op)
2944{
d1d84c96
BF
2945 return (op_encode_hdr_size
2946 + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
ccae70a9
BF
2947}
2948
2282cd2c
KM
2949static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2950{
2951 return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
2952 * sizeof(__be32);
2953}
2954
58e7b33a
MJ
2955static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2956{
2957 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2958}
2959
2282cd2c
KM
2960static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2961{
2962 return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
2963 (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
2964}
2965
58e7b33a
MJ
2966static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2967{
480efaee
BF
2968 return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2969 sizeof(__be32);
58e7b33a
MJ
2970}
2971
2972static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2973{
f34e432b 2974 return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
58e7b33a
MJ
2975}
2976
2977static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2978{
2979 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
a8bb84bc
KM
2980 1 + 1 + /* eir_flags, spr_how */\
2981 4 + /* spo_must_enforce & _allow with bitmap */\
58e7b33a
MJ
2982 2 + /*eir_server_owner.so_minor_id */\
2983 /* eir_server_owner.so_major_id<> */\
2984 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2985 /* eir_server_scope<> */\
2986 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2987 1 + /* eir_server_impl_id array length */\
2988 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
2989}
2990
2991static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2992{
2993 return (op_encode_hdr_size + \
2994 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
2995 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
2996}
2997
2998static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2999{
3000 return (op_encode_hdr_size + \
3001 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
3002 2 + /* csr_sequence, csr_flags */\
3003 op_encode_channel_attrs_maxsz + \
3004 op_encode_channel_attrs_maxsz) * sizeof(__be32);
3005}
3006
29ae7f9d
AS
3007static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3008{
3009 return (op_encode_hdr_size +
3010 1 /* wr_callback */ +
3011 op_encode_stateid_maxsz /* wr_callback */ +
3012 2 /* wr_count */ +
3013 1 /* wr_committed */ +
3014 op_encode_verifier_maxsz +
3015 1 /* cr_consecutive */ +
3016 1 /* cr_synchronous */) * sizeof(__be32);
3017}
3018
6308bc98
OK
3019static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
3020 struct nfsd4_op *op)
3021{
3022 return (op_encode_hdr_size +
3023 2 /* osr_count */ +
3024 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
3025}
3026
51911868
OK
3027static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp,
3028 struct nfsd4_op *op)
3029{
3030 return (op_encode_hdr_size +
3031 3 /* cnr_lease_time */ +
3032 1 /* We support one cnr_source_server */ +
3033 1 /* cnr_stateid seq */ +
3034 op_encode_stateid_maxsz /* cnr_stateid */ +
3035 1 /* num cnr_source_server*/ +
3036 1 /* nl4_type */ +
3037 1 /* nl4 size */ +
3038 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */)
3039 * sizeof(__be32);
3040}
3041
9cf514cc 3042#ifdef CONFIG_NFSD_PNFS
2282cd2c
KM
3043static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3044{
3045 u32 maxcount = 0, rlen = 0;
3046
3047 maxcount = svc_max_payload(rqstp);
3048 rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
3049
3050 return (op_encode_hdr_size +
3051 1 /* gd_layout_type*/ +
3052 XDR_QUADLEN(rlen) +
3053 2 /* gd_notify_types */) * sizeof(__be32);
3054}
3055
9cf514cc
CH
3056/*
3057 * At this stage we don't really know what layout driver will handle the request,
3058 * so we need to define an arbitrary upper bound here.
3059 */
3060#define MAX_LAYOUT_SIZE 128
3061static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3062{
3063 return (op_encode_hdr_size +
3064 1 /* logr_return_on_close */ +
3065 op_encode_stateid_maxsz +
3066 1 /* nr of layouts */ +
3067 MAX_LAYOUT_SIZE) * sizeof(__be32);
3068}
3069
3070static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3071{
3072 return (op_encode_hdr_size +
3073 1 /* locr_newsize */ +
3074 2 /* ns_size */) * sizeof(__be32);
3075}
3076
3077static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3078{
3079 return (op_encode_hdr_size +
3080 1 /* lrs_stateid */ +
3081 op_encode_stateid_maxsz) * sizeof(__be32);
3082}
3083#endif /* CONFIG_NFSD_PNFS */
3084
2282cd2c
KM
3085
3086static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3087{
3088 return (op_encode_hdr_size + 3) * sizeof(__be32);
3089}
3090
23e50fe3
FL
3091static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp,
3092 struct nfsd4_op *op)
3093{
3094 u32 maxcount, rlen;
3095
3096 maxcount = svc_max_payload(rqstp);
3097 rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
3098
3099 return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3100}
3101
3102static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp,
3103 struct nfsd4_op *op)
3104{
3105 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3106 * sizeof(__be32);
3107}
3108static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp,
3109 struct nfsd4_op *op)
3110{
3111 u32 maxcount, rlen;
3112
3113 maxcount = svc_max_payload(rqstp);
3114 rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
3115
3116 return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3117}
3118
3119static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp,
3120 struct nfsd4_op *op)
3121{
3122 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3123 * sizeof(__be32);
3124}
3125
3126
bb2a8b0c 3127static const struct nfsd4_operation nfsd4_ops[] = {
b591480b 3128 [OP_ACCESS] = {
eb69853d 3129 .op_func = nfsd4_access,
b001a1b6 3130 .op_name = "OP_ACCESS",
1c122638 3131 .op_rsize_bop = nfsd4_access_rsize,
b591480b
BF
3132 },
3133 [OP_CLOSE] = {
eb69853d 3134 .op_func = nfsd4_close,
58e7b33a 3135 .op_flags = OP_MODIFIES_SOMETHING,
b001a1b6 3136 .op_name = "OP_CLOSE",
1c122638 3137 .op_rsize_bop = nfsd4_status_stateid_rsize,
57832e7b 3138 .op_get_currentstateid = nfsd4_get_closestateid,
b60e9859 3139 .op_set_currentstateid = nfsd4_set_closestateid,
b591480b
BF
3140 },
3141 [OP_COMMIT] = {
eb69853d 3142 .op_func = nfsd4_commit,
58e7b33a 3143 .op_flags = OP_MODIFIES_SOMETHING,
b001a1b6 3144 .op_name = "OP_COMMIT",
1c122638 3145 .op_rsize_bop = nfsd4_commit_rsize,
b591480b
BF
3146 },
3147 [OP_CREATE] = {
eb69853d 3148 .op_func = nfsd4_create,
d1471053 3149 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
b001a1b6 3150 .op_name = "OP_CREATE",
1c122638 3151 .op_rsize_bop = nfsd4_create_rsize,
b591480b
BF
3152 },
3153 [OP_DELEGRETURN] = {
eb69853d 3154 .op_func = nfsd4_delegreturn,
58e7b33a 3155 .op_flags = OP_MODIFIES_SOMETHING,
b001a1b6 3156 .op_name = "OP_DELEGRETURN",
58e7b33a 3157 .op_rsize_bop = nfsd4_only_status_rsize,
57832e7b 3158 .op_get_currentstateid = nfsd4_get_delegreturnstateid,
b591480b
BF
3159 },
3160 [OP_GETATTR] = {
eb69853d 3161 .op_func = nfsd4_getattr,
eeac294e 3162 .op_flags = ALLOWED_ON_ABSENT_FS,
b86cef60 3163 .op_rsize_bop = nfsd4_getattr_rsize,
b001a1b6 3164 .op_name = "OP_GETATTR",
b591480b
BF
3165 },
3166 [OP_GETFH] = {
eb69853d 3167 .op_func = nfsd4_getfh,
b001a1b6 3168 .op_name = "OP_GETFH",
1c122638 3169 .op_rsize_bop = nfsd4_getfh_rsize,
b591480b
BF
3170 },
3171 [OP_LINK] = {
eb69853d 3172 .op_func = nfsd4_link,
c856694e
BF
3173 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
3174 | OP_CACHEME,
b001a1b6 3175 .op_name = "OP_LINK",
1c122638 3176 .op_rsize_bop = nfsd4_link_rsize,
b591480b
BF
3177 },
3178 [OP_LOCK] = {
eb69853d 3179 .op_func = nfsd4_lock,
b7571e4c
BF
3180 .op_flags = OP_MODIFIES_SOMETHING |
3181 OP_NONTRIVIAL_ERROR_ENCODE,
b001a1b6 3182 .op_name = "OP_LOCK",
1c122638 3183 .op_rsize_bop = nfsd4_lock_rsize,
b60e9859 3184 .op_set_currentstateid = nfsd4_set_lockstateid,
b591480b
BF
3185 },
3186 [OP_LOCKT] = {
eb69853d 3187 .op_func = nfsd4_lockt,
b7571e4c 3188 .op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
b001a1b6 3189 .op_name = "OP_LOCKT",
1c122638 3190 .op_rsize_bop = nfsd4_lock_rsize,
b591480b
BF
3191 },
3192 [OP_LOCKU] = {
eb69853d 3193 .op_func = nfsd4_locku,
58e7b33a 3194 .op_flags = OP_MODIFIES_SOMETHING,
b001a1b6 3195 .op_name = "OP_LOCKU",
1c122638 3196 .op_rsize_bop = nfsd4_status_stateid_rsize,
57832e7b 3197 .op_get_currentstateid = nfsd4_get_lockustateid,
b591480b
BF
3198 },
3199 [OP_LOOKUP] = {
eb69853d 3200 .op_func = nfsd4_lookup,
d1471053 3201 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
b001a1b6 3202 .op_name = "OP_LOOKUP",
1c122638 3203 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3204 },
3205 [OP_LOOKUPP] = {
eb69853d 3206 .op_func = nfsd4_lookupp,
d1471053 3207 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
b001a1b6 3208 .op_name = "OP_LOOKUPP",
1c122638 3209 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3210 },
3211 [OP_NVERIFY] = {
eb69853d 3212 .op_func = nfsd4_nverify,
b001a1b6 3213 .op_name = "OP_NVERIFY",
1c122638 3214 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3215 },
3216 [OP_OPEN] = {
eb69853d 3217 .op_func = nfsd4_open,
58e7b33a 3218 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
b001a1b6 3219 .op_name = "OP_OPEN",
1c122638 3220 .op_rsize_bop = nfsd4_open_rsize,
b60e9859 3221 .op_set_currentstateid = nfsd4_set_openstateid,
b591480b
BF
3222 },
3223 [OP_OPEN_CONFIRM] = {
eb69853d 3224 .op_func = nfsd4_open_confirm,
58e7b33a 3225 .op_flags = OP_MODIFIES_SOMETHING,
b001a1b6 3226 .op_name = "OP_OPEN_CONFIRM",
1c122638 3227 .op_rsize_bop = nfsd4_status_stateid_rsize,
b591480b
BF
3228 },
3229 [OP_OPEN_DOWNGRADE] = {
eb69853d 3230 .op_func = nfsd4_open_downgrade,
58e7b33a 3231 .op_flags = OP_MODIFIES_SOMETHING,
b001a1b6 3232 .op_name = "OP_OPEN_DOWNGRADE",
1c122638 3233 .op_rsize_bop = nfsd4_status_stateid_rsize,
57832e7b 3234 .op_get_currentstateid = nfsd4_get_opendowngradestateid,
b60e9859 3235 .op_set_currentstateid = nfsd4_set_opendowngradestateid,
b591480b
BF
3236 },
3237 [OP_PUTFH] = {
eb69853d 3238 .op_func = nfsd4_putfh,
68d93184 3239 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
5b648699 3240 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
b001a1b6 3241 .op_name = "OP_PUTFH",
1c122638 3242 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b 3243 },
eeac294e 3244 [OP_PUTPUBFH] = {
eb69853d 3245 .op_func = nfsd4_putrootfh,
68d93184 3246 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
5b648699 3247 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
b001a1b6 3248 .op_name = "OP_PUTPUBFH",
1c122638 3249 .op_rsize_bop = nfsd4_only_status_rsize,
eeac294e 3250 },
b591480b 3251 [OP_PUTROOTFH] = {
eb69853d 3252 .op_func = nfsd4_putrootfh,
68d93184 3253 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
5b648699 3254 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
b001a1b6 3255 .op_name = "OP_PUTROOTFH",
1c122638 3256 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3257 },
3258 [OP_READ] = {
eb69853d 3259 .op_func = nfsd4_read,
34b1744c 3260 .op_release = nfsd4_read_release,
b001a1b6 3261 .op_name = "OP_READ",
1c122638 3262 .op_rsize_bop = nfsd4_read_rsize,
57832e7b 3263 .op_get_currentstateid = nfsd4_get_readstateid,
b591480b
BF
3264 },
3265 [OP_READDIR] = {
eb69853d 3266 .op_func = nfsd4_readdir,
b001a1b6 3267 .op_name = "OP_READDIR",
1c122638 3268 .op_rsize_bop = nfsd4_readdir_rsize,
b591480b
BF
3269 },
3270 [OP_READLINK] = {
eb69853d 3271 .op_func = nfsd4_readlink,
b001a1b6 3272 .op_name = "OP_READLINK",
1c122638 3273 .op_rsize_bop = nfsd4_readlink_rsize,
b591480b
BF
3274 },
3275 [OP_REMOVE] = {
eb69853d 3276 .op_func = nfsd4_remove,
c856694e 3277 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
b001a1b6 3278 .op_name = "OP_REMOVE",
1c122638 3279 .op_rsize_bop = nfsd4_remove_rsize,
b591480b
BF
3280 },
3281 [OP_RENAME] = {
eb69853d 3282 .op_func = nfsd4_rename,
c856694e 3283 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
58e7b33a 3284 .op_name = "OP_RENAME",
1c122638 3285 .op_rsize_bop = nfsd4_rename_rsize,
b591480b
BF
3286 },
3287 [OP_RENEW] = {
eb69853d 3288 .op_func = nfsd4_renew,
58e7b33a
MJ
3289 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3290 | OP_MODIFIES_SOMETHING,
b001a1b6 3291 .op_name = "OP_RENEW",
1c122638 3292 .op_rsize_bop = nfsd4_only_status_rsize,
58e7b33a 3293
b591480b
BF
3294 },
3295 [OP_RESTOREFH] = {
eb69853d 3296 .op_func = nfsd4_restorefh,
68d93184 3297 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
58e7b33a 3298 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
b001a1b6 3299 .op_name = "OP_RESTOREFH",
1c122638 3300 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3301 },
3302 [OP_SAVEFH] = {
eb69853d 3303 .op_func = nfsd4_savefh,
58e7b33a 3304 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
b001a1b6 3305 .op_name = "OP_SAVEFH",
1c122638 3306 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b 3307 },
dcb488a3 3308 [OP_SECINFO] = {
eb69853d 3309 .op_func = nfsd4_secinfo,
34b1744c 3310 .op_release = nfsd4_secinfo_release,
68d93184 3311 .op_flags = OP_HANDLES_WRONGSEC,
b001a1b6 3312 .op_name = "OP_SECINFO",
1c122638 3313 .op_rsize_bop = nfsd4_secinfo_rsize,
dcb488a3 3314 },
b591480b 3315 [OP_SETATTR] = {
eb69853d 3316 .op_func = nfsd4_setattr,
b001a1b6 3317 .op_name = "OP_SETATTR",
b7571e4c
BF
3318 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
3319 | OP_NONTRIVIAL_ERROR_ENCODE,
1c122638 3320 .op_rsize_bop = nfsd4_setattr_rsize,
57832e7b 3321 .op_get_currentstateid = nfsd4_get_setattrstateid,
b591480b
BF
3322 },
3323 [OP_SETCLIENTID] = {
eb69853d 3324 .op_func = nfsd4_setclientid,
58e7b33a 3325 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
b7571e4c
BF
3326 | OP_MODIFIES_SOMETHING | OP_CACHEME
3327 | OP_NONTRIVIAL_ERROR_ENCODE,
b001a1b6 3328 .op_name = "OP_SETCLIENTID",
1c122638 3329 .op_rsize_bop = nfsd4_setclientid_rsize,
b591480b
BF
3330 },
3331 [OP_SETCLIENTID_CONFIRM] = {
eb69853d 3332 .op_func = nfsd4_setclientid_confirm,
58e7b33a 3333 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
c856694e 3334 | OP_MODIFIES_SOMETHING | OP_CACHEME,
b001a1b6 3335 .op_name = "OP_SETCLIENTID_CONFIRM",
1c122638 3336 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3337 },
3338 [OP_VERIFY] = {
eb69853d 3339 .op_func = nfsd4_verify,
b001a1b6 3340 .op_name = "OP_VERIFY",
1c122638 3341 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b
BF
3342 },
3343 [OP_WRITE] = {
eb69853d 3344 .op_func = nfsd4_write,
c856694e 3345 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
b001a1b6 3346 .op_name = "OP_WRITE",
1c122638 3347 .op_rsize_bop = nfsd4_write_rsize,
57832e7b 3348 .op_get_currentstateid = nfsd4_get_writestateid,
b591480b
BF
3349 },
3350 [OP_RELEASE_LOCKOWNER] = {
eb69853d 3351 .op_func = nfsd4_release_lockowner,
58e7b33a
MJ
3352 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3353 | OP_MODIFIES_SOMETHING,
b001a1b6 3354 .op_name = "OP_RELEASE_LOCKOWNER",
1c122638 3355 .op_rsize_bop = nfsd4_only_status_rsize,
b591480b 3356 },
069b6ad4
AA
3357
3358 /* NFSv4.1 operations */
3359 [OP_EXCHANGE_ID] = {
eb69853d 3360 .op_func = nfsd4_exchange_id,
58e7b33a
MJ
3361 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3362 | OP_MODIFIES_SOMETHING,
069b6ad4 3363 .op_name = "OP_EXCHANGE_ID",
1c122638 3364 .op_rsize_bop = nfsd4_exchange_id_rsize,
069b6ad4 3365 },
cb73a9f4 3366 [OP_BACKCHANNEL_CTL] = {
eb69853d 3367 .op_func = nfsd4_backchannel_ctl,
cb73a9f4
BF
3368 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3369 .op_name = "OP_BACKCHANNEL_CTL",
1c122638 3370 .op_rsize_bop = nfsd4_only_status_rsize,
cb73a9f4 3371 },
1d1bc8f2 3372 [OP_BIND_CONN_TO_SESSION] = {
eb69853d 3373 .op_func = nfsd4_bind_conn_to_session,
58e7b33a
MJ
3374 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3375 | OP_MODIFIES_SOMETHING,
1d1bc8f2 3376 .op_name = "OP_BIND_CONN_TO_SESSION",
1c122638 3377 .op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
1d1bc8f2 3378 },
069b6ad4 3379 [OP_CREATE_SESSION] = {
eb69853d 3380 .op_func = nfsd4_create_session,
58e7b33a
MJ
3381 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3382 | OP_MODIFIES_SOMETHING,
069b6ad4 3383 .op_name = "OP_CREATE_SESSION",
1c122638 3384 .op_rsize_bop = nfsd4_create_session_rsize,
069b6ad4
AA
3385 },
3386 [OP_DESTROY_SESSION] = {
eb69853d 3387 .op_func = nfsd4_destroy_session,
58e7b33a
MJ
3388 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3389 | OP_MODIFIES_SOMETHING,
069b6ad4 3390 .op_name = "OP_DESTROY_SESSION",
1c122638 3391 .op_rsize_bop = nfsd4_only_status_rsize,
069b6ad4
AA
3392 },
3393 [OP_SEQUENCE] = {
eb69853d 3394 .op_func = nfsd4_sequence,
f9bb94c4 3395 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
069b6ad4 3396 .op_name = "OP_SEQUENCE",
1c122638 3397 .op_rsize_bop = nfsd4_sequence_rsize,
069b6ad4 3398 },
094b5d74 3399 [OP_DESTROY_CLIENTID] = {
eb69853d 3400 .op_func = nfsd4_destroy_clientid,
58e7b33a
MJ
3401 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3402 | OP_MODIFIES_SOMETHING,
094b5d74 3403 .op_name = "OP_DESTROY_CLIENTID",
1c122638 3404 .op_rsize_bop = nfsd4_only_status_rsize,
094b5d74 3405 },
4dc6ec00 3406 [OP_RECLAIM_COMPLETE] = {
eb69853d 3407 .op_func = nfsd4_reclaim_complete,
58e7b33a 3408 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
4dc6ec00 3409 .op_name = "OP_RECLAIM_COMPLETE",
1c122638 3410 .op_rsize_bop = nfsd4_only_status_rsize,
4dc6ec00 3411 },
04f4ad16 3412 [OP_SECINFO_NO_NAME] = {
eb69853d 3413 .op_func = nfsd4_secinfo_no_name,
ec572b9e 3414 .op_release = nfsd4_secinfo_no_name_release,
68d93184 3415 .op_flags = OP_HANDLES_WRONGSEC,
04f4ad16 3416 .op_name = "OP_SECINFO_NO_NAME",
1c122638 3417 .op_rsize_bop = nfsd4_secinfo_rsize,
04f4ad16 3418 },
17456804 3419 [OP_TEST_STATEID] = {
eb69853d 3420 .op_func = nfsd4_test_stateid,
17456804
BS
3421 .op_flags = ALLOWED_WITHOUT_FH,
3422 .op_name = "OP_TEST_STATEID",
1c122638 3423 .op_rsize_bop = nfsd4_test_stateid_rsize,
17456804 3424 },
e1ca12df 3425 [OP_FREE_STATEID] = {
eb69853d 3426 .op_func = nfsd4_free_stateid,
58e7b33a 3427 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
e1ca12df 3428 .op_name = "OP_FREE_STATEID",
57832e7b 3429 .op_get_currentstateid = nfsd4_get_freestateid,
1c122638 3430 .op_rsize_bop = nfsd4_only_status_rsize,
e1ca12df 3431 },
9cf514cc
CH
3432#ifdef CONFIG_NFSD_PNFS
3433 [OP_GETDEVICEINFO] = {
eb69853d 3434 .op_func = nfsd4_getdeviceinfo,
34b1744c 3435 .op_release = nfsd4_getdeviceinfo_release,
9cf514cc
CH
3436 .op_flags = ALLOWED_WITHOUT_FH,
3437 .op_name = "OP_GETDEVICEINFO",
1c122638 3438 .op_rsize_bop = nfsd4_getdeviceinfo_rsize,
9cf514cc
CH
3439 },
3440 [OP_LAYOUTGET] = {
eb69853d 3441 .op_func = nfsd4_layoutget,
34b1744c 3442 .op_release = nfsd4_layoutget_release,
9cf514cc
CH
3443 .op_flags = OP_MODIFIES_SOMETHING,
3444 .op_name = "OP_LAYOUTGET",
1c122638 3445 .op_rsize_bop = nfsd4_layoutget_rsize,
9cf514cc
CH
3446 },
3447 [OP_LAYOUTCOMMIT] = {
eb69853d 3448 .op_func = nfsd4_layoutcommit,
9cf514cc
CH
3449 .op_flags = OP_MODIFIES_SOMETHING,
3450 .op_name = "OP_LAYOUTCOMMIT",
1c122638 3451 .op_rsize_bop = nfsd4_layoutcommit_rsize,
9cf514cc
CH
3452 },
3453 [OP_LAYOUTRETURN] = {
eb69853d 3454 .op_func = nfsd4_layoutreturn,
9cf514cc
CH
3455 .op_flags = OP_MODIFIES_SOMETHING,
3456 .op_name = "OP_LAYOUTRETURN",
1c122638 3457 .op_rsize_bop = nfsd4_layoutreturn_rsize,
9cf514cc
CH
3458 },
3459#endif /* CONFIG_NFSD_PNFS */
24bab491
AS
3460
3461 /* NFSv4.2 operations */
95d871f0 3462 [OP_ALLOCATE] = {
eb69853d 3463 .op_func = nfsd4_allocate,
03b31f48 3464 .op_flags = OP_MODIFIES_SOMETHING,
95d871f0 3465 .op_name = "OP_ALLOCATE",
1c122638 3466 .op_rsize_bop = nfsd4_only_status_rsize,
95d871f0 3467 },
b0cb9085 3468 [OP_DEALLOCATE] = {
eb69853d 3469 .op_func = nfsd4_deallocate,
03b31f48 3470 .op_flags = OP_MODIFIES_SOMETHING,
b0cb9085 3471 .op_name = "OP_DEALLOCATE",
1c122638 3472 .op_rsize_bop = nfsd4_only_status_rsize,
b0cb9085 3473 },
ffa0160a 3474 [OP_CLONE] = {
eb69853d 3475 .op_func = nfsd4_clone,
03b31f48 3476 .op_flags = OP_MODIFIES_SOMETHING,
ffa0160a 3477 .op_name = "OP_CLONE",
1c122638 3478 .op_rsize_bop = nfsd4_only_status_rsize,
ffa0160a 3479 },
29ae7f9d 3480 [OP_COPY] = {
eb69853d 3481 .op_func = nfsd4_copy,
03b31f48 3482 .op_flags = OP_MODIFIES_SOMETHING,
29ae7f9d 3483 .op_name = "OP_COPY",
1c122638 3484 .op_rsize_bop = nfsd4_copy_rsize,
29ae7f9d 3485 },
528b8493
AS
3486 [OP_READ_PLUS] = {
3487 .op_func = nfsd4_read,
3488 .op_release = nfsd4_read_release,
3489 .op_name = "OP_READ_PLUS",
3490 .op_rsize_bop = nfsd4_read_plus_rsize,
3491 .op_get_currentstateid = nfsd4_get_readstateid,
3492 },
24bab491 3493 [OP_SEEK] = {
eb69853d 3494 .op_func = nfsd4_seek,
24bab491 3495 .op_name = "OP_SEEK",
1c122638 3496 .op_rsize_bop = nfsd4_seek_rsize,
24bab491 3497 },
6308bc98
OK
3498 [OP_OFFLOAD_STATUS] = {
3499 .op_func = nfsd4_offload_status,
3500 .op_name = "OP_OFFLOAD_STATUS",
3501 .op_rsize_bop = nfsd4_offload_status_rsize,
3502 },
885e2bf3
OK
3503 [OP_OFFLOAD_CANCEL] = {
3504 .op_func = nfsd4_offload_cancel,
3505 .op_flags = OP_MODIFIES_SOMETHING,
3506 .op_name = "OP_OFFLOAD_CANCEL",
3507 .op_rsize_bop = nfsd4_only_status_rsize,
3508 },
51911868
OK
3509 [OP_COPY_NOTIFY] = {
3510 .op_func = nfsd4_copy_notify,
3511 .op_flags = OP_MODIFIES_SOMETHING,
3512 .op_name = "OP_COPY_NOTIFY",
3513 .op_rsize_bop = nfsd4_copy_notify_rsize,
3514 },
23e50fe3
FL
3515 [OP_GETXATTR] = {
3516 .op_func = nfsd4_getxattr,
3517 .op_name = "OP_GETXATTR",
3518 .op_rsize_bop = nfsd4_getxattr_rsize,
3519 },
3520 [OP_SETXATTR] = {
3521 .op_func = nfsd4_setxattr,
3522 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3523 .op_name = "OP_SETXATTR",
3524 .op_rsize_bop = nfsd4_setxattr_rsize,
3525 },
3526 [OP_LISTXATTRS] = {
3527 .op_func = nfsd4_listxattrs,
3528 .op_name = "OP_LISTXATTRS",
3529 .op_rsize_bop = nfsd4_listxattrs_rsize,
3530 },
3531 [OP_REMOVEXATTR] = {
3532 .op_func = nfsd4_removexattr,
3533 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3534 .op_name = "OP_REMOVEXATTR",
3535 .op_rsize_bop = nfsd4_removexattr_rsize,
3536 },
b591480b
BF
3537};
3538
ed941643
AE
3539/**
3540 * nfsd4_spo_must_allow - Determine if the compound op contains an
3541 * operation that is allowed to be sent with machine credentials
3542 *
3543 * @rqstp: a pointer to the struct svc_rqst
3544 *
3545 * Checks to see if the compound contains a spo_must_allow op
3546 * and confirms that it was sent with the proper machine creds.
3547 */
3548
3549bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
3550{
3551 struct nfsd4_compoundres *resp = rqstp->rq_resp;
3552 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
e34c0ce9 3553 struct nfsd4_op *this;
ed941643
AE
3554 struct nfsd4_compound_state *cstate = &resp->cstate;
3555 struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
3556 u32 opiter;
3557
3558 if (!cstate->minorversion)
3559 return false;
3560
44b49aa6 3561 if (cstate->spo_must_allowed)
ed941643
AE
3562 return true;
3563
3564 opiter = resp->opcnt;
3565 while (opiter < argp->opcnt) {
3566 this = &argp->ops[opiter++];
3567 if (test_bit(this->opnum, allow->u.longs) &&
3568 cstate->clp->cl_mach_cred &&
3569 nfsd4_mach_creds_match(cstate->clp, rqstp)) {
3570 cstate->spo_must_allowed = true;
3571 return true;
3572 }
3573 }
3574 cstate->spo_must_allowed = false;
3575 return false;
3576}
3577
4f0cefbf
BF
3578int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
3579{
05b7278d 3580 if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
4f0cefbf 3581 return op_encode_hdr_size * sizeof(__be32);
2282cd2c
KM
3582
3583 BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
3584 return OPDESC(op)->op_rsize_bop(rqstp, op);
4f0cefbf
BF
3585}
3586
07d1f802
BF
3587void warn_on_nonidempotent_op(struct nfsd4_op *op)
3588{
3589 if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
3a237b4a 3590 pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
07d1f802
BF
3591 op->opnum, nfsd4_op_name(op->opnum));
3592 WARN_ON_ONCE(1);
3593 }
3594}
3595
f1c7f79b 3596static const char *nfsd4_op_name(unsigned opnum)
b001a1b6
BH
3597{
3598 if (opnum < ARRAY_SIZE(nfsd4_ops))
3599 return nfsd4_ops[opnum].op_name;
3600 return "unknown_operation";
3601}
3602
860bda29 3603static const struct svc_procedure nfsd_procedures4[2] = {
0a93a47f 3604 [NFSPROC4_NULL] = {
f7235b6b 3605 .pc_func = nfsd4_proc_null,
788f7183
CL
3606 .pc_decode = nfssvc_decode_voidarg,
3607 .pc_encode = nfssvc_encode_voidres,
3608 .pc_argsize = sizeof(struct nfsd_voidargs),
3609 .pc_ressize = sizeof(struct nfsd_voidres),
0a93a47f
YZ
3610 .pc_cachetype = RC_NOCACHE,
3611 .pc_xdrressize = 1,
2289e87b 3612 .pc_name = "NULL",
0a93a47f
YZ
3613 },
3614 [NFSPROC4_COMPOUND] = {
f7235b6b 3615 .pc_func = nfsd4_proc_compound,
026fec7e 3616 .pc_decode = nfs4svc_decode_compoundargs,
63f8de37 3617 .pc_encode = nfs4svc_encode_compoundres,
0a93a47f
YZ
3618 .pc_argsize = sizeof(struct nfsd4_compoundargs),
3619 .pc_ressize = sizeof(struct nfsd4_compoundres),
3e98abff 3620 .pc_release = nfsd4_release_compoundargs,
0a93a47f
YZ
3621 .pc_cachetype = RC_NOCACHE,
3622 .pc_xdrressize = NFSD_BUFSIZE/4,
2289e87b 3623 .pc_name = "COMPOUND",
0a93a47f 3624 },
1da177e4
LT
3625};
3626
7fd38af9 3627static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
e9679189 3628const struct svc_version nfsd_version4 = {
5283b03e
JL
3629 .vs_vers = 4,
3630 .vs_nproc = 2,
3631 .vs_proc = nfsd_procedures4,
7fd38af9 3632 .vs_count = nfsd_count3,
5283b03e
JL
3633 .vs_dispatch = nfsd_dispatch,
3634 .vs_xdrsize = NFS4_SVC_XDRSIZE,
3635 .vs_rpcb_optnl = true,
3636 .vs_need_cong_ctrl = true,
1da177e4 3637};