Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Server-side procedures for NFSv4. |
| 3 | * |
| 4 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Kendrick Smith <kmsmith@umich.edu> |
| 8 | * Andy Adamson <andros@umich.edu> |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. Neither the name of the University nor the names of its |
| 20 | * contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 35 | #include <linux/fs_struct.h> |
NeilBrown | 7e06b7f | 2005-06-23 22:03:13 -0700 | [diff] [blame] | 36 | #include <linux/file.h> |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 37 | #include <linux/falloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 39 | #include <linux/kthread.h> |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 40 | #include <linux/sunrpc/addr.h> |
Dai Ngo | 0cfcd40 | 2020-10-18 23:42:49 -0400 | [diff] [blame] | 41 | #include <linux/nfs_ssc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 43 | #include "idmap.h" |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 44 | #include "cache.h" |
| 45 | #include "xdr4.h" |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame] | 46 | #include "vfs.h" |
Tigran Mkrtchyan | 8b70484 | 2012-02-13 22:55:24 +0100 | [diff] [blame] | 47 | #include "current_stateid.h" |
Stanislav Kinsbursky | 3320fef19 | 2012-11-14 18:22:07 +0300 | [diff] [blame] | 48 | #include "netns.h" |
Christoph Hellwig | 4ac7249 | 2013-12-20 05:16:55 -0800 | [diff] [blame] | 49 | #include "acl.h" |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 50 | #include "pnfs.h" |
Christoph Hellwig | 31ef83d | 2014-08-16 19:02:22 -0500 | [diff] [blame] | 51 | #include "trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Chuck Lever | d6c9e43 | 2020-12-18 12:28:23 -0500 | [diff] [blame] | 53 | static bool inter_copy_offload_enable; |
| 54 | module_param(inter_copy_offload_enable, bool, 0644); |
| 55 | MODULE_PARM_DESC(inter_copy_offload_enable, |
| 56 | "Enable inter server to server copy offload. Default: false"); |
| 57 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 58 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 59 | #include <linux/security.h> |
| 60 | |
| 61 | static inline void |
| 62 | nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) |
| 63 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 64 | struct inode *inode = d_inode(resfh->fh_dentry); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 65 | int status; |
| 66 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 67 | inode_lock(inode); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 68 | status = security_inode_setsecctx(resfh->fh_dentry, |
| 69 | label->data, label->len); |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 70 | inode_unlock(inode); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 71 | |
| 72 | if (status) |
| 73 | /* |
| 74 | * XXX: We should really fail the whole open, but we may |
| 75 | * already have created a new file, so it may be too |
| 76 | * late. For now this seems the least of evils: |
| 77 | */ |
| 78 | bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 79 | |
| 80 | return; |
| 81 | } |
| 82 | #else |
| 83 | static inline void |
| 84 | nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) |
| 85 | { } |
| 86 | #endif |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 89 | |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 90 | static u32 nfsd_attrmask[] = { |
| 91 | NFSD_WRITEABLE_ATTRS_WORD0, |
| 92 | NFSD_WRITEABLE_ATTRS_WORD1, |
| 93 | NFSD_WRITEABLE_ATTRS_WORD2 |
| 94 | }; |
| 95 | |
| 96 | static u32 nfsd41_ex_attrmask[] = { |
| 97 | NFSD_SUPPATTR_EXCLCREAT_WORD0, |
| 98 | NFSD_SUPPATTR_EXCLCREAT_WORD1, |
| 99 | NFSD_SUPPATTR_EXCLCREAT_WORD2 |
| 100 | }; |
| 101 | |
| 102 | static __be32 |
| 103 | check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 104 | u32 *bmval, u32 *writable) |
| 105 | { |
| 106 | struct dentry *dentry = cstate->current_fh.fh_dentry; |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 107 | struct svc_export *exp = cstate->current_fh.fh_export; |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 108 | |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 109 | if (!nfsd_attrs_supported(cstate->minorversion, bmval)) |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 110 | return nfserr_attrnotsupp; |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 111 | if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) |
| 112 | return nfserr_attrnotsupp; |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 113 | if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && |
| 114 | !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) |
| 115 | return nfserr_attrnotsupp; |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 116 | if (writable && !bmval_is_subset(bmval, writable)) |
| 117 | return nfserr_inval; |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 118 | if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && |
| 119 | (bmval[1] & FATTR4_WORD1_MODE)) |
| 120 | return nfserr_inval; |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 121 | return nfs_ok; |
| 122 | } |
| 123 | |
| 124 | static __be32 |
| 125 | nfsd4_check_open_attributes(struct svc_rqst *rqstp, |
| 126 | struct nfsd4_compound_state *cstate, struct nfsd4_open *open) |
| 127 | { |
| 128 | __be32 status = nfs_ok; |
| 129 | |
| 130 | if (open->op_create == NFS4_OPEN_CREATE) { |
| 131 | if (open->op_createmode == NFS4_CREATE_UNCHECKED |
| 132 | || open->op_createmode == NFS4_CREATE_GUARDED) |
| 133 | status = check_attr_support(rqstp, cstate, |
| 134 | open->op_bmval, nfsd_attrmask); |
| 135 | else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 136 | status = check_attr_support(rqstp, cstate, |
| 137 | open->op_bmval, nfsd41_ex_attrmask); |
| 138 | } |
| 139 | |
| 140 | return status; |
| 141 | } |
| 142 | |
Yu Zhiguo | 9208faf | 2009-07-06 17:24:16 +0800 | [diff] [blame] | 143 | static int |
| 144 | is_create_with_attrs(struct nfsd4_open *open) |
| 145 | { |
| 146 | return open->op_create == NFS4_OPEN_CREATE |
| 147 | && (open->op_createmode == NFS4_CREATE_UNCHECKED |
| 148 | || open->op_createmode == NFS4_CREATE_GUARDED |
| 149 | || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * if error occurs when setting the acl, just clear the acl bit |
| 154 | * in the returned attr bitmap. |
| 155 | */ |
| 156 | static void |
| 157 | do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, |
| 158 | struct nfs4_acl *acl, u32 *bmval) |
| 159 | { |
| 160 | __be32 status; |
| 161 | |
| 162 | status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); |
| 163 | if (status) |
| 164 | /* |
| 165 | * We should probably fail the whole open at this point, |
| 166 | * but we've already created the file, so it's too late; |
| 167 | * So this seems the least of evils: |
| 168 | */ |
| 169 | bmval[0] &= ~FATTR4_WORD0_ACL; |
| 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | static inline void |
| 173 | fh_dup2(struct svc_fh *dst, struct svc_fh *src) |
| 174 | { |
| 175 | fh_put(dst); |
| 176 | dget(src->fh_dentry); |
| 177 | if (src->fh_export) |
Kinglong Mee | bf18f16 | 2014-06-10 22:06:44 +0800 | [diff] [blame] | 178 | exp_get(src->fh_export); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | *dst = *src; |
| 180 | } |
| 181 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 182 | static __be32 |
J. Bruce Fields | dc730e1 | 2006-10-17 00:10:13 -0700 | [diff] [blame] | 183 | do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 185 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | if (open->op_truncate && |
| 188 | !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) |
| 189 | return nfserr_inval; |
| 190 | |
J. Bruce Fields | a043226 | 2011-08-25 10:48:39 -0400 | [diff] [blame] | 191 | accmode |= NFSD_MAY_READ_IF_EXEC; |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | if (open->op_share_access & NFS4_SHARE_ACCESS_READ) |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 194 | accmode |= NFSD_MAY_READ; |
J. Bruce Fields | 9801d8a | 2006-10-17 00:10:14 -0700 | [diff] [blame] | 195 | if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 196 | accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); |
J. Bruce Fields | 57ecb34 | 2009-12-01 19:42:57 -0500 | [diff] [blame] | 197 | if (open->op_share_deny & NFS4_SHARE_DENY_READ) |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 198 | accmode |= NFSD_MAY_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | status = fh_verify(rqstp, current_fh, S_IFREG, accmode); |
| 201 | |
| 202 | return status; |
| 203 | } |
| 204 | |
J. Bruce Fields | aadab6c | 2011-08-15 16:55:02 -0400 | [diff] [blame] | 205 | static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) |
| 206 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 207 | umode_t mode = d_inode(fh->fh_dentry)->i_mode; |
J. Bruce Fields | aadab6c | 2011-08-15 16:55:02 -0400 | [diff] [blame] | 208 | |
| 209 | if (S_ISREG(mode)) |
| 210 | return nfs_ok; |
| 211 | if (S_ISDIR(mode)) |
| 212 | return nfserr_isdir; |
| 213 | /* |
| 214 | * Using err_symlink as our catch-all case may look odd; but |
| 215 | * there's no other obvious error for this case in 4.0, and we |
| 216 | * happen to know that it will cause the linux v4 client to do |
| 217 | * the right thing on attempts to open something other than a |
| 218 | * regular file. |
| 219 | */ |
| 220 | return nfserr_symlink; |
| 221 | } |
| 222 | |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 223 | static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 225 | if (nfsd4_has_session(cstate)) |
| 226 | return; |
| 227 | fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, |
| 228 | &resfh->fh_handle); |
| 229 | } |
| 230 | |
| 231 | static __be32 |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 232 | do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 233 | { |
| 234 | struct svc_fh *current_fh = &cstate->current_fh; |
Neil Brown | 7007c90 | 2012-12-07 15:40:55 -0500 | [diff] [blame] | 235 | int accmode; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 236 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 238 | *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
| 239 | if (!*resfh) |
J. Bruce Fields | 59deeb9 | 2012-01-27 16:49:55 -0500 | [diff] [blame] | 240 | return nfserr_jukebox; |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 241 | fh_init(*resfh, NFS4_FHSIZE); |
zhengbin | 500c2481 | 2019-12-25 11:19:35 +0800 | [diff] [blame] | 242 | open->op_truncate = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | if (open->op_create) { |
Benny Halevy | 79fb54a | 2009-04-03 08:29:17 +0300 | [diff] [blame] | 245 | /* FIXME: check session persistence and pnfs flags. |
| 246 | * The nfsv4.1 spec requires the following semantics: |
| 247 | * |
| 248 | * Persistent | pNFS | Server REQUIRED | Client Allowed |
| 249 | * Reply Cache | server | | |
| 250 | * -------------+--------+-----------------+-------------------- |
| 251 | * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 |
| 252 | * | | | (SHOULD) |
| 253 | * | | and EXCLUSIVE4 | or EXCLUSIVE4 |
| 254 | * | | | (SHOULD NOT) |
| 255 | * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 |
| 256 | * yes | no | GUARDED4 | GUARDED4 |
| 257 | * yes | yes | GUARDED4 | GUARDED4 |
| 258 | */ |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | /* |
| 261 | * Note: create modes (UNCHECKED,GUARDED...) are the same |
Mi Jinlong | ac6721a | 2011-04-20 17:06:25 +0800 | [diff] [blame] | 262 | * in NFSv4 as in v3 except EXCLUSIVE4_1. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | */ |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 264 | current->fs->umask = open->op_umask; |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 265 | status = do_nfsd_create(rqstp, current_fh, open->op_fname, |
| 266 | open->op_fnamelen, &open->op_iattr, |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 267 | *resfh, open->op_createmode, |
Jeff Layton | 749997e | 2007-07-31 00:37:51 -0700 | [diff] [blame] | 268 | (u32 *)open->op_verf.data, |
J. Bruce Fields | 856121b | 2011-10-13 11:37:11 -0400 | [diff] [blame] | 269 | &open->op_truncate, &open->op_created); |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 270 | current->fs->umask = 0; |
Jeff Layton | 749997e | 2007-07-31 00:37:51 -0700 | [diff] [blame] | 271 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 272 | if (!status && open->op_label.len) |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 273 | nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 274 | |
J. Bruce Fields | 99f8872 | 2009-02-02 15:12:27 -0500 | [diff] [blame] | 275 | /* |
Kinglong Mee | ead8fb8 | 2015-07-30 21:55:02 +0800 | [diff] [blame] | 276 | * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 |
| 277 | * use the returned bitmask to indicate which attributes |
| 278 | * we used to store the verifier: |
Jeff Layton | 749997e | 2007-07-31 00:37:51 -0700 | [diff] [blame] | 279 | */ |
Kinglong Mee | ead8fb8 | 2015-07-30 21:55:02 +0800 | [diff] [blame] | 280 | if (nfsd_create_is_exclusive(open->op_createmode) && status == 0) |
| 281 | open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | |
| 282 | FATTR4_WORD1_TIME_MODIFY); |
J. Bruce Fields | 4335723 | 2014-01-24 18:04:40 -0500 | [diff] [blame] | 283 | } else |
| 284 | /* |
| 285 | * Note this may exit with the parent still locked. |
| 286 | * We will hold the lock until nfsd4_open's final |
| 287 | * lookup, to prevent renames or unlinks until we've had |
| 288 | * a chance to an acquire a delegation if appropriate. |
| 289 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | status = nfsd_lookup(rqstp, current_fh, |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 291 | open->op_fname, open->op_fnamelen, *resfh); |
J. Bruce Fields | af85852 | 2006-11-08 17:44:39 -0800 | [diff] [blame] | 292 | if (status) |
| 293 | goto out; |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 294 | status = nfsd_check_obj_isreg(*resfh); |
J. Bruce Fields | 9dc4e6c | 2012-04-09 18:06:49 -0400 | [diff] [blame] | 295 | if (status) |
| 296 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Yu Zhiguo | 9208faf | 2009-07-06 17:24:16 +0800 | [diff] [blame] | 298 | if (is_create_with_attrs(open) && open->op_acl != NULL) |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 299 | do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); |
Yu Zhiguo | 9208faf | 2009-07-06 17:24:16 +0800 | [diff] [blame] | 300 | |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 301 | nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); |
Neil Brown | 7007c90 | 2012-12-07 15:40:55 -0500 | [diff] [blame] | 302 | accmode = NFSD_MAY_NOP; |
J. Bruce Fields | 89f6c33 | 2013-06-19 15:47:37 -0400 | [diff] [blame] | 303 | if (open->op_created || |
| 304 | open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) |
Neil Brown | 7007c90 | 2012-12-07 15:40:55 -0500 | [diff] [blame] | 305 | accmode |= NFSD_MAY_OWNER_OVERRIDE; |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 306 | status = do_open_permission(rqstp, *resfh, open, accmode); |
J. Bruce Fields | 41fd1e4 | 2012-01-27 16:26:02 -0500 | [diff] [blame] | 307 | set_change_info(&open->op_cinfo, current_fh); |
J. Bruce Fields | af85852 | 2006-11-08 17:44:39 -0800 | [diff] [blame] | 308 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | return status; |
| 310 | } |
| 311 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 312 | static __be32 |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 313 | do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 315 | struct svc_fh *current_fh = &cstate->current_fh; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 316 | __be32 status; |
J. Bruce Fields | 9f415eb | 2013-05-03 16:09:09 -0400 | [diff] [blame] | 317 | int accmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* We don't know the target directory, and therefore can not |
| 320 | * set the change info |
| 321 | */ |
| 322 | |
| 323 | memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); |
| 324 | |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 325 | nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && |
| 328 | (open->op_iattr.ia_size == 0); |
J. Bruce Fields | 9f415eb | 2013-05-03 16:09:09 -0400 | [diff] [blame] | 329 | /* |
| 330 | * In the delegation case, the client is telling us about an |
| 331 | * open that it *already* performed locally, some time ago. We |
| 332 | * should let it succeed now if possible. |
| 333 | * |
| 334 | * In the case of a CLAIM_FH open, on the other hand, the client |
| 335 | * may be counting on us to enforce permissions (the Linux 4.1 |
| 336 | * client uses this for normal opens, for example). |
| 337 | */ |
| 338 | if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) |
| 339 | accmode = NFSD_MAY_OWNER_OVERRIDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
J. Bruce Fields | 9f415eb | 2013-05-03 16:09:09 -0400 | [diff] [blame] | 341 | status = do_open_permission(rqstp, current_fh, open, accmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | return status; |
| 344 | } |
| 345 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 346 | static void |
| 347 | copy_clientid(clientid_t *clid, struct nfsd4_session *session) |
| 348 | { |
| 349 | struct nfsd4_sessionid *sid = |
| 350 | (struct nfsd4_sessionid *)session->se_sessionid.data; |
| 351 | |
| 352 | clid->cl_boot = sid->clientid.cl_boot; |
| 353 | clid->cl_id = sid->clientid.cl_id; |
| 354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 356 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 357 | nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 358 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 360 | struct nfsd4_open *open = &u->open; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 361 | __be32 status; |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 362 | struct svc_fh *resfh = NULL; |
Stanislav Kinsbursky | 3320fef19 | 2012-11-14 18:22:07 +0300 | [diff] [blame] | 363 | struct net *net = SVC_NET(rqstp); |
| 364 | struct nfsd_net *nn = net_generic(net, nfsd_net_id); |
J. Bruce Fields | 03f318c | 2018-06-08 12:28:47 -0400 | [diff] [blame] | 365 | bool reclaim = false; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 366 | |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 367 | dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 368 | (int)open->op_fnamelen, open->op_fname, |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 369 | open->op_openowner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* This check required by spec. */ |
| 372 | if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) |
| 373 | return nfserr_inval; |
| 374 | |
zhengbin | 500c2481 | 2019-12-25 11:19:35 +0800 | [diff] [blame] | 375 | open->op_created = false; |
Mi Jinlong | ab1350b | 2011-07-14 15:06:26 +0800 | [diff] [blame] | 376 | /* |
| 377 | * RFC5661 18.51.3 |
| 378 | * Before RECLAIM_COMPLETE done, server should deny new lock |
| 379 | */ |
| 380 | if (nfsd4_has_session(cstate) && |
Jeff Layton | a52d726 | 2012-03-21 09:52:02 -0400 | [diff] [blame] | 381 | !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, |
| 382 | &cstate->session->se_client->cl_flags) && |
Mi Jinlong | ab1350b | 2011-07-14 15:06:26 +0800 | [diff] [blame] | 383 | open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) |
| 384 | return nfserr_grace; |
| 385 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 386 | if (nfsd4_has_session(cstate)) |
| 387 | copy_clientid(&open->op_clientid, cstate->session); |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* check seqid for replay. set nfs4_owner */ |
Kinglong Mee | 6cd2266 | 2015-07-13 17:32:05 +0800 | [diff] [blame] | 390 | status = nfsd4_process_open1(cstate, open, nn); |
Al Viro | a90b061 | 2006-10-19 23:29:03 -0700 | [diff] [blame] | 391 | if (status == nfserr_replay_me) { |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 392 | struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 393 | fh_put(&cstate->current_fh); |
J. Bruce Fields | a4773c0 | 2009-02-02 17:23:10 -0500 | [diff] [blame] | 394 | fh_copy_shallow(&cstate->current_fh.fh_handle, |
| 395 | &rp->rp_openfh); |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 396 | status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | if (status) |
| 398 | dprintk("nfsd4_open: replay failed" |
| 399 | " restoring previous filehandle\n"); |
| 400 | else |
Al Viro | a90b061 | 2006-10-19 23:29:03 -0700 | [diff] [blame] | 401 | status = nfserr_replay_me; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | if (status) |
| 404 | goto out; |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 405 | if (open->op_xdr_error) { |
| 406 | status = open->op_xdr_error; |
| 407 | goto out; |
| 408 | } |
J. Bruce Fields | fb553c0 | 2006-01-18 17:43:36 -0800 | [diff] [blame] | 409 | |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 410 | status = nfsd4_check_open_attributes(rqstp, cstate, open); |
| 411 | if (status) |
| 412 | goto out; |
| 413 | |
J. Bruce Fields | fb553c0 | 2006-01-18 17:43:36 -0800 | [diff] [blame] | 414 | /* Openowner is now set, so sequence id will get bumped. Now we need |
| 415 | * these checks before we do any creates: */ |
J. Bruce Fields | cbd0d51 | 2006-02-07 12:58:32 -0800 | [diff] [blame] | 416 | status = nfserr_grace; |
J. Bruce Fields | c87fb4a | 2015-08-06 12:47:02 -0400 | [diff] [blame] | 417 | if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) |
J. Bruce Fields | cbd0d51 | 2006-02-07 12:58:32 -0800 | [diff] [blame] | 418 | goto out; |
| 419 | status = nfserr_no_grace; |
J. Bruce Fields | c87fb4a | 2015-08-06 12:47:02 -0400 | [diff] [blame] | 420 | if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) |
J. Bruce Fields | cbd0d51 | 2006-02-07 12:58:32 -0800 | [diff] [blame] | 421 | goto out; |
J. Bruce Fields | fb553c0 | 2006-01-18 17:43:36 -0800 | [diff] [blame] | 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | switch (open->op_claim_type) { |
NeilBrown | 0dd3c19 | 2005-06-23 22:02:56 -0700 | [diff] [blame] | 424 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | case NFS4_OPEN_CLAIM_NULL: |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 426 | status = do_open_lookup(rqstp, cstate, open, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (status) |
| 428 | goto out; |
| 429 | break; |
| 430 | case NFS4_OPEN_CLAIM_PREVIOUS: |
Stanislav Kinsbursky | 3320fef19 | 2012-11-14 18:22:07 +0300 | [diff] [blame] | 431 | status = nfs4_check_open_reclaim(&open->op_clientid, |
Trond Myklebust | 0fe492d | 2014-06-30 11:48:47 -0400 | [diff] [blame] | 432 | cstate, nn); |
Mi Jinlong | 0cf99b9 | 2011-11-23 10:48:40 +0800 | [diff] [blame] | 433 | if (status) |
| 434 | goto out; |
Jeff Layton | ba5378b | 2014-05-30 09:09:28 -0400 | [diff] [blame] | 435 | open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; |
J. Bruce Fields | 03f318c | 2018-06-08 12:28:47 -0400 | [diff] [blame] | 436 | reclaim = true; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 437 | fallthrough; |
J. Bruce Fields | 8b289b2 | 2011-10-19 11:52:12 -0400 | [diff] [blame] | 438 | case NFS4_OPEN_CLAIM_FH: |
| 439 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
J. Bruce Fields | bbc9c36 | 2013-03-22 18:03:49 -0400 | [diff] [blame] | 440 | status = do_open_fhandle(rqstp, cstate, open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (status) |
| 442 | goto out; |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 443 | resfh = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | break; |
J. Bruce Fields | 8b289b2 | 2011-10-19 11:52:12 -0400 | [diff] [blame] | 445 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 447 | dprintk("NFSD: unsupported OPEN claim type %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | open->op_claim_type); |
| 449 | status = nfserr_notsupp; |
| 450 | goto out; |
| 451 | default: |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 452 | dprintk("NFSD: Invalid OPEN claim type %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | open->op_claim_type); |
| 454 | status = nfserr_inval; |
| 455 | goto out; |
| 456 | } |
| 457 | /* |
| 458 | * nfsd4_process_open2() does the actual opening of the file. If |
| 459 | * successful, it (1) truncates the file if open->op_truncate was |
| 460 | * set, (2) sets open->op_stateid, (3) sets open->op_delegation. |
| 461 | */ |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 462 | status = nfsd4_process_open2(rqstp, resfh, open); |
Jeff Layton | b3fbfe0 | 2014-07-29 21:37:44 -0400 | [diff] [blame] | 463 | WARN(status && open->op_created, |
| 464 | "nfsd4_process_open2 failed to open newly-created file! status=%u\n", |
| 465 | be32_to_cpu(status)); |
J. Bruce Fields | 03f318c | 2018-06-08 12:28:47 -0400 | [diff] [blame] | 466 | if (reclaim && !status) |
| 467 | nn->somebody_reclaimed = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | out: |
J. Bruce Fields | c0e6bee | 2012-01-27 17:26:06 -0500 | [diff] [blame] | 469 | if (resfh && resfh != &cstate->current_fh) { |
| 470 | fh_dup2(&cstate->current_fh, resfh); |
| 471 | fh_put(resfh); |
| 472 | kfree(resfh); |
| 473 | } |
Jeff Layton | 4229789 | 2015-03-23 10:53:44 -0400 | [diff] [blame] | 474 | nfsd4_cleanup_open_state(cstate, open); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 475 | nfsd4_bump_seqid(cstate, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | return status; |
| 477 | } |
| 478 | |
| 479 | /* |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 480 | * OPEN is the only seqid-mutating operation whose decoding can fail |
| 481 | * with a seqid-mutating error (specifically, decoding of user names in |
| 482 | * the attributes). Therefore we have to do some processing to look up |
| 483 | * the stateowner so that we can bump the seqid. |
| 484 | */ |
| 485 | static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) |
| 486 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 487 | struct nfsd4_open *open = &op->u.open; |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 488 | |
| 489 | if (!seqid_mutating_err(ntohl(op->status))) |
| 490 | return op->status; |
| 491 | if (nfsd4_has_session(cstate)) |
| 492 | return op->status; |
| 493 | open->op_xdr_error = op->status; |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 494 | return nfsd4_open(rqstp, cstate, &op->u); |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | * filehandle-manipulating ops. |
| 499 | */ |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 500 | static __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 501 | nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 502 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 504 | u->getfh = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return nfs_ok; |
| 506 | } |
| 507 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 508 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 509 | nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 510 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 512 | struct nfsd4_putfh *putfh = &u->putfh; |
Olga Kornievskaia | b9e8638 | 2019-10-07 10:56:48 -0400 | [diff] [blame] | 513 | __be32 ret; |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 514 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 515 | fh_put(&cstate->current_fh); |
| 516 | cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; |
| 517 | memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, |
| 518 | putfh->pf_fhlen); |
Olga Kornievskaia | b9e8638 | 2019-10-07 10:56:48 -0400 | [diff] [blame] | 519 | ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); |
| 520 | #ifdef CONFIG_NFSD_V4_2_INTER_SSC |
| 521 | if (ret == nfserr_stale && putfh->no_verify) { |
| 522 | SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN); |
| 523 | ret = 0; |
| 524 | } |
| 525 | #endif |
| 526 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 529 | static __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 530 | nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 531 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 533 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 535 | fh_put(&cstate->current_fh); |
J. Bruce Fields | df547ef | 2007-07-17 04:04:43 -0700 | [diff] [blame] | 536 | status = exp_pseudoroot(rqstp, &cstate->current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return status; |
| 538 | } |
| 539 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 540 | static __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 541 | nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 542 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 544 | if (!cstate->save_fh.fh_dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return nfserr_restorefh; |
| 546 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 547 | fh_dup2(&cstate->current_fh, &cstate->save_fh); |
Olga Kornievskaia | 51100d2 | 2018-09-13 13:58:24 -0400 | [diff] [blame] | 548 | if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) { |
Tigran Mkrtchyan | 37c593c | 2012-02-13 22:55:32 +0100 | [diff] [blame] | 549 | memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); |
Olga Kornievskaia | 51100d2 | 2018-09-13 13:58:24 -0400 | [diff] [blame] | 550 | SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); |
Tigran Mkrtchyan | 37c593c | 2012-02-13 22:55:32 +0100 | [diff] [blame] | 551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return nfs_ok; |
| 553 | } |
| 554 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 555 | static __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 556 | nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 557 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 559 | fh_dup2(&cstate->save_fh, &cstate->current_fh); |
Olga Kornievskaia | 51100d2 | 2018-09-13 13:58:24 -0400 | [diff] [blame] | 560 | if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) { |
Tigran Mkrtchyan | 37c593c | 2012-02-13 22:55:32 +0100 | [diff] [blame] | 561 | memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); |
Olga Kornievskaia | 51100d2 | 2018-09-13 13:58:24 -0400 | [diff] [blame] | 562 | SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG); |
Tigran Mkrtchyan | 37c593c | 2012-02-13 22:55:32 +0100 | [diff] [blame] | 563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | return nfs_ok; |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | * misc nfsv4 ops |
| 569 | */ |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 570 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 571 | nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 572 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 574 | struct nfsd4_access *access = &u->access; |
Frank van der Linden | c11d7fd | 2020-06-23 22:39:24 +0000 | [diff] [blame] | 575 | u32 access_full; |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 576 | |
Frank van der Linden | c11d7fd | 2020-06-23 22:39:24 +0000 | [diff] [blame] | 577 | access_full = NFS3_ACCESS_FULL; |
| 578 | if (cstate->minorversion >= 2) |
| 579 | access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD | |
| 580 | NFS4_ACCESS_XAWRITE; |
| 581 | |
| 582 | if (access->ac_req_access & ~access_full) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | return nfserr_inval; |
| 584 | |
| 585 | access->ac_resp_access = access->ac_req_access; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 586 | return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, |
| 587 | &access->ac_supported); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Stanislav Kinsbursky | b9c0ef8 | 2012-12-06 14:23:19 +0300 | [diff] [blame] | 590 | static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 591 | { |
Trond Myklebust | 27c438f | 2019-09-02 13:02:56 -0400 | [diff] [blame] | 592 | __be32 *verf = (__be32 *)verifier->data; |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 593 | |
Trond Myklebust | 27c438f | 2019-09-02 13:02:56 -0400 | [diff] [blame] | 594 | BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data)); |
| 595 | |
| 596 | nfsd_copy_boot_verifier(verf, net_generic(net, nfsd_net_id)); |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 597 | } |
| 598 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 599 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 600 | nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 601 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 603 | struct nfsd4_commit *commit = &u->commit; |
| 604 | |
J. Bruce Fields | 75c096f | 2011-08-15 18:39:32 -0400 | [diff] [blame] | 605 | return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, |
Trond Myklebust | 524ff1a | 2020-01-06 13:40:36 -0500 | [diff] [blame] | 606 | commit->co_count, |
| 607 | (__be32 *)commit->co_verf.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 610 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 611 | nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 612 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 614 | struct nfsd4_create *create = &u->create; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | struct svc_fh resfh; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 616 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | dev_t rdev; |
| 618 | |
| 619 | fh_init(&resfh, NFS4_FHSIZE); |
| 620 | |
J. Bruce Fields | fa08139 | 2016-07-21 16:00:12 -0400 | [diff] [blame] | 621 | status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | if (status) |
| 623 | return status; |
| 624 | |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 625 | status = check_attr_support(rqstp, cstate, create->cr_bmval, |
| 626 | nfsd_attrmask); |
| 627 | if (status) |
| 628 | return status; |
| 629 | |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 630 | current->fs->umask = create->cr_umask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | switch (create->cr_type) { |
| 632 | case NF4LNK: |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 633 | status = nfsd_symlink(rqstp, &cstate->current_fh, |
| 634 | create->cr_name, create->cr_namelen, |
Kinglong Mee | 1e444f5 | 2014-07-01 17:48:02 +0800 | [diff] [blame] | 635 | create->cr_data, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case NF4BLK: |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 639 | status = nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); |
| 641 | if (MAJOR(rdev) != create->cr_specdata1 || |
| 642 | MINOR(rdev) != create->cr_specdata2) |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 643 | goto out_umask; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 644 | status = nfsd_create(rqstp, &cstate->current_fh, |
| 645 | create->cr_name, create->cr_namelen, |
| 646 | &create->cr_iattr, S_IFBLK, rdev, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case NF4CHR: |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 650 | status = nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); |
| 652 | if (MAJOR(rdev) != create->cr_specdata1 || |
| 653 | MINOR(rdev) != create->cr_specdata2) |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 654 | goto out_umask; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 655 | status = nfsd_create(rqstp, &cstate->current_fh, |
| 656 | create->cr_name, create->cr_namelen, |
| 657 | &create->cr_iattr,S_IFCHR, rdev, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | break; |
| 659 | |
| 660 | case NF4SOCK: |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 661 | status = nfsd_create(rqstp, &cstate->current_fh, |
| 662 | create->cr_name, create->cr_namelen, |
| 663 | &create->cr_iattr, S_IFSOCK, 0, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | break; |
| 665 | |
| 666 | case NF4FIFO: |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 667 | status = nfsd_create(rqstp, &cstate->current_fh, |
| 668 | create->cr_name, create->cr_namelen, |
| 669 | &create->cr_iattr, S_IFIFO, 0, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | case NF4DIR: |
| 673 | create->cr_iattr.ia_valid &= ~ATTR_SIZE; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 674 | status = nfsd_create(rqstp, &cstate->current_fh, |
| 675 | create->cr_name, create->cr_namelen, |
| 676 | &create->cr_iattr, S_IFDIR, 0, &resfh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | default: |
| 680 | status = nfserr_badtype; |
| 681 | } |
| 682 | |
Yu Zhiguo | 9208faf | 2009-07-06 17:24:16 +0800 | [diff] [blame] | 683 | if (status) |
| 684 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 686 | if (create->cr_label.len) |
| 687 | nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); |
| 688 | |
Yu Zhiguo | 9208faf | 2009-07-06 17:24:16 +0800 | [diff] [blame] | 689 | if (create->cr_acl != NULL) |
| 690 | do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, |
| 691 | create->cr_bmval); |
| 692 | |
| 693 | fh_unlock(&cstate->current_fh); |
| 694 | set_change_info(&create->cr_cinfo, &cstate->current_fh); |
| 695 | fh_dup2(&cstate->current_fh, &resfh); |
| 696 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | fh_put(&resfh); |
J. Bruce Fields | 880a3a5 | 2018-03-21 17:19:02 -0400 | [diff] [blame] | 698 | out_umask: |
| 699 | current->fs->umask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | return status; |
| 701 | } |
| 702 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 703 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 704 | nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 705 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 707 | struct nfsd4_getattr *getattr = &u->getattr; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 708 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 710 | status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if (status) |
| 712 | return status; |
| 713 | |
| 714 | if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) |
| 715 | return nfserr_inval; |
| 716 | |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 717 | getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; |
| 718 | getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; |
| 719 | getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 721 | getattr->ga_fhp = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | return nfs_ok; |
| 723 | } |
| 724 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 725 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 726 | nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 727 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 729 | struct nfsd4_link *link = &u->link; |
J. Bruce Fields | 9542446 | 2017-09-15 16:02:52 -0400 | [diff] [blame] | 730 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 732 | status = nfsd_link(rqstp, &cstate->current_fh, |
| 733 | link->li_name, link->li_namelen, &cstate->save_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | if (!status) |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 735 | set_change_info(&link->li_cinfo, &cstate->current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | return status; |
| 737 | } |
| 738 | |
J. Bruce Fields | 0ff7ab4 | 2010-12-16 10:06:27 -0500 | [diff] [blame] | 739 | static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | { |
| 741 | struct svc_fh tmp_fh; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 742 | __be32 ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
| 744 | fh_init(&tmp_fh, NFS4_FHSIZE); |
J. Bruce Fields | df547ef | 2007-07-17 04:04:43 -0700 | [diff] [blame] | 745 | ret = exp_pseudoroot(rqstp, &tmp_fh); |
| 746 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return ret; |
J. Bruce Fields | 0ff7ab4 | 2010-12-16 10:06:27 -0500 | [diff] [blame] | 748 | if (tmp_fh.fh_dentry == fh->fh_dentry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | fh_put(&tmp_fh); |
| 750 | return nfserr_noent; |
| 751 | } |
| 752 | fh_put(&tmp_fh); |
J. Bruce Fields | 0ff7ab4 | 2010-12-16 10:06:27 -0500 | [diff] [blame] | 753 | return nfsd_lookup(rqstp, fh, "..", 2, fh); |
| 754 | } |
| 755 | |
| 756 | static __be32 |
| 757 | nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 758 | union nfsd4_op_u *u) |
J. Bruce Fields | 0ff7ab4 | 2010-12-16 10:06:27 -0500 | [diff] [blame] | 759 | { |
| 760 | return nfsd4_do_lookupp(rqstp, &cstate->current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 763 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 764 | nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 765 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 767 | return nfsd_lookup(rqstp, &cstate->current_fh, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 768 | u->lookup.lo_name, u->lookup.lo_len, |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 769 | &cstate->current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 772 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 773 | nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 774 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 776 | struct nfsd4_read *read = &u->read; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 777 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 779 | read->rd_nf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | if (read->rd_offset >= OFFSET_MAX) |
| 781 | return nfserr_inval; |
| 782 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 783 | trace_nfsd_read_start(rqstp, &cstate->current_fh, |
| 784 | read->rd_offset, read->rd_length); |
| 785 | |
J. Bruce Fields | 9b3234b | 2012-12-04 18:03:46 -0500 | [diff] [blame] | 786 | /* |
| 787 | * If we do a zero copy read, then a client will see read data |
| 788 | * that reflects the state of the file *after* performing the |
| 789 | * following compound. |
| 790 | * |
| 791 | * To ensure proper ordering, we therefore turn off zero copy if |
| 792 | * the client wants us to do more in this compound: |
| 793 | */ |
| 794 | if (!nfsd4_last_compound_op(rqstp)) |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 795 | clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); |
J. Bruce Fields | 9b3234b | 2012-12-04 18:03:46 -0500 | [diff] [blame] | 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | /* check stateid */ |
Anna Schumaker | aa0d6ae | 2015-12-03 12:59:51 +0100 | [diff] [blame] | 798 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
| 799 | &read->rd_stateid, RD_STATE, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 800 | &read->rd_nf, NULL); |
Christoph Hellwig | af90f70 | 2015-06-18 16:45:00 +0200 | [diff] [blame] | 801 | if (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); |
| 803 | goto out; |
| 804 | } |
| 805 | status = nfs_ok; |
| 806 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | read->rd_rqstp = rqstp; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 808 | read->rd_fhp = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | return status; |
| 810 | } |
| 811 | |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 812 | |
| 813 | static void |
| 814 | nfsd4_read_release(union nfsd4_op_u *u) |
| 815 | { |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 816 | if (u->read.rd_nf) |
| 817 | nfsd_file_put(u->read.rd_nf); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 818 | trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp, |
| 819 | u->read.rd_offset, u->read.rd_length); |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 820 | } |
| 821 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 822 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 823 | nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 824 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 826 | struct nfsd4_readdir *readdir = &u->readdir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | u64 cookie = readdir->rd_cookie; |
| 828 | static const nfs4_verifier zeroverf; |
| 829 | |
| 830 | /* no need to check permission - this will be done in nfsd_readdir() */ |
| 831 | |
| 832 | if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) |
| 833 | return nfserr_inval; |
| 834 | |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 835 | readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; |
| 836 | readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; |
| 837 | readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
Bernd Schubert | 832023b | 2011-08-08 17:38:08 +0200 | [diff] [blame] | 839 | if ((cookie == 1) || (cookie == 2) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) |
| 841 | return nfserr_bad_cookie; |
| 842 | |
| 843 | readdir->rd_rqstp = rqstp; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 844 | readdir->rd_fhp = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | return nfs_ok; |
| 846 | } |
| 847 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 848 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 849 | nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 850 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 852 | u->readlink.rl_rqstp = rqstp; |
| 853 | u->readlink.rl_fhp = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | return nfs_ok; |
| 855 | } |
| 856 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 857 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 858 | nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 859 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 861 | struct nfsd4_remove *remove = &u->remove; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 862 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
J. Bruce Fields | c87fb4a | 2015-08-06 12:47:02 -0400 | [diff] [blame] | 864 | if (opens_in_grace(SVC_NET(rqstp))) |
NeilBrown | c815afc | 2005-06-23 22:03:00 -0700 | [diff] [blame] | 865 | return nfserr_grace; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 866 | status = nfsd_unlink(rqstp, &cstate->current_fh, 0, |
| 867 | remove->rm_name, remove->rm_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | if (!status) { |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 869 | fh_unlock(&cstate->current_fh); |
| 870 | set_change_info(&remove->rm_cinfo, &cstate->current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } |
| 872 | return status; |
| 873 | } |
| 874 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 875 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 876 | nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 877 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 879 | struct nfsd4_rename *rename = &u->rename; |
J. Bruce Fields | 9542446 | 2017-09-15 16:02:52 -0400 | [diff] [blame] | 880 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
J. Bruce Fields | f8f71d0 | 2018-11-06 11:47:20 -0500 | [diff] [blame] | 882 | if (opens_in_grace(SVC_NET(rqstp))) |
NeilBrown | c815afc | 2005-06-23 22:03:00 -0700 | [diff] [blame] | 883 | return nfserr_grace; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 884 | status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, |
| 885 | rename->rn_snamelen, &cstate->current_fh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | rename->rn_tname, rename->rn_tnamelen); |
J. Bruce Fields | 2a6cf94 | 2013-04-30 15:28:51 -0400 | [diff] [blame] | 887 | if (status) |
| 888 | return status; |
| 889 | set_change_info(&rename->rn_sinfo, &cstate->current_fh); |
| 890 | set_change_info(&rename->rn_tinfo, &cstate->save_fh); |
| 891 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 894 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 895 | nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 896 | union nfsd4_op_u *u) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 897 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 898 | struct nfsd4_secinfo *secinfo = &u->secinfo; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 899 | struct svc_export *exp; |
| 900 | struct dentry *dentry; |
| 901 | __be32 err; |
| 902 | |
J. Bruce Fields | 29a78a3 | 2011-04-09 11:28:53 -0400 | [diff] [blame] | 903 | err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); |
| 904 | if (err) |
| 905 | return err; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 906 | err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, |
| 907 | secinfo->si_name, secinfo->si_namelen, |
| 908 | &exp, &dentry); |
| 909 | if (err) |
| 910 | return err; |
J. Bruce Fields | 2f6fc05 | 2016-03-02 16:36:21 -0800 | [diff] [blame] | 911 | fh_unlock(&cstate->current_fh); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 912 | if (d_really_is_negative(dentry)) { |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 913 | exp_put(exp); |
| 914 | err = nfserr_noent; |
| 915 | } else |
| 916 | secinfo->si_exp = exp; |
| 917 | dput(dentry); |
J. Bruce Fields | 56560b9 | 2010-12-16 09:57:15 -0500 | [diff] [blame] | 918 | if (cstate->minorversion) |
| 919 | /* See rfc 5661 section 2.6.3.1.1.8 */ |
| 920 | fh_put(&cstate->current_fh); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 921 | return err; |
| 922 | } |
| 923 | |
| 924 | static __be32 |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 925 | nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 926 | union nfsd4_op_u *u) |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 927 | { |
| 928 | __be32 err; |
| 929 | |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 930 | switch (u->secinfo_no_name.sin_style) { |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 931 | case NFS4_SECINFO_STYLE4_CURRENT_FH: |
| 932 | break; |
| 933 | case NFS4_SECINFO_STYLE4_PARENT: |
| 934 | err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); |
| 935 | if (err) |
| 936 | return err; |
| 937 | break; |
| 938 | default: |
| 939 | return nfserr_inval; |
| 940 | } |
Kinglong Mee | bf18f16 | 2014-06-10 22:06:44 +0800 | [diff] [blame] | 941 | |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 942 | u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export); |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 943 | fh_put(&cstate->current_fh); |
| 944 | return nfs_ok; |
| 945 | } |
| 946 | |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 947 | static void |
| 948 | nfsd4_secinfo_release(union nfsd4_op_u *u) |
| 949 | { |
| 950 | if (u->secinfo.si_exp) |
| 951 | exp_put(u->secinfo.si_exp); |
| 952 | } |
| 953 | |
Eryu Guan | ec572b9 | 2017-09-29 15:01:10 +0800 | [diff] [blame] | 954 | static void |
| 955 | nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) |
| 956 | { |
| 957 | if (u->secinfo_no_name.sin_exp) |
| 958 | exp_put(u->secinfo_no_name.sin_exp); |
| 959 | } |
| 960 | |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 961 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 962 | nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 963 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 965 | struct nfsd4_setattr *setattr = &u->setattr; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 966 | __be32 status = nfs_ok; |
Al Viro | 96f6f98 | 2012-04-12 23:47:00 -0400 | [diff] [blame] | 967 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { |
Christoph Hellwig | af90f70 | 2015-06-18 16:45:00 +0200 | [diff] [blame] | 970 | status = nfs4_preprocess_stateid_op(rqstp, cstate, |
Anna Schumaker | aa0d6ae | 2015-12-03 12:59:51 +0100 | [diff] [blame] | 971 | &cstate->current_fh, &setattr->sa_stateid, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 972 | WR_STATE, NULL, NULL); |
J. Bruce Fields | 375c554 | 2006-01-18 17:43:33 -0800 | [diff] [blame] | 973 | if (status) { |
Greg Banks | 3e3b480 | 2006-10-02 02:17:41 -0700 | [diff] [blame] | 974 | dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); |
J. Bruce Fields | 375c554 | 2006-01-18 17:43:33 -0800 | [diff] [blame] | 975 | return status; |
| 976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } |
Al Viro | 96f6f98 | 2012-04-12 23:47:00 -0400 | [diff] [blame] | 978 | err = fh_want_write(&cstate->current_fh); |
| 979 | if (err) |
| 980 | return nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | status = nfs_ok; |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 982 | |
| 983 | status = check_attr_support(rqstp, cstate, setattr->sa_bmval, |
| 984 | nfsd_attrmask); |
| 985 | if (status) |
| 986 | goto out; |
| 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | if (setattr->sa_acl != NULL) |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 989 | status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, |
| 990 | setattr->sa_acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | if (status) |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 992 | goto out; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 993 | if (setattr->sa_label.len) |
| 994 | status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, |
| 995 | &setattr->sa_label); |
| 996 | if (status) |
| 997 | goto out; |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 998 | status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, |
Arnd Bergmann | 2a1aa48 | 2019-11-03 17:50:18 +0100 | [diff] [blame] | 999 | 0, (time64_t)0); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 1000 | out: |
Al Viro | bad0dcf | 2011-11-23 12:03:18 -0500 | [diff] [blame] | 1001 | fh_drop_write(&cstate->current_fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | return status; |
| 1003 | } |
| 1004 | |
J.Bruce Fields | 7191155 | 2006-12-13 00:35:29 -0800 | [diff] [blame] | 1005 | static __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 1006 | nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1007 | union nfsd4_op_u *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1009 | struct nfsd4_write *write = &u->write; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | stateid_t *stateid = &write->wr_stateid; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1011 | struct nfsd_file *nf = NULL; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1012 | __be32 status = nfs_ok; |
David Shaw | 31dec25 | 2009-03-05 20:16:14 -0500 | [diff] [blame] | 1013 | unsigned long cnt; |
J. Bruce Fields | ffe1137 | 2012-11-15 14:52:19 -0500 | [diff] [blame] | 1014 | int nvecs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | if (write->wr_offset >= OFFSET_MAX) |
| 1017 | return nfserr_inval; |
| 1018 | |
Chuck Lever | d890be1 | 2018-03-27 10:53:27 -0400 | [diff] [blame] | 1019 | cnt = write->wr_buflen; |
| 1020 | trace_nfsd_write_start(rqstp, &cstate->current_fh, |
| 1021 | write->wr_offset, cnt); |
Anna Schumaker | aa0d6ae | 2015-12-03 12:59:51 +0100 | [diff] [blame] | 1022 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1023 | stateid, WR_STATE, &nf, NULL); |
J. Bruce Fields | 375c554 | 2006-01-18 17:43:33 -0800 | [diff] [blame] | 1024 | if (status) { |
| 1025 | dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); |
| 1026 | return status; |
| 1027 | } |
| 1028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | write->wr_how_written = write->wr_stable_how; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1031 | nvecs = svc_fill_write_vector(rqstp, write->wr_payload.pages, |
| 1032 | write->wr_payload.head, write->wr_buflen); |
J. Bruce Fields | ffe1137 | 2012-11-15 14:52:19 -0500 | [diff] [blame] | 1033 | WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); |
| 1034 | |
Trond Myklebust | 16f8f89 | 2020-01-06 13:40:29 -0500 | [diff] [blame] | 1035 | status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, |
Christoph Hellwig | af90f70 | 2015-06-18 16:45:00 +0200 | [diff] [blame] | 1036 | write->wr_offset, rqstp->rq_vec, nvecs, &cnt, |
Trond Myklebust | 19e0663 | 2020-01-06 13:40:37 -0500 | [diff] [blame] | 1037 | write->wr_how_written, |
| 1038 | (__be32 *)write->wr_verifier.data); |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1039 | nfsd_file_put(nf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
David Shaw | 31dec25 | 2009-03-05 20:16:14 -0500 | [diff] [blame] | 1041 | write->wr_bytes_written = cnt; |
Chuck Lever | d890be1 | 2018-03-27 10:53:27 -0400 | [diff] [blame] | 1042 | trace_nfsd_write_done(rqstp, &cstate->current_fh, |
| 1043 | write->wr_offset, cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1047 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1048 | nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1049 | stateid_t *src_stateid, struct nfsd_file **src, |
| 1050 | stateid_t *dst_stateid, struct nfsd_file **dst) |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1051 | { |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1052 | __be32 status; |
| 1053 | |
Scott Mayhew | 01310bb | 2018-11-08 11:11:36 -0500 | [diff] [blame] | 1054 | if (!cstate->save_fh.fh_dentry) |
| 1055 | return nfserr_nofilehandle; |
| 1056 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1057 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1058 | src_stateid, RD_STATE, src, NULL); |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1059 | if (status) { |
| 1060 | dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); |
| 1061 | goto out; |
| 1062 | } |
| 1063 | |
| 1064 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1065 | dst_stateid, WR_STATE, dst, NULL); |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1066 | if (status) { |
| 1067 | dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); |
| 1068 | goto out_put_src; |
| 1069 | } |
| 1070 | |
| 1071 | /* fix up for NFS-specific error code */ |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1072 | if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) || |
| 1073 | !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) { |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1074 | status = nfserr_wrong_type; |
| 1075 | goto out_put_dst; |
| 1076 | } |
| 1077 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1078 | out: |
| 1079 | return status; |
| 1080 | out_put_dst: |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1081 | nfsd_file_put(*dst); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1082 | out_put_src: |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1083 | nfsd_file_put(*src); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1084 | goto out; |
| 1085 | } |
| 1086 | |
| 1087 | static __be32 |
| 1088 | nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1089 | union nfsd4_op_u *u) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1090 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1091 | struct nfsd4_clone *clone = &u->clone; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1092 | struct nfsd_file *src, *dst; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1093 | __be32 status; |
| 1094 | |
| 1095 | status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, |
| 1096 | &clone->cl_dst_stateid, &dst); |
| 1097 | if (status) |
| 1098 | goto out; |
| 1099 | |
Trond Myklebust | b66ae6d | 2020-01-06 13:40:32 -0500 | [diff] [blame] | 1100 | status = nfsd4_clone_file_range(src, clone->cl_src_pos, |
| 1101 | dst, clone->cl_dst_pos, clone->cl_count, |
Trond Myklebust | a25e3726 | 2019-11-27 17:05:51 -0500 | [diff] [blame] | 1102 | EX_ISSYNC(cstate->current_fh.fh_export)); |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1103 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1104 | nfsd_file_put(dst); |
| 1105 | nfsd_file_put(src); |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1106 | out: |
| 1107 | return status; |
| 1108 | } |
| 1109 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1110 | void nfs4_put_copy(struct nfsd4_copy *copy) |
| 1111 | { |
| 1112 | if (!refcount_dec_and_test(©->refcount)) |
| 1113 | return; |
| 1114 | kfree(copy); |
| 1115 | } |
| 1116 | |
| 1117 | static bool |
| 1118 | check_and_set_stop_copy(struct nfsd4_copy *copy) |
| 1119 | { |
| 1120 | bool value; |
| 1121 | |
| 1122 | spin_lock(©->cp_clp->async_lock); |
| 1123 | value = copy->stopped; |
| 1124 | if (!copy->stopped) |
| 1125 | copy->stopped = true; |
| 1126 | spin_unlock(©->cp_clp->async_lock); |
| 1127 | return value; |
| 1128 | } |
| 1129 | |
| 1130 | static void nfsd4_stop_copy(struct nfsd4_copy *copy) |
| 1131 | { |
| 1132 | /* only 1 thread should stop the copy */ |
| 1133 | if (!check_and_set_stop_copy(copy)) |
| 1134 | kthread_stop(copy->copy_task); |
| 1135 | nfs4_put_copy(copy); |
| 1136 | } |
| 1137 | |
| 1138 | static struct nfsd4_copy *nfsd4_get_copy(struct nfs4_client *clp) |
| 1139 | { |
| 1140 | struct nfsd4_copy *copy = NULL; |
| 1141 | |
| 1142 | spin_lock(&clp->async_lock); |
| 1143 | if (!list_empty(&clp->async_copies)) { |
| 1144 | copy = list_first_entry(&clp->async_copies, struct nfsd4_copy, |
| 1145 | copies); |
| 1146 | refcount_inc(©->refcount); |
| 1147 | } |
| 1148 | spin_unlock(&clp->async_lock); |
| 1149 | return copy; |
| 1150 | } |
| 1151 | |
| 1152 | void nfsd4_shutdown_copy(struct nfs4_client *clp) |
| 1153 | { |
| 1154 | struct nfsd4_copy *copy; |
| 1155 | |
| 1156 | while ((copy = nfsd4_get_copy(clp)) != NULL) |
| 1157 | nfsd4_stop_copy(copy); |
| 1158 | } |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1159 | #ifdef CONFIG_NFSD_V4_2_INTER_SSC |
| 1160 | |
| 1161 | extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, |
| 1162 | struct nfs_fh *src_fh, |
| 1163 | nfs4_stateid *stateid); |
| 1164 | extern void nfs42_ssc_close(struct file *filep); |
| 1165 | |
| 1166 | extern void nfs_sb_deactive(struct super_block *sb); |
| 1167 | |
| 1168 | #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys" |
| 1169 | |
Chuck Lever | f245397 | 2020-04-06 16:01:42 -0400 | [diff] [blame] | 1170 | /* |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1171 | * Support one copy source server for now. |
| 1172 | */ |
| 1173 | static __be32 |
| 1174 | nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp, |
| 1175 | struct vfsmount **mount) |
| 1176 | { |
| 1177 | struct file_system_type *type; |
| 1178 | struct vfsmount *ss_mnt; |
| 1179 | struct nfs42_netaddr *naddr; |
| 1180 | struct sockaddr_storage tmp_addr; |
| 1181 | size_t tmp_addrlen, match_netid_len = 3; |
| 1182 | char *startsep = "", *endsep = "", *match_netid = "tcp"; |
| 1183 | char *ipaddr, *dev_name, *raw_data; |
Olga Kornievskaia | b8290ca | 2019-12-04 15:13:53 -0500 | [diff] [blame] | 1184 | int len, raw_len; |
| 1185 | __be32 status = nfserr_inval; |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1186 | |
| 1187 | naddr = &nss->u.nl4_addr; |
| 1188 | tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr, |
| 1189 | naddr->addr_len, |
| 1190 | (struct sockaddr *)&tmp_addr, |
| 1191 | sizeof(tmp_addr)); |
| 1192 | if (tmp_addrlen == 0) |
| 1193 | goto out_err; |
| 1194 | |
| 1195 | if (tmp_addr.ss_family == AF_INET6) { |
| 1196 | startsep = "["; |
| 1197 | endsep = "]"; |
| 1198 | match_netid = "tcp6"; |
| 1199 | match_netid_len = 4; |
| 1200 | } |
| 1201 | |
| 1202 | if (naddr->netid_len != match_netid_len || |
| 1203 | strncmp(naddr->netid, match_netid, naddr->netid_len)) |
| 1204 | goto out_err; |
| 1205 | |
| 1206 | /* Construct the raw data for the vfs_kern_mount call */ |
| 1207 | len = RPC_MAX_ADDRBUFLEN + 1; |
| 1208 | ipaddr = kzalloc(len, GFP_KERNEL); |
| 1209 | if (!ipaddr) |
| 1210 | goto out_err; |
| 1211 | |
| 1212 | rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len); |
| 1213 | |
| 1214 | /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/ |
| 1215 | |
| 1216 | raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr); |
| 1217 | raw_data = kzalloc(raw_len, GFP_KERNEL); |
| 1218 | if (!raw_data) |
| 1219 | goto out_free_ipaddr; |
| 1220 | |
| 1221 | snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr); |
| 1222 | |
Olga Kornievskaia | b8290ca | 2019-12-04 15:13:53 -0500 | [diff] [blame] | 1223 | status = nfserr_nodev; |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1224 | type = get_fs_type("nfs"); |
| 1225 | if (!type) |
| 1226 | goto out_free_rawdata; |
| 1227 | |
| 1228 | /* Set the server:<export> for the vfs_kern_mount call */ |
| 1229 | dev_name = kzalloc(len + 5, GFP_KERNEL); |
| 1230 | if (!dev_name) |
| 1231 | goto out_free_rawdata; |
| 1232 | snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep); |
| 1233 | |
| 1234 | /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */ |
| 1235 | ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data); |
| 1236 | module_put(type->owner); |
| 1237 | if (IS_ERR(ss_mnt)) |
| 1238 | goto out_free_devname; |
| 1239 | |
| 1240 | status = 0; |
| 1241 | *mount = ss_mnt; |
| 1242 | |
| 1243 | out_free_devname: |
| 1244 | kfree(dev_name); |
| 1245 | out_free_rawdata: |
| 1246 | kfree(raw_data); |
| 1247 | out_free_ipaddr: |
| 1248 | kfree(ipaddr); |
| 1249 | out_err: |
| 1250 | return status; |
| 1251 | } |
| 1252 | |
| 1253 | static void |
| 1254 | nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) |
| 1255 | { |
Dai Ngo | 0cfcd40 | 2020-10-18 23:42:49 -0400 | [diff] [blame] | 1256 | nfs_do_sb_deactive(ss_mnt->mnt_sb); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1257 | mntput(ss_mnt); |
| 1258 | } |
| 1259 | |
Chuck Lever | f245397 | 2020-04-06 16:01:42 -0400 | [diff] [blame] | 1260 | /* |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1261 | * Verify COPY destination stateid. |
Chuck Lever | f245397 | 2020-04-06 16:01:42 -0400 | [diff] [blame] | 1262 | * |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1263 | * Connect to the source server with NFSv4.1. |
| 1264 | * Create the source struct file for nfsd_copy_range. |
| 1265 | * Called with COPY cstate: |
| 1266 | * SAVED_FH: source filehandle |
| 1267 | * CURRENT_FH: destination filehandle |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1268 | */ |
| 1269 | static __be32 |
| 1270 | nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, |
| 1271 | struct nfsd4_compound_state *cstate, |
| 1272 | struct nfsd4_copy *copy, struct vfsmount **mount) |
| 1273 | { |
| 1274 | struct svc_fh *s_fh = NULL; |
| 1275 | stateid_t *s_stid = ©->cp_src_stateid; |
Olga Kornievskaia | b8290ca | 2019-12-04 15:13:53 -0500 | [diff] [blame] | 1276 | __be32 status = nfserr_inval; |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1277 | |
| 1278 | /* Verify the destination stateid and set dst struct file*/ |
| 1279 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
| 1280 | ©->cp_dst_stateid, |
| 1281 | WR_STATE, ©->nf_dst, NULL); |
| 1282 | if (status) |
| 1283 | goto out; |
| 1284 | |
| 1285 | status = nfsd4_interssc_connect(©->cp_src, rqstp, mount); |
| 1286 | if (status) |
| 1287 | goto out; |
| 1288 | |
| 1289 | s_fh = &cstate->save_fh; |
| 1290 | |
| 1291 | copy->c_fh.size = s_fh->fh_handle.fh_size; |
| 1292 | memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_base, copy->c_fh.size); |
Olga Kornievskaia | 3f9544c | 2019-12-04 15:13:53 -0500 | [diff] [blame] | 1293 | copy->stateid.seqid = cpu_to_be32(s_stid->si_generation); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1294 | memcpy(copy->stateid.other, (void *)&s_stid->si_opaque, |
| 1295 | sizeof(stateid_opaque_t)); |
| 1296 | |
| 1297 | status = 0; |
| 1298 | out: |
| 1299 | return status; |
| 1300 | } |
| 1301 | |
| 1302 | static void |
| 1303 | nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, |
| 1304 | struct nfsd_file *dst) |
| 1305 | { |
| 1306 | nfs42_ssc_close(src->nf_file); |
Dai Ngo | 36e1e5b | 2020-10-29 15:07:15 -0400 | [diff] [blame] | 1307 | /* 'src' is freed by nfsd4_do_async_copy */ |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1308 | nfsd_file_put(dst); |
| 1309 | mntput(ss_mnt); |
| 1310 | } |
| 1311 | |
| 1312 | #else /* CONFIG_NFSD_V4_2_INTER_SSC */ |
| 1313 | |
| 1314 | static __be32 |
| 1315 | nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, |
| 1316 | struct nfsd4_compound_state *cstate, |
| 1317 | struct nfsd4_copy *copy, |
| 1318 | struct vfsmount **mount) |
| 1319 | { |
| 1320 | *mount = NULL; |
Olga Kornievskaia | b8290ca | 2019-12-04 15:13:53 -0500 | [diff] [blame] | 1321 | return nfserr_inval; |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static void |
| 1325 | nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, |
| 1326 | struct nfsd_file *dst) |
| 1327 | { |
| 1328 | } |
| 1329 | |
| 1330 | static void |
| 1331 | nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) |
| 1332 | { |
| 1333 | } |
| 1334 | |
| 1335 | static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, |
| 1336 | struct nfs_fh *src_fh, |
| 1337 | nfs4_stateid *stateid) |
| 1338 | { |
| 1339 | return NULL; |
| 1340 | } |
| 1341 | #endif /* CONFIG_NFSD_V4_2_INTER_SSC */ |
| 1342 | |
| 1343 | static __be32 |
| 1344 | nfsd4_setup_intra_ssc(struct svc_rqst *rqstp, |
| 1345 | struct nfsd4_compound_state *cstate, |
| 1346 | struct nfsd4_copy *copy) |
| 1347 | { |
| 1348 | return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, |
| 1349 | ©->nf_src, ©->cp_dst_stateid, |
| 1350 | ©->nf_dst); |
| 1351 | } |
| 1352 | |
| 1353 | static void |
| 1354 | nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst) |
| 1355 | { |
| 1356 | nfsd_file_put(src); |
| 1357 | nfsd_file_put(dst); |
| 1358 | } |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1359 | |
| 1360 | static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) |
| 1361 | { |
| 1362 | struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb); |
| 1363 | |
| 1364 | nfs4_put_copy(copy); |
| 1365 | } |
| 1366 | |
| 1367 | static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, |
| 1368 | struct rpc_task *task) |
| 1369 | { |
| 1370 | return 1; |
| 1371 | } |
| 1372 | |
| 1373 | static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = { |
| 1374 | .release = nfsd4_cb_offload_release, |
| 1375 | .done = nfsd4_cb_offload_done |
| 1376 | }; |
| 1377 | |
| 1378 | static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) |
| 1379 | { |
| 1380 | copy->cp_res.wr_stable_how = NFS_UNSTABLE; |
| 1381 | copy->cp_synchronous = sync; |
| 1382 | gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); |
| 1383 | } |
| 1384 | |
| 1385 | static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) |
| 1386 | { |
| 1387 | ssize_t bytes_copied = 0; |
| 1388 | size_t bytes_total = copy->cp_count; |
| 1389 | u64 src_pos = copy->cp_src_pos; |
| 1390 | u64 dst_pos = copy->cp_dst_pos; |
| 1391 | |
| 1392 | do { |
| 1393 | if (kthread_should_stop()) |
| 1394 | break; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1395 | bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file, |
| 1396 | src_pos, copy->nf_dst->nf_file, dst_pos, |
| 1397 | bytes_total); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1398 | if (bytes_copied <= 0) |
| 1399 | break; |
| 1400 | bytes_total -= bytes_copied; |
| 1401 | copy->cp_res.wr_bytes_written += bytes_copied; |
| 1402 | src_pos += bytes_copied; |
| 1403 | dst_pos += bytes_copied; |
| 1404 | } while (bytes_total > 0 && !copy->cp_synchronous); |
| 1405 | return bytes_copied; |
| 1406 | } |
| 1407 | |
| 1408 | static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) |
| 1409 | { |
| 1410 | __be32 status; |
| 1411 | ssize_t bytes; |
| 1412 | |
| 1413 | bytes = _nfsd_copy_file_range(copy); |
| 1414 | /* for async copy, we ignore the error, client can always retry |
| 1415 | * to get the error |
| 1416 | */ |
| 1417 | if (bytes < 0 && !copy->cp_res.wr_bytes_written) |
| 1418 | status = nfserrno(bytes); |
| 1419 | else { |
| 1420 | nfsd4_init_copy_res(copy, sync); |
| 1421 | status = nfs_ok; |
| 1422 | } |
| 1423 | |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1424 | if (!copy->cp_intra) /* Inter server SSC */ |
| 1425 | nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src, |
| 1426 | copy->nf_dst); |
| 1427 | else |
| 1428 | nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst); |
| 1429 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1430 | return status; |
| 1431 | } |
| 1432 | |
Chuck Lever | eb162e1 | 2020-11-30 16:17:40 -0500 | [diff] [blame] | 1433 | static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1434 | { |
| 1435 | dst->cp_src_pos = src->cp_src_pos; |
| 1436 | dst->cp_dst_pos = src->cp_dst_pos; |
| 1437 | dst->cp_count = src->cp_count; |
| 1438 | dst->cp_synchronous = src->cp_synchronous; |
| 1439 | memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); |
| 1440 | memcpy(&dst->fh, &src->fh, sizeof(src->fh)); |
| 1441 | dst->cp_clp = src->cp_clp; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1442 | dst->nf_dst = nfsd_file_get(src->nf_dst); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1443 | dst->cp_intra = src->cp_intra; |
| 1444 | if (src->cp_intra) /* for inter, file_src doesn't exist yet */ |
| 1445 | dst->nf_src = nfsd_file_get(src->nf_src); |
| 1446 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1447 | memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1448 | memcpy(&dst->cp_src, &src->cp_src, sizeof(struct nl4_server)); |
| 1449 | memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); |
| 1450 | memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); |
| 1451 | dst->ss_mnt = src->ss_mnt; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static void cleanup_async_copy(struct nfsd4_copy *copy) |
| 1455 | { |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1456 | nfs4_free_copy_state(copy); |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1457 | nfsd_file_put(copy->nf_dst); |
Olga Kornievskaia | 2e577f0 | 2019-12-04 15:13:54 -0500 | [diff] [blame] | 1458 | if (copy->cp_intra) |
| 1459 | nfsd_file_put(copy->nf_src); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1460 | spin_lock(©->cp_clp->async_lock); |
| 1461 | list_del(©->copies); |
| 1462 | spin_unlock(©->cp_clp->async_lock); |
| 1463 | nfs4_put_copy(copy); |
| 1464 | } |
| 1465 | |
| 1466 | static int nfsd4_do_async_copy(void *data) |
| 1467 | { |
| 1468 | struct nfsd4_copy *copy = (struct nfsd4_copy *)data; |
| 1469 | struct nfsd4_copy *cb_copy; |
| 1470 | |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1471 | if (!copy->cp_intra) { /* Inter server SSC */ |
| 1472 | copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); |
| 1473 | if (!copy->nf_src) { |
| 1474 | copy->nfserr = nfserr_serverfault; |
| 1475 | nfsd4_interssc_disconnect(copy->ss_mnt); |
| 1476 | goto do_callback; |
| 1477 | } |
| 1478 | copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, |
| 1479 | ©->stateid); |
| 1480 | if (IS_ERR(copy->nf_src->nf_file)) { |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1481 | copy->nfserr = nfserr_offload_denied; |
| 1482 | nfsd4_interssc_disconnect(copy->ss_mnt); |
| 1483 | goto do_callback; |
| 1484 | } |
| 1485 | } |
| 1486 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1487 | copy->nfserr = nfsd4_do_copy(copy, 0); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1488 | do_callback: |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1489 | cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); |
| 1490 | if (!cb_copy) |
| 1491 | goto out; |
Dai Ngo | 49a3613 | 2020-10-29 15:07:16 -0400 | [diff] [blame] | 1492 | refcount_set(&cb_copy->refcount, 1); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1493 | memcpy(&cb_copy->cp_res, ©->cp_res, sizeof(copy->cp_res)); |
| 1494 | cb_copy->cp_clp = copy->cp_clp; |
| 1495 | cb_copy->nfserr = copy->nfserr; |
| 1496 | memcpy(&cb_copy->fh, ©->fh, sizeof(copy->fh)); |
| 1497 | nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp, |
| 1498 | &nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD); |
| 1499 | nfsd4_run_cb(&cb_copy->cp_cb); |
| 1500 | out: |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1501 | if (!copy->cp_intra) |
| 1502 | kfree(copy->nf_src); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1503 | cleanup_async_copy(copy); |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1507 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1508 | nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1509 | union nfsd4_op_u *u) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1510 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1511 | struct nfsd4_copy *copy = &u->copy; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1512 | __be32 status; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1513 | struct nfsd4_copy *async_copy = NULL; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1514 | |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1515 | if (!copy->cp_intra) { /* Inter server SSC */ |
| 1516 | if (!inter_copy_offload_enable || copy->cp_synchronous) { |
| 1517 | status = nfserr_notsupp; |
| 1518 | goto out; |
| 1519 | } |
| 1520 | status = nfsd4_setup_inter_ssc(rqstp, cstate, copy, |
| 1521 | ©->ss_mnt); |
| 1522 | if (status) |
| 1523 | return nfserr_offload_denied; |
| 1524 | } else { |
| 1525 | status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); |
| 1526 | if (status) |
| 1527 | return status; |
| 1528 | } |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1529 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1530 | copy->cp_clp = cstate->clp; |
| 1531 | memcpy(©->fh, &cstate->current_fh.fh_handle, |
| 1532 | sizeof(struct knfsd_fh)); |
| 1533 | if (!copy->cp_synchronous) { |
| 1534 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1535 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1536 | status = nfserrno(-ENOMEM); |
| 1537 | async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); |
| 1538 | if (!async_copy) |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1539 | goto out_err; |
| 1540 | if (!nfs4_init_copy_state(nn, copy)) |
| 1541 | goto out_err; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1542 | refcount_set(&async_copy->refcount, 1); |
| 1543 | memcpy(©->cp_res.cb_stateid, ©->cp_stateid, |
| 1544 | sizeof(copy->cp_stateid)); |
Chuck Lever | eb162e1 | 2020-11-30 16:17:40 -0500 | [diff] [blame] | 1545 | dup_copy_fields(copy, async_copy); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1546 | async_copy->copy_task = kthread_create(nfsd4_do_async_copy, |
| 1547 | async_copy, "%s", "copy thread"); |
| 1548 | if (IS_ERR(async_copy->copy_task)) |
| 1549 | goto out_err; |
| 1550 | spin_lock(&async_copy->cp_clp->async_lock); |
| 1551 | list_add(&async_copy->copies, |
| 1552 | &async_copy->cp_clp->async_copies); |
| 1553 | spin_unlock(&async_copy->cp_clp->async_lock); |
| 1554 | wake_up_process(async_copy->copy_task); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1555 | status = nfs_ok; |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1556 | } else { |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1557 | status = nfsd4_do_copy(copy, 1); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1558 | } |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1559 | out: |
| 1560 | return status; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1561 | out_err: |
Olga Kornievskaia | 18f428d | 2019-12-04 15:13:54 -0500 | [diff] [blame] | 1562 | if (async_copy) |
| 1563 | cleanup_async_copy(async_copy); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1564 | status = nfserrno(-ENOMEM); |
| 1565 | if (!copy->cp_intra) |
| 1566 | nfsd4_interssc_disconnect(copy->ss_mnt); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1567 | goto out; |
| 1568 | } |
| 1569 | |
| 1570 | struct nfsd4_copy * |
| 1571 | find_async_copy(struct nfs4_client *clp, stateid_t *stateid) |
| 1572 | { |
| 1573 | struct nfsd4_copy *copy; |
| 1574 | |
| 1575 | spin_lock(&clp->async_lock); |
| 1576 | list_for_each_entry(copy, &clp->async_copies, copies) { |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1577 | if (memcmp(©->cp_stateid.stid, stateid, NFS4_STATEID_SIZE)) |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1578 | continue; |
| 1579 | refcount_inc(©->refcount); |
| 1580 | spin_unlock(&clp->async_lock); |
| 1581 | return copy; |
| 1582 | } |
| 1583 | spin_unlock(&clp->async_lock); |
| 1584 | return NULL; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | static __be32 |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 1588 | nfsd4_offload_cancel(struct svc_rqst *rqstp, |
| 1589 | struct nfsd4_compound_state *cstate, |
| 1590 | union nfsd4_op_u *u) |
| 1591 | { |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1592 | struct nfsd4_offload_status *os = &u->offload_status; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1593 | struct nfsd4_copy *copy; |
| 1594 | struct nfs4_client *clp = cstate->clp; |
| 1595 | |
| 1596 | copy = find_async_copy(clp, &os->stateid); |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1597 | if (!copy) { |
| 1598 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1599 | |
Olga Kornievskaia | ce0887a | 2019-10-09 11:50:48 -0400 | [diff] [blame] | 1600 | return manage_cpntf_state(nn, &os->stateid, clp, NULL); |
| 1601 | } else |
| 1602 | nfsd4_stop_copy(copy); |
| 1603 | |
| 1604 | return nfs_ok; |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1608 | nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 1609 | union nfsd4_op_u *u) |
| 1610 | { |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1611 | struct nfsd4_copy_notify *cn = &u->copy_notify; |
| 1612 | __be32 status; |
| 1613 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
| 1614 | struct nfs4_stid *stid; |
| 1615 | struct nfs4_cpntf_state *cps; |
| 1616 | struct nfs4_client *clp = cstate->clp; |
| 1617 | |
| 1618 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
| 1619 | &cn->cpn_src_stateid, RD_STATE, NULL, |
| 1620 | &stid); |
| 1621 | if (status) |
| 1622 | return status; |
| 1623 | |
| 1624 | cn->cpn_sec = nn->nfsd4_lease; |
| 1625 | cn->cpn_nsec = 0; |
| 1626 | |
| 1627 | status = nfserrno(-ENOMEM); |
| 1628 | cps = nfs4_alloc_init_cpntf_state(nn, stid); |
| 1629 | if (!cps) |
| 1630 | goto out; |
| 1631 | memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.stid, sizeof(stateid_t)); |
| 1632 | memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t)); |
| 1633 | memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t)); |
| 1634 | |
| 1635 | /* For now, only return one server address in cpn_src, the |
| 1636 | * address used by the client to connect to this server. |
| 1637 | */ |
| 1638 | cn->cpn_src.nl4_type = NL4_NETADDR; |
| 1639 | status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, |
| 1640 | &cn->cpn_src.u.nl4_addr); |
| 1641 | WARN_ON_ONCE(status); |
| 1642 | if (status) { |
| 1643 | nfs4_put_cpntf_state(nn, cps); |
| 1644 | goto out; |
| 1645 | } |
| 1646 | out: |
| 1647 | nfs4_put_stid(stid); |
| 1648 | return status; |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | static __be32 |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1652 | nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 1653 | struct nfsd4_fallocate *fallocate, int flags) |
| 1654 | { |
J. Bruce Fields | 0d4d672 | 2018-11-06 17:44:03 -0500 | [diff] [blame] | 1655 | __be32 status; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1656 | struct nfsd_file *nf; |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1657 | |
Anna Schumaker | aa0d6ae | 2015-12-03 12:59:51 +0100 | [diff] [blame] | 1658 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1659 | &fallocate->falloc_stateid, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1660 | WR_STATE, &nf, NULL); |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1661 | if (status != nfs_ok) { |
| 1662 | dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); |
| 1663 | return status; |
| 1664 | } |
| 1665 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1666 | status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file, |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1667 | fallocate->falloc_offset, |
| 1668 | fallocate->falloc_length, |
| 1669 | flags); |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1670 | nfsd_file_put(nf); |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1671 | return status; |
| 1672 | } |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 1673 | static __be32 |
| 1674 | nfsd4_offload_status(struct svc_rqst *rqstp, |
| 1675 | struct nfsd4_compound_state *cstate, |
| 1676 | union nfsd4_op_u *u) |
| 1677 | { |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 1678 | struct nfsd4_offload_status *os = &u->offload_status; |
| 1679 | __be32 status = 0; |
| 1680 | struct nfsd4_copy *copy; |
| 1681 | struct nfs4_client *clp = cstate->clp; |
| 1682 | |
| 1683 | copy = find_async_copy(clp, &os->stateid); |
| 1684 | if (copy) { |
| 1685 | os->count = copy->cp_res.wr_bytes_written; |
| 1686 | nfs4_put_copy(copy); |
| 1687 | } else |
| 1688 | status = nfserr_bad_stateid; |
| 1689 | |
| 1690 | return status; |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 1691 | } |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1692 | |
| 1693 | static __be32 |
| 1694 | nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1695 | union nfsd4_op_u *u) |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1696 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1697 | return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0); |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | static __be32 |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 1701 | nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1702 | union nfsd4_op_u *u) |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 1703 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1704 | return nfsd4_fallocate(rqstp, cstate, &u->deallocate, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 1705 | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); |
| 1706 | } |
| 1707 | |
| 1708 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1709 | nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1710 | union nfsd4_op_u *u) |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1711 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1712 | struct nfsd4_seek *seek = &u->seek; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1713 | int whence; |
| 1714 | __be32 status; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1715 | struct nfsd_file *nf; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1716 | |
Anna Schumaker | aa0d6ae | 2015-12-03 12:59:51 +0100 | [diff] [blame] | 1717 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1718 | &seek->seek_stateid, |
Olga Kornievskaia | 624322f | 2019-10-04 16:34:26 -0400 | [diff] [blame] | 1719 | RD_STATE, &nf, NULL); |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1720 | if (status) { |
| 1721 | dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); |
| 1722 | return status; |
| 1723 | } |
| 1724 | |
| 1725 | switch (seek->seek_whence) { |
| 1726 | case NFS4_CONTENT_DATA: |
| 1727 | whence = SEEK_DATA; |
| 1728 | break; |
| 1729 | case NFS4_CONTENT_HOLE: |
| 1730 | whence = SEEK_HOLE; |
| 1731 | break; |
| 1732 | default: |
| 1733 | status = nfserr_union_notsupp; |
| 1734 | goto out; |
| 1735 | } |
| 1736 | |
| 1737 | /* |
| 1738 | * Note: This call does change file->f_pos, but nothing in NFSD |
| 1739 | * should ever file->f_pos. |
| 1740 | */ |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1741 | seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence); |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1742 | if (seek->seek_pos < 0) |
| 1743 | status = nfserrno(seek->seek_pos); |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1744 | else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file))) |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1745 | seek->seek_eof = true; |
| 1746 | |
| 1747 | out: |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 1748 | nfsd_file_put(nf); |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1749 | return status; |
| 1750 | } |
| 1751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | /* This routine never returns NFS_OK! If there are no other errors, it |
| 1753 | * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the |
| 1754 | * attributes matched. VERIFY is implemented by mapping NFSERR_SAME |
| 1755 | * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. |
| 1756 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1757 | static __be32 |
J.Bruce Fields | c954e2a | 2006-12-13 00:35:31 -0800 | [diff] [blame] | 1758 | _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 1759 | struct nfsd4_verify *verify) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | { |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1761 | __be32 *buf, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | int count; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1763 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 1765 | status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | if (status) |
| 1767 | return status; |
| 1768 | |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 1769 | status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); |
| 1770 | if (status) |
| 1771 | return status; |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) |
| 1774 | || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) |
| 1775 | return nfserr_inval; |
| 1776 | if (verify->ve_attrlen & 3) |
| 1777 | return nfserr_inval; |
| 1778 | |
| 1779 | /* count in words: |
| 1780 | * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 |
| 1781 | */ |
| 1782 | count = 4 + (verify->ve_attrlen >> 2); |
| 1783 | buf = kmalloc(count << 2, GFP_KERNEL); |
| 1784 | if (!buf) |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame] | 1785 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 1787 | p = buf; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 1788 | status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 1789 | cstate->current_fh.fh_export, |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 1790 | cstate->current_fh.fh_dentry, |
| 1791 | verify->ve_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1792 | rqstp, 0); |
J. Bruce Fields | 41ae6e71 | 2013-08-21 15:32:50 -0400 | [diff] [blame] | 1793 | /* |
| 1794 | * If nfsd4_encode_fattr() ran out of space, assume that's because |
| 1795 | * the attributes are longer (hence different) than those given: |
| 1796 | */ |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 1797 | if (status == nfserr_resource) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | status = nfserr_not_same; |
| 1799 | if (status) |
| 1800 | goto out_kfree; |
| 1801 | |
Benny Halevy | 95ec28c | 2009-04-03 08:29:08 +0300 | [diff] [blame] | 1802 | /* skip bitmap */ |
| 1803 | p = buf + 1 + ntohl(buf[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | status = nfserr_not_same; |
| 1805 | if (ntohl(*p++) != verify->ve_attrlen) |
| 1806 | goto out_kfree; |
| 1807 | if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) |
| 1808 | status = nfserr_same; |
| 1809 | |
| 1810 | out_kfree: |
| 1811 | kfree(buf); |
| 1812 | return status; |
| 1813 | } |
| 1814 | |
J.Bruce Fields | c954e2a | 2006-12-13 00:35:31 -0800 | [diff] [blame] | 1815 | static __be32 |
| 1816 | nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1817 | union nfsd4_op_u *u) |
J.Bruce Fields | c954e2a | 2006-12-13 00:35:31 -0800 | [diff] [blame] | 1818 | { |
| 1819 | __be32 status; |
| 1820 | |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1821 | status = _nfsd4_verify(rqstp, cstate, &u->verify); |
J.Bruce Fields | c954e2a | 2006-12-13 00:35:31 -0800 | [diff] [blame] | 1822 | return status == nfserr_not_same ? nfs_ok : status; |
| 1823 | } |
| 1824 | |
| 1825 | static __be32 |
| 1826 | nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1827 | union nfsd4_op_u *u) |
J.Bruce Fields | c954e2a | 2006-12-13 00:35:31 -0800 | [diff] [blame] | 1828 | { |
| 1829 | __be32 status; |
| 1830 | |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1831 | status = _nfsd4_verify(rqstp, cstate, &u->nverify); |
J.Bruce Fields | c954e2a | 2006-12-13 00:35:31 -0800 | [diff] [blame] | 1832 | return status == nfserr_same ? nfs_ok : status; |
| 1833 | } |
| 1834 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1835 | #ifdef CONFIG_NFSD_PNFS |
| 1836 | static const struct nfsd4_layout_ops * |
| 1837 | nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) |
| 1838 | { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 1839 | if (!exp->ex_layout_types) { |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1840 | dprintk("%s: export does not support pNFS\n", __func__); |
| 1841 | return NULL; |
| 1842 | } |
| 1843 | |
Ari Kauppi | b550a32 | 2017-05-05 16:07:55 -0400 | [diff] [blame] | 1844 | if (layout_type >= LAYOUT_TYPE_MAX || |
| 1845 | !(exp->ex_layout_types & (1 << layout_type))) { |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1846 | dprintk("%s: layout type %d not supported\n", |
| 1847 | __func__, layout_type); |
| 1848 | return NULL; |
| 1849 | } |
| 1850 | |
| 1851 | return nfsd4_layout_ops[layout_type]; |
| 1852 | } |
| 1853 | |
| 1854 | static __be32 |
| 1855 | nfsd4_getdeviceinfo(struct svc_rqst *rqstp, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1856 | struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1857 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1858 | struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1859 | const struct nfsd4_layout_ops *ops; |
| 1860 | struct nfsd4_deviceid_map *map; |
| 1861 | struct svc_export *exp; |
| 1862 | __be32 nfserr; |
| 1863 | |
| 1864 | dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", |
| 1865 | __func__, |
| 1866 | gdp->gd_layout_type, |
| 1867 | gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, |
| 1868 | gdp->gd_maxcount); |
| 1869 | |
| 1870 | map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); |
| 1871 | if (!map) { |
| 1872 | dprintk("%s: couldn't find device ID to export mapping!\n", |
| 1873 | __func__); |
| 1874 | return nfserr_noent; |
| 1875 | } |
| 1876 | |
| 1877 | exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); |
| 1878 | if (IS_ERR(exp)) { |
| 1879 | dprintk("%s: could not find device id\n", __func__); |
| 1880 | return nfserr_noent; |
| 1881 | } |
| 1882 | |
| 1883 | nfserr = nfserr_layoutunavailable; |
| 1884 | ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); |
| 1885 | if (!ops) |
| 1886 | goto out; |
| 1887 | |
| 1888 | nfserr = nfs_ok; |
Christoph Hellwig | f99d4fb | 2016-03-04 20:46:17 +0100 | [diff] [blame] | 1889 | if (gdp->gd_maxcount != 0) { |
| 1890 | nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, |
Tom Haynes | d7c920d | 2016-06-14 13:41:27 -0700 | [diff] [blame] | 1891 | rqstp, cstate->session->se_client, gdp); |
Christoph Hellwig | f99d4fb | 2016-03-04 20:46:17 +0100 | [diff] [blame] | 1892 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1893 | |
| 1894 | gdp->gd_notify_types &= ops->notify_types; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1895 | out: |
Kinglong Mee | a142038 | 2015-03-15 23:12:15 +0800 | [diff] [blame] | 1896 | exp_put(exp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1897 | return nfserr; |
| 1898 | } |
| 1899 | |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 1900 | static void |
| 1901 | nfsd4_getdeviceinfo_release(union nfsd4_op_u *u) |
| 1902 | { |
| 1903 | kfree(u->getdeviceinfo.gd_device); |
| 1904 | } |
| 1905 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1906 | static __be32 |
| 1907 | nfsd4_layoutget(struct svc_rqst *rqstp, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1908 | struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1909 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1910 | struct nfsd4_layoutget *lgp = &u->layoutget; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1911 | struct svc_fh *current_fh = &cstate->current_fh; |
| 1912 | const struct nfsd4_layout_ops *ops; |
| 1913 | struct nfs4_layout_stateid *ls; |
| 1914 | __be32 nfserr; |
Benjamin Coddington | 66282ec | 2017-12-19 09:35:25 -0500 | [diff] [blame] | 1915 | int accmode = NFSD_MAY_READ_IF_EXEC; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1916 | |
| 1917 | switch (lgp->lg_seg.iomode) { |
| 1918 | case IOMODE_READ: |
Benjamin Coddington | 66282ec | 2017-12-19 09:35:25 -0500 | [diff] [blame] | 1919 | accmode |= NFSD_MAY_READ; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1920 | break; |
| 1921 | case IOMODE_RW: |
Benjamin Coddington | 66282ec | 2017-12-19 09:35:25 -0500 | [diff] [blame] | 1922 | accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1923 | break; |
| 1924 | default: |
| 1925 | dprintk("%s: invalid iomode %d\n", |
| 1926 | __func__, lgp->lg_seg.iomode); |
| 1927 | nfserr = nfserr_badiomode; |
| 1928 | goto out; |
| 1929 | } |
| 1930 | |
| 1931 | nfserr = fh_verify(rqstp, current_fh, 0, accmode); |
| 1932 | if (nfserr) |
| 1933 | goto out; |
| 1934 | |
| 1935 | nfserr = nfserr_layoutunavailable; |
| 1936 | ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); |
| 1937 | if (!ops) |
| 1938 | goto out; |
| 1939 | |
| 1940 | /* |
| 1941 | * Verify minlength and range as per RFC5661: |
| 1942 | * o If loga_length is less than loga_minlength, |
| 1943 | * the metadata server MUST return NFS4ERR_INVAL. |
| 1944 | * o If the sum of loga_offset and loga_minlength exceeds |
| 1945 | * NFS4_UINT64_MAX, and loga_minlength is not |
| 1946 | * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. |
| 1947 | * o If the sum of loga_offset and loga_length exceeds |
| 1948 | * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, |
| 1949 | * the error NFS4ERR_INVAL MUST result. |
| 1950 | */ |
| 1951 | nfserr = nfserr_inval; |
| 1952 | if (lgp->lg_seg.length < lgp->lg_minlength || |
| 1953 | (lgp->lg_minlength != NFS4_MAX_UINT64 && |
| 1954 | lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || |
| 1955 | (lgp->lg_seg.length != NFS4_MAX_UINT64 && |
| 1956 | lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) |
| 1957 | goto out; |
| 1958 | if (lgp->lg_seg.length == 0) |
| 1959 | goto out; |
| 1960 | |
| 1961 | nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, |
| 1962 | true, lgp->lg_layout_type, &ls); |
Christoph Hellwig | 31ef83d | 2014-08-16 19:02:22 -0500 | [diff] [blame] | 1963 | if (nfserr) { |
Chuck Lever | f394b62 | 2018-03-27 10:53:11 -0400 | [diff] [blame] | 1964 | trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1965 | goto out; |
Christoph Hellwig | 31ef83d | 2014-08-16 19:02:22 -0500 | [diff] [blame] | 1966 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1967 | |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 1968 | nfserr = nfserr_recallconflict; |
| 1969 | if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) |
| 1970 | goto out_put_stid; |
| 1971 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1972 | nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1973 | current_fh, lgp); |
| 1974 | if (nfserr) |
| 1975 | goto out_put_stid; |
| 1976 | |
| 1977 | nfserr = nfsd4_insert_layout(lgp, ls); |
| 1978 | |
| 1979 | out_put_stid: |
Jeff Layton | cc8a553 | 2015-09-17 07:58:24 -0400 | [diff] [blame] | 1980 | mutex_unlock(&ls->ls_mutex); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1981 | nfs4_put_stid(&ls->ls_stid); |
| 1982 | out: |
| 1983 | return nfserr; |
| 1984 | } |
| 1985 | |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 1986 | static void |
| 1987 | nfsd4_layoutget_release(union nfsd4_op_u *u) |
| 1988 | { |
| 1989 | kfree(u->layoutget.lg_content); |
| 1990 | } |
| 1991 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1992 | static __be32 |
| 1993 | nfsd4_layoutcommit(struct svc_rqst *rqstp, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1994 | struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1995 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 1996 | struct nfsd4_layoutcommit *lcp = &u->layoutcommit; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1997 | const struct nfsd4_layout_seg *seg = &lcp->lc_seg; |
| 1998 | struct svc_fh *current_fh = &cstate->current_fh; |
| 1999 | const struct nfsd4_layout_ops *ops; |
| 2000 | loff_t new_size = lcp->lc_last_wr + 1; |
| 2001 | struct inode *inode; |
| 2002 | struct nfs4_layout_stateid *ls; |
| 2003 | __be32 nfserr; |
| 2004 | |
| 2005 | nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); |
| 2006 | if (nfserr) |
| 2007 | goto out; |
| 2008 | |
| 2009 | nfserr = nfserr_layoutunavailable; |
| 2010 | ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); |
| 2011 | if (!ops) |
| 2012 | goto out; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2013 | inode = d_inode(current_fh->fh_dentry); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2014 | |
| 2015 | nfserr = nfserr_inval; |
| 2016 | if (new_size <= seg->offset) { |
| 2017 | dprintk("pnfsd: last write before layout segment\n"); |
| 2018 | goto out; |
| 2019 | } |
| 2020 | if (new_size > seg->offset + seg->length) { |
| 2021 | dprintk("pnfsd: last write beyond layout segment\n"); |
| 2022 | goto out; |
| 2023 | } |
| 2024 | if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { |
| 2025 | dprintk("pnfsd: layoutcommit beyond EOF\n"); |
| 2026 | goto out; |
| 2027 | } |
| 2028 | |
| 2029 | nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, |
| 2030 | false, lcp->lc_layout_type, |
| 2031 | &ls); |
| 2032 | if (nfserr) { |
Chuck Lever | f394b62 | 2018-03-27 10:53:11 -0400 | [diff] [blame] | 2033 | trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2034 | /* fixup error code as per RFC5661 */ |
| 2035 | if (nfserr == nfserr_bad_stateid) |
| 2036 | nfserr = nfserr_badlayout; |
| 2037 | goto out; |
| 2038 | } |
| 2039 | |
Jeff Layton | cc8a553 | 2015-09-17 07:58:24 -0400 | [diff] [blame] | 2040 | /* LAYOUTCOMMIT does not require any serialization */ |
| 2041 | mutex_unlock(&ls->ls_mutex); |
| 2042 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2043 | if (new_size > i_size_read(inode)) { |
| 2044 | lcp->lc_size_chg = 1; |
| 2045 | lcp->lc_newsize = new_size; |
| 2046 | } else { |
| 2047 | lcp->lc_size_chg = 0; |
| 2048 | } |
| 2049 | |
Kinglong Mee | d8398fc | 2015-07-07 10:12:03 +0800 | [diff] [blame] | 2050 | nfserr = ops->proc_layoutcommit(inode, lcp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2051 | nfs4_put_stid(&ls->ls_stid); |
| 2052 | out: |
| 2053 | return nfserr; |
| 2054 | } |
| 2055 | |
| 2056 | static __be32 |
| 2057 | nfsd4_layoutreturn(struct svc_rqst *rqstp, |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2058 | struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2059 | { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2060 | struct nfsd4_layoutreturn *lrp = &u->layoutreturn; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2061 | struct svc_fh *current_fh = &cstate->current_fh; |
| 2062 | __be32 nfserr; |
| 2063 | |
| 2064 | nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); |
| 2065 | if (nfserr) |
| 2066 | goto out; |
| 2067 | |
| 2068 | nfserr = nfserr_layoutunavailable; |
| 2069 | if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) |
| 2070 | goto out; |
| 2071 | |
| 2072 | switch (lrp->lr_seg.iomode) { |
| 2073 | case IOMODE_READ: |
| 2074 | case IOMODE_RW: |
| 2075 | case IOMODE_ANY: |
| 2076 | break; |
| 2077 | default: |
| 2078 | dprintk("%s: invalid iomode %d\n", __func__, |
| 2079 | lrp->lr_seg.iomode); |
| 2080 | nfserr = nfserr_inval; |
| 2081 | goto out; |
| 2082 | } |
| 2083 | |
| 2084 | switch (lrp->lr_return_type) { |
| 2085 | case RETURN_FILE: |
| 2086 | nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); |
| 2087 | break; |
| 2088 | case RETURN_FSID: |
| 2089 | case RETURN_ALL: |
| 2090 | nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); |
| 2091 | break; |
| 2092 | default: |
| 2093 | dprintk("%s: invalid return_type %d\n", __func__, |
| 2094 | lrp->lr_return_type); |
| 2095 | nfserr = nfserr_inval; |
| 2096 | break; |
| 2097 | } |
| 2098 | out: |
| 2099 | return nfserr; |
| 2100 | } |
| 2101 | #endif /* CONFIG_NFSD_PNFS */ |
| 2102 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2103 | static __be32 |
| 2104 | nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 2105 | union nfsd4_op_u *u) |
| 2106 | { |
| 2107 | struct nfsd4_getxattr *getxattr = &u->getxattr; |
| 2108 | |
| 2109 | return nfsd_getxattr(rqstp, &cstate->current_fh, |
| 2110 | getxattr->getxa_name, &getxattr->getxa_buf, |
| 2111 | &getxattr->getxa_len); |
| 2112 | } |
| 2113 | |
| 2114 | static __be32 |
| 2115 | nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 2116 | union nfsd4_op_u *u) |
| 2117 | { |
| 2118 | struct nfsd4_setxattr *setxattr = &u->setxattr; |
| 2119 | __be32 ret; |
| 2120 | |
| 2121 | if (opens_in_grace(SVC_NET(rqstp))) |
| 2122 | return nfserr_grace; |
| 2123 | |
| 2124 | ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name, |
| 2125 | setxattr->setxa_buf, setxattr->setxa_len, |
| 2126 | setxattr->setxa_flags); |
| 2127 | |
| 2128 | if (!ret) |
| 2129 | set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh); |
| 2130 | |
| 2131 | return ret; |
| 2132 | } |
| 2133 | |
| 2134 | static __be32 |
| 2135 | nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 2136 | union nfsd4_op_u *u) |
| 2137 | { |
| 2138 | /* |
| 2139 | * Get the entire list, then copy out only the user attributes |
| 2140 | * in the encode function. |
| 2141 | */ |
| 2142 | return nfsd_listxattr(rqstp, &cstate->current_fh, |
| 2143 | &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len); |
| 2144 | } |
| 2145 | |
| 2146 | static __be32 |
| 2147 | nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 2148 | union nfsd4_op_u *u) |
| 2149 | { |
| 2150 | struct nfsd4_removexattr *removexattr = &u->removexattr; |
| 2151 | __be32 ret; |
| 2152 | |
| 2153 | if (opens_in_grace(SVC_NET(rqstp))) |
| 2154 | return nfserr_grace; |
| 2155 | |
| 2156 | ret = nfsd_removexattr(rqstp, &cstate->current_fh, |
| 2157 | removexattr->rmxa_name); |
| 2158 | |
| 2159 | if (!ret) |
| 2160 | set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh); |
| 2161 | |
| 2162 | return ret; |
| 2163 | } |
| 2164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | /* |
| 2166 | * NULL call. |
| 2167 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 2168 | static __be32 |
Christoph Hellwig | a6beb73 | 2017-05-08 17:35:49 +0200 | [diff] [blame] | 2169 | nfsd4_proc_null(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | { |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 2171 | return rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Shankar Anand | e2b2095 | 2006-07-10 04:45:44 -0700 | [diff] [blame] | 2174 | static inline void nfsd4_increment_op_stats(u32 opnum) |
| 2175 | { |
| 2176 | if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame^] | 2177 | percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_NFS4_OP(opnum)]); |
Shankar Anand | e2b2095 | 2006-07-10 04:45:44 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Christoph Hellwig | bb2a8b0 | 2017-05-08 23:46:47 +0200 | [diff] [blame] | 2180 | static const struct nfsd4_operation nfsd4_ops[]; |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2181 | |
Adrian Bunk | f1c7f79 | 2008-08-08 19:26:42 +0300 | [diff] [blame] | 2182 | static const char *nfsd4_op_name(unsigned opnum); |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | /* |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2185 | * Enforce NFSv4.1 COMPOUND ordering rules: |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2186 | * |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2187 | * Also note, enforced elsewhere: |
| 2188 | * - SEQUENCE other than as first op results in |
| 2189 | * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2190 | * - BIND_CONN_TO_SESSION must be the only op in its compound. |
| 2191 | * (Enforced in nfsd4_bind_conn_to_session().) |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2192 | * - DESTROY_SESSION must be the final operation in a compound, if |
| 2193 | * sessionid's in SEQUENCE and DESTROY_SESSION are the same. |
| 2194 | * (Enforced in nfsd4_destroy_session().) |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2195 | */ |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2196 | static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2197 | { |
J. Bruce Fields | 7a04cfd | 2018-06-13 15:04:59 -0400 | [diff] [blame] | 2198 | struct nfsd4_op *first_op = &args->ops[0]; |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2199 | |
| 2200 | /* These ordering requirements don't apply to NFSv4.0: */ |
| 2201 | if (args->minorversion == 0) |
| 2202 | return nfs_ok; |
| 2203 | /* This is weird, but OK, not our problem: */ |
| 2204 | if (args->opcnt == 0) |
| 2205 | return nfs_ok; |
J. Bruce Fields | 7a04cfd | 2018-06-13 15:04:59 -0400 | [diff] [blame] | 2206 | if (first_op->status == nfserr_op_illegal) |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2207 | return nfs_ok; |
J. Bruce Fields | 7a04cfd | 2018-06-13 15:04:59 -0400 | [diff] [blame] | 2208 | if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2209 | return nfserr_op_not_in_session; |
J. Bruce Fields | 7a04cfd | 2018-06-13 15:04:59 -0400 | [diff] [blame] | 2210 | if (first_op->opnum == OP_SEQUENCE) |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2211 | return nfs_ok; |
J. Bruce Fields | 7a04cfd | 2018-06-13 15:04:59 -0400 | [diff] [blame] | 2212 | /* |
| 2213 | * So first_op is something allowed outside a session, like |
| 2214 | * EXCHANGE_ID; but then it has to be the only op in the |
| 2215 | * compound: |
| 2216 | */ |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2217 | if (args->opcnt != 1) |
| 2218 | return nfserr_not_only_op; |
| 2219 | return nfs_ok; |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2220 | } |
| 2221 | |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2222 | const struct nfsd4_operation *OPDESC(struct nfsd4_op *op) |
J. Bruce Fields | 22b0321 | 2011-04-09 11:23:24 -0400 | [diff] [blame] | 2223 | { |
| 2224 | return &nfsd4_ops[op->opnum]; |
| 2225 | } |
| 2226 | |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2227 | bool nfsd4_cache_this_op(struct nfsd4_op *op) |
| 2228 | { |
J. Bruce Fields | e372ba6 | 2014-05-19 12:27:11 -0400 | [diff] [blame] | 2229 | if (op->opnum == OP_ILLEGAL) |
| 2230 | return false; |
J. Bruce Fields | c856694 | 2011-09-20 08:49:51 -0400 | [diff] [blame] | 2231 | return OPDESC(op)->op_flags & OP_CACHEME; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2232 | } |
| 2233 | |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2234 | static bool need_wrongsec_check(struct svc_rqst *rqstp) |
| 2235 | { |
| 2236 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2237 | struct nfsd4_compoundargs *argp = rqstp->rq_argp; |
| 2238 | struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; |
| 2239 | struct nfsd4_op *next = &argp->ops[resp->opcnt]; |
Christoph Hellwig | bb2a8b0 | 2017-05-08 23:46:47 +0200 | [diff] [blame] | 2240 | const struct nfsd4_operation *thisd = OPDESC(this); |
| 2241 | const struct nfsd4_operation *nextd; |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2242 | |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2243 | /* |
| 2244 | * Most ops check wronsec on our own; only the putfh-like ops |
| 2245 | * have special rules. |
| 2246 | */ |
| 2247 | if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) |
| 2248 | return false; |
| 2249 | /* |
| 2250 | * rfc 5661 2.6.3.1.1.6: don't bother erroring out a |
| 2251 | * put-filehandle operation if we're not going to use the |
| 2252 | * result: |
| 2253 | */ |
| 2254 | if (argp->opcnt == resp->opcnt) |
| 2255 | return false; |
J. Bruce Fields | 51904b0 | 2014-10-22 14:46:29 -0400 | [diff] [blame] | 2256 | if (next->opnum == OP_ILLEGAL) |
| 2257 | return false; |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2258 | nextd = OPDESC(next); |
| 2259 | /* |
| 2260 | * Rest of 2.6.3.1.1: certain operations will return WRONGSEC |
| 2261 | * errors themselves as necessary; others should check for them |
| 2262 | * now: |
| 2263 | */ |
| 2264 | return !(nextd->op_flags & OP_HANDLES_WRONGSEC); |
| 2265 | } |
| 2266 | |
J. Bruce Fields | 2d124dfaa | 2014-01-15 16:26:42 -0500 | [diff] [blame] | 2267 | static void svcxdr_init_encode(struct svc_rqst *rqstp, |
| 2268 | struct nfsd4_compoundres *resp) |
| 2269 | { |
| 2270 | struct xdr_stream *xdr = &resp->xdr; |
| 2271 | struct xdr_buf *buf = &rqstp->rq_res; |
| 2272 | struct kvec *head = buf->head; |
| 2273 | |
| 2274 | xdr->buf = buf; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2275 | xdr->iov = head; |
J. Bruce Fields | 2d124dfaa | 2014-01-15 16:26:42 -0500 | [diff] [blame] | 2276 | xdr->p = head->iov_base + head->iov_len; |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2277 | xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; |
J. Bruce Fields | 6ac9039 | 2014-02-26 17:39:35 -0500 | [diff] [blame] | 2278 | /* Tail and page_len should be zero at this point: */ |
| 2279 | buf->len = buf->head[0].iov_len; |
Chuck Lever | 0ae4c3e | 2020-11-11 15:52:47 -0500 | [diff] [blame] | 2280 | xdr_reset_scratch_buffer(xdr); |
J. Bruce Fields | 05638dc | 2014-06-02 12:05:47 -0400 | [diff] [blame] | 2281 | xdr->page_ptr = buf->pages - 1; |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 2282 | buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2283 | - rqstp->rq_auth_slack; |
J. Bruce Fields | 2d124dfaa | 2014-01-15 16:26:42 -0500 | [diff] [blame] | 2284 | } |
| 2285 | |
Olga Kornievskaia | b9e8638 | 2019-10-07 10:56:48 -0400 | [diff] [blame] | 2286 | #ifdef CONFIG_NFSD_V4_2_INTER_SSC |
| 2287 | static void |
| 2288 | check_if_stalefh_allowed(struct nfsd4_compoundargs *args) |
| 2289 | { |
| 2290 | struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL; |
| 2291 | struct nfsd4_copy *copy; |
| 2292 | struct nfsd4_putfh *putfh; |
| 2293 | int i; |
| 2294 | |
| 2295 | /* traverse all operation and if it's a COPY compound, mark the |
| 2296 | * source filehandle to skip verification |
| 2297 | */ |
| 2298 | for (i = 0; i < args->opcnt; i++) { |
| 2299 | op = &args->ops[i]; |
| 2300 | if (op->opnum == OP_PUTFH) |
| 2301 | current_op = op; |
| 2302 | else if (op->opnum == OP_SAVEFH) |
| 2303 | saved_op = current_op; |
| 2304 | else if (op->opnum == OP_RESTOREFH) |
| 2305 | current_op = saved_op; |
| 2306 | else if (op->opnum == OP_COPY) { |
| 2307 | copy = (struct nfsd4_copy *)&op->u; |
| 2308 | if (!saved_op) { |
| 2309 | op->status = nfserr_nofilehandle; |
| 2310 | return; |
| 2311 | } |
| 2312 | putfh = (struct nfsd4_putfh *)&saved_op->u; |
| 2313 | if (!copy->cp_intra) |
| 2314 | putfh->no_verify = true; |
| 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | #else |
| 2319 | static void |
| 2320 | check_if_stalefh_allowed(struct nfsd4_compoundargs *args) |
| 2321 | { |
| 2322 | } |
| 2323 | #endif |
| 2324 | |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2325 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | * COMPOUND call. |
| 2327 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 2328 | static __be32 |
Christoph Hellwig | a6beb73 | 2017-05-08 17:35:49 +0200 | [diff] [blame] | 2329 | nfsd4_proc_compound(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | { |
Christoph Hellwig | a6beb73 | 2017-05-08 17:35:49 +0200 | [diff] [blame] | 2331 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 2332 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | struct nfsd4_op *op; |
Andy Adamson | e354d57 | 2009-03-28 11:30:52 +0300 | [diff] [blame] | 2334 | struct nfsd4_compound_state *cstate = &resp->cstate; |
Kinglong Mee | 4daeed2 | 2014-03-26 17:10:37 +0800 | [diff] [blame] | 2335 | struct svc_fh *current_fh = &cstate->current_fh; |
| 2336 | struct svc_fh *save_fh = &cstate->save_fh; |
Trond Myklebust | e333f3b | 2019-04-09 11:46:19 -0400 | [diff] [blame] | 2337 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2338 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
J. Bruce Fields | 2d124dfaa | 2014-01-15 16:26:42 -0500 | [diff] [blame] | 2340 | svcxdr_init_encode(rqstp, resp); |
J. Bruce Fields | 4aea24b | 2014-01-15 15:17:58 -0500 | [diff] [blame] | 2341 | resp->tagp = resp->xdr.p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | /* reserve space for: taglen, tag, and opcnt */ |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 2343 | xdr_reserve_space(&resp->xdr, 8 + args->taglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | resp->taglen = args->taglen; |
| 2345 | resp->tag = args->tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | resp->rqstp = rqstp; |
Kinglong Mee | 4daeed2 | 2014-03-26 17:10:37 +0800 | [diff] [blame] | 2347 | cstate->minorversion = args->minorversion; |
Kinglong Mee | 4daeed2 | 2014-03-26 17:10:37 +0800 | [diff] [blame] | 2348 | fh_init(current_fh, NFS4_FHSIZE); |
| 2349 | fh_init(save_fh, NFS4_FHSIZE); |
NeilBrown | 8ff30fa | 2010-08-12 17:04:07 +1000 | [diff] [blame] | 2350 | /* |
| 2351 | * Don't use the deferral mechanism for NFSv4; compounds make it |
| 2352 | * too hard to avoid non-idempotency problems. |
| 2353 | */ |
Jeff Layton | 30660e04b | 2014-11-19 07:51:16 -0500 | [diff] [blame] | 2354 | clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | |
| 2356 | /* |
| 2357 | * According to RFC3010, this takes precedence over all other errors. |
| 2358 | */ |
| 2359 | status = nfserr_minor_vers_mismatch; |
Trond Myklebust | e333f3b | 2019-04-09 11:46:19 -0400 | [diff] [blame] | 2360 | if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | goto out; |
J. Bruce Fields | 0078117 | 2017-11-15 12:30:27 -0500 | [diff] [blame] | 2362 | status = nfserr_resource; |
| 2363 | if (args->opcnt > NFSD_MAX_OPS_PER_COMPOUND) |
| 2364 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2366 | status = nfs41_check_op_ordering(args); |
| 2367 | if (status) { |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2368 | op = &args->ops[0]; |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 2369 | op->status = status; |
J. Bruce Fields | 5b7b15ae | 2018-06-13 15:21:35 -0400 | [diff] [blame] | 2370 | resp->opcnt = 1; |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2371 | goto encode_op; |
| 2372 | } |
Olga Kornievskaia | b9e8638 | 2019-10-07 10:56:48 -0400 | [diff] [blame] | 2373 | check_if_stalefh_allowed(args); |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 2374 | |
J. Bruce Fields | 28df3d1 | 2017-07-28 16:35:15 -0400 | [diff] [blame] | 2375 | rqstp->rq_lease_breaker = (void **)&cstate->clp; |
| 2376 | |
Chuck Lever | fff4080 | 2018-03-27 10:53:54 -0400 | [diff] [blame] | 2377 | trace_nfsd_compound(rqstp, args->opcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | while (!status && resp->opcnt < args->opcnt) { |
| 2379 | op = &args->ops[resp->opcnt++]; |
| 2380 | |
| 2381 | /* |
| 2382 | * The XDR decode routines may have pre-set op->status; |
| 2383 | * for example, if there is a miscellaneous XDR error |
| 2384 | * it will be set to nfserr_bad_xdr. |
| 2385 | */ |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 2386 | if (op->status) { |
| 2387 | if (op->opnum == OP_OPEN) |
| 2388 | op->status = nfsd4_open_omfg(rqstp, cstate, op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | goto encode_op; |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 2390 | } |
Olga Kornievskaia | b9e8638 | 2019-10-07 10:56:48 -0400 | [diff] [blame] | 2391 | if (!current_fh->fh_dentry && |
| 2392 | !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2393 | if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2394 | op->status = nfserr_nofilehandle; |
| 2395 | goto encode_op; |
| 2396 | } |
Olga Kornievskaia | b9e8638 | 2019-10-07 10:56:48 -0400 | [diff] [blame] | 2397 | } else if (current_fh->fh_export && |
| 2398 | current_fh->fh_export->ex_fslocs.migrated && |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2399 | !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2400 | op->status = nfserr_moved; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | goto encode_op; |
| 2402 | } |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2403 | |
Kinglong Mee | 2336745 | 2014-03-29 10:23:47 +0800 | [diff] [blame] | 2404 | fh_clear_wcc(current_fh); |
| 2405 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2406 | /* If op is non-idempotent */ |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2407 | if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) { |
J. Bruce Fields | 4c69d58 | 2014-01-28 16:01:04 -0500 | [diff] [blame] | 2408 | /* |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 2409 | * Don't execute this op if we couldn't encode a |
| 2410 | * succesful reply: |
| 2411 | */ |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2412 | u32 plen = op->opdesc->op_rsize_bop(rqstp, op); |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 2413 | /* |
| 2414 | * Plus if there's another operation, make sure |
J. Bruce Fields | 4c69d58 | 2014-01-28 16:01:04 -0500 | [diff] [blame] | 2415 | * we'll have space to at least encode an error: |
| 2416 | */ |
| 2417 | if (resp->opcnt < args->opcnt) |
| 2418 | plen += COMPOUND_ERR_SLACK_SPACE; |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2419 | op->status = nfsd4_check_resp_size(resp, plen); |
| 2420 | } |
| 2421 | |
| 2422 | if (op->status) |
| 2423 | goto encode_op; |
| 2424 | |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2425 | if (op->opdesc->op_get_currentstateid) |
| 2426 | op->opdesc->op_get_currentstateid(cstate, &op->u); |
| 2427 | op->status = op->opdesc->op_func(rqstp, cstate, &op->u); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | |
J. Bruce Fields | 9a30740 | 2017-05-23 12:24:40 -0400 | [diff] [blame] | 2429 | /* Only from SEQUENCE */ |
| 2430 | if (cstate->status == nfserr_replay_cache) { |
| 2431 | dprintk("%s NFS4.1 replay from cache\n", __func__); |
| 2432 | status = op->status; |
| 2433 | goto out; |
| 2434 | } |
Tigran Mkrtchyan | 8b70484 | 2012-02-13 22:55:24 +0100 | [diff] [blame] | 2435 | if (!op->status) { |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2436 | if (op->opdesc->op_set_currentstateid) |
| 2437 | op->opdesc->op_set_currentstateid(cstate, &op->u); |
Tigran Mkrtchyan | 8b70484 | 2012-02-13 22:55:24 +0100 | [diff] [blame] | 2438 | |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2439 | if (op->opdesc->op_flags & OP_CLEAR_STATEID) |
Tigran Mkrtchyan | 37c593c | 2012-02-13 22:55:32 +0100 | [diff] [blame] | 2440 | clear_current_stateid(cstate); |
Tigran Mkrtchyan | 8b70484 | 2012-02-13 22:55:24 +0100 | [diff] [blame] | 2441 | |
J. Bruce Fields | d781e3d | 2019-12-06 16:07:32 -0500 | [diff] [blame] | 2442 | if (current_fh->fh_export && |
| 2443 | need_wrongsec_check(rqstp)) |
Kinglong Mee | 4daeed2 | 2014-03-26 17:10:37 +0800 | [diff] [blame] | 2444 | op->status = check_nfsd_access(current_fh->fh_export, rqstp); |
Tigran Mkrtchyan | 8b70484 | 2012-02-13 22:55:24 +0100 | [diff] [blame] | 2445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | encode_op: |
Al Viro | a90b061 | 2006-10-19 23:29:03 -0700 | [diff] [blame] | 2447 | if (op->status == nfserr_replay_me) { |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 2448 | op->replay = &cstate->replay_owner->so_replay; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 2449 | nfsd4_encode_replay(&resp->xdr, op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | status = op->status = op->replay->rp_status; |
| 2451 | } else { |
| 2452 | nfsd4_encode_operation(resp, op); |
| 2453 | status = op->status; |
| 2454 | } |
Benny Halevy | 0407717 | 2008-12-15 19:40:49 +0200 | [diff] [blame] | 2455 | |
Chuck Lever | fff4080 | 2018-03-27 10:53:54 -0400 | [diff] [blame] | 2456 | trace_nfsd_compound_status(args->opcnt, resp->opcnt, status, |
| 2457 | nfsd4_op_name(op->opnum)); |
Benny Halevy | 0407717 | 2008-12-15 19:40:49 +0200 | [diff] [blame] | 2458 | |
Jeff Layton | 58fb12e | 2014-07-29 21:34:27 -0400 | [diff] [blame] | 2459 | nfsd4_cstate_clear_replay(cstate); |
Shankar Anand | e2b2095 | 2006-07-10 04:45:44 -0700 | [diff] [blame] | 2460 | nfsd4_increment_op_stats(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
Kinglong Mee | 4daeed2 | 2014-03-26 17:10:37 +0800 | [diff] [blame] | 2463 | fh_put(current_fh); |
| 2464 | fh_put(save_fh); |
| 2465 | BUG_ON(cstate->replay_owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | out: |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 2467 | cstate->status = status; |
Andy Adamson | 2f42587 | 2009-04-03 08:27:32 +0300 | [diff] [blame] | 2468 | /* Reset deferral mechanism for RPC deferrals */ |
Jeff Layton | 30660e04b | 2014-11-19 07:51:16 -0500 | [diff] [blame] | 2469 | set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 2470 | return rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2473 | #define op_encode_hdr_size (2) |
| 2474 | #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) |
| 2475 | #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) |
| 2476 | #define op_encode_change_info_maxsz (5) |
| 2477 | #define nfs4_fattr_bitmap_maxsz (4) |
| 2478 | |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 2479 | /* We'll fall back on returning no lockowner if run out of space: */ |
| 2480 | #define op_encode_lockowner_maxsz (0) |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2481 | #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) |
| 2482 | |
| 2483 | #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
| 2484 | |
| 2485 | #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) |
| 2486 | #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ |
| 2487 | op_encode_ace_maxsz) |
| 2488 | |
| 2489 | #define op_encode_channel_attrs_maxsz (6 + 1 + 1) |
| 2490 | |
| 2491 | static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2492 | { |
| 2493 | return (op_encode_hdr_size) * sizeof(__be32); |
| 2494 | } |
| 2495 | |
| 2496 | static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2497 | { |
| 2498 | return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); |
| 2499 | } |
| 2500 | |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2501 | static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2502 | { |
| 2503 | /* ac_supported, ac_resp_access */ |
| 2504 | return (op_encode_hdr_size + 2)* sizeof(__be32); |
| 2505 | } |
| 2506 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2507 | static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2508 | { |
| 2509 | return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); |
| 2510 | } |
| 2511 | |
| 2512 | static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2513 | { |
| 2514 | return (op_encode_hdr_size + op_encode_change_info_maxsz |
| 2515 | + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); |
| 2516 | } |
| 2517 | |
J. Bruce Fields | b86cef6 | 2014-03-23 12:01:48 -0400 | [diff] [blame] | 2518 | /* |
| 2519 | * Note since this is an idempotent operation we won't insist on failing |
| 2520 | * the op prematurely if the estimate is too large. We may turn off splice |
| 2521 | * reads unnecessarily. |
| 2522 | */ |
| 2523 | static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, |
| 2524 | struct nfsd4_op *op) |
| 2525 | { |
| 2526 | u32 *bmap = op->u.getattr.ga_bmval; |
| 2527 | u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; |
| 2528 | u32 ret = 0; |
| 2529 | |
| 2530 | if (bmap0 & FATTR4_WORD0_ACL) |
| 2531 | return svc_max_payload(rqstp); |
| 2532 | if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2533 | return svc_max_payload(rqstp); |
| 2534 | |
| 2535 | if (bmap1 & FATTR4_WORD1_OWNER) { |
| 2536 | ret += IDMAP_NAMESZ + 4; |
| 2537 | bmap1 &= ~FATTR4_WORD1_OWNER; |
| 2538 | } |
| 2539 | if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { |
| 2540 | ret += IDMAP_NAMESZ + 4; |
| 2541 | bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; |
| 2542 | } |
| 2543 | if (bmap0 & FATTR4_WORD0_FILEHANDLE) { |
| 2544 | ret += NFS4_FHSIZE + 4; |
| 2545 | bmap0 &= ~FATTR4_WORD0_FILEHANDLE; |
| 2546 | } |
| 2547 | if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { |
Kinglong Mee | 1ec8c0c | 2015-03-28 23:46:09 +0800 | [diff] [blame] | 2548 | ret += NFS4_MAXLABELLEN + 12; |
J. Bruce Fields | b86cef6 | 2014-03-23 12:01:48 -0400 | [diff] [blame] | 2549 | bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2550 | } |
| 2551 | /* |
| 2552 | * Largest of remaining attributes are 16 bytes (e.g., |
| 2553 | * supported_attributes) |
| 2554 | */ |
| 2555 | ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); |
| 2556 | /* bitmask, length */ |
| 2557 | ret += 20; |
| 2558 | return ret; |
| 2559 | } |
| 2560 | |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2561 | static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2562 | { |
| 2563 | return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; |
| 2564 | } |
| 2565 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2566 | static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2567 | { |
| 2568 | return (op_encode_hdr_size + op_encode_change_info_maxsz) |
| 2569 | * sizeof(__be32); |
| 2570 | } |
| 2571 | |
| 2572 | static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2573 | { |
| 2574 | return (op_encode_hdr_size + op_encode_lock_denied_maxsz) |
| 2575 | * sizeof(__be32); |
| 2576 | } |
| 2577 | |
| 2578 | static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2579 | { |
| 2580 | return (op_encode_hdr_size + op_encode_stateid_maxsz |
| 2581 | + op_encode_change_info_maxsz + 1 |
| 2582 | + nfs4_fattr_bitmap_maxsz |
| 2583 | + op_encode_delegation_maxsz) * sizeof(__be32); |
| 2584 | } |
| 2585 | |
| 2586 | static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2587 | { |
| 2588 | u32 maxcount = 0, rlen = 0; |
| 2589 | |
| 2590 | maxcount = svc_max_payload(rqstp); |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 2591 | rlen = min(op->u.read.rd_length, maxcount); |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2592 | |
J. Bruce Fields | 622f560 | 2014-05-16 14:38:20 -0400 | [diff] [blame] | 2593 | return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2594 | } |
| 2595 | |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2596 | static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2597 | { |
| 2598 | u32 maxcount = svc_max_payload(rqstp); |
| 2599 | u32 rlen = min(op->u.read.rd_length, maxcount); |
| 2600 | /* |
| 2601 | * If we detect that the file changed during hole encoding, then we |
| 2602 | * recover by encoding the remaining reply as data. This means we need |
| 2603 | * to set aside enough room to encode two data segments. |
| 2604 | */ |
| 2605 | u32 seg_len = 2 * (1 + 2 + 1); |
| 2606 | |
| 2607 | return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32); |
| 2608 | } |
| 2609 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2610 | static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2611 | { |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 2612 | u32 maxcount = 0, rlen = 0; |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2613 | |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 2614 | maxcount = svc_max_payload(rqstp); |
| 2615 | rlen = min(op->u.readdir.rd_maxcount, maxcount); |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2616 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 2617 | return (op_encode_hdr_size + op_encode_verifier_maxsz + |
| 2618 | XDR_QUADLEN(rlen)) * sizeof(__be32); |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2619 | } |
| 2620 | |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2621 | static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2622 | { |
| 2623 | return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; |
| 2624 | } |
| 2625 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2626 | static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2627 | { |
| 2628 | return (op_encode_hdr_size + op_encode_change_info_maxsz) |
| 2629 | * sizeof(__be32); |
| 2630 | } |
| 2631 | |
| 2632 | static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2633 | { |
| 2634 | return (op_encode_hdr_size + op_encode_change_info_maxsz |
| 2635 | + op_encode_change_info_maxsz) * sizeof(__be32); |
| 2636 | } |
| 2637 | |
J. Bruce Fields | ccae70a | 2014-03-23 09:34:22 -0700 | [diff] [blame] | 2638 | static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, |
| 2639 | struct nfsd4_op *op) |
| 2640 | { |
J. Bruce Fields | d1d84c9 | 2014-08-21 15:04:31 -0400 | [diff] [blame] | 2641 | return (op_encode_hdr_size |
| 2642 | + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); |
J. Bruce Fields | ccae70a | 2014-03-23 09:34:22 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2645 | static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2646 | { |
| 2647 | return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) |
| 2648 | * sizeof(__be32); |
| 2649 | } |
| 2650 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2651 | static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2652 | { |
| 2653 | return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); |
| 2654 | } |
| 2655 | |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2656 | static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2657 | { |
| 2658 | return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * |
| 2659 | (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); |
| 2660 | } |
| 2661 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2662 | static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2663 | { |
J. Bruce Fields | 480efae | 2014-03-10 14:17:55 -0400 | [diff] [blame] | 2664 | return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * |
| 2665 | sizeof(__be32); |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2669 | { |
J. Bruce Fields | f34e432 | 2014-05-16 21:24:56 -0400 | [diff] [blame] | 2670 | return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2674 | { |
| 2675 | return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 2676 | 1 + 1 + /* eir_flags, spr_how */\ |
| 2677 | 4 + /* spo_must_enforce & _allow with bitmap */\ |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2678 | 2 + /*eir_server_owner.so_minor_id */\ |
| 2679 | /* eir_server_owner.so_major_id<> */\ |
| 2680 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ |
| 2681 | /* eir_server_scope<> */\ |
| 2682 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ |
| 2683 | 1 + /* eir_server_impl_id array length */\ |
| 2684 | 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); |
| 2685 | } |
| 2686 | |
| 2687 | static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2688 | { |
| 2689 | return (op_encode_hdr_size + \ |
| 2690 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ |
| 2691 | 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); |
| 2692 | } |
| 2693 | |
| 2694 | static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2695 | { |
| 2696 | return (op_encode_hdr_size + \ |
| 2697 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ |
| 2698 | 2 + /* csr_sequence, csr_flags */\ |
| 2699 | op_encode_channel_attrs_maxsz + \ |
| 2700 | op_encode_channel_attrs_maxsz) * sizeof(__be32); |
| 2701 | } |
| 2702 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2703 | static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2704 | { |
| 2705 | return (op_encode_hdr_size + |
| 2706 | 1 /* wr_callback */ + |
| 2707 | op_encode_stateid_maxsz /* wr_callback */ + |
| 2708 | 2 /* wr_count */ + |
| 2709 | 1 /* wr_committed */ + |
| 2710 | op_encode_verifier_maxsz + |
| 2711 | 1 /* cr_consecutive */ + |
| 2712 | 1 /* cr_synchronous */) * sizeof(__be32); |
| 2713 | } |
| 2714 | |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2715 | static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, |
| 2716 | struct nfsd4_op *op) |
| 2717 | { |
| 2718 | return (op_encode_hdr_size + |
| 2719 | 2 /* osr_count */ + |
| 2720 | 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); |
| 2721 | } |
| 2722 | |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2723 | static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, |
| 2724 | struct nfsd4_op *op) |
| 2725 | { |
| 2726 | return (op_encode_hdr_size + |
| 2727 | 3 /* cnr_lease_time */ + |
| 2728 | 1 /* We support one cnr_source_server */ + |
| 2729 | 1 /* cnr_stateid seq */ + |
| 2730 | op_encode_stateid_maxsz /* cnr_stateid */ + |
| 2731 | 1 /* num cnr_source_server*/ + |
| 2732 | 1 /* nl4_type */ + |
| 2733 | 1 /* nl4 size */ + |
| 2734 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) |
| 2735 | * sizeof(__be32); |
| 2736 | } |
| 2737 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2738 | #ifdef CONFIG_NFSD_PNFS |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2739 | static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2740 | { |
| 2741 | u32 maxcount = 0, rlen = 0; |
| 2742 | |
| 2743 | maxcount = svc_max_payload(rqstp); |
| 2744 | rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); |
| 2745 | |
| 2746 | return (op_encode_hdr_size + |
| 2747 | 1 /* gd_layout_type*/ + |
| 2748 | XDR_QUADLEN(rlen) + |
| 2749 | 2 /* gd_notify_types */) * sizeof(__be32); |
| 2750 | } |
| 2751 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2752 | /* |
| 2753 | * At this stage we don't really know what layout driver will handle the request, |
| 2754 | * so we need to define an arbitrary upper bound here. |
| 2755 | */ |
| 2756 | #define MAX_LAYOUT_SIZE 128 |
| 2757 | static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2758 | { |
| 2759 | return (op_encode_hdr_size + |
| 2760 | 1 /* logr_return_on_close */ + |
| 2761 | op_encode_stateid_maxsz + |
| 2762 | 1 /* nr of layouts */ + |
| 2763 | MAX_LAYOUT_SIZE) * sizeof(__be32); |
| 2764 | } |
| 2765 | |
| 2766 | static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2767 | { |
| 2768 | return (op_encode_hdr_size + |
| 2769 | 1 /* locr_newsize */ + |
| 2770 | 2 /* ns_size */) * sizeof(__be32); |
| 2771 | } |
| 2772 | |
| 2773 | static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2774 | { |
| 2775 | return (op_encode_hdr_size + |
| 2776 | 1 /* lrs_stateid */ + |
| 2777 | op_encode_stateid_maxsz) * sizeof(__be32); |
| 2778 | } |
| 2779 | #endif /* CONFIG_NFSD_PNFS */ |
| 2780 | |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 2781 | |
| 2782 | static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2783 | { |
| 2784 | return (op_encode_hdr_size + 3) * sizeof(__be32); |
| 2785 | } |
| 2786 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2787 | static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp, |
| 2788 | struct nfsd4_op *op) |
| 2789 | { |
| 2790 | u32 maxcount, rlen; |
| 2791 | |
| 2792 | maxcount = svc_max_payload(rqstp); |
| 2793 | rlen = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2794 | |
| 2795 | return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); |
| 2796 | } |
| 2797 | |
| 2798 | static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp, |
| 2799 | struct nfsd4_op *op) |
| 2800 | { |
| 2801 | return (op_encode_hdr_size + op_encode_change_info_maxsz) |
| 2802 | * sizeof(__be32); |
| 2803 | } |
| 2804 | static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp, |
| 2805 | struct nfsd4_op *op) |
| 2806 | { |
| 2807 | u32 maxcount, rlen; |
| 2808 | |
| 2809 | maxcount = svc_max_payload(rqstp); |
| 2810 | rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount); |
| 2811 | |
| 2812 | return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); |
| 2813 | } |
| 2814 | |
| 2815 | static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp, |
| 2816 | struct nfsd4_op *op) |
| 2817 | { |
| 2818 | return (op_encode_hdr_size + op_encode_change_info_maxsz) |
| 2819 | * sizeof(__be32); |
| 2820 | } |
| 2821 | |
| 2822 | |
Christoph Hellwig | bb2a8b0 | 2017-05-08 23:46:47 +0200 | [diff] [blame] | 2823 | static const struct nfsd4_operation nfsd4_ops[] = { |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2824 | [OP_ACCESS] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2825 | .op_func = nfsd4_access, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2826 | .op_name = "OP_ACCESS", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2827 | .op_rsize_bop = nfsd4_access_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2828 | }, |
| 2829 | [OP_CLOSE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2830 | .op_func = nfsd4_close, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2831 | .op_flags = OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2832 | .op_name = "OP_CLOSE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2833 | .op_rsize_bop = nfsd4_status_stateid_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 2834 | .op_get_currentstateid = nfsd4_get_closestateid, |
Christoph Hellwig | b60e985 | 2017-05-08 20:03:15 +0200 | [diff] [blame] | 2835 | .op_set_currentstateid = nfsd4_set_closestateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2836 | }, |
| 2837 | [OP_COMMIT] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2838 | .op_func = nfsd4_commit, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2839 | .op_flags = OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2840 | .op_name = "OP_COMMIT", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2841 | .op_rsize_bop = nfsd4_commit_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2842 | }, |
| 2843 | [OP_CREATE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2844 | .op_func = nfsd4_create, |
Tigran Mkrtchyan | d147105 | 2012-02-13 22:55:29 +0100 | [diff] [blame] | 2845 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2846 | .op_name = "OP_CREATE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2847 | .op_rsize_bop = nfsd4_create_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2848 | }, |
| 2849 | [OP_DELEGRETURN] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2850 | .op_func = nfsd4_delegreturn, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2851 | .op_flags = OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2852 | .op_name = "OP_DELEGRETURN", |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2853 | .op_rsize_bop = nfsd4_only_status_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 2854 | .op_get_currentstateid = nfsd4_get_delegreturnstateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2855 | }, |
| 2856 | [OP_GETATTR] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2857 | .op_func = nfsd4_getattr, |
J.Bruce Fields | eeac294 | 2006-12-13 00:35:39 -0800 | [diff] [blame] | 2858 | .op_flags = ALLOWED_ON_ABSENT_FS, |
J. Bruce Fields | b86cef6 | 2014-03-23 12:01:48 -0400 | [diff] [blame] | 2859 | .op_rsize_bop = nfsd4_getattr_rsize, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2860 | .op_name = "OP_GETATTR", |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2861 | }, |
| 2862 | [OP_GETFH] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2863 | .op_func = nfsd4_getfh, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2864 | .op_name = "OP_GETFH", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2865 | .op_rsize_bop = nfsd4_getfh_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2866 | }, |
| 2867 | [OP_LINK] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2868 | .op_func = nfsd4_link, |
J. Bruce Fields | c856694 | 2011-09-20 08:49:51 -0400 | [diff] [blame] | 2869 | .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING |
| 2870 | | OP_CACHEME, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2871 | .op_name = "OP_LINK", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2872 | .op_rsize_bop = nfsd4_link_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2873 | }, |
| 2874 | [OP_LOCK] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2875 | .op_func = nfsd4_lock, |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 2876 | .op_flags = OP_MODIFIES_SOMETHING | |
| 2877 | OP_NONTRIVIAL_ERROR_ENCODE, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2878 | .op_name = "OP_LOCK", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2879 | .op_rsize_bop = nfsd4_lock_rsize, |
Christoph Hellwig | b60e985 | 2017-05-08 20:03:15 +0200 | [diff] [blame] | 2880 | .op_set_currentstateid = nfsd4_set_lockstateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2881 | }, |
| 2882 | [OP_LOCKT] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2883 | .op_func = nfsd4_lockt, |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 2884 | .op_flags = OP_NONTRIVIAL_ERROR_ENCODE, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2885 | .op_name = "OP_LOCKT", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2886 | .op_rsize_bop = nfsd4_lock_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2887 | }, |
| 2888 | [OP_LOCKU] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2889 | .op_func = nfsd4_locku, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2890 | .op_flags = OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2891 | .op_name = "OP_LOCKU", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2892 | .op_rsize_bop = nfsd4_status_stateid_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 2893 | .op_get_currentstateid = nfsd4_get_lockustateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2894 | }, |
| 2895 | [OP_LOOKUP] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2896 | .op_func = nfsd4_lookup, |
Tigran Mkrtchyan | d147105 | 2012-02-13 22:55:29 +0100 | [diff] [blame] | 2897 | .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2898 | .op_name = "OP_LOOKUP", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2899 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2900 | }, |
| 2901 | [OP_LOOKUPP] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2902 | .op_func = nfsd4_lookupp, |
Tigran Mkrtchyan | d147105 | 2012-02-13 22:55:29 +0100 | [diff] [blame] | 2903 | .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2904 | .op_name = "OP_LOOKUPP", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2905 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2906 | }, |
| 2907 | [OP_NVERIFY] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2908 | .op_func = nfsd4_nverify, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2909 | .op_name = "OP_NVERIFY", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2910 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2911 | }, |
| 2912 | [OP_OPEN] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2913 | .op_func = nfsd4_open, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2914 | .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2915 | .op_name = "OP_OPEN", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2916 | .op_rsize_bop = nfsd4_open_rsize, |
Christoph Hellwig | b60e985 | 2017-05-08 20:03:15 +0200 | [diff] [blame] | 2917 | .op_set_currentstateid = nfsd4_set_openstateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2918 | }, |
| 2919 | [OP_OPEN_CONFIRM] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2920 | .op_func = nfsd4_open_confirm, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2921 | .op_flags = OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2922 | .op_name = "OP_OPEN_CONFIRM", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2923 | .op_rsize_bop = nfsd4_status_stateid_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2924 | }, |
| 2925 | [OP_OPEN_DOWNGRADE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2926 | .op_func = nfsd4_open_downgrade, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2927 | .op_flags = OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2928 | .op_name = "OP_OPEN_DOWNGRADE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2929 | .op_rsize_bop = nfsd4_status_stateid_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 2930 | .op_get_currentstateid = nfsd4_get_opendowngradestateid, |
Christoph Hellwig | b60e985 | 2017-05-08 20:03:15 +0200 | [diff] [blame] | 2931 | .op_set_currentstateid = nfsd4_set_opendowngradestateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2932 | }, |
| 2933 | [OP_PUTFH] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2934 | .op_func = nfsd4_putfh, |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2935 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
J. Bruce Fields | 5b64869 | 2014-03-07 11:43:58 -0500 | [diff] [blame] | 2936 | | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2937 | .op_name = "OP_PUTFH", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2938 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2939 | }, |
J.Bruce Fields | eeac294 | 2006-12-13 00:35:39 -0800 | [diff] [blame] | 2940 | [OP_PUTPUBFH] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2941 | .op_func = nfsd4_putrootfh, |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2942 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
J. Bruce Fields | 5b64869 | 2014-03-07 11:43:58 -0500 | [diff] [blame] | 2943 | | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2944 | .op_name = "OP_PUTPUBFH", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2945 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | eeac294 | 2006-12-13 00:35:39 -0800 | [diff] [blame] | 2946 | }, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2947 | [OP_PUTROOTFH] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2948 | .op_func = nfsd4_putrootfh, |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2949 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
J. Bruce Fields | 5b64869 | 2014-03-07 11:43:58 -0500 | [diff] [blame] | 2950 | | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2951 | .op_name = "OP_PUTROOTFH", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2952 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2953 | }, |
| 2954 | [OP_READ] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2955 | .op_func = nfsd4_read, |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 2956 | .op_release = nfsd4_read_release, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2957 | .op_name = "OP_READ", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2958 | .op_rsize_bop = nfsd4_read_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 2959 | .op_get_currentstateid = nfsd4_get_readstateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2960 | }, |
| 2961 | [OP_READDIR] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2962 | .op_func = nfsd4_readdir, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2963 | .op_name = "OP_READDIR", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2964 | .op_rsize_bop = nfsd4_readdir_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2965 | }, |
| 2966 | [OP_READLINK] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2967 | .op_func = nfsd4_readlink, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2968 | .op_name = "OP_READLINK", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2969 | .op_rsize_bop = nfsd4_readlink_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2970 | }, |
| 2971 | [OP_REMOVE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2972 | .op_func = nfsd4_remove, |
J. Bruce Fields | c856694 | 2011-09-20 08:49:51 -0400 | [diff] [blame] | 2973 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2974 | .op_name = "OP_REMOVE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2975 | .op_rsize_bop = nfsd4_remove_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2976 | }, |
| 2977 | [OP_RENAME] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2978 | .op_func = nfsd4_rename, |
J. Bruce Fields | c856694 | 2011-09-20 08:49:51 -0400 | [diff] [blame] | 2979 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2980 | .op_name = "OP_RENAME", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2981 | .op_rsize_bop = nfsd4_rename_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2982 | }, |
| 2983 | [OP_RENEW] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2984 | .op_func = nfsd4_renew, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2985 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
| 2986 | | OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2987 | .op_name = "OP_RENEW", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2988 | .op_rsize_bop = nfsd4_only_status_rsize, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2989 | |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2990 | }, |
| 2991 | [OP_RESTOREFH] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2992 | .op_func = nfsd4_restorefh, |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 2993 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 2994 | | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 2995 | .op_name = "OP_RESTOREFH", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 2996 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2997 | }, |
| 2998 | [OP_SAVEFH] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 2999 | .op_func = nfsd4_savefh, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3000 | .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3001 | .op_name = "OP_SAVEFH", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3002 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3003 | }, |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3004 | [OP_SECINFO] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3005 | .op_func = nfsd4_secinfo, |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 3006 | .op_release = nfsd4_secinfo_release, |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 3007 | .op_flags = OP_HANDLES_WRONGSEC, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3008 | .op_name = "OP_SECINFO", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3009 | .op_rsize_bop = nfsd4_secinfo_rsize, |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3010 | }, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3011 | [OP_SETATTR] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3012 | .op_func = nfsd4_setattr, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3013 | .op_name = "OP_SETATTR", |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 3014 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME |
| 3015 | | OP_NONTRIVIAL_ERROR_ENCODE, |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3016 | .op_rsize_bop = nfsd4_setattr_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 3017 | .op_get_currentstateid = nfsd4_get_setattrstateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3018 | }, |
| 3019 | [OP_SETCLIENTID] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3020 | .op_func = nfsd4_setclientid, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3021 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 3022 | | OP_MODIFIES_SOMETHING | OP_CACHEME |
| 3023 | | OP_NONTRIVIAL_ERROR_ENCODE, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3024 | .op_name = "OP_SETCLIENTID", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3025 | .op_rsize_bop = nfsd4_setclientid_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3026 | }, |
| 3027 | [OP_SETCLIENTID_CONFIRM] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3028 | .op_func = nfsd4_setclientid_confirm, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3029 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
J. Bruce Fields | c856694 | 2011-09-20 08:49:51 -0400 | [diff] [blame] | 3030 | | OP_MODIFIES_SOMETHING | OP_CACHEME, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3031 | .op_name = "OP_SETCLIENTID_CONFIRM", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3032 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3033 | }, |
| 3034 | [OP_VERIFY] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3035 | .op_func = nfsd4_verify, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3036 | .op_name = "OP_VERIFY", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3037 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3038 | }, |
| 3039 | [OP_WRITE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3040 | .op_func = nfsd4_write, |
J. Bruce Fields | c856694 | 2011-09-20 08:49:51 -0400 | [diff] [blame] | 3041 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3042 | .op_name = "OP_WRITE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3043 | .op_rsize_bop = nfsd4_write_rsize, |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 3044 | .op_get_currentstateid = nfsd4_get_writestateid, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3045 | }, |
| 3046 | [OP_RELEASE_LOCKOWNER] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3047 | .op_func = nfsd4_release_lockowner, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3048 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
| 3049 | | OP_MODIFIES_SOMETHING, |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3050 | .op_name = "OP_RELEASE_LOCKOWNER", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3051 | .op_rsize_bop = nfsd4_only_status_rsize, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3052 | }, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3053 | |
| 3054 | /* NFSv4.1 operations */ |
| 3055 | [OP_EXCHANGE_ID] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3056 | .op_func = nfsd4_exchange_id, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3057 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
| 3058 | | OP_MODIFIES_SOMETHING, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3059 | .op_name = "OP_EXCHANGE_ID", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3060 | .op_rsize_bop = nfsd4_exchange_id_rsize, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3061 | }, |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 3062 | [OP_BACKCHANNEL_CTL] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3063 | .op_func = nfsd4_backchannel_ctl, |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 3064 | .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, |
| 3065 | .op_name = "OP_BACKCHANNEL_CTL", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3066 | .op_rsize_bop = nfsd4_only_status_rsize, |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 3067 | }, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3068 | [OP_BIND_CONN_TO_SESSION] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3069 | .op_func = nfsd4_bind_conn_to_session, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3070 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
| 3071 | | OP_MODIFIES_SOMETHING, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3072 | .op_name = "OP_BIND_CONN_TO_SESSION", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3073 | .op_rsize_bop = nfsd4_bind_conn_to_session_rsize, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3074 | }, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3075 | [OP_CREATE_SESSION] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3076 | .op_func = nfsd4_create_session, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3077 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
| 3078 | | OP_MODIFIES_SOMETHING, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3079 | .op_name = "OP_CREATE_SESSION", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3080 | .op_rsize_bop = nfsd4_create_session_rsize, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3081 | }, |
| 3082 | [OP_DESTROY_SESSION] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3083 | .op_func = nfsd4_destroy_session, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3084 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
| 3085 | | OP_MODIFIES_SOMETHING, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3086 | .op_name = "OP_DESTROY_SESSION", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3087 | .op_rsize_bop = nfsd4_only_status_rsize, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3088 | }, |
| 3089 | [OP_SEQUENCE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3090 | .op_func = nfsd4_sequence, |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 3091 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3092 | .op_name = "OP_SEQUENCE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3093 | .op_rsize_bop = nfsd4_sequence_rsize, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 3094 | }, |
Benny Halevy | 094b5d7 | 2011-06-16 11:39:10 -0400 | [diff] [blame] | 3095 | [OP_DESTROY_CLIENTID] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3096 | .op_func = nfsd4_destroy_clientid, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3097 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
| 3098 | | OP_MODIFIES_SOMETHING, |
Benny Halevy | 094b5d7 | 2011-06-16 11:39:10 -0400 | [diff] [blame] | 3099 | .op_name = "OP_DESTROY_CLIENTID", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3100 | .op_rsize_bop = nfsd4_only_status_rsize, |
Benny Halevy | 094b5d7 | 2011-06-16 11:39:10 -0400 | [diff] [blame] | 3101 | }, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 3102 | [OP_RECLAIM_COMPLETE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3103 | .op_func = nfsd4_reclaim_complete, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3104 | .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 3105 | .op_name = "OP_RECLAIM_COMPLETE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3106 | .op_rsize_bop = nfsd4_only_status_rsize, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 3107 | }, |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 3108 | [OP_SECINFO_NO_NAME] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3109 | .op_func = nfsd4_secinfo_no_name, |
Eryu Guan | ec572b9 | 2017-09-29 15:01:10 +0800 | [diff] [blame] | 3110 | .op_release = nfsd4_secinfo_no_name_release, |
J. Bruce Fields | 68d9318 | 2011-04-08 17:00:50 -0400 | [diff] [blame] | 3111 | .op_flags = OP_HANDLES_WRONGSEC, |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 3112 | .op_name = "OP_SECINFO_NO_NAME", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3113 | .op_rsize_bop = nfsd4_secinfo_rsize, |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 3114 | }, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3115 | [OP_TEST_STATEID] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3116 | .op_func = nfsd4_test_stateid, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3117 | .op_flags = ALLOWED_WITHOUT_FH, |
| 3118 | .op_name = "OP_TEST_STATEID", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3119 | .op_rsize_bop = nfsd4_test_stateid_rsize, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3120 | }, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3121 | [OP_FREE_STATEID] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3122 | .op_func = nfsd4_free_stateid, |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3123 | .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3124 | .op_name = "OP_FREE_STATEID", |
Christoph Hellwig | 57832e7 | 2017-05-08 20:37:33 +0200 | [diff] [blame] | 3125 | .op_get_currentstateid = nfsd4_get_freestateid, |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3126 | .op_rsize_bop = nfsd4_only_status_rsize, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3127 | }, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3128 | #ifdef CONFIG_NFSD_PNFS |
| 3129 | [OP_GETDEVICEINFO] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3130 | .op_func = nfsd4_getdeviceinfo, |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 3131 | .op_release = nfsd4_getdeviceinfo_release, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3132 | .op_flags = ALLOWED_WITHOUT_FH, |
| 3133 | .op_name = "OP_GETDEVICEINFO", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3134 | .op_rsize_bop = nfsd4_getdeviceinfo_rsize, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3135 | }, |
| 3136 | [OP_LAYOUTGET] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3137 | .op_func = nfsd4_layoutget, |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 3138 | .op_release = nfsd4_layoutget_release, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3139 | .op_flags = OP_MODIFIES_SOMETHING, |
| 3140 | .op_name = "OP_LAYOUTGET", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3141 | .op_rsize_bop = nfsd4_layoutget_rsize, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3142 | }, |
| 3143 | [OP_LAYOUTCOMMIT] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3144 | .op_func = nfsd4_layoutcommit, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3145 | .op_flags = OP_MODIFIES_SOMETHING, |
| 3146 | .op_name = "OP_LAYOUTCOMMIT", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3147 | .op_rsize_bop = nfsd4_layoutcommit_rsize, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3148 | }, |
| 3149 | [OP_LAYOUTRETURN] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3150 | .op_func = nfsd4_layoutreturn, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3151 | .op_flags = OP_MODIFIES_SOMETHING, |
| 3152 | .op_name = "OP_LAYOUTRETURN", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3153 | .op_rsize_bop = nfsd4_layoutreturn_rsize, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3154 | }, |
| 3155 | #endif /* CONFIG_NFSD_PNFS */ |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 3156 | |
| 3157 | /* NFSv4.2 operations */ |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 3158 | [OP_ALLOCATE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3159 | .op_func = nfsd4_allocate, |
Olga Kornievskaia | 03b31f4 | 2018-12-04 14:09:21 -0500 | [diff] [blame] | 3160 | .op_flags = OP_MODIFIES_SOMETHING, |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 3161 | .op_name = "OP_ALLOCATE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3162 | .op_rsize_bop = nfsd4_only_status_rsize, |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 3163 | }, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 3164 | [OP_DEALLOCATE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3165 | .op_func = nfsd4_deallocate, |
Olga Kornievskaia | 03b31f4 | 2018-12-04 14:09:21 -0500 | [diff] [blame] | 3166 | .op_flags = OP_MODIFIES_SOMETHING, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 3167 | .op_name = "OP_DEALLOCATE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3168 | .op_rsize_bop = nfsd4_only_status_rsize, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 3169 | }, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 3170 | [OP_CLONE] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3171 | .op_func = nfsd4_clone, |
Olga Kornievskaia | 03b31f4 | 2018-12-04 14:09:21 -0500 | [diff] [blame] | 3172 | .op_flags = OP_MODIFIES_SOMETHING, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 3173 | .op_name = "OP_CLONE", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3174 | .op_rsize_bop = nfsd4_only_status_rsize, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 3175 | }, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 3176 | [OP_COPY] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3177 | .op_func = nfsd4_copy, |
Olga Kornievskaia | 03b31f4 | 2018-12-04 14:09:21 -0500 | [diff] [blame] | 3178 | .op_flags = OP_MODIFIES_SOMETHING, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 3179 | .op_name = "OP_COPY", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3180 | .op_rsize_bop = nfsd4_copy_rsize, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 3181 | }, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 3182 | [OP_READ_PLUS] = { |
| 3183 | .op_func = nfsd4_read, |
| 3184 | .op_release = nfsd4_read_release, |
| 3185 | .op_name = "OP_READ_PLUS", |
| 3186 | .op_rsize_bop = nfsd4_read_plus_rsize, |
| 3187 | .op_get_currentstateid = nfsd4_get_readstateid, |
| 3188 | }, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 3189 | [OP_SEEK] = { |
Christoph Hellwig | eb69853 | 2017-05-08 20:58:35 +0200 | [diff] [blame] | 3190 | .op_func = nfsd4_seek, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 3191 | .op_name = "OP_SEEK", |
Christoph Hellwig | 1c12263 | 2017-05-08 20:42:10 +0200 | [diff] [blame] | 3192 | .op_rsize_bop = nfsd4_seek_rsize, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 3193 | }, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 3194 | [OP_OFFLOAD_STATUS] = { |
| 3195 | .op_func = nfsd4_offload_status, |
| 3196 | .op_name = "OP_OFFLOAD_STATUS", |
| 3197 | .op_rsize_bop = nfsd4_offload_status_rsize, |
| 3198 | }, |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 3199 | [OP_OFFLOAD_CANCEL] = { |
| 3200 | .op_func = nfsd4_offload_cancel, |
| 3201 | .op_flags = OP_MODIFIES_SOMETHING, |
| 3202 | .op_name = "OP_OFFLOAD_CANCEL", |
| 3203 | .op_rsize_bop = nfsd4_only_status_rsize, |
| 3204 | }, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 3205 | [OP_COPY_NOTIFY] = { |
| 3206 | .op_func = nfsd4_copy_notify, |
| 3207 | .op_flags = OP_MODIFIES_SOMETHING, |
| 3208 | .op_name = "OP_COPY_NOTIFY", |
| 3209 | .op_rsize_bop = nfsd4_copy_notify_rsize, |
| 3210 | }, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 3211 | [OP_GETXATTR] = { |
| 3212 | .op_func = nfsd4_getxattr, |
| 3213 | .op_name = "OP_GETXATTR", |
| 3214 | .op_rsize_bop = nfsd4_getxattr_rsize, |
| 3215 | }, |
| 3216 | [OP_SETXATTR] = { |
| 3217 | .op_func = nfsd4_setxattr, |
| 3218 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
| 3219 | .op_name = "OP_SETXATTR", |
| 3220 | .op_rsize_bop = nfsd4_setxattr_rsize, |
| 3221 | }, |
| 3222 | [OP_LISTXATTRS] = { |
| 3223 | .op_func = nfsd4_listxattrs, |
| 3224 | .op_name = "OP_LISTXATTRS", |
| 3225 | .op_rsize_bop = nfsd4_listxattrs_rsize, |
| 3226 | }, |
| 3227 | [OP_REMOVEXATTR] = { |
| 3228 | .op_func = nfsd4_removexattr, |
| 3229 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
| 3230 | .op_name = "OP_REMOVEXATTR", |
| 3231 | .op_rsize_bop = nfsd4_removexattr_rsize, |
| 3232 | }, |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 3233 | }; |
| 3234 | |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 3235 | /** |
| 3236 | * nfsd4_spo_must_allow - Determine if the compound op contains an |
| 3237 | * operation that is allowed to be sent with machine credentials |
| 3238 | * |
| 3239 | * @rqstp: a pointer to the struct svc_rqst |
| 3240 | * |
| 3241 | * Checks to see if the compound contains a spo_must_allow op |
| 3242 | * and confirms that it was sent with the proper machine creds. |
| 3243 | */ |
| 3244 | |
| 3245 | bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) |
| 3246 | { |
| 3247 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 3248 | struct nfsd4_compoundargs *argp = rqstp->rq_argp; |
| 3249 | struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; |
| 3250 | struct nfsd4_compound_state *cstate = &resp->cstate; |
| 3251 | struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; |
| 3252 | u32 opiter; |
| 3253 | |
| 3254 | if (!cstate->minorversion) |
| 3255 | return false; |
| 3256 | |
Zheng Bin | 44b49aa | 2020-09-11 12:10:14 +0800 | [diff] [blame] | 3257 | if (cstate->spo_must_allowed) |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 3258 | return true; |
| 3259 | |
| 3260 | opiter = resp->opcnt; |
| 3261 | while (opiter < argp->opcnt) { |
| 3262 | this = &argp->ops[opiter++]; |
| 3263 | if (test_bit(this->opnum, allow->u.longs) && |
| 3264 | cstate->clp->cl_mach_cred && |
| 3265 | nfsd4_mach_creds_match(cstate->clp, rqstp)) { |
| 3266 | cstate->spo_must_allowed = true; |
| 3267 | return true; |
| 3268 | } |
| 3269 | } |
| 3270 | cstate->spo_must_allowed = false; |
| 3271 | return false; |
| 3272 | } |
| 3273 | |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 3274 | int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 3275 | { |
Olga Kornievskaia | 05b7278 | 2017-03-23 14:36:20 -0400 | [diff] [blame] | 3276 | if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 3277 | return op_encode_hdr_size * sizeof(__be32); |
Kinglong Mee | 2282cd2 | 2017-02-03 22:36:00 +0800 | [diff] [blame] | 3278 | |
| 3279 | BUG_ON(OPDESC(op)->op_rsize_bop == NULL); |
| 3280 | return OPDESC(op)->op_rsize_bop(rqstp, op); |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 3281 | } |
| 3282 | |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 3283 | void warn_on_nonidempotent_op(struct nfsd4_op *op) |
| 3284 | { |
| 3285 | if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { |
Chuck Lever | 3a237b4 | 2020-11-22 12:49:52 -0500 | [diff] [blame] | 3286 | pr_err("unable to encode reply to nonidempotent op %u (%s)\n", |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 3287 | op->opnum, nfsd4_op_name(op->opnum)); |
| 3288 | WARN_ON_ONCE(1); |
| 3289 | } |
| 3290 | } |
| 3291 | |
Adrian Bunk | f1c7f79 | 2008-08-08 19:26:42 +0300 | [diff] [blame] | 3292 | static const char *nfsd4_op_name(unsigned opnum) |
Benny Halevy | b001a1b | 2008-07-02 11:15:03 +0300 | [diff] [blame] | 3293 | { |
| 3294 | if (opnum < ARRAY_SIZE(nfsd4_ops)) |
| 3295 | return nfsd4_ops[opnum].op_name; |
| 3296 | return "unknown_operation"; |
| 3297 | } |
| 3298 | |
Christoph Hellwig | 860bda2 | 2017-05-12 16:11:49 +0200 | [diff] [blame] | 3299 | static const struct svc_procedure nfsd_procedures4[2] = { |
Yu Zhiguo | 0a93a47 | 2009-05-19 14:09:54 +0800 | [diff] [blame] | 3300 | [NFSPROC4_NULL] = { |
Christoph Hellwig | f7235b6 | 2017-05-08 17:59:13 +0200 | [diff] [blame] | 3301 | .pc_func = nfsd4_proc_null, |
Chuck Lever | 788f718 | 2020-11-05 14:48:29 -0500 | [diff] [blame] | 3302 | .pc_decode = nfssvc_decode_voidarg, |
| 3303 | .pc_encode = nfssvc_encode_voidres, |
| 3304 | .pc_argsize = sizeof(struct nfsd_voidargs), |
| 3305 | .pc_ressize = sizeof(struct nfsd_voidres), |
Yu Zhiguo | 0a93a47 | 2009-05-19 14:09:54 +0800 | [diff] [blame] | 3306 | .pc_cachetype = RC_NOCACHE, |
| 3307 | .pc_xdrressize = 1, |
Chuck Lever | 2289e87 | 2020-09-17 17:22:49 -0400 | [diff] [blame] | 3308 | .pc_name = "NULL", |
Yu Zhiguo | 0a93a47 | 2009-05-19 14:09:54 +0800 | [diff] [blame] | 3309 | }, |
| 3310 | [NFSPROC4_COMPOUND] = { |
Christoph Hellwig | f7235b6 | 2017-05-08 17:59:13 +0200 | [diff] [blame] | 3311 | .pc_func = nfsd4_proc_compound, |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 3312 | .pc_decode = nfs4svc_decode_compoundargs, |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 3313 | .pc_encode = nfs4svc_encode_compoundres, |
Yu Zhiguo | 0a93a47 | 2009-05-19 14:09:54 +0800 | [diff] [blame] | 3314 | .pc_argsize = sizeof(struct nfsd4_compoundargs), |
| 3315 | .pc_ressize = sizeof(struct nfsd4_compoundres), |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 3316 | .pc_release = nfsd4_release_compoundargs, |
Yu Zhiguo | 0a93a47 | 2009-05-19 14:09:54 +0800 | [diff] [blame] | 3317 | .pc_cachetype = RC_NOCACHE, |
| 3318 | .pc_xdrressize = NFSD_BUFSIZE/4, |
Chuck Lever | 2289e87 | 2020-09-17 17:22:49 -0400 | [diff] [blame] | 3319 | .pc_name = "COMPOUND", |
Yu Zhiguo | 0a93a47 | 2009-05-19 14:09:54 +0800 | [diff] [blame] | 3320 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | }; |
| 3322 | |
Christoph Hellwig | 7fd38af | 2017-05-08 23:40:27 +0200 | [diff] [blame] | 3323 | static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures4)]; |
Christoph Hellwig | e967918 | 2017-05-12 16:21:37 +0200 | [diff] [blame] | 3324 | const struct svc_version nfsd_version4 = { |
Jeff Layton | 5283b03 | 2017-02-24 13:25:24 -0500 | [diff] [blame] | 3325 | .vs_vers = 4, |
| 3326 | .vs_nproc = 2, |
| 3327 | .vs_proc = nfsd_procedures4, |
Christoph Hellwig | 7fd38af | 2017-05-08 23:40:27 +0200 | [diff] [blame] | 3328 | .vs_count = nfsd_count3, |
Jeff Layton | 5283b03 | 2017-02-24 13:25:24 -0500 | [diff] [blame] | 3329 | .vs_dispatch = nfsd_dispatch, |
| 3330 | .vs_xdrsize = NFS4_SVC_XDRSIZE, |
| 3331 | .vs_rpcb_optnl = true, |
| 3332 | .vs_need_cong_ctrl = true, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | }; |
| 3334 | |
| 3335 | /* |
| 3336 | * Local variables: |
| 3337 | * c-basic-offset: 8 |
| 3338 | * End: |
| 3339 | */ |