2 * Server-side procedures for NFSv4.
4 * Copyright (c) 2002 The Regents of the University of Michigan.
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 #define NFSDDBG_FACILITY NFSDDBG_PROC
69 static u32 nfsd_attrmask[] = {
70 NFSD_WRITEABLE_ATTRS_WORD0,
71 NFSD_WRITEABLE_ATTRS_WORD1,
72 NFSD_WRITEABLE_ATTRS_WORD2
75 static u32 nfsd41_ex_attrmask[] = {
76 NFSD_SUPPATTR_EXCLCREAT_WORD0,
77 NFSD_SUPPATTR_EXCLCREAT_WORD1,
78 NFSD_SUPPATTR_EXCLCREAT_WORD2
82 check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
83 u32 *bmval, u32 *writable)
85 struct dentry *dentry = cstate->current_fh.fh_dentry;
86 struct svc_export *exp = cstate->current_fh.fh_export;
88 if (!nfsd_attrs_supported(cstate->minorversion, bmval))
89 return nfserr_attrnotsupp;
90 if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
91 return nfserr_attrnotsupp;
92 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
93 !(exp->ex_flags & NFSEXP_SECURITY_LABEL))
94 return nfserr_attrnotsupp;
95 if (writable && !bmval_is_subset(bmval, writable))
97 if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
98 (bmval[1] & FATTR4_WORD1_MODE))
104 nfsd4_check_open_attributes(struct svc_rqst *rqstp,
105 struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
107 __be32 status = nfs_ok;
109 if (open->op_create == NFS4_OPEN_CREATE) {
110 if (open->op_createmode == NFS4_CREATE_UNCHECKED
111 || open->op_createmode == NFS4_CREATE_GUARDED)
112 status = check_attr_support(rqstp, cstate,
113 open->op_bmval, nfsd_attrmask);
114 else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
115 status = check_attr_support(rqstp, cstate,
116 open->op_bmval, nfsd41_ex_attrmask);
123 is_create_with_attrs(struct nfsd4_open *open)
125 return open->op_create == NFS4_OPEN_CREATE
126 && (open->op_createmode == NFS4_CREATE_UNCHECKED
127 || open->op_createmode == NFS4_CREATE_GUARDED
128 || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
132 fh_dup2(struct svc_fh *dst, struct svc_fh *src)
135 dget(src->fh_dentry);
137 exp_get(src->fh_export);
142 do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
146 if (open->op_truncate &&
147 !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
150 accmode |= NFSD_MAY_READ_IF_EXEC;
152 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
153 accmode |= NFSD_MAY_READ;
154 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
155 accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
156 if (open->op_share_deny & NFS4_SHARE_DENY_READ)
157 accmode |= NFSD_MAY_WRITE;
159 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
164 static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
166 umode_t mode = d_inode(fh->fh_dentry)->i_mode;
173 * Using err_symlink as our catch-all case may look odd; but
174 * there's no other obvious error for this case in 4.0, and we
175 * happen to know that it will cause the linux v4 client to do
176 * the right thing on attempts to open something other than a
179 return nfserr_symlink;
182 static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
184 if (nfsd4_has_session(cstate))
186 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
190 static inline bool nfsd4_create_is_exclusive(int createmode)
192 return createmode == NFS4_CREATE_EXCLUSIVE ||
193 createmode == NFS4_CREATE_EXCLUSIVE4_1;
197 nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
198 struct nfsd4_open *open)
204 oflags = O_CREAT | O_LARGEFILE;
205 switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) {
206 case NFS4_SHARE_ACCESS_WRITE:
209 case NFS4_SHARE_ACCESS_BOTH:
216 path.mnt = fhp->fh_export->ex_path.mnt;
218 filp = dentry_create(&path, oflags, open->op_iattr.ia_mode,
221 return nfserrno(PTR_ERR(filp));
223 open->op_filp = filp;
228 * Implement NFSv4's unchecked, guarded, and exclusive create
229 * semantics for regular files. Open state for this new file is
230 * subsequently fabricated in nfsd4_process_open2().
232 * Upon return, caller must release @fhp and @resfhp.
235 nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
236 struct svc_fh *resfhp, struct nfsd4_open *open)
238 struct iattr *iap = &open->op_iattr;
239 struct nfsd_attrs attrs = {
241 .na_seclabel = &open->op_label,
243 struct dentry *parent, *child;
244 __u32 v_mtime, v_atime;
249 if (isdotent(open->op_fname, open->op_fnamelen))
251 if (!(iap->ia_valid & ATTR_MODE))
254 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
255 if (status != nfs_ok)
257 parent = fhp->fh_dentry;
258 inode = d_inode(parent);
260 host_err = fh_want_write(fhp);
262 return nfserrno(host_err);
264 if (is_create_with_attrs(open))
265 nfsd4_acl_to_attr(NF4REG, open->op_acl, &attrs);
267 inode_lock_nested(inode, I_MUTEX_PARENT);
269 child = lookup_one_len(open->op_fname, parent, open->op_fnamelen);
271 status = nfserrno(PTR_ERR(child));
275 if (d_really_is_negative(child)) {
276 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
277 if (status != nfs_ok)
281 status = fh_compose(resfhp, fhp->fh_export, child, fhp);
282 if (status != nfs_ok)
287 if (nfsd4_create_is_exclusive(open->op_createmode)) {
288 u32 *verifier = (u32 *)open->op_verf.data;
291 * Solaris 7 gets confused (bugid 4218508) if these have
292 * the high bit set, as do xfs filesystems without the
293 * "bigtime" feature. So just clear the high bits. If this
294 * is ever changed to use different attrs for storing the
295 * verifier, then do_open_lookup() will also need to be
298 v_mtime = verifier[0] & 0x7fffffff;
299 v_atime = verifier[1] & 0x7fffffff;
302 if (d_really_is_positive(child)) {
305 /* NFSv4 protocol requires change attributes even though
306 * no change happened.
308 fh_fill_both_attrs(fhp);
310 switch (open->op_createmode) {
311 case NFS4_CREATE_UNCHECKED:
312 if (!d_is_reg(child))
316 * In NFSv4, we don't want to truncate the file
317 * now. This would be wrong if the OPEN fails for
318 * some other reason. Furthermore, if the size is
319 * nonzero, we should ignore it according to spec!
321 open->op_truncate = (iap->ia_valid & ATTR_SIZE) &&
324 case NFS4_CREATE_GUARDED:
325 status = nfserr_exist;
327 case NFS4_CREATE_EXCLUSIVE:
328 if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
329 d_inode(child)->i_atime.tv_sec == v_atime &&
330 d_inode(child)->i_size == 0) {
331 open->op_created = true;
334 status = nfserr_exist;
336 case NFS4_CREATE_EXCLUSIVE4_1:
337 if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
338 d_inode(child)->i_atime.tv_sec == v_atime &&
339 d_inode(child)->i_size == 0) {
340 open->op_created = true;
341 goto set_attr; /* subtle */
343 status = nfserr_exist;
348 if (!IS_POSIXACL(inode))
349 iap->ia_mode &= ~current_umask();
351 fh_fill_pre_attrs(fhp);
352 status = nfsd4_vfs_create(fhp, child, open);
353 if (status != nfs_ok)
355 open->op_created = true;
356 fh_fill_post_attrs(fhp);
358 /* A newly created file already has a file size of zero. */
359 if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0))
360 iap->ia_valid &= ~ATTR_SIZE;
361 if (nfsd4_create_is_exclusive(open->op_createmode)) {
362 iap->ia_valid = ATTR_MTIME | ATTR_ATIME |
363 ATTR_MTIME_SET|ATTR_ATIME_SET;
364 iap->ia_mtime.tv_sec = v_mtime;
365 iap->ia_atime.tv_sec = v_atime;
366 iap->ia_mtime.tv_nsec = 0;
367 iap->ia_atime.tv_nsec = 0;
371 status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs);
373 if (attrs.na_labelerr)
374 open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
376 open->op_bmval[0] &= ~FATTR4_WORD0_ACL;
379 nfsd_attrs_free(&attrs);
380 if (child && !IS_ERR(child))
387 do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
389 struct svc_fh *current_fh = &cstate->current_fh;
393 *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
395 return nfserr_jukebox;
396 fh_init(*resfh, NFS4_FHSIZE);
397 open->op_truncate = false;
399 if (open->op_create) {
400 /* FIXME: check session persistence and pnfs flags.
401 * The nfsv4.1 spec requires the following semantics:
403 * Persistent | pNFS | Server REQUIRED | Client Allowed
404 * Reply Cache | server | |
405 * -------------+--------+-----------------+--------------------
406 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
408 * | | and EXCLUSIVE4 | or EXCLUSIVE4
410 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
411 * yes | no | GUARDED4 | GUARDED4
412 * yes | yes | GUARDED4 | GUARDED4
415 current->fs->umask = open->op_umask;
416 status = nfsd4_create_file(rqstp, current_fh, *resfh, open);
417 current->fs->umask = 0;
420 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
421 * use the returned bitmask to indicate which attributes
422 * we used to store the verifier:
424 if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0)
425 open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
426 FATTR4_WORD1_TIME_MODIFY);
428 status = nfsd_lookup(rqstp, current_fh,
429 open->op_fname, open->op_fnamelen, *resfh);
431 /* NFSv4 protocol requires change attributes even though
432 * no change happened.
434 fh_fill_both_attrs(current_fh);
438 status = nfsd_check_obj_isreg(*resfh);
442 nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
443 accmode = NFSD_MAY_NOP;
444 if (open->op_created ||
445 open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
446 accmode |= NFSD_MAY_OWNER_OVERRIDE;
447 status = do_open_permission(rqstp, *resfh, open, accmode);
448 set_change_info(&open->op_cinfo, current_fh);
454 do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
456 struct svc_fh *current_fh = &cstate->current_fh;
460 /* We don't know the target directory, and therefore can not
461 * set the change info
464 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
466 nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
468 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
469 (open->op_iattr.ia_size == 0);
471 * In the delegation case, the client is telling us about an
472 * open that it *already* performed locally, some time ago. We
473 * should let it succeed now if possible.
475 * In the case of a CLAIM_FH open, on the other hand, the client
476 * may be counting on us to enforce permissions (the Linux 4.1
477 * client uses this for normal opens, for example).
479 if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
480 accmode = NFSD_MAY_OWNER_OVERRIDE;
482 status = do_open_permission(rqstp, current_fh, open, accmode);
488 copy_clientid(clientid_t *clid, struct nfsd4_session *session)
490 struct nfsd4_sessionid *sid =
491 (struct nfsd4_sessionid *)session->se_sessionid.data;
493 clid->cl_boot = sid->clientid.cl_boot;
494 clid->cl_id = sid->clientid.cl_id;
498 nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
501 struct nfsd4_open *open = &u->open;
503 struct svc_fh *resfh = NULL;
504 struct net *net = SVC_NET(rqstp);
505 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
506 bool reclaim = false;
508 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
509 (int)open->op_fnamelen, open->op_fname,
512 open->op_filp = NULL;
513 open->op_rqstp = rqstp;
515 /* This check required by spec. */
516 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
519 open->op_created = false;
522 * Before RECLAIM_COMPLETE done, server should deny new lock
524 if (nfsd4_has_session(cstate) &&
525 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) &&
526 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
529 if (nfsd4_has_session(cstate))
530 copy_clientid(&open->op_clientid, cstate->session);
532 /* check seqid for replay. set nfs4_owner */
533 status = nfsd4_process_open1(cstate, open, nn);
534 if (status == nfserr_replay_me) {
535 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
536 fh_put(&cstate->current_fh);
537 fh_copy_shallow(&cstate->current_fh.fh_handle,
539 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
541 dprintk("nfsd4_open: replay failed"
542 " restoring previous filehandle\n");
544 status = nfserr_replay_me;
548 if (open->op_xdr_error) {
549 status = open->op_xdr_error;
553 status = nfsd4_check_open_attributes(rqstp, cstate, open);
557 /* Openowner is now set, so sequence id will get bumped. Now we need
558 * these checks before we do any creates: */
559 status = nfserr_grace;
560 if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
562 status = nfserr_no_grace;
563 if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
566 switch (open->op_claim_type) {
567 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
568 case NFS4_OPEN_CLAIM_NULL:
569 status = do_open_lookup(rqstp, cstate, open, &resfh);
573 case NFS4_OPEN_CLAIM_PREVIOUS:
574 status = nfs4_check_open_reclaim(cstate->clp);
577 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
580 case NFS4_OPEN_CLAIM_FH:
581 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
582 status = do_open_fhandle(rqstp, cstate, open);
585 resfh = &cstate->current_fh;
587 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
588 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
589 status = nfserr_notsupp;
592 status = nfserr_inval;
596 status = nfsd4_process_open2(rqstp, resfh, open);
597 if (status && open->op_created)
598 pr_warn("nfsd4_process_open2 failed to open newly-created file: status=%u\n",
599 be32_to_cpu(status));
600 if (reclaim && !status)
601 nn->somebody_reclaimed = true;
605 open->op_filp = NULL;
607 if (resfh && resfh != &cstate->current_fh) {
608 fh_dup2(&cstate->current_fh, resfh);
612 nfsd4_cleanup_open_state(cstate, open);
613 nfsd4_bump_seqid(cstate, status);
618 * OPEN is the only seqid-mutating operation whose decoding can fail
619 * with a seqid-mutating error (specifically, decoding of user names in
620 * the attributes). Therefore we have to do some processing to look up
621 * the stateowner so that we can bump the seqid.
623 static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
625 struct nfsd4_open *open = &op->u.open;
627 if (!seqid_mutating_err(ntohl(op->status)))
629 if (nfsd4_has_session(cstate))
631 open->op_xdr_error = op->status;
632 return nfsd4_open(rqstp, cstate, &op->u);
636 * filehandle-manipulating ops.
639 nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
642 u->getfh = &cstate->current_fh;
647 nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
650 struct nfsd4_putfh *putfh = &u->putfh;
653 fh_put(&cstate->current_fh);
654 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
655 memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval,
657 ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
658 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
659 if (ret == nfserr_stale && putfh->no_verify) {
660 SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN);
668 nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
673 fh_put(&cstate->current_fh);
674 status = exp_pseudoroot(rqstp, &cstate->current_fh);
679 nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
682 if (!cstate->save_fh.fh_dentry)
683 return nfserr_restorefh;
685 fh_dup2(&cstate->current_fh, &cstate->save_fh);
686 if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) {
687 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
688 SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
694 nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
697 fh_dup2(&cstate->save_fh, &cstate->current_fh);
698 if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
699 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
700 SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG);
709 nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
712 struct nfsd4_access *access = &u->access;
715 access_full = NFS3_ACCESS_FULL;
716 if (cstate->minorversion >= 2)
717 access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
720 if (access->ac_req_access & ~access_full)
723 access->ac_resp_access = access->ac_req_access;
724 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
725 &access->ac_supported);
728 static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
730 __be32 *verf = (__be32 *)verifier->data;
732 BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data));
734 nfsd_copy_write_verifier(verf, net_generic(net, nfsd_net_id));
738 nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
741 struct nfsd4_commit *commit = &u->commit;
743 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
745 (__be32 *)commit->co_verf.data);
749 nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
752 struct nfsd4_create *create = &u->create;
753 struct nfsd_attrs attrs = {
754 .na_iattr = &create->cr_iattr,
755 .na_seclabel = &create->cr_label,
761 fh_init(&resfh, NFS4_FHSIZE);
763 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
767 status = check_attr_support(rqstp, cstate, create->cr_bmval,
772 status = nfsd4_acl_to_attr(create->cr_type, create->cr_acl, &attrs);
773 current->fs->umask = create->cr_umask;
774 switch (create->cr_type) {
776 status = nfsd_symlink(rqstp, &cstate->current_fh,
777 create->cr_name, create->cr_namelen,
778 create->cr_data, &attrs, &resfh);
782 status = nfserr_inval;
783 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
784 if (MAJOR(rdev) != create->cr_specdata1 ||
785 MINOR(rdev) != create->cr_specdata2)
787 status = nfsd_create(rqstp, &cstate->current_fh,
788 create->cr_name, create->cr_namelen,
789 &attrs, S_IFBLK, rdev, &resfh);
793 status = nfserr_inval;
794 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
795 if (MAJOR(rdev) != create->cr_specdata1 ||
796 MINOR(rdev) != create->cr_specdata2)
798 status = nfsd_create(rqstp, &cstate->current_fh,
799 create->cr_name, create->cr_namelen,
800 &attrs, S_IFCHR, rdev, &resfh);
804 status = nfsd_create(rqstp, &cstate->current_fh,
805 create->cr_name, create->cr_namelen,
806 &attrs, S_IFSOCK, 0, &resfh);
810 status = nfsd_create(rqstp, &cstate->current_fh,
811 create->cr_name, create->cr_namelen,
812 &attrs, S_IFIFO, 0, &resfh);
816 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
817 status = nfsd_create(rqstp, &cstate->current_fh,
818 create->cr_name, create->cr_namelen,
819 &attrs, S_IFDIR, 0, &resfh);
823 status = nfserr_badtype;
829 if (attrs.na_labelerr)
830 create->cr_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
832 create->cr_bmval[0] &= ~FATTR4_WORD0_ACL;
833 set_change_info(&create->cr_cinfo, &cstate->current_fh);
834 fh_dup2(&cstate->current_fh, &resfh);
838 current->fs->umask = 0;
839 nfsd_attrs_free(&attrs);
844 nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
847 struct nfsd4_getattr *getattr = &u->getattr;
850 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
854 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
857 getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
858 getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
859 getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
861 getattr->ga_fhp = &cstate->current_fh;
866 nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
869 struct nfsd4_link *link = &u->link;
872 status = nfsd_link(rqstp, &cstate->current_fh,
873 link->li_name, link->li_namelen, &cstate->save_fh);
875 set_change_info(&link->li_cinfo, &cstate->current_fh);
879 static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
881 struct svc_fh tmp_fh;
884 fh_init(&tmp_fh, NFS4_FHSIZE);
885 ret = exp_pseudoroot(rqstp, &tmp_fh);
888 if (tmp_fh.fh_dentry == fh->fh_dentry) {
893 return nfsd_lookup(rqstp, fh, "..", 2, fh);
897 nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
900 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
904 nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
907 return nfsd_lookup(rqstp, &cstate->current_fh,
908 u->lookup.lo_name, u->lookup.lo_len,
909 &cstate->current_fh);
913 nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
916 struct nfsd4_read *read = &u->read;
921 trace_nfsd_read_start(rqstp, &cstate->current_fh,
922 read->rd_offset, read->rd_length);
924 read->rd_length = min_t(u32, read->rd_length, svc_max_payload(rqstp));
925 if (read->rd_offset > (u64)OFFSET_MAX)
926 read->rd_offset = (u64)OFFSET_MAX;
927 if (read->rd_offset + read->rd_length > (u64)OFFSET_MAX)
928 read->rd_length = (u64)OFFSET_MAX - read->rd_offset;
931 * If we do a zero copy read, then a client will see read data
932 * that reflects the state of the file *after* performing the
933 * following compound.
935 * To ensure proper ordering, we therefore turn off zero copy if
936 * the client wants us to do more in this compound:
938 if (!nfsd4_last_compound_op(rqstp))
939 __clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
942 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
943 &read->rd_stateid, RD_STATE,
946 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
951 read->rd_rqstp = rqstp;
952 read->rd_fhp = &cstate->current_fh;
958 nfsd4_read_release(union nfsd4_op_u *u)
961 nfsd_file_put(u->read.rd_nf);
962 trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
963 u->read.rd_offset, u->read.rd_length);
967 nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
970 struct nfsd4_readdir *readdir = &u->readdir;
971 u64 cookie = readdir->rd_cookie;
972 static const nfs4_verifier zeroverf;
974 /* no need to check permission - this will be done in nfsd_readdir() */
976 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
979 readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
980 readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
981 readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
983 if ((cookie == 1) || (cookie == 2) ||
984 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
985 return nfserr_bad_cookie;
987 readdir->rd_rqstp = rqstp;
988 readdir->rd_fhp = &cstate->current_fh;
993 nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
996 u->readlink.rl_rqstp = rqstp;
997 u->readlink.rl_fhp = &cstate->current_fh;
1002 nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1003 union nfsd4_op_u *u)
1005 struct nfsd4_remove *remove = &u->remove;
1008 if (opens_in_grace(SVC_NET(rqstp)))
1009 return nfserr_grace;
1010 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
1011 remove->rm_name, remove->rm_namelen);
1013 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
1018 nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1019 union nfsd4_op_u *u)
1021 struct nfsd4_rename *rename = &u->rename;
1024 if (opens_in_grace(SVC_NET(rqstp)))
1025 return nfserr_grace;
1026 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
1027 rename->rn_snamelen, &cstate->current_fh,
1028 rename->rn_tname, rename->rn_tnamelen);
1031 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
1032 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
1037 nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1038 union nfsd4_op_u *u)
1040 struct nfsd4_secinfo *secinfo = &u->secinfo;
1041 struct svc_export *exp;
1042 struct dentry *dentry;
1045 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
1048 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
1049 secinfo->si_name, secinfo->si_namelen,
1053 if (d_really_is_negative(dentry)) {
1057 secinfo->si_exp = exp;
1059 if (cstate->minorversion)
1060 /* See rfc 5661 section 2.6.3.1.1.8 */
1061 fh_put(&cstate->current_fh);
1066 nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1067 union nfsd4_op_u *u)
1071 switch (u->secinfo_no_name.sin_style) {
1072 case NFS4_SECINFO_STYLE4_CURRENT_FH:
1074 case NFS4_SECINFO_STYLE4_PARENT:
1075 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
1080 return nfserr_inval;
1083 u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
1084 fh_put(&cstate->current_fh);
1089 nfsd4_secinfo_release(union nfsd4_op_u *u)
1091 if (u->secinfo.si_exp)
1092 exp_put(u->secinfo.si_exp);
1096 nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
1098 if (u->secinfo_no_name.sin_exp)
1099 exp_put(u->secinfo_no_name.sin_exp);
1103 nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1104 union nfsd4_op_u *u)
1106 struct nfsd4_setattr *setattr = &u->setattr;
1107 struct nfsd_attrs attrs = {
1108 .na_iattr = &setattr->sa_iattr,
1109 .na_seclabel = &setattr->sa_label,
1111 struct inode *inode;
1112 __be32 status = nfs_ok;
1115 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
1116 status = nfs4_preprocess_stateid_op(rqstp, cstate,
1117 &cstate->current_fh, &setattr->sa_stateid,
1118 WR_STATE, NULL, NULL);
1120 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
1124 err = fh_want_write(&cstate->current_fh);
1126 return nfserrno(err);
1129 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
1134 inode = cstate->current_fh.fh_dentry->d_inode;
1135 status = nfsd4_acl_to_attr(S_ISDIR(inode->i_mode) ? NF4DIR : NF4REG,
1136 setattr->sa_acl, &attrs);
1140 status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
1143 status = nfserrno(attrs.na_labelerr);
1145 nfsd_attrs_free(&attrs);
1146 fh_drop_write(&cstate->current_fh);
1151 nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1152 union nfsd4_op_u *u)
1154 struct nfsd4_write *write = &u->write;
1155 stateid_t *stateid = &write->wr_stateid;
1156 struct nfsd_file *nf = NULL;
1157 __be32 status = nfs_ok;
1161 if (write->wr_offset > (u64)OFFSET_MAX ||
1162 write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
1165 cnt = write->wr_buflen;
1166 trace_nfsd_write_start(rqstp, &cstate->current_fh,
1167 write->wr_offset, cnt);
1168 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1169 stateid, WR_STATE, &nf, NULL);
1171 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1175 write->wr_how_written = write->wr_stable_how;
1177 nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
1178 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1180 status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
1181 write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
1182 write->wr_how_written,
1183 (__be32 *)write->wr_verifier.data);
1186 write->wr_bytes_written = cnt;
1187 trace_nfsd_write_done(rqstp, &cstate->current_fh,
1188 write->wr_offset, cnt);
1193 nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1194 stateid_t *src_stateid, struct nfsd_file **src,
1195 stateid_t *dst_stateid, struct nfsd_file **dst)
1199 if (!cstate->save_fh.fh_dentry)
1200 return nfserr_nofilehandle;
1202 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
1203 src_stateid, RD_STATE, src, NULL);
1205 dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1209 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1210 dst_stateid, WR_STATE, dst, NULL);
1212 dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1216 /* fix up for NFS-specific error code */
1217 if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
1218 !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
1219 status = nfserr_wrong_type;
1226 nfsd_file_put(*dst);
1228 nfsd_file_put(*src);
1233 nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1234 union nfsd4_op_u *u)
1236 struct nfsd4_clone *clone = &u->clone;
1237 struct nfsd_file *src, *dst;
1240 status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
1241 &clone->cl_dst_stateid, &dst);
1245 status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos,
1246 dst, clone->cl_dst_pos, clone->cl_count,
1247 EX_ISSYNC(cstate->current_fh.fh_export));
1255 static void nfs4_put_copy(struct nfsd4_copy *copy)
1257 if (!refcount_dec_and_test(©->refcount))
1259 kfree(copy->cp_src);
1263 static void nfsd4_stop_copy(struct nfsd4_copy *copy)
1265 if (!test_and_set_bit(NFSD4_COPY_F_STOPPED, ©->cp_flags))
1266 kthread_stop(copy->copy_task);
1267 nfs4_put_copy(copy);
1270 static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp)
1272 struct nfsd4_copy *copy = NULL;
1274 spin_lock(&clp->async_lock);
1275 if (!list_empty(&clp->async_copies)) {
1276 copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
1278 refcount_inc(©->refcount);
1280 spin_unlock(&clp->async_lock);
1284 void nfsd4_shutdown_copy(struct nfs4_client *clp)
1286 struct nfsd4_copy *copy;
1288 while ((copy = nfsd4_get_copy(clp)) != NULL)
1289 nfsd4_stop_copy(copy);
1291 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
1293 extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1294 struct nfs_fh *src_fh,
1295 nfs4_stateid *stateid);
1296 extern void nfs42_ssc_close(struct file *filep);
1298 extern void nfs_sb_deactive(struct super_block *sb);
1300 #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
1303 * setup a work entry in the ssc delayed unmount list.
1305 static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr,
1306 struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt)
1308 struct nfsd4_ssc_umount_item *ni = NULL;
1309 struct nfsd4_ssc_umount_item *work = NULL;
1310 struct nfsd4_ssc_umount_item *tmp;
1315 work = kzalloc(sizeof(*work), GFP_KERNEL);
1317 spin_lock(&nn->nfsd_ssc_lock);
1318 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1319 if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
1322 if (ni->nsui_busy) {
1323 /* wait - and try again */
1324 prepare_to_wait(&nn->nfsd_ssc_waitq, &wait,
1325 TASK_INTERRUPTIBLE);
1326 spin_unlock(&nn->nfsd_ssc_lock);
1328 /* allow 20secs for mount/unmount for now - revisit */
1329 if (signal_pending(current) ||
1330 (schedule_timeout(20*HZ) == 0)) {
1332 return nfserr_eagain;
1334 finish_wait(&nn->nfsd_ssc_waitq, &wait);
1337 *ss_mnt = ni->nsui_vfsmount;
1338 refcount_inc(&ni->nsui_refcnt);
1339 spin_unlock(&nn->nfsd_ssc_lock);
1342 /* return vfsmount in ss_mnt */
1346 strlcpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr) - 1);
1347 refcount_set(&work->nsui_refcnt, 2);
1348 work->nsui_busy = true;
1349 list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list);
1352 spin_unlock(&nn->nfsd_ssc_lock);
1356 static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn,
1357 struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt)
1359 /* set nsui_vfsmount, clear busy flag and wakeup waiters */
1360 spin_lock(&nn->nfsd_ssc_lock);
1361 work->nsui_vfsmount = ss_mnt;
1362 work->nsui_busy = false;
1363 wake_up_all(&nn->nfsd_ssc_waitq);
1364 spin_unlock(&nn->nfsd_ssc_lock);
1367 static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn,
1368 struct nfsd4_ssc_umount_item *work)
1370 spin_lock(&nn->nfsd_ssc_lock);
1371 list_del(&work->nsui_list);
1372 wake_up_all(&nn->nfsd_ssc_waitq);
1373 spin_unlock(&nn->nfsd_ssc_lock);
1378 * Support one copy source server for now.
1381 nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
1382 struct vfsmount **mount)
1384 struct file_system_type *type;
1385 struct vfsmount *ss_mnt;
1386 struct nfs42_netaddr *naddr;
1387 struct sockaddr_storage tmp_addr;
1388 size_t tmp_addrlen, match_netid_len = 3;
1389 char *startsep = "", *endsep = "", *match_netid = "tcp";
1390 char *ipaddr, *dev_name, *raw_data;
1392 __be32 status = nfserr_inval;
1393 struct nfsd4_ssc_umount_item *work = NULL;
1394 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1396 naddr = &nss->u.nl4_addr;
1397 tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
1399 (struct sockaddr *)&tmp_addr,
1401 if (tmp_addrlen == 0)
1404 if (tmp_addr.ss_family == AF_INET6) {
1407 match_netid = "tcp6";
1408 match_netid_len = 4;
1411 if (naddr->netid_len != match_netid_len ||
1412 strncmp(naddr->netid, match_netid, naddr->netid_len))
1415 /* Construct the raw data for the vfs_kern_mount call */
1416 len = RPC_MAX_ADDRBUFLEN + 1;
1417 ipaddr = kzalloc(len, GFP_KERNEL);
1421 rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len);
1423 /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
1425 raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr);
1426 raw_data = kzalloc(raw_len, GFP_KERNEL);
1428 goto out_free_ipaddr;
1430 snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr);
1432 status = nfserr_nodev;
1433 type = get_fs_type("nfs");
1435 goto out_free_rawdata;
1437 /* Set the server:<export> for the vfs_kern_mount call */
1438 dev_name = kzalloc(len + 5, GFP_KERNEL);
1440 goto out_free_rawdata;
1441 snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
1443 status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt);
1445 goto out_free_devname;
1449 /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
1450 ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
1451 module_put(type->owner);
1452 if (IS_ERR(ss_mnt)) {
1453 status = nfserr_nodev;
1455 nfsd4_ssc_cancel_dul_work(nn, work);
1456 goto out_free_devname;
1459 nfsd4_ssc_update_dul_work(nn, work, ss_mnt);
1475 nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1477 nfs_do_sb_deactive(ss_mnt->mnt_sb);
1482 * Verify COPY destination stateid.
1484 * Connect to the source server with NFSv4.1.
1485 * Create the source struct file for nfsd_copy_range.
1486 * Called with COPY cstate:
1487 * SAVED_FH: source filehandle
1488 * CURRENT_FH: destination filehandle
1491 nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1492 struct nfsd4_compound_state *cstate,
1493 struct nfsd4_copy *copy, struct vfsmount **mount)
1495 struct svc_fh *s_fh = NULL;
1496 stateid_t *s_stid = ©->cp_src_stateid;
1497 __be32 status = nfserr_inval;
1499 /* Verify the destination stateid and set dst struct file*/
1500 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1501 ©->cp_dst_stateid,
1502 WR_STATE, ©->nf_dst, NULL);
1506 status = nfsd4_interssc_connect(copy->cp_src, rqstp, mount);
1510 s_fh = &cstate->save_fh;
1512 copy->c_fh.size = s_fh->fh_handle.fh_size;
1513 memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size);
1514 copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
1515 memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
1516 sizeof(stateid_opaque_t));
1524 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp,
1525 struct nfsd_file *dst)
1529 struct nfsd4_ssc_umount_item *tmp;
1530 struct nfsd4_ssc_umount_item *ni = NULL;
1531 struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
1533 nfs42_ssc_close(filp);
1541 spin_lock(&nn->nfsd_ssc_lock);
1542 timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
1543 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
1544 if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
1545 list_del(&ni->nsui_list);
1547 * vfsmount can be shared by multiple exports,
1548 * decrement refcnt. If the count drops to 1 it
1549 * will be unmounted when nsui_expire expires.
1551 refcount_dec(&ni->nsui_refcnt);
1552 ni->nsui_expire = jiffies + timeout;
1553 list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list);
1558 spin_unlock(&nn->nfsd_ssc_lock);
1565 #else /* CONFIG_NFSD_V4_2_INTER_SSC */
1568 nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
1569 struct nfsd4_compound_state *cstate,
1570 struct nfsd4_copy *copy,
1571 struct vfsmount **mount)
1574 return nfserr_inval;
1578 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp,
1579 struct nfsd_file *dst)
1584 nfsd4_interssc_disconnect(struct vfsmount *ss_mnt)
1588 static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
1589 struct nfs_fh *src_fh,
1590 nfs4_stateid *stateid)
1594 #endif /* CONFIG_NFSD_V4_2_INTER_SSC */
1597 nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
1598 struct nfsd4_compound_state *cstate,
1599 struct nfsd4_copy *copy)
1601 return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid,
1602 ©->nf_src, ©->cp_dst_stateid,
1607 nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst)
1613 static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
1615 struct nfsd4_cb_offload *cbo =
1616 container_of(cb, struct nfsd4_cb_offload, co_cb);
1621 static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
1622 struct rpc_task *task)
1627 static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
1628 .release = nfsd4_cb_offload_release,
1629 .done = nfsd4_cb_offload_done
1632 static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
1634 copy->cp_res.wr_stable_how =
1635 test_bit(NFSD4_COPY_F_COMMITTED, ©->cp_flags) ?
1636 NFS_FILE_SYNC : NFS_UNSTABLE;
1637 nfsd4_copy_set_sync(copy, sync);
1638 gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net);
1641 static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy,
1646 ssize_t bytes_copied = 0;
1647 u64 bytes_total = copy->cp_count;
1648 u64 src_pos = copy->cp_src_pos;
1649 u64 dst_pos = copy->cp_dst_pos;
1652 /* See RFC 7862 p.67: */
1653 if (bytes_total == 0)
1654 bytes_total = ULLONG_MAX;
1656 if (kthread_should_stop())
1658 bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos,
1660 if (bytes_copied <= 0)
1662 bytes_total -= bytes_copied;
1663 copy->cp_res.wr_bytes_written += bytes_copied;
1664 src_pos += bytes_copied;
1665 dst_pos += bytes_copied;
1666 } while (bytes_total > 0 && nfsd4_copy_is_async(copy));
1667 /* for a non-zero asynchronous copy do a commit of data */
1668 if (nfsd4_copy_is_async(copy) && copy->cp_res.wr_bytes_written > 0) {
1669 since = READ_ONCE(dst->f_wb_err);
1670 status = vfs_fsync_range(dst, copy->cp_dst_pos,
1671 copy->cp_res.wr_bytes_written, 0);
1673 status = filemap_check_wb_err(dst->f_mapping, since);
1675 set_bit(NFSD4_COPY_F_COMMITTED, ©->cp_flags);
1677 return bytes_copied;
1680 static __be32 nfsd4_do_copy(struct nfsd4_copy *copy,
1681 struct file *src, struct file *dst,
1687 bytes = _nfsd_copy_file_range(copy, dst, src);
1689 /* for async copy, we ignore the error, client can always retry
1692 if (bytes < 0 && !copy->cp_res.wr_bytes_written)
1693 status = nfserrno(bytes);
1695 nfsd4_init_copy_res(copy, sync);
1701 static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
1703 dst->cp_src_pos = src->cp_src_pos;
1704 dst->cp_dst_pos = src->cp_dst_pos;
1705 dst->cp_count = src->cp_count;
1706 dst->cp_flags = src->cp_flags;
1707 memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
1708 memcpy(&dst->fh, &src->fh, sizeof(src->fh));
1709 dst->cp_clp = src->cp_clp;
1710 dst->nf_dst = nfsd_file_get(src->nf_dst);
1711 /* for inter, nf_src doesn't exist yet */
1712 if (!nfsd4_ssc_is_inter(src))
1713 dst->nf_src = nfsd_file_get(src->nf_src);
1715 memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
1716 memcpy(dst->cp_src, src->cp_src, sizeof(struct nl4_server));
1717 memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid));
1718 memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh));
1719 dst->ss_mnt = src->ss_mnt;
1722 static void cleanup_async_copy(struct nfsd4_copy *copy)
1724 nfs4_free_copy_state(copy);
1725 nfsd_file_put(copy->nf_dst);
1726 if (!nfsd4_ssc_is_inter(copy))
1727 nfsd_file_put(copy->nf_src);
1728 spin_lock(©->cp_clp->async_lock);
1729 list_del(©->copies);
1730 spin_unlock(©->cp_clp->async_lock);
1731 nfs4_put_copy(copy);
1734 static void nfsd4_send_cb_offload(struct nfsd4_copy *copy, __be32 nfserr)
1736 struct nfsd4_cb_offload *cbo;
1738 cbo = kzalloc(sizeof(*cbo), GFP_KERNEL);
1742 memcpy(&cbo->co_res, ©->cp_res, sizeof(copy->cp_res));
1743 memcpy(&cbo->co_fh, ©->fh, sizeof(copy->fh));
1744 cbo->co_nfserr = nfserr;
1746 nfsd4_init_cb(&cbo->co_cb, copy->cp_clp, &nfsd4_cb_offload_ops,
1747 NFSPROC4_CLNT_CB_OFFLOAD);
1748 trace_nfsd_cb_offload(copy->cp_clp, &cbo->co_res.cb_stateid,
1749 &cbo->co_fh, copy->cp_count, nfserr);
1750 nfsd4_run_cb(&cbo->co_cb);
1754 * nfsd4_do_async_copy - kthread function for background server-side COPY
1755 * @data: arguments for COPY operation
1758 * %0: Copy operation is done.
1760 static int nfsd4_do_async_copy(void *data)
1762 struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1765 if (nfsd4_ssc_is_inter(copy)) {
1768 filp = nfs42_ssc_open(copy->ss_mnt, ©->c_fh,
1771 nfserr = nfserr_offload_denied;
1772 nfsd4_interssc_disconnect(copy->ss_mnt);
1775 nfserr = nfsd4_do_copy(copy, filp, copy->nf_dst->nf_file,
1777 nfsd4_cleanup_inter_ssc(copy->ss_mnt, filp, copy->nf_dst);
1779 nfserr = nfsd4_do_copy(copy, copy->nf_src->nf_file,
1780 copy->nf_dst->nf_file, false);
1781 nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
1785 nfsd4_send_cb_offload(copy, nfserr);
1786 cleanup_async_copy(copy);
1791 nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1792 union nfsd4_op_u *u)
1794 struct nfsd4_copy *copy = &u->copy;
1796 struct nfsd4_copy *async_copy = NULL;
1798 if (nfsd4_ssc_is_inter(copy)) {
1799 if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) {
1800 status = nfserr_notsupp;
1803 status = nfsd4_setup_inter_ssc(rqstp, cstate, copy,
1806 return nfserr_offload_denied;
1808 status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
1813 copy->cp_clp = cstate->clp;
1814 memcpy(©->fh, &cstate->current_fh.fh_handle,
1815 sizeof(struct knfsd_fh));
1816 if (nfsd4_copy_is_async(copy)) {
1817 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1819 status = nfserrno(-ENOMEM);
1820 async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1823 async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL);
1824 if (!async_copy->cp_src)
1826 if (!nfs4_init_copy_state(nn, copy))
1828 refcount_set(&async_copy->refcount, 1);
1829 memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid,
1830 sizeof(copy->cp_res.cb_stateid));
1831 dup_copy_fields(copy, async_copy);
1832 async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
1833 async_copy, "%s", "copy thread");
1834 if (IS_ERR(async_copy->copy_task))
1836 spin_lock(&async_copy->cp_clp->async_lock);
1837 list_add(&async_copy->copies,
1838 &async_copy->cp_clp->async_copies);
1839 spin_unlock(&async_copy->cp_clp->async_lock);
1840 wake_up_process(async_copy->copy_task);
1843 status = nfsd4_do_copy(copy, copy->nf_src->nf_file,
1844 copy->nf_dst->nf_file, true);
1845 nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
1851 cleanup_async_copy(async_copy);
1852 status = nfserrno(-ENOMEM);
1853 if (nfsd4_ssc_is_inter(copy))
1854 nfsd4_interssc_disconnect(copy->ss_mnt);
1859 find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
1861 struct nfsd4_copy *copy;
1863 spin_lock(&clp->async_lock);
1864 list_for_each_entry(copy, &clp->async_copies, copies) {
1865 if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE))
1867 refcount_inc(©->refcount);
1868 spin_unlock(&clp->async_lock);
1871 spin_unlock(&clp->async_lock);
1876 nfsd4_offload_cancel(struct svc_rqst *rqstp,
1877 struct nfsd4_compound_state *cstate,
1878 union nfsd4_op_u *u)
1880 struct nfsd4_offload_status *os = &u->offload_status;
1881 struct nfsd4_copy *copy;
1882 struct nfs4_client *clp = cstate->clp;
1884 copy = find_async_copy(clp, &os->stateid);
1886 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1888 return manage_cpntf_state(nn, &os->stateid, clp, NULL);
1890 nfsd4_stop_copy(copy);
1896 nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1897 union nfsd4_op_u *u)
1899 struct nfsd4_copy_notify *cn = &u->copy_notify;
1901 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1902 struct nfs4_stid *stid;
1903 struct nfs4_cpntf_state *cps;
1904 struct nfs4_client *clp = cstate->clp;
1906 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1907 &cn->cpn_src_stateid, RD_STATE, NULL,
1912 cn->cpn_sec = nn->nfsd4_lease;
1915 status = nfserrno(-ENOMEM);
1916 cps = nfs4_alloc_init_cpntf_state(nn, stid);
1919 memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t));
1920 memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t));
1921 memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t));
1923 /* For now, only return one server address in cpn_src, the
1924 * address used by the client to connect to this server.
1926 cn->cpn_src->nl4_type = NL4_NETADDR;
1927 status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr,
1928 &cn->cpn_src->u.nl4_addr);
1929 WARN_ON_ONCE(status);
1931 nfs4_put_cpntf_state(nn, cps);
1935 nfs4_put_stid(stid);
1940 nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1941 struct nfsd4_fallocate *fallocate, int flags)
1944 struct nfsd_file *nf;
1946 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1947 &fallocate->falloc_stateid,
1948 WR_STATE, &nf, NULL);
1949 if (status != nfs_ok) {
1950 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
1954 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
1955 fallocate->falloc_offset,
1956 fallocate->falloc_length,
1962 nfsd4_offload_status(struct svc_rqst *rqstp,
1963 struct nfsd4_compound_state *cstate,
1964 union nfsd4_op_u *u)
1966 struct nfsd4_offload_status *os = &u->offload_status;
1968 struct nfsd4_copy *copy;
1969 struct nfs4_client *clp = cstate->clp;
1971 copy = find_async_copy(clp, &os->stateid);
1973 os->count = copy->cp_res.wr_bytes_written;
1974 nfs4_put_copy(copy);
1976 status = nfserr_bad_stateid;
1982 nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1983 union nfsd4_op_u *u)
1985 return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
1989 nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1990 union nfsd4_op_u *u)
1992 return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
1993 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
1997 nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1998 union nfsd4_op_u *u)
2000 struct nfsd4_seek *seek = &u->seek;
2003 struct nfsd_file *nf;
2005 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
2006 &seek->seek_stateid,
2007 RD_STATE, &nf, NULL);
2009 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
2013 switch (seek->seek_whence) {
2014 case NFS4_CONTENT_DATA:
2017 case NFS4_CONTENT_HOLE:
2021 status = nfserr_union_notsupp;
2026 * Note: This call does change file->f_pos, but nothing in NFSD
2027 * should ever file->f_pos.
2029 seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
2030 if (seek->seek_pos < 0)
2031 status = nfserrno(seek->seek_pos);
2032 else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
2033 seek->seek_eof = true;
2040 /* This routine never returns NFS_OK! If there are no other errors, it
2041 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
2042 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
2043 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
2046 _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2047 struct nfsd4_verify *verify)
2053 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
2057 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
2061 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
2062 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
2063 return nfserr_inval;
2064 if (verify->ve_attrlen & 3)
2065 return nfserr_inval;
2068 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
2070 count = 4 + (verify->ve_attrlen >> 2);
2071 buf = kmalloc(count << 2, GFP_KERNEL);
2073 return nfserr_jukebox;
2076 status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
2077 cstate->current_fh.fh_export,
2078 cstate->current_fh.fh_dentry,
2082 * If nfsd4_encode_fattr() ran out of space, assume that's because
2083 * the attributes are longer (hence different) than those given:
2085 if (status == nfserr_resource)
2086 status = nfserr_not_same;
2091 p = buf + 1 + ntohl(buf[0]);
2092 status = nfserr_not_same;
2093 if (ntohl(*p++) != verify->ve_attrlen)
2095 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
2096 status = nfserr_same;
2104 nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2105 union nfsd4_op_u *u)
2109 status = _nfsd4_verify(rqstp, cstate, &u->verify);
2110 return status == nfserr_not_same ? nfs_ok : status;
2114 nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2115 union nfsd4_op_u *u)
2119 status = _nfsd4_verify(rqstp, cstate, &u->nverify);
2120 return status == nfserr_same ? nfs_ok : status;
2123 #ifdef CONFIG_NFSD_PNFS
2124 static const struct nfsd4_layout_ops *
2125 nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
2127 if (!exp->ex_layout_types) {
2128 dprintk("%s: export does not support pNFS\n", __func__);
2132 if (layout_type >= LAYOUT_TYPE_MAX ||
2133 !(exp->ex_layout_types & (1 << layout_type))) {
2134 dprintk("%s: layout type %d not supported\n",
2135 __func__, layout_type);
2139 return nfsd4_layout_ops[layout_type];
2143 nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
2144 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2146 struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
2147 const struct nfsd4_layout_ops *ops;
2148 struct nfsd4_deviceid_map *map;
2149 struct svc_export *exp;
2152 dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
2154 gdp->gd_layout_type,
2155 gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
2158 map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
2160 dprintk("%s: couldn't find device ID to export mapping!\n",
2162 return nfserr_noent;
2165 exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
2167 dprintk("%s: could not find device id\n", __func__);
2168 return nfserr_noent;
2171 nfserr = nfserr_layoutunavailable;
2172 ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
2177 if (gdp->gd_maxcount != 0) {
2178 nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
2179 rqstp, cstate->clp, gdp);
2182 gdp->gd_notify_types &= ops->notify_types;
2189 nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
2191 kfree(u->getdeviceinfo.gd_device);
2195 nfsd4_layoutget(struct svc_rqst *rqstp,
2196 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2198 struct nfsd4_layoutget *lgp = &u->layoutget;
2199 struct svc_fh *current_fh = &cstate->current_fh;
2200 const struct nfsd4_layout_ops *ops;
2201 struct nfs4_layout_stateid *ls;
2203 int accmode = NFSD_MAY_READ_IF_EXEC;
2205 switch (lgp->lg_seg.iomode) {
2207 accmode |= NFSD_MAY_READ;
2210 accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
2213 dprintk("%s: invalid iomode %d\n",
2214 __func__, lgp->lg_seg.iomode);
2215 nfserr = nfserr_badiomode;
2219 nfserr = fh_verify(rqstp, current_fh, 0, accmode);
2223 nfserr = nfserr_layoutunavailable;
2224 ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
2229 * Verify minlength and range as per RFC5661:
2230 * o If loga_length is less than loga_minlength,
2231 * the metadata server MUST return NFS4ERR_INVAL.
2232 * o If the sum of loga_offset and loga_minlength exceeds
2233 * NFS4_UINT64_MAX, and loga_minlength is not
2234 * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
2235 * o If the sum of loga_offset and loga_length exceeds
2236 * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
2237 * the error NFS4ERR_INVAL MUST result.
2239 nfserr = nfserr_inval;
2240 if (lgp->lg_seg.length < lgp->lg_minlength ||
2241 (lgp->lg_minlength != NFS4_MAX_UINT64 &&
2242 lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
2243 (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
2244 lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
2246 if (lgp->lg_seg.length == 0)
2249 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
2250 true, lgp->lg_layout_type, &ls);
2252 trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
2256 nfserr = nfserr_recallconflict;
2257 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
2260 nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
2265 nfserr = nfsd4_insert_layout(lgp, ls);
2268 mutex_unlock(&ls->ls_mutex);
2269 nfs4_put_stid(&ls->ls_stid);
2275 nfsd4_layoutget_release(union nfsd4_op_u *u)
2277 kfree(u->layoutget.lg_content);
2281 nfsd4_layoutcommit(struct svc_rqst *rqstp,
2282 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2284 struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
2285 const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
2286 struct svc_fh *current_fh = &cstate->current_fh;
2287 const struct nfsd4_layout_ops *ops;
2288 loff_t new_size = lcp->lc_last_wr + 1;
2289 struct inode *inode;
2290 struct nfs4_layout_stateid *ls;
2293 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
2297 nfserr = nfserr_layoutunavailable;
2298 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
2301 inode = d_inode(current_fh->fh_dentry);
2303 nfserr = nfserr_inval;
2304 if (new_size <= seg->offset) {
2305 dprintk("pnfsd: last write before layout segment\n");
2308 if (new_size > seg->offset + seg->length) {
2309 dprintk("pnfsd: last write beyond layout segment\n");
2312 if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
2313 dprintk("pnfsd: layoutcommit beyond EOF\n");
2317 nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
2318 false, lcp->lc_layout_type,
2321 trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
2322 /* fixup error code as per RFC5661 */
2323 if (nfserr == nfserr_bad_stateid)
2324 nfserr = nfserr_badlayout;
2328 /* LAYOUTCOMMIT does not require any serialization */
2329 mutex_unlock(&ls->ls_mutex);
2331 if (new_size > i_size_read(inode)) {
2332 lcp->lc_size_chg = 1;
2333 lcp->lc_newsize = new_size;
2335 lcp->lc_size_chg = 0;
2338 nfserr = ops->proc_layoutcommit(inode, lcp);
2339 nfs4_put_stid(&ls->ls_stid);
2345 nfsd4_layoutreturn(struct svc_rqst *rqstp,
2346 struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
2348 struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
2349 struct svc_fh *current_fh = &cstate->current_fh;
2352 nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
2356 nfserr = nfserr_layoutunavailable;
2357 if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
2360 switch (lrp->lr_seg.iomode) {
2366 dprintk("%s: invalid iomode %d\n", __func__,
2367 lrp->lr_seg.iomode);
2368 nfserr = nfserr_inval;
2372 switch (lrp->lr_return_type) {
2374 nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
2378 nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
2381 dprintk("%s: invalid return_type %d\n", __func__,
2382 lrp->lr_return_type);
2383 nfserr = nfserr_inval;
2389 #endif /* CONFIG_NFSD_PNFS */
2392 nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2393 union nfsd4_op_u *u)
2395 struct nfsd4_getxattr *getxattr = &u->getxattr;
2397 return nfsd_getxattr(rqstp, &cstate->current_fh,
2398 getxattr->getxa_name, &getxattr->getxa_buf,
2399 &getxattr->getxa_len);
2403 nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2404 union nfsd4_op_u *u)
2406 struct nfsd4_setxattr *setxattr = &u->setxattr;
2409 if (opens_in_grace(SVC_NET(rqstp)))
2410 return nfserr_grace;
2412 ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
2413 setxattr->setxa_buf, setxattr->setxa_len,
2414 setxattr->setxa_flags);
2417 set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
2423 nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2424 union nfsd4_op_u *u)
2427 * Get the entire list, then copy out only the user attributes
2428 * in the encode function.
2430 return nfsd_listxattr(rqstp, &cstate->current_fh,
2431 &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
2435 nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2436 union nfsd4_op_u *u)
2438 struct nfsd4_removexattr *removexattr = &u->removexattr;
2441 if (opens_in_grace(SVC_NET(rqstp)))
2442 return nfserr_grace;
2444 ret = nfsd_removexattr(rqstp, &cstate->current_fh,
2445 removexattr->rmxa_name);
2448 set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
2457 nfsd4_proc_null(struct svc_rqst *rqstp)
2462 static inline void nfsd4_increment_op_stats(u32 opnum)
2464 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
2465 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]);
2468 static const struct nfsd4_operation nfsd4_ops[];
2470 static const char *nfsd4_op_name(unsigned opnum);
2473 * Enforce NFSv4.1 COMPOUND ordering rules:
2475 * Also note, enforced elsewhere:
2476 * - SEQUENCE other than as first op results in
2477 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
2478 * - BIND_CONN_TO_SESSION must be the only op in its compound.
2479 * (Enforced in nfsd4_bind_conn_to_session().)
2480 * - DESTROY_SESSION must be the final operation in a compound, if
2481 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
2482 * (Enforced in nfsd4_destroy_session().)
2484 static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
2486 struct nfsd4_op *first_op = &args->ops[0];
2488 /* These ordering requirements don't apply to NFSv4.0: */
2489 if (args->minorversion == 0)
2491 /* This is weird, but OK, not our problem: */
2492 if (args->opcnt == 0)
2494 if (first_op->status == nfserr_op_illegal)
2496 if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
2497 return nfserr_op_not_in_session;
2498 if (first_op->opnum == OP_SEQUENCE)
2501 * So first_op is something allowed outside a session, like
2502 * EXCHANGE_ID; but then it has to be the only op in the
2505 if (args->opcnt != 1)
2506 return nfserr_not_only_op;
2510 const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
2512 return &nfsd4_ops[op->opnum];
2515 bool nfsd4_cache_this_op(struct nfsd4_op *op)
2517 if (op->opnum == OP_ILLEGAL)
2519 return OPDESC(op)->op_flags & OP_CACHEME;
2522 static bool need_wrongsec_check(struct svc_rqst *rqstp)
2524 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2525 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2526 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2527 struct nfsd4_op *next = &argp->ops[resp->opcnt];
2528 const struct nfsd4_operation *thisd = OPDESC(this);
2529 const struct nfsd4_operation *nextd;
2532 * Most ops check wronsec on our own; only the putfh-like ops
2533 * have special rules.
2535 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
2538 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
2539 * put-filehandle operation if we're not going to use the
2542 if (argp->opcnt == resp->opcnt)
2544 if (next->opnum == OP_ILLEGAL)
2546 nextd = OPDESC(next);
2548 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
2549 * errors themselves as necessary; others should check for them
2552 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
2555 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
2557 check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2559 struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL;
2560 struct nfsd4_copy *copy;
2561 struct nfsd4_putfh *putfh;
2564 /* traverse all operation and if it's a COPY compound, mark the
2565 * source filehandle to skip verification
2567 for (i = 0; i < args->opcnt; i++) {
2569 if (op->opnum == OP_PUTFH)
2571 else if (op->opnum == OP_SAVEFH)
2572 saved_op = current_op;
2573 else if (op->opnum == OP_RESTOREFH)
2574 current_op = saved_op;
2575 else if (op->opnum == OP_COPY) {
2576 copy = (struct nfsd4_copy *)&op->u;
2578 op->status = nfserr_nofilehandle;
2581 putfh = (struct nfsd4_putfh *)&saved_op->u;
2582 if (nfsd4_ssc_is_inter(copy))
2583 putfh->no_verify = true;
2589 check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
2598 nfsd4_proc_compound(struct svc_rqst *rqstp)
2600 struct nfsd4_compoundargs *args = rqstp->rq_argp;
2601 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2602 struct nfsd4_op *op;
2603 struct nfsd4_compound_state *cstate = &resp->cstate;
2604 struct svc_fh *current_fh = &cstate->current_fh;
2605 struct svc_fh *save_fh = &cstate->save_fh;
2606 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
2609 resp->xdr = &rqstp->rq_res_stream;
2610 resp->statusp = resp->xdr->p;
2612 /* reserve space for: NFS status code */
2613 xdr_reserve_space(resp->xdr, XDR_UNIT);
2615 /* reserve space for: taglen, tag, and opcnt */
2616 xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
2617 resp->taglen = args->taglen;
2618 resp->tag = args->tag;
2619 resp->rqstp = rqstp;
2620 cstate->minorversion = args->minorversion;
2621 fh_init(current_fh, NFS4_FHSIZE);
2622 fh_init(save_fh, NFS4_FHSIZE);
2625 * Don't use the deferral mechanism for NFSv4; compounds make it
2626 * too hard to avoid non-idempotency problems.
2628 __clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
2631 * According to RFC3010, this takes precedence over all other errors.
2633 status = nfserr_minor_vers_mismatch;
2634 if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
2636 status = nfserr_resource;
2637 if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
2640 status = nfs41_check_op_ordering(args);
2643 op->status = status;
2647 check_if_stalefh_allowed(args);
2649 rqstp->rq_lease_breaker = (void **)&cstate->clp;
2651 trace_nfsd_compound(rqstp, args->opcnt);
2652 while (!status && resp->opcnt < args->opcnt) {
2653 op = &args->ops[resp->opcnt++];
2656 * The XDR decode routines may have pre-set op->status;
2657 * for example, if there is a miscellaneous XDR error
2658 * it will be set to nfserr_bad_xdr.
2661 if (op->opnum == OP_OPEN)
2662 op->status = nfsd4_open_omfg(rqstp, cstate, op);
2665 if (!current_fh->fh_dentry &&
2666 !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) {
2667 if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
2668 op->status = nfserr_nofilehandle;
2671 } else if (current_fh->fh_export &&
2672 current_fh->fh_export->ex_fslocs.migrated &&
2673 !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
2674 op->status = nfserr_moved;
2678 fh_clear_pre_post_attrs(current_fh);
2680 /* If op is non-idempotent */
2681 if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
2683 * Don't execute this op if we couldn't encode a
2686 u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
2688 * Plus if there's another operation, make sure
2689 * we'll have space to at least encode an error:
2691 if (resp->opcnt < args->opcnt)
2692 plen += COMPOUND_ERR_SLACK_SPACE;
2693 op->status = nfsd4_check_resp_size(resp, plen);
2699 if (op->opdesc->op_get_currentstateid)
2700 op->opdesc->op_get_currentstateid(cstate, &op->u);
2701 op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
2703 /* Only from SEQUENCE */
2704 if (cstate->status == nfserr_replay_cache) {
2705 dprintk("%s NFS4.1 replay from cache\n", __func__);
2706 status = op->status;
2710 if (op->opdesc->op_set_currentstateid)
2711 op->opdesc->op_set_currentstateid(cstate, &op->u);
2713 if (op->opdesc->op_flags & OP_CLEAR_STATEID)
2714 clear_current_stateid(cstate);
2716 if (current_fh->fh_export &&
2717 need_wrongsec_check(rqstp))
2718 op->status = check_nfsd_access(current_fh->fh_export, rqstp);
2721 if (op->status == nfserr_replay_me) {
2722 op->replay = &cstate->replay_owner->so_replay;
2723 nfsd4_encode_replay(resp->xdr, op);
2724 status = op->status = op->replay->rp_status;
2726 nfsd4_encode_operation(resp, op);
2727 status = op->status;
2730 trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
2731 nfsd4_op_name(op->opnum));
2733 nfsd4_cstate_clear_replay(cstate);
2734 nfsd4_increment_op_stats(op->opnum);
2739 BUG_ON(cstate->replay_owner);
2741 cstate->status = status;
2742 /* Reset deferral mechanism for RPC deferrals */
2743 __set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
2747 #define op_encode_hdr_size (2)
2748 #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
2749 #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
2750 #define op_encode_change_info_maxsz (5)
2751 #define nfs4_fattr_bitmap_maxsz (4)
2753 /* We'll fall back on returning no lockowner if run out of space: */
2754 #define op_encode_lockowner_maxsz (0)
2755 #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
2757 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
2759 #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
2760 #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
2761 op_encode_ace_maxsz)
2763 #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
2765 static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2767 return (op_encode_hdr_size) * sizeof(__be32);
2770 static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2772 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
2775 static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2777 /* ac_supported, ac_resp_access */
2778 return (op_encode_hdr_size + 2)* sizeof(__be32);
2781 static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2783 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
2786 static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2788 return (op_encode_hdr_size + op_encode_change_info_maxsz
2789 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2793 * Note since this is an idempotent operation we won't insist on failing
2794 * the op prematurely if the estimate is too large. We may turn off splice
2795 * reads unnecessarily.
2797 static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
2798 struct nfsd4_op *op)
2800 u32 *bmap = op->u.getattr.ga_bmval;
2801 u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
2804 if (bmap0 & FATTR4_WORD0_ACL)
2805 return svc_max_payload(rqstp);
2806 if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
2807 return svc_max_payload(rqstp);
2809 if (bmap1 & FATTR4_WORD1_OWNER) {
2810 ret += IDMAP_NAMESZ + 4;
2811 bmap1 &= ~FATTR4_WORD1_OWNER;
2813 if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
2814 ret += IDMAP_NAMESZ + 4;
2815 bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
2817 if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
2818 ret += NFS4_FHSIZE + 4;
2819 bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
2821 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
2822 ret += NFS4_MAXLABELLEN + 12;
2823 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2826 * Largest of remaining attributes are 16 bytes (e.g.,
2827 * supported_attributes)
2829 ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
2830 /* bitmask, length */
2835 static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2837 return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
2840 static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2842 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2846 static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2848 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
2852 static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2854 return (op_encode_hdr_size + op_encode_stateid_maxsz
2855 + op_encode_change_info_maxsz + 1
2856 + nfs4_fattr_bitmap_maxsz
2857 + op_encode_delegation_maxsz) * sizeof(__be32);
2860 static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2862 u32 maxcount = 0, rlen = 0;
2864 maxcount = svc_max_payload(rqstp);
2865 rlen = min(op->u.read.rd_length, maxcount);
2867 return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2870 static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2872 u32 maxcount = svc_max_payload(rqstp);
2873 u32 rlen = min(op->u.read.rd_length, maxcount);
2875 * If we detect that the file changed during hole encoding, then we
2876 * recover by encoding the remaining reply as data. This means we need
2877 * to set aside enough room to encode two data segments.
2879 u32 seg_len = 2 * (1 + 2 + 1);
2881 return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32);
2884 static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2886 u32 maxcount = 0, rlen = 0;
2888 maxcount = svc_max_payload(rqstp);
2889 rlen = min(op->u.readdir.rd_maxcount, maxcount);
2891 return (op_encode_hdr_size + op_encode_verifier_maxsz +
2892 XDR_QUADLEN(rlen)) * sizeof(__be32);
2895 static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2897 return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
2900 static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2902 return (op_encode_hdr_size + op_encode_change_info_maxsz)
2906 static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2908 return (op_encode_hdr_size + op_encode_change_info_maxsz
2909 + op_encode_change_info_maxsz) * sizeof(__be32);
2912 static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
2913 struct nfsd4_op *op)
2915 return (op_encode_hdr_size
2916 + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
2919 static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2921 return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
2925 static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2927 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
2930 static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2932 return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
2933 (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
2936 static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2938 return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2942 static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2944 return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
2947 static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2949 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
2950 1 + 1 + /* eir_flags, spr_how */\
2951 4 + /* spo_must_enforce & _allow with bitmap */\
2952 2 + /*eir_server_owner.so_minor_id */\
2953 /* eir_server_owner.so_major_id<> */\
2954 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2955 /* eir_server_scope<> */\
2956 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
2957 1 + /* eir_server_impl_id array length */\
2958 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
2961 static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2963 return (op_encode_hdr_size + \
2964 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
2965 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
2968 static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2970 return (op_encode_hdr_size + \
2971 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
2972 2 + /* csr_sequence, csr_flags */\
2973 op_encode_channel_attrs_maxsz + \
2974 op_encode_channel_attrs_maxsz) * sizeof(__be32);
2977 static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
2979 return (op_encode_hdr_size +
2980 1 /* wr_callback */ +
2981 op_encode_stateid_maxsz /* wr_callback */ +
2983 1 /* wr_committed */ +
2984 op_encode_verifier_maxsz +
2985 1 /* cr_consecutive */ +
2986 1 /* cr_synchronous */) * sizeof(__be32);
2989 static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
2990 struct nfsd4_op *op)
2992 return (op_encode_hdr_size +
2994 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
2997 static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp,
2998 struct nfsd4_op *op)
3000 return (op_encode_hdr_size +
3001 3 /* cnr_lease_time */ +
3002 1 /* We support one cnr_source_server */ +
3003 1 /* cnr_stateid seq */ +
3004 op_encode_stateid_maxsz /* cnr_stateid */ +
3005 1 /* num cnr_source_server*/ +
3008 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */)
3012 #ifdef CONFIG_NFSD_PNFS
3013 static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3015 u32 maxcount = 0, rlen = 0;
3017 maxcount = svc_max_payload(rqstp);
3018 rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
3020 return (op_encode_hdr_size +
3021 1 /* gd_layout_type*/ +
3023 2 /* gd_notify_types */) * sizeof(__be32);
3027 * At this stage we don't really know what layout driver will handle the request,
3028 * so we need to define an arbitrary upper bound here.
3030 #define MAX_LAYOUT_SIZE 128
3031 static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3033 return (op_encode_hdr_size +
3034 1 /* logr_return_on_close */ +
3035 op_encode_stateid_maxsz +
3036 1 /* nr of layouts */ +
3037 MAX_LAYOUT_SIZE) * sizeof(__be32);
3040 static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3042 return (op_encode_hdr_size +
3043 1 /* locr_newsize */ +
3044 2 /* ns_size */) * sizeof(__be32);
3047 static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3049 return (op_encode_hdr_size +
3050 1 /* lrs_stateid */ +
3051 op_encode_stateid_maxsz) * sizeof(__be32);
3053 #endif /* CONFIG_NFSD_PNFS */
3056 static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
3058 return (op_encode_hdr_size + 3) * sizeof(__be32);
3061 static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp,
3062 struct nfsd4_op *op)
3066 maxcount = svc_max_payload(rqstp);
3067 rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
3069 return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3072 static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp,
3073 struct nfsd4_op *op)
3075 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3078 static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp,
3079 struct nfsd4_op *op)
3083 maxcount = svc_max_payload(rqstp);
3084 rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
3086 return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
3089 static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp,
3090 struct nfsd4_op *op)
3092 return (op_encode_hdr_size + op_encode_change_info_maxsz)
3097 static const struct nfsd4_operation nfsd4_ops[] = {
3099 .op_func = nfsd4_access,
3100 .op_name = "OP_ACCESS",
3101 .op_rsize_bop = nfsd4_access_rsize,
3104 .op_func = nfsd4_close,
3105 .op_flags = OP_MODIFIES_SOMETHING,
3106 .op_name = "OP_CLOSE",
3107 .op_rsize_bop = nfsd4_status_stateid_rsize,
3108 .op_get_currentstateid = nfsd4_get_closestateid,
3109 .op_set_currentstateid = nfsd4_set_closestateid,
3112 .op_func = nfsd4_commit,
3113 .op_flags = OP_MODIFIES_SOMETHING,
3114 .op_name = "OP_COMMIT",
3115 .op_rsize_bop = nfsd4_commit_rsize,
3118 .op_func = nfsd4_create,
3119 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
3120 .op_name = "OP_CREATE",
3121 .op_rsize_bop = nfsd4_create_rsize,
3123 [OP_DELEGRETURN] = {
3124 .op_func = nfsd4_delegreturn,
3125 .op_flags = OP_MODIFIES_SOMETHING,
3126 .op_name = "OP_DELEGRETURN",
3127 .op_rsize_bop = nfsd4_only_status_rsize,
3128 .op_get_currentstateid = nfsd4_get_delegreturnstateid,
3131 .op_func = nfsd4_getattr,
3132 .op_flags = ALLOWED_ON_ABSENT_FS,
3133 .op_rsize_bop = nfsd4_getattr_rsize,
3134 .op_name = "OP_GETATTR",
3137 .op_func = nfsd4_getfh,
3138 .op_name = "OP_GETFH",
3139 .op_rsize_bop = nfsd4_getfh_rsize,
3142 .op_func = nfsd4_link,
3143 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
3145 .op_name = "OP_LINK",
3146 .op_rsize_bop = nfsd4_link_rsize,
3149 .op_func = nfsd4_lock,
3150 .op_flags = OP_MODIFIES_SOMETHING |
3151 OP_NONTRIVIAL_ERROR_ENCODE,
3152 .op_name = "OP_LOCK",
3153 .op_rsize_bop = nfsd4_lock_rsize,
3154 .op_set_currentstateid = nfsd4_set_lockstateid,
3157 .op_func = nfsd4_lockt,
3158 .op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
3159 .op_name = "OP_LOCKT",
3160 .op_rsize_bop = nfsd4_lock_rsize,
3163 .op_func = nfsd4_locku,
3164 .op_flags = OP_MODIFIES_SOMETHING,
3165 .op_name = "OP_LOCKU",
3166 .op_rsize_bop = nfsd4_status_stateid_rsize,
3167 .op_get_currentstateid = nfsd4_get_lockustateid,
3170 .op_func = nfsd4_lookup,
3171 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
3172 .op_name = "OP_LOOKUP",
3173 .op_rsize_bop = nfsd4_only_status_rsize,
3176 .op_func = nfsd4_lookupp,
3177 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
3178 .op_name = "OP_LOOKUPP",
3179 .op_rsize_bop = nfsd4_only_status_rsize,
3182 .op_func = nfsd4_nverify,
3183 .op_name = "OP_NVERIFY",
3184 .op_rsize_bop = nfsd4_only_status_rsize,
3187 .op_func = nfsd4_open,
3188 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
3189 .op_name = "OP_OPEN",
3190 .op_rsize_bop = nfsd4_open_rsize,
3191 .op_set_currentstateid = nfsd4_set_openstateid,
3193 [OP_OPEN_CONFIRM] = {
3194 .op_func = nfsd4_open_confirm,
3195 .op_flags = OP_MODIFIES_SOMETHING,
3196 .op_name = "OP_OPEN_CONFIRM",
3197 .op_rsize_bop = nfsd4_status_stateid_rsize,
3199 [OP_OPEN_DOWNGRADE] = {
3200 .op_func = nfsd4_open_downgrade,
3201 .op_flags = OP_MODIFIES_SOMETHING,
3202 .op_name = "OP_OPEN_DOWNGRADE",
3203 .op_rsize_bop = nfsd4_status_stateid_rsize,
3204 .op_get_currentstateid = nfsd4_get_opendowngradestateid,
3205 .op_set_currentstateid = nfsd4_set_opendowngradestateid,
3208 .op_func = nfsd4_putfh,
3209 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3210 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3211 .op_name = "OP_PUTFH",
3212 .op_rsize_bop = nfsd4_only_status_rsize,
3215 .op_func = nfsd4_putrootfh,
3216 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3217 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3218 .op_name = "OP_PUTPUBFH",
3219 .op_rsize_bop = nfsd4_only_status_rsize,
3222 .op_func = nfsd4_putrootfh,
3223 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3224 | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
3225 .op_name = "OP_PUTROOTFH",
3226 .op_rsize_bop = nfsd4_only_status_rsize,
3229 .op_func = nfsd4_read,
3230 .op_release = nfsd4_read_release,
3231 .op_name = "OP_READ",
3232 .op_rsize_bop = nfsd4_read_rsize,
3233 .op_get_currentstateid = nfsd4_get_readstateid,
3236 .op_func = nfsd4_readdir,
3237 .op_name = "OP_READDIR",
3238 .op_rsize_bop = nfsd4_readdir_rsize,
3241 .op_func = nfsd4_readlink,
3242 .op_name = "OP_READLINK",
3243 .op_rsize_bop = nfsd4_readlink_rsize,
3246 .op_func = nfsd4_remove,
3247 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3248 .op_name = "OP_REMOVE",
3249 .op_rsize_bop = nfsd4_remove_rsize,
3252 .op_func = nfsd4_rename,
3253 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3254 .op_name = "OP_RENAME",
3255 .op_rsize_bop = nfsd4_rename_rsize,
3258 .op_func = nfsd4_renew,
3259 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3260 | OP_MODIFIES_SOMETHING,
3261 .op_name = "OP_RENEW",
3262 .op_rsize_bop = nfsd4_only_status_rsize,
3266 .op_func = nfsd4_restorefh,
3267 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3268 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
3269 .op_name = "OP_RESTOREFH",
3270 .op_rsize_bop = nfsd4_only_status_rsize,
3273 .op_func = nfsd4_savefh,
3274 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
3275 .op_name = "OP_SAVEFH",
3276 .op_rsize_bop = nfsd4_only_status_rsize,
3279 .op_func = nfsd4_secinfo,
3280 .op_release = nfsd4_secinfo_release,
3281 .op_flags = OP_HANDLES_WRONGSEC,
3282 .op_name = "OP_SECINFO",
3283 .op_rsize_bop = nfsd4_secinfo_rsize,
3286 .op_func = nfsd4_setattr,
3287 .op_name = "OP_SETATTR",
3288 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
3289 | OP_NONTRIVIAL_ERROR_ENCODE,
3290 .op_rsize_bop = nfsd4_setattr_rsize,
3291 .op_get_currentstateid = nfsd4_get_setattrstateid,
3293 [OP_SETCLIENTID] = {
3294 .op_func = nfsd4_setclientid,
3295 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3296 | OP_MODIFIES_SOMETHING | OP_CACHEME
3297 | OP_NONTRIVIAL_ERROR_ENCODE,
3298 .op_name = "OP_SETCLIENTID",
3299 .op_rsize_bop = nfsd4_setclientid_rsize,
3301 [OP_SETCLIENTID_CONFIRM] = {
3302 .op_func = nfsd4_setclientid_confirm,
3303 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3304 | OP_MODIFIES_SOMETHING | OP_CACHEME,
3305 .op_name = "OP_SETCLIENTID_CONFIRM",
3306 .op_rsize_bop = nfsd4_only_status_rsize,
3309 .op_func = nfsd4_verify,
3310 .op_name = "OP_VERIFY",
3311 .op_rsize_bop = nfsd4_only_status_rsize,
3314 .op_func = nfsd4_write,
3315 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3316 .op_name = "OP_WRITE",
3317 .op_rsize_bop = nfsd4_write_rsize,
3318 .op_get_currentstateid = nfsd4_get_writestateid,
3320 [OP_RELEASE_LOCKOWNER] = {
3321 .op_func = nfsd4_release_lockowner,
3322 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
3323 | OP_MODIFIES_SOMETHING,
3324 .op_name = "OP_RELEASE_LOCKOWNER",
3325 .op_rsize_bop = nfsd4_only_status_rsize,
3328 /* NFSv4.1 operations */
3329 [OP_EXCHANGE_ID] = {
3330 .op_func = nfsd4_exchange_id,
3331 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3332 | OP_MODIFIES_SOMETHING,
3333 .op_name = "OP_EXCHANGE_ID",
3334 .op_rsize_bop = nfsd4_exchange_id_rsize,
3336 [OP_BACKCHANNEL_CTL] = {
3337 .op_func = nfsd4_backchannel_ctl,
3338 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3339 .op_name = "OP_BACKCHANNEL_CTL",
3340 .op_rsize_bop = nfsd4_only_status_rsize,
3342 [OP_BIND_CONN_TO_SESSION] = {
3343 .op_func = nfsd4_bind_conn_to_session,
3344 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3345 | OP_MODIFIES_SOMETHING,
3346 .op_name = "OP_BIND_CONN_TO_SESSION",
3347 .op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
3349 [OP_CREATE_SESSION] = {
3350 .op_func = nfsd4_create_session,
3351 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3352 | OP_MODIFIES_SOMETHING,
3353 .op_name = "OP_CREATE_SESSION",
3354 .op_rsize_bop = nfsd4_create_session_rsize,
3356 [OP_DESTROY_SESSION] = {
3357 .op_func = nfsd4_destroy_session,
3358 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3359 | OP_MODIFIES_SOMETHING,
3360 .op_name = "OP_DESTROY_SESSION",
3361 .op_rsize_bop = nfsd4_only_status_rsize,
3364 .op_func = nfsd4_sequence,
3365 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
3366 .op_name = "OP_SEQUENCE",
3367 .op_rsize_bop = nfsd4_sequence_rsize,
3369 [OP_DESTROY_CLIENTID] = {
3370 .op_func = nfsd4_destroy_clientid,
3371 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
3372 | OP_MODIFIES_SOMETHING,
3373 .op_name = "OP_DESTROY_CLIENTID",
3374 .op_rsize_bop = nfsd4_only_status_rsize,
3376 [OP_RECLAIM_COMPLETE] = {
3377 .op_func = nfsd4_reclaim_complete,
3378 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3379 .op_name = "OP_RECLAIM_COMPLETE",
3380 .op_rsize_bop = nfsd4_only_status_rsize,
3382 [OP_SECINFO_NO_NAME] = {
3383 .op_func = nfsd4_secinfo_no_name,
3384 .op_release = nfsd4_secinfo_no_name_release,
3385 .op_flags = OP_HANDLES_WRONGSEC,
3386 .op_name = "OP_SECINFO_NO_NAME",
3387 .op_rsize_bop = nfsd4_secinfo_rsize,
3389 [OP_TEST_STATEID] = {
3390 .op_func = nfsd4_test_stateid,
3391 .op_flags = ALLOWED_WITHOUT_FH,
3392 .op_name = "OP_TEST_STATEID",
3393 .op_rsize_bop = nfsd4_test_stateid_rsize,
3395 [OP_FREE_STATEID] = {
3396 .op_func = nfsd4_free_stateid,
3397 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
3398 .op_name = "OP_FREE_STATEID",
3399 .op_get_currentstateid = nfsd4_get_freestateid,
3400 .op_rsize_bop = nfsd4_only_status_rsize,
3402 #ifdef CONFIG_NFSD_PNFS
3403 [OP_GETDEVICEINFO] = {
3404 .op_func = nfsd4_getdeviceinfo,
3405 .op_release = nfsd4_getdeviceinfo_release,
3406 .op_flags = ALLOWED_WITHOUT_FH,
3407 .op_name = "OP_GETDEVICEINFO",
3408 .op_rsize_bop = nfsd4_getdeviceinfo_rsize,
3411 .op_func = nfsd4_layoutget,
3412 .op_release = nfsd4_layoutget_release,
3413 .op_flags = OP_MODIFIES_SOMETHING,
3414 .op_name = "OP_LAYOUTGET",
3415 .op_rsize_bop = nfsd4_layoutget_rsize,
3417 [OP_LAYOUTCOMMIT] = {
3418 .op_func = nfsd4_layoutcommit,
3419 .op_flags = OP_MODIFIES_SOMETHING,
3420 .op_name = "OP_LAYOUTCOMMIT",
3421 .op_rsize_bop = nfsd4_layoutcommit_rsize,
3423 [OP_LAYOUTRETURN] = {
3424 .op_func = nfsd4_layoutreturn,
3425 .op_flags = OP_MODIFIES_SOMETHING,
3426 .op_name = "OP_LAYOUTRETURN",
3427 .op_rsize_bop = nfsd4_layoutreturn_rsize,
3429 #endif /* CONFIG_NFSD_PNFS */
3431 /* NFSv4.2 operations */
3433 .op_func = nfsd4_allocate,
3434 .op_flags = OP_MODIFIES_SOMETHING,
3435 .op_name = "OP_ALLOCATE",
3436 .op_rsize_bop = nfsd4_only_status_rsize,
3439 .op_func = nfsd4_deallocate,
3440 .op_flags = OP_MODIFIES_SOMETHING,
3441 .op_name = "OP_DEALLOCATE",
3442 .op_rsize_bop = nfsd4_only_status_rsize,
3445 .op_func = nfsd4_clone,
3446 .op_flags = OP_MODIFIES_SOMETHING,
3447 .op_name = "OP_CLONE",
3448 .op_rsize_bop = nfsd4_only_status_rsize,
3451 .op_func = nfsd4_copy,
3452 .op_flags = OP_MODIFIES_SOMETHING,
3453 .op_name = "OP_COPY",
3454 .op_rsize_bop = nfsd4_copy_rsize,
3457 .op_func = nfsd4_read,
3458 .op_release = nfsd4_read_release,
3459 .op_name = "OP_READ_PLUS",
3460 .op_rsize_bop = nfsd4_read_plus_rsize,
3461 .op_get_currentstateid = nfsd4_get_readstateid,
3464 .op_func = nfsd4_seek,
3465 .op_name = "OP_SEEK",
3466 .op_rsize_bop = nfsd4_seek_rsize,
3468 [OP_OFFLOAD_STATUS] = {
3469 .op_func = nfsd4_offload_status,
3470 .op_name = "OP_OFFLOAD_STATUS",
3471 .op_rsize_bop = nfsd4_offload_status_rsize,
3473 [OP_OFFLOAD_CANCEL] = {
3474 .op_func = nfsd4_offload_cancel,
3475 .op_flags = OP_MODIFIES_SOMETHING,
3476 .op_name = "OP_OFFLOAD_CANCEL",
3477 .op_rsize_bop = nfsd4_only_status_rsize,
3479 [OP_COPY_NOTIFY] = {
3480 .op_func = nfsd4_copy_notify,
3481 .op_flags = OP_MODIFIES_SOMETHING,
3482 .op_name = "OP_COPY_NOTIFY",
3483 .op_rsize_bop = nfsd4_copy_notify_rsize,
3486 .op_func = nfsd4_getxattr,
3487 .op_name = "OP_GETXATTR",
3488 .op_rsize_bop = nfsd4_getxattr_rsize,
3491 .op_func = nfsd4_setxattr,
3492 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3493 .op_name = "OP_SETXATTR",
3494 .op_rsize_bop = nfsd4_setxattr_rsize,
3497 .op_func = nfsd4_listxattrs,
3498 .op_name = "OP_LISTXATTRS",
3499 .op_rsize_bop = nfsd4_listxattrs_rsize,
3501 [OP_REMOVEXATTR] = {
3502 .op_func = nfsd4_removexattr,
3503 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3504 .op_name = "OP_REMOVEXATTR",
3505 .op_rsize_bop = nfsd4_removexattr_rsize,
3510 * nfsd4_spo_must_allow - Determine if the compound op contains an
3511 * operation that is allowed to be sent with machine credentials
3513 * @rqstp: a pointer to the struct svc_rqst
3515 * Checks to see if the compound contains a spo_must_allow op
3516 * and confirms that it was sent with the proper machine creds.
3519 bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
3521 struct nfsd4_compoundres *resp = rqstp->rq_resp;
3522 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
3523 struct nfsd4_op *this;
3524 struct nfsd4_compound_state *cstate = &resp->cstate;
3525 struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
3528 if (!cstate->minorversion)
3531 if (cstate->spo_must_allowed)
3534 opiter = resp->opcnt;
3535 while (opiter < argp->opcnt) {
3536 this = &argp->ops[opiter++];
3537 if (test_bit(this->opnum, allow->u.longs) &&
3538 cstate->clp->cl_mach_cred &&
3539 nfsd4_mach_creds_match(cstate->clp, rqstp)) {
3540 cstate->spo_must_allowed = true;
3544 cstate->spo_must_allowed = false;
3548 int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
3550 if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
3551 return op_encode_hdr_size * sizeof(__be32);
3553 BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
3554 return OPDESC(op)->op_rsize_bop(rqstp, op);
3557 void warn_on_nonidempotent_op(struct nfsd4_op *op)
3559 if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
3560 pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
3561 op->opnum, nfsd4_op_name(op->opnum));
3566 static const char *nfsd4_op_name(unsigned opnum)
3568 if (opnum < ARRAY_SIZE(nfsd4_ops))
3569 return nfsd4_ops[opnum].op_name;
3570 return "unknown_operation";
3573 static const struct svc_procedure nfsd_procedures4[2] = {
3575 .pc_func = nfsd4_proc_null,
3576 .pc_decode = nfssvc_decode_voidarg,
3577 .pc_encode = nfssvc_encode_voidres,
3578 .pc_argsize = sizeof(struct nfsd_voidargs),
3579 .pc_ressize = sizeof(struct nfsd_voidres),
3580 .pc_cachetype = RC_NOCACHE,
3584 [NFSPROC4_COMPOUND] = {
3585 .pc_func = nfsd4_proc_compound,
3586 .pc_decode = nfs4svc_decode_compoundargs,
3587 .pc_encode = nfs4svc_encode_compoundres,
3588 .pc_argsize = sizeof(struct nfsd4_compoundargs),
3589 .pc_ressize = sizeof(struct nfsd4_compoundres),
3590 .pc_release = nfsd4_release_compoundargs,
3591 .pc_cachetype = RC_NOCACHE,
3592 .pc_xdrressize = NFSD_BUFSIZE/4,
3593 .pc_name = "COMPOUND",
3597 static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
3598 const struct svc_version nfsd_version4 = {
3601 .vs_proc = nfsd_procedures4,
3602 .vs_count = nfsd_count3,
3603 .vs_dispatch = nfsd_dispatch,
3604 .vs_xdrsize = NFS4_SVC_XDRSIZE,
3605 .vs_rpcb_optnl = true,
3606 .vs_need_cong_ctrl = true,