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 * Implement NFSv4's unchecked, guarded, and exclusive create
248 * semantics for regular files. Open state for this new file is
249 * subsequently fabricated in nfsd4_process_open2().
251 * Upon return, caller must release @fhp and @resfhp.
254 nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
255 struct svc_fh *resfhp, struct nfsd4_open *open)
257 struct iattr *iap = &open->op_iattr;
258 struct dentry *parent, *child;
259 __u32 v_mtime, v_atime;
264 if (isdotent(open->op_fname, open->op_fnamelen))
266 if (!(iap->ia_valid & ATTR_MODE))
269 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
270 if (status != nfs_ok)
272 parent = fhp->fh_dentry;
273 inode = d_inode(parent);
275 host_err = fh_want_write(fhp);
277 return nfserrno(host_err);
279 fh_lock_nested(fhp, I_MUTEX_PARENT);
281 child = lookup_one_len(open->op_fname, parent, open->op_fnamelen);
283 status = nfserrno(PTR_ERR(child));
287 if (d_really_is_negative(child)) {
288 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
289 if (status != nfs_ok)
293 status = fh_compose(resfhp, fhp->fh_export, child, fhp);
294 if (status != nfs_ok)
299 if (nfsd4_create_is_exclusive(open->op_createmode)) {
300 u32 *verifier = (u32 *)open->op_verf.data;
303 * Solaris 7 gets confused (bugid 4218508) if these have
304 * the high bit set, as do xfs filesystems without the
305 * "bigtime" feature. So just clear the high bits. If this
306 * is ever changed to use different attrs for storing the
307 * verifier, then do_open_lookup() will also need to be
310 v_mtime = verifier[0] & 0x7fffffff;
311 v_atime = verifier[1] & 0x7fffffff;
314 if (d_really_is_positive(child)) {
317 switch (open->op_createmode) {
318 case NFS4_CREATE_UNCHECKED:
319 if (!d_is_reg(child))
323 * In NFSv4, we don't want to truncate the file
324 * now. This would be wrong if the OPEN fails for
325 * some other reason. Furthermore, if the size is
326 * nonzero, we should ignore it according to spec!
328 open->op_truncate = (iap->ia_valid & ATTR_SIZE) &&
331 case NFS4_CREATE_GUARDED:
332 status = nfserr_exist;
334 case NFS4_CREATE_EXCLUSIVE:
335 if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
336 d_inode(child)->i_atime.tv_sec == v_atime &&
337 d_inode(child)->i_size == 0) {
338 open->op_created = true;
341 status = nfserr_exist;
343 case NFS4_CREATE_EXCLUSIVE4_1:
344 if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
345 d_inode(child)->i_atime.tv_sec == v_atime &&
346 d_inode(child)->i_size == 0) {
347 open->op_created = true;
348 goto set_attr; /* subtle */
350 status = nfserr_exist;
355 if (!IS_POSIXACL(inode))
356 iap->ia_mode &= ~current_umask();
358 host_err = vfs_create(&init_user_ns, inode, child, iap->ia_mode, true);
360 status = nfserrno(host_err);
363 open->op_created = true;
365 /* A newly created file already has a file size of zero. */
366 if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0))
367 iap->ia_valid &= ~ATTR_SIZE;
368 if (nfsd4_create_is_exclusive(open->op_createmode)) {
369 iap->ia_valid = ATTR_MTIME | ATTR_ATIME |
370 ATTR_MTIME_SET|ATTR_ATIME_SET;
371 iap->ia_mtime.tv_sec = v_mtime;
372 iap->ia_atime.tv_sec = v_atime;
373 iap->ia_mtime.tv_nsec = 0;
374 iap->ia_atime.tv_nsec = 0;
378 status = nfsd_create_setattr(rqstp, fhp, resfhp, iap);
382 if (child && !IS_ERR(child))
389 do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
391 struct svc_fh *current_fh = &cstate->current_fh;
395 *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
397 return nfserr_jukebox;
398 fh_init(*resfh, NFS4_FHSIZE);
399 open->op_truncate = false;
401 if (open->op_create) {
402 /* FIXME: check session persistence and pnfs flags.
403 * The nfsv4.1 spec requires the following semantics:
405 * Persistent | pNFS | Server REQUIRED | Client Allowed
406 * Reply Cache | server | |
407 * -------------+--------+-----------------+--------------------
408 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
410 * | | and EXCLUSIVE4 | or EXCLUSIVE4
412 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
413 * yes | no | GUARDED4 | GUARDED4
414 * yes | yes | GUARDED4 | GUARDED4
417 current->fs->umask = open->op_umask;
418 status = nfsd4_create_file(rqstp, current_fh, *resfh, open);
419 current->fs->umask = 0;
421 if (!status && open->op_label.len)
422 nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
425 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
426 * use the returned bitmask to indicate which attributes
427 * we used to store the verifier:
429 if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0)
430 open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
431 FATTR4_WORD1_TIME_MODIFY);
434 * Note this may exit with the parent still locked.
435 * We will hold the lock until nfsd4_open's final
436 * lookup, to prevent renames or unlinks until we've had
437 * a chance to an acquire a delegation if appropriate.
439 status = nfsd_lookup(rqstp, current_fh,
440 open->op_fname, open->op_fnamelen, *resfh);
443 status = nfsd_check_obj_isreg(*resfh);
447 if (is_create_with_attrs(open) && open->op_acl != NULL)
448 do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
450 nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
451 accmode = NFSD_MAY_NOP;
452 if (open->op_created ||
453 open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
454 accmode |= NFSD_MAY_OWNER_OVERRIDE;
455 status = do_open_permission(rqstp, *resfh, open, accmode);
456 set_change_info(&open->op_cinfo, current_fh);
462 do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
464 struct svc_fh *current_fh = &cstate->current_fh;
468 /* We don't know the target directory, and therefore can not
469 * set the change info
472 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
474 nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
476 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
477 (open->op_iattr.ia_size == 0);
479 * In the delegation case, the client is telling us about an
480 * open that it *already* performed locally, some time ago. We
481 * should let it succeed now if possible.
483 * In the case of a CLAIM_FH open, on the other hand, the client
484 * may be counting on us to enforce permissions (the Linux 4.1
485 * client uses this for normal opens, for example).
487 if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
488 accmode = NFSD_MAY_OWNER_OVERRIDE;
490 status = do_open_permission(rqstp, current_fh, open, accmode);
496 copy_clientid(clientid_t *clid, struct nfsd4_session *session)
498 struct nfsd4_sessionid *sid =
499 (struct nfsd4_sessionid *)session->se_sessionid.data;
501 clid->cl_boot = sid->clientid.cl_boot;
502 clid->cl_id = sid->clientid.cl_id;
506 nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
509 struct nfsd4_open *open = &u->open;
511 struct svc_fh *resfh = NULL;
512 struct net *net = SVC_NET(rqstp);
513 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
514 bool reclaim = false;
516 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
517 (int)open->op_fnamelen, open->op_fname,
520 /* This check required by spec. */
521 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
524 open->op_created = false;
527 * Before RECLAIM_COMPLETE done, server should deny new lock
529 if (nfsd4_has_session(cstate) &&
530 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) &&
531 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
534 if (nfsd4_has_session(cstate))
535 copy_clientid(&open->op_clientid, cstate->session);
537 /* check seqid for replay. set nfs4_owner */
538 status = nfsd4_process_open1(cstate, open, nn);
539 if (status == nfserr_replay_me) {
540 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
541 fh_put(&cstate->current_fh);
542 fh_copy_shallow(&cstate->current_fh.fh_handle,
544 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
546 dprintk("nfsd4_open: replay failed"
547 " restoring previous filehandle\n");
549 status = nfserr_replay_me;
553 if (open->op_xdr_error) {
554 status = open->op_xdr_error;
558 status = nfsd4_check_open_attributes(rqstp, cstate, open);
562 /* Openowner is now set, so sequence id will get bumped. Now we need
563 * these checks before we do any creates: */
564 status = nfserr_grace;
565 if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
567 status = nfserr_no_grace;
568 if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
571 switch (open->op_claim_type) {
572 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
573 case NFS4_OPEN_CLAIM_NULL:
574 status = do_open_lookup(rqstp, cstate, open, &resfh);
578 case NFS4_OPEN_CLAIM_PREVIOUS:
579 status = nfs4_check_open_reclaim(cstate->clp);
582 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
585 case NFS4_OPEN_CLAIM_FH:
586 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
587 status = do_open_fhandle(rqstp, cstate, open);
590 resfh = &cstate->current_fh;
592 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
593 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
594 dprintk("NFSD: unsupported OPEN claim type %d\n",
595 open->op_claim_type);
596 status = nfserr_notsupp;
599 dprintk("NFSD: Invalid OPEN claim type %d\n",
600 open->op_claim_type);
601 status = nfserr_inval;
605 * nfsd4_process_open2() does the actual opening of the file. If
606 * successful, it (1) truncates the file if open->op_truncate was
607 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
609 status = nfsd4_process_open2(rqstp, resfh, open);
610 WARN(status && open->op_created,
611 "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
612 be32_to_cpu(status));
613 if (reclaim && !status)
614 nn->somebody_reclaimed = true;
616 if (resfh && resfh != &cstate->current_fh) {
617 fh_dup2(&cstate->current_fh, resfh);
621 nfsd4_cleanup_open_state(cstate, open);
622 nfsd4_bump_seqid(cstate, status);
627 * OPEN is the only seqid-mutating operation whose decoding can fail
628 * with a seqid-mutating error (specifically, decoding of user names in
629 * the attributes). Therefore we have to do some processing to look up
630 * the stateowner so that we can bump the seqid.
632 static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
634 struct nfsd4_open *open = &op->u.open;
636 if (!seqid_mutating_err(ntohl(op->status)))
638 if (nfsd4_has_session(cstate))
640 open->op_xdr_error = op->status;
641 return nfsd4_open(rqstp, cstate, &op->u);
645 * filehandle-manipulating ops.
648 nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
651 u->getfh = &cstate->current_fh;
656 nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
659 struct nfsd4_putfh *putfh = &u->putfh;
662 fh_put(&cstate->current_fh);
663 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
664 memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval,
666 ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
667 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
668 if (ret == nfserr_stale && putfh->no_verify) {
669 SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN);
677 nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
682 fh_put(&cstate->current_fh);
683 status = exp_pseudoroot(rqstp, &cstate->current_fh);
688 nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
691 if (!cstate->save_fh.fh_dentry)
692 return nfserr_restorefh;
694 fh_dup2(&cstate->current_fh, &cstate->save_fh);
695 if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) {
696 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
697 SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
703 nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
706 fh_dup2(&cstate->save_fh, &cstate->current_fh);
707 if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
708 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
709 SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG);
718 nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
721 struct nfsd4_access *access = &u->access;
724 access_full = NFS3_ACCESS_FULL;
725 if (cstate->minorversion >= 2)
726 access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
729 if (access->ac_req_access & ~access_full)
732 access->ac_resp_access = access->ac_req_access;
733 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
734 &access->ac_supported);
737 static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
739 __be32 *verf = (__be32 *)verifier->data;
741 BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data));
743 nfsd_copy_write_verifier(verf, net_generic(net, nfsd_net_id));
747 nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
750 struct nfsd4_commit *commit = &u->commit;
752 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
754 (__be32 *)commit->co_verf.data);
758 nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
761 struct nfsd4_create *create = &u->create;
766 fh_init(&resfh, NFS4_FHSIZE);
768 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
772 status = check_attr_support(rqstp, cstate, create->cr_bmval,
777 current->fs->umask = create->cr_umask;
778 switch (create->cr_type) {
780 status = nfsd_symlink(rqstp, &cstate->current_fh,
781 create->cr_name, create->cr_namelen,
782 create->cr_data, &resfh);
786 status = nfserr_inval;
787 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
788 if (MAJOR(rdev) != create->cr_specdata1 ||
789 MINOR(rdev) != create->cr_specdata2)
791 status = nfsd_create(rqstp, &cstate->current_fh,
792 create->cr_name, create->cr_namelen,
793 &create->cr_iattr, S_IFBLK, rdev, &resfh);
797 status = nfserr_inval;
798 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
799 if (MAJOR(rdev) != create->cr_specdata1 ||
800 MINOR(rdev) != create->cr_specdata2)
802 status = nfsd_create(rqstp, &cstate->current_fh,
803 create->cr_name, create->cr_namelen,
804 &create->cr_iattr,S_IFCHR, rdev, &resfh);
808 status = nfsd_create(rqstp, &cstate->current_fh,
809 create->cr_name, create->cr_namelen,
810 &create->cr_iattr, S_IFSOCK, 0, &resfh);
814 status = nfsd_create(rqstp, &cstate->current_fh,
815 create->cr_name, create->cr_namelen,
816 &create->cr_iattr, S_IFIFO, 0, &resfh);
820 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
821 status = nfsd_create(rqstp, &cstate->current_fh,
822 create->cr_name, create->cr_namelen,
823 &create->cr_iattr, S_IFDIR, 0, &resfh);
827 status = nfserr_badtype;
833 if (create->cr_label.len)
834 nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
836 if (create->cr_acl != NULL)
837 do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
840 fh_unlock(&cstate->current_fh);
841 set_change_info(&create->cr_cinfo, &cstate->current_fh);
842 fh_dup2(&cstate->current_fh, &resfh);
846 current->fs->umask = 0;
851 nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
854 struct nfsd4_getattr *getattr = &u->getattr;
857 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
861 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
864 getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
865 getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
866 getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
868 getattr->ga_fhp = &cstate->current_fh;
873 nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
876 struct nfsd4_link *link = &u->link;
879 status = nfsd_link(rqstp, &cstate->current_fh,
880 link->li_name, link->li_namelen, &cstate->save_fh);
882 set_change_info(&link->li_cinfo, &cstate->current_fh);
886 static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
888 struct svc_fh tmp_fh;
891 fh_init(&tmp_fh, NFS4_FHSIZE);
892 ret = exp_pseudoroot(rqstp, &tmp_fh);
895 if (tmp_fh.fh_dentry == fh->fh_dentry) {
900 return nfsd_lookup(rqstp, fh, "..", 2, fh);
904 nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
907 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
911 nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
914 return nfsd_lookup(rqstp, &cstate->current_fh,
915 u->lookup.lo_name, u->lookup.lo_len,
916 &cstate->current_fh);
920 nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
923 struct nfsd4_read *read = &u->read;
928 trace_nfsd_read_start(rqstp, &cstate->current_fh,
929 read->rd_offset, read->rd_length);
931 read->rd_length = min_t(u32, read->rd_length, svc_max_payload(rqstp));
932 if (read->rd_offset > (u64)OFFSET_MAX)
933 read->rd_offset = (u64)OFFSET_MAX;
934 if (read->rd_offset + read->rd_length > (u64)OFFSET_MAX)
935 read->rd_length = (u64)OFFSET_MAX - read->rd_offset;
938 * If we do a zero copy read, then a client will see read data
939 * that reflects the state of the file *after* performing the
940 * following compound.
942 * To ensure proper ordering, we therefore turn off zero copy if
943 * the client wants us to do more in this compound:
945 if (!nfsd4_last_compound_op(rqstp))
946 clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
949 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
950 &read->rd_stateid, RD_STATE,
953 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
958 read->rd_rqstp = rqstp;
959 read->rd_fhp = &cstate->current_fh;
965 nfsd4_read_release(union nfsd4_op_u *u)
968 nfsd_file_put(u->read.rd_nf);
969 trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
970 u->read.rd_offset, u->read.rd_length);
974 nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
977 struct nfsd4_readdir *readdir = &u->readdir;
978 u64 cookie = readdir->rd_cookie;
979 static const nfs4_verifier zeroverf;
981 /* no need to check permission - this will be done in nfsd_readdir() */
983 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
986 readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
987 readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
988 readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
990 if ((cookie == 1) || (cookie == 2) ||
991 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
992 return nfserr_bad_cookie;
994 readdir->rd_rqstp = rqstp;
995 readdir->rd_fhp = &cstate->current_fh;
1000 nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1001 union nfsd4_op_u *u)
1003 u->readlink.rl_rqstp = rqstp;
1004 u->readlink.rl_fhp = &cstate->current_fh;
1009 nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1010 union nfsd4_op_u *u)
1012 struct nfsd4_remove *remove = &u->remove;
1015 if (opens_in_grace(SVC_NET(rqstp)))
1016 return nfserr_grace;
1017 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
1018 remove->rm_name, remove->rm_namelen);
1020 fh_unlock(&cstate->current_fh);
1021 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
1027 nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1028 union nfsd4_op_u *u)
1030 struct nfsd4_rename *rename = &u->rename;
1033 if (opens_in_grace(SVC_NET(rqstp)))
1034 return nfserr_grace;
1035 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
1036 rename->rn_snamelen, &cstate->current_fh,
1037 rename->rn_tname, rename->rn_tnamelen);
1040 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
1041 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
1046 nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1047 union nfsd4_op_u *u)
1049 struct nfsd4_secinfo *secinfo = &u->secinfo;
1050 struct svc_export *exp;
1051 struct dentry *dentry;
1054 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
1057 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
1058 secinfo->si_name, secinfo->si_namelen,
1062 fh_unlock(&cstate->current_fh);
1063 if (d_really_is_negative(dentry)) {
1067 secinfo->si_exp = exp;
1069 if (cstate->minorversion)
1070 /* See rfc 5661 section 2.6.3.1.1.8 */
1071 fh_put(&cstate->current_fh);
1076 nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1077 union nfsd4_op_u *u)
1081 switch (u->secinfo_no_name.sin_style) {
1082 case NFS4_SECINFO_STYLE4_CURRENT_FH:
1084 case NFS4_SECINFO_STYLE4_PARENT:
1085 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
1090 return nfserr_inval;
1093 u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
1094 fh_put(&cstate->current_fh);
1099 nfsd4_secinfo_release(union nfsd4_op_u *u)
1101 if (u->secinfo.si_exp)
1102 exp_put(u->secinfo.si_exp);
1106 nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
1108 if (u->secinfo_no_name.sin_exp)
1109 exp_put(u->secinfo_no_name.sin_exp);
1113 nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1114 union nfsd4_op_u *u)
1116 struct nfsd4_setattr *setattr = &u->setattr;
1117 __be32 status = nfs_ok;
1120 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
1121 status = nfs4_preprocess_stateid_op(rqstp, cstate,
1122 &cstate->current_fh, &setattr->sa_stateid,
1123 WR_STATE, NULL, NULL);
1125 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
1129 err = fh_want_write(&cstate->current_fh);
1131 return nfserrno(err);
1134 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
1139 if (setattr->sa_acl != NULL)
1140 status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
1144 if (setattr->sa_label.len)
1145 status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
1146 &setattr->sa_label);
1149 status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
1152 fh_drop_write(&cstate->current_fh);
1157 nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1158 union nfsd4_op_u *u)
1160 struct nfsd4_write *write = &u->write;
1161 stateid_t *stateid = &write->wr_stateid;
1162 struct nfsd_file *nf = NULL;
1163 __be32 status = nfs_ok;
1167 if (write->wr_offset > (u64)OFFSET_MAX ||
1168 write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
1171 cnt = write->wr_buflen;
1172 trace_nfsd_write_start(rqstp, &cstate->current_fh,
1173 write->wr_offset, cnt);
1174 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1175 stateid, WR_STATE, &nf, NULL);
1177 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1181 write->wr_how_written = write->wr_stable_how;
1183 nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
1184 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1186 status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
1187 write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
1188 write->wr_how_written,
1189 (__be32 *)write->wr_verifier.data);
1192 write->wr_bytes_written = cnt;
1193 trace_nfsd_write_done(rqstp, &cstate->current_fh,
1194 write->wr_offset, cnt);
1199 nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1200 stateid_t *src_stateid, struct nfsd_file **src,
1201 stateid_t *dst_stateid, struct nfsd_file **dst)
1205 if (!cstate->save_fh.fh_dentry)
1206 return nfserr_nofilehandle;
1208 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
1209 src_stateid, RD_STATE, src, NULL);
1211 dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1215 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1216 dst_stateid, WR_STATE, dst, NULL);
1218 dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1222 /* fix up for NFS-specific error code */
1223 if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
1224 !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
1225 status = nfserr_wrong_type;
1232 nfsd_file_put(*dst);
1234 nfsd_file_put(*src);
1239 nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1240 union nfsd4_op_u *u)
1242 struct nfsd4_clone *clone = &u->clone;
1243 struct nfsd_file *src, *dst;
1246 status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
1247 &clone->cl_dst_stateid, &dst);
1251 status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos,
1252 dst, clone->cl_dst_pos, clone->cl_count,
1253 EX_ISSYNC(cstate->current_fh.fh_export));
1261 void nfs4_put_copy(struct nfsd4_copy *copy)
1263 if (!refcount_dec_and_test(©->refcount))
1269 check_and_set_stop_copy(struct nfsd4_copy *copy)
1273 spin_lock(©->cp_clp->async_lock);
1274 value = copy->stopped;
1276 copy->stopped = true;
1277 spin_unlock(©->cp_clp->async_lock);
1281 static void nfsd4_stop_copy(struct nfsd4_copy *copy)
1283 /* only 1 thread should stop the copy */
1284 if (!check_and_set_stop_copy(copy))
1285 kthread_stop(copy->copy_task);
1286 nfs4_put_copy(copy);
1289 static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp)
1291 struct nfsd4_copy *copy = NULL;
1293 spin_lock(&clp->async_lock);
1294 if (!list_empty(&clp->async_copies)) {
1295 copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
1297 refcount_inc(©->refcount);
1299 spin_unlock(&clp->async_lock);
1303 void nfsd4_shutdown_copy(struct nfs4_client *clp)
1305 struct nfsd4_copy *copy;
1307 while ((copy = nfsd4_get_copy(clp)) != NULL)
1308 nfsd4_stop_copy(copy);
1310 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
1312 extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1313 struct nfs_fh *src_fh,
1314 nfs4_stateid *stateid);
1315 extern void nfs42_ssc_close(struct file *filep);
1317 extern void nfs_sb_deactive(struct super_block *sb);
1319 #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
1322 * setup a work entry in the ssc delayed unmount list.
1324 static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr,
1325 struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt)
1327 struct nfsd4_ssc_umount_item *ni = NULL;
1328 struct nfsd4_ssc_umount_item *work = NULL;
1329 struct nfsd4_ssc_umount_item *tmp;
1334 work = kzalloc(sizeof(*work), GFP_KERNEL);
1336 spin_lock(&nn->nfsd_ssc_lock);
1337 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1338 if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
1341 if (ni->nsui_busy) {
1342 /* wait - and try again */
1343 prepare_to_wait(&nn->nfsd_ssc_waitq, &wait,
1344 TASK_INTERRUPTIBLE);
1345 spin_unlock(&nn->nfsd_ssc_lock);
1347 /* allow 20secs for mount/unmount for now - revisit */
1348 if (signal_pending(current) ||
1349 (schedule_timeout(20*HZ) == 0)) {
1351 return nfserr_eagain;
1353 finish_wait(&nn->nfsd_ssc_waitq, &wait);
1356 *ss_mnt = ni->nsui_vfsmount;
1357 refcount_inc(&ni->nsui_refcnt);
1358 spin_unlock(&nn->nfsd_ssc_lock);
1361 /* return vfsmount in ss_mnt */
1365 strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
1366 refcount_set(&work->nsui_refcnt, 2);
1367 work->nsui_busy = true;
1368 list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list);
1371 spin_unlock(&nn->nfsd_ssc_lock);
1375 static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn,
1376 struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt)
1378 /* set nsui_vfsmount, clear busy flag and wakeup waiters */
1379 spin_lock(&nn->nfsd_ssc_lock);
1380 work->nsui_vfsmount = ss_mnt;
1381 work->nsui_busy = false;
1382 wake_up_all(&nn->nfsd_ssc_waitq);
1383 spin_unlock(&nn->nfsd_ssc_lock);
1386 static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn,
1387 struct nfsd4_ssc_umount_item *work)
1389 spin_lock(&nn->nfsd_ssc_lock);
1390 list_del(&work->nsui_list);
1391 wake_up_all(&nn->nfsd_ssc_waitq);
1392 spin_unlock(&nn->nfsd_ssc_lock);
1397 * Support one copy source server for now.
1400 nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
1401 struct vfsmount **mount)
1403 struct file_system_type *type;
1404 struct vfsmount *ss_mnt;
1405 struct nfs42_netaddr *naddr;
1406 struct sockaddr_storage tmp_addr;
1407 size_t tmp_addrlen, match_netid_len = 3;
1408 char *startsep = "", *endsep = "", *match_netid = "tcp";
1409 char *ipaddr, *dev_name, *raw_data;
1411 __be32 status = nfserr_inval;
1412 struct nfsd4_ssc_umount_item *work = NULL;
1413 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1415 naddr = &nss->u.nl4_addr;
1416 tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
1418 (struct sockaddr *)&tmp_addr,
1420 if (tmp_addrlen == 0)
1423 if (tmp_addr.ss_family == AF_INET6) {
1426 match_netid = "tcp6";
1427 match_netid_len = 4;
1430 if (naddr->netid_len != match_netid_len ||
1431 strncmp(naddr->netid, match_netid, naddr->netid_len))
1434 /* Construct the raw data for the vfs_kern_mount call */
1435 len = RPC_MAX_ADDRBUFLEN + 1;
1436 ipaddr = kzalloc(len, GFP_KERNEL);
1440 rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len);
1442 /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
1444 raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr);
1445 raw_data = kzalloc(raw_len, GFP_KERNEL);
1447 goto out_free_ipaddr;
1449 snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr);
1451 status = nfserr_nodev;
1452 type = get_fs_type("nfs");
1454 goto out_free_rawdata;
1456 /* Set the server:<export> for the vfs_kern_mount call */
1457 dev_name = kzalloc(len + 5, GFP_KERNEL);
1459 goto out_free_rawdata;
1460 snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
1462 status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt);
1464 goto out_free_devname;
1468 /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
1469 ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
1470 module_put(type->owner);
1471 if (IS_ERR(ss_mnt)) {
1472 status = nfserr_nodev;
1474 nfsd4_ssc_cancel_dul_work(nn, work);
1475 goto out_free_devname;
1478 nfsd4_ssc_update_dul_work(nn, work, ss_mnt);
1494 nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1496 nfs_do_sb_deactive(ss_mnt->mnt_sb);
1501 * Verify COPY destination stateid.
1503 * Connect to the source server with NFSv4.1.
1504 * Create the source struct file for nfsd_copy_range.
1505 * Called with COPY cstate:
1506 * SAVED_FH: source filehandle
1507 * CURRENT_FH: destination filehandle
1510 nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1511 struct nfsd4_compound_state *cstate,
1512 struct nfsd4_copy *copy, struct vfsmount **mount)
1514 struct svc_fh *s_fh = NULL;
1515 stateid_t *s_stid = ©->cp_src_stateid;
1516 __be32 status = nfserr_inval;
1518 /* Verify the destination stateid and set dst struct file*/
1519 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1520 ©->cp_dst_stateid,
1521 WR_STATE, ©->nf_dst, NULL);
1525 status = nfsd4_interssc_connect(©->cp_src, rqstp, mount);
1529 s_fh = &cstate->save_fh;
1531 copy->c_fh.size = s_fh->fh_handle.fh_size;
1532 memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size);
1533 copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
1534 memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
1535 sizeof(stateid_opaque_t));
1543 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1544 struct nfsd_file *dst)
1548 struct nfsd4_ssc_umount_item *tmp;
1549 struct nfsd4_ssc_umount_item *ni = NULL;
1550 struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
1552 nfs42_ssc_close(src->nf_file);
1560 spin_lock(&nn->nfsd_ssc_lock);
1561 timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
1562 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1563 if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
1564 list_del(&ni->nsui_list);
1566 * vfsmount can be shared by multiple exports,
1567 * decrement refcnt. If the count drops to 1 it
1568 * will be unmounted when nsui_expire expires.
1570 refcount_dec(&ni->nsui_refcnt);
1571 ni->nsui_expire = jiffies + timeout;
1572 list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list);
1577 spin_unlock(&nn->nfsd_ssc_lock);
1584 #else /* CONFIG_NFSD_V4_2_INTER_SSC */
1587 nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1588 struct nfsd4_compound_state *cstate,
1589 struct nfsd4_copy *copy,
1590 struct vfsmount **mount)
1593 return nfserr_inval;
1597 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
1598 struct nfsd_file *dst)
1603 nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1607 static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1608 struct nfs_fh *src_fh,
1609 nfs4_stateid *stateid)
1613 #endif /* CONFIG_NFSD_V4_2_INTER_SSC */
1616 nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
1617 struct nfsd4_compound_state *cstate,
1618 struct nfsd4_copy *copy)
1620 return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid,
1621 ©->nf_src, ©->cp_dst_stateid,
1626 nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst)
1632 static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
1634 struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
1636 nfs4_put_copy(copy);
1639 static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
1640 struct rpc_task *task)
1645 static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
1646 .release = nfsd4_cb_offload_release,
1647 .done = nfsd4_cb_offload_done
1650 static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
1652 copy->cp_res.wr_stable_how =
1653 copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE;
1654 copy->cp_synchronous = sync;
1655 gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net);
1658 static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
1660 struct file *dst = copy->nf_dst->nf_file;
1661 struct file *src = copy->nf_src->nf_file;
1663 ssize_t bytes_copied = 0;
1664 u64 bytes_total = copy->cp_count;
1665 u64 src_pos = copy->cp_src_pos;
1666 u64 dst_pos = copy->cp_dst_pos;
1669 /* See RFC 7862 p.67: */
1670 if (bytes_total == 0)
1671 bytes_total = ULLONG_MAX;
1673 if (kthread_should_stop())
1675 bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos,
1677 if (bytes_copied <= 0)
1679 bytes_total -= bytes_copied;
1680 copy->cp_res.wr_bytes_written += bytes_copied;
1681 src_pos += bytes_copied;
1682 dst_pos += bytes_copied;
1683 } while (bytes_total > 0 && !copy->cp_synchronous);
1684 /* for a non-zero asynchronous copy do a commit of data */
1685 if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) {
1686 since = READ_ONCE(dst->f_wb_err);
1687 status = vfs_fsync_range(dst, copy->cp_dst_pos,
1688 copy->cp_res.wr_bytes_written, 0);
1690 status = filemap_check_wb_err(dst->f_mapping, since);
1692 copy->committed = true;
1694 return bytes_copied;
1697 static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
1702 bytes = _nfsd_copy_file_range(copy);
1703 /* for async copy, we ignore the error, client can always retry
1706 if (bytes < 0 && !copy->cp_res.wr_bytes_written)
1707 status = nfserrno(bytes);
1709 nfsd4_init_copy_res(copy, sync);
1713 if (!copy->cp_intra) /* Inter server SSC */
1714 nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src,
1717 nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
1722 static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
1724 dst->cp_src_pos = src->cp_src_pos;
1725 dst->cp_dst_pos = src->cp_dst_pos;
1726 dst->cp_count = src->cp_count;
1727 dst->cp_synchronous = src->cp_synchronous;
1728 memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
1729 memcpy(&dst->fh, &src->fh, sizeof(src->fh));
1730 dst->cp_clp = src->cp_clp;
1731 dst->nf_dst = nfsd_file_get(src->nf_dst);
1732 dst->cp_intra = src->cp_intra;
1733 if (src->cp_intra) /* for inter, file_src doesn't exist yet */
1734 dst->nf_src = nfsd_file_get(src->nf_src);
1736 memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
1737 memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server));
1738 memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid));
1739 memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh));
1740 dst->ss_mnt = src->ss_mnt;
1743 static void cleanup_async_copy(struct nfsd4_copy *copy)
1745 nfs4_free_copy_state(copy);
1746 nfsd_file_put(copy->nf_dst);
1748 nfsd_file_put(copy->nf_src);
1749 spin_lock(©->cp_clp->async_lock);
1750 list_del(©->copies);
1751 spin_unlock(©->cp_clp->async_lock);
1752 nfs4_put_copy(copy);
1755 static int nfsd4_do_async_copy(void *data)
1757 struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1758 struct nfsd4_copy *cb_copy;
1760 if (!copy->cp_intra) { /* Inter server SSC */
1761 copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL);
1762 if (!copy->nf_src) {
1763 copy->nfserr = nfserr_serverfault;
1764 nfsd4_interssc_disconnect(copy->ss_mnt);
1767 copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh,
1769 if (IS_ERR(copy->nf_src->nf_file)) {
1770 copy->nfserr = nfserr_offload_denied;
1771 nfsd4_interssc_disconnect(copy->ss_mnt);
1776 copy->nfserr = nfsd4_do_copy(copy, 0);
1778 cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1781 refcount_set(&cb_copy->refcount, 1);
1782 memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res));
1783 cb_copy->cp_clp = copy->cp_clp;
1784 cb_copy->nfserr = copy->nfserr;
1785 memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh));
1786 nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp,
1787 &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD);
1788 trace_nfsd_cb_offload(copy->cp_clp, ©->cp_res.cb_stateid,
1789 ©->fh, copy->cp_count, copy->nfserr);
1790 nfsd4_run_cb(&cb_copy->cp_cb);
1792 if (!copy->cp_intra)
1793 kfree(copy->nf_src);
1794 cleanup_async_copy(copy);
1799 nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1800 union nfsd4_op_u *u)
1802 struct nfsd4_copy *copy = &u->copy;
1804 struct nfsd4_copy *async_copy = NULL;
1806 if (!copy->cp_intra) { /* Inter server SSC */
1807 if (!inter_copy_offload_enable || copy->cp_synchronous) {
1808 status = nfserr_notsupp;
1811 status = nfsd4_setup_inter_ssc(rqstp, cstate, copy,
1814 return nfserr_offload_denied;
1816 status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
1821 copy->cp_clp = cstate->clp;
1822 memcpy(©->fh, &cstate->current_fh.fh_handle,
1823 sizeof(struct knfsd_fh));
1824 if (!copy->cp_synchronous) {
1825 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1827 status = nfserrno(-ENOMEM);
1828 async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1831 if (!nfs4_init_copy_state(nn, copy))
1833 refcount_set(&async_copy->refcount, 1);
1834 memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid,
1835 sizeof(copy->cp_res.cb_stateid));
1836 dup_copy_fields(copy, async_copy);
1837 async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
1838 async_copy, "%s", "copy thread");
1839 if (IS_ERR(async_copy->copy_task))
1841 spin_lock(&async_copy->cp_clp->async_lock);
1842 list_add(&async_copy->copies,
1843 &async_copy->cp_clp->async_copies);
1844 spin_unlock(&async_copy->cp_clp->async_lock);
1845 wake_up_process(async_copy->copy_task);
1848 status = nfsd4_do_copy(copy, 1);
1854 cleanup_async_copy(async_copy);
1855 status = nfserrno(-ENOMEM);
1856 if (!copy->cp_intra)
1857 nfsd4_interssc_disconnect(copy->ss_mnt);
1862 find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
1864 struct nfsd4_copy *copy;
1866 spin_lock(&clp->async_lock);
1867 list_for_each_entry(copy, &clp->async_copies, copies) {
1868 if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE))
1870 refcount_inc(©->refcount);
1871 spin_unlock(&clp->async_lock);
1874 spin_unlock(&clp->async_lock);
1879 nfsd4_offload_cancel(struct svc_rqst *rqstp,
1880 struct nfsd4_compound_state *cstate,
1881 union nfsd4_op_u *u)
1883 struct nfsd4_offload_status *os = &u->offload_status;
1884 struct nfsd4_copy *copy;
1885 struct nfs4_client *clp = cstate->clp;
1887 copy = find_async_copy(clp, &os->stateid);
1889 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1891 return manage_cpntf_state(nn, &os->stateid, clp, NULL);
1893 nfsd4_stop_copy(copy);
1899 nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1900 union nfsd4_op_u *u)
1902 struct nfsd4_copy_notify *cn = &u->copy_notify;
1904 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1905 struct nfs4_stid *stid;
1906 struct nfs4_cpntf_state *cps;
1907 struct nfs4_client *clp = cstate->clp;
1909 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1910 &cn->cpn_src_stateid, RD_STATE, NULL,
1915 cn->cpn_sec = nn->nfsd4_lease;
1918 status = nfserrno(-ENOMEM);
1919 cps = nfs4_alloc_init_cpntf_state(nn, stid);
1922 memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t));
1923 memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t));
1924 memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t));
1926 /* For now, only return one server address in cpn_src, the
1927 * address used by the client to connect to this server.
1929 cn->cpn_src.nl4_type = NL4_NETADDR;
1930 status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr,
1931 &cn->cpn_src.u.nl4_addr);
1932 WARN_ON_ONCE(status);
1934 nfs4_put_cpntf_state(nn, cps);
1938 nfs4_put_stid(stid);
1943 nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1944 struct nfsd4_fallocate *fallocate, int flags)
1947 struct nfsd_file *nf;
1949 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1950 &fallocate->falloc_stateid,
1951 WR_STATE, &nf, NULL);
1952 if (status != nfs_ok) {
1953 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
1957 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
1958 fallocate->falloc_offset,
1959 fallocate->falloc_length,
1965 nfsd4_offload_status(struct svc_rqst *rqstp,
1966 struct nfsd4_compound_state *cstate,
1967 union nfsd4_op_u *u)
1969 struct nfsd4_offload_status *os = &u->offload_status;
1971 struct nfsd4_copy *copy;
1972 struct nfs4_client *clp = cstate->clp;
1974 copy = find_async_copy(clp, &os->stateid);
1976 os->count = copy->cp_res.wr_bytes_written;
1977 nfs4_put_copy(copy);
1979 status = nfserr_bad_stateid;
1985 nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1986 union nfsd4_op_u *u)
1988 return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
1992 nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1993 union nfsd4_op_u *u)
1995 return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
1996 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
2000 nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2001 union nfsd4_op_u *u)
2003 struct nfsd4_seek *seek = &u->seek;
2006 struct nfsd_file *nf;
2008 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
2009 &seek->seek_stateid,
2010 RD_STATE, &nf, NULL);
2012 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
2016 switch (seek->seek_whence) {
2017 case NFS4_CONTENT_DATA:
2020 case NFS4_CONTENT_HOLE:
2024 status = nfserr_union_notsupp;
2029 * Note: This call does change file->f_pos, but nothing in NFSD
2030 * should ever file->f_pos.
2032 seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
2033 if (seek->seek_pos < 0)
2034 status = nfserrno(seek->seek_pos);
2035 else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
2036 seek->seek_eof = true;
2043 /* This routine never returns NFS_OK! If there are no other errors, it
2044 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
2045 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
2046 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
2049 _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2050 struct nfsd4_verify *verify)
2056 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
2060 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
2064 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
2065 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
2066 return nfserr_inval;
2067 if (verify->ve_attrlen & 3)
2068 return nfserr_inval;
2071 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
2073 count = 4 + (verify->ve_attrlen >> 2);
2074 buf = kmalloc(count << 2, GFP_KERNEL);
2076 return nfserr_jukebox;
2079 status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
2080 cstate->current_fh.fh_export,
2081 cstate->current_fh.fh_dentry,
2085 * If nfsd4_encode_fattr() ran out of space, assume that's because
2086 * the attributes are longer (hence different) than those given:
2088 if (status == nfserr_resource)
2089 status = nfserr_not_same;
2094 p = buf + 1 + ntohl(buf[0]);
2095 status = nfserr_not_same;
2096 if (ntohl(*p++) != verify->ve_attrlen)
2098 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
2099 status = nfserr_same;
2107 nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2108 union nfsd4_op_u *u)
2112 status = _nfsd4_verify(rqstp, cstate, &u->verify);
2113 return status == nfserr_not_same ? nfs_ok : status;
2117 nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2118 union nfsd4_op_u *u)
2122 status = _nfsd4_verify(rqstp, cstate, &u->nverify);
2123 return status == nfserr_same ? nfs_ok : status;
2126 #ifdef CONFIG_NFSD_PNFS
2127 static const struct nfsd4_layout_ops *
2128 nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
2130 if (!exp->ex_layout_types) {
2131 dprintk("%s: export does not support pNFS\n", __func__);
2135 if (layout_type >= LAYOUT_TYPE_MAX ||
2136 !(exp->ex_layout_types & (1 << layout_type))) {
2137 dprintk("%s: layout type %d not supported\n",
2138 __func__, layout_type);
2142 return nfsd4_layout_ops[layout_type];
2146 nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
2147 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2149 struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
2150 const struct nfsd4_layout_ops *ops;
2151 struct nfsd4_deviceid_map *map;
2152 struct svc_export *exp;
2155 dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
2157 gdp->gd_layout_type,
2158 gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
2161 map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
2163 dprintk("%s: couldn't find device ID to export mapping!\n",
2165 return nfserr_noent;
2168 exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
2170 dprintk("%s: could not find device id\n", __func__);
2171 return nfserr_noent;
2174 nfserr = nfserr_layoutunavailable;
2175 ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
2180 if (gdp->gd_maxcount != 0) {
2181 nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
2182 rqstp, cstate->clp, gdp);
2185 gdp->gd_notify_types &= ops->notify_types;
2192 nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
2194 kfree(u->getdeviceinfo.gd_device);
2198 nfsd4_layoutget(struct svc_rqst *rqstp,
2199 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2201 struct nfsd4_layoutget *lgp = &u->layoutget;
2202 struct svc_fh *current_fh = &cstate->current_fh;
2203 const struct nfsd4_layout_ops *ops;
2204 struct nfs4_layout_stateid *ls;
2206 int accmode = NFSD_MAY_READ_IF_EXEC;
2208 switch (lgp->lg_seg.iomode) {
2210 accmode |= NFSD_MAY_READ;
2213 accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
2216 dprintk("%s: invalid iomode %d\n",
2217 __func__, lgp->lg_seg.iomode);
2218 nfserr = nfserr_badiomode;
2222 nfserr = fh_verify(rqstp, current_fh, 0, accmode);
2226 nfserr = nfserr_layoutunavailable;
2227 ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
2232 * Verify minlength and range as per RFC5661:
2233 * o If loga_length is less than loga_minlength,
2234 * the metadata server MUST return NFS4ERR_INVAL.
2235 * o If the sum of loga_offset and loga_minlength exceeds
2236 * NFS4_UINT64_MAX, and loga_minlength is not
2237 * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
2238 * o If the sum of loga_offset and loga_length exceeds
2239 * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
2240 * the error NFS4ERR_INVAL MUST result.
2242 nfserr = nfserr_inval;
2243 if (lgp->lg_seg.length < lgp->lg_minlength ||
2244 (lgp->lg_minlength != NFS4_MAX_UINT64 &&
2245 lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
2246 (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
2247 lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
2249 if (lgp->lg_seg.length == 0)
2252 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
2253 true, lgp->lg_layout_type, &ls);
2255 trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
2259 nfserr = nfserr_recallconflict;
2260 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
2263 nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
2268 nfserr = nfsd4_insert_layout(lgp, ls);
2271 mutex_unlock(&ls->ls_mutex);
2272 nfs4_put_stid(&ls->ls_stid);
2278 nfsd4_layoutget_release(union nfsd4_op_u *u)
2280 kfree(u->layoutget.lg_content);
2284 nfsd4_layoutcommit(struct svc_rqst *rqstp,
2285 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2287 struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
2288 const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
2289 struct svc_fh *current_fh = &cstate->current_fh;
2290 const struct nfsd4_layout_ops *ops;
2291 loff_t new_size = lcp->lc_last_wr + 1;
2292 struct inode *inode;
2293 struct nfs4_layout_stateid *ls;
2296 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
2300 nfserr = nfserr_layoutunavailable;
2301 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
2304 inode = d_inode(current_fh->fh_dentry);
2306 nfserr = nfserr_inval;
2307 if (new_size <= seg->offset) {
2308 dprintk("pnfsd: last write before layout segment\n");
2311 if (new_size > seg->offset + seg->length) {
2312 dprintk("pnfsd: last write beyond layout segment\n");
2315 if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
2316 dprintk("pnfsd: layoutcommit beyond EOF\n");
2320 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
2321 false, lcp->lc_layout_type,
2324 trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
2325 /* fixup error code as per RFC5661 */
2326 if (nfserr == nfserr_bad_stateid)
2327 nfserr = nfserr_badlayout;
2331 /* LAYOUTCOMMIT does not require any serialization */
2332 mutex_unlock(&ls->ls_mutex);
2334 if (new_size > i_size_read(inode)) {
2335 lcp->lc_size_chg = 1;
2336 lcp->lc_newsize = new_size;
2338 lcp->lc_size_chg = 0;
2341 nfserr = ops->proc_layoutcommit(inode, lcp);
2342 nfs4_put_stid(&ls->ls_stid);
2348 nfsd4_layoutreturn(struct svc_rqst *rqstp,
2349 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2351 struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
2352 struct svc_fh *current_fh = &cstate->current_fh;
2355 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
2359 nfserr = nfserr_layoutunavailable;
2360 if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
2363 switch (lrp->lr_seg.iomode) {
2369 dprintk("%s: invalid iomode %d\n", __func__,
2370 lrp->lr_seg.iomode);
2371 nfserr = nfserr_inval;
2375 switch (lrp->lr_return_type) {
2377 nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
2381 nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
2384 dprintk("%s: invalid return_type %d\n", __func__,
2385 lrp->lr_return_type);
2386 nfserr = nfserr_inval;
2392 #endif /* CONFIG_NFSD_PNFS */
2395 nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2396 union nfsd4_op_u *u)
2398 struct nfsd4_getxattr *getxattr = &u->getxattr;
2400 return nfsd_getxattr(rqstp, &cstate->current_fh,
2401 getxattr->getxa_name, &getxattr->getxa_buf,
2402 &getxattr->getxa_len);
2406 nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2407 union nfsd4_op_u *u)
2409 struct nfsd4_setxattr *setxattr = &u->setxattr;
2412 if (opens_in_grace(SVC_NET(rqstp)))
2413 return nfserr_grace;
2415 ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
2416 setxattr->setxa_buf, setxattr->setxa_len,
2417 setxattr->setxa_flags);
2420 set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
2426 nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2427 union nfsd4_op_u *u)
2430 * Get the entire list, then copy out only the user attributes
2431 * in the encode function.
2433 return nfsd_listxattr(rqstp, &cstate->current_fh,
2434 &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
2438 nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2439 union nfsd4_op_u *u)
2441 struct nfsd4_removexattr *removexattr = &u->removexattr;
2444 if (opens_in_grace(SVC_NET(rqstp)))
2445 return nfserr_grace;
2447 ret = nfsd_removexattr(rqstp, &cstate->current_fh,
2448 removexattr->rmxa_name);
2451 set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
2460 nfsd4_proc_null(struct svc_rqst *rqstp)
2465 static inline void nfsd4_increment_op_stats(u32 opnum)
2467 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
2468 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]);
2471 static const struct nfsd4_operation nfsd4_ops[];
2473 static const char *nfsd4_op_name(unsigned opnum);
2476 * Enforce NFSv4.1 COMPOUND ordering rules:
2478 * Also note, enforced elsewhere:
2479 * - SEQUENCE other than as first op results in
2480 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
2481 * - BIND_CONN_TO_SESSION must be the only op in its compound.
2482 * (Enforced in nfsd4_bind_conn_to_session().)
2483 * - DESTROY_SESSION must be the final operation in a compound, if
2484 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
2485 * (Enforced in nfsd4_destroy_session().)
2487 static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
2489 struct nfsd4_op *first_op = &args->ops[0];
2491 /* These ordering requirements don't apply to NFSv4.0: */
2492 if (args->minorversion == 0)
2494 /* This is weird, but OK, not our problem: */
2495 if (args->opcnt == 0)
2497 if (first_op->status == nfserr_op_illegal)
2499 if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
2500 return nfserr_op_not_in_session;
2501 if (first_op->opnum == OP_SEQUENCE)
2504 * So first_op is something allowed outside a session, like
2505 * EXCHANGE_ID; but then it has to be the only op in the
2508 if (args->opcnt != 1)
2509 return nfserr_not_only_op;
2513 const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
2515 return &nfsd4_ops[op->opnum];
2518 bool nfsd4_cache_this_op(struct nfsd4_op *op)
2520 if (op->opnum == OP_ILLEGAL)
2522 return OPDESC(op)->op_flags & OP_CACHEME;
2525 static bool need_wrongsec_check(struct svc_rqst *rqstp)
2527 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2528 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2529 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2530 struct nfsd4_op *next = &argp->ops[resp->opcnt];
2531 const struct nfsd4_operation *thisd = OPDESC(this);
2532 const struct nfsd4_operation *nextd;
2535 * Most ops check wronsec on our own; only the putfh-like ops
2536 * have special rules.
2538 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
2541 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
2542 * put-filehandle operation if we're not going to use the
2545 if (argp->opcnt == resp->opcnt)
2547 if (next->opnum == OP_ILLEGAL)
2549 nextd = OPDESC(next);
2551 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
2552 * errors themselves as necessary; others should check for them
2555 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
2558 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
2560 check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2562 struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL;
2563 struct nfsd4_copy *copy;
2564 struct nfsd4_putfh *putfh;
2567 /* traverse all operation and if it's a COPY compound, mark the
2568 * source filehandle to skip verification
2570 for (i = 0; i < args->opcnt; i++) {
2572 if (op->opnum == OP_PUTFH)
2574 else if (op->opnum == OP_SAVEFH)
2575 saved_op = current_op;
2576 else if (op->opnum == OP_RESTOREFH)
2577 current_op = saved_op;
2578 else if (op->opnum == OP_COPY) {
2579 copy = (struct nfsd4_copy *)&op->u;
2581 op->status = nfserr_nofilehandle;
2584 putfh = (struct nfsd4_putfh *)&saved_op->u;
2585 if (!copy->cp_intra)
2586 putfh->no_verify = true;
2592 check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2601 nfsd4_proc_compound(struct svc_rqst *rqstp)
2603 struct nfsd4_compoundargs *args = rqstp->rq_argp;
2604 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2605 struct nfsd4_op *op;
2606 struct nfsd4_compound_state *cstate = &resp->cstate;
2607 struct svc_fh *current_fh = &cstate->current_fh;
2608 struct svc_fh *save_fh = &cstate->save_fh;
2609 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
2612 resp->xdr = &rqstp->rq_res_stream;
2613 resp->statusp = resp->xdr->p;
2615 /* reserve space for: NFS status code */
2616 xdr_reserve_space(resp->xdr, XDR_UNIT);
2618 /* reserve space for: taglen, tag, and opcnt */
2619 xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
2620 resp->taglen = args->taglen;
2621 resp->tag = args->tag;
2622 resp->rqstp = rqstp;
2623 cstate->minorversion = args->minorversion;
2624 fh_init(current_fh, NFS4_FHSIZE);
2625 fh_init(save_fh, NFS4_FHSIZE);
2627 * Don't use the deferral mechanism for NFSv4; compounds make it
2628 * too hard to avoid non-idempotency problems.
2630 clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
2633 * According to RFC3010, this takes precedence over all other errors.
2635 status = nfserr_minor_vers_mismatch;
2636 if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
2638 status = nfserr_resource;
2639 if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
2642 status = nfs41_check_op_ordering(args);
2645 op->status = status;
2649 check_if_stalefh_allowed(args);
2651 rqstp->rq_lease_breaker = (void **)&cstate->clp;
2653 trace_nfsd_compound(rqstp, args->opcnt);
2654 while (!status && resp->opcnt < args->opcnt) {
2655 op = &args->ops[resp->opcnt++];
2658 * The XDR decode routines may have pre-set op->status;
2659 * for example, if there is a miscellaneous XDR error
2660 * it will be set to nfserr_bad_xdr.
2663 if (op->opnum == OP_OPEN)
2664 op->status = nfsd4_open_omfg(rqstp, cstate, op);
2667 if (!current_fh->fh_dentry &&
2668 !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) {
2669 if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
2670 op->status = nfserr_nofilehandle;
2673 } else if (current_fh->fh_export &&
2674 current_fh->fh_export->ex_fslocs.migrated &&
2675 !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
2676 op->status = nfserr_moved;
2680 fh_clear_pre_post_attrs(current_fh);
2682 /* If op is non-idempotent */
2683 if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
2685 * Don't execute this op if we couldn't encode a
2688 u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
2690 * Plus if there's another operation, make sure
2691 * we'll have space to at least encode an error:
2693 if (resp->opcnt < args->opcnt)
2694 plen += COMPOUND_ERR_SLACK_SPACE;
2695 op->status = nfsd4_check_resp_size(resp, plen);
2701 if (op->opdesc->op_get_currentstateid)
2702 op->opdesc->op_get_currentstateid(cstate, &op->u);
2703 op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
2705 /* Only from SEQUENCE */
2706 if (cstate->status == nfserr_replay_cache) {
2707 dprintk("%s NFS4.1 replay from cache\n", __func__);
2708 status = op->status;
2712 if (op->opdesc->op_set_currentstateid)
2713 op->opdesc->op_set_currentstateid(cstate, &op->u);
2715 if (op->opdesc->op_flags & OP_CLEAR_STATEID)
2716 clear_current_stateid(cstate);
2718 if (current_fh->fh_export &&
2719 need_wrongsec_check(rqstp))
2720 op->status = check_nfsd_access(current_fh->fh_export, rqstp);
2723 if (op->status == nfserr_replay_me) {
2724 op->replay = &cstate->replay_owner->so_replay;
2725 nfsd4_encode_replay(resp->xdr, op);
2726 status = op->status = op->replay->rp_status;
2728 nfsd4_encode_operation(resp, op);
2729 status = op->status;
2732 trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
2733 nfsd4_op_name(op->opnum));
2735 nfsd4_cstate_clear_replay(cstate);
2736 nfsd4_increment_op_stats(op->opnum);
2741 BUG_ON(cstate->replay_owner);
2743 cstate->status = status;
2744 /* Reset deferral mechanism for RPC deferrals */
2745 set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
2749 #define op_encode_hdr_size (2)
2750 #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
2751 #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
2752 #define op_encode_change_info_maxsz (5)
2753 #define nfs4_fattr_bitmap_maxsz (4)
2755 /* We'll fall back on returning no lockowner if run out of space: */
2756 #define op_encode_lockowner_maxsz (0)
2757 #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
2759 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
2761 #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
2762 #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
2763 op_encode_ace_maxsz)
2765 #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
2767 static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2769 return (op_encode_hdr_size) * sizeof(__be32);
2772 static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2774 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
2777 static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2779 /* ac_supported, ac_resp_access */
2780 return (op_encode_hdr_size + 2)* sizeof(__be32);
2783 static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2785 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
2788 static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2790 return (op_encode_hdr_size + op_encode_change_info_maxsz
2791 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2795 * Note since this is an idempotent operation we won't insist on failing
2796 * the op prematurely if the estimate is too large. We may turn off splice
2797 * reads unnecessarily.
2799 static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
2800 struct nfsd4_op *op)
2802 u32 *bmap = op->u.getattr.ga_bmval;
2803 u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
2806 if (bmap0 & FATTR4_WORD0_ACL)
2807 return svc_max_payload(rqstp);
2808 if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
2809 return svc_max_payload(rqstp);
2811 if (bmap1 & FATTR4_WORD1_OWNER) {
2812 ret += IDMAP_NAMESZ + 4;
2813 bmap1 &= ~FATTR4_WORD1_OWNER;
2815 if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
2816 ret += IDMAP_NAMESZ + 4;
2817 bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
2819 if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
2820 ret += NFS4_FHSIZE + 4;
2821 bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
2823 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
2824 ret += NFS4_MAXLABELLEN + 12;
2825 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2828 * Largest of remaining attributes are 16 bytes (e.g.,
2829 * supported_attributes)
2831 ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
2832 /* bitmask, length */
2837 static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2839 return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
2842 static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2844 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2848 static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2850 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
2854 static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2856 return (op_encode_hdr_size + op_encode_stateid_maxsz
2857 + op_encode_change_info_maxsz + 1
2858 + nfs4_fattr_bitmap_maxsz
2859 + op_encode_delegation_maxsz) * sizeof(__be32);
2862 static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2864 u32 maxcount = 0, rlen = 0;
2866 maxcount = svc_max_payload(rqstp);
2867 rlen = min(op->u.read.rd_length, maxcount);
2869 return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2872 static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2874 u32 maxcount = svc_max_payload(rqstp);
2875 u32 rlen = min(op->u.read.rd_length, maxcount);
2877 * If we detect that the file changed during hole encoding, then we
2878 * recover by encoding the remaining reply as data. This means we need
2879 * to set aside enough room to encode two data segments.
2881 u32 seg_len = 2 * (1 + 2 + 1);
2883 return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32);
2886 static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2888 u32 maxcount = 0, rlen = 0;
2890 maxcount = svc_max_payload(rqstp);
2891 rlen = min(op->u.readdir.rd_maxcount, maxcount);
2893 return (op_encode_hdr_size + op_encode_verifier_maxsz +
2894 XDR_QUADLEN(rlen)) * sizeof(__be32);
2897 static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2899 return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
2902 static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2904 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2908 static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2910 return (op_encode_hdr_size + op_encode_change_info_maxsz
2911 + op_encode_change_info_maxsz) * sizeof(__be32);
2914 static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
2915 struct nfsd4_op *op)
2917 return (op_encode_hdr_size
2918 + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
2921 static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2923 return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
2927 static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2929 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2932 static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2934 return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
2935 (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
2938 static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2940 return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2944 static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2946 return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
2949 static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2951 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
2952 1 + 1 + /* eir_flags, spr_how */\
2953 4 + /* spo_must_enforce & _allow with bitmap */\
2954 2 + /*eir_server_owner.so_minor_id */\
2955 /* eir_server_owner.so_major_id<> */\
2956 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2957 /* eir_server_scope<> */\
2958 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2959 1 + /* eir_server_impl_id array length */\
2960 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
2963 static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2965 return (op_encode_hdr_size + \
2966 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
2967 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
2970 static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2972 return (op_encode_hdr_size + \
2973 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
2974 2 + /* csr_sequence, csr_flags */\
2975 op_encode_channel_attrs_maxsz + \
2976 op_encode_channel_attrs_maxsz) * sizeof(__be32);
2979 static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2981 return (op_encode_hdr_size +
2982 1 /* wr_callback */ +
2983 op_encode_stateid_maxsz /* wr_callback */ +
2985 1 /* wr_committed */ +
2986 op_encode_verifier_maxsz +
2987 1 /* cr_consecutive */ +
2988 1 /* cr_synchronous */) * sizeof(__be32);
2991 static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
2992 struct nfsd4_op *op)
2994 return (op_encode_hdr_size +
2996 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
2999 static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp,
3000 struct nfsd4_op *op)
3002 return (op_encode_hdr_size +
3003 3 /* cnr_lease_time */ +
3004 1 /* We support one cnr_source_server */ +
3005 1 /* cnr_stateid seq */ +
3006 op_encode_stateid_maxsz /* cnr_stateid */ +
3007 1 /* num cnr_source_server*/ +
3010 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */)
3014 #ifdef CONFIG_NFSD_PNFS
3015 static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3017 u32 maxcount = 0, rlen = 0;
3019 maxcount = svc_max_payload(rqstp);
3020 rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
3022 return (op_encode_hdr_size +
3023 1 /* gd_layout_type*/ +
3025 2 /* gd_notify_types */) * sizeof(__be32);
3029 * At this stage we don't really know what layout driver will handle the request,
3030 * so we need to define an arbitrary upper bound here.
3032 #define MAX_LAYOUT_SIZE 128
3033 static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3035 return (op_encode_hdr_size +
3036 1 /* logr_return_on_close */ +
3037 op_encode_stateid_maxsz +
3038 1 /* nr of layouts */ +
3039 MAX_LAYOUT_SIZE) * sizeof(__be32);
3042 static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3044 return (op_encode_hdr_size +
3045 1 /* locr_newsize */ +
3046 2 /* ns_size */) * sizeof(__be32);
3049 static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3051 return (op_encode_hdr_size +
3052 1 /* lrs_stateid */ +
3053 op_encode_stateid_maxsz) * sizeof(__be32);
3055 #endif /* CONFIG_NFSD_PNFS */
3058 static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3060 return (op_encode_hdr_size + 3) * sizeof(__be32);
3063 static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp,
3064 struct nfsd4_op *op)
3068 maxcount = svc_max_payload(rqstp);
3069 rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
3071 return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3074 static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp,
3075 struct nfsd4_op *op)
3077 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3080 static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp,
3081 struct nfsd4_op *op)
3085 maxcount = svc_max_payload(rqstp);
3086 rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
3088 return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3091 static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp,
3092 struct nfsd4_op *op)
3094 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3099 static const struct nfsd4_operation nfsd4_ops[] = {
3101 .op_func = nfsd4_access,
3102 .op_name = "OP_ACCESS",
3103 .op_rsize_bop = nfsd4_access_rsize,
3106 .op_func = nfsd4_close,
3107 .op_flags = OP_MODIFIES_SOMETHING,
3108 .op_name = "OP_CLOSE",
3109 .op_rsize_bop = nfsd4_status_stateid_rsize,
3110 .op_get_currentstateid = nfsd4_get_closestateid,
3111 .op_set_currentstateid = nfsd4_set_closestateid,
3114 .op_func = nfsd4_commit,
3115 .op_flags = OP_MODIFIES_SOMETHING,
3116 .op_name = "OP_COMMIT",
3117 .op_rsize_bop = nfsd4_commit_rsize,
3120 .op_func = nfsd4_create,
3121 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
3122 .op_name = "OP_CREATE",
3123 .op_rsize_bop = nfsd4_create_rsize,
3125 [OP_DELEGRETURN] = {
3126 .op_func = nfsd4_delegreturn,
3127 .op_flags = OP_MODIFIES_SOMETHING,
3128 .op_name = "OP_DELEGRETURN",
3129 .op_rsize_bop = nfsd4_only_status_rsize,
3130 .op_get_currentstateid = nfsd4_get_delegreturnstateid,
3133 .op_func = nfsd4_getattr,
3134 .op_flags = ALLOWED_ON_ABSENT_FS,
3135 .op_rsize_bop = nfsd4_getattr_rsize,
3136 .op_name = "OP_GETATTR",
3139 .op_func = nfsd4_getfh,
3140 .op_name = "OP_GETFH",
3141 .op_rsize_bop = nfsd4_getfh_rsize,
3144 .op_func = nfsd4_link,
3145 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
3147 .op_name = "OP_LINK",
3148 .op_rsize_bop = nfsd4_link_rsize,
3151 .op_func = nfsd4_lock,
3152 .op_flags = OP_MODIFIES_SOMETHING |
3153 OP_NONTRIVIAL_ERROR_ENCODE,
3154 .op_name = "OP_LOCK",
3155 .op_rsize_bop = nfsd4_lock_rsize,
3156 .op_set_currentstateid = nfsd4_set_lockstateid,
3159 .op_func = nfsd4_lockt,
3160 .op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
3161 .op_name = "OP_LOCKT",
3162 .op_rsize_bop = nfsd4_lock_rsize,
3165 .op_func = nfsd4_locku,
3166 .op_flags = OP_MODIFIES_SOMETHING,
3167 .op_name = "OP_LOCKU",
3168 .op_rsize_bop = nfsd4_status_stateid_rsize,
3169 .op_get_currentstateid = nfsd4_get_lockustateid,
3172 .op_func = nfsd4_lookup,
3173 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
3174 .op_name = "OP_LOOKUP",
3175 .op_rsize_bop = nfsd4_only_status_rsize,
3178 .op_func = nfsd4_lookupp,
3179 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
3180 .op_name = "OP_LOOKUPP",
3181 .op_rsize_bop = nfsd4_only_status_rsize,
3184 .op_func = nfsd4_nverify,
3185 .op_name = "OP_NVERIFY",
3186 .op_rsize_bop = nfsd4_only_status_rsize,
3189 .op_func = nfsd4_open,
3190 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
3191 .op_name = "OP_OPEN",
3192 .op_rsize_bop = nfsd4_open_rsize,
3193 .op_set_currentstateid = nfsd4_set_openstateid,
3195 [OP_OPEN_CONFIRM] = {
3196 .op_func = nfsd4_open_confirm,
3197 .op_flags = OP_MODIFIES_SOMETHING,
3198 .op_name = "OP_OPEN_CONFIRM",
3199 .op_rsize_bop = nfsd4_status_stateid_rsize,
3201 [OP_OPEN_DOWNGRADE] = {
3202 .op_func = nfsd4_open_downgrade,
3203 .op_flags = OP_MODIFIES_SOMETHING,
3204 .op_name = "OP_OPEN_DOWNGRADE",
3205 .op_rsize_bop = nfsd4_status_stateid_rsize,
3206 .op_get_currentstateid = nfsd4_get_opendowngradestateid,
3207 .op_set_currentstateid = nfsd4_set_opendowngradestateid,
3210 .op_func = nfsd4_putfh,
3211 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3212 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3213 .op_name = "OP_PUTFH",
3214 .op_rsize_bop = nfsd4_only_status_rsize,
3217 .op_func = nfsd4_putrootfh,
3218 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3219 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3220 .op_name = "OP_PUTPUBFH",
3221 .op_rsize_bop = nfsd4_only_status_rsize,
3224 .op_func = nfsd4_putrootfh,
3225 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3226 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3227 .op_name = "OP_PUTROOTFH",
3228 .op_rsize_bop = nfsd4_only_status_rsize,
3231 .op_func = nfsd4_read,
3232 .op_release = nfsd4_read_release,
3233 .op_name = "OP_READ",
3234 .op_rsize_bop = nfsd4_read_rsize,
3235 .op_get_currentstateid = nfsd4_get_readstateid,
3238 .op_func = nfsd4_readdir,
3239 .op_name = "OP_READDIR",
3240 .op_rsize_bop = nfsd4_readdir_rsize,
3243 .op_func = nfsd4_readlink,
3244 .op_name = "OP_READLINK",
3245 .op_rsize_bop = nfsd4_readlink_rsize,
3248 .op_func = nfsd4_remove,
3249 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3250 .op_name = "OP_REMOVE",
3251 .op_rsize_bop = nfsd4_remove_rsize,
3254 .op_func = nfsd4_rename,
3255 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3256 .op_name = "OP_RENAME",
3257 .op_rsize_bop = nfsd4_rename_rsize,
3260 .op_func = nfsd4_renew,
3261 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3262 | OP_MODIFIES_SOMETHING,
3263 .op_name = "OP_RENEW",
3264 .op_rsize_bop = nfsd4_only_status_rsize,
3268 .op_func = nfsd4_restorefh,
3269 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3270 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
3271 .op_name = "OP_RESTOREFH",
3272 .op_rsize_bop = nfsd4_only_status_rsize,
3275 .op_func = nfsd4_savefh,
3276 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
3277 .op_name = "OP_SAVEFH",
3278 .op_rsize_bop = nfsd4_only_status_rsize,
3281 .op_func = nfsd4_secinfo,
3282 .op_release = nfsd4_secinfo_release,
3283 .op_flags = OP_HANDLES_WRONGSEC,
3284 .op_name = "OP_SECINFO",
3285 .op_rsize_bop = nfsd4_secinfo_rsize,
3288 .op_func = nfsd4_setattr,
3289 .op_name = "OP_SETATTR",
3290 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
3291 | OP_NONTRIVIAL_ERROR_ENCODE,
3292 .op_rsize_bop = nfsd4_setattr_rsize,
3293 .op_get_currentstateid = nfsd4_get_setattrstateid,
3295 [OP_SETCLIENTID] = {
3296 .op_func = nfsd4_setclientid,
3297 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3298 | OP_MODIFIES_SOMETHING | OP_CACHEME
3299 | OP_NONTRIVIAL_ERROR_ENCODE,
3300 .op_name = "OP_SETCLIENTID",
3301 .op_rsize_bop = nfsd4_setclientid_rsize,
3303 [OP_SETCLIENTID_CONFIRM] = {
3304 .op_func = nfsd4_setclientid_confirm,
3305 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3306 | OP_MODIFIES_SOMETHING | OP_CACHEME,
3307 .op_name = "OP_SETCLIENTID_CONFIRM",
3308 .op_rsize_bop = nfsd4_only_status_rsize,
3311 .op_func = nfsd4_verify,
3312 .op_name = "OP_VERIFY",
3313 .op_rsize_bop = nfsd4_only_status_rsize,
3316 .op_func = nfsd4_write,
3317 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3318 .op_name = "OP_WRITE",
3319 .op_rsize_bop = nfsd4_write_rsize,
3320 .op_get_currentstateid = nfsd4_get_writestateid,
3322 [OP_RELEASE_LOCKOWNER] = {
3323 .op_func = nfsd4_release_lockowner,
3324 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3325 | OP_MODIFIES_SOMETHING,
3326 .op_name = "OP_RELEASE_LOCKOWNER",
3327 .op_rsize_bop = nfsd4_only_status_rsize,
3330 /* NFSv4.1 operations */
3331 [OP_EXCHANGE_ID] = {
3332 .op_func = nfsd4_exchange_id,
3333 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3334 | OP_MODIFIES_SOMETHING,
3335 .op_name = "OP_EXCHANGE_ID",
3336 .op_rsize_bop = nfsd4_exchange_id_rsize,
3338 [OP_BACKCHANNEL_CTL] = {
3339 .op_func = nfsd4_backchannel_ctl,
3340 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3341 .op_name = "OP_BACKCHANNEL_CTL",
3342 .op_rsize_bop = nfsd4_only_status_rsize,
3344 [OP_BIND_CONN_TO_SESSION] = {
3345 .op_func = nfsd4_bind_conn_to_session,
3346 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3347 | OP_MODIFIES_SOMETHING,
3348 .op_name = "OP_BIND_CONN_TO_SESSION",
3349 .op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
3351 [OP_CREATE_SESSION] = {
3352 .op_func = nfsd4_create_session,
3353 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3354 | OP_MODIFIES_SOMETHING,
3355 .op_name = "OP_CREATE_SESSION",
3356 .op_rsize_bop = nfsd4_create_session_rsize,
3358 [OP_DESTROY_SESSION] = {
3359 .op_func = nfsd4_destroy_session,
3360 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3361 | OP_MODIFIES_SOMETHING,
3362 .op_name = "OP_DESTROY_SESSION",
3363 .op_rsize_bop = nfsd4_only_status_rsize,
3366 .op_func = nfsd4_sequence,
3367 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
3368 .op_name = "OP_SEQUENCE",
3369 .op_rsize_bop = nfsd4_sequence_rsize,
3371 [OP_DESTROY_CLIENTID] = {
3372 .op_func = nfsd4_destroy_clientid,
3373 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3374 | OP_MODIFIES_SOMETHING,
3375 .op_name = "OP_DESTROY_CLIENTID",
3376 .op_rsize_bop = nfsd4_only_status_rsize,
3378 [OP_RECLAIM_COMPLETE] = {
3379 .op_func = nfsd4_reclaim_complete,
3380 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3381 .op_name = "OP_RECLAIM_COMPLETE",
3382 .op_rsize_bop = nfsd4_only_status_rsize,
3384 [OP_SECINFO_NO_NAME] = {
3385 .op_func = nfsd4_secinfo_no_name,
3386 .op_release = nfsd4_secinfo_no_name_release,
3387 .op_flags = OP_HANDLES_WRONGSEC,
3388 .op_name = "OP_SECINFO_NO_NAME",
3389 .op_rsize_bop = nfsd4_secinfo_rsize,
3391 [OP_TEST_STATEID] = {
3392 .op_func = nfsd4_test_stateid,
3393 .op_flags = ALLOWED_WITHOUT_FH,
3394 .op_name = "OP_TEST_STATEID",
3395 .op_rsize_bop = nfsd4_test_stateid_rsize,
3397 [OP_FREE_STATEID] = {
3398 .op_func = nfsd4_free_stateid,
3399 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3400 .op_name = "OP_FREE_STATEID",
3401 .op_get_currentstateid = nfsd4_get_freestateid,
3402 .op_rsize_bop = nfsd4_only_status_rsize,
3404 #ifdef CONFIG_NFSD_PNFS
3405 [OP_GETDEVICEINFO] = {
3406 .op_func = nfsd4_getdeviceinfo,
3407 .op_release = nfsd4_getdeviceinfo_release,
3408 .op_flags = ALLOWED_WITHOUT_FH,
3409 .op_name = "OP_GETDEVICEINFO",
3410 .op_rsize_bop = nfsd4_getdeviceinfo_rsize,
3413 .op_func = nfsd4_layoutget,
3414 .op_release = nfsd4_layoutget_release,
3415 .op_flags = OP_MODIFIES_SOMETHING,
3416 .op_name = "OP_LAYOUTGET",
3417 .op_rsize_bop = nfsd4_layoutget_rsize,
3419 [OP_LAYOUTCOMMIT] = {
3420 .op_func = nfsd4_layoutcommit,
3421 .op_flags = OP_MODIFIES_SOMETHING,
3422 .op_name = "OP_LAYOUTCOMMIT",
3423 .op_rsize_bop = nfsd4_layoutcommit_rsize,
3425 [OP_LAYOUTRETURN] = {
3426 .op_func = nfsd4_layoutreturn,
3427 .op_flags = OP_MODIFIES_SOMETHING,
3428 .op_name = "OP_LAYOUTRETURN",
3429 .op_rsize_bop = nfsd4_layoutreturn_rsize,
3431 #endif /* CONFIG_NFSD_PNFS */
3433 /* NFSv4.2 operations */
3435 .op_func = nfsd4_allocate,
3436 .op_flags = OP_MODIFIES_SOMETHING,
3437 .op_name = "OP_ALLOCATE",
3438 .op_rsize_bop = nfsd4_only_status_rsize,
3441 .op_func = nfsd4_deallocate,
3442 .op_flags = OP_MODIFIES_SOMETHING,
3443 .op_name = "OP_DEALLOCATE",
3444 .op_rsize_bop = nfsd4_only_status_rsize,
3447 .op_func = nfsd4_clone,
3448 .op_flags = OP_MODIFIES_SOMETHING,
3449 .op_name = "OP_CLONE",
3450 .op_rsize_bop = nfsd4_only_status_rsize,
3453 .op_func = nfsd4_copy,
3454 .op_flags = OP_MODIFIES_SOMETHING,
3455 .op_name = "OP_COPY",
3456 .op_rsize_bop = nfsd4_copy_rsize,
3459 .op_func = nfsd4_read,
3460 .op_release = nfsd4_read_release,
3461 .op_name = "OP_READ_PLUS",
3462 .op_rsize_bop = nfsd4_read_plus_rsize,
3463 .op_get_currentstateid = nfsd4_get_readstateid,
3466 .op_func = nfsd4_seek,
3467 .op_name = "OP_SEEK",
3468 .op_rsize_bop = nfsd4_seek_rsize,
3470 [OP_OFFLOAD_STATUS] = {
3471 .op_func = nfsd4_offload_status,
3472 .op_name = "OP_OFFLOAD_STATUS",
3473 .op_rsize_bop = nfsd4_offload_status_rsize,
3475 [OP_OFFLOAD_CANCEL] = {
3476 .op_func = nfsd4_offload_cancel,
3477 .op_flags = OP_MODIFIES_SOMETHING,
3478 .op_name = "OP_OFFLOAD_CANCEL",
3479 .op_rsize_bop = nfsd4_only_status_rsize,
3481 [OP_COPY_NOTIFY] = {
3482 .op_func = nfsd4_copy_notify,
3483 .op_flags = OP_MODIFIES_SOMETHING,
3484 .op_name = "OP_COPY_NOTIFY",
3485 .op_rsize_bop = nfsd4_copy_notify_rsize,
3488 .op_func = nfsd4_getxattr,
3489 .op_name = "OP_GETXATTR",
3490 .op_rsize_bop = nfsd4_getxattr_rsize,
3493 .op_func = nfsd4_setxattr,
3494 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3495 .op_name = "OP_SETXATTR",
3496 .op_rsize_bop = nfsd4_setxattr_rsize,
3499 .op_func = nfsd4_listxattrs,
3500 .op_name = "OP_LISTXATTRS",
3501 .op_rsize_bop = nfsd4_listxattrs_rsize,
3503 [OP_REMOVEXATTR] = {
3504 .op_func = nfsd4_removexattr,
3505 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3506 .op_name = "OP_REMOVEXATTR",
3507 .op_rsize_bop = nfsd4_removexattr_rsize,
3512 * nfsd4_spo_must_allow - Determine if the compound op contains an
3513 * operation that is allowed to be sent with machine credentials
3515 * @rqstp: a pointer to the struct svc_rqst
3517 * Checks to see if the compound contains a spo_must_allow op
3518 * and confirms that it was sent with the proper machine creds.
3521 bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
3523 struct nfsd4_compoundres *resp = rqstp->rq_resp;
3524 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
3525 struct nfsd4_op *this;
3526 struct nfsd4_compound_state *cstate = &resp->cstate;
3527 struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
3530 if (!cstate->minorversion)
3533 if (cstate->spo_must_allowed)
3536 opiter = resp->opcnt;
3537 while (opiter < argp->opcnt) {
3538 this = &argp->ops[opiter++];
3539 if (test_bit(this->opnum, allow->u.longs) &&
3540 cstate->clp->cl_mach_cred &&
3541 nfsd4_mach_creds_match(cstate->clp, rqstp)) {
3542 cstate->spo_must_allowed = true;
3546 cstate->spo_must_allowed = false;
3550 int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
3552 if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
3553 return op_encode_hdr_size * sizeof(__be32);
3555 BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
3556 return OPDESC(op)->op_rsize_bop(rqstp, op);
3559 void warn_on_nonidempotent_op(struct nfsd4_op *op)
3561 if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
3562 pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
3563 op->opnum, nfsd4_op_name(op->opnum));
3568 static const char *nfsd4_op_name(unsigned opnum)
3570 if (opnum < ARRAY_SIZE(nfsd4_ops))
3571 return nfsd4_ops[opnum].op_name;
3572 return "unknown_operation";
3575 static const struct svc_procedure nfsd_procedures4[2] = {
3577 .pc_func = nfsd4_proc_null,
3578 .pc_decode = nfssvc_decode_voidarg,
3579 .pc_encode = nfssvc_encode_voidres,
3580 .pc_argsize = sizeof(struct nfsd_voidargs),
3581 .pc_ressize = sizeof(struct nfsd_voidres),
3582 .pc_cachetype = RC_NOCACHE,
3586 [NFSPROC4_COMPOUND] = {
3587 .pc_func = nfsd4_proc_compound,
3588 .pc_decode = nfs4svc_decode_compoundargs,
3589 .pc_encode = nfs4svc_encode_compoundres,
3590 .pc_argsize = sizeof(struct nfsd4_compoundargs),
3591 .pc_ressize = sizeof(struct nfsd4_compoundres),
3592 .pc_release = nfsd4_release_compoundargs,
3593 .pc_cachetype = RC_NOCACHE,
3594 .pc_xdrressize = NFSD_BUFSIZE/4,
3595 .pc_name = "COMPOUND",
3599 static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
3600 const struct svc_version nfsd_version4 = {
3603 .vs_proc = nfsd_procedures4,
3604 .vs_count = nfsd_count3,
3605 .vs_dispatch = nfsd_dispatch,
3606 .vs_xdrsize = NFS4_SVC_XDRSIZE,
3607 .vs_rpcb_optnl = true,
3608 .vs_need_cong_ctrl = true,