xref: /openbmc/linux/fs/nfsd/nfs4proc.c (revision 6308bc98e86ee8c7bbd56a39839a257a16c9378c)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  Server-side procedures for NFSv4.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Copyright (c) 2002 The Regents of the University of Michigan.
51da177e4SLinus Torvalds  *  All rights reserved.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *  Kendrick Smith <kmsmith@umich.edu>
81da177e4SLinus Torvalds  *  Andy Adamson   <andros@umich.edu>
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  *  Redistribution and use in source and binary forms, with or without
111da177e4SLinus Torvalds  *  modification, are permitted provided that the following conditions
121da177e4SLinus Torvalds  *  are met:
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  *  1. Redistributions of source code must retain the above copyright
151da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer.
161da177e4SLinus Torvalds  *  2. Redistributions in binary form must reproduce the above copyright
171da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer in the
181da177e4SLinus Torvalds  *     documentation and/or other materials provided with the distribution.
191da177e4SLinus Torvalds  *  3. Neither the name of the University nor the names of its
201da177e4SLinus Torvalds  *     contributors may be used to endorse or promote products derived
211da177e4SLinus Torvalds  *     from this software without specific prior written permission.
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
241da177e4SLinus Torvalds  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
251da177e4SLinus Torvalds  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
261da177e4SLinus Torvalds  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271da177e4SLinus Torvalds  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
281da177e4SLinus Torvalds  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
291da177e4SLinus Torvalds  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
301da177e4SLinus Torvalds  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
311da177e4SLinus Torvalds  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
321da177e4SLinus Torvalds  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
331da177e4SLinus Torvalds  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
341da177e4SLinus Torvalds  */
35880a3a53SJ. Bruce Fields #include <linux/fs_struct.h>
367e06b7f9SNeilBrown #include <linux/file.h>
37b0cb9085SAnna Schumaker #include <linux/falloc.h>
385a0e3ad6STejun Heo #include <linux/slab.h>
391da177e4SLinus Torvalds 
4058e7b33aSMi Jinlong #include "idmap.h"
419a74af21SBoaz Harrosh #include "cache.h"
429a74af21SBoaz Harrosh #include "xdr4.h"
430a3adadeSJ. Bruce Fields #include "vfs.h"
448b70484cSTigran Mkrtchyan #include "current_stateid.h"
453320fef1SStanislav Kinsbursky #include "netns.h"
464ac7249eSChristoph Hellwig #include "acl.h"
479cf514ccSChristoph Hellwig #include "pnfs.h"
4831ef83dcSChristoph Hellwig #include "trace.h"
491da177e4SLinus Torvalds 
5018032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
5118032ca0SDavid Quigley #include <linux/security.h>
5218032ca0SDavid Quigley 
5318032ca0SDavid Quigley static inline void
5418032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
5518032ca0SDavid Quigley {
562b0143b5SDavid Howells 	struct inode *inode = d_inode(resfh->fh_dentry);
5718032ca0SDavid Quigley 	int status;
5818032ca0SDavid Quigley 
595955102cSAl Viro 	inode_lock(inode);
6018032ca0SDavid Quigley 	status = security_inode_setsecctx(resfh->fh_dentry,
6118032ca0SDavid Quigley 		label->data, label->len);
625955102cSAl Viro 	inode_unlock(inode);
6318032ca0SDavid Quigley 
6418032ca0SDavid Quigley 	if (status)
6518032ca0SDavid Quigley 		/*
6618032ca0SDavid Quigley 		 * XXX: We should really fail the whole open, but we may
6718032ca0SDavid Quigley 		 * already have created a new file, so it may be too
6818032ca0SDavid Quigley 		 * late.  For now this seems the least of evils:
6918032ca0SDavid Quigley 		 */
7018032ca0SDavid Quigley 		bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
7118032ca0SDavid Quigley 
7218032ca0SDavid Quigley 	return;
7318032ca0SDavid Quigley }
7418032ca0SDavid Quigley #else
7518032ca0SDavid Quigley static inline void
7618032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
7718032ca0SDavid Quigley { }
7818032ca0SDavid Quigley #endif
7918032ca0SDavid Quigley 
801da177e4SLinus Torvalds #define NFSDDBG_FACILITY		NFSDDBG_PROC
811da177e4SLinus Torvalds 
823c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = {
833c8e0316SYu Zhiguo 	NFSD_WRITEABLE_ATTRS_WORD0,
843c8e0316SYu Zhiguo 	NFSD_WRITEABLE_ATTRS_WORD1,
853c8e0316SYu Zhiguo 	NFSD_WRITEABLE_ATTRS_WORD2
863c8e0316SYu Zhiguo };
873c8e0316SYu Zhiguo 
883c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = {
893c8e0316SYu Zhiguo 	NFSD_SUPPATTR_EXCLCREAT_WORD0,
903c8e0316SYu Zhiguo 	NFSD_SUPPATTR_EXCLCREAT_WORD1,
913c8e0316SYu Zhiguo 	NFSD_SUPPATTR_EXCLCREAT_WORD2
923c8e0316SYu Zhiguo };
933c8e0316SYu Zhiguo 
943c8e0316SYu Zhiguo static __be32
953c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
963c8e0316SYu Zhiguo 		   u32 *bmval, u32 *writable)
973c8e0316SYu Zhiguo {
983c8e0316SYu Zhiguo 	struct dentry *dentry = cstate->current_fh.fh_dentry;
9932ddd944SJ. Bruce Fields 	struct svc_export *exp = cstate->current_fh.fh_export;
1003c8e0316SYu Zhiguo 
101916d2d84SJ. Bruce Fields 	if (!nfsd_attrs_supported(cstate->minorversion, bmval))
1023c8e0316SYu Zhiguo 		return nfserr_attrnotsupp;
103916d2d84SJ. Bruce Fields 	if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
1043c8e0316SYu Zhiguo 		return nfserr_attrnotsupp;
10532ddd944SJ. Bruce Fields 	if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
10632ddd944SJ. Bruce Fields 			!(exp->ex_flags & NFSEXP_SECURITY_LABEL))
10732ddd944SJ. Bruce Fields 		return nfserr_attrnotsupp;
108916d2d84SJ. Bruce Fields 	if (writable && !bmval_is_subset(bmval, writable))
1093c8e0316SYu Zhiguo 		return nfserr_inval;
11047057abdSAndreas Gruenbacher 	if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
11147057abdSAndreas Gruenbacher 			(bmval[1] & FATTR4_WORD1_MODE))
11247057abdSAndreas Gruenbacher 		return nfserr_inval;
1133c8e0316SYu Zhiguo 	return nfs_ok;
1143c8e0316SYu Zhiguo }
1153c8e0316SYu Zhiguo 
1163c8e0316SYu Zhiguo static __be32
1173c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp,
1183c8e0316SYu Zhiguo 	struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
1193c8e0316SYu Zhiguo {
1203c8e0316SYu Zhiguo 	__be32 status = nfs_ok;
1213c8e0316SYu Zhiguo 
1223c8e0316SYu Zhiguo 	if (open->op_create == NFS4_OPEN_CREATE) {
1233c8e0316SYu Zhiguo 		if (open->op_createmode == NFS4_CREATE_UNCHECKED
1243c8e0316SYu Zhiguo 		    || open->op_createmode == NFS4_CREATE_GUARDED)
1253c8e0316SYu Zhiguo 			status = check_attr_support(rqstp, cstate,
1263c8e0316SYu Zhiguo 					open->op_bmval, nfsd_attrmask);
1273c8e0316SYu Zhiguo 		else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
1283c8e0316SYu Zhiguo 			status = check_attr_support(rqstp, cstate,
1293c8e0316SYu Zhiguo 					open->op_bmval, nfsd41_ex_attrmask);
1303c8e0316SYu Zhiguo 	}
1313c8e0316SYu Zhiguo 
1323c8e0316SYu Zhiguo 	return status;
1333c8e0316SYu Zhiguo }
1343c8e0316SYu Zhiguo 
1359208faf2SYu Zhiguo static int
1369208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open)
1379208faf2SYu Zhiguo {
1389208faf2SYu Zhiguo 	return open->op_create == NFS4_OPEN_CREATE
1399208faf2SYu Zhiguo 		&& (open->op_createmode == NFS4_CREATE_UNCHECKED
1409208faf2SYu Zhiguo 		    || open->op_createmode == NFS4_CREATE_GUARDED
1419208faf2SYu Zhiguo 		    || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
1429208faf2SYu Zhiguo }
1439208faf2SYu Zhiguo 
1449208faf2SYu Zhiguo /*
1459208faf2SYu Zhiguo  * if error occurs when setting the acl, just clear the acl bit
1469208faf2SYu Zhiguo  * in the returned attr bitmap.
1479208faf2SYu Zhiguo  */
1489208faf2SYu Zhiguo static void
1499208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
1509208faf2SYu Zhiguo 		struct nfs4_acl *acl, u32 *bmval)
1519208faf2SYu Zhiguo {
1529208faf2SYu Zhiguo 	__be32 status;
1539208faf2SYu Zhiguo 
1549208faf2SYu Zhiguo 	status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
1559208faf2SYu Zhiguo 	if (status)
1569208faf2SYu Zhiguo 		/*
1579208faf2SYu Zhiguo 		 * We should probably fail the whole open at this point,
1589208faf2SYu Zhiguo 		 * but we've already created the file, so it's too late;
1599208faf2SYu Zhiguo 		 * So this seems the least of evils:
1609208faf2SYu Zhiguo 		 */
1619208faf2SYu Zhiguo 		bmval[0] &= ~FATTR4_WORD0_ACL;
1629208faf2SYu Zhiguo }
1639208faf2SYu Zhiguo 
1641da177e4SLinus Torvalds static inline void
1651da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src)
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds 	fh_put(dst);
1681da177e4SLinus Torvalds 	dget(src->fh_dentry);
1691da177e4SLinus Torvalds 	if (src->fh_export)
170bf18f163SKinglong Mee 		exp_get(src->fh_export);
1711da177e4SLinus Torvalds 	*dst = *src;
1721da177e4SLinus Torvalds }
1731da177e4SLinus Torvalds 
174b37ad28bSAl Viro static __be32
175dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
1761da177e4SLinus Torvalds {
177b37ad28bSAl Viro 	__be32 status;
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds 	if (open->op_truncate &&
1801da177e4SLinus Torvalds 		!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
1811da177e4SLinus Torvalds 		return nfserr_inval;
1821da177e4SLinus Torvalds 
183a043226bSJ. Bruce Fields 	accmode |= NFSD_MAY_READ_IF_EXEC;
184a043226bSJ. Bruce Fields 
1851da177e4SLinus Torvalds 	if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
1868837abcaSMiklos Szeredi 		accmode |= NFSD_MAY_READ;
1879801d8a3SJ. Bruce Fields 	if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
1888837abcaSMiklos Szeredi 		accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
18957ecb34fSJ. Bruce Fields 	if (open->op_share_deny & NFS4_SHARE_DENY_READ)
1908837abcaSMiklos Szeredi 		accmode |= NFSD_MAY_WRITE;
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds 	status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds 	return status;
1951da177e4SLinus Torvalds }
1961da177e4SLinus Torvalds 
197aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
198aadab6c6SJ. Bruce Fields {
1992b0143b5SDavid Howells 	umode_t mode = d_inode(fh->fh_dentry)->i_mode;
200aadab6c6SJ. Bruce Fields 
201aadab6c6SJ. Bruce Fields 	if (S_ISREG(mode))
202aadab6c6SJ. Bruce Fields 		return nfs_ok;
203aadab6c6SJ. Bruce Fields 	if (S_ISDIR(mode))
204aadab6c6SJ. Bruce Fields 		return nfserr_isdir;
205aadab6c6SJ. Bruce Fields 	/*
206aadab6c6SJ. Bruce Fields 	 * Using err_symlink as our catch-all case may look odd; but
207aadab6c6SJ. Bruce Fields 	 * there's no other obvious error for this case in 4.0, and we
208aadab6c6SJ. Bruce Fields 	 * happen to know that it will cause the linux v4 client to do
209aadab6c6SJ. Bruce Fields 	 * the right thing on attempts to open something other than a
210aadab6c6SJ. Bruce Fields 	 * regular file.
211aadab6c6SJ. Bruce Fields 	 */
212aadab6c6SJ. Bruce Fields 	return nfserr_symlink;
213aadab6c6SJ. Bruce Fields }
214aadab6c6SJ. Bruce Fields 
215bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
2161da177e4SLinus Torvalds {
217bbc9c36cSJ. Bruce Fields 	if (nfsd4_has_session(cstate))
218bbc9c36cSJ. Bruce Fields 		return;
219bbc9c36cSJ. Bruce Fields 	fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
220bbc9c36cSJ. Bruce Fields 			&resfh->fh_handle);
221bbc9c36cSJ. Bruce Fields }
222bbc9c36cSJ. Bruce Fields 
223bbc9c36cSJ. Bruce Fields static __be32
224c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
225bbc9c36cSJ. Bruce Fields {
226bbc9c36cSJ. Bruce Fields 	struct svc_fh *current_fh = &cstate->current_fh;
2277007c90fSNeil Brown 	int accmode;
228b37ad28bSAl Viro 	__be32 status;
2291da177e4SLinus Torvalds 
230c0e6bee4SJ. Bruce Fields 	*resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
231c0e6bee4SJ. Bruce Fields 	if (!*resfh)
23259deeb9eSJ. Bruce Fields 		return nfserr_jukebox;
233c0e6bee4SJ. Bruce Fields 	fh_init(*resfh, NFS4_FHSIZE);
2341da177e4SLinus Torvalds 	open->op_truncate = 0;
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds 	if (open->op_create) {
23779fb54abSBenny Halevy 		/* FIXME: check session persistence and pnfs flags.
23879fb54abSBenny Halevy 		 * The nfsv4.1 spec requires the following semantics:
23979fb54abSBenny Halevy 		 *
24079fb54abSBenny Halevy 		 * Persistent   | pNFS   | Server REQUIRED | Client Allowed
24179fb54abSBenny Halevy 		 * Reply Cache  | server |                 |
24279fb54abSBenny Halevy 		 * -------------+--------+-----------------+--------------------
24379fb54abSBenny Halevy 		 * no           | no     | EXCLUSIVE4_1    | EXCLUSIVE4_1
24479fb54abSBenny Halevy 		 *              |        |                 | (SHOULD)
24579fb54abSBenny Halevy 		 *              |        | and EXCLUSIVE4  | or EXCLUSIVE4
24679fb54abSBenny Halevy 		 *              |        |                 | (SHOULD NOT)
24779fb54abSBenny Halevy 		 * no           | yes    | EXCLUSIVE4_1    | EXCLUSIVE4_1
24879fb54abSBenny Halevy 		 * yes          | no     | GUARDED4        | GUARDED4
24979fb54abSBenny Halevy 		 * yes          | yes    | GUARDED4        | GUARDED4
25079fb54abSBenny Halevy 		 */
25179fb54abSBenny Halevy 
2521da177e4SLinus Torvalds 		/*
2531da177e4SLinus Torvalds 		 * Note: create modes (UNCHECKED,GUARDED...) are the same
254ac6721a1SMi Jinlong 		 * in NFSv4 as in v3 except EXCLUSIVE4_1.
2551da177e4SLinus Torvalds 		 */
256880a3a53SJ. Bruce Fields 		current->fs->umask = open->op_umask;
257ac6721a1SMi Jinlong 		status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
2581da177e4SLinus Torvalds 					open->op_fname.len, &open->op_iattr,
259c0e6bee4SJ. Bruce Fields 					*resfh, open->op_createmode,
260749997e5SJeff Layton 					(u32 *)open->op_verf.data,
261856121b2SJ. Bruce Fields 					&open->op_truncate, &open->op_created);
262880a3a53SJ. Bruce Fields 		current->fs->umask = 0;
263749997e5SJeff Layton 
26418032ca0SDavid Quigley 		if (!status && open->op_label.len)
265c0e6bee4SJ. Bruce Fields 			nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
26618032ca0SDavid Quigley 
26799f88726SJ. Bruce Fields 		/*
268ead8fb8cSKinglong Mee 		 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
269ead8fb8cSKinglong Mee 		 * use the returned bitmask to indicate which attributes
270ead8fb8cSKinglong Mee 		 * we used to store the verifier:
271749997e5SJeff Layton 		 */
272ead8fb8cSKinglong Mee 		if (nfsd_create_is_exclusive(open->op_createmode) && status == 0)
273ead8fb8cSKinglong Mee 			open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
274749997e5SJeff Layton 						FATTR4_WORD1_TIME_MODIFY);
2754335723eSJ. Bruce Fields 	} else
2764335723eSJ. Bruce Fields 		/*
2774335723eSJ. Bruce Fields 		 * Note this may exit with the parent still locked.
2784335723eSJ. Bruce Fields 		 * We will hold the lock until nfsd4_open's final
2794335723eSJ. Bruce Fields 		 * lookup, to prevent renames or unlinks until we've had
2804335723eSJ. Bruce Fields 		 * a chance to an acquire a delegation if appropriate.
2814335723eSJ. Bruce Fields 		 */
2821da177e4SLinus Torvalds 		status = nfsd_lookup(rqstp, current_fh,
283c0e6bee4SJ. Bruce Fields 				     open->op_fname.data, open->op_fname.len, *resfh);
284aadab6c6SJ. Bruce Fields 	if (status)
285aadab6c6SJ. Bruce Fields 		goto out;
286c0e6bee4SJ. Bruce Fields 	status = nfsd_check_obj_isreg(*resfh);
287af85852dSJ. Bruce Fields 	if (status)
288af85852dSJ. Bruce Fields 		goto out;
2891da177e4SLinus Torvalds 
2909208faf2SYu Zhiguo 	if (is_create_with_attrs(open) && open->op_acl != NULL)
291c0e6bee4SJ. Bruce Fields 		do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
2929208faf2SYu Zhiguo 
293c0e6bee4SJ. Bruce Fields 	nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
2947007c90fSNeil Brown 	accmode = NFSD_MAY_NOP;
29589f6c336SJ. Bruce Fields 	if (open->op_created ||
29689f6c336SJ. Bruce Fields 			open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
2977007c90fSNeil Brown 		accmode |= NFSD_MAY_OWNER_OVERRIDE;
298c0e6bee4SJ. Bruce Fields 	status = do_open_permission(rqstp, *resfh, open, accmode);
29941fd1e42SJ. Bruce Fields 	set_change_info(&open->op_cinfo, current_fh);
300af85852dSJ. Bruce Fields out:
3011da177e4SLinus Torvalds 	return status;
3021da177e4SLinus Torvalds }
3031da177e4SLinus Torvalds 
304b37ad28bSAl Viro static __be32
305bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
3061da177e4SLinus Torvalds {
307bbc9c36cSJ. Bruce Fields 	struct svc_fh *current_fh = &cstate->current_fh;
308b37ad28bSAl Viro 	__be32 status;
3099f415eb2SJ. Bruce Fields 	int accmode = 0;
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds 	/* We don't know the target directory, and therefore can not
3121da177e4SLinus Torvalds 	* set the change info
3131da177e4SLinus Torvalds 	*/
3141da177e4SLinus Torvalds 
3151da177e4SLinus Torvalds 	memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
3161da177e4SLinus Torvalds 
317bbc9c36cSJ. Bruce Fields 	nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds 	open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
3201da177e4SLinus Torvalds 		(open->op_iattr.ia_size == 0);
3219f415eb2SJ. Bruce Fields 	/*
3229f415eb2SJ. Bruce Fields 	 * In the delegation case, the client is telling us about an
3239f415eb2SJ. Bruce Fields 	 * open that it *already* performed locally, some time ago.  We
3249f415eb2SJ. Bruce Fields 	 * should let it succeed now if possible.
3259f415eb2SJ. Bruce Fields 	 *
3269f415eb2SJ. Bruce Fields 	 * In the case of a CLAIM_FH open, on the other hand, the client
3279f415eb2SJ. Bruce Fields 	 * may be counting on us to enforce permissions (the Linux 4.1
3289f415eb2SJ. Bruce Fields 	 * client uses this for normal opens, for example).
3299f415eb2SJ. Bruce Fields 	 */
3309f415eb2SJ. Bruce Fields 	if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
3319f415eb2SJ. Bruce Fields 		accmode = NFSD_MAY_OWNER_OVERRIDE;
3321da177e4SLinus Torvalds 
3339f415eb2SJ. Bruce Fields 	status = do_open_permission(rqstp, current_fh, open, accmode);
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 	return status;
3361da177e4SLinus Torvalds }
3371da177e4SLinus Torvalds 
33860adfc50SAndy Adamson static void
33960adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session)
34060adfc50SAndy Adamson {
34160adfc50SAndy Adamson 	struct nfsd4_sessionid *sid =
34260adfc50SAndy Adamson 			(struct nfsd4_sessionid *)session->se_sessionid.data;
34360adfc50SAndy Adamson 
34460adfc50SAndy Adamson 	clid->cl_boot = sid->clientid.cl_boot;
34560adfc50SAndy Adamson 	clid->cl_id = sid->clientid.cl_id;
34660adfc50SAndy Adamson }
3471da177e4SLinus Torvalds 
3487191155bSJ.Bruce Fields static __be32
349ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
350eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
3511da177e4SLinus Torvalds {
352eb69853dSChristoph Hellwig 	struct nfsd4_open *open = &u->open;
353b37ad28bSAl Viro 	__be32 status;
354c0e6bee4SJ. Bruce Fields 	struct svc_fh *resfh = NULL;
3553320fef1SStanislav Kinsbursky 	struct net *net = SVC_NET(rqstp);
3563320fef1SStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
35703f318caSJ. Bruce Fields 	bool reclaim = false;
3586668958fSAndy Adamson 
359fe0750e5SJ. Bruce Fields 	dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
3601da177e4SLinus Torvalds 		(int)open->op_fname.len, open->op_fname.data,
361fe0750e5SJ. Bruce Fields 		open->op_openowner);
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds 	/* This check required by spec. */
3641da177e4SLinus Torvalds 	if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
3651da177e4SLinus Torvalds 		return nfserr_inval;
3661da177e4SLinus Torvalds 
367856121b2SJ. Bruce Fields 	open->op_created = 0;
368ab1350b2SMi Jinlong 	/*
369ab1350b2SMi Jinlong 	 * RFC5661 18.51.3
370ab1350b2SMi Jinlong 	 * Before RECLAIM_COMPLETE done, server should deny new lock
371ab1350b2SMi Jinlong 	 */
372ab1350b2SMi Jinlong 	if (nfsd4_has_session(cstate) &&
373a52d726bSJeff Layton 	    !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE,
374a52d726bSJeff Layton 		      &cstate->session->se_client->cl_flags) &&
375ab1350b2SMi Jinlong 	    open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
376ab1350b2SMi Jinlong 		return nfserr_grace;
377ab1350b2SMi Jinlong 
37860adfc50SAndy Adamson 	if (nfsd4_has_session(cstate))
37960adfc50SAndy Adamson 		copy_clientid(&open->op_clientid, cstate->session);
38060adfc50SAndy Adamson 
3811da177e4SLinus Torvalds 	/* check seqid for replay. set nfs4_owner */
3826cd22668SKinglong Mee 	status = nfsd4_process_open1(cstate, open, nn);
383a90b061cSAl Viro 	if (status == nfserr_replay_me) {
384fe0750e5SJ. Bruce Fields 		struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
385ca364317SJ.Bruce Fields 		fh_put(&cstate->current_fh);
386a4773c08SJ. Bruce Fields 		fh_copy_shallow(&cstate->current_fh.fh_handle,
387a4773c08SJ. Bruce Fields 				&rp->rp_openfh);
3888837abcaSMiklos Szeredi 		status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
3891da177e4SLinus Torvalds 		if (status)
3901da177e4SLinus Torvalds 			dprintk("nfsd4_open: replay failed"
3911da177e4SLinus Torvalds 				" restoring previous filehandle\n");
3921da177e4SLinus Torvalds 		else
393a90b061cSAl Viro 			status = nfserr_replay_me;
3941da177e4SLinus Torvalds 	}
3951da177e4SLinus Torvalds 	if (status)
3961da177e4SLinus Torvalds 		goto out;
3979d313b17SJ. Bruce Fields 	if (open->op_xdr_error) {
3989d313b17SJ. Bruce Fields 		status = open->op_xdr_error;
3999d313b17SJ. Bruce Fields 		goto out;
4009d313b17SJ. Bruce Fields 	}
401fb553c0fSJ. Bruce Fields 
4023c8e0316SYu Zhiguo 	status = nfsd4_check_open_attributes(rqstp, cstate, open);
4033c8e0316SYu Zhiguo 	if (status)
4043c8e0316SYu Zhiguo 		goto out;
4053c8e0316SYu Zhiguo 
406fb553c0fSJ. Bruce Fields 	/* Openowner is now set, so sequence id will get bumped.  Now we need
407fb553c0fSJ. Bruce Fields 	 * these checks before we do any creates: */
408cbd0d51aSJ. Bruce Fields 	status = nfserr_grace;
409c87fb4a3SJ. Bruce Fields 	if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
410cbd0d51aSJ. Bruce Fields 		goto out;
411cbd0d51aSJ. Bruce Fields 	status = nfserr_no_grace;
412c87fb4a3SJ. Bruce Fields 	if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
413cbd0d51aSJ. Bruce Fields 		goto out;
414fb553c0fSJ. Bruce Fields 
4151da177e4SLinus Torvalds 	switch (open->op_claim_type) {
4160dd3c192SNeilBrown 		case NFS4_OPEN_CLAIM_DELEGATE_CUR:
4171da177e4SLinus Torvalds 		case NFS4_OPEN_CLAIM_NULL:
418c0e6bee4SJ. Bruce Fields 			status = do_open_lookup(rqstp, cstate, open, &resfh);
4191da177e4SLinus Torvalds 			if (status)
4201da177e4SLinus Torvalds 				goto out;
4211da177e4SLinus Torvalds 			break;
4221da177e4SLinus Torvalds 		case NFS4_OPEN_CLAIM_PREVIOUS:
4233320fef1SStanislav Kinsbursky 			status = nfs4_check_open_reclaim(&open->op_clientid,
4240fe492dbSTrond Myklebust 							 cstate, nn);
4250cf99b91SMi Jinlong 			if (status)
4260cf99b91SMi Jinlong 				goto out;
427ba5378b6SJeff Layton 			open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
42803f318caSJ. Bruce Fields 			reclaim = true;
4298b289b2cSJ. Bruce Fields 		case NFS4_OPEN_CLAIM_FH:
4308b289b2cSJ. Bruce Fields 		case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
431bbc9c36cSJ. Bruce Fields 			status = do_open_fhandle(rqstp, cstate, open);
4321da177e4SLinus Torvalds 			if (status)
4331da177e4SLinus Torvalds 				goto out;
434c0e6bee4SJ. Bruce Fields 			resfh = &cstate->current_fh;
4351da177e4SLinus Torvalds 			break;
4368b289b2cSJ. Bruce Fields 		case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
4371da177e4SLinus Torvalds              	case NFS4_OPEN_CLAIM_DELEGATE_PREV:
4382fdada03SJ. Bruce Fields 			dprintk("NFSD: unsupported OPEN claim type %d\n",
4391da177e4SLinus Torvalds 				open->op_claim_type);
4401da177e4SLinus Torvalds 			status = nfserr_notsupp;
4411da177e4SLinus Torvalds 			goto out;
4421da177e4SLinus Torvalds 		default:
4432fdada03SJ. Bruce Fields 			dprintk("NFSD: Invalid OPEN claim type %d\n",
4441da177e4SLinus Torvalds 				open->op_claim_type);
4451da177e4SLinus Torvalds 			status = nfserr_inval;
4461da177e4SLinus Torvalds 			goto out;
4471da177e4SLinus Torvalds 	}
4481da177e4SLinus Torvalds 	/*
4491da177e4SLinus Torvalds 	 * nfsd4_process_open2() does the actual opening of the file.  If
4501da177e4SLinus Torvalds 	 * successful, it (1) truncates the file if open->op_truncate was
4511da177e4SLinus Torvalds 	 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
4521da177e4SLinus Torvalds 	 */
453c0e6bee4SJ. Bruce Fields 	status = nfsd4_process_open2(rqstp, resfh, open);
454b3fbfe0eSJeff Layton 	WARN(status && open->op_created,
455b3fbfe0eSJeff Layton 	     "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
456b3fbfe0eSJeff Layton 	     be32_to_cpu(status));
45703f318caSJ. Bruce Fields 	if (reclaim && !status)
45803f318caSJ. Bruce Fields 		nn->somebody_reclaimed = true;
4591da177e4SLinus Torvalds out:
460c0e6bee4SJ. Bruce Fields 	if (resfh && resfh != &cstate->current_fh) {
461c0e6bee4SJ. Bruce Fields 		fh_dup2(&cstate->current_fh, resfh);
462c0e6bee4SJ. Bruce Fields 		fh_put(resfh);
463c0e6bee4SJ. Bruce Fields 		kfree(resfh);
464c0e6bee4SJ. Bruce Fields 	}
46542297899SJeff Layton 	nfsd4_cleanup_open_state(cstate, open);
4669411b1d4SJ. Bruce Fields 	nfsd4_bump_seqid(cstate, status);
4671da177e4SLinus Torvalds 	return status;
4681da177e4SLinus Torvalds }
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds /*
4719d313b17SJ. Bruce Fields  * OPEN is the only seqid-mutating operation whose decoding can fail
4729d313b17SJ. Bruce Fields  * with a seqid-mutating error (specifically, decoding of user names in
4739d313b17SJ. Bruce Fields  * the attributes).  Therefore we have to do some processing to look up
4749d313b17SJ. Bruce Fields  * the stateowner so that we can bump the seqid.
4759d313b17SJ. Bruce Fields  */
4769d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
4779d313b17SJ. Bruce Fields {
478eb69853dSChristoph Hellwig 	struct nfsd4_open *open = &op->u.open;
4799d313b17SJ. Bruce Fields 
4809d313b17SJ. Bruce Fields 	if (!seqid_mutating_err(ntohl(op->status)))
4819d313b17SJ. Bruce Fields 		return op->status;
4829d313b17SJ. Bruce Fields 	if (nfsd4_has_session(cstate))
4839d313b17SJ. Bruce Fields 		return op->status;
4849d313b17SJ. Bruce Fields 	open->op_xdr_error = op->status;
485eb69853dSChristoph Hellwig 	return nfsd4_open(rqstp, cstate, &op->u);
4869d313b17SJ. Bruce Fields }
4879d313b17SJ. Bruce Fields 
4889d313b17SJ. Bruce Fields /*
4891da177e4SLinus Torvalds  * filehandle-manipulating ops.
4901da177e4SLinus Torvalds  */
4917191155bSJ.Bruce Fields static __be32
492b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
493eb69853dSChristoph Hellwig 	    union nfsd4_op_u *u)
4941da177e4SLinus Torvalds {
495eb69853dSChristoph Hellwig 	u->getfh = &cstate->current_fh;
4961da177e4SLinus Torvalds 	return nfs_ok;
4971da177e4SLinus Torvalds }
4981da177e4SLinus Torvalds 
4997191155bSJ.Bruce Fields static __be32
500ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
501eb69853dSChristoph Hellwig 	    union nfsd4_op_u *u)
5021da177e4SLinus Torvalds {
503eb69853dSChristoph Hellwig 	struct nfsd4_putfh *putfh = &u->putfh;
504eb69853dSChristoph Hellwig 
505ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
506ca364317SJ.Bruce Fields 	cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
507ca364317SJ.Bruce Fields 	memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
508ca364317SJ.Bruce Fields 	       putfh->pf_fhlen);
50968d93184SJ. Bruce Fields 	return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
5101da177e4SLinus Torvalds }
5111da177e4SLinus Torvalds 
5127191155bSJ.Bruce Fields static __be32
513b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
514eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
5151da177e4SLinus Torvalds {
516b37ad28bSAl Viro 	__be32 status;
5171da177e4SLinus Torvalds 
518ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
519df547efbSJ. Bruce Fields 	status = exp_pseudoroot(rqstp, &cstate->current_fh);
5201da177e4SLinus Torvalds 	return status;
5211da177e4SLinus Torvalds }
5221da177e4SLinus Torvalds 
5237191155bSJ.Bruce Fields static __be32
524b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
525eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
5261da177e4SLinus Torvalds {
527ca364317SJ.Bruce Fields 	if (!cstate->save_fh.fh_dentry)
5281da177e4SLinus Torvalds 		return nfserr_restorefh;
5291da177e4SLinus Torvalds 
530ca364317SJ.Bruce Fields 	fh_dup2(&cstate->current_fh, &cstate->save_fh);
53137c593c5STigran Mkrtchyan 	if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
53237c593c5STigran Mkrtchyan 		memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
53337c593c5STigran Mkrtchyan 		SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
53437c593c5STigran Mkrtchyan 	}
5351da177e4SLinus Torvalds 	return nfs_ok;
5361da177e4SLinus Torvalds }
5371da177e4SLinus Torvalds 
5387191155bSJ.Bruce Fields static __be32
539b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
540eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5411da177e4SLinus Torvalds {
542ca364317SJ.Bruce Fields 	fh_dup2(&cstate->save_fh, &cstate->current_fh);
54337c593c5STigran Mkrtchyan 	if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
54437c593c5STigran Mkrtchyan 		memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
54537c593c5STigran Mkrtchyan 		SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
54637c593c5STigran Mkrtchyan 	}
5471da177e4SLinus Torvalds 	return nfs_ok;
5481da177e4SLinus Torvalds }
5491da177e4SLinus Torvalds 
5501da177e4SLinus Torvalds /*
5511da177e4SLinus Torvalds  * misc nfsv4 ops
5521da177e4SLinus Torvalds  */
5537191155bSJ.Bruce Fields static __be32
554ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
555eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5561da177e4SLinus Torvalds {
557eb69853dSChristoph Hellwig 	struct nfsd4_access *access = &u->access;
558eb69853dSChristoph Hellwig 
5591da177e4SLinus Torvalds 	if (access->ac_req_access & ~NFS3_ACCESS_FULL)
5601da177e4SLinus Torvalds 		return nfserr_inval;
5611da177e4SLinus Torvalds 
5621da177e4SLinus Torvalds 	access->ac_resp_access = access->ac_req_access;
563ca364317SJ.Bruce Fields 	return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
564ca364317SJ.Bruce Fields 			   &access->ac_supported);
5651da177e4SLinus Torvalds }
5661da177e4SLinus Torvalds 
567b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
568ab4684d1SChuck Lever {
569ab4684d1SChuck Lever 	__be32 verf[2];
570b9c0ef85SStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
571ab4684d1SChuck Lever 
572f419992cSJeff Layton 	/*
573f419992cSJeff Layton 	 * This is opaque to client, so no need to byte-swap. Use
574256a89faSArnd Bergmann 	 * __force to keep sparse happy. y2038 time_t overflow is
575256a89faSArnd Bergmann 	 * irrelevant in this usage.
576f419992cSJeff Layton 	 */
577f419992cSJeff Layton 	verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
578256a89faSArnd Bergmann 	verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec;
579ab4684d1SChuck Lever 	memcpy(verifier->data, verf, sizeof(verifier->data));
580ab4684d1SChuck Lever }
581ab4684d1SChuck Lever 
5827191155bSJ.Bruce Fields static __be32
583ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
584eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5851da177e4SLinus Torvalds {
586eb69853dSChristoph Hellwig 	struct nfsd4_commit *commit = &u->commit;
587eb69853dSChristoph Hellwig 
588b9c0ef85SStanislav Kinsbursky 	gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp));
58975c096f7SJ. Bruce Fields 	return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
590ca364317SJ.Bruce Fields 			     commit->co_count);
5911da177e4SLinus Torvalds }
5921da177e4SLinus Torvalds 
593b37ad28bSAl Viro static __be32
594ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
595eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5961da177e4SLinus Torvalds {
597eb69853dSChristoph Hellwig 	struct nfsd4_create *create = &u->create;
5981da177e4SLinus Torvalds 	struct svc_fh resfh;
599b37ad28bSAl Viro 	__be32 status;
6001da177e4SLinus Torvalds 	dev_t rdev;
6011da177e4SLinus Torvalds 
6021da177e4SLinus Torvalds 	fh_init(&resfh, NFS4_FHSIZE);
6031da177e4SLinus Torvalds 
604fa08139dSJ. Bruce Fields 	status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
6051da177e4SLinus Torvalds 	if (status)
6061da177e4SLinus Torvalds 		return status;
6071da177e4SLinus Torvalds 
6083c8e0316SYu Zhiguo 	status = check_attr_support(rqstp, cstate, create->cr_bmval,
6093c8e0316SYu Zhiguo 				    nfsd_attrmask);
6103c8e0316SYu Zhiguo 	if (status)
6113c8e0316SYu Zhiguo 		return status;
6123c8e0316SYu Zhiguo 
613880a3a53SJ. Bruce Fields 	current->fs->umask = create->cr_umask;
6141da177e4SLinus Torvalds 	switch (create->cr_type) {
6151da177e4SLinus Torvalds 	case NF4LNK:
616ca364317SJ.Bruce Fields 		status = nfsd_symlink(rqstp, &cstate->current_fh,
617ca364317SJ.Bruce Fields 				      create->cr_name, create->cr_namelen,
6181e444f5bSKinglong Mee 				      create->cr_data, &resfh);
6191da177e4SLinus Torvalds 		break;
6201da177e4SLinus Torvalds 
6211da177e4SLinus Torvalds 	case NF4BLK:
622880a3a53SJ. Bruce Fields 		status = nfserr_inval;
6231da177e4SLinus Torvalds 		rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
6241da177e4SLinus Torvalds 		if (MAJOR(rdev) != create->cr_specdata1 ||
6251da177e4SLinus Torvalds 		    MINOR(rdev) != create->cr_specdata2)
626880a3a53SJ. Bruce Fields 			goto out_umask;
627ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
628ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
629ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFBLK, rdev, &resfh);
6301da177e4SLinus Torvalds 		break;
6311da177e4SLinus Torvalds 
6321da177e4SLinus Torvalds 	case NF4CHR:
633880a3a53SJ. Bruce Fields 		status = nfserr_inval;
6341da177e4SLinus Torvalds 		rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
6351da177e4SLinus Torvalds 		if (MAJOR(rdev) != create->cr_specdata1 ||
6361da177e4SLinus Torvalds 		    MINOR(rdev) != create->cr_specdata2)
637880a3a53SJ. Bruce Fields 			goto out_umask;
638ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
639ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
640ca364317SJ.Bruce Fields 				     &create->cr_iattr,S_IFCHR, rdev, &resfh);
6411da177e4SLinus Torvalds 		break;
6421da177e4SLinus Torvalds 
6431da177e4SLinus Torvalds 	case NF4SOCK:
644ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
645ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
646ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFSOCK, 0, &resfh);
6471da177e4SLinus Torvalds 		break;
6481da177e4SLinus Torvalds 
6491da177e4SLinus Torvalds 	case NF4FIFO:
650ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
651ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
652ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFIFO, 0, &resfh);
6531da177e4SLinus Torvalds 		break;
6541da177e4SLinus Torvalds 
6551da177e4SLinus Torvalds 	case NF4DIR:
6561da177e4SLinus Torvalds 		create->cr_iattr.ia_valid &= ~ATTR_SIZE;
657ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
658ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
659ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFDIR, 0, &resfh);
6601da177e4SLinus Torvalds 		break;
6611da177e4SLinus Torvalds 
6621da177e4SLinus Torvalds 	default:
6631da177e4SLinus Torvalds 		status = nfserr_badtype;
6641da177e4SLinus Torvalds 	}
6651da177e4SLinus Torvalds 
6669208faf2SYu Zhiguo 	if (status)
6679208faf2SYu Zhiguo 		goto out;
6689208faf2SYu Zhiguo 
66918032ca0SDavid Quigley 	if (create->cr_label.len)
67018032ca0SDavid Quigley 		nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
67118032ca0SDavid Quigley 
6729208faf2SYu Zhiguo 	if (create->cr_acl != NULL)
6739208faf2SYu Zhiguo 		do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
6749208faf2SYu Zhiguo 				create->cr_bmval);
6759208faf2SYu Zhiguo 
676ca364317SJ.Bruce Fields 	fh_unlock(&cstate->current_fh);
677ca364317SJ.Bruce Fields 	set_change_info(&create->cr_cinfo, &cstate->current_fh);
678ca364317SJ.Bruce Fields 	fh_dup2(&cstate->current_fh, &resfh);
6799208faf2SYu Zhiguo out:
6801da177e4SLinus Torvalds 	fh_put(&resfh);
681880a3a53SJ. Bruce Fields out_umask:
682880a3a53SJ. Bruce Fields 	current->fs->umask = 0;
6831da177e4SLinus Torvalds 	return status;
6841da177e4SLinus Torvalds }
6851da177e4SLinus Torvalds 
6867191155bSJ.Bruce Fields static __be32
687ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
688eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
6891da177e4SLinus Torvalds {
690eb69853dSChristoph Hellwig 	struct nfsd4_getattr *getattr = &u->getattr;
691b37ad28bSAl Viro 	__be32 status;
6921da177e4SLinus Torvalds 
6938837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
6941da177e4SLinus Torvalds 	if (status)
6951da177e4SLinus Torvalds 		return status;
6961da177e4SLinus Torvalds 
6971da177e4SLinus Torvalds 	if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
6981da177e4SLinus Torvalds 		return nfserr_inval;
6991da177e4SLinus Torvalds 
700916d2d84SJ. Bruce Fields 	getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
701916d2d84SJ. Bruce Fields 	getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
702916d2d84SJ. Bruce Fields 	getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
7031da177e4SLinus Torvalds 
704ca364317SJ.Bruce Fields 	getattr->ga_fhp = &cstate->current_fh;
7051da177e4SLinus Torvalds 	return nfs_ok;
7061da177e4SLinus Torvalds }
7071da177e4SLinus Torvalds 
7087191155bSJ.Bruce Fields static __be32
709ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
710eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
7111da177e4SLinus Torvalds {
712eb69853dSChristoph Hellwig 	struct nfsd4_link *link = &u->link;
71395424460SJ. Bruce Fields 	__be32 status;
7141da177e4SLinus Torvalds 
715ca364317SJ.Bruce Fields 	status = nfsd_link(rqstp, &cstate->current_fh,
716ca364317SJ.Bruce Fields 			   link->li_name, link->li_namelen, &cstate->save_fh);
7171da177e4SLinus Torvalds 	if (!status)
718ca364317SJ.Bruce Fields 		set_change_info(&link->li_cinfo, &cstate->current_fh);
7191da177e4SLinus Torvalds 	return status;
7201da177e4SLinus Torvalds }
7211da177e4SLinus Torvalds 
7220ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
7231da177e4SLinus Torvalds {
7241da177e4SLinus Torvalds 	struct svc_fh tmp_fh;
725b37ad28bSAl Viro 	__be32 ret;
7261da177e4SLinus Torvalds 
7271da177e4SLinus Torvalds 	fh_init(&tmp_fh, NFS4_FHSIZE);
728df547efbSJ. Bruce Fields 	ret = exp_pseudoroot(rqstp, &tmp_fh);
729df547efbSJ. Bruce Fields 	if (ret)
7301da177e4SLinus Torvalds 		return ret;
7310ff7ab46SJ. Bruce Fields 	if (tmp_fh.fh_dentry == fh->fh_dentry) {
7321da177e4SLinus Torvalds 		fh_put(&tmp_fh);
7331da177e4SLinus Torvalds 		return nfserr_noent;
7341da177e4SLinus Torvalds 	}
7351da177e4SLinus Torvalds 	fh_put(&tmp_fh);
7360ff7ab46SJ. Bruce Fields 	return nfsd_lookup(rqstp, fh, "..", 2, fh);
7370ff7ab46SJ. Bruce Fields }
7380ff7ab46SJ. Bruce Fields 
7390ff7ab46SJ. Bruce Fields static __be32
7400ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
741eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
7420ff7ab46SJ. Bruce Fields {
7430ff7ab46SJ. Bruce Fields 	return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
7441da177e4SLinus Torvalds }
7451da177e4SLinus Torvalds 
7467191155bSJ.Bruce Fields static __be32
747ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
748eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
7491da177e4SLinus Torvalds {
750ca364317SJ.Bruce Fields 	return nfsd_lookup(rqstp, &cstate->current_fh,
751eb69853dSChristoph Hellwig 			   u->lookup.lo_name, u->lookup.lo_len,
752ca364317SJ.Bruce Fields 			   &cstate->current_fh);
7531da177e4SLinus Torvalds }
7541da177e4SLinus Torvalds 
7557191155bSJ.Bruce Fields static __be32
756ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
757eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
7581da177e4SLinus Torvalds {
759eb69853dSChristoph Hellwig 	struct nfsd4_read *read = &u->read;
760b37ad28bSAl Viro 	__be32 status;
7611da177e4SLinus Torvalds 
7627e06b7f9SNeilBrown 	read->rd_filp = NULL;
7631da177e4SLinus Torvalds 	if (read->rd_offset >= OFFSET_MAX)
7641da177e4SLinus Torvalds 		return nfserr_inval;
7651da177e4SLinus Torvalds 
76687c5942eSChuck Lever 	trace_nfsd_read_start(rqstp, &cstate->current_fh,
76787c5942eSChuck Lever 			      read->rd_offset, read->rd_length);
76887c5942eSChuck Lever 
7699b3234b9SJ. Bruce Fields 	/*
7709b3234b9SJ. Bruce Fields 	 * If we do a zero copy read, then a client will see read data
7719b3234b9SJ. Bruce Fields 	 * that reflects the state of the file *after* performing the
7729b3234b9SJ. Bruce Fields 	 * following compound.
7739b3234b9SJ. Bruce Fields 	 *
7749b3234b9SJ. Bruce Fields 	 * To ensure proper ordering, we therefore turn off zero copy if
7759b3234b9SJ. Bruce Fields 	 * the client wants us to do more in this compound:
7769b3234b9SJ. Bruce Fields 	 */
7779b3234b9SJ. Bruce Fields 	if (!nfsd4_last_compound_op(rqstp))
778779fb0f3SJeff Layton 		clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
7799b3234b9SJ. Bruce Fields 
7801da177e4SLinus Torvalds 	/* check stateid */
781aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
782aa0d6aedSAnna Schumaker 					&read->rd_stateid, RD_STATE,
783aa0d6aedSAnna Schumaker 					&read->rd_filp, &read->rd_tmp_file);
784af90f707SChristoph Hellwig 	if (status) {
7851da177e4SLinus Torvalds 		dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
7861da177e4SLinus Torvalds 		goto out;
7871da177e4SLinus Torvalds 	}
7881da177e4SLinus Torvalds 	status = nfs_ok;
7891da177e4SLinus Torvalds out:
7901da177e4SLinus Torvalds 	read->rd_rqstp = rqstp;
791ca364317SJ.Bruce Fields 	read->rd_fhp = &cstate->current_fh;
7921da177e4SLinus Torvalds 	return status;
7931da177e4SLinus Torvalds }
7941da177e4SLinus Torvalds 
79534b1744cSJ. Bruce Fields 
79634b1744cSJ. Bruce Fields static void
79734b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u)
79834b1744cSJ. Bruce Fields {
79934b1744cSJ. Bruce Fields 	if (u->read.rd_filp)
80034b1744cSJ. Bruce Fields 		fput(u->read.rd_filp);
80187c5942eSChuck Lever 	trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
80287c5942eSChuck Lever 			     u->read.rd_offset, u->read.rd_length);
80334b1744cSJ. Bruce Fields }
80434b1744cSJ. Bruce Fields 
8057191155bSJ.Bruce Fields static __be32
806ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
807eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
8081da177e4SLinus Torvalds {
809eb69853dSChristoph Hellwig 	struct nfsd4_readdir *readdir = &u->readdir;
8101da177e4SLinus Torvalds 	u64 cookie = readdir->rd_cookie;
8111da177e4SLinus Torvalds 	static const nfs4_verifier zeroverf;
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds 	/* no need to check permission - this will be done in nfsd_readdir() */
8141da177e4SLinus Torvalds 
8151da177e4SLinus Torvalds 	if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
8161da177e4SLinus Torvalds 		return nfserr_inval;
8171da177e4SLinus Torvalds 
818916d2d84SJ. Bruce Fields 	readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
819916d2d84SJ. Bruce Fields 	readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
820916d2d84SJ. Bruce Fields 	readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
8211da177e4SLinus Torvalds 
822832023bfSBernd Schubert 	if ((cookie == 1) || (cookie == 2) ||
8231da177e4SLinus Torvalds 	    (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
8241da177e4SLinus Torvalds 		return nfserr_bad_cookie;
8251da177e4SLinus Torvalds 
8261da177e4SLinus Torvalds 	readdir->rd_rqstp = rqstp;
827ca364317SJ.Bruce Fields 	readdir->rd_fhp = &cstate->current_fh;
8281da177e4SLinus Torvalds 	return nfs_ok;
8291da177e4SLinus Torvalds }
8301da177e4SLinus Torvalds 
8317191155bSJ.Bruce Fields static __be32
832ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
833eb69853dSChristoph Hellwig 	       union nfsd4_op_u *u)
8341da177e4SLinus Torvalds {
835eb69853dSChristoph Hellwig 	u->readlink.rl_rqstp = rqstp;
836eb69853dSChristoph Hellwig 	u->readlink.rl_fhp = &cstate->current_fh;
8371da177e4SLinus Torvalds 	return nfs_ok;
8381da177e4SLinus Torvalds }
8391da177e4SLinus Torvalds 
8407191155bSJ.Bruce Fields static __be32
841ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
842eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
8431da177e4SLinus Torvalds {
844eb69853dSChristoph Hellwig 	struct nfsd4_remove *remove = &u->remove;
845b37ad28bSAl Viro 	__be32 status;
8461da177e4SLinus Torvalds 
847c87fb4a3SJ. Bruce Fields 	if (opens_in_grace(SVC_NET(rqstp)))
848c815afc7SNeilBrown 		return nfserr_grace;
849ca364317SJ.Bruce Fields 	status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
850ca364317SJ.Bruce Fields 			     remove->rm_name, remove->rm_namelen);
8511da177e4SLinus Torvalds 	if (!status) {
852ca364317SJ.Bruce Fields 		fh_unlock(&cstate->current_fh);
853ca364317SJ.Bruce Fields 		set_change_info(&remove->rm_cinfo, &cstate->current_fh);
8541da177e4SLinus Torvalds 	}
8551da177e4SLinus Torvalds 	return status;
8561da177e4SLinus Torvalds }
8571da177e4SLinus Torvalds 
8587191155bSJ.Bruce Fields static __be32
859ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
860eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
8611da177e4SLinus Torvalds {
862eb69853dSChristoph Hellwig 	struct nfsd4_rename *rename = &u->rename;
86395424460SJ. Bruce Fields 	__be32 status;
8641da177e4SLinus Torvalds 
865c87fb4a3SJ. Bruce Fields 	if (opens_in_grace(SVC_NET(rqstp)) &&
8665ccb0066SStanislav Kinsbursky 		!(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
867c815afc7SNeilBrown 		return nfserr_grace;
868ca364317SJ.Bruce Fields 	status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
869ca364317SJ.Bruce Fields 			     rename->rn_snamelen, &cstate->current_fh,
8701da177e4SLinus Torvalds 			     rename->rn_tname, rename->rn_tnamelen);
8712a6cf944SJ. Bruce Fields 	if (status)
8722a6cf944SJ. Bruce Fields 		return status;
873ca364317SJ.Bruce Fields 	set_change_info(&rename->rn_sinfo, &cstate->current_fh);
874ca364317SJ.Bruce Fields 	set_change_info(&rename->rn_tinfo, &cstate->save_fh);
8752a6cf944SJ. Bruce Fields 	return nfs_ok;
8761da177e4SLinus Torvalds }
8771da177e4SLinus Torvalds 
8787191155bSJ.Bruce Fields static __be32
879dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
880eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
881dcb488a3SAndy Adamson {
882eb69853dSChristoph Hellwig 	struct nfsd4_secinfo *secinfo = &u->secinfo;
883dcb488a3SAndy Adamson 	struct svc_export *exp;
884dcb488a3SAndy Adamson 	struct dentry *dentry;
885dcb488a3SAndy Adamson 	__be32 err;
886dcb488a3SAndy Adamson 
88729a78a3eSJ. Bruce Fields 	err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
88829a78a3eSJ. Bruce Fields 	if (err)
88929a78a3eSJ. Bruce Fields 		return err;
890dcb488a3SAndy Adamson 	err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
891dcb488a3SAndy Adamson 				    secinfo->si_name, secinfo->si_namelen,
892dcb488a3SAndy Adamson 				    &exp, &dentry);
893dcb488a3SAndy Adamson 	if (err)
894dcb488a3SAndy Adamson 		return err;
8952f6fc056SJ. Bruce Fields 	fh_unlock(&cstate->current_fh);
8962b0143b5SDavid Howells 	if (d_really_is_negative(dentry)) {
897dcb488a3SAndy Adamson 		exp_put(exp);
898dcb488a3SAndy Adamson 		err = nfserr_noent;
899dcb488a3SAndy Adamson 	} else
900dcb488a3SAndy Adamson 		secinfo->si_exp = exp;
901dcb488a3SAndy Adamson 	dput(dentry);
90256560b9aSJ. Bruce Fields 	if (cstate->minorversion)
90356560b9aSJ. Bruce Fields 		/* See rfc 5661 section 2.6.3.1.1.8 */
90456560b9aSJ. Bruce Fields 		fh_put(&cstate->current_fh);
905dcb488a3SAndy Adamson 	return err;
906dcb488a3SAndy Adamson }
907dcb488a3SAndy Adamson 
908dcb488a3SAndy Adamson static __be32
90904f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
910eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
91104f4ad16SJ. Bruce Fields {
91204f4ad16SJ. Bruce Fields 	__be32 err;
91304f4ad16SJ. Bruce Fields 
914eb69853dSChristoph Hellwig 	switch (u->secinfo_no_name.sin_style) {
91504f4ad16SJ. Bruce Fields 	case NFS4_SECINFO_STYLE4_CURRENT_FH:
91604f4ad16SJ. Bruce Fields 		break;
91704f4ad16SJ. Bruce Fields 	case NFS4_SECINFO_STYLE4_PARENT:
91804f4ad16SJ. Bruce Fields 		err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
91904f4ad16SJ. Bruce Fields 		if (err)
92004f4ad16SJ. Bruce Fields 			return err;
92104f4ad16SJ. Bruce Fields 		break;
92204f4ad16SJ. Bruce Fields 	default:
92304f4ad16SJ. Bruce Fields 		return nfserr_inval;
92404f4ad16SJ. Bruce Fields 	}
925bf18f163SKinglong Mee 
926eb69853dSChristoph Hellwig 	u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
92704f4ad16SJ. Bruce Fields 	fh_put(&cstate->current_fh);
92804f4ad16SJ. Bruce Fields 	return nfs_ok;
92904f4ad16SJ. Bruce Fields }
93004f4ad16SJ. Bruce Fields 
93134b1744cSJ. Bruce Fields static void
93234b1744cSJ. Bruce Fields nfsd4_secinfo_release(union nfsd4_op_u *u)
93334b1744cSJ. Bruce Fields {
93434b1744cSJ. Bruce Fields 	if (u->secinfo.si_exp)
93534b1744cSJ. Bruce Fields 		exp_put(u->secinfo.si_exp);
93634b1744cSJ. Bruce Fields }
93734b1744cSJ. Bruce Fields 
938ec572b9eSEryu Guan static void
939ec572b9eSEryu Guan nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
940ec572b9eSEryu Guan {
941ec572b9eSEryu Guan 	if (u->secinfo_no_name.sin_exp)
942ec572b9eSEryu Guan 		exp_put(u->secinfo_no_name.sin_exp);
943ec572b9eSEryu Guan }
944ec572b9eSEryu Guan 
94504f4ad16SJ. Bruce Fields static __be32
946ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
947eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
9481da177e4SLinus Torvalds {
949eb69853dSChristoph Hellwig 	struct nfsd4_setattr *setattr = &u->setattr;
950b37ad28bSAl Viro 	__be32 status = nfs_ok;
95196f6f985SAl Viro 	int err;
9521da177e4SLinus Torvalds 
9531da177e4SLinus Torvalds 	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
954af90f707SChristoph Hellwig 		status = nfs4_preprocess_stateid_op(rqstp, cstate,
955aa0d6aedSAnna Schumaker 				&cstate->current_fh, &setattr->sa_stateid,
956aa0d6aedSAnna Schumaker 				WR_STATE, NULL, NULL);
957375c5547SJ. Bruce Fields 		if (status) {
9583e3b4800SGreg Banks 			dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
959375c5547SJ. Bruce Fields 			return status;
960375c5547SJ. Bruce Fields 		}
9611da177e4SLinus Torvalds 	}
96296f6f985SAl Viro 	err = fh_want_write(&cstate->current_fh);
96396f6f985SAl Viro 	if (err)
96496f6f985SAl Viro 		return nfserrno(err);
9651da177e4SLinus Torvalds 	status = nfs_ok;
9663c8e0316SYu Zhiguo 
9673c8e0316SYu Zhiguo 	status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
9683c8e0316SYu Zhiguo 				    nfsd_attrmask);
9693c8e0316SYu Zhiguo 	if (status)
9703c8e0316SYu Zhiguo 		goto out;
9713c8e0316SYu Zhiguo 
9721da177e4SLinus Torvalds 	if (setattr->sa_acl != NULL)
973ca364317SJ.Bruce Fields 		status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
974ca364317SJ.Bruce Fields 					    setattr->sa_acl);
9751da177e4SLinus Torvalds 	if (status)
97618f335afSDave Hansen 		goto out;
97718032ca0SDavid Quigley 	if (setattr->sa_label.len)
97818032ca0SDavid Quigley 		status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
97918032ca0SDavid Quigley 				&setattr->sa_label);
98018032ca0SDavid Quigley 	if (status)
98118032ca0SDavid Quigley 		goto out;
982ca364317SJ.Bruce Fields 	status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
9831da177e4SLinus Torvalds 				0, (time_t)0);
98418f335afSDave Hansen out:
985bad0dcffSAl Viro 	fh_drop_write(&cstate->current_fh);
9861da177e4SLinus Torvalds 	return status;
9871da177e4SLinus Torvalds }
9881da177e4SLinus Torvalds 
9897191155bSJ.Bruce Fields static __be32
990ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
991eb69853dSChristoph Hellwig 	    union nfsd4_op_u *u)
9921da177e4SLinus Torvalds {
993eb69853dSChristoph Hellwig 	struct nfsd4_write *write = &u->write;
9941da177e4SLinus Torvalds 	stateid_t *stateid = &write->wr_stateid;
9951da177e4SLinus Torvalds 	struct file *filp = NULL;
996b37ad28bSAl Viro 	__be32 status = nfs_ok;
99731dec253SDavid Shaw 	unsigned long cnt;
998ffe1137bSJ. Bruce Fields 	int nvecs;
9991da177e4SLinus Torvalds 
10001da177e4SLinus Torvalds 	if (write->wr_offset >= OFFSET_MAX)
10011da177e4SLinus Torvalds 		return nfserr_inval;
10021da177e4SLinus Torvalds 
1003d890be15SChuck Lever 	cnt = write->wr_buflen;
1004d890be15SChuck Lever 	trace_nfsd_write_start(rqstp, &cstate->current_fh,
1005d890be15SChuck Lever 			       write->wr_offset, cnt);
1006aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1007aa0d6aedSAnna Schumaker 						stateid, WR_STATE, &filp, NULL);
1008375c5547SJ. Bruce Fields 	if (status) {
1009375c5547SJ. Bruce Fields 		dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1010375c5547SJ. Bruce Fields 		return status;
1011375c5547SJ. Bruce Fields 	}
1012375c5547SJ. Bruce Fields 
10131da177e4SLinus Torvalds 	write->wr_how_written = write->wr_stable_how;
1014b9c0ef85SStanislav Kinsbursky 	gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp));
10151da177e4SLinus Torvalds 
10163fd9557aSChuck Lever 	nvecs = svc_fill_write_vector(rqstp, write->wr_pagelist,
10173fd9557aSChuck Lever 				      &write->wr_head, write->wr_buflen);
10183fd9557aSChuck Lever 	if (!nvecs)
10193fd9557aSChuck Lever 		return nfserr_io;
1020ffe1137bSJ. Bruce Fields 	WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1021ffe1137bSJ. Bruce Fields 
1022af90f707SChristoph Hellwig 	status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp,
1023af90f707SChristoph Hellwig 				write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
102454bbb7d2SKinglong Mee 				write->wr_how_written);
10257e06b7f9SNeilBrown 	fput(filp);
10261da177e4SLinus Torvalds 
102731dec253SDavid Shaw 	write->wr_bytes_written = cnt;
1028d890be15SChuck Lever 	trace_nfsd_write_done(rqstp, &cstate->current_fh,
1029d890be15SChuck Lever 			      write->wr_offset, cnt);
10301da177e4SLinus Torvalds 	return status;
10311da177e4SLinus Torvalds }
10321da177e4SLinus Torvalds 
103324bab491SAnna Schumaker static __be32
103429ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
103529ae7f9dSAnna Schumaker 		  stateid_t *src_stateid, struct file **src,
103629ae7f9dSAnna Schumaker 		  stateid_t *dst_stateid, struct file **dst)
1037ffa0160aSChristoph Hellwig {
1038ffa0160aSChristoph Hellwig 	__be32 status;
1039ffa0160aSChristoph Hellwig 
1040ffa0160aSChristoph Hellwig 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
104129ae7f9dSAnna Schumaker 					    src_stateid, RD_STATE, src, NULL);
1042ffa0160aSChristoph Hellwig 	if (status) {
1043ffa0160aSChristoph Hellwig 		dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1044ffa0160aSChristoph Hellwig 		goto out;
1045ffa0160aSChristoph Hellwig 	}
1046ffa0160aSChristoph Hellwig 
1047ffa0160aSChristoph Hellwig 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
104829ae7f9dSAnna Schumaker 					    dst_stateid, WR_STATE, dst, NULL);
1049ffa0160aSChristoph Hellwig 	if (status) {
1050ffa0160aSChristoph Hellwig 		dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1051ffa0160aSChristoph Hellwig 		goto out_put_src;
1052ffa0160aSChristoph Hellwig 	}
1053ffa0160aSChristoph Hellwig 
1054ffa0160aSChristoph Hellwig 	/* fix up for NFS-specific error code */
105529ae7f9dSAnna Schumaker 	if (!S_ISREG(file_inode(*src)->i_mode) ||
105629ae7f9dSAnna Schumaker 	    !S_ISREG(file_inode(*dst)->i_mode)) {
1057ffa0160aSChristoph Hellwig 		status = nfserr_wrong_type;
1058ffa0160aSChristoph Hellwig 		goto out_put_dst;
1059ffa0160aSChristoph Hellwig 	}
1060ffa0160aSChristoph Hellwig 
106129ae7f9dSAnna Schumaker out:
106229ae7f9dSAnna Schumaker 	return status;
106329ae7f9dSAnna Schumaker out_put_dst:
106429ae7f9dSAnna Schumaker 	fput(*dst);
106529ae7f9dSAnna Schumaker out_put_src:
106629ae7f9dSAnna Schumaker 	fput(*src);
106729ae7f9dSAnna Schumaker 	goto out;
106829ae7f9dSAnna Schumaker }
106929ae7f9dSAnna Schumaker 
107029ae7f9dSAnna Schumaker static __be32
107129ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1072eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
107329ae7f9dSAnna Schumaker {
1074eb69853dSChristoph Hellwig 	struct nfsd4_clone *clone = &u->clone;
107529ae7f9dSAnna Schumaker 	struct file *src, *dst;
107629ae7f9dSAnna Schumaker 	__be32 status;
107729ae7f9dSAnna Schumaker 
107829ae7f9dSAnna Schumaker 	status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
107929ae7f9dSAnna Schumaker 				   &clone->cl_dst_stateid, &dst);
108029ae7f9dSAnna Schumaker 	if (status)
108129ae7f9dSAnna Schumaker 		goto out;
108229ae7f9dSAnna Schumaker 
1083ffa0160aSChristoph Hellwig 	status = nfsd4_clone_file_range(src, clone->cl_src_pos,
1084ffa0160aSChristoph Hellwig 			dst, clone->cl_dst_pos, clone->cl_count);
1085ffa0160aSChristoph Hellwig 
1086ffa0160aSChristoph Hellwig 	fput(dst);
1087ffa0160aSChristoph Hellwig 	fput(src);
1088ffa0160aSChristoph Hellwig out:
1089ffa0160aSChristoph Hellwig 	return status;
1090ffa0160aSChristoph Hellwig }
1091ffa0160aSChristoph Hellwig 
1092ffa0160aSChristoph Hellwig static __be32
109329ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1094eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
109529ae7f9dSAnna Schumaker {
1096eb69853dSChristoph Hellwig 	struct nfsd4_copy *copy = &u->copy;
109729ae7f9dSAnna Schumaker 	struct file *src, *dst;
109829ae7f9dSAnna Schumaker 	__be32 status;
109929ae7f9dSAnna Schumaker 	ssize_t bytes;
110029ae7f9dSAnna Schumaker 
110129ae7f9dSAnna Schumaker 	status = nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid, &src,
110229ae7f9dSAnna Schumaker 				   &copy->cp_dst_stateid, &dst);
110329ae7f9dSAnna Schumaker 	if (status)
110429ae7f9dSAnna Schumaker 		goto out;
110529ae7f9dSAnna Schumaker 
110629ae7f9dSAnna Schumaker 	bytes = nfsd_copy_file_range(src, copy->cp_src_pos,
110729ae7f9dSAnna Schumaker 			dst, copy->cp_dst_pos, copy->cp_count);
110829ae7f9dSAnna Schumaker 
110929ae7f9dSAnna Schumaker 	if (bytes < 0)
111029ae7f9dSAnna Schumaker 		status = nfserrno(bytes);
111129ae7f9dSAnna Schumaker 	else {
111229ae7f9dSAnna Schumaker 		copy->cp_res.wr_bytes_written = bytes;
111329ae7f9dSAnna Schumaker 		copy->cp_res.wr_stable_how = NFS_UNSTABLE;
111429ae7f9dSAnna Schumaker 		copy->cp_synchronous = 1;
111529ae7f9dSAnna Schumaker 		gen_boot_verifier(&copy->cp_res.wr_verifier, SVC_NET(rqstp));
111629ae7f9dSAnna Schumaker 		status = nfs_ok;
111729ae7f9dSAnna Schumaker 	}
111829ae7f9dSAnna Schumaker 
111929ae7f9dSAnna Schumaker 	fput(src);
112029ae7f9dSAnna Schumaker 	fput(dst);
112129ae7f9dSAnna Schumaker out:
112229ae7f9dSAnna Schumaker 	return status;
112329ae7f9dSAnna Schumaker }
112429ae7f9dSAnna Schumaker 
112529ae7f9dSAnna Schumaker static __be32
112695d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
112795d871f0SAnna Schumaker 		struct nfsd4_fallocate *fallocate, int flags)
112895d871f0SAnna Schumaker {
112995d871f0SAnna Schumaker 	__be32 status = nfserr_notsupp;
113095d871f0SAnna Schumaker 	struct file *file;
113195d871f0SAnna Schumaker 
1132aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
113395d871f0SAnna Schumaker 					    &fallocate->falloc_stateid,
1134af90f707SChristoph Hellwig 					    WR_STATE, &file, NULL);
113595d871f0SAnna Schumaker 	if (status != nfs_ok) {
113695d871f0SAnna Schumaker 		dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
113795d871f0SAnna Schumaker 		return status;
113895d871f0SAnna Schumaker 	}
113995d871f0SAnna Schumaker 
114095d871f0SAnna Schumaker 	status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
114195d871f0SAnna Schumaker 				     fallocate->falloc_offset,
114295d871f0SAnna Schumaker 				     fallocate->falloc_length,
114395d871f0SAnna Schumaker 				     flags);
114495d871f0SAnna Schumaker 	fput(file);
114595d871f0SAnna Schumaker 	return status;
114695d871f0SAnna Schumaker }
1147*6308bc98SOlga Kornievskaia static __be32
1148*6308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp,
1149*6308bc98SOlga Kornievskaia 		     struct nfsd4_compound_state *cstate,
1150*6308bc98SOlga Kornievskaia 		     union nfsd4_op_u *u)
1151*6308bc98SOlga Kornievskaia {
1152*6308bc98SOlga Kornievskaia 	return nfserr_notsupp;
1153*6308bc98SOlga Kornievskaia }
115495d871f0SAnna Schumaker 
115595d871f0SAnna Schumaker static __be32
115695d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1157eb69853dSChristoph Hellwig 	       union nfsd4_op_u *u)
115895d871f0SAnna Schumaker {
1159eb69853dSChristoph Hellwig 	return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
116095d871f0SAnna Schumaker }
116195d871f0SAnna Schumaker 
116295d871f0SAnna Schumaker static __be32
1163b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1164eb69853dSChristoph Hellwig 		 union nfsd4_op_u *u)
1165b0cb9085SAnna Schumaker {
1166eb69853dSChristoph Hellwig 	return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
1167b0cb9085SAnna Schumaker 			       FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
1168b0cb9085SAnna Schumaker }
1169b0cb9085SAnna Schumaker 
1170b0cb9085SAnna Schumaker static __be32
117124bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1172eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
117324bab491SAnna Schumaker {
1174eb69853dSChristoph Hellwig 	struct nfsd4_seek *seek = &u->seek;
117524bab491SAnna Schumaker 	int whence;
117624bab491SAnna Schumaker 	__be32 status;
117724bab491SAnna Schumaker 	struct file *file;
117824bab491SAnna Schumaker 
1179aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
118024bab491SAnna Schumaker 					    &seek->seek_stateid,
1181af90f707SChristoph Hellwig 					    RD_STATE, &file, NULL);
118224bab491SAnna Schumaker 	if (status) {
118324bab491SAnna Schumaker 		dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
118424bab491SAnna Schumaker 		return status;
118524bab491SAnna Schumaker 	}
118624bab491SAnna Schumaker 
118724bab491SAnna Schumaker 	switch (seek->seek_whence) {
118824bab491SAnna Schumaker 	case NFS4_CONTENT_DATA:
118924bab491SAnna Schumaker 		whence = SEEK_DATA;
119024bab491SAnna Schumaker 		break;
119124bab491SAnna Schumaker 	case NFS4_CONTENT_HOLE:
119224bab491SAnna Schumaker 		whence = SEEK_HOLE;
119324bab491SAnna Schumaker 		break;
119424bab491SAnna Schumaker 	default:
119524bab491SAnna Schumaker 		status = nfserr_union_notsupp;
119624bab491SAnna Schumaker 		goto out;
119724bab491SAnna Schumaker 	}
119824bab491SAnna Schumaker 
119924bab491SAnna Schumaker 	/*
120024bab491SAnna Schumaker 	 * Note:  This call does change file->f_pos, but nothing in NFSD
120124bab491SAnna Schumaker 	 *        should ever file->f_pos.
120224bab491SAnna Schumaker 	 */
120324bab491SAnna Schumaker 	seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
120424bab491SAnna Schumaker 	if (seek->seek_pos < 0)
120524bab491SAnna Schumaker 		status = nfserrno(seek->seek_pos);
120624bab491SAnna Schumaker 	else if (seek->seek_pos >= i_size_read(file_inode(file)))
120724bab491SAnna Schumaker 		seek->seek_eof = true;
120824bab491SAnna Schumaker 
120924bab491SAnna Schumaker out:
121024bab491SAnna Schumaker 	fput(file);
121124bab491SAnna Schumaker 	return status;
121224bab491SAnna Schumaker }
121324bab491SAnna Schumaker 
12141da177e4SLinus Torvalds /* This routine never returns NFS_OK!  If there are no other errors, it
12151da177e4SLinus Torvalds  * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
12161da177e4SLinus Torvalds  * attributes matched.  VERIFY is implemented by mapping NFSERR_SAME
12171da177e4SLinus Torvalds  * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
12181da177e4SLinus Torvalds  */
1219b37ad28bSAl Viro static __be32
1220c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1221ca364317SJ.Bruce Fields 	     struct nfsd4_verify *verify)
12221da177e4SLinus Torvalds {
12232ebbc012SAl Viro 	__be32 *buf, *p;
12241da177e4SLinus Torvalds 	int count;
1225b37ad28bSAl Viro 	__be32 status;
12261da177e4SLinus Torvalds 
12278837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
12281da177e4SLinus Torvalds 	if (status)
12291da177e4SLinus Torvalds 		return status;
12301da177e4SLinus Torvalds 
12313c8e0316SYu Zhiguo 	status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
12323c8e0316SYu Zhiguo 	if (status)
12333c8e0316SYu Zhiguo 		return status;
12343c8e0316SYu Zhiguo 
12351da177e4SLinus Torvalds 	if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
12361da177e4SLinus Torvalds 	    || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
12371da177e4SLinus Torvalds 		return nfserr_inval;
12381da177e4SLinus Torvalds 	if (verify->ve_attrlen & 3)
12391da177e4SLinus Torvalds 		return nfserr_inval;
12401da177e4SLinus Torvalds 
12411da177e4SLinus Torvalds 	/* count in words:
12421da177e4SLinus Torvalds 	 *   bitmap_len(1) + bitmap(2) + attr_len(1) = 4
12431da177e4SLinus Torvalds 	 */
12441da177e4SLinus Torvalds 	count = 4 + (verify->ve_attrlen >> 2);
12451da177e4SLinus Torvalds 	buf = kmalloc(count << 2, GFP_KERNEL);
12461da177e4SLinus Torvalds 	if (!buf)
12473e772463SJ. Bruce Fields 		return nfserr_jukebox;
12481da177e4SLinus Torvalds 
124984822d0bSJ. Bruce Fields 	p = buf;
1250d5184658SJ. Bruce Fields 	status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
1251ca364317SJ.Bruce Fields 				    cstate->current_fh.fh_export,
1252d5184658SJ. Bruce Fields 				    cstate->current_fh.fh_dentry,
1253d5184658SJ. Bruce Fields 				    verify->ve_bmval,
1254406a7ea9SFrank Filz 				    rqstp, 0);
125541ae6e71SJ. Bruce Fields 	/*
125641ae6e71SJ. Bruce Fields 	 * If nfsd4_encode_fattr() ran out of space, assume that's because
125741ae6e71SJ. Bruce Fields 	 * the attributes are longer (hence different) than those given:
125841ae6e71SJ. Bruce Fields 	 */
125984822d0bSJ. Bruce Fields 	if (status == nfserr_resource)
12601da177e4SLinus Torvalds 		status = nfserr_not_same;
12611da177e4SLinus Torvalds 	if (status)
12621da177e4SLinus Torvalds 		goto out_kfree;
12631da177e4SLinus Torvalds 
126495ec28cdSBenny Halevy 	/* skip bitmap */
126595ec28cdSBenny Halevy 	p = buf + 1 + ntohl(buf[0]);
12661da177e4SLinus Torvalds 	status = nfserr_not_same;
12671da177e4SLinus Torvalds 	if (ntohl(*p++) != verify->ve_attrlen)
12681da177e4SLinus Torvalds 		goto out_kfree;
12691da177e4SLinus Torvalds 	if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
12701da177e4SLinus Torvalds 		status = nfserr_same;
12711da177e4SLinus Torvalds 
12721da177e4SLinus Torvalds out_kfree:
12731da177e4SLinus Torvalds 	kfree(buf);
12741da177e4SLinus Torvalds 	return status;
12751da177e4SLinus Torvalds }
12761da177e4SLinus Torvalds 
1277c954e2a5SJ.Bruce Fields static __be32
1278c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1279eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
1280c954e2a5SJ.Bruce Fields {
1281c954e2a5SJ.Bruce Fields 	__be32 status;
1282c954e2a5SJ.Bruce Fields 
1283eb69853dSChristoph Hellwig 	status = _nfsd4_verify(rqstp, cstate, &u->verify);
1284c954e2a5SJ.Bruce Fields 	return status == nfserr_not_same ? nfs_ok : status;
1285c954e2a5SJ.Bruce Fields }
1286c954e2a5SJ.Bruce Fields 
1287c954e2a5SJ.Bruce Fields static __be32
1288c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1289eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
1290c954e2a5SJ.Bruce Fields {
1291c954e2a5SJ.Bruce Fields 	__be32 status;
1292c954e2a5SJ.Bruce Fields 
1293eb69853dSChristoph Hellwig 	status = _nfsd4_verify(rqstp, cstate, &u->nverify);
1294c954e2a5SJ.Bruce Fields 	return status == nfserr_same ? nfs_ok : status;
1295c954e2a5SJ.Bruce Fields }
1296c954e2a5SJ.Bruce Fields 
12979cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
12989cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops *
12999cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
13009cf514ccSChristoph Hellwig {
13018a4c3926SJeff Layton 	if (!exp->ex_layout_types) {
13029cf514ccSChristoph Hellwig 		dprintk("%s: export does not support pNFS\n", __func__);
13039cf514ccSChristoph Hellwig 		return NULL;
13049cf514ccSChristoph Hellwig 	}
13059cf514ccSChristoph Hellwig 
1306b550a32eSAri Kauppi 	if (layout_type >= LAYOUT_TYPE_MAX ||
1307b550a32eSAri Kauppi 	    !(exp->ex_layout_types & (1 << layout_type))) {
13089cf514ccSChristoph Hellwig 		dprintk("%s: layout type %d not supported\n",
13099cf514ccSChristoph Hellwig 			__func__, layout_type);
13109cf514ccSChristoph Hellwig 		return NULL;
13119cf514ccSChristoph Hellwig 	}
13129cf514ccSChristoph Hellwig 
13139cf514ccSChristoph Hellwig 	return nfsd4_layout_ops[layout_type];
13149cf514ccSChristoph Hellwig }
13159cf514ccSChristoph Hellwig 
13169cf514ccSChristoph Hellwig static __be32
13179cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
1318eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
13199cf514ccSChristoph Hellwig {
1320eb69853dSChristoph Hellwig 	struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
13219cf514ccSChristoph Hellwig 	const struct nfsd4_layout_ops *ops;
13229cf514ccSChristoph Hellwig 	struct nfsd4_deviceid_map *map;
13239cf514ccSChristoph Hellwig 	struct svc_export *exp;
13249cf514ccSChristoph Hellwig 	__be32 nfserr;
13259cf514ccSChristoph Hellwig 
13269cf514ccSChristoph Hellwig 	dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
13279cf514ccSChristoph Hellwig 	       __func__,
13289cf514ccSChristoph Hellwig 	       gdp->gd_layout_type,
13299cf514ccSChristoph Hellwig 	       gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
13309cf514ccSChristoph Hellwig 	       gdp->gd_maxcount);
13319cf514ccSChristoph Hellwig 
13329cf514ccSChristoph Hellwig 	map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
13339cf514ccSChristoph Hellwig 	if (!map) {
13349cf514ccSChristoph Hellwig 		dprintk("%s: couldn't find device ID to export mapping!\n",
13359cf514ccSChristoph Hellwig 			__func__);
13369cf514ccSChristoph Hellwig 		return nfserr_noent;
13379cf514ccSChristoph Hellwig 	}
13389cf514ccSChristoph Hellwig 
13399cf514ccSChristoph Hellwig 	exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
13409cf514ccSChristoph Hellwig 	if (IS_ERR(exp)) {
13419cf514ccSChristoph Hellwig 		dprintk("%s: could not find device id\n", __func__);
13429cf514ccSChristoph Hellwig 		return nfserr_noent;
13439cf514ccSChristoph Hellwig 	}
13449cf514ccSChristoph Hellwig 
13459cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
13469cf514ccSChristoph Hellwig 	ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
13479cf514ccSChristoph Hellwig 	if (!ops)
13489cf514ccSChristoph Hellwig 		goto out;
13499cf514ccSChristoph Hellwig 
13509cf514ccSChristoph Hellwig 	nfserr = nfs_ok;
1351f99d4fbdSChristoph Hellwig 	if (gdp->gd_maxcount != 0) {
1352f99d4fbdSChristoph Hellwig 		nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
1353d7c920d1STom Haynes 				rqstp, cstate->session->se_client, gdp);
1354f99d4fbdSChristoph Hellwig 	}
13559cf514ccSChristoph Hellwig 
13569cf514ccSChristoph Hellwig 	gdp->gd_notify_types &= ops->notify_types;
13579cf514ccSChristoph Hellwig out:
1358a1420384SKinglong Mee 	exp_put(exp);
13599cf514ccSChristoph Hellwig 	return nfserr;
13609cf514ccSChristoph Hellwig }
13619cf514ccSChristoph Hellwig 
136234b1744cSJ. Bruce Fields static void
136334b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
136434b1744cSJ. Bruce Fields {
136534b1744cSJ. Bruce Fields 	kfree(u->getdeviceinfo.gd_device);
136634b1744cSJ. Bruce Fields }
136734b1744cSJ. Bruce Fields 
13689cf514ccSChristoph Hellwig static __be32
13699cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp,
1370eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
13719cf514ccSChristoph Hellwig {
1372eb69853dSChristoph Hellwig 	struct nfsd4_layoutget *lgp = &u->layoutget;
13739cf514ccSChristoph Hellwig 	struct svc_fh *current_fh = &cstate->current_fh;
13749cf514ccSChristoph Hellwig 	const struct nfsd4_layout_ops *ops;
13759cf514ccSChristoph Hellwig 	struct nfs4_layout_stateid *ls;
13769cf514ccSChristoph Hellwig 	__be32 nfserr;
137766282ec1SBenjamin Coddington 	int accmode = NFSD_MAY_READ_IF_EXEC;
13789cf514ccSChristoph Hellwig 
13799cf514ccSChristoph Hellwig 	switch (lgp->lg_seg.iomode) {
13809cf514ccSChristoph Hellwig 	case IOMODE_READ:
138166282ec1SBenjamin Coddington 		accmode |= NFSD_MAY_READ;
13829cf514ccSChristoph Hellwig 		break;
13839cf514ccSChristoph Hellwig 	case IOMODE_RW:
138466282ec1SBenjamin Coddington 		accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
13859cf514ccSChristoph Hellwig 		break;
13869cf514ccSChristoph Hellwig 	default:
13879cf514ccSChristoph Hellwig 		dprintk("%s: invalid iomode %d\n",
13889cf514ccSChristoph Hellwig 			__func__, lgp->lg_seg.iomode);
13899cf514ccSChristoph Hellwig 		nfserr = nfserr_badiomode;
13909cf514ccSChristoph Hellwig 		goto out;
13919cf514ccSChristoph Hellwig 	}
13929cf514ccSChristoph Hellwig 
13939cf514ccSChristoph Hellwig 	nfserr = fh_verify(rqstp, current_fh, 0, accmode);
13949cf514ccSChristoph Hellwig 	if (nfserr)
13959cf514ccSChristoph Hellwig 		goto out;
13969cf514ccSChristoph Hellwig 
13979cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
13989cf514ccSChristoph Hellwig 	ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
13999cf514ccSChristoph Hellwig 	if (!ops)
14009cf514ccSChristoph Hellwig 		goto out;
14019cf514ccSChristoph Hellwig 
14029cf514ccSChristoph Hellwig 	/*
14039cf514ccSChristoph Hellwig 	 * Verify minlength and range as per RFC5661:
14049cf514ccSChristoph Hellwig 	 *  o  If loga_length is less than loga_minlength,
14059cf514ccSChristoph Hellwig 	 *     the metadata server MUST return NFS4ERR_INVAL.
14069cf514ccSChristoph Hellwig 	 *  o  If the sum of loga_offset and loga_minlength exceeds
14079cf514ccSChristoph Hellwig 	 *     NFS4_UINT64_MAX, and loga_minlength is not
14089cf514ccSChristoph Hellwig 	 *     NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
14099cf514ccSChristoph Hellwig 	 *  o  If the sum of loga_offset and loga_length exceeds
14109cf514ccSChristoph Hellwig 	 *     NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
14119cf514ccSChristoph Hellwig 	 *     the error NFS4ERR_INVAL MUST result.
14129cf514ccSChristoph Hellwig 	 */
14139cf514ccSChristoph Hellwig 	nfserr = nfserr_inval;
14149cf514ccSChristoph Hellwig 	if (lgp->lg_seg.length < lgp->lg_minlength ||
14159cf514ccSChristoph Hellwig 	    (lgp->lg_minlength != NFS4_MAX_UINT64 &&
14169cf514ccSChristoph Hellwig 	     lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
14179cf514ccSChristoph Hellwig 	    (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
14189cf514ccSChristoph Hellwig 	     lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
14199cf514ccSChristoph Hellwig 		goto out;
14209cf514ccSChristoph Hellwig 	if (lgp->lg_seg.length == 0)
14219cf514ccSChristoph Hellwig 		goto out;
14229cf514ccSChristoph Hellwig 
14239cf514ccSChristoph Hellwig 	nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
14249cf514ccSChristoph Hellwig 						true, lgp->lg_layout_type, &ls);
142531ef83dcSChristoph Hellwig 	if (nfserr) {
1426f394b62bSChuck Lever 		trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
14279cf514ccSChristoph Hellwig 		goto out;
142831ef83dcSChristoph Hellwig 	}
14299cf514ccSChristoph Hellwig 
1430c5c707f9SChristoph Hellwig 	nfserr = nfserr_recallconflict;
1431c5c707f9SChristoph Hellwig 	if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
1432c5c707f9SChristoph Hellwig 		goto out_put_stid;
1433c5c707f9SChristoph Hellwig 
14342b0143b5SDavid Howells 	nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
14359cf514ccSChristoph Hellwig 				     current_fh, lgp);
14369cf514ccSChristoph Hellwig 	if (nfserr)
14379cf514ccSChristoph Hellwig 		goto out_put_stid;
14389cf514ccSChristoph Hellwig 
14399cf514ccSChristoph Hellwig 	nfserr = nfsd4_insert_layout(lgp, ls);
14409cf514ccSChristoph Hellwig 
14419cf514ccSChristoph Hellwig out_put_stid:
1442cc8a5532SJeff Layton 	mutex_unlock(&ls->ls_mutex);
14439cf514ccSChristoph Hellwig 	nfs4_put_stid(&ls->ls_stid);
14449cf514ccSChristoph Hellwig out:
14459cf514ccSChristoph Hellwig 	return nfserr;
14469cf514ccSChristoph Hellwig }
14479cf514ccSChristoph Hellwig 
144834b1744cSJ. Bruce Fields static void
144934b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u)
145034b1744cSJ. Bruce Fields {
145134b1744cSJ. Bruce Fields 	kfree(u->layoutget.lg_content);
145234b1744cSJ. Bruce Fields }
145334b1744cSJ. Bruce Fields 
14549cf514ccSChristoph Hellwig static __be32
14559cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp,
1456eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
14579cf514ccSChristoph Hellwig {
1458eb69853dSChristoph Hellwig 	struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
14599cf514ccSChristoph Hellwig 	const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
14609cf514ccSChristoph Hellwig 	struct svc_fh *current_fh = &cstate->current_fh;
14619cf514ccSChristoph Hellwig 	const struct nfsd4_layout_ops *ops;
14629cf514ccSChristoph Hellwig 	loff_t new_size = lcp->lc_last_wr + 1;
14639cf514ccSChristoph Hellwig 	struct inode *inode;
14649cf514ccSChristoph Hellwig 	struct nfs4_layout_stateid *ls;
14659cf514ccSChristoph Hellwig 	__be32 nfserr;
14669cf514ccSChristoph Hellwig 
14679cf514ccSChristoph Hellwig 	nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
14689cf514ccSChristoph Hellwig 	if (nfserr)
14699cf514ccSChristoph Hellwig 		goto out;
14709cf514ccSChristoph Hellwig 
14719cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
14729cf514ccSChristoph Hellwig 	ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
14739cf514ccSChristoph Hellwig 	if (!ops)
14749cf514ccSChristoph Hellwig 		goto out;
14752b0143b5SDavid Howells 	inode = d_inode(current_fh->fh_dentry);
14769cf514ccSChristoph Hellwig 
14779cf514ccSChristoph Hellwig 	nfserr = nfserr_inval;
14789cf514ccSChristoph Hellwig 	if (new_size <= seg->offset) {
14799cf514ccSChristoph Hellwig 		dprintk("pnfsd: last write before layout segment\n");
14809cf514ccSChristoph Hellwig 		goto out;
14819cf514ccSChristoph Hellwig 	}
14829cf514ccSChristoph Hellwig 	if (new_size > seg->offset + seg->length) {
14839cf514ccSChristoph Hellwig 		dprintk("pnfsd: last write beyond layout segment\n");
14849cf514ccSChristoph Hellwig 		goto out;
14859cf514ccSChristoph Hellwig 	}
14869cf514ccSChristoph Hellwig 	if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
14879cf514ccSChristoph Hellwig 		dprintk("pnfsd: layoutcommit beyond EOF\n");
14889cf514ccSChristoph Hellwig 		goto out;
14899cf514ccSChristoph Hellwig 	}
14909cf514ccSChristoph Hellwig 
14919cf514ccSChristoph Hellwig 	nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
14929cf514ccSChristoph Hellwig 						false, lcp->lc_layout_type,
14939cf514ccSChristoph Hellwig 						&ls);
14949cf514ccSChristoph Hellwig 	if (nfserr) {
1495f394b62bSChuck Lever 		trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
14969cf514ccSChristoph Hellwig 		/* fixup error code as per RFC5661 */
14979cf514ccSChristoph Hellwig 		if (nfserr == nfserr_bad_stateid)
14989cf514ccSChristoph Hellwig 			nfserr = nfserr_badlayout;
14999cf514ccSChristoph Hellwig 		goto out;
15009cf514ccSChristoph Hellwig 	}
15019cf514ccSChristoph Hellwig 
1502cc8a5532SJeff Layton 	/* LAYOUTCOMMIT does not require any serialization */
1503cc8a5532SJeff Layton 	mutex_unlock(&ls->ls_mutex);
1504cc8a5532SJeff Layton 
15059cf514ccSChristoph Hellwig 	if (new_size > i_size_read(inode)) {
15069cf514ccSChristoph Hellwig 		lcp->lc_size_chg = 1;
15079cf514ccSChristoph Hellwig 		lcp->lc_newsize = new_size;
15089cf514ccSChristoph Hellwig 	} else {
15099cf514ccSChristoph Hellwig 		lcp->lc_size_chg = 0;
15109cf514ccSChristoph Hellwig 	}
15119cf514ccSChristoph Hellwig 
1512d8398fc1SKinglong Mee 	nfserr = ops->proc_layoutcommit(inode, lcp);
15139cf514ccSChristoph Hellwig 	nfs4_put_stid(&ls->ls_stid);
15149cf514ccSChristoph Hellwig out:
15159cf514ccSChristoph Hellwig 	return nfserr;
15169cf514ccSChristoph Hellwig }
15179cf514ccSChristoph Hellwig 
15189cf514ccSChristoph Hellwig static __be32
15199cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp,
1520eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
15219cf514ccSChristoph Hellwig {
1522eb69853dSChristoph Hellwig 	struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
15239cf514ccSChristoph Hellwig 	struct svc_fh *current_fh = &cstate->current_fh;
15249cf514ccSChristoph Hellwig 	__be32 nfserr;
15259cf514ccSChristoph Hellwig 
15269cf514ccSChristoph Hellwig 	nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
15279cf514ccSChristoph Hellwig 	if (nfserr)
15289cf514ccSChristoph Hellwig 		goto out;
15299cf514ccSChristoph Hellwig 
15309cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
15319cf514ccSChristoph Hellwig 	if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
15329cf514ccSChristoph Hellwig 		goto out;
15339cf514ccSChristoph Hellwig 
15349cf514ccSChristoph Hellwig 	switch (lrp->lr_seg.iomode) {
15359cf514ccSChristoph Hellwig 	case IOMODE_READ:
15369cf514ccSChristoph Hellwig 	case IOMODE_RW:
15379cf514ccSChristoph Hellwig 	case IOMODE_ANY:
15389cf514ccSChristoph Hellwig 		break;
15399cf514ccSChristoph Hellwig 	default:
15409cf514ccSChristoph Hellwig 		dprintk("%s: invalid iomode %d\n", __func__,
15419cf514ccSChristoph Hellwig 			lrp->lr_seg.iomode);
15429cf514ccSChristoph Hellwig 		nfserr = nfserr_inval;
15439cf514ccSChristoph Hellwig 		goto out;
15449cf514ccSChristoph Hellwig 	}
15459cf514ccSChristoph Hellwig 
15469cf514ccSChristoph Hellwig 	switch (lrp->lr_return_type) {
15479cf514ccSChristoph Hellwig 	case RETURN_FILE:
15489cf514ccSChristoph Hellwig 		nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
15499cf514ccSChristoph Hellwig 		break;
15509cf514ccSChristoph Hellwig 	case RETURN_FSID:
15519cf514ccSChristoph Hellwig 	case RETURN_ALL:
15529cf514ccSChristoph Hellwig 		nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
15539cf514ccSChristoph Hellwig 		break;
15549cf514ccSChristoph Hellwig 	default:
15559cf514ccSChristoph Hellwig 		dprintk("%s: invalid return_type %d\n", __func__,
15569cf514ccSChristoph Hellwig 			lrp->lr_return_type);
15579cf514ccSChristoph Hellwig 		nfserr = nfserr_inval;
15589cf514ccSChristoph Hellwig 		break;
15599cf514ccSChristoph Hellwig 	}
15609cf514ccSChristoph Hellwig out:
15619cf514ccSChristoph Hellwig 	return nfserr;
15629cf514ccSChristoph Hellwig }
15639cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */
15649cf514ccSChristoph Hellwig 
15651da177e4SLinus Torvalds /*
15661da177e4SLinus Torvalds  * NULL call.
15671da177e4SLinus Torvalds  */
15687111c66eSAl Viro static __be32
1569a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp)
15701da177e4SLinus Torvalds {
15711da177e4SLinus Torvalds 	return nfs_ok;
15721da177e4SLinus Torvalds }
15731da177e4SLinus Torvalds 
1574e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum)
1575e2b20950SShankar Anand {
1576e2b20950SShankar Anand 	if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
1577e2b20950SShankar Anand 		nfsdstats.nfs4_opcount[opnum]++;
1578e2b20950SShankar Anand }
1579e2b20950SShankar Anand 
1580bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[];
1581b591480bSJ.Bruce Fields 
1582f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum);
1583b001a1b6SBenny Halevy 
15841da177e4SLinus Torvalds /*
158557716355SJ. Bruce Fields  * Enforce NFSv4.1 COMPOUND ordering rules:
1586f9bb94c4SAndy Adamson  *
158757716355SJ. Bruce Fields  * Also note, enforced elsewhere:
158857716355SJ. Bruce Fields  *	- SEQUENCE other than as first op results in
158957716355SJ. Bruce Fields  *	  NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
15901d1bc8f2SJ. Bruce Fields  *	- BIND_CONN_TO_SESSION must be the only op in its compound.
15911d1bc8f2SJ. Bruce Fields  *	  (Enforced in nfsd4_bind_conn_to_session().)
159257716355SJ. Bruce Fields  *	- DESTROY_SESSION must be the final operation in a compound, if
159357716355SJ. Bruce Fields  *	  sessionid's in SEQUENCE and DESTROY_SESSION are the same.
159457716355SJ. Bruce Fields  *	  (Enforced in nfsd4_destroy_session().)
1595f9bb94c4SAndy Adamson  */
159657716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
1597f9bb94c4SAndy Adamson {
15987a04cfdaSJ. Bruce Fields 	struct nfsd4_op *first_op = &args->ops[0];
159957716355SJ. Bruce Fields 
160057716355SJ. Bruce Fields 	/* These ordering requirements don't apply to NFSv4.0: */
160157716355SJ. Bruce Fields 	if (args->minorversion == 0)
160257716355SJ. Bruce Fields 		return nfs_ok;
160357716355SJ. Bruce Fields 	/* This is weird, but OK, not our problem: */
160457716355SJ. Bruce Fields 	if (args->opcnt == 0)
160557716355SJ. Bruce Fields 		return nfs_ok;
16067a04cfdaSJ. Bruce Fields 	if (first_op->status == nfserr_op_illegal)
160757716355SJ. Bruce Fields 		return nfs_ok;
16087a04cfdaSJ. Bruce Fields 	if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
160957716355SJ. Bruce Fields 		return nfserr_op_not_in_session;
16107a04cfdaSJ. Bruce Fields 	if (first_op->opnum == OP_SEQUENCE)
161157716355SJ. Bruce Fields 		return nfs_ok;
16127a04cfdaSJ. Bruce Fields 	/*
16137a04cfdaSJ. Bruce Fields 	 * So first_op is something allowed outside a session, like
16147a04cfdaSJ. Bruce Fields 	 * EXCHANGE_ID; but then it has to be the only op in the
16157a04cfdaSJ. Bruce Fields 	 * compound:
16167a04cfdaSJ. Bruce Fields 	 */
161757716355SJ. Bruce Fields 	if (args->opcnt != 1)
161857716355SJ. Bruce Fields 		return nfserr_not_only_op;
161957716355SJ. Bruce Fields 	return nfs_ok;
1620f9bb94c4SAndy Adamson }
1621f9bb94c4SAndy Adamson 
1622f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
162322b03214SJ. Bruce Fields {
162422b03214SJ. Bruce Fields 	return &nfsd4_ops[op->opnum];
162522b03214SJ. Bruce Fields }
162622b03214SJ. Bruce Fields 
16271091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op)
16281091006cSJ. Bruce Fields {
1629e372ba60SJ. Bruce Fields 	if (op->opnum == OP_ILLEGAL)
1630e372ba60SJ. Bruce Fields 		return false;
1631c856694eSJ. Bruce Fields 	return OPDESC(op)->op_flags & OP_CACHEME;
16321091006cSJ. Bruce Fields }
16331091006cSJ. Bruce Fields 
163468d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp)
163568d93184SJ. Bruce Fields {
163668d93184SJ. Bruce Fields 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
163768d93184SJ. Bruce Fields 	struct nfsd4_compoundargs *argp = rqstp->rq_argp;
163868d93184SJ. Bruce Fields 	struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
163968d93184SJ. Bruce Fields 	struct nfsd4_op *next = &argp->ops[resp->opcnt];
1640bb2a8b0cSChristoph Hellwig 	const struct nfsd4_operation *thisd = OPDESC(this);
1641bb2a8b0cSChristoph Hellwig 	const struct nfsd4_operation *nextd;
164268d93184SJ. Bruce Fields 
164368d93184SJ. Bruce Fields 	/*
164468d93184SJ. Bruce Fields 	 * Most ops check wronsec on our own; only the putfh-like ops
164568d93184SJ. Bruce Fields 	 * have special rules.
164668d93184SJ. Bruce Fields 	 */
164768d93184SJ. Bruce Fields 	if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
164868d93184SJ. Bruce Fields 		return false;
164968d93184SJ. Bruce Fields 	/*
165068d93184SJ. Bruce Fields 	 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
165168d93184SJ. Bruce Fields 	 * put-filehandle operation if we're not going to use the
165268d93184SJ. Bruce Fields 	 * result:
165368d93184SJ. Bruce Fields 	 */
165468d93184SJ. Bruce Fields 	if (argp->opcnt == resp->opcnt)
165568d93184SJ. Bruce Fields 		return false;
165651904b08SJ. Bruce Fields 	if (next->opnum == OP_ILLEGAL)
165751904b08SJ. Bruce Fields 		return false;
165868d93184SJ. Bruce Fields 	nextd = OPDESC(next);
165968d93184SJ. Bruce Fields 	/*
166068d93184SJ. Bruce Fields 	 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
166168d93184SJ. Bruce Fields 	 * errors themselves as necessary; others should check for them
166268d93184SJ. Bruce Fields 	 * now:
166368d93184SJ. Bruce Fields 	 */
166468d93184SJ. Bruce Fields 	return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
166568d93184SJ. Bruce Fields }
166668d93184SJ. Bruce Fields 
16672d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp,
16682d124dfaSJ. Bruce Fields 			       struct nfsd4_compoundres *resp)
16692d124dfaSJ. Bruce Fields {
16702d124dfaSJ. Bruce Fields 	struct xdr_stream *xdr = &resp->xdr;
16712d124dfaSJ. Bruce Fields 	struct xdr_buf *buf = &rqstp->rq_res;
16722d124dfaSJ. Bruce Fields 	struct kvec *head = buf->head;
16732d124dfaSJ. Bruce Fields 
16742d124dfaSJ. Bruce Fields 	xdr->buf = buf;
1675ddd1ea56SJ. Bruce Fields 	xdr->iov = head;
16762d124dfaSJ. Bruce Fields 	xdr->p   = head->iov_base + head->iov_len;
1677a5cddc88SJ. Bruce Fields 	xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
16786ac90391SJ. Bruce Fields 	/* Tail and page_len should be zero at this point: */
16796ac90391SJ. Bruce Fields 	buf->len = buf->head[0].iov_len;
16802825a7f9SJ. Bruce Fields 	xdr->scratch.iov_len = 0;
168105638dc7SJ. Bruce Fields 	xdr->page_ptr = buf->pages - 1;
16822825a7f9SJ. Bruce Fields 	buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
1683a5cddc88SJ. Bruce Fields 		- rqstp->rq_auth_slack;
16842d124dfaSJ. Bruce Fields }
16852d124dfaSJ. Bruce Fields 
1686f9bb94c4SAndy Adamson /*
16871da177e4SLinus Torvalds  * COMPOUND call.
16881da177e4SLinus Torvalds  */
16897111c66eSAl Viro static __be32
1690a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp)
16911da177e4SLinus Torvalds {
1692a6beb732SChristoph Hellwig 	struct nfsd4_compoundargs *args = rqstp->rq_argp;
1693a6beb732SChristoph Hellwig 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
16941da177e4SLinus Torvalds 	struct nfsd4_op	*op;
1695e354d571SAndy Adamson 	struct nfsd4_compound_state *cstate = &resp->cstate;
16964daeed25SKinglong Mee 	struct svc_fh *current_fh = &cstate->current_fh;
16974daeed25SKinglong Mee 	struct svc_fh *save_fh = &cstate->save_fh;
1698b37ad28bSAl Viro 	__be32		status;
16991da177e4SLinus Torvalds 
17002d124dfaSJ. Bruce Fields 	svcxdr_init_encode(rqstp, resp);
17014aea24b2SJ. Bruce Fields 	resp->tagp = resp->xdr.p;
17021da177e4SLinus Torvalds 	/* reserve space for: taglen, tag, and opcnt */
1703d3f627c8SJ. Bruce Fields 	xdr_reserve_space(&resp->xdr, 8 + args->taglen);
17041da177e4SLinus Torvalds 	resp->taglen = args->taglen;
17051da177e4SLinus Torvalds 	resp->tag = args->tag;
17061da177e4SLinus Torvalds 	resp->rqstp = rqstp;
17074daeed25SKinglong Mee 	cstate->minorversion = args->minorversion;
17084daeed25SKinglong Mee 	fh_init(current_fh, NFS4_FHSIZE);
17094daeed25SKinglong Mee 	fh_init(save_fh, NFS4_FHSIZE);
17108ff30fa4SNeilBrown 	/*
17118ff30fa4SNeilBrown 	 * Don't use the deferral mechanism for NFSv4; compounds make it
17128ff30fa4SNeilBrown 	 * too hard to avoid non-idempotency problems.
17138ff30fa4SNeilBrown 	 */
171430660e04SJeff Layton 	clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
17151da177e4SLinus Torvalds 
17161da177e4SLinus Torvalds 	/*
17171da177e4SLinus Torvalds 	 * According to RFC3010, this takes precedence over all other errors.
17181da177e4SLinus Torvalds 	 */
17191da177e4SLinus Torvalds 	status = nfserr_minor_vers_mismatch;
172035f7a14fSJ. Bruce Fields 	if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0)
17211da177e4SLinus Torvalds 		goto out;
17220078117cSJ. Bruce Fields 	status = nfserr_resource;
17230078117cSJ. Bruce Fields 	if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
17240078117cSJ. Bruce Fields 		goto out;
17251da177e4SLinus Torvalds 
172657716355SJ. Bruce Fields 	status = nfs41_check_op_ordering(args);
172757716355SJ. Bruce Fields 	if (status) {
1728f9bb94c4SAndy Adamson 		op = &args->ops[0];
172957716355SJ. Bruce Fields 		op->status = status;
17305b7b15aeSJ. Bruce Fields 		resp->opcnt = 1;
1731f9bb94c4SAndy Adamson 		goto encode_op;
1732f9bb94c4SAndy Adamson 	}
1733f9bb94c4SAndy Adamson 
1734fff4080bSChuck Lever 	trace_nfsd_compound(rqstp, args->opcnt);
17351da177e4SLinus Torvalds 	while (!status && resp->opcnt < args->opcnt) {
17361da177e4SLinus Torvalds 		op = &args->ops[resp->opcnt++];
17371da177e4SLinus Torvalds 
17381da177e4SLinus Torvalds 		/*
17391da177e4SLinus Torvalds 		 * The XDR decode routines may have pre-set op->status;
17401da177e4SLinus Torvalds 		 * for example, if there is a miscellaneous XDR error
17411da177e4SLinus Torvalds 		 * it will be set to nfserr_bad_xdr.
17421da177e4SLinus Torvalds 		 */
17439d313b17SJ. Bruce Fields 		if (op->status) {
17449d313b17SJ. Bruce Fields 			if (op->opnum == OP_OPEN)
17459d313b17SJ. Bruce Fields 				op->status = nfsd4_open_omfg(rqstp, cstate, op);
17461da177e4SLinus Torvalds 			goto encode_op;
17479d313b17SJ. Bruce Fields 		}
17481da177e4SLinus Torvalds 
17494daeed25SKinglong Mee 		if (!current_fh->fh_dentry) {
1750f4f9ef4aSJ. Bruce Fields 			if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
17511da177e4SLinus Torvalds 				op->status = nfserr_nofilehandle;
17521da177e4SLinus Torvalds 				goto encode_op;
17531da177e4SLinus Torvalds 			}
17544daeed25SKinglong Mee 		} else if (current_fh->fh_export->ex_fslocs.migrated &&
1755f4f9ef4aSJ. Bruce Fields 			  !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
175642ca0993SJ.Bruce Fields 			op->status = nfserr_moved;
175742ca0993SJ.Bruce Fields 			goto encode_op;
175842ca0993SJ.Bruce Fields 		}
1759b591480bSJ.Bruce Fields 
17602336745eSKinglong Mee 		fh_clear_wcc(current_fh);
17612336745eSKinglong Mee 
176258e7b33aSMi Jinlong 		/* If op is non-idempotent */
1763f4f9ef4aSJ. Bruce Fields 		if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
17644c69d585SJ. Bruce Fields 			/*
1765a8095f7eSJ. Bruce Fields 			 * Don't execute this op if we couldn't encode a
1766a8095f7eSJ. Bruce Fields 			 * succesful reply:
1767a8095f7eSJ. Bruce Fields 			 */
1768f4f9ef4aSJ. Bruce Fields 			u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
1769a8095f7eSJ. Bruce Fields 			/*
1770a8095f7eSJ. Bruce Fields 			 * Plus if there's another operation, make sure
17714c69d585SJ. Bruce Fields 			 * we'll have space to at least encode an error:
17724c69d585SJ. Bruce Fields 			 */
17734c69d585SJ. Bruce Fields 			if (resp->opcnt < args->opcnt)
17744c69d585SJ. Bruce Fields 				plen += COMPOUND_ERR_SLACK_SPACE;
177558e7b33aSMi Jinlong 			op->status = nfsd4_check_resp_size(resp, plen);
177658e7b33aSMi Jinlong 		}
177758e7b33aSMi Jinlong 
177858e7b33aSMi Jinlong 		if (op->status)
177958e7b33aSMi Jinlong 			goto encode_op;
178058e7b33aSMi Jinlong 
1781f4f9ef4aSJ. Bruce Fields 		if (op->opdesc->op_get_currentstateid)
1782f4f9ef4aSJ. Bruce Fields 			op->opdesc->op_get_currentstateid(cstate, &op->u);
1783f4f9ef4aSJ. Bruce Fields 		op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
17841da177e4SLinus Torvalds 
17859a307403SJ. Bruce Fields 		/* Only from SEQUENCE */
17869a307403SJ. Bruce Fields 		if (cstate->status == nfserr_replay_cache) {
17879a307403SJ. Bruce Fields 			dprintk("%s NFS4.1 replay from cache\n", __func__);
17889a307403SJ. Bruce Fields 			status = op->status;
17899a307403SJ. Bruce Fields 			goto out;
17909a307403SJ. Bruce Fields 		}
17918b70484cSTigran Mkrtchyan 		if (!op->status) {
1792f4f9ef4aSJ. Bruce Fields 			if (op->opdesc->op_set_currentstateid)
1793f4f9ef4aSJ. Bruce Fields 				op->opdesc->op_set_currentstateid(cstate, &op->u);
17948b70484cSTigran Mkrtchyan 
1795f4f9ef4aSJ. Bruce Fields 			if (op->opdesc->op_flags & OP_CLEAR_STATEID)
179637c593c5STigran Mkrtchyan 				clear_current_stateid(cstate);
17978b70484cSTigran Mkrtchyan 
17988b70484cSTigran Mkrtchyan 			if (need_wrongsec_check(rqstp))
17994daeed25SKinglong Mee 				op->status = check_nfsd_access(current_fh->fh_export, rqstp);
18008b70484cSTigran Mkrtchyan 		}
18011da177e4SLinus Torvalds encode_op:
1802a90b061cSAl Viro 		if (op->status == nfserr_replay_me) {
1803a4f1706aSJ.Bruce Fields 			op->replay = &cstate->replay_owner->so_replay;
1804d0a381ddSJ. Bruce Fields 			nfsd4_encode_replay(&resp->xdr, op);
18051da177e4SLinus Torvalds 			status = op->status = op->replay->rp_status;
18061da177e4SLinus Torvalds 		} else {
18071da177e4SLinus Torvalds 			nfsd4_encode_operation(resp, op);
18081da177e4SLinus Torvalds 			status = op->status;
18091da177e4SLinus Torvalds 		}
18100407717dSBenny Halevy 
1811fff4080bSChuck Lever 		trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
1812fff4080bSChuck Lever 					   nfsd4_op_name(op->opnum));
18130407717dSBenny Halevy 
181458fb12e6SJeff Layton 		nfsd4_cstate_clear_replay(cstate);
1815e2b20950SShankar Anand 		nfsd4_increment_op_stats(op->opnum);
18161da177e4SLinus Torvalds 	}
18171da177e4SLinus Torvalds 
18184daeed25SKinglong Mee 	cstate->status = status;
18194daeed25SKinglong Mee 	fh_put(current_fh);
18204daeed25SKinglong Mee 	fh_put(save_fh);
18214daeed25SKinglong Mee 	BUG_ON(cstate->replay_owner);
18221da177e4SLinus Torvalds out:
18232f425878SAndy Adamson 	/* Reset deferral mechanism for RPC deferrals */
182430660e04SJeff Layton 	set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
18253b12cd98SJ. Bruce Fields 	dprintk("nfsv4 compound returned %d\n", ntohl(status));
18261da177e4SLinus Torvalds 	return status;
18271da177e4SLinus Torvalds }
18281da177e4SLinus Torvalds 
182958e7b33aSMi Jinlong #define op_encode_hdr_size		(2)
183058e7b33aSMi Jinlong #define op_encode_stateid_maxsz		(XDR_QUADLEN(NFS4_STATEID_SIZE))
183158e7b33aSMi Jinlong #define op_encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
183258e7b33aSMi Jinlong #define op_encode_change_info_maxsz	(5)
183358e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz		(4)
183458e7b33aSMi Jinlong 
18358c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */
18368c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz	(0)
183758e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz	(8 + op_encode_lockowner_maxsz)
183858e7b33aSMi Jinlong 
183958e7b33aSMi Jinlong #define nfs4_owner_maxsz		(1 + XDR_QUADLEN(IDMAP_NAMESZ))
184058e7b33aSMi Jinlong 
184158e7b33aSMi Jinlong #define op_encode_ace_maxsz		(3 + nfs4_owner_maxsz)
184258e7b33aSMi Jinlong #define op_encode_delegation_maxsz	(1 + op_encode_stateid_maxsz + 1 + \
184358e7b33aSMi Jinlong 					 op_encode_ace_maxsz)
184458e7b33aSMi Jinlong 
184558e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz	(6 + 1 + 1)
184658e7b33aSMi Jinlong 
184758e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
184858e7b33aSMi Jinlong {
184958e7b33aSMi Jinlong 	return (op_encode_hdr_size) * sizeof(__be32);
185058e7b33aSMi Jinlong }
185158e7b33aSMi Jinlong 
185258e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
185358e7b33aSMi Jinlong {
185458e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
185558e7b33aSMi Jinlong }
185658e7b33aSMi Jinlong 
18572282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
18582282cd2cSKinglong Mee {
18592282cd2cSKinglong Mee 	/* ac_supported, ac_resp_access */
18602282cd2cSKinglong Mee 	return (op_encode_hdr_size + 2)* sizeof(__be32);
18612282cd2cSKinglong Mee }
18622282cd2cSKinglong Mee 
186358e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
186458e7b33aSMi Jinlong {
186558e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
186658e7b33aSMi Jinlong }
186758e7b33aSMi Jinlong 
186858e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
186958e7b33aSMi Jinlong {
187058e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz
187158e7b33aSMi Jinlong 		+ nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
187258e7b33aSMi Jinlong }
187358e7b33aSMi Jinlong 
1874b86cef60SJ. Bruce Fields /*
1875b86cef60SJ. Bruce Fields  * Note since this is an idempotent operation we won't insist on failing
1876b86cef60SJ. Bruce Fields  * the op prematurely if the estimate is too large.  We may turn off splice
1877b86cef60SJ. Bruce Fields  * reads unnecessarily.
1878b86cef60SJ. Bruce Fields  */
1879b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
1880b86cef60SJ. Bruce Fields 				      struct nfsd4_op *op)
1881b86cef60SJ. Bruce Fields {
1882b86cef60SJ. Bruce Fields 	u32 *bmap = op->u.getattr.ga_bmval;
1883b86cef60SJ. Bruce Fields 	u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
1884b86cef60SJ. Bruce Fields 	u32 ret = 0;
1885b86cef60SJ. Bruce Fields 
1886b86cef60SJ. Bruce Fields 	if (bmap0 & FATTR4_WORD0_ACL)
1887b86cef60SJ. Bruce Fields 		return svc_max_payload(rqstp);
1888b86cef60SJ. Bruce Fields 	if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
1889b86cef60SJ. Bruce Fields 		return svc_max_payload(rqstp);
1890b86cef60SJ. Bruce Fields 
1891b86cef60SJ. Bruce Fields 	if (bmap1 & FATTR4_WORD1_OWNER) {
1892b86cef60SJ. Bruce Fields 		ret += IDMAP_NAMESZ + 4;
1893b86cef60SJ. Bruce Fields 		bmap1 &= ~FATTR4_WORD1_OWNER;
1894b86cef60SJ. Bruce Fields 	}
1895b86cef60SJ. Bruce Fields 	if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
1896b86cef60SJ. Bruce Fields 		ret += IDMAP_NAMESZ + 4;
1897b86cef60SJ. Bruce Fields 		bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
1898b86cef60SJ. Bruce Fields 	}
1899b86cef60SJ. Bruce Fields 	if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
1900b86cef60SJ. Bruce Fields 		ret += NFS4_FHSIZE + 4;
1901b86cef60SJ. Bruce Fields 		bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
1902b86cef60SJ. Bruce Fields 	}
1903b86cef60SJ. Bruce Fields 	if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
19041ec8c0c4SKinglong Mee 		ret += NFS4_MAXLABELLEN + 12;
1905b86cef60SJ. Bruce Fields 		bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
1906b86cef60SJ. Bruce Fields 	}
1907b86cef60SJ. Bruce Fields 	/*
1908b86cef60SJ. Bruce Fields 	 * Largest of remaining attributes are 16 bytes (e.g.,
1909b86cef60SJ. Bruce Fields 	 * supported_attributes)
1910b86cef60SJ. Bruce Fields 	 */
1911b86cef60SJ. Bruce Fields 	ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
1912b86cef60SJ. Bruce Fields 	/* bitmask, length */
1913b86cef60SJ. Bruce Fields 	ret += 20;
1914b86cef60SJ. Bruce Fields 	return ret;
1915b86cef60SJ. Bruce Fields }
1916b86cef60SJ. Bruce Fields 
19172282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
19182282cd2cSKinglong Mee {
19192282cd2cSKinglong Mee 	return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
19202282cd2cSKinglong Mee }
19212282cd2cSKinglong Mee 
192258e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
192358e7b33aSMi Jinlong {
192458e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz)
192558e7b33aSMi Jinlong 		* sizeof(__be32);
192658e7b33aSMi Jinlong }
192758e7b33aSMi Jinlong 
192858e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
192958e7b33aSMi Jinlong {
193058e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
193158e7b33aSMi Jinlong 		* sizeof(__be32);
193258e7b33aSMi Jinlong }
193358e7b33aSMi Jinlong 
193458e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
193558e7b33aSMi Jinlong {
193658e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_stateid_maxsz
193758e7b33aSMi Jinlong 		+ op_encode_change_info_maxsz + 1
193858e7b33aSMi Jinlong 		+ nfs4_fattr_bitmap_maxsz
193958e7b33aSMi Jinlong 		+ op_encode_delegation_maxsz) * sizeof(__be32);
194058e7b33aSMi Jinlong }
194158e7b33aSMi Jinlong 
194258e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
194358e7b33aSMi Jinlong {
194458e7b33aSMi Jinlong 	u32 maxcount = 0, rlen = 0;
194558e7b33aSMi Jinlong 
194658e7b33aSMi Jinlong 	maxcount = svc_max_payload(rqstp);
19473c7aa15dSKinglong Mee 	rlen = min(op->u.read.rd_length, maxcount);
194858e7b33aSMi Jinlong 
1949622f560eSJ. Bruce Fields 	return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
195058e7b33aSMi Jinlong }
195158e7b33aSMi Jinlong 
195258e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
195358e7b33aSMi Jinlong {
19543c7aa15dSKinglong Mee 	u32 maxcount = 0, rlen = 0;
195558e7b33aSMi Jinlong 
19563c7aa15dSKinglong Mee 	maxcount = svc_max_payload(rqstp);
19573c7aa15dSKinglong Mee 	rlen = min(op->u.readdir.rd_maxcount, maxcount);
195858e7b33aSMi Jinlong 
1959561f0ed4SJ. Bruce Fields 	return (op_encode_hdr_size + op_encode_verifier_maxsz +
1960561f0ed4SJ. Bruce Fields 		XDR_QUADLEN(rlen)) * sizeof(__be32);
196158e7b33aSMi Jinlong }
196258e7b33aSMi Jinlong 
19632282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
19642282cd2cSKinglong Mee {
19652282cd2cSKinglong Mee 	return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
19662282cd2cSKinglong Mee }
19672282cd2cSKinglong Mee 
196858e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
196958e7b33aSMi Jinlong {
197058e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz)
197158e7b33aSMi Jinlong 		* sizeof(__be32);
197258e7b33aSMi Jinlong }
197358e7b33aSMi Jinlong 
197458e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
197558e7b33aSMi Jinlong {
197658e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz
197758e7b33aSMi Jinlong 		+ op_encode_change_info_maxsz) * sizeof(__be32);
197858e7b33aSMi Jinlong }
197958e7b33aSMi Jinlong 
1980ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
1981ccae70a9SJ. Bruce Fields 				       struct nfsd4_op *op)
1982ccae70a9SJ. Bruce Fields {
1983d1d84c96SJ. Bruce Fields 	return (op_encode_hdr_size
1984d1d84c96SJ. Bruce Fields 		+ XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
1985ccae70a9SJ. Bruce Fields }
1986ccae70a9SJ. Bruce Fields 
19872282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
19882282cd2cSKinglong Mee {
19892282cd2cSKinglong Mee 	return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
19902282cd2cSKinglong Mee 		* sizeof(__be32);
19912282cd2cSKinglong Mee }
19922282cd2cSKinglong Mee 
199358e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
199458e7b33aSMi Jinlong {
199558e7b33aSMi Jinlong 	return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
199658e7b33aSMi Jinlong }
199758e7b33aSMi Jinlong 
19982282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
19992282cd2cSKinglong Mee {
20002282cd2cSKinglong Mee 	return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
20012282cd2cSKinglong Mee 		(4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
20022282cd2cSKinglong Mee }
20032282cd2cSKinglong Mee 
200458e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
200558e7b33aSMi Jinlong {
2006480efaeeSJ. Bruce Fields 	return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2007480efaeeSJ. Bruce Fields 								sizeof(__be32);
200858e7b33aSMi Jinlong }
200958e7b33aSMi Jinlong 
201058e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
201158e7b33aSMi Jinlong {
2012f34e432bSJ. Bruce Fields 	return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
201358e7b33aSMi Jinlong }
201458e7b33aSMi Jinlong 
201558e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
201658e7b33aSMi Jinlong {
201758e7b33aSMi Jinlong 	return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
2018a8bb84bcSKinglong Mee 		1 + 1 + /* eir_flags, spr_how */\
2019a8bb84bcSKinglong Mee 		4 + /* spo_must_enforce & _allow with bitmap */\
202058e7b33aSMi Jinlong 		2 + /*eir_server_owner.so_minor_id */\
202158e7b33aSMi Jinlong 		/* eir_server_owner.so_major_id<> */\
202258e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
202358e7b33aSMi Jinlong 		/* eir_server_scope<> */\
202458e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
202558e7b33aSMi Jinlong 		1 + /* eir_server_impl_id array length */\
202658e7b33aSMi Jinlong 		0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
202758e7b33aSMi Jinlong }
202858e7b33aSMi Jinlong 
202958e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
203058e7b33aSMi Jinlong {
203158e7b33aSMi Jinlong 	return (op_encode_hdr_size + \
203258e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
203358e7b33aSMi Jinlong 		2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
203458e7b33aSMi Jinlong }
203558e7b33aSMi Jinlong 
203658e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
203758e7b33aSMi Jinlong {
203858e7b33aSMi Jinlong 	return (op_encode_hdr_size + \
203958e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
204058e7b33aSMi Jinlong 		2 + /* csr_sequence, csr_flags */\
204158e7b33aSMi Jinlong 		op_encode_channel_attrs_maxsz + \
204258e7b33aSMi Jinlong 		op_encode_channel_attrs_maxsz) * sizeof(__be32);
204358e7b33aSMi Jinlong }
204458e7b33aSMi Jinlong 
204529ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
204629ae7f9dSAnna Schumaker {
204729ae7f9dSAnna Schumaker 	return (op_encode_hdr_size +
204829ae7f9dSAnna Schumaker 		1 /* wr_callback */ +
204929ae7f9dSAnna Schumaker 		op_encode_stateid_maxsz /* wr_callback */ +
205029ae7f9dSAnna Schumaker 		2 /* wr_count */ +
205129ae7f9dSAnna Schumaker 		1 /* wr_committed */ +
205229ae7f9dSAnna Schumaker 		op_encode_verifier_maxsz +
205329ae7f9dSAnna Schumaker 		1 /* cr_consecutive */ +
205429ae7f9dSAnna Schumaker 		1 /* cr_synchronous */) * sizeof(__be32);
205529ae7f9dSAnna Schumaker }
205629ae7f9dSAnna Schumaker 
2057*6308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
2058*6308bc98SOlga Kornievskaia 					     struct nfsd4_op *op)
2059*6308bc98SOlga Kornievskaia {
2060*6308bc98SOlga Kornievskaia 	return (op_encode_hdr_size +
2061*6308bc98SOlga Kornievskaia 		2 /* osr_count */ +
2062*6308bc98SOlga Kornievskaia 		1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
2063*6308bc98SOlga Kornievskaia }
2064*6308bc98SOlga Kornievskaia 
20659cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
20662282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
20672282cd2cSKinglong Mee {
20682282cd2cSKinglong Mee 	u32 maxcount = 0, rlen = 0;
20692282cd2cSKinglong Mee 
20702282cd2cSKinglong Mee 	maxcount = svc_max_payload(rqstp);
20712282cd2cSKinglong Mee 	rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
20722282cd2cSKinglong Mee 
20732282cd2cSKinglong Mee 	return (op_encode_hdr_size +
20742282cd2cSKinglong Mee 		1 /* gd_layout_type*/ +
20752282cd2cSKinglong Mee 		XDR_QUADLEN(rlen) +
20762282cd2cSKinglong Mee 		2 /* gd_notify_types */) * sizeof(__be32);
20772282cd2cSKinglong Mee }
20782282cd2cSKinglong Mee 
20799cf514ccSChristoph Hellwig /*
20809cf514ccSChristoph Hellwig  * At this stage we don't really know what layout driver will handle the request,
20819cf514ccSChristoph Hellwig  * so we need to define an arbitrary upper bound here.
20829cf514ccSChristoph Hellwig  */
20839cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE		128
20849cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
20859cf514ccSChristoph Hellwig {
20869cf514ccSChristoph Hellwig 	return (op_encode_hdr_size +
20879cf514ccSChristoph Hellwig 		1 /* logr_return_on_close */ +
20889cf514ccSChristoph Hellwig 		op_encode_stateid_maxsz +
20899cf514ccSChristoph Hellwig 		1 /* nr of layouts */ +
20909cf514ccSChristoph Hellwig 		MAX_LAYOUT_SIZE) * sizeof(__be32);
20919cf514ccSChristoph Hellwig }
20929cf514ccSChristoph Hellwig 
20939cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
20949cf514ccSChristoph Hellwig {
20959cf514ccSChristoph Hellwig 	return (op_encode_hdr_size +
20969cf514ccSChristoph Hellwig 		1 /* locr_newsize */ +
20979cf514ccSChristoph Hellwig 		2 /* ns_size */) * sizeof(__be32);
20989cf514ccSChristoph Hellwig }
20999cf514ccSChristoph Hellwig 
21009cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
21019cf514ccSChristoph Hellwig {
21029cf514ccSChristoph Hellwig 	return (op_encode_hdr_size +
21039cf514ccSChristoph Hellwig 		1 /* lrs_stateid */ +
21049cf514ccSChristoph Hellwig 		op_encode_stateid_maxsz) * sizeof(__be32);
21059cf514ccSChristoph Hellwig }
21069cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */
21079cf514ccSChristoph Hellwig 
21082282cd2cSKinglong Mee 
21092282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
21102282cd2cSKinglong Mee {
21112282cd2cSKinglong Mee 	return (op_encode_hdr_size + 3) * sizeof(__be32);
21122282cd2cSKinglong Mee }
21132282cd2cSKinglong Mee 
2114bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = {
2115b591480bSJ.Bruce Fields 	[OP_ACCESS] = {
2116eb69853dSChristoph Hellwig 		.op_func = nfsd4_access,
2117b001a1b6SBenny Halevy 		.op_name = "OP_ACCESS",
21181c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_access_rsize,
2119b591480bSJ.Bruce Fields 	},
2120b591480bSJ.Bruce Fields 	[OP_CLOSE] = {
2121eb69853dSChristoph Hellwig 		.op_func = nfsd4_close,
212258e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2123b001a1b6SBenny Halevy 		.op_name = "OP_CLOSE",
21241c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
212557832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_closestateid,
2126b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_closestateid,
2127b591480bSJ.Bruce Fields 	},
2128b591480bSJ.Bruce Fields 	[OP_COMMIT] = {
2129eb69853dSChristoph Hellwig 		.op_func = nfsd4_commit,
213058e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2131b001a1b6SBenny Halevy 		.op_name = "OP_COMMIT",
21321c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_commit_rsize,
2133b591480bSJ.Bruce Fields 	},
2134b591480bSJ.Bruce Fields 	[OP_CREATE] = {
2135eb69853dSChristoph Hellwig 		.op_func = nfsd4_create,
2136d1471053STigran Mkrtchyan 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
2137b001a1b6SBenny Halevy 		.op_name = "OP_CREATE",
21381c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_create_rsize,
2139b591480bSJ.Bruce Fields 	},
2140b591480bSJ.Bruce Fields 	[OP_DELEGRETURN] = {
2141eb69853dSChristoph Hellwig 		.op_func = nfsd4_delegreturn,
214258e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2143b001a1b6SBenny Halevy 		.op_name = "OP_DELEGRETURN",
214458e7b33aSMi Jinlong 		.op_rsize_bop = nfsd4_only_status_rsize,
214557832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_delegreturnstateid,
2146b591480bSJ.Bruce Fields 	},
2147b591480bSJ.Bruce Fields 	[OP_GETATTR] = {
2148eb69853dSChristoph Hellwig 		.op_func = nfsd4_getattr,
2149eeac294eSJ.Bruce Fields 		.op_flags = ALLOWED_ON_ABSENT_FS,
2150b86cef60SJ. Bruce Fields 		.op_rsize_bop = nfsd4_getattr_rsize,
2151b001a1b6SBenny Halevy 		.op_name = "OP_GETATTR",
2152b591480bSJ.Bruce Fields 	},
2153b591480bSJ.Bruce Fields 	[OP_GETFH] = {
2154eb69853dSChristoph Hellwig 		.op_func = nfsd4_getfh,
2155b001a1b6SBenny Halevy 		.op_name = "OP_GETFH",
21561c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_getfh_rsize,
2157b591480bSJ.Bruce Fields 	},
2158b591480bSJ.Bruce Fields 	[OP_LINK] = {
2159eb69853dSChristoph Hellwig 		.op_func = nfsd4_link,
2160c856694eSJ. Bruce Fields 		.op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
2161c856694eSJ. Bruce Fields 				| OP_CACHEME,
2162b001a1b6SBenny Halevy 		.op_name = "OP_LINK",
21631c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_link_rsize,
2164b591480bSJ.Bruce Fields 	},
2165b591480bSJ.Bruce Fields 	[OP_LOCK] = {
2166eb69853dSChristoph Hellwig 		.op_func = nfsd4_lock,
2167b7571e4cSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING |
2168b7571e4cSJ. Bruce Fields 				OP_NONTRIVIAL_ERROR_ENCODE,
2169b001a1b6SBenny Halevy 		.op_name = "OP_LOCK",
21701c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_lock_rsize,
2171b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_lockstateid,
2172b591480bSJ.Bruce Fields 	},
2173b591480bSJ.Bruce Fields 	[OP_LOCKT] = {
2174eb69853dSChristoph Hellwig 		.op_func = nfsd4_lockt,
2175b7571e4cSJ. Bruce Fields 		.op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
2176b001a1b6SBenny Halevy 		.op_name = "OP_LOCKT",
21771c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_lock_rsize,
2178b591480bSJ.Bruce Fields 	},
2179b591480bSJ.Bruce Fields 	[OP_LOCKU] = {
2180eb69853dSChristoph Hellwig 		.op_func = nfsd4_locku,
218158e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2182b001a1b6SBenny Halevy 		.op_name = "OP_LOCKU",
21831c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
218457832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_lockustateid,
2185b591480bSJ.Bruce Fields 	},
2186b591480bSJ.Bruce Fields 	[OP_LOOKUP] = {
2187eb69853dSChristoph Hellwig 		.op_func = nfsd4_lookup,
2188d1471053STigran Mkrtchyan 		.op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
2189b001a1b6SBenny Halevy 		.op_name = "OP_LOOKUP",
21901c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2191b591480bSJ.Bruce Fields 	},
2192b591480bSJ.Bruce Fields 	[OP_LOOKUPP] = {
2193eb69853dSChristoph Hellwig 		.op_func = nfsd4_lookupp,
2194d1471053STigran Mkrtchyan 		.op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
2195b001a1b6SBenny Halevy 		.op_name = "OP_LOOKUPP",
21961c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2197b591480bSJ.Bruce Fields 	},
2198b591480bSJ.Bruce Fields 	[OP_NVERIFY] = {
2199eb69853dSChristoph Hellwig 		.op_func = nfsd4_nverify,
2200b001a1b6SBenny Halevy 		.op_name = "OP_NVERIFY",
22011c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2202b591480bSJ.Bruce Fields 	},
2203b591480bSJ.Bruce Fields 	[OP_OPEN] = {
2204eb69853dSChristoph Hellwig 		.op_func = nfsd4_open,
220558e7b33aSMi Jinlong 		.op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
2206b001a1b6SBenny Halevy 		.op_name = "OP_OPEN",
22071c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_open_rsize,
2208b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_openstateid,
2209b591480bSJ.Bruce Fields 	},
2210b591480bSJ.Bruce Fields 	[OP_OPEN_CONFIRM] = {
2211eb69853dSChristoph Hellwig 		.op_func = nfsd4_open_confirm,
221258e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2213b001a1b6SBenny Halevy 		.op_name = "OP_OPEN_CONFIRM",
22141c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
2215b591480bSJ.Bruce Fields 	},
2216b591480bSJ.Bruce Fields 	[OP_OPEN_DOWNGRADE] = {
2217eb69853dSChristoph Hellwig 		.op_func = nfsd4_open_downgrade,
221858e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2219b001a1b6SBenny Halevy 		.op_name = "OP_OPEN_DOWNGRADE",
22201c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
222157832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_opendowngradestateid,
2222b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_opendowngradestateid,
2223b591480bSJ.Bruce Fields 	},
2224b591480bSJ.Bruce Fields 	[OP_PUTFH] = {
2225eb69853dSChristoph Hellwig 		.op_func = nfsd4_putfh,
222668d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
22275b648699SJ. Bruce Fields 				| OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
2228b001a1b6SBenny Halevy 		.op_name = "OP_PUTFH",
22291c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2230b591480bSJ.Bruce Fields 	},
2231eeac294eSJ.Bruce Fields 	[OP_PUTPUBFH] = {
2232eb69853dSChristoph Hellwig 		.op_func = nfsd4_putrootfh,
223368d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
22345b648699SJ. Bruce Fields 				| OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
2235b001a1b6SBenny Halevy 		.op_name = "OP_PUTPUBFH",
22361c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2237eeac294eSJ.Bruce Fields 	},
2238b591480bSJ.Bruce Fields 	[OP_PUTROOTFH] = {
2239eb69853dSChristoph Hellwig 		.op_func = nfsd4_putrootfh,
224068d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
22415b648699SJ. Bruce Fields 				| OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
2242b001a1b6SBenny Halevy 		.op_name = "OP_PUTROOTFH",
22431c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2244b591480bSJ.Bruce Fields 	},
2245b591480bSJ.Bruce Fields 	[OP_READ] = {
2246eb69853dSChristoph Hellwig 		.op_func = nfsd4_read,
224734b1744cSJ. Bruce Fields 		.op_release = nfsd4_read_release,
2248b001a1b6SBenny Halevy 		.op_name = "OP_READ",
22491c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_read_rsize,
225057832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_readstateid,
2251b591480bSJ.Bruce Fields 	},
2252b591480bSJ.Bruce Fields 	[OP_READDIR] = {
2253eb69853dSChristoph Hellwig 		.op_func = nfsd4_readdir,
2254b001a1b6SBenny Halevy 		.op_name = "OP_READDIR",
22551c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_readdir_rsize,
2256b591480bSJ.Bruce Fields 	},
2257b591480bSJ.Bruce Fields 	[OP_READLINK] = {
2258eb69853dSChristoph Hellwig 		.op_func = nfsd4_readlink,
2259b001a1b6SBenny Halevy 		.op_name = "OP_READLINK",
22601c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_readlink_rsize,
2261b591480bSJ.Bruce Fields 	},
2262b591480bSJ.Bruce Fields 	[OP_REMOVE] = {
2263eb69853dSChristoph Hellwig 		.op_func = nfsd4_remove,
2264c856694eSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2265b001a1b6SBenny Halevy 		.op_name = "OP_REMOVE",
22661c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_remove_rsize,
2267b591480bSJ.Bruce Fields 	},
2268b591480bSJ.Bruce Fields 	[OP_RENAME] = {
2269eb69853dSChristoph Hellwig 		.op_func = nfsd4_rename,
2270c856694eSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
227158e7b33aSMi Jinlong 		.op_name = "OP_RENAME",
22721c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_rename_rsize,
2273b591480bSJ.Bruce Fields 	},
2274b591480bSJ.Bruce Fields 	[OP_RENEW] = {
2275eb69853dSChristoph Hellwig 		.op_func = nfsd4_renew,
227658e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
227758e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2278b001a1b6SBenny Halevy 		.op_name = "OP_RENEW",
22791c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
228058e7b33aSMi Jinlong 
2281b591480bSJ.Bruce Fields 	},
2282b591480bSJ.Bruce Fields 	[OP_RESTOREFH] = {
2283eb69853dSChristoph Hellwig 		.op_func = nfsd4_restorefh,
228468d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
228558e7b33aSMi Jinlong 				| OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
2286b001a1b6SBenny Halevy 		.op_name = "OP_RESTOREFH",
22871c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2288b591480bSJ.Bruce Fields 	},
2289b591480bSJ.Bruce Fields 	[OP_SAVEFH] = {
2290eb69853dSChristoph Hellwig 		.op_func = nfsd4_savefh,
229158e7b33aSMi Jinlong 		.op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
2292b001a1b6SBenny Halevy 		.op_name = "OP_SAVEFH",
22931c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2294b591480bSJ.Bruce Fields 	},
2295dcb488a3SAndy Adamson 	[OP_SECINFO] = {
2296eb69853dSChristoph Hellwig 		.op_func = nfsd4_secinfo,
229734b1744cSJ. Bruce Fields 		.op_release = nfsd4_secinfo_release,
229868d93184SJ. Bruce Fields 		.op_flags = OP_HANDLES_WRONGSEC,
2299b001a1b6SBenny Halevy 		.op_name = "OP_SECINFO",
23001c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_secinfo_rsize,
2301dcb488a3SAndy Adamson 	},
2302b591480bSJ.Bruce Fields 	[OP_SETATTR] = {
2303eb69853dSChristoph Hellwig 		.op_func = nfsd4_setattr,
2304b001a1b6SBenny Halevy 		.op_name = "OP_SETATTR",
2305b7571e4cSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
2306b7571e4cSJ. Bruce Fields 				| OP_NONTRIVIAL_ERROR_ENCODE,
23071c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_setattr_rsize,
230857832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_setattrstateid,
2309b591480bSJ.Bruce Fields 	},
2310b591480bSJ.Bruce Fields 	[OP_SETCLIENTID] = {
2311eb69853dSChristoph Hellwig 		.op_func = nfsd4_setclientid,
231258e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
2313b7571e4cSJ. Bruce Fields 				| OP_MODIFIES_SOMETHING | OP_CACHEME
2314b7571e4cSJ. Bruce Fields 				| OP_NONTRIVIAL_ERROR_ENCODE,
2315b001a1b6SBenny Halevy 		.op_name = "OP_SETCLIENTID",
23161c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_setclientid_rsize,
2317b591480bSJ.Bruce Fields 	},
2318b591480bSJ.Bruce Fields 	[OP_SETCLIENTID_CONFIRM] = {
2319eb69853dSChristoph Hellwig 		.op_func = nfsd4_setclientid_confirm,
232058e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
2321c856694eSJ. Bruce Fields 				| OP_MODIFIES_SOMETHING | OP_CACHEME,
2322b001a1b6SBenny Halevy 		.op_name = "OP_SETCLIENTID_CONFIRM",
23231c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2324b591480bSJ.Bruce Fields 	},
2325b591480bSJ.Bruce Fields 	[OP_VERIFY] = {
2326eb69853dSChristoph Hellwig 		.op_func = nfsd4_verify,
2327b001a1b6SBenny Halevy 		.op_name = "OP_VERIFY",
23281c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2329b591480bSJ.Bruce Fields 	},
2330b591480bSJ.Bruce Fields 	[OP_WRITE] = {
2331eb69853dSChristoph Hellwig 		.op_func = nfsd4_write,
2332c856694eSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2333b001a1b6SBenny Halevy 		.op_name = "OP_WRITE",
23341c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_write_rsize,
233557832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_writestateid,
2336b591480bSJ.Bruce Fields 	},
2337b591480bSJ.Bruce Fields 	[OP_RELEASE_LOCKOWNER] = {
2338eb69853dSChristoph Hellwig 		.op_func = nfsd4_release_lockowner,
233958e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
234058e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2341b001a1b6SBenny Halevy 		.op_name = "OP_RELEASE_LOCKOWNER",
23421c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2343b591480bSJ.Bruce Fields 	},
2344069b6ad4SAndy Adamson 
2345069b6ad4SAndy Adamson 	/* NFSv4.1 operations */
2346069b6ad4SAndy Adamson 	[OP_EXCHANGE_ID] = {
2347eb69853dSChristoph Hellwig 		.op_func = nfsd4_exchange_id,
234858e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
234958e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2350069b6ad4SAndy Adamson 		.op_name = "OP_EXCHANGE_ID",
23511c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_exchange_id_rsize,
2352069b6ad4SAndy Adamson 	},
2353cb73a9f4SJ. Bruce Fields 	[OP_BACKCHANNEL_CTL] = {
2354eb69853dSChristoph Hellwig 		.op_func = nfsd4_backchannel_ctl,
2355cb73a9f4SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
2356cb73a9f4SJ. Bruce Fields 		.op_name = "OP_BACKCHANNEL_CTL",
23571c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2358cb73a9f4SJ. Bruce Fields 	},
23591d1bc8f2SJ. Bruce Fields 	[OP_BIND_CONN_TO_SESSION] = {
2360eb69853dSChristoph Hellwig 		.op_func = nfsd4_bind_conn_to_session,
236158e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
236258e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
23631d1bc8f2SJ. Bruce Fields 		.op_name = "OP_BIND_CONN_TO_SESSION",
23641c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
23651d1bc8f2SJ. Bruce Fields 	},
2366069b6ad4SAndy Adamson 	[OP_CREATE_SESSION] = {
2367eb69853dSChristoph Hellwig 		.op_func = nfsd4_create_session,
236858e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
236958e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2370069b6ad4SAndy Adamson 		.op_name = "OP_CREATE_SESSION",
23711c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_create_session_rsize,
2372069b6ad4SAndy Adamson 	},
2373069b6ad4SAndy Adamson 	[OP_DESTROY_SESSION] = {
2374eb69853dSChristoph Hellwig 		.op_func = nfsd4_destroy_session,
237558e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
237658e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2377069b6ad4SAndy Adamson 		.op_name = "OP_DESTROY_SESSION",
23781c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2379069b6ad4SAndy Adamson 	},
2380069b6ad4SAndy Adamson 	[OP_SEQUENCE] = {
2381eb69853dSChristoph Hellwig 		.op_func = nfsd4_sequence,
2382f9bb94c4SAndy Adamson 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
2383069b6ad4SAndy Adamson 		.op_name = "OP_SEQUENCE",
23841c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_sequence_rsize,
2385069b6ad4SAndy Adamson 	},
2386094b5d74SBenny Halevy 	[OP_DESTROY_CLIENTID] = {
2387eb69853dSChristoph Hellwig 		.op_func = nfsd4_destroy_clientid,
238858e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
238958e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2390094b5d74SBenny Halevy 		.op_name = "OP_DESTROY_CLIENTID",
23911c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2392094b5d74SBenny Halevy 	},
23934dc6ec00SJ. Bruce Fields 	[OP_RECLAIM_COMPLETE] = {
2394eb69853dSChristoph Hellwig 		.op_func = nfsd4_reclaim_complete,
239558e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
23964dc6ec00SJ. Bruce Fields 		.op_name = "OP_RECLAIM_COMPLETE",
23971c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
23984dc6ec00SJ. Bruce Fields 	},
239904f4ad16SJ. Bruce Fields 	[OP_SECINFO_NO_NAME] = {
2400eb69853dSChristoph Hellwig 		.op_func = nfsd4_secinfo_no_name,
2401ec572b9eSEryu Guan 		.op_release = nfsd4_secinfo_no_name_release,
240268d93184SJ. Bruce Fields 		.op_flags = OP_HANDLES_WRONGSEC,
240304f4ad16SJ. Bruce Fields 		.op_name = "OP_SECINFO_NO_NAME",
24041c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_secinfo_rsize,
240504f4ad16SJ. Bruce Fields 	},
240617456804SBryan Schumaker 	[OP_TEST_STATEID] = {
2407eb69853dSChristoph Hellwig 		.op_func = nfsd4_test_stateid,
240817456804SBryan Schumaker 		.op_flags = ALLOWED_WITHOUT_FH,
240917456804SBryan Schumaker 		.op_name = "OP_TEST_STATEID",
24101c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_test_stateid_rsize,
241117456804SBryan Schumaker 	},
2412e1ca12dfSBryan Schumaker 	[OP_FREE_STATEID] = {
2413eb69853dSChristoph Hellwig 		.op_func = nfsd4_free_stateid,
241458e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
2415e1ca12dfSBryan Schumaker 		.op_name = "OP_FREE_STATEID",
241657832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_freestateid,
24171c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2418e1ca12dfSBryan Schumaker 	},
24199cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
24209cf514ccSChristoph Hellwig 	[OP_GETDEVICEINFO] = {
2421eb69853dSChristoph Hellwig 		.op_func = nfsd4_getdeviceinfo,
242234b1744cSJ. Bruce Fields 		.op_release = nfsd4_getdeviceinfo_release,
24239cf514ccSChristoph Hellwig 		.op_flags = ALLOWED_WITHOUT_FH,
24249cf514ccSChristoph Hellwig 		.op_name = "OP_GETDEVICEINFO",
24251c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_getdeviceinfo_rsize,
24269cf514ccSChristoph Hellwig 	},
24279cf514ccSChristoph Hellwig 	[OP_LAYOUTGET] = {
2428eb69853dSChristoph Hellwig 		.op_func = nfsd4_layoutget,
242934b1744cSJ. Bruce Fields 		.op_release = nfsd4_layoutget_release,
24309cf514ccSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING,
24319cf514ccSChristoph Hellwig 		.op_name = "OP_LAYOUTGET",
24321c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_layoutget_rsize,
24339cf514ccSChristoph Hellwig 	},
24349cf514ccSChristoph Hellwig 	[OP_LAYOUTCOMMIT] = {
2435eb69853dSChristoph Hellwig 		.op_func = nfsd4_layoutcommit,
24369cf514ccSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING,
24379cf514ccSChristoph Hellwig 		.op_name = "OP_LAYOUTCOMMIT",
24381c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_layoutcommit_rsize,
24399cf514ccSChristoph Hellwig 	},
24409cf514ccSChristoph Hellwig 	[OP_LAYOUTRETURN] = {
2441eb69853dSChristoph Hellwig 		.op_func = nfsd4_layoutreturn,
24429cf514ccSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING,
24439cf514ccSChristoph Hellwig 		.op_name = "OP_LAYOUTRETURN",
24441c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_layoutreturn_rsize,
24459cf514ccSChristoph Hellwig 	},
24469cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */
244724bab491SAnna Schumaker 
244824bab491SAnna Schumaker 	/* NFSv4.2 operations */
244995d871f0SAnna Schumaker 	[OP_ALLOCATE] = {
2450eb69853dSChristoph Hellwig 		.op_func = nfsd4_allocate,
245195d871f0SAnna Schumaker 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
245295d871f0SAnna Schumaker 		.op_name = "OP_ALLOCATE",
24531c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
245495d871f0SAnna Schumaker 	},
2455b0cb9085SAnna Schumaker 	[OP_DEALLOCATE] = {
2456eb69853dSChristoph Hellwig 		.op_func = nfsd4_deallocate,
2457b0cb9085SAnna Schumaker 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2458b0cb9085SAnna Schumaker 		.op_name = "OP_DEALLOCATE",
24591c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2460b0cb9085SAnna Schumaker 	},
2461ffa0160aSChristoph Hellwig 	[OP_CLONE] = {
2462eb69853dSChristoph Hellwig 		.op_func = nfsd4_clone,
2463ffa0160aSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2464ffa0160aSChristoph Hellwig 		.op_name = "OP_CLONE",
24651c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2466ffa0160aSChristoph Hellwig 	},
246729ae7f9dSAnna Schumaker 	[OP_COPY] = {
2468eb69853dSChristoph Hellwig 		.op_func = nfsd4_copy,
246929ae7f9dSAnna Schumaker 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
247029ae7f9dSAnna Schumaker 		.op_name = "OP_COPY",
24711c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_copy_rsize,
247229ae7f9dSAnna Schumaker 	},
247324bab491SAnna Schumaker 	[OP_SEEK] = {
2474eb69853dSChristoph Hellwig 		.op_func = nfsd4_seek,
247524bab491SAnna Schumaker 		.op_name = "OP_SEEK",
24761c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_seek_rsize,
247724bab491SAnna Schumaker 	},
2478*6308bc98SOlga Kornievskaia 	[OP_OFFLOAD_STATUS] = {
2479*6308bc98SOlga Kornievskaia 		.op_func = nfsd4_offload_status,
2480*6308bc98SOlga Kornievskaia 		.op_name = "OP_OFFLOAD_STATUS",
2481*6308bc98SOlga Kornievskaia 		.op_rsize_bop = nfsd4_offload_status_rsize,
2482*6308bc98SOlga Kornievskaia 	},
2483b591480bSJ.Bruce Fields };
2484b591480bSJ.Bruce Fields 
2485ed941643SAndrew Elble /**
2486ed941643SAndrew Elble  * nfsd4_spo_must_allow - Determine if the compound op contains an
2487ed941643SAndrew Elble  * operation that is allowed to be sent with machine credentials
2488ed941643SAndrew Elble  *
2489ed941643SAndrew Elble  * @rqstp: a pointer to the struct svc_rqst
2490ed941643SAndrew Elble  *
2491ed941643SAndrew Elble  * Checks to see if the compound contains a spo_must_allow op
2492ed941643SAndrew Elble  * and confirms that it was sent with the proper machine creds.
2493ed941643SAndrew Elble  */
2494ed941643SAndrew Elble 
2495ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
2496ed941643SAndrew Elble {
2497ed941643SAndrew Elble 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
2498ed941643SAndrew Elble 	struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2499ed941643SAndrew Elble 	struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2500ed941643SAndrew Elble 	struct nfsd4_compound_state *cstate = &resp->cstate;
2501ed941643SAndrew Elble 	struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
2502ed941643SAndrew Elble 	u32 opiter;
2503ed941643SAndrew Elble 
2504ed941643SAndrew Elble 	if (!cstate->minorversion)
2505ed941643SAndrew Elble 		return false;
2506ed941643SAndrew Elble 
2507ed941643SAndrew Elble 	if (cstate->spo_must_allowed == true)
2508ed941643SAndrew Elble 		return true;
2509ed941643SAndrew Elble 
2510ed941643SAndrew Elble 	opiter = resp->opcnt;
2511ed941643SAndrew Elble 	while (opiter < argp->opcnt) {
2512ed941643SAndrew Elble 		this = &argp->ops[opiter++];
2513ed941643SAndrew Elble 		if (test_bit(this->opnum, allow->u.longs) &&
2514ed941643SAndrew Elble 			cstate->clp->cl_mach_cred &&
2515ed941643SAndrew Elble 			nfsd4_mach_creds_match(cstate->clp, rqstp)) {
2516ed941643SAndrew Elble 			cstate->spo_must_allowed = true;
2517ed941643SAndrew Elble 			return true;
2518ed941643SAndrew Elble 		}
2519ed941643SAndrew Elble 	}
2520ed941643SAndrew Elble 	cstate->spo_must_allowed = false;
2521ed941643SAndrew Elble 	return false;
2522ed941643SAndrew Elble }
2523ed941643SAndrew Elble 
25244f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
25254f0cefbfSJ. Bruce Fields {
252605b7278dSOlga Kornievskaia 	if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
25274f0cefbfSJ. Bruce Fields 		return op_encode_hdr_size * sizeof(__be32);
25282282cd2cSKinglong Mee 
25292282cd2cSKinglong Mee 	BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
25302282cd2cSKinglong Mee 	return OPDESC(op)->op_rsize_bop(rqstp, op);
25314f0cefbfSJ. Bruce Fields }
25324f0cefbfSJ. Bruce Fields 
253307d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op)
253407d1f802SJ. Bruce Fields {
253507d1f802SJ. Bruce Fields 	if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
253607d1f802SJ. Bruce Fields 		pr_err("unable to encode reply to nonidempotent op %d (%s)\n",
253707d1f802SJ. Bruce Fields 			op->opnum, nfsd4_op_name(op->opnum));
253807d1f802SJ. Bruce Fields 		WARN_ON_ONCE(1);
253907d1f802SJ. Bruce Fields 	}
254007d1f802SJ. Bruce Fields }
254107d1f802SJ. Bruce Fields 
2542f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum)
2543b001a1b6SBenny Halevy {
2544b001a1b6SBenny Halevy 	if (opnum < ARRAY_SIZE(nfsd4_ops))
2545b001a1b6SBenny Halevy 		return nfsd4_ops[opnum].op_name;
2546b001a1b6SBenny Halevy 	return "unknown_operation";
2547b001a1b6SBenny Halevy }
2548b001a1b6SBenny Halevy 
25491da177e4SLinus Torvalds #define nfsd4_voidres			nfsd4_voidargs
25501da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; };
25511da177e4SLinus Torvalds 
2552860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = {
25530a93a47fSYu Zhiguo 	[NFSPROC4_NULL] = {
2554f7235b6bSChristoph Hellwig 		.pc_func = nfsd4_proc_null,
255563f8de37SChristoph Hellwig 		.pc_encode = nfs4svc_encode_voidres,
25560a93a47fSYu Zhiguo 		.pc_argsize = sizeof(struct nfsd4_voidargs),
25570a93a47fSYu Zhiguo 		.pc_ressize = sizeof(struct nfsd4_voidres),
25580a93a47fSYu Zhiguo 		.pc_cachetype = RC_NOCACHE,
25590a93a47fSYu Zhiguo 		.pc_xdrressize = 1,
25600a93a47fSYu Zhiguo 	},
25610a93a47fSYu Zhiguo 	[NFSPROC4_COMPOUND] = {
2562f7235b6bSChristoph Hellwig 		.pc_func = nfsd4_proc_compound,
2563026fec7eSChristoph Hellwig 		.pc_decode = nfs4svc_decode_compoundargs,
256463f8de37SChristoph Hellwig 		.pc_encode = nfs4svc_encode_compoundres,
25650a93a47fSYu Zhiguo 		.pc_argsize = sizeof(struct nfsd4_compoundargs),
25660a93a47fSYu Zhiguo 		.pc_ressize = sizeof(struct nfsd4_compoundres),
25673e98abffSJ. Bruce Fields 		.pc_release = nfsd4_release_compoundargs,
25680a93a47fSYu Zhiguo 		.pc_cachetype = RC_NOCACHE,
25690a93a47fSYu Zhiguo 		.pc_xdrressize = NFSD_BUFSIZE/4,
25700a93a47fSYu Zhiguo 	},
25711da177e4SLinus Torvalds };
25721da177e4SLinus Torvalds 
25737fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
2574e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = {
25751da177e4SLinus Torvalds 	.vs_vers		= 4,
25761da177e4SLinus Torvalds 	.vs_nproc		= 2,
25771da177e4SLinus Torvalds 	.vs_proc		= nfsd_procedures4,
25787fd38af9SChristoph Hellwig 	.vs_count		= nfsd_count3,
25791da177e4SLinus Torvalds 	.vs_dispatch		= nfsd_dispatch,
25801da177e4SLinus Torvalds 	.vs_xdrsize		= NFS4_SVC_XDRSIZE,
258105a45a2dSJeff Layton 	.vs_rpcb_optnl		= true,
25825283b03eSJeff Layton 	.vs_need_cong_ctrl	= true,
25831da177e4SLinus Torvalds };
25841da177e4SLinus Torvalds 
25851da177e4SLinus Torvalds /*
25861da177e4SLinus Torvalds  * Local variables:
25871da177e4SLinus Torvalds  *  c-basic-offset: 8
25881da177e4SLinus Torvalds  * End:
25891da177e4SLinus Torvalds  */
2590