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; 4308b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4318b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 432bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4331da177e4SLinus Torvalds if (status) 4341da177e4SLinus Torvalds goto out; 435c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4361da177e4SLinus Torvalds break; 4378b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4381da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4392fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4401da177e4SLinus Torvalds open->op_claim_type); 4411da177e4SLinus Torvalds status = nfserr_notsupp; 4421da177e4SLinus Torvalds goto out; 4431da177e4SLinus Torvalds default: 4442fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4451da177e4SLinus Torvalds open->op_claim_type); 4461da177e4SLinus Torvalds status = nfserr_inval; 4471da177e4SLinus Torvalds goto out; 4481da177e4SLinus Torvalds } 4491da177e4SLinus Torvalds /* 4501da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4511da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4521da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4531da177e4SLinus Torvalds */ 454c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 455b3fbfe0eSJeff Layton WARN(status && open->op_created, 456b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 457b3fbfe0eSJeff Layton be32_to_cpu(status)); 45803f318caSJ. Bruce Fields if (reclaim && !status) 45903f318caSJ. Bruce Fields nn->somebody_reclaimed = true; 4601da177e4SLinus Torvalds out: 461c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 462c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 463c0e6bee4SJ. Bruce Fields fh_put(resfh); 464c0e6bee4SJ. Bruce Fields kfree(resfh); 465c0e6bee4SJ. Bruce Fields } 46642297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4679411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4681da177e4SLinus Torvalds return status; 4691da177e4SLinus Torvalds } 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds /* 4729d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4739d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4749d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4759d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4769d313b17SJ. Bruce Fields */ 4779d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4789d313b17SJ. Bruce Fields { 479eb69853dSChristoph Hellwig struct nfsd4_open *open = &op->u.open; 4809d313b17SJ. Bruce Fields 4819d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4829d313b17SJ. Bruce Fields return op->status; 4839d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4849d313b17SJ. Bruce Fields return op->status; 4859d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 486eb69853dSChristoph Hellwig return nfsd4_open(rqstp, cstate, &op->u); 4879d313b17SJ. Bruce Fields } 4889d313b17SJ. Bruce Fields 4899d313b17SJ. Bruce Fields /* 4901da177e4SLinus Torvalds * filehandle-manipulating ops. 4911da177e4SLinus Torvalds */ 4927191155bSJ.Bruce Fields static __be32 493b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 494eb69853dSChristoph Hellwig union nfsd4_op_u *u) 4951da177e4SLinus Torvalds { 496eb69853dSChristoph Hellwig u->getfh = &cstate->current_fh; 4971da177e4SLinus Torvalds return nfs_ok; 4981da177e4SLinus Torvalds } 4991da177e4SLinus Torvalds 5007191155bSJ.Bruce Fields static __be32 501ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 502eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5031da177e4SLinus Torvalds { 504eb69853dSChristoph Hellwig struct nfsd4_putfh *putfh = &u->putfh; 505eb69853dSChristoph Hellwig 506ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 507ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 508ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 509ca364317SJ.Bruce Fields putfh->pf_fhlen); 51068d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds 5137191155bSJ.Bruce Fields static __be32 514b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 515eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5161da177e4SLinus Torvalds { 517b37ad28bSAl Viro __be32 status; 5181da177e4SLinus Torvalds 519ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 520df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5211da177e4SLinus Torvalds return status; 5221da177e4SLinus Torvalds } 5231da177e4SLinus Torvalds 5247191155bSJ.Bruce Fields static __be32 525b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 526eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5271da177e4SLinus Torvalds { 528ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5291da177e4SLinus Torvalds return nfserr_restorefh; 5301da177e4SLinus Torvalds 531ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 53237c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 53337c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 53437c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 53537c593c5STigran Mkrtchyan } 5361da177e4SLinus Torvalds return nfs_ok; 5371da177e4SLinus Torvalds } 5381da177e4SLinus Torvalds 5397191155bSJ.Bruce Fields static __be32 540b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 541eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5421da177e4SLinus Torvalds { 543ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 54437c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 54537c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 54637c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 54737c593c5STigran Mkrtchyan } 5481da177e4SLinus Torvalds return nfs_ok; 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds /* 5521da177e4SLinus Torvalds * misc nfsv4 ops 5531da177e4SLinus Torvalds */ 5547191155bSJ.Bruce Fields static __be32 555ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 556eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5571da177e4SLinus Torvalds { 558eb69853dSChristoph Hellwig struct nfsd4_access *access = &u->access; 559eb69853dSChristoph Hellwig 5601da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5611da177e4SLinus Torvalds return nfserr_inval; 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 564ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 565ca364317SJ.Bruce Fields &access->ac_supported); 5661da177e4SLinus Torvalds } 5671da177e4SLinus Torvalds 568b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 569ab4684d1SChuck Lever { 570ab4684d1SChuck Lever __be32 verf[2]; 571b9c0ef85SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 572ab4684d1SChuck Lever 573f419992cSJeff Layton /* 574f419992cSJeff Layton * This is opaque to client, so no need to byte-swap. Use 575256a89faSArnd Bergmann * __force to keep sparse happy. y2038 time_t overflow is 576256a89faSArnd Bergmann * irrelevant in this usage. 577f419992cSJeff Layton */ 578f419992cSJeff Layton verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; 579256a89faSArnd Bergmann verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec; 580ab4684d1SChuck Lever memcpy(verifier->data, verf, sizeof(verifier->data)); 581ab4684d1SChuck Lever } 582ab4684d1SChuck Lever 5837191155bSJ.Bruce Fields static __be32 584ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 585eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5861da177e4SLinus Torvalds { 587eb69853dSChristoph Hellwig struct nfsd4_commit *commit = &u->commit; 588eb69853dSChristoph Hellwig 589b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 59075c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 591ca364317SJ.Bruce Fields commit->co_count); 5921da177e4SLinus Torvalds } 5931da177e4SLinus Torvalds 594b37ad28bSAl Viro static __be32 595ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 596eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5971da177e4SLinus Torvalds { 598eb69853dSChristoph Hellwig struct nfsd4_create *create = &u->create; 5991da177e4SLinus Torvalds struct svc_fh resfh; 600b37ad28bSAl Viro __be32 status; 6011da177e4SLinus Torvalds dev_t rdev; 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6041da177e4SLinus Torvalds 605fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 6061da177e4SLinus Torvalds if (status) 6071da177e4SLinus Torvalds return status; 6081da177e4SLinus Torvalds 6093c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6103c8e0316SYu Zhiguo nfsd_attrmask); 6113c8e0316SYu Zhiguo if (status) 6123c8e0316SYu Zhiguo return status; 6133c8e0316SYu Zhiguo 614880a3a53SJ. Bruce Fields current->fs->umask = create->cr_umask; 6151da177e4SLinus Torvalds switch (create->cr_type) { 6161da177e4SLinus Torvalds case NF4LNK: 617ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 618ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6191e444f5bSKinglong Mee create->cr_data, &resfh); 6201da177e4SLinus Torvalds break; 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds case NF4BLK: 623880a3a53SJ. Bruce Fields status = nfserr_inval; 6241da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6251da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6261da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 627880a3a53SJ. Bruce Fields goto out_umask; 628ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 629ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 630ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6311da177e4SLinus Torvalds break; 6321da177e4SLinus Torvalds 6331da177e4SLinus Torvalds case NF4CHR: 634880a3a53SJ. Bruce Fields status = nfserr_inval; 6351da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6361da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6371da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 638880a3a53SJ. Bruce Fields goto out_umask; 639ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 640ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 641ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6421da177e4SLinus Torvalds break; 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds case NF4SOCK: 645ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 646ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 647ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6481da177e4SLinus Torvalds break; 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds case NF4FIFO: 651ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 652ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 653ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6541da177e4SLinus Torvalds break; 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds case NF4DIR: 6571da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 658ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 659ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 660ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6611da177e4SLinus Torvalds break; 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds default: 6641da177e4SLinus Torvalds status = nfserr_badtype; 6651da177e4SLinus Torvalds } 6661da177e4SLinus Torvalds 6679208faf2SYu Zhiguo if (status) 6689208faf2SYu Zhiguo goto out; 6699208faf2SYu Zhiguo 67018032ca0SDavid Quigley if (create->cr_label.len) 67118032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 67218032ca0SDavid Quigley 6739208faf2SYu Zhiguo if (create->cr_acl != NULL) 6749208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6759208faf2SYu Zhiguo create->cr_bmval); 6769208faf2SYu Zhiguo 677ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 678ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 679ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6809208faf2SYu Zhiguo out: 6811da177e4SLinus Torvalds fh_put(&resfh); 682880a3a53SJ. Bruce Fields out_umask: 683880a3a53SJ. Bruce Fields current->fs->umask = 0; 6841da177e4SLinus Torvalds return status; 6851da177e4SLinus Torvalds } 6861da177e4SLinus Torvalds 6877191155bSJ.Bruce Fields static __be32 688ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 689eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6901da177e4SLinus Torvalds { 691eb69853dSChristoph Hellwig struct nfsd4_getattr *getattr = &u->getattr; 692b37ad28bSAl Viro __be32 status; 6931da177e4SLinus Torvalds 6948837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 6951da177e4SLinus Torvalds if (status) 6961da177e4SLinus Torvalds return status; 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6991da177e4SLinus Torvalds return nfserr_inval; 7001da177e4SLinus Torvalds 701916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 702916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 703916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 7041da177e4SLinus Torvalds 705ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7061da177e4SLinus Torvalds return nfs_ok; 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds 7097191155bSJ.Bruce Fields static __be32 710ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 711eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7121da177e4SLinus Torvalds { 713eb69853dSChristoph Hellwig struct nfsd4_link *link = &u->link; 71495424460SJ. Bruce Fields __be32 status; 7151da177e4SLinus Torvalds 716ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 717ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7181da177e4SLinus Torvalds if (!status) 719ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7201da177e4SLinus Torvalds return status; 7211da177e4SLinus Torvalds } 7221da177e4SLinus Torvalds 7230ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7241da177e4SLinus Torvalds { 7251da177e4SLinus Torvalds struct svc_fh tmp_fh; 726b37ad28bSAl Viro __be32 ret; 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 729df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 730df547efbSJ. Bruce Fields if (ret) 7311da177e4SLinus Torvalds return ret; 7320ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7331da177e4SLinus Torvalds fh_put(&tmp_fh); 7341da177e4SLinus Torvalds return nfserr_noent; 7351da177e4SLinus Torvalds } 7361da177e4SLinus Torvalds fh_put(&tmp_fh); 7370ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7380ff7ab46SJ. Bruce Fields } 7390ff7ab46SJ. Bruce Fields 7400ff7ab46SJ. Bruce Fields static __be32 7410ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 742eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7430ff7ab46SJ. Bruce Fields { 7440ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7451da177e4SLinus Torvalds } 7461da177e4SLinus Torvalds 7477191155bSJ.Bruce Fields static __be32 748ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 749eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7501da177e4SLinus Torvalds { 751ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 752eb69853dSChristoph Hellwig u->lookup.lo_name, u->lookup.lo_len, 753ca364317SJ.Bruce Fields &cstate->current_fh); 7541da177e4SLinus Torvalds } 7551da177e4SLinus Torvalds 7567191155bSJ.Bruce Fields static __be32 757ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 758eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7591da177e4SLinus Torvalds { 760eb69853dSChristoph Hellwig struct nfsd4_read *read = &u->read; 761b37ad28bSAl Viro __be32 status; 7621da177e4SLinus Torvalds 7637e06b7f9SNeilBrown read->rd_filp = NULL; 7641da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7651da177e4SLinus Torvalds return nfserr_inval; 7661da177e4SLinus Torvalds 76787c5942eSChuck Lever trace_nfsd_read_start(rqstp, &cstate->current_fh, 76887c5942eSChuck Lever read->rd_offset, read->rd_length); 76987c5942eSChuck Lever 7709b3234b9SJ. Bruce Fields /* 7719b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7729b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7739b3234b9SJ. Bruce Fields * following compound. 7749b3234b9SJ. Bruce Fields * 7759b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7769b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7779b3234b9SJ. Bruce Fields */ 7789b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 779779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 7809b3234b9SJ. Bruce Fields 7811da177e4SLinus Torvalds /* check stateid */ 782aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 783aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 784aa0d6aedSAnna Schumaker &read->rd_filp, &read->rd_tmp_file); 785af90f707SChristoph Hellwig if (status) { 7861da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7871da177e4SLinus Torvalds goto out; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds status = nfs_ok; 7901da177e4SLinus Torvalds out: 7911da177e4SLinus Torvalds read->rd_rqstp = rqstp; 792ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 7931da177e4SLinus Torvalds return status; 7941da177e4SLinus Torvalds } 7951da177e4SLinus Torvalds 79634b1744cSJ. Bruce Fields 79734b1744cSJ. Bruce Fields static void 79834b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u) 79934b1744cSJ. Bruce Fields { 80034b1744cSJ. Bruce Fields if (u->read.rd_filp) 80134b1744cSJ. Bruce Fields fput(u->read.rd_filp); 80287c5942eSChuck Lever trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, 80387c5942eSChuck Lever u->read.rd_offset, u->read.rd_length); 80434b1744cSJ. Bruce Fields } 80534b1744cSJ. Bruce Fields 8067191155bSJ.Bruce Fields static __be32 807ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 808eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8091da177e4SLinus Torvalds { 810eb69853dSChristoph Hellwig struct nfsd4_readdir *readdir = &u->readdir; 8111da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 8121da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8151da177e4SLinus Torvalds 8161da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8171da177e4SLinus Torvalds return nfserr_inval; 8181da177e4SLinus Torvalds 819916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 820916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 821916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 8221da177e4SLinus Torvalds 823832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8241da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8251da177e4SLinus Torvalds return nfserr_bad_cookie; 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 828ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8291da177e4SLinus Torvalds return nfs_ok; 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds 8327191155bSJ.Bruce Fields static __be32 833ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 834eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8351da177e4SLinus Torvalds { 836eb69853dSChristoph Hellwig u->readlink.rl_rqstp = rqstp; 837eb69853dSChristoph Hellwig u->readlink.rl_fhp = &cstate->current_fh; 8381da177e4SLinus Torvalds return nfs_ok; 8391da177e4SLinus Torvalds } 8401da177e4SLinus Torvalds 8417191155bSJ.Bruce Fields static __be32 842ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 843eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8441da177e4SLinus Torvalds { 845eb69853dSChristoph Hellwig struct nfsd4_remove *remove = &u->remove; 846b37ad28bSAl Viro __be32 status; 8471da177e4SLinus Torvalds 848c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 849c815afc7SNeilBrown return nfserr_grace; 850ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 851ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8521da177e4SLinus Torvalds if (!status) { 853ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 854ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8551da177e4SLinus Torvalds } 8561da177e4SLinus Torvalds return status; 8571da177e4SLinus Torvalds } 8581da177e4SLinus Torvalds 8597191155bSJ.Bruce Fields static __be32 860ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 861eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8621da177e4SLinus Torvalds { 863eb69853dSChristoph Hellwig struct nfsd4_rename *rename = &u->rename; 86495424460SJ. Bruce Fields __be32 status; 8651da177e4SLinus Torvalds 866c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp)) && 8675ccb0066SStanislav Kinsbursky !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) 868c815afc7SNeilBrown return nfserr_grace; 869ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 870ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8711da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8722a6cf944SJ. Bruce Fields if (status) 8732a6cf944SJ. Bruce Fields return status; 874ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 875ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8762a6cf944SJ. Bruce Fields return nfs_ok; 8771da177e4SLinus Torvalds } 8781da177e4SLinus Torvalds 8797191155bSJ.Bruce Fields static __be32 880dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 881eb69853dSChristoph Hellwig union nfsd4_op_u *u) 882dcb488a3SAndy Adamson { 883eb69853dSChristoph Hellwig struct nfsd4_secinfo *secinfo = &u->secinfo; 884dcb488a3SAndy Adamson struct svc_export *exp; 885dcb488a3SAndy Adamson struct dentry *dentry; 886dcb488a3SAndy Adamson __be32 err; 887dcb488a3SAndy Adamson 88829a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 88929a78a3eSJ. Bruce Fields if (err) 89029a78a3eSJ. Bruce Fields return err; 891dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 892dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 893dcb488a3SAndy Adamson &exp, &dentry); 894dcb488a3SAndy Adamson if (err) 895dcb488a3SAndy Adamson return err; 8962f6fc056SJ. Bruce Fields fh_unlock(&cstate->current_fh); 8972b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 898dcb488a3SAndy Adamson exp_put(exp); 899dcb488a3SAndy Adamson err = nfserr_noent; 900dcb488a3SAndy Adamson } else 901dcb488a3SAndy Adamson secinfo->si_exp = exp; 902dcb488a3SAndy Adamson dput(dentry); 90356560b9aSJ. Bruce Fields if (cstate->minorversion) 90456560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 90556560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 906dcb488a3SAndy Adamson return err; 907dcb488a3SAndy Adamson } 908dcb488a3SAndy Adamson 909dcb488a3SAndy Adamson static __be32 91004f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 911eb69853dSChristoph Hellwig union nfsd4_op_u *u) 91204f4ad16SJ. Bruce Fields { 91304f4ad16SJ. Bruce Fields __be32 err; 91404f4ad16SJ. Bruce Fields 915eb69853dSChristoph Hellwig switch (u->secinfo_no_name.sin_style) { 91604f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 91704f4ad16SJ. Bruce Fields break; 91804f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 91904f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 92004f4ad16SJ. Bruce Fields if (err) 92104f4ad16SJ. Bruce Fields return err; 92204f4ad16SJ. Bruce Fields break; 92304f4ad16SJ. Bruce Fields default: 92404f4ad16SJ. Bruce Fields return nfserr_inval; 92504f4ad16SJ. Bruce Fields } 926bf18f163SKinglong Mee 927eb69853dSChristoph Hellwig u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export); 92804f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 92904f4ad16SJ. Bruce Fields return nfs_ok; 93004f4ad16SJ. Bruce Fields } 93104f4ad16SJ. Bruce Fields 93234b1744cSJ. Bruce Fields static void 93334b1744cSJ. Bruce Fields nfsd4_secinfo_release(union nfsd4_op_u *u) 93434b1744cSJ. Bruce Fields { 93534b1744cSJ. Bruce Fields if (u->secinfo.si_exp) 93634b1744cSJ. Bruce Fields exp_put(u->secinfo.si_exp); 93734b1744cSJ. Bruce Fields } 93834b1744cSJ. Bruce Fields 939ec572b9eSEryu Guan static void 940ec572b9eSEryu Guan nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) 941ec572b9eSEryu Guan { 942ec572b9eSEryu Guan if (u->secinfo_no_name.sin_exp) 943ec572b9eSEryu Guan exp_put(u->secinfo_no_name.sin_exp); 944ec572b9eSEryu Guan } 945ec572b9eSEryu Guan 94604f4ad16SJ. Bruce Fields static __be32 947ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 948eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9491da177e4SLinus Torvalds { 950eb69853dSChristoph Hellwig struct nfsd4_setattr *setattr = &u->setattr; 951b37ad28bSAl Viro __be32 status = nfs_ok; 95296f6f985SAl Viro int err; 9531da177e4SLinus Torvalds 9541da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 955af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 956aa0d6aedSAnna Schumaker &cstate->current_fh, &setattr->sa_stateid, 957aa0d6aedSAnna Schumaker WR_STATE, NULL, NULL); 958375c5547SJ. Bruce Fields if (status) { 9593e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 960375c5547SJ. Bruce Fields return status; 961375c5547SJ. Bruce Fields } 9621da177e4SLinus Torvalds } 96396f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 96496f6f985SAl Viro if (err) 96596f6f985SAl Viro return nfserrno(err); 9661da177e4SLinus Torvalds status = nfs_ok; 9673c8e0316SYu Zhiguo 9683c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9693c8e0316SYu Zhiguo nfsd_attrmask); 9703c8e0316SYu Zhiguo if (status) 9713c8e0316SYu Zhiguo goto out; 9723c8e0316SYu Zhiguo 9731da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 974ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 975ca364317SJ.Bruce Fields setattr->sa_acl); 9761da177e4SLinus Torvalds if (status) 97718f335afSDave Hansen goto out; 97818032ca0SDavid Quigley if (setattr->sa_label.len) 97918032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 98018032ca0SDavid Quigley &setattr->sa_label); 98118032ca0SDavid Quigley if (status) 98218032ca0SDavid Quigley goto out; 983ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9841da177e4SLinus Torvalds 0, (time_t)0); 98518f335afSDave Hansen out: 986bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9871da177e4SLinus Torvalds return status; 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds 9907191155bSJ.Bruce Fields static __be32 991ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 992eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9931da177e4SLinus Torvalds { 994eb69853dSChristoph Hellwig struct nfsd4_write *write = &u->write; 9951da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 9961da177e4SLinus Torvalds struct file *filp = NULL; 997b37ad28bSAl Viro __be32 status = nfs_ok; 99831dec253SDavid Shaw unsigned long cnt; 999ffe1137bSJ. Bruce Fields int nvecs; 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 10021da177e4SLinus Torvalds return nfserr_inval; 10031da177e4SLinus Torvalds 1004d890be15SChuck Lever cnt = write->wr_buflen; 1005d890be15SChuck Lever trace_nfsd_write_start(rqstp, &cstate->current_fh, 1006d890be15SChuck Lever write->wr_offset, cnt); 1007aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1008aa0d6aedSAnna Schumaker stateid, WR_STATE, &filp, NULL); 1009375c5547SJ. Bruce Fields if (status) { 1010375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 1011375c5547SJ. Bruce Fields return status; 1012375c5547SJ. Bruce Fields } 1013375c5547SJ. Bruce Fields 10141da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 1015b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); 10161da177e4SLinus Torvalds 10173fd9557aSChuck Lever nvecs = svc_fill_write_vector(rqstp, write->wr_pagelist, 10183fd9557aSChuck Lever &write->wr_head, write->wr_buflen); 10193fd9557aSChuck Lever if (!nvecs) 10203fd9557aSChuck Lever return nfserr_io; 1021ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1022ffe1137bSJ. Bruce Fields 1023af90f707SChristoph Hellwig status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp, 1024af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 102554bbb7d2SKinglong Mee write->wr_how_written); 10267e06b7f9SNeilBrown fput(filp); 10271da177e4SLinus Torvalds 102831dec253SDavid Shaw write->wr_bytes_written = cnt; 1029d890be15SChuck Lever trace_nfsd_write_done(rqstp, &cstate->current_fh, 1030d890be15SChuck Lever write->wr_offset, cnt); 10311da177e4SLinus Torvalds return status; 10321da177e4SLinus Torvalds } 10331da177e4SLinus Torvalds 103424bab491SAnna Schumaker static __be32 103529ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 103629ae7f9dSAnna Schumaker stateid_t *src_stateid, struct file **src, 103729ae7f9dSAnna Schumaker stateid_t *dst_stateid, struct file **dst) 1038ffa0160aSChristoph Hellwig { 1039ffa0160aSChristoph Hellwig __be32 status; 1040ffa0160aSChristoph Hellwig 1041*01310bb7SScott Mayhew if (!cstate->save_fh.fh_dentry) 1042*01310bb7SScott Mayhew return nfserr_nofilehandle; 1043*01310bb7SScott Mayhew 1044ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 104529ae7f9dSAnna Schumaker src_stateid, RD_STATE, src, NULL); 1046ffa0160aSChristoph Hellwig if (status) { 1047ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1048ffa0160aSChristoph Hellwig goto out; 1049ffa0160aSChristoph Hellwig } 1050ffa0160aSChristoph Hellwig 1051ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 105229ae7f9dSAnna Schumaker dst_stateid, WR_STATE, dst, NULL); 1053ffa0160aSChristoph Hellwig if (status) { 1054ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1055ffa0160aSChristoph Hellwig goto out_put_src; 1056ffa0160aSChristoph Hellwig } 1057ffa0160aSChristoph Hellwig 1058ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 105929ae7f9dSAnna Schumaker if (!S_ISREG(file_inode(*src)->i_mode) || 106029ae7f9dSAnna Schumaker !S_ISREG(file_inode(*dst)->i_mode)) { 1061ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1062ffa0160aSChristoph Hellwig goto out_put_dst; 1063ffa0160aSChristoph Hellwig } 1064ffa0160aSChristoph Hellwig 106529ae7f9dSAnna Schumaker out: 106629ae7f9dSAnna Schumaker return status; 106729ae7f9dSAnna Schumaker out_put_dst: 106829ae7f9dSAnna Schumaker fput(*dst); 106929ae7f9dSAnna Schumaker out_put_src: 107029ae7f9dSAnna Schumaker fput(*src); 107129ae7f9dSAnna Schumaker goto out; 107229ae7f9dSAnna Schumaker } 107329ae7f9dSAnna Schumaker 107429ae7f9dSAnna Schumaker static __be32 107529ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1076eb69853dSChristoph Hellwig union nfsd4_op_u *u) 107729ae7f9dSAnna Schumaker { 1078eb69853dSChristoph Hellwig struct nfsd4_clone *clone = &u->clone; 107929ae7f9dSAnna Schumaker struct file *src, *dst; 108029ae7f9dSAnna Schumaker __be32 status; 108129ae7f9dSAnna Schumaker 108229ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 108329ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 108429ae7f9dSAnna Schumaker if (status) 108529ae7f9dSAnna Schumaker goto out; 108629ae7f9dSAnna Schumaker 1087ffa0160aSChristoph Hellwig status = nfsd4_clone_file_range(src, clone->cl_src_pos, 1088ffa0160aSChristoph Hellwig dst, clone->cl_dst_pos, clone->cl_count); 1089ffa0160aSChristoph Hellwig 1090ffa0160aSChristoph Hellwig fput(dst); 1091ffa0160aSChristoph Hellwig fput(src); 1092ffa0160aSChristoph Hellwig out: 1093ffa0160aSChristoph Hellwig return status; 1094ffa0160aSChristoph Hellwig } 1095ffa0160aSChristoph Hellwig 1096e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy) 1097e0639dc5SOlga Kornievskaia { 1098e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1099e0639dc5SOlga Kornievskaia return; 1100e0639dc5SOlga Kornievskaia kfree(copy); 1101e0639dc5SOlga Kornievskaia } 1102e0639dc5SOlga Kornievskaia 1103e0639dc5SOlga Kornievskaia static bool 1104e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy) 1105e0639dc5SOlga Kornievskaia { 1106e0639dc5SOlga Kornievskaia bool value; 1107e0639dc5SOlga Kornievskaia 1108e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1109e0639dc5SOlga Kornievskaia value = copy->stopped; 1110e0639dc5SOlga Kornievskaia if (!copy->stopped) 1111e0639dc5SOlga Kornievskaia copy->stopped = true; 1112e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1113e0639dc5SOlga Kornievskaia return value; 1114e0639dc5SOlga Kornievskaia } 1115e0639dc5SOlga Kornievskaia 1116e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1117e0639dc5SOlga Kornievskaia { 1118e0639dc5SOlga Kornievskaia /* only 1 thread should stop the copy */ 1119e0639dc5SOlga Kornievskaia if (!check_and_set_stop_copy(copy)) 1120e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1121e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1122e0639dc5SOlga Kornievskaia } 1123e0639dc5SOlga Kornievskaia 1124e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1125e0639dc5SOlga Kornievskaia { 1126e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1127e0639dc5SOlga Kornievskaia 1128e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1129e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1130e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1131e0639dc5SOlga Kornievskaia copies); 1132e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1133e0639dc5SOlga Kornievskaia } 1134e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1135e0639dc5SOlga Kornievskaia return copy; 1136e0639dc5SOlga Kornievskaia } 1137e0639dc5SOlga Kornievskaia 1138e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1139e0639dc5SOlga Kornievskaia { 1140e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1141e0639dc5SOlga Kornievskaia 1142e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1143e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1144e0639dc5SOlga Kornievskaia } 1145e0639dc5SOlga Kornievskaia 1146e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1147e0639dc5SOlga Kornievskaia { 1148e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); 1149e0639dc5SOlga Kornievskaia 1150e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1151e0639dc5SOlga Kornievskaia } 1152e0639dc5SOlga Kornievskaia 1153e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1154e0639dc5SOlga Kornievskaia struct rpc_task *task) 1155e0639dc5SOlga Kornievskaia { 1156e0639dc5SOlga Kornievskaia return 1; 1157e0639dc5SOlga Kornievskaia } 1158e0639dc5SOlga Kornievskaia 1159e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1160e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1161e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1162e0639dc5SOlga Kornievskaia }; 1163e0639dc5SOlga Kornievskaia 1164e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1165e0639dc5SOlga Kornievskaia { 1166e0639dc5SOlga Kornievskaia copy->cp_res.wr_stable_how = NFS_UNSTABLE; 1167e0639dc5SOlga Kornievskaia copy->cp_synchronous = sync; 1168e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1169e0639dc5SOlga Kornievskaia } 1170e0639dc5SOlga Kornievskaia 1171e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) 1172e0639dc5SOlga Kornievskaia { 1173e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1174e0639dc5SOlga Kornievskaia size_t bytes_total = copy->cp_count; 1175e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1176e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1177e0639dc5SOlga Kornievskaia 1178e0639dc5SOlga Kornievskaia do { 1179e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1180e0639dc5SOlga Kornievskaia break; 1181e0639dc5SOlga Kornievskaia bytes_copied = nfsd_copy_file_range(copy->file_src, src_pos, 1182e0639dc5SOlga Kornievskaia copy->file_dst, dst_pos, bytes_total); 1183e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1184e0639dc5SOlga Kornievskaia break; 1185e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1186e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1187e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1188e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1189e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1190e0639dc5SOlga Kornievskaia return bytes_copied; 1191e0639dc5SOlga Kornievskaia } 1192e0639dc5SOlga Kornievskaia 1193e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1194e0639dc5SOlga Kornievskaia { 1195e0639dc5SOlga Kornievskaia __be32 status; 1196e0639dc5SOlga Kornievskaia ssize_t bytes; 1197e0639dc5SOlga Kornievskaia 1198e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1199e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1200e0639dc5SOlga Kornievskaia * to get the error 1201e0639dc5SOlga Kornievskaia */ 1202e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1203e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1204e0639dc5SOlga Kornievskaia else { 1205e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1206e0639dc5SOlga Kornievskaia status = nfs_ok; 1207e0639dc5SOlga Kornievskaia } 1208e0639dc5SOlga Kornievskaia 1209e0639dc5SOlga Kornievskaia fput(copy->file_src); 1210e0639dc5SOlga Kornievskaia fput(copy->file_dst); 1211e0639dc5SOlga Kornievskaia return status; 1212e0639dc5SOlga Kornievskaia } 1213e0639dc5SOlga Kornievskaia 1214e0639dc5SOlga Kornievskaia static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1215e0639dc5SOlga Kornievskaia { 1216e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1217e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1218e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1219e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1220e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1221e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1222e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 1223e0639dc5SOlga Kornievskaia dst->file_dst = get_file(src->file_dst); 1224e0639dc5SOlga Kornievskaia dst->file_src = get_file(src->file_src); 1225e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1226e0639dc5SOlga Kornievskaia } 1227e0639dc5SOlga Kornievskaia 1228e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1229e0639dc5SOlga Kornievskaia { 1230e0639dc5SOlga Kornievskaia nfs4_free_cp_state(copy); 1231e0639dc5SOlga Kornievskaia fput(copy->file_dst); 1232e0639dc5SOlga Kornievskaia fput(copy->file_src); 1233e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1234e0639dc5SOlga Kornievskaia list_del(©->copies); 1235e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1236e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1237e0639dc5SOlga Kornievskaia } 1238e0639dc5SOlga Kornievskaia 1239e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1240e0639dc5SOlga Kornievskaia { 1241e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1242e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1243e0639dc5SOlga Kornievskaia 1244e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1245e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1246e0639dc5SOlga Kornievskaia if (!cb_copy) 1247e0639dc5SOlga Kornievskaia goto out; 1248e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1249e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1250e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1251e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1252e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1253e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 1254e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1255e0639dc5SOlga Kornievskaia out: 1256e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1257e0639dc5SOlga Kornievskaia return 0; 1258e0639dc5SOlga Kornievskaia } 1259e0639dc5SOlga Kornievskaia 1260ffa0160aSChristoph Hellwig static __be32 126129ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1262eb69853dSChristoph Hellwig union nfsd4_op_u *u) 126329ae7f9dSAnna Schumaker { 1264eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 126529ae7f9dSAnna Schumaker __be32 status; 1266e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 126729ae7f9dSAnna Schumaker 1268e0639dc5SOlga Kornievskaia status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 1269e0639dc5SOlga Kornievskaia ©->file_src, ©->cp_dst_stateid, 1270e0639dc5SOlga Kornievskaia ©->file_dst); 127129ae7f9dSAnna Schumaker if (status) 127229ae7f9dSAnna Schumaker goto out; 127329ae7f9dSAnna Schumaker 1274e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1275e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1276e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1277e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1278e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 127929ae7f9dSAnna Schumaker 1280e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1281e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1282e0639dc5SOlga Kornievskaia if (!async_copy) 1283e0639dc5SOlga Kornievskaia goto out; 1284e0639dc5SOlga Kornievskaia if (!nfs4_init_cp_state(nn, copy)) { 1285e0639dc5SOlga Kornievskaia kfree(async_copy); 1286e0639dc5SOlga Kornievskaia goto out; 128729ae7f9dSAnna Schumaker } 1288e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1289e0639dc5SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid, 1290e0639dc5SOlga Kornievskaia sizeof(copy->cp_stateid)); 1291e0639dc5SOlga Kornievskaia dup_copy_fields(copy, async_copy); 1292e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1293e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1294e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1295e0639dc5SOlga Kornievskaia goto out_err; 1296e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1297e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1298e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1299e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1300e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1301e0639dc5SOlga Kornievskaia status = nfs_ok; 1302e0639dc5SOlga Kornievskaia } else 1303e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 130429ae7f9dSAnna Schumaker out: 130529ae7f9dSAnna Schumaker return status; 1306e0639dc5SOlga Kornievskaia out_err: 1307e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1308e0639dc5SOlga Kornievskaia goto out; 1309e0639dc5SOlga Kornievskaia } 1310e0639dc5SOlga Kornievskaia 1311e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1312e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1313e0639dc5SOlga Kornievskaia { 1314e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1315e0639dc5SOlga Kornievskaia 1316e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1317e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1318e0639dc5SOlga Kornievskaia if (memcmp(©->cp_stateid, stateid, NFS4_STATEID_SIZE)) 1319e0639dc5SOlga Kornievskaia continue; 1320e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1321e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1322e0639dc5SOlga Kornievskaia return copy; 1323e0639dc5SOlga Kornievskaia } 1324e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1325e0639dc5SOlga Kornievskaia return NULL; 132629ae7f9dSAnna Schumaker } 132729ae7f9dSAnna Schumaker 132829ae7f9dSAnna Schumaker static __be32 1329885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1330885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1331885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1332885e2bf3SOlga Kornievskaia { 1333e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1334e0639dc5SOlga Kornievskaia __be32 status = 0; 1335e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1336e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1337e0639dc5SOlga Kornievskaia 1338e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1339e0639dc5SOlga Kornievskaia if (copy) 1340e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1341e0639dc5SOlga Kornievskaia else 1342e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1343e0639dc5SOlga Kornievskaia 1344e0639dc5SOlga Kornievskaia return status; 1345885e2bf3SOlga Kornievskaia } 1346885e2bf3SOlga Kornievskaia 1347885e2bf3SOlga Kornievskaia static __be32 134895d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 134995d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 135095d871f0SAnna Schumaker { 135195d871f0SAnna Schumaker __be32 status = nfserr_notsupp; 135295d871f0SAnna Schumaker struct file *file; 135395d871f0SAnna Schumaker 1354aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 135595d871f0SAnna Schumaker &fallocate->falloc_stateid, 1356af90f707SChristoph Hellwig WR_STATE, &file, NULL); 135795d871f0SAnna Schumaker if (status != nfs_ok) { 135895d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 135995d871f0SAnna Schumaker return status; 136095d871f0SAnna Schumaker } 136195d871f0SAnna Schumaker 136295d871f0SAnna Schumaker status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, 136395d871f0SAnna Schumaker fallocate->falloc_offset, 136495d871f0SAnna Schumaker fallocate->falloc_length, 136595d871f0SAnna Schumaker flags); 136695d871f0SAnna Schumaker fput(file); 136795d871f0SAnna Schumaker return status; 136895d871f0SAnna Schumaker } 13696308bc98SOlga Kornievskaia static __be32 13706308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 13716308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 13726308bc98SOlga Kornievskaia union nfsd4_op_u *u) 13736308bc98SOlga Kornievskaia { 1374e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1375e0639dc5SOlga Kornievskaia __be32 status = 0; 1376e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1377e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1378e0639dc5SOlga Kornievskaia 1379e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1380e0639dc5SOlga Kornievskaia if (copy) { 1381e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 1382e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1383e0639dc5SOlga Kornievskaia } else 1384e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1385e0639dc5SOlga Kornievskaia 1386e0639dc5SOlga Kornievskaia return status; 13876308bc98SOlga Kornievskaia } 138895d871f0SAnna Schumaker 138995d871f0SAnna Schumaker static __be32 139095d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1391eb69853dSChristoph Hellwig union nfsd4_op_u *u) 139295d871f0SAnna Schumaker { 1393eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 139495d871f0SAnna Schumaker } 139595d871f0SAnna Schumaker 139695d871f0SAnna Schumaker static __be32 1397b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1398eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1399b0cb9085SAnna Schumaker { 1400eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 1401b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1402b0cb9085SAnna Schumaker } 1403b0cb9085SAnna Schumaker 1404b0cb9085SAnna Schumaker static __be32 140524bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1406eb69853dSChristoph Hellwig union nfsd4_op_u *u) 140724bab491SAnna Schumaker { 1408eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 140924bab491SAnna Schumaker int whence; 141024bab491SAnna Schumaker __be32 status; 141124bab491SAnna Schumaker struct file *file; 141224bab491SAnna Schumaker 1413aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 141424bab491SAnna Schumaker &seek->seek_stateid, 1415af90f707SChristoph Hellwig RD_STATE, &file, NULL); 141624bab491SAnna Schumaker if (status) { 141724bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 141824bab491SAnna Schumaker return status; 141924bab491SAnna Schumaker } 142024bab491SAnna Schumaker 142124bab491SAnna Schumaker switch (seek->seek_whence) { 142224bab491SAnna Schumaker case NFS4_CONTENT_DATA: 142324bab491SAnna Schumaker whence = SEEK_DATA; 142424bab491SAnna Schumaker break; 142524bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 142624bab491SAnna Schumaker whence = SEEK_HOLE; 142724bab491SAnna Schumaker break; 142824bab491SAnna Schumaker default: 142924bab491SAnna Schumaker status = nfserr_union_notsupp; 143024bab491SAnna Schumaker goto out; 143124bab491SAnna Schumaker } 143224bab491SAnna Schumaker 143324bab491SAnna Schumaker /* 143424bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 143524bab491SAnna Schumaker * should ever file->f_pos. 143624bab491SAnna Schumaker */ 143724bab491SAnna Schumaker seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence); 143824bab491SAnna Schumaker if (seek->seek_pos < 0) 143924bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 144024bab491SAnna Schumaker else if (seek->seek_pos >= i_size_read(file_inode(file))) 144124bab491SAnna Schumaker seek->seek_eof = true; 144224bab491SAnna Schumaker 144324bab491SAnna Schumaker out: 144424bab491SAnna Schumaker fput(file); 144524bab491SAnna Schumaker return status; 144624bab491SAnna Schumaker } 144724bab491SAnna Schumaker 14481da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 14491da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 14501da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 14511da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 14521da177e4SLinus Torvalds */ 1453b37ad28bSAl Viro static __be32 1454c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1455ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 14561da177e4SLinus Torvalds { 14572ebbc012SAl Viro __be32 *buf, *p; 14581da177e4SLinus Torvalds int count; 1459b37ad28bSAl Viro __be32 status; 14601da177e4SLinus Torvalds 14618837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 14621da177e4SLinus Torvalds if (status) 14631da177e4SLinus Torvalds return status; 14641da177e4SLinus Torvalds 14653c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 14663c8e0316SYu Zhiguo if (status) 14673c8e0316SYu Zhiguo return status; 14683c8e0316SYu Zhiguo 14691da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 14701da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 14711da177e4SLinus Torvalds return nfserr_inval; 14721da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 14731da177e4SLinus Torvalds return nfserr_inval; 14741da177e4SLinus Torvalds 14751da177e4SLinus Torvalds /* count in words: 14761da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 14771da177e4SLinus Torvalds */ 14781da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 14791da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 14801da177e4SLinus Torvalds if (!buf) 14813e772463SJ. Bruce Fields return nfserr_jukebox; 14821da177e4SLinus Torvalds 148384822d0bSJ. Bruce Fields p = buf; 1484d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1485ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1486d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1487d5184658SJ. Bruce Fields verify->ve_bmval, 1488406a7ea9SFrank Filz rqstp, 0); 148941ae6e71SJ. Bruce Fields /* 149041ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 149141ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 149241ae6e71SJ. Bruce Fields */ 149384822d0bSJ. Bruce Fields if (status == nfserr_resource) 14941da177e4SLinus Torvalds status = nfserr_not_same; 14951da177e4SLinus Torvalds if (status) 14961da177e4SLinus Torvalds goto out_kfree; 14971da177e4SLinus Torvalds 149895ec28cdSBenny Halevy /* skip bitmap */ 149995ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 15001da177e4SLinus Torvalds status = nfserr_not_same; 15011da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 15021da177e4SLinus Torvalds goto out_kfree; 15031da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 15041da177e4SLinus Torvalds status = nfserr_same; 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds out_kfree: 15071da177e4SLinus Torvalds kfree(buf); 15081da177e4SLinus Torvalds return status; 15091da177e4SLinus Torvalds } 15101da177e4SLinus Torvalds 1511c954e2a5SJ.Bruce Fields static __be32 1512c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1513eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1514c954e2a5SJ.Bruce Fields { 1515c954e2a5SJ.Bruce Fields __be32 status; 1516c954e2a5SJ.Bruce Fields 1517eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 1518c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1519c954e2a5SJ.Bruce Fields } 1520c954e2a5SJ.Bruce Fields 1521c954e2a5SJ.Bruce Fields static __be32 1522c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1523eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1524c954e2a5SJ.Bruce Fields { 1525c954e2a5SJ.Bruce Fields __be32 status; 1526c954e2a5SJ.Bruce Fields 1527eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 1528c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1529c954e2a5SJ.Bruce Fields } 1530c954e2a5SJ.Bruce Fields 15319cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 15329cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 15339cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 15349cf514ccSChristoph Hellwig { 15358a4c3926SJeff Layton if (!exp->ex_layout_types) { 15369cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 15379cf514ccSChristoph Hellwig return NULL; 15389cf514ccSChristoph Hellwig } 15399cf514ccSChristoph Hellwig 1540b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1541b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 15429cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 15439cf514ccSChristoph Hellwig __func__, layout_type); 15449cf514ccSChristoph Hellwig return NULL; 15459cf514ccSChristoph Hellwig } 15469cf514ccSChristoph Hellwig 15479cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 15489cf514ccSChristoph Hellwig } 15499cf514ccSChristoph Hellwig 15509cf514ccSChristoph Hellwig static __be32 15519cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 1552eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 15539cf514ccSChristoph Hellwig { 1554eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 15559cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 15569cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 15579cf514ccSChristoph Hellwig struct svc_export *exp; 15589cf514ccSChristoph Hellwig __be32 nfserr; 15599cf514ccSChristoph Hellwig 15609cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 15619cf514ccSChristoph Hellwig __func__, 15629cf514ccSChristoph Hellwig gdp->gd_layout_type, 15639cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 15649cf514ccSChristoph Hellwig gdp->gd_maxcount); 15659cf514ccSChristoph Hellwig 15669cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 15679cf514ccSChristoph Hellwig if (!map) { 15689cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 15699cf514ccSChristoph Hellwig __func__); 15709cf514ccSChristoph Hellwig return nfserr_noent; 15719cf514ccSChristoph Hellwig } 15729cf514ccSChristoph Hellwig 15739cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 15749cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 15759cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 15769cf514ccSChristoph Hellwig return nfserr_noent; 15779cf514ccSChristoph Hellwig } 15789cf514ccSChristoph Hellwig 15799cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 15809cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 15819cf514ccSChristoph Hellwig if (!ops) 15829cf514ccSChristoph Hellwig goto out; 15839cf514ccSChristoph Hellwig 15849cf514ccSChristoph Hellwig nfserr = nfs_ok; 1585f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 1586f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 1587d7c920d1STom Haynes rqstp, cstate->session->se_client, gdp); 1588f99d4fbdSChristoph Hellwig } 15899cf514ccSChristoph Hellwig 15909cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 15919cf514ccSChristoph Hellwig out: 1592a1420384SKinglong Mee exp_put(exp); 15939cf514ccSChristoph Hellwig return nfserr; 15949cf514ccSChristoph Hellwig } 15959cf514ccSChristoph Hellwig 159634b1744cSJ. Bruce Fields static void 159734b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 159834b1744cSJ. Bruce Fields { 159934b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 160034b1744cSJ. Bruce Fields } 160134b1744cSJ. Bruce Fields 16029cf514ccSChristoph Hellwig static __be32 16039cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 1604eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 16059cf514ccSChristoph Hellwig { 1606eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 16079cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 16089cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 16099cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 16109cf514ccSChristoph Hellwig __be32 nfserr; 161166282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 16129cf514ccSChristoph Hellwig 16139cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 16149cf514ccSChristoph Hellwig case IOMODE_READ: 161566282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 16169cf514ccSChristoph Hellwig break; 16179cf514ccSChristoph Hellwig case IOMODE_RW: 161866282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 16199cf514ccSChristoph Hellwig break; 16209cf514ccSChristoph Hellwig default: 16219cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 16229cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 16239cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 16249cf514ccSChristoph Hellwig goto out; 16259cf514ccSChristoph Hellwig } 16269cf514ccSChristoph Hellwig 16279cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 16289cf514ccSChristoph Hellwig if (nfserr) 16299cf514ccSChristoph Hellwig goto out; 16309cf514ccSChristoph Hellwig 16319cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 16329cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 16339cf514ccSChristoph Hellwig if (!ops) 16349cf514ccSChristoph Hellwig goto out; 16359cf514ccSChristoph Hellwig 16369cf514ccSChristoph Hellwig /* 16379cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 16389cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 16399cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 16409cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 16419cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 16429cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 16439cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 16449cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 16459cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 16469cf514ccSChristoph Hellwig */ 16479cf514ccSChristoph Hellwig nfserr = nfserr_inval; 16489cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 16499cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 16509cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 16519cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 16529cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 16539cf514ccSChristoph Hellwig goto out; 16549cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 16559cf514ccSChristoph Hellwig goto out; 16569cf514ccSChristoph Hellwig 16579cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 16589cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 165931ef83dcSChristoph Hellwig if (nfserr) { 1660f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 16619cf514ccSChristoph Hellwig goto out; 166231ef83dcSChristoph Hellwig } 16639cf514ccSChristoph Hellwig 1664c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1665c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1666c5c707f9SChristoph Hellwig goto out_put_stid; 1667c5c707f9SChristoph Hellwig 16682b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 16699cf514ccSChristoph Hellwig current_fh, lgp); 16709cf514ccSChristoph Hellwig if (nfserr) 16719cf514ccSChristoph Hellwig goto out_put_stid; 16729cf514ccSChristoph Hellwig 16739cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 16749cf514ccSChristoph Hellwig 16759cf514ccSChristoph Hellwig out_put_stid: 1676cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 16779cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 16789cf514ccSChristoph Hellwig out: 16799cf514ccSChristoph Hellwig return nfserr; 16809cf514ccSChristoph Hellwig } 16819cf514ccSChristoph Hellwig 168234b1744cSJ. Bruce Fields static void 168334b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 168434b1744cSJ. Bruce Fields { 168534b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 168634b1744cSJ. Bruce Fields } 168734b1744cSJ. Bruce Fields 16889cf514ccSChristoph Hellwig static __be32 16899cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 1690eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 16919cf514ccSChristoph Hellwig { 1692eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 16939cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 16949cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 16959cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 16969cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 16979cf514ccSChristoph Hellwig struct inode *inode; 16989cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 16999cf514ccSChristoph Hellwig __be32 nfserr; 17009cf514ccSChristoph Hellwig 17019cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 17029cf514ccSChristoph Hellwig if (nfserr) 17039cf514ccSChristoph Hellwig goto out; 17049cf514ccSChristoph Hellwig 17059cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 17069cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 17079cf514ccSChristoph Hellwig if (!ops) 17089cf514ccSChristoph Hellwig goto out; 17092b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 17109cf514ccSChristoph Hellwig 17119cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17129cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 17139cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 17149cf514ccSChristoph Hellwig goto out; 17159cf514ccSChristoph Hellwig } 17169cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 17179cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 17189cf514ccSChristoph Hellwig goto out; 17199cf514ccSChristoph Hellwig } 17209cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 17219cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 17229cf514ccSChristoph Hellwig goto out; 17239cf514ccSChristoph Hellwig } 17249cf514ccSChristoph Hellwig 17259cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 17269cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 17279cf514ccSChristoph Hellwig &ls); 17289cf514ccSChristoph Hellwig if (nfserr) { 1729f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 17309cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 17319cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 17329cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 17339cf514ccSChristoph Hellwig goto out; 17349cf514ccSChristoph Hellwig } 17359cf514ccSChristoph Hellwig 1736cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 1737cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 1738cc8a5532SJeff Layton 17399cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 17409cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 17419cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 17429cf514ccSChristoph Hellwig } else { 17439cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 17449cf514ccSChristoph Hellwig } 17459cf514ccSChristoph Hellwig 1746d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 17479cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 17489cf514ccSChristoph Hellwig out: 17499cf514ccSChristoph Hellwig return nfserr; 17509cf514ccSChristoph Hellwig } 17519cf514ccSChristoph Hellwig 17529cf514ccSChristoph Hellwig static __be32 17539cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 1754eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 17559cf514ccSChristoph Hellwig { 1756eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 17579cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 17589cf514ccSChristoph Hellwig __be32 nfserr; 17599cf514ccSChristoph Hellwig 17609cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 17619cf514ccSChristoph Hellwig if (nfserr) 17629cf514ccSChristoph Hellwig goto out; 17639cf514ccSChristoph Hellwig 17649cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 17659cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 17669cf514ccSChristoph Hellwig goto out; 17679cf514ccSChristoph Hellwig 17689cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 17699cf514ccSChristoph Hellwig case IOMODE_READ: 17709cf514ccSChristoph Hellwig case IOMODE_RW: 17719cf514ccSChristoph Hellwig case IOMODE_ANY: 17729cf514ccSChristoph Hellwig break; 17739cf514ccSChristoph Hellwig default: 17749cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 17759cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 17769cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17779cf514ccSChristoph Hellwig goto out; 17789cf514ccSChristoph Hellwig } 17799cf514ccSChristoph Hellwig 17809cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 17819cf514ccSChristoph Hellwig case RETURN_FILE: 17829cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 17839cf514ccSChristoph Hellwig break; 17849cf514ccSChristoph Hellwig case RETURN_FSID: 17859cf514ccSChristoph Hellwig case RETURN_ALL: 17869cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 17879cf514ccSChristoph Hellwig break; 17889cf514ccSChristoph Hellwig default: 17899cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 17909cf514ccSChristoph Hellwig lrp->lr_return_type); 17919cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17929cf514ccSChristoph Hellwig break; 17939cf514ccSChristoph Hellwig } 17949cf514ccSChristoph Hellwig out: 17959cf514ccSChristoph Hellwig return nfserr; 17969cf514ccSChristoph Hellwig } 17979cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 17989cf514ccSChristoph Hellwig 17991da177e4SLinus Torvalds /* 18001da177e4SLinus Torvalds * NULL call. 18011da177e4SLinus Torvalds */ 18027111c66eSAl Viro static __be32 1803a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 18041da177e4SLinus Torvalds { 18051da177e4SLinus Torvalds return nfs_ok; 18061da177e4SLinus Torvalds } 18071da177e4SLinus Torvalds 1808e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1809e2b20950SShankar Anand { 1810e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1811e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1812e2b20950SShankar Anand } 1813e2b20950SShankar Anand 1814bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 1815b591480bSJ.Bruce Fields 1816f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1817b001a1b6SBenny Halevy 18181da177e4SLinus Torvalds /* 181957716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1820f9bb94c4SAndy Adamson * 182157716355SJ. Bruce Fields * Also note, enforced elsewhere: 182257716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 182357716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 18241d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 18251d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 182657716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 182757716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 182857716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1829f9bb94c4SAndy Adamson */ 183057716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1831f9bb94c4SAndy Adamson { 18327a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 183357716355SJ. Bruce Fields 183457716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 183557716355SJ. Bruce Fields if (args->minorversion == 0) 183657716355SJ. Bruce Fields return nfs_ok; 183757716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 183857716355SJ. Bruce Fields if (args->opcnt == 0) 183957716355SJ. Bruce Fields return nfs_ok; 18407a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 184157716355SJ. Bruce Fields return nfs_ok; 18427a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 184357716355SJ. Bruce Fields return nfserr_op_not_in_session; 18447a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 184557716355SJ. Bruce Fields return nfs_ok; 18467a04cfdaSJ. Bruce Fields /* 18477a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 18487a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 18497a04cfdaSJ. Bruce Fields * compound: 18507a04cfdaSJ. Bruce Fields */ 185157716355SJ. Bruce Fields if (args->opcnt != 1) 185257716355SJ. Bruce Fields return nfserr_not_only_op; 185357716355SJ. Bruce Fields return nfs_ok; 1854f9bb94c4SAndy Adamson } 1855f9bb94c4SAndy Adamson 1856f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 185722b03214SJ. Bruce Fields { 185822b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 185922b03214SJ. Bruce Fields } 186022b03214SJ. Bruce Fields 18611091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 18621091006cSJ. Bruce Fields { 1863e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 1864e372ba60SJ. Bruce Fields return false; 1865c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 18661091006cSJ. Bruce Fields } 18671091006cSJ. Bruce Fields 186868d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 186968d93184SJ. Bruce Fields { 187068d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 187168d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 187268d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 187368d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 1874bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 1875bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 187668d93184SJ. Bruce Fields 187768d93184SJ. Bruce Fields /* 187868d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 187968d93184SJ. Bruce Fields * have special rules. 188068d93184SJ. Bruce Fields */ 188168d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 188268d93184SJ. Bruce Fields return false; 188368d93184SJ. Bruce Fields /* 188468d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 188568d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 188668d93184SJ. Bruce Fields * result: 188768d93184SJ. Bruce Fields */ 188868d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 188968d93184SJ. Bruce Fields return false; 189051904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 189151904b08SJ. Bruce Fields return false; 189268d93184SJ. Bruce Fields nextd = OPDESC(next); 189368d93184SJ. Bruce Fields /* 189468d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 189568d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 189668d93184SJ. Bruce Fields * now: 189768d93184SJ. Bruce Fields */ 189868d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 189968d93184SJ. Bruce Fields } 190068d93184SJ. Bruce Fields 19012d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 19022d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 19032d124dfaSJ. Bruce Fields { 19042d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 19052d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 19062d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 19072d124dfaSJ. Bruce Fields 19082d124dfaSJ. Bruce Fields xdr->buf = buf; 1909ddd1ea56SJ. Bruce Fields xdr->iov = head; 19102d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 1911a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 19126ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 19136ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 19142825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 191505638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 19162825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 1917a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 19182d124dfaSJ. Bruce Fields } 19192d124dfaSJ. Bruce Fields 1920f9bb94c4SAndy Adamson /* 19211da177e4SLinus Torvalds * COMPOUND call. 19221da177e4SLinus Torvalds */ 19237111c66eSAl Viro static __be32 1924a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 19251da177e4SLinus Torvalds { 1926a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 1927a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 19281da177e4SLinus Torvalds struct nfsd4_op *op; 1929e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 19304daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 19314daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1932b37ad28bSAl Viro __be32 status; 19331da177e4SLinus Torvalds 19342d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 19354aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 19361da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 1937d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 19381da177e4SLinus Torvalds resp->taglen = args->taglen; 19391da177e4SLinus Torvalds resp->tag = args->tag; 19401da177e4SLinus Torvalds resp->rqstp = rqstp; 19414daeed25SKinglong Mee cstate->minorversion = args->minorversion; 19424daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 19434daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 19448ff30fa4SNeilBrown /* 19458ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 19468ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 19478ff30fa4SNeilBrown */ 194830660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 19491da177e4SLinus Torvalds 19501da177e4SLinus Torvalds /* 19511da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 19521da177e4SLinus Torvalds */ 19531da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 195435f7a14fSJ. Bruce Fields if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) 19551da177e4SLinus Torvalds goto out; 19560078117cSJ. Bruce Fields status = nfserr_resource; 19570078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 19580078117cSJ. Bruce Fields goto out; 19591da177e4SLinus Torvalds 196057716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 196157716355SJ. Bruce Fields if (status) { 1962f9bb94c4SAndy Adamson op = &args->ops[0]; 196357716355SJ. Bruce Fields op->status = status; 19645b7b15aeSJ. Bruce Fields resp->opcnt = 1; 1965f9bb94c4SAndy Adamson goto encode_op; 1966f9bb94c4SAndy Adamson } 1967f9bb94c4SAndy Adamson 1968fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 19691da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 19701da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 19711da177e4SLinus Torvalds 19721da177e4SLinus Torvalds /* 19731da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 19741da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 19751da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 19761da177e4SLinus Torvalds */ 19779d313b17SJ. Bruce Fields if (op->status) { 19789d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 19799d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 19801da177e4SLinus Torvalds goto encode_op; 19819d313b17SJ. Bruce Fields } 19821da177e4SLinus Torvalds 19834daeed25SKinglong Mee if (!current_fh->fh_dentry) { 1984f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 19851da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 19861da177e4SLinus Torvalds goto encode_op; 19871da177e4SLinus Torvalds } 19884daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1989f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 199042ca0993SJ.Bruce Fields op->status = nfserr_moved; 199142ca0993SJ.Bruce Fields goto encode_op; 199242ca0993SJ.Bruce Fields } 1993b591480bSJ.Bruce Fields 19942336745eSKinglong Mee fh_clear_wcc(current_fh); 19952336745eSKinglong Mee 199658e7b33aSMi Jinlong /* If op is non-idempotent */ 1997f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 19984c69d585SJ. Bruce Fields /* 1999a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2000a8095f7eSJ. Bruce Fields * succesful reply: 2001a8095f7eSJ. Bruce Fields */ 2002f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2003a8095f7eSJ. Bruce Fields /* 2004a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 20054c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 20064c69d585SJ. Bruce Fields */ 20074c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 20084c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 200958e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 201058e7b33aSMi Jinlong } 201158e7b33aSMi Jinlong 201258e7b33aSMi Jinlong if (op->status) 201358e7b33aSMi Jinlong goto encode_op; 201458e7b33aSMi Jinlong 2015f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2016f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2017f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 20181da177e4SLinus Torvalds 20199a307403SJ. Bruce Fields /* Only from SEQUENCE */ 20209a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 20219a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 20229a307403SJ. Bruce Fields status = op->status; 20239a307403SJ. Bruce Fields goto out; 20249a307403SJ. Bruce Fields } 20258b70484cSTigran Mkrtchyan if (!op->status) { 2026f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2027f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 20288b70484cSTigran Mkrtchyan 2029f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 203037c593c5STigran Mkrtchyan clear_current_stateid(cstate); 20318b70484cSTigran Mkrtchyan 20328b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 20334daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 20348b70484cSTigran Mkrtchyan } 20351da177e4SLinus Torvalds encode_op: 2036a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2037a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2038d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 20391da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 20401da177e4SLinus Torvalds } else { 20411da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 20421da177e4SLinus Torvalds status = op->status; 20431da177e4SLinus Torvalds } 20440407717dSBenny Halevy 2045fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2046fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 20470407717dSBenny Halevy 204858fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2049e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 20501da177e4SLinus Torvalds } 20511da177e4SLinus Torvalds 20524daeed25SKinglong Mee cstate->status = status; 20534daeed25SKinglong Mee fh_put(current_fh); 20544daeed25SKinglong Mee fh_put(save_fh); 20554daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 20561da177e4SLinus Torvalds out: 20572f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 205830660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 20593b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 20601da177e4SLinus Torvalds return status; 20611da177e4SLinus Torvalds } 20621da177e4SLinus Torvalds 206358e7b33aSMi Jinlong #define op_encode_hdr_size (2) 206458e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 206558e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 206658e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 206758e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 206858e7b33aSMi Jinlong 20698c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 20708c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 207158e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 207258e7b33aSMi Jinlong 207358e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 207458e7b33aSMi Jinlong 207558e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 207658e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 207758e7b33aSMi Jinlong op_encode_ace_maxsz) 207858e7b33aSMi Jinlong 207958e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 208058e7b33aSMi Jinlong 208158e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 208258e7b33aSMi Jinlong { 208358e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 208458e7b33aSMi Jinlong } 208558e7b33aSMi Jinlong 208658e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 208758e7b33aSMi Jinlong { 208858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 208958e7b33aSMi Jinlong } 209058e7b33aSMi Jinlong 20912282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20922282cd2cSKinglong Mee { 20932282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 20942282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 20952282cd2cSKinglong Mee } 20962282cd2cSKinglong Mee 209758e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 209858e7b33aSMi Jinlong { 209958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 210058e7b33aSMi Jinlong } 210158e7b33aSMi Jinlong 210258e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 210358e7b33aSMi Jinlong { 210458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 210558e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 210658e7b33aSMi Jinlong } 210758e7b33aSMi Jinlong 2108b86cef60SJ. Bruce Fields /* 2109b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2110b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2111b86cef60SJ. Bruce Fields * reads unnecessarily. 2112b86cef60SJ. Bruce Fields */ 2113b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2114b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2115b86cef60SJ. Bruce Fields { 2116b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2117b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2118b86cef60SJ. Bruce Fields u32 ret = 0; 2119b86cef60SJ. Bruce Fields 2120b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2121b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2122b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2123b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2124b86cef60SJ. Bruce Fields 2125b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2126b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2127b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2128b86cef60SJ. Bruce Fields } 2129b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2130b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2131b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2132b86cef60SJ. Bruce Fields } 2133b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2134b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2135b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2136b86cef60SJ. Bruce Fields } 2137b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 21381ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2139b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2140b86cef60SJ. Bruce Fields } 2141b86cef60SJ. Bruce Fields /* 2142b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2143b86cef60SJ. Bruce Fields * supported_attributes) 2144b86cef60SJ. Bruce Fields */ 2145b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2146b86cef60SJ. Bruce Fields /* bitmask, length */ 2147b86cef60SJ. Bruce Fields ret += 20; 2148b86cef60SJ. Bruce Fields return ret; 2149b86cef60SJ. Bruce Fields } 2150b86cef60SJ. Bruce Fields 21512282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 21522282cd2cSKinglong Mee { 21532282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 21542282cd2cSKinglong Mee } 21552282cd2cSKinglong Mee 215658e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 215758e7b33aSMi Jinlong { 215858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 215958e7b33aSMi Jinlong * sizeof(__be32); 216058e7b33aSMi Jinlong } 216158e7b33aSMi Jinlong 216258e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 216358e7b33aSMi Jinlong { 216458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 216558e7b33aSMi Jinlong * sizeof(__be32); 216658e7b33aSMi Jinlong } 216758e7b33aSMi Jinlong 216858e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 216958e7b33aSMi Jinlong { 217058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 217158e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 217258e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 217358e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 217458e7b33aSMi Jinlong } 217558e7b33aSMi Jinlong 217658e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 217758e7b33aSMi Jinlong { 217858e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 217958e7b33aSMi Jinlong 218058e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 21813c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 218258e7b33aSMi Jinlong 2183622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 218458e7b33aSMi Jinlong } 218558e7b33aSMi Jinlong 218658e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 218758e7b33aSMi Jinlong { 21883c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 218958e7b33aSMi Jinlong 21903c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 21913c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 219258e7b33aSMi Jinlong 2193561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2194561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 219558e7b33aSMi Jinlong } 219658e7b33aSMi Jinlong 21972282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 21982282cd2cSKinglong Mee { 21992282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 22002282cd2cSKinglong Mee } 22012282cd2cSKinglong Mee 220258e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 220358e7b33aSMi Jinlong { 220458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 220558e7b33aSMi Jinlong * sizeof(__be32); 220658e7b33aSMi Jinlong } 220758e7b33aSMi Jinlong 220858e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 220958e7b33aSMi Jinlong { 221058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 221158e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 221258e7b33aSMi Jinlong } 221358e7b33aSMi Jinlong 2214ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2215ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2216ccae70a9SJ. Bruce Fields { 2217d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2218d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2219ccae70a9SJ. Bruce Fields } 2220ccae70a9SJ. Bruce Fields 22212282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22222282cd2cSKinglong Mee { 22232282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 22242282cd2cSKinglong Mee * sizeof(__be32); 22252282cd2cSKinglong Mee } 22262282cd2cSKinglong Mee 222758e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 222858e7b33aSMi Jinlong { 222958e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 223058e7b33aSMi Jinlong } 223158e7b33aSMi Jinlong 22322282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22332282cd2cSKinglong Mee { 22342282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 22352282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 22362282cd2cSKinglong Mee } 22372282cd2cSKinglong Mee 223858e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 223958e7b33aSMi Jinlong { 2240480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2241480efaeeSJ. Bruce Fields sizeof(__be32); 224258e7b33aSMi Jinlong } 224358e7b33aSMi Jinlong 224458e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 224558e7b33aSMi Jinlong { 2246f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 224758e7b33aSMi Jinlong } 224858e7b33aSMi Jinlong 224958e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 225058e7b33aSMi Jinlong { 225158e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2252a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2253a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 225458e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 225558e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 225658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 225758e7b33aSMi Jinlong /* eir_server_scope<> */\ 225858e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 225958e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 226058e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 226158e7b33aSMi Jinlong } 226258e7b33aSMi Jinlong 226358e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 226458e7b33aSMi Jinlong { 226558e7b33aSMi Jinlong return (op_encode_hdr_size + \ 226658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 226758e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 226858e7b33aSMi Jinlong } 226958e7b33aSMi Jinlong 227058e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 227158e7b33aSMi Jinlong { 227258e7b33aSMi Jinlong return (op_encode_hdr_size + \ 227358e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 227458e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 227558e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 227658e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 227758e7b33aSMi Jinlong } 227858e7b33aSMi Jinlong 227929ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 228029ae7f9dSAnna Schumaker { 228129ae7f9dSAnna Schumaker return (op_encode_hdr_size + 228229ae7f9dSAnna Schumaker 1 /* wr_callback */ + 228329ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 228429ae7f9dSAnna Schumaker 2 /* wr_count */ + 228529ae7f9dSAnna Schumaker 1 /* wr_committed */ + 228629ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 228729ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 228829ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 228929ae7f9dSAnna Schumaker } 229029ae7f9dSAnna Schumaker 22916308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 22926308bc98SOlga Kornievskaia struct nfsd4_op *op) 22936308bc98SOlga Kornievskaia { 22946308bc98SOlga Kornievskaia return (op_encode_hdr_size + 22956308bc98SOlga Kornievskaia 2 /* osr_count */ + 22966308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 22976308bc98SOlga Kornievskaia } 22986308bc98SOlga Kornievskaia 22999cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 23002282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23012282cd2cSKinglong Mee { 23022282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 23032282cd2cSKinglong Mee 23042282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 23052282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 23062282cd2cSKinglong Mee 23072282cd2cSKinglong Mee return (op_encode_hdr_size + 23082282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 23092282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 23102282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 23112282cd2cSKinglong Mee } 23122282cd2cSKinglong Mee 23139cf514ccSChristoph Hellwig /* 23149cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 23159cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 23169cf514ccSChristoph Hellwig */ 23179cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 23189cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23199cf514ccSChristoph Hellwig { 23209cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23219cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 23229cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 23239cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 23249cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 23259cf514ccSChristoph Hellwig } 23269cf514ccSChristoph Hellwig 23279cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23289cf514ccSChristoph Hellwig { 23299cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23309cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 23319cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 23329cf514ccSChristoph Hellwig } 23339cf514ccSChristoph Hellwig 23349cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23359cf514ccSChristoph Hellwig { 23369cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23379cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 23389cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 23399cf514ccSChristoph Hellwig } 23409cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 23419cf514ccSChristoph Hellwig 23422282cd2cSKinglong Mee 23432282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23442282cd2cSKinglong Mee { 23452282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 23462282cd2cSKinglong Mee } 23472282cd2cSKinglong Mee 2348bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2349b591480bSJ.Bruce Fields [OP_ACCESS] = { 2350eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2351b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 23521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2353b591480bSJ.Bruce Fields }, 2354b591480bSJ.Bruce Fields [OP_CLOSE] = { 2355eb69853dSChristoph Hellwig .op_func = nfsd4_close, 235658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2357b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 23581c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 235957832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2360b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2361b591480bSJ.Bruce Fields }, 2362b591480bSJ.Bruce Fields [OP_COMMIT] = { 2363eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 236458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2365b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 23661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2367b591480bSJ.Bruce Fields }, 2368b591480bSJ.Bruce Fields [OP_CREATE] = { 2369eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2370d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2371b001a1b6SBenny Halevy .op_name = "OP_CREATE", 23721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2373b591480bSJ.Bruce Fields }, 2374b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2375eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 237658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2377b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 237858e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 237957832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2380b591480bSJ.Bruce Fields }, 2381b591480bSJ.Bruce Fields [OP_GETATTR] = { 2382eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2383eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2384b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2385b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2386b591480bSJ.Bruce Fields }, 2387b591480bSJ.Bruce Fields [OP_GETFH] = { 2388eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2389b001a1b6SBenny Halevy .op_name = "OP_GETFH", 23901c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2391b591480bSJ.Bruce Fields }, 2392b591480bSJ.Bruce Fields [OP_LINK] = { 2393eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2394c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2395c856694eSJ. Bruce Fields | OP_CACHEME, 2396b001a1b6SBenny Halevy .op_name = "OP_LINK", 23971c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 2398b591480bSJ.Bruce Fields }, 2399b591480bSJ.Bruce Fields [OP_LOCK] = { 2400eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 2401b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 2402b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 2403b001a1b6SBenny Halevy .op_name = "OP_LOCK", 24041c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2405b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 2406b591480bSJ.Bruce Fields }, 2407b591480bSJ.Bruce Fields [OP_LOCKT] = { 2408eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 2409b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 2410b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 24111c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2412b591480bSJ.Bruce Fields }, 2413b591480bSJ.Bruce Fields [OP_LOCKU] = { 2414eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 241558e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2416b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 24171c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 241857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 2419b591480bSJ.Bruce Fields }, 2420b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2421eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 2422d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2423b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 24241c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2425b591480bSJ.Bruce Fields }, 2426b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2427eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 2428d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2429b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 24301c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2431b591480bSJ.Bruce Fields }, 2432b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2433eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 2434b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 24351c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2436b591480bSJ.Bruce Fields }, 2437b591480bSJ.Bruce Fields [OP_OPEN] = { 2438eb69853dSChristoph Hellwig .op_func = nfsd4_open, 243958e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2440b001a1b6SBenny Halevy .op_name = "OP_OPEN", 24411c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 2442b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 2443b591480bSJ.Bruce Fields }, 2444b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2445eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 244658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2447b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 24481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 2449b591480bSJ.Bruce Fields }, 2450b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2451eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 245258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2453b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 24541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 245557832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 2456b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 2457b591480bSJ.Bruce Fields }, 2458b591480bSJ.Bruce Fields [OP_PUTFH] = { 2459eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 246068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24615b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2462b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 24631c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2464b591480bSJ.Bruce Fields }, 2465eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2466eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 246768d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24685b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2469b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 24701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2471eeac294eSJ.Bruce Fields }, 2472b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2473eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 247468d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24755b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2476b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 24771c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2478b591480bSJ.Bruce Fields }, 2479b591480bSJ.Bruce Fields [OP_READ] = { 2480eb69853dSChristoph Hellwig .op_func = nfsd4_read, 248134b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 2482b001a1b6SBenny Halevy .op_name = "OP_READ", 24831c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 248457832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 2485b591480bSJ.Bruce Fields }, 2486b591480bSJ.Bruce Fields [OP_READDIR] = { 2487eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 2488b001a1b6SBenny Halevy .op_name = "OP_READDIR", 24891c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 2490b591480bSJ.Bruce Fields }, 2491b591480bSJ.Bruce Fields [OP_READLINK] = { 2492eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 2493b001a1b6SBenny Halevy .op_name = "OP_READLINK", 24941c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 2495b591480bSJ.Bruce Fields }, 2496b591480bSJ.Bruce Fields [OP_REMOVE] = { 2497eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 2498c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2499b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 25001c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 2501b591480bSJ.Bruce Fields }, 2502b591480bSJ.Bruce Fields [OP_RENAME] = { 2503eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 2504c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 250558e7b33aSMi Jinlong .op_name = "OP_RENAME", 25061c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 2507b591480bSJ.Bruce Fields }, 2508b591480bSJ.Bruce Fields [OP_RENEW] = { 2509eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 251058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 251158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2512b001a1b6SBenny Halevy .op_name = "OP_RENEW", 25131c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 251458e7b33aSMi Jinlong 2515b591480bSJ.Bruce Fields }, 2516b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2517eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 251868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 251958e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2520b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 25211c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2522b591480bSJ.Bruce Fields }, 2523b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2524eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 252558e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2526b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 25271c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2528b591480bSJ.Bruce Fields }, 2529dcb488a3SAndy Adamson [OP_SECINFO] = { 2530eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 253134b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 253268d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2533b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 25341c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 2535dcb488a3SAndy Adamson }, 2536b591480bSJ.Bruce Fields [OP_SETATTR] = { 2537eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 2538b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2539b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 2540b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 25411c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 254257832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 2543b591480bSJ.Bruce Fields }, 2544b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2545eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 254658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2547b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 2548b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 2549b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 25501c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 2551b591480bSJ.Bruce Fields }, 2552b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2553eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 255458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2555c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2556b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 25571c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2558b591480bSJ.Bruce Fields }, 2559b591480bSJ.Bruce Fields [OP_VERIFY] = { 2560eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 2561b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 25621c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2563b591480bSJ.Bruce Fields }, 2564b591480bSJ.Bruce Fields [OP_WRITE] = { 2565eb69853dSChristoph Hellwig .op_func = nfsd4_write, 2566c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2567b001a1b6SBenny Halevy .op_name = "OP_WRITE", 25681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 256957832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 2570b591480bSJ.Bruce Fields }, 2571b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2572eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 257358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 257458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2575b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 25761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2577b591480bSJ.Bruce Fields }, 2578069b6ad4SAndy Adamson 2579069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2580069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2581eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 258258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 258358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2584069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 25851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 2586069b6ad4SAndy Adamson }, 2587cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2588eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 2589cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2590cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 25911c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2592cb73a9f4SJ. Bruce Fields }, 25931d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 2594eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 259558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 259658e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 25971d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 25981c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 25991d1bc8f2SJ. Bruce Fields }, 2600069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2601eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 260258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 260358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2604069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 26051c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 2606069b6ad4SAndy Adamson }, 2607069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2608eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 260958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 261058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2611069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 26121c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2613069b6ad4SAndy Adamson }, 2614069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2615eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 2616f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2617069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 26181c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 2619069b6ad4SAndy Adamson }, 2620094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2621eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 262258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 262358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2624094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 26251c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2626094b5d74SBenny Halevy }, 26274dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 2628eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 262958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 26304dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 26311c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 26324dc6ec00SJ. Bruce Fields }, 263304f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 2634eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 2635ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 263668d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 263704f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 26381c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 263904f4ad16SJ. Bruce Fields }, 264017456804SBryan Schumaker [OP_TEST_STATEID] = { 2641eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 264217456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 264317456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 26441c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 264517456804SBryan Schumaker }, 2646e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 2647eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 264858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2649e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 265057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 26511c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2652e1ca12dfSBryan Schumaker }, 26539cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 26549cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 2655eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 265634b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 26579cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 26589cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 26591c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 26609cf514ccSChristoph Hellwig }, 26619cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 2662eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 266334b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 26649cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26659cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 26661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 26679cf514ccSChristoph Hellwig }, 26689cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 2669eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 26709cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26719cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 26721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 26739cf514ccSChristoph Hellwig }, 26749cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 2675eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 26769cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26779cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 26781c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 26799cf514ccSChristoph Hellwig }, 26809cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 268124bab491SAnna Schumaker 268224bab491SAnna Schumaker /* NFSv4.2 operations */ 268395d871f0SAnna Schumaker [OP_ALLOCATE] = { 2684eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 268595d871f0SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 268695d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 26871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 268895d871f0SAnna Schumaker }, 2689b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 2690eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 2691b0cb9085SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2692b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 26931c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2694b0cb9085SAnna Schumaker }, 2695ffa0160aSChristoph Hellwig [OP_CLONE] = { 2696eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 2697ffa0160aSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2698ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 26991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2700ffa0160aSChristoph Hellwig }, 270129ae7f9dSAnna Schumaker [OP_COPY] = { 2702eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 270329ae7f9dSAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 270429ae7f9dSAnna Schumaker .op_name = "OP_COPY", 27051c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 270629ae7f9dSAnna Schumaker }, 270724bab491SAnna Schumaker [OP_SEEK] = { 2708eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 270924bab491SAnna Schumaker .op_name = "OP_SEEK", 27101c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 271124bab491SAnna Schumaker }, 27126308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 27136308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 27146308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 27156308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 27166308bc98SOlga Kornievskaia }, 2717885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 2718885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 2719885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2720885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 2721885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 2722885e2bf3SOlga Kornievskaia }, 2723b591480bSJ.Bruce Fields }; 2724b591480bSJ.Bruce Fields 2725ed941643SAndrew Elble /** 2726ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 2727ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 2728ed941643SAndrew Elble * 2729ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 2730ed941643SAndrew Elble * 2731ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 2732ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 2733ed941643SAndrew Elble */ 2734ed941643SAndrew Elble 2735ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 2736ed941643SAndrew Elble { 2737ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 2738ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 2739ed941643SAndrew Elble struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 2740ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 2741ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 2742ed941643SAndrew Elble u32 opiter; 2743ed941643SAndrew Elble 2744ed941643SAndrew Elble if (!cstate->minorversion) 2745ed941643SAndrew Elble return false; 2746ed941643SAndrew Elble 2747ed941643SAndrew Elble if (cstate->spo_must_allowed == true) 2748ed941643SAndrew Elble return true; 2749ed941643SAndrew Elble 2750ed941643SAndrew Elble opiter = resp->opcnt; 2751ed941643SAndrew Elble while (opiter < argp->opcnt) { 2752ed941643SAndrew Elble this = &argp->ops[opiter++]; 2753ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 2754ed941643SAndrew Elble cstate->clp->cl_mach_cred && 2755ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 2756ed941643SAndrew Elble cstate->spo_must_allowed = true; 2757ed941643SAndrew Elble return true; 2758ed941643SAndrew Elble } 2759ed941643SAndrew Elble } 2760ed941643SAndrew Elble cstate->spo_must_allowed = false; 2761ed941643SAndrew Elble return false; 2762ed941643SAndrew Elble } 2763ed941643SAndrew Elble 27644f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 27654f0cefbfSJ. Bruce Fields { 276605b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 27674f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 27682282cd2cSKinglong Mee 27692282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 27702282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 27714f0cefbfSJ. Bruce Fields } 27724f0cefbfSJ. Bruce Fields 277307d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 277407d1f802SJ. Bruce Fields { 277507d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 277607d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 277707d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 277807d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 277907d1f802SJ. Bruce Fields } 278007d1f802SJ. Bruce Fields } 278107d1f802SJ. Bruce Fields 2782f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 2783b001a1b6SBenny Halevy { 2784b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 2785b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 2786b001a1b6SBenny Halevy return "unknown_operation"; 2787b001a1b6SBenny Halevy } 2788b001a1b6SBenny Halevy 27891da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 27901da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 27911da177e4SLinus Torvalds 2792860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 27930a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 2794f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 279563f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_voidres, 27960a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 27970a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 27980a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 27990a93a47fSYu Zhiguo .pc_xdrressize = 1, 28000a93a47fSYu Zhiguo }, 28010a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 2802f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 2803026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 280463f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 28050a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 28060a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 28073e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 28080a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 28090a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 28100a93a47fSYu Zhiguo }, 28111da177e4SLinus Torvalds }; 28121da177e4SLinus Torvalds 28137fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 2814e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 28151da177e4SLinus Torvalds .vs_vers = 4, 28161da177e4SLinus Torvalds .vs_nproc = 2, 28171da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 28187fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 28191da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 28201da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 282105a45a2dSJeff Layton .vs_rpcb_optnl = true, 28225283b03eSJeff Layton .vs_need_cong_ctrl = true, 28231da177e4SLinus Torvalds }; 28241da177e4SLinus Torvalds 28251da177e4SLinus Torvalds /* 28261da177e4SLinus Torvalds * Local variables: 28271da177e4SLinus Torvalds * c-basic-offset: 8 28281da177e4SLinus Torvalds * End: 28291da177e4SLinus Torvalds */ 2830