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> 410cfcd405SDai Ngo #include <linux/nfs_ssc.h> 421da177e4SLinus Torvalds 4358e7b33aSMi Jinlong #include "idmap.h" 449a74af21SBoaz Harrosh #include "cache.h" 459a74af21SBoaz Harrosh #include "xdr4.h" 460a3adadeSJ. Bruce Fields #include "vfs.h" 478b70484cSTigran Mkrtchyan #include "current_stateid.h" 483320fef1SStanislav Kinsbursky #include "netns.h" 494ac7249eSChristoph Hellwig #include "acl.h" 509cf514ccSChristoph Hellwig #include "pnfs.h" 5131ef83dcSChristoph Hellwig #include "trace.h" 521da177e4SLinus Torvalds 53d6c9e436SChuck Lever static bool inter_copy_offload_enable; 54d6c9e436SChuck Lever module_param(inter_copy_offload_enable, bool, 0644); 55d6c9e436SChuck Lever MODULE_PARM_DESC(inter_copy_offload_enable, 56d6c9e436SChuck Lever "Enable inter server to server copy offload. Default: false"); 57d6c9e436SChuck Lever 58f4e44b39SDai Ngo #ifdef CONFIG_NFSD_V4_2_INTER_SSC 59f4e44b39SDai Ngo static int nfsd4_ssc_umount_timeout = 900000; /* default to 15 mins */ 60f4e44b39SDai Ngo module_param(nfsd4_ssc_umount_timeout, int, 0644); 61f4e44b39SDai Ngo MODULE_PARM_DESC(nfsd4_ssc_umount_timeout, 62f4e44b39SDai Ngo "idle msecs before unmount export from source server"); 63f4e44b39SDai Ngo #endif 64f4e44b39SDai Ngo 6518032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 6618032ca0SDavid Quigley #include <linux/security.h> 6718032ca0SDavid Quigley 6818032ca0SDavid Quigley static inline void 6918032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7018032ca0SDavid Quigley { 712b0143b5SDavid Howells struct inode *inode = d_inode(resfh->fh_dentry); 7218032ca0SDavid Quigley int status; 7318032ca0SDavid Quigley 745955102cSAl Viro inode_lock(inode); 7518032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 7618032ca0SDavid Quigley label->data, label->len); 775955102cSAl Viro inode_unlock(inode); 7818032ca0SDavid Quigley 7918032ca0SDavid Quigley if (status) 8018032ca0SDavid Quigley /* 8118032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 8218032ca0SDavid Quigley * already have created a new file, so it may be too 8318032ca0SDavid Quigley * late. For now this seems the least of evils: 8418032ca0SDavid Quigley */ 8518032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 8618032ca0SDavid Quigley 8718032ca0SDavid Quigley return; 8818032ca0SDavid Quigley } 8918032ca0SDavid Quigley #else 9018032ca0SDavid Quigley static inline void 9118032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 9218032ca0SDavid Quigley { } 9318032ca0SDavid Quigley #endif 9418032ca0SDavid Quigley 951da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 961da177e4SLinus Torvalds 973c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 983c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 993c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 1003c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 1013c8e0316SYu Zhiguo }; 1023c8e0316SYu Zhiguo 1033c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 1043c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 1053c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 1063c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 1073c8e0316SYu Zhiguo }; 1083c8e0316SYu Zhiguo 1093c8e0316SYu Zhiguo static __be32 1103c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1113c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 1123c8e0316SYu Zhiguo { 1133c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 11432ddd944SJ. Bruce Fields struct svc_export *exp = cstate->current_fh.fh_export; 1153c8e0316SYu Zhiguo 116916d2d84SJ. Bruce Fields if (!nfsd_attrs_supported(cstate->minorversion, bmval)) 1173c8e0316SYu Zhiguo return nfserr_attrnotsupp; 118916d2d84SJ. Bruce Fields if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) 1193c8e0316SYu Zhiguo return nfserr_attrnotsupp; 12032ddd944SJ. Bruce Fields if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && 12132ddd944SJ. Bruce Fields !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) 12232ddd944SJ. Bruce Fields return nfserr_attrnotsupp; 123916d2d84SJ. Bruce Fields if (writable && !bmval_is_subset(bmval, writable)) 1243c8e0316SYu Zhiguo return nfserr_inval; 12547057abdSAndreas Gruenbacher if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && 12647057abdSAndreas Gruenbacher (bmval[1] & FATTR4_WORD1_MODE)) 12747057abdSAndreas Gruenbacher return nfserr_inval; 1283c8e0316SYu Zhiguo return nfs_ok; 1293c8e0316SYu Zhiguo } 1303c8e0316SYu Zhiguo 1313c8e0316SYu Zhiguo static __be32 1323c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1333c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1343c8e0316SYu Zhiguo { 1353c8e0316SYu Zhiguo __be32 status = nfs_ok; 1363c8e0316SYu Zhiguo 1373c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1383c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1393c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1403c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1413c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1423c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1433c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1443c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1453c8e0316SYu Zhiguo } 1463c8e0316SYu Zhiguo 1473c8e0316SYu Zhiguo return status; 1483c8e0316SYu Zhiguo } 1493c8e0316SYu Zhiguo 1509208faf2SYu Zhiguo static int 1519208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1529208faf2SYu Zhiguo { 1539208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1549208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1559208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1569208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1579208faf2SYu Zhiguo } 1589208faf2SYu Zhiguo 1599208faf2SYu Zhiguo /* 1609208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1619208faf2SYu Zhiguo * in the returned attr bitmap. 1629208faf2SYu Zhiguo */ 1639208faf2SYu Zhiguo static void 1649208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1659208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1669208faf2SYu Zhiguo { 1679208faf2SYu Zhiguo __be32 status; 1689208faf2SYu Zhiguo 1699208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1709208faf2SYu Zhiguo if (status) 1719208faf2SYu Zhiguo /* 1729208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1739208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1749208faf2SYu Zhiguo * So this seems the least of evils: 1759208faf2SYu Zhiguo */ 1769208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1779208faf2SYu Zhiguo } 1789208faf2SYu Zhiguo 1791da177e4SLinus Torvalds static inline void 1801da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1811da177e4SLinus Torvalds { 1821da177e4SLinus Torvalds fh_put(dst); 1831da177e4SLinus Torvalds dget(src->fh_dentry); 1841da177e4SLinus Torvalds if (src->fh_export) 185bf18f163SKinglong Mee exp_get(src->fh_export); 1861da177e4SLinus Torvalds *dst = *src; 1871da177e4SLinus Torvalds } 1881da177e4SLinus Torvalds 189b37ad28bSAl Viro static __be32 190dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1911da177e4SLinus Torvalds { 192b37ad28bSAl Viro __be32 status; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds if (open->op_truncate && 1951da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1961da177e4SLinus Torvalds return nfserr_inval; 1971da177e4SLinus Torvalds 198a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 199a043226bSJ. Bruce Fields 2001da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 2018837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 2029801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 2038837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 20457ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 2058837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds return status; 2101da177e4SLinus Torvalds } 2111da177e4SLinus Torvalds 212aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 213aadab6c6SJ. Bruce Fields { 2142b0143b5SDavid Howells umode_t mode = d_inode(fh->fh_dentry)->i_mode; 215aadab6c6SJ. Bruce Fields 216aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 217aadab6c6SJ. Bruce Fields return nfs_ok; 218aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 219aadab6c6SJ. Bruce Fields return nfserr_isdir; 220aadab6c6SJ. Bruce Fields /* 221aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 222aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 223aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 224aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 225aadab6c6SJ. Bruce Fields * regular file. 226aadab6c6SJ. Bruce Fields */ 227aadab6c6SJ. Bruce Fields return nfserr_symlink; 228aadab6c6SJ. Bruce Fields } 229aadab6c6SJ. Bruce Fields 230bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2311da177e4SLinus Torvalds { 232bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 233bbc9c36cSJ. Bruce Fields return; 234bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 235bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 236bbc9c36cSJ. Bruce Fields } 237bbc9c36cSJ. Bruce Fields 238bbc9c36cSJ. Bruce Fields static __be32 239c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 240bbc9c36cSJ. Bruce Fields { 241bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 2427007c90fSNeil Brown int accmode; 243b37ad28bSAl Viro __be32 status; 2441da177e4SLinus Torvalds 245c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 246c0e6bee4SJ. Bruce Fields if (!*resfh) 24759deeb9eSJ. Bruce Fields return nfserr_jukebox; 248c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 249500c2481Szhengbin open->op_truncate = false; 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds if (open->op_create) { 25279fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 25379fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 25479fb54abSBenny Halevy * 25579fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 25679fb54abSBenny Halevy * Reply Cache | server | | 25779fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 25879fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 25979fb54abSBenny Halevy * | | | (SHOULD) 26079fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 26179fb54abSBenny Halevy * | | | (SHOULD NOT) 26279fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 26379fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 26479fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 26579fb54abSBenny Halevy */ 26679fb54abSBenny Halevy 2671da177e4SLinus Torvalds /* 2681da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 269ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2701da177e4SLinus Torvalds */ 271880a3a53SJ. Bruce Fields current->fs->umask = open->op_umask; 2721708e50bSChuck Lever status = do_nfsd_create(rqstp, current_fh, open->op_fname, 2731708e50bSChuck Lever open->op_fnamelen, &open->op_iattr, 274c0e6bee4SJ. Bruce Fields *resfh, open->op_createmode, 275749997e5SJeff Layton (u32 *)open->op_verf.data, 276856121b2SJ. Bruce Fields &open->op_truncate, &open->op_created); 277880a3a53SJ. Bruce Fields current->fs->umask = 0; 278749997e5SJeff Layton 27918032ca0SDavid Quigley if (!status && open->op_label.len) 280c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 28118032ca0SDavid Quigley 28299f88726SJ. Bruce Fields /* 283ead8fb8cSKinglong Mee * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 284ead8fb8cSKinglong Mee * use the returned bitmask to indicate which attributes 285ead8fb8cSKinglong Mee * we used to store the verifier: 286749997e5SJeff Layton */ 287ead8fb8cSKinglong Mee if (nfsd_create_is_exclusive(open->op_createmode) && status == 0) 288ead8fb8cSKinglong Mee open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | 289749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 2904335723eSJ. Bruce Fields } else 2914335723eSJ. Bruce Fields /* 2924335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 2934335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 2944335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 2954335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 2964335723eSJ. Bruce Fields */ 2971da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 2981708e50bSChuck Lever open->op_fname, open->op_fnamelen, *resfh); 299aadab6c6SJ. Bruce Fields if (status) 300aadab6c6SJ. Bruce Fields goto out; 301c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 302af85852dSJ. Bruce Fields if (status) 303af85852dSJ. Bruce Fields goto out; 3041da177e4SLinus Torvalds 3059208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 306c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 3079208faf2SYu Zhiguo 308c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 3097007c90fSNeil Brown accmode = NFSD_MAY_NOP; 31089f6c336SJ. Bruce Fields if (open->op_created || 31189f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 3127007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 313c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 31441fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 315af85852dSJ. Bruce Fields out: 3161da177e4SLinus Torvalds return status; 3171da177e4SLinus Torvalds } 3181da177e4SLinus Torvalds 319b37ad28bSAl Viro static __be32 320bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 3211da177e4SLinus Torvalds { 322bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 323b37ad28bSAl Viro __be32 status; 3249f415eb2SJ. Bruce Fields int accmode = 0; 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 3271da177e4SLinus Torvalds * set the change info 3281da177e4SLinus Torvalds */ 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 3311da177e4SLinus Torvalds 332bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 3351da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 3369f415eb2SJ. Bruce Fields /* 3379f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 3389f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 3399f415eb2SJ. Bruce Fields * should let it succeed now if possible. 3409f415eb2SJ. Bruce Fields * 3419f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 3429f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 3439f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 3449f415eb2SJ. Bruce Fields */ 3459f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 3469f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 3471da177e4SLinus Torvalds 3489f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds return status; 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds 35360adfc50SAndy Adamson static void 35460adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 35560adfc50SAndy Adamson { 35660adfc50SAndy Adamson struct nfsd4_sessionid *sid = 35760adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 35860adfc50SAndy Adamson 35960adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 36060adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 36160adfc50SAndy Adamson } 3621da177e4SLinus Torvalds 3637191155bSJ.Bruce Fields static __be32 364ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 365eb69853dSChristoph Hellwig union nfsd4_op_u *u) 3661da177e4SLinus Torvalds { 367eb69853dSChristoph Hellwig struct nfsd4_open *open = &u->open; 368b37ad28bSAl Viro __be32 status; 369c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 3703320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3713320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 37203f318caSJ. Bruce Fields bool reclaim = false; 3736668958fSAndy Adamson 374fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3751708e50bSChuck Lever (int)open->op_fnamelen, open->op_fname, 376fe0750e5SJ. Bruce Fields open->op_openowner); 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds /* This check required by spec. */ 3791da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3801da177e4SLinus Torvalds return nfserr_inval; 3811da177e4SLinus Torvalds 382500c2481Szhengbin open->op_created = false; 383ab1350b2SMi Jinlong /* 384ab1350b2SMi Jinlong * RFC5661 18.51.3 385ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 386ab1350b2SMi Jinlong */ 387ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 388ec59659bSJ. Bruce Fields !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) && 389ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 390ab1350b2SMi Jinlong return nfserr_grace; 391ab1350b2SMi Jinlong 39260adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 39360adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 39460adfc50SAndy Adamson 3951da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3966cd22668SKinglong Mee status = nfsd4_process_open1(cstate, open, nn); 397a90b061cSAl Viro if (status == nfserr_replay_me) { 398fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 399ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 400a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 401a4773c08SJ. Bruce Fields &rp->rp_openfh); 4028837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 4031da177e4SLinus Torvalds if (status) 4041da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 4051da177e4SLinus Torvalds " restoring previous filehandle\n"); 4061da177e4SLinus Torvalds else 407a90b061cSAl Viro status = nfserr_replay_me; 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds if (status) 4101da177e4SLinus Torvalds goto out; 4119d313b17SJ. Bruce Fields if (open->op_xdr_error) { 4129d313b17SJ. Bruce Fields status = open->op_xdr_error; 4139d313b17SJ. Bruce Fields goto out; 4149d313b17SJ. Bruce Fields } 415fb553c0fSJ. Bruce Fields 4163c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 4173c8e0316SYu Zhiguo if (status) 4183c8e0316SYu Zhiguo goto out; 4193c8e0316SYu Zhiguo 420fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 421fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 422cbd0d51aSJ. Bruce Fields status = nfserr_grace; 423c87fb4a3SJ. Bruce Fields if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 424cbd0d51aSJ. Bruce Fields goto out; 425cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 426c87fb4a3SJ. Bruce Fields if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 427cbd0d51aSJ. Bruce Fields goto out; 428fb553c0fSJ. Bruce Fields 4291da177e4SLinus Torvalds switch (open->op_claim_type) { 4300dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4311da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 432c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4331da177e4SLinus Torvalds if (status) 4341da177e4SLinus Torvalds goto out; 4351da177e4SLinus Torvalds break; 4361da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 4371722b046SJ. Bruce Fields status = nfs4_check_open_reclaim(cstate->clp); 4380cf99b91SMi Jinlong if (status) 4390cf99b91SMi Jinlong goto out; 440ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 44103f318caSJ. Bruce Fields reclaim = true; 442df561f66SGustavo A. R. Silva fallthrough; 4438b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4448b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 445bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4461da177e4SLinus Torvalds if (status) 4471da177e4SLinus Torvalds goto out; 448c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4491da177e4SLinus Torvalds break; 4508b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4511da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4522fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4531da177e4SLinus Torvalds open->op_claim_type); 4541da177e4SLinus Torvalds status = nfserr_notsupp; 4551da177e4SLinus Torvalds goto out; 4561da177e4SLinus Torvalds default: 4572fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4581da177e4SLinus Torvalds open->op_claim_type); 4591da177e4SLinus Torvalds status = nfserr_inval; 4601da177e4SLinus Torvalds goto out; 4611da177e4SLinus Torvalds } 4621da177e4SLinus Torvalds /* 4631da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4641da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4651da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4661da177e4SLinus Torvalds */ 467c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 468b3fbfe0eSJeff Layton WARN(status && open->op_created, 469b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 470b3fbfe0eSJeff Layton be32_to_cpu(status)); 47103f318caSJ. Bruce Fields if (reclaim && !status) 47203f318caSJ. Bruce Fields nn->somebody_reclaimed = true; 4731da177e4SLinus Torvalds out: 474c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 475c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 476c0e6bee4SJ. Bruce Fields fh_put(resfh); 477c0e6bee4SJ. Bruce Fields kfree(resfh); 478c0e6bee4SJ. Bruce Fields } 47942297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4809411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4811da177e4SLinus Torvalds return status; 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds /* 4859d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4869d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4879d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4889d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4899d313b17SJ. Bruce Fields */ 4909d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4919d313b17SJ. Bruce Fields { 492eb69853dSChristoph Hellwig struct nfsd4_open *open = &op->u.open; 4939d313b17SJ. Bruce Fields 4949d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4959d313b17SJ. Bruce Fields return op->status; 4969d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4979d313b17SJ. Bruce Fields return op->status; 4989d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 499eb69853dSChristoph Hellwig return nfsd4_open(rqstp, cstate, &op->u); 5009d313b17SJ. Bruce Fields } 5019d313b17SJ. Bruce Fields 5029d313b17SJ. Bruce Fields /* 5031da177e4SLinus Torvalds * filehandle-manipulating ops. 5041da177e4SLinus Torvalds */ 5057191155bSJ.Bruce Fields static __be32 506b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 507eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5081da177e4SLinus Torvalds { 509eb69853dSChristoph Hellwig u->getfh = &cstate->current_fh; 5101da177e4SLinus Torvalds return nfs_ok; 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds 5137191155bSJ.Bruce Fields static __be32 514ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 515eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5161da177e4SLinus Torvalds { 517eb69853dSChristoph Hellwig struct nfsd4_putfh *putfh = &u->putfh; 518b9e8638eSOlga Kornievskaia __be32 ret; 519eb69853dSChristoph Hellwig 520ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 521ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 522d8b26071SNeilBrown memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval, 523ca364317SJ.Bruce Fields putfh->pf_fhlen); 524b9e8638eSOlga Kornievskaia ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 525b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 526b9e8638eSOlga Kornievskaia if (ret == nfserr_stale && putfh->no_verify) { 527b9e8638eSOlga Kornievskaia SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN); 528b9e8638eSOlga Kornievskaia ret = 0; 529b9e8638eSOlga Kornievskaia } 530b9e8638eSOlga Kornievskaia #endif 531b9e8638eSOlga Kornievskaia return ret; 5321da177e4SLinus Torvalds } 5331da177e4SLinus Torvalds 5347191155bSJ.Bruce Fields static __be32 535b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 536eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5371da177e4SLinus Torvalds { 538b37ad28bSAl Viro __be32 status; 5391da177e4SLinus Torvalds 540ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 541df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5421da177e4SLinus Torvalds return status; 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds 5457191155bSJ.Bruce Fields static __be32 546b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 547eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5481da177e4SLinus Torvalds { 549ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5501da177e4SLinus Torvalds return nfserr_restorefh; 5511da177e4SLinus Torvalds 552ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 55351100d2bSOlga Kornievskaia if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) { 55437c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 55551100d2bSOlga Kornievskaia SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); 55637c593c5STigran Mkrtchyan } 5571da177e4SLinus Torvalds return nfs_ok; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds 5607191155bSJ.Bruce Fields static __be32 561b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 562eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5631da177e4SLinus Torvalds { 564ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 56551100d2bSOlga Kornievskaia if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) { 56637c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 56751100d2bSOlga Kornievskaia SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG); 56837c593c5STigran Mkrtchyan } 5691da177e4SLinus Torvalds return nfs_ok; 5701da177e4SLinus Torvalds } 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds /* 5731da177e4SLinus Torvalds * misc nfsv4 ops 5741da177e4SLinus Torvalds */ 5757191155bSJ.Bruce Fields static __be32 576ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 577eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5781da177e4SLinus Torvalds { 579eb69853dSChristoph Hellwig struct nfsd4_access *access = &u->access; 580c11d7fd1SFrank van der Linden u32 access_full; 581eb69853dSChristoph Hellwig 582c11d7fd1SFrank van der Linden access_full = NFS3_ACCESS_FULL; 583c11d7fd1SFrank van der Linden if (cstate->minorversion >= 2) 584c11d7fd1SFrank van der Linden access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD | 585c11d7fd1SFrank van der Linden NFS4_ACCESS_XAWRITE; 586c11d7fd1SFrank van der Linden 587c11d7fd1SFrank van der Linden if (access->ac_req_access & ~access_full) 5881da177e4SLinus Torvalds return nfserr_inval; 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 591ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 592ca364317SJ.Bruce Fields &access->ac_supported); 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds 595b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 596ab4684d1SChuck Lever { 59727c438f5STrond Myklebust __be32 *verf = (__be32 *)verifier->data; 598ab4684d1SChuck Lever 59927c438f5STrond Myklebust BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data)); 60027c438f5STrond Myklebust 60127c438f5STrond Myklebust nfsd_copy_boot_verifier(verf, net_generic(net, nfsd_net_id)); 602ab4684d1SChuck Lever } 603ab4684d1SChuck Lever 6047191155bSJ.Bruce Fields static __be32 605ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 606eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6071da177e4SLinus Torvalds { 608eb69853dSChristoph Hellwig struct nfsd4_commit *commit = &u->commit; 609eb69853dSChristoph Hellwig 61075c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 611524ff1afSTrond Myklebust commit->co_count, 612524ff1afSTrond Myklebust (__be32 *)commit->co_verf.data); 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds 615b37ad28bSAl Viro static __be32 616ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 617eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6181da177e4SLinus Torvalds { 619eb69853dSChristoph Hellwig struct nfsd4_create *create = &u->create; 6201da177e4SLinus Torvalds struct svc_fh resfh; 621b37ad28bSAl Viro __be32 status; 6221da177e4SLinus Torvalds dev_t rdev; 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 6251da177e4SLinus Torvalds 626fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 6271da177e4SLinus Torvalds if (status) 6281da177e4SLinus Torvalds return status; 6291da177e4SLinus Torvalds 6303c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 6313c8e0316SYu Zhiguo nfsd_attrmask); 6323c8e0316SYu Zhiguo if (status) 6333c8e0316SYu Zhiguo return status; 6343c8e0316SYu Zhiguo 635880a3a53SJ. Bruce Fields current->fs->umask = create->cr_umask; 6361da177e4SLinus Torvalds switch (create->cr_type) { 6371da177e4SLinus Torvalds case NF4LNK: 638ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 639ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6401e444f5bSKinglong Mee create->cr_data, &resfh); 6411da177e4SLinus Torvalds break; 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds case NF4BLK: 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_IFBLK, rdev, &resfh); 6521da177e4SLinus Torvalds break; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds case NF4CHR: 655880a3a53SJ. Bruce Fields status = nfserr_inval; 6561da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6571da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6581da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 659880a3a53SJ. Bruce Fields goto out_umask; 660ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 661ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 662ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6631da177e4SLinus Torvalds break; 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds case NF4SOCK: 666ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 667ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 668ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6691da177e4SLinus Torvalds break; 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds case NF4FIFO: 672ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 673ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 674ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6751da177e4SLinus Torvalds break; 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds case NF4DIR: 6781da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 679ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 680ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 681ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6821da177e4SLinus Torvalds break; 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds default: 6851da177e4SLinus Torvalds status = nfserr_badtype; 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds 6889208faf2SYu Zhiguo if (status) 6899208faf2SYu Zhiguo goto out; 6909208faf2SYu Zhiguo 69118032ca0SDavid Quigley if (create->cr_label.len) 69218032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 69318032ca0SDavid Quigley 6949208faf2SYu Zhiguo if (create->cr_acl != NULL) 6959208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6969208faf2SYu Zhiguo create->cr_bmval); 6979208faf2SYu Zhiguo 698ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 699ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 700ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 7019208faf2SYu Zhiguo out: 7021da177e4SLinus Torvalds fh_put(&resfh); 703880a3a53SJ. Bruce Fields out_umask: 704880a3a53SJ. Bruce Fields current->fs->umask = 0; 7051da177e4SLinus Torvalds return status; 7061da177e4SLinus Torvalds } 7071da177e4SLinus Torvalds 7087191155bSJ.Bruce Fields static __be32 709ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 710eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7111da177e4SLinus Torvalds { 712eb69853dSChristoph Hellwig struct nfsd4_getattr *getattr = &u->getattr; 713b37ad28bSAl Viro __be32 status; 7141da177e4SLinus Torvalds 7158837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 7161da177e4SLinus Torvalds if (status) 7171da177e4SLinus Torvalds return status; 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 7201da177e4SLinus Torvalds return nfserr_inval; 7211da177e4SLinus Torvalds 722916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 723916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 724916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 7251da177e4SLinus Torvalds 726ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 7271da177e4SLinus Torvalds return nfs_ok; 7281da177e4SLinus Torvalds } 7291da177e4SLinus Torvalds 7307191155bSJ.Bruce Fields static __be32 731ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 732eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7331da177e4SLinus Torvalds { 734eb69853dSChristoph Hellwig struct nfsd4_link *link = &u->link; 73595424460SJ. Bruce Fields __be32 status; 7361da177e4SLinus Torvalds 737ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 738ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7391da177e4SLinus Torvalds if (!status) 740ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7411da177e4SLinus Torvalds return status; 7421da177e4SLinus Torvalds } 7431da177e4SLinus Torvalds 7440ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7451da177e4SLinus Torvalds { 7461da177e4SLinus Torvalds struct svc_fh tmp_fh; 747b37ad28bSAl Viro __be32 ret; 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 750df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 751df547efbSJ. Bruce Fields if (ret) 7521da177e4SLinus Torvalds return ret; 7530ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7541da177e4SLinus Torvalds fh_put(&tmp_fh); 7551da177e4SLinus Torvalds return nfserr_noent; 7561da177e4SLinus Torvalds } 7571da177e4SLinus Torvalds fh_put(&tmp_fh); 7580ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7590ff7ab46SJ. Bruce Fields } 7600ff7ab46SJ. Bruce Fields 7610ff7ab46SJ. Bruce Fields static __be32 7620ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 763eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7640ff7ab46SJ. Bruce Fields { 7650ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7661da177e4SLinus Torvalds } 7671da177e4SLinus Torvalds 7687191155bSJ.Bruce Fields static __be32 769ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 770eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7711da177e4SLinus Torvalds { 772ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 773eb69853dSChristoph Hellwig u->lookup.lo_name, u->lookup.lo_len, 774ca364317SJ.Bruce Fields &cstate->current_fh); 7751da177e4SLinus Torvalds } 7761da177e4SLinus Torvalds 7777191155bSJ.Bruce Fields static __be32 778ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 779eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7801da177e4SLinus Torvalds { 781eb69853dSChristoph Hellwig struct nfsd4_read *read = &u->read; 782b37ad28bSAl Viro __be32 status; 7831da177e4SLinus Torvalds 7845c4583b2SJeff Layton read->rd_nf = NULL; 7851da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7861da177e4SLinus Torvalds return nfserr_inval; 7871da177e4SLinus Torvalds 78887c5942eSChuck Lever trace_nfsd_read_start(rqstp, &cstate->current_fh, 78987c5942eSChuck Lever read->rd_offset, read->rd_length); 79087c5942eSChuck Lever 7919b3234b9SJ. Bruce Fields /* 7929b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7939b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7949b3234b9SJ. Bruce Fields * following compound. 7959b3234b9SJ. Bruce Fields * 7969b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7979b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7989b3234b9SJ. Bruce Fields */ 7999b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 800779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 8019b3234b9SJ. Bruce Fields 8021da177e4SLinus Torvalds /* check stateid */ 803aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 804aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 805624322f1SOlga Kornievskaia &read->rd_nf, NULL); 806af90f707SChristoph Hellwig if (status) { 8071da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 8081da177e4SLinus Torvalds goto out; 8091da177e4SLinus Torvalds } 8101da177e4SLinus Torvalds status = nfs_ok; 8111da177e4SLinus Torvalds out: 8121da177e4SLinus Torvalds read->rd_rqstp = rqstp; 813ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 8141da177e4SLinus Torvalds return status; 8151da177e4SLinus Torvalds } 8161da177e4SLinus Torvalds 81734b1744cSJ. Bruce Fields 81834b1744cSJ. Bruce Fields static void 81934b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u) 82034b1744cSJ. Bruce Fields { 8215c4583b2SJeff Layton if (u->read.rd_nf) 8225c4583b2SJeff Layton nfsd_file_put(u->read.rd_nf); 82387c5942eSChuck Lever trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, 82487c5942eSChuck Lever u->read.rd_offset, u->read.rd_length); 82534b1744cSJ. Bruce Fields } 82634b1744cSJ. Bruce Fields 8277191155bSJ.Bruce Fields static __be32 828ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 829eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8301da177e4SLinus Torvalds { 831eb69853dSChristoph Hellwig struct nfsd4_readdir *readdir = &u->readdir; 8321da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 8331da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 8341da177e4SLinus Torvalds 8351da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 8361da177e4SLinus Torvalds 8371da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8381da177e4SLinus Torvalds return nfserr_inval; 8391da177e4SLinus Torvalds 840916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 841916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 842916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 8431da177e4SLinus Torvalds 844832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 8451da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 8461da177e4SLinus Torvalds return nfserr_bad_cookie; 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 849ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 8501da177e4SLinus Torvalds return nfs_ok; 8511da177e4SLinus Torvalds } 8521da177e4SLinus Torvalds 8537191155bSJ.Bruce Fields static __be32 854ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 855eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8561da177e4SLinus Torvalds { 857eb69853dSChristoph Hellwig u->readlink.rl_rqstp = rqstp; 858eb69853dSChristoph Hellwig u->readlink.rl_fhp = &cstate->current_fh; 8591da177e4SLinus Torvalds return nfs_ok; 8601da177e4SLinus Torvalds } 8611da177e4SLinus Torvalds 8627191155bSJ.Bruce Fields static __be32 863ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 864eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8651da177e4SLinus Torvalds { 866eb69853dSChristoph Hellwig struct nfsd4_remove *remove = &u->remove; 867b37ad28bSAl Viro __be32 status; 8681da177e4SLinus Torvalds 869c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 870c815afc7SNeilBrown return nfserr_grace; 871ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 872ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8731da177e4SLinus Torvalds if (!status) { 874ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 875ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8761da177e4SLinus Torvalds } 8771da177e4SLinus Torvalds return status; 8781da177e4SLinus Torvalds } 8791da177e4SLinus Torvalds 8807191155bSJ.Bruce Fields static __be32 881ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 882eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8831da177e4SLinus Torvalds { 884eb69853dSChristoph Hellwig struct nfsd4_rename *rename = &u->rename; 88595424460SJ. Bruce Fields __be32 status; 8861da177e4SLinus Torvalds 887f8f71d00SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 888c815afc7SNeilBrown return nfserr_grace; 889ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 890ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8911da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8922a6cf944SJ. Bruce Fields if (status) 8932a6cf944SJ. Bruce Fields return status; 894ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 895ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8962a6cf944SJ. Bruce Fields return nfs_ok; 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 8997191155bSJ.Bruce Fields static __be32 900dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 901eb69853dSChristoph Hellwig union nfsd4_op_u *u) 902dcb488a3SAndy Adamson { 903eb69853dSChristoph Hellwig struct nfsd4_secinfo *secinfo = &u->secinfo; 904dcb488a3SAndy Adamson struct svc_export *exp; 905dcb488a3SAndy Adamson struct dentry *dentry; 906dcb488a3SAndy Adamson __be32 err; 907dcb488a3SAndy Adamson 90829a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 90929a78a3eSJ. Bruce Fields if (err) 91029a78a3eSJ. Bruce Fields return err; 911dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 912dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 913dcb488a3SAndy Adamson &exp, &dentry); 914dcb488a3SAndy Adamson if (err) 915dcb488a3SAndy Adamson return err; 9162f6fc056SJ. Bruce Fields fh_unlock(&cstate->current_fh); 9172b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 918dcb488a3SAndy Adamson exp_put(exp); 919dcb488a3SAndy Adamson err = nfserr_noent; 920dcb488a3SAndy Adamson } else 921dcb488a3SAndy Adamson secinfo->si_exp = exp; 922dcb488a3SAndy Adamson dput(dentry); 92356560b9aSJ. Bruce Fields if (cstate->minorversion) 92456560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 92556560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 926dcb488a3SAndy Adamson return err; 927dcb488a3SAndy Adamson } 928dcb488a3SAndy Adamson 929dcb488a3SAndy Adamson static __be32 93004f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 931eb69853dSChristoph Hellwig union nfsd4_op_u *u) 93204f4ad16SJ. Bruce Fields { 93304f4ad16SJ. Bruce Fields __be32 err; 93404f4ad16SJ. Bruce Fields 935eb69853dSChristoph Hellwig switch (u->secinfo_no_name.sin_style) { 93604f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 93704f4ad16SJ. Bruce Fields break; 93804f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 93904f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 94004f4ad16SJ. Bruce Fields if (err) 94104f4ad16SJ. Bruce Fields return err; 94204f4ad16SJ. Bruce Fields break; 94304f4ad16SJ. Bruce Fields default: 94404f4ad16SJ. Bruce Fields return nfserr_inval; 94504f4ad16SJ. Bruce Fields } 946bf18f163SKinglong Mee 947eb69853dSChristoph Hellwig u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export); 94804f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 94904f4ad16SJ. Bruce Fields return nfs_ok; 95004f4ad16SJ. Bruce Fields } 95104f4ad16SJ. Bruce Fields 95234b1744cSJ. Bruce Fields static void 95334b1744cSJ. Bruce Fields nfsd4_secinfo_release(union nfsd4_op_u *u) 95434b1744cSJ. Bruce Fields { 95534b1744cSJ. Bruce Fields if (u->secinfo.si_exp) 95634b1744cSJ. Bruce Fields exp_put(u->secinfo.si_exp); 95734b1744cSJ. Bruce Fields } 95834b1744cSJ. Bruce Fields 959ec572b9eSEryu Guan static void 960ec572b9eSEryu Guan nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) 961ec572b9eSEryu Guan { 962ec572b9eSEryu Guan if (u->secinfo_no_name.sin_exp) 963ec572b9eSEryu Guan exp_put(u->secinfo_no_name.sin_exp); 964ec572b9eSEryu Guan } 965ec572b9eSEryu Guan 96604f4ad16SJ. Bruce Fields static __be32 967ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 968eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9691da177e4SLinus Torvalds { 970eb69853dSChristoph Hellwig struct nfsd4_setattr *setattr = &u->setattr; 971b37ad28bSAl Viro __be32 status = nfs_ok; 97296f6f985SAl Viro int err; 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 975af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 976aa0d6aedSAnna Schumaker &cstate->current_fh, &setattr->sa_stateid, 977624322f1SOlga Kornievskaia WR_STATE, NULL, NULL); 978375c5547SJ. Bruce Fields if (status) { 9793e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 980375c5547SJ. Bruce Fields return status; 981375c5547SJ. Bruce Fields } 9821da177e4SLinus Torvalds } 98396f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 98496f6f985SAl Viro if (err) 98596f6f985SAl Viro return nfserrno(err); 9861da177e4SLinus Torvalds status = nfs_ok; 9873c8e0316SYu Zhiguo 9883c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9893c8e0316SYu Zhiguo nfsd_attrmask); 9903c8e0316SYu Zhiguo if (status) 9913c8e0316SYu Zhiguo goto out; 9923c8e0316SYu Zhiguo 9931da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 994ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 995ca364317SJ.Bruce Fields setattr->sa_acl); 9961da177e4SLinus Torvalds if (status) 99718f335afSDave Hansen goto out; 99818032ca0SDavid Quigley if (setattr->sa_label.len) 99918032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 100018032ca0SDavid Quigley &setattr->sa_label); 100118032ca0SDavid Quigley if (status) 100218032ca0SDavid Quigley goto out; 1003ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 10042a1aa489SArnd Bergmann 0, (time64_t)0); 100518f335afSDave Hansen out: 1006bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 10071da177e4SLinus Torvalds return status; 10081da177e4SLinus Torvalds } 10091da177e4SLinus Torvalds 10107191155bSJ.Bruce Fields static __be32 1011ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1012eb69853dSChristoph Hellwig union nfsd4_op_u *u) 10131da177e4SLinus Torvalds { 1014eb69853dSChristoph Hellwig struct nfsd4_write *write = &u->write; 10151da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 10165c4583b2SJeff Layton struct nfsd_file *nf = NULL; 1017b37ad28bSAl Viro __be32 status = nfs_ok; 101831dec253SDavid Shaw unsigned long cnt; 1019ffe1137bSJ. Bruce Fields int nvecs; 10201da177e4SLinus Torvalds 10211da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 10221da177e4SLinus Torvalds return nfserr_inval; 10231da177e4SLinus Torvalds 1024d890be15SChuck Lever cnt = write->wr_buflen; 1025d890be15SChuck Lever trace_nfsd_write_start(rqstp, &cstate->current_fh, 1026d890be15SChuck Lever write->wr_offset, cnt); 1027aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1028624322f1SOlga Kornievskaia stateid, WR_STATE, &nf, NULL); 1029375c5547SJ. Bruce Fields if (status) { 1030375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 1031375c5547SJ. Bruce Fields return status; 1032375c5547SJ. Bruce Fields } 1033375c5547SJ. Bruce Fields 10341da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 10351da177e4SLinus Torvalds 1036dae9a6caSChuck Lever nvecs = svc_fill_write_vector(rqstp, &write->wr_payload); 1037ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1038ffe1137bSJ. Bruce Fields 103916f8f894STrond Myklebust status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, 1040af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 104119e0663fSTrond Myklebust write->wr_how_written, 104219e0663fSTrond Myklebust (__be32 *)write->wr_verifier.data); 10435c4583b2SJeff Layton nfsd_file_put(nf); 10441da177e4SLinus Torvalds 104531dec253SDavid Shaw write->wr_bytes_written = cnt; 1046d890be15SChuck Lever trace_nfsd_write_done(rqstp, &cstate->current_fh, 1047d890be15SChuck Lever write->wr_offset, cnt); 10481da177e4SLinus Torvalds return status; 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds 105124bab491SAnna Schumaker static __be32 105229ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 10535c4583b2SJeff Layton stateid_t *src_stateid, struct nfsd_file **src, 10545c4583b2SJeff Layton stateid_t *dst_stateid, struct nfsd_file **dst) 1055ffa0160aSChristoph Hellwig { 1056ffa0160aSChristoph Hellwig __be32 status; 1057ffa0160aSChristoph Hellwig 105801310bb7SScott Mayhew if (!cstate->save_fh.fh_dentry) 105901310bb7SScott Mayhew return nfserr_nofilehandle; 106001310bb7SScott Mayhew 1061ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 1062624322f1SOlga Kornievskaia src_stateid, RD_STATE, src, NULL); 1063ffa0160aSChristoph Hellwig if (status) { 1064ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1065ffa0160aSChristoph Hellwig goto out; 1066ffa0160aSChristoph Hellwig } 1067ffa0160aSChristoph Hellwig 1068ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1069624322f1SOlga Kornievskaia dst_stateid, WR_STATE, dst, NULL); 1070ffa0160aSChristoph Hellwig if (status) { 1071ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1072ffa0160aSChristoph Hellwig goto out_put_src; 1073ffa0160aSChristoph Hellwig } 1074ffa0160aSChristoph Hellwig 1075ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 10765c4583b2SJeff Layton if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) || 10775c4583b2SJeff Layton !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) { 1078ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1079ffa0160aSChristoph Hellwig goto out_put_dst; 1080ffa0160aSChristoph Hellwig } 1081ffa0160aSChristoph Hellwig 108229ae7f9dSAnna Schumaker out: 108329ae7f9dSAnna Schumaker return status; 108429ae7f9dSAnna Schumaker out_put_dst: 10855c4583b2SJeff Layton nfsd_file_put(*dst); 108629ae7f9dSAnna Schumaker out_put_src: 10875c4583b2SJeff Layton nfsd_file_put(*src); 108829ae7f9dSAnna Schumaker goto out; 108929ae7f9dSAnna Schumaker } 109029ae7f9dSAnna Schumaker 109129ae7f9dSAnna Schumaker static __be32 109229ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1093eb69853dSChristoph Hellwig union nfsd4_op_u *u) 109429ae7f9dSAnna Schumaker { 1095eb69853dSChristoph Hellwig struct nfsd4_clone *clone = &u->clone; 10965c4583b2SJeff Layton struct nfsd_file *src, *dst; 109729ae7f9dSAnna Schumaker __be32 status; 109829ae7f9dSAnna Schumaker 109929ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 110029ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 110129ae7f9dSAnna Schumaker if (status) 110229ae7f9dSAnna Schumaker goto out; 110329ae7f9dSAnna Schumaker 1104b66ae6ddSTrond Myklebust status = nfsd4_clone_file_range(src, clone->cl_src_pos, 1105b66ae6ddSTrond Myklebust dst, clone->cl_dst_pos, clone->cl_count, 1106a25e3726STrond Myklebust EX_ISSYNC(cstate->current_fh.fh_export)); 1107ffa0160aSChristoph Hellwig 11085c4583b2SJeff Layton nfsd_file_put(dst); 11095c4583b2SJeff Layton nfsd_file_put(src); 1110ffa0160aSChristoph Hellwig out: 1111ffa0160aSChristoph Hellwig return status; 1112ffa0160aSChristoph Hellwig } 1113ffa0160aSChristoph Hellwig 1114e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy) 1115e0639dc5SOlga Kornievskaia { 1116e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1117e0639dc5SOlga Kornievskaia return; 1118e0639dc5SOlga Kornievskaia kfree(copy); 1119e0639dc5SOlga Kornievskaia } 1120e0639dc5SOlga Kornievskaia 1121e0639dc5SOlga Kornievskaia static bool 1122e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy) 1123e0639dc5SOlga Kornievskaia { 1124e0639dc5SOlga Kornievskaia bool value; 1125e0639dc5SOlga Kornievskaia 1126e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1127e0639dc5SOlga Kornievskaia value = copy->stopped; 1128e0639dc5SOlga Kornievskaia if (!copy->stopped) 1129e0639dc5SOlga Kornievskaia copy->stopped = true; 1130e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1131e0639dc5SOlga Kornievskaia return value; 1132e0639dc5SOlga Kornievskaia } 1133e0639dc5SOlga Kornievskaia 1134e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1135e0639dc5SOlga Kornievskaia { 1136e0639dc5SOlga Kornievskaia /* only 1 thread should stop the copy */ 1137e0639dc5SOlga Kornievskaia if (!check_and_set_stop_copy(copy)) 1138e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1139e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1140e0639dc5SOlga Kornievskaia } 1141e0639dc5SOlga Kornievskaia 1142e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1143e0639dc5SOlga Kornievskaia { 1144e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1145e0639dc5SOlga Kornievskaia 1146e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1147e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1148e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1149e0639dc5SOlga Kornievskaia copies); 1150e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1151e0639dc5SOlga Kornievskaia } 1152e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1153e0639dc5SOlga Kornievskaia return copy; 1154e0639dc5SOlga Kornievskaia } 1155e0639dc5SOlga Kornievskaia 1156e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1157e0639dc5SOlga Kornievskaia { 1158e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1159e0639dc5SOlga Kornievskaia 1160e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1161e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1162e0639dc5SOlga Kornievskaia } 1163ce0887acSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 1164ce0887acSOlga Kornievskaia 1165ce0887acSOlga Kornievskaia extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1166ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1167ce0887acSOlga Kornievskaia nfs4_stateid *stateid); 1168ce0887acSOlga Kornievskaia extern void nfs42_ssc_close(struct file *filep); 1169ce0887acSOlga Kornievskaia 1170ce0887acSOlga Kornievskaia extern void nfs_sb_deactive(struct super_block *sb); 1171ce0887acSOlga Kornievskaia 1172ce0887acSOlga Kornievskaia #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys" 1173ce0887acSOlga Kornievskaia 1174f2453978SChuck Lever /* 1175f4e44b39SDai Ngo * setup a work entry in the ssc delayed unmount list. 1176f4e44b39SDai Ngo */ 1177f47dc2d3SDai Ngo static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr, 1178f4e44b39SDai Ngo struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt) 1179f4e44b39SDai Ngo { 11808e70bf27SColin Ian King struct nfsd4_ssc_umount_item *ni = NULL; 1181f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work = NULL; 1182f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *tmp; 1183f4e44b39SDai Ngo DEFINE_WAIT(wait); 1184f4e44b39SDai Ngo 1185f4e44b39SDai Ngo *ss_mnt = NULL; 1186f4e44b39SDai Ngo *retwork = NULL; 1187f4e44b39SDai Ngo work = kzalloc(sizeof(*work), GFP_KERNEL); 1188f4e44b39SDai Ngo try_again: 1189f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1190f4e44b39SDai Ngo list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { 1191f4e44b39SDai Ngo if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr))) 1192f4e44b39SDai Ngo continue; 1193f4e44b39SDai Ngo /* found a match */ 1194f4e44b39SDai Ngo if (ni->nsui_busy) { 1195f4e44b39SDai Ngo /* wait - and try again */ 1196f4e44b39SDai Ngo prepare_to_wait(&nn->nfsd_ssc_waitq, &wait, 1197f4e44b39SDai Ngo TASK_INTERRUPTIBLE); 1198f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1199f4e44b39SDai Ngo 1200f4e44b39SDai Ngo /* allow 20secs for mount/unmount for now - revisit */ 1201f4e44b39SDai Ngo if (signal_pending(current) || 1202f4e44b39SDai Ngo (schedule_timeout(20*HZ) == 0)) { 1203f4e44b39SDai Ngo kfree(work); 1204f4e44b39SDai Ngo return nfserr_eagain; 1205f4e44b39SDai Ngo } 1206f4e44b39SDai Ngo finish_wait(&nn->nfsd_ssc_waitq, &wait); 1207f4e44b39SDai Ngo goto try_again; 1208f4e44b39SDai Ngo } 1209f4e44b39SDai Ngo *ss_mnt = ni->nsui_vfsmount; 1210f4e44b39SDai Ngo refcount_inc(&ni->nsui_refcnt); 1211f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1212f4e44b39SDai Ngo kfree(work); 1213f4e44b39SDai Ngo 1214f4e44b39SDai Ngo /* return vfsmount in ss_mnt */ 1215f4e44b39SDai Ngo return 0; 1216f4e44b39SDai Ngo } 1217f4e44b39SDai Ngo if (work) { 1218f4e44b39SDai Ngo strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr)); 1219f4e44b39SDai Ngo refcount_set(&work->nsui_refcnt, 2); 1220f4e44b39SDai Ngo work->nsui_busy = true; 1221f4e44b39SDai Ngo list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list); 1222f4e44b39SDai Ngo *retwork = work; 1223f4e44b39SDai Ngo } 1224f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1225f4e44b39SDai Ngo return 0; 1226f4e44b39SDai Ngo } 1227f4e44b39SDai Ngo 1228f4e44b39SDai Ngo static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn, 1229f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt) 1230f4e44b39SDai Ngo { 1231f4e44b39SDai Ngo /* set nsui_vfsmount, clear busy flag and wakeup waiters */ 1232f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1233f4e44b39SDai Ngo work->nsui_vfsmount = ss_mnt; 1234f4e44b39SDai Ngo work->nsui_busy = false; 1235f4e44b39SDai Ngo wake_up_all(&nn->nfsd_ssc_waitq); 1236f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1237f4e44b39SDai Ngo } 1238f4e44b39SDai Ngo 1239f4e44b39SDai Ngo static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn, 1240f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work) 1241f4e44b39SDai Ngo { 1242f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1243f4e44b39SDai Ngo list_del(&work->nsui_list); 1244f4e44b39SDai Ngo wake_up_all(&nn->nfsd_ssc_waitq); 1245f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1246f4e44b39SDai Ngo kfree(work); 1247f4e44b39SDai Ngo } 1248f4e44b39SDai Ngo 1249f4e44b39SDai Ngo /* 1250ce0887acSOlga Kornievskaia * Support one copy source server for now. 1251ce0887acSOlga Kornievskaia */ 1252ce0887acSOlga Kornievskaia static __be32 1253ce0887acSOlga Kornievskaia nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp, 1254ce0887acSOlga Kornievskaia struct vfsmount **mount) 1255ce0887acSOlga Kornievskaia { 1256ce0887acSOlga Kornievskaia struct file_system_type *type; 1257ce0887acSOlga Kornievskaia struct vfsmount *ss_mnt; 1258ce0887acSOlga Kornievskaia struct nfs42_netaddr *naddr; 1259ce0887acSOlga Kornievskaia struct sockaddr_storage tmp_addr; 1260ce0887acSOlga Kornievskaia size_t tmp_addrlen, match_netid_len = 3; 1261ce0887acSOlga Kornievskaia char *startsep = "", *endsep = "", *match_netid = "tcp"; 1262ce0887acSOlga Kornievskaia char *ipaddr, *dev_name, *raw_data; 1263b8290ca2SOlga Kornievskaia int len, raw_len; 1264b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1265f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work = NULL; 1266f4e44b39SDai Ngo struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1267ce0887acSOlga Kornievskaia 1268ce0887acSOlga Kornievskaia naddr = &nss->u.nl4_addr; 1269ce0887acSOlga Kornievskaia tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr, 1270ce0887acSOlga Kornievskaia naddr->addr_len, 1271ce0887acSOlga Kornievskaia (struct sockaddr *)&tmp_addr, 1272ce0887acSOlga Kornievskaia sizeof(tmp_addr)); 1273ce0887acSOlga Kornievskaia if (tmp_addrlen == 0) 1274ce0887acSOlga Kornievskaia goto out_err; 1275ce0887acSOlga Kornievskaia 1276ce0887acSOlga Kornievskaia if (tmp_addr.ss_family == AF_INET6) { 1277ce0887acSOlga Kornievskaia startsep = "["; 1278ce0887acSOlga Kornievskaia endsep = "]"; 1279ce0887acSOlga Kornievskaia match_netid = "tcp6"; 1280ce0887acSOlga Kornievskaia match_netid_len = 4; 1281ce0887acSOlga Kornievskaia } 1282ce0887acSOlga Kornievskaia 1283ce0887acSOlga Kornievskaia if (naddr->netid_len != match_netid_len || 1284ce0887acSOlga Kornievskaia strncmp(naddr->netid, match_netid, naddr->netid_len)) 1285ce0887acSOlga Kornievskaia goto out_err; 1286ce0887acSOlga Kornievskaia 1287ce0887acSOlga Kornievskaia /* Construct the raw data for the vfs_kern_mount call */ 1288ce0887acSOlga Kornievskaia len = RPC_MAX_ADDRBUFLEN + 1; 1289ce0887acSOlga Kornievskaia ipaddr = kzalloc(len, GFP_KERNEL); 1290ce0887acSOlga Kornievskaia if (!ipaddr) 1291ce0887acSOlga Kornievskaia goto out_err; 1292ce0887acSOlga Kornievskaia 1293ce0887acSOlga Kornievskaia rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len); 1294ce0887acSOlga Kornievskaia 1295ce0887acSOlga Kornievskaia /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/ 1296ce0887acSOlga Kornievskaia 1297ce0887acSOlga Kornievskaia raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr); 1298ce0887acSOlga Kornievskaia raw_data = kzalloc(raw_len, GFP_KERNEL); 1299ce0887acSOlga Kornievskaia if (!raw_data) 1300ce0887acSOlga Kornievskaia goto out_free_ipaddr; 1301ce0887acSOlga Kornievskaia 1302ce0887acSOlga Kornievskaia snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr); 1303ce0887acSOlga Kornievskaia 1304b8290ca2SOlga Kornievskaia status = nfserr_nodev; 1305ce0887acSOlga Kornievskaia type = get_fs_type("nfs"); 1306ce0887acSOlga Kornievskaia if (!type) 1307ce0887acSOlga Kornievskaia goto out_free_rawdata; 1308ce0887acSOlga Kornievskaia 1309ce0887acSOlga Kornievskaia /* Set the server:<export> for the vfs_kern_mount call */ 1310ce0887acSOlga Kornievskaia dev_name = kzalloc(len + 5, GFP_KERNEL); 1311ce0887acSOlga Kornievskaia if (!dev_name) 1312ce0887acSOlga Kornievskaia goto out_free_rawdata; 1313ce0887acSOlga Kornievskaia snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep); 1314ce0887acSOlga Kornievskaia 1315f4e44b39SDai Ngo status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt); 1316f4e44b39SDai Ngo if (status) 1317f4e44b39SDai Ngo goto out_free_devname; 1318f4e44b39SDai Ngo if (ss_mnt) 1319f4e44b39SDai Ngo goto out_done; 1320f4e44b39SDai Ngo 1321ce0887acSOlga Kornievskaia /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */ 1322ce0887acSOlga Kornievskaia ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data); 1323ce0887acSOlga Kornievskaia module_put(type->owner); 1324f4e44b39SDai Ngo if (IS_ERR(ss_mnt)) { 132554185267SWei Yongjun status = nfserr_nodev; 1326f4e44b39SDai Ngo if (work) 1327f4e44b39SDai Ngo nfsd4_ssc_cancel_dul_work(nn, work); 1328ce0887acSOlga Kornievskaia goto out_free_devname; 1329f4e44b39SDai Ngo } 1330f4e44b39SDai Ngo if (work) 1331f4e44b39SDai Ngo nfsd4_ssc_update_dul_work(nn, work, ss_mnt); 1332f4e44b39SDai Ngo out_done: 1333ce0887acSOlga Kornievskaia status = 0; 1334ce0887acSOlga Kornievskaia *mount = ss_mnt; 1335ce0887acSOlga Kornievskaia 1336ce0887acSOlga Kornievskaia out_free_devname: 1337ce0887acSOlga Kornievskaia kfree(dev_name); 1338ce0887acSOlga Kornievskaia out_free_rawdata: 1339ce0887acSOlga Kornievskaia kfree(raw_data); 1340ce0887acSOlga Kornievskaia out_free_ipaddr: 1341ce0887acSOlga Kornievskaia kfree(ipaddr); 1342ce0887acSOlga Kornievskaia out_err: 1343ce0887acSOlga Kornievskaia return status; 1344ce0887acSOlga Kornievskaia } 1345ce0887acSOlga Kornievskaia 1346ce0887acSOlga Kornievskaia static void 1347ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1348ce0887acSOlga Kornievskaia { 13490cfcd405SDai Ngo nfs_do_sb_deactive(ss_mnt->mnt_sb); 1350ce0887acSOlga Kornievskaia mntput(ss_mnt); 1351ce0887acSOlga Kornievskaia } 1352ce0887acSOlga Kornievskaia 1353f2453978SChuck Lever /* 1354ce0887acSOlga Kornievskaia * Verify COPY destination stateid. 1355f2453978SChuck Lever * 1356ce0887acSOlga Kornievskaia * Connect to the source server with NFSv4.1. 1357ce0887acSOlga Kornievskaia * Create the source struct file for nfsd_copy_range. 1358ce0887acSOlga Kornievskaia * Called with COPY cstate: 1359ce0887acSOlga Kornievskaia * SAVED_FH: source filehandle 1360ce0887acSOlga Kornievskaia * CURRENT_FH: destination filehandle 1361ce0887acSOlga Kornievskaia */ 1362ce0887acSOlga Kornievskaia static __be32 1363ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1364ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1365ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, struct vfsmount **mount) 1366ce0887acSOlga Kornievskaia { 1367ce0887acSOlga Kornievskaia struct svc_fh *s_fh = NULL; 1368ce0887acSOlga Kornievskaia stateid_t *s_stid = ©->cp_src_stateid; 1369b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1370ce0887acSOlga Kornievskaia 1371ce0887acSOlga Kornievskaia /* Verify the destination stateid and set dst struct file*/ 1372ce0887acSOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1373ce0887acSOlga Kornievskaia ©->cp_dst_stateid, 1374ce0887acSOlga Kornievskaia WR_STATE, ©->nf_dst, NULL); 1375ce0887acSOlga Kornievskaia if (status) 1376ce0887acSOlga Kornievskaia goto out; 1377ce0887acSOlga Kornievskaia 1378ce0887acSOlga Kornievskaia status = nfsd4_interssc_connect(©->cp_src, rqstp, mount); 1379ce0887acSOlga Kornievskaia if (status) 1380ce0887acSOlga Kornievskaia goto out; 1381ce0887acSOlga Kornievskaia 1382ce0887acSOlga Kornievskaia s_fh = &cstate->save_fh; 1383ce0887acSOlga Kornievskaia 1384ce0887acSOlga Kornievskaia copy->c_fh.size = s_fh->fh_handle.fh_size; 1385d8b26071SNeilBrown memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size); 13863f9544caSOlga Kornievskaia copy->stateid.seqid = cpu_to_be32(s_stid->si_generation); 1387ce0887acSOlga Kornievskaia memcpy(copy->stateid.other, (void *)&s_stid->si_opaque, 1388ce0887acSOlga Kornievskaia sizeof(stateid_opaque_t)); 1389ce0887acSOlga Kornievskaia 1390ce0887acSOlga Kornievskaia status = 0; 1391ce0887acSOlga Kornievskaia out: 1392ce0887acSOlga Kornievskaia return status; 1393ce0887acSOlga Kornievskaia } 1394ce0887acSOlga Kornievskaia 1395ce0887acSOlga Kornievskaia static void 1396ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, 1397ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1398ce0887acSOlga Kornievskaia { 1399f4e44b39SDai Ngo bool found = false; 1400f4e44b39SDai Ngo long timeout; 1401f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *tmp; 1402f47dc2d3SDai Ngo struct nfsd4_ssc_umount_item *ni = NULL; 1403f4e44b39SDai Ngo struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id); 1404f4e44b39SDai Ngo 1405ce0887acSOlga Kornievskaia nfs42_ssc_close(src->nf_file); 1406ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1407f4e44b39SDai Ngo fput(src->nf_file); 1408f4e44b39SDai Ngo 1409f4e44b39SDai Ngo if (!nn) { 1410ce0887acSOlga Kornievskaia mntput(ss_mnt); 1411f4e44b39SDai Ngo return; 1412f4e44b39SDai Ngo } 1413f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1414f4e44b39SDai Ngo timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout); 1415f4e44b39SDai Ngo list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { 1416f4e44b39SDai Ngo if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) { 1417f4e44b39SDai Ngo list_del(&ni->nsui_list); 1418f4e44b39SDai Ngo /* 1419f4e44b39SDai Ngo * vfsmount can be shared by multiple exports, 1420f4e44b39SDai Ngo * decrement refcnt. If the count drops to 1 it 1421f4e44b39SDai Ngo * will be unmounted when nsui_expire expires. 1422f4e44b39SDai Ngo */ 1423f4e44b39SDai Ngo refcount_dec(&ni->nsui_refcnt); 1424f4e44b39SDai Ngo ni->nsui_expire = jiffies + timeout; 1425f4e44b39SDai Ngo list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list); 1426f4e44b39SDai Ngo found = true; 1427f4e44b39SDai Ngo break; 1428f4e44b39SDai Ngo } 1429f4e44b39SDai Ngo } 1430f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1431f4e44b39SDai Ngo if (!found) { 1432f4e44b39SDai Ngo mntput(ss_mnt); 1433f4e44b39SDai Ngo return; 1434f4e44b39SDai Ngo } 1435ce0887acSOlga Kornievskaia } 1436ce0887acSOlga Kornievskaia 1437ce0887acSOlga Kornievskaia #else /* CONFIG_NFSD_V4_2_INTER_SSC */ 1438ce0887acSOlga Kornievskaia 1439ce0887acSOlga Kornievskaia static __be32 1440ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1441ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1442ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, 1443ce0887acSOlga Kornievskaia struct vfsmount **mount) 1444ce0887acSOlga Kornievskaia { 1445ce0887acSOlga Kornievskaia *mount = NULL; 1446b8290ca2SOlga Kornievskaia return nfserr_inval; 1447ce0887acSOlga Kornievskaia } 1448ce0887acSOlga Kornievskaia 1449ce0887acSOlga Kornievskaia static void 1450ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, 1451ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1452ce0887acSOlga Kornievskaia { 1453ce0887acSOlga Kornievskaia } 1454ce0887acSOlga Kornievskaia 1455ce0887acSOlga Kornievskaia static void 1456ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1457ce0887acSOlga Kornievskaia { 1458ce0887acSOlga Kornievskaia } 1459ce0887acSOlga Kornievskaia 1460ce0887acSOlga Kornievskaia static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1461ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1462ce0887acSOlga Kornievskaia nfs4_stateid *stateid) 1463ce0887acSOlga Kornievskaia { 1464ce0887acSOlga Kornievskaia return NULL; 1465ce0887acSOlga Kornievskaia } 1466ce0887acSOlga Kornievskaia #endif /* CONFIG_NFSD_V4_2_INTER_SSC */ 1467ce0887acSOlga Kornievskaia 1468ce0887acSOlga Kornievskaia static __be32 1469ce0887acSOlga Kornievskaia nfsd4_setup_intra_ssc(struct svc_rqst *rqstp, 1470ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1471ce0887acSOlga Kornievskaia struct nfsd4_copy *copy) 1472ce0887acSOlga Kornievskaia { 1473ce0887acSOlga Kornievskaia return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 1474ce0887acSOlga Kornievskaia ©->nf_src, ©->cp_dst_stateid, 1475ce0887acSOlga Kornievskaia ©->nf_dst); 1476ce0887acSOlga Kornievskaia } 1477ce0887acSOlga Kornievskaia 1478ce0887acSOlga Kornievskaia static void 1479ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst) 1480ce0887acSOlga Kornievskaia { 1481ce0887acSOlga Kornievskaia nfsd_file_put(src); 1482ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1483ce0887acSOlga Kornievskaia } 1484e0639dc5SOlga Kornievskaia 1485e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1486e0639dc5SOlga Kornievskaia { 1487e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); 1488e0639dc5SOlga Kornievskaia 1489e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1490e0639dc5SOlga Kornievskaia } 1491e0639dc5SOlga Kornievskaia 1492e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1493e0639dc5SOlga Kornievskaia struct rpc_task *task) 1494e0639dc5SOlga Kornievskaia { 1495e0639dc5SOlga Kornievskaia return 1; 1496e0639dc5SOlga Kornievskaia } 1497e0639dc5SOlga Kornievskaia 1498e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1499e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1500e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1501e0639dc5SOlga Kornievskaia }; 1502e0639dc5SOlga Kornievskaia 1503e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1504e0639dc5SOlga Kornievskaia { 1505eac0b17aSOlga Kornievskaia copy->cp_res.wr_stable_how = 1506eac0b17aSOlga Kornievskaia copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE; 1507e0639dc5SOlga Kornievskaia copy->cp_synchronous = sync; 1508e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1509e0639dc5SOlga Kornievskaia } 1510e0639dc5SOlga Kornievskaia 1511e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) 1512e0639dc5SOlga Kornievskaia { 1513e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1514e7a833e9SJ. Bruce Fields u64 bytes_total = copy->cp_count; 1515e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1516e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1517eac0b17aSOlga Kornievskaia __be32 status; 1518e0639dc5SOlga Kornievskaia 1519792a5112SJ. Bruce Fields /* See RFC 7862 p.67: */ 1520792a5112SJ. Bruce Fields if (bytes_total == 0) 1521792a5112SJ. Bruce Fields bytes_total = ULLONG_MAX; 1522e0639dc5SOlga Kornievskaia do { 1523e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1524e0639dc5SOlga Kornievskaia break; 15255c4583b2SJeff Layton bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file, 15265c4583b2SJeff Layton src_pos, copy->nf_dst->nf_file, dst_pos, 15275c4583b2SJeff Layton bytes_total); 1528e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1529e0639dc5SOlga Kornievskaia break; 1530e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1531e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1532e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1533e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1534e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1535eac0b17aSOlga Kornievskaia /* for a non-zero asynchronous copy do a commit of data */ 1536eac0b17aSOlga Kornievskaia if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) { 1537eac0b17aSOlga Kornievskaia down_write(©->nf_dst->nf_rwsem); 1538eac0b17aSOlga Kornievskaia status = vfs_fsync_range(copy->nf_dst->nf_file, 1539eac0b17aSOlga Kornievskaia copy->cp_dst_pos, 1540eac0b17aSOlga Kornievskaia copy->cp_res.wr_bytes_written, 0); 1541eac0b17aSOlga Kornievskaia up_write(©->nf_dst->nf_rwsem); 1542eac0b17aSOlga Kornievskaia if (!status) 1543eac0b17aSOlga Kornievskaia copy->committed = true; 1544eac0b17aSOlga Kornievskaia } 1545e0639dc5SOlga Kornievskaia return bytes_copied; 1546e0639dc5SOlga Kornievskaia } 1547e0639dc5SOlga Kornievskaia 1548e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1549e0639dc5SOlga Kornievskaia { 1550e0639dc5SOlga Kornievskaia __be32 status; 1551e0639dc5SOlga Kornievskaia ssize_t bytes; 1552e0639dc5SOlga Kornievskaia 1553e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1554e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1555e0639dc5SOlga Kornievskaia * to get the error 1556e0639dc5SOlga Kornievskaia */ 1557e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1558e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1559e0639dc5SOlga Kornievskaia else { 1560e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1561e0639dc5SOlga Kornievskaia status = nfs_ok; 1562e0639dc5SOlga Kornievskaia } 1563e0639dc5SOlga Kornievskaia 1564ce0887acSOlga Kornievskaia if (!copy->cp_intra) /* Inter server SSC */ 1565ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src, 1566ce0887acSOlga Kornievskaia copy->nf_dst); 1567ce0887acSOlga Kornievskaia else 1568ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); 1569ce0887acSOlga Kornievskaia 1570e0639dc5SOlga Kornievskaia return status; 1571e0639dc5SOlga Kornievskaia } 1572e0639dc5SOlga Kornievskaia 1573eb162e17SChuck Lever static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1574e0639dc5SOlga Kornievskaia { 1575e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1576e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1577e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1578e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1579e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1580e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1581e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 15825c4583b2SJeff Layton dst->nf_dst = nfsd_file_get(src->nf_dst); 1583ce0887acSOlga Kornievskaia dst->cp_intra = src->cp_intra; 1584ce0887acSOlga Kornievskaia if (src->cp_intra) /* for inter, file_src doesn't exist yet */ 15855c4583b2SJeff Layton dst->nf_src = nfsd_file_get(src->nf_src); 1586ce0887acSOlga Kornievskaia 1587e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1588ce0887acSOlga Kornievskaia memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server)); 1589ce0887acSOlga Kornievskaia memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); 1590ce0887acSOlga Kornievskaia memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); 1591ce0887acSOlga Kornievskaia dst->ss_mnt = src->ss_mnt; 1592e0639dc5SOlga Kornievskaia } 1593e0639dc5SOlga Kornievskaia 1594e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1595e0639dc5SOlga Kornievskaia { 1596624322f1SOlga Kornievskaia nfs4_free_copy_state(copy); 15975c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 15982e577f0fSOlga Kornievskaia if (copy->cp_intra) 15995c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 1600e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1601e0639dc5SOlga Kornievskaia list_del(©->copies); 1602e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1603e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1604e0639dc5SOlga Kornievskaia } 1605e0639dc5SOlga Kornievskaia 1606e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1607e0639dc5SOlga Kornievskaia { 1608e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1609e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1610e0639dc5SOlga Kornievskaia 1611ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1612ce0887acSOlga Kornievskaia copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); 1613ce0887acSOlga Kornievskaia if (!copy->nf_src) { 1614ce0887acSOlga Kornievskaia copy->nfserr = nfserr_serverfault; 1615ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1616ce0887acSOlga Kornievskaia goto do_callback; 1617ce0887acSOlga Kornievskaia } 1618ce0887acSOlga Kornievskaia copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, 1619ce0887acSOlga Kornievskaia ©->stateid); 1620ce0887acSOlga Kornievskaia if (IS_ERR(copy->nf_src->nf_file)) { 1621ce0887acSOlga Kornievskaia copy->nfserr = nfserr_offload_denied; 1622ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1623ce0887acSOlga Kornievskaia goto do_callback; 1624ce0887acSOlga Kornievskaia } 1625ce0887acSOlga Kornievskaia } 1626ce0887acSOlga Kornievskaia 1627e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1628ce0887acSOlga Kornievskaia do_callback: 1629e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1630e0639dc5SOlga Kornievskaia if (!cb_copy) 1631e0639dc5SOlga Kornievskaia goto out; 163249a36132SDai Ngo refcount_set(&cb_copy->refcount, 1); 1633e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1634e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1635e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1636e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1637e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1638e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 163987512386SChuck Lever trace_nfsd_cb_offload(copy->cp_clp, ©->cp_res.cb_stateid, 164087512386SChuck Lever ©->fh, copy->cp_count, copy->nfserr); 1641e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1642e0639dc5SOlga Kornievskaia out: 1643ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1644ce0887acSOlga Kornievskaia kfree(copy->nf_src); 1645e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1646e0639dc5SOlga Kornievskaia return 0; 1647e0639dc5SOlga Kornievskaia } 1648e0639dc5SOlga Kornievskaia 1649ffa0160aSChristoph Hellwig static __be32 165029ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1651eb69853dSChristoph Hellwig union nfsd4_op_u *u) 165229ae7f9dSAnna Schumaker { 1653eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 165429ae7f9dSAnna Schumaker __be32 status; 1655e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 165629ae7f9dSAnna Schumaker 1657ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1658ce0887acSOlga Kornievskaia if (!inter_copy_offload_enable || copy->cp_synchronous) { 1659ce0887acSOlga Kornievskaia status = nfserr_notsupp; 166029ae7f9dSAnna Schumaker goto out; 1661ce0887acSOlga Kornievskaia } 1662ce0887acSOlga Kornievskaia status = nfsd4_setup_inter_ssc(rqstp, cstate, copy, 1663ce0887acSOlga Kornievskaia ©->ss_mnt); 1664ce0887acSOlga Kornievskaia if (status) 1665ce0887acSOlga Kornievskaia return nfserr_offload_denied; 1666ce0887acSOlga Kornievskaia } else { 1667ce0887acSOlga Kornievskaia status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); 1668ce0887acSOlga Kornievskaia if (status) 1669ce0887acSOlga Kornievskaia return status; 1670ce0887acSOlga Kornievskaia } 167129ae7f9dSAnna Schumaker 1672e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1673e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1674e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1675e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1676e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 167729ae7f9dSAnna Schumaker 1678e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1679e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1680e0639dc5SOlga Kornievskaia if (!async_copy) 1681ce0887acSOlga Kornievskaia goto out_err; 1682ce0887acSOlga Kornievskaia if (!nfs4_init_copy_state(nn, copy)) 1683ce0887acSOlga Kornievskaia goto out_err; 1684e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1685e739b120SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid, 1686e739b120SOlga Kornievskaia sizeof(copy->cp_res.cb_stateid)); 1687eb162e17SChuck Lever dup_copy_fields(copy, async_copy); 1688e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1689e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1690e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1691e0639dc5SOlga Kornievskaia goto out_err; 1692e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1693e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1694e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1695e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1696e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1697e0639dc5SOlga Kornievskaia status = nfs_ok; 1698ce0887acSOlga Kornievskaia } else { 1699e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 1700ce0887acSOlga Kornievskaia } 170129ae7f9dSAnna Schumaker out: 170229ae7f9dSAnna Schumaker return status; 1703e0639dc5SOlga Kornievskaia out_err: 170418f428d4SOlga Kornievskaia if (async_copy) 1705e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1706ce0887acSOlga Kornievskaia status = nfserrno(-ENOMEM); 1707ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1708ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1709e0639dc5SOlga Kornievskaia goto out; 1710e0639dc5SOlga Kornievskaia } 1711e0639dc5SOlga Kornievskaia 1712e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1713e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1714e0639dc5SOlga Kornievskaia { 1715e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1716e0639dc5SOlga Kornievskaia 1717e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1718e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1719ce0887acSOlga Kornievskaia if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE)) 1720e0639dc5SOlga Kornievskaia continue; 1721e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1722e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1723e0639dc5SOlga Kornievskaia return copy; 1724e0639dc5SOlga Kornievskaia } 1725e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1726e0639dc5SOlga Kornievskaia return NULL; 172729ae7f9dSAnna Schumaker } 172829ae7f9dSAnna Schumaker 172929ae7f9dSAnna Schumaker static __be32 1730885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1731885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1732885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1733885e2bf3SOlga Kornievskaia { 1734e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1735e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1736e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1737e0639dc5SOlga Kornievskaia 1738e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1739ce0887acSOlga Kornievskaia if (!copy) { 1740ce0887acSOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1741e0639dc5SOlga Kornievskaia 1742ce0887acSOlga Kornievskaia return manage_cpntf_state(nn, &os->stateid, clp, NULL); 1743ce0887acSOlga Kornievskaia } else 1744ce0887acSOlga Kornievskaia nfsd4_stop_copy(copy); 1745ce0887acSOlga Kornievskaia 1746ce0887acSOlga Kornievskaia return nfs_ok; 1747885e2bf3SOlga Kornievskaia } 1748885e2bf3SOlga Kornievskaia 1749885e2bf3SOlga Kornievskaia static __be32 175051911868SOlga Kornievskaia nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 175151911868SOlga Kornievskaia union nfsd4_op_u *u) 175251911868SOlga Kornievskaia { 1753624322f1SOlga Kornievskaia struct nfsd4_copy_notify *cn = &u->copy_notify; 1754624322f1SOlga Kornievskaia __be32 status; 1755624322f1SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1756624322f1SOlga Kornievskaia struct nfs4_stid *stid; 1757624322f1SOlga Kornievskaia struct nfs4_cpntf_state *cps; 1758624322f1SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1759624322f1SOlga Kornievskaia 1760624322f1SOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1761624322f1SOlga Kornievskaia &cn->cpn_src_stateid, RD_STATE, NULL, 1762624322f1SOlga Kornievskaia &stid); 1763624322f1SOlga Kornievskaia if (status) 1764624322f1SOlga Kornievskaia return status; 1765624322f1SOlga Kornievskaia 1766624322f1SOlga Kornievskaia cn->cpn_sec = nn->nfsd4_lease; 1767624322f1SOlga Kornievskaia cn->cpn_nsec = 0; 1768624322f1SOlga Kornievskaia 1769624322f1SOlga Kornievskaia status = nfserrno(-ENOMEM); 1770624322f1SOlga Kornievskaia cps = nfs4_alloc_init_cpntf_state(nn, stid); 1771624322f1SOlga Kornievskaia if (!cps) 1772624322f1SOlga Kornievskaia goto out; 1773624322f1SOlga Kornievskaia memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t)); 1774624322f1SOlga Kornievskaia memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t)); 1775624322f1SOlga Kornievskaia memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t)); 1776624322f1SOlga Kornievskaia 1777624322f1SOlga Kornievskaia /* For now, only return one server address in cpn_src, the 1778624322f1SOlga Kornievskaia * address used by the client to connect to this server. 1779624322f1SOlga Kornievskaia */ 1780624322f1SOlga Kornievskaia cn->cpn_src.nl4_type = NL4_NETADDR; 1781624322f1SOlga Kornievskaia status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, 1782624322f1SOlga Kornievskaia &cn->cpn_src.u.nl4_addr); 1783624322f1SOlga Kornievskaia WARN_ON_ONCE(status); 1784624322f1SOlga Kornievskaia if (status) { 1785624322f1SOlga Kornievskaia nfs4_put_cpntf_state(nn, cps); 1786624322f1SOlga Kornievskaia goto out; 1787624322f1SOlga Kornievskaia } 1788624322f1SOlga Kornievskaia out: 1789624322f1SOlga Kornievskaia nfs4_put_stid(stid); 1790624322f1SOlga Kornievskaia return status; 179151911868SOlga Kornievskaia } 179251911868SOlga Kornievskaia 179351911868SOlga Kornievskaia static __be32 179495d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 179595d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 179695d871f0SAnna Schumaker { 17970d4d6720SJ. Bruce Fields __be32 status; 17985c4583b2SJeff Layton struct nfsd_file *nf; 179995d871f0SAnna Schumaker 1800aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 180195d871f0SAnna Schumaker &fallocate->falloc_stateid, 1802624322f1SOlga Kornievskaia WR_STATE, &nf, NULL); 180395d871f0SAnna Schumaker if (status != nfs_ok) { 180495d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 180595d871f0SAnna Schumaker return status; 180695d871f0SAnna Schumaker } 180795d871f0SAnna Schumaker 18085c4583b2SJeff Layton status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, 180995d871f0SAnna Schumaker fallocate->falloc_offset, 181095d871f0SAnna Schumaker fallocate->falloc_length, 181195d871f0SAnna Schumaker flags); 18125c4583b2SJeff Layton nfsd_file_put(nf); 181395d871f0SAnna Schumaker return status; 181495d871f0SAnna Schumaker } 18156308bc98SOlga Kornievskaia static __be32 18166308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 18176308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 18186308bc98SOlga Kornievskaia union nfsd4_op_u *u) 18196308bc98SOlga Kornievskaia { 1820e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1821e0639dc5SOlga Kornievskaia __be32 status = 0; 1822e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1823e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1824e0639dc5SOlga Kornievskaia 1825e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1826e0639dc5SOlga Kornievskaia if (copy) { 1827e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 1828e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1829e0639dc5SOlga Kornievskaia } else 1830e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1831e0639dc5SOlga Kornievskaia 1832e0639dc5SOlga Kornievskaia return status; 18336308bc98SOlga Kornievskaia } 183495d871f0SAnna Schumaker 183595d871f0SAnna Schumaker static __be32 183695d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1837eb69853dSChristoph Hellwig union nfsd4_op_u *u) 183895d871f0SAnna Schumaker { 1839eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 184095d871f0SAnna Schumaker } 184195d871f0SAnna Schumaker 184295d871f0SAnna Schumaker static __be32 1843b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1844eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1845b0cb9085SAnna Schumaker { 1846eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 1847b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1848b0cb9085SAnna Schumaker } 1849b0cb9085SAnna Schumaker 1850b0cb9085SAnna Schumaker static __be32 185124bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1852eb69853dSChristoph Hellwig union nfsd4_op_u *u) 185324bab491SAnna Schumaker { 1854eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 185524bab491SAnna Schumaker int whence; 185624bab491SAnna Schumaker __be32 status; 18575c4583b2SJeff Layton struct nfsd_file *nf; 185824bab491SAnna Schumaker 1859aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 186024bab491SAnna Schumaker &seek->seek_stateid, 1861624322f1SOlga Kornievskaia RD_STATE, &nf, NULL); 186224bab491SAnna Schumaker if (status) { 186324bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 186424bab491SAnna Schumaker return status; 186524bab491SAnna Schumaker } 186624bab491SAnna Schumaker 186724bab491SAnna Schumaker switch (seek->seek_whence) { 186824bab491SAnna Schumaker case NFS4_CONTENT_DATA: 186924bab491SAnna Schumaker whence = SEEK_DATA; 187024bab491SAnna Schumaker break; 187124bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 187224bab491SAnna Schumaker whence = SEEK_HOLE; 187324bab491SAnna Schumaker break; 187424bab491SAnna Schumaker default: 187524bab491SAnna Schumaker status = nfserr_union_notsupp; 187624bab491SAnna Schumaker goto out; 187724bab491SAnna Schumaker } 187824bab491SAnna Schumaker 187924bab491SAnna Schumaker /* 188024bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 188124bab491SAnna Schumaker * should ever file->f_pos. 188224bab491SAnna Schumaker */ 18835c4583b2SJeff Layton seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); 188424bab491SAnna Schumaker if (seek->seek_pos < 0) 188524bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 18865c4583b2SJeff Layton else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) 188724bab491SAnna Schumaker seek->seek_eof = true; 188824bab491SAnna Schumaker 188924bab491SAnna Schumaker out: 18905c4583b2SJeff Layton nfsd_file_put(nf); 189124bab491SAnna Schumaker return status; 189224bab491SAnna Schumaker } 189324bab491SAnna Schumaker 18941da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 18951da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 18961da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 18971da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 18981da177e4SLinus Torvalds */ 1899b37ad28bSAl Viro static __be32 1900c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1901ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 19021da177e4SLinus Torvalds { 19032ebbc012SAl Viro __be32 *buf, *p; 19041da177e4SLinus Torvalds int count; 1905b37ad28bSAl Viro __be32 status; 19061da177e4SLinus Torvalds 19078837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 19081da177e4SLinus Torvalds if (status) 19091da177e4SLinus Torvalds return status; 19101da177e4SLinus Torvalds 19113c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 19123c8e0316SYu Zhiguo if (status) 19133c8e0316SYu Zhiguo return status; 19143c8e0316SYu Zhiguo 19151da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 19161da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 19171da177e4SLinus Torvalds return nfserr_inval; 19181da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 19191da177e4SLinus Torvalds return nfserr_inval; 19201da177e4SLinus Torvalds 19211da177e4SLinus Torvalds /* count in words: 19221da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 19231da177e4SLinus Torvalds */ 19241da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 19251da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 19261da177e4SLinus Torvalds if (!buf) 19273e772463SJ. Bruce Fields return nfserr_jukebox; 19281da177e4SLinus Torvalds 192984822d0bSJ. Bruce Fields p = buf; 1930d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1931ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1932d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1933d5184658SJ. Bruce Fields verify->ve_bmval, 1934406a7ea9SFrank Filz rqstp, 0); 193541ae6e71SJ. Bruce Fields /* 193641ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 193741ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 193841ae6e71SJ. Bruce Fields */ 193984822d0bSJ. Bruce Fields if (status == nfserr_resource) 19401da177e4SLinus Torvalds status = nfserr_not_same; 19411da177e4SLinus Torvalds if (status) 19421da177e4SLinus Torvalds goto out_kfree; 19431da177e4SLinus Torvalds 194495ec28cdSBenny Halevy /* skip bitmap */ 194595ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 19461da177e4SLinus Torvalds status = nfserr_not_same; 19471da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 19481da177e4SLinus Torvalds goto out_kfree; 19491da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 19501da177e4SLinus Torvalds status = nfserr_same; 19511da177e4SLinus Torvalds 19521da177e4SLinus Torvalds out_kfree: 19531da177e4SLinus Torvalds kfree(buf); 19541da177e4SLinus Torvalds return status; 19551da177e4SLinus Torvalds } 19561da177e4SLinus Torvalds 1957c954e2a5SJ.Bruce Fields static __be32 1958c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1959eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1960c954e2a5SJ.Bruce Fields { 1961c954e2a5SJ.Bruce Fields __be32 status; 1962c954e2a5SJ.Bruce Fields 1963eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 1964c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1965c954e2a5SJ.Bruce Fields } 1966c954e2a5SJ.Bruce Fields 1967c954e2a5SJ.Bruce Fields static __be32 1968c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1969eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1970c954e2a5SJ.Bruce Fields { 1971c954e2a5SJ.Bruce Fields __be32 status; 1972c954e2a5SJ.Bruce Fields 1973eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 1974c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1975c954e2a5SJ.Bruce Fields } 1976c954e2a5SJ.Bruce Fields 19779cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 19789cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 19799cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 19809cf514ccSChristoph Hellwig { 19818a4c3926SJeff Layton if (!exp->ex_layout_types) { 19829cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 19839cf514ccSChristoph Hellwig return NULL; 19849cf514ccSChristoph Hellwig } 19859cf514ccSChristoph Hellwig 1986b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1987b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 19889cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 19899cf514ccSChristoph Hellwig __func__, layout_type); 19909cf514ccSChristoph Hellwig return NULL; 19919cf514ccSChristoph Hellwig } 19929cf514ccSChristoph Hellwig 19939cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 19949cf514ccSChristoph Hellwig } 19959cf514ccSChristoph Hellwig 19969cf514ccSChristoph Hellwig static __be32 19979cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 1998eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 19999cf514ccSChristoph Hellwig { 2000eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 20019cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 20029cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 20039cf514ccSChristoph Hellwig struct svc_export *exp; 20049cf514ccSChristoph Hellwig __be32 nfserr; 20059cf514ccSChristoph Hellwig 20069cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 20079cf514ccSChristoph Hellwig __func__, 20089cf514ccSChristoph Hellwig gdp->gd_layout_type, 20099cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 20109cf514ccSChristoph Hellwig gdp->gd_maxcount); 20119cf514ccSChristoph Hellwig 20129cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 20139cf514ccSChristoph Hellwig if (!map) { 20149cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 20159cf514ccSChristoph Hellwig __func__); 20169cf514ccSChristoph Hellwig return nfserr_noent; 20179cf514ccSChristoph Hellwig } 20189cf514ccSChristoph Hellwig 20199cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 20209cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 20219cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 20229cf514ccSChristoph Hellwig return nfserr_noent; 20239cf514ccSChristoph Hellwig } 20249cf514ccSChristoph Hellwig 20259cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 20269cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 20279cf514ccSChristoph Hellwig if (!ops) 20289cf514ccSChristoph Hellwig goto out; 20299cf514ccSChristoph Hellwig 20309cf514ccSChristoph Hellwig nfserr = nfs_ok; 2031f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 2032f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 2033ec59659bSJ. Bruce Fields rqstp, cstate->clp, gdp); 2034f99d4fbdSChristoph Hellwig } 20359cf514ccSChristoph Hellwig 20369cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 20379cf514ccSChristoph Hellwig out: 2038a1420384SKinglong Mee exp_put(exp); 20399cf514ccSChristoph Hellwig return nfserr; 20409cf514ccSChristoph Hellwig } 20419cf514ccSChristoph Hellwig 204234b1744cSJ. Bruce Fields static void 204334b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 204434b1744cSJ. Bruce Fields { 204534b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 204634b1744cSJ. Bruce Fields } 204734b1744cSJ. Bruce Fields 20489cf514ccSChristoph Hellwig static __be32 20499cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 2050eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 20519cf514ccSChristoph Hellwig { 2052eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 20539cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 20549cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 20559cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 20569cf514ccSChristoph Hellwig __be32 nfserr; 205766282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 20589cf514ccSChristoph Hellwig 20599cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 20609cf514ccSChristoph Hellwig case IOMODE_READ: 206166282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 20629cf514ccSChristoph Hellwig break; 20639cf514ccSChristoph Hellwig case IOMODE_RW: 206466282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 20659cf514ccSChristoph Hellwig break; 20669cf514ccSChristoph Hellwig default: 20679cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 20689cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 20699cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 20709cf514ccSChristoph Hellwig goto out; 20719cf514ccSChristoph Hellwig } 20729cf514ccSChristoph Hellwig 20739cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 20749cf514ccSChristoph Hellwig if (nfserr) 20759cf514ccSChristoph Hellwig goto out; 20769cf514ccSChristoph Hellwig 20779cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 20789cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 20799cf514ccSChristoph Hellwig if (!ops) 20809cf514ccSChristoph Hellwig goto out; 20819cf514ccSChristoph Hellwig 20829cf514ccSChristoph Hellwig /* 20839cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 20849cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 20859cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 20869cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 20879cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 20889cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 20899cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 20909cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 20919cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 20929cf514ccSChristoph Hellwig */ 20939cf514ccSChristoph Hellwig nfserr = nfserr_inval; 20949cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 20959cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 20969cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 20979cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 20989cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 20999cf514ccSChristoph Hellwig goto out; 21009cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 21019cf514ccSChristoph Hellwig goto out; 21029cf514ccSChristoph Hellwig 21039cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 21049cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 210531ef83dcSChristoph Hellwig if (nfserr) { 2106f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 21079cf514ccSChristoph Hellwig goto out; 210831ef83dcSChristoph Hellwig } 21099cf514ccSChristoph Hellwig 2110c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 2111c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 2112c5c707f9SChristoph Hellwig goto out_put_stid; 2113c5c707f9SChristoph Hellwig 21142b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 21159cf514ccSChristoph Hellwig current_fh, lgp); 21169cf514ccSChristoph Hellwig if (nfserr) 21179cf514ccSChristoph Hellwig goto out_put_stid; 21189cf514ccSChristoph Hellwig 21199cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 21209cf514ccSChristoph Hellwig 21219cf514ccSChristoph Hellwig out_put_stid: 2122cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 21239cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 21249cf514ccSChristoph Hellwig out: 21259cf514ccSChristoph Hellwig return nfserr; 21269cf514ccSChristoph Hellwig } 21279cf514ccSChristoph Hellwig 212834b1744cSJ. Bruce Fields static void 212934b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 213034b1744cSJ. Bruce Fields { 213134b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 213234b1744cSJ. Bruce Fields } 213334b1744cSJ. Bruce Fields 21349cf514ccSChristoph Hellwig static __be32 21359cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 2136eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 21379cf514ccSChristoph Hellwig { 2138eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 21399cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 21409cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 21419cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 21429cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 21439cf514ccSChristoph Hellwig struct inode *inode; 21449cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 21459cf514ccSChristoph Hellwig __be32 nfserr; 21469cf514ccSChristoph Hellwig 21479cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 21489cf514ccSChristoph Hellwig if (nfserr) 21499cf514ccSChristoph Hellwig goto out; 21509cf514ccSChristoph Hellwig 21519cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 21529cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 21539cf514ccSChristoph Hellwig if (!ops) 21549cf514ccSChristoph Hellwig goto out; 21552b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 21569cf514ccSChristoph Hellwig 21579cf514ccSChristoph Hellwig nfserr = nfserr_inval; 21589cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 21599cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 21609cf514ccSChristoph Hellwig goto out; 21619cf514ccSChristoph Hellwig } 21629cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 21639cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 21649cf514ccSChristoph Hellwig goto out; 21659cf514ccSChristoph Hellwig } 21669cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 21679cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 21689cf514ccSChristoph Hellwig goto out; 21699cf514ccSChristoph Hellwig } 21709cf514ccSChristoph Hellwig 21719cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 21729cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 21739cf514ccSChristoph Hellwig &ls); 21749cf514ccSChristoph Hellwig if (nfserr) { 2175f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 21769cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 21779cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 21789cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 21799cf514ccSChristoph Hellwig goto out; 21809cf514ccSChristoph Hellwig } 21819cf514ccSChristoph Hellwig 2182cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 2183cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 2184cc8a5532SJeff Layton 21859cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 21869cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 21879cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 21889cf514ccSChristoph Hellwig } else { 21899cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 21909cf514ccSChristoph Hellwig } 21919cf514ccSChristoph Hellwig 2192d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 21939cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 21949cf514ccSChristoph Hellwig out: 21959cf514ccSChristoph Hellwig return nfserr; 21969cf514ccSChristoph Hellwig } 21979cf514ccSChristoph Hellwig 21989cf514ccSChristoph Hellwig static __be32 21999cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 2200eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 22019cf514ccSChristoph Hellwig { 2202eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 22039cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 22049cf514ccSChristoph Hellwig __be32 nfserr; 22059cf514ccSChristoph Hellwig 22069cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 22079cf514ccSChristoph Hellwig if (nfserr) 22089cf514ccSChristoph Hellwig goto out; 22099cf514ccSChristoph Hellwig 22109cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 22119cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 22129cf514ccSChristoph Hellwig goto out; 22139cf514ccSChristoph Hellwig 22149cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 22159cf514ccSChristoph Hellwig case IOMODE_READ: 22169cf514ccSChristoph Hellwig case IOMODE_RW: 22179cf514ccSChristoph Hellwig case IOMODE_ANY: 22189cf514ccSChristoph Hellwig break; 22199cf514ccSChristoph Hellwig default: 22209cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 22219cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 22229cf514ccSChristoph Hellwig nfserr = nfserr_inval; 22239cf514ccSChristoph Hellwig goto out; 22249cf514ccSChristoph Hellwig } 22259cf514ccSChristoph Hellwig 22269cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 22279cf514ccSChristoph Hellwig case RETURN_FILE: 22289cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 22299cf514ccSChristoph Hellwig break; 22309cf514ccSChristoph Hellwig case RETURN_FSID: 22319cf514ccSChristoph Hellwig case RETURN_ALL: 22329cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 22339cf514ccSChristoph Hellwig break; 22349cf514ccSChristoph Hellwig default: 22359cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 22369cf514ccSChristoph Hellwig lrp->lr_return_type); 22379cf514ccSChristoph Hellwig nfserr = nfserr_inval; 22389cf514ccSChristoph Hellwig break; 22399cf514ccSChristoph Hellwig } 22409cf514ccSChristoph Hellwig out: 22419cf514ccSChristoph Hellwig return nfserr; 22429cf514ccSChristoph Hellwig } 22439cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 22449cf514ccSChristoph Hellwig 224523e50fe3SFrank van der Linden static __be32 224623e50fe3SFrank van der Linden nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 224723e50fe3SFrank van der Linden union nfsd4_op_u *u) 224823e50fe3SFrank van der Linden { 224923e50fe3SFrank van der Linden struct nfsd4_getxattr *getxattr = &u->getxattr; 225023e50fe3SFrank van der Linden 225123e50fe3SFrank van der Linden return nfsd_getxattr(rqstp, &cstate->current_fh, 225223e50fe3SFrank van der Linden getxattr->getxa_name, &getxattr->getxa_buf, 225323e50fe3SFrank van der Linden &getxattr->getxa_len); 225423e50fe3SFrank van der Linden } 225523e50fe3SFrank van der Linden 225623e50fe3SFrank van der Linden static __be32 225723e50fe3SFrank van der Linden nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 225823e50fe3SFrank van der Linden union nfsd4_op_u *u) 225923e50fe3SFrank van der Linden { 226023e50fe3SFrank van der Linden struct nfsd4_setxattr *setxattr = &u->setxattr; 226123e50fe3SFrank van der Linden __be32 ret; 226223e50fe3SFrank van der Linden 226323e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 226423e50fe3SFrank van der Linden return nfserr_grace; 226523e50fe3SFrank van der Linden 226623e50fe3SFrank van der Linden ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name, 226723e50fe3SFrank van der Linden setxattr->setxa_buf, setxattr->setxa_len, 226823e50fe3SFrank van der Linden setxattr->setxa_flags); 226923e50fe3SFrank van der Linden 227023e50fe3SFrank van der Linden if (!ret) 227123e50fe3SFrank van der Linden set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh); 227223e50fe3SFrank van der Linden 227323e50fe3SFrank van der Linden return ret; 227423e50fe3SFrank van der Linden } 227523e50fe3SFrank van der Linden 227623e50fe3SFrank van der Linden static __be32 227723e50fe3SFrank van der Linden nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 227823e50fe3SFrank van der Linden union nfsd4_op_u *u) 227923e50fe3SFrank van der Linden { 228023e50fe3SFrank van der Linden /* 228123e50fe3SFrank van der Linden * Get the entire list, then copy out only the user attributes 228223e50fe3SFrank van der Linden * in the encode function. 228323e50fe3SFrank van der Linden */ 228423e50fe3SFrank van der Linden return nfsd_listxattr(rqstp, &cstate->current_fh, 228523e50fe3SFrank van der Linden &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len); 228623e50fe3SFrank van der Linden } 228723e50fe3SFrank van der Linden 228823e50fe3SFrank van der Linden static __be32 228923e50fe3SFrank van der Linden nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 229023e50fe3SFrank van der Linden union nfsd4_op_u *u) 229123e50fe3SFrank van der Linden { 229223e50fe3SFrank van der Linden struct nfsd4_removexattr *removexattr = &u->removexattr; 229323e50fe3SFrank van der Linden __be32 ret; 229423e50fe3SFrank van der Linden 229523e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 229623e50fe3SFrank van der Linden return nfserr_grace; 229723e50fe3SFrank van der Linden 229823e50fe3SFrank van der Linden ret = nfsd_removexattr(rqstp, &cstate->current_fh, 229923e50fe3SFrank van der Linden removexattr->rmxa_name); 230023e50fe3SFrank van der Linden 230123e50fe3SFrank van der Linden if (!ret) 230223e50fe3SFrank van der Linden set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh); 230323e50fe3SFrank van der Linden 230423e50fe3SFrank van der Linden return ret; 230523e50fe3SFrank van der Linden } 230623e50fe3SFrank van der Linden 23071da177e4SLinus Torvalds /* 23081da177e4SLinus Torvalds * NULL call. 23091da177e4SLinus Torvalds */ 23107111c66eSAl Viro static __be32 2311a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 23121da177e4SLinus Torvalds { 2313cc028a10SChuck Lever return rpc_success; 23141da177e4SLinus Torvalds } 23151da177e4SLinus Torvalds 2316e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 2317e2b20950SShankar Anand { 2318e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 2319e567b98cSAmir Goldstein percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]); 2320e2b20950SShankar Anand } 2321e2b20950SShankar Anand 2322bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 2323b591480bSJ.Bruce Fields 2324f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 2325b001a1b6SBenny Halevy 23261da177e4SLinus Torvalds /* 232757716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 2328f9bb94c4SAndy Adamson * 232957716355SJ. Bruce Fields * Also note, enforced elsewhere: 233057716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 233157716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 23321d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 23331d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 233457716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 233557716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 233657716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 2337f9bb94c4SAndy Adamson */ 233857716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 2339f9bb94c4SAndy Adamson { 23407a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 234157716355SJ. Bruce Fields 234257716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 234357716355SJ. Bruce Fields if (args->minorversion == 0) 234457716355SJ. Bruce Fields return nfs_ok; 234557716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 234657716355SJ. Bruce Fields if (args->opcnt == 0) 234757716355SJ. Bruce Fields return nfs_ok; 23487a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 234957716355SJ. Bruce Fields return nfs_ok; 23507a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 235157716355SJ. Bruce Fields return nfserr_op_not_in_session; 23527a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 235357716355SJ. Bruce Fields return nfs_ok; 23547a04cfdaSJ. Bruce Fields /* 23557a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 23567a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 23577a04cfdaSJ. Bruce Fields * compound: 23587a04cfdaSJ. Bruce Fields */ 235957716355SJ. Bruce Fields if (args->opcnt != 1) 236057716355SJ. Bruce Fields return nfserr_not_only_op; 236157716355SJ. Bruce Fields return nfs_ok; 2362f9bb94c4SAndy Adamson } 2363f9bb94c4SAndy Adamson 2364f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 236522b03214SJ. Bruce Fields { 236622b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 236722b03214SJ. Bruce Fields } 236822b03214SJ. Bruce Fields 23691091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 23701091006cSJ. Bruce Fields { 2371e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 2372e372ba60SJ. Bruce Fields return false; 2373c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 23741091006cSJ. Bruce Fields } 23751091006cSJ. Bruce Fields 237668d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 237768d93184SJ. Bruce Fields { 237868d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 237968d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 238068d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 238168d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 2382bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 2383bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 238468d93184SJ. Bruce Fields 238568d93184SJ. Bruce Fields /* 238668d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 238768d93184SJ. Bruce Fields * have special rules. 238868d93184SJ. Bruce Fields */ 238968d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 239068d93184SJ. Bruce Fields return false; 239168d93184SJ. Bruce Fields /* 239268d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 239368d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 239468d93184SJ. Bruce Fields * result: 239568d93184SJ. Bruce Fields */ 239668d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 239768d93184SJ. Bruce Fields return false; 239851904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 239951904b08SJ. Bruce Fields return false; 240068d93184SJ. Bruce Fields nextd = OPDESC(next); 240168d93184SJ. Bruce Fields /* 240268d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 240368d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 240468d93184SJ. Bruce Fields * now: 240568d93184SJ. Bruce Fields */ 240668d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 240768d93184SJ. Bruce Fields } 240868d93184SJ. Bruce Fields 2409b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 2410b9e8638eSOlga Kornievskaia static void 2411b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2412b9e8638eSOlga Kornievskaia { 2413b9e8638eSOlga Kornievskaia struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; 2414b9e8638eSOlga Kornievskaia struct nfsd4_copy *copy; 2415b9e8638eSOlga Kornievskaia struct nfsd4_putfh *putfh; 2416b9e8638eSOlga Kornievskaia int i; 2417b9e8638eSOlga Kornievskaia 2418b9e8638eSOlga Kornievskaia /* traverse all operation and if it's a COPY compound, mark the 2419b9e8638eSOlga Kornievskaia * source filehandle to skip verification 2420b9e8638eSOlga Kornievskaia */ 2421b9e8638eSOlga Kornievskaia for (i = 0; i < args->opcnt; i++) { 2422b9e8638eSOlga Kornievskaia op = &args->ops[i]; 2423b9e8638eSOlga Kornievskaia if (op->opnum == OP_PUTFH) 2424b9e8638eSOlga Kornievskaia current_op = op; 2425b9e8638eSOlga Kornievskaia else if (op->opnum == OP_SAVEFH) 2426b9e8638eSOlga Kornievskaia saved_op = current_op; 2427b9e8638eSOlga Kornievskaia else if (op->opnum == OP_RESTOREFH) 2428b9e8638eSOlga Kornievskaia current_op = saved_op; 2429b9e8638eSOlga Kornievskaia else if (op->opnum == OP_COPY) { 2430b9e8638eSOlga Kornievskaia copy = (struct nfsd4_copy *)&op->u; 2431b9e8638eSOlga Kornievskaia if (!saved_op) { 2432b9e8638eSOlga Kornievskaia op->status = nfserr_nofilehandle; 2433b9e8638eSOlga Kornievskaia return; 2434b9e8638eSOlga Kornievskaia } 2435b9e8638eSOlga Kornievskaia putfh = (struct nfsd4_putfh *)&saved_op->u; 2436b9e8638eSOlga Kornievskaia if (!copy->cp_intra) 2437b9e8638eSOlga Kornievskaia putfh->no_verify = true; 2438b9e8638eSOlga Kornievskaia } 2439b9e8638eSOlga Kornievskaia } 2440b9e8638eSOlga Kornievskaia } 2441b9e8638eSOlga Kornievskaia #else 2442b9e8638eSOlga Kornievskaia static void 2443b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2444b9e8638eSOlga Kornievskaia { 2445b9e8638eSOlga Kornievskaia } 2446b9e8638eSOlga Kornievskaia #endif 2447b9e8638eSOlga Kornievskaia 2448f9bb94c4SAndy Adamson /* 24491da177e4SLinus Torvalds * COMPOUND call. 24501da177e4SLinus Torvalds */ 24517111c66eSAl Viro static __be32 2452a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 24531da177e4SLinus Torvalds { 2454a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 2455a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 24561da177e4SLinus Torvalds struct nfsd4_op *op; 2457e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 24584daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 24594daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 2460e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 2461b37ad28bSAl Viro __be32 status; 24621da177e4SLinus Torvalds 2463bddfdbcdSChuck Lever resp->xdr = &rqstp->rq_res_stream; 2464*3b0ebb25SChuck Lever resp->statusp = resp->xdr->p; 2465bddfdbcdSChuck Lever 2466bddfdbcdSChuck Lever /* reserve space for: NFS status code */ 2467bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT); 2468bddfdbcdSChuck Lever 24691da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 2470bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen); 24711da177e4SLinus Torvalds resp->taglen = args->taglen; 24721da177e4SLinus Torvalds resp->tag = args->tag; 24731da177e4SLinus Torvalds resp->rqstp = rqstp; 24744daeed25SKinglong Mee cstate->minorversion = args->minorversion; 24754daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 24764daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 24778ff30fa4SNeilBrown /* 24788ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 24798ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 24808ff30fa4SNeilBrown */ 248130660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 24821da177e4SLinus Torvalds 24831da177e4SLinus Torvalds /* 24841da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 24851da177e4SLinus Torvalds */ 24861da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 2487e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 24881da177e4SLinus Torvalds goto out; 24890078117cSJ. Bruce Fields status = nfserr_resource; 24900078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 24910078117cSJ. Bruce Fields goto out; 24921da177e4SLinus Torvalds 249357716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 249457716355SJ. Bruce Fields if (status) { 2495f9bb94c4SAndy Adamson op = &args->ops[0]; 249657716355SJ. Bruce Fields op->status = status; 24975b7b15aeSJ. Bruce Fields resp->opcnt = 1; 2498f9bb94c4SAndy Adamson goto encode_op; 2499f9bb94c4SAndy Adamson } 2500b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(args); 2501f9bb94c4SAndy Adamson 250228df3d15SJ. Bruce Fields rqstp->rq_lease_breaker = (void **)&cstate->clp; 250328df3d15SJ. Bruce Fields 2504fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 25051da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 25061da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 25071da177e4SLinus Torvalds 25081da177e4SLinus Torvalds /* 25091da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 25101da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 25111da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 25121da177e4SLinus Torvalds */ 25139d313b17SJ. Bruce Fields if (op->status) { 25149d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 25159d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 25161da177e4SLinus Torvalds goto encode_op; 25179d313b17SJ. Bruce Fields } 2518b9e8638eSOlga Kornievskaia if (!current_fh->fh_dentry && 2519b9e8638eSOlga Kornievskaia !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { 2520f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 25211da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 25221da177e4SLinus Torvalds goto encode_op; 25231da177e4SLinus Torvalds } 2524b9e8638eSOlga Kornievskaia } else if (current_fh->fh_export && 2525b9e8638eSOlga Kornievskaia current_fh->fh_export->ex_fslocs.migrated && 2526f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 252742ca0993SJ.Bruce Fields op->status = nfserr_moved; 252842ca0993SJ.Bruce Fields goto encode_op; 252942ca0993SJ.Bruce Fields } 2530b591480bSJ.Bruce Fields 25312336745eSKinglong Mee fh_clear_wcc(current_fh); 25322336745eSKinglong Mee 253358e7b33aSMi Jinlong /* If op is non-idempotent */ 2534f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 25354c69d585SJ. Bruce Fields /* 2536a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2537a8095f7eSJ. Bruce Fields * succesful reply: 2538a8095f7eSJ. Bruce Fields */ 2539f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2540a8095f7eSJ. Bruce Fields /* 2541a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 25424c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 25434c69d585SJ. Bruce Fields */ 25444c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 25454c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 254658e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 254758e7b33aSMi Jinlong } 254858e7b33aSMi Jinlong 254958e7b33aSMi Jinlong if (op->status) 255058e7b33aSMi Jinlong goto encode_op; 255158e7b33aSMi Jinlong 2552f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2553f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2554f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 25551da177e4SLinus Torvalds 25569a307403SJ. Bruce Fields /* Only from SEQUENCE */ 25579a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 25589a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 25599a307403SJ. Bruce Fields status = op->status; 25609a307403SJ. Bruce Fields goto out; 25619a307403SJ. Bruce Fields } 25628b70484cSTigran Mkrtchyan if (!op->status) { 2563f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2564f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 25658b70484cSTigran Mkrtchyan 2566f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 256737c593c5STigran Mkrtchyan clear_current_stateid(cstate); 25688b70484cSTigran Mkrtchyan 2569d781e3dfSJ. Bruce Fields if (current_fh->fh_export && 2570d781e3dfSJ. Bruce Fields need_wrongsec_check(rqstp)) 25714daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 25728b70484cSTigran Mkrtchyan } 25731da177e4SLinus Torvalds encode_op: 2574a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2575a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2576bddfdbcdSChuck Lever nfsd4_encode_replay(resp->xdr, op); 25771da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 25781da177e4SLinus Torvalds } else { 25791da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 25801da177e4SLinus Torvalds status = op->status; 25811da177e4SLinus Torvalds } 25820407717dSBenny Halevy 2583fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2584fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 25850407717dSBenny Halevy 258658fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2587e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 25881da177e4SLinus Torvalds } 25891da177e4SLinus Torvalds 25904daeed25SKinglong Mee fh_put(current_fh); 25914daeed25SKinglong Mee fh_put(save_fh); 25924daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 25931da177e4SLinus Torvalds out: 2594cc028a10SChuck Lever cstate->status = status; 25952f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 259630660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 2597cc028a10SChuck Lever return rpc_success; 25981da177e4SLinus Torvalds } 25991da177e4SLinus Torvalds 260058e7b33aSMi Jinlong #define op_encode_hdr_size (2) 260158e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 260258e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 260358e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 260458e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 260558e7b33aSMi Jinlong 26068c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 26078c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 260858e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 260958e7b33aSMi Jinlong 261058e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 261158e7b33aSMi Jinlong 261258e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 261358e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 261458e7b33aSMi Jinlong op_encode_ace_maxsz) 261558e7b33aSMi Jinlong 261658e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 261758e7b33aSMi Jinlong 261858e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 261958e7b33aSMi Jinlong { 262058e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 262158e7b33aSMi Jinlong } 262258e7b33aSMi Jinlong 262358e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 262458e7b33aSMi Jinlong { 262558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 262658e7b33aSMi Jinlong } 262758e7b33aSMi Jinlong 26282282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26292282cd2cSKinglong Mee { 26302282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 26312282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 26322282cd2cSKinglong Mee } 26332282cd2cSKinglong Mee 263458e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 263558e7b33aSMi Jinlong { 263658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 263758e7b33aSMi Jinlong } 263858e7b33aSMi Jinlong 263958e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 264058e7b33aSMi Jinlong { 264158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 264258e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 264358e7b33aSMi Jinlong } 264458e7b33aSMi Jinlong 2645b86cef60SJ. Bruce Fields /* 2646b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2647b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2648b86cef60SJ. Bruce Fields * reads unnecessarily. 2649b86cef60SJ. Bruce Fields */ 2650b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2651b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2652b86cef60SJ. Bruce Fields { 2653b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2654b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2655b86cef60SJ. Bruce Fields u32 ret = 0; 2656b86cef60SJ. Bruce Fields 2657b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2658b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2659b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2660b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2661b86cef60SJ. Bruce Fields 2662b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2663b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2664b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2665b86cef60SJ. Bruce Fields } 2666b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2667b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2668b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2669b86cef60SJ. Bruce Fields } 2670b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2671b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2672b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2673b86cef60SJ. Bruce Fields } 2674b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 26751ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2676b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2677b86cef60SJ. Bruce Fields } 2678b86cef60SJ. Bruce Fields /* 2679b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2680b86cef60SJ. Bruce Fields * supported_attributes) 2681b86cef60SJ. Bruce Fields */ 2682b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2683b86cef60SJ. Bruce Fields /* bitmask, length */ 2684b86cef60SJ. Bruce Fields ret += 20; 2685b86cef60SJ. Bruce Fields return ret; 2686b86cef60SJ. Bruce Fields } 2687b86cef60SJ. Bruce Fields 26882282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26892282cd2cSKinglong Mee { 26902282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 26912282cd2cSKinglong Mee } 26922282cd2cSKinglong Mee 269358e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 269458e7b33aSMi Jinlong { 269558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 269658e7b33aSMi Jinlong * sizeof(__be32); 269758e7b33aSMi Jinlong } 269858e7b33aSMi Jinlong 269958e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 270058e7b33aSMi Jinlong { 270158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 270258e7b33aSMi Jinlong * sizeof(__be32); 270358e7b33aSMi Jinlong } 270458e7b33aSMi Jinlong 270558e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 270658e7b33aSMi Jinlong { 270758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 270858e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 270958e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 271058e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 271158e7b33aSMi Jinlong } 271258e7b33aSMi Jinlong 271358e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 271458e7b33aSMi Jinlong { 271558e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 271658e7b33aSMi Jinlong 271758e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 27183c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 271958e7b33aSMi Jinlong 2720622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 272158e7b33aSMi Jinlong } 272258e7b33aSMi Jinlong 2723528b8493SAnna Schumaker static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 2724528b8493SAnna Schumaker { 2725528b8493SAnna Schumaker u32 maxcount = svc_max_payload(rqstp); 2726528b8493SAnna Schumaker u32 rlen = min(op->u.read.rd_length, maxcount); 2727528b8493SAnna Schumaker /* 2728528b8493SAnna Schumaker * If we detect that the file changed during hole encoding, then we 2729528b8493SAnna Schumaker * recover by encoding the remaining reply as data. This means we need 2730528b8493SAnna Schumaker * to set aside enough room to encode two data segments. 2731528b8493SAnna Schumaker */ 2732528b8493SAnna Schumaker u32 seg_len = 2 * (1 + 2 + 1); 2733528b8493SAnna Schumaker 2734528b8493SAnna Schumaker return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32); 2735528b8493SAnna Schumaker } 2736528b8493SAnna Schumaker 273758e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 273858e7b33aSMi Jinlong { 27393c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 274058e7b33aSMi Jinlong 27413c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 27423c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 274358e7b33aSMi Jinlong 2744561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2745561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 274658e7b33aSMi Jinlong } 274758e7b33aSMi Jinlong 27482282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27492282cd2cSKinglong Mee { 27502282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 27512282cd2cSKinglong Mee } 27522282cd2cSKinglong Mee 275358e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 275458e7b33aSMi Jinlong { 275558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 275658e7b33aSMi Jinlong * sizeof(__be32); 275758e7b33aSMi Jinlong } 275858e7b33aSMi Jinlong 275958e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 276058e7b33aSMi Jinlong { 276158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 276258e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 276358e7b33aSMi Jinlong } 276458e7b33aSMi Jinlong 2765ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2766ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2767ccae70a9SJ. Bruce Fields { 2768d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2769d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2770ccae70a9SJ. Bruce Fields } 2771ccae70a9SJ. Bruce Fields 27722282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27732282cd2cSKinglong Mee { 27742282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 27752282cd2cSKinglong Mee * sizeof(__be32); 27762282cd2cSKinglong Mee } 27772282cd2cSKinglong Mee 277858e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 277958e7b33aSMi Jinlong { 278058e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 278158e7b33aSMi Jinlong } 278258e7b33aSMi Jinlong 27832282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27842282cd2cSKinglong Mee { 27852282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 27862282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 27872282cd2cSKinglong Mee } 27882282cd2cSKinglong Mee 278958e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 279058e7b33aSMi Jinlong { 2791480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2792480efaeeSJ. Bruce Fields sizeof(__be32); 279358e7b33aSMi Jinlong } 279458e7b33aSMi Jinlong 279558e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 279658e7b33aSMi Jinlong { 2797f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 279858e7b33aSMi Jinlong } 279958e7b33aSMi Jinlong 280058e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 280158e7b33aSMi Jinlong { 280258e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2803a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2804a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 280558e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 280658e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 280758e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 280858e7b33aSMi Jinlong /* eir_server_scope<> */\ 280958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 281058e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 281158e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 281258e7b33aSMi Jinlong } 281358e7b33aSMi Jinlong 281458e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 281558e7b33aSMi Jinlong { 281658e7b33aSMi Jinlong return (op_encode_hdr_size + \ 281758e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 281858e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 281958e7b33aSMi Jinlong } 282058e7b33aSMi Jinlong 282158e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 282258e7b33aSMi Jinlong { 282358e7b33aSMi Jinlong return (op_encode_hdr_size + \ 282458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 282558e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 282658e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 282758e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 282858e7b33aSMi Jinlong } 282958e7b33aSMi Jinlong 283029ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 283129ae7f9dSAnna Schumaker { 283229ae7f9dSAnna Schumaker return (op_encode_hdr_size + 283329ae7f9dSAnna Schumaker 1 /* wr_callback */ + 283429ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 283529ae7f9dSAnna Schumaker 2 /* wr_count */ + 283629ae7f9dSAnna Schumaker 1 /* wr_committed */ + 283729ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 283829ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 283929ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 284029ae7f9dSAnna Schumaker } 284129ae7f9dSAnna Schumaker 28426308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 28436308bc98SOlga Kornievskaia struct nfsd4_op *op) 28446308bc98SOlga Kornievskaia { 28456308bc98SOlga Kornievskaia return (op_encode_hdr_size + 28466308bc98SOlga Kornievskaia 2 /* osr_count */ + 28476308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 28486308bc98SOlga Kornievskaia } 28496308bc98SOlga Kornievskaia 285051911868SOlga Kornievskaia static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, 285151911868SOlga Kornievskaia struct nfsd4_op *op) 285251911868SOlga Kornievskaia { 285351911868SOlga Kornievskaia return (op_encode_hdr_size + 285451911868SOlga Kornievskaia 3 /* cnr_lease_time */ + 285551911868SOlga Kornievskaia 1 /* We support one cnr_source_server */ + 285651911868SOlga Kornievskaia 1 /* cnr_stateid seq */ + 285751911868SOlga Kornievskaia op_encode_stateid_maxsz /* cnr_stateid */ + 285851911868SOlga Kornievskaia 1 /* num cnr_source_server*/ + 285951911868SOlga Kornievskaia 1 /* nl4_type */ + 286051911868SOlga Kornievskaia 1 /* nl4 size */ + 286151911868SOlga Kornievskaia XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) 286251911868SOlga Kornievskaia * sizeof(__be32); 286351911868SOlga Kornievskaia } 286451911868SOlga Kornievskaia 28659cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 28662282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28672282cd2cSKinglong Mee { 28682282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 28692282cd2cSKinglong Mee 28702282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 28712282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 28722282cd2cSKinglong Mee 28732282cd2cSKinglong Mee return (op_encode_hdr_size + 28742282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 28752282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 28762282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 28772282cd2cSKinglong Mee } 28782282cd2cSKinglong Mee 28799cf514ccSChristoph Hellwig /* 28809cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 28819cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 28829cf514ccSChristoph Hellwig */ 28839cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 28849cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28859cf514ccSChristoph Hellwig { 28869cf514ccSChristoph Hellwig return (op_encode_hdr_size + 28879cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 28889cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 28899cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 28909cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 28919cf514ccSChristoph Hellwig } 28929cf514ccSChristoph Hellwig 28939cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28949cf514ccSChristoph Hellwig { 28959cf514ccSChristoph Hellwig return (op_encode_hdr_size + 28969cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 28979cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 28989cf514ccSChristoph Hellwig } 28999cf514ccSChristoph Hellwig 29009cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29019cf514ccSChristoph Hellwig { 29029cf514ccSChristoph Hellwig return (op_encode_hdr_size + 29039cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 29049cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 29059cf514ccSChristoph Hellwig } 29069cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 29079cf514ccSChristoph Hellwig 29082282cd2cSKinglong Mee 29092282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29102282cd2cSKinglong Mee { 29112282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 29122282cd2cSKinglong Mee } 29132282cd2cSKinglong Mee 291423e50fe3SFrank van der Linden static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp, 291523e50fe3SFrank van der Linden struct nfsd4_op *op) 291623e50fe3SFrank van der Linden { 291723e50fe3SFrank van der Linden u32 maxcount, rlen; 291823e50fe3SFrank van der Linden 291923e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 292023e50fe3SFrank van der Linden rlen = min_t(u32, XATTR_SIZE_MAX, maxcount); 292123e50fe3SFrank van der Linden 292223e50fe3SFrank van der Linden return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); 292323e50fe3SFrank van der Linden } 292423e50fe3SFrank van der Linden 292523e50fe3SFrank van der Linden static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp, 292623e50fe3SFrank van der Linden struct nfsd4_op *op) 292723e50fe3SFrank van der Linden { 292823e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 292923e50fe3SFrank van der Linden * sizeof(__be32); 293023e50fe3SFrank van der Linden } 293123e50fe3SFrank van der Linden static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp, 293223e50fe3SFrank van der Linden struct nfsd4_op *op) 293323e50fe3SFrank van der Linden { 293423e50fe3SFrank van der Linden u32 maxcount, rlen; 293523e50fe3SFrank van der Linden 293623e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 293723e50fe3SFrank van der Linden rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount); 293823e50fe3SFrank van der Linden 293923e50fe3SFrank van der Linden return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); 294023e50fe3SFrank van der Linden } 294123e50fe3SFrank van der Linden 294223e50fe3SFrank van der Linden static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp, 294323e50fe3SFrank van der Linden struct nfsd4_op *op) 294423e50fe3SFrank van der Linden { 294523e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 294623e50fe3SFrank van der Linden * sizeof(__be32); 294723e50fe3SFrank van der Linden } 294823e50fe3SFrank van der Linden 294923e50fe3SFrank van der Linden 2950bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2951b591480bSJ.Bruce Fields [OP_ACCESS] = { 2952eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2953b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 29541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2955b591480bSJ.Bruce Fields }, 2956b591480bSJ.Bruce Fields [OP_CLOSE] = { 2957eb69853dSChristoph Hellwig .op_func = nfsd4_close, 295858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2959b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 29601c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 296157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2962b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2963b591480bSJ.Bruce Fields }, 2964b591480bSJ.Bruce Fields [OP_COMMIT] = { 2965eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 296658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2967b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 29681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2969b591480bSJ.Bruce Fields }, 2970b591480bSJ.Bruce Fields [OP_CREATE] = { 2971eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2972d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2973b001a1b6SBenny Halevy .op_name = "OP_CREATE", 29741c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2975b591480bSJ.Bruce Fields }, 2976b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2977eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 297858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2979b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 298058e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 298157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2982b591480bSJ.Bruce Fields }, 2983b591480bSJ.Bruce Fields [OP_GETATTR] = { 2984eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2985eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2986b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2987b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2988b591480bSJ.Bruce Fields }, 2989b591480bSJ.Bruce Fields [OP_GETFH] = { 2990eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2991b001a1b6SBenny Halevy .op_name = "OP_GETFH", 29921c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2993b591480bSJ.Bruce Fields }, 2994b591480bSJ.Bruce Fields [OP_LINK] = { 2995eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2996c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2997c856694eSJ. Bruce Fields | OP_CACHEME, 2998b001a1b6SBenny Halevy .op_name = "OP_LINK", 29991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 3000b591480bSJ.Bruce Fields }, 3001b591480bSJ.Bruce Fields [OP_LOCK] = { 3002eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 3003b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 3004b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 3005b001a1b6SBenny Halevy .op_name = "OP_LOCK", 30061c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3007b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 3008b591480bSJ.Bruce Fields }, 3009b591480bSJ.Bruce Fields [OP_LOCKT] = { 3010eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 3011b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 3012b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 30131c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3014b591480bSJ.Bruce Fields }, 3015b591480bSJ.Bruce Fields [OP_LOCKU] = { 3016eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 301758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3018b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 30191c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 302057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 3021b591480bSJ.Bruce Fields }, 3022b591480bSJ.Bruce Fields [OP_LOOKUP] = { 3023eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 3024d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3025b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 30261c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3027b591480bSJ.Bruce Fields }, 3028b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 3029eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 3030d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3031b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 30321c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3033b591480bSJ.Bruce Fields }, 3034b591480bSJ.Bruce Fields [OP_NVERIFY] = { 3035eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 3036b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 30371c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3038b591480bSJ.Bruce Fields }, 3039b591480bSJ.Bruce Fields [OP_OPEN] = { 3040eb69853dSChristoph Hellwig .op_func = nfsd4_open, 304158e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3042b001a1b6SBenny Halevy .op_name = "OP_OPEN", 30431c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 3044b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 3045b591480bSJ.Bruce Fields }, 3046b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 3047eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 304858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3049b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 30501c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 3051b591480bSJ.Bruce Fields }, 3052b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 3053eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 305458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3055b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 30561c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 305757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 3058b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 3059b591480bSJ.Bruce Fields }, 3060b591480bSJ.Bruce Fields [OP_PUTFH] = { 3061eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 306268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 30635b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3064b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 30651c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3066b591480bSJ.Bruce Fields }, 3067eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 3068eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 306968d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 30705b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3071b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 30721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3073eeac294eSJ.Bruce Fields }, 3074b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 3075eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 307668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 30775b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3078b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 30791c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3080b591480bSJ.Bruce Fields }, 3081b591480bSJ.Bruce Fields [OP_READ] = { 3082eb69853dSChristoph Hellwig .op_func = nfsd4_read, 308334b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 3084b001a1b6SBenny Halevy .op_name = "OP_READ", 30851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 308657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 3087b591480bSJ.Bruce Fields }, 3088b591480bSJ.Bruce Fields [OP_READDIR] = { 3089eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 3090b001a1b6SBenny Halevy .op_name = "OP_READDIR", 30911c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 3092b591480bSJ.Bruce Fields }, 3093b591480bSJ.Bruce Fields [OP_READLINK] = { 3094eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 3095b001a1b6SBenny Halevy .op_name = "OP_READLINK", 30961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 3097b591480bSJ.Bruce Fields }, 3098b591480bSJ.Bruce Fields [OP_REMOVE] = { 3099eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 3100c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3101b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 31021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 3103b591480bSJ.Bruce Fields }, 3104b591480bSJ.Bruce Fields [OP_RENAME] = { 3105eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 3106c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 310758e7b33aSMi Jinlong .op_name = "OP_RENAME", 31081c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 3109b591480bSJ.Bruce Fields }, 3110b591480bSJ.Bruce Fields [OP_RENEW] = { 3111eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 311258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 311358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3114b001a1b6SBenny Halevy .op_name = "OP_RENEW", 31151c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 311658e7b33aSMi Jinlong 3117b591480bSJ.Bruce Fields }, 3118b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 3119eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 312068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 312158e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 3122b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 31231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3124b591480bSJ.Bruce Fields }, 3125b591480bSJ.Bruce Fields [OP_SAVEFH] = { 3126eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 312758e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3128b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 31291c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3130b591480bSJ.Bruce Fields }, 3131dcb488a3SAndy Adamson [OP_SECINFO] = { 3132eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 313334b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 313468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 3135b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 31361c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 3137dcb488a3SAndy Adamson }, 3138b591480bSJ.Bruce Fields [OP_SETATTR] = { 3139eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 3140b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 3141b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 3142b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 31431c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 314457832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 3145b591480bSJ.Bruce Fields }, 3146b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 3147eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 314858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3149b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 3150b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 3151b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 31521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 3153b591480bSJ.Bruce Fields }, 3154b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 3155eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 315658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3157c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 3158b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 31591c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3160b591480bSJ.Bruce Fields }, 3161b591480bSJ.Bruce Fields [OP_VERIFY] = { 3162eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 3163b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 31641c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3165b591480bSJ.Bruce Fields }, 3166b591480bSJ.Bruce Fields [OP_WRITE] = { 3167eb69853dSChristoph Hellwig .op_func = nfsd4_write, 3168c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3169b001a1b6SBenny Halevy .op_name = "OP_WRITE", 31701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 317157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 3172b591480bSJ.Bruce Fields }, 3173b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 3174eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 317558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 317658e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3177b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 31781c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3179b591480bSJ.Bruce Fields }, 3180069b6ad4SAndy Adamson 3181069b6ad4SAndy Adamson /* NFSv4.1 operations */ 3182069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 3183eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 318458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 318558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3186069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 31871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 3188069b6ad4SAndy Adamson }, 3189cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 3190eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 3191cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3192cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 31931c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3194cb73a9f4SJ. Bruce Fields }, 31951d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 3196eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 319758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 319858e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 31991d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 32001c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 32011d1bc8f2SJ. Bruce Fields }, 3202069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 3203eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 320458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 320558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3206069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 32071c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 3208069b6ad4SAndy Adamson }, 3209069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 3210eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 321158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 321258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3213069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 32141c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3215069b6ad4SAndy Adamson }, 3216069b6ad4SAndy Adamson [OP_SEQUENCE] = { 3217eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 3218f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 3219069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 32201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 3221069b6ad4SAndy Adamson }, 3222094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 3223eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 322458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 322558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3226094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 32271c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3228094b5d74SBenny Halevy }, 32294dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 3230eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 323158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 32324dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 32331c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 32344dc6ec00SJ. Bruce Fields }, 323504f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 3236eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 3237ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 323868d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 323904f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 32401c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 324104f4ad16SJ. Bruce Fields }, 324217456804SBryan Schumaker [OP_TEST_STATEID] = { 3243eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 324417456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 324517456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 32461c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 324717456804SBryan Schumaker }, 3248e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 3249eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 325058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3251e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 325257832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 32531c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3254e1ca12dfSBryan Schumaker }, 32559cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 32569cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 3257eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 325834b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 32599cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 32609cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 32611c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 32629cf514ccSChristoph Hellwig }, 32639cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 3264eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 326534b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 32669cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 32679cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 32681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 32699cf514ccSChristoph Hellwig }, 32709cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 3271eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 32729cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 32739cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 32741c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 32759cf514ccSChristoph Hellwig }, 32769cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 3277eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 32789cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 32799cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 32801c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 32819cf514ccSChristoph Hellwig }, 32829cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 328324bab491SAnna Schumaker 328424bab491SAnna Schumaker /* NFSv4.2 operations */ 328595d871f0SAnna Schumaker [OP_ALLOCATE] = { 3286eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 328703b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 328895d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 32891c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 329095d871f0SAnna Schumaker }, 3291b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 3292eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 329303b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3294b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 32951c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3296b0cb9085SAnna Schumaker }, 3297ffa0160aSChristoph Hellwig [OP_CLONE] = { 3298eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 329903b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3300ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 33011c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3302ffa0160aSChristoph Hellwig }, 330329ae7f9dSAnna Schumaker [OP_COPY] = { 3304eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 330503b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 330629ae7f9dSAnna Schumaker .op_name = "OP_COPY", 33071c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 330829ae7f9dSAnna Schumaker }, 3309528b8493SAnna Schumaker [OP_READ_PLUS] = { 3310528b8493SAnna Schumaker .op_func = nfsd4_read, 3311528b8493SAnna Schumaker .op_release = nfsd4_read_release, 3312528b8493SAnna Schumaker .op_name = "OP_READ_PLUS", 3313528b8493SAnna Schumaker .op_rsize_bop = nfsd4_read_plus_rsize, 3314528b8493SAnna Schumaker .op_get_currentstateid = nfsd4_get_readstateid, 3315528b8493SAnna Schumaker }, 331624bab491SAnna Schumaker [OP_SEEK] = { 3317eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 331824bab491SAnna Schumaker .op_name = "OP_SEEK", 33191c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 332024bab491SAnna Schumaker }, 33216308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 33226308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 33236308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 33246308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 33256308bc98SOlga Kornievskaia }, 3326885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 3327885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 3328885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3329885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 3330885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 3331885e2bf3SOlga Kornievskaia }, 333251911868SOlga Kornievskaia [OP_COPY_NOTIFY] = { 333351911868SOlga Kornievskaia .op_func = nfsd4_copy_notify, 333451911868SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 333551911868SOlga Kornievskaia .op_name = "OP_COPY_NOTIFY", 333651911868SOlga Kornievskaia .op_rsize_bop = nfsd4_copy_notify_rsize, 333751911868SOlga Kornievskaia }, 333823e50fe3SFrank van der Linden [OP_GETXATTR] = { 333923e50fe3SFrank van der Linden .op_func = nfsd4_getxattr, 334023e50fe3SFrank van der Linden .op_name = "OP_GETXATTR", 334123e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_getxattr_rsize, 334223e50fe3SFrank van der Linden }, 334323e50fe3SFrank van der Linden [OP_SETXATTR] = { 334423e50fe3SFrank van der Linden .op_func = nfsd4_setxattr, 334523e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 334623e50fe3SFrank van der Linden .op_name = "OP_SETXATTR", 334723e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_setxattr_rsize, 334823e50fe3SFrank van der Linden }, 334923e50fe3SFrank van der Linden [OP_LISTXATTRS] = { 335023e50fe3SFrank van der Linden .op_func = nfsd4_listxattrs, 335123e50fe3SFrank van der Linden .op_name = "OP_LISTXATTRS", 335223e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_listxattrs_rsize, 335323e50fe3SFrank van der Linden }, 335423e50fe3SFrank van der Linden [OP_REMOVEXATTR] = { 335523e50fe3SFrank van der Linden .op_func = nfsd4_removexattr, 335623e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 335723e50fe3SFrank van der Linden .op_name = "OP_REMOVEXATTR", 335823e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_removexattr_rsize, 335923e50fe3SFrank van der Linden }, 3360b591480bSJ.Bruce Fields }; 3361b591480bSJ.Bruce Fields 3362ed941643SAndrew Elble /** 3363ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 3364ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 3365ed941643SAndrew Elble * 3366ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 3367ed941643SAndrew Elble * 3368ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 3369ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 3370ed941643SAndrew Elble */ 3371ed941643SAndrew Elble 3372ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 3373ed941643SAndrew Elble { 3374ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 3375ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 3376e34c0ce9SColin Ian King struct nfsd4_op *this; 3377ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 3378ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 3379ed941643SAndrew Elble u32 opiter; 3380ed941643SAndrew Elble 3381ed941643SAndrew Elble if (!cstate->minorversion) 3382ed941643SAndrew Elble return false; 3383ed941643SAndrew Elble 338444b49aa6SZheng Bin if (cstate->spo_must_allowed) 3385ed941643SAndrew Elble return true; 3386ed941643SAndrew Elble 3387ed941643SAndrew Elble opiter = resp->opcnt; 3388ed941643SAndrew Elble while (opiter < argp->opcnt) { 3389ed941643SAndrew Elble this = &argp->ops[opiter++]; 3390ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 3391ed941643SAndrew Elble cstate->clp->cl_mach_cred && 3392ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 3393ed941643SAndrew Elble cstate->spo_must_allowed = true; 3394ed941643SAndrew Elble return true; 3395ed941643SAndrew Elble } 3396ed941643SAndrew Elble } 3397ed941643SAndrew Elble cstate->spo_must_allowed = false; 3398ed941643SAndrew Elble return false; 3399ed941643SAndrew Elble } 3400ed941643SAndrew Elble 34014f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 34024f0cefbfSJ. Bruce Fields { 340305b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 34044f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 34052282cd2cSKinglong Mee 34062282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 34072282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 34084f0cefbfSJ. Bruce Fields } 34094f0cefbfSJ. Bruce Fields 341007d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 341107d1f802SJ. Bruce Fields { 341207d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 34133a237b4aSChuck Lever pr_err("unable to encode reply to nonidempotent op %u (%s)\n", 341407d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 341507d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 341607d1f802SJ. Bruce Fields } 341707d1f802SJ. Bruce Fields } 341807d1f802SJ. Bruce Fields 3419f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 3420b001a1b6SBenny Halevy { 3421b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 3422b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 3423b001a1b6SBenny Halevy return "unknown_operation"; 3424b001a1b6SBenny Halevy } 3425b001a1b6SBenny Halevy 3426860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 34270a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 3428f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 3429788f7183SChuck Lever .pc_decode = nfssvc_decode_voidarg, 3430788f7183SChuck Lever .pc_encode = nfssvc_encode_voidres, 3431788f7183SChuck Lever .pc_argsize = sizeof(struct nfsd_voidargs), 3432788f7183SChuck Lever .pc_ressize = sizeof(struct nfsd_voidres), 34330a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 34340a93a47fSYu Zhiguo .pc_xdrressize = 1, 34352289e87bSChuck Lever .pc_name = "NULL", 34360a93a47fSYu Zhiguo }, 34370a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 3438f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 3439026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 344063f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 34410a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 34420a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 34433e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 34440a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 34450a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 34462289e87bSChuck Lever .pc_name = "COMPOUND", 34470a93a47fSYu Zhiguo }, 34481da177e4SLinus Torvalds }; 34491da177e4SLinus Torvalds 34507fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 3451e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 34521da177e4SLinus Torvalds .vs_vers = 4, 34531da177e4SLinus Torvalds .vs_nproc = 2, 34541da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 34557fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 34561da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 34571da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 345805a45a2dSJeff Layton .vs_rpcb_optnl = true, 34595283b03eSJeff Layton .vs_need_cong_ctrl = true, 34601da177e4SLinus Torvalds }; 3461