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> 40624322f1SOlga Kornievskaia #include <linux/sunrpc/addr.h> 411da177e4SLinus Torvalds 4258e7b33aSMi Jinlong #include "idmap.h" 439a74af21SBoaz Harrosh #include "cache.h" 449a74af21SBoaz Harrosh #include "xdr4.h" 450a3adadeSJ. Bruce Fields #include "vfs.h" 468b70484cSTigran Mkrtchyan #include "current_stateid.h" 473320fef1SStanislav Kinsbursky #include "netns.h" 484ac7249eSChristoph Hellwig #include "acl.h" 499cf514ccSChristoph Hellwig #include "pnfs.h" 5031ef83dcSChristoph Hellwig #include "trace.h" 511da177e4SLinus Torvalds 5218032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 5318032ca0SDavid Quigley #include <linux/security.h> 5418032ca0SDavid Quigley 5518032ca0SDavid Quigley static inline void 5618032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 5718032ca0SDavid Quigley { 582b0143b5SDavid Howells struct inode *inode = d_inode(resfh->fh_dentry); 5918032ca0SDavid Quigley int status; 6018032ca0SDavid Quigley 615955102cSAl Viro inode_lock(inode); 6218032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 6318032ca0SDavid Quigley label->data, label->len); 645955102cSAl Viro inode_unlock(inode); 6518032ca0SDavid Quigley 6618032ca0SDavid Quigley if (status) 6718032ca0SDavid Quigley /* 6818032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 6918032ca0SDavid Quigley * already have created a new file, so it may be too 7018032ca0SDavid Quigley * late. For now this seems the least of evils: 7118032ca0SDavid Quigley */ 7218032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 7318032ca0SDavid Quigley 7418032ca0SDavid Quigley return; 7518032ca0SDavid Quigley } 7618032ca0SDavid Quigley #else 7718032ca0SDavid Quigley static inline void 7818032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7918032ca0SDavid Quigley { } 8018032ca0SDavid Quigley #endif 8118032ca0SDavid Quigley 821da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 831da177e4SLinus Torvalds 843c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 853c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 863c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 873c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 883c8e0316SYu Zhiguo }; 893c8e0316SYu Zhiguo 903c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 913c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 923c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 933c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 943c8e0316SYu Zhiguo }; 953c8e0316SYu Zhiguo 963c8e0316SYu Zhiguo static __be32 973c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 983c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 993c8e0316SYu Zhiguo { 1003c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 10132ddd944SJ. Bruce Fields struct svc_export *exp = cstate->current_fh.fh_export; 1023c8e0316SYu Zhiguo 103916d2d84SJ. Bruce Fields if (!nfsd_attrs_supported(cstate->minorversion, bmval)) 1043c8e0316SYu Zhiguo return nfserr_attrnotsupp; 105916d2d84SJ. Bruce Fields if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) 1063c8e0316SYu Zhiguo return nfserr_attrnotsupp; 10732ddd944SJ. Bruce Fields if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && 10832ddd944SJ. Bruce Fields !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) 10932ddd944SJ. Bruce Fields return nfserr_attrnotsupp; 110916d2d84SJ. Bruce Fields if (writable && !bmval_is_subset(bmval, writable)) 1113c8e0316SYu Zhiguo return nfserr_inval; 11247057abdSAndreas Gruenbacher if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && 11347057abdSAndreas Gruenbacher (bmval[1] & FATTR4_WORD1_MODE)) 11447057abdSAndreas Gruenbacher return nfserr_inval; 1153c8e0316SYu Zhiguo return nfs_ok; 1163c8e0316SYu Zhiguo } 1173c8e0316SYu Zhiguo 1183c8e0316SYu Zhiguo static __be32 1193c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1203c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1213c8e0316SYu Zhiguo { 1223c8e0316SYu Zhiguo __be32 status = nfs_ok; 1233c8e0316SYu Zhiguo 1243c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1253c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1263c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1273c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1283c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1293c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1303c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1313c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1323c8e0316SYu Zhiguo } 1333c8e0316SYu Zhiguo 1343c8e0316SYu Zhiguo return status; 1353c8e0316SYu Zhiguo } 1363c8e0316SYu Zhiguo 1379208faf2SYu Zhiguo static int 1389208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1399208faf2SYu Zhiguo { 1409208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1419208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1429208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1439208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1449208faf2SYu Zhiguo } 1459208faf2SYu Zhiguo 1469208faf2SYu Zhiguo /* 1479208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1489208faf2SYu Zhiguo * in the returned attr bitmap. 1499208faf2SYu Zhiguo */ 1509208faf2SYu Zhiguo static void 1519208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1529208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1539208faf2SYu Zhiguo { 1549208faf2SYu Zhiguo __be32 status; 1559208faf2SYu Zhiguo 1569208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1579208faf2SYu Zhiguo if (status) 1589208faf2SYu Zhiguo /* 1599208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1609208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1619208faf2SYu Zhiguo * So this seems the least of evils: 1629208faf2SYu Zhiguo */ 1639208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1649208faf2SYu Zhiguo } 1659208faf2SYu Zhiguo 1661da177e4SLinus Torvalds static inline void 1671da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1681da177e4SLinus Torvalds { 1691da177e4SLinus Torvalds fh_put(dst); 1701da177e4SLinus Torvalds dget(src->fh_dentry); 1711da177e4SLinus Torvalds if (src->fh_export) 172bf18f163SKinglong Mee exp_get(src->fh_export); 1731da177e4SLinus Torvalds *dst = *src; 1741da177e4SLinus Torvalds } 1751da177e4SLinus Torvalds 176b37ad28bSAl Viro static __be32 177dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1781da177e4SLinus Torvalds { 179b37ad28bSAl Viro __be32 status; 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds if (open->op_truncate && 1821da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1831da177e4SLinus Torvalds return nfserr_inval; 1841da177e4SLinus Torvalds 185a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 186a043226bSJ. Bruce Fields 1871da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 1888837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 1899801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 1908837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 19157ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 1928837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds return status; 1971da177e4SLinus Torvalds } 1981da177e4SLinus Torvalds 199aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 200aadab6c6SJ. Bruce Fields { 2012b0143b5SDavid Howells umode_t mode = d_inode(fh->fh_dentry)->i_mode; 202aadab6c6SJ. Bruce Fields 203aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 204aadab6c6SJ. Bruce Fields return nfs_ok; 205aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 206aadab6c6SJ. Bruce Fields return nfserr_isdir; 207aadab6c6SJ. Bruce Fields /* 208aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 209aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 210aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 211aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 212aadab6c6SJ. Bruce Fields * regular file. 213aadab6c6SJ. Bruce Fields */ 214aadab6c6SJ. Bruce Fields return nfserr_symlink; 215aadab6c6SJ. Bruce Fields } 216aadab6c6SJ. Bruce Fields 217bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2181da177e4SLinus Torvalds { 219bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 220bbc9c36cSJ. Bruce Fields return; 221bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 222bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 223bbc9c36cSJ. Bruce Fields } 224bbc9c36cSJ. Bruce Fields 225bbc9c36cSJ. Bruce Fields static __be32 226c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 227bbc9c36cSJ. Bruce Fields { 228bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 2297007c90fSNeil Brown int accmode; 230b37ad28bSAl Viro __be32 status; 2311da177e4SLinus Torvalds 232c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 233c0e6bee4SJ. Bruce Fields if (!*resfh) 23459deeb9eSJ. Bruce Fields return nfserr_jukebox; 235c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 236500c2481Szhengbin open->op_truncate = false; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds if (open->op_create) { 23979fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 24079fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 24179fb54abSBenny Halevy * 24279fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 24379fb54abSBenny Halevy * Reply Cache | server | | 24479fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 24579fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 24679fb54abSBenny Halevy * | | | (SHOULD) 24779fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 24879fb54abSBenny Halevy * | | | (SHOULD NOT) 24979fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 25079fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 25179fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 25279fb54abSBenny Halevy */ 25379fb54abSBenny Halevy 2541da177e4SLinus Torvalds /* 2551da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 256ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2571da177e4SLinus Torvalds */ 258880a3a53SJ. Bruce Fields current->fs->umask = open->op_umask; 259ac6721a1SMi Jinlong status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, 2601da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 261c0e6bee4SJ. Bruce Fields *resfh, open->op_createmode, 262749997e5SJeff Layton (u32 *)open->op_verf.data, 263856121b2SJ. Bruce Fields &open->op_truncate, &open->op_created); 264880a3a53SJ. Bruce Fields current->fs->umask = 0; 265749997e5SJeff Layton 26618032ca0SDavid Quigley if (!status && open->op_label.len) 267c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 26818032ca0SDavid Quigley 26999f88726SJ. Bruce Fields /* 270ead8fb8cSKinglong Mee * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 271ead8fb8cSKinglong Mee * use the returned bitmask to indicate which attributes 272ead8fb8cSKinglong Mee * we used to store the verifier: 273749997e5SJeff Layton */ 274ead8fb8cSKinglong Mee if (nfsd_create_is_exclusive(open->op_createmode) && status == 0) 275ead8fb8cSKinglong Mee open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | 276749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 2774335723eSJ. Bruce Fields } else 2784335723eSJ. Bruce Fields /* 2794335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 2804335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 2814335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 2824335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 2834335723eSJ. Bruce Fields */ 2841da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 285c0e6bee4SJ. Bruce Fields open->op_fname.data, open->op_fname.len, *resfh); 286aadab6c6SJ. Bruce Fields if (status) 287aadab6c6SJ. Bruce Fields goto out; 288c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 289af85852dSJ. Bruce Fields if (status) 290af85852dSJ. Bruce Fields goto out; 2911da177e4SLinus Torvalds 2929208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 293c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 2949208faf2SYu Zhiguo 295c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 2967007c90fSNeil Brown accmode = NFSD_MAY_NOP; 29789f6c336SJ. Bruce Fields if (open->op_created || 29889f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 2997007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 300c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 30141fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 302af85852dSJ. Bruce Fields out: 3031da177e4SLinus Torvalds return status; 3041da177e4SLinus Torvalds } 3051da177e4SLinus Torvalds 306b37ad28bSAl Viro static __be32 307bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 3081da177e4SLinus Torvalds { 309bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 310b37ad28bSAl Viro __be32 status; 3119f415eb2SJ. Bruce Fields int accmode = 0; 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 3141da177e4SLinus Torvalds * set the change info 3151da177e4SLinus Torvalds */ 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 3181da177e4SLinus Torvalds 319bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 3221da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 3239f415eb2SJ. Bruce Fields /* 3249f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 3259f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 3269f415eb2SJ. Bruce Fields * should let it succeed now if possible. 3279f415eb2SJ. Bruce Fields * 3289f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 3299f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 3309f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 3319f415eb2SJ. Bruce Fields */ 3329f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 3339f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 3341da177e4SLinus Torvalds 3359f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds return status; 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds 34060adfc50SAndy Adamson static void 34160adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 34260adfc50SAndy Adamson { 34360adfc50SAndy Adamson struct nfsd4_sessionid *sid = 34460adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 34560adfc50SAndy Adamson 34660adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 34760adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 34860adfc50SAndy Adamson } 3491da177e4SLinus Torvalds 3507191155bSJ.Bruce Fields static __be32 351ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 352eb69853dSChristoph Hellwig union nfsd4_op_u *u) 3531da177e4SLinus Torvalds { 354eb69853dSChristoph Hellwig struct nfsd4_open *open = &u->open; 355b37ad28bSAl Viro __be32 status; 356c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 3573320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3583320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 35903f318caSJ. Bruce Fields bool reclaim = false; 3606668958fSAndy Adamson 361fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3621da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 363fe0750e5SJ. Bruce Fields open->op_openowner); 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds /* This check required by spec. */ 3661da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3671da177e4SLinus Torvalds return nfserr_inval; 3681da177e4SLinus Torvalds 369500c2481Szhengbin open->op_created = false; 370ab1350b2SMi Jinlong /* 371ab1350b2SMi Jinlong * RFC5661 18.51.3 372ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 373ab1350b2SMi Jinlong */ 374ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 375a52d726bSJeff Layton !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, 376a52d726bSJeff Layton &cstate->session->se_client->cl_flags) && 377ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 378ab1350b2SMi Jinlong return nfserr_grace; 379ab1350b2SMi Jinlong 38060adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 38160adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 38260adfc50SAndy Adamson 3831da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3846cd22668SKinglong Mee status = nfsd4_process_open1(cstate, open, nn); 385a90b061cSAl Viro if (status == nfserr_replay_me) { 386fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 387ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 388a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 389a4773c08SJ. Bruce Fields &rp->rp_openfh); 3908837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3911da177e4SLinus Torvalds if (status) 3921da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 3931da177e4SLinus Torvalds " restoring previous filehandle\n"); 3941da177e4SLinus Torvalds else 395a90b061cSAl Viro status = nfserr_replay_me; 3961da177e4SLinus Torvalds } 3971da177e4SLinus Torvalds if (status) 3981da177e4SLinus Torvalds goto out; 3999d313b17SJ. Bruce Fields if (open->op_xdr_error) { 4009d313b17SJ. Bruce Fields status = open->op_xdr_error; 4019d313b17SJ. Bruce Fields goto out; 4029d313b17SJ. Bruce Fields } 403fb553c0fSJ. Bruce Fields 4043c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 4053c8e0316SYu Zhiguo if (status) 4063c8e0316SYu Zhiguo goto out; 4073c8e0316SYu Zhiguo 408fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 409fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 410cbd0d51aSJ. Bruce Fields status = nfserr_grace; 411c87fb4a3SJ. Bruce Fields if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 412cbd0d51aSJ. Bruce Fields goto out; 413cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 414c87fb4a3SJ. Bruce Fields if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 415cbd0d51aSJ. Bruce Fields goto out; 416fb553c0fSJ. Bruce Fields 4171da177e4SLinus Torvalds switch (open->op_claim_type) { 4180dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4191da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 420c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4211da177e4SLinus Torvalds if (status) 4221da177e4SLinus Torvalds goto out; 4231da177e4SLinus Torvalds break; 4241da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 4253320fef1SStanislav Kinsbursky status = nfs4_check_open_reclaim(&open->op_clientid, 4260fe492dbSTrond Myklebust cstate, nn); 4270cf99b91SMi Jinlong if (status) 4280cf99b91SMi Jinlong goto out; 429ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 43003f318caSJ. Bruce Fields reclaim = true; 4310a4c9265SGustavo A. R. Silva /* fall through */ 4328b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4338b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 434bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4351da177e4SLinus Torvalds if (status) 4361da177e4SLinus Torvalds goto out; 437c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4381da177e4SLinus Torvalds break; 4398b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4401da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4412fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4421da177e4SLinus Torvalds open->op_claim_type); 4431da177e4SLinus Torvalds status = nfserr_notsupp; 4441da177e4SLinus Torvalds goto out; 4451da177e4SLinus Torvalds default: 4462fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4471da177e4SLinus Torvalds open->op_claim_type); 4481da177e4SLinus Torvalds status = nfserr_inval; 4491da177e4SLinus Torvalds goto out; 4501da177e4SLinus Torvalds } 4511da177e4SLinus Torvalds /* 4521da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4531da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4541da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4551da177e4SLinus Torvalds */ 456c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 457b3fbfe0eSJeff Layton WARN(status && open->op_created, 458b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 459b3fbfe0eSJeff Layton be32_to_cpu(status)); 46003f318caSJ. Bruce Fields if (reclaim && !status) 46103f318caSJ. Bruce Fields nn->somebody_reclaimed = true; 4621da177e4SLinus Torvalds out: 463c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 464c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 465c0e6bee4SJ. Bruce Fields fh_put(resfh); 466c0e6bee4SJ. Bruce Fields kfree(resfh); 467c0e6bee4SJ. Bruce Fields } 46842297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4699411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4701da177e4SLinus Torvalds return status; 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds /* 4749d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4759d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4769d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4779d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4789d313b17SJ. Bruce Fields */ 4799d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4809d313b17SJ. Bruce Fields { 481eb69853dSChristoph Hellwig struct nfsd4_open *open = &op->u.open; 4829d313b17SJ. Bruce Fields 4839d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4849d313b17SJ. Bruce Fields return op->status; 4859d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4869d313b17SJ. Bruce Fields return op->status; 4879d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 488eb69853dSChristoph Hellwig return nfsd4_open(rqstp, cstate, &op->u); 4899d313b17SJ. Bruce Fields } 4909d313b17SJ. Bruce Fields 4919d313b17SJ. Bruce Fields /* 4921da177e4SLinus Torvalds * filehandle-manipulating ops. 4931da177e4SLinus Torvalds */ 4947191155bSJ.Bruce Fields static __be32 495b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 496eb69853dSChristoph Hellwig union nfsd4_op_u *u) 4971da177e4SLinus Torvalds { 498eb69853dSChristoph Hellwig u->getfh = &cstate->current_fh; 4991da177e4SLinus Torvalds return nfs_ok; 5001da177e4SLinus Torvalds } 5011da177e4SLinus Torvalds 5027191155bSJ.Bruce Fields static __be32 503ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 504eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5051da177e4SLinus Torvalds { 506eb69853dSChristoph Hellwig struct nfsd4_putfh *putfh = &u->putfh; 507b9e8638eSOlga Kornievskaia __be32 ret; 508eb69853dSChristoph Hellwig 509ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 510ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 511ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 512ca364317SJ.Bruce Fields putfh->pf_fhlen); 513b9e8638eSOlga Kornievskaia ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 514b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 515b9e8638eSOlga Kornievskaia if (ret == nfserr_stale && putfh->no_verify) { 516b9e8638eSOlga Kornievskaia SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN); 517b9e8638eSOlga Kornievskaia ret = 0; 518b9e8638eSOlga Kornievskaia } 519b9e8638eSOlga Kornievskaia #endif 520b9e8638eSOlga Kornievskaia return ret; 5211da177e4SLinus Torvalds } 5221da177e4SLinus Torvalds 5237191155bSJ.Bruce Fields static __be32 524b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 525eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5261da177e4SLinus Torvalds { 527b37ad28bSAl Viro __be32 status; 5281da177e4SLinus Torvalds 529ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 530df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5311da177e4SLinus Torvalds return status; 5321da177e4SLinus Torvalds } 5331da177e4SLinus Torvalds 5347191155bSJ.Bruce Fields static __be32 535b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 536eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5371da177e4SLinus Torvalds { 538ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5391da177e4SLinus Torvalds return nfserr_restorefh; 5401da177e4SLinus Torvalds 541ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 54251100d2bSOlga Kornievskaia if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) { 54337c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 54451100d2bSOlga Kornievskaia SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); 54537c593c5STigran Mkrtchyan } 5461da177e4SLinus Torvalds return nfs_ok; 5471da177e4SLinus Torvalds } 5481da177e4SLinus Torvalds 5497191155bSJ.Bruce Fields static __be32 550b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 551eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5521da177e4SLinus Torvalds { 553ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 55451100d2bSOlga Kornievskaia if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) { 55537c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 55651100d2bSOlga Kornievskaia SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG); 55737c593c5STigran Mkrtchyan } 5581da177e4SLinus Torvalds return nfs_ok; 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds /* 5621da177e4SLinus Torvalds * misc nfsv4 ops 5631da177e4SLinus Torvalds */ 5647191155bSJ.Bruce Fields static __be32 565ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 566eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5671da177e4SLinus Torvalds { 568eb69853dSChristoph Hellwig struct nfsd4_access *access = &u->access; 569*c11d7fd1SFrank van der Linden u32 access_full; 570eb69853dSChristoph Hellwig 571*c11d7fd1SFrank van der Linden access_full = NFS3_ACCESS_FULL; 572*c11d7fd1SFrank van der Linden if (cstate->minorversion >= 2) 573*c11d7fd1SFrank van der Linden access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD | 574*c11d7fd1SFrank van der Linden NFS4_ACCESS_XAWRITE; 575*c11d7fd1SFrank van der Linden 576*c11d7fd1SFrank van der Linden if (access->ac_req_access & ~access_full) 5771da177e4SLinus Torvalds return nfserr_inval; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 580ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 581ca364317SJ.Bruce Fields &access->ac_supported); 5821da177e4SLinus Torvalds } 5831da177e4SLinus Torvalds 584b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 585ab4684d1SChuck Lever { 58627c438f5STrond Myklebust __be32 *verf = (__be32 *)verifier->data; 587ab4684d1SChuck Lever 58827c438f5STrond Myklebust BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data)); 58927c438f5STrond Myklebust 59027c438f5STrond Myklebust nfsd_copy_boot_verifier(verf, net_generic(net, nfsd_net_id)); 591ab4684d1SChuck Lever } 592ab4684d1SChuck Lever 5937191155bSJ.Bruce Fields static __be32 594ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 595eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5961da177e4SLinus Torvalds { 597eb69853dSChristoph Hellwig struct nfsd4_commit *commit = &u->commit; 598eb69853dSChristoph Hellwig 59975c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 600524ff1afSTrond Myklebust commit->co_count, 601524ff1afSTrond Myklebust (__be32 *)commit->co_verf.data); 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds 604b37ad28bSAl Viro static __be32 605ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 606eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6071da177e4SLinus Torvalds { 608eb69853dSChristoph Hellwig struct nfsd4_create *create = &u->create; 6091da177e4SLinus Torvalds struct svc_fh resfh; 610b37ad28bSAl Viro __be32 status; 6111da177e4SLinus Torvalds dev_t rdev; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6141da177e4SLinus Torvalds 615fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 6161da177e4SLinus Torvalds if (status) 6171da177e4SLinus Torvalds return status; 6181da177e4SLinus Torvalds 6193c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6203c8e0316SYu Zhiguo nfsd_attrmask); 6213c8e0316SYu Zhiguo if (status) 6223c8e0316SYu Zhiguo return status; 6233c8e0316SYu Zhiguo 624880a3a53SJ. Bruce Fields current->fs->umask = create->cr_umask; 6251da177e4SLinus Torvalds switch (create->cr_type) { 6261da177e4SLinus Torvalds case NF4LNK: 627ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 628ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6291e444f5bSKinglong Mee create->cr_data, &resfh); 6301da177e4SLinus Torvalds break; 6311da177e4SLinus Torvalds 6321da177e4SLinus Torvalds case NF4BLK: 633880a3a53SJ. Bruce Fields status = nfserr_inval; 6341da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6351da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6361da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 637880a3a53SJ. Bruce Fields goto out_umask; 638ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 639ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 640ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6411da177e4SLinus Torvalds break; 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds case NF4CHR: 644880a3a53SJ. Bruce Fields status = nfserr_inval; 6451da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6461da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6471da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 648880a3a53SJ. Bruce Fields goto out_umask; 649ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 650ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 651ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6521da177e4SLinus Torvalds break; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds case NF4SOCK: 655ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 656ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 657ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6581da177e4SLinus Torvalds break; 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds case NF4FIFO: 661ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 662ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 663ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6641da177e4SLinus Torvalds break; 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds case NF4DIR: 6671da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 668ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 669ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 670ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6711da177e4SLinus Torvalds break; 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds default: 6741da177e4SLinus Torvalds status = nfserr_badtype; 6751da177e4SLinus Torvalds } 6761da177e4SLinus Torvalds 6779208faf2SYu Zhiguo if (status) 6789208faf2SYu Zhiguo goto out; 6799208faf2SYu Zhiguo 68018032ca0SDavid Quigley if (create->cr_label.len) 68118032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 68218032ca0SDavid Quigley 6839208faf2SYu Zhiguo if (create->cr_acl != NULL) 6849208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6859208faf2SYu Zhiguo create->cr_bmval); 6869208faf2SYu Zhiguo 687ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 688ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 689ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6909208faf2SYu Zhiguo out: 6911da177e4SLinus Torvalds fh_put(&resfh); 692880a3a53SJ. Bruce Fields out_umask: 693880a3a53SJ. Bruce Fields current->fs->umask = 0; 6941da177e4SLinus Torvalds return status; 6951da177e4SLinus Torvalds } 6961da177e4SLinus Torvalds 6977191155bSJ.Bruce Fields static __be32 698ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 699eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7001da177e4SLinus Torvalds { 701eb69853dSChristoph Hellwig struct nfsd4_getattr *getattr = &u->getattr; 702b37ad28bSAl Viro __be32 status; 7031da177e4SLinus Torvalds 7048837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 7051da177e4SLinus Torvalds if (status) 7061da177e4SLinus Torvalds return status; 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 7091da177e4SLinus Torvalds return nfserr_inval; 7101da177e4SLinus Torvalds 711916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 712916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 713916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 7141da177e4SLinus Torvalds 715ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7161da177e4SLinus Torvalds return nfs_ok; 7171da177e4SLinus Torvalds } 7181da177e4SLinus Torvalds 7197191155bSJ.Bruce Fields static __be32 720ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 721eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7221da177e4SLinus Torvalds { 723eb69853dSChristoph Hellwig struct nfsd4_link *link = &u->link; 72495424460SJ. Bruce Fields __be32 status; 7251da177e4SLinus Torvalds 726ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 727ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7281da177e4SLinus Torvalds if (!status) 729ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7301da177e4SLinus Torvalds return status; 7311da177e4SLinus Torvalds } 7321da177e4SLinus Torvalds 7330ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7341da177e4SLinus Torvalds { 7351da177e4SLinus Torvalds struct svc_fh tmp_fh; 736b37ad28bSAl Viro __be32 ret; 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 739df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 740df547efbSJ. Bruce Fields if (ret) 7411da177e4SLinus Torvalds return ret; 7420ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7431da177e4SLinus Torvalds fh_put(&tmp_fh); 7441da177e4SLinus Torvalds return nfserr_noent; 7451da177e4SLinus Torvalds } 7461da177e4SLinus Torvalds fh_put(&tmp_fh); 7470ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7480ff7ab46SJ. Bruce Fields } 7490ff7ab46SJ. Bruce Fields 7500ff7ab46SJ. Bruce Fields static __be32 7510ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 752eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7530ff7ab46SJ. Bruce Fields { 7540ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds 7577191155bSJ.Bruce Fields static __be32 758ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 759eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7601da177e4SLinus Torvalds { 761ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 762eb69853dSChristoph Hellwig u->lookup.lo_name, u->lookup.lo_len, 763ca364317SJ.Bruce Fields &cstate->current_fh); 7641da177e4SLinus Torvalds } 7651da177e4SLinus Torvalds 7667191155bSJ.Bruce Fields static __be32 767ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 768eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7691da177e4SLinus Torvalds { 770eb69853dSChristoph Hellwig struct nfsd4_read *read = &u->read; 771b37ad28bSAl Viro __be32 status; 7721da177e4SLinus Torvalds 7735c4583b2SJeff Layton read->rd_nf = NULL; 7741da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7751da177e4SLinus Torvalds return nfserr_inval; 7761da177e4SLinus Torvalds 77787c5942eSChuck Lever trace_nfsd_read_start(rqstp, &cstate->current_fh, 77887c5942eSChuck Lever read->rd_offset, read->rd_length); 77987c5942eSChuck Lever 7809b3234b9SJ. Bruce Fields /* 7819b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7829b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7839b3234b9SJ. Bruce Fields * following compound. 7849b3234b9SJ. Bruce Fields * 7859b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7869b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7879b3234b9SJ. Bruce Fields */ 7889b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 789779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 7909b3234b9SJ. Bruce Fields 7911da177e4SLinus Torvalds /* check stateid */ 792aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 793aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 794624322f1SOlga Kornievskaia &read->rd_nf, NULL); 795af90f707SChristoph Hellwig if (status) { 7961da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7971da177e4SLinus Torvalds goto out; 7981da177e4SLinus Torvalds } 7991da177e4SLinus Torvalds status = nfs_ok; 8001da177e4SLinus Torvalds out: 8011da177e4SLinus Torvalds read->rd_rqstp = rqstp; 802ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 8031da177e4SLinus Torvalds return status; 8041da177e4SLinus Torvalds } 8051da177e4SLinus Torvalds 80634b1744cSJ. Bruce Fields 80734b1744cSJ. Bruce Fields static void 80834b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u) 80934b1744cSJ. Bruce Fields { 8105c4583b2SJeff Layton if (u->read.rd_nf) 8115c4583b2SJeff Layton nfsd_file_put(u->read.rd_nf); 81287c5942eSChuck Lever trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, 81387c5942eSChuck Lever u->read.rd_offset, u->read.rd_length); 81434b1744cSJ. Bruce Fields } 81534b1744cSJ. Bruce Fields 8167191155bSJ.Bruce Fields static __be32 817ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 818eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8191da177e4SLinus Torvalds { 820eb69853dSChristoph Hellwig struct nfsd4_readdir *readdir = &u->readdir; 8211da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 8221da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8271da177e4SLinus Torvalds return nfserr_inval; 8281da177e4SLinus Torvalds 829916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 830916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 831916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 8321da177e4SLinus Torvalds 833832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8341da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8351da177e4SLinus Torvalds return nfserr_bad_cookie; 8361da177e4SLinus Torvalds 8371da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 838ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8391da177e4SLinus Torvalds return nfs_ok; 8401da177e4SLinus Torvalds } 8411da177e4SLinus Torvalds 8427191155bSJ.Bruce Fields static __be32 843ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 844eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8451da177e4SLinus Torvalds { 846eb69853dSChristoph Hellwig u->readlink.rl_rqstp = rqstp; 847eb69853dSChristoph Hellwig u->readlink.rl_fhp = &cstate->current_fh; 8481da177e4SLinus Torvalds return nfs_ok; 8491da177e4SLinus Torvalds } 8501da177e4SLinus Torvalds 8517191155bSJ.Bruce Fields static __be32 852ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 853eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8541da177e4SLinus Torvalds { 855eb69853dSChristoph Hellwig struct nfsd4_remove *remove = &u->remove; 856b37ad28bSAl Viro __be32 status; 8571da177e4SLinus Torvalds 858c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 859c815afc7SNeilBrown return nfserr_grace; 860ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 861ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8621da177e4SLinus Torvalds if (!status) { 863ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 864ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8651da177e4SLinus Torvalds } 8661da177e4SLinus Torvalds return status; 8671da177e4SLinus Torvalds } 8681da177e4SLinus Torvalds 8697191155bSJ.Bruce Fields static __be32 870ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 871eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8721da177e4SLinus Torvalds { 873eb69853dSChristoph Hellwig struct nfsd4_rename *rename = &u->rename; 87495424460SJ. Bruce Fields __be32 status; 8751da177e4SLinus Torvalds 876f8f71d00SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 877c815afc7SNeilBrown return nfserr_grace; 878ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 879ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8801da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8812a6cf944SJ. Bruce Fields if (status) 8822a6cf944SJ. Bruce Fields return status; 883ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 884ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8852a6cf944SJ. Bruce Fields return nfs_ok; 8861da177e4SLinus Torvalds } 8871da177e4SLinus Torvalds 8887191155bSJ.Bruce Fields static __be32 889dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 890eb69853dSChristoph Hellwig union nfsd4_op_u *u) 891dcb488a3SAndy Adamson { 892eb69853dSChristoph Hellwig struct nfsd4_secinfo *secinfo = &u->secinfo; 893dcb488a3SAndy Adamson struct svc_export *exp; 894dcb488a3SAndy Adamson struct dentry *dentry; 895dcb488a3SAndy Adamson __be32 err; 896dcb488a3SAndy Adamson 89729a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 89829a78a3eSJ. Bruce Fields if (err) 89929a78a3eSJ. Bruce Fields return err; 900dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 901dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 902dcb488a3SAndy Adamson &exp, &dentry); 903dcb488a3SAndy Adamson if (err) 904dcb488a3SAndy Adamson return err; 9052f6fc056SJ. Bruce Fields fh_unlock(&cstate->current_fh); 9062b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 907dcb488a3SAndy Adamson exp_put(exp); 908dcb488a3SAndy Adamson err = nfserr_noent; 909dcb488a3SAndy Adamson } else 910dcb488a3SAndy Adamson secinfo->si_exp = exp; 911dcb488a3SAndy Adamson dput(dentry); 91256560b9aSJ. Bruce Fields if (cstate->minorversion) 91356560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 91456560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 915dcb488a3SAndy Adamson return err; 916dcb488a3SAndy Adamson } 917dcb488a3SAndy Adamson 918dcb488a3SAndy Adamson static __be32 91904f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 920eb69853dSChristoph Hellwig union nfsd4_op_u *u) 92104f4ad16SJ. Bruce Fields { 92204f4ad16SJ. Bruce Fields __be32 err; 92304f4ad16SJ. Bruce Fields 924eb69853dSChristoph Hellwig switch (u->secinfo_no_name.sin_style) { 92504f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 92604f4ad16SJ. Bruce Fields break; 92704f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 92804f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 92904f4ad16SJ. Bruce Fields if (err) 93004f4ad16SJ. Bruce Fields return err; 93104f4ad16SJ. Bruce Fields break; 93204f4ad16SJ. Bruce Fields default: 93304f4ad16SJ. Bruce Fields return nfserr_inval; 93404f4ad16SJ. Bruce Fields } 935bf18f163SKinglong Mee 936eb69853dSChristoph Hellwig u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export); 93704f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 93804f4ad16SJ. Bruce Fields return nfs_ok; 93904f4ad16SJ. Bruce Fields } 94004f4ad16SJ. Bruce Fields 94134b1744cSJ. Bruce Fields static void 94234b1744cSJ. Bruce Fields nfsd4_secinfo_release(union nfsd4_op_u *u) 94334b1744cSJ. Bruce Fields { 94434b1744cSJ. Bruce Fields if (u->secinfo.si_exp) 94534b1744cSJ. Bruce Fields exp_put(u->secinfo.si_exp); 94634b1744cSJ. Bruce Fields } 94734b1744cSJ. Bruce Fields 948ec572b9eSEryu Guan static void 949ec572b9eSEryu Guan nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) 950ec572b9eSEryu Guan { 951ec572b9eSEryu Guan if (u->secinfo_no_name.sin_exp) 952ec572b9eSEryu Guan exp_put(u->secinfo_no_name.sin_exp); 953ec572b9eSEryu Guan } 954ec572b9eSEryu Guan 95504f4ad16SJ. Bruce Fields static __be32 956ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 957eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9581da177e4SLinus Torvalds { 959eb69853dSChristoph Hellwig struct nfsd4_setattr *setattr = &u->setattr; 960b37ad28bSAl Viro __be32 status = nfs_ok; 96196f6f985SAl Viro int err; 9621da177e4SLinus Torvalds 9631da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 964af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 965aa0d6aedSAnna Schumaker &cstate->current_fh, &setattr->sa_stateid, 966624322f1SOlga Kornievskaia WR_STATE, NULL, NULL); 967375c5547SJ. Bruce Fields if (status) { 9683e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 969375c5547SJ. Bruce Fields return status; 970375c5547SJ. Bruce Fields } 9711da177e4SLinus Torvalds } 97296f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 97396f6f985SAl Viro if (err) 97496f6f985SAl Viro return nfserrno(err); 9751da177e4SLinus Torvalds status = nfs_ok; 9763c8e0316SYu Zhiguo 9773c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9783c8e0316SYu Zhiguo nfsd_attrmask); 9793c8e0316SYu Zhiguo if (status) 9803c8e0316SYu Zhiguo goto out; 9813c8e0316SYu Zhiguo 9821da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 983ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 984ca364317SJ.Bruce Fields setattr->sa_acl); 9851da177e4SLinus Torvalds if (status) 98618f335afSDave Hansen goto out; 98718032ca0SDavid Quigley if (setattr->sa_label.len) 98818032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 98918032ca0SDavid Quigley &setattr->sa_label); 99018032ca0SDavid Quigley if (status) 99118032ca0SDavid Quigley goto out; 992ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9932a1aa489SArnd Bergmann 0, (time64_t)0); 99418f335afSDave Hansen out: 995bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9961da177e4SLinus Torvalds return status; 9971da177e4SLinus Torvalds } 9981da177e4SLinus Torvalds 9997191155bSJ.Bruce Fields static __be32 1000ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1001eb69853dSChristoph Hellwig union nfsd4_op_u *u) 10021da177e4SLinus Torvalds { 1003eb69853dSChristoph Hellwig struct nfsd4_write *write = &u->write; 10041da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 10055c4583b2SJeff Layton struct nfsd_file *nf = NULL; 1006b37ad28bSAl Viro __be32 status = nfs_ok; 100731dec253SDavid Shaw unsigned long cnt; 1008ffe1137bSJ. Bruce Fields int nvecs; 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 10111da177e4SLinus Torvalds return nfserr_inval; 10121da177e4SLinus Torvalds 1013d890be15SChuck Lever cnt = write->wr_buflen; 1014d890be15SChuck Lever trace_nfsd_write_start(rqstp, &cstate->current_fh, 1015d890be15SChuck Lever write->wr_offset, cnt); 1016aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1017624322f1SOlga Kornievskaia stateid, WR_STATE, &nf, NULL); 1018375c5547SJ. Bruce Fields if (status) { 1019375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 1020375c5547SJ. Bruce Fields return status; 1021375c5547SJ. Bruce Fields } 1022375c5547SJ. Bruce Fields 10231da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 10241da177e4SLinus Torvalds 10253fd9557aSChuck Lever nvecs = svc_fill_write_vector(rqstp, write->wr_pagelist, 10263fd9557aSChuck Lever &write->wr_head, write->wr_buflen); 1027ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1028ffe1137bSJ. Bruce Fields 102916f8f894STrond Myklebust status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, 1030af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 103119e0663fSTrond Myklebust write->wr_how_written, 103219e0663fSTrond Myklebust (__be32 *)write->wr_verifier.data); 10335c4583b2SJeff Layton nfsd_file_put(nf); 10341da177e4SLinus Torvalds 103531dec253SDavid Shaw write->wr_bytes_written = cnt; 1036d890be15SChuck Lever trace_nfsd_write_done(rqstp, &cstate->current_fh, 1037d890be15SChuck Lever write->wr_offset, cnt); 10381da177e4SLinus Torvalds return status; 10391da177e4SLinus Torvalds } 10401da177e4SLinus Torvalds 104124bab491SAnna Schumaker static __be32 104229ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 10435c4583b2SJeff Layton stateid_t *src_stateid, struct nfsd_file **src, 10445c4583b2SJeff Layton stateid_t *dst_stateid, struct nfsd_file **dst) 1045ffa0160aSChristoph Hellwig { 1046ffa0160aSChristoph Hellwig __be32 status; 1047ffa0160aSChristoph Hellwig 104801310bb7SScott Mayhew if (!cstate->save_fh.fh_dentry) 104901310bb7SScott Mayhew return nfserr_nofilehandle; 105001310bb7SScott Mayhew 1051ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 1052624322f1SOlga Kornievskaia src_stateid, RD_STATE, src, NULL); 1053ffa0160aSChristoph Hellwig if (status) { 1054ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1055ffa0160aSChristoph Hellwig goto out; 1056ffa0160aSChristoph Hellwig } 1057ffa0160aSChristoph Hellwig 1058ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1059624322f1SOlga Kornievskaia dst_stateid, WR_STATE, dst, NULL); 1060ffa0160aSChristoph Hellwig if (status) { 1061ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1062ffa0160aSChristoph Hellwig goto out_put_src; 1063ffa0160aSChristoph Hellwig } 1064ffa0160aSChristoph Hellwig 1065ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 10665c4583b2SJeff Layton if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) || 10675c4583b2SJeff Layton !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) { 1068ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1069ffa0160aSChristoph Hellwig goto out_put_dst; 1070ffa0160aSChristoph Hellwig } 1071ffa0160aSChristoph Hellwig 107229ae7f9dSAnna Schumaker out: 107329ae7f9dSAnna Schumaker return status; 107429ae7f9dSAnna Schumaker out_put_dst: 10755c4583b2SJeff Layton nfsd_file_put(*dst); 107629ae7f9dSAnna Schumaker out_put_src: 10775c4583b2SJeff Layton nfsd_file_put(*src); 107829ae7f9dSAnna Schumaker goto out; 107929ae7f9dSAnna Schumaker } 108029ae7f9dSAnna Schumaker 108129ae7f9dSAnna Schumaker static __be32 108229ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1083eb69853dSChristoph Hellwig union nfsd4_op_u *u) 108429ae7f9dSAnna Schumaker { 1085eb69853dSChristoph Hellwig struct nfsd4_clone *clone = &u->clone; 10865c4583b2SJeff Layton struct nfsd_file *src, *dst; 108729ae7f9dSAnna Schumaker __be32 status; 108829ae7f9dSAnna Schumaker 108929ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 109029ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 109129ae7f9dSAnna Schumaker if (status) 109229ae7f9dSAnna Schumaker goto out; 109329ae7f9dSAnna Schumaker 1094b66ae6ddSTrond Myklebust status = nfsd4_clone_file_range(src, clone->cl_src_pos, 1095b66ae6ddSTrond Myklebust dst, clone->cl_dst_pos, clone->cl_count, 1096a25e3726STrond Myklebust EX_ISSYNC(cstate->current_fh.fh_export)); 1097ffa0160aSChristoph Hellwig 10985c4583b2SJeff Layton nfsd_file_put(dst); 10995c4583b2SJeff Layton nfsd_file_put(src); 1100ffa0160aSChristoph Hellwig out: 1101ffa0160aSChristoph Hellwig return status; 1102ffa0160aSChristoph Hellwig } 1103ffa0160aSChristoph Hellwig 1104e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy) 1105e0639dc5SOlga Kornievskaia { 1106e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1107e0639dc5SOlga Kornievskaia return; 1108e0639dc5SOlga Kornievskaia kfree(copy); 1109e0639dc5SOlga Kornievskaia } 1110e0639dc5SOlga Kornievskaia 1111e0639dc5SOlga Kornievskaia static bool 1112e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy) 1113e0639dc5SOlga Kornievskaia { 1114e0639dc5SOlga Kornievskaia bool value; 1115e0639dc5SOlga Kornievskaia 1116e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1117e0639dc5SOlga Kornievskaia value = copy->stopped; 1118e0639dc5SOlga Kornievskaia if (!copy->stopped) 1119e0639dc5SOlga Kornievskaia copy->stopped = true; 1120e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1121e0639dc5SOlga Kornievskaia return value; 1122e0639dc5SOlga Kornievskaia } 1123e0639dc5SOlga Kornievskaia 1124e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1125e0639dc5SOlga Kornievskaia { 1126e0639dc5SOlga Kornievskaia /* only 1 thread should stop the copy */ 1127e0639dc5SOlga Kornievskaia if (!check_and_set_stop_copy(copy)) 1128e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1129e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1130e0639dc5SOlga Kornievskaia } 1131e0639dc5SOlga Kornievskaia 1132e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1133e0639dc5SOlga Kornievskaia { 1134e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1135e0639dc5SOlga Kornievskaia 1136e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1137e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1138e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1139e0639dc5SOlga Kornievskaia copies); 1140e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1141e0639dc5SOlga Kornievskaia } 1142e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1143e0639dc5SOlga Kornievskaia return copy; 1144e0639dc5SOlga Kornievskaia } 1145e0639dc5SOlga Kornievskaia 1146e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1147e0639dc5SOlga Kornievskaia { 1148e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1149e0639dc5SOlga Kornievskaia 1150e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1151e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1152e0639dc5SOlga Kornievskaia } 1153ce0887acSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 1154ce0887acSOlga Kornievskaia 1155ce0887acSOlga Kornievskaia extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1156ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1157ce0887acSOlga Kornievskaia nfs4_stateid *stateid); 1158ce0887acSOlga Kornievskaia extern void nfs42_ssc_close(struct file *filep); 1159ce0887acSOlga Kornievskaia 1160ce0887acSOlga Kornievskaia extern void nfs_sb_deactive(struct super_block *sb); 1161ce0887acSOlga Kornievskaia 1162ce0887acSOlga Kornievskaia #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys" 1163ce0887acSOlga Kornievskaia 1164f2453978SChuck Lever /* 1165ce0887acSOlga Kornievskaia * Support one copy source server for now. 1166ce0887acSOlga Kornievskaia */ 1167ce0887acSOlga Kornievskaia static __be32 1168ce0887acSOlga Kornievskaia nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp, 1169ce0887acSOlga Kornievskaia struct vfsmount **mount) 1170ce0887acSOlga Kornievskaia { 1171ce0887acSOlga Kornievskaia struct file_system_type *type; 1172ce0887acSOlga Kornievskaia struct vfsmount *ss_mnt; 1173ce0887acSOlga Kornievskaia struct nfs42_netaddr *naddr; 1174ce0887acSOlga Kornievskaia struct sockaddr_storage tmp_addr; 1175ce0887acSOlga Kornievskaia size_t tmp_addrlen, match_netid_len = 3; 1176ce0887acSOlga Kornievskaia char *startsep = "", *endsep = "", *match_netid = "tcp"; 1177ce0887acSOlga Kornievskaia char *ipaddr, *dev_name, *raw_data; 1178b8290ca2SOlga Kornievskaia int len, raw_len; 1179b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1180ce0887acSOlga Kornievskaia 1181ce0887acSOlga Kornievskaia naddr = &nss->u.nl4_addr; 1182ce0887acSOlga Kornievskaia tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr, 1183ce0887acSOlga Kornievskaia naddr->addr_len, 1184ce0887acSOlga Kornievskaia (struct sockaddr *)&tmp_addr, 1185ce0887acSOlga Kornievskaia sizeof(tmp_addr)); 1186ce0887acSOlga Kornievskaia if (tmp_addrlen == 0) 1187ce0887acSOlga Kornievskaia goto out_err; 1188ce0887acSOlga Kornievskaia 1189ce0887acSOlga Kornievskaia if (tmp_addr.ss_family == AF_INET6) { 1190ce0887acSOlga Kornievskaia startsep = "["; 1191ce0887acSOlga Kornievskaia endsep = "]"; 1192ce0887acSOlga Kornievskaia match_netid = "tcp6"; 1193ce0887acSOlga Kornievskaia match_netid_len = 4; 1194ce0887acSOlga Kornievskaia } 1195ce0887acSOlga Kornievskaia 1196ce0887acSOlga Kornievskaia if (naddr->netid_len != match_netid_len || 1197ce0887acSOlga Kornievskaia strncmp(naddr->netid, match_netid, naddr->netid_len)) 1198ce0887acSOlga Kornievskaia goto out_err; 1199ce0887acSOlga Kornievskaia 1200ce0887acSOlga Kornievskaia /* Construct the raw data for the vfs_kern_mount call */ 1201ce0887acSOlga Kornievskaia len = RPC_MAX_ADDRBUFLEN + 1; 1202ce0887acSOlga Kornievskaia ipaddr = kzalloc(len, GFP_KERNEL); 1203ce0887acSOlga Kornievskaia if (!ipaddr) 1204ce0887acSOlga Kornievskaia goto out_err; 1205ce0887acSOlga Kornievskaia 1206ce0887acSOlga Kornievskaia rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len); 1207ce0887acSOlga Kornievskaia 1208ce0887acSOlga Kornievskaia /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/ 1209ce0887acSOlga Kornievskaia 1210ce0887acSOlga Kornievskaia raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr); 1211ce0887acSOlga Kornievskaia raw_data = kzalloc(raw_len, GFP_KERNEL); 1212ce0887acSOlga Kornievskaia if (!raw_data) 1213ce0887acSOlga Kornievskaia goto out_free_ipaddr; 1214ce0887acSOlga Kornievskaia 1215ce0887acSOlga Kornievskaia snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr); 1216ce0887acSOlga Kornievskaia 1217b8290ca2SOlga Kornievskaia status = nfserr_nodev; 1218ce0887acSOlga Kornievskaia type = get_fs_type("nfs"); 1219ce0887acSOlga Kornievskaia if (!type) 1220ce0887acSOlga Kornievskaia goto out_free_rawdata; 1221ce0887acSOlga Kornievskaia 1222ce0887acSOlga Kornievskaia /* Set the server:<export> for the vfs_kern_mount call */ 1223ce0887acSOlga Kornievskaia dev_name = kzalloc(len + 5, GFP_KERNEL); 1224ce0887acSOlga Kornievskaia if (!dev_name) 1225ce0887acSOlga Kornievskaia goto out_free_rawdata; 1226ce0887acSOlga Kornievskaia snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep); 1227ce0887acSOlga Kornievskaia 1228ce0887acSOlga Kornievskaia /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */ 1229ce0887acSOlga Kornievskaia ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data); 1230ce0887acSOlga Kornievskaia module_put(type->owner); 1231ce0887acSOlga Kornievskaia if (IS_ERR(ss_mnt)) 1232ce0887acSOlga Kornievskaia goto out_free_devname; 1233ce0887acSOlga Kornievskaia 1234ce0887acSOlga Kornievskaia status = 0; 1235ce0887acSOlga Kornievskaia *mount = ss_mnt; 1236ce0887acSOlga Kornievskaia 1237ce0887acSOlga Kornievskaia out_free_devname: 1238ce0887acSOlga Kornievskaia kfree(dev_name); 1239ce0887acSOlga Kornievskaia out_free_rawdata: 1240ce0887acSOlga Kornievskaia kfree(raw_data); 1241ce0887acSOlga Kornievskaia out_free_ipaddr: 1242ce0887acSOlga Kornievskaia kfree(ipaddr); 1243ce0887acSOlga Kornievskaia out_err: 1244ce0887acSOlga Kornievskaia return status; 1245ce0887acSOlga Kornievskaia } 1246ce0887acSOlga Kornievskaia 1247ce0887acSOlga Kornievskaia static void 1248ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1249ce0887acSOlga Kornievskaia { 1250ce0887acSOlga Kornievskaia nfs_sb_deactive(ss_mnt->mnt_sb); 1251ce0887acSOlga Kornievskaia mntput(ss_mnt); 1252ce0887acSOlga Kornievskaia } 1253ce0887acSOlga Kornievskaia 1254f2453978SChuck Lever /* 1255ce0887acSOlga Kornievskaia * Verify COPY destination stateid. 1256f2453978SChuck Lever * 1257ce0887acSOlga Kornievskaia * Connect to the source server with NFSv4.1. 1258ce0887acSOlga Kornievskaia * Create the source struct file for nfsd_copy_range. 1259ce0887acSOlga Kornievskaia * Called with COPY cstate: 1260ce0887acSOlga Kornievskaia * SAVED_FH: source filehandle 1261ce0887acSOlga Kornievskaia * CURRENT_FH: destination filehandle 1262ce0887acSOlga Kornievskaia */ 1263ce0887acSOlga Kornievskaia static __be32 1264ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1265ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1266ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, struct vfsmount **mount) 1267ce0887acSOlga Kornievskaia { 1268ce0887acSOlga Kornievskaia struct svc_fh *s_fh = NULL; 1269ce0887acSOlga Kornievskaia stateid_t *s_stid = ©->cp_src_stateid; 1270b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1271ce0887acSOlga Kornievskaia 1272ce0887acSOlga Kornievskaia /* Verify the destination stateid and set dst struct file*/ 1273ce0887acSOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1274ce0887acSOlga Kornievskaia ©->cp_dst_stateid, 1275ce0887acSOlga Kornievskaia WR_STATE, ©->nf_dst, NULL); 1276ce0887acSOlga Kornievskaia if (status) 1277ce0887acSOlga Kornievskaia goto out; 1278ce0887acSOlga Kornievskaia 1279ce0887acSOlga Kornievskaia status = nfsd4_interssc_connect(©->cp_src, rqstp, mount); 1280ce0887acSOlga Kornievskaia if (status) 1281ce0887acSOlga Kornievskaia goto out; 1282ce0887acSOlga Kornievskaia 1283ce0887acSOlga Kornievskaia s_fh = &cstate->save_fh; 1284ce0887acSOlga Kornievskaia 1285ce0887acSOlga Kornievskaia copy->c_fh.size = s_fh->fh_handle.fh_size; 1286ce0887acSOlga Kornievskaia memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_base, copy->c_fh.size); 12873f9544caSOlga Kornievskaia copy->stateid.seqid = cpu_to_be32(s_stid->si_generation); 1288ce0887acSOlga Kornievskaia memcpy(copy->stateid.other, (void *)&s_stid->si_opaque, 1289ce0887acSOlga Kornievskaia sizeof(stateid_opaque_t)); 1290ce0887acSOlga Kornievskaia 1291ce0887acSOlga Kornievskaia status = 0; 1292ce0887acSOlga Kornievskaia out: 1293ce0887acSOlga Kornievskaia return status; 1294ce0887acSOlga Kornievskaia } 1295ce0887acSOlga Kornievskaia 1296ce0887acSOlga Kornievskaia static void 1297ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, 1298ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1299ce0887acSOlga Kornievskaia { 1300ce0887acSOlga Kornievskaia nfs42_ssc_close(src->nf_file); 1301ce0887acSOlga Kornievskaia nfsd_file_put(src); 1302ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1303ce0887acSOlga Kornievskaia mntput(ss_mnt); 1304ce0887acSOlga Kornievskaia } 1305ce0887acSOlga Kornievskaia 1306ce0887acSOlga Kornievskaia #else /* CONFIG_NFSD_V4_2_INTER_SSC */ 1307ce0887acSOlga Kornievskaia 1308ce0887acSOlga Kornievskaia static __be32 1309ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1310ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1311ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, 1312ce0887acSOlga Kornievskaia struct vfsmount **mount) 1313ce0887acSOlga Kornievskaia { 1314ce0887acSOlga Kornievskaia *mount = NULL; 1315b8290ca2SOlga Kornievskaia return nfserr_inval; 1316ce0887acSOlga Kornievskaia } 1317ce0887acSOlga Kornievskaia 1318ce0887acSOlga Kornievskaia static void 1319ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, 1320ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1321ce0887acSOlga Kornievskaia { 1322ce0887acSOlga Kornievskaia } 1323ce0887acSOlga Kornievskaia 1324ce0887acSOlga Kornievskaia static void 1325ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1326ce0887acSOlga Kornievskaia { 1327ce0887acSOlga Kornievskaia } 1328ce0887acSOlga Kornievskaia 1329ce0887acSOlga Kornievskaia static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1330ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1331ce0887acSOlga Kornievskaia nfs4_stateid *stateid) 1332ce0887acSOlga Kornievskaia { 1333ce0887acSOlga Kornievskaia return NULL; 1334ce0887acSOlga Kornievskaia } 1335ce0887acSOlga Kornievskaia #endif /* CONFIG_NFSD_V4_2_INTER_SSC */ 1336ce0887acSOlga Kornievskaia 1337ce0887acSOlga Kornievskaia static __be32 1338ce0887acSOlga Kornievskaia nfsd4_setup_intra_ssc(struct svc_rqst *rqstp, 1339ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1340ce0887acSOlga Kornievskaia struct nfsd4_copy *copy) 1341ce0887acSOlga Kornievskaia { 1342ce0887acSOlga Kornievskaia return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 1343ce0887acSOlga Kornievskaia ©->nf_src, ©->cp_dst_stateid, 1344ce0887acSOlga Kornievskaia ©->nf_dst); 1345ce0887acSOlga Kornievskaia } 1346ce0887acSOlga Kornievskaia 1347ce0887acSOlga Kornievskaia static void 1348ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst) 1349ce0887acSOlga Kornievskaia { 1350ce0887acSOlga Kornievskaia nfsd_file_put(src); 1351ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1352ce0887acSOlga Kornievskaia } 1353e0639dc5SOlga Kornievskaia 1354e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1355e0639dc5SOlga Kornievskaia { 1356e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); 1357e0639dc5SOlga Kornievskaia 1358e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1359e0639dc5SOlga Kornievskaia } 1360e0639dc5SOlga Kornievskaia 1361e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1362e0639dc5SOlga Kornievskaia struct rpc_task *task) 1363e0639dc5SOlga Kornievskaia { 1364e0639dc5SOlga Kornievskaia return 1; 1365e0639dc5SOlga Kornievskaia } 1366e0639dc5SOlga Kornievskaia 1367e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1368e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1369e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1370e0639dc5SOlga Kornievskaia }; 1371e0639dc5SOlga Kornievskaia 1372e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1373e0639dc5SOlga Kornievskaia { 1374e0639dc5SOlga Kornievskaia copy->cp_res.wr_stable_how = NFS_UNSTABLE; 1375e0639dc5SOlga Kornievskaia copy->cp_synchronous = sync; 1376e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1377e0639dc5SOlga Kornievskaia } 1378e0639dc5SOlga Kornievskaia 1379e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) 1380e0639dc5SOlga Kornievskaia { 1381e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1382e0639dc5SOlga Kornievskaia size_t bytes_total = copy->cp_count; 1383e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1384e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1385e0639dc5SOlga Kornievskaia 1386e0639dc5SOlga Kornievskaia do { 1387e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1388e0639dc5SOlga Kornievskaia break; 13895c4583b2SJeff Layton bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file, 13905c4583b2SJeff Layton src_pos, copy->nf_dst->nf_file, dst_pos, 13915c4583b2SJeff Layton bytes_total); 1392e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1393e0639dc5SOlga Kornievskaia break; 1394e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1395e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1396e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1397e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1398e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1399e0639dc5SOlga Kornievskaia return bytes_copied; 1400e0639dc5SOlga Kornievskaia } 1401e0639dc5SOlga Kornievskaia 1402e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1403e0639dc5SOlga Kornievskaia { 1404e0639dc5SOlga Kornievskaia __be32 status; 1405e0639dc5SOlga Kornievskaia ssize_t bytes; 1406e0639dc5SOlga Kornievskaia 1407e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1408e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1409e0639dc5SOlga Kornievskaia * to get the error 1410e0639dc5SOlga Kornievskaia */ 1411e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1412e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1413e0639dc5SOlga Kornievskaia else { 1414e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1415e0639dc5SOlga Kornievskaia status = nfs_ok; 1416e0639dc5SOlga Kornievskaia } 1417e0639dc5SOlga Kornievskaia 1418ce0887acSOlga Kornievskaia if (!copy->cp_intra) /* Inter server SSC */ 1419ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src, 1420ce0887acSOlga Kornievskaia copy->nf_dst); 1421ce0887acSOlga Kornievskaia else 1422ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); 1423ce0887acSOlga Kornievskaia 1424e0639dc5SOlga Kornievskaia return status; 1425e0639dc5SOlga Kornievskaia } 1426e0639dc5SOlga Kornievskaia 1427ce0887acSOlga Kornievskaia static int dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1428e0639dc5SOlga Kornievskaia { 1429e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1430e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1431e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1432e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1433e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1434e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1435e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 14365c4583b2SJeff Layton dst->nf_dst = nfsd_file_get(src->nf_dst); 1437ce0887acSOlga Kornievskaia dst->cp_intra = src->cp_intra; 1438ce0887acSOlga Kornievskaia if (src->cp_intra) /* for inter, file_src doesn't exist yet */ 14395c4583b2SJeff Layton dst->nf_src = nfsd_file_get(src->nf_src); 1440ce0887acSOlga Kornievskaia 1441e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1442ce0887acSOlga Kornievskaia memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server)); 1443ce0887acSOlga Kornievskaia memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); 1444ce0887acSOlga Kornievskaia memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); 1445ce0887acSOlga Kornievskaia dst->ss_mnt = src->ss_mnt; 1446ce0887acSOlga Kornievskaia 1447ce0887acSOlga Kornievskaia return 0; 1448e0639dc5SOlga Kornievskaia } 1449e0639dc5SOlga Kornievskaia 1450e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1451e0639dc5SOlga Kornievskaia { 1452624322f1SOlga Kornievskaia nfs4_free_copy_state(copy); 14535c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 14542e577f0fSOlga Kornievskaia if (copy->cp_intra) 14555c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 1456e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1457e0639dc5SOlga Kornievskaia list_del(©->copies); 1458e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1459e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1460e0639dc5SOlga Kornievskaia } 1461e0639dc5SOlga Kornievskaia 1462e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1463e0639dc5SOlga Kornievskaia { 1464e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1465e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1466e0639dc5SOlga Kornievskaia 1467ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1468ce0887acSOlga Kornievskaia copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); 1469ce0887acSOlga Kornievskaia if (!copy->nf_src) { 1470ce0887acSOlga Kornievskaia copy->nfserr = nfserr_serverfault; 1471ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1472ce0887acSOlga Kornievskaia goto do_callback; 1473ce0887acSOlga Kornievskaia } 1474ce0887acSOlga Kornievskaia copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, 1475ce0887acSOlga Kornievskaia ©->stateid); 1476ce0887acSOlga Kornievskaia if (IS_ERR(copy->nf_src->nf_file)) { 1477ce0887acSOlga Kornievskaia copy->nfserr = nfserr_offload_denied; 1478ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1479ce0887acSOlga Kornievskaia goto do_callback; 1480ce0887acSOlga Kornievskaia } 1481ce0887acSOlga Kornievskaia } 1482ce0887acSOlga Kornievskaia 1483e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1484ce0887acSOlga Kornievskaia do_callback: 1485e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1486e0639dc5SOlga Kornievskaia if (!cb_copy) 1487e0639dc5SOlga Kornievskaia goto out; 1488e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1489e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1490e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1491e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1492e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1493e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 1494e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1495e0639dc5SOlga Kornievskaia out: 1496ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1497ce0887acSOlga Kornievskaia kfree(copy->nf_src); 1498e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1499e0639dc5SOlga Kornievskaia return 0; 1500e0639dc5SOlga Kornievskaia } 1501e0639dc5SOlga Kornievskaia 1502ffa0160aSChristoph Hellwig static __be32 150329ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1504eb69853dSChristoph Hellwig union nfsd4_op_u *u) 150529ae7f9dSAnna Schumaker { 1506eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 150729ae7f9dSAnna Schumaker __be32 status; 1508e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 150929ae7f9dSAnna Schumaker 1510ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1511ce0887acSOlga Kornievskaia if (!inter_copy_offload_enable || copy->cp_synchronous) { 1512ce0887acSOlga Kornievskaia status = nfserr_notsupp; 151329ae7f9dSAnna Schumaker goto out; 1514ce0887acSOlga Kornievskaia } 1515ce0887acSOlga Kornievskaia status = nfsd4_setup_inter_ssc(rqstp, cstate, copy, 1516ce0887acSOlga Kornievskaia ©->ss_mnt); 1517ce0887acSOlga Kornievskaia if (status) 1518ce0887acSOlga Kornievskaia return nfserr_offload_denied; 1519ce0887acSOlga Kornievskaia } else { 1520ce0887acSOlga Kornievskaia status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); 1521ce0887acSOlga Kornievskaia if (status) 1522ce0887acSOlga Kornievskaia return status; 1523ce0887acSOlga Kornievskaia } 152429ae7f9dSAnna Schumaker 1525e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1526e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1527e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1528e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1529e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 153029ae7f9dSAnna Schumaker 1531e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1532e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1533e0639dc5SOlga Kornievskaia if (!async_copy) 1534ce0887acSOlga Kornievskaia goto out_err; 1535ce0887acSOlga Kornievskaia if (!nfs4_init_copy_state(nn, copy)) 1536ce0887acSOlga Kornievskaia goto out_err; 1537e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1538e0639dc5SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid, 1539e0639dc5SOlga Kornievskaia sizeof(copy->cp_stateid)); 1540ce0887acSOlga Kornievskaia status = dup_copy_fields(copy, async_copy); 1541ce0887acSOlga Kornievskaia if (status) 1542ce0887acSOlga Kornievskaia goto out_err; 1543e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1544e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1545e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1546e0639dc5SOlga Kornievskaia goto out_err; 1547e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1548e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1549e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1550e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1551e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1552e0639dc5SOlga Kornievskaia status = nfs_ok; 1553ce0887acSOlga Kornievskaia } else { 1554e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 1555ce0887acSOlga Kornievskaia } 155629ae7f9dSAnna Schumaker out: 155729ae7f9dSAnna Schumaker return status; 1558e0639dc5SOlga Kornievskaia out_err: 155918f428d4SOlga Kornievskaia if (async_copy) 1560e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1561ce0887acSOlga Kornievskaia status = nfserrno(-ENOMEM); 1562ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1563ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1564e0639dc5SOlga Kornievskaia goto out; 1565e0639dc5SOlga Kornievskaia } 1566e0639dc5SOlga Kornievskaia 1567e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1568e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1569e0639dc5SOlga Kornievskaia { 1570e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1571e0639dc5SOlga Kornievskaia 1572e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1573e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1574ce0887acSOlga Kornievskaia if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE)) 1575e0639dc5SOlga Kornievskaia continue; 1576e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1577e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1578e0639dc5SOlga Kornievskaia return copy; 1579e0639dc5SOlga Kornievskaia } 1580e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1581e0639dc5SOlga Kornievskaia return NULL; 158229ae7f9dSAnna Schumaker } 158329ae7f9dSAnna Schumaker 158429ae7f9dSAnna Schumaker static __be32 1585885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1586885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1587885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1588885e2bf3SOlga Kornievskaia { 1589e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1590e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1591e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1592e0639dc5SOlga Kornievskaia 1593e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1594ce0887acSOlga Kornievskaia if (!copy) { 1595ce0887acSOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1596e0639dc5SOlga Kornievskaia 1597ce0887acSOlga Kornievskaia return manage_cpntf_state(nn, &os->stateid, clp, NULL); 1598ce0887acSOlga Kornievskaia } else 1599ce0887acSOlga Kornievskaia nfsd4_stop_copy(copy); 1600ce0887acSOlga Kornievskaia 1601ce0887acSOlga Kornievskaia return nfs_ok; 1602885e2bf3SOlga Kornievskaia } 1603885e2bf3SOlga Kornievskaia 1604885e2bf3SOlga Kornievskaia static __be32 160551911868SOlga Kornievskaia nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 160651911868SOlga Kornievskaia union nfsd4_op_u *u) 160751911868SOlga Kornievskaia { 1608624322f1SOlga Kornievskaia struct nfsd4_copy_notify *cn = &u->copy_notify; 1609624322f1SOlga Kornievskaia __be32 status; 1610624322f1SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1611624322f1SOlga Kornievskaia struct nfs4_stid *stid; 1612624322f1SOlga Kornievskaia struct nfs4_cpntf_state *cps; 1613624322f1SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1614624322f1SOlga Kornievskaia 1615624322f1SOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1616624322f1SOlga Kornievskaia &cn->cpn_src_stateid, RD_STATE, NULL, 1617624322f1SOlga Kornievskaia &stid); 1618624322f1SOlga Kornievskaia if (status) 1619624322f1SOlga Kornievskaia return status; 1620624322f1SOlga Kornievskaia 1621624322f1SOlga Kornievskaia cn->cpn_sec = nn->nfsd4_lease; 1622624322f1SOlga Kornievskaia cn->cpn_nsec = 0; 1623624322f1SOlga Kornievskaia 1624624322f1SOlga Kornievskaia status = nfserrno(-ENOMEM); 1625624322f1SOlga Kornievskaia cps = nfs4_alloc_init_cpntf_state(nn, stid); 1626624322f1SOlga Kornievskaia if (!cps) 1627624322f1SOlga Kornievskaia goto out; 1628624322f1SOlga Kornievskaia memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t)); 1629624322f1SOlga Kornievskaia memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t)); 1630624322f1SOlga Kornievskaia memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t)); 1631624322f1SOlga Kornievskaia 1632624322f1SOlga Kornievskaia /* For now, only return one server address in cpn_src, the 1633624322f1SOlga Kornievskaia * address used by the client to connect to this server. 1634624322f1SOlga Kornievskaia */ 1635624322f1SOlga Kornievskaia cn->cpn_src.nl4_type = NL4_NETADDR; 1636624322f1SOlga Kornievskaia status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, 1637624322f1SOlga Kornievskaia &cn->cpn_src.u.nl4_addr); 1638624322f1SOlga Kornievskaia WARN_ON_ONCE(status); 1639624322f1SOlga Kornievskaia if (status) { 1640624322f1SOlga Kornievskaia nfs4_put_cpntf_state(nn, cps); 1641624322f1SOlga Kornievskaia goto out; 1642624322f1SOlga Kornievskaia } 1643624322f1SOlga Kornievskaia out: 1644624322f1SOlga Kornievskaia nfs4_put_stid(stid); 1645624322f1SOlga Kornievskaia return status; 164651911868SOlga Kornievskaia } 164751911868SOlga Kornievskaia 164851911868SOlga Kornievskaia static __be32 164995d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 165095d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 165195d871f0SAnna Schumaker { 16520d4d6720SJ. Bruce Fields __be32 status; 16535c4583b2SJeff Layton struct nfsd_file *nf; 165495d871f0SAnna Schumaker 1655aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 165695d871f0SAnna Schumaker &fallocate->falloc_stateid, 1657624322f1SOlga Kornievskaia WR_STATE, &nf, NULL); 165895d871f0SAnna Schumaker if (status != nfs_ok) { 165995d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 166095d871f0SAnna Schumaker return status; 166195d871f0SAnna Schumaker } 166295d871f0SAnna Schumaker 16635c4583b2SJeff Layton status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, 166495d871f0SAnna Schumaker fallocate->falloc_offset, 166595d871f0SAnna Schumaker fallocate->falloc_length, 166695d871f0SAnna Schumaker flags); 16675c4583b2SJeff Layton nfsd_file_put(nf); 166895d871f0SAnna Schumaker return status; 166995d871f0SAnna Schumaker } 16706308bc98SOlga Kornievskaia static __be32 16716308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 16726308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 16736308bc98SOlga Kornievskaia union nfsd4_op_u *u) 16746308bc98SOlga Kornievskaia { 1675e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1676e0639dc5SOlga Kornievskaia __be32 status = 0; 1677e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1678e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1679e0639dc5SOlga Kornievskaia 1680e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1681e0639dc5SOlga Kornievskaia if (copy) { 1682e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 1683e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1684e0639dc5SOlga Kornievskaia } else 1685e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1686e0639dc5SOlga Kornievskaia 1687e0639dc5SOlga Kornievskaia return status; 16886308bc98SOlga Kornievskaia } 168995d871f0SAnna Schumaker 169095d871f0SAnna Schumaker static __be32 169195d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1692eb69853dSChristoph Hellwig union nfsd4_op_u *u) 169395d871f0SAnna Schumaker { 1694eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 169595d871f0SAnna Schumaker } 169695d871f0SAnna Schumaker 169795d871f0SAnna Schumaker static __be32 1698b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1699eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1700b0cb9085SAnna Schumaker { 1701eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 1702b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1703b0cb9085SAnna Schumaker } 1704b0cb9085SAnna Schumaker 1705b0cb9085SAnna Schumaker static __be32 170624bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1707eb69853dSChristoph Hellwig union nfsd4_op_u *u) 170824bab491SAnna Schumaker { 1709eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 171024bab491SAnna Schumaker int whence; 171124bab491SAnna Schumaker __be32 status; 17125c4583b2SJeff Layton struct nfsd_file *nf; 171324bab491SAnna Schumaker 1714aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 171524bab491SAnna Schumaker &seek->seek_stateid, 1716624322f1SOlga Kornievskaia RD_STATE, &nf, NULL); 171724bab491SAnna Schumaker if (status) { 171824bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 171924bab491SAnna Schumaker return status; 172024bab491SAnna Schumaker } 172124bab491SAnna Schumaker 172224bab491SAnna Schumaker switch (seek->seek_whence) { 172324bab491SAnna Schumaker case NFS4_CONTENT_DATA: 172424bab491SAnna Schumaker whence = SEEK_DATA; 172524bab491SAnna Schumaker break; 172624bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 172724bab491SAnna Schumaker whence = SEEK_HOLE; 172824bab491SAnna Schumaker break; 172924bab491SAnna Schumaker default: 173024bab491SAnna Schumaker status = nfserr_union_notsupp; 173124bab491SAnna Schumaker goto out; 173224bab491SAnna Schumaker } 173324bab491SAnna Schumaker 173424bab491SAnna Schumaker /* 173524bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 173624bab491SAnna Schumaker * should ever file->f_pos. 173724bab491SAnna Schumaker */ 17385c4583b2SJeff Layton seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); 173924bab491SAnna Schumaker if (seek->seek_pos < 0) 174024bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 17415c4583b2SJeff Layton else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) 174224bab491SAnna Schumaker seek->seek_eof = true; 174324bab491SAnna Schumaker 174424bab491SAnna Schumaker out: 17455c4583b2SJeff Layton nfsd_file_put(nf); 174624bab491SAnna Schumaker return status; 174724bab491SAnna Schumaker } 174824bab491SAnna Schumaker 17491da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 17501da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 17511da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 17521da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 17531da177e4SLinus Torvalds */ 1754b37ad28bSAl Viro static __be32 1755c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1756ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 17571da177e4SLinus Torvalds { 17582ebbc012SAl Viro __be32 *buf, *p; 17591da177e4SLinus Torvalds int count; 1760b37ad28bSAl Viro __be32 status; 17611da177e4SLinus Torvalds 17628837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 17631da177e4SLinus Torvalds if (status) 17641da177e4SLinus Torvalds return status; 17651da177e4SLinus Torvalds 17663c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 17673c8e0316SYu Zhiguo if (status) 17683c8e0316SYu Zhiguo return status; 17693c8e0316SYu Zhiguo 17701da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 17711da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 17721da177e4SLinus Torvalds return nfserr_inval; 17731da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 17741da177e4SLinus Torvalds return nfserr_inval; 17751da177e4SLinus Torvalds 17761da177e4SLinus Torvalds /* count in words: 17771da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 17781da177e4SLinus Torvalds */ 17791da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 17801da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 17811da177e4SLinus Torvalds if (!buf) 17823e772463SJ. Bruce Fields return nfserr_jukebox; 17831da177e4SLinus Torvalds 178484822d0bSJ. Bruce Fields p = buf; 1785d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1786ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1787d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1788d5184658SJ. Bruce Fields verify->ve_bmval, 1789406a7ea9SFrank Filz rqstp, 0); 179041ae6e71SJ. Bruce Fields /* 179141ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 179241ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 179341ae6e71SJ. Bruce Fields */ 179484822d0bSJ. Bruce Fields if (status == nfserr_resource) 17951da177e4SLinus Torvalds status = nfserr_not_same; 17961da177e4SLinus Torvalds if (status) 17971da177e4SLinus Torvalds goto out_kfree; 17981da177e4SLinus Torvalds 179995ec28cdSBenny Halevy /* skip bitmap */ 180095ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 18011da177e4SLinus Torvalds status = nfserr_not_same; 18021da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 18031da177e4SLinus Torvalds goto out_kfree; 18041da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 18051da177e4SLinus Torvalds status = nfserr_same; 18061da177e4SLinus Torvalds 18071da177e4SLinus Torvalds out_kfree: 18081da177e4SLinus Torvalds kfree(buf); 18091da177e4SLinus Torvalds return status; 18101da177e4SLinus Torvalds } 18111da177e4SLinus Torvalds 1812c954e2a5SJ.Bruce Fields static __be32 1813c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1814eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1815c954e2a5SJ.Bruce Fields { 1816c954e2a5SJ.Bruce Fields __be32 status; 1817c954e2a5SJ.Bruce Fields 1818eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 1819c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1820c954e2a5SJ.Bruce Fields } 1821c954e2a5SJ.Bruce Fields 1822c954e2a5SJ.Bruce Fields static __be32 1823c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1824eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1825c954e2a5SJ.Bruce Fields { 1826c954e2a5SJ.Bruce Fields __be32 status; 1827c954e2a5SJ.Bruce Fields 1828eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 1829c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1830c954e2a5SJ.Bruce Fields } 1831c954e2a5SJ.Bruce Fields 18329cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 18339cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 18349cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 18359cf514ccSChristoph Hellwig { 18368a4c3926SJeff Layton if (!exp->ex_layout_types) { 18379cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 18389cf514ccSChristoph Hellwig return NULL; 18399cf514ccSChristoph Hellwig } 18409cf514ccSChristoph Hellwig 1841b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1842b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 18439cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 18449cf514ccSChristoph Hellwig __func__, layout_type); 18459cf514ccSChristoph Hellwig return NULL; 18469cf514ccSChristoph Hellwig } 18479cf514ccSChristoph Hellwig 18489cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 18499cf514ccSChristoph Hellwig } 18509cf514ccSChristoph Hellwig 18519cf514ccSChristoph Hellwig static __be32 18529cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 1853eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 18549cf514ccSChristoph Hellwig { 1855eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 18569cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 18579cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 18589cf514ccSChristoph Hellwig struct svc_export *exp; 18599cf514ccSChristoph Hellwig __be32 nfserr; 18609cf514ccSChristoph Hellwig 18619cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 18629cf514ccSChristoph Hellwig __func__, 18639cf514ccSChristoph Hellwig gdp->gd_layout_type, 18649cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 18659cf514ccSChristoph Hellwig gdp->gd_maxcount); 18669cf514ccSChristoph Hellwig 18679cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 18689cf514ccSChristoph Hellwig if (!map) { 18699cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 18709cf514ccSChristoph Hellwig __func__); 18719cf514ccSChristoph Hellwig return nfserr_noent; 18729cf514ccSChristoph Hellwig } 18739cf514ccSChristoph Hellwig 18749cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 18759cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 18769cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 18779cf514ccSChristoph Hellwig return nfserr_noent; 18789cf514ccSChristoph Hellwig } 18799cf514ccSChristoph Hellwig 18809cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 18819cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 18829cf514ccSChristoph Hellwig if (!ops) 18839cf514ccSChristoph Hellwig goto out; 18849cf514ccSChristoph Hellwig 18859cf514ccSChristoph Hellwig nfserr = nfs_ok; 1886f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 1887f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 1888d7c920d1STom Haynes rqstp, cstate->session->se_client, gdp); 1889f99d4fbdSChristoph Hellwig } 18909cf514ccSChristoph Hellwig 18919cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 18929cf514ccSChristoph Hellwig out: 1893a1420384SKinglong Mee exp_put(exp); 18949cf514ccSChristoph Hellwig return nfserr; 18959cf514ccSChristoph Hellwig } 18969cf514ccSChristoph Hellwig 189734b1744cSJ. Bruce Fields static void 189834b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 189934b1744cSJ. Bruce Fields { 190034b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 190134b1744cSJ. Bruce Fields } 190234b1744cSJ. Bruce Fields 19039cf514ccSChristoph Hellwig static __be32 19049cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 1905eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 19069cf514ccSChristoph Hellwig { 1907eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 19089cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 19099cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 19109cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 19119cf514ccSChristoph Hellwig __be32 nfserr; 191266282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 19139cf514ccSChristoph Hellwig 19149cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 19159cf514ccSChristoph Hellwig case IOMODE_READ: 191666282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 19179cf514ccSChristoph Hellwig break; 19189cf514ccSChristoph Hellwig case IOMODE_RW: 191966282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 19209cf514ccSChristoph Hellwig break; 19219cf514ccSChristoph Hellwig default: 19229cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 19239cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 19249cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 19259cf514ccSChristoph Hellwig goto out; 19269cf514ccSChristoph Hellwig } 19279cf514ccSChristoph Hellwig 19289cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 19299cf514ccSChristoph Hellwig if (nfserr) 19309cf514ccSChristoph Hellwig goto out; 19319cf514ccSChristoph Hellwig 19329cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 19339cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 19349cf514ccSChristoph Hellwig if (!ops) 19359cf514ccSChristoph Hellwig goto out; 19369cf514ccSChristoph Hellwig 19379cf514ccSChristoph Hellwig /* 19389cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 19399cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 19409cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 19419cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 19429cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 19439cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 19449cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 19459cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 19469cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 19479cf514ccSChristoph Hellwig */ 19489cf514ccSChristoph Hellwig nfserr = nfserr_inval; 19499cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 19509cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 19519cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 19529cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 19539cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 19549cf514ccSChristoph Hellwig goto out; 19559cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 19569cf514ccSChristoph Hellwig goto out; 19579cf514ccSChristoph Hellwig 19589cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 19599cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 196031ef83dcSChristoph Hellwig if (nfserr) { 1961f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 19629cf514ccSChristoph Hellwig goto out; 196331ef83dcSChristoph Hellwig } 19649cf514ccSChristoph Hellwig 1965c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1966c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1967c5c707f9SChristoph Hellwig goto out_put_stid; 1968c5c707f9SChristoph Hellwig 19692b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 19709cf514ccSChristoph Hellwig current_fh, lgp); 19719cf514ccSChristoph Hellwig if (nfserr) 19729cf514ccSChristoph Hellwig goto out_put_stid; 19739cf514ccSChristoph Hellwig 19749cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 19759cf514ccSChristoph Hellwig 19769cf514ccSChristoph Hellwig out_put_stid: 1977cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 19789cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 19799cf514ccSChristoph Hellwig out: 19809cf514ccSChristoph Hellwig return nfserr; 19819cf514ccSChristoph Hellwig } 19829cf514ccSChristoph Hellwig 198334b1744cSJ. Bruce Fields static void 198434b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 198534b1744cSJ. Bruce Fields { 198634b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 198734b1744cSJ. Bruce Fields } 198834b1744cSJ. Bruce Fields 19899cf514ccSChristoph Hellwig static __be32 19909cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 1991eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 19929cf514ccSChristoph Hellwig { 1993eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 19949cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 19959cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 19969cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 19979cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 19989cf514ccSChristoph Hellwig struct inode *inode; 19999cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 20009cf514ccSChristoph Hellwig __be32 nfserr; 20019cf514ccSChristoph Hellwig 20029cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 20039cf514ccSChristoph Hellwig if (nfserr) 20049cf514ccSChristoph Hellwig goto out; 20059cf514ccSChristoph Hellwig 20069cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 20079cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 20089cf514ccSChristoph Hellwig if (!ops) 20099cf514ccSChristoph Hellwig goto out; 20102b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 20119cf514ccSChristoph Hellwig 20129cf514ccSChristoph Hellwig nfserr = nfserr_inval; 20139cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 20149cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 20159cf514ccSChristoph Hellwig goto out; 20169cf514ccSChristoph Hellwig } 20179cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 20189cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 20199cf514ccSChristoph Hellwig goto out; 20209cf514ccSChristoph Hellwig } 20219cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 20229cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 20239cf514ccSChristoph Hellwig goto out; 20249cf514ccSChristoph Hellwig } 20259cf514ccSChristoph Hellwig 20269cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 20279cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 20289cf514ccSChristoph Hellwig &ls); 20299cf514ccSChristoph Hellwig if (nfserr) { 2030f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 20319cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 20329cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 20339cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 20349cf514ccSChristoph Hellwig goto out; 20359cf514ccSChristoph Hellwig } 20369cf514ccSChristoph Hellwig 2037cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 2038cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 2039cc8a5532SJeff Layton 20409cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 20419cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 20429cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 20439cf514ccSChristoph Hellwig } else { 20449cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 20459cf514ccSChristoph Hellwig } 20469cf514ccSChristoph Hellwig 2047d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 20489cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 20499cf514ccSChristoph Hellwig out: 20509cf514ccSChristoph Hellwig return nfserr; 20519cf514ccSChristoph Hellwig } 20529cf514ccSChristoph Hellwig 20539cf514ccSChristoph Hellwig static __be32 20549cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 2055eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 20569cf514ccSChristoph Hellwig { 2057eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 20589cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 20599cf514ccSChristoph Hellwig __be32 nfserr; 20609cf514ccSChristoph Hellwig 20619cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 20629cf514ccSChristoph Hellwig if (nfserr) 20639cf514ccSChristoph Hellwig goto out; 20649cf514ccSChristoph Hellwig 20659cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 20669cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 20679cf514ccSChristoph Hellwig goto out; 20689cf514ccSChristoph Hellwig 20699cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 20709cf514ccSChristoph Hellwig case IOMODE_READ: 20719cf514ccSChristoph Hellwig case IOMODE_RW: 20729cf514ccSChristoph Hellwig case IOMODE_ANY: 20739cf514ccSChristoph Hellwig break; 20749cf514ccSChristoph Hellwig default: 20759cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 20769cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 20779cf514ccSChristoph Hellwig nfserr = nfserr_inval; 20789cf514ccSChristoph Hellwig goto out; 20799cf514ccSChristoph Hellwig } 20809cf514ccSChristoph Hellwig 20819cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 20829cf514ccSChristoph Hellwig case RETURN_FILE: 20839cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 20849cf514ccSChristoph Hellwig break; 20859cf514ccSChristoph Hellwig case RETURN_FSID: 20869cf514ccSChristoph Hellwig case RETURN_ALL: 20879cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 20889cf514ccSChristoph Hellwig break; 20899cf514ccSChristoph Hellwig default: 20909cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 20919cf514ccSChristoph Hellwig lrp->lr_return_type); 20929cf514ccSChristoph Hellwig nfserr = nfserr_inval; 20939cf514ccSChristoph Hellwig break; 20949cf514ccSChristoph Hellwig } 20959cf514ccSChristoph Hellwig out: 20969cf514ccSChristoph Hellwig return nfserr; 20979cf514ccSChristoph Hellwig } 20989cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 20999cf514ccSChristoph Hellwig 21001da177e4SLinus Torvalds /* 21011da177e4SLinus Torvalds * NULL call. 21021da177e4SLinus Torvalds */ 21037111c66eSAl Viro static __be32 2104a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 21051da177e4SLinus Torvalds { 21061da177e4SLinus Torvalds return nfs_ok; 21071da177e4SLinus Torvalds } 21081da177e4SLinus Torvalds 2109e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 2110e2b20950SShankar Anand { 2111e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 2112e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 2113e2b20950SShankar Anand } 2114e2b20950SShankar Anand 2115bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 2116b591480bSJ.Bruce Fields 2117f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 2118b001a1b6SBenny Halevy 21191da177e4SLinus Torvalds /* 212057716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 2121f9bb94c4SAndy Adamson * 212257716355SJ. Bruce Fields * Also note, enforced elsewhere: 212357716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 212457716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 21251d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 21261d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 212757716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 212857716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 212957716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 2130f9bb94c4SAndy Adamson */ 213157716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 2132f9bb94c4SAndy Adamson { 21337a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 213457716355SJ. Bruce Fields 213557716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 213657716355SJ. Bruce Fields if (args->minorversion == 0) 213757716355SJ. Bruce Fields return nfs_ok; 213857716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 213957716355SJ. Bruce Fields if (args->opcnt == 0) 214057716355SJ. Bruce Fields return nfs_ok; 21417a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 214257716355SJ. Bruce Fields return nfs_ok; 21437a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 214457716355SJ. Bruce Fields return nfserr_op_not_in_session; 21457a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 214657716355SJ. Bruce Fields return nfs_ok; 21477a04cfdaSJ. Bruce Fields /* 21487a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 21497a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 21507a04cfdaSJ. Bruce Fields * compound: 21517a04cfdaSJ. Bruce Fields */ 215257716355SJ. Bruce Fields if (args->opcnt != 1) 215357716355SJ. Bruce Fields return nfserr_not_only_op; 215457716355SJ. Bruce Fields return nfs_ok; 2155f9bb94c4SAndy Adamson } 2156f9bb94c4SAndy Adamson 2157f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 215822b03214SJ. Bruce Fields { 215922b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 216022b03214SJ. Bruce Fields } 216122b03214SJ. Bruce Fields 21621091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 21631091006cSJ. Bruce Fields { 2164e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 2165e372ba60SJ. Bruce Fields return false; 2166c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 21671091006cSJ. Bruce Fields } 21681091006cSJ. Bruce Fields 216968d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 217068d93184SJ. Bruce Fields { 217168d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 217268d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 217368d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 217468d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 2175bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 2176bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 217768d93184SJ. Bruce Fields 217868d93184SJ. Bruce Fields /* 217968d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 218068d93184SJ. Bruce Fields * have special rules. 218168d93184SJ. Bruce Fields */ 218268d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 218368d93184SJ. Bruce Fields return false; 218468d93184SJ. Bruce Fields /* 218568d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 218668d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 218768d93184SJ. Bruce Fields * result: 218868d93184SJ. Bruce Fields */ 218968d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 219068d93184SJ. Bruce Fields return false; 219151904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 219251904b08SJ. Bruce Fields return false; 219368d93184SJ. Bruce Fields nextd = OPDESC(next); 219468d93184SJ. Bruce Fields /* 219568d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 219668d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 219768d93184SJ. Bruce Fields * now: 219868d93184SJ. Bruce Fields */ 219968d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 220068d93184SJ. Bruce Fields } 220168d93184SJ. Bruce Fields 22022d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 22032d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 22042d124dfaSJ. Bruce Fields { 22052d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 22062d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 22072d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 22082d124dfaSJ. Bruce Fields 22092d124dfaSJ. Bruce Fields xdr->buf = buf; 2210ddd1ea56SJ. Bruce Fields xdr->iov = head; 22112d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 2212a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 22136ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 22146ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 22152825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 221605638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 22172825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 2218a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 22192d124dfaSJ. Bruce Fields } 22202d124dfaSJ. Bruce Fields 2221b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 2222b9e8638eSOlga Kornievskaia static void 2223b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2224b9e8638eSOlga Kornievskaia { 2225b9e8638eSOlga Kornievskaia struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; 2226b9e8638eSOlga Kornievskaia struct nfsd4_copy *copy; 2227b9e8638eSOlga Kornievskaia struct nfsd4_putfh *putfh; 2228b9e8638eSOlga Kornievskaia int i; 2229b9e8638eSOlga Kornievskaia 2230b9e8638eSOlga Kornievskaia /* traverse all operation and if it's a COPY compound, mark the 2231b9e8638eSOlga Kornievskaia * source filehandle to skip verification 2232b9e8638eSOlga Kornievskaia */ 2233b9e8638eSOlga Kornievskaia for (i = 0; i < args->opcnt; i++) { 2234b9e8638eSOlga Kornievskaia op = &args->ops[i]; 2235b9e8638eSOlga Kornievskaia if (op->opnum == OP_PUTFH) 2236b9e8638eSOlga Kornievskaia current_op = op; 2237b9e8638eSOlga Kornievskaia else if (op->opnum == OP_SAVEFH) 2238b9e8638eSOlga Kornievskaia saved_op = current_op; 2239b9e8638eSOlga Kornievskaia else if (op->opnum == OP_RESTOREFH) 2240b9e8638eSOlga Kornievskaia current_op = saved_op; 2241b9e8638eSOlga Kornievskaia else if (op->opnum == OP_COPY) { 2242b9e8638eSOlga Kornievskaia copy = (struct nfsd4_copy *)&op->u; 2243b9e8638eSOlga Kornievskaia if (!saved_op) { 2244b9e8638eSOlga Kornievskaia op->status = nfserr_nofilehandle; 2245b9e8638eSOlga Kornievskaia return; 2246b9e8638eSOlga Kornievskaia } 2247b9e8638eSOlga Kornievskaia putfh = (struct nfsd4_putfh *)&saved_op->u; 2248b9e8638eSOlga Kornievskaia if (!copy->cp_intra) 2249b9e8638eSOlga Kornievskaia putfh->no_verify = true; 2250b9e8638eSOlga Kornievskaia } 2251b9e8638eSOlga Kornievskaia } 2252b9e8638eSOlga Kornievskaia } 2253b9e8638eSOlga Kornievskaia #else 2254b9e8638eSOlga Kornievskaia static void 2255b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2256b9e8638eSOlga Kornievskaia { 2257b9e8638eSOlga Kornievskaia } 2258b9e8638eSOlga Kornievskaia #endif 2259b9e8638eSOlga Kornievskaia 2260f9bb94c4SAndy Adamson /* 22611da177e4SLinus Torvalds * COMPOUND call. 22621da177e4SLinus Torvalds */ 22637111c66eSAl Viro static __be32 2264a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 22651da177e4SLinus Torvalds { 2266a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 2267a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 22681da177e4SLinus Torvalds struct nfsd4_op *op; 2269e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 22704daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 22714daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 2272e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 2273b37ad28bSAl Viro __be32 status; 22741da177e4SLinus Torvalds 22752d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 22764aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 22771da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 2278d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 22791da177e4SLinus Torvalds resp->taglen = args->taglen; 22801da177e4SLinus Torvalds resp->tag = args->tag; 22811da177e4SLinus Torvalds resp->rqstp = rqstp; 22824daeed25SKinglong Mee cstate->minorversion = args->minorversion; 22834daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 22844daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 22858ff30fa4SNeilBrown /* 22868ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 22878ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 22888ff30fa4SNeilBrown */ 228930660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 22901da177e4SLinus Torvalds 22911da177e4SLinus Torvalds /* 22921da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 22931da177e4SLinus Torvalds */ 22941da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 2295e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 22961da177e4SLinus Torvalds goto out; 22970078117cSJ. Bruce Fields status = nfserr_resource; 22980078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 22990078117cSJ. Bruce Fields goto out; 23001da177e4SLinus Torvalds 230157716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 230257716355SJ. Bruce Fields if (status) { 2303f9bb94c4SAndy Adamson op = &args->ops[0]; 230457716355SJ. Bruce Fields op->status = status; 23055b7b15aeSJ. Bruce Fields resp->opcnt = 1; 2306f9bb94c4SAndy Adamson goto encode_op; 2307f9bb94c4SAndy Adamson } 2308b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(args); 2309f9bb94c4SAndy Adamson 231028df3d15SJ. Bruce Fields rqstp->rq_lease_breaker = (void **)&cstate->clp; 231128df3d15SJ. Bruce Fields 2312fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 23131da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 23141da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 23151da177e4SLinus Torvalds 23161da177e4SLinus Torvalds /* 23171da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 23181da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 23191da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 23201da177e4SLinus Torvalds */ 23219d313b17SJ. Bruce Fields if (op->status) { 23229d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 23239d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 23241da177e4SLinus Torvalds goto encode_op; 23259d313b17SJ. Bruce Fields } 2326b9e8638eSOlga Kornievskaia if (!current_fh->fh_dentry && 2327b9e8638eSOlga Kornievskaia !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { 2328f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 23291da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 23301da177e4SLinus Torvalds goto encode_op; 23311da177e4SLinus Torvalds } 2332b9e8638eSOlga Kornievskaia } else if (current_fh->fh_export && 2333b9e8638eSOlga Kornievskaia current_fh->fh_export->ex_fslocs.migrated && 2334f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 233542ca0993SJ.Bruce Fields op->status = nfserr_moved; 233642ca0993SJ.Bruce Fields goto encode_op; 233742ca0993SJ.Bruce Fields } 2338b591480bSJ.Bruce Fields 23392336745eSKinglong Mee fh_clear_wcc(current_fh); 23402336745eSKinglong Mee 234158e7b33aSMi Jinlong /* If op is non-idempotent */ 2342f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 23434c69d585SJ. Bruce Fields /* 2344a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2345a8095f7eSJ. Bruce Fields * succesful reply: 2346a8095f7eSJ. Bruce Fields */ 2347f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2348a8095f7eSJ. Bruce Fields /* 2349a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 23504c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 23514c69d585SJ. Bruce Fields */ 23524c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 23534c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 235458e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 235558e7b33aSMi Jinlong } 235658e7b33aSMi Jinlong 235758e7b33aSMi Jinlong if (op->status) 235858e7b33aSMi Jinlong goto encode_op; 235958e7b33aSMi Jinlong 2360f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2361f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2362f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 23631da177e4SLinus Torvalds 23649a307403SJ. Bruce Fields /* Only from SEQUENCE */ 23659a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 23669a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 23679a307403SJ. Bruce Fields status = op->status; 23689a307403SJ. Bruce Fields goto out; 23699a307403SJ. Bruce Fields } 23708b70484cSTigran Mkrtchyan if (!op->status) { 2371f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2372f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 23738b70484cSTigran Mkrtchyan 2374f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 237537c593c5STigran Mkrtchyan clear_current_stateid(cstate); 23768b70484cSTigran Mkrtchyan 2377d781e3dfSJ. Bruce Fields if (current_fh->fh_export && 2378d781e3dfSJ. Bruce Fields need_wrongsec_check(rqstp)) 23794daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 23808b70484cSTigran Mkrtchyan } 23811da177e4SLinus Torvalds encode_op: 2382a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2383a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2384d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 23851da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 23861da177e4SLinus Torvalds } else { 23871da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 23881da177e4SLinus Torvalds status = op->status; 23891da177e4SLinus Torvalds } 23900407717dSBenny Halevy 2391fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2392fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 23930407717dSBenny Halevy 239458fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2395e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 23961da177e4SLinus Torvalds } 23971da177e4SLinus Torvalds 23984daeed25SKinglong Mee cstate->status = status; 23994daeed25SKinglong Mee fh_put(current_fh); 24004daeed25SKinglong Mee fh_put(save_fh); 24014daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 24021da177e4SLinus Torvalds out: 24032f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 240430660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 24053b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 24061da177e4SLinus Torvalds return status; 24071da177e4SLinus Torvalds } 24081da177e4SLinus Torvalds 240958e7b33aSMi Jinlong #define op_encode_hdr_size (2) 241058e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 241158e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 241258e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 241358e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 241458e7b33aSMi Jinlong 24158c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 24168c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 241758e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 241858e7b33aSMi Jinlong 241958e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 242058e7b33aSMi Jinlong 242158e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 242258e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 242358e7b33aSMi Jinlong op_encode_ace_maxsz) 242458e7b33aSMi Jinlong 242558e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 242658e7b33aSMi Jinlong 242758e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 242858e7b33aSMi Jinlong { 242958e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 243058e7b33aSMi Jinlong } 243158e7b33aSMi Jinlong 243258e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 243358e7b33aSMi Jinlong { 243458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 243558e7b33aSMi Jinlong } 243658e7b33aSMi Jinlong 24372282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 24382282cd2cSKinglong Mee { 24392282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 24402282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 24412282cd2cSKinglong Mee } 24422282cd2cSKinglong Mee 244358e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 244458e7b33aSMi Jinlong { 244558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 244658e7b33aSMi Jinlong } 244758e7b33aSMi Jinlong 244858e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 244958e7b33aSMi Jinlong { 245058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 245158e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 245258e7b33aSMi Jinlong } 245358e7b33aSMi Jinlong 2454b86cef60SJ. Bruce Fields /* 2455b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2456b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2457b86cef60SJ. Bruce Fields * reads unnecessarily. 2458b86cef60SJ. Bruce Fields */ 2459b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2460b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2461b86cef60SJ. Bruce Fields { 2462b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2463b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2464b86cef60SJ. Bruce Fields u32 ret = 0; 2465b86cef60SJ. Bruce Fields 2466b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2467b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2468b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2469b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2470b86cef60SJ. Bruce Fields 2471b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2472b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2473b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2474b86cef60SJ. Bruce Fields } 2475b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2476b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2477b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2478b86cef60SJ. Bruce Fields } 2479b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2480b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2481b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2482b86cef60SJ. Bruce Fields } 2483b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 24841ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2485b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2486b86cef60SJ. Bruce Fields } 2487b86cef60SJ. Bruce Fields /* 2488b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2489b86cef60SJ. Bruce Fields * supported_attributes) 2490b86cef60SJ. Bruce Fields */ 2491b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2492b86cef60SJ. Bruce Fields /* bitmask, length */ 2493b86cef60SJ. Bruce Fields ret += 20; 2494b86cef60SJ. Bruce Fields return ret; 2495b86cef60SJ. Bruce Fields } 2496b86cef60SJ. Bruce Fields 24972282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 24982282cd2cSKinglong Mee { 24992282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 25002282cd2cSKinglong Mee } 25012282cd2cSKinglong Mee 250258e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 250358e7b33aSMi Jinlong { 250458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 250558e7b33aSMi Jinlong * sizeof(__be32); 250658e7b33aSMi Jinlong } 250758e7b33aSMi Jinlong 250858e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 250958e7b33aSMi Jinlong { 251058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 251158e7b33aSMi Jinlong * sizeof(__be32); 251258e7b33aSMi Jinlong } 251358e7b33aSMi Jinlong 251458e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 251558e7b33aSMi Jinlong { 251658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 251758e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 251858e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 251958e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 252058e7b33aSMi Jinlong } 252158e7b33aSMi Jinlong 252258e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 252358e7b33aSMi Jinlong { 252458e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 252558e7b33aSMi Jinlong 252658e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 25273c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 252858e7b33aSMi Jinlong 2529622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 253058e7b33aSMi Jinlong } 253158e7b33aSMi Jinlong 253258e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 253358e7b33aSMi Jinlong { 25343c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 253558e7b33aSMi Jinlong 25363c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 25373c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 253858e7b33aSMi Jinlong 2539561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2540561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 254158e7b33aSMi Jinlong } 254258e7b33aSMi Jinlong 25432282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 25442282cd2cSKinglong Mee { 25452282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 25462282cd2cSKinglong Mee } 25472282cd2cSKinglong Mee 254858e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 254958e7b33aSMi Jinlong { 255058e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 255158e7b33aSMi Jinlong * sizeof(__be32); 255258e7b33aSMi Jinlong } 255358e7b33aSMi Jinlong 255458e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 255558e7b33aSMi Jinlong { 255658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 255758e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 255858e7b33aSMi Jinlong } 255958e7b33aSMi Jinlong 2560ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2561ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2562ccae70a9SJ. Bruce Fields { 2563d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2564d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2565ccae70a9SJ. Bruce Fields } 2566ccae70a9SJ. Bruce Fields 25672282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 25682282cd2cSKinglong Mee { 25692282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 25702282cd2cSKinglong Mee * sizeof(__be32); 25712282cd2cSKinglong Mee } 25722282cd2cSKinglong Mee 257358e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 257458e7b33aSMi Jinlong { 257558e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 257658e7b33aSMi Jinlong } 257758e7b33aSMi Jinlong 25782282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 25792282cd2cSKinglong Mee { 25802282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 25812282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 25822282cd2cSKinglong Mee } 25832282cd2cSKinglong Mee 258458e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 258558e7b33aSMi Jinlong { 2586480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2587480efaeeSJ. Bruce Fields sizeof(__be32); 258858e7b33aSMi Jinlong } 258958e7b33aSMi Jinlong 259058e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 259158e7b33aSMi Jinlong { 2592f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 259358e7b33aSMi Jinlong } 259458e7b33aSMi Jinlong 259558e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 259658e7b33aSMi Jinlong { 259758e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2598a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2599a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 260058e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 260158e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 260258e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 260358e7b33aSMi Jinlong /* eir_server_scope<> */\ 260458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 260558e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 260658e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 260758e7b33aSMi Jinlong } 260858e7b33aSMi Jinlong 260958e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 261058e7b33aSMi Jinlong { 261158e7b33aSMi Jinlong return (op_encode_hdr_size + \ 261258e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 261358e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 261458e7b33aSMi Jinlong } 261558e7b33aSMi Jinlong 261658e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 261758e7b33aSMi Jinlong { 261858e7b33aSMi Jinlong return (op_encode_hdr_size + \ 261958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 262058e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 262158e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 262258e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 262358e7b33aSMi Jinlong } 262458e7b33aSMi Jinlong 262529ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 262629ae7f9dSAnna Schumaker { 262729ae7f9dSAnna Schumaker return (op_encode_hdr_size + 262829ae7f9dSAnna Schumaker 1 /* wr_callback */ + 262929ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 263029ae7f9dSAnna Schumaker 2 /* wr_count */ + 263129ae7f9dSAnna Schumaker 1 /* wr_committed */ + 263229ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 263329ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 263429ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 263529ae7f9dSAnna Schumaker } 263629ae7f9dSAnna Schumaker 26376308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 26386308bc98SOlga Kornievskaia struct nfsd4_op *op) 26396308bc98SOlga Kornievskaia { 26406308bc98SOlga Kornievskaia return (op_encode_hdr_size + 26416308bc98SOlga Kornievskaia 2 /* osr_count */ + 26426308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 26436308bc98SOlga Kornievskaia } 26446308bc98SOlga Kornievskaia 264551911868SOlga Kornievskaia static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, 264651911868SOlga Kornievskaia struct nfsd4_op *op) 264751911868SOlga Kornievskaia { 264851911868SOlga Kornievskaia return (op_encode_hdr_size + 264951911868SOlga Kornievskaia 3 /* cnr_lease_time */ + 265051911868SOlga Kornievskaia 1 /* We support one cnr_source_server */ + 265151911868SOlga Kornievskaia 1 /* cnr_stateid seq */ + 265251911868SOlga Kornievskaia op_encode_stateid_maxsz /* cnr_stateid */ + 265351911868SOlga Kornievskaia 1 /* num cnr_source_server*/ + 265451911868SOlga Kornievskaia 1 /* nl4_type */ + 265551911868SOlga Kornievskaia 1 /* nl4 size */ + 265651911868SOlga Kornievskaia XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) 265751911868SOlga Kornievskaia * sizeof(__be32); 265851911868SOlga Kornievskaia } 265951911868SOlga Kornievskaia 26609cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 26612282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26622282cd2cSKinglong Mee { 26632282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 26642282cd2cSKinglong Mee 26652282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 26662282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 26672282cd2cSKinglong Mee 26682282cd2cSKinglong Mee return (op_encode_hdr_size + 26692282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 26702282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 26712282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 26722282cd2cSKinglong Mee } 26732282cd2cSKinglong Mee 26749cf514ccSChristoph Hellwig /* 26759cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 26769cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 26779cf514ccSChristoph Hellwig */ 26789cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 26799cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26809cf514ccSChristoph Hellwig { 26819cf514ccSChristoph Hellwig return (op_encode_hdr_size + 26829cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 26839cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 26849cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 26859cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 26869cf514ccSChristoph Hellwig } 26879cf514ccSChristoph Hellwig 26889cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26899cf514ccSChristoph Hellwig { 26909cf514ccSChristoph Hellwig return (op_encode_hdr_size + 26919cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 26929cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 26939cf514ccSChristoph Hellwig } 26949cf514ccSChristoph Hellwig 26959cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26969cf514ccSChristoph Hellwig { 26979cf514ccSChristoph Hellwig return (op_encode_hdr_size + 26989cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 26999cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 27009cf514ccSChristoph Hellwig } 27019cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 27029cf514ccSChristoph Hellwig 27032282cd2cSKinglong Mee 27042282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27052282cd2cSKinglong Mee { 27062282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 27072282cd2cSKinglong Mee } 27082282cd2cSKinglong Mee 2709bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2710b591480bSJ.Bruce Fields [OP_ACCESS] = { 2711eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2712b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 27131c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2714b591480bSJ.Bruce Fields }, 2715b591480bSJ.Bruce Fields [OP_CLOSE] = { 2716eb69853dSChristoph Hellwig .op_func = nfsd4_close, 271758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2718b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 27191c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 272057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2721b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2722b591480bSJ.Bruce Fields }, 2723b591480bSJ.Bruce Fields [OP_COMMIT] = { 2724eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 272558e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2726b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 27271c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2728b591480bSJ.Bruce Fields }, 2729b591480bSJ.Bruce Fields [OP_CREATE] = { 2730eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2731d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2732b001a1b6SBenny Halevy .op_name = "OP_CREATE", 27331c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2734b591480bSJ.Bruce Fields }, 2735b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2736eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 273758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2738b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 273958e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 274057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2741b591480bSJ.Bruce Fields }, 2742b591480bSJ.Bruce Fields [OP_GETATTR] = { 2743eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2744eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2745b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2746b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2747b591480bSJ.Bruce Fields }, 2748b591480bSJ.Bruce Fields [OP_GETFH] = { 2749eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2750b001a1b6SBenny Halevy .op_name = "OP_GETFH", 27511c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2752b591480bSJ.Bruce Fields }, 2753b591480bSJ.Bruce Fields [OP_LINK] = { 2754eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2755c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2756c856694eSJ. Bruce Fields | OP_CACHEME, 2757b001a1b6SBenny Halevy .op_name = "OP_LINK", 27581c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 2759b591480bSJ.Bruce Fields }, 2760b591480bSJ.Bruce Fields [OP_LOCK] = { 2761eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 2762b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 2763b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 2764b001a1b6SBenny Halevy .op_name = "OP_LOCK", 27651c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2766b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 2767b591480bSJ.Bruce Fields }, 2768b591480bSJ.Bruce Fields [OP_LOCKT] = { 2769eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 2770b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 2771b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 27721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2773b591480bSJ.Bruce Fields }, 2774b591480bSJ.Bruce Fields [OP_LOCKU] = { 2775eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 277658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2777b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 27781c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 277957832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 2780b591480bSJ.Bruce Fields }, 2781b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2782eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 2783d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2784b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 27851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2786b591480bSJ.Bruce Fields }, 2787b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2788eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 2789d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2790b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 27911c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2792b591480bSJ.Bruce Fields }, 2793b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2794eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 2795b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 27961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2797b591480bSJ.Bruce Fields }, 2798b591480bSJ.Bruce Fields [OP_OPEN] = { 2799eb69853dSChristoph Hellwig .op_func = nfsd4_open, 280058e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2801b001a1b6SBenny Halevy .op_name = "OP_OPEN", 28021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 2803b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 2804b591480bSJ.Bruce Fields }, 2805b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2806eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 280758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2808b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 28091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 2810b591480bSJ.Bruce Fields }, 2811b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2812eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 281358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2814b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 28151c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 281657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 2817b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 2818b591480bSJ.Bruce Fields }, 2819b591480bSJ.Bruce Fields [OP_PUTFH] = { 2820eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 282168d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 28225b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2823b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 28241c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2825b591480bSJ.Bruce Fields }, 2826eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2827eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 282868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 28295b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2830b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 28311c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2832eeac294eSJ.Bruce Fields }, 2833b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2834eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 283568d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 28365b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2837b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 28381c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2839b591480bSJ.Bruce Fields }, 2840b591480bSJ.Bruce Fields [OP_READ] = { 2841eb69853dSChristoph Hellwig .op_func = nfsd4_read, 284234b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 2843b001a1b6SBenny Halevy .op_name = "OP_READ", 28441c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 284557832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 2846b591480bSJ.Bruce Fields }, 2847b591480bSJ.Bruce Fields [OP_READDIR] = { 2848eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 2849b001a1b6SBenny Halevy .op_name = "OP_READDIR", 28501c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 2851b591480bSJ.Bruce Fields }, 2852b591480bSJ.Bruce Fields [OP_READLINK] = { 2853eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 2854b001a1b6SBenny Halevy .op_name = "OP_READLINK", 28551c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 2856b591480bSJ.Bruce Fields }, 2857b591480bSJ.Bruce Fields [OP_REMOVE] = { 2858eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 2859c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2860b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 28611c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 2862b591480bSJ.Bruce Fields }, 2863b591480bSJ.Bruce Fields [OP_RENAME] = { 2864eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 2865c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 286658e7b33aSMi Jinlong .op_name = "OP_RENAME", 28671c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 2868b591480bSJ.Bruce Fields }, 2869b591480bSJ.Bruce Fields [OP_RENEW] = { 2870eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 287158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 287258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2873b001a1b6SBenny Halevy .op_name = "OP_RENEW", 28741c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 287558e7b33aSMi Jinlong 2876b591480bSJ.Bruce Fields }, 2877b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2878eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 287968d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 288058e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2881b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 28821c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2883b591480bSJ.Bruce Fields }, 2884b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2885eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 288658e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2887b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 28881c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2889b591480bSJ.Bruce Fields }, 2890dcb488a3SAndy Adamson [OP_SECINFO] = { 2891eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 289234b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 289368d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2894b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 28951c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 2896dcb488a3SAndy Adamson }, 2897b591480bSJ.Bruce Fields [OP_SETATTR] = { 2898eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 2899b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2900b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 2901b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 29021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 290357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 2904b591480bSJ.Bruce Fields }, 2905b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2906eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 290758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2908b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 2909b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 2910b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 29111c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 2912b591480bSJ.Bruce Fields }, 2913b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2914eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 291558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2916c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2917b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 29181c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2919b591480bSJ.Bruce Fields }, 2920b591480bSJ.Bruce Fields [OP_VERIFY] = { 2921eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 2922b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 29231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2924b591480bSJ.Bruce Fields }, 2925b591480bSJ.Bruce Fields [OP_WRITE] = { 2926eb69853dSChristoph Hellwig .op_func = nfsd4_write, 2927c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2928b001a1b6SBenny Halevy .op_name = "OP_WRITE", 29291c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 293057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 2931b591480bSJ.Bruce Fields }, 2932b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2933eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 293458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 293558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2936b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 29371c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2938b591480bSJ.Bruce Fields }, 2939069b6ad4SAndy Adamson 2940069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2941069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2942eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 294358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 294458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2945069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 29461c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 2947069b6ad4SAndy Adamson }, 2948cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2949eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 2950cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2951cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 29521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2953cb73a9f4SJ. Bruce Fields }, 29541d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 2955eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 295658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 295758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 29581d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 29591c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 29601d1bc8f2SJ. Bruce Fields }, 2961069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2962eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 296358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 296458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2965069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 29661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 2967069b6ad4SAndy Adamson }, 2968069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2969eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 297058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 297158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2972069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 29731c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2974069b6ad4SAndy Adamson }, 2975069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2976eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 2977f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2978069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 29791c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 2980069b6ad4SAndy Adamson }, 2981094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2982eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 298358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 298458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2985094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 29861c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2987094b5d74SBenny Halevy }, 29884dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 2989eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 299058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 29914dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 29921c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 29934dc6ec00SJ. Bruce Fields }, 299404f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 2995eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 2996ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 299768d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 299804f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 29991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 300004f4ad16SJ. Bruce Fields }, 300117456804SBryan Schumaker [OP_TEST_STATEID] = { 3002eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 300317456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 300417456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 30051c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 300617456804SBryan Schumaker }, 3007e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 3008eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 300958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3010e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 301157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 30121c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3013e1ca12dfSBryan Schumaker }, 30149cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 30159cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 3016eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 301734b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 30189cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 30199cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 30201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 30219cf514ccSChristoph Hellwig }, 30229cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 3023eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 302434b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 30259cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 30269cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 30271c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 30289cf514ccSChristoph Hellwig }, 30299cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 3030eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 30319cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 30329cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 30331c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 30349cf514ccSChristoph Hellwig }, 30359cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 3036eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 30379cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 30389cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 30391c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 30409cf514ccSChristoph Hellwig }, 30419cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 304224bab491SAnna Schumaker 304324bab491SAnna Schumaker /* NFSv4.2 operations */ 304495d871f0SAnna Schumaker [OP_ALLOCATE] = { 3045eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 304603b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 304795d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 30481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 304995d871f0SAnna Schumaker }, 3050b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 3051eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 305203b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3053b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 30541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3055b0cb9085SAnna Schumaker }, 3056ffa0160aSChristoph Hellwig [OP_CLONE] = { 3057eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 305803b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3059ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 30601c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3061ffa0160aSChristoph Hellwig }, 306229ae7f9dSAnna Schumaker [OP_COPY] = { 3063eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 306403b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 306529ae7f9dSAnna Schumaker .op_name = "OP_COPY", 30661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 306729ae7f9dSAnna Schumaker }, 306824bab491SAnna Schumaker [OP_SEEK] = { 3069eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 307024bab491SAnna Schumaker .op_name = "OP_SEEK", 30711c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 307224bab491SAnna Schumaker }, 30736308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 30746308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 30756308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 30766308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 30776308bc98SOlga Kornievskaia }, 3078885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 3079885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 3080885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3081885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 3082885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 3083885e2bf3SOlga Kornievskaia }, 308451911868SOlga Kornievskaia [OP_COPY_NOTIFY] = { 308551911868SOlga Kornievskaia .op_func = nfsd4_copy_notify, 308651911868SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 308751911868SOlga Kornievskaia .op_name = "OP_COPY_NOTIFY", 308851911868SOlga Kornievskaia .op_rsize_bop = nfsd4_copy_notify_rsize, 308951911868SOlga Kornievskaia }, 3090b591480bSJ.Bruce Fields }; 3091b591480bSJ.Bruce Fields 3092ed941643SAndrew Elble /** 3093ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 3094ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 3095ed941643SAndrew Elble * 3096ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 3097ed941643SAndrew Elble * 3098ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 3099ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 3100ed941643SAndrew Elble */ 3101ed941643SAndrew Elble 3102ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 3103ed941643SAndrew Elble { 3104ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 3105ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 3106ed941643SAndrew Elble struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 3107ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 3108ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 3109ed941643SAndrew Elble u32 opiter; 3110ed941643SAndrew Elble 3111ed941643SAndrew Elble if (!cstate->minorversion) 3112ed941643SAndrew Elble return false; 3113ed941643SAndrew Elble 3114ed941643SAndrew Elble if (cstate->spo_must_allowed == true) 3115ed941643SAndrew Elble return true; 3116ed941643SAndrew Elble 3117ed941643SAndrew Elble opiter = resp->opcnt; 3118ed941643SAndrew Elble while (opiter < argp->opcnt) { 3119ed941643SAndrew Elble this = &argp->ops[opiter++]; 3120ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 3121ed941643SAndrew Elble cstate->clp->cl_mach_cred && 3122ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 3123ed941643SAndrew Elble cstate->spo_must_allowed = true; 3124ed941643SAndrew Elble return true; 3125ed941643SAndrew Elble } 3126ed941643SAndrew Elble } 3127ed941643SAndrew Elble cstate->spo_must_allowed = false; 3128ed941643SAndrew Elble return false; 3129ed941643SAndrew Elble } 3130ed941643SAndrew Elble 31314f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 31324f0cefbfSJ. Bruce Fields { 313305b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 31344f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 31352282cd2cSKinglong Mee 31362282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 31372282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 31384f0cefbfSJ. Bruce Fields } 31394f0cefbfSJ. Bruce Fields 314007d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 314107d1f802SJ. Bruce Fields { 314207d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 314307d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 314407d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 314507d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 314607d1f802SJ. Bruce Fields } 314707d1f802SJ. Bruce Fields } 314807d1f802SJ. Bruce Fields 3149f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 3150b001a1b6SBenny Halevy { 3151b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 3152b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 3153b001a1b6SBenny Halevy return "unknown_operation"; 3154b001a1b6SBenny Halevy } 3155b001a1b6SBenny Halevy 31561da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 31571da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 31581da177e4SLinus Torvalds 3159860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 31600a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 3161f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 316263f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_voidres, 31630a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 31640a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 31650a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 31660a93a47fSYu Zhiguo .pc_xdrressize = 1, 31670a93a47fSYu Zhiguo }, 31680a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 3169f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 3170026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 317163f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 31720a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 31730a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 31743e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 31750a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 31760a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 31770a93a47fSYu Zhiguo }, 31781da177e4SLinus Torvalds }; 31791da177e4SLinus Torvalds 31807fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 3181e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 31821da177e4SLinus Torvalds .vs_vers = 4, 31831da177e4SLinus Torvalds .vs_nproc = 2, 31841da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 31857fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 31861da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 31871da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 318805a45a2dSJeff Layton .vs_rpcb_optnl = true, 31895283b03eSJeff Layton .vs_need_cong_ctrl = true, 31901da177e4SLinus Torvalds }; 31911da177e4SLinus Torvalds 31921da177e4SLinus Torvalds /* 31931da177e4SLinus Torvalds * Local variables: 31941da177e4SLinus Torvalds * c-basic-offset: 8 31951da177e4SLinus Torvalds * End: 31961da177e4SLinus Torvalds */ 3197