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); 633ca3f9acbSChuck Lever if (status && open->op_created) 634ca3f9acbSChuck 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 12888ea6e2c9SChuck Lever static void nfs4_put_copy(struct nfsd4_copy *copy) 1289e0639dc5SOlga Kornievskaia { 1290e0639dc5SOlga Kornievskaia if (!refcount_dec_and_test(©->refcount)) 1291e0639dc5SOlga Kornievskaia return; 129287689df6SChuck Lever kfree(copy->cp_src); 1293e0639dc5SOlga Kornievskaia kfree(copy); 1294e0639dc5SOlga Kornievskaia } 1295e0639dc5SOlga Kornievskaia 1296e0639dc5SOlga Kornievskaia static void nfsd4_stop_copy(struct nfsd4_copy *copy) 1297e0639dc5SOlga Kornievskaia { 12981913cdf5SChuck Lever if (!test_and_set_bit(NFSD4_COPY_F_STOPPED, ©->cp_flags)) 1299e0639dc5SOlga Kornievskaia kthread_stop(copy->copy_task); 1300e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1301e0639dc5SOlga Kornievskaia } 1302e0639dc5SOlga Kornievskaia 1303e0639dc5SOlga Kornievskaia static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) 1304e0639dc5SOlga Kornievskaia { 1305e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = NULL; 1306e0639dc5SOlga Kornievskaia 1307e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1308e0639dc5SOlga Kornievskaia if (!list_empty(&clp->async_copies)) { 1309e0639dc5SOlga Kornievskaia copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, 1310e0639dc5SOlga Kornievskaia copies); 1311e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1312e0639dc5SOlga Kornievskaia } 1313e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1314e0639dc5SOlga Kornievskaia return copy; 1315e0639dc5SOlga Kornievskaia } 1316e0639dc5SOlga Kornievskaia 1317e0639dc5SOlga Kornievskaia void nfsd4_shutdown_copy(struct nfs4_client *clp) 1318e0639dc5SOlga Kornievskaia { 1319e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1320e0639dc5SOlga Kornievskaia 1321e0639dc5SOlga Kornievskaia while ((copy = nfsd4_get_copy(clp)) != NULL) 1322e0639dc5SOlga Kornievskaia nfsd4_stop_copy(copy); 1323e0639dc5SOlga Kornievskaia } 1324ce0887acSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 1325ce0887acSOlga Kornievskaia 1326ce0887acSOlga Kornievskaia extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1327ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1328ce0887acSOlga Kornievskaia nfs4_stateid *stateid); 1329ce0887acSOlga Kornievskaia extern void nfs42_ssc_close(struct file *filep); 1330ce0887acSOlga Kornievskaia 1331ce0887acSOlga Kornievskaia extern void nfs_sb_deactive(struct super_block *sb); 1332ce0887acSOlga Kornievskaia 1333ce0887acSOlga Kornievskaia #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys" 1334ce0887acSOlga Kornievskaia 1335f2453978SChuck Lever /* 1336f4e44b39SDai Ngo * setup a work entry in the ssc delayed unmount list. 1337f4e44b39SDai Ngo */ 1338f47dc2d3SDai Ngo static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr, 1339f4e44b39SDai Ngo struct nfsd4_ssc_umount_item **retwork, struct vfsmount **ss_mnt) 1340f4e44b39SDai Ngo { 13418e70bf27SColin Ian King struct nfsd4_ssc_umount_item *ni = NULL; 1342f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work = NULL; 1343f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *tmp; 1344f4e44b39SDai Ngo DEFINE_WAIT(wait); 1345f4e44b39SDai Ngo 1346f4e44b39SDai Ngo *ss_mnt = NULL; 1347f4e44b39SDai Ngo *retwork = NULL; 1348f4e44b39SDai Ngo work = kzalloc(sizeof(*work), GFP_KERNEL); 1349f4e44b39SDai Ngo try_again: 1350f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1351f4e44b39SDai Ngo list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { 1352f4e44b39SDai Ngo if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr))) 1353f4e44b39SDai Ngo continue; 1354f4e44b39SDai Ngo /* found a match */ 1355f4e44b39SDai Ngo if (ni->nsui_busy) { 1356f4e44b39SDai Ngo /* wait - and try again */ 1357f4e44b39SDai Ngo prepare_to_wait(&nn->nfsd_ssc_waitq, &wait, 1358f4e44b39SDai Ngo TASK_INTERRUPTIBLE); 1359f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1360f4e44b39SDai Ngo 1361f4e44b39SDai Ngo /* allow 20secs for mount/unmount for now - revisit */ 1362f4e44b39SDai Ngo if (signal_pending(current) || 1363f4e44b39SDai Ngo (schedule_timeout(20*HZ) == 0)) { 1364f4e44b39SDai Ngo kfree(work); 1365f4e44b39SDai Ngo return nfserr_eagain; 1366f4e44b39SDai Ngo } 1367f4e44b39SDai Ngo finish_wait(&nn->nfsd_ssc_waitq, &wait); 1368f4e44b39SDai Ngo goto try_again; 1369f4e44b39SDai Ngo } 1370f4e44b39SDai Ngo *ss_mnt = ni->nsui_vfsmount; 1371f4e44b39SDai Ngo refcount_inc(&ni->nsui_refcnt); 1372f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1373f4e44b39SDai Ngo kfree(work); 1374f4e44b39SDai Ngo 1375f4e44b39SDai Ngo /* return vfsmount in ss_mnt */ 1376f4e44b39SDai Ngo return 0; 1377f4e44b39SDai Ngo } 1378f4e44b39SDai Ngo if (work) { 137953048779SChuck Lever strlcpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr) - 1); 1380f4e44b39SDai Ngo refcount_set(&work->nsui_refcnt, 2); 1381f4e44b39SDai Ngo work->nsui_busy = true; 1382f4e44b39SDai Ngo list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list); 1383f4e44b39SDai Ngo *retwork = work; 1384f4e44b39SDai Ngo } 1385f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1386f4e44b39SDai Ngo return 0; 1387f4e44b39SDai Ngo } 1388f4e44b39SDai Ngo 1389f4e44b39SDai Ngo static void nfsd4_ssc_update_dul_work(struct nfsd_net *nn, 1390f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work, struct vfsmount *ss_mnt) 1391f4e44b39SDai Ngo { 1392f4e44b39SDai Ngo /* set nsui_vfsmount, clear busy flag and wakeup waiters */ 1393f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1394f4e44b39SDai Ngo work->nsui_vfsmount = ss_mnt; 1395f4e44b39SDai Ngo work->nsui_busy = false; 1396f4e44b39SDai Ngo wake_up_all(&nn->nfsd_ssc_waitq); 1397f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1398f4e44b39SDai Ngo } 1399f4e44b39SDai Ngo 1400f4e44b39SDai Ngo static void nfsd4_ssc_cancel_dul_work(struct nfsd_net *nn, 1401f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work) 1402f4e44b39SDai Ngo { 1403f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1404f4e44b39SDai Ngo list_del(&work->nsui_list); 1405f4e44b39SDai Ngo wake_up_all(&nn->nfsd_ssc_waitq); 1406f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1407f4e44b39SDai Ngo kfree(work); 1408f4e44b39SDai Ngo } 1409f4e44b39SDai Ngo 1410f4e44b39SDai Ngo /* 1411ce0887acSOlga Kornievskaia * Support one copy source server for now. 1412ce0887acSOlga Kornievskaia */ 1413ce0887acSOlga Kornievskaia static __be32 1414ce0887acSOlga Kornievskaia nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp, 1415ce0887acSOlga Kornievskaia struct vfsmount **mount) 1416ce0887acSOlga Kornievskaia { 1417ce0887acSOlga Kornievskaia struct file_system_type *type; 1418ce0887acSOlga Kornievskaia struct vfsmount *ss_mnt; 1419ce0887acSOlga Kornievskaia struct nfs42_netaddr *naddr; 1420ce0887acSOlga Kornievskaia struct sockaddr_storage tmp_addr; 1421ce0887acSOlga Kornievskaia size_t tmp_addrlen, match_netid_len = 3; 1422ce0887acSOlga Kornievskaia char *startsep = "", *endsep = "", *match_netid = "tcp"; 1423ce0887acSOlga Kornievskaia char *ipaddr, *dev_name, *raw_data; 1424b8290ca2SOlga Kornievskaia int len, raw_len; 1425b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1426f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *work = NULL; 1427f4e44b39SDai Ngo struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1428ce0887acSOlga Kornievskaia 1429ce0887acSOlga Kornievskaia naddr = &nss->u.nl4_addr; 1430ce0887acSOlga Kornievskaia tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr, 1431ce0887acSOlga Kornievskaia naddr->addr_len, 1432ce0887acSOlga Kornievskaia (struct sockaddr *)&tmp_addr, 1433ce0887acSOlga Kornievskaia sizeof(tmp_addr)); 1434ce0887acSOlga Kornievskaia if (tmp_addrlen == 0) 1435ce0887acSOlga Kornievskaia goto out_err; 1436ce0887acSOlga Kornievskaia 1437ce0887acSOlga Kornievskaia if (tmp_addr.ss_family == AF_INET6) { 1438ce0887acSOlga Kornievskaia startsep = "["; 1439ce0887acSOlga Kornievskaia endsep = "]"; 1440ce0887acSOlga Kornievskaia match_netid = "tcp6"; 1441ce0887acSOlga Kornievskaia match_netid_len = 4; 1442ce0887acSOlga Kornievskaia } 1443ce0887acSOlga Kornievskaia 1444ce0887acSOlga Kornievskaia if (naddr->netid_len != match_netid_len || 1445ce0887acSOlga Kornievskaia strncmp(naddr->netid, match_netid, naddr->netid_len)) 1446ce0887acSOlga Kornievskaia goto out_err; 1447ce0887acSOlga Kornievskaia 1448ce0887acSOlga Kornievskaia /* Construct the raw data for the vfs_kern_mount call */ 1449ce0887acSOlga Kornievskaia len = RPC_MAX_ADDRBUFLEN + 1; 1450ce0887acSOlga Kornievskaia ipaddr = kzalloc(len, GFP_KERNEL); 1451ce0887acSOlga Kornievskaia if (!ipaddr) 1452ce0887acSOlga Kornievskaia goto out_err; 1453ce0887acSOlga Kornievskaia 1454ce0887acSOlga Kornievskaia rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len); 1455ce0887acSOlga Kornievskaia 1456ce0887acSOlga Kornievskaia /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/ 1457ce0887acSOlga Kornievskaia 1458ce0887acSOlga Kornievskaia raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr); 1459ce0887acSOlga Kornievskaia raw_data = kzalloc(raw_len, GFP_KERNEL); 1460ce0887acSOlga Kornievskaia if (!raw_data) 1461ce0887acSOlga Kornievskaia goto out_free_ipaddr; 1462ce0887acSOlga Kornievskaia 1463ce0887acSOlga Kornievskaia snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr); 1464ce0887acSOlga Kornievskaia 1465b8290ca2SOlga Kornievskaia status = nfserr_nodev; 1466ce0887acSOlga Kornievskaia type = get_fs_type("nfs"); 1467ce0887acSOlga Kornievskaia if (!type) 1468ce0887acSOlga Kornievskaia goto out_free_rawdata; 1469ce0887acSOlga Kornievskaia 1470ce0887acSOlga Kornievskaia /* Set the server:<export> for the vfs_kern_mount call */ 1471ce0887acSOlga Kornievskaia dev_name = kzalloc(len + 5, GFP_KERNEL); 1472ce0887acSOlga Kornievskaia if (!dev_name) 1473ce0887acSOlga Kornievskaia goto out_free_rawdata; 1474ce0887acSOlga Kornievskaia snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep); 1475ce0887acSOlga Kornievskaia 1476f4e44b39SDai Ngo status = nfsd4_ssc_setup_dul(nn, ipaddr, &work, &ss_mnt); 1477f4e44b39SDai Ngo if (status) 1478f4e44b39SDai Ngo goto out_free_devname; 1479f4e44b39SDai Ngo if (ss_mnt) 1480f4e44b39SDai Ngo goto out_done; 1481f4e44b39SDai Ngo 1482ce0887acSOlga Kornievskaia /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */ 1483ce0887acSOlga Kornievskaia ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data); 1484ce0887acSOlga Kornievskaia module_put(type->owner); 1485f4e44b39SDai Ngo if (IS_ERR(ss_mnt)) { 148654185267SWei Yongjun status = nfserr_nodev; 1487f4e44b39SDai Ngo if (work) 1488f4e44b39SDai Ngo nfsd4_ssc_cancel_dul_work(nn, work); 1489ce0887acSOlga Kornievskaia goto out_free_devname; 1490f4e44b39SDai Ngo } 1491f4e44b39SDai Ngo if (work) 1492f4e44b39SDai Ngo nfsd4_ssc_update_dul_work(nn, work, ss_mnt); 1493f4e44b39SDai Ngo out_done: 1494ce0887acSOlga Kornievskaia status = 0; 1495ce0887acSOlga Kornievskaia *mount = ss_mnt; 1496ce0887acSOlga Kornievskaia 1497ce0887acSOlga Kornievskaia out_free_devname: 1498ce0887acSOlga Kornievskaia kfree(dev_name); 1499ce0887acSOlga Kornievskaia out_free_rawdata: 1500ce0887acSOlga Kornievskaia kfree(raw_data); 1501ce0887acSOlga Kornievskaia out_free_ipaddr: 1502ce0887acSOlga Kornievskaia kfree(ipaddr); 1503ce0887acSOlga Kornievskaia out_err: 1504ce0887acSOlga Kornievskaia return status; 1505ce0887acSOlga Kornievskaia } 1506ce0887acSOlga Kornievskaia 1507ce0887acSOlga Kornievskaia static void 1508ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1509ce0887acSOlga Kornievskaia { 15100cfcd405SDai Ngo nfs_do_sb_deactive(ss_mnt->mnt_sb); 1511ce0887acSOlga Kornievskaia mntput(ss_mnt); 1512ce0887acSOlga Kornievskaia } 1513ce0887acSOlga Kornievskaia 1514f2453978SChuck Lever /* 1515ce0887acSOlga Kornievskaia * Verify COPY destination stateid. 1516f2453978SChuck Lever * 1517ce0887acSOlga Kornievskaia * Connect to the source server with NFSv4.1. 1518ce0887acSOlga Kornievskaia * Create the source struct file for nfsd_copy_range. 1519ce0887acSOlga Kornievskaia * Called with COPY cstate: 1520ce0887acSOlga Kornievskaia * SAVED_FH: source filehandle 1521ce0887acSOlga Kornievskaia * CURRENT_FH: destination filehandle 1522ce0887acSOlga Kornievskaia */ 1523ce0887acSOlga Kornievskaia static __be32 1524ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1525ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1526ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, struct vfsmount **mount) 1527ce0887acSOlga Kornievskaia { 1528ce0887acSOlga Kornievskaia struct svc_fh *s_fh = NULL; 1529ce0887acSOlga Kornievskaia stateid_t *s_stid = ©->cp_src_stateid; 1530b8290ca2SOlga Kornievskaia __be32 status = nfserr_inval; 1531ce0887acSOlga Kornievskaia 1532ce0887acSOlga Kornievskaia /* Verify the destination stateid and set dst struct file*/ 1533ce0887acSOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1534ce0887acSOlga Kornievskaia ©->cp_dst_stateid, 1535ce0887acSOlga Kornievskaia WR_STATE, ©->nf_dst, NULL); 1536ce0887acSOlga Kornievskaia if (status) 1537ce0887acSOlga Kornievskaia goto out; 1538ce0887acSOlga Kornievskaia 153987689df6SChuck Lever status = nfsd4_interssc_connect(copy->cp_src, rqstp, mount); 1540ce0887acSOlga Kornievskaia if (status) 1541ce0887acSOlga Kornievskaia goto out; 1542ce0887acSOlga Kornievskaia 1543ce0887acSOlga Kornievskaia s_fh = &cstate->save_fh; 1544ce0887acSOlga Kornievskaia 1545ce0887acSOlga Kornievskaia copy->c_fh.size = s_fh->fh_handle.fh_size; 1546d8b26071SNeilBrown memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size); 15473f9544caSOlga Kornievskaia copy->stateid.seqid = cpu_to_be32(s_stid->si_generation); 1548ce0887acSOlga Kornievskaia memcpy(copy->stateid.other, (void *)&s_stid->si_opaque, 1549ce0887acSOlga Kornievskaia sizeof(stateid_opaque_t)); 1550ce0887acSOlga Kornievskaia 1551ce0887acSOlga Kornievskaia status = 0; 1552ce0887acSOlga Kornievskaia out: 1553ce0887acSOlga Kornievskaia return status; 1554ce0887acSOlga Kornievskaia } 1555ce0887acSOlga Kornievskaia 1556ce0887acSOlga Kornievskaia static void 155724d796eaSChuck Lever nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp, 1558ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1559ce0887acSOlga Kornievskaia { 1560f4e44b39SDai Ngo bool found = false; 1561f4e44b39SDai Ngo long timeout; 1562f4e44b39SDai Ngo struct nfsd4_ssc_umount_item *tmp; 1563f47dc2d3SDai Ngo struct nfsd4_ssc_umount_item *ni = NULL; 1564f4e44b39SDai Ngo struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id); 1565f4e44b39SDai Ngo 156624d796eaSChuck Lever nfs42_ssc_close(filp); 1567ce0887acSOlga Kornievskaia nfsd_file_put(dst); 156824d796eaSChuck Lever fput(filp); 1569f4e44b39SDai Ngo 1570f4e44b39SDai Ngo if (!nn) { 1571ce0887acSOlga Kornievskaia mntput(ss_mnt); 1572f4e44b39SDai Ngo return; 1573f4e44b39SDai Ngo } 1574f4e44b39SDai Ngo spin_lock(&nn->nfsd_ssc_lock); 1575f4e44b39SDai Ngo timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout); 1576f4e44b39SDai Ngo list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { 1577f4e44b39SDai Ngo if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) { 1578f4e44b39SDai Ngo list_del(&ni->nsui_list); 1579f4e44b39SDai Ngo /* 1580f4e44b39SDai Ngo * vfsmount can be shared by multiple exports, 1581f4e44b39SDai Ngo * decrement refcnt. If the count drops to 1 it 1582f4e44b39SDai Ngo * will be unmounted when nsui_expire expires. 1583f4e44b39SDai Ngo */ 1584f4e44b39SDai Ngo refcount_dec(&ni->nsui_refcnt); 1585f4e44b39SDai Ngo ni->nsui_expire = jiffies + timeout; 1586f4e44b39SDai Ngo list_add_tail(&ni->nsui_list, &nn->nfsd_ssc_mount_list); 1587f4e44b39SDai Ngo found = true; 1588f4e44b39SDai Ngo break; 1589f4e44b39SDai Ngo } 1590f4e44b39SDai Ngo } 1591f4e44b39SDai Ngo spin_unlock(&nn->nfsd_ssc_lock); 1592f4e44b39SDai Ngo if (!found) { 1593f4e44b39SDai Ngo mntput(ss_mnt); 1594f4e44b39SDai Ngo return; 1595f4e44b39SDai Ngo } 1596ce0887acSOlga Kornievskaia } 1597ce0887acSOlga Kornievskaia 1598ce0887acSOlga Kornievskaia #else /* CONFIG_NFSD_V4_2_INTER_SSC */ 1599ce0887acSOlga Kornievskaia 1600ce0887acSOlga Kornievskaia static __be32 1601ce0887acSOlga Kornievskaia nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, 1602ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1603ce0887acSOlga Kornievskaia struct nfsd4_copy *copy, 1604ce0887acSOlga Kornievskaia struct vfsmount **mount) 1605ce0887acSOlga Kornievskaia { 1606ce0887acSOlga Kornievskaia *mount = NULL; 1607b8290ca2SOlga Kornievskaia return nfserr_inval; 1608ce0887acSOlga Kornievskaia } 1609ce0887acSOlga Kornievskaia 1610ce0887acSOlga Kornievskaia static void 161124d796eaSChuck Lever nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp, 1612ce0887acSOlga Kornievskaia struct nfsd_file *dst) 1613ce0887acSOlga Kornievskaia { 1614ce0887acSOlga Kornievskaia } 1615ce0887acSOlga Kornievskaia 1616ce0887acSOlga Kornievskaia static void 1617ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) 1618ce0887acSOlga Kornievskaia { 1619ce0887acSOlga Kornievskaia } 1620ce0887acSOlga Kornievskaia 1621ce0887acSOlga Kornievskaia static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, 1622ce0887acSOlga Kornievskaia struct nfs_fh *src_fh, 1623ce0887acSOlga Kornievskaia nfs4_stateid *stateid) 1624ce0887acSOlga Kornievskaia { 1625ce0887acSOlga Kornievskaia return NULL; 1626ce0887acSOlga Kornievskaia } 1627ce0887acSOlga Kornievskaia #endif /* CONFIG_NFSD_V4_2_INTER_SSC */ 1628ce0887acSOlga Kornievskaia 1629ce0887acSOlga Kornievskaia static __be32 1630ce0887acSOlga Kornievskaia nfsd4_setup_intra_ssc(struct svc_rqst *rqstp, 1631ce0887acSOlga Kornievskaia struct nfsd4_compound_state *cstate, 1632ce0887acSOlga Kornievskaia struct nfsd4_copy *copy) 1633ce0887acSOlga Kornievskaia { 1634ce0887acSOlga Kornievskaia return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, 1635ce0887acSOlga Kornievskaia ©->nf_src, ©->cp_dst_stateid, 1636ce0887acSOlga Kornievskaia ©->nf_dst); 1637ce0887acSOlga Kornievskaia } 1638ce0887acSOlga Kornievskaia 1639ce0887acSOlga Kornievskaia static void 1640ce0887acSOlga Kornievskaia nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst) 1641ce0887acSOlga Kornievskaia { 1642ce0887acSOlga Kornievskaia nfsd_file_put(src); 1643ce0887acSOlga Kornievskaia nfsd_file_put(dst); 1644ce0887acSOlga Kornievskaia } 1645e0639dc5SOlga Kornievskaia 1646e0639dc5SOlga Kornievskaia static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) 1647e0639dc5SOlga Kornievskaia { 1648*a11ada99SChuck Lever struct nfsd4_cb_offload *cbo = 1649*a11ada99SChuck Lever container_of(cb, struct nfsd4_cb_offload, co_cb); 1650e0639dc5SOlga Kornievskaia 1651*a11ada99SChuck Lever kfree(cbo); 1652e0639dc5SOlga Kornievskaia } 1653e0639dc5SOlga Kornievskaia 1654e0639dc5SOlga Kornievskaia static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, 1655e0639dc5SOlga Kornievskaia struct rpc_task *task) 1656e0639dc5SOlga Kornievskaia { 1657e0639dc5SOlga Kornievskaia return 1; 1658e0639dc5SOlga Kornievskaia } 1659e0639dc5SOlga Kornievskaia 1660e0639dc5SOlga Kornievskaia static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { 1661e0639dc5SOlga Kornievskaia .release = nfsd4_cb_offload_release, 1662e0639dc5SOlga Kornievskaia .done = nfsd4_cb_offload_done 1663e0639dc5SOlga Kornievskaia }; 1664e0639dc5SOlga Kornievskaia 1665e0639dc5SOlga Kornievskaia static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) 1666e0639dc5SOlga Kornievskaia { 1667eac0b17aSOlga Kornievskaia copy->cp_res.wr_stable_how = 16681913cdf5SChuck Lever test_bit(NFSD4_COPY_F_COMMITTED, ©->cp_flags) ? 16691913cdf5SChuck Lever NFS_FILE_SYNC : NFS_UNSTABLE; 16701913cdf5SChuck Lever nfsd4_copy_set_sync(copy, sync); 1671e0639dc5SOlga Kornievskaia gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); 1672e0639dc5SOlga Kornievskaia } 1673e0639dc5SOlga Kornievskaia 16743b7bf593SChuck Lever static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy, 16753b7bf593SChuck Lever struct file *dst, 16763b7bf593SChuck Lever struct file *src) 1677e0639dc5SOlga Kornievskaia { 1678555dbf1aSTrond Myklebust errseq_t since; 1679e0639dc5SOlga Kornievskaia ssize_t bytes_copied = 0; 1680e7a833e9SJ. Bruce Fields u64 bytes_total = copy->cp_count; 1681e0639dc5SOlga Kornievskaia u64 src_pos = copy->cp_src_pos; 1682e0639dc5SOlga Kornievskaia u64 dst_pos = copy->cp_dst_pos; 1683c2f1c4bdSChuck Lever int status; 1684e0639dc5SOlga Kornievskaia 1685792a5112SJ. Bruce Fields /* See RFC 7862 p.67: */ 1686792a5112SJ. Bruce Fields if (bytes_total == 0) 1687792a5112SJ. Bruce Fields bytes_total = ULLONG_MAX; 1688e0639dc5SOlga Kornievskaia do { 1689e0639dc5SOlga Kornievskaia if (kthread_should_stop()) 1690e0639dc5SOlga Kornievskaia break; 1691555dbf1aSTrond Myklebust bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos, 16925c4583b2SJeff Layton bytes_total); 1693e0639dc5SOlga Kornievskaia if (bytes_copied <= 0) 1694e0639dc5SOlga Kornievskaia break; 1695e0639dc5SOlga Kornievskaia bytes_total -= bytes_copied; 1696e0639dc5SOlga Kornievskaia copy->cp_res.wr_bytes_written += bytes_copied; 1697e0639dc5SOlga Kornievskaia src_pos += bytes_copied; 1698e0639dc5SOlga Kornievskaia dst_pos += bytes_copied; 16991913cdf5SChuck Lever } while (bytes_total > 0 && nfsd4_copy_is_async(copy)); 1700eac0b17aSOlga Kornievskaia /* for a non-zero asynchronous copy do a commit of data */ 17011913cdf5SChuck Lever if (nfsd4_copy_is_async(copy) && copy->cp_res.wr_bytes_written > 0) { 1702555dbf1aSTrond Myklebust since = READ_ONCE(dst->f_wb_err); 1703555dbf1aSTrond Myklebust status = vfs_fsync_range(dst, copy->cp_dst_pos, 1704eac0b17aSOlga Kornievskaia copy->cp_res.wr_bytes_written, 0); 1705555dbf1aSTrond Myklebust if (!status) 1706555dbf1aSTrond Myklebust status = filemap_check_wb_err(dst->f_mapping, since); 1707eac0b17aSOlga Kornievskaia if (!status) 17081913cdf5SChuck Lever set_bit(NFSD4_COPY_F_COMMITTED, ©->cp_flags); 1709eac0b17aSOlga Kornievskaia } 1710e0639dc5SOlga Kornievskaia return bytes_copied; 1711e0639dc5SOlga Kornievskaia } 1712e0639dc5SOlga Kornievskaia 17133b7bf593SChuck Lever static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, 17143b7bf593SChuck Lever struct file *src, struct file *dst, 17153b7bf593SChuck Lever bool sync) 1716e0639dc5SOlga Kornievskaia { 1717e0639dc5SOlga Kornievskaia __be32 status; 1718e0639dc5SOlga Kornievskaia ssize_t bytes; 1719e0639dc5SOlga Kornievskaia 17203b7bf593SChuck Lever bytes = _nfsd_copy_file_range(copy, dst, src); 17213b7bf593SChuck Lever 1722e0639dc5SOlga Kornievskaia /* for async copy, we ignore the error, client can always retry 1723e0639dc5SOlga Kornievskaia * to get the error 1724e0639dc5SOlga Kornievskaia */ 1725e0639dc5SOlga Kornievskaia if (bytes < 0 && !copy->cp_res.wr_bytes_written) 1726e0639dc5SOlga Kornievskaia status = nfserrno(bytes); 1727e0639dc5SOlga Kornievskaia else { 1728e0639dc5SOlga Kornievskaia nfsd4_init_copy_res(copy, sync); 1729e0639dc5SOlga Kornievskaia status = nfs_ok; 1730e0639dc5SOlga Kornievskaia } 1731e0639dc5SOlga Kornievskaia return status; 1732e0639dc5SOlga Kornievskaia } 1733e0639dc5SOlga Kornievskaia 1734eb162e17SChuck Lever static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) 1735e0639dc5SOlga Kornievskaia { 1736e0639dc5SOlga Kornievskaia dst->cp_src_pos = src->cp_src_pos; 1737e0639dc5SOlga Kornievskaia dst->cp_dst_pos = src->cp_dst_pos; 1738e0639dc5SOlga Kornievskaia dst->cp_count = src->cp_count; 17391913cdf5SChuck Lever dst->cp_flags = src->cp_flags; 1740e0639dc5SOlga Kornievskaia memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); 1741e0639dc5SOlga Kornievskaia memcpy(&dst->fh, &src->fh, sizeof(src->fh)); 1742e0639dc5SOlga Kornievskaia dst->cp_clp = src->cp_clp; 17435c4583b2SJeff Layton dst->nf_dst = nfsd_file_get(src->nf_dst); 17441913cdf5SChuck Lever /* for inter, nf_src doesn't exist yet */ 17451913cdf5SChuck Lever if (!nfsd4_ssc_is_inter(src)) 17465c4583b2SJeff Layton dst->nf_src = nfsd_file_get(src->nf_src); 1747ce0887acSOlga Kornievskaia 1748e0639dc5SOlga Kornievskaia memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); 174987689df6SChuck Lever memcpy(dst->cp_src, src->cp_src, sizeof(struct nl4_server)); 1750ce0887acSOlga Kornievskaia memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); 1751ce0887acSOlga Kornievskaia memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); 1752ce0887acSOlga Kornievskaia dst->ss_mnt = src->ss_mnt; 1753e0639dc5SOlga Kornievskaia } 1754e0639dc5SOlga Kornievskaia 1755e0639dc5SOlga Kornievskaia static void cleanup_async_copy(struct nfsd4_copy *copy) 1756e0639dc5SOlga Kornievskaia { 1757624322f1SOlga Kornievskaia nfs4_free_copy_state(copy); 17585c4583b2SJeff Layton nfsd_file_put(copy->nf_dst); 17591913cdf5SChuck Lever if (!nfsd4_ssc_is_inter(copy)) 17605c4583b2SJeff Layton nfsd_file_put(copy->nf_src); 1761e0639dc5SOlga Kornievskaia spin_lock(©->cp_clp->async_lock); 1762e0639dc5SOlga Kornievskaia list_del(©->copies); 1763e0639dc5SOlga Kornievskaia spin_unlock(©->cp_clp->async_lock); 1764e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 1765e0639dc5SOlga Kornievskaia } 1766e0639dc5SOlga Kornievskaia 1767*a11ada99SChuck Lever static void nfsd4_send_cb_offload(struct nfsd4_copy *copy, __be32 nfserr) 1768e72f9bc0SChuck Lever { 1769*a11ada99SChuck Lever struct nfsd4_cb_offload *cbo; 1770e72f9bc0SChuck Lever 1771*a11ada99SChuck Lever cbo = kzalloc(sizeof(*cbo), GFP_KERNEL); 1772*a11ada99SChuck Lever if (!cbo) 1773e72f9bc0SChuck Lever return; 1774e72f9bc0SChuck Lever 1775*a11ada99SChuck Lever memcpy(&cbo->co_res, ©->cp_res, sizeof(copy->cp_res)); 1776*a11ada99SChuck Lever memcpy(&cbo->co_fh, ©->fh, sizeof(copy->fh)); 1777*a11ada99SChuck Lever cbo->co_nfserr = nfserr; 1778e72f9bc0SChuck Lever 1779*a11ada99SChuck Lever nfsd4_init_cb(&cbo->co_cb, copy->cp_clp, &nfsd4_cb_offload_ops, 1780*a11ada99SChuck Lever NFSPROC4_CLNT_CB_OFFLOAD); 1781*a11ada99SChuck Lever trace_nfsd_cb_offload(copy->cp_clp, &cbo->co_res.cb_stateid, 1782*a11ada99SChuck Lever &cbo->co_fh, copy->cp_count, nfserr); 1783*a11ada99SChuck Lever nfsd4_run_cb(&cbo->co_cb); 1784e72f9bc0SChuck Lever } 1785e72f9bc0SChuck Lever 1786ad1e46c9SChuck Lever /** 1787ad1e46c9SChuck Lever * nfsd4_do_async_copy - kthread function for background server-side COPY 1788ad1e46c9SChuck Lever * @data: arguments for COPY operation 1789ad1e46c9SChuck Lever * 1790ad1e46c9SChuck Lever * Return values: 1791ad1e46c9SChuck Lever * %0: Copy operation is done. 1792ad1e46c9SChuck Lever */ 1793e0639dc5SOlga Kornievskaia static int nfsd4_do_async_copy(void *data) 1794e0639dc5SOlga Kornievskaia { 1795e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy = (struct nfsd4_copy *)data; 1796*a11ada99SChuck Lever __be32 nfserr; 1797e0639dc5SOlga Kornievskaia 17981913cdf5SChuck Lever if (nfsd4_ssc_is_inter(copy)) { 1799ad1e46c9SChuck Lever struct file *filp; 1800ad1e46c9SChuck Lever 1801ad1e46c9SChuck Lever filp = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, 1802ce0887acSOlga Kornievskaia ©->stateid); 1803ad1e46c9SChuck Lever if (IS_ERR(filp)) { 1804*a11ada99SChuck Lever nfserr = nfserr_offload_denied; 1805ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1806ce0887acSOlga Kornievskaia goto do_callback; 1807ce0887acSOlga Kornievskaia } 1808*a11ada99SChuck Lever nfserr = nfsd4_do_copy(copy, filp, copy->nf_dst->nf_file, 1809*a11ada99SChuck Lever false); 1810ad1e46c9SChuck Lever nfsd4_cleanup_inter_ssc(copy->ss_mnt, filp, copy->nf_dst); 1811478ed7b1SChuck Lever } else { 1812*a11ada99SChuck Lever nfserr = nfsd4_do_copy(copy, copy->nf_src->nf_file, 18133b7bf593SChuck Lever copy->nf_dst->nf_file, false); 1814478ed7b1SChuck Lever nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); 1815ce0887acSOlga Kornievskaia } 1816ce0887acSOlga Kornievskaia 1817ce0887acSOlga Kornievskaia do_callback: 1818*a11ada99SChuck Lever nfsd4_send_cb_offload(copy, nfserr); 1819e0639dc5SOlga Kornievskaia cleanup_async_copy(copy); 1820e0639dc5SOlga Kornievskaia return 0; 1821e0639dc5SOlga Kornievskaia } 1822e0639dc5SOlga Kornievskaia 1823ffa0160aSChristoph Hellwig static __be32 182429ae7f9dSAnna Schumaker nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1825eb69853dSChristoph Hellwig union nfsd4_op_u *u) 182629ae7f9dSAnna Schumaker { 1827eb69853dSChristoph Hellwig struct nfsd4_copy *copy = &u->copy; 182829ae7f9dSAnna Schumaker __be32 status; 1829e0639dc5SOlga Kornievskaia struct nfsd4_copy *async_copy = NULL; 183029ae7f9dSAnna Schumaker 18311913cdf5SChuck Lever if (nfsd4_ssc_is_inter(copy)) { 18321913cdf5SChuck Lever if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) { 1833ce0887acSOlga Kornievskaia status = nfserr_notsupp; 183429ae7f9dSAnna Schumaker goto out; 1835ce0887acSOlga Kornievskaia } 1836ce0887acSOlga Kornievskaia status = nfsd4_setup_inter_ssc(rqstp, cstate, copy, 1837ce0887acSOlga Kornievskaia ©->ss_mnt); 1838ce0887acSOlga Kornievskaia if (status) 1839ce0887acSOlga Kornievskaia return nfserr_offload_denied; 1840ce0887acSOlga Kornievskaia } else { 1841ce0887acSOlga Kornievskaia status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); 1842ce0887acSOlga Kornievskaia if (status) 1843ce0887acSOlga Kornievskaia return status; 1844ce0887acSOlga Kornievskaia } 184529ae7f9dSAnna Schumaker 1846e0639dc5SOlga Kornievskaia copy->cp_clp = cstate->clp; 1847e0639dc5SOlga Kornievskaia memcpy(©->fh, &cstate->current_fh.fh_handle, 1848e0639dc5SOlga Kornievskaia sizeof(struct knfsd_fh)); 18491913cdf5SChuck Lever if (nfsd4_copy_is_async(copy)) { 1850e0639dc5SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 185129ae7f9dSAnna Schumaker 1852e0639dc5SOlga Kornievskaia status = nfserrno(-ENOMEM); 1853e0639dc5SOlga Kornievskaia async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); 1854e0639dc5SOlga Kornievskaia if (!async_copy) 1855ce0887acSOlga Kornievskaia goto out_err; 185687689df6SChuck Lever async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL); 185787689df6SChuck Lever if (!async_copy->cp_src) 185887689df6SChuck Lever goto out_err; 1859ce0887acSOlga Kornievskaia if (!nfs4_init_copy_state(nn, copy)) 1860ce0887acSOlga Kornievskaia goto out_err; 1861e0639dc5SOlga Kornievskaia refcount_set(&async_copy->refcount, 1); 1862e739b120SOlga Kornievskaia memcpy(©->cp_res.cb_stateid, ©->cp_stateid.stid, 1863e739b120SOlga Kornievskaia sizeof(copy->cp_res.cb_stateid)); 1864eb162e17SChuck Lever dup_copy_fields(copy, async_copy); 1865e0639dc5SOlga Kornievskaia async_copy->copy_task = kthread_create(nfsd4_do_async_copy, 1866e0639dc5SOlga Kornievskaia async_copy, "%s", "copy thread"); 1867e0639dc5SOlga Kornievskaia if (IS_ERR(async_copy->copy_task)) 1868e0639dc5SOlga Kornievskaia goto out_err; 1869e0639dc5SOlga Kornievskaia spin_lock(&async_copy->cp_clp->async_lock); 1870e0639dc5SOlga Kornievskaia list_add(&async_copy->copies, 1871e0639dc5SOlga Kornievskaia &async_copy->cp_clp->async_copies); 1872e0639dc5SOlga Kornievskaia spin_unlock(&async_copy->cp_clp->async_lock); 1873e0639dc5SOlga Kornievskaia wake_up_process(async_copy->copy_task); 1874e0639dc5SOlga Kornievskaia status = nfs_ok; 1875ce0887acSOlga Kornievskaia } else { 18763b7bf593SChuck Lever status = nfsd4_do_copy(copy, copy->nf_src->nf_file, 18773b7bf593SChuck Lever copy->nf_dst->nf_file, true); 1878478ed7b1SChuck Lever nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); 1879ce0887acSOlga Kornievskaia } 188029ae7f9dSAnna Schumaker out: 188129ae7f9dSAnna Schumaker return status; 1882e0639dc5SOlga Kornievskaia out_err: 188318f428d4SOlga Kornievskaia if (async_copy) 1884e0639dc5SOlga Kornievskaia cleanup_async_copy(async_copy); 1885ce0887acSOlga Kornievskaia status = nfserrno(-ENOMEM); 18861913cdf5SChuck Lever if (nfsd4_ssc_is_inter(copy)) 1887ce0887acSOlga Kornievskaia nfsd4_interssc_disconnect(copy->ss_mnt); 1888e0639dc5SOlga Kornievskaia goto out; 1889e0639dc5SOlga Kornievskaia } 1890e0639dc5SOlga Kornievskaia 1891e0639dc5SOlga Kornievskaia struct nfsd4_copy * 1892e0639dc5SOlga Kornievskaia find_async_copy(struct nfs4_client *clp, stateid_t *stateid) 1893e0639dc5SOlga Kornievskaia { 1894e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1895e0639dc5SOlga Kornievskaia 1896e0639dc5SOlga Kornievskaia spin_lock(&clp->async_lock); 1897e0639dc5SOlga Kornievskaia list_for_each_entry(copy, &clp->async_copies, copies) { 1898ce0887acSOlga Kornievskaia if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE)) 1899e0639dc5SOlga Kornievskaia continue; 1900e0639dc5SOlga Kornievskaia refcount_inc(©->refcount); 1901e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1902e0639dc5SOlga Kornievskaia return copy; 1903e0639dc5SOlga Kornievskaia } 1904e0639dc5SOlga Kornievskaia spin_unlock(&clp->async_lock); 1905e0639dc5SOlga Kornievskaia return NULL; 190629ae7f9dSAnna Schumaker } 190729ae7f9dSAnna Schumaker 190829ae7f9dSAnna Schumaker static __be32 1909885e2bf3SOlga Kornievskaia nfsd4_offload_cancel(struct svc_rqst *rqstp, 1910885e2bf3SOlga Kornievskaia struct nfsd4_compound_state *cstate, 1911885e2bf3SOlga Kornievskaia union nfsd4_op_u *u) 1912885e2bf3SOlga Kornievskaia { 1913e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 1914e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 1915e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1916e0639dc5SOlga Kornievskaia 1917e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 1918ce0887acSOlga Kornievskaia if (!copy) { 1919ce0887acSOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1920e0639dc5SOlga Kornievskaia 1921ce0887acSOlga Kornievskaia return manage_cpntf_state(nn, &os->stateid, clp, NULL); 1922ce0887acSOlga Kornievskaia } else 1923ce0887acSOlga Kornievskaia nfsd4_stop_copy(copy); 1924ce0887acSOlga Kornievskaia 1925ce0887acSOlga Kornievskaia return nfs_ok; 1926885e2bf3SOlga Kornievskaia } 1927885e2bf3SOlga Kornievskaia 1928885e2bf3SOlga Kornievskaia static __be32 192951911868SOlga Kornievskaia nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 193051911868SOlga Kornievskaia union nfsd4_op_u *u) 193151911868SOlga Kornievskaia { 1932624322f1SOlga Kornievskaia struct nfsd4_copy_notify *cn = &u->copy_notify; 1933624322f1SOlga Kornievskaia __be32 status; 1934624322f1SOlga Kornievskaia struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 1935624322f1SOlga Kornievskaia struct nfs4_stid *stid; 1936624322f1SOlga Kornievskaia struct nfs4_cpntf_state *cps; 1937624322f1SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 1938624322f1SOlga Kornievskaia 1939624322f1SOlga Kornievskaia status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 1940624322f1SOlga Kornievskaia &cn->cpn_src_stateid, RD_STATE, NULL, 1941624322f1SOlga Kornievskaia &stid); 1942624322f1SOlga Kornievskaia if (status) 1943624322f1SOlga Kornievskaia return status; 1944624322f1SOlga Kornievskaia 1945624322f1SOlga Kornievskaia cn->cpn_sec = nn->nfsd4_lease; 1946624322f1SOlga Kornievskaia cn->cpn_nsec = 0; 1947624322f1SOlga Kornievskaia 1948624322f1SOlga Kornievskaia status = nfserrno(-ENOMEM); 1949624322f1SOlga Kornievskaia cps = nfs4_alloc_init_cpntf_state(nn, stid); 1950624322f1SOlga Kornievskaia if (!cps) 1951624322f1SOlga Kornievskaia goto out; 1952624322f1SOlga Kornievskaia memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t)); 1953624322f1SOlga Kornievskaia memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t)); 1954624322f1SOlga Kornievskaia memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t)); 1955624322f1SOlga Kornievskaia 1956624322f1SOlga Kornievskaia /* For now, only return one server address in cpn_src, the 1957624322f1SOlga Kornievskaia * address used by the client to connect to this server. 1958624322f1SOlga Kornievskaia */ 195909426ef2SChuck Lever cn->cpn_src->nl4_type = NL4_NETADDR; 1960624322f1SOlga Kornievskaia status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, 196109426ef2SChuck Lever &cn->cpn_src->u.nl4_addr); 1962624322f1SOlga Kornievskaia WARN_ON_ONCE(status); 1963624322f1SOlga Kornievskaia if (status) { 1964624322f1SOlga Kornievskaia nfs4_put_cpntf_state(nn, cps); 1965624322f1SOlga Kornievskaia goto out; 1966624322f1SOlga Kornievskaia } 1967624322f1SOlga Kornievskaia out: 1968624322f1SOlga Kornievskaia nfs4_put_stid(stid); 1969624322f1SOlga Kornievskaia return status; 197051911868SOlga Kornievskaia } 197151911868SOlga Kornievskaia 197251911868SOlga Kornievskaia static __be32 197395d871f0SAnna Schumaker nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 197495d871f0SAnna Schumaker struct nfsd4_fallocate *fallocate, int flags) 197595d871f0SAnna Schumaker { 19760d4d6720SJ. Bruce Fields __be32 status; 19775c4583b2SJeff Layton struct nfsd_file *nf; 197895d871f0SAnna Schumaker 1979aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 198095d871f0SAnna Schumaker &fallocate->falloc_stateid, 1981624322f1SOlga Kornievskaia WR_STATE, &nf, NULL); 198295d871f0SAnna Schumaker if (status != nfs_ok) { 198395d871f0SAnna Schumaker dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 198495d871f0SAnna Schumaker return status; 198595d871f0SAnna Schumaker } 198695d871f0SAnna Schumaker 19875c4583b2SJeff Layton status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, 198895d871f0SAnna Schumaker fallocate->falloc_offset, 198995d871f0SAnna Schumaker fallocate->falloc_length, 199095d871f0SAnna Schumaker flags); 19915c4583b2SJeff Layton nfsd_file_put(nf); 199295d871f0SAnna Schumaker return status; 199395d871f0SAnna Schumaker } 19946308bc98SOlga Kornievskaia static __be32 19956308bc98SOlga Kornievskaia nfsd4_offload_status(struct svc_rqst *rqstp, 19966308bc98SOlga Kornievskaia struct nfsd4_compound_state *cstate, 19976308bc98SOlga Kornievskaia union nfsd4_op_u *u) 19986308bc98SOlga Kornievskaia { 1999e0639dc5SOlga Kornievskaia struct nfsd4_offload_status *os = &u->offload_status; 2000e0639dc5SOlga Kornievskaia __be32 status = 0; 2001e0639dc5SOlga Kornievskaia struct nfsd4_copy *copy; 2002e0639dc5SOlga Kornievskaia struct nfs4_client *clp = cstate->clp; 2003e0639dc5SOlga Kornievskaia 2004e0639dc5SOlga Kornievskaia copy = find_async_copy(clp, &os->stateid); 2005e0639dc5SOlga Kornievskaia if (copy) { 2006e0639dc5SOlga Kornievskaia os->count = copy->cp_res.wr_bytes_written; 2007e0639dc5SOlga Kornievskaia nfs4_put_copy(copy); 2008e0639dc5SOlga Kornievskaia } else 2009e0639dc5SOlga Kornievskaia status = nfserr_bad_stateid; 2010e0639dc5SOlga Kornievskaia 2011e0639dc5SOlga Kornievskaia return status; 20126308bc98SOlga Kornievskaia } 201395d871f0SAnna Schumaker 201495d871f0SAnna Schumaker static __be32 201595d871f0SAnna Schumaker nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2016eb69853dSChristoph Hellwig union nfsd4_op_u *u) 201795d871f0SAnna Schumaker { 2018eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); 201995d871f0SAnna Schumaker } 202095d871f0SAnna Schumaker 202195d871f0SAnna Schumaker static __be32 2022b0cb9085SAnna Schumaker nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2023eb69853dSChristoph Hellwig union nfsd4_op_u *u) 2024b0cb9085SAnna Schumaker { 2025eb69853dSChristoph Hellwig return nfsd4_fallocate(rqstp, cstate, &u->deallocate, 2026b0cb9085SAnna Schumaker FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); 2027b0cb9085SAnna Schumaker } 2028b0cb9085SAnna Schumaker 2029b0cb9085SAnna Schumaker static __be32 203024bab491SAnna Schumaker nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2031eb69853dSChristoph Hellwig union nfsd4_op_u *u) 203224bab491SAnna Schumaker { 2033eb69853dSChristoph Hellwig struct nfsd4_seek *seek = &u->seek; 203424bab491SAnna Schumaker int whence; 203524bab491SAnna Schumaker __be32 status; 20365c4583b2SJeff Layton struct nfsd_file *nf; 203724bab491SAnna Schumaker 2038aa0d6aedSAnna Schumaker status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, 203924bab491SAnna Schumaker &seek->seek_stateid, 2040624322f1SOlga Kornievskaia RD_STATE, &nf, NULL); 204124bab491SAnna Schumaker if (status) { 204224bab491SAnna Schumaker dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 204324bab491SAnna Schumaker return status; 204424bab491SAnna Schumaker } 204524bab491SAnna Schumaker 204624bab491SAnna Schumaker switch (seek->seek_whence) { 204724bab491SAnna Schumaker case NFS4_CONTENT_DATA: 204824bab491SAnna Schumaker whence = SEEK_DATA; 204924bab491SAnna Schumaker break; 205024bab491SAnna Schumaker case NFS4_CONTENT_HOLE: 205124bab491SAnna Schumaker whence = SEEK_HOLE; 205224bab491SAnna Schumaker break; 205324bab491SAnna Schumaker default: 205424bab491SAnna Schumaker status = nfserr_union_notsupp; 205524bab491SAnna Schumaker goto out; 205624bab491SAnna Schumaker } 205724bab491SAnna Schumaker 205824bab491SAnna Schumaker /* 205924bab491SAnna Schumaker * Note: This call does change file->f_pos, but nothing in NFSD 206024bab491SAnna Schumaker * should ever file->f_pos. 206124bab491SAnna Schumaker */ 20625c4583b2SJeff Layton seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); 206324bab491SAnna Schumaker if (seek->seek_pos < 0) 206424bab491SAnna Schumaker status = nfserrno(seek->seek_pos); 20655c4583b2SJeff Layton else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) 206624bab491SAnna Schumaker seek->seek_eof = true; 206724bab491SAnna Schumaker 206824bab491SAnna Schumaker out: 20695c4583b2SJeff Layton nfsd_file_put(nf); 207024bab491SAnna Schumaker return status; 207124bab491SAnna Schumaker } 207224bab491SAnna Schumaker 20731da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 20741da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 20751da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 20761da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 20771da177e4SLinus Torvalds */ 2078b37ad28bSAl Viro static __be32 2079c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2080ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 20811da177e4SLinus Torvalds { 20822ebbc012SAl Viro __be32 *buf, *p; 20831da177e4SLinus Torvalds int count; 2084b37ad28bSAl Viro __be32 status; 20851da177e4SLinus Torvalds 20868837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 20871da177e4SLinus Torvalds if (status) 20881da177e4SLinus Torvalds return status; 20891da177e4SLinus Torvalds 20903c8e0316SYu Zhiguo status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); 20913c8e0316SYu Zhiguo if (status) 20923c8e0316SYu Zhiguo return status; 20933c8e0316SYu Zhiguo 20941da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 20951da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 20961da177e4SLinus Torvalds return nfserr_inval; 20971da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 20981da177e4SLinus Torvalds return nfserr_inval; 20991da177e4SLinus Torvalds 21001da177e4SLinus Torvalds /* count in words: 21011da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 21021da177e4SLinus Torvalds */ 21031da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 21041da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 21051da177e4SLinus Torvalds if (!buf) 21063e772463SJ. Bruce Fields return nfserr_jukebox; 21071da177e4SLinus Torvalds 210884822d0bSJ. Bruce Fields p = buf; 2109d5184658SJ. Bruce Fields status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, 2110ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 2111d5184658SJ. Bruce Fields cstate->current_fh.fh_dentry, 2112d5184658SJ. Bruce Fields verify->ve_bmval, 2113406a7ea9SFrank Filz rqstp, 0); 211441ae6e71SJ. Bruce Fields /* 211541ae6e71SJ. Bruce Fields * If nfsd4_encode_fattr() ran out of space, assume that's because 211641ae6e71SJ. Bruce Fields * the attributes are longer (hence different) than those given: 211741ae6e71SJ. Bruce Fields */ 211884822d0bSJ. Bruce Fields if (status == nfserr_resource) 21191da177e4SLinus Torvalds status = nfserr_not_same; 21201da177e4SLinus Torvalds if (status) 21211da177e4SLinus Torvalds goto out_kfree; 21221da177e4SLinus Torvalds 212395ec28cdSBenny Halevy /* skip bitmap */ 212495ec28cdSBenny Halevy p = buf + 1 + ntohl(buf[0]); 21251da177e4SLinus Torvalds status = nfserr_not_same; 21261da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 21271da177e4SLinus Torvalds goto out_kfree; 21281da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 21291da177e4SLinus Torvalds status = nfserr_same; 21301da177e4SLinus Torvalds 21311da177e4SLinus Torvalds out_kfree: 21321da177e4SLinus Torvalds kfree(buf); 21331da177e4SLinus Torvalds return status; 21341da177e4SLinus Torvalds } 21351da177e4SLinus Torvalds 2136c954e2a5SJ.Bruce Fields static __be32 2137c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2138eb69853dSChristoph Hellwig union nfsd4_op_u *u) 2139c954e2a5SJ.Bruce Fields { 2140c954e2a5SJ.Bruce Fields __be32 status; 2141c954e2a5SJ.Bruce Fields 2142eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->verify); 2143c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 2144c954e2a5SJ.Bruce Fields } 2145c954e2a5SJ.Bruce Fields 2146c954e2a5SJ.Bruce Fields static __be32 2147c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 2148eb69853dSChristoph Hellwig union nfsd4_op_u *u) 2149c954e2a5SJ.Bruce Fields { 2150c954e2a5SJ.Bruce Fields __be32 status; 2151c954e2a5SJ.Bruce Fields 2152eb69853dSChristoph Hellwig status = _nfsd4_verify(rqstp, cstate, &u->nverify); 2153c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 2154c954e2a5SJ.Bruce Fields } 2155c954e2a5SJ.Bruce Fields 21569cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 21579cf514ccSChristoph Hellwig static const struct nfsd4_layout_ops * 21589cf514ccSChristoph Hellwig nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) 21599cf514ccSChristoph Hellwig { 21608a4c3926SJeff Layton if (!exp->ex_layout_types) { 21619cf514ccSChristoph Hellwig dprintk("%s: export does not support pNFS\n", __func__); 21629cf514ccSChristoph Hellwig return NULL; 21639cf514ccSChristoph Hellwig } 21649cf514ccSChristoph Hellwig 2165b550a32eSAri Kauppi if (layout_type >= LAYOUT_TYPE_MAX || 2166b550a32eSAri Kauppi !(exp->ex_layout_types & (1 << layout_type))) { 21679cf514ccSChristoph Hellwig dprintk("%s: layout type %d not supported\n", 21689cf514ccSChristoph Hellwig __func__, layout_type); 21699cf514ccSChristoph Hellwig return NULL; 21709cf514ccSChristoph Hellwig } 21719cf514ccSChristoph Hellwig 21729cf514ccSChristoph Hellwig return nfsd4_layout_ops[layout_type]; 21739cf514ccSChristoph Hellwig } 21749cf514ccSChristoph Hellwig 21759cf514ccSChristoph Hellwig static __be32 21769cf514ccSChristoph Hellwig nfsd4_getdeviceinfo(struct svc_rqst *rqstp, 2177eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 21789cf514ccSChristoph Hellwig { 2179eb69853dSChristoph Hellwig struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; 21809cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 21819cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *map; 21829cf514ccSChristoph Hellwig struct svc_export *exp; 21839cf514ccSChristoph Hellwig __be32 nfserr; 21849cf514ccSChristoph Hellwig 21859cf514ccSChristoph Hellwig dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", 21869cf514ccSChristoph Hellwig __func__, 21879cf514ccSChristoph Hellwig gdp->gd_layout_type, 21889cf514ccSChristoph Hellwig gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, 21899cf514ccSChristoph Hellwig gdp->gd_maxcount); 21909cf514ccSChristoph Hellwig 21919cf514ccSChristoph Hellwig map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); 21929cf514ccSChristoph Hellwig if (!map) { 21939cf514ccSChristoph Hellwig dprintk("%s: couldn't find device ID to export mapping!\n", 21949cf514ccSChristoph Hellwig __func__); 21959cf514ccSChristoph Hellwig return nfserr_noent; 21969cf514ccSChristoph Hellwig } 21979cf514ccSChristoph Hellwig 21989cf514ccSChristoph Hellwig exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); 21999cf514ccSChristoph Hellwig if (IS_ERR(exp)) { 22009cf514ccSChristoph Hellwig dprintk("%s: could not find device id\n", __func__); 22019cf514ccSChristoph Hellwig return nfserr_noent; 22029cf514ccSChristoph Hellwig } 22039cf514ccSChristoph Hellwig 22049cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 22059cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); 22069cf514ccSChristoph Hellwig if (!ops) 22079cf514ccSChristoph Hellwig goto out; 22089cf514ccSChristoph Hellwig 22099cf514ccSChristoph Hellwig nfserr = nfs_ok; 2210f99d4fbdSChristoph Hellwig if (gdp->gd_maxcount != 0) { 2211f99d4fbdSChristoph Hellwig nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, 2212ec59659bSJ. Bruce Fields rqstp, cstate->clp, gdp); 2213f99d4fbdSChristoph Hellwig } 22149cf514ccSChristoph Hellwig 22159cf514ccSChristoph Hellwig gdp->gd_notify_types &= ops->notify_types; 22169cf514ccSChristoph Hellwig out: 2217a1420384SKinglong Mee exp_put(exp); 22189cf514ccSChristoph Hellwig return nfserr; 22199cf514ccSChristoph Hellwig } 22209cf514ccSChristoph Hellwig 222134b1744cSJ. Bruce Fields static void 222234b1744cSJ. Bruce Fields nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) 222334b1744cSJ. Bruce Fields { 222434b1744cSJ. Bruce Fields kfree(u->getdeviceinfo.gd_device); 222534b1744cSJ. Bruce Fields } 222634b1744cSJ. Bruce Fields 22279cf514ccSChristoph Hellwig static __be32 22289cf514ccSChristoph Hellwig nfsd4_layoutget(struct svc_rqst *rqstp, 2229eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 22309cf514ccSChristoph Hellwig { 2231eb69853dSChristoph Hellwig struct nfsd4_layoutget *lgp = &u->layoutget; 22329cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 22339cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 22349cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 22359cf514ccSChristoph Hellwig __be32 nfserr; 223666282ec1SBenjamin Coddington int accmode = NFSD_MAY_READ_IF_EXEC; 22379cf514ccSChristoph Hellwig 22389cf514ccSChristoph Hellwig switch (lgp->lg_seg.iomode) { 22399cf514ccSChristoph Hellwig case IOMODE_READ: 224066282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ; 22419cf514ccSChristoph Hellwig break; 22429cf514ccSChristoph Hellwig case IOMODE_RW: 224366282ec1SBenjamin Coddington accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; 22449cf514ccSChristoph Hellwig break; 22459cf514ccSChristoph Hellwig default: 22469cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", 22479cf514ccSChristoph Hellwig __func__, lgp->lg_seg.iomode); 22489cf514ccSChristoph Hellwig nfserr = nfserr_badiomode; 22499cf514ccSChristoph Hellwig goto out; 22509cf514ccSChristoph Hellwig } 22519cf514ccSChristoph Hellwig 22529cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, accmode); 22539cf514ccSChristoph Hellwig if (nfserr) 22549cf514ccSChristoph Hellwig goto out; 22559cf514ccSChristoph Hellwig 22569cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 22579cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); 22589cf514ccSChristoph Hellwig if (!ops) 22599cf514ccSChristoph Hellwig goto out; 22609cf514ccSChristoph Hellwig 22619cf514ccSChristoph Hellwig /* 22629cf514ccSChristoph Hellwig * Verify minlength and range as per RFC5661: 22639cf514ccSChristoph Hellwig * o If loga_length is less than loga_minlength, 22649cf514ccSChristoph Hellwig * the metadata server MUST return NFS4ERR_INVAL. 22659cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_minlength exceeds 22669cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_minlength is not 22679cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. 22689cf514ccSChristoph Hellwig * o If the sum of loga_offset and loga_length exceeds 22699cf514ccSChristoph Hellwig * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, 22709cf514ccSChristoph Hellwig * the error NFS4ERR_INVAL MUST result. 22719cf514ccSChristoph Hellwig */ 22729cf514ccSChristoph Hellwig nfserr = nfserr_inval; 22739cf514ccSChristoph Hellwig if (lgp->lg_seg.length < lgp->lg_minlength || 22749cf514ccSChristoph Hellwig (lgp->lg_minlength != NFS4_MAX_UINT64 && 22759cf514ccSChristoph Hellwig lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || 22769cf514ccSChristoph Hellwig (lgp->lg_seg.length != NFS4_MAX_UINT64 && 22779cf514ccSChristoph Hellwig lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) 22789cf514ccSChristoph Hellwig goto out; 22799cf514ccSChristoph Hellwig if (lgp->lg_seg.length == 0) 22809cf514ccSChristoph Hellwig goto out; 22819cf514ccSChristoph Hellwig 22829cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, 22839cf514ccSChristoph Hellwig true, lgp->lg_layout_type, &ls); 228431ef83dcSChristoph Hellwig if (nfserr) { 2285f394b62bSChuck Lever trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); 22869cf514ccSChristoph Hellwig goto out; 228731ef83dcSChristoph Hellwig } 22889cf514ccSChristoph Hellwig 2289c5c707f9SChristoph Hellwig nfserr = nfserr_recallconflict; 2290c5c707f9SChristoph Hellwig if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 2291c5c707f9SChristoph Hellwig goto out_put_stid; 2292c5c707f9SChristoph Hellwig 22932b0143b5SDavid Howells nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), 22949cf514ccSChristoph Hellwig current_fh, lgp); 22959cf514ccSChristoph Hellwig if (nfserr) 22969cf514ccSChristoph Hellwig goto out_put_stid; 22979cf514ccSChristoph Hellwig 22989cf514ccSChristoph Hellwig nfserr = nfsd4_insert_layout(lgp, ls); 22999cf514ccSChristoph Hellwig 23009cf514ccSChristoph Hellwig out_put_stid: 2301cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 23029cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 23039cf514ccSChristoph Hellwig out: 23049cf514ccSChristoph Hellwig return nfserr; 23059cf514ccSChristoph Hellwig } 23069cf514ccSChristoph Hellwig 230734b1744cSJ. Bruce Fields static void 230834b1744cSJ. Bruce Fields nfsd4_layoutget_release(union nfsd4_op_u *u) 230934b1744cSJ. Bruce Fields { 231034b1744cSJ. Bruce Fields kfree(u->layoutget.lg_content); 231134b1744cSJ. Bruce Fields } 231234b1744cSJ. Bruce Fields 23139cf514ccSChristoph Hellwig static __be32 23149cf514ccSChristoph Hellwig nfsd4_layoutcommit(struct svc_rqst *rqstp, 2315eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 23169cf514ccSChristoph Hellwig { 2317eb69853dSChristoph Hellwig struct nfsd4_layoutcommit *lcp = &u->layoutcommit; 23189cf514ccSChristoph Hellwig const struct nfsd4_layout_seg *seg = &lcp->lc_seg; 23199cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 23209cf514ccSChristoph Hellwig const struct nfsd4_layout_ops *ops; 23219cf514ccSChristoph Hellwig loff_t new_size = lcp->lc_last_wr + 1; 23229cf514ccSChristoph Hellwig struct inode *inode; 23239cf514ccSChristoph Hellwig struct nfs4_layout_stateid *ls; 23249cf514ccSChristoph Hellwig __be32 nfserr; 23259cf514ccSChristoph Hellwig 23269cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); 23279cf514ccSChristoph Hellwig if (nfserr) 23289cf514ccSChristoph Hellwig goto out; 23299cf514ccSChristoph Hellwig 23309cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 23319cf514ccSChristoph Hellwig ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 23329cf514ccSChristoph Hellwig if (!ops) 23339cf514ccSChristoph Hellwig goto out; 23342b0143b5SDavid Howells inode = d_inode(current_fh->fh_dentry); 23359cf514ccSChristoph Hellwig 23369cf514ccSChristoph Hellwig nfserr = nfserr_inval; 23379cf514ccSChristoph Hellwig if (new_size <= seg->offset) { 23389cf514ccSChristoph Hellwig dprintk("pnfsd: last write before layout segment\n"); 23399cf514ccSChristoph Hellwig goto out; 23409cf514ccSChristoph Hellwig } 23419cf514ccSChristoph Hellwig if (new_size > seg->offset + seg->length) { 23429cf514ccSChristoph Hellwig dprintk("pnfsd: last write beyond layout segment\n"); 23439cf514ccSChristoph Hellwig goto out; 23449cf514ccSChristoph Hellwig } 23459cf514ccSChristoph Hellwig if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { 23469cf514ccSChristoph Hellwig dprintk("pnfsd: layoutcommit beyond EOF\n"); 23479cf514ccSChristoph Hellwig goto out; 23489cf514ccSChristoph Hellwig } 23499cf514ccSChristoph Hellwig 23509cf514ccSChristoph Hellwig nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, 23519cf514ccSChristoph Hellwig false, lcp->lc_layout_type, 23529cf514ccSChristoph Hellwig &ls); 23539cf514ccSChristoph Hellwig if (nfserr) { 2354f394b62bSChuck Lever trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); 23559cf514ccSChristoph Hellwig /* fixup error code as per RFC5661 */ 23569cf514ccSChristoph Hellwig if (nfserr == nfserr_bad_stateid) 23579cf514ccSChristoph Hellwig nfserr = nfserr_badlayout; 23589cf514ccSChristoph Hellwig goto out; 23599cf514ccSChristoph Hellwig } 23609cf514ccSChristoph Hellwig 2361cc8a5532SJeff Layton /* LAYOUTCOMMIT does not require any serialization */ 2362cc8a5532SJeff Layton mutex_unlock(&ls->ls_mutex); 2363cc8a5532SJeff Layton 23649cf514ccSChristoph Hellwig if (new_size > i_size_read(inode)) { 23659cf514ccSChristoph Hellwig lcp->lc_size_chg = 1; 23669cf514ccSChristoph Hellwig lcp->lc_newsize = new_size; 23679cf514ccSChristoph Hellwig } else { 23689cf514ccSChristoph Hellwig lcp->lc_size_chg = 0; 23699cf514ccSChristoph Hellwig } 23709cf514ccSChristoph Hellwig 2371d8398fc1SKinglong Mee nfserr = ops->proc_layoutcommit(inode, lcp); 23729cf514ccSChristoph Hellwig nfs4_put_stid(&ls->ls_stid); 23739cf514ccSChristoph Hellwig out: 23749cf514ccSChristoph Hellwig return nfserr; 23759cf514ccSChristoph Hellwig } 23769cf514ccSChristoph Hellwig 23779cf514ccSChristoph Hellwig static __be32 23789cf514ccSChristoph Hellwig nfsd4_layoutreturn(struct svc_rqst *rqstp, 2379eb69853dSChristoph Hellwig struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) 23809cf514ccSChristoph Hellwig { 2381eb69853dSChristoph Hellwig struct nfsd4_layoutreturn *lrp = &u->layoutreturn; 23829cf514ccSChristoph Hellwig struct svc_fh *current_fh = &cstate->current_fh; 23839cf514ccSChristoph Hellwig __be32 nfserr; 23849cf514ccSChristoph Hellwig 23859cf514ccSChristoph Hellwig nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); 23869cf514ccSChristoph Hellwig if (nfserr) 23879cf514ccSChristoph Hellwig goto out; 23889cf514ccSChristoph Hellwig 23899cf514ccSChristoph Hellwig nfserr = nfserr_layoutunavailable; 23909cf514ccSChristoph Hellwig if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) 23919cf514ccSChristoph Hellwig goto out; 23929cf514ccSChristoph Hellwig 23939cf514ccSChristoph Hellwig switch (lrp->lr_seg.iomode) { 23949cf514ccSChristoph Hellwig case IOMODE_READ: 23959cf514ccSChristoph Hellwig case IOMODE_RW: 23969cf514ccSChristoph Hellwig case IOMODE_ANY: 23979cf514ccSChristoph Hellwig break; 23989cf514ccSChristoph Hellwig default: 23999cf514ccSChristoph Hellwig dprintk("%s: invalid iomode %d\n", __func__, 24009cf514ccSChristoph Hellwig lrp->lr_seg.iomode); 24019cf514ccSChristoph Hellwig nfserr = nfserr_inval; 24029cf514ccSChristoph Hellwig goto out; 24039cf514ccSChristoph Hellwig } 24049cf514ccSChristoph Hellwig 24059cf514ccSChristoph Hellwig switch (lrp->lr_return_type) { 24069cf514ccSChristoph Hellwig case RETURN_FILE: 24079cf514ccSChristoph Hellwig nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); 24089cf514ccSChristoph Hellwig break; 24099cf514ccSChristoph Hellwig case RETURN_FSID: 24109cf514ccSChristoph Hellwig case RETURN_ALL: 24119cf514ccSChristoph Hellwig nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); 24129cf514ccSChristoph Hellwig break; 24139cf514ccSChristoph Hellwig default: 24149cf514ccSChristoph Hellwig dprintk("%s: invalid return_type %d\n", __func__, 24159cf514ccSChristoph Hellwig lrp->lr_return_type); 24169cf514ccSChristoph Hellwig nfserr = nfserr_inval; 24179cf514ccSChristoph Hellwig break; 24189cf514ccSChristoph Hellwig } 24199cf514ccSChristoph Hellwig out: 24209cf514ccSChristoph Hellwig return nfserr; 24219cf514ccSChristoph Hellwig } 24229cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 24239cf514ccSChristoph Hellwig 242423e50fe3SFrank van der Linden static __be32 242523e50fe3SFrank van der Linden nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 242623e50fe3SFrank van der Linden union nfsd4_op_u *u) 242723e50fe3SFrank van der Linden { 242823e50fe3SFrank van der Linden struct nfsd4_getxattr *getxattr = &u->getxattr; 242923e50fe3SFrank van der Linden 243023e50fe3SFrank van der Linden return nfsd_getxattr(rqstp, &cstate->current_fh, 243123e50fe3SFrank van der Linden getxattr->getxa_name, &getxattr->getxa_buf, 243223e50fe3SFrank van der Linden &getxattr->getxa_len); 243323e50fe3SFrank van der Linden } 243423e50fe3SFrank van der Linden 243523e50fe3SFrank van der Linden static __be32 243623e50fe3SFrank van der Linden nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 243723e50fe3SFrank van der Linden union nfsd4_op_u *u) 243823e50fe3SFrank van der Linden { 243923e50fe3SFrank van der Linden struct nfsd4_setxattr *setxattr = &u->setxattr; 244023e50fe3SFrank van der Linden __be32 ret; 244123e50fe3SFrank van der Linden 244223e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 244323e50fe3SFrank van der Linden return nfserr_grace; 244423e50fe3SFrank van der Linden 244523e50fe3SFrank van der Linden ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name, 244623e50fe3SFrank van der Linden setxattr->setxa_buf, setxattr->setxa_len, 244723e50fe3SFrank van der Linden setxattr->setxa_flags); 244823e50fe3SFrank van der Linden 244923e50fe3SFrank van der Linden if (!ret) 245023e50fe3SFrank van der Linden set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh); 245123e50fe3SFrank van der Linden 245223e50fe3SFrank van der Linden return ret; 245323e50fe3SFrank van der Linden } 245423e50fe3SFrank van der Linden 245523e50fe3SFrank van der Linden static __be32 245623e50fe3SFrank van der Linden nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 245723e50fe3SFrank van der Linden union nfsd4_op_u *u) 245823e50fe3SFrank van der Linden { 245923e50fe3SFrank van der Linden /* 246023e50fe3SFrank van der Linden * Get the entire list, then copy out only the user attributes 246123e50fe3SFrank van der Linden * in the encode function. 246223e50fe3SFrank van der Linden */ 246323e50fe3SFrank van der Linden return nfsd_listxattr(rqstp, &cstate->current_fh, 246423e50fe3SFrank van der Linden &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len); 246523e50fe3SFrank van der Linden } 246623e50fe3SFrank van der Linden 246723e50fe3SFrank van der Linden static __be32 246823e50fe3SFrank van der Linden nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 246923e50fe3SFrank van der Linden union nfsd4_op_u *u) 247023e50fe3SFrank van der Linden { 247123e50fe3SFrank van der Linden struct nfsd4_removexattr *removexattr = &u->removexattr; 247223e50fe3SFrank van der Linden __be32 ret; 247323e50fe3SFrank van der Linden 247423e50fe3SFrank van der Linden if (opens_in_grace(SVC_NET(rqstp))) 247523e50fe3SFrank van der Linden return nfserr_grace; 247623e50fe3SFrank van der Linden 247723e50fe3SFrank van der Linden ret = nfsd_removexattr(rqstp, &cstate->current_fh, 247823e50fe3SFrank van der Linden removexattr->rmxa_name); 247923e50fe3SFrank van der Linden 248023e50fe3SFrank van der Linden if (!ret) 248123e50fe3SFrank van der Linden set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh); 248223e50fe3SFrank van der Linden 248323e50fe3SFrank van der Linden return ret; 248423e50fe3SFrank van der Linden } 248523e50fe3SFrank van der Linden 24861da177e4SLinus Torvalds /* 24871da177e4SLinus Torvalds * NULL call. 24881da177e4SLinus Torvalds */ 24897111c66eSAl Viro static __be32 2490a6beb732SChristoph Hellwig nfsd4_proc_null(struct svc_rqst *rqstp) 24911da177e4SLinus Torvalds { 2492cc028a10SChuck Lever return rpc_success; 24931da177e4SLinus Torvalds } 24941da177e4SLinus Torvalds 2495e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 2496e2b20950SShankar Anand { 2497e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 2498e567b98cSAmir Goldstein percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]); 2499e2b20950SShankar Anand } 2500e2b20950SShankar Anand 2501bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[]; 2502b591480bSJ.Bruce Fields 2503f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 2504b001a1b6SBenny Halevy 25051da177e4SLinus Torvalds /* 250657716355SJ. Bruce Fields * Enforce NFSv4.1 COMPOUND ordering rules: 2507f9bb94c4SAndy Adamson * 250857716355SJ. Bruce Fields * Also note, enforced elsewhere: 250957716355SJ. Bruce Fields * - SEQUENCE other than as first op results in 251057716355SJ. Bruce Fields * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) 25111d1bc8f2SJ. Bruce Fields * - BIND_CONN_TO_SESSION must be the only op in its compound. 25121d1bc8f2SJ. Bruce Fields * (Enforced in nfsd4_bind_conn_to_session().) 251357716355SJ. Bruce Fields * - DESTROY_SESSION must be the final operation in a compound, if 251457716355SJ. Bruce Fields * sessionid's in SEQUENCE and DESTROY_SESSION are the same. 251557716355SJ. Bruce Fields * (Enforced in nfsd4_destroy_session().) 2516f9bb94c4SAndy Adamson */ 251757716355SJ. Bruce Fields static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) 2518f9bb94c4SAndy Adamson { 25197a04cfdaSJ. Bruce Fields struct nfsd4_op *first_op = &args->ops[0]; 252057716355SJ. Bruce Fields 252157716355SJ. Bruce Fields /* These ordering requirements don't apply to NFSv4.0: */ 252257716355SJ. Bruce Fields if (args->minorversion == 0) 252357716355SJ. Bruce Fields return nfs_ok; 252457716355SJ. Bruce Fields /* This is weird, but OK, not our problem: */ 252557716355SJ. Bruce Fields if (args->opcnt == 0) 252657716355SJ. Bruce Fields return nfs_ok; 25277a04cfdaSJ. Bruce Fields if (first_op->status == nfserr_op_illegal) 252857716355SJ. Bruce Fields return nfs_ok; 25297a04cfdaSJ. Bruce Fields if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) 253057716355SJ. Bruce Fields return nfserr_op_not_in_session; 25317a04cfdaSJ. Bruce Fields if (first_op->opnum == OP_SEQUENCE) 253257716355SJ. Bruce Fields return nfs_ok; 25337a04cfdaSJ. Bruce Fields /* 25347a04cfdaSJ. Bruce Fields * So first_op is something allowed outside a session, like 25357a04cfdaSJ. Bruce Fields * EXCHANGE_ID; but then it has to be the only op in the 25367a04cfdaSJ. Bruce Fields * compound: 25377a04cfdaSJ. Bruce Fields */ 253857716355SJ. Bruce Fields if (args->opcnt != 1) 253957716355SJ. Bruce Fields return nfserr_not_only_op; 254057716355SJ. Bruce Fields return nfs_ok; 2541f9bb94c4SAndy Adamson } 2542f9bb94c4SAndy Adamson 2543f4f9ef4aSJ. Bruce Fields const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) 254422b03214SJ. Bruce Fields { 254522b03214SJ. Bruce Fields return &nfsd4_ops[op->opnum]; 254622b03214SJ. Bruce Fields } 254722b03214SJ. Bruce Fields 25481091006cSJ. Bruce Fields bool nfsd4_cache_this_op(struct nfsd4_op *op) 25491091006cSJ. Bruce Fields { 2550e372ba60SJ. Bruce Fields if (op->opnum == OP_ILLEGAL) 2551e372ba60SJ. Bruce Fields return false; 2552c856694eSJ. Bruce Fields return OPDESC(op)->op_flags & OP_CACHEME; 25531091006cSJ. Bruce Fields } 25541091006cSJ. Bruce Fields 255568d93184SJ. Bruce Fields static bool need_wrongsec_check(struct svc_rqst *rqstp) 255668d93184SJ. Bruce Fields { 255768d93184SJ. Bruce Fields struct nfsd4_compoundres *resp = rqstp->rq_resp; 255868d93184SJ. Bruce Fields struct nfsd4_compoundargs *argp = rqstp->rq_argp; 255968d93184SJ. Bruce Fields struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; 256068d93184SJ. Bruce Fields struct nfsd4_op *next = &argp->ops[resp->opcnt]; 2561bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *thisd = OPDESC(this); 2562bb2a8b0cSChristoph Hellwig const struct nfsd4_operation *nextd; 256368d93184SJ. Bruce Fields 256468d93184SJ. Bruce Fields /* 256568d93184SJ. Bruce Fields * Most ops check wronsec on our own; only the putfh-like ops 256668d93184SJ. Bruce Fields * have special rules. 256768d93184SJ. Bruce Fields */ 256868d93184SJ. Bruce Fields if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) 256968d93184SJ. Bruce Fields return false; 257068d93184SJ. Bruce Fields /* 257168d93184SJ. Bruce Fields * rfc 5661 2.6.3.1.1.6: don't bother erroring out a 257268d93184SJ. Bruce Fields * put-filehandle operation if we're not going to use the 257368d93184SJ. Bruce Fields * result: 257468d93184SJ. Bruce Fields */ 257568d93184SJ. Bruce Fields if (argp->opcnt == resp->opcnt) 257668d93184SJ. Bruce Fields return false; 257751904b08SJ. Bruce Fields if (next->opnum == OP_ILLEGAL) 257851904b08SJ. Bruce Fields return false; 257968d93184SJ. Bruce Fields nextd = OPDESC(next); 258068d93184SJ. Bruce Fields /* 258168d93184SJ. Bruce Fields * Rest of 2.6.3.1.1: certain operations will return WRONGSEC 258268d93184SJ. Bruce Fields * errors themselves as necessary; others should check for them 258368d93184SJ. Bruce Fields * now: 258468d93184SJ. Bruce Fields */ 258568d93184SJ. Bruce Fields return !(nextd->op_flags & OP_HANDLES_WRONGSEC); 258668d93184SJ. Bruce Fields } 258768d93184SJ. Bruce Fields 2588b9e8638eSOlga Kornievskaia #ifdef CONFIG_NFSD_V4_2_INTER_SSC 2589b9e8638eSOlga Kornievskaia static void 2590b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2591b9e8638eSOlga Kornievskaia { 2592b9e8638eSOlga Kornievskaia struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; 2593b9e8638eSOlga Kornievskaia struct nfsd4_copy *copy; 2594b9e8638eSOlga Kornievskaia struct nfsd4_putfh *putfh; 2595b9e8638eSOlga Kornievskaia int i; 2596b9e8638eSOlga Kornievskaia 2597b9e8638eSOlga Kornievskaia /* traverse all operation and if it's a COPY compound, mark the 2598b9e8638eSOlga Kornievskaia * source filehandle to skip verification 2599b9e8638eSOlga Kornievskaia */ 2600b9e8638eSOlga Kornievskaia for (i = 0; i < args->opcnt; i++) { 2601b9e8638eSOlga Kornievskaia op = &args->ops[i]; 2602b9e8638eSOlga Kornievskaia if (op->opnum == OP_PUTFH) 2603b9e8638eSOlga Kornievskaia current_op = op; 2604b9e8638eSOlga Kornievskaia else if (op->opnum == OP_SAVEFH) 2605b9e8638eSOlga Kornievskaia saved_op = current_op; 2606b9e8638eSOlga Kornievskaia else if (op->opnum == OP_RESTOREFH) 2607b9e8638eSOlga Kornievskaia current_op = saved_op; 2608b9e8638eSOlga Kornievskaia else if (op->opnum == OP_COPY) { 2609b9e8638eSOlga Kornievskaia copy = (struct nfsd4_copy *)&op->u; 2610b9e8638eSOlga Kornievskaia if (!saved_op) { 2611b9e8638eSOlga Kornievskaia op->status = nfserr_nofilehandle; 2612b9e8638eSOlga Kornievskaia return; 2613b9e8638eSOlga Kornievskaia } 2614b9e8638eSOlga Kornievskaia putfh = (struct nfsd4_putfh *)&saved_op->u; 26151913cdf5SChuck Lever if (nfsd4_ssc_is_inter(copy)) 2616b9e8638eSOlga Kornievskaia putfh->no_verify = true; 2617b9e8638eSOlga Kornievskaia } 2618b9e8638eSOlga Kornievskaia } 2619b9e8638eSOlga Kornievskaia } 2620b9e8638eSOlga Kornievskaia #else 2621b9e8638eSOlga Kornievskaia static void 2622b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(struct nfsd4_compoundargs *args) 2623b9e8638eSOlga Kornievskaia { 2624b9e8638eSOlga Kornievskaia } 2625b9e8638eSOlga Kornievskaia #endif 2626b9e8638eSOlga Kornievskaia 2627f9bb94c4SAndy Adamson /* 26281da177e4SLinus Torvalds * COMPOUND call. 26291da177e4SLinus Torvalds */ 26307111c66eSAl Viro static __be32 2631a6beb732SChristoph Hellwig nfsd4_proc_compound(struct svc_rqst *rqstp) 26321da177e4SLinus Torvalds { 2633a6beb732SChristoph Hellwig struct nfsd4_compoundargs *args = rqstp->rq_argp; 2634a6beb732SChristoph Hellwig struct nfsd4_compoundres *resp = rqstp->rq_resp; 26351da177e4SLinus Torvalds struct nfsd4_op *op; 2636e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 26374daeed25SKinglong Mee struct svc_fh *current_fh = &cstate->current_fh; 26384daeed25SKinglong Mee struct svc_fh *save_fh = &cstate->save_fh; 2639e333f3bbSTrond Myklebust struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); 2640b37ad28bSAl Viro __be32 status; 26411da177e4SLinus Torvalds 2642bddfdbcdSChuck Lever resp->xdr = &rqstp->rq_res_stream; 26433b0ebb25SChuck Lever resp->statusp = resp->xdr->p; 2644bddfdbcdSChuck Lever 2645bddfdbcdSChuck Lever /* reserve space for: NFS status code */ 2646bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT); 2647bddfdbcdSChuck Lever 26481da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 2649bddfdbcdSChuck Lever xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen); 26501da177e4SLinus Torvalds resp->taglen = args->taglen; 26511da177e4SLinus Torvalds resp->tag = args->tag; 26521da177e4SLinus Torvalds resp->rqstp = rqstp; 26534daeed25SKinglong Mee cstate->minorversion = args->minorversion; 26544daeed25SKinglong Mee fh_init(current_fh, NFS4_FHSIZE); 26554daeed25SKinglong Mee fh_init(save_fh, NFS4_FHSIZE); 265628df0988SChuck Lever 26578ff30fa4SNeilBrown /* 26588ff30fa4SNeilBrown * Don't use the deferral mechanism for NFSv4; compounds make it 26598ff30fa4SNeilBrown * too hard to avoid non-idempotency problems. 26608ff30fa4SNeilBrown */ 266128df0988SChuck Lever __clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 26621da177e4SLinus Torvalds 26631da177e4SLinus Torvalds /* 26641da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 26651da177e4SLinus Torvalds */ 26661da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 2667e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) 26681da177e4SLinus Torvalds goto out; 26690078117cSJ. Bruce Fields status = nfserr_resource; 26700078117cSJ. Bruce Fields if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) 26710078117cSJ. Bruce Fields goto out; 26721da177e4SLinus Torvalds 267357716355SJ. Bruce Fields status = nfs41_check_op_ordering(args); 267457716355SJ. Bruce Fields if (status) { 2675f9bb94c4SAndy Adamson op = &args->ops[0]; 267657716355SJ. Bruce Fields op->status = status; 26775b7b15aeSJ. Bruce Fields resp->opcnt = 1; 2678f9bb94c4SAndy Adamson goto encode_op; 2679f9bb94c4SAndy Adamson } 2680b9e8638eSOlga Kornievskaia check_if_stalefh_allowed(args); 2681f9bb94c4SAndy Adamson 268228df3d15SJ. Bruce Fields rqstp->rq_lease_breaker = (void **)&cstate->clp; 268328df3d15SJ. Bruce Fields 2684fff4080bSChuck Lever trace_nfsd_compound(rqstp, args->opcnt); 26851da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 26861da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 26871da177e4SLinus Torvalds 26881da177e4SLinus Torvalds /* 26891da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 26901da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 26911da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 26921da177e4SLinus Torvalds */ 26939d313b17SJ. Bruce Fields if (op->status) { 26949d313b17SJ. Bruce Fields if (op->opnum == OP_OPEN) 26959d313b17SJ. Bruce Fields op->status = nfsd4_open_omfg(rqstp, cstate, op); 26961da177e4SLinus Torvalds goto encode_op; 26979d313b17SJ. Bruce Fields } 2698b9e8638eSOlga Kornievskaia if (!current_fh->fh_dentry && 2699b9e8638eSOlga Kornievskaia !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { 2700f4f9ef4aSJ. Bruce Fields if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 27011da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 27021da177e4SLinus Torvalds goto encode_op; 27031da177e4SLinus Torvalds } 2704b9e8638eSOlga Kornievskaia } else if (current_fh->fh_export && 2705b9e8638eSOlga Kornievskaia current_fh->fh_export->ex_fslocs.migrated && 2706f4f9ef4aSJ. Bruce Fields !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 270742ca0993SJ.Bruce Fields op->status = nfserr_moved; 270842ca0993SJ.Bruce Fields goto encode_op; 270942ca0993SJ.Bruce Fields } 2710b591480bSJ.Bruce Fields 2711fcb5e3faSChuck Lever fh_clear_pre_post_attrs(current_fh); 27122336745eSKinglong Mee 271358e7b33aSMi Jinlong /* If op is non-idempotent */ 2714f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { 27154c69d585SJ. Bruce Fields /* 2716a8095f7eSJ. Bruce Fields * Don't execute this op if we couldn't encode a 2717f532c9ffSZhang Jiaming * successful reply: 2718a8095f7eSJ. Bruce Fields */ 2719f4f9ef4aSJ. Bruce Fields u32 plen = op->opdesc->op_rsize_bop(rqstp, op); 2720a8095f7eSJ. Bruce Fields /* 2721a8095f7eSJ. Bruce Fields * Plus if there's another operation, make sure 27224c69d585SJ. Bruce Fields * we'll have space to at least encode an error: 27234c69d585SJ. Bruce Fields */ 27244c69d585SJ. Bruce Fields if (resp->opcnt < args->opcnt) 27254c69d585SJ. Bruce Fields plen += COMPOUND_ERR_SLACK_SPACE; 272658e7b33aSMi Jinlong op->status = nfsd4_check_resp_size(resp, plen); 272758e7b33aSMi Jinlong } 272858e7b33aSMi Jinlong 272958e7b33aSMi Jinlong if (op->status) 273058e7b33aSMi Jinlong goto encode_op; 273158e7b33aSMi Jinlong 2732f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_get_currentstateid) 2733f4f9ef4aSJ. Bruce Fields op->opdesc->op_get_currentstateid(cstate, &op->u); 2734f4f9ef4aSJ. Bruce Fields op->status = op->opdesc->op_func(rqstp, cstate, &op->u); 27351da177e4SLinus Torvalds 27369a307403SJ. Bruce Fields /* Only from SEQUENCE */ 27379a307403SJ. Bruce Fields if (cstate->status == nfserr_replay_cache) { 27389a307403SJ. Bruce Fields dprintk("%s NFS4.1 replay from cache\n", __func__); 27399a307403SJ. Bruce Fields status = op->status; 27409a307403SJ. Bruce Fields goto out; 27419a307403SJ. Bruce Fields } 27428b70484cSTigran Mkrtchyan if (!op->status) { 2743f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_set_currentstateid) 2744f4f9ef4aSJ. Bruce Fields op->opdesc->op_set_currentstateid(cstate, &op->u); 27458b70484cSTigran Mkrtchyan 2746f4f9ef4aSJ. Bruce Fields if (op->opdesc->op_flags & OP_CLEAR_STATEID) 274737c593c5STigran Mkrtchyan clear_current_stateid(cstate); 27488b70484cSTigran Mkrtchyan 2749d781e3dfSJ. Bruce Fields if (current_fh->fh_export && 2750d781e3dfSJ. Bruce Fields need_wrongsec_check(rqstp)) 27514daeed25SKinglong Mee op->status = check_nfsd_access(current_fh->fh_export, rqstp); 27528b70484cSTigran Mkrtchyan } 27531da177e4SLinus Torvalds encode_op: 2754a90b061cSAl Viro if (op->status == nfserr_replay_me) { 2755a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 2756bddfdbcdSChuck Lever nfsd4_encode_replay(resp->xdr, op); 27571da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 27581da177e4SLinus Torvalds } else { 27591da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 27601da177e4SLinus Torvalds status = op->status; 27611da177e4SLinus Torvalds } 27620407717dSBenny Halevy 2763fff4080bSChuck Lever trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, 2764fff4080bSChuck Lever nfsd4_op_name(op->opnum)); 27650407717dSBenny Halevy 276658fb12e6SJeff Layton nfsd4_cstate_clear_replay(cstate); 2767e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 27681da177e4SLinus Torvalds } 27691da177e4SLinus Torvalds 27704daeed25SKinglong Mee fh_put(current_fh); 27714daeed25SKinglong Mee fh_put(save_fh); 27724daeed25SKinglong Mee BUG_ON(cstate->replay_owner); 27731da177e4SLinus Torvalds out: 2774cc028a10SChuck Lever cstate->status = status; 27752f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 277628df0988SChuck Lever __set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); 2777cc028a10SChuck Lever return rpc_success; 27781da177e4SLinus Torvalds } 27791da177e4SLinus Torvalds 278058e7b33aSMi Jinlong #define op_encode_hdr_size (2) 278158e7b33aSMi Jinlong #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 278258e7b33aSMi Jinlong #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 278358e7b33aSMi Jinlong #define op_encode_change_info_maxsz (5) 278458e7b33aSMi Jinlong #define nfs4_fattr_bitmap_maxsz (4) 278558e7b33aSMi Jinlong 27868c7424cfSJ. Bruce Fields /* We'll fall back on returning no lockowner if run out of space: */ 27878c7424cfSJ. Bruce Fields #define op_encode_lockowner_maxsz (0) 278858e7b33aSMi Jinlong #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) 278958e7b33aSMi Jinlong 279058e7b33aSMi Jinlong #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 279158e7b33aSMi Jinlong 279258e7b33aSMi Jinlong #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) 279358e7b33aSMi Jinlong #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ 279458e7b33aSMi Jinlong op_encode_ace_maxsz) 279558e7b33aSMi Jinlong 279658e7b33aSMi Jinlong #define op_encode_channel_attrs_maxsz (6 + 1 + 1) 279758e7b33aSMi Jinlong 279858e7b33aSMi Jinlong static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 279958e7b33aSMi Jinlong { 280058e7b33aSMi Jinlong return (op_encode_hdr_size) * sizeof(__be32); 280158e7b33aSMi Jinlong } 280258e7b33aSMi Jinlong 280358e7b33aSMi Jinlong static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 280458e7b33aSMi Jinlong { 280558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); 280658e7b33aSMi Jinlong } 280758e7b33aSMi Jinlong 28082282cd2cSKinglong Mee static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28092282cd2cSKinglong Mee { 28102282cd2cSKinglong Mee /* ac_supported, ac_resp_access */ 28112282cd2cSKinglong Mee return (op_encode_hdr_size + 2)* sizeof(__be32); 28122282cd2cSKinglong Mee } 28132282cd2cSKinglong Mee 281458e7b33aSMi Jinlong static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 281558e7b33aSMi Jinlong { 281658e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); 281758e7b33aSMi Jinlong } 281858e7b33aSMi Jinlong 281958e7b33aSMi Jinlong static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 282058e7b33aSMi Jinlong { 282158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 282258e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 282358e7b33aSMi Jinlong } 282458e7b33aSMi Jinlong 2825b86cef60SJ. Bruce Fields /* 2826b86cef60SJ. Bruce Fields * Note since this is an idempotent operation we won't insist on failing 2827b86cef60SJ. Bruce Fields * the op prematurely if the estimate is too large. We may turn off splice 2828b86cef60SJ. Bruce Fields * reads unnecessarily. 2829b86cef60SJ. Bruce Fields */ 2830b86cef60SJ. Bruce Fields static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, 2831b86cef60SJ. Bruce Fields struct nfsd4_op *op) 2832b86cef60SJ. Bruce Fields { 2833b86cef60SJ. Bruce Fields u32 *bmap = op->u.getattr.ga_bmval; 2834b86cef60SJ. Bruce Fields u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; 2835b86cef60SJ. Bruce Fields u32 ret = 0; 2836b86cef60SJ. Bruce Fields 2837b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_ACL) 2838b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2839b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) 2840b86cef60SJ. Bruce Fields return svc_max_payload(rqstp); 2841b86cef60SJ. Bruce Fields 2842b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER) { 2843b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2844b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER; 2845b86cef60SJ. Bruce Fields } 2846b86cef60SJ. Bruce Fields if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { 2847b86cef60SJ. Bruce Fields ret += IDMAP_NAMESZ + 4; 2848b86cef60SJ. Bruce Fields bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; 2849b86cef60SJ. Bruce Fields } 2850b86cef60SJ. Bruce Fields if (bmap0 & FATTR4_WORD0_FILEHANDLE) { 2851b86cef60SJ. Bruce Fields ret += NFS4_FHSIZE + 4; 2852b86cef60SJ. Bruce Fields bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 2853b86cef60SJ. Bruce Fields } 2854b86cef60SJ. Bruce Fields if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 28551ec8c0c4SKinglong Mee ret += NFS4_MAXLABELLEN + 12; 2856b86cef60SJ. Bruce Fields bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 2857b86cef60SJ. Bruce Fields } 2858b86cef60SJ. Bruce Fields /* 2859b86cef60SJ. Bruce Fields * Largest of remaining attributes are 16 bytes (e.g., 2860b86cef60SJ. Bruce Fields * supported_attributes) 2861b86cef60SJ. Bruce Fields */ 2862b86cef60SJ. Bruce Fields ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); 2863b86cef60SJ. Bruce Fields /* bitmask, length */ 2864b86cef60SJ. Bruce Fields ret += 20; 2865b86cef60SJ. Bruce Fields return ret; 2866b86cef60SJ. Bruce Fields } 2867b86cef60SJ. Bruce Fields 28682282cd2cSKinglong Mee static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 28692282cd2cSKinglong Mee { 28702282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; 28712282cd2cSKinglong Mee } 28722282cd2cSKinglong Mee 287358e7b33aSMi Jinlong static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 287458e7b33aSMi Jinlong { 287558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 287658e7b33aSMi Jinlong * sizeof(__be32); 287758e7b33aSMi Jinlong } 287858e7b33aSMi Jinlong 287958e7b33aSMi Jinlong static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 288058e7b33aSMi Jinlong { 288158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_lock_denied_maxsz) 288258e7b33aSMi Jinlong * sizeof(__be32); 288358e7b33aSMi Jinlong } 288458e7b33aSMi Jinlong 288558e7b33aSMi Jinlong static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 288658e7b33aSMi Jinlong { 288758e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_stateid_maxsz 288858e7b33aSMi Jinlong + op_encode_change_info_maxsz + 1 288958e7b33aSMi Jinlong + nfs4_fattr_bitmap_maxsz 289058e7b33aSMi Jinlong + op_encode_delegation_maxsz) * sizeof(__be32); 289158e7b33aSMi Jinlong } 289258e7b33aSMi Jinlong 289358e7b33aSMi Jinlong static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 289458e7b33aSMi Jinlong { 289558e7b33aSMi Jinlong u32 maxcount = 0, rlen = 0; 289658e7b33aSMi Jinlong 289758e7b33aSMi Jinlong maxcount = svc_max_payload(rqstp); 28983c7aa15dSKinglong Mee rlen = min(op->u.read.rd_length, maxcount); 289958e7b33aSMi Jinlong 2900622f560eSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); 290158e7b33aSMi Jinlong } 290258e7b33aSMi Jinlong 2903528b8493SAnna Schumaker static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 2904528b8493SAnna Schumaker { 2905528b8493SAnna Schumaker u32 maxcount = svc_max_payload(rqstp); 2906528b8493SAnna Schumaker u32 rlen = min(op->u.read.rd_length, maxcount); 2907528b8493SAnna Schumaker /* 2908528b8493SAnna Schumaker * If we detect that the file changed during hole encoding, then we 2909528b8493SAnna Schumaker * recover by encoding the remaining reply as data. This means we need 2910528b8493SAnna Schumaker * to set aside enough room to encode two data segments. 2911528b8493SAnna Schumaker */ 2912528b8493SAnna Schumaker u32 seg_len = 2 * (1 + 2 + 1); 2913528b8493SAnna Schumaker 2914528b8493SAnna Schumaker return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32); 2915528b8493SAnna Schumaker } 2916528b8493SAnna Schumaker 291758e7b33aSMi Jinlong static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 291858e7b33aSMi Jinlong { 29193c7aa15dSKinglong Mee u32 maxcount = 0, rlen = 0; 292058e7b33aSMi Jinlong 29213c7aa15dSKinglong Mee maxcount = svc_max_payload(rqstp); 29223c7aa15dSKinglong Mee rlen = min(op->u.readdir.rd_maxcount, maxcount); 292358e7b33aSMi Jinlong 2924561f0ed4SJ. Bruce Fields return (op_encode_hdr_size + op_encode_verifier_maxsz + 2925561f0ed4SJ. Bruce Fields XDR_QUADLEN(rlen)) * sizeof(__be32); 292658e7b33aSMi Jinlong } 292758e7b33aSMi Jinlong 29282282cd2cSKinglong Mee static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29292282cd2cSKinglong Mee { 29302282cd2cSKinglong Mee return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; 29312282cd2cSKinglong Mee } 29322282cd2cSKinglong Mee 293358e7b33aSMi Jinlong static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 293458e7b33aSMi Jinlong { 293558e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz) 293658e7b33aSMi Jinlong * sizeof(__be32); 293758e7b33aSMi Jinlong } 293858e7b33aSMi Jinlong 293958e7b33aSMi Jinlong static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 294058e7b33aSMi Jinlong { 294158e7b33aSMi Jinlong return (op_encode_hdr_size + op_encode_change_info_maxsz 294258e7b33aSMi Jinlong + op_encode_change_info_maxsz) * sizeof(__be32); 294358e7b33aSMi Jinlong } 294458e7b33aSMi Jinlong 2945ccae70a9SJ. Bruce Fields static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, 2946ccae70a9SJ. Bruce Fields struct nfsd4_op *op) 2947ccae70a9SJ. Bruce Fields { 2948d1d84c96SJ. Bruce Fields return (op_encode_hdr_size 2949d1d84c96SJ. Bruce Fields + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); 2950ccae70a9SJ. Bruce Fields } 2951ccae70a9SJ. Bruce Fields 29522282cd2cSKinglong Mee static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29532282cd2cSKinglong Mee { 29542282cd2cSKinglong Mee return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) 29552282cd2cSKinglong Mee * sizeof(__be32); 29562282cd2cSKinglong Mee } 29572282cd2cSKinglong Mee 295858e7b33aSMi Jinlong static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 295958e7b33aSMi Jinlong { 296058e7b33aSMi Jinlong return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); 296158e7b33aSMi Jinlong } 296258e7b33aSMi Jinlong 29632282cd2cSKinglong Mee static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 29642282cd2cSKinglong Mee { 29652282cd2cSKinglong Mee return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * 29662282cd2cSKinglong Mee (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); 29672282cd2cSKinglong Mee } 29682282cd2cSKinglong Mee 296958e7b33aSMi Jinlong static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 297058e7b33aSMi Jinlong { 2971480efaeeSJ. Bruce Fields return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * 2972480efaeeSJ. Bruce Fields sizeof(__be32); 297358e7b33aSMi Jinlong } 297458e7b33aSMi Jinlong 297558e7b33aSMi Jinlong static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 297658e7b33aSMi Jinlong { 2977f34e432bSJ. Bruce Fields return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); 297858e7b33aSMi Jinlong } 297958e7b33aSMi Jinlong 298058e7b33aSMi Jinlong static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 298158e7b33aSMi Jinlong { 298258e7b33aSMi Jinlong return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ 2983a8bb84bcSKinglong Mee 1 + 1 + /* eir_flags, spr_how */\ 2984a8bb84bcSKinglong Mee 4 + /* spo_must_enforce & _allow with bitmap */\ 298558e7b33aSMi Jinlong 2 + /*eir_server_owner.so_minor_id */\ 298658e7b33aSMi Jinlong /* eir_server_owner.so_major_id<> */\ 298758e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 298858e7b33aSMi Jinlong /* eir_server_scope<> */\ 298958e7b33aSMi Jinlong XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ 299058e7b33aSMi Jinlong 1 + /* eir_server_impl_id array length */\ 299158e7b33aSMi Jinlong 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); 299258e7b33aSMi Jinlong } 299358e7b33aSMi Jinlong 299458e7b33aSMi Jinlong static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 299558e7b33aSMi Jinlong { 299658e7b33aSMi Jinlong return (op_encode_hdr_size + \ 299758e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ 299858e7b33aSMi Jinlong 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); 299958e7b33aSMi Jinlong } 300058e7b33aSMi Jinlong 300158e7b33aSMi Jinlong static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 300258e7b33aSMi Jinlong { 300358e7b33aSMi Jinlong return (op_encode_hdr_size + \ 300458e7b33aSMi Jinlong XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ 300558e7b33aSMi Jinlong 2 + /* csr_sequence, csr_flags */\ 300658e7b33aSMi Jinlong op_encode_channel_attrs_maxsz + \ 300758e7b33aSMi Jinlong op_encode_channel_attrs_maxsz) * sizeof(__be32); 300858e7b33aSMi Jinlong } 300958e7b33aSMi Jinlong 301029ae7f9dSAnna Schumaker static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 301129ae7f9dSAnna Schumaker { 301229ae7f9dSAnna Schumaker return (op_encode_hdr_size + 301329ae7f9dSAnna Schumaker 1 /* wr_callback */ + 301429ae7f9dSAnna Schumaker op_encode_stateid_maxsz /* wr_callback */ + 301529ae7f9dSAnna Schumaker 2 /* wr_count */ + 301629ae7f9dSAnna Schumaker 1 /* wr_committed */ + 301729ae7f9dSAnna Schumaker op_encode_verifier_maxsz + 301829ae7f9dSAnna Schumaker 1 /* cr_consecutive */ + 301929ae7f9dSAnna Schumaker 1 /* cr_synchronous */) * sizeof(__be32); 302029ae7f9dSAnna Schumaker } 302129ae7f9dSAnna Schumaker 30226308bc98SOlga Kornievskaia static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 30236308bc98SOlga Kornievskaia struct nfsd4_op *op) 30246308bc98SOlga Kornievskaia { 30256308bc98SOlga Kornievskaia return (op_encode_hdr_size + 30266308bc98SOlga Kornievskaia 2 /* osr_count */ + 30276308bc98SOlga Kornievskaia 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); 30286308bc98SOlga Kornievskaia } 30296308bc98SOlga Kornievskaia 303051911868SOlga Kornievskaia static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, 303151911868SOlga Kornievskaia struct nfsd4_op *op) 303251911868SOlga Kornievskaia { 303351911868SOlga Kornievskaia return (op_encode_hdr_size + 303451911868SOlga Kornievskaia 3 /* cnr_lease_time */ + 303551911868SOlga Kornievskaia 1 /* We support one cnr_source_server */ + 303651911868SOlga Kornievskaia 1 /* cnr_stateid seq */ + 303751911868SOlga Kornievskaia op_encode_stateid_maxsz /* cnr_stateid */ + 303851911868SOlga Kornievskaia 1 /* num cnr_source_server*/ + 303951911868SOlga Kornievskaia 1 /* nl4_type */ + 304051911868SOlga Kornievskaia 1 /* nl4 size */ + 304151911868SOlga Kornievskaia XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) 304251911868SOlga Kornievskaia * sizeof(__be32); 304351911868SOlga Kornievskaia } 304451911868SOlga Kornievskaia 30459cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 30462282cd2cSKinglong Mee static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30472282cd2cSKinglong Mee { 30482282cd2cSKinglong Mee u32 maxcount = 0, rlen = 0; 30492282cd2cSKinglong Mee 30502282cd2cSKinglong Mee maxcount = svc_max_payload(rqstp); 30512282cd2cSKinglong Mee rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); 30522282cd2cSKinglong Mee 30532282cd2cSKinglong Mee return (op_encode_hdr_size + 30542282cd2cSKinglong Mee 1 /* gd_layout_type*/ + 30552282cd2cSKinglong Mee XDR_QUADLEN(rlen) + 30562282cd2cSKinglong Mee 2 /* gd_notify_types */) * sizeof(__be32); 30572282cd2cSKinglong Mee } 30582282cd2cSKinglong Mee 30599cf514ccSChristoph Hellwig /* 30609cf514ccSChristoph Hellwig * At this stage we don't really know what layout driver will handle the request, 30619cf514ccSChristoph Hellwig * so we need to define an arbitrary upper bound here. 30629cf514ccSChristoph Hellwig */ 30639cf514ccSChristoph Hellwig #define MAX_LAYOUT_SIZE 128 30649cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30659cf514ccSChristoph Hellwig { 30669cf514ccSChristoph Hellwig return (op_encode_hdr_size + 30679cf514ccSChristoph Hellwig 1 /* logr_return_on_close */ + 30689cf514ccSChristoph Hellwig op_encode_stateid_maxsz + 30699cf514ccSChristoph Hellwig 1 /* nr of layouts */ + 30709cf514ccSChristoph Hellwig MAX_LAYOUT_SIZE) * sizeof(__be32); 30719cf514ccSChristoph Hellwig } 30729cf514ccSChristoph Hellwig 30739cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30749cf514ccSChristoph Hellwig { 30759cf514ccSChristoph Hellwig return (op_encode_hdr_size + 30769cf514ccSChristoph Hellwig 1 /* locr_newsize */ + 30779cf514ccSChristoph Hellwig 2 /* ns_size */) * sizeof(__be32); 30789cf514ccSChristoph Hellwig } 30799cf514ccSChristoph Hellwig 30809cf514ccSChristoph Hellwig static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30819cf514ccSChristoph Hellwig { 30829cf514ccSChristoph Hellwig return (op_encode_hdr_size + 30839cf514ccSChristoph Hellwig 1 /* lrs_stateid */ + 30849cf514ccSChristoph Hellwig op_encode_stateid_maxsz) * sizeof(__be32); 30859cf514ccSChristoph Hellwig } 30869cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 30879cf514ccSChristoph Hellwig 30882282cd2cSKinglong Mee 30892282cd2cSKinglong Mee static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) 30902282cd2cSKinglong Mee { 30912282cd2cSKinglong Mee return (op_encode_hdr_size + 3) * sizeof(__be32); 30922282cd2cSKinglong Mee } 30932282cd2cSKinglong Mee 309423e50fe3SFrank van der Linden static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp, 309523e50fe3SFrank van der Linden struct nfsd4_op *op) 309623e50fe3SFrank van der Linden { 309723e50fe3SFrank van der Linden u32 maxcount, rlen; 309823e50fe3SFrank van der Linden 309923e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 310023e50fe3SFrank van der Linden rlen = min_t(u32, XATTR_SIZE_MAX, maxcount); 310123e50fe3SFrank van der Linden 310223e50fe3SFrank van der Linden return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); 310323e50fe3SFrank van der Linden } 310423e50fe3SFrank van der Linden 310523e50fe3SFrank van der Linden static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp, 310623e50fe3SFrank van der Linden struct nfsd4_op *op) 310723e50fe3SFrank van der Linden { 310823e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 310923e50fe3SFrank van der Linden * sizeof(__be32); 311023e50fe3SFrank van der Linden } 311123e50fe3SFrank van der Linden static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp, 311223e50fe3SFrank van der Linden struct nfsd4_op *op) 311323e50fe3SFrank van der Linden { 311423e50fe3SFrank van der Linden u32 maxcount, rlen; 311523e50fe3SFrank van der Linden 311623e50fe3SFrank van der Linden maxcount = svc_max_payload(rqstp); 311723e50fe3SFrank van der Linden rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount); 311823e50fe3SFrank van der Linden 311923e50fe3SFrank van der Linden return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); 312023e50fe3SFrank van der Linden } 312123e50fe3SFrank van der Linden 312223e50fe3SFrank van der Linden static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp, 312323e50fe3SFrank van der Linden struct nfsd4_op *op) 312423e50fe3SFrank van der Linden { 312523e50fe3SFrank van der Linden return (op_encode_hdr_size + op_encode_change_info_maxsz) 312623e50fe3SFrank van der Linden * sizeof(__be32); 312723e50fe3SFrank van der Linden } 312823e50fe3SFrank van der Linden 312923e50fe3SFrank van der Linden 3130bb2a8b0cSChristoph Hellwig static const struct nfsd4_operation nfsd4_ops[] = { 3131b591480bSJ.Bruce Fields [OP_ACCESS] = { 3132eb69853dSChristoph Hellwig .op_func = nfsd4_access, 3133b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 31341c122638SChristoph Hellwig .op_rsize_bop = nfsd4_access_rsize, 3135b591480bSJ.Bruce Fields }, 3136b591480bSJ.Bruce Fields [OP_CLOSE] = { 3137eb69853dSChristoph Hellwig .op_func = nfsd4_close, 313858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3139b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 31401c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 314157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_closestateid, 3142b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_closestateid, 3143b591480bSJ.Bruce Fields }, 3144b591480bSJ.Bruce Fields [OP_COMMIT] = { 3145eb69853dSChristoph Hellwig .op_func = nfsd4_commit, 314658e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3147b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 31481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_commit_rsize, 3149b591480bSJ.Bruce Fields }, 3150b591480bSJ.Bruce Fields [OP_CREATE] = { 3151eb69853dSChristoph Hellwig .op_func = nfsd4_create, 3152d1471053STigran Mkrtchyan .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, 3153b001a1b6SBenny Halevy .op_name = "OP_CREATE", 31541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_rsize, 3155b591480bSJ.Bruce Fields }, 3156b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 3157eb69853dSChristoph Hellwig .op_func = nfsd4_delegreturn, 315858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3159b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 316058e7b33aSMi Jinlong .op_rsize_bop = nfsd4_only_status_rsize, 316157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_delegreturnstateid, 3162b591480bSJ.Bruce Fields }, 3163b591480bSJ.Bruce Fields [OP_GETATTR] = { 3164eb69853dSChristoph Hellwig .op_func = nfsd4_getattr, 3165eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 3166b86cef60SJ. Bruce Fields .op_rsize_bop = nfsd4_getattr_rsize, 3167b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 3168b591480bSJ.Bruce Fields }, 3169b591480bSJ.Bruce Fields [OP_GETFH] = { 3170eb69853dSChristoph Hellwig .op_func = nfsd4_getfh, 3171b001a1b6SBenny Halevy .op_name = "OP_GETFH", 31721c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getfh_rsize, 3173b591480bSJ.Bruce Fields }, 3174b591480bSJ.Bruce Fields [OP_LINK] = { 3175eb69853dSChristoph Hellwig .op_func = nfsd4_link, 3176c856694eSJ. Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING 3177c856694eSJ. Bruce Fields | OP_CACHEME, 3178b001a1b6SBenny Halevy .op_name = "OP_LINK", 31791c122638SChristoph Hellwig .op_rsize_bop = nfsd4_link_rsize, 3180b591480bSJ.Bruce Fields }, 3181b591480bSJ.Bruce Fields [OP_LOCK] = { 3182eb69853dSChristoph Hellwig .op_func = nfsd4_lock, 3183b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | 3184b7571e4cSJ. Bruce Fields OP_NONTRIVIAL_ERROR_ENCODE, 3185b001a1b6SBenny Halevy .op_name = "OP_LOCK", 31861c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3187b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_lockstateid, 3188b591480bSJ.Bruce Fields }, 3189b591480bSJ.Bruce Fields [OP_LOCKT] = { 3190eb69853dSChristoph Hellwig .op_func = nfsd4_lockt, 3191b7571e4cSJ. Bruce Fields .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, 3192b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 31931c122638SChristoph Hellwig .op_rsize_bop = nfsd4_lock_rsize, 3194b591480bSJ.Bruce Fields }, 3195b591480bSJ.Bruce Fields [OP_LOCKU] = { 3196eb69853dSChristoph Hellwig .op_func = nfsd4_locku, 319758e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3198b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 31991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 320057832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_lockustateid, 3201b591480bSJ.Bruce Fields }, 3202b591480bSJ.Bruce Fields [OP_LOOKUP] = { 3203eb69853dSChristoph Hellwig .op_func = nfsd4_lookup, 3204d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3205b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 32061c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3207b591480bSJ.Bruce Fields }, 3208b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 3209eb69853dSChristoph Hellwig .op_func = nfsd4_lookupp, 3210d1471053STigran Mkrtchyan .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, 3211b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 32121c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3213b591480bSJ.Bruce Fields }, 3214b591480bSJ.Bruce Fields [OP_NVERIFY] = { 3215eb69853dSChristoph Hellwig .op_func = nfsd4_nverify, 3216b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 32171c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3218b591480bSJ.Bruce Fields }, 3219b591480bSJ.Bruce Fields [OP_OPEN] = { 3220eb69853dSChristoph Hellwig .op_func = nfsd4_open, 322158e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3222b001a1b6SBenny Halevy .op_name = "OP_OPEN", 32231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_open_rsize, 3224b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_openstateid, 3225b591480bSJ.Bruce Fields }, 3226b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 3227eb69853dSChristoph Hellwig .op_func = nfsd4_open_confirm, 322858e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3229b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 32301c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 3231b591480bSJ.Bruce Fields }, 3232b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 3233eb69853dSChristoph Hellwig .op_func = nfsd4_open_downgrade, 323458e7b33aSMi Jinlong .op_flags = OP_MODIFIES_SOMETHING, 3235b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 32361c122638SChristoph Hellwig .op_rsize_bop = nfsd4_status_stateid_rsize, 323757832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_opendowngradestateid, 3238b60e9859SChristoph Hellwig .op_set_currentstateid = nfsd4_set_opendowngradestateid, 3239b591480bSJ.Bruce Fields }, 3240b591480bSJ.Bruce Fields [OP_PUTFH] = { 3241eb69853dSChristoph Hellwig .op_func = nfsd4_putfh, 324268d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 32435b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3244b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 32451c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3246b591480bSJ.Bruce Fields }, 3247eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 3248eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 324968d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 32505b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3251b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 32521c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3253eeac294eSJ.Bruce Fields }, 3254b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 3255eb69853dSChristoph Hellwig .op_func = nfsd4_putrootfh, 325668d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 32575b648699SJ. Bruce Fields | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, 3258b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 32591c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3260b591480bSJ.Bruce Fields }, 3261b591480bSJ.Bruce Fields [OP_READ] = { 3262eb69853dSChristoph Hellwig .op_func = nfsd4_read, 326334b1744cSJ. Bruce Fields .op_release = nfsd4_read_release, 3264b001a1b6SBenny Halevy .op_name = "OP_READ", 32651c122638SChristoph Hellwig .op_rsize_bop = nfsd4_read_rsize, 326657832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_readstateid, 3267b591480bSJ.Bruce Fields }, 3268b591480bSJ.Bruce Fields [OP_READDIR] = { 3269eb69853dSChristoph Hellwig .op_func = nfsd4_readdir, 3270b001a1b6SBenny Halevy .op_name = "OP_READDIR", 32711c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readdir_rsize, 3272b591480bSJ.Bruce Fields }, 3273b591480bSJ.Bruce Fields [OP_READLINK] = { 3274eb69853dSChristoph Hellwig .op_func = nfsd4_readlink, 3275b001a1b6SBenny Halevy .op_name = "OP_READLINK", 32761c122638SChristoph Hellwig .op_rsize_bop = nfsd4_readlink_rsize, 3277b591480bSJ.Bruce Fields }, 3278b591480bSJ.Bruce Fields [OP_REMOVE] = { 3279eb69853dSChristoph Hellwig .op_func = nfsd4_remove, 3280c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3281b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 32821c122638SChristoph Hellwig .op_rsize_bop = nfsd4_remove_rsize, 3283b591480bSJ.Bruce Fields }, 3284b591480bSJ.Bruce Fields [OP_RENAME] = { 3285eb69853dSChristoph Hellwig .op_func = nfsd4_rename, 3286c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 328758e7b33aSMi Jinlong .op_name = "OP_RENAME", 32881c122638SChristoph Hellwig .op_rsize_bop = nfsd4_rename_rsize, 3289b591480bSJ.Bruce Fields }, 3290b591480bSJ.Bruce Fields [OP_RENEW] = { 3291eb69853dSChristoph Hellwig .op_func = nfsd4_renew, 329258e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 329358e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3294b001a1b6SBenny Halevy .op_name = "OP_RENEW", 32951c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 329658e7b33aSMi Jinlong 3297b591480bSJ.Bruce Fields }, 3298b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 3299eb69853dSChristoph Hellwig .op_func = nfsd4_restorefh, 330068d93184SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 330158e7b33aSMi Jinlong | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, 3302b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 33031c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3304b591480bSJ.Bruce Fields }, 3305b591480bSJ.Bruce Fields [OP_SAVEFH] = { 3306eb69853dSChristoph Hellwig .op_func = nfsd4_savefh, 330758e7b33aSMi Jinlong .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, 3308b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 33091c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3310b591480bSJ.Bruce Fields }, 3311dcb488a3SAndy Adamson [OP_SECINFO] = { 3312eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo, 331334b1744cSJ. Bruce Fields .op_release = nfsd4_secinfo_release, 331468d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 3315b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 33161c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 3317dcb488a3SAndy Adamson }, 3318b591480bSJ.Bruce Fields [OP_SETATTR] = { 3319eb69853dSChristoph Hellwig .op_func = nfsd4_setattr, 3320b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 3321b7571e4cSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME 3322b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 33231c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setattr_rsize, 332457832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_setattrstateid, 3325b591480bSJ.Bruce Fields }, 3326b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 3327eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid, 332858e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3329b7571e4cSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME 3330b7571e4cSJ. Bruce Fields | OP_NONTRIVIAL_ERROR_ENCODE, 3331b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 33321c122638SChristoph Hellwig .op_rsize_bop = nfsd4_setclientid_rsize, 3333b591480bSJ.Bruce Fields }, 3334b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 3335eb69853dSChristoph Hellwig .op_func = nfsd4_setclientid_confirm, 333658e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 3337c856694eSJ. Bruce Fields | OP_MODIFIES_SOMETHING | OP_CACHEME, 3338b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 33391c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3340b591480bSJ.Bruce Fields }, 3341b591480bSJ.Bruce Fields [OP_VERIFY] = { 3342eb69853dSChristoph Hellwig .op_func = nfsd4_verify, 3343b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 33441c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3345b591480bSJ.Bruce Fields }, 3346b591480bSJ.Bruce Fields [OP_WRITE] = { 3347eb69853dSChristoph Hellwig .op_func = nfsd4_write, 3348c856694eSJ. Bruce Fields .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 3349b001a1b6SBenny Halevy .op_name = "OP_WRITE", 33501c122638SChristoph Hellwig .op_rsize_bop = nfsd4_write_rsize, 335157832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_writestateid, 3352b591480bSJ.Bruce Fields }, 3353b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 3354eb69853dSChristoph Hellwig .op_func = nfsd4_release_lockowner, 335558e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS 335658e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3357b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 33581c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3359b591480bSJ.Bruce Fields }, 3360069b6ad4SAndy Adamson 3361069b6ad4SAndy Adamson /* NFSv4.1 operations */ 3362069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 3363eb69853dSChristoph Hellwig .op_func = nfsd4_exchange_id, 336458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 336558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3366069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 33671c122638SChristoph Hellwig .op_rsize_bop = nfsd4_exchange_id_rsize, 3368069b6ad4SAndy Adamson }, 3369cb73a9f4SJ. Bruce Fields [OP_BACKCHANNEL_CTL] = { 3370eb69853dSChristoph Hellwig .op_func = nfsd4_backchannel_ctl, 3371cb73a9f4SJ. Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3372cb73a9f4SJ. Bruce Fields .op_name = "OP_BACKCHANNEL_CTL", 33731c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3374cb73a9f4SJ. Bruce Fields }, 33751d1bc8f2SJ. Bruce Fields [OP_BIND_CONN_TO_SESSION] = { 3376eb69853dSChristoph Hellwig .op_func = nfsd4_bind_conn_to_session, 337758e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 337858e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 33791d1bc8f2SJ. Bruce Fields .op_name = "OP_BIND_CONN_TO_SESSION", 33801c122638SChristoph Hellwig .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, 33811d1bc8f2SJ. Bruce Fields }, 3382069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 3383eb69853dSChristoph Hellwig .op_func = nfsd4_create_session, 338458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 338558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3386069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 33871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_create_session_rsize, 3388069b6ad4SAndy Adamson }, 3389069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 3390eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_session, 339158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 339258e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3393069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 33941c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3395069b6ad4SAndy Adamson }, 3396069b6ad4SAndy Adamson [OP_SEQUENCE] = { 3397eb69853dSChristoph Hellwig .op_func = nfsd4_sequence, 3398f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 3399069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 34001c122638SChristoph Hellwig .op_rsize_bop = nfsd4_sequence_rsize, 3401069b6ad4SAndy Adamson }, 3402094b5d74SBenny Halevy [OP_DESTROY_CLIENTID] = { 3403eb69853dSChristoph Hellwig .op_func = nfsd4_destroy_clientid, 340458e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP 340558e7b33aSMi Jinlong | OP_MODIFIES_SOMETHING, 3406094b5d74SBenny Halevy .op_name = "OP_DESTROY_CLIENTID", 34071c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3408094b5d74SBenny Halevy }, 34094dc6ec00SJ. Bruce Fields [OP_RECLAIM_COMPLETE] = { 3410eb69853dSChristoph Hellwig .op_func = nfsd4_reclaim_complete, 341158e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 34124dc6ec00SJ. Bruce Fields .op_name = "OP_RECLAIM_COMPLETE", 34131c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 34144dc6ec00SJ. Bruce Fields }, 341504f4ad16SJ. Bruce Fields [OP_SECINFO_NO_NAME] = { 3416eb69853dSChristoph Hellwig .op_func = nfsd4_secinfo_no_name, 3417ec572b9eSEryu Guan .op_release = nfsd4_secinfo_no_name_release, 341868d93184SJ. Bruce Fields .op_flags = OP_HANDLES_WRONGSEC, 341904f4ad16SJ. Bruce Fields .op_name = "OP_SECINFO_NO_NAME", 34201c122638SChristoph Hellwig .op_rsize_bop = nfsd4_secinfo_rsize, 342104f4ad16SJ. Bruce Fields }, 342217456804SBryan Schumaker [OP_TEST_STATEID] = { 3423eb69853dSChristoph Hellwig .op_func = nfsd4_test_stateid, 342417456804SBryan Schumaker .op_flags = ALLOWED_WITHOUT_FH, 342517456804SBryan Schumaker .op_name = "OP_TEST_STATEID", 34261c122638SChristoph Hellwig .op_rsize_bop = nfsd4_test_stateid_rsize, 342717456804SBryan Schumaker }, 3428e1ca12dfSBryan Schumaker [OP_FREE_STATEID] = { 3429eb69853dSChristoph Hellwig .op_func = nfsd4_free_stateid, 343058e7b33aSMi Jinlong .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, 3431e1ca12dfSBryan Schumaker .op_name = "OP_FREE_STATEID", 343257832e7bSChristoph Hellwig .op_get_currentstateid = nfsd4_get_freestateid, 34331c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3434e1ca12dfSBryan Schumaker }, 34359cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 34369cf514ccSChristoph Hellwig [OP_GETDEVICEINFO] = { 3437eb69853dSChristoph Hellwig .op_func = nfsd4_getdeviceinfo, 343834b1744cSJ. Bruce Fields .op_release = nfsd4_getdeviceinfo_release, 34399cf514ccSChristoph Hellwig .op_flags = ALLOWED_WITHOUT_FH, 34409cf514ccSChristoph Hellwig .op_name = "OP_GETDEVICEINFO", 34411c122638SChristoph Hellwig .op_rsize_bop = nfsd4_getdeviceinfo_rsize, 34429cf514ccSChristoph Hellwig }, 34439cf514ccSChristoph Hellwig [OP_LAYOUTGET] = { 3444eb69853dSChristoph Hellwig .op_func = nfsd4_layoutget, 344534b1744cSJ. Bruce Fields .op_release = nfsd4_layoutget_release, 34469cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 34479cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTGET", 34481c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutget_rsize, 34499cf514ccSChristoph Hellwig }, 34509cf514ccSChristoph Hellwig [OP_LAYOUTCOMMIT] = { 3451eb69853dSChristoph Hellwig .op_func = nfsd4_layoutcommit, 34529cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 34539cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTCOMMIT", 34541c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutcommit_rsize, 34559cf514ccSChristoph Hellwig }, 34569cf514ccSChristoph Hellwig [OP_LAYOUTRETURN] = { 3457eb69853dSChristoph Hellwig .op_func = nfsd4_layoutreturn, 34589cf514ccSChristoph Hellwig .op_flags = OP_MODIFIES_SOMETHING, 34599cf514ccSChristoph Hellwig .op_name = "OP_LAYOUTRETURN", 34601c122638SChristoph Hellwig .op_rsize_bop = nfsd4_layoutreturn_rsize, 34619cf514ccSChristoph Hellwig }, 34629cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 346324bab491SAnna Schumaker 346424bab491SAnna Schumaker /* NFSv4.2 operations */ 346595d871f0SAnna Schumaker [OP_ALLOCATE] = { 3466eb69853dSChristoph Hellwig .op_func = nfsd4_allocate, 346703b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 346895d871f0SAnna Schumaker .op_name = "OP_ALLOCATE", 34691c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 347095d871f0SAnna Schumaker }, 3471b0cb9085SAnna Schumaker [OP_DEALLOCATE] = { 3472eb69853dSChristoph Hellwig .op_func = nfsd4_deallocate, 347303b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3474b0cb9085SAnna Schumaker .op_name = "OP_DEALLOCATE", 34751c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3476b0cb9085SAnna Schumaker }, 3477ffa0160aSChristoph Hellwig [OP_CLONE] = { 3478eb69853dSChristoph Hellwig .op_func = nfsd4_clone, 347903b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3480ffa0160aSChristoph Hellwig .op_name = "OP_CLONE", 34811c122638SChristoph Hellwig .op_rsize_bop = nfsd4_only_status_rsize, 3482ffa0160aSChristoph Hellwig }, 348329ae7f9dSAnna Schumaker [OP_COPY] = { 3484eb69853dSChristoph Hellwig .op_func = nfsd4_copy, 348503b31f48SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 348629ae7f9dSAnna Schumaker .op_name = "OP_COPY", 34871c122638SChristoph Hellwig .op_rsize_bop = nfsd4_copy_rsize, 348829ae7f9dSAnna Schumaker }, 3489528b8493SAnna Schumaker [OP_READ_PLUS] = { 3490528b8493SAnna Schumaker .op_func = nfsd4_read, 3491528b8493SAnna Schumaker .op_release = nfsd4_read_release, 3492528b8493SAnna Schumaker .op_name = "OP_READ_PLUS", 3493528b8493SAnna Schumaker .op_rsize_bop = nfsd4_read_plus_rsize, 3494528b8493SAnna Schumaker .op_get_currentstateid = nfsd4_get_readstateid, 3495528b8493SAnna Schumaker }, 349624bab491SAnna Schumaker [OP_SEEK] = { 3497eb69853dSChristoph Hellwig .op_func = nfsd4_seek, 349824bab491SAnna Schumaker .op_name = "OP_SEEK", 34991c122638SChristoph Hellwig .op_rsize_bop = nfsd4_seek_rsize, 350024bab491SAnna Schumaker }, 35016308bc98SOlga Kornievskaia [OP_OFFLOAD_STATUS] = { 35026308bc98SOlga Kornievskaia .op_func = nfsd4_offload_status, 35036308bc98SOlga Kornievskaia .op_name = "OP_OFFLOAD_STATUS", 35046308bc98SOlga Kornievskaia .op_rsize_bop = nfsd4_offload_status_rsize, 35056308bc98SOlga Kornievskaia }, 3506885e2bf3SOlga Kornievskaia [OP_OFFLOAD_CANCEL] = { 3507885e2bf3SOlga Kornievskaia .op_func = nfsd4_offload_cancel, 3508885e2bf3SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 3509885e2bf3SOlga Kornievskaia .op_name = "OP_OFFLOAD_CANCEL", 3510885e2bf3SOlga Kornievskaia .op_rsize_bop = nfsd4_only_status_rsize, 3511885e2bf3SOlga Kornievskaia }, 351251911868SOlga Kornievskaia [OP_COPY_NOTIFY] = { 351351911868SOlga Kornievskaia .op_func = nfsd4_copy_notify, 351451911868SOlga Kornievskaia .op_flags = OP_MODIFIES_SOMETHING, 351551911868SOlga Kornievskaia .op_name = "OP_COPY_NOTIFY", 351651911868SOlga Kornievskaia .op_rsize_bop = nfsd4_copy_notify_rsize, 351751911868SOlga Kornievskaia }, 351823e50fe3SFrank van der Linden [OP_GETXATTR] = { 351923e50fe3SFrank van der Linden .op_func = nfsd4_getxattr, 352023e50fe3SFrank van der Linden .op_name = "OP_GETXATTR", 352123e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_getxattr_rsize, 352223e50fe3SFrank van der Linden }, 352323e50fe3SFrank van der Linden [OP_SETXATTR] = { 352423e50fe3SFrank van der Linden .op_func = nfsd4_setxattr, 352523e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 352623e50fe3SFrank van der Linden .op_name = "OP_SETXATTR", 352723e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_setxattr_rsize, 352823e50fe3SFrank van der Linden }, 352923e50fe3SFrank van der Linden [OP_LISTXATTRS] = { 353023e50fe3SFrank van der Linden .op_func = nfsd4_listxattrs, 353123e50fe3SFrank van der Linden .op_name = "OP_LISTXATTRS", 353223e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_listxattrs_rsize, 353323e50fe3SFrank van der Linden }, 353423e50fe3SFrank van der Linden [OP_REMOVEXATTR] = { 353523e50fe3SFrank van der Linden .op_func = nfsd4_removexattr, 353623e50fe3SFrank van der Linden .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 353723e50fe3SFrank van der Linden .op_name = "OP_REMOVEXATTR", 353823e50fe3SFrank van der Linden .op_rsize_bop = nfsd4_removexattr_rsize, 353923e50fe3SFrank van der Linden }, 3540b591480bSJ.Bruce Fields }; 3541b591480bSJ.Bruce Fields 3542ed941643SAndrew Elble /** 3543ed941643SAndrew Elble * nfsd4_spo_must_allow - Determine if the compound op contains an 3544ed941643SAndrew Elble * operation that is allowed to be sent with machine credentials 3545ed941643SAndrew Elble * 3546ed941643SAndrew Elble * @rqstp: a pointer to the struct svc_rqst 3547ed941643SAndrew Elble * 3548ed941643SAndrew Elble * Checks to see if the compound contains a spo_must_allow op 3549ed941643SAndrew Elble * and confirms that it was sent with the proper machine creds. 3550ed941643SAndrew Elble */ 3551ed941643SAndrew Elble 3552ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 3553ed941643SAndrew Elble { 3554ed941643SAndrew Elble struct nfsd4_compoundres *resp = rqstp->rq_resp; 3555ed941643SAndrew Elble struct nfsd4_compoundargs *argp = rqstp->rq_argp; 3556e34c0ce9SColin Ian King struct nfsd4_op *this; 3557ed941643SAndrew Elble struct nfsd4_compound_state *cstate = &resp->cstate; 3558ed941643SAndrew Elble struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; 3559ed941643SAndrew Elble u32 opiter; 3560ed941643SAndrew Elble 3561ed941643SAndrew Elble if (!cstate->minorversion) 3562ed941643SAndrew Elble return false; 3563ed941643SAndrew Elble 356444b49aa6SZheng Bin if (cstate->spo_must_allowed) 3565ed941643SAndrew Elble return true; 3566ed941643SAndrew Elble 3567ed941643SAndrew Elble opiter = resp->opcnt; 3568ed941643SAndrew Elble while (opiter < argp->opcnt) { 3569ed941643SAndrew Elble this = &argp->ops[opiter++]; 3570ed941643SAndrew Elble if (test_bit(this->opnum, allow->u.longs) && 3571ed941643SAndrew Elble cstate->clp->cl_mach_cred && 3572ed941643SAndrew Elble nfsd4_mach_creds_match(cstate->clp, rqstp)) { 3573ed941643SAndrew Elble cstate->spo_must_allowed = true; 3574ed941643SAndrew Elble return true; 3575ed941643SAndrew Elble } 3576ed941643SAndrew Elble } 3577ed941643SAndrew Elble cstate->spo_must_allowed = false; 3578ed941643SAndrew Elble return false; 3579ed941643SAndrew Elble } 3580ed941643SAndrew Elble 35814f0cefbfSJ. Bruce Fields int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 35824f0cefbfSJ. Bruce Fields { 358305b7278dSOlga Kornievskaia if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) 35844f0cefbfSJ. Bruce Fields return op_encode_hdr_size * sizeof(__be32); 35852282cd2cSKinglong Mee 35862282cd2cSKinglong Mee BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 35872282cd2cSKinglong Mee return OPDESC(op)->op_rsize_bop(rqstp, op); 35884f0cefbfSJ. Bruce Fields } 35894f0cefbfSJ. Bruce Fields 359007d1f802SJ. Bruce Fields void warn_on_nonidempotent_op(struct nfsd4_op *op) 359107d1f802SJ. Bruce Fields { 359207d1f802SJ. Bruce Fields if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { 35933a237b4aSChuck Lever pr_err("unable to encode reply to nonidempotent op %u (%s)\n", 359407d1f802SJ. Bruce Fields op->opnum, nfsd4_op_name(op->opnum)); 359507d1f802SJ. Bruce Fields WARN_ON_ONCE(1); 359607d1f802SJ. Bruce Fields } 359707d1f802SJ. Bruce Fields } 359807d1f802SJ. Bruce Fields 3599f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 3600b001a1b6SBenny Halevy { 3601b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 3602b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 3603b001a1b6SBenny Halevy return "unknown_operation"; 3604b001a1b6SBenny Halevy } 3605b001a1b6SBenny Halevy 3606860bda29SChristoph Hellwig static const struct svc_procedure nfsd_procedures4[2] = { 36070a93a47fSYu Zhiguo [NFSPROC4_NULL] = { 3608f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_null, 3609788f7183SChuck Lever .pc_decode = nfssvc_decode_voidarg, 3610788f7183SChuck Lever .pc_encode = nfssvc_encode_voidres, 3611788f7183SChuck Lever .pc_argsize = sizeof(struct nfsd_voidargs), 3612788f7183SChuck Lever .pc_ressize = sizeof(struct nfsd_voidres), 36130a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 36140a93a47fSYu Zhiguo .pc_xdrressize = 1, 36152289e87bSChuck Lever .pc_name = "NULL", 36160a93a47fSYu Zhiguo }, 36170a93a47fSYu Zhiguo [NFSPROC4_COMPOUND] = { 3618f7235b6bSChristoph Hellwig .pc_func = nfsd4_proc_compound, 3619026fec7eSChristoph Hellwig .pc_decode = nfs4svc_decode_compoundargs, 362063f8de37SChristoph Hellwig .pc_encode = nfs4svc_encode_compoundres, 36210a93a47fSYu Zhiguo .pc_argsize = sizeof(struct nfsd4_compoundargs), 36220a93a47fSYu Zhiguo .pc_ressize = sizeof(struct nfsd4_compoundres), 36233e98abffSJ. Bruce Fields .pc_release = nfsd4_release_compoundargs, 36240a93a47fSYu Zhiguo .pc_cachetype = RC_NOCACHE, 36250a93a47fSYu Zhiguo .pc_xdrressize = NFSD_BUFSIZE/4, 36262289e87bSChuck Lever .pc_name = "COMPOUND", 36270a93a47fSYu Zhiguo }, 36281da177e4SLinus Torvalds }; 36291da177e4SLinus Torvalds 36307fd38af9SChristoph Hellwig static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; 3631e9679189SChristoph Hellwig const struct svc_version nfsd_version4 = { 36321da177e4SLinus Torvalds .vs_vers = 4, 36331da177e4SLinus Torvalds .vs_nproc = 2, 36341da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 36357fd38af9SChristoph Hellwig .vs_count = nfsd_count3, 36361da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 36371da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 363805a45a2dSJeff Layton .vs_rpcb_optnl = true, 36395283b03eSJeff Layton .vs_need_cong_ctrl = true, 36401da177e4SLinus Torvalds }; 3641