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> 36b0cb9085SAnna Schumaker #include <linux/falloc.h> 375a0e3ad6STejun Heo #include <linux/slab.h> 381da177e4SLinus Torvalds 3958e7b33aSMi Jinlong #include "idmap.h" 409a74af21SBoaz Harrosh #include "cache.h" 419a74af21SBoaz Harrosh #include "xdr4.h" 420a3adadeSJ. Bruce Fields #include "vfs.h" 438b70484cSTigran Mkrtchyan #include "current_stateid.h" 443320fef1SStanislav Kinsbursky #include "netns.h" 454ac7249eSChristoph Hellwig #include "acl.h" 469cf514ccSChristoph Hellwig #include "pnfs.h" 4731ef83dcSChristoph Hellwig #include "trace.h" 481da177e4SLinus Torvalds 4918032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 5018032ca0SDavid Quigley #include <linux/security.h> 5118032ca0SDavid Quigley 5218032ca0SDavid Quigley static inline void 5318032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 5418032ca0SDavid Quigley { 5518032ca0SDavid Quigley struct inode *inode = resfh->fh_dentry->d_inode; 5618032ca0SDavid Quigley int status; 5718032ca0SDavid Quigley 5818032ca0SDavid Quigley mutex_lock(&inode->i_mutex); 5918032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 6018032ca0SDavid Quigley label->data, label->len); 6118032ca0SDavid Quigley mutex_unlock(&inode->i_mutex); 6218032ca0SDavid Quigley 6318032ca0SDavid Quigley if (status) 6418032ca0SDavid Quigley /* 6518032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 6618032ca0SDavid Quigley * already have created a new file, so it may be too 6718032ca0SDavid Quigley * late. For now this seems the least of evils: 6818032ca0SDavid Quigley */ 6918032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 7018032ca0SDavid Quigley 7118032ca0SDavid Quigley return; 7218032ca0SDavid Quigley } 7318032ca0SDavid Quigley #else 7418032ca0SDavid Quigley static inline void 7518032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7618032ca0SDavid Quigley { } 7718032ca0SDavid Quigley #endif 7818032ca0SDavid Quigley 791da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 801da177e4SLinus Torvalds 813c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 823c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 833c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 843c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 853c8e0316SYu Zhiguo }; 863c8e0316SYu Zhiguo 873c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 883c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 893c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 903c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 913c8e0316SYu Zhiguo }; 923c8e0316SYu Zhiguo 933c8e0316SYu Zhiguo static __be32 943c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 953c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 963c8e0316SYu Zhiguo { 973c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 983c8e0316SYu Zhiguo 993c8e0316SYu Zhiguo /* 1003c8e0316SYu Zhiguo * Check about attributes are supported by the NFSv4 server or not. 1013c8e0316SYu Zhiguo * According to spec, unsupported attributes return ERR_ATTRNOTSUPP. 1023c8e0316SYu Zhiguo */ 1033c8e0316SYu Zhiguo if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) || 1043c8e0316SYu Zhiguo (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) || 1053c8e0316SYu Zhiguo (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion))) 1063c8e0316SYu Zhiguo return nfserr_attrnotsupp; 1073c8e0316SYu Zhiguo 1083c8e0316SYu Zhiguo /* 109a06b1261STrond Myklebust * Check FATTR4_WORD0_ACL can be supported 1103c8e0316SYu Zhiguo * in current environment or not. 1113c8e0316SYu Zhiguo */ 1123c8e0316SYu Zhiguo if (bmval[0] & FATTR4_WORD0_ACL) { 1133c8e0316SYu Zhiguo if (!IS_POSIXACL(dentry->d_inode)) 1143c8e0316SYu Zhiguo return nfserr_attrnotsupp; 1153c8e0316SYu Zhiguo } 1163c8e0316SYu Zhiguo 1173c8e0316SYu Zhiguo /* 1183c8e0316SYu Zhiguo * According to spec, read-only attributes return ERR_INVAL. 1193c8e0316SYu Zhiguo */ 1203c8e0316SYu Zhiguo if (writable) { 1213c8e0316SYu Zhiguo if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) || 1223c8e0316SYu Zhiguo (bmval[2] & ~writable[2])) 1233c8e0316SYu Zhiguo return nfserr_inval; 1243c8e0316SYu Zhiguo } 1253c8e0316SYu Zhiguo 1263c8e0316SYu Zhiguo return nfs_ok; 1273c8e0316SYu Zhiguo } 1283c8e0316SYu Zhiguo 1293c8e0316SYu Zhiguo static __be32 1303c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1313c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1323c8e0316SYu Zhiguo { 1333c8e0316SYu Zhiguo __be32 status = nfs_ok; 1343c8e0316SYu Zhiguo 1353c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1363c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1373c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1383c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1393c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1403c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1413c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1423c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1433c8e0316SYu Zhiguo } 1443c8e0316SYu Zhiguo 1453c8e0316SYu Zhiguo return status; 1463c8e0316SYu Zhiguo } 1473c8e0316SYu Zhiguo 1489208faf2SYu Zhiguo static int 1499208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1509208faf2SYu Zhiguo { 1519208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1529208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1539208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1549208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1559208faf2SYu Zhiguo } 1569208faf2SYu Zhiguo 1579208faf2SYu Zhiguo /* 1589208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1599208faf2SYu Zhiguo * in the returned attr bitmap. 1609208faf2SYu Zhiguo */ 1619208faf2SYu Zhiguo static void 1629208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1639208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1649208faf2SYu Zhiguo { 1659208faf2SYu Zhiguo __be32 status; 1669208faf2SYu Zhiguo 1679208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1689208faf2SYu Zhiguo if (status) 1699208faf2SYu Zhiguo /* 1709208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1719208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1729208faf2SYu Zhiguo * So this seems the least of evils: 1739208faf2SYu Zhiguo */ 1749208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1759208faf2SYu Zhiguo } 1769208faf2SYu Zhiguo 1771da177e4SLinus Torvalds static inline void 1781da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1791da177e4SLinus Torvalds { 1801da177e4SLinus Torvalds fh_put(dst); 1811da177e4SLinus Torvalds dget(src->fh_dentry); 1821da177e4SLinus Torvalds if (src->fh_export) 183bf18f163SKinglong Mee exp_get(src->fh_export); 1841da177e4SLinus Torvalds *dst = *src; 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 187b37ad28bSAl Viro static __be32 188dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1891da177e4SLinus Torvalds { 190b37ad28bSAl Viro __be32 status; 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds if (open->op_truncate && 1931da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1941da177e4SLinus Torvalds return nfserr_inval; 1951da177e4SLinus Torvalds 196a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 197a043226bSJ. Bruce Fields 1981da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 1998837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 2009801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 2018837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 20257ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 2038837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds return status; 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds 210aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 211aadab6c6SJ. Bruce Fields { 212aadab6c6SJ. Bruce Fields umode_t mode = fh->fh_dentry->d_inode->i_mode; 213aadab6c6SJ. Bruce Fields 214aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 215aadab6c6SJ. Bruce Fields return nfs_ok; 216aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 217aadab6c6SJ. Bruce Fields return nfserr_isdir; 218aadab6c6SJ. Bruce Fields /* 219aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 220aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 221aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 222aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 223aadab6c6SJ. Bruce Fields * regular file. 224aadab6c6SJ. Bruce Fields */ 225aadab6c6SJ. Bruce Fields return nfserr_symlink; 226aadab6c6SJ. Bruce Fields } 227aadab6c6SJ. Bruce Fields 228bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2291da177e4SLinus Torvalds { 230bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 231bbc9c36cSJ. Bruce Fields return; 232bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 233bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 234bbc9c36cSJ. Bruce Fields } 235bbc9c36cSJ. Bruce Fields 236bbc9c36cSJ. Bruce Fields static __be32 237c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 238bbc9c36cSJ. Bruce Fields { 239bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 2407007c90fSNeil Brown int accmode; 241b37ad28bSAl Viro __be32 status; 2421da177e4SLinus Torvalds 243c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 244c0e6bee4SJ. Bruce Fields if (!*resfh) 24559deeb9eSJ. Bruce Fields return nfserr_jukebox; 246c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 2471da177e4SLinus Torvalds open->op_truncate = 0; 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds if (open->op_create) { 25079fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 25179fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 25279fb54abSBenny Halevy * 25379fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 25479fb54abSBenny Halevy * Reply Cache | server | | 25579fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 25679fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 25779fb54abSBenny Halevy * | | | (SHOULD) 25879fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 25979fb54abSBenny Halevy * | | | (SHOULD NOT) 26079fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 26179fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 26279fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 26379fb54abSBenny Halevy */ 26479fb54abSBenny Halevy 2651da177e4SLinus Torvalds /* 2661da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 267ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2681da177e4SLinus Torvalds */ 269ac6721a1SMi Jinlong status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, 2701da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 271c0e6bee4SJ. Bruce Fields *resfh, open->op_createmode, 272749997e5SJeff Layton (u32 *)open->op_verf.data, 273856121b2SJ. Bruce Fields &open->op_truncate, &open->op_created); 274749997e5SJeff Layton 27518032ca0SDavid Quigley if (!status && open->op_label.len) 276c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 27718032ca0SDavid Quigley 27899f88726SJ. Bruce Fields /* 27999f88726SJ. Bruce Fields * Following rfc 3530 14.2.16, use the returned bitmask 28099f88726SJ. Bruce Fields * to indicate which attributes we used to store the 28199f88726SJ. Bruce Fields * verifier: 282749997e5SJeff Layton */ 283749997e5SJeff Layton if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0) 28499f88726SJ. Bruce Fields open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS | 285749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 2864335723eSJ. Bruce Fields } else 2874335723eSJ. Bruce Fields /* 2884335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 2894335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 2904335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 2914335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 2924335723eSJ. Bruce Fields */ 2931da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 294c0e6bee4SJ. Bruce Fields open->op_fname.data, open->op_fname.len, *resfh); 295aadab6c6SJ. Bruce Fields if (status) 296aadab6c6SJ. Bruce Fields goto out; 297c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 298af85852dSJ. Bruce Fields if (status) 299af85852dSJ. Bruce Fields goto out; 3001da177e4SLinus Torvalds 3019208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 302c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 3039208faf2SYu Zhiguo 304c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 3057007c90fSNeil Brown accmode = NFSD_MAY_NOP; 30689f6c336SJ. Bruce Fields if (open->op_created || 30789f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 3087007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 309c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 31041fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 311af85852dSJ. Bruce Fields out: 3121da177e4SLinus Torvalds return status; 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds 315b37ad28bSAl Viro static __be32 316bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 3171da177e4SLinus Torvalds { 318bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 319b37ad28bSAl Viro __be32 status; 3209f415eb2SJ. Bruce Fields int accmode = 0; 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 3231da177e4SLinus Torvalds * set the change info 3241da177e4SLinus Torvalds */ 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 3271da177e4SLinus Torvalds 328bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 3311da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 3329f415eb2SJ. Bruce Fields /* 3339f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 3349f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 3359f415eb2SJ. Bruce Fields * should let it succeed now if possible. 3369f415eb2SJ. Bruce Fields * 3379f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 3389f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 3399f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 3409f415eb2SJ. Bruce Fields */ 3419f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 3429f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 3431da177e4SLinus Torvalds 3449f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds return status; 3471da177e4SLinus Torvalds } 3481da177e4SLinus Torvalds 34960adfc50SAndy Adamson static void 35060adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 35160adfc50SAndy Adamson { 35260adfc50SAndy Adamson struct nfsd4_sessionid *sid = 35360adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 35460adfc50SAndy Adamson 35560adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 35660adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 35760adfc50SAndy Adamson } 3581da177e4SLinus Torvalds 3597191155bSJ.Bruce Fields static __be32 360ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 361a4f1706aSJ.Bruce Fields struct nfsd4_open *open) 3621da177e4SLinus Torvalds { 363b37ad28bSAl Viro __be32 status; 364c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 3656668958fSAndy Adamson struct nfsd4_compoundres *resp; 3663320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3673320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 3686668958fSAndy Adamson 369fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3701da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 371fe0750e5SJ. Bruce Fields open->op_openowner); 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds /* This check required by spec. */ 3741da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3751da177e4SLinus Torvalds return nfserr_inval; 3761da177e4SLinus Torvalds 377856121b2SJ. Bruce Fields open->op_created = 0; 378ab1350b2SMi Jinlong /* 379ab1350b2SMi Jinlong * RFC5661 18.51.3 380ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 381ab1350b2SMi Jinlong */ 382ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 383a52d726bSJeff Layton !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, 384a52d726bSJeff Layton &cstate->session->se_client->cl_flags) && 385ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 386ab1350b2SMi Jinlong return nfserr_grace; 387ab1350b2SMi Jinlong 38860adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 38960adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 39060adfc50SAndy Adamson 3911da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3926668958fSAndy Adamson resp = rqstp->rq_resp; 3933320fef1SStanislav Kinsbursky status = nfsd4_process_open1(&resp->cstate, open, nn); 394a90b061cSAl Viro if (status == nfserr_replay_me) { 395fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 396ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 397a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 398a4773c08SJ. Bruce Fields &rp->rp_openfh); 3998837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 4001da177e4SLinus Torvalds if (status) 4011da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 4021da177e4SLinus Torvalds " restoring previous filehandle\n"); 4031da177e4SLinus Torvalds else 404a90b061cSAl Viro status = nfserr_replay_me; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds if (status) 4071da177e4SLinus Torvalds goto out; 4089d313b17SJ. Bruce Fields if (open->op_xdr_error) { 4099d313b17SJ. Bruce Fields status = open->op_xdr_error; 4109d313b17SJ. Bruce Fields goto out; 4119d313b17SJ. Bruce Fields } 412fb553c0fSJ. Bruce Fields 4133c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 4143c8e0316SYu Zhiguo if (status) 4153c8e0316SYu Zhiguo goto out; 4163c8e0316SYu Zhiguo 417fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 418fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 419cbd0d51aSJ. Bruce Fields status = nfserr_grace; 4203320fef1SStanislav Kinsbursky if (locks_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 421cbd0d51aSJ. Bruce Fields goto out; 422cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 4233320fef1SStanislav Kinsbursky if (!locks_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 424cbd0d51aSJ. Bruce Fields goto out; 425fb553c0fSJ. Bruce Fields 4261da177e4SLinus Torvalds switch (open->op_claim_type) { 4270dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4281da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 429c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4301da177e4SLinus Torvalds if (status) 4311da177e4SLinus Torvalds goto out; 4321da177e4SLinus Torvalds break; 4331da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 4343320fef1SStanislav Kinsbursky status = nfs4_check_open_reclaim(&open->op_clientid, 4350fe492dbSTrond Myklebust cstate, nn); 4360cf99b91SMi Jinlong if (status) 4370cf99b91SMi Jinlong goto out; 438ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 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: 4482fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4491da177e4SLinus Torvalds open->op_claim_type); 4501da177e4SLinus Torvalds status = nfserr_notsupp; 4511da177e4SLinus Torvalds goto out; 4521da177e4SLinus Torvalds default: 4532fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4541da177e4SLinus Torvalds open->op_claim_type); 4551da177e4SLinus Torvalds status = nfserr_inval; 4561da177e4SLinus Torvalds goto out; 4571da177e4SLinus Torvalds } 4581da177e4SLinus Torvalds /* 4591da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4601da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4611da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4621da177e4SLinus Torvalds */ 463c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 464b3fbfe0eSJeff Layton WARN(status && open->op_created, 465b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 466b3fbfe0eSJeff Layton be32_to_cpu(status)); 4671da177e4SLinus Torvalds out: 468c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 469c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 470c0e6bee4SJ. Bruce Fields fh_put(resfh); 471c0e6bee4SJ. Bruce Fields kfree(resfh); 472c0e6bee4SJ. Bruce Fields } 47358fb12e6SJeff Layton nfsd4_cleanup_open_state(cstate, open, status); 4749411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4751da177e4SLinus Torvalds return status; 4761da177e4SLinus Torvalds } 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds /* 4799d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4809d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4819d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4829d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4839d313b17SJ. Bruce Fields */ 4849d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4859d313b17SJ. Bruce Fields { 4869d313b17SJ. Bruce Fields struct nfsd4_open *open = (struct nfsd4_open *)&op->u; 4879d313b17SJ. Bruce Fields 4889d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4899d313b17SJ. Bruce Fields return op->status; 4909d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4919d313b17SJ. Bruce Fields return op->status; 4929d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 4939d313b17SJ. Bruce Fields return nfsd4_open(rqstp, cstate, open); 4949d313b17SJ. Bruce Fields } 4959d313b17SJ. Bruce Fields 4969d313b17SJ. Bruce Fields /* 4971da177e4SLinus Torvalds * filehandle-manipulating ops. 4981da177e4SLinus Torvalds */ 4997191155bSJ.Bruce Fields static __be32 500b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 501b591480bSJ.Bruce Fields struct svc_fh **getfh) 5021da177e4SLinus Torvalds { 503ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5041da177e4SLinus Torvalds return nfserr_nofilehandle; 5051da177e4SLinus Torvalds 506ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 5071da177e4SLinus Torvalds return nfs_ok; 5081da177e4SLinus Torvalds } 5091da177e4SLinus Torvalds 5107191155bSJ.Bruce Fields static __be32 511ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 512ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 5131da177e4SLinus Torvalds { 514ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 515ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 516ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 517ca364317SJ.Bruce Fields putfh->pf_fhlen); 51868d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5191da177e4SLinus Torvalds } 5201da177e4SLinus Torvalds 5217191155bSJ.Bruce Fields static __be32 522b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 523b591480bSJ.Bruce Fields void *arg) 5241da177e4SLinus Torvalds { 525b37ad28bSAl Viro __be32 status; 5261da177e4SLinus Torvalds 527ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 528df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5291da177e4SLinus Torvalds return status; 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds 5327191155bSJ.Bruce Fields static __be32 533b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 534b591480bSJ.Bruce Fields void *arg) 5351da177e4SLinus Torvalds { 536ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5371da177e4SLinus Torvalds return nfserr_restorefh; 5381da177e4SLinus Torvalds 539ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 54037c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 54137c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 54237c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 54337c593c5STigran Mkrtchyan } 5441da177e4SLinus Torvalds return nfs_ok; 5451da177e4SLinus Torvalds } 5461da177e4SLinus Torvalds 5477191155bSJ.Bruce Fields static __be32 548b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 549b591480bSJ.Bruce Fields void *arg) 5501da177e4SLinus Torvalds { 551ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5521da177e4SLinus Torvalds return nfserr_nofilehandle; 5531da177e4SLinus Torvalds 554ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 55537c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 55637c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 55737c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 55837c593c5STigran Mkrtchyan } 5591da177e4SLinus Torvalds return nfs_ok; 5601da177e4SLinus Torvalds } 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds /* 5631da177e4SLinus Torvalds * misc nfsv4 ops 5641da177e4SLinus Torvalds */ 5657191155bSJ.Bruce Fields static __be32 566ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 567ca364317SJ.Bruce Fields struct nfsd4_access *access) 5681da177e4SLinus Torvalds { 5691da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5701da177e4SLinus Torvalds return nfserr_inval; 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 573ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 574ca364317SJ.Bruce Fields &access->ac_supported); 5751da177e4SLinus Torvalds } 5761da177e4SLinus Torvalds 577b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 578ab4684d1SChuck Lever { 579ab4684d1SChuck Lever __be32 verf[2]; 580b9c0ef85SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 581ab4684d1SChuck Lever 582f419992cSJeff Layton /* 583f419992cSJeff Layton * This is opaque to client, so no need to byte-swap. Use 584f419992cSJeff Layton * __force to keep sparse happy 585f419992cSJeff Layton */ 586f419992cSJeff Layton verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; 587f419992cSJeff Layton verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec; 588ab4684d1SChuck Lever memcpy(verifier->data, verf, sizeof(verifier->data)); 589ab4684d1SChuck Lever } 590ab4684d1SChuck Lever 5917191155bSJ.Bruce Fields static __be32 592ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 593ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 5941da177e4SLinus Torvalds { 595b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 59675c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 597ca364317SJ.Bruce Fields commit->co_count); 5981da177e4SLinus Torvalds } 5991da177e4SLinus Torvalds 600b37ad28bSAl Viro static __be32 601ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 602ca364317SJ.Bruce Fields struct nfsd4_create *create) 6031da177e4SLinus Torvalds { 6041da177e4SLinus Torvalds struct svc_fh resfh; 605b37ad28bSAl Viro __be32 status; 6061da177e4SLinus Torvalds dev_t rdev; 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6091da177e4SLinus Torvalds 6108837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, 6118837abcaSMiklos Szeredi NFSD_MAY_CREATE); 6121da177e4SLinus Torvalds if (status) 6131da177e4SLinus Torvalds return status; 6141da177e4SLinus Torvalds 6153c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6163c8e0316SYu Zhiguo nfsd_attrmask); 6173c8e0316SYu Zhiguo if (status) 6183c8e0316SYu Zhiguo return status; 6193c8e0316SYu Zhiguo 6201da177e4SLinus Torvalds switch (create->cr_type) { 6211da177e4SLinus Torvalds case NF4LNK: 622ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 623ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6241e444f5bSKinglong Mee create->cr_data, &resfh); 6251da177e4SLinus Torvalds break; 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds case NF4BLK: 6281da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6291da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6301da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6311da177e4SLinus Torvalds return nfserr_inval; 632ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 633ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 634ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6351da177e4SLinus Torvalds break; 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds case NF4CHR: 6381da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6391da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6401da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6411da177e4SLinus Torvalds return nfserr_inval; 642ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 643ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 644ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6451da177e4SLinus Torvalds break; 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds case NF4SOCK: 648ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 649ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 650ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6511da177e4SLinus Torvalds break; 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds case NF4FIFO: 654ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 655ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 656ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6571da177e4SLinus Torvalds break; 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds case NF4DIR: 6601da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 661ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 662ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 663ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6641da177e4SLinus Torvalds break; 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds default: 6671da177e4SLinus Torvalds status = nfserr_badtype; 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds 6709208faf2SYu Zhiguo if (status) 6719208faf2SYu Zhiguo goto out; 6729208faf2SYu Zhiguo 67318032ca0SDavid Quigley if (create->cr_label.len) 67418032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 67518032ca0SDavid Quigley 6769208faf2SYu Zhiguo if (create->cr_acl != NULL) 6779208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6789208faf2SYu Zhiguo create->cr_bmval); 6799208faf2SYu Zhiguo 680ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 681ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 682ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6839208faf2SYu Zhiguo out: 6841da177e4SLinus Torvalds fh_put(&resfh); 6851da177e4SLinus Torvalds return status; 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds 6887191155bSJ.Bruce Fields static __be32 689ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 690ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 6911da177e4SLinus Torvalds { 692b37ad28bSAl Viro __be32 status; 6931da177e4SLinus Torvalds 6948837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 6951da177e4SLinus Torvalds if (status) 6961da177e4SLinus Torvalds return status; 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6991da177e4SLinus Torvalds return nfserr_inval; 7001da177e4SLinus Torvalds 7017e705706SAndy Adamson getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 7027e705706SAndy Adamson getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 7037e705706SAndy Adamson getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 7041da177e4SLinus Torvalds 705ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7061da177e4SLinus Torvalds return nfs_ok; 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds 7097191155bSJ.Bruce Fields static __be32 710ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 711ca364317SJ.Bruce Fields struct nfsd4_link *link) 7121da177e4SLinus Torvalds { 713b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 7141da177e4SLinus Torvalds 715ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 7161da177e4SLinus Torvalds return status; 717ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 718ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7191da177e4SLinus Torvalds if (!status) 720ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7211da177e4SLinus Torvalds return status; 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds 7240ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7251da177e4SLinus Torvalds { 7261da177e4SLinus Torvalds struct svc_fh tmp_fh; 727b37ad28bSAl Viro __be32 ret; 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 730df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 731df547efbSJ. Bruce Fields if (ret) 7321da177e4SLinus Torvalds return ret; 7330ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7341da177e4SLinus Torvalds fh_put(&tmp_fh); 7351da177e4SLinus Torvalds return nfserr_noent; 7361da177e4SLinus Torvalds } 7371da177e4SLinus Torvalds fh_put(&tmp_fh); 7380ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7390ff7ab46SJ. Bruce Fields } 7400ff7ab46SJ. Bruce Fields 7410ff7ab46SJ. Bruce Fields static __be32 7420ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 7430ff7ab46SJ. Bruce Fields void *arg) 7440ff7ab46SJ. Bruce Fields { 7450ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds 7487191155bSJ.Bruce Fields static __be32 749ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 750ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 7511da177e4SLinus Torvalds { 752ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 753ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 754ca364317SJ.Bruce Fields &cstate->current_fh); 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds 7577191155bSJ.Bruce Fields static __be32 758ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 759ca364317SJ.Bruce Fields struct nfsd4_read *read) 7601da177e4SLinus Torvalds { 761b37ad28bSAl Viro __be32 status; 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_read() */ 7641da177e4SLinus Torvalds 7657e06b7f9SNeilBrown read->rd_filp = NULL; 7661da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7671da177e4SLinus Torvalds return nfserr_inval; 7681da177e4SLinus Torvalds 7699b3234b9SJ. Bruce Fields /* 7709b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7719b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7729b3234b9SJ. Bruce Fields * following compound. 7739b3234b9SJ. Bruce Fields * 7749b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7759b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7769b3234b9SJ. Bruce Fields */ 7779b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 778779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 7799b3234b9SJ. Bruce Fields 7801da177e4SLinus Torvalds /* check stateid */ 7815ccb0066SStanislav Kinsbursky if ((status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), 7825ccb0066SStanislav Kinsbursky cstate, &read->rd_stateid, 7836150ef0dSJ. Bruce Fields RD_STATE, &read->rd_filp))) { 7841da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7851da177e4SLinus Torvalds goto out; 7861da177e4SLinus Torvalds } 7871da177e4SLinus Torvalds status = nfs_ok; 7881da177e4SLinus Torvalds out: 7891da177e4SLinus Torvalds read->rd_rqstp = rqstp; 790ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 7911da177e4SLinus Torvalds return status; 7921da177e4SLinus Torvalds } 7931da177e4SLinus Torvalds 7947191155bSJ.Bruce Fields static __be32 795ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 796ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 7971da177e4SLinus Torvalds { 7981da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 7991da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8041da177e4SLinus Torvalds return nfserr_inval; 8051da177e4SLinus Torvalds 8067e705706SAndy Adamson readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 8077e705706SAndy Adamson readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 8087e705706SAndy Adamson readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 8091da177e4SLinus Torvalds 810832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8111da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8121da177e4SLinus Torvalds return nfserr_bad_cookie; 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 815ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8161da177e4SLinus Torvalds return nfs_ok; 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds 8197191155bSJ.Bruce Fields static __be32 820ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 821ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 8221da177e4SLinus Torvalds { 8231da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 824ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 8251da177e4SLinus Torvalds return nfs_ok; 8261da177e4SLinus Torvalds } 8271da177e4SLinus Torvalds 8287191155bSJ.Bruce Fields static __be32 829ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 830ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 8311da177e4SLinus Torvalds { 832b37ad28bSAl Viro __be32 status; 8331da177e4SLinus Torvalds 8345ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp))) 835c815afc7SNeilBrown return nfserr_grace; 836ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 837ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8381da177e4SLinus Torvalds if (!status) { 839ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 840ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8411da177e4SLinus Torvalds } 8421da177e4SLinus Torvalds return status; 8431da177e4SLinus Torvalds } 8441da177e4SLinus Torvalds 8457191155bSJ.Bruce Fields static __be32 846ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 847ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 8481da177e4SLinus Torvalds { 849b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 8501da177e4SLinus Torvalds 851ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 8521da177e4SLinus Torvalds return status; 8535ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp)) && 8545ccb0066SStanislav Kinsbursky !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) 855c815afc7SNeilBrown return nfserr_grace; 856ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 857ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8581da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8592a6cf944SJ. Bruce Fields if (status) 8602a6cf944SJ. Bruce Fields return status; 861ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 862ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8632a6cf944SJ. Bruce Fields return nfs_ok; 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds 8667191155bSJ.Bruce Fields static __be32 867dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 868dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 869dcb488a3SAndy Adamson { 870dcb488a3SAndy Adamson struct svc_fh resfh; 871dcb488a3SAndy Adamson struct svc_export *exp; 872dcb488a3SAndy Adamson struct dentry *dentry; 873dcb488a3SAndy Adamson __be32 err; 874dcb488a3SAndy Adamson 875dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 87629a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 87729a78a3eSJ. Bruce Fields if (err) 87829a78a3eSJ. Bruce Fields return err; 879dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 880dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 881dcb488a3SAndy Adamson &exp, &dentry); 882dcb488a3SAndy Adamson if (err) 883dcb488a3SAndy Adamson return err; 884dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 885dcb488a3SAndy Adamson exp_put(exp); 886dcb488a3SAndy Adamson err = nfserr_noent; 887dcb488a3SAndy Adamson } else 888dcb488a3SAndy Adamson secinfo->si_exp = exp; 889dcb488a3SAndy Adamson dput(dentry); 89056560b9aSJ. Bruce Fields if (cstate->minorversion) 89156560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 89256560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 893dcb488a3SAndy Adamson return err; 894dcb488a3SAndy Adamson } 895dcb488a3SAndy Adamson 896dcb488a3SAndy Adamson static __be32 89704f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 89804f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 89904f4ad16SJ. Bruce Fields { 90004f4ad16SJ. Bruce Fields __be32 err; 90104f4ad16SJ. Bruce Fields 90204f4ad16SJ. Bruce Fields switch (sin->sin_style) { 90304f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 90404f4ad16SJ. Bruce Fields break; 90504f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 90604f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 90704f4ad16SJ. Bruce Fields if (err) 90804f4ad16SJ. Bruce Fields return err; 90904f4ad16SJ. Bruce Fields break; 91004f4ad16SJ. Bruce Fields default: 91104f4ad16SJ. Bruce Fields return nfserr_inval; 91204f4ad16SJ. Bruce Fields } 913bf18f163SKinglong Mee 914bf18f163SKinglong Mee sin->sin_exp = exp_get(cstate->current_fh.fh_export); 91504f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 91604f4ad16SJ. Bruce Fields return nfs_ok; 91704f4ad16SJ. Bruce Fields } 91804f4ad16SJ. Bruce Fields 91904f4ad16SJ. Bruce Fields static __be32 920ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 921ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 9221da177e4SLinus Torvalds { 923b37ad28bSAl Viro __be32 status = nfs_ok; 92496f6f985SAl Viro int err; 9251da177e4SLinus Torvalds 9261da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 9275ccb0066SStanislav Kinsbursky status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate, 9286150ef0dSJ. Bruce Fields &setattr->sa_stateid, WR_STATE, NULL); 929375c5547SJ. Bruce Fields if (status) { 9303e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 931375c5547SJ. Bruce Fields return status; 932375c5547SJ. Bruce Fields } 9331da177e4SLinus Torvalds } 93496f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 93596f6f985SAl Viro if (err) 93696f6f985SAl Viro return nfserrno(err); 9371da177e4SLinus Torvalds status = nfs_ok; 9383c8e0316SYu Zhiguo 9393c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9403c8e0316SYu Zhiguo nfsd_attrmask); 9413c8e0316SYu Zhiguo if (status) 9423c8e0316SYu Zhiguo goto out; 9433c8e0316SYu Zhiguo 9441da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 945ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 946ca364317SJ.Bruce Fields setattr->sa_acl); 9471da177e4SLinus Torvalds if (status) 94818f335afSDave Hansen goto out; 94918032ca0SDavid Quigley if (setattr->sa_label.len) 95018032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 95118032ca0SDavid Quigley &setattr->sa_label); 95218032ca0SDavid Quigley if (status) 95318032ca0SDavid Quigley goto out; 954ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9551da177e4SLinus Torvalds 0, (time_t)0); 95618f335afSDave Hansen out: 957bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9581da177e4SLinus Torvalds return status; 9591da177e4SLinus Torvalds } 9601da177e4SLinus Torvalds 961ffe1137bSJ. Bruce Fields static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write) 962ffe1137bSJ. Bruce Fields { 963ffe1137bSJ. Bruce Fields int i = 1; 964ffe1137bSJ. Bruce Fields int buflen = write->wr_buflen; 965ffe1137bSJ. Bruce Fields 966ffe1137bSJ. Bruce Fields vec[0].iov_base = write->wr_head.iov_base; 967ffe1137bSJ. Bruce Fields vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len); 968ffe1137bSJ. Bruce Fields buflen -= vec[0].iov_len; 969ffe1137bSJ. Bruce Fields 970ffe1137bSJ. Bruce Fields while (buflen) { 971ffe1137bSJ. Bruce Fields vec[i].iov_base = page_address(write->wr_pagelist[i - 1]); 972ffe1137bSJ. Bruce Fields vec[i].iov_len = min_t(int, PAGE_SIZE, buflen); 973ffe1137bSJ. Bruce Fields buflen -= vec[i].iov_len; 974ffe1137bSJ. Bruce Fields i++; 975ffe1137bSJ. Bruce Fields } 976ffe1137bSJ. Bruce Fields return i; 977ffe1137bSJ. Bruce Fields } 978ffe1137bSJ. Bruce Fields 9797191155bSJ.Bruce Fields static __be32 980ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 981ca364317SJ.Bruce Fields struct nfsd4_write *write) 9821da177e4SLinus Torvalds { 9831da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 9841da177e4SLinus Torvalds struct file *filp = NULL; 985b37ad28bSAl Viro __be32 status = nfs_ok; 98631dec253SDavid Shaw unsigned long cnt; 987ffe1137bSJ. Bruce Fields int nvecs; 9881da177e4SLinus Torvalds 9891da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 9901da177e4SLinus Torvalds 9911da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 9921da177e4SLinus Torvalds return nfserr_inval; 9931da177e4SLinus Torvalds 9945ccb0066SStanislav Kinsbursky status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), 9955ccb0066SStanislav Kinsbursky cstate, stateid, WR_STATE, &filp); 996375c5547SJ. Bruce Fields if (status) { 997375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 998375c5547SJ. Bruce Fields return status; 999375c5547SJ. Bruce Fields } 1000375c5547SJ. Bruce Fields 100131dec253SDavid Shaw cnt = write->wr_buflen; 10021da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 1003b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); 10041da177e4SLinus Torvalds 1005ffe1137bSJ. Bruce Fields nvecs = fill_in_write_vector(rqstp->rq_vec, write); 1006ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1007ffe1137bSJ. Bruce Fields 1008ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 1009ffe1137bSJ. Bruce Fields write->wr_offset, rqstp->rq_vec, nvecs, 101031dec253SDavid Shaw &cnt, &write->wr_how_written); 10117e06b7f9SNeilBrown if (filp) 10127e06b7f9SNeilBrown fput(filp); 10131da177e4SLinus Torvalds 101431dec253SDavid Shaw write->wr_bytes_written = cnt; 101531dec253SDavid Shaw 10161da177e4SLinus Torvalds return status; 10171da177e4SLinus Torvalds } 10181da177e4SLinus Torvalds 101924bab491SAnna Schumaker static __be32 102095d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 102195d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 102295d871f0SAnna Schumaker { 102395d871f0SAnna Schumaker __be32 status = nfserr_notsupp; 102495d871f0SAnna Schumaker struct file *file; 102595d871f0SAnna Schumaker 102695d871f0SAnna Schumaker status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate, 102795d871f0SAnna Schumaker &fallocate->falloc_stateid, 102895d871f0SAnna Schumaker WR_STATE, &file); 102995d871f0SAnna Schumaker if (status != nfs_ok) { 103095d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 103195d871f0SAnna Schumaker return status; 103295d871f0SAnna Schumaker } 103395d871f0SAnna Schumaker 103495d871f0SAnna Schumaker status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, 103595d871f0SAnna Schumaker fallocate->falloc_offset, 103695d871f0SAnna Schumaker fallocate->falloc_length, 103795d871f0SAnna Schumaker flags); 103895d871f0SAnna Schumaker fput(file); 103995d871f0SAnna Schumaker return status; 104095d871f0SAnna Schumaker } 104195d871f0SAnna Schumaker 104295d871f0SAnna Schumaker static __be32 104395d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 104495d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate) 104595d871f0SAnna Schumaker { 104695d871f0SAnna Schumaker return nfsd4_fallocate(rqstp, cstate, fallocate, 0); 104795d871f0SAnna Schumaker } 104895d871f0SAnna Schumaker 104995d871f0SAnna Schumaker static __be32 1050b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1051b0cb9085SAnna Schumaker struct nfsd4_fallocate *fallocate) 1052b0cb9085SAnna Schumaker { 1053b0cb9085SAnna Schumaker return nfsd4_fallocate(rqstp, cstate, fallocate, 1054b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1055b0cb9085SAnna Schumaker } 1056b0cb9085SAnna Schumaker 1057b0cb9085SAnna Schumaker static __be32 105824bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 105924bab491SAnna Schumaker struct nfsd4_seek *seek) 106024bab491SAnna Schumaker { 106124bab491SAnna Schumaker int whence; 106224bab491SAnna Schumaker __be32 status; 106324bab491SAnna Schumaker struct file *file; 106424bab491SAnna Schumaker 106524bab491SAnna Schumaker status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate, 106624bab491SAnna Schumaker &seek->seek_stateid, 106724bab491SAnna Schumaker RD_STATE, &file); 106824bab491SAnna Schumaker if (status) { 106924bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 107024bab491SAnna Schumaker return status; 107124bab491SAnna Schumaker } 107224bab491SAnna Schumaker 107324bab491SAnna Schumaker switch (seek->seek_whence) { 107424bab491SAnna Schumaker case NFS4_CONTENT_DATA: 107524bab491SAnna Schumaker whence = SEEK_DATA; 107624bab491SAnna Schumaker break; 107724bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 107824bab491SAnna Schumaker whence = SEEK_HOLE; 107924bab491SAnna Schumaker break; 108024bab491SAnna Schumaker default: 108124bab491SAnna Schumaker status = nfserr_union_notsupp; 108224bab491SAnna Schumaker goto out; 108324bab491SAnna Schumaker } 108424bab491SAnna Schumaker 108524bab491SAnna Schumaker /* 108624bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 108724bab491SAnna Schumaker * should ever file->f_pos. 108824bab491SAnna Schumaker */ 108924bab491SAnna Schumaker seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence); 109024bab491SAnna Schumaker if (seek->seek_pos < 0) 109124bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 109224bab491SAnna Schumaker else if (seek->seek_pos >= i_size_read(file_inode(file))) 109324bab491SAnna Schumaker seek->seek_eof = true; 109424bab491SAnna Schumaker 109524bab491SAnna Schumaker out: 109624bab491SAnna Schumaker fput(file); 109724bab491SAnna Schumaker return status; 109824bab491SAnna Schumaker } 109924bab491SAnna Schumaker 11001da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 11011da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 11021da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 11031da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 11041da177e4SLinus Torvalds */ 1105b37ad28bSAl Viro static __be32 1106c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1107ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 11081da177e4SLinus Torvalds { 11092ebbc012SAl Viro __be32 *buf, *p; 11101da177e4SLinus Torvalds int count; 1111b37ad28bSAl Viro __be32 status; 11121da177e4SLinus Torvalds 11138837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 11141da177e4SLinus Torvalds if (status) 11151da177e4SLinus Torvalds return status; 11161da177e4SLinus Torvalds 11173c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 11183c8e0316SYu Zhiguo if (status) 11193c8e0316SYu Zhiguo return status; 11203c8e0316SYu Zhiguo 11211da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 11221da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 11231da177e4SLinus Torvalds return nfserr_inval; 11241da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 11251da177e4SLinus Torvalds return nfserr_inval; 11261da177e4SLinus Torvalds 11271da177e4SLinus Torvalds /* count in words: 11281da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 11291da177e4SLinus Torvalds */ 11301da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 11311da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 11321da177e4SLinus Torvalds if (!buf) 11333e772463SJ. Bruce Fields return nfserr_jukebox; 11341da177e4SLinus Torvalds 113584822d0bSJ. Bruce Fields p = buf; 1136d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1137ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1138d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1139d5184658SJ. Bruce Fields verify->ve_bmval, 1140406a7ea9SFrank Filz rqstp, 0); 114141ae6e71SJ. Bruce Fields /* 114241ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 114341ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 114441ae6e71SJ. Bruce Fields */ 114584822d0bSJ. Bruce Fields if (status == nfserr_resource) 11461da177e4SLinus Torvalds status = nfserr_not_same; 11471da177e4SLinus Torvalds if (status) 11481da177e4SLinus Torvalds goto out_kfree; 11491da177e4SLinus Torvalds 115095ec28cdSBenny Halevy /* skip bitmap */ 115195ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 11521da177e4SLinus Torvalds status = nfserr_not_same; 11531da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 11541da177e4SLinus Torvalds goto out_kfree; 11551da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 11561da177e4SLinus Torvalds status = nfserr_same; 11571da177e4SLinus Torvalds 11581da177e4SLinus Torvalds out_kfree: 11591da177e4SLinus Torvalds kfree(buf); 11601da177e4SLinus Torvalds return status; 11611da177e4SLinus Torvalds } 11621da177e4SLinus Torvalds 1163c954e2a5SJ.Bruce Fields static __be32 1164c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1165c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1166c954e2a5SJ.Bruce Fields { 1167c954e2a5SJ.Bruce Fields __be32 status; 1168c954e2a5SJ.Bruce Fields 1169c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1170c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1171c954e2a5SJ.Bruce Fields } 1172c954e2a5SJ.Bruce Fields 1173c954e2a5SJ.Bruce Fields static __be32 1174c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1175c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1176c954e2a5SJ.Bruce Fields { 1177c954e2a5SJ.Bruce Fields __be32 status; 1178c954e2a5SJ.Bruce Fields 1179c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1180c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1181c954e2a5SJ.Bruce Fields } 1182c954e2a5SJ.Bruce Fields 11839cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 11849cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 11859cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 11869cf514ccSChristoph Hellwig { 11879cf514ccSChristoph Hellwig if (!exp->ex_layout_type) { 11889cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 11899cf514ccSChristoph Hellwig return NULL; 11909cf514ccSChristoph Hellwig } 11919cf514ccSChristoph Hellwig 11929cf514ccSChristoph Hellwig if (exp->ex_layout_type != layout_type) { 11939cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 11949cf514ccSChristoph Hellwig __func__, layout_type); 11959cf514ccSChristoph Hellwig return NULL; 11969cf514ccSChristoph Hellwig } 11979cf514ccSChristoph Hellwig 11989cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 11999cf514ccSChristoph Hellwig } 12009cf514ccSChristoph Hellwig 12019cf514ccSChristoph Hellwig static __be32 12029cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 12039cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 12049cf514ccSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp) 12059cf514ccSChristoph Hellwig { 12069cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 12079cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 12089cf514ccSChristoph Hellwig struct svc_export *exp; 12099cf514ccSChristoph Hellwig __be32 nfserr; 12109cf514ccSChristoph Hellwig 12119cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 12129cf514ccSChristoph Hellwig __func__, 12139cf514ccSChristoph Hellwig gdp->gd_layout_type, 12149cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 12159cf514ccSChristoph Hellwig gdp->gd_maxcount); 12169cf514ccSChristoph Hellwig 12179cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 12189cf514ccSChristoph Hellwig if (!map) { 12199cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 12209cf514ccSChristoph Hellwig __func__); 12219cf514ccSChristoph Hellwig return nfserr_noent; 12229cf514ccSChristoph Hellwig } 12239cf514ccSChristoph Hellwig 12249cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 12259cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 12269cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 12279cf514ccSChristoph Hellwig return nfserr_noent; 12289cf514ccSChristoph Hellwig } 12299cf514ccSChristoph Hellwig 12309cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 12319cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 12329cf514ccSChristoph Hellwig if (!ops) 12339cf514ccSChristoph Hellwig goto out; 12349cf514ccSChristoph Hellwig 12359cf514ccSChristoph Hellwig nfserr = nfs_ok; 12369cf514ccSChristoph Hellwig if (gdp->gd_maxcount != 0) 12379cf514ccSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, gdp); 12389cf514ccSChristoph Hellwig 12399cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 12409cf514ccSChristoph Hellwig out: 1241*a1420384SKinglong Mee exp_put(exp); 12429cf514ccSChristoph Hellwig return nfserr; 12439cf514ccSChristoph Hellwig } 12449cf514ccSChristoph Hellwig 12459cf514ccSChristoph Hellwig static __be32 12469cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 12479cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 12489cf514ccSChristoph Hellwig struct nfsd4_layoutget *lgp) 12499cf514ccSChristoph Hellwig { 12509cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 12519cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 12529cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 12539cf514ccSChristoph Hellwig __be32 nfserr; 12549cf514ccSChristoph Hellwig int accmode; 12559cf514ccSChristoph Hellwig 12569cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 12579cf514ccSChristoph Hellwig case IOMODE_READ: 12589cf514ccSChristoph Hellwig accmode = NFSD_MAY_READ; 12599cf514ccSChristoph Hellwig break; 12609cf514ccSChristoph Hellwig case IOMODE_RW: 12619cf514ccSChristoph Hellwig accmode = NFSD_MAY_READ | NFSD_MAY_WRITE; 12629cf514ccSChristoph Hellwig break; 12639cf514ccSChristoph Hellwig default: 12649cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 12659cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 12669cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 12679cf514ccSChristoph Hellwig goto out; 12689cf514ccSChristoph Hellwig } 12699cf514ccSChristoph Hellwig 12709cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 12719cf514ccSChristoph Hellwig if (nfserr) 12729cf514ccSChristoph Hellwig goto out; 12739cf514ccSChristoph Hellwig 12749cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 12759cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 12769cf514ccSChristoph Hellwig if (!ops) 12779cf514ccSChristoph Hellwig goto out; 12789cf514ccSChristoph Hellwig 12799cf514ccSChristoph Hellwig /* 12809cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 12819cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 12829cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 12839cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 12849cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 12859cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 12869cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 12879cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 12889cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 12899cf514ccSChristoph Hellwig */ 12909cf514ccSChristoph Hellwig nfserr = nfserr_inval; 12919cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 12929cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 12939cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 12949cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 12959cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 12969cf514ccSChristoph Hellwig goto out; 12979cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 12989cf514ccSChristoph Hellwig goto out; 12999cf514ccSChristoph Hellwig 13009cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 13019cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 130231ef83dcSChristoph Hellwig if (nfserr) { 130331ef83dcSChristoph Hellwig trace_layout_get_lookup_fail(&lgp->lg_sid); 13049cf514ccSChristoph Hellwig goto out; 130531ef83dcSChristoph Hellwig } 13069cf514ccSChristoph Hellwig 1307c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1308c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1309c5c707f9SChristoph Hellwig goto out_put_stid; 1310c5c707f9SChristoph Hellwig 13119cf514ccSChristoph Hellwig nfserr = ops->proc_layoutget(current_fh->fh_dentry->d_inode, 13129cf514ccSChristoph Hellwig current_fh, lgp); 13139cf514ccSChristoph Hellwig if (nfserr) 13149cf514ccSChristoph Hellwig goto out_put_stid; 13159cf514ccSChristoph Hellwig 13169cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 13179cf514ccSChristoph Hellwig 13189cf514ccSChristoph Hellwig out_put_stid: 13199cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 13209cf514ccSChristoph Hellwig out: 13219cf514ccSChristoph Hellwig return nfserr; 13229cf514ccSChristoph Hellwig } 13239cf514ccSChristoph Hellwig 13249cf514ccSChristoph Hellwig static __be32 13259cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 13269cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 13279cf514ccSChristoph Hellwig struct nfsd4_layoutcommit *lcp) 13289cf514ccSChristoph Hellwig { 13299cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 13309cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 13319cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 13329cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 13339cf514ccSChristoph Hellwig struct inode *inode; 13349cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 13359cf514ccSChristoph Hellwig __be32 nfserr; 13369cf514ccSChristoph Hellwig 13379cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 13389cf514ccSChristoph Hellwig if (nfserr) 13399cf514ccSChristoph Hellwig goto out; 13409cf514ccSChristoph Hellwig 13419cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 13429cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 13439cf514ccSChristoph Hellwig if (!ops) 13449cf514ccSChristoph Hellwig goto out; 13459cf514ccSChristoph Hellwig inode = current_fh->fh_dentry->d_inode; 13469cf514ccSChristoph Hellwig 13479cf514ccSChristoph Hellwig nfserr = nfserr_inval; 13489cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 13499cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 13509cf514ccSChristoph Hellwig goto out; 13519cf514ccSChristoph Hellwig } 13529cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 13539cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 13549cf514ccSChristoph Hellwig goto out; 13559cf514ccSChristoph Hellwig } 13569cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 13579cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 13589cf514ccSChristoph Hellwig goto out; 13599cf514ccSChristoph Hellwig } 13609cf514ccSChristoph Hellwig 13619cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 13629cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 13639cf514ccSChristoph Hellwig &ls); 13649cf514ccSChristoph Hellwig if (nfserr) { 136531ef83dcSChristoph Hellwig trace_layout_commit_lookup_fail(&lcp->lc_sid); 13669cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 13679cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 13689cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 13699cf514ccSChristoph Hellwig goto out; 13709cf514ccSChristoph Hellwig } 13719cf514ccSChristoph Hellwig 13729cf514ccSChristoph Hellwig nfserr = ops->proc_layoutcommit(inode, lcp); 13739cf514ccSChristoph Hellwig if (nfserr) 13749cf514ccSChristoph Hellwig goto out_put_stid; 13759cf514ccSChristoph Hellwig 13769cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 13779cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 13789cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 13799cf514ccSChristoph Hellwig } else { 13809cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 13819cf514ccSChristoph Hellwig } 13829cf514ccSChristoph Hellwig 13839cf514ccSChristoph Hellwig out_put_stid: 13849cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 13859cf514ccSChristoph Hellwig out: 13869cf514ccSChristoph Hellwig return nfserr; 13879cf514ccSChristoph Hellwig } 13889cf514ccSChristoph Hellwig 13899cf514ccSChristoph Hellwig static __be32 13909cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 13919cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 13929cf514ccSChristoph Hellwig struct nfsd4_layoutreturn *lrp) 13939cf514ccSChristoph Hellwig { 13949cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 13959cf514ccSChristoph Hellwig __be32 nfserr; 13969cf514ccSChristoph Hellwig 13979cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 13989cf514ccSChristoph Hellwig if (nfserr) 13999cf514ccSChristoph Hellwig goto out; 14009cf514ccSChristoph Hellwig 14019cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 14029cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 14039cf514ccSChristoph Hellwig goto out; 14049cf514ccSChristoph Hellwig 14059cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 14069cf514ccSChristoph Hellwig case IOMODE_READ: 14079cf514ccSChristoph Hellwig case IOMODE_RW: 14089cf514ccSChristoph Hellwig case IOMODE_ANY: 14099cf514ccSChristoph Hellwig break; 14109cf514ccSChristoph Hellwig default: 14119cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 14129cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 14139cf514ccSChristoph Hellwig nfserr = nfserr_inval; 14149cf514ccSChristoph Hellwig goto out; 14159cf514ccSChristoph Hellwig } 14169cf514ccSChristoph Hellwig 14179cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 14189cf514ccSChristoph Hellwig case RETURN_FILE: 14199cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 14209cf514ccSChristoph Hellwig break; 14219cf514ccSChristoph Hellwig case RETURN_FSID: 14229cf514ccSChristoph Hellwig case RETURN_ALL: 14239cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 14249cf514ccSChristoph Hellwig break; 14259cf514ccSChristoph Hellwig default: 14269cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 14279cf514ccSChristoph Hellwig lrp->lr_return_type); 14289cf514ccSChristoph Hellwig nfserr = nfserr_inval; 14299cf514ccSChristoph Hellwig break; 14309cf514ccSChristoph Hellwig } 14319cf514ccSChristoph Hellwig out: 14329cf514ccSChristoph Hellwig return nfserr; 14339cf514ccSChristoph Hellwig } 14349cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 14359cf514ccSChristoph Hellwig 14361da177e4SLinus Torvalds /* 14371da177e4SLinus Torvalds * NULL call. 14381da177e4SLinus Torvalds */ 14397111c66eSAl Viro static __be32 14401da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 14411da177e4SLinus Torvalds { 14421da177e4SLinus Torvalds return nfs_ok; 14431da177e4SLinus Torvalds } 14441da177e4SLinus Torvalds 1445e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1446e2b20950SShankar Anand { 1447e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1448e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1449e2b20950SShankar Anand } 1450e2b20950SShankar Anand 1451b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 1452b591480bSJ.Bruce Fields void *); 145358e7b33aSMi Jinlong typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op); 14548b70484cSTigran Mkrtchyan typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *); 14558b70484cSTigran Mkrtchyan typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *); 145658e7b33aSMi Jinlong 1457f9bb94c4SAndy Adamson enum nfsd4_op_flags { 1458f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 14595ece3cafSMi Jinlong ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 14605ece3cafSMi Jinlong ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 146168d93184SJ. Bruce Fields /* For rfc 5661 section 2.6.3.1.1: */ 146268d93184SJ. Bruce Fields OP_HANDLES_WRONGSEC = 1 << 3, 146368d93184SJ. Bruce Fields OP_IS_PUTFH_LIKE = 1 << 4, 14641091006cSJ. Bruce Fields /* 1465c856694eSJ. Bruce Fields * These are the ops whose result size we estimate before 1466c856694eSJ. Bruce Fields * encoding, to avoid performing an op then not being able to 1467c856694eSJ. Bruce Fields * respond or cache a response. This includes writes and setattrs 1468c856694eSJ. Bruce Fields * as well as the operations usually called "nonidempotent": 1469c856694eSJ. Bruce Fields */ 1470c856694eSJ. Bruce Fields OP_MODIFIES_SOMETHING = 1 << 5, 1471c856694eSJ. Bruce Fields /* 1472c856694eSJ. Bruce Fields * Cache compounds containing these ops in the xid-based drc: 14731091006cSJ. Bruce Fields * We use the DRC for compounds containing non-idempotent 14741091006cSJ. Bruce Fields * operations, *except* those that are 4.1-specific (since 14751091006cSJ. Bruce Fields * sessions provide their own EOS), and except for stateful 14761091006cSJ. Bruce Fields * operations other than setclientid and setclientid_confirm 14771091006cSJ. Bruce Fields * (since sequence numbers provide EOS for open, lock, etc in 14781091006cSJ. Bruce Fields * the v4.0 case). 14791091006cSJ. Bruce Fields */ 1480c856694eSJ. Bruce Fields OP_CACHEME = 1 << 6, 14818b70484cSTigran Mkrtchyan /* 14828b70484cSTigran Mkrtchyan * These are ops which clear current state id. 14838b70484cSTigran Mkrtchyan */ 14848b70484cSTigran Mkrtchyan OP_CLEAR_STATEID = 1 << 7, 1485c856694eSJ. Bruce Fields }; 1486c856694eSJ. Bruce Fields 1487c856694eSJ. Bruce Fields struct nfsd4_operation { 1488c856694eSJ. Bruce Fields nfsd4op_func op_func; 1489c856694eSJ. Bruce Fields u32 op_flags; 1490c856694eSJ. Bruce Fields char *op_name; 149158e7b33aSMi Jinlong /* Try to get response size before operation */ 149258e7b33aSMi Jinlong nfsd4op_rsize op_rsize_bop; 149324ff99c6SBryan Schumaker stateid_getter op_get_currentstateid; 149424ff99c6SBryan Schumaker stateid_setter op_set_currentstateid; 1495b591480bSJ.Bruce Fields }; 1496b591480bSJ.Bruce Fields 1497b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 1498b591480bSJ.Bruce Fields 1499f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1500b001a1b6SBenny Halevy 15011da177e4SLinus Torvalds /* 150257716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1503f9bb94c4SAndy Adamson * 150457716355SJ. Bruce Fields * Also note, enforced elsewhere: 150557716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 150657716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 15071d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 15081d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 150957716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 151057716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 151157716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1512f9bb94c4SAndy Adamson */ 151357716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1514f9bb94c4SAndy Adamson { 1515f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 151657716355SJ. Bruce Fields 151757716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 151857716355SJ. Bruce Fields if (args->minorversion == 0) 151957716355SJ. Bruce Fields return nfs_ok; 152057716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 152157716355SJ. Bruce Fields if (args->opcnt == 0) 152257716355SJ. Bruce Fields return nfs_ok; 152357716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 152457716355SJ. Bruce Fields return nfs_ok; 152557716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 152657716355SJ. Bruce Fields return nfserr_op_not_in_session; 152757716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 152857716355SJ. Bruce Fields return nfs_ok; 152957716355SJ. Bruce Fields if (args->opcnt != 1) 153057716355SJ. Bruce Fields return nfserr_not_only_op; 153157716355SJ. Bruce Fields return nfs_ok; 1532f9bb94c4SAndy Adamson } 1533f9bb94c4SAndy Adamson 153422b03214SJ. Bruce Fields static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 153522b03214SJ. Bruce Fields { 153622b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 153722b03214SJ. Bruce Fields } 153822b03214SJ. Bruce Fields 15391091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 15401091006cSJ. Bruce Fields { 1541e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 1542e372ba60SJ. Bruce Fields return false; 1543c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 15441091006cSJ. Bruce Fields } 15451091006cSJ. Bruce Fields 154668d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 154768d93184SJ. Bruce Fields { 154868d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 154968d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 155068d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 155168d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 155268d93184SJ. Bruce Fields struct nfsd4_operation *thisd; 155368d93184SJ. Bruce Fields struct nfsd4_operation *nextd; 155468d93184SJ. Bruce Fields 155568d93184SJ. Bruce Fields thisd = OPDESC(this); 155668d93184SJ. Bruce Fields /* 155768d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 155868d93184SJ. Bruce Fields * have special rules. 155968d93184SJ. Bruce Fields */ 156068d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 156168d93184SJ. Bruce Fields return false; 156268d93184SJ. Bruce Fields /* 156368d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 156468d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 156568d93184SJ. Bruce Fields * result: 156668d93184SJ. Bruce Fields */ 156768d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 156868d93184SJ. Bruce Fields return false; 156951904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 157051904b08SJ. Bruce Fields return false; 157168d93184SJ. Bruce Fields nextd = OPDESC(next); 157268d93184SJ. Bruce Fields /* 157368d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 157468d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 157568d93184SJ. Bruce Fields * now: 157668d93184SJ. Bruce Fields */ 157768d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 157868d93184SJ. Bruce Fields } 157968d93184SJ. Bruce Fields 15802d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 15812d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 15822d124dfaSJ. Bruce Fields { 15832d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 15842d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 15852d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 15862d124dfaSJ. Bruce Fields 15872d124dfaSJ. Bruce Fields xdr->buf = buf; 1588ddd1ea56SJ. Bruce Fields xdr->iov = head; 15892d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 1590a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 15916ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 15926ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 15932825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 159405638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 15952825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 1596a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 15972d124dfaSJ. Bruce Fields } 15982d124dfaSJ. Bruce Fields 1599f9bb94c4SAndy Adamson /* 16001da177e4SLinus Torvalds * COMPOUND call. 16011da177e4SLinus Torvalds */ 16027111c66eSAl Viro static __be32 16031da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 16041da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 16051da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 16061da177e4SLinus Torvalds { 16071da177e4SLinus Torvalds struct nfsd4_op *op; 1608b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1609e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 16104daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 16114daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1612b37ad28bSAl Viro __be32 status; 16131da177e4SLinus Torvalds 16142d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 16154aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 16161da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 1617d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 16181da177e4SLinus Torvalds resp->taglen = args->taglen; 16191da177e4SLinus Torvalds resp->tag = args->tag; 16201da177e4SLinus Torvalds resp->rqstp = rqstp; 16214daeed25SKinglong Mee cstate->minorversion = args->minorversion; 16224daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 16234daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 16248ff30fa4SNeilBrown /* 16258ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 16268ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 16278ff30fa4SNeilBrown */ 162830660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 16291da177e4SLinus Torvalds 16301da177e4SLinus Torvalds /* 16311da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 16321da177e4SLinus Torvalds */ 16331da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 163435f7a14fSJ. Bruce Fields if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) 16351da177e4SLinus Torvalds goto out; 16361da177e4SLinus Torvalds 163757716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 163857716355SJ. Bruce Fields if (status) { 1639f9bb94c4SAndy Adamson op = &args->ops[0]; 164057716355SJ. Bruce Fields op->status = status; 1641f9bb94c4SAndy Adamson goto encode_op; 1642f9bb94c4SAndy Adamson } 1643f9bb94c4SAndy Adamson 16441da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 16451da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 16461da177e4SLinus Torvalds 1647b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1648b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1649b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 16501da177e4SLinus Torvalds /* 16511da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 16521da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 16531da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 16541da177e4SLinus Torvalds */ 16559d313b17SJ. Bruce Fields if (op->status) { 16569d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 16579d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 16581da177e4SLinus Torvalds goto encode_op; 16599d313b17SJ. Bruce Fields } 16601da177e4SLinus Torvalds 166122b03214SJ. Bruce Fields opdesc = OPDESC(op); 1662b591480bSJ.Bruce Fields 16634daeed25SKinglong Mee if (!current_fh->fh_dentry) { 166427d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 16651da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 16661da177e4SLinus Torvalds goto encode_op; 16671da177e4SLinus Torvalds } 16684daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1669eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 167042ca0993SJ.Bruce Fields op->status = nfserr_moved; 167142ca0993SJ.Bruce Fields goto encode_op; 167242ca0993SJ.Bruce Fields } 1673b591480bSJ.Bruce Fields 16742336745eSKinglong Mee fh_clear_wcc(current_fh); 16752336745eSKinglong Mee 167658e7b33aSMi Jinlong /* If op is non-idempotent */ 167758e7b33aSMi Jinlong if (opdesc->op_flags & OP_MODIFIES_SOMETHING) { 16784c69d585SJ. Bruce Fields /* 1679a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 1680a8095f7eSJ. Bruce Fields * succesful reply: 1681a8095f7eSJ. Bruce Fields */ 1682a8095f7eSJ. Bruce Fields u32 plen = opdesc->op_rsize_bop(rqstp, op); 1683a8095f7eSJ. Bruce Fields /* 1684a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 16854c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 16864c69d585SJ. Bruce Fields */ 16874c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 16884c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 168958e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 169058e7b33aSMi Jinlong } 169158e7b33aSMi Jinlong 169258e7b33aSMi Jinlong if (op->status) 169358e7b33aSMi Jinlong goto encode_op; 169458e7b33aSMi Jinlong 16958b70484cSTigran Mkrtchyan if (opdesc->op_get_currentstateid) 16968b70484cSTigran Mkrtchyan opdesc->op_get_currentstateid(cstate, &op->u); 1697b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 16981da177e4SLinus Torvalds 16998b70484cSTigran Mkrtchyan if (!op->status) { 17008b70484cSTigran Mkrtchyan if (opdesc->op_set_currentstateid) 17018b70484cSTigran Mkrtchyan opdesc->op_set_currentstateid(cstate, &op->u); 17028b70484cSTigran Mkrtchyan 17038b70484cSTigran Mkrtchyan if (opdesc->op_flags & OP_CLEAR_STATEID) 170437c593c5STigran Mkrtchyan clear_current_stateid(cstate); 17058b70484cSTigran Mkrtchyan 17068b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 17074daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 17088b70484cSTigran Mkrtchyan } 170968d93184SJ. Bruce Fields 17101da177e4SLinus Torvalds encode_op: 171149557cc7SAndy Adamson /* Only from SEQUENCE */ 17124daeed25SKinglong Mee if (cstate->status == nfserr_replay_cache) { 1713da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1714da3846a2SAndy Adamson status = op->status; 1715da3846a2SAndy Adamson goto out; 1716da3846a2SAndy Adamson } 1717a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1718a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 1719d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 17201da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 17211da177e4SLinus Torvalds } else { 17221da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 17231da177e4SLinus Torvalds status = op->status; 17241da177e4SLinus Torvalds } 17250407717dSBenny Halevy 17260407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 17270407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 17280407717dSBenny Halevy be32_to_cpu(status)); 17290407717dSBenny Halevy 173058fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 17317e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 17327e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 17337e06b7f9SNeilBrown fput(op->u.read.rd_filp); 1734e2b20950SShankar Anand 1735e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 17361da177e4SLinus Torvalds } 17371da177e4SLinus Torvalds 17384daeed25SKinglong Mee cstate->status = status; 17394daeed25SKinglong Mee fh_put(current_fh); 17404daeed25SKinglong Mee fh_put(save_fh); 17414daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 17421da177e4SLinus Torvalds out: 17432f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 174430660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 17453b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 17461da177e4SLinus Torvalds return status; 17471da177e4SLinus Torvalds } 17481da177e4SLinus Torvalds 174958e7b33aSMi Jinlong #define op_encode_hdr_size (2) 175058e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 175158e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 175258e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 175358e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 175458e7b33aSMi Jinlong 17558c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 17568c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 175758e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 175858e7b33aSMi Jinlong 175958e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 176058e7b33aSMi Jinlong 176158e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 176258e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 176358e7b33aSMi Jinlong op_encode_ace_maxsz) 176458e7b33aSMi Jinlong 176558e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 176658e7b33aSMi Jinlong 176758e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 176858e7b33aSMi Jinlong { 176958e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 177058e7b33aSMi Jinlong } 177158e7b33aSMi Jinlong 177258e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 177358e7b33aSMi Jinlong { 177458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 177558e7b33aSMi Jinlong } 177658e7b33aSMi Jinlong 177758e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 177858e7b33aSMi Jinlong { 177958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 178058e7b33aSMi Jinlong } 178158e7b33aSMi Jinlong 178258e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 178358e7b33aSMi Jinlong { 178458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 178558e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 178658e7b33aSMi Jinlong } 178758e7b33aSMi Jinlong 1788b86cef60SJ. Bruce Fields /* 1789b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 1790b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 1791b86cef60SJ. Bruce Fields * reads unnecessarily. 1792b86cef60SJ. Bruce Fields */ 1793b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 1794b86cef60SJ. Bruce Fields struct nfsd4_op *op) 1795b86cef60SJ. Bruce Fields { 1796b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 1797b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 1798b86cef60SJ. Bruce Fields u32 ret = 0; 1799b86cef60SJ. Bruce Fields 1800b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 1801b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 1802b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 1803b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 1804b86cef60SJ. Bruce Fields 1805b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 1806b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 1807b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 1808b86cef60SJ. Bruce Fields } 1809b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 1810b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 1811b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 1812b86cef60SJ. Bruce Fields } 1813b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 1814b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 1815b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 1816b86cef60SJ. Bruce Fields } 1817b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 1818b86cef60SJ. Bruce Fields ret += NFSD4_MAX_SEC_LABEL_LEN + 12; 1819b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 1820b86cef60SJ. Bruce Fields } 1821b86cef60SJ. Bruce Fields /* 1822b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 1823b86cef60SJ. Bruce Fields * supported_attributes) 1824b86cef60SJ. Bruce Fields */ 1825b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 1826b86cef60SJ. Bruce Fields /* bitmask, length */ 1827b86cef60SJ. Bruce Fields ret += 20; 1828b86cef60SJ. Bruce Fields return ret; 1829b86cef60SJ. Bruce Fields } 1830b86cef60SJ. Bruce Fields 183158e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 183258e7b33aSMi Jinlong { 183358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 183458e7b33aSMi Jinlong * sizeof(__be32); 183558e7b33aSMi Jinlong } 183658e7b33aSMi Jinlong 183758e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 183858e7b33aSMi Jinlong { 183958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 184058e7b33aSMi Jinlong * sizeof(__be32); 184158e7b33aSMi Jinlong } 184258e7b33aSMi Jinlong 184358e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 184458e7b33aSMi Jinlong { 184558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 184658e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 184758e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 184858e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 184958e7b33aSMi Jinlong } 185058e7b33aSMi Jinlong 185158e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 185258e7b33aSMi Jinlong { 185358e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 185458e7b33aSMi Jinlong 185558e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 18563c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 185758e7b33aSMi Jinlong 1858622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 185958e7b33aSMi Jinlong } 186058e7b33aSMi Jinlong 186158e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 186258e7b33aSMi Jinlong { 18633c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 186458e7b33aSMi Jinlong 18653c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 18663c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 186758e7b33aSMi Jinlong 1868561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 1869561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 187058e7b33aSMi Jinlong } 187158e7b33aSMi Jinlong 187258e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 187358e7b33aSMi Jinlong { 187458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 187558e7b33aSMi Jinlong * sizeof(__be32); 187658e7b33aSMi Jinlong } 187758e7b33aSMi Jinlong 187858e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 187958e7b33aSMi Jinlong { 188058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 188158e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 188258e7b33aSMi Jinlong } 188358e7b33aSMi Jinlong 1884ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 1885ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 1886ccae70a9SJ. Bruce Fields { 1887d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 1888d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 1889ccae70a9SJ. Bruce Fields } 1890ccae70a9SJ. Bruce Fields 189158e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 189258e7b33aSMi Jinlong { 189358e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 189458e7b33aSMi Jinlong } 189558e7b33aSMi Jinlong 189658e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 189758e7b33aSMi Jinlong { 1898480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 1899480efaeeSJ. Bruce Fields sizeof(__be32); 190058e7b33aSMi Jinlong } 190158e7b33aSMi Jinlong 190258e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 190358e7b33aSMi Jinlong { 1904f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 190558e7b33aSMi Jinlong } 190658e7b33aSMi Jinlong 190758e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 190858e7b33aSMi Jinlong { 190958e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 1910a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 1911a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 191258e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 191358e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 191458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 191558e7b33aSMi Jinlong /* eir_server_scope<> */\ 191658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 191758e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 191858e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 191958e7b33aSMi Jinlong } 192058e7b33aSMi Jinlong 192158e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 192258e7b33aSMi Jinlong { 192358e7b33aSMi Jinlong return (op_encode_hdr_size + \ 192458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 192558e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 192658e7b33aSMi Jinlong } 192758e7b33aSMi Jinlong 192858e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 192958e7b33aSMi Jinlong { 193058e7b33aSMi Jinlong return (op_encode_hdr_size + \ 193158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 193258e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 193358e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 193458e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 193558e7b33aSMi Jinlong } 193658e7b33aSMi Jinlong 19379cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 19389cf514ccSChristoph Hellwig /* 19399cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 19409cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 19419cf514ccSChristoph Hellwig */ 19429cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 19439cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19449cf514ccSChristoph Hellwig { 19459cf514ccSChristoph Hellwig return (op_encode_hdr_size + 19469cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 19479cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 19489cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 19499cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 19509cf514ccSChristoph Hellwig } 19519cf514ccSChristoph Hellwig 19529cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19539cf514ccSChristoph Hellwig { 19549cf514ccSChristoph Hellwig return (op_encode_hdr_size + 19559cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 19569cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 19579cf514ccSChristoph Hellwig } 19589cf514ccSChristoph Hellwig 19599cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19609cf514ccSChristoph Hellwig { 19619cf514ccSChristoph Hellwig return (op_encode_hdr_size + 19629cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 19639cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 19649cf514ccSChristoph Hellwig } 19659cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 19669cf514ccSChristoph Hellwig 196720766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1968b591480bSJ.Bruce Fields [OP_ACCESS] = { 1969b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1970b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1971b591480bSJ.Bruce Fields }, 1972b591480bSJ.Bruce Fields [OP_CLOSE] = { 1973b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 197458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1975b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 197658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 19778b70484cSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid, 19788b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid, 1979b591480bSJ.Bruce Fields }, 1980b591480bSJ.Bruce Fields [OP_COMMIT] = { 1981b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 198258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1983b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 198458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize, 1985b591480bSJ.Bruce Fields }, 1986b591480bSJ.Bruce Fields [OP_CREATE] = { 1987b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1988d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 1989b001a1b6SBenny Halevy .op_name = "OP_CREATE", 199058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize, 1991b591480bSJ.Bruce Fields }, 1992b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1993b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 199458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1995b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 199658e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 19979428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid, 1998b591480bSJ.Bruce Fields }, 1999b591480bSJ.Bruce Fields [OP_GETATTR] = { 2000b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 2001eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2002b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2003b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2004b591480bSJ.Bruce Fields }, 2005b591480bSJ.Bruce Fields [OP_GETFH] = { 2006b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 2007b001a1b6SBenny Halevy .op_name = "OP_GETFH", 2008b591480bSJ.Bruce Fields }, 2009b591480bSJ.Bruce Fields [OP_LINK] = { 2010b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 2011c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2012c856694eSJ. Bruce Fields | OP_CACHEME, 2013b001a1b6SBenny Halevy .op_name = "OP_LINK", 201458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize, 2015b591480bSJ.Bruce Fields }, 2016b591480bSJ.Bruce Fields [OP_LOCK] = { 2017b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 201858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2019b001a1b6SBenny Halevy .op_name = "OP_LOCK", 202058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, 202162cd4a59STigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid, 2022b591480bSJ.Bruce Fields }, 2023b591480bSJ.Bruce Fields [OP_LOCKT] = { 2024b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 2025b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 2026b591480bSJ.Bruce Fields }, 2027b591480bSJ.Bruce Fields [OP_LOCKU] = { 2028b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 202958e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2030b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 203158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 203262cd4a59STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid, 2033b591480bSJ.Bruce Fields }, 2034b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2035b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 2036d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2037b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 2038b591480bSJ.Bruce Fields }, 2039b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2040b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 2041d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2042b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 2043b591480bSJ.Bruce Fields }, 2044b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2045b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 2046b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 2047b591480bSJ.Bruce Fields }, 2048b591480bSJ.Bruce Fields [OP_OPEN] = { 2049b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 205058e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2051b001a1b6SBenny Halevy .op_name = "OP_OPEN", 205258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize, 20538b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid, 2054b591480bSJ.Bruce Fields }, 2055b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2056b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 205758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2058b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 205958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 2060b591480bSJ.Bruce Fields }, 2061b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2062b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 206358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2064b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 206558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 20669428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid, 20679428fe1aSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid, 2068b591480bSJ.Bruce Fields }, 2069b591480bSJ.Bruce Fields [OP_PUTFH] = { 2070b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 207168d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 20725b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2073b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 207458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2075b591480bSJ.Bruce Fields }, 2076eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2077a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 207868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 20795b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2080b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 208158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2082eeac294eSJ.Bruce Fields }, 2083b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2084b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 208568d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 20865b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2087b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 208858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2089b591480bSJ.Bruce Fields }, 2090b591480bSJ.Bruce Fields [OP_READ] = { 2091b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 2092b001a1b6SBenny Halevy .op_name = "OP_READ", 209358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, 209430813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, 2095b591480bSJ.Bruce Fields }, 2096b591480bSJ.Bruce Fields [OP_READDIR] = { 2097b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 2098b001a1b6SBenny Halevy .op_name = "OP_READDIR", 209958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, 2100b591480bSJ.Bruce Fields }, 2101b591480bSJ.Bruce Fields [OP_READLINK] = { 2102b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 2103b001a1b6SBenny Halevy .op_name = "OP_READLINK", 2104b591480bSJ.Bruce Fields }, 2105b591480bSJ.Bruce Fields [OP_REMOVE] = { 2106b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 2107c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2108b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 210958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize, 2110b591480bSJ.Bruce Fields }, 2111b591480bSJ.Bruce Fields [OP_RENAME] = { 2112b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 2113c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 211458e7b33aSMi Jinlong .op_name = "OP_RENAME", 211558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize, 2116b591480bSJ.Bruce Fields }, 2117b591480bSJ.Bruce Fields [OP_RENEW] = { 2118b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 211958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 212058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2121b001a1b6SBenny Halevy .op_name = "OP_RENEW", 212258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 212358e7b33aSMi Jinlong 2124b591480bSJ.Bruce Fields }, 2125b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2126b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 212768d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 212858e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2129b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 213058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2131b591480bSJ.Bruce Fields }, 2132b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2133b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 213458e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2135b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 213658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2137b591480bSJ.Bruce Fields }, 2138dcb488a3SAndy Adamson [OP_SECINFO] = { 2139dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 214068d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2141b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 2142dcb488a3SAndy Adamson }, 2143b591480bSJ.Bruce Fields [OP_SETATTR] = { 2144b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 2145b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2146c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 214758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize, 21481e97b519STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid, 2149b591480bSJ.Bruce Fields }, 2150b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2151b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 215258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2153c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2154b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 215558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize, 2156b591480bSJ.Bruce Fields }, 2157b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2158b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 215958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2160c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2161b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 216258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2163b591480bSJ.Bruce Fields }, 2164b591480bSJ.Bruce Fields [OP_VERIFY] = { 2165b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 2166b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 2167b591480bSJ.Bruce Fields }, 2168b591480bSJ.Bruce Fields [OP_WRITE] = { 2169b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 2170c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2171b001a1b6SBenny Halevy .op_name = "OP_WRITE", 217258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 217330813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid, 2174b591480bSJ.Bruce Fields }, 2175b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2176b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 217758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 217858e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2179b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 218058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2181b591480bSJ.Bruce Fields }, 2182069b6ad4SAndy Adamson 2183069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2184069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2185069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 218658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 218758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2188069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 218958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize, 2190069b6ad4SAndy Adamson }, 2191cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2192cb73a9f4SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_backchannel_ctl, 2193cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2194cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 2195cb73a9f4SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2196cb73a9f4SJ. Bruce Fields }, 21971d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 21981d1bc8f2SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, 219958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 220058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 22011d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 220258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize, 22031d1bc8f2SJ. Bruce Fields }, 2204069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2205069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 220658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 220758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2208069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 220958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize, 2210069b6ad4SAndy Adamson }, 2211069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2212069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 221358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 221458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2215069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 221658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2217069b6ad4SAndy Adamson }, 2218069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2219069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 2220f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2221069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 2222d1d84c96SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize, 2223069b6ad4SAndy Adamson }, 2224094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2225345c2842SMi Jinlong .op_func = (nfsd4op_func)nfsd4_destroy_clientid, 222658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 222758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2228094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 222958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2230094b5d74SBenny Halevy }, 22314dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 22324dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 223358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 22344dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 223558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 22364dc6ec00SJ. Bruce Fields }, 223704f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 223804f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 223968d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 224004f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 224104f4ad16SJ. Bruce Fields }, 224217456804SBryan Schumaker [OP_TEST_STATEID] = { 224317456804SBryan Schumaker .op_func = (nfsd4op_func)nfsd4_test_stateid, 224417456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 224517456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 224617456804SBryan Schumaker }, 2247e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 2248e1ca12dfSBryan Schumaker .op_func = (nfsd4op_func)nfsd4_free_stateid, 224958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2250e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 2251a1dc6955SJ. Bruce Fields .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid, 225258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2253e1ca12dfSBryan Schumaker }, 22549cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 22559cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 22569cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_getdeviceinfo, 22579cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 22589cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 22599cf514ccSChristoph Hellwig }, 22609cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 22619cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutget, 22629cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 22639cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 22649cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize, 22659cf514ccSChristoph Hellwig }, 22669cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 22679cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutcommit, 22689cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 22699cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 22709cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize, 22719cf514ccSChristoph Hellwig }, 22729cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 22739cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutreturn, 22749cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 22759cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 22769cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize, 22779cf514ccSChristoph Hellwig }, 22789cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 227924bab491SAnna Schumaker 228024bab491SAnna Schumaker /* NFSv4.2 operations */ 228195d871f0SAnna Schumaker [OP_ALLOCATE] = { 228295d871f0SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_allocate, 228395d871f0SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 228495d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 228595d871f0SAnna Schumaker .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 228695d871f0SAnna Schumaker }, 2287b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 2288b0cb9085SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_deallocate, 2289b0cb9085SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2290b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 2291b0cb9085SAnna Schumaker .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 2292b0cb9085SAnna Schumaker }, 229324bab491SAnna Schumaker [OP_SEEK] = { 229424bab491SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_seek, 229524bab491SAnna Schumaker .op_name = "OP_SEEK", 229624bab491SAnna Schumaker }, 2297b591480bSJ.Bruce Fields }; 2298b591480bSJ.Bruce Fields 22994f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 23004f0cefbfSJ. Bruce Fields { 23014f0cefbfSJ. Bruce Fields struct nfsd4_operation *opdesc; 23024f0cefbfSJ. Bruce Fields nfsd4op_rsize estimator; 23034f0cefbfSJ. Bruce Fields 23044f0cefbfSJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 23054f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 23064f0cefbfSJ. Bruce Fields opdesc = OPDESC(op); 23074f0cefbfSJ. Bruce Fields estimator = opdesc->op_rsize_bop; 23084f0cefbfSJ. Bruce Fields return estimator ? estimator(rqstp, op) : PAGE_SIZE; 23094f0cefbfSJ. Bruce Fields } 23104f0cefbfSJ. Bruce Fields 231107d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 231207d1f802SJ. Bruce Fields { 231307d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 231407d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 231507d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 231607d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 231707d1f802SJ. Bruce Fields } 231807d1f802SJ. Bruce Fields } 231907d1f802SJ. Bruce Fields 2320f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 2321b001a1b6SBenny Halevy { 2322b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 2323b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 2324b001a1b6SBenny Halevy return "unknown_operation"; 2325b001a1b6SBenny Halevy } 2326b001a1b6SBenny Halevy 23271da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 23281da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 23291da177e4SLinus Torvalds 23301da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 23310a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 23320a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_null, 23330a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 23340a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 23350a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 23360a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 23370a93a47fSYu Zhiguo .pc_xdrressize = 1, 23380a93a47fSYu Zhiguo }, 23390a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 23400a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_compound, 23410a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 23420a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 23430a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 23440a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 23453e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 23460a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 23470a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 23480a93a47fSYu Zhiguo }, 23491da177e4SLinus Torvalds }; 23501da177e4SLinus Torvalds 23511da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 23521da177e4SLinus Torvalds .vs_vers = 4, 23531da177e4SLinus Torvalds .vs_nproc = 2, 23541da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 23551da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 23561da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 23577e55b59bSKinglong Mee .vs_rpcb_optnl = 1, 23581da177e4SLinus Torvalds }; 23591da177e4SLinus Torvalds 23601da177e4SLinus Torvalds /* 23611da177e4SLinus Torvalds * Local variables: 23621da177e4SLinus Torvalds * c-basic-offset: 8 23631da177e4SLinus Torvalds * End: 23641da177e4SLinus Torvalds */ 2365