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 { 552b0143b5SDavid Howells struct inode *inode = d_inode(resfh->fh_dentry); 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) { 1132b0143b5SDavid Howells if (!IS_POSIXACL(d_inode(dentry))) 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 { 2122b0143b5SDavid Howells umode_t mode = d_inode(fh->fh_dentry)->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; 3653320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3663320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 3676668958fSAndy Adamson 368fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3691da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 370fe0750e5SJ. Bruce Fields open->op_openowner); 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds /* This check required by spec. */ 3731da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3741da177e4SLinus Torvalds return nfserr_inval; 3751da177e4SLinus Torvalds 376856121b2SJ. Bruce Fields open->op_created = 0; 377ab1350b2SMi Jinlong /* 378ab1350b2SMi Jinlong * RFC5661 18.51.3 379ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 380ab1350b2SMi Jinlong */ 381ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 382a52d726bSJeff Layton !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, 383a52d726bSJeff Layton &cstate->session->se_client->cl_flags) && 384ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 385ab1350b2SMi Jinlong return nfserr_grace; 386ab1350b2SMi Jinlong 38760adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 38860adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 38960adfc50SAndy Adamson 3901da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 391*6cd22668SKinglong Mee status = nfsd4_process_open1(cstate, open, nn); 392a90b061cSAl Viro if (status == nfserr_replay_me) { 393fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 394ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 395a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 396a4773c08SJ. Bruce Fields &rp->rp_openfh); 3978837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3981da177e4SLinus Torvalds if (status) 3991da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 4001da177e4SLinus Torvalds " restoring previous filehandle\n"); 4011da177e4SLinus Torvalds else 402a90b061cSAl Viro status = nfserr_replay_me; 4031da177e4SLinus Torvalds } 4041da177e4SLinus Torvalds if (status) 4051da177e4SLinus Torvalds goto out; 4069d313b17SJ. Bruce Fields if (open->op_xdr_error) { 4079d313b17SJ. Bruce Fields status = open->op_xdr_error; 4089d313b17SJ. Bruce Fields goto out; 4099d313b17SJ. Bruce Fields } 410fb553c0fSJ. Bruce Fields 4113c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 4123c8e0316SYu Zhiguo if (status) 4133c8e0316SYu Zhiguo goto out; 4143c8e0316SYu Zhiguo 415fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 416fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 417cbd0d51aSJ. Bruce Fields status = nfserr_grace; 4183320fef1SStanislav Kinsbursky if (locks_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 419cbd0d51aSJ. Bruce Fields goto out; 420cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 4213320fef1SStanislav Kinsbursky if (!locks_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 422cbd0d51aSJ. Bruce Fields goto out; 423fb553c0fSJ. Bruce Fields 4241da177e4SLinus Torvalds switch (open->op_claim_type) { 4250dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4261da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 427c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4281da177e4SLinus Torvalds if (status) 4291da177e4SLinus Torvalds goto out; 4301da177e4SLinus Torvalds break; 4311da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 4323320fef1SStanislav Kinsbursky status = nfs4_check_open_reclaim(&open->op_clientid, 4330fe492dbSTrond Myklebust cstate, nn); 4340cf99b91SMi Jinlong if (status) 4350cf99b91SMi Jinlong goto out; 436ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 4378b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4388b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 439bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4401da177e4SLinus Torvalds if (status) 4411da177e4SLinus Torvalds goto out; 442c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4431da177e4SLinus Torvalds break; 4448b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4451da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4462fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4471da177e4SLinus Torvalds open->op_claim_type); 4481da177e4SLinus Torvalds status = nfserr_notsupp; 4491da177e4SLinus Torvalds goto out; 4501da177e4SLinus Torvalds default: 4512fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4521da177e4SLinus Torvalds open->op_claim_type); 4531da177e4SLinus Torvalds status = nfserr_inval; 4541da177e4SLinus Torvalds goto out; 4551da177e4SLinus Torvalds } 4561da177e4SLinus Torvalds /* 4571da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4581da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4591da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4601da177e4SLinus Torvalds */ 461c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 462b3fbfe0eSJeff Layton WARN(status && open->op_created, 463b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 464b3fbfe0eSJeff Layton be32_to_cpu(status)); 4651da177e4SLinus Torvalds out: 466c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 467c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 468c0e6bee4SJ. Bruce Fields fh_put(resfh); 469c0e6bee4SJ. Bruce Fields kfree(resfh); 470c0e6bee4SJ. Bruce Fields } 47142297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4729411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4731da177e4SLinus Torvalds return status; 4741da177e4SLinus Torvalds } 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds /* 4779d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4789d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4799d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4809d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4819d313b17SJ. Bruce Fields */ 4829d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4839d313b17SJ. Bruce Fields { 4849d313b17SJ. Bruce Fields struct nfsd4_open *open = (struct nfsd4_open *)&op->u; 4859d313b17SJ. Bruce Fields 4869d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4879d313b17SJ. Bruce Fields return op->status; 4889d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4899d313b17SJ. Bruce Fields return op->status; 4909d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 4919d313b17SJ. Bruce Fields return nfsd4_open(rqstp, cstate, open); 4929d313b17SJ. Bruce Fields } 4939d313b17SJ. Bruce Fields 4949d313b17SJ. Bruce Fields /* 4951da177e4SLinus Torvalds * filehandle-manipulating ops. 4961da177e4SLinus Torvalds */ 4977191155bSJ.Bruce Fields static __be32 498b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 499b591480bSJ.Bruce Fields struct svc_fh **getfh) 5001da177e4SLinus Torvalds { 501ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5021da177e4SLinus Torvalds return nfserr_nofilehandle; 5031da177e4SLinus Torvalds 504ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 5051da177e4SLinus Torvalds return nfs_ok; 5061da177e4SLinus Torvalds } 5071da177e4SLinus Torvalds 5087191155bSJ.Bruce Fields static __be32 509ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 510ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 5111da177e4SLinus Torvalds { 512ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 513ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 514ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 515ca364317SJ.Bruce Fields putfh->pf_fhlen); 51668d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5171da177e4SLinus Torvalds } 5181da177e4SLinus Torvalds 5197191155bSJ.Bruce Fields static __be32 520b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 521b591480bSJ.Bruce Fields void *arg) 5221da177e4SLinus Torvalds { 523b37ad28bSAl Viro __be32 status; 5241da177e4SLinus Torvalds 525ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 526df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5271da177e4SLinus Torvalds return status; 5281da177e4SLinus Torvalds } 5291da177e4SLinus Torvalds 5307191155bSJ.Bruce Fields static __be32 531b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 532b591480bSJ.Bruce Fields void *arg) 5331da177e4SLinus Torvalds { 534ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5351da177e4SLinus Torvalds return nfserr_restorefh; 5361da177e4SLinus Torvalds 537ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 53837c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 53937c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 54037c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 54137c593c5STigran Mkrtchyan } 5421da177e4SLinus Torvalds return nfs_ok; 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds 5457191155bSJ.Bruce Fields static __be32 546b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 547b591480bSJ.Bruce Fields void *arg) 5481da177e4SLinus Torvalds { 549ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5501da177e4SLinus Torvalds return nfserr_nofilehandle; 5511da177e4SLinus Torvalds 552ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 55337c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 55437c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 55537c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 55637c593c5STigran Mkrtchyan } 5571da177e4SLinus Torvalds return nfs_ok; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds 5601da177e4SLinus Torvalds /* 5611da177e4SLinus Torvalds * misc nfsv4 ops 5621da177e4SLinus Torvalds */ 5637191155bSJ.Bruce Fields static __be32 564ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 565ca364317SJ.Bruce Fields struct nfsd4_access *access) 5661da177e4SLinus Torvalds { 5671da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5681da177e4SLinus Torvalds return nfserr_inval; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 571ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 572ca364317SJ.Bruce Fields &access->ac_supported); 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 575b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 576ab4684d1SChuck Lever { 577ab4684d1SChuck Lever __be32 verf[2]; 578b9c0ef85SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 579ab4684d1SChuck Lever 580f419992cSJeff Layton /* 581f419992cSJeff Layton * This is opaque to client, so no need to byte-swap. Use 582f419992cSJeff Layton * __force to keep sparse happy 583f419992cSJeff Layton */ 584f419992cSJeff Layton verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; 585f419992cSJeff Layton verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec; 586ab4684d1SChuck Lever memcpy(verifier->data, verf, sizeof(verifier->data)); 587ab4684d1SChuck Lever } 588ab4684d1SChuck Lever 5897191155bSJ.Bruce Fields static __be32 590ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 591ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 5921da177e4SLinus Torvalds { 593b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 59475c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 595ca364317SJ.Bruce Fields commit->co_count); 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds 598b37ad28bSAl Viro static __be32 599ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 600ca364317SJ.Bruce Fields struct nfsd4_create *create) 6011da177e4SLinus Torvalds { 6021da177e4SLinus Torvalds struct svc_fh resfh; 603b37ad28bSAl Viro __be32 status; 6041da177e4SLinus Torvalds dev_t rdev; 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6071da177e4SLinus Torvalds 6088837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, 6098837abcaSMiklos Szeredi NFSD_MAY_CREATE); 6101da177e4SLinus Torvalds if (status) 6111da177e4SLinus Torvalds return status; 6121da177e4SLinus Torvalds 6133c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6143c8e0316SYu Zhiguo nfsd_attrmask); 6153c8e0316SYu Zhiguo if (status) 6163c8e0316SYu Zhiguo return status; 6173c8e0316SYu Zhiguo 6181da177e4SLinus Torvalds switch (create->cr_type) { 6191da177e4SLinus Torvalds case NF4LNK: 620ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 621ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6221e444f5bSKinglong Mee create->cr_data, &resfh); 6231da177e4SLinus Torvalds break; 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds case NF4BLK: 6261da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6271da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6281da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6291da177e4SLinus Torvalds return nfserr_inval; 630ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 631ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 632ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6331da177e4SLinus Torvalds break; 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds case NF4CHR: 6361da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6371da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6381da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6391da177e4SLinus Torvalds return nfserr_inval; 640ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 641ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 642ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6431da177e4SLinus Torvalds break; 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds case NF4SOCK: 646ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 647ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 648ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6491da177e4SLinus Torvalds break; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds case NF4FIFO: 652ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 653ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 654ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6551da177e4SLinus Torvalds break; 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds case NF4DIR: 6581da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 659ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 660ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 661ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6621da177e4SLinus Torvalds break; 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds default: 6651da177e4SLinus Torvalds status = nfserr_badtype; 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds 6689208faf2SYu Zhiguo if (status) 6699208faf2SYu Zhiguo goto out; 6709208faf2SYu Zhiguo 67118032ca0SDavid Quigley if (create->cr_label.len) 67218032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 67318032ca0SDavid Quigley 6749208faf2SYu Zhiguo if (create->cr_acl != NULL) 6759208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6769208faf2SYu Zhiguo create->cr_bmval); 6779208faf2SYu Zhiguo 678ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 679ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 680ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6819208faf2SYu Zhiguo out: 6821da177e4SLinus Torvalds fh_put(&resfh); 6831da177e4SLinus Torvalds return status; 6841da177e4SLinus Torvalds } 6851da177e4SLinus Torvalds 6867191155bSJ.Bruce Fields static __be32 687ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 688ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 6891da177e4SLinus Torvalds { 690b37ad28bSAl Viro __be32 status; 6911da177e4SLinus Torvalds 6928837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 6931da177e4SLinus Torvalds if (status) 6941da177e4SLinus Torvalds return status; 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6971da177e4SLinus Torvalds return nfserr_inval; 6981da177e4SLinus Torvalds 6997e705706SAndy Adamson getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 7007e705706SAndy Adamson getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 7017e705706SAndy Adamson getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 7021da177e4SLinus Torvalds 703ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7041da177e4SLinus Torvalds return nfs_ok; 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds 7077191155bSJ.Bruce Fields static __be32 708ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 709ca364317SJ.Bruce Fields struct nfsd4_link *link) 7101da177e4SLinus Torvalds { 711b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 7121da177e4SLinus Torvalds 713ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 7141da177e4SLinus Torvalds return status; 715ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 716ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7171da177e4SLinus Torvalds if (!status) 718ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7191da177e4SLinus Torvalds return status; 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds 7220ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7231da177e4SLinus Torvalds { 7241da177e4SLinus Torvalds struct svc_fh tmp_fh; 725b37ad28bSAl Viro __be32 ret; 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 728df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 729df547efbSJ. Bruce Fields if (ret) 7301da177e4SLinus Torvalds return ret; 7310ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7321da177e4SLinus Torvalds fh_put(&tmp_fh); 7331da177e4SLinus Torvalds return nfserr_noent; 7341da177e4SLinus Torvalds } 7351da177e4SLinus Torvalds fh_put(&tmp_fh); 7360ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7370ff7ab46SJ. Bruce Fields } 7380ff7ab46SJ. Bruce Fields 7390ff7ab46SJ. Bruce Fields static __be32 7400ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 7410ff7ab46SJ. Bruce Fields void *arg) 7420ff7ab46SJ. Bruce Fields { 7430ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7441da177e4SLinus Torvalds } 7451da177e4SLinus Torvalds 7467191155bSJ.Bruce Fields static __be32 747ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 748ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 7491da177e4SLinus Torvalds { 750ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 751ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 752ca364317SJ.Bruce Fields &cstate->current_fh); 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds 7557191155bSJ.Bruce Fields static __be32 756ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 757ca364317SJ.Bruce Fields struct nfsd4_read *read) 7581da177e4SLinus Torvalds { 759b37ad28bSAl Viro __be32 status; 7601da177e4SLinus Torvalds 7617e06b7f9SNeilBrown read->rd_filp = NULL; 7621da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7631da177e4SLinus Torvalds return nfserr_inval; 7641da177e4SLinus Torvalds 7659b3234b9SJ. Bruce Fields /* 7669b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7679b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7689b3234b9SJ. Bruce Fields * following compound. 7699b3234b9SJ. Bruce Fields * 7709b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7719b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7729b3234b9SJ. Bruce Fields */ 7739b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 774779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 7759b3234b9SJ. Bruce Fields 7761da177e4SLinus Torvalds /* check stateid */ 777af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &read->rd_stateid, 778af90f707SChristoph Hellwig RD_STATE, &read->rd_filp, &read->rd_tmp_file); 779af90f707SChristoph Hellwig if (status) { 7801da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7811da177e4SLinus Torvalds goto out; 7821da177e4SLinus Torvalds } 7831da177e4SLinus Torvalds status = nfs_ok; 7841da177e4SLinus Torvalds out: 7851da177e4SLinus Torvalds read->rd_rqstp = rqstp; 786ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 7871da177e4SLinus Torvalds return status; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds 7907191155bSJ.Bruce Fields static __be32 791ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 792ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 7931da177e4SLinus Torvalds { 7941da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 7951da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8001da177e4SLinus Torvalds return nfserr_inval; 8011da177e4SLinus Torvalds 8027e705706SAndy Adamson readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion); 8037e705706SAndy Adamson readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion); 8047e705706SAndy Adamson readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion); 8051da177e4SLinus Torvalds 806832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8071da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8081da177e4SLinus Torvalds return nfserr_bad_cookie; 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 811ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8121da177e4SLinus Torvalds return nfs_ok; 8131da177e4SLinus Torvalds } 8141da177e4SLinus Torvalds 8157191155bSJ.Bruce Fields static __be32 816ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 817ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 8181da177e4SLinus Torvalds { 8191da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 820ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 8211da177e4SLinus Torvalds return nfs_ok; 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds 8247191155bSJ.Bruce Fields static __be32 825ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 826ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 8271da177e4SLinus Torvalds { 828b37ad28bSAl Viro __be32 status; 8291da177e4SLinus Torvalds 8305ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp))) 831c815afc7SNeilBrown return nfserr_grace; 832ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 833ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8341da177e4SLinus Torvalds if (!status) { 835ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 836ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8371da177e4SLinus Torvalds } 8381da177e4SLinus Torvalds return status; 8391da177e4SLinus Torvalds } 8401da177e4SLinus Torvalds 8417191155bSJ.Bruce Fields static __be32 842ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 843ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 8441da177e4SLinus Torvalds { 845b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 8461da177e4SLinus Torvalds 847ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 8481da177e4SLinus Torvalds return status; 8495ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp)) && 8505ccb0066SStanislav Kinsbursky !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) 851c815afc7SNeilBrown return nfserr_grace; 852ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 853ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8541da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8552a6cf944SJ. Bruce Fields if (status) 8562a6cf944SJ. Bruce Fields return status; 857ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 858ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8592a6cf944SJ. Bruce Fields return nfs_ok; 8601da177e4SLinus Torvalds } 8611da177e4SLinus Torvalds 8627191155bSJ.Bruce Fields static __be32 863dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 864dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 865dcb488a3SAndy Adamson { 866dcb488a3SAndy Adamson struct svc_fh resfh; 867dcb488a3SAndy Adamson struct svc_export *exp; 868dcb488a3SAndy Adamson struct dentry *dentry; 869dcb488a3SAndy Adamson __be32 err; 870dcb488a3SAndy Adamson 871dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 87229a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 87329a78a3eSJ. Bruce Fields if (err) 87429a78a3eSJ. Bruce Fields return err; 875dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 876dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 877dcb488a3SAndy Adamson &exp, &dentry); 878dcb488a3SAndy Adamson if (err) 879dcb488a3SAndy Adamson return err; 8802b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 881dcb488a3SAndy Adamson exp_put(exp); 882dcb488a3SAndy Adamson err = nfserr_noent; 883dcb488a3SAndy Adamson } else 884dcb488a3SAndy Adamson secinfo->si_exp = exp; 885dcb488a3SAndy Adamson dput(dentry); 88656560b9aSJ. Bruce Fields if (cstate->minorversion) 88756560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 88856560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 889dcb488a3SAndy Adamson return err; 890dcb488a3SAndy Adamson } 891dcb488a3SAndy Adamson 892dcb488a3SAndy Adamson static __be32 89304f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 89404f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 89504f4ad16SJ. Bruce Fields { 89604f4ad16SJ. Bruce Fields __be32 err; 89704f4ad16SJ. Bruce Fields 89804f4ad16SJ. Bruce Fields switch (sin->sin_style) { 89904f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 90004f4ad16SJ. Bruce Fields break; 90104f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 90204f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 90304f4ad16SJ. Bruce Fields if (err) 90404f4ad16SJ. Bruce Fields return err; 90504f4ad16SJ. Bruce Fields break; 90604f4ad16SJ. Bruce Fields default: 90704f4ad16SJ. Bruce Fields return nfserr_inval; 90804f4ad16SJ. Bruce Fields } 909bf18f163SKinglong Mee 910bf18f163SKinglong Mee sin->sin_exp = exp_get(cstate->current_fh.fh_export); 91104f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 91204f4ad16SJ. Bruce Fields return nfs_ok; 91304f4ad16SJ. Bruce Fields } 91404f4ad16SJ. Bruce Fields 91504f4ad16SJ. Bruce Fields static __be32 916ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 917ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 9181da177e4SLinus Torvalds { 919b37ad28bSAl Viro __be32 status = nfs_ok; 92096f6f985SAl Viro int err; 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 923af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 924af90f707SChristoph Hellwig &setattr->sa_stateid, WR_STATE, NULL, NULL); 925375c5547SJ. Bruce Fields if (status) { 9263e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 927375c5547SJ. Bruce Fields return status; 928375c5547SJ. Bruce Fields } 9291da177e4SLinus Torvalds } 93096f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 93196f6f985SAl Viro if (err) 93296f6f985SAl Viro return nfserrno(err); 9331da177e4SLinus Torvalds status = nfs_ok; 9343c8e0316SYu Zhiguo 9353c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9363c8e0316SYu Zhiguo nfsd_attrmask); 9373c8e0316SYu Zhiguo if (status) 9383c8e0316SYu Zhiguo goto out; 9393c8e0316SYu Zhiguo 9401da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 941ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 942ca364317SJ.Bruce Fields setattr->sa_acl); 9431da177e4SLinus Torvalds if (status) 94418f335afSDave Hansen goto out; 94518032ca0SDavid Quigley if (setattr->sa_label.len) 94618032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 94718032ca0SDavid Quigley &setattr->sa_label); 94818032ca0SDavid Quigley if (status) 94918032ca0SDavid Quigley goto out; 950ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9511da177e4SLinus Torvalds 0, (time_t)0); 95218f335afSDave Hansen out: 953bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9541da177e4SLinus Torvalds return status; 9551da177e4SLinus Torvalds } 9561da177e4SLinus Torvalds 957ffe1137bSJ. Bruce Fields static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write) 958ffe1137bSJ. Bruce Fields { 959ffe1137bSJ. Bruce Fields int i = 1; 960ffe1137bSJ. Bruce Fields int buflen = write->wr_buflen; 961ffe1137bSJ. Bruce Fields 962ffe1137bSJ. Bruce Fields vec[0].iov_base = write->wr_head.iov_base; 963ffe1137bSJ. Bruce Fields vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len); 964ffe1137bSJ. Bruce Fields buflen -= vec[0].iov_len; 965ffe1137bSJ. Bruce Fields 966ffe1137bSJ. Bruce Fields while (buflen) { 967ffe1137bSJ. Bruce Fields vec[i].iov_base = page_address(write->wr_pagelist[i - 1]); 968ffe1137bSJ. Bruce Fields vec[i].iov_len = min_t(int, PAGE_SIZE, buflen); 969ffe1137bSJ. Bruce Fields buflen -= vec[i].iov_len; 970ffe1137bSJ. Bruce Fields i++; 971ffe1137bSJ. Bruce Fields } 972ffe1137bSJ. Bruce Fields return i; 973ffe1137bSJ. Bruce Fields } 974ffe1137bSJ. Bruce Fields 9757191155bSJ.Bruce Fields static __be32 976ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 977ca364317SJ.Bruce Fields struct nfsd4_write *write) 9781da177e4SLinus Torvalds { 9791da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 9801da177e4SLinus Torvalds struct file *filp = NULL; 981b37ad28bSAl Viro __be32 status = nfs_ok; 98231dec253SDavid Shaw unsigned long cnt; 983ffe1137bSJ. Bruce Fields int nvecs; 9841da177e4SLinus Torvalds 9851da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 9861da177e4SLinus Torvalds return nfserr_inval; 9871da177e4SLinus Torvalds 988af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, stateid, WR_STATE, 989af90f707SChristoph Hellwig &filp, NULL); 990375c5547SJ. Bruce Fields if (status) { 991375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 992375c5547SJ. Bruce Fields return status; 993375c5547SJ. Bruce Fields } 994375c5547SJ. Bruce Fields 99531dec253SDavid Shaw cnt = write->wr_buflen; 9961da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 997b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); 9981da177e4SLinus Torvalds 999ffe1137bSJ. Bruce Fields nvecs = fill_in_write_vector(rqstp->rq_vec, write); 1000ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1001ffe1137bSJ. Bruce Fields 1002af90f707SChristoph Hellwig status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp, 1003af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 1004af90f707SChristoph Hellwig &write->wr_how_written); 10057e06b7f9SNeilBrown fput(filp); 10061da177e4SLinus Torvalds 100731dec253SDavid Shaw write->wr_bytes_written = cnt; 100831dec253SDavid Shaw 10091da177e4SLinus Torvalds return status; 10101da177e4SLinus Torvalds } 10111da177e4SLinus Torvalds 101224bab491SAnna Schumaker static __be32 101395d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 101495d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 101595d871f0SAnna Schumaker { 101695d871f0SAnna Schumaker __be32 status = nfserr_notsupp; 101795d871f0SAnna Schumaker struct file *file; 101895d871f0SAnna Schumaker 1019af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 102095d871f0SAnna Schumaker &fallocate->falloc_stateid, 1021af90f707SChristoph Hellwig WR_STATE, &file, NULL); 102295d871f0SAnna Schumaker if (status != nfs_ok) { 102395d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 102495d871f0SAnna Schumaker return status; 102595d871f0SAnna Schumaker } 102695d871f0SAnna Schumaker 102795d871f0SAnna Schumaker status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, 102895d871f0SAnna Schumaker fallocate->falloc_offset, 102995d871f0SAnna Schumaker fallocate->falloc_length, 103095d871f0SAnna Schumaker flags); 103195d871f0SAnna Schumaker fput(file); 103295d871f0SAnna Schumaker return status; 103395d871f0SAnna Schumaker } 103495d871f0SAnna Schumaker 103595d871f0SAnna Schumaker static __be32 103695d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 103795d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate) 103895d871f0SAnna Schumaker { 103995d871f0SAnna Schumaker return nfsd4_fallocate(rqstp, cstate, fallocate, 0); 104095d871f0SAnna Schumaker } 104195d871f0SAnna Schumaker 104295d871f0SAnna Schumaker static __be32 1043b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1044b0cb9085SAnna Schumaker struct nfsd4_fallocate *fallocate) 1045b0cb9085SAnna Schumaker { 1046b0cb9085SAnna Schumaker return nfsd4_fallocate(rqstp, cstate, fallocate, 1047b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1048b0cb9085SAnna Schumaker } 1049b0cb9085SAnna Schumaker 1050b0cb9085SAnna Schumaker static __be32 105124bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 105224bab491SAnna Schumaker struct nfsd4_seek *seek) 105324bab491SAnna Schumaker { 105424bab491SAnna Schumaker int whence; 105524bab491SAnna Schumaker __be32 status; 105624bab491SAnna Schumaker struct file *file; 105724bab491SAnna Schumaker 1058af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 105924bab491SAnna Schumaker &seek->seek_stateid, 1060af90f707SChristoph Hellwig RD_STATE, &file, NULL); 106124bab491SAnna Schumaker if (status) { 106224bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 106324bab491SAnna Schumaker return status; 106424bab491SAnna Schumaker } 106524bab491SAnna Schumaker 106624bab491SAnna Schumaker switch (seek->seek_whence) { 106724bab491SAnna Schumaker case NFS4_CONTENT_DATA: 106824bab491SAnna Schumaker whence = SEEK_DATA; 106924bab491SAnna Schumaker break; 107024bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 107124bab491SAnna Schumaker whence = SEEK_HOLE; 107224bab491SAnna Schumaker break; 107324bab491SAnna Schumaker default: 107424bab491SAnna Schumaker status = nfserr_union_notsupp; 107524bab491SAnna Schumaker goto out; 107624bab491SAnna Schumaker } 107724bab491SAnna Schumaker 107824bab491SAnna Schumaker /* 107924bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 108024bab491SAnna Schumaker * should ever file->f_pos. 108124bab491SAnna Schumaker */ 108224bab491SAnna Schumaker seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence); 108324bab491SAnna Schumaker if (seek->seek_pos < 0) 108424bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 108524bab491SAnna Schumaker else if (seek->seek_pos >= i_size_read(file_inode(file))) 108624bab491SAnna Schumaker seek->seek_eof = true; 108724bab491SAnna Schumaker 108824bab491SAnna Schumaker out: 108924bab491SAnna Schumaker fput(file); 109024bab491SAnna Schumaker return status; 109124bab491SAnna Schumaker } 109224bab491SAnna Schumaker 10931da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 10941da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 10951da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 10961da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 10971da177e4SLinus Torvalds */ 1098b37ad28bSAl Viro static __be32 1099c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1100ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 11011da177e4SLinus Torvalds { 11022ebbc012SAl Viro __be32 *buf, *p; 11031da177e4SLinus Torvalds int count; 1104b37ad28bSAl Viro __be32 status; 11051da177e4SLinus Torvalds 11068837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 11071da177e4SLinus Torvalds if (status) 11081da177e4SLinus Torvalds return status; 11091da177e4SLinus Torvalds 11103c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 11113c8e0316SYu Zhiguo if (status) 11123c8e0316SYu Zhiguo return status; 11133c8e0316SYu Zhiguo 11141da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 11151da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 11161da177e4SLinus Torvalds return nfserr_inval; 11171da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 11181da177e4SLinus Torvalds return nfserr_inval; 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds /* count in words: 11211da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 11221da177e4SLinus Torvalds */ 11231da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 11241da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 11251da177e4SLinus Torvalds if (!buf) 11263e772463SJ. Bruce Fields return nfserr_jukebox; 11271da177e4SLinus Torvalds 112884822d0bSJ. Bruce Fields p = buf; 1129d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1130ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1131d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1132d5184658SJ. Bruce Fields verify->ve_bmval, 1133406a7ea9SFrank Filz rqstp, 0); 113441ae6e71SJ. Bruce Fields /* 113541ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 113641ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 113741ae6e71SJ. Bruce Fields */ 113884822d0bSJ. Bruce Fields if (status == nfserr_resource) 11391da177e4SLinus Torvalds status = nfserr_not_same; 11401da177e4SLinus Torvalds if (status) 11411da177e4SLinus Torvalds goto out_kfree; 11421da177e4SLinus Torvalds 114395ec28cdSBenny Halevy /* skip bitmap */ 114495ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 11451da177e4SLinus Torvalds status = nfserr_not_same; 11461da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 11471da177e4SLinus Torvalds goto out_kfree; 11481da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 11491da177e4SLinus Torvalds status = nfserr_same; 11501da177e4SLinus Torvalds 11511da177e4SLinus Torvalds out_kfree: 11521da177e4SLinus Torvalds kfree(buf); 11531da177e4SLinus Torvalds return status; 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds 1156c954e2a5SJ.Bruce Fields static __be32 1157c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1158c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1159c954e2a5SJ.Bruce Fields { 1160c954e2a5SJ.Bruce Fields __be32 status; 1161c954e2a5SJ.Bruce Fields 1162c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1163c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1164c954e2a5SJ.Bruce Fields } 1165c954e2a5SJ.Bruce Fields 1166c954e2a5SJ.Bruce Fields static __be32 1167c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1168c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1169c954e2a5SJ.Bruce Fields { 1170c954e2a5SJ.Bruce Fields __be32 status; 1171c954e2a5SJ.Bruce Fields 1172c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1173c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1174c954e2a5SJ.Bruce Fields } 1175c954e2a5SJ.Bruce Fields 11769cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 11779cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 11789cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 11799cf514ccSChristoph Hellwig { 11809cf514ccSChristoph Hellwig if (!exp->ex_layout_type) { 11819cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 11829cf514ccSChristoph Hellwig return NULL; 11839cf514ccSChristoph Hellwig } 11849cf514ccSChristoph Hellwig 11859cf514ccSChristoph Hellwig if (exp->ex_layout_type != layout_type) { 11869cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 11879cf514ccSChristoph Hellwig __func__, layout_type); 11889cf514ccSChristoph Hellwig return NULL; 11899cf514ccSChristoph Hellwig } 11909cf514ccSChristoph Hellwig 11919cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 11929cf514ccSChristoph Hellwig } 11939cf514ccSChristoph Hellwig 11949cf514ccSChristoph Hellwig static __be32 11959cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 11969cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 11979cf514ccSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp) 11989cf514ccSChristoph Hellwig { 11999cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 12009cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 12019cf514ccSChristoph Hellwig struct svc_export *exp; 12029cf514ccSChristoph Hellwig __be32 nfserr; 12039cf514ccSChristoph Hellwig 12049cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 12059cf514ccSChristoph Hellwig __func__, 12069cf514ccSChristoph Hellwig gdp->gd_layout_type, 12079cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 12089cf514ccSChristoph Hellwig gdp->gd_maxcount); 12099cf514ccSChristoph Hellwig 12109cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 12119cf514ccSChristoph Hellwig if (!map) { 12129cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 12139cf514ccSChristoph Hellwig __func__); 12149cf514ccSChristoph Hellwig return nfserr_noent; 12159cf514ccSChristoph Hellwig } 12169cf514ccSChristoph Hellwig 12179cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 12189cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 12199cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 12209cf514ccSChristoph Hellwig return nfserr_noent; 12219cf514ccSChristoph Hellwig } 12229cf514ccSChristoph Hellwig 12239cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 12249cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 12259cf514ccSChristoph Hellwig if (!ops) 12269cf514ccSChristoph Hellwig goto out; 12279cf514ccSChristoph Hellwig 12289cf514ccSChristoph Hellwig nfserr = nfs_ok; 12299cf514ccSChristoph Hellwig if (gdp->gd_maxcount != 0) 12309cf514ccSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, gdp); 12319cf514ccSChristoph Hellwig 12329cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 12339cf514ccSChristoph Hellwig out: 1234a1420384SKinglong Mee exp_put(exp); 12359cf514ccSChristoph Hellwig return nfserr; 12369cf514ccSChristoph Hellwig } 12379cf514ccSChristoph Hellwig 12389cf514ccSChristoph Hellwig static __be32 12399cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 12409cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 12419cf514ccSChristoph Hellwig struct nfsd4_layoutget *lgp) 12429cf514ccSChristoph Hellwig { 12439cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 12449cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 12459cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 12469cf514ccSChristoph Hellwig __be32 nfserr; 12479cf514ccSChristoph Hellwig int accmode; 12489cf514ccSChristoph Hellwig 12499cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 12509cf514ccSChristoph Hellwig case IOMODE_READ: 12519cf514ccSChristoph Hellwig accmode = NFSD_MAY_READ; 12529cf514ccSChristoph Hellwig break; 12539cf514ccSChristoph Hellwig case IOMODE_RW: 12549cf514ccSChristoph Hellwig accmode = NFSD_MAY_READ | NFSD_MAY_WRITE; 12559cf514ccSChristoph Hellwig break; 12569cf514ccSChristoph Hellwig default: 12579cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 12589cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 12599cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 12609cf514ccSChristoph Hellwig goto out; 12619cf514ccSChristoph Hellwig } 12629cf514ccSChristoph Hellwig 12639cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 12649cf514ccSChristoph Hellwig if (nfserr) 12659cf514ccSChristoph Hellwig goto out; 12669cf514ccSChristoph Hellwig 12679cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 12689cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 12699cf514ccSChristoph Hellwig if (!ops) 12709cf514ccSChristoph Hellwig goto out; 12719cf514ccSChristoph Hellwig 12729cf514ccSChristoph Hellwig /* 12739cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 12749cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 12759cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 12769cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 12779cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 12789cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 12799cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 12809cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 12819cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 12829cf514ccSChristoph Hellwig */ 12839cf514ccSChristoph Hellwig nfserr = nfserr_inval; 12849cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 12859cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 12869cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 12879cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 12889cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 12899cf514ccSChristoph Hellwig goto out; 12909cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 12919cf514ccSChristoph Hellwig goto out; 12929cf514ccSChristoph Hellwig 12939cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 12949cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 129531ef83dcSChristoph Hellwig if (nfserr) { 129631ef83dcSChristoph Hellwig trace_layout_get_lookup_fail(&lgp->lg_sid); 12979cf514ccSChristoph Hellwig goto out; 129831ef83dcSChristoph Hellwig } 12999cf514ccSChristoph Hellwig 1300c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1301c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1302c5c707f9SChristoph Hellwig goto out_put_stid; 1303c5c707f9SChristoph Hellwig 13042b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 13059cf514ccSChristoph Hellwig current_fh, lgp); 13069cf514ccSChristoph Hellwig if (nfserr) 13079cf514ccSChristoph Hellwig goto out_put_stid; 13089cf514ccSChristoph Hellwig 13099cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 13109cf514ccSChristoph Hellwig 13119cf514ccSChristoph Hellwig out_put_stid: 13129cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 13139cf514ccSChristoph Hellwig out: 13149cf514ccSChristoph Hellwig return nfserr; 13159cf514ccSChristoph Hellwig } 13169cf514ccSChristoph Hellwig 13179cf514ccSChristoph Hellwig static __be32 13189cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 13199cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 13209cf514ccSChristoph Hellwig struct nfsd4_layoutcommit *lcp) 13219cf514ccSChristoph Hellwig { 13229cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 13239cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 13249cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 13259cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 13269cf514ccSChristoph Hellwig struct inode *inode; 13279cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 13289cf514ccSChristoph Hellwig __be32 nfserr; 13299cf514ccSChristoph Hellwig 13309cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 13319cf514ccSChristoph Hellwig if (nfserr) 13329cf514ccSChristoph Hellwig goto out; 13339cf514ccSChristoph Hellwig 13349cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 13359cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 13369cf514ccSChristoph Hellwig if (!ops) 13379cf514ccSChristoph Hellwig goto out; 13382b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 13399cf514ccSChristoph Hellwig 13409cf514ccSChristoph Hellwig nfserr = nfserr_inval; 13419cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 13429cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 13439cf514ccSChristoph Hellwig goto out; 13449cf514ccSChristoph Hellwig } 13459cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 13469cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 13479cf514ccSChristoph Hellwig goto out; 13489cf514ccSChristoph Hellwig } 13499cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 13509cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 13519cf514ccSChristoph Hellwig goto out; 13529cf514ccSChristoph Hellwig } 13539cf514ccSChristoph Hellwig 13549cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 13559cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 13569cf514ccSChristoph Hellwig &ls); 13579cf514ccSChristoph Hellwig if (nfserr) { 135831ef83dcSChristoph Hellwig trace_layout_commit_lookup_fail(&lcp->lc_sid); 13599cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 13609cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 13619cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 13629cf514ccSChristoph Hellwig goto out; 13639cf514ccSChristoph Hellwig } 13649cf514ccSChristoph Hellwig 13659cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 13669cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 13679cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 13689cf514ccSChristoph Hellwig } else { 13699cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 13709cf514ccSChristoph Hellwig } 13719cf514ccSChristoph Hellwig 1372d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 13739cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 13749cf514ccSChristoph Hellwig out: 13759cf514ccSChristoph Hellwig return nfserr; 13769cf514ccSChristoph Hellwig } 13779cf514ccSChristoph Hellwig 13789cf514ccSChristoph Hellwig static __be32 13799cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 13809cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 13819cf514ccSChristoph Hellwig struct nfsd4_layoutreturn *lrp) 13829cf514ccSChristoph Hellwig { 13839cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 13849cf514ccSChristoph Hellwig __be32 nfserr; 13859cf514ccSChristoph Hellwig 13869cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 13879cf514ccSChristoph Hellwig if (nfserr) 13889cf514ccSChristoph Hellwig goto out; 13899cf514ccSChristoph Hellwig 13909cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 13919cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 13929cf514ccSChristoph Hellwig goto out; 13939cf514ccSChristoph Hellwig 13949cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 13959cf514ccSChristoph Hellwig case IOMODE_READ: 13969cf514ccSChristoph Hellwig case IOMODE_RW: 13979cf514ccSChristoph Hellwig case IOMODE_ANY: 13989cf514ccSChristoph Hellwig break; 13999cf514ccSChristoph Hellwig default: 14009cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 14019cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 14029cf514ccSChristoph Hellwig nfserr = nfserr_inval; 14039cf514ccSChristoph Hellwig goto out; 14049cf514ccSChristoph Hellwig } 14059cf514ccSChristoph Hellwig 14069cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 14079cf514ccSChristoph Hellwig case RETURN_FILE: 14089cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 14099cf514ccSChristoph Hellwig break; 14109cf514ccSChristoph Hellwig case RETURN_FSID: 14119cf514ccSChristoph Hellwig case RETURN_ALL: 14129cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 14139cf514ccSChristoph Hellwig break; 14149cf514ccSChristoph Hellwig default: 14159cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 14169cf514ccSChristoph Hellwig lrp->lr_return_type); 14179cf514ccSChristoph Hellwig nfserr = nfserr_inval; 14189cf514ccSChristoph Hellwig break; 14199cf514ccSChristoph Hellwig } 14209cf514ccSChristoph Hellwig out: 14219cf514ccSChristoph Hellwig return nfserr; 14229cf514ccSChristoph Hellwig } 14239cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 14249cf514ccSChristoph Hellwig 14251da177e4SLinus Torvalds /* 14261da177e4SLinus Torvalds * NULL call. 14271da177e4SLinus Torvalds */ 14287111c66eSAl Viro static __be32 14291da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 14301da177e4SLinus Torvalds { 14311da177e4SLinus Torvalds return nfs_ok; 14321da177e4SLinus Torvalds } 14331da177e4SLinus Torvalds 1434e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1435e2b20950SShankar Anand { 1436e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1437e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1438e2b20950SShankar Anand } 1439e2b20950SShankar Anand 1440b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 1441b591480bSJ.Bruce Fields void *); 144258e7b33aSMi Jinlong typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op); 14438b70484cSTigran Mkrtchyan typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *); 14448b70484cSTigran Mkrtchyan typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *); 144558e7b33aSMi Jinlong 1446f9bb94c4SAndy Adamson enum nfsd4_op_flags { 1447f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 14485ece3cafSMi Jinlong ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 14495ece3cafSMi Jinlong ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 145068d93184SJ. Bruce Fields /* For rfc 5661 section 2.6.3.1.1: */ 145168d93184SJ. Bruce Fields OP_HANDLES_WRONGSEC = 1 << 3, 145268d93184SJ. Bruce Fields OP_IS_PUTFH_LIKE = 1 << 4, 14531091006cSJ. Bruce Fields /* 1454c856694eSJ. Bruce Fields * These are the ops whose result size we estimate before 1455c856694eSJ. Bruce Fields * encoding, to avoid performing an op then not being able to 1456c856694eSJ. Bruce Fields * respond or cache a response. This includes writes and setattrs 1457c856694eSJ. Bruce Fields * as well as the operations usually called "nonidempotent": 1458c856694eSJ. Bruce Fields */ 1459c856694eSJ. Bruce Fields OP_MODIFIES_SOMETHING = 1 << 5, 1460c856694eSJ. Bruce Fields /* 1461c856694eSJ. Bruce Fields * Cache compounds containing these ops in the xid-based drc: 14621091006cSJ. Bruce Fields * We use the DRC for compounds containing non-idempotent 14631091006cSJ. Bruce Fields * operations, *except* those that are 4.1-specific (since 14641091006cSJ. Bruce Fields * sessions provide their own EOS), and except for stateful 14651091006cSJ. Bruce Fields * operations other than setclientid and setclientid_confirm 14661091006cSJ. Bruce Fields * (since sequence numbers provide EOS for open, lock, etc in 14671091006cSJ. Bruce Fields * the v4.0 case). 14681091006cSJ. Bruce Fields */ 1469c856694eSJ. Bruce Fields OP_CACHEME = 1 << 6, 14708b70484cSTigran Mkrtchyan /* 14718b70484cSTigran Mkrtchyan * These are ops which clear current state id. 14728b70484cSTigran Mkrtchyan */ 14738b70484cSTigran Mkrtchyan OP_CLEAR_STATEID = 1 << 7, 1474c856694eSJ. Bruce Fields }; 1475c856694eSJ. Bruce Fields 1476c856694eSJ. Bruce Fields struct nfsd4_operation { 1477c856694eSJ. Bruce Fields nfsd4op_func op_func; 1478c856694eSJ. Bruce Fields u32 op_flags; 1479c856694eSJ. Bruce Fields char *op_name; 148058e7b33aSMi Jinlong /* Try to get response size before operation */ 148158e7b33aSMi Jinlong nfsd4op_rsize op_rsize_bop; 148224ff99c6SBryan Schumaker stateid_getter op_get_currentstateid; 148324ff99c6SBryan Schumaker stateid_setter op_set_currentstateid; 1484b591480bSJ.Bruce Fields }; 1485b591480bSJ.Bruce Fields 1486b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 1487b591480bSJ.Bruce Fields 1488f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1489b001a1b6SBenny Halevy 14901da177e4SLinus Torvalds /* 149157716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1492f9bb94c4SAndy Adamson * 149357716355SJ. Bruce Fields * Also note, enforced elsewhere: 149457716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 149557716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 14961d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 14971d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 149857716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 149957716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 150057716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1501f9bb94c4SAndy Adamson */ 150257716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1503f9bb94c4SAndy Adamson { 1504f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 150557716355SJ. Bruce Fields 150657716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 150757716355SJ. Bruce Fields if (args->minorversion == 0) 150857716355SJ. Bruce Fields return nfs_ok; 150957716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 151057716355SJ. Bruce Fields if (args->opcnt == 0) 151157716355SJ. Bruce Fields return nfs_ok; 151257716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 151357716355SJ. Bruce Fields return nfs_ok; 151457716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 151557716355SJ. Bruce Fields return nfserr_op_not_in_session; 151657716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 151757716355SJ. Bruce Fields return nfs_ok; 151857716355SJ. Bruce Fields if (args->opcnt != 1) 151957716355SJ. Bruce Fields return nfserr_not_only_op; 152057716355SJ. Bruce Fields return nfs_ok; 1521f9bb94c4SAndy Adamson } 1522f9bb94c4SAndy Adamson 152322b03214SJ. Bruce Fields static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 152422b03214SJ. Bruce Fields { 152522b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 152622b03214SJ. Bruce Fields } 152722b03214SJ. Bruce Fields 15281091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 15291091006cSJ. Bruce Fields { 1530e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 1531e372ba60SJ. Bruce Fields return false; 1532c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 15331091006cSJ. Bruce Fields } 15341091006cSJ. Bruce Fields 153568d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 153668d93184SJ. Bruce Fields { 153768d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 153868d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 153968d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 154068d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 154168d93184SJ. Bruce Fields struct nfsd4_operation *thisd; 154268d93184SJ. Bruce Fields struct nfsd4_operation *nextd; 154368d93184SJ. Bruce Fields 154468d93184SJ. Bruce Fields thisd = OPDESC(this); 154568d93184SJ. Bruce Fields /* 154668d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 154768d93184SJ. Bruce Fields * have special rules. 154868d93184SJ. Bruce Fields */ 154968d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 155068d93184SJ. Bruce Fields return false; 155168d93184SJ. Bruce Fields /* 155268d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 155368d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 155468d93184SJ. Bruce Fields * result: 155568d93184SJ. Bruce Fields */ 155668d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 155768d93184SJ. Bruce Fields return false; 155851904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 155951904b08SJ. Bruce Fields return false; 156068d93184SJ. Bruce Fields nextd = OPDESC(next); 156168d93184SJ. Bruce Fields /* 156268d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 156368d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 156468d93184SJ. Bruce Fields * now: 156568d93184SJ. Bruce Fields */ 156668d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 156768d93184SJ. Bruce Fields } 156868d93184SJ. Bruce Fields 15692d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 15702d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 15712d124dfaSJ. Bruce Fields { 15722d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 15732d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 15742d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 15752d124dfaSJ. Bruce Fields 15762d124dfaSJ. Bruce Fields xdr->buf = buf; 1577ddd1ea56SJ. Bruce Fields xdr->iov = head; 15782d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 1579a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 15806ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 15816ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 15822825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 158305638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 15842825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 1585a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 15862d124dfaSJ. Bruce Fields } 15872d124dfaSJ. Bruce Fields 1588f9bb94c4SAndy Adamson /* 15891da177e4SLinus Torvalds * COMPOUND call. 15901da177e4SLinus Torvalds */ 15917111c66eSAl Viro static __be32 15921da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 15931da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 15941da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 15951da177e4SLinus Torvalds { 15961da177e4SLinus Torvalds struct nfsd4_op *op; 1597b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1598e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 15994daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 16004daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1601b37ad28bSAl Viro __be32 status; 16021da177e4SLinus Torvalds 16032d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 16044aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 16051da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 1606d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 16071da177e4SLinus Torvalds resp->taglen = args->taglen; 16081da177e4SLinus Torvalds resp->tag = args->tag; 16091da177e4SLinus Torvalds resp->rqstp = rqstp; 16104daeed25SKinglong Mee cstate->minorversion = args->minorversion; 16114daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 16124daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 16138ff30fa4SNeilBrown /* 16148ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 16158ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 16168ff30fa4SNeilBrown */ 161730660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 16181da177e4SLinus Torvalds 16191da177e4SLinus Torvalds /* 16201da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 16211da177e4SLinus Torvalds */ 16221da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 162335f7a14fSJ. Bruce Fields if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) 16241da177e4SLinus Torvalds goto out; 16251da177e4SLinus Torvalds 162657716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 162757716355SJ. Bruce Fields if (status) { 1628f9bb94c4SAndy Adamson op = &args->ops[0]; 162957716355SJ. Bruce Fields op->status = status; 1630f9bb94c4SAndy Adamson goto encode_op; 1631f9bb94c4SAndy Adamson } 1632f9bb94c4SAndy Adamson 16331da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 16341da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 16351da177e4SLinus Torvalds 1636b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1637b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1638b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 16391da177e4SLinus Torvalds /* 16401da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 16411da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 16421da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 16431da177e4SLinus Torvalds */ 16449d313b17SJ. Bruce Fields if (op->status) { 16459d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 16469d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 16471da177e4SLinus Torvalds goto encode_op; 16489d313b17SJ. Bruce Fields } 16491da177e4SLinus Torvalds 165022b03214SJ. Bruce Fields opdesc = OPDESC(op); 1651b591480bSJ.Bruce Fields 16524daeed25SKinglong Mee if (!current_fh->fh_dentry) { 165327d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 16541da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 16551da177e4SLinus Torvalds goto encode_op; 16561da177e4SLinus Torvalds } 16574daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1658eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 165942ca0993SJ.Bruce Fields op->status = nfserr_moved; 166042ca0993SJ.Bruce Fields goto encode_op; 166142ca0993SJ.Bruce Fields } 1662b591480bSJ.Bruce Fields 16632336745eSKinglong Mee fh_clear_wcc(current_fh); 16642336745eSKinglong Mee 166558e7b33aSMi Jinlong /* If op is non-idempotent */ 166658e7b33aSMi Jinlong if (opdesc->op_flags & OP_MODIFIES_SOMETHING) { 16674c69d585SJ. Bruce Fields /* 1668a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 1669a8095f7eSJ. Bruce Fields * succesful reply: 1670a8095f7eSJ. Bruce Fields */ 1671a8095f7eSJ. Bruce Fields u32 plen = opdesc->op_rsize_bop(rqstp, op); 1672a8095f7eSJ. Bruce Fields /* 1673a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 16744c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 16754c69d585SJ. Bruce Fields */ 16764c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 16774c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 167858e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 167958e7b33aSMi Jinlong } 168058e7b33aSMi Jinlong 168158e7b33aSMi Jinlong if (op->status) 168258e7b33aSMi Jinlong goto encode_op; 168358e7b33aSMi Jinlong 16848b70484cSTigran Mkrtchyan if (opdesc->op_get_currentstateid) 16858b70484cSTigran Mkrtchyan opdesc->op_get_currentstateid(cstate, &op->u); 1686b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 16871da177e4SLinus Torvalds 16888b70484cSTigran Mkrtchyan if (!op->status) { 16898b70484cSTigran Mkrtchyan if (opdesc->op_set_currentstateid) 16908b70484cSTigran Mkrtchyan opdesc->op_set_currentstateid(cstate, &op->u); 16918b70484cSTigran Mkrtchyan 16928b70484cSTigran Mkrtchyan if (opdesc->op_flags & OP_CLEAR_STATEID) 169337c593c5STigran Mkrtchyan clear_current_stateid(cstate); 16948b70484cSTigran Mkrtchyan 16958b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 16964daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 16978b70484cSTigran Mkrtchyan } 169868d93184SJ. Bruce Fields 16991da177e4SLinus Torvalds encode_op: 170049557cc7SAndy Adamson /* Only from SEQUENCE */ 17014daeed25SKinglong Mee if (cstate->status == nfserr_replay_cache) { 1702da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1703da3846a2SAndy Adamson status = op->status; 1704da3846a2SAndy Adamson goto out; 1705da3846a2SAndy Adamson } 1706a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1707a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 1708d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 17091da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 17101da177e4SLinus Torvalds } else { 17111da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 17121da177e4SLinus Torvalds status = op->status; 17131da177e4SLinus Torvalds } 17140407717dSBenny Halevy 17150407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 17160407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 17170407717dSBenny Halevy be32_to_cpu(status)); 17180407717dSBenny Halevy 171958fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 1720e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 17211da177e4SLinus Torvalds } 17221da177e4SLinus Torvalds 17234daeed25SKinglong Mee cstate->status = status; 17244daeed25SKinglong Mee fh_put(current_fh); 17254daeed25SKinglong Mee fh_put(save_fh); 17264daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 17271da177e4SLinus Torvalds out: 17282f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 172930660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 17303b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 17311da177e4SLinus Torvalds return status; 17321da177e4SLinus Torvalds } 17331da177e4SLinus Torvalds 173458e7b33aSMi Jinlong #define op_encode_hdr_size (2) 173558e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 173658e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 173758e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 173858e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 173958e7b33aSMi Jinlong 17408c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 17418c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 174258e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 174358e7b33aSMi Jinlong 174458e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 174558e7b33aSMi Jinlong 174658e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 174758e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 174858e7b33aSMi Jinlong op_encode_ace_maxsz) 174958e7b33aSMi Jinlong 175058e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 175158e7b33aSMi Jinlong 175258e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 175358e7b33aSMi Jinlong { 175458e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 175558e7b33aSMi Jinlong } 175658e7b33aSMi Jinlong 175758e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 175858e7b33aSMi Jinlong { 175958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 176058e7b33aSMi Jinlong } 176158e7b33aSMi Jinlong 176258e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 176358e7b33aSMi Jinlong { 176458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 176558e7b33aSMi Jinlong } 176658e7b33aSMi Jinlong 176758e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 176858e7b33aSMi Jinlong { 176958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 177058e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 177158e7b33aSMi Jinlong } 177258e7b33aSMi Jinlong 1773b86cef60SJ. Bruce Fields /* 1774b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 1775b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 1776b86cef60SJ. Bruce Fields * reads unnecessarily. 1777b86cef60SJ. Bruce Fields */ 1778b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 1779b86cef60SJ. Bruce Fields struct nfsd4_op *op) 1780b86cef60SJ. Bruce Fields { 1781b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 1782b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 1783b86cef60SJ. Bruce Fields u32 ret = 0; 1784b86cef60SJ. Bruce Fields 1785b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 1786b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 1787b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 1788b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 1789b86cef60SJ. Bruce Fields 1790b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 1791b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 1792b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 1793b86cef60SJ. Bruce Fields } 1794b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 1795b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 1796b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 1797b86cef60SJ. Bruce Fields } 1798b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 1799b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 1800b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 1801b86cef60SJ. Bruce Fields } 1802b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 18031ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 1804b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 1805b86cef60SJ. Bruce Fields } 1806b86cef60SJ. Bruce Fields /* 1807b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 1808b86cef60SJ. Bruce Fields * supported_attributes) 1809b86cef60SJ. Bruce Fields */ 1810b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 1811b86cef60SJ. Bruce Fields /* bitmask, length */ 1812b86cef60SJ. Bruce Fields ret += 20; 1813b86cef60SJ. Bruce Fields return ret; 1814b86cef60SJ. Bruce Fields } 1815b86cef60SJ. Bruce Fields 181658e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 181758e7b33aSMi Jinlong { 181858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 181958e7b33aSMi Jinlong * sizeof(__be32); 182058e7b33aSMi Jinlong } 182158e7b33aSMi Jinlong 182258e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 182358e7b33aSMi Jinlong { 182458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 182558e7b33aSMi Jinlong * sizeof(__be32); 182658e7b33aSMi Jinlong } 182758e7b33aSMi Jinlong 182858e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 182958e7b33aSMi Jinlong { 183058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 183158e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 183258e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 183358e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 183458e7b33aSMi Jinlong } 183558e7b33aSMi Jinlong 183658e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 183758e7b33aSMi Jinlong { 183858e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 183958e7b33aSMi Jinlong 184058e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 18413c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 184258e7b33aSMi Jinlong 1843622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 184458e7b33aSMi Jinlong } 184558e7b33aSMi Jinlong 184658e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 184758e7b33aSMi Jinlong { 18483c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 184958e7b33aSMi Jinlong 18503c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 18513c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 185258e7b33aSMi Jinlong 1853561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 1854561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 185558e7b33aSMi Jinlong } 185658e7b33aSMi Jinlong 185758e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 185858e7b33aSMi Jinlong { 185958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 186058e7b33aSMi Jinlong * sizeof(__be32); 186158e7b33aSMi Jinlong } 186258e7b33aSMi Jinlong 186358e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 186458e7b33aSMi Jinlong { 186558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 186658e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 186758e7b33aSMi Jinlong } 186858e7b33aSMi Jinlong 1869ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 1870ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 1871ccae70a9SJ. Bruce Fields { 1872d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 1873d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 1874ccae70a9SJ. Bruce Fields } 1875ccae70a9SJ. Bruce Fields 187658e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 187758e7b33aSMi Jinlong { 187858e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 187958e7b33aSMi Jinlong } 188058e7b33aSMi Jinlong 188158e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 188258e7b33aSMi Jinlong { 1883480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 1884480efaeeSJ. Bruce Fields sizeof(__be32); 188558e7b33aSMi Jinlong } 188658e7b33aSMi Jinlong 188758e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 188858e7b33aSMi Jinlong { 1889f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 189058e7b33aSMi Jinlong } 189158e7b33aSMi Jinlong 189258e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 189358e7b33aSMi Jinlong { 189458e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 1895a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 1896a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 189758e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 189858e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 189958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 190058e7b33aSMi Jinlong /* eir_server_scope<> */\ 190158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 190258e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 190358e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 190458e7b33aSMi Jinlong } 190558e7b33aSMi Jinlong 190658e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 190758e7b33aSMi Jinlong { 190858e7b33aSMi Jinlong return (op_encode_hdr_size + \ 190958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 191058e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 191158e7b33aSMi Jinlong } 191258e7b33aSMi Jinlong 191358e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 191458e7b33aSMi Jinlong { 191558e7b33aSMi Jinlong return (op_encode_hdr_size + \ 191658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 191758e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 191858e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 191958e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 192058e7b33aSMi Jinlong } 192158e7b33aSMi Jinlong 19229cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 19239cf514ccSChristoph Hellwig /* 19249cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 19259cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 19269cf514ccSChristoph Hellwig */ 19279cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 19289cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19299cf514ccSChristoph Hellwig { 19309cf514ccSChristoph Hellwig return (op_encode_hdr_size + 19319cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 19329cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 19339cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 19349cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 19359cf514ccSChristoph Hellwig } 19369cf514ccSChristoph Hellwig 19379cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19389cf514ccSChristoph Hellwig { 19399cf514ccSChristoph Hellwig return (op_encode_hdr_size + 19409cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 19419cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 19429cf514ccSChristoph Hellwig } 19439cf514ccSChristoph Hellwig 19449cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19459cf514ccSChristoph Hellwig { 19469cf514ccSChristoph Hellwig return (op_encode_hdr_size + 19479cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 19489cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 19499cf514ccSChristoph Hellwig } 19509cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 19519cf514ccSChristoph Hellwig 195220766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1953b591480bSJ.Bruce Fields [OP_ACCESS] = { 1954b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1955b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1956b591480bSJ.Bruce Fields }, 1957b591480bSJ.Bruce Fields [OP_CLOSE] = { 1958b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 195958e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1960b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 196158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 19628b70484cSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid, 19638b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid, 1964b591480bSJ.Bruce Fields }, 1965b591480bSJ.Bruce Fields [OP_COMMIT] = { 1966b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 196758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1968b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 196958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize, 1970b591480bSJ.Bruce Fields }, 1971b591480bSJ.Bruce Fields [OP_CREATE] = { 1972b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1973d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 1974b001a1b6SBenny Halevy .op_name = "OP_CREATE", 197558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize, 1976b591480bSJ.Bruce Fields }, 1977b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1978b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 197958e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 1980b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 198158e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 19829428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid, 1983b591480bSJ.Bruce Fields }, 1984b591480bSJ.Bruce Fields [OP_GETATTR] = { 1985b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 1986eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 1987b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 1988b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 1989b591480bSJ.Bruce Fields }, 1990b591480bSJ.Bruce Fields [OP_GETFH] = { 1991b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 1992b001a1b6SBenny Halevy .op_name = "OP_GETFH", 1993b591480bSJ.Bruce Fields }, 1994b591480bSJ.Bruce Fields [OP_LINK] = { 1995b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 1996c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 1997c856694eSJ. Bruce Fields | OP_CACHEME, 1998b001a1b6SBenny Halevy .op_name = "OP_LINK", 199958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize, 2000b591480bSJ.Bruce Fields }, 2001b591480bSJ.Bruce Fields [OP_LOCK] = { 2002b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 200358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2004b001a1b6SBenny Halevy .op_name = "OP_LOCK", 200558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, 200662cd4a59STigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid, 2007b591480bSJ.Bruce Fields }, 2008b591480bSJ.Bruce Fields [OP_LOCKT] = { 2009b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 2010b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 2011b591480bSJ.Bruce Fields }, 2012b591480bSJ.Bruce Fields [OP_LOCKU] = { 2013b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 201458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2015b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 201658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 201762cd4a59STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid, 2018b591480bSJ.Bruce Fields }, 2019b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2020b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 2021d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2022b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 2023b591480bSJ.Bruce Fields }, 2024b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2025b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 2026d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2027b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 2028b591480bSJ.Bruce Fields }, 2029b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2030b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 2031b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 2032b591480bSJ.Bruce Fields }, 2033b591480bSJ.Bruce Fields [OP_OPEN] = { 2034b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 203558e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2036b001a1b6SBenny Halevy .op_name = "OP_OPEN", 203758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize, 20388b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid, 2039b591480bSJ.Bruce Fields }, 2040b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2041b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 204258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2043b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 204458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 2045b591480bSJ.Bruce Fields }, 2046b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2047b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 204858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2049b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 205058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 20519428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid, 20529428fe1aSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid, 2053b591480bSJ.Bruce Fields }, 2054b591480bSJ.Bruce Fields [OP_PUTFH] = { 2055b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 205668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 20575b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2058b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 205958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2060b591480bSJ.Bruce Fields }, 2061eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2062a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 206368d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 20645b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2065b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 206658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2067eeac294eSJ.Bruce Fields }, 2068b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2069b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 207068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 20715b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2072b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 207358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2074b591480bSJ.Bruce Fields }, 2075b591480bSJ.Bruce Fields [OP_READ] = { 2076b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 2077b001a1b6SBenny Halevy .op_name = "OP_READ", 207858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, 207930813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, 2080b591480bSJ.Bruce Fields }, 2081b591480bSJ.Bruce Fields [OP_READDIR] = { 2082b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 2083b001a1b6SBenny Halevy .op_name = "OP_READDIR", 208458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, 2085b591480bSJ.Bruce Fields }, 2086b591480bSJ.Bruce Fields [OP_READLINK] = { 2087b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 2088b001a1b6SBenny Halevy .op_name = "OP_READLINK", 2089b591480bSJ.Bruce Fields }, 2090b591480bSJ.Bruce Fields [OP_REMOVE] = { 2091b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 2092c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2093b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 209458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize, 2095b591480bSJ.Bruce Fields }, 2096b591480bSJ.Bruce Fields [OP_RENAME] = { 2097b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 2098c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 209958e7b33aSMi Jinlong .op_name = "OP_RENAME", 210058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize, 2101b591480bSJ.Bruce Fields }, 2102b591480bSJ.Bruce Fields [OP_RENEW] = { 2103b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 210458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 210558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2106b001a1b6SBenny Halevy .op_name = "OP_RENEW", 210758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 210858e7b33aSMi Jinlong 2109b591480bSJ.Bruce Fields }, 2110b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2111b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 211268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 211358e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2114b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 211558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2116b591480bSJ.Bruce Fields }, 2117b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2118b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 211958e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2120b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 212158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2122b591480bSJ.Bruce Fields }, 2123dcb488a3SAndy Adamson [OP_SECINFO] = { 2124dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 212568d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2126b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 2127dcb488a3SAndy Adamson }, 2128b591480bSJ.Bruce Fields [OP_SETATTR] = { 2129b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 2130b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2131c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 213258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize, 21331e97b519STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid, 2134b591480bSJ.Bruce Fields }, 2135b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2136b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 213758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2138c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2139b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 214058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize, 2141b591480bSJ.Bruce Fields }, 2142b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2143b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 214458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2145c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2146b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 214758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2148b591480bSJ.Bruce Fields }, 2149b591480bSJ.Bruce Fields [OP_VERIFY] = { 2150b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 2151b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 2152b591480bSJ.Bruce Fields }, 2153b591480bSJ.Bruce Fields [OP_WRITE] = { 2154b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 2155c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2156b001a1b6SBenny Halevy .op_name = "OP_WRITE", 215758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 215830813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid, 2159b591480bSJ.Bruce Fields }, 2160b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2161b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 216258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 216358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2164b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 216558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2166b591480bSJ.Bruce Fields }, 2167069b6ad4SAndy Adamson 2168069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2169069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2170069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 217158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 217258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2173069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 217458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize, 2175069b6ad4SAndy Adamson }, 2176cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2177cb73a9f4SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_backchannel_ctl, 2178cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2179cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 2180cb73a9f4SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2181cb73a9f4SJ. Bruce Fields }, 21821d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 21831d1bc8f2SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, 218458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 218558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 21861d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 218758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize, 21881d1bc8f2SJ. Bruce Fields }, 2189069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2190069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 219158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 219258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2193069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 219458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize, 2195069b6ad4SAndy Adamson }, 2196069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2197069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 219858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 219958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2200069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 220158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2202069b6ad4SAndy Adamson }, 2203069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2204069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 2205f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2206069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 2207d1d84c96SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize, 2208069b6ad4SAndy Adamson }, 2209094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2210345c2842SMi Jinlong .op_func = (nfsd4op_func)nfsd4_destroy_clientid, 221158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 221258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2213094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 221458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2215094b5d74SBenny Halevy }, 22164dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 22174dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 221858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 22194dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 222058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 22214dc6ec00SJ. Bruce Fields }, 222204f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 222304f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 222468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 222504f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 222604f4ad16SJ. Bruce Fields }, 222717456804SBryan Schumaker [OP_TEST_STATEID] = { 222817456804SBryan Schumaker .op_func = (nfsd4op_func)nfsd4_test_stateid, 222917456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 223017456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 223117456804SBryan Schumaker }, 2232e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 2233e1ca12dfSBryan Schumaker .op_func = (nfsd4op_func)nfsd4_free_stateid, 223458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2235e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 2236a1dc6955SJ. Bruce Fields .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid, 223758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2238e1ca12dfSBryan Schumaker }, 22399cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 22409cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 22419cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_getdeviceinfo, 22429cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 22439cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 22449cf514ccSChristoph Hellwig }, 22459cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 22469cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutget, 22479cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 22489cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 22499cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize, 22509cf514ccSChristoph Hellwig }, 22519cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 22529cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutcommit, 22539cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 22549cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 22559cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize, 22569cf514ccSChristoph Hellwig }, 22579cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 22589cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutreturn, 22599cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 22609cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 22619cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize, 22629cf514ccSChristoph Hellwig }, 22639cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 226424bab491SAnna Schumaker 226524bab491SAnna Schumaker /* NFSv4.2 operations */ 226695d871f0SAnna Schumaker [OP_ALLOCATE] = { 226795d871f0SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_allocate, 226895d871f0SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 226995d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 2270beaca234SKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 227195d871f0SAnna Schumaker }, 2272b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 2273b0cb9085SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_deallocate, 2274b0cb9085SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2275b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 2276beaca234SKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2277b0cb9085SAnna Schumaker }, 227824bab491SAnna Schumaker [OP_SEEK] = { 227924bab491SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_seek, 228024bab491SAnna Schumaker .op_name = "OP_SEEK", 228124bab491SAnna Schumaker }, 2282b591480bSJ.Bruce Fields }; 2283b591480bSJ.Bruce Fields 22844f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 22854f0cefbfSJ. Bruce Fields { 22864f0cefbfSJ. Bruce Fields struct nfsd4_operation *opdesc; 22874f0cefbfSJ. Bruce Fields nfsd4op_rsize estimator; 22884f0cefbfSJ. Bruce Fields 22894f0cefbfSJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 22904f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 22914f0cefbfSJ. Bruce Fields opdesc = OPDESC(op); 22924f0cefbfSJ. Bruce Fields estimator = opdesc->op_rsize_bop; 22934f0cefbfSJ. Bruce Fields return estimator ? estimator(rqstp, op) : PAGE_SIZE; 22944f0cefbfSJ. Bruce Fields } 22954f0cefbfSJ. Bruce Fields 229607d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 229707d1f802SJ. Bruce Fields { 229807d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 229907d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 230007d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 230107d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 230207d1f802SJ. Bruce Fields } 230307d1f802SJ. Bruce Fields } 230407d1f802SJ. Bruce Fields 2305f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 2306b001a1b6SBenny Halevy { 2307b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 2308b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 2309b001a1b6SBenny Halevy return "unknown_operation"; 2310b001a1b6SBenny Halevy } 2311b001a1b6SBenny Halevy 23121da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 23131da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 23141da177e4SLinus Torvalds 23151da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 23160a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 23170a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_null, 23180a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 23190a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 23200a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 23210a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 23220a93a47fSYu Zhiguo .pc_xdrressize = 1, 23230a93a47fSYu Zhiguo }, 23240a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 23250a93a47fSYu Zhiguo .pc_func = (svc_procfunc) nfsd4_proc_compound, 23260a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 23270a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 23280a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 23290a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 23303e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 23310a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 23320a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 23330a93a47fSYu Zhiguo }, 23341da177e4SLinus Torvalds }; 23351da177e4SLinus Torvalds 23361da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 23371da177e4SLinus Torvalds .vs_vers = 4, 23381da177e4SLinus Torvalds .vs_nproc = 2, 23391da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 23401da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 23411da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 23427e55b59bSKinglong Mee .vs_rpcb_optnl = 1, 23431da177e4SLinus Torvalds }; 23441da177e4SLinus Torvalds 23451da177e4SLinus Torvalds /* 23461da177e4SLinus Torvalds * Local variables: 23471da177e4SLinus Torvalds * c-basic-offset: 8 23481da177e4SLinus Torvalds * End: 23491da177e4SLinus Torvalds */ 2350