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 1104*a2f4c3faSTrond Myklebust status = nfsd4_clone_file_range(rqstp, 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 { 1513555dbf1aSTrond Myklebust struct file *dst = copy->nf_dst->nf_file; 1514555dbf1aSTrond Myklebust struct file *src = copy->nf_src->nf_file; 1515555dbf1aSTrond Myklebust errseq_t since; 1516e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1517e7a833e9SJ. Bruce Fields u64 bytes_total = copy->cp_count; 1518e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1519e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1520c2f1c4bdSChuck Lever int status; 1521e0639dc5SOlga Kornievskaia 1522792a5112SJ. Bruce Fields /* See RFC 7862 p.67: */ 1523792a5112SJ. Bruce Fields if (bytes_total == 0) 1524792a5112SJ. Bruce Fields bytes_total = ULLONG_MAX; 1525e0639dc5SOlga Kornievskaia do { 1526e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1527e0639dc5SOlga Kornievskaia break; 1528555dbf1aSTrond Myklebust bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos, 15295c4583b2SJeff Layton bytes_total); 1530e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1531e0639dc5SOlga Kornievskaia break; 1532e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1533e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1534e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1535e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1536e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1537eac0b17aSOlga Kornievskaia /* for a non-zero asynchronous copy do a commit of data */ 1538eac0b17aSOlga Kornievskaia if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) { 1539555dbf1aSTrond Myklebust since = READ_ONCE(dst->f_wb_err); 1540555dbf1aSTrond Myklebust status = vfs_fsync_range(dst, copy->cp_dst_pos, 1541eac0b17aSOlga Kornievskaia copy->cp_res.wr_bytes_written, 0); 1542555dbf1aSTrond Myklebust if (!status) 1543555dbf1aSTrond Myklebust status = filemap_check_wb_err(dst->f_mapping, since); 1544eac0b17aSOlga Kornievskaia if (!status) 1545eac0b17aSOlga Kornievskaia copy->committed = true; 1546eac0b17aSOlga Kornievskaia } 1547e0639dc5SOlga Kornievskaia return bytes_copied; 1548e0639dc5SOlga Kornievskaia } 1549e0639dc5SOlga Kornievskaia 1550e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1551e0639dc5SOlga Kornievskaia { 1552e0639dc5SOlga Kornievskaia __be32 status; 1553e0639dc5SOlga Kornievskaia ssize_t bytes; 1554e0639dc5SOlga Kornievskaia 1555e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1556e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1557e0639dc5SOlga Kornievskaia * to get the error 1558e0639dc5SOlga Kornievskaia */ 1559e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1560e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1561e0639dc5SOlga Kornievskaia else { 1562e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1563e0639dc5SOlga Kornievskaia status = nfs_ok; 1564e0639dc5SOlga Kornievskaia } 1565e0639dc5SOlga Kornievskaia 1566ce0887acSOlga Kornievskaia if (!copy->cp_intra) /* Inter server SSC */ 1567ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src, 1568ce0887acSOlga Kornievskaia copy->nf_dst); 1569ce0887acSOlga Kornievskaia else 1570ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); 1571ce0887acSOlga Kornievskaia 1572e0639dc5SOlga Kornievskaia return status; 1573e0639dc5SOlga Kornievskaia } 1574e0639dc5SOlga Kornievskaia 1575eb162e17SChuck Lever static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1576e0639dc5SOlga Kornievskaia { 1577e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1578e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1579e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1580e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1581e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1582e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1583e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 15845c4583b2SJeff Layton dst->nf_dst = nfsd_file_get(src->nf_dst); 1585ce0887acSOlga Kornievskaia dst->cp_intra = src->cp_intra; 1586ce0887acSOlga Kornievskaia if (src->cp_intra) /* for inter, file_src doesn't exist yet */ 15875c4583b2SJeff Layton dst->nf_src = nfsd_file_get(src->nf_src); 1588ce0887acSOlga Kornievskaia 1589e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1590ce0887acSOlga Kornievskaia memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server)); 1591ce0887acSOlga Kornievskaia memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); 1592ce0887acSOlga Kornievskaia memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); 1593ce0887acSOlga Kornievskaia dst->ss_mnt = src->ss_mnt; 1594e0639dc5SOlga Kornievskaia } 1595e0639dc5SOlga Kornievskaia 1596e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1597e0639dc5SOlga Kornievskaia { 1598624322f1SOlga Kornievskaia nfs4_free_copy_state(copy); 15995c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 16002e577f0fSOlga Kornievskaia if (copy->cp_intra) 16015c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 1602e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1603e0639dc5SOlga Kornievskaia list_del(©->copies); 1604e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1605e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1606e0639dc5SOlga Kornievskaia } 1607e0639dc5SOlga Kornievskaia 1608e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1609e0639dc5SOlga Kornievskaia { 1610e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1611e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1612e0639dc5SOlga Kornievskaia 1613ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1614ce0887acSOlga Kornievskaia copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); 1615ce0887acSOlga Kornievskaia if (!copy->nf_src) { 1616ce0887acSOlga Kornievskaia copy->nfserr = nfserr_serverfault; 1617ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1618ce0887acSOlga Kornievskaia goto do_callback; 1619ce0887acSOlga Kornievskaia } 1620ce0887acSOlga Kornievskaia copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, 1621ce0887acSOlga Kornievskaia ©->stateid); 1622ce0887acSOlga Kornievskaia if (IS_ERR(copy->nf_src->nf_file)) { 1623ce0887acSOlga Kornievskaia copy->nfserr = nfserr_offload_denied; 1624ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1625ce0887acSOlga Kornievskaia goto do_callback; 1626ce0887acSOlga Kornievskaia } 1627ce0887acSOlga Kornievskaia } 1628ce0887acSOlga Kornievskaia 1629e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1630ce0887acSOlga Kornievskaia do_callback: 1631e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1632e0639dc5SOlga Kornievskaia if (!cb_copy) 1633e0639dc5SOlga Kornievskaia goto out; 163449a36132SDai Ngo refcount_set(&cb_copy->refcount, 1); 1635e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1636e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1637e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1638e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1639e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1640e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 164187512386SChuck Lever trace_nfsd_cb_offload(copy->cp_clp, ©->cp_res.cb_stateid, 164287512386SChuck Lever ©->fh, copy->cp_count, copy->nfserr); 1643e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1644e0639dc5SOlga Kornievskaia out: 1645ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1646ce0887acSOlga Kornievskaia kfree(copy->nf_src); 1647e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1648e0639dc5SOlga Kornievskaia return 0; 1649e0639dc5SOlga Kornievskaia } 1650e0639dc5SOlga Kornievskaia 1651ffa0160aSChristoph Hellwig static __be32 165229ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1653eb69853dSChristoph Hellwig union nfsd4_op_u *u) 165429ae7f9dSAnna Schumaker { 1655eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 165629ae7f9dSAnna Schumaker __be32 status; 1657e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 165829ae7f9dSAnna Schumaker 1659ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1660ce0887acSOlga Kornievskaia if (!inter_copy_offload_enable || copy->cp_synchronous) { 1661ce0887acSOlga Kornievskaia status = nfserr_notsupp; 166229ae7f9dSAnna Schumaker goto out; 1663ce0887acSOlga Kornievskaia } 1664ce0887acSOlga Kornievskaia status = nfsd4_setup_inter_ssc(rqstp, cstate, copy, 1665ce0887acSOlga Kornievskaia ©->ss_mnt); 1666ce0887acSOlga Kornievskaia if (status) 1667ce0887acSOlga Kornievskaia return nfserr_offload_denied; 1668ce0887acSOlga Kornievskaia } else { 1669ce0887acSOlga Kornievskaia status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); 1670ce0887acSOlga Kornievskaia if (status) 1671ce0887acSOlga Kornievskaia return status; 1672ce0887acSOlga Kornievskaia } 167329ae7f9dSAnna Schumaker 1674e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1675e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1676e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1677e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1678e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 167929ae7f9dSAnna Schumaker 1680e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1681e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1682e0639dc5SOlga Kornievskaia if (!async_copy) 1683ce0887acSOlga Kornievskaia goto out_err; 1684ce0887acSOlga Kornievskaia if (!nfs4_init_copy_state(nn, copy)) 1685ce0887acSOlga Kornievskaia goto out_err; 1686e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1687e739b120SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid, 1688e739b120SOlga Kornievskaia sizeof(copy->cp_res.cb_stateid)); 1689eb162e17SChuck Lever dup_copy_fields(copy, async_copy); 1690e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1691e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1692e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1693e0639dc5SOlga Kornievskaia goto out_err; 1694e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1695e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1696e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1697e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1698e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1699e0639dc5SOlga Kornievskaia status = nfs_ok; 1700ce0887acSOlga Kornievskaia } else { 1701e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 1702ce0887acSOlga Kornievskaia } 170329ae7f9dSAnna Schumaker out: 170429ae7f9dSAnna Schumaker return status; 1705e0639dc5SOlga Kornievskaia out_err: 170618f428d4SOlga Kornievskaia if (async_copy) 1707e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1708ce0887acSOlga Kornievskaia status = nfserrno(-ENOMEM); 1709ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1710ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1711e0639dc5SOlga Kornievskaia goto out; 1712e0639dc5SOlga Kornievskaia } 1713e0639dc5SOlga Kornievskaia 1714e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1715e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1716e0639dc5SOlga Kornievskaia { 1717e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1718e0639dc5SOlga Kornievskaia 1719e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1720e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1721ce0887acSOlga Kornievskaia if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE)) 1722e0639dc5SOlga Kornievskaia continue; 1723e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1724e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1725e0639dc5SOlga Kornievskaia return copy; 1726e0639dc5SOlga Kornievskaia } 1727e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1728e0639dc5SOlga Kornievskaia return NULL; 172929ae7f9dSAnna Schumaker } 173029ae7f9dSAnna Schumaker 173129ae7f9dSAnna Schumaker static __be32 1732885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1733885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1734885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1735885e2bf3SOlga Kornievskaia { 1736e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1737e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1738e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1739e0639dc5SOlga Kornievskaia 1740e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1741ce0887acSOlga Kornievskaia if (!copy) { 1742ce0887acSOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1743e0639dc5SOlga Kornievskaia 1744ce0887acSOlga Kornievskaia return manage_cpntf_state(nn, &os->stateid, clp, NULL); 1745ce0887acSOlga Kornievskaia } else 1746ce0887acSOlga Kornievskaia nfsd4_stop_copy(copy); 1747ce0887acSOlga Kornievskaia 1748ce0887acSOlga Kornievskaia return nfs_ok; 1749885e2bf3SOlga Kornievskaia } 1750885e2bf3SOlga Kornievskaia 1751885e2bf3SOlga Kornievskaia static __be32 175251911868SOlga Kornievskaia nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 175351911868SOlga Kornievskaia union nfsd4_op_u *u) 175451911868SOlga Kornievskaia { 1755624322f1SOlga Kornievskaia struct nfsd4_copy_notify *cn = &u->copy_notify; 1756624322f1SOlga Kornievskaia __be32 status; 1757624322f1SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1758624322f1SOlga Kornievskaia struct nfs4_stid *stid; 1759624322f1SOlga Kornievskaia struct nfs4_cpntf_state *cps; 1760624322f1SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1761624322f1SOlga Kornievskaia 1762624322f1SOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1763624322f1SOlga Kornievskaia &cn->cpn_src_stateid, RD_STATE, NULL, 1764624322f1SOlga Kornievskaia &stid); 1765624322f1SOlga Kornievskaia if (status) 1766624322f1SOlga Kornievskaia return status; 1767624322f1SOlga Kornievskaia 1768624322f1SOlga Kornievskaia cn->cpn_sec = nn->nfsd4_lease; 1769624322f1SOlga Kornievskaia cn->cpn_nsec = 0; 1770624322f1SOlga Kornievskaia 1771624322f1SOlga Kornievskaia status = nfserrno(-ENOMEM); 1772624322f1SOlga Kornievskaia cps = nfs4_alloc_init_cpntf_state(nn, stid); 1773624322f1SOlga Kornievskaia if (!cps) 1774624322f1SOlga Kornievskaia goto out; 1775624322f1SOlga Kornievskaia memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t)); 1776624322f1SOlga Kornievskaia memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t)); 1777624322f1SOlga Kornievskaia memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t)); 1778624322f1SOlga Kornievskaia 1779624322f1SOlga Kornievskaia /* For now, only return one server address in cpn_src, the 1780624322f1SOlga Kornievskaia * address used by the client to connect to this server. 1781624322f1SOlga Kornievskaia */ 1782624322f1SOlga Kornievskaia cn->cpn_src.nl4_type = NL4_NETADDR; 1783624322f1SOlga Kornievskaia status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, 1784624322f1SOlga Kornievskaia &cn->cpn_src.u.nl4_addr); 1785624322f1SOlga Kornievskaia WARN_ON_ONCE(status); 1786624322f1SOlga Kornievskaia if (status) { 1787624322f1SOlga Kornievskaia nfs4_put_cpntf_state(nn, cps); 1788624322f1SOlga Kornievskaia goto out; 1789624322f1SOlga Kornievskaia } 1790624322f1SOlga Kornievskaia out: 1791624322f1SOlga Kornievskaia nfs4_put_stid(stid); 1792624322f1SOlga Kornievskaia return status; 179351911868SOlga Kornievskaia } 179451911868SOlga Kornievskaia 179551911868SOlga Kornievskaia static __be32 179695d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 179795d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 179895d871f0SAnna Schumaker { 17990d4d6720SJ. Bruce Fields __be32 status; 18005c4583b2SJeff Layton struct nfsd_file *nf; 180195d871f0SAnna Schumaker 1802aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 180395d871f0SAnna Schumaker &fallocate->falloc_stateid, 1804624322f1SOlga Kornievskaia WR_STATE, &nf, NULL); 180595d871f0SAnna Schumaker if (status != nfs_ok) { 180695d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 180795d871f0SAnna Schumaker return status; 180895d871f0SAnna Schumaker } 180995d871f0SAnna Schumaker 18105c4583b2SJeff Layton status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, 181195d871f0SAnna Schumaker fallocate->falloc_offset, 181295d871f0SAnna Schumaker fallocate->falloc_length, 181395d871f0SAnna Schumaker flags); 18145c4583b2SJeff Layton nfsd_file_put(nf); 181595d871f0SAnna Schumaker return status; 181695d871f0SAnna Schumaker } 18176308bc98SOlga Kornievskaia static __be32 18186308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 18196308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 18206308bc98SOlga Kornievskaia union nfsd4_op_u *u) 18216308bc98SOlga Kornievskaia { 1822e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1823e0639dc5SOlga Kornievskaia __be32 status = 0; 1824e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1825e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1826e0639dc5SOlga Kornievskaia 1827e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1828e0639dc5SOlga Kornievskaia if (copy) { 1829e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 1830e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1831e0639dc5SOlga Kornievskaia } else 1832e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 1833e0639dc5SOlga Kornievskaia 1834e0639dc5SOlga Kornievskaia return status; 18356308bc98SOlga Kornievskaia } 183695d871f0SAnna Schumaker 183795d871f0SAnna Schumaker static __be32 183895d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1839eb69853dSChristoph Hellwig union nfsd4_op_u *u) 184095d871f0SAnna Schumaker { 1841eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 184295d871f0SAnna Schumaker } 184395d871f0SAnna Schumaker 184495d871f0SAnna Schumaker static __be32 1845b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1846eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1847b0cb9085SAnna Schumaker { 1848eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 1849b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1850b0cb9085SAnna Schumaker } 1851b0cb9085SAnna Schumaker 1852b0cb9085SAnna Schumaker static __be32 185324bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1854eb69853dSChristoph Hellwig union nfsd4_op_u *u) 185524bab491SAnna Schumaker { 1856eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 185724bab491SAnna Schumaker int whence; 185824bab491SAnna Schumaker __be32 status; 18595c4583b2SJeff Layton struct nfsd_file *nf; 186024bab491SAnna Schumaker 1861aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 186224bab491SAnna Schumaker &seek->seek_stateid, 1863624322f1SOlga Kornievskaia RD_STATE, &nf, NULL); 186424bab491SAnna Schumaker if (status) { 186524bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 186624bab491SAnna Schumaker return status; 186724bab491SAnna Schumaker } 186824bab491SAnna Schumaker 186924bab491SAnna Schumaker switch (seek->seek_whence) { 187024bab491SAnna Schumaker case NFS4_CONTENT_DATA: 187124bab491SAnna Schumaker whence = SEEK_DATA; 187224bab491SAnna Schumaker break; 187324bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 187424bab491SAnna Schumaker whence = SEEK_HOLE; 187524bab491SAnna Schumaker break; 187624bab491SAnna Schumaker default: 187724bab491SAnna Schumaker status = nfserr_union_notsupp; 187824bab491SAnna Schumaker goto out; 187924bab491SAnna Schumaker } 188024bab491SAnna Schumaker 188124bab491SAnna Schumaker /* 188224bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 188324bab491SAnna Schumaker * should ever file->f_pos. 188424bab491SAnna Schumaker */ 18855c4583b2SJeff Layton seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); 188624bab491SAnna Schumaker if (seek->seek_pos < 0) 188724bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 18885c4583b2SJeff Layton else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) 188924bab491SAnna Schumaker seek->seek_eof = true; 189024bab491SAnna Schumaker 189124bab491SAnna Schumaker out: 18925c4583b2SJeff Layton nfsd_file_put(nf); 189324bab491SAnna Schumaker return status; 189424bab491SAnna Schumaker } 189524bab491SAnna Schumaker 18961da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 18971da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 18981da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 18991da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 19001da177e4SLinus Torvalds */ 1901b37ad28bSAl Viro static __be32 1902c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1903ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 19041da177e4SLinus Torvalds { 19052ebbc012SAl Viro __be32 *buf, *p; 19061da177e4SLinus Torvalds int count; 1907b37ad28bSAl Viro __be32 status; 19081da177e4SLinus Torvalds 19098837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 19101da177e4SLinus Torvalds if (status) 19111da177e4SLinus Torvalds return status; 19121da177e4SLinus Torvalds 19133c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 19143c8e0316SYu Zhiguo if (status) 19153c8e0316SYu Zhiguo return status; 19163c8e0316SYu Zhiguo 19171da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 19181da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 19191da177e4SLinus Torvalds return nfserr_inval; 19201da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 19211da177e4SLinus Torvalds return nfserr_inval; 19221da177e4SLinus Torvalds 19231da177e4SLinus Torvalds /* count in words: 19241da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 19251da177e4SLinus Torvalds */ 19261da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 19271da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 19281da177e4SLinus Torvalds if (!buf) 19293e772463SJ. Bruce Fields return nfserr_jukebox; 19301da177e4SLinus Torvalds 193184822d0bSJ. Bruce Fields p = buf; 1932d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1933ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1934d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1935d5184658SJ. Bruce Fields verify->ve_bmval, 1936406a7ea9SFrank Filz rqstp, 0); 193741ae6e71SJ. Bruce Fields /* 193841ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 193941ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 194041ae6e71SJ. Bruce Fields */ 194184822d0bSJ. Bruce Fields if (status == nfserr_resource) 19421da177e4SLinus Torvalds status = nfserr_not_same; 19431da177e4SLinus Torvalds if (status) 19441da177e4SLinus Torvalds goto out_kfree; 19451da177e4SLinus Torvalds 194695ec28cdSBenny Halevy /* skip bitmap */ 194795ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 19481da177e4SLinus Torvalds status = nfserr_not_same; 19491da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 19501da177e4SLinus Torvalds goto out_kfree; 19511da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 19521da177e4SLinus Torvalds status = nfserr_same; 19531da177e4SLinus Torvalds 19541da177e4SLinus Torvalds out_kfree: 19551da177e4SLinus Torvalds kfree(buf); 19561da177e4SLinus Torvalds return status; 19571da177e4SLinus Torvalds } 19581da177e4SLinus Torvalds 1959c954e2a5SJ.Bruce Fields static __be32 1960c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1961eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1962c954e2a5SJ.Bruce Fields { 1963c954e2a5SJ.Bruce Fields __be32 status; 1964c954e2a5SJ.Bruce Fields 1965eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 1966c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1967c954e2a5SJ.Bruce Fields } 1968c954e2a5SJ.Bruce Fields 1969c954e2a5SJ.Bruce Fields static __be32 1970c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1971eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1972c954e2a5SJ.Bruce Fields { 1973c954e2a5SJ.Bruce Fields __be32 status; 1974c954e2a5SJ.Bruce Fields 1975eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 1976c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1977c954e2a5SJ.Bruce Fields } 1978c954e2a5SJ.Bruce Fields 19799cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 19809cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 19819cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 19829cf514ccSChristoph Hellwig { 19838a4c3926SJeff Layton if (!exp->ex_layout_types) { 19849cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 19859cf514ccSChristoph Hellwig return NULL; 19869cf514ccSChristoph Hellwig } 19879cf514ccSChristoph Hellwig 1988b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1989b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 19909cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 19919cf514ccSChristoph Hellwig __func__, layout_type); 19929cf514ccSChristoph Hellwig return NULL; 19939cf514ccSChristoph Hellwig } 19949cf514ccSChristoph Hellwig 19959cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 19969cf514ccSChristoph Hellwig } 19979cf514ccSChristoph Hellwig 19989cf514ccSChristoph Hellwig static __be32 19999cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 2000eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 20019cf514ccSChristoph Hellwig { 2002eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 20039cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 20049cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 20059cf514ccSChristoph Hellwig struct svc_export *exp; 20069cf514ccSChristoph Hellwig __be32 nfserr; 20079cf514ccSChristoph Hellwig 20089cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 20099cf514ccSChristoph Hellwig __func__, 20109cf514ccSChristoph Hellwig gdp->gd_layout_type, 20119cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 20129cf514ccSChristoph Hellwig gdp->gd_maxcount); 20139cf514ccSChristoph Hellwig 20149cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 20159cf514ccSChristoph Hellwig if (!map) { 20169cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 20179cf514ccSChristoph Hellwig __func__); 20189cf514ccSChristoph Hellwig return nfserr_noent; 20199cf514ccSChristoph Hellwig } 20209cf514ccSChristoph Hellwig 20219cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 20229cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 20239cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 20249cf514ccSChristoph Hellwig return nfserr_noent; 20259cf514ccSChristoph Hellwig } 20269cf514ccSChristoph Hellwig 20279cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 20289cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 20299cf514ccSChristoph Hellwig if (!ops) 20309cf514ccSChristoph Hellwig goto out; 20319cf514ccSChristoph Hellwig 20329cf514ccSChristoph Hellwig nfserr = nfs_ok; 2033f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 2034f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 2035ec59659bSJ. Bruce Fields rqstp, cstate->clp, gdp); 2036f99d4fbdSChristoph Hellwig } 20379cf514ccSChristoph Hellwig 20389cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 20399cf514ccSChristoph Hellwig out: 2040a1420384SKinglong Mee exp_put(exp); 20419cf514ccSChristoph Hellwig return nfserr; 20429cf514ccSChristoph Hellwig } 20439cf514ccSChristoph Hellwig 204434b1744cSJ. Bruce Fields static void 204534b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 204634b1744cSJ. Bruce Fields { 204734b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 204834b1744cSJ. Bruce Fields } 204934b1744cSJ. Bruce Fields 20509cf514ccSChristoph Hellwig static __be32 20519cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 2052eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 20539cf514ccSChristoph Hellwig { 2054eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 20559cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 20569cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 20579cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 20589cf514ccSChristoph Hellwig __be32 nfserr; 205966282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 20609cf514ccSChristoph Hellwig 20619cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 20629cf514ccSChristoph Hellwig case IOMODE_READ: 206366282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 20649cf514ccSChristoph Hellwig break; 20659cf514ccSChristoph Hellwig case IOMODE_RW: 206666282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 20679cf514ccSChristoph Hellwig break; 20689cf514ccSChristoph Hellwig default: 20699cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 20709cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 20719cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 20729cf514ccSChristoph Hellwig goto out; 20739cf514ccSChristoph Hellwig } 20749cf514ccSChristoph Hellwig 20759cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 20769cf514ccSChristoph Hellwig if (nfserr) 20779cf514ccSChristoph Hellwig goto out; 20789cf514ccSChristoph Hellwig 20799cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 20809cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 20819cf514ccSChristoph Hellwig if (!ops) 20829cf514ccSChristoph Hellwig goto out; 20839cf514ccSChristoph Hellwig 20849cf514ccSChristoph Hellwig /* 20859cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 20869cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 20879cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 20889cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 20899cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 20909cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 20919cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 20929cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 20939cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 20949cf514ccSChristoph Hellwig */ 20959cf514ccSChristoph Hellwig nfserr = nfserr_inval; 20969cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 20979cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 20989cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 20999cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 21009cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 21019cf514ccSChristoph Hellwig goto out; 21029cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 21039cf514ccSChristoph Hellwig goto out; 21049cf514ccSChristoph Hellwig 21059cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 21069cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 210731ef83dcSChristoph Hellwig if (nfserr) { 2108f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 21099cf514ccSChristoph Hellwig goto out; 211031ef83dcSChristoph Hellwig } 21119cf514ccSChristoph Hellwig 2112c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 2113c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 2114c5c707f9SChristoph Hellwig goto out_put_stid; 2115c5c707f9SChristoph Hellwig 21162b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 21179cf514ccSChristoph Hellwig current_fh, lgp); 21189cf514ccSChristoph Hellwig if (nfserr) 21199cf514ccSChristoph Hellwig goto out_put_stid; 21209cf514ccSChristoph Hellwig 21219cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 21229cf514ccSChristoph Hellwig 21239cf514ccSChristoph Hellwig out_put_stid: 2124cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 21259cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 21269cf514ccSChristoph Hellwig out: 21279cf514ccSChristoph Hellwig return nfserr; 21289cf514ccSChristoph Hellwig } 21299cf514ccSChristoph Hellwig 213034b1744cSJ. Bruce Fields static void 213134b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 213234b1744cSJ. Bruce Fields { 213334b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 213434b1744cSJ. Bruce Fields } 213534b1744cSJ. Bruce Fields 21369cf514ccSChristoph Hellwig static __be32 21379cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 2138eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 21399cf514ccSChristoph Hellwig { 2140eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 21419cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 21429cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 21439cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 21449cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 21459cf514ccSChristoph Hellwig struct inode *inode; 21469cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 21479cf514ccSChristoph Hellwig __be32 nfserr; 21489cf514ccSChristoph Hellwig 21499cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 21509cf514ccSChristoph Hellwig if (nfserr) 21519cf514ccSChristoph Hellwig goto out; 21529cf514ccSChristoph Hellwig 21539cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 21549cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 21559cf514ccSChristoph Hellwig if (!ops) 21569cf514ccSChristoph Hellwig goto out; 21572b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 21589cf514ccSChristoph Hellwig 21599cf514ccSChristoph Hellwig nfserr = nfserr_inval; 21609cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 21619cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 21629cf514ccSChristoph Hellwig goto out; 21639cf514ccSChristoph Hellwig } 21649cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 21659cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 21669cf514ccSChristoph Hellwig goto out; 21679cf514ccSChristoph Hellwig } 21689cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 21699cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 21709cf514ccSChristoph Hellwig goto out; 21719cf514ccSChristoph Hellwig } 21729cf514ccSChristoph Hellwig 21739cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 21749cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 21759cf514ccSChristoph Hellwig &ls); 21769cf514ccSChristoph Hellwig if (nfserr) { 2177f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 21789cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 21799cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 21809cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 21819cf514ccSChristoph Hellwig goto out; 21829cf514ccSChristoph Hellwig } 21839cf514ccSChristoph Hellwig 2184cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 2185cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 2186cc8a5532SJeff Layton 21879cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 21889cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 21899cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 21909cf514ccSChristoph Hellwig } else { 21919cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 21929cf514ccSChristoph Hellwig } 21939cf514ccSChristoph Hellwig 2194d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 21959cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 21969cf514ccSChristoph Hellwig out: 21979cf514ccSChristoph Hellwig return nfserr; 21989cf514ccSChristoph Hellwig } 21999cf514ccSChristoph Hellwig 22009cf514ccSChristoph Hellwig static __be32 22019cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 2202eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 22039cf514ccSChristoph Hellwig { 2204eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 22059cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 22069cf514ccSChristoph Hellwig __be32 nfserr; 22079cf514ccSChristoph Hellwig 22089cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 22099cf514ccSChristoph Hellwig if (nfserr) 22109cf514ccSChristoph Hellwig goto out; 22119cf514ccSChristoph Hellwig 22129cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 22139cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 22149cf514ccSChristoph Hellwig goto out; 22159cf514ccSChristoph Hellwig 22169cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 22179cf514ccSChristoph Hellwig case IOMODE_READ: 22189cf514ccSChristoph Hellwig case IOMODE_RW: 22199cf514ccSChristoph Hellwig case IOMODE_ANY: 22209cf514ccSChristoph Hellwig break; 22219cf514ccSChristoph Hellwig default: 22229cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 22239cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 22249cf514ccSChristoph Hellwig nfserr = nfserr_inval; 22259cf514ccSChristoph Hellwig goto out; 22269cf514ccSChristoph Hellwig } 22279cf514ccSChristoph Hellwig 22289cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 22299cf514ccSChristoph Hellwig case RETURN_FILE: 22309cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 22319cf514ccSChristoph Hellwig break; 22329cf514ccSChristoph Hellwig case RETURN_FSID: 22339cf514ccSChristoph Hellwig case RETURN_ALL: 22349cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 22359cf514ccSChristoph Hellwig break; 22369cf514ccSChristoph Hellwig default: 22379cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 22389cf514ccSChristoph Hellwig lrp->lr_return_type); 22399cf514ccSChristoph Hellwig nfserr = nfserr_inval; 22409cf514ccSChristoph Hellwig break; 22419cf514ccSChristoph Hellwig } 22429cf514ccSChristoph Hellwig out: 22439cf514ccSChristoph Hellwig return nfserr; 22449cf514ccSChristoph Hellwig } 22459cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 22469cf514ccSChristoph Hellwig 224723e50fe3SFrank van der Linden static __be32 224823e50fe3SFrank van der Linden nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 224923e50fe3SFrank van der Linden union nfsd4_op_u *u) 225023e50fe3SFrank van der Linden { 225123e50fe3SFrank van der Linden struct nfsd4_getxattr *getxattr = &u->getxattr; 225223e50fe3SFrank van der Linden 225323e50fe3SFrank van der Linden return nfsd_getxattr(rqstp, &cstate->current_fh, 225423e50fe3SFrank van der Linden getxattr->getxa_name, &getxattr->getxa_buf, 225523e50fe3SFrank van der Linden &getxattr->getxa_len); 225623e50fe3SFrank van der Linden } 225723e50fe3SFrank van der Linden 225823e50fe3SFrank van der Linden static __be32 225923e50fe3SFrank van der Linden nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 226023e50fe3SFrank van der Linden union nfsd4_op_u *u) 226123e50fe3SFrank van der Linden { 226223e50fe3SFrank van der Linden struct nfsd4_setxattr *setxattr = &u->setxattr; 226323e50fe3SFrank van der Linden __be32 ret; 226423e50fe3SFrank van der Linden 226523e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 226623e50fe3SFrank van der Linden return nfserr_grace; 226723e50fe3SFrank van der Linden 226823e50fe3SFrank van der Linden ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name, 226923e50fe3SFrank van der Linden setxattr->setxa_buf, setxattr->setxa_len, 227023e50fe3SFrank van der Linden setxattr->setxa_flags); 227123e50fe3SFrank van der Linden 227223e50fe3SFrank van der Linden if (!ret) 227323e50fe3SFrank van der Linden set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh); 227423e50fe3SFrank van der Linden 227523e50fe3SFrank van der Linden return ret; 227623e50fe3SFrank van der Linden } 227723e50fe3SFrank van der Linden 227823e50fe3SFrank van der Linden static __be32 227923e50fe3SFrank van der Linden nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 228023e50fe3SFrank van der Linden union nfsd4_op_u *u) 228123e50fe3SFrank van der Linden { 228223e50fe3SFrank van der Linden /* 228323e50fe3SFrank van der Linden * Get the entire list, then copy out only the user attributes 228423e50fe3SFrank van der Linden * in the encode function. 228523e50fe3SFrank van der Linden */ 228623e50fe3SFrank van der Linden return nfsd_listxattr(rqstp, &cstate->current_fh, 228723e50fe3SFrank van der Linden &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len); 228823e50fe3SFrank van der Linden } 228923e50fe3SFrank van der Linden 229023e50fe3SFrank van der Linden static __be32 229123e50fe3SFrank van der Linden nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 229223e50fe3SFrank van der Linden union nfsd4_op_u *u) 229323e50fe3SFrank van der Linden { 229423e50fe3SFrank van der Linden struct nfsd4_removexattr *removexattr = &u->removexattr; 229523e50fe3SFrank van der Linden __be32 ret; 229623e50fe3SFrank van der Linden 229723e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 229823e50fe3SFrank van der Linden return nfserr_grace; 229923e50fe3SFrank van der Linden 230023e50fe3SFrank van der Linden ret = nfsd_removexattr(rqstp, &cstate->current_fh, 230123e50fe3SFrank van der Linden removexattr->rmxa_name); 230223e50fe3SFrank van der Linden 230323e50fe3SFrank van der Linden if (!ret) 230423e50fe3SFrank van der Linden set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh); 230523e50fe3SFrank van der Linden 230623e50fe3SFrank van der Linden return ret; 230723e50fe3SFrank van der Linden } 230823e50fe3SFrank van der Linden 23091da177e4SLinus Torvalds /* 23101da177e4SLinus Torvalds * NULL call. 23111da177e4SLinus Torvalds */ 23127111c66eSAl Viro static __be32 2313a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 23141da177e4SLinus Torvalds { 2315cc028a10SChuck Lever return rpc_success; 23161da177e4SLinus Torvalds } 23171da177e4SLinus Torvalds 2318e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 2319e2b20950SShankar Anand { 2320e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 2321e567b98cSAmir Goldstein percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]); 2322e2b20950SShankar Anand } 2323e2b20950SShankar Anand 2324bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 2325b591480bSJ.Bruce Fields 2326f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 2327b001a1b6SBenny Halevy 23281da177e4SLinus Torvalds /* 232957716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 2330f9bb94c4SAndy Adamson * 233157716355SJ. Bruce Fields * Also note, enforced elsewhere: 233257716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 233357716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 23341d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 23351d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 233657716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 233757716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 233857716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 2339f9bb94c4SAndy Adamson */ 234057716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 2341f9bb94c4SAndy Adamson { 23427a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 234357716355SJ. Bruce Fields 234457716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 234557716355SJ. Bruce Fields if (args->minorversion == 0) 234657716355SJ. Bruce Fields return nfs_ok; 234757716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 234857716355SJ. Bruce Fields if (args->opcnt == 0) 234957716355SJ. Bruce Fields return nfs_ok; 23507a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 235157716355SJ. Bruce Fields return nfs_ok; 23527a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 235357716355SJ. Bruce Fields return nfserr_op_not_in_session; 23547a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 235557716355SJ. Bruce Fields return nfs_ok; 23567a04cfdaSJ. Bruce Fields /* 23577a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 23587a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 23597a04cfdaSJ. Bruce Fields * compound: 23607a04cfdaSJ. Bruce Fields */ 236157716355SJ. Bruce Fields if (args->opcnt != 1) 236257716355SJ. Bruce Fields return nfserr_not_only_op; 236357716355SJ. Bruce Fields return nfs_ok; 2364f9bb94c4SAndy Adamson } 2365f9bb94c4SAndy Adamson 2366f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 236722b03214SJ. Bruce Fields { 236822b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 236922b03214SJ. Bruce Fields } 237022b03214SJ. Bruce Fields 23711091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 23721091006cSJ. Bruce Fields { 2373e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 2374e372ba60SJ. Bruce Fields return false; 2375c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 23761091006cSJ. Bruce Fields } 23771091006cSJ. Bruce Fields 237868d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 237968d93184SJ. Bruce Fields { 238068d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 238168d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 238268d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 238368d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 2384bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 2385bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 238668d93184SJ. Bruce Fields 238768d93184SJ. Bruce Fields /* 238868d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 238968d93184SJ. Bruce Fields * have special rules. 239068d93184SJ. Bruce Fields */ 239168d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 239268d93184SJ. Bruce Fields return false; 239368d93184SJ. Bruce Fields /* 239468d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 239568d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 239668d93184SJ. Bruce Fields * result: 239768d93184SJ. Bruce Fields */ 239868d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 239968d93184SJ. Bruce Fields return false; 240051904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 240151904b08SJ. Bruce Fields return false; 240268d93184SJ. Bruce Fields nextd = OPDESC(next); 240368d93184SJ. Bruce Fields /* 240468d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 240568d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 240668d93184SJ. Bruce Fields * now: 240768d93184SJ. Bruce Fields */ 240868d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 240968d93184SJ. Bruce Fields } 241068d93184SJ. Bruce Fields 2411b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 2412b9e8638eSOlga Kornievskaia static void 2413b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2414b9e8638eSOlga Kornievskaia { 2415b9e8638eSOlga Kornievskaia struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; 2416b9e8638eSOlga Kornievskaia struct nfsd4_copy *copy; 2417b9e8638eSOlga Kornievskaia struct nfsd4_putfh *putfh; 2418b9e8638eSOlga Kornievskaia int i; 2419b9e8638eSOlga Kornievskaia 2420b9e8638eSOlga Kornievskaia /* traverse all operation and if it's a COPY compound, mark the 2421b9e8638eSOlga Kornievskaia * source filehandle to skip verification 2422b9e8638eSOlga Kornievskaia */ 2423b9e8638eSOlga Kornievskaia for (i = 0; i < args->opcnt; i++) { 2424b9e8638eSOlga Kornievskaia op = &args->ops[i]; 2425b9e8638eSOlga Kornievskaia if (op->opnum == OP_PUTFH) 2426b9e8638eSOlga Kornievskaia current_op = op; 2427b9e8638eSOlga Kornievskaia else if (op->opnum == OP_SAVEFH) 2428b9e8638eSOlga Kornievskaia saved_op = current_op; 2429b9e8638eSOlga Kornievskaia else if (op->opnum == OP_RESTOREFH) 2430b9e8638eSOlga Kornievskaia current_op = saved_op; 2431b9e8638eSOlga Kornievskaia else if (op->opnum == OP_COPY) { 2432b9e8638eSOlga Kornievskaia copy = (struct nfsd4_copy *)&op->u; 2433b9e8638eSOlga Kornievskaia if (!saved_op) { 2434b9e8638eSOlga Kornievskaia op->status = nfserr_nofilehandle; 2435b9e8638eSOlga Kornievskaia return; 2436b9e8638eSOlga Kornievskaia } 2437b9e8638eSOlga Kornievskaia putfh = (struct nfsd4_putfh *)&saved_op->u; 2438b9e8638eSOlga Kornievskaia if (!copy->cp_intra) 2439b9e8638eSOlga Kornievskaia putfh->no_verify = true; 2440b9e8638eSOlga Kornievskaia } 2441b9e8638eSOlga Kornievskaia } 2442b9e8638eSOlga Kornievskaia } 2443b9e8638eSOlga Kornievskaia #else 2444b9e8638eSOlga Kornievskaia static void 2445b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2446b9e8638eSOlga Kornievskaia { 2447b9e8638eSOlga Kornievskaia } 2448b9e8638eSOlga Kornievskaia #endif 2449b9e8638eSOlga Kornievskaia 2450f9bb94c4SAndy Adamson /* 24511da177e4SLinus Torvalds * COMPOUND call. 24521da177e4SLinus Torvalds */ 24537111c66eSAl Viro static __be32 2454a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 24551da177e4SLinus Torvalds { 2456a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 2457a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 24581da177e4SLinus Torvalds struct nfsd4_op *op; 2459e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 24604daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 24614daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 2462e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 2463b37ad28bSAl Viro __be32 status; 24641da177e4SLinus Torvalds 2465bddfdbcdSChuck Lever resp->xdr = &rqstp->rq_res_stream; 24663b0ebb25SChuck Lever resp->statusp = resp->xdr->p; 2467bddfdbcdSChuck Lever 2468bddfdbcdSChuck Lever /* reserve space for: NFS status code */ 2469bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT); 2470bddfdbcdSChuck Lever 24711da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 2472bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen); 24731da177e4SLinus Torvalds resp->taglen = args->taglen; 24741da177e4SLinus Torvalds resp->tag = args->tag; 24751da177e4SLinus Torvalds resp->rqstp = rqstp; 24764daeed25SKinglong Mee cstate->minorversion = args->minorversion; 24774daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 24784daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 24798ff30fa4SNeilBrown /* 24808ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 24818ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 24828ff30fa4SNeilBrown */ 248330660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 24841da177e4SLinus Torvalds 24851da177e4SLinus Torvalds /* 24861da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 24871da177e4SLinus Torvalds */ 24881da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 2489e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 24901da177e4SLinus Torvalds goto out; 24910078117cSJ. Bruce Fields status = nfserr_resource; 24920078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 24930078117cSJ. Bruce Fields goto out; 24941da177e4SLinus Torvalds 249557716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 249657716355SJ. Bruce Fields if (status) { 2497f9bb94c4SAndy Adamson op = &args->ops[0]; 249857716355SJ. Bruce Fields op->status = status; 24995b7b15aeSJ. Bruce Fields resp->opcnt = 1; 2500f9bb94c4SAndy Adamson goto encode_op; 2501f9bb94c4SAndy Adamson } 2502b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(args); 2503f9bb94c4SAndy Adamson 250428df3d15SJ. Bruce Fields rqstp->rq_lease_breaker = (void **)&cstate->clp; 250528df3d15SJ. Bruce Fields 2506fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 25071da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 25081da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 25091da177e4SLinus Torvalds 25101da177e4SLinus Torvalds /* 25111da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 25121da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 25131da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 25141da177e4SLinus Torvalds */ 25159d313b17SJ. Bruce Fields if (op->status) { 25169d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 25179d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 25181da177e4SLinus Torvalds goto encode_op; 25199d313b17SJ. Bruce Fields } 2520b9e8638eSOlga Kornievskaia if (!current_fh->fh_dentry && 2521b9e8638eSOlga Kornievskaia !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { 2522f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 25231da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 25241da177e4SLinus Torvalds goto encode_op; 25251da177e4SLinus Torvalds } 2526b9e8638eSOlga Kornievskaia } else if (current_fh->fh_export && 2527b9e8638eSOlga Kornievskaia current_fh->fh_export->ex_fslocs.migrated && 2528f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 252942ca0993SJ.Bruce Fields op->status = nfserr_moved; 253042ca0993SJ.Bruce Fields goto encode_op; 253142ca0993SJ.Bruce Fields } 2532b591480bSJ.Bruce Fields 25332336745eSKinglong Mee fh_clear_wcc(current_fh); 25342336745eSKinglong Mee 253558e7b33aSMi Jinlong /* If op is non-idempotent */ 2536f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 25374c69d585SJ. Bruce Fields /* 2538a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2539a8095f7eSJ. Bruce Fields * succesful reply: 2540a8095f7eSJ. Bruce Fields */ 2541f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2542a8095f7eSJ. Bruce Fields /* 2543a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 25444c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 25454c69d585SJ. Bruce Fields */ 25464c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 25474c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 254858e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 254958e7b33aSMi Jinlong } 255058e7b33aSMi Jinlong 255158e7b33aSMi Jinlong if (op->status) 255258e7b33aSMi Jinlong goto encode_op; 255358e7b33aSMi Jinlong 2554f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2555f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2556f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 25571da177e4SLinus Torvalds 25589a307403SJ. Bruce Fields /* Only from SEQUENCE */ 25599a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 25609a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 25619a307403SJ. Bruce Fields status = op->status; 25629a307403SJ. Bruce Fields goto out; 25639a307403SJ. Bruce Fields } 25648b70484cSTigran Mkrtchyan if (!op->status) { 2565f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2566f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 25678b70484cSTigran Mkrtchyan 2568f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 256937c593c5STigran Mkrtchyan clear_current_stateid(cstate); 25708b70484cSTigran Mkrtchyan 2571d781e3dfSJ. Bruce Fields if (current_fh->fh_export && 2572d781e3dfSJ. Bruce Fields need_wrongsec_check(rqstp)) 25734daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 25748b70484cSTigran Mkrtchyan } 25751da177e4SLinus Torvalds encode_op: 2576a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2577a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2578bddfdbcdSChuck Lever nfsd4_encode_replay(resp->xdr, op); 25791da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 25801da177e4SLinus Torvalds } else { 25811da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 25821da177e4SLinus Torvalds status = op->status; 25831da177e4SLinus Torvalds } 25840407717dSBenny Halevy 2585fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2586fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 25870407717dSBenny Halevy 258858fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2589e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 25901da177e4SLinus Torvalds } 25911da177e4SLinus Torvalds 25924daeed25SKinglong Mee fh_put(current_fh); 25934daeed25SKinglong Mee fh_put(save_fh); 25944daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 25951da177e4SLinus Torvalds out: 2596cc028a10SChuck Lever cstate->status = status; 25972f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 259830660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 2599cc028a10SChuck Lever return rpc_success; 26001da177e4SLinus Torvalds } 26011da177e4SLinus Torvalds 260258e7b33aSMi Jinlong #define op_encode_hdr_size (2) 260358e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 260458e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 260558e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 260658e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 260758e7b33aSMi Jinlong 26088c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 26098c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 261058e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 261158e7b33aSMi Jinlong 261258e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 261358e7b33aSMi Jinlong 261458e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 261558e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 261658e7b33aSMi Jinlong op_encode_ace_maxsz) 261758e7b33aSMi Jinlong 261858e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 261958e7b33aSMi Jinlong 262058e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 262158e7b33aSMi Jinlong { 262258e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 262358e7b33aSMi Jinlong } 262458e7b33aSMi Jinlong 262558e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 262658e7b33aSMi Jinlong { 262758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 262858e7b33aSMi Jinlong } 262958e7b33aSMi Jinlong 26302282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26312282cd2cSKinglong Mee { 26322282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 26332282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 26342282cd2cSKinglong Mee } 26352282cd2cSKinglong Mee 263658e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 263758e7b33aSMi Jinlong { 263858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 263958e7b33aSMi Jinlong } 264058e7b33aSMi Jinlong 264158e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 264258e7b33aSMi Jinlong { 264358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 264458e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 264558e7b33aSMi Jinlong } 264658e7b33aSMi Jinlong 2647b86cef60SJ. Bruce Fields /* 2648b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2649b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2650b86cef60SJ. Bruce Fields * reads unnecessarily. 2651b86cef60SJ. Bruce Fields */ 2652b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2653b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2654b86cef60SJ. Bruce Fields { 2655b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2656b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2657b86cef60SJ. Bruce Fields u32 ret = 0; 2658b86cef60SJ. Bruce Fields 2659b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2660b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2661b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2662b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2663b86cef60SJ. Bruce Fields 2664b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2665b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2666b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2667b86cef60SJ. Bruce Fields } 2668b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2669b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2670b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2671b86cef60SJ. Bruce Fields } 2672b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2673b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2674b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2675b86cef60SJ. Bruce Fields } 2676b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 26771ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2678b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2679b86cef60SJ. Bruce Fields } 2680b86cef60SJ. Bruce Fields /* 2681b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2682b86cef60SJ. Bruce Fields * supported_attributes) 2683b86cef60SJ. Bruce Fields */ 2684b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2685b86cef60SJ. Bruce Fields /* bitmask, length */ 2686b86cef60SJ. Bruce Fields ret += 20; 2687b86cef60SJ. Bruce Fields return ret; 2688b86cef60SJ. Bruce Fields } 2689b86cef60SJ. Bruce Fields 26902282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 26912282cd2cSKinglong Mee { 26922282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 26932282cd2cSKinglong Mee } 26942282cd2cSKinglong Mee 269558e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 269658e7b33aSMi Jinlong { 269758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 269858e7b33aSMi Jinlong * sizeof(__be32); 269958e7b33aSMi Jinlong } 270058e7b33aSMi Jinlong 270158e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 270258e7b33aSMi Jinlong { 270358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 270458e7b33aSMi Jinlong * sizeof(__be32); 270558e7b33aSMi Jinlong } 270658e7b33aSMi Jinlong 270758e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 270858e7b33aSMi Jinlong { 270958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 271058e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 271158e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 271258e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 271358e7b33aSMi Jinlong } 271458e7b33aSMi Jinlong 271558e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 271658e7b33aSMi Jinlong { 271758e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 271858e7b33aSMi Jinlong 271958e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 27203c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 272158e7b33aSMi Jinlong 2722622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 272358e7b33aSMi Jinlong } 272458e7b33aSMi Jinlong 2725528b8493SAnna Schumaker static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 2726528b8493SAnna Schumaker { 2727528b8493SAnna Schumaker u32 maxcount = svc_max_payload(rqstp); 2728528b8493SAnna Schumaker u32 rlen = min(op->u.read.rd_length, maxcount); 2729528b8493SAnna Schumaker /* 2730528b8493SAnna Schumaker * If we detect that the file changed during hole encoding, then we 2731528b8493SAnna Schumaker * recover by encoding the remaining reply as data. This means we need 2732528b8493SAnna Schumaker * to set aside enough room to encode two data segments. 2733528b8493SAnna Schumaker */ 2734528b8493SAnna Schumaker u32 seg_len = 2 * (1 + 2 + 1); 2735528b8493SAnna Schumaker 2736528b8493SAnna Schumaker return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32); 2737528b8493SAnna Schumaker } 2738528b8493SAnna Schumaker 273958e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 274058e7b33aSMi Jinlong { 27413c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 274258e7b33aSMi Jinlong 27433c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 27443c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 274558e7b33aSMi Jinlong 2746561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2747561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 274858e7b33aSMi Jinlong } 274958e7b33aSMi Jinlong 27502282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27512282cd2cSKinglong Mee { 27522282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 27532282cd2cSKinglong Mee } 27542282cd2cSKinglong Mee 275558e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 275658e7b33aSMi Jinlong { 275758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 275858e7b33aSMi Jinlong * sizeof(__be32); 275958e7b33aSMi Jinlong } 276058e7b33aSMi Jinlong 276158e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 276258e7b33aSMi Jinlong { 276358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 276458e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 276558e7b33aSMi Jinlong } 276658e7b33aSMi Jinlong 2767ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2768ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2769ccae70a9SJ. Bruce Fields { 2770d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2771d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2772ccae70a9SJ. Bruce Fields } 2773ccae70a9SJ. Bruce Fields 27742282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27752282cd2cSKinglong Mee { 27762282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 27772282cd2cSKinglong Mee * sizeof(__be32); 27782282cd2cSKinglong Mee } 27792282cd2cSKinglong Mee 278058e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 278158e7b33aSMi Jinlong { 278258e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 278358e7b33aSMi Jinlong } 278458e7b33aSMi Jinlong 27852282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 27862282cd2cSKinglong Mee { 27872282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 27882282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 27892282cd2cSKinglong Mee } 27902282cd2cSKinglong Mee 279158e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 279258e7b33aSMi Jinlong { 2793480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2794480efaeeSJ. Bruce Fields sizeof(__be32); 279558e7b33aSMi Jinlong } 279658e7b33aSMi Jinlong 279758e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 279858e7b33aSMi Jinlong { 2799f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 280058e7b33aSMi Jinlong } 280158e7b33aSMi Jinlong 280258e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 280358e7b33aSMi Jinlong { 280458e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2805a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2806a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 280758e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 280858e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 280958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 281058e7b33aSMi Jinlong /* eir_server_scope<> */\ 281158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 281258e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 281358e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 281458e7b33aSMi Jinlong } 281558e7b33aSMi Jinlong 281658e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 281758e7b33aSMi Jinlong { 281858e7b33aSMi Jinlong return (op_encode_hdr_size + \ 281958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 282058e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 282158e7b33aSMi Jinlong } 282258e7b33aSMi Jinlong 282358e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 282458e7b33aSMi Jinlong { 282558e7b33aSMi Jinlong return (op_encode_hdr_size + \ 282658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 282758e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 282858e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 282958e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 283058e7b33aSMi Jinlong } 283158e7b33aSMi Jinlong 283229ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 283329ae7f9dSAnna Schumaker { 283429ae7f9dSAnna Schumaker return (op_encode_hdr_size + 283529ae7f9dSAnna Schumaker 1 /* wr_callback */ + 283629ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 283729ae7f9dSAnna Schumaker 2 /* wr_count */ + 283829ae7f9dSAnna Schumaker 1 /* wr_committed */ + 283929ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 284029ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 284129ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 284229ae7f9dSAnna Schumaker } 284329ae7f9dSAnna Schumaker 28446308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 28456308bc98SOlga Kornievskaia struct nfsd4_op *op) 28466308bc98SOlga Kornievskaia { 28476308bc98SOlga Kornievskaia return (op_encode_hdr_size + 28486308bc98SOlga Kornievskaia 2 /* osr_count */ + 28496308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 28506308bc98SOlga Kornievskaia } 28516308bc98SOlga Kornievskaia 285251911868SOlga Kornievskaia static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, 285351911868SOlga Kornievskaia struct nfsd4_op *op) 285451911868SOlga Kornievskaia { 285551911868SOlga Kornievskaia return (op_encode_hdr_size + 285651911868SOlga Kornievskaia 3 /* cnr_lease_time */ + 285751911868SOlga Kornievskaia 1 /* We support one cnr_source_server */ + 285851911868SOlga Kornievskaia 1 /* cnr_stateid seq */ + 285951911868SOlga Kornievskaia op_encode_stateid_maxsz /* cnr_stateid */ + 286051911868SOlga Kornievskaia 1 /* num cnr_source_server*/ + 286151911868SOlga Kornievskaia 1 /* nl4_type */ + 286251911868SOlga Kornievskaia 1 /* nl4 size */ + 286351911868SOlga Kornievskaia XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) 286451911868SOlga Kornievskaia * sizeof(__be32); 286551911868SOlga Kornievskaia } 286651911868SOlga Kornievskaia 28679cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 28682282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28692282cd2cSKinglong Mee { 28702282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 28712282cd2cSKinglong Mee 28722282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 28732282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 28742282cd2cSKinglong Mee 28752282cd2cSKinglong Mee return (op_encode_hdr_size + 28762282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 28772282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 28782282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 28792282cd2cSKinglong Mee } 28802282cd2cSKinglong Mee 28819cf514ccSChristoph Hellwig /* 28829cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 28839cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 28849cf514ccSChristoph Hellwig */ 28859cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 28869cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28879cf514ccSChristoph Hellwig { 28889cf514ccSChristoph Hellwig return (op_encode_hdr_size + 28899cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 28909cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 28919cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 28929cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 28939cf514ccSChristoph Hellwig } 28949cf514ccSChristoph Hellwig 28959cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28969cf514ccSChristoph Hellwig { 28979cf514ccSChristoph Hellwig return (op_encode_hdr_size + 28989cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 28999cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 29009cf514ccSChristoph Hellwig } 29019cf514ccSChristoph Hellwig 29029cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29039cf514ccSChristoph Hellwig { 29049cf514ccSChristoph Hellwig return (op_encode_hdr_size + 29059cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 29069cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 29079cf514ccSChristoph Hellwig } 29089cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 29099cf514ccSChristoph Hellwig 29102282cd2cSKinglong Mee 29112282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29122282cd2cSKinglong Mee { 29132282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 29142282cd2cSKinglong Mee } 29152282cd2cSKinglong Mee 291623e50fe3SFrank van der Linden static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp, 291723e50fe3SFrank van der Linden struct nfsd4_op *op) 291823e50fe3SFrank van der Linden { 291923e50fe3SFrank van der Linden u32 maxcount, rlen; 292023e50fe3SFrank van der Linden 292123e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 292223e50fe3SFrank van der Linden rlen = min_t(u32, XATTR_SIZE_MAX, maxcount); 292323e50fe3SFrank van der Linden 292423e50fe3SFrank van der Linden return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); 292523e50fe3SFrank van der Linden } 292623e50fe3SFrank van der Linden 292723e50fe3SFrank van der Linden static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp, 292823e50fe3SFrank van der Linden struct nfsd4_op *op) 292923e50fe3SFrank van der Linden { 293023e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 293123e50fe3SFrank van der Linden * sizeof(__be32); 293223e50fe3SFrank van der Linden } 293323e50fe3SFrank van der Linden static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp, 293423e50fe3SFrank van der Linden struct nfsd4_op *op) 293523e50fe3SFrank van der Linden { 293623e50fe3SFrank van der Linden u32 maxcount, rlen; 293723e50fe3SFrank van der Linden 293823e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 293923e50fe3SFrank van der Linden rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount); 294023e50fe3SFrank van der Linden 294123e50fe3SFrank van der Linden return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); 294223e50fe3SFrank van der Linden } 294323e50fe3SFrank van der Linden 294423e50fe3SFrank van der Linden static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp, 294523e50fe3SFrank van der Linden struct nfsd4_op *op) 294623e50fe3SFrank van der Linden { 294723e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 294823e50fe3SFrank van der Linden * sizeof(__be32); 294923e50fe3SFrank van der Linden } 295023e50fe3SFrank van der Linden 295123e50fe3SFrank van der Linden 2952bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 2953b591480bSJ.Bruce Fields [OP_ACCESS] = { 2954eb69853dSChristoph Hellwig .op_func = nfsd4_access, 2955b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 29561c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 2957b591480bSJ.Bruce Fields }, 2958b591480bSJ.Bruce Fields [OP_CLOSE] = { 2959eb69853dSChristoph Hellwig .op_func = nfsd4_close, 296058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2961b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 29621c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 296357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 2964b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 2965b591480bSJ.Bruce Fields }, 2966b591480bSJ.Bruce Fields [OP_COMMIT] = { 2967eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 296858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2969b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 29701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 2971b591480bSJ.Bruce Fields }, 2972b591480bSJ.Bruce Fields [OP_CREATE] = { 2973eb69853dSChristoph Hellwig .op_func = nfsd4_create, 2974d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2975b001a1b6SBenny Halevy .op_name = "OP_CREATE", 29761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 2977b591480bSJ.Bruce Fields }, 2978b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2979eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 298058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2981b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 298258e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 298357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 2984b591480bSJ.Bruce Fields }, 2985b591480bSJ.Bruce Fields [OP_GETATTR] = { 2986eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 2987eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2988b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2989b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2990b591480bSJ.Bruce Fields }, 2991b591480bSJ.Bruce Fields [OP_GETFH] = { 2992eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 2993b001a1b6SBenny Halevy .op_name = "OP_GETFH", 29941c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 2995b591480bSJ.Bruce Fields }, 2996b591480bSJ.Bruce Fields [OP_LINK] = { 2997eb69853dSChristoph Hellwig .op_func = nfsd4_link, 2998c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2999c856694eSJ. Bruce Fields | OP_CACHEME, 3000b001a1b6SBenny Halevy .op_name = "OP_LINK", 30011c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 3002b591480bSJ.Bruce Fields }, 3003b591480bSJ.Bruce Fields [OP_LOCK] = { 3004eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 3005b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 3006b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 3007b001a1b6SBenny Halevy .op_name = "OP_LOCK", 30081c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3009b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 3010b591480bSJ.Bruce Fields }, 3011b591480bSJ.Bruce Fields [OP_LOCKT] = { 3012eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 3013b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 3014b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 30151c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3016b591480bSJ.Bruce Fields }, 3017b591480bSJ.Bruce Fields [OP_LOCKU] = { 3018eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 301958e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3020b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 30211c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 302257832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 3023b591480bSJ.Bruce Fields }, 3024b591480bSJ.Bruce Fields [OP_LOOKUP] = { 3025eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 3026d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3027b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 30281c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3029b591480bSJ.Bruce Fields }, 3030b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 3031eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 3032d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3033b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 30341c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3035b591480bSJ.Bruce Fields }, 3036b591480bSJ.Bruce Fields [OP_NVERIFY] = { 3037eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 3038b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 30391c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3040b591480bSJ.Bruce Fields }, 3041b591480bSJ.Bruce Fields [OP_OPEN] = { 3042eb69853dSChristoph Hellwig .op_func = nfsd4_open, 304358e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3044b001a1b6SBenny Halevy .op_name = "OP_OPEN", 30451c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 3046b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 3047b591480bSJ.Bruce Fields }, 3048b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 3049eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 305058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3051b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 30521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 3053b591480bSJ.Bruce Fields }, 3054b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 3055eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 305658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3057b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 30581c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 305957832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 3060b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 3061b591480bSJ.Bruce Fields }, 3062b591480bSJ.Bruce Fields [OP_PUTFH] = { 3063eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 306468d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 30655b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3066b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 30671c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3068b591480bSJ.Bruce Fields }, 3069eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 3070eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 307168d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 30725b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3073b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 30741c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3075eeac294eSJ.Bruce Fields }, 3076b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 3077eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 307868d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 30795b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3080b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 30811c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3082b591480bSJ.Bruce Fields }, 3083b591480bSJ.Bruce Fields [OP_READ] = { 3084eb69853dSChristoph Hellwig .op_func = nfsd4_read, 308534b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 3086b001a1b6SBenny Halevy .op_name = "OP_READ", 30871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 308857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 3089b591480bSJ.Bruce Fields }, 3090b591480bSJ.Bruce Fields [OP_READDIR] = { 3091eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 3092b001a1b6SBenny Halevy .op_name = "OP_READDIR", 30931c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 3094b591480bSJ.Bruce Fields }, 3095b591480bSJ.Bruce Fields [OP_READLINK] = { 3096eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 3097b001a1b6SBenny Halevy .op_name = "OP_READLINK", 30981c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 3099b591480bSJ.Bruce Fields }, 3100b591480bSJ.Bruce Fields [OP_REMOVE] = { 3101eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 3102c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3103b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 31041c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 3105b591480bSJ.Bruce Fields }, 3106b591480bSJ.Bruce Fields [OP_RENAME] = { 3107eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 3108c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 310958e7b33aSMi Jinlong .op_name = "OP_RENAME", 31101c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 3111b591480bSJ.Bruce Fields }, 3112b591480bSJ.Bruce Fields [OP_RENEW] = { 3113eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 311458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 311558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3116b001a1b6SBenny Halevy .op_name = "OP_RENEW", 31171c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 311858e7b33aSMi Jinlong 3119b591480bSJ.Bruce Fields }, 3120b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 3121eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 312268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 312358e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 3124b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 31251c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3126b591480bSJ.Bruce Fields }, 3127b591480bSJ.Bruce Fields [OP_SAVEFH] = { 3128eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 312958e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3130b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 31311c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3132b591480bSJ.Bruce Fields }, 3133dcb488a3SAndy Adamson [OP_SECINFO] = { 3134eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 313534b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 313668d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 3137b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 31381c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 3139dcb488a3SAndy Adamson }, 3140b591480bSJ.Bruce Fields [OP_SETATTR] = { 3141eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 3142b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 3143b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 3144b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 31451c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 314657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 3147b591480bSJ.Bruce Fields }, 3148b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 3149eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 315058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3151b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 3152b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 3153b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 31541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 3155b591480bSJ.Bruce Fields }, 3156b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 3157eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 315858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3159c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 3160b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 31611c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3162b591480bSJ.Bruce Fields }, 3163b591480bSJ.Bruce Fields [OP_VERIFY] = { 3164eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 3165b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 31661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3167b591480bSJ.Bruce Fields }, 3168b591480bSJ.Bruce Fields [OP_WRITE] = { 3169eb69853dSChristoph Hellwig .op_func = nfsd4_write, 3170c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3171b001a1b6SBenny Halevy .op_name = "OP_WRITE", 31721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 317357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 3174b591480bSJ.Bruce Fields }, 3175b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 3176eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 317758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 317858e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3179b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 31801c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3181b591480bSJ.Bruce Fields }, 3182069b6ad4SAndy Adamson 3183069b6ad4SAndy Adamson /* NFSv4.1 operations */ 3184069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 3185eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 318658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 318758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3188069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 31891c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 3190069b6ad4SAndy Adamson }, 3191cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 3192eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 3193cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3194cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 31951c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3196cb73a9f4SJ. Bruce Fields }, 31971d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 3198eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 319958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 320058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 32011d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 32021c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 32031d1bc8f2SJ. Bruce Fields }, 3204069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 3205eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 320658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 320758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3208069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 32091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 3210069b6ad4SAndy Adamson }, 3211069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 3212eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 321358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 321458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3215069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 32161c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3217069b6ad4SAndy Adamson }, 3218069b6ad4SAndy Adamson [OP_SEQUENCE] = { 3219eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 3220f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 3221069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 32221c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 3223069b6ad4SAndy Adamson }, 3224094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 3225eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 322658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 322758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3228094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 32291c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3230094b5d74SBenny Halevy }, 32314dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 3232eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 323358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 32344dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 32351c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 32364dc6ec00SJ. Bruce Fields }, 323704f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 3238eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 3239ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 324068d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 324104f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 32421c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 324304f4ad16SJ. Bruce Fields }, 324417456804SBryan Schumaker [OP_TEST_STATEID] = { 3245eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 324617456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 324717456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 32481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 324917456804SBryan Schumaker }, 3250e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 3251eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 325258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3253e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 325457832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 32551c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3256e1ca12dfSBryan Schumaker }, 32579cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 32589cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 3259eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 326034b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 32619cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 32629cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 32631c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 32649cf514ccSChristoph Hellwig }, 32659cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 3266eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 326734b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 32689cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 32699cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 32701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 32719cf514ccSChristoph Hellwig }, 32729cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 3273eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 32749cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 32759cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 32761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 32779cf514ccSChristoph Hellwig }, 32789cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 3279eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 32809cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 32819cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 32821c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 32839cf514ccSChristoph Hellwig }, 32849cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 328524bab491SAnna Schumaker 328624bab491SAnna Schumaker /* NFSv4.2 operations */ 328795d871f0SAnna Schumaker [OP_ALLOCATE] = { 3288eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 328903b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 329095d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 32911c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 329295d871f0SAnna Schumaker }, 3293b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 3294eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 329503b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3296b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 32971c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3298b0cb9085SAnna Schumaker }, 3299ffa0160aSChristoph Hellwig [OP_CLONE] = { 3300eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 330103b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3302ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 33031c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3304ffa0160aSChristoph Hellwig }, 330529ae7f9dSAnna Schumaker [OP_COPY] = { 3306eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 330703b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 330829ae7f9dSAnna Schumaker .op_name = "OP_COPY", 33091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 331029ae7f9dSAnna Schumaker }, 3311528b8493SAnna Schumaker [OP_READ_PLUS] = { 3312528b8493SAnna Schumaker .op_func = nfsd4_read, 3313528b8493SAnna Schumaker .op_release = nfsd4_read_release, 3314528b8493SAnna Schumaker .op_name = "OP_READ_PLUS", 3315528b8493SAnna Schumaker .op_rsize_bop = nfsd4_read_plus_rsize, 3316528b8493SAnna Schumaker .op_get_currentstateid = nfsd4_get_readstateid, 3317528b8493SAnna Schumaker }, 331824bab491SAnna Schumaker [OP_SEEK] = { 3319eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 332024bab491SAnna Schumaker .op_name = "OP_SEEK", 33211c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 332224bab491SAnna Schumaker }, 33236308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 33246308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 33256308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 33266308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 33276308bc98SOlga Kornievskaia }, 3328885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 3329885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 3330885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3331885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 3332885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 3333885e2bf3SOlga Kornievskaia }, 333451911868SOlga Kornievskaia [OP_COPY_NOTIFY] = { 333551911868SOlga Kornievskaia .op_func = nfsd4_copy_notify, 333651911868SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 333751911868SOlga Kornievskaia .op_name = "OP_COPY_NOTIFY", 333851911868SOlga Kornievskaia .op_rsize_bop = nfsd4_copy_notify_rsize, 333951911868SOlga Kornievskaia }, 334023e50fe3SFrank van der Linden [OP_GETXATTR] = { 334123e50fe3SFrank van der Linden .op_func = nfsd4_getxattr, 334223e50fe3SFrank van der Linden .op_name = "OP_GETXATTR", 334323e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_getxattr_rsize, 334423e50fe3SFrank van der Linden }, 334523e50fe3SFrank van der Linden [OP_SETXATTR] = { 334623e50fe3SFrank van der Linden .op_func = nfsd4_setxattr, 334723e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 334823e50fe3SFrank van der Linden .op_name = "OP_SETXATTR", 334923e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_setxattr_rsize, 335023e50fe3SFrank van der Linden }, 335123e50fe3SFrank van der Linden [OP_LISTXATTRS] = { 335223e50fe3SFrank van der Linden .op_func = nfsd4_listxattrs, 335323e50fe3SFrank van der Linden .op_name = "OP_LISTXATTRS", 335423e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_listxattrs_rsize, 335523e50fe3SFrank van der Linden }, 335623e50fe3SFrank van der Linden [OP_REMOVEXATTR] = { 335723e50fe3SFrank van der Linden .op_func = nfsd4_removexattr, 335823e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 335923e50fe3SFrank van der Linden .op_name = "OP_REMOVEXATTR", 336023e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_removexattr_rsize, 336123e50fe3SFrank van der Linden }, 3362b591480bSJ.Bruce Fields }; 3363b591480bSJ.Bruce Fields 3364ed941643SAndrew Elble /** 3365ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 3366ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 3367ed941643SAndrew Elble * 3368ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 3369ed941643SAndrew Elble * 3370ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 3371ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 3372ed941643SAndrew Elble */ 3373ed941643SAndrew Elble 3374ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 3375ed941643SAndrew Elble { 3376ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 3377ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 3378e34c0ce9SColin Ian King struct nfsd4_op *this; 3379ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 3380ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 3381ed941643SAndrew Elble u32 opiter; 3382ed941643SAndrew Elble 3383ed941643SAndrew Elble if (!cstate->minorversion) 3384ed941643SAndrew Elble return false; 3385ed941643SAndrew Elble 338644b49aa6SZheng Bin if (cstate->spo_must_allowed) 3387ed941643SAndrew Elble return true; 3388ed941643SAndrew Elble 3389ed941643SAndrew Elble opiter = resp->opcnt; 3390ed941643SAndrew Elble while (opiter < argp->opcnt) { 3391ed941643SAndrew Elble this = &argp->ops[opiter++]; 3392ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 3393ed941643SAndrew Elble cstate->clp->cl_mach_cred && 3394ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 3395ed941643SAndrew Elble cstate->spo_must_allowed = true; 3396ed941643SAndrew Elble return true; 3397ed941643SAndrew Elble } 3398ed941643SAndrew Elble } 3399ed941643SAndrew Elble cstate->spo_must_allowed = false; 3400ed941643SAndrew Elble return false; 3401ed941643SAndrew Elble } 3402ed941643SAndrew Elble 34034f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 34044f0cefbfSJ. Bruce Fields { 340505b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 34064f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 34072282cd2cSKinglong Mee 34082282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 34092282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 34104f0cefbfSJ. Bruce Fields } 34114f0cefbfSJ. Bruce Fields 341207d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 341307d1f802SJ. Bruce Fields { 341407d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 34153a237b4aSChuck Lever pr_err("unable to encode reply to nonidempotent op %u (%s)\n", 341607d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 341707d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 341807d1f802SJ. Bruce Fields } 341907d1f802SJ. Bruce Fields } 342007d1f802SJ. Bruce Fields 3421f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 3422b001a1b6SBenny Halevy { 3423b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 3424b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 3425b001a1b6SBenny Halevy return "unknown_operation"; 3426b001a1b6SBenny Halevy } 3427b001a1b6SBenny Halevy 3428860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 34290a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 3430f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 3431788f7183SChuck Lever .pc_decode = nfssvc_decode_voidarg, 3432788f7183SChuck Lever .pc_encode = nfssvc_encode_voidres, 3433788f7183SChuck Lever .pc_argsize = sizeof(struct nfsd_voidargs), 3434788f7183SChuck Lever .pc_ressize = sizeof(struct nfsd_voidres), 34350a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 34360a93a47fSYu Zhiguo .pc_xdrressize = 1, 34372289e87bSChuck Lever .pc_name = "NULL", 34380a93a47fSYu Zhiguo }, 34390a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 3440f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 3441026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 344263f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 34430a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 34440a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 34453e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 34460a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 34470a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 34482289e87bSChuck Lever .pc_name = "COMPOUND", 34490a93a47fSYu Zhiguo }, 34501da177e4SLinus Torvalds }; 34511da177e4SLinus Torvalds 34527fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 3453e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 34541da177e4SLinus Torvalds .vs_vers = 4, 34551da177e4SLinus Torvalds .vs_nproc = 2, 34561da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 34577fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 34581da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 34591da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 346005a45a2dSJeff Layton .vs_rpcb_optnl = true, 34615283b03eSJeff Layton .vs_need_cong_ctrl = true, 34621da177e4SLinus Torvalds }; 3463