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; 431df561f66SGustavo A. R. Silva fallthrough; 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; 569c11d7fd1SFrank van der Linden u32 access_full; 570eb69853dSChristoph Hellwig 571c11d7fd1SFrank van der Linden access_full = NFS3_ACCESS_FULL; 572c11d7fd1SFrank van der Linden if (cstate->minorversion >= 2) 573c11d7fd1SFrank van der Linden access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD | 574c11d7fd1SFrank van der Linden NFS4_ACCESS_XAWRITE; 575c11d7fd1SFrank van der Linden 576c11d7fd1SFrank 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 210023e50fe3SFrank van der Linden static __be32 210123e50fe3SFrank van der Linden nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 210223e50fe3SFrank van der Linden union nfsd4_op_u *u) 210323e50fe3SFrank van der Linden { 210423e50fe3SFrank van der Linden struct nfsd4_getxattr *getxattr = &u->getxattr; 210523e50fe3SFrank van der Linden 210623e50fe3SFrank van der Linden return nfsd_getxattr(rqstp, &cstate->current_fh, 210723e50fe3SFrank van der Linden getxattr->getxa_name, &getxattr->getxa_buf, 210823e50fe3SFrank van der Linden &getxattr->getxa_len); 210923e50fe3SFrank van der Linden } 211023e50fe3SFrank van der Linden 211123e50fe3SFrank van der Linden static __be32 211223e50fe3SFrank van der Linden nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 211323e50fe3SFrank van der Linden union nfsd4_op_u *u) 211423e50fe3SFrank van der Linden { 211523e50fe3SFrank van der Linden struct nfsd4_setxattr *setxattr = &u->setxattr; 211623e50fe3SFrank van der Linden __be32 ret; 211723e50fe3SFrank van der Linden 211823e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 211923e50fe3SFrank van der Linden return nfserr_grace; 212023e50fe3SFrank van der Linden 212123e50fe3SFrank van der Linden ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name, 212223e50fe3SFrank van der Linden setxattr->setxa_buf, setxattr->setxa_len, 212323e50fe3SFrank van der Linden setxattr->setxa_flags); 212423e50fe3SFrank van der Linden 212523e50fe3SFrank van der Linden if (!ret) 212623e50fe3SFrank van der Linden set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh); 212723e50fe3SFrank van der Linden 212823e50fe3SFrank van der Linden return ret; 212923e50fe3SFrank van der Linden } 213023e50fe3SFrank van der Linden 213123e50fe3SFrank van der Linden static __be32 213223e50fe3SFrank van der Linden nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 213323e50fe3SFrank van der Linden union nfsd4_op_u *u) 213423e50fe3SFrank van der Linden { 213523e50fe3SFrank van der Linden /* 213623e50fe3SFrank van der Linden * Get the entire list, then copy out only the user attributes 213723e50fe3SFrank van der Linden * in the encode function. 213823e50fe3SFrank van der Linden */ 213923e50fe3SFrank van der Linden return nfsd_listxattr(rqstp, &cstate->current_fh, 214023e50fe3SFrank van der Linden &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len); 214123e50fe3SFrank van der Linden } 214223e50fe3SFrank van der Linden 214323e50fe3SFrank van der Linden static __be32 214423e50fe3SFrank van der Linden nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 214523e50fe3SFrank van der Linden union nfsd4_op_u *u) 214623e50fe3SFrank van der Linden { 214723e50fe3SFrank van der Linden struct nfsd4_removexattr *removexattr = &u->removexattr; 214823e50fe3SFrank van der Linden __be32 ret; 214923e50fe3SFrank van der Linden 215023e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 215123e50fe3SFrank van der Linden return nfserr_grace; 215223e50fe3SFrank van der Linden 215323e50fe3SFrank van der Linden ret = nfsd_removexattr(rqstp, &cstate->current_fh, 215423e50fe3SFrank van der Linden removexattr->rmxa_name); 215523e50fe3SFrank van der Linden 215623e50fe3SFrank van der Linden if (!ret) 215723e50fe3SFrank van der Linden set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh); 215823e50fe3SFrank van der Linden 215923e50fe3SFrank van der Linden return ret; 216023e50fe3SFrank van der Linden } 216123e50fe3SFrank van der Linden 21621da177e4SLinus Torvalds /* 21631da177e4SLinus Torvalds * NULL call. 21641da177e4SLinus Torvalds */ 21657111c66eSAl Viro static __be32 2166a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 21671da177e4SLinus Torvalds { 2168*cc028a10SChuck Lever return rpc_success; 21691da177e4SLinus Torvalds } 21701da177e4SLinus Torvalds 2171e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 2172e2b20950SShankar Anand { 2173e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 2174e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 2175e2b20950SShankar Anand } 2176e2b20950SShankar Anand 2177bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 2178b591480bSJ.Bruce Fields 2179f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 2180b001a1b6SBenny Halevy 21811da177e4SLinus Torvalds /* 218257716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 2183f9bb94c4SAndy Adamson * 218457716355SJ. Bruce Fields * Also note, enforced elsewhere: 218557716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 218657716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 21871d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 21881d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 218957716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 219057716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 219157716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 2192f9bb94c4SAndy Adamson */ 219357716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 2194f9bb94c4SAndy Adamson { 21957a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 219657716355SJ. Bruce Fields 219757716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 219857716355SJ. Bruce Fields if (args->minorversion == 0) 219957716355SJ. Bruce Fields return nfs_ok; 220057716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 220157716355SJ. Bruce Fields if (args->opcnt == 0) 220257716355SJ. Bruce Fields return nfs_ok; 22037a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 220457716355SJ. Bruce Fields return nfs_ok; 22057a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 220657716355SJ. Bruce Fields return nfserr_op_not_in_session; 22077a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 220857716355SJ. Bruce Fields return nfs_ok; 22097a04cfdaSJ. Bruce Fields /* 22107a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 22117a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 22127a04cfdaSJ. Bruce Fields * compound: 22137a04cfdaSJ. Bruce Fields */ 221457716355SJ. Bruce Fields if (args->opcnt != 1) 221557716355SJ. Bruce Fields return nfserr_not_only_op; 221657716355SJ. Bruce Fields return nfs_ok; 2217f9bb94c4SAndy Adamson } 2218f9bb94c4SAndy Adamson 2219f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 222022b03214SJ. Bruce Fields { 222122b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 222222b03214SJ. Bruce Fields } 222322b03214SJ. Bruce Fields 22241091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 22251091006cSJ. Bruce Fields { 2226e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 2227e372ba60SJ. Bruce Fields return false; 2228c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 22291091006cSJ. Bruce Fields } 22301091006cSJ. Bruce Fields 223168d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 223268d93184SJ. Bruce Fields { 223368d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 223468d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 223568d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 223668d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 2237bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 2238bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 223968d93184SJ. Bruce Fields 224068d93184SJ. Bruce Fields /* 224168d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 224268d93184SJ. Bruce Fields * have special rules. 224368d93184SJ. Bruce Fields */ 224468d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 224568d93184SJ. Bruce Fields return false; 224668d93184SJ. Bruce Fields /* 224768d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 224868d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 224968d93184SJ. Bruce Fields * result: 225068d93184SJ. Bruce Fields */ 225168d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 225268d93184SJ. Bruce Fields return false; 225351904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 225451904b08SJ. Bruce Fields return false; 225568d93184SJ. Bruce Fields nextd = OPDESC(next); 225668d93184SJ. Bruce Fields /* 225768d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 225868d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 225968d93184SJ. Bruce Fields * now: 226068d93184SJ. Bruce Fields */ 226168d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 226268d93184SJ. Bruce Fields } 226368d93184SJ. Bruce Fields 22642d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 22652d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 22662d124dfaSJ. Bruce Fields { 22672d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 22682d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 22692d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 22702d124dfaSJ. Bruce Fields 22712d124dfaSJ. Bruce Fields xdr->buf = buf; 2272ddd1ea56SJ. Bruce Fields xdr->iov = head; 22732d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 2274a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 22756ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 22766ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 22772825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 227805638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 22792825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 2280a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 22812d124dfaSJ. Bruce Fields } 22822d124dfaSJ. Bruce Fields 2283b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 2284b9e8638eSOlga Kornievskaia static void 2285b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2286b9e8638eSOlga Kornievskaia { 2287b9e8638eSOlga Kornievskaia struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; 2288b9e8638eSOlga Kornievskaia struct nfsd4_copy *copy; 2289b9e8638eSOlga Kornievskaia struct nfsd4_putfh *putfh; 2290b9e8638eSOlga Kornievskaia int i; 2291b9e8638eSOlga Kornievskaia 2292b9e8638eSOlga Kornievskaia /* traverse all operation and if it's a COPY compound, mark the 2293b9e8638eSOlga Kornievskaia * source filehandle to skip verification 2294b9e8638eSOlga Kornievskaia */ 2295b9e8638eSOlga Kornievskaia for (i = 0; i < args->opcnt; i++) { 2296b9e8638eSOlga Kornievskaia op = &args->ops[i]; 2297b9e8638eSOlga Kornievskaia if (op->opnum == OP_PUTFH) 2298b9e8638eSOlga Kornievskaia current_op = op; 2299b9e8638eSOlga Kornievskaia else if (op->opnum == OP_SAVEFH) 2300b9e8638eSOlga Kornievskaia saved_op = current_op; 2301b9e8638eSOlga Kornievskaia else if (op->opnum == OP_RESTOREFH) 2302b9e8638eSOlga Kornievskaia current_op = saved_op; 2303b9e8638eSOlga Kornievskaia else if (op->opnum == OP_COPY) { 2304b9e8638eSOlga Kornievskaia copy = (struct nfsd4_copy *)&op->u; 2305b9e8638eSOlga Kornievskaia if (!saved_op) { 2306b9e8638eSOlga Kornievskaia op->status = nfserr_nofilehandle; 2307b9e8638eSOlga Kornievskaia return; 2308b9e8638eSOlga Kornievskaia } 2309b9e8638eSOlga Kornievskaia putfh = (struct nfsd4_putfh *)&saved_op->u; 2310b9e8638eSOlga Kornievskaia if (!copy->cp_intra) 2311b9e8638eSOlga Kornievskaia putfh->no_verify = true; 2312b9e8638eSOlga Kornievskaia } 2313b9e8638eSOlga Kornievskaia } 2314b9e8638eSOlga Kornievskaia } 2315b9e8638eSOlga Kornievskaia #else 2316b9e8638eSOlga Kornievskaia static void 2317b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2318b9e8638eSOlga Kornievskaia { 2319b9e8638eSOlga Kornievskaia } 2320b9e8638eSOlga Kornievskaia #endif 2321b9e8638eSOlga Kornievskaia 2322f9bb94c4SAndy Adamson /* 23231da177e4SLinus Torvalds * COMPOUND call. 23241da177e4SLinus Torvalds */ 23257111c66eSAl Viro static __be32 2326a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 23271da177e4SLinus Torvalds { 2328a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 2329a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 23301da177e4SLinus Torvalds struct nfsd4_op *op; 2331e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 23324daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 23334daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 2334e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 2335b37ad28bSAl Viro __be32 status; 23361da177e4SLinus Torvalds 23372d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 23384aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 23391da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 2340d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 23411da177e4SLinus Torvalds resp->taglen = args->taglen; 23421da177e4SLinus Torvalds resp->tag = args->tag; 23431da177e4SLinus Torvalds resp->rqstp = rqstp; 23444daeed25SKinglong Mee cstate->minorversion = args->minorversion; 23454daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 23464daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 23478ff30fa4SNeilBrown /* 23488ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 23498ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 23508ff30fa4SNeilBrown */ 235130660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds /* 23541da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 23551da177e4SLinus Torvalds */ 23561da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 2357e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 23581da177e4SLinus Torvalds goto out; 23590078117cSJ. Bruce Fields status = nfserr_resource; 23600078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 23610078117cSJ. Bruce Fields goto out; 23621da177e4SLinus Torvalds 236357716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 236457716355SJ. Bruce Fields if (status) { 2365f9bb94c4SAndy Adamson op = &args->ops[0]; 236657716355SJ. Bruce Fields op->status = status; 23675b7b15aeSJ. Bruce Fields resp->opcnt = 1; 2368f9bb94c4SAndy Adamson goto encode_op; 2369f9bb94c4SAndy Adamson } 2370b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(args); 2371f9bb94c4SAndy Adamson 237228df3d15SJ. Bruce Fields rqstp->rq_lease_breaker = (void **)&cstate->clp; 237328df3d15SJ. Bruce Fields 2374fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 23751da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 23761da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 23771da177e4SLinus Torvalds 23781da177e4SLinus Torvalds /* 23791da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 23801da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 23811da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 23821da177e4SLinus Torvalds */ 23839d313b17SJ. Bruce Fields if (op->status) { 23849d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 23859d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 23861da177e4SLinus Torvalds goto encode_op; 23879d313b17SJ. Bruce Fields } 2388b9e8638eSOlga Kornievskaia if (!current_fh->fh_dentry && 2389b9e8638eSOlga Kornievskaia !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { 2390f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 23911da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 23921da177e4SLinus Torvalds goto encode_op; 23931da177e4SLinus Torvalds } 2394b9e8638eSOlga Kornievskaia } else if (current_fh->fh_export && 2395b9e8638eSOlga Kornievskaia current_fh->fh_export->ex_fslocs.migrated && 2396f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 239742ca0993SJ.Bruce Fields op->status = nfserr_moved; 239842ca0993SJ.Bruce Fields goto encode_op; 239942ca0993SJ.Bruce Fields } 2400b591480bSJ.Bruce Fields 24012336745eSKinglong Mee fh_clear_wcc(current_fh); 24022336745eSKinglong Mee 240358e7b33aSMi Jinlong /* If op is non-idempotent */ 2404f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 24054c69d585SJ. Bruce Fields /* 2406a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2407a8095f7eSJ. Bruce Fields * succesful reply: 2408a8095f7eSJ. Bruce Fields */ 2409f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2410a8095f7eSJ. Bruce Fields /* 2411a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 24124c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 24134c69d585SJ. Bruce Fields */ 24144c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 24154c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 241658e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 241758e7b33aSMi Jinlong } 241858e7b33aSMi Jinlong 241958e7b33aSMi Jinlong if (op->status) 242058e7b33aSMi Jinlong goto encode_op; 242158e7b33aSMi Jinlong 2422f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2423f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2424f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 24251da177e4SLinus Torvalds 24269a307403SJ. Bruce Fields /* Only from SEQUENCE */ 24279a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 24289a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 24299a307403SJ. Bruce Fields status = op->status; 24309a307403SJ. Bruce Fields goto out; 24319a307403SJ. Bruce Fields } 24328b70484cSTigran Mkrtchyan if (!op->status) { 2433f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2434f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 24358b70484cSTigran Mkrtchyan 2436f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 243737c593c5STigran Mkrtchyan clear_current_stateid(cstate); 24388b70484cSTigran Mkrtchyan 2439d781e3dfSJ. Bruce Fields if (current_fh->fh_export && 2440d781e3dfSJ. Bruce Fields need_wrongsec_check(rqstp)) 24414daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 24428b70484cSTigran Mkrtchyan } 24431da177e4SLinus Torvalds encode_op: 2444a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2445a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2446d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 24471da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 24481da177e4SLinus Torvalds } else { 24491da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 24501da177e4SLinus Torvalds status = op->status; 24511da177e4SLinus Torvalds } 24520407717dSBenny Halevy 2453fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2454fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 24550407717dSBenny Halevy 245658fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2457e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 24581da177e4SLinus Torvalds } 24591da177e4SLinus Torvalds 24604daeed25SKinglong Mee fh_put(current_fh); 24614daeed25SKinglong Mee fh_put(save_fh); 24624daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 24631da177e4SLinus Torvalds out: 2464*cc028a10SChuck Lever cstate->status = status; 24652f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 246630660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 2467*cc028a10SChuck Lever return rpc_success; 24681da177e4SLinus Torvalds } 24691da177e4SLinus Torvalds 247058e7b33aSMi Jinlong #define op_encode_hdr_size (2) 247158e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 247258e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 247358e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 247458e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 247558e7b33aSMi Jinlong 24768c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 24778c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 247858e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 247958e7b33aSMi Jinlong 248058e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 248158e7b33aSMi Jinlong 248258e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 248358e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 248458e7b33aSMi Jinlong op_encode_ace_maxsz) 248558e7b33aSMi Jinlong 248658e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 248758e7b33aSMi Jinlong 248858e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 248958e7b33aSMi Jinlong { 249058e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 249158e7b33aSMi Jinlong } 249258e7b33aSMi Jinlong 249358e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 249458e7b33aSMi Jinlong { 249558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 249658e7b33aSMi Jinlong } 249758e7b33aSMi Jinlong 24982282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 24992282cd2cSKinglong Mee { 25002282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 25012282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 25022282cd2cSKinglong Mee } 25032282cd2cSKinglong Mee 250458e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 250558e7b33aSMi Jinlong { 250658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 250758e7b33aSMi Jinlong } 250858e7b33aSMi Jinlong 250958e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 251058e7b33aSMi Jinlong { 251158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 251258e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 251358e7b33aSMi Jinlong } 251458e7b33aSMi Jinlong 2515b86cef60SJ. Bruce Fields /* 2516b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2517b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2518b86cef60SJ. Bruce Fields * reads unnecessarily. 2519b86cef60SJ. Bruce Fields */ 2520b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2521b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2522b86cef60SJ. Bruce Fields { 2523b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2524b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2525b86cef60SJ. Bruce Fields u32 ret = 0; 2526b86cef60SJ. Bruce Fields 2527b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2528b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2529b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2530b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2531b86cef60SJ. Bruce Fields 2532b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2533b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2534b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2535b86cef60SJ. Bruce Fields } 2536b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2537b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2538b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2539b86cef60SJ. Bruce Fields } 2540b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2541b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2542b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2543b86cef60SJ. Bruce Fields } 2544b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 25451ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2546b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2547b86cef60SJ. Bruce Fields } 2548b86cef60SJ. Bruce Fields /* 2549b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2550b86cef60SJ. Bruce Fields * supported_attributes) 2551b86cef60SJ. Bruce Fields */ 2552b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2553b86cef60SJ. Bruce Fields /* bitmask, length */ 2554b86cef60SJ. Bruce Fields ret += 20; 2555b86cef60SJ. Bruce Fields return ret; 2556b86cef60SJ. Bruce Fields } 2557b86cef60SJ. Bruce Fields 25582282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 25592282cd2cSKinglong Mee { 25602282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 25612282cd2cSKinglong Mee } 25622282cd2cSKinglong Mee 256358e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 256458e7b33aSMi Jinlong { 256558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 256658e7b33aSMi Jinlong * sizeof(__be32); 256758e7b33aSMi Jinlong } 256858e7b33aSMi Jinlong 256958e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 257058e7b33aSMi Jinlong { 257158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 257258e7b33aSMi Jinlong * sizeof(__be32); 257358e7b33aSMi Jinlong } 257458e7b33aSMi Jinlong 257558e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 257658e7b33aSMi Jinlong { 257758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 257858e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 257958e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 258058e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 258158e7b33aSMi Jinlong } 258258e7b33aSMi Jinlong 258358e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 258458e7b33aSMi Jinlong { 258558e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 258658e7b33aSMi Jinlong 258758e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 25883c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 258958e7b33aSMi Jinlong 2590622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 259158e7b33aSMi Jinlong } 259258e7b33aSMi Jinlong 259358e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 259458e7b33aSMi Jinlong { 25953c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 259658e7b33aSMi Jinlong 25973c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 25983c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 259958e7b33aSMi Jinlong 2600561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2601561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 260258e7b33aSMi Jinlong } 260358e7b33aSMi Jinlong 26042282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26052282cd2cSKinglong Mee { 26062282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 26072282cd2cSKinglong Mee } 26082282cd2cSKinglong Mee 260958e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 261058e7b33aSMi Jinlong { 261158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 261258e7b33aSMi Jinlong * sizeof(__be32); 261358e7b33aSMi Jinlong } 261458e7b33aSMi Jinlong 261558e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 261658e7b33aSMi Jinlong { 261758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 261858e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 261958e7b33aSMi Jinlong } 262058e7b33aSMi Jinlong 2621ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2622ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2623ccae70a9SJ. Bruce Fields { 2624d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2625d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2626ccae70a9SJ. Bruce Fields } 2627ccae70a9SJ. Bruce Fields 26282282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26292282cd2cSKinglong Mee { 26302282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 26312282cd2cSKinglong Mee * sizeof(__be32); 26322282cd2cSKinglong Mee } 26332282cd2cSKinglong Mee 263458e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 263558e7b33aSMi Jinlong { 263658e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 263758e7b33aSMi Jinlong } 263858e7b33aSMi Jinlong 26392282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26402282cd2cSKinglong Mee { 26412282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 26422282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 26432282cd2cSKinglong Mee } 26442282cd2cSKinglong Mee 264558e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 264658e7b33aSMi Jinlong { 2647480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2648480efaeeSJ. Bruce Fields sizeof(__be32); 264958e7b33aSMi Jinlong } 265058e7b33aSMi Jinlong 265158e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 265258e7b33aSMi Jinlong { 2653f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 265458e7b33aSMi Jinlong } 265558e7b33aSMi Jinlong 265658e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 265758e7b33aSMi Jinlong { 265858e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2659a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2660a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 266158e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 266258e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 266358e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 266458e7b33aSMi Jinlong /* eir_server_scope<> */\ 266558e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 266658e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 266758e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 266858e7b33aSMi Jinlong } 266958e7b33aSMi Jinlong 267058e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 267158e7b33aSMi Jinlong { 267258e7b33aSMi Jinlong return (op_encode_hdr_size + \ 267358e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 267458e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 267558e7b33aSMi Jinlong } 267658e7b33aSMi Jinlong 267758e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 267858e7b33aSMi Jinlong { 267958e7b33aSMi Jinlong return (op_encode_hdr_size + \ 268058e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 268158e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 268258e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 268358e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 268458e7b33aSMi Jinlong } 268558e7b33aSMi Jinlong 268629ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 268729ae7f9dSAnna Schumaker { 268829ae7f9dSAnna Schumaker return (op_encode_hdr_size + 268929ae7f9dSAnna Schumaker 1 /* wr_callback */ + 269029ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 269129ae7f9dSAnna Schumaker 2 /* wr_count */ + 269229ae7f9dSAnna Schumaker 1 /* wr_committed */ + 269329ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 269429ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 269529ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 269629ae7f9dSAnna Schumaker } 269729ae7f9dSAnna Schumaker 26986308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 26996308bc98SOlga Kornievskaia struct nfsd4_op *op) 27006308bc98SOlga Kornievskaia { 27016308bc98SOlga Kornievskaia return (op_encode_hdr_size + 27026308bc98SOlga Kornievskaia 2 /* osr_count */ + 27036308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 27046308bc98SOlga Kornievskaia } 27056308bc98SOlga Kornievskaia 270651911868SOlga Kornievskaia static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, 270751911868SOlga Kornievskaia struct nfsd4_op *op) 270851911868SOlga Kornievskaia { 270951911868SOlga Kornievskaia return (op_encode_hdr_size + 271051911868SOlga Kornievskaia 3 /* cnr_lease_time */ + 271151911868SOlga Kornievskaia 1 /* We support one cnr_source_server */ + 271251911868SOlga Kornievskaia 1 /* cnr_stateid seq */ + 271351911868SOlga Kornievskaia op_encode_stateid_maxsz /* cnr_stateid */ + 271451911868SOlga Kornievskaia 1 /* num cnr_source_server*/ + 271551911868SOlga Kornievskaia 1 /* nl4_type */ + 271651911868SOlga Kornievskaia 1 /* nl4 size */ + 271751911868SOlga Kornievskaia XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) 271851911868SOlga Kornievskaia * sizeof(__be32); 271951911868SOlga Kornievskaia } 272051911868SOlga Kornievskaia 27219cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 27222282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27232282cd2cSKinglong Mee { 27242282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 27252282cd2cSKinglong Mee 27262282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 27272282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 27282282cd2cSKinglong Mee 27292282cd2cSKinglong Mee return (op_encode_hdr_size + 27302282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 27312282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 27322282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 27332282cd2cSKinglong Mee } 27342282cd2cSKinglong Mee 27359cf514ccSChristoph Hellwig /* 27369cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 27379cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 27389cf514ccSChristoph Hellwig */ 27399cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 27409cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27419cf514ccSChristoph Hellwig { 27429cf514ccSChristoph Hellwig return (op_encode_hdr_size + 27439cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 27449cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 27459cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 27469cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 27479cf514ccSChristoph Hellwig } 27489cf514ccSChristoph Hellwig 27499cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27509cf514ccSChristoph Hellwig { 27519cf514ccSChristoph Hellwig return (op_encode_hdr_size + 27529cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 27539cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 27549cf514ccSChristoph Hellwig } 27559cf514ccSChristoph Hellwig 27569cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27579cf514ccSChristoph Hellwig { 27589cf514ccSChristoph Hellwig return (op_encode_hdr_size + 27599cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 27609cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 27619cf514ccSChristoph Hellwig } 27629cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 27639cf514ccSChristoph Hellwig 27642282cd2cSKinglong Mee 27652282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27662282cd2cSKinglong Mee { 27672282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 27682282cd2cSKinglong Mee } 27692282cd2cSKinglong Mee 277023e50fe3SFrank van der Linden static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp, 277123e50fe3SFrank van der Linden struct nfsd4_op *op) 277223e50fe3SFrank van der Linden { 277323e50fe3SFrank van der Linden u32 maxcount, rlen; 277423e50fe3SFrank van der Linden 277523e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 277623e50fe3SFrank van der Linden rlen = min_t(u32, XATTR_SIZE_MAX, maxcount); 277723e50fe3SFrank van der Linden 277823e50fe3SFrank van der Linden return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); 277923e50fe3SFrank van der Linden } 278023e50fe3SFrank van der Linden 278123e50fe3SFrank van der Linden static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp, 278223e50fe3SFrank van der Linden struct nfsd4_op *op) 278323e50fe3SFrank van der Linden { 278423e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 278523e50fe3SFrank van der Linden * sizeof(__be32); 278623e50fe3SFrank van der Linden } 278723e50fe3SFrank van der Linden static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp, 278823e50fe3SFrank van der Linden struct nfsd4_op *op) 278923e50fe3SFrank van der Linden { 279023e50fe3SFrank van der Linden u32 maxcount, rlen; 279123e50fe3SFrank van der Linden 279223e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 279323e50fe3SFrank van der Linden rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount); 279423e50fe3SFrank van der Linden 279523e50fe3SFrank van der Linden return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); 279623e50fe3SFrank van der Linden } 279723e50fe3SFrank van der Linden 279823e50fe3SFrank van der Linden static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp, 279923e50fe3SFrank van der Linden struct nfsd4_op *op) 280023e50fe3SFrank van der Linden { 280123e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 280223e50fe3SFrank van der Linden * sizeof(__be32); 280323e50fe3SFrank van der Linden } 280423e50fe3SFrank van der Linden 280523e50fe3SFrank van der Linden 2806bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2807b591480bSJ.Bruce Fields [OP_ACCESS] = { 2808eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2809b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 28101c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2811b591480bSJ.Bruce Fields }, 2812b591480bSJ.Bruce Fields [OP_CLOSE] = { 2813eb69853dSChristoph Hellwig .op_func = nfsd4_close, 281458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2815b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 28161c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 281757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2818b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2819b591480bSJ.Bruce Fields }, 2820b591480bSJ.Bruce Fields [OP_COMMIT] = { 2821eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 282258e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2823b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 28241c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2825b591480bSJ.Bruce Fields }, 2826b591480bSJ.Bruce Fields [OP_CREATE] = { 2827eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2828d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2829b001a1b6SBenny Halevy .op_name = "OP_CREATE", 28301c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2831b591480bSJ.Bruce Fields }, 2832b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2833eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 283458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2835b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 283658e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 283757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2838b591480bSJ.Bruce Fields }, 2839b591480bSJ.Bruce Fields [OP_GETATTR] = { 2840eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2841eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2842b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2843b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2844b591480bSJ.Bruce Fields }, 2845b591480bSJ.Bruce Fields [OP_GETFH] = { 2846eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2847b001a1b6SBenny Halevy .op_name = "OP_GETFH", 28481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2849b591480bSJ.Bruce Fields }, 2850b591480bSJ.Bruce Fields [OP_LINK] = { 2851eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2852c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2853c856694eSJ. Bruce Fields | OP_CACHEME, 2854b001a1b6SBenny Halevy .op_name = "OP_LINK", 28551c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 2856b591480bSJ.Bruce Fields }, 2857b591480bSJ.Bruce Fields [OP_LOCK] = { 2858eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 2859b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 2860b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 2861b001a1b6SBenny Halevy .op_name = "OP_LOCK", 28621c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2863b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 2864b591480bSJ.Bruce Fields }, 2865b591480bSJ.Bruce Fields [OP_LOCKT] = { 2866eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 2867b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 2868b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 28691c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 2870b591480bSJ.Bruce Fields }, 2871b591480bSJ.Bruce Fields [OP_LOCKU] = { 2872eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 287358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2874b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 28751c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 287657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 2877b591480bSJ.Bruce Fields }, 2878b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2879eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 2880d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2881b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 28821c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2883b591480bSJ.Bruce Fields }, 2884b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2885eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 2886d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2887b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 28881c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2889b591480bSJ.Bruce Fields }, 2890b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2891eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 2892b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 28931c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2894b591480bSJ.Bruce Fields }, 2895b591480bSJ.Bruce Fields [OP_OPEN] = { 2896eb69853dSChristoph Hellwig .op_func = nfsd4_open, 289758e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2898b001a1b6SBenny Halevy .op_name = "OP_OPEN", 28991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 2900b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 2901b591480bSJ.Bruce Fields }, 2902b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2903eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 290458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2905b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 29061c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 2907b591480bSJ.Bruce Fields }, 2908b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2909eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 291058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2911b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 29121c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 291357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 2914b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 2915b591480bSJ.Bruce Fields }, 2916b591480bSJ.Bruce Fields [OP_PUTFH] = { 2917eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 291868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 29195b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2920b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 29211c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2922b591480bSJ.Bruce Fields }, 2923eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2924eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 292568d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 29265b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2927b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 29281c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2929eeac294eSJ.Bruce Fields }, 2930b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2931eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 293268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 29335b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2934b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 29351c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2936b591480bSJ.Bruce Fields }, 2937b591480bSJ.Bruce Fields [OP_READ] = { 2938eb69853dSChristoph Hellwig .op_func = nfsd4_read, 293934b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 2940b001a1b6SBenny Halevy .op_name = "OP_READ", 29411c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 294257832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 2943b591480bSJ.Bruce Fields }, 2944b591480bSJ.Bruce Fields [OP_READDIR] = { 2945eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 2946b001a1b6SBenny Halevy .op_name = "OP_READDIR", 29471c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 2948b591480bSJ.Bruce Fields }, 2949b591480bSJ.Bruce Fields [OP_READLINK] = { 2950eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 2951b001a1b6SBenny Halevy .op_name = "OP_READLINK", 29521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 2953b591480bSJ.Bruce Fields }, 2954b591480bSJ.Bruce Fields [OP_REMOVE] = { 2955eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 2956c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2957b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 29581c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 2959b591480bSJ.Bruce Fields }, 2960b591480bSJ.Bruce Fields [OP_RENAME] = { 2961eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 2962c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 296358e7b33aSMi Jinlong .op_name = "OP_RENAME", 29641c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 2965b591480bSJ.Bruce Fields }, 2966b591480bSJ.Bruce Fields [OP_RENEW] = { 2967eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 296858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 296958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2970b001a1b6SBenny Halevy .op_name = "OP_RENEW", 29711c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 297258e7b33aSMi Jinlong 2973b591480bSJ.Bruce Fields }, 2974b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2975eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 297668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 297758e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2978b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 29791c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2980b591480bSJ.Bruce Fields }, 2981b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2982eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 298358e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2984b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 29851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 2986b591480bSJ.Bruce Fields }, 2987dcb488a3SAndy Adamson [OP_SECINFO] = { 2988eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 298934b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 299068d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2991b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 29921c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 2993dcb488a3SAndy Adamson }, 2994b591480bSJ.Bruce Fields [OP_SETATTR] = { 2995eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 2996b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2997b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 2998b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 29991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 300057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 3001b591480bSJ.Bruce Fields }, 3002b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 3003eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 300458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3005b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 3006b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 3007b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 30081c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 3009b591480bSJ.Bruce Fields }, 3010b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 3011eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 301258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3013c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 3014b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 30151c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3016b591480bSJ.Bruce Fields }, 3017b591480bSJ.Bruce Fields [OP_VERIFY] = { 3018eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 3019b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 30201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3021b591480bSJ.Bruce Fields }, 3022b591480bSJ.Bruce Fields [OP_WRITE] = { 3023eb69853dSChristoph Hellwig .op_func = nfsd4_write, 3024c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3025b001a1b6SBenny Halevy .op_name = "OP_WRITE", 30261c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 302757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 3028b591480bSJ.Bruce Fields }, 3029b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 3030eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 303158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 303258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3033b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 30341c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3035b591480bSJ.Bruce Fields }, 3036069b6ad4SAndy Adamson 3037069b6ad4SAndy Adamson /* NFSv4.1 operations */ 3038069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 3039eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 304058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 304158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3042069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 30431c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 3044069b6ad4SAndy Adamson }, 3045cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 3046eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 3047cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3048cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 30491c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3050cb73a9f4SJ. Bruce Fields }, 30511d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 3052eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 305358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 305458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 30551d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 30561c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 30571d1bc8f2SJ. Bruce Fields }, 3058069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 3059eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 306058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 306158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3062069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 30631c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 3064069b6ad4SAndy Adamson }, 3065069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 3066eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 306758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 306858e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3069069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 30701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3071069b6ad4SAndy Adamson }, 3072069b6ad4SAndy Adamson [OP_SEQUENCE] = { 3073eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 3074f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 3075069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 30761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 3077069b6ad4SAndy Adamson }, 3078094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 3079eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 308058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 308158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3082094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 30831c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3084094b5d74SBenny Halevy }, 30854dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 3086eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 308758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 30884dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 30891c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 30904dc6ec00SJ. Bruce Fields }, 309104f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 3092eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 3093ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 309468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 309504f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 30961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 309704f4ad16SJ. Bruce Fields }, 309817456804SBryan Schumaker [OP_TEST_STATEID] = { 3099eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 310017456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 310117456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 31021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 310317456804SBryan Schumaker }, 3104e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 3105eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 310658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3107e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 310857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 31091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3110e1ca12dfSBryan Schumaker }, 31119cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 31129cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 3113eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 311434b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 31159cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 31169cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 31171c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 31189cf514ccSChristoph Hellwig }, 31199cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 3120eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 312134b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 31229cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 31239cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 31241c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 31259cf514ccSChristoph Hellwig }, 31269cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 3127eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 31289cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 31299cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 31301c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 31319cf514ccSChristoph Hellwig }, 31329cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 3133eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 31349cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 31359cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 31361c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 31379cf514ccSChristoph Hellwig }, 31389cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 313924bab491SAnna Schumaker 314024bab491SAnna Schumaker /* NFSv4.2 operations */ 314195d871f0SAnna Schumaker [OP_ALLOCATE] = { 3142eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 314303b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 314495d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 31451c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 314695d871f0SAnna Schumaker }, 3147b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 3148eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 314903b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3150b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 31511c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3152b0cb9085SAnna Schumaker }, 3153ffa0160aSChristoph Hellwig [OP_CLONE] = { 3154eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 315503b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3156ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 31571c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3158ffa0160aSChristoph Hellwig }, 315929ae7f9dSAnna Schumaker [OP_COPY] = { 3160eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 316103b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 316229ae7f9dSAnna Schumaker .op_name = "OP_COPY", 31631c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 316429ae7f9dSAnna Schumaker }, 316524bab491SAnna Schumaker [OP_SEEK] = { 3166eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 316724bab491SAnna Schumaker .op_name = "OP_SEEK", 31681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 316924bab491SAnna Schumaker }, 31706308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 31716308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 31726308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 31736308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 31746308bc98SOlga Kornievskaia }, 3175885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 3176885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 3177885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3178885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 3179885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 3180885e2bf3SOlga Kornievskaia }, 318151911868SOlga Kornievskaia [OP_COPY_NOTIFY] = { 318251911868SOlga Kornievskaia .op_func = nfsd4_copy_notify, 318351911868SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 318451911868SOlga Kornievskaia .op_name = "OP_COPY_NOTIFY", 318551911868SOlga Kornievskaia .op_rsize_bop = nfsd4_copy_notify_rsize, 318651911868SOlga Kornievskaia }, 318723e50fe3SFrank van der Linden [OP_GETXATTR] = { 318823e50fe3SFrank van der Linden .op_func = nfsd4_getxattr, 318923e50fe3SFrank van der Linden .op_name = "OP_GETXATTR", 319023e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_getxattr_rsize, 319123e50fe3SFrank van der Linden }, 319223e50fe3SFrank van der Linden [OP_SETXATTR] = { 319323e50fe3SFrank van der Linden .op_func = nfsd4_setxattr, 319423e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 319523e50fe3SFrank van der Linden .op_name = "OP_SETXATTR", 319623e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_setxattr_rsize, 319723e50fe3SFrank van der Linden }, 319823e50fe3SFrank van der Linden [OP_LISTXATTRS] = { 319923e50fe3SFrank van der Linden .op_func = nfsd4_listxattrs, 320023e50fe3SFrank van der Linden .op_name = "OP_LISTXATTRS", 320123e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_listxattrs_rsize, 320223e50fe3SFrank van der Linden }, 320323e50fe3SFrank van der Linden [OP_REMOVEXATTR] = { 320423e50fe3SFrank van der Linden .op_func = nfsd4_removexattr, 320523e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 320623e50fe3SFrank van der Linden .op_name = "OP_REMOVEXATTR", 320723e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_removexattr_rsize, 320823e50fe3SFrank van der Linden }, 3209b591480bSJ.Bruce Fields }; 3210b591480bSJ.Bruce Fields 3211ed941643SAndrew Elble /** 3212ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 3213ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 3214ed941643SAndrew Elble * 3215ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 3216ed941643SAndrew Elble * 3217ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 3218ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 3219ed941643SAndrew Elble */ 3220ed941643SAndrew Elble 3221ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 3222ed941643SAndrew Elble { 3223ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 3224ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 3225ed941643SAndrew Elble struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 3226ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 3227ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 3228ed941643SAndrew Elble u32 opiter; 3229ed941643SAndrew Elble 3230ed941643SAndrew Elble if (!cstate->minorversion) 3231ed941643SAndrew Elble return false; 3232ed941643SAndrew Elble 323344b49aa6SZheng Bin if (cstate->spo_must_allowed) 3234ed941643SAndrew Elble return true; 3235ed941643SAndrew Elble 3236ed941643SAndrew Elble opiter = resp->opcnt; 3237ed941643SAndrew Elble while (opiter < argp->opcnt) { 3238ed941643SAndrew Elble this = &argp->ops[opiter++]; 3239ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 3240ed941643SAndrew Elble cstate->clp->cl_mach_cred && 3241ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 3242ed941643SAndrew Elble cstate->spo_must_allowed = true; 3243ed941643SAndrew Elble return true; 3244ed941643SAndrew Elble } 3245ed941643SAndrew Elble } 3246ed941643SAndrew Elble cstate->spo_must_allowed = false; 3247ed941643SAndrew Elble return false; 3248ed941643SAndrew Elble } 3249ed941643SAndrew Elble 32504f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 32514f0cefbfSJ. Bruce Fields { 325205b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 32534f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 32542282cd2cSKinglong Mee 32552282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 32562282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 32574f0cefbfSJ. Bruce Fields } 32584f0cefbfSJ. Bruce Fields 325907d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 326007d1f802SJ. Bruce Fields { 326107d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 326207d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 326307d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 326407d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 326507d1f802SJ. Bruce Fields } 326607d1f802SJ. Bruce Fields } 326707d1f802SJ. Bruce Fields 3268f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 3269b001a1b6SBenny Halevy { 3270b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 3271b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 3272b001a1b6SBenny Halevy return "unknown_operation"; 3273b001a1b6SBenny Halevy } 3274b001a1b6SBenny Halevy 32751da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 32761da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 32771da177e4SLinus Torvalds 3278860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 32790a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 3280f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 3281dcc46991SChuck Lever .pc_decode = nfs4svc_decode_voidarg, 328263f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_voidres, 32830a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 32840a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 32850a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 32860a93a47fSYu Zhiguo .pc_xdrressize = 1, 32870a93a47fSYu Zhiguo }, 32880a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 3289f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 3290026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 329163f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 32920a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 32930a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 32943e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 32950a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 32960a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 32970a93a47fSYu Zhiguo }, 32981da177e4SLinus Torvalds }; 32991da177e4SLinus Torvalds 33007fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 3301e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 33021da177e4SLinus Torvalds .vs_vers = 4, 33031da177e4SLinus Torvalds .vs_nproc = 2, 33041da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 33057fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 33061da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 33071da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 330805a45a2dSJeff Layton .vs_rpcb_optnl = true, 33095283b03eSJeff Layton .vs_need_cong_ctrl = true, 33101da177e4SLinus Torvalds }; 33111da177e4SLinus Torvalds 33121da177e4SLinus Torvalds /* 33131da177e4SLinus Torvalds * Local variables: 33141da177e4SLinus Torvalds * c-basic-offset: 8 33151da177e4SLinus Torvalds * End: 33161da177e4SLinus Torvalds */ 3317