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 29460adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 29560adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 29660adfc50SAndy Adamson 2971da177e4SLinus Torvalds nfs4_lock_state(); 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3006668958fSAndy Adamson resp = rqstp->rq_resp; 3016668958fSAndy Adamson status = nfsd4_process_open1(&resp->cstate, open); 302a90b061cSAl Viro if (status == nfserr_replay_me) { 3031da177e4SLinus Torvalds struct nfs4_replay *rp = &open->op_stateowner->so_replay; 304ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 305a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 306a4773c08SJ. Bruce Fields &rp->rp_openfh); 3078837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3081da177e4SLinus Torvalds if (status) 3091da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 3101da177e4SLinus Torvalds " restoring previous filehandle\n"); 3111da177e4SLinus Torvalds else 312a90b061cSAl Viro status = nfserr_replay_me; 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds if (status) 3151da177e4SLinus Torvalds goto out; 316fb553c0fSJ. Bruce Fields 3173c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 3183c8e0316SYu Zhiguo if (status) 3193c8e0316SYu Zhiguo goto out; 3203c8e0316SYu Zhiguo 321fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 322fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 323cbd0d51aSJ. Bruce Fields status = nfserr_grace; 324af558e33SJ. Bruce Fields if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 325cbd0d51aSJ. Bruce Fields goto out; 326cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 327af558e33SJ. Bruce Fields if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 328cbd0d51aSJ. Bruce Fields goto out; 329fb553c0fSJ. Bruce Fields 3301da177e4SLinus Torvalds switch (open->op_claim_type) { 3310dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 3321da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 3331da177e4SLinus Torvalds /* 3341da177e4SLinus Torvalds * (1) set CURRENT_FH to the file being opened, 3351da177e4SLinus Torvalds * creating it if necessary, (2) set open->op_cinfo, 3361da177e4SLinus Torvalds * (3) set open->op_truncate if the file is to be 3371da177e4SLinus Torvalds * truncated after opening, (4) do permission checking. 3381da177e4SLinus Torvalds */ 339ca364317SJ.Bruce Fields status = do_open_lookup(rqstp, &cstate->current_fh, 340ca364317SJ.Bruce Fields open); 3411da177e4SLinus Torvalds if (status) 3421da177e4SLinus Torvalds goto out; 3431da177e4SLinus Torvalds break; 3441da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 345a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 3461da177e4SLinus Torvalds /* 3471da177e4SLinus Torvalds * The CURRENT_FH is already set to the file being 3481da177e4SLinus Torvalds * opened. (1) set open->op_cinfo, (2) set 3491da177e4SLinus Torvalds * open->op_truncate if the file is to be truncated 3501da177e4SLinus Torvalds * after opening, (3) do permission checking. 3511da177e4SLinus Torvalds */ 352ca364317SJ.Bruce Fields status = do_open_fhandle(rqstp, &cstate->current_fh, 353ca364317SJ.Bruce Fields open); 3541da177e4SLinus Torvalds if (status) 3551da177e4SLinus Torvalds goto out; 3561da177e4SLinus Torvalds break; 3571da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 358a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 3592fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 3601da177e4SLinus Torvalds open->op_claim_type); 3611da177e4SLinus Torvalds status = nfserr_notsupp; 3621da177e4SLinus Torvalds goto out; 3631da177e4SLinus Torvalds default: 3642fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 3651da177e4SLinus Torvalds open->op_claim_type); 3661da177e4SLinus Torvalds status = nfserr_inval; 3671da177e4SLinus Torvalds goto out; 3681da177e4SLinus Torvalds } 3691da177e4SLinus Torvalds /* 3701da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 3711da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 3721da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 3731da177e4SLinus Torvalds */ 374ca364317SJ.Bruce Fields status = nfsd4_process_open2(rqstp, &cstate->current_fh, open); 3751da177e4SLinus Torvalds out: 376f2327d9aSNeil Brown if (open->op_stateowner) { 3771da177e4SLinus Torvalds nfs4_get_stateowner(open->op_stateowner); 378a4f1706aSJ.Bruce Fields cstate->replay_owner = open->op_stateowner; 379f2327d9aSNeil Brown } 3801da177e4SLinus Torvalds nfs4_unlock_state(); 3811da177e4SLinus Torvalds return status; 3821da177e4SLinus Torvalds } 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds /* 3851da177e4SLinus Torvalds * filehandle-manipulating ops. 3861da177e4SLinus Torvalds */ 3877191155bSJ.Bruce Fields static __be32 388b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 389b591480bSJ.Bruce Fields struct svc_fh **getfh) 3901da177e4SLinus Torvalds { 391ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 3921da177e4SLinus Torvalds return nfserr_nofilehandle; 3931da177e4SLinus Torvalds 394ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 3951da177e4SLinus Torvalds return nfs_ok; 3961da177e4SLinus Torvalds } 3971da177e4SLinus Torvalds 3987191155bSJ.Bruce Fields static __be32 399ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 400ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 4011da177e4SLinus Torvalds { 402ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 403ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 404ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 405ca364317SJ.Bruce Fields putfh->pf_fhlen); 40668d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 4071da177e4SLinus Torvalds } 4081da177e4SLinus Torvalds 4097191155bSJ.Bruce Fields static __be32 410b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 411b591480bSJ.Bruce Fields void *arg) 4121da177e4SLinus Torvalds { 413b37ad28bSAl Viro __be32 status; 4141da177e4SLinus Torvalds 415ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 416df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 4171da177e4SLinus Torvalds return status; 4181da177e4SLinus Torvalds } 4191da177e4SLinus Torvalds 4207191155bSJ.Bruce Fields static __be32 421b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 422b591480bSJ.Bruce Fields void *arg) 4231da177e4SLinus Torvalds { 424ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 4251da177e4SLinus Torvalds return nfserr_restorefh; 4261da177e4SLinus Torvalds 427ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 4281da177e4SLinus Torvalds return nfs_ok; 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds 4317191155bSJ.Bruce Fields static __be32 432b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 433b591480bSJ.Bruce Fields void *arg) 4341da177e4SLinus Torvalds { 435ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 4361da177e4SLinus Torvalds return nfserr_nofilehandle; 4371da177e4SLinus Torvalds 438ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 4391da177e4SLinus Torvalds return nfs_ok; 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds /* 4431da177e4SLinus Torvalds * misc nfsv4 ops 4441da177e4SLinus Torvalds */ 4457191155bSJ.Bruce Fields static __be32 446ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 447ca364317SJ.Bruce Fields struct nfsd4_access *access) 4481da177e4SLinus Torvalds { 4491da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 4501da177e4SLinus Torvalds return nfserr_inval; 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 453ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 454ca364317SJ.Bruce Fields &access->ac_supported); 4551da177e4SLinus Torvalds } 4561da177e4SLinus Torvalds 4577191155bSJ.Bruce Fields static __be32 458ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 459ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 4601da177e4SLinus Torvalds { 461b37ad28bSAl Viro __be32 status; 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds u32 *p = (u32 *)commit->co_verf.data; 4641da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 4651da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 4661da177e4SLinus Torvalds 467ca364317SJ.Bruce Fields status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 468ca364317SJ.Bruce Fields commit->co_count); 4691da177e4SLinus Torvalds if (status == nfserr_symlink) 4701da177e4SLinus Torvalds status = nfserr_inval; 4711da177e4SLinus Torvalds return status; 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds 474b37ad28bSAl Viro static __be32 475ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 476ca364317SJ.Bruce Fields struct nfsd4_create *create) 4771da177e4SLinus Torvalds { 4781da177e4SLinus Torvalds struct svc_fh resfh; 479b37ad28bSAl Viro __be32 status; 4801da177e4SLinus Torvalds dev_t rdev; 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 4831da177e4SLinus Torvalds 4848837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, 4858837abcaSMiklos Szeredi NFSD_MAY_CREATE); 4861da177e4SLinus Torvalds if (status == nfserr_symlink) 4871da177e4SLinus Torvalds status = nfserr_notdir; 4881da177e4SLinus Torvalds if (status) 4891da177e4SLinus Torvalds return status; 4901da177e4SLinus Torvalds 4913c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 4923c8e0316SYu Zhiguo nfsd_attrmask); 4933c8e0316SYu Zhiguo if (status) 4943c8e0316SYu Zhiguo return status; 4953c8e0316SYu Zhiguo 4961da177e4SLinus Torvalds switch (create->cr_type) { 4971da177e4SLinus Torvalds case NF4LNK: 4981da177e4SLinus Torvalds /* ugh! we have to null-terminate the linktext, or 4991da177e4SLinus Torvalds * vfs_symlink() will choke. it is always safe to 5001da177e4SLinus Torvalds * null-terminate by brute force, since at worst we 5011da177e4SLinus Torvalds * will overwrite the first byte of the create namelen 5021da177e4SLinus Torvalds * in the XDR buffer, which has already been extracted 5031da177e4SLinus Torvalds * during XDR decode. 5041da177e4SLinus Torvalds */ 5051da177e4SLinus Torvalds create->cr_linkname[create->cr_linklen] = 0; 5061da177e4SLinus Torvalds 507ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 508ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 509ca364317SJ.Bruce Fields create->cr_linkname, create->cr_linklen, 510ca364317SJ.Bruce Fields &resfh, &create->cr_iattr); 5111da177e4SLinus Torvalds break; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds case NF4BLK: 5141da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 5151da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 5161da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 5171da177e4SLinus Torvalds return nfserr_inval; 518ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 519ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 520ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 5211da177e4SLinus Torvalds break; 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds case NF4CHR: 5241da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 5251da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 5261da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 5271da177e4SLinus Torvalds return nfserr_inval; 528ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 529ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 530ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 5311da177e4SLinus Torvalds break; 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds case NF4SOCK: 534ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 535ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 536ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 5371da177e4SLinus Torvalds break; 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds case NF4FIFO: 540ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 541ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 542ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 5431da177e4SLinus Torvalds break; 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds case NF4DIR: 5461da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 547ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 548ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 549ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 5501da177e4SLinus Torvalds break; 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds default: 5531da177e4SLinus Torvalds status = nfserr_badtype; 5541da177e4SLinus Torvalds } 5551da177e4SLinus Torvalds 5569208faf2SYu Zhiguo if (status) 5579208faf2SYu Zhiguo goto out; 5589208faf2SYu Zhiguo 5599208faf2SYu Zhiguo if (create->cr_acl != NULL) 5609208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 5619208faf2SYu Zhiguo create->cr_bmval); 5629208faf2SYu Zhiguo 563ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 564ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 565ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 5669208faf2SYu Zhiguo out: 5671da177e4SLinus Torvalds fh_put(&resfh); 5681da177e4SLinus Torvalds return status; 5691da177e4SLinus Torvalds } 5701da177e4SLinus Torvalds 5717191155bSJ.Bruce Fields static __be32 572ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 573ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 5741da177e4SLinus Torvalds { 575b37ad28bSAl Viro __be32 status; 5761da177e4SLinus Torvalds 5778837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 5781da177e4SLinus Torvalds if (status) 5791da177e4SLinus Torvalds return status; 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 5821da177e4SLinus Torvalds return nfserr_inval; 5831da177e4SLinus Torvalds 5847e705706SAndy Adamson getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 5857e705706SAndy Adamson getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 5867e705706SAndy Adamson getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 5871da177e4SLinus Torvalds 588ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 5891da177e4SLinus Torvalds return nfs_ok; 5901da177e4SLinus Torvalds } 5911da177e4SLinus Torvalds 5927191155bSJ.Bruce Fields static __be32 593ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 594ca364317SJ.Bruce Fields struct nfsd4_link *link) 5951da177e4SLinus Torvalds { 596b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 5971da177e4SLinus Torvalds 598ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5991da177e4SLinus Torvalds return status; 600ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 601ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 6021da177e4SLinus Torvalds if (!status) 603ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 6041da177e4SLinus Torvalds return status; 6051da177e4SLinus Torvalds } 6061da177e4SLinus Torvalds 6070ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 6081da177e4SLinus Torvalds { 6091da177e4SLinus Torvalds struct svc_fh tmp_fh; 610b37ad28bSAl Viro __be32 ret; 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 613df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 614df547efbSJ. Bruce Fields if (ret) 6151da177e4SLinus Torvalds return ret; 6160ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 6171da177e4SLinus Torvalds fh_put(&tmp_fh); 6181da177e4SLinus Torvalds return nfserr_noent; 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds fh_put(&tmp_fh); 6210ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 6220ff7ab46SJ. Bruce Fields } 6230ff7ab46SJ. Bruce Fields 6240ff7ab46SJ. Bruce Fields static __be32 6250ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 6260ff7ab46SJ. Bruce Fields void *arg) 6270ff7ab46SJ. Bruce Fields { 6280ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 6291da177e4SLinus Torvalds } 6301da177e4SLinus Torvalds 6317191155bSJ.Bruce Fields static __be32 632ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 633ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 6341da177e4SLinus Torvalds { 635ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 636ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 637ca364317SJ.Bruce Fields &cstate->current_fh); 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds 6407191155bSJ.Bruce Fields static __be32 641ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 642ca364317SJ.Bruce Fields struct nfsd4_read *read) 6431da177e4SLinus Torvalds { 644b37ad28bSAl Viro __be32 status; 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_read() */ 6471da177e4SLinus Torvalds 6487e06b7f9SNeilBrown read->rd_filp = NULL; 6491da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 6501da177e4SLinus Torvalds return nfserr_inval; 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds nfs4_lock_state(); 6531da177e4SLinus Torvalds /* check stateid */ 654dd453dfdSBenny Halevy if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid, 6556150ef0dSJ. Bruce Fields RD_STATE, &read->rd_filp))) { 6561da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 6571da177e4SLinus Torvalds goto out; 6581da177e4SLinus Torvalds } 6597e06b7f9SNeilBrown if (read->rd_filp) 6607e06b7f9SNeilBrown get_file(read->rd_filp); 6611da177e4SLinus Torvalds status = nfs_ok; 6621da177e4SLinus Torvalds out: 6631da177e4SLinus Torvalds nfs4_unlock_state(); 6641da177e4SLinus Torvalds read->rd_rqstp = rqstp; 665ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 6661da177e4SLinus Torvalds return status; 6671da177e4SLinus Torvalds } 6681da177e4SLinus Torvalds 6697191155bSJ.Bruce Fields static __be32 670ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 671ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 6721da177e4SLinus Torvalds { 6731da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 6741da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6791da177e4SLinus Torvalds return nfserr_inval; 6801da177e4SLinus Torvalds 6817e705706SAndy Adamson readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 6827e705706SAndy Adamson readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 6837e705706SAndy Adamson readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds if ((cookie > ~(u32)0) || (cookie == 1) || (cookie == 2) || 6861da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 6871da177e4SLinus Torvalds return nfserr_bad_cookie; 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 690ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 6911da177e4SLinus Torvalds return nfs_ok; 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds 6947191155bSJ.Bruce Fields static __be32 695ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 696ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 6971da177e4SLinus Torvalds { 6981da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 699ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 7001da177e4SLinus Torvalds return nfs_ok; 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds 7037191155bSJ.Bruce Fields static __be32 704ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 705ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 7061da177e4SLinus Torvalds { 707b37ad28bSAl Viro __be32 status; 7081da177e4SLinus Torvalds 709af558e33SJ. Bruce Fields if (locks_in_grace()) 710c815afc7SNeilBrown return nfserr_grace; 711ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 712ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 7131da177e4SLinus Torvalds if (status == nfserr_symlink) 7141da177e4SLinus Torvalds return nfserr_notdir; 7151da177e4SLinus Torvalds if (!status) { 716ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 717ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds return status; 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds 7227191155bSJ.Bruce Fields static __be32 723ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 724ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 7251da177e4SLinus Torvalds { 726b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 7271da177e4SLinus Torvalds 728ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 7291da177e4SLinus Torvalds return status; 730af558e33SJ. Bruce Fields if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags 731c815afc7SNeilBrown & NFSEXP_NOSUBTREECHECK)) 732c815afc7SNeilBrown return nfserr_grace; 733ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 734ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 7351da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds /* the underlying filesystem returns different error's than required 7381da177e4SLinus Torvalds * by NFSv4. both save_fh and current_fh have been verified.. */ 7391da177e4SLinus Torvalds if (status == nfserr_isdir) 7401da177e4SLinus Torvalds status = nfserr_exist; 7411da177e4SLinus Torvalds else if ((status == nfserr_notdir) && 742ca364317SJ.Bruce Fields (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) && 743ca364317SJ.Bruce Fields S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode))) 7441da177e4SLinus Torvalds status = nfserr_exist; 7451da177e4SLinus Torvalds else if (status == nfserr_symlink) 7461da177e4SLinus Torvalds status = nfserr_notdir; 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds if (!status) { 749ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 750ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 7511da177e4SLinus Torvalds } 7521da177e4SLinus Torvalds return status; 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds 7557191155bSJ.Bruce Fields static __be32 756dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 757dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 758dcb488a3SAndy Adamson { 759dcb488a3SAndy Adamson struct svc_fh resfh; 760dcb488a3SAndy Adamson struct svc_export *exp; 761dcb488a3SAndy Adamson struct dentry *dentry; 762dcb488a3SAndy Adamson __be32 err; 763dcb488a3SAndy Adamson 764dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 76529a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 76629a78a3eSJ. Bruce Fields if (err) 76729a78a3eSJ. Bruce Fields return err; 768dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 769dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 770dcb488a3SAndy Adamson &exp, &dentry); 771dcb488a3SAndy Adamson if (err) 772dcb488a3SAndy Adamson return err; 773dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 774dcb488a3SAndy Adamson exp_put(exp); 775dcb488a3SAndy Adamson err = nfserr_noent; 776dcb488a3SAndy Adamson } else 777dcb488a3SAndy Adamson secinfo->si_exp = exp; 778dcb488a3SAndy Adamson dput(dentry); 77956560b9aSJ. Bruce Fields if (cstate->minorversion) 78056560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 78156560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 782dcb488a3SAndy Adamson return err; 783dcb488a3SAndy Adamson } 784dcb488a3SAndy Adamson 785dcb488a3SAndy Adamson static __be32 78604f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 78704f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 78804f4ad16SJ. Bruce Fields { 78904f4ad16SJ. Bruce Fields __be32 err; 79004f4ad16SJ. Bruce Fields 79104f4ad16SJ. Bruce Fields switch (sin->sin_style) { 79204f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 79304f4ad16SJ. Bruce Fields break; 79404f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 79504f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 79604f4ad16SJ. Bruce Fields if (err) 79704f4ad16SJ. Bruce Fields return err; 79804f4ad16SJ. Bruce Fields break; 79904f4ad16SJ. Bruce Fields default: 80004f4ad16SJ. Bruce Fields return nfserr_inval; 80104f4ad16SJ. Bruce Fields } 80204f4ad16SJ. Bruce Fields exp_get(cstate->current_fh.fh_export); 80304f4ad16SJ. Bruce Fields sin->sin_exp = cstate->current_fh.fh_export; 80404f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 80504f4ad16SJ. Bruce Fields return nfs_ok; 80604f4ad16SJ. Bruce Fields } 80704f4ad16SJ. Bruce Fields 80804f4ad16SJ. Bruce Fields static __be32 809ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 810ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 8111da177e4SLinus Torvalds { 812b37ad28bSAl Viro __be32 status = nfs_ok; 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 8151da177e4SLinus Torvalds nfs4_lock_state(); 816dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, 8176150ef0dSJ. Bruce Fields &setattr->sa_stateid, WR_STATE, NULL); 8181da177e4SLinus Torvalds nfs4_unlock_state(); 819375c5547SJ. Bruce Fields if (status) { 8203e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 821375c5547SJ. Bruce Fields return status; 822375c5547SJ. Bruce Fields } 8231da177e4SLinus Torvalds } 82418f335afSDave Hansen status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt); 82518f335afSDave Hansen if (status) 82618f335afSDave Hansen return status; 8271da177e4SLinus Torvalds status = nfs_ok; 8283c8e0316SYu Zhiguo 8293c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 8303c8e0316SYu Zhiguo nfsd_attrmask); 8313c8e0316SYu Zhiguo if (status) 8323c8e0316SYu Zhiguo goto out; 8333c8e0316SYu Zhiguo 8341da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 835ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 836ca364317SJ.Bruce Fields setattr->sa_acl); 8371da177e4SLinus Torvalds if (status) 83818f335afSDave Hansen goto out; 839ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 8401da177e4SLinus Torvalds 0, (time_t)0); 84118f335afSDave Hansen out: 84218f335afSDave Hansen mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt); 8431da177e4SLinus Torvalds return status; 8441da177e4SLinus Torvalds } 8451da177e4SLinus Torvalds 8467191155bSJ.Bruce Fields static __be32 847ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 848ca364317SJ.Bruce Fields struct nfsd4_write *write) 8491da177e4SLinus Torvalds { 8501da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 8511da177e4SLinus Torvalds struct file *filp = NULL; 8521da177e4SLinus Torvalds u32 *p; 853b37ad28bSAl Viro __be32 status = nfs_ok; 85431dec253SDavid Shaw unsigned long cnt; 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 8591da177e4SLinus Torvalds return nfserr_inval; 8601da177e4SLinus Torvalds 8611da177e4SLinus Torvalds nfs4_lock_state(); 862dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp); 8637e06b7f9SNeilBrown if (filp) 8647e06b7f9SNeilBrown get_file(filp); 8651da177e4SLinus Torvalds nfs4_unlock_state(); 8661da177e4SLinus Torvalds 867375c5547SJ. Bruce Fields if (status) { 868375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 869375c5547SJ. Bruce Fields return status; 870375c5547SJ. Bruce Fields } 871375c5547SJ. Bruce Fields 87231dec253SDavid Shaw cnt = write->wr_buflen; 8731da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 8741da177e4SLinus Torvalds p = (u32 *)write->wr_verifier.data; 8751da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 8761da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 8771da177e4SLinus Torvalds 878ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 879ca364317SJ.Bruce Fields write->wr_offset, rqstp->rq_vec, write->wr_vlen, 88031dec253SDavid Shaw &cnt, &write->wr_how_written); 8817e06b7f9SNeilBrown if (filp) 8827e06b7f9SNeilBrown fput(filp); 8831da177e4SLinus Torvalds 88431dec253SDavid Shaw write->wr_bytes_written = cnt; 88531dec253SDavid Shaw 8861da177e4SLinus Torvalds if (status == nfserr_symlink) 8871da177e4SLinus Torvalds status = nfserr_inval; 8881da177e4SLinus Torvalds return status; 8891da177e4SLinus Torvalds } 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 8921da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 8931da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 8941da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 8951da177e4SLinus Torvalds */ 896b37ad28bSAl Viro static __be32 897c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 898ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 8991da177e4SLinus Torvalds { 9002ebbc012SAl Viro __be32 *buf, *p; 9011da177e4SLinus Torvalds int count; 902b37ad28bSAl Viro __be32 status; 9031da177e4SLinus Torvalds 9048837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 9051da177e4SLinus Torvalds if (status) 9061da177e4SLinus Torvalds return status; 9071da177e4SLinus Torvalds 9083c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 9093c8e0316SYu Zhiguo if (status) 9103c8e0316SYu Zhiguo return status; 9113c8e0316SYu Zhiguo 9121da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 9131da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 9141da177e4SLinus Torvalds return nfserr_inval; 9151da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 9161da177e4SLinus Torvalds return nfserr_inval; 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds /* count in words: 9191da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 9201da177e4SLinus Torvalds */ 9211da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 9221da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 9231da177e4SLinus Torvalds if (!buf) 9241da177e4SLinus Torvalds return nfserr_resource; 9251da177e4SLinus Torvalds 926ca364317SJ.Bruce Fields status = nfsd4_encode_fattr(&cstate->current_fh, 927ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 928ca364317SJ.Bruce Fields cstate->current_fh.fh_dentry, buf, 9291da177e4SLinus Torvalds &count, verify->ve_bmval, 930406a7ea9SFrank Filz rqstp, 0); 9311da177e4SLinus Torvalds 9321da177e4SLinus Torvalds /* this means that nfsd4_encode_fattr() ran out of space */ 9331da177e4SLinus Torvalds if (status == nfserr_resource && count == 0) 9341da177e4SLinus Torvalds status = nfserr_not_same; 9351da177e4SLinus Torvalds if (status) 9361da177e4SLinus Torvalds goto out_kfree; 9371da177e4SLinus Torvalds 93895ec28cdSBenny Halevy /* skip bitmap */ 93995ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 9401da177e4SLinus Torvalds status = nfserr_not_same; 9411da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 9421da177e4SLinus Torvalds goto out_kfree; 9431da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 9441da177e4SLinus Torvalds status = nfserr_same; 9451da177e4SLinus Torvalds 9461da177e4SLinus Torvalds out_kfree: 9471da177e4SLinus Torvalds kfree(buf); 9481da177e4SLinus Torvalds return status; 9491da177e4SLinus Torvalds } 9501da177e4SLinus Torvalds 951c954e2a5SJ.Bruce Fields static __be32 952c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 953c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 954c954e2a5SJ.Bruce Fields { 955c954e2a5SJ.Bruce Fields __be32 status; 956c954e2a5SJ.Bruce Fields 957c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 958c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 959c954e2a5SJ.Bruce Fields } 960c954e2a5SJ.Bruce Fields 961c954e2a5SJ.Bruce Fields static __be32 962c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 963c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 964c954e2a5SJ.Bruce Fields { 965c954e2a5SJ.Bruce Fields __be32 status; 966c954e2a5SJ.Bruce Fields 967c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 968c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 969c954e2a5SJ.Bruce Fields } 970c954e2a5SJ.Bruce Fields 9711da177e4SLinus Torvalds /* 9721da177e4SLinus Torvalds * NULL call. 9731da177e4SLinus Torvalds */ 9747111c66eSAl Viro static __be32 9751da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 9761da177e4SLinus Torvalds { 9771da177e4SLinus Torvalds return nfs_ok; 9781da177e4SLinus Torvalds } 9791da177e4SLinus Torvalds 980e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 981e2b20950SShankar Anand { 982e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 983e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 984e2b20950SShankar Anand } 985e2b20950SShankar Anand 986b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 987b591480bSJ.Bruce Fields void *); 988f9bb94c4SAndy Adamson enum nfsd4_op_flags { 989f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 9905ece3cafSMi Jinlong ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 9915ece3cafSMi Jinlong ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 99268d93184SJ. Bruce Fields /* For rfc 5661 section 2.6.3.1.1: */ 99368d93184SJ. Bruce Fields OP_HANDLES_WRONGSEC = 1 << 3, 99468d93184SJ. Bruce Fields OP_IS_PUTFH_LIKE = 1 << 4, 995f9bb94c4SAndy Adamson }; 996b591480bSJ.Bruce Fields 997b591480bSJ.Bruce Fields struct nfsd4_operation { 998b591480bSJ.Bruce Fields nfsd4op_func op_func; 999b591480bSJ.Bruce Fields u32 op_flags; 1000b001a1b6SBenny Halevy char *op_name; 1001b591480bSJ.Bruce Fields }; 1002b591480bSJ.Bruce Fields 1003b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 1004b591480bSJ.Bruce Fields 1005f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1006b001a1b6SBenny Halevy 10071da177e4SLinus Torvalds /* 100857716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1009f9bb94c4SAndy Adamson * 101057716355SJ. Bruce Fields * Also note, enforced elsewhere: 101157716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 101257716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 10131d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 10141d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 101557716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 101657716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 101757716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1018f9bb94c4SAndy Adamson */ 101957716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1020f9bb94c4SAndy Adamson { 1021f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 102257716355SJ. Bruce Fields 102357716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 102457716355SJ. Bruce Fields if (args->minorversion == 0) 102557716355SJ. Bruce Fields return nfs_ok; 102657716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 102757716355SJ. Bruce Fields if (args->opcnt == 0) 102857716355SJ. Bruce Fields return nfs_ok; 102957716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 103057716355SJ. Bruce Fields return nfs_ok; 103157716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 103257716355SJ. Bruce Fields return nfserr_op_not_in_session; 103357716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 103457716355SJ. Bruce Fields return nfs_ok; 103557716355SJ. Bruce Fields if (args->opcnt != 1) 103657716355SJ. Bruce Fields return nfserr_not_only_op; 103757716355SJ. Bruce Fields return nfs_ok; 1038f9bb94c4SAndy Adamson } 1039f9bb94c4SAndy Adamson 104022b03214SJ. Bruce Fields static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 104122b03214SJ. Bruce Fields { 104222b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 104322b03214SJ. Bruce Fields } 104422b03214SJ. Bruce Fields 104568d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 104668d93184SJ. Bruce Fields { 104768d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 104868d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 104968d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 105068d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 105168d93184SJ. Bruce Fields struct nfsd4_operation *thisd; 105268d93184SJ. Bruce Fields struct nfsd4_operation *nextd; 105368d93184SJ. Bruce Fields 105468d93184SJ. Bruce Fields thisd = OPDESC(this); 105568d93184SJ. Bruce Fields /* 105668d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 105768d93184SJ. Bruce Fields * have special rules. 105868d93184SJ. Bruce Fields */ 105968d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 106068d93184SJ. Bruce Fields return false; 106168d93184SJ. Bruce Fields /* 106268d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 106368d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 106468d93184SJ. Bruce Fields * result: 106568d93184SJ. Bruce Fields */ 106668d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 106768d93184SJ. Bruce Fields return false; 106868d93184SJ. Bruce Fields 106968d93184SJ. Bruce Fields nextd = OPDESC(next); 107068d93184SJ. Bruce Fields /* 107168d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 107268d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 107368d93184SJ. Bruce Fields * now: 107468d93184SJ. Bruce Fields */ 107568d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 107668d93184SJ. Bruce Fields } 107768d93184SJ. Bruce Fields 1078f9bb94c4SAndy Adamson /* 10791da177e4SLinus Torvalds * COMPOUND call. 10801da177e4SLinus Torvalds */ 10817111c66eSAl Viro static __be32 10821da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 10831da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 10841da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 10851da177e4SLinus Torvalds { 10861da177e4SLinus Torvalds struct nfsd4_op *op; 1087b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1088e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 1089e5710199SJ.Bruce Fields int slack_bytes; 1090b37ad28bSAl Viro __be32 status; 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds resp->xbuf = &rqstp->rq_res; 1093e354d571SAndy Adamson resp->p = rqstp->rq_res.head[0].iov_base + 1094e354d571SAndy Adamson rqstp->rq_res.head[0].iov_len; 10951da177e4SLinus Torvalds resp->tagp = resp->p; 10961da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 10971da177e4SLinus Torvalds resp->p += 2 + XDR_QUADLEN(args->taglen); 10981da177e4SLinus Torvalds resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE; 10991da177e4SLinus Torvalds resp->taglen = args->taglen; 11001da177e4SLinus Torvalds resp->tag = args->tag; 11011da177e4SLinus Torvalds resp->opcnt = 0; 11021da177e4SLinus Torvalds resp->rqstp = rqstp; 1103d87a8adeSAndy Adamson resp->cstate.minorversion = args->minorversion; 1104e354d571SAndy Adamson resp->cstate.replay_owner = NULL; 110526c0c75eSJ. Bruce Fields resp->cstate.session = NULL; 1106e354d571SAndy Adamson fh_init(&resp->cstate.current_fh, NFS4_FHSIZE); 1107e354d571SAndy Adamson fh_init(&resp->cstate.save_fh, NFS4_FHSIZE); 11088ff30fa4SNeilBrown /* 11098ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 11108ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 11118ff30fa4SNeilBrown */ 11128ff30fa4SNeilBrown rqstp->rq_usedeferral = 0; 11131da177e4SLinus Torvalds 11141da177e4SLinus Torvalds /* 11151da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 11161da177e4SLinus Torvalds */ 11171da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 11188daf220aSBenny Halevy if (args->minorversion > nfsd_supported_minorversion) 11191da177e4SLinus Torvalds goto out; 11201da177e4SLinus Torvalds 112157716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 112257716355SJ. Bruce Fields if (status) { 1123f9bb94c4SAndy Adamson op = &args->ops[0]; 112457716355SJ. Bruce Fields op->status = status; 1125f9bb94c4SAndy Adamson goto encode_op; 1126f9bb94c4SAndy Adamson } 1127f9bb94c4SAndy Adamson 11281da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 11291da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 11301da177e4SLinus Torvalds 1131b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1132b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1133b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 11341da177e4SLinus Torvalds /* 11351da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 11361da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 11371da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 11381da177e4SLinus Torvalds */ 11391da177e4SLinus Torvalds if (op->status) 11401da177e4SLinus Torvalds goto encode_op; 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds /* We must be able to encode a successful response to 11431da177e4SLinus Torvalds * this operation, with enough room left over to encode a 11441da177e4SLinus Torvalds * failed response to the next operation. If we don't 11451da177e4SLinus Torvalds * have enough room, fail with ERR_RESOURCE. 11461da177e4SLinus Torvalds */ 1147e5710199SJ.Bruce Fields slack_bytes = (char *)resp->end - (char *)resp->p; 1148e5710199SJ.Bruce Fields if (slack_bytes < COMPOUND_SLACK_SPACE 1149e5710199SJ.Bruce Fields + COMPOUND_ERR_SLACK_SPACE) { 1150e5710199SJ.Bruce Fields BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE); 11511da177e4SLinus Torvalds op->status = nfserr_resource; 11521da177e4SLinus Torvalds goto encode_op; 11531da177e4SLinus Torvalds } 11541da177e4SLinus Torvalds 115522b03214SJ. Bruce Fields opdesc = OPDESC(op); 1156b591480bSJ.Bruce Fields 1157ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) { 115827d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 11591da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 11601da177e4SLinus Torvalds goto encode_op; 11611da177e4SLinus Torvalds } 1162eeac294eSJ.Bruce Fields } else if (cstate->current_fh.fh_export->ex_fslocs.migrated && 1163eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 116442ca0993SJ.Bruce Fields op->status = nfserr_moved; 116542ca0993SJ.Bruce Fields goto encode_op; 116642ca0993SJ.Bruce Fields } 1167b591480bSJ.Bruce Fields 1168b591480bSJ.Bruce Fields if (opdesc->op_func) 1169b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 1170b591480bSJ.Bruce Fields else 11711da177e4SLinus Torvalds BUG_ON(op->status == nfs_ok); 11721da177e4SLinus Torvalds 117368d93184SJ. Bruce Fields if (!op->status && need_wrongsec_check(rqstp)) 117468d93184SJ. Bruce Fields op->status = check_nfsd_access(cstate->current_fh.fh_export, rqstp); 117568d93184SJ. Bruce Fields 11761da177e4SLinus Torvalds encode_op: 117749557cc7SAndy Adamson /* Only from SEQUENCE */ 1178da3846a2SAndy Adamson if (resp->cstate.status == nfserr_replay_cache) { 1179da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1180da3846a2SAndy Adamson status = op->status; 1181da3846a2SAndy Adamson goto out; 1182da3846a2SAndy Adamson } 1183a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1184a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 11851da177e4SLinus Torvalds nfsd4_encode_replay(resp, op); 11861da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 11871da177e4SLinus Torvalds } else { 11881da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 11891da177e4SLinus Torvalds status = op->status; 11901da177e4SLinus Torvalds } 11910407717dSBenny Halevy 11920407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 11930407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 11940407717dSBenny Halevy be32_to_cpu(status)); 11950407717dSBenny Halevy 1196a4f1706aSJ.Bruce Fields if (cstate->replay_owner) { 1197a4f1706aSJ.Bruce Fields nfs4_put_stateowner(cstate->replay_owner); 1198a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 11991da177e4SLinus Torvalds } 12007e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 12017e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 12027e06b7f9SNeilBrown fput(op->u.read.rd_filp); 1203e2b20950SShankar Anand 1204e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 12051da177e4SLinus Torvalds } 12061da177e4SLinus Torvalds 1207da3846a2SAndy Adamson resp->cstate.status = status; 1208e354d571SAndy Adamson fh_put(&resp->cstate.current_fh); 1209e354d571SAndy Adamson fh_put(&resp->cstate.save_fh); 1210e354d571SAndy Adamson BUG_ON(resp->cstate.replay_owner); 12111da177e4SLinus Torvalds out: 12121da177e4SLinus Torvalds nfsd4_release_compoundargs(args); 12132f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 12142f425878SAndy Adamson rqstp->rq_usedeferral = 1; 12153b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 12161da177e4SLinus Torvalds return status; 12171da177e4SLinus Torvalds } 12181da177e4SLinus Torvalds 121920766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1220b591480bSJ.Bruce Fields [OP_ACCESS] = { 1221b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1222b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1223b591480bSJ.Bruce Fields }, 1224b591480bSJ.Bruce Fields [OP_CLOSE] = { 1225b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 1226b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 1227b591480bSJ.Bruce Fields }, 1228b591480bSJ.Bruce Fields [OP_COMMIT] = { 1229b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 1230b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 1231b591480bSJ.Bruce Fields }, 1232b591480bSJ.Bruce Fields [OP_CREATE] = { 1233b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1234b001a1b6SBenny Halevy .op_name = "OP_CREATE", 1235b591480bSJ.Bruce Fields }, 1236b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1237b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 1238b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 1239b591480bSJ.Bruce Fields }, 1240b591480bSJ.Bruce Fields [OP_GETATTR] = { 1241b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 1242eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 1243b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 1244b591480bSJ.Bruce Fields }, 1245b591480bSJ.Bruce Fields [OP_GETFH] = { 1246b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 1247b001a1b6SBenny Halevy .op_name = "OP_GETFH", 1248b591480bSJ.Bruce Fields }, 1249b591480bSJ.Bruce Fields [OP_LINK] = { 1250b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 1251b001a1b6SBenny Halevy .op_name = "OP_LINK", 1252b591480bSJ.Bruce Fields }, 1253b591480bSJ.Bruce Fields [OP_LOCK] = { 1254b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 1255b001a1b6SBenny Halevy .op_name = "OP_LOCK", 1256b591480bSJ.Bruce Fields }, 1257b591480bSJ.Bruce Fields [OP_LOCKT] = { 1258b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 1259b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 1260b591480bSJ.Bruce Fields }, 1261b591480bSJ.Bruce Fields [OP_LOCKU] = { 1262b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 1263b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 1264b591480bSJ.Bruce Fields }, 1265b591480bSJ.Bruce Fields [OP_LOOKUP] = { 1266b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 126768d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1268b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 1269b591480bSJ.Bruce Fields }, 1270b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 1271b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 127268d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1273b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 1274b591480bSJ.Bruce Fields }, 1275b591480bSJ.Bruce Fields [OP_NVERIFY] = { 1276b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 1277b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 1278b591480bSJ.Bruce Fields }, 1279b591480bSJ.Bruce Fields [OP_OPEN] = { 1280b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 128168d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1282b001a1b6SBenny Halevy .op_name = "OP_OPEN", 1283b591480bSJ.Bruce Fields }, 1284b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 1285b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 1286b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 1287b591480bSJ.Bruce Fields }, 1288b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 1289b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 1290b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 1291b591480bSJ.Bruce Fields }, 1292b591480bSJ.Bruce Fields [OP_PUTFH] = { 1293b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 129468d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 129568d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1296b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 1297b591480bSJ.Bruce Fields }, 1298eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 1299a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 130068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 130168d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1302b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 1303eeac294eSJ.Bruce Fields }, 1304b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 1305b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 130668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 130768d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1308b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 1309b591480bSJ.Bruce Fields }, 1310b591480bSJ.Bruce Fields [OP_READ] = { 1311b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 1312b001a1b6SBenny Halevy .op_name = "OP_READ", 1313b591480bSJ.Bruce Fields }, 1314b591480bSJ.Bruce Fields [OP_READDIR] = { 1315b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 1316b001a1b6SBenny Halevy .op_name = "OP_READDIR", 1317b591480bSJ.Bruce Fields }, 1318b591480bSJ.Bruce Fields [OP_READLINK] = { 1319b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 1320b001a1b6SBenny Halevy .op_name = "OP_READLINK", 1321b591480bSJ.Bruce Fields }, 1322b591480bSJ.Bruce Fields [OP_REMOVE] = { 1323b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 1324b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 1325b591480bSJ.Bruce Fields }, 1326b591480bSJ.Bruce Fields [OP_RENAME] = { 1327b001a1b6SBenny Halevy .op_name = "OP_RENAME", 1328b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 1329b591480bSJ.Bruce Fields }, 1330b591480bSJ.Bruce Fields [OP_RENEW] = { 1331b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 133227d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1333b001a1b6SBenny Halevy .op_name = "OP_RENEW", 1334b591480bSJ.Bruce Fields }, 1335b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 1336b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 133768d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 133868d93184SJ. Bruce Fields | OP_IS_PUTFH_LIKE, 1339b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 1340b591480bSJ.Bruce Fields }, 1341b591480bSJ.Bruce Fields [OP_SAVEFH] = { 1342b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 134368d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1344b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 1345b591480bSJ.Bruce Fields }, 1346dcb488a3SAndy Adamson [OP_SECINFO] = { 1347dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 134868d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1349b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 1350dcb488a3SAndy Adamson }, 1351b591480bSJ.Bruce Fields [OP_SETATTR] = { 1352b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 1353b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 1354b591480bSJ.Bruce Fields }, 1355b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 1356b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 135727d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1358b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 1359b591480bSJ.Bruce Fields }, 1360b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 1361b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 136227d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1363b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 1364b591480bSJ.Bruce Fields }, 1365b591480bSJ.Bruce Fields [OP_VERIFY] = { 1366b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 1367b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 1368b591480bSJ.Bruce Fields }, 1369b591480bSJ.Bruce Fields [OP_WRITE] = { 1370b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 1371b001a1b6SBenny Halevy .op_name = "OP_WRITE", 1372b591480bSJ.Bruce Fields }, 1373b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 1374b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 137527d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1376b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 1377b591480bSJ.Bruce Fields }, 1378069b6ad4SAndy Adamson 1379069b6ad4SAndy Adamson /* NFSv4.1 operations */ 1380069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 1381069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 1382f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1383069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 1384069b6ad4SAndy Adamson }, 13851d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 13861d1bc8f2SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, 13871d1bc8f2SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 13881d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 13891d1bc8f2SJ. Bruce Fields }, 1390069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 1391069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 1392f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1393069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 1394069b6ad4SAndy Adamson }, 1395069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 1396069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 1397f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1398069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 1399069b6ad4SAndy Adamson }, 1400069b6ad4SAndy Adamson [OP_SEQUENCE] = { 1401069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 1402f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1403069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 1404069b6ad4SAndy Adamson }, 1405094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 1406094b5d74SBenny Halevy .op_func = NULL, 1407094b5d74SBenny Halevy .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1408094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 1409094b5d74SBenny Halevy }, 14104dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 14114dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 14124dc6ec00SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH, 14134dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 14144dc6ec00SJ. Bruce Fields }, 141504f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 141604f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 141768d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 141804f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 141904f4ad16SJ. Bruce Fields }, 1420*17456804SBryan Schumaker [OP_TEST_STATEID] = { 1421*17456804SBryan Schumaker .op_func = (nfsd4op_func)nfsd4_test_stateid, 1422*17456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 1423*17456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 1424*17456804SBryan Schumaker }, 1425e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 1426e1ca12dfSBryan Schumaker .op_func = (nfsd4op_func)nfsd4_free_stateid, 1427e1ca12dfSBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 1428e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 1429e1ca12dfSBryan Schumaker }, 1430b591480bSJ.Bruce Fields }; 1431b591480bSJ.Bruce Fields 1432f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 1433b001a1b6SBenny Halevy { 1434b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 1435b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 1436b001a1b6SBenny Halevy return "unknown_operation"; 1437b001a1b6SBenny Halevy } 1438b001a1b6SBenny Halevy 14391da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 14401da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 14411da177e4SLinus Torvalds 14421da177e4SLinus Torvalds /* 14431da177e4SLinus Torvalds * TODO: At the present time, the NFSv4 server does not do XID caching 14441da177e4SLinus Torvalds * of requests. Implementing XID caching would not be a serious problem, 14451da177e4SLinus Torvalds * although it would require a mild change in interfaces since one 14461da177e4SLinus Torvalds * doesn't know whether an NFSv4 request is idempotent until after the 14471da177e4SLinus Torvalds * XDR decode. However, XID caching totally confuses pynfs (Peter 14481da177e4SLinus Torvalds * Astrand's regression testsuite for NFSv4 servers), which reuses 14491da177e4SLinus Torvalds * XID's liberally, so I've left it unimplemented until pynfs generates 14501da177e4SLinus Torvalds * better XID's. 14511da177e4SLinus Torvalds */ 14521da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 14530a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 14540a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_null, 14550a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 14560a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 14570a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 14580a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 14590a93a47fSYu Zhiguo .pc_xdrressize = 1, 14600a93a47fSYu Zhiguo }, 14610a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 14620a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_compound, 14630a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 14640a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 14650a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 14660a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 14670a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 14680a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 14690a93a47fSYu Zhiguo }, 14701da177e4SLinus Torvalds }; 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 14731da177e4SLinus Torvalds .vs_vers = 4, 14741da177e4SLinus Torvalds .vs_nproc = 2, 14751da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 14761da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 14771da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 14781da177e4SLinus Torvalds }; 14791da177e4SLinus Torvalds 14801da177e4SLinus Torvalds /* 14811da177e4SLinus Torvalds * Local variables: 14821da177e4SLinus Torvalds * c-basic-offset: 8 14831da177e4SLinus Torvalds * End: 14841da177e4SLinus Torvalds */ 1485