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 */ 35880a3a53SJ. Bruce Fields #include <linux/fs_struct.h> 367e06b7f9SNeilBrown #include <linux/file.h> 37b0cb9085SAnna Schumaker #include <linux/falloc.h> 385a0e3ad6STejun Heo #include <linux/slab.h> 39e0639dc5SOlga Kornievskaia #include <linux/kthread.h> 401da177e4SLinus Torvalds 4158e7b33aSMi Jinlong #include "idmap.h" 429a74af21SBoaz Harrosh #include "cache.h" 439a74af21SBoaz Harrosh #include "xdr4.h" 440a3adadeSJ. Bruce Fields #include "vfs.h" 458b70484cSTigran Mkrtchyan #include "current_stateid.h" 463320fef1SStanislav Kinsbursky #include "netns.h" 474ac7249eSChristoph Hellwig #include "acl.h" 489cf514ccSChristoph Hellwig #include "pnfs.h" 4931ef83dcSChristoph Hellwig #include "trace.h" 501da177e4SLinus Torvalds 5118032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 5218032ca0SDavid Quigley #include <linux/security.h> 5318032ca0SDavid Quigley 5418032ca0SDavid Quigley static inline void 5518032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 5618032ca0SDavid Quigley { 572b0143b5SDavid Howells struct inode *inode = d_inode(resfh->fh_dentry); 5818032ca0SDavid Quigley int status; 5918032ca0SDavid Quigley 605955102cSAl Viro inode_lock(inode); 6118032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 6218032ca0SDavid Quigley label->data, label->len); 635955102cSAl Viro inode_unlock(inode); 6418032ca0SDavid Quigley 6518032ca0SDavid Quigley if (status) 6618032ca0SDavid Quigley /* 6718032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 6818032ca0SDavid Quigley * already have created a new file, so it may be too 6918032ca0SDavid Quigley * late. For now this seems the least of evils: 7018032ca0SDavid Quigley */ 7118032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 7218032ca0SDavid Quigley 7318032ca0SDavid Quigley return; 7418032ca0SDavid Quigley } 7518032ca0SDavid Quigley #else 7618032ca0SDavid Quigley static inline void 7718032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7818032ca0SDavid Quigley { } 7918032ca0SDavid Quigley #endif 8018032ca0SDavid Quigley 811da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 821da177e4SLinus Torvalds 833c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 843c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 853c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 863c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 873c8e0316SYu Zhiguo }; 883c8e0316SYu Zhiguo 893c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 903c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 913c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 923c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 933c8e0316SYu Zhiguo }; 943c8e0316SYu Zhiguo 953c8e0316SYu Zhiguo static __be32 963c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 973c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 983c8e0316SYu Zhiguo { 993c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 10032ddd944SJ. Bruce Fields struct svc_export *exp = cstate->current_fh.fh_export; 1013c8e0316SYu Zhiguo 102916d2d84SJ. Bruce Fields if (!nfsd_attrs_supported(cstate->minorversion, bmval)) 1033c8e0316SYu Zhiguo return nfserr_attrnotsupp; 104916d2d84SJ. Bruce Fields if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) 1053c8e0316SYu Zhiguo return nfserr_attrnotsupp; 10632ddd944SJ. Bruce Fields if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && 10732ddd944SJ. Bruce Fields !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) 10832ddd944SJ. Bruce Fields return nfserr_attrnotsupp; 109916d2d84SJ. Bruce Fields if (writable && !bmval_is_subset(bmval, writable)) 1103c8e0316SYu Zhiguo return nfserr_inval; 11147057abdSAndreas Gruenbacher if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && 11247057abdSAndreas Gruenbacher (bmval[1] & FATTR4_WORD1_MODE)) 11347057abdSAndreas Gruenbacher return nfserr_inval; 1143c8e0316SYu Zhiguo return nfs_ok; 1153c8e0316SYu Zhiguo } 1163c8e0316SYu Zhiguo 1173c8e0316SYu Zhiguo static __be32 1183c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1193c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1203c8e0316SYu Zhiguo { 1213c8e0316SYu Zhiguo __be32 status = nfs_ok; 1223c8e0316SYu Zhiguo 1233c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1243c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1253c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1263c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1273c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1283c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1293c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1303c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1313c8e0316SYu Zhiguo } 1323c8e0316SYu Zhiguo 1333c8e0316SYu Zhiguo return status; 1343c8e0316SYu Zhiguo } 1353c8e0316SYu Zhiguo 1369208faf2SYu Zhiguo static int 1379208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1389208faf2SYu Zhiguo { 1399208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1409208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1419208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1429208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1439208faf2SYu Zhiguo } 1449208faf2SYu Zhiguo 1459208faf2SYu Zhiguo /* 1469208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1479208faf2SYu Zhiguo * in the returned attr bitmap. 1489208faf2SYu Zhiguo */ 1499208faf2SYu Zhiguo static void 1509208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1519208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1529208faf2SYu Zhiguo { 1539208faf2SYu Zhiguo __be32 status; 1549208faf2SYu Zhiguo 1559208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1569208faf2SYu Zhiguo if (status) 1579208faf2SYu Zhiguo /* 1589208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1599208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1609208faf2SYu Zhiguo * So this seems the least of evils: 1619208faf2SYu Zhiguo */ 1629208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1639208faf2SYu Zhiguo } 1649208faf2SYu Zhiguo 1651da177e4SLinus Torvalds static inline void 1661da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1671da177e4SLinus Torvalds { 1681da177e4SLinus Torvalds fh_put(dst); 1691da177e4SLinus Torvalds dget(src->fh_dentry); 1701da177e4SLinus Torvalds if (src->fh_export) 171bf18f163SKinglong Mee exp_get(src->fh_export); 1721da177e4SLinus Torvalds *dst = *src; 1731da177e4SLinus Torvalds } 1741da177e4SLinus Torvalds 175b37ad28bSAl Viro static __be32 176dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1771da177e4SLinus Torvalds { 178b37ad28bSAl Viro __be32 status; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds if (open->op_truncate && 1811da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1821da177e4SLinus Torvalds return nfserr_inval; 1831da177e4SLinus Torvalds 184a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 185a043226bSJ. Bruce Fields 1861da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 1878837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 1889801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 1898837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 19057ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 1918837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds return status; 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds 198aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 199aadab6c6SJ. Bruce Fields { 2002b0143b5SDavid Howells umode_t mode = d_inode(fh->fh_dentry)->i_mode; 201aadab6c6SJ. Bruce Fields 202aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 203aadab6c6SJ. Bruce Fields return nfs_ok; 204aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 205aadab6c6SJ. Bruce Fields return nfserr_isdir; 206aadab6c6SJ. Bruce Fields /* 207aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 208aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 209aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 210aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 211aadab6c6SJ. Bruce Fields * regular file. 212aadab6c6SJ. Bruce Fields */ 213aadab6c6SJ. Bruce Fields return nfserr_symlink; 214aadab6c6SJ. Bruce Fields } 215aadab6c6SJ. Bruce Fields 216bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2171da177e4SLinus Torvalds { 218bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 219bbc9c36cSJ. Bruce Fields return; 220bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 221bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 222bbc9c36cSJ. Bruce Fields } 223bbc9c36cSJ. Bruce Fields 224bbc9c36cSJ. Bruce Fields static __be32 225c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 226bbc9c36cSJ. Bruce Fields { 227bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 2287007c90fSNeil Brown int accmode; 229b37ad28bSAl Viro __be32 status; 2301da177e4SLinus Torvalds 231c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 232c0e6bee4SJ. Bruce Fields if (!*resfh) 23359deeb9eSJ. Bruce Fields return nfserr_jukebox; 234c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 2351da177e4SLinus Torvalds open->op_truncate = 0; 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds if (open->op_create) { 23879fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 23979fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 24079fb54abSBenny Halevy * 24179fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 24279fb54abSBenny Halevy * Reply Cache | server | | 24379fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 24479fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 24579fb54abSBenny Halevy * | | | (SHOULD) 24679fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 24779fb54abSBenny Halevy * | | | (SHOULD NOT) 24879fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 24979fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 25079fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 25179fb54abSBenny Halevy */ 25279fb54abSBenny Halevy 2531da177e4SLinus Torvalds /* 2541da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 255ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2561da177e4SLinus Torvalds */ 257880a3a53SJ. Bruce Fields current->fs->umask = open->op_umask; 258ac6721a1SMi Jinlong status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, 2591da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 260c0e6bee4SJ. Bruce Fields *resfh, open->op_createmode, 261749997e5SJeff Layton (u32 *)open->op_verf.data, 262856121b2SJ. Bruce Fields &open->op_truncate, &open->op_created); 263880a3a53SJ. Bruce Fields current->fs->umask = 0; 264749997e5SJeff Layton 26518032ca0SDavid Quigley if (!status && open->op_label.len) 266c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 26718032ca0SDavid Quigley 26899f88726SJ. Bruce Fields /* 269ead8fb8cSKinglong Mee * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 270ead8fb8cSKinglong Mee * use the returned bitmask to indicate which attributes 271ead8fb8cSKinglong Mee * we used to store the verifier: 272749997e5SJeff Layton */ 273ead8fb8cSKinglong Mee if (nfsd_create_is_exclusive(open->op_createmode) && status == 0) 274ead8fb8cSKinglong Mee open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | 275749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 2764335723eSJ. Bruce Fields } else 2774335723eSJ. Bruce Fields /* 2784335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 2794335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 2804335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 2814335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 2824335723eSJ. Bruce Fields */ 2831da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 284c0e6bee4SJ. Bruce Fields open->op_fname.data, open->op_fname.len, *resfh); 285aadab6c6SJ. Bruce Fields if (status) 286aadab6c6SJ. Bruce Fields goto out; 287c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 288af85852dSJ. Bruce Fields if (status) 289af85852dSJ. Bruce Fields goto out; 2901da177e4SLinus Torvalds 2919208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 292c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 2939208faf2SYu Zhiguo 294c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 2957007c90fSNeil Brown accmode = NFSD_MAY_NOP; 29689f6c336SJ. Bruce Fields if (open->op_created || 29789f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 2987007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 299c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 30041fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 301af85852dSJ. Bruce Fields out: 3021da177e4SLinus Torvalds return status; 3031da177e4SLinus Torvalds } 3041da177e4SLinus Torvalds 305b37ad28bSAl Viro static __be32 306bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 3071da177e4SLinus Torvalds { 308bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 309b37ad28bSAl Viro __be32 status; 3109f415eb2SJ. Bruce Fields int accmode = 0; 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 3131da177e4SLinus Torvalds * set the change info 3141da177e4SLinus Torvalds */ 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 3171da177e4SLinus Torvalds 318bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 3211da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 3229f415eb2SJ. Bruce Fields /* 3239f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 3249f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 3259f415eb2SJ. Bruce Fields * should let it succeed now if possible. 3269f415eb2SJ. Bruce Fields * 3279f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 3289f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 3299f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 3309f415eb2SJ. Bruce Fields */ 3319f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 3329f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 3331da177e4SLinus Torvalds 3349f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds return status; 3371da177e4SLinus Torvalds } 3381da177e4SLinus Torvalds 33960adfc50SAndy Adamson static void 34060adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 34160adfc50SAndy Adamson { 34260adfc50SAndy Adamson struct nfsd4_sessionid *sid = 34360adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 34460adfc50SAndy Adamson 34560adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 34660adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 34760adfc50SAndy Adamson } 3481da177e4SLinus Torvalds 3497191155bSJ.Bruce Fields static __be32 350ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 351eb69853dSChristoph Hellwig union nfsd4_op_u *u) 3521da177e4SLinus Torvalds { 353eb69853dSChristoph Hellwig struct nfsd4_open *open = &u->open; 354b37ad28bSAl Viro __be32 status; 355c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 3563320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3573320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 35803f318caSJ. Bruce Fields bool reclaim = false; 3596668958fSAndy Adamson 360fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3611da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 362fe0750e5SJ. Bruce Fields open->op_openowner); 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds /* This check required by spec. */ 3651da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3661da177e4SLinus Torvalds return nfserr_inval; 3671da177e4SLinus Torvalds 368856121b2SJ. Bruce Fields open->op_created = 0; 369ab1350b2SMi Jinlong /* 370ab1350b2SMi Jinlong * RFC5661 18.51.3 371ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 372ab1350b2SMi Jinlong */ 373ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 374a52d726bSJeff Layton !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, 375a52d726bSJeff Layton &cstate->session->se_client->cl_flags) && 376ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 377ab1350b2SMi Jinlong return nfserr_grace; 378ab1350b2SMi Jinlong 37960adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 38060adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 38160adfc50SAndy Adamson 3821da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3836cd22668SKinglong Mee status = nfsd4_process_open1(cstate, open, nn); 384a90b061cSAl Viro if (status == nfserr_replay_me) { 385fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 386ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 387a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 388a4773c08SJ. Bruce Fields &rp->rp_openfh); 3898837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3901da177e4SLinus Torvalds if (status) 3911da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 3921da177e4SLinus Torvalds " restoring previous filehandle\n"); 3931da177e4SLinus Torvalds else 394a90b061cSAl Viro status = nfserr_replay_me; 3951da177e4SLinus Torvalds } 3961da177e4SLinus Torvalds if (status) 3971da177e4SLinus Torvalds goto out; 3989d313b17SJ. Bruce Fields if (open->op_xdr_error) { 3999d313b17SJ. Bruce Fields status = open->op_xdr_error; 4009d313b17SJ. Bruce Fields goto out; 4019d313b17SJ. Bruce Fields } 402fb553c0fSJ. Bruce Fields 4033c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 4043c8e0316SYu Zhiguo if (status) 4053c8e0316SYu Zhiguo goto out; 4063c8e0316SYu Zhiguo 407fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 408fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 409cbd0d51aSJ. Bruce Fields status = nfserr_grace; 410c87fb4a3SJ. Bruce Fields if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 411cbd0d51aSJ. Bruce Fields goto out; 412cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 413c87fb4a3SJ. Bruce Fields if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 414cbd0d51aSJ. Bruce Fields goto out; 415fb553c0fSJ. Bruce Fields 4161da177e4SLinus Torvalds switch (open->op_claim_type) { 4170dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4181da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 419c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4201da177e4SLinus Torvalds if (status) 4211da177e4SLinus Torvalds goto out; 4221da177e4SLinus Torvalds break; 4231da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 4243320fef1SStanislav Kinsbursky status = nfs4_check_open_reclaim(&open->op_clientid, 4250fe492dbSTrond Myklebust cstate, nn); 4260cf99b91SMi Jinlong if (status) 4270cf99b91SMi Jinlong goto out; 428ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 42903f318caSJ. Bruce Fields reclaim = true; 4300a4c9265SGustavo A. R. Silva /* fall through */ 4318b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4328b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 433bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4341da177e4SLinus Torvalds if (status) 4351da177e4SLinus Torvalds goto out; 436c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4371da177e4SLinus Torvalds break; 4388b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4391da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4402fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4411da177e4SLinus Torvalds open->op_claim_type); 4421da177e4SLinus Torvalds status = nfserr_notsupp; 4431da177e4SLinus Torvalds goto out; 4441da177e4SLinus Torvalds default: 4452fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4461da177e4SLinus Torvalds open->op_claim_type); 4471da177e4SLinus Torvalds status = nfserr_inval; 4481da177e4SLinus Torvalds goto out; 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds /* 4511da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4521da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4531da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4541da177e4SLinus Torvalds */ 455c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 456b3fbfe0eSJeff Layton WARN(status && open->op_created, 457b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 458b3fbfe0eSJeff Layton be32_to_cpu(status)); 45903f318caSJ. Bruce Fields if (reclaim && !status) 46003f318caSJ. Bruce Fields nn->somebody_reclaimed = true; 4611da177e4SLinus Torvalds out: 462c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 463c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 464c0e6bee4SJ. Bruce Fields fh_put(resfh); 465c0e6bee4SJ. Bruce Fields kfree(resfh); 466c0e6bee4SJ. Bruce Fields } 46742297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4689411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4691da177e4SLinus Torvalds return status; 4701da177e4SLinus Torvalds } 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds /* 4739d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4749d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4759d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4769d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4779d313b17SJ. Bruce Fields */ 4789d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4799d313b17SJ. Bruce Fields { 480eb69853dSChristoph Hellwig struct nfsd4_open *open = &op->u.open; 4819d313b17SJ. Bruce Fields 4829d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4839d313b17SJ. Bruce Fields return op->status; 4849d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4859d313b17SJ. Bruce Fields return op->status; 4869d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 487eb69853dSChristoph Hellwig return nfsd4_open(rqstp, cstate, &op->u); 4889d313b17SJ. Bruce Fields } 4899d313b17SJ. Bruce Fields 4909d313b17SJ. Bruce Fields /* 4911da177e4SLinus Torvalds * filehandle-manipulating ops. 4921da177e4SLinus Torvalds */ 4937191155bSJ.Bruce Fields static __be32 494b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 495eb69853dSChristoph Hellwig union nfsd4_op_u *u) 4961da177e4SLinus Torvalds { 497eb69853dSChristoph Hellwig u->getfh = &cstate->current_fh; 4981da177e4SLinus Torvalds return nfs_ok; 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds 5017191155bSJ.Bruce Fields static __be32 502ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 503eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5041da177e4SLinus Torvalds { 505eb69853dSChristoph Hellwig struct nfsd4_putfh *putfh = &u->putfh; 506eb69853dSChristoph Hellwig 507ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 508ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 509ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 510ca364317SJ.Bruce Fields putfh->pf_fhlen); 51168d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds 5147191155bSJ.Bruce Fields static __be32 515b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 516eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5171da177e4SLinus Torvalds { 518b37ad28bSAl Viro __be32 status; 5191da177e4SLinus Torvalds 520ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 521df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5221da177e4SLinus Torvalds return status; 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds 5257191155bSJ.Bruce Fields static __be32 526b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 527eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5281da177e4SLinus Torvalds { 529ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5301da177e4SLinus Torvalds return nfserr_restorefh; 5311da177e4SLinus Torvalds 532ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 53337c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 53437c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 53537c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 53637c593c5STigran Mkrtchyan } 5371da177e4SLinus Torvalds return nfs_ok; 5381da177e4SLinus Torvalds } 5391da177e4SLinus Torvalds 5407191155bSJ.Bruce Fields static __be32 541b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 542eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5431da177e4SLinus Torvalds { 544ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 54537c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 54637c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 54737c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 54837c593c5STigran Mkrtchyan } 5491da177e4SLinus Torvalds return nfs_ok; 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds /* 5531da177e4SLinus Torvalds * misc nfsv4 ops 5541da177e4SLinus Torvalds */ 5557191155bSJ.Bruce Fields static __be32 556ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 557eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5581da177e4SLinus Torvalds { 559eb69853dSChristoph Hellwig struct nfsd4_access *access = &u->access; 560eb69853dSChristoph Hellwig 5611da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5621da177e4SLinus Torvalds return nfserr_inval; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 565ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 566ca364317SJ.Bruce Fields &access->ac_supported); 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds 569b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 570ab4684d1SChuck Lever { 57127c438f5STrond Myklebust __be32 *verf = (__be32 *)verifier->data; 572ab4684d1SChuck Lever 57327c438f5STrond Myklebust BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data)); 57427c438f5STrond Myklebust 57527c438f5STrond Myklebust nfsd_copy_boot_verifier(verf, net_generic(net, nfsd_net_id)); 576ab4684d1SChuck Lever } 577ab4684d1SChuck Lever 5787191155bSJ.Bruce Fields static __be32 579ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 580eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5811da177e4SLinus Torvalds { 582eb69853dSChristoph Hellwig struct nfsd4_commit *commit = &u->commit; 583eb69853dSChristoph Hellwig 584b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 58575c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 586ca364317SJ.Bruce Fields commit->co_count); 5871da177e4SLinus Torvalds } 5881da177e4SLinus Torvalds 589b37ad28bSAl Viro static __be32 590ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 591eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5921da177e4SLinus Torvalds { 593eb69853dSChristoph Hellwig struct nfsd4_create *create = &u->create; 5941da177e4SLinus Torvalds struct svc_fh resfh; 595b37ad28bSAl Viro __be32 status; 5961da177e4SLinus Torvalds dev_t rdev; 5971da177e4SLinus Torvalds 5981da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 5991da177e4SLinus Torvalds 600fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 6011da177e4SLinus Torvalds if (status) 6021da177e4SLinus Torvalds return status; 6031da177e4SLinus Torvalds 6043c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6053c8e0316SYu Zhiguo nfsd_attrmask); 6063c8e0316SYu Zhiguo if (status) 6073c8e0316SYu Zhiguo return status; 6083c8e0316SYu Zhiguo 609880a3a53SJ. Bruce Fields current->fs->umask = create->cr_umask; 6101da177e4SLinus Torvalds switch (create->cr_type) { 6111da177e4SLinus Torvalds case NF4LNK: 612ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 613ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6141e444f5bSKinglong Mee create->cr_data, &resfh); 6151da177e4SLinus Torvalds break; 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds case NF4BLK: 618880a3a53SJ. Bruce Fields status = nfserr_inval; 6191da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6201da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6211da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 622880a3a53SJ. Bruce Fields goto out_umask; 623ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 624ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 625ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6261da177e4SLinus Torvalds break; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds case NF4CHR: 629880a3a53SJ. Bruce Fields status = nfserr_inval; 6301da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6311da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6321da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 633880a3a53SJ. Bruce Fields goto out_umask; 634ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 635ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 636ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6371da177e4SLinus Torvalds break; 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds case NF4SOCK: 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_IFSOCK, 0, &resfh); 6431da177e4SLinus Torvalds break; 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds case NF4FIFO: 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_IFIFO, 0, &resfh); 6491da177e4SLinus Torvalds break; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds case NF4DIR: 6521da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 653ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 654ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 655ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6561da177e4SLinus Torvalds break; 6571da177e4SLinus Torvalds 6581da177e4SLinus Torvalds default: 6591da177e4SLinus Torvalds status = nfserr_badtype; 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds 6629208faf2SYu Zhiguo if (status) 6639208faf2SYu Zhiguo goto out; 6649208faf2SYu Zhiguo 66518032ca0SDavid Quigley if (create->cr_label.len) 66618032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 66718032ca0SDavid Quigley 6689208faf2SYu Zhiguo if (create->cr_acl != NULL) 6699208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6709208faf2SYu Zhiguo create->cr_bmval); 6719208faf2SYu Zhiguo 672ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 673ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 674ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6759208faf2SYu Zhiguo out: 6761da177e4SLinus Torvalds fh_put(&resfh); 677880a3a53SJ. Bruce Fields out_umask: 678880a3a53SJ. Bruce Fields current->fs->umask = 0; 6791da177e4SLinus Torvalds return status; 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds 6827191155bSJ.Bruce Fields static __be32 683ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 684eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6851da177e4SLinus Torvalds { 686eb69853dSChristoph Hellwig struct nfsd4_getattr *getattr = &u->getattr; 687b37ad28bSAl Viro __be32 status; 6881da177e4SLinus Torvalds 6898837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 6901da177e4SLinus Torvalds if (status) 6911da177e4SLinus Torvalds return status; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6941da177e4SLinus Torvalds return nfserr_inval; 6951da177e4SLinus Torvalds 696916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 697916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 698916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 6991da177e4SLinus Torvalds 700ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7011da177e4SLinus Torvalds return nfs_ok; 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds 7047191155bSJ.Bruce Fields static __be32 705ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 706eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7071da177e4SLinus Torvalds { 708eb69853dSChristoph Hellwig struct nfsd4_link *link = &u->link; 70995424460SJ. Bruce Fields __be32 status; 7101da177e4SLinus Torvalds 711ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 712ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7131da177e4SLinus Torvalds if (!status) 714ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7151da177e4SLinus Torvalds return status; 7161da177e4SLinus Torvalds } 7171da177e4SLinus Torvalds 7180ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7191da177e4SLinus Torvalds { 7201da177e4SLinus Torvalds struct svc_fh tmp_fh; 721b37ad28bSAl Viro __be32 ret; 7221da177e4SLinus Torvalds 7231da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 724df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 725df547efbSJ. Bruce Fields if (ret) 7261da177e4SLinus Torvalds return ret; 7270ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7281da177e4SLinus Torvalds fh_put(&tmp_fh); 7291da177e4SLinus Torvalds return nfserr_noent; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds fh_put(&tmp_fh); 7320ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7330ff7ab46SJ. Bruce Fields } 7340ff7ab46SJ. Bruce Fields 7350ff7ab46SJ. Bruce Fields static __be32 7360ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 737eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7380ff7ab46SJ. Bruce Fields { 7390ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds 7427191155bSJ.Bruce Fields static __be32 743ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 744eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7451da177e4SLinus Torvalds { 746ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 747eb69853dSChristoph Hellwig u->lookup.lo_name, u->lookup.lo_len, 748ca364317SJ.Bruce Fields &cstate->current_fh); 7491da177e4SLinus Torvalds } 7501da177e4SLinus Torvalds 7517191155bSJ.Bruce Fields static __be32 752ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 753eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7541da177e4SLinus Torvalds { 755eb69853dSChristoph Hellwig struct nfsd4_read *read = &u->read; 756b37ad28bSAl Viro __be32 status; 7571da177e4SLinus Torvalds 7585c4583b2SJeff Layton read->rd_nf = NULL; 7591da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7601da177e4SLinus Torvalds return nfserr_inval; 7611da177e4SLinus Torvalds 76287c5942eSChuck Lever trace_nfsd_read_start(rqstp, &cstate->current_fh, 76387c5942eSChuck Lever read->rd_offset, read->rd_length); 76487c5942eSChuck Lever 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 */ 777aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 778aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 7795c4583b2SJeff Layton &read->rd_nf); 780af90f707SChristoph Hellwig if (status) { 7811da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7821da177e4SLinus Torvalds goto out; 7831da177e4SLinus Torvalds } 7841da177e4SLinus Torvalds status = nfs_ok; 7851da177e4SLinus Torvalds out: 7861da177e4SLinus Torvalds read->rd_rqstp = rqstp; 787ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 7881da177e4SLinus Torvalds return status; 7891da177e4SLinus Torvalds } 7901da177e4SLinus Torvalds 79134b1744cSJ. Bruce Fields 79234b1744cSJ. Bruce Fields static void 79334b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u) 79434b1744cSJ. Bruce Fields { 7955c4583b2SJeff Layton if (u->read.rd_nf) 7965c4583b2SJeff Layton nfsd_file_put(u->read.rd_nf); 79787c5942eSChuck Lever trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, 79887c5942eSChuck Lever u->read.rd_offset, u->read.rd_length); 79934b1744cSJ. Bruce Fields } 80034b1744cSJ. Bruce Fields 8017191155bSJ.Bruce Fields static __be32 802ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 803eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8041da177e4SLinus Torvalds { 805eb69853dSChristoph Hellwig struct nfsd4_readdir *readdir = &u->readdir; 8061da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 8071da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8081da177e4SLinus Torvalds 8091da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8101da177e4SLinus Torvalds 8111da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8121da177e4SLinus Torvalds return nfserr_inval; 8131da177e4SLinus Torvalds 814916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 815916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 816916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 8171da177e4SLinus Torvalds 818832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8191da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8201da177e4SLinus Torvalds return nfserr_bad_cookie; 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 823ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8241da177e4SLinus Torvalds return nfs_ok; 8251da177e4SLinus Torvalds } 8261da177e4SLinus Torvalds 8277191155bSJ.Bruce Fields static __be32 828ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 829eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8301da177e4SLinus Torvalds { 831eb69853dSChristoph Hellwig u->readlink.rl_rqstp = rqstp; 832eb69853dSChristoph Hellwig u->readlink.rl_fhp = &cstate->current_fh; 8331da177e4SLinus Torvalds return nfs_ok; 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds 8367191155bSJ.Bruce Fields static __be32 837ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 838eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8391da177e4SLinus Torvalds { 840eb69853dSChristoph Hellwig struct nfsd4_remove *remove = &u->remove; 841b37ad28bSAl Viro __be32 status; 8421da177e4SLinus Torvalds 843c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 844c815afc7SNeilBrown return nfserr_grace; 845ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 846ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8471da177e4SLinus Torvalds if (!status) { 848ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 849ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8501da177e4SLinus Torvalds } 8511da177e4SLinus Torvalds return status; 8521da177e4SLinus Torvalds } 8531da177e4SLinus Torvalds 8547191155bSJ.Bruce Fields static __be32 855ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 856eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8571da177e4SLinus Torvalds { 858eb69853dSChristoph Hellwig struct nfsd4_rename *rename = &u->rename; 85995424460SJ. Bruce Fields __be32 status; 8601da177e4SLinus Torvalds 861f8f71d00SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 862c815afc7SNeilBrown return nfserr_grace; 863ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 864ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8651da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8662a6cf944SJ. Bruce Fields if (status) 8672a6cf944SJ. Bruce Fields return status; 868ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 869ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8702a6cf944SJ. Bruce Fields return nfs_ok; 8711da177e4SLinus Torvalds } 8721da177e4SLinus Torvalds 8737191155bSJ.Bruce Fields static __be32 874dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 875eb69853dSChristoph Hellwig union nfsd4_op_u *u) 876dcb488a3SAndy Adamson { 877eb69853dSChristoph Hellwig struct nfsd4_secinfo *secinfo = &u->secinfo; 878dcb488a3SAndy Adamson struct svc_export *exp; 879dcb488a3SAndy Adamson struct dentry *dentry; 880dcb488a3SAndy Adamson __be32 err; 881dcb488a3SAndy Adamson 88229a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 88329a78a3eSJ. Bruce Fields if (err) 88429a78a3eSJ. Bruce Fields return err; 885dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 886dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 887dcb488a3SAndy Adamson &exp, &dentry); 888dcb488a3SAndy Adamson if (err) 889dcb488a3SAndy Adamson return err; 8902f6fc056SJ. Bruce Fields fh_unlock(&cstate->current_fh); 8912b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 892dcb488a3SAndy Adamson exp_put(exp); 893dcb488a3SAndy Adamson err = nfserr_noent; 894dcb488a3SAndy Adamson } else 895dcb488a3SAndy Adamson secinfo->si_exp = exp; 896dcb488a3SAndy Adamson dput(dentry); 89756560b9aSJ. Bruce Fields if (cstate->minorversion) 89856560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 89956560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 900dcb488a3SAndy Adamson return err; 901dcb488a3SAndy Adamson } 902dcb488a3SAndy Adamson 903dcb488a3SAndy Adamson static __be32 90404f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 905eb69853dSChristoph Hellwig union nfsd4_op_u *u) 90604f4ad16SJ. Bruce Fields { 90704f4ad16SJ. Bruce Fields __be32 err; 90804f4ad16SJ. Bruce Fields 909eb69853dSChristoph Hellwig switch (u->secinfo_no_name.sin_style) { 91004f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 91104f4ad16SJ. Bruce Fields break; 91204f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 91304f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 91404f4ad16SJ. Bruce Fields if (err) 91504f4ad16SJ. Bruce Fields return err; 91604f4ad16SJ. Bruce Fields break; 91704f4ad16SJ. Bruce Fields default: 91804f4ad16SJ. Bruce Fields return nfserr_inval; 91904f4ad16SJ. Bruce Fields } 920bf18f163SKinglong Mee 921eb69853dSChristoph Hellwig u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export); 92204f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 92304f4ad16SJ. Bruce Fields return nfs_ok; 92404f4ad16SJ. Bruce Fields } 92504f4ad16SJ. Bruce Fields 92634b1744cSJ. Bruce Fields static void 92734b1744cSJ. Bruce Fields nfsd4_secinfo_release(union nfsd4_op_u *u) 92834b1744cSJ. Bruce Fields { 92934b1744cSJ. Bruce Fields if (u->secinfo.si_exp) 93034b1744cSJ. Bruce Fields exp_put(u->secinfo.si_exp); 93134b1744cSJ. Bruce Fields } 93234b1744cSJ. Bruce Fields 933ec572b9eSEryu Guan static void 934ec572b9eSEryu Guan nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) 935ec572b9eSEryu Guan { 936ec572b9eSEryu Guan if (u->secinfo_no_name.sin_exp) 937ec572b9eSEryu Guan exp_put(u->secinfo_no_name.sin_exp); 938ec572b9eSEryu Guan } 939ec572b9eSEryu Guan 94004f4ad16SJ. Bruce Fields static __be32 941ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 942eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9431da177e4SLinus Torvalds { 944eb69853dSChristoph Hellwig struct nfsd4_setattr *setattr = &u->setattr; 945b37ad28bSAl Viro __be32 status = nfs_ok; 94696f6f985SAl Viro int err; 9471da177e4SLinus Torvalds 9481da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 949af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 950aa0d6aedSAnna Schumaker &cstate->current_fh, &setattr->sa_stateid, 9515c4583b2SJeff Layton WR_STATE, NULL); 952375c5547SJ. Bruce Fields if (status) { 9533e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 954375c5547SJ. Bruce Fields return status; 955375c5547SJ. Bruce Fields } 9561da177e4SLinus Torvalds } 95796f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 95896f6f985SAl Viro if (err) 95996f6f985SAl Viro return nfserrno(err); 9601da177e4SLinus Torvalds status = nfs_ok; 9613c8e0316SYu Zhiguo 9623c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9633c8e0316SYu Zhiguo nfsd_attrmask); 9643c8e0316SYu Zhiguo if (status) 9653c8e0316SYu Zhiguo goto out; 9663c8e0316SYu Zhiguo 9671da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 968ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 969ca364317SJ.Bruce Fields setattr->sa_acl); 9701da177e4SLinus Torvalds if (status) 97118f335afSDave Hansen goto out; 97218032ca0SDavid Quigley if (setattr->sa_label.len) 97318032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 97418032ca0SDavid Quigley &setattr->sa_label); 97518032ca0SDavid Quigley if (status) 97618032ca0SDavid Quigley goto out; 977ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9781da177e4SLinus Torvalds 0, (time_t)0); 97918f335afSDave Hansen out: 980bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9811da177e4SLinus Torvalds return status; 9821da177e4SLinus Torvalds } 9831da177e4SLinus Torvalds 9847191155bSJ.Bruce Fields static __be32 985ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 986eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9871da177e4SLinus Torvalds { 988eb69853dSChristoph Hellwig struct nfsd4_write *write = &u->write; 9891da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 9905c4583b2SJeff Layton struct nfsd_file *nf = NULL; 991b37ad28bSAl Viro __be32 status = nfs_ok; 99231dec253SDavid Shaw unsigned long cnt; 993ffe1137bSJ. Bruce Fields int nvecs; 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 9961da177e4SLinus Torvalds return nfserr_inval; 9971da177e4SLinus Torvalds 998d890be15SChuck Lever cnt = write->wr_buflen; 999d890be15SChuck Lever trace_nfsd_write_start(rqstp, &cstate->current_fh, 1000d890be15SChuck Lever write->wr_offset, cnt); 1001aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 10025c4583b2SJeff Layton stateid, WR_STATE, &nf); 1003375c5547SJ. Bruce Fields if (status) { 1004375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 1005375c5547SJ. Bruce Fields return status; 1006375c5547SJ. Bruce Fields } 1007375c5547SJ. Bruce Fields 10081da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 1009b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); 10101da177e4SLinus Torvalds 10113fd9557aSChuck Lever nvecs = svc_fill_write_vector(rqstp, write->wr_pagelist, 10123fd9557aSChuck Lever &write->wr_head, write->wr_buflen); 1013ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1014ffe1137bSJ. Bruce Fields 10155c4583b2SJeff Layton status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf->nf_file, 1016af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 101754bbb7d2SKinglong Mee write->wr_how_written); 10185c4583b2SJeff Layton nfsd_file_put(nf); 10191da177e4SLinus Torvalds 102031dec253SDavid Shaw write->wr_bytes_written = cnt; 1021d890be15SChuck Lever trace_nfsd_write_done(rqstp, &cstate->current_fh, 1022d890be15SChuck Lever write->wr_offset, cnt); 10231da177e4SLinus Torvalds return status; 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds 102624bab491SAnna Schumaker static __be32 102729ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 10285c4583b2SJeff Layton stateid_t *src_stateid, struct nfsd_file **src, 10295c4583b2SJeff Layton stateid_t *dst_stateid, struct nfsd_file **dst) 1030ffa0160aSChristoph Hellwig { 1031ffa0160aSChristoph Hellwig __be32 status; 1032ffa0160aSChristoph Hellwig 103301310bb7SScott Mayhew if (!cstate->save_fh.fh_dentry) 103401310bb7SScott Mayhew return nfserr_nofilehandle; 103501310bb7SScott Mayhew 1036ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 10375c4583b2SJeff Layton src_stateid, RD_STATE, src); 1038ffa0160aSChristoph Hellwig if (status) { 1039ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1040ffa0160aSChristoph Hellwig goto out; 1041ffa0160aSChristoph Hellwig } 1042ffa0160aSChristoph Hellwig 1043ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 10445c4583b2SJeff Layton dst_stateid, WR_STATE, dst); 1045ffa0160aSChristoph Hellwig if (status) { 1046ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1047ffa0160aSChristoph Hellwig goto out_put_src; 1048ffa0160aSChristoph Hellwig } 1049ffa0160aSChristoph Hellwig 1050ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 10515c4583b2SJeff Layton if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) || 10525c4583b2SJeff Layton !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) { 1053ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1054ffa0160aSChristoph Hellwig goto out_put_dst; 1055ffa0160aSChristoph Hellwig } 1056ffa0160aSChristoph Hellwig 105729ae7f9dSAnna Schumaker out: 105829ae7f9dSAnna Schumaker return status; 105929ae7f9dSAnna Schumaker out_put_dst: 10605c4583b2SJeff Layton nfsd_file_put(*dst); 106129ae7f9dSAnna Schumaker out_put_src: 10625c4583b2SJeff Layton nfsd_file_put(*src); 106329ae7f9dSAnna Schumaker goto out; 106429ae7f9dSAnna Schumaker } 106529ae7f9dSAnna Schumaker 106629ae7f9dSAnna Schumaker static __be32 106729ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1068eb69853dSChristoph Hellwig union nfsd4_op_u *u) 106929ae7f9dSAnna Schumaker { 1070eb69853dSChristoph Hellwig struct nfsd4_clone *clone = &u->clone; 10715c4583b2SJeff Layton struct nfsd_file *src, *dst; 107229ae7f9dSAnna Schumaker __be32 status; 107329ae7f9dSAnna Schumaker 107429ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 107529ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 107629ae7f9dSAnna Schumaker if (status) 107729ae7f9dSAnna Schumaker goto out; 107829ae7f9dSAnna Schumaker 10795c4583b2SJeff Layton status = nfsd4_clone_file_range(src->nf_file, clone->cl_src_pos, 1080a25e3726STrond Myklebust dst->nf_file, clone->cl_dst_pos, clone->cl_count, 1081a25e3726STrond Myklebust EX_ISSYNC(cstate->current_fh.fh_export)); 1082ffa0160aSChristoph Hellwig 10835c4583b2SJeff Layton nfsd_file_put(dst); 10845c4583b2SJeff Layton nfsd_file_put(src); 1085ffa0160aSChristoph Hellwig out: 1086ffa0160aSChristoph Hellwig return status; 1087ffa0160aSChristoph Hellwig } 1088ffa0160aSChristoph Hellwig 1089e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy) 1090e0639dc5SOlga Kornievskaia { 1091e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1092e0639dc5SOlga Kornievskaia return; 1093e0639dc5SOlga Kornievskaia kfree(copy); 1094e0639dc5SOlga Kornievskaia } 1095e0639dc5SOlga Kornievskaia 1096e0639dc5SOlga Kornievskaia static bool 1097e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy) 1098e0639dc5SOlga Kornievskaia { 1099e0639dc5SOlga Kornievskaia bool value; 1100e0639dc5SOlga Kornievskaia 1101e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1102e0639dc5SOlga Kornievskaia value = copy->stopped; 1103e0639dc5SOlga Kornievskaia if (!copy->stopped) 1104e0639dc5SOlga Kornievskaia copy->stopped = true; 1105e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1106e0639dc5SOlga Kornievskaia return value; 1107e0639dc5SOlga Kornievskaia } 1108e0639dc5SOlga Kornievskaia 1109e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1110e0639dc5SOlga Kornievskaia { 1111e0639dc5SOlga Kornievskaia /* only 1 thread should stop the copy */ 1112e0639dc5SOlga Kornievskaia if (!check_and_set_stop_copy(copy)) 1113e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1114e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1115e0639dc5SOlga Kornievskaia } 1116e0639dc5SOlga Kornievskaia 1117e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1118e0639dc5SOlga Kornievskaia { 1119e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1120e0639dc5SOlga Kornievskaia 1121e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1122e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1123e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1124e0639dc5SOlga Kornievskaia copies); 1125e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1126e0639dc5SOlga Kornievskaia } 1127e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1128e0639dc5SOlga Kornievskaia return copy; 1129e0639dc5SOlga Kornievskaia } 1130e0639dc5SOlga Kornievskaia 1131e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1132e0639dc5SOlga Kornievskaia { 1133e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1134e0639dc5SOlga Kornievskaia 1135e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1136e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1137e0639dc5SOlga Kornievskaia } 1138e0639dc5SOlga Kornievskaia 1139e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1140e0639dc5SOlga Kornievskaia { 1141e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); 1142e0639dc5SOlga Kornievskaia 1143e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1144e0639dc5SOlga Kornievskaia } 1145e0639dc5SOlga Kornievskaia 1146e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1147e0639dc5SOlga Kornievskaia struct rpc_task *task) 1148e0639dc5SOlga Kornievskaia { 1149e0639dc5SOlga Kornievskaia return 1; 1150e0639dc5SOlga Kornievskaia } 1151e0639dc5SOlga Kornievskaia 1152e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1153e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1154e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1155e0639dc5SOlga Kornievskaia }; 1156e0639dc5SOlga Kornievskaia 1157e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1158e0639dc5SOlga Kornievskaia { 1159e0639dc5SOlga Kornievskaia copy->cp_res.wr_stable_how = NFS_UNSTABLE; 1160e0639dc5SOlga Kornievskaia copy->cp_synchronous = sync; 1161e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1162e0639dc5SOlga Kornievskaia } 1163e0639dc5SOlga Kornievskaia 1164e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) 1165e0639dc5SOlga Kornievskaia { 1166e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1167e0639dc5SOlga Kornievskaia size_t bytes_total = copy->cp_count; 1168e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1169e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1170e0639dc5SOlga Kornievskaia 1171e0639dc5SOlga Kornievskaia do { 1172e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1173e0639dc5SOlga Kornievskaia break; 11745c4583b2SJeff Layton bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file, 11755c4583b2SJeff Layton src_pos, copy->nf_dst->nf_file, dst_pos, 11765c4583b2SJeff Layton bytes_total); 1177e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1178e0639dc5SOlga Kornievskaia break; 1179e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1180e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1181e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1182e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1183e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1184e0639dc5SOlga Kornievskaia return bytes_copied; 1185e0639dc5SOlga Kornievskaia } 1186e0639dc5SOlga Kornievskaia 1187e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1188e0639dc5SOlga Kornievskaia { 1189e0639dc5SOlga Kornievskaia __be32 status; 1190e0639dc5SOlga Kornievskaia ssize_t bytes; 1191e0639dc5SOlga Kornievskaia 1192e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1193e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1194e0639dc5SOlga Kornievskaia * to get the error 1195e0639dc5SOlga Kornievskaia */ 1196e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1197e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1198e0639dc5SOlga Kornievskaia else { 1199e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1200e0639dc5SOlga Kornievskaia status = nfs_ok; 1201e0639dc5SOlga Kornievskaia } 1202e0639dc5SOlga Kornievskaia 12035c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 12045c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 1205e0639dc5SOlga Kornievskaia return status; 1206e0639dc5SOlga Kornievskaia } 1207e0639dc5SOlga Kornievskaia 1208e0639dc5SOlga Kornievskaia static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1209e0639dc5SOlga Kornievskaia { 1210e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1211e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1212e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1213e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1214e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1215e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1216e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 12175c4583b2SJeff Layton dst->nf_dst = nfsd_file_get(src->nf_dst); 12185c4583b2SJeff Layton dst->nf_src = nfsd_file_get(src->nf_src); 1219e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1220e0639dc5SOlga Kornievskaia } 1221e0639dc5SOlga Kornievskaia 1222e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1223e0639dc5SOlga Kornievskaia { 1224e0639dc5SOlga Kornievskaia nfs4_free_cp_state(copy); 12255c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 12265c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 1227e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1228e0639dc5SOlga Kornievskaia list_del(©->copies); 1229e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1230e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1231e0639dc5SOlga Kornievskaia } 1232e0639dc5SOlga Kornievskaia 1233e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1234e0639dc5SOlga Kornievskaia { 1235e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1236e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1237e0639dc5SOlga Kornievskaia 1238e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1239e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1240e0639dc5SOlga Kornievskaia if (!cb_copy) 1241e0639dc5SOlga Kornievskaia goto out; 1242e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1243e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1244e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1245e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1246e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1247e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 1248e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1249e0639dc5SOlga Kornievskaia out: 1250e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1251e0639dc5SOlga Kornievskaia return 0; 1252e0639dc5SOlga Kornievskaia } 1253e0639dc5SOlga Kornievskaia 1254ffa0160aSChristoph Hellwig static __be32 125529ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1256eb69853dSChristoph Hellwig union nfsd4_op_u *u) 125729ae7f9dSAnna Schumaker { 1258eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 125929ae7f9dSAnna Schumaker __be32 status; 1260e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 126129ae7f9dSAnna Schumaker 1262e0639dc5SOlga Kornievskaia status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 12635c4583b2SJeff Layton ©->nf_src, ©->cp_dst_stateid, 12645c4583b2SJeff Layton ©->nf_dst); 126529ae7f9dSAnna Schumaker if (status) 126629ae7f9dSAnna Schumaker goto out; 126729ae7f9dSAnna Schumaker 1268e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1269e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1270e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1271e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1272e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 127329ae7f9dSAnna Schumaker 1274e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1275e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1276e0639dc5SOlga Kornievskaia if (!async_copy) 1277e0639dc5SOlga Kornievskaia goto out; 1278e0639dc5SOlga Kornievskaia if (!nfs4_init_cp_state(nn, copy)) { 1279e0639dc5SOlga Kornievskaia kfree(async_copy); 1280e0639dc5SOlga Kornievskaia goto out; 128129ae7f9dSAnna Schumaker } 1282e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1283e0639dc5SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid, 1284e0639dc5SOlga Kornievskaia sizeof(copy->cp_stateid)); 1285e0639dc5SOlga Kornievskaia dup_copy_fields(copy, async_copy); 1286e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1287e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1288e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1289e0639dc5SOlga Kornievskaia goto out_err; 1290e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1291e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1292e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1293e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1294e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1295e0639dc5SOlga Kornievskaia status = nfs_ok; 1296e0639dc5SOlga Kornievskaia } else 1297e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 129829ae7f9dSAnna Schumaker out: 129929ae7f9dSAnna Schumaker return status; 1300e0639dc5SOlga Kornievskaia out_err: 1301*18f428d4SOlga Kornievskaia if (async_copy) 1302e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1303e0639dc5SOlga Kornievskaia goto out; 1304e0639dc5SOlga Kornievskaia } 1305e0639dc5SOlga Kornievskaia 1306e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1307e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1308e0639dc5SOlga Kornievskaia { 1309e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1310e0639dc5SOlga Kornievskaia 1311e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1312e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1313e0639dc5SOlga Kornievskaia if (memcmp(©->cp_stateid, stateid, NFS4_STATEID_SIZE)) 1314e0639dc5SOlga Kornievskaia continue; 1315e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1316e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1317e0639dc5SOlga Kornievskaia return copy; 1318e0639dc5SOlga Kornievskaia } 1319e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1320e0639dc5SOlga Kornievskaia return NULL; 132129ae7f9dSAnna Schumaker } 132229ae7f9dSAnna Schumaker 132329ae7f9dSAnna Schumaker static __be32 1324885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1325885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1326885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1327885e2bf3SOlga Kornievskaia { 1328e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1329e0639dc5SOlga Kornievskaia __be32 status = 0; 1330e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1331e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1332e0639dc5SOlga Kornievskaia 1333e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1334e0639dc5SOlga Kornievskaia if (copy) 1335e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1336e0639dc5SOlga Kornievskaia else 1337e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1338e0639dc5SOlga Kornievskaia 1339e0639dc5SOlga Kornievskaia return status; 1340885e2bf3SOlga Kornievskaia } 1341885e2bf3SOlga Kornievskaia 1342885e2bf3SOlga Kornievskaia static __be32 134395d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 134495d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 134595d871f0SAnna Schumaker { 13460d4d6720SJ. Bruce Fields __be32 status; 13475c4583b2SJeff Layton struct nfsd_file *nf; 134895d871f0SAnna Schumaker 1349aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 135095d871f0SAnna Schumaker &fallocate->falloc_stateid, 13515c4583b2SJeff Layton WR_STATE, &nf); 135295d871f0SAnna Schumaker if (status != nfs_ok) { 135395d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 135495d871f0SAnna Schumaker return status; 135595d871f0SAnna Schumaker } 135695d871f0SAnna Schumaker 13575c4583b2SJeff Layton status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, 135895d871f0SAnna Schumaker fallocate->falloc_offset, 135995d871f0SAnna Schumaker fallocate->falloc_length, 136095d871f0SAnna Schumaker flags); 13615c4583b2SJeff Layton nfsd_file_put(nf); 136295d871f0SAnna Schumaker return status; 136395d871f0SAnna Schumaker } 13646308bc98SOlga Kornievskaia static __be32 13656308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 13666308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 13676308bc98SOlga Kornievskaia union nfsd4_op_u *u) 13686308bc98SOlga Kornievskaia { 1369e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1370e0639dc5SOlga Kornievskaia __be32 status = 0; 1371e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1372e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1373e0639dc5SOlga Kornievskaia 1374e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1375e0639dc5SOlga Kornievskaia if (copy) { 1376e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 1377e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1378e0639dc5SOlga Kornievskaia } else 1379e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1380e0639dc5SOlga Kornievskaia 1381e0639dc5SOlga Kornievskaia return status; 13826308bc98SOlga Kornievskaia } 138395d871f0SAnna Schumaker 138495d871f0SAnna Schumaker static __be32 138595d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1386eb69853dSChristoph Hellwig union nfsd4_op_u *u) 138795d871f0SAnna Schumaker { 1388eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 138995d871f0SAnna Schumaker } 139095d871f0SAnna Schumaker 139195d871f0SAnna Schumaker static __be32 1392b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1393eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1394b0cb9085SAnna Schumaker { 1395eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 1396b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1397b0cb9085SAnna Schumaker } 1398b0cb9085SAnna Schumaker 1399b0cb9085SAnna Schumaker static __be32 140024bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1401eb69853dSChristoph Hellwig union nfsd4_op_u *u) 140224bab491SAnna Schumaker { 1403eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 140424bab491SAnna Schumaker int whence; 140524bab491SAnna Schumaker __be32 status; 14065c4583b2SJeff Layton struct nfsd_file *nf; 140724bab491SAnna Schumaker 1408aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 140924bab491SAnna Schumaker &seek->seek_stateid, 14105c4583b2SJeff Layton RD_STATE, &nf); 141124bab491SAnna Schumaker if (status) { 141224bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 141324bab491SAnna Schumaker return status; 141424bab491SAnna Schumaker } 141524bab491SAnna Schumaker 141624bab491SAnna Schumaker switch (seek->seek_whence) { 141724bab491SAnna Schumaker case NFS4_CONTENT_DATA: 141824bab491SAnna Schumaker whence = SEEK_DATA; 141924bab491SAnna Schumaker break; 142024bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 142124bab491SAnna Schumaker whence = SEEK_HOLE; 142224bab491SAnna Schumaker break; 142324bab491SAnna Schumaker default: 142424bab491SAnna Schumaker status = nfserr_union_notsupp; 142524bab491SAnna Schumaker goto out; 142624bab491SAnna Schumaker } 142724bab491SAnna Schumaker 142824bab491SAnna Schumaker /* 142924bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 143024bab491SAnna Schumaker * should ever file->f_pos. 143124bab491SAnna Schumaker */ 14325c4583b2SJeff Layton seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); 143324bab491SAnna Schumaker if (seek->seek_pos < 0) 143424bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 14355c4583b2SJeff Layton else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) 143624bab491SAnna Schumaker seek->seek_eof = true; 143724bab491SAnna Schumaker 143824bab491SAnna Schumaker out: 14395c4583b2SJeff Layton nfsd_file_put(nf); 144024bab491SAnna Schumaker return status; 144124bab491SAnna Schumaker } 144224bab491SAnna Schumaker 14431da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 14441da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 14451da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 14461da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 14471da177e4SLinus Torvalds */ 1448b37ad28bSAl Viro static __be32 1449c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1450ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 14511da177e4SLinus Torvalds { 14522ebbc012SAl Viro __be32 *buf, *p; 14531da177e4SLinus Torvalds int count; 1454b37ad28bSAl Viro __be32 status; 14551da177e4SLinus Torvalds 14568837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 14571da177e4SLinus Torvalds if (status) 14581da177e4SLinus Torvalds return status; 14591da177e4SLinus Torvalds 14603c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 14613c8e0316SYu Zhiguo if (status) 14623c8e0316SYu Zhiguo return status; 14633c8e0316SYu Zhiguo 14641da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 14651da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 14661da177e4SLinus Torvalds return nfserr_inval; 14671da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 14681da177e4SLinus Torvalds return nfserr_inval; 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds /* count in words: 14711da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 14721da177e4SLinus Torvalds */ 14731da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 14741da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 14751da177e4SLinus Torvalds if (!buf) 14763e772463SJ. Bruce Fields return nfserr_jukebox; 14771da177e4SLinus Torvalds 147884822d0bSJ. Bruce Fields p = buf; 1479d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1480ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1481d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1482d5184658SJ. Bruce Fields verify->ve_bmval, 1483406a7ea9SFrank Filz rqstp, 0); 148441ae6e71SJ. Bruce Fields /* 148541ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 148641ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 148741ae6e71SJ. Bruce Fields */ 148884822d0bSJ. Bruce Fields if (status == nfserr_resource) 14891da177e4SLinus Torvalds status = nfserr_not_same; 14901da177e4SLinus Torvalds if (status) 14911da177e4SLinus Torvalds goto out_kfree; 14921da177e4SLinus Torvalds 149395ec28cdSBenny Halevy /* skip bitmap */ 149495ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 14951da177e4SLinus Torvalds status = nfserr_not_same; 14961da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 14971da177e4SLinus Torvalds goto out_kfree; 14981da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 14991da177e4SLinus Torvalds status = nfserr_same; 15001da177e4SLinus Torvalds 15011da177e4SLinus Torvalds out_kfree: 15021da177e4SLinus Torvalds kfree(buf); 15031da177e4SLinus Torvalds return status; 15041da177e4SLinus Torvalds } 15051da177e4SLinus Torvalds 1506c954e2a5SJ.Bruce Fields static __be32 1507c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1508eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1509c954e2a5SJ.Bruce Fields { 1510c954e2a5SJ.Bruce Fields __be32 status; 1511c954e2a5SJ.Bruce Fields 1512eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 1513c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1514c954e2a5SJ.Bruce Fields } 1515c954e2a5SJ.Bruce Fields 1516c954e2a5SJ.Bruce Fields static __be32 1517c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1518eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1519c954e2a5SJ.Bruce Fields { 1520c954e2a5SJ.Bruce Fields __be32 status; 1521c954e2a5SJ.Bruce Fields 1522eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 1523c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1524c954e2a5SJ.Bruce Fields } 1525c954e2a5SJ.Bruce Fields 15269cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 15279cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 15289cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 15299cf514ccSChristoph Hellwig { 15308a4c3926SJeff Layton if (!exp->ex_layout_types) { 15319cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 15329cf514ccSChristoph Hellwig return NULL; 15339cf514ccSChristoph Hellwig } 15349cf514ccSChristoph Hellwig 1535b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1536b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 15379cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 15389cf514ccSChristoph Hellwig __func__, layout_type); 15399cf514ccSChristoph Hellwig return NULL; 15409cf514ccSChristoph Hellwig } 15419cf514ccSChristoph Hellwig 15429cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 15439cf514ccSChristoph Hellwig } 15449cf514ccSChristoph Hellwig 15459cf514ccSChristoph Hellwig static __be32 15469cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 1547eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 15489cf514ccSChristoph Hellwig { 1549eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 15509cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 15519cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 15529cf514ccSChristoph Hellwig struct svc_export *exp; 15539cf514ccSChristoph Hellwig __be32 nfserr; 15549cf514ccSChristoph Hellwig 15559cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 15569cf514ccSChristoph Hellwig __func__, 15579cf514ccSChristoph Hellwig gdp->gd_layout_type, 15589cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 15599cf514ccSChristoph Hellwig gdp->gd_maxcount); 15609cf514ccSChristoph Hellwig 15619cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 15629cf514ccSChristoph Hellwig if (!map) { 15639cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 15649cf514ccSChristoph Hellwig __func__); 15659cf514ccSChristoph Hellwig return nfserr_noent; 15669cf514ccSChristoph Hellwig } 15679cf514ccSChristoph Hellwig 15689cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 15699cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 15709cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 15719cf514ccSChristoph Hellwig return nfserr_noent; 15729cf514ccSChristoph Hellwig } 15739cf514ccSChristoph Hellwig 15749cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 15759cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 15769cf514ccSChristoph Hellwig if (!ops) 15779cf514ccSChristoph Hellwig goto out; 15789cf514ccSChristoph Hellwig 15799cf514ccSChristoph Hellwig nfserr = nfs_ok; 1580f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 1581f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 1582d7c920d1STom Haynes rqstp, cstate->session->se_client, gdp); 1583f99d4fbdSChristoph Hellwig } 15849cf514ccSChristoph Hellwig 15859cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 15869cf514ccSChristoph Hellwig out: 1587a1420384SKinglong Mee exp_put(exp); 15889cf514ccSChristoph Hellwig return nfserr; 15899cf514ccSChristoph Hellwig } 15909cf514ccSChristoph Hellwig 159134b1744cSJ. Bruce Fields static void 159234b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 159334b1744cSJ. Bruce Fields { 159434b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 159534b1744cSJ. Bruce Fields } 159634b1744cSJ. Bruce Fields 15979cf514ccSChristoph Hellwig static __be32 15989cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 1599eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 16009cf514ccSChristoph Hellwig { 1601eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 16029cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 16039cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 16049cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 16059cf514ccSChristoph Hellwig __be32 nfserr; 160666282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 16079cf514ccSChristoph Hellwig 16089cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 16099cf514ccSChristoph Hellwig case IOMODE_READ: 161066282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 16119cf514ccSChristoph Hellwig break; 16129cf514ccSChristoph Hellwig case IOMODE_RW: 161366282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 16149cf514ccSChristoph Hellwig break; 16159cf514ccSChristoph Hellwig default: 16169cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 16179cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 16189cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 16199cf514ccSChristoph Hellwig goto out; 16209cf514ccSChristoph Hellwig } 16219cf514ccSChristoph Hellwig 16229cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 16239cf514ccSChristoph Hellwig if (nfserr) 16249cf514ccSChristoph Hellwig goto out; 16259cf514ccSChristoph Hellwig 16269cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 16279cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 16289cf514ccSChristoph Hellwig if (!ops) 16299cf514ccSChristoph Hellwig goto out; 16309cf514ccSChristoph Hellwig 16319cf514ccSChristoph Hellwig /* 16329cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 16339cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 16349cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 16359cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 16369cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 16379cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 16389cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 16399cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 16409cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 16419cf514ccSChristoph Hellwig */ 16429cf514ccSChristoph Hellwig nfserr = nfserr_inval; 16439cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 16449cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 16459cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 16469cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 16479cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 16489cf514ccSChristoph Hellwig goto out; 16499cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 16509cf514ccSChristoph Hellwig goto out; 16519cf514ccSChristoph Hellwig 16529cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 16539cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 165431ef83dcSChristoph Hellwig if (nfserr) { 1655f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 16569cf514ccSChristoph Hellwig goto out; 165731ef83dcSChristoph Hellwig } 16589cf514ccSChristoph Hellwig 1659c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1660c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1661c5c707f9SChristoph Hellwig goto out_put_stid; 1662c5c707f9SChristoph Hellwig 16632b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 16649cf514ccSChristoph Hellwig current_fh, lgp); 16659cf514ccSChristoph Hellwig if (nfserr) 16669cf514ccSChristoph Hellwig goto out_put_stid; 16679cf514ccSChristoph Hellwig 16689cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 16699cf514ccSChristoph Hellwig 16709cf514ccSChristoph Hellwig out_put_stid: 1671cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 16729cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 16739cf514ccSChristoph Hellwig out: 16749cf514ccSChristoph Hellwig return nfserr; 16759cf514ccSChristoph Hellwig } 16769cf514ccSChristoph Hellwig 167734b1744cSJ. Bruce Fields static void 167834b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 167934b1744cSJ. Bruce Fields { 168034b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 168134b1744cSJ. Bruce Fields } 168234b1744cSJ. Bruce Fields 16839cf514ccSChristoph Hellwig static __be32 16849cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 1685eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 16869cf514ccSChristoph Hellwig { 1687eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 16889cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 16899cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 16909cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 16919cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 16929cf514ccSChristoph Hellwig struct inode *inode; 16939cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 16949cf514ccSChristoph Hellwig __be32 nfserr; 16959cf514ccSChristoph Hellwig 16969cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 16979cf514ccSChristoph Hellwig if (nfserr) 16989cf514ccSChristoph Hellwig goto out; 16999cf514ccSChristoph Hellwig 17009cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 17019cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 17029cf514ccSChristoph Hellwig if (!ops) 17039cf514ccSChristoph Hellwig goto out; 17042b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 17059cf514ccSChristoph Hellwig 17069cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17079cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 17089cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 17099cf514ccSChristoph Hellwig goto out; 17109cf514ccSChristoph Hellwig } 17119cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 17129cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 17139cf514ccSChristoph Hellwig goto out; 17149cf514ccSChristoph Hellwig } 17159cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 17169cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 17179cf514ccSChristoph Hellwig goto out; 17189cf514ccSChristoph Hellwig } 17199cf514ccSChristoph Hellwig 17209cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 17219cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 17229cf514ccSChristoph Hellwig &ls); 17239cf514ccSChristoph Hellwig if (nfserr) { 1724f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 17259cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 17269cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 17279cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 17289cf514ccSChristoph Hellwig goto out; 17299cf514ccSChristoph Hellwig } 17309cf514ccSChristoph Hellwig 1731cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 1732cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 1733cc8a5532SJeff Layton 17349cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 17359cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 17369cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 17379cf514ccSChristoph Hellwig } else { 17389cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 17399cf514ccSChristoph Hellwig } 17409cf514ccSChristoph Hellwig 1741d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 17429cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 17439cf514ccSChristoph Hellwig out: 17449cf514ccSChristoph Hellwig return nfserr; 17459cf514ccSChristoph Hellwig } 17469cf514ccSChristoph Hellwig 17479cf514ccSChristoph Hellwig static __be32 17489cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 1749eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 17509cf514ccSChristoph Hellwig { 1751eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 17529cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 17539cf514ccSChristoph Hellwig __be32 nfserr; 17549cf514ccSChristoph Hellwig 17559cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 17569cf514ccSChristoph Hellwig if (nfserr) 17579cf514ccSChristoph Hellwig goto out; 17589cf514ccSChristoph Hellwig 17599cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 17609cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 17619cf514ccSChristoph Hellwig goto out; 17629cf514ccSChristoph Hellwig 17639cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 17649cf514ccSChristoph Hellwig case IOMODE_READ: 17659cf514ccSChristoph Hellwig case IOMODE_RW: 17669cf514ccSChristoph Hellwig case IOMODE_ANY: 17679cf514ccSChristoph Hellwig break; 17689cf514ccSChristoph Hellwig default: 17699cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 17709cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 17719cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17729cf514ccSChristoph Hellwig goto out; 17739cf514ccSChristoph Hellwig } 17749cf514ccSChristoph Hellwig 17759cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 17769cf514ccSChristoph Hellwig case RETURN_FILE: 17779cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 17789cf514ccSChristoph Hellwig break; 17799cf514ccSChristoph Hellwig case RETURN_FSID: 17809cf514ccSChristoph Hellwig case RETURN_ALL: 17819cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 17829cf514ccSChristoph Hellwig break; 17839cf514ccSChristoph Hellwig default: 17849cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 17859cf514ccSChristoph Hellwig lrp->lr_return_type); 17869cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17879cf514ccSChristoph Hellwig break; 17889cf514ccSChristoph Hellwig } 17899cf514ccSChristoph Hellwig out: 17909cf514ccSChristoph Hellwig return nfserr; 17919cf514ccSChristoph Hellwig } 17929cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 17939cf514ccSChristoph Hellwig 17941da177e4SLinus Torvalds /* 17951da177e4SLinus Torvalds * NULL call. 17961da177e4SLinus Torvalds */ 17977111c66eSAl Viro static __be32 1798a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 17991da177e4SLinus Torvalds { 18001da177e4SLinus Torvalds return nfs_ok; 18011da177e4SLinus Torvalds } 18021da177e4SLinus Torvalds 1803e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1804e2b20950SShankar Anand { 1805e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1806e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1807e2b20950SShankar Anand } 1808e2b20950SShankar Anand 1809bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 1810b591480bSJ.Bruce Fields 1811f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1812b001a1b6SBenny Halevy 18131da177e4SLinus Torvalds /* 181457716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1815f9bb94c4SAndy Adamson * 181657716355SJ. Bruce Fields * Also note, enforced elsewhere: 181757716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 181857716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 18191d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 18201d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 182157716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 182257716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 182357716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1824f9bb94c4SAndy Adamson */ 182557716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1826f9bb94c4SAndy Adamson { 18277a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 182857716355SJ. Bruce Fields 182957716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 183057716355SJ. Bruce Fields if (args->minorversion == 0) 183157716355SJ. Bruce Fields return nfs_ok; 183257716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 183357716355SJ. Bruce Fields if (args->opcnt == 0) 183457716355SJ. Bruce Fields return nfs_ok; 18357a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 183657716355SJ. Bruce Fields return nfs_ok; 18377a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 183857716355SJ. Bruce Fields return nfserr_op_not_in_session; 18397a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 184057716355SJ. Bruce Fields return nfs_ok; 18417a04cfdaSJ. Bruce Fields /* 18427a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 18437a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 18447a04cfdaSJ. Bruce Fields * compound: 18457a04cfdaSJ. Bruce Fields */ 184657716355SJ. Bruce Fields if (args->opcnt != 1) 184757716355SJ. Bruce Fields return nfserr_not_only_op; 184857716355SJ. Bruce Fields return nfs_ok; 1849f9bb94c4SAndy Adamson } 1850f9bb94c4SAndy Adamson 1851f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 185222b03214SJ. Bruce Fields { 185322b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 185422b03214SJ. Bruce Fields } 185522b03214SJ. Bruce Fields 18561091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 18571091006cSJ. Bruce Fields { 1858e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 1859e372ba60SJ. Bruce Fields return false; 1860c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 18611091006cSJ. Bruce Fields } 18621091006cSJ. Bruce Fields 186368d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 186468d93184SJ. Bruce Fields { 186568d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 186668d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 186768d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 186868d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 1869bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 1870bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 187168d93184SJ. Bruce Fields 187268d93184SJ. Bruce Fields /* 187368d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 187468d93184SJ. Bruce Fields * have special rules. 187568d93184SJ. Bruce Fields */ 187668d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 187768d93184SJ. Bruce Fields return false; 187868d93184SJ. Bruce Fields /* 187968d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 188068d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 188168d93184SJ. Bruce Fields * result: 188268d93184SJ. Bruce Fields */ 188368d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 188468d93184SJ. Bruce Fields return false; 188551904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 188651904b08SJ. Bruce Fields return false; 188768d93184SJ. Bruce Fields nextd = OPDESC(next); 188868d93184SJ. Bruce Fields /* 188968d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 189068d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 189168d93184SJ. Bruce Fields * now: 189268d93184SJ. Bruce Fields */ 189368d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 189468d93184SJ. Bruce Fields } 189568d93184SJ. Bruce Fields 18962d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 18972d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 18982d124dfaSJ. Bruce Fields { 18992d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 19002d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 19012d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 19022d124dfaSJ. Bruce Fields 19032d124dfaSJ. Bruce Fields xdr->buf = buf; 1904ddd1ea56SJ. Bruce Fields xdr->iov = head; 19052d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 1906a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 19076ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 19086ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 19092825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 191005638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 19112825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 1912a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 19132d124dfaSJ. Bruce Fields } 19142d124dfaSJ. Bruce Fields 1915f9bb94c4SAndy Adamson /* 19161da177e4SLinus Torvalds * COMPOUND call. 19171da177e4SLinus Torvalds */ 19187111c66eSAl Viro static __be32 1919a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 19201da177e4SLinus Torvalds { 1921a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 1922a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 19231da177e4SLinus Torvalds struct nfsd4_op *op; 1924e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 19254daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 19264daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1927e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1928b37ad28bSAl Viro __be32 status; 19291da177e4SLinus Torvalds 19302d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 19314aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 19321da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 1933d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 19341da177e4SLinus Torvalds resp->taglen = args->taglen; 19351da177e4SLinus Torvalds resp->tag = args->tag; 19361da177e4SLinus Torvalds resp->rqstp = rqstp; 19374daeed25SKinglong Mee cstate->minorversion = args->minorversion; 19384daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 19394daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 19408ff30fa4SNeilBrown /* 19418ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 19428ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 19438ff30fa4SNeilBrown */ 194430660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 19451da177e4SLinus Torvalds 19461da177e4SLinus Torvalds /* 19471da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 19481da177e4SLinus Torvalds */ 19491da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 1950e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 19511da177e4SLinus Torvalds goto out; 19520078117cSJ. Bruce Fields status = nfserr_resource; 19530078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 19540078117cSJ. Bruce Fields goto out; 19551da177e4SLinus Torvalds 195657716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 195757716355SJ. Bruce Fields if (status) { 1958f9bb94c4SAndy Adamson op = &args->ops[0]; 195957716355SJ. Bruce Fields op->status = status; 19605b7b15aeSJ. Bruce Fields resp->opcnt = 1; 1961f9bb94c4SAndy Adamson goto encode_op; 1962f9bb94c4SAndy Adamson } 1963f9bb94c4SAndy Adamson 1964fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 19651da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 19661da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 19671da177e4SLinus Torvalds 19681da177e4SLinus Torvalds /* 19691da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 19701da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 19711da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 19721da177e4SLinus Torvalds */ 19739d313b17SJ. Bruce Fields if (op->status) { 19749d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 19759d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 19761da177e4SLinus Torvalds goto encode_op; 19779d313b17SJ. Bruce Fields } 19781da177e4SLinus Torvalds 19794daeed25SKinglong Mee if (!current_fh->fh_dentry) { 1980f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 19811da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 19821da177e4SLinus Torvalds goto encode_op; 19831da177e4SLinus Torvalds } 19844daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1985f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 198642ca0993SJ.Bruce Fields op->status = nfserr_moved; 198742ca0993SJ.Bruce Fields goto encode_op; 198842ca0993SJ.Bruce Fields } 1989b591480bSJ.Bruce Fields 19902336745eSKinglong Mee fh_clear_wcc(current_fh); 19912336745eSKinglong Mee 199258e7b33aSMi Jinlong /* If op is non-idempotent */ 1993f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 19944c69d585SJ. Bruce Fields /* 1995a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 1996a8095f7eSJ. Bruce Fields * succesful reply: 1997a8095f7eSJ. Bruce Fields */ 1998f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 1999a8095f7eSJ. Bruce Fields /* 2000a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 20014c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 20024c69d585SJ. Bruce Fields */ 20034c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 20044c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 200558e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 200658e7b33aSMi Jinlong } 200758e7b33aSMi Jinlong 200858e7b33aSMi Jinlong if (op->status) 200958e7b33aSMi Jinlong goto encode_op; 201058e7b33aSMi Jinlong 2011f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2012f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2013f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 20141da177e4SLinus Torvalds 20159a307403SJ. Bruce Fields /* Only from SEQUENCE */ 20169a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 20179a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 20189a307403SJ. Bruce Fields status = op->status; 20199a307403SJ. Bruce Fields goto out; 20209a307403SJ. Bruce Fields } 20218b70484cSTigran Mkrtchyan if (!op->status) { 2022f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2023f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 20248b70484cSTigran Mkrtchyan 2025f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 202637c593c5STigran Mkrtchyan clear_current_stateid(cstate); 20278b70484cSTigran Mkrtchyan 20288b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 20294daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 20308b70484cSTigran Mkrtchyan } 20311da177e4SLinus Torvalds encode_op: 2032a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2033a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2034d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 20351da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 20361da177e4SLinus Torvalds } else { 20371da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 20381da177e4SLinus Torvalds status = op->status; 20391da177e4SLinus Torvalds } 20400407717dSBenny Halevy 2041fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2042fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 20430407717dSBenny Halevy 204458fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2045e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 20461da177e4SLinus Torvalds } 20471da177e4SLinus Torvalds 20484daeed25SKinglong Mee cstate->status = status; 20494daeed25SKinglong Mee fh_put(current_fh); 20504daeed25SKinglong Mee fh_put(save_fh); 20514daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 20521da177e4SLinus Torvalds out: 20532f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 205430660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 20553b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 20561da177e4SLinus Torvalds return status; 20571da177e4SLinus Torvalds } 20581da177e4SLinus Torvalds 205958e7b33aSMi Jinlong #define op_encode_hdr_size (2) 206058e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 206158e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 206258e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 206358e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 206458e7b33aSMi Jinlong 20658c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 20668c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 206758e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 206858e7b33aSMi Jinlong 206958e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 207058e7b33aSMi Jinlong 207158e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 207258e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 207358e7b33aSMi Jinlong op_encode_ace_maxsz) 207458e7b33aSMi Jinlong 207558e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 207658e7b33aSMi Jinlong 207758e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 207858e7b33aSMi Jinlong { 207958e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 208058e7b33aSMi Jinlong } 208158e7b33aSMi Jinlong 208258e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 208358e7b33aSMi Jinlong { 208458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 208558e7b33aSMi Jinlong } 208658e7b33aSMi Jinlong 20872282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20882282cd2cSKinglong Mee { 20892282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 20902282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 20912282cd2cSKinglong Mee } 20922282cd2cSKinglong Mee 209358e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 209458e7b33aSMi Jinlong { 209558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 209658e7b33aSMi Jinlong } 209758e7b33aSMi Jinlong 209858e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 209958e7b33aSMi Jinlong { 210058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 210158e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 210258e7b33aSMi Jinlong } 210358e7b33aSMi Jinlong 2104b86cef60SJ. Bruce Fields /* 2105b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2106b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2107b86cef60SJ. Bruce Fields * reads unnecessarily. 2108b86cef60SJ. Bruce Fields */ 2109b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2110b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2111b86cef60SJ. Bruce Fields { 2112b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2113b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2114b86cef60SJ. Bruce Fields u32 ret = 0; 2115b86cef60SJ. Bruce Fields 2116b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2117b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2118b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2119b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2120b86cef60SJ. Bruce Fields 2121b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2122b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2123b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2124b86cef60SJ. Bruce Fields } 2125b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2126b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2127b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2128b86cef60SJ. Bruce Fields } 2129b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2130b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2131b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2132b86cef60SJ. Bruce Fields } 2133b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 21341ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2135b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2136b86cef60SJ. Bruce Fields } 2137b86cef60SJ. Bruce Fields /* 2138b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2139b86cef60SJ. Bruce Fields * supported_attributes) 2140b86cef60SJ. Bruce Fields */ 2141b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2142b86cef60SJ. Bruce Fields /* bitmask, length */ 2143b86cef60SJ. Bruce Fields ret += 20; 2144b86cef60SJ. Bruce Fields return ret; 2145b86cef60SJ. Bruce Fields } 2146b86cef60SJ. Bruce Fields 21472282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 21482282cd2cSKinglong Mee { 21492282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 21502282cd2cSKinglong Mee } 21512282cd2cSKinglong Mee 215258e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 215358e7b33aSMi Jinlong { 215458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 215558e7b33aSMi Jinlong * sizeof(__be32); 215658e7b33aSMi Jinlong } 215758e7b33aSMi Jinlong 215858e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 215958e7b33aSMi Jinlong { 216058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 216158e7b33aSMi Jinlong * sizeof(__be32); 216258e7b33aSMi Jinlong } 216358e7b33aSMi Jinlong 216458e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 216558e7b33aSMi Jinlong { 216658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 216758e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 216858e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 216958e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 217058e7b33aSMi Jinlong } 217158e7b33aSMi Jinlong 217258e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 217358e7b33aSMi Jinlong { 217458e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 217558e7b33aSMi Jinlong 217658e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 21773c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 217858e7b33aSMi Jinlong 2179622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 218058e7b33aSMi Jinlong } 218158e7b33aSMi Jinlong 218258e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 218358e7b33aSMi Jinlong { 21843c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 218558e7b33aSMi Jinlong 21863c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 21873c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 218858e7b33aSMi Jinlong 2189561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2190561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 219158e7b33aSMi Jinlong } 219258e7b33aSMi Jinlong 21932282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 21942282cd2cSKinglong Mee { 21952282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 21962282cd2cSKinglong Mee } 21972282cd2cSKinglong Mee 219858e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 219958e7b33aSMi Jinlong { 220058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 220158e7b33aSMi Jinlong * sizeof(__be32); 220258e7b33aSMi Jinlong } 220358e7b33aSMi Jinlong 220458e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 220558e7b33aSMi Jinlong { 220658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 220758e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 220858e7b33aSMi Jinlong } 220958e7b33aSMi Jinlong 2210ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2211ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2212ccae70a9SJ. Bruce Fields { 2213d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2214d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2215ccae70a9SJ. Bruce Fields } 2216ccae70a9SJ. Bruce Fields 22172282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22182282cd2cSKinglong Mee { 22192282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 22202282cd2cSKinglong Mee * sizeof(__be32); 22212282cd2cSKinglong Mee } 22222282cd2cSKinglong Mee 222358e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 222458e7b33aSMi Jinlong { 222558e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 222658e7b33aSMi Jinlong } 222758e7b33aSMi Jinlong 22282282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22292282cd2cSKinglong Mee { 22302282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 22312282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 22322282cd2cSKinglong Mee } 22332282cd2cSKinglong Mee 223458e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 223558e7b33aSMi Jinlong { 2236480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2237480efaeeSJ. Bruce Fields sizeof(__be32); 223858e7b33aSMi Jinlong } 223958e7b33aSMi Jinlong 224058e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 224158e7b33aSMi Jinlong { 2242f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 224358e7b33aSMi Jinlong } 224458e7b33aSMi Jinlong 224558e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 224658e7b33aSMi Jinlong { 224758e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2248a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2249a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 225058e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 225158e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 225258e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 225358e7b33aSMi Jinlong /* eir_server_scope<> */\ 225458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 225558e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 225658e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 225758e7b33aSMi Jinlong } 225858e7b33aSMi Jinlong 225958e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 226058e7b33aSMi Jinlong { 226158e7b33aSMi Jinlong return (op_encode_hdr_size + \ 226258e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 226358e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 226458e7b33aSMi Jinlong } 226558e7b33aSMi Jinlong 226658e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 226758e7b33aSMi Jinlong { 226858e7b33aSMi Jinlong return (op_encode_hdr_size + \ 226958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 227058e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 227158e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 227258e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 227358e7b33aSMi Jinlong } 227458e7b33aSMi Jinlong 227529ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 227629ae7f9dSAnna Schumaker { 227729ae7f9dSAnna Schumaker return (op_encode_hdr_size + 227829ae7f9dSAnna Schumaker 1 /* wr_callback */ + 227929ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 228029ae7f9dSAnna Schumaker 2 /* wr_count */ + 228129ae7f9dSAnna Schumaker 1 /* wr_committed */ + 228229ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 228329ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 228429ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 228529ae7f9dSAnna Schumaker } 228629ae7f9dSAnna Schumaker 22876308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 22886308bc98SOlga Kornievskaia struct nfsd4_op *op) 22896308bc98SOlga Kornievskaia { 22906308bc98SOlga Kornievskaia return (op_encode_hdr_size + 22916308bc98SOlga Kornievskaia 2 /* osr_count */ + 22926308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 22936308bc98SOlga Kornievskaia } 22946308bc98SOlga Kornievskaia 22959cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 22962282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22972282cd2cSKinglong Mee { 22982282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 22992282cd2cSKinglong Mee 23002282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 23012282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 23022282cd2cSKinglong Mee 23032282cd2cSKinglong Mee return (op_encode_hdr_size + 23042282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 23052282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 23062282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 23072282cd2cSKinglong Mee } 23082282cd2cSKinglong Mee 23099cf514ccSChristoph Hellwig /* 23109cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 23119cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 23129cf514ccSChristoph Hellwig */ 23139cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 23149cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23159cf514ccSChristoph Hellwig { 23169cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23179cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 23189cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 23199cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 23209cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 23219cf514ccSChristoph Hellwig } 23229cf514ccSChristoph Hellwig 23239cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23249cf514ccSChristoph Hellwig { 23259cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23269cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 23279cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 23289cf514ccSChristoph Hellwig } 23299cf514ccSChristoph Hellwig 23309cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23319cf514ccSChristoph Hellwig { 23329cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23339cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 23349cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 23359cf514ccSChristoph Hellwig } 23369cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 23379cf514ccSChristoph Hellwig 23382282cd2cSKinglong Mee 23392282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23402282cd2cSKinglong Mee { 23412282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 23422282cd2cSKinglong Mee } 23432282cd2cSKinglong Mee 2344bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2345b591480bSJ.Bruce Fields [OP_ACCESS] = { 2346eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2347b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 23481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2349b591480bSJ.Bruce Fields }, 2350b591480bSJ.Bruce Fields [OP_CLOSE] = { 2351eb69853dSChristoph Hellwig .op_func = nfsd4_close, 235258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2353b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 23541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 235557832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2356b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2357b591480bSJ.Bruce Fields }, 2358b591480bSJ.Bruce Fields [OP_COMMIT] = { 2359eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 236058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2361b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 23621c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2363b591480bSJ.Bruce Fields }, 2364b591480bSJ.Bruce Fields [OP_CREATE] = { 2365eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2366d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2367b001a1b6SBenny Halevy .op_name = "OP_CREATE", 23681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2369b591480bSJ.Bruce Fields }, 2370b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2371eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 237258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2373b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 237458e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 237557832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2376b591480bSJ.Bruce Fields }, 2377b591480bSJ.Bruce Fields [OP_GETATTR] = { 2378eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2379eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2380b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2381b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2382b591480bSJ.Bruce Fields }, 2383b591480bSJ.Bruce Fields [OP_GETFH] = { 2384eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2385b001a1b6SBenny Halevy .op_name = "OP_GETFH", 23861c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2387b591480bSJ.Bruce Fields }, 2388b591480bSJ.Bruce Fields [OP_LINK] = { 2389eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2390c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2391c856694eSJ. Bruce Fields | OP_CACHEME, 2392b001a1b6SBenny Halevy .op_name = "OP_LINK", 23931c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 2394b591480bSJ.Bruce Fields }, 2395b591480bSJ.Bruce Fields [OP_LOCK] = { 2396eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 2397b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 2398b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 2399b001a1b6SBenny Halevy .op_name = "OP_LOCK", 24001c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2401b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 2402b591480bSJ.Bruce Fields }, 2403b591480bSJ.Bruce Fields [OP_LOCKT] = { 2404eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 2405b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 2406b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 24071c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2408b591480bSJ.Bruce Fields }, 2409b591480bSJ.Bruce Fields [OP_LOCKU] = { 2410eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 241158e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2412b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 24131c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 241457832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 2415b591480bSJ.Bruce Fields }, 2416b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2417eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 2418d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2419b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 24201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2421b591480bSJ.Bruce Fields }, 2422b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2423eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 2424d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2425b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 24261c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2427b591480bSJ.Bruce Fields }, 2428b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2429eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 2430b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 24311c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2432b591480bSJ.Bruce Fields }, 2433b591480bSJ.Bruce Fields [OP_OPEN] = { 2434eb69853dSChristoph Hellwig .op_func = nfsd4_open, 243558e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2436b001a1b6SBenny Halevy .op_name = "OP_OPEN", 24371c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 2438b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 2439b591480bSJ.Bruce Fields }, 2440b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2441eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 244258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2443b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 24441c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 2445b591480bSJ.Bruce Fields }, 2446b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2447eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 244858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2449b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 24501c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 245157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 2452b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 2453b591480bSJ.Bruce Fields }, 2454b591480bSJ.Bruce Fields [OP_PUTFH] = { 2455eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 245668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24575b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2458b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 24591c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2460b591480bSJ.Bruce Fields }, 2461eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2462eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 246368d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24645b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2465b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 24661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2467eeac294eSJ.Bruce Fields }, 2468b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2469eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 247068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24715b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2472b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 24731c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2474b591480bSJ.Bruce Fields }, 2475b591480bSJ.Bruce Fields [OP_READ] = { 2476eb69853dSChristoph Hellwig .op_func = nfsd4_read, 247734b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 2478b001a1b6SBenny Halevy .op_name = "OP_READ", 24791c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 248057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 2481b591480bSJ.Bruce Fields }, 2482b591480bSJ.Bruce Fields [OP_READDIR] = { 2483eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 2484b001a1b6SBenny Halevy .op_name = "OP_READDIR", 24851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 2486b591480bSJ.Bruce Fields }, 2487b591480bSJ.Bruce Fields [OP_READLINK] = { 2488eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 2489b001a1b6SBenny Halevy .op_name = "OP_READLINK", 24901c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 2491b591480bSJ.Bruce Fields }, 2492b591480bSJ.Bruce Fields [OP_REMOVE] = { 2493eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 2494c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2495b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 24961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 2497b591480bSJ.Bruce Fields }, 2498b591480bSJ.Bruce Fields [OP_RENAME] = { 2499eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 2500c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 250158e7b33aSMi Jinlong .op_name = "OP_RENAME", 25021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 2503b591480bSJ.Bruce Fields }, 2504b591480bSJ.Bruce Fields [OP_RENEW] = { 2505eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 250658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 250758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2508b001a1b6SBenny Halevy .op_name = "OP_RENEW", 25091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 251058e7b33aSMi Jinlong 2511b591480bSJ.Bruce Fields }, 2512b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2513eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 251468d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 251558e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2516b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 25171c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2518b591480bSJ.Bruce Fields }, 2519b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2520eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 252158e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2522b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 25231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2524b591480bSJ.Bruce Fields }, 2525dcb488a3SAndy Adamson [OP_SECINFO] = { 2526eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 252734b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 252868d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2529b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 25301c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 2531dcb488a3SAndy Adamson }, 2532b591480bSJ.Bruce Fields [OP_SETATTR] = { 2533eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 2534b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2535b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 2536b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 25371c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 253857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 2539b591480bSJ.Bruce Fields }, 2540b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2541eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 254258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2543b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 2544b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 2545b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 25461c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 2547b591480bSJ.Bruce Fields }, 2548b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2549eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 255058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2551c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2552b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 25531c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2554b591480bSJ.Bruce Fields }, 2555b591480bSJ.Bruce Fields [OP_VERIFY] = { 2556eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 2557b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 25581c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2559b591480bSJ.Bruce Fields }, 2560b591480bSJ.Bruce Fields [OP_WRITE] = { 2561eb69853dSChristoph Hellwig .op_func = nfsd4_write, 2562c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2563b001a1b6SBenny Halevy .op_name = "OP_WRITE", 25641c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 256557832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 2566b591480bSJ.Bruce Fields }, 2567b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2568eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 256958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 257058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2571b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 25721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2573b591480bSJ.Bruce Fields }, 2574069b6ad4SAndy Adamson 2575069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2576069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2577eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 257858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 257958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2580069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 25811c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 2582069b6ad4SAndy Adamson }, 2583cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2584eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 2585cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2586cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 25871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2588cb73a9f4SJ. Bruce Fields }, 25891d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 2590eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 259158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 259258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 25931d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 25941c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 25951d1bc8f2SJ. Bruce Fields }, 2596069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2597eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 259858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 259958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2600069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 26011c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 2602069b6ad4SAndy Adamson }, 2603069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2604eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 260558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 260658e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2607069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 26081c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2609069b6ad4SAndy Adamson }, 2610069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2611eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 2612f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2613069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 26141c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 2615069b6ad4SAndy Adamson }, 2616094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2617eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 261858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 261958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2620094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 26211c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2622094b5d74SBenny Halevy }, 26234dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 2624eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 262558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 26264dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 26271c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 26284dc6ec00SJ. Bruce Fields }, 262904f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 2630eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 2631ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 263268d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 263304f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 26341c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 263504f4ad16SJ. Bruce Fields }, 263617456804SBryan Schumaker [OP_TEST_STATEID] = { 2637eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 263817456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 263917456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 26401c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 264117456804SBryan Schumaker }, 2642e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 2643eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 264458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2645e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 264657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 26471c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2648e1ca12dfSBryan Schumaker }, 26499cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 26509cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 2651eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 265234b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 26539cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 26549cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 26551c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 26569cf514ccSChristoph Hellwig }, 26579cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 2658eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 265934b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 26609cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26619cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 26621c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 26639cf514ccSChristoph Hellwig }, 26649cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 2665eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 26669cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26679cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 26681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 26699cf514ccSChristoph Hellwig }, 26709cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 2671eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 26729cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26739cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 26741c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 26759cf514ccSChristoph Hellwig }, 26769cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 267724bab491SAnna Schumaker 267824bab491SAnna Schumaker /* NFSv4.2 operations */ 267995d871f0SAnna Schumaker [OP_ALLOCATE] = { 2680eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 268103b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 268295d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 26831c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 268495d871f0SAnna Schumaker }, 2685b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 2686eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 268703b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2688b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 26891c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2690b0cb9085SAnna Schumaker }, 2691ffa0160aSChristoph Hellwig [OP_CLONE] = { 2692eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 269303b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2694ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 26951c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2696ffa0160aSChristoph Hellwig }, 269729ae7f9dSAnna Schumaker [OP_COPY] = { 2698eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 269903b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 270029ae7f9dSAnna Schumaker .op_name = "OP_COPY", 27011c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 270229ae7f9dSAnna Schumaker }, 270324bab491SAnna Schumaker [OP_SEEK] = { 2704eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 270524bab491SAnna Schumaker .op_name = "OP_SEEK", 27061c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 270724bab491SAnna Schumaker }, 27086308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 27096308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 27106308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 27116308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 27126308bc98SOlga Kornievskaia }, 2713885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 2714885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 2715885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2716885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 2717885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 2718885e2bf3SOlga Kornievskaia }, 2719b591480bSJ.Bruce Fields }; 2720b591480bSJ.Bruce Fields 2721ed941643SAndrew Elble /** 2722ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 2723ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 2724ed941643SAndrew Elble * 2725ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 2726ed941643SAndrew Elble * 2727ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 2728ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 2729ed941643SAndrew Elble */ 2730ed941643SAndrew Elble 2731ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 2732ed941643SAndrew Elble { 2733ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 2734ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 2735ed941643SAndrew Elble struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 2736ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 2737ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 2738ed941643SAndrew Elble u32 opiter; 2739ed941643SAndrew Elble 2740ed941643SAndrew Elble if (!cstate->minorversion) 2741ed941643SAndrew Elble return false; 2742ed941643SAndrew Elble 2743ed941643SAndrew Elble if (cstate->spo_must_allowed == true) 2744ed941643SAndrew Elble return true; 2745ed941643SAndrew Elble 2746ed941643SAndrew Elble opiter = resp->opcnt; 2747ed941643SAndrew Elble while (opiter < argp->opcnt) { 2748ed941643SAndrew Elble this = &argp->ops[opiter++]; 2749ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 2750ed941643SAndrew Elble cstate->clp->cl_mach_cred && 2751ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 2752ed941643SAndrew Elble cstate->spo_must_allowed = true; 2753ed941643SAndrew Elble return true; 2754ed941643SAndrew Elble } 2755ed941643SAndrew Elble } 2756ed941643SAndrew Elble cstate->spo_must_allowed = false; 2757ed941643SAndrew Elble return false; 2758ed941643SAndrew Elble } 2759ed941643SAndrew Elble 27604f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 27614f0cefbfSJ. Bruce Fields { 276205b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 27634f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 27642282cd2cSKinglong Mee 27652282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 27662282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 27674f0cefbfSJ. Bruce Fields } 27684f0cefbfSJ. Bruce Fields 276907d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 277007d1f802SJ. Bruce Fields { 277107d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 277207d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 277307d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 277407d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 277507d1f802SJ. Bruce Fields } 277607d1f802SJ. Bruce Fields } 277707d1f802SJ. Bruce Fields 2778f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 2779b001a1b6SBenny Halevy { 2780b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 2781b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 2782b001a1b6SBenny Halevy return "unknown_operation"; 2783b001a1b6SBenny Halevy } 2784b001a1b6SBenny Halevy 27851da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 27861da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 27871da177e4SLinus Torvalds 2788860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 27890a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 2790f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 279163f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_voidres, 27920a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 27930a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 27940a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 27950a93a47fSYu Zhiguo .pc_xdrressize = 1, 27960a93a47fSYu Zhiguo }, 27970a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 2798f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 2799026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 280063f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 28010a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 28020a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 28033e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 28040a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 28050a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 28060a93a47fSYu Zhiguo }, 28071da177e4SLinus Torvalds }; 28081da177e4SLinus Torvalds 28097fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 2810e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 28111da177e4SLinus Torvalds .vs_vers = 4, 28121da177e4SLinus Torvalds .vs_nproc = 2, 28131da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 28147fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 28151da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 28161da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 281705a45a2dSJeff Layton .vs_rpcb_optnl = true, 28185283b03eSJeff Layton .vs_need_cong_ctrl = true, 28191da177e4SLinus Torvalds }; 28201da177e4SLinus Torvalds 28211da177e4SLinus Torvalds /* 28221da177e4SLinus Torvalds * Local variables: 28231da177e4SLinus Torvalds * c-basic-offset: 8 28241da177e4SLinus Torvalds * End: 28251da177e4SLinus Torvalds */ 2826