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 3858e7b33aSMi Jinlong #include "idmap.h" 399a74af21SBoaz Harrosh #include "cache.h" 409a74af21SBoaz Harrosh #include "xdr4.h" 410a3adadeSJ. Bruce Fields #include "vfs.h" 428b70484cSTigran Mkrtchyan #include "current_stateid.h" 433320fef1SStanislav Kinsbursky #include "netns.h" 444ac7249eSChristoph Hellwig #include "acl.h" 451da177e4SLinus Torvalds 4618032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 4718032ca0SDavid Quigley #include <linux/security.h> 4818032ca0SDavid Quigley 4918032ca0SDavid Quigley static inline void 5018032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 5118032ca0SDavid Quigley { 5218032ca0SDavid Quigley struct inode *inode = resfh->fh_dentry->d_inode; 5318032ca0SDavid Quigley int status; 5418032ca0SDavid Quigley 5518032ca0SDavid Quigley mutex_lock(&inode->i_mutex); 5618032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 5718032ca0SDavid Quigley label->data, label->len); 5818032ca0SDavid Quigley mutex_unlock(&inode->i_mutex); 5918032ca0SDavid Quigley 6018032ca0SDavid Quigley if (status) 6118032ca0SDavid Quigley /* 6218032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 6318032ca0SDavid Quigley * already have created a new file, so it may be too 6418032ca0SDavid Quigley * late. For now this seems the least of evils: 6518032ca0SDavid Quigley */ 6618032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 6718032ca0SDavid Quigley 6818032ca0SDavid Quigley return; 6918032ca0SDavid Quigley } 7018032ca0SDavid Quigley #else 7118032ca0SDavid Quigley static inline void 7218032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7318032ca0SDavid Quigley { } 7418032ca0SDavid Quigley #endif 7518032ca0SDavid Quigley 761da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 771da177e4SLinus Torvalds 783c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 793c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 803c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 813c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 823c8e0316SYu Zhiguo }; 833c8e0316SYu Zhiguo 843c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 853c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 863c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 873c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 883c8e0316SYu Zhiguo }; 893c8e0316SYu Zhiguo 903c8e0316SYu Zhiguo static __be32 913c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 923c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 933c8e0316SYu Zhiguo { 943c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 953c8e0316SYu Zhiguo 963c8e0316SYu Zhiguo /* 973c8e0316SYu Zhiguo * Check about attributes are supported by the NFSv4 server or not. 983c8e0316SYu Zhiguo * According to spec, unsupported attributes return ERR_ATTRNOTSUPP. 993c8e0316SYu Zhiguo */ 1003c8e0316SYu Zhiguo if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) || 1013c8e0316SYu Zhiguo (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) || 1023c8e0316SYu Zhiguo (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion))) 1033c8e0316SYu Zhiguo return nfserr_attrnotsupp; 1043c8e0316SYu Zhiguo 1053c8e0316SYu Zhiguo /* 106a06b1261STrond Myklebust * Check FATTR4_WORD0_ACL can be supported 1073c8e0316SYu Zhiguo * in current environment or not. 1083c8e0316SYu Zhiguo */ 1093c8e0316SYu Zhiguo if (bmval[0] & FATTR4_WORD0_ACL) { 1103c8e0316SYu Zhiguo if (!IS_POSIXACL(dentry->d_inode)) 1113c8e0316SYu Zhiguo return nfserr_attrnotsupp; 1123c8e0316SYu Zhiguo } 1133c8e0316SYu Zhiguo 1143c8e0316SYu Zhiguo /* 1153c8e0316SYu Zhiguo * According to spec, read-only attributes return ERR_INVAL. 1163c8e0316SYu Zhiguo */ 1173c8e0316SYu Zhiguo if (writable) { 1183c8e0316SYu Zhiguo if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) || 1193c8e0316SYu Zhiguo (bmval[2] & ~writable[2])) 1203c8e0316SYu Zhiguo return nfserr_inval; 1213c8e0316SYu Zhiguo } 1223c8e0316SYu Zhiguo 1233c8e0316SYu Zhiguo return nfs_ok; 1243c8e0316SYu Zhiguo } 1253c8e0316SYu Zhiguo 1263c8e0316SYu Zhiguo static __be32 1273c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1283c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1293c8e0316SYu Zhiguo { 1303c8e0316SYu Zhiguo __be32 status = nfs_ok; 1313c8e0316SYu Zhiguo 1323c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1333c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1343c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1353c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1363c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1373c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1383c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1393c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1403c8e0316SYu Zhiguo } 1413c8e0316SYu Zhiguo 1423c8e0316SYu Zhiguo return status; 1433c8e0316SYu Zhiguo } 1443c8e0316SYu Zhiguo 1459208faf2SYu Zhiguo static int 1469208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1479208faf2SYu Zhiguo { 1489208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1499208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1509208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1519208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1529208faf2SYu Zhiguo } 1539208faf2SYu Zhiguo 1549208faf2SYu Zhiguo /* 1559208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1569208faf2SYu Zhiguo * in the returned attr bitmap. 1579208faf2SYu Zhiguo */ 1589208faf2SYu Zhiguo static void 1599208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1609208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1619208faf2SYu Zhiguo { 1629208faf2SYu Zhiguo __be32 status; 1639208faf2SYu Zhiguo 1649208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1659208faf2SYu Zhiguo if (status) 1669208faf2SYu Zhiguo /* 1679208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1689208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1699208faf2SYu Zhiguo * So this seems the least of evils: 1709208faf2SYu Zhiguo */ 1719208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1729208faf2SYu Zhiguo } 1739208faf2SYu Zhiguo 1741da177e4SLinus Torvalds static inline void 1751da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1761da177e4SLinus Torvalds { 1771da177e4SLinus Torvalds fh_put(dst); 1781da177e4SLinus Torvalds dget(src->fh_dentry); 1791da177e4SLinus Torvalds if (src->fh_export) 1801da177e4SLinus Torvalds cache_get(&src->fh_export->h); 1811da177e4SLinus Torvalds *dst = *src; 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 184b37ad28bSAl Viro static __be32 185dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1861da177e4SLinus Torvalds { 187b37ad28bSAl Viro __be32 status; 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds if (open->op_truncate && 1901da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1911da177e4SLinus Torvalds return nfserr_inval; 1921da177e4SLinus Torvalds 193a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 194a043226bSJ. Bruce Fields 1951da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 1968837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 1979801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 1988837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 19957ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 2008837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds return status; 2051da177e4SLinus Torvalds } 2061da177e4SLinus Torvalds 207aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 208aadab6c6SJ. Bruce Fields { 209aadab6c6SJ. Bruce Fields umode_t mode = fh->fh_dentry->d_inode->i_mode; 210aadab6c6SJ. Bruce Fields 211aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 212aadab6c6SJ. Bruce Fields return nfs_ok; 213aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 214aadab6c6SJ. Bruce Fields return nfserr_isdir; 215aadab6c6SJ. Bruce Fields /* 216aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 217aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 218aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 219aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 220aadab6c6SJ. Bruce Fields * regular file. 221aadab6c6SJ. Bruce Fields */ 222aadab6c6SJ. Bruce Fields return nfserr_symlink; 223aadab6c6SJ. Bruce Fields } 224aadab6c6SJ. Bruce Fields 225bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2261da177e4SLinus Torvalds { 227bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 228bbc9c36cSJ. Bruce Fields return; 229bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 230bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 231bbc9c36cSJ. Bruce Fields } 232bbc9c36cSJ. Bruce Fields 233bbc9c36cSJ. Bruce Fields static __be32 234c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 235bbc9c36cSJ. Bruce Fields { 236bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 2377007c90fSNeil Brown int accmode; 238b37ad28bSAl Viro __be32 status; 2391da177e4SLinus Torvalds 240c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 241c0e6bee4SJ. Bruce Fields if (!*resfh) 24259deeb9eSJ. Bruce Fields return nfserr_jukebox; 243c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 2441da177e4SLinus Torvalds open->op_truncate = 0; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds if (open->op_create) { 24779fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 24879fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 24979fb54abSBenny Halevy * 25079fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 25179fb54abSBenny Halevy * Reply Cache | server | | 25279fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 25379fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 25479fb54abSBenny Halevy * | | | (SHOULD) 25579fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 25679fb54abSBenny Halevy * | | | (SHOULD NOT) 25779fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 25879fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 25979fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 26079fb54abSBenny Halevy */ 26179fb54abSBenny Halevy 2621da177e4SLinus Torvalds /* 2631da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 264ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2651da177e4SLinus Torvalds */ 266ac6721a1SMi Jinlong status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, 2671da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 268c0e6bee4SJ. Bruce Fields *resfh, open->op_createmode, 269749997e5SJeff Layton (u32 *)open->op_verf.data, 270856121b2SJ. Bruce Fields &open->op_truncate, &open->op_created); 271749997e5SJeff Layton 27218032ca0SDavid Quigley if (!status && open->op_label.len) 273c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 27418032ca0SDavid Quigley 27599f88726SJ. Bruce Fields /* 27699f88726SJ. Bruce Fields * Following rfc 3530 14.2.16, use the returned bitmask 27799f88726SJ. Bruce Fields * to indicate which attributes we used to store the 27899f88726SJ. Bruce Fields * verifier: 279749997e5SJeff Layton */ 280749997e5SJeff Layton if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0) 28199f88726SJ. Bruce Fields open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS | 282749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 2834335723eSJ. Bruce Fields } else 2844335723eSJ. Bruce Fields /* 2854335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 2864335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 2874335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 2884335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 2894335723eSJ. Bruce Fields */ 2901da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 291c0e6bee4SJ. Bruce Fields open->op_fname.data, open->op_fname.len, *resfh); 292aadab6c6SJ. Bruce Fields if (status) 293aadab6c6SJ. Bruce Fields goto out; 294c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 295af85852dSJ. Bruce Fields if (status) 296af85852dSJ. Bruce Fields goto out; 2971da177e4SLinus Torvalds 2989208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 299c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 3009208faf2SYu Zhiguo 301c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 3027007c90fSNeil Brown accmode = NFSD_MAY_NOP; 30389f6c336SJ. Bruce Fields if (open->op_created || 30489f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 3057007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 306c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 30741fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 308af85852dSJ. Bruce Fields out: 3091da177e4SLinus Torvalds return status; 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 312b37ad28bSAl Viro static __be32 313bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 3141da177e4SLinus Torvalds { 315bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 316b37ad28bSAl Viro __be32 status; 3179f415eb2SJ. Bruce Fields int accmode = 0; 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 3201da177e4SLinus Torvalds * set the change info 3211da177e4SLinus Torvalds */ 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 3241da177e4SLinus Torvalds 325bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 3281da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 3299f415eb2SJ. Bruce Fields /* 3309f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 3319f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 3329f415eb2SJ. Bruce Fields * should let it succeed now if possible. 3339f415eb2SJ. Bruce Fields * 3349f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 3359f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 3369f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 3379f415eb2SJ. Bruce Fields */ 3389f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 3399f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 3401da177e4SLinus Torvalds 3419f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds return status; 3441da177e4SLinus Torvalds } 3451da177e4SLinus Torvalds 34660adfc50SAndy Adamson static void 34760adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 34860adfc50SAndy Adamson { 34960adfc50SAndy Adamson struct nfsd4_sessionid *sid = 35060adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 35160adfc50SAndy Adamson 35260adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 35360adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 35460adfc50SAndy Adamson } 3551da177e4SLinus Torvalds 3567191155bSJ.Bruce Fields static __be32 357ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 358a4f1706aSJ.Bruce Fields struct nfsd4_open *open) 3591da177e4SLinus Torvalds { 360b37ad28bSAl Viro __be32 status; 361c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 3626668958fSAndy Adamson struct nfsd4_compoundres *resp; 3633320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3643320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 3656668958fSAndy Adamson 366fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3671da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 368fe0750e5SJ. Bruce Fields open->op_openowner); 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds /* This check required by spec. */ 3711da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3721da177e4SLinus Torvalds return nfserr_inval; 3731da177e4SLinus Torvalds 374856121b2SJ. Bruce Fields open->op_created = 0; 375ab1350b2SMi Jinlong /* 376ab1350b2SMi Jinlong * RFC5661 18.51.3 377ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 378ab1350b2SMi Jinlong */ 379ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 380a52d726bSJeff Layton !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, 381a52d726bSJeff Layton &cstate->session->se_client->cl_flags) && 382ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 383ab1350b2SMi Jinlong return nfserr_grace; 384ab1350b2SMi Jinlong 38560adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 38660adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 38760adfc50SAndy Adamson 3881da177e4SLinus Torvalds nfs4_lock_state(); 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3916668958fSAndy Adamson resp = rqstp->rq_resp; 3923320fef1SStanislav Kinsbursky status = nfsd4_process_open1(&resp->cstate, open, nn); 393a90b061cSAl Viro if (status == nfserr_replay_me) { 394fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 395ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 396a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 397a4773c08SJ. Bruce Fields &rp->rp_openfh); 3988837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3991da177e4SLinus Torvalds if (status) 4001da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 4011da177e4SLinus Torvalds " restoring previous filehandle\n"); 4021da177e4SLinus Torvalds else 403a90b061cSAl Viro status = nfserr_replay_me; 4041da177e4SLinus Torvalds } 4051da177e4SLinus Torvalds if (status) 4061da177e4SLinus Torvalds goto out; 4079d313b17SJ. Bruce Fields if (open->op_xdr_error) { 4089d313b17SJ. Bruce Fields status = open->op_xdr_error; 4099d313b17SJ. Bruce Fields goto out; 4109d313b17SJ. Bruce Fields } 411fb553c0fSJ. Bruce Fields 4123c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 4133c8e0316SYu Zhiguo if (status) 4143c8e0316SYu Zhiguo goto out; 4153c8e0316SYu Zhiguo 416fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 417fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 418cbd0d51aSJ. Bruce Fields status = nfserr_grace; 4193320fef1SStanislav Kinsbursky if (locks_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 420cbd0d51aSJ. Bruce Fields goto out; 421cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 4223320fef1SStanislav Kinsbursky if (!locks_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 423cbd0d51aSJ. Bruce Fields goto out; 424fb553c0fSJ. Bruce Fields 4251da177e4SLinus Torvalds switch (open->op_claim_type) { 4260dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4271da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 428c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4291da177e4SLinus Torvalds if (status) 4301da177e4SLinus Torvalds goto out; 4311da177e4SLinus Torvalds break; 4321da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 433dad1c067SJ. Bruce Fields open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 4343320fef1SStanislav Kinsbursky status = nfs4_check_open_reclaim(&open->op_clientid, 4353320fef1SStanislav Kinsbursky cstate->minorversion, 4363320fef1SStanislav Kinsbursky nn); 4370cf99b91SMi Jinlong if (status) 4380cf99b91SMi Jinlong goto out; 4398b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4408b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 441bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4421da177e4SLinus Torvalds if (status) 4431da177e4SLinus Torvalds goto out; 444c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4451da177e4SLinus Torvalds break; 4468b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4471da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 448dad1c067SJ. Bruce Fields open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 4492fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4501da177e4SLinus Torvalds open->op_claim_type); 4511da177e4SLinus Torvalds status = nfserr_notsupp; 4521da177e4SLinus Torvalds goto out; 4531da177e4SLinus Torvalds default: 4542fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4551da177e4SLinus Torvalds open->op_claim_type); 4561da177e4SLinus Torvalds status = nfserr_inval; 4571da177e4SLinus Torvalds goto out; 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds /* 4601da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4611da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4621da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4631da177e4SLinus Torvalds */ 464c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 465856121b2SJ. Bruce Fields WARN_ON(status && open->op_created); 4661da177e4SLinus Torvalds out: 467c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 468c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 469c0e6bee4SJ. Bruce Fields fh_put(resfh); 470c0e6bee4SJ. Bruce Fields kfree(resfh); 471c0e6bee4SJ. Bruce Fields } 472d29b20cdSJ. Bruce Fields nfsd4_cleanup_open_state(open, status); 4733d74e6a5SJ. Bruce Fields if (open->op_openowner && !nfsd4_has_session(cstate)) 474fe0750e5SJ. Bruce Fields cstate->replay_owner = &open->op_openowner->oo_owner; 4759411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4769411b1d4SJ. Bruce Fields if (!cstate->replay_owner) 4771da177e4SLinus Torvalds nfs4_unlock_state(); 4781da177e4SLinus Torvalds return status; 4791da177e4SLinus Torvalds } 4801da177e4SLinus Torvalds 4811da177e4SLinus Torvalds /* 4829d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4839d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4849d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4859d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4869d313b17SJ. Bruce Fields */ 4879d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4889d313b17SJ. Bruce Fields { 4899d313b17SJ. Bruce Fields struct nfsd4_open *open = (struct nfsd4_open *)&op->u; 4909d313b17SJ. Bruce Fields 4919d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4929d313b17SJ. Bruce Fields return op->status; 4939d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4949d313b17SJ. Bruce Fields return op->status; 4959d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 4969d313b17SJ. Bruce Fields return nfsd4_open(rqstp, cstate, open); 4979d313b17SJ. Bruce Fields } 4989d313b17SJ. Bruce Fields 4999d313b17SJ. Bruce Fields /* 5001da177e4SLinus Torvalds * filehandle-manipulating ops. 5011da177e4SLinus Torvalds */ 5027191155bSJ.Bruce Fields static __be32 503b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 504b591480bSJ.Bruce Fields struct svc_fh **getfh) 5051da177e4SLinus Torvalds { 506ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5071da177e4SLinus Torvalds return nfserr_nofilehandle; 5081da177e4SLinus Torvalds 509ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 5101da177e4SLinus Torvalds return nfs_ok; 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds 5137191155bSJ.Bruce Fields static __be32 514ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 515ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 5161da177e4SLinus Torvalds { 517ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 518ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 519ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 520ca364317SJ.Bruce Fields putfh->pf_fhlen); 52168d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5221da177e4SLinus Torvalds } 5231da177e4SLinus Torvalds 5247191155bSJ.Bruce Fields static __be32 525b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 526b591480bSJ.Bruce Fields void *arg) 5271da177e4SLinus Torvalds { 528b37ad28bSAl Viro __be32 status; 5291da177e4SLinus Torvalds 530ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 531df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5321da177e4SLinus Torvalds return status; 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds 5357191155bSJ.Bruce Fields static __be32 536b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 537b591480bSJ.Bruce Fields void *arg) 5381da177e4SLinus Torvalds { 539ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5401da177e4SLinus Torvalds return nfserr_restorefh; 5411da177e4SLinus Torvalds 542ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 54337c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 54437c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 54537c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 54637c593c5STigran Mkrtchyan } 5471da177e4SLinus Torvalds return nfs_ok; 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds 5507191155bSJ.Bruce Fields static __be32 551b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 552b591480bSJ.Bruce Fields void *arg) 5531da177e4SLinus Torvalds { 554ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5551da177e4SLinus Torvalds return nfserr_nofilehandle; 5561da177e4SLinus Torvalds 557ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 55837c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 55937c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 56037c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 56137c593c5STigran Mkrtchyan } 5621da177e4SLinus Torvalds return nfs_ok; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds /* 5661da177e4SLinus Torvalds * misc nfsv4 ops 5671da177e4SLinus Torvalds */ 5687191155bSJ.Bruce Fields static __be32 569ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 570ca364317SJ.Bruce Fields struct nfsd4_access *access) 5711da177e4SLinus Torvalds { 5721da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5731da177e4SLinus Torvalds return nfserr_inval; 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 576ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 577ca364317SJ.Bruce Fields &access->ac_supported); 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds 580b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 581ab4684d1SChuck Lever { 582ab4684d1SChuck Lever __be32 verf[2]; 583b9c0ef85SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 584ab4684d1SChuck Lever 585b9c0ef85SStanislav Kinsbursky verf[0] = (__be32)nn->nfssvc_boot.tv_sec; 586b9c0ef85SStanislav Kinsbursky verf[1] = (__be32)nn->nfssvc_boot.tv_usec; 587ab4684d1SChuck Lever memcpy(verifier->data, verf, sizeof(verifier->data)); 588ab4684d1SChuck Lever } 589ab4684d1SChuck Lever 5907191155bSJ.Bruce Fields static __be32 591ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 592ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 5931da177e4SLinus Torvalds { 594b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 59575c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 596ca364317SJ.Bruce Fields commit->co_count); 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds 599b37ad28bSAl Viro static __be32 600ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 601ca364317SJ.Bruce Fields struct nfsd4_create *create) 6021da177e4SLinus Torvalds { 6031da177e4SLinus Torvalds struct svc_fh resfh; 604b37ad28bSAl Viro __be32 status; 6051da177e4SLinus Torvalds dev_t rdev; 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6081da177e4SLinus Torvalds 6098837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, 6108837abcaSMiklos Szeredi NFSD_MAY_CREATE); 6111da177e4SLinus Torvalds if (status) 6121da177e4SLinus Torvalds return status; 6131da177e4SLinus Torvalds 6143c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6153c8e0316SYu Zhiguo nfsd_attrmask); 6163c8e0316SYu Zhiguo if (status) 6173c8e0316SYu Zhiguo return status; 6183c8e0316SYu Zhiguo 6191da177e4SLinus Torvalds switch (create->cr_type) { 6201da177e4SLinus Torvalds case NF4LNK: 6211da177e4SLinus Torvalds /* ugh! we have to null-terminate the linktext, or 6221da177e4SLinus Torvalds * vfs_symlink() will choke. it is always safe to 6231da177e4SLinus Torvalds * null-terminate by brute force, since at worst we 6241da177e4SLinus Torvalds * will overwrite the first byte of the create namelen 6251da177e4SLinus Torvalds * in the XDR buffer, which has already been extracted 6261da177e4SLinus Torvalds * during XDR decode. 6271da177e4SLinus Torvalds */ 6281da177e4SLinus Torvalds create->cr_linkname[create->cr_linklen] = 0; 6291da177e4SLinus Torvalds 630ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 631ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 632ca364317SJ.Bruce Fields create->cr_linkname, create->cr_linklen, 633ca364317SJ.Bruce Fields &resfh, &create->cr_iattr); 6341da177e4SLinus Torvalds break; 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvalds case NF4BLK: 6371da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6381da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6391da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6401da177e4SLinus Torvalds return nfserr_inval; 641ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 642ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 643ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6441da177e4SLinus Torvalds break; 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds case NF4CHR: 6471da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6481da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6491da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6501da177e4SLinus Torvalds return nfserr_inval; 651ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 652ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 653ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6541da177e4SLinus Torvalds break; 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds case NF4SOCK: 657ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 658ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 659ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6601da177e4SLinus Torvalds break; 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds case NF4FIFO: 663ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 664ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 665ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6661da177e4SLinus Torvalds break; 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds case NF4DIR: 6691da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 670ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 671ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 672ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6731da177e4SLinus Torvalds break; 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds default: 6761da177e4SLinus Torvalds status = nfserr_badtype; 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds 6799208faf2SYu Zhiguo if (status) 6809208faf2SYu Zhiguo goto out; 6819208faf2SYu Zhiguo 68218032ca0SDavid Quigley if (create->cr_label.len) 68318032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 68418032ca0SDavid Quigley 6859208faf2SYu Zhiguo if (create->cr_acl != NULL) 6869208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6879208faf2SYu Zhiguo create->cr_bmval); 6889208faf2SYu Zhiguo 689ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 690ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 691ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6929208faf2SYu Zhiguo out: 6931da177e4SLinus Torvalds fh_put(&resfh); 6941da177e4SLinus Torvalds return status; 6951da177e4SLinus Torvalds } 6961da177e4SLinus Torvalds 6977191155bSJ.Bruce Fields static __be32 698ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 699ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 7001da177e4SLinus Torvalds { 701b37ad28bSAl Viro __be32 status; 7021da177e4SLinus Torvalds 7038837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 7041da177e4SLinus Torvalds if (status) 7051da177e4SLinus Torvalds return status; 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 7081da177e4SLinus Torvalds return nfserr_inval; 7091da177e4SLinus Torvalds 7107e705706SAndy Adamson getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 7117e705706SAndy Adamson getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 7127e705706SAndy Adamson getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 7131da177e4SLinus Torvalds 714ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7151da177e4SLinus Torvalds return nfs_ok; 7161da177e4SLinus Torvalds } 7171da177e4SLinus Torvalds 7187191155bSJ.Bruce Fields static __be32 719ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 720ca364317SJ.Bruce Fields struct nfsd4_link *link) 7211da177e4SLinus Torvalds { 722b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 7231da177e4SLinus Torvalds 724ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 7251da177e4SLinus Torvalds return status; 726ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 727ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7281da177e4SLinus Torvalds if (!status) 729ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7301da177e4SLinus Torvalds return status; 7311da177e4SLinus Torvalds } 7321da177e4SLinus Torvalds 7330ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7341da177e4SLinus Torvalds { 7351da177e4SLinus Torvalds struct svc_fh tmp_fh; 736b37ad28bSAl Viro __be32 ret; 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 739df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 740df547efbSJ. Bruce Fields if (ret) 7411da177e4SLinus Torvalds return ret; 7420ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7431da177e4SLinus Torvalds fh_put(&tmp_fh); 7441da177e4SLinus Torvalds return nfserr_noent; 7451da177e4SLinus Torvalds } 7461da177e4SLinus Torvalds fh_put(&tmp_fh); 7470ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7480ff7ab46SJ. Bruce Fields } 7490ff7ab46SJ. Bruce Fields 7500ff7ab46SJ. Bruce Fields static __be32 7510ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 7520ff7ab46SJ. Bruce Fields void *arg) 7530ff7ab46SJ. Bruce Fields { 7540ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds 7577191155bSJ.Bruce Fields static __be32 758ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 759ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 7601da177e4SLinus Torvalds { 761ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 762ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 763ca364317SJ.Bruce Fields &cstate->current_fh); 7641da177e4SLinus Torvalds } 7651da177e4SLinus Torvalds 7667191155bSJ.Bruce Fields static __be32 767ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 768ca364317SJ.Bruce Fields struct nfsd4_read *read) 7691da177e4SLinus Torvalds { 770b37ad28bSAl Viro __be32 status; 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_read() */ 7731da177e4SLinus Torvalds 7747e06b7f9SNeilBrown read->rd_filp = NULL; 7751da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7761da177e4SLinus Torvalds return nfserr_inval; 7771da177e4SLinus Torvalds 7789b3234b9SJ. Bruce Fields /* 7799b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7809b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7819b3234b9SJ. Bruce Fields * following compound. 7829b3234b9SJ. Bruce Fields * 7839b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7849b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7859b3234b9SJ. Bruce Fields */ 7869b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 7879b3234b9SJ. Bruce Fields rqstp->rq_splice_ok = false; 7889b3234b9SJ. Bruce Fields 7891da177e4SLinus Torvalds /* check stateid */ 7905ccb0066SStanislav Kinsbursky if ((status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), 7915ccb0066SStanislav Kinsbursky cstate, &read->rd_stateid, 7926150ef0dSJ. Bruce Fields RD_STATE, &read->rd_filp))) { 7931da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7941da177e4SLinus Torvalds goto out; 7951da177e4SLinus Torvalds } 7961da177e4SLinus Torvalds status = nfs_ok; 7971da177e4SLinus Torvalds out: 7981da177e4SLinus Torvalds read->rd_rqstp = rqstp; 799ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 8001da177e4SLinus Torvalds return status; 8011da177e4SLinus Torvalds } 8021da177e4SLinus Torvalds 8037191155bSJ.Bruce Fields static __be32 804ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 805ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 8061da177e4SLinus Torvalds { 8071da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 8081da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8131da177e4SLinus Torvalds return nfserr_inval; 8141da177e4SLinus Torvalds 8157e705706SAndy Adamson readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 8167e705706SAndy Adamson readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 8177e705706SAndy Adamson readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 8181da177e4SLinus Torvalds 819832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8201da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8211da177e4SLinus Torvalds return nfserr_bad_cookie; 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 824ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8251da177e4SLinus Torvalds return nfs_ok; 8261da177e4SLinus Torvalds } 8271da177e4SLinus Torvalds 8287191155bSJ.Bruce Fields static __be32 829ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 830ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 8311da177e4SLinus Torvalds { 8321da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 833ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 8341da177e4SLinus Torvalds return nfs_ok; 8351da177e4SLinus Torvalds } 8361da177e4SLinus Torvalds 8377191155bSJ.Bruce Fields static __be32 838ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 839ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 8401da177e4SLinus Torvalds { 841b37ad28bSAl Viro __be32 status; 8421da177e4SLinus Torvalds 8435ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp))) 844c815afc7SNeilBrown return nfserr_grace; 845ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 846ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8471da177e4SLinus Torvalds if (!status) { 848ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 849ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8501da177e4SLinus Torvalds } 8511da177e4SLinus Torvalds return status; 8521da177e4SLinus Torvalds } 8531da177e4SLinus Torvalds 8547191155bSJ.Bruce Fields static __be32 855ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 856ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 8571da177e4SLinus Torvalds { 858b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 8591da177e4SLinus Torvalds 860ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 8611da177e4SLinus Torvalds return status; 8625ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp)) && 8635ccb0066SStanislav Kinsbursky !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) 864c815afc7SNeilBrown return nfserr_grace; 865ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 866ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8671da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8682a6cf944SJ. Bruce Fields if (status) 8692a6cf944SJ. Bruce Fields return status; 870ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 871ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8722a6cf944SJ. Bruce Fields return nfs_ok; 8731da177e4SLinus Torvalds } 8741da177e4SLinus Torvalds 8757191155bSJ.Bruce Fields static __be32 876dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 877dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 878dcb488a3SAndy Adamson { 879dcb488a3SAndy Adamson struct svc_fh resfh; 880dcb488a3SAndy Adamson struct svc_export *exp; 881dcb488a3SAndy Adamson struct dentry *dentry; 882dcb488a3SAndy Adamson __be32 err; 883dcb488a3SAndy Adamson 884dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 88529a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 88629a78a3eSJ. Bruce Fields if (err) 88729a78a3eSJ. Bruce Fields return err; 888dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 889dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 890dcb488a3SAndy Adamson &exp, &dentry); 891dcb488a3SAndy Adamson if (err) 892dcb488a3SAndy Adamson return err; 893dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 894dcb488a3SAndy Adamson exp_put(exp); 895dcb488a3SAndy Adamson err = nfserr_noent; 896dcb488a3SAndy Adamson } else 897dcb488a3SAndy Adamson secinfo->si_exp = exp; 898dcb488a3SAndy Adamson dput(dentry); 89956560b9aSJ. Bruce Fields if (cstate->minorversion) 90056560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 90156560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 902dcb488a3SAndy Adamson return err; 903dcb488a3SAndy Adamson } 904dcb488a3SAndy Adamson 905dcb488a3SAndy Adamson static __be32 90604f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 90704f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 90804f4ad16SJ. Bruce Fields { 90904f4ad16SJ. Bruce Fields __be32 err; 91004f4ad16SJ. Bruce Fields 91104f4ad16SJ. Bruce Fields switch (sin->sin_style) { 91204f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 91304f4ad16SJ. Bruce Fields break; 91404f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 91504f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 91604f4ad16SJ. Bruce Fields if (err) 91704f4ad16SJ. Bruce Fields return err; 91804f4ad16SJ. Bruce Fields break; 91904f4ad16SJ. Bruce Fields default: 92004f4ad16SJ. Bruce Fields return nfserr_inval; 92104f4ad16SJ. Bruce Fields } 92204f4ad16SJ. Bruce Fields exp_get(cstate->current_fh.fh_export); 92304f4ad16SJ. Bruce Fields sin->sin_exp = cstate->current_fh.fh_export; 92404f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 92504f4ad16SJ. Bruce Fields return nfs_ok; 92604f4ad16SJ. Bruce Fields } 92704f4ad16SJ. Bruce Fields 92804f4ad16SJ. Bruce Fields static __be32 929ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 930ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 9311da177e4SLinus Torvalds { 932b37ad28bSAl Viro __be32 status = nfs_ok; 93396f6f985SAl Viro int err; 9341da177e4SLinus Torvalds 9351da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 9365ccb0066SStanislav Kinsbursky status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate, 9376150ef0dSJ. Bruce Fields &setattr->sa_stateid, WR_STATE, NULL); 938375c5547SJ. Bruce Fields if (status) { 9393e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 940375c5547SJ. Bruce Fields return status; 941375c5547SJ. Bruce Fields } 9421da177e4SLinus Torvalds } 94396f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 94496f6f985SAl Viro if (err) 94596f6f985SAl Viro return nfserrno(err); 9461da177e4SLinus Torvalds status = nfs_ok; 9473c8e0316SYu Zhiguo 9483c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9493c8e0316SYu Zhiguo nfsd_attrmask); 9503c8e0316SYu Zhiguo if (status) 9513c8e0316SYu Zhiguo goto out; 9523c8e0316SYu Zhiguo 9531da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 954ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 955ca364317SJ.Bruce Fields setattr->sa_acl); 9561da177e4SLinus Torvalds if (status) 95718f335afSDave Hansen goto out; 95818032ca0SDavid Quigley if (setattr->sa_label.len) 95918032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 96018032ca0SDavid Quigley &setattr->sa_label); 96118032ca0SDavid Quigley if (status) 96218032ca0SDavid Quigley goto out; 963ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9641da177e4SLinus Torvalds 0, (time_t)0); 96518f335afSDave Hansen out: 966bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9671da177e4SLinus Torvalds return status; 9681da177e4SLinus Torvalds } 9691da177e4SLinus Torvalds 970ffe1137bSJ. Bruce Fields static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write) 971ffe1137bSJ. Bruce Fields { 972ffe1137bSJ. Bruce Fields int i = 1; 973ffe1137bSJ. Bruce Fields int buflen = write->wr_buflen; 974ffe1137bSJ. Bruce Fields 975ffe1137bSJ. Bruce Fields vec[0].iov_base = write->wr_head.iov_base; 976ffe1137bSJ. Bruce Fields vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len); 977ffe1137bSJ. Bruce Fields buflen -= vec[0].iov_len; 978ffe1137bSJ. Bruce Fields 979ffe1137bSJ. Bruce Fields while (buflen) { 980ffe1137bSJ. Bruce Fields vec[i].iov_base = page_address(write->wr_pagelist[i - 1]); 981ffe1137bSJ. Bruce Fields vec[i].iov_len = min_t(int, PAGE_SIZE, buflen); 982ffe1137bSJ. Bruce Fields buflen -= vec[i].iov_len; 983ffe1137bSJ. Bruce Fields i++; 984ffe1137bSJ. Bruce Fields } 985ffe1137bSJ. Bruce Fields return i; 986ffe1137bSJ. Bruce Fields } 987ffe1137bSJ. Bruce Fields 9887191155bSJ.Bruce Fields static __be32 989ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 990ca364317SJ.Bruce Fields struct nfsd4_write *write) 9911da177e4SLinus Torvalds { 9921da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 9931da177e4SLinus Torvalds struct file *filp = NULL; 994b37ad28bSAl Viro __be32 status = nfs_ok; 99531dec253SDavid Shaw unsigned long cnt; 996ffe1137bSJ. Bruce Fields int nvecs; 9971da177e4SLinus Torvalds 9981da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 9991da177e4SLinus Torvalds 10001da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 10011da177e4SLinus Torvalds return nfserr_inval; 10021da177e4SLinus Torvalds 10035ccb0066SStanislav Kinsbursky status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), 10045ccb0066SStanislav Kinsbursky cstate, stateid, WR_STATE, &filp); 1005375c5547SJ. Bruce Fields if (status) { 1006375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 1007375c5547SJ. Bruce Fields return status; 1008375c5547SJ. Bruce Fields } 1009375c5547SJ. Bruce Fields 101031dec253SDavid Shaw cnt = write->wr_buflen; 10111da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 1012b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); 10131da177e4SLinus Torvalds 1014ffe1137bSJ. Bruce Fields nvecs = fill_in_write_vector(rqstp->rq_vec, write); 1015ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1016ffe1137bSJ. Bruce Fields 1017ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 1018ffe1137bSJ. Bruce Fields write->wr_offset, rqstp->rq_vec, nvecs, 101931dec253SDavid Shaw &cnt, &write->wr_how_written); 10207e06b7f9SNeilBrown if (filp) 10217e06b7f9SNeilBrown fput(filp); 10221da177e4SLinus Torvalds 102331dec253SDavid Shaw write->wr_bytes_written = cnt; 102431dec253SDavid Shaw 10251da177e4SLinus Torvalds return status; 10261da177e4SLinus Torvalds } 10271da177e4SLinus Torvalds 10281da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 10291da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 10301da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 10311da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 10321da177e4SLinus Torvalds */ 1033b37ad28bSAl Viro static __be32 1034c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1035ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 10361da177e4SLinus Torvalds { 10372ebbc012SAl Viro __be32 *buf, *p; 10381da177e4SLinus Torvalds int count; 1039b37ad28bSAl Viro __be32 status; 10401da177e4SLinus Torvalds 10418837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 10421da177e4SLinus Torvalds if (status) 10431da177e4SLinus Torvalds return status; 10441da177e4SLinus Torvalds 10453c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 10463c8e0316SYu Zhiguo if (status) 10473c8e0316SYu Zhiguo return status; 10483c8e0316SYu Zhiguo 10491da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 10501da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 10511da177e4SLinus Torvalds return nfserr_inval; 10521da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 10531da177e4SLinus Torvalds return nfserr_inval; 10541da177e4SLinus Torvalds 10551da177e4SLinus Torvalds /* count in words: 10561da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 10571da177e4SLinus Torvalds */ 10581da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 10591da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 10601da177e4SLinus Torvalds if (!buf) 10613e772463SJ. Bruce Fields return nfserr_jukebox; 10621da177e4SLinus Torvalds 106384822d0bSJ. Bruce Fields p = buf; 1064ca364317SJ.Bruce Fields status = nfsd4_encode_fattr(&cstate->current_fh, 1065ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 106684822d0bSJ. Bruce Fields cstate->current_fh.fh_dentry, &p, 106784822d0bSJ. Bruce Fields count, verify->ve_bmval, 1068406a7ea9SFrank Filz rqstp, 0); 106941ae6e71SJ. Bruce Fields /* 107041ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 107141ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 107241ae6e71SJ. Bruce Fields */ 107384822d0bSJ. Bruce Fields if (status == nfserr_resource) 10741da177e4SLinus Torvalds status = nfserr_not_same; 10751da177e4SLinus Torvalds if (status) 10761da177e4SLinus Torvalds goto out_kfree; 10771da177e4SLinus Torvalds 107895ec28cdSBenny Halevy /* skip bitmap */ 107995ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 10801da177e4SLinus Torvalds status = nfserr_not_same; 10811da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 10821da177e4SLinus Torvalds goto out_kfree; 10831da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 10841da177e4SLinus Torvalds status = nfserr_same; 10851da177e4SLinus Torvalds 10861da177e4SLinus Torvalds out_kfree: 10871da177e4SLinus Torvalds kfree(buf); 10881da177e4SLinus Torvalds return status; 10891da177e4SLinus Torvalds } 10901da177e4SLinus Torvalds 1091c954e2a5SJ.Bruce Fields static __be32 1092c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1093c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1094c954e2a5SJ.Bruce Fields { 1095c954e2a5SJ.Bruce Fields __be32 status; 1096c954e2a5SJ.Bruce Fields 1097c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1098c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1099c954e2a5SJ.Bruce Fields } 1100c954e2a5SJ.Bruce Fields 1101c954e2a5SJ.Bruce Fields static __be32 1102c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1103c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1104c954e2a5SJ.Bruce Fields { 1105c954e2a5SJ.Bruce Fields __be32 status; 1106c954e2a5SJ.Bruce Fields 1107c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1108c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1109c954e2a5SJ.Bruce Fields } 1110c954e2a5SJ.Bruce Fields 11111da177e4SLinus Torvalds /* 11121da177e4SLinus Torvalds * NULL call. 11131da177e4SLinus Torvalds */ 11147111c66eSAl Viro static __be32 11151da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 11161da177e4SLinus Torvalds { 11171da177e4SLinus Torvalds return nfs_ok; 11181da177e4SLinus Torvalds } 11191da177e4SLinus Torvalds 1120e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1121e2b20950SShankar Anand { 1122e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1123e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1124e2b20950SShankar Anand } 1125e2b20950SShankar Anand 1126b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 1127b591480bSJ.Bruce Fields void *); 112858e7b33aSMi Jinlong typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op); 11298b70484cSTigran Mkrtchyan typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *); 11308b70484cSTigran Mkrtchyan typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *); 113158e7b33aSMi Jinlong 1132f9bb94c4SAndy Adamson enum nfsd4_op_flags { 1133f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 11345ece3cafSMi Jinlong ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 11355ece3cafSMi Jinlong ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 113668d93184SJ. Bruce Fields /* For rfc 5661 section 2.6.3.1.1: */ 113768d93184SJ. Bruce Fields OP_HANDLES_WRONGSEC = 1 << 3, 113868d93184SJ. Bruce Fields OP_IS_PUTFH_LIKE = 1 << 4, 11391091006cSJ. Bruce Fields /* 1140c856694eSJ. Bruce Fields * These are the ops whose result size we estimate before 1141c856694eSJ. Bruce Fields * encoding, to avoid performing an op then not being able to 1142c856694eSJ. Bruce Fields * respond or cache a response. This includes writes and setattrs 1143c856694eSJ. Bruce Fields * as well as the operations usually called "nonidempotent": 1144c856694eSJ. Bruce Fields */ 1145c856694eSJ. Bruce Fields OP_MODIFIES_SOMETHING = 1 << 5, 1146c856694eSJ. Bruce Fields /* 1147c856694eSJ. Bruce Fields * Cache compounds containing these ops in the xid-based drc: 11481091006cSJ. Bruce Fields * We use the DRC for compounds containing non-idempotent 11491091006cSJ. Bruce Fields * operations, *except* those that are 4.1-specific (since 11501091006cSJ. Bruce Fields * sessions provide their own EOS), and except for stateful 11511091006cSJ. Bruce Fields * operations other than setclientid and setclientid_confirm 11521091006cSJ. Bruce Fields * (since sequence numbers provide EOS for open, lock, etc in 11531091006cSJ. Bruce Fields * the v4.0 case). 11541091006cSJ. Bruce Fields */ 1155c856694eSJ. Bruce Fields OP_CACHEME = 1 << 6, 11568b70484cSTigran Mkrtchyan /* 11578b70484cSTigran Mkrtchyan * These are ops which clear current state id. 11588b70484cSTigran Mkrtchyan */ 11598b70484cSTigran Mkrtchyan OP_CLEAR_STATEID = 1 << 7, 1160c856694eSJ. Bruce Fields }; 1161c856694eSJ. Bruce Fields 1162c856694eSJ. Bruce Fields struct nfsd4_operation { 1163c856694eSJ. Bruce Fields nfsd4op_func op_func; 1164c856694eSJ. Bruce Fields u32 op_flags; 1165c856694eSJ. Bruce Fields char *op_name; 116658e7b33aSMi Jinlong /* Try to get response size before operation */ 116758e7b33aSMi Jinlong nfsd4op_rsize op_rsize_bop; 116824ff99c6SBryan Schumaker stateid_getter op_get_currentstateid; 116924ff99c6SBryan Schumaker stateid_setter op_set_currentstateid; 1170b591480bSJ.Bruce Fields }; 1171b591480bSJ.Bruce Fields 1172b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 1173b591480bSJ.Bruce Fields 11748f199b82STrond Myklebust #ifdef NFSD_DEBUG 1175f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 11768f199b82STrond Myklebust #endif 1177b001a1b6SBenny Halevy 11781da177e4SLinus Torvalds /* 117957716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1180f9bb94c4SAndy Adamson * 118157716355SJ. Bruce Fields * Also note, enforced elsewhere: 118257716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 118357716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 11841d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 11851d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 118657716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 118757716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 118857716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1189f9bb94c4SAndy Adamson */ 119057716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1191f9bb94c4SAndy Adamson { 1192f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 119357716355SJ. Bruce Fields 119457716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 119557716355SJ. Bruce Fields if (args->minorversion == 0) 119657716355SJ. Bruce Fields return nfs_ok; 119757716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 119857716355SJ. Bruce Fields if (args->opcnt == 0) 119957716355SJ. Bruce Fields return nfs_ok; 120057716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 120157716355SJ. Bruce Fields return nfs_ok; 120257716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 120357716355SJ. Bruce Fields return nfserr_op_not_in_session; 120457716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 120557716355SJ. Bruce Fields return nfs_ok; 120657716355SJ. Bruce Fields if (args->opcnt != 1) 120757716355SJ. Bruce Fields return nfserr_not_only_op; 120857716355SJ. Bruce Fields return nfs_ok; 1209f9bb94c4SAndy Adamson } 1210f9bb94c4SAndy Adamson 121122b03214SJ. Bruce Fields static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 121222b03214SJ. Bruce Fields { 121322b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 121422b03214SJ. Bruce Fields } 121522b03214SJ. Bruce Fields 12161091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 12171091006cSJ. Bruce Fields { 1218c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 12191091006cSJ. Bruce Fields } 12201091006cSJ. Bruce Fields 122168d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 122268d93184SJ. Bruce Fields { 122368d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 122468d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 122568d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 122668d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 122768d93184SJ. Bruce Fields struct nfsd4_operation *thisd; 122868d93184SJ. Bruce Fields struct nfsd4_operation *nextd; 122968d93184SJ. Bruce Fields 123068d93184SJ. Bruce Fields thisd = OPDESC(this); 123168d93184SJ. Bruce Fields /* 123268d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 123368d93184SJ. Bruce Fields * have special rules. 123468d93184SJ. Bruce Fields */ 123568d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 123668d93184SJ. Bruce Fields return false; 123768d93184SJ. Bruce Fields /* 123868d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 123968d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 124068d93184SJ. Bruce Fields * result: 124168d93184SJ. Bruce Fields */ 124268d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 124368d93184SJ. Bruce Fields return false; 124468d93184SJ. Bruce Fields 124568d93184SJ. Bruce Fields nextd = OPDESC(next); 124668d93184SJ. Bruce Fields /* 124768d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 124868d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 124968d93184SJ. Bruce Fields * now: 125068d93184SJ. Bruce Fields */ 125168d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 125268d93184SJ. Bruce Fields } 125368d93184SJ. Bruce Fields 1254f9bb94c4SAndy Adamson /* 12551da177e4SLinus Torvalds * COMPOUND call. 12561da177e4SLinus Torvalds */ 12577111c66eSAl Viro static __be32 12581da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 12591da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 12601da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 12611da177e4SLinus Torvalds { 12621da177e4SLinus Torvalds struct nfsd4_op *op; 1263b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1264e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 12654daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 12664daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1267e5710199SJ.Bruce Fields int slack_bytes; 126858e7b33aSMi Jinlong u32 plen = 0; 1269b37ad28bSAl Viro __be32 status; 12701da177e4SLinus Torvalds 12711da177e4SLinus Torvalds resp->xbuf = &rqstp->rq_res; 1272e354d571SAndy Adamson resp->p = rqstp->rq_res.head[0].iov_base + 1273e354d571SAndy Adamson rqstp->rq_res.head[0].iov_len; 12741da177e4SLinus Torvalds resp->tagp = resp->p; 12751da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 12761da177e4SLinus Torvalds resp->p += 2 + XDR_QUADLEN(args->taglen); 12771da177e4SLinus Torvalds resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE; 12781da177e4SLinus Torvalds resp->taglen = args->taglen; 12791da177e4SLinus Torvalds resp->tag = args->tag; 12801da177e4SLinus Torvalds resp->opcnt = 0; 12811da177e4SLinus Torvalds resp->rqstp = rqstp; 12824daeed25SKinglong Mee cstate->minorversion = args->minorversion; 12834daeed25SKinglong Mee cstate->replay_owner = NULL; 12844daeed25SKinglong Mee cstate->session = NULL; 12854daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 12864daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 12878ff30fa4SNeilBrown /* 12888ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 12898ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 12908ff30fa4SNeilBrown */ 12918ff30fa4SNeilBrown rqstp->rq_usedeferral = 0; 12921da177e4SLinus Torvalds 12931da177e4SLinus Torvalds /* 12941da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 12951da177e4SLinus Torvalds */ 12961da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 129735f7a14fSJ. Bruce Fields if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) 12981da177e4SLinus Torvalds goto out; 12991da177e4SLinus Torvalds 130057716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 130157716355SJ. Bruce Fields if (status) { 1302f9bb94c4SAndy Adamson op = &args->ops[0]; 130357716355SJ. Bruce Fields op->status = status; 1304f9bb94c4SAndy Adamson goto encode_op; 1305f9bb94c4SAndy Adamson } 1306f9bb94c4SAndy Adamson 13071da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 13081da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 13091da177e4SLinus Torvalds 1310b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1311b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1312b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 13131da177e4SLinus Torvalds /* 13141da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 13151da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 13161da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 13171da177e4SLinus Torvalds */ 13189d313b17SJ. Bruce Fields if (op->status) { 13199d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 13209d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 13211da177e4SLinus Torvalds goto encode_op; 13229d313b17SJ. Bruce Fields } 13231da177e4SLinus Torvalds 13241da177e4SLinus Torvalds /* We must be able to encode a successful response to 13251da177e4SLinus Torvalds * this operation, with enough room left over to encode a 13261da177e4SLinus Torvalds * failed response to the next operation. If we don't 13271da177e4SLinus Torvalds * have enough room, fail with ERR_RESOURCE. 13281da177e4SLinus Torvalds */ 1329e5710199SJ.Bruce Fields slack_bytes = (char *)resp->end - (char *)resp->p; 1330e5710199SJ.Bruce Fields if (slack_bytes < COMPOUND_SLACK_SPACE 1331e5710199SJ.Bruce Fields + COMPOUND_ERR_SLACK_SPACE) { 1332e5710199SJ.Bruce Fields BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE); 13331da177e4SLinus Torvalds op->status = nfserr_resource; 13341da177e4SLinus Torvalds goto encode_op; 13351da177e4SLinus Torvalds } 13361da177e4SLinus Torvalds 133722b03214SJ. Bruce Fields opdesc = OPDESC(op); 1338b591480bSJ.Bruce Fields 13394daeed25SKinglong Mee if (!current_fh->fh_dentry) { 134027d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 13411da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 13421da177e4SLinus Torvalds goto encode_op; 13431da177e4SLinus Torvalds } 13444daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1345eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 134642ca0993SJ.Bruce Fields op->status = nfserr_moved; 134742ca0993SJ.Bruce Fields goto encode_op; 134842ca0993SJ.Bruce Fields } 1349b591480bSJ.Bruce Fields 13502336745eSKinglong Mee fh_clear_wcc(current_fh); 13512336745eSKinglong Mee 135258e7b33aSMi Jinlong /* If op is non-idempotent */ 135358e7b33aSMi Jinlong if (opdesc->op_flags & OP_MODIFIES_SOMETHING) { 135458e7b33aSMi Jinlong plen = opdesc->op_rsize_bop(rqstp, op); 13554c69d585SJ. Bruce Fields /* 13564c69d585SJ. Bruce Fields * If there's still another operation, make sure 13574c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 13584c69d585SJ. Bruce Fields */ 13594c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 13604c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 136158e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 136258e7b33aSMi Jinlong } 136358e7b33aSMi Jinlong 136458e7b33aSMi Jinlong if (op->status) 136558e7b33aSMi Jinlong goto encode_op; 136658e7b33aSMi Jinlong 13678b70484cSTigran Mkrtchyan if (opdesc->op_get_currentstateid) 13688b70484cSTigran Mkrtchyan opdesc->op_get_currentstateid(cstate, &op->u); 1369b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 13701da177e4SLinus Torvalds 13718b70484cSTigran Mkrtchyan if (!op->status) { 13728b70484cSTigran Mkrtchyan if (opdesc->op_set_currentstateid) 13738b70484cSTigran Mkrtchyan opdesc->op_set_currentstateid(cstate, &op->u); 13748b70484cSTigran Mkrtchyan 13758b70484cSTigran Mkrtchyan if (opdesc->op_flags & OP_CLEAR_STATEID) 137637c593c5STigran Mkrtchyan clear_current_stateid(cstate); 13778b70484cSTigran Mkrtchyan 13788b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 13794daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 13808b70484cSTigran Mkrtchyan } 138168d93184SJ. Bruce Fields 13821da177e4SLinus Torvalds encode_op: 138349557cc7SAndy Adamson /* Only from SEQUENCE */ 13844daeed25SKinglong Mee if (cstate->status == nfserr_replay_cache) { 1385da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1386da3846a2SAndy Adamson status = op->status; 1387da3846a2SAndy Adamson goto out; 1388da3846a2SAndy Adamson } 1389a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1390a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 13911da177e4SLinus Torvalds nfsd4_encode_replay(resp, op); 13921da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 13931da177e4SLinus Torvalds } else { 13941da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 13951da177e4SLinus Torvalds status = op->status; 13961da177e4SLinus Torvalds } 13970407717dSBenny Halevy 13980407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 13990407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 14000407717dSBenny Halevy be32_to_cpu(status)); 14010407717dSBenny Halevy 1402a4f1706aSJ.Bruce Fields if (cstate->replay_owner) { 14035ec094c1SJ. Bruce Fields nfs4_unlock_state(); 1404a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 14051da177e4SLinus Torvalds } 14067e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 14077e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 14087e06b7f9SNeilBrown fput(op->u.read.rd_filp); 1409e2b20950SShankar Anand 1410e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 14111da177e4SLinus Torvalds } 14121da177e4SLinus Torvalds 14134daeed25SKinglong Mee cstate->status = status; 14144daeed25SKinglong Mee fh_put(current_fh); 14154daeed25SKinglong Mee fh_put(save_fh); 14164daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 14171da177e4SLinus Torvalds out: 14182f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 14192f425878SAndy Adamson rqstp->rq_usedeferral = 1; 14203b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 14211da177e4SLinus Torvalds return status; 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds 142458e7b33aSMi Jinlong #define op_encode_hdr_size (2) 142558e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 142658e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 142758e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 142858e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 142958e7b33aSMi Jinlong 143058e7b33aSMi Jinlong #define op_encode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 143158e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 143258e7b33aSMi Jinlong 143358e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 143458e7b33aSMi Jinlong 143558e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 143658e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 143758e7b33aSMi Jinlong op_encode_ace_maxsz) 143858e7b33aSMi Jinlong 143958e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 144058e7b33aSMi Jinlong 144158e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 144258e7b33aSMi Jinlong { 144358e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 144458e7b33aSMi Jinlong } 144558e7b33aSMi Jinlong 144658e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 144758e7b33aSMi Jinlong { 144858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 144958e7b33aSMi Jinlong } 145058e7b33aSMi Jinlong 145158e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 145258e7b33aSMi Jinlong { 145358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 145458e7b33aSMi Jinlong } 145558e7b33aSMi Jinlong 145658e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 145758e7b33aSMi Jinlong { 145858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 145958e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 146058e7b33aSMi Jinlong } 146158e7b33aSMi Jinlong 146258e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 146358e7b33aSMi Jinlong { 146458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 146558e7b33aSMi Jinlong * sizeof(__be32); 146658e7b33aSMi Jinlong } 146758e7b33aSMi Jinlong 146858e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 146958e7b33aSMi Jinlong { 147058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 147158e7b33aSMi Jinlong * sizeof(__be32); 147258e7b33aSMi Jinlong } 147358e7b33aSMi Jinlong 147458e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 147558e7b33aSMi Jinlong { 147658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 147758e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 147858e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 147958e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 148058e7b33aSMi Jinlong } 148158e7b33aSMi Jinlong 148258e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 148358e7b33aSMi Jinlong { 148458e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 148558e7b33aSMi Jinlong 148658e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 148758e7b33aSMi Jinlong rlen = op->u.read.rd_length; 148858e7b33aSMi Jinlong 148958e7b33aSMi Jinlong if (rlen > maxcount) 149058e7b33aSMi Jinlong rlen = maxcount; 149158e7b33aSMi Jinlong 1492*622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 149358e7b33aSMi Jinlong } 149458e7b33aSMi Jinlong 149558e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 149658e7b33aSMi Jinlong { 149758e7b33aSMi Jinlong u32 rlen = op->u.readdir.rd_maxcount; 149858e7b33aSMi Jinlong 149958e7b33aSMi Jinlong if (rlen > PAGE_SIZE) 150058e7b33aSMi Jinlong rlen = PAGE_SIZE; 150158e7b33aSMi Jinlong 150258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) 150358e7b33aSMi Jinlong * sizeof(__be32) + rlen; 150458e7b33aSMi Jinlong } 150558e7b33aSMi Jinlong 150658e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 150758e7b33aSMi Jinlong { 150858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 150958e7b33aSMi Jinlong * sizeof(__be32); 151058e7b33aSMi Jinlong } 151158e7b33aSMi Jinlong 151258e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 151358e7b33aSMi Jinlong { 151458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 151558e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 151658e7b33aSMi Jinlong } 151758e7b33aSMi Jinlong 151858e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 151958e7b33aSMi Jinlong { 152058e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 152158e7b33aSMi Jinlong } 152258e7b33aSMi Jinlong 152358e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 152458e7b33aSMi Jinlong { 1525480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 1526480efaeeSJ. Bruce Fields sizeof(__be32); 152758e7b33aSMi Jinlong } 152858e7b33aSMi Jinlong 152958e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 153058e7b33aSMi Jinlong { 153158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 153258e7b33aSMi Jinlong } 153358e7b33aSMi Jinlong 153458e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 153558e7b33aSMi Jinlong { 153658e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 1537a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 1538a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 153958e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 154058e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 154158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 154258e7b33aSMi Jinlong /* eir_server_scope<> */\ 154358e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 154458e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 154558e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 154658e7b33aSMi Jinlong } 154758e7b33aSMi Jinlong 154858e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 154958e7b33aSMi Jinlong { 155058e7b33aSMi Jinlong return (op_encode_hdr_size + \ 155158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 155258e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 155358e7b33aSMi Jinlong } 155458e7b33aSMi Jinlong 155558e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 155658e7b33aSMi Jinlong { 155758e7b33aSMi Jinlong return (op_encode_hdr_size + \ 155858e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 155958e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 156058e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 156158e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 156258e7b33aSMi Jinlong } 156358e7b33aSMi Jinlong 156420766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1565b591480bSJ.Bruce Fields [OP_ACCESS] = { 1566b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1567b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1568b591480bSJ.Bruce Fields }, 1569b591480bSJ.Bruce Fields [OP_CLOSE] = { 1570b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 157158e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1572b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 157358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 15748b70484cSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid, 15758b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid, 1576b591480bSJ.Bruce Fields }, 1577b591480bSJ.Bruce Fields [OP_COMMIT] = { 1578b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 157958e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1580b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 158158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize, 1582b591480bSJ.Bruce Fields }, 1583b591480bSJ.Bruce Fields [OP_CREATE] = { 1584b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1585d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 1586b001a1b6SBenny Halevy .op_name = "OP_CREATE", 158758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize, 1588b591480bSJ.Bruce Fields }, 1589b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1590b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 159158e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1592b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 159358e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 15949428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid, 1595b591480bSJ.Bruce Fields }, 1596b591480bSJ.Bruce Fields [OP_GETATTR] = { 1597b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 1598eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 1599b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 1600b591480bSJ.Bruce Fields }, 1601b591480bSJ.Bruce Fields [OP_GETFH] = { 1602b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 1603b001a1b6SBenny Halevy .op_name = "OP_GETFH", 1604b591480bSJ.Bruce Fields }, 1605b591480bSJ.Bruce Fields [OP_LINK] = { 1606b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 1607c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 1608c856694eSJ. Bruce Fields | OP_CACHEME, 1609b001a1b6SBenny Halevy .op_name = "OP_LINK", 161058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize, 1611b591480bSJ.Bruce Fields }, 1612b591480bSJ.Bruce Fields [OP_LOCK] = { 1613b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 161458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1615b001a1b6SBenny Halevy .op_name = "OP_LOCK", 161658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, 161762cd4a59STigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid, 1618b591480bSJ.Bruce Fields }, 1619b591480bSJ.Bruce Fields [OP_LOCKT] = { 1620b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 1621b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 1622b591480bSJ.Bruce Fields }, 1623b591480bSJ.Bruce Fields [OP_LOCKU] = { 1624b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 162558e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1626b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 162758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 162862cd4a59STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid, 1629b591480bSJ.Bruce Fields }, 1630b591480bSJ.Bruce Fields [OP_LOOKUP] = { 1631b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 1632d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 1633b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 1634b591480bSJ.Bruce Fields }, 1635b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 1636b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 1637d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 1638b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 1639b591480bSJ.Bruce Fields }, 1640b591480bSJ.Bruce Fields [OP_NVERIFY] = { 1641b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 1642b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 1643b591480bSJ.Bruce Fields }, 1644b591480bSJ.Bruce Fields [OP_OPEN] = { 1645b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 164658e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 1647b001a1b6SBenny Halevy .op_name = "OP_OPEN", 164858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize, 16498b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid, 1650b591480bSJ.Bruce Fields }, 1651b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 1652b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 165358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1654b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 165558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 1656b591480bSJ.Bruce Fields }, 1657b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 1658b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 165958e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1660b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 166158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 16629428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid, 16639428fe1aSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid, 1664b591480bSJ.Bruce Fields }, 1665b591480bSJ.Bruce Fields [OP_PUTFH] = { 1666b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 166768d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 16685b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 1669b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 167058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1671b591480bSJ.Bruce Fields }, 1672eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 1673a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 167468d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 16755b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 1676b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 167758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1678eeac294eSJ.Bruce Fields }, 1679b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 1680b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 168168d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 16825b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 1683b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 168458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1685b591480bSJ.Bruce Fields }, 1686b591480bSJ.Bruce Fields [OP_READ] = { 1687b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 1688b001a1b6SBenny Halevy .op_name = "OP_READ", 168958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, 169030813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, 1691b591480bSJ.Bruce Fields }, 1692b591480bSJ.Bruce Fields [OP_READDIR] = { 1693b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 1694b001a1b6SBenny Halevy .op_name = "OP_READDIR", 169558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, 1696b591480bSJ.Bruce Fields }, 1697b591480bSJ.Bruce Fields [OP_READLINK] = { 1698b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 1699b001a1b6SBenny Halevy .op_name = "OP_READLINK", 1700b591480bSJ.Bruce Fields }, 1701b591480bSJ.Bruce Fields [OP_REMOVE] = { 1702b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 1703c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 1704b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 170558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize, 1706b591480bSJ.Bruce Fields }, 1707b591480bSJ.Bruce Fields [OP_RENAME] = { 1708b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 1709c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 171058e7b33aSMi Jinlong .op_name = "OP_RENAME", 171158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize, 1712b591480bSJ.Bruce Fields }, 1713b591480bSJ.Bruce Fields [OP_RENEW] = { 1714b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 171558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 171658e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 1717b001a1b6SBenny Halevy .op_name = "OP_RENEW", 171858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 171958e7b33aSMi Jinlong 1720b591480bSJ.Bruce Fields }, 1721b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 1722b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 172368d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 172458e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 1725b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 172658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1727b591480bSJ.Bruce Fields }, 1728b591480bSJ.Bruce Fields [OP_SAVEFH] = { 1729b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 173058e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 1731b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 173258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1733b591480bSJ.Bruce Fields }, 1734dcb488a3SAndy Adamson [OP_SECINFO] = { 1735dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 173668d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 1737b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 1738dcb488a3SAndy Adamson }, 1739b591480bSJ.Bruce Fields [OP_SETATTR] = { 1740b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 1741b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 1742c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 174358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize, 17441e97b519STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid, 1745b591480bSJ.Bruce Fields }, 1746b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 1747b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 174858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 1749c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 1750b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 175158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize, 1752b591480bSJ.Bruce Fields }, 1753b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 1754b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 175558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 1756c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 1757b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 175858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1759b591480bSJ.Bruce Fields }, 1760b591480bSJ.Bruce Fields [OP_VERIFY] = { 1761b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 1762b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 1763b591480bSJ.Bruce Fields }, 1764b591480bSJ.Bruce Fields [OP_WRITE] = { 1765b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 1766c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 1767b001a1b6SBenny Halevy .op_name = "OP_WRITE", 176858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 176930813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid, 1770b591480bSJ.Bruce Fields }, 1771b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 1772b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 177358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 177458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 1775b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 177658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1777b591480bSJ.Bruce Fields }, 1778069b6ad4SAndy Adamson 1779069b6ad4SAndy Adamson /* NFSv4.1 operations */ 1780069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 1781069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 178258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 178358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 1784069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 178558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize, 1786069b6ad4SAndy Adamson }, 1787cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 1788cb73a9f4SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_backchannel_ctl, 1789cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 1790cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 1791cb73a9f4SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1792cb73a9f4SJ. Bruce Fields }, 17931d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 17941d1bc8f2SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, 179558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 179658e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 17971d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 179858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize, 17991d1bc8f2SJ. Bruce Fields }, 1800069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 1801069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 180258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 180358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 1804069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 180558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize, 1806069b6ad4SAndy Adamson }, 1807069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 1808069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 180958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 181058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 1811069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 181258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1813069b6ad4SAndy Adamson }, 1814069b6ad4SAndy Adamson [OP_SEQUENCE] = { 1815069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 1816f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1817069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 1818069b6ad4SAndy Adamson }, 1819094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 1820345c2842SMi Jinlong .op_func = (nfsd4op_func)nfsd4_destroy_clientid, 182158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 182258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 1823094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 182458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1825094b5d74SBenny Halevy }, 18264dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 18274dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 182858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 18294dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 183058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 18314dc6ec00SJ. Bruce Fields }, 183204f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 183304f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 183468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 183504f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 183604f4ad16SJ. Bruce Fields }, 183717456804SBryan Schumaker [OP_TEST_STATEID] = { 183817456804SBryan Schumaker .op_func = (nfsd4op_func)nfsd4_test_stateid, 183917456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 184017456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 184117456804SBryan Schumaker }, 1842e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 1843e1ca12dfSBryan Schumaker .op_func = (nfsd4op_func)nfsd4_free_stateid, 184458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 1845e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 1846a1dc6955SJ. Bruce Fields .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid, 184758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 1848e1ca12dfSBryan Schumaker }, 1849b591480bSJ.Bruce Fields }; 1850b591480bSJ.Bruce Fields 18518f199b82STrond Myklebust #ifdef NFSD_DEBUG 1852f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 1853b001a1b6SBenny Halevy { 1854b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 1855b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 1856b001a1b6SBenny Halevy return "unknown_operation"; 1857b001a1b6SBenny Halevy } 18588f199b82STrond Myklebust #endif 1859b001a1b6SBenny Halevy 18601da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 18611da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 18621da177e4SLinus Torvalds 18631da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 18640a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 18650a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_null, 18660a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 18670a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 18680a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 18690a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 18700a93a47fSYu Zhiguo .pc_xdrressize = 1, 18710a93a47fSYu Zhiguo }, 18720a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 18730a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_compound, 18740a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 18750a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 18760a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 18770a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 18783e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 18790a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 18800a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 18810a93a47fSYu Zhiguo }, 18821da177e4SLinus Torvalds }; 18831da177e4SLinus Torvalds 18841da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 18851da177e4SLinus Torvalds .vs_vers = 4, 18861da177e4SLinus Torvalds .vs_nproc = 2, 18871da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 18881da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 18891da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 18907e55b59bSKinglong Mee .vs_rpcb_optnl = 1, 18911da177e4SLinus Torvalds }; 18921da177e4SLinus Torvalds 18931da177e4SLinus Torvalds /* 18941da177e4SLinus Torvalds * Local variables: 18951da177e4SLinus Torvalds * c-basic-offset: 8 18961da177e4SLinus Torvalds * End: 18971da177e4SLinus Torvalds */ 1898