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; 430*0a4c9265SGustavo A. R. Silva /* fall through */ 4318b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4328b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 433bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4341da177e4SLinus Torvalds if (status) 4351da177e4SLinus Torvalds goto out; 436c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4371da177e4SLinus Torvalds break; 4388b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4391da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4402fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4411da177e4SLinus Torvalds open->op_claim_type); 4421da177e4SLinus Torvalds status = nfserr_notsupp; 4431da177e4SLinus Torvalds goto out; 4441da177e4SLinus Torvalds default: 4452fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4461da177e4SLinus Torvalds open->op_claim_type); 4471da177e4SLinus Torvalds status = nfserr_inval; 4481da177e4SLinus Torvalds goto out; 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds /* 4511da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4521da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4531da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4541da177e4SLinus Torvalds */ 455c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 456b3fbfe0eSJeff Layton WARN(status && open->op_created, 457b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 458b3fbfe0eSJeff Layton be32_to_cpu(status)); 45903f318caSJ. Bruce Fields if (reclaim && !status) 46003f318caSJ. Bruce Fields nn->somebody_reclaimed = true; 4611da177e4SLinus Torvalds out: 462c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 463c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 464c0e6bee4SJ. Bruce Fields fh_put(resfh); 465c0e6bee4SJ. Bruce Fields kfree(resfh); 466c0e6bee4SJ. Bruce Fields } 46742297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4689411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4691da177e4SLinus Torvalds return status; 4701da177e4SLinus Torvalds } 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds /* 4739d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4749d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4759d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4769d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4779d313b17SJ. Bruce Fields */ 4789d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4799d313b17SJ. Bruce Fields { 480eb69853dSChristoph Hellwig struct nfsd4_open *open = &op->u.open; 4819d313b17SJ. Bruce Fields 4829d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4839d313b17SJ. Bruce Fields return op->status; 4849d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4859d313b17SJ. Bruce Fields return op->status; 4869d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 487eb69853dSChristoph Hellwig return nfsd4_open(rqstp, cstate, &op->u); 4889d313b17SJ. Bruce Fields } 4899d313b17SJ. Bruce Fields 4909d313b17SJ. Bruce Fields /* 4911da177e4SLinus Torvalds * filehandle-manipulating ops. 4921da177e4SLinus Torvalds */ 4937191155bSJ.Bruce Fields static __be32 494b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 495eb69853dSChristoph Hellwig union nfsd4_op_u *u) 4961da177e4SLinus Torvalds { 497eb69853dSChristoph Hellwig u->getfh = &cstate->current_fh; 4981da177e4SLinus Torvalds return nfs_ok; 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds 5017191155bSJ.Bruce Fields static __be32 502ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 503eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5041da177e4SLinus Torvalds { 505eb69853dSChristoph Hellwig struct nfsd4_putfh *putfh = &u->putfh; 506eb69853dSChristoph Hellwig 507ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 508ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 509ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 510ca364317SJ.Bruce Fields putfh->pf_fhlen); 51168d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds 5147191155bSJ.Bruce Fields static __be32 515b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 516eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5171da177e4SLinus Torvalds { 518b37ad28bSAl Viro __be32 status; 5191da177e4SLinus Torvalds 520ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 521df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5221da177e4SLinus Torvalds return status; 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds 5257191155bSJ.Bruce Fields static __be32 526b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 527eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5281da177e4SLinus Torvalds { 529ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5301da177e4SLinus Torvalds return nfserr_restorefh; 5311da177e4SLinus Torvalds 532ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 53337c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 53437c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 53537c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 53637c593c5STigran Mkrtchyan } 5371da177e4SLinus Torvalds return nfs_ok; 5381da177e4SLinus Torvalds } 5391da177e4SLinus Torvalds 5407191155bSJ.Bruce Fields static __be32 541b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 542eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5431da177e4SLinus Torvalds { 544ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 54537c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 54637c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 54737c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 54837c593c5STigran Mkrtchyan } 5491da177e4SLinus Torvalds return nfs_ok; 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds /* 5531da177e4SLinus Torvalds * misc nfsv4 ops 5541da177e4SLinus Torvalds */ 5557191155bSJ.Bruce Fields static __be32 556ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 557eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5581da177e4SLinus Torvalds { 559eb69853dSChristoph Hellwig struct nfsd4_access *access = &u->access; 560eb69853dSChristoph Hellwig 5611da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5621da177e4SLinus Torvalds return nfserr_inval; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 565ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 566ca364317SJ.Bruce Fields &access->ac_supported); 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds 569b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 570ab4684d1SChuck Lever { 571ab4684d1SChuck Lever __be32 verf[2]; 572b9c0ef85SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 573ab4684d1SChuck Lever 574f419992cSJeff Layton /* 575f419992cSJeff Layton * This is opaque to client, so no need to byte-swap. Use 576256a89faSArnd Bergmann * __force to keep sparse happy. y2038 time_t overflow is 577256a89faSArnd Bergmann * irrelevant in this usage. 578f419992cSJeff Layton */ 579f419992cSJeff Layton verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; 580256a89faSArnd Bergmann verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec; 581ab4684d1SChuck Lever memcpy(verifier->data, verf, sizeof(verifier->data)); 582ab4684d1SChuck Lever } 583ab4684d1SChuck Lever 5847191155bSJ.Bruce Fields static __be32 585ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 586eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5871da177e4SLinus Torvalds { 588eb69853dSChristoph Hellwig struct nfsd4_commit *commit = &u->commit; 589eb69853dSChristoph Hellwig 590b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 59175c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 592ca364317SJ.Bruce Fields commit->co_count); 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds 595b37ad28bSAl Viro static __be32 596ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 597eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5981da177e4SLinus Torvalds { 599eb69853dSChristoph Hellwig struct nfsd4_create *create = &u->create; 6001da177e4SLinus Torvalds struct svc_fh resfh; 601b37ad28bSAl Viro __be32 status; 6021da177e4SLinus Torvalds dev_t rdev; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6051da177e4SLinus Torvalds 606fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 6071da177e4SLinus Torvalds if (status) 6081da177e4SLinus Torvalds return status; 6091da177e4SLinus Torvalds 6103c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6113c8e0316SYu Zhiguo nfsd_attrmask); 6123c8e0316SYu Zhiguo if (status) 6133c8e0316SYu Zhiguo return status; 6143c8e0316SYu Zhiguo 615880a3a53SJ. Bruce Fields current->fs->umask = create->cr_umask; 6161da177e4SLinus Torvalds switch (create->cr_type) { 6171da177e4SLinus Torvalds case NF4LNK: 618ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 619ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6201e444f5bSKinglong Mee create->cr_data, &resfh); 6211da177e4SLinus Torvalds break; 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds case NF4BLK: 624880a3a53SJ. Bruce Fields status = nfserr_inval; 6251da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6261da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6271da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 628880a3a53SJ. Bruce Fields goto out_umask; 629ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 630ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 631ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6321da177e4SLinus Torvalds break; 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds case NF4CHR: 635880a3a53SJ. Bruce Fields status = nfserr_inval; 6361da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6371da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6381da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 639880a3a53SJ. Bruce Fields goto out_umask; 640ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 641ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 642ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6431da177e4SLinus Torvalds break; 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds case NF4SOCK: 646ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 647ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 648ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6491da177e4SLinus Torvalds break; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds case NF4FIFO: 652ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 653ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 654ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6551da177e4SLinus Torvalds break; 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds case NF4DIR: 6581da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 659ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 660ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 661ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6621da177e4SLinus Torvalds break; 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds default: 6651da177e4SLinus Torvalds status = nfserr_badtype; 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds 6689208faf2SYu Zhiguo if (status) 6699208faf2SYu Zhiguo goto out; 6709208faf2SYu Zhiguo 67118032ca0SDavid Quigley if (create->cr_label.len) 67218032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 67318032ca0SDavid Quigley 6749208faf2SYu Zhiguo if (create->cr_acl != NULL) 6759208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6769208faf2SYu Zhiguo create->cr_bmval); 6779208faf2SYu Zhiguo 678ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 679ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 680ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6819208faf2SYu Zhiguo out: 6821da177e4SLinus Torvalds fh_put(&resfh); 683880a3a53SJ. Bruce Fields out_umask: 684880a3a53SJ. Bruce Fields current->fs->umask = 0; 6851da177e4SLinus Torvalds return status; 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds 6887191155bSJ.Bruce Fields static __be32 689ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 690eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6911da177e4SLinus Torvalds { 692eb69853dSChristoph Hellwig struct nfsd4_getattr *getattr = &u->getattr; 693b37ad28bSAl Viro __be32 status; 6941da177e4SLinus Torvalds 6958837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 6961da177e4SLinus Torvalds if (status) 6971da177e4SLinus Torvalds return status; 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 7001da177e4SLinus Torvalds return nfserr_inval; 7011da177e4SLinus Torvalds 702916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 703916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 704916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 7051da177e4SLinus Torvalds 706ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7071da177e4SLinus Torvalds return nfs_ok; 7081da177e4SLinus Torvalds } 7091da177e4SLinus Torvalds 7107191155bSJ.Bruce Fields static __be32 711ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 712eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7131da177e4SLinus Torvalds { 714eb69853dSChristoph Hellwig struct nfsd4_link *link = &u->link; 71595424460SJ. Bruce Fields __be32 status; 7161da177e4SLinus Torvalds 717ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 718ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7191da177e4SLinus Torvalds if (!status) 720ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7211da177e4SLinus Torvalds return status; 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds 7240ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7251da177e4SLinus Torvalds { 7261da177e4SLinus Torvalds struct svc_fh tmp_fh; 727b37ad28bSAl Viro __be32 ret; 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 730df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 731df547efbSJ. Bruce Fields if (ret) 7321da177e4SLinus Torvalds return ret; 7330ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7341da177e4SLinus Torvalds fh_put(&tmp_fh); 7351da177e4SLinus Torvalds return nfserr_noent; 7361da177e4SLinus Torvalds } 7371da177e4SLinus Torvalds fh_put(&tmp_fh); 7380ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7390ff7ab46SJ. Bruce Fields } 7400ff7ab46SJ. Bruce Fields 7410ff7ab46SJ. Bruce Fields static __be32 7420ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 743eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7440ff7ab46SJ. Bruce Fields { 7450ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds 7487191155bSJ.Bruce Fields static __be32 749ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 750eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7511da177e4SLinus Torvalds { 752ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 753eb69853dSChristoph Hellwig u->lookup.lo_name, u->lookup.lo_len, 754ca364317SJ.Bruce Fields &cstate->current_fh); 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds 7577191155bSJ.Bruce Fields static __be32 758ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 759eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7601da177e4SLinus Torvalds { 761eb69853dSChristoph Hellwig struct nfsd4_read *read = &u->read; 762b37ad28bSAl Viro __be32 status; 7631da177e4SLinus Torvalds 7647e06b7f9SNeilBrown read->rd_filp = NULL; 7651da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7661da177e4SLinus Torvalds return nfserr_inval; 7671da177e4SLinus Torvalds 76887c5942eSChuck Lever trace_nfsd_read_start(rqstp, &cstate->current_fh, 76987c5942eSChuck Lever read->rd_offset, read->rd_length); 77087c5942eSChuck Lever 7719b3234b9SJ. Bruce Fields /* 7729b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7739b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7749b3234b9SJ. Bruce Fields * following compound. 7759b3234b9SJ. Bruce Fields * 7769b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7779b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7789b3234b9SJ. Bruce Fields */ 7799b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 780779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 7819b3234b9SJ. Bruce Fields 7821da177e4SLinus Torvalds /* check stateid */ 783aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 784aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 785aa0d6aedSAnna Schumaker &read->rd_filp, &read->rd_tmp_file); 786af90f707SChristoph Hellwig if (status) { 7871da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7881da177e4SLinus Torvalds goto out; 7891da177e4SLinus Torvalds } 7901da177e4SLinus Torvalds status = nfs_ok; 7911da177e4SLinus Torvalds out: 7921da177e4SLinus Torvalds read->rd_rqstp = rqstp; 793ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 7941da177e4SLinus Torvalds return status; 7951da177e4SLinus Torvalds } 7961da177e4SLinus Torvalds 79734b1744cSJ. Bruce Fields 79834b1744cSJ. Bruce Fields static void 79934b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u) 80034b1744cSJ. Bruce Fields { 80134b1744cSJ. Bruce Fields if (u->read.rd_filp) 80234b1744cSJ. Bruce Fields fput(u->read.rd_filp); 80387c5942eSChuck Lever trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, 80487c5942eSChuck Lever u->read.rd_offset, u->read.rd_length); 80534b1744cSJ. Bruce Fields } 80634b1744cSJ. Bruce Fields 8077191155bSJ.Bruce Fields static __be32 808ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 809eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8101da177e4SLinus Torvalds { 811eb69853dSChristoph Hellwig struct nfsd4_readdir *readdir = &u->readdir; 8121da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 8131da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8161da177e4SLinus Torvalds 8171da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8181da177e4SLinus Torvalds return nfserr_inval; 8191da177e4SLinus Torvalds 820916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 821916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 822916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 8231da177e4SLinus Torvalds 824832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8251da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8261da177e4SLinus Torvalds return nfserr_bad_cookie; 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 829ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8301da177e4SLinus Torvalds return nfs_ok; 8311da177e4SLinus Torvalds } 8321da177e4SLinus Torvalds 8337191155bSJ.Bruce Fields static __be32 834ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 835eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8361da177e4SLinus Torvalds { 837eb69853dSChristoph Hellwig u->readlink.rl_rqstp = rqstp; 838eb69853dSChristoph Hellwig u->readlink.rl_fhp = &cstate->current_fh; 8391da177e4SLinus Torvalds return nfs_ok; 8401da177e4SLinus Torvalds } 8411da177e4SLinus Torvalds 8427191155bSJ.Bruce Fields static __be32 843ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 844eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8451da177e4SLinus Torvalds { 846eb69853dSChristoph Hellwig struct nfsd4_remove *remove = &u->remove; 847b37ad28bSAl Viro __be32 status; 8481da177e4SLinus Torvalds 849c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 850c815afc7SNeilBrown return nfserr_grace; 851ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 852ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8531da177e4SLinus Torvalds if (!status) { 854ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 855ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8561da177e4SLinus Torvalds } 8571da177e4SLinus Torvalds return status; 8581da177e4SLinus Torvalds } 8591da177e4SLinus Torvalds 8607191155bSJ.Bruce Fields static __be32 861ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 862eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8631da177e4SLinus Torvalds { 864eb69853dSChristoph Hellwig struct nfsd4_rename *rename = &u->rename; 86595424460SJ. Bruce Fields __be32 status; 8661da177e4SLinus Torvalds 867f8f71d00SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 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); 1019ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1020ffe1137bSJ. Bruce Fields 1021af90f707SChristoph Hellwig status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp, 1022af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 102354bbb7d2SKinglong Mee write->wr_how_written); 10247e06b7f9SNeilBrown fput(filp); 10251da177e4SLinus Torvalds 102631dec253SDavid Shaw write->wr_bytes_written = cnt; 1027d890be15SChuck Lever trace_nfsd_write_done(rqstp, &cstate->current_fh, 1028d890be15SChuck Lever write->wr_offset, cnt); 10291da177e4SLinus Torvalds return status; 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds 103224bab491SAnna Schumaker static __be32 103329ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 103429ae7f9dSAnna Schumaker stateid_t *src_stateid, struct file **src, 103529ae7f9dSAnna Schumaker stateid_t *dst_stateid, struct file **dst) 1036ffa0160aSChristoph Hellwig { 1037ffa0160aSChristoph Hellwig __be32 status; 1038ffa0160aSChristoph Hellwig 103901310bb7SScott Mayhew if (!cstate->save_fh.fh_dentry) 104001310bb7SScott Mayhew return nfserr_nofilehandle; 104101310bb7SScott Mayhew 1042ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 104329ae7f9dSAnna Schumaker src_stateid, RD_STATE, src, NULL); 1044ffa0160aSChristoph Hellwig if (status) { 1045ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1046ffa0160aSChristoph Hellwig goto out; 1047ffa0160aSChristoph Hellwig } 1048ffa0160aSChristoph Hellwig 1049ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 105029ae7f9dSAnna Schumaker dst_stateid, WR_STATE, dst, NULL); 1051ffa0160aSChristoph Hellwig if (status) { 1052ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1053ffa0160aSChristoph Hellwig goto out_put_src; 1054ffa0160aSChristoph Hellwig } 1055ffa0160aSChristoph Hellwig 1056ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 105729ae7f9dSAnna Schumaker if (!S_ISREG(file_inode(*src)->i_mode) || 105829ae7f9dSAnna Schumaker !S_ISREG(file_inode(*dst)->i_mode)) { 1059ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1060ffa0160aSChristoph Hellwig goto out_put_dst; 1061ffa0160aSChristoph Hellwig } 1062ffa0160aSChristoph Hellwig 106329ae7f9dSAnna Schumaker out: 106429ae7f9dSAnna Schumaker return status; 106529ae7f9dSAnna Schumaker out_put_dst: 106629ae7f9dSAnna Schumaker fput(*dst); 106729ae7f9dSAnna Schumaker out_put_src: 106829ae7f9dSAnna Schumaker fput(*src); 106929ae7f9dSAnna Schumaker goto out; 107029ae7f9dSAnna Schumaker } 107129ae7f9dSAnna Schumaker 107229ae7f9dSAnna Schumaker static __be32 107329ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1074eb69853dSChristoph Hellwig union nfsd4_op_u *u) 107529ae7f9dSAnna Schumaker { 1076eb69853dSChristoph Hellwig struct nfsd4_clone *clone = &u->clone; 107729ae7f9dSAnna Schumaker struct file *src, *dst; 107829ae7f9dSAnna Schumaker __be32 status; 107929ae7f9dSAnna Schumaker 108029ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 108129ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 108229ae7f9dSAnna Schumaker if (status) 108329ae7f9dSAnna Schumaker goto out; 108429ae7f9dSAnna Schumaker 1085ffa0160aSChristoph Hellwig status = nfsd4_clone_file_range(src, clone->cl_src_pos, 1086ffa0160aSChristoph Hellwig dst, clone->cl_dst_pos, clone->cl_count); 1087ffa0160aSChristoph Hellwig 1088ffa0160aSChristoph Hellwig fput(dst); 1089ffa0160aSChristoph Hellwig fput(src); 1090ffa0160aSChristoph Hellwig out: 1091ffa0160aSChristoph Hellwig return status; 1092ffa0160aSChristoph Hellwig } 1093ffa0160aSChristoph Hellwig 1094e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy) 1095e0639dc5SOlga Kornievskaia { 1096e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1097e0639dc5SOlga Kornievskaia return; 1098e0639dc5SOlga Kornievskaia kfree(copy); 1099e0639dc5SOlga Kornievskaia } 1100e0639dc5SOlga Kornievskaia 1101e0639dc5SOlga Kornievskaia static bool 1102e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy) 1103e0639dc5SOlga Kornievskaia { 1104e0639dc5SOlga Kornievskaia bool value; 1105e0639dc5SOlga Kornievskaia 1106e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1107e0639dc5SOlga Kornievskaia value = copy->stopped; 1108e0639dc5SOlga Kornievskaia if (!copy->stopped) 1109e0639dc5SOlga Kornievskaia copy->stopped = true; 1110e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1111e0639dc5SOlga Kornievskaia return value; 1112e0639dc5SOlga Kornievskaia } 1113e0639dc5SOlga Kornievskaia 1114e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1115e0639dc5SOlga Kornievskaia { 1116e0639dc5SOlga Kornievskaia /* only 1 thread should stop the copy */ 1117e0639dc5SOlga Kornievskaia if (!check_and_set_stop_copy(copy)) 1118e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1119e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1120e0639dc5SOlga Kornievskaia } 1121e0639dc5SOlga Kornievskaia 1122e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1123e0639dc5SOlga Kornievskaia { 1124e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1125e0639dc5SOlga Kornievskaia 1126e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1127e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1128e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1129e0639dc5SOlga Kornievskaia copies); 1130e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1131e0639dc5SOlga Kornievskaia } 1132e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1133e0639dc5SOlga Kornievskaia return copy; 1134e0639dc5SOlga Kornievskaia } 1135e0639dc5SOlga Kornievskaia 1136e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1137e0639dc5SOlga Kornievskaia { 1138e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1139e0639dc5SOlga Kornievskaia 1140e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1141e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1142e0639dc5SOlga Kornievskaia } 1143e0639dc5SOlga Kornievskaia 1144e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1145e0639dc5SOlga Kornievskaia { 1146e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); 1147e0639dc5SOlga Kornievskaia 1148e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1149e0639dc5SOlga Kornievskaia } 1150e0639dc5SOlga Kornievskaia 1151e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1152e0639dc5SOlga Kornievskaia struct rpc_task *task) 1153e0639dc5SOlga Kornievskaia { 1154e0639dc5SOlga Kornievskaia return 1; 1155e0639dc5SOlga Kornievskaia } 1156e0639dc5SOlga Kornievskaia 1157e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1158e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1159e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1160e0639dc5SOlga Kornievskaia }; 1161e0639dc5SOlga Kornievskaia 1162e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1163e0639dc5SOlga Kornievskaia { 1164e0639dc5SOlga Kornievskaia copy->cp_res.wr_stable_how = NFS_UNSTABLE; 1165e0639dc5SOlga Kornievskaia copy->cp_synchronous = sync; 1166e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1167e0639dc5SOlga Kornievskaia } 1168e0639dc5SOlga Kornievskaia 1169e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) 1170e0639dc5SOlga Kornievskaia { 1171e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1172e0639dc5SOlga Kornievskaia size_t bytes_total = copy->cp_count; 1173e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1174e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1175e0639dc5SOlga Kornievskaia 1176e0639dc5SOlga Kornievskaia do { 1177e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1178e0639dc5SOlga Kornievskaia break; 1179e0639dc5SOlga Kornievskaia bytes_copied = nfsd_copy_file_range(copy->file_src, src_pos, 1180e0639dc5SOlga Kornievskaia copy->file_dst, dst_pos, bytes_total); 1181e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1182e0639dc5SOlga Kornievskaia break; 1183e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1184e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1185e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1186e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1187e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1188e0639dc5SOlga Kornievskaia return bytes_copied; 1189e0639dc5SOlga Kornievskaia } 1190e0639dc5SOlga Kornievskaia 1191e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1192e0639dc5SOlga Kornievskaia { 1193e0639dc5SOlga Kornievskaia __be32 status; 1194e0639dc5SOlga Kornievskaia ssize_t bytes; 1195e0639dc5SOlga Kornievskaia 1196e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1197e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1198e0639dc5SOlga Kornievskaia * to get the error 1199e0639dc5SOlga Kornievskaia */ 1200e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1201e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1202e0639dc5SOlga Kornievskaia else { 1203e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1204e0639dc5SOlga Kornievskaia status = nfs_ok; 1205e0639dc5SOlga Kornievskaia } 1206e0639dc5SOlga Kornievskaia 1207e0639dc5SOlga Kornievskaia fput(copy->file_src); 1208e0639dc5SOlga Kornievskaia fput(copy->file_dst); 1209e0639dc5SOlga Kornievskaia return status; 1210e0639dc5SOlga Kornievskaia } 1211e0639dc5SOlga Kornievskaia 1212e0639dc5SOlga Kornievskaia static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1213e0639dc5SOlga Kornievskaia { 1214e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1215e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1216e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1217e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1218e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1219e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1220e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 1221e0639dc5SOlga Kornievskaia dst->file_dst = get_file(src->file_dst); 1222e0639dc5SOlga Kornievskaia dst->file_src = get_file(src->file_src); 1223e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1224e0639dc5SOlga Kornievskaia } 1225e0639dc5SOlga Kornievskaia 1226e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1227e0639dc5SOlga Kornievskaia { 1228e0639dc5SOlga Kornievskaia nfs4_free_cp_state(copy); 1229e0639dc5SOlga Kornievskaia fput(copy->file_dst); 1230e0639dc5SOlga Kornievskaia fput(copy->file_src); 1231e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1232e0639dc5SOlga Kornievskaia list_del(©->copies); 1233e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1234e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1235e0639dc5SOlga Kornievskaia } 1236e0639dc5SOlga Kornievskaia 1237e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1238e0639dc5SOlga Kornievskaia { 1239e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1240e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1241e0639dc5SOlga Kornievskaia 1242e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1243e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1244e0639dc5SOlga Kornievskaia if (!cb_copy) 1245e0639dc5SOlga Kornievskaia goto out; 1246e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1247e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1248e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1249e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1250e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1251e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 1252e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1253e0639dc5SOlga Kornievskaia out: 1254e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1255e0639dc5SOlga Kornievskaia return 0; 1256e0639dc5SOlga Kornievskaia } 1257e0639dc5SOlga Kornievskaia 1258ffa0160aSChristoph Hellwig static __be32 125929ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1260eb69853dSChristoph Hellwig union nfsd4_op_u *u) 126129ae7f9dSAnna Schumaker { 1262eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 126329ae7f9dSAnna Schumaker __be32 status; 1264e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 126529ae7f9dSAnna Schumaker 1266e0639dc5SOlga Kornievskaia status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 1267e0639dc5SOlga Kornievskaia ©->file_src, ©->cp_dst_stateid, 1268e0639dc5SOlga Kornievskaia ©->file_dst); 126929ae7f9dSAnna Schumaker if (status) 127029ae7f9dSAnna Schumaker goto out; 127129ae7f9dSAnna Schumaker 1272e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1273e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1274e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1275e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1276e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 127729ae7f9dSAnna Schumaker 1278e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1279e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1280e0639dc5SOlga Kornievskaia if (!async_copy) 1281e0639dc5SOlga Kornievskaia goto out; 1282e0639dc5SOlga Kornievskaia if (!nfs4_init_cp_state(nn, copy)) { 1283e0639dc5SOlga Kornievskaia kfree(async_copy); 1284e0639dc5SOlga Kornievskaia goto out; 128529ae7f9dSAnna Schumaker } 1286e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1287e0639dc5SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid, 1288e0639dc5SOlga Kornievskaia sizeof(copy->cp_stateid)); 1289e0639dc5SOlga Kornievskaia dup_copy_fields(copy, async_copy); 1290e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1291e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1292e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1293e0639dc5SOlga Kornievskaia goto out_err; 1294e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1295e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1296e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1297e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1298e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1299e0639dc5SOlga Kornievskaia status = nfs_ok; 1300e0639dc5SOlga Kornievskaia } else 1301e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 130229ae7f9dSAnna Schumaker out: 130329ae7f9dSAnna Schumaker return status; 1304e0639dc5SOlga Kornievskaia out_err: 1305e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1306e0639dc5SOlga Kornievskaia goto out; 1307e0639dc5SOlga Kornievskaia } 1308e0639dc5SOlga Kornievskaia 1309e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1310e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1311e0639dc5SOlga Kornievskaia { 1312e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1313e0639dc5SOlga Kornievskaia 1314e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1315e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1316e0639dc5SOlga Kornievskaia if (memcmp(©->cp_stateid, stateid, NFS4_STATEID_SIZE)) 1317e0639dc5SOlga Kornievskaia continue; 1318e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1319e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1320e0639dc5SOlga Kornievskaia return copy; 1321e0639dc5SOlga Kornievskaia } 1322e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1323e0639dc5SOlga Kornievskaia return NULL; 132429ae7f9dSAnna Schumaker } 132529ae7f9dSAnna Schumaker 132629ae7f9dSAnna Schumaker static __be32 1327885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1328885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1329885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1330885e2bf3SOlga Kornievskaia { 1331e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1332e0639dc5SOlga Kornievskaia __be32 status = 0; 1333e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1334e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1335e0639dc5SOlga Kornievskaia 1336e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1337e0639dc5SOlga Kornievskaia if (copy) 1338e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1339e0639dc5SOlga Kornievskaia else 1340e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1341e0639dc5SOlga Kornievskaia 1342e0639dc5SOlga Kornievskaia return status; 1343885e2bf3SOlga Kornievskaia } 1344885e2bf3SOlga Kornievskaia 1345885e2bf3SOlga Kornievskaia static __be32 134695d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 134795d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 134895d871f0SAnna Schumaker { 13490d4d6720SJ. Bruce Fields __be32 status; 135095d871f0SAnna Schumaker struct file *file; 135195d871f0SAnna Schumaker 1352aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 135395d871f0SAnna Schumaker &fallocate->falloc_stateid, 1354af90f707SChristoph Hellwig WR_STATE, &file, NULL); 135595d871f0SAnna Schumaker if (status != nfs_ok) { 135695d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 135795d871f0SAnna Schumaker return status; 135895d871f0SAnna Schumaker } 135995d871f0SAnna Schumaker 136095d871f0SAnna Schumaker status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, 136195d871f0SAnna Schumaker fallocate->falloc_offset, 136295d871f0SAnna Schumaker fallocate->falloc_length, 136395d871f0SAnna Schumaker flags); 136495d871f0SAnna Schumaker fput(file); 136595d871f0SAnna Schumaker return status; 136695d871f0SAnna Schumaker } 13676308bc98SOlga Kornievskaia static __be32 13686308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 13696308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 13706308bc98SOlga Kornievskaia union nfsd4_op_u *u) 13716308bc98SOlga Kornievskaia { 1372e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1373e0639dc5SOlga Kornievskaia __be32 status = 0; 1374e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1375e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1376e0639dc5SOlga Kornievskaia 1377e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1378e0639dc5SOlga Kornievskaia if (copy) { 1379e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 1380e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1381e0639dc5SOlga Kornievskaia } else 1382e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1383e0639dc5SOlga Kornievskaia 1384e0639dc5SOlga Kornievskaia return status; 13856308bc98SOlga Kornievskaia } 138695d871f0SAnna Schumaker 138795d871f0SAnna Schumaker static __be32 138895d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1389eb69853dSChristoph Hellwig union nfsd4_op_u *u) 139095d871f0SAnna Schumaker { 1391eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 139295d871f0SAnna Schumaker } 139395d871f0SAnna Schumaker 139495d871f0SAnna Schumaker static __be32 1395b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1396eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1397b0cb9085SAnna Schumaker { 1398eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 1399b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1400b0cb9085SAnna Schumaker } 1401b0cb9085SAnna Schumaker 1402b0cb9085SAnna Schumaker static __be32 140324bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1404eb69853dSChristoph Hellwig union nfsd4_op_u *u) 140524bab491SAnna Schumaker { 1406eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 140724bab491SAnna Schumaker int whence; 140824bab491SAnna Schumaker __be32 status; 140924bab491SAnna Schumaker struct file *file; 141024bab491SAnna Schumaker 1411aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 141224bab491SAnna Schumaker &seek->seek_stateid, 1413af90f707SChristoph Hellwig RD_STATE, &file, NULL); 141424bab491SAnna Schumaker if (status) { 141524bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 141624bab491SAnna Schumaker return status; 141724bab491SAnna Schumaker } 141824bab491SAnna Schumaker 141924bab491SAnna Schumaker switch (seek->seek_whence) { 142024bab491SAnna Schumaker case NFS4_CONTENT_DATA: 142124bab491SAnna Schumaker whence = SEEK_DATA; 142224bab491SAnna Schumaker break; 142324bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 142424bab491SAnna Schumaker whence = SEEK_HOLE; 142524bab491SAnna Schumaker break; 142624bab491SAnna Schumaker default: 142724bab491SAnna Schumaker status = nfserr_union_notsupp; 142824bab491SAnna Schumaker goto out; 142924bab491SAnna Schumaker } 143024bab491SAnna Schumaker 143124bab491SAnna Schumaker /* 143224bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 143324bab491SAnna Schumaker * should ever file->f_pos. 143424bab491SAnna Schumaker */ 143524bab491SAnna Schumaker seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence); 143624bab491SAnna Schumaker if (seek->seek_pos < 0) 143724bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 143824bab491SAnna Schumaker else if (seek->seek_pos >= i_size_read(file_inode(file))) 143924bab491SAnna Schumaker seek->seek_eof = true; 144024bab491SAnna Schumaker 144124bab491SAnna Schumaker out: 144224bab491SAnna Schumaker fput(file); 144324bab491SAnna Schumaker return status; 144424bab491SAnna Schumaker } 144524bab491SAnna Schumaker 14461da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 14471da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 14481da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 14491da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 14501da177e4SLinus Torvalds */ 1451b37ad28bSAl Viro static __be32 1452c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1453ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 14541da177e4SLinus Torvalds { 14552ebbc012SAl Viro __be32 *buf, *p; 14561da177e4SLinus Torvalds int count; 1457b37ad28bSAl Viro __be32 status; 14581da177e4SLinus Torvalds 14598837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 14601da177e4SLinus Torvalds if (status) 14611da177e4SLinus Torvalds return status; 14621da177e4SLinus Torvalds 14633c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 14643c8e0316SYu Zhiguo if (status) 14653c8e0316SYu Zhiguo return status; 14663c8e0316SYu Zhiguo 14671da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 14681da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 14691da177e4SLinus Torvalds return nfserr_inval; 14701da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 14711da177e4SLinus Torvalds return nfserr_inval; 14721da177e4SLinus Torvalds 14731da177e4SLinus Torvalds /* count in words: 14741da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 14751da177e4SLinus Torvalds */ 14761da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 14771da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 14781da177e4SLinus Torvalds if (!buf) 14793e772463SJ. Bruce Fields return nfserr_jukebox; 14801da177e4SLinus Torvalds 148184822d0bSJ. Bruce Fields p = buf; 1482d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1483ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1484d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1485d5184658SJ. Bruce Fields verify->ve_bmval, 1486406a7ea9SFrank Filz rqstp, 0); 148741ae6e71SJ. Bruce Fields /* 148841ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 148941ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 149041ae6e71SJ. Bruce Fields */ 149184822d0bSJ. Bruce Fields if (status == nfserr_resource) 14921da177e4SLinus Torvalds status = nfserr_not_same; 14931da177e4SLinus Torvalds if (status) 14941da177e4SLinus Torvalds goto out_kfree; 14951da177e4SLinus Torvalds 149695ec28cdSBenny Halevy /* skip bitmap */ 149795ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 14981da177e4SLinus Torvalds status = nfserr_not_same; 14991da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 15001da177e4SLinus Torvalds goto out_kfree; 15011da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 15021da177e4SLinus Torvalds status = nfserr_same; 15031da177e4SLinus Torvalds 15041da177e4SLinus Torvalds out_kfree: 15051da177e4SLinus Torvalds kfree(buf); 15061da177e4SLinus Torvalds return status; 15071da177e4SLinus Torvalds } 15081da177e4SLinus Torvalds 1509c954e2a5SJ.Bruce Fields static __be32 1510c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1511eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1512c954e2a5SJ.Bruce Fields { 1513c954e2a5SJ.Bruce Fields __be32 status; 1514c954e2a5SJ.Bruce Fields 1515eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 1516c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1517c954e2a5SJ.Bruce Fields } 1518c954e2a5SJ.Bruce Fields 1519c954e2a5SJ.Bruce Fields static __be32 1520c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1521eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1522c954e2a5SJ.Bruce Fields { 1523c954e2a5SJ.Bruce Fields __be32 status; 1524c954e2a5SJ.Bruce Fields 1525eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 1526c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1527c954e2a5SJ.Bruce Fields } 1528c954e2a5SJ.Bruce Fields 15299cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 15309cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 15319cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 15329cf514ccSChristoph Hellwig { 15338a4c3926SJeff Layton if (!exp->ex_layout_types) { 15349cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 15359cf514ccSChristoph Hellwig return NULL; 15369cf514ccSChristoph Hellwig } 15379cf514ccSChristoph Hellwig 1538b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1539b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 15409cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 15419cf514ccSChristoph Hellwig __func__, layout_type); 15429cf514ccSChristoph Hellwig return NULL; 15439cf514ccSChristoph Hellwig } 15449cf514ccSChristoph Hellwig 15459cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 15469cf514ccSChristoph Hellwig } 15479cf514ccSChristoph Hellwig 15489cf514ccSChristoph Hellwig static __be32 15499cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 1550eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 15519cf514ccSChristoph Hellwig { 1552eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 15539cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 15549cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 15559cf514ccSChristoph Hellwig struct svc_export *exp; 15569cf514ccSChristoph Hellwig __be32 nfserr; 15579cf514ccSChristoph Hellwig 15589cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 15599cf514ccSChristoph Hellwig __func__, 15609cf514ccSChristoph Hellwig gdp->gd_layout_type, 15619cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 15629cf514ccSChristoph Hellwig gdp->gd_maxcount); 15639cf514ccSChristoph Hellwig 15649cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 15659cf514ccSChristoph Hellwig if (!map) { 15669cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 15679cf514ccSChristoph Hellwig __func__); 15689cf514ccSChristoph Hellwig return nfserr_noent; 15699cf514ccSChristoph Hellwig } 15709cf514ccSChristoph Hellwig 15719cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 15729cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 15739cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 15749cf514ccSChristoph Hellwig return nfserr_noent; 15759cf514ccSChristoph Hellwig } 15769cf514ccSChristoph Hellwig 15779cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 15789cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 15799cf514ccSChristoph Hellwig if (!ops) 15809cf514ccSChristoph Hellwig goto out; 15819cf514ccSChristoph Hellwig 15829cf514ccSChristoph Hellwig nfserr = nfs_ok; 1583f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 1584f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 1585d7c920d1STom Haynes rqstp, cstate->session->se_client, gdp); 1586f99d4fbdSChristoph Hellwig } 15879cf514ccSChristoph Hellwig 15889cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 15899cf514ccSChristoph Hellwig out: 1590a1420384SKinglong Mee exp_put(exp); 15919cf514ccSChristoph Hellwig return nfserr; 15929cf514ccSChristoph Hellwig } 15939cf514ccSChristoph Hellwig 159434b1744cSJ. Bruce Fields static void 159534b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 159634b1744cSJ. Bruce Fields { 159734b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 159834b1744cSJ. Bruce Fields } 159934b1744cSJ. Bruce Fields 16009cf514ccSChristoph Hellwig static __be32 16019cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 1602eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 16039cf514ccSChristoph Hellwig { 1604eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 16059cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 16069cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 16079cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 16089cf514ccSChristoph Hellwig __be32 nfserr; 160966282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 16109cf514ccSChristoph Hellwig 16119cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 16129cf514ccSChristoph Hellwig case IOMODE_READ: 161366282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 16149cf514ccSChristoph Hellwig break; 16159cf514ccSChristoph Hellwig case IOMODE_RW: 161666282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 16179cf514ccSChristoph Hellwig break; 16189cf514ccSChristoph Hellwig default: 16199cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 16209cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 16219cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 16229cf514ccSChristoph Hellwig goto out; 16239cf514ccSChristoph Hellwig } 16249cf514ccSChristoph Hellwig 16259cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 16269cf514ccSChristoph Hellwig if (nfserr) 16279cf514ccSChristoph Hellwig goto out; 16289cf514ccSChristoph Hellwig 16299cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 16309cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 16319cf514ccSChristoph Hellwig if (!ops) 16329cf514ccSChristoph Hellwig goto out; 16339cf514ccSChristoph Hellwig 16349cf514ccSChristoph Hellwig /* 16359cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 16369cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 16379cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 16389cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 16399cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 16409cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 16419cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 16429cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 16439cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 16449cf514ccSChristoph Hellwig */ 16459cf514ccSChristoph Hellwig nfserr = nfserr_inval; 16469cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 16479cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 16489cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 16499cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 16509cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 16519cf514ccSChristoph Hellwig goto out; 16529cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 16539cf514ccSChristoph Hellwig goto out; 16549cf514ccSChristoph Hellwig 16559cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 16569cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 165731ef83dcSChristoph Hellwig if (nfserr) { 1658f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 16599cf514ccSChristoph Hellwig goto out; 166031ef83dcSChristoph Hellwig } 16619cf514ccSChristoph Hellwig 1662c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1663c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1664c5c707f9SChristoph Hellwig goto out_put_stid; 1665c5c707f9SChristoph Hellwig 16662b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 16679cf514ccSChristoph Hellwig current_fh, lgp); 16689cf514ccSChristoph Hellwig if (nfserr) 16699cf514ccSChristoph Hellwig goto out_put_stid; 16709cf514ccSChristoph Hellwig 16719cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 16729cf514ccSChristoph Hellwig 16739cf514ccSChristoph Hellwig out_put_stid: 1674cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 16759cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 16769cf514ccSChristoph Hellwig out: 16779cf514ccSChristoph Hellwig return nfserr; 16789cf514ccSChristoph Hellwig } 16799cf514ccSChristoph Hellwig 168034b1744cSJ. Bruce Fields static void 168134b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 168234b1744cSJ. Bruce Fields { 168334b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 168434b1744cSJ. Bruce Fields } 168534b1744cSJ. Bruce Fields 16869cf514ccSChristoph Hellwig static __be32 16879cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 1688eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 16899cf514ccSChristoph Hellwig { 1690eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 16919cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 16929cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 16939cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 16949cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 16959cf514ccSChristoph Hellwig struct inode *inode; 16969cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 16979cf514ccSChristoph Hellwig __be32 nfserr; 16989cf514ccSChristoph Hellwig 16999cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 17009cf514ccSChristoph Hellwig if (nfserr) 17019cf514ccSChristoph Hellwig goto out; 17029cf514ccSChristoph Hellwig 17039cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 17049cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 17059cf514ccSChristoph Hellwig if (!ops) 17069cf514ccSChristoph Hellwig goto out; 17072b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 17089cf514ccSChristoph Hellwig 17099cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17109cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 17119cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 17129cf514ccSChristoph Hellwig goto out; 17139cf514ccSChristoph Hellwig } 17149cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 17159cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 17169cf514ccSChristoph Hellwig goto out; 17179cf514ccSChristoph Hellwig } 17189cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 17199cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 17209cf514ccSChristoph Hellwig goto out; 17219cf514ccSChristoph Hellwig } 17229cf514ccSChristoph Hellwig 17239cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 17249cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 17259cf514ccSChristoph Hellwig &ls); 17269cf514ccSChristoph Hellwig if (nfserr) { 1727f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 17289cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 17299cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 17309cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 17319cf514ccSChristoph Hellwig goto out; 17329cf514ccSChristoph Hellwig } 17339cf514ccSChristoph Hellwig 1734cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 1735cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 1736cc8a5532SJeff Layton 17379cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 17389cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 17399cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 17409cf514ccSChristoph Hellwig } else { 17419cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 17429cf514ccSChristoph Hellwig } 17439cf514ccSChristoph Hellwig 1744d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 17459cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 17469cf514ccSChristoph Hellwig out: 17479cf514ccSChristoph Hellwig return nfserr; 17489cf514ccSChristoph Hellwig } 17499cf514ccSChristoph Hellwig 17509cf514ccSChristoph Hellwig static __be32 17519cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 1752eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 17539cf514ccSChristoph Hellwig { 1754eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 17559cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 17569cf514ccSChristoph Hellwig __be32 nfserr; 17579cf514ccSChristoph Hellwig 17589cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 17599cf514ccSChristoph Hellwig if (nfserr) 17609cf514ccSChristoph Hellwig goto out; 17619cf514ccSChristoph Hellwig 17629cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 17639cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 17649cf514ccSChristoph Hellwig goto out; 17659cf514ccSChristoph Hellwig 17669cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 17679cf514ccSChristoph Hellwig case IOMODE_READ: 17689cf514ccSChristoph Hellwig case IOMODE_RW: 17699cf514ccSChristoph Hellwig case IOMODE_ANY: 17709cf514ccSChristoph Hellwig break; 17719cf514ccSChristoph Hellwig default: 17729cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 17739cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 17749cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17759cf514ccSChristoph Hellwig goto out; 17769cf514ccSChristoph Hellwig } 17779cf514ccSChristoph Hellwig 17789cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 17799cf514ccSChristoph Hellwig case RETURN_FILE: 17809cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 17819cf514ccSChristoph Hellwig break; 17829cf514ccSChristoph Hellwig case RETURN_FSID: 17839cf514ccSChristoph Hellwig case RETURN_ALL: 17849cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 17859cf514ccSChristoph Hellwig break; 17869cf514ccSChristoph Hellwig default: 17879cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 17889cf514ccSChristoph Hellwig lrp->lr_return_type); 17899cf514ccSChristoph Hellwig nfserr = nfserr_inval; 17909cf514ccSChristoph Hellwig break; 17919cf514ccSChristoph Hellwig } 17929cf514ccSChristoph Hellwig out: 17939cf514ccSChristoph Hellwig return nfserr; 17949cf514ccSChristoph Hellwig } 17959cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 17969cf514ccSChristoph Hellwig 17971da177e4SLinus Torvalds /* 17981da177e4SLinus Torvalds * NULL call. 17991da177e4SLinus Torvalds */ 18007111c66eSAl Viro static __be32 1801a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 18021da177e4SLinus Torvalds { 18031da177e4SLinus Torvalds return nfs_ok; 18041da177e4SLinus Torvalds } 18051da177e4SLinus Torvalds 1806e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1807e2b20950SShankar Anand { 1808e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1809e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1810e2b20950SShankar Anand } 1811e2b20950SShankar Anand 1812bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 1813b591480bSJ.Bruce Fields 1814f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1815b001a1b6SBenny Halevy 18161da177e4SLinus Torvalds /* 181757716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1818f9bb94c4SAndy Adamson * 181957716355SJ. Bruce Fields * Also note, enforced elsewhere: 182057716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 182157716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 18221d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 18231d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 182457716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 182557716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 182657716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1827f9bb94c4SAndy Adamson */ 182857716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1829f9bb94c4SAndy Adamson { 18307a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 183157716355SJ. Bruce Fields 183257716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 183357716355SJ. Bruce Fields if (args->minorversion == 0) 183457716355SJ. Bruce Fields return nfs_ok; 183557716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 183657716355SJ. Bruce Fields if (args->opcnt == 0) 183757716355SJ. Bruce Fields return nfs_ok; 18387a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 183957716355SJ. Bruce Fields return nfs_ok; 18407a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 184157716355SJ. Bruce Fields return nfserr_op_not_in_session; 18427a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 184357716355SJ. Bruce Fields return nfs_ok; 18447a04cfdaSJ. Bruce Fields /* 18457a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 18467a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 18477a04cfdaSJ. Bruce Fields * compound: 18487a04cfdaSJ. Bruce Fields */ 184957716355SJ. Bruce Fields if (args->opcnt != 1) 185057716355SJ. Bruce Fields return nfserr_not_only_op; 185157716355SJ. Bruce Fields return nfs_ok; 1852f9bb94c4SAndy Adamson } 1853f9bb94c4SAndy Adamson 1854f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 185522b03214SJ. Bruce Fields { 185622b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 185722b03214SJ. Bruce Fields } 185822b03214SJ. Bruce Fields 18591091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 18601091006cSJ. Bruce Fields { 1861e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 1862e372ba60SJ. Bruce Fields return false; 1863c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 18641091006cSJ. Bruce Fields } 18651091006cSJ. Bruce Fields 186668d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 186768d93184SJ. Bruce Fields { 186868d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 186968d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 187068d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 187168d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 1872bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 1873bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 187468d93184SJ. Bruce Fields 187568d93184SJ. Bruce Fields /* 187668d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 187768d93184SJ. Bruce Fields * have special rules. 187868d93184SJ. Bruce Fields */ 187968d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 188068d93184SJ. Bruce Fields return false; 188168d93184SJ. Bruce Fields /* 188268d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 188368d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 188468d93184SJ. Bruce Fields * result: 188568d93184SJ. Bruce Fields */ 188668d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 188768d93184SJ. Bruce Fields return false; 188851904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 188951904b08SJ. Bruce Fields return false; 189068d93184SJ. Bruce Fields nextd = OPDESC(next); 189168d93184SJ. Bruce Fields /* 189268d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 189368d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 189468d93184SJ. Bruce Fields * now: 189568d93184SJ. Bruce Fields */ 189668d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 189768d93184SJ. Bruce Fields } 189868d93184SJ. Bruce Fields 18992d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 19002d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 19012d124dfaSJ. Bruce Fields { 19022d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 19032d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 19042d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 19052d124dfaSJ. Bruce Fields 19062d124dfaSJ. Bruce Fields xdr->buf = buf; 1907ddd1ea56SJ. Bruce Fields xdr->iov = head; 19082d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 1909a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 19106ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 19116ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 19122825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 191305638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 19142825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 1915a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 19162d124dfaSJ. Bruce Fields } 19172d124dfaSJ. Bruce Fields 1918f9bb94c4SAndy Adamson /* 19191da177e4SLinus Torvalds * COMPOUND call. 19201da177e4SLinus Torvalds */ 19217111c66eSAl Viro static __be32 1922a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 19231da177e4SLinus Torvalds { 1924a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 1925a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 19261da177e4SLinus Torvalds struct nfsd4_op *op; 1927e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 19284daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 19294daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1930b37ad28bSAl Viro __be32 status; 19311da177e4SLinus Torvalds 19322d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 19334aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 19341da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 1935d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 19361da177e4SLinus Torvalds resp->taglen = args->taglen; 19371da177e4SLinus Torvalds resp->tag = args->tag; 19381da177e4SLinus Torvalds resp->rqstp = rqstp; 19394daeed25SKinglong Mee cstate->minorversion = args->minorversion; 19404daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 19414daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 19428ff30fa4SNeilBrown /* 19438ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 19448ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 19458ff30fa4SNeilBrown */ 194630660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 19471da177e4SLinus Torvalds 19481da177e4SLinus Torvalds /* 19491da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 19501da177e4SLinus Torvalds */ 19511da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 195235f7a14fSJ. Bruce Fields if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) 19531da177e4SLinus Torvalds goto out; 19540078117cSJ. Bruce Fields status = nfserr_resource; 19550078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 19560078117cSJ. Bruce Fields goto out; 19571da177e4SLinus Torvalds 195857716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 195957716355SJ. Bruce Fields if (status) { 1960f9bb94c4SAndy Adamson op = &args->ops[0]; 196157716355SJ. Bruce Fields op->status = status; 19625b7b15aeSJ. Bruce Fields resp->opcnt = 1; 1963f9bb94c4SAndy Adamson goto encode_op; 1964f9bb94c4SAndy Adamson } 1965f9bb94c4SAndy Adamson 1966fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 19671da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 19681da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 19691da177e4SLinus Torvalds 19701da177e4SLinus Torvalds /* 19711da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 19721da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 19731da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 19741da177e4SLinus Torvalds */ 19759d313b17SJ. Bruce Fields if (op->status) { 19769d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 19779d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 19781da177e4SLinus Torvalds goto encode_op; 19799d313b17SJ. Bruce Fields } 19801da177e4SLinus Torvalds 19814daeed25SKinglong Mee if (!current_fh->fh_dentry) { 1982f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 19831da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 19841da177e4SLinus Torvalds goto encode_op; 19851da177e4SLinus Torvalds } 19864daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1987f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 198842ca0993SJ.Bruce Fields op->status = nfserr_moved; 198942ca0993SJ.Bruce Fields goto encode_op; 199042ca0993SJ.Bruce Fields } 1991b591480bSJ.Bruce Fields 19922336745eSKinglong Mee fh_clear_wcc(current_fh); 19932336745eSKinglong Mee 199458e7b33aSMi Jinlong /* If op is non-idempotent */ 1995f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 19964c69d585SJ. Bruce Fields /* 1997a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 1998a8095f7eSJ. Bruce Fields * succesful reply: 1999a8095f7eSJ. Bruce Fields */ 2000f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2001a8095f7eSJ. Bruce Fields /* 2002a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 20034c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 20044c69d585SJ. Bruce Fields */ 20054c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 20064c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 200758e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 200858e7b33aSMi Jinlong } 200958e7b33aSMi Jinlong 201058e7b33aSMi Jinlong if (op->status) 201158e7b33aSMi Jinlong goto encode_op; 201258e7b33aSMi Jinlong 2013f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2014f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2015f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 20161da177e4SLinus Torvalds 20179a307403SJ. Bruce Fields /* Only from SEQUENCE */ 20189a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 20199a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 20209a307403SJ. Bruce Fields status = op->status; 20219a307403SJ. Bruce Fields goto out; 20229a307403SJ. Bruce Fields } 20238b70484cSTigran Mkrtchyan if (!op->status) { 2024f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2025f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 20268b70484cSTigran Mkrtchyan 2027f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 202837c593c5STigran Mkrtchyan clear_current_stateid(cstate); 20298b70484cSTigran Mkrtchyan 20308b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 20314daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 20328b70484cSTigran Mkrtchyan } 20331da177e4SLinus Torvalds encode_op: 2034a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2035a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2036d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 20371da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 20381da177e4SLinus Torvalds } else { 20391da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 20401da177e4SLinus Torvalds status = op->status; 20411da177e4SLinus Torvalds } 20420407717dSBenny Halevy 2043fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2044fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 20450407717dSBenny Halevy 204658fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2047e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 20481da177e4SLinus Torvalds } 20491da177e4SLinus Torvalds 20504daeed25SKinglong Mee cstate->status = status; 20514daeed25SKinglong Mee fh_put(current_fh); 20524daeed25SKinglong Mee fh_put(save_fh); 20534daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 20541da177e4SLinus Torvalds out: 20552f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 205630660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 20573b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 20581da177e4SLinus Torvalds return status; 20591da177e4SLinus Torvalds } 20601da177e4SLinus Torvalds 206158e7b33aSMi Jinlong #define op_encode_hdr_size (2) 206258e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 206358e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 206458e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 206558e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 206658e7b33aSMi Jinlong 20678c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 20688c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 206958e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 207058e7b33aSMi Jinlong 207158e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 207258e7b33aSMi Jinlong 207358e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 207458e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 207558e7b33aSMi Jinlong op_encode_ace_maxsz) 207658e7b33aSMi Jinlong 207758e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 207858e7b33aSMi Jinlong 207958e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 208058e7b33aSMi Jinlong { 208158e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 208258e7b33aSMi Jinlong } 208358e7b33aSMi Jinlong 208458e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 208558e7b33aSMi Jinlong { 208658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 208758e7b33aSMi Jinlong } 208858e7b33aSMi Jinlong 20892282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20902282cd2cSKinglong Mee { 20912282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 20922282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 20932282cd2cSKinglong Mee } 20942282cd2cSKinglong Mee 209558e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 209658e7b33aSMi Jinlong { 209758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 209858e7b33aSMi Jinlong } 209958e7b33aSMi Jinlong 210058e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 210158e7b33aSMi Jinlong { 210258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 210358e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 210458e7b33aSMi Jinlong } 210558e7b33aSMi Jinlong 2106b86cef60SJ. Bruce Fields /* 2107b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2108b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2109b86cef60SJ. Bruce Fields * reads unnecessarily. 2110b86cef60SJ. Bruce Fields */ 2111b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2112b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2113b86cef60SJ. Bruce Fields { 2114b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2115b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2116b86cef60SJ. Bruce Fields u32 ret = 0; 2117b86cef60SJ. Bruce Fields 2118b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2119b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2120b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2121b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2122b86cef60SJ. Bruce Fields 2123b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2124b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2125b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2126b86cef60SJ. Bruce Fields } 2127b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2128b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2129b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2130b86cef60SJ. Bruce Fields } 2131b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2132b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2133b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2134b86cef60SJ. Bruce Fields } 2135b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 21361ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2137b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2138b86cef60SJ. Bruce Fields } 2139b86cef60SJ. Bruce Fields /* 2140b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2141b86cef60SJ. Bruce Fields * supported_attributes) 2142b86cef60SJ. Bruce Fields */ 2143b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2144b86cef60SJ. Bruce Fields /* bitmask, length */ 2145b86cef60SJ. Bruce Fields ret += 20; 2146b86cef60SJ. Bruce Fields return ret; 2147b86cef60SJ. Bruce Fields } 2148b86cef60SJ. Bruce Fields 21492282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 21502282cd2cSKinglong Mee { 21512282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 21522282cd2cSKinglong Mee } 21532282cd2cSKinglong Mee 215458e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 215558e7b33aSMi Jinlong { 215658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 215758e7b33aSMi Jinlong * sizeof(__be32); 215858e7b33aSMi Jinlong } 215958e7b33aSMi Jinlong 216058e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 216158e7b33aSMi Jinlong { 216258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 216358e7b33aSMi Jinlong * sizeof(__be32); 216458e7b33aSMi Jinlong } 216558e7b33aSMi Jinlong 216658e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 216758e7b33aSMi Jinlong { 216858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 216958e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 217058e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 217158e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 217258e7b33aSMi Jinlong } 217358e7b33aSMi Jinlong 217458e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 217558e7b33aSMi Jinlong { 217658e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 217758e7b33aSMi Jinlong 217858e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 21793c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 218058e7b33aSMi Jinlong 2181622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 218258e7b33aSMi Jinlong } 218358e7b33aSMi Jinlong 218458e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 218558e7b33aSMi Jinlong { 21863c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 218758e7b33aSMi Jinlong 21883c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 21893c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 219058e7b33aSMi Jinlong 2191561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2192561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 219358e7b33aSMi Jinlong } 219458e7b33aSMi Jinlong 21952282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 21962282cd2cSKinglong Mee { 21972282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 21982282cd2cSKinglong Mee } 21992282cd2cSKinglong Mee 220058e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 220158e7b33aSMi Jinlong { 220258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 220358e7b33aSMi Jinlong * sizeof(__be32); 220458e7b33aSMi Jinlong } 220558e7b33aSMi Jinlong 220658e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 220758e7b33aSMi Jinlong { 220858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 220958e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 221058e7b33aSMi Jinlong } 221158e7b33aSMi Jinlong 2212ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2213ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2214ccae70a9SJ. Bruce Fields { 2215d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2216d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2217ccae70a9SJ. Bruce Fields } 2218ccae70a9SJ. Bruce Fields 22192282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22202282cd2cSKinglong Mee { 22212282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 22222282cd2cSKinglong Mee * sizeof(__be32); 22232282cd2cSKinglong Mee } 22242282cd2cSKinglong Mee 222558e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 222658e7b33aSMi Jinlong { 222758e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 222858e7b33aSMi Jinlong } 222958e7b33aSMi Jinlong 22302282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22312282cd2cSKinglong Mee { 22322282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 22332282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 22342282cd2cSKinglong Mee } 22352282cd2cSKinglong Mee 223658e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 223758e7b33aSMi Jinlong { 2238480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2239480efaeeSJ. Bruce Fields sizeof(__be32); 224058e7b33aSMi Jinlong } 224158e7b33aSMi Jinlong 224258e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 224358e7b33aSMi Jinlong { 2244f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 224558e7b33aSMi Jinlong } 224658e7b33aSMi Jinlong 224758e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 224858e7b33aSMi Jinlong { 224958e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2250a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2251a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 225258e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 225358e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 225458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 225558e7b33aSMi Jinlong /* eir_server_scope<> */\ 225658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 225758e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 225858e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 225958e7b33aSMi Jinlong } 226058e7b33aSMi Jinlong 226158e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 226258e7b33aSMi Jinlong { 226358e7b33aSMi Jinlong return (op_encode_hdr_size + \ 226458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 226558e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 226658e7b33aSMi Jinlong } 226758e7b33aSMi Jinlong 226858e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 226958e7b33aSMi Jinlong { 227058e7b33aSMi Jinlong return (op_encode_hdr_size + \ 227158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 227258e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 227358e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 227458e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 227558e7b33aSMi Jinlong } 227658e7b33aSMi Jinlong 227729ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 227829ae7f9dSAnna Schumaker { 227929ae7f9dSAnna Schumaker return (op_encode_hdr_size + 228029ae7f9dSAnna Schumaker 1 /* wr_callback */ + 228129ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 228229ae7f9dSAnna Schumaker 2 /* wr_count */ + 228329ae7f9dSAnna Schumaker 1 /* wr_committed */ + 228429ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 228529ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 228629ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 228729ae7f9dSAnna Schumaker } 228829ae7f9dSAnna Schumaker 22896308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 22906308bc98SOlga Kornievskaia struct nfsd4_op *op) 22916308bc98SOlga Kornievskaia { 22926308bc98SOlga Kornievskaia return (op_encode_hdr_size + 22936308bc98SOlga Kornievskaia 2 /* osr_count */ + 22946308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 22956308bc98SOlga Kornievskaia } 22966308bc98SOlga Kornievskaia 22979cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 22982282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 22992282cd2cSKinglong Mee { 23002282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 23012282cd2cSKinglong Mee 23022282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 23032282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 23042282cd2cSKinglong Mee 23052282cd2cSKinglong Mee return (op_encode_hdr_size + 23062282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 23072282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 23082282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 23092282cd2cSKinglong Mee } 23102282cd2cSKinglong Mee 23119cf514ccSChristoph Hellwig /* 23129cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 23139cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 23149cf514ccSChristoph Hellwig */ 23159cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 23169cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23179cf514ccSChristoph Hellwig { 23189cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23199cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 23209cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 23219cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 23229cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 23239cf514ccSChristoph Hellwig } 23249cf514ccSChristoph Hellwig 23259cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23269cf514ccSChristoph Hellwig { 23279cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23289cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 23299cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 23309cf514ccSChristoph Hellwig } 23319cf514ccSChristoph Hellwig 23329cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23339cf514ccSChristoph Hellwig { 23349cf514ccSChristoph Hellwig return (op_encode_hdr_size + 23359cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 23369cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 23379cf514ccSChristoph Hellwig } 23389cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 23399cf514ccSChristoph Hellwig 23402282cd2cSKinglong Mee 23412282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 23422282cd2cSKinglong Mee { 23432282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 23442282cd2cSKinglong Mee } 23452282cd2cSKinglong Mee 2346bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2347b591480bSJ.Bruce Fields [OP_ACCESS] = { 2348eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2349b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 23501c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2351b591480bSJ.Bruce Fields }, 2352b591480bSJ.Bruce Fields [OP_CLOSE] = { 2353eb69853dSChristoph Hellwig .op_func = nfsd4_close, 235458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2355b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 23561c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 235757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2358b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2359b591480bSJ.Bruce Fields }, 2360b591480bSJ.Bruce Fields [OP_COMMIT] = { 2361eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 236258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2363b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 23641c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2365b591480bSJ.Bruce Fields }, 2366b591480bSJ.Bruce Fields [OP_CREATE] = { 2367eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2368d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2369b001a1b6SBenny Halevy .op_name = "OP_CREATE", 23701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2371b591480bSJ.Bruce Fields }, 2372b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2373eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 237458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2375b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 237658e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 237757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2378b591480bSJ.Bruce Fields }, 2379b591480bSJ.Bruce Fields [OP_GETATTR] = { 2380eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2381eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2382b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2383b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2384b591480bSJ.Bruce Fields }, 2385b591480bSJ.Bruce Fields [OP_GETFH] = { 2386eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2387b001a1b6SBenny Halevy .op_name = "OP_GETFH", 23881c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2389b591480bSJ.Bruce Fields }, 2390b591480bSJ.Bruce Fields [OP_LINK] = { 2391eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2392c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2393c856694eSJ. Bruce Fields | OP_CACHEME, 2394b001a1b6SBenny Halevy .op_name = "OP_LINK", 23951c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 2396b591480bSJ.Bruce Fields }, 2397b591480bSJ.Bruce Fields [OP_LOCK] = { 2398eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 2399b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 2400b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 2401b001a1b6SBenny Halevy .op_name = "OP_LOCK", 24021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2403b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 2404b591480bSJ.Bruce Fields }, 2405b591480bSJ.Bruce Fields [OP_LOCKT] = { 2406eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 2407b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 2408b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 24091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2410b591480bSJ.Bruce Fields }, 2411b591480bSJ.Bruce Fields [OP_LOCKU] = { 2412eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 241358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2414b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 24151c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 241657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 2417b591480bSJ.Bruce Fields }, 2418b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2419eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 2420d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2421b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 24221c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2423b591480bSJ.Bruce Fields }, 2424b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2425eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 2426d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2427b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 24281c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2429b591480bSJ.Bruce Fields }, 2430b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2431eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 2432b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 24331c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2434b591480bSJ.Bruce Fields }, 2435b591480bSJ.Bruce Fields [OP_OPEN] = { 2436eb69853dSChristoph Hellwig .op_func = nfsd4_open, 243758e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2438b001a1b6SBenny Halevy .op_name = "OP_OPEN", 24391c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 2440b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 2441b591480bSJ.Bruce Fields }, 2442b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2443eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 244458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2445b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 24461c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 2447b591480bSJ.Bruce Fields }, 2448b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2449eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 245058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2451b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 24521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 245357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 2454b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 2455b591480bSJ.Bruce Fields }, 2456b591480bSJ.Bruce Fields [OP_PUTFH] = { 2457eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 245868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24595b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2460b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 24611c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2462b591480bSJ.Bruce Fields }, 2463eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2464eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 246568d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24665b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2467b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 24681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2469eeac294eSJ.Bruce Fields }, 2470b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2471eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 247268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 24735b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2474b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 24751c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2476b591480bSJ.Bruce Fields }, 2477b591480bSJ.Bruce Fields [OP_READ] = { 2478eb69853dSChristoph Hellwig .op_func = nfsd4_read, 247934b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 2480b001a1b6SBenny Halevy .op_name = "OP_READ", 24811c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 248257832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 2483b591480bSJ.Bruce Fields }, 2484b591480bSJ.Bruce Fields [OP_READDIR] = { 2485eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 2486b001a1b6SBenny Halevy .op_name = "OP_READDIR", 24871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 2488b591480bSJ.Bruce Fields }, 2489b591480bSJ.Bruce Fields [OP_READLINK] = { 2490eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 2491b001a1b6SBenny Halevy .op_name = "OP_READLINK", 24921c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 2493b591480bSJ.Bruce Fields }, 2494b591480bSJ.Bruce Fields [OP_REMOVE] = { 2495eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 2496c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2497b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 24981c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 2499b591480bSJ.Bruce Fields }, 2500b591480bSJ.Bruce Fields [OP_RENAME] = { 2501eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 2502c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 250358e7b33aSMi Jinlong .op_name = "OP_RENAME", 25041c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 2505b591480bSJ.Bruce Fields }, 2506b591480bSJ.Bruce Fields [OP_RENEW] = { 2507eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 250858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 250958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2510b001a1b6SBenny Halevy .op_name = "OP_RENEW", 25111c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 251258e7b33aSMi Jinlong 2513b591480bSJ.Bruce Fields }, 2514b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2515eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 251668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 251758e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2518b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 25191c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2520b591480bSJ.Bruce Fields }, 2521b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2522eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 252358e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2524b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 25251c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2526b591480bSJ.Bruce Fields }, 2527dcb488a3SAndy Adamson [OP_SECINFO] = { 2528eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 252934b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 253068d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2531b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 25321c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 2533dcb488a3SAndy Adamson }, 2534b591480bSJ.Bruce Fields [OP_SETATTR] = { 2535eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 2536b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2537b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 2538b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 25391c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 254057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 2541b591480bSJ.Bruce Fields }, 2542b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2543eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 254458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2545b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 2546b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 2547b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 25481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 2549b591480bSJ.Bruce Fields }, 2550b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2551eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 255258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2553c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2554b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 25551c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2556b591480bSJ.Bruce Fields }, 2557b591480bSJ.Bruce Fields [OP_VERIFY] = { 2558eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 2559b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 25601c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2561b591480bSJ.Bruce Fields }, 2562b591480bSJ.Bruce Fields [OP_WRITE] = { 2563eb69853dSChristoph Hellwig .op_func = nfsd4_write, 2564c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2565b001a1b6SBenny Halevy .op_name = "OP_WRITE", 25661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 256757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 2568b591480bSJ.Bruce Fields }, 2569b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2570eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 257158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 257258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2573b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 25741c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2575b591480bSJ.Bruce Fields }, 2576069b6ad4SAndy Adamson 2577069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2578069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2579eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 258058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 258158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2582069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 25831c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 2584069b6ad4SAndy Adamson }, 2585cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2586eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 2587cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2588cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 25891c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2590cb73a9f4SJ. Bruce Fields }, 25911d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 2592eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 259358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 259458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 25951d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 25961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 25971d1bc8f2SJ. Bruce Fields }, 2598069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2599eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 260058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 260158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2602069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 26031c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 2604069b6ad4SAndy Adamson }, 2605069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2606eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 260758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 260858e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2609069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 26101c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2611069b6ad4SAndy Adamson }, 2612069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2613eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 2614f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2615069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 26161c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 2617069b6ad4SAndy Adamson }, 2618094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2619eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 262058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 262158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2622094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 26231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2624094b5d74SBenny Halevy }, 26254dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 2626eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 262758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 26284dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 26291c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 26304dc6ec00SJ. Bruce Fields }, 263104f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 2632eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 2633ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 263468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 263504f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 26361c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 263704f4ad16SJ. Bruce Fields }, 263817456804SBryan Schumaker [OP_TEST_STATEID] = { 2639eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 264017456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 264117456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 26421c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 264317456804SBryan Schumaker }, 2644e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 2645eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 264658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2647e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 264857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 26491c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2650e1ca12dfSBryan Schumaker }, 26519cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 26529cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 2653eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 265434b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 26559cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 26569cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 26571c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 26589cf514ccSChristoph Hellwig }, 26599cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 2660eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 266134b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 26629cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26639cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 26641c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 26659cf514ccSChristoph Hellwig }, 26669cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 2667eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 26689cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26699cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 26701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 26719cf514ccSChristoph Hellwig }, 26729cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 2673eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 26749cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 26759cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 26761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 26779cf514ccSChristoph Hellwig }, 26789cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 267924bab491SAnna Schumaker 268024bab491SAnna Schumaker /* NFSv4.2 operations */ 268195d871f0SAnna Schumaker [OP_ALLOCATE] = { 2682eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 268303b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 268495d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 26851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 268695d871f0SAnna Schumaker }, 2687b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 2688eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 268903b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2690b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 26911c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2692b0cb9085SAnna Schumaker }, 2693ffa0160aSChristoph Hellwig [OP_CLONE] = { 2694eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 269503b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2696ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 26971c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2698ffa0160aSChristoph Hellwig }, 269929ae7f9dSAnna Schumaker [OP_COPY] = { 2700eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 270103b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 270229ae7f9dSAnna Schumaker .op_name = "OP_COPY", 27031c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 270429ae7f9dSAnna Schumaker }, 270524bab491SAnna Schumaker [OP_SEEK] = { 2706eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 270724bab491SAnna Schumaker .op_name = "OP_SEEK", 27081c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 270924bab491SAnna Schumaker }, 27106308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 27116308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 27126308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 27136308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 27146308bc98SOlga Kornievskaia }, 2715885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 2716885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 2717885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 2718885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 2719885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 2720885e2bf3SOlga Kornievskaia }, 2721b591480bSJ.Bruce Fields }; 2722b591480bSJ.Bruce Fields 2723ed941643SAndrew Elble /** 2724ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 2725ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 2726ed941643SAndrew Elble * 2727ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 2728ed941643SAndrew Elble * 2729ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 2730ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 2731ed941643SAndrew Elble */ 2732ed941643SAndrew Elble 2733ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 2734ed941643SAndrew Elble { 2735ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 2736ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 2737ed941643SAndrew Elble struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 2738ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 2739ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 2740ed941643SAndrew Elble u32 opiter; 2741ed941643SAndrew Elble 2742ed941643SAndrew Elble if (!cstate->minorversion) 2743ed941643SAndrew Elble return false; 2744ed941643SAndrew Elble 2745ed941643SAndrew Elble if (cstate->spo_must_allowed == true) 2746ed941643SAndrew Elble return true; 2747ed941643SAndrew Elble 2748ed941643SAndrew Elble opiter = resp->opcnt; 2749ed941643SAndrew Elble while (opiter < argp->opcnt) { 2750ed941643SAndrew Elble this = &argp->ops[opiter++]; 2751ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 2752ed941643SAndrew Elble cstate->clp->cl_mach_cred && 2753ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 2754ed941643SAndrew Elble cstate->spo_must_allowed = true; 2755ed941643SAndrew Elble return true; 2756ed941643SAndrew Elble } 2757ed941643SAndrew Elble } 2758ed941643SAndrew Elble cstate->spo_must_allowed = false; 2759ed941643SAndrew Elble return false; 2760ed941643SAndrew Elble } 2761ed941643SAndrew Elble 27624f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 27634f0cefbfSJ. Bruce Fields { 276405b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 27654f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 27662282cd2cSKinglong Mee 27672282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 27682282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 27694f0cefbfSJ. Bruce Fields } 27704f0cefbfSJ. Bruce Fields 277107d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 277207d1f802SJ. Bruce Fields { 277307d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 277407d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 277507d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 277607d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 277707d1f802SJ. Bruce Fields } 277807d1f802SJ. Bruce Fields } 277907d1f802SJ. Bruce Fields 2780f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 2781b001a1b6SBenny Halevy { 2782b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 2783b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 2784b001a1b6SBenny Halevy return "unknown_operation"; 2785b001a1b6SBenny Halevy } 2786b001a1b6SBenny Halevy 27871da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 27881da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 27891da177e4SLinus Torvalds 2790860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 27910a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 2792f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 279363f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_voidres, 27940a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 27950a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 27960a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 27970a93a47fSYu Zhiguo .pc_xdrressize = 1, 27980a93a47fSYu Zhiguo }, 27990a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 2800f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 2801026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 280263f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 28030a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 28040a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 28053e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 28060a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 28070a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 28080a93a47fSYu Zhiguo }, 28091da177e4SLinus Torvalds }; 28101da177e4SLinus Torvalds 28117fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 2812e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 28131da177e4SLinus Torvalds .vs_vers = 4, 28141da177e4SLinus Torvalds .vs_nproc = 2, 28151da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 28167fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 28171da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 28181da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 281905a45a2dSJeff Layton .vs_rpcb_optnl = true, 28205283b03eSJeff Layton .vs_need_cong_ctrl = true, 28211da177e4SLinus Torvalds }; 28221da177e4SLinus Torvalds 28231da177e4SLinus Torvalds /* 28241da177e4SLinus Torvalds * Local variables: 28251da177e4SLinus Torvalds * c-basic-offset: 8 28261da177e4SLinus Torvalds * End: 28271da177e4SLinus Torvalds */ 2828