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 */ 357e06b7f9SNeilBrown #include <linux/file.h> 36b0cb9085SAnna Schumaker #include <linux/falloc.h> 375a0e3ad6STejun Heo #include <linux/slab.h> 381da177e4SLinus Torvalds 3958e7b33aSMi Jinlong #include "idmap.h" 409a74af21SBoaz Harrosh #include "cache.h" 419a74af21SBoaz Harrosh #include "xdr4.h" 420a3adadeSJ. Bruce Fields #include "vfs.h" 438b70484cSTigran Mkrtchyan #include "current_stateid.h" 443320fef1SStanislav Kinsbursky #include "netns.h" 454ac7249eSChristoph Hellwig #include "acl.h" 469cf514ccSChristoph Hellwig #include "pnfs.h" 4731ef83dcSChristoph Hellwig #include "trace.h" 481da177e4SLinus Torvalds 4918032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 5018032ca0SDavid Quigley #include <linux/security.h> 5118032ca0SDavid Quigley 5218032ca0SDavid Quigley static inline void 5318032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 5418032ca0SDavid Quigley { 552b0143b5SDavid Howells struct inode *inode = d_inode(resfh->fh_dentry); 5618032ca0SDavid Quigley int status; 5718032ca0SDavid Quigley 585955102cSAl Viro inode_lock(inode); 5918032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 6018032ca0SDavid Quigley label->data, label->len); 615955102cSAl Viro inode_unlock(inode); 6218032ca0SDavid Quigley 6318032ca0SDavid Quigley if (status) 6418032ca0SDavid Quigley /* 6518032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 6618032ca0SDavid Quigley * already have created a new file, so it may be too 6718032ca0SDavid Quigley * late. For now this seems the least of evils: 6818032ca0SDavid Quigley */ 6918032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 7018032ca0SDavid Quigley 7118032ca0SDavid Quigley return; 7218032ca0SDavid Quigley } 7318032ca0SDavid Quigley #else 7418032ca0SDavid Quigley static inline void 7518032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7618032ca0SDavid Quigley { } 7718032ca0SDavid Quigley #endif 7818032ca0SDavid Quigley 791da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 801da177e4SLinus Torvalds 813c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 823c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 833c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 843c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 853c8e0316SYu Zhiguo }; 863c8e0316SYu Zhiguo 873c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 883c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 893c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 903c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 913c8e0316SYu Zhiguo }; 923c8e0316SYu Zhiguo 933c8e0316SYu Zhiguo static __be32 943c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 953c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 963c8e0316SYu Zhiguo { 973c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 9832ddd944SJ. Bruce Fields struct svc_export *exp = cstate->current_fh.fh_export; 993c8e0316SYu Zhiguo 100916d2d84SJ. Bruce Fields if (!nfsd_attrs_supported(cstate->minorversion, bmval)) 1013c8e0316SYu Zhiguo return nfserr_attrnotsupp; 102916d2d84SJ. Bruce Fields if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) 1033c8e0316SYu Zhiguo return nfserr_attrnotsupp; 10432ddd944SJ. Bruce Fields if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && 10532ddd944SJ. Bruce Fields !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) 10632ddd944SJ. Bruce Fields return nfserr_attrnotsupp; 107916d2d84SJ. Bruce Fields if (writable && !bmval_is_subset(bmval, writable)) 1083c8e0316SYu Zhiguo return nfserr_inval; 10947057abdSAndreas Gruenbacher if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && 11047057abdSAndreas Gruenbacher (bmval[1] & FATTR4_WORD1_MODE)) 11147057abdSAndreas Gruenbacher return nfserr_inval; 1123c8e0316SYu Zhiguo return nfs_ok; 1133c8e0316SYu Zhiguo } 1143c8e0316SYu Zhiguo 1153c8e0316SYu Zhiguo static __be32 1163c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1173c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1183c8e0316SYu Zhiguo { 1193c8e0316SYu Zhiguo __be32 status = nfs_ok; 1203c8e0316SYu Zhiguo 1213c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1223c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1233c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1243c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1253c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1263c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1273c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1283c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1293c8e0316SYu Zhiguo } 1303c8e0316SYu Zhiguo 1313c8e0316SYu Zhiguo return status; 1323c8e0316SYu Zhiguo } 1333c8e0316SYu Zhiguo 1349208faf2SYu Zhiguo static int 1359208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1369208faf2SYu Zhiguo { 1379208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1389208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1399208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1409208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1419208faf2SYu Zhiguo } 1429208faf2SYu Zhiguo 1439208faf2SYu Zhiguo /* 1449208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1459208faf2SYu Zhiguo * in the returned attr bitmap. 1469208faf2SYu Zhiguo */ 1479208faf2SYu Zhiguo static void 1489208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1499208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1509208faf2SYu Zhiguo { 1519208faf2SYu Zhiguo __be32 status; 1529208faf2SYu Zhiguo 1539208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1549208faf2SYu Zhiguo if (status) 1559208faf2SYu Zhiguo /* 1569208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1579208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1589208faf2SYu Zhiguo * So this seems the least of evils: 1599208faf2SYu Zhiguo */ 1609208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1619208faf2SYu Zhiguo } 1629208faf2SYu Zhiguo 1631da177e4SLinus Torvalds static inline void 1641da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1651da177e4SLinus Torvalds { 1661da177e4SLinus Torvalds fh_put(dst); 1671da177e4SLinus Torvalds dget(src->fh_dentry); 1681da177e4SLinus Torvalds if (src->fh_export) 169bf18f163SKinglong Mee exp_get(src->fh_export); 1701da177e4SLinus Torvalds *dst = *src; 1711da177e4SLinus Torvalds } 1721da177e4SLinus Torvalds 173b37ad28bSAl Viro static __be32 174dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1751da177e4SLinus Torvalds { 176b37ad28bSAl Viro __be32 status; 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds if (open->op_truncate && 1791da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1801da177e4SLinus Torvalds return nfserr_inval; 1811da177e4SLinus Torvalds 182a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 183a043226bSJ. Bruce Fields 1841da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 1858837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 1869801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 1878837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 18857ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 1898837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds return status; 1941da177e4SLinus Torvalds } 1951da177e4SLinus Torvalds 196aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 197aadab6c6SJ. Bruce Fields { 1982b0143b5SDavid Howells umode_t mode = d_inode(fh->fh_dentry)->i_mode; 199aadab6c6SJ. Bruce Fields 200aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 201aadab6c6SJ. Bruce Fields return nfs_ok; 202aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 203aadab6c6SJ. Bruce Fields return nfserr_isdir; 204aadab6c6SJ. Bruce Fields /* 205aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 206aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 207aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 208aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 209aadab6c6SJ. Bruce Fields * regular file. 210aadab6c6SJ. Bruce Fields */ 211aadab6c6SJ. Bruce Fields return nfserr_symlink; 212aadab6c6SJ. Bruce Fields } 213aadab6c6SJ. Bruce Fields 214bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2151da177e4SLinus Torvalds { 216bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 217bbc9c36cSJ. Bruce Fields return; 218bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 219bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 220bbc9c36cSJ. Bruce Fields } 221bbc9c36cSJ. Bruce Fields 222bbc9c36cSJ. Bruce Fields static __be32 223c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 224bbc9c36cSJ. Bruce Fields { 225bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 2267007c90fSNeil Brown int accmode; 227b37ad28bSAl Viro __be32 status; 2281da177e4SLinus Torvalds 229c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 230c0e6bee4SJ. Bruce Fields if (!*resfh) 23159deeb9eSJ. Bruce Fields return nfserr_jukebox; 232c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 2331da177e4SLinus Torvalds open->op_truncate = 0; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds if (open->op_create) { 23679fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 23779fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 23879fb54abSBenny Halevy * 23979fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 24079fb54abSBenny Halevy * Reply Cache | server | | 24179fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 24279fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 24379fb54abSBenny Halevy * | | | (SHOULD) 24479fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 24579fb54abSBenny Halevy * | | | (SHOULD NOT) 24679fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 24779fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 24879fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 24979fb54abSBenny Halevy */ 25079fb54abSBenny Halevy 2511da177e4SLinus Torvalds /* 2521da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 253ac6721a1SMi Jinlong * in NFSv4 as in v3 except EXCLUSIVE4_1. 2541da177e4SLinus Torvalds */ 255ac6721a1SMi Jinlong status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, 2561da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 257c0e6bee4SJ. Bruce Fields *resfh, open->op_createmode, 258749997e5SJeff Layton (u32 *)open->op_verf.data, 259856121b2SJ. Bruce Fields &open->op_truncate, &open->op_created); 260749997e5SJeff Layton 26118032ca0SDavid Quigley if (!status && open->op_label.len) 262c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 26318032ca0SDavid Quigley 26499f88726SJ. Bruce Fields /* 265ead8fb8cSKinglong Mee * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 266ead8fb8cSKinglong Mee * use the returned bitmask to indicate which attributes 267ead8fb8cSKinglong Mee * we used to store the verifier: 268749997e5SJeff Layton */ 269ead8fb8cSKinglong Mee if (nfsd_create_is_exclusive(open->op_createmode) && status == 0) 270ead8fb8cSKinglong Mee open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | 271749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 2724335723eSJ. Bruce Fields } else 2734335723eSJ. Bruce Fields /* 2744335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 2754335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 2764335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 2774335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 2784335723eSJ. Bruce Fields */ 2791da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 280c0e6bee4SJ. Bruce Fields open->op_fname.data, open->op_fname.len, *resfh); 281aadab6c6SJ. Bruce Fields if (status) 282aadab6c6SJ. Bruce Fields goto out; 283c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 284af85852dSJ. Bruce Fields if (status) 285af85852dSJ. Bruce Fields goto out; 2861da177e4SLinus Torvalds 2879208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 288c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 2899208faf2SYu Zhiguo 290c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 2917007c90fSNeil Brown accmode = NFSD_MAY_NOP; 29289f6c336SJ. Bruce Fields if (open->op_created || 29389f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 2947007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 295c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 29641fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 297af85852dSJ. Bruce Fields out: 2981da177e4SLinus Torvalds return status; 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 301b37ad28bSAl Viro static __be32 302bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 3031da177e4SLinus Torvalds { 304bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 305b37ad28bSAl Viro __be32 status; 3069f415eb2SJ. Bruce Fields int accmode = 0; 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 3091da177e4SLinus Torvalds * set the change info 3101da177e4SLinus Torvalds */ 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 3131da177e4SLinus Torvalds 314bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 3171da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 3189f415eb2SJ. Bruce Fields /* 3199f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 3209f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 3219f415eb2SJ. Bruce Fields * should let it succeed now if possible. 3229f415eb2SJ. Bruce Fields * 3239f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 3249f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 3259f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 3269f415eb2SJ. Bruce Fields */ 3279f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 3289f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 3291da177e4SLinus Torvalds 3309f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvalds return status; 3331da177e4SLinus Torvalds } 3341da177e4SLinus Torvalds 33560adfc50SAndy Adamson static void 33660adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 33760adfc50SAndy Adamson { 33860adfc50SAndy Adamson struct nfsd4_sessionid *sid = 33960adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 34060adfc50SAndy Adamson 34160adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 34260adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 34360adfc50SAndy Adamson } 3441da177e4SLinus Torvalds 3457191155bSJ.Bruce Fields static __be32 346ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 347a4f1706aSJ.Bruce Fields struct nfsd4_open *open) 3481da177e4SLinus Torvalds { 349b37ad28bSAl Viro __be32 status; 350c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 3513320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 3523320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 3536668958fSAndy Adamson 354fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 3551da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 356fe0750e5SJ. Bruce Fields open->op_openowner); 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds /* This check required by spec. */ 3591da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 3601da177e4SLinus Torvalds return nfserr_inval; 3611da177e4SLinus Torvalds 362856121b2SJ. Bruce Fields open->op_created = 0; 363ab1350b2SMi Jinlong /* 364ab1350b2SMi Jinlong * RFC5661 18.51.3 365ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 366ab1350b2SMi Jinlong */ 367ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 368a52d726bSJeff Layton !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, 369a52d726bSJeff Layton &cstate->session->se_client->cl_flags) && 370ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 371ab1350b2SMi Jinlong return nfserr_grace; 372ab1350b2SMi Jinlong 37360adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 37460adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 37560adfc50SAndy Adamson 3761da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 3776cd22668SKinglong Mee status = nfsd4_process_open1(cstate, open, nn); 378a90b061cSAl Viro if (status == nfserr_replay_me) { 379fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 380ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 381a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 382a4773c08SJ. Bruce Fields &rp->rp_openfh); 3838837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 3841da177e4SLinus Torvalds if (status) 3851da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 3861da177e4SLinus Torvalds " restoring previous filehandle\n"); 3871da177e4SLinus Torvalds else 388a90b061cSAl Viro status = nfserr_replay_me; 3891da177e4SLinus Torvalds } 3901da177e4SLinus Torvalds if (status) 3911da177e4SLinus Torvalds goto out; 3929d313b17SJ. Bruce Fields if (open->op_xdr_error) { 3939d313b17SJ. Bruce Fields status = open->op_xdr_error; 3949d313b17SJ. Bruce Fields goto out; 3959d313b17SJ. Bruce Fields } 396fb553c0fSJ. Bruce Fields 3973c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 3983c8e0316SYu Zhiguo if (status) 3993c8e0316SYu Zhiguo goto out; 4003c8e0316SYu Zhiguo 401fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 402fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 403cbd0d51aSJ. Bruce Fields status = nfserr_grace; 404c87fb4a3SJ. Bruce Fields if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 405cbd0d51aSJ. Bruce Fields goto out; 406cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 407c87fb4a3SJ. Bruce Fields if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 408cbd0d51aSJ. Bruce Fields goto out; 409fb553c0fSJ. Bruce Fields 4101da177e4SLinus Torvalds switch (open->op_claim_type) { 4110dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 4121da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 413c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 4141da177e4SLinus Torvalds if (status) 4151da177e4SLinus Torvalds goto out; 4161da177e4SLinus Torvalds break; 4171da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 4183320fef1SStanislav Kinsbursky status = nfs4_check_open_reclaim(&open->op_clientid, 4190fe492dbSTrond Myklebust cstate, nn); 4200cf99b91SMi Jinlong if (status) 4210cf99b91SMi Jinlong goto out; 422ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 4238b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 4248b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 425bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 4261da177e4SLinus Torvalds if (status) 4271da177e4SLinus Torvalds goto out; 428c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 4291da177e4SLinus Torvalds break; 4308b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 4311da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 4322fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 4331da177e4SLinus Torvalds open->op_claim_type); 4341da177e4SLinus Torvalds status = nfserr_notsupp; 4351da177e4SLinus Torvalds goto out; 4361da177e4SLinus Torvalds default: 4372fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 4381da177e4SLinus Torvalds open->op_claim_type); 4391da177e4SLinus Torvalds status = nfserr_inval; 4401da177e4SLinus Torvalds goto out; 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds /* 4431da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 4441da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 4451da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 4461da177e4SLinus Torvalds */ 447c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 448b3fbfe0eSJeff Layton WARN(status && open->op_created, 449b3fbfe0eSJeff Layton "nfsd4_process_open2 failed to open newly-created file! status=%u\n", 450b3fbfe0eSJeff Layton be32_to_cpu(status)); 4511da177e4SLinus Torvalds out: 452c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 453c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 454c0e6bee4SJ. Bruce Fields fh_put(resfh); 455c0e6bee4SJ. Bruce Fields kfree(resfh); 456c0e6bee4SJ. Bruce Fields } 45742297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 4589411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 4591da177e4SLinus Torvalds return status; 4601da177e4SLinus Torvalds } 4611da177e4SLinus Torvalds 4621da177e4SLinus Torvalds /* 4639d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 4649d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 4659d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 4669d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 4679d313b17SJ. Bruce Fields */ 4689d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 4699d313b17SJ. Bruce Fields { 4709d313b17SJ. Bruce Fields struct nfsd4_open *open = (struct nfsd4_open *)&op->u; 4719d313b17SJ. Bruce Fields 4729d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 4739d313b17SJ. Bruce Fields return op->status; 4749d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 4759d313b17SJ. Bruce Fields return op->status; 4769d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 4779d313b17SJ. Bruce Fields return nfsd4_open(rqstp, cstate, open); 4789d313b17SJ. Bruce Fields } 4799d313b17SJ. Bruce Fields 4809d313b17SJ. Bruce Fields /* 4811da177e4SLinus Torvalds * filehandle-manipulating ops. 4821da177e4SLinus Torvalds */ 4837191155bSJ.Bruce Fields static __be32 484b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 485b591480bSJ.Bruce Fields struct svc_fh **getfh) 4861da177e4SLinus Torvalds { 487ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 4881da177e4SLinus Torvalds return nfserr_nofilehandle; 4891da177e4SLinus Torvalds 490ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 4911da177e4SLinus Torvalds return nfs_ok; 4921da177e4SLinus Torvalds } 4931da177e4SLinus Torvalds 4947191155bSJ.Bruce Fields static __be32 495ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 496ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 4971da177e4SLinus Torvalds { 498ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 499ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 500ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 501ca364317SJ.Bruce Fields putfh->pf_fhlen); 50268d93184SJ. Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 5031da177e4SLinus Torvalds } 5041da177e4SLinus Torvalds 5057191155bSJ.Bruce Fields static __be32 506b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 507b591480bSJ.Bruce Fields void *arg) 5081da177e4SLinus Torvalds { 509b37ad28bSAl Viro __be32 status; 5101da177e4SLinus Torvalds 511ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 512df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 5131da177e4SLinus Torvalds return status; 5141da177e4SLinus Torvalds } 5151da177e4SLinus Torvalds 5167191155bSJ.Bruce Fields static __be32 517b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 518b591480bSJ.Bruce Fields void *arg) 5191da177e4SLinus Torvalds { 520ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5211da177e4SLinus Torvalds return nfserr_restorefh; 5221da177e4SLinus Torvalds 523ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 52437c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { 52537c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 52637c593c5STigran Mkrtchyan SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); 52737c593c5STigran Mkrtchyan } 5281da177e4SLinus Torvalds return nfs_ok; 5291da177e4SLinus Torvalds } 5301da177e4SLinus Torvalds 5317191155bSJ.Bruce Fields static __be32 532b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 533b591480bSJ.Bruce Fields void *arg) 5341da177e4SLinus Torvalds { 535ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 5361da177e4SLinus Torvalds return nfserr_nofilehandle; 5371da177e4SLinus Torvalds 538ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 53937c593c5STigran Mkrtchyan if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { 54037c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 54137c593c5STigran Mkrtchyan SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); 54237c593c5STigran Mkrtchyan } 5431da177e4SLinus Torvalds return nfs_ok; 5441da177e4SLinus Torvalds } 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds /* 5471da177e4SLinus Torvalds * misc nfsv4 ops 5481da177e4SLinus Torvalds */ 5497191155bSJ.Bruce Fields static __be32 550ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 551ca364317SJ.Bruce Fields struct nfsd4_access *access) 5521da177e4SLinus Torvalds { 5531da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 5541da177e4SLinus Torvalds return nfserr_inval; 5551da177e4SLinus Torvalds 5561da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 557ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 558ca364317SJ.Bruce Fields &access->ac_supported); 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds 561b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 562ab4684d1SChuck Lever { 563ab4684d1SChuck Lever __be32 verf[2]; 564b9c0ef85SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 565ab4684d1SChuck Lever 566f419992cSJeff Layton /* 567f419992cSJeff Layton * This is opaque to client, so no need to byte-swap. Use 568f419992cSJeff Layton * __force to keep sparse happy 569f419992cSJeff Layton */ 570f419992cSJeff Layton verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; 571f419992cSJeff Layton verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec; 572ab4684d1SChuck Lever memcpy(verifier->data, verf, sizeof(verifier->data)); 573ab4684d1SChuck Lever } 574ab4684d1SChuck Lever 5757191155bSJ.Bruce Fields static __be32 576ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 577ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 5781da177e4SLinus Torvalds { 579b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); 58075c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 581ca364317SJ.Bruce Fields commit->co_count); 5821da177e4SLinus Torvalds } 5831da177e4SLinus Torvalds 584b37ad28bSAl Viro static __be32 585ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 586ca364317SJ.Bruce Fields struct nfsd4_create *create) 5871da177e4SLinus Torvalds { 5881da177e4SLinus Torvalds struct svc_fh resfh; 589b37ad28bSAl Viro __be32 status; 5901da177e4SLinus Torvalds dev_t rdev; 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 5931da177e4SLinus Torvalds 594fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 5951da177e4SLinus Torvalds if (status) 5961da177e4SLinus Torvalds return status; 5971da177e4SLinus Torvalds 5983c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 5993c8e0316SYu Zhiguo nfsd_attrmask); 6003c8e0316SYu Zhiguo if (status) 6013c8e0316SYu Zhiguo return status; 6023c8e0316SYu Zhiguo 6031da177e4SLinus Torvalds switch (create->cr_type) { 6041da177e4SLinus Torvalds case NF4LNK: 605ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 606ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 6071e444f5bSKinglong Mee create->cr_data, &resfh); 6081da177e4SLinus Torvalds break; 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds case NF4BLK: 6111da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6121da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6131da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6141da177e4SLinus Torvalds return nfserr_inval; 615ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 616ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 617ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 6181da177e4SLinus Torvalds break; 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds case NF4CHR: 6211da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 6221da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 6231da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 6241da177e4SLinus Torvalds return nfserr_inval; 625ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 626ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 627ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 6281da177e4SLinus Torvalds break; 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds case NF4SOCK: 631ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 632ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 633ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 6341da177e4SLinus Torvalds break; 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvalds case NF4FIFO: 637ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 638ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 639ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 6401da177e4SLinus Torvalds break; 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds case NF4DIR: 6431da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 644ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 645ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 646ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 6471da177e4SLinus Torvalds break; 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvalds default: 6501da177e4SLinus Torvalds status = nfserr_badtype; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds 6539208faf2SYu Zhiguo if (status) 6549208faf2SYu Zhiguo goto out; 6559208faf2SYu Zhiguo 65618032ca0SDavid Quigley if (create->cr_label.len) 65718032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 65818032ca0SDavid Quigley 6599208faf2SYu Zhiguo if (create->cr_acl != NULL) 6609208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 6619208faf2SYu Zhiguo create->cr_bmval); 6629208faf2SYu Zhiguo 663ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 664ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 665ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 6669208faf2SYu Zhiguo out: 6671da177e4SLinus Torvalds fh_put(&resfh); 6681da177e4SLinus Torvalds return status; 6691da177e4SLinus Torvalds } 6701da177e4SLinus Torvalds 6717191155bSJ.Bruce Fields static __be32 672ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 673ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 6741da177e4SLinus Torvalds { 675b37ad28bSAl Viro __be32 status; 6761da177e4SLinus Torvalds 6778837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 6781da177e4SLinus Torvalds if (status) 6791da177e4SLinus Torvalds return status; 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 6821da177e4SLinus Torvalds return nfserr_inval; 6831da177e4SLinus Torvalds 684916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 685916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 686916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 6871da177e4SLinus Torvalds 688ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 6891da177e4SLinus Torvalds return nfs_ok; 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 6927191155bSJ.Bruce Fields static __be32 693ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 694ca364317SJ.Bruce Fields struct nfsd4_link *link) 6951da177e4SLinus Torvalds { 696b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 6971da177e4SLinus Torvalds 698ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 6991da177e4SLinus Torvalds return status; 700ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 701ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 7021da177e4SLinus Torvalds if (!status) 703ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 7041da177e4SLinus Torvalds return status; 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds 7070ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 7081da177e4SLinus Torvalds { 7091da177e4SLinus Torvalds struct svc_fh tmp_fh; 710b37ad28bSAl Viro __be32 ret; 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 713df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 714df547efbSJ. Bruce Fields if (ret) 7151da177e4SLinus Torvalds return ret; 7160ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 7171da177e4SLinus Torvalds fh_put(&tmp_fh); 7181da177e4SLinus Torvalds return nfserr_noent; 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds fh_put(&tmp_fh); 7210ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 7220ff7ab46SJ. Bruce Fields } 7230ff7ab46SJ. Bruce Fields 7240ff7ab46SJ. Bruce Fields static __be32 7250ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 7260ff7ab46SJ. Bruce Fields void *arg) 7270ff7ab46SJ. Bruce Fields { 7280ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 7291da177e4SLinus Torvalds } 7301da177e4SLinus Torvalds 7317191155bSJ.Bruce Fields static __be32 732ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 733ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 7341da177e4SLinus Torvalds { 735ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 736ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 737ca364317SJ.Bruce Fields &cstate->current_fh); 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds 7407191155bSJ.Bruce Fields static __be32 741ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 742ca364317SJ.Bruce Fields struct nfsd4_read *read) 7431da177e4SLinus Torvalds { 744b37ad28bSAl Viro __be32 status; 7451da177e4SLinus Torvalds 7467e06b7f9SNeilBrown read->rd_filp = NULL; 7471da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 7481da177e4SLinus Torvalds return nfserr_inval; 7491da177e4SLinus Torvalds 7509b3234b9SJ. Bruce Fields /* 7519b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 7529b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 7539b3234b9SJ. Bruce Fields * following compound. 7549b3234b9SJ. Bruce Fields * 7559b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 7569b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 7579b3234b9SJ. Bruce Fields */ 7589b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 759779fb0f3SJeff Layton clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 7609b3234b9SJ. Bruce Fields 7611da177e4SLinus Torvalds /* check stateid */ 762aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 763aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 764aa0d6aedSAnna Schumaker &read->rd_filp, &read->rd_tmp_file); 765af90f707SChristoph Hellwig if (status) { 7661da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 7671da177e4SLinus Torvalds goto out; 7681da177e4SLinus Torvalds } 7691da177e4SLinus Torvalds status = nfs_ok; 7701da177e4SLinus Torvalds out: 7711da177e4SLinus Torvalds read->rd_rqstp = rqstp; 772ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 7731da177e4SLinus Torvalds return status; 7741da177e4SLinus Torvalds } 7751da177e4SLinus Torvalds 7767191155bSJ.Bruce Fields static __be32 777ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 778ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 7791da177e4SLinus Torvalds { 7801da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 7811da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 7821da177e4SLinus Torvalds 7831da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 7861da177e4SLinus Torvalds return nfserr_inval; 7871da177e4SLinus Torvalds 788916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 789916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 790916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 7911da177e4SLinus Torvalds 792832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 7931da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 7941da177e4SLinus Torvalds return nfserr_bad_cookie; 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 797ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 7981da177e4SLinus Torvalds return nfs_ok; 7991da177e4SLinus Torvalds } 8001da177e4SLinus Torvalds 8017191155bSJ.Bruce Fields static __be32 802ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 803ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 8041da177e4SLinus Torvalds { 8051da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 806ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 8071da177e4SLinus Torvalds return nfs_ok; 8081da177e4SLinus Torvalds } 8091da177e4SLinus Torvalds 8107191155bSJ.Bruce Fields static __be32 811ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 812ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 8131da177e4SLinus Torvalds { 814b37ad28bSAl Viro __be32 status; 8151da177e4SLinus Torvalds 816c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 817c815afc7SNeilBrown return nfserr_grace; 818ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 819ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 8201da177e4SLinus Torvalds if (!status) { 821ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 822ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 8231da177e4SLinus Torvalds } 8241da177e4SLinus Torvalds return status; 8251da177e4SLinus Torvalds } 8261da177e4SLinus Torvalds 8277191155bSJ.Bruce Fields static __be32 828ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 829ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 8301da177e4SLinus Torvalds { 831b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 8321da177e4SLinus Torvalds 833ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 8341da177e4SLinus Torvalds return status; 835c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp)) && 8365ccb0066SStanislav Kinsbursky !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) 837c815afc7SNeilBrown return nfserr_grace; 838ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 839ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 8401da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 8412a6cf944SJ. Bruce Fields if (status) 8422a6cf944SJ. Bruce Fields return status; 843ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 844ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 8452a6cf944SJ. Bruce Fields return nfs_ok; 8461da177e4SLinus Torvalds } 8471da177e4SLinus Torvalds 8487191155bSJ.Bruce Fields static __be32 849dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 850dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 851dcb488a3SAndy Adamson { 852dcb488a3SAndy Adamson struct svc_export *exp; 853dcb488a3SAndy Adamson struct dentry *dentry; 854dcb488a3SAndy Adamson __be32 err; 855dcb488a3SAndy Adamson 85629a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 85729a78a3eSJ. Bruce Fields if (err) 85829a78a3eSJ. Bruce Fields return err; 859dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 860dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 861dcb488a3SAndy Adamson &exp, &dentry); 862dcb488a3SAndy Adamson if (err) 863dcb488a3SAndy Adamson return err; 8642f6fc056SJ. Bruce Fields fh_unlock(&cstate->current_fh); 8652b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 866dcb488a3SAndy Adamson exp_put(exp); 867dcb488a3SAndy Adamson err = nfserr_noent; 868dcb488a3SAndy Adamson } else 869dcb488a3SAndy Adamson secinfo->si_exp = exp; 870dcb488a3SAndy Adamson dput(dentry); 87156560b9aSJ. Bruce Fields if (cstate->minorversion) 87256560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 87356560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 874dcb488a3SAndy Adamson return err; 875dcb488a3SAndy Adamson } 876dcb488a3SAndy Adamson 877dcb488a3SAndy Adamson static __be32 87804f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 87904f4ad16SJ. Bruce Fields struct nfsd4_secinfo_no_name *sin) 88004f4ad16SJ. Bruce Fields { 88104f4ad16SJ. Bruce Fields __be32 err; 88204f4ad16SJ. Bruce Fields 88304f4ad16SJ. Bruce Fields switch (sin->sin_style) { 88404f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 88504f4ad16SJ. Bruce Fields break; 88604f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 88704f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 88804f4ad16SJ. Bruce Fields if (err) 88904f4ad16SJ. Bruce Fields return err; 89004f4ad16SJ. Bruce Fields break; 89104f4ad16SJ. Bruce Fields default: 89204f4ad16SJ. Bruce Fields return nfserr_inval; 89304f4ad16SJ. Bruce Fields } 894bf18f163SKinglong Mee 895bf18f163SKinglong Mee sin->sin_exp = exp_get(cstate->current_fh.fh_export); 89604f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 89704f4ad16SJ. Bruce Fields return nfs_ok; 89804f4ad16SJ. Bruce Fields } 89904f4ad16SJ. Bruce Fields 90004f4ad16SJ. Bruce Fields static __be32 901ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 902ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 9031da177e4SLinus Torvalds { 904b37ad28bSAl Viro __be32 status = nfs_ok; 90596f6f985SAl Viro int err; 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 908af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 909aa0d6aedSAnna Schumaker &cstate->current_fh, &setattr->sa_stateid, 910aa0d6aedSAnna Schumaker WR_STATE, NULL, NULL); 911375c5547SJ. Bruce Fields if (status) { 9123e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 913375c5547SJ. Bruce Fields return status; 914375c5547SJ. Bruce Fields } 9151da177e4SLinus Torvalds } 91696f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 91796f6f985SAl Viro if (err) 91896f6f985SAl Viro return nfserrno(err); 9191da177e4SLinus Torvalds status = nfs_ok; 9203c8e0316SYu Zhiguo 9213c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 9223c8e0316SYu Zhiguo nfsd_attrmask); 9233c8e0316SYu Zhiguo if (status) 9243c8e0316SYu Zhiguo goto out; 9253c8e0316SYu Zhiguo 9261da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 927ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 928ca364317SJ.Bruce Fields setattr->sa_acl); 9291da177e4SLinus Torvalds if (status) 93018f335afSDave Hansen goto out; 93118032ca0SDavid Quigley if (setattr->sa_label.len) 93218032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 93318032ca0SDavid Quigley &setattr->sa_label); 93418032ca0SDavid Quigley if (status) 93518032ca0SDavid Quigley goto out; 936ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 9371da177e4SLinus Torvalds 0, (time_t)0); 93818f335afSDave Hansen out: 939bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 9401da177e4SLinus Torvalds return status; 9411da177e4SLinus Torvalds } 9421da177e4SLinus Torvalds 943ffe1137bSJ. Bruce Fields static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write) 944ffe1137bSJ. Bruce Fields { 945ffe1137bSJ. Bruce Fields int i = 1; 946ffe1137bSJ. Bruce Fields int buflen = write->wr_buflen; 947ffe1137bSJ. Bruce Fields 948ffe1137bSJ. Bruce Fields vec[0].iov_base = write->wr_head.iov_base; 949ffe1137bSJ. Bruce Fields vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len); 950ffe1137bSJ. Bruce Fields buflen -= vec[0].iov_len; 951ffe1137bSJ. Bruce Fields 952ffe1137bSJ. Bruce Fields while (buflen) { 953ffe1137bSJ. Bruce Fields vec[i].iov_base = page_address(write->wr_pagelist[i - 1]); 954ffe1137bSJ. Bruce Fields vec[i].iov_len = min_t(int, PAGE_SIZE, buflen); 955ffe1137bSJ. Bruce Fields buflen -= vec[i].iov_len; 956ffe1137bSJ. Bruce Fields i++; 957ffe1137bSJ. Bruce Fields } 958ffe1137bSJ. Bruce Fields return i; 959ffe1137bSJ. Bruce Fields } 960ffe1137bSJ. Bruce Fields 9617191155bSJ.Bruce Fields static __be32 962ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 963ca364317SJ.Bruce Fields struct nfsd4_write *write) 9641da177e4SLinus Torvalds { 9651da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 9661da177e4SLinus Torvalds struct file *filp = NULL; 967b37ad28bSAl Viro __be32 status = nfs_ok; 96831dec253SDavid Shaw unsigned long cnt; 969ffe1137bSJ. Bruce Fields int nvecs; 9701da177e4SLinus Torvalds 9711da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 9721da177e4SLinus Torvalds return nfserr_inval; 9731da177e4SLinus Torvalds 974aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 975aa0d6aedSAnna Schumaker stateid, WR_STATE, &filp, NULL); 976375c5547SJ. Bruce Fields if (status) { 977375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 978375c5547SJ. Bruce Fields return status; 979375c5547SJ. Bruce Fields } 980375c5547SJ. Bruce Fields 98131dec253SDavid Shaw cnt = write->wr_buflen; 9821da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 983b9c0ef85SStanislav Kinsbursky gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); 9841da177e4SLinus Torvalds 985ffe1137bSJ. Bruce Fields nvecs = fill_in_write_vector(rqstp->rq_vec, write); 986ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 987ffe1137bSJ. Bruce Fields 988af90f707SChristoph Hellwig status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp, 989af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 99054bbb7d2SKinglong Mee write->wr_how_written); 9917e06b7f9SNeilBrown fput(filp); 9921da177e4SLinus Torvalds 99331dec253SDavid Shaw write->wr_bytes_written = cnt; 99431dec253SDavid Shaw 9951da177e4SLinus Torvalds return status; 9961da177e4SLinus Torvalds } 9971da177e4SLinus Torvalds 99824bab491SAnna Schumaker static __be32 99929ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 100029ae7f9dSAnna Schumaker stateid_t *src_stateid, struct file **src, 100129ae7f9dSAnna Schumaker stateid_t *dst_stateid, struct file **dst) 1002ffa0160aSChristoph Hellwig { 1003ffa0160aSChristoph Hellwig __be32 status; 1004ffa0160aSChristoph Hellwig 1005ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 100629ae7f9dSAnna Schumaker src_stateid, RD_STATE, src, NULL); 1007ffa0160aSChristoph Hellwig if (status) { 1008ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1009ffa0160aSChristoph Hellwig goto out; 1010ffa0160aSChristoph Hellwig } 1011ffa0160aSChristoph Hellwig 1012ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 101329ae7f9dSAnna Schumaker dst_stateid, WR_STATE, dst, NULL); 1014ffa0160aSChristoph Hellwig if (status) { 1015ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1016ffa0160aSChristoph Hellwig goto out_put_src; 1017ffa0160aSChristoph Hellwig } 1018ffa0160aSChristoph Hellwig 1019ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 102029ae7f9dSAnna Schumaker if (!S_ISREG(file_inode(*src)->i_mode) || 102129ae7f9dSAnna Schumaker !S_ISREG(file_inode(*dst)->i_mode)) { 1022ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1023ffa0160aSChristoph Hellwig goto out_put_dst; 1024ffa0160aSChristoph Hellwig } 1025ffa0160aSChristoph Hellwig 102629ae7f9dSAnna Schumaker out: 102729ae7f9dSAnna Schumaker return status; 102829ae7f9dSAnna Schumaker out_put_dst: 102929ae7f9dSAnna Schumaker fput(*dst); 103029ae7f9dSAnna Schumaker out_put_src: 103129ae7f9dSAnna Schumaker fput(*src); 103229ae7f9dSAnna Schumaker goto out; 103329ae7f9dSAnna Schumaker } 103429ae7f9dSAnna Schumaker 103529ae7f9dSAnna Schumaker static __be32 103629ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 103729ae7f9dSAnna Schumaker struct nfsd4_clone *clone) 103829ae7f9dSAnna Schumaker { 103929ae7f9dSAnna Schumaker struct file *src, *dst; 104029ae7f9dSAnna Schumaker __be32 status; 104129ae7f9dSAnna Schumaker 104229ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 104329ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 104429ae7f9dSAnna Schumaker if (status) 104529ae7f9dSAnna Schumaker goto out; 104629ae7f9dSAnna Schumaker 1047ffa0160aSChristoph Hellwig status = nfsd4_clone_file_range(src, clone->cl_src_pos, 1048ffa0160aSChristoph Hellwig dst, clone->cl_dst_pos, clone->cl_count); 1049ffa0160aSChristoph Hellwig 1050ffa0160aSChristoph Hellwig fput(dst); 1051ffa0160aSChristoph Hellwig fput(src); 1052ffa0160aSChristoph Hellwig out: 1053ffa0160aSChristoph Hellwig return status; 1054ffa0160aSChristoph Hellwig } 1055ffa0160aSChristoph Hellwig 1056ffa0160aSChristoph Hellwig static __be32 105729ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 105829ae7f9dSAnna Schumaker struct nfsd4_copy *copy) 105929ae7f9dSAnna Schumaker { 106029ae7f9dSAnna Schumaker struct file *src, *dst; 106129ae7f9dSAnna Schumaker __be32 status; 106229ae7f9dSAnna Schumaker ssize_t bytes; 106329ae7f9dSAnna Schumaker 106429ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, &src, 106529ae7f9dSAnna Schumaker ©->cp_dst_stateid, &dst); 106629ae7f9dSAnna Schumaker if (status) 106729ae7f9dSAnna Schumaker goto out; 106829ae7f9dSAnna Schumaker 106929ae7f9dSAnna Schumaker bytes = nfsd_copy_file_range(src, copy->cp_src_pos, 107029ae7f9dSAnna Schumaker dst, copy->cp_dst_pos, copy->cp_count); 107129ae7f9dSAnna Schumaker 107229ae7f9dSAnna Schumaker if (bytes < 0) 107329ae7f9dSAnna Schumaker status = nfserrno(bytes); 107429ae7f9dSAnna Schumaker else { 107529ae7f9dSAnna Schumaker copy->cp_res.wr_bytes_written = bytes; 107629ae7f9dSAnna Schumaker copy->cp_res.wr_stable_how = NFS_UNSTABLE; 107729ae7f9dSAnna Schumaker copy->cp_consecutive = 1; 107829ae7f9dSAnna Schumaker copy->cp_synchronous = 1; 107929ae7f9dSAnna Schumaker gen_boot_verifier(©->cp_res.wr_verifier, SVC_NET(rqstp)); 108029ae7f9dSAnna Schumaker status = nfs_ok; 108129ae7f9dSAnna Schumaker } 108229ae7f9dSAnna Schumaker 108329ae7f9dSAnna Schumaker fput(src); 108429ae7f9dSAnna Schumaker fput(dst); 108529ae7f9dSAnna Schumaker out: 108629ae7f9dSAnna Schumaker return status; 108729ae7f9dSAnna Schumaker } 108829ae7f9dSAnna Schumaker 108929ae7f9dSAnna Schumaker static __be32 109095d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 109195d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 109295d871f0SAnna Schumaker { 109395d871f0SAnna Schumaker __be32 status = nfserr_notsupp; 109495d871f0SAnna Schumaker struct file *file; 109595d871f0SAnna Schumaker 1096aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 109795d871f0SAnna Schumaker &fallocate->falloc_stateid, 1098af90f707SChristoph Hellwig WR_STATE, &file, NULL); 109995d871f0SAnna Schumaker if (status != nfs_ok) { 110095d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 110195d871f0SAnna Schumaker return status; 110295d871f0SAnna Schumaker } 110395d871f0SAnna Schumaker 110495d871f0SAnna Schumaker status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, 110595d871f0SAnna Schumaker fallocate->falloc_offset, 110695d871f0SAnna Schumaker fallocate->falloc_length, 110795d871f0SAnna Schumaker flags); 110895d871f0SAnna Schumaker fput(file); 110995d871f0SAnna Schumaker return status; 111095d871f0SAnna Schumaker } 111195d871f0SAnna Schumaker 111295d871f0SAnna Schumaker static __be32 111395d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 111495d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate) 111595d871f0SAnna Schumaker { 111695d871f0SAnna Schumaker return nfsd4_fallocate(rqstp, cstate, fallocate, 0); 111795d871f0SAnna Schumaker } 111895d871f0SAnna Schumaker 111995d871f0SAnna Schumaker static __be32 1120b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1121b0cb9085SAnna Schumaker struct nfsd4_fallocate *fallocate) 1122b0cb9085SAnna Schumaker { 1123b0cb9085SAnna Schumaker return nfsd4_fallocate(rqstp, cstate, fallocate, 1124b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 1125b0cb9085SAnna Schumaker } 1126b0cb9085SAnna Schumaker 1127b0cb9085SAnna Schumaker static __be32 112824bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 112924bab491SAnna Schumaker struct nfsd4_seek *seek) 113024bab491SAnna Schumaker { 113124bab491SAnna Schumaker int whence; 113224bab491SAnna Schumaker __be32 status; 113324bab491SAnna Schumaker struct file *file; 113424bab491SAnna Schumaker 1135aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 113624bab491SAnna Schumaker &seek->seek_stateid, 1137af90f707SChristoph Hellwig RD_STATE, &file, NULL); 113824bab491SAnna Schumaker if (status) { 113924bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 114024bab491SAnna Schumaker return status; 114124bab491SAnna Schumaker } 114224bab491SAnna Schumaker 114324bab491SAnna Schumaker switch (seek->seek_whence) { 114424bab491SAnna Schumaker case NFS4_CONTENT_DATA: 114524bab491SAnna Schumaker whence = SEEK_DATA; 114624bab491SAnna Schumaker break; 114724bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 114824bab491SAnna Schumaker whence = SEEK_HOLE; 114924bab491SAnna Schumaker break; 115024bab491SAnna Schumaker default: 115124bab491SAnna Schumaker status = nfserr_union_notsupp; 115224bab491SAnna Schumaker goto out; 115324bab491SAnna Schumaker } 115424bab491SAnna Schumaker 115524bab491SAnna Schumaker /* 115624bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 115724bab491SAnna Schumaker * should ever file->f_pos. 115824bab491SAnna Schumaker */ 115924bab491SAnna Schumaker seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence); 116024bab491SAnna Schumaker if (seek->seek_pos < 0) 116124bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 116224bab491SAnna Schumaker else if (seek->seek_pos >= i_size_read(file_inode(file))) 116324bab491SAnna Schumaker seek->seek_eof = true; 116424bab491SAnna Schumaker 116524bab491SAnna Schumaker out: 116624bab491SAnna Schumaker fput(file); 116724bab491SAnna Schumaker return status; 116824bab491SAnna Schumaker } 116924bab491SAnna Schumaker 11701da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 11711da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 11721da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 11731da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 11741da177e4SLinus Torvalds */ 1175b37ad28bSAl Viro static __be32 1176c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1177ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 11781da177e4SLinus Torvalds { 11792ebbc012SAl Viro __be32 *buf, *p; 11801da177e4SLinus Torvalds int count; 1181b37ad28bSAl Viro __be32 status; 11821da177e4SLinus Torvalds 11838837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 11841da177e4SLinus Torvalds if (status) 11851da177e4SLinus Torvalds return status; 11861da177e4SLinus Torvalds 11873c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 11883c8e0316SYu Zhiguo if (status) 11893c8e0316SYu Zhiguo return status; 11903c8e0316SYu Zhiguo 11911da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 11921da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 11931da177e4SLinus Torvalds return nfserr_inval; 11941da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 11951da177e4SLinus Torvalds return nfserr_inval; 11961da177e4SLinus Torvalds 11971da177e4SLinus Torvalds /* count in words: 11981da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 11991da177e4SLinus Torvalds */ 12001da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 12011da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 12021da177e4SLinus Torvalds if (!buf) 12033e772463SJ. Bruce Fields return nfserr_jukebox; 12041da177e4SLinus Torvalds 120584822d0bSJ. Bruce Fields p = buf; 1206d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 1207ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 1208d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 1209d5184658SJ. Bruce Fields verify->ve_bmval, 1210406a7ea9SFrank Filz rqstp, 0); 121141ae6e71SJ. Bruce Fields /* 121241ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 121341ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 121441ae6e71SJ. Bruce Fields */ 121584822d0bSJ. Bruce Fields if (status == nfserr_resource) 12161da177e4SLinus Torvalds status = nfserr_not_same; 12171da177e4SLinus Torvalds if (status) 12181da177e4SLinus Torvalds goto out_kfree; 12191da177e4SLinus Torvalds 122095ec28cdSBenny Halevy /* skip bitmap */ 122195ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 12221da177e4SLinus Torvalds status = nfserr_not_same; 12231da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 12241da177e4SLinus Torvalds goto out_kfree; 12251da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 12261da177e4SLinus Torvalds status = nfserr_same; 12271da177e4SLinus Torvalds 12281da177e4SLinus Torvalds out_kfree: 12291da177e4SLinus Torvalds kfree(buf); 12301da177e4SLinus Torvalds return status; 12311da177e4SLinus Torvalds } 12321da177e4SLinus Torvalds 1233c954e2a5SJ.Bruce Fields static __be32 1234c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1235c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1236c954e2a5SJ.Bruce Fields { 1237c954e2a5SJ.Bruce Fields __be32 status; 1238c954e2a5SJ.Bruce Fields 1239c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1240c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 1241c954e2a5SJ.Bruce Fields } 1242c954e2a5SJ.Bruce Fields 1243c954e2a5SJ.Bruce Fields static __be32 1244c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1245c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 1246c954e2a5SJ.Bruce Fields { 1247c954e2a5SJ.Bruce Fields __be32 status; 1248c954e2a5SJ.Bruce Fields 1249c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 1250c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 1251c954e2a5SJ.Bruce Fields } 1252c954e2a5SJ.Bruce Fields 12539cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 12549cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 12559cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 12569cf514ccSChristoph Hellwig { 12578a4c3926SJeff Layton if (!exp->ex_layout_types) { 12589cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 12599cf514ccSChristoph Hellwig return NULL; 12609cf514ccSChristoph Hellwig } 12619cf514ccSChristoph Hellwig 1262b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 1263b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 12649cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 12659cf514ccSChristoph Hellwig __func__, layout_type); 12669cf514ccSChristoph Hellwig return NULL; 12679cf514ccSChristoph Hellwig } 12689cf514ccSChristoph Hellwig 12699cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 12709cf514ccSChristoph Hellwig } 12719cf514ccSChristoph Hellwig 12729cf514ccSChristoph Hellwig static __be32 12739cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 12749cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 12759cf514ccSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp) 12769cf514ccSChristoph Hellwig { 12779cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 12789cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 12799cf514ccSChristoph Hellwig struct svc_export *exp; 12809cf514ccSChristoph Hellwig __be32 nfserr; 12819cf514ccSChristoph Hellwig 12829cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 12839cf514ccSChristoph Hellwig __func__, 12849cf514ccSChristoph Hellwig gdp->gd_layout_type, 12859cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 12869cf514ccSChristoph Hellwig gdp->gd_maxcount); 12879cf514ccSChristoph Hellwig 12889cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 12899cf514ccSChristoph Hellwig if (!map) { 12909cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 12919cf514ccSChristoph Hellwig __func__); 12929cf514ccSChristoph Hellwig return nfserr_noent; 12939cf514ccSChristoph Hellwig } 12949cf514ccSChristoph Hellwig 12959cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 12969cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 12979cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 12989cf514ccSChristoph Hellwig return nfserr_noent; 12999cf514ccSChristoph Hellwig } 13009cf514ccSChristoph Hellwig 13019cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 13029cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 13039cf514ccSChristoph Hellwig if (!ops) 13049cf514ccSChristoph Hellwig goto out; 13059cf514ccSChristoph Hellwig 13069cf514ccSChristoph Hellwig nfserr = nfs_ok; 1307f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 1308f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 1309d7c920d1STom Haynes rqstp, cstate->session->se_client, gdp); 1310f99d4fbdSChristoph Hellwig } 13119cf514ccSChristoph Hellwig 13129cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 13139cf514ccSChristoph Hellwig out: 1314a1420384SKinglong Mee exp_put(exp); 13159cf514ccSChristoph Hellwig return nfserr; 13169cf514ccSChristoph Hellwig } 13179cf514ccSChristoph Hellwig 13189cf514ccSChristoph Hellwig static __be32 13199cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 13209cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 13219cf514ccSChristoph Hellwig struct nfsd4_layoutget *lgp) 13229cf514ccSChristoph Hellwig { 13239cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 13249cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 13259cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 13269cf514ccSChristoph Hellwig __be32 nfserr; 13279cf514ccSChristoph Hellwig int accmode; 13289cf514ccSChristoph Hellwig 13299cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 13309cf514ccSChristoph Hellwig case IOMODE_READ: 13319cf514ccSChristoph Hellwig accmode = NFSD_MAY_READ; 13329cf514ccSChristoph Hellwig break; 13339cf514ccSChristoph Hellwig case IOMODE_RW: 13349cf514ccSChristoph Hellwig accmode = NFSD_MAY_READ | NFSD_MAY_WRITE; 13359cf514ccSChristoph Hellwig break; 13369cf514ccSChristoph Hellwig default: 13379cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 13389cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 13399cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 13409cf514ccSChristoph Hellwig goto out; 13419cf514ccSChristoph Hellwig } 13429cf514ccSChristoph Hellwig 13439cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 13449cf514ccSChristoph Hellwig if (nfserr) 13459cf514ccSChristoph Hellwig goto out; 13469cf514ccSChristoph Hellwig 13479cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 13489cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 13499cf514ccSChristoph Hellwig if (!ops) 13509cf514ccSChristoph Hellwig goto out; 13519cf514ccSChristoph Hellwig 13529cf514ccSChristoph Hellwig /* 13539cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 13549cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 13559cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 13569cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 13579cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 13589cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 13599cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 13609cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 13619cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 13629cf514ccSChristoph Hellwig */ 13639cf514ccSChristoph Hellwig nfserr = nfserr_inval; 13649cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 13659cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 13669cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 13679cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 13689cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 13699cf514ccSChristoph Hellwig goto out; 13709cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 13719cf514ccSChristoph Hellwig goto out; 13729cf514ccSChristoph Hellwig 13739cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 13749cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 137531ef83dcSChristoph Hellwig if (nfserr) { 137631ef83dcSChristoph Hellwig trace_layout_get_lookup_fail(&lgp->lg_sid); 13779cf514ccSChristoph Hellwig goto out; 137831ef83dcSChristoph Hellwig } 13799cf514ccSChristoph Hellwig 1380c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 1381c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1382c5c707f9SChristoph Hellwig goto out_put_stid; 1383c5c707f9SChristoph Hellwig 13842b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 13859cf514ccSChristoph Hellwig current_fh, lgp); 13869cf514ccSChristoph Hellwig if (nfserr) 13879cf514ccSChristoph Hellwig goto out_put_stid; 13889cf514ccSChristoph Hellwig 13899cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 13909cf514ccSChristoph Hellwig 13919cf514ccSChristoph Hellwig out_put_stid: 1392cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 13939cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 13949cf514ccSChristoph Hellwig out: 13959cf514ccSChristoph Hellwig return nfserr; 13969cf514ccSChristoph Hellwig } 13979cf514ccSChristoph Hellwig 13989cf514ccSChristoph Hellwig static __be32 13999cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 14009cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 14019cf514ccSChristoph Hellwig struct nfsd4_layoutcommit *lcp) 14029cf514ccSChristoph Hellwig { 14039cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 14049cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 14059cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 14069cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 14079cf514ccSChristoph Hellwig struct inode *inode; 14089cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 14099cf514ccSChristoph Hellwig __be32 nfserr; 14109cf514ccSChristoph Hellwig 14119cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 14129cf514ccSChristoph Hellwig if (nfserr) 14139cf514ccSChristoph Hellwig goto out; 14149cf514ccSChristoph Hellwig 14159cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 14169cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 14179cf514ccSChristoph Hellwig if (!ops) 14189cf514ccSChristoph Hellwig goto out; 14192b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 14209cf514ccSChristoph Hellwig 14219cf514ccSChristoph Hellwig nfserr = nfserr_inval; 14229cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 14239cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 14249cf514ccSChristoph Hellwig goto out; 14259cf514ccSChristoph Hellwig } 14269cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 14279cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 14289cf514ccSChristoph Hellwig goto out; 14299cf514ccSChristoph Hellwig } 14309cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 14319cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 14329cf514ccSChristoph Hellwig goto out; 14339cf514ccSChristoph Hellwig } 14349cf514ccSChristoph Hellwig 14359cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 14369cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 14379cf514ccSChristoph Hellwig &ls); 14389cf514ccSChristoph Hellwig if (nfserr) { 143931ef83dcSChristoph Hellwig trace_layout_commit_lookup_fail(&lcp->lc_sid); 14409cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 14419cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 14429cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 14439cf514ccSChristoph Hellwig goto out; 14449cf514ccSChristoph Hellwig } 14459cf514ccSChristoph Hellwig 1446cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 1447cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 1448cc8a5532SJeff Layton 14499cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 14509cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 14519cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 14529cf514ccSChristoph Hellwig } else { 14539cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 14549cf514ccSChristoph Hellwig } 14559cf514ccSChristoph Hellwig 1456d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 14579cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 14589cf514ccSChristoph Hellwig out: 14599cf514ccSChristoph Hellwig return nfserr; 14609cf514ccSChristoph Hellwig } 14619cf514ccSChristoph Hellwig 14629cf514ccSChristoph Hellwig static __be32 14639cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 14649cf514ccSChristoph Hellwig struct nfsd4_compound_state *cstate, 14659cf514ccSChristoph Hellwig struct nfsd4_layoutreturn *lrp) 14669cf514ccSChristoph Hellwig { 14679cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 14689cf514ccSChristoph Hellwig __be32 nfserr; 14699cf514ccSChristoph Hellwig 14709cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 14719cf514ccSChristoph Hellwig if (nfserr) 14729cf514ccSChristoph Hellwig goto out; 14739cf514ccSChristoph Hellwig 14749cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 14759cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 14769cf514ccSChristoph Hellwig goto out; 14779cf514ccSChristoph Hellwig 14789cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 14799cf514ccSChristoph Hellwig case IOMODE_READ: 14809cf514ccSChristoph Hellwig case IOMODE_RW: 14819cf514ccSChristoph Hellwig case IOMODE_ANY: 14829cf514ccSChristoph Hellwig break; 14839cf514ccSChristoph Hellwig default: 14849cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 14859cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 14869cf514ccSChristoph Hellwig nfserr = nfserr_inval; 14879cf514ccSChristoph Hellwig goto out; 14889cf514ccSChristoph Hellwig } 14899cf514ccSChristoph Hellwig 14909cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 14919cf514ccSChristoph Hellwig case RETURN_FILE: 14929cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 14939cf514ccSChristoph Hellwig break; 14949cf514ccSChristoph Hellwig case RETURN_FSID: 14959cf514ccSChristoph Hellwig case RETURN_ALL: 14969cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 14979cf514ccSChristoph Hellwig break; 14989cf514ccSChristoph Hellwig default: 14999cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 15009cf514ccSChristoph Hellwig lrp->lr_return_type); 15019cf514ccSChristoph Hellwig nfserr = nfserr_inval; 15029cf514ccSChristoph Hellwig break; 15039cf514ccSChristoph Hellwig } 15049cf514ccSChristoph Hellwig out: 15059cf514ccSChristoph Hellwig return nfserr; 15069cf514ccSChristoph Hellwig } 15079cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 15089cf514ccSChristoph Hellwig 15091da177e4SLinus Torvalds /* 15101da177e4SLinus Torvalds * NULL call. 15111da177e4SLinus Torvalds */ 15127111c66eSAl Viro static __be32 15131da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 15141da177e4SLinus Torvalds { 15151da177e4SLinus Torvalds return nfs_ok; 15161da177e4SLinus Torvalds } 15171da177e4SLinus Torvalds 1518e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 1519e2b20950SShankar Anand { 1520e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 1521e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 1522e2b20950SShankar Anand } 1523e2b20950SShankar Anand 1524b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 1525b591480bSJ.Bruce Fields void *); 152658e7b33aSMi Jinlong typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op); 15278b70484cSTigran Mkrtchyan typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *); 15288b70484cSTigran Mkrtchyan typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *); 152958e7b33aSMi Jinlong 1530f9bb94c4SAndy Adamson enum nfsd4_op_flags { 1531f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 15325ece3cafSMi Jinlong ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 15335ece3cafSMi Jinlong ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 153468d93184SJ. Bruce Fields /* For rfc 5661 section 2.6.3.1.1: */ 153568d93184SJ. Bruce Fields OP_HANDLES_WRONGSEC = 1 << 3, 153668d93184SJ. Bruce Fields OP_IS_PUTFH_LIKE = 1 << 4, 15371091006cSJ. Bruce Fields /* 1538c856694eSJ. Bruce Fields * These are the ops whose result size we estimate before 1539c856694eSJ. Bruce Fields * encoding, to avoid performing an op then not being able to 1540c856694eSJ. Bruce Fields * respond or cache a response. This includes writes and setattrs 1541c856694eSJ. Bruce Fields * as well as the operations usually called "nonidempotent": 1542c856694eSJ. Bruce Fields */ 1543c856694eSJ. Bruce Fields OP_MODIFIES_SOMETHING = 1 << 5, 1544c856694eSJ. Bruce Fields /* 1545c856694eSJ. Bruce Fields * Cache compounds containing these ops in the xid-based drc: 15461091006cSJ. Bruce Fields * We use the DRC for compounds containing non-idempotent 15471091006cSJ. Bruce Fields * operations, *except* those that are 4.1-specific (since 15481091006cSJ. Bruce Fields * sessions provide their own EOS), and except for stateful 15491091006cSJ. Bruce Fields * operations other than setclientid and setclientid_confirm 15501091006cSJ. Bruce Fields * (since sequence numbers provide EOS for open, lock, etc in 15511091006cSJ. Bruce Fields * the v4.0 case). 15521091006cSJ. Bruce Fields */ 1553c856694eSJ. Bruce Fields OP_CACHEME = 1 << 6, 15548b70484cSTigran Mkrtchyan /* 15558b70484cSTigran Mkrtchyan * These are ops which clear current state id. 15568b70484cSTigran Mkrtchyan */ 15578b70484cSTigran Mkrtchyan OP_CLEAR_STATEID = 1 << 7, 1558c856694eSJ. Bruce Fields }; 1559c856694eSJ. Bruce Fields 1560c856694eSJ. Bruce Fields struct nfsd4_operation { 1561c856694eSJ. Bruce Fields nfsd4op_func op_func; 1562c856694eSJ. Bruce Fields u32 op_flags; 1563c856694eSJ. Bruce Fields char *op_name; 156458e7b33aSMi Jinlong /* Try to get response size before operation */ 156558e7b33aSMi Jinlong nfsd4op_rsize op_rsize_bop; 156624ff99c6SBryan Schumaker stateid_getter op_get_currentstateid; 156724ff99c6SBryan Schumaker stateid_setter op_set_currentstateid; 1568b591480bSJ.Bruce Fields }; 1569b591480bSJ.Bruce Fields 1570b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 1571b591480bSJ.Bruce Fields 1572f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 1573b001a1b6SBenny Halevy 15741da177e4SLinus Torvalds /* 157557716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 1576f9bb94c4SAndy Adamson * 157757716355SJ. Bruce Fields * Also note, enforced elsewhere: 157857716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 157957716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 15801d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 15811d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 158257716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 158357716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 158457716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 1585f9bb94c4SAndy Adamson */ 158657716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 1587f9bb94c4SAndy Adamson { 1588f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 158957716355SJ. Bruce Fields 159057716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 159157716355SJ. Bruce Fields if (args->minorversion == 0) 159257716355SJ. Bruce Fields return nfs_ok; 159357716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 159457716355SJ. Bruce Fields if (args->opcnt == 0) 159557716355SJ. Bruce Fields return nfs_ok; 159657716355SJ. Bruce Fields if (op->status == nfserr_op_illegal) 159757716355SJ. Bruce Fields return nfs_ok; 159857716355SJ. Bruce Fields if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 159957716355SJ. Bruce Fields return nfserr_op_not_in_session; 160057716355SJ. Bruce Fields if (op->opnum == OP_SEQUENCE) 160157716355SJ. Bruce Fields return nfs_ok; 160257716355SJ. Bruce Fields if (args->opcnt != 1) 160357716355SJ. Bruce Fields return nfserr_not_only_op; 160457716355SJ. Bruce Fields return nfs_ok; 1605f9bb94c4SAndy Adamson } 1606f9bb94c4SAndy Adamson 160722b03214SJ. Bruce Fields static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 160822b03214SJ. Bruce Fields { 160922b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 161022b03214SJ. Bruce Fields } 161122b03214SJ. Bruce Fields 16121091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 16131091006cSJ. Bruce Fields { 1614e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 1615e372ba60SJ. Bruce Fields return false; 1616c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 16171091006cSJ. Bruce Fields } 16181091006cSJ. Bruce Fields 161968d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 162068d93184SJ. Bruce Fields { 162168d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 162268d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 162368d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 162468d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 162568d93184SJ. Bruce Fields struct nfsd4_operation *thisd; 162668d93184SJ. Bruce Fields struct nfsd4_operation *nextd; 162768d93184SJ. Bruce Fields 162868d93184SJ. Bruce Fields thisd = OPDESC(this); 162968d93184SJ. Bruce Fields /* 163068d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 163168d93184SJ. Bruce Fields * have special rules. 163268d93184SJ. Bruce Fields */ 163368d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 163468d93184SJ. Bruce Fields return false; 163568d93184SJ. Bruce Fields /* 163668d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 163768d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 163868d93184SJ. Bruce Fields * result: 163968d93184SJ. Bruce Fields */ 164068d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 164168d93184SJ. Bruce Fields return false; 164251904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 164351904b08SJ. Bruce Fields return false; 164468d93184SJ. Bruce Fields nextd = OPDESC(next); 164568d93184SJ. Bruce Fields /* 164668d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 164768d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 164868d93184SJ. Bruce Fields * now: 164968d93184SJ. Bruce Fields */ 165068d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 165168d93184SJ. Bruce Fields } 165268d93184SJ. Bruce Fields 16532d124dfaSJ. Bruce Fields static void svcxdr_init_encode(struct svc_rqst *rqstp, 16542d124dfaSJ. Bruce Fields struct nfsd4_compoundres *resp) 16552d124dfaSJ. Bruce Fields { 16562d124dfaSJ. Bruce Fields struct xdr_stream *xdr = &resp->xdr; 16572d124dfaSJ. Bruce Fields struct xdr_buf *buf = &rqstp->rq_res; 16582d124dfaSJ. Bruce Fields struct kvec *head = buf->head; 16592d124dfaSJ. Bruce Fields 16602d124dfaSJ. Bruce Fields xdr->buf = buf; 1661ddd1ea56SJ. Bruce Fields xdr->iov = head; 16622d124dfaSJ. Bruce Fields xdr->p = head->iov_base + head->iov_len; 1663a5cddc88SJ. Bruce Fields xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; 16646ac90391SJ. Bruce Fields /* Tail and page_len should be zero at this point: */ 16656ac90391SJ. Bruce Fields buf->len = buf->head[0].iov_len; 16662825a7f9SJ. Bruce Fields xdr->scratch.iov_len = 0; 166705638dc7SJ. Bruce Fields xdr->page_ptr = buf->pages - 1; 16682825a7f9SJ. Bruce Fields buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) 1669a5cddc88SJ. Bruce Fields - rqstp->rq_auth_slack; 16702d124dfaSJ. Bruce Fields } 16712d124dfaSJ. Bruce Fields 1672f9bb94c4SAndy Adamson /* 16731da177e4SLinus Torvalds * COMPOUND call. 16741da177e4SLinus Torvalds */ 16757111c66eSAl Viro static __be32 1676*f7235b6bSChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp, void *arg, void *res) 16771da177e4SLinus Torvalds { 1678*f7235b6bSChristoph Hellwig struct nfsd4_compoundargs *args = arg; 1679*f7235b6bSChristoph Hellwig struct nfsd4_compoundres *resp = res; 16801da177e4SLinus Torvalds struct nfsd4_op *op; 1681b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 1682e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 16834daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 16844daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 1685b37ad28bSAl Viro __be32 status; 16861da177e4SLinus Torvalds 16872d124dfaSJ. Bruce Fields svcxdr_init_encode(rqstp, resp); 16884aea24b2SJ. Bruce Fields resp->tagp = resp->xdr.p; 16891da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 1690d3f627c8SJ. Bruce Fields xdr_reserve_space(&resp->xdr, 8 + args->taglen); 16911da177e4SLinus Torvalds resp->taglen = args->taglen; 16921da177e4SLinus Torvalds resp->tag = args->tag; 16931da177e4SLinus Torvalds resp->rqstp = rqstp; 16944daeed25SKinglong Mee cstate->minorversion = args->minorversion; 16954daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 16964daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 16978ff30fa4SNeilBrown /* 16988ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 16998ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 17008ff30fa4SNeilBrown */ 170130660e04SJeff Layton clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 17021da177e4SLinus Torvalds 17031da177e4SLinus Torvalds /* 17041da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 17051da177e4SLinus Torvalds */ 17061da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 170735f7a14fSJ. Bruce Fields if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) 17081da177e4SLinus Torvalds goto out; 17091da177e4SLinus Torvalds 171057716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 171157716355SJ. Bruce Fields if (status) { 1712f9bb94c4SAndy Adamson op = &args->ops[0]; 171357716355SJ. Bruce Fields op->status = status; 1714f9bb94c4SAndy Adamson goto encode_op; 1715f9bb94c4SAndy Adamson } 1716f9bb94c4SAndy Adamson 17171da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 17181da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 17191da177e4SLinus Torvalds 1720b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 1721b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 1722b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 17231da177e4SLinus Torvalds /* 17241da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 17251da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 17261da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 17271da177e4SLinus Torvalds */ 17289d313b17SJ. Bruce Fields if (op->status) { 17299d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 17309d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 17311da177e4SLinus Torvalds goto encode_op; 17329d313b17SJ. Bruce Fields } 17331da177e4SLinus Torvalds 173422b03214SJ. Bruce Fields opdesc = OPDESC(op); 1735b591480bSJ.Bruce Fields 17364daeed25SKinglong Mee if (!current_fh->fh_dentry) { 173727d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 17381da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 17391da177e4SLinus Torvalds goto encode_op; 17401da177e4SLinus Torvalds } 17414daeed25SKinglong Mee } else if (current_fh->fh_export->ex_fslocs.migrated && 1742eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 174342ca0993SJ.Bruce Fields op->status = nfserr_moved; 174442ca0993SJ.Bruce Fields goto encode_op; 174542ca0993SJ.Bruce Fields } 1746b591480bSJ.Bruce Fields 17472336745eSKinglong Mee fh_clear_wcc(current_fh); 17482336745eSKinglong Mee 174958e7b33aSMi Jinlong /* If op is non-idempotent */ 175058e7b33aSMi Jinlong if (opdesc->op_flags & OP_MODIFIES_SOMETHING) { 17514c69d585SJ. Bruce Fields /* 1752a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 1753a8095f7eSJ. Bruce Fields * succesful reply: 1754a8095f7eSJ. Bruce Fields */ 1755a8095f7eSJ. Bruce Fields u32 plen = opdesc->op_rsize_bop(rqstp, op); 1756a8095f7eSJ. Bruce Fields /* 1757a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 17584c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 17594c69d585SJ. Bruce Fields */ 17604c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 17614c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 176258e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 176358e7b33aSMi Jinlong } 176458e7b33aSMi Jinlong 176558e7b33aSMi Jinlong if (op->status) 176658e7b33aSMi Jinlong goto encode_op; 176758e7b33aSMi Jinlong 17688b70484cSTigran Mkrtchyan if (opdesc->op_get_currentstateid) 17698b70484cSTigran Mkrtchyan opdesc->op_get_currentstateid(cstate, &op->u); 1770b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 17711da177e4SLinus Torvalds 17728b70484cSTigran Mkrtchyan if (!op->status) { 17738b70484cSTigran Mkrtchyan if (opdesc->op_set_currentstateid) 17748b70484cSTigran Mkrtchyan opdesc->op_set_currentstateid(cstate, &op->u); 17758b70484cSTigran Mkrtchyan 17768b70484cSTigran Mkrtchyan if (opdesc->op_flags & OP_CLEAR_STATEID) 177737c593c5STigran Mkrtchyan clear_current_stateid(cstate); 17788b70484cSTigran Mkrtchyan 17798b70484cSTigran Mkrtchyan if (need_wrongsec_check(rqstp)) 17804daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 17818b70484cSTigran Mkrtchyan } 178268d93184SJ. Bruce Fields 17831da177e4SLinus Torvalds encode_op: 178449557cc7SAndy Adamson /* Only from SEQUENCE */ 17854daeed25SKinglong Mee if (cstate->status == nfserr_replay_cache) { 1786da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 1787da3846a2SAndy Adamson status = op->status; 1788da3846a2SAndy Adamson goto out; 1789da3846a2SAndy Adamson } 1790a90b061cSAl Viro if (op->status == nfserr_replay_me) { 1791a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 1792d0a381ddSJ. Bruce Fields nfsd4_encode_replay(&resp->xdr, op); 17931da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 17941da177e4SLinus Torvalds } else { 17951da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 17961da177e4SLinus Torvalds status = op->status; 17971da177e4SLinus Torvalds } 17980407717dSBenny Halevy 17990407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 18000407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 18010407717dSBenny Halevy be32_to_cpu(status)); 18020407717dSBenny Halevy 180358fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 1804e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 18051da177e4SLinus Torvalds } 18061da177e4SLinus Torvalds 18074daeed25SKinglong Mee cstate->status = status; 18084daeed25SKinglong Mee fh_put(current_fh); 18094daeed25SKinglong Mee fh_put(save_fh); 18104daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 18111da177e4SLinus Torvalds out: 18122f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 181330660e04SJeff Layton set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 18143b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 18151da177e4SLinus Torvalds return status; 18161da177e4SLinus Torvalds } 18171da177e4SLinus Torvalds 181858e7b33aSMi Jinlong #define op_encode_hdr_size (2) 181958e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 182058e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 182158e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 182258e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 182358e7b33aSMi Jinlong 18248c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 18258c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 182658e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 182758e7b33aSMi Jinlong 182858e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 182958e7b33aSMi Jinlong 183058e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 183158e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 183258e7b33aSMi Jinlong op_encode_ace_maxsz) 183358e7b33aSMi Jinlong 183458e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 183558e7b33aSMi Jinlong 183658e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 183758e7b33aSMi Jinlong { 183858e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 183958e7b33aSMi Jinlong } 184058e7b33aSMi Jinlong 184158e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 184258e7b33aSMi Jinlong { 184358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 184458e7b33aSMi Jinlong } 184558e7b33aSMi Jinlong 18462282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 18472282cd2cSKinglong Mee { 18482282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 18492282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 18502282cd2cSKinglong Mee } 18512282cd2cSKinglong Mee 185258e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 185358e7b33aSMi Jinlong { 185458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 185558e7b33aSMi Jinlong } 185658e7b33aSMi Jinlong 185758e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 185858e7b33aSMi Jinlong { 185958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 186058e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 186158e7b33aSMi Jinlong } 186258e7b33aSMi Jinlong 1863b86cef60SJ. Bruce Fields /* 1864b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 1865b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 1866b86cef60SJ. Bruce Fields * reads unnecessarily. 1867b86cef60SJ. Bruce Fields */ 1868b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 1869b86cef60SJ. Bruce Fields struct nfsd4_op *op) 1870b86cef60SJ. Bruce Fields { 1871b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 1872b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 1873b86cef60SJ. Bruce Fields u32 ret = 0; 1874b86cef60SJ. Bruce Fields 1875b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 1876b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 1877b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 1878b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 1879b86cef60SJ. Bruce Fields 1880b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 1881b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 1882b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 1883b86cef60SJ. Bruce Fields } 1884b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 1885b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 1886b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 1887b86cef60SJ. Bruce Fields } 1888b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 1889b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 1890b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 1891b86cef60SJ. Bruce Fields } 1892b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 18931ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 1894b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 1895b86cef60SJ. Bruce Fields } 1896b86cef60SJ. Bruce Fields /* 1897b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 1898b86cef60SJ. Bruce Fields * supported_attributes) 1899b86cef60SJ. Bruce Fields */ 1900b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 1901b86cef60SJ. Bruce Fields /* bitmask, length */ 1902b86cef60SJ. Bruce Fields ret += 20; 1903b86cef60SJ. Bruce Fields return ret; 1904b86cef60SJ. Bruce Fields } 1905b86cef60SJ. Bruce Fields 19062282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19072282cd2cSKinglong Mee { 19082282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 19092282cd2cSKinglong Mee } 19102282cd2cSKinglong Mee 191158e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 191258e7b33aSMi Jinlong { 191358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 191458e7b33aSMi Jinlong * sizeof(__be32); 191558e7b33aSMi Jinlong } 191658e7b33aSMi Jinlong 191758e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 191858e7b33aSMi Jinlong { 191958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 192058e7b33aSMi Jinlong * sizeof(__be32); 192158e7b33aSMi Jinlong } 192258e7b33aSMi Jinlong 192358e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 192458e7b33aSMi Jinlong { 192558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 192658e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 192758e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 192858e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 192958e7b33aSMi Jinlong } 193058e7b33aSMi Jinlong 193158e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 193258e7b33aSMi Jinlong { 193358e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 193458e7b33aSMi Jinlong 193558e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 19363c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 193758e7b33aSMi Jinlong 1938622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 193958e7b33aSMi Jinlong } 194058e7b33aSMi Jinlong 194158e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 194258e7b33aSMi Jinlong { 19433c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 194458e7b33aSMi Jinlong 19453c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 19463c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 194758e7b33aSMi Jinlong 1948561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 1949561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 195058e7b33aSMi Jinlong } 195158e7b33aSMi Jinlong 19522282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19532282cd2cSKinglong Mee { 19542282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 19552282cd2cSKinglong Mee } 19562282cd2cSKinglong Mee 195758e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 195858e7b33aSMi Jinlong { 195958e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 196058e7b33aSMi Jinlong * sizeof(__be32); 196158e7b33aSMi Jinlong } 196258e7b33aSMi Jinlong 196358e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 196458e7b33aSMi Jinlong { 196558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 196658e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 196758e7b33aSMi Jinlong } 196858e7b33aSMi Jinlong 1969ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 1970ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 1971ccae70a9SJ. Bruce Fields { 1972d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 1973d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 1974ccae70a9SJ. Bruce Fields } 1975ccae70a9SJ. Bruce Fields 19762282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19772282cd2cSKinglong Mee { 19782282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 19792282cd2cSKinglong Mee * sizeof(__be32); 19802282cd2cSKinglong Mee } 19812282cd2cSKinglong Mee 198258e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 198358e7b33aSMi Jinlong { 198458e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 198558e7b33aSMi Jinlong } 198658e7b33aSMi Jinlong 19872282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 19882282cd2cSKinglong Mee { 19892282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 19902282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 19912282cd2cSKinglong Mee } 19922282cd2cSKinglong Mee 199358e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 199458e7b33aSMi Jinlong { 1995480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 1996480efaeeSJ. Bruce Fields sizeof(__be32); 199758e7b33aSMi Jinlong } 199858e7b33aSMi Jinlong 199958e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 200058e7b33aSMi Jinlong { 2001f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 200258e7b33aSMi Jinlong } 200358e7b33aSMi Jinlong 200458e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 200558e7b33aSMi Jinlong { 200658e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2007a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2008a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 200958e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 201058e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 201158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 201258e7b33aSMi Jinlong /* eir_server_scope<> */\ 201358e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 201458e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 201558e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 201658e7b33aSMi Jinlong } 201758e7b33aSMi Jinlong 201858e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 201958e7b33aSMi Jinlong { 202058e7b33aSMi Jinlong return (op_encode_hdr_size + \ 202158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 202258e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 202358e7b33aSMi Jinlong } 202458e7b33aSMi Jinlong 202558e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 202658e7b33aSMi Jinlong { 202758e7b33aSMi Jinlong return (op_encode_hdr_size + \ 202858e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 202958e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 203058e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 203158e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 203258e7b33aSMi Jinlong } 203358e7b33aSMi Jinlong 203429ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 203529ae7f9dSAnna Schumaker { 203629ae7f9dSAnna Schumaker return (op_encode_hdr_size + 203729ae7f9dSAnna Schumaker 1 /* wr_callback */ + 203829ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 203929ae7f9dSAnna Schumaker 2 /* wr_count */ + 204029ae7f9dSAnna Schumaker 1 /* wr_committed */ + 204129ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 204229ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 204329ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 204429ae7f9dSAnna Schumaker } 204529ae7f9dSAnna Schumaker 20469cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 20472282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20482282cd2cSKinglong Mee { 20492282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 20502282cd2cSKinglong Mee 20512282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 20522282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 20532282cd2cSKinglong Mee 20542282cd2cSKinglong Mee return (op_encode_hdr_size + 20552282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 20562282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 20572282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 20582282cd2cSKinglong Mee } 20592282cd2cSKinglong Mee 20609cf514ccSChristoph Hellwig /* 20619cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 20629cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 20639cf514ccSChristoph Hellwig */ 20649cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 20659cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20669cf514ccSChristoph Hellwig { 20679cf514ccSChristoph Hellwig return (op_encode_hdr_size + 20689cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 20699cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 20709cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 20719cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 20729cf514ccSChristoph Hellwig } 20739cf514ccSChristoph Hellwig 20749cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20759cf514ccSChristoph Hellwig { 20769cf514ccSChristoph Hellwig return (op_encode_hdr_size + 20779cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 20789cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 20799cf514ccSChristoph Hellwig } 20809cf514ccSChristoph Hellwig 20819cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20829cf514ccSChristoph Hellwig { 20839cf514ccSChristoph Hellwig return (op_encode_hdr_size + 20849cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 20859cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 20869cf514ccSChristoph Hellwig } 20879cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 20889cf514ccSChristoph Hellwig 20892282cd2cSKinglong Mee 20902282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 20912282cd2cSKinglong Mee { 20922282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 20932282cd2cSKinglong Mee } 20942282cd2cSKinglong Mee 209520766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 2096b591480bSJ.Bruce Fields [OP_ACCESS] = { 2097b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 2098b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 20992282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_access_rsize, 2100b591480bSJ.Bruce Fields }, 2101b591480bSJ.Bruce Fields [OP_CLOSE] = { 2102b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 210358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2104b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 210558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 21068b70484cSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid, 21078b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid, 2108b591480bSJ.Bruce Fields }, 2109b591480bSJ.Bruce Fields [OP_COMMIT] = { 2110b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 211158e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2112b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 211358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize, 2114b591480bSJ.Bruce Fields }, 2115b591480bSJ.Bruce Fields [OP_CREATE] = { 2116b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 2117d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 2118b001a1b6SBenny Halevy .op_name = "OP_CREATE", 211958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize, 2120b591480bSJ.Bruce Fields }, 2121b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 2122b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 212358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2124b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 212558e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 21269428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid, 2127b591480bSJ.Bruce Fields }, 2128b591480bSJ.Bruce Fields [OP_GETATTR] = { 2129b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 2130eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 2131b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 2132b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 2133b591480bSJ.Bruce Fields }, 2134b591480bSJ.Bruce Fields [OP_GETFH] = { 2135b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 2136b001a1b6SBenny Halevy .op_name = "OP_GETFH", 21372282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_getfh_rsize, 2138b591480bSJ.Bruce Fields }, 2139b591480bSJ.Bruce Fields [OP_LINK] = { 2140b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 2141c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 2142c856694eSJ. Bruce Fields | OP_CACHEME, 2143b001a1b6SBenny Halevy .op_name = "OP_LINK", 214458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize, 2145b591480bSJ.Bruce Fields }, 2146b591480bSJ.Bruce Fields [OP_LOCK] = { 2147b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 214858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2149b001a1b6SBenny Halevy .op_name = "OP_LOCK", 215058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, 215162cd4a59STigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid, 2152b591480bSJ.Bruce Fields }, 2153b591480bSJ.Bruce Fields [OP_LOCKT] = { 2154b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 2155b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 21562282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, 2157b591480bSJ.Bruce Fields }, 2158b591480bSJ.Bruce Fields [OP_LOCKU] = { 2159b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 216058e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2161b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 216258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 216362cd4a59STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid, 2164b591480bSJ.Bruce Fields }, 2165b591480bSJ.Bruce Fields [OP_LOOKUP] = { 2166b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 2167d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2168b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 21692282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2170b591480bSJ.Bruce Fields }, 2171b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 2172b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 2173d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 2174b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 21752282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2176b591480bSJ.Bruce Fields }, 2177b591480bSJ.Bruce Fields [OP_NVERIFY] = { 2178b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 2179b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 21802282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2181b591480bSJ.Bruce Fields }, 2182b591480bSJ.Bruce Fields [OP_OPEN] = { 2183b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 218458e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2185b001a1b6SBenny Halevy .op_name = "OP_OPEN", 218658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize, 21878b70484cSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid, 2188b591480bSJ.Bruce Fields }, 2189b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 2190b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 219158e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2192b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 219358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 2194b591480bSJ.Bruce Fields }, 2195b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 2196b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 219758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 2198b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 219958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, 22009428fe1aSTigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid, 22019428fe1aSTigran Mkrtchyan .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid, 2202b591480bSJ.Bruce Fields }, 2203b591480bSJ.Bruce Fields [OP_PUTFH] = { 2204b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 220568d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 22065b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2207b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 220858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2209b591480bSJ.Bruce Fields }, 2210eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 2211a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 221268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 22135b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2214b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 221558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2216eeac294eSJ.Bruce Fields }, 2217b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 2218b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 221968d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 22205b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 2221b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 222258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2223b591480bSJ.Bruce Fields }, 2224b591480bSJ.Bruce Fields [OP_READ] = { 2225b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 2226b001a1b6SBenny Halevy .op_name = "OP_READ", 222758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, 222830813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, 2229b591480bSJ.Bruce Fields }, 2230b591480bSJ.Bruce Fields [OP_READDIR] = { 2231b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 2232b001a1b6SBenny Halevy .op_name = "OP_READDIR", 223358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, 2234b591480bSJ.Bruce Fields }, 2235b591480bSJ.Bruce Fields [OP_READLINK] = { 2236b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 2237b001a1b6SBenny Halevy .op_name = "OP_READLINK", 22382282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_readlink_rsize, 2239b591480bSJ.Bruce Fields }, 2240b591480bSJ.Bruce Fields [OP_REMOVE] = { 2241b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 2242c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2243b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 224458e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize, 2245b591480bSJ.Bruce Fields }, 2246b591480bSJ.Bruce Fields [OP_RENAME] = { 2247b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 2248c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 224958e7b33aSMi Jinlong .op_name = "OP_RENAME", 225058e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize, 2251b591480bSJ.Bruce Fields }, 2252b591480bSJ.Bruce Fields [OP_RENEW] = { 2253b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 225458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 225558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2256b001a1b6SBenny Halevy .op_name = "OP_RENEW", 225758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 225858e7b33aSMi Jinlong 2259b591480bSJ.Bruce Fields }, 2260b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 2261b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 226268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 226358e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 2264b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 226558e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2266b591480bSJ.Bruce Fields }, 2267b591480bSJ.Bruce Fields [OP_SAVEFH] = { 2268b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 226958e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 2270b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 227158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2272b591480bSJ.Bruce Fields }, 2273dcb488a3SAndy Adamson [OP_SECINFO] = { 2274dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 227568d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 2276b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 22772282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_secinfo_rsize, 2278dcb488a3SAndy Adamson }, 2279b591480bSJ.Bruce Fields [OP_SETATTR] = { 2280b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 2281b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 2282c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 228358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize, 22841e97b519STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid, 2285b591480bSJ.Bruce Fields }, 2286b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 2287b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 228858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2289c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2290b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 229158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize, 2292b591480bSJ.Bruce Fields }, 2293b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 2294b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 229558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 2296c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 2297b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 229858e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2299b591480bSJ.Bruce Fields }, 2300b591480bSJ.Bruce Fields [OP_VERIFY] = { 2301b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 2302b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 23032282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2304b591480bSJ.Bruce Fields }, 2305b591480bSJ.Bruce Fields [OP_WRITE] = { 2306b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 2307c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2308b001a1b6SBenny Halevy .op_name = "OP_WRITE", 230958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 231030813e27STigran Mkrtchyan .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid, 2311b591480bSJ.Bruce Fields }, 2312b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 2313b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 231458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 231558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2316b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 231758e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2318b591480bSJ.Bruce Fields }, 2319069b6ad4SAndy Adamson 2320069b6ad4SAndy Adamson /* NFSv4.1 operations */ 2321069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 2322069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 232358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 232458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2325069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 232658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize, 2327069b6ad4SAndy Adamson }, 2328cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 2329cb73a9f4SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_backchannel_ctl, 2330cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2331cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 2332cb73a9f4SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2333cb73a9f4SJ. Bruce Fields }, 23341d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 23351d1bc8f2SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, 233658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 233758e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 23381d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 233958e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize, 23401d1bc8f2SJ. Bruce Fields }, 2341069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 2342069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 234358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 234458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2345069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 234658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize, 2347069b6ad4SAndy Adamson }, 2348069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 2349069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 235058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 235158e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2352069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 235358e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2354069b6ad4SAndy Adamson }, 2355069b6ad4SAndy Adamson [OP_SEQUENCE] = { 2356069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 2357f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 2358069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 2359d1d84c96SJ. Bruce Fields .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize, 2360069b6ad4SAndy Adamson }, 2361094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 2362345c2842SMi Jinlong .op_func = (nfsd4op_func)nfsd4_destroy_clientid, 236358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 236458e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 2365094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 236658e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2367094b5d74SBenny Halevy }, 23684dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 23694dc6ec00SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_reclaim_complete, 237058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 23714dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 237258e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 23734dc6ec00SJ. Bruce Fields }, 237404f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 237504f4ad16SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, 237668d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 237704f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 23782282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_secinfo_rsize, 237904f4ad16SJ. Bruce Fields }, 238017456804SBryan Schumaker [OP_TEST_STATEID] = { 238117456804SBryan Schumaker .op_func = (nfsd4op_func)nfsd4_test_stateid, 238217456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 238317456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 23842282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_test_stateid_rsize, 238517456804SBryan Schumaker }, 2386e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 2387e1ca12dfSBryan Schumaker .op_func = (nfsd4op_func)nfsd4_free_stateid, 238858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 2389e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 2390a1dc6955SJ. Bruce Fields .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid, 239158e7b33aSMi Jinlong .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2392e1ca12dfSBryan Schumaker }, 23939cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 23949cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 23959cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_getdeviceinfo, 23969cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 23979cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 23982282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_getdeviceinfo_rsize, 23999cf514ccSChristoph Hellwig }, 24009cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 24019cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutget, 24029cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 24039cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 24049cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize, 24059cf514ccSChristoph Hellwig }, 24069cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 24079cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutcommit, 24089cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 24099cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 24109cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize, 24119cf514ccSChristoph Hellwig }, 24129cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 24139cf514ccSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_layoutreturn, 24149cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 24159cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 24169cf514ccSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize, 24179cf514ccSChristoph Hellwig }, 24189cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 241924bab491SAnna Schumaker 242024bab491SAnna Schumaker /* NFSv4.2 operations */ 242195d871f0SAnna Schumaker [OP_ALLOCATE] = { 242295d871f0SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_allocate, 242395d871f0SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 242495d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 2425beaca234SKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 242695d871f0SAnna Schumaker }, 2427b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 2428b0cb9085SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_deallocate, 2429b0cb9085SAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2430b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 2431beaca234SKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2432b0cb9085SAnna Schumaker }, 2433ffa0160aSChristoph Hellwig [OP_CLONE] = { 2434ffa0160aSChristoph Hellwig .op_func = (nfsd4op_func)nfsd4_clone, 2435ffa0160aSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2436ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 2437ffa0160aSChristoph Hellwig .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, 2438ffa0160aSChristoph Hellwig }, 243929ae7f9dSAnna Schumaker [OP_COPY] = { 244029ae7f9dSAnna Schumaker .op_func = (nfsd4op_func)nfsd4_copy, 244129ae7f9dSAnna Schumaker .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 244229ae7f9dSAnna Schumaker .op_name = "OP_COPY", 244329ae7f9dSAnna Schumaker .op_rsize_bop = (nfsd4op_rsize)nfsd4_copy_rsize, 244429ae7f9dSAnna Schumaker }, 244524bab491SAnna Schumaker [OP_SEEK] = { 244624bab491SAnna Schumaker .op_func = (nfsd4op_func)nfsd4_seek, 244724bab491SAnna Schumaker .op_name = "OP_SEEK", 24482282cd2cSKinglong Mee .op_rsize_bop = (nfsd4op_rsize)nfsd4_seek_rsize, 244924bab491SAnna Schumaker }, 2450b591480bSJ.Bruce Fields }; 2451b591480bSJ.Bruce Fields 2452ed941643SAndrew Elble /** 2453ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 2454ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 2455ed941643SAndrew Elble * 2456ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 2457ed941643SAndrew Elble * 2458ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 2459ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 2460ed941643SAndrew Elble */ 2461ed941643SAndrew Elble 2462ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 2463ed941643SAndrew Elble { 2464ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 2465ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 2466ed941643SAndrew Elble struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 2467ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 2468ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 2469ed941643SAndrew Elble u32 opiter; 2470ed941643SAndrew Elble 2471ed941643SAndrew Elble if (!cstate->minorversion) 2472ed941643SAndrew Elble return false; 2473ed941643SAndrew Elble 2474ed941643SAndrew Elble if (cstate->spo_must_allowed == true) 2475ed941643SAndrew Elble return true; 2476ed941643SAndrew Elble 2477ed941643SAndrew Elble opiter = resp->opcnt; 2478ed941643SAndrew Elble while (opiter < argp->opcnt) { 2479ed941643SAndrew Elble this = &argp->ops[opiter++]; 2480ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 2481ed941643SAndrew Elble cstate->clp->cl_mach_cred && 2482ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 2483ed941643SAndrew Elble cstate->spo_must_allowed = true; 2484ed941643SAndrew Elble return true; 2485ed941643SAndrew Elble } 2486ed941643SAndrew Elble } 2487ed941643SAndrew Elble cstate->spo_must_allowed = false; 2488ed941643SAndrew Elble return false; 2489ed941643SAndrew Elble } 2490ed941643SAndrew Elble 24914f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 24924f0cefbfSJ. Bruce Fields { 249305b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 24944f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 24952282cd2cSKinglong Mee 24962282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 24972282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 24984f0cefbfSJ. Bruce Fields } 24994f0cefbfSJ. Bruce Fields 250007d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 250107d1f802SJ. Bruce Fields { 250207d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 250307d1f802SJ. Bruce Fields pr_err("unable to encode reply to nonidempotent op %d (%s)\n", 250407d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 250507d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 250607d1f802SJ. Bruce Fields } 250707d1f802SJ. Bruce Fields } 250807d1f802SJ. Bruce Fields 2509f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 2510b001a1b6SBenny Halevy { 2511b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 2512b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 2513b001a1b6SBenny Halevy return "unknown_operation"; 2514b001a1b6SBenny Halevy } 2515b001a1b6SBenny Halevy 25161da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 25171da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 25181da177e4SLinus Torvalds 25191da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 25200a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 2521*f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 25220a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, 25230a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_voidargs), 25240a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_voidres), 25250a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 25260a93a47fSYu Zhiguo .pc_xdrressize = 1, 25270a93a47fSYu Zhiguo }, 25280a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 2529*f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 25300a93a47fSYu Zhiguo .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs, 25310a93a47fSYu Zhiguo .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, 25320a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 25330a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 25343e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 25350a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 25360a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 25370a93a47fSYu Zhiguo }, 25381da177e4SLinus Torvalds }; 25391da177e4SLinus Torvalds 25401da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 25411da177e4SLinus Torvalds .vs_vers = 4, 25421da177e4SLinus Torvalds .vs_nproc = 2, 25431da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 25441da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 25451da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 254605a45a2dSJeff Layton .vs_rpcb_optnl = true, 25475283b03eSJeff Layton .vs_need_cong_ctrl = true, 25481da177e4SLinus Torvalds }; 25491da177e4SLinus Torvalds 25501da177e4SLinus Torvalds /* 25511da177e4SLinus Torvalds * Local variables: 25521da177e4SLinus Torvalds * c-basic-offset: 8 25531da177e4SLinus Torvalds * End: 25541da177e4SLinus Torvalds */ 2555