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 XDR 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 | */ |
| 35 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 36 | #include <linux/file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/namei.h> |
Boaz Harrosh | 341eb18 | 2009-12-03 20:29:12 +0200 | [diff] [blame] | 39 | #include <linux/statfs.h> |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 40 | #include <linux/utsname.h> |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 41 | #include <linux/pagemap.h> |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 42 | #include <linux/sunrpc/svcauth_gss.h> |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 43 | #include <linux/sunrpc/addr.h> |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 44 | #include <linux/xattr.h> |
| 45 | #include <uapi/linux/xattr.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 46 | |
J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 47 | #include "idmap.h" |
| 48 | #include "acl.h" |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 49 | #include "xdr4.h" |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame] | 50 | #include "vfs.h" |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 51 | #include "state.h" |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 52 | #include "cache.h" |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 53 | #include "netns.h" |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 54 | #include "pnfs.h" |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 55 | #include "filecache.h" |
J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 56 | |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 57 | #include "trace.h" |
| 58 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 59 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 60 | #include <linux/security.h> |
| 61 | #endif |
| 62 | |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define NFSDDBG_FACILITY NFSDDBG_XDR |
| 65 | |
J. Bruce Fields | 5cf23db | 2017-01-11 20:40:36 -0500 | [diff] [blame] | 66 | const u32 nfsd_suppattrs[3][3] = { |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 67 | {NFSD4_SUPPORTED_ATTRS_WORD0, |
| 68 | NFSD4_SUPPORTED_ATTRS_WORD1, |
| 69 | NFSD4_SUPPORTED_ATTRS_WORD2}, |
| 70 | |
| 71 | {NFSD4_1_SUPPORTED_ATTRS_WORD0, |
| 72 | NFSD4_1_SUPPORTED_ATTRS_WORD1, |
| 73 | NFSD4_1_SUPPORTED_ATTRS_WORD2}, |
| 74 | |
| 75 | {NFSD4_1_SUPPORTED_ATTRS_WORD0, |
| 76 | NFSD4_1_SUPPORTED_ATTRS_WORD1, |
| 77 | NFSD4_2_SUPPORTED_ATTRS_WORD2}, |
| 78 | }; |
| 79 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 80 | /* |
| 81 | * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing |
| 82 | * directory in order to indicate to the client that a filesystem boundary is present |
| 83 | * We use a fixed fsid for a referral |
| 84 | */ |
| 85 | #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL |
| 86 | #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL |
| 87 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 88 | static __be32 |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 89 | check_filename(char *str, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | int i; |
| 92 | |
| 93 | if (len == 0) |
| 94 | return nfserr_inval; |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 95 | if (len > NFS4_MAXNAMLEN) |
| 96 | return nfserr_nametoolong; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (isdotent(str, len)) |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 98 | return nfserr_badname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | for (i = 0; i < len; i++) |
| 100 | if (str[i] == '/') |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 101 | return nfserr_badname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 105 | static int zero_clientid(clientid_t *clid) |
| 106 | { |
| 107 | return (clid->cl_boot == 0) && (clid->cl_id == 0); |
| 108 | } |
| 109 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 110 | /** |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 111 | * svcxdr_tmpalloc - allocate memory to be freed after compound processing |
J. Bruce Fields | ce043ac | 2014-06-24 16:51:12 -0400 | [diff] [blame] | 112 | * @argp: NFSv4 compound argument structure |
Trond Myklebust | ed99275 | 2019-08-18 14:18:59 -0400 | [diff] [blame] | 113 | * @len: length of buffer to allocate |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 114 | * |
Trond Myklebust | ed99275 | 2019-08-18 14:18:59 -0400 | [diff] [blame] | 115 | * Allocates a buffer of size @len to be freed when processing the compound |
| 116 | * operation described in @argp finishes. |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 117 | */ |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 118 | static void * |
| 119 | svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 121 | struct svcxdr_tmpbuf *tb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 123 | tb = kmalloc(sizeof(*tb) + len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (!tb) |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 125 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | tb->next = argp->to_free; |
| 127 | argp->to_free = tb; |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 128 | return tb->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 131 | /* |
| 132 | * For xdr strings that need to be passed to other kernel api's |
| 133 | * as null-terminated strings. |
| 134 | * |
| 135 | * Note null-terminating in place usually isn't safe since the |
| 136 | * buffer might end on a page boundary. |
| 137 | */ |
| 138 | static char * |
| 139 | svcxdr_dupstr(struct nfsd4_compoundargs *argp, void *buf, u32 len) |
| 140 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 141 | char *p = svcxdr_tmpalloc(argp, len + 1); |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 142 | |
| 143 | if (!p) |
| 144 | return NULL; |
| 145 | memcpy(p, buf, len); |
| 146 | p[len] = '\0'; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 147 | return p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Chuck Lever | 5dcbfab | 2020-11-04 11:41:55 -0500 | [diff] [blame] | 150 | /* |
| 151 | * NFSv4 basic data type decoders |
| 152 | */ |
| 153 | |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 154 | /* |
| 155 | * This helper handles variable-length opaques which belong to protocol |
| 156 | * elements that this implementation does not support. |
| 157 | */ |
| 158 | static __be32 |
| 159 | nfsd4_decode_ignored_string(struct nfsd4_compoundargs *argp, u32 maxlen) |
| 160 | { |
| 161 | u32 len; |
| 162 | |
| 163 | if (xdr_stream_decode_u32(argp->xdr, &len) < 0) |
| 164 | return nfserr_bad_xdr; |
| 165 | if (maxlen && len > maxlen) |
| 166 | return nfserr_bad_xdr; |
| 167 | if (!xdr_inline_decode(argp->xdr, len)) |
| 168 | return nfserr_bad_xdr; |
| 169 | |
| 170 | return nfs_ok; |
| 171 | } |
| 172 | |
Chuck Lever | 5dcbfab | 2020-11-04 11:41:55 -0500 | [diff] [blame] | 173 | static __be32 |
| 174 | nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
| 175 | { |
| 176 | __be32 *p; |
| 177 | u32 len; |
| 178 | |
| 179 | if (xdr_stream_decode_u32(argp->xdr, &len) < 0) |
| 180 | return nfserr_bad_xdr; |
| 181 | if (len == 0 || len > NFS4_OPAQUE_LIMIT) |
| 182 | return nfserr_bad_xdr; |
| 183 | p = xdr_inline_decode(argp->xdr, len); |
| 184 | if (!p) |
| 185 | return nfserr_bad_xdr; |
| 186 | o->data = svcxdr_tmpalloc(argp, len); |
| 187 | if (!o->data) |
| 188 | return nfserr_jukebox; |
| 189 | o->len = len; |
| 190 | memcpy(o->data, p, len); |
| 191 | |
| 192 | return nfs_ok; |
| 193 | } |
| 194 | |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 195 | static __be32 |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 196 | nfsd4_decode_component4(struct nfsd4_compoundargs *argp, char **namp, u32 *lenp) |
| 197 | { |
| 198 | __be32 *p, status; |
| 199 | |
| 200 | if (xdr_stream_decode_u32(argp->xdr, lenp) < 0) |
| 201 | return nfserr_bad_xdr; |
| 202 | p = xdr_inline_decode(argp->xdr, *lenp); |
| 203 | if (!p) |
| 204 | return nfserr_bad_xdr; |
| 205 | status = check_filename((char *)p, *lenp); |
| 206 | if (status) |
| 207 | return status; |
| 208 | *namp = svcxdr_tmpalloc(argp, *lenp); |
| 209 | if (!*namp) |
| 210 | return nfserr_jukebox; |
| 211 | memcpy(*namp, p, *lenp); |
| 212 | |
| 213 | return nfs_ok; |
| 214 | } |
| 215 | |
| 216 | static __be32 |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 217 | nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
| 218 | { |
| 219 | __be32 *p; |
| 220 | |
| 221 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 3); |
| 222 | if (!p) |
| 223 | return nfserr_bad_xdr; |
| 224 | p = xdr_decode_hyper(p, &tv->tv_sec); |
| 225 | tv->tv_nsec = be32_to_cpup(p++); |
| 226 | if (tv->tv_nsec >= (u32)1000000000) |
| 227 | return nfserr_inval; |
| 228 | return nfs_ok; |
| 229 | } |
| 230 | |
| 231 | static __be32 |
Chuck Lever | 796dd1c | 2020-11-16 17:34:01 -0500 | [diff] [blame] | 232 | nfsd4_decode_verifier4(struct nfsd4_compoundargs *argp, nfs4_verifier *verf) |
| 233 | { |
| 234 | __be32 *p; |
| 235 | |
| 236 | p = xdr_inline_decode(argp->xdr, NFS4_VERIFIER_SIZE); |
| 237 | if (!p) |
| 238 | return nfserr_bad_xdr; |
| 239 | memcpy(verf->data, p, sizeof(verf->data)); |
| 240 | return nfs_ok; |
| 241 | } |
| 242 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 243 | /** |
| 244 | * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4 |
| 245 | * @argp: NFSv4 compound argument structure |
| 246 | * @bmval: pointer to an array of u32's to decode into |
| 247 | * @bmlen: size of the @bmval array |
| 248 | * |
| 249 | * The server needs to return nfs_ok rather than nfserr_bad_xdr when |
| 250 | * encountering bitmaps containing bits it does not recognize. This |
| 251 | * includes bits in bitmap words past WORDn, where WORDn is the last |
| 252 | * bitmap WORD the implementation currently supports. Thus we are |
| 253 | * careful here to simply ignore bits in bitmap words that this |
| 254 | * implementation has yet to support explicitly. |
| 255 | * |
| 256 | * Return values: |
| 257 | * %nfs_ok: @bmval populated successfully |
| 258 | * %nfserr_bad_xdr: the encoded bitmap was invalid |
| 259 | */ |
| 260 | static __be32 |
| 261 | nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen) |
| 262 | { |
| 263 | u32 i, count; |
| 264 | __be32 *p; |
| 265 | |
| 266 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 267 | return nfserr_bad_xdr; |
| 268 | /* request sanity */ |
| 269 | if (count > 1000) |
| 270 | return nfserr_bad_xdr; |
| 271 | p = xdr_inline_decode(argp->xdr, count << 2); |
| 272 | if (!p) |
| 273 | return nfserr_bad_xdr; |
| 274 | i = 0; |
| 275 | while (i < count) |
| 276 | bmval[i++] = be32_to_cpup(p++); |
| 277 | while (i < bmlen) |
| 278 | bmval[i++] = 0; |
| 279 | |
| 280 | return nfs_ok; |
| 281 | } |
| 282 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 283 | static __be32 |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 284 | nfsd4_decode_nfsace4(struct nfsd4_compoundargs *argp, struct nfs4_ace *ace) |
| 285 | { |
| 286 | __be32 *p, status; |
| 287 | u32 length; |
| 288 | |
| 289 | if (xdr_stream_decode_u32(argp->xdr, &ace->type) < 0) |
| 290 | return nfserr_bad_xdr; |
| 291 | if (xdr_stream_decode_u32(argp->xdr, &ace->flag) < 0) |
| 292 | return nfserr_bad_xdr; |
| 293 | if (xdr_stream_decode_u32(argp->xdr, &ace->access_mask) < 0) |
| 294 | return nfserr_bad_xdr; |
| 295 | |
| 296 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 297 | return nfserr_bad_xdr; |
| 298 | p = xdr_inline_decode(argp->xdr, length); |
| 299 | if (!p) |
| 300 | return nfserr_bad_xdr; |
| 301 | ace->whotype = nfs4_acl_get_whotype((char *)p, length); |
| 302 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
| 303 | status = nfs_ok; |
| 304 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
| 305 | status = nfsd_map_name_to_gid(argp->rqstp, |
| 306 | (char *)p, length, &ace->who_gid); |
| 307 | else |
| 308 | status = nfsd_map_name_to_uid(argp->rqstp, |
| 309 | (char *)p, length, &ace->who_uid); |
| 310 | |
| 311 | return status; |
| 312 | } |
| 313 | |
| 314 | /* A counted array of nfsace4's */ |
| 315 | static noinline __be32 |
| 316 | nfsd4_decode_acl(struct nfsd4_compoundargs *argp, struct nfs4_acl **acl) |
| 317 | { |
| 318 | struct nfs4_ace *ace; |
| 319 | __be32 status; |
| 320 | u32 count; |
| 321 | |
| 322 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 323 | return nfserr_bad_xdr; |
| 324 | |
| 325 | if (count > xdr_stream_remaining(argp->xdr) / 20) |
| 326 | /* |
| 327 | * Even with 4-byte names there wouldn't be |
| 328 | * space for that many aces; something fishy is |
| 329 | * going on: |
| 330 | */ |
| 331 | return nfserr_fbig; |
| 332 | |
| 333 | *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(count)); |
| 334 | if (*acl == NULL) |
| 335 | return nfserr_jukebox; |
| 336 | |
| 337 | (*acl)->naces = count; |
| 338 | for (ace = (*acl)->aces; ace < (*acl)->aces + count; ace++) { |
| 339 | status = nfsd4_decode_nfsace4(argp, ace); |
| 340 | if (status) |
| 341 | return status; |
| 342 | } |
| 343 | |
| 344 | return nfs_ok; |
| 345 | } |
| 346 | |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 347 | static noinline __be32 |
| 348 | nfsd4_decode_security_label(struct nfsd4_compoundargs *argp, |
| 349 | struct xdr_netobj *label) |
| 350 | { |
| 351 | u32 lfs, pi, length; |
| 352 | __be32 *p; |
| 353 | |
| 354 | if (xdr_stream_decode_u32(argp->xdr, &lfs) < 0) |
| 355 | return nfserr_bad_xdr; |
| 356 | if (xdr_stream_decode_u32(argp->xdr, &pi) < 0) |
| 357 | return nfserr_bad_xdr; |
| 358 | |
| 359 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 360 | return nfserr_bad_xdr; |
| 361 | if (length > NFS4_MAXLABELLEN) |
| 362 | return nfserr_badlabel; |
| 363 | p = xdr_inline_decode(argp->xdr, length); |
| 364 | if (!p) |
| 365 | return nfserr_bad_xdr; |
| 366 | label->len = length; |
| 367 | label->data = svcxdr_dupstr(argp, p, length); |
| 368 | if (!label->data) |
| 369 | return nfserr_jukebox; |
| 370 | |
| 371 | return nfs_ok; |
| 372 | } |
| 373 | |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 374 | static __be32 |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 375 | nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, |
| 376 | struct iattr *iattr, struct nfs4_acl **acl, |
| 377 | struct xdr_netobj *label, int *umask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 379 | unsigned int starting_pos; |
| 380 | u32 attrlist4_count; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 381 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | iattr->ia_valid = 0; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 384 | status = nfsd4_decode_bitmap4(argp, bmval, bmlen); |
| 385 | if (status) |
| 386 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
J. Bruce Fields | e864c18 | 2016-06-10 16:56:05 -0400 | [diff] [blame] | 388 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
| 389 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 |
| 390 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) { |
| 391 | if (nfsd_attrs_supported(argp->minorversion, bmval)) |
| 392 | return nfserr_inval; |
| 393 | return nfserr_attrnotsupp; |
| 394 | } |
| 395 | |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 396 | if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0) |
| 397 | return nfserr_bad_xdr; |
| 398 | starting_pos = xdr_stream_pos(argp->xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
Chuck Lever | 2ac1b9b | 2020-11-19 13:47:16 -0500 | [diff] [blame] | 401 | u64 size; |
| 402 | |
| 403 | if (xdr_stream_decode_u64(argp->xdr, &size) < 0) |
| 404 | return nfserr_bad_xdr; |
| 405 | iattr->ia_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | iattr->ia_valid |= ATTR_SIZE; |
| 407 | } |
| 408 | if (bmval[0] & FATTR4_WORD0_ACL) { |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 409 | status = nfsd4_decode_acl(argp, acl); |
| 410 | if (status) |
| 411 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } else |
| 413 | *acl = NULL; |
| 414 | if (bmval[1] & FATTR4_WORD1_MODE) { |
Chuck Lever | 1c8f0ad | 2020-11-19 13:54:26 -0500 | [diff] [blame] | 415 | u32 mode; |
| 416 | |
| 417 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 418 | return nfserr_bad_xdr; |
| 419 | iattr->ia_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 421 | iattr->ia_valid |= ATTR_MODE; |
| 422 | } |
| 423 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
Chuck Lever | 9853a5a | 2020-11-19 13:56:42 -0500 | [diff] [blame] | 424 | u32 length; |
| 425 | |
| 426 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 427 | return nfserr_bad_xdr; |
| 428 | p = xdr_inline_decode(argp->xdr, length); |
| 429 | if (!p) |
| 430 | return nfserr_bad_xdr; |
| 431 | status = nfsd_map_name_to_uid(argp->rqstp, (char *)p, length, |
| 432 | &iattr->ia_uid); |
| 433 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 434 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | iattr->ia_valid |= ATTR_UID; |
| 436 | } |
| 437 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
Chuck Lever | 393c31d | 2020-11-19 13:58:18 -0500 | [diff] [blame] | 438 | u32 length; |
| 439 | |
| 440 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 441 | return nfserr_bad_xdr; |
| 442 | p = xdr_inline_decode(argp->xdr, length); |
| 443 | if (!p) |
| 444 | return nfserr_bad_xdr; |
| 445 | status = nfsd_map_name_to_gid(argp->rqstp, (char *)p, length, |
| 446 | &iattr->ia_gid); |
| 447 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 448 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | iattr->ia_valid |= ATTR_GID; |
| 450 | } |
| 451 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 452 | u32 set_it; |
| 453 | |
| 454 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 455 | return nfserr_bad_xdr; |
| 456 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 458 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_atime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 459 | if (status) |
| 460 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 462 | break; |
| 463 | case NFS4_SET_TO_SERVER_TIME: |
| 464 | iattr->ia_valid |= ATTR_ATIME; |
| 465 | break; |
| 466 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 467 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 471 | u32 set_it; |
| 472 | |
| 473 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 474 | return nfserr_bad_xdr; |
| 475 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 477 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_mtime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 478 | if (status) |
| 479 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 481 | break; |
| 482 | case NFS4_SET_TO_SERVER_TIME: |
| 483 | iattr->ia_valid |= ATTR_MTIME; |
| 484 | break; |
| 485 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 486 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 489 | label->len = 0; |
Arnd Bergmann | 2285ae7 | 2018-01-22 22:09:12 +0100 | [diff] [blame] | 490 | if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) && |
| 491 | bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 492 | status = nfsd4_decode_security_label(argp, label); |
| 493 | if (status) |
| 494 | return status; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 495 | } |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 496 | if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 497 | u32 mode, mask; |
| 498 | |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 499 | if (!umask) |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 500 | return nfserr_bad_xdr; |
| 501 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 502 | return nfserr_bad_xdr; |
| 503 | iattr->ia_mode = mode & (S_IFMT | S_IALLUGO); |
| 504 | if (xdr_stream_decode_u32(argp->xdr, &mask) < 0) |
| 505 | return nfserr_bad_xdr; |
| 506 | *umask = mask & S_IRWXUGO; |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 507 | iattr->ia_valid |= ATTR_MODE; |
| 508 | } |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 509 | |
| 510 | /* request sanity: did attrlist4 contain the expected number of words? */ |
| 511 | if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos) |
| 512 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 514 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 517 | static __be32 |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 518 | nfsd4_decode_stateid4(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 519 | { |
| 520 | __be32 *p; |
| 521 | |
| 522 | p = xdr_inline_decode(argp->xdr, NFS4_STATEID_SIZE); |
| 523 | if (!p) |
| 524 | return nfserr_bad_xdr; |
| 525 | sid->si_generation = be32_to_cpup(p++); |
| 526 | memcpy(&sid->si_opaque, p, sizeof(sid->si_opaque)); |
| 527 | return nfs_ok; |
| 528 | } |
| 529 | |
Chuck Lever | 144e826 | 2020-11-16 17:25:02 -0500 | [diff] [blame] | 530 | static __be32 |
| 531 | nfsd4_decode_clientid4(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 532 | { |
| 533 | __be32 *p; |
| 534 | |
| 535 | p = xdr_inline_decode(argp->xdr, sizeof(__be64)); |
| 536 | if (!p) |
| 537 | return nfserr_bad_xdr; |
| 538 | memcpy(clientid, p, sizeof(*clientid)); |
| 539 | return nfs_ok; |
| 540 | } |
| 541 | |
| 542 | static __be32 |
| 543 | nfsd4_decode_state_owner4(struct nfsd4_compoundargs *argp, |
| 544 | clientid_t *clientid, struct xdr_netobj *owner) |
| 545 | { |
| 546 | __be32 status; |
| 547 | |
| 548 | status = nfsd4_decode_clientid4(argp, clientid); |
| 549 | if (status) |
| 550 | return status; |
| 551 | return nfsd4_decode_opaque(argp, owner); |
| 552 | } |
| 553 | |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 554 | #ifdef CONFIG_NFSD_PNFS |
| 555 | static __be32 |
| 556 | nfsd4_decode_deviceid4(struct nfsd4_compoundargs *argp, |
| 557 | struct nfsd4_deviceid *devid) |
| 558 | { |
| 559 | __be32 *p; |
| 560 | |
| 561 | p = xdr_inline_decode(argp->xdr, NFS4_DEVICEID4_SIZE); |
| 562 | if (!p) |
| 563 | return nfserr_bad_xdr; |
| 564 | memcpy(devid, p, sizeof(*devid)); |
| 565 | return nfs_ok; |
| 566 | } |
Chuck Lever | 5185980 | 2020-11-04 10:40:07 -0500 | [diff] [blame] | 567 | |
| 568 | static __be32 |
| 569 | nfsd4_decode_layoutupdate4(struct nfsd4_compoundargs *argp, |
| 570 | struct nfsd4_layoutcommit *lcp) |
| 571 | { |
| 572 | if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_layout_type) < 0) |
| 573 | return nfserr_bad_xdr; |
| 574 | if (lcp->lc_layout_type < LAYOUT_NFSV4_1_FILES) |
| 575 | return nfserr_bad_xdr; |
| 576 | if (lcp->lc_layout_type >= LAYOUT_TYPE_MAX) |
| 577 | return nfserr_bad_xdr; |
| 578 | |
| 579 | if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_up_len) < 0) |
| 580 | return nfserr_bad_xdr; |
| 581 | if (lcp->lc_up_len > 0) { |
| 582 | lcp->lc_up_layout = xdr_inline_decode(argp->xdr, lcp->lc_up_len); |
| 583 | if (!lcp->lc_up_layout) |
| 584 | return nfserr_bad_xdr; |
| 585 | } |
| 586 | |
| 587 | return nfs_ok; |
| 588 | } |
| 589 | |
Chuck Lever | 645fcad | 2020-11-04 10:42:25 -0500 | [diff] [blame] | 590 | static __be32 |
| 591 | nfsd4_decode_layoutreturn4(struct nfsd4_compoundargs *argp, |
| 592 | struct nfsd4_layoutreturn *lrp) |
| 593 | { |
| 594 | __be32 status; |
| 595 | |
| 596 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_return_type) < 0) |
| 597 | return nfserr_bad_xdr; |
| 598 | switch (lrp->lr_return_type) { |
| 599 | case RETURN_FILE: |
| 600 | if (xdr_stream_decode_u64(argp->xdr, &lrp->lr_seg.offset) < 0) |
| 601 | return nfserr_bad_xdr; |
| 602 | if (xdr_stream_decode_u64(argp->xdr, &lrp->lr_seg.length) < 0) |
| 603 | return nfserr_bad_xdr; |
| 604 | status = nfsd4_decode_stateid4(argp, &lrp->lr_sid); |
| 605 | if (status) |
| 606 | return status; |
| 607 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lrf_body_len) < 0) |
| 608 | return nfserr_bad_xdr; |
| 609 | if (lrp->lrf_body_len > 0) { |
| 610 | lrp->lrf_body = xdr_inline_decode(argp->xdr, lrp->lrf_body_len); |
| 611 | if (!lrp->lrf_body) |
| 612 | return nfserr_bad_xdr; |
| 613 | } |
| 614 | break; |
| 615 | case RETURN_FSID: |
| 616 | case RETURN_ALL: |
| 617 | lrp->lr_seg.offset = 0; |
| 618 | lrp->lr_seg.length = NFS4_MAX_UINT64; |
| 619 | break; |
| 620 | default: |
| 621 | return nfserr_bad_xdr; |
| 622 | } |
| 623 | |
| 624 | return nfs_ok; |
| 625 | } |
| 626 | |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 627 | #endif /* CONFIG_NFSD_PNFS */ |
| 628 | |
Chuck Lever | 571e045 | 2020-11-03 13:16:23 -0500 | [diff] [blame] | 629 | static __be32 |
| 630 | nfsd4_decode_sessionid4(struct nfsd4_compoundargs *argp, |
| 631 | struct nfs4_sessionid *sessionid) |
| 632 | { |
| 633 | __be32 *p; |
| 634 | |
| 635 | p = xdr_inline_decode(argp->xdr, NFS4_MAX_SESSIONID_LEN); |
| 636 | if (!p) |
| 637 | return nfserr_bad_xdr; |
| 638 | memcpy(sessionid->data, p, sizeof(sessionid->data)); |
| 639 | return nfs_ok; |
| 640 | } |
| 641 | |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 642 | /* Defined in Appendix A of RFC 5531 */ |
| 643 | static __be32 |
| 644 | nfsd4_decode_authsys_parms(struct nfsd4_compoundargs *argp, |
| 645 | struct nfsd4_cb_sec *cbs) |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 646 | { |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 647 | u32 stamp, gidcount, uid, gid; |
| 648 | __be32 *p, status; |
| 649 | |
| 650 | if (xdr_stream_decode_u32(argp->xdr, &stamp) < 0) |
| 651 | return nfserr_bad_xdr; |
| 652 | /* machine name */ |
| 653 | status = nfsd4_decode_ignored_string(argp, 255); |
| 654 | if (status) |
| 655 | return status; |
| 656 | if (xdr_stream_decode_u32(argp->xdr, &uid) < 0) |
| 657 | return nfserr_bad_xdr; |
| 658 | if (xdr_stream_decode_u32(argp->xdr, &gid) < 0) |
| 659 | return nfserr_bad_xdr; |
| 660 | if (xdr_stream_decode_u32(argp->xdr, &gidcount) < 0) |
| 661 | return nfserr_bad_xdr; |
| 662 | if (gidcount > 16) |
| 663 | return nfserr_bad_xdr; |
| 664 | p = xdr_inline_decode(argp->xdr, gidcount << 2); |
| 665 | if (!p) |
| 666 | return nfserr_bad_xdr; |
| 667 | if (cbs->flavor == (u32)(-1)) { |
| 668 | struct user_namespace *userns = nfsd_user_namespace(argp->rqstp); |
| 669 | |
| 670 | kuid_t kuid = make_kuid(userns, uid); |
| 671 | kgid_t kgid = make_kgid(userns, gid); |
| 672 | if (uid_valid(kuid) && gid_valid(kgid)) { |
| 673 | cbs->uid = kuid; |
| 674 | cbs->gid = kgid; |
| 675 | cbs->flavor = RPC_AUTH_UNIX; |
| 676 | } else { |
| 677 | dprintk("RPC_AUTH_UNIX with invalid uid or gid, ignoring!\n"); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return nfs_ok; |
| 682 | } |
| 683 | |
| 684 | static __be32 |
| 685 | nfsd4_decode_gss_cb_handles4(struct nfsd4_compoundargs *argp, |
| 686 | struct nfsd4_cb_sec *cbs) |
| 687 | { |
| 688 | __be32 status; |
| 689 | u32 service; |
| 690 | |
| 691 | dprintk("RPC_AUTH_GSS callback secflavor not supported!\n"); |
| 692 | |
| 693 | if (xdr_stream_decode_u32(argp->xdr, &service) < 0) |
| 694 | return nfserr_bad_xdr; |
| 695 | if (service < RPC_GSS_SVC_NONE || service > RPC_GSS_SVC_PRIVACY) |
| 696 | return nfserr_bad_xdr; |
| 697 | /* gcbp_handle_from_server */ |
| 698 | status = nfsd4_decode_ignored_string(argp, 0); |
| 699 | if (status) |
| 700 | return status; |
| 701 | /* gcbp_handle_from_client */ |
| 702 | status = nfsd4_decode_ignored_string(argp, 0); |
| 703 | if (status) |
| 704 | return status; |
| 705 | |
| 706 | return nfs_ok; |
| 707 | } |
| 708 | |
| 709 | /* a counted array of callback_sec_parms4 items */ |
| 710 | static __be32 |
| 711 | nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
| 712 | { |
| 713 | u32 i, secflavor, nr_secflavs; |
| 714 | __be32 status; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 715 | |
| 716 | /* callback_sec_params4 */ |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 717 | if (xdr_stream_decode_u32(argp->xdr, &nr_secflavs) < 0) |
| 718 | return nfserr_bad_xdr; |
J. Bruce Fields | 57569a7 | 2013-05-17 16:25:32 -0400 | [diff] [blame] | 719 | if (nr_secflavs) |
| 720 | cbs->flavor = (u32)(-1); |
| 721 | else |
| 722 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ |
| 723 | cbs->flavor = 0; |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 724 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 725 | for (i = 0; i < nr_secflavs; ++i) { |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 726 | if (xdr_stream_decode_u32(argp->xdr, &secflavor) < 0) |
| 727 | return nfserr_bad_xdr; |
| 728 | switch (secflavor) { |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 729 | case RPC_AUTH_NULL: |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 730 | /* void */ |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 731 | if (cbs->flavor == (u32)(-1)) |
| 732 | cbs->flavor = RPC_AUTH_NULL; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 733 | break; |
| 734 | case RPC_AUTH_UNIX: |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 735 | status = nfsd4_decode_authsys_parms(argp, cbs); |
| 736 | if (status) |
| 737 | return status; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 738 | break; |
| 739 | case RPC_AUTH_GSS: |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 740 | status = nfsd4_decode_gss_cb_handles4(argp, cbs); |
| 741 | if (status) |
| 742 | return status; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 743 | break; |
| 744 | default: |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 745 | return nfserr_inval; |
| 746 | } |
| 747 | } |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 748 | |
| 749 | return nfs_ok; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 750 | } |
| 751 | |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 752 | |
Chuck Lever | d169a6a | 2020-11-03 13:12:27 -0500 | [diff] [blame] | 753 | /* |
| 754 | * NFSv4 operation argument decoders |
| 755 | */ |
| 756 | |
| 757 | static __be32 |
| 758 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, |
| 759 | struct nfsd4_access *access) |
| 760 | { |
| 761 | if (xdr_stream_decode_u32(argp->xdr, &access->ac_req_access) < 0) |
| 762 | return nfserr_bad_xdr; |
| 763 | return nfs_ok; |
| 764 | } |
| 765 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 766 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 768 | { |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 769 | if (xdr_stream_decode_u32(argp->xdr, &close->cl_seqid) < 0) |
| 770 | return nfserr_bad_xdr; |
| 771 | return nfsd4_decode_stateid4(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 775 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 777 | { |
Chuck Lever | cbd9abb | 2020-11-03 13:19:51 -0500 | [diff] [blame] | 778 | if (xdr_stream_decode_u64(argp->xdr, &commit->co_offset) < 0) |
| 779 | return nfserr_bad_xdr; |
| 780 | if (xdr_stream_decode_u32(argp->xdr, &commit->co_count) < 0) |
| 781 | return nfserr_bad_xdr; |
| 782 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 785 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 787 | { |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 788 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 790 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0) |
| 791 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | switch (create->cr_type) { |
| 793 | case NF4LNK: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 794 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0) |
| 795 | return nfserr_bad_xdr; |
| 796 | p = xdr_inline_decode(argp->xdr, create->cr_datalen); |
| 797 | if (!p) |
| 798 | return nfserr_bad_xdr; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 799 | create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen); |
J. Bruce Fields | 7fb8430 | 2014-06-24 15:06:41 -0400 | [diff] [blame] | 800 | if (!create->cr_data) |
J. Bruce Fields | 76f47128 | 2014-06-19 16:44:48 -0400 | [diff] [blame] | 801 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | break; |
| 803 | case NF4BLK: |
| 804 | case NF4CHR: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 805 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0) |
| 806 | return nfserr_bad_xdr; |
| 807 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0) |
| 808 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | break; |
| 810 | case NF4SOCK: |
| 811 | case NF4FIFO: |
| 812 | case NF4DIR: |
| 813 | default: |
| 814 | break; |
| 815 | } |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 816 | status = nfsd4_decode_component4(argp, &create->cr_name, |
| 817 | &create->cr_namelen); |
| 818 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 820 | status = nfsd4_decode_fattr4(argp, create->cr_bmval, |
| 821 | ARRAY_SIZE(create->cr_bmval), |
| 822 | &create->cr_iattr, &create->cr_acl, |
| 823 | &create->cr_label, &create->cr_umask); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 824 | if (status) |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 825 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 827 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 830 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 832 | { |
Chuck Lever | 95e6482 | 2020-11-21 14:11:58 -0500 | [diff] [blame] | 833 | return nfsd4_decode_stateid4(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 836 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 838 | { |
Chuck Lever | f759eff | 2020-11-19 14:40:20 -0500 | [diff] [blame] | 839 | return nfsd4_decode_bitmap4(argp, getattr->ga_bmval, |
| 840 | ARRAY_SIZE(getattr->ga_bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 843 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 845 | { |
Chuck Lever | 5c505d1 | 2020-11-04 15:01:24 -0500 | [diff] [blame] | 846 | return nfsd4_decode_component4(argp, &link->li_name, &link->li_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 849 | static __be32 |
Chuck Lever | 8918cc0 | 2020-11-16 17:16:52 -0500 | [diff] [blame] | 850 | nfsd4_decode_open_to_lock_owner4(struct nfsd4_compoundargs *argp, |
| 851 | struct nfsd4_lock *lock) |
| 852 | { |
| 853 | __be32 status; |
| 854 | |
| 855 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_open_seqid) < 0) |
| 856 | return nfserr_bad_xdr; |
| 857 | status = nfsd4_decode_stateid4(argp, &lock->lk_new_open_stateid); |
| 858 | if (status) |
| 859 | return status; |
| 860 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_lock_seqid) < 0) |
| 861 | return nfserr_bad_xdr; |
| 862 | return nfsd4_decode_state_owner4(argp, &lock->lk_new_clientid, |
| 863 | &lock->lk_new_owner); |
| 864 | } |
| 865 | |
| 866 | static __be32 |
| 867 | nfsd4_decode_exist_lock_owner4(struct nfsd4_compoundargs *argp, |
| 868 | struct nfsd4_lock *lock) |
| 869 | { |
| 870 | __be32 status; |
| 871 | |
| 872 | status = nfsd4_decode_stateid4(argp, &lock->lk_old_lock_stateid); |
| 873 | if (status) |
| 874 | return status; |
| 875 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_old_lock_seqid) < 0) |
| 876 | return nfserr_bad_xdr; |
| 877 | |
| 878 | return nfs_ok; |
| 879 | } |
| 880 | |
| 881 | static __be32 |
| 882 | nfsd4_decode_locker4(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 883 | { |
| 884 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_is_new) < 0) |
| 885 | return nfserr_bad_xdr; |
| 886 | if (lock->lk_is_new) |
| 887 | return nfsd4_decode_open_to_lock_owner4(argp, lock); |
| 888 | return nfsd4_decode_exist_lock_owner4(argp, lock); |
| 889 | } |
| 890 | |
| 891 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 893 | { |
Chuck Lever | 7c59dee | 2020-11-03 13:29:27 -0500 | [diff] [blame] | 894 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_type) < 0) |
| 895 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT)) |
Chuck Lever | 7c59dee | 2020-11-03 13:29:27 -0500 | [diff] [blame] | 897 | return nfserr_bad_xdr; |
| 898 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_reclaim) < 0) |
| 899 | return nfserr_bad_xdr; |
| 900 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_offset) < 0) |
| 901 | return nfserr_bad_xdr; |
| 902 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_length) < 0) |
| 903 | return nfserr_bad_xdr; |
| 904 | return nfsd4_decode_locker4(argp, lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 907 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 909 | { |
Chuck Lever | 0a146f0 | 2020-11-03 13:31:44 -0500 | [diff] [blame] | 910 | if (xdr_stream_decode_u32(argp->xdr, &lockt->lt_type) < 0) |
| 911 | return nfserr_bad_xdr; |
| 912 | if ((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 913 | return nfserr_bad_xdr; |
| 914 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_offset) < 0) |
| 915 | return nfserr_bad_xdr; |
| 916 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_length) < 0) |
| 917 | return nfserr_bad_xdr; |
| 918 | return nfsd4_decode_state_owner4(argp, &lockt->lt_clientid, |
| 919 | &lockt->lt_owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 922 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 924 | { |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 925 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 927 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_type) < 0) |
| 928 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 930 | return nfserr_bad_xdr; |
| 931 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_seqid) < 0) |
| 932 | return nfserr_bad_xdr; |
| 933 | status = nfsd4_decode_stateid4(argp, &locku->lu_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 934 | if (status) |
| 935 | return status; |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 936 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_offset) < 0) |
| 937 | return nfserr_bad_xdr; |
| 938 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_length) < 0) |
| 939 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 941 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 944 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 946 | { |
Chuck Lever | 3d5877e | 2020-11-04 15:02:40 -0500 | [diff] [blame] | 947 | return nfsd4_decode_component4(argp, &lookup->lo_name, &lookup->lo_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Chuck Lever | bf33bab | 2020-11-16 17:37:42 -0500 | [diff] [blame] | 950 | static __be32 |
| 951 | nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 952 | { |
| 953 | __be32 status; |
| 954 | |
| 955 | if (xdr_stream_decode_u32(argp->xdr, &open->op_createmode) < 0) |
| 956 | return nfserr_bad_xdr; |
| 957 | switch (open->op_createmode) { |
| 958 | case NFS4_CREATE_UNCHECKED: |
| 959 | case NFS4_CREATE_GUARDED: |
| 960 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 961 | ARRAY_SIZE(open->op_bmval), |
| 962 | &open->op_iattr, &open->op_acl, |
| 963 | &open->op_label, &open->op_umask); |
| 964 | if (status) |
| 965 | return status; |
| 966 | break; |
| 967 | case NFS4_CREATE_EXCLUSIVE: |
| 968 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 969 | if (status) |
| 970 | return status; |
| 971 | break; |
| 972 | case NFS4_CREATE_EXCLUSIVE4_1: |
| 973 | if (argp->minorversion < 1) |
| 974 | return nfserr_bad_xdr; |
| 975 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 976 | if (status) |
| 977 | return status; |
| 978 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 979 | ARRAY_SIZE(open->op_bmval), |
| 980 | &open->op_iattr, &open->op_acl, |
| 981 | &open->op_label, &open->op_umask); |
| 982 | if (status) |
| 983 | return status; |
| 984 | break; |
| 985 | default: |
| 986 | return nfserr_bad_xdr; |
| 987 | } |
| 988 | |
| 989 | return nfs_ok; |
| 990 | } |
| 991 | |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 992 | static __be32 |
| 993 | nfsd4_decode_openflag4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 994 | { |
| 995 | __be32 status; |
| 996 | |
| 997 | if (xdr_stream_decode_u32(argp->xdr, &open->op_create) < 0) |
| 998 | return nfserr_bad_xdr; |
| 999 | switch (open->op_create) { |
| 1000 | case NFS4_OPEN_NOCREATE: |
| 1001 | break; |
| 1002 | case NFS4_OPEN_CREATE: |
| 1003 | status = nfsd4_decode_createhow4(argp, open); |
| 1004 | if (status) |
| 1005 | return status; |
| 1006 | break; |
| 1007 | default: |
| 1008 | return nfserr_bad_xdr; |
| 1009 | } |
| 1010 | |
| 1011 | return nfs_ok; |
| 1012 | } |
| 1013 | |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1014 | static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1015 | { |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1016 | u32 w; |
| 1017 | |
Chuck Lever | 9aa62f5 | 2020-11-16 17:54:48 -0500 | [diff] [blame] | 1018 | if (xdr_stream_decode_u32(argp->xdr, &w) < 0) |
| 1019 | return nfserr_bad_xdr; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1020 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
| 1021 | *deleg_want = w & NFS4_SHARE_WANT_MASK; |
| 1022 | if (deleg_when) |
| 1023 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; |
| 1024 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1025 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
| 1026 | case NFS4_SHARE_ACCESS_READ: |
| 1027 | case NFS4_SHARE_ACCESS_WRITE: |
| 1028 | case NFS4_SHARE_ACCESS_BOTH: |
| 1029 | break; |
| 1030 | default: |
| 1031 | return nfserr_bad_xdr; |
| 1032 | } |
Benny Halevy | fc0d14f | 2011-10-27 20:43:01 +0200 | [diff] [blame] | 1033 | w &= ~NFS4_SHARE_ACCESS_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1034 | if (!w) |
| 1035 | return nfs_ok; |
| 1036 | if (!argp->minorversion) |
| 1037 | return nfserr_bad_xdr; |
| 1038 | switch (w & NFS4_SHARE_WANT_MASK) { |
| 1039 | case NFS4_SHARE_WANT_NO_PREFERENCE: |
| 1040 | case NFS4_SHARE_WANT_READ_DELEG: |
| 1041 | case NFS4_SHARE_WANT_WRITE_DELEG: |
| 1042 | case NFS4_SHARE_WANT_ANY_DELEG: |
| 1043 | case NFS4_SHARE_WANT_NO_DELEG: |
| 1044 | case NFS4_SHARE_WANT_CANCEL: |
| 1045 | break; |
| 1046 | default: |
| 1047 | return nfserr_bad_xdr; |
| 1048 | } |
Benny Halevy | 92bac8c | 2011-10-19 19:13:29 -0700 | [diff] [blame] | 1049 | w &= ~NFS4_SHARE_WANT_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1050 | if (!w) |
| 1051 | return nfs_ok; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1052 | |
| 1053 | if (!deleg_when) /* open_downgrade */ |
| 1054 | return nfserr_inval; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1055 | switch (w) { |
| 1056 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: |
| 1057 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: |
Benny Halevy | c668fc6 | 2011-10-19 19:13:13 -0700 | [diff] [blame] | 1058 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
| 1059 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1060 | return nfs_ok; |
| 1061 | } |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1062 | return nfserr_bad_xdr; |
| 1063 | } |
| 1064 | |
| 1065 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) |
| 1066 | { |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1067 | if (xdr_stream_decode_u32(argp->xdr, x) < 0) |
| 1068 | return nfserr_bad_xdr; |
| 1069 | /* Note: unlike access bits, deny bits may be zero. */ |
Dan Carpenter | 01cd4af | 2011-10-17 10:41:17 +0300 | [diff] [blame] | 1070 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1071 | return nfserr_bad_xdr; |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1072 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1073 | return nfs_ok; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1076 | static __be32 |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 1077 | nfsd4_decode_open_claim4(struct nfsd4_compoundargs *argp, |
| 1078 | struct nfsd4_open *open) |
| 1079 | { |
| 1080 | __be32 status; |
| 1081 | |
| 1082 | if (xdr_stream_decode_u32(argp->xdr, &open->op_claim_type) < 0) |
| 1083 | return nfserr_bad_xdr; |
| 1084 | switch (open->op_claim_type) { |
| 1085 | case NFS4_OPEN_CLAIM_NULL: |
| 1086 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1087 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1088 | &open->op_fnamelen); |
| 1089 | if (status) |
| 1090 | return status; |
| 1091 | break; |
| 1092 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1093 | if (xdr_stream_decode_u32(argp->xdr, &open->op_delegate_type) < 0) |
| 1094 | return nfserr_bad_xdr; |
| 1095 | break; |
| 1096 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1097 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1098 | if (status) |
| 1099 | return status; |
| 1100 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1101 | &open->op_fnamelen); |
| 1102 | if (status) |
| 1103 | return status; |
| 1104 | break; |
| 1105 | case NFS4_OPEN_CLAIM_FH: |
| 1106 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1107 | if (argp->minorversion < 1) |
| 1108 | return nfserr_bad_xdr; |
| 1109 | /* void */ |
| 1110 | break; |
| 1111 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1112 | if (argp->minorversion < 1) |
| 1113 | return nfserr_bad_xdr; |
| 1114 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1115 | if (status) |
| 1116 | return status; |
| 1117 | break; |
| 1118 | default: |
| 1119 | return nfserr_bad_xdr; |
| 1120 | } |
| 1121 | |
| 1122 | return nfs_ok; |
| 1123 | } |
| 1124 | |
| 1125 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 1127 | { |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1128 | __be32 status; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1129 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
| 1131 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 1132 | open->op_iattr.ia_valid = 0; |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 1133 | open->op_openowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 1135 | open->op_xdr_error = 0; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1136 | if (xdr_stream_decode_u32(argp->xdr, &open->op_seqid) < 0) |
| 1137 | return nfserr_bad_xdr; |
| 1138 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1139 | status = nfsd4_decode_share_access(argp, &open->op_share_access, |
| 1140 | &open->op_deleg_want, &dummy); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1141 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1142 | return status; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1143 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); |
| 1144 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1145 | return status; |
| 1146 | status = nfsd4_decode_state_owner4(argp, &open->op_clientid, |
| 1147 | &open->op_owner); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1148 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1149 | return status; |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 1150 | status = nfsd4_decode_openflag4(argp, open); |
| 1151 | if (status) |
| 1152 | return status; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1153 | return nfsd4_decode_open_claim4(argp, open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1156 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 1158 | { |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1159 | __be32 status; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1160 | |
| 1161 | if (argp->minorversion >= 1) |
| 1162 | return nfserr_notsupp; |
| 1163 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1164 | status = nfsd4_decode_stateid4(argp, &open_conf->oc_req_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1165 | if (status) |
| 1166 | return status; |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1167 | if (xdr_stream_decode_u32(argp->xdr, &open_conf->oc_seqid) < 0) |
| 1168 | return nfserr_bad_xdr; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1169 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1170 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1173 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 1175 | { |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1176 | __be32 status; |
| 1177 | |
| 1178 | status = nfsd4_decode_stateid4(argp, &open_down->od_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1179 | if (status) |
| 1180 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1181 | if (xdr_stream_decode_u32(argp->xdr, &open_down->od_seqid) < 0) |
| 1182 | return nfserr_bad_xdr; |
| 1183 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1184 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
| 1185 | &open_down->od_deleg_want, NULL); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1186 | if (status) |
| 1187 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1188 | return nfsd4_decode_share_deny(argp, &open_down->od_share_deny); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1191 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 1193 | { |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1194 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1196 | if (xdr_stream_decode_u32(argp->xdr, &putfh->pf_fhlen) < 0) |
| 1197 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1199 | return nfserr_bad_xdr; |
| 1200 | p = xdr_inline_decode(argp->xdr, putfh->pf_fhlen); |
| 1201 | if (!p) |
| 1202 | return nfserr_bad_xdr; |
| 1203 | putfh->pf_fhval = svcxdr_tmpalloc(argp, putfh->pf_fhlen); |
| 1204 | if (!putfh->pf_fhval) |
| 1205 | return nfserr_jukebox; |
| 1206 | memcpy(putfh->pf_fhval, p, putfh->pf_fhlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1208 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1211 | static __be32 |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1212 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) |
| 1213 | { |
| 1214 | if (argp->minorversion == 0) |
| 1215 | return nfs_ok; |
| 1216 | return nfserr_notsupp; |
| 1217 | } |
| 1218 | |
| 1219 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 1221 | { |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1222 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1224 | status = nfsd4_decode_stateid4(argp, &read->rd_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1225 | if (status) |
| 1226 | return status; |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1227 | if (xdr_stream_decode_u64(argp->xdr, &read->rd_offset) < 0) |
| 1228 | return nfserr_bad_xdr; |
| 1229 | if (xdr_stream_decode_u32(argp->xdr, &read->rd_length) < 0) |
| 1230 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1232 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1235 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 1237 | { |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1238 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1240 | if (xdr_stream_decode_u64(argp->xdr, &readdir->rd_cookie) < 0) |
| 1241 | return nfserr_bad_xdr; |
| 1242 | status = nfsd4_decode_verifier4(argp, &readdir->rd_verf); |
| 1243 | if (status) |
| 1244 | return status; |
| 1245 | if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_dircount) < 0) |
| 1246 | return nfserr_bad_xdr; |
| 1247 | if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_maxcount) < 0) |
| 1248 | return nfserr_bad_xdr; |
| 1249 | if (xdr_stream_decode_uint32_array(argp->xdr, readdir->rd_bmval, |
| 1250 | ARRAY_SIZE(readdir->rd_bmval)) < 0) |
| 1251 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1253 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1256 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 1258 | { |
Chuck Lever | b7f5fbf | 2020-11-04 15:04:36 -0500 | [diff] [blame] | 1259 | return nfsd4_decode_component4(argp, &remove->rm_name, &remove->rm_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1262 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 1264 | { |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1265 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1267 | status = nfsd4_decode_component4(argp, &rename->rn_sname, &rename->rn_snamelen); |
| 1268 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | return status; |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1270 | return nfsd4_decode_component4(argp, &rename->rn_tname, &rename->rn_tnamelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1273 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 1275 | { |
Chuck Lever | d12f904 | 2020-11-04 15:08:50 -0500 | [diff] [blame] | 1276 | return nfsd4_decode_clientid4(argp, clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1279 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1280 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 1281 | struct nfsd4_secinfo *secinfo) |
| 1282 | { |
Chuck Lever | d0abdae | 2020-11-04 15:09:42 -0500 | [diff] [blame] | 1283 | return nfsd4_decode_component4(argp, &secinfo->si_name, &secinfo->si_namelen); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 1288 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1289 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | |
Chuck Lever | 44592fe | 2020-11-21 14:14:59 -0500 | [diff] [blame] | 1291 | status = nfsd4_decode_stateid4(argp, &setattr->sa_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1292 | if (status) |
| 1293 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1294 | return nfsd4_decode_fattr4(argp, setattr->sa_bmval, |
| 1295 | ARRAY_SIZE(setattr->sa_bmval), |
| 1296 | &setattr->sa_iattr, &setattr->sa_acl, |
| 1297 | &setattr->sa_label, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1300 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 1302 | { |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1303 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1305 | if (argp->minorversion >= 1) |
| 1306 | return nfserr_notsupp; |
| 1307 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1308 | status = nfsd4_decode_verifier4(argp, &setclientid->se_verf); |
| 1309 | if (status) |
| 1310 | return status; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1311 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
| 1312 | if (status) |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1313 | return status; |
| 1314 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_prog) < 0) |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1315 | return nfserr_bad_xdr; |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1316 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_netid_len) < 0) |
| 1317 | return nfserr_bad_xdr; |
| 1318 | p = xdr_inline_decode(argp->xdr, setclientid->se_callback_netid_len); |
| 1319 | if (!p) |
| 1320 | return nfserr_bad_xdr; |
| 1321 | setclientid->se_callback_netid_val = svcxdr_tmpalloc(argp, |
| 1322 | setclientid->se_callback_netid_len); |
| 1323 | if (!setclientid->se_callback_netid_val) |
| 1324 | return nfserr_jukebox; |
| 1325 | memcpy(setclientid->se_callback_netid_val, p, |
| 1326 | setclientid->se_callback_netid_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1328 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_addr_len) < 0) |
| 1329 | return nfserr_bad_xdr; |
| 1330 | p = xdr_inline_decode(argp->xdr, setclientid->se_callback_addr_len); |
| 1331 | if (!p) |
| 1332 | return nfserr_bad_xdr; |
| 1333 | setclientid->se_callback_addr_val = svcxdr_tmpalloc(argp, |
| 1334 | setclientid->se_callback_addr_len); |
| 1335 | if (!setclientid->se_callback_addr_val) |
| 1336 | return nfserr_jukebox; |
| 1337 | memcpy(setclientid->se_callback_addr_val, p, |
| 1338 | setclientid->se_callback_addr_len); |
| 1339 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_ident) < 0) |
| 1340 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1342 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1345 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 1347 | { |
Chuck Lever | d1ca551 | 2020-11-04 15:12:33 -0500 | [diff] [blame] | 1348 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1350 | if (argp->minorversion >= 1) |
| 1351 | return nfserr_notsupp; |
| 1352 | |
Chuck Lever | d1ca551 | 2020-11-04 15:12:33 -0500 | [diff] [blame] | 1353 | status = nfsd4_decode_clientid4(argp, &scd_c->sc_clientid); |
| 1354 | if (status) |
| 1355 | return status; |
| 1356 | return nfsd4_decode_verifier4(argp, &scd_c->sc_confirm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1360 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 1362 | { |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1363 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1365 | status = nfsd4_decode_bitmap4(argp, verify->ve_bmval, |
| 1366 | ARRAY_SIZE(verify->ve_bmval)); |
| 1367 | if (status) |
| 1368 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | /* For convenience's sake, we compare raw xdr'd attributes in |
J. Bruce Fields | e5f9570 | 2012-11-30 17:24:18 -0500 | [diff] [blame] | 1371 | * nfsd4_proc_verify */ |
| 1372 | |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1373 | if (xdr_stream_decode_u32(argp->xdr, &verify->ve_attrlen) < 0) |
| 1374 | return nfserr_bad_xdr; |
| 1375 | p = xdr_inline_decode(argp->xdr, verify->ve_attrlen); |
| 1376 | if (!p) |
| 1377 | return nfserr_bad_xdr; |
| 1378 | verify->ve_attrval = svcxdr_tmpalloc(argp, verify->ve_attrlen); |
| 1379 | if (!verify->ve_attrval) |
| 1380 | return nfserr_jukebox; |
| 1381 | memcpy(verify->ve_attrval, p, verify->ve_attrlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1383 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1386 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 1388 | { |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1389 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1391 | status = nfsd4_decode_stateid4(argp, &write->wr_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1392 | if (status) |
| 1393 | return status; |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1394 | if (xdr_stream_decode_u64(argp->xdr, &write->wr_offset) < 0) |
| 1395 | return nfserr_bad_xdr; |
| 1396 | if (xdr_stream_decode_u32(argp->xdr, &write->wr_stable_how) < 0) |
| 1397 | return nfserr_bad_xdr; |
Kinglong Mee | 54bbb7d | 2016-12-31 20:59:53 +0800 | [diff] [blame] | 1398 | if (write->wr_stable_how > NFS_FILE_SYNC) |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1399 | return nfserr_bad_xdr; |
| 1400 | if (xdr_stream_decode_u32(argp->xdr, &write->wr_buflen) < 0) |
| 1401 | return nfserr_bad_xdr; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1402 | if (!xdr_stream_subsegment(argp->xdr, &write->wr_payload, write->wr_buflen)) |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1403 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1405 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1408 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 1410 | { |
Chuck Lever | a4a80c1 | 2020-11-04 13:42:25 -0500 | [diff] [blame] | 1411 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1413 | if (argp->minorversion >= 1) |
| 1414 | return nfserr_notsupp; |
| 1415 | |
Chuck Lever | a4a80c1 | 2020-11-04 13:42:25 -0500 | [diff] [blame] | 1416 | status = nfsd4_decode_state_owner4(argp, &rlockowner->rl_clientid, |
| 1417 | &rlockowner->rl_owner); |
| 1418 | if (status) |
| 1419 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 1421 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
| 1422 | return nfserr_inval; |
Chuck Lever | a4a80c1 | 2020-11-04 13:42:25 -0500 | [diff] [blame] | 1423 | |
| 1424 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Chuck Lever | 0f81d96 | 2020-11-03 13:14:35 -0500 | [diff] [blame] | 1427 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
| 1428 | { |
| 1429 | if (xdr_stream_decode_u32(argp->xdr, &bc->bc_cb_program) < 0) |
| 1430 | return nfserr_bad_xdr; |
| 1431 | return nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
| 1432 | } |
| 1433 | |
Chuck Lever | 571e045 | 2020-11-03 13:16:23 -0500 | [diff] [blame] | 1434 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
| 1435 | { |
| 1436 | u32 use_conn_in_rdma_mode; |
| 1437 | __be32 status; |
| 1438 | |
| 1439 | status = nfsd4_decode_sessionid4(argp, &bcts->sessionid); |
| 1440 | if (status) |
| 1441 | return status; |
| 1442 | if (xdr_stream_decode_u32(argp->xdr, &bcts->dir) < 0) |
| 1443 | return nfserr_bad_xdr; |
| 1444 | if (xdr_stream_decode_u32(argp->xdr, &use_conn_in_rdma_mode) < 0) |
| 1445 | return nfserr_bad_xdr; |
| 1446 | |
| 1447 | return nfs_ok; |
| 1448 | } |
| 1449 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1450 | static __be32 |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1451 | nfsd4_decode_state_protect_ops(struct nfsd4_compoundargs *argp, |
| 1452 | struct nfsd4_exchange_id *exid) |
| 1453 | { |
| 1454 | __be32 status; |
| 1455 | |
| 1456 | status = nfsd4_decode_bitmap4(argp, exid->spo_must_enforce, |
| 1457 | ARRAY_SIZE(exid->spo_must_enforce)); |
| 1458 | if (status) |
| 1459 | return nfserr_bad_xdr; |
| 1460 | status = nfsd4_decode_bitmap4(argp, exid->spo_must_allow, |
| 1461 | ARRAY_SIZE(exid->spo_must_allow)); |
| 1462 | if (status) |
| 1463 | return nfserr_bad_xdr; |
| 1464 | |
| 1465 | return nfs_ok; |
| 1466 | } |
| 1467 | |
Chuck Lever | 547bfeb | 2020-11-03 11:17:50 -0500 | [diff] [blame] | 1468 | /* |
| 1469 | * This implementation currently does not support SP4_SSV. |
| 1470 | * This decoder simply skips over these arguments. |
| 1471 | */ |
| 1472 | static noinline __be32 |
| 1473 | nfsd4_decode_ssv_sp_parms(struct nfsd4_compoundargs *argp, |
| 1474 | struct nfsd4_exchange_id *exid) |
| 1475 | { |
| 1476 | u32 count, window, num_gss_handles; |
| 1477 | __be32 status; |
| 1478 | |
| 1479 | /* ssp_ops */ |
| 1480 | status = nfsd4_decode_state_protect_ops(argp, exid); |
| 1481 | if (status) |
| 1482 | return status; |
| 1483 | |
| 1484 | /* ssp_hash_algs<> */ |
| 1485 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1486 | return nfserr_bad_xdr; |
| 1487 | while (count--) { |
| 1488 | status = nfsd4_decode_ignored_string(argp, 0); |
| 1489 | if (status) |
| 1490 | return status; |
| 1491 | } |
| 1492 | |
| 1493 | /* ssp_encr_algs<> */ |
| 1494 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1495 | return nfserr_bad_xdr; |
| 1496 | while (count--) { |
| 1497 | status = nfsd4_decode_ignored_string(argp, 0); |
| 1498 | if (status) |
| 1499 | return status; |
| 1500 | } |
| 1501 | |
| 1502 | if (xdr_stream_decode_u32(argp->xdr, &window) < 0) |
| 1503 | return nfserr_bad_xdr; |
| 1504 | if (xdr_stream_decode_u32(argp->xdr, &num_gss_handles) < 0) |
| 1505 | return nfserr_bad_xdr; |
| 1506 | |
| 1507 | return nfs_ok; |
| 1508 | } |
| 1509 | |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1510 | static __be32 |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1511 | nfsd4_decode_state_protect4_a(struct nfsd4_compoundargs *argp, |
| 1512 | struct nfsd4_exchange_id *exid) |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1513 | { |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1514 | __be32 status; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1515 | |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1516 | if (xdr_stream_decode_u32(argp->xdr, &exid->spa_how) < 0) |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1517 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1518 | switch (exid->spa_how) { |
| 1519 | case SP4_NONE: |
| 1520 | break; |
| 1521 | case SP4_MACH_CRED: |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1522 | status = nfsd4_decode_state_protect_ops(argp, exid); |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1523 | if (status) |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1524 | return status; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1525 | break; |
| 1526 | case SP4_SSV: |
Chuck Lever | 547bfeb | 2020-11-03 11:17:50 -0500 | [diff] [blame] | 1527 | status = nfsd4_decode_ssv_sp_parms(argp, exid); |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1528 | if (status) |
| 1529 | return status; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1530 | break; |
| 1531 | default: |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1532 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1533 | } |
| 1534 | |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1535 | return nfs_ok; |
| 1536 | } |
| 1537 | |
| 1538 | static __be32 |
Chuck Lever | 10ff842 | 2020-11-16 15:21:55 -0500 | [diff] [blame] | 1539 | nfsd4_decode_nfs_impl_id4(struct nfsd4_compoundargs *argp, |
| 1540 | struct nfsd4_exchange_id *exid) |
| 1541 | { |
| 1542 | __be32 status; |
| 1543 | u32 count; |
| 1544 | |
| 1545 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1546 | return nfserr_bad_xdr; |
| 1547 | switch (count) { |
| 1548 | case 0: |
| 1549 | break; |
| 1550 | case 1: |
| 1551 | /* Note that RFC 8881 places no length limit on |
| 1552 | * nii_domain, but this implementation permits no |
| 1553 | * more than NFS4_OPAQUE_LIMIT bytes */ |
| 1554 | status = nfsd4_decode_opaque(argp, &exid->nii_domain); |
| 1555 | if (status) |
| 1556 | return status; |
| 1557 | /* Note that RFC 8881 places no length limit on |
| 1558 | * nii_name, but this implementation permits no |
| 1559 | * more than NFS4_OPAQUE_LIMIT bytes */ |
| 1560 | status = nfsd4_decode_opaque(argp, &exid->nii_name); |
| 1561 | if (status) |
| 1562 | return status; |
| 1563 | status = nfsd4_decode_nfstime4(argp, &exid->nii_time); |
| 1564 | if (status) |
| 1565 | return status; |
| 1566 | break; |
| 1567 | default: |
| 1568 | return nfserr_bad_xdr; |
| 1569 | } |
| 1570 | |
| 1571 | return nfs_ok; |
| 1572 | } |
| 1573 | |
| 1574 | static __be32 |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1575 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, |
| 1576 | struct nfsd4_exchange_id *exid) |
| 1577 | { |
Chuck Lever | 10ff842 | 2020-11-16 15:21:55 -0500 | [diff] [blame] | 1578 | __be32 status; |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1579 | |
| 1580 | status = nfsd4_decode_verifier4(argp, &exid->verifier); |
| 1581 | if (status) |
| 1582 | return status; |
| 1583 | status = nfsd4_decode_opaque(argp, &exid->clname); |
| 1584 | if (status) |
| 1585 | return status; |
| 1586 | if (xdr_stream_decode_u32(argp->xdr, &exid->flags) < 0) |
| 1587 | return nfserr_bad_xdr; |
| 1588 | status = nfsd4_decode_state_protect4_a(argp, exid); |
| 1589 | if (status) |
| 1590 | return status; |
Chuck Lever | 10ff842 | 2020-11-16 15:21:55 -0500 | [diff] [blame] | 1591 | return nfsd4_decode_nfs_impl_id4(argp, exid); |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static __be32 |
Chuck Lever | 3a3f1fb | 2020-11-16 15:35:05 -0500 | [diff] [blame] | 1595 | nfsd4_decode_channel_attrs4(struct nfsd4_compoundargs *argp, |
| 1596 | struct nfsd4_channel_attrs *ca) |
| 1597 | { |
| 1598 | __be32 *p; |
| 1599 | |
| 1600 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 7); |
| 1601 | if (!p) |
| 1602 | return nfserr_bad_xdr; |
| 1603 | |
| 1604 | /* headerpadsz is ignored */ |
| 1605 | p++; |
| 1606 | ca->maxreq_sz = be32_to_cpup(p++); |
| 1607 | ca->maxresp_sz = be32_to_cpup(p++); |
| 1608 | ca->maxresp_cached = be32_to_cpup(p++); |
| 1609 | ca->maxops = be32_to_cpup(p++); |
| 1610 | ca->maxreqs = be32_to_cpup(p++); |
| 1611 | ca->nr_rdma_attrs = be32_to_cpup(p); |
| 1612 | switch (ca->nr_rdma_attrs) { |
| 1613 | case 0: |
| 1614 | break; |
| 1615 | case 1: |
| 1616 | if (xdr_stream_decode_u32(argp->xdr, &ca->rdma_attrs) < 0) |
| 1617 | return nfserr_bad_xdr; |
| 1618 | break; |
| 1619 | default: |
| 1620 | return nfserr_bad_xdr; |
| 1621 | } |
| 1622 | |
| 1623 | return nfs_ok; |
| 1624 | } |
| 1625 | |
| 1626 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1627 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, |
| 1628 | struct nfsd4_create_session *sess) |
| 1629 | { |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1630 | __be32 status; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1631 | |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1632 | status = nfsd4_decode_clientid4(argp, &sess->clientid); |
| 1633 | if (status) |
| 1634 | return status; |
| 1635 | if (xdr_stream_decode_u32(argp->xdr, &sess->seqid) < 0) |
| 1636 | return nfserr_bad_xdr; |
| 1637 | if (xdr_stream_decode_u32(argp->xdr, &sess->flags) < 0) |
| 1638 | return nfserr_bad_xdr; |
Chuck Lever | 3a3f1fb | 2020-11-16 15:35:05 -0500 | [diff] [blame] | 1639 | status = nfsd4_decode_channel_attrs4(argp, &sess->fore_channel); |
| 1640 | if (status) |
| 1641 | return status; |
| 1642 | status = nfsd4_decode_channel_attrs4(argp, &sess->back_channel); |
| 1643 | if (status) |
| 1644 | return status; |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1645 | if (xdr_stream_decode_u32(argp->xdr, &sess->callback_prog) < 0) |
| 1646 | return nfserr_bad_xdr; |
| 1647 | status = nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
| 1648 | if (status) |
| 1649 | return status; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1650 | |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1651 | return nfs_ok; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | static __be32 |
| 1655 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, |
| 1656 | struct nfsd4_destroy_session *destroy_session) |
| 1657 | { |
Chuck Lever | 94e254a | 2020-11-04 13:50:55 -0500 | [diff] [blame] | 1658 | return nfsd4_decode_sessionid4(argp, &destroy_session->sessionid); |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | static __be32 |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1662 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, |
| 1663 | struct nfsd4_free_stateid *free_stateid) |
| 1664 | { |
Chuck Lever | aec387d | 2020-11-01 13:38:27 -0500 | [diff] [blame] | 1665 | return nfsd4_decode_stateid4(argp, &free_stateid->fr_stateid); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1666 | } |
| 1667 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1668 | #ifdef CONFIG_NFSD_PNFS |
| 1669 | static __be32 |
| 1670 | nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, |
| 1671 | struct nfsd4_getdeviceinfo *gdev) |
| 1672 | { |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 1673 | __be32 status; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1674 | |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 1675 | status = nfsd4_decode_deviceid4(argp, &gdev->gd_devid); |
| 1676 | if (status) |
| 1677 | return status; |
| 1678 | if (xdr_stream_decode_u32(argp->xdr, &gdev->gd_layout_type) < 0) |
| 1679 | return nfserr_bad_xdr; |
| 1680 | if (xdr_stream_decode_u32(argp->xdr, &gdev->gd_maxcount) < 0) |
| 1681 | return nfserr_bad_xdr; |
| 1682 | if (xdr_stream_decode_uint32_array(argp->xdr, |
| 1683 | &gdev->gd_notify_types, 1) < 0) |
| 1684 | return nfserr_bad_xdr; |
| 1685 | |
| 1686 | return nfs_ok; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | static __be32 |
Chuck Lever | 5185980 | 2020-11-04 10:40:07 -0500 | [diff] [blame] | 1690 | nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, |
| 1691 | struct nfsd4_layoutcommit *lcp) |
| 1692 | { |
| 1693 | __be32 *p, status; |
| 1694 | |
| 1695 | if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_seg.offset) < 0) |
| 1696 | return nfserr_bad_xdr; |
| 1697 | if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_seg.length) < 0) |
| 1698 | return nfserr_bad_xdr; |
| 1699 | if (xdr_stream_decode_bool(argp->xdr, &lcp->lc_reclaim) < 0) |
| 1700 | return nfserr_bad_xdr; |
| 1701 | status = nfsd4_decode_stateid4(argp, &lcp->lc_sid); |
| 1702 | if (status) |
| 1703 | return status; |
| 1704 | if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_newoffset) < 0) |
| 1705 | return nfserr_bad_xdr; |
| 1706 | if (lcp->lc_newoffset) { |
| 1707 | if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_last_wr) < 0) |
| 1708 | return nfserr_bad_xdr; |
| 1709 | } else |
| 1710 | lcp->lc_last_wr = 0; |
| 1711 | p = xdr_inline_decode(argp->xdr, XDR_UNIT); |
| 1712 | if (!p) |
| 1713 | return nfserr_bad_xdr; |
| 1714 | if (xdr_item_is_present(p)) { |
| 1715 | status = nfsd4_decode_nfstime4(argp, &lcp->lc_mtime); |
| 1716 | if (status) |
| 1717 | return status; |
| 1718 | } else { |
| 1719 | lcp->lc_mtime.tv_nsec = UTIME_NOW; |
| 1720 | } |
| 1721 | return nfsd4_decode_layoutupdate4(argp, lcp); |
| 1722 | } |
| 1723 | |
| 1724 | static __be32 |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1725 | nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, |
| 1726 | struct nfsd4_layoutget *lgp) |
| 1727 | { |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1728 | __be32 status; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1729 | |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1730 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_signal) < 0) |
| 1731 | return nfserr_bad_xdr; |
| 1732 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_layout_type) < 0) |
| 1733 | return nfserr_bad_xdr; |
| 1734 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_seg.iomode) < 0) |
| 1735 | return nfserr_bad_xdr; |
| 1736 | if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_seg.offset) < 0) |
| 1737 | return nfserr_bad_xdr; |
| 1738 | if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_seg.length) < 0) |
| 1739 | return nfserr_bad_xdr; |
| 1740 | if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_minlength) < 0) |
| 1741 | return nfserr_bad_xdr; |
| 1742 | status = nfsd4_decode_stateid4(argp, &lgp->lg_sid); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1743 | if (status) |
| 1744 | return status; |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1745 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_maxcount) < 0) |
| 1746 | return nfserr_bad_xdr; |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1747 | |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1748 | return nfs_ok; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | static __be32 |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1752 | nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, |
| 1753 | struct nfsd4_layoutreturn *lrp) |
| 1754 | { |
Chuck Lever | 645fcad | 2020-11-04 10:42:25 -0500 | [diff] [blame] | 1755 | if (xdr_stream_decode_bool(argp->xdr, &lrp->lr_reclaim) < 0) |
| 1756 | return nfserr_bad_xdr; |
| 1757 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_layout_type) < 0) |
| 1758 | return nfserr_bad_xdr; |
| 1759 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_seg.iomode) < 0) |
| 1760 | return nfserr_bad_xdr; |
| 1761 | return nfsd4_decode_layoutreturn4(argp, lrp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1762 | } |
| 1763 | #endif /* CONFIG_NFSD_PNFS */ |
| 1764 | |
Chuck Lever | 53d7087 | 2020-11-03 14:33:12 -0500 | [diff] [blame] | 1765 | static __be32 nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, |
| 1766 | struct nfsd4_secinfo_no_name *sin) |
| 1767 | { |
| 1768 | if (xdr_stream_decode_u32(argp->xdr, &sin->sin_style) < 0) |
| 1769 | return nfserr_bad_xdr; |
| 1770 | return nfs_ok; |
| 1771 | } |
| 1772 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1773 | static __be32 |
Chuck Lever | cf907b1 | 2020-11-03 14:55:19 -0500 | [diff] [blame] | 1774 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, |
| 1775 | struct nfsd4_sequence *seq) |
| 1776 | { |
| 1777 | __be32 *p, status; |
| 1778 | |
| 1779 | status = nfsd4_decode_sessionid4(argp, &seq->sessionid); |
| 1780 | if (status) |
| 1781 | return status; |
| 1782 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 4); |
| 1783 | if (!p) |
| 1784 | return nfserr_bad_xdr; |
| 1785 | seq->seqid = be32_to_cpup(p++); |
| 1786 | seq->slotid = be32_to_cpup(p++); |
| 1787 | seq->maxslots = be32_to_cpup(p++); |
| 1788 | seq->cachethis = be32_to_cpup(p); |
| 1789 | |
| 1790 | return nfs_ok; |
| 1791 | } |
| 1792 | |
| 1793 | static __be32 |
Chuck Lever | b7a0c8f | 2020-11-03 14:57:44 -0500 | [diff] [blame] | 1794 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) |
| 1795 | { |
| 1796 | struct nfsd4_test_stateid_id *stateid; |
| 1797 | __be32 status; |
| 1798 | u32 i; |
| 1799 | |
| 1800 | if (xdr_stream_decode_u32(argp->xdr, &test_stateid->ts_num_ids) < 0) |
| 1801 | return nfserr_bad_xdr; |
| 1802 | |
| 1803 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
| 1804 | for (i = 0; i < test_stateid->ts_num_ids; i++) { |
| 1805 | stateid = svcxdr_tmpalloc(argp, sizeof(*stateid)); |
| 1806 | if (!stateid) |
| 1807 | return nfserrno(-ENOMEM); /* XXX: not jukebox? */ |
| 1808 | INIT_LIST_HEAD(&stateid->ts_id_list); |
| 1809 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); |
| 1810 | status = nfsd4_decode_stateid4(argp, &stateid->ts_id_stateid); |
| 1811 | if (status) |
| 1812 | return status; |
| 1813 | } |
| 1814 | |
| 1815 | return nfs_ok; |
| 1816 | } |
| 1817 | |
Chuck Lever | c95f2ec | 2020-11-04 15:15:09 -0500 | [diff] [blame] | 1818 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, |
| 1819 | struct nfsd4_destroy_clientid *dc) |
| 1820 | { |
| 1821 | return nfsd4_decode_clientid4(argp, &dc->clientid); |
| 1822 | } |
| 1823 | |
Chuck Lever | 0d64678 | 2020-11-03 15:02:11 -0500 | [diff] [blame] | 1824 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, |
| 1825 | struct nfsd4_reclaim_complete *rc) |
| 1826 | { |
| 1827 | if (xdr_stream_decode_bool(argp->xdr, &rc->rca_one_fs) < 0) |
| 1828 | return nfserr_bad_xdr; |
| 1829 | return nfs_ok; |
| 1830 | } |
| 1831 | |
Chuck Lever | b7a0c8f | 2020-11-03 14:57:44 -0500 | [diff] [blame] | 1832 | static __be32 |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1833 | nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, |
| 1834 | struct nfsd4_fallocate *fallocate) |
| 1835 | { |
Chuck Lever | 6aef27a | 2020-11-04 10:44:05 -0500 | [diff] [blame] | 1836 | __be32 status; |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1837 | |
Chuck Lever | 6aef27a | 2020-11-04 10:44:05 -0500 | [diff] [blame] | 1838 | status = nfsd4_decode_stateid4(argp, &fallocate->falloc_stateid); |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1839 | if (status) |
| 1840 | return status; |
Chuck Lever | 6aef27a | 2020-11-04 10:44:05 -0500 | [diff] [blame] | 1841 | if (xdr_stream_decode_u64(argp->xdr, &fallocate->falloc_offset) < 0) |
| 1842 | return nfserr_bad_xdr; |
| 1843 | if (xdr_stream_decode_u64(argp->xdr, &fallocate->falloc_length) < 0) |
| 1844 | return nfserr_bad_xdr; |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1845 | |
Chuck Lever | 6aef27a | 2020-11-04 10:44:05 -0500 | [diff] [blame] | 1846 | return nfs_ok; |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1847 | } |
| 1848 | |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1849 | static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, |
| 1850 | struct nl4_server *ns) |
| 1851 | { |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1852 | struct nfs42_netaddr *naddr; |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1853 | __be32 *p; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1854 | |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1855 | if (xdr_stream_decode_u32(argp->xdr, &ns->nl4_type) < 0) |
| 1856 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1857 | |
| 1858 | /* currently support for 1 inter-server source server */ |
| 1859 | switch (ns->nl4_type) { |
| 1860 | case NL4_NETADDR: |
| 1861 | naddr = &ns->u.nl4_addr; |
| 1862 | |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1863 | if (xdr_stream_decode_u32(argp->xdr, &naddr->netid_len) < 0) |
| 1864 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1865 | if (naddr->netid_len > RPCBIND_MAXNETIDLEN) |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1866 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1867 | |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1868 | p = xdr_inline_decode(argp->xdr, naddr->netid_len); |
| 1869 | if (!p) |
| 1870 | return nfserr_bad_xdr; |
| 1871 | memcpy(naddr->netid, p, naddr->netid_len); |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1872 | |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1873 | if (xdr_stream_decode_u32(argp->xdr, &naddr->addr_len) < 0) |
| 1874 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1875 | if (naddr->addr_len > RPCBIND_MAXUADDRLEN) |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1876 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1877 | |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1878 | p = xdr_inline_decode(argp->xdr, naddr->addr_len); |
| 1879 | if (!p) |
| 1880 | return nfserr_bad_xdr; |
| 1881 | memcpy(naddr->addr, p, naddr->addr_len); |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1882 | break; |
| 1883 | default: |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1884 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1885 | } |
Chuck Lever | f49e4b4 | 2020-11-16 18:05:06 -0500 | [diff] [blame] | 1886 | |
| 1887 | return nfs_ok; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1888 | } |
| 1889 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1890 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1891 | nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) |
| 1892 | { |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1893 | struct nl4_server *ns_dummy; |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1894 | u32 consecutive, i, count; |
| 1895 | __be32 status; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1896 | |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1897 | status = nfsd4_decode_stateid4(argp, ©->cp_src_stateid); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1898 | if (status) |
| 1899 | return status; |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1900 | status = nfsd4_decode_stateid4(argp, ©->cp_dst_stateid); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1901 | if (status) |
| 1902 | return status; |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1903 | if (xdr_stream_decode_u64(argp->xdr, ©->cp_src_pos) < 0) |
| 1904 | return nfserr_bad_xdr; |
| 1905 | if (xdr_stream_decode_u64(argp->xdr, ©->cp_dst_pos) < 0) |
| 1906 | return nfserr_bad_xdr; |
| 1907 | if (xdr_stream_decode_u64(argp->xdr, ©->cp_count) < 0) |
| 1908 | return nfserr_bad_xdr; |
| 1909 | /* ca_consecutive: we always do consecutive copies */ |
| 1910 | if (xdr_stream_decode_u32(argp->xdr, &consecutive) < 0) |
| 1911 | return nfserr_bad_xdr; |
| 1912 | if (xdr_stream_decode_u32(argp->xdr, ©->cp_synchronous) < 0) |
| 1913 | return nfserr_bad_xdr; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1914 | |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1915 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1916 | return nfserr_bad_xdr; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1917 | copy->cp_intra = false; |
| 1918 | if (count == 0) { /* intra-server copy */ |
| 1919 | copy->cp_intra = true; |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1920 | return nfs_ok; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1921 | } |
| 1922 | |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1923 | /* decode all the supplied server addresses but use only the first */ |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1924 | status = nfsd4_decode_nl4_server(argp, ©->cp_src); |
| 1925 | if (status) |
| 1926 | return status; |
| 1927 | |
| 1928 | ns_dummy = kmalloc(sizeof(struct nl4_server), GFP_KERNEL); |
| 1929 | if (ns_dummy == NULL) |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1930 | return nfserrno(-ENOMEM); /* XXX: jukebox? */ |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1931 | for (i = 0; i < count - 1; i++) { |
| 1932 | status = nfsd4_decode_nl4_server(argp, ns_dummy); |
| 1933 | if (status) { |
| 1934 | kfree(ns_dummy); |
| 1935 | return status; |
| 1936 | } |
| 1937 | } |
| 1938 | kfree(ns_dummy); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1939 | |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 1940 | return nfs_ok; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1944 | nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp, |
| 1945 | struct nfsd4_copy_notify *cn) |
| 1946 | { |
Chuck Lever | 5aff7d0 | 2020-09-11 14:47:59 -0400 | [diff] [blame] | 1947 | __be32 status; |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1948 | |
Chuck Lever | f9a953f | 2020-11-21 14:19:24 -0500 | [diff] [blame] | 1949 | status = nfsd4_decode_stateid4(argp, &cn->cpn_src_stateid); |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1950 | if (status) |
| 1951 | return status; |
| 1952 | return nfsd4_decode_nl4_server(argp, &cn->cpn_dst); |
| 1953 | } |
| 1954 | |
| 1955 | static __be32 |
Chuck Lever | f9a953f | 2020-11-21 14:19:24 -0500 | [diff] [blame] | 1956 | nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp, |
| 1957 | struct nfsd4_offload_status *os) |
| 1958 | { |
Chuck Lever | 2846bb05 | 2020-11-21 14:21:25 -0500 | [diff] [blame] | 1959 | return nfsd4_decode_stateid4(argp, &os->stateid); |
Chuck Lever | f9a953f | 2020-11-21 14:19:24 -0500 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1963 | nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) |
| 1964 | { |
Chuck Lever | 9d32b41 | 2020-11-04 10:54:47 -0500 | [diff] [blame] | 1965 | __be32 status; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1966 | |
Chuck Lever | 9d32b41 | 2020-11-04 10:54:47 -0500 | [diff] [blame] | 1967 | status = nfsd4_decode_stateid4(argp, &seek->seek_stateid); |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1968 | if (status) |
| 1969 | return status; |
Chuck Lever | 9d32b41 | 2020-11-04 10:54:47 -0500 | [diff] [blame] | 1970 | if (xdr_stream_decode_u64(argp->xdr, &seek->seek_offset) < 0) |
| 1971 | return nfserr_bad_xdr; |
| 1972 | if (xdr_stream_decode_u32(argp->xdr, &seek->seek_whence) < 0) |
| 1973 | return nfserr_bad_xdr; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1974 | |
Chuck Lever | 9d32b41 | 2020-11-04 10:54:47 -0500 | [diff] [blame] | 1975 | return nfs_ok; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1976 | } |
| 1977 | |
Chuck Lever | 3dfd0b0 | 2020-11-04 10:46:46 -0500 | [diff] [blame] | 1978 | static __be32 |
| 1979 | nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone) |
| 1980 | { |
| 1981 | __be32 status; |
| 1982 | |
| 1983 | status = nfsd4_decode_stateid4(argp, &clone->cl_src_stateid); |
| 1984 | if (status) |
| 1985 | return status; |
| 1986 | status = nfsd4_decode_stateid4(argp, &clone->cl_dst_stateid); |
| 1987 | if (status) |
| 1988 | return status; |
| 1989 | if (xdr_stream_decode_u64(argp->xdr, &clone->cl_src_pos) < 0) |
| 1990 | return nfserr_bad_xdr; |
| 1991 | if (xdr_stream_decode_u64(argp->xdr, &clone->cl_dst_pos) < 0) |
| 1992 | return nfserr_bad_xdr; |
| 1993 | if (xdr_stream_decode_u64(argp->xdr, &clone->cl_count) < 0) |
| 1994 | return nfserr_bad_xdr; |
| 1995 | |
| 1996 | return nfs_ok; |
| 1997 | } |
| 1998 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1999 | /* |
| 2000 | * XDR data that is more than PAGE_SIZE in size is normally part of a |
| 2001 | * read or write. However, the size of extended attributes is limited |
| 2002 | * by the maximum request size, and then further limited by the underlying |
| 2003 | * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX |
| 2004 | * is 64k). Since there is no kvec- or page-based interface to xattrs, |
| 2005 | * and we're not dealing with contiguous pages, we need to do some copying. |
| 2006 | */ |
| 2007 | |
| 2008 | /* |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2009 | * Decode data into buffer. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2010 | */ |
| 2011 | static __be32 |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2012 | nfsd4_vbuf_from_vector(struct nfsd4_compoundargs *argp, struct xdr_buf *xdr, |
| 2013 | char **bufp, u32 buflen) |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2014 | { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2015 | struct page **pages = xdr->pages; |
| 2016 | struct kvec *head = xdr->head; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2017 | char *tmp, *dp; |
| 2018 | u32 len; |
| 2019 | |
| 2020 | if (buflen <= head->iov_len) { |
| 2021 | /* |
| 2022 | * We're in luck, the head has enough space. Just return |
| 2023 | * the head, no need for copying. |
| 2024 | */ |
| 2025 | *bufp = head->iov_base; |
| 2026 | return 0; |
| 2027 | } |
| 2028 | |
| 2029 | tmp = svcxdr_tmpalloc(argp, buflen); |
| 2030 | if (tmp == NULL) |
| 2031 | return nfserr_jukebox; |
| 2032 | |
| 2033 | dp = tmp; |
| 2034 | memcpy(dp, head->iov_base, head->iov_len); |
| 2035 | buflen -= head->iov_len; |
| 2036 | dp += head->iov_len; |
| 2037 | |
| 2038 | while (buflen > 0) { |
| 2039 | len = min_t(u32, buflen, PAGE_SIZE); |
| 2040 | memcpy(dp, page_address(*pages), len); |
| 2041 | |
| 2042 | buflen -= len; |
| 2043 | dp += len; |
| 2044 | pages++; |
| 2045 | } |
| 2046 | |
| 2047 | *bufp = tmp; |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
| 2051 | /* |
| 2052 | * Get a user extended attribute name from the XDR buffer. |
| 2053 | * It will not have the "user." prefix, so prepend it. |
| 2054 | * Lastly, check for nul characters in the name. |
| 2055 | */ |
| 2056 | static __be32 |
| 2057 | nfsd4_decode_xattr_name(struct nfsd4_compoundargs *argp, char **namep) |
| 2058 | { |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2059 | char *name, *sp, *dp; |
| 2060 | u32 namelen, cnt; |
Chuck Lever | 830c715 | 2020-11-04 10:56:52 -0500 | [diff] [blame] | 2061 | __be32 *p; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2062 | |
Chuck Lever | 830c715 | 2020-11-04 10:56:52 -0500 | [diff] [blame] | 2063 | if (xdr_stream_decode_u32(argp->xdr, &namelen) < 0) |
| 2064 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2065 | if (namelen > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) |
| 2066 | return nfserr_nametoolong; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2067 | if (namelen == 0) |
Chuck Lever | 830c715 | 2020-11-04 10:56:52 -0500 | [diff] [blame] | 2068 | return nfserr_bad_xdr; |
| 2069 | p = xdr_inline_decode(argp->xdr, namelen); |
| 2070 | if (!p) |
| 2071 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2072 | name = svcxdr_tmpalloc(argp, namelen + XATTR_USER_PREFIX_LEN + 1); |
| 2073 | if (!name) |
| 2074 | return nfserr_jukebox; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2075 | memcpy(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
| 2076 | |
| 2077 | /* |
| 2078 | * Copy the extended attribute name over while checking for 0 |
| 2079 | * characters. |
| 2080 | */ |
| 2081 | sp = (char *)p; |
| 2082 | dp = name + XATTR_USER_PREFIX_LEN; |
| 2083 | cnt = namelen; |
| 2084 | |
| 2085 | while (cnt-- > 0) { |
| 2086 | if (*sp == '\0') |
Chuck Lever | 830c715 | 2020-11-04 10:56:52 -0500 | [diff] [blame] | 2087 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2088 | *dp++ = *sp++; |
| 2089 | } |
| 2090 | *dp = '\0'; |
| 2091 | |
| 2092 | *namep = name; |
| 2093 | |
Chuck Lever | 830c715 | 2020-11-04 10:56:52 -0500 | [diff] [blame] | 2094 | return nfs_ok; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | /* |
| 2098 | * A GETXATTR op request comes without a length specifier. We just set the |
| 2099 | * maximum length for the reply based on XATTR_SIZE_MAX and the maximum |
| 2100 | * channel reply size. nfsd_getxattr will probe the length of the xattr, |
| 2101 | * check it against getxa_len, and allocate + return the value. |
| 2102 | */ |
| 2103 | static __be32 |
| 2104 | nfsd4_decode_getxattr(struct nfsd4_compoundargs *argp, |
| 2105 | struct nfsd4_getxattr *getxattr) |
| 2106 | { |
| 2107 | __be32 status; |
| 2108 | u32 maxcount; |
| 2109 | |
| 2110 | status = nfsd4_decode_xattr_name(argp, &getxattr->getxa_name); |
| 2111 | if (status) |
| 2112 | return status; |
| 2113 | |
| 2114 | maxcount = svc_max_payload(argp->rqstp); |
| 2115 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2116 | |
| 2117 | getxattr->getxa_len = maxcount; |
| 2118 | |
| 2119 | return status; |
| 2120 | } |
| 2121 | |
| 2122 | static __be32 |
| 2123 | nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp, |
| 2124 | struct nfsd4_setxattr *setxattr) |
| 2125 | { |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2126 | u32 flags, maxcount, size; |
Chuck Lever | 403366a | 2020-11-04 10:59:57 -0500 | [diff] [blame] | 2127 | __be32 status; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2128 | |
Chuck Lever | 403366a | 2020-11-04 10:59:57 -0500 | [diff] [blame] | 2129 | if (xdr_stream_decode_u32(argp->xdr, &flags) < 0) |
| 2130 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2131 | |
| 2132 | if (flags > SETXATTR4_REPLACE) |
| 2133 | return nfserr_inval; |
| 2134 | setxattr->setxa_flags = flags; |
| 2135 | |
| 2136 | status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name); |
| 2137 | if (status) |
| 2138 | return status; |
| 2139 | |
| 2140 | maxcount = svc_max_payload(argp->rqstp); |
| 2141 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2142 | |
Chuck Lever | 403366a | 2020-11-04 10:59:57 -0500 | [diff] [blame] | 2143 | if (xdr_stream_decode_u32(argp->xdr, &size) < 0) |
| 2144 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2145 | if (size > maxcount) |
| 2146 | return nfserr_xattr2big; |
| 2147 | |
| 2148 | setxattr->setxa_len = size; |
| 2149 | if (size > 0) { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2150 | struct xdr_buf payload; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2151 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2152 | if (!xdr_stream_subsegment(argp->xdr, &payload, size)) |
Chuck Lever | 403366a | 2020-11-04 10:59:57 -0500 | [diff] [blame] | 2153 | return nfserr_bad_xdr; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2154 | status = nfsd4_vbuf_from_vector(argp, &payload, |
| 2155 | &setxattr->setxa_buf, size); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
Chuck Lever | 403366a | 2020-11-04 10:59:57 -0500 | [diff] [blame] | 2158 | return nfs_ok; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | static __be32 |
| 2162 | nfsd4_decode_listxattrs(struct nfsd4_compoundargs *argp, |
| 2163 | struct nfsd4_listxattrs *listxattrs) |
| 2164 | { |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2165 | u32 maxcount; |
| 2166 | |
Chuck Lever | 2212036 | 2020-11-04 11:04:02 -0500 | [diff] [blame] | 2167 | if (xdr_stream_decode_u64(argp->xdr, &listxattrs->lsxa_cookie) < 0) |
| 2168 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2169 | |
| 2170 | /* |
| 2171 | * If the cookie is too large to have even one user.x attribute |
| 2172 | * plus trailing '\0' left in a maximum size buffer, it's invalid. |
| 2173 | */ |
| 2174 | if (listxattrs->lsxa_cookie >= |
| 2175 | (XATTR_LIST_MAX / (XATTR_USER_PREFIX_LEN + 2))) |
| 2176 | return nfserr_badcookie; |
| 2177 | |
Chuck Lever | 2212036 | 2020-11-04 11:04:02 -0500 | [diff] [blame] | 2178 | if (xdr_stream_decode_u32(argp->xdr, &maxcount) < 0) |
| 2179 | return nfserr_bad_xdr; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2180 | if (maxcount < 8) |
| 2181 | /* Always need at least 2 words (length and one character) */ |
| 2182 | return nfserr_inval; |
| 2183 | |
| 2184 | maxcount = min(maxcount, svc_max_payload(argp->rqstp)); |
| 2185 | listxattrs->lsxa_maxcount = maxcount; |
| 2186 | |
Chuck Lever | 2212036 | 2020-11-04 11:04:02 -0500 | [diff] [blame] | 2187 | return nfs_ok; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | static __be32 |
| 2191 | nfsd4_decode_removexattr(struct nfsd4_compoundargs *argp, |
| 2192 | struct nfsd4_removexattr *removexattr) |
| 2193 | { |
| 2194 | return nfsd4_decode_xattr_name(argp, &removexattr->rmxa_name); |
| 2195 | } |
| 2196 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2197 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2198 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 2199 | { |
| 2200 | return nfs_ok; |
| 2201 | } |
| 2202 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2203 | static __be32 |
| 2204 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 2205 | { |
Benny Halevy | 1e685ec | 2009-03-04 23:06:06 +0200 | [diff] [blame] | 2206 | return nfserr_notsupp; |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2207 | } |
| 2208 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2209 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 2210 | |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 2211 | static const nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2212 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 2213 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 2214 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 2215 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 2216 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2217 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 2218 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 2219 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2220 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 2221 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 2222 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 2223 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 2224 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 2225 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 2226 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2227 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 2228 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2229 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 2230 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 2231 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2232 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2233 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2234 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 2235 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 2236 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 2237 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 2238 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 2239 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 2240 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2241 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2242 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 2243 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 2244 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 2245 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 2246 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2247 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 2248 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2249 | |
| 2250 | /* new operations for NFSv4.1 */ |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 2251 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2252 | [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2253 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
| 2254 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, |
| 2255 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 2256 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2257 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2258 | #ifdef CONFIG_NFSD_PNFS |
| 2259 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo, |
| 2260 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2261 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit, |
| 2262 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget, |
| 2263 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn, |
| 2264 | #else |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2265 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2266 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2267 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2268 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2269 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2270 | #endif |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 2271 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2272 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
| 2273 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 2274 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2275 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 2276 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 2277 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2278 | |
| 2279 | /* new operations for NFSv4.2 */ |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 2280 | [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2281 | [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2282 | [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_copy_notify, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 2283 | [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2284 | [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2285 | [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2286 | [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp, |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 2287 | [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2288 | [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2289 | [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_read, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2290 | [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2291 | [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 2292 | [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2293 | /* RFC 8276 extended atributes operations */ |
| 2294 | [OP_GETXATTR] = (nfsd4_dec)nfsd4_decode_getxattr, |
| 2295 | [OP_SETXATTR] = (nfsd4_dec)nfsd4_decode_setxattr, |
| 2296 | [OP_LISTXATTRS] = (nfsd4_dec)nfsd4_decode_listxattrs, |
| 2297 | [OP_REMOVEXATTR] = (nfsd4_dec)nfsd4_decode_removexattr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2298 | }; |
| 2299 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2300 | static inline bool |
| 2301 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) |
| 2302 | { |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2303 | if (op->opnum < FIRST_NFS4_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2304 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2305 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2306 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2307 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
| 2308 | return false; |
| 2309 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2310 | return false; |
| 2311 | return true; |
| 2312 | } |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 2313 | |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2314 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 2316 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | struct nfsd4_op *op; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2318 | bool cachethis = false; |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2319 | int auth_slack= argp->rqstp->rq_auth_slack; |
| 2320 | int max_reply = auth_slack + 8; /* opcnt, status */ |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2321 | int readcount = 0; |
| 2322 | int readbytes = 0; |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2323 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | int i; |
| 2325 | |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2326 | if (xdr_stream_decode_u32(argp->xdr, &argp->taglen) < 0) |
| 2327 | return 0; |
| 2328 | max_reply += XDR_UNIT; |
| 2329 | argp->tag = NULL; |
| 2330 | if (unlikely(argp->taglen)) { |
| 2331 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 2332 | return 0; |
| 2333 | p = xdr_inline_decode(argp->xdr, argp->taglen); |
| 2334 | if (!p) |
| 2335 | return 0; |
| 2336 | argp->tag = svcxdr_tmpalloc(argp, argp->taglen); |
| 2337 | if (!argp->tag) |
| 2338 | return 0; |
| 2339 | memcpy(argp->tag, p, argp->taglen); |
| 2340 | max_reply += xdr_align_size(argp->taglen); |
| 2341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2343 | if (xdr_stream_decode_u32(argp->xdr, &argp->minorversion) < 0) |
| 2344 | return 0; |
| 2345 | if (xdr_stream_decode_u32(argp->xdr, &argp->opcnt) < 0) |
| 2346 | return 0; |
| 2347 | |
J. Bruce Fields | 0078117 | 2017-11-15 12:30:27 -0500 | [diff] [blame] | 2348 | /* |
| 2349 | * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS |
| 2350 | * here, so we return success at the xdr level so that |
| 2351 | * nfsd4_proc can handle this is an NFS-level error. |
| 2352 | */ |
| 2353 | if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND) |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2354 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 2356 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
J. Bruce Fields | 5d6031c | 2014-07-17 16:20:39 -0400 | [diff] [blame] | 2357 | argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | if (!argp->ops) { |
| 2359 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 2360 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2361 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2365 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 2366 | argp->opcnt = 0; |
| 2367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | for (i = 0; i < argp->opcnt; i++) { |
| 2369 | op = &argp->ops[i]; |
| 2370 | op->replay = NULL; |
| 2371 | |
Chuck Lever | 3a237b4 | 2020-11-22 12:49:52 -0500 | [diff] [blame] | 2372 | if (xdr_stream_decode_u32(argp->xdr, &op->opnum) < 0) |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2373 | return 0; |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2374 | if (nfsd4_opnum_in_range(argp, op)) { |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2375 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2376 | if (op->status != nfs_ok) |
| 2377 | trace_nfsd_compound_decode_err(argp->rqstp, |
| 2378 | argp->opcnt, i, |
| 2379 | op->opnum, |
| 2380 | op->status); |
| 2381 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | op->opnum = OP_ILLEGAL; |
| 2383 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2385 | op->opdesc = OPDESC(op); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2386 | /* |
| 2387 | * We'll try to cache the result in the DRC if any one |
| 2388 | * op in the compound wants to be cached: |
| 2389 | */ |
| 2390 | cachethis |= nfsd4_cache_this_op(op); |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 2391 | |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2392 | if (op->opnum == OP_READ || op->opnum == OP_READ_PLUS) { |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2393 | readcount++; |
| 2394 | readbytes += nfsd4_max_reply(argp->rqstp, op); |
| 2395 | } else |
| 2396 | max_reply += nfsd4_max_reply(argp->rqstp, op); |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2397 | /* |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2398 | * OP_LOCK and OP_LOCKT may return a conflicting lock. |
| 2399 | * (Special case because it will just skip encoding this |
| 2400 | * if it runs out of xdr buffer space, and it is the only |
| 2401 | * operation that behaves this way.) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2402 | */ |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2403 | if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2404 | max_reply += NFS4_OPAQUE_LIMIT; |
J. Bruce Fields | e372ba6 | 2014-05-19 12:27:11 -0400 | [diff] [blame] | 2405 | |
| 2406 | if (op->status) { |
| 2407 | argp->opcnt = i+1; |
| 2408 | break; |
| 2409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2411 | /* Sessions make the DRC unnecessary: */ |
| 2412 | if (argp->minorversion) |
| 2413 | cachethis = false; |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2414 | svc_reserve(argp->rqstp, max_reply + readbytes); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2415 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2417 | if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack) |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 2418 | clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags); |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2419 | |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 2420 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2423 | static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode, |
| 2424 | struct svc_export *exp) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2425 | { |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2426 | if (exp->ex_flags & NFSEXP_V4ROOT) { |
| 2427 | *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time)); |
| 2428 | *p++ = 0; |
| 2429 | } else if (IS_I_VERSION(inode)) { |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 2430 | p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode)); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2431 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2432 | *p++ = cpu_to_be32(stat->ctime.tv_sec); |
| 2433 | *p++ = cpu_to_be32(stat->ctime.tv_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2434 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2435 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2436 | } |
| 2437 | |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2438 | /* |
| 2439 | * ctime (in NFSv4, time_metadata) is not writeable, and the client |
| 2440 | * doesn't really care what resolution could theoretically be stored by |
| 2441 | * the filesystem. |
| 2442 | * |
| 2443 | * The client cares how close together changes can be while still |
| 2444 | * guaranteeing ctime changes. For most filesystems (which have |
| 2445 | * timestamps with nanosecond fields) that is limited by the resolution |
| 2446 | * of the time returned from current_time() (which I'm assuming to be |
| 2447 | * 1/HZ). |
| 2448 | */ |
| 2449 | static __be32 *encode_time_delta(__be32 *p, struct inode *inode) |
| 2450 | { |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2451 | struct timespec64 ts; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2452 | u32 ns; |
| 2453 | |
| 2454 | ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran); |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2455 | ts = ns_to_timespec64(ns); |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2456 | |
| 2457 | p = xdr_encode_hyper(p, ts.tv_sec); |
| 2458 | *p++ = cpu_to_be32(ts.tv_nsec); |
| 2459 | |
| 2460 | return p; |
| 2461 | } |
| 2462 | |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2463 | static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2464 | { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2465 | *p++ = cpu_to_be32(c->atomic); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2466 | if (c->change_supported) { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2467 | p = xdr_encode_hyper(p, c->before_change); |
| 2468 | p = xdr_encode_hyper(p, c->after_change); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2469 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2470 | *p++ = cpu_to_be32(c->before_ctime_sec); |
| 2471 | *p++ = cpu_to_be32(c->before_ctime_nsec); |
| 2472 | *p++ = cpu_to_be32(c->after_ctime_sec); |
| 2473 | *p++ = cpu_to_be32(c->after_ctime_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2474 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2475 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2478 | /* Encode as an array of strings the string given with components |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2479 | * separated @sep, escaped with esc_enter and esc_exit. |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2480 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2481 | static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, |
| 2482 | char *components, char esc_enter, |
| 2483 | char esc_exit) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2484 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2485 | __be32 *p; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2486 | __be32 pathlen; |
| 2487 | int pathlen_offset; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2488 | int strlen, count=0; |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2489 | char *str, *end, *next; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2490 | |
| 2491 | dprintk("nfsd4_encode_components(%s)\n", components); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2492 | |
| 2493 | pathlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2494 | p = xdr_reserve_space(xdr, 4); |
| 2495 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2496 | return nfserr_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2497 | p++; /* We will fill this in with @count later */ |
| 2498 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2499 | end = str = components; |
| 2500 | while (*end) { |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2501 | bool found_esc = false; |
| 2502 | |
| 2503 | /* try to parse as esc_start, ..., esc_end, sep */ |
| 2504 | if (*str == esc_enter) { |
| 2505 | for (; *end && (*end != esc_exit); end++) |
| 2506 | /* find esc_exit or end of string */; |
| 2507 | next = end + 1; |
| 2508 | if (*end && (!*next || *next == sep)) { |
| 2509 | str++; |
| 2510 | found_esc = true; |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | if (!found_esc) |
| 2515 | for (; *end && (*end != sep); end++) |
| 2516 | /* find sep or end of string */; |
| 2517 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2518 | strlen = end - str; |
| 2519 | if (strlen) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2520 | p = xdr_reserve_space(xdr, strlen + 4); |
| 2521 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2522 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2523 | p = xdr_encode_opaque(p, str, strlen); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2524 | count++; |
| 2525 | } |
| 2526 | else |
| 2527 | end++; |
Benjamin Coddington | 5a64e56 | 2014-12-07 16:05:47 -0500 | [diff] [blame] | 2528 | if (found_esc) |
| 2529 | end = next; |
| 2530 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2531 | str = end; |
| 2532 | } |
Benjamin Coddington | bf7491f | 2014-12-07 16:05:48 -0500 | [diff] [blame] | 2533 | pathlen = htonl(count); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2534 | write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2535 | return 0; |
| 2536 | } |
| 2537 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2538 | /* Encode as an array of strings the string given with components |
| 2539 | * separated @sep. |
| 2540 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2541 | static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep, |
| 2542 | char *components) |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2543 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2544 | return nfsd4_encode_components_esc(xdr, sep, components, 0, 0); |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2545 | } |
| 2546 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2547 | /* |
| 2548 | * encode a location element of a fs_locations structure |
| 2549 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2550 | static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr, |
| 2551 | struct nfsd4_fs_location *location) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2552 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2553 | __be32 status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2554 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2555 | status = nfsd4_encode_components_esc(xdr, ':', location->hosts, |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2556 | '[', ']'); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2557 | if (status) |
| 2558 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2559 | status = nfsd4_encode_components(xdr, '/', location->path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2560 | if (status) |
| 2561 | return status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | /* |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2566 | * Encode a path in RFC3530 'pathname4' format |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2567 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2568 | static __be32 nfsd4_encode_path(struct xdr_stream *xdr, |
| 2569 | const struct path *root, |
| 2570 | const struct path *path) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2571 | { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2572 | struct path cur = *path; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2573 | __be32 *p; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2574 | struct dentry **components = NULL; |
| 2575 | unsigned int ncomponents = 0; |
| 2576 | __be32 err = nfserr_jukebox; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2577 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2578 | dprintk("nfsd4_encode_components("); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2579 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2580 | path_get(&cur); |
| 2581 | /* First walk the path up to the nfsd root, and store the |
| 2582 | * dentries/path components in an array. |
| 2583 | */ |
| 2584 | for (;;) { |
Kinglong Mee | b77a4b2 | 2015-03-15 23:13:32 +0800 | [diff] [blame] | 2585 | if (path_equal(&cur, root)) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2586 | break; |
| 2587 | if (cur.dentry == cur.mnt->mnt_root) { |
| 2588 | if (follow_up(&cur)) |
| 2589 | continue; |
| 2590 | goto out_free; |
| 2591 | } |
| 2592 | if ((ncomponents & 15) == 0) { |
| 2593 | struct dentry **new; |
| 2594 | new = krealloc(components, |
| 2595 | sizeof(*new) * (ncomponents + 16), |
| 2596 | GFP_KERNEL); |
| 2597 | if (!new) |
| 2598 | goto out_free; |
| 2599 | components = new; |
| 2600 | } |
| 2601 | components[ncomponents++] = cur.dentry; |
| 2602 | cur.dentry = dget_parent(cur.dentry); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2603 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2604 | err = nfserr_resource; |
| 2605 | p = xdr_reserve_space(xdr, 4); |
| 2606 | if (!p) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2607 | goto out_free; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2608 | *p++ = cpu_to_be32(ncomponents); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2609 | |
| 2610 | while (ncomponents) { |
| 2611 | struct dentry *dentry = components[ncomponents - 1]; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2612 | unsigned int len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2613 | |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2614 | spin_lock(&dentry->d_lock); |
| 2615 | len = dentry->d_name.len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2616 | p = xdr_reserve_space(xdr, len + 4); |
| 2617 | if (!p) { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2618 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2619 | goto out_free; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2620 | } |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2621 | p = xdr_encode_opaque(p, dentry->d_name.name, len); |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 2622 | dprintk("/%pd", dentry); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2623 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2624 | dput(dentry); |
| 2625 | ncomponents--; |
| 2626 | } |
| 2627 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2628 | err = 0; |
| 2629 | out_free: |
| 2630 | dprintk(")\n"); |
| 2631 | while (ncomponents) |
| 2632 | dput(components[--ncomponents]); |
| 2633 | kfree(components); |
| 2634 | path_put(&cur); |
| 2635 | return err; |
| 2636 | } |
| 2637 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2638 | static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr, |
| 2639 | struct svc_rqst *rqstp, const struct path *path) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2640 | { |
| 2641 | struct svc_export *exp_ps; |
| 2642 | __be32 res; |
| 2643 | |
| 2644 | exp_ps = rqst_find_fsidzero_export(rqstp); |
| 2645 | if (IS_ERR(exp_ps)) |
| 2646 | return nfserrno(PTR_ERR(exp_ps)); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2647 | res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2648 | exp_put(exp_ps); |
| 2649 | return res; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | /* |
| 2653 | * encode a fs_locations structure |
| 2654 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2655 | static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, |
| 2656 | struct svc_rqst *rqstp, struct svc_export *exp) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2657 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2658 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 2659 | int i; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2660 | __be32 *p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2661 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2662 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2663 | status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2664 | if (status) |
| 2665 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2666 | p = xdr_reserve_space(xdr, 4); |
| 2667 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2668 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2669 | *p++ = cpu_to_be32(fslocs->locations_count); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2670 | for (i=0; i<fslocs->locations_count; i++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2671 | status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2672 | if (status) |
| 2673 | return status; |
| 2674 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2675 | return 0; |
| 2676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2678 | static u32 nfs4_file_type(umode_t mode) |
| 2679 | { |
| 2680 | switch (mode & S_IFMT) { |
| 2681 | case S_IFIFO: return NF4FIFO; |
| 2682 | case S_IFCHR: return NF4CHR; |
| 2683 | case S_IFDIR: return NF4DIR; |
| 2684 | case S_IFBLK: return NF4BLK; |
| 2685 | case S_IFLNK: return NF4LNK; |
| 2686 | case S_IFREG: return NF4REG; |
| 2687 | case S_IFSOCK: return NF4SOCK; |
| 2688 | default: return NF4BAD; |
Tom Rix | 25fef48 | 2020-11-01 07:32:34 -0800 | [diff] [blame] | 2689 | } |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2690 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2692 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2693 | nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2694 | struct nfs4_ace *ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | { |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2696 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2697 | return nfs4_acl_write_who(xdr, ace->whotype); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2698 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2699 | return nfsd4_encode_group(xdr, rqstp, ace->who_gid); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2700 | else |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2701 | return nfsd4_encode_user(xdr, rqstp, ace->who_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2704 | static inline __be32 |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2705 | nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2706 | { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2707 | __be32 *p; |
| 2708 | unsigned long i = hweight_long(layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2709 | |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2710 | p = xdr_reserve_space(xdr, 4 + 4 * i); |
| 2711 | if (!p) |
| 2712 | return nfserr_resource; |
| 2713 | |
| 2714 | *p++ = cpu_to_be32(i); |
| 2715 | |
| 2716 | for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) |
| 2717 | if (layout_types & (1 << i)) |
| 2718 | *p++ = cpu_to_be32(i); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2719 | |
| 2720 | return 0; |
| 2721 | } |
| 2722 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2723 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 2724 | FATTR4_WORD0_RDATTR_ERROR) |
| 2725 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2726 | #define WORD2_ABSENT_FS_ATTRS 0 |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2727 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2728 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2729 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2730 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2731 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2732 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2733 | __be32 *p; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2734 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2735 | p = xdr_reserve_space(xdr, len + 4 + 4 + 4); |
| 2736 | if (!p) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2737 | return nfserr_resource; |
| 2738 | |
| 2739 | /* |
| 2740 | * For now we use a 0 here to indicate the null translation; in |
| 2741 | * the future we may place a call to translation code here. |
| 2742 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2743 | *p++ = cpu_to_be32(0); /* lfs */ |
| 2744 | *p++ = cpu_to_be32(0); /* pi */ |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2745 | p = xdr_encode_opaque(p, context, len); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2746 | return 0; |
| 2747 | } |
| 2748 | #else |
| 2749 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2750 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2751 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2752 | { return 0; } |
| 2753 | #endif |
| 2754 | |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2755 | static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *bmval2, u32 *rdattr_err) |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2756 | { |
| 2757 | /* As per referral draft: */ |
| 2758 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 2759 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 2760 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 2761 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2762 | *rdattr_err = NFSERR_MOVED; |
| 2763 | else |
| 2764 | return nfserr_moved; |
| 2765 | } |
| 2766 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 2767 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2768 | *bmval2 &= WORD2_ABSENT_FS_ATTRS; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2769 | return 0; |
| 2770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2772 | |
| 2773 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) |
| 2774 | { |
| 2775 | struct path path = exp->ex_path; |
| 2776 | int err; |
| 2777 | |
| 2778 | path_get(&path); |
| 2779 | while (follow_up(&path)) { |
| 2780 | if (path.dentry != path.mnt->mnt_root) |
| 2781 | break; |
| 2782 | } |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2783 | err = vfs_getattr(&path, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2784 | path_put(&path); |
| 2785 | return err; |
| 2786 | } |
| 2787 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2788 | static __be32 |
| 2789 | nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2) |
| 2790 | { |
| 2791 | __be32 *p; |
| 2792 | |
| 2793 | if (bmval2) { |
| 2794 | p = xdr_reserve_space(xdr, 16); |
| 2795 | if (!p) |
| 2796 | goto out_resource; |
| 2797 | *p++ = cpu_to_be32(3); |
| 2798 | *p++ = cpu_to_be32(bmval0); |
| 2799 | *p++ = cpu_to_be32(bmval1); |
| 2800 | *p++ = cpu_to_be32(bmval2); |
| 2801 | } else if (bmval1) { |
| 2802 | p = xdr_reserve_space(xdr, 12); |
| 2803 | if (!p) |
| 2804 | goto out_resource; |
| 2805 | *p++ = cpu_to_be32(2); |
| 2806 | *p++ = cpu_to_be32(bmval0); |
| 2807 | *p++ = cpu_to_be32(bmval1); |
| 2808 | } else { |
| 2809 | p = xdr_reserve_space(xdr, 8); |
| 2810 | if (!p) |
| 2811 | goto out_resource; |
| 2812 | *p++ = cpu_to_be32(1); |
| 2813 | *p++ = cpu_to_be32(bmval0); |
| 2814 | } |
| 2815 | |
| 2816 | return 0; |
| 2817 | out_resource: |
| 2818 | return nfserr_resource; |
| 2819 | } |
| 2820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | /* |
| 2822 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 2823 | * ourselves. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | */ |
Jeff Layton | da2ebce | 2014-05-30 09:09:25 -0400 | [diff] [blame] | 2825 | static __be32 |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 2826 | nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, |
| 2827 | struct svc_export *exp, |
| 2828 | struct dentry *dentry, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2829 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | { |
| 2831 | u32 bmval0 = bmval[0]; |
| 2832 | u32 bmval1 = bmval[1]; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2833 | u32 bmval2 = bmval[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | struct kstat stat; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2835 | struct svc_fh *tempfh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | struct kstatfs statfs; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2837 | __be32 *p; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 2838 | int starting_len = xdr->buf->len; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2839 | int attrlen_offset; |
| 2840 | __be32 attrlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | u32 dummy; |
| 2842 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2843 | u32 rdattr_err = 0; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2844 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2845 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | struct nfs4_acl *acl = NULL; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2847 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2848 | void *context = NULL; |
| 2849 | int contextlen; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2850 | #endif |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2851 | bool contextsupport = false; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2852 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2853 | u32 minorversion = resp->cstate.minorversion; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2854 | struct path path = { |
| 2855 | .mnt = exp->ex_path.mnt, |
| 2856 | .dentry = dentry, |
| 2857 | }; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2858 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | |
| 2860 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2861 | BUG_ON(!nfsd_attrs_supported(minorversion, bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2863 | if (exp->ex_fslocs.migrated) { |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2864 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2865 | if (status) |
| 2866 | goto out; |
| 2867 | } |
| 2868 | |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2869 | err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2870 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | goto out_nfserr; |
Christoph Hellwig | 1233790 | 2014-05-28 10:46:13 +0200 | [diff] [blame] | 2872 | if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | |
| 2873 | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 2875 | FATTR4_WORD1_SPACE_TOTAL))) { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2876 | err = vfs_statfs(&path, &statfs); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2877 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | goto out_nfserr; |
| 2879 | } |
| 2880 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2881 | tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
| 2882 | status = nfserr_jukebox; |
| 2883 | if (!tempfh) |
| 2884 | goto out; |
| 2885 | fh_init(tempfh, NFS4_FHSIZE); |
| 2886 | status = fh_compose(tempfh, exp, dentry, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | if (status) |
| 2888 | goto out; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2889 | fhp = tempfh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | } |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2891 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2892 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2893 | if (err == -EOPNOTSUPP) |
| 2894 | bmval0 &= ~FATTR4_WORD0_ACL; |
| 2895 | else if (err == -EINVAL) { |
| 2896 | status = nfserr_attrnotsupp; |
| 2897 | goto out; |
| 2898 | } else if (err != 0) |
| 2899 | goto out_nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2902 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2903 | if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || |
| 2904 | bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2905 | if (exp->ex_flags & NFSEXP_SECURITY_LABEL) |
| 2906 | err = security_inode_getsecctx(d_inode(dentry), |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2907 | &context, &contextlen); |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2908 | else |
| 2909 | err = -EOPNOTSUPP; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2910 | contextsupport = (err == 0); |
| 2911 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2912 | if (err == -EOPNOTSUPP) |
| 2913 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2914 | else if (err) |
| 2915 | goto out_nfserr; |
| 2916 | } |
| 2917 | } |
| 2918 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
| 2919 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2920 | status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2); |
| 2921 | if (status) |
| 2922 | goto out; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2923 | |
| 2924 | attrlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2925 | p = xdr_reserve_space(xdr, 4); |
| 2926 | if (!p) |
| 2927 | goto out_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2928 | p++; /* to be backfilled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | |
| 2930 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | dcd20869 | 2017-01-11 20:34:50 -0500 | [diff] [blame] | 2931 | u32 supp[3]; |
| 2932 | |
| 2933 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2934 | |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2935 | if (!IS_POSIXACL(dentry->d_inode)) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2936 | supp[0] &= ~FATTR4_WORD0_ACL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2937 | if (!contextsupport) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2938 | supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2939 | if (!supp[2]) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2940 | p = xdr_reserve_space(xdr, 12); |
| 2941 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2942 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2943 | *p++ = cpu_to_be32(2); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2944 | *p++ = cpu_to_be32(supp[0]); |
| 2945 | *p++ = cpu_to_be32(supp[1]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2946 | } else { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2947 | p = xdr_reserve_space(xdr, 16); |
| 2948 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2949 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2950 | *p++ = cpu_to_be32(3); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2951 | *p++ = cpu_to_be32(supp[0]); |
| 2952 | *p++ = cpu_to_be32(supp[1]); |
| 2953 | *p++ = cpu_to_be32(supp[2]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | } |
| 2956 | if (bmval0 & FATTR4_WORD0_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2957 | p = xdr_reserve_space(xdr, 4); |
| 2958 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | goto out_resource; |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2960 | dummy = nfs4_file_type(stat.mode); |
J. Bruce Fields | 6b6d8137 | 2013-01-16 17:11:11 -0500 | [diff] [blame] | 2961 | if (dummy == NF4BAD) { |
| 2962 | status = nfserr_serverfault; |
| 2963 | goto out; |
| 2964 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2965 | *p++ = cpu_to_be32(dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | } |
| 2967 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2968 | p = xdr_reserve_space(xdr, 4); |
| 2969 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2971 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2972 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2973 | else |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2974 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT| |
| 2975 | NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | } |
| 2977 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2978 | p = xdr_reserve_space(xdr, 8); |
| 2979 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | goto out_resource; |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2981 | p = encode_change(p, &stat, d_inode(dentry), exp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
| 2983 | if (bmval0 & FATTR4_WORD0_SIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2984 | p = xdr_reserve_space(xdr, 8); |
| 2985 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2987 | p = xdr_encode_hyper(p, stat.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | } |
| 2989 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2990 | p = xdr_reserve_space(xdr, 4); |
| 2991 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2993 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | } |
| 2995 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2996 | p = xdr_reserve_space(xdr, 4); |
| 2997 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2999 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | } |
| 3001 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3002 | p = xdr_reserve_space(xdr, 4); |
| 3003 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3005 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | } |
| 3007 | if (bmval0 & FATTR4_WORD0_FSID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3008 | p = xdr_reserve_space(xdr, 16); |
| 3009 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 3011 | if (exp->ex_fslocs.migrated) { |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3012 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR); |
| 3013 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3014 | } else switch(fsid_source(fhp)) { |
| 3015 | case FSIDSOURCE_FSID: |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3016 | p = xdr_encode_hyper(p, (u64)exp->ex_fsid); |
| 3017 | p = xdr_encode_hyper(p, (u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3018 | break; |
| 3019 | case FSIDSOURCE_DEV: |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3020 | *p++ = cpu_to_be32(0); |
| 3021 | *p++ = cpu_to_be32(MAJOR(stat.dev)); |
| 3022 | *p++ = cpu_to_be32(0); |
| 3023 | *p++ = cpu_to_be32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3024 | break; |
| 3025 | case FSIDSOURCE_UUID: |
Kinglong Mee | 94eb368 | 2014-05-23 20:00:19 +0800 | [diff] [blame] | 3026 | p = xdr_encode_opaque_fixed(p, exp->ex_uuid, |
| 3027 | EX_UUID_LEN); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3028 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3032 | p = xdr_reserve_space(xdr, 4); |
| 3033 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3035 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | } |
| 3037 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3038 | p = xdr_reserve_space(xdr, 4); |
| 3039 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3041 | *p++ = cpu_to_be32(nn->nfsd4_lease); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | } |
| 3043 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3044 | p = xdr_reserve_space(xdr, 4); |
| 3045 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3047 | *p++ = cpu_to_be32(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | } |
| 3049 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 3050 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
| 3052 | if (acl == NULL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3053 | p = xdr_reserve_space(xdr, 4); |
| 3054 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | goto out_resource; |
| 3056 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3057 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | goto out_acl; |
| 3059 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3060 | p = xdr_reserve_space(xdr, 4); |
| 3061 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3063 | *p++ = cpu_to_be32(acl->naces); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3065 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3066 | p = xdr_reserve_space(xdr, 4*3); |
| 3067 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3069 | *p++ = cpu_to_be32(ace->type); |
| 3070 | *p++ = cpu_to_be32(ace->flag); |
| 3071 | *p++ = cpu_to_be32(ace->access_mask & |
| 3072 | NFS4_ACE_MASK_ALL); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3073 | status = nfsd4_encode_aclname(xdr, rqstp, ace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | if (status) |
| 3075 | goto out; |
| 3076 | } |
| 3077 | } |
| 3078 | out_acl: |
| 3079 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3080 | p = xdr_reserve_space(xdr, 4); |
| 3081 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | goto out_resource; |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 3083 | *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 3085 | } |
| 3086 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3087 | p = xdr_reserve_space(xdr, 4); |
| 3088 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3090 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | } |
| 3092 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3093 | p = xdr_reserve_space(xdr, 4); |
| 3094 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3096 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | } |
| 3098 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3099 | p = xdr_reserve_space(xdr, 4); |
| 3100 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3102 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | } |
| 3104 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3105 | p = xdr_reserve_space(xdr, 4); |
| 3106 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3108 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | } |
| 3110 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3111 | p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4); |
| 3112 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | goto out_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3114 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, |
| 3115 | fhp->fh_handle.fh_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | } |
| 3117 | if (bmval0 & FATTR4_WORD0_FILEID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3118 | p = xdr_reserve_space(xdr, 8); |
| 3119 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3121 | p = xdr_encode_hyper(p, stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | } |
| 3123 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3124 | p = xdr_reserve_space(xdr, 8); |
| 3125 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3127 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | } |
| 3129 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3130 | p = xdr_reserve_space(xdr, 8); |
| 3131 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3133 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | } |
| 3135 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3136 | p = xdr_reserve_space(xdr, 8); |
| 3137 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3139 | p = xdr_encode_hyper(p, (u64) statfs.f_files); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3141 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3142 | status = nfsd4_encode_fs_locations(xdr, rqstp, exp); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3143 | if (status) |
| 3144 | goto out; |
| 3145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3147 | p = xdr_reserve_space(xdr, 4); |
| 3148 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3150 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | } |
| 3152 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3153 | p = xdr_reserve_space(xdr, 8); |
| 3154 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3156 | p = xdr_encode_hyper(p, exp->ex_path.mnt->mnt_sb->s_maxbytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | } |
| 3158 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3159 | p = xdr_reserve_space(xdr, 4); |
| 3160 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3162 | *p++ = cpu_to_be32(255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | } |
| 3164 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3165 | p = xdr_reserve_space(xdr, 4); |
| 3166 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3168 | *p++ = cpu_to_be32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | } |
| 3170 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3171 | p = xdr_reserve_space(xdr, 8); |
| 3172 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3174 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | } |
| 3176 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3177 | p = xdr_reserve_space(xdr, 8); |
| 3178 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3180 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
| 3182 | if (bmval1 & FATTR4_WORD1_MODE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3183 | p = xdr_reserve_space(xdr, 4); |
| 3184 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3186 | *p++ = cpu_to_be32(stat.mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | } |
| 3188 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3189 | p = xdr_reserve_space(xdr, 4); |
| 3190 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3192 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | } |
| 3194 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3195 | p = xdr_reserve_space(xdr, 4); |
| 3196 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3198 | *p++ = cpu_to_be32(stat.nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | } |
| 3200 | if (bmval1 & FATTR4_WORD1_OWNER) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3201 | status = nfsd4_encode_user(xdr, rqstp, stat.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | if (status) |
| 3203 | goto out; |
| 3204 | } |
| 3205 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3206 | status = nfsd4_encode_group(xdr, rqstp, stat.gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | if (status) |
| 3208 | goto out; |
| 3209 | } |
| 3210 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3211 | p = xdr_reserve_space(xdr, 8); |
| 3212 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3214 | *p++ = cpu_to_be32((u32) MAJOR(stat.rdev)); |
| 3215 | *p++ = cpu_to_be32((u32) MINOR(stat.rdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | } |
| 3217 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3218 | p = xdr_reserve_space(xdr, 8); |
| 3219 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | goto out_resource; |
| 3221 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3222 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
| 3224 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3225 | p = xdr_reserve_space(xdr, 8); |
| 3226 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | goto out_resource; |
| 3228 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3229 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | } |
| 3231 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3232 | p = xdr_reserve_space(xdr, 8); |
| 3233 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | goto out_resource; |
| 3235 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3236 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | } |
| 3238 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3239 | p = xdr_reserve_space(xdr, 8); |
| 3240 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | goto out_resource; |
| 3242 | dummy64 = (u64)stat.blocks << 9; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3243 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | } |
| 3245 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3246 | p = xdr_reserve_space(xdr, 12); |
| 3247 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3249 | p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3250 | *p++ = cpu_to_be32(stat.atime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | } |
| 3252 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3253 | p = xdr_reserve_space(xdr, 12); |
| 3254 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | goto out_resource; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 3256 | p = encode_time_delta(p, d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | } |
| 3258 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3259 | p = xdr_reserve_space(xdr, 12); |
| 3260 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3262 | p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3263 | *p++ = cpu_to_be32(stat.ctime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | } |
| 3265 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3266 | p = xdr_reserve_space(xdr, 12); |
| 3267 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3269 | p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3270 | *p++ = cpu_to_be32(stat.mtime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | } |
| 3272 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3273 | struct kstat parent_stat; |
| 3274 | u64 ino = stat.ino; |
| 3275 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3276 | p = xdr_reserve_space(xdr, 8); |
| 3277 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3279 | /* |
| 3280 | * Get parent's attributes if not ignoring crossmount |
| 3281 | * and this is the root of a cross-mounted filesystem. |
| 3282 | */ |
| 3283 | if (ignore_crossmnt == 0 && |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3284 | dentry == exp->ex_path.mnt->mnt_root) { |
| 3285 | err = get_parent_attributes(exp, &parent_stat); |
| 3286 | if (err) |
| 3287 | goto out_nfserr; |
| 3288 | ino = parent_stat.ino; |
| 3289 | } |
| 3290 | p = xdr_encode_hyper(p, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3292 | #ifdef CONFIG_NFSD_PNFS |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3293 | if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3294 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3295 | if (status) |
| 3296 | goto out; |
| 3297 | } |
| 3298 | |
| 3299 | if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3300 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3301 | if (status) |
| 3302 | goto out; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) { |
| 3306 | p = xdr_reserve_space(xdr, 4); |
| 3307 | if (!p) |
| 3308 | goto out_resource; |
| 3309 | *p++ = cpu_to_be32(stat.blksize); |
| 3310 | } |
| 3311 | #endif /* CONFIG_NFSD_PNFS */ |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3312 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
Trond Myklebust | b26b78c | 2017-05-09 16:24:59 -0400 | [diff] [blame] | 3313 | u32 supp[3]; |
| 3314 | |
| 3315 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
| 3316 | supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0; |
| 3317 | supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1; |
| 3318 | supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2; |
| 3319 | |
| 3320 | status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]); |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3321 | if (status) |
| 3322 | goto out; |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3323 | } |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3324 | |
J. Bruce Fields | a858576 | 2018-04-25 13:26:23 -0400 | [diff] [blame] | 3325 | if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) { |
| 3326 | p = xdr_reserve_space(xdr, 4); |
| 3327 | if (!p) |
| 3328 | goto out_resource; |
| 3329 | if (IS_I_VERSION(d_inode(dentry))) |
| 3330 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR); |
| 3331 | else |
| 3332 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); |
| 3333 | } |
| 3334 | |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3335 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3336 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 3337 | status = nfsd4_encode_security_label(xdr, rqstp, context, |
| 3338 | contextlen); |
| 3339 | if (status) |
| 3340 | goto out; |
| 3341 | } |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3342 | #endif |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3343 | |
Frank van der Linden | 0e885e8 | 2020-06-23 22:39:27 +0000 | [diff] [blame] | 3344 | if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) { |
| 3345 | p = xdr_reserve_space(xdr, 4); |
| 3346 | if (!p) |
| 3347 | goto out_resource; |
| 3348 | err = xattr_supported_namespace(d_inode(dentry), |
| 3349 | XATTR_USER_PREFIX); |
| 3350 | *p++ = cpu_to_be32(err == 0); |
| 3351 | } |
| 3352 | |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 3353 | attrlen = htonl(xdr->buf->len - attrlen_offset - 4); |
| 3354 | write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | status = nfs_ok; |
| 3356 | |
| 3357 | out: |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3358 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3359 | if (context) |
| 3360 | security_release_secctx(context, contextlen); |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3361 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3362 | kfree(acl); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3363 | if (tempfh) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 3364 | fh_put(tempfh); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3365 | kfree(tempfh); |
| 3366 | } |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3367 | if (status) |
| 3368 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | return status; |
| 3370 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 3371 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | goto out; |
| 3373 | out_resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | status = nfserr_resource; |
| 3375 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3378 | static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, |
| 3379 | struct xdr_buf *buf, __be32 *p, int bytes) |
| 3380 | { |
| 3381 | xdr->scratch.iov_len = 0; |
| 3382 | memset(buf, 0, sizeof(struct xdr_buf)); |
| 3383 | buf->head[0].iov_base = p; |
| 3384 | buf->head[0].iov_len = 0; |
| 3385 | buf->len = 0; |
| 3386 | xdr->buf = buf; |
| 3387 | xdr->iov = buf->head; |
| 3388 | xdr->p = p; |
| 3389 | xdr->end = (void *)p + bytes; |
| 3390 | buf->buflen = bytes; |
| 3391 | } |
| 3392 | |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3393 | __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, |
| 3394 | struct svc_fh *fhp, struct svc_export *exp, |
| 3395 | struct dentry *dentry, u32 *bmval, |
| 3396 | struct svc_rqst *rqstp, int ignore_crossmnt) |
| 3397 | { |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3398 | struct xdr_buf dummy; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3399 | struct xdr_stream xdr; |
| 3400 | __be32 ret; |
| 3401 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3402 | svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2); |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3403 | ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp, |
| 3404 | ignore_crossmnt); |
| 3405 | *p = xdr.p; |
| 3406 | return ret; |
| 3407 | } |
| 3408 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 3409 | static inline int attributes_need_mount(u32 *bmval) |
| 3410 | { |
| 3411 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 3412 | return 1; |
| 3413 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 3414 | return 1; |
| 3415 | return 0; |
| 3416 | } |
| 3417 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3418 | static __be32 |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3419 | nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, |
| 3420 | const char *name, int namlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | { |
| 3422 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 3423 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3424 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3425 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 3427 | dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | if (IS_ERR(dentry)) |
| 3429 | return nfserrno(PTR_ERR(dentry)); |
| 3430 | |
| 3431 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3432 | /* |
| 3433 | * In the case of a mountpoint, the client may be asking for |
| 3434 | * attributes that are only properties of the underlying filesystem |
| 3435 | * as opposed to the cross-mounted file system. In such a case, |
| 3436 | * we will not follow the cross mount and will fill the attribtutes |
| 3437 | * directly from the mountpoint dentry. |
| 3438 | */ |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3439 | if (nfsd_mountpoint(dentry, exp)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3440 | int err; |
| 3441 | |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3442 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
| 3443 | && !attributes_need_mount(cd->rd_bmval)) { |
| 3444 | ignore_crossmnt = 1; |
| 3445 | goto out_encode; |
| 3446 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3447 | /* |
| 3448 | * Why the heck aren't we just using nfsd_lookup?? |
| 3449 | * Different "."/".." handling? Something else? |
| 3450 | * At least, add a comment here to explain.... |
| 3451 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3452 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 3453 | if (err) { |
| 3454 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | goto out_put; |
| 3456 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3457 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 3458 | if (nfserr) |
| 3459 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | |
| 3461 | } |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3462 | out_encode: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3463 | nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3464 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | out_put: |
| 3466 | dput(dentry); |
| 3467 | exp_put(exp); |
| 3468 | return nfserr; |
| 3469 | } |
| 3470 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3471 | static __be32 * |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3472 | nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | { |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3474 | __be32 *p; |
| 3475 | |
Kinglong Mee | c3a4561 | 2014-07-06 11:34:43 +0800 | [diff] [blame] | 3476 | p = xdr_reserve_space(xdr, 20); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3477 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | return NULL; |
| 3479 | *p++ = htonl(2); |
| 3480 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 3481 | *p++ = htonl(0); /* bmval1 */ |
| 3482 | |
J. Bruce Fields | 87915c6 | 2013-01-16 17:33:28 -0500 | [diff] [blame] | 3483 | *p++ = htonl(4); /* attribute length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | *p++ = nfserr; /* no htonl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | return p; |
| 3486 | } |
| 3487 | |
| 3488 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3489 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 3490 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3492 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3494 | struct xdr_stream *xdr = cd->xdr; |
| 3495 | int start_offset = xdr->buf->len; |
| 3496 | int cookie_offset; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3497 | u32 name_and_cookie; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3498 | int entry_bytes; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3499 | __be32 nfserr = nfserr_toosmall; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3500 | __be64 wire_offset; |
| 3501 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | |
| 3503 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 3504 | if (name && isdotent(name, namlen)) { |
| 3505 | cd->common.err = nfs_ok; |
| 3506 | return 0; |
| 3507 | } |
| 3508 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3509 | if (cd->cookie_offset) { |
| 3510 | wire_offset = cpu_to_be64(offset); |
| 3511 | write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, |
| 3512 | &wire_offset, 8); |
| 3513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3515 | p = xdr_reserve_space(xdr, 4); |
| 3516 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | *p++ = xdr_one; /* mark entry present */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3519 | cookie_offset = xdr->buf->len; |
| 3520 | p = xdr_reserve_space(xdr, 3*4 + namlen); |
| 3521 | if (!p) |
| 3522 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 3524 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 3525 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3526 | nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | switch (nfserr) { |
| 3528 | case nfs_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | break; |
| 3530 | case nfserr_resource: |
| 3531 | nfserr = nfserr_toosmall; |
| 3532 | goto fail; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3533 | case nfserr_noent: |
Kinglong Mee | f41c5ad | 2014-06-13 17:32:42 +0800 | [diff] [blame] | 3534 | xdr_truncate_encode(xdr, start_offset); |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3535 | goto skip_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | default: |
| 3537 | /* |
| 3538 | * If the client requested the RDATTR_ERROR attribute, |
| 3539 | * we stuff the error code into this attribute |
| 3540 | * and continue. If this attribute was not requested, |
| 3541 | * then in accordance with the spec, we fail the |
| 3542 | * entire READDIR operation(!) |
| 3543 | */ |
| 3544 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 3545 | goto fail; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3546 | p = nfsd4_encode_rdattr_error(xdr, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3547 | if (p == NULL) { |
| 3548 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | } |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3552 | nfserr = nfserr_toosmall; |
| 3553 | entry_bytes = xdr->buf->len - start_offset; |
| 3554 | if (entry_bytes > cd->rd_maxcount) |
| 3555 | goto fail; |
| 3556 | cd->rd_maxcount -= entry_bytes; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3557 | /* |
| 3558 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so |
| 3559 | * let's always let through the first entry, at least: |
| 3560 | */ |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3561 | if (!cd->rd_dircount) |
| 3562 | goto fail; |
| 3563 | name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3564 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) |
| 3565 | goto fail; |
| 3566 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3567 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3568 | cd->cookie_offset = cookie_offset; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3569 | skip_entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | cd->common.err = nfs_ok; |
| 3571 | return 0; |
| 3572 | fail: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3573 | xdr_truncate_encode(xdr, start_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | cd->common.err = nfserr; |
| 3575 | return -EINVAL; |
| 3576 | } |
| 3577 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3578 | static __be32 |
| 3579 | nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3580 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3581 | __be32 *p; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3582 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3583 | p = xdr_reserve_space(xdr, sizeof(stateid_t)); |
| 3584 | if (!p) |
| 3585 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3586 | *p++ = cpu_to_be32(sid->si_generation); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3587 | p = xdr_encode_opaque_fixed(p, &sid->si_opaque, |
| 3588 | sizeof(stateid_opaque_t)); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3589 | return 0; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3590 | } |
| 3591 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3592 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3593 | nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3595 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3596 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3598 | p = xdr_reserve_space(xdr, 8); |
| 3599 | if (!p) |
| 3600 | return nfserr_resource; |
| 3601 | *p++ = cpu_to_be32(access->ac_supported); |
| 3602 | *p++ = cpu_to_be32(access->ac_resp_access); |
| 3603 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | } |
| 3605 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3606 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
| 3607 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3608 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3609 | __be32 *p; |
| 3610 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3611 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8); |
| 3612 | if (!p) |
| 3613 | return nfserr_resource; |
| 3614 | p = xdr_encode_opaque_fixed(p, bcts->sessionid.data, |
| 3615 | NFS4_MAX_SESSIONID_LEN); |
| 3616 | *p++ = cpu_to_be32(bcts->dir); |
| 3617 | /* Upshifting from TCP to RDMA is not supported */ |
| 3618 | *p++ = cpu_to_be32(0); |
| 3619 | return 0; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3620 | } |
| 3621 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3622 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3623 | nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3625 | struct xdr_stream *xdr = &resp->xdr; |
| 3626 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3627 | return nfsd4_encode_stateid(xdr, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3631 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3632 | nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3634 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3635 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3637 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 3638 | if (!p) |
| 3639 | return nfserr_resource; |
| 3640 | p = xdr_encode_opaque_fixed(p, commit->co_verf.data, |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3641 | NFS4_VERIFIER_SIZE); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3642 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3645 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3646 | nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3648 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3649 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3651 | p = xdr_reserve_space(xdr, 20); |
| 3652 | if (!p) |
| 3653 | return nfserr_resource; |
| 3654 | encode_cinfo(p, &create->cr_cinfo); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 3655 | return nfsd4_encode_bitmap(xdr, create->cr_bmval[0], |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3656 | create->cr_bmval[1], create->cr_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3659 | static __be32 |
| 3660 | nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | { |
| 3662 | struct svc_fh *fhp = getattr->ga_fhp; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3663 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3665 | return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry, |
| 3666 | getattr->ga_bmval, resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | } |
| 3668 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3669 | static __be32 |
| 3670 | nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3672 | struct xdr_stream *xdr = &resp->xdr; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3673 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | unsigned int len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3675 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3677 | len = fhp->fh_handle.fh_size; |
| 3678 | p = xdr_reserve_space(xdr, len + 4); |
| 3679 | if (!p) |
| 3680 | return nfserr_resource; |
| 3681 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len); |
| 3682 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | /* |
| 3686 | * Including all fields other than the name, a LOCK4denied structure requires |
| 3687 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 3688 | */ |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3689 | static __be32 |
| 3690 | nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | { |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3692 | struct xdr_netobj *conf = &ld->ld_owner; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3693 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3695 | again: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3696 | p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3697 | if (!p) { |
| 3698 | /* |
| 3699 | * Don't fail to return the result just because we can't |
| 3700 | * return the conflicting open: |
| 3701 | */ |
| 3702 | if (conf->len) { |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3703 | kfree(conf->data); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3704 | conf->len = 0; |
| 3705 | conf->data = NULL; |
| 3706 | goto again; |
| 3707 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3708 | return nfserr_resource; |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3709 | } |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3710 | p = xdr_encode_hyper(p, ld->ld_start); |
| 3711 | p = xdr_encode_hyper(p, ld->ld_length); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3712 | *p++ = cpu_to_be32(ld->ld_type); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3713 | if (conf->len) { |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3714 | p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); |
| 3715 | p = xdr_encode_opaque(p, conf->data, conf->len); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3716 | kfree(conf->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3718 | p = xdr_encode_hyper(p, (u64)0); /* clientid */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3719 | *p++ = cpu_to_be32(0); /* length of owner name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3721 | return nfserr_denied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3724 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3725 | nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3727 | struct xdr_stream *xdr = &resp->xdr; |
| 3728 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3729 | if (!nfserr) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3730 | nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid); |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3731 | else if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3732 | nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3733 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3734 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | } |
| 3736 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3737 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3738 | nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3740 | struct xdr_stream *xdr = &resp->xdr; |
| 3741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3743 | nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3744 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3747 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3748 | nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3750 | struct xdr_stream *xdr = &resp->xdr; |
| 3751 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3752 | return nfsd4_encode_stateid(xdr, &locku->lu_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3756 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3757 | nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3759 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3760 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3762 | p = xdr_reserve_space(xdr, 20); |
| 3763 | if (!p) |
| 3764 | return nfserr_resource; |
| 3765 | p = encode_cinfo(p, &link->li_cinfo); |
| 3766 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3770 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3771 | nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3773 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3774 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3776 | nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid); |
| 3777 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3778 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3779 | p = xdr_reserve_space(xdr, 24); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3780 | if (!p) |
| 3781 | return nfserr_resource; |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 3782 | p = encode_cinfo(p, &open->op_cinfo); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3783 | *p++ = cpu_to_be32(open->op_rflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3785 | nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1], |
| 3786 | open->op_bmval[2]); |
| 3787 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3788 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3789 | |
| 3790 | p = xdr_reserve_space(xdr, 4); |
| 3791 | if (!p) |
| 3792 | return nfserr_resource; |
| 3793 | |
| 3794 | *p++ = cpu_to_be32(open->op_delegate_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | switch (open->op_delegate_type) { |
| 3796 | case NFS4_OPEN_DELEGATE_NONE: |
| 3797 | break; |
| 3798 | case NFS4_OPEN_DELEGATE_READ: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3799 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3800 | if (nfserr) |
| 3801 | return nfserr; |
| 3802 | p = xdr_reserve_space(xdr, 20); |
| 3803 | if (!p) |
| 3804 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3805 | *p++ = cpu_to_be32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
| 3807 | /* |
| 3808 | * TODO: ACE's in delegations |
| 3809 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3810 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3811 | *p++ = cpu_to_be32(0); |
| 3812 | *p++ = cpu_to_be32(0); |
| 3813 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | break; |
| 3815 | case NFS4_OPEN_DELEGATE_WRITE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3816 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3817 | if (nfserr) |
| 3818 | return nfserr; |
| 3819 | p = xdr_reserve_space(xdr, 32); |
| 3820 | if (!p) |
| 3821 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3822 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | |
| 3824 | /* |
| 3825 | * TODO: space_limit's in delegations |
| 3826 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3827 | *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); |
| 3828 | *p++ = cpu_to_be32(~(u32)0); |
| 3829 | *p++ = cpu_to_be32(~(u32)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | |
| 3831 | /* |
| 3832 | * TODO: ACE's in delegations |
| 3833 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3834 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3835 | *p++ = cpu_to_be32(0); |
| 3836 | *p++ = cpu_to_be32(0); |
| 3837 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | break; |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3839 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
| 3840 | switch (open->op_why_no_deleg) { |
| 3841 | case WND4_CONTENTION: |
| 3842 | case WND4_RESOURCE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3843 | p = xdr_reserve_space(xdr, 8); |
| 3844 | if (!p) |
| 3845 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3846 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
| 3847 | /* deleg signaling not supported yet: */ |
| 3848 | *p++ = cpu_to_be32(0); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3849 | break; |
| 3850 | default: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3851 | p = xdr_reserve_space(xdr, 4); |
| 3852 | if (!p) |
| 3853 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3854 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3855 | } |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3856 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | default: |
| 3858 | BUG(); |
| 3859 | } |
| 3860 | /* XXX save filehandle here */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3861 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3864 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3865 | nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3867 | struct xdr_stream *xdr = &resp->xdr; |
| 3868 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3869 | return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | } |
| 3871 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3872 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3873 | nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3875 | struct xdr_stream *xdr = &resp->xdr; |
| 3876 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3877 | return nfsd4_encode_stateid(xdr, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3880 | static __be32 nfsd4_encode_splice_read( |
| 3881 | struct nfsd4_compoundres *resp, |
| 3882 | struct nfsd4_read *read, |
| 3883 | struct file *file, unsigned long maxcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | { |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3885 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3886 | struct xdr_buf *buf = xdr->buf; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3887 | int status, space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3888 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3889 | __be32 nfserr; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3890 | __be32 *p = xdr->p - 2; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3891 | |
Kinglong Mee | d5d5c30 | 2014-07-09 21:51:27 +0800 | [diff] [blame] | 3892 | /* Make sure there will be room for padding if needed */ |
| 3893 | if (xdr->end - xdr->p < 1) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3894 | return nfserr_resource; |
| 3895 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3896 | nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3897 | file, read->rd_offset, &maxcount, &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3898 | read->rd_length = maxcount; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3899 | if (nfserr) |
| 3900 | goto out_err; |
| 3901 | status = svc_encode_result_payload(read->rd_rqstp, |
| 3902 | buf->head[0].iov_len, maxcount); |
| 3903 | if (status) { |
| 3904 | nfserr = nfserrno(status); |
| 3905 | goto out_err; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3906 | } |
| 3907 | |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3908 | *(p++) = htonl(eof); |
| 3909 | *(p++) = htonl(maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3910 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3911 | buf->page_len = maxcount; |
| 3912 | buf->len += maxcount; |
J. Bruce Fields | 15b23ef | 2014-09-24 16:32:34 -0400 | [diff] [blame] | 3913 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
| 3914 | / PAGE_SIZE; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3915 | |
| 3916 | /* Use rest of head for padding and remaining ops: */ |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3917 | buf->tail[0].iov_base = xdr->p; |
| 3918 | buf->tail[0].iov_len = 0; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3919 | xdr->iov = buf->tail; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3920 | if (maxcount&3) { |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3921 | int pad = 4 - (maxcount&3); |
| 3922 | |
| 3923 | *(xdr->p++) = 0; |
| 3924 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3925 | buf->tail[0].iov_base += maxcount&3; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3926 | buf->tail[0].iov_len = pad; |
| 3927 | buf->len += pad; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | space_left = min_t(int, (void *)xdr->end - (void *)xdr->p, |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3931 | buf->buflen - buf->len); |
| 3932 | buf->buflen = buf->len + space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3933 | xdr->end = (__be32 *)((void *)xdr->end + space_left); |
| 3934 | |
| 3935 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3936 | |
| 3937 | out_err: |
| 3938 | /* |
| 3939 | * nfsd_splice_actor may have already messed with the |
| 3940 | * page length; reset it so as not to confuse |
| 3941 | * xdr_truncate_encode in our caller. |
| 3942 | */ |
| 3943 | buf->page_len = 0; |
| 3944 | return nfserr; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, |
| 3948 | struct nfsd4_read *read, |
| 3949 | struct file *file, unsigned long maxcount) |
| 3950 | { |
| 3951 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3953 | int starting_len = xdr->buf->len - 8; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3954 | __be32 nfserr; |
| 3955 | __be32 tmp; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3956 | int pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | |
Anna Schumaker | 403217f | 2020-08-17 12:53:06 -0400 | [diff] [blame] | 3958 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, maxcount); |
| 3959 | if (read->rd_vlen < 0) |
| 3960 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3962 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3963 | resp->rqstp->rq_vec, read->rd_vlen, &maxcount, |
| 3964 | &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3965 | read->rd_length = maxcount; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3966 | if (nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | return nfserr; |
Chuck Lever | 03493bc | 2020-06-10 10:36:42 -0400 | [diff] [blame] | 3968 | if (svc_encode_result_payload(resp->rqstp, starting_len + 8, maxcount)) |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 3969 | return nfserr_io; |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3970 | xdr_truncate_encode(xdr, starting_len + 8 + xdr_align_size(maxcount)); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3971 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3972 | tmp = htonl(eof); |
| 3973 | write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); |
| 3974 | tmp = htonl(maxcount); |
| 3975 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
| 3976 | |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3977 | tmp = xdr_zero; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3978 | pad = (maxcount&3) ? 4 - (maxcount&3) : 0; |
| 3979 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3980 | &tmp, pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | return 0; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3982 | |
| 3983 | } |
| 3984 | |
| 3985 | static __be32 |
| 3986 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 3987 | struct nfsd4_read *read) |
| 3988 | { |
| 3989 | unsigned long maxcount; |
| 3990 | struct xdr_stream *xdr = &resp->xdr; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3991 | struct file *file; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3992 | int starting_len = xdr->buf->len; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3993 | __be32 *p; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3994 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3995 | if (nfserr) |
| 3996 | return nfserr; |
| 3997 | file = read->rd_nf->nf_file; |
| 3998 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3999 | p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */ |
| 4000 | if (!p) { |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 4001 | WARN_ON_ONCE(test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4002 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4003 | } |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 4004 | if (resp->xdr.buf->page_len && |
| 4005 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) { |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 4006 | WARN_ON_ONCE(1); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4007 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4008 | } |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4009 | xdr_commit_encode(xdr); |
| 4010 | |
| 4011 | maxcount = svc_max_payload(resp->rqstp); |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 4012 | maxcount = min_t(unsigned long, maxcount, |
| 4013 | (xdr->buf->buflen - xdr->buf->len)); |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 4014 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4015 | |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 4016 | if (file->f_op->splice_read && |
| 4017 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4018 | nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4019 | else |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4020 | nfserr = nfsd4_encode_readv(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4021 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4022 | if (nfserr) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4023 | xdr_truncate_encode(xdr, starting_len); |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4024 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4025 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4028 | static __be32 |
| 4029 | nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | { |
| 4031 | int maxcount; |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4032 | __be32 wire_count; |
| 4033 | int zero = 0; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4034 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4035 | int length_offset = xdr->buf->len; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4036 | int status; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4037 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 4039 | p = xdr_reserve_space(xdr, 4); |
| 4040 | if (!p) |
| 4041 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | maxcount = PAGE_SIZE; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4043 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4044 | p = xdr_reserve_space(xdr, maxcount); |
| 4045 | if (!p) |
J. Bruce Fields | 4e21ac4 | 2014-03-22 15:15:11 -0400 | [diff] [blame] | 4046 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | /* |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 4048 | * XXX: By default, vfs_readlink() will truncate symlinks if they |
| 4049 | * would overflow the buffer. Is this kosher in NFSv4? If not, one |
| 4050 | * easy fix is: if vfs_readlink() precisely fills the buffer, assume |
| 4051 | * that truncation occurred, and return NFS4ERR_RESOURCE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | */ |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4053 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, |
| 4054 | (char *)p, &maxcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | if (nfserr == nfserr_isdir) |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4056 | nfserr = nfserr_inval; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4057 | if (nfserr) |
| 4058 | goto out_err; |
| 4059 | status = svc_encode_result_payload(readlink->rl_rqstp, length_offset, |
| 4060 | maxcount); |
| 4061 | if (status) { |
| 4062 | nfserr = nfserrno(status); |
| 4063 | goto out_err; |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4066 | wire_count = htonl(maxcount); |
| 4067 | write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); |
Avi Kivity | 69bbd9c | 2014-06-26 17:23:12 +0300 | [diff] [blame] | 4068 | xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4)); |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4069 | if (maxcount & 3) |
| 4070 | write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, |
| 4071 | &zero, 4 - (maxcount&3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4073 | |
| 4074 | out_err: |
| 4075 | xdr_truncate_encode(xdr, length_offset); |
| 4076 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | } |
| 4078 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4079 | static __be32 |
| 4080 | nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | { |
| 4082 | int maxcount; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4083 | int bytes_left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | loff_t offset; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4085 | __be64 wire_offset; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4086 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4087 | int starting_len = xdr->buf->len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4088 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4090 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 4091 | if (!p) |
| 4092 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | |
| 4094 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4095 | *p++ = cpu_to_be32(0); |
| 4096 | *p++ = cpu_to_be32(0); |
J. Bruce Fields | 4aea24b | 2014-01-15 15:17:58 -0500 | [diff] [blame] | 4097 | resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p) |
| 4098 | - (char *)resp->xdr.buf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | |
| 4100 | /* |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4101 | * Number of bytes left for directory entries allowing for the |
| 4102 | * final 8 bytes of the readdir and a following failed op: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4104 | bytes_left = xdr->buf->buflen - xdr->buf->len |
| 4105 | - COMPOUND_ERR_SLACK_SPACE - 8; |
| 4106 | if (bytes_left < 0) { |
| 4107 | nfserr = nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | goto err_no_verf; |
| 4109 | } |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4110 | maxcount = svc_max_payload(resp->rqstp); |
| 4111 | maxcount = min_t(u32, readdir->rd_maxcount, maxcount); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4112 | /* |
| 4113 | * Note the rfc defines rd_maxcount as the size of the |
| 4114 | * READDIR4resok structure, which includes the verifier above |
| 4115 | * and the 8 bytes encoded at the end of this function: |
| 4116 | */ |
| 4117 | if (maxcount < 16) { |
| 4118 | nfserr = nfserr_toosmall; |
| 4119 | goto err_no_verf; |
| 4120 | } |
| 4121 | maxcount = min_t(int, maxcount-16, bytes_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4123 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ |
| 4124 | if (!readdir->rd_dircount) |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4125 | readdir->rd_dircount = svc_max_payload(resp->rqstp); |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4126 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4127 | readdir->xdr = xdr; |
| 4128 | readdir->rd_maxcount = maxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | readdir->common.err = 0; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4130 | readdir->cookie_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | |
| 4132 | offset = readdir->rd_cookie; |
| 4133 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 4134 | &offset, |
| 4135 | &readdir->common, nfsd4_encode_dirent); |
| 4136 | if (nfserr == nfs_ok && |
| 4137 | readdir->common.err == nfserr_toosmall && |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4138 | xdr->buf->len == starting_len + 8) { |
| 4139 | /* nothing encoded; which limit did we hit?: */ |
| 4140 | if (maxcount - 16 < bytes_left) |
| 4141 | /* It was the fault of rd_maxcount: */ |
| 4142 | nfserr = nfserr_toosmall; |
| 4143 | else |
| 4144 | /* We ran out of buffer space: */ |
| 4145 | nfserr = nfserr_resource; |
| 4146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | if (nfserr) |
| 4148 | goto err_no_verf; |
| 4149 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4150 | if (readdir->cookie_offset) { |
| 4151 | wire_offset = cpu_to_be64(offset); |
| 4152 | write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, |
| 4153 | &wire_offset, 8); |
| 4154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4156 | p = xdr_reserve_space(xdr, 8); |
| 4157 | if (!p) { |
| 4158 | WARN_ON_ONCE(1); |
| 4159 | goto err_no_verf; |
| 4160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | *p++ = 0; /* no more entries */ |
| 4162 | *p++ = htonl(readdir->common.err == nfserr_eof); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | |
| 4164 | return 0; |
| 4165 | err_no_verf: |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4166 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | return nfserr; |
| 4168 | } |
| 4169 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4170 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4171 | nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4173 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4174 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4176 | p = xdr_reserve_space(xdr, 20); |
| 4177 | if (!p) |
| 4178 | return nfserr_resource; |
| 4179 | p = encode_cinfo(p, &remove->rm_cinfo); |
| 4180 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4183 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4184 | nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4186 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4187 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4189 | p = xdr_reserve_space(xdr, 40); |
| 4190 | if (!p) |
| 4191 | return nfserr_resource; |
| 4192 | p = encode_cinfo(p, &rename->rn_sinfo); |
| 4193 | p = encode_cinfo(p, &rename->rn_tinfo); |
| 4194 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4197 | static __be32 |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4198 | nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4199 | { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4200 | u32 i, nflavs, supported; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4201 | struct exp_flavor_info *flavs; |
| 4202 | struct exp_flavor_info def_flavs[2]; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4203 | __be32 *p, *flavorsp; |
| 4204 | static bool report = true; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4205 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4206 | if (exp->ex_nflavors) { |
| 4207 | flavs = exp->ex_flavors; |
| 4208 | nflavs = exp->ex_nflavors; |
| 4209 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 4210 | flavs = def_flavs; |
| 4211 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 4212 | nflavs = 2; |
| 4213 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 4214 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 4215 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 4216 | nflavs = 1; |
| 4217 | flavs[0].pseudoflavor |
| 4218 | = svcauth_gss_flavor(exp->ex_client); |
| 4219 | } else { |
| 4220 | nflavs = 1; |
| 4221 | flavs[0].pseudoflavor |
| 4222 | = exp->ex_client->flavour->flavour; |
| 4223 | } |
| 4224 | } |
| 4225 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4226 | supported = 0; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4227 | p = xdr_reserve_space(xdr, 4); |
| 4228 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4229 | return nfserr_resource; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4230 | flavorsp = p++; /* to be backfilled later */ |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4231 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4232 | for (i = 0; i < nflavs; i++) { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4233 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4234 | struct rpcsec_gss_info info; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4235 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4236 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
| 4237 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4238 | p = xdr_reserve_space(xdr, 4 + 4 + |
| 4239 | XDR_LEN(info.oid.len) + 4 + 4); |
| 4240 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4241 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4242 | *p++ = cpu_to_be32(RPC_AUTH_GSS); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4243 | p = xdr_encode_opaque(p, info.oid.data, info.oid.len); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4244 | *p++ = cpu_to_be32(info.qop); |
| 4245 | *p++ = cpu_to_be32(info.service); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4246 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
| 4247 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4248 | p = xdr_reserve_space(xdr, 4); |
| 4249 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4250 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4251 | *p++ = cpu_to_be32(pf); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4252 | } else { |
| 4253 | if (report) |
| 4254 | pr_warn("NFS: SECINFO: security flavor %u " |
| 4255 | "is not supported\n", pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4256 | } |
| 4257 | } |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4258 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4259 | if (nflavs != supported) |
| 4260 | report = false; |
| 4261 | *flavorsp = htonl(supported); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4262 | return 0; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4265 | static __be32 |
| 4266 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4267 | struct nfsd4_secinfo *secinfo) |
| 4268 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4269 | struct xdr_stream *xdr = &resp->xdr; |
| 4270 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4271 | return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | static __be32 |
| 4275 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4276 | struct nfsd4_secinfo_no_name *secinfo) |
| 4277 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4278 | struct xdr_stream *xdr = &resp->xdr; |
| 4279 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4280 | return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4281 | } |
| 4282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | /* |
| 4284 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 4285 | * regardless of the error status. |
| 4286 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4287 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4288 | nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4290 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4291 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4293 | p = xdr_reserve_space(xdr, 16); |
| 4294 | if (!p) |
| 4295 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | if (nfserr) { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4297 | *p++ = cpu_to_be32(3); |
| 4298 | *p++ = cpu_to_be32(0); |
| 4299 | *p++ = cpu_to_be32(0); |
| 4300 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | } |
| 4302 | else { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4303 | *p++ = cpu_to_be32(3); |
| 4304 | *p++ = cpu_to_be32(setattr->sa_bmval[0]); |
| 4305 | *p++ = cpu_to_be32(setattr->sa_bmval[1]); |
| 4306 | *p++ = cpu_to_be32(setattr->sa_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4308 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4311 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4312 | nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4314 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4315 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | |
| 4317 | if (!nfserr) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4318 | p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE); |
| 4319 | if (!p) |
| 4320 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4321 | p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8); |
| 4322 | p = xdr_encode_opaque_fixed(p, &scd->se_confirm, |
| 4323 | NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | } |
| 4325 | else if (nfserr == nfserr_clid_inuse) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4326 | p = xdr_reserve_space(xdr, 8); |
| 4327 | if (!p) |
| 4328 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4329 | *p++ = cpu_to_be32(0); |
| 4330 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4332 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4335 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4336 | nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4337 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4338 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4339 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4341 | p = xdr_reserve_space(xdr, 16); |
| 4342 | if (!p) |
| 4343 | return nfserr_resource; |
| 4344 | *p++ = cpu_to_be32(write->wr_bytes_written); |
| 4345 | *p++ = cpu_to_be32(write->wr_how_written); |
| 4346 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4347 | NFS4_VERIFIER_SIZE); |
| 4348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4351 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4352 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4353 | struct nfsd4_exchange_id *exid) |
| 4354 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4355 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4356 | __be32 *p; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4357 | char *major_id; |
| 4358 | char *server_scope; |
| 4359 | int major_id_sz; |
| 4360 | int server_scope_sz; |
| 4361 | uint64_t minor_id = 0; |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4362 | struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4363 | |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4364 | major_id = nn->nfsd_name; |
| 4365 | major_id_sz = strlen(nn->nfsd_name); |
| 4366 | server_scope = nn->nfsd_name; |
| 4367 | server_scope_sz = strlen(nn->nfsd_name); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4368 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4369 | p = xdr_reserve_space(xdr, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4370 | 8 /* eir_clientid */ + |
| 4371 | 4 /* eir_sequenceid */ + |
| 4372 | 4 /* eir_flags */ + |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4373 | 4 /* spr_how */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4374 | if (!p) |
| 4375 | return nfserr_resource; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4376 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4377 | p = xdr_encode_opaque_fixed(p, &exid->clientid, 8); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4378 | *p++ = cpu_to_be32(exid->seqid); |
| 4379 | *p++ = cpu_to_be32(exid->flags); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4380 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4381 | *p++ = cpu_to_be32(exid->spa_how); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4382 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4383 | switch (exid->spa_how) { |
| 4384 | case SP4_NONE: |
| 4385 | break; |
| 4386 | case SP4_MACH_CRED: |
| 4387 | /* spo_must_enforce bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4388 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4389 | exid->spo_must_enforce[0], |
| 4390 | exid->spo_must_enforce[1], |
| 4391 | exid->spo_must_enforce[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4392 | if (nfserr) |
| 4393 | return nfserr; |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4394 | /* spo_must_allow bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4395 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4396 | exid->spo_must_allow[0], |
| 4397 | exid->spo_must_allow[1], |
| 4398 | exid->spo_must_allow[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4399 | if (nfserr) |
| 4400 | return nfserr; |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4401 | break; |
| 4402 | default: |
| 4403 | WARN_ON_ONCE(1); |
| 4404 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4405 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4406 | p = xdr_reserve_space(xdr, |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4407 | 8 /* so_minor_id */ + |
| 4408 | 4 /* so_major_id.len */ + |
| 4409 | (XDR_QUADLEN(major_id_sz) * 4) + |
| 4410 | 4 /* eir_server_scope.len */ + |
| 4411 | (XDR_QUADLEN(server_scope_sz) * 4) + |
| 4412 | 4 /* eir_server_impl_id.count (0) */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4413 | if (!p) |
| 4414 | return nfserr_resource; |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4415 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4416 | /* The server_owner struct */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 4417 | p = xdr_encode_hyper(p, minor_id); /* Minor id */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4418 | /* major id */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4419 | p = xdr_encode_opaque(p, major_id, major_id_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4420 | |
| 4421 | /* Server scope */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4422 | p = xdr_encode_opaque(p, server_scope, server_scope_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4423 | |
| 4424 | /* Implementation id */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4425 | *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4426 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4430 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4431 | struct nfsd4_create_session *sess) |
| 4432 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4433 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4434 | __be32 *p; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4435 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4436 | p = xdr_reserve_space(xdr, 24); |
| 4437 | if (!p) |
| 4438 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4439 | p = xdr_encode_opaque_fixed(p, sess->sessionid.data, |
| 4440 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4441 | *p++ = cpu_to_be32(sess->seqid); |
| 4442 | *p++ = cpu_to_be32(sess->flags); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4443 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4444 | p = xdr_reserve_space(xdr, 28); |
| 4445 | if (!p) |
| 4446 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4447 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4448 | *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz); |
| 4449 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz); |
| 4450 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached); |
| 4451 | *p++ = cpu_to_be32(sess->fore_channel.maxops); |
| 4452 | *p++ = cpu_to_be32(sess->fore_channel.maxreqs); |
| 4453 | *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4454 | |
| 4455 | if (sess->fore_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4456 | p = xdr_reserve_space(xdr, 4); |
| 4457 | if (!p) |
| 4458 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4459 | *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4460 | } |
| 4461 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4462 | p = xdr_reserve_space(xdr, 28); |
| 4463 | if (!p) |
| 4464 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4465 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4466 | *p++ = cpu_to_be32(sess->back_channel.maxreq_sz); |
| 4467 | *p++ = cpu_to_be32(sess->back_channel.maxresp_sz); |
| 4468 | *p++ = cpu_to_be32(sess->back_channel.maxresp_cached); |
| 4469 | *p++ = cpu_to_be32(sess->back_channel.maxops); |
| 4470 | *p++ = cpu_to_be32(sess->back_channel.maxreqs); |
| 4471 | *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4472 | |
| 4473 | if (sess->back_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4474 | p = xdr_reserve_space(xdr, 4); |
| 4475 | if (!p) |
| 4476 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4477 | *p++ = cpu_to_be32(sess->back_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4478 | } |
| 4479 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4483 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4484 | struct nfsd4_sequence *seq) |
| 4485 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4486 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4487 | __be32 *p; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4488 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4489 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); |
| 4490 | if (!p) |
| 4491 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4492 | p = xdr_encode_opaque_fixed(p, seq->sessionid.data, |
| 4493 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4494 | *p++ = cpu_to_be32(seq->seqid); |
| 4495 | *p++ = cpu_to_be32(seq->slotid); |
J. Bruce Fields | b7d7ca3 | 2011-08-31 15:39:30 -0400 | [diff] [blame] | 4496 | /* Note slotid's are numbered from zero: */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4497 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ |
| 4498 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ |
| 4499 | *p++ = cpu_to_be32(seq->status_flags); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4500 | |
J. Bruce Fields | f523601 | 2014-03-21 17:57:57 -0400 | [diff] [blame] | 4501 | resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4502 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4503 | } |
| 4504 | |
J. Bruce Fields | 2355c59 | 2012-04-25 16:56:22 -0400 | [diff] [blame] | 4505 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4506 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4507 | struct nfsd4_test_stateid *test_stateid) |
| 4508 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4509 | struct xdr_stream *xdr = &resp->xdr; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4510 | struct nfsd4_test_stateid_id *stateid, *next; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4511 | __be32 *p; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4512 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4513 | p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids)); |
| 4514 | if (!p) |
| 4515 | return nfserr_resource; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4516 | *p++ = htonl(test_stateid->ts_num_ids); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4517 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4518 | list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) { |
Al Viro | 02f5fde | 2012-04-13 00:10:34 -0400 | [diff] [blame] | 4519 | *p++ = stateid->ts_id_status; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4520 | } |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4521 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4522 | return 0; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4523 | } |
| 4524 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4525 | #ifdef CONFIG_NFSD_PNFS |
| 4526 | static __be32 |
| 4527 | nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4528 | struct nfsd4_getdeviceinfo *gdev) |
| 4529 | { |
| 4530 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4531 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4532 | u32 starting_len = xdr->buf->len, needed_len; |
| 4533 | __be32 *p; |
| 4534 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4535 | p = xdr_reserve_space(xdr, 4); |
| 4536 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4537 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4538 | |
| 4539 | *p++ = cpu_to_be32(gdev->gd_layout_type); |
| 4540 | |
| 4541 | /* If maxcount is 0 then just update notifications */ |
| 4542 | if (gdev->gd_maxcount != 0) { |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4543 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4544 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
| 4545 | if (nfserr) { |
| 4546 | /* |
| 4547 | * We don't bother to burden the layout drivers with |
| 4548 | * enforcing gd_maxcount, just tell the client to |
| 4549 | * come back with a bigger buffer if it's not enough. |
| 4550 | */ |
| 4551 | if (xdr->buf->len + 4 > gdev->gd_maxcount) |
| 4552 | goto toosmall; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4553 | return nfserr; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4554 | } |
| 4555 | } |
| 4556 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4557 | if (gdev->gd_notify_types) { |
| 4558 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4559 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4560 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4561 | *p++ = cpu_to_be32(1); /* bitmap length */ |
| 4562 | *p++ = cpu_to_be32(gdev->gd_notify_types); |
| 4563 | } else { |
| 4564 | p = xdr_reserve_space(xdr, 4); |
| 4565 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4566 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4567 | *p++ = 0; |
| 4568 | } |
| 4569 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4570 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4571 | toosmall: |
| 4572 | dprintk("%s: maxcount too small\n", __func__); |
| 4573 | needed_len = xdr->buf->len + 4 /* notifications */; |
| 4574 | xdr_truncate_encode(xdr, starting_len); |
| 4575 | p = xdr_reserve_space(xdr, 4); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4576 | if (!p) |
| 4577 | return nfserr_resource; |
| 4578 | *p++ = cpu_to_be32(needed_len); |
| 4579 | return nfserr_toosmall; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | static __be32 |
| 4583 | nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4584 | struct nfsd4_layoutget *lgp) |
| 4585 | { |
| 4586 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4587 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4588 | __be32 *p; |
| 4589 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4590 | p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t)); |
| 4591 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4592 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4593 | |
| 4594 | *p++ = cpu_to_be32(1); /* we always set return-on-close */ |
| 4595 | *p++ = cpu_to_be32(lgp->lg_sid.si_generation); |
| 4596 | p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque, |
| 4597 | sizeof(stateid_opaque_t)); |
| 4598 | |
| 4599 | *p++ = cpu_to_be32(1); /* we always return a single layout */ |
| 4600 | p = xdr_encode_hyper(p, lgp->lg_seg.offset); |
| 4601 | p = xdr_encode_hyper(p, lgp->lg_seg.length); |
| 4602 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); |
| 4603 | *p++ = cpu_to_be32(lgp->lg_layout_type); |
| 4604 | |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4605 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4606 | return ops->encode_layoutget(xdr, lgp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4607 | } |
| 4608 | |
| 4609 | static __be32 |
| 4610 | nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4611 | struct nfsd4_layoutcommit *lcp) |
| 4612 | { |
| 4613 | struct xdr_stream *xdr = &resp->xdr; |
| 4614 | __be32 *p; |
| 4615 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4616 | p = xdr_reserve_space(xdr, 4); |
| 4617 | if (!p) |
| 4618 | return nfserr_resource; |
| 4619 | *p++ = cpu_to_be32(lcp->lc_size_chg); |
| 4620 | if (lcp->lc_size_chg) { |
| 4621 | p = xdr_reserve_space(xdr, 8); |
| 4622 | if (!p) |
| 4623 | return nfserr_resource; |
| 4624 | p = xdr_encode_hyper(p, lcp->lc_newsize); |
| 4625 | } |
| 4626 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4627 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | static __be32 |
| 4631 | nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4632 | struct nfsd4_layoutreturn *lrp) |
| 4633 | { |
| 4634 | struct xdr_stream *xdr = &resp->xdr; |
| 4635 | __be32 *p; |
| 4636 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4637 | p = xdr_reserve_space(xdr, 4); |
| 4638 | if (!p) |
| 4639 | return nfserr_resource; |
| 4640 | *p++ = cpu_to_be32(lrp->lrs_present); |
| 4641 | if (lrp->lrs_present) |
Kinglong Mee | 376675d | 2015-03-22 22:17:10 +0800 | [diff] [blame] | 4642 | return nfsd4_encode_stateid(xdr, &lrp->lr_sid); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4643 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4644 | } |
| 4645 | #endif /* CONFIG_NFSD_PNFS */ |
| 4646 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4647 | static __be32 |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4648 | nfsd42_encode_write_res(struct nfsd4_compoundres *resp, |
| 4649 | struct nfsd42_write_res *write, bool sync) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4650 | { |
| 4651 | __be32 *p; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4652 | p = xdr_reserve_space(&resp->xdr, 4); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4653 | if (!p) |
| 4654 | return nfserr_resource; |
| 4655 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4656 | if (sync) |
| 4657 | *p++ = cpu_to_be32(0); |
| 4658 | else { |
| 4659 | __be32 nfserr; |
| 4660 | *p++ = cpu_to_be32(1); |
| 4661 | nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid); |
| 4662 | if (nfserr) |
| 4663 | return nfserr; |
| 4664 | } |
| 4665 | p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE); |
| 4666 | if (!p) |
| 4667 | return nfserr_resource; |
| 4668 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4669 | p = xdr_encode_hyper(p, write->wr_bytes_written); |
| 4670 | *p++ = cpu_to_be32(write->wr_stable_how); |
| 4671 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4672 | NFS4_VERIFIER_SIZE); |
| 4673 | return nfs_ok; |
| 4674 | } |
| 4675 | |
| 4676 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4677 | nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns) |
| 4678 | { |
| 4679 | struct xdr_stream *xdr = &resp->xdr; |
| 4680 | struct nfs42_netaddr *addr; |
| 4681 | __be32 *p; |
| 4682 | |
| 4683 | p = xdr_reserve_space(xdr, 4); |
| 4684 | *p++ = cpu_to_be32(ns->nl4_type); |
| 4685 | |
| 4686 | switch (ns->nl4_type) { |
| 4687 | case NL4_NETADDR: |
| 4688 | addr = &ns->u.nl4_addr; |
| 4689 | |
| 4690 | /* netid_len, netid, uaddr_len, uaddr (port included |
| 4691 | * in RPCBIND_MAXUADDRLEN) |
| 4692 | */ |
| 4693 | p = xdr_reserve_space(xdr, |
| 4694 | 4 /* netid len */ + |
| 4695 | (XDR_QUADLEN(addr->netid_len) * 4) + |
| 4696 | 4 /* uaddr len */ + |
| 4697 | (XDR_QUADLEN(addr->addr_len) * 4)); |
| 4698 | if (!p) |
| 4699 | return nfserr_resource; |
| 4700 | |
| 4701 | *p++ = cpu_to_be32(addr->netid_len); |
| 4702 | p = xdr_encode_opaque_fixed(p, addr->netid, |
| 4703 | addr->netid_len); |
| 4704 | *p++ = cpu_to_be32(addr->addr_len); |
| 4705 | p = xdr_encode_opaque_fixed(p, addr->addr, |
| 4706 | addr->addr_len); |
| 4707 | break; |
| 4708 | default: |
| 4709 | WARN_ON_ONCE(ns->nl4_type != NL4_NETADDR); |
| 4710 | return nfserr_inval; |
| 4711 | } |
| 4712 | |
| 4713 | return 0; |
| 4714 | } |
| 4715 | |
| 4716 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4717 | nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4718 | struct nfsd4_copy *copy) |
| 4719 | { |
| 4720 | __be32 *p; |
| 4721 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4722 | nfserr = nfsd42_encode_write_res(resp, ©->cp_res, |
Chuck Lever | e8febea | 2020-11-04 10:49:37 -0500 | [diff] [blame] | 4723 | !!copy->cp_synchronous); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4724 | if (nfserr) |
| 4725 | return nfserr; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4726 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4727 | p = xdr_reserve_space(&resp->xdr, 4 + 4); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 4728 | *p++ = xdr_one; /* cr_consecutive */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4729 | *p++ = cpu_to_be32(copy->cp_synchronous); |
| 4730 | return 0; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4734 | nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4735 | struct nfsd4_offload_status *os) |
| 4736 | { |
| 4737 | struct xdr_stream *xdr = &resp->xdr; |
| 4738 | __be32 *p; |
| 4739 | |
| 4740 | p = xdr_reserve_space(xdr, 8 + 4); |
| 4741 | if (!p) |
| 4742 | return nfserr_resource; |
| 4743 | p = xdr_encode_hyper(p, os->count); |
| 4744 | *p++ = cpu_to_be32(0); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4745 | return nfserr; |
| 4746 | } |
| 4747 | |
| 4748 | static __be32 |
| 4749 | nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, |
| 4750 | struct nfsd4_read *read, |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4751 | unsigned long *maxcount, u32 *eof, |
| 4752 | loff_t *pos) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4753 | { |
| 4754 | struct xdr_stream *xdr = &resp->xdr; |
| 4755 | struct file *file = read->rd_nf->nf_file; |
| 4756 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4757 | loff_t hole_pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4758 | __be32 nfserr; |
| 4759 | __be32 *p, tmp; |
| 4760 | __be64 tmp64; |
| 4761 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4762 | hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4763 | if (hole_pos > read->rd_offset) |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4764 | *maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset); |
| 4765 | *maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len)); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4766 | |
| 4767 | /* Content type, offset, byte count */ |
| 4768 | p = xdr_reserve_space(xdr, 4 + 8 + 4); |
| 4769 | if (!p) |
| 4770 | return nfserr_resource; |
| 4771 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4772 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, *maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4773 | if (read->rd_vlen < 0) |
| 4774 | return nfserr_resource; |
| 4775 | |
| 4776 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4777 | resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4778 | if (nfserr) |
| 4779 | return nfserr; |
| 4780 | |
| 4781 | tmp = htonl(NFS4_CONTENT_DATA); |
| 4782 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4783 | tmp64 = cpu_to_be64(read->rd_offset); |
| 4784 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp64, 8); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4785 | tmp = htonl(*maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4786 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp, 4); |
| 4787 | return nfs_ok; |
| 4788 | } |
| 4789 | |
| 4790 | static __be32 |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4791 | nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, |
| 4792 | struct nfsd4_read *read, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4793 | unsigned long *maxcount, u32 *eof) |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4794 | { |
| 4795 | struct file *file = read->rd_nf->nf_file; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4796 | loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4797 | loff_t f_size = i_size_read(file_inode(file)); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4798 | unsigned long count; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4799 | __be32 *p; |
| 4800 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4801 | if (data_pos == -ENXIO) |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4802 | data_pos = f_size; |
| 4803 | else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE)) |
| 4804 | return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4805 | count = data_pos - read->rd_offset; |
| 4806 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4807 | /* Content type, offset, byte count */ |
| 4808 | p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8); |
| 4809 | if (!p) |
| 4810 | return nfserr_resource; |
| 4811 | |
| 4812 | *p++ = htonl(NFS4_CONTENT_HOLE); |
| 4813 | p = xdr_encode_hyper(p, read->rd_offset); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4814 | p = xdr_encode_hyper(p, count); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4815 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4816 | *eof = (read->rd_offset + count) >= f_size; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4817 | *maxcount = min_t(unsigned long, count, *maxcount); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4818 | return nfs_ok; |
| 4819 | } |
| 4820 | |
| 4821 | static __be32 |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4822 | nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4823 | struct nfsd4_read *read) |
| 4824 | { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4825 | unsigned long maxcount, count; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4826 | struct xdr_stream *xdr = &resp->xdr; |
| 4827 | struct file *file; |
| 4828 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4829 | int last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4830 | int segments = 0; |
| 4831 | __be32 *p, tmp; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4832 | bool is_data; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4833 | loff_t pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4834 | u32 eof; |
| 4835 | |
| 4836 | if (nfserr) |
| 4837 | return nfserr; |
| 4838 | file = read->rd_nf->nf_file; |
| 4839 | |
| 4840 | /* eof flag, segment count */ |
| 4841 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4842 | if (!p) |
| 4843 | return nfserr_resource; |
| 4844 | xdr_commit_encode(xdr); |
| 4845 | |
| 4846 | maxcount = svc_max_payload(resp->rqstp); |
| 4847 | maxcount = min_t(unsigned long, maxcount, |
| 4848 | (xdr->buf->buflen - xdr->buf->len)); |
| 4849 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4850 | count = maxcount; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4851 | |
| 4852 | eof = read->rd_offset >= i_size_read(file_inode(file)); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4853 | if (eof) |
| 4854 | goto out; |
| 4855 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4856 | pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
| 4857 | is_data = pos > read->rd_offset; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4858 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4859 | while (count > 0 && !eof) { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4860 | maxcount = count; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4861 | if (is_data) |
| 4862 | nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof, |
| 4863 | segments == 0 ? &pos : NULL); |
| 4864 | else |
| 4865 | nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4866 | if (nfserr) |
| 4867 | goto out; |
| 4868 | count -= maxcount; |
| 4869 | read->rd_offset += maxcount; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4870 | is_data = !is_data; |
| 4871 | last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4872 | segments++; |
| 4873 | } |
| 4874 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4875 | out: |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4876 | if (nfserr && segments == 0) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4877 | xdr_truncate_encode(xdr, starting_len); |
| 4878 | else { |
| 4879 | tmp = htonl(eof); |
| 4880 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4881 | tmp = htonl(segments); |
| 4882 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4883 | if (nfserr) { |
| 4884 | xdr_truncate_encode(xdr, last_segment); |
| 4885 | nfserr = nfs_ok; |
| 4886 | } |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4887 | } |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4888 | |
| 4889 | return nfserr; |
| 4890 | } |
| 4891 | |
| 4892 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4893 | nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4894 | struct nfsd4_copy_notify *cn) |
| 4895 | { |
| 4896 | struct xdr_stream *xdr = &resp->xdr; |
| 4897 | __be32 *p; |
| 4898 | |
| 4899 | if (nfserr) |
| 4900 | return nfserr; |
| 4901 | |
| 4902 | /* 8 sec, 4 nsec */ |
| 4903 | p = xdr_reserve_space(xdr, 12); |
| 4904 | if (!p) |
| 4905 | return nfserr_resource; |
| 4906 | |
| 4907 | /* cnr_lease_time */ |
| 4908 | p = xdr_encode_hyper(p, cn->cpn_sec); |
| 4909 | *p++ = cpu_to_be32(cn->cpn_nsec); |
| 4910 | |
| 4911 | /* cnr_stateid */ |
| 4912 | nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid); |
| 4913 | if (nfserr) |
| 4914 | return nfserr; |
| 4915 | |
| 4916 | /* cnr_src.nl_nsvr */ |
| 4917 | p = xdr_reserve_space(xdr, 4); |
| 4918 | if (!p) |
| 4919 | return nfserr_resource; |
| 4920 | |
| 4921 | *p++ = cpu_to_be32(1); |
| 4922 | |
| 4923 | return nfsd42_encode_nl4_server(resp, &cn->cpn_src); |
| 4924 | } |
| 4925 | |
| 4926 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4927 | nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4928 | struct nfsd4_seek *seek) |
| 4929 | { |
| 4930 | __be32 *p; |
| 4931 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4932 | p = xdr_reserve_space(&resp->xdr, 4 + 8); |
| 4933 | *p++ = cpu_to_be32(seek->seek_eof); |
| 4934 | p = xdr_encode_hyper(p, seek->seek_pos); |
| 4935 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4936 | return 0; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | static __be32 |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4940 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 4941 | { |
| 4942 | return nfserr; |
| 4943 | } |
| 4944 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4945 | /* |
| 4946 | * Encode kmalloc-ed buffer in to XDR stream. |
| 4947 | */ |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 4948 | static __be32 |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4949 | nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen) |
| 4950 | { |
| 4951 | u32 cplen; |
| 4952 | __be32 *p; |
| 4953 | |
| 4954 | cplen = min_t(unsigned long, buflen, |
| 4955 | ((void *)xdr->end - (void *)xdr->p)); |
| 4956 | p = xdr_reserve_space(xdr, cplen); |
| 4957 | if (!p) |
| 4958 | return nfserr_resource; |
| 4959 | |
| 4960 | memcpy(p, buf, cplen); |
| 4961 | buf += cplen; |
| 4962 | buflen -= cplen; |
| 4963 | |
| 4964 | while (buflen) { |
| 4965 | cplen = min_t(u32, buflen, PAGE_SIZE); |
| 4966 | p = xdr_reserve_space(xdr, cplen); |
| 4967 | if (!p) |
| 4968 | return nfserr_resource; |
| 4969 | |
| 4970 | memcpy(p, buf, cplen); |
| 4971 | |
| 4972 | if (cplen < PAGE_SIZE) { |
| 4973 | /* |
| 4974 | * We're done, with a length that wasn't page |
| 4975 | * aligned, so possibly not word aligned. Pad |
| 4976 | * any trailing bytes with 0. |
| 4977 | */ |
| 4978 | xdr_encode_opaque_fixed(p, NULL, cplen); |
| 4979 | break; |
| 4980 | } |
| 4981 | |
| 4982 | buflen -= PAGE_SIZE; |
| 4983 | buf += PAGE_SIZE; |
| 4984 | } |
| 4985 | |
| 4986 | return 0; |
| 4987 | } |
| 4988 | |
| 4989 | static __be32 |
| 4990 | nfsd4_encode_getxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4991 | struct nfsd4_getxattr *getxattr) |
| 4992 | { |
| 4993 | struct xdr_stream *xdr = &resp->xdr; |
| 4994 | __be32 *p, err; |
| 4995 | |
| 4996 | p = xdr_reserve_space(xdr, 4); |
| 4997 | if (!p) |
| 4998 | return nfserr_resource; |
| 4999 | |
| 5000 | *p = cpu_to_be32(getxattr->getxa_len); |
| 5001 | |
| 5002 | if (getxattr->getxa_len == 0) |
| 5003 | return 0; |
| 5004 | |
| 5005 | err = nfsd4_vbuf_to_stream(xdr, getxattr->getxa_buf, |
| 5006 | getxattr->getxa_len); |
| 5007 | |
| 5008 | kvfree(getxattr->getxa_buf); |
| 5009 | |
| 5010 | return err; |
| 5011 | } |
| 5012 | |
| 5013 | static __be32 |
| 5014 | nfsd4_encode_setxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5015 | struct nfsd4_setxattr *setxattr) |
| 5016 | { |
| 5017 | struct xdr_stream *xdr = &resp->xdr; |
| 5018 | __be32 *p; |
| 5019 | |
| 5020 | p = xdr_reserve_space(xdr, 20); |
| 5021 | if (!p) |
| 5022 | return nfserr_resource; |
| 5023 | |
| 5024 | encode_cinfo(p, &setxattr->setxa_cinfo); |
| 5025 | |
| 5026 | return 0; |
| 5027 | } |
| 5028 | |
| 5029 | /* |
| 5030 | * See if there are cookie values that can be rejected outright. |
| 5031 | */ |
| 5032 | static __be32 |
| 5033 | nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs, |
| 5034 | u32 *offsetp) |
| 5035 | { |
| 5036 | u64 cookie = listxattrs->lsxa_cookie; |
| 5037 | |
| 5038 | /* |
| 5039 | * If the cookie is larger than the maximum number we can fit |
| 5040 | * in either the buffer we just got back from vfs_listxattr, or, |
| 5041 | * XDR-encoded, in the return buffer, it's invalid. |
| 5042 | */ |
| 5043 | if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2)) |
| 5044 | return nfserr_badcookie; |
| 5045 | |
| 5046 | if (cookie > (listxattrs->lsxa_maxcount / |
| 5047 | (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4))) |
| 5048 | return nfserr_badcookie; |
| 5049 | |
| 5050 | *offsetp = (u32)cookie; |
| 5051 | return 0; |
| 5052 | } |
| 5053 | |
| 5054 | static __be32 |
| 5055 | nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5056 | struct nfsd4_listxattrs *listxattrs) |
| 5057 | { |
| 5058 | struct xdr_stream *xdr = &resp->xdr; |
| 5059 | u32 cookie_offset, count_offset, eof; |
| 5060 | u32 left, xdrleft, slen, count; |
| 5061 | u32 xdrlen, offset; |
| 5062 | u64 cookie; |
| 5063 | char *sp; |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5064 | __be32 status, tmp; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5065 | __be32 *p; |
| 5066 | u32 nuser; |
| 5067 | |
| 5068 | eof = 1; |
| 5069 | |
| 5070 | status = nfsd4_listxattr_validate_cookie(listxattrs, &offset); |
| 5071 | if (status) |
| 5072 | goto out; |
| 5073 | |
| 5074 | /* |
| 5075 | * Reserve space for the cookie and the name array count. Record |
| 5076 | * the offsets to save them later. |
| 5077 | */ |
| 5078 | cookie_offset = xdr->buf->len; |
| 5079 | count_offset = cookie_offset + 8; |
| 5080 | p = xdr_reserve_space(xdr, 12); |
| 5081 | if (!p) { |
| 5082 | status = nfserr_resource; |
| 5083 | goto out; |
| 5084 | } |
| 5085 | |
| 5086 | count = 0; |
| 5087 | left = listxattrs->lsxa_len; |
| 5088 | sp = listxattrs->lsxa_buf; |
| 5089 | nuser = 0; |
| 5090 | |
| 5091 | xdrleft = listxattrs->lsxa_maxcount; |
| 5092 | |
| 5093 | while (left > 0 && xdrleft > 0) { |
| 5094 | slen = strlen(sp); |
| 5095 | |
| 5096 | /* |
Alex Dewar | 4cce11fa | 2020-08-17 18:51:26 +0100 | [diff] [blame] | 5097 | * Check if this is a "user." attribute, skip it if not. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5098 | */ |
| 5099 | if (strncmp(sp, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) |
| 5100 | goto contloop; |
| 5101 | |
| 5102 | slen -= XATTR_USER_PREFIX_LEN; |
| 5103 | xdrlen = 4 + ((slen + 3) & ~3); |
| 5104 | if (xdrlen > xdrleft) { |
| 5105 | if (count == 0) { |
| 5106 | /* |
| 5107 | * Can't even fit the first attribute name. |
| 5108 | */ |
| 5109 | status = nfserr_toosmall; |
| 5110 | goto out; |
| 5111 | } |
| 5112 | eof = 0; |
| 5113 | goto wreof; |
| 5114 | } |
| 5115 | |
| 5116 | left -= XATTR_USER_PREFIX_LEN; |
| 5117 | sp += XATTR_USER_PREFIX_LEN; |
| 5118 | if (nuser++ < offset) |
| 5119 | goto contloop; |
| 5120 | |
| 5121 | |
| 5122 | p = xdr_reserve_space(xdr, xdrlen); |
| 5123 | if (!p) { |
| 5124 | status = nfserr_resource; |
| 5125 | goto out; |
| 5126 | } |
| 5127 | |
Alex Dewar | e2a1840 | 2020-08-12 15:12:51 +0100 | [diff] [blame] | 5128 | xdr_encode_opaque(p, sp, slen); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5129 | |
| 5130 | xdrleft -= xdrlen; |
| 5131 | count++; |
| 5132 | contloop: |
| 5133 | sp += slen + 1; |
| 5134 | left -= slen + 1; |
| 5135 | } |
| 5136 | |
| 5137 | /* |
| 5138 | * If there were user attributes to copy, but we didn't copy |
| 5139 | * any, the offset was too large (e.g. the cookie was invalid). |
| 5140 | */ |
| 5141 | if (nuser > 0 && count == 0) { |
| 5142 | status = nfserr_badcookie; |
| 5143 | goto out; |
| 5144 | } |
| 5145 | |
| 5146 | wreof: |
| 5147 | p = xdr_reserve_space(xdr, 4); |
| 5148 | if (!p) { |
| 5149 | status = nfserr_resource; |
| 5150 | goto out; |
| 5151 | } |
| 5152 | *p = cpu_to_be32(eof); |
| 5153 | |
| 5154 | cookie = offset + count; |
| 5155 | |
| 5156 | write_bytes_to_xdr_buf(xdr->buf, cookie_offset, &cookie, 8); |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5157 | tmp = cpu_to_be32(count); |
| 5158 | write_bytes_to_xdr_buf(xdr->buf, count_offset, &tmp, 4); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5159 | out: |
| 5160 | if (listxattrs->lsxa_len) |
| 5161 | kvfree(listxattrs->lsxa_buf); |
| 5162 | return status; |
| 5163 | } |
| 5164 | |
| 5165 | static __be32 |
| 5166 | nfsd4_encode_removexattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5167 | struct nfsd4_removexattr *removexattr) |
| 5168 | { |
| 5169 | struct xdr_stream *xdr = &resp->xdr; |
| 5170 | __be32 *p; |
| 5171 | |
| 5172 | p = xdr_reserve_space(xdr, 20); |
| 5173 | if (!p) |
| 5174 | return nfserr_resource; |
| 5175 | |
| 5176 | p = encode_cinfo(p, &removexattr->rmxa_cinfo); |
| 5177 | return 0; |
| 5178 | } |
| 5179 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5180 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 5181 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5182 | /* |
| 5183 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 |
| 5184 | * since we don't need to filter out obsolete ops as this is |
| 5185 | * done in the decoding phase. |
| 5186 | */ |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 5187 | static const nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5188 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 5189 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 5190 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 5191 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 5192 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5193 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 5194 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 5195 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 5196 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 5197 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 5198 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 5199 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 5200 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5201 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5202 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5203 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
Benny Halevy | 84f09f4 | 2009-03-04 23:05:35 +0200 | [diff] [blame] | 5204 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5205 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 5206 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 5207 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5208 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5209 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5210 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 5211 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 5212 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 5213 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 5214 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 5215 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 5216 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5217 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5218 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 5219 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 5220 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 5221 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 5222 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5223 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 5224 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5225 | |
| 5226 | /* NFSv4.1 operations */ |
| 5227 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 5228 | [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5229 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
| 5230 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, |
Kinglong Mee | 43212cc | 2013-12-09 19:04:23 +0800 | [diff] [blame] | 5231 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5232 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5233 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5234 | #ifdef CONFIG_NFSD_PNFS |
| 5235 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo, |
| 5236 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5237 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit, |
| 5238 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget, |
| 5239 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn, |
| 5240 | #else |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5241 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
| 5242 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5243 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, |
| 5244 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, |
| 5245 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5246 | #endif |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 5247 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5248 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
| 5249 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 5250 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5251 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5252 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, |
| 5253 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5254 | |
| 5255 | /* NFSv4.2 operations */ |
| 5256 | [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 5257 | [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 5258 | [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_copy_notify, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5259 | [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5260 | [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5261 | [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, |
| 5262 | [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop, |
| 5263 | [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 5264 | [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 5265 | [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_read_plus, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5266 | [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5267 | [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 5268 | [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5269 | |
| 5270 | /* RFC 8276 extended atributes operations */ |
| 5271 | [OP_GETXATTR] = (nfsd4_enc)nfsd4_encode_getxattr, |
| 5272 | [OP_SETXATTR] = (nfsd4_enc)nfsd4_encode_setxattr, |
| 5273 | [OP_LISTXATTRS] = (nfsd4_enc)nfsd4_encode_listxattrs, |
| 5274 | [OP_REMOVEXATTR] = (nfsd4_enc)nfsd4_encode_removexattr, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5275 | }; |
| 5276 | |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5277 | /* |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5278 | * Calculate whether we still have space to encode repsize bytes. |
| 5279 | * There are two considerations: |
| 5280 | * - For NFS versions >=4.1, the size of the reply must stay within |
| 5281 | * session limits |
| 5282 | * - For all NFS versions, we must stay within limited preallocated |
| 5283 | * buffer space. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5284 | * |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5285 | * This is called before the operation is processed, so can only provide |
| 5286 | * an upper estimate. For some nonidempotent operations (such as |
| 5287 | * getattr), it's not necessarily a problem if that estimate is wrong, |
| 5288 | * as we can fail it after processing without significant side effects. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5289 | */ |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5290 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5291 | { |
J. Bruce Fields | 67492c9 | 2014-03-08 16:42:05 -0500 | [diff] [blame] | 5292 | struct xdr_buf *buf = &resp->rqstp->rq_res; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5293 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5294 | |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5295 | if (buf->len + respsize <= buf->buflen) |
| 5296 | return nfs_ok; |
| 5297 | if (!nfsd4_has_session(&resp->cstate)) |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5298 | return nfserr_resource; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5299 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) { |
| 5300 | WARN_ON_ONCE(1); |
| 5301 | return nfserr_rep_too_big_to_cache; |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5302 | } |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5303 | return nfserr_rep_too_big; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5304 | } |
| 5305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | void |
| 5307 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 5308 | { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5309 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5310 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5311 | struct svc_rqst *rqstp = resp->rqstp; |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5312 | const struct nfsd4_operation *opdesc = op->opdesc; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5313 | int post_err_offset; |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5314 | nfsd4_enc encoder; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5315 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5317 | p = xdr_reserve_space(xdr, 8); |
| 5318 | if (!p) { |
| 5319 | WARN_ON_ONCE(1); |
| 5320 | return; |
| 5321 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5322 | *p++ = cpu_to_be32(op->opnum); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5323 | post_err_offset = xdr->buf->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5325 | if (op->opnum == OP_ILLEGAL) |
| 5326 | goto status; |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 5327 | if (op->status && opdesc && |
| 5328 | !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE)) |
| 5329 | goto status; |
Chuck Lever | 3a237b4 | 2020-11-22 12:49:52 -0500 | [diff] [blame] | 5330 | BUG_ON(op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5331 | !nfsd4_enc_ops[op->opnum]); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5332 | encoder = nfsd4_enc_ops[op->opnum]; |
| 5333 | op->status = encoder(resp, op->status, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 5334 | if (op->status) |
| 5335 | trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status); |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5336 | if (opdesc && opdesc->op_release) |
| 5337 | opdesc->op_release(&op->u); |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5338 | xdr_commit_encode(xdr); |
| 5339 | |
J. Bruce Fields | 067e1ac | 2014-03-21 17:26:44 -0400 | [diff] [blame] | 5340 | /* nfsd4_check_resp_size guarantees enough room for error status */ |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5341 | if (!op->status) { |
| 5342 | int space_needed = 0; |
| 5343 | if (!nfsd4_last_compound_op(rqstp)) |
| 5344 | space_needed = COMPOUND_ERR_SLACK_SPACE; |
| 5345 | op->status = nfsd4_check_resp_size(resp, space_needed); |
| 5346 | } |
J. Bruce Fields | c8f13d9 | 2014-05-08 17:38:18 -0400 | [diff] [blame] | 5347 | if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) { |
| 5348 | struct nfsd4_slot *slot = resp->cstate.slot; |
| 5349 | |
| 5350 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) |
| 5351 | op->status = nfserr_rep_too_big_to_cache; |
| 5352 | else |
| 5353 | op->status = nfserr_rep_too_big; |
| 5354 | } |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5355 | if (op->status == nfserr_resource || |
| 5356 | op->status == nfserr_rep_too_big || |
| 5357 | op->status == nfserr_rep_too_big_to_cache) { |
| 5358 | /* |
| 5359 | * The operation may have already been encoded or |
| 5360 | * partially encoded. No op returns anything additional |
| 5361 | * in the case of one of these three errors, so we can |
| 5362 | * just truncate back to after the status. But it's a |
| 5363 | * bug if we had to do this on a non-idempotent op: |
| 5364 | */ |
| 5365 | warn_on_nonidempotent_op(op); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5366 | xdr_truncate_encode(xdr, post_err_offset); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5367 | } |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5368 | if (so) { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5369 | int len = xdr->buf->len - post_err_offset; |
| 5370 | |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5371 | so->so_replay.rp_status = op->status; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5372 | so->so_replay.rp_buflen = len; |
| 5373 | read_bytes_from_xdr_buf(xdr->buf, post_err_offset, |
| 5374 | so->so_replay.rp_buf, len); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5375 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5376 | status: |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5377 | /* Note that op->status is already in network byte order: */ |
| 5378 | write_bytes_to_xdr_buf(xdr->buf, post_err_offset - 4, &op->status, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | /* |
| 5382 | * Encode the reply stored in the stateowner reply cache |
| 5383 | * |
| 5384 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 5385 | * previously sent already encoded operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | */ |
| 5387 | void |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5388 | nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5390 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | struct nfs4_replay *rp = op->replay; |
| 5392 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5393 | p = xdr_reserve_space(xdr, 8 + rp->rp_buflen); |
| 5394 | if (!p) { |
| 5395 | WARN_ON_ONCE(1); |
| 5396 | return; |
| 5397 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5398 | *p++ = cpu_to_be32(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | *p++ = rp->rp_status; /* already xdr'ed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 5401 | p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | } |
| 5403 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 5404 | void nfsd4_release_compoundargs(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | { |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5406 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | if (args->ops != args->iops) { |
| 5409 | kfree(args->ops); |
| 5410 | args->ops = args->iops; |
| 5411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | while (args->to_free) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 5413 | struct svcxdr_tmpbuf *tb = args->to_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | args->to_free = tb->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | kfree(tb); |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5420 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5422 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5423 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5424 | /* svcxdr_tmp_alloc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5425 | args->to_free = NULL; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5426 | |
| 5427 | args->xdr = &rqstp->rq_arg_stream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5428 | args->ops = args->iops; |
| 5429 | args->rqstp = rqstp; |
| 5430 | |
Chuck Lever | d9b74bd | 2020-11-04 11:07:06 -0500 | [diff] [blame] | 5431 | return nfsd4_decode_compound(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5435 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5437 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
J. Bruce Fields | 6ac9039 | 2014-02-26 17:39:35 -0500 | [diff] [blame] | 5438 | struct xdr_buf *buf = resp->xdr.buf; |
| 5439 | |
| 5440 | WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len + |
| 5441 | buf->tail[0].iov_len); |
J. Bruce Fields | dd97fdd | 2014-02-26 17:16:27 -0500 | [diff] [blame] | 5442 | |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 5443 | *p = resp->cstate.status; |
| 5444 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5445 | rqstp->rq_next_page = resp->xdr.page_ptr + 1; |
| 5446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | p = resp->tagp; |
| 5448 | *p++ = htonl(resp->taglen); |
| 5449 | memcpy(p, resp->tag, resp->taglen); |
| 5450 | p += XDR_QUADLEN(resp->taglen); |
| 5451 | *p++ = htonl(resp->opcnt); |
| 5452 | |
Trond Myklebust | b607664 | 2014-06-30 11:48:35 -0400 | [diff] [blame] | 5453 | nfsd4_sequence_done(resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 | return 1; |
| 5455 | } |
| 5456 | |
| 5457 | /* |
| 5458 | * Local variables: |
| 5459 | * c-basic-offset: 8 |
| 5460 | * End: |
| 5461 | */ |