2 * Server-side procedures for NFSv4.
4 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * Kendrick Smith <kmsmith@umich.edu>
8 * Andy Adamson <andros@umich.edu>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
35 #include <linux/fs_struct.h>
36 #include <linux/file.h>
37 #include <linux/falloc.h>
38 #include <linux/slab.h>
39 #include <linux/kthread.h>
40 #include <linux/namei.h>
42 #include <linux/sunrpc/addr.h>
43 #include <linux/nfs_ssc.h>
49 #include "current_stateid.h"
55 static bool inter_copy_offload_enable;
56 module_param(inter_copy_offload_enable, bool, 0644);
57 MODULE_PARM_DESC(inter_copy_offload_enable,
58 "Enable inter server to server copy offload. Default: false");
60 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
61 static int nfsd4_ssc_umount_timeout = 900000; /* default to 15 mins */
62 module_param(nfsd4_ssc_umount_timeout, int, 0644);
63 MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
64 "idle msecs before unmount export from source server");
67 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
68 #include <linux/security.h>
71 nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
73 struct inode *inode = d_inode(resfh->fh_dentry);
77 status = security_inode_setsecctx(resfh->fh_dentry,
78 label->data, label->len);
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:
87 bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
93 nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
97 #define NFSDDBG_FACILITY NFSDDBG_PROC
99 static u32 nfsd_attrmask[] = {
100 NFSD_WRITEABLE_ATTRS_WORD0,
101 NFSD_WRITEABLE_ATTRS_WORD1,
102 NFSD_WRITEABLE_ATTRS_WORD2
105 static u32 nfsd41_ex_attrmask[] = {
106 NFSD_SUPPATTR_EXCLCREAT_WORD0,
107 NFSD_SUPPATTR_EXCLCREAT_WORD1,
108 NFSD_SUPPATTR_EXCLCREAT_WORD2
112 check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
113 u32 *bmval, u32 *writable)
115 struct dentry *dentry = cstate->current_fh.fh_dentry;
116 struct svc_export *exp = cstate->current_fh.fh_export;
118 if (!nfsd_attrs_supported(cstate->minorversion, bmval))
119 return nfserr_attrnotsupp;
120 if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
121 return nfserr_attrnotsupp;
122 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
123 !(exp->ex_flags & NFSEXP_SECURITY_LABEL))
124 return nfserr_attrnotsupp;
125 if (writable && !bmval_is_subset(bmval, writable))
127 if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
128 (bmval[1] & FATTR4_WORD1_MODE))
134 nfsd4_check_open_attributes(struct svc_rqst *rqstp,
135 struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
137 __be32 status = nfs_ok;
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);
153 is_create_with_attrs(struct nfsd4_open *open)
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);
162 * if error occurs when setting the acl, just clear the acl bit
163 * in the returned attr bitmap.
166 do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
167 struct nfs4_acl *acl, u32 *bmval)
171 status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
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:
178 bmval[0] &= ~FATTR4_WORD0_ACL;
182 fh_dup2(struct svc_fh *dst, struct svc_fh *src)
185 dget(src->fh_dentry);
187 exp_get(src->fh_export);
192 do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
196 if (open->op_truncate &&
197 !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
200 accmode |= NFSD_MAY_READ_IF_EXEC;
202 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
203 accmode |= NFSD_MAY_READ;
204 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
205 accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
206 if (open->op_share_deny & NFS4_SHARE_DENY_READ)
207 accmode |= NFSD_MAY_WRITE;
209 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
214 static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
216 umode_t mode = d_inode(fh->fh_dentry)->i_mode;
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
229 return nfserr_symlink;
232 static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
234 if (nfsd4_has_session(cstate))
236 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
240 static inline bool nfsd4_create_is_exclusive(int createmode)
242 return createmode == NFS4_CREATE_EXCLUSIVE ||
243 createmode == NFS4_CREATE_EXCLUSIVE4_1;
247 nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
248 struct nfsd4_open *open)
254 oflags = O_CREAT | O_LARGEFILE;
255 switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) {
256 case NFS4_SHARE_ACCESS_WRITE:
259 case NFS4_SHARE_ACCESS_BOTH:
266 path.mnt = fhp->fh_export->ex_path.mnt;
268 filp = dentry_create(&path, oflags, open->op_iattr.ia_mode,
271 return nfserrno(PTR_ERR(filp));
273 open->op_filp = filp;
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().
282 * Upon return, caller must release @fhp and @resfhp.
285 nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
286 struct svc_fh *resfhp, struct nfsd4_open *open)
288 struct iattr *iap = &open->op_iattr;
289 struct dentry *parent, *child;
290 __u32 v_mtime, v_atime;
295 if (isdotent(open->op_fname, open->op_fnamelen))
297 if (!(iap->ia_valid & ATTR_MODE))
300 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
301 if (status != nfs_ok)
303 parent = fhp->fh_dentry;
304 inode = d_inode(parent);
306 host_err = fh_want_write(fhp);
308 return nfserrno(host_err);
310 fh_lock_nested(fhp, I_MUTEX_PARENT);
312 child = lookup_one_len(open->op_fname, parent, open->op_fnamelen);
314 status = nfserrno(PTR_ERR(child));
318 if (d_really_is_negative(child)) {
319 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
320 if (status != nfs_ok)
324 status = fh_compose(resfhp, fhp->fh_export, child, fhp);
325 if (status != nfs_ok)
330 if (nfsd4_create_is_exclusive(open->op_createmode)) {
331 u32 *verifier = (u32 *)open->op_verf.data;
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
341 v_mtime = verifier[0] & 0x7fffffff;
342 v_atime = verifier[1] & 0x7fffffff;
345 if (d_really_is_positive(child)) {
348 switch (open->op_createmode) {
349 case NFS4_CREATE_UNCHECKED:
350 if (!d_is_reg(child))
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!
359 open->op_truncate = (iap->ia_valid & ATTR_SIZE) &&
362 case NFS4_CREATE_GUARDED:
363 status = nfserr_exist;
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;
372 status = nfserr_exist;
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 */
381 status = nfserr_exist;
386 if (!IS_POSIXACL(inode))
387 iap->ia_mode &= ~current_umask();
389 status = nfsd4_vfs_create(fhp, child, open);
390 if (status != nfs_ok)
392 open->op_created = true;
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;
407 status = nfsd_create_setattr(rqstp, fhp, resfhp, iap);
411 if (child && !IS_ERR(child))
418 do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
420 struct svc_fh *current_fh = &cstate->current_fh;
424 *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
426 return nfserr_jukebox;
427 fh_init(*resfh, NFS4_FHSIZE);
428 open->op_truncate = false;
430 if (open->op_create) {
431 /* FIXME: check session persistence and pnfs flags.
432 * The nfsv4.1 spec requires the following semantics:
434 * Persistent | pNFS | Server REQUIRED | Client Allowed
435 * Reply Cache | server | |
436 * -------------+--------+-----------------+--------------------
437 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
439 * | | and EXCLUSIVE4 | or EXCLUSIVE4
441 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
442 * yes | no | GUARDED4 | GUARDED4
443 * yes | yes | GUARDED4 | GUARDED4
446 current->fs->umask = open->op_umask;
447 status = nfsd4_create_file(rqstp, current_fh, *resfh, open);
448 current->fs->umask = 0;
450 if (!status && open->op_label.len)
451 nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
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:
458 if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0)
459 open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
460 FATTR4_WORD1_TIME_MODIFY);
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.
468 status = nfsd_lookup(rqstp, current_fh,
469 open->op_fname, open->op_fnamelen, *resfh);
472 status = nfsd_check_obj_isreg(*resfh);
476 if (is_create_with_attrs(open) && open->op_acl != NULL)
477 do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
479 nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
480 accmode = NFSD_MAY_NOP;
481 if (open->op_created ||
482 open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
483 accmode |= NFSD_MAY_OWNER_OVERRIDE;
484 status = do_open_permission(rqstp, *resfh, open, accmode);
485 set_change_info(&open->op_cinfo, current_fh);
491 do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
493 struct svc_fh *current_fh = &cstate->current_fh;
497 /* We don't know the target directory, and therefore can not
498 * set the change info
501 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
503 nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
505 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
506 (open->op_iattr.ia_size == 0);
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.
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).
516 if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
517 accmode = NFSD_MAY_OWNER_OVERRIDE;
519 status = do_open_permission(rqstp, current_fh, open, accmode);
525 copy_clientid(clientid_t *clid, struct nfsd4_session *session)
527 struct nfsd4_sessionid *sid =
528 (struct nfsd4_sessionid *)session->se_sessionid.data;
530 clid->cl_boot = sid->clientid.cl_boot;
531 clid->cl_id = sid->clientid.cl_id;
535 nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
538 struct nfsd4_open *open = &u->open;
540 struct svc_fh *resfh = NULL;
541 struct net *net = SVC_NET(rqstp);
542 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
543 bool reclaim = false;
545 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
546 (int)open->op_fnamelen, open->op_fname,
549 open->op_filp = NULL;
551 /* This check required by spec. */
552 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
555 open->op_created = false;
558 * Before RECLAIM_COMPLETE done, server should deny new lock
560 if (nfsd4_has_session(cstate) &&
561 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) &&
562 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
565 if (nfsd4_has_session(cstate))
566 copy_clientid(&open->op_clientid, cstate->session);
568 /* check seqid for replay. set nfs4_owner */
569 status = nfsd4_process_open1(cstate, open, nn);
570 if (status == nfserr_replay_me) {
571 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
572 fh_put(&cstate->current_fh);
573 fh_copy_shallow(&cstate->current_fh.fh_handle,
575 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
577 dprintk("nfsd4_open: replay failed"
578 " restoring previous filehandle\n");
580 status = nfserr_replay_me;
584 if (open->op_xdr_error) {
585 status = open->op_xdr_error;
589 status = nfsd4_check_open_attributes(rqstp, cstate, open);
593 /* Openowner is now set, so sequence id will get bumped. Now we need
594 * these checks before we do any creates: */
595 status = nfserr_grace;
596 if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
598 status = nfserr_no_grace;
599 if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
602 switch (open->op_claim_type) {
603 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
604 case NFS4_OPEN_CLAIM_NULL:
605 status = do_open_lookup(rqstp, cstate, open, &resfh);
609 case NFS4_OPEN_CLAIM_PREVIOUS:
610 status = nfs4_check_open_reclaim(cstate->clp);
613 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
616 case NFS4_OPEN_CLAIM_FH:
617 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
618 status = do_open_fhandle(rqstp, cstate, open);
621 resfh = &cstate->current_fh;
623 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
624 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
625 dprintk("NFSD: unsupported OPEN claim type %d\n",
626 open->op_claim_type);
627 status = nfserr_notsupp;
630 dprintk("NFSD: Invalid OPEN claim type %d\n",
631 open->op_claim_type);
632 status = nfserr_inval;
636 * nfsd4_process_open2() does the actual opening of the file. If
637 * successful, it (1) truncates the file if open->op_truncate was
638 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
640 status = nfsd4_process_open2(rqstp, resfh, open);
641 WARN(status && open->op_created,
642 "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
643 be32_to_cpu(status));
644 if (reclaim && !status)
645 nn->somebody_reclaimed = true;
649 open->op_filp = NULL;
651 if (resfh && resfh != &cstate->current_fh) {
652 fh_dup2(&cstate->current_fh, resfh);
656 nfsd4_cleanup_open_state(cstate, open);
657 nfsd4_bump_seqid(cstate, status);
662 * OPEN is the only seqid-mutating operation whose decoding can fail
663 * with a seqid-mutating error (specifically, decoding of user names in
664 * the attributes). Therefore we have to do some processing to look up
665 * the stateowner so that we can bump the seqid.
667 static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
669 struct nfsd4_open *open = &op->u.open;
671 if (!seqid_mutating_err(ntohl(op->status)))
673 if (nfsd4_has_session(cstate))
675 open->op_xdr_error = op->status;
676 return nfsd4_open(rqstp, cstate, &op->u);
680 * filehandle-manipulating ops.
683 nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
686 u->getfh = &cstate->current_fh;
691 nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
694 struct nfsd4_putfh *putfh = &u->putfh;
697 fh_put(&cstate->current_fh);
698 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
699 memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval,
701 ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
702 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
703 if (ret == nfserr_stale && putfh->no_verify) {
704 SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN);
712 nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
717 fh_put(&cstate->current_fh);
718 status = exp_pseudoroot(rqstp, &cstate->current_fh);
723 nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
726 if (!cstate->save_fh.fh_dentry)
727 return nfserr_restorefh;
729 fh_dup2(&cstate->current_fh, &cstate->save_fh);
730 if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) {
731 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
732 SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
738 nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
741 fh_dup2(&cstate->save_fh, &cstate->current_fh);
742 if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
743 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
744 SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG);
753 nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
756 struct nfsd4_access *access = &u->access;
759 access_full = NFS3_ACCESS_FULL;
760 if (cstate->minorversion >= 2)
761 access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
764 if (access->ac_req_access & ~access_full)
767 access->ac_resp_access = access->ac_req_access;
768 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
769 &access->ac_supported);
772 static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
774 __be32 *verf = (__be32 *)verifier->data;
776 BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data));
778 nfsd_copy_write_verifier(verf, net_generic(net, nfsd_net_id));
782 nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
785 struct nfsd4_commit *commit = &u->commit;
787 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
789 (__be32 *)commit->co_verf.data);
793 nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
796 struct nfsd4_create *create = &u->create;
801 fh_init(&resfh, NFS4_FHSIZE);
803 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
807 status = check_attr_support(rqstp, cstate, create->cr_bmval,
812 current->fs->umask = create->cr_umask;
813 switch (create->cr_type) {
815 status = nfsd_symlink(rqstp, &cstate->current_fh,
816 create->cr_name, create->cr_namelen,
817 create->cr_data, &resfh);
821 status = nfserr_inval;
822 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
823 if (MAJOR(rdev) != create->cr_specdata1 ||
824 MINOR(rdev) != create->cr_specdata2)
826 status = nfsd_create(rqstp, &cstate->current_fh,
827 create->cr_name, create->cr_namelen,
828 &create->cr_iattr, S_IFBLK, rdev, &resfh);
832 status = nfserr_inval;
833 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
834 if (MAJOR(rdev) != create->cr_specdata1 ||
835 MINOR(rdev) != create->cr_specdata2)
837 status = nfsd_create(rqstp, &cstate->current_fh,
838 create->cr_name, create->cr_namelen,
839 &create->cr_iattr,S_IFCHR, rdev, &resfh);
843 status = nfsd_create(rqstp, &cstate->current_fh,
844 create->cr_name, create->cr_namelen,
845 &create->cr_iattr, S_IFSOCK, 0, &resfh);
849 status = nfsd_create(rqstp, &cstate->current_fh,
850 create->cr_name, create->cr_namelen,
851 &create->cr_iattr, S_IFIFO, 0, &resfh);
855 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
856 status = nfsd_create(rqstp, &cstate->current_fh,
857 create->cr_name, create->cr_namelen,
858 &create->cr_iattr, S_IFDIR, 0, &resfh);
862 status = nfserr_badtype;
868 if (create->cr_label.len)
869 nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
871 if (create->cr_acl != NULL)
872 do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
875 fh_unlock(&cstate->current_fh);
876 set_change_info(&create->cr_cinfo, &cstate->current_fh);
877 fh_dup2(&cstate->current_fh, &resfh);
881 current->fs->umask = 0;
886 nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
889 struct nfsd4_getattr *getattr = &u->getattr;
892 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
896 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
899 getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
900 getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
901 getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
903 getattr->ga_fhp = &cstate->current_fh;
908 nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
911 struct nfsd4_link *link = &u->link;
914 status = nfsd_link(rqstp, &cstate->current_fh,
915 link->li_name, link->li_namelen, &cstate->save_fh);
917 set_change_info(&link->li_cinfo, &cstate->current_fh);
921 static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
923 struct svc_fh tmp_fh;
926 fh_init(&tmp_fh, NFS4_FHSIZE);
927 ret = exp_pseudoroot(rqstp, &tmp_fh);
930 if (tmp_fh.fh_dentry == fh->fh_dentry) {
935 return nfsd_lookup(rqstp, fh, "..", 2, fh);
939 nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
942 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
946 nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
949 return nfsd_lookup(rqstp, &cstate->current_fh,
950 u->lookup.lo_name, u->lookup.lo_len,
951 &cstate->current_fh);
955 nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
958 struct nfsd4_read *read = &u->read;
963 trace_nfsd_read_start(rqstp, &cstate->current_fh,
964 read->rd_offset, read->rd_length);
966 read->rd_length = min_t(u32, read->rd_length, svc_max_payload(rqstp));
967 if (read->rd_offset > (u64)OFFSET_MAX)
968 read->rd_offset = (u64)OFFSET_MAX;
969 if (read->rd_offset + read->rd_length > (u64)OFFSET_MAX)
970 read->rd_length = (u64)OFFSET_MAX - read->rd_offset;
973 * If we do a zero copy read, then a client will see read data
974 * that reflects the state of the file *after* performing the
975 * following compound.
977 * To ensure proper ordering, we therefore turn off zero copy if
978 * the client wants us to do more in this compound:
980 if (!nfsd4_last_compound_op(rqstp))
981 clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
984 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
985 &read->rd_stateid, RD_STATE,
988 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
993 read->rd_rqstp = rqstp;
994 read->rd_fhp = &cstate->current_fh;
1000 nfsd4_read_release(union nfsd4_op_u *u)
1003 nfsd_file_put(u->read.rd_nf);
1004 trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
1005 u->read.rd_offset, u->read.rd_length);
1009 nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1010 union nfsd4_op_u *u)
1012 struct nfsd4_readdir *readdir = &u->readdir;
1013 u64 cookie = readdir->rd_cookie;
1014 static const nfs4_verifier zeroverf;
1016 /* no need to check permission - this will be done in nfsd_readdir() */
1018 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
1019 return nfserr_inval;
1021 readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
1022 readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
1023 readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
1025 if ((cookie == 1) || (cookie == 2) ||
1026 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
1027 return nfserr_bad_cookie;
1029 readdir->rd_rqstp = rqstp;
1030 readdir->rd_fhp = &cstate->current_fh;
1035 nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1036 union nfsd4_op_u *u)
1038 u->readlink.rl_rqstp = rqstp;
1039 u->readlink.rl_fhp = &cstate->current_fh;
1044 nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1045 union nfsd4_op_u *u)
1047 struct nfsd4_remove *remove = &u->remove;
1050 if (opens_in_grace(SVC_NET(rqstp)))
1051 return nfserr_grace;
1052 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
1053 remove->rm_name, remove->rm_namelen);
1055 fh_unlock(&cstate->current_fh);
1056 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
1062 nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1063 union nfsd4_op_u *u)
1065 struct nfsd4_rename *rename = &u->rename;
1068 if (opens_in_grace(SVC_NET(rqstp)))
1069 return nfserr_grace;
1070 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
1071 rename->rn_snamelen, &cstate->current_fh,
1072 rename->rn_tname, rename->rn_tnamelen);
1075 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
1076 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
1081 nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1082 union nfsd4_op_u *u)
1084 struct nfsd4_secinfo *secinfo = &u->secinfo;
1085 struct svc_export *exp;
1086 struct dentry *dentry;
1089 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
1092 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
1093 secinfo->si_name, secinfo->si_namelen,
1097 fh_unlock(&cstate->current_fh);
1098 if (d_really_is_negative(dentry)) {
1102 secinfo->si_exp = exp;
1104 if (cstate->minorversion)
1105 /* See rfc 5661 section 2.6.3.1.1.8 */
1106 fh_put(&cstate->current_fh);
1111 nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1112 union nfsd4_op_u *u)
1116 switch (u->secinfo_no_name.sin_style) {
1117 case NFS4_SECINFO_STYLE4_CURRENT_FH:
1119 case NFS4_SECINFO_STYLE4_PARENT:
1120 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
1125 return nfserr_inval;
1128 u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
1129 fh_put(&cstate->current_fh);
1134 nfsd4_secinfo_release(union nfsd4_op_u *u)
1136 if (u->secinfo.si_exp)
1137 exp_put(u->secinfo.si_exp);
1141 nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
1143 if (u->secinfo_no_name.sin_exp)
1144 exp_put(u->secinfo_no_name.sin_exp);
1148 nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1149 union nfsd4_op_u *u)
1151 struct nfsd4_setattr *setattr = &u->setattr;
1152 __be32 status = nfs_ok;
1155 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
1156 status = nfs4_preprocess_stateid_op(rqstp, cstate,
1157 &cstate->current_fh, &setattr->sa_stateid,
1158 WR_STATE, NULL, NULL);
1160 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
1164 err = fh_want_write(&cstate->current_fh);
1166 return nfserrno(err);
1169 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
1174 if (setattr->sa_acl != NULL)
1175 status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
1179 if (setattr->sa_label.len)
1180 status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
1181 &setattr->sa_label);
1184 status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
1187 fh_drop_write(&cstate->current_fh);
1192 nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1193 union nfsd4_op_u *u)
1195 struct nfsd4_write *write = &u->write;
1196 stateid_t *stateid = &write->wr_stateid;
1197 struct nfsd_file *nf = NULL;
1198 __be32 status = nfs_ok;
1202 if (write->wr_offset > (u64)OFFSET_MAX ||
1203 write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
1206 cnt = write->wr_buflen;
1207 trace_nfsd_write_start(rqstp, &cstate->current_fh,
1208 write->wr_offset, cnt);
1209 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1210 stateid, WR_STATE, &nf, NULL);
1212 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1216 write->wr_how_written = write->wr_stable_how;
1218 nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
1219 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1221 status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
1222 write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
1223 write->wr_how_written,
1224 (__be32 *)write->wr_verifier.data);
1227 write->wr_bytes_written = cnt;
1228 trace_nfsd_write_done(rqstp, &cstate->current_fh,
1229 write->wr_offset, cnt);
1234 nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1235 stateid_t *src_stateid, struct nfsd_file **src,
1236 stateid_t *dst_stateid, struct nfsd_file **dst)
1240 if (!cstate->save_fh.fh_dentry)
1241 return nfserr_nofilehandle;
1243 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
1244 src_stateid, RD_STATE, src, NULL);
1246 dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1250 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1251 dst_stateid, WR_STATE, dst, NULL);
1253 dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1257 /* fix up for NFS-specific error code */
1258 if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
1259 !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
1260 status = nfserr_wrong_type;
1267 nfsd_file_put(*dst);
1269 nfsd_file_put(*src);
1274 nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1275 union nfsd4_op_u *u)
1277 struct nfsd4_clone *clone = &u->clone;
1278 struct nfsd_file *src, *dst;
1281 status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
1282 &clone->cl_dst_stateid, &dst);
1286 status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos,
1287 dst, clone->cl_dst_pos, clone->cl_count,
1288 EX_ISSYNC(cstate->current_fh.fh_export));
1296 void nfs4_put_copy(struct nfsd4_copy *copy)
1298 if (!refcount_dec_and_test(©->refcount))
1304 check_and_set_stop_copy(struct nfsd4_copy *copy)
1308 spin_lock(©->cp_clp->async_lock);
1309 value = copy->stopped;
1311 copy->stopped = true;
1312 spin_unlock(©->cp_clp->async_lock);
1316 static void nfsd4_stop_copy(struct nfsd4_copy *copy)
1318 /* only 1 thread should stop the copy */
1319 if (!check_and_set_stop_copy(copy))
1320 kthread_stop(copy->copy_task);
1321 nfs4_put_copy(copy);
1324 static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp)
1326 struct nfsd4_copy *copy = NULL;
1328 spin_lock(&clp->async_lock);
1329 if (!list_empty(&clp->async_copies)) {
1330 copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
1332 refcount_inc(©->refcount);
1334 spin_unlock(&clp->async_lock);
1338 void nfsd4_shutdown_copy(struct nfs4_client *clp)
1340 struct nfsd4_copy *copy;
1342 while ((copy = nfsd4_get_copy(clp)) != NULL)
1343 nfsd4_stop_copy(copy);
1345 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
1347 extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1348 struct nfs_fh *src_fh,
1349 nfs4_stateid *stateid);
1350 extern void nfs42_ssc_close(struct file *filep);
1352 extern void nfs_sb_deactive(struct super_block *sb);
1354 #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
1357 * setup a work entry in the ssc delayed unmount list.
1359 static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr,
1360 struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt)
1362 struct nfsd4_ssc_umount_item *ni = NULL;
1363 struct nfsd4_ssc_umount_item *work = NULL;
1364 struct nfsd4_ssc_umount_item *tmp;
1369 work = kzalloc(sizeof(*work), GFP_KERNEL);
1371 spin_lock(&nn->nfsd_ssc_lock);
1372 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1373 if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
1376 if (ni->nsui_busy) {
1377 /* wait - and try again */
1378 prepare_to_wait(&nn->nfsd_ssc_waitq, &wait,
1379 TASK_INTERRUPTIBLE);
1380 spin_unlock(&nn->nfsd_ssc_lock);
1382 /* allow 20secs for mount/unmount for now - revisit */
1383 if (signal_pending(current) ||
1384 (schedule_timeout(20*HZ) == 0)) {
1386 return nfserr_eagain;
1388 finish_wait(&nn->nfsd_ssc_waitq, &wait);
1391 *ss_mnt = ni->nsui_vfsmount;
1392 refcount_inc(&ni->nsui_refcnt);
1393 spin_unlock(&nn->nfsd_ssc_lock);
1396 /* return vfsmount in ss_mnt */
1400 strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
1401 refcount_set(&work->nsui_refcnt, 2);
1402 work->nsui_busy = true;
1403 list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list);
1406 spin_unlock(&nn->nfsd_ssc_lock);
1410 static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn,
1411 struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt)
1413 /* set nsui_vfsmount, clear busy flag and wakeup waiters */
1414 spin_lock(&nn->nfsd_ssc_lock);
1415 work->nsui_vfsmount = ss_mnt;
1416 work->nsui_busy = false;
1417 wake_up_all(&nn->nfsd_ssc_waitq);
1418 spin_unlock(&nn->nfsd_ssc_lock);
1421 static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn,
1422 struct nfsd4_ssc_umount_item *work)
1424 spin_lock(&nn->nfsd_ssc_lock);
1425 list_del(&work->nsui_list);
1426 wake_up_all(&nn->nfsd_ssc_waitq);
1427 spin_unlock(&nn->nfsd_ssc_lock);
1432 * Support one copy source server for now.
1435 nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
1436 struct vfsmount **mount)
1438 struct file_system_type *type;
1439 struct vfsmount *ss_mnt;
1440 struct nfs42_netaddr *naddr;
1441 struct sockaddr_storage tmp_addr;
1442 size_t tmp_addrlen, match_netid_len = 3;
1443 char *startsep = "", *endsep = "", *match_netid = "tcp";
1444 char *ipaddr, *dev_name, *raw_data;
1446 __be32 status = nfserr_inval;
1447 struct nfsd4_ssc_umount_item *work = NULL;
1448 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1450 naddr = &nss->u.nl4_addr;
1451 tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
1453 (struct sockaddr *)&tmp_addr,
1455 if (tmp_addrlen == 0)
1458 if (tmp_addr.ss_family == AF_INET6) {
1461 match_netid = "tcp6";
1462 match_netid_len = 4;
1465 if (naddr->netid_len != match_netid_len ||
1466 strncmp(naddr->netid, match_netid, naddr->netid_len))
1469 /* Construct the raw data for the vfs_kern_mount call */
1470 len = RPC_MAX_ADDRBUFLEN + 1;
1471 ipaddr = kzalloc(len, GFP_KERNEL);
1475 rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len);
1477 /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
1479 raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr);
1480 raw_data = kzalloc(raw_len, GFP_KERNEL);
1482 goto out_free_ipaddr;
1484 snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr);
1486 status = nfserr_nodev;
1487 type = get_fs_type("nfs");
1489 goto out_free_rawdata;
1491 /* Set the server:<export> for the vfs_kern_mount call */
1492 dev_name = kzalloc(len + 5, GFP_KERNEL);
1494 goto out_free_rawdata;
1495 snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
1497 status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt);
1499 goto out_free_devname;
1503 /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
1504 ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
1505 module_put(type->owner);
1506 if (IS_ERR(ss_mnt)) {
1507 status = nfserr_nodev;
1509 nfsd4_ssc_cancel_dul_work(nn, work);
1510 goto out_free_devname;
1513 nfsd4_ssc_update_dul_work(nn, work, ss_mnt);
1529 nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1531 nfs_do_sb_deactive(ss_mnt->mnt_sb);
1536 * Verify COPY destination stateid.
1538 * Connect to the source server with NFSv4.1.
1539 * Create the source struct file for nfsd_copy_range.
1540 * Called with COPY cstate:
1541 * SAVED_FH: source filehandle
1542 * CURRENT_FH: destination filehandle
1545 nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1546 struct nfsd4_compound_state *cstate,
1547 struct nfsd4_copy *copy, struct vfsmount **mount)
1549 struct svc_fh *s_fh = NULL;
1550 stateid_t *s_stid = ©->cp_src_stateid;
1551 __be32 status = nfserr_inval;
1553 /* Verify the destination stateid and set dst struct file*/
1554 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1555 ©->cp_dst_stateid,
1556 WR_STATE, ©->nf_dst, NULL);
1560 status = nfsd4_interssc_connect(©->cp_src, rqstp, mount);
1564 s_fh = &cstate->save_fh;
1566 copy->c_fh.size = s_fh->fh_handle.fh_size;
1567 memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size);
1568 copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
1569 memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
1570 sizeof(stateid_opaque_t));
1578 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1579 struct nfsd_file *dst)
1583 struct nfsd4_ssc_umount_item *tmp;
1584 struct nfsd4_ssc_umount_item *ni = NULL;
1585 struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
1587 nfs42_ssc_close(src->nf_file);
1595 spin_lock(&nn->nfsd_ssc_lock);
1596 timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
1597 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1598 if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
1599 list_del(&ni->nsui_list);
1601 * vfsmount can be shared by multiple exports,
1602 * decrement refcnt. If the count drops to 1 it
1603 * will be unmounted when nsui_expire expires.
1605 refcount_dec(&ni->nsui_refcnt);
1606 ni->nsui_expire = jiffies + timeout;
1607 list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list);
1612 spin_unlock(&nn->nfsd_ssc_lock);
1619 #else /* CONFIG_NFSD_V4_2_INTER_SSC */
1622 nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1623 struct nfsd4_compound_state *cstate,
1624 struct nfsd4_copy *copy,
1625 struct vfsmount **mount)
1628 return nfserr_inval;
1632 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1633 struct nfsd_file *dst)
1638 nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1642 static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1643 struct nfs_fh *src_fh,
1644 nfs4_stateid *stateid)
1648 #endif /* CONFIG_NFSD_V4_2_INTER_SSC */
1651 nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
1652 struct nfsd4_compound_state *cstate,
1653 struct nfsd4_copy *copy)
1655 return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid,
1656 ©->nf_src, ©->cp_dst_stateid,
1661 nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst)
1667 static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
1669 struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
1671 nfs4_put_copy(copy);
1674 static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
1675 struct rpc_task *task)
1680 static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
1681 .release = nfsd4_cb_offload_release,
1682 .done = nfsd4_cb_offload_done
1685 static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
1687 copy->cp_res.wr_stable_how =
1688 copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE;
1689 copy->cp_synchronous = sync;
1690 gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net);
1693 static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
1695 struct file *dst = copy->nf_dst->nf_file;
1696 struct file *src = copy->nf_src->nf_file;
1698 ssize_t bytes_copied = 0;
1699 u64 bytes_total = copy->cp_count;
1700 u64 src_pos = copy->cp_src_pos;
1701 u64 dst_pos = copy->cp_dst_pos;
1704 /* See RFC 7862 p.67: */
1705 if (bytes_total == 0)
1706 bytes_total = ULLONG_MAX;
1708 if (kthread_should_stop())
1710 bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos,
1712 if (bytes_copied <= 0)
1714 bytes_total -= bytes_copied;
1715 copy->cp_res.wr_bytes_written += bytes_copied;
1716 src_pos += bytes_copied;
1717 dst_pos += bytes_copied;
1718 } while (bytes_total > 0 && !copy->cp_synchronous);
1719 /* for a non-zero asynchronous copy do a commit of data */
1720 if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) {
1721 since = READ_ONCE(dst->f_wb_err);
1722 status = vfs_fsync_range(dst, copy->cp_dst_pos,
1723 copy->cp_res.wr_bytes_written, 0);
1725 status = filemap_check_wb_err(dst->f_mapping, since);
1727 copy->committed = true;
1729 return bytes_copied;
1732 static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
1737 bytes = _nfsd_copy_file_range(copy);
1738 /* for async copy, we ignore the error, client can always retry
1741 if (bytes < 0 && !copy->cp_res.wr_bytes_written)
1742 status = nfserrno(bytes);
1744 nfsd4_init_copy_res(copy, sync);
1748 if (!copy->cp_intra) /* Inter server SSC */
1749 nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src,
1752 nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
1757 static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
1759 dst->cp_src_pos = src->cp_src_pos;
1760 dst->cp_dst_pos = src->cp_dst_pos;
1761 dst->cp_count = src->cp_count;
1762 dst->cp_synchronous = src->cp_synchronous;
1763 memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
1764 memcpy(&dst->fh, &src->fh, sizeof(src->fh));
1765 dst->cp_clp = src->cp_clp;
1766 dst->nf_dst = nfsd_file_get(src->nf_dst);
1767 dst->cp_intra = src->cp_intra;
1768 if (src->cp_intra) /* for inter, file_src doesn't exist yet */
1769 dst->nf_src = nfsd_file_get(src->nf_src);
1771 memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
1772 memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server));
1773 memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid));
1774 memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh));
1775 dst->ss_mnt = src->ss_mnt;
1778 static void cleanup_async_copy(struct nfsd4_copy *copy)
1780 nfs4_free_copy_state(copy);
1781 nfsd_file_put(copy->nf_dst);
1783 nfsd_file_put(copy->nf_src);
1784 spin_lock(©->cp_clp->async_lock);
1785 list_del(©->copies);
1786 spin_unlock(©->cp_clp->async_lock);
1787 nfs4_put_copy(copy);
1790 static int nfsd4_do_async_copy(void *data)
1792 struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1793 struct nfsd4_copy *cb_copy;
1795 if (!copy->cp_intra) { /* Inter server SSC */
1796 copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL);
1797 if (!copy->nf_src) {
1798 copy->nfserr = nfserr_serverfault;
1799 nfsd4_interssc_disconnect(copy->ss_mnt);
1802 copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh,
1804 if (IS_ERR(copy->nf_src->nf_file)) {
1805 copy->nfserr = nfserr_offload_denied;
1806 nfsd4_interssc_disconnect(copy->ss_mnt);
1811 copy->nfserr = nfsd4_do_copy(copy, 0);
1813 cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1816 refcount_set(&cb_copy->refcount, 1);
1817 memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res));
1818 cb_copy->cp_clp = copy->cp_clp;
1819 cb_copy->nfserr = copy->nfserr;
1820 memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh));
1821 nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp,
1822 &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD);
1823 trace_nfsd_cb_offload(copy->cp_clp, ©->cp_res.cb_stateid,
1824 ©->fh, copy->cp_count, copy->nfserr);
1825 nfsd4_run_cb(&cb_copy->cp_cb);
1827 if (!copy->cp_intra)
1828 kfree(copy->nf_src);
1829 cleanup_async_copy(copy);
1834 nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1835 union nfsd4_op_u *u)
1837 struct nfsd4_copy *copy = &u->copy;
1839 struct nfsd4_copy *async_copy = NULL;
1841 if (!copy->cp_intra) { /* Inter server SSC */
1842 if (!inter_copy_offload_enable || copy->cp_synchronous) {
1843 status = nfserr_notsupp;
1846 status = nfsd4_setup_inter_ssc(rqstp, cstate, copy,
1849 return nfserr_offload_denied;
1851 status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
1856 copy->cp_clp = cstate->clp;
1857 memcpy(©->fh, &cstate->current_fh.fh_handle,
1858 sizeof(struct knfsd_fh));
1859 if (!copy->cp_synchronous) {
1860 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1862 status = nfserrno(-ENOMEM);
1863 async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1866 if (!nfs4_init_copy_state(nn, copy))
1868 refcount_set(&async_copy->refcount, 1);
1869 memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid,
1870 sizeof(copy->cp_res.cb_stateid));
1871 dup_copy_fields(copy, async_copy);
1872 async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
1873 async_copy, "%s", "copy thread");
1874 if (IS_ERR(async_copy->copy_task))
1876 spin_lock(&async_copy->cp_clp->async_lock);
1877 list_add(&async_copy->copies,
1878 &async_copy->cp_clp->async_copies);
1879 spin_unlock(&async_copy->cp_clp->async_lock);
1880 wake_up_process(async_copy->copy_task);
1883 status = nfsd4_do_copy(copy, 1);
1889 cleanup_async_copy(async_copy);
1890 status = nfserrno(-ENOMEM);
1891 if (!copy->cp_intra)
1892 nfsd4_interssc_disconnect(copy->ss_mnt);
1897 find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
1899 struct nfsd4_copy *copy;
1901 spin_lock(&clp->async_lock);
1902 list_for_each_entry(copy, &clp->async_copies, copies) {
1903 if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE))
1905 refcount_inc(©->refcount);
1906 spin_unlock(&clp->async_lock);
1909 spin_unlock(&clp->async_lock);
1914 nfsd4_offload_cancel(struct svc_rqst *rqstp,
1915 struct nfsd4_compound_state *cstate,
1916 union nfsd4_op_u *u)
1918 struct nfsd4_offload_status *os = &u->offload_status;
1919 struct nfsd4_copy *copy;
1920 struct nfs4_client *clp = cstate->clp;
1922 copy = find_async_copy(clp, &os->stateid);
1924 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1926 return manage_cpntf_state(nn, &os->stateid, clp, NULL);
1928 nfsd4_stop_copy(copy);
1934 nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1935 union nfsd4_op_u *u)
1937 struct nfsd4_copy_notify *cn = &u->copy_notify;
1939 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1940 struct nfs4_stid *stid;
1941 struct nfs4_cpntf_state *cps;
1942 struct nfs4_client *clp = cstate->clp;
1944 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1945 &cn->cpn_src_stateid, RD_STATE, NULL,
1950 cn->cpn_sec = nn->nfsd4_lease;
1953 status = nfserrno(-ENOMEM);
1954 cps = nfs4_alloc_init_cpntf_state(nn, stid);
1957 memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t));
1958 memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t));
1959 memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t));
1961 /* For now, only return one server address in cpn_src, the
1962 * address used by the client to connect to this server.
1964 cn->cpn_src.nl4_type = NL4_NETADDR;
1965 status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr,
1966 &cn->cpn_src.u.nl4_addr);
1967 WARN_ON_ONCE(status);
1969 nfs4_put_cpntf_state(nn, cps);
1973 nfs4_put_stid(stid);
1978 nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1979 struct nfsd4_fallocate *fallocate, int flags)
1982 struct nfsd_file *nf;
1984 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1985 &fallocate->falloc_stateid,
1986 WR_STATE, &nf, NULL);
1987 if (status != nfs_ok) {
1988 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
1992 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
1993 fallocate->falloc_offset,
1994 fallocate->falloc_length,
2000 nfsd4_offload_status(struct svc_rqst *rqstp,
2001 struct nfsd4_compound_state *cstate,
2002 union nfsd4_op_u *u)
2004 struct nfsd4_offload_status *os = &u->offload_status;
2006 struct nfsd4_copy *copy;
2007 struct nfs4_client *clp = cstate->clp;
2009 copy = find_async_copy(clp, &os->stateid);
2011 os->count = copy->cp_res.wr_bytes_written;
2012 nfs4_put_copy(copy);
2014 status = nfserr_bad_stateid;
2020 nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2021 union nfsd4_op_u *u)
2023 return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
2027 nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2028 union nfsd4_op_u *u)
2030 return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
2031 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
2035 nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2036 union nfsd4_op_u *u)
2038 struct nfsd4_seek *seek = &u->seek;
2041 struct nfsd_file *nf;
2043 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
2044 &seek->seek_stateid,
2045 RD_STATE, &nf, NULL);
2047 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
2051 switch (seek->seek_whence) {
2052 case NFS4_CONTENT_DATA:
2055 case NFS4_CONTENT_HOLE:
2059 status = nfserr_union_notsupp;
2064 * Note: This call does change file->f_pos, but nothing in NFSD
2065 * should ever file->f_pos.
2067 seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
2068 if (seek->seek_pos < 0)
2069 status = nfserrno(seek->seek_pos);
2070 else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
2071 seek->seek_eof = true;
2078 /* This routine never returns NFS_OK! If there are no other errors, it
2079 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
2080 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
2081 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
2084 _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2085 struct nfsd4_verify *verify)
2091 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
2095 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
2099 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
2100 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
2101 return nfserr_inval;
2102 if (verify->ve_attrlen & 3)
2103 return nfserr_inval;
2106 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
2108 count = 4 + (verify->ve_attrlen >> 2);
2109 buf = kmalloc(count << 2, GFP_KERNEL);
2111 return nfserr_jukebox;
2114 status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
2115 cstate->current_fh.fh_export,
2116 cstate->current_fh.fh_dentry,
2120 * If nfsd4_encode_fattr() ran out of space, assume that's because
2121 * the attributes are longer (hence different) than those given:
2123 if (status == nfserr_resource)
2124 status = nfserr_not_same;
2129 p = buf + 1 + ntohl(buf[0]);
2130 status = nfserr_not_same;
2131 if (ntohl(*p++) != verify->ve_attrlen)
2133 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
2134 status = nfserr_same;
2142 nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2143 union nfsd4_op_u *u)
2147 status = _nfsd4_verify(rqstp, cstate, &u->verify);
2148 return status == nfserr_not_same ? nfs_ok : status;
2152 nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2153 union nfsd4_op_u *u)
2157 status = _nfsd4_verify(rqstp, cstate, &u->nverify);
2158 return status == nfserr_same ? nfs_ok : status;
2161 #ifdef CONFIG_NFSD_PNFS
2162 static const struct nfsd4_layout_ops *
2163 nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
2165 if (!exp->ex_layout_types) {
2166 dprintk("%s: export does not support pNFS\n", __func__);
2170 if (layout_type >= LAYOUT_TYPE_MAX ||
2171 !(exp->ex_layout_types & (1 << layout_type))) {
2172 dprintk("%s: layout type %d not supported\n",
2173 __func__, layout_type);
2177 return nfsd4_layout_ops[layout_type];
2181 nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
2182 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2184 struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
2185 const struct nfsd4_layout_ops *ops;
2186 struct nfsd4_deviceid_map *map;
2187 struct svc_export *exp;
2190 dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
2192 gdp->gd_layout_type,
2193 gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
2196 map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
2198 dprintk("%s: couldn't find device ID to export mapping!\n",
2200 return nfserr_noent;
2203 exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
2205 dprintk("%s: could not find device id\n", __func__);
2206 return nfserr_noent;
2209 nfserr = nfserr_layoutunavailable;
2210 ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
2215 if (gdp->gd_maxcount != 0) {
2216 nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
2217 rqstp, cstate->clp, gdp);
2220 gdp->gd_notify_types &= ops->notify_types;
2227 nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
2229 kfree(u->getdeviceinfo.gd_device);
2233 nfsd4_layoutget(struct svc_rqst *rqstp,
2234 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2236 struct nfsd4_layoutget *lgp = &u->layoutget;
2237 struct svc_fh *current_fh = &cstate->current_fh;
2238 const struct nfsd4_layout_ops *ops;
2239 struct nfs4_layout_stateid *ls;
2241 int accmode = NFSD_MAY_READ_IF_EXEC;
2243 switch (lgp->lg_seg.iomode) {
2245 accmode |= NFSD_MAY_READ;
2248 accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
2251 dprintk("%s: invalid iomode %d\n",
2252 __func__, lgp->lg_seg.iomode);
2253 nfserr = nfserr_badiomode;
2257 nfserr = fh_verify(rqstp, current_fh, 0, accmode);
2261 nfserr = nfserr_layoutunavailable;
2262 ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
2267 * Verify minlength and range as per RFC5661:
2268 * o If loga_length is less than loga_minlength,
2269 * the metadata server MUST return NFS4ERR_INVAL.
2270 * o If the sum of loga_offset and loga_minlength exceeds
2271 * NFS4_UINT64_MAX, and loga_minlength is not
2272 * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
2273 * o If the sum of loga_offset and loga_length exceeds
2274 * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
2275 * the error NFS4ERR_INVAL MUST result.
2277 nfserr = nfserr_inval;
2278 if (lgp->lg_seg.length < lgp->lg_minlength ||
2279 (lgp->lg_minlength != NFS4_MAX_UINT64 &&
2280 lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
2281 (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
2282 lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
2284 if (lgp->lg_seg.length == 0)
2287 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
2288 true, lgp->lg_layout_type, &ls);
2290 trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
2294 nfserr = nfserr_recallconflict;
2295 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
2298 nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
2303 nfserr = nfsd4_insert_layout(lgp, ls);
2306 mutex_unlock(&ls->ls_mutex);
2307 nfs4_put_stid(&ls->ls_stid);
2313 nfsd4_layoutget_release(union nfsd4_op_u *u)
2315 kfree(u->layoutget.lg_content);
2319 nfsd4_layoutcommit(struct svc_rqst *rqstp,
2320 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2322 struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
2323 const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
2324 struct svc_fh *current_fh = &cstate->current_fh;
2325 const struct nfsd4_layout_ops *ops;
2326 loff_t new_size = lcp->lc_last_wr + 1;
2327 struct inode *inode;
2328 struct nfs4_layout_stateid *ls;
2331 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
2335 nfserr = nfserr_layoutunavailable;
2336 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
2339 inode = d_inode(current_fh->fh_dentry);
2341 nfserr = nfserr_inval;
2342 if (new_size <= seg->offset) {
2343 dprintk("pnfsd: last write before layout segment\n");
2346 if (new_size > seg->offset + seg->length) {
2347 dprintk("pnfsd: last write beyond layout segment\n");
2350 if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
2351 dprintk("pnfsd: layoutcommit beyond EOF\n");
2355 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
2356 false, lcp->lc_layout_type,
2359 trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
2360 /* fixup error code as per RFC5661 */
2361 if (nfserr == nfserr_bad_stateid)
2362 nfserr = nfserr_badlayout;
2366 /* LAYOUTCOMMIT does not require any serialization */
2367 mutex_unlock(&ls->ls_mutex);
2369 if (new_size > i_size_read(inode)) {
2370 lcp->lc_size_chg = 1;
2371 lcp->lc_newsize = new_size;
2373 lcp->lc_size_chg = 0;
2376 nfserr = ops->proc_layoutcommit(inode, lcp);
2377 nfs4_put_stid(&ls->ls_stid);
2383 nfsd4_layoutreturn(struct svc_rqst *rqstp,
2384 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2386 struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
2387 struct svc_fh *current_fh = &cstate->current_fh;
2390 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
2394 nfserr = nfserr_layoutunavailable;
2395 if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
2398 switch (lrp->lr_seg.iomode) {
2404 dprintk("%s: invalid iomode %d\n", __func__,
2405 lrp->lr_seg.iomode);
2406 nfserr = nfserr_inval;
2410 switch (lrp->lr_return_type) {
2412 nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
2416 nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
2419 dprintk("%s: invalid return_type %d\n", __func__,
2420 lrp->lr_return_type);
2421 nfserr = nfserr_inval;
2427 #endif /* CONFIG_NFSD_PNFS */
2430 nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2431 union nfsd4_op_u *u)
2433 struct nfsd4_getxattr *getxattr = &u->getxattr;
2435 return nfsd_getxattr(rqstp, &cstate->current_fh,
2436 getxattr->getxa_name, &getxattr->getxa_buf,
2437 &getxattr->getxa_len);
2441 nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2442 union nfsd4_op_u *u)
2444 struct nfsd4_setxattr *setxattr = &u->setxattr;
2447 if (opens_in_grace(SVC_NET(rqstp)))
2448 return nfserr_grace;
2450 ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
2451 setxattr->setxa_buf, setxattr->setxa_len,
2452 setxattr->setxa_flags);
2455 set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
2461 nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2462 union nfsd4_op_u *u)
2465 * Get the entire list, then copy out only the user attributes
2466 * in the encode function.
2468 return nfsd_listxattr(rqstp, &cstate->current_fh,
2469 &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
2473 nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2474 union nfsd4_op_u *u)
2476 struct nfsd4_removexattr *removexattr = &u->removexattr;
2479 if (opens_in_grace(SVC_NET(rqstp)))
2480 return nfserr_grace;
2482 ret = nfsd_removexattr(rqstp, &cstate->current_fh,
2483 removexattr->rmxa_name);
2486 set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
2495 nfsd4_proc_null(struct svc_rqst *rqstp)
2500 static inline void nfsd4_increment_op_stats(u32 opnum)
2502 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
2503 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]);
2506 static const struct nfsd4_operation nfsd4_ops[];
2508 static const char *nfsd4_op_name(unsigned opnum);
2511 * Enforce NFSv4.1 COMPOUND ordering rules:
2513 * Also note, enforced elsewhere:
2514 * - SEQUENCE other than as first op results in
2515 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
2516 * - BIND_CONN_TO_SESSION must be the only op in its compound.
2517 * (Enforced in nfsd4_bind_conn_to_session().)
2518 * - DESTROY_SESSION must be the final operation in a compound, if
2519 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
2520 * (Enforced in nfsd4_destroy_session().)
2522 static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
2524 struct nfsd4_op *first_op = &args->ops[0];
2526 /* These ordering requirements don't apply to NFSv4.0: */
2527 if (args->minorversion == 0)
2529 /* This is weird, but OK, not our problem: */
2530 if (args->opcnt == 0)
2532 if (first_op->status == nfserr_op_illegal)
2534 if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
2535 return nfserr_op_not_in_session;
2536 if (first_op->opnum == OP_SEQUENCE)
2539 * So first_op is something allowed outside a session, like
2540 * EXCHANGE_ID; but then it has to be the only op in the
2543 if (args->opcnt != 1)
2544 return nfserr_not_only_op;
2548 const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
2550 return &nfsd4_ops[op->opnum];
2553 bool nfsd4_cache_this_op(struct nfsd4_op *op)
2555 if (op->opnum == OP_ILLEGAL)
2557 return OPDESC(op)->op_flags & OP_CACHEME;
2560 static bool need_wrongsec_check(struct svc_rqst *rqstp)
2562 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2563 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2564 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2565 struct nfsd4_op *next = &argp->ops[resp->opcnt];
2566 const struct nfsd4_operation *thisd = OPDESC(this);
2567 const struct nfsd4_operation *nextd;
2570 * Most ops check wronsec on our own; only the putfh-like ops
2571 * have special rules.
2573 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
2576 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
2577 * put-filehandle operation if we're not going to use the
2580 if (argp->opcnt == resp->opcnt)
2582 if (next->opnum == OP_ILLEGAL)
2584 nextd = OPDESC(next);
2586 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
2587 * errors themselves as necessary; others should check for them
2590 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
2593 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
2595 check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2597 struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL;
2598 struct nfsd4_copy *copy;
2599 struct nfsd4_putfh *putfh;
2602 /* traverse all operation and if it's a COPY compound, mark the
2603 * source filehandle to skip verification
2605 for (i = 0; i < args->opcnt; i++) {
2607 if (op->opnum == OP_PUTFH)
2609 else if (op->opnum == OP_SAVEFH)
2610 saved_op = current_op;
2611 else if (op->opnum == OP_RESTOREFH)
2612 current_op = saved_op;
2613 else if (op->opnum == OP_COPY) {
2614 copy = (struct nfsd4_copy *)&op->u;
2616 op->status = nfserr_nofilehandle;
2619 putfh = (struct nfsd4_putfh *)&saved_op->u;
2620 if (!copy->cp_intra)
2621 putfh->no_verify = true;
2627 check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2636 nfsd4_proc_compound(struct svc_rqst *rqstp)
2638 struct nfsd4_compoundargs *args = rqstp->rq_argp;
2639 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2640 struct nfsd4_op *op;
2641 struct nfsd4_compound_state *cstate = &resp->cstate;
2642 struct svc_fh *current_fh = &cstate->current_fh;
2643 struct svc_fh *save_fh = &cstate->save_fh;
2644 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
2647 resp->xdr = &rqstp->rq_res_stream;
2648 resp->statusp = resp->xdr->p;
2650 /* reserve space for: NFS status code */
2651 xdr_reserve_space(resp->xdr, XDR_UNIT);
2653 /* reserve space for: taglen, tag, and opcnt */
2654 xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
2655 resp->taglen = args->taglen;
2656 resp->tag = args->tag;
2657 resp->rqstp = rqstp;
2658 cstate->minorversion = args->minorversion;
2659 fh_init(current_fh, NFS4_FHSIZE);
2660 fh_init(save_fh, NFS4_FHSIZE);
2662 * Don't use the deferral mechanism for NFSv4; compounds make it
2663 * too hard to avoid non-idempotency problems.
2665 clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
2668 * According to RFC3010, this takes precedence over all other errors.
2670 status = nfserr_minor_vers_mismatch;
2671 if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
2673 status = nfserr_resource;
2674 if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
2677 status = nfs41_check_op_ordering(args);
2680 op->status = status;
2684 check_if_stalefh_allowed(args);
2686 rqstp->rq_lease_breaker = (void **)&cstate->clp;
2688 trace_nfsd_compound(rqstp, args->opcnt);
2689 while (!status && resp->opcnt < args->opcnt) {
2690 op = &args->ops[resp->opcnt++];
2693 * The XDR decode routines may have pre-set op->status;
2694 * for example, if there is a miscellaneous XDR error
2695 * it will be set to nfserr_bad_xdr.
2698 if (op->opnum == OP_OPEN)
2699 op->status = nfsd4_open_omfg(rqstp, cstate, op);
2702 if (!current_fh->fh_dentry &&
2703 !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) {
2704 if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
2705 op->status = nfserr_nofilehandle;
2708 } else if (current_fh->fh_export &&
2709 current_fh->fh_export->ex_fslocs.migrated &&
2710 !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
2711 op->status = nfserr_moved;
2715 fh_clear_pre_post_attrs(current_fh);
2717 /* If op is non-idempotent */
2718 if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
2720 * Don't execute this op if we couldn't encode a
2723 u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
2725 * Plus if there's another operation, make sure
2726 * we'll have space to at least encode an error:
2728 if (resp->opcnt < args->opcnt)
2729 plen += COMPOUND_ERR_SLACK_SPACE;
2730 op->status = nfsd4_check_resp_size(resp, plen);
2736 if (op->opdesc->op_get_currentstateid)
2737 op->opdesc->op_get_currentstateid(cstate, &op->u);
2738 op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
2740 /* Only from SEQUENCE */
2741 if (cstate->status == nfserr_replay_cache) {
2742 dprintk("%s NFS4.1 replay from cache\n", __func__);
2743 status = op->status;
2747 if (op->opdesc->op_set_currentstateid)
2748 op->opdesc->op_set_currentstateid(cstate, &op->u);
2750 if (op->opdesc->op_flags & OP_CLEAR_STATEID)
2751 clear_current_stateid(cstate);
2753 if (current_fh->fh_export &&
2754 need_wrongsec_check(rqstp))
2755 op->status = check_nfsd_access(current_fh->fh_export, rqstp);
2758 if (op->status == nfserr_replay_me) {
2759 op->replay = &cstate->replay_owner->so_replay;
2760 nfsd4_encode_replay(resp->xdr, op);
2761 status = op->status = op->replay->rp_status;
2763 nfsd4_encode_operation(resp, op);
2764 status = op->status;
2767 trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
2768 nfsd4_op_name(op->opnum));
2770 nfsd4_cstate_clear_replay(cstate);
2771 nfsd4_increment_op_stats(op->opnum);
2776 BUG_ON(cstate->replay_owner);
2778 cstate->status = status;
2779 /* Reset deferral mechanism for RPC deferrals */
2780 set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
2784 #define op_encode_hdr_size (2)
2785 #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
2786 #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
2787 #define op_encode_change_info_maxsz (5)
2788 #define nfs4_fattr_bitmap_maxsz (4)
2790 /* We'll fall back on returning no lockowner if run out of space: */
2791 #define op_encode_lockowner_maxsz (0)
2792 #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
2794 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
2796 #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
2797 #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
2798 op_encode_ace_maxsz)
2800 #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
2802 static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2804 return (op_encode_hdr_size) * sizeof(__be32);
2807 static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2809 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
2812 static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2814 /* ac_supported, ac_resp_access */
2815 return (op_encode_hdr_size + 2)* sizeof(__be32);
2818 static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2820 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
2823 static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2825 return (op_encode_hdr_size + op_encode_change_info_maxsz
2826 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2830 * Note since this is an idempotent operation we won't insist on failing
2831 * the op prematurely if the estimate is too large. We may turn off splice
2832 * reads unnecessarily.
2834 static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
2835 struct nfsd4_op *op)
2837 u32 *bmap = op->u.getattr.ga_bmval;
2838 u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
2841 if (bmap0 & FATTR4_WORD0_ACL)
2842 return svc_max_payload(rqstp);
2843 if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
2844 return svc_max_payload(rqstp);
2846 if (bmap1 & FATTR4_WORD1_OWNER) {
2847 ret += IDMAP_NAMESZ + 4;
2848 bmap1 &= ~FATTR4_WORD1_OWNER;
2850 if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
2851 ret += IDMAP_NAMESZ + 4;
2852 bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
2854 if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
2855 ret += NFS4_FHSIZE + 4;
2856 bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
2858 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
2859 ret += NFS4_MAXLABELLEN + 12;
2860 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2863 * Largest of remaining attributes are 16 bytes (e.g.,
2864 * supported_attributes)
2866 ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
2867 /* bitmask, length */
2872 static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2874 return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
2877 static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2879 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2883 static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2885 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
2889 static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2891 return (op_encode_hdr_size + op_encode_stateid_maxsz
2892 + op_encode_change_info_maxsz + 1
2893 + nfs4_fattr_bitmap_maxsz
2894 + op_encode_delegation_maxsz) * sizeof(__be32);
2897 static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2899 u32 maxcount = 0, rlen = 0;
2901 maxcount = svc_max_payload(rqstp);
2902 rlen = min(op->u.read.rd_length, maxcount);
2904 return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2907 static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2909 u32 maxcount = svc_max_payload(rqstp);
2910 u32 rlen = min(op->u.read.rd_length, maxcount);
2912 * If we detect that the file changed during hole encoding, then we
2913 * recover by encoding the remaining reply as data. This means we need
2914 * to set aside enough room to encode two data segments.
2916 u32 seg_len = 2 * (1 + 2 + 1);
2918 return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32);
2921 static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2923 u32 maxcount = 0, rlen = 0;
2925 maxcount = svc_max_payload(rqstp);
2926 rlen = min(op->u.readdir.rd_maxcount, maxcount);
2928 return (op_encode_hdr_size + op_encode_verifier_maxsz +
2929 XDR_QUADLEN(rlen)) * sizeof(__be32);
2932 static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2934 return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
2937 static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2939 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2943 static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2945 return (op_encode_hdr_size + op_encode_change_info_maxsz
2946 + op_encode_change_info_maxsz) * sizeof(__be32);
2949 static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
2950 struct nfsd4_op *op)
2952 return (op_encode_hdr_size
2953 + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
2956 static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2958 return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
2962 static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2964 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2967 static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2969 return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
2970 (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
2973 static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2975 return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2979 static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2981 return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
2984 static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2986 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
2987 1 + 1 + /* eir_flags, spr_how */\
2988 4 + /* spo_must_enforce & _allow with bitmap */\
2989 2 + /*eir_server_owner.so_minor_id */\
2990 /* eir_server_owner.so_major_id<> */\
2991 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2992 /* eir_server_scope<> */\
2993 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2994 1 + /* eir_server_impl_id array length */\
2995 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
2998 static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3000 return (op_encode_hdr_size + \
3001 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
3002 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
3005 static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3007 return (op_encode_hdr_size + \
3008 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
3009 2 + /* csr_sequence, csr_flags */\
3010 op_encode_channel_attrs_maxsz + \
3011 op_encode_channel_attrs_maxsz) * sizeof(__be32);
3014 static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3016 return (op_encode_hdr_size +
3017 1 /* wr_callback */ +
3018 op_encode_stateid_maxsz /* wr_callback */ +
3020 1 /* wr_committed */ +
3021 op_encode_verifier_maxsz +
3022 1 /* cr_consecutive */ +
3023 1 /* cr_synchronous */) * sizeof(__be32);
3026 static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
3027 struct nfsd4_op *op)
3029 return (op_encode_hdr_size +
3031 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
3034 static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp,
3035 struct nfsd4_op *op)
3037 return (op_encode_hdr_size +
3038 3 /* cnr_lease_time */ +
3039 1 /* We support one cnr_source_server */ +
3040 1 /* cnr_stateid seq */ +
3041 op_encode_stateid_maxsz /* cnr_stateid */ +
3042 1 /* num cnr_source_server*/ +
3045 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */)
3049 #ifdef CONFIG_NFSD_PNFS
3050 static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3052 u32 maxcount = 0, rlen = 0;
3054 maxcount = svc_max_payload(rqstp);
3055 rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
3057 return (op_encode_hdr_size +
3058 1 /* gd_layout_type*/ +
3060 2 /* gd_notify_types */) * sizeof(__be32);
3064 * At this stage we don't really know what layout driver will handle the request,
3065 * so we need to define an arbitrary upper bound here.
3067 #define MAX_LAYOUT_SIZE 128
3068 static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3070 return (op_encode_hdr_size +
3071 1 /* logr_return_on_close */ +
3072 op_encode_stateid_maxsz +
3073 1 /* nr of layouts */ +
3074 MAX_LAYOUT_SIZE) * sizeof(__be32);
3077 static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3079 return (op_encode_hdr_size +
3080 1 /* locr_newsize */ +
3081 2 /* ns_size */) * sizeof(__be32);
3084 static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3086 return (op_encode_hdr_size +
3087 1 /* lrs_stateid */ +
3088 op_encode_stateid_maxsz) * sizeof(__be32);
3090 #endif /* CONFIG_NFSD_PNFS */
3093 static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3095 return (op_encode_hdr_size + 3) * sizeof(__be32);
3098 static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp,
3099 struct nfsd4_op *op)
3103 maxcount = svc_max_payload(rqstp);
3104 rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
3106 return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3109 static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp,
3110 struct nfsd4_op *op)
3112 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3115 static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp,
3116 struct nfsd4_op *op)
3120 maxcount = svc_max_payload(rqstp);
3121 rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
3123 return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3126 static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp,
3127 struct nfsd4_op *op)
3129 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3134 static const struct nfsd4_operation nfsd4_ops[] = {
3136 .op_func = nfsd4_access,
3137 .op_name = "OP_ACCESS",
3138 .op_rsize_bop = nfsd4_access_rsize,
3141 .op_func = nfsd4_close,
3142 .op_flags = OP_MODIFIES_SOMETHING,
3143 .op_name = "OP_CLOSE",
3144 .op_rsize_bop = nfsd4_status_stateid_rsize,
3145 .op_get_currentstateid = nfsd4_get_closestateid,
3146 .op_set_currentstateid = nfsd4_set_closestateid,
3149 .op_func = nfsd4_commit,
3150 .op_flags = OP_MODIFIES_SOMETHING,
3151 .op_name = "OP_COMMIT",
3152 .op_rsize_bop = nfsd4_commit_rsize,
3155 .op_func = nfsd4_create,
3156 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
3157 .op_name = "OP_CREATE",
3158 .op_rsize_bop = nfsd4_create_rsize,
3160 [OP_DELEGRETURN] = {
3161 .op_func = nfsd4_delegreturn,
3162 .op_flags = OP_MODIFIES_SOMETHING,
3163 .op_name = "OP_DELEGRETURN",
3164 .op_rsize_bop = nfsd4_only_status_rsize,
3165 .op_get_currentstateid = nfsd4_get_delegreturnstateid,
3168 .op_func = nfsd4_getattr,
3169 .op_flags = ALLOWED_ON_ABSENT_FS,
3170 .op_rsize_bop = nfsd4_getattr_rsize,
3171 .op_name = "OP_GETATTR",
3174 .op_func = nfsd4_getfh,
3175 .op_name = "OP_GETFH",
3176 .op_rsize_bop = nfsd4_getfh_rsize,
3179 .op_func = nfsd4_link,
3180 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
3182 .op_name = "OP_LINK",
3183 .op_rsize_bop = nfsd4_link_rsize,
3186 .op_func = nfsd4_lock,
3187 .op_flags = OP_MODIFIES_SOMETHING |
3188 OP_NONTRIVIAL_ERROR_ENCODE,
3189 .op_name = "OP_LOCK",
3190 .op_rsize_bop = nfsd4_lock_rsize,
3191 .op_set_currentstateid = nfsd4_set_lockstateid,
3194 .op_func = nfsd4_lockt,
3195 .op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
3196 .op_name = "OP_LOCKT",
3197 .op_rsize_bop = nfsd4_lock_rsize,
3200 .op_func = nfsd4_locku,
3201 .op_flags = OP_MODIFIES_SOMETHING,
3202 .op_name = "OP_LOCKU",
3203 .op_rsize_bop = nfsd4_status_stateid_rsize,
3204 .op_get_currentstateid = nfsd4_get_lockustateid,
3207 .op_func = nfsd4_lookup,
3208 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
3209 .op_name = "OP_LOOKUP",
3210 .op_rsize_bop = nfsd4_only_status_rsize,
3213 .op_func = nfsd4_lookupp,
3214 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
3215 .op_name = "OP_LOOKUPP",
3216 .op_rsize_bop = nfsd4_only_status_rsize,
3219 .op_func = nfsd4_nverify,
3220 .op_name = "OP_NVERIFY",
3221 .op_rsize_bop = nfsd4_only_status_rsize,
3224 .op_func = nfsd4_open,
3225 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
3226 .op_name = "OP_OPEN",
3227 .op_rsize_bop = nfsd4_open_rsize,
3228 .op_set_currentstateid = nfsd4_set_openstateid,
3230 [OP_OPEN_CONFIRM] = {
3231 .op_func = nfsd4_open_confirm,
3232 .op_flags = OP_MODIFIES_SOMETHING,
3233 .op_name = "OP_OPEN_CONFIRM",
3234 .op_rsize_bop = nfsd4_status_stateid_rsize,
3236 [OP_OPEN_DOWNGRADE] = {
3237 .op_func = nfsd4_open_downgrade,
3238 .op_flags = OP_MODIFIES_SOMETHING,
3239 .op_name = "OP_OPEN_DOWNGRADE",
3240 .op_rsize_bop = nfsd4_status_stateid_rsize,
3241 .op_get_currentstateid = nfsd4_get_opendowngradestateid,
3242 .op_set_currentstateid = nfsd4_set_opendowngradestateid,
3245 .op_func = nfsd4_putfh,
3246 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3247 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3248 .op_name = "OP_PUTFH",
3249 .op_rsize_bop = nfsd4_only_status_rsize,
3252 .op_func = nfsd4_putrootfh,
3253 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3254 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3255 .op_name = "OP_PUTPUBFH",
3256 .op_rsize_bop = nfsd4_only_status_rsize,
3259 .op_func = nfsd4_putrootfh,
3260 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3261 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3262 .op_name = "OP_PUTROOTFH",
3263 .op_rsize_bop = nfsd4_only_status_rsize,
3266 .op_func = nfsd4_read,
3267 .op_release = nfsd4_read_release,
3268 .op_name = "OP_READ",
3269 .op_rsize_bop = nfsd4_read_rsize,
3270 .op_get_currentstateid = nfsd4_get_readstateid,
3273 .op_func = nfsd4_readdir,
3274 .op_name = "OP_READDIR",
3275 .op_rsize_bop = nfsd4_readdir_rsize,
3278 .op_func = nfsd4_readlink,
3279 .op_name = "OP_READLINK",
3280 .op_rsize_bop = nfsd4_readlink_rsize,
3283 .op_func = nfsd4_remove,
3284 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3285 .op_name = "OP_REMOVE",
3286 .op_rsize_bop = nfsd4_remove_rsize,
3289 .op_func = nfsd4_rename,
3290 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3291 .op_name = "OP_RENAME",
3292 .op_rsize_bop = nfsd4_rename_rsize,
3295 .op_func = nfsd4_renew,
3296 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3297 | OP_MODIFIES_SOMETHING,
3298 .op_name = "OP_RENEW",
3299 .op_rsize_bop = nfsd4_only_status_rsize,
3303 .op_func = nfsd4_restorefh,
3304 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3305 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
3306 .op_name = "OP_RESTOREFH",
3307 .op_rsize_bop = nfsd4_only_status_rsize,
3310 .op_func = nfsd4_savefh,
3311 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
3312 .op_name = "OP_SAVEFH",
3313 .op_rsize_bop = nfsd4_only_status_rsize,
3316 .op_func = nfsd4_secinfo,
3317 .op_release = nfsd4_secinfo_release,
3318 .op_flags = OP_HANDLES_WRONGSEC,
3319 .op_name = "OP_SECINFO",
3320 .op_rsize_bop = nfsd4_secinfo_rsize,
3323 .op_func = nfsd4_setattr,
3324 .op_name = "OP_SETATTR",
3325 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
3326 | OP_NONTRIVIAL_ERROR_ENCODE,
3327 .op_rsize_bop = nfsd4_setattr_rsize,
3328 .op_get_currentstateid = nfsd4_get_setattrstateid,
3330 [OP_SETCLIENTID] = {
3331 .op_func = nfsd4_setclientid,
3332 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3333 | OP_MODIFIES_SOMETHING | OP_CACHEME
3334 | OP_NONTRIVIAL_ERROR_ENCODE,
3335 .op_name = "OP_SETCLIENTID",
3336 .op_rsize_bop = nfsd4_setclientid_rsize,
3338 [OP_SETCLIENTID_CONFIRM] = {
3339 .op_func = nfsd4_setclientid_confirm,
3340 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3341 | OP_MODIFIES_SOMETHING | OP_CACHEME,
3342 .op_name = "OP_SETCLIENTID_CONFIRM",
3343 .op_rsize_bop = nfsd4_only_status_rsize,
3346 .op_func = nfsd4_verify,
3347 .op_name = "OP_VERIFY",
3348 .op_rsize_bop = nfsd4_only_status_rsize,
3351 .op_func = nfsd4_write,
3352 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3353 .op_name = "OP_WRITE",
3354 .op_rsize_bop = nfsd4_write_rsize,
3355 .op_get_currentstateid = nfsd4_get_writestateid,
3357 [OP_RELEASE_LOCKOWNER] = {
3358 .op_func = nfsd4_release_lockowner,
3359 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3360 | OP_MODIFIES_SOMETHING,
3361 .op_name = "OP_RELEASE_LOCKOWNER",
3362 .op_rsize_bop = nfsd4_only_status_rsize,
3365 /* NFSv4.1 operations */
3366 [OP_EXCHANGE_ID] = {
3367 .op_func = nfsd4_exchange_id,
3368 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3369 | OP_MODIFIES_SOMETHING,
3370 .op_name = "OP_EXCHANGE_ID",
3371 .op_rsize_bop = nfsd4_exchange_id_rsize,
3373 [OP_BACKCHANNEL_CTL] = {
3374 .op_func = nfsd4_backchannel_ctl,
3375 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3376 .op_name = "OP_BACKCHANNEL_CTL",
3377 .op_rsize_bop = nfsd4_only_status_rsize,
3379 [OP_BIND_CONN_TO_SESSION] = {
3380 .op_func = nfsd4_bind_conn_to_session,
3381 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3382 | OP_MODIFIES_SOMETHING,
3383 .op_name = "OP_BIND_CONN_TO_SESSION",
3384 .op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
3386 [OP_CREATE_SESSION] = {
3387 .op_func = nfsd4_create_session,
3388 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3389 | OP_MODIFIES_SOMETHING,
3390 .op_name = "OP_CREATE_SESSION",
3391 .op_rsize_bop = nfsd4_create_session_rsize,
3393 [OP_DESTROY_SESSION] = {
3394 .op_func = nfsd4_destroy_session,
3395 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3396 | OP_MODIFIES_SOMETHING,
3397 .op_name = "OP_DESTROY_SESSION",
3398 .op_rsize_bop = nfsd4_only_status_rsize,
3401 .op_func = nfsd4_sequence,
3402 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
3403 .op_name = "OP_SEQUENCE",
3404 .op_rsize_bop = nfsd4_sequence_rsize,
3406 [OP_DESTROY_CLIENTID] = {
3407 .op_func = nfsd4_destroy_clientid,
3408 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3409 | OP_MODIFIES_SOMETHING,
3410 .op_name = "OP_DESTROY_CLIENTID",
3411 .op_rsize_bop = nfsd4_only_status_rsize,
3413 [OP_RECLAIM_COMPLETE] = {
3414 .op_func = nfsd4_reclaim_complete,
3415 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3416 .op_name = "OP_RECLAIM_COMPLETE",
3417 .op_rsize_bop = nfsd4_only_status_rsize,
3419 [OP_SECINFO_NO_NAME] = {
3420 .op_func = nfsd4_secinfo_no_name,
3421 .op_release = nfsd4_secinfo_no_name_release,
3422 .op_flags = OP_HANDLES_WRONGSEC,
3423 .op_name = "OP_SECINFO_NO_NAME",
3424 .op_rsize_bop = nfsd4_secinfo_rsize,
3426 [OP_TEST_STATEID] = {
3427 .op_func = nfsd4_test_stateid,
3428 .op_flags = ALLOWED_WITHOUT_FH,
3429 .op_name = "OP_TEST_STATEID",
3430 .op_rsize_bop = nfsd4_test_stateid_rsize,
3432 [OP_FREE_STATEID] = {
3433 .op_func = nfsd4_free_stateid,
3434 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3435 .op_name = "OP_FREE_STATEID",
3436 .op_get_currentstateid = nfsd4_get_freestateid,
3437 .op_rsize_bop = nfsd4_only_status_rsize,
3439 #ifdef CONFIG_NFSD_PNFS
3440 [OP_GETDEVICEINFO] = {
3441 .op_func = nfsd4_getdeviceinfo,
3442 .op_release = nfsd4_getdeviceinfo_release,
3443 .op_flags = ALLOWED_WITHOUT_FH,
3444 .op_name = "OP_GETDEVICEINFO",
3445 .op_rsize_bop = nfsd4_getdeviceinfo_rsize,
3448 .op_func = nfsd4_layoutget,
3449 .op_release = nfsd4_layoutget_release,
3450 .op_flags = OP_MODIFIES_SOMETHING,
3451 .op_name = "OP_LAYOUTGET",
3452 .op_rsize_bop = nfsd4_layoutget_rsize,
3454 [OP_LAYOUTCOMMIT] = {
3455 .op_func = nfsd4_layoutcommit,
3456 .op_flags = OP_MODIFIES_SOMETHING,
3457 .op_name = "OP_LAYOUTCOMMIT",
3458 .op_rsize_bop = nfsd4_layoutcommit_rsize,
3460 [OP_LAYOUTRETURN] = {
3461 .op_func = nfsd4_layoutreturn,
3462 .op_flags = OP_MODIFIES_SOMETHING,
3463 .op_name = "OP_LAYOUTRETURN",
3464 .op_rsize_bop = nfsd4_layoutreturn_rsize,
3466 #endif /* CONFIG_NFSD_PNFS */
3468 /* NFSv4.2 operations */
3470 .op_func = nfsd4_allocate,
3471 .op_flags = OP_MODIFIES_SOMETHING,
3472 .op_name = "OP_ALLOCATE",
3473 .op_rsize_bop = nfsd4_only_status_rsize,
3476 .op_func = nfsd4_deallocate,
3477 .op_flags = OP_MODIFIES_SOMETHING,
3478 .op_name = "OP_DEALLOCATE",
3479 .op_rsize_bop = nfsd4_only_status_rsize,
3482 .op_func = nfsd4_clone,
3483 .op_flags = OP_MODIFIES_SOMETHING,
3484 .op_name = "OP_CLONE",
3485 .op_rsize_bop = nfsd4_only_status_rsize,
3488 .op_func = nfsd4_copy,
3489 .op_flags = OP_MODIFIES_SOMETHING,
3490 .op_name = "OP_COPY",
3491 .op_rsize_bop = nfsd4_copy_rsize,
3494 .op_func = nfsd4_read,
3495 .op_release = nfsd4_read_release,
3496 .op_name = "OP_READ_PLUS",
3497 .op_rsize_bop = nfsd4_read_plus_rsize,
3498 .op_get_currentstateid = nfsd4_get_readstateid,
3501 .op_func = nfsd4_seek,
3502 .op_name = "OP_SEEK",
3503 .op_rsize_bop = nfsd4_seek_rsize,
3505 [OP_OFFLOAD_STATUS] = {
3506 .op_func = nfsd4_offload_status,
3507 .op_name = "OP_OFFLOAD_STATUS",
3508 .op_rsize_bop = nfsd4_offload_status_rsize,
3510 [OP_OFFLOAD_CANCEL] = {
3511 .op_func = nfsd4_offload_cancel,
3512 .op_flags = OP_MODIFIES_SOMETHING,
3513 .op_name = "OP_OFFLOAD_CANCEL",
3514 .op_rsize_bop = nfsd4_only_status_rsize,
3516 [OP_COPY_NOTIFY] = {
3517 .op_func = nfsd4_copy_notify,
3518 .op_flags = OP_MODIFIES_SOMETHING,
3519 .op_name = "OP_COPY_NOTIFY",
3520 .op_rsize_bop = nfsd4_copy_notify_rsize,
3523 .op_func = nfsd4_getxattr,
3524 .op_name = "OP_GETXATTR",
3525 .op_rsize_bop = nfsd4_getxattr_rsize,
3528 .op_func = nfsd4_setxattr,
3529 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3530 .op_name = "OP_SETXATTR",
3531 .op_rsize_bop = nfsd4_setxattr_rsize,
3534 .op_func = nfsd4_listxattrs,
3535 .op_name = "OP_LISTXATTRS",
3536 .op_rsize_bop = nfsd4_listxattrs_rsize,
3538 [OP_REMOVEXATTR] = {
3539 .op_func = nfsd4_removexattr,
3540 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3541 .op_name = "OP_REMOVEXATTR",
3542 .op_rsize_bop = nfsd4_removexattr_rsize,
3547 * nfsd4_spo_must_allow - Determine if the compound op contains an
3548 * operation that is allowed to be sent with machine credentials
3550 * @rqstp: a pointer to the struct svc_rqst
3552 * Checks to see if the compound contains a spo_must_allow op
3553 * and confirms that it was sent with the proper machine creds.
3556 bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
3558 struct nfsd4_compoundres *resp = rqstp->rq_resp;
3559 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
3560 struct nfsd4_op *this;
3561 struct nfsd4_compound_state *cstate = &resp->cstate;
3562 struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
3565 if (!cstate->minorversion)
3568 if (cstate->spo_must_allowed)
3571 opiter = resp->opcnt;
3572 while (opiter < argp->opcnt) {
3573 this = &argp->ops[opiter++];
3574 if (test_bit(this->opnum, allow->u.longs) &&
3575 cstate->clp->cl_mach_cred &&
3576 nfsd4_mach_creds_match(cstate->clp, rqstp)) {
3577 cstate->spo_must_allowed = true;
3581 cstate->spo_must_allowed = false;
3585 int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
3587 if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
3588 return op_encode_hdr_size * sizeof(__be32);
3590 BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
3591 return OPDESC(op)->op_rsize_bop(rqstp, op);
3594 void warn_on_nonidempotent_op(struct nfsd4_op *op)
3596 if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
3597 pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
3598 op->opnum, nfsd4_op_name(op->opnum));
3603 static const char *nfsd4_op_name(unsigned opnum)
3605 if (opnum < ARRAY_SIZE(nfsd4_ops))
3606 return nfsd4_ops[opnum].op_name;
3607 return "unknown_operation";
3610 static const struct svc_procedure nfsd_procedures4[2] = {
3612 .pc_func = nfsd4_proc_null,
3613 .pc_decode = nfssvc_decode_voidarg,
3614 .pc_encode = nfssvc_encode_voidres,
3615 .pc_argsize = sizeof(struct nfsd_voidargs),
3616 .pc_ressize = sizeof(struct nfsd_voidres),
3617 .pc_cachetype = RC_NOCACHE,
3621 [NFSPROC4_COMPOUND] = {
3622 .pc_func = nfsd4_proc_compound,
3623 .pc_decode = nfs4svc_decode_compoundargs,
3624 .pc_encode = nfs4svc_encode_compoundres,
3625 .pc_argsize = sizeof(struct nfsd4_compoundargs),
3626 .pc_ressize = sizeof(struct nfsd4_compoundres),
3627 .pc_release = nfsd4_release_compoundargs,
3628 .pc_cachetype = RC_NOCACHE,
3629 .pc_xdrressize = NFSD_BUFSIZE/4,
3630 .pc_name = "COMPOUND",
3634 static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
3635 const struct svc_version nfsd_version4 = {
3638 .vs_proc = nfsd_procedures4,
3639 .vs_count = nfsd_count3,
3640 .vs_dispatch = nfsd_dispatch,
3641 .vs_xdrsize = NFS4_SVC_XDRSIZE,
3642 .vs_rpcb_optnl = true,
3643 .vs_need_cong_ctrl = true,