xref: /openbmc/linux/fs/nfsd/nfs4proc.c (revision e333f3bbefe3e25e2bcff58063f920a2eaba224b)
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>
39e0639dc5SOlga Kornievskaia #include <linux/kthread.h>
401da177e4SLinus Torvalds 
4158e7b33aSMi Jinlong #include "idmap.h"
429a74af21SBoaz Harrosh #include "cache.h"
439a74af21SBoaz Harrosh #include "xdr4.h"
440a3adadeSJ. Bruce Fields #include "vfs.h"
458b70484cSTigran Mkrtchyan #include "current_stateid.h"
463320fef1SStanislav Kinsbursky #include "netns.h"
474ac7249eSChristoph Hellwig #include "acl.h"
489cf514ccSChristoph Hellwig #include "pnfs.h"
4931ef83dcSChristoph Hellwig #include "trace.h"
501da177e4SLinus Torvalds 
5118032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
5218032ca0SDavid Quigley #include <linux/security.h>
5318032ca0SDavid Quigley 
5418032ca0SDavid Quigley static inline void
5518032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
5618032ca0SDavid Quigley {
572b0143b5SDavid Howells 	struct inode *inode = d_inode(resfh->fh_dentry);
5818032ca0SDavid Quigley 	int status;
5918032ca0SDavid Quigley 
605955102cSAl Viro 	inode_lock(inode);
6118032ca0SDavid Quigley 	status = security_inode_setsecctx(resfh->fh_dentry,
6218032ca0SDavid Quigley 		label->data, label->len);
635955102cSAl Viro 	inode_unlock(inode);
6418032ca0SDavid Quigley 
6518032ca0SDavid Quigley 	if (status)
6618032ca0SDavid Quigley 		/*
6718032ca0SDavid Quigley 		 * XXX: We should really fail the whole open, but we may
6818032ca0SDavid Quigley 		 * already have created a new file, so it may be too
6918032ca0SDavid Quigley 		 * late.  For now this seems the least of evils:
7018032ca0SDavid Quigley 		 */
7118032ca0SDavid Quigley 		bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
7218032ca0SDavid Quigley 
7318032ca0SDavid Quigley 	return;
7418032ca0SDavid Quigley }
7518032ca0SDavid Quigley #else
7618032ca0SDavid Quigley static inline void
7718032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
7818032ca0SDavid Quigley { }
7918032ca0SDavid Quigley #endif
8018032ca0SDavid Quigley 
811da177e4SLinus Torvalds #define NFSDDBG_FACILITY		NFSDDBG_PROC
821da177e4SLinus Torvalds 
833c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = {
843c8e0316SYu Zhiguo 	NFSD_WRITEABLE_ATTRS_WORD0,
853c8e0316SYu Zhiguo 	NFSD_WRITEABLE_ATTRS_WORD1,
863c8e0316SYu Zhiguo 	NFSD_WRITEABLE_ATTRS_WORD2
873c8e0316SYu Zhiguo };
883c8e0316SYu Zhiguo 
893c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = {
903c8e0316SYu Zhiguo 	NFSD_SUPPATTR_EXCLCREAT_WORD0,
913c8e0316SYu Zhiguo 	NFSD_SUPPATTR_EXCLCREAT_WORD1,
923c8e0316SYu Zhiguo 	NFSD_SUPPATTR_EXCLCREAT_WORD2
933c8e0316SYu Zhiguo };
943c8e0316SYu Zhiguo 
953c8e0316SYu Zhiguo static __be32
963c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
973c8e0316SYu Zhiguo 		   u32 *bmval, u32 *writable)
983c8e0316SYu Zhiguo {
993c8e0316SYu Zhiguo 	struct dentry *dentry = cstate->current_fh.fh_dentry;
10032ddd944SJ. Bruce Fields 	struct svc_export *exp = cstate->current_fh.fh_export;
1013c8e0316SYu Zhiguo 
102916d2d84SJ. Bruce Fields 	if (!nfsd_attrs_supported(cstate->minorversion, bmval))
1033c8e0316SYu Zhiguo 		return nfserr_attrnotsupp;
104916d2d84SJ. Bruce Fields 	if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
1053c8e0316SYu Zhiguo 		return nfserr_attrnotsupp;
10632ddd944SJ. Bruce Fields 	if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
10732ddd944SJ. Bruce Fields 			!(exp->ex_flags & NFSEXP_SECURITY_LABEL))
10832ddd944SJ. Bruce Fields 		return nfserr_attrnotsupp;
109916d2d84SJ. Bruce Fields 	if (writable && !bmval_is_subset(bmval, writable))
1103c8e0316SYu Zhiguo 		return nfserr_inval;
11147057abdSAndreas Gruenbacher 	if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
11247057abdSAndreas Gruenbacher 			(bmval[1] & FATTR4_WORD1_MODE))
11347057abdSAndreas Gruenbacher 		return nfserr_inval;
1143c8e0316SYu Zhiguo 	return nfs_ok;
1153c8e0316SYu Zhiguo }
1163c8e0316SYu Zhiguo 
1173c8e0316SYu Zhiguo static __be32
1183c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp,
1193c8e0316SYu Zhiguo 	struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
1203c8e0316SYu Zhiguo {
1213c8e0316SYu Zhiguo 	__be32 status = nfs_ok;
1223c8e0316SYu Zhiguo 
1233c8e0316SYu Zhiguo 	if (open->op_create == NFS4_OPEN_CREATE) {
1243c8e0316SYu Zhiguo 		if (open->op_createmode == NFS4_CREATE_UNCHECKED
1253c8e0316SYu Zhiguo 		    || open->op_createmode == NFS4_CREATE_GUARDED)
1263c8e0316SYu Zhiguo 			status = check_attr_support(rqstp, cstate,
1273c8e0316SYu Zhiguo 					open->op_bmval, nfsd_attrmask);
1283c8e0316SYu Zhiguo 		else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
1293c8e0316SYu Zhiguo 			status = check_attr_support(rqstp, cstate,
1303c8e0316SYu Zhiguo 					open->op_bmval, nfsd41_ex_attrmask);
1313c8e0316SYu Zhiguo 	}
1323c8e0316SYu Zhiguo 
1333c8e0316SYu Zhiguo 	return status;
1343c8e0316SYu Zhiguo }
1353c8e0316SYu Zhiguo 
1369208faf2SYu Zhiguo static int
1379208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open)
1389208faf2SYu Zhiguo {
1399208faf2SYu Zhiguo 	return open->op_create == NFS4_OPEN_CREATE
1409208faf2SYu Zhiguo 		&& (open->op_createmode == NFS4_CREATE_UNCHECKED
1419208faf2SYu Zhiguo 		    || open->op_createmode == NFS4_CREATE_GUARDED
1429208faf2SYu Zhiguo 		    || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
1439208faf2SYu Zhiguo }
1449208faf2SYu Zhiguo 
1459208faf2SYu Zhiguo /*
1469208faf2SYu Zhiguo  * if error occurs when setting the acl, just clear the acl bit
1479208faf2SYu Zhiguo  * in the returned attr bitmap.
1489208faf2SYu Zhiguo  */
1499208faf2SYu Zhiguo static void
1509208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
1519208faf2SYu Zhiguo 		struct nfs4_acl *acl, u32 *bmval)
1529208faf2SYu Zhiguo {
1539208faf2SYu Zhiguo 	__be32 status;
1549208faf2SYu Zhiguo 
1559208faf2SYu Zhiguo 	status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
1569208faf2SYu Zhiguo 	if (status)
1579208faf2SYu Zhiguo 		/*
1589208faf2SYu Zhiguo 		 * We should probably fail the whole open at this point,
1599208faf2SYu Zhiguo 		 * but we've already created the file, so it's too late;
1609208faf2SYu Zhiguo 		 * So this seems the least of evils:
1619208faf2SYu Zhiguo 		 */
1629208faf2SYu Zhiguo 		bmval[0] &= ~FATTR4_WORD0_ACL;
1639208faf2SYu Zhiguo }
1649208faf2SYu Zhiguo 
1651da177e4SLinus Torvalds static inline void
1661da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src)
1671da177e4SLinus Torvalds {
1681da177e4SLinus Torvalds 	fh_put(dst);
1691da177e4SLinus Torvalds 	dget(src->fh_dentry);
1701da177e4SLinus Torvalds 	if (src->fh_export)
171bf18f163SKinglong Mee 		exp_get(src->fh_export);
1721da177e4SLinus Torvalds 	*dst = *src;
1731da177e4SLinus Torvalds }
1741da177e4SLinus Torvalds 
175b37ad28bSAl Viro static __be32
176dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
1771da177e4SLinus Torvalds {
178b37ad28bSAl Viro 	__be32 status;
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds 	if (open->op_truncate &&
1811da177e4SLinus Torvalds 		!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
1821da177e4SLinus Torvalds 		return nfserr_inval;
1831da177e4SLinus Torvalds 
184a043226bSJ. Bruce Fields 	accmode |= NFSD_MAY_READ_IF_EXEC;
185a043226bSJ. Bruce Fields 
1861da177e4SLinus Torvalds 	if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
1878837abcaSMiklos Szeredi 		accmode |= NFSD_MAY_READ;
1889801d8a3SJ. Bruce Fields 	if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
1898837abcaSMiklos Szeredi 		accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
19057ecb34fSJ. Bruce Fields 	if (open->op_share_deny & NFS4_SHARE_DENY_READ)
1918837abcaSMiklos Szeredi 		accmode |= NFSD_MAY_WRITE;
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 	status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds 	return status;
1961da177e4SLinus Torvalds }
1971da177e4SLinus Torvalds 
198aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
199aadab6c6SJ. Bruce Fields {
2002b0143b5SDavid Howells 	umode_t mode = d_inode(fh->fh_dentry)->i_mode;
201aadab6c6SJ. Bruce Fields 
202aadab6c6SJ. Bruce Fields 	if (S_ISREG(mode))
203aadab6c6SJ. Bruce Fields 		return nfs_ok;
204aadab6c6SJ. Bruce Fields 	if (S_ISDIR(mode))
205aadab6c6SJ. Bruce Fields 		return nfserr_isdir;
206aadab6c6SJ. Bruce Fields 	/*
207aadab6c6SJ. Bruce Fields 	 * Using err_symlink as our catch-all case may look odd; but
208aadab6c6SJ. Bruce Fields 	 * there's no other obvious error for this case in 4.0, and we
209aadab6c6SJ. Bruce Fields 	 * happen to know that it will cause the linux v4 client to do
210aadab6c6SJ. Bruce Fields 	 * the right thing on attempts to open something other than a
211aadab6c6SJ. Bruce Fields 	 * regular file.
212aadab6c6SJ. Bruce Fields 	 */
213aadab6c6SJ. Bruce Fields 	return nfserr_symlink;
214aadab6c6SJ. Bruce Fields }
215aadab6c6SJ. Bruce Fields 
216bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
2171da177e4SLinus Torvalds {
218bbc9c36cSJ. Bruce Fields 	if (nfsd4_has_session(cstate))
219bbc9c36cSJ. Bruce Fields 		return;
220bbc9c36cSJ. Bruce Fields 	fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
221bbc9c36cSJ. Bruce Fields 			&resfh->fh_handle);
222bbc9c36cSJ. Bruce Fields }
223bbc9c36cSJ. Bruce Fields 
224bbc9c36cSJ. Bruce Fields static __be32
225c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
226bbc9c36cSJ. Bruce Fields {
227bbc9c36cSJ. Bruce Fields 	struct svc_fh *current_fh = &cstate->current_fh;
2287007c90fSNeil Brown 	int accmode;
229b37ad28bSAl Viro 	__be32 status;
2301da177e4SLinus Torvalds 
231c0e6bee4SJ. Bruce Fields 	*resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
232c0e6bee4SJ. Bruce Fields 	if (!*resfh)
23359deeb9eSJ. Bruce Fields 		return nfserr_jukebox;
234c0e6bee4SJ. Bruce Fields 	fh_init(*resfh, NFS4_FHSIZE);
2351da177e4SLinus Torvalds 	open->op_truncate = 0;
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds 	if (open->op_create) {
23879fb54abSBenny Halevy 		/* FIXME: check session persistence and pnfs flags.
23979fb54abSBenny Halevy 		 * The nfsv4.1 spec requires the following semantics:
24079fb54abSBenny Halevy 		 *
24179fb54abSBenny Halevy 		 * Persistent   | pNFS   | Server REQUIRED | Client Allowed
24279fb54abSBenny Halevy 		 * Reply Cache  | server |                 |
24379fb54abSBenny Halevy 		 * -------------+--------+-----------------+--------------------
24479fb54abSBenny Halevy 		 * no           | no     | EXCLUSIVE4_1    | EXCLUSIVE4_1
24579fb54abSBenny Halevy 		 *              |        |                 | (SHOULD)
24679fb54abSBenny Halevy 		 *              |        | and EXCLUSIVE4  | or EXCLUSIVE4
24779fb54abSBenny Halevy 		 *              |        |                 | (SHOULD NOT)
24879fb54abSBenny Halevy 		 * no           | yes    | EXCLUSIVE4_1    | EXCLUSIVE4_1
24979fb54abSBenny Halevy 		 * yes          | no     | GUARDED4        | GUARDED4
25079fb54abSBenny Halevy 		 * yes          | yes    | GUARDED4        | GUARDED4
25179fb54abSBenny Halevy 		 */
25279fb54abSBenny Halevy 
2531da177e4SLinus Torvalds 		/*
2541da177e4SLinus Torvalds 		 * Note: create modes (UNCHECKED,GUARDED...) are the same
255ac6721a1SMi Jinlong 		 * in NFSv4 as in v3 except EXCLUSIVE4_1.
2561da177e4SLinus Torvalds 		 */
257880a3a53SJ. Bruce Fields 		current->fs->umask = open->op_umask;
258ac6721a1SMi Jinlong 		status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
2591da177e4SLinus Torvalds 					open->op_fname.len, &open->op_iattr,
260c0e6bee4SJ. Bruce Fields 					*resfh, open->op_createmode,
261749997e5SJeff Layton 					(u32 *)open->op_verf.data,
262856121b2SJ. Bruce Fields 					&open->op_truncate, &open->op_created);
263880a3a53SJ. Bruce Fields 		current->fs->umask = 0;
264749997e5SJeff Layton 
26518032ca0SDavid Quigley 		if (!status && open->op_label.len)
266c0e6bee4SJ. Bruce Fields 			nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
26718032ca0SDavid Quigley 
26899f88726SJ. Bruce Fields 		/*
269ead8fb8cSKinglong Mee 		 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
270ead8fb8cSKinglong Mee 		 * use the returned bitmask to indicate which attributes
271ead8fb8cSKinglong Mee 		 * we used to store the verifier:
272749997e5SJeff Layton 		 */
273ead8fb8cSKinglong Mee 		if (nfsd_create_is_exclusive(open->op_createmode) && status == 0)
274ead8fb8cSKinglong Mee 			open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
275749997e5SJeff Layton 						FATTR4_WORD1_TIME_MODIFY);
2764335723eSJ. Bruce Fields 	} else
2774335723eSJ. Bruce Fields 		/*
2784335723eSJ. Bruce Fields 		 * Note this may exit with the parent still locked.
2794335723eSJ. Bruce Fields 		 * We will hold the lock until nfsd4_open's final
2804335723eSJ. Bruce Fields 		 * lookup, to prevent renames or unlinks until we've had
2814335723eSJ. Bruce Fields 		 * a chance to an acquire a delegation if appropriate.
2824335723eSJ. Bruce Fields 		 */
2831da177e4SLinus Torvalds 		status = nfsd_lookup(rqstp, current_fh,
284c0e6bee4SJ. Bruce Fields 				     open->op_fname.data, open->op_fname.len, *resfh);
285aadab6c6SJ. Bruce Fields 	if (status)
286aadab6c6SJ. Bruce Fields 		goto out;
287c0e6bee4SJ. Bruce Fields 	status = nfsd_check_obj_isreg(*resfh);
288af85852dSJ. Bruce Fields 	if (status)
289af85852dSJ. Bruce Fields 		goto out;
2901da177e4SLinus Torvalds 
2919208faf2SYu Zhiguo 	if (is_create_with_attrs(open) && open->op_acl != NULL)
292c0e6bee4SJ. Bruce Fields 		do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
2939208faf2SYu Zhiguo 
294c0e6bee4SJ. Bruce Fields 	nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
2957007c90fSNeil Brown 	accmode = NFSD_MAY_NOP;
29689f6c336SJ. Bruce Fields 	if (open->op_created ||
29789f6c336SJ. Bruce Fields 			open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
2987007c90fSNeil Brown 		accmode |= NFSD_MAY_OWNER_OVERRIDE;
299c0e6bee4SJ. Bruce Fields 	status = do_open_permission(rqstp, *resfh, open, accmode);
30041fd1e42SJ. Bruce Fields 	set_change_info(&open->op_cinfo, current_fh);
301af85852dSJ. Bruce Fields out:
3021da177e4SLinus Torvalds 	return status;
3031da177e4SLinus Torvalds }
3041da177e4SLinus Torvalds 
305b37ad28bSAl Viro static __be32
306bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
3071da177e4SLinus Torvalds {
308bbc9c36cSJ. Bruce Fields 	struct svc_fh *current_fh = &cstate->current_fh;
309b37ad28bSAl Viro 	__be32 status;
3109f415eb2SJ. Bruce Fields 	int accmode = 0;
3111da177e4SLinus Torvalds 
3121da177e4SLinus Torvalds 	/* We don't know the target directory, and therefore can not
3131da177e4SLinus Torvalds 	* set the change info
3141da177e4SLinus Torvalds 	*/
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds 	memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
3171da177e4SLinus Torvalds 
318bbc9c36cSJ. Bruce Fields 	nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds 	open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
3211da177e4SLinus Torvalds 		(open->op_iattr.ia_size == 0);
3229f415eb2SJ. Bruce Fields 	/*
3239f415eb2SJ. Bruce Fields 	 * In the delegation case, the client is telling us about an
3249f415eb2SJ. Bruce Fields 	 * open that it *already* performed locally, some time ago.  We
3259f415eb2SJ. Bruce Fields 	 * should let it succeed now if possible.
3269f415eb2SJ. Bruce Fields 	 *
3279f415eb2SJ. Bruce Fields 	 * In the case of a CLAIM_FH open, on the other hand, the client
3289f415eb2SJ. Bruce Fields 	 * may be counting on us to enforce permissions (the Linux 4.1
3299f415eb2SJ. Bruce Fields 	 * client uses this for normal opens, for example).
3309f415eb2SJ. Bruce Fields 	 */
3319f415eb2SJ. Bruce Fields 	if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
3329f415eb2SJ. Bruce Fields 		accmode = NFSD_MAY_OWNER_OVERRIDE;
3331da177e4SLinus Torvalds 
3349f415eb2SJ. Bruce Fields 	status = do_open_permission(rqstp, current_fh, open, accmode);
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds 	return status;
3371da177e4SLinus Torvalds }
3381da177e4SLinus Torvalds 
33960adfc50SAndy Adamson static void
34060adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session)
34160adfc50SAndy Adamson {
34260adfc50SAndy Adamson 	struct nfsd4_sessionid *sid =
34360adfc50SAndy Adamson 			(struct nfsd4_sessionid *)session->se_sessionid.data;
34460adfc50SAndy Adamson 
34560adfc50SAndy Adamson 	clid->cl_boot = sid->clientid.cl_boot;
34660adfc50SAndy Adamson 	clid->cl_id = sid->clientid.cl_id;
34760adfc50SAndy Adamson }
3481da177e4SLinus Torvalds 
3497191155bSJ.Bruce Fields static __be32
350ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
351eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
3521da177e4SLinus Torvalds {
353eb69853dSChristoph Hellwig 	struct nfsd4_open *open = &u->open;
354b37ad28bSAl Viro 	__be32 status;
355c0e6bee4SJ. Bruce Fields 	struct svc_fh *resfh = NULL;
3563320fef1SStanislav Kinsbursky 	struct net *net = SVC_NET(rqstp);
3573320fef1SStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
35803f318caSJ. Bruce Fields 	bool reclaim = false;
3596668958fSAndy Adamson 
360fe0750e5SJ. Bruce Fields 	dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
3611da177e4SLinus Torvalds 		(int)open->op_fname.len, open->op_fname.data,
362fe0750e5SJ. Bruce Fields 		open->op_openowner);
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds 	/* This check required by spec. */
3651da177e4SLinus Torvalds 	if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
3661da177e4SLinus Torvalds 		return nfserr_inval;
3671da177e4SLinus Torvalds 
368856121b2SJ. Bruce Fields 	open->op_created = 0;
369ab1350b2SMi Jinlong 	/*
370ab1350b2SMi Jinlong 	 * RFC5661 18.51.3
371ab1350b2SMi Jinlong 	 * Before RECLAIM_COMPLETE done, server should deny new lock
372ab1350b2SMi Jinlong 	 */
373ab1350b2SMi Jinlong 	if (nfsd4_has_session(cstate) &&
374a52d726bSJeff Layton 	    !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE,
375a52d726bSJeff Layton 		      &cstate->session->se_client->cl_flags) &&
376ab1350b2SMi Jinlong 	    open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
377ab1350b2SMi Jinlong 		return nfserr_grace;
378ab1350b2SMi Jinlong 
37960adfc50SAndy Adamson 	if (nfsd4_has_session(cstate))
38060adfc50SAndy Adamson 		copy_clientid(&open->op_clientid, cstate->session);
38160adfc50SAndy Adamson 
3821da177e4SLinus Torvalds 	/* check seqid for replay. set nfs4_owner */
3836cd22668SKinglong Mee 	status = nfsd4_process_open1(cstate, open, nn);
384a90b061cSAl Viro 	if (status == nfserr_replay_me) {
385fe0750e5SJ. Bruce Fields 		struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
386ca364317SJ.Bruce Fields 		fh_put(&cstate->current_fh);
387a4773c08SJ. Bruce Fields 		fh_copy_shallow(&cstate->current_fh.fh_handle,
388a4773c08SJ. Bruce Fields 				&rp->rp_openfh);
3898837abcaSMiklos Szeredi 		status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
3901da177e4SLinus Torvalds 		if (status)
3911da177e4SLinus Torvalds 			dprintk("nfsd4_open: replay failed"
3921da177e4SLinus Torvalds 				" restoring previous filehandle\n");
3931da177e4SLinus Torvalds 		else
394a90b061cSAl Viro 			status = nfserr_replay_me;
3951da177e4SLinus Torvalds 	}
3961da177e4SLinus Torvalds 	if (status)
3971da177e4SLinus Torvalds 		goto out;
3989d313b17SJ. Bruce Fields 	if (open->op_xdr_error) {
3999d313b17SJ. Bruce Fields 		status = open->op_xdr_error;
4009d313b17SJ. Bruce Fields 		goto out;
4019d313b17SJ. Bruce Fields 	}
402fb553c0fSJ. Bruce Fields 
4033c8e0316SYu Zhiguo 	status = nfsd4_check_open_attributes(rqstp, cstate, open);
4043c8e0316SYu Zhiguo 	if (status)
4053c8e0316SYu Zhiguo 		goto out;
4063c8e0316SYu Zhiguo 
407fb553c0fSJ. Bruce Fields 	/* Openowner is now set, so sequence id will get bumped.  Now we need
408fb553c0fSJ. Bruce Fields 	 * these checks before we do any creates: */
409cbd0d51aSJ. Bruce Fields 	status = nfserr_grace;
410c87fb4a3SJ. Bruce Fields 	if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
411cbd0d51aSJ. Bruce Fields 		goto out;
412cbd0d51aSJ. Bruce Fields 	status = nfserr_no_grace;
413c87fb4a3SJ. Bruce Fields 	if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
414cbd0d51aSJ. Bruce Fields 		goto out;
415fb553c0fSJ. Bruce Fields 
4161da177e4SLinus Torvalds 	switch (open->op_claim_type) {
4170dd3c192SNeilBrown 		case NFS4_OPEN_CLAIM_DELEGATE_CUR:
4181da177e4SLinus Torvalds 		case NFS4_OPEN_CLAIM_NULL:
419c0e6bee4SJ. Bruce Fields 			status = do_open_lookup(rqstp, cstate, open, &resfh);
4201da177e4SLinus Torvalds 			if (status)
4211da177e4SLinus Torvalds 				goto out;
4221da177e4SLinus Torvalds 			break;
4231da177e4SLinus Torvalds 		case NFS4_OPEN_CLAIM_PREVIOUS:
4243320fef1SStanislav Kinsbursky 			status = nfs4_check_open_reclaim(&open->op_clientid,
4250fe492dbSTrond Myklebust 							 cstate, nn);
4260cf99b91SMi Jinlong 			if (status)
4270cf99b91SMi Jinlong 				goto out;
428ba5378b6SJeff Layton 			open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
42903f318caSJ. Bruce Fields 			reclaim = true;
4308b289b2cSJ. Bruce Fields 		case NFS4_OPEN_CLAIM_FH:
4318b289b2cSJ. Bruce Fields 		case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
432bbc9c36cSJ. Bruce Fields 			status = do_open_fhandle(rqstp, cstate, open);
4331da177e4SLinus Torvalds 			if (status)
4341da177e4SLinus Torvalds 				goto out;
435c0e6bee4SJ. Bruce Fields 			resfh = &cstate->current_fh;
4361da177e4SLinus Torvalds 			break;
4378b289b2cSJ. Bruce Fields 		case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
4381da177e4SLinus Torvalds              	case NFS4_OPEN_CLAIM_DELEGATE_PREV:
4392fdada03SJ. Bruce Fields 			dprintk("NFSD: unsupported OPEN claim type %d\n",
4401da177e4SLinus Torvalds 				open->op_claim_type);
4411da177e4SLinus Torvalds 			status = nfserr_notsupp;
4421da177e4SLinus Torvalds 			goto out;
4431da177e4SLinus Torvalds 		default:
4442fdada03SJ. Bruce Fields 			dprintk("NFSD: Invalid OPEN claim type %d\n",
4451da177e4SLinus Torvalds 				open->op_claim_type);
4461da177e4SLinus Torvalds 			status = nfserr_inval;
4471da177e4SLinus Torvalds 			goto out;
4481da177e4SLinus Torvalds 	}
4491da177e4SLinus Torvalds 	/*
4501da177e4SLinus Torvalds 	 * nfsd4_process_open2() does the actual opening of the file.  If
4511da177e4SLinus Torvalds 	 * successful, it (1) truncates the file if open->op_truncate was
4521da177e4SLinus Torvalds 	 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
4531da177e4SLinus Torvalds 	 */
454c0e6bee4SJ. Bruce Fields 	status = nfsd4_process_open2(rqstp, resfh, open);
455b3fbfe0eSJeff Layton 	WARN(status && open->op_created,
456b3fbfe0eSJeff Layton 	     "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
457b3fbfe0eSJeff Layton 	     be32_to_cpu(status));
45803f318caSJ. Bruce Fields 	if (reclaim && !status)
45903f318caSJ. Bruce Fields 		nn->somebody_reclaimed = true;
4601da177e4SLinus Torvalds out:
461c0e6bee4SJ. Bruce Fields 	if (resfh && resfh != &cstate->current_fh) {
462c0e6bee4SJ. Bruce Fields 		fh_dup2(&cstate->current_fh, resfh);
463c0e6bee4SJ. Bruce Fields 		fh_put(resfh);
464c0e6bee4SJ. Bruce Fields 		kfree(resfh);
465c0e6bee4SJ. Bruce Fields 	}
46642297899SJeff Layton 	nfsd4_cleanup_open_state(cstate, open);
4679411b1d4SJ. Bruce Fields 	nfsd4_bump_seqid(cstate, status);
4681da177e4SLinus Torvalds 	return status;
4691da177e4SLinus Torvalds }
4701da177e4SLinus Torvalds 
4711da177e4SLinus Torvalds /*
4729d313b17SJ. Bruce Fields  * OPEN is the only seqid-mutating operation whose decoding can fail
4739d313b17SJ. Bruce Fields  * with a seqid-mutating error (specifically, decoding of user names in
4749d313b17SJ. Bruce Fields  * the attributes).  Therefore we have to do some processing to look up
4759d313b17SJ. Bruce Fields  * the stateowner so that we can bump the seqid.
4769d313b17SJ. Bruce Fields  */
4779d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
4789d313b17SJ. Bruce Fields {
479eb69853dSChristoph Hellwig 	struct nfsd4_open *open = &op->u.open;
4809d313b17SJ. Bruce Fields 
4819d313b17SJ. Bruce Fields 	if (!seqid_mutating_err(ntohl(op->status)))
4829d313b17SJ. Bruce Fields 		return op->status;
4839d313b17SJ. Bruce Fields 	if (nfsd4_has_session(cstate))
4849d313b17SJ. Bruce Fields 		return op->status;
4859d313b17SJ. Bruce Fields 	open->op_xdr_error = op->status;
486eb69853dSChristoph Hellwig 	return nfsd4_open(rqstp, cstate, &op->u);
4879d313b17SJ. Bruce Fields }
4889d313b17SJ. Bruce Fields 
4899d313b17SJ. Bruce Fields /*
4901da177e4SLinus Torvalds  * filehandle-manipulating ops.
4911da177e4SLinus Torvalds  */
4927191155bSJ.Bruce Fields static __be32
493b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
494eb69853dSChristoph Hellwig 	    union nfsd4_op_u *u)
4951da177e4SLinus Torvalds {
496eb69853dSChristoph Hellwig 	u->getfh = &cstate->current_fh;
4971da177e4SLinus Torvalds 	return nfs_ok;
4981da177e4SLinus Torvalds }
4991da177e4SLinus Torvalds 
5007191155bSJ.Bruce Fields static __be32
501ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
502eb69853dSChristoph Hellwig 	    union nfsd4_op_u *u)
5031da177e4SLinus Torvalds {
504eb69853dSChristoph Hellwig 	struct nfsd4_putfh *putfh = &u->putfh;
505eb69853dSChristoph Hellwig 
506ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
507ca364317SJ.Bruce Fields 	cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
508ca364317SJ.Bruce Fields 	memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
509ca364317SJ.Bruce Fields 	       putfh->pf_fhlen);
51068d93184SJ. Bruce Fields 	return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
5111da177e4SLinus Torvalds }
5121da177e4SLinus Torvalds 
5137191155bSJ.Bruce Fields static __be32
514b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
515eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
5161da177e4SLinus Torvalds {
517b37ad28bSAl Viro 	__be32 status;
5181da177e4SLinus Torvalds 
519ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
520df547efbSJ. Bruce Fields 	status = exp_pseudoroot(rqstp, &cstate->current_fh);
5211da177e4SLinus Torvalds 	return status;
5221da177e4SLinus Torvalds }
5231da177e4SLinus Torvalds 
5247191155bSJ.Bruce Fields static __be32
525b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
526eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
5271da177e4SLinus Torvalds {
528ca364317SJ.Bruce Fields 	if (!cstate->save_fh.fh_dentry)
5291da177e4SLinus Torvalds 		return nfserr_restorefh;
5301da177e4SLinus Torvalds 
531ca364317SJ.Bruce Fields 	fh_dup2(&cstate->current_fh, &cstate->save_fh);
53237c593c5STigran Mkrtchyan 	if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
53337c593c5STigran Mkrtchyan 		memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
53437c593c5STigran Mkrtchyan 		SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
53537c593c5STigran Mkrtchyan 	}
5361da177e4SLinus Torvalds 	return nfs_ok;
5371da177e4SLinus Torvalds }
5381da177e4SLinus Torvalds 
5397191155bSJ.Bruce Fields static __be32
540b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
541eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5421da177e4SLinus Torvalds {
543ca364317SJ.Bruce Fields 	fh_dup2(&cstate->save_fh, &cstate->current_fh);
54437c593c5STigran Mkrtchyan 	if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
54537c593c5STigran Mkrtchyan 		memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
54637c593c5STigran Mkrtchyan 		SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
54737c593c5STigran Mkrtchyan 	}
5481da177e4SLinus Torvalds 	return nfs_ok;
5491da177e4SLinus Torvalds }
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds /*
5521da177e4SLinus Torvalds  * misc nfsv4 ops
5531da177e4SLinus Torvalds  */
5547191155bSJ.Bruce Fields static __be32
555ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
556eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5571da177e4SLinus Torvalds {
558eb69853dSChristoph Hellwig 	struct nfsd4_access *access = &u->access;
559eb69853dSChristoph Hellwig 
5601da177e4SLinus Torvalds 	if (access->ac_req_access & ~NFS3_ACCESS_FULL)
5611da177e4SLinus Torvalds 		return nfserr_inval;
5621da177e4SLinus Torvalds 
5631da177e4SLinus Torvalds 	access->ac_resp_access = access->ac_req_access;
564ca364317SJ.Bruce Fields 	return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
565ca364317SJ.Bruce Fields 			   &access->ac_supported);
5661da177e4SLinus Torvalds }
5671da177e4SLinus Torvalds 
568b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
569ab4684d1SChuck Lever {
570ab4684d1SChuck Lever 	__be32 verf[2];
571b9c0ef85SStanislav Kinsbursky 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
572ab4684d1SChuck Lever 
573f419992cSJeff Layton 	/*
574f419992cSJeff Layton 	 * This is opaque to client, so no need to byte-swap. Use
575256a89faSArnd Bergmann 	 * __force to keep sparse happy. y2038 time_t overflow is
576256a89faSArnd Bergmann 	 * irrelevant in this usage.
577f419992cSJeff Layton 	 */
578f419992cSJeff Layton 	verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
579256a89faSArnd Bergmann 	verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec;
580ab4684d1SChuck Lever 	memcpy(verifier->data, verf, sizeof(verifier->data));
581ab4684d1SChuck Lever }
582ab4684d1SChuck Lever 
5837191155bSJ.Bruce Fields static __be32
584ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
585eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5861da177e4SLinus Torvalds {
587eb69853dSChristoph Hellwig 	struct nfsd4_commit *commit = &u->commit;
588eb69853dSChristoph Hellwig 
589b9c0ef85SStanislav Kinsbursky 	gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp));
59075c096f7SJ. Bruce Fields 	return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
591ca364317SJ.Bruce Fields 			     commit->co_count);
5921da177e4SLinus Torvalds }
5931da177e4SLinus Torvalds 
594b37ad28bSAl Viro static __be32
595ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
596eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
5971da177e4SLinus Torvalds {
598eb69853dSChristoph Hellwig 	struct nfsd4_create *create = &u->create;
5991da177e4SLinus Torvalds 	struct svc_fh resfh;
600b37ad28bSAl Viro 	__be32 status;
6011da177e4SLinus Torvalds 	dev_t rdev;
6021da177e4SLinus Torvalds 
6031da177e4SLinus Torvalds 	fh_init(&resfh, NFS4_FHSIZE);
6041da177e4SLinus Torvalds 
605fa08139dSJ. Bruce Fields 	status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
6061da177e4SLinus Torvalds 	if (status)
6071da177e4SLinus Torvalds 		return status;
6081da177e4SLinus Torvalds 
6093c8e0316SYu Zhiguo 	status = check_attr_support(rqstp, cstate, create->cr_bmval,
6103c8e0316SYu Zhiguo 				    nfsd_attrmask);
6113c8e0316SYu Zhiguo 	if (status)
6123c8e0316SYu Zhiguo 		return status;
6133c8e0316SYu Zhiguo 
614880a3a53SJ. Bruce Fields 	current->fs->umask = create->cr_umask;
6151da177e4SLinus Torvalds 	switch (create->cr_type) {
6161da177e4SLinus Torvalds 	case NF4LNK:
617ca364317SJ.Bruce Fields 		status = nfsd_symlink(rqstp, &cstate->current_fh,
618ca364317SJ.Bruce Fields 				      create->cr_name, create->cr_namelen,
6191e444f5bSKinglong Mee 				      create->cr_data, &resfh);
6201da177e4SLinus Torvalds 		break;
6211da177e4SLinus Torvalds 
6221da177e4SLinus Torvalds 	case NF4BLK:
623880a3a53SJ. Bruce Fields 		status = nfserr_inval;
6241da177e4SLinus Torvalds 		rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
6251da177e4SLinus Torvalds 		if (MAJOR(rdev) != create->cr_specdata1 ||
6261da177e4SLinus Torvalds 		    MINOR(rdev) != create->cr_specdata2)
627880a3a53SJ. Bruce Fields 			goto out_umask;
628ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
629ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
630ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFBLK, rdev, &resfh);
6311da177e4SLinus Torvalds 		break;
6321da177e4SLinus Torvalds 
6331da177e4SLinus Torvalds 	case NF4CHR:
634880a3a53SJ. Bruce Fields 		status = nfserr_inval;
6351da177e4SLinus Torvalds 		rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
6361da177e4SLinus Torvalds 		if (MAJOR(rdev) != create->cr_specdata1 ||
6371da177e4SLinus Torvalds 		    MINOR(rdev) != create->cr_specdata2)
638880a3a53SJ. Bruce Fields 			goto out_umask;
639ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
640ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
641ca364317SJ.Bruce Fields 				     &create->cr_iattr,S_IFCHR, rdev, &resfh);
6421da177e4SLinus Torvalds 		break;
6431da177e4SLinus Torvalds 
6441da177e4SLinus Torvalds 	case NF4SOCK:
645ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
646ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
647ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFSOCK, 0, &resfh);
6481da177e4SLinus Torvalds 		break;
6491da177e4SLinus Torvalds 
6501da177e4SLinus Torvalds 	case NF4FIFO:
651ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
652ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
653ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFIFO, 0, &resfh);
6541da177e4SLinus Torvalds 		break;
6551da177e4SLinus Torvalds 
6561da177e4SLinus Torvalds 	case NF4DIR:
6571da177e4SLinus Torvalds 		create->cr_iattr.ia_valid &= ~ATTR_SIZE;
658ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
659ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
660ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFDIR, 0, &resfh);
6611da177e4SLinus Torvalds 		break;
6621da177e4SLinus Torvalds 
6631da177e4SLinus Torvalds 	default:
6641da177e4SLinus Torvalds 		status = nfserr_badtype;
6651da177e4SLinus Torvalds 	}
6661da177e4SLinus Torvalds 
6679208faf2SYu Zhiguo 	if (status)
6689208faf2SYu Zhiguo 		goto out;
6699208faf2SYu Zhiguo 
67018032ca0SDavid Quigley 	if (create->cr_label.len)
67118032ca0SDavid Quigley 		nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
67218032ca0SDavid Quigley 
6739208faf2SYu Zhiguo 	if (create->cr_acl != NULL)
6749208faf2SYu Zhiguo 		do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
6759208faf2SYu Zhiguo 				create->cr_bmval);
6769208faf2SYu Zhiguo 
677ca364317SJ.Bruce Fields 	fh_unlock(&cstate->current_fh);
678ca364317SJ.Bruce Fields 	set_change_info(&create->cr_cinfo, &cstate->current_fh);
679ca364317SJ.Bruce Fields 	fh_dup2(&cstate->current_fh, &resfh);
6809208faf2SYu Zhiguo out:
6811da177e4SLinus Torvalds 	fh_put(&resfh);
682880a3a53SJ. Bruce Fields out_umask:
683880a3a53SJ. Bruce Fields 	current->fs->umask = 0;
6841da177e4SLinus Torvalds 	return status;
6851da177e4SLinus Torvalds }
6861da177e4SLinus Torvalds 
6877191155bSJ.Bruce Fields static __be32
688ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
689eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
6901da177e4SLinus Torvalds {
691eb69853dSChristoph Hellwig 	struct nfsd4_getattr *getattr = &u->getattr;
692b37ad28bSAl Viro 	__be32 status;
6931da177e4SLinus Torvalds 
6948837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
6951da177e4SLinus Torvalds 	if (status)
6961da177e4SLinus Torvalds 		return status;
6971da177e4SLinus Torvalds 
6981da177e4SLinus Torvalds 	if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
6991da177e4SLinus Torvalds 		return nfserr_inval;
7001da177e4SLinus Torvalds 
701916d2d84SJ. Bruce Fields 	getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
702916d2d84SJ. Bruce Fields 	getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
703916d2d84SJ. Bruce Fields 	getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
7041da177e4SLinus Torvalds 
705ca364317SJ.Bruce Fields 	getattr->ga_fhp = &cstate->current_fh;
7061da177e4SLinus Torvalds 	return nfs_ok;
7071da177e4SLinus Torvalds }
7081da177e4SLinus Torvalds 
7097191155bSJ.Bruce Fields static __be32
710ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
711eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
7121da177e4SLinus Torvalds {
713eb69853dSChristoph Hellwig 	struct nfsd4_link *link = &u->link;
71495424460SJ. Bruce Fields 	__be32 status;
7151da177e4SLinus Torvalds 
716ca364317SJ.Bruce Fields 	status = nfsd_link(rqstp, &cstate->current_fh,
717ca364317SJ.Bruce Fields 			   link->li_name, link->li_namelen, &cstate->save_fh);
7181da177e4SLinus Torvalds 	if (!status)
719ca364317SJ.Bruce Fields 		set_change_info(&link->li_cinfo, &cstate->current_fh);
7201da177e4SLinus Torvalds 	return status;
7211da177e4SLinus Torvalds }
7221da177e4SLinus Torvalds 
7230ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
7241da177e4SLinus Torvalds {
7251da177e4SLinus Torvalds 	struct svc_fh tmp_fh;
726b37ad28bSAl Viro 	__be32 ret;
7271da177e4SLinus Torvalds 
7281da177e4SLinus Torvalds 	fh_init(&tmp_fh, NFS4_FHSIZE);
729df547efbSJ. Bruce Fields 	ret = exp_pseudoroot(rqstp, &tmp_fh);
730df547efbSJ. Bruce Fields 	if (ret)
7311da177e4SLinus Torvalds 		return ret;
7320ff7ab46SJ. Bruce Fields 	if (tmp_fh.fh_dentry == fh->fh_dentry) {
7331da177e4SLinus Torvalds 		fh_put(&tmp_fh);
7341da177e4SLinus Torvalds 		return nfserr_noent;
7351da177e4SLinus Torvalds 	}
7361da177e4SLinus Torvalds 	fh_put(&tmp_fh);
7370ff7ab46SJ. Bruce Fields 	return nfsd_lookup(rqstp, fh, "..", 2, fh);
7380ff7ab46SJ. Bruce Fields }
7390ff7ab46SJ. Bruce Fields 
7400ff7ab46SJ. Bruce Fields static __be32
7410ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
742eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
7430ff7ab46SJ. Bruce Fields {
7440ff7ab46SJ. Bruce Fields 	return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
7451da177e4SLinus Torvalds }
7461da177e4SLinus Torvalds 
7477191155bSJ.Bruce Fields static __be32
748ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
749eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
7501da177e4SLinus Torvalds {
751ca364317SJ.Bruce Fields 	return nfsd_lookup(rqstp, &cstate->current_fh,
752eb69853dSChristoph Hellwig 			   u->lookup.lo_name, u->lookup.lo_len,
753ca364317SJ.Bruce Fields 			   &cstate->current_fh);
7541da177e4SLinus Torvalds }
7551da177e4SLinus Torvalds 
7567191155bSJ.Bruce Fields static __be32
757ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
758eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
7591da177e4SLinus Torvalds {
760eb69853dSChristoph Hellwig 	struct nfsd4_read *read = &u->read;
761b37ad28bSAl Viro 	__be32 status;
7621da177e4SLinus Torvalds 
7637e06b7f9SNeilBrown 	read->rd_filp = NULL;
7641da177e4SLinus Torvalds 	if (read->rd_offset >= OFFSET_MAX)
7651da177e4SLinus Torvalds 		return nfserr_inval;
7661da177e4SLinus Torvalds 
76787c5942eSChuck Lever 	trace_nfsd_read_start(rqstp, &cstate->current_fh,
76887c5942eSChuck Lever 			      read->rd_offset, read->rd_length);
76987c5942eSChuck Lever 
7709b3234b9SJ. Bruce Fields 	/*
7719b3234b9SJ. Bruce Fields 	 * If we do a zero copy read, then a client will see read data
7729b3234b9SJ. Bruce Fields 	 * that reflects the state of the file *after* performing the
7739b3234b9SJ. Bruce Fields 	 * following compound.
7749b3234b9SJ. Bruce Fields 	 *
7759b3234b9SJ. Bruce Fields 	 * To ensure proper ordering, we therefore turn off zero copy if
7769b3234b9SJ. Bruce Fields 	 * the client wants us to do more in this compound:
7779b3234b9SJ. Bruce Fields 	 */
7789b3234b9SJ. Bruce Fields 	if (!nfsd4_last_compound_op(rqstp))
779779fb0f3SJeff Layton 		clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
7809b3234b9SJ. Bruce Fields 
7811da177e4SLinus Torvalds 	/* check stateid */
782aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
783aa0d6aedSAnna Schumaker 					&read->rd_stateid, RD_STATE,
784aa0d6aedSAnna Schumaker 					&read->rd_filp, &read->rd_tmp_file);
785af90f707SChristoph Hellwig 	if (status) {
7861da177e4SLinus Torvalds 		dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
7871da177e4SLinus Torvalds 		goto out;
7881da177e4SLinus Torvalds 	}
7891da177e4SLinus Torvalds 	status = nfs_ok;
7901da177e4SLinus Torvalds out:
7911da177e4SLinus Torvalds 	read->rd_rqstp = rqstp;
792ca364317SJ.Bruce Fields 	read->rd_fhp = &cstate->current_fh;
7931da177e4SLinus Torvalds 	return status;
7941da177e4SLinus Torvalds }
7951da177e4SLinus Torvalds 
79634b1744cSJ. Bruce Fields 
79734b1744cSJ. Bruce Fields static void
79834b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u)
79934b1744cSJ. Bruce Fields {
80034b1744cSJ. Bruce Fields 	if (u->read.rd_filp)
80134b1744cSJ. Bruce Fields 		fput(u->read.rd_filp);
80287c5942eSChuck Lever 	trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
80387c5942eSChuck Lever 			     u->read.rd_offset, u->read.rd_length);
80434b1744cSJ. Bruce Fields }
80534b1744cSJ. Bruce Fields 
8067191155bSJ.Bruce Fields static __be32
807ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
808eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
8091da177e4SLinus Torvalds {
810eb69853dSChristoph Hellwig 	struct nfsd4_readdir *readdir = &u->readdir;
8111da177e4SLinus Torvalds 	u64 cookie = readdir->rd_cookie;
8121da177e4SLinus Torvalds 	static const nfs4_verifier zeroverf;
8131da177e4SLinus Torvalds 
8141da177e4SLinus Torvalds 	/* no need to check permission - this will be done in nfsd_readdir() */
8151da177e4SLinus Torvalds 
8161da177e4SLinus Torvalds 	if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
8171da177e4SLinus Torvalds 		return nfserr_inval;
8181da177e4SLinus Torvalds 
819916d2d84SJ. Bruce Fields 	readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
820916d2d84SJ. Bruce Fields 	readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
821916d2d84SJ. Bruce Fields 	readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
8221da177e4SLinus Torvalds 
823832023bfSBernd Schubert 	if ((cookie == 1) || (cookie == 2) ||
8241da177e4SLinus Torvalds 	    (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
8251da177e4SLinus Torvalds 		return nfserr_bad_cookie;
8261da177e4SLinus Torvalds 
8271da177e4SLinus Torvalds 	readdir->rd_rqstp = rqstp;
828ca364317SJ.Bruce Fields 	readdir->rd_fhp = &cstate->current_fh;
8291da177e4SLinus Torvalds 	return nfs_ok;
8301da177e4SLinus Torvalds }
8311da177e4SLinus Torvalds 
8327191155bSJ.Bruce Fields static __be32
833ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
834eb69853dSChristoph Hellwig 	       union nfsd4_op_u *u)
8351da177e4SLinus Torvalds {
836eb69853dSChristoph Hellwig 	u->readlink.rl_rqstp = rqstp;
837eb69853dSChristoph Hellwig 	u->readlink.rl_fhp = &cstate->current_fh;
8381da177e4SLinus Torvalds 	return nfs_ok;
8391da177e4SLinus Torvalds }
8401da177e4SLinus Torvalds 
8417191155bSJ.Bruce Fields static __be32
842ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
843eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
8441da177e4SLinus Torvalds {
845eb69853dSChristoph Hellwig 	struct nfsd4_remove *remove = &u->remove;
846b37ad28bSAl Viro 	__be32 status;
8471da177e4SLinus Torvalds 
848c87fb4a3SJ. Bruce Fields 	if (opens_in_grace(SVC_NET(rqstp)))
849c815afc7SNeilBrown 		return nfserr_grace;
850ca364317SJ.Bruce Fields 	status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
851ca364317SJ.Bruce Fields 			     remove->rm_name, remove->rm_namelen);
8521da177e4SLinus Torvalds 	if (!status) {
853ca364317SJ.Bruce Fields 		fh_unlock(&cstate->current_fh);
854ca364317SJ.Bruce Fields 		set_change_info(&remove->rm_cinfo, &cstate->current_fh);
8551da177e4SLinus Torvalds 	}
8561da177e4SLinus Torvalds 	return status;
8571da177e4SLinus Torvalds }
8581da177e4SLinus Torvalds 
8597191155bSJ.Bruce Fields static __be32
860ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
861eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
8621da177e4SLinus Torvalds {
863eb69853dSChristoph Hellwig 	struct nfsd4_rename *rename = &u->rename;
86495424460SJ. Bruce Fields 	__be32 status;
8651da177e4SLinus Torvalds 
866f8f71d00SJ. Bruce Fields 	if (opens_in_grace(SVC_NET(rqstp)))
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);
1018ffe1137bSJ. Bruce Fields 	WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1019ffe1137bSJ. Bruce Fields 
1020af90f707SChristoph Hellwig 	status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp,
1021af90f707SChristoph Hellwig 				write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
102254bbb7d2SKinglong Mee 				write->wr_how_written);
10237e06b7f9SNeilBrown 	fput(filp);
10241da177e4SLinus Torvalds 
102531dec253SDavid Shaw 	write->wr_bytes_written = cnt;
1026d890be15SChuck Lever 	trace_nfsd_write_done(rqstp, &cstate->current_fh,
1027d890be15SChuck Lever 			      write->wr_offset, cnt);
10281da177e4SLinus Torvalds 	return status;
10291da177e4SLinus Torvalds }
10301da177e4SLinus Torvalds 
103124bab491SAnna Schumaker static __be32
103229ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
103329ae7f9dSAnna Schumaker 		  stateid_t *src_stateid, struct file **src,
103429ae7f9dSAnna Schumaker 		  stateid_t *dst_stateid, struct file **dst)
1035ffa0160aSChristoph Hellwig {
1036ffa0160aSChristoph Hellwig 	__be32 status;
1037ffa0160aSChristoph Hellwig 
103801310bb7SScott Mayhew 	if (!cstate->save_fh.fh_dentry)
103901310bb7SScott Mayhew 		return nfserr_nofilehandle;
104001310bb7SScott Mayhew 
1041ffa0160aSChristoph Hellwig 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
104229ae7f9dSAnna Schumaker 					    src_stateid, RD_STATE, src, NULL);
1043ffa0160aSChristoph Hellwig 	if (status) {
1044ffa0160aSChristoph Hellwig 		dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
1045ffa0160aSChristoph Hellwig 		goto out;
1046ffa0160aSChristoph Hellwig 	}
1047ffa0160aSChristoph Hellwig 
1048ffa0160aSChristoph Hellwig 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
104929ae7f9dSAnna Schumaker 					    dst_stateid, WR_STATE, dst, NULL);
1050ffa0160aSChristoph Hellwig 	if (status) {
1051ffa0160aSChristoph Hellwig 		dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
1052ffa0160aSChristoph Hellwig 		goto out_put_src;
1053ffa0160aSChristoph Hellwig 	}
1054ffa0160aSChristoph Hellwig 
1055ffa0160aSChristoph Hellwig 	/* fix up for NFS-specific error code */
105629ae7f9dSAnna Schumaker 	if (!S_ISREG(file_inode(*src)->i_mode) ||
105729ae7f9dSAnna Schumaker 	    !S_ISREG(file_inode(*dst)->i_mode)) {
1058ffa0160aSChristoph Hellwig 		status = nfserr_wrong_type;
1059ffa0160aSChristoph Hellwig 		goto out_put_dst;
1060ffa0160aSChristoph Hellwig 	}
1061ffa0160aSChristoph Hellwig 
106229ae7f9dSAnna Schumaker out:
106329ae7f9dSAnna Schumaker 	return status;
106429ae7f9dSAnna Schumaker out_put_dst:
106529ae7f9dSAnna Schumaker 	fput(*dst);
106629ae7f9dSAnna Schumaker out_put_src:
106729ae7f9dSAnna Schumaker 	fput(*src);
106829ae7f9dSAnna Schumaker 	goto out;
106929ae7f9dSAnna Schumaker }
107029ae7f9dSAnna Schumaker 
107129ae7f9dSAnna Schumaker static __be32
107229ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1073eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
107429ae7f9dSAnna Schumaker {
1075eb69853dSChristoph Hellwig 	struct nfsd4_clone *clone = &u->clone;
107629ae7f9dSAnna Schumaker 	struct file *src, *dst;
107729ae7f9dSAnna Schumaker 	__be32 status;
107829ae7f9dSAnna Schumaker 
107929ae7f9dSAnna Schumaker 	status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
108029ae7f9dSAnna Schumaker 				   &clone->cl_dst_stateid, &dst);
108129ae7f9dSAnna Schumaker 	if (status)
108229ae7f9dSAnna Schumaker 		goto out;
108329ae7f9dSAnna Schumaker 
1084ffa0160aSChristoph Hellwig 	status = nfsd4_clone_file_range(src, clone->cl_src_pos,
1085ffa0160aSChristoph Hellwig 			dst, clone->cl_dst_pos, clone->cl_count);
1086ffa0160aSChristoph Hellwig 
1087ffa0160aSChristoph Hellwig 	fput(dst);
1088ffa0160aSChristoph Hellwig 	fput(src);
1089ffa0160aSChristoph Hellwig out:
1090ffa0160aSChristoph Hellwig 	return status;
1091ffa0160aSChristoph Hellwig }
1092ffa0160aSChristoph Hellwig 
1093e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy)
1094e0639dc5SOlga Kornievskaia {
1095e0639dc5SOlga Kornievskaia 	if (!refcount_dec_and_test(&copy->refcount))
1096e0639dc5SOlga Kornievskaia 		return;
1097e0639dc5SOlga Kornievskaia 	kfree(copy);
1098e0639dc5SOlga Kornievskaia }
1099e0639dc5SOlga Kornievskaia 
1100e0639dc5SOlga Kornievskaia static bool
1101e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy)
1102e0639dc5SOlga Kornievskaia {
1103e0639dc5SOlga Kornievskaia 	bool value;
1104e0639dc5SOlga Kornievskaia 
1105e0639dc5SOlga Kornievskaia 	spin_lock(&copy->cp_clp->async_lock);
1106e0639dc5SOlga Kornievskaia 	value = copy->stopped;
1107e0639dc5SOlga Kornievskaia 	if (!copy->stopped)
1108e0639dc5SOlga Kornievskaia 		copy->stopped = true;
1109e0639dc5SOlga Kornievskaia 	spin_unlock(&copy->cp_clp->async_lock);
1110e0639dc5SOlga Kornievskaia 	return value;
1111e0639dc5SOlga Kornievskaia }
1112e0639dc5SOlga Kornievskaia 
1113e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy)
1114e0639dc5SOlga Kornievskaia {
1115e0639dc5SOlga Kornievskaia 	/* only 1 thread should stop the copy */
1116e0639dc5SOlga Kornievskaia 	if (!check_and_set_stop_copy(copy))
1117e0639dc5SOlga Kornievskaia 		kthread_stop(copy->copy_task);
1118e0639dc5SOlga Kornievskaia 	nfs4_put_copy(copy);
1119e0639dc5SOlga Kornievskaia }
1120e0639dc5SOlga Kornievskaia 
1121e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp)
1122e0639dc5SOlga Kornievskaia {
1123e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy = NULL;
1124e0639dc5SOlga Kornievskaia 
1125e0639dc5SOlga Kornievskaia 	spin_lock(&clp->async_lock);
1126e0639dc5SOlga Kornievskaia 	if (!list_empty(&clp->async_copies)) {
1127e0639dc5SOlga Kornievskaia 		copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
1128e0639dc5SOlga Kornievskaia 					copies);
1129e0639dc5SOlga Kornievskaia 		refcount_inc(&copy->refcount);
1130e0639dc5SOlga Kornievskaia 	}
1131e0639dc5SOlga Kornievskaia 	spin_unlock(&clp->async_lock);
1132e0639dc5SOlga Kornievskaia 	return copy;
1133e0639dc5SOlga Kornievskaia }
1134e0639dc5SOlga Kornievskaia 
1135e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp)
1136e0639dc5SOlga Kornievskaia {
1137e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy;
1138e0639dc5SOlga Kornievskaia 
1139e0639dc5SOlga Kornievskaia 	while ((copy = nfsd4_get_copy(clp)) != NULL)
1140e0639dc5SOlga Kornievskaia 		nfsd4_stop_copy(copy);
1141e0639dc5SOlga Kornievskaia }
1142e0639dc5SOlga Kornievskaia 
1143e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
1144e0639dc5SOlga Kornievskaia {
1145e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
1146e0639dc5SOlga Kornievskaia 
1147e0639dc5SOlga Kornievskaia 	nfs4_put_copy(copy);
1148e0639dc5SOlga Kornievskaia }
1149e0639dc5SOlga Kornievskaia 
1150e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
1151e0639dc5SOlga Kornievskaia 				 struct rpc_task *task)
1152e0639dc5SOlga Kornievskaia {
1153e0639dc5SOlga Kornievskaia 	return 1;
1154e0639dc5SOlga Kornievskaia }
1155e0639dc5SOlga Kornievskaia 
1156e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
1157e0639dc5SOlga Kornievskaia 	.release = nfsd4_cb_offload_release,
1158e0639dc5SOlga Kornievskaia 	.done = nfsd4_cb_offload_done
1159e0639dc5SOlga Kornievskaia };
1160e0639dc5SOlga Kornievskaia 
1161e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
1162e0639dc5SOlga Kornievskaia {
1163e0639dc5SOlga Kornievskaia 	copy->cp_res.wr_stable_how = NFS_UNSTABLE;
1164e0639dc5SOlga Kornievskaia 	copy->cp_synchronous = sync;
1165e0639dc5SOlga Kornievskaia 	gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net);
1166e0639dc5SOlga Kornievskaia }
1167e0639dc5SOlga Kornievskaia 
1168e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
1169e0639dc5SOlga Kornievskaia {
1170e0639dc5SOlga Kornievskaia 	ssize_t bytes_copied = 0;
1171e0639dc5SOlga Kornievskaia 	size_t bytes_total = copy->cp_count;
1172e0639dc5SOlga Kornievskaia 	u64 src_pos = copy->cp_src_pos;
1173e0639dc5SOlga Kornievskaia 	u64 dst_pos = copy->cp_dst_pos;
1174e0639dc5SOlga Kornievskaia 
1175e0639dc5SOlga Kornievskaia 	do {
1176e0639dc5SOlga Kornievskaia 		if (kthread_should_stop())
1177e0639dc5SOlga Kornievskaia 			break;
1178e0639dc5SOlga Kornievskaia 		bytes_copied = nfsd_copy_file_range(copy->file_src, src_pos,
1179e0639dc5SOlga Kornievskaia 				copy->file_dst, dst_pos, bytes_total);
1180e0639dc5SOlga Kornievskaia 		if (bytes_copied <= 0)
1181e0639dc5SOlga Kornievskaia 			break;
1182e0639dc5SOlga Kornievskaia 		bytes_total -= bytes_copied;
1183e0639dc5SOlga Kornievskaia 		copy->cp_res.wr_bytes_written += bytes_copied;
1184e0639dc5SOlga Kornievskaia 		src_pos += bytes_copied;
1185e0639dc5SOlga Kornievskaia 		dst_pos += bytes_copied;
1186e0639dc5SOlga Kornievskaia 	} while (bytes_total > 0 && !copy->cp_synchronous);
1187e0639dc5SOlga Kornievskaia 	return bytes_copied;
1188e0639dc5SOlga Kornievskaia }
1189e0639dc5SOlga Kornievskaia 
1190e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
1191e0639dc5SOlga Kornievskaia {
1192e0639dc5SOlga Kornievskaia 	__be32 status;
1193e0639dc5SOlga Kornievskaia 	ssize_t bytes;
1194e0639dc5SOlga Kornievskaia 
1195e0639dc5SOlga Kornievskaia 	bytes = _nfsd_copy_file_range(copy);
1196e0639dc5SOlga Kornievskaia 	/* for async copy, we ignore the error, client can always retry
1197e0639dc5SOlga Kornievskaia 	 * to get the error
1198e0639dc5SOlga Kornievskaia 	 */
1199e0639dc5SOlga Kornievskaia 	if (bytes < 0 && !copy->cp_res.wr_bytes_written)
1200e0639dc5SOlga Kornievskaia 		status = nfserrno(bytes);
1201e0639dc5SOlga Kornievskaia 	else {
1202e0639dc5SOlga Kornievskaia 		nfsd4_init_copy_res(copy, sync);
1203e0639dc5SOlga Kornievskaia 		status = nfs_ok;
1204e0639dc5SOlga Kornievskaia 	}
1205e0639dc5SOlga Kornievskaia 
1206e0639dc5SOlga Kornievskaia 	fput(copy->file_src);
1207e0639dc5SOlga Kornievskaia 	fput(copy->file_dst);
1208e0639dc5SOlga Kornievskaia 	return status;
1209e0639dc5SOlga Kornievskaia }
1210e0639dc5SOlga Kornievskaia 
1211e0639dc5SOlga Kornievskaia static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
1212e0639dc5SOlga Kornievskaia {
1213e0639dc5SOlga Kornievskaia 	dst->cp_src_pos = src->cp_src_pos;
1214e0639dc5SOlga Kornievskaia 	dst->cp_dst_pos = src->cp_dst_pos;
1215e0639dc5SOlga Kornievskaia 	dst->cp_count = src->cp_count;
1216e0639dc5SOlga Kornievskaia 	dst->cp_synchronous = src->cp_synchronous;
1217e0639dc5SOlga Kornievskaia 	memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
1218e0639dc5SOlga Kornievskaia 	memcpy(&dst->fh, &src->fh, sizeof(src->fh));
1219e0639dc5SOlga Kornievskaia 	dst->cp_clp = src->cp_clp;
1220e0639dc5SOlga Kornievskaia 	dst->file_dst = get_file(src->file_dst);
1221e0639dc5SOlga Kornievskaia 	dst->file_src = get_file(src->file_src);
1222e0639dc5SOlga Kornievskaia 	memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
1223e0639dc5SOlga Kornievskaia }
1224e0639dc5SOlga Kornievskaia 
1225e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy)
1226e0639dc5SOlga Kornievskaia {
1227e0639dc5SOlga Kornievskaia 	nfs4_free_cp_state(copy);
1228e0639dc5SOlga Kornievskaia 	fput(copy->file_dst);
1229e0639dc5SOlga Kornievskaia 	fput(copy->file_src);
1230e0639dc5SOlga Kornievskaia 	spin_lock(&copy->cp_clp->async_lock);
1231e0639dc5SOlga Kornievskaia 	list_del(&copy->copies);
1232e0639dc5SOlga Kornievskaia 	spin_unlock(&copy->cp_clp->async_lock);
1233e0639dc5SOlga Kornievskaia 	nfs4_put_copy(copy);
1234e0639dc5SOlga Kornievskaia }
1235e0639dc5SOlga Kornievskaia 
1236e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data)
1237e0639dc5SOlga Kornievskaia {
1238e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1239e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *cb_copy;
1240e0639dc5SOlga Kornievskaia 
1241e0639dc5SOlga Kornievskaia 	copy->nfserr = nfsd4_do_copy(copy, 0);
1242e0639dc5SOlga Kornievskaia 	cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1243e0639dc5SOlga Kornievskaia 	if (!cb_copy)
1244e0639dc5SOlga Kornievskaia 		goto out;
1245e0639dc5SOlga Kornievskaia 	memcpy(&cb_copy->cp_res, &copy->cp_res, sizeof(copy->cp_res));
1246e0639dc5SOlga Kornievskaia 	cb_copy->cp_clp = copy->cp_clp;
1247e0639dc5SOlga Kornievskaia 	cb_copy->nfserr = copy->nfserr;
1248e0639dc5SOlga Kornievskaia 	memcpy(&cb_copy->fh, &copy->fh, sizeof(copy->fh));
1249e0639dc5SOlga Kornievskaia 	nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp,
1250e0639dc5SOlga Kornievskaia 			&nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD);
1251e0639dc5SOlga Kornievskaia 	nfsd4_run_cb(&cb_copy->cp_cb);
1252e0639dc5SOlga Kornievskaia out:
1253e0639dc5SOlga Kornievskaia 	cleanup_async_copy(copy);
1254e0639dc5SOlga Kornievskaia 	return 0;
1255e0639dc5SOlga Kornievskaia }
1256e0639dc5SOlga Kornievskaia 
1257ffa0160aSChristoph Hellwig static __be32
125829ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1259eb69853dSChristoph Hellwig 		union nfsd4_op_u *u)
126029ae7f9dSAnna Schumaker {
1261eb69853dSChristoph Hellwig 	struct nfsd4_copy *copy = &u->copy;
126229ae7f9dSAnna Schumaker 	__be32 status;
1263e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *async_copy = NULL;
126429ae7f9dSAnna Schumaker 
1265e0639dc5SOlga Kornievskaia 	status = nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid,
1266e0639dc5SOlga Kornievskaia 				   &copy->file_src, &copy->cp_dst_stateid,
1267e0639dc5SOlga Kornievskaia 				   &copy->file_dst);
126829ae7f9dSAnna Schumaker 	if (status)
126929ae7f9dSAnna Schumaker 		goto out;
127029ae7f9dSAnna Schumaker 
1271e0639dc5SOlga Kornievskaia 	copy->cp_clp = cstate->clp;
1272e0639dc5SOlga Kornievskaia 	memcpy(&copy->fh, &cstate->current_fh.fh_handle,
1273e0639dc5SOlga Kornievskaia 		sizeof(struct knfsd_fh));
1274e0639dc5SOlga Kornievskaia 	if (!copy->cp_synchronous) {
1275e0639dc5SOlga Kornievskaia 		struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
127629ae7f9dSAnna Schumaker 
1277e0639dc5SOlga Kornievskaia 		status = nfserrno(-ENOMEM);
1278e0639dc5SOlga Kornievskaia 		async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1279e0639dc5SOlga Kornievskaia 		if (!async_copy)
1280e0639dc5SOlga Kornievskaia 			goto out;
1281e0639dc5SOlga Kornievskaia 		if (!nfs4_init_cp_state(nn, copy)) {
1282e0639dc5SOlga Kornievskaia 			kfree(async_copy);
1283e0639dc5SOlga Kornievskaia 			goto out;
128429ae7f9dSAnna Schumaker 		}
1285e0639dc5SOlga Kornievskaia 		refcount_set(&async_copy->refcount, 1);
1286e0639dc5SOlga Kornievskaia 		memcpy(&copy->cp_res.cb_stateid, &copy->cp_stateid,
1287e0639dc5SOlga Kornievskaia 			sizeof(copy->cp_stateid));
1288e0639dc5SOlga Kornievskaia 		dup_copy_fields(copy, async_copy);
1289e0639dc5SOlga Kornievskaia 		async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
1290e0639dc5SOlga Kornievskaia 				async_copy, "%s", "copy thread");
1291e0639dc5SOlga Kornievskaia 		if (IS_ERR(async_copy->copy_task))
1292e0639dc5SOlga Kornievskaia 			goto out_err;
1293e0639dc5SOlga Kornievskaia 		spin_lock(&async_copy->cp_clp->async_lock);
1294e0639dc5SOlga Kornievskaia 		list_add(&async_copy->copies,
1295e0639dc5SOlga Kornievskaia 				&async_copy->cp_clp->async_copies);
1296e0639dc5SOlga Kornievskaia 		spin_unlock(&async_copy->cp_clp->async_lock);
1297e0639dc5SOlga Kornievskaia 		wake_up_process(async_copy->copy_task);
1298e0639dc5SOlga Kornievskaia 		status = nfs_ok;
1299e0639dc5SOlga Kornievskaia 	} else
1300e0639dc5SOlga Kornievskaia 		status = nfsd4_do_copy(copy, 1);
130129ae7f9dSAnna Schumaker out:
130229ae7f9dSAnna Schumaker 	return status;
1303e0639dc5SOlga Kornievskaia out_err:
1304e0639dc5SOlga Kornievskaia 	cleanup_async_copy(async_copy);
1305e0639dc5SOlga Kornievskaia 	goto out;
1306e0639dc5SOlga Kornievskaia }
1307e0639dc5SOlga Kornievskaia 
1308e0639dc5SOlga Kornievskaia struct nfsd4_copy *
1309e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
1310e0639dc5SOlga Kornievskaia {
1311e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy;
1312e0639dc5SOlga Kornievskaia 
1313e0639dc5SOlga Kornievskaia 	spin_lock(&clp->async_lock);
1314e0639dc5SOlga Kornievskaia 	list_for_each_entry(copy, &clp->async_copies, copies) {
1315e0639dc5SOlga Kornievskaia 		if (memcmp(&copy->cp_stateid, stateid, NFS4_STATEID_SIZE))
1316e0639dc5SOlga Kornievskaia 			continue;
1317e0639dc5SOlga Kornievskaia 		refcount_inc(&copy->refcount);
1318e0639dc5SOlga Kornievskaia 		spin_unlock(&clp->async_lock);
1319e0639dc5SOlga Kornievskaia 		return copy;
1320e0639dc5SOlga Kornievskaia 	}
1321e0639dc5SOlga Kornievskaia 	spin_unlock(&clp->async_lock);
1322e0639dc5SOlga Kornievskaia 	return NULL;
132329ae7f9dSAnna Schumaker }
132429ae7f9dSAnna Schumaker 
132529ae7f9dSAnna Schumaker static __be32
1326885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp,
1327885e2bf3SOlga Kornievskaia 		     struct nfsd4_compound_state *cstate,
1328885e2bf3SOlga Kornievskaia 		     union nfsd4_op_u *u)
1329885e2bf3SOlga Kornievskaia {
1330e0639dc5SOlga Kornievskaia 	struct nfsd4_offload_status *os = &u->offload_status;
1331e0639dc5SOlga Kornievskaia 	__be32 status = 0;
1332e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy;
1333e0639dc5SOlga Kornievskaia 	struct nfs4_client *clp = cstate->clp;
1334e0639dc5SOlga Kornievskaia 
1335e0639dc5SOlga Kornievskaia 	copy = find_async_copy(clp, &os->stateid);
1336e0639dc5SOlga Kornievskaia 	if (copy)
1337e0639dc5SOlga Kornievskaia 		nfsd4_stop_copy(copy);
1338e0639dc5SOlga Kornievskaia 	else
1339e0639dc5SOlga Kornievskaia 		status = nfserr_bad_stateid;
1340e0639dc5SOlga Kornievskaia 
1341e0639dc5SOlga Kornievskaia 	return status;
1342885e2bf3SOlga Kornievskaia }
1343885e2bf3SOlga Kornievskaia 
1344885e2bf3SOlga Kornievskaia static __be32
134595d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
134695d871f0SAnna Schumaker 		struct nfsd4_fallocate *fallocate, int flags)
134795d871f0SAnna Schumaker {
13480d4d6720SJ. Bruce Fields 	__be32 status;
134995d871f0SAnna Schumaker 	struct file *file;
135095d871f0SAnna Schumaker 
1351aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
135295d871f0SAnna Schumaker 					    &fallocate->falloc_stateid,
1353af90f707SChristoph Hellwig 					    WR_STATE, &file, NULL);
135495d871f0SAnna Schumaker 	if (status != nfs_ok) {
135595d871f0SAnna Schumaker 		dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
135695d871f0SAnna Schumaker 		return status;
135795d871f0SAnna Schumaker 	}
135895d871f0SAnna Schumaker 
135995d871f0SAnna Schumaker 	status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
136095d871f0SAnna Schumaker 				     fallocate->falloc_offset,
136195d871f0SAnna Schumaker 				     fallocate->falloc_length,
136295d871f0SAnna Schumaker 				     flags);
136395d871f0SAnna Schumaker 	fput(file);
136495d871f0SAnna Schumaker 	return status;
136595d871f0SAnna Schumaker }
13666308bc98SOlga Kornievskaia static __be32
13676308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp,
13686308bc98SOlga Kornievskaia 		     struct nfsd4_compound_state *cstate,
13696308bc98SOlga Kornievskaia 		     union nfsd4_op_u *u)
13706308bc98SOlga Kornievskaia {
1371e0639dc5SOlga Kornievskaia 	struct nfsd4_offload_status *os = &u->offload_status;
1372e0639dc5SOlga Kornievskaia 	__be32 status = 0;
1373e0639dc5SOlga Kornievskaia 	struct nfsd4_copy *copy;
1374e0639dc5SOlga Kornievskaia 	struct nfs4_client *clp = cstate->clp;
1375e0639dc5SOlga Kornievskaia 
1376e0639dc5SOlga Kornievskaia 	copy = find_async_copy(clp, &os->stateid);
1377e0639dc5SOlga Kornievskaia 	if (copy) {
1378e0639dc5SOlga Kornievskaia 		os->count = copy->cp_res.wr_bytes_written;
1379e0639dc5SOlga Kornievskaia 		nfs4_put_copy(copy);
1380e0639dc5SOlga Kornievskaia 	} else
1381e0639dc5SOlga Kornievskaia 		status = nfserr_bad_stateid;
1382e0639dc5SOlga Kornievskaia 
1383e0639dc5SOlga Kornievskaia 	return status;
13846308bc98SOlga Kornievskaia }
138595d871f0SAnna Schumaker 
138695d871f0SAnna Schumaker static __be32
138795d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1388eb69853dSChristoph Hellwig 	       union nfsd4_op_u *u)
138995d871f0SAnna Schumaker {
1390eb69853dSChristoph Hellwig 	return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
139195d871f0SAnna Schumaker }
139295d871f0SAnna Schumaker 
139395d871f0SAnna Schumaker static __be32
1394b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1395eb69853dSChristoph Hellwig 		 union nfsd4_op_u *u)
1396b0cb9085SAnna Schumaker {
1397eb69853dSChristoph Hellwig 	return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
1398b0cb9085SAnna Schumaker 			       FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
1399b0cb9085SAnna Schumaker }
1400b0cb9085SAnna Schumaker 
1401b0cb9085SAnna Schumaker static __be32
140224bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1403eb69853dSChristoph Hellwig 	   union nfsd4_op_u *u)
140424bab491SAnna Schumaker {
1405eb69853dSChristoph Hellwig 	struct nfsd4_seek *seek = &u->seek;
140624bab491SAnna Schumaker 	int whence;
140724bab491SAnna Schumaker 	__be32 status;
140824bab491SAnna Schumaker 	struct file *file;
140924bab491SAnna Schumaker 
1410aa0d6aedSAnna Schumaker 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
141124bab491SAnna Schumaker 					    &seek->seek_stateid,
1412af90f707SChristoph Hellwig 					    RD_STATE, &file, NULL);
141324bab491SAnna Schumaker 	if (status) {
141424bab491SAnna Schumaker 		dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
141524bab491SAnna Schumaker 		return status;
141624bab491SAnna Schumaker 	}
141724bab491SAnna Schumaker 
141824bab491SAnna Schumaker 	switch (seek->seek_whence) {
141924bab491SAnna Schumaker 	case NFS4_CONTENT_DATA:
142024bab491SAnna Schumaker 		whence = SEEK_DATA;
142124bab491SAnna Schumaker 		break;
142224bab491SAnna Schumaker 	case NFS4_CONTENT_HOLE:
142324bab491SAnna Schumaker 		whence = SEEK_HOLE;
142424bab491SAnna Schumaker 		break;
142524bab491SAnna Schumaker 	default:
142624bab491SAnna Schumaker 		status = nfserr_union_notsupp;
142724bab491SAnna Schumaker 		goto out;
142824bab491SAnna Schumaker 	}
142924bab491SAnna Schumaker 
143024bab491SAnna Schumaker 	/*
143124bab491SAnna Schumaker 	 * Note:  This call does change file->f_pos, but nothing in NFSD
143224bab491SAnna Schumaker 	 *        should ever file->f_pos.
143324bab491SAnna Schumaker 	 */
143424bab491SAnna Schumaker 	seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
143524bab491SAnna Schumaker 	if (seek->seek_pos < 0)
143624bab491SAnna Schumaker 		status = nfserrno(seek->seek_pos);
143724bab491SAnna Schumaker 	else if (seek->seek_pos >= i_size_read(file_inode(file)))
143824bab491SAnna Schumaker 		seek->seek_eof = true;
143924bab491SAnna Schumaker 
144024bab491SAnna Schumaker out:
144124bab491SAnna Schumaker 	fput(file);
144224bab491SAnna Schumaker 	return status;
144324bab491SAnna Schumaker }
144424bab491SAnna Schumaker 
14451da177e4SLinus Torvalds /* This routine never returns NFS_OK!  If there are no other errors, it
14461da177e4SLinus Torvalds  * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
14471da177e4SLinus Torvalds  * attributes matched.  VERIFY is implemented by mapping NFSERR_SAME
14481da177e4SLinus Torvalds  * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
14491da177e4SLinus Torvalds  */
1450b37ad28bSAl Viro static __be32
1451c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1452ca364317SJ.Bruce Fields 	     struct nfsd4_verify *verify)
14531da177e4SLinus Torvalds {
14542ebbc012SAl Viro 	__be32 *buf, *p;
14551da177e4SLinus Torvalds 	int count;
1456b37ad28bSAl Viro 	__be32 status;
14571da177e4SLinus Torvalds 
14588837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
14591da177e4SLinus Torvalds 	if (status)
14601da177e4SLinus Torvalds 		return status;
14611da177e4SLinus Torvalds 
14623c8e0316SYu Zhiguo 	status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
14633c8e0316SYu Zhiguo 	if (status)
14643c8e0316SYu Zhiguo 		return status;
14653c8e0316SYu Zhiguo 
14661da177e4SLinus Torvalds 	if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
14671da177e4SLinus Torvalds 	    || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
14681da177e4SLinus Torvalds 		return nfserr_inval;
14691da177e4SLinus Torvalds 	if (verify->ve_attrlen & 3)
14701da177e4SLinus Torvalds 		return nfserr_inval;
14711da177e4SLinus Torvalds 
14721da177e4SLinus Torvalds 	/* count in words:
14731da177e4SLinus Torvalds 	 *   bitmap_len(1) + bitmap(2) + attr_len(1) = 4
14741da177e4SLinus Torvalds 	 */
14751da177e4SLinus Torvalds 	count = 4 + (verify->ve_attrlen >> 2);
14761da177e4SLinus Torvalds 	buf = kmalloc(count << 2, GFP_KERNEL);
14771da177e4SLinus Torvalds 	if (!buf)
14783e772463SJ. Bruce Fields 		return nfserr_jukebox;
14791da177e4SLinus Torvalds 
148084822d0bSJ. Bruce Fields 	p = buf;
1481d5184658SJ. Bruce Fields 	status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
1482ca364317SJ.Bruce Fields 				    cstate->current_fh.fh_export,
1483d5184658SJ. Bruce Fields 				    cstate->current_fh.fh_dentry,
1484d5184658SJ. Bruce Fields 				    verify->ve_bmval,
1485406a7ea9SFrank Filz 				    rqstp, 0);
148641ae6e71SJ. Bruce Fields 	/*
148741ae6e71SJ. Bruce Fields 	 * If nfsd4_encode_fattr() ran out of space, assume that's because
148841ae6e71SJ. Bruce Fields 	 * the attributes are longer (hence different) than those given:
148941ae6e71SJ. Bruce Fields 	 */
149084822d0bSJ. Bruce Fields 	if (status == nfserr_resource)
14911da177e4SLinus Torvalds 		status = nfserr_not_same;
14921da177e4SLinus Torvalds 	if (status)
14931da177e4SLinus Torvalds 		goto out_kfree;
14941da177e4SLinus Torvalds 
149595ec28cdSBenny Halevy 	/* skip bitmap */
149695ec28cdSBenny Halevy 	p = buf + 1 + ntohl(buf[0]);
14971da177e4SLinus Torvalds 	status = nfserr_not_same;
14981da177e4SLinus Torvalds 	if (ntohl(*p++) != verify->ve_attrlen)
14991da177e4SLinus Torvalds 		goto out_kfree;
15001da177e4SLinus Torvalds 	if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
15011da177e4SLinus Torvalds 		status = nfserr_same;
15021da177e4SLinus Torvalds 
15031da177e4SLinus Torvalds out_kfree:
15041da177e4SLinus Torvalds 	kfree(buf);
15051da177e4SLinus Torvalds 	return status;
15061da177e4SLinus Torvalds }
15071da177e4SLinus Torvalds 
1508c954e2a5SJ.Bruce Fields static __be32
1509c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1510eb69853dSChristoph Hellwig 	      union nfsd4_op_u *u)
1511c954e2a5SJ.Bruce Fields {
1512c954e2a5SJ.Bruce Fields 	__be32 status;
1513c954e2a5SJ.Bruce Fields 
1514eb69853dSChristoph Hellwig 	status = _nfsd4_verify(rqstp, cstate, &u->verify);
1515c954e2a5SJ.Bruce Fields 	return status == nfserr_not_same ? nfs_ok : status;
1516c954e2a5SJ.Bruce Fields }
1517c954e2a5SJ.Bruce Fields 
1518c954e2a5SJ.Bruce Fields static __be32
1519c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1520eb69853dSChristoph Hellwig 	     union nfsd4_op_u *u)
1521c954e2a5SJ.Bruce Fields {
1522c954e2a5SJ.Bruce Fields 	__be32 status;
1523c954e2a5SJ.Bruce Fields 
1524eb69853dSChristoph Hellwig 	status = _nfsd4_verify(rqstp, cstate, &u->nverify);
1525c954e2a5SJ.Bruce Fields 	return status == nfserr_same ? nfs_ok : status;
1526c954e2a5SJ.Bruce Fields }
1527c954e2a5SJ.Bruce Fields 
15289cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
15299cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops *
15309cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
15319cf514ccSChristoph Hellwig {
15328a4c3926SJeff Layton 	if (!exp->ex_layout_types) {
15339cf514ccSChristoph Hellwig 		dprintk("%s: export does not support pNFS\n", __func__);
15349cf514ccSChristoph Hellwig 		return NULL;
15359cf514ccSChristoph Hellwig 	}
15369cf514ccSChristoph Hellwig 
1537b550a32eSAri Kauppi 	if (layout_type >= LAYOUT_TYPE_MAX ||
1538b550a32eSAri Kauppi 	    !(exp->ex_layout_types & (1 << layout_type))) {
15399cf514ccSChristoph Hellwig 		dprintk("%s: layout type %d not supported\n",
15409cf514ccSChristoph Hellwig 			__func__, layout_type);
15419cf514ccSChristoph Hellwig 		return NULL;
15429cf514ccSChristoph Hellwig 	}
15439cf514ccSChristoph Hellwig 
15449cf514ccSChristoph Hellwig 	return nfsd4_layout_ops[layout_type];
15459cf514ccSChristoph Hellwig }
15469cf514ccSChristoph Hellwig 
15479cf514ccSChristoph Hellwig static __be32
15489cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
1549eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
15509cf514ccSChristoph Hellwig {
1551eb69853dSChristoph Hellwig 	struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
15529cf514ccSChristoph Hellwig 	const struct nfsd4_layout_ops *ops;
15539cf514ccSChristoph Hellwig 	struct nfsd4_deviceid_map *map;
15549cf514ccSChristoph Hellwig 	struct svc_export *exp;
15559cf514ccSChristoph Hellwig 	__be32 nfserr;
15569cf514ccSChristoph Hellwig 
15579cf514ccSChristoph Hellwig 	dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
15589cf514ccSChristoph Hellwig 	       __func__,
15599cf514ccSChristoph Hellwig 	       gdp->gd_layout_type,
15609cf514ccSChristoph Hellwig 	       gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
15619cf514ccSChristoph Hellwig 	       gdp->gd_maxcount);
15629cf514ccSChristoph Hellwig 
15639cf514ccSChristoph Hellwig 	map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
15649cf514ccSChristoph Hellwig 	if (!map) {
15659cf514ccSChristoph Hellwig 		dprintk("%s: couldn't find device ID to export mapping!\n",
15669cf514ccSChristoph Hellwig 			__func__);
15679cf514ccSChristoph Hellwig 		return nfserr_noent;
15689cf514ccSChristoph Hellwig 	}
15699cf514ccSChristoph Hellwig 
15709cf514ccSChristoph Hellwig 	exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
15719cf514ccSChristoph Hellwig 	if (IS_ERR(exp)) {
15729cf514ccSChristoph Hellwig 		dprintk("%s: could not find device id\n", __func__);
15739cf514ccSChristoph Hellwig 		return nfserr_noent;
15749cf514ccSChristoph Hellwig 	}
15759cf514ccSChristoph Hellwig 
15769cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
15779cf514ccSChristoph Hellwig 	ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
15789cf514ccSChristoph Hellwig 	if (!ops)
15799cf514ccSChristoph Hellwig 		goto out;
15809cf514ccSChristoph Hellwig 
15819cf514ccSChristoph Hellwig 	nfserr = nfs_ok;
1582f99d4fbdSChristoph Hellwig 	if (gdp->gd_maxcount != 0) {
1583f99d4fbdSChristoph Hellwig 		nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
1584d7c920d1STom Haynes 				rqstp, cstate->session->se_client, gdp);
1585f99d4fbdSChristoph Hellwig 	}
15869cf514ccSChristoph Hellwig 
15879cf514ccSChristoph Hellwig 	gdp->gd_notify_types &= ops->notify_types;
15889cf514ccSChristoph Hellwig out:
1589a1420384SKinglong Mee 	exp_put(exp);
15909cf514ccSChristoph Hellwig 	return nfserr;
15919cf514ccSChristoph Hellwig }
15929cf514ccSChristoph Hellwig 
159334b1744cSJ. Bruce Fields static void
159434b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
159534b1744cSJ. Bruce Fields {
159634b1744cSJ. Bruce Fields 	kfree(u->getdeviceinfo.gd_device);
159734b1744cSJ. Bruce Fields }
159834b1744cSJ. Bruce Fields 
15999cf514ccSChristoph Hellwig static __be32
16009cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp,
1601eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
16029cf514ccSChristoph Hellwig {
1603eb69853dSChristoph Hellwig 	struct nfsd4_layoutget *lgp = &u->layoutget;
16049cf514ccSChristoph Hellwig 	struct svc_fh *current_fh = &cstate->current_fh;
16059cf514ccSChristoph Hellwig 	const struct nfsd4_layout_ops *ops;
16069cf514ccSChristoph Hellwig 	struct nfs4_layout_stateid *ls;
16079cf514ccSChristoph Hellwig 	__be32 nfserr;
160866282ec1SBenjamin Coddington 	int accmode = NFSD_MAY_READ_IF_EXEC;
16099cf514ccSChristoph Hellwig 
16109cf514ccSChristoph Hellwig 	switch (lgp->lg_seg.iomode) {
16119cf514ccSChristoph Hellwig 	case IOMODE_READ:
161266282ec1SBenjamin Coddington 		accmode |= NFSD_MAY_READ;
16139cf514ccSChristoph Hellwig 		break;
16149cf514ccSChristoph Hellwig 	case IOMODE_RW:
161566282ec1SBenjamin Coddington 		accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
16169cf514ccSChristoph Hellwig 		break;
16179cf514ccSChristoph Hellwig 	default:
16189cf514ccSChristoph Hellwig 		dprintk("%s: invalid iomode %d\n",
16199cf514ccSChristoph Hellwig 			__func__, lgp->lg_seg.iomode);
16209cf514ccSChristoph Hellwig 		nfserr = nfserr_badiomode;
16219cf514ccSChristoph Hellwig 		goto out;
16229cf514ccSChristoph Hellwig 	}
16239cf514ccSChristoph Hellwig 
16249cf514ccSChristoph Hellwig 	nfserr = fh_verify(rqstp, current_fh, 0, accmode);
16259cf514ccSChristoph Hellwig 	if (nfserr)
16269cf514ccSChristoph Hellwig 		goto out;
16279cf514ccSChristoph Hellwig 
16289cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
16299cf514ccSChristoph Hellwig 	ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
16309cf514ccSChristoph Hellwig 	if (!ops)
16319cf514ccSChristoph Hellwig 		goto out;
16329cf514ccSChristoph Hellwig 
16339cf514ccSChristoph Hellwig 	/*
16349cf514ccSChristoph Hellwig 	 * Verify minlength and range as per RFC5661:
16359cf514ccSChristoph Hellwig 	 *  o  If loga_length is less than loga_minlength,
16369cf514ccSChristoph Hellwig 	 *     the metadata server MUST return NFS4ERR_INVAL.
16379cf514ccSChristoph Hellwig 	 *  o  If the sum of loga_offset and loga_minlength exceeds
16389cf514ccSChristoph Hellwig 	 *     NFS4_UINT64_MAX, and loga_minlength is not
16399cf514ccSChristoph Hellwig 	 *     NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
16409cf514ccSChristoph Hellwig 	 *  o  If the sum of loga_offset and loga_length exceeds
16419cf514ccSChristoph Hellwig 	 *     NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
16429cf514ccSChristoph Hellwig 	 *     the error NFS4ERR_INVAL MUST result.
16439cf514ccSChristoph Hellwig 	 */
16449cf514ccSChristoph Hellwig 	nfserr = nfserr_inval;
16459cf514ccSChristoph Hellwig 	if (lgp->lg_seg.length < lgp->lg_minlength ||
16469cf514ccSChristoph Hellwig 	    (lgp->lg_minlength != NFS4_MAX_UINT64 &&
16479cf514ccSChristoph Hellwig 	     lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
16489cf514ccSChristoph Hellwig 	    (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
16499cf514ccSChristoph Hellwig 	     lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
16509cf514ccSChristoph Hellwig 		goto out;
16519cf514ccSChristoph Hellwig 	if (lgp->lg_seg.length == 0)
16529cf514ccSChristoph Hellwig 		goto out;
16539cf514ccSChristoph Hellwig 
16549cf514ccSChristoph Hellwig 	nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
16559cf514ccSChristoph Hellwig 						true, lgp->lg_layout_type, &ls);
165631ef83dcSChristoph Hellwig 	if (nfserr) {
1657f394b62bSChuck Lever 		trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
16589cf514ccSChristoph Hellwig 		goto out;
165931ef83dcSChristoph Hellwig 	}
16609cf514ccSChristoph Hellwig 
1661c5c707f9SChristoph Hellwig 	nfserr = nfserr_recallconflict;
1662c5c707f9SChristoph Hellwig 	if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
1663c5c707f9SChristoph Hellwig 		goto out_put_stid;
1664c5c707f9SChristoph Hellwig 
16652b0143b5SDavid Howells 	nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
16669cf514ccSChristoph Hellwig 				     current_fh, lgp);
16679cf514ccSChristoph Hellwig 	if (nfserr)
16689cf514ccSChristoph Hellwig 		goto out_put_stid;
16699cf514ccSChristoph Hellwig 
16709cf514ccSChristoph Hellwig 	nfserr = nfsd4_insert_layout(lgp, ls);
16719cf514ccSChristoph Hellwig 
16729cf514ccSChristoph Hellwig out_put_stid:
1673cc8a5532SJeff Layton 	mutex_unlock(&ls->ls_mutex);
16749cf514ccSChristoph Hellwig 	nfs4_put_stid(&ls->ls_stid);
16759cf514ccSChristoph Hellwig out:
16769cf514ccSChristoph Hellwig 	return nfserr;
16779cf514ccSChristoph Hellwig }
16789cf514ccSChristoph Hellwig 
167934b1744cSJ. Bruce Fields static void
168034b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u)
168134b1744cSJ. Bruce Fields {
168234b1744cSJ. Bruce Fields 	kfree(u->layoutget.lg_content);
168334b1744cSJ. Bruce Fields }
168434b1744cSJ. Bruce Fields 
16859cf514ccSChristoph Hellwig static __be32
16869cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp,
1687eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
16889cf514ccSChristoph Hellwig {
1689eb69853dSChristoph Hellwig 	struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
16909cf514ccSChristoph Hellwig 	const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
16919cf514ccSChristoph Hellwig 	struct svc_fh *current_fh = &cstate->current_fh;
16929cf514ccSChristoph Hellwig 	const struct nfsd4_layout_ops *ops;
16939cf514ccSChristoph Hellwig 	loff_t new_size = lcp->lc_last_wr + 1;
16949cf514ccSChristoph Hellwig 	struct inode *inode;
16959cf514ccSChristoph Hellwig 	struct nfs4_layout_stateid *ls;
16969cf514ccSChristoph Hellwig 	__be32 nfserr;
16979cf514ccSChristoph Hellwig 
16989cf514ccSChristoph Hellwig 	nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
16999cf514ccSChristoph Hellwig 	if (nfserr)
17009cf514ccSChristoph Hellwig 		goto out;
17019cf514ccSChristoph Hellwig 
17029cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
17039cf514ccSChristoph Hellwig 	ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
17049cf514ccSChristoph Hellwig 	if (!ops)
17059cf514ccSChristoph Hellwig 		goto out;
17062b0143b5SDavid Howells 	inode = d_inode(current_fh->fh_dentry);
17079cf514ccSChristoph Hellwig 
17089cf514ccSChristoph Hellwig 	nfserr = nfserr_inval;
17099cf514ccSChristoph Hellwig 	if (new_size <= seg->offset) {
17109cf514ccSChristoph Hellwig 		dprintk("pnfsd: last write before layout segment\n");
17119cf514ccSChristoph Hellwig 		goto out;
17129cf514ccSChristoph Hellwig 	}
17139cf514ccSChristoph Hellwig 	if (new_size > seg->offset + seg->length) {
17149cf514ccSChristoph Hellwig 		dprintk("pnfsd: last write beyond layout segment\n");
17159cf514ccSChristoph Hellwig 		goto out;
17169cf514ccSChristoph Hellwig 	}
17179cf514ccSChristoph Hellwig 	if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
17189cf514ccSChristoph Hellwig 		dprintk("pnfsd: layoutcommit beyond EOF\n");
17199cf514ccSChristoph Hellwig 		goto out;
17209cf514ccSChristoph Hellwig 	}
17219cf514ccSChristoph Hellwig 
17229cf514ccSChristoph Hellwig 	nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
17239cf514ccSChristoph Hellwig 						false, lcp->lc_layout_type,
17249cf514ccSChristoph Hellwig 						&ls);
17259cf514ccSChristoph Hellwig 	if (nfserr) {
1726f394b62bSChuck Lever 		trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
17279cf514ccSChristoph Hellwig 		/* fixup error code as per RFC5661 */
17289cf514ccSChristoph Hellwig 		if (nfserr == nfserr_bad_stateid)
17299cf514ccSChristoph Hellwig 			nfserr = nfserr_badlayout;
17309cf514ccSChristoph Hellwig 		goto out;
17319cf514ccSChristoph Hellwig 	}
17329cf514ccSChristoph Hellwig 
1733cc8a5532SJeff Layton 	/* LAYOUTCOMMIT does not require any serialization */
1734cc8a5532SJeff Layton 	mutex_unlock(&ls->ls_mutex);
1735cc8a5532SJeff Layton 
17369cf514ccSChristoph Hellwig 	if (new_size > i_size_read(inode)) {
17379cf514ccSChristoph Hellwig 		lcp->lc_size_chg = 1;
17389cf514ccSChristoph Hellwig 		lcp->lc_newsize = new_size;
17399cf514ccSChristoph Hellwig 	} else {
17409cf514ccSChristoph Hellwig 		lcp->lc_size_chg = 0;
17419cf514ccSChristoph Hellwig 	}
17429cf514ccSChristoph Hellwig 
1743d8398fc1SKinglong Mee 	nfserr = ops->proc_layoutcommit(inode, lcp);
17449cf514ccSChristoph Hellwig 	nfs4_put_stid(&ls->ls_stid);
17459cf514ccSChristoph Hellwig out:
17469cf514ccSChristoph Hellwig 	return nfserr;
17479cf514ccSChristoph Hellwig }
17489cf514ccSChristoph Hellwig 
17499cf514ccSChristoph Hellwig static __be32
17509cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp,
1751eb69853dSChristoph Hellwig 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
17529cf514ccSChristoph Hellwig {
1753eb69853dSChristoph Hellwig 	struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
17549cf514ccSChristoph Hellwig 	struct svc_fh *current_fh = &cstate->current_fh;
17559cf514ccSChristoph Hellwig 	__be32 nfserr;
17569cf514ccSChristoph Hellwig 
17579cf514ccSChristoph Hellwig 	nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
17589cf514ccSChristoph Hellwig 	if (nfserr)
17599cf514ccSChristoph Hellwig 		goto out;
17609cf514ccSChristoph Hellwig 
17619cf514ccSChristoph Hellwig 	nfserr = nfserr_layoutunavailable;
17629cf514ccSChristoph Hellwig 	if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
17639cf514ccSChristoph Hellwig 		goto out;
17649cf514ccSChristoph Hellwig 
17659cf514ccSChristoph Hellwig 	switch (lrp->lr_seg.iomode) {
17669cf514ccSChristoph Hellwig 	case IOMODE_READ:
17679cf514ccSChristoph Hellwig 	case IOMODE_RW:
17689cf514ccSChristoph Hellwig 	case IOMODE_ANY:
17699cf514ccSChristoph Hellwig 		break;
17709cf514ccSChristoph Hellwig 	default:
17719cf514ccSChristoph Hellwig 		dprintk("%s: invalid iomode %d\n", __func__,
17729cf514ccSChristoph Hellwig 			lrp->lr_seg.iomode);
17739cf514ccSChristoph Hellwig 		nfserr = nfserr_inval;
17749cf514ccSChristoph Hellwig 		goto out;
17759cf514ccSChristoph Hellwig 	}
17769cf514ccSChristoph Hellwig 
17779cf514ccSChristoph Hellwig 	switch (lrp->lr_return_type) {
17789cf514ccSChristoph Hellwig 	case RETURN_FILE:
17799cf514ccSChristoph Hellwig 		nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
17809cf514ccSChristoph Hellwig 		break;
17819cf514ccSChristoph Hellwig 	case RETURN_FSID:
17829cf514ccSChristoph Hellwig 	case RETURN_ALL:
17839cf514ccSChristoph Hellwig 		nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
17849cf514ccSChristoph Hellwig 		break;
17859cf514ccSChristoph Hellwig 	default:
17869cf514ccSChristoph Hellwig 		dprintk("%s: invalid return_type %d\n", __func__,
17879cf514ccSChristoph Hellwig 			lrp->lr_return_type);
17889cf514ccSChristoph Hellwig 		nfserr = nfserr_inval;
17899cf514ccSChristoph Hellwig 		break;
17909cf514ccSChristoph Hellwig 	}
17919cf514ccSChristoph Hellwig out:
17929cf514ccSChristoph Hellwig 	return nfserr;
17939cf514ccSChristoph Hellwig }
17949cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */
17959cf514ccSChristoph Hellwig 
17961da177e4SLinus Torvalds /*
17971da177e4SLinus Torvalds  * NULL call.
17981da177e4SLinus Torvalds  */
17997111c66eSAl Viro static __be32
1800a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp)
18011da177e4SLinus Torvalds {
18021da177e4SLinus Torvalds 	return nfs_ok;
18031da177e4SLinus Torvalds }
18041da177e4SLinus Torvalds 
1805e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum)
1806e2b20950SShankar Anand {
1807e2b20950SShankar Anand 	if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
1808e2b20950SShankar Anand 		nfsdstats.nfs4_opcount[opnum]++;
1809e2b20950SShankar Anand }
1810e2b20950SShankar Anand 
1811bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[];
1812b591480bSJ.Bruce Fields 
1813f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum);
1814b001a1b6SBenny Halevy 
18151da177e4SLinus Torvalds /*
181657716355SJ. Bruce Fields  * Enforce NFSv4.1 COMPOUND ordering rules:
1817f9bb94c4SAndy Adamson  *
181857716355SJ. Bruce Fields  * Also note, enforced elsewhere:
181957716355SJ. Bruce Fields  *	- SEQUENCE other than as first op results in
182057716355SJ. Bruce Fields  *	  NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
18211d1bc8f2SJ. Bruce Fields  *	- BIND_CONN_TO_SESSION must be the only op in its compound.
18221d1bc8f2SJ. Bruce Fields  *	  (Enforced in nfsd4_bind_conn_to_session().)
182357716355SJ. Bruce Fields  *	- DESTROY_SESSION must be the final operation in a compound, if
182457716355SJ. Bruce Fields  *	  sessionid's in SEQUENCE and DESTROY_SESSION are the same.
182557716355SJ. Bruce Fields  *	  (Enforced in nfsd4_destroy_session().)
1826f9bb94c4SAndy Adamson  */
182757716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
1828f9bb94c4SAndy Adamson {
18297a04cfdaSJ. Bruce Fields 	struct nfsd4_op *first_op = &args->ops[0];
183057716355SJ. Bruce Fields 
183157716355SJ. Bruce Fields 	/* These ordering requirements don't apply to NFSv4.0: */
183257716355SJ. Bruce Fields 	if (args->minorversion == 0)
183357716355SJ. Bruce Fields 		return nfs_ok;
183457716355SJ. Bruce Fields 	/* This is weird, but OK, not our problem: */
183557716355SJ. Bruce Fields 	if (args->opcnt == 0)
183657716355SJ. Bruce Fields 		return nfs_ok;
18377a04cfdaSJ. Bruce Fields 	if (first_op->status == nfserr_op_illegal)
183857716355SJ. Bruce Fields 		return nfs_ok;
18397a04cfdaSJ. Bruce Fields 	if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
184057716355SJ. Bruce Fields 		return nfserr_op_not_in_session;
18417a04cfdaSJ. Bruce Fields 	if (first_op->opnum == OP_SEQUENCE)
184257716355SJ. Bruce Fields 		return nfs_ok;
18437a04cfdaSJ. Bruce Fields 	/*
18447a04cfdaSJ. Bruce Fields 	 * So first_op is something allowed outside a session, like
18457a04cfdaSJ. Bruce Fields 	 * EXCHANGE_ID; but then it has to be the only op in the
18467a04cfdaSJ. Bruce Fields 	 * compound:
18477a04cfdaSJ. Bruce Fields 	 */
184857716355SJ. Bruce Fields 	if (args->opcnt != 1)
184957716355SJ. Bruce Fields 		return nfserr_not_only_op;
185057716355SJ. Bruce Fields 	return nfs_ok;
1851f9bb94c4SAndy Adamson }
1852f9bb94c4SAndy Adamson 
1853f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
185422b03214SJ. Bruce Fields {
185522b03214SJ. Bruce Fields 	return &nfsd4_ops[op->opnum];
185622b03214SJ. Bruce Fields }
185722b03214SJ. Bruce Fields 
18581091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op)
18591091006cSJ. Bruce Fields {
1860e372ba60SJ. Bruce Fields 	if (op->opnum == OP_ILLEGAL)
1861e372ba60SJ. Bruce Fields 		return false;
1862c856694eSJ. Bruce Fields 	return OPDESC(op)->op_flags & OP_CACHEME;
18631091006cSJ. Bruce Fields }
18641091006cSJ. Bruce Fields 
186568d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp)
186668d93184SJ. Bruce Fields {
186768d93184SJ. Bruce Fields 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
186868d93184SJ. Bruce Fields 	struct nfsd4_compoundargs *argp = rqstp->rq_argp;
186968d93184SJ. Bruce Fields 	struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
187068d93184SJ. Bruce Fields 	struct nfsd4_op *next = &argp->ops[resp->opcnt];
1871bb2a8b0cSChristoph Hellwig 	const struct nfsd4_operation *thisd = OPDESC(this);
1872bb2a8b0cSChristoph Hellwig 	const struct nfsd4_operation *nextd;
187368d93184SJ. Bruce Fields 
187468d93184SJ. Bruce Fields 	/*
187568d93184SJ. Bruce Fields 	 * Most ops check wronsec on our own; only the putfh-like ops
187668d93184SJ. Bruce Fields 	 * have special rules.
187768d93184SJ. Bruce Fields 	 */
187868d93184SJ. Bruce Fields 	if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
187968d93184SJ. Bruce Fields 		return false;
188068d93184SJ. Bruce Fields 	/*
188168d93184SJ. Bruce Fields 	 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
188268d93184SJ. Bruce Fields 	 * put-filehandle operation if we're not going to use the
188368d93184SJ. Bruce Fields 	 * result:
188468d93184SJ. Bruce Fields 	 */
188568d93184SJ. Bruce Fields 	if (argp->opcnt == resp->opcnt)
188668d93184SJ. Bruce Fields 		return false;
188751904b08SJ. Bruce Fields 	if (next->opnum == OP_ILLEGAL)
188851904b08SJ. Bruce Fields 		return false;
188968d93184SJ. Bruce Fields 	nextd = OPDESC(next);
189068d93184SJ. Bruce Fields 	/*
189168d93184SJ. Bruce Fields 	 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
189268d93184SJ. Bruce Fields 	 * errors themselves as necessary; others should check for them
189368d93184SJ. Bruce Fields 	 * now:
189468d93184SJ. Bruce Fields 	 */
189568d93184SJ. Bruce Fields 	return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
189668d93184SJ. Bruce Fields }
189768d93184SJ. Bruce Fields 
18982d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp,
18992d124dfaSJ. Bruce Fields 			       struct nfsd4_compoundres *resp)
19002d124dfaSJ. Bruce Fields {
19012d124dfaSJ. Bruce Fields 	struct xdr_stream *xdr = &resp->xdr;
19022d124dfaSJ. Bruce Fields 	struct xdr_buf *buf = &rqstp->rq_res;
19032d124dfaSJ. Bruce Fields 	struct kvec *head = buf->head;
19042d124dfaSJ. Bruce Fields 
19052d124dfaSJ. Bruce Fields 	xdr->buf = buf;
1906ddd1ea56SJ. Bruce Fields 	xdr->iov = head;
19072d124dfaSJ. Bruce Fields 	xdr->p   = head->iov_base + head->iov_len;
1908a5cddc88SJ. Bruce Fields 	xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
19096ac90391SJ. Bruce Fields 	/* Tail and page_len should be zero at this point: */
19106ac90391SJ. Bruce Fields 	buf->len = buf->head[0].iov_len;
19112825a7f9SJ. Bruce Fields 	xdr->scratch.iov_len = 0;
191205638dc7SJ. Bruce Fields 	xdr->page_ptr = buf->pages - 1;
19132825a7f9SJ. Bruce Fields 	buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
1914a5cddc88SJ. Bruce Fields 		- rqstp->rq_auth_slack;
19152d124dfaSJ. Bruce Fields }
19162d124dfaSJ. Bruce Fields 
1917f9bb94c4SAndy Adamson /*
19181da177e4SLinus Torvalds  * COMPOUND call.
19191da177e4SLinus Torvalds  */
19207111c66eSAl Viro static __be32
1921a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp)
19221da177e4SLinus Torvalds {
1923a6beb732SChristoph Hellwig 	struct nfsd4_compoundargs *args = rqstp->rq_argp;
1924a6beb732SChristoph Hellwig 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
19251da177e4SLinus Torvalds 	struct nfsd4_op	*op;
1926e354d571SAndy Adamson 	struct nfsd4_compound_state *cstate = &resp->cstate;
19274daeed25SKinglong Mee 	struct svc_fh *current_fh = &cstate->current_fh;
19284daeed25SKinglong Mee 	struct svc_fh *save_fh = &cstate->save_fh;
1929*e333f3bbSTrond Myklebust 	struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1930b37ad28bSAl Viro 	__be32		status;
19311da177e4SLinus Torvalds 
19322d124dfaSJ. Bruce Fields 	svcxdr_init_encode(rqstp, resp);
19334aea24b2SJ. Bruce Fields 	resp->tagp = resp->xdr.p;
19341da177e4SLinus Torvalds 	/* reserve space for: taglen, tag, and opcnt */
1935d3f627c8SJ. Bruce Fields 	xdr_reserve_space(&resp->xdr, 8 + args->taglen);
19361da177e4SLinus Torvalds 	resp->taglen = args->taglen;
19371da177e4SLinus Torvalds 	resp->tag = args->tag;
19381da177e4SLinus Torvalds 	resp->rqstp = rqstp;
19394daeed25SKinglong Mee 	cstate->minorversion = args->minorversion;
19404daeed25SKinglong Mee 	fh_init(current_fh, NFS4_FHSIZE);
19414daeed25SKinglong Mee 	fh_init(save_fh, NFS4_FHSIZE);
19428ff30fa4SNeilBrown 	/*
19438ff30fa4SNeilBrown 	 * Don't use the deferral mechanism for NFSv4; compounds make it
19448ff30fa4SNeilBrown 	 * too hard to avoid non-idempotency problems.
19458ff30fa4SNeilBrown 	 */
194630660e04SJeff Layton 	clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
19471da177e4SLinus Torvalds 
19481da177e4SLinus Torvalds 	/*
19491da177e4SLinus Torvalds 	 * According to RFC3010, this takes precedence over all other errors.
19501da177e4SLinus Torvalds 	 */
19511da177e4SLinus Torvalds 	status = nfserr_minor_vers_mismatch;
1952*e333f3bbSTrond Myklebust 	if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
19531da177e4SLinus Torvalds 		goto out;
19540078117cSJ. Bruce Fields 	status = nfserr_resource;
19550078117cSJ. Bruce Fields 	if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
19560078117cSJ. Bruce Fields 		goto out;
19571da177e4SLinus Torvalds 
195857716355SJ. Bruce Fields 	status = nfs41_check_op_ordering(args);
195957716355SJ. Bruce Fields 	if (status) {
1960f9bb94c4SAndy Adamson 		op = &args->ops[0];
196157716355SJ. Bruce Fields 		op->status = status;
19625b7b15aeSJ. Bruce Fields 		resp->opcnt = 1;
1963f9bb94c4SAndy Adamson 		goto encode_op;
1964f9bb94c4SAndy Adamson 	}
1965f9bb94c4SAndy Adamson 
1966fff4080bSChuck Lever 	trace_nfsd_compound(rqstp, args->opcnt);
19671da177e4SLinus Torvalds 	while (!status && resp->opcnt < args->opcnt) {
19681da177e4SLinus Torvalds 		op = &args->ops[resp->opcnt++];
19691da177e4SLinus Torvalds 
19701da177e4SLinus Torvalds 		/*
19711da177e4SLinus Torvalds 		 * The XDR decode routines may have pre-set op->status;
19721da177e4SLinus Torvalds 		 * for example, if there is a miscellaneous XDR error
19731da177e4SLinus Torvalds 		 * it will be set to nfserr_bad_xdr.
19741da177e4SLinus Torvalds 		 */
19759d313b17SJ. Bruce Fields 		if (op->status) {
19769d313b17SJ. Bruce Fields 			if (op->opnum == OP_OPEN)
19779d313b17SJ. Bruce Fields 				op->status = nfsd4_open_omfg(rqstp, cstate, op);
19781da177e4SLinus Torvalds 			goto encode_op;
19799d313b17SJ. Bruce Fields 		}
19801da177e4SLinus Torvalds 
19814daeed25SKinglong Mee 		if (!current_fh->fh_dentry) {
1982f4f9ef4aSJ. Bruce Fields 			if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
19831da177e4SLinus Torvalds 				op->status = nfserr_nofilehandle;
19841da177e4SLinus Torvalds 				goto encode_op;
19851da177e4SLinus Torvalds 			}
19864daeed25SKinglong Mee 		} else if (current_fh->fh_export->ex_fslocs.migrated &&
1987f4f9ef4aSJ. Bruce Fields 			  !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
198842ca0993SJ.Bruce Fields 			op->status = nfserr_moved;
198942ca0993SJ.Bruce Fields 			goto encode_op;
199042ca0993SJ.Bruce Fields 		}
1991b591480bSJ.Bruce Fields 
19922336745eSKinglong Mee 		fh_clear_wcc(current_fh);
19932336745eSKinglong Mee 
199458e7b33aSMi Jinlong 		/* If op is non-idempotent */
1995f4f9ef4aSJ. Bruce Fields 		if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
19964c69d585SJ. Bruce Fields 			/*
1997a8095f7eSJ. Bruce Fields 			 * Don't execute this op if we couldn't encode a
1998a8095f7eSJ. Bruce Fields 			 * succesful reply:
1999a8095f7eSJ. Bruce Fields 			 */
2000f4f9ef4aSJ. Bruce Fields 			u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
2001a8095f7eSJ. Bruce Fields 			/*
2002a8095f7eSJ. Bruce Fields 			 * Plus if there's another operation, make sure
20034c69d585SJ. Bruce Fields 			 * we'll have space to at least encode an error:
20044c69d585SJ. Bruce Fields 			 */
20054c69d585SJ. Bruce Fields 			if (resp->opcnt < args->opcnt)
20064c69d585SJ. Bruce Fields 				plen += COMPOUND_ERR_SLACK_SPACE;
200758e7b33aSMi Jinlong 			op->status = nfsd4_check_resp_size(resp, plen);
200858e7b33aSMi Jinlong 		}
200958e7b33aSMi Jinlong 
201058e7b33aSMi Jinlong 		if (op->status)
201158e7b33aSMi Jinlong 			goto encode_op;
201258e7b33aSMi Jinlong 
2013f4f9ef4aSJ. Bruce Fields 		if (op->opdesc->op_get_currentstateid)
2014f4f9ef4aSJ. Bruce Fields 			op->opdesc->op_get_currentstateid(cstate, &op->u);
2015f4f9ef4aSJ. Bruce Fields 		op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
20161da177e4SLinus Torvalds 
20179a307403SJ. Bruce Fields 		/* Only from SEQUENCE */
20189a307403SJ. Bruce Fields 		if (cstate->status == nfserr_replay_cache) {
20199a307403SJ. Bruce Fields 			dprintk("%s NFS4.1 replay from cache\n", __func__);
20209a307403SJ. Bruce Fields 			status = op->status;
20219a307403SJ. Bruce Fields 			goto out;
20229a307403SJ. Bruce Fields 		}
20238b70484cSTigran Mkrtchyan 		if (!op->status) {
2024f4f9ef4aSJ. Bruce Fields 			if (op->opdesc->op_set_currentstateid)
2025f4f9ef4aSJ. Bruce Fields 				op->opdesc->op_set_currentstateid(cstate, &op->u);
20268b70484cSTigran Mkrtchyan 
2027f4f9ef4aSJ. Bruce Fields 			if (op->opdesc->op_flags & OP_CLEAR_STATEID)
202837c593c5STigran Mkrtchyan 				clear_current_stateid(cstate);
20298b70484cSTigran Mkrtchyan 
20308b70484cSTigran Mkrtchyan 			if (need_wrongsec_check(rqstp))
20314daeed25SKinglong Mee 				op->status = check_nfsd_access(current_fh->fh_export, rqstp);
20328b70484cSTigran Mkrtchyan 		}
20331da177e4SLinus Torvalds encode_op:
2034a90b061cSAl Viro 		if (op->status == nfserr_replay_me) {
2035a4f1706aSJ.Bruce Fields 			op->replay = &cstate->replay_owner->so_replay;
2036d0a381ddSJ. Bruce Fields 			nfsd4_encode_replay(&resp->xdr, op);
20371da177e4SLinus Torvalds 			status = op->status = op->replay->rp_status;
20381da177e4SLinus Torvalds 		} else {
20391da177e4SLinus Torvalds 			nfsd4_encode_operation(resp, op);
20401da177e4SLinus Torvalds 			status = op->status;
20411da177e4SLinus Torvalds 		}
20420407717dSBenny Halevy 
2043fff4080bSChuck Lever 		trace_nfsd_compound_status(args->opcnt, resp->opcnt, status,
2044fff4080bSChuck Lever 					   nfsd4_op_name(op->opnum));
20450407717dSBenny Halevy 
204658fb12e6SJeff Layton 		nfsd4_cstate_clear_replay(cstate);
2047e2b20950SShankar Anand 		nfsd4_increment_op_stats(op->opnum);
20481da177e4SLinus Torvalds 	}
20491da177e4SLinus Torvalds 
20504daeed25SKinglong Mee 	cstate->status = status;
20514daeed25SKinglong Mee 	fh_put(current_fh);
20524daeed25SKinglong Mee 	fh_put(save_fh);
20534daeed25SKinglong Mee 	BUG_ON(cstate->replay_owner);
20541da177e4SLinus Torvalds out:
20552f425878SAndy Adamson 	/* Reset deferral mechanism for RPC deferrals */
205630660e04SJeff Layton 	set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
20573b12cd98SJ. Bruce Fields 	dprintk("nfsv4 compound returned %d\n", ntohl(status));
20581da177e4SLinus Torvalds 	return status;
20591da177e4SLinus Torvalds }
20601da177e4SLinus Torvalds 
206158e7b33aSMi Jinlong #define op_encode_hdr_size		(2)
206258e7b33aSMi Jinlong #define op_encode_stateid_maxsz		(XDR_QUADLEN(NFS4_STATEID_SIZE))
206358e7b33aSMi Jinlong #define op_encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
206458e7b33aSMi Jinlong #define op_encode_change_info_maxsz	(5)
206558e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz		(4)
206658e7b33aSMi Jinlong 
20678c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */
20688c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz	(0)
206958e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz	(8 + op_encode_lockowner_maxsz)
207058e7b33aSMi Jinlong 
207158e7b33aSMi Jinlong #define nfs4_owner_maxsz		(1 + XDR_QUADLEN(IDMAP_NAMESZ))
207258e7b33aSMi Jinlong 
207358e7b33aSMi Jinlong #define op_encode_ace_maxsz		(3 + nfs4_owner_maxsz)
207458e7b33aSMi Jinlong #define op_encode_delegation_maxsz	(1 + op_encode_stateid_maxsz + 1 + \
207558e7b33aSMi Jinlong 					 op_encode_ace_maxsz)
207658e7b33aSMi Jinlong 
207758e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz	(6 + 1 + 1)
207858e7b33aSMi Jinlong 
207958e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
208058e7b33aSMi Jinlong {
208158e7b33aSMi Jinlong 	return (op_encode_hdr_size) * sizeof(__be32);
208258e7b33aSMi Jinlong }
208358e7b33aSMi Jinlong 
208458e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
208558e7b33aSMi Jinlong {
208658e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
208758e7b33aSMi Jinlong }
208858e7b33aSMi Jinlong 
20892282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
20902282cd2cSKinglong Mee {
20912282cd2cSKinglong Mee 	/* ac_supported, ac_resp_access */
20922282cd2cSKinglong Mee 	return (op_encode_hdr_size + 2)* sizeof(__be32);
20932282cd2cSKinglong Mee }
20942282cd2cSKinglong Mee 
209558e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
209658e7b33aSMi Jinlong {
209758e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
209858e7b33aSMi Jinlong }
209958e7b33aSMi Jinlong 
210058e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
210158e7b33aSMi Jinlong {
210258e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz
210358e7b33aSMi Jinlong 		+ nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
210458e7b33aSMi Jinlong }
210558e7b33aSMi Jinlong 
2106b86cef60SJ. Bruce Fields /*
2107b86cef60SJ. Bruce Fields  * Note since this is an idempotent operation we won't insist on failing
2108b86cef60SJ. Bruce Fields  * the op prematurely if the estimate is too large.  We may turn off splice
2109b86cef60SJ. Bruce Fields  * reads unnecessarily.
2110b86cef60SJ. Bruce Fields  */
2111b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
2112b86cef60SJ. Bruce Fields 				      struct nfsd4_op *op)
2113b86cef60SJ. Bruce Fields {
2114b86cef60SJ. Bruce Fields 	u32 *bmap = op->u.getattr.ga_bmval;
2115b86cef60SJ. Bruce Fields 	u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
2116b86cef60SJ. Bruce Fields 	u32 ret = 0;
2117b86cef60SJ. Bruce Fields 
2118b86cef60SJ. Bruce Fields 	if (bmap0 & FATTR4_WORD0_ACL)
2119b86cef60SJ. Bruce Fields 		return svc_max_payload(rqstp);
2120b86cef60SJ. Bruce Fields 	if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
2121b86cef60SJ. Bruce Fields 		return svc_max_payload(rqstp);
2122b86cef60SJ. Bruce Fields 
2123b86cef60SJ. Bruce Fields 	if (bmap1 & FATTR4_WORD1_OWNER) {
2124b86cef60SJ. Bruce Fields 		ret += IDMAP_NAMESZ + 4;
2125b86cef60SJ. Bruce Fields 		bmap1 &= ~FATTR4_WORD1_OWNER;
2126b86cef60SJ. Bruce Fields 	}
2127b86cef60SJ. Bruce Fields 	if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
2128b86cef60SJ. Bruce Fields 		ret += IDMAP_NAMESZ + 4;
2129b86cef60SJ. Bruce Fields 		bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
2130b86cef60SJ. Bruce Fields 	}
2131b86cef60SJ. Bruce Fields 	if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
2132b86cef60SJ. Bruce Fields 		ret += NFS4_FHSIZE + 4;
2133b86cef60SJ. Bruce Fields 		bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
2134b86cef60SJ. Bruce Fields 	}
2135b86cef60SJ. Bruce Fields 	if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
21361ec8c0c4SKinglong Mee 		ret += NFS4_MAXLABELLEN + 12;
2137b86cef60SJ. Bruce Fields 		bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2138b86cef60SJ. Bruce Fields 	}
2139b86cef60SJ. Bruce Fields 	/*
2140b86cef60SJ. Bruce Fields 	 * Largest of remaining attributes are 16 bytes (e.g.,
2141b86cef60SJ. Bruce Fields 	 * supported_attributes)
2142b86cef60SJ. Bruce Fields 	 */
2143b86cef60SJ. Bruce Fields 	ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
2144b86cef60SJ. Bruce Fields 	/* bitmask, length */
2145b86cef60SJ. Bruce Fields 	ret += 20;
2146b86cef60SJ. Bruce Fields 	return ret;
2147b86cef60SJ. Bruce Fields }
2148b86cef60SJ. Bruce Fields 
21492282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
21502282cd2cSKinglong Mee {
21512282cd2cSKinglong Mee 	return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
21522282cd2cSKinglong Mee }
21532282cd2cSKinglong Mee 
215458e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
215558e7b33aSMi Jinlong {
215658e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz)
215758e7b33aSMi Jinlong 		* sizeof(__be32);
215858e7b33aSMi Jinlong }
215958e7b33aSMi Jinlong 
216058e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
216158e7b33aSMi Jinlong {
216258e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
216358e7b33aSMi Jinlong 		* sizeof(__be32);
216458e7b33aSMi Jinlong }
216558e7b33aSMi Jinlong 
216658e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
216758e7b33aSMi Jinlong {
216858e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_stateid_maxsz
216958e7b33aSMi Jinlong 		+ op_encode_change_info_maxsz + 1
217058e7b33aSMi Jinlong 		+ nfs4_fattr_bitmap_maxsz
217158e7b33aSMi Jinlong 		+ op_encode_delegation_maxsz) * sizeof(__be32);
217258e7b33aSMi Jinlong }
217358e7b33aSMi Jinlong 
217458e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
217558e7b33aSMi Jinlong {
217658e7b33aSMi Jinlong 	u32 maxcount = 0, rlen = 0;
217758e7b33aSMi Jinlong 
217858e7b33aSMi Jinlong 	maxcount = svc_max_payload(rqstp);
21793c7aa15dSKinglong Mee 	rlen = min(op->u.read.rd_length, maxcount);
218058e7b33aSMi Jinlong 
2181622f560eSJ. Bruce Fields 	return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
218258e7b33aSMi Jinlong }
218358e7b33aSMi Jinlong 
218458e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
218558e7b33aSMi Jinlong {
21863c7aa15dSKinglong Mee 	u32 maxcount = 0, rlen = 0;
218758e7b33aSMi Jinlong 
21883c7aa15dSKinglong Mee 	maxcount = svc_max_payload(rqstp);
21893c7aa15dSKinglong Mee 	rlen = min(op->u.readdir.rd_maxcount, maxcount);
219058e7b33aSMi Jinlong 
2191561f0ed4SJ. Bruce Fields 	return (op_encode_hdr_size + op_encode_verifier_maxsz +
2192561f0ed4SJ. Bruce Fields 		XDR_QUADLEN(rlen)) * sizeof(__be32);
219358e7b33aSMi Jinlong }
219458e7b33aSMi Jinlong 
21952282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
21962282cd2cSKinglong Mee {
21972282cd2cSKinglong Mee 	return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
21982282cd2cSKinglong Mee }
21992282cd2cSKinglong Mee 
220058e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
220158e7b33aSMi Jinlong {
220258e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz)
220358e7b33aSMi Jinlong 		* sizeof(__be32);
220458e7b33aSMi Jinlong }
220558e7b33aSMi Jinlong 
220658e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
220758e7b33aSMi Jinlong {
220858e7b33aSMi Jinlong 	return (op_encode_hdr_size + op_encode_change_info_maxsz
220958e7b33aSMi Jinlong 		+ op_encode_change_info_maxsz) * sizeof(__be32);
221058e7b33aSMi Jinlong }
221158e7b33aSMi Jinlong 
2212ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
2213ccae70a9SJ. Bruce Fields 				       struct nfsd4_op *op)
2214ccae70a9SJ. Bruce Fields {
2215d1d84c96SJ. Bruce Fields 	return (op_encode_hdr_size
2216d1d84c96SJ. Bruce Fields 		+ XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
2217ccae70a9SJ. Bruce Fields }
2218ccae70a9SJ. Bruce Fields 
22192282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
22202282cd2cSKinglong Mee {
22212282cd2cSKinglong Mee 	return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
22222282cd2cSKinglong Mee 		* sizeof(__be32);
22232282cd2cSKinglong Mee }
22242282cd2cSKinglong Mee 
222558e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
222658e7b33aSMi Jinlong {
222758e7b33aSMi Jinlong 	return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
222858e7b33aSMi Jinlong }
222958e7b33aSMi Jinlong 
22302282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
22312282cd2cSKinglong Mee {
22322282cd2cSKinglong Mee 	return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
22332282cd2cSKinglong Mee 		(4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
22342282cd2cSKinglong Mee }
22352282cd2cSKinglong Mee 
223658e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
223758e7b33aSMi Jinlong {
2238480efaeeSJ. Bruce Fields 	return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
2239480efaeeSJ. Bruce Fields 								sizeof(__be32);
224058e7b33aSMi Jinlong }
224158e7b33aSMi Jinlong 
224258e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
224358e7b33aSMi Jinlong {
2244f34e432bSJ. Bruce Fields 	return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
224558e7b33aSMi Jinlong }
224658e7b33aSMi Jinlong 
224758e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
224858e7b33aSMi Jinlong {
224958e7b33aSMi Jinlong 	return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
2250a8bb84bcSKinglong Mee 		1 + 1 + /* eir_flags, spr_how */\
2251a8bb84bcSKinglong Mee 		4 + /* spo_must_enforce & _allow with bitmap */\
225258e7b33aSMi Jinlong 		2 + /*eir_server_owner.so_minor_id */\
225358e7b33aSMi Jinlong 		/* eir_server_owner.so_major_id<> */\
225458e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
225558e7b33aSMi Jinlong 		/* eir_server_scope<> */\
225658e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
225758e7b33aSMi Jinlong 		1 + /* eir_server_impl_id array length */\
225858e7b33aSMi Jinlong 		0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
225958e7b33aSMi Jinlong }
226058e7b33aSMi Jinlong 
226158e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
226258e7b33aSMi Jinlong {
226358e7b33aSMi Jinlong 	return (op_encode_hdr_size + \
226458e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
226558e7b33aSMi Jinlong 		2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
226658e7b33aSMi Jinlong }
226758e7b33aSMi Jinlong 
226858e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
226958e7b33aSMi Jinlong {
227058e7b33aSMi Jinlong 	return (op_encode_hdr_size + \
227158e7b33aSMi Jinlong 		XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
227258e7b33aSMi Jinlong 		2 + /* csr_sequence, csr_flags */\
227358e7b33aSMi Jinlong 		op_encode_channel_attrs_maxsz + \
227458e7b33aSMi Jinlong 		op_encode_channel_attrs_maxsz) * sizeof(__be32);
227558e7b33aSMi Jinlong }
227658e7b33aSMi Jinlong 
227729ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
227829ae7f9dSAnna Schumaker {
227929ae7f9dSAnna Schumaker 	return (op_encode_hdr_size +
228029ae7f9dSAnna Schumaker 		1 /* wr_callback */ +
228129ae7f9dSAnna Schumaker 		op_encode_stateid_maxsz /* wr_callback */ +
228229ae7f9dSAnna Schumaker 		2 /* wr_count */ +
228329ae7f9dSAnna Schumaker 		1 /* wr_committed */ +
228429ae7f9dSAnna Schumaker 		op_encode_verifier_maxsz +
228529ae7f9dSAnna Schumaker 		1 /* cr_consecutive */ +
228629ae7f9dSAnna Schumaker 		1 /* cr_synchronous */) * sizeof(__be32);
228729ae7f9dSAnna Schumaker }
228829ae7f9dSAnna Schumaker 
22896308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp,
22906308bc98SOlga Kornievskaia 					     struct nfsd4_op *op)
22916308bc98SOlga Kornievskaia {
22926308bc98SOlga Kornievskaia 	return (op_encode_hdr_size +
22936308bc98SOlga Kornievskaia 		2 /* osr_count */ +
22946308bc98SOlga Kornievskaia 		1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
22956308bc98SOlga Kornievskaia }
22966308bc98SOlga Kornievskaia 
22979cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
22982282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
22992282cd2cSKinglong Mee {
23002282cd2cSKinglong Mee 	u32 maxcount = 0, rlen = 0;
23012282cd2cSKinglong Mee 
23022282cd2cSKinglong Mee 	maxcount = svc_max_payload(rqstp);
23032282cd2cSKinglong Mee 	rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
23042282cd2cSKinglong Mee 
23052282cd2cSKinglong Mee 	return (op_encode_hdr_size +
23062282cd2cSKinglong Mee 		1 /* gd_layout_type*/ +
23072282cd2cSKinglong Mee 		XDR_QUADLEN(rlen) +
23082282cd2cSKinglong Mee 		2 /* gd_notify_types */) * sizeof(__be32);
23092282cd2cSKinglong Mee }
23102282cd2cSKinglong Mee 
23119cf514ccSChristoph Hellwig /*
23129cf514ccSChristoph Hellwig  * At this stage we don't really know what layout driver will handle the request,
23139cf514ccSChristoph Hellwig  * so we need to define an arbitrary upper bound here.
23149cf514ccSChristoph Hellwig  */
23159cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE		128
23169cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
23179cf514ccSChristoph Hellwig {
23189cf514ccSChristoph Hellwig 	return (op_encode_hdr_size +
23199cf514ccSChristoph Hellwig 		1 /* logr_return_on_close */ +
23209cf514ccSChristoph Hellwig 		op_encode_stateid_maxsz +
23219cf514ccSChristoph Hellwig 		1 /* nr of layouts */ +
23229cf514ccSChristoph Hellwig 		MAX_LAYOUT_SIZE) * sizeof(__be32);
23239cf514ccSChristoph Hellwig }
23249cf514ccSChristoph Hellwig 
23259cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
23269cf514ccSChristoph Hellwig {
23279cf514ccSChristoph Hellwig 	return (op_encode_hdr_size +
23289cf514ccSChristoph Hellwig 		1 /* locr_newsize */ +
23299cf514ccSChristoph Hellwig 		2 /* ns_size */) * sizeof(__be32);
23309cf514ccSChristoph Hellwig }
23319cf514ccSChristoph Hellwig 
23329cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
23339cf514ccSChristoph Hellwig {
23349cf514ccSChristoph Hellwig 	return (op_encode_hdr_size +
23359cf514ccSChristoph Hellwig 		1 /* lrs_stateid */ +
23369cf514ccSChristoph Hellwig 		op_encode_stateid_maxsz) * sizeof(__be32);
23379cf514ccSChristoph Hellwig }
23389cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */
23399cf514ccSChristoph Hellwig 
23402282cd2cSKinglong Mee 
23412282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
23422282cd2cSKinglong Mee {
23432282cd2cSKinglong Mee 	return (op_encode_hdr_size + 3) * sizeof(__be32);
23442282cd2cSKinglong Mee }
23452282cd2cSKinglong Mee 
2346bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = {
2347b591480bSJ.Bruce Fields 	[OP_ACCESS] = {
2348eb69853dSChristoph Hellwig 		.op_func = nfsd4_access,
2349b001a1b6SBenny Halevy 		.op_name = "OP_ACCESS",
23501c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_access_rsize,
2351b591480bSJ.Bruce Fields 	},
2352b591480bSJ.Bruce Fields 	[OP_CLOSE] = {
2353eb69853dSChristoph Hellwig 		.op_func = nfsd4_close,
235458e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2355b001a1b6SBenny Halevy 		.op_name = "OP_CLOSE",
23561c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
235757832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_closestateid,
2358b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_closestateid,
2359b591480bSJ.Bruce Fields 	},
2360b591480bSJ.Bruce Fields 	[OP_COMMIT] = {
2361eb69853dSChristoph Hellwig 		.op_func = nfsd4_commit,
236258e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2363b001a1b6SBenny Halevy 		.op_name = "OP_COMMIT",
23641c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_commit_rsize,
2365b591480bSJ.Bruce Fields 	},
2366b591480bSJ.Bruce Fields 	[OP_CREATE] = {
2367eb69853dSChristoph Hellwig 		.op_func = nfsd4_create,
2368d1471053STigran Mkrtchyan 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
2369b001a1b6SBenny Halevy 		.op_name = "OP_CREATE",
23701c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_create_rsize,
2371b591480bSJ.Bruce Fields 	},
2372b591480bSJ.Bruce Fields 	[OP_DELEGRETURN] = {
2373eb69853dSChristoph Hellwig 		.op_func = nfsd4_delegreturn,
237458e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2375b001a1b6SBenny Halevy 		.op_name = "OP_DELEGRETURN",
237658e7b33aSMi Jinlong 		.op_rsize_bop = nfsd4_only_status_rsize,
237757832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_delegreturnstateid,
2378b591480bSJ.Bruce Fields 	},
2379b591480bSJ.Bruce Fields 	[OP_GETATTR] = {
2380eb69853dSChristoph Hellwig 		.op_func = nfsd4_getattr,
2381eeac294eSJ.Bruce Fields 		.op_flags = ALLOWED_ON_ABSENT_FS,
2382b86cef60SJ. Bruce Fields 		.op_rsize_bop = nfsd4_getattr_rsize,
2383b001a1b6SBenny Halevy 		.op_name = "OP_GETATTR",
2384b591480bSJ.Bruce Fields 	},
2385b591480bSJ.Bruce Fields 	[OP_GETFH] = {
2386eb69853dSChristoph Hellwig 		.op_func = nfsd4_getfh,
2387b001a1b6SBenny Halevy 		.op_name = "OP_GETFH",
23881c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_getfh_rsize,
2389b591480bSJ.Bruce Fields 	},
2390b591480bSJ.Bruce Fields 	[OP_LINK] = {
2391eb69853dSChristoph Hellwig 		.op_func = nfsd4_link,
2392c856694eSJ. Bruce Fields 		.op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
2393c856694eSJ. Bruce Fields 				| OP_CACHEME,
2394b001a1b6SBenny Halevy 		.op_name = "OP_LINK",
23951c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_link_rsize,
2396b591480bSJ.Bruce Fields 	},
2397b591480bSJ.Bruce Fields 	[OP_LOCK] = {
2398eb69853dSChristoph Hellwig 		.op_func = nfsd4_lock,
2399b7571e4cSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING |
2400b7571e4cSJ. Bruce Fields 				OP_NONTRIVIAL_ERROR_ENCODE,
2401b001a1b6SBenny Halevy 		.op_name = "OP_LOCK",
24021c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_lock_rsize,
2403b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_lockstateid,
2404b591480bSJ.Bruce Fields 	},
2405b591480bSJ.Bruce Fields 	[OP_LOCKT] = {
2406eb69853dSChristoph Hellwig 		.op_func = nfsd4_lockt,
2407b7571e4cSJ. Bruce Fields 		.op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
2408b001a1b6SBenny Halevy 		.op_name = "OP_LOCKT",
24091c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_lock_rsize,
2410b591480bSJ.Bruce Fields 	},
2411b591480bSJ.Bruce Fields 	[OP_LOCKU] = {
2412eb69853dSChristoph Hellwig 		.op_func = nfsd4_locku,
241358e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2414b001a1b6SBenny Halevy 		.op_name = "OP_LOCKU",
24151c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
241657832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_lockustateid,
2417b591480bSJ.Bruce Fields 	},
2418b591480bSJ.Bruce Fields 	[OP_LOOKUP] = {
2419eb69853dSChristoph Hellwig 		.op_func = nfsd4_lookup,
2420d1471053STigran Mkrtchyan 		.op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
2421b001a1b6SBenny Halevy 		.op_name = "OP_LOOKUP",
24221c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2423b591480bSJ.Bruce Fields 	},
2424b591480bSJ.Bruce Fields 	[OP_LOOKUPP] = {
2425eb69853dSChristoph Hellwig 		.op_func = nfsd4_lookupp,
2426d1471053STigran Mkrtchyan 		.op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
2427b001a1b6SBenny Halevy 		.op_name = "OP_LOOKUPP",
24281c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2429b591480bSJ.Bruce Fields 	},
2430b591480bSJ.Bruce Fields 	[OP_NVERIFY] = {
2431eb69853dSChristoph Hellwig 		.op_func = nfsd4_nverify,
2432b001a1b6SBenny Halevy 		.op_name = "OP_NVERIFY",
24331c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2434b591480bSJ.Bruce Fields 	},
2435b591480bSJ.Bruce Fields 	[OP_OPEN] = {
2436eb69853dSChristoph Hellwig 		.op_func = nfsd4_open,
243758e7b33aSMi Jinlong 		.op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
2438b001a1b6SBenny Halevy 		.op_name = "OP_OPEN",
24391c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_open_rsize,
2440b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_openstateid,
2441b591480bSJ.Bruce Fields 	},
2442b591480bSJ.Bruce Fields 	[OP_OPEN_CONFIRM] = {
2443eb69853dSChristoph Hellwig 		.op_func = nfsd4_open_confirm,
244458e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2445b001a1b6SBenny Halevy 		.op_name = "OP_OPEN_CONFIRM",
24461c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
2447b591480bSJ.Bruce Fields 	},
2448b591480bSJ.Bruce Fields 	[OP_OPEN_DOWNGRADE] = {
2449eb69853dSChristoph Hellwig 		.op_func = nfsd4_open_downgrade,
245058e7b33aSMi Jinlong 		.op_flags = OP_MODIFIES_SOMETHING,
2451b001a1b6SBenny Halevy 		.op_name = "OP_OPEN_DOWNGRADE",
24521c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_status_stateid_rsize,
245357832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_opendowngradestateid,
2454b60e9859SChristoph Hellwig 		.op_set_currentstateid = nfsd4_set_opendowngradestateid,
2455b591480bSJ.Bruce Fields 	},
2456b591480bSJ.Bruce Fields 	[OP_PUTFH] = {
2457eb69853dSChristoph Hellwig 		.op_func = nfsd4_putfh,
245868d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
24595b648699SJ. Bruce Fields 				| OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
2460b001a1b6SBenny Halevy 		.op_name = "OP_PUTFH",
24611c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2462b591480bSJ.Bruce Fields 	},
2463eeac294eSJ.Bruce Fields 	[OP_PUTPUBFH] = {
2464eb69853dSChristoph Hellwig 		.op_func = nfsd4_putrootfh,
246568d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
24665b648699SJ. Bruce Fields 				| OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
2467b001a1b6SBenny Halevy 		.op_name = "OP_PUTPUBFH",
24681c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2469eeac294eSJ.Bruce Fields 	},
2470b591480bSJ.Bruce Fields 	[OP_PUTROOTFH] = {
2471eb69853dSChristoph Hellwig 		.op_func = nfsd4_putrootfh,
247268d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
24735b648699SJ. Bruce Fields 				| OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
2474b001a1b6SBenny Halevy 		.op_name = "OP_PUTROOTFH",
24751c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2476b591480bSJ.Bruce Fields 	},
2477b591480bSJ.Bruce Fields 	[OP_READ] = {
2478eb69853dSChristoph Hellwig 		.op_func = nfsd4_read,
247934b1744cSJ. Bruce Fields 		.op_release = nfsd4_read_release,
2480b001a1b6SBenny Halevy 		.op_name = "OP_READ",
24811c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_read_rsize,
248257832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_readstateid,
2483b591480bSJ.Bruce Fields 	},
2484b591480bSJ.Bruce Fields 	[OP_READDIR] = {
2485eb69853dSChristoph Hellwig 		.op_func = nfsd4_readdir,
2486b001a1b6SBenny Halevy 		.op_name = "OP_READDIR",
24871c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_readdir_rsize,
2488b591480bSJ.Bruce Fields 	},
2489b591480bSJ.Bruce Fields 	[OP_READLINK] = {
2490eb69853dSChristoph Hellwig 		.op_func = nfsd4_readlink,
2491b001a1b6SBenny Halevy 		.op_name = "OP_READLINK",
24921c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_readlink_rsize,
2493b591480bSJ.Bruce Fields 	},
2494b591480bSJ.Bruce Fields 	[OP_REMOVE] = {
2495eb69853dSChristoph Hellwig 		.op_func = nfsd4_remove,
2496c856694eSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2497b001a1b6SBenny Halevy 		.op_name = "OP_REMOVE",
24981c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_remove_rsize,
2499b591480bSJ.Bruce Fields 	},
2500b591480bSJ.Bruce Fields 	[OP_RENAME] = {
2501eb69853dSChristoph Hellwig 		.op_func = nfsd4_rename,
2502c856694eSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
250358e7b33aSMi Jinlong 		.op_name = "OP_RENAME",
25041c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_rename_rsize,
2505b591480bSJ.Bruce Fields 	},
2506b591480bSJ.Bruce Fields 	[OP_RENEW] = {
2507eb69853dSChristoph Hellwig 		.op_func = nfsd4_renew,
250858e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
250958e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2510b001a1b6SBenny Halevy 		.op_name = "OP_RENEW",
25111c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
251258e7b33aSMi Jinlong 
2513b591480bSJ.Bruce Fields 	},
2514b591480bSJ.Bruce Fields 	[OP_RESTOREFH] = {
2515eb69853dSChristoph Hellwig 		.op_func = nfsd4_restorefh,
251668d93184SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
251758e7b33aSMi Jinlong 				| OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
2518b001a1b6SBenny Halevy 		.op_name = "OP_RESTOREFH",
25191c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2520b591480bSJ.Bruce Fields 	},
2521b591480bSJ.Bruce Fields 	[OP_SAVEFH] = {
2522eb69853dSChristoph Hellwig 		.op_func = nfsd4_savefh,
252358e7b33aSMi Jinlong 		.op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
2524b001a1b6SBenny Halevy 		.op_name = "OP_SAVEFH",
25251c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2526b591480bSJ.Bruce Fields 	},
2527dcb488a3SAndy Adamson 	[OP_SECINFO] = {
2528eb69853dSChristoph Hellwig 		.op_func = nfsd4_secinfo,
252934b1744cSJ. Bruce Fields 		.op_release = nfsd4_secinfo_release,
253068d93184SJ. Bruce Fields 		.op_flags = OP_HANDLES_WRONGSEC,
2531b001a1b6SBenny Halevy 		.op_name = "OP_SECINFO",
25321c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_secinfo_rsize,
2533dcb488a3SAndy Adamson 	},
2534b591480bSJ.Bruce Fields 	[OP_SETATTR] = {
2535eb69853dSChristoph Hellwig 		.op_func = nfsd4_setattr,
2536b001a1b6SBenny Halevy 		.op_name = "OP_SETATTR",
2537b7571e4cSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
2538b7571e4cSJ. Bruce Fields 				| OP_NONTRIVIAL_ERROR_ENCODE,
25391c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_setattr_rsize,
254057832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_setattrstateid,
2541b591480bSJ.Bruce Fields 	},
2542b591480bSJ.Bruce Fields 	[OP_SETCLIENTID] = {
2543eb69853dSChristoph Hellwig 		.op_func = nfsd4_setclientid,
254458e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
2545b7571e4cSJ. Bruce Fields 				| OP_MODIFIES_SOMETHING | OP_CACHEME
2546b7571e4cSJ. Bruce Fields 				| OP_NONTRIVIAL_ERROR_ENCODE,
2547b001a1b6SBenny Halevy 		.op_name = "OP_SETCLIENTID",
25481c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_setclientid_rsize,
2549b591480bSJ.Bruce Fields 	},
2550b591480bSJ.Bruce Fields 	[OP_SETCLIENTID_CONFIRM] = {
2551eb69853dSChristoph Hellwig 		.op_func = nfsd4_setclientid_confirm,
255258e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
2553c856694eSJ. Bruce Fields 				| OP_MODIFIES_SOMETHING | OP_CACHEME,
2554b001a1b6SBenny Halevy 		.op_name = "OP_SETCLIENTID_CONFIRM",
25551c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2556b591480bSJ.Bruce Fields 	},
2557b591480bSJ.Bruce Fields 	[OP_VERIFY] = {
2558eb69853dSChristoph Hellwig 		.op_func = nfsd4_verify,
2559b001a1b6SBenny Halevy 		.op_name = "OP_VERIFY",
25601c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2561b591480bSJ.Bruce Fields 	},
2562b591480bSJ.Bruce Fields 	[OP_WRITE] = {
2563eb69853dSChristoph Hellwig 		.op_func = nfsd4_write,
2564c856694eSJ. Bruce Fields 		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2565b001a1b6SBenny Halevy 		.op_name = "OP_WRITE",
25661c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_write_rsize,
256757832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_writestateid,
2568b591480bSJ.Bruce Fields 	},
2569b591480bSJ.Bruce Fields 	[OP_RELEASE_LOCKOWNER] = {
2570eb69853dSChristoph Hellwig 		.op_func = nfsd4_release_lockowner,
257158e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
257258e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2573b001a1b6SBenny Halevy 		.op_name = "OP_RELEASE_LOCKOWNER",
25741c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2575b591480bSJ.Bruce Fields 	},
2576069b6ad4SAndy Adamson 
2577069b6ad4SAndy Adamson 	/* NFSv4.1 operations */
2578069b6ad4SAndy Adamson 	[OP_EXCHANGE_ID] = {
2579eb69853dSChristoph Hellwig 		.op_func = nfsd4_exchange_id,
258058e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
258158e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2582069b6ad4SAndy Adamson 		.op_name = "OP_EXCHANGE_ID",
25831c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_exchange_id_rsize,
2584069b6ad4SAndy Adamson 	},
2585cb73a9f4SJ. Bruce Fields 	[OP_BACKCHANNEL_CTL] = {
2586eb69853dSChristoph Hellwig 		.op_func = nfsd4_backchannel_ctl,
2587cb73a9f4SJ. Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
2588cb73a9f4SJ. Bruce Fields 		.op_name = "OP_BACKCHANNEL_CTL",
25891c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2590cb73a9f4SJ. Bruce Fields 	},
25911d1bc8f2SJ. Bruce Fields 	[OP_BIND_CONN_TO_SESSION] = {
2592eb69853dSChristoph Hellwig 		.op_func = nfsd4_bind_conn_to_session,
259358e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
259458e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
25951d1bc8f2SJ. Bruce Fields 		.op_name = "OP_BIND_CONN_TO_SESSION",
25961c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
25971d1bc8f2SJ. Bruce Fields 	},
2598069b6ad4SAndy Adamson 	[OP_CREATE_SESSION] = {
2599eb69853dSChristoph Hellwig 		.op_func = nfsd4_create_session,
260058e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
260158e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2602069b6ad4SAndy Adamson 		.op_name = "OP_CREATE_SESSION",
26031c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_create_session_rsize,
2604069b6ad4SAndy Adamson 	},
2605069b6ad4SAndy Adamson 	[OP_DESTROY_SESSION] = {
2606eb69853dSChristoph Hellwig 		.op_func = nfsd4_destroy_session,
260758e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
260858e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2609069b6ad4SAndy Adamson 		.op_name = "OP_DESTROY_SESSION",
26101c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2611069b6ad4SAndy Adamson 	},
2612069b6ad4SAndy Adamson 	[OP_SEQUENCE] = {
2613eb69853dSChristoph Hellwig 		.op_func = nfsd4_sequence,
2614f9bb94c4SAndy Adamson 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
2615069b6ad4SAndy Adamson 		.op_name = "OP_SEQUENCE",
26161c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_sequence_rsize,
2617069b6ad4SAndy Adamson 	},
2618094b5d74SBenny Halevy 	[OP_DESTROY_CLIENTID] = {
2619eb69853dSChristoph Hellwig 		.op_func = nfsd4_destroy_clientid,
262058e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
262158e7b33aSMi Jinlong 				| OP_MODIFIES_SOMETHING,
2622094b5d74SBenny Halevy 		.op_name = "OP_DESTROY_CLIENTID",
26231c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2624094b5d74SBenny Halevy 	},
26254dc6ec00SJ. Bruce Fields 	[OP_RECLAIM_COMPLETE] = {
2626eb69853dSChristoph Hellwig 		.op_func = nfsd4_reclaim_complete,
262758e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
26284dc6ec00SJ. Bruce Fields 		.op_name = "OP_RECLAIM_COMPLETE",
26291c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
26304dc6ec00SJ. Bruce Fields 	},
263104f4ad16SJ. Bruce Fields 	[OP_SECINFO_NO_NAME] = {
2632eb69853dSChristoph Hellwig 		.op_func = nfsd4_secinfo_no_name,
2633ec572b9eSEryu Guan 		.op_release = nfsd4_secinfo_no_name_release,
263468d93184SJ. Bruce Fields 		.op_flags = OP_HANDLES_WRONGSEC,
263504f4ad16SJ. Bruce Fields 		.op_name = "OP_SECINFO_NO_NAME",
26361c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_secinfo_rsize,
263704f4ad16SJ. Bruce Fields 	},
263817456804SBryan Schumaker 	[OP_TEST_STATEID] = {
2639eb69853dSChristoph Hellwig 		.op_func = nfsd4_test_stateid,
264017456804SBryan Schumaker 		.op_flags = ALLOWED_WITHOUT_FH,
264117456804SBryan Schumaker 		.op_name = "OP_TEST_STATEID",
26421c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_test_stateid_rsize,
264317456804SBryan Schumaker 	},
2644e1ca12dfSBryan Schumaker 	[OP_FREE_STATEID] = {
2645eb69853dSChristoph Hellwig 		.op_func = nfsd4_free_stateid,
264658e7b33aSMi Jinlong 		.op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
2647e1ca12dfSBryan Schumaker 		.op_name = "OP_FREE_STATEID",
264857832e7bSChristoph Hellwig 		.op_get_currentstateid = nfsd4_get_freestateid,
26491c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2650e1ca12dfSBryan Schumaker 	},
26519cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
26529cf514ccSChristoph Hellwig 	[OP_GETDEVICEINFO] = {
2653eb69853dSChristoph Hellwig 		.op_func = nfsd4_getdeviceinfo,
265434b1744cSJ. Bruce Fields 		.op_release = nfsd4_getdeviceinfo_release,
26559cf514ccSChristoph Hellwig 		.op_flags = ALLOWED_WITHOUT_FH,
26569cf514ccSChristoph Hellwig 		.op_name = "OP_GETDEVICEINFO",
26571c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_getdeviceinfo_rsize,
26589cf514ccSChristoph Hellwig 	},
26599cf514ccSChristoph Hellwig 	[OP_LAYOUTGET] = {
2660eb69853dSChristoph Hellwig 		.op_func = nfsd4_layoutget,
266134b1744cSJ. Bruce Fields 		.op_release = nfsd4_layoutget_release,
26629cf514ccSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING,
26639cf514ccSChristoph Hellwig 		.op_name = "OP_LAYOUTGET",
26641c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_layoutget_rsize,
26659cf514ccSChristoph Hellwig 	},
26669cf514ccSChristoph Hellwig 	[OP_LAYOUTCOMMIT] = {
2667eb69853dSChristoph Hellwig 		.op_func = nfsd4_layoutcommit,
26689cf514ccSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING,
26699cf514ccSChristoph Hellwig 		.op_name = "OP_LAYOUTCOMMIT",
26701c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_layoutcommit_rsize,
26719cf514ccSChristoph Hellwig 	},
26729cf514ccSChristoph Hellwig 	[OP_LAYOUTRETURN] = {
2673eb69853dSChristoph Hellwig 		.op_func = nfsd4_layoutreturn,
26749cf514ccSChristoph Hellwig 		.op_flags = OP_MODIFIES_SOMETHING,
26759cf514ccSChristoph Hellwig 		.op_name = "OP_LAYOUTRETURN",
26761c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_layoutreturn_rsize,
26779cf514ccSChristoph Hellwig 	},
26789cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */
267924bab491SAnna Schumaker 
268024bab491SAnna Schumaker 	/* NFSv4.2 operations */
268195d871f0SAnna Schumaker 	[OP_ALLOCATE] = {
2682eb69853dSChristoph Hellwig 		.op_func = nfsd4_allocate,
268303b31f48SOlga Kornievskaia 		.op_flags = OP_MODIFIES_SOMETHING,
268495d871f0SAnna Schumaker 		.op_name = "OP_ALLOCATE",
26851c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
268695d871f0SAnna Schumaker 	},
2687b0cb9085SAnna Schumaker 	[OP_DEALLOCATE] = {
2688eb69853dSChristoph Hellwig 		.op_func = nfsd4_deallocate,
268903b31f48SOlga Kornievskaia 		.op_flags = OP_MODIFIES_SOMETHING,
2690b0cb9085SAnna Schumaker 		.op_name = "OP_DEALLOCATE",
26911c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2692b0cb9085SAnna Schumaker 	},
2693ffa0160aSChristoph Hellwig 	[OP_CLONE] = {
2694eb69853dSChristoph Hellwig 		.op_func = nfsd4_clone,
269503b31f48SOlga Kornievskaia 		.op_flags = OP_MODIFIES_SOMETHING,
2696ffa0160aSChristoph Hellwig 		.op_name = "OP_CLONE",
26971c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_only_status_rsize,
2698ffa0160aSChristoph Hellwig 	},
269929ae7f9dSAnna Schumaker 	[OP_COPY] = {
2700eb69853dSChristoph Hellwig 		.op_func = nfsd4_copy,
270103b31f48SOlga Kornievskaia 		.op_flags = OP_MODIFIES_SOMETHING,
270229ae7f9dSAnna Schumaker 		.op_name = "OP_COPY",
27031c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_copy_rsize,
270429ae7f9dSAnna Schumaker 	},
270524bab491SAnna Schumaker 	[OP_SEEK] = {
2706eb69853dSChristoph Hellwig 		.op_func = nfsd4_seek,
270724bab491SAnna Schumaker 		.op_name = "OP_SEEK",
27081c122638SChristoph Hellwig 		.op_rsize_bop = nfsd4_seek_rsize,
270924bab491SAnna Schumaker 	},
27106308bc98SOlga Kornievskaia 	[OP_OFFLOAD_STATUS] = {
27116308bc98SOlga Kornievskaia 		.op_func = nfsd4_offload_status,
27126308bc98SOlga Kornievskaia 		.op_name = "OP_OFFLOAD_STATUS",
27136308bc98SOlga Kornievskaia 		.op_rsize_bop = nfsd4_offload_status_rsize,
27146308bc98SOlga Kornievskaia 	},
2715885e2bf3SOlga Kornievskaia 	[OP_OFFLOAD_CANCEL] = {
2716885e2bf3SOlga Kornievskaia 		.op_func = nfsd4_offload_cancel,
2717885e2bf3SOlga Kornievskaia 		.op_flags = OP_MODIFIES_SOMETHING,
2718885e2bf3SOlga Kornievskaia 		.op_name = "OP_OFFLOAD_CANCEL",
2719885e2bf3SOlga Kornievskaia 		.op_rsize_bop = nfsd4_only_status_rsize,
2720885e2bf3SOlga Kornievskaia 	},
2721b591480bSJ.Bruce Fields };
2722b591480bSJ.Bruce Fields 
2723ed941643SAndrew Elble /**
2724ed941643SAndrew Elble  * nfsd4_spo_must_allow - Determine if the compound op contains an
2725ed941643SAndrew Elble  * operation that is allowed to be sent with machine credentials
2726ed941643SAndrew Elble  *
2727ed941643SAndrew Elble  * @rqstp: a pointer to the struct svc_rqst
2728ed941643SAndrew Elble  *
2729ed941643SAndrew Elble  * Checks to see if the compound contains a spo_must_allow op
2730ed941643SAndrew Elble  * and confirms that it was sent with the proper machine creds.
2731ed941643SAndrew Elble  */
2732ed941643SAndrew Elble 
2733ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
2734ed941643SAndrew Elble {
2735ed941643SAndrew Elble 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
2736ed941643SAndrew Elble 	struct nfsd4_compoundargs *argp = rqstp->rq_argp;
2737ed941643SAndrew Elble 	struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
2738ed941643SAndrew Elble 	struct nfsd4_compound_state *cstate = &resp->cstate;
2739ed941643SAndrew Elble 	struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
2740ed941643SAndrew Elble 	u32 opiter;
2741ed941643SAndrew Elble 
2742ed941643SAndrew Elble 	if (!cstate->minorversion)
2743ed941643SAndrew Elble 		return false;
2744ed941643SAndrew Elble 
2745ed941643SAndrew Elble 	if (cstate->spo_must_allowed == true)
2746ed941643SAndrew Elble 		return true;
2747ed941643SAndrew Elble 
2748ed941643SAndrew Elble 	opiter = resp->opcnt;
2749ed941643SAndrew Elble 	while (opiter < argp->opcnt) {
2750ed941643SAndrew Elble 		this = &argp->ops[opiter++];
2751ed941643SAndrew Elble 		if (test_bit(this->opnum, allow->u.longs) &&
2752ed941643SAndrew Elble 			cstate->clp->cl_mach_cred &&
2753ed941643SAndrew Elble 			nfsd4_mach_creds_match(cstate->clp, rqstp)) {
2754ed941643SAndrew Elble 			cstate->spo_must_allowed = true;
2755ed941643SAndrew Elble 			return true;
2756ed941643SAndrew Elble 		}
2757ed941643SAndrew Elble 	}
2758ed941643SAndrew Elble 	cstate->spo_must_allowed = false;
2759ed941643SAndrew Elble 	return false;
2760ed941643SAndrew Elble }
2761ed941643SAndrew Elble 
27624f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
27634f0cefbfSJ. Bruce Fields {
276405b7278dSOlga Kornievskaia 	if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
27654f0cefbfSJ. Bruce Fields 		return op_encode_hdr_size * sizeof(__be32);
27662282cd2cSKinglong Mee 
27672282cd2cSKinglong Mee 	BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
27682282cd2cSKinglong Mee 	return OPDESC(op)->op_rsize_bop(rqstp, op);
27694f0cefbfSJ. Bruce Fields }
27704f0cefbfSJ. Bruce Fields 
277107d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op)
277207d1f802SJ. Bruce Fields {
277307d1f802SJ. Bruce Fields 	if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
277407d1f802SJ. Bruce Fields 		pr_err("unable to encode reply to nonidempotent op %d (%s)\n",
277507d1f802SJ. Bruce Fields 			op->opnum, nfsd4_op_name(op->opnum));
277607d1f802SJ. Bruce Fields 		WARN_ON_ONCE(1);
277707d1f802SJ. Bruce Fields 	}
277807d1f802SJ. Bruce Fields }
277907d1f802SJ. Bruce Fields 
2780f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum)
2781b001a1b6SBenny Halevy {
2782b001a1b6SBenny Halevy 	if (opnum < ARRAY_SIZE(nfsd4_ops))
2783b001a1b6SBenny Halevy 		return nfsd4_ops[opnum].op_name;
2784b001a1b6SBenny Halevy 	return "unknown_operation";
2785b001a1b6SBenny Halevy }
2786b001a1b6SBenny Halevy 
27871da177e4SLinus Torvalds #define nfsd4_voidres			nfsd4_voidargs
27881da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; };
27891da177e4SLinus Torvalds 
2790860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = {
27910a93a47fSYu Zhiguo 	[NFSPROC4_NULL] = {
2792f7235b6bSChristoph Hellwig 		.pc_func = nfsd4_proc_null,
279363f8de37SChristoph Hellwig 		.pc_encode = nfs4svc_encode_voidres,
27940a93a47fSYu Zhiguo 		.pc_argsize = sizeof(struct nfsd4_voidargs),
27950a93a47fSYu Zhiguo 		.pc_ressize = sizeof(struct nfsd4_voidres),
27960a93a47fSYu Zhiguo 		.pc_cachetype = RC_NOCACHE,
27970a93a47fSYu Zhiguo 		.pc_xdrressize = 1,
27980a93a47fSYu Zhiguo 	},
27990a93a47fSYu Zhiguo 	[NFSPROC4_COMPOUND] = {
2800f7235b6bSChristoph Hellwig 		.pc_func = nfsd4_proc_compound,
2801026fec7eSChristoph Hellwig 		.pc_decode = nfs4svc_decode_compoundargs,
280263f8de37SChristoph Hellwig 		.pc_encode = nfs4svc_encode_compoundres,
28030a93a47fSYu Zhiguo 		.pc_argsize = sizeof(struct nfsd4_compoundargs),
28040a93a47fSYu Zhiguo 		.pc_ressize = sizeof(struct nfsd4_compoundres),
28053e98abffSJ. Bruce Fields 		.pc_release = nfsd4_release_compoundargs,
28060a93a47fSYu Zhiguo 		.pc_cachetype = RC_NOCACHE,
28070a93a47fSYu Zhiguo 		.pc_xdrressize = NFSD_BUFSIZE/4,
28080a93a47fSYu Zhiguo 	},
28091da177e4SLinus Torvalds };
28101da177e4SLinus Torvalds 
28117fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)];
2812e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = {
28131da177e4SLinus Torvalds 	.vs_vers		= 4,
28141da177e4SLinus Torvalds 	.vs_nproc		= 2,
28151da177e4SLinus Torvalds 	.vs_proc		= nfsd_procedures4,
28167fd38af9SChristoph Hellwig 	.vs_count		= nfsd_count3,
28171da177e4SLinus Torvalds 	.vs_dispatch		= nfsd_dispatch,
28181da177e4SLinus Torvalds 	.vs_xdrsize		= NFS4_SVC_XDRSIZE,
281905a45a2dSJeff Layton 	.vs_rpcb_optnl		= true,
28205283b03eSJeff Layton 	.vs_need_cong_ctrl	= true,
28211da177e4SLinus Torvalds };
28221da177e4SLinus Torvalds 
28231da177e4SLinus Torvalds /*
28241da177e4SLinus Torvalds  * Local variables:
28251da177e4SLinus Torvalds  *  c-basic-offset: 8
28261da177e4SLinus Torvalds  * End:
28271da177e4SLinus Torvalds  */
2828