11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Server-side procedures for NFSv4. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (c) 2002 The Regents of the University of Michigan. 51da177e4SLinus Torvalds * All rights reserved. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Kendrick Smith <kmsmith@umich.edu> 81da177e4SLinus Torvalds * Andy Adamson <andros@umich.edu> 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without 111da177e4SLinus Torvalds * modification, are permitted provided that the following conditions 121da177e4SLinus Torvalds * are met: 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright 151da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer. 161da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright 171da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer in the 181da177e4SLinus Torvalds * documentation and/or other materials provided with the distribution. 191da177e4SLinus Torvalds * 3. Neither the name of the University nor the names of its 201da177e4SLinus Torvalds * contributors may be used to endorse or promote products derived 211da177e4SLinus Torvalds * from this software without specific prior written permission. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 241da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 251da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 261da177e4SLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271da177e4SLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 281da177e4SLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 291da177e4SLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 301da177e4SLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 311da177e4SLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 321da177e4SLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 331da177e4SLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 341da177e4SLinus Torvalds */ 35880a3a53SJ. Bruce Fields #include <linux/fs_struct.h> 367e06b7f9SNeilBrown #include <linux/file.h> 37b0cb9085SAnna Schumaker #include <linux/falloc.h> 385a0e3ad6STejun Heo #include <linux/slab.h> 39e0639dc5SOlga Kornievskaia #include <linux/kthread.h> 40254454a5SChuck Lever #include <linux/namei.h> 41254454a5SChuck Lever 42624322f1SOlga Kornievskaia #include <linux/sunrpc/addr.h> 430cfcd405SDai Ngo #include <linux/nfs_ssc.h> 441da177e4SLinus Torvalds 4558e7b33aSMi Jinlong #include "idmap.h" 469a74af21SBoaz Harrosh #include "cache.h" 479a74af21SBoaz Harrosh #include "xdr4.h" 480a3adadeSJ. Bruce Fields #include "vfs.h" 498b70484cSTigran Mkrtchyan #include "current_stateid.h" 503320fef1SStanislav Kinsbursky #include "netns.h" 514ac7249eSChristoph Hellwig #include "acl.h" 529cf514ccSChristoph Hellwig #include "pnfs.h" 5331ef83dcSChristoph Hellwig #include "trace.h" 541da177e4SLinus Torvalds 55d6c9e436SChuck Lever static bool inter_copy_offload_enable; 56d6c9e436SChuck Lever module_param(inter_copy_offload_enable, bool, 0644); 57d6c9e436SChuck Lever MODULE_PARM_DESC(inter_copy_offload_enable, 58d6c9e436SChuck Lever "Enable inter server to server copy offload. Default: false"); 59d6c9e436SChuck Lever 60f4e44b39SDai Ngo #ifdef CONFIG_NFSD_V4_2_INTER_SSC 61f4e44b39SDai Ngo static int nfsd4_ssc_umount_timeout = 900000; /* default to 15 mins */ 62f4e44b39SDai Ngo module_param(nfsd4_ssc_umount_timeout, int, 0644); 63f4e44b39SDai Ngo MODULE_PARM_DESC(nfsd4_ssc_umount_timeout, 64f4e44b39SDai Ngo "idle msecs before unmount export from source server"); 65f4e44b39SDai Ngo #endif 66f4e44b39SDai Ngo 6718032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 6818032ca0SDavid Quigley #include <linux/security.h> 6918032ca0SDavid Quigley 7018032ca0SDavid Quigley static inline void 7118032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 7218032ca0SDavid Quigley { 732b0143b5SDavid Howells struct inode *inode = d_inode(resfh->fh_dentry); 7418032ca0SDavid Quigley int status; 7518032ca0SDavid Quigley 765955102cSAl Viro inode_lock(inode); 7718032ca0SDavid Quigley status = security_inode_setsecctx(resfh->fh_dentry, 7818032ca0SDavid Quigley label->data, label->len); 795955102cSAl Viro inode_unlock(inode); 8018032ca0SDavid Quigley 8118032ca0SDavid Quigley if (status) 8218032ca0SDavid Quigley /* 8318032ca0SDavid Quigley * XXX: We should really fail the whole open, but we may 8418032ca0SDavid Quigley * already have created a new file, so it may be too 8518032ca0SDavid Quigley * late. For now this seems the least of evils: 8618032ca0SDavid Quigley */ 8718032ca0SDavid Quigley bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 8818032ca0SDavid Quigley 8918032ca0SDavid Quigley return; 9018032ca0SDavid Quigley } 9118032ca0SDavid Quigley #else 9218032ca0SDavid Quigley static inline void 9318032ca0SDavid Quigley nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 9418032ca0SDavid Quigley { } 9518032ca0SDavid Quigley #endif 9618032ca0SDavid Quigley 971da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 981da177e4SLinus Torvalds 993c8e0316SYu Zhiguo static u32 nfsd_attrmask[] = { 1003c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD0, 1013c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD1, 1023c8e0316SYu Zhiguo NFSD_WRITEABLE_ATTRS_WORD2 1033c8e0316SYu Zhiguo }; 1043c8e0316SYu Zhiguo 1053c8e0316SYu Zhiguo static u32 nfsd41_ex_attrmask[] = { 1063c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD0, 1073c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD1, 1083c8e0316SYu Zhiguo NFSD_SUPPATTR_EXCLCREAT_WORD2 1093c8e0316SYu Zhiguo }; 1103c8e0316SYu Zhiguo 1113c8e0316SYu Zhiguo static __be32 1123c8e0316SYu Zhiguo check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1133c8e0316SYu Zhiguo u32 *bmval, u32 *writable) 1143c8e0316SYu Zhiguo { 1153c8e0316SYu Zhiguo struct dentry *dentry = cstate->current_fh.fh_dentry; 11632ddd944SJ. Bruce Fields struct svc_export *exp = cstate->current_fh.fh_export; 1173c8e0316SYu Zhiguo 118916d2d84SJ. Bruce Fields if (!nfsd_attrs_supported(cstate->minorversion, bmval)) 1193c8e0316SYu Zhiguo return nfserr_attrnotsupp; 120916d2d84SJ. Bruce Fields if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) 1213c8e0316SYu Zhiguo return nfserr_attrnotsupp; 12232ddd944SJ. Bruce Fields if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && 12332ddd944SJ. Bruce Fields !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) 12432ddd944SJ. Bruce Fields return nfserr_attrnotsupp; 125916d2d84SJ. Bruce Fields if (writable && !bmval_is_subset(bmval, writable)) 1263c8e0316SYu Zhiguo return nfserr_inval; 12747057abdSAndreas Gruenbacher if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && 12847057abdSAndreas Gruenbacher (bmval[1] & FATTR4_WORD1_MODE)) 12947057abdSAndreas Gruenbacher return nfserr_inval; 1303c8e0316SYu Zhiguo return nfs_ok; 1313c8e0316SYu Zhiguo } 1323c8e0316SYu Zhiguo 1333c8e0316SYu Zhiguo static __be32 1343c8e0316SYu Zhiguo nfsd4_check_open_attributes(struct svc_rqst *rqstp, 1353c8e0316SYu Zhiguo struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 1363c8e0316SYu Zhiguo { 1373c8e0316SYu Zhiguo __be32 status = nfs_ok; 1383c8e0316SYu Zhiguo 1393c8e0316SYu Zhiguo if (open->op_create == NFS4_OPEN_CREATE) { 1403c8e0316SYu Zhiguo if (open->op_createmode == NFS4_CREATE_UNCHECKED 1413c8e0316SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED) 1423c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1433c8e0316SYu Zhiguo open->op_bmval, nfsd_attrmask); 1443c8e0316SYu Zhiguo else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) 1453c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, 1463c8e0316SYu Zhiguo open->op_bmval, nfsd41_ex_attrmask); 1473c8e0316SYu Zhiguo } 1483c8e0316SYu Zhiguo 1493c8e0316SYu Zhiguo return status; 1503c8e0316SYu Zhiguo } 1513c8e0316SYu Zhiguo 1529208faf2SYu Zhiguo static int 1539208faf2SYu Zhiguo is_create_with_attrs(struct nfsd4_open *open) 1549208faf2SYu Zhiguo { 1559208faf2SYu Zhiguo return open->op_create == NFS4_OPEN_CREATE 1569208faf2SYu Zhiguo && (open->op_createmode == NFS4_CREATE_UNCHECKED 1579208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_GUARDED 1589208faf2SYu Zhiguo || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); 1599208faf2SYu Zhiguo } 1609208faf2SYu Zhiguo 1619208faf2SYu Zhiguo /* 1629208faf2SYu Zhiguo * if error occurs when setting the acl, just clear the acl bit 1639208faf2SYu Zhiguo * in the returned attr bitmap. 1649208faf2SYu Zhiguo */ 1659208faf2SYu Zhiguo static void 1669208faf2SYu Zhiguo do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, 1679208faf2SYu Zhiguo struct nfs4_acl *acl, u32 *bmval) 1689208faf2SYu Zhiguo { 1699208faf2SYu Zhiguo __be32 status; 1709208faf2SYu Zhiguo 1719208faf2SYu Zhiguo status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); 1729208faf2SYu Zhiguo if (status) 1739208faf2SYu Zhiguo /* 1749208faf2SYu Zhiguo * We should probably fail the whole open at this point, 1759208faf2SYu Zhiguo * but we've already created the file, so it's too late; 1769208faf2SYu Zhiguo * So this seems the least of evils: 1779208faf2SYu Zhiguo */ 1789208faf2SYu Zhiguo bmval[0] &= ~FATTR4_WORD0_ACL; 1799208faf2SYu Zhiguo } 1809208faf2SYu Zhiguo 1811da177e4SLinus Torvalds static inline void 1821da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 1831da177e4SLinus Torvalds { 1841da177e4SLinus Torvalds fh_put(dst); 1851da177e4SLinus Torvalds dget(src->fh_dentry); 1861da177e4SLinus Torvalds if (src->fh_export) 187bf18f163SKinglong Mee exp_get(src->fh_export); 1881da177e4SLinus Torvalds *dst = *src; 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds 191b37ad28bSAl Viro static __be32 192dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 1931da177e4SLinus Torvalds { 194b37ad28bSAl Viro __be32 status; 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds if (open->op_truncate && 1971da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 1981da177e4SLinus Torvalds return nfserr_inval; 1991da177e4SLinus Torvalds 200a043226bSJ. Bruce Fields accmode |= NFSD_MAY_READ_IF_EXEC; 201a043226bSJ. Bruce Fields 2021da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 2038837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 2049801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 2058837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 20657ecb34fSJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_READ) 2078837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds return status; 2121da177e4SLinus Torvalds } 2131da177e4SLinus Torvalds 214aadab6c6SJ. Bruce Fields static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 215aadab6c6SJ. Bruce Fields { 2162b0143b5SDavid Howells umode_t mode = d_inode(fh->fh_dentry)->i_mode; 217aadab6c6SJ. Bruce Fields 218aadab6c6SJ. Bruce Fields if (S_ISREG(mode)) 219aadab6c6SJ. Bruce Fields return nfs_ok; 220aadab6c6SJ. Bruce Fields if (S_ISDIR(mode)) 221aadab6c6SJ. Bruce Fields return nfserr_isdir; 222aadab6c6SJ. Bruce Fields /* 223aadab6c6SJ. Bruce Fields * Using err_symlink as our catch-all case may look odd; but 224aadab6c6SJ. Bruce Fields * there's no other obvious error for this case in 4.0, and we 225aadab6c6SJ. Bruce Fields * happen to know that it will cause the linux v4 client to do 226aadab6c6SJ. Bruce Fields * the right thing on attempts to open something other than a 227aadab6c6SJ. Bruce Fields * regular file. 228aadab6c6SJ. Bruce Fields */ 229aadab6c6SJ. Bruce Fields return nfserr_symlink; 230aadab6c6SJ. Bruce Fields } 231aadab6c6SJ. Bruce Fields 232bbc9c36cSJ. Bruce Fields static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) 2331da177e4SLinus Torvalds { 234bbc9c36cSJ. Bruce Fields if (nfsd4_has_session(cstate)) 235bbc9c36cSJ. Bruce Fields return; 236bbc9c36cSJ. Bruce Fields fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, 237bbc9c36cSJ. Bruce Fields &resfh->fh_handle); 238bbc9c36cSJ. Bruce Fields } 239bbc9c36cSJ. Bruce Fields 240254454a5SChuck Lever static inline bool nfsd4_create_is_exclusive(int createmode) 241254454a5SChuck Lever { 242254454a5SChuck Lever return createmode == NFS4_CREATE_EXCLUSIVE || 243254454a5SChuck Lever createmode == NFS4_CREATE_EXCLUSIVE4_1; 244254454a5SChuck Lever } 245254454a5SChuck Lever 246fb70bf12SChuck Lever static __be32 247fb70bf12SChuck Lever nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child, 248fb70bf12SChuck Lever struct nfsd4_open *open) 249fb70bf12SChuck Lever { 250fb70bf12SChuck Lever struct file *filp; 251fb70bf12SChuck Lever struct path path; 252fb70bf12SChuck Lever int oflags; 253fb70bf12SChuck Lever 254fb70bf12SChuck Lever oflags = O_CREAT | O_LARGEFILE; 255fb70bf12SChuck Lever switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) { 256fb70bf12SChuck Lever case NFS4_SHARE_ACCESS_WRITE: 257fb70bf12SChuck Lever oflags |= O_WRONLY; 258fb70bf12SChuck Lever break; 259fb70bf12SChuck Lever case NFS4_SHARE_ACCESS_BOTH: 260fb70bf12SChuck Lever oflags |= O_RDWR; 261fb70bf12SChuck Lever break; 262fb70bf12SChuck Lever default: 263fb70bf12SChuck Lever oflags |= O_RDONLY; 264fb70bf12SChuck Lever } 265fb70bf12SChuck Lever 266fb70bf12SChuck Lever path.mnt = fhp->fh_export->ex_path.mnt; 267fb70bf12SChuck Lever path.dentry = child; 268fb70bf12SChuck Lever filp = dentry_create(&path, oflags, open->op_iattr.ia_mode, 269fb70bf12SChuck Lever current_cred()); 270fb70bf12SChuck Lever if (IS_ERR(filp)) 271fb70bf12SChuck Lever return nfserrno(PTR_ERR(filp)); 272fb70bf12SChuck Lever 273fb70bf12SChuck Lever open->op_filp = filp; 274fb70bf12SChuck Lever return nfs_ok; 275fb70bf12SChuck Lever } 276fb70bf12SChuck Lever 277254454a5SChuck Lever /* 278254454a5SChuck Lever * Implement NFSv4's unchecked, guarded, and exclusive create 279254454a5SChuck Lever * semantics for regular files. Open state for this new file is 280254454a5SChuck Lever * subsequently fabricated in nfsd4_process_open2(). 281254454a5SChuck Lever * 282254454a5SChuck Lever * Upon return, caller must release @fhp and @resfhp. 283254454a5SChuck Lever */ 284254454a5SChuck Lever static __be32 285254454a5SChuck Lever nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, 286254454a5SChuck Lever struct svc_fh *resfhp, struct nfsd4_open *open) 287254454a5SChuck Lever { 288254454a5SChuck Lever struct iattr *iap = &open->op_iattr; 289254454a5SChuck Lever struct dentry *parent, *child; 290254454a5SChuck Lever __u32 v_mtime, v_atime; 291254454a5SChuck Lever struct inode *inode; 292254454a5SChuck Lever __be32 status; 293254454a5SChuck Lever int host_err; 294254454a5SChuck Lever 295254454a5SChuck Lever if (isdotent(open->op_fname, open->op_fnamelen)) 296254454a5SChuck Lever return nfserr_exist; 297254454a5SChuck Lever if (!(iap->ia_valid & ATTR_MODE)) 298254454a5SChuck Lever iap->ia_mode = 0; 299254454a5SChuck Lever 300254454a5SChuck Lever status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC); 301254454a5SChuck Lever if (status != nfs_ok) 302254454a5SChuck Lever return status; 303254454a5SChuck Lever parent = fhp->fh_dentry; 304254454a5SChuck Lever inode = d_inode(parent); 305254454a5SChuck Lever 306254454a5SChuck Lever host_err = fh_want_write(fhp); 307254454a5SChuck Lever if (host_err) 308254454a5SChuck Lever return nfserrno(host_err); 309254454a5SChuck Lever 310254454a5SChuck Lever fh_lock_nested(fhp, I_MUTEX_PARENT); 311254454a5SChuck Lever 312254454a5SChuck Lever child = lookup_one_len(open->op_fname, parent, open->op_fnamelen); 313254454a5SChuck Lever if (IS_ERR(child)) { 314254454a5SChuck Lever status = nfserrno(PTR_ERR(child)); 315254454a5SChuck Lever goto out; 316254454a5SChuck Lever } 317254454a5SChuck Lever 318254454a5SChuck Lever if (d_really_is_negative(child)) { 319254454a5SChuck Lever status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE); 320254454a5SChuck Lever if (status != nfs_ok) 321254454a5SChuck Lever goto out; 322254454a5SChuck Lever } 323254454a5SChuck Lever 324254454a5SChuck Lever status = fh_compose(resfhp, fhp->fh_export, child, fhp); 325254454a5SChuck Lever if (status != nfs_ok) 326254454a5SChuck Lever goto out; 327254454a5SChuck Lever 328254454a5SChuck Lever v_mtime = 0; 329254454a5SChuck Lever v_atime = 0; 330254454a5SChuck Lever if (nfsd4_create_is_exclusive(open->op_createmode)) { 331254454a5SChuck Lever u32 *verifier = (u32 *)open->op_verf.data; 332254454a5SChuck Lever 333254454a5SChuck Lever /* 334254454a5SChuck Lever * Solaris 7 gets confused (bugid 4218508) if these have 335254454a5SChuck Lever * the high bit set, as do xfs filesystems without the 336254454a5SChuck Lever * "bigtime" feature. So just clear the high bits. If this 337254454a5SChuck Lever * is ever changed to use different attrs for storing the 338254454a5SChuck Lever * verifier, then do_open_lookup() will also need to be 339254454a5SChuck Lever * fixed accordingly. 340254454a5SChuck Lever */ 341254454a5SChuck Lever v_mtime = verifier[0] & 0x7fffffff; 342254454a5SChuck Lever v_atime = verifier[1] & 0x7fffffff; 343254454a5SChuck Lever } 344254454a5SChuck Lever 345254454a5SChuck Lever if (d_really_is_positive(child)) { 346254454a5SChuck Lever status = nfs_ok; 347254454a5SChuck Lever 348254454a5SChuck Lever switch (open->op_createmode) { 349254454a5SChuck Lever case NFS4_CREATE_UNCHECKED: 350254454a5SChuck Lever if (!d_is_reg(child)) 351254454a5SChuck Lever break; 352254454a5SChuck Lever 353254454a5SChuck Lever /* 354254454a5SChuck Lever * In NFSv4, we don't want to truncate the file 355254454a5SChuck Lever * now. This would be wrong if the OPEN fails for 356254454a5SChuck Lever * some other reason. Furthermore, if the size is 357254454a5SChuck Lever * nonzero, we should ignore it according to spec! 358254454a5SChuck Lever */ 359254454a5SChuck Lever open->op_truncate = (iap->ia_valid & ATTR_SIZE) && 360254454a5SChuck Lever !iap->ia_size; 361254454a5SChuck Lever break; 362254454a5SChuck Lever case NFS4_CREATE_GUARDED: 363254454a5SChuck Lever status = nfserr_exist; 364254454a5SChuck Lever break; 365254454a5SChuck Lever case NFS4_CREATE_EXCLUSIVE: 366254454a5SChuck Lever if (d_inode(child)->i_mtime.tv_sec == v_mtime && 367254454a5SChuck Lever d_inode(child)->i_atime.tv_sec == v_atime && 368254454a5SChuck Lever d_inode(child)->i_size == 0) { 369254454a5SChuck Lever open->op_created = true; 370254454a5SChuck Lever break; /* subtle */ 371254454a5SChuck Lever } 372254454a5SChuck Lever status = nfserr_exist; 373254454a5SChuck Lever break; 374254454a5SChuck Lever case NFS4_CREATE_EXCLUSIVE4_1: 375254454a5SChuck Lever if (d_inode(child)->i_mtime.tv_sec == v_mtime && 376254454a5SChuck Lever d_inode(child)->i_atime.tv_sec == v_atime && 377254454a5SChuck Lever d_inode(child)->i_size == 0) { 378254454a5SChuck Lever open->op_created = true; 379254454a5SChuck Lever goto set_attr; /* subtle */ 380254454a5SChuck Lever } 381254454a5SChuck Lever status = nfserr_exist; 382254454a5SChuck Lever } 383254454a5SChuck Lever goto out; 384254454a5SChuck Lever } 385254454a5SChuck Lever 386254454a5SChuck Lever if (!IS_POSIXACL(inode)) 387254454a5SChuck Lever iap->ia_mode &= ~current_umask(); 388254454a5SChuck Lever 389fb70bf12SChuck Lever status = nfsd4_vfs_create(fhp, child, open); 390fb70bf12SChuck Lever if (status != nfs_ok) 391254454a5SChuck Lever goto out; 392254454a5SChuck Lever open->op_created = true; 393254454a5SChuck Lever 394254454a5SChuck Lever /* A newly created file already has a file size of zero. */ 395254454a5SChuck Lever if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0)) 396254454a5SChuck Lever iap->ia_valid &= ~ATTR_SIZE; 397254454a5SChuck Lever if (nfsd4_create_is_exclusive(open->op_createmode)) { 398254454a5SChuck Lever iap->ia_valid = ATTR_MTIME | ATTR_ATIME | 399254454a5SChuck Lever ATTR_MTIME_SET|ATTR_ATIME_SET; 400254454a5SChuck Lever iap->ia_mtime.tv_sec = v_mtime; 401254454a5SChuck Lever iap->ia_atime.tv_sec = v_atime; 402254454a5SChuck Lever iap->ia_mtime.tv_nsec = 0; 403254454a5SChuck Lever iap->ia_atime.tv_nsec = 0; 404254454a5SChuck Lever } 405254454a5SChuck Lever 406254454a5SChuck Lever set_attr: 407254454a5SChuck Lever status = nfsd_create_setattr(rqstp, fhp, resfhp, iap); 408254454a5SChuck Lever 409254454a5SChuck Lever out: 410254454a5SChuck Lever fh_unlock(fhp); 411254454a5SChuck Lever if (child && !IS_ERR(child)) 412254454a5SChuck Lever dput(child); 413254454a5SChuck Lever fh_drop_write(fhp); 414254454a5SChuck Lever return status; 415254454a5SChuck Lever } 416254454a5SChuck Lever 417bbc9c36cSJ. Bruce Fields static __be32 418c0e6bee4SJ. Bruce Fields do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) 419bbc9c36cSJ. Bruce Fields { 420bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 4217007c90fSNeil Brown int accmode; 422b37ad28bSAl Viro __be32 status; 4231da177e4SLinus Torvalds 424c0e6bee4SJ. Bruce Fields *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); 425c0e6bee4SJ. Bruce Fields if (!*resfh) 42659deeb9eSJ. Bruce Fields return nfserr_jukebox; 427c0e6bee4SJ. Bruce Fields fh_init(*resfh, NFS4_FHSIZE); 428500c2481Szhengbin open->op_truncate = false; 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds if (open->op_create) { 43179fb54abSBenny Halevy /* FIXME: check session persistence and pnfs flags. 43279fb54abSBenny Halevy * The nfsv4.1 spec requires the following semantics: 43379fb54abSBenny Halevy * 43479fb54abSBenny Halevy * Persistent | pNFS | Server REQUIRED | Client Allowed 43579fb54abSBenny Halevy * Reply Cache | server | | 43679fb54abSBenny Halevy * -------------+--------+-----------------+-------------------- 43779fb54abSBenny Halevy * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 43879fb54abSBenny Halevy * | | | (SHOULD) 43979fb54abSBenny Halevy * | | and EXCLUSIVE4 | or EXCLUSIVE4 44079fb54abSBenny Halevy * | | | (SHOULD NOT) 44179fb54abSBenny Halevy * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 44279fb54abSBenny Halevy * yes | no | GUARDED4 | GUARDED4 44379fb54abSBenny Halevy * yes | yes | GUARDED4 | GUARDED4 44479fb54abSBenny Halevy */ 44579fb54abSBenny Halevy 446880a3a53SJ. Bruce Fields current->fs->umask = open->op_umask; 447254454a5SChuck Lever status = nfsd4_create_file(rqstp, current_fh, *resfh, open); 448880a3a53SJ. Bruce Fields current->fs->umask = 0; 449749997e5SJeff Layton 45018032ca0SDavid Quigley if (!status && open->op_label.len) 451c0e6bee4SJ. Bruce Fields nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); 45218032ca0SDavid Quigley 45399f88726SJ. Bruce Fields /* 454ead8fb8cSKinglong Mee * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 455ead8fb8cSKinglong Mee * use the returned bitmask to indicate which attributes 456ead8fb8cSKinglong Mee * we used to store the verifier: 457749997e5SJeff Layton */ 458254454a5SChuck Lever if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0) 459ead8fb8cSKinglong Mee open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | 460749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 4614335723eSJ. Bruce Fields } else 4624335723eSJ. Bruce Fields /* 4634335723eSJ. Bruce Fields * Note this may exit with the parent still locked. 4644335723eSJ. Bruce Fields * We will hold the lock until nfsd4_open's final 4654335723eSJ. Bruce Fields * lookup, to prevent renames or unlinks until we've had 4664335723eSJ. Bruce Fields * a chance to an acquire a delegation if appropriate. 4674335723eSJ. Bruce Fields */ 4681da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 4691708e50bSChuck Lever open->op_fname, open->op_fnamelen, *resfh); 470aadab6c6SJ. Bruce Fields if (status) 471aadab6c6SJ. Bruce Fields goto out; 472c0e6bee4SJ. Bruce Fields status = nfsd_check_obj_isreg(*resfh); 473af85852dSJ. Bruce Fields if (status) 474af85852dSJ. Bruce Fields goto out; 4751da177e4SLinus Torvalds 4769208faf2SYu Zhiguo if (is_create_with_attrs(open) && open->op_acl != NULL) 477c0e6bee4SJ. Bruce Fields do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); 4789208faf2SYu Zhiguo 479c0e6bee4SJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); 4807007c90fSNeil Brown accmode = NFSD_MAY_NOP; 48189f6c336SJ. Bruce Fields if (open->op_created || 48289f6c336SJ. Bruce Fields open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) 4837007c90fSNeil Brown accmode |= NFSD_MAY_OWNER_OVERRIDE; 484c0e6bee4SJ. Bruce Fields status = do_open_permission(rqstp, *resfh, open, accmode); 48541fd1e42SJ. Bruce Fields set_change_info(&open->op_cinfo, current_fh); 486af85852dSJ. Bruce Fields out: 4871da177e4SLinus Torvalds return status; 4881da177e4SLinus Torvalds } 4891da177e4SLinus Torvalds 490b37ad28bSAl Viro static __be32 491bbc9c36cSJ. Bruce Fields do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) 4921da177e4SLinus Torvalds { 493bbc9c36cSJ. Bruce Fields struct svc_fh *current_fh = &cstate->current_fh; 494b37ad28bSAl Viro __be32 status; 4959f415eb2SJ. Bruce Fields int accmode = 0; 4961da177e4SLinus Torvalds 4971da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 4981da177e4SLinus Torvalds * set the change info 4991da177e4SLinus Torvalds */ 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 5021da177e4SLinus Torvalds 503bbc9c36cSJ. Bruce Fields nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); 5041da177e4SLinus Torvalds 5051da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 5061da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 5079f415eb2SJ. Bruce Fields /* 5089f415eb2SJ. Bruce Fields * In the delegation case, the client is telling us about an 5099f415eb2SJ. Bruce Fields * open that it *already* performed locally, some time ago. We 5109f415eb2SJ. Bruce Fields * should let it succeed now if possible. 5119f415eb2SJ. Bruce Fields * 5129f415eb2SJ. Bruce Fields * In the case of a CLAIM_FH open, on the other hand, the client 5139f415eb2SJ. Bruce Fields * may be counting on us to enforce permissions (the Linux 4.1 5149f415eb2SJ. Bruce Fields * client uses this for normal opens, for example). 5159f415eb2SJ. Bruce Fields */ 5169f415eb2SJ. Bruce Fields if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) 5179f415eb2SJ. Bruce Fields accmode = NFSD_MAY_OWNER_OVERRIDE; 5181da177e4SLinus Torvalds 5199f415eb2SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, accmode); 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds return status; 5221da177e4SLinus Torvalds } 5231da177e4SLinus Torvalds 52460adfc50SAndy Adamson static void 52560adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 52660adfc50SAndy Adamson { 52760adfc50SAndy Adamson struct nfsd4_sessionid *sid = 52860adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 52960adfc50SAndy Adamson 53060adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 53160adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 53260adfc50SAndy Adamson } 5331da177e4SLinus Torvalds 5347191155bSJ.Bruce Fields static __be32 535ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 536eb69853dSChristoph Hellwig union nfsd4_op_u *u) 5371da177e4SLinus Torvalds { 538eb69853dSChristoph Hellwig struct nfsd4_open *open = &u->open; 539b37ad28bSAl Viro __be32 status; 540c0e6bee4SJ. Bruce Fields struct svc_fh *resfh = NULL; 5413320fef1SStanislav Kinsbursky struct net *net = SVC_NET(rqstp); 5423320fef1SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 54303f318caSJ. Bruce Fields bool reclaim = false; 5446668958fSAndy Adamson 545fe0750e5SJ. Bruce Fields dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", 5461708e50bSChuck Lever (int)open->op_fnamelen, open->op_fname, 547fe0750e5SJ. Bruce Fields open->op_openowner); 5481da177e4SLinus Torvalds 549fb70bf12SChuck Lever open->op_filp = NULL; 550fb70bf12SChuck Lever 5511da177e4SLinus Torvalds /* This check required by spec. */ 5521da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 5531da177e4SLinus Torvalds return nfserr_inval; 5541da177e4SLinus Torvalds 555500c2481Szhengbin open->op_created = false; 556ab1350b2SMi Jinlong /* 557ab1350b2SMi Jinlong * RFC5661 18.51.3 558ab1350b2SMi Jinlong * Before RECLAIM_COMPLETE done, server should deny new lock 559ab1350b2SMi Jinlong */ 560ab1350b2SMi Jinlong if (nfsd4_has_session(cstate) && 561ec59659bSJ. Bruce Fields !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) && 562ab1350b2SMi Jinlong open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 563ab1350b2SMi Jinlong return nfserr_grace; 564ab1350b2SMi Jinlong 56560adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 56660adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 56760adfc50SAndy Adamson 5681da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 5696cd22668SKinglong Mee status = nfsd4_process_open1(cstate, open, nn); 570a90b061cSAl Viro if (status == nfserr_replay_me) { 571fe0750e5SJ. Bruce Fields struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; 572ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 573a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 574a4773c08SJ. Bruce Fields &rp->rp_openfh); 5758837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 5761da177e4SLinus Torvalds if (status) 5771da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 5781da177e4SLinus Torvalds " restoring previous filehandle\n"); 5791da177e4SLinus Torvalds else 580a90b061cSAl Viro status = nfserr_replay_me; 5811da177e4SLinus Torvalds } 5821da177e4SLinus Torvalds if (status) 5831da177e4SLinus Torvalds goto out; 5849d313b17SJ. Bruce Fields if (open->op_xdr_error) { 5859d313b17SJ. Bruce Fields status = open->op_xdr_error; 5869d313b17SJ. Bruce Fields goto out; 5879d313b17SJ. Bruce Fields } 588fb553c0fSJ. Bruce Fields 5893c8e0316SYu Zhiguo status = nfsd4_check_open_attributes(rqstp, cstate, open); 5903c8e0316SYu Zhiguo if (status) 5913c8e0316SYu Zhiguo goto out; 5923c8e0316SYu Zhiguo 593fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 594fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 595cbd0d51aSJ. Bruce Fields status = nfserr_grace; 596c87fb4a3SJ. Bruce Fields if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 597cbd0d51aSJ. Bruce Fields goto out; 598cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 599c87fb4a3SJ. Bruce Fields if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 600cbd0d51aSJ. Bruce Fields goto out; 601fb553c0fSJ. Bruce Fields 6021da177e4SLinus Torvalds switch (open->op_claim_type) { 6030dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 6041da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 605c0e6bee4SJ. Bruce Fields status = do_open_lookup(rqstp, cstate, open, &resfh); 6061da177e4SLinus Torvalds if (status) 6071da177e4SLinus Torvalds goto out; 6081da177e4SLinus Torvalds break; 6091da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 6101722b046SJ. Bruce Fields status = nfs4_check_open_reclaim(cstate->clp); 6110cf99b91SMi Jinlong if (status) 6120cf99b91SMi Jinlong goto out; 613ba5378b6SJeff Layton open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 61403f318caSJ. Bruce Fields reclaim = true; 615df561f66SGustavo A. R. Silva fallthrough; 6168b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_FH: 6178b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 618bbc9c36cSJ. Bruce Fields status = do_open_fhandle(rqstp, cstate, open); 6191da177e4SLinus Torvalds if (status) 6201da177e4SLinus Torvalds goto out; 621c0e6bee4SJ. Bruce Fields resfh = &cstate->current_fh; 6221da177e4SLinus Torvalds break; 6238b289b2cSJ. Bruce Fields case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 6241da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 6251da177e4SLinus Torvalds status = nfserr_notsupp; 6261da177e4SLinus Torvalds goto out; 6271da177e4SLinus Torvalds default: 6281da177e4SLinus Torvalds status = nfserr_inval; 6291da177e4SLinus Torvalds goto out; 6301da177e4SLinus Torvalds } 6317e2ce0ccSChuck Lever 632c0e6bee4SJ. Bruce Fields status = nfsd4_process_open2(rqstp, resfh, open); 633*ca3f9acbSChuck Lever if (status && open->op_created) 634*ca3f9acbSChuck Lever pr_warn("nfsd4_process_open2 failed to open newly-created file: status=%u\n", 635b3fbfe0eSJeff Layton be32_to_cpu(status)); 63603f318caSJ. Bruce Fields if (reclaim && !status) 63703f318caSJ. Bruce Fields nn->somebody_reclaimed = true; 6381da177e4SLinus Torvalds out: 639fb70bf12SChuck Lever if (open->op_filp) { 640fb70bf12SChuck Lever fput(open->op_filp); 641fb70bf12SChuck Lever open->op_filp = NULL; 642fb70bf12SChuck Lever } 643c0e6bee4SJ. Bruce Fields if (resfh && resfh != &cstate->current_fh) { 644c0e6bee4SJ. Bruce Fields fh_dup2(&cstate->current_fh, resfh); 645c0e6bee4SJ. Bruce Fields fh_put(resfh); 646c0e6bee4SJ. Bruce Fields kfree(resfh); 647c0e6bee4SJ. Bruce Fields } 64842297899SJeff Layton nfsd4_cleanup_open_state(cstate, open); 6499411b1d4SJ. Bruce Fields nfsd4_bump_seqid(cstate, status); 6501da177e4SLinus Torvalds return status; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds /* 6549d313b17SJ. Bruce Fields * OPEN is the only seqid-mutating operation whose decoding can fail 6559d313b17SJ. Bruce Fields * with a seqid-mutating error (specifically, decoding of user names in 6569d313b17SJ. Bruce Fields * the attributes). Therefore we have to do some processing to look up 6579d313b17SJ. Bruce Fields * the stateowner so that we can bump the seqid. 6589d313b17SJ. Bruce Fields */ 6599d313b17SJ. Bruce Fields static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) 6609d313b17SJ. Bruce Fields { 661eb69853dSChristoph Hellwig struct nfsd4_open *open = &op->u.open; 6629d313b17SJ. Bruce Fields 6639d313b17SJ. Bruce Fields if (!seqid_mutating_err(ntohl(op->status))) 6649d313b17SJ. Bruce Fields return op->status; 6659d313b17SJ. Bruce Fields if (nfsd4_has_session(cstate)) 6669d313b17SJ. Bruce Fields return op->status; 6679d313b17SJ. Bruce Fields open->op_xdr_error = op->status; 668eb69853dSChristoph Hellwig return nfsd4_open(rqstp, cstate, &op->u); 6699d313b17SJ. Bruce Fields } 6709d313b17SJ. Bruce Fields 6719d313b17SJ. Bruce Fields /* 6721da177e4SLinus Torvalds * filehandle-manipulating ops. 6731da177e4SLinus Torvalds */ 6747191155bSJ.Bruce Fields static __be32 675b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 676eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6771da177e4SLinus Torvalds { 678eb69853dSChristoph Hellwig u->getfh = &cstate->current_fh; 6791da177e4SLinus Torvalds return nfs_ok; 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds 6827191155bSJ.Bruce Fields static __be32 683ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 684eb69853dSChristoph Hellwig union nfsd4_op_u *u) 6851da177e4SLinus Torvalds { 686eb69853dSChristoph Hellwig struct nfsd4_putfh *putfh = &u->putfh; 687b9e8638eSOlga Kornievskaia __be32 ret; 688eb69853dSChristoph Hellwig 689ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 690ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 691d8b26071SNeilBrown memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval, 692ca364317SJ.Bruce Fields putfh->pf_fhlen); 693b9e8638eSOlga Kornievskaia ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); 694b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 695b9e8638eSOlga Kornievskaia if (ret == nfserr_stale && putfh->no_verify) { 696b9e8638eSOlga Kornievskaia SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN); 697b9e8638eSOlga Kornievskaia ret = 0; 698b9e8638eSOlga Kornievskaia } 699b9e8638eSOlga Kornievskaia #endif 700b9e8638eSOlga Kornievskaia return ret; 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds 7037191155bSJ.Bruce Fields static __be32 704b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 705eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7061da177e4SLinus Torvalds { 707b37ad28bSAl Viro __be32 status; 7081da177e4SLinus Torvalds 709ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 710df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 7111da177e4SLinus Torvalds return status; 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds 7147191155bSJ.Bruce Fields static __be32 715b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 716eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7171da177e4SLinus Torvalds { 718ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 7191da177e4SLinus Torvalds return nfserr_restorefh; 7201da177e4SLinus Torvalds 721ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 72251100d2bSOlga Kornievskaia if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) { 72337c593c5STigran Mkrtchyan memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); 72451100d2bSOlga Kornievskaia SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); 72537c593c5STigran Mkrtchyan } 7261da177e4SLinus Torvalds return nfs_ok; 7271da177e4SLinus Torvalds } 7281da177e4SLinus Torvalds 7297191155bSJ.Bruce Fields static __be32 730b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 731eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7321da177e4SLinus Torvalds { 733ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 73451100d2bSOlga Kornievskaia if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) { 73537c593c5STigran Mkrtchyan memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); 73651100d2bSOlga Kornievskaia SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG); 73737c593c5STigran Mkrtchyan } 7381da177e4SLinus Torvalds return nfs_ok; 7391da177e4SLinus Torvalds } 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds /* 7421da177e4SLinus Torvalds * misc nfsv4 ops 7431da177e4SLinus Torvalds */ 7447191155bSJ.Bruce Fields static __be32 745ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 746eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7471da177e4SLinus Torvalds { 748eb69853dSChristoph Hellwig struct nfsd4_access *access = &u->access; 749c11d7fd1SFrank van der Linden u32 access_full; 750eb69853dSChristoph Hellwig 751c11d7fd1SFrank van der Linden access_full = NFS3_ACCESS_FULL; 752c11d7fd1SFrank van der Linden if (cstate->minorversion >= 2) 753c11d7fd1SFrank van der Linden access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD | 754c11d7fd1SFrank van der Linden NFS4_ACCESS_XAWRITE; 755c11d7fd1SFrank van der Linden 756c11d7fd1SFrank van der Linden if (access->ac_req_access & ~access_full) 7571da177e4SLinus Torvalds return nfserr_inval; 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 760ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 761ca364317SJ.Bruce Fields &access->ac_supported); 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 764b9c0ef85SStanislav Kinsbursky static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) 765ab4684d1SChuck Lever { 76627c438f5STrond Myklebust __be32 *verf = (__be32 *)verifier->data; 767ab4684d1SChuck Lever 76827c438f5STrond Myklebust BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data)); 76927c438f5STrond Myklebust 7703988a578SChuck Lever nfsd_copy_write_verifier(verf, net_generic(net, nfsd_net_id)); 771ab4684d1SChuck Lever } 772ab4684d1SChuck Lever 7737191155bSJ.Bruce Fields static __be32 774ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 775eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7761da177e4SLinus Torvalds { 777eb69853dSChristoph Hellwig struct nfsd4_commit *commit = &u->commit; 778eb69853dSChristoph Hellwig 77975c096f7SJ. Bruce Fields return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 780524ff1afSTrond Myklebust commit->co_count, 781524ff1afSTrond Myklebust (__be32 *)commit->co_verf.data); 7821da177e4SLinus Torvalds } 7831da177e4SLinus Torvalds 784b37ad28bSAl Viro static __be32 785ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 786eb69853dSChristoph Hellwig union nfsd4_op_u *u) 7871da177e4SLinus Torvalds { 788eb69853dSChristoph Hellwig struct nfsd4_create *create = &u->create; 7891da177e4SLinus Torvalds struct svc_fh resfh; 790b37ad28bSAl Viro __be32 status; 7911da177e4SLinus Torvalds dev_t rdev; 7921da177e4SLinus Torvalds 7931da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 7941da177e4SLinus Torvalds 795fa08139dSJ. Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); 7961da177e4SLinus Torvalds if (status) 7971da177e4SLinus Torvalds return status; 7981da177e4SLinus Torvalds 7993c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, create->cr_bmval, 8003c8e0316SYu Zhiguo nfsd_attrmask); 8013c8e0316SYu Zhiguo if (status) 8023c8e0316SYu Zhiguo return status; 8033c8e0316SYu Zhiguo 804880a3a53SJ. Bruce Fields current->fs->umask = create->cr_umask; 8051da177e4SLinus Torvalds switch (create->cr_type) { 8061da177e4SLinus Torvalds case NF4LNK: 807ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 808ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 8091e444f5bSKinglong Mee create->cr_data, &resfh); 8101da177e4SLinus Torvalds break; 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds case NF4BLK: 813880a3a53SJ. Bruce Fields status = nfserr_inval; 8141da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 8151da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 8161da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 817880a3a53SJ. Bruce Fields goto out_umask; 818ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 819ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 820ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 8211da177e4SLinus Torvalds break; 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds case NF4CHR: 824880a3a53SJ. Bruce Fields status = nfserr_inval; 8251da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 8261da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 8271da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 828880a3a53SJ. Bruce Fields goto out_umask; 829ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 830ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 831ca364317SJ.Bruce Fields &create->cr_iattr, S_IFCHR, rdev, &resfh); 8321da177e4SLinus Torvalds break; 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds case NF4SOCK: 835ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 836ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 837ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 8381da177e4SLinus Torvalds break; 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds case NF4FIFO: 841ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 842ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 843ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 8441da177e4SLinus Torvalds break; 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds case NF4DIR: 8471da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 848ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 849ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 850ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 8511da177e4SLinus Torvalds break; 8521da177e4SLinus Torvalds 8531da177e4SLinus Torvalds default: 8541da177e4SLinus Torvalds status = nfserr_badtype; 8551da177e4SLinus Torvalds } 8561da177e4SLinus Torvalds 8579208faf2SYu Zhiguo if (status) 8589208faf2SYu Zhiguo goto out; 8599208faf2SYu Zhiguo 86018032ca0SDavid Quigley if (create->cr_label.len) 86118032ca0SDavid Quigley nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); 86218032ca0SDavid Quigley 8639208faf2SYu Zhiguo if (create->cr_acl != NULL) 8649208faf2SYu Zhiguo do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, 8659208faf2SYu Zhiguo create->cr_bmval); 8669208faf2SYu Zhiguo 867ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 868ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 869ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 8709208faf2SYu Zhiguo out: 8711da177e4SLinus Torvalds fh_put(&resfh); 872880a3a53SJ. Bruce Fields out_umask: 873880a3a53SJ. Bruce Fields current->fs->umask = 0; 8741da177e4SLinus Torvalds return status; 8751da177e4SLinus Torvalds } 8761da177e4SLinus Torvalds 8777191155bSJ.Bruce Fields static __be32 878ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 879eb69853dSChristoph Hellwig union nfsd4_op_u *u) 8801da177e4SLinus Torvalds { 881eb69853dSChristoph Hellwig struct nfsd4_getattr *getattr = &u->getattr; 882b37ad28bSAl Viro __be32 status; 8831da177e4SLinus Torvalds 8848837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 8851da177e4SLinus Torvalds if (status) 8861da177e4SLinus Torvalds return status; 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 8891da177e4SLinus Torvalds return nfserr_inval; 8901da177e4SLinus Torvalds 891916d2d84SJ. Bruce Fields getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 892916d2d84SJ. Bruce Fields getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 893916d2d84SJ. Bruce Fields getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 8941da177e4SLinus Torvalds 895ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 8961da177e4SLinus Torvalds return nfs_ok; 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 8997191155bSJ.Bruce Fields static __be32 900ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 901eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9021da177e4SLinus Torvalds { 903eb69853dSChristoph Hellwig struct nfsd4_link *link = &u->link; 90495424460SJ. Bruce Fields __be32 status; 9051da177e4SLinus Torvalds 906ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 907ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 9081da177e4SLinus Torvalds if (!status) 909ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 9101da177e4SLinus Torvalds return status; 9111da177e4SLinus Torvalds } 9121da177e4SLinus Torvalds 9130ff7ab46SJ. Bruce Fields static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) 9141da177e4SLinus Torvalds { 9151da177e4SLinus Torvalds struct svc_fh tmp_fh; 916b37ad28bSAl Viro __be32 ret; 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 919df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 920df547efbSJ. Bruce Fields if (ret) 9211da177e4SLinus Torvalds return ret; 9220ff7ab46SJ. Bruce Fields if (tmp_fh.fh_dentry == fh->fh_dentry) { 9231da177e4SLinus Torvalds fh_put(&tmp_fh); 9241da177e4SLinus Torvalds return nfserr_noent; 9251da177e4SLinus Torvalds } 9261da177e4SLinus Torvalds fh_put(&tmp_fh); 9270ff7ab46SJ. Bruce Fields return nfsd_lookup(rqstp, fh, "..", 2, fh); 9280ff7ab46SJ. Bruce Fields } 9290ff7ab46SJ. Bruce Fields 9300ff7ab46SJ. Bruce Fields static __be32 9310ff7ab46SJ. Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 932eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9330ff7ab46SJ. Bruce Fields { 9340ff7ab46SJ. Bruce Fields return nfsd4_do_lookupp(rqstp, &cstate->current_fh); 9351da177e4SLinus Torvalds } 9361da177e4SLinus Torvalds 9377191155bSJ.Bruce Fields static __be32 938ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 939eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9401da177e4SLinus Torvalds { 941ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 942eb69853dSChristoph Hellwig u->lookup.lo_name, u->lookup.lo_len, 943ca364317SJ.Bruce Fields &cstate->current_fh); 9441da177e4SLinus Torvalds } 9451da177e4SLinus Torvalds 9467191155bSJ.Bruce Fields static __be32 947ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 948eb69853dSChristoph Hellwig union nfsd4_op_u *u) 9491da177e4SLinus Torvalds { 950eb69853dSChristoph Hellwig struct nfsd4_read *read = &u->read; 951b37ad28bSAl Viro __be32 status; 9521da177e4SLinus Torvalds 9535c4583b2SJeff Layton read->rd_nf = NULL; 9541da177e4SLinus Torvalds 95587c5942eSChuck Lever trace_nfsd_read_start(rqstp, &cstate->current_fh, 95687c5942eSChuck Lever read->rd_offset, read->rd_length); 95787c5942eSChuck Lever 9580cb4d23aSChuck Lever read->rd_length = min_t(u32, read->rd_length, svc_max_payload(rqstp)); 9590cb4d23aSChuck Lever if (read->rd_offset > (u64)OFFSET_MAX) 9600cb4d23aSChuck Lever read->rd_offset = (u64)OFFSET_MAX; 9610cb4d23aSChuck Lever if (read->rd_offset + read->rd_length > (u64)OFFSET_MAX) 9620cb4d23aSChuck Lever read->rd_length = (u64)OFFSET_MAX - read->rd_offset; 9630cb4d23aSChuck Lever 9649b3234b9SJ. Bruce Fields /* 9659b3234b9SJ. Bruce Fields * If we do a zero copy read, then a client will see read data 9669b3234b9SJ. Bruce Fields * that reflects the state of the file *after* performing the 9679b3234b9SJ. Bruce Fields * following compound. 9689b3234b9SJ. Bruce Fields * 9699b3234b9SJ. Bruce Fields * To ensure proper ordering, we therefore turn off zero copy if 9709b3234b9SJ. Bruce Fields * the client wants us to do more in this compound: 9719b3234b9SJ. Bruce Fields */ 9729b3234b9SJ. Bruce Fields if (!nfsd4_last_compound_op(rqstp)) 97328df0988SChuck Lever __clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); 9749b3234b9SJ. Bruce Fields 9751da177e4SLinus Torvalds /* check stateid */ 976aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 977aa0d6aedSAnna Schumaker &read->rd_stateid, RD_STATE, 978624322f1SOlga Kornievskaia &read->rd_nf, NULL); 979af90f707SChristoph Hellwig if (status) { 9801da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 9811da177e4SLinus Torvalds goto out; 9821da177e4SLinus Torvalds } 9831da177e4SLinus Torvalds status = nfs_ok; 9841da177e4SLinus Torvalds out: 9851da177e4SLinus Torvalds read->rd_rqstp = rqstp; 986ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 9871da177e4SLinus Torvalds return status; 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds 99034b1744cSJ. Bruce Fields 99134b1744cSJ. Bruce Fields static void 99234b1744cSJ. Bruce Fields nfsd4_read_release(union nfsd4_op_u *u) 99334b1744cSJ. Bruce Fields { 9945c4583b2SJeff Layton if (u->read.rd_nf) 9955c4583b2SJeff Layton nfsd_file_put(u->read.rd_nf); 99687c5942eSChuck Lever trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, 99787c5942eSChuck Lever u->read.rd_offset, u->read.rd_length); 99834b1744cSJ. Bruce Fields } 99934b1744cSJ. Bruce Fields 10007191155bSJ.Bruce Fields static __be32 1001ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1002eb69853dSChristoph Hellwig union nfsd4_op_u *u) 10031da177e4SLinus Torvalds { 1004eb69853dSChristoph Hellwig struct nfsd4_readdir *readdir = &u->readdir; 10051da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 10061da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 10071da177e4SLinus Torvalds 10081da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 10111da177e4SLinus Torvalds return nfserr_inval; 10121da177e4SLinus Torvalds 1013916d2d84SJ. Bruce Fields readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; 1014916d2d84SJ. Bruce Fields readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; 1015916d2d84SJ. Bruce Fields readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; 10161da177e4SLinus Torvalds 1017832023bfSBernd Schubert if ((cookie == 1) || (cookie == 2) || 10181da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 10191da177e4SLinus Torvalds return nfserr_bad_cookie; 10201da177e4SLinus Torvalds 10211da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 1022ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 10231da177e4SLinus Torvalds return nfs_ok; 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds 10267191155bSJ.Bruce Fields static __be32 1027ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1028eb69853dSChristoph Hellwig union nfsd4_op_u *u) 10291da177e4SLinus Torvalds { 1030eb69853dSChristoph Hellwig u->readlink.rl_rqstp = rqstp; 1031eb69853dSChristoph Hellwig u->readlink.rl_fhp = &cstate->current_fh; 10321da177e4SLinus Torvalds return nfs_ok; 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds 10357191155bSJ.Bruce Fields static __be32 1036ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1037eb69853dSChristoph Hellwig union nfsd4_op_u *u) 10381da177e4SLinus Torvalds { 1039eb69853dSChristoph Hellwig struct nfsd4_remove *remove = &u->remove; 1040b37ad28bSAl Viro __be32 status; 10411da177e4SLinus Torvalds 1042c87fb4a3SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 1043c815afc7SNeilBrown return nfserr_grace; 1044ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 1045ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 10461da177e4SLinus Torvalds if (!status) { 1047ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 1048ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds return status; 10511da177e4SLinus Torvalds } 10521da177e4SLinus Torvalds 10537191155bSJ.Bruce Fields static __be32 1054ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1055eb69853dSChristoph Hellwig union nfsd4_op_u *u) 10561da177e4SLinus Torvalds { 1057eb69853dSChristoph Hellwig struct nfsd4_rename *rename = &u->rename; 105895424460SJ. Bruce Fields __be32 status; 10591da177e4SLinus Torvalds 1060f8f71d00SJ. Bruce Fields if (opens_in_grace(SVC_NET(rqstp))) 1061c815afc7SNeilBrown return nfserr_grace; 1062ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 1063ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 10641da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 10652a6cf944SJ. Bruce Fields if (status) 10662a6cf944SJ. Bruce Fields return status; 1067ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 1068ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 10692a6cf944SJ. Bruce Fields return nfs_ok; 10701da177e4SLinus Torvalds } 10711da177e4SLinus Torvalds 10727191155bSJ.Bruce Fields static __be32 1073dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1074eb69853dSChristoph Hellwig union nfsd4_op_u *u) 1075dcb488a3SAndy Adamson { 1076eb69853dSChristoph Hellwig struct nfsd4_secinfo *secinfo = &u->secinfo; 1077dcb488a3SAndy Adamson struct svc_export *exp; 1078dcb488a3SAndy Adamson struct dentry *dentry; 1079dcb488a3SAndy Adamson __be32 err; 1080dcb488a3SAndy Adamson 108129a78a3eSJ. Bruce Fields err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); 108229a78a3eSJ. Bruce Fields if (err) 108329a78a3eSJ. Bruce Fields return err; 1084dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 1085dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 1086dcb488a3SAndy Adamson &exp, &dentry); 1087dcb488a3SAndy Adamson if (err) 1088dcb488a3SAndy Adamson return err; 10892f6fc056SJ. Bruce Fields fh_unlock(&cstate->current_fh); 10902b0143b5SDavid Howells if (d_really_is_negative(dentry)) { 1091dcb488a3SAndy Adamson exp_put(exp); 1092dcb488a3SAndy Adamson err = nfserr_noent; 1093dcb488a3SAndy Adamson } else 1094dcb488a3SAndy Adamson secinfo->si_exp = exp; 1095dcb488a3SAndy Adamson dput(dentry); 109656560b9aSJ. Bruce Fields if (cstate->minorversion) 109756560b9aSJ. Bruce Fields /* See rfc 5661 section 2.6.3.1.1.8 */ 109856560b9aSJ. Bruce Fields fh_put(&cstate->current_fh); 1099dcb488a3SAndy Adamson return err; 1100dcb488a3SAndy Adamson } 1101dcb488a3SAndy Adamson 1102dcb488a3SAndy Adamson static __be32 110304f4ad16SJ. Bruce Fields nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1104eb69853dSChristoph Hellwig union nfsd4_op_u *u) 110504f4ad16SJ. Bruce Fields { 110604f4ad16SJ. Bruce Fields __be32 err; 110704f4ad16SJ. Bruce Fields 1108eb69853dSChristoph Hellwig switch (u->secinfo_no_name.sin_style) { 110904f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_CURRENT_FH: 111004f4ad16SJ. Bruce Fields break; 111104f4ad16SJ. Bruce Fields case NFS4_SECINFO_STYLE4_PARENT: 111204f4ad16SJ. Bruce Fields err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); 111304f4ad16SJ. Bruce Fields if (err) 111404f4ad16SJ. Bruce Fields return err; 111504f4ad16SJ. Bruce Fields break; 111604f4ad16SJ. Bruce Fields default: 111704f4ad16SJ. Bruce Fields return nfserr_inval; 111804f4ad16SJ. Bruce Fields } 1119bf18f163SKinglong Mee 1120eb69853dSChristoph Hellwig u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export); 112104f4ad16SJ. Bruce Fields fh_put(&cstate->current_fh); 112204f4ad16SJ. Bruce Fields return nfs_ok; 112304f4ad16SJ. Bruce Fields } 112404f4ad16SJ. Bruce Fields 112534b1744cSJ. Bruce Fields static void 112634b1744cSJ. Bruce Fields nfsd4_secinfo_release(union nfsd4_op_u *u) 112734b1744cSJ. Bruce Fields { 112834b1744cSJ. Bruce Fields if (u->secinfo.si_exp) 112934b1744cSJ. Bruce Fields exp_put(u->secinfo.si_exp); 113034b1744cSJ. Bruce Fields } 113134b1744cSJ. Bruce Fields 1132ec572b9eSEryu Guan static void 1133ec572b9eSEryu Guan nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) 1134ec572b9eSEryu Guan { 1135ec572b9eSEryu Guan if (u->secinfo_no_name.sin_exp) 1136ec572b9eSEryu Guan exp_put(u->secinfo_no_name.sin_exp); 1137ec572b9eSEryu Guan } 1138ec572b9eSEryu Guan 113904f4ad16SJ. Bruce Fields static __be32 1140ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1141eb69853dSChristoph Hellwig union nfsd4_op_u *u) 11421da177e4SLinus Torvalds { 1143eb69853dSChristoph Hellwig struct nfsd4_setattr *setattr = &u->setattr; 1144b37ad28bSAl Viro __be32 status = nfs_ok; 114596f6f985SAl Viro int err; 11461da177e4SLinus Torvalds 11471da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 1148af90f707SChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, 1149aa0d6aedSAnna Schumaker &cstate->current_fh, &setattr->sa_stateid, 1150624322f1SOlga Kornievskaia WR_STATE, NULL, NULL); 1151375c5547SJ. Bruce Fields if (status) { 11523e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 1153375c5547SJ. Bruce Fields return status; 1154375c5547SJ. Bruce Fields } 11551da177e4SLinus Torvalds } 115696f6f985SAl Viro err = fh_want_write(&cstate->current_fh); 115796f6f985SAl Viro if (err) 115896f6f985SAl Viro return nfserrno(err); 11591da177e4SLinus Torvalds status = nfs_ok; 11603c8e0316SYu Zhiguo 11613c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 11623c8e0316SYu Zhiguo nfsd_attrmask); 11633c8e0316SYu Zhiguo if (status) 11643c8e0316SYu Zhiguo goto out; 11653c8e0316SYu Zhiguo 11661da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 1167ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 1168ca364317SJ.Bruce Fields setattr->sa_acl); 11691da177e4SLinus Torvalds if (status) 117018f335afSDave Hansen goto out; 117118032ca0SDavid Quigley if (setattr->sa_label.len) 117218032ca0SDavid Quigley status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, 117318032ca0SDavid Quigley &setattr->sa_label); 117418032ca0SDavid Quigley if (status) 117518032ca0SDavid Quigley goto out; 1176ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 11772a1aa489SArnd Bergmann 0, (time64_t)0); 117818f335afSDave Hansen out: 1179bad0dcffSAl Viro fh_drop_write(&cstate->current_fh); 11801da177e4SLinus Torvalds return status; 11811da177e4SLinus Torvalds } 11821da177e4SLinus Torvalds 11837191155bSJ.Bruce Fields static __be32 1184ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1185eb69853dSChristoph Hellwig union nfsd4_op_u *u) 11861da177e4SLinus Torvalds { 1187eb69853dSChristoph Hellwig struct nfsd4_write *write = &u->write; 11881da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 11895c4583b2SJeff Layton struct nfsd_file *nf = NULL; 1190b37ad28bSAl Viro __be32 status = nfs_ok; 119131dec253SDavid Shaw unsigned long cnt; 1192ffe1137bSJ. Bruce Fields int nvecs; 11931da177e4SLinus Torvalds 11946260d9a5SChuck Lever if (write->wr_offset > (u64)OFFSET_MAX || 11956260d9a5SChuck Lever write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX) 11966260d9a5SChuck Lever return nfserr_fbig; 11971da177e4SLinus Torvalds 1198d890be15SChuck Lever cnt = write->wr_buflen; 1199d890be15SChuck Lever trace_nfsd_write_start(rqstp, &cstate->current_fh, 1200d890be15SChuck Lever write->wr_offset, cnt); 1201aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1202624322f1SOlga Kornievskaia stateid, WR_STATE, &nf, NULL); 1203375c5547SJ. Bruce Fields if (status) { 1204375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 1205375c5547SJ. Bruce Fields return status; 1206375c5547SJ. Bruce Fields } 1207375c5547SJ. Bruce Fields 12081da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 12091da177e4SLinus Torvalds 1210dae9a6caSChuck Lever nvecs = svc_fill_write_vector(rqstp, &write->wr_payload); 1211ffe1137bSJ. Bruce Fields WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); 1212ffe1137bSJ. Bruce Fields 121316f8f894STrond Myklebust status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, 1214af90f707SChristoph Hellwig write->wr_offset, rqstp->rq_vec, nvecs, &cnt, 121519e0663fSTrond Myklebust write->wr_how_written, 121619e0663fSTrond Myklebust (__be32 *)write->wr_verifier.data); 12175c4583b2SJeff Layton nfsd_file_put(nf); 12181da177e4SLinus Torvalds 121931dec253SDavid Shaw write->wr_bytes_written = cnt; 1220d890be15SChuck Lever trace_nfsd_write_done(rqstp, &cstate->current_fh, 1221d890be15SChuck Lever write->wr_offset, cnt); 12221da177e4SLinus Torvalds return status; 12231da177e4SLinus Torvalds } 12241da177e4SLinus Torvalds 122524bab491SAnna Schumaker static __be32 122629ae7f9dSAnna Schumaker nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 12275c4583b2SJeff Layton stateid_t *src_stateid, struct nfsd_file **src, 12285c4583b2SJeff Layton stateid_t *dst_stateid, struct nfsd_file **dst) 1229ffa0160aSChristoph Hellwig { 1230ffa0160aSChristoph Hellwig __be32 status; 1231ffa0160aSChristoph Hellwig 123201310bb7SScott Mayhew if (!cstate->save_fh.fh_dentry) 123301310bb7SScott Mayhew return nfserr_nofilehandle; 123401310bb7SScott Mayhew 1235ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, 1236624322f1SOlga Kornievskaia src_stateid, RD_STATE, src, NULL); 1237ffa0160aSChristoph Hellwig if (status) { 1238ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); 1239ffa0160aSChristoph Hellwig goto out; 1240ffa0160aSChristoph Hellwig } 1241ffa0160aSChristoph Hellwig 1242ffa0160aSChristoph Hellwig status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1243624322f1SOlga Kornievskaia dst_stateid, WR_STATE, dst, NULL); 1244ffa0160aSChristoph Hellwig if (status) { 1245ffa0160aSChristoph Hellwig dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); 1246ffa0160aSChristoph Hellwig goto out_put_src; 1247ffa0160aSChristoph Hellwig } 1248ffa0160aSChristoph Hellwig 1249ffa0160aSChristoph Hellwig /* fix up for NFS-specific error code */ 12505c4583b2SJeff Layton if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) || 12515c4583b2SJeff Layton !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) { 1252ffa0160aSChristoph Hellwig status = nfserr_wrong_type; 1253ffa0160aSChristoph Hellwig goto out_put_dst; 1254ffa0160aSChristoph Hellwig } 1255ffa0160aSChristoph Hellwig 125629ae7f9dSAnna Schumaker out: 125729ae7f9dSAnna Schumaker return status; 125829ae7f9dSAnna Schumaker out_put_dst: 12595c4583b2SJeff Layton nfsd_file_put(*dst); 126029ae7f9dSAnna Schumaker out_put_src: 12615c4583b2SJeff Layton nfsd_file_put(*src); 126229ae7f9dSAnna Schumaker goto out; 126329ae7f9dSAnna Schumaker } 126429ae7f9dSAnna Schumaker 126529ae7f9dSAnna Schumaker static __be32 126629ae7f9dSAnna Schumaker nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1267eb69853dSChristoph Hellwig union nfsd4_op_u *u) 126829ae7f9dSAnna Schumaker { 1269eb69853dSChristoph Hellwig struct nfsd4_clone *clone = &u->clone; 12705c4583b2SJeff Layton struct nfsd_file *src, *dst; 127129ae7f9dSAnna Schumaker __be32 status; 127229ae7f9dSAnna Schumaker 127329ae7f9dSAnna Schumaker status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, 127429ae7f9dSAnna Schumaker &clone->cl_dst_stateid, &dst); 127529ae7f9dSAnna Schumaker if (status) 127629ae7f9dSAnna Schumaker goto out; 127729ae7f9dSAnna Schumaker 1278a2f4c3faSTrond Myklebust status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos, 1279b66ae6ddSTrond Myklebust dst, clone->cl_dst_pos, clone->cl_count, 1280a25e3726STrond Myklebust EX_ISSYNC(cstate->current_fh.fh_export)); 1281ffa0160aSChristoph Hellwig 12825c4583b2SJeff Layton nfsd_file_put(dst); 12835c4583b2SJeff Layton nfsd_file_put(src); 1284ffa0160aSChristoph Hellwig out: 1285ffa0160aSChristoph Hellwig return status; 1286ffa0160aSChristoph Hellwig } 1287ffa0160aSChristoph Hellwig 1288e0639dc5SOlga Kornievskaia void nfs4_put_copy(struct nfsd4_copy *copy) 1289e0639dc5SOlga Kornievskaia { 1290e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1291e0639dc5SOlga Kornievskaia return; 1292e0639dc5SOlga Kornievskaia kfree(copy); 1293e0639dc5SOlga Kornievskaia } 1294e0639dc5SOlga Kornievskaia 1295e0639dc5SOlga Kornievskaia static bool 1296e0639dc5SOlga Kornievskaia check_and_set_stop_copy(struct nfsd4_copy *copy) 1297e0639dc5SOlga Kornievskaia { 1298e0639dc5SOlga Kornievskaia bool value; 1299e0639dc5SOlga Kornievskaia 1300e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1301e0639dc5SOlga Kornievskaia value = copy->stopped; 1302e0639dc5SOlga Kornievskaia if (!copy->stopped) 1303e0639dc5SOlga Kornievskaia copy->stopped = true; 1304e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1305e0639dc5SOlga Kornievskaia return value; 1306e0639dc5SOlga Kornievskaia } 1307e0639dc5SOlga Kornievskaia 1308e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1309e0639dc5SOlga Kornievskaia { 1310e0639dc5SOlga Kornievskaia /* only 1 thread should stop the copy */ 1311e0639dc5SOlga Kornievskaia if (!check_and_set_stop_copy(copy)) 1312e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1313e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1314e0639dc5SOlga Kornievskaia } 1315e0639dc5SOlga Kornievskaia 1316e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1317e0639dc5SOlga Kornievskaia { 1318e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1319e0639dc5SOlga Kornievskaia 1320e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1321e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1322e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1323e0639dc5SOlga Kornievskaia copies); 1324e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1325e0639dc5SOlga Kornievskaia } 1326e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1327e0639dc5SOlga Kornievskaia return copy; 1328e0639dc5SOlga Kornievskaia } 1329e0639dc5SOlga Kornievskaia 1330e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1331e0639dc5SOlga Kornievskaia { 1332e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1333e0639dc5SOlga Kornievskaia 1334e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1335e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1336e0639dc5SOlga Kornievskaia } 1337ce0887acSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 1338ce0887acSOlga Kornievskaia 1339ce0887acSOlga Kornievskaia extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1340ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1341ce0887acSOlga Kornievskaia nfs4_stateid *stateid); 1342ce0887acSOlga Kornievskaia extern void nfs42_ssc_close(struct file *filep); 1343ce0887acSOlga Kornievskaia 1344ce0887acSOlga Kornievskaia extern void nfs_sb_deactive(struct super_block *sb); 1345ce0887acSOlga Kornievskaia 1346ce0887acSOlga Kornievskaia #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys" 1347ce0887acSOlga Kornievskaia 1348f2453978SChuck Lever /* 1349f4e44b39SDai Ngo * setup a work entry in the ssc delayed unmount list. 1350f4e44b39SDai Ngo */ 1351f47dc2d3SDai Ngo static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr, 1352f4e44b39SDai Ngo struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt) 1353f4e44b39SDai Ngo { 13548e70bf27SColin Ian King struct nfsd4_ssc_umount_item *ni = NULL; 1355f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work = NULL; 1356f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *tmp; 1357f4e44b39SDai Ngo DEFINE_WAIT(wait); 1358f4e44b39SDai Ngo 1359f4e44b39SDai Ngo *ss_mnt = NULL; 1360f4e44b39SDai Ngo *retwork = NULL; 1361f4e44b39SDai Ngo work = kzalloc(sizeof(*work), GFP_KERNEL); 1362f4e44b39SDai Ngo try_again: 1363f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1364f4e44b39SDai Ngo list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { 1365f4e44b39SDai Ngo if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr))) 1366f4e44b39SDai Ngo continue; 1367f4e44b39SDai Ngo /* found a match */ 1368f4e44b39SDai Ngo if (ni->nsui_busy) { 1369f4e44b39SDai Ngo /* wait - and try again */ 1370f4e44b39SDai Ngo prepare_to_wait(&nn->nfsd_ssc_waitq, &wait, 1371f4e44b39SDai Ngo TASK_INTERRUPTIBLE); 1372f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1373f4e44b39SDai Ngo 1374f4e44b39SDai Ngo /* allow 20secs for mount/unmount for now - revisit */ 1375f4e44b39SDai Ngo if (signal_pending(current) || 1376f4e44b39SDai Ngo (schedule_timeout(20*HZ) == 0)) { 1377f4e44b39SDai Ngo kfree(work); 1378f4e44b39SDai Ngo return nfserr_eagain; 1379f4e44b39SDai Ngo } 1380f4e44b39SDai Ngo finish_wait(&nn->nfsd_ssc_waitq, &wait); 1381f4e44b39SDai Ngo goto try_again; 1382f4e44b39SDai Ngo } 1383f4e44b39SDai Ngo *ss_mnt = ni->nsui_vfsmount; 1384f4e44b39SDai Ngo refcount_inc(&ni->nsui_refcnt); 1385f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1386f4e44b39SDai Ngo kfree(work); 1387f4e44b39SDai Ngo 1388f4e44b39SDai Ngo /* return vfsmount in ss_mnt */ 1389f4e44b39SDai Ngo return 0; 1390f4e44b39SDai Ngo } 1391f4e44b39SDai Ngo if (work) { 1392f4e44b39SDai Ngo strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr)); 1393f4e44b39SDai Ngo refcount_set(&work->nsui_refcnt, 2); 1394f4e44b39SDai Ngo work->nsui_busy = true; 1395f4e44b39SDai Ngo list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list); 1396f4e44b39SDai Ngo *retwork = work; 1397f4e44b39SDai Ngo } 1398f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1399f4e44b39SDai Ngo return 0; 1400f4e44b39SDai Ngo } 1401f4e44b39SDai Ngo 1402f4e44b39SDai Ngo static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn, 1403f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt) 1404f4e44b39SDai Ngo { 1405f4e44b39SDai Ngo /* set nsui_vfsmount, clear busy flag and wakeup waiters */ 1406f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1407f4e44b39SDai Ngo work->nsui_vfsmount = ss_mnt; 1408f4e44b39SDai Ngo work->nsui_busy = false; 1409f4e44b39SDai Ngo wake_up_all(&nn->nfsd_ssc_waitq); 1410f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1411f4e44b39SDai Ngo } 1412f4e44b39SDai Ngo 1413f4e44b39SDai Ngo static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn, 1414f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work) 1415f4e44b39SDai Ngo { 1416f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1417f4e44b39SDai Ngo list_del(&work->nsui_list); 1418f4e44b39SDai Ngo wake_up_all(&nn->nfsd_ssc_waitq); 1419f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1420f4e44b39SDai Ngo kfree(work); 1421f4e44b39SDai Ngo } 1422f4e44b39SDai Ngo 1423f4e44b39SDai Ngo /* 1424ce0887acSOlga Kornievskaia * Support one copy source server for now. 1425ce0887acSOlga Kornievskaia */ 1426ce0887acSOlga Kornievskaia static __be32 1427ce0887acSOlga Kornievskaia nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp, 1428ce0887acSOlga Kornievskaia struct vfsmount **mount) 1429ce0887acSOlga Kornievskaia { 1430ce0887acSOlga Kornievskaia struct file_system_type *type; 1431ce0887acSOlga Kornievskaia struct vfsmount *ss_mnt; 1432ce0887acSOlga Kornievskaia struct nfs42_netaddr *naddr; 1433ce0887acSOlga Kornievskaia struct sockaddr_storage tmp_addr; 1434ce0887acSOlga Kornievskaia size_t tmp_addrlen, match_netid_len = 3; 1435ce0887acSOlga Kornievskaia char *startsep = "", *endsep = "", *match_netid = "tcp"; 1436ce0887acSOlga Kornievskaia char *ipaddr, *dev_name, *raw_data; 1437b8290ca2SOlga Kornievskaia int len, raw_len; 1438b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1439f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work = NULL; 1440f4e44b39SDai Ngo struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1441ce0887acSOlga Kornievskaia 1442ce0887acSOlga Kornievskaia naddr = &nss->u.nl4_addr; 1443ce0887acSOlga Kornievskaia tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr, 1444ce0887acSOlga Kornievskaia naddr->addr_len, 1445ce0887acSOlga Kornievskaia (struct sockaddr *)&tmp_addr, 1446ce0887acSOlga Kornievskaia sizeof(tmp_addr)); 1447ce0887acSOlga Kornievskaia if (tmp_addrlen == 0) 1448ce0887acSOlga Kornievskaia goto out_err; 1449ce0887acSOlga Kornievskaia 1450ce0887acSOlga Kornievskaia if (tmp_addr.ss_family == AF_INET6) { 1451ce0887acSOlga Kornievskaia startsep = "["; 1452ce0887acSOlga Kornievskaia endsep = "]"; 1453ce0887acSOlga Kornievskaia match_netid = "tcp6"; 1454ce0887acSOlga Kornievskaia match_netid_len = 4; 1455ce0887acSOlga Kornievskaia } 1456ce0887acSOlga Kornievskaia 1457ce0887acSOlga Kornievskaia if (naddr->netid_len != match_netid_len || 1458ce0887acSOlga Kornievskaia strncmp(naddr->netid, match_netid, naddr->netid_len)) 1459ce0887acSOlga Kornievskaia goto out_err; 1460ce0887acSOlga Kornievskaia 1461ce0887acSOlga Kornievskaia /* Construct the raw data for the vfs_kern_mount call */ 1462ce0887acSOlga Kornievskaia len = RPC_MAX_ADDRBUFLEN + 1; 1463ce0887acSOlga Kornievskaia ipaddr = kzalloc(len, GFP_KERNEL); 1464ce0887acSOlga Kornievskaia if (!ipaddr) 1465ce0887acSOlga Kornievskaia goto out_err; 1466ce0887acSOlga Kornievskaia 1467ce0887acSOlga Kornievskaia rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len); 1468ce0887acSOlga Kornievskaia 1469ce0887acSOlga Kornievskaia /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/ 1470ce0887acSOlga Kornievskaia 1471ce0887acSOlga Kornievskaia raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr); 1472ce0887acSOlga Kornievskaia raw_data = kzalloc(raw_len, GFP_KERNEL); 1473ce0887acSOlga Kornievskaia if (!raw_data) 1474ce0887acSOlga Kornievskaia goto out_free_ipaddr; 1475ce0887acSOlga Kornievskaia 1476ce0887acSOlga Kornievskaia snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr); 1477ce0887acSOlga Kornievskaia 1478b8290ca2SOlga Kornievskaia status = nfserr_nodev; 1479ce0887acSOlga Kornievskaia type = get_fs_type("nfs"); 1480ce0887acSOlga Kornievskaia if (!type) 1481ce0887acSOlga Kornievskaia goto out_free_rawdata; 1482ce0887acSOlga Kornievskaia 1483ce0887acSOlga Kornievskaia /* Set the server:<export> for the vfs_kern_mount call */ 1484ce0887acSOlga Kornievskaia dev_name = kzalloc(len + 5, GFP_KERNEL); 1485ce0887acSOlga Kornievskaia if (!dev_name) 1486ce0887acSOlga Kornievskaia goto out_free_rawdata; 1487ce0887acSOlga Kornievskaia snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep); 1488ce0887acSOlga Kornievskaia 1489f4e44b39SDai Ngo status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt); 1490f4e44b39SDai Ngo if (status) 1491f4e44b39SDai Ngo goto out_free_devname; 1492f4e44b39SDai Ngo if (ss_mnt) 1493f4e44b39SDai Ngo goto out_done; 1494f4e44b39SDai Ngo 1495ce0887acSOlga Kornievskaia /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */ 1496ce0887acSOlga Kornievskaia ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data); 1497ce0887acSOlga Kornievskaia module_put(type->owner); 1498f4e44b39SDai Ngo if (IS_ERR(ss_mnt)) { 149954185267SWei Yongjun status = nfserr_nodev; 1500f4e44b39SDai Ngo if (work) 1501f4e44b39SDai Ngo nfsd4_ssc_cancel_dul_work(nn, work); 1502ce0887acSOlga Kornievskaia goto out_free_devname; 1503f4e44b39SDai Ngo } 1504f4e44b39SDai Ngo if (work) 1505f4e44b39SDai Ngo nfsd4_ssc_update_dul_work(nn, work, ss_mnt); 1506f4e44b39SDai Ngo out_done: 1507ce0887acSOlga Kornievskaia status = 0; 1508ce0887acSOlga Kornievskaia *mount = ss_mnt; 1509ce0887acSOlga Kornievskaia 1510ce0887acSOlga Kornievskaia out_free_devname: 1511ce0887acSOlga Kornievskaia kfree(dev_name); 1512ce0887acSOlga Kornievskaia out_free_rawdata: 1513ce0887acSOlga Kornievskaia kfree(raw_data); 1514ce0887acSOlga Kornievskaia out_free_ipaddr: 1515ce0887acSOlga Kornievskaia kfree(ipaddr); 1516ce0887acSOlga Kornievskaia out_err: 1517ce0887acSOlga Kornievskaia return status; 1518ce0887acSOlga Kornievskaia } 1519ce0887acSOlga Kornievskaia 1520ce0887acSOlga Kornievskaia static void 1521ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1522ce0887acSOlga Kornievskaia { 15230cfcd405SDai Ngo nfs_do_sb_deactive(ss_mnt->mnt_sb); 1524ce0887acSOlga Kornievskaia mntput(ss_mnt); 1525ce0887acSOlga Kornievskaia } 1526ce0887acSOlga Kornievskaia 1527f2453978SChuck Lever /* 1528ce0887acSOlga Kornievskaia * Verify COPY destination stateid. 1529f2453978SChuck Lever * 1530ce0887acSOlga Kornievskaia * Connect to the source server with NFSv4.1. 1531ce0887acSOlga Kornievskaia * Create the source struct file for nfsd_copy_range. 1532ce0887acSOlga Kornievskaia * Called with COPY cstate: 1533ce0887acSOlga Kornievskaia * SAVED_FH: source filehandle 1534ce0887acSOlga Kornievskaia * CURRENT_FH: destination filehandle 1535ce0887acSOlga Kornievskaia */ 1536ce0887acSOlga Kornievskaia static __be32 1537ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1538ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1539ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, struct vfsmount **mount) 1540ce0887acSOlga Kornievskaia { 1541ce0887acSOlga Kornievskaia struct svc_fh *s_fh = NULL; 1542ce0887acSOlga Kornievskaia stateid_t *s_stid = ©->cp_src_stateid; 1543b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1544ce0887acSOlga Kornievskaia 1545ce0887acSOlga Kornievskaia /* Verify the destination stateid and set dst struct file*/ 1546ce0887acSOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1547ce0887acSOlga Kornievskaia ©->cp_dst_stateid, 1548ce0887acSOlga Kornievskaia WR_STATE, ©->nf_dst, NULL); 1549ce0887acSOlga Kornievskaia if (status) 1550ce0887acSOlga Kornievskaia goto out; 1551ce0887acSOlga Kornievskaia 1552ce0887acSOlga Kornievskaia status = nfsd4_interssc_connect(©->cp_src, rqstp, mount); 1553ce0887acSOlga Kornievskaia if (status) 1554ce0887acSOlga Kornievskaia goto out; 1555ce0887acSOlga Kornievskaia 1556ce0887acSOlga Kornievskaia s_fh = &cstate->save_fh; 1557ce0887acSOlga Kornievskaia 1558ce0887acSOlga Kornievskaia copy->c_fh.size = s_fh->fh_handle.fh_size; 1559d8b26071SNeilBrown memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size); 15603f9544caSOlga Kornievskaia copy->stateid.seqid = cpu_to_be32(s_stid->si_generation); 1561ce0887acSOlga Kornievskaia memcpy(copy->stateid.other, (void *)&s_stid->si_opaque, 1562ce0887acSOlga Kornievskaia sizeof(stateid_opaque_t)); 1563ce0887acSOlga Kornievskaia 1564ce0887acSOlga Kornievskaia status = 0; 1565ce0887acSOlga Kornievskaia out: 1566ce0887acSOlga Kornievskaia return status; 1567ce0887acSOlga Kornievskaia } 1568ce0887acSOlga Kornievskaia 1569ce0887acSOlga Kornievskaia static void 1570ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, 1571ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1572ce0887acSOlga Kornievskaia { 1573f4e44b39SDai Ngo bool found = false; 1574f4e44b39SDai Ngo long timeout; 1575f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *tmp; 1576f47dc2d3SDai Ngo struct nfsd4_ssc_umount_item *ni = NULL; 1577f4e44b39SDai Ngo struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id); 1578f4e44b39SDai Ngo 1579ce0887acSOlga Kornievskaia nfs42_ssc_close(src->nf_file); 1580ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1581f4e44b39SDai Ngo fput(src->nf_file); 1582f4e44b39SDai Ngo 1583f4e44b39SDai Ngo if (!nn) { 1584ce0887acSOlga Kornievskaia mntput(ss_mnt); 1585f4e44b39SDai Ngo return; 1586f4e44b39SDai Ngo } 1587f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1588f4e44b39SDai Ngo timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout); 1589f4e44b39SDai Ngo list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { 1590f4e44b39SDai Ngo if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) { 1591f4e44b39SDai Ngo list_del(&ni->nsui_list); 1592f4e44b39SDai Ngo /* 1593f4e44b39SDai Ngo * vfsmount can be shared by multiple exports, 1594f4e44b39SDai Ngo * decrement refcnt. If the count drops to 1 it 1595f4e44b39SDai Ngo * will be unmounted when nsui_expire expires. 1596f4e44b39SDai Ngo */ 1597f4e44b39SDai Ngo refcount_dec(&ni->nsui_refcnt); 1598f4e44b39SDai Ngo ni->nsui_expire = jiffies + timeout; 1599f4e44b39SDai Ngo list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list); 1600f4e44b39SDai Ngo found = true; 1601f4e44b39SDai Ngo break; 1602f4e44b39SDai Ngo } 1603f4e44b39SDai Ngo } 1604f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1605f4e44b39SDai Ngo if (!found) { 1606f4e44b39SDai Ngo mntput(ss_mnt); 1607f4e44b39SDai Ngo return; 1608f4e44b39SDai Ngo } 1609ce0887acSOlga Kornievskaia } 1610ce0887acSOlga Kornievskaia 1611ce0887acSOlga Kornievskaia #else /* CONFIG_NFSD_V4_2_INTER_SSC */ 1612ce0887acSOlga Kornievskaia 1613ce0887acSOlga Kornievskaia static __be32 1614ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1615ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1616ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, 1617ce0887acSOlga Kornievskaia struct vfsmount **mount) 1618ce0887acSOlga Kornievskaia { 1619ce0887acSOlga Kornievskaia *mount = NULL; 1620b8290ca2SOlga Kornievskaia return nfserr_inval; 1621ce0887acSOlga Kornievskaia } 1622ce0887acSOlga Kornievskaia 1623ce0887acSOlga Kornievskaia static void 1624ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, 1625ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1626ce0887acSOlga Kornievskaia { 1627ce0887acSOlga Kornievskaia } 1628ce0887acSOlga Kornievskaia 1629ce0887acSOlga Kornievskaia static void 1630ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1631ce0887acSOlga Kornievskaia { 1632ce0887acSOlga Kornievskaia } 1633ce0887acSOlga Kornievskaia 1634ce0887acSOlga Kornievskaia static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1635ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1636ce0887acSOlga Kornievskaia nfs4_stateid *stateid) 1637ce0887acSOlga Kornievskaia { 1638ce0887acSOlga Kornievskaia return NULL; 1639ce0887acSOlga Kornievskaia } 1640ce0887acSOlga Kornievskaia #endif /* CONFIG_NFSD_V4_2_INTER_SSC */ 1641ce0887acSOlga Kornievskaia 1642ce0887acSOlga Kornievskaia static __be32 1643ce0887acSOlga Kornievskaia nfsd4_setup_intra_ssc(struct svc_rqst *rqstp, 1644ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1645ce0887acSOlga Kornievskaia struct nfsd4_copy *copy) 1646ce0887acSOlga Kornievskaia { 1647ce0887acSOlga Kornievskaia return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 1648ce0887acSOlga Kornievskaia ©->nf_src, ©->cp_dst_stateid, 1649ce0887acSOlga Kornievskaia ©->nf_dst); 1650ce0887acSOlga Kornievskaia } 1651ce0887acSOlga Kornievskaia 1652ce0887acSOlga Kornievskaia static void 1653ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst) 1654ce0887acSOlga Kornievskaia { 1655ce0887acSOlga Kornievskaia nfsd_file_put(src); 1656ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1657ce0887acSOlga Kornievskaia } 1658e0639dc5SOlga Kornievskaia 1659e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1660e0639dc5SOlga Kornievskaia { 1661e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); 1662e0639dc5SOlga Kornievskaia 1663e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1664e0639dc5SOlga Kornievskaia } 1665e0639dc5SOlga Kornievskaia 1666e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1667e0639dc5SOlga Kornievskaia struct rpc_task *task) 1668e0639dc5SOlga Kornievskaia { 1669e0639dc5SOlga Kornievskaia return 1; 1670e0639dc5SOlga Kornievskaia } 1671e0639dc5SOlga Kornievskaia 1672e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1673e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1674e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1675e0639dc5SOlga Kornievskaia }; 1676e0639dc5SOlga Kornievskaia 1677e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1678e0639dc5SOlga Kornievskaia { 1679eac0b17aSOlga Kornievskaia copy->cp_res.wr_stable_how = 1680eac0b17aSOlga Kornievskaia copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE; 1681e0639dc5SOlga Kornievskaia copy->cp_synchronous = sync; 1682e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1683e0639dc5SOlga Kornievskaia } 1684e0639dc5SOlga Kornievskaia 1685e0639dc5SOlga Kornievskaia static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) 1686e0639dc5SOlga Kornievskaia { 1687555dbf1aSTrond Myklebust struct file *dst = copy->nf_dst->nf_file; 1688555dbf1aSTrond Myklebust struct file *src = copy->nf_src->nf_file; 1689555dbf1aSTrond Myklebust errseq_t since; 1690e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1691e7a833e9SJ. Bruce Fields u64 bytes_total = copy->cp_count; 1692e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1693e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1694c2f1c4bdSChuck Lever int status; 1695e0639dc5SOlga Kornievskaia 1696792a5112SJ. Bruce Fields /* See RFC 7862 p.67: */ 1697792a5112SJ. Bruce Fields if (bytes_total == 0) 1698792a5112SJ. Bruce Fields bytes_total = ULLONG_MAX; 1699e0639dc5SOlga Kornievskaia do { 1700e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1701e0639dc5SOlga Kornievskaia break; 1702555dbf1aSTrond Myklebust bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos, 17035c4583b2SJeff Layton bytes_total); 1704e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1705e0639dc5SOlga Kornievskaia break; 1706e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1707e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1708e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1709e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 1710e0639dc5SOlga Kornievskaia } while (bytes_total > 0 && !copy->cp_synchronous); 1711eac0b17aSOlga Kornievskaia /* for a non-zero asynchronous copy do a commit of data */ 1712eac0b17aSOlga Kornievskaia if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) { 1713555dbf1aSTrond Myklebust since = READ_ONCE(dst->f_wb_err); 1714555dbf1aSTrond Myklebust status = vfs_fsync_range(dst, copy->cp_dst_pos, 1715eac0b17aSOlga Kornievskaia copy->cp_res.wr_bytes_written, 0); 1716555dbf1aSTrond Myklebust if (!status) 1717555dbf1aSTrond Myklebust status = filemap_check_wb_err(dst->f_mapping, since); 1718eac0b17aSOlga Kornievskaia if (!status) 1719eac0b17aSOlga Kornievskaia copy->committed = true; 1720eac0b17aSOlga Kornievskaia } 1721e0639dc5SOlga Kornievskaia return bytes_copied; 1722e0639dc5SOlga Kornievskaia } 1723e0639dc5SOlga Kornievskaia 1724e0639dc5SOlga Kornievskaia static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) 1725e0639dc5SOlga Kornievskaia { 1726e0639dc5SOlga Kornievskaia __be32 status; 1727e0639dc5SOlga Kornievskaia ssize_t bytes; 1728e0639dc5SOlga Kornievskaia 1729e0639dc5SOlga Kornievskaia bytes = _nfsd_copy_file_range(copy); 1730e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1731e0639dc5SOlga Kornievskaia * to get the error 1732e0639dc5SOlga Kornievskaia */ 1733e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1734e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1735e0639dc5SOlga Kornievskaia else { 1736e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1737e0639dc5SOlga Kornievskaia status = nfs_ok; 1738e0639dc5SOlga Kornievskaia } 1739e0639dc5SOlga Kornievskaia 1740ce0887acSOlga Kornievskaia if (!copy->cp_intra) /* Inter server SSC */ 1741ce0887acSOlga Kornievskaia nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src, 1742ce0887acSOlga Kornievskaia copy->nf_dst); 1743ce0887acSOlga Kornievskaia else 1744ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); 1745ce0887acSOlga Kornievskaia 1746e0639dc5SOlga Kornievskaia return status; 1747e0639dc5SOlga Kornievskaia } 1748e0639dc5SOlga Kornievskaia 1749eb162e17SChuck Lever static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1750e0639dc5SOlga Kornievskaia { 1751e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1752e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1753e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 1754e0639dc5SOlga Kornievskaia dst->cp_synchronous = src->cp_synchronous; 1755e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1756e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1757e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 17585c4583b2SJeff Layton dst->nf_dst = nfsd_file_get(src->nf_dst); 1759ce0887acSOlga Kornievskaia dst->cp_intra = src->cp_intra; 1760ce0887acSOlga Kornievskaia if (src->cp_intra) /* for inter, file_src doesn't exist yet */ 17615c4583b2SJeff Layton dst->nf_src = nfsd_file_get(src->nf_src); 1762ce0887acSOlga Kornievskaia 1763e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 1764ce0887acSOlga Kornievskaia memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server)); 1765ce0887acSOlga Kornievskaia memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); 1766ce0887acSOlga Kornievskaia memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); 1767ce0887acSOlga Kornievskaia dst->ss_mnt = src->ss_mnt; 1768e0639dc5SOlga Kornievskaia } 1769e0639dc5SOlga Kornievskaia 1770e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1771e0639dc5SOlga Kornievskaia { 1772624322f1SOlga Kornievskaia nfs4_free_copy_state(copy); 17735c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 17742e577f0fSOlga Kornievskaia if (copy->cp_intra) 17755c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 1776e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1777e0639dc5SOlga Kornievskaia list_del(©->copies); 1778e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1779e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1780e0639dc5SOlga Kornievskaia } 1781e0639dc5SOlga Kornievskaia 1782e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1783e0639dc5SOlga Kornievskaia { 1784e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1785e0639dc5SOlga Kornievskaia struct nfsd4_copy *cb_copy; 1786e0639dc5SOlga Kornievskaia 1787ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1788ce0887acSOlga Kornievskaia copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); 1789ce0887acSOlga Kornievskaia if (!copy->nf_src) { 1790ce0887acSOlga Kornievskaia copy->nfserr = nfserr_serverfault; 1791ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1792ce0887acSOlga Kornievskaia goto do_callback; 1793ce0887acSOlga Kornievskaia } 1794ce0887acSOlga Kornievskaia copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, 1795ce0887acSOlga Kornievskaia ©->stateid); 1796ce0887acSOlga Kornievskaia if (IS_ERR(copy->nf_src->nf_file)) { 1797ce0887acSOlga Kornievskaia copy->nfserr = nfserr_offload_denied; 1798ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1799ce0887acSOlga Kornievskaia goto do_callback; 1800ce0887acSOlga Kornievskaia } 1801ce0887acSOlga Kornievskaia } 1802ce0887acSOlga Kornievskaia 1803e0639dc5SOlga Kornievskaia copy->nfserr = nfsd4_do_copy(copy, 0); 1804ce0887acSOlga Kornievskaia do_callback: 1805e0639dc5SOlga Kornievskaia cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1806e0639dc5SOlga Kornievskaia if (!cb_copy) 1807e0639dc5SOlga Kornievskaia goto out; 180849a36132SDai Ngo refcount_set(&cb_copy->refcount, 1); 1809e0639dc5SOlga Kornievskaia memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); 1810e0639dc5SOlga Kornievskaia cb_copy->cp_clp = copy->cp_clp; 1811e0639dc5SOlga Kornievskaia cb_copy->nfserr = copy->nfserr; 1812e0639dc5SOlga Kornievskaia memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); 1813e0639dc5SOlga Kornievskaia nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, 1814e0639dc5SOlga Kornievskaia &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); 181587512386SChuck Lever trace_nfsd_cb_offload(copy->cp_clp, ©->cp_res.cb_stateid, 181687512386SChuck Lever ©->fh, copy->cp_count, copy->nfserr); 1817e0639dc5SOlga Kornievskaia nfsd4_run_cb(&cb_copy->cp_cb); 1818e0639dc5SOlga Kornievskaia out: 1819ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1820ce0887acSOlga Kornievskaia kfree(copy->nf_src); 1821e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1822e0639dc5SOlga Kornievskaia return 0; 1823e0639dc5SOlga Kornievskaia } 1824e0639dc5SOlga Kornievskaia 1825ffa0160aSChristoph Hellwig static __be32 182629ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1827eb69853dSChristoph Hellwig union nfsd4_op_u *u) 182829ae7f9dSAnna Schumaker { 1829eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 183029ae7f9dSAnna Schumaker __be32 status; 1831e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 183229ae7f9dSAnna Schumaker 1833ce0887acSOlga Kornievskaia if (!copy->cp_intra) { /* Inter server SSC */ 1834ce0887acSOlga Kornievskaia if (!inter_copy_offload_enable || copy->cp_synchronous) { 1835ce0887acSOlga Kornievskaia status = nfserr_notsupp; 183629ae7f9dSAnna Schumaker goto out; 1837ce0887acSOlga Kornievskaia } 1838ce0887acSOlga Kornievskaia status = nfsd4_setup_inter_ssc(rqstp, cstate, copy, 1839ce0887acSOlga Kornievskaia ©->ss_mnt); 1840ce0887acSOlga Kornievskaia if (status) 1841ce0887acSOlga Kornievskaia return nfserr_offload_denied; 1842ce0887acSOlga Kornievskaia } else { 1843ce0887acSOlga Kornievskaia status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); 1844ce0887acSOlga Kornievskaia if (status) 1845ce0887acSOlga Kornievskaia return status; 1846ce0887acSOlga Kornievskaia } 184729ae7f9dSAnna Schumaker 1848e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1849e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1850e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 1851e0639dc5SOlga Kornievskaia if (!copy->cp_synchronous) { 1852e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 185329ae7f9dSAnna Schumaker 1854e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1855e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1856e0639dc5SOlga Kornievskaia if (!async_copy) 1857ce0887acSOlga Kornievskaia goto out_err; 1858ce0887acSOlga Kornievskaia if (!nfs4_init_copy_state(nn, copy)) 1859ce0887acSOlga Kornievskaia goto out_err; 1860e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1861e739b120SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid, 1862e739b120SOlga Kornievskaia sizeof(copy->cp_res.cb_stateid)); 1863eb162e17SChuck Lever dup_copy_fields(copy, async_copy); 1864e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1865e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1866e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1867e0639dc5SOlga Kornievskaia goto out_err; 1868e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1869e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1870e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1871e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1872e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1873e0639dc5SOlga Kornievskaia status = nfs_ok; 1874ce0887acSOlga Kornievskaia } else { 1875e0639dc5SOlga Kornievskaia status = nfsd4_do_copy(copy, 1); 1876ce0887acSOlga Kornievskaia } 187729ae7f9dSAnna Schumaker out: 187829ae7f9dSAnna Schumaker return status; 1879e0639dc5SOlga Kornievskaia out_err: 188018f428d4SOlga Kornievskaia if (async_copy) 1881e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1882ce0887acSOlga Kornievskaia status = nfserrno(-ENOMEM); 1883ce0887acSOlga Kornievskaia if (!copy->cp_intra) 1884ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1885e0639dc5SOlga Kornievskaia goto out; 1886e0639dc5SOlga Kornievskaia } 1887e0639dc5SOlga Kornievskaia 1888e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1889e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1890e0639dc5SOlga Kornievskaia { 1891e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1892e0639dc5SOlga Kornievskaia 1893e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1894e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1895ce0887acSOlga Kornievskaia if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE)) 1896e0639dc5SOlga Kornievskaia continue; 1897e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1898e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1899e0639dc5SOlga Kornievskaia return copy; 1900e0639dc5SOlga Kornievskaia } 1901e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1902e0639dc5SOlga Kornievskaia return NULL; 190329ae7f9dSAnna Schumaker } 190429ae7f9dSAnna Schumaker 190529ae7f9dSAnna Schumaker static __be32 1906885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1907885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1908885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1909885e2bf3SOlga Kornievskaia { 1910e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1911e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1912e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1913e0639dc5SOlga Kornievskaia 1914e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1915ce0887acSOlga Kornievskaia if (!copy) { 1916ce0887acSOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1917e0639dc5SOlga Kornievskaia 1918ce0887acSOlga Kornievskaia return manage_cpntf_state(nn, &os->stateid, clp, NULL); 1919ce0887acSOlga Kornievskaia } else 1920ce0887acSOlga Kornievskaia nfsd4_stop_copy(copy); 1921ce0887acSOlga Kornievskaia 1922ce0887acSOlga Kornievskaia return nfs_ok; 1923885e2bf3SOlga Kornievskaia } 1924885e2bf3SOlga Kornievskaia 1925885e2bf3SOlga Kornievskaia static __be32 192651911868SOlga Kornievskaia nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 192751911868SOlga Kornievskaia union nfsd4_op_u *u) 192851911868SOlga Kornievskaia { 1929624322f1SOlga Kornievskaia struct nfsd4_copy_notify *cn = &u->copy_notify; 1930624322f1SOlga Kornievskaia __be32 status; 1931624322f1SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1932624322f1SOlga Kornievskaia struct nfs4_stid *stid; 1933624322f1SOlga Kornievskaia struct nfs4_cpntf_state *cps; 1934624322f1SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1935624322f1SOlga Kornievskaia 1936624322f1SOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1937624322f1SOlga Kornievskaia &cn->cpn_src_stateid, RD_STATE, NULL, 1938624322f1SOlga Kornievskaia &stid); 1939624322f1SOlga Kornievskaia if (status) 1940624322f1SOlga Kornievskaia return status; 1941624322f1SOlga Kornievskaia 1942624322f1SOlga Kornievskaia cn->cpn_sec = nn->nfsd4_lease; 1943624322f1SOlga Kornievskaia cn->cpn_nsec = 0; 1944624322f1SOlga Kornievskaia 1945624322f1SOlga Kornievskaia status = nfserrno(-ENOMEM); 1946624322f1SOlga Kornievskaia cps = nfs4_alloc_init_cpntf_state(nn, stid); 1947624322f1SOlga Kornievskaia if (!cps) 1948624322f1SOlga Kornievskaia goto out; 1949624322f1SOlga Kornievskaia memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t)); 1950624322f1SOlga Kornievskaia memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t)); 1951624322f1SOlga Kornievskaia memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t)); 1952624322f1SOlga Kornievskaia 1953624322f1SOlga Kornievskaia /* For now, only return one server address in cpn_src, the 1954624322f1SOlga Kornievskaia * address used by the client to connect to this server. 1955624322f1SOlga Kornievskaia */ 1956624322f1SOlga Kornievskaia cn->cpn_src.nl4_type = NL4_NETADDR; 1957624322f1SOlga Kornievskaia status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, 1958624322f1SOlga Kornievskaia &cn->cpn_src.u.nl4_addr); 1959624322f1SOlga Kornievskaia WARN_ON_ONCE(status); 1960624322f1SOlga Kornievskaia if (status) { 1961624322f1SOlga Kornievskaia nfs4_put_cpntf_state(nn, cps); 1962624322f1SOlga Kornievskaia goto out; 1963624322f1SOlga Kornievskaia } 1964624322f1SOlga Kornievskaia out: 1965624322f1SOlga Kornievskaia nfs4_put_stid(stid); 1966624322f1SOlga Kornievskaia return status; 196751911868SOlga Kornievskaia } 196851911868SOlga Kornievskaia 196951911868SOlga Kornievskaia static __be32 197095d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 197195d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 197295d871f0SAnna Schumaker { 19730d4d6720SJ. Bruce Fields __be32 status; 19745c4583b2SJeff Layton struct nfsd_file *nf; 197595d871f0SAnna Schumaker 1976aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 197795d871f0SAnna Schumaker &fallocate->falloc_stateid, 1978624322f1SOlga Kornievskaia WR_STATE, &nf, NULL); 197995d871f0SAnna Schumaker if (status != nfs_ok) { 198095d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 198195d871f0SAnna Schumaker return status; 198295d871f0SAnna Schumaker } 198395d871f0SAnna Schumaker 19845c4583b2SJeff Layton status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, 198595d871f0SAnna Schumaker fallocate->falloc_offset, 198695d871f0SAnna Schumaker fallocate->falloc_length, 198795d871f0SAnna Schumaker flags); 19885c4583b2SJeff Layton nfsd_file_put(nf); 198995d871f0SAnna Schumaker return status; 199095d871f0SAnna Schumaker } 19916308bc98SOlga Kornievskaia static __be32 19926308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 19936308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 19946308bc98SOlga Kornievskaia union nfsd4_op_u *u) 19956308bc98SOlga Kornievskaia { 1996e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1997e0639dc5SOlga Kornievskaia __be32 status = 0; 1998e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1999e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 2000e0639dc5SOlga Kornievskaia 2001e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 2002e0639dc5SOlga Kornievskaia if (copy) { 2003e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 2004e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 2005e0639dc5SOlga Kornievskaia } else 2006e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 2007e0639dc5SOlga Kornievskaia 2008e0639dc5SOlga Kornievskaia return status; 20096308bc98SOlga Kornievskaia } 201095d871f0SAnna Schumaker 201195d871f0SAnna Schumaker static __be32 201295d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2013eb69853dSChristoph Hellwig union nfsd4_op_u *u) 201495d871f0SAnna Schumaker { 2015eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 201695d871f0SAnna Schumaker } 201795d871f0SAnna Schumaker 201895d871f0SAnna Schumaker static __be32 2019b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2020eb69853dSChristoph Hellwig union nfsd4_op_u *u) 2021b0cb9085SAnna Schumaker { 2022eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 2023b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 2024b0cb9085SAnna Schumaker } 2025b0cb9085SAnna Schumaker 2026b0cb9085SAnna Schumaker static __be32 202724bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2028eb69853dSChristoph Hellwig union nfsd4_op_u *u) 202924bab491SAnna Schumaker { 2030eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 203124bab491SAnna Schumaker int whence; 203224bab491SAnna Schumaker __be32 status; 20335c4583b2SJeff Layton struct nfsd_file *nf; 203424bab491SAnna Schumaker 2035aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 203624bab491SAnna Schumaker &seek->seek_stateid, 2037624322f1SOlga Kornievskaia RD_STATE, &nf, NULL); 203824bab491SAnna Schumaker if (status) { 203924bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 204024bab491SAnna Schumaker return status; 204124bab491SAnna Schumaker } 204224bab491SAnna Schumaker 204324bab491SAnna Schumaker switch (seek->seek_whence) { 204424bab491SAnna Schumaker case NFS4_CONTENT_DATA: 204524bab491SAnna Schumaker whence = SEEK_DATA; 204624bab491SAnna Schumaker break; 204724bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 204824bab491SAnna Schumaker whence = SEEK_HOLE; 204924bab491SAnna Schumaker break; 205024bab491SAnna Schumaker default: 205124bab491SAnna Schumaker status = nfserr_union_notsupp; 205224bab491SAnna Schumaker goto out; 205324bab491SAnna Schumaker } 205424bab491SAnna Schumaker 205524bab491SAnna Schumaker /* 205624bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 205724bab491SAnna Schumaker * should ever file->f_pos. 205824bab491SAnna Schumaker */ 20595c4583b2SJeff Layton seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); 206024bab491SAnna Schumaker if (seek->seek_pos < 0) 206124bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 20625c4583b2SJeff Layton else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) 206324bab491SAnna Schumaker seek->seek_eof = true; 206424bab491SAnna Schumaker 206524bab491SAnna Schumaker out: 20665c4583b2SJeff Layton nfsd_file_put(nf); 206724bab491SAnna Schumaker return status; 206824bab491SAnna Schumaker } 206924bab491SAnna Schumaker 20701da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 20711da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 20721da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 20731da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 20741da177e4SLinus Torvalds */ 2075b37ad28bSAl Viro static __be32 2076c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2077ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 20781da177e4SLinus Torvalds { 20792ebbc012SAl Viro __be32 *buf, *p; 20801da177e4SLinus Torvalds int count; 2081b37ad28bSAl Viro __be32 status; 20821da177e4SLinus Torvalds 20838837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 20841da177e4SLinus Torvalds if (status) 20851da177e4SLinus Torvalds return status; 20861da177e4SLinus Torvalds 20873c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 20883c8e0316SYu Zhiguo if (status) 20893c8e0316SYu Zhiguo return status; 20903c8e0316SYu Zhiguo 20911da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 20921da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 20931da177e4SLinus Torvalds return nfserr_inval; 20941da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 20951da177e4SLinus Torvalds return nfserr_inval; 20961da177e4SLinus Torvalds 20971da177e4SLinus Torvalds /* count in words: 20981da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 20991da177e4SLinus Torvalds */ 21001da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 21011da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 21021da177e4SLinus Torvalds if (!buf) 21033e772463SJ. Bruce Fields return nfserr_jukebox; 21041da177e4SLinus Torvalds 210584822d0bSJ. Bruce Fields p = buf; 2106d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 2107ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 2108d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 2109d5184658SJ. Bruce Fields verify->ve_bmval, 2110406a7ea9SFrank Filz rqstp, 0); 211141ae6e71SJ. Bruce Fields /* 211241ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 211341ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 211441ae6e71SJ. Bruce Fields */ 211584822d0bSJ. Bruce Fields if (status == nfserr_resource) 21161da177e4SLinus Torvalds status = nfserr_not_same; 21171da177e4SLinus Torvalds if (status) 21181da177e4SLinus Torvalds goto out_kfree; 21191da177e4SLinus Torvalds 212095ec28cdSBenny Halevy /* skip bitmap */ 212195ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 21221da177e4SLinus Torvalds status = nfserr_not_same; 21231da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 21241da177e4SLinus Torvalds goto out_kfree; 21251da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 21261da177e4SLinus Torvalds status = nfserr_same; 21271da177e4SLinus Torvalds 21281da177e4SLinus Torvalds out_kfree: 21291da177e4SLinus Torvalds kfree(buf); 21301da177e4SLinus Torvalds return status; 21311da177e4SLinus Torvalds } 21321da177e4SLinus Torvalds 2133c954e2a5SJ.Bruce Fields static __be32 2134c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2135eb69853dSChristoph Hellwig union nfsd4_op_u *u) 2136c954e2a5SJ.Bruce Fields { 2137c954e2a5SJ.Bruce Fields __be32 status; 2138c954e2a5SJ.Bruce Fields 2139eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 2140c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 2141c954e2a5SJ.Bruce Fields } 2142c954e2a5SJ.Bruce Fields 2143c954e2a5SJ.Bruce Fields static __be32 2144c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2145eb69853dSChristoph Hellwig union nfsd4_op_u *u) 2146c954e2a5SJ.Bruce Fields { 2147c954e2a5SJ.Bruce Fields __be32 status; 2148c954e2a5SJ.Bruce Fields 2149eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 2150c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 2151c954e2a5SJ.Bruce Fields } 2152c954e2a5SJ.Bruce Fields 21539cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 21549cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 21559cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 21569cf514ccSChristoph Hellwig { 21578a4c3926SJeff Layton if (!exp->ex_layout_types) { 21589cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 21599cf514ccSChristoph Hellwig return NULL; 21609cf514ccSChristoph Hellwig } 21619cf514ccSChristoph Hellwig 2162b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 2163b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 21649cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 21659cf514ccSChristoph Hellwig __func__, layout_type); 21669cf514ccSChristoph Hellwig return NULL; 21679cf514ccSChristoph Hellwig } 21689cf514ccSChristoph Hellwig 21699cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 21709cf514ccSChristoph Hellwig } 21719cf514ccSChristoph Hellwig 21729cf514ccSChristoph Hellwig static __be32 21739cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 2174eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 21759cf514ccSChristoph Hellwig { 2176eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 21779cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 21789cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 21799cf514ccSChristoph Hellwig struct svc_export *exp; 21809cf514ccSChristoph Hellwig __be32 nfserr; 21819cf514ccSChristoph Hellwig 21829cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 21839cf514ccSChristoph Hellwig __func__, 21849cf514ccSChristoph Hellwig gdp->gd_layout_type, 21859cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 21869cf514ccSChristoph Hellwig gdp->gd_maxcount); 21879cf514ccSChristoph Hellwig 21889cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 21899cf514ccSChristoph Hellwig if (!map) { 21909cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 21919cf514ccSChristoph Hellwig __func__); 21929cf514ccSChristoph Hellwig return nfserr_noent; 21939cf514ccSChristoph Hellwig } 21949cf514ccSChristoph Hellwig 21959cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 21969cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 21979cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 21989cf514ccSChristoph Hellwig return nfserr_noent; 21999cf514ccSChristoph Hellwig } 22009cf514ccSChristoph Hellwig 22019cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 22029cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 22039cf514ccSChristoph Hellwig if (!ops) 22049cf514ccSChristoph Hellwig goto out; 22059cf514ccSChristoph Hellwig 22069cf514ccSChristoph Hellwig nfserr = nfs_ok; 2207f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 2208f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 2209ec59659bSJ. Bruce Fields rqstp, cstate->clp, gdp); 2210f99d4fbdSChristoph Hellwig } 22119cf514ccSChristoph Hellwig 22129cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 22139cf514ccSChristoph Hellwig out: 2214a1420384SKinglong Mee exp_put(exp); 22159cf514ccSChristoph Hellwig return nfserr; 22169cf514ccSChristoph Hellwig } 22179cf514ccSChristoph Hellwig 221834b1744cSJ. Bruce Fields static void 221934b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 222034b1744cSJ. Bruce Fields { 222134b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 222234b1744cSJ. Bruce Fields } 222334b1744cSJ. Bruce Fields 22249cf514ccSChristoph Hellwig static __be32 22259cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 2226eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 22279cf514ccSChristoph Hellwig { 2228eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 22299cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 22309cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 22319cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 22329cf514ccSChristoph Hellwig __be32 nfserr; 223366282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 22349cf514ccSChristoph Hellwig 22359cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 22369cf514ccSChristoph Hellwig case IOMODE_READ: 223766282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 22389cf514ccSChristoph Hellwig break; 22399cf514ccSChristoph Hellwig case IOMODE_RW: 224066282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 22419cf514ccSChristoph Hellwig break; 22429cf514ccSChristoph Hellwig default: 22439cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 22449cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 22459cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 22469cf514ccSChristoph Hellwig goto out; 22479cf514ccSChristoph Hellwig } 22489cf514ccSChristoph Hellwig 22499cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 22509cf514ccSChristoph Hellwig if (nfserr) 22519cf514ccSChristoph Hellwig goto out; 22529cf514ccSChristoph Hellwig 22539cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 22549cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 22559cf514ccSChristoph Hellwig if (!ops) 22569cf514ccSChristoph Hellwig goto out; 22579cf514ccSChristoph Hellwig 22589cf514ccSChristoph Hellwig /* 22599cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 22609cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 22619cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 22629cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 22639cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 22649cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 22659cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 22669cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 22679cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 22689cf514ccSChristoph Hellwig */ 22699cf514ccSChristoph Hellwig nfserr = nfserr_inval; 22709cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 22719cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 22729cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 22739cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 22749cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 22759cf514ccSChristoph Hellwig goto out; 22769cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 22779cf514ccSChristoph Hellwig goto out; 22789cf514ccSChristoph Hellwig 22799cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 22809cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 228131ef83dcSChristoph Hellwig if (nfserr) { 2282f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 22839cf514ccSChristoph Hellwig goto out; 228431ef83dcSChristoph Hellwig } 22859cf514ccSChristoph Hellwig 2286c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 2287c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 2288c5c707f9SChristoph Hellwig goto out_put_stid; 2289c5c707f9SChristoph Hellwig 22902b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 22919cf514ccSChristoph Hellwig current_fh, lgp); 22929cf514ccSChristoph Hellwig if (nfserr) 22939cf514ccSChristoph Hellwig goto out_put_stid; 22949cf514ccSChristoph Hellwig 22959cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 22969cf514ccSChristoph Hellwig 22979cf514ccSChristoph Hellwig out_put_stid: 2298cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 22999cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 23009cf514ccSChristoph Hellwig out: 23019cf514ccSChristoph Hellwig return nfserr; 23029cf514ccSChristoph Hellwig } 23039cf514ccSChristoph Hellwig 230434b1744cSJ. Bruce Fields static void 230534b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 230634b1744cSJ. Bruce Fields { 230734b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 230834b1744cSJ. Bruce Fields } 230934b1744cSJ. Bruce Fields 23109cf514ccSChristoph Hellwig static __be32 23119cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 2312eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 23139cf514ccSChristoph Hellwig { 2314eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 23159cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 23169cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 23179cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 23189cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 23199cf514ccSChristoph Hellwig struct inode *inode; 23209cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 23219cf514ccSChristoph Hellwig __be32 nfserr; 23229cf514ccSChristoph Hellwig 23239cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 23249cf514ccSChristoph Hellwig if (nfserr) 23259cf514ccSChristoph Hellwig goto out; 23269cf514ccSChristoph Hellwig 23279cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 23289cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 23299cf514ccSChristoph Hellwig if (!ops) 23309cf514ccSChristoph Hellwig goto out; 23312b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 23329cf514ccSChristoph Hellwig 23339cf514ccSChristoph Hellwig nfserr = nfserr_inval; 23349cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 23359cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 23369cf514ccSChristoph Hellwig goto out; 23379cf514ccSChristoph Hellwig } 23389cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 23399cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 23409cf514ccSChristoph Hellwig goto out; 23419cf514ccSChristoph Hellwig } 23429cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 23439cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 23449cf514ccSChristoph Hellwig goto out; 23459cf514ccSChristoph Hellwig } 23469cf514ccSChristoph Hellwig 23479cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 23489cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 23499cf514ccSChristoph Hellwig &ls); 23509cf514ccSChristoph Hellwig if (nfserr) { 2351f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 23529cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 23539cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 23549cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 23559cf514ccSChristoph Hellwig goto out; 23569cf514ccSChristoph Hellwig } 23579cf514ccSChristoph Hellwig 2358cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 2359cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 2360cc8a5532SJeff Layton 23619cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 23629cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 23639cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 23649cf514ccSChristoph Hellwig } else { 23659cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 23669cf514ccSChristoph Hellwig } 23679cf514ccSChristoph Hellwig 2368d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 23699cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 23709cf514ccSChristoph Hellwig out: 23719cf514ccSChristoph Hellwig return nfserr; 23729cf514ccSChristoph Hellwig } 23739cf514ccSChristoph Hellwig 23749cf514ccSChristoph Hellwig static __be32 23759cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 2376eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 23779cf514ccSChristoph Hellwig { 2378eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 23799cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 23809cf514ccSChristoph Hellwig __be32 nfserr; 23819cf514ccSChristoph Hellwig 23829cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 23839cf514ccSChristoph Hellwig if (nfserr) 23849cf514ccSChristoph Hellwig goto out; 23859cf514ccSChristoph Hellwig 23869cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 23879cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 23889cf514ccSChristoph Hellwig goto out; 23899cf514ccSChristoph Hellwig 23909cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 23919cf514ccSChristoph Hellwig case IOMODE_READ: 23929cf514ccSChristoph Hellwig case IOMODE_RW: 23939cf514ccSChristoph Hellwig case IOMODE_ANY: 23949cf514ccSChristoph Hellwig break; 23959cf514ccSChristoph Hellwig default: 23969cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 23979cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 23989cf514ccSChristoph Hellwig nfserr = nfserr_inval; 23999cf514ccSChristoph Hellwig goto out; 24009cf514ccSChristoph Hellwig } 24019cf514ccSChristoph Hellwig 24029cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 24039cf514ccSChristoph Hellwig case RETURN_FILE: 24049cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 24059cf514ccSChristoph Hellwig break; 24069cf514ccSChristoph Hellwig case RETURN_FSID: 24079cf514ccSChristoph Hellwig case RETURN_ALL: 24089cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 24099cf514ccSChristoph Hellwig break; 24109cf514ccSChristoph Hellwig default: 24119cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 24129cf514ccSChristoph Hellwig lrp->lr_return_type); 24139cf514ccSChristoph Hellwig nfserr = nfserr_inval; 24149cf514ccSChristoph Hellwig break; 24159cf514ccSChristoph Hellwig } 24169cf514ccSChristoph Hellwig out: 24179cf514ccSChristoph Hellwig return nfserr; 24189cf514ccSChristoph Hellwig } 24199cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 24209cf514ccSChristoph Hellwig 242123e50fe3SFrank van der Linden static __be32 242223e50fe3SFrank van der Linden nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 242323e50fe3SFrank van der Linden union nfsd4_op_u *u) 242423e50fe3SFrank van der Linden { 242523e50fe3SFrank van der Linden struct nfsd4_getxattr *getxattr = &u->getxattr; 242623e50fe3SFrank van der Linden 242723e50fe3SFrank van der Linden return nfsd_getxattr(rqstp, &cstate->current_fh, 242823e50fe3SFrank van der Linden getxattr->getxa_name, &getxattr->getxa_buf, 242923e50fe3SFrank van der Linden &getxattr->getxa_len); 243023e50fe3SFrank van der Linden } 243123e50fe3SFrank van der Linden 243223e50fe3SFrank van der Linden static __be32 243323e50fe3SFrank van der Linden nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 243423e50fe3SFrank van der Linden union nfsd4_op_u *u) 243523e50fe3SFrank van der Linden { 243623e50fe3SFrank van der Linden struct nfsd4_setxattr *setxattr = &u->setxattr; 243723e50fe3SFrank van der Linden __be32 ret; 243823e50fe3SFrank van der Linden 243923e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 244023e50fe3SFrank van der Linden return nfserr_grace; 244123e50fe3SFrank van der Linden 244223e50fe3SFrank van der Linden ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name, 244323e50fe3SFrank van der Linden setxattr->setxa_buf, setxattr->setxa_len, 244423e50fe3SFrank van der Linden setxattr->setxa_flags); 244523e50fe3SFrank van der Linden 244623e50fe3SFrank van der Linden if (!ret) 244723e50fe3SFrank van der Linden set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh); 244823e50fe3SFrank van der Linden 244923e50fe3SFrank van der Linden return ret; 245023e50fe3SFrank van der Linden } 245123e50fe3SFrank van der Linden 245223e50fe3SFrank van der Linden static __be32 245323e50fe3SFrank van der Linden nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 245423e50fe3SFrank van der Linden union nfsd4_op_u *u) 245523e50fe3SFrank van der Linden { 245623e50fe3SFrank van der Linden /* 245723e50fe3SFrank van der Linden * Get the entire list, then copy out only the user attributes 245823e50fe3SFrank van der Linden * in the encode function. 245923e50fe3SFrank van der Linden */ 246023e50fe3SFrank van der Linden return nfsd_listxattr(rqstp, &cstate->current_fh, 246123e50fe3SFrank van der Linden &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len); 246223e50fe3SFrank van der Linden } 246323e50fe3SFrank van der Linden 246423e50fe3SFrank van der Linden static __be32 246523e50fe3SFrank van der Linden nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 246623e50fe3SFrank van der Linden union nfsd4_op_u *u) 246723e50fe3SFrank van der Linden { 246823e50fe3SFrank van der Linden struct nfsd4_removexattr *removexattr = &u->removexattr; 246923e50fe3SFrank van der Linden __be32 ret; 247023e50fe3SFrank van der Linden 247123e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 247223e50fe3SFrank van der Linden return nfserr_grace; 247323e50fe3SFrank van der Linden 247423e50fe3SFrank van der Linden ret = nfsd_removexattr(rqstp, &cstate->current_fh, 247523e50fe3SFrank van der Linden removexattr->rmxa_name); 247623e50fe3SFrank van der Linden 247723e50fe3SFrank van der Linden if (!ret) 247823e50fe3SFrank van der Linden set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh); 247923e50fe3SFrank van der Linden 248023e50fe3SFrank van der Linden return ret; 248123e50fe3SFrank van der Linden } 248223e50fe3SFrank van der Linden 24831da177e4SLinus Torvalds /* 24841da177e4SLinus Torvalds * NULL call. 24851da177e4SLinus Torvalds */ 24867111c66eSAl Viro static __be32 2487a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 24881da177e4SLinus Torvalds { 2489cc028a10SChuck Lever return rpc_success; 24901da177e4SLinus Torvalds } 24911da177e4SLinus Torvalds 2492e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 2493e2b20950SShankar Anand { 2494e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 2495e567b98cSAmir Goldstein percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]); 2496e2b20950SShankar Anand } 2497e2b20950SShankar Anand 2498bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 2499b591480bSJ.Bruce Fields 2500f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 2501b001a1b6SBenny Halevy 25021da177e4SLinus Torvalds /* 250357716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 2504f9bb94c4SAndy Adamson * 250557716355SJ. Bruce Fields * Also note, enforced elsewhere: 250657716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 250757716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 25081d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 25091d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 251057716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 251157716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 251257716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 2513f9bb94c4SAndy Adamson */ 251457716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 2515f9bb94c4SAndy Adamson { 25167a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 251757716355SJ. Bruce Fields 251857716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 251957716355SJ. Bruce Fields if (args->minorversion == 0) 252057716355SJ. Bruce Fields return nfs_ok; 252157716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 252257716355SJ. Bruce Fields if (args->opcnt == 0) 252357716355SJ. Bruce Fields return nfs_ok; 25247a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 252557716355SJ. Bruce Fields return nfs_ok; 25267a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 252757716355SJ. Bruce Fields return nfserr_op_not_in_session; 25287a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 252957716355SJ. Bruce Fields return nfs_ok; 25307a04cfdaSJ. Bruce Fields /* 25317a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 25327a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 25337a04cfdaSJ. Bruce Fields * compound: 25347a04cfdaSJ. Bruce Fields */ 253557716355SJ. Bruce Fields if (args->opcnt != 1) 253657716355SJ. Bruce Fields return nfserr_not_only_op; 253757716355SJ. Bruce Fields return nfs_ok; 2538f9bb94c4SAndy Adamson } 2539f9bb94c4SAndy Adamson 2540f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 254122b03214SJ. Bruce Fields { 254222b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 254322b03214SJ. Bruce Fields } 254422b03214SJ. Bruce Fields 25451091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 25461091006cSJ. Bruce Fields { 2547e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 2548e372ba60SJ. Bruce Fields return false; 2549c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 25501091006cSJ. Bruce Fields } 25511091006cSJ. Bruce Fields 255268d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 255368d93184SJ. Bruce Fields { 255468d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 255568d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 255668d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 255768d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 2558bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 2559bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 256068d93184SJ. Bruce Fields 256168d93184SJ. Bruce Fields /* 256268d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 256368d93184SJ. Bruce Fields * have special rules. 256468d93184SJ. Bruce Fields */ 256568d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 256668d93184SJ. Bruce Fields return false; 256768d93184SJ. Bruce Fields /* 256868d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 256968d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 257068d93184SJ. Bruce Fields * result: 257168d93184SJ. Bruce Fields */ 257268d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 257368d93184SJ. Bruce Fields return false; 257451904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 257551904b08SJ. Bruce Fields return false; 257668d93184SJ. Bruce Fields nextd = OPDESC(next); 257768d93184SJ. Bruce Fields /* 257868d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 257968d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 258068d93184SJ. Bruce Fields * now: 258168d93184SJ. Bruce Fields */ 258268d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 258368d93184SJ. Bruce Fields } 258468d93184SJ. Bruce Fields 2585b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 2586b9e8638eSOlga Kornievskaia static void 2587b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2588b9e8638eSOlga Kornievskaia { 2589b9e8638eSOlga Kornievskaia struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; 2590b9e8638eSOlga Kornievskaia struct nfsd4_copy *copy; 2591b9e8638eSOlga Kornievskaia struct nfsd4_putfh *putfh; 2592b9e8638eSOlga Kornievskaia int i; 2593b9e8638eSOlga Kornievskaia 2594b9e8638eSOlga Kornievskaia /* traverse all operation and if it's a COPY compound, mark the 2595b9e8638eSOlga Kornievskaia * source filehandle to skip verification 2596b9e8638eSOlga Kornievskaia */ 2597b9e8638eSOlga Kornievskaia for (i = 0; i < args->opcnt; i++) { 2598b9e8638eSOlga Kornievskaia op = &args->ops[i]; 2599b9e8638eSOlga Kornievskaia if (op->opnum == OP_PUTFH) 2600b9e8638eSOlga Kornievskaia current_op = op; 2601b9e8638eSOlga Kornievskaia else if (op->opnum == OP_SAVEFH) 2602b9e8638eSOlga Kornievskaia saved_op = current_op; 2603b9e8638eSOlga Kornievskaia else if (op->opnum == OP_RESTOREFH) 2604b9e8638eSOlga Kornievskaia current_op = saved_op; 2605b9e8638eSOlga Kornievskaia else if (op->opnum == OP_COPY) { 2606b9e8638eSOlga Kornievskaia copy = (struct nfsd4_copy *)&op->u; 2607b9e8638eSOlga Kornievskaia if (!saved_op) { 2608b9e8638eSOlga Kornievskaia op->status = nfserr_nofilehandle; 2609b9e8638eSOlga Kornievskaia return; 2610b9e8638eSOlga Kornievskaia } 2611b9e8638eSOlga Kornievskaia putfh = (struct nfsd4_putfh *)&saved_op->u; 2612b9e8638eSOlga Kornievskaia if (!copy->cp_intra) 2613b9e8638eSOlga Kornievskaia putfh->no_verify = true; 2614b9e8638eSOlga Kornievskaia } 2615b9e8638eSOlga Kornievskaia } 2616b9e8638eSOlga Kornievskaia } 2617b9e8638eSOlga Kornievskaia #else 2618b9e8638eSOlga Kornievskaia static void 2619b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2620b9e8638eSOlga Kornievskaia { 2621b9e8638eSOlga Kornievskaia } 2622b9e8638eSOlga Kornievskaia #endif 2623b9e8638eSOlga Kornievskaia 2624f9bb94c4SAndy Adamson /* 26251da177e4SLinus Torvalds * COMPOUND call. 26261da177e4SLinus Torvalds */ 26277111c66eSAl Viro static __be32 2628a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 26291da177e4SLinus Torvalds { 2630a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 2631a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 26321da177e4SLinus Torvalds struct nfsd4_op *op; 2633e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 26344daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 26354daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 2636e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 2637b37ad28bSAl Viro __be32 status; 26381da177e4SLinus Torvalds 2639bddfdbcdSChuck Lever resp->xdr = &rqstp->rq_res_stream; 26403b0ebb25SChuck Lever resp->statusp = resp->xdr->p; 2641bddfdbcdSChuck Lever 2642bddfdbcdSChuck Lever /* reserve space for: NFS status code */ 2643bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT); 2644bddfdbcdSChuck Lever 26451da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 2646bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen); 26471da177e4SLinus Torvalds resp->taglen = args->taglen; 26481da177e4SLinus Torvalds resp->tag = args->tag; 26491da177e4SLinus Torvalds resp->rqstp = rqstp; 26504daeed25SKinglong Mee cstate->minorversion = args->minorversion; 26514daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 26524daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 265328df0988SChuck Lever 26548ff30fa4SNeilBrown /* 26558ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 26568ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 26578ff30fa4SNeilBrown */ 265828df0988SChuck Lever __clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 26591da177e4SLinus Torvalds 26601da177e4SLinus Torvalds /* 26611da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 26621da177e4SLinus Torvalds */ 26631da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 2664e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 26651da177e4SLinus Torvalds goto out; 26660078117cSJ. Bruce Fields status = nfserr_resource; 26670078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 26680078117cSJ. Bruce Fields goto out; 26691da177e4SLinus Torvalds 267057716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 267157716355SJ. Bruce Fields if (status) { 2672f9bb94c4SAndy Adamson op = &args->ops[0]; 267357716355SJ. Bruce Fields op->status = status; 26745b7b15aeSJ. Bruce Fields resp->opcnt = 1; 2675f9bb94c4SAndy Adamson goto encode_op; 2676f9bb94c4SAndy Adamson } 2677b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(args); 2678f9bb94c4SAndy Adamson 267928df3d15SJ. Bruce Fields rqstp->rq_lease_breaker = (void **)&cstate->clp; 268028df3d15SJ. Bruce Fields 2681fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 26821da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 26831da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 26841da177e4SLinus Torvalds 26851da177e4SLinus Torvalds /* 26861da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 26871da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 26881da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 26891da177e4SLinus Torvalds */ 26909d313b17SJ. Bruce Fields if (op->status) { 26919d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 26929d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 26931da177e4SLinus Torvalds goto encode_op; 26949d313b17SJ. Bruce Fields } 2695b9e8638eSOlga Kornievskaia if (!current_fh->fh_dentry && 2696b9e8638eSOlga Kornievskaia !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { 2697f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 26981da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 26991da177e4SLinus Torvalds goto encode_op; 27001da177e4SLinus Torvalds } 2701b9e8638eSOlga Kornievskaia } else if (current_fh->fh_export && 2702b9e8638eSOlga Kornievskaia current_fh->fh_export->ex_fslocs.migrated && 2703f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 270442ca0993SJ.Bruce Fields op->status = nfserr_moved; 270542ca0993SJ.Bruce Fields goto encode_op; 270642ca0993SJ.Bruce Fields } 2707b591480bSJ.Bruce Fields 2708fcb5e3faSChuck Lever fh_clear_pre_post_attrs(current_fh); 27092336745eSKinglong Mee 271058e7b33aSMi Jinlong /* If op is non-idempotent */ 2711f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 27124c69d585SJ. Bruce Fields /* 2713a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2714f532c9ffSZhang Jiaming * successful reply: 2715a8095f7eSJ. Bruce Fields */ 2716f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2717a8095f7eSJ. Bruce Fields /* 2718a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 27194c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 27204c69d585SJ. Bruce Fields */ 27214c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 27224c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 272358e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 272458e7b33aSMi Jinlong } 272558e7b33aSMi Jinlong 272658e7b33aSMi Jinlong if (op->status) 272758e7b33aSMi Jinlong goto encode_op; 272858e7b33aSMi Jinlong 2729f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2730f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2731f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 27321da177e4SLinus Torvalds 27339a307403SJ. Bruce Fields /* Only from SEQUENCE */ 27349a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 27359a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 27369a307403SJ. Bruce Fields status = op->status; 27379a307403SJ. Bruce Fields goto out; 27389a307403SJ. Bruce Fields } 27398b70484cSTigran Mkrtchyan if (!op->status) { 2740f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2741f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 27428b70484cSTigran Mkrtchyan 2743f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 274437c593c5STigran Mkrtchyan clear_current_stateid(cstate); 27458b70484cSTigran Mkrtchyan 2746d781e3dfSJ. Bruce Fields if (current_fh->fh_export && 2747d781e3dfSJ. Bruce Fields need_wrongsec_check(rqstp)) 27484daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 27498b70484cSTigran Mkrtchyan } 27501da177e4SLinus Torvalds encode_op: 2751a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2752a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2753bddfdbcdSChuck Lever nfsd4_encode_replay(resp->xdr, op); 27541da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 27551da177e4SLinus Torvalds } else { 27561da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 27571da177e4SLinus Torvalds status = op->status; 27581da177e4SLinus Torvalds } 27590407717dSBenny Halevy 2760fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2761fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 27620407717dSBenny Halevy 276358fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2764e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 27651da177e4SLinus Torvalds } 27661da177e4SLinus Torvalds 27674daeed25SKinglong Mee fh_put(current_fh); 27684daeed25SKinglong Mee fh_put(save_fh); 27694daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 27701da177e4SLinus Torvalds out: 2771cc028a10SChuck Lever cstate->status = status; 27722f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 277328df0988SChuck Lever __set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 2774cc028a10SChuck Lever return rpc_success; 27751da177e4SLinus Torvalds } 27761da177e4SLinus Torvalds 277758e7b33aSMi Jinlong #define op_encode_hdr_size (2) 277858e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 277958e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 278058e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 278158e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 278258e7b33aSMi Jinlong 27838c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 27848c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 278558e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 278658e7b33aSMi Jinlong 278758e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 278858e7b33aSMi Jinlong 278958e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 279058e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 279158e7b33aSMi Jinlong op_encode_ace_maxsz) 279258e7b33aSMi Jinlong 279358e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 279458e7b33aSMi Jinlong 279558e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 279658e7b33aSMi Jinlong { 279758e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 279858e7b33aSMi Jinlong } 279958e7b33aSMi Jinlong 280058e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 280158e7b33aSMi Jinlong { 280258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 280358e7b33aSMi Jinlong } 280458e7b33aSMi Jinlong 28052282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28062282cd2cSKinglong Mee { 28072282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 28082282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 28092282cd2cSKinglong Mee } 28102282cd2cSKinglong Mee 281158e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 281258e7b33aSMi Jinlong { 281358e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 281458e7b33aSMi Jinlong } 281558e7b33aSMi Jinlong 281658e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 281758e7b33aSMi Jinlong { 281858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 281958e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 282058e7b33aSMi Jinlong } 282158e7b33aSMi Jinlong 2822b86cef60SJ. Bruce Fields /* 2823b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2824b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2825b86cef60SJ. Bruce Fields * reads unnecessarily. 2826b86cef60SJ. Bruce Fields */ 2827b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2828b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2829b86cef60SJ. Bruce Fields { 2830b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2831b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2832b86cef60SJ. Bruce Fields u32 ret = 0; 2833b86cef60SJ. Bruce Fields 2834b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2835b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2836b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2837b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2838b86cef60SJ. Bruce Fields 2839b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2840b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2841b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2842b86cef60SJ. Bruce Fields } 2843b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2844b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2845b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2846b86cef60SJ. Bruce Fields } 2847b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2848b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2849b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2850b86cef60SJ. Bruce Fields } 2851b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 28521ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2853b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2854b86cef60SJ. Bruce Fields } 2855b86cef60SJ. Bruce Fields /* 2856b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2857b86cef60SJ. Bruce Fields * supported_attributes) 2858b86cef60SJ. Bruce Fields */ 2859b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2860b86cef60SJ. Bruce Fields /* bitmask, length */ 2861b86cef60SJ. Bruce Fields ret += 20; 2862b86cef60SJ. Bruce Fields return ret; 2863b86cef60SJ. Bruce Fields } 2864b86cef60SJ. Bruce Fields 28652282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28662282cd2cSKinglong Mee { 28672282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 28682282cd2cSKinglong Mee } 28692282cd2cSKinglong Mee 287058e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 287158e7b33aSMi Jinlong { 287258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 287358e7b33aSMi Jinlong * sizeof(__be32); 287458e7b33aSMi Jinlong } 287558e7b33aSMi Jinlong 287658e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 287758e7b33aSMi Jinlong { 287858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 287958e7b33aSMi Jinlong * sizeof(__be32); 288058e7b33aSMi Jinlong } 288158e7b33aSMi Jinlong 288258e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 288358e7b33aSMi Jinlong { 288458e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 288558e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 288658e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 288758e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 288858e7b33aSMi Jinlong } 288958e7b33aSMi Jinlong 289058e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 289158e7b33aSMi Jinlong { 289258e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 289358e7b33aSMi Jinlong 289458e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 28953c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 289658e7b33aSMi Jinlong 2897622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 289858e7b33aSMi Jinlong } 289958e7b33aSMi Jinlong 2900528b8493SAnna Schumaker static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 2901528b8493SAnna Schumaker { 2902528b8493SAnna Schumaker u32 maxcount = svc_max_payload(rqstp); 2903528b8493SAnna Schumaker u32 rlen = min(op->u.read.rd_length, maxcount); 2904528b8493SAnna Schumaker /* 2905528b8493SAnna Schumaker * If we detect that the file changed during hole encoding, then we 2906528b8493SAnna Schumaker * recover by encoding the remaining reply as data. This means we need 2907528b8493SAnna Schumaker * to set aside enough room to encode two data segments. 2908528b8493SAnna Schumaker */ 2909528b8493SAnna Schumaker u32 seg_len = 2 * (1 + 2 + 1); 2910528b8493SAnna Schumaker 2911528b8493SAnna Schumaker return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32); 2912528b8493SAnna Schumaker } 2913528b8493SAnna Schumaker 291458e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 291558e7b33aSMi Jinlong { 29163c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 291758e7b33aSMi Jinlong 29183c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 29193c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 292058e7b33aSMi Jinlong 2921561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2922561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 292358e7b33aSMi Jinlong } 292458e7b33aSMi Jinlong 29252282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29262282cd2cSKinglong Mee { 29272282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 29282282cd2cSKinglong Mee } 29292282cd2cSKinglong Mee 293058e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 293158e7b33aSMi Jinlong { 293258e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 293358e7b33aSMi Jinlong * sizeof(__be32); 293458e7b33aSMi Jinlong } 293558e7b33aSMi Jinlong 293658e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 293758e7b33aSMi Jinlong { 293858e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 293958e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 294058e7b33aSMi Jinlong } 294158e7b33aSMi Jinlong 2942ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2943ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2944ccae70a9SJ. Bruce Fields { 2945d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2946d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2947ccae70a9SJ. Bruce Fields } 2948ccae70a9SJ. Bruce Fields 29492282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29502282cd2cSKinglong Mee { 29512282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 29522282cd2cSKinglong Mee * sizeof(__be32); 29532282cd2cSKinglong Mee } 29542282cd2cSKinglong Mee 295558e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 295658e7b33aSMi Jinlong { 295758e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 295858e7b33aSMi Jinlong } 295958e7b33aSMi Jinlong 29602282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29612282cd2cSKinglong Mee { 29622282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 29632282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 29642282cd2cSKinglong Mee } 29652282cd2cSKinglong Mee 296658e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 296758e7b33aSMi Jinlong { 2968480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2969480efaeeSJ. Bruce Fields sizeof(__be32); 297058e7b33aSMi Jinlong } 297158e7b33aSMi Jinlong 297258e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 297358e7b33aSMi Jinlong { 2974f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 297558e7b33aSMi Jinlong } 297658e7b33aSMi Jinlong 297758e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 297858e7b33aSMi Jinlong { 297958e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2980a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2981a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 298258e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 298358e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 298458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 298558e7b33aSMi Jinlong /* eir_server_scope<> */\ 298658e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 298758e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 298858e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 298958e7b33aSMi Jinlong } 299058e7b33aSMi Jinlong 299158e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 299258e7b33aSMi Jinlong { 299358e7b33aSMi Jinlong return (op_encode_hdr_size + \ 299458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 299558e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 299658e7b33aSMi Jinlong } 299758e7b33aSMi Jinlong 299858e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 299958e7b33aSMi Jinlong { 300058e7b33aSMi Jinlong return (op_encode_hdr_size + \ 300158e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 300258e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 300358e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 300458e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 300558e7b33aSMi Jinlong } 300658e7b33aSMi Jinlong 300729ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 300829ae7f9dSAnna Schumaker { 300929ae7f9dSAnna Schumaker return (op_encode_hdr_size + 301029ae7f9dSAnna Schumaker 1 /* wr_callback */ + 301129ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 301229ae7f9dSAnna Schumaker 2 /* wr_count */ + 301329ae7f9dSAnna Schumaker 1 /* wr_committed */ + 301429ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 301529ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 301629ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 301729ae7f9dSAnna Schumaker } 301829ae7f9dSAnna Schumaker 30196308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 30206308bc98SOlga Kornievskaia struct nfsd4_op *op) 30216308bc98SOlga Kornievskaia { 30226308bc98SOlga Kornievskaia return (op_encode_hdr_size + 30236308bc98SOlga Kornievskaia 2 /* osr_count */ + 30246308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 30256308bc98SOlga Kornievskaia } 30266308bc98SOlga Kornievskaia 302751911868SOlga Kornievskaia static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, 302851911868SOlga Kornievskaia struct nfsd4_op *op) 302951911868SOlga Kornievskaia { 303051911868SOlga Kornievskaia return (op_encode_hdr_size + 303151911868SOlga Kornievskaia 3 /* cnr_lease_time */ + 303251911868SOlga Kornievskaia 1 /* We support one cnr_source_server */ + 303351911868SOlga Kornievskaia 1 /* cnr_stateid seq */ + 303451911868SOlga Kornievskaia op_encode_stateid_maxsz /* cnr_stateid */ + 303551911868SOlga Kornievskaia 1 /* num cnr_source_server*/ + 303651911868SOlga Kornievskaia 1 /* nl4_type */ + 303751911868SOlga Kornievskaia 1 /* nl4 size */ + 303851911868SOlga Kornievskaia XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) 303951911868SOlga Kornievskaia * sizeof(__be32); 304051911868SOlga Kornievskaia } 304151911868SOlga Kornievskaia 30429cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 30432282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30442282cd2cSKinglong Mee { 30452282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 30462282cd2cSKinglong Mee 30472282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 30482282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 30492282cd2cSKinglong Mee 30502282cd2cSKinglong Mee return (op_encode_hdr_size + 30512282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 30522282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 30532282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 30542282cd2cSKinglong Mee } 30552282cd2cSKinglong Mee 30569cf514ccSChristoph Hellwig /* 30579cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 30589cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 30599cf514ccSChristoph Hellwig */ 30609cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 30619cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30629cf514ccSChristoph Hellwig { 30639cf514ccSChristoph Hellwig return (op_encode_hdr_size + 30649cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 30659cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 30669cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 30679cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 30689cf514ccSChristoph Hellwig } 30699cf514ccSChristoph Hellwig 30709cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30719cf514ccSChristoph Hellwig { 30729cf514ccSChristoph Hellwig return (op_encode_hdr_size + 30739cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 30749cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 30759cf514ccSChristoph Hellwig } 30769cf514ccSChristoph Hellwig 30779cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30789cf514ccSChristoph Hellwig { 30799cf514ccSChristoph Hellwig return (op_encode_hdr_size + 30809cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 30819cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 30829cf514ccSChristoph Hellwig } 30839cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 30849cf514ccSChristoph Hellwig 30852282cd2cSKinglong Mee 30862282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30872282cd2cSKinglong Mee { 30882282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 30892282cd2cSKinglong Mee } 30902282cd2cSKinglong Mee 309123e50fe3SFrank van der Linden static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp, 309223e50fe3SFrank van der Linden struct nfsd4_op *op) 309323e50fe3SFrank van der Linden { 309423e50fe3SFrank van der Linden u32 maxcount, rlen; 309523e50fe3SFrank van der Linden 309623e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 309723e50fe3SFrank van der Linden rlen = min_t(u32, XATTR_SIZE_MAX, maxcount); 309823e50fe3SFrank van der Linden 309923e50fe3SFrank van der Linden return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); 310023e50fe3SFrank van der Linden } 310123e50fe3SFrank van der Linden 310223e50fe3SFrank van der Linden static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp, 310323e50fe3SFrank van der Linden struct nfsd4_op *op) 310423e50fe3SFrank van der Linden { 310523e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 310623e50fe3SFrank van der Linden * sizeof(__be32); 310723e50fe3SFrank van der Linden } 310823e50fe3SFrank van der Linden static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp, 310923e50fe3SFrank van der Linden struct nfsd4_op *op) 311023e50fe3SFrank van der Linden { 311123e50fe3SFrank van der Linden u32 maxcount, rlen; 311223e50fe3SFrank van der Linden 311323e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 311423e50fe3SFrank van der Linden rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount); 311523e50fe3SFrank van der Linden 311623e50fe3SFrank van der Linden return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); 311723e50fe3SFrank van der Linden } 311823e50fe3SFrank van der Linden 311923e50fe3SFrank van der Linden static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp, 312023e50fe3SFrank van der Linden struct nfsd4_op *op) 312123e50fe3SFrank van der Linden { 312223e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 312323e50fe3SFrank van der Linden * sizeof(__be32); 312423e50fe3SFrank van der Linden } 312523e50fe3SFrank van der Linden 312623e50fe3SFrank van der Linden 3127bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 3128b591480bSJ.Bruce Fields [OP_ACCESS] = { 3129eb69853dSChristoph Hellwig .op_func = nfsd4_access, 3130b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 31311c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 3132b591480bSJ.Bruce Fields }, 3133b591480bSJ.Bruce Fields [OP_CLOSE] = { 3134eb69853dSChristoph Hellwig .op_func = nfsd4_close, 313558e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3136b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 31371c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 313857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 3139b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 3140b591480bSJ.Bruce Fields }, 3141b591480bSJ.Bruce Fields [OP_COMMIT] = { 3142eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 314358e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3144b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 31451c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 3146b591480bSJ.Bruce Fields }, 3147b591480bSJ.Bruce Fields [OP_CREATE] = { 3148eb69853dSChristoph Hellwig .op_func = nfsd4_create, 3149d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 3150b001a1b6SBenny Halevy .op_name = "OP_CREATE", 31511c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 3152b591480bSJ.Bruce Fields }, 3153b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 3154eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 315558e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3156b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 315758e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 315857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 3159b591480bSJ.Bruce Fields }, 3160b591480bSJ.Bruce Fields [OP_GETATTR] = { 3161eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 3162eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 3163b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 3164b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 3165b591480bSJ.Bruce Fields }, 3166b591480bSJ.Bruce Fields [OP_GETFH] = { 3167eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 3168b001a1b6SBenny Halevy .op_name = "OP_GETFH", 31691c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 3170b591480bSJ.Bruce Fields }, 3171b591480bSJ.Bruce Fields [OP_LINK] = { 3172eb69853dSChristoph Hellwig .op_func = nfsd4_link, 3173c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 3174c856694eSJ. Bruce Fields | OP_CACHEME, 3175b001a1b6SBenny Halevy .op_name = "OP_LINK", 31761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 3177b591480bSJ.Bruce Fields }, 3178b591480bSJ.Bruce Fields [OP_LOCK] = { 3179eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 3180b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 3181b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 3182b001a1b6SBenny Halevy .op_name = "OP_LOCK", 31831c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3184b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 3185b591480bSJ.Bruce Fields }, 3186b591480bSJ.Bruce Fields [OP_LOCKT] = { 3187eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 3188b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 3189b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 31901c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3191b591480bSJ.Bruce Fields }, 3192b591480bSJ.Bruce Fields [OP_LOCKU] = { 3193eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 319458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3195b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 31961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 319757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 3198b591480bSJ.Bruce Fields }, 3199b591480bSJ.Bruce Fields [OP_LOOKUP] = { 3200eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 3201d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3202b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 32031c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3204b591480bSJ.Bruce Fields }, 3205b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 3206eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 3207d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3208b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 32091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3210b591480bSJ.Bruce Fields }, 3211b591480bSJ.Bruce Fields [OP_NVERIFY] = { 3212eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 3213b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 32141c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3215b591480bSJ.Bruce Fields }, 3216b591480bSJ.Bruce Fields [OP_OPEN] = { 3217eb69853dSChristoph Hellwig .op_func = nfsd4_open, 321858e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3219b001a1b6SBenny Halevy .op_name = "OP_OPEN", 32201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 3221b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 3222b591480bSJ.Bruce Fields }, 3223b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 3224eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 322558e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3226b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 32271c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 3228b591480bSJ.Bruce Fields }, 3229b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 3230eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 323158e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3232b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 32331c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 323457832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 3235b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 3236b591480bSJ.Bruce Fields }, 3237b591480bSJ.Bruce Fields [OP_PUTFH] = { 3238eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 323968d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 32405b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3241b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 32421c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3243b591480bSJ.Bruce Fields }, 3244eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 3245eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 324668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 32475b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3248b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 32491c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3250eeac294eSJ.Bruce Fields }, 3251b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 3252eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 325368d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 32545b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3255b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 32561c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3257b591480bSJ.Bruce Fields }, 3258b591480bSJ.Bruce Fields [OP_READ] = { 3259eb69853dSChristoph Hellwig .op_func = nfsd4_read, 326034b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 3261b001a1b6SBenny Halevy .op_name = "OP_READ", 32621c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 326357832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 3264b591480bSJ.Bruce Fields }, 3265b591480bSJ.Bruce Fields [OP_READDIR] = { 3266eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 3267b001a1b6SBenny Halevy .op_name = "OP_READDIR", 32681c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 3269b591480bSJ.Bruce Fields }, 3270b591480bSJ.Bruce Fields [OP_READLINK] = { 3271eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 3272b001a1b6SBenny Halevy .op_name = "OP_READLINK", 32731c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 3274b591480bSJ.Bruce Fields }, 3275b591480bSJ.Bruce Fields [OP_REMOVE] = { 3276eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 3277c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3278b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 32791c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 3280b591480bSJ.Bruce Fields }, 3281b591480bSJ.Bruce Fields [OP_RENAME] = { 3282eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 3283c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 328458e7b33aSMi Jinlong .op_name = "OP_RENAME", 32851c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 3286b591480bSJ.Bruce Fields }, 3287b591480bSJ.Bruce Fields [OP_RENEW] = { 3288eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 328958e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 329058e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3291b001a1b6SBenny Halevy .op_name = "OP_RENEW", 32921c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 329358e7b33aSMi Jinlong 3294b591480bSJ.Bruce Fields }, 3295b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 3296eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 329768d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 329858e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 3299b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 33001c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3301b591480bSJ.Bruce Fields }, 3302b591480bSJ.Bruce Fields [OP_SAVEFH] = { 3303eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 330458e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3305b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 33061c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3307b591480bSJ.Bruce Fields }, 3308dcb488a3SAndy Adamson [OP_SECINFO] = { 3309eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 331034b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 331168d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 3312b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 33131c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 3314dcb488a3SAndy Adamson }, 3315b591480bSJ.Bruce Fields [OP_SETATTR] = { 3316eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 3317b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 3318b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 3319b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 33201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 332157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 3322b591480bSJ.Bruce Fields }, 3323b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 3324eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 332558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3326b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 3327b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 3328b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 33291c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 3330b591480bSJ.Bruce Fields }, 3331b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 3332eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 333358e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3334c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 3335b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 33361c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3337b591480bSJ.Bruce Fields }, 3338b591480bSJ.Bruce Fields [OP_VERIFY] = { 3339eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 3340b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 33411c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3342b591480bSJ.Bruce Fields }, 3343b591480bSJ.Bruce Fields [OP_WRITE] = { 3344eb69853dSChristoph Hellwig .op_func = nfsd4_write, 3345c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3346b001a1b6SBenny Halevy .op_name = "OP_WRITE", 33471c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 334857832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 3349b591480bSJ.Bruce Fields }, 3350b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 3351eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 335258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 335358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3354b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 33551c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3356b591480bSJ.Bruce Fields }, 3357069b6ad4SAndy Adamson 3358069b6ad4SAndy Adamson /* NFSv4.1 operations */ 3359069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 3360eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 336158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 336258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3363069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 33641c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 3365069b6ad4SAndy Adamson }, 3366cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 3367eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 3368cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3369cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 33701c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3371cb73a9f4SJ. Bruce Fields }, 33721d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 3373eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 337458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 337558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 33761d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 33771c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 33781d1bc8f2SJ. Bruce Fields }, 3379069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 3380eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 338158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 338258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3383069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 33841c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 3385069b6ad4SAndy Adamson }, 3386069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 3387eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 338858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 338958e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3390069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 33911c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3392069b6ad4SAndy Adamson }, 3393069b6ad4SAndy Adamson [OP_SEQUENCE] = { 3394eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 3395f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 3396069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 33971c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 3398069b6ad4SAndy Adamson }, 3399094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 3400eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 340158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 340258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3403094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 34041c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3405094b5d74SBenny Halevy }, 34064dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 3407eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 340858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 34094dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 34101c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 34114dc6ec00SJ. Bruce Fields }, 341204f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 3413eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 3414ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 341568d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 341604f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 34171c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 341804f4ad16SJ. Bruce Fields }, 341917456804SBryan Schumaker [OP_TEST_STATEID] = { 3420eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 342117456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 342217456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 34231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 342417456804SBryan Schumaker }, 3425e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 3426eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 342758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3428e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 342957832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 34301c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3431e1ca12dfSBryan Schumaker }, 34329cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 34339cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 3434eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 343534b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 34369cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 34379cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 34381c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 34399cf514ccSChristoph Hellwig }, 34409cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 3441eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 344234b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 34439cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 34449cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 34451c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 34469cf514ccSChristoph Hellwig }, 34479cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 3448eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 34499cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 34509cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 34511c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 34529cf514ccSChristoph Hellwig }, 34539cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 3454eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 34559cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 34569cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 34571c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 34589cf514ccSChristoph Hellwig }, 34599cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 346024bab491SAnna Schumaker 346124bab491SAnna Schumaker /* NFSv4.2 operations */ 346295d871f0SAnna Schumaker [OP_ALLOCATE] = { 3463eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 346403b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 346595d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 34661c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 346795d871f0SAnna Schumaker }, 3468b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 3469eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 347003b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3471b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 34721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3473b0cb9085SAnna Schumaker }, 3474ffa0160aSChristoph Hellwig [OP_CLONE] = { 3475eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 347603b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3477ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 34781c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3479ffa0160aSChristoph Hellwig }, 348029ae7f9dSAnna Schumaker [OP_COPY] = { 3481eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 348203b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 348329ae7f9dSAnna Schumaker .op_name = "OP_COPY", 34841c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 348529ae7f9dSAnna Schumaker }, 3486528b8493SAnna Schumaker [OP_READ_PLUS] = { 3487528b8493SAnna Schumaker .op_func = nfsd4_read, 3488528b8493SAnna Schumaker .op_release = nfsd4_read_release, 3489528b8493SAnna Schumaker .op_name = "OP_READ_PLUS", 3490528b8493SAnna Schumaker .op_rsize_bop = nfsd4_read_plus_rsize, 3491528b8493SAnna Schumaker .op_get_currentstateid = nfsd4_get_readstateid, 3492528b8493SAnna Schumaker }, 349324bab491SAnna Schumaker [OP_SEEK] = { 3494eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 349524bab491SAnna Schumaker .op_name = "OP_SEEK", 34961c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 349724bab491SAnna Schumaker }, 34986308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 34996308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 35006308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 35016308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 35026308bc98SOlga Kornievskaia }, 3503885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 3504885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 3505885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3506885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 3507885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 3508885e2bf3SOlga Kornievskaia }, 350951911868SOlga Kornievskaia [OP_COPY_NOTIFY] = { 351051911868SOlga Kornievskaia .op_func = nfsd4_copy_notify, 351151911868SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 351251911868SOlga Kornievskaia .op_name = "OP_COPY_NOTIFY", 351351911868SOlga Kornievskaia .op_rsize_bop = nfsd4_copy_notify_rsize, 351451911868SOlga Kornievskaia }, 351523e50fe3SFrank van der Linden [OP_GETXATTR] = { 351623e50fe3SFrank van der Linden .op_func = nfsd4_getxattr, 351723e50fe3SFrank van der Linden .op_name = "OP_GETXATTR", 351823e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_getxattr_rsize, 351923e50fe3SFrank van der Linden }, 352023e50fe3SFrank van der Linden [OP_SETXATTR] = { 352123e50fe3SFrank van der Linden .op_func = nfsd4_setxattr, 352223e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 352323e50fe3SFrank van der Linden .op_name = "OP_SETXATTR", 352423e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_setxattr_rsize, 352523e50fe3SFrank van der Linden }, 352623e50fe3SFrank van der Linden [OP_LISTXATTRS] = { 352723e50fe3SFrank van der Linden .op_func = nfsd4_listxattrs, 352823e50fe3SFrank van der Linden .op_name = "OP_LISTXATTRS", 352923e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_listxattrs_rsize, 353023e50fe3SFrank van der Linden }, 353123e50fe3SFrank van der Linden [OP_REMOVEXATTR] = { 353223e50fe3SFrank van der Linden .op_func = nfsd4_removexattr, 353323e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 353423e50fe3SFrank van der Linden .op_name = "OP_REMOVEXATTR", 353523e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_removexattr_rsize, 353623e50fe3SFrank van der Linden }, 3537b591480bSJ.Bruce Fields }; 3538b591480bSJ.Bruce Fields 3539ed941643SAndrew Elble /** 3540ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 3541ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 3542ed941643SAndrew Elble * 3543ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 3544ed941643SAndrew Elble * 3545ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 3546ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 3547ed941643SAndrew Elble */ 3548ed941643SAndrew Elble 3549ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 3550ed941643SAndrew Elble { 3551ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 3552ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 3553e34c0ce9SColin Ian King struct nfsd4_op *this; 3554ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 3555ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 3556ed941643SAndrew Elble u32 opiter; 3557ed941643SAndrew Elble 3558ed941643SAndrew Elble if (!cstate->minorversion) 3559ed941643SAndrew Elble return false; 3560ed941643SAndrew Elble 356144b49aa6SZheng Bin if (cstate->spo_must_allowed) 3562ed941643SAndrew Elble return true; 3563ed941643SAndrew Elble 3564ed941643SAndrew Elble opiter = resp->opcnt; 3565ed941643SAndrew Elble while (opiter < argp->opcnt) { 3566ed941643SAndrew Elble this = &argp->ops[opiter++]; 3567ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 3568ed941643SAndrew Elble cstate->clp->cl_mach_cred && 3569ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 3570ed941643SAndrew Elble cstate->spo_must_allowed = true; 3571ed941643SAndrew Elble return true; 3572ed941643SAndrew Elble } 3573ed941643SAndrew Elble } 3574ed941643SAndrew Elble cstate->spo_must_allowed = false; 3575ed941643SAndrew Elble return false; 3576ed941643SAndrew Elble } 3577ed941643SAndrew Elble 35784f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 35794f0cefbfSJ. Bruce Fields { 358005b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 35814f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 35822282cd2cSKinglong Mee 35832282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 35842282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 35854f0cefbfSJ. Bruce Fields } 35864f0cefbfSJ. Bruce Fields 358707d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 358807d1f802SJ. Bruce Fields { 358907d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 35903a237b4aSChuck Lever pr_err("unable to encode reply to nonidempotent op %u (%s)\n", 359107d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 359207d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 359307d1f802SJ. Bruce Fields } 359407d1f802SJ. Bruce Fields } 359507d1f802SJ. Bruce Fields 3596f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 3597b001a1b6SBenny Halevy { 3598b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 3599b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 3600b001a1b6SBenny Halevy return "unknown_operation"; 3601b001a1b6SBenny Halevy } 3602b001a1b6SBenny Halevy 3603860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 36040a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 3605f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 3606788f7183SChuck Lever .pc_decode = nfssvc_decode_voidarg, 3607788f7183SChuck Lever .pc_encode = nfssvc_encode_voidres, 3608788f7183SChuck Lever .pc_argsize = sizeof(struct nfsd_voidargs), 3609788f7183SChuck Lever .pc_ressize = sizeof(struct nfsd_voidres), 36100a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 36110a93a47fSYu Zhiguo .pc_xdrressize = 1, 36122289e87bSChuck Lever .pc_name = "NULL", 36130a93a47fSYu Zhiguo }, 36140a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 3615f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 3616026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 361763f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 36180a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 36190a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 36203e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 36210a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 36220a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 36232289e87bSChuck Lever .pc_name = "COMPOUND", 36240a93a47fSYu Zhiguo }, 36251da177e4SLinus Torvalds }; 36261da177e4SLinus Torvalds 36277fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 3628e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 36291da177e4SLinus Torvalds .vs_vers = 4, 36301da177e4SLinus Torvalds .vs_nproc = 2, 36311da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 36327fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 36331da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 36341da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 363505a45a2dSJeff Layton .vs_rpcb_optnl = true, 36365283b03eSJeff Layton .vs_need_cong_ctrl = true, 36371da177e4SLinus Torvalds }; 3638