xref: /openbmc/linux/fs/nfsd/nfs4proc.c (revision a1c8c4d1ff54c6c86930ee3c4c73c69eeb9ede61)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  fs/nfsd/nfs4proc.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Server-side procedures for NFSv4.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Copyright (c) 2002 The Regents of the University of Michigan.
71da177e4SLinus Torvalds  *  All rights reserved.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *  Kendrick Smith <kmsmith@umich.edu>
101da177e4SLinus Torvalds  *  Andy Adamson   <andros@umich.edu>
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *  Redistribution and use in source and binary forms, with or without
131da177e4SLinus Torvalds  *  modification, are permitted provided that the following conditions
141da177e4SLinus Torvalds  *  are met:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *  1. Redistributions of source code must retain the above copyright
171da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer.
181da177e4SLinus Torvalds  *  2. Redistributions in binary form must reproduce the above copyright
191da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer in the
201da177e4SLinus Torvalds  *     documentation and/or other materials provided with the distribution.
211da177e4SLinus Torvalds  *  3. Neither the name of the University nor the names of its
221da177e4SLinus Torvalds  *     contributors may be used to endorse or promote products derived
231da177e4SLinus Torvalds  *     from this software without specific prior written permission.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
261da177e4SLinus Torvalds  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
271da177e4SLinus Torvalds  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
281da177e4SLinus Torvalds  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291da177e4SLinus Torvalds  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301da177e4SLinus Torvalds  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311da177e4SLinus Torvalds  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
321da177e4SLinus Torvalds  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
331da177e4SLinus Torvalds  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
341da177e4SLinus Torvalds  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
351da177e4SLinus Torvalds  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361da177e4SLinus Torvalds  */
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #include <linux/param.h>
391da177e4SLinus Torvalds #include <linux/major.h>
401da177e4SLinus Torvalds #include <linux/slab.h>
417e06b7f9SNeilBrown #include <linux/file.h>
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds #include <linux/sunrpc/svc.h>
441da177e4SLinus Torvalds #include <linux/nfsd/nfsd.h>
451da177e4SLinus Torvalds #include <linux/nfsd/cache.h>
461da177e4SLinus Torvalds #include <linux/nfs4.h>
471da177e4SLinus Torvalds #include <linux/nfsd/state.h>
481da177e4SLinus Torvalds #include <linux/nfsd/xdr4.h>
491da177e4SLinus Torvalds #include <linux/nfs4_acl.h>
50dcb488a3SAndy Adamson #include <linux/sunrpc/gss_api.h>
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #define NFSDDBG_FACILITY		NFSDDBG_PROC
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds static inline void
551da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src)
561da177e4SLinus Torvalds {
571da177e4SLinus Torvalds 	fh_put(dst);
581da177e4SLinus Torvalds 	dget(src->fh_dentry);
591da177e4SLinus Torvalds 	if (src->fh_export)
601da177e4SLinus Torvalds 		cache_get(&src->fh_export->h);
611da177e4SLinus Torvalds 	*dst = *src;
621da177e4SLinus Torvalds }
631da177e4SLinus Torvalds 
64b37ad28bSAl Viro static __be32
65dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
661da177e4SLinus Torvalds {
67b37ad28bSAl Viro 	__be32 status;
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds 	if (open->op_truncate &&
701da177e4SLinus Torvalds 		!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
711da177e4SLinus Torvalds 		return nfserr_inval;
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds 	if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
748837abcaSMiklos Szeredi 		accmode |= NFSD_MAY_READ;
759801d8a3SJ. Bruce Fields 	if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
768837abcaSMiklos Szeredi 		accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
779801d8a3SJ. Bruce Fields 	if (open->op_share_deny & NFS4_SHARE_DENY_WRITE)
788837abcaSMiklos Szeredi 		accmode |= NFSD_MAY_WRITE;
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds 	status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds 	return status;
831da177e4SLinus Torvalds }
841da177e4SLinus Torvalds 
85b37ad28bSAl Viro static __be32
861da177e4SLinus Torvalds do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds 	struct svc_fh resfh;
89b37ad28bSAl Viro 	__be32 status;
9081ac95c5SJ. Bruce Fields 	int created = 0;
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds 	fh_init(&resfh, NFS4_FHSIZE);
931da177e4SLinus Torvalds 	open->op_truncate = 0;
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds 	if (open->op_create) {
961da177e4SLinus Torvalds 		/*
971da177e4SLinus Torvalds 		 * Note: create modes (UNCHECKED,GUARDED...) are the same
981da177e4SLinus Torvalds 		 * in NFSv4 as in v3.
991da177e4SLinus Torvalds 		 */
1001da177e4SLinus Torvalds 		status = nfsd_create_v3(rqstp, current_fh, open->op_fname.data,
1011da177e4SLinus Torvalds 					open->op_fname.len, &open->op_iattr,
1021da177e4SLinus Torvalds 					&resfh, open->op_createmode,
103749997e5SJeff Layton 					(u32 *)open->op_verf.data,
104749997e5SJeff Layton 					&open->op_truncate, &created);
105749997e5SJeff Layton 
10699f88726SJ. Bruce Fields 		/*
10799f88726SJ. Bruce Fields 		 * Following rfc 3530 14.2.16, use the returned bitmask
10899f88726SJ. Bruce Fields 		 * to indicate which attributes we used to store the
10999f88726SJ. Bruce Fields 		 * verifier:
110749997e5SJeff Layton 		 */
111749997e5SJeff Layton 		if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
11299f88726SJ. Bruce Fields 			open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
113749997e5SJeff Layton 						FATTR4_WORD1_TIME_MODIFY);
114af85852dSJ. Bruce Fields 	} else {
1151da177e4SLinus Torvalds 		status = nfsd_lookup(rqstp, current_fh,
1161da177e4SLinus Torvalds 				     open->op_fname.data, open->op_fname.len, &resfh);
1171da177e4SLinus Torvalds 		fh_unlock(current_fh);
1181da177e4SLinus Torvalds 	}
119af85852dSJ. Bruce Fields 	if (status)
120af85852dSJ. Bruce Fields 		goto out;
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds 	set_change_info(&open->op_cinfo, current_fh);
12313024b7bSJ. Bruce Fields 	fh_dup2(current_fh, &resfh);
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds 	/* set reply cache */
126a4773c08SJ. Bruce Fields 	fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh,
127a4773c08SJ. Bruce Fields 			&resfh.fh_handle);
12881ac95c5SJ. Bruce Fields 	if (!created)
1298837abcaSMiklos Szeredi 		status = do_open_permission(rqstp, current_fh, open,
1308837abcaSMiklos Szeredi 					    NFSD_MAY_NOP);
1311da177e4SLinus Torvalds 
132af85852dSJ. Bruce Fields out:
1331da177e4SLinus Torvalds 	fh_put(&resfh);
1341da177e4SLinus Torvalds 	return status;
1351da177e4SLinus Torvalds }
1361da177e4SLinus Torvalds 
137b37ad28bSAl Viro static __be32
1381da177e4SLinus Torvalds do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
1391da177e4SLinus Torvalds {
140b37ad28bSAl Viro 	__be32 status;
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds 	/* Only reclaims from previously confirmed clients are valid */
1431da177e4SLinus Torvalds 	if ((status = nfs4_check_open_reclaim(&open->op_clientid)))
1441da177e4SLinus Torvalds 		return status;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds 	/* We don't know the target directory, and therefore can not
1471da177e4SLinus Torvalds 	* set the change info
1481da177e4SLinus Torvalds 	*/
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds 	memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 	/* set replay cache */
153a4773c08SJ. Bruce Fields 	fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh,
154a4773c08SJ. Bruce Fields 			&current_fh->fh_handle);
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
1571da177e4SLinus Torvalds 		(open->op_iattr.ia_size == 0);
1581da177e4SLinus Torvalds 
1598837abcaSMiklos Szeredi 	status = do_open_permission(rqstp, current_fh, open,
1608837abcaSMiklos Szeredi 				    NFSD_MAY_OWNER_OVERRIDE);
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds 	return status;
1631da177e4SLinus Torvalds }
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 
1667191155bSJ.Bruce Fields static __be32
167ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
168a4f1706aSJ.Bruce Fields 	   struct nfsd4_open *open)
1691da177e4SLinus Torvalds {
170b37ad28bSAl Viro 	__be32 status;
1711da177e4SLinus Torvalds 	dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n",
1721da177e4SLinus Torvalds 		(int)open->op_fname.len, open->op_fname.data,
1731da177e4SLinus Torvalds 		open->op_stateowner);
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds 	/* This check required by spec. */
1761da177e4SLinus Torvalds 	if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
1771da177e4SLinus Torvalds 		return nfserr_inval;
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds 	nfs4_lock_state();
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds 	/* check seqid for replay. set nfs4_owner */
1821da177e4SLinus Torvalds 	status = nfsd4_process_open1(open);
183a90b061cSAl Viro 	if (status == nfserr_replay_me) {
1841da177e4SLinus Torvalds 		struct nfs4_replay *rp = &open->op_stateowner->so_replay;
185ca364317SJ.Bruce Fields 		fh_put(&cstate->current_fh);
186a4773c08SJ. Bruce Fields 		fh_copy_shallow(&cstate->current_fh.fh_handle,
187a4773c08SJ. Bruce Fields 				&rp->rp_openfh);
1888837abcaSMiklos Szeredi 		status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
1891da177e4SLinus Torvalds 		if (status)
1901da177e4SLinus Torvalds 			dprintk("nfsd4_open: replay failed"
1911da177e4SLinus Torvalds 				" restoring previous filehandle\n");
1921da177e4SLinus Torvalds 		else
193a90b061cSAl Viro 			status = nfserr_replay_me;
1941da177e4SLinus Torvalds 	}
1951da177e4SLinus Torvalds 	if (status)
1961da177e4SLinus Torvalds 		goto out;
197fb553c0fSJ. Bruce Fields 
198fb553c0fSJ. Bruce Fields 	/* Openowner is now set, so sequence id will get bumped.  Now we need
199fb553c0fSJ. Bruce Fields 	 * these checks before we do any creates: */
200cbd0d51aSJ. Bruce Fields 	status = nfserr_grace;
201af558e33SJ. Bruce Fields 	if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
202cbd0d51aSJ. Bruce Fields 		goto out;
203cbd0d51aSJ. Bruce Fields 	status = nfserr_no_grace;
204af558e33SJ. Bruce Fields 	if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
205cbd0d51aSJ. Bruce Fields 		goto out;
206fb553c0fSJ. Bruce Fields 
2071da177e4SLinus Torvalds 	switch (open->op_claim_type) {
2080dd3c192SNeilBrown 		case NFS4_OPEN_CLAIM_DELEGATE_CUR:
2090dd3c192SNeilBrown 			status = nfserr_inval;
2100dd3c192SNeilBrown 			if (open->op_create)
2110dd3c192SNeilBrown 				goto out;
2120dd3c192SNeilBrown 			/* fall through */
2131da177e4SLinus Torvalds 		case NFS4_OPEN_CLAIM_NULL:
2141da177e4SLinus Torvalds 			/*
2151da177e4SLinus Torvalds 			 * (1) set CURRENT_FH to the file being opened,
2161da177e4SLinus Torvalds 			 * creating it if necessary, (2) set open->op_cinfo,
2171da177e4SLinus Torvalds 			 * (3) set open->op_truncate if the file is to be
2181da177e4SLinus Torvalds 			 * truncated after opening, (4) do permission checking.
2191da177e4SLinus Torvalds 			 */
220ca364317SJ.Bruce Fields 			status = do_open_lookup(rqstp, &cstate->current_fh,
221ca364317SJ.Bruce Fields 						open);
2221da177e4SLinus Torvalds 			if (status)
2231da177e4SLinus Torvalds 				goto out;
2241da177e4SLinus Torvalds 			break;
2251da177e4SLinus Torvalds 		case NFS4_OPEN_CLAIM_PREVIOUS:
226a525825dSJ. Bruce Fields 			open->op_stateowner->so_confirmed = 1;
2271da177e4SLinus Torvalds 			/*
2281da177e4SLinus Torvalds 			 * The CURRENT_FH is already set to the file being
2291da177e4SLinus Torvalds 			 * opened.  (1) set open->op_cinfo, (2) set
2301da177e4SLinus Torvalds 			 * open->op_truncate if the file is to be truncated
2311da177e4SLinus Torvalds 			 * after opening, (3) do permission checking.
2321da177e4SLinus Torvalds 			*/
233ca364317SJ.Bruce Fields 			status = do_open_fhandle(rqstp, &cstate->current_fh,
234ca364317SJ.Bruce Fields 						 open);
2351da177e4SLinus Torvalds 			if (status)
2361da177e4SLinus Torvalds 				goto out;
2371da177e4SLinus Torvalds 			break;
2381da177e4SLinus Torvalds              	case NFS4_OPEN_CLAIM_DELEGATE_PREV:
239a525825dSJ. Bruce Fields 			open->op_stateowner->so_confirmed = 1;
2402fdada03SJ. Bruce Fields 			dprintk("NFSD: unsupported OPEN claim type %d\n",
2411da177e4SLinus Torvalds 				open->op_claim_type);
2421da177e4SLinus Torvalds 			status = nfserr_notsupp;
2431da177e4SLinus Torvalds 			goto out;
2441da177e4SLinus Torvalds 		default:
2452fdada03SJ. Bruce Fields 			dprintk("NFSD: Invalid OPEN claim type %d\n",
2461da177e4SLinus Torvalds 				open->op_claim_type);
2471da177e4SLinus Torvalds 			status = nfserr_inval;
2481da177e4SLinus Torvalds 			goto out;
2491da177e4SLinus Torvalds 	}
2501da177e4SLinus Torvalds 	/*
2511da177e4SLinus Torvalds 	 * nfsd4_process_open2() does the actual opening of the file.  If
2521da177e4SLinus Torvalds 	 * successful, it (1) truncates the file if open->op_truncate was
2531da177e4SLinus Torvalds 	 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
2541da177e4SLinus Torvalds 	 */
255ca364317SJ.Bruce Fields 	status = nfsd4_process_open2(rqstp, &cstate->current_fh, open);
2561da177e4SLinus Torvalds out:
257f2327d9aSNeil Brown 	if (open->op_stateowner) {
2581da177e4SLinus Torvalds 		nfs4_get_stateowner(open->op_stateowner);
259a4f1706aSJ.Bruce Fields 		cstate->replay_owner = open->op_stateowner;
260f2327d9aSNeil Brown 	}
2611da177e4SLinus Torvalds 	nfs4_unlock_state();
2621da177e4SLinus Torvalds 	return status;
2631da177e4SLinus Torvalds }
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds /*
2661da177e4SLinus Torvalds  * filehandle-manipulating ops.
2671da177e4SLinus Torvalds  */
2687191155bSJ.Bruce Fields static __be32
269b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
270b591480bSJ.Bruce Fields 	    struct svc_fh **getfh)
2711da177e4SLinus Torvalds {
272ca364317SJ.Bruce Fields 	if (!cstate->current_fh.fh_dentry)
2731da177e4SLinus Torvalds 		return nfserr_nofilehandle;
2741da177e4SLinus Torvalds 
275ca364317SJ.Bruce Fields 	*getfh = &cstate->current_fh;
2761da177e4SLinus Torvalds 	return nfs_ok;
2771da177e4SLinus Torvalds }
2781da177e4SLinus Torvalds 
2797191155bSJ.Bruce Fields static __be32
280ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
281ca364317SJ.Bruce Fields 	    struct nfsd4_putfh *putfh)
2821da177e4SLinus Torvalds {
283ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
284ca364317SJ.Bruce Fields 	cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
285ca364317SJ.Bruce Fields 	memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
286ca364317SJ.Bruce Fields 	       putfh->pf_fhlen);
2878837abcaSMiklos Szeredi 	return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
2881da177e4SLinus Torvalds }
2891da177e4SLinus Torvalds 
2907191155bSJ.Bruce Fields static __be32
291b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
292b591480bSJ.Bruce Fields 		void *arg)
2931da177e4SLinus Torvalds {
294b37ad28bSAl Viro 	__be32 status;
2951da177e4SLinus Torvalds 
296ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
297df547efbSJ. Bruce Fields 	status = exp_pseudoroot(rqstp, &cstate->current_fh);
2981da177e4SLinus Torvalds 	return status;
2991da177e4SLinus Torvalds }
3001da177e4SLinus Torvalds 
3017191155bSJ.Bruce Fields static __be32
302b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
303b591480bSJ.Bruce Fields 		void *arg)
3041da177e4SLinus Torvalds {
305ca364317SJ.Bruce Fields 	if (!cstate->save_fh.fh_dentry)
3061da177e4SLinus Torvalds 		return nfserr_restorefh;
3071da177e4SLinus Torvalds 
308ca364317SJ.Bruce Fields 	fh_dup2(&cstate->current_fh, &cstate->save_fh);
3091da177e4SLinus Torvalds 	return nfs_ok;
3101da177e4SLinus Torvalds }
3111da177e4SLinus Torvalds 
3127191155bSJ.Bruce Fields static __be32
313b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
314b591480bSJ.Bruce Fields 	     void *arg)
3151da177e4SLinus Torvalds {
316ca364317SJ.Bruce Fields 	if (!cstate->current_fh.fh_dentry)
3171da177e4SLinus Torvalds 		return nfserr_nofilehandle;
3181da177e4SLinus Torvalds 
319ca364317SJ.Bruce Fields 	fh_dup2(&cstate->save_fh, &cstate->current_fh);
3201da177e4SLinus Torvalds 	return nfs_ok;
3211da177e4SLinus Torvalds }
3221da177e4SLinus Torvalds 
3231da177e4SLinus Torvalds /*
3241da177e4SLinus Torvalds  * misc nfsv4 ops
3251da177e4SLinus Torvalds  */
3267191155bSJ.Bruce Fields static __be32
327ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
328ca364317SJ.Bruce Fields 	     struct nfsd4_access *access)
3291da177e4SLinus Torvalds {
3301da177e4SLinus Torvalds 	if (access->ac_req_access & ~NFS3_ACCESS_FULL)
3311da177e4SLinus Torvalds 		return nfserr_inval;
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds 	access->ac_resp_access = access->ac_req_access;
334ca364317SJ.Bruce Fields 	return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
335ca364317SJ.Bruce Fields 			   &access->ac_supported);
3361da177e4SLinus Torvalds }
3371da177e4SLinus Torvalds 
3387191155bSJ.Bruce Fields static __be32
339ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
340ca364317SJ.Bruce Fields 	     struct nfsd4_commit *commit)
3411da177e4SLinus Torvalds {
342b37ad28bSAl Viro 	__be32 status;
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	u32 *p = (u32 *)commit->co_verf.data;
3451da177e4SLinus Torvalds 	*p++ = nfssvc_boot.tv_sec;
3461da177e4SLinus Torvalds 	*p++ = nfssvc_boot.tv_usec;
3471da177e4SLinus Torvalds 
348ca364317SJ.Bruce Fields 	status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
349ca364317SJ.Bruce Fields 			     commit->co_count);
3501da177e4SLinus Torvalds 	if (status == nfserr_symlink)
3511da177e4SLinus Torvalds 		status = nfserr_inval;
3521da177e4SLinus Torvalds 	return status;
3531da177e4SLinus Torvalds }
3541da177e4SLinus Torvalds 
355b37ad28bSAl Viro static __be32
356ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
357ca364317SJ.Bruce Fields 	     struct nfsd4_create *create)
3581da177e4SLinus Torvalds {
3591da177e4SLinus Torvalds 	struct svc_fh resfh;
360b37ad28bSAl Viro 	__be32 status;
3611da177e4SLinus Torvalds 	dev_t rdev;
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds 	fh_init(&resfh, NFS4_FHSIZE);
3641da177e4SLinus Torvalds 
3658837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
3668837abcaSMiklos Szeredi 			   NFSD_MAY_CREATE);
3671da177e4SLinus Torvalds 	if (status == nfserr_symlink)
3681da177e4SLinus Torvalds 		status = nfserr_notdir;
3691da177e4SLinus Torvalds 	if (status)
3701da177e4SLinus Torvalds 		return status;
3711da177e4SLinus Torvalds 
3721da177e4SLinus Torvalds 	switch (create->cr_type) {
3731da177e4SLinus Torvalds 	case NF4LNK:
3741da177e4SLinus Torvalds 		/* ugh! we have to null-terminate the linktext, or
3751da177e4SLinus Torvalds 		 * vfs_symlink() will choke.  it is always safe to
3761da177e4SLinus Torvalds 		 * null-terminate by brute force, since at worst we
3771da177e4SLinus Torvalds 		 * will overwrite the first byte of the create namelen
3781da177e4SLinus Torvalds 		 * in the XDR buffer, which has already been extracted
3791da177e4SLinus Torvalds 		 * during XDR decode.
3801da177e4SLinus Torvalds 		 */
3811da177e4SLinus Torvalds 		create->cr_linkname[create->cr_linklen] = 0;
3821da177e4SLinus Torvalds 
383ca364317SJ.Bruce Fields 		status = nfsd_symlink(rqstp, &cstate->current_fh,
384ca364317SJ.Bruce Fields 				      create->cr_name, create->cr_namelen,
385ca364317SJ.Bruce Fields 				      create->cr_linkname, create->cr_linklen,
386ca364317SJ.Bruce Fields 				      &resfh, &create->cr_iattr);
3871da177e4SLinus Torvalds 		break;
3881da177e4SLinus Torvalds 
3891da177e4SLinus Torvalds 	case NF4BLK:
3901da177e4SLinus Torvalds 		rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
3911da177e4SLinus Torvalds 		if (MAJOR(rdev) != create->cr_specdata1 ||
3921da177e4SLinus Torvalds 		    MINOR(rdev) != create->cr_specdata2)
3931da177e4SLinus Torvalds 			return nfserr_inval;
394ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
395ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
396ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFBLK, rdev, &resfh);
3971da177e4SLinus Torvalds 		break;
3981da177e4SLinus Torvalds 
3991da177e4SLinus Torvalds 	case NF4CHR:
4001da177e4SLinus Torvalds 		rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
4011da177e4SLinus Torvalds 		if (MAJOR(rdev) != create->cr_specdata1 ||
4021da177e4SLinus Torvalds 		    MINOR(rdev) != create->cr_specdata2)
4031da177e4SLinus Torvalds 			return nfserr_inval;
404ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
405ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
406ca364317SJ.Bruce Fields 				     &create->cr_iattr,S_IFCHR, rdev, &resfh);
4071da177e4SLinus Torvalds 		break;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	case NF4SOCK:
410ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
411ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
412ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFSOCK, 0, &resfh);
4131da177e4SLinus Torvalds 		break;
4141da177e4SLinus Torvalds 
4151da177e4SLinus Torvalds 	case NF4FIFO:
416ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
417ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
418ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFIFO, 0, &resfh);
4191da177e4SLinus Torvalds 		break;
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds 	case NF4DIR:
4221da177e4SLinus Torvalds 		create->cr_iattr.ia_valid &= ~ATTR_SIZE;
423ca364317SJ.Bruce Fields 		status = nfsd_create(rqstp, &cstate->current_fh,
424ca364317SJ.Bruce Fields 				     create->cr_name, create->cr_namelen,
425ca364317SJ.Bruce Fields 				     &create->cr_iattr, S_IFDIR, 0, &resfh);
4261da177e4SLinus Torvalds 		break;
4271da177e4SLinus Torvalds 
4281da177e4SLinus Torvalds 	default:
4291da177e4SLinus Torvalds 		status = nfserr_badtype;
4301da177e4SLinus Torvalds 	}
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds 	if (!status) {
433ca364317SJ.Bruce Fields 		fh_unlock(&cstate->current_fh);
434ca364317SJ.Bruce Fields 		set_change_info(&create->cr_cinfo, &cstate->current_fh);
435ca364317SJ.Bruce Fields 		fh_dup2(&cstate->current_fh, &resfh);
4361da177e4SLinus Torvalds 	}
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds 	fh_put(&resfh);
4391da177e4SLinus Torvalds 	return status;
4401da177e4SLinus Torvalds }
4411da177e4SLinus Torvalds 
4427191155bSJ.Bruce Fields static __be32
443ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
444ca364317SJ.Bruce Fields 	      struct nfsd4_getattr *getattr)
4451da177e4SLinus Torvalds {
446b37ad28bSAl Viro 	__be32 status;
4471da177e4SLinus Torvalds 
4488837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
4491da177e4SLinus Torvalds 	if (status)
4501da177e4SLinus Torvalds 		return status;
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds 	if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
4531da177e4SLinus Torvalds 		return nfserr_inval;
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds 	getattr->ga_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0;
4561da177e4SLinus Torvalds 	getattr->ga_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1;
4571da177e4SLinus Torvalds 
458ca364317SJ.Bruce Fields 	getattr->ga_fhp = &cstate->current_fh;
4591da177e4SLinus Torvalds 	return nfs_ok;
4601da177e4SLinus Torvalds }
4611da177e4SLinus Torvalds 
4627191155bSJ.Bruce Fields static __be32
463ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
464ca364317SJ.Bruce Fields 	   struct nfsd4_link *link)
4651da177e4SLinus Torvalds {
466b37ad28bSAl Viro 	__be32 status = nfserr_nofilehandle;
4671da177e4SLinus Torvalds 
468ca364317SJ.Bruce Fields 	if (!cstate->save_fh.fh_dentry)
4691da177e4SLinus Torvalds 		return status;
470ca364317SJ.Bruce Fields 	status = nfsd_link(rqstp, &cstate->current_fh,
471ca364317SJ.Bruce Fields 			   link->li_name, link->li_namelen, &cstate->save_fh);
4721da177e4SLinus Torvalds 	if (!status)
473ca364317SJ.Bruce Fields 		set_change_info(&link->li_cinfo, &cstate->current_fh);
4741da177e4SLinus Torvalds 	return status;
4751da177e4SLinus Torvalds }
4761da177e4SLinus Torvalds 
477b37ad28bSAl Viro static __be32
478b591480bSJ.Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
479b591480bSJ.Bruce Fields 	      void *arg)
4801da177e4SLinus Torvalds {
4811da177e4SLinus Torvalds 	struct svc_fh tmp_fh;
482b37ad28bSAl Viro 	__be32 ret;
4831da177e4SLinus Torvalds 
4841da177e4SLinus Torvalds 	fh_init(&tmp_fh, NFS4_FHSIZE);
485df547efbSJ. Bruce Fields 	ret = exp_pseudoroot(rqstp, &tmp_fh);
486df547efbSJ. Bruce Fields 	if (ret)
4871da177e4SLinus Torvalds 		return ret;
488ca364317SJ.Bruce Fields 	if (tmp_fh.fh_dentry == cstate->current_fh.fh_dentry) {
4891da177e4SLinus Torvalds 		fh_put(&tmp_fh);
4901da177e4SLinus Torvalds 		return nfserr_noent;
4911da177e4SLinus Torvalds 	}
4921da177e4SLinus Torvalds 	fh_put(&tmp_fh);
493ca364317SJ.Bruce Fields 	return nfsd_lookup(rqstp, &cstate->current_fh,
494ca364317SJ.Bruce Fields 			   "..", 2, &cstate->current_fh);
4951da177e4SLinus Torvalds }
4961da177e4SLinus Torvalds 
4977191155bSJ.Bruce Fields static __be32
498ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
499ca364317SJ.Bruce Fields 	     struct nfsd4_lookup *lookup)
5001da177e4SLinus Torvalds {
501ca364317SJ.Bruce Fields 	return nfsd_lookup(rqstp, &cstate->current_fh,
502ca364317SJ.Bruce Fields 			   lookup->lo_name, lookup->lo_len,
503ca364317SJ.Bruce Fields 			   &cstate->current_fh);
5041da177e4SLinus Torvalds }
5051da177e4SLinus Torvalds 
5067191155bSJ.Bruce Fields static __be32
507ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
508ca364317SJ.Bruce Fields 	   struct nfsd4_read *read)
5091da177e4SLinus Torvalds {
510b37ad28bSAl Viro 	__be32 status;
5111da177e4SLinus Torvalds 
5121da177e4SLinus Torvalds 	/* no need to check permission - this will be done in nfsd_read() */
5131da177e4SLinus Torvalds 
5147e06b7f9SNeilBrown 	read->rd_filp = NULL;
5151da177e4SLinus Torvalds 	if (read->rd_offset >= OFFSET_MAX)
5161da177e4SLinus Torvalds 		return nfserr_inval;
5171da177e4SLinus Torvalds 
5181da177e4SLinus Torvalds 	nfs4_lock_state();
5191da177e4SLinus Torvalds 	/* check stateid */
520ca364317SJ.Bruce Fields 	if ((status = nfs4_preprocess_stateid_op(&cstate->current_fh,
521ca364317SJ.Bruce Fields 				&read->rd_stateid,
5226150ef0dSJ. Bruce Fields 				RD_STATE, &read->rd_filp))) {
5231da177e4SLinus Torvalds 		dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
5241da177e4SLinus Torvalds 		goto out;
5251da177e4SLinus Torvalds 	}
5267e06b7f9SNeilBrown 	if (read->rd_filp)
5277e06b7f9SNeilBrown 		get_file(read->rd_filp);
5281da177e4SLinus Torvalds 	status = nfs_ok;
5291da177e4SLinus Torvalds out:
5301da177e4SLinus Torvalds 	nfs4_unlock_state();
5311da177e4SLinus Torvalds 	read->rd_rqstp = rqstp;
532ca364317SJ.Bruce Fields 	read->rd_fhp = &cstate->current_fh;
5331da177e4SLinus Torvalds 	return status;
5341da177e4SLinus Torvalds }
5351da177e4SLinus Torvalds 
5367191155bSJ.Bruce Fields static __be32
537ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
538ca364317SJ.Bruce Fields 	      struct nfsd4_readdir *readdir)
5391da177e4SLinus Torvalds {
5401da177e4SLinus Torvalds 	u64 cookie = readdir->rd_cookie;
5411da177e4SLinus Torvalds 	static const nfs4_verifier zeroverf;
5421da177e4SLinus Torvalds 
5431da177e4SLinus Torvalds 	/* no need to check permission - this will be done in nfsd_readdir() */
5441da177e4SLinus Torvalds 
5451da177e4SLinus Torvalds 	if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
5461da177e4SLinus Torvalds 		return nfserr_inval;
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds 	readdir->rd_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0;
5491da177e4SLinus Torvalds 	readdir->rd_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1;
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds 	if ((cookie > ~(u32)0) || (cookie == 1) || (cookie == 2) ||
5521da177e4SLinus Torvalds 	    (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
5531da177e4SLinus Torvalds 		return nfserr_bad_cookie;
5541da177e4SLinus Torvalds 
5551da177e4SLinus Torvalds 	readdir->rd_rqstp = rqstp;
556ca364317SJ.Bruce Fields 	readdir->rd_fhp = &cstate->current_fh;
5571da177e4SLinus Torvalds 	return nfs_ok;
5581da177e4SLinus Torvalds }
5591da177e4SLinus Torvalds 
5607191155bSJ.Bruce Fields static __be32
561ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
562ca364317SJ.Bruce Fields 	       struct nfsd4_readlink *readlink)
5631da177e4SLinus Torvalds {
5641da177e4SLinus Torvalds 	readlink->rl_rqstp = rqstp;
565ca364317SJ.Bruce Fields 	readlink->rl_fhp = &cstate->current_fh;
5661da177e4SLinus Torvalds 	return nfs_ok;
5671da177e4SLinus Torvalds }
5681da177e4SLinus Torvalds 
5697191155bSJ.Bruce Fields static __be32
570ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
571ca364317SJ.Bruce Fields 	     struct nfsd4_remove *remove)
5721da177e4SLinus Torvalds {
573b37ad28bSAl Viro 	__be32 status;
5741da177e4SLinus Torvalds 
575af558e33SJ. Bruce Fields 	if (locks_in_grace())
576c815afc7SNeilBrown 		return nfserr_grace;
577ca364317SJ.Bruce Fields 	status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
578ca364317SJ.Bruce Fields 			     remove->rm_name, remove->rm_namelen);
5791da177e4SLinus Torvalds 	if (status == nfserr_symlink)
5801da177e4SLinus Torvalds 		return nfserr_notdir;
5811da177e4SLinus Torvalds 	if (!status) {
582ca364317SJ.Bruce Fields 		fh_unlock(&cstate->current_fh);
583ca364317SJ.Bruce Fields 		set_change_info(&remove->rm_cinfo, &cstate->current_fh);
5841da177e4SLinus Torvalds 	}
5851da177e4SLinus Torvalds 	return status;
5861da177e4SLinus Torvalds }
5871da177e4SLinus Torvalds 
5887191155bSJ.Bruce Fields static __be32
589ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
590ca364317SJ.Bruce Fields 	     struct nfsd4_rename *rename)
5911da177e4SLinus Torvalds {
592b37ad28bSAl Viro 	__be32 status = nfserr_nofilehandle;
5931da177e4SLinus Torvalds 
594ca364317SJ.Bruce Fields 	if (!cstate->save_fh.fh_dentry)
5951da177e4SLinus Torvalds 		return status;
596af558e33SJ. Bruce Fields 	if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
597c815afc7SNeilBrown 					& NFSEXP_NOSUBTREECHECK))
598c815afc7SNeilBrown 		return nfserr_grace;
599ca364317SJ.Bruce Fields 	status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
600ca364317SJ.Bruce Fields 			     rename->rn_snamelen, &cstate->current_fh,
6011da177e4SLinus Torvalds 			     rename->rn_tname, rename->rn_tnamelen);
6021da177e4SLinus Torvalds 
6031da177e4SLinus Torvalds 	/* the underlying filesystem returns different error's than required
6041da177e4SLinus Torvalds 	 * by NFSv4. both save_fh and current_fh have been verified.. */
6051da177e4SLinus Torvalds 	if (status == nfserr_isdir)
6061da177e4SLinus Torvalds 		status = nfserr_exist;
6071da177e4SLinus Torvalds 	else if ((status == nfserr_notdir) &&
608ca364317SJ.Bruce Fields                   (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) &&
609ca364317SJ.Bruce Fields                    S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode)))
6101da177e4SLinus Torvalds 		status = nfserr_exist;
6111da177e4SLinus Torvalds 	else if (status == nfserr_symlink)
6121da177e4SLinus Torvalds 		status = nfserr_notdir;
6131da177e4SLinus Torvalds 
6141da177e4SLinus Torvalds 	if (!status) {
615ca364317SJ.Bruce Fields 		set_change_info(&rename->rn_sinfo, &cstate->current_fh);
616ca364317SJ.Bruce Fields 		set_change_info(&rename->rn_tinfo, &cstate->save_fh);
6171da177e4SLinus Torvalds 	}
6181da177e4SLinus Torvalds 	return status;
6191da177e4SLinus Torvalds }
6201da177e4SLinus Torvalds 
6217191155bSJ.Bruce Fields static __be32
622dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
623dcb488a3SAndy Adamson 	      struct nfsd4_secinfo *secinfo)
624dcb488a3SAndy Adamson {
625dcb488a3SAndy Adamson 	struct svc_fh resfh;
626dcb488a3SAndy Adamson 	struct svc_export *exp;
627dcb488a3SAndy Adamson 	struct dentry *dentry;
628dcb488a3SAndy Adamson 	__be32 err;
629dcb488a3SAndy Adamson 
630dcb488a3SAndy Adamson 	fh_init(&resfh, NFS4_FHSIZE);
631dcb488a3SAndy Adamson 	err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
632dcb488a3SAndy Adamson 				    secinfo->si_name, secinfo->si_namelen,
633dcb488a3SAndy Adamson 				    &exp, &dentry);
634dcb488a3SAndy Adamson 	if (err)
635dcb488a3SAndy Adamson 		return err;
636dcb488a3SAndy Adamson 	if (dentry->d_inode == NULL) {
637dcb488a3SAndy Adamson 		exp_put(exp);
638dcb488a3SAndy Adamson 		err = nfserr_noent;
639dcb488a3SAndy Adamson 	} else
640dcb488a3SAndy Adamson 		secinfo->si_exp = exp;
641dcb488a3SAndy Adamson 	dput(dentry);
642dcb488a3SAndy Adamson 	return err;
643dcb488a3SAndy Adamson }
644dcb488a3SAndy Adamson 
645dcb488a3SAndy Adamson static __be32
646ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
647ca364317SJ.Bruce Fields 	      struct nfsd4_setattr *setattr)
6481da177e4SLinus Torvalds {
649b37ad28bSAl Viro 	__be32 status = nfs_ok;
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds 	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
6521da177e4SLinus Torvalds 		nfs4_lock_state();
653ca364317SJ.Bruce Fields 		status = nfs4_preprocess_stateid_op(&cstate->current_fh,
6546150ef0dSJ. Bruce Fields 			&setattr->sa_stateid, WR_STATE, NULL);
6551da177e4SLinus Torvalds 		nfs4_unlock_state();
656375c5547SJ. Bruce Fields 		if (status) {
6573e3b4800SGreg Banks 			dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
658375c5547SJ. Bruce Fields 			return status;
659375c5547SJ. Bruce Fields 		}
6601da177e4SLinus Torvalds 	}
66118f335afSDave Hansen 	status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt);
66218f335afSDave Hansen 	if (status)
66318f335afSDave Hansen 		return status;
6641da177e4SLinus Torvalds 	status = nfs_ok;
6651da177e4SLinus Torvalds 	if (setattr->sa_acl != NULL)
666ca364317SJ.Bruce Fields 		status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
667ca364317SJ.Bruce Fields 					    setattr->sa_acl);
6681da177e4SLinus Torvalds 	if (status)
66918f335afSDave Hansen 		goto out;
670ca364317SJ.Bruce Fields 	status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
6711da177e4SLinus Torvalds 				0, (time_t)0);
67218f335afSDave Hansen out:
67318f335afSDave Hansen 	mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt);
6741da177e4SLinus Torvalds 	return status;
6751da177e4SLinus Torvalds }
6761da177e4SLinus Torvalds 
6777191155bSJ.Bruce Fields static __be32
678ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
679ca364317SJ.Bruce Fields 	    struct nfsd4_write *write)
6801da177e4SLinus Torvalds {
6811da177e4SLinus Torvalds 	stateid_t *stateid = &write->wr_stateid;
6821da177e4SLinus Torvalds 	struct file *filp = NULL;
6831da177e4SLinus Torvalds 	u32 *p;
684b37ad28bSAl Viro 	__be32 status = nfs_ok;
68531dec253SDavid Shaw 	unsigned long cnt;
6861da177e4SLinus Torvalds 
6871da177e4SLinus Torvalds 	/* no need to check permission - this will be done in nfsd_write() */
6881da177e4SLinus Torvalds 
6891da177e4SLinus Torvalds 	if (write->wr_offset >= OFFSET_MAX)
6901da177e4SLinus Torvalds 		return nfserr_inval;
6911da177e4SLinus Torvalds 
6921da177e4SLinus Torvalds 	nfs4_lock_state();
693ca364317SJ.Bruce Fields 	status = nfs4_preprocess_stateid_op(&cstate->current_fh, stateid,
6946150ef0dSJ. Bruce Fields 					WR_STATE, &filp);
6957e06b7f9SNeilBrown 	if (filp)
6967e06b7f9SNeilBrown 		get_file(filp);
6971da177e4SLinus Torvalds 	nfs4_unlock_state();
6981da177e4SLinus Torvalds 
699375c5547SJ. Bruce Fields 	if (status) {
700375c5547SJ. Bruce Fields 		dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
701375c5547SJ. Bruce Fields 		return status;
702375c5547SJ. Bruce Fields 	}
703375c5547SJ. Bruce Fields 
70431dec253SDavid Shaw 	cnt = write->wr_buflen;
7051da177e4SLinus Torvalds 	write->wr_how_written = write->wr_stable_how;
7061da177e4SLinus Torvalds 	p = (u32 *)write->wr_verifier.data;
7071da177e4SLinus Torvalds 	*p++ = nfssvc_boot.tv_sec;
7081da177e4SLinus Torvalds 	*p++ = nfssvc_boot.tv_usec;
7091da177e4SLinus Torvalds 
710ca364317SJ.Bruce Fields 	status =  nfsd_write(rqstp, &cstate->current_fh, filp,
711ca364317SJ.Bruce Fields 			     write->wr_offset, rqstp->rq_vec, write->wr_vlen,
71231dec253SDavid Shaw 			     &cnt, &write->wr_how_written);
7137e06b7f9SNeilBrown 	if (filp)
7147e06b7f9SNeilBrown 		fput(filp);
7151da177e4SLinus Torvalds 
71631dec253SDavid Shaw 	write->wr_bytes_written = cnt;
71731dec253SDavid Shaw 
7181da177e4SLinus Torvalds 	if (status == nfserr_symlink)
7191da177e4SLinus Torvalds 		status = nfserr_inval;
7201da177e4SLinus Torvalds 	return status;
7211da177e4SLinus Torvalds }
7221da177e4SLinus Torvalds 
7231da177e4SLinus Torvalds /* This routine never returns NFS_OK!  If there are no other errors, it
7241da177e4SLinus Torvalds  * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
7251da177e4SLinus Torvalds  * attributes matched.  VERIFY is implemented by mapping NFSERR_SAME
7261da177e4SLinus Torvalds  * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
7271da177e4SLinus Torvalds  */
728b37ad28bSAl Viro static __be32
729c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
730ca364317SJ.Bruce Fields 	     struct nfsd4_verify *verify)
7311da177e4SLinus Torvalds {
7322ebbc012SAl Viro 	__be32 *buf, *p;
7331da177e4SLinus Torvalds 	int count;
734b37ad28bSAl Viro 	__be32 status;
7351da177e4SLinus Torvalds 
7368837abcaSMiklos Szeredi 	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
7371da177e4SLinus Torvalds 	if (status)
7381da177e4SLinus Torvalds 		return status;
7391da177e4SLinus Torvalds 
7401da177e4SLinus Torvalds 	if ((verify->ve_bmval[0] & ~NFSD_SUPPORTED_ATTRS_WORD0)
7411da177e4SLinus Torvalds 	    || (verify->ve_bmval[1] & ~NFSD_SUPPORTED_ATTRS_WORD1))
7421da177e4SLinus Torvalds 		return nfserr_attrnotsupp;
7431da177e4SLinus Torvalds 	if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
7441da177e4SLinus Torvalds 	    || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
7451da177e4SLinus Torvalds 		return nfserr_inval;
7461da177e4SLinus Torvalds 	if (verify->ve_attrlen & 3)
7471da177e4SLinus Torvalds 		return nfserr_inval;
7481da177e4SLinus Torvalds 
7491da177e4SLinus Torvalds 	/* count in words:
7501da177e4SLinus Torvalds 	 *   bitmap_len(1) + bitmap(2) + attr_len(1) = 4
7511da177e4SLinus Torvalds 	 */
7521da177e4SLinus Torvalds 	count = 4 + (verify->ve_attrlen >> 2);
7531da177e4SLinus Torvalds 	buf = kmalloc(count << 2, GFP_KERNEL);
7541da177e4SLinus Torvalds 	if (!buf)
7551da177e4SLinus Torvalds 		return nfserr_resource;
7561da177e4SLinus Torvalds 
757ca364317SJ.Bruce Fields 	status = nfsd4_encode_fattr(&cstate->current_fh,
758ca364317SJ.Bruce Fields 				    cstate->current_fh.fh_export,
759ca364317SJ.Bruce Fields 				    cstate->current_fh.fh_dentry, buf,
7601da177e4SLinus Torvalds 				    &count, verify->ve_bmval,
761406a7ea9SFrank Filz 				    rqstp, 0);
7621da177e4SLinus Torvalds 
7631da177e4SLinus Torvalds 	/* this means that nfsd4_encode_fattr() ran out of space */
7641da177e4SLinus Torvalds 	if (status == nfserr_resource && count == 0)
7651da177e4SLinus Torvalds 		status = nfserr_not_same;
7661da177e4SLinus Torvalds 	if (status)
7671da177e4SLinus Torvalds 		goto out_kfree;
7681da177e4SLinus Torvalds 
7691da177e4SLinus Torvalds 	p = buf + 3;
7701da177e4SLinus Torvalds 	status = nfserr_not_same;
7711da177e4SLinus Torvalds 	if (ntohl(*p++) != verify->ve_attrlen)
7721da177e4SLinus Torvalds 		goto out_kfree;
7731da177e4SLinus Torvalds 	if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
7741da177e4SLinus Torvalds 		status = nfserr_same;
7751da177e4SLinus Torvalds 
7761da177e4SLinus Torvalds out_kfree:
7771da177e4SLinus Torvalds 	kfree(buf);
7781da177e4SLinus Torvalds 	return status;
7791da177e4SLinus Torvalds }
7801da177e4SLinus Torvalds 
781c954e2a5SJ.Bruce Fields static __be32
782c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
783c954e2a5SJ.Bruce Fields 	      struct nfsd4_verify *verify)
784c954e2a5SJ.Bruce Fields {
785c954e2a5SJ.Bruce Fields 	__be32 status;
786c954e2a5SJ.Bruce Fields 
787c954e2a5SJ.Bruce Fields 	status = _nfsd4_verify(rqstp, cstate, verify);
788c954e2a5SJ.Bruce Fields 	return status == nfserr_not_same ? nfs_ok : status;
789c954e2a5SJ.Bruce Fields }
790c954e2a5SJ.Bruce Fields 
791c954e2a5SJ.Bruce Fields static __be32
792c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
793c954e2a5SJ.Bruce Fields 	     struct nfsd4_verify *verify)
794c954e2a5SJ.Bruce Fields {
795c954e2a5SJ.Bruce Fields 	__be32 status;
796c954e2a5SJ.Bruce Fields 
797c954e2a5SJ.Bruce Fields 	status = _nfsd4_verify(rqstp, cstate, verify);
798c954e2a5SJ.Bruce Fields 	return status == nfserr_same ? nfs_ok : status;
799c954e2a5SJ.Bruce Fields }
800c954e2a5SJ.Bruce Fields 
8011da177e4SLinus Torvalds /*
8021da177e4SLinus Torvalds  * NULL call.
8031da177e4SLinus Torvalds  */
8047111c66eSAl Viro static __be32
8051da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
8061da177e4SLinus Torvalds {
8071da177e4SLinus Torvalds 	return nfs_ok;
8081da177e4SLinus Torvalds }
8091da177e4SLinus Torvalds 
810e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum)
811e2b20950SShankar Anand {
812e2b20950SShankar Anand 	if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
813e2b20950SShankar Anand 		nfsdstats.nfs4_opcount[opnum]++;
814e2b20950SShankar Anand }
815e2b20950SShankar Anand 
816ca364317SJ.Bruce Fields static void cstate_free(struct nfsd4_compound_state *cstate)
817ca364317SJ.Bruce Fields {
818ca364317SJ.Bruce Fields 	if (cstate == NULL)
819ca364317SJ.Bruce Fields 		return;
820ca364317SJ.Bruce Fields 	fh_put(&cstate->current_fh);
821ca364317SJ.Bruce Fields 	fh_put(&cstate->save_fh);
822a4f1706aSJ.Bruce Fields 	BUG_ON(cstate->replay_owner);
823ca364317SJ.Bruce Fields 	kfree(cstate);
824ca364317SJ.Bruce Fields }
825ca364317SJ.Bruce Fields 
826ca364317SJ.Bruce Fields static struct nfsd4_compound_state *cstate_alloc(void)
827ca364317SJ.Bruce Fields {
828ca364317SJ.Bruce Fields 	struct nfsd4_compound_state *cstate;
829ca364317SJ.Bruce Fields 
830ca364317SJ.Bruce Fields 	cstate = kmalloc(sizeof(struct nfsd4_compound_state), GFP_KERNEL);
831ca364317SJ.Bruce Fields 	if (cstate == NULL)
832ca364317SJ.Bruce Fields 		return NULL;
833ca364317SJ.Bruce Fields 	fh_init(&cstate->current_fh, NFS4_FHSIZE);
834ca364317SJ.Bruce Fields 	fh_init(&cstate->save_fh, NFS4_FHSIZE);
835a4f1706aSJ.Bruce Fields 	cstate->replay_owner = NULL;
836ca364317SJ.Bruce Fields 	return cstate;
837ca364317SJ.Bruce Fields }
8381da177e4SLinus Torvalds 
839b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
840b591480bSJ.Bruce Fields 			      void *);
841b591480bSJ.Bruce Fields 
842b591480bSJ.Bruce Fields struct nfsd4_operation {
843b591480bSJ.Bruce Fields 	nfsd4op_func op_func;
844b591480bSJ.Bruce Fields 	u32 op_flags;
84527d630ecSJ.Bruce Fields /* Most ops require a valid current filehandle; a few don't: */
84627d630ecSJ.Bruce Fields #define ALLOWED_WITHOUT_FH 1
847eeac294eSJ.Bruce Fields /* GETATTR and ops not listed as returning NFS4ERR_MOVED: */
84827d630ecSJ.Bruce Fields #define ALLOWED_ON_ABSENT_FS 2
849b001a1b6SBenny Halevy 	char *op_name;
850b591480bSJ.Bruce Fields };
851b591480bSJ.Bruce Fields 
852b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[];
853b591480bSJ.Bruce Fields 
854f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum);
855b001a1b6SBenny Halevy 
8561da177e4SLinus Torvalds /*
8571da177e4SLinus Torvalds  * COMPOUND call.
8581da177e4SLinus Torvalds  */
8597111c66eSAl Viro static __be32
8601da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp,
8611da177e4SLinus Torvalds 		    struct nfsd4_compoundargs *args,
8621da177e4SLinus Torvalds 		    struct nfsd4_compoundres *resp)
8631da177e4SLinus Torvalds {
8641da177e4SLinus Torvalds 	struct nfsd4_op	*op;
865b591480bSJ.Bruce Fields 	struct nfsd4_operation *opdesc;
866ca364317SJ.Bruce Fields 	struct nfsd4_compound_state *cstate = NULL;
867e5710199SJ.Bruce Fields 	int		slack_bytes;
868b37ad28bSAl Viro 	__be32		status;
8691da177e4SLinus Torvalds 
8701da177e4SLinus Torvalds 	resp->xbuf = &rqstp->rq_res;
8711da177e4SLinus Torvalds 	resp->p = rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len;
8721da177e4SLinus Torvalds 	resp->tagp = resp->p;
8731da177e4SLinus Torvalds 	/* reserve space for: taglen, tag, and opcnt */
8741da177e4SLinus Torvalds 	resp->p += 2 + XDR_QUADLEN(args->taglen);
8751da177e4SLinus Torvalds 	resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
8761da177e4SLinus Torvalds 	resp->taglen = args->taglen;
8771da177e4SLinus Torvalds 	resp->tag = args->tag;
8781da177e4SLinus Torvalds 	resp->opcnt = 0;
8791da177e4SLinus Torvalds 	resp->rqstp = rqstp;
8801da177e4SLinus Torvalds 
8811da177e4SLinus Torvalds 	/*
8821da177e4SLinus Torvalds 	 * According to RFC3010, this takes precedence over all other errors.
8831da177e4SLinus Torvalds 	 */
8841da177e4SLinus Torvalds 	status = nfserr_minor_vers_mismatch;
8851da177e4SLinus Torvalds 	if (args->minorversion > NFSD_SUPPORTED_MINOR_VERSION)
8861da177e4SLinus Torvalds 		goto out;
8871da177e4SLinus Torvalds 
888c228c24bSAndy Adamson 	status = nfserr_resource;
889c228c24bSAndy Adamson 	cstate = cstate_alloc();
890c228c24bSAndy Adamson 	if (cstate == NULL)
891c228c24bSAndy Adamson 		goto out;
892c228c24bSAndy Adamson 
8931da177e4SLinus Torvalds 	status = nfs_ok;
8941da177e4SLinus Torvalds 	while (!status && resp->opcnt < args->opcnt) {
8951da177e4SLinus Torvalds 		op = &args->ops[resp->opcnt++];
8961da177e4SLinus Torvalds 
897b001a1b6SBenny Halevy 		dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
898b001a1b6SBenny Halevy 			resp->opcnt, args->opcnt, op->opnum,
899b001a1b6SBenny Halevy 			nfsd4_op_name(op->opnum));
900fd445277SJ. Bruce Fields 
9011da177e4SLinus Torvalds 		/*
9021da177e4SLinus Torvalds 		 * The XDR decode routines may have pre-set op->status;
9031da177e4SLinus Torvalds 		 * for example, if there is a miscellaneous XDR error
9041da177e4SLinus Torvalds 		 * it will be set to nfserr_bad_xdr.
9051da177e4SLinus Torvalds 		 */
9061da177e4SLinus Torvalds 		if (op->status)
9071da177e4SLinus Torvalds 			goto encode_op;
9081da177e4SLinus Torvalds 
9091da177e4SLinus Torvalds 		/* We must be able to encode a successful response to
9101da177e4SLinus Torvalds 		 * this operation, with enough room left over to encode a
9111da177e4SLinus Torvalds 		 * failed response to the next operation.  If we don't
9121da177e4SLinus Torvalds 		 * have enough room, fail with ERR_RESOURCE.
9131da177e4SLinus Torvalds 		 */
914e5710199SJ.Bruce Fields 		slack_bytes = (char *)resp->end - (char *)resp->p;
915e5710199SJ.Bruce Fields 		if (slack_bytes < COMPOUND_SLACK_SPACE
916e5710199SJ.Bruce Fields 				+ COMPOUND_ERR_SLACK_SPACE) {
917e5710199SJ.Bruce Fields 			BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE);
9181da177e4SLinus Torvalds 			op->status = nfserr_resource;
9191da177e4SLinus Torvalds 			goto encode_op;
9201da177e4SLinus Torvalds 		}
9211da177e4SLinus Torvalds 
922b591480bSJ.Bruce Fields 		opdesc = &nfsd4_ops[op->opnum];
923b591480bSJ.Bruce Fields 
924ca364317SJ.Bruce Fields 		if (!cstate->current_fh.fh_dentry) {
92527d630ecSJ.Bruce Fields 			if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
9261da177e4SLinus Torvalds 				op->status = nfserr_nofilehandle;
9271da177e4SLinus Torvalds 				goto encode_op;
9281da177e4SLinus Torvalds 			}
929eeac294eSJ.Bruce Fields 		} else if (cstate->current_fh.fh_export->ex_fslocs.migrated &&
930eeac294eSJ.Bruce Fields 			  !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
93142ca0993SJ.Bruce Fields 			op->status = nfserr_moved;
93242ca0993SJ.Bruce Fields 			goto encode_op;
93342ca0993SJ.Bruce Fields 		}
934b591480bSJ.Bruce Fields 
935b591480bSJ.Bruce Fields 		if (opdesc->op_func)
936b591480bSJ.Bruce Fields 			op->status = opdesc->op_func(rqstp, cstate, &op->u);
937b591480bSJ.Bruce Fields 		else
9381da177e4SLinus Torvalds 			BUG_ON(op->status == nfs_ok);
9391da177e4SLinus Torvalds 
9401da177e4SLinus Torvalds encode_op:
941a90b061cSAl Viro 		if (op->status == nfserr_replay_me) {
942a4f1706aSJ.Bruce Fields 			op->replay = &cstate->replay_owner->so_replay;
9431da177e4SLinus Torvalds 			nfsd4_encode_replay(resp, op);
9441da177e4SLinus Torvalds 			status = op->status = op->replay->rp_status;
9451da177e4SLinus Torvalds 		} else {
9461da177e4SLinus Torvalds 			nfsd4_encode_operation(resp, op);
9471da177e4SLinus Torvalds 			status = op->status;
9481da177e4SLinus Torvalds 		}
9490407717dSBenny Halevy 
9500407717dSBenny Halevy 		dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
9510407717dSBenny Halevy 			args->ops, args->opcnt, resp->opcnt, op->opnum,
9520407717dSBenny Halevy 			be32_to_cpu(status));
9530407717dSBenny Halevy 
954a4f1706aSJ.Bruce Fields 		if (cstate->replay_owner) {
955a4f1706aSJ.Bruce Fields 			nfs4_put_stateowner(cstate->replay_owner);
956a4f1706aSJ.Bruce Fields 			cstate->replay_owner = NULL;
9571da177e4SLinus Torvalds 		}
9587e06b7f9SNeilBrown 		/* XXX Ugh, we need to get rid of this kind of special case: */
9597e06b7f9SNeilBrown 		if (op->opnum == OP_READ && op->u.read.rd_filp)
9607e06b7f9SNeilBrown 			fput(op->u.read.rd_filp);
961e2b20950SShankar Anand 
962e2b20950SShankar Anand 		nfsd4_increment_op_stats(op->opnum);
9631da177e4SLinus Torvalds 	}
9641da177e4SLinus Torvalds 
965c228c24bSAndy Adamson 	cstate_free(cstate);
9661da177e4SLinus Torvalds out:
9671da177e4SLinus Torvalds 	nfsd4_release_compoundargs(args);
9683b12cd98SJ. Bruce Fields 	dprintk("nfsv4 compound returned %d\n", ntohl(status));
9691da177e4SLinus Torvalds 	return status;
9701da177e4SLinus Torvalds }
9711da177e4SLinus Torvalds 
972b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[OP_RELEASE_LOCKOWNER+1] = {
973b591480bSJ.Bruce Fields 	[OP_ACCESS] = {
974b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_access,
975b001a1b6SBenny Halevy 		.op_name = "OP_ACCESS",
976b591480bSJ.Bruce Fields 	},
977b591480bSJ.Bruce Fields 	[OP_CLOSE] = {
978b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_close,
979b001a1b6SBenny Halevy 		.op_name = "OP_CLOSE",
980b591480bSJ.Bruce Fields 	},
981b591480bSJ.Bruce Fields 	[OP_COMMIT] = {
982b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_commit,
983b001a1b6SBenny Halevy 		.op_name = "OP_COMMIT",
984b591480bSJ.Bruce Fields 	},
985b591480bSJ.Bruce Fields 	[OP_CREATE] = {
986b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_create,
987b001a1b6SBenny Halevy 		.op_name = "OP_CREATE",
988b591480bSJ.Bruce Fields 	},
989b591480bSJ.Bruce Fields 	[OP_DELEGRETURN] = {
990b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_delegreturn,
991b001a1b6SBenny Halevy 		.op_name = "OP_DELEGRETURN",
992b591480bSJ.Bruce Fields 	},
993b591480bSJ.Bruce Fields 	[OP_GETATTR] = {
994b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_getattr,
995eeac294eSJ.Bruce Fields 		.op_flags = ALLOWED_ON_ABSENT_FS,
996b001a1b6SBenny Halevy 		.op_name = "OP_GETATTR",
997b591480bSJ.Bruce Fields 	},
998b591480bSJ.Bruce Fields 	[OP_GETFH] = {
999b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_getfh,
1000b001a1b6SBenny Halevy 		.op_name = "OP_GETFH",
1001b591480bSJ.Bruce Fields 	},
1002b591480bSJ.Bruce Fields 	[OP_LINK] = {
1003b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_link,
1004b001a1b6SBenny Halevy 		.op_name = "OP_LINK",
1005b591480bSJ.Bruce Fields 	},
1006b591480bSJ.Bruce Fields 	[OP_LOCK] = {
1007b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_lock,
1008b001a1b6SBenny Halevy 		.op_name = "OP_LOCK",
1009b591480bSJ.Bruce Fields 	},
1010b591480bSJ.Bruce Fields 	[OP_LOCKT] = {
1011b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_lockt,
1012b001a1b6SBenny Halevy 		.op_name = "OP_LOCKT",
1013b591480bSJ.Bruce Fields 	},
1014b591480bSJ.Bruce Fields 	[OP_LOCKU] = {
1015b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_locku,
1016b001a1b6SBenny Halevy 		.op_name = "OP_LOCKU",
1017b591480bSJ.Bruce Fields 	},
1018b591480bSJ.Bruce Fields 	[OP_LOOKUP] = {
1019b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_lookup,
1020b001a1b6SBenny Halevy 		.op_name = "OP_LOOKUP",
1021b591480bSJ.Bruce Fields 	},
1022b591480bSJ.Bruce Fields 	[OP_LOOKUPP] = {
1023b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_lookupp,
1024b001a1b6SBenny Halevy 		.op_name = "OP_LOOKUPP",
1025b591480bSJ.Bruce Fields 	},
1026b591480bSJ.Bruce Fields 	[OP_NVERIFY] = {
1027b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_nverify,
1028b001a1b6SBenny Halevy 		.op_name = "OP_NVERIFY",
1029b591480bSJ.Bruce Fields 	},
1030b591480bSJ.Bruce Fields 	[OP_OPEN] = {
1031b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_open,
1032b001a1b6SBenny Halevy 		.op_name = "OP_OPEN",
1033b591480bSJ.Bruce Fields 	},
1034b591480bSJ.Bruce Fields 	[OP_OPEN_CONFIRM] = {
1035b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_open_confirm,
1036b001a1b6SBenny Halevy 		.op_name = "OP_OPEN_CONFIRM",
1037b591480bSJ.Bruce Fields 	},
1038b591480bSJ.Bruce Fields 	[OP_OPEN_DOWNGRADE] = {
1039b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_open_downgrade,
1040b001a1b6SBenny Halevy 		.op_name = "OP_OPEN_DOWNGRADE",
1041b591480bSJ.Bruce Fields 	},
1042b591480bSJ.Bruce Fields 	[OP_PUTFH] = {
1043b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_putfh,
104427d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1045b001a1b6SBenny Halevy 		.op_name = "OP_PUTFH",
1046b591480bSJ.Bruce Fields 	},
1047eeac294eSJ.Bruce Fields 	[OP_PUTPUBFH] = {
1048*a1c8c4d1SJ. Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_putrootfh,
104927d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1050b001a1b6SBenny Halevy 		.op_name = "OP_PUTPUBFH",
1051eeac294eSJ.Bruce Fields 	},
1052b591480bSJ.Bruce Fields 	[OP_PUTROOTFH] = {
1053b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_putrootfh,
105427d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1055b001a1b6SBenny Halevy 		.op_name = "OP_PUTROOTFH",
1056b591480bSJ.Bruce Fields 	},
1057b591480bSJ.Bruce Fields 	[OP_READ] = {
1058b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_read,
1059b001a1b6SBenny Halevy 		.op_name = "OP_READ",
1060b591480bSJ.Bruce Fields 	},
1061b591480bSJ.Bruce Fields 	[OP_READDIR] = {
1062b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_readdir,
1063b001a1b6SBenny Halevy 		.op_name = "OP_READDIR",
1064b591480bSJ.Bruce Fields 	},
1065b591480bSJ.Bruce Fields 	[OP_READLINK] = {
1066b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_readlink,
1067b001a1b6SBenny Halevy 		.op_name = "OP_READLINK",
1068b591480bSJ.Bruce Fields 	},
1069b591480bSJ.Bruce Fields 	[OP_REMOVE] = {
1070b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_remove,
1071b001a1b6SBenny Halevy 		.op_name = "OP_REMOVE",
1072b591480bSJ.Bruce Fields 	},
1073b591480bSJ.Bruce Fields 	[OP_RENAME] = {
1074b001a1b6SBenny Halevy 		.op_name = "OP_RENAME",
1075b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_rename,
1076b591480bSJ.Bruce Fields 	},
1077b591480bSJ.Bruce Fields 	[OP_RENEW] = {
1078b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_renew,
107927d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1080b001a1b6SBenny Halevy 		.op_name = "OP_RENEW",
1081b591480bSJ.Bruce Fields 	},
1082b591480bSJ.Bruce Fields 	[OP_RESTOREFH] = {
1083b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_restorefh,
108427d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1085b001a1b6SBenny Halevy 		.op_name = "OP_RESTOREFH",
1086b591480bSJ.Bruce Fields 	},
1087b591480bSJ.Bruce Fields 	[OP_SAVEFH] = {
1088b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_savefh,
1089b001a1b6SBenny Halevy 		.op_name = "OP_SAVEFH",
1090b591480bSJ.Bruce Fields 	},
1091dcb488a3SAndy Adamson 	[OP_SECINFO] = {
1092dcb488a3SAndy Adamson 		.op_func = (nfsd4op_func)nfsd4_secinfo,
1093b001a1b6SBenny Halevy 		.op_name = "OP_SECINFO",
1094dcb488a3SAndy Adamson 	},
1095b591480bSJ.Bruce Fields 	[OP_SETATTR] = {
1096b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_setattr,
1097b001a1b6SBenny Halevy 		.op_name = "OP_SETATTR",
1098b591480bSJ.Bruce Fields 	},
1099b591480bSJ.Bruce Fields 	[OP_SETCLIENTID] = {
1100b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_setclientid,
110127d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1102b001a1b6SBenny Halevy 		.op_name = "OP_SETCLIENTID",
1103b591480bSJ.Bruce Fields 	},
1104b591480bSJ.Bruce Fields 	[OP_SETCLIENTID_CONFIRM] = {
1105b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
110627d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1107b001a1b6SBenny Halevy 		.op_name = "OP_SETCLIENTID_CONFIRM",
1108b591480bSJ.Bruce Fields 	},
1109b591480bSJ.Bruce Fields 	[OP_VERIFY] = {
1110b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_verify,
1111b001a1b6SBenny Halevy 		.op_name = "OP_VERIFY",
1112b591480bSJ.Bruce Fields 	},
1113b591480bSJ.Bruce Fields 	[OP_WRITE] = {
1114b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_write,
1115b001a1b6SBenny Halevy 		.op_name = "OP_WRITE",
1116b591480bSJ.Bruce Fields 	},
1117b591480bSJ.Bruce Fields 	[OP_RELEASE_LOCKOWNER] = {
1118b591480bSJ.Bruce Fields 		.op_func = (nfsd4op_func)nfsd4_release_lockowner,
111927d630ecSJ.Bruce Fields 		.op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
1120b001a1b6SBenny Halevy 		.op_name = "OP_RELEASE_LOCKOWNER",
1121b591480bSJ.Bruce Fields 	},
1122b591480bSJ.Bruce Fields };
1123b591480bSJ.Bruce Fields 
1124f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum)
1125b001a1b6SBenny Halevy {
1126b001a1b6SBenny Halevy 	if (opnum < ARRAY_SIZE(nfsd4_ops))
1127b001a1b6SBenny Halevy 		return nfsd4_ops[opnum].op_name;
1128b001a1b6SBenny Halevy 	return "unknown_operation";
1129b001a1b6SBenny Halevy }
1130b001a1b6SBenny Halevy 
11311da177e4SLinus Torvalds #define nfs4svc_decode_voidargs		NULL
11321da177e4SLinus Torvalds #define nfs4svc_release_void		NULL
11331da177e4SLinus Torvalds #define nfsd4_voidres			nfsd4_voidargs
11341da177e4SLinus Torvalds #define nfs4svc_release_compound	NULL
11351da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; };
11361da177e4SLinus Torvalds 
11371da177e4SLinus Torvalds #define PROC(name, argt, rest, relt, cache, respsize)	\
11381da177e4SLinus Torvalds  { (svc_procfunc) nfsd4_proc_##name,		\
11391da177e4SLinus Torvalds    (kxdrproc_t) nfs4svc_decode_##argt##args,	\
11401da177e4SLinus Torvalds    (kxdrproc_t) nfs4svc_encode_##rest##res,	\
11411da177e4SLinus Torvalds    (kxdrproc_t) nfs4svc_release_##relt,		\
11421da177e4SLinus Torvalds    sizeof(struct nfsd4_##argt##args),		\
11431da177e4SLinus Torvalds    sizeof(struct nfsd4_##rest##res),		\
11441da177e4SLinus Torvalds    0,						\
11451da177e4SLinus Torvalds    cache,					\
11461da177e4SLinus Torvalds    respsize,					\
11471da177e4SLinus Torvalds  }
11481da177e4SLinus Torvalds 
11491da177e4SLinus Torvalds /*
11501da177e4SLinus Torvalds  * TODO: At the present time, the NFSv4 server does not do XID caching
11511da177e4SLinus Torvalds  * of requests.  Implementing XID caching would not be a serious problem,
11521da177e4SLinus Torvalds  * although it would require a mild change in interfaces since one
11531da177e4SLinus Torvalds  * doesn't know whether an NFSv4 request is idempotent until after the
11541da177e4SLinus Torvalds  * XDR decode.  However, XID caching totally confuses pynfs (Peter
11551da177e4SLinus Torvalds  * Astrand's regression testsuite for NFSv4 servers), which reuses
11561da177e4SLinus Torvalds  * XID's liberally, so I've left it unimplemented until pynfs generates
11571da177e4SLinus Torvalds  * better XID's.
11581da177e4SLinus Torvalds  */
11591da177e4SLinus Torvalds static struct svc_procedure		nfsd_procedures4[2] = {
11601da177e4SLinus Torvalds   PROC(null,	 void,		void,		void,	  RC_NOCACHE, 1),
11617775f4c8SNeilBrown   PROC(compound, compound,	compound,	compound, RC_NOCACHE, NFSD_BUFSIZE/4)
11621da177e4SLinus Torvalds };
11631da177e4SLinus Torvalds 
11641da177e4SLinus Torvalds struct svc_version	nfsd_version4 = {
11651da177e4SLinus Torvalds 		.vs_vers	= 4,
11661da177e4SLinus Torvalds 		.vs_nproc	= 2,
11671da177e4SLinus Torvalds 		.vs_proc	= nfsd_procedures4,
11681da177e4SLinus Torvalds 		.vs_dispatch	= nfsd_dispatch,
11691da177e4SLinus Torvalds 		.vs_xdrsize	= NFS4_SVC_XDRSIZE,
11701da177e4SLinus Torvalds };
11711da177e4SLinus Torvalds 
11721da177e4SLinus Torvalds /*
11731da177e4SLinus Torvalds  * Local variables:
11741da177e4SLinus Torvalds  *  c-basic-offset: 8
11751da177e4SLinus Torvalds  * End:
11761da177e4SLinus Torvalds  */
1177