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 1991da177e4SLinus Torvalds * in NFSv4 as in v3. 2001da177e4SLinus Torvalds */ 2011da177e4SLinus Torvalds status = nfsd_create_v3(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); 4068837abcaSMiklos Szeredi return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 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); 765dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 766dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 767dcb488a3SAndy Adamson &exp, &dentry); 768dcb488a3SAndy Adamson if (err) 769dcb488a3SAndy Adamson return err; 770dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 771dcb488a3SAndy Adamson exp_put(exp); 772dcb488a3SAndy Adamson err = nfserr_noent; 773dcb488a3SAndy Adamson } else 774dcb488a3SAndy Adamson secinfo->si_exp = exp; 775dcb488a3SAndy Adamson dput(dentry); 77656560b9aSJ. Bruce Fields if (cstate->minorversion) 77756560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 77856560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 779dcb488a3SAndy Adamson return err; 780dcb488a3SAndy Adamson } 781dcb488a3SAndy Adamson 782dcb488a3SAndy Adamson static __be32 783*04f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 784*04f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 785*04f4ad16SJ. Bruce Fields { 786*04f4ad16SJ. Bruce Fields __be32 err; 787*04f4ad16SJ. Bruce Fields 788*04f4ad16SJ. Bruce Fields switch (sin->sin_style) { 789*04f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 790*04f4ad16SJ. Bruce Fields break; 791*04f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 792*04f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 793*04f4ad16SJ. Bruce Fields if (err) 794*04f4ad16SJ. Bruce Fields return err; 795*04f4ad16SJ. Bruce Fields break; 796*04f4ad16SJ. Bruce Fields default: 797*04f4ad16SJ. Bruce Fields return nfserr_inval; 798*04f4ad16SJ. Bruce Fields } 799*04f4ad16SJ. Bruce Fields exp_get(cstate->current_fh.fh_export); 800*04f4ad16SJ. Bruce Fields sin->sin_exp = cstate->current_fh.fh_export; 801*04f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 802*04f4ad16SJ. Bruce Fields return nfs_ok; 803*04f4ad16SJ. Bruce Fields } 804*04f4ad16SJ. Bruce Fields 805*04f4ad16SJ. Bruce Fields static __be32 806ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 807ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 8081da177e4SLinus Torvalds { 809b37ad28bSAl Viro __be32 status = nfs_ok; 8101da177e4SLinus Torvalds 8111da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 8121da177e4SLinus Torvalds nfs4_lock_state(); 813dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, 8146150ef0dSJ. Bruce Fields &setattr->sa_stateid, WR_STATE, NULL); 8151da177e4SLinus Torvalds nfs4_unlock_state(); 816375c5547SJ. Bruce Fields if (status) { 8173e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 818375c5547SJ. Bruce Fields return status; 819375c5547SJ. Bruce Fields } 8201da177e4SLinus Torvalds } 82118f335afSDave Hansen status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt); 82218f335afSDave Hansen if (status) 82318f335afSDave Hansen return status; 8241da177e4SLinus Torvalds status = nfs_ok; 8253c8e0316SYu Zhiguo 8263c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 8273c8e0316SYu Zhiguo nfsd_attrmask); 8283c8e0316SYu Zhiguo if (status) 8293c8e0316SYu Zhiguo goto out; 8303c8e0316SYu Zhiguo 8311da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 832ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 833ca364317SJ.Bruce Fields setattr->sa_acl); 8341da177e4SLinus Torvalds if (status) 83518f335afSDave Hansen goto out; 836ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 8371da177e4SLinus Torvalds 0, (time_t)0); 83818f335afSDave Hansen out: 83918f335afSDave Hansen mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt); 8401da177e4SLinus Torvalds return status; 8411da177e4SLinus Torvalds } 8421da177e4SLinus Torvalds 8437191155bSJ.Bruce Fields static __be32 844ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 845ca364317SJ.Bruce Fields struct nfsd4_write *write) 8461da177e4SLinus Torvalds { 8471da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 8481da177e4SLinus Torvalds struct file *filp = NULL; 8491da177e4SLinus Torvalds u32 *p; 850b37ad28bSAl Viro __be32 status = nfs_ok; 85131dec253SDavid Shaw unsigned long cnt; 8521da177e4SLinus Torvalds 8531da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 8541da177e4SLinus Torvalds 8551da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 8561da177e4SLinus Torvalds return nfserr_inval; 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds nfs4_lock_state(); 859dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp); 8607e06b7f9SNeilBrown if (filp) 8617e06b7f9SNeilBrown get_file(filp); 8621da177e4SLinus Torvalds nfs4_unlock_state(); 8631da177e4SLinus Torvalds 864375c5547SJ. Bruce Fields if (status) { 865375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 866375c5547SJ. Bruce Fields return status; 867375c5547SJ. Bruce Fields } 868375c5547SJ. Bruce Fields 86931dec253SDavid Shaw cnt = write->wr_buflen; 8701da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 8711da177e4SLinus Torvalds p = (u32 *)write->wr_verifier.data; 8721da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 8731da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 8741da177e4SLinus Torvalds 875ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 876ca364317SJ.Bruce Fields write->wr_offset, rqstp->rq_vec, write->wr_vlen, 87731dec253SDavid Shaw &cnt, &write->wr_how_written); 8787e06b7f9SNeilBrown if (filp) 8797e06b7f9SNeilBrown fput(filp); 8801da177e4SLinus Torvalds 88131dec253SDavid Shaw write->wr_bytes_written = cnt; 88231dec253SDavid Shaw 8831da177e4SLinus Torvalds if (status == nfserr_symlink) 8841da177e4SLinus Torvalds status = nfserr_inval; 8851da177e4SLinus Torvalds return status; 8861da177e4SLinus Torvalds } 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 8891da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 8901da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 8911da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 8921da177e4SLinus Torvalds */ 893b37ad28bSAl Viro static __be32 894c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 895ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 8961da177e4SLinus Torvalds { 8972ebbc012SAl Viro __be32 *buf, *p; 8981da177e4SLinus Torvalds int count; 899b37ad28bSAl Viro __be32 status; 9001da177e4SLinus Torvalds 9018837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 9021da177e4SLinus Torvalds if (status) 9031da177e4SLinus Torvalds return status; 9041da177e4SLinus Torvalds 9053c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 9063c8e0316SYu Zhiguo if (status) 9073c8e0316SYu Zhiguo return status; 9083c8e0316SYu Zhiguo 9091da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 9101da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 9111da177e4SLinus Torvalds return nfserr_inval; 9121da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 9131da177e4SLinus Torvalds return nfserr_inval; 9141da177e4SLinus Torvalds 9151da177e4SLinus Torvalds /* count in words: 9161da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 9171da177e4SLinus Torvalds */ 9181da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 9191da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 9201da177e4SLinus Torvalds if (!buf) 9211da177e4SLinus Torvalds return nfserr_resource; 9221da177e4SLinus Torvalds 923ca364317SJ.Bruce Fields status = nfsd4_encode_fattr(&cstate->current_fh, 924ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 925ca364317SJ.Bruce Fields cstate->current_fh.fh_dentry, buf, 9261da177e4SLinus Torvalds &count, verify->ve_bmval, 927406a7ea9SFrank Filz rqstp, 0); 9281da177e4SLinus Torvalds 9291da177e4SLinus Torvalds /* this means that nfsd4_encode_fattr() ran out of space */ 9301da177e4SLinus Torvalds if (status == nfserr_resource && count == 0) 9311da177e4SLinus Torvalds status = nfserr_not_same; 9321da177e4SLinus Torvalds if (status) 9331da177e4SLinus Torvalds goto out_kfree; 9341da177e4SLinus Torvalds 93595ec28cdSBenny Halevy /* skip bitmap */ 93695ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 9371da177e4SLinus Torvalds status = nfserr_not_same; 9381da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 9391da177e4SLinus Torvalds goto out_kfree; 9401da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 9411da177e4SLinus Torvalds status = nfserr_same; 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds out_kfree: 9441da177e4SLinus Torvalds kfree(buf); 9451da177e4SLinus Torvalds return status; 9461da177e4SLinus Torvalds } 9471da177e4SLinus Torvalds 948c954e2a5SJ.Bruce Fields static __be32 949c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 950c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 951c954e2a5SJ.Bruce Fields { 952c954e2a5SJ.Bruce Fields __be32 status; 953c954e2a5SJ.Bruce Fields 954c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 955c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 956c954e2a5SJ.Bruce Fields } 957c954e2a5SJ.Bruce Fields 958c954e2a5SJ.Bruce Fields static __be32 959c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 960c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 961c954e2a5SJ.Bruce Fields { 962c954e2a5SJ.Bruce Fields __be32 status; 963c954e2a5SJ.Bruce Fields 964c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 965c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 966c954e2a5SJ.Bruce Fields } 967c954e2a5SJ.Bruce Fields 9681da177e4SLinus Torvalds /* 9691da177e4SLinus Torvalds * NULL call. 9701da177e4SLinus Torvalds */ 9717111c66eSAl Viro static __be32 9721da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 9731da177e4SLinus Torvalds { 9741da177e4SLinus Torvalds return nfs_ok; 9751da177e4SLinus Torvalds } 9761da177e4SLinus Torvalds 977e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 978e2b20950SShankar Anand { 979e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 980e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 981e2b20950SShankar Anand } 982e2b20950SShankar Anand 983b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 984b591480bSJ.Bruce Fields void *); 985f9bb94c4SAndy Adamson enum nfsd4_op_flags { 986f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 987f9bb94c4SAndy Adamson ALLOWED_ON_ABSENT_FS = 2 << 0, /* ops processed on absent fs */ 988f9bb94c4SAndy Adamson ALLOWED_AS_FIRST_OP = 3 << 0, /* ops reqired first in compound */ 989f9bb94c4SAndy Adamson }; 990b591480bSJ.Bruce Fields 991b591480bSJ.Bruce Fields struct nfsd4_operation { 992b591480bSJ.Bruce Fields nfsd4op_func op_func; 993b591480bSJ.Bruce Fields u32 op_flags; 994b001a1b6SBenny Halevy char *op_name; 995b591480bSJ.Bruce Fields }; 996b591480bSJ.Bruce Fields 997b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 998b591480bSJ.Bruce Fields 999f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1000b001a1b6SBenny Halevy 10011da177e4SLinus Torvalds /* 100257716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1003f9bb94c4SAndy Adamson * 100457716355SJ. Bruce Fields * Also note, enforced elsewhere: 100557716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 100657716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 100757716355SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound 100857716355SJ. Bruce Fields * (Will be enforced in nfsd4_bind_conn_to_session().) 100957716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 101057716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 101157716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1012f9bb94c4SAndy Adamson */ 101357716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1014f9bb94c4SAndy Adamson { 1015f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 101657716355SJ. Bruce Fields 101757716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 101857716355SJ. Bruce Fields if (args->minorversion == 0) 101957716355SJ. Bruce Fields return nfs_ok; 102057716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 102157716355SJ. Bruce Fields if (args->opcnt == 0) 102257716355SJ. Bruce Fields return nfs_ok; 102357716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 102457716355SJ. Bruce Fields return nfs_ok; 102557716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 102657716355SJ. Bruce Fields return nfserr_op_not_in_session; 102757716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 102857716355SJ. Bruce Fields return nfs_ok; 102957716355SJ. Bruce Fields if (args->opcnt != 1) 103057716355SJ. Bruce Fields return nfserr_not_only_op; 103157716355SJ. Bruce Fields return nfs_ok; 1032f9bb94c4SAndy Adamson } 1033f9bb94c4SAndy Adamson 1034f9bb94c4SAndy Adamson /* 10351da177e4SLinus Torvalds * COMPOUND call. 10361da177e4SLinus Torvalds */ 10377111c66eSAl Viro static __be32 10381da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 10391da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 10401da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 10411da177e4SLinus Torvalds { 10421da177e4SLinus Torvalds struct nfsd4_op *op; 1043b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1044e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 1045e5710199SJ.Bruce Fields int slack_bytes; 1046b37ad28bSAl Viro __be32 status; 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds resp->xbuf = &rqstp->rq_res; 1049e354d571SAndy Adamson resp->p = rqstp->rq_res.head[0].iov_base + 1050e354d571SAndy Adamson rqstp->rq_res.head[0].iov_len; 10511da177e4SLinus Torvalds resp->tagp = resp->p; 10521da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 10531da177e4SLinus Torvalds resp->p += 2 + XDR_QUADLEN(args->taglen); 10541da177e4SLinus Torvalds resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE; 10551da177e4SLinus Torvalds resp->taglen = args->taglen; 10561da177e4SLinus Torvalds resp->tag = args->tag; 10571da177e4SLinus Torvalds resp->opcnt = 0; 10581da177e4SLinus Torvalds resp->rqstp = rqstp; 1059d87a8adeSAndy Adamson resp->cstate.minorversion = args->minorversion; 1060e354d571SAndy Adamson resp->cstate.replay_owner = NULL; 106126c0c75eSJ. Bruce Fields resp->cstate.session = NULL; 1062e354d571SAndy Adamson fh_init(&resp->cstate.current_fh, NFS4_FHSIZE); 1063e354d571SAndy Adamson fh_init(&resp->cstate.save_fh, NFS4_FHSIZE); 10648ff30fa4SNeilBrown /* 10658ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 10668ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 10678ff30fa4SNeilBrown */ 10688ff30fa4SNeilBrown rqstp->rq_usedeferral = 0; 10691da177e4SLinus Torvalds 10701da177e4SLinus Torvalds /* 10711da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 10721da177e4SLinus Torvalds */ 10731da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 10748daf220aSBenny Halevy if (args->minorversion > nfsd_supported_minorversion) 10751da177e4SLinus Torvalds goto out; 10761da177e4SLinus Torvalds 107757716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 107857716355SJ. Bruce Fields if (status) { 1079f9bb94c4SAndy Adamson op = &args->ops[0]; 108057716355SJ. Bruce Fields op->status = status; 1081f9bb94c4SAndy Adamson goto encode_op; 1082f9bb94c4SAndy Adamson } 1083f9bb94c4SAndy Adamson 10841da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 10851da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 10861da177e4SLinus Torvalds 1087b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1088b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1089b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 10901da177e4SLinus Torvalds /* 10911da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 10921da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 10931da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 10941da177e4SLinus Torvalds */ 10951da177e4SLinus Torvalds if (op->status) 10961da177e4SLinus Torvalds goto encode_op; 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds /* We must be able to encode a successful response to 10991da177e4SLinus Torvalds * this operation, with enough room left over to encode a 11001da177e4SLinus Torvalds * failed response to the next operation. If we don't 11011da177e4SLinus Torvalds * have enough room, fail with ERR_RESOURCE. 11021da177e4SLinus Torvalds */ 1103e5710199SJ.Bruce Fields slack_bytes = (char *)resp->end - (char *)resp->p; 1104e5710199SJ.Bruce Fields if (slack_bytes < COMPOUND_SLACK_SPACE 1105e5710199SJ.Bruce Fields + COMPOUND_ERR_SLACK_SPACE) { 1106e5710199SJ.Bruce Fields BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE); 11071da177e4SLinus Torvalds op->status = nfserr_resource; 11081da177e4SLinus Torvalds goto encode_op; 11091da177e4SLinus Torvalds } 11101da177e4SLinus Torvalds 1111b591480bSJ.Bruce Fields opdesc = &nfsd4_ops[op->opnum]; 1112b591480bSJ.Bruce Fields 1113ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) { 111427d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 11151da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 11161da177e4SLinus Torvalds goto encode_op; 11171da177e4SLinus Torvalds } 1118eeac294eSJ.Bruce Fields } else if (cstate->current_fh.fh_export->ex_fslocs.migrated && 1119eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 112042ca0993SJ.Bruce Fields op->status = nfserr_moved; 112142ca0993SJ.Bruce Fields goto encode_op; 112242ca0993SJ.Bruce Fields } 1123b591480bSJ.Bruce Fields 1124b591480bSJ.Bruce Fields if (opdesc->op_func) 1125b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 1126b591480bSJ.Bruce Fields else 11271da177e4SLinus Torvalds BUG_ON(op->status == nfs_ok); 11281da177e4SLinus Torvalds 11291da177e4SLinus Torvalds encode_op: 113049557cc7SAndy Adamson /* Only from SEQUENCE */ 1131da3846a2SAndy Adamson if (resp->cstate.status == nfserr_replay_cache) { 1132da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1133da3846a2SAndy Adamson status = op->status; 1134da3846a2SAndy Adamson goto out; 1135da3846a2SAndy Adamson } 1136a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1137a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 11381da177e4SLinus Torvalds nfsd4_encode_replay(resp, op); 11391da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 11401da177e4SLinus Torvalds } else { 11411da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 11421da177e4SLinus Torvalds status = op->status; 11431da177e4SLinus Torvalds } 11440407717dSBenny Halevy 11450407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 11460407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 11470407717dSBenny Halevy be32_to_cpu(status)); 11480407717dSBenny Halevy 1149a4f1706aSJ.Bruce Fields if (cstate->replay_owner) { 1150a4f1706aSJ.Bruce Fields nfs4_put_stateowner(cstate->replay_owner); 1151a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 11521da177e4SLinus Torvalds } 11537e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 11547e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 11557e06b7f9SNeilBrown fput(op->u.read.rd_filp); 1156e2b20950SShankar Anand 1157e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 11581da177e4SLinus Torvalds } 11592f425878SAndy Adamson if (!rqstp->rq_usedeferral && status == nfserr_dropit) { 11602f425878SAndy Adamson dprintk("%s Dropit - send NFS4ERR_DELAY\n", __func__); 11612f425878SAndy Adamson status = nfserr_jukebox; 11622f425878SAndy Adamson } 11631da177e4SLinus Torvalds 1164da3846a2SAndy Adamson resp->cstate.status = status; 1165e354d571SAndy Adamson fh_put(&resp->cstate.current_fh); 1166e354d571SAndy Adamson fh_put(&resp->cstate.save_fh); 1167e354d571SAndy Adamson BUG_ON(resp->cstate.replay_owner); 11681da177e4SLinus Torvalds out: 11691da177e4SLinus Torvalds nfsd4_release_compoundargs(args); 11702f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 11712f425878SAndy Adamson rqstp->rq_usedeferral = 1; 11723b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 11731da177e4SLinus Torvalds return status; 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds 117620766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1177b591480bSJ.Bruce Fields [OP_ACCESS] = { 1178b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1179b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1180b591480bSJ.Bruce Fields }, 1181b591480bSJ.Bruce Fields [OP_CLOSE] = { 1182b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 1183b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 1184b591480bSJ.Bruce Fields }, 1185b591480bSJ.Bruce Fields [OP_COMMIT] = { 1186b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 1187b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 1188b591480bSJ.Bruce Fields }, 1189b591480bSJ.Bruce Fields [OP_CREATE] = { 1190b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1191b001a1b6SBenny Halevy .op_name = "OP_CREATE", 1192b591480bSJ.Bruce Fields }, 1193b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1194b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 1195b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 1196b591480bSJ.Bruce Fields }, 1197b591480bSJ.Bruce Fields [OP_GETATTR] = { 1198b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 1199eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 1200b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 1201b591480bSJ.Bruce Fields }, 1202b591480bSJ.Bruce Fields [OP_GETFH] = { 1203b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 1204b001a1b6SBenny Halevy .op_name = "OP_GETFH", 1205b591480bSJ.Bruce Fields }, 1206b591480bSJ.Bruce Fields [OP_LINK] = { 1207b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 1208b001a1b6SBenny Halevy .op_name = "OP_LINK", 1209b591480bSJ.Bruce Fields }, 1210b591480bSJ.Bruce Fields [OP_LOCK] = { 1211b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 1212b001a1b6SBenny Halevy .op_name = "OP_LOCK", 1213b591480bSJ.Bruce Fields }, 1214b591480bSJ.Bruce Fields [OP_LOCKT] = { 1215b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 1216b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 1217b591480bSJ.Bruce Fields }, 1218b591480bSJ.Bruce Fields [OP_LOCKU] = { 1219b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 1220b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 1221b591480bSJ.Bruce Fields }, 1222b591480bSJ.Bruce Fields [OP_LOOKUP] = { 1223b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 1224b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 1225b591480bSJ.Bruce Fields }, 1226b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 1227b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 1228b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 1229b591480bSJ.Bruce Fields }, 1230b591480bSJ.Bruce Fields [OP_NVERIFY] = { 1231b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 1232b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 1233b591480bSJ.Bruce Fields }, 1234b591480bSJ.Bruce Fields [OP_OPEN] = { 1235b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 1236b001a1b6SBenny Halevy .op_name = "OP_OPEN", 1237b591480bSJ.Bruce Fields }, 1238b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 1239b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 1240b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 1241b591480bSJ.Bruce Fields }, 1242b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 1243b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 1244b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 1245b591480bSJ.Bruce Fields }, 1246b591480bSJ.Bruce Fields [OP_PUTFH] = { 1247b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 124827d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1249b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 1250b591480bSJ.Bruce Fields }, 1251eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 1252a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 125327d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1254b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 1255eeac294eSJ.Bruce Fields }, 1256b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 1257b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 125827d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1259b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 1260b591480bSJ.Bruce Fields }, 1261b591480bSJ.Bruce Fields [OP_READ] = { 1262b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 1263b001a1b6SBenny Halevy .op_name = "OP_READ", 1264b591480bSJ.Bruce Fields }, 1265b591480bSJ.Bruce Fields [OP_READDIR] = { 1266b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 1267b001a1b6SBenny Halevy .op_name = "OP_READDIR", 1268b591480bSJ.Bruce Fields }, 1269b591480bSJ.Bruce Fields [OP_READLINK] = { 1270b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 1271b001a1b6SBenny Halevy .op_name = "OP_READLINK", 1272b591480bSJ.Bruce Fields }, 1273b591480bSJ.Bruce Fields [OP_REMOVE] = { 1274b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 1275b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 1276b591480bSJ.Bruce Fields }, 1277b591480bSJ.Bruce Fields [OP_RENAME] = { 1278b001a1b6SBenny Halevy .op_name = "OP_RENAME", 1279b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 1280b591480bSJ.Bruce Fields }, 1281b591480bSJ.Bruce Fields [OP_RENEW] = { 1282b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 128327d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1284b001a1b6SBenny Halevy .op_name = "OP_RENEW", 1285b591480bSJ.Bruce Fields }, 1286b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 1287b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 128827d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1289b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 1290b591480bSJ.Bruce Fields }, 1291b591480bSJ.Bruce Fields [OP_SAVEFH] = { 1292b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 1293b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 1294b591480bSJ.Bruce Fields }, 1295dcb488a3SAndy Adamson [OP_SECINFO] = { 1296dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 1297b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 1298dcb488a3SAndy Adamson }, 1299b591480bSJ.Bruce Fields [OP_SETATTR] = { 1300b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 1301b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 1302b591480bSJ.Bruce Fields }, 1303b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 1304b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 130527d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1306b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 1307b591480bSJ.Bruce Fields }, 1308b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 1309b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 131027d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1311b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 1312b591480bSJ.Bruce Fields }, 1313b591480bSJ.Bruce Fields [OP_VERIFY] = { 1314b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 1315b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 1316b591480bSJ.Bruce Fields }, 1317b591480bSJ.Bruce Fields [OP_WRITE] = { 1318b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 1319b001a1b6SBenny Halevy .op_name = "OP_WRITE", 1320b591480bSJ.Bruce Fields }, 1321b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 1322b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 132327d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1324b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 1325b591480bSJ.Bruce Fields }, 1326069b6ad4SAndy Adamson 1327069b6ad4SAndy Adamson /* NFSv4.1 operations */ 1328069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 1329069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 1330f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1331069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 1332069b6ad4SAndy Adamson }, 1333069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 1334069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 1335f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1336069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 1337069b6ad4SAndy Adamson }, 1338069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 1339069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 1340f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1341069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 1342069b6ad4SAndy Adamson }, 1343069b6ad4SAndy Adamson [OP_SEQUENCE] = { 1344069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 1345f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1346069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 1347069b6ad4SAndy Adamson }, 13484dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 13494dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 13504dc6ec00SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH, 13514dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 13524dc6ec00SJ. Bruce Fields }, 1353*04f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 1354*04f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 1355*04f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 1356*04f4ad16SJ. Bruce Fields }, 1357b591480bSJ.Bruce Fields }; 1358b591480bSJ.Bruce Fields 1359f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 1360b001a1b6SBenny Halevy { 1361b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 1362b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 1363b001a1b6SBenny Halevy return "unknown_operation"; 1364b001a1b6SBenny Halevy } 1365b001a1b6SBenny Halevy 13661da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 13671da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 13681da177e4SLinus Torvalds 13691da177e4SLinus Torvalds /* 13701da177e4SLinus Torvalds * TODO: At the present time, the NFSv4 server does not do XID caching 13711da177e4SLinus Torvalds * of requests. Implementing XID caching would not be a serious problem, 13721da177e4SLinus Torvalds * although it would require a mild change in interfaces since one 13731da177e4SLinus Torvalds * doesn't know whether an NFSv4 request is idempotent until after the 13741da177e4SLinus Torvalds * XDR decode. However, XID caching totally confuses pynfs (Peter 13751da177e4SLinus Torvalds * Astrand's regression testsuite for NFSv4 servers), which reuses 13761da177e4SLinus Torvalds * XID's liberally, so I've left it unimplemented until pynfs generates 13771da177e4SLinus Torvalds * better XID's. 13781da177e4SLinus Torvalds */ 13791da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 13800a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 13810a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_null, 13820a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 13830a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 13840a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 13850a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 13860a93a47fSYu Zhiguo .pc_xdrressize = 1, 13870a93a47fSYu Zhiguo }, 13880a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 13890a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_compound, 13900a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 13910a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 13920a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 13930a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 13940a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 13950a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 13960a93a47fSYu Zhiguo }, 13971da177e4SLinus Torvalds }; 13981da177e4SLinus Torvalds 13991da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 14001da177e4SLinus Torvalds .vs_vers = 4, 14011da177e4SLinus Torvalds .vs_nproc = 2, 14021da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 14031da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 14041da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 14051da177e4SLinus Torvalds }; 14061da177e4SLinus Torvalds 14071da177e4SLinus Torvalds /* 14081da177e4SLinus Torvalds * Local variables: 14091da177e4SLinus Torvalds * c-basic-offset: 8 14101da177e4SLinus Torvalds * End: 14111da177e4SLinus Torvalds */ 1412