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 */ 357e06b7f9SNeilBrown #include <linux/file.h> 365a0e3ad6STejun Heo #include <linux/slab.h> 371da177e4SLinus Torvalds 389a74af21SBoaz Harrosh #include "cache.h" 399a74af21SBoaz Harrosh #include "xdr4.h" 400a3adadeSJ. Bruce Fields #include "vfs.h" 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 431da177e4SLinus Torvalds 443c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 453c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 463c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 473c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 483c8e0316SYu Zhiguo }; 493c8e0316SYu Zhiguo 503c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 513c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 523c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 533c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 543c8e0316SYu Zhiguo }; 553c8e0316SYu Zhiguo 563c8e0316SYu Zhiguo static __be32 573c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 583c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 593c8e0316SYu Zhiguo { 603c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 613c8e0316SYu Zhiguo 623c8e0316SYu Zhiguo /* 633c8e0316SYu Zhiguo * Check about attributes are supported by the NFSv4 server or not. 643c8e0316SYu Zhiguo * According to spec, unsupported attributes return ERR_ATTRNOTSUPP. 653c8e0316SYu Zhiguo */ 663c8e0316SYu Zhiguo if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) || 673c8e0316SYu Zhiguo (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) || 683c8e0316SYu Zhiguo (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion))) 693c8e0316SYu Zhiguo return nfserr_attrnotsupp; 703c8e0316SYu Zhiguo 713c8e0316SYu Zhiguo /* 72a06b1261STrond Myklebust * Check FATTR4_WORD0_ACL can be supported 733c8e0316SYu Zhiguo * in current environment or not. 743c8e0316SYu Zhiguo */ 753c8e0316SYu Zhiguo if (bmval[0] & FATTR4_WORD0_ACL) { 763c8e0316SYu Zhiguo if (!IS_POSIXACL(dentry->d_inode)) 773c8e0316SYu Zhiguo return nfserr_attrnotsupp; 783c8e0316SYu Zhiguo } 793c8e0316SYu Zhiguo 803c8e0316SYu Zhiguo /* 813c8e0316SYu Zhiguo * According to spec, read-only attributes return ERR_INVAL. 823c8e0316SYu Zhiguo */ 833c8e0316SYu Zhiguo if (writable) { 843c8e0316SYu Zhiguo if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) || 853c8e0316SYu Zhiguo (bmval[2] & ~writable[2])) 863c8e0316SYu Zhiguo return nfserr_inval; 873c8e0316SYu Zhiguo } 883c8e0316SYu Zhiguo 893c8e0316SYu Zhiguo return nfs_ok; 903c8e0316SYu Zhiguo } 913c8e0316SYu Zhiguo 923c8e0316SYu Zhiguo static __be32 933c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 943c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 953c8e0316SYu Zhiguo { 963c8e0316SYu Zhiguo __be32 status = nfs_ok; 973c8e0316SYu Zhiguo 983c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 993c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1003c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1013c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1023c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1033c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1043c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1053c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1063c8e0316SYu Zhiguo } 1073c8e0316SYu Zhiguo 1083c8e0316SYu Zhiguo return status; 1093c8e0316SYu Zhiguo } 1103c8e0316SYu Zhiguo 1119208faf2SYu Zhiguo static int 1129208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1139208faf2SYu Zhiguo { 1149208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1159208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1169208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1179208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1189208faf2SYu Zhiguo } 1199208faf2SYu Zhiguo 1209208faf2SYu Zhiguo /* 1219208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1229208faf2SYu Zhiguo * in the returned attr bitmap. 1239208faf2SYu Zhiguo */ 1249208faf2SYu Zhiguo static void 1259208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1269208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1279208faf2SYu Zhiguo { 1289208faf2SYu Zhiguo __be32 status; 1299208faf2SYu Zhiguo 1309208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1319208faf2SYu Zhiguo if (status) 1329208faf2SYu Zhiguo /* 1339208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1349208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1359208faf2SYu Zhiguo * So this seems the least of evils: 1369208faf2SYu Zhiguo */ 1379208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1389208faf2SYu Zhiguo } 1399208faf2SYu Zhiguo 1401da177e4SLinus Torvalds static inline void 1411da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1421da177e4SLinus Torvalds { 1431da177e4SLinus Torvalds fh_put(dst); 1441da177e4SLinus Torvalds dget(src->fh_dentry); 1451da177e4SLinus Torvalds if (src->fh_export) 1461da177e4SLinus Torvalds cache_get(&src->fh_export->h); 1471da177e4SLinus Torvalds *dst = *src; 1481da177e4SLinus Torvalds } 1491da177e4SLinus Torvalds 150b37ad28bSAl Viro static __be32 151dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1521da177e4SLinus Torvalds { 153b37ad28bSAl Viro __be32 status; 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds if (open->op_truncate && 1561da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1571da177e4SLinus Torvalds return nfserr_inval; 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 1608837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 1619801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 1628837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 16357ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 1648837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds return status; 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds 171b37ad28bSAl Viro static __be32 1721da177e4SLinus Torvalds do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) 1731da177e4SLinus Torvalds { 1741da177e4SLinus Torvalds struct svc_fh resfh; 175b37ad28bSAl Viro __be32 status; 17681ac95c5SJ. Bruce Fields int created = 0; 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 1791da177e4SLinus Torvalds open->op_truncate = 0; 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds if (open->op_create) { 18279fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 18379fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 18479fb54abSBenny Halevy * 18579fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 18679fb54abSBenny Halevy * Reply Cache | server | | 18779fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 18879fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 18979fb54abSBenny Halevy * | | | (SHOULD) 19079fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 19179fb54abSBenny Halevy * | | | (SHOULD NOT) 19279fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 19379fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 19479fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 19579fb54abSBenny Halevy */ 19679fb54abSBenny Halevy 1971da177e4SLinus Torvalds /* 1981da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 199ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2001da177e4SLinus Torvalds */ 201ac6721a1SMi Jinlong status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, 2021da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 2031da177e4SLinus Torvalds &resfh, open->op_createmode, 204749997e5SJeff Layton (u32 *)open->op_verf.data, 205749997e5SJeff Layton &open->op_truncate, &created); 206749997e5SJeff Layton 20799f88726SJ. Bruce Fields /* 20899f88726SJ. Bruce Fields * Following rfc 3530 14.2.16, use the returned bitmask 20999f88726SJ. Bruce Fields * to indicate which attributes we used to store the 21099f88726SJ. Bruce Fields * verifier: 211749997e5SJeff Layton */ 212749997e5SJeff Layton if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0) 21399f88726SJ. Bruce Fields open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS | 214749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 215af85852dSJ. Bruce Fields } else { 2161da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 2171da177e4SLinus Torvalds open->op_fname.data, open->op_fname.len, &resfh); 2181da177e4SLinus Torvalds fh_unlock(current_fh); 2191da177e4SLinus Torvalds } 220af85852dSJ. Bruce Fields if (status) 221af85852dSJ. Bruce Fields goto out; 2221da177e4SLinus Torvalds 2239208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 2249208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, open->op_acl, open->op_bmval); 2259208faf2SYu Zhiguo 2261da177e4SLinus Torvalds set_change_info(&open->op_cinfo, current_fh); 22713024b7bSJ. Bruce Fields fh_dup2(current_fh, &resfh); 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds /* set reply cache */ 230a4773c08SJ. Bruce Fields fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh, 231a4773c08SJ. Bruce Fields &resfh.fh_handle); 23281ac95c5SJ. Bruce Fields if (!created) 2338837abcaSMiklos Szeredi status = do_open_permission(rqstp, current_fh, open, 2348837abcaSMiklos Szeredi NFSD_MAY_NOP); 2351da177e4SLinus Torvalds 236af85852dSJ. Bruce Fields out: 2371da177e4SLinus Torvalds fh_put(&resfh); 2381da177e4SLinus Torvalds return status; 2391da177e4SLinus Torvalds } 2401da177e4SLinus Torvalds 241b37ad28bSAl Viro static __be32 2421da177e4SLinus Torvalds do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) 2431da177e4SLinus Torvalds { 244b37ad28bSAl Viro __be32 status; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds /* Only reclaims from previously confirmed clients are valid */ 2471da177e4SLinus Torvalds if ((status = nfs4_check_open_reclaim(&open->op_clientid))) 2481da177e4SLinus Torvalds return status; 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 2511da177e4SLinus Torvalds * set the change info 2521da177e4SLinus Torvalds */ 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds /* set replay cache */ 257a4773c08SJ. Bruce Fields fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh, 258a4773c08SJ. Bruce Fields ¤t_fh->fh_handle); 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 2611da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 2621da177e4SLinus Torvalds 2638837abcaSMiklos Szeredi status = do_open_permission(rqstp, current_fh, open, 2648837abcaSMiklos Szeredi NFSD_MAY_OWNER_OVERRIDE); 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds return status; 2671da177e4SLinus Torvalds } 2681da177e4SLinus Torvalds 26960adfc50SAndy Adamson static void 27060adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 27160adfc50SAndy Adamson { 27260adfc50SAndy Adamson struct nfsd4_sessionid *sid = 27360adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 27460adfc50SAndy Adamson 27560adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 27660adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 27760adfc50SAndy Adamson } 2781da177e4SLinus Torvalds 2797191155bSJ.Bruce Fields static __be32 280ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 281a4f1706aSJ.Bruce Fields struct nfsd4_open *open) 2821da177e4SLinus Torvalds { 283b37ad28bSAl Viro __be32 status; 2846668958fSAndy Adamson struct nfsd4_compoundres *resp; 2856668958fSAndy Adamson 2861da177e4SLinus Torvalds dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n", 2871da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 2881da177e4SLinus Torvalds open->op_stateowner); 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds /* This check required by spec. */ 2911da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 2921da177e4SLinus Torvalds return nfserr_inval; 2931da177e4SLinus Torvalds 294ab1350b2SMi Jinlong /* 295ab1350b2SMi Jinlong * RFC5661 18.51.3 296ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 297ab1350b2SMi Jinlong */ 298ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 299ab1350b2SMi Jinlong !cstate->session->se_client->cl_firststate && 300ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 301ab1350b2SMi Jinlong return nfserr_grace; 302ab1350b2SMi Jinlong 30360adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 30460adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 30560adfc50SAndy Adamson 3061da177e4SLinus Torvalds nfs4_lock_state(); 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3096668958fSAndy Adamson resp = rqstp->rq_resp; 3106668958fSAndy Adamson status = nfsd4_process_open1(&resp->cstate, open); 311a90b061cSAl Viro if (status == nfserr_replay_me) { 3121da177e4SLinus Torvalds struct nfs4_replay *rp = &open->op_stateowner->so_replay; 313ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 314a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 315a4773c08SJ. Bruce Fields &rp->rp_openfh); 3168837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3171da177e4SLinus Torvalds if (status) 3181da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 3191da177e4SLinus Torvalds " restoring previous filehandle\n"); 3201da177e4SLinus Torvalds else 321a90b061cSAl Viro status = nfserr_replay_me; 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds if (status) 3241da177e4SLinus Torvalds goto out; 325fb553c0fSJ. Bruce Fields 3263c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 3273c8e0316SYu Zhiguo if (status) 3283c8e0316SYu Zhiguo goto out; 3293c8e0316SYu Zhiguo 330fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 331fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 332cbd0d51aSJ. Bruce Fields status = nfserr_grace; 333af558e33SJ. Bruce Fields if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 334cbd0d51aSJ. Bruce Fields goto out; 335cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 336af558e33SJ. Bruce Fields if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 337cbd0d51aSJ. Bruce Fields goto out; 338fb553c0fSJ. Bruce Fields 3391da177e4SLinus Torvalds switch (open->op_claim_type) { 3400dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 3411da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 3421da177e4SLinus Torvalds /* 3431da177e4SLinus Torvalds * (1) set CURRENT_FH to the file being opened, 3441da177e4SLinus Torvalds * creating it if necessary, (2) set open->op_cinfo, 3451da177e4SLinus Torvalds * (3) set open->op_truncate if the file is to be 3461da177e4SLinus Torvalds * truncated after opening, (4) do permission checking. 3471da177e4SLinus Torvalds */ 348ca364317SJ.Bruce Fields status = do_open_lookup(rqstp, &cstate->current_fh, 349ca364317SJ.Bruce Fields open); 3501da177e4SLinus Torvalds if (status) 3511da177e4SLinus Torvalds goto out; 3521da177e4SLinus Torvalds break; 3531da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 354a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 3551da177e4SLinus Torvalds /* 3561da177e4SLinus Torvalds * The CURRENT_FH is already set to the file being 3571da177e4SLinus Torvalds * opened. (1) set open->op_cinfo, (2) set 3581da177e4SLinus Torvalds * open->op_truncate if the file is to be truncated 3591da177e4SLinus Torvalds * after opening, (3) do permission checking. 3601da177e4SLinus Torvalds */ 361ca364317SJ.Bruce Fields status = do_open_fhandle(rqstp, &cstate->current_fh, 362ca364317SJ.Bruce Fields open); 3631da177e4SLinus Torvalds if (status) 3641da177e4SLinus Torvalds goto out; 3651da177e4SLinus Torvalds break; 3661da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 367a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 3682fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 3691da177e4SLinus Torvalds open->op_claim_type); 3701da177e4SLinus Torvalds status = nfserr_notsupp; 3711da177e4SLinus Torvalds goto out; 3721da177e4SLinus Torvalds default: 3732fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 3741da177e4SLinus Torvalds open->op_claim_type); 3751da177e4SLinus Torvalds status = nfserr_inval; 3761da177e4SLinus Torvalds goto out; 3771da177e4SLinus Torvalds } 3781da177e4SLinus Torvalds /* 3791da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 3801da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 3811da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 3821da177e4SLinus Torvalds */ 383ca364317SJ.Bruce Fields status = nfsd4_process_open2(rqstp, &cstate->current_fh, open); 3841da177e4SLinus Torvalds out: 385f2327d9aSNeil Brown if (open->op_stateowner) { 3861da177e4SLinus Torvalds nfs4_get_stateowner(open->op_stateowner); 387a4f1706aSJ.Bruce Fields cstate->replay_owner = open->op_stateowner; 388f2327d9aSNeil Brown } 3891da177e4SLinus Torvalds nfs4_unlock_state(); 3901da177e4SLinus Torvalds return status; 3911da177e4SLinus Torvalds } 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds /* 3941da177e4SLinus Torvalds * filehandle-manipulating ops. 3951da177e4SLinus Torvalds */ 3967191155bSJ.Bruce Fields static __be32 397b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 398b591480bSJ.Bruce Fields struct svc_fh **getfh) 3991da177e4SLinus Torvalds { 400ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 4011da177e4SLinus Torvalds return nfserr_nofilehandle; 4021da177e4SLinus Torvalds 403ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 4041da177e4SLinus Torvalds return nfs_ok; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds 4077191155bSJ.Bruce Fields static __be32 408ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 409ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 4101da177e4SLinus Torvalds { 411ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 412ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 413ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 414ca364317SJ.Bruce Fields putfh->pf_fhlen); 41568d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds 4187191155bSJ.Bruce Fields static __be32 419b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 420b591480bSJ.Bruce Fields void *arg) 4211da177e4SLinus Torvalds { 422b37ad28bSAl Viro __be32 status; 4231da177e4SLinus Torvalds 424ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 425df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 4261da177e4SLinus Torvalds return status; 4271da177e4SLinus Torvalds } 4281da177e4SLinus Torvalds 4297191155bSJ.Bruce Fields static __be32 430b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 431b591480bSJ.Bruce Fields void *arg) 4321da177e4SLinus Torvalds { 433ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 4341da177e4SLinus Torvalds return nfserr_restorefh; 4351da177e4SLinus Torvalds 436ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 4371da177e4SLinus Torvalds return nfs_ok; 4381da177e4SLinus Torvalds } 4391da177e4SLinus Torvalds 4407191155bSJ.Bruce Fields static __be32 441b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 442b591480bSJ.Bruce Fields void *arg) 4431da177e4SLinus Torvalds { 444ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 4451da177e4SLinus Torvalds return nfserr_nofilehandle; 4461da177e4SLinus Torvalds 447ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 4481da177e4SLinus Torvalds return nfs_ok; 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds /* 4521da177e4SLinus Torvalds * misc nfsv4 ops 4531da177e4SLinus Torvalds */ 4547191155bSJ.Bruce Fields static __be32 455ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 456ca364317SJ.Bruce Fields struct nfsd4_access *access) 4571da177e4SLinus Torvalds { 4581da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 4591da177e4SLinus Torvalds return nfserr_inval; 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 462ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 463ca364317SJ.Bruce Fields &access->ac_supported); 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 4667191155bSJ.Bruce Fields static __be32 467ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 468ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 4691da177e4SLinus Torvalds { 470b37ad28bSAl Viro __be32 status; 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds u32 *p = (u32 *)commit->co_verf.data; 4731da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 4741da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 4751da177e4SLinus Torvalds 476ca364317SJ.Bruce Fields status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 477ca364317SJ.Bruce Fields commit->co_count); 4781da177e4SLinus Torvalds if (status == nfserr_symlink) 4791da177e4SLinus Torvalds status = nfserr_inval; 4801da177e4SLinus Torvalds return status; 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds 483b37ad28bSAl Viro static __be32 484ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 485ca364317SJ.Bruce Fields struct nfsd4_create *create) 4861da177e4SLinus Torvalds { 4871da177e4SLinus Torvalds struct svc_fh resfh; 488b37ad28bSAl Viro __be32 status; 4891da177e4SLinus Torvalds dev_t rdev; 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 4921da177e4SLinus Torvalds 4938837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, 4948837abcaSMiklos Szeredi NFSD_MAY_CREATE); 4951da177e4SLinus Torvalds if (status == nfserr_symlink) 4961da177e4SLinus Torvalds status = nfserr_notdir; 4971da177e4SLinus Torvalds if (status) 4981da177e4SLinus Torvalds return status; 4991da177e4SLinus Torvalds 5003c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 5013c8e0316SYu Zhiguo nfsd_attrmask); 5023c8e0316SYu Zhiguo if (status) 5033c8e0316SYu Zhiguo return status; 5043c8e0316SYu Zhiguo 5051da177e4SLinus Torvalds switch (create->cr_type) { 5061da177e4SLinus Torvalds case NF4LNK: 5071da177e4SLinus Torvalds /* ugh! we have to null-terminate the linktext, or 5081da177e4SLinus Torvalds * vfs_symlink() will choke. it is always safe to 5091da177e4SLinus Torvalds * null-terminate by brute force, since at worst we 5101da177e4SLinus Torvalds * will overwrite the first byte of the create namelen 5111da177e4SLinus Torvalds * in the XDR buffer, which has already been extracted 5121da177e4SLinus Torvalds * during XDR decode. 5131da177e4SLinus Torvalds */ 5141da177e4SLinus Torvalds create->cr_linkname[create->cr_linklen] = 0; 5151da177e4SLinus Torvalds 516ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 517ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 518ca364317SJ.Bruce Fields create->cr_linkname, create->cr_linklen, 519ca364317SJ.Bruce Fields &resfh, &create->cr_iattr); 5201da177e4SLinus Torvalds break; 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds case NF4BLK: 5231da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 5241da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 5251da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 5261da177e4SLinus Torvalds return nfserr_inval; 527ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 528ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 529ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 5301da177e4SLinus Torvalds break; 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds case NF4CHR: 5331da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 5341da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 5351da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 5361da177e4SLinus Torvalds return nfserr_inval; 537ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 538ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 539ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 5401da177e4SLinus Torvalds break; 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds case NF4SOCK: 543ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 544ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 545ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 5461da177e4SLinus Torvalds break; 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds case NF4FIFO: 549ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 550ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 551ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 5521da177e4SLinus Torvalds break; 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds case NF4DIR: 5551da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 556ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 557ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 558ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 5591da177e4SLinus Torvalds break; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds default: 5621da177e4SLinus Torvalds status = nfserr_badtype; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5659208faf2SYu Zhiguo if (status) 5669208faf2SYu Zhiguo goto out; 5679208faf2SYu Zhiguo 5689208faf2SYu Zhiguo if (create->cr_acl != NULL) 5699208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 5709208faf2SYu Zhiguo create->cr_bmval); 5719208faf2SYu Zhiguo 572ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 573ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 574ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 5759208faf2SYu Zhiguo out: 5761da177e4SLinus Torvalds fh_put(&resfh); 5771da177e4SLinus Torvalds return status; 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds 5807191155bSJ.Bruce Fields static __be32 581ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 582ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 5831da177e4SLinus Torvalds { 584b37ad28bSAl Viro __be32 status; 5851da177e4SLinus Torvalds 5868837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 5871da177e4SLinus Torvalds if (status) 5881da177e4SLinus Torvalds return status; 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 5911da177e4SLinus Torvalds return nfserr_inval; 5921da177e4SLinus Torvalds 5937e705706SAndy Adamson getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 5947e705706SAndy Adamson getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 5957e705706SAndy Adamson getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 5961da177e4SLinus Torvalds 597ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 5981da177e4SLinus Torvalds return nfs_ok; 5991da177e4SLinus Torvalds } 6001da177e4SLinus Torvalds 6017191155bSJ.Bruce Fields static __be32 602ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 603ca364317SJ.Bruce Fields struct nfsd4_link *link) 6041da177e4SLinus Torvalds { 605b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 6061da177e4SLinus Torvalds 607ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 6081da177e4SLinus Torvalds return status; 609ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 610ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 6111da177e4SLinus Torvalds if (!status) 612ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 6131da177e4SLinus Torvalds return status; 6141da177e4SLinus Torvalds } 6151da177e4SLinus Torvalds 6160ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 6171da177e4SLinus Torvalds { 6181da177e4SLinus Torvalds struct svc_fh tmp_fh; 619b37ad28bSAl Viro __be32 ret; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 622df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 623df547efbSJ. Bruce Fields if (ret) 6241da177e4SLinus Torvalds return ret; 6250ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 6261da177e4SLinus Torvalds fh_put(&tmp_fh); 6271da177e4SLinus Torvalds return nfserr_noent; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds fh_put(&tmp_fh); 6300ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 6310ff7ab46SJ. Bruce Fields } 6320ff7ab46SJ. Bruce Fields 6330ff7ab46SJ. Bruce Fields static __be32 6340ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 6350ff7ab46SJ. Bruce Fields void *arg) 6360ff7ab46SJ. Bruce Fields { 6370ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds 6407191155bSJ.Bruce Fields static __be32 641ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 642ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 6431da177e4SLinus Torvalds { 644ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 645ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 646ca364317SJ.Bruce Fields &cstate->current_fh); 6471da177e4SLinus Torvalds } 6481da177e4SLinus Torvalds 6497191155bSJ.Bruce Fields static __be32 650ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 651ca364317SJ.Bruce Fields struct nfsd4_read *read) 6521da177e4SLinus Torvalds { 653b37ad28bSAl Viro __be32 status; 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_read() */ 6561da177e4SLinus Torvalds 6577e06b7f9SNeilBrown read->rd_filp = NULL; 6581da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 6591da177e4SLinus Torvalds return nfserr_inval; 6601da177e4SLinus Torvalds 6611da177e4SLinus Torvalds nfs4_lock_state(); 6621da177e4SLinus Torvalds /* check stateid */ 663dd453dfdSBenny Halevy if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid, 6646150ef0dSJ. Bruce Fields RD_STATE, &read->rd_filp))) { 6651da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 6661da177e4SLinus Torvalds goto out; 6671da177e4SLinus Torvalds } 6687e06b7f9SNeilBrown if (read->rd_filp) 6697e06b7f9SNeilBrown get_file(read->rd_filp); 6701da177e4SLinus Torvalds status = nfs_ok; 6711da177e4SLinus Torvalds out: 6721da177e4SLinus Torvalds nfs4_unlock_state(); 6731da177e4SLinus Torvalds read->rd_rqstp = rqstp; 674ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 6751da177e4SLinus Torvalds return status; 6761da177e4SLinus Torvalds } 6771da177e4SLinus Torvalds 6787191155bSJ.Bruce Fields static __be32 679ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 680ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 6811da177e4SLinus Torvalds { 6821da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 6831da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 6861da177e4SLinus Torvalds 6871da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6881da177e4SLinus Torvalds return nfserr_inval; 6891da177e4SLinus Torvalds 6907e705706SAndy Adamson readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 6917e705706SAndy Adamson readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 6927e705706SAndy Adamson readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 6931da177e4SLinus Torvalds 694*832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 6951da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 6961da177e4SLinus Torvalds return nfserr_bad_cookie; 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 699ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 7001da177e4SLinus Torvalds return nfs_ok; 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds 7037191155bSJ.Bruce Fields static __be32 704ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 705ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 7061da177e4SLinus Torvalds { 7071da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 708ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 7091da177e4SLinus Torvalds return nfs_ok; 7101da177e4SLinus Torvalds } 7111da177e4SLinus Torvalds 7127191155bSJ.Bruce Fields static __be32 713ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 714ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 7151da177e4SLinus Torvalds { 716b37ad28bSAl Viro __be32 status; 7171da177e4SLinus Torvalds 718af558e33SJ. Bruce Fields if (locks_in_grace()) 719c815afc7SNeilBrown return nfserr_grace; 720ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 721ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 7221da177e4SLinus Torvalds if (status == nfserr_symlink) 7231da177e4SLinus Torvalds return nfserr_notdir; 7241da177e4SLinus Torvalds if (!status) { 725ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 726ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 7271da177e4SLinus Torvalds } 7281da177e4SLinus Torvalds return status; 7291da177e4SLinus Torvalds } 7301da177e4SLinus Torvalds 7317191155bSJ.Bruce Fields static __be32 732ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 733ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 7341da177e4SLinus Torvalds { 735b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 7361da177e4SLinus Torvalds 737ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 7381da177e4SLinus Torvalds return status; 739af558e33SJ. Bruce Fields if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags 740c815afc7SNeilBrown & NFSEXP_NOSUBTREECHECK)) 741c815afc7SNeilBrown return nfserr_grace; 742ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 743ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 7441da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds /* the underlying filesystem returns different error's than required 7471da177e4SLinus Torvalds * by NFSv4. both save_fh and current_fh have been verified.. */ 7481da177e4SLinus Torvalds if (status == nfserr_isdir) 7491da177e4SLinus Torvalds status = nfserr_exist; 7501da177e4SLinus Torvalds else if ((status == nfserr_notdir) && 751ca364317SJ.Bruce Fields (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) && 752ca364317SJ.Bruce Fields S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode))) 7531da177e4SLinus Torvalds status = nfserr_exist; 7541da177e4SLinus Torvalds else if (status == nfserr_symlink) 7551da177e4SLinus Torvalds status = nfserr_notdir; 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds if (!status) { 758ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 759ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 7601da177e4SLinus Torvalds } 7611da177e4SLinus Torvalds return status; 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 7647191155bSJ.Bruce Fields static __be32 765dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 766dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 767dcb488a3SAndy Adamson { 768dcb488a3SAndy Adamson struct svc_fh resfh; 769dcb488a3SAndy Adamson struct svc_export *exp; 770dcb488a3SAndy Adamson struct dentry *dentry; 771dcb488a3SAndy Adamson __be32 err; 772dcb488a3SAndy Adamson 773dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 77429a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 77529a78a3eSJ. Bruce Fields if (err) 77629a78a3eSJ. Bruce Fields return err; 777dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 778dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 779dcb488a3SAndy Adamson &exp, &dentry); 780dcb488a3SAndy Adamson if (err) 781dcb488a3SAndy Adamson return err; 782dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 783dcb488a3SAndy Adamson exp_put(exp); 784dcb488a3SAndy Adamson err = nfserr_noent; 785dcb488a3SAndy Adamson } else 786dcb488a3SAndy Adamson secinfo->si_exp = exp; 787dcb488a3SAndy Adamson dput(dentry); 78856560b9aSJ. Bruce Fields if (cstate->minorversion) 78956560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 79056560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 791dcb488a3SAndy Adamson return err; 792dcb488a3SAndy Adamson } 793dcb488a3SAndy Adamson 794dcb488a3SAndy Adamson static __be32 79504f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 79604f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 79704f4ad16SJ. Bruce Fields { 79804f4ad16SJ. Bruce Fields __be32 err; 79904f4ad16SJ. Bruce Fields 80004f4ad16SJ. Bruce Fields switch (sin->sin_style) { 80104f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 80204f4ad16SJ. Bruce Fields break; 80304f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 80404f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 80504f4ad16SJ. Bruce Fields if (err) 80604f4ad16SJ. Bruce Fields return err; 80704f4ad16SJ. Bruce Fields break; 80804f4ad16SJ. Bruce Fields default: 80904f4ad16SJ. Bruce Fields return nfserr_inval; 81004f4ad16SJ. Bruce Fields } 81104f4ad16SJ. Bruce Fields exp_get(cstate->current_fh.fh_export); 81204f4ad16SJ. Bruce Fields sin->sin_exp = cstate->current_fh.fh_export; 81304f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 81404f4ad16SJ. Bruce Fields return nfs_ok; 81504f4ad16SJ. Bruce Fields } 81604f4ad16SJ. Bruce Fields 81704f4ad16SJ. Bruce Fields static __be32 818ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 819ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 8201da177e4SLinus Torvalds { 821b37ad28bSAl Viro __be32 status = nfs_ok; 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 8241da177e4SLinus Torvalds nfs4_lock_state(); 825dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, 8266150ef0dSJ. Bruce Fields &setattr->sa_stateid, WR_STATE, NULL); 8271da177e4SLinus Torvalds nfs4_unlock_state(); 828375c5547SJ. Bruce Fields if (status) { 8293e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 830375c5547SJ. Bruce Fields return status; 831375c5547SJ. Bruce Fields } 8321da177e4SLinus Torvalds } 83318f335afSDave Hansen status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt); 83418f335afSDave Hansen if (status) 83518f335afSDave Hansen return status; 8361da177e4SLinus Torvalds status = nfs_ok; 8373c8e0316SYu Zhiguo 8383c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 8393c8e0316SYu Zhiguo nfsd_attrmask); 8403c8e0316SYu Zhiguo if (status) 8413c8e0316SYu Zhiguo goto out; 8423c8e0316SYu Zhiguo 8431da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 844ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 845ca364317SJ.Bruce Fields setattr->sa_acl); 8461da177e4SLinus Torvalds if (status) 84718f335afSDave Hansen goto out; 848ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 8491da177e4SLinus Torvalds 0, (time_t)0); 85018f335afSDave Hansen out: 85118f335afSDave Hansen mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt); 8521da177e4SLinus Torvalds return status; 8531da177e4SLinus Torvalds } 8541da177e4SLinus Torvalds 8557191155bSJ.Bruce Fields static __be32 856ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 857ca364317SJ.Bruce Fields struct nfsd4_write *write) 8581da177e4SLinus Torvalds { 8591da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 8601da177e4SLinus Torvalds struct file *filp = NULL; 8611da177e4SLinus Torvalds u32 *p; 862b37ad28bSAl Viro __be32 status = nfs_ok; 86331dec253SDavid Shaw unsigned long cnt; 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 8661da177e4SLinus Torvalds 8671da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 8681da177e4SLinus Torvalds return nfserr_inval; 8691da177e4SLinus Torvalds 8701da177e4SLinus Torvalds nfs4_lock_state(); 871dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp); 8727e06b7f9SNeilBrown if (filp) 8737e06b7f9SNeilBrown get_file(filp); 8741da177e4SLinus Torvalds nfs4_unlock_state(); 8751da177e4SLinus Torvalds 876375c5547SJ. Bruce Fields if (status) { 877375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 878375c5547SJ. Bruce Fields return status; 879375c5547SJ. Bruce Fields } 880375c5547SJ. Bruce Fields 88131dec253SDavid Shaw cnt = write->wr_buflen; 8821da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 8831da177e4SLinus Torvalds p = (u32 *)write->wr_verifier.data; 8841da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 8851da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 8861da177e4SLinus Torvalds 887ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 888ca364317SJ.Bruce Fields write->wr_offset, rqstp->rq_vec, write->wr_vlen, 88931dec253SDavid Shaw &cnt, &write->wr_how_written); 8907e06b7f9SNeilBrown if (filp) 8917e06b7f9SNeilBrown fput(filp); 8921da177e4SLinus Torvalds 89331dec253SDavid Shaw write->wr_bytes_written = cnt; 89431dec253SDavid Shaw 8951da177e4SLinus Torvalds if (status == nfserr_symlink) 8961da177e4SLinus Torvalds status = nfserr_inval; 8971da177e4SLinus Torvalds return status; 8981da177e4SLinus Torvalds } 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 9011da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 9021da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 9031da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 9041da177e4SLinus Torvalds */ 905b37ad28bSAl Viro static __be32 906c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 907ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 9081da177e4SLinus Torvalds { 9092ebbc012SAl Viro __be32 *buf, *p; 9101da177e4SLinus Torvalds int count; 911b37ad28bSAl Viro __be32 status; 9121da177e4SLinus Torvalds 9138837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 9141da177e4SLinus Torvalds if (status) 9151da177e4SLinus Torvalds return status; 9161da177e4SLinus Torvalds 9173c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 9183c8e0316SYu Zhiguo if (status) 9193c8e0316SYu Zhiguo return status; 9203c8e0316SYu Zhiguo 9211da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 9221da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 9231da177e4SLinus Torvalds return nfserr_inval; 9241da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 9251da177e4SLinus Torvalds return nfserr_inval; 9261da177e4SLinus Torvalds 9271da177e4SLinus Torvalds /* count in words: 9281da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 9291da177e4SLinus Torvalds */ 9301da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 9311da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 9321da177e4SLinus Torvalds if (!buf) 9331da177e4SLinus Torvalds return nfserr_resource; 9341da177e4SLinus Torvalds 935ca364317SJ.Bruce Fields status = nfsd4_encode_fattr(&cstate->current_fh, 936ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 937ca364317SJ.Bruce Fields cstate->current_fh.fh_dentry, buf, 9381da177e4SLinus Torvalds &count, verify->ve_bmval, 939406a7ea9SFrank Filz rqstp, 0); 9401da177e4SLinus Torvalds 9411da177e4SLinus Torvalds /* this means that nfsd4_encode_fattr() ran out of space */ 9421da177e4SLinus Torvalds if (status == nfserr_resource && count == 0) 9431da177e4SLinus Torvalds status = nfserr_not_same; 9441da177e4SLinus Torvalds if (status) 9451da177e4SLinus Torvalds goto out_kfree; 9461da177e4SLinus Torvalds 94795ec28cdSBenny Halevy /* skip bitmap */ 94895ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 9491da177e4SLinus Torvalds status = nfserr_not_same; 9501da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 9511da177e4SLinus Torvalds goto out_kfree; 9521da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 9531da177e4SLinus Torvalds status = nfserr_same; 9541da177e4SLinus Torvalds 9551da177e4SLinus Torvalds out_kfree: 9561da177e4SLinus Torvalds kfree(buf); 9571da177e4SLinus Torvalds return status; 9581da177e4SLinus Torvalds } 9591da177e4SLinus Torvalds 960c954e2a5SJ.Bruce Fields static __be32 961c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 962c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 963c954e2a5SJ.Bruce Fields { 964c954e2a5SJ.Bruce Fields __be32 status; 965c954e2a5SJ.Bruce Fields 966c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 967c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 968c954e2a5SJ.Bruce Fields } 969c954e2a5SJ.Bruce Fields 970c954e2a5SJ.Bruce Fields static __be32 971c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 972c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 973c954e2a5SJ.Bruce Fields { 974c954e2a5SJ.Bruce Fields __be32 status; 975c954e2a5SJ.Bruce Fields 976c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 977c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 978c954e2a5SJ.Bruce Fields } 979c954e2a5SJ.Bruce Fields 9801da177e4SLinus Torvalds /* 9811da177e4SLinus Torvalds * NULL call. 9821da177e4SLinus Torvalds */ 9837111c66eSAl Viro static __be32 9841da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 9851da177e4SLinus Torvalds { 9861da177e4SLinus Torvalds return nfs_ok; 9871da177e4SLinus Torvalds } 9881da177e4SLinus Torvalds 989e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 990e2b20950SShankar Anand { 991e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 992e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 993e2b20950SShankar Anand } 994e2b20950SShankar Anand 995b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 996b591480bSJ.Bruce Fields void *); 997f9bb94c4SAndy Adamson enum nfsd4_op_flags { 998f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 9995ece3cafSMi Jinlong ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 10005ece3cafSMi Jinlong ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 100168d93184SJ. Bruce Fields /* For rfc 5661 section 2.6.3.1.1: */ 100268d93184SJ. Bruce Fields OP_HANDLES_WRONGSEC = 1 << 3, 100368d93184SJ. Bruce Fields OP_IS_PUTFH_LIKE = 1 << 4, 1004f9bb94c4SAndy Adamson }; 1005b591480bSJ.Bruce Fields 1006b591480bSJ.Bruce Fields struct nfsd4_operation { 1007b591480bSJ.Bruce Fields nfsd4op_func op_func; 1008b591480bSJ.Bruce Fields u32 op_flags; 1009b001a1b6SBenny Halevy char *op_name; 10101091006cSJ. Bruce Fields /* 10111091006cSJ. Bruce Fields * We use the DRC for compounds containing non-idempotent 10121091006cSJ. Bruce Fields * operations, *except* those that are 4.1-specific (since 10131091006cSJ. Bruce Fields * sessions provide their own EOS), and except for stateful 10141091006cSJ. Bruce Fields * operations other than setclientid and setclientid_confirm 10151091006cSJ. Bruce Fields * (since sequence numbers provide EOS for open, lock, etc in 10161091006cSJ. Bruce Fields * the v4.0 case). 10171091006cSJ. Bruce Fields */ 10181091006cSJ. Bruce Fields bool op_cacheresult; 1019b591480bSJ.Bruce Fields }; 1020b591480bSJ.Bruce Fields 1021b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 1022b591480bSJ.Bruce Fields 1023f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1024b001a1b6SBenny Halevy 10251da177e4SLinus Torvalds /* 102657716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1027f9bb94c4SAndy Adamson * 102857716355SJ. Bruce Fields * Also note, enforced elsewhere: 102957716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 103057716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 10311d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 10321d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 103357716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 103457716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 103557716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1036f9bb94c4SAndy Adamson */ 103757716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1038f9bb94c4SAndy Adamson { 1039f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 104057716355SJ. Bruce Fields 104157716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 104257716355SJ. Bruce Fields if (args->minorversion == 0) 104357716355SJ. Bruce Fields return nfs_ok; 104457716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 104557716355SJ. Bruce Fields if (args->opcnt == 0) 104657716355SJ. Bruce Fields return nfs_ok; 104757716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 104857716355SJ. Bruce Fields return nfs_ok; 104957716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 105057716355SJ. Bruce Fields return nfserr_op_not_in_session; 105157716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 105257716355SJ. Bruce Fields return nfs_ok; 105357716355SJ. Bruce Fields if (args->opcnt != 1) 105457716355SJ. Bruce Fields return nfserr_not_only_op; 105557716355SJ. Bruce Fields return nfs_ok; 1056f9bb94c4SAndy Adamson } 1057f9bb94c4SAndy Adamson 105822b03214SJ. Bruce Fields static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 105922b03214SJ. Bruce Fields { 106022b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 106122b03214SJ. Bruce Fields } 106222b03214SJ. Bruce Fields 10631091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 10641091006cSJ. Bruce Fields { 10651091006cSJ. Bruce Fields return OPDESC(op)->op_cacheresult; 10661091006cSJ. Bruce Fields } 10671091006cSJ. Bruce Fields 106868d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 106968d93184SJ. Bruce Fields { 107068d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 107168d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 107268d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 107368d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 107468d93184SJ. Bruce Fields struct nfsd4_operation *thisd; 107568d93184SJ. Bruce Fields struct nfsd4_operation *nextd; 107668d93184SJ. Bruce Fields 107768d93184SJ. Bruce Fields thisd = OPDESC(this); 107868d93184SJ. Bruce Fields /* 107968d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 108068d93184SJ. Bruce Fields * have special rules. 108168d93184SJ. Bruce Fields */ 108268d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 108368d93184SJ. Bruce Fields return false; 108468d93184SJ. Bruce Fields /* 108568d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 108668d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 108768d93184SJ. Bruce Fields * result: 108868d93184SJ. Bruce Fields */ 108968d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 109068d93184SJ. Bruce Fields return false; 109168d93184SJ. Bruce Fields 109268d93184SJ. Bruce Fields nextd = OPDESC(next); 109368d93184SJ. Bruce Fields /* 109468d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 109568d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 109668d93184SJ. Bruce Fields * now: 109768d93184SJ. Bruce Fields */ 109868d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 109968d93184SJ. Bruce Fields } 110068d93184SJ. Bruce Fields 1101f9bb94c4SAndy Adamson /* 11021da177e4SLinus Torvalds * COMPOUND call. 11031da177e4SLinus Torvalds */ 11047111c66eSAl Viro static __be32 11051da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 11061da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 11071da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 11081da177e4SLinus Torvalds { 11091da177e4SLinus Torvalds struct nfsd4_op *op; 1110b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1111e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 1112e5710199SJ.Bruce Fields int slack_bytes; 1113b37ad28bSAl Viro __be32 status; 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds resp->xbuf = &rqstp->rq_res; 1116e354d571SAndy Adamson resp->p = rqstp->rq_res.head[0].iov_base + 1117e354d571SAndy Adamson rqstp->rq_res.head[0].iov_len; 11181da177e4SLinus Torvalds resp->tagp = resp->p; 11191da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 11201da177e4SLinus Torvalds resp->p += 2 + XDR_QUADLEN(args->taglen); 11211da177e4SLinus Torvalds resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE; 11221da177e4SLinus Torvalds resp->taglen = args->taglen; 11231da177e4SLinus Torvalds resp->tag = args->tag; 11241da177e4SLinus Torvalds resp->opcnt = 0; 11251da177e4SLinus Torvalds resp->rqstp = rqstp; 1126d87a8adeSAndy Adamson resp->cstate.minorversion = args->minorversion; 1127e354d571SAndy Adamson resp->cstate.replay_owner = NULL; 112826c0c75eSJ. Bruce Fields resp->cstate.session = NULL; 1129e354d571SAndy Adamson fh_init(&resp->cstate.current_fh, NFS4_FHSIZE); 1130e354d571SAndy Adamson fh_init(&resp->cstate.save_fh, NFS4_FHSIZE); 11318ff30fa4SNeilBrown /* 11328ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 11338ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 11348ff30fa4SNeilBrown */ 11358ff30fa4SNeilBrown rqstp->rq_usedeferral = 0; 11361da177e4SLinus Torvalds 11371da177e4SLinus Torvalds /* 11381da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 11391da177e4SLinus Torvalds */ 11401da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 11418daf220aSBenny Halevy if (args->minorversion > nfsd_supported_minorversion) 11421da177e4SLinus Torvalds goto out; 11431da177e4SLinus Torvalds 114457716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 114557716355SJ. Bruce Fields if (status) { 1146f9bb94c4SAndy Adamson op = &args->ops[0]; 114757716355SJ. Bruce Fields op->status = status; 1148f9bb94c4SAndy Adamson goto encode_op; 1149f9bb94c4SAndy Adamson } 1150f9bb94c4SAndy Adamson 11511da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 11521da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 11531da177e4SLinus Torvalds 1154b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1155b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1156b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 11571da177e4SLinus Torvalds /* 11581da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 11591da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 11601da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 11611da177e4SLinus Torvalds */ 11621da177e4SLinus Torvalds if (op->status) 11631da177e4SLinus Torvalds goto encode_op; 11641da177e4SLinus Torvalds 11651da177e4SLinus Torvalds /* We must be able to encode a successful response to 11661da177e4SLinus Torvalds * this operation, with enough room left over to encode a 11671da177e4SLinus Torvalds * failed response to the next operation. If we don't 11681da177e4SLinus Torvalds * have enough room, fail with ERR_RESOURCE. 11691da177e4SLinus Torvalds */ 1170e5710199SJ.Bruce Fields slack_bytes = (char *)resp->end - (char *)resp->p; 1171e5710199SJ.Bruce Fields if (slack_bytes < COMPOUND_SLACK_SPACE 1172e5710199SJ.Bruce Fields + COMPOUND_ERR_SLACK_SPACE) { 1173e5710199SJ.Bruce Fields BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE); 11741da177e4SLinus Torvalds op->status = nfserr_resource; 11751da177e4SLinus Torvalds goto encode_op; 11761da177e4SLinus Torvalds } 11771da177e4SLinus Torvalds 117822b03214SJ. Bruce Fields opdesc = OPDESC(op); 1179b591480bSJ.Bruce Fields 1180ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) { 118127d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 11821da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 11831da177e4SLinus Torvalds goto encode_op; 11841da177e4SLinus Torvalds } 1185eeac294eSJ.Bruce Fields } else if (cstate->current_fh.fh_export->ex_fslocs.migrated && 1186eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 118742ca0993SJ.Bruce Fields op->status = nfserr_moved; 118842ca0993SJ.Bruce Fields goto encode_op; 118942ca0993SJ.Bruce Fields } 1190b591480bSJ.Bruce Fields 1191b591480bSJ.Bruce Fields if (opdesc->op_func) 1192b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 1193b591480bSJ.Bruce Fields else 11941da177e4SLinus Torvalds BUG_ON(op->status == nfs_ok); 11951da177e4SLinus Torvalds 119668d93184SJ. Bruce Fields if (!op->status && need_wrongsec_check(rqstp)) 119768d93184SJ. Bruce Fields op->status = check_nfsd_access(cstate->current_fh.fh_export, rqstp); 119868d93184SJ. Bruce Fields 11991da177e4SLinus Torvalds encode_op: 120049557cc7SAndy Adamson /* Only from SEQUENCE */ 1201da3846a2SAndy Adamson if (resp->cstate.status == nfserr_replay_cache) { 1202da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1203da3846a2SAndy Adamson status = op->status; 1204da3846a2SAndy Adamson goto out; 1205da3846a2SAndy Adamson } 1206a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1207a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 12081da177e4SLinus Torvalds nfsd4_encode_replay(resp, op); 12091da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 12101da177e4SLinus Torvalds } else { 12111da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 12121da177e4SLinus Torvalds status = op->status; 12131da177e4SLinus Torvalds } 12140407717dSBenny Halevy 12150407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 12160407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 12170407717dSBenny Halevy be32_to_cpu(status)); 12180407717dSBenny Halevy 1219a4f1706aSJ.Bruce Fields if (cstate->replay_owner) { 1220a4f1706aSJ.Bruce Fields nfs4_put_stateowner(cstate->replay_owner); 1221a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 12221da177e4SLinus Torvalds } 12237e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 12247e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 12257e06b7f9SNeilBrown fput(op->u.read.rd_filp); 1226e2b20950SShankar Anand 1227e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 12281da177e4SLinus Torvalds } 12291da177e4SLinus Torvalds 1230da3846a2SAndy Adamson resp->cstate.status = status; 1231e354d571SAndy Adamson fh_put(&resp->cstate.current_fh); 1232e354d571SAndy Adamson fh_put(&resp->cstate.save_fh); 1233e354d571SAndy Adamson BUG_ON(resp->cstate.replay_owner); 12341da177e4SLinus Torvalds out: 12352f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 12362f425878SAndy Adamson rqstp->rq_usedeferral = 1; 12373b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 12381da177e4SLinus Torvalds return status; 12391da177e4SLinus Torvalds } 12401da177e4SLinus Torvalds 124120766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1242b591480bSJ.Bruce Fields [OP_ACCESS] = { 1243b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1244b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1245b591480bSJ.Bruce Fields }, 1246b591480bSJ.Bruce Fields [OP_CLOSE] = { 1247b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 1248b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 1249b591480bSJ.Bruce Fields }, 1250b591480bSJ.Bruce Fields [OP_COMMIT] = { 1251b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 1252b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 1253b591480bSJ.Bruce Fields }, 1254b591480bSJ.Bruce Fields [OP_CREATE] = { 1255b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1256b001a1b6SBenny Halevy .op_name = "OP_CREATE", 12571091006cSJ. Bruce Fields .op_cacheresult = true, 1258b591480bSJ.Bruce Fields }, 1259b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1260b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 1261b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 1262b591480bSJ.Bruce Fields }, 1263b591480bSJ.Bruce Fields [OP_GETATTR] = { 1264b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 1265eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 1266b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 1267b591480bSJ.Bruce Fields }, 1268b591480bSJ.Bruce Fields [OP_GETFH] = { 1269b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 1270b001a1b6SBenny Halevy .op_name = "OP_GETFH", 1271b591480bSJ.Bruce Fields }, 1272b591480bSJ.Bruce Fields [OP_LINK] = { 1273b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 1274b001a1b6SBenny Halevy .op_name = "OP_LINK", 12751091006cSJ. Bruce Fields .op_cacheresult = true, 1276b591480bSJ.Bruce Fields }, 1277b591480bSJ.Bruce Fields [OP_LOCK] = { 1278b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 1279b001a1b6SBenny Halevy .op_name = "OP_LOCK", 1280b591480bSJ.Bruce Fields }, 1281b591480bSJ.Bruce Fields [OP_LOCKT] = { 1282b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 1283b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 1284b591480bSJ.Bruce Fields }, 1285b591480bSJ.Bruce Fields [OP_LOCKU] = { 1286b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 1287b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 1288b591480bSJ.Bruce Fields }, 1289b591480bSJ.Bruce Fields [OP_LOOKUP] = { 1290b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 129168d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1292b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 1293b591480bSJ.Bruce Fields }, 1294b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 1295b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 129668d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1297b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 1298b591480bSJ.Bruce Fields }, 1299b591480bSJ.Bruce Fields [OP_NVERIFY] = { 1300b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 1301b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 1302b591480bSJ.Bruce Fields }, 1303b591480bSJ.Bruce Fields [OP_OPEN] = { 1304b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 130568d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1306b001a1b6SBenny Halevy .op_name = "OP_OPEN", 1307b591480bSJ.Bruce Fields }, 1308b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 1309b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 1310b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 1311b591480bSJ.Bruce Fields }, 1312b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 1313b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 1314b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 1315b591480bSJ.Bruce Fields }, 1316b591480bSJ.Bruce Fields [OP_PUTFH] = { 1317b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 131868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 131968d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1320b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 1321b591480bSJ.Bruce Fields }, 1322eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 1323a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 132468d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 132568d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1326b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 1327eeac294eSJ.Bruce Fields }, 1328b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 1329b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 133068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 133168d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1332b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 1333b591480bSJ.Bruce Fields }, 1334b591480bSJ.Bruce Fields [OP_READ] = { 1335b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 1336b001a1b6SBenny Halevy .op_name = "OP_READ", 1337b591480bSJ.Bruce Fields }, 1338b591480bSJ.Bruce Fields [OP_READDIR] = { 1339b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 1340b001a1b6SBenny Halevy .op_name = "OP_READDIR", 1341b591480bSJ.Bruce Fields }, 1342b591480bSJ.Bruce Fields [OP_READLINK] = { 1343b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 1344b001a1b6SBenny Halevy .op_name = "OP_READLINK", 1345b591480bSJ.Bruce Fields }, 1346b591480bSJ.Bruce Fields [OP_REMOVE] = { 1347b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 1348b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 13491091006cSJ. Bruce Fields .op_cacheresult = true, 1350b591480bSJ.Bruce Fields }, 1351b591480bSJ.Bruce Fields [OP_RENAME] = { 1352b001a1b6SBenny Halevy .op_name = "OP_RENAME", 1353b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 13541091006cSJ. Bruce Fields .op_cacheresult = true, 1355b591480bSJ.Bruce Fields }, 1356b591480bSJ.Bruce Fields [OP_RENEW] = { 1357b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 135827d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1359b001a1b6SBenny Halevy .op_name = "OP_RENEW", 1360b591480bSJ.Bruce Fields }, 1361b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 1362b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 136368d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 136468d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1365b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 1366b591480bSJ.Bruce Fields }, 1367b591480bSJ.Bruce Fields [OP_SAVEFH] = { 1368b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 136968d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1370b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 1371b591480bSJ.Bruce Fields }, 1372dcb488a3SAndy Adamson [OP_SECINFO] = { 1373dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 137468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1375b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 1376dcb488a3SAndy Adamson }, 1377b591480bSJ.Bruce Fields [OP_SETATTR] = { 1378b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 1379b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 13801091006cSJ. Bruce Fields .op_cacheresult = true, 1381b591480bSJ.Bruce Fields }, 1382b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 1383b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 138427d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1385b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 13861091006cSJ. Bruce Fields .op_cacheresult = true, 1387b591480bSJ.Bruce Fields }, 1388b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 1389b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 139027d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1391b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 13921091006cSJ. Bruce Fields .op_cacheresult = true, 1393b591480bSJ.Bruce Fields }, 1394b591480bSJ.Bruce Fields [OP_VERIFY] = { 1395b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 1396b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 1397b591480bSJ.Bruce Fields }, 1398b591480bSJ.Bruce Fields [OP_WRITE] = { 1399b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 1400b001a1b6SBenny Halevy .op_name = "OP_WRITE", 14011091006cSJ. Bruce Fields .op_cacheresult = true, 1402b591480bSJ.Bruce Fields }, 1403b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 1404b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 140527d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1406b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 1407b591480bSJ.Bruce Fields }, 1408069b6ad4SAndy Adamson 1409069b6ad4SAndy Adamson /* NFSv4.1 operations */ 1410069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 1411069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 1412f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1413069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 1414069b6ad4SAndy Adamson }, 14151d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 14161d1bc8f2SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, 14171d1bc8f2SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 14181d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 14191d1bc8f2SJ. Bruce Fields }, 1420069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 1421069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 1422f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1423069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 1424069b6ad4SAndy Adamson }, 1425069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 1426069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 1427f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1428069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 1429069b6ad4SAndy Adamson }, 1430069b6ad4SAndy Adamson [OP_SEQUENCE] = { 1431069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 1432f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1433069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 1434069b6ad4SAndy Adamson }, 1435094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 1436094b5d74SBenny Halevy .op_func = NULL, 1437094b5d74SBenny Halevy .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1438094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 1439094b5d74SBenny Halevy }, 14404dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 14414dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 14424dc6ec00SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH, 14434dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 14444dc6ec00SJ. Bruce Fields }, 144504f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 144604f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 144768d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 144804f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 144904f4ad16SJ. Bruce Fields }, 145017456804SBryan Schumaker [OP_TEST_STATEID] = { 145117456804SBryan Schumaker .op_func = (nfsd4op_func)nfsd4_test_stateid, 145217456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 145317456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 145417456804SBryan Schumaker }, 1455e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 1456e1ca12dfSBryan Schumaker .op_func = (nfsd4op_func)nfsd4_free_stateid, 1457e1ca12dfSBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 1458e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 1459e1ca12dfSBryan Schumaker }, 1460b591480bSJ.Bruce Fields }; 1461b591480bSJ.Bruce Fields 1462f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 1463b001a1b6SBenny Halevy { 1464b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 1465b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 1466b001a1b6SBenny Halevy return "unknown_operation"; 1467b001a1b6SBenny Halevy } 1468b001a1b6SBenny Halevy 14691da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 14701da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 14730a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 14740a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_null, 14750a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 14760a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 14770a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 14780a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 14790a93a47fSYu Zhiguo .pc_xdrressize = 1, 14800a93a47fSYu Zhiguo }, 14810a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 14820a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_compound, 14830a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 14840a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 14850a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 14860a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 14873e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 14880a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 14890a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 14900a93a47fSYu Zhiguo }, 14911da177e4SLinus Torvalds }; 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 14941da177e4SLinus Torvalds .vs_vers = 4, 14951da177e4SLinus Torvalds .vs_nproc = 2, 14961da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 14971da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 14981da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 14991da177e4SLinus Torvalds }; 15001da177e4SLinus Torvalds 15011da177e4SLinus Torvalds /* 15021da177e4SLinus Torvalds * Local variables: 15031da177e4SLinus Torvalds * c-basic-offset: 8 15041da177e4SLinus Torvalds * End: 15051da177e4SLinus Torvalds */ 1506